feat: Enhance context management and agent functionality in SUI

- Added support for assistant ID in context handling to improve user-specific interactions.
- Updated asset metadata in bindata.go to reflect recent changes in modification times.
- Enhanced the Agent class in libsui/agent.ts with improved type definitions for the Call method, ensuring better type safety and clarity in asynchronous operations.
- Improved event handling in the Agent class to manage message completion more effectively.
This commit is contained in:
Max 2025-05-06 19:24:06 +08:00
parent 3b723fbce8
commit 83bdab3499
4 changed files with 104 additions and 85 deletions

File diff suppressed because one or more lines are too long

View file

@ -232,6 +232,12 @@ func (neo *DSL) handleChat(c *gin.Context) {
defer cancel()
defer ctx.Release() // Release the context after the request is done
// Set the assistant ID
assistantID := c.Query("assistant_id")
if assistantID != "" {
ctx = chatctx.WithAssistantID(ctx, assistantID)
}
err := neo.Answer(ctx, content, c)
// Error handling

View file

@ -71,6 +71,12 @@ func NewWithCancel(sid, cid, payload string) (Context, context.CancelFunc) {
return WithCancel(ctx)
}
// WithAssistantID set the assistant ID
func WithAssistantID(ctx Context, assistantID string) Context {
ctx.AssistantID = assistantID
return ctx
}
// NewWithTimeout create a new context with timeout
func NewWithTimeout(sid, cid, payload string, timeout time.Duration) (Context, context.CancelFunc) {
ctx := New(sid, cid, payload)

View file

@ -103,7 +103,7 @@ class Agent {
* @param input Text message or input object with text and optional attachments
* @param args Additional arguments to pass to the agent
*/
async Call(input: AgentInput, ...args: any[]) {
async Call(input: AgentInput, ...args: any[]): Promise<any> {
const messages: AgentMessage[] = [];
let currentContent = "";
let lastAssistant = {
@ -302,6 +302,13 @@ class Agent {
messages.push(newMessage);
messageHandler(newMessage);
// If the message is done, close the event source
if (done) {
const doneHandler = this.events["done"] as DoneHandler;
doneHandler?.(messages);
es.close();
}
return;
}