diff --git a/agent/src/modules/chat.ts b/agent/src/modules/chat.ts index 64b48226..5805468f 100644 --- a/agent/src/modules/chat.ts +++ b/agent/src/modules/chat.ts @@ -17,7 +17,7 @@ const AgentModel = z.object({ skills: z.array(z.string()), query: z.string(), identity: IdentityContextModel, - attachments: z.array(AttachmentModel), + attachments: z.array(AttachmentModel).optional().default([]), }) export const chatModule = new Elysia({ prefix: '/chat' }) @@ -42,7 +42,8 @@ export const chatModule = new Elysia({ prefix: '/chat' }) body: AgentModel, }) .post('/stream', async function* ({ body, bearer }) { - const authFetcher = createAuthFetcher(bearer) + try { + const authFetcher = createAuthFetcher(bearer) const { stream } = createAgent({ model: body.model as ModelConfig, activeContextTime: body.activeContextTime, @@ -59,6 +60,13 @@ export const chatModule = new Elysia({ prefix: '/chat' }) })) { yield sse(JSON.stringify(action)) } + } catch (error) { + console.error(error) + yield sse(JSON.stringify({ + type: 'error', + message: 'Internal server error', + })) + } }, { body: AgentModel, }) diff --git a/docs/docs.go b/docs/docs.go index e47b06dc..3ef5efd5 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -4476,7 +4476,13 @@ const docTemplate = `{ "type": "string" } }, - "current_platform": { + "channels": { + "type": "array", + "items": { + "type": "string" + } + }, + "current_channel": { "type": "string" }, "language": { @@ -4494,12 +4500,6 @@ const docTemplate = `{ "model": { "type": "string" }, - "platforms": { - "type": "array", - "items": { - "type": "string" - } - }, "provider": { "type": "string" }, diff --git a/docs/swagger.json b/docs/swagger.json index c513dacc..16a8a22a 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -4467,7 +4467,13 @@ "type": "string" } }, - "current_platform": { + "channels": { + "type": "array", + "items": { + "type": "string" + } + }, + "current_channel": { "type": "string" }, "language": { @@ -4485,12 +4491,6 @@ "model": { "type": "string" }, - "platforms": { - "type": "array", - "items": { - "type": "string" - } - }, "provider": { "type": "string" }, diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 35f0c8f6..e5e35f18 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -416,7 +416,11 @@ definitions: items: type: string type: array - current_platform: + channels: + items: + type: string + type: array + current_channel: type: string language: type: string @@ -428,10 +432,6 @@ definitions: type: array model: type: string - platforms: - items: - type: string - type: array provider: type: string query: diff --git a/internal/chat/resolver.go b/internal/chat/resolver.go index b262398b..35c01286 100644 --- a/internal/chat/resolver.go +++ b/internal/chat/resolver.go @@ -95,8 +95,8 @@ type gatewayIdentity struct { type agentGatewayRequest struct { Model gatewayModelConfig `json:"model"` ActiveContextTime int `json:"activeContextTime"` - Platforms []string `json:"platforms"` - CurrentPlatform string `json:"currentPlatform"` + Channels []string `json:"channels"` + CurrentChannel string `json:"currentChannel"` AllowedActions []string `json:"allowedActions,omitempty"` Messages []GatewayMessage `json:"messages"` Skills []string `json:"skills"` @@ -177,8 +177,8 @@ func (r *Resolver) Chat(ctx context.Context, req ChatRequest) (ChatResponse, err BaseURL: provider.BaseUrl, }, ActiveContextTime: normalizeMaxContextLoad(maxContextLoadTime), - Platforms: req.Platforms, - CurrentPlatform: req.CurrentPlatform, + Channels: req.Channels, + CurrentChannel: req.CurrentChannel, AllowedActions: req.AllowedActions, Messages: messages, Skills: skills, @@ -191,7 +191,7 @@ func (r *Resolver) Chat(ctx context.Context, req ChatRequest) (ChatResponse, err ContactName: defaultString(req.ContactName, "User"), ContactAlias: req.ContactAlias, UserID: req.UserID, - CurrentPlatform: req.CurrentPlatform, + CurrentPlatform: req.CurrentChannel, ReplyTarget: req.ReplyTarget, SessionToken: req.SessionToken, }, @@ -381,8 +381,8 @@ func (r *Resolver) StreamChat(ctx context.Context, req ChatRequest) (<-chan Stre BaseURL: provider.BaseUrl, }, ActiveContextTime: normalizeMaxContextLoad(maxContextLoadTime), - Platforms: req.Platforms, - CurrentPlatform: req.CurrentPlatform, + Channels: req.Channels, + CurrentChannel: req.CurrentChannel, AllowedActions: req.AllowedActions, Messages: messages, Skills: skills, @@ -395,7 +395,7 @@ func (r *Resolver) StreamChat(ctx context.Context, req ChatRequest) (<-chan Stre ContactName: defaultString(req.ContactName, "User"), ContactAlias: req.ContactAlias, UserID: req.UserID, - CurrentPlatform: req.CurrentPlatform, + CurrentPlatform: req.CurrentChannel, ReplyTarget: req.ReplyTarget, SessionToken: req.SessionToken, }, diff --git a/internal/chat/types.go b/internal/chat/types.go index 295cbf6f..47a32a0c 100644 --- a/internal/chat/types.go +++ b/internal/chat/types.go @@ -25,8 +25,8 @@ type ChatRequest struct { Provider string `json:"provider,omitempty"` MaxContextLoadTime int `json:"max_context_load_time,omitempty"` Language string `json:"language,omitempty"` - Platforms []string `json:"platforms,omitempty"` - CurrentPlatform string `json:"current_platform,omitempty"` + Channels []string `json:"channels,omitempty"` + CurrentChannel string `json:"current_channel,omitempty"` Messages []GatewayMessage `json:"messages,omitempty"` Skills []string `json:"skills,omitempty"` AllowedActions []string `json:"allowed_actions,omitempty"` diff --git a/internal/router/channel.go b/internal/router/channel.go index d146441d..184d5ef2 100644 --- a/internal/router/channel.go +++ b/internal/router/channel.go @@ -140,8 +140,8 @@ func (p *ChannelInboundProcessor) HandleInbound(ctx context.Context, cfg channel ReplyTarget: strings.TrimSpace(msg.ReplyTarget), SessionToken: sessionToken, Query: text, - CurrentPlatform: msg.Channel.String(), - Platforms: []string{msg.Channel.String()}, + CurrentChannel: msg.Channel.String(), + Channels: []string{msg.Channel.String()}, }) if err != nil { if p.logger != nil { diff --git a/packages/cli/src/cli/index.ts b/packages/cli/src/cli/index.ts index da2ee40a..4f3dd925 100755 --- a/packages/cli/src/cli/index.ts +++ b/packages/cli/src/cli/index.ts @@ -835,7 +835,7 @@ const startLocalStream = (botId: string, sessionId: string, token: TokenInfo, on const baseURL = getBaseURL(config) const controller = new AbortController() void (async () => { - const resp = await fetch(`${baseURL}/bots/${botId}/cli/sessions/${sessionId}/stream`, { + const resp = await fetch(`${baseURL}/bots/${botId}/chat/stream`, { method: 'GET', headers: { 'Authorization': `Bearer ${token.access_token}`,