Skip to content

Commit 7ffc11a

Browse files
v0.5.57: subagents, context menu improvements, bug fixes
2 parents be578e2 + 4941b52 commit 7ffc11a

File tree

113 files changed

+7214
-1982
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+7214
-1982
lines changed

apps/docs/content/docs/en/blocks/router.mdx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
title: Router
33
---
44

5-
import { Callout } from 'fumadocs-ui/components/callout'
65
import { Tab, Tabs } from 'fumadocs-ui/components/tabs'
76
import { Image } from '@/components/ui/image'
87

@@ -102,11 +101,18 @@ Input (Lead) → Router
102101
└── [Self-serve] → Workflow (Automated Onboarding)
103102
```
104103

104+
## Error Handling
105+
106+
When the Router cannot determine an appropriate route for the given context, it will route to the **error path** instead of arbitrarily selecting a route. This happens when:
107+
108+
- The context doesn't clearly match any of the defined route descriptions
109+
- The AI determines that none of the available routes are appropriate
110+
105111
## Best Practices
106112

107113
- **Write clear route descriptions**: Each route description should clearly explain when that route should be selected. Be specific about the criteria.
108114
- **Make routes mutually exclusive**: When possible, ensure route descriptions don't overlap to prevent ambiguous routing decisions.
109-
- **Include an error/fallback route**: Add a catch-all route for unexpected inputs that don't match other routes.
115+
- **Connect an error path**: Handle cases where no route matches by connecting an error handler for graceful fallback behavior.
110116
- **Use descriptive route titles**: Route titles appear in the workflow canvas, so make them meaningful for readability.
111117
- **Test with diverse inputs**: Ensure the Router handles various input types, edge cases, and unexpected content.
112118
- **Monitor routing performance**: Review routing decisions regularly and refine route descriptions based on actual usage patterns.

apps/sim/app/api/copilot/chat/route.ts

Lines changed: 17 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -802,49 +802,29 @@ export async function POST(req: NextRequest) {
802802
toolNames: toolCalls.map((tc) => tc?.name).filter(Boolean),
803803
})
804804

805-
// Save messages to database after streaming completes (including aborted messages)
805+
// NOTE: Messages are saved by the client via update-messages endpoint with full contentBlocks.
806+
// Server only updates conversationId here to avoid overwriting client's richer save.
806807
if (currentChat) {
807-
const updatedMessages = [...conversationHistory, userMessage]
808-
809-
// Save assistant message if there's any content or tool calls (even partial from abort)
810-
if (assistantContent.trim() || toolCalls.length > 0) {
811-
const assistantMessage = {
812-
id: crypto.randomUUID(),
813-
role: 'assistant',
814-
content: assistantContent,
815-
timestamp: new Date().toISOString(),
816-
...(toolCalls.length > 0 && { toolCalls }),
817-
}
818-
updatedMessages.push(assistantMessage)
819-
logger.info(
820-
`[${tracker.requestId}] Saving assistant message with content (${assistantContent.length} chars) and ${toolCalls.length} tool calls`
821-
)
822-
} else {
823-
logger.info(
824-
`[${tracker.requestId}] No assistant content or tool calls to save (aborted before response)`
825-
)
826-
}
827-
828808
// Persist only a safe conversationId to avoid continuing from a state that expects tool outputs
829809
const previousConversationId = currentChat?.conversationId as string | undefined
830810
const responseId = lastSafeDoneResponseId || previousConversationId || undefined
831811

832-
// Update chat in database immediately (without title)
833-
await db
834-
.update(copilotChats)
835-
.set({
836-
messages: updatedMessages,
837-
updatedAt: new Date(),
838-
...(responseId ? { conversationId: responseId } : {}),
839-
})
840-
.where(eq(copilotChats.id, actualChatId!))
812+
if (responseId) {
813+
await db
814+
.update(copilotChats)
815+
.set({
816+
updatedAt: new Date(),
817+
conversationId: responseId,
818+
})
819+
.where(eq(copilotChats.id, actualChatId!))
841820

842-
logger.info(`[${tracker.requestId}] Updated chat ${actualChatId} with new messages`, {
843-
messageCount: updatedMessages.length,
844-
savedUserMessage: true,
845-
savedAssistantMessage: assistantContent.trim().length > 0,
846-
updatedConversationId: responseId || null,
847-
})
821+
logger.info(
822+
`[${tracker.requestId}] Updated conversationId for chat ${actualChatId}`,
823+
{
824+
updatedConversationId: responseId,
825+
}
826+
)
827+
}
848828
}
849829
} catch (error) {
850830
logger.error(`[${tracker.requestId}] Error processing stream:`, error)

apps/sim/app/api/copilot/chat/update-messages/route.ts

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,30 @@ const logger = createLogger('CopilotChatUpdateAPI')
1717
const UpdateMessagesSchema = z.object({
1818
chatId: z.string(),
1919
messages: z.array(
20-
z.object({
21-
id: z.string(),
22-
role: z.enum(['user', 'assistant']),
23-
content: z.string(),
24-
timestamp: z.string(),
25-
toolCalls: z.array(z.any()).optional(),
26-
contentBlocks: z.array(z.any()).optional(),
27-
fileAttachments: z
28-
.array(
29-
z.object({
30-
id: z.string(),
31-
key: z.string(),
32-
filename: z.string(),
33-
media_type: z.string(),
34-
size: z.number(),
35-
})
36-
)
37-
.optional(),
38-
})
20+
z
21+
.object({
22+
id: z.string(),
23+
role: z.enum(['user', 'assistant', 'system']),
24+
content: z.string(),
25+
timestamp: z.string(),
26+
toolCalls: z.array(z.any()).optional(),
27+
contentBlocks: z.array(z.any()).optional(),
28+
fileAttachments: z
29+
.array(
30+
z.object({
31+
id: z.string(),
32+
key: z.string(),
33+
filename: z.string(),
34+
media_type: z.string(),
35+
size: z.number(),
36+
})
37+
)
38+
.optional(),
39+
contexts: z.array(z.any()).optional(),
40+
citations: z.array(z.any()).optional(),
41+
errorType: z.string().optional(),
42+
})
43+
.passthrough() // Preserve any additional fields for future compatibility
3944
),
4045
planArtifact: z.string().nullable().optional(),
4146
config: z
@@ -57,8 +62,33 @@ export async function POST(req: NextRequest) {
5762
}
5863

5964
const body = await req.json()
65+
66+
// Debug: Log what we received
67+
const lastMsg = body.messages?.[body.messages.length - 1]
68+
if (lastMsg?.role === 'assistant') {
69+
logger.info(`[${tracker.requestId}] Received messages to save`, {
70+
messageCount: body.messages?.length,
71+
lastMsgId: lastMsg.id,
72+
lastMsgContentLength: lastMsg.content?.length || 0,
73+
lastMsgContentBlockCount: lastMsg.contentBlocks?.length || 0,
74+
lastMsgContentBlockTypes: lastMsg.contentBlocks?.map((b: any) => b?.type) || [],
75+
})
76+
}
77+
6078
const { chatId, messages, planArtifact, config } = UpdateMessagesSchema.parse(body)
6179

80+
// Debug: Log what we're about to save
81+
const lastMsgParsed = messages[messages.length - 1]
82+
if (lastMsgParsed?.role === 'assistant') {
83+
logger.info(`[${tracker.requestId}] Parsed messages to save`, {
84+
messageCount: messages.length,
85+
lastMsgId: lastMsgParsed.id,
86+
lastMsgContentLength: lastMsgParsed.content?.length || 0,
87+
lastMsgContentBlockCount: lastMsgParsed.contentBlocks?.length || 0,
88+
lastMsgContentBlockTypes: lastMsgParsed.contentBlocks?.map((b: any) => b?.type) || [],
89+
})
90+
}
91+
6292
// Verify that the chat belongs to the user
6393
const [chat] = await db
6494
.select()

apps/sim/app/api/copilot/context-usage/route.ts

Lines changed: 0 additions & 134 deletions
This file was deleted.

apps/sim/app/playground/page.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -462,9 +462,6 @@ export default function PlaygroundPage() {
462462
<Avatar size='lg'>
463463
<AvatarFallback>LG</AvatarFallback>
464464
</Avatar>
465-
<Avatar size='xl'>
466-
<AvatarFallback>XL</AvatarFallback>
467-
</Avatar>
468465
</VariantRow>
469466
<VariantRow label='with image'>
470467
<Avatar size='md'>
@@ -505,9 +502,6 @@ export default function PlaygroundPage() {
505502
<Avatar size='lg' status='online'>
506503
<AvatarFallback>LG</AvatarFallback>
507504
</Avatar>
508-
<Avatar size='xl' status='online'>
509-
<AvatarFallback>XL</AvatarFallback>
510-
</Avatar>
511505
</VariantRow>
512506
</Section>
513507

apps/sim/app/workspace/[workspaceId]/utils/commands-utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type { GlobalCommand } from '@/app/workspace/[workspaceId]/providers/glob
77
* ad-hoc ids or shortcuts to ensure a single source of truth.
88
*/
99
export type CommandId =
10+
| 'accept-diff-changes'
1011
| 'add-agent'
1112
| 'goto-templates'
1213
| 'goto-logs'
@@ -43,6 +44,11 @@ export interface CommandDefinition {
4344
* All global commands must be declared here to be usable.
4445
*/
4546
export const COMMAND_DEFINITIONS: Record<CommandId, CommandDefinition> = {
47+
'accept-diff-changes': {
48+
id: 'accept-diff-changes',
49+
shortcut: 'Mod+Shift+Enter',
50+
allowInEditable: true,
51+
},
4652
'add-agent': {
4753
id: 'add-agent',
4854
shortcut: 'Mod+Shift+A',

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/command-list/command-list.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
import { useCallback } from 'react'
44
import { createLogger } from '@sim/logger'
5-
import { Layout, LibraryBig, Search } from 'lucide-react'
5+
import { Layout, Search } from 'lucide-react'
66
import Image from 'next/image'
77
import { useParams, useRouter } from 'next/navigation'
8-
import { Button } from '@/components/emcn'
8+
import { Button, Library } from '@/components/emcn'
99
import { AgentIcon } from '@/components/icons'
1010
import { cn } from '@/lib/core/utils/cn'
1111
import { usePreventZoom } from '@/app/workspace/[workspaceId]/w/[workflowId]/hooks'
@@ -41,7 +41,7 @@ const commands: CommandItem[] = [
4141
},
4242
{
4343
label: 'Logs',
44-
icon: LibraryBig,
44+
icon: Library,
4545
shortcut: 'L',
4646
},
4747
{

0 commit comments

Comments
 (0)