@yuriai/web 0.2.8-beta.1 → 0.2.8-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AgentAvatar-MzDm6uBf.js → AgentAvatar--DsfGfhZ.js} +1 -1
- package/dist/assets/{AssistantView-Df-G2DX8.js → AssistantView-Bf19-qvJ.js} +3 -3
- package/dist/assets/{DiagramView-BoVqJRQb.js → DiagramView-UvYyjtWA.js} +1 -1
- package/dist/assets/{FadeInOnReveal-DkmfVoTO.js → FadeInOnReveal-NAFOww9Y.js} +1 -1
- package/dist/assets/{GuiPluginSurface-DxLoeTDb.js → GuiPluginSurface-DNzJNcMh.js} +1 -1
- package/dist/assets/{GuiPluginWindow-dDG5Uyqb.js → GuiPluginWindow-C73klYx3.js} +1 -1
- package/dist/assets/{Icon-BjiyvtB2.js → Icon-Cy25fgQb.js} +1 -1
- package/dist/assets/{ImageLoadingPlaceholder-CUKFQTAG.js → ImageLoadingPlaceholder-DGRjdn_K.js} +1 -1
- package/dist/assets/{LoadingImage-B7cT_4Oe.js → LoadingImage-2pPdTFHh.js} +1 -1
- package/dist/assets/{MarkdownRenderer-DYi_qpYy.js → MarkdownRenderer-GuwP9qiJ.js} +2 -2
- package/dist/assets/{MarkdownRendererImpl-CMxRMFqp.js → MarkdownRendererImpl-tHItN1IG.js} +1 -1
- package/dist/assets/{MarkstreamRendererImpl-DQ4urBZW.js → MarkstreamRendererImpl-Dh13e1UE.js} +1 -1
- package/dist/assets/{MobileDetailNavigation-C4fJlKdu.js → MobileDetailNavigation-CSxBgVuQ.js} +1 -1
- package/dist/assets/{MobileResizableSheet-C9YzOQis.js → MobileResizableSheet-BN07cmQQ.js} +1 -1
- package/dist/assets/{MobileShareBridge-DLC-TdRy.js → MobileShareBridge-7SAELdqu.js} +1 -1
- package/dist/assets/MobileTabPageHeader-Bbb36BtD.js +2 -0
- package/dist/assets/{MultiRunWindow-Cwp8-_Wh.js → MultiRunWindow-DbI9KTph.js} +1 -1
- package/dist/assets/{OnboardingScreen-D6iQ5qjF.js → OnboardingScreen-rp0qwvgz.js} +1 -1
- package/dist/assets/{OverlayScrollbar-Dbx1atD-.js → OverlayScrollbar-B--v-oQW.js} +1 -1
- package/dist/assets/{SettingsView-CYDk0wpN.js → SettingsView-C1AQoEIQ.js} +1 -1
- package/dist/assets/{SettingsWindow-Vuzphf9b.js → SettingsWindow-6M0ssWHM.js} +1 -1
- package/dist/assets/{TerminalView-Dhalx6_Z.js → TerminalView-bhL6Ccen.js} +1 -1
- package/dist/assets/{ToolOutputDialog-DBxSxWNh.js → ToolOutputDialog-BaLKI3Yc.js} +1 -1
- package/dist/assets/{YuriLogo-DvRSd5NN.js → YuriLogo-kwLWc5Hi.js} +1 -1
- package/dist/assets/{appThemeRegistry-JEhMXHGF.js → appThemeRegistry-Bk_N8btz.js} +1 -1
- package/dist/assets/{button-BSFWH-Ok.js → button-Dodw6LWV.js} +1 -1
- package/dist/assets/{capgoAdapter-BgD0wyhC.js → capgoAdapter-DqHX7fkj.js} +1 -1
- package/dist/assets/{collapsible-DaevjAvt.js → collapsible-C9kOfVDe.js} +1 -1
- package/dist/assets/{diagram-7OgmyecX.js → diagram-CfBQ9Icg.js} +1 -1
- package/dist/assets/{dialog-D1pXn_b9.js → dialog-D0bq7nr2.js} +1 -1
- package/dist/assets/{dropdown-menu.styles-CGHPvEgD.js → dropdown-menu.styles-CLxDPSrk.js} +1 -1
- package/dist/assets/{es-DJzbuYpv.js → es-Diy_UpPF.js} +1 -1
- package/dist/assets/{fileMentionTouchSelection-BQdfRBkk.js → fileMentionTouchSelection-C16Q21Ht.js} +1 -1
- package/dist/assets/{fr-YDYbYIZQ.js → fr-CPRTMaky.js} +1 -1
- package/dist/assets/{gitApi-DhDVqj9b.js → gitApi-_yKaBF0a.js} +1 -1
- package/dist/assets/{input-BhHXFla6.js → input-HddqDhRi.js} +1 -1
- package/dist/assets/{insertionBoundaries-BMe1F3uB.js → insertionBoundaries-CHqJLwJg.js} +1 -1
- package/dist/assets/{ja-SjX3NBJz.js → ja-Cc1jn0Ag.js} +1 -1
- package/dist/assets/{ko-BxcUEWjB.js → ko-CfHUuNNe.js} +1 -1
- package/dist/assets/{main-DXlMu2LF.js → main-Bja5DG1P.js} +2 -2
- package/dist/assets/{main-CfOYzhn0.js → main-njE9rVzm.js} +4 -4
- package/dist/assets/{markdownHeightCache-DV2j4PlS.js → markdownHeightCache-BQiIj0aM.js} +1 -1
- package/dist/assets/{mcpQueries-vxcQAIGB.js → mcpQueries-uM1Chfdc.js} +1 -1
- package/dist/assets/{miniChat-D48iGEEW.js → miniChat-DAwBa-3U.js} +2 -2
- package/dist/assets/{mobile-Cy5qSiDY.js → mobile-BQmrdXmD.js} +2 -2
- package/dist/assets/{mobileBackNavigation-QtBK9OSb.js → mobileBackNavigation-DsU3qQ8W.js} +1 -1
- package/dist/assets/{multirun-BR9a6EBo.js → multirun-DRL1Wf-K.js} +1 -1
- package/dist/assets/{native-config-CHySeHif.js → native-config-BMflOjo8.js} +1 -1
- package/dist/assets/{pl-vh0XFuDb.js → pl-mUyhvp8O.js} +1 -1
- package/dist/assets/{projectMeta-Bn2vBNDe.js → projectMeta-DK-kl6vM.js} +1 -1
- package/dist/assets/{pt-BR-Cv5tssQz.js → pt-BR-D3E4Wxao.js} +1 -1
- package/dist/assets/{readiness-BAssoNVf.js → readiness-CMHDs1YN.js} +1 -1
- package/dist/assets/{renderElectronMiniChatApp-B9Kci_8q.js → renderElectronMiniChatApp-CkSP0eQz.js} +2 -2
- package/dist/assets/{renderMobileApp-CBivL8Ps.js → renderMobileApp-wELnHLDT.js} +4 -4
- package/dist/assets/{runtimeConfig-COdEwlK-.js → runtimeConfig-KpW0l510.js} +1 -1
- package/dist/assets/{runtimeEndpointReset-D3x76Qpf.js → runtimeEndpointReset-BBxpXfkE.js} +3 -3
- package/dist/assets/{scheduledTaskNavigation-BZ3B5bpN.js → scheduledTaskNavigation-CyPkVBKs.js} +1 -1
- package/dist/assets/{sessionChangeSummary-Dtgq0CWg.js → sessionChangeSummary-Bb7dqAie.js} +1 -1
- package/dist/assets/{sessionLookup--Wlr3e8X.js → sessionLookup-D_P3C7rX.js} +1 -1
- package/dist/assets/{sortable-tabs-strip-BnTV_KYG.js → sortable-tabs-strip-C-qSUWlr.js} +1 -1
- package/dist/assets/{speechSettingsQueries-D3fc_4Iy.js → speechSettingsQueries-BSBjx3wG.js} +1 -1
- package/dist/assets/src-CbY9YJrh.css +2 -0
- package/dist/assets/{store-CgQdmzpX.js → store-FxBFwq--.js} +2 -2
- package/dist/assets/{textarea-Deh9E1KP.js → textarea-BvfW0tsL.js} +1 -1
- package/dist/assets/{tooltip-DygQ-2xe.js → tooltip-BmKpb74n.js} +1 -1
- package/dist/assets/{types-D8_26ZKT.js → types-rJezumB4.js} +1 -1
- package/dist/assets/{uk-3a9vdLJ-.js → uk-D9iQbGbr.js} +1 -1
- package/dist/assets/{useAppFontEffects-DLT9jVl1.js → useAppFontEffects-DZ1W3_cy.js} +5 -5
- package/dist/assets/{useDesktopWindowControlsLayout-BNAZWH9L.js → useDesktopWindowControlsLayout-D_1DLCOD.js} +1 -1
- package/dist/assets/{useEffectiveDirectory-D2_-KCB7.js → useEffectiveDirectory-joUiryc3.js} +1 -1
- package/dist/assets/{useMobileNavigationStore-DJwk64Po.js → useMobileNavigationStore-BaQ7TIpx.js} +6 -6
- package/dist/assets/{useWorkerHighlightedLines-k48txabk.js → useWorkerHighlightedLines-CiU1xPjX.js} +1 -1
- package/dist/assets/{zh-CN-kwaUr5W5.js → zh-CN-mNVX6pMK.js} +1 -1
- package/dist/assets/{zh-TW-BBs44W7l.js → zh-TW-B7T0e-Qv.js} +1 -1
- package/dist/index.html +6 -6
- package/dist/mini-chat.html +6 -6
- package/dist/mobile.html +6 -6
- package/package.json +1 -1
- package/server/lib/assistants/DOCUMENTATION.md +18 -15
- package/server/lib/assistants/bubbles.js +0 -14
- package/server/lib/assistants/bubbles.test.js +1 -18
- package/server/lib/assistants/contact-tools.js +179 -211
- package/server/lib/assistants/contact-tools.test.js +35 -161
- package/server/lib/assistants/harness.js +76 -238
- package/server/lib/assistants/harness.test.js +255 -279
- package/server/lib/assistants/memory.http.test.js +2 -2
- package/server/lib/assistants/pi-tools.js +1 -54
- package/server/lib/assistants/pi-tools.test.js +5 -9
- package/server/lib/assistants/routes.js +1 -0
- package/server/lib/assistants/service.js +66 -1
- package/server/lib/assistants/service.test.js +60 -42
- package/server/lib/llm/DOCUMENTATION.md +3 -0
- package/server/lib/llm/completions.js +2 -1
- package/server/lib/llm/completions.test.js +9 -0
- package/server/lib/opencode/feature-routes-runtime.js +1 -0
- package/server/lib/scheduled-tasks/runtime.test.js +3 -3
- package/dist/assets/MobileTabPageHeader-CMbbtHh7.js +0 -2
- package/dist/assets/src-NlrSCyPZ.css +0 -2
|
@@ -20,7 +20,69 @@ import { PI_CODING_TOOL_NAMES } from './pi-tools.js'
|
|
|
20
20
|
import { createChatCompletion as gatewayCompletion } from '../llm/completions.js'
|
|
21
21
|
import { generateOpenCodeText } from '../llm/generate.js'
|
|
22
22
|
|
|
23
|
+
const nativeToolCall = (name, args = {}, id = `call_${name}`) => ({ id, type: 'function', function: { name, arguments: JSON.stringify(args) } })
|
|
24
|
+
const toolBatch = (calls, content = '') => ({ completion: { choices: [{ message: { content, tool_calls: calls.map(([name, args, id]) => nativeToolCall(name, args, id)) } }] } })
|
|
25
|
+
const toolCall = (name, args, id) => toolBatch([[name, args, id]])
|
|
26
|
+
const notifyCall = (text, id) => ['notify_user', { text }, id]
|
|
27
|
+
|
|
23
28
|
describe('createContactStreamFn', () => {
|
|
29
|
+
it('offers scheduled-task lookup but no mutation or shell tools in read-only turns', async () => {
|
|
30
|
+
const seen = [];
|
|
31
|
+
const tools = createContactTools({ listScheduledTasks: vi.fn(), updateScheduledTask: vi.fn() });
|
|
32
|
+
await runContactTurn({ assistant: { providerID: 'p', modelID: 'm' }, history: [], userText: '后台复盘', tools, readOnly: true,
|
|
33
|
+
createChatCompletion: async ({ body }) => { seen.push(...body.tools.map(tool => tool.function.name)); return { text: '已检查。' }; },
|
|
34
|
+
});
|
|
35
|
+
expect(seen).toContain('list_scheduled_tasks');
|
|
36
|
+
expect(seen).not.toContain('update_scheduled_task');
|
|
37
|
+
expect(seen).not.toContain('bash');
|
|
38
|
+
});
|
|
39
|
+
it('runs scheduled-task listing and updating through native schemas and the real pi loop', async () => {
|
|
40
|
+
const listScheduledTasks = vi.fn(async () => ({ tasks: [{ id: 'task1', projectID: 'project1' }] }));
|
|
41
|
+
const updateScheduledTask = vi.fn(async () => ({ task: { id: 'task1', name: 'Task', schedule: { kind: 'daily', times: ['09:00'] }, execution: { providerID: 'p', modelID: 'm' } } }));
|
|
42
|
+
const tools = createContactTools({ listScheduledTasks, updateScheduledTask });
|
|
43
|
+
let round = 0;
|
|
44
|
+
const completion = input => gatewayCompletion({ ...input,
|
|
45
|
+
loadCatalog: async () => ({ models: [{ providerID: 'p', modelID: 'm' }] }),
|
|
46
|
+
generateText: async ({ messages, tools: schemas }) => {
|
|
47
|
+
expect(schemas.map(tool => tool.name)).toEqual(expect.arrayContaining(['list_scheduled_tasks', 'update_scheduled_task']));
|
|
48
|
+
round++;
|
|
49
|
+
if (round === 1) return { text: '', toolCalls: [{ id: 'list1', name: 'list_scheduled_tasks', arguments: {} }] };
|
|
50
|
+
expect(messages.some(message => message.role === 'tool' && message.tool_call_id === 'list1')).toBe(true);
|
|
51
|
+
if (round === 2) return { text: '', toolCalls: [{ id: 'update1', name: 'update_scheduled_task', arguments: { taskID: 'task1', projectID: 'project1', model: 'p/m' } }] };
|
|
52
|
+
return { text: '任务已更新。', toolCalls: [] };
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
const result = await runContactTurn({ assistant: { providerID: 'p', modelID: 'm' }, history: [], userText: '修改定时任务的模型', tools, createChatCompletion: completion });
|
|
56
|
+
expect(result.text).toBe('任务已更新。');
|
|
57
|
+
expect(listScheduledTasks).toHaveBeenCalledTimes(1);
|
|
58
|
+
expect(updateScheduledTask).toHaveBeenCalledExactlyOnceWith({ taskID: 'task1', projectID: 'project1', model: 'p/m' });
|
|
59
|
+
expect(round).toBe(3);
|
|
60
|
+
});
|
|
61
|
+
it('normalizes native shell aliases through the production gateway and preserves call identity', async () => {
|
|
62
|
+
const completion = input => gatewayCompletion({ ...input,
|
|
63
|
+
loadCatalog: async () => ({ models: [{ providerID: 'p', modelID: 'm' }] }),
|
|
64
|
+
generateText: async () => ({ text: '', toolCalls: [{ id: 'native_alias', name: 'grep', arguments: { pattern: 'needle', path: 'src' } }] }),
|
|
65
|
+
});
|
|
66
|
+
const result = await createContactStreamFn(completion)(
|
|
67
|
+
{ name: 'p/m', id: 'm', provider: 'yuri', api: 'openai-completions' },
|
|
68
|
+
{ messages: [{ role: 'user', content: 'Find needle in src' }], tools: [{ name: 'bash', parameters: { type: 'object', properties: { command: { type: 'string' } } } }] },
|
|
69
|
+
).result();
|
|
70
|
+
expect(result.content.at(-1)).toMatchObject({ type: 'toolCall', id: 'native_alias', name: 'bash', arguments: { command: expect.stringContaining("-e 'needle' 'src'") } });
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('corrects unavailable native tools with actionable tool names', async () => {
|
|
74
|
+
const completion = vi.fn()
|
|
75
|
+
.mockResolvedValueOnce({ completion: { choices: [{ message: { content: '', tool_calls: [{ id: 'bad', function: { name: 'list_cron', arguments: '{}' } }] } }] } })
|
|
76
|
+
.mockResolvedValueOnce({ completion: { choices: [{ message: { content: '', tool_calls: [{ id: 'good', function: { name: 'list_scheduled_tasks', arguments: '{}' } }] } }] } });
|
|
77
|
+
const result = await createContactStreamFn(completion)(
|
|
78
|
+
{ name: 'p/m', id: 'm', provider: 'yuri', api: 'openai-completions' },
|
|
79
|
+
{ messages: [], tools: [{ name: 'list_scheduled_tasks' }] },
|
|
80
|
+
).result();
|
|
81
|
+
expect(completion).toHaveBeenCalledTimes(2);
|
|
82
|
+
expect(JSON.stringify(completion.mock.calls[1][0].body.messages)).toContain('list_cron');
|
|
83
|
+
expect(JSON.stringify(completion.mock.calls[1][0].body.messages)).toContain('list_scheduled_tasks');
|
|
84
|
+
expect(result.content.at(-1)).toMatchObject({ type: 'toolCall', id: 'good', name: 'list_scheduled_tasks' });
|
|
85
|
+
});
|
|
24
86
|
it('continues eight real Agent tool rounds through gateway recovery without replaying completed tools', async () => {
|
|
25
87
|
vi.useFakeTimers()
|
|
26
88
|
try {
|
|
@@ -38,7 +100,7 @@ describe('createContactStreamFn', () => {
|
|
|
38
100
|
if ((index === 3 && attempt <= 9) || (index === 4 && attempt <= 3)) return { text: '' }
|
|
39
101
|
return index <= 8
|
|
40
102
|
? { text: '', toolCalls: [{ id: `call_${index}`, name: 'get_assistant_settings', arguments: {} }], finishReason: 'tool-calls' }
|
|
41
|
-
: { text: '
|
|
103
|
+
: { text: 'Verified all eight steps.', toolCalls: [], finishReason: 'stop' }
|
|
42
104
|
})
|
|
43
105
|
const completion = (input) => gatewayCompletion({
|
|
44
106
|
...input, buildOpenCodeUrl: () => 'http://127.0.0.1:4096', getOpenCodeAuthHeaders: () => ({}),
|
|
@@ -62,7 +124,7 @@ describe('createContactStreamFn', () => {
|
|
|
62
124
|
const onBubbleDelta = vi.fn();
|
|
63
125
|
const completion = vi.fn(async ({ onTextDelta }) => {
|
|
64
126
|
onTextDelta('Private reasoning');
|
|
65
|
-
return { text: '
|
|
127
|
+
return { text: '已完成。' };
|
|
66
128
|
});
|
|
67
129
|
const result = await runContactTurn({
|
|
68
130
|
assistant: { providerID: 'p', modelID: 'm', variant: 'high' },
|
|
@@ -78,30 +140,23 @@ describe('createContactStreamFn', () => {
|
|
|
78
140
|
expect(JSON.stringify(onBubbleDelta.mock.calls)).not.toContain('Private reasoning');
|
|
79
141
|
});
|
|
80
142
|
|
|
81
|
-
it('publishes
|
|
82
|
-
let release;
|
|
83
|
-
const gate = new Promise((resolve) => { release = resolve })
|
|
143
|
+
it('publishes notify_user text before the tool executes and keeps narration beside it private', async () => {
|
|
84
144
|
const onBubbleDelta = vi.fn()
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
await gate
|
|
90
|
-
onTextDelta(tool)
|
|
91
|
-
return { text: prefix + tool }
|
|
92
|
-
})
|
|
145
|
+
const createChatCompletion = vi.fn(async () => toolBatch([
|
|
146
|
+
notifyCall('我先检查配置,再保存这次修改。'),
|
|
147
|
+
['read', { path: 'config.json' }, 'call_read'],
|
|
148
|
+
], 'I will plan the read privately.'))
|
|
93
149
|
const stream = createContactStreamFn(createChatCompletion, { onBubbleDelta })(
|
|
94
150
|
{ name: 'p/m', id: 'm', provider: 'yuri', api: 'openai-completions' },
|
|
95
|
-
{ messages: [], tools: [{ name: 'read' }] },
|
|
151
|
+
{ messages: [], tools: [{ name: 'read' }, { name: 'notify_user' }] },
|
|
96
152
|
)
|
|
97
|
-
try {
|
|
98
|
-
await vi.waitFor(() => expect(onBubbleDelta).toHaveBeenCalledWith(0, '我先检查配置,再保存这次修改。', true))
|
|
99
|
-
expect(onBubbleDelta).toHaveBeenCalledTimes(1)
|
|
100
|
-
} finally { release() }
|
|
101
153
|
const result = await stream.result()
|
|
154
|
+
expect(onBubbleDelta.mock.calls).toEqual([[0, '我先检查配置,再保存这次修改。', true]])
|
|
102
155
|
expect(projectStreamedContactTurnBubbles([result])).toEqual(['我先检查配置,再保存这次修改。'])
|
|
103
|
-
|
|
104
|
-
expect(
|
|
156
|
+
// Batched notes are delivered by the stream, so only the operation executes.
|
|
157
|
+
expect(result.content.filter((part) => part.type === 'toolCall')).toEqual([expect.objectContaining({ id: 'call_read', name: 'read' })])
|
|
158
|
+
expect(result.contactPublicText).toBe(true)
|
|
159
|
+
expect(JSON.stringify(result.content)).not.toContain('plan the read privately')
|
|
105
160
|
})
|
|
106
161
|
|
|
107
162
|
it('keeps raw tokens, reasoning, partial public records and nested tool examples private', async () => {
|
|
@@ -127,9 +182,9 @@ describe('createContactStreamFn', () => {
|
|
|
127
182
|
const result = body.messages.find((m) => m.role === 'tool' && m.name === 'update_default_prompt')
|
|
128
183
|
if (result) {
|
|
129
184
|
expect(result.content).toContain('Default prompt saved.')
|
|
130
|
-
return { text: '
|
|
185
|
+
return { text: '提示词已保存,接下来的对话会按这个设置回复。' }
|
|
131
186
|
}
|
|
132
|
-
return
|
|
187
|
+
return toolBatch([notifyCall('我来保存这个默认提示词。'), ['update_default_prompt', { prompt: '简洁回复' }]])
|
|
133
188
|
})
|
|
134
189
|
const onBubbleDelta = vi.fn()
|
|
135
190
|
const result = await runContactTurn({
|
|
@@ -142,62 +197,53 @@ describe('createContactStreamFn', () => {
|
|
|
142
197
|
expect(result.text).not.toContain('Default prompt saved.')
|
|
143
198
|
})
|
|
144
199
|
|
|
145
|
-
it('preserves a published
|
|
200
|
+
it('preserves a published note on abort and suppresses later notes and tools', async () => {
|
|
146
201
|
const controller = new AbortController()
|
|
147
202
|
const onBubbleDelta = vi.fn()
|
|
148
|
-
const
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
{
|
|
157
|
-
|
|
158
|
-
|
|
203
|
+
const updateAssistantSettings = vi.fn()
|
|
204
|
+
const createChatCompletion = vi.fn()
|
|
205
|
+
.mockResolvedValueOnce(toolBatch([notifyCall('我先确认设置。'), ['get_assistant_settings', {}]]))
|
|
206
|
+
.mockImplementationOnce(async () => {
|
|
207
|
+
controller.abort()
|
|
208
|
+
return toolBatch([notifyCall('这条迟到消息应丢弃。'), ['update_default_prompt', { prompt: 'late' }]])
|
|
209
|
+
})
|
|
210
|
+
await expect(runContactTurn({
|
|
211
|
+
assistant: { providerID: 'p', modelID: 'm' }, history: [], userText: '确认设置',
|
|
212
|
+
tools: createContactTools({ readAssistantSettings: async () => ({ id: 'a', name: 'A', defaultPrompt: '' }), updateAssistantSettings, currentAssistant: { id: 'a', name: 'A' } }),
|
|
213
|
+
createChatCompletion, onBubbleDelta, signal: controller.signal,
|
|
214
|
+
})).rejects.toMatchObject({ name: 'AbortError' })
|
|
215
|
+
expect(createChatCompletion).toHaveBeenCalledTimes(2)
|
|
216
|
+
expect(updateAssistantSettings).not.toHaveBeenCalled()
|
|
159
217
|
expect(onBubbleDelta.mock.calls).toEqual([[0, '我先确认设置。', true]])
|
|
160
218
|
})
|
|
161
219
|
|
|
162
|
-
it('
|
|
163
|
-
const onBubbleDelta = vi.fn()
|
|
164
|
-
const prefix = '```yuri-message\n{"text":"先确认一下。"}\n```\n'
|
|
165
|
-
const stream = createContactStreamFn(async ({ onTextDelta }) => {
|
|
166
|
-
onTextDelta(prefix.slice(0, 30))
|
|
167
|
-
return { text: prefix + '结果已确认。' }
|
|
168
|
-
}, { onBubbleDelta })(
|
|
169
|
-
{ name: 'p/m', id: 'm', provider: 'yuri', api: 'openai-completions' }, { messages: [] },
|
|
170
|
-
)
|
|
171
|
-
expect((await stream.result()).stopReason).toBe('stop')
|
|
172
|
-
expect(onBubbleDelta.mock.calls).toEqual([[0, '先确认一下。', true], [1, '结果已确认。', true]])
|
|
173
|
-
})
|
|
174
|
-
|
|
175
|
-
it('preserves delivered public messages across a protocol correction without replaying rejected prose', async () => {
|
|
220
|
+
it('never publishes or replays a rejected response across a protocol correction', async () => {
|
|
176
221
|
const onBubbleDelta = vi.fn()
|
|
177
222
|
const completion = vi.fn()
|
|
178
|
-
.mockResolvedValueOnce(
|
|
179
|
-
.mockResolvedValueOnce({ text: '
|
|
223
|
+
.mockResolvedValueOnce(toolBatch([notifyCall('我先检查配置。'), ['list_cron', {}]], 'I need to plan privately.'))
|
|
224
|
+
.mockResolvedValueOnce({ text: '请提供配置文件位置。' })
|
|
180
225
|
const stream = createContactStreamFn(completion, { onBubbleDelta })(
|
|
181
226
|
{ name: 'p/m', id: 'm', provider: 'yuri', api: 'openai-completions' },
|
|
182
|
-
{ messages: [], tools: [{ name: 'read' }] },
|
|
227
|
+
{ messages: [], tools: [{ name: 'read' }, { name: 'notify_user' }] },
|
|
183
228
|
)
|
|
184
229
|
const result = await stream.result()
|
|
185
|
-
expect(projectStreamedContactTurnBubbles([result])).toEqual(['
|
|
186
|
-
expect(onBubbleDelta.mock.calls).toEqual([[0, '
|
|
187
|
-
|
|
188
|
-
expect(
|
|
230
|
+
expect(projectStreamedContactTurnBubbles([result])).toEqual(['请提供配置文件位置。'])
|
|
231
|
+
expect(onBubbleDelta.mock.calls).toEqual([[0, '请提供配置文件位置。', true]])
|
|
232
|
+
const repair = JSON.stringify(completion.mock.calls[1][0].body)
|
|
233
|
+
expect(repair).toContain('Yuri response protocol correction')
|
|
234
|
+
expect(repair).not.toContain('I need to plan privately.')
|
|
235
|
+
expect(repair).not.toContain('我先检查配置。')
|
|
189
236
|
})
|
|
190
237
|
|
|
191
|
-
it.each([
|
|
238
|
+
it.each([{ text: 42 }, { text: '' }, { text: 'x'.repeat(2001) }])('does not publish malformed notify_user text: %j', async (args) => {
|
|
192
239
|
const onBubbleDelta = vi.fn()
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
return { text }
|
|
197
|
-
}, { onBubbleDelta })(
|
|
198
|
-
{ name: 'p/m', id: 'm', provider: 'yuri', api: 'openai-completions' }, { messages: [] },
|
|
240
|
+
const stream = createContactStreamFn(async () => toolCall('notify_user', args), { onBubbleDelta })(
|
|
241
|
+
{ name: 'p/m', id: 'm', provider: 'yuri', api: 'openai-completions' },
|
|
242
|
+
{ messages: [], tools: [{ name: 'notify_user' }] },
|
|
199
243
|
)
|
|
200
|
-
|
|
244
|
+
const result = await stream.result()
|
|
245
|
+
expect(result.stopReason).toBe('toolUse')
|
|
246
|
+
expect(result.content).toEqual([expect.objectContaining({ type: 'toolCall', name: 'notify_user' })])
|
|
201
247
|
expect(onBubbleDelta).not.toHaveBeenCalled()
|
|
202
248
|
})
|
|
203
249
|
|
|
@@ -205,7 +251,7 @@ describe('createContactStreamFn', () => {
|
|
|
205
251
|
const clearContactMemory = vi.fn(async () => ({ reset: true, memoryCleared: true }))
|
|
206
252
|
const onBubbleDelta = vi.fn()
|
|
207
253
|
const createChatCompletion = vi.fn()
|
|
208
|
-
.mockResolvedValueOnce(
|
|
254
|
+
.mockResolvedValueOnce(toolCall('new_conversation', {}))
|
|
209
255
|
.mockRejectedValueOnce(new Error('model unavailable'))
|
|
210
256
|
await expect(runContactTurn({
|
|
211
257
|
assistant: { providerID: 'p', modelID: 'm', variant: 'high' }, history: [], userText: '清除记忆',
|
|
@@ -232,9 +278,9 @@ describe('createContactStreamFn', () => {
|
|
|
232
278
|
const result = body.messages.find((message) => message.role === 'tool' && message.name === 'read')
|
|
233
279
|
if (result) {
|
|
234
280
|
expect(result.content).toContain('configured value')
|
|
235
|
-
return { completion: { choices: [{ message: { content: '
|
|
281
|
+
return { completion: { choices: [{ message: { content: 'configured value' } }] } }
|
|
236
282
|
}
|
|
237
|
-
return
|
|
283
|
+
return toolCall('read', { path: 'example-config.txt' })
|
|
238
284
|
})
|
|
239
285
|
try {
|
|
240
286
|
const result = await runContactTurn({
|
|
@@ -301,7 +347,7 @@ describe('createContactStreamFn', () => {
|
|
|
301
347
|
})
|
|
302
348
|
function AgentImpl(options) {
|
|
303
349
|
expect(options.initialState.thinkingLevel).toBe('off')
|
|
304
|
-
expect(options.initialState.tools).toEqual([])
|
|
350
|
+
expect(options.initialState.tools.map((tool) => tool.name)).toEqual(['notify_user'])
|
|
305
351
|
this.state = { ...options.initialState, messages: [] }
|
|
306
352
|
this.prompt = prompt
|
|
307
353
|
}
|
|
@@ -314,20 +360,12 @@ describe('createContactStreamFn', () => {
|
|
|
314
360
|
AgentImpl,
|
|
315
361
|
})
|
|
316
362
|
expect(result.thinkingLevel).toBe('off')
|
|
317
|
-
expect(result.tools).toEqual([])
|
|
363
|
+
expect(result.tools.map((tool) => tool.name)).toEqual(['notify_user'])
|
|
318
364
|
expect(prompt).toHaveBeenCalledWith('[attachment]')
|
|
319
365
|
})
|
|
320
366
|
|
|
321
|
-
it('replays
|
|
322
|
-
const createChatCompletion = vi.fn(async () => ({
|
|
323
|
-
completion: {
|
|
324
|
-
choices: [{
|
|
325
|
-
message: {
|
|
326
|
-
content: 'On it.\n\n```yuri-tool\n{"name":"assign_session","arguments":{"prompt":"Fix login"}}\n```',
|
|
327
|
-
},
|
|
328
|
-
}],
|
|
329
|
-
},
|
|
330
|
-
}))
|
|
367
|
+
it('replays a native assign_session call as a toolUse burst, not token SSE', async () => {
|
|
368
|
+
const createChatCompletion = vi.fn(async () => toolBatch([['assign_session', { prompt: 'Fix login' }]], 'On it.'))
|
|
331
369
|
const streamFn = createContactStreamFn(createChatCompletion)
|
|
332
370
|
const events = []
|
|
333
371
|
const stream = streamFn(
|
|
@@ -339,21 +377,14 @@ describe('createContactStreamFn', () => {
|
|
|
339
377
|
)
|
|
340
378
|
for await (const event of stream) events.push(event)
|
|
341
379
|
expect(events.some((event) => event.type === 'toolcall_end' && event.toolCall?.name === 'assign_session')).toBe(true)
|
|
380
|
+
expect(events.some((event) => event.type === 'text_delta')).toBe(false)
|
|
342
381
|
expect(events.at(-1)).toMatchObject({ type: 'done', reason: 'toolUse' })
|
|
343
382
|
expect(createChatCompletion.mock.calls[0][0].body.stream).toBeUndefined()
|
|
344
383
|
})
|
|
345
384
|
|
|
346
|
-
it('replays watch_session and stop_session
|
|
385
|
+
it('replays native watch_session and stop_session calls as toolUse bursts', async () => {
|
|
347
386
|
for (const name of ['watch_session', 'stop_session']) {
|
|
348
|
-
const createChatCompletion = vi.fn(async () => ({
|
|
349
|
-
completion: {
|
|
350
|
-
choices: [{
|
|
351
|
-
message: {
|
|
352
|
-
content: `\`\`\`yuri-tool\n${JSON.stringify({ name, arguments: { sessionID: 'ses_1' } })}\n\`\`\``,
|
|
353
|
-
},
|
|
354
|
-
}],
|
|
355
|
-
},
|
|
356
|
-
}))
|
|
387
|
+
const createChatCompletion = vi.fn(async () => toolCall(name, { sessionID: 'ses_1' }))
|
|
357
388
|
const events = []
|
|
358
389
|
const stream = createContactStreamFn(createChatCompletion)(
|
|
359
390
|
{ name: 'openai/gpt-5.2', id: 'gpt-5.2', provider: 'yuri', api: 'openai-completions' },
|
|
@@ -426,30 +457,6 @@ describe('createContactStreamFn', () => {
|
|
|
426
457
|
expect(result.bubbles.join('\n')).not.toContain('Watching that coding session')
|
|
427
458
|
})
|
|
428
459
|
|
|
429
|
-
it('replays a bare {name, arguments} object as a toolUse burst', async () => {
|
|
430
|
-
const createChatCompletion = vi.fn(async () => ({
|
|
431
|
-
completion: {
|
|
432
|
-
choices: [{
|
|
433
|
-
message: {
|
|
434
|
-
content: '好的 {"name":"create_assistant","arguments":{"name":"FlowNL"}}',
|
|
435
|
-
},
|
|
436
|
-
}],
|
|
437
|
-
},
|
|
438
|
-
}))
|
|
439
|
-
const streamFn = createContactStreamFn(createChatCompletion)
|
|
440
|
-
const events = []
|
|
441
|
-
const stream = streamFn(
|
|
442
|
-
{ name: 'opencode-go/deepseek-v4-flash', id: 'deepseek-v4-flash', provider: 'yuri', api: 'openai-completions' },
|
|
443
|
-
{
|
|
444
|
-
messages: [{ role: 'user', content: '新建助理 FlowNL', timestamp: 1 }],
|
|
445
|
-
tools: [{ name: 'create_assistant' }],
|
|
446
|
-
},
|
|
447
|
-
)
|
|
448
|
-
for await (const event of stream) events.push(event)
|
|
449
|
-
expect(events.some((event) => event.type === 'toolcall_end' && event.toolCall?.name === 'create_assistant')).toBe(true)
|
|
450
|
-
expect(events.at(-1)).toMatchObject({ type: 'done', reason: 'toolUse' })
|
|
451
|
-
})
|
|
452
|
-
|
|
453
460
|
it('passes onTextDelta and globalEventHub into createChatCompletion and forwards real deltas', async () => {
|
|
454
461
|
const deltas = []
|
|
455
462
|
const bubbleDeltas = []
|
|
@@ -476,35 +483,37 @@ describe('createContactStreamFn', () => {
|
|
|
476
483
|
expect(bubbleDeltas).toEqual([{ index: 0, delta: 'Hello world', done: true }])
|
|
477
484
|
})
|
|
478
485
|
|
|
479
|
-
it('
|
|
486
|
+
it('keeps native tool-call narration private while publishing notify_user text', async () => {
|
|
480
487
|
const bubbleDeltas = []
|
|
481
488
|
const createChatCompletion = vi.fn(async ({ onTextDelta }) => {
|
|
482
|
-
onTextDelta?.('
|
|
483
|
-
|
|
484
|
-
return {
|
|
485
|
-
completion: {
|
|
486
|
-
choices: [{
|
|
487
|
-
message: {
|
|
488
|
-
content: 'On it.\n\n```yuri-tool\n{"name":"assign_session","arguments":{"prompt":"x"}}\n```',
|
|
489
|
-
},
|
|
490
|
-
}],
|
|
491
|
-
},
|
|
492
|
-
}
|
|
489
|
+
onTextDelta?.('我先看看目录结构。')
|
|
490
|
+
return toolBatch([notifyCall('配置不在本地,改查服务端。'), ['bash', { command: 'ls' }, 'call_1']], '我先看看目录结构。')
|
|
493
491
|
})
|
|
494
|
-
const
|
|
492
|
+
const stream = createContactStreamFn(createChatCompletion, {
|
|
495
493
|
onBubbleDelta: (index, delta, done) => bubbleDeltas.push({ index, delta, done }),
|
|
496
|
-
})
|
|
497
|
-
const stream = streamFn(
|
|
494
|
+
})(
|
|
498
495
|
{ name: 'openai/gpt-5.2', id: 'gpt-5.2', provider: 'yuri', api: 'openai-completions' },
|
|
499
|
-
{
|
|
500
|
-
messages: [{ role: 'user', content: 'assign', timestamp: 1 }],
|
|
501
|
-
tools: [{ name: 'assign_session' }],
|
|
502
|
-
},
|
|
496
|
+
{ messages: [{ role: 'user', content: 'look', timestamp: 1 }], tools: [{ name: 'bash' }, { name: 'notify_user' }] },
|
|
503
497
|
)
|
|
504
498
|
for await (const event of stream) void event
|
|
505
|
-
const
|
|
506
|
-
expect(
|
|
507
|
-
expect(
|
|
499
|
+
const result = await stream.result()
|
|
500
|
+
expect(bubbleDeltas).toEqual([{ index: 0, delta: '配置不在本地,改查服务端。', done: true }])
|
|
501
|
+
expect(result.content[0]).toEqual({ type: 'text', text: '配置不在本地,改查服务端。' })
|
|
502
|
+
expect(JSON.stringify(result.content)).not.toContain('目录结构')
|
|
503
|
+
})
|
|
504
|
+
|
|
505
|
+
it('never paints plain narration beside a tool call as a bubble', async () => {
|
|
506
|
+
const bubbleDeltas = []
|
|
507
|
+
const stream = createContactStreamFn(async () => toolBatch([['assign_session', { prompt: 'x' }]], 'On it.'), {
|
|
508
|
+
onBubbleDelta: (index, delta, done) => bubbleDeltas.push({ index, delta, done }),
|
|
509
|
+
})(
|
|
510
|
+
{ name: 'openai/gpt-5.2', id: 'gpt-5.2', provider: 'yuri', api: 'openai-completions' },
|
|
511
|
+
{ messages: [{ role: 'user', content: 'assign', timestamp: 1 }], tools: [{ name: 'assign_session' }] },
|
|
512
|
+
)
|
|
513
|
+
const result = await stream.result()
|
|
514
|
+
expect(bubbleDeltas).toEqual([])
|
|
515
|
+
expect(projectStreamedContactTurnBubbles([result])).toEqual([])
|
|
516
|
+
expect(JSON.stringify(result.content)).not.toContain('On it.')
|
|
508
517
|
})
|
|
509
518
|
|
|
510
519
|
it('emits final stripped bubbles as done:true once when no live deltas arrive', async () => {
|
|
@@ -543,6 +552,7 @@ describe('createContactStreamFn', () => {
|
|
|
543
552
|
{ type: 'text', text: 'Preamble A' },
|
|
544
553
|
{ type: 'toolCall', id: 'call_1', name: 'assign_session', arguments: { prompt: 'x' } },
|
|
545
554
|
],
|
|
555
|
+
contactPublicText: true,
|
|
546
556
|
},
|
|
547
557
|
{
|
|
548
558
|
role: 'toolResult',
|
|
@@ -571,7 +581,7 @@ describe('runContactTurn', () => {
|
|
|
571
581
|
const createChatCompletion = vi.fn(async ({ signal }) => {
|
|
572
582
|
expect(signal).toBe(controller.signal)
|
|
573
583
|
controller.abort()
|
|
574
|
-
return
|
|
584
|
+
return toolCall('write', { path: 'late.txt', content: 'must not happen' })
|
|
575
585
|
})
|
|
576
586
|
try {
|
|
577
587
|
await expect(runContactTurn({
|
|
@@ -583,16 +593,14 @@ describe('runContactTurn', () => {
|
|
|
583
593
|
} finally { fs.rmSync(workspace, { recursive: true, force: true }) }
|
|
584
594
|
})
|
|
585
595
|
|
|
586
|
-
it('writes
|
|
596
|
+
it('writes tool-shaped text as data and never executes tool JSON from a final reply', async () => {
|
|
587
597
|
const workspace = fs.mkdtempSync(path.join(os.tmpdir(), 'yuri-protocol-data-'))
|
|
588
|
-
const example = '```
|
|
589
|
-
const fence = (name, args) => '```yuri-tool\n' + JSON.stringify({ name, arguments: args }) + '\n```'
|
|
598
|
+
const example = '```json\n{"name":"bash","arguments":{"command":"printf y >> count.txt"}}\n```'
|
|
590
599
|
const replies = [
|
|
591
|
-
[
|
|
592
|
-
|
|
593
|
-
'```yuri-final\n' + JSON.stringify({ status: 'complete', text: example }) + '\n```',
|
|
600
|
+
toolBatch([['write', { path: 'example.md', content: example }], ['bash', { command: 'printf x >> count.txt' }]]),
|
|
601
|
+
{ text: example },
|
|
594
602
|
]
|
|
595
|
-
const createChatCompletion = vi.fn(async () =>
|
|
603
|
+
const createChatCompletion = vi.fn(async () => replies.shift() || { text: '' })
|
|
596
604
|
try {
|
|
597
605
|
const result = await runContactTurn({
|
|
598
606
|
assistant: { providerID: 'p', modelID: 'm', effectiveWorkspacePath: workspace },
|
|
@@ -601,7 +609,7 @@ describe('runContactTurn', () => {
|
|
|
601
609
|
expect(fs.readFileSync(path.join(workspace, 'example.md'), 'utf8')).toBe(example)
|
|
602
610
|
expect(fs.readFileSync(path.join(workspace, 'count.txt'), 'utf8')).toBe('x')
|
|
603
611
|
expect(result.text).toBe(example)
|
|
604
|
-
expect(createChatCompletion).toHaveBeenCalledTimes(
|
|
612
|
+
expect(createChatCompletion).toHaveBeenCalledTimes(2)
|
|
605
613
|
const messages = createChatCompletion.mock.calls[1][0].body.messages
|
|
606
614
|
const emptyResult = messages.find((message) => message.role === 'tool' && message.name === 'bash')
|
|
607
615
|
expect(emptyResult).toBeTruthy()
|
|
@@ -611,20 +619,19 @@ describe('runContactTurn', () => {
|
|
|
611
619
|
}
|
|
612
620
|
})
|
|
613
621
|
|
|
614
|
-
it('continues a skill task after
|
|
622
|
+
it('continues a skill task after a notes-only response and executes every coding call in order', async () => {
|
|
615
623
|
const workspace = fs.mkdtempSync(path.join(os.tmpdir(), 'yuri-skill-loop-'))
|
|
616
624
|
const skillPath = '.agents/skills/note/SKILL.md'
|
|
617
625
|
fs.mkdirSync(path.dirname(path.join(workspace, skillPath)), { recursive: true })
|
|
618
626
|
fs.writeFileSync(path.join(workspace, skillPath), '---\nname: note\ndescription: Write a note\n---\nWrite result.txt then read it to verify.\n')
|
|
619
|
-
const fence = (name, args) => '```yuri-tool\n' + JSON.stringify({ name, arguments: args }) + '\n```'
|
|
620
627
|
const replies = [
|
|
621
|
-
|
|
622
|
-
'
|
|
623
|
-
[
|
|
624
|
-
|
|
628
|
+
toolCall('read', { path: skillPath }),
|
|
629
|
+
toolBatch([notifyCall('笔记会写入 result.txt,写完再读回验证。')]),
|
|
630
|
+
toolBatch([['write', { path: 'result.txt', content: 'verified note' }], ['read', { path: 'result.txt' }]], '我先写入,然后验证。'),
|
|
631
|
+
{ text: '已写入并验证。' },
|
|
625
632
|
]
|
|
626
633
|
const onBubbleDelta = vi.fn()
|
|
627
|
-
const createChatCompletion = vi.fn(async () =>
|
|
634
|
+
const createChatCompletion = vi.fn(async () => replies.shift() || { text: '' })
|
|
628
635
|
try {
|
|
629
636
|
const result = await runContactTurn({
|
|
630
637
|
assistant: { providerID: 'p', modelID: 'm', effectiveWorkspacePath: workspace },
|
|
@@ -632,7 +639,7 @@ describe('runContactTurn', () => {
|
|
|
632
639
|
tools: createContactTools({}), createChatCompletion, onBubbleDelta,
|
|
633
640
|
})
|
|
634
641
|
expect(fs.readFileSync(path.join(workspace, 'result.txt'), 'utf8')).toBe('verified note')
|
|
635
|
-
expect(result.
|
|
642
|
+
expect(result.bubbles).toEqual(['笔记会写入 result.txt,写完再读回验证。', '已写入并验证。'])
|
|
636
643
|
expect(createChatCompletion).toHaveBeenCalledTimes(4)
|
|
637
644
|
const lastRequest = createChatCompletion.mock.calls.at(-1)[0].body.messages
|
|
638
645
|
const calls = JSON.stringify(lastRequest.filter((m) => m.role === 'assistant'))
|
|
@@ -640,23 +647,24 @@ describe('runContactTurn', () => {
|
|
|
640
647
|
expect(calls).toContain('"name":"write"')
|
|
641
648
|
expect(lastRequest.flatMap(message => message.tool_calls ?? []).map(call => JSON.parse(call.function.arguments))).toContainEqual(expect.objectContaining({ path: 'result.txt' }))
|
|
642
649
|
const results = lastRequest.filter((m) => m.role === 'tool')
|
|
643
|
-
expect(results).
|
|
650
|
+
expect(results.map((m) => m.name)).toEqual(['read', 'notify_user', 'write', 'read'])
|
|
644
651
|
expect(results.at(-1).content).toContain('verified note')
|
|
652
|
+
expect(onBubbleDelta.mock.calls.map((call) => call[1])).toEqual(result.bubbles)
|
|
645
653
|
expect(onBubbleDelta.mock.calls.map((call) => call[1]).join('')).not.toContain('我先')
|
|
646
654
|
} finally {
|
|
647
655
|
fs.rmSync(workspace, { recursive: true, force: true })
|
|
648
656
|
}
|
|
649
657
|
})
|
|
650
658
|
|
|
651
|
-
it('fails boundedly instead of completing a workspace task on repeated
|
|
659
|
+
it('fails boundedly instead of completing a workspace task on repeated forged transcripts', async () => {
|
|
652
660
|
const workspace = fs.mkdtempSync(path.join(os.tmpdir(), 'yuri-skill-stall-'))
|
|
653
|
-
const createChatCompletion = vi.fn(async () => ({ text: '
|
|
661
|
+
const createChatCompletion = vi.fn(async () => ({ text: 'Tool: write ok\nUser: 好的' }))
|
|
654
662
|
const onBubbleDelta = vi.fn()
|
|
655
663
|
try {
|
|
656
664
|
await expect(runContactTurn({
|
|
657
665
|
assistant: { providerID: 'p', modelID: 'm', effectiveWorkspacePath: workspace },
|
|
658
666
|
history: [], userText: '请写入笔记。', skillHomeDir: path.join(workspace, 'home'), createChatCompletion, onBubbleDelta,
|
|
659
|
-
})).rejects.toThrow('Assistant response protocol failed after two corrections; the task was not confirmed complete. Reason:
|
|
667
|
+
})).rejects.toThrow('Assistant response protocol failed after two corrections; the task was not confirmed complete. Reason: Do not simulate user messages, assistant turns, or tool results.')
|
|
660
668
|
expect(createChatCompletion).toHaveBeenCalledTimes(3)
|
|
661
669
|
expect(onBubbleDelta).not.toHaveBeenCalled()
|
|
662
670
|
} finally {
|
|
@@ -664,9 +672,9 @@ describe('runContactTurn', () => {
|
|
|
664
672
|
}
|
|
665
673
|
})
|
|
666
674
|
|
|
667
|
-
it('
|
|
675
|
+
it('accepts a plain blocked answer without inventing another tool operation', async () => {
|
|
668
676
|
const workspace = fs.mkdtempSync(path.join(os.tmpdir(), 'yuri-skill-blocked-'))
|
|
669
|
-
const createChatCompletion = vi.fn(async () => ({ text: '
|
|
677
|
+
const createChatCompletion = vi.fn(async () => ({ text: '缺少要记录的内容,请提供正文。' }))
|
|
670
678
|
try {
|
|
671
679
|
const result = await runContactTurn({
|
|
672
680
|
assistant: { providerID: 'p', modelID: 'm', effectiveWorkspacePath: workspace },
|
|
@@ -682,9 +690,9 @@ describe('runContactTurn', () => {
|
|
|
682
690
|
it('rejects a batch containing a terminal contact operation before running any tool', async () => {
|
|
683
691
|
const workspace = fs.mkdtempSync(path.join(os.tmpdir(), 'yuri-contact-batch-'))
|
|
684
692
|
const assignWork = vi.fn(async () => ({ sessionID: 'ses_once', directory: workspace, title: 'Work', status: 'busy' }))
|
|
685
|
-
const assign = '
|
|
686
|
-
const replies = [assign
|
|
687
|
-
const createChatCompletion = vi.fn(async () =>
|
|
693
|
+
const assign = ['assign_session', { projectPath: workspace, prompt: 'Work' }]
|
|
694
|
+
const replies = [toolBatch([notifyCall('开始安排。'), assign, ['write', { path: 'unexpected.txt', content: 'bad' }]]), toolBatch([assign]), { text: '任务已经交给工作会话。' }]
|
|
695
|
+
const createChatCompletion = vi.fn(async () => replies.shift() || { text: '' })
|
|
688
696
|
try {
|
|
689
697
|
const result = await runContactTurn({
|
|
690
698
|
assistant: { providerID: 'p', modelID: 'm', effectiveWorkspacePath: workspace },
|
|
@@ -694,6 +702,8 @@ describe('runContactTurn', () => {
|
|
|
694
702
|
expect(assignWork).toHaveBeenCalledTimes(1)
|
|
695
703
|
expect(result.cards[0].sessionID).toBe('ses_once')
|
|
696
704
|
expect(fs.existsSync(path.join(workspace, 'unexpected.txt'))).toBe(false)
|
|
705
|
+
expect(JSON.stringify(createChatCompletion.mock.calls[1][0].body.messages)).toContain('Send Yuri operation tools one at a time')
|
|
706
|
+
expect(result.bubbles).toEqual(['任务已经交给工作会话。'])
|
|
697
707
|
} finally {
|
|
698
708
|
fs.rmSync(workspace, { recursive: true, force: true })
|
|
699
709
|
}
|
|
@@ -708,23 +718,24 @@ describe('runContactTurn', () => {
|
|
|
708
718
|
const assignWork = vi.fn(async () => ({ sessionID: 'ses_mixed', directory: workspace, title: 'Fix', status: 'busy' }))
|
|
709
719
|
const tools = createContactTools({ assignWork })
|
|
710
720
|
const replies = [
|
|
711
|
-
'
|
|
712
|
-
'Only documentation search is available.',
|
|
713
|
-
|
|
714
|
-
'Session opened.',
|
|
721
|
+
toolCall('read', { path: '.agents/skills/docs/SKILL.md' }),
|
|
722
|
+
{ text: 'Only documentation search is available.' },
|
|
723
|
+
toolCall('assign_session', { prompt: 'Fix the issue', projectPath: workspace }),
|
|
724
|
+
{ text: 'Session opened.' },
|
|
715
725
|
]
|
|
716
726
|
let call = 0
|
|
717
727
|
const createChatCompletion = vi.fn(async ({ body }) => {
|
|
718
|
-
if (call === 3) return
|
|
728
|
+
if (call === 3) return replies[call++]
|
|
719
729
|
expect(body.messages[0].content).toContain('assign_session')
|
|
720
730
|
expect(body.messages[0].content).toContain('docs')
|
|
721
|
-
expect(body.messages[0].content).toContain('
|
|
722
|
-
expect(body.messages[0].content).toContain('
|
|
723
|
-
expect(body.messages[0].content).toContain('
|
|
731
|
+
expect(body.messages[0].content).toContain('notify_user')
|
|
732
|
+
expect(body.messages[0].content).not.toContain('arguments schema:')
|
|
733
|
+
expect(body.messages[0].content).not.toContain('yuri-tool')
|
|
724
734
|
expect(body.messages[0].content).toContain('not OpenCode native tools and not MCP')
|
|
735
|
+
expect(body.tools.map((tool) => tool.function.name)).toEqual(expect.arrayContaining(['edit', 'write', 'assign_session', 'notify_user']))
|
|
725
736
|
const content = replies[call++]
|
|
726
737
|
if (!content) throw new Error('Unexpected completion')
|
|
727
|
-
return
|
|
738
|
+
return content
|
|
728
739
|
})
|
|
729
740
|
try {
|
|
730
741
|
const result = await runContactTurn({
|
|
@@ -732,7 +743,7 @@ describe('runContactTurn', () => {
|
|
|
732
743
|
history: [], userText: '再建个会话去修这个问题', tools,
|
|
733
744
|
projects: [{ id: 'project', path: workspace }], skillHomeDir: home, createChatCompletion,
|
|
734
745
|
})
|
|
735
|
-
expect(result.tools.map((tool) => tool.name)).toEqual([...PI_CODING_TOOL_NAMES, ...tools.map((tool) => tool.name)])
|
|
746
|
+
expect(result.tools.map((tool) => tool.name)).toEqual([...PI_CODING_TOOL_NAMES, ...tools.map((tool) => tool.name), 'notify_user'])
|
|
736
747
|
expect(assignWork).toHaveBeenCalledTimes(1)
|
|
737
748
|
expect(result.cards).toEqual([expect.objectContaining({ sessionID: 'ses_mixed' })])
|
|
738
749
|
// Assignment terminates mutations; a tools-disabled completion summarizes the result.
|
|
@@ -764,15 +775,7 @@ describe('runContactTurn', () => {
|
|
|
764
775
|
if (completions > 8) {
|
|
765
776
|
throw new Error('harness safety stop: too many completions without terminate')
|
|
766
777
|
}
|
|
767
|
-
return {
|
|
768
|
-
completion: {
|
|
769
|
-
choices: [{
|
|
770
|
-
message: {
|
|
771
|
-
content: '```yuri-tool\n{"name":"assign_session","arguments":{"prompt":"Fix login","projectPath":"/repo"}}\n```',
|
|
772
|
-
},
|
|
773
|
-
}],
|
|
774
|
-
},
|
|
775
|
-
}
|
|
778
|
+
return toolCall('assign_session', { prompt: 'Fix login', projectPath: '/repo' })
|
|
776
779
|
})
|
|
777
780
|
const result = await runContactTurn({
|
|
778
781
|
assistant: { providerID: 'p', modelID: 'm', defaultPrompt: '' },
|
|
@@ -811,37 +814,13 @@ describe('runContactTurn', () => {
|
|
|
811
814
|
const last = body.messages.at(-1)
|
|
812
815
|
const lastText = typeof last?.content === 'string' ? last.content : ''
|
|
813
816
|
if (body.messages.at(-1)?.name === 'list_projects' || lastText.includes('Registered projects')) {
|
|
814
|
-
return {
|
|
815
|
-
completion: {
|
|
816
|
-
choices: [{
|
|
817
|
-
message: {
|
|
818
|
-
content: '```yuri-tool\n{"name":"assign_session","arguments":{"prompt":"Fix","projectPath":"/repo"}}\n```',
|
|
819
|
-
},
|
|
820
|
-
}],
|
|
821
|
-
},
|
|
822
|
-
}
|
|
817
|
+
return toolCall('assign_session', { prompt: 'Fix', projectPath: '/repo' })
|
|
823
818
|
}
|
|
824
819
|
if (completions === 1) {
|
|
825
|
-
return {
|
|
826
|
-
completion: {
|
|
827
|
-
choices: [{
|
|
828
|
-
message: {
|
|
829
|
-
content: '```yuri-tool\n{"name":"list_projects","arguments":{"query":"repo"}}\n```',
|
|
830
|
-
},
|
|
831
|
-
}],
|
|
832
|
-
},
|
|
833
|
-
}
|
|
820
|
+
return toolCall('list_projects', { query: 'repo' })
|
|
834
821
|
}
|
|
835
822
|
// If assign did not terminate, a looping model would keep assigning — fail closed.
|
|
836
|
-
return {
|
|
837
|
-
completion: {
|
|
838
|
-
choices: [{
|
|
839
|
-
message: {
|
|
840
|
-
content: '```yuri-tool\n{"name":"assign_session","arguments":{"prompt":"Fix again","projectPath":"/repo"}}\n```',
|
|
841
|
-
},
|
|
842
|
-
}],
|
|
843
|
-
},
|
|
844
|
-
}
|
|
823
|
+
return toolCall('assign_session', { prompt: 'Fix again', projectPath: '/repo' })
|
|
845
824
|
})
|
|
846
825
|
const result = await runContactTurn({
|
|
847
826
|
assistant: { providerID: 'p', modelID: 'm', defaultPrompt: '' },
|
|
@@ -883,7 +862,7 @@ describe('runContactTurn', () => {
|
|
|
883
862
|
expect(result.bubbles).toEqual(['Only document search is available.', '已安排工作。'])
|
|
884
863
|
expect(result.bubbles.join('\n')).not.toContain('Opened session.')
|
|
885
864
|
})
|
|
886
|
-
it('runs pi-agent-core with thinking off and
|
|
865
|
+
it('runs pi-agent-core with thinking off and only notify_user by default', async () => {
|
|
887
866
|
const prompt = vi.fn(async function prompt() {
|
|
888
867
|
this.state.messages = [{
|
|
889
868
|
role: 'assistant',
|
|
@@ -892,7 +871,7 @@ describe('runContactTurn', () => {
|
|
|
892
871
|
})
|
|
893
872
|
function AgentImpl(options) {
|
|
894
873
|
expect(options.initialState.thinkingLevel).toBe('off')
|
|
895
|
-
expect(options.initialState.tools).toEqual([])
|
|
874
|
+
expect(options.initialState.tools.map((tool) => tool.name)).toEqual(['notify_user'])
|
|
896
875
|
this.state = { ...options.initialState, messages: [] }
|
|
897
876
|
this.prompt = prompt
|
|
898
877
|
}
|
|
@@ -922,7 +901,7 @@ describe('runContactTurn', () => {
|
|
|
922
901
|
fs.writeFileSync(path.join(globalAgents, 'SKILL.md'), '---\nname: global-skill\ndescription: Global agents skill\n---\nDo the global thing\n')
|
|
923
902
|
function AgentImpl(options) {
|
|
924
903
|
expect(options.initialState.thinkingLevel).toBe('off')
|
|
925
|
-
expect(options.initialState.tools.map((tool) => tool.name)).toEqual([...PI_CODING_TOOL_NAMES])
|
|
904
|
+
expect(options.initialState.tools.map((tool) => tool.name)).toEqual([...PI_CODING_TOOL_NAMES, 'notify_user'])
|
|
926
905
|
expect(options.initialState.systemPrompt).toContain(workspace)
|
|
927
906
|
expect(options.initialState.systemPrompt).toContain('Be terse.')
|
|
928
907
|
expect(options.initialState.systemPrompt).toContain('project-skill')
|
|
@@ -1003,17 +982,11 @@ describe('runContactTurn', () => {
|
|
|
1003
982
|
const createChatCompletion = vi.fn(async ({ body }) => {
|
|
1004
983
|
calls += 1
|
|
1005
984
|
if (calls === 1) {
|
|
1006
|
-
return {
|
|
1007
|
-
completion: {
|
|
1008
|
-
choices: [{
|
|
1009
|
-
message: { content: '```yuri-tool\n{"name":"bash","arguments":{"command":"pwd"}}\n```' },
|
|
1010
|
-
}],
|
|
1011
|
-
},
|
|
1012
|
-
}
|
|
985
|
+
return toolCall('bash', { command: 'pwd' })
|
|
1013
986
|
}
|
|
1014
987
|
const last = body.messages.at(-1)
|
|
1015
988
|
const content = typeof last?.content === 'string' ? last.content : ''
|
|
1016
|
-
return { completion: { choices: [{ message: { content:
|
|
989
|
+
return { completion: { choices: [{ message: { content: content || 'done' } }] } }
|
|
1017
990
|
})
|
|
1018
991
|
try {
|
|
1019
992
|
const result = await runContactTurn({
|
|
@@ -1047,7 +1020,7 @@ describe('runContactTurn', () => {
|
|
|
1047
1020
|
}
|
|
1048
1021
|
function AgentImpl(options) {
|
|
1049
1022
|
expect(options.initialState.thinkingLevel).toBe('off')
|
|
1050
|
-
expect(options.initialState.tools.map((tool) => tool.name)).toEqual(['assign_session'])
|
|
1023
|
+
expect(options.initialState.tools.map((tool) => tool.name)).toEqual(['assign_session', 'notify_user'])
|
|
1051
1024
|
expect(options.initialState.tools.some((tool) => ['bash', 'edit', 'read', 'write'].includes(tool.name))).toBe(false)
|
|
1052
1025
|
expect(options.initialState.systemPrompt).toContain('assign_session')
|
|
1053
1026
|
expect(options.initialState.systemPrompt).toContain('create_assistant')
|
|
@@ -1143,7 +1116,7 @@ describe('runContactTurn', () => {
|
|
|
1143
1116
|
expect(result.cards).toEqual([expect.objectContaining({ sessionID: 'ses_plan' })])
|
|
1144
1117
|
})
|
|
1145
1118
|
|
|
1146
|
-
it('keeps a short
|
|
1119
|
+
it('keeps a short notify_user preamble then the model summary', async () => {
|
|
1147
1120
|
function AgentImpl(options) {
|
|
1148
1121
|
this.state = { ...options.initialState, messages: [] }
|
|
1149
1122
|
this.prompt = async () => {
|
|
@@ -1154,6 +1127,7 @@ describe('runContactTurn', () => {
|
|
|
1154
1127
|
{ type: 'text', text: '我去找一下' },
|
|
1155
1128
|
{ type: 'toolCall', id: 'call_1', name: 'assign_session', arguments: { prompt: 'x' } },
|
|
1156
1129
|
],
|
|
1130
|
+
contactPublicText: true,
|
|
1157
1131
|
},
|
|
1158
1132
|
{
|
|
1159
1133
|
role: 'toolResult',
|
|
@@ -1197,6 +1171,7 @@ describe('runContactTurn', () => {
|
|
|
1197
1171
|
{ type: 'text', text: '我去读一下这个会话。' },
|
|
1198
1172
|
{ type: 'toolCall', id: 'call_r', name: 'read_session', arguments: { sessionID: 'ses_quote' } },
|
|
1199
1173
|
],
|
|
1174
|
+
contactPublicText: true,
|
|
1200
1175
|
},
|
|
1201
1176
|
{
|
|
1202
1177
|
role: 'toolResult',
|
|
@@ -1234,6 +1209,7 @@ describe('runContactTurn', () => {
|
|
|
1234
1209
|
{ type: 'text', text: '我去读一下这个会话。' },
|
|
1235
1210
|
{ type: 'toolCall', id: 'call_r', name: 'read_session', arguments: { sessionID: 'ses_quote' } },
|
|
1236
1211
|
],
|
|
1212
|
+
contactPublicText: true,
|
|
1237
1213
|
},
|
|
1238
1214
|
{
|
|
1239
1215
|
role: 'toolResult',
|
|
@@ -1509,16 +1485,8 @@ describe('runContactTurn', () => {
|
|
|
1509
1485
|
if (completions > 4) {
|
|
1510
1486
|
throw new Error('harness safety stop: clear_chat_history must terminate without follow-up LLM')
|
|
1511
1487
|
}
|
|
1512
|
-
// Looping model would keep emitting wipe
|
|
1513
|
-
return {
|
|
1514
|
-
completion: {
|
|
1515
|
-
choices: [{
|
|
1516
|
-
message: {
|
|
1517
|
-
content: '```yuri-tool\n{"name":"clear_chat_history","arguments":{}}\n```',
|
|
1518
|
-
},
|
|
1519
|
-
}],
|
|
1520
|
-
},
|
|
1521
|
-
}
|
|
1488
|
+
// Looping model would keep emitting wipe calls; terminate must stop after one tool run.
|
|
1489
|
+
return toolCall('clear_chat_history', {})
|
|
1522
1490
|
})
|
|
1523
1491
|
const result = await runContactTurn({
|
|
1524
1492
|
assistant: { providerID: 'p', modelID: 'm', defaultPrompt: '' },
|
|
@@ -1554,15 +1522,7 @@ describe('runContactTurn', () => {
|
|
|
1554
1522
|
if (completions > 4) {
|
|
1555
1523
|
throw new Error('harness safety stop: wipe must terminate once')
|
|
1556
1524
|
}
|
|
1557
|
-
return {
|
|
1558
|
-
completion: {
|
|
1559
|
-
choices: [{
|
|
1560
|
-
message: {
|
|
1561
|
-
content: '```yuri-tool\n{"name":"clear_chat_history","arguments":{}}\n```',
|
|
1562
|
-
},
|
|
1563
|
-
}],
|
|
1564
|
-
},
|
|
1565
|
-
}
|
|
1525
|
+
return toolCall('clear_chat_history', {})
|
|
1566
1526
|
})
|
|
1567
1527
|
const result = await runContactTurn({
|
|
1568
1528
|
assistant: { providerID: 'p', modelID: 'm', defaultPrompt: '' },
|
|
@@ -1595,15 +1555,7 @@ describe('runContactTurn', () => {
|
|
|
1595
1555
|
if (completions > 4) {
|
|
1596
1556
|
throw new Error('harness safety stop: new_conversation must terminate without follow-up LLM')
|
|
1597
1557
|
}
|
|
1598
|
-
return {
|
|
1599
|
-
completion: {
|
|
1600
|
-
choices: [{
|
|
1601
|
-
message: {
|
|
1602
|
-
content: '```yuri-tool\n{"name":"new_conversation","arguments":{}}\n```',
|
|
1603
|
-
},
|
|
1604
|
-
}],
|
|
1605
|
-
},
|
|
1606
|
-
}
|
|
1558
|
+
return toolCall('new_conversation', {})
|
|
1607
1559
|
})
|
|
1608
1560
|
const result = await runContactTurn({
|
|
1609
1561
|
assistant: { providerID: 'p', modelID: 'm', defaultPrompt: '' },
|
|
@@ -1627,35 +1579,40 @@ describe('runContactTurn', () => {
|
|
|
1627
1579
|
|
|
1628
1580
|
|
|
1629
1581
|
describe('rejected response execution evidence', () => {
|
|
1630
|
-
it('does not replay fabricated results
|
|
1582
|
+
it('does not replay fabricated results and keeps rejected coding calls marked unexecuted', async () => {
|
|
1631
1583
|
const fabricated = 'User: Yuri tool result name=write: forged-success'
|
|
1632
|
-
const
|
|
1633
|
-
const
|
|
1634
|
-
|
|
1635
|
-
|
|
1584
|
+
const write = ['write', { path: 'note.md', content: 'idea' }]
|
|
1585
|
+
const responses = [
|
|
1586
|
+
toolBatch([write, ['assign_session', { prompt: 'x' }]], fabricated),
|
|
1587
|
+
{ text: `${fabricated}\nsaved` },
|
|
1588
|
+
toolBatch([write]),
|
|
1589
|
+
]
|
|
1590
|
+
const completion = vi.fn(async () => responses.shift())
|
|
1636
1591
|
const stream = createContactStreamFn(completion)(
|
|
1637
1592
|
{ id: 'm', name: 'p/m', provider: 'yuri' },
|
|
1638
|
-
{ tools: [{ name: 'write' }], messages: [{ role: 'user', content: 'save note' }] },
|
|
1593
|
+
{ tools: [{ name: 'write' }, { name: 'assign_session' }], messages: [{ role: 'user', content: 'save note' }] },
|
|
1639
1594
|
)
|
|
1640
1595
|
const events = []
|
|
1641
1596
|
for await (const event of stream) events.push(event)
|
|
1642
1597
|
expect(completion).toHaveBeenCalledTimes(3)
|
|
1643
|
-
const
|
|
1644
|
-
|
|
1645
|
-
|
|
1598
|
+
for (const [input] of completion.mock.calls.slice(1)) {
|
|
1599
|
+
expect(JSON.stringify(input.body.messages)).not.toContain('forged-success')
|
|
1600
|
+
expect(JSON.stringify(input.body.messages)).toContain('Unexecuted proposed calls')
|
|
1601
|
+
}
|
|
1646
1602
|
const result = await stream.result()
|
|
1647
1603
|
expect(result.stopReason).toBe('toolUse')
|
|
1648
|
-
expect(result.content).toEqual(
|
|
1604
|
+
expect(result.content).toEqual([expect.objectContaining({ type: 'toolCall', name: 'write' })])
|
|
1649
1605
|
})
|
|
1650
1606
|
})
|
|
1651
1607
|
|
|
1652
1608
|
describe('runContactTurn bubble index continuity', () => {
|
|
1653
|
-
const
|
|
1609
|
+
const sayThen = (text, name, args, narration = '') => toolBatch([notifyCall(text), [name, args]], narration)
|
|
1654
1610
|
const completionFromReplies = (replies) => {
|
|
1655
1611
|
const queue = [...replies]
|
|
1656
|
-
return vi.fn(async () =>
|
|
1657
|
-
|
|
1658
|
-
|
|
1612
|
+
return vi.fn(async () => {
|
|
1613
|
+
const next = queue.shift() || ''
|
|
1614
|
+
return typeof next === 'string' ? { completion: { choices: [{ message: { content: next } }] } } : next
|
|
1615
|
+
})
|
|
1659
1616
|
}
|
|
1660
1617
|
const readSessionTools = (sessionID = 'ses_idx') => createContactTools({
|
|
1661
1618
|
readSession: async () => ({
|
|
@@ -1667,7 +1624,7 @@ describe('runContactTurn bubble index continuity', () => {
|
|
|
1667
1624
|
it('real Agent gateway stub: preamble then read_session then multi-bubble final keeps stable SSE indices', async () => {
|
|
1668
1625
|
const bubbleDeltas = []
|
|
1669
1626
|
const createChatCompletion = completionFromReplies([
|
|
1670
|
-
|
|
1627
|
+
sayThen('我去读一下', 'read_session', { sessionID: 'ses_idx' }, '先私下确认会话 ID。'),
|
|
1671
1628
|
'办好了。\n\n还有后续说明。',
|
|
1672
1629
|
])
|
|
1673
1630
|
const result = await runContactTurn({
|
|
@@ -1686,6 +1643,7 @@ describe('runContactTurn bubble index continuity', () => {
|
|
|
1686
1643
|
{ index: 2, delta: '还有后续说明。' },
|
|
1687
1644
|
])
|
|
1688
1645
|
expect(result.bubbles).toEqual(['我去读一下', '办好了。', '还有后续说明。'])
|
|
1646
|
+
expect(result.bubbles.join('\n')).not.toContain('私下确认')
|
|
1689
1647
|
// Published stream is a stable prefix of the final array.
|
|
1690
1648
|
expect(result.bubbles.slice(0, doneBubbles.length)).toEqual(doneBubbles.map((item) => item.delta))
|
|
1691
1649
|
})
|
|
@@ -1693,8 +1651,8 @@ describe('runContactTurn bubble index continuity', () => {
|
|
|
1693
1651
|
it('real Agent: two read_session preambles keep both spoken lines plus final in bubbles', async () => {
|
|
1694
1652
|
const bubbleDeltas = []
|
|
1695
1653
|
const createChatCompletion = completionFromReplies([
|
|
1696
|
-
|
|
1697
|
-
|
|
1654
|
+
sayThen('我去读一下', 'read_session', { sessionID: 'ses_a' }),
|
|
1655
|
+
sayThen('我再读一下', 'read_session', { sessionID: 'ses_b' }),
|
|
1698
1656
|
'办好了',
|
|
1699
1657
|
])
|
|
1700
1658
|
const result = await runContactTurn({
|
|
@@ -1715,8 +1673,8 @@ describe('runContactTurn bubble index continuity', () => {
|
|
|
1715
1673
|
it('real Agent: duplicate preamble text is kept as independent bubbles', async () => {
|
|
1716
1674
|
const bubbleDeltas = []
|
|
1717
1675
|
const createChatCompletion = completionFromReplies([
|
|
1718
|
-
|
|
1719
|
-
|
|
1676
|
+
sayThen('我去读一下', 'read_session', { sessionID: 'ses_a' }),
|
|
1677
|
+
sayThen('我去读一下', 'read_session', { sessionID: 'ses_b' }),
|
|
1720
1678
|
'办好了',
|
|
1721
1679
|
])
|
|
1722
1680
|
const result = await runContactTurn({
|
|
@@ -1737,8 +1695,8 @@ describe('runContactTurn bubble index continuity', () => {
|
|
|
1737
1695
|
// Two independent short spokens (each tool turn); confirm-only tool text appends at end.
|
|
1738
1696
|
// update_default_prompt is terminate:false so a plain final closes the agent loop.
|
|
1739
1697
|
const createChatCompletion = completionFromReplies([
|
|
1740
|
-
|
|
1741
|
-
|
|
1698
|
+
sayThen('我先看一下', 'list_sessions', { query: 'login' }),
|
|
1699
|
+
sayThen('马上改人设', 'update_default_prompt', { prompt: 'be brief' }),
|
|
1742
1700
|
'改好了',
|
|
1743
1701
|
])
|
|
1744
1702
|
const tools = createContactTools({
|
|
@@ -1761,7 +1719,7 @@ describe('runContactTurn bubble index continuity', () => {
|
|
|
1761
1719
|
expect(result.bubbles).toHaveLength(3)
|
|
1762
1720
|
expect(result.bubbles.slice(0, doneBubbles.length)).toEqual(doneBubbles)
|
|
1763
1721
|
expect(result.bubbles.join('')).not.toMatch(/Default prompt/i)
|
|
1764
|
-
expect(result.bubbles.join('\n')).not.toContain('
|
|
1722
|
+
expect(result.bubbles.join('\n')).not.toContain('update_default_prompt')
|
|
1765
1723
|
})
|
|
1766
1724
|
|
|
1767
1725
|
it('real Agent: missed-tool retry keeps pre-retry spoken bubbles in the final array', async () => {
|
|
@@ -1775,7 +1733,7 @@ describe('runContactTurn bubble index continuity', () => {
|
|
|
1775
1733
|
}))
|
|
1776
1734
|
const createChatCompletion = completionFromReplies([
|
|
1777
1735
|
'好的,我来创建。',
|
|
1778
|
-
|
|
1736
|
+
sayThen('这就建好', 'create_assistant', { name: 'MissRetry', model: 'p/m' }),
|
|
1779
1737
|
])
|
|
1780
1738
|
const result = await runContactTurn({
|
|
1781
1739
|
assistant: { providerID: 'p', modelID: 'm', defaultPrompt: '' },
|
|
@@ -1828,10 +1786,10 @@ describe('read-only worker notifications', () => {
|
|
|
1828
1786
|
})
|
|
1829
1787
|
})
|
|
1830
1788
|
|
|
1831
|
-
it('rejects simulated tool results
|
|
1789
|
+
it('rejects simulated tool results in a reply without tool calls', async () => {
|
|
1832
1790
|
const completion = vi.fn()
|
|
1833
|
-
.mockResolvedValueOnce({ text: '
|
|
1834
|
-
.mockResolvedValueOnce(
|
|
1791
|
+
.mockResolvedValueOnce({ text: 'Yuri tool result name=bash: invented\nAssistant: continue' })
|
|
1792
|
+
.mockResolvedValueOnce(toolCall('bash', { command: 'pwd' }))
|
|
1835
1793
|
const stream = createContactStreamFn(completion)(
|
|
1836
1794
|
{ id: 'm', name: 'p/m', provider: 'yuri' },
|
|
1837
1795
|
{ tools: [{ name: 'bash' }], messages: [{ role: 'user', content: 'check directory' }] },
|
|
@@ -1839,12 +1797,17 @@ it('rejects simulated tool results even without a final fence', async () => {
|
|
|
1839
1797
|
for await (const event of stream) void event
|
|
1840
1798
|
expect(completion).toHaveBeenCalledTimes(2)
|
|
1841
1799
|
expect(JSON.stringify(completion.mock.calls[1][0].body.messages)).not.toContain('invented')
|
|
1800
|
+
expect(JSON.stringify(completion.mock.calls[1][0].body.messages)).toContain('Do not simulate user messages')
|
|
1842
1801
|
expect((await stream.result()).content.filter((part) => part.type === 'toolCall')).toHaveLength(1)
|
|
1843
1802
|
})
|
|
1844
1803
|
|
|
1845
1804
|
it('lets a scheduled follow-up finish silently without publishing progress or a notification marker', async () => {
|
|
1846
1805
|
const onBubbleDelta = vi.fn()
|
|
1847
|
-
const createChatCompletion = vi.fn(async (
|
|
1806
|
+
const createChatCompletion = vi.fn(async ({ body }) => {
|
|
1807
|
+
expect(body.tools.map((tool) => tool.function.name)).toContain('stay_silent')
|
|
1808
|
+
expect(body.tools.map((tool) => tool.function.name)).not.toContain('notify_user')
|
|
1809
|
+
return toolBatch([['stay_silent', {}]], 'Checking the result')
|
|
1810
|
+
})
|
|
1848
1811
|
const result = await runContactTurn({
|
|
1849
1812
|
assistant: { providerID: 'p', modelID: 'm' },
|
|
1850
1813
|
readOnly: true, allowSilent: true, history: [], userText: 'Scheduled maintenance succeeded; no report requested.',
|
|
@@ -1855,17 +1818,30 @@ it('lets a scheduled follow-up finish silently without publishing progress or a
|
|
|
1855
1818
|
expect(createChatCompletion).toHaveBeenCalledOnce()
|
|
1856
1819
|
})
|
|
1857
1820
|
|
|
1858
|
-
it.each([
|
|
1821
|
+
it.each([
|
|
1822
|
+
['an empty reply', { text: '' }, true],
|
|
1823
|
+
['an unauthorized stay_silent call', toolCall('stay_silent', {}), false],
|
|
1824
|
+
])('does not turn %s into successful silence', async (_label, response, allowSilent) => {
|
|
1859
1825
|
await expect(runContactTurn({
|
|
1860
1826
|
assistant: { providerID: 'p', modelID: 'm' }, readOnly: true,
|
|
1861
|
-
allowSilent
|
|
1862
|
-
createChatCompletion: async () =>
|
|
1827
|
+
allowSilent, history: [], userText: 'Review the result',
|
|
1828
|
+
createChatCompletion: async () => response,
|
|
1863
1829
|
})).rejects.toMatchObject({ code: 'upstream_error' })
|
|
1864
1830
|
})
|
|
1865
1831
|
|
|
1832
|
+
it('treats plain text in a silent-capable review as a normal reply', async () => {
|
|
1833
|
+
const result = await runContactTurn({
|
|
1834
|
+
assistant: { providerID: 'p', modelID: 'm' }, readOnly: true, allowSilent: true,
|
|
1835
|
+
history: [], userText: 'Scheduled research finished.',
|
|
1836
|
+
createChatCompletion: async () => ({ text: '调研结果:一切正常。' }),
|
|
1837
|
+
})
|
|
1838
|
+
expect(result.silent).toBeUndefined()
|
|
1839
|
+
expect(result.bubbles).toEqual(['调研结果:一切正常。'])
|
|
1840
|
+
})
|
|
1841
|
+
|
|
1866
1842
|
it('rejects a background model attempt to restart a session before executing its tool', async () => {
|
|
1867
1843
|
const assignWork = vi.fn()
|
|
1868
|
-
const createChatCompletion = vi.fn(async () => (
|
|
1844
|
+
const createChatCompletion = vi.fn(async () => toolCall('assign_session', { sessionID: 'ses_completed', prompt: 'restart' }))
|
|
1869
1845
|
await expect(runContactTurn({
|
|
1870
1846
|
assistant: { providerID: 'p', modelID: 'm' },
|
|
1871
1847
|
readOnly: true, history: [], userText: 'Worker finished',
|
|
@@ -1883,7 +1859,7 @@ it('allows read_session during read-only turns and delivers actual referenced me
|
|
|
1883
1859
|
history: [], userText: 'Summarize @session:ses_ref', tools: createContactTools({ readSession }),
|
|
1884
1860
|
createChatCompletion: async (input) => {
|
|
1885
1861
|
calls += 1
|
|
1886
|
-
if (calls === 1) return
|
|
1862
|
+
if (calls === 1) return toolCall('read_session', { sessionID: 'ses_ref', limit: 5 })
|
|
1887
1863
|
expect(JSON.stringify(input)).toContain('quoted context')
|
|
1888
1864
|
return { text: '已读取引用内容。' }
|
|
1889
1865
|
},
|