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
35 changes: 34 additions & 1 deletion src/workbench/extensions/agent/schemas/agentApiSchema.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, it } from 'vitest'
import { assert, describe, expect, it } from 'vitest'

import {
AGENT_WS_EVENT_TYPES,
Expand Down Expand Up @@ -98,6 +98,39 @@ describe('agentApiSchema contract subtleties', () => {
data: { message_id: 'm1', thread_id: 't1' }
}

it('accepts a null skill on a tool-call frame', () => {
const parsed = zAgentWsEvent.parse({
type: 'agent_tool_call',
data: {
tool_call_id: 'call-1',
tool_name: 'load_skill',
status: 'success',
skill: null,
message_id: 'm1',
thread_id: 't1'
}
})

expect(parsed).toMatchObject({ data: { skill: null } })
})

it('clamps an over-long skill without splitting a Unicode code point', () => {
Comment thread
christian-byrne marked this conversation as resolved.
Resolved
const parsed = zAgentWsEvent.parse({
type: 'agent_tool_call',
data: {
tool_call_id: 'call-1',
tool_name: 'load_skill',
status: 'running',
skill: `${'a'.repeat(255)}😀tail`,
message_id: 'm1',
thread_id: 't1'
}
})

assert(parsed.type === 'agent_tool_call')
expect(parsed.data.skill).toBe(`${'a'.repeat(255)}😀`)
})

it('accepts agent_message_done with usage null (cancelled turn)', () => {
expect(
zAgentWsEvent.safeParse({
Expand Down
18 changes: 17 additions & 1 deletion src/workbench/extensions/agent/schemas/agentApiSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,22 @@ export const zAgentRunMode = zGeneratedAgentRunMode.superRefine(
)
export type AgentRunModeValue = AgentRunModePreference['mode']

const SKILL_NAME_MAX = 256

/**
* Display-only, so an over-long name is clamped instead of dropping its frame.
*/
const zSkillName = z
.string()
.nullish()
.transform((skill) =>
typeof skill === 'string'
? Array.from(skill.slice(0, SKILL_NAME_MAX * 2))
Comment thread
christian-byrne marked this conversation as resolved.
Resolved
.slice(0, SKILL_NAME_MAX)
.join('')
: skill
)

/**
* One entry of a persisted assistant row's `content.tool_calls` (see
* `agentTranscript.ts`'s `parseToolCallEntry`), the reload-path counterpart
Expand Down Expand Up @@ -182,7 +198,7 @@ const zAgentToolCallData = z
tool_call_id: z.string(),
tool_name: z.string(),
status: z.enum(['running', 'success', 'error']),
skill: z.string().optional(),
skill: zSkillName,
args: z.never().optional(),
duration_ms: z.number().optional(),
message_id: z.string(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,23 @@ describe('foldActivity', () => {

expect(rows[0]).toMatchObject({ count: 3, ok: false, state: 'streaming' })
})

it('shows a successful retry as successful', () => {
const rows = foldActivity([
{ ...tool('load_skill', false), skill: 'comfy-director' },
{ ...tool('load_skill', true), skill: 'comfy-director' }
])

expect(rows[0]).toMatchObject({ count: 2, ok: true })
Comment thread
christian-byrne marked this conversation as resolved.
Resolved
})

it('uses the latest outcome across repeated retries', () => {
Comment thread
christian-byrne marked this conversation as resolved.
Resolved
const rows = foldActivity([
{ ...tool('load_skill', true), skill: 'comfy-director' },
{ ...tool('load_skill', false), skill: 'comfy-director' },
{ ...tool('load_skill', true), skill: 'comfy-director' }
])

expect(rows[0]).toMatchObject({ count: 3, ok: true })
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function foldActivity(parts: readonly ActivityPart[]): ActivityRow[] {
if (isSameToolStep(previous, part)) {
previous.count += 1
if (part.state === 'streaming') previous.state = 'streaming'
if (part.ok === false) previous.ok = false
if (part.ok !== undefined) previous.ok = part.ok
Comment thread
christian-byrne marked this conversation as resolved.
Resolved
Comment thread
christian-byrne marked this conversation as resolved.
Resolved
} else {
rows.push({
kind: 'tool',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,38 @@ describe('agentEventTransport text and tool parts', () => {
ok: true
})
})

it.for([
['null', null],
['empty', '']
] as const)(
'preserves a running skill through a %s completion value',
([, skill]) => {
const frame = (status: 'running' | 'success', value: string | null) =>
zAgentWsEvent.parse({
type: 'agent_tool_call',
data: {
tool_call_id: 'call-1',
tool_name: 'load_skill',
status,
skill: value,
message_id: 'm',
thread_id: 't'
}
})

const message = drive([
frame('running', 'comfy-director'),
frame('success', skill)
])

expect(toolParts(message)[0]).toMatchObject({
skill: 'comfy-director',
state: 'done',
ok: true
})
}
)
})

describe('agentEventTransport run approval', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ export interface AgentEventTransport {
dispose: () => void
}

function updateSkill(part: ToolPart, skill: string | undefined): void {
if (skill !== undefined) part.skill = skill
function updateSkill(part: ToolPart, skill: string | null | undefined): void {
if (skill) part.skill = skill
}

export function createAgentEventTransport(
Expand Down
Loading