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

Function DryRunTaskPlugin

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

Source from the content-addressed store, hash-verified

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