From 46b0947dfd2241e2cca7f9adea9098dc16cb797b Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 3 Apr 2025 14:36:39 +0800 Subject: [PATCH] fix: Update Assistant API to handle arguments and improve error logging - Modify APIPayload structure to include Args field for passing arguments. - Enhance error handling in Call method by adding logging for method not found scenarios. - Adjust Call method to handle cases with and without arguments, ensuring flexibility in API usage. --- neo/assistant/api.go | 7 ++++++- neo/assistant/types.go | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/neo/assistant/api.go b/neo/assistant/api.go index 9f2eedb1..7ccf925e 100644 --- a/neo/assistant/api.go +++ b/neo/assistant/api.go @@ -306,10 +306,15 @@ func (ast *Assistant) Call(c *gin.Context, payload APIPayload) (interface{}, err // Check if the method exists if !scriptCtx.Global().Has(method) { + color.Red("Assistant Call: %s Method %s not found", ast.ID, method) return nil, fmt.Errorf(HookErrorMethodNotFound) } - return scriptCtx.CallWith(ctx, method, payload.Payload) + if payload.Args == nil || len(payload.Args) == 0 { + return scriptCtx.CallWith(ctx, method) + } + + return scriptCtx.CallWith(ctx, method, payload.Args...) } // handleChatStream manages the streaming chat interaction with the AI diff --git a/neo/assistant/types.go b/neo/assistant/types.go index 036cf5bc..c3a4097a 100644 --- a/neo/assistant/types.go +++ b/neo/assistant/types.go @@ -32,9 +32,9 @@ type API interface { // APIPayload the API payload type APIPayload struct { - Sid string `json:"sid"` - Name string `json:"name"` - Payload map[string]interface{} `json:"payload"` + Sid string `json:"sid"` + Name string `json:"name"` + Args []interface{} `json:"args,omitempty"` } // ResHookInit the response of the init hook