MCPcopy Create free account
hub / github.com/QuantumNous/new-api / DryRunTaskPlugin

Function DryRunTaskPlugin

controller/task_plugin.go:547–587  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

545}
546
547func DryRunTaskPlugin(c *gin.Context) {
548 var request taskPluginDryRunRequest
549 if err := c.ShouldBindJSON(&request); err != nil {
550 common.ApiErrorMsg(c, err.Error())
551 return
552 }
553 detailSource := ""
554 plugin, err := model.GetTaskPluginVersion(c.Param("key"), "")
555 if err == nil {
556 detailSource = string(plugin.Source)
557 } else if errors.Is(err, gorm.ErrRecordNotFound) {
558 detailSource, err = plugins.Source(c.Param("key"))
559 }
560 if err != nil {
561 common.ApiErrorMsg(c, "task plugin not found")
562 return
563 }
564 loaded, err := jsplugin.NewRegistry().Register(detailSource, jsplugin.Options{Key: c.Param("key")})
565 if err != nil {
566 taskPluginCompileError(c, err)
567 return
568 }
569 args := make([]any, len(request.Args))
570 for index, raw := range request.Args {
571 if err = common.Unmarshal(raw, &args[index]); err != nil {
572 common.ApiErrorMsg(c, fmt.Sprintf("invalid argument %d: %v", index+1, err))
573 return
574 }
575 }
576 var output any
577 if request.Member == "" {
578 output, err = loaded.Engine.Call(context.Background(), request.Hook, args...)
579 } else {
580 output, err = loaded.Engine.CallMember(context.Background(), request.Hook, request.Member, args...)
581 }
582 if err != nil {
583 common.ApiErrorMsg(c, err.Error())
584 return
585 }
586 common.ApiSuccess(c, output)
587}
588
589func DeleteTaskPluginVersion(c *gin.Context) {
590 key := c.Param("key")

Callers 1

runTaskPluginDryRunFunction · 0.85

Calls 11

ApiErrorMsgFunction · 0.92
GetTaskPluginVersionFunction · 0.92
SourceFunction · 0.92
NewRegistryFunction · 0.92
UnmarshalFunction · 0.92
ApiSuccessFunction · 0.92
taskPluginCompileErrorFunction · 0.85
CallMethod · 0.80
CallMemberMethod · 0.80
ErrorMethod · 0.45
RegisterMethod · 0.45

Tested by 1

runTaskPluginDryRunFunction · 0.68