Merge pull request #917 from trheyi/main

fix: Update Assistant API to handle arguments and improve error logging
This commit is contained in:
Max 2025-04-03 14:38:02 +08:00 committed by GitHub
commit 2e74595ad0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 4 deletions

View file

@ -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

View file

@ -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