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

Function DryRunTaskPlugin

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

Source from the content-addressed store, hash-verified

314}
315
316func DryRunTaskPlugin(c *gin.Context) {
317 var request taskPluginDryRunRequest
318 if err := c.ShouldBindJSON(&request); err != nil {
319 common.ApiErrorMsg(c, err.Error())
320 return
321 }
322 detailSource := ""
323 plugin, err := model.GetTaskPluginVersion(c.Param("key"), "")
324 if err == nil {
325 detailSource = plugin.Source
326 } else if errors.Is(err, gorm.ErrRecordNotFound) {
327 detailSource, err = plugins.Source(c.Param("key"))
328 }
329 if err != nil {
330 common.ApiErrorMsg(c, "task plugin not found")
331 return
332 }
333 loaded, err := jsplugin.NewRegistry().Register(detailSource, jsplugin.Options{Key: c.Param("key")})
334 if err != nil {
335 common.ApiErrorMsg(c, err.Error())
336 return
337 }
338 args := make([]any, len(request.Args))
339 for index, raw := range request.Args {
340 if err = common.Unmarshal(raw, &args[index]); err != nil {
341 common.ApiErrorMsg(c, fmt.Sprintf("invalid argument %d: %v", index+1, err))
342 return
343 }
344 }
345 var output any
346 if request.Member == "" {
347 output, err = loaded.Engine.Call(context.Background(), request.Hook, args...)
348 } else {
349 output, err = loaded.Engine.CallMember(context.Background(), request.Hook, request.Member, args...)
350 }
351 if err != nil {
352 common.ApiErrorMsg(c, err.Error())
353 return
354 }
355 common.ApiSuccess(c, output)
356}
357
358func DeleteTaskPluginVersion(c *gin.Context) {
359 key := c.Param("key")

Callers 1

runTaskPluginDryRunFunction · 0.85

Calls 10

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

Tested by 1

runTaskPluginDryRunFunction · 0.68