Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions browser_tests/tests/agent/agentPanelMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ export const THINKING_EVENT: AgentWsEvent = {
export const TOOL_CALL_EVENT: AgentWsEvent = {
type: 'agent_tool_call',
data: {
tool_call_id: 'call-set-widget',
tool_name: 'set_widget',
status: 'ok',
args: ['workflow', 'set-widget', 'workflow.json'],
status: 'success',
duration_ms: 1300,
message_id: TURN_ID,
thread_id: THREAD_ID
Expand Down Expand Up @@ -70,9 +70,9 @@ export const RESUMED_THINKING_EVENT: AgentWsEvent = {
export const OPEN_TAB_TOOL_EVENT: AgentWsEvent = {
type: 'agent_tool_call',
data: {
tool_call_id: 'call-new-tab',
tool_name: 'new_tab',
status: 'ok',
args: [],
status: 'success',
duration_ms: 500,
message_id: TURN_ID,
thread_id: THREAD_ID
Expand All @@ -82,9 +82,9 @@ export const OPEN_TAB_TOOL_EVENT: AgentWsEvent = {
export const RESIZE_IMAGE_TOOL_EVENT: AgentWsEvent = {
type: 'agent_tool_call',
data: {
tool_call_id: 'call-resize-image-node',
tool_name: 'resize_image_node',
status: 'ok',
args: [],
status: 'success',
duration_ms: 200,
message_id: TURN_ID,
thread_id: THREAD_ID
Expand Down Expand Up @@ -236,6 +236,7 @@ type AgentFixtures = {

export const agentTest = comfyPageFixture.extend<AgentFixtures>({
agentFlagEnabled: [true, { option: true }],
// oxlint-disable-next-line no-empty-pattern -- Playwright requires an object pattern.
postedMessages: async ({}, use) => {
await use([])
},
Expand Down
4 changes: 2 additions & 2 deletions src/workbench/extensions/agent/AgentPanelRoot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1687,9 +1687,9 @@ describe('AgentPanelRoot transcript copy', () => {
zAgentWsEventForTest({
type: 'agent_tool_call',
data: {
tool_call_id: 'call-add-node',
tool_name: 'add_node',
status: 'ok',
args: [],
status: 'success',
message_id: 'turn-1',
thread_id: 'th-1'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ const delta = (id: string, text: string) =>
const toolCall = (id: string, name: string, status: string) =>
chat({
type: 'agent_tool_call',
data: { tool_name: name, status, args: [], message_id: id, thread_id: 'th' }
data: {
tool_call_id: `call-${name}`,
tool_name: name,
status,
message_id: id,
thread_id: 'th'
}
})
const done = (id: string) =>
chat({
Expand Down Expand Up @@ -95,7 +101,7 @@ describe('ConversationView', () => {
expect(await screen.findByText('pondering')).toBeInTheDocument()

store.ingest(delta('msg-1', 'Here is a **cat**'))
store.ingest(toolCall('msg-1', 'add_node', 'ok'))
store.ingest(toolCall('msg-1', 'add_node', 'success'))
store.ingest(done('msg-1'))

expect(await screen.findByText('make a cat')).toBeInTheDocument()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ describe('AgentMessage thinking narration', () => {
transport.ingest({
type: 'agent_tool_call',
data: {
tool_call_id: 'call-set-widget',
tool_name: 'set_widget',
status: 'ok',
args: [],
status: 'success',
message_id: 'msg-0',
thread_id: 'thread-0'
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
{"capturedAt":1783366827411,"frame":{"type":"status","data":{"status":{"exec_info":{"queue_remaining":0}},"sid":"c3bf440f-8131-481d-b46d-fffbf799d950"}}}
{"capturedAt":1783366879318,"frame":{"data":{"delta":"I'll find the exact widget addresses first, then edit those two values in place.","message_id":"172a6ede-7ab7-4b01-83b6-5b15f66dee4b","thread_id":"d4c016c4-3b8c-44cf-97de-1ae27e43e718"},"type":"agent_thinking"}}
{"capturedAt":1783366881383,"frame":{"data":{"args":["workflow","slots","workflow.json"],"message_id":"172a6ede-7ab7-4b01-83b6-5b15f66dee4b","status":"ok","thread_id":"d4c016c4-3b8c-44cf-97de-1ae27e43e718","tool_name":"list_slots"},"type":"agent_tool_call"}}
{"capturedAt":1783366881382,"frame":{"data":{"message_id":"172a6ede-7ab7-4b01-83b6-5b15f66dee4b","status":"running","thread_id":"d4c016c4-3b8c-44cf-97de-1ae27e43e718","tool_call_id":"call-list-slots","tool_name":"list_slots"},"type":"agent_tool_call"}}
{"capturedAt":1783366881383,"frame":{"data":{"message_id":"172a6ede-7ab7-4b01-83b6-5b15f66dee4b","status":"success","thread_id":"d4c016c4-3b8c-44cf-97de-1ae27e43e718","tool_call_id":"call-list-slots","tool_name":"list_slots"},"type":"agent_tool_call"}}
{"capturedAt":1783366883967,"frame":{"data":{"delta":"Let me get the full slot list to find the exact node addresses.","message_id":"172a6ede-7ab7-4b01-83b6-5b15f66dee4b","thread_id":"d4c016c4-3b8c-44cf-97de-1ae27e43e718"},"type":"agent_thinking"}}
{"capturedAt":1783366884944,"frame":{"data":{"args":["workflow","ls-nodes","workflow.json"],"message_id":"172a6ede-7ab7-4b01-83b6-5b15f66dee4b","status":"ok","thread_id":"d4c016c4-3b8c-44cf-97de-1ae27e43e718","tool_name":"ls_nodes"},"type":"agent_tool_call"}}
{"capturedAt":1783366889506,"frame":{"data":{"args":["workflow","set-widget","workflow.json","--actor","MjVkuhzz6vSuA19LWfBa9lMQdKv2","--base-version","24","--where","cloud","--","1906165638342264.steps","12"],"message_id":"172a6ede-7ab7-4b01-83b6-5b15f66dee4b","status":"ok","thread_id":"d4c016c4-3b8c-44cf-97de-1ae27e43e718","tool_name":"set_widget"},"type":"agent_tool_call"}}
{"capturedAt":1783366891339,"frame":{"data":{"args":["workflow","set-widget","workflow.json","--actor","MjVkuhzz6vSuA19LWfBa9lMQdKv2","--base-version","25","--where","cloud","--","1906165638342264.cfg","6.5"],"message_id":"172a6ede-7ab7-4b01-83b6-5b15f66dee4b","status":"ok","thread_id":"d4c016c4-3b8c-44cf-97de-1ae27e43e718","tool_name":"set_widget"},"type":"agent_tool_call"}}
{"capturedAt":1783366884943,"frame":{"data":{"message_id":"172a6ede-7ab7-4b01-83b6-5b15f66dee4b","status":"running","thread_id":"d4c016c4-3b8c-44cf-97de-1ae27e43e718","tool_call_id":"call-ls-nodes","tool_name":"ls_nodes"},"type":"agent_tool_call"}}
{"capturedAt":1783366884944,"frame":{"data":{"message_id":"172a6ede-7ab7-4b01-83b6-5b15f66dee4b","status":"success","thread_id":"d4c016c4-3b8c-44cf-97de-1ae27e43e718","tool_call_id":"call-ls-nodes","tool_name":"ls_nodes"},"type":"agent_tool_call"}}
{"capturedAt":1783366889505,"frame":{"data":{"message_id":"172a6ede-7ab7-4b01-83b6-5b15f66dee4b","status":"running","thread_id":"d4c016c4-3b8c-44cf-97de-1ae27e43e718","tool_call_id":"call-set-steps","tool_name":"set_widget"},"type":"agent_tool_call"}}
{"capturedAt":1783366889506,"frame":{"data":{"message_id":"172a6ede-7ab7-4b01-83b6-5b15f66dee4b","status":"success","thread_id":"d4c016c4-3b8c-44cf-97de-1ae27e43e718","tool_call_id":"call-set-steps","tool_name":"set_widget"},"type":"agent_tool_call"}}
{"capturedAt":1783366891338,"frame":{"data":{"message_id":"172a6ede-7ab7-4b01-83b6-5b15f66dee4b","status":"running","thread_id":"d4c016c4-3b8c-44cf-97de-1ae27e43e718","tool_call_id":"call-set-cfg","tool_name":"set_widget"},"type":"agent_tool_call"}}
{"capturedAt":1783366891339,"frame":{"data":{"message_id":"172a6ede-7ab7-4b01-83b6-5b15f66dee4b","status":"success","thread_id":"d4c016c4-3b8c-44cf-97de-1ae27e43e718","tool_call_id":"call-set-cfg","tool_name":"set_widget"},"type":"agent_tool_call"}}
{"capturedAt":1783366894953,"frame":{"data":{"delta":"Done — both values updated in place, nothing else touched:\n\n- **Steps:** 20 → **12**\n- **Guidance (CFG):** 7 → **6.5**\n\nThe rest of the graph is unchanged, and I didn't run anything. Let me know when you'd like to generate.","message_id":"172a6ede-7ab7-4b01-83b6-5b15f66dee4b","thread_id":"d4c016c4-3b8c-44cf-97de-1ae27e43e718"},"type":"agent_message_delta"}}
{"capturedAt":1783366894960,"frame":{"data":{"message_id":"172a6ede-7ab7-4b01-83b6-5b15f66dee4b","thread_id":"d4c016c4-3b8c-44cf-97de-1ae27e43e718","usage":{"cache_creation_input_tokens":0,"cache_read_input_tokens":35596,"input_tokens":4493,"output_tokens":425,"total_tokens":4918}},"type":"agent_message_done"}}
36 changes: 35 additions & 1 deletion src/workbench/extensions/agent/schemas/agentApiSchema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ interface RestLine {

describe('agentApiSchema fixture gate', () => {
describe('ws frames: every line is a valid agent event or a recognized-foreign frame', () => {
it('the ws fixture glob finds at least one capture', () => {
expect(wsPaths.length).toBeGreaterThan(0)
})

it.for(wsPaths)('%s', (path) => {
const lines = jsonlLines(path) as WsLine[]
lines.forEach((line, index) => {
Expand Down Expand Up @@ -139,7 +143,7 @@ describe('agentApiSchema contract subtleties', () => {
}
})

it('keeps the retired draft frames foreign to the union', () => {
it('keeps draft frames foreign to this union', () => {
expect(isAgentEvent('draft_patch')).toBe(false)
expect(isAgentEvent('draft_version')).toBe(false)
})
Expand All @@ -159,6 +163,36 @@ describe('agentApiSchema contract subtleties', () => {
expect(parsed.success).toBe(true)
})

it('accepts the canonical tool lifecycle and rejects the legacy shape', () => {
const data = {
tool_call_id: 'call-1',
tool_name: 'add_node',
message_id: 'm1',
thread_id: 't1'
}

for (const status of ['running', 'success', 'error']) {
expect(
zAgentWsEvent.safeParse({
type: 'agent_tool_call',
data: { ...data, status }
}).success
).toBe(true)
}
expect(
zAgentWsEvent.safeParse({
type: 'agent_tool_call',
data: { ...data, tool_call_id: undefined, status: 'success' }
}).success
).toBe(false)
expect(
zAgentWsEvent.safeParse({
type: 'agent_tool_call',
data: { ...data, status: 'success', args: [] }
}).success
).toBe(false)
})

it('exposes exactly the five agent event types', () => {
expect([...AGENT_WS_EVENT_TYPES].sort()).toEqual(
[
Expand Down
6 changes: 4 additions & 2 deletions src/workbench/extensions/agent/schemas/agentApiSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { z } from 'zod'

const zTurnId = z.string().brand<'TurnId'>()
export type TurnId = z.infer<typeof zTurnId>
export const toTurnId = (value: string): TurnId => zTurnId.parse(value)

export const zAgentTurnAccepted = z
.object({
Expand Down Expand Up @@ -81,9 +82,10 @@ const zAgentThinkingData = z

const zAgentToolCallData = z
.object({
tool_call_id: z.string(),
tool_name: z.string(),
status: z.string(),
args: z.array(z.string()),
status: z.enum(['running', 'success', 'error']),
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
args: z.never().optional(),
duration_ms: z.number().optional(),
message_id: z.string(),
thread_id: z.string()
Expand Down
Loading
Loading