@yuriai/web 0.2.8-beta.2 → 0.2.8
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-BjpY2u0c.js → AssistantView-CaLm2pDU.js} +3 -3
- package/dist/assets/{DiagramView-7j0sZC_P.js → DiagramView-Bh_Y3wjs.js} +1 -1
- package/dist/assets/{FadeInOnReveal-DkmfVoTO.js → FadeInOnReveal-NAFOww9Y.js} +1 -1
- package/dist/assets/{GuiPluginSurface-D_TK-2vZ.js → GuiPluginSurface-qGOqnbF5.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-CniMrVC7.js +2 -0
- package/dist/assets/{MarkdownRendererImpl-Dh7XVDLd.js → MarkdownRendererImpl-BoMHV8l0.js} +1 -1
- package/dist/assets/{MarkstreamRendererImpl-D-qtRrvg.js → MarkstreamRendererImpl-BXEZlJGP.js} +1 -1
- package/dist/assets/{MobileDetailNavigation-LkTVYLZX.js → MobileDetailNavigation-B6Ohvu93.js} +1 -1
- package/dist/assets/{MobileResizableSheet-C9YzOQis.js → MobileResizableSheet-BN07cmQQ.js} +1 -1
- package/dist/assets/{MobileShareBridge-CsTyKMtN.js → MobileShareBridge-DRx1mbUO.js} +1 -1
- package/dist/assets/MobileTabPageHeader-CHXNz-XU.js +2 -0
- package/dist/assets/{MultiRunWindow-hMpjV7so.js → MultiRunWindow-CWwawp5s.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-D8qpss-X.js → SettingsView-q2q_C3kF.js} +1 -1
- package/dist/assets/{SettingsWindow-B1VuFkFq.js → SettingsWindow-BO4fG8ON.js} +1 -1
- package/dist/assets/{TerminalView-CLcaJh2M.js → TerminalView-OVVhfpeZ.js} +1 -1
- package/dist/assets/{ToolOutputDialog-BuZo3XvN.js → ToolOutputDialog-CqirE_Q0.js} +1 -1
- package/dist/assets/{YuriLogo-DvRSd5NN.js → YuriLogo-kwLWc5Hi.js} +1 -1
- package/dist/assets/{appThemeRegistry-B7sp1Hw8.js → appThemeRegistry-Dg6MpoKd.js} +1 -1
- package/dist/assets/{button-BSFWH-Ok.js → button-Dodw6LWV.js} +1 -1
- package/dist/assets/{capgoAdapter-vxOdqloD.js → capgoAdapter-B7ToX3Rx.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-DspnKU8D.js → fileMentionTouchSelection-CHBe_36a.js} +1 -1
- package/dist/assets/{fr-YDYbYIZQ.js → fr-CPRTMaky.js} +1 -1
- package/dist/assets/{gitApi-BLYdWaG8.js → gitApi-CesLpypb.js} +1 -1
- package/dist/assets/{input-BhHXFla6.js → input-HddqDhRi.js} +1 -1
- package/dist/assets/{insertionBoundaries-DqlfZVY9.js → insertionBoundaries-BLxQiOvC.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-DA7z198b.js → main-DlTR1Jke.js} +2 -2
- package/dist/assets/{main-Qw23QJ7L.js → main-Z6Jwv7Aw.js} +4 -4
- package/dist/assets/{markdownHeightCache-DV2j4PlS.js → markdownHeightCache-BQiIj0aM.js} +1 -1
- package/dist/assets/{mcpQueries-C6Tu2cF3.js → mcpQueries-CZLOskV8.js} +1 -1
- package/dist/assets/{miniChat-HafcB3H-.js → miniChat-SzvTUnN9.js} +2 -2
- package/dist/assets/{mobile-DwXoGpxm.js → mobile-dh54OsZj.js} +2 -2
- package/dist/assets/{mobileBackNavigation-9MR5h5K6.js → mobileBackNavigation-D9_5Uqi3.js} +1 -1
- package/dist/assets/{multirun-D-je_w02.js → multirun-J_f9gEPw.js} +1 -1
- package/dist/assets/{native-config-Bb3pPQPD.js → native-config-Bohk_yve.js} +1 -1
- package/dist/assets/{pl-vh0XFuDb.js → pl-mUyhvp8O.js} +1 -1
- package/dist/assets/{projectMeta-DaCyZW_D.js → projectMeta-BH9vbJqs.js} +1 -1
- package/dist/assets/{pt-BR-Cv5tssQz.js → pt-BR-D3E4Wxao.js} +1 -1
- package/dist/assets/{readiness-BHqz_NPS.js → readiness-D1Glg4WD.js} +1 -1
- package/dist/assets/{renderElectronMiniChatApp-COaMALRh.js → renderElectronMiniChatApp-DM5OW4_M.js} +2 -2
- package/dist/assets/{renderMobileApp-BOGntDSu.js → renderMobileApp-CvDZu5Qx.js} +4 -4
- package/dist/assets/{runtimeConfig-BiSluBXe.js → runtimeConfig-CwEhy80T.js} +1 -1
- package/dist/assets/{runtimeEndpointReset-CJwlI_R-.js → runtimeEndpointReset-CFELYYml.js} +3 -3
- package/dist/assets/{scheduledTaskNavigation-BZ3B5bpN.js → scheduledTaskNavigation-CyPkVBKs.js} +1 -1
- package/dist/assets/{sessionChangeSummary-BAv8zzro.js → sessionChangeSummary-DnCiwEhi.js} +1 -1
- package/dist/assets/{sessionLookup-DOw7g15p.js → sessionLookup-BxXJcGxg.js} +1 -1
- package/dist/assets/{sortable-tabs-strip-BnTV_KYG.js → sortable-tabs-strip-C-qSUWlr.js} +1 -1
- package/dist/assets/{speechSettingsQueries-B8zEN5QM.js → speechSettingsQueries-7aN_QCn_.js} +1 -1
- package/dist/assets/src-BJ51FtVW.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-Dzzdq2e0.js +2 -0
- package/dist/assets/{uk-3a9vdLJ-.js → uk-D9iQbGbr.js} +1 -1
- package/dist/assets/{useAppFontEffects-De1qI6c-.js → useAppFontEffects-Ql6SjWay.js} +5 -5
- package/dist/assets/{useDesktopWindowControlsLayout-BzXi6Wf1.js → useDesktopWindowControlsLayout-DpovjCsM.js} +1 -1
- package/dist/assets/{useEffectiveDirectory-BcbBl_6y.js → useEffectiveDirectory-CjXQBqAr.js} +1 -1
- package/dist/assets/{useMobileNavigationStore-DqDCVXO1.js → useMobileNavigationStore-BTJNY1Yo.js} +6 -6
- package/dist/assets/{useWorkerHighlightedLines-CDVleuma.js → useWorkerHighlightedLines-cS9vGi9t.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 +16 -16
- package/server/lib/assistants/bubbles.js +0 -14
- package/server/lib/assistants/bubbles.test.js +1 -18
- package/server/lib/assistants/contact-tools.js +64 -231
- package/server/lib/assistants/contact-tools.test.js +29 -164
- package/server/lib/assistants/harness.js +72 -237
- package/server/lib/assistants/harness.test.js +199 -280
- 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/service.test.js +23 -42
- package/server/lib/scheduled-tasks/runtime.test.js +3 -3
- package/dist/assets/MarkdownRenderer-B8zgOCfr.js +0 -2
- package/dist/assets/MobileTabPageHeader-xz9RMXg4.js +0 -2
- package/dist/assets/src-NlrSCyPZ.css +0 -2
- package/dist/assets/types-BiP0jssb.js +0 -2
|
@@ -20,6 +20,11 @@ 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', () => {
|
|
24
29
|
it('offers scheduled-task lookup but no mutation or shell tools in read-only turns', async () => {
|
|
25
30
|
const seen = [];
|
|
@@ -44,7 +49,7 @@ describe('createContactStreamFn', () => {
|
|
|
44
49
|
if (round === 1) return { text: '', toolCalls: [{ id: 'list1', name: 'list_scheduled_tasks', arguments: {} }] };
|
|
45
50
|
expect(messages.some(message => message.role === 'tool' && message.tool_call_id === 'list1')).toBe(true);
|
|
46
51
|
if (round === 2) return { text: '', toolCalls: [{ id: 'update1', name: 'update_scheduled_task', arguments: { taskID: 'task1', projectID: 'project1', model: 'p/m' } }] };
|
|
47
|
-
return { text: '
|
|
52
|
+
return { text: '任务已更新。', toolCalls: [] };
|
|
48
53
|
},
|
|
49
54
|
});
|
|
50
55
|
const result = await runContactTurn({ assistant: { providerID: 'p', modelID: 'm' }, history: [], userText: '修改定时任务的模型', tools, createChatCompletion: completion });
|
|
@@ -95,7 +100,7 @@ describe('createContactStreamFn', () => {
|
|
|
95
100
|
if ((index === 3 && attempt <= 9) || (index === 4 && attempt <= 3)) return { text: '' }
|
|
96
101
|
return index <= 8
|
|
97
102
|
? { text: '', toolCalls: [{ id: `call_${index}`, name: 'get_assistant_settings', arguments: {} }], finishReason: 'tool-calls' }
|
|
98
|
-
: { text: '
|
|
103
|
+
: { text: 'Verified all eight steps.', toolCalls: [], finishReason: 'stop' }
|
|
99
104
|
})
|
|
100
105
|
const completion = (input) => gatewayCompletion({
|
|
101
106
|
...input, buildOpenCodeUrl: () => 'http://127.0.0.1:4096', getOpenCodeAuthHeaders: () => ({}),
|
|
@@ -119,7 +124,7 @@ describe('createContactStreamFn', () => {
|
|
|
119
124
|
const onBubbleDelta = vi.fn();
|
|
120
125
|
const completion = vi.fn(async ({ onTextDelta }) => {
|
|
121
126
|
onTextDelta('Private reasoning');
|
|
122
|
-
return { text: '
|
|
127
|
+
return { text: '已完成。' };
|
|
123
128
|
});
|
|
124
129
|
const result = await runContactTurn({
|
|
125
130
|
assistant: { providerID: 'p', modelID: 'm', variant: 'high' },
|
|
@@ -135,30 +140,23 @@ describe('createContactStreamFn', () => {
|
|
|
135
140
|
expect(JSON.stringify(onBubbleDelta.mock.calls)).not.toContain('Private reasoning');
|
|
136
141
|
});
|
|
137
142
|
|
|
138
|
-
it('publishes
|
|
139
|
-
let release;
|
|
140
|
-
const gate = new Promise((resolve) => { release = resolve })
|
|
143
|
+
it('publishes notify_user text before the tool executes and keeps narration beside it private', async () => {
|
|
141
144
|
const onBubbleDelta = vi.fn()
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
await gate
|
|
147
|
-
onTextDelta(tool)
|
|
148
|
-
return { text: prefix + tool }
|
|
149
|
-
})
|
|
145
|
+
const createChatCompletion = vi.fn(async () => toolBatch([
|
|
146
|
+
notifyCall('我先检查配置,再保存这次修改。'),
|
|
147
|
+
['read', { path: 'config.json' }, 'call_read'],
|
|
148
|
+
], 'I will plan the read privately.'))
|
|
150
149
|
const stream = createContactStreamFn(createChatCompletion, { onBubbleDelta })(
|
|
151
150
|
{ name: 'p/m', id: 'm', provider: 'yuri', api: 'openai-completions' },
|
|
152
|
-
{ messages: [], tools: [{ name: 'read' }] },
|
|
151
|
+
{ messages: [], tools: [{ name: 'read' }, { name: 'notify_user' }] },
|
|
153
152
|
)
|
|
154
|
-
try {
|
|
155
|
-
await vi.waitFor(() => expect(onBubbleDelta).toHaveBeenCalledWith(0, '我先检查配置,再保存这次修改。', true))
|
|
156
|
-
expect(onBubbleDelta).toHaveBeenCalledTimes(1)
|
|
157
|
-
} finally { release() }
|
|
158
153
|
const result = await stream.result()
|
|
154
|
+
expect(onBubbleDelta.mock.calls).toEqual([[0, '我先检查配置,再保存这次修改。', true]])
|
|
159
155
|
expect(projectStreamedContactTurnBubbles([result])).toEqual(['我先检查配置,再保存这次修改。'])
|
|
160
|
-
|
|
161
|
-
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')
|
|
162
160
|
})
|
|
163
161
|
|
|
164
162
|
it('keeps raw tokens, reasoning, partial public records and nested tool examples private', async () => {
|
|
@@ -184,9 +182,9 @@ describe('createContactStreamFn', () => {
|
|
|
184
182
|
const result = body.messages.find((m) => m.role === 'tool' && m.name === 'update_default_prompt')
|
|
185
183
|
if (result) {
|
|
186
184
|
expect(result.content).toContain('Default prompt saved.')
|
|
187
|
-
return { text: '
|
|
185
|
+
return { text: '提示词已保存,接下来的对话会按这个设置回复。' }
|
|
188
186
|
}
|
|
189
|
-
return
|
|
187
|
+
return toolBatch([notifyCall('我来保存这个默认提示词。'), ['update_default_prompt', { prompt: '简洁回复' }]])
|
|
190
188
|
})
|
|
191
189
|
const onBubbleDelta = vi.fn()
|
|
192
190
|
const result = await runContactTurn({
|
|
@@ -199,62 +197,53 @@ describe('createContactStreamFn', () => {
|
|
|
199
197
|
expect(result.text).not.toContain('Default prompt saved.')
|
|
200
198
|
})
|
|
201
199
|
|
|
202
|
-
it('preserves a published
|
|
200
|
+
it('preserves a published note on abort and suppresses later notes and tools', async () => {
|
|
203
201
|
const controller = new AbortController()
|
|
204
202
|
const onBubbleDelta = vi.fn()
|
|
205
|
-
const
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
{
|
|
214
|
-
|
|
215
|
-
|
|
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()
|
|
216
217
|
expect(onBubbleDelta.mock.calls).toEqual([[0, '我先确认设置。', true]])
|
|
217
218
|
})
|
|
218
219
|
|
|
219
|
-
it('
|
|
220
|
-
const onBubbleDelta = vi.fn()
|
|
221
|
-
const prefix = '```yuri-message\n{"text":"先确认一下。"}\n```\n'
|
|
222
|
-
const stream = createContactStreamFn(async ({ onTextDelta }) => {
|
|
223
|
-
onTextDelta(prefix.slice(0, 30))
|
|
224
|
-
return { text: prefix + '结果已确认。' }
|
|
225
|
-
}, { onBubbleDelta })(
|
|
226
|
-
{ name: 'p/m', id: 'm', provider: 'yuri', api: 'openai-completions' }, { messages: [] },
|
|
227
|
-
)
|
|
228
|
-
expect((await stream.result()).stopReason).toBe('stop')
|
|
229
|
-
expect(onBubbleDelta.mock.calls).toEqual([[0, '先确认一下。', true], [1, '结果已确认。', true]])
|
|
230
|
-
})
|
|
231
|
-
|
|
232
|
-
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 () => {
|
|
233
221
|
const onBubbleDelta = vi.fn()
|
|
234
222
|
const completion = vi.fn()
|
|
235
|
-
.mockResolvedValueOnce(
|
|
236
|
-
.mockResolvedValueOnce({ text: '
|
|
223
|
+
.mockResolvedValueOnce(toolBatch([notifyCall('我先检查配置。'), ['list_cron', {}]], 'I need to plan privately.'))
|
|
224
|
+
.mockResolvedValueOnce({ text: '请提供配置文件位置。' })
|
|
237
225
|
const stream = createContactStreamFn(completion, { onBubbleDelta })(
|
|
238
226
|
{ name: 'p/m', id: 'm', provider: 'yuri', api: 'openai-completions' },
|
|
239
|
-
{ messages: [], tools: [{ name: 'read' }] },
|
|
227
|
+
{ messages: [], tools: [{ name: 'read' }, { name: 'notify_user' }] },
|
|
240
228
|
)
|
|
241
229
|
const result = await stream.result()
|
|
242
|
-
expect(projectStreamedContactTurnBubbles([result])).toEqual(['
|
|
243
|
-
expect(onBubbleDelta.mock.calls).toEqual([[0, '
|
|
244
|
-
|
|
245
|
-
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('我先检查配置。')
|
|
246
236
|
})
|
|
247
237
|
|
|
248
|
-
it.each([
|
|
238
|
+
it.each([{ text: 42 }, { text: '' }, { text: 'x'.repeat(2001) }])('does not publish malformed notify_user text: %j', async (args) => {
|
|
249
239
|
const onBubbleDelta = vi.fn()
|
|
250
|
-
const
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
return { text }
|
|
254
|
-
}, { onBubbleDelta })(
|
|
255
|
-
{ 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' }] },
|
|
256
243
|
)
|
|
257
|
-
|
|
244
|
+
const result = await stream.result()
|
|
245
|
+
expect(result.stopReason).toBe('toolUse')
|
|
246
|
+
expect(result.content).toEqual([expect.objectContaining({ type: 'toolCall', name: 'notify_user' })])
|
|
258
247
|
expect(onBubbleDelta).not.toHaveBeenCalled()
|
|
259
248
|
})
|
|
260
249
|
|
|
@@ -262,7 +251,7 @@ describe('createContactStreamFn', () => {
|
|
|
262
251
|
const clearContactMemory = vi.fn(async () => ({ reset: true, memoryCleared: true }))
|
|
263
252
|
const onBubbleDelta = vi.fn()
|
|
264
253
|
const createChatCompletion = vi.fn()
|
|
265
|
-
.mockResolvedValueOnce(
|
|
254
|
+
.mockResolvedValueOnce(toolCall('new_conversation', {}))
|
|
266
255
|
.mockRejectedValueOnce(new Error('model unavailable'))
|
|
267
256
|
await expect(runContactTurn({
|
|
268
257
|
assistant: { providerID: 'p', modelID: 'm', variant: 'high' }, history: [], userText: '清除记忆',
|
|
@@ -289,9 +278,9 @@ describe('createContactStreamFn', () => {
|
|
|
289
278
|
const result = body.messages.find((message) => message.role === 'tool' && message.name === 'read')
|
|
290
279
|
if (result) {
|
|
291
280
|
expect(result.content).toContain('configured value')
|
|
292
|
-
return { completion: { choices: [{ message: { content: '
|
|
281
|
+
return { completion: { choices: [{ message: { content: 'configured value' } }] } }
|
|
293
282
|
}
|
|
294
|
-
return
|
|
283
|
+
return toolCall('read', { path: 'example-config.txt' })
|
|
295
284
|
})
|
|
296
285
|
try {
|
|
297
286
|
const result = await runContactTurn({
|
|
@@ -358,7 +347,7 @@ describe('createContactStreamFn', () => {
|
|
|
358
347
|
})
|
|
359
348
|
function AgentImpl(options) {
|
|
360
349
|
expect(options.initialState.thinkingLevel).toBe('off')
|
|
361
|
-
expect(options.initialState.tools).toEqual([])
|
|
350
|
+
expect(options.initialState.tools.map((tool) => tool.name)).toEqual(['notify_user'])
|
|
362
351
|
this.state = { ...options.initialState, messages: [] }
|
|
363
352
|
this.prompt = prompt
|
|
364
353
|
}
|
|
@@ -371,20 +360,12 @@ describe('createContactStreamFn', () => {
|
|
|
371
360
|
AgentImpl,
|
|
372
361
|
})
|
|
373
362
|
expect(result.thinkingLevel).toBe('off')
|
|
374
|
-
expect(result.tools).toEqual([])
|
|
363
|
+
expect(result.tools.map((tool) => tool.name)).toEqual(['notify_user'])
|
|
375
364
|
expect(prompt).toHaveBeenCalledWith('[attachment]')
|
|
376
365
|
})
|
|
377
366
|
|
|
378
|
-
it('replays
|
|
379
|
-
const createChatCompletion = vi.fn(async () => ({
|
|
380
|
-
completion: {
|
|
381
|
-
choices: [{
|
|
382
|
-
message: {
|
|
383
|
-
content: 'On it.\n\n```yuri-tool\n{"name":"assign_session","arguments":{"prompt":"Fix login"}}\n```',
|
|
384
|
-
},
|
|
385
|
-
}],
|
|
386
|
-
},
|
|
387
|
-
}))
|
|
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.'))
|
|
388
369
|
const streamFn = createContactStreamFn(createChatCompletion)
|
|
389
370
|
const events = []
|
|
390
371
|
const stream = streamFn(
|
|
@@ -396,21 +377,14 @@ describe('createContactStreamFn', () => {
|
|
|
396
377
|
)
|
|
397
378
|
for await (const event of stream) events.push(event)
|
|
398
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)
|
|
399
381
|
expect(events.at(-1)).toMatchObject({ type: 'done', reason: 'toolUse' })
|
|
400
382
|
expect(createChatCompletion.mock.calls[0][0].body.stream).toBeUndefined()
|
|
401
383
|
})
|
|
402
384
|
|
|
403
|
-
it('replays watch_session and stop_session
|
|
385
|
+
it('replays native watch_session and stop_session calls as toolUse bursts', async () => {
|
|
404
386
|
for (const name of ['watch_session', 'stop_session']) {
|
|
405
|
-
const createChatCompletion = vi.fn(async () => ({
|
|
406
|
-
completion: {
|
|
407
|
-
choices: [{
|
|
408
|
-
message: {
|
|
409
|
-
content: `\`\`\`yuri-tool\n${JSON.stringify({ name, arguments: { sessionID: 'ses_1' } })}\n\`\`\``,
|
|
410
|
-
},
|
|
411
|
-
}],
|
|
412
|
-
},
|
|
413
|
-
}))
|
|
387
|
+
const createChatCompletion = vi.fn(async () => toolCall(name, { sessionID: 'ses_1' }))
|
|
414
388
|
const events = []
|
|
415
389
|
const stream = createContactStreamFn(createChatCompletion)(
|
|
416
390
|
{ name: 'openai/gpt-5.2', id: 'gpt-5.2', provider: 'yuri', api: 'openai-completions' },
|
|
@@ -483,30 +457,6 @@ describe('createContactStreamFn', () => {
|
|
|
483
457
|
expect(result.bubbles.join('\n')).not.toContain('Watching that coding session')
|
|
484
458
|
})
|
|
485
459
|
|
|
486
|
-
it('replays a bare {name, arguments} object as a toolUse burst', async () => {
|
|
487
|
-
const createChatCompletion = vi.fn(async () => ({
|
|
488
|
-
completion: {
|
|
489
|
-
choices: [{
|
|
490
|
-
message: {
|
|
491
|
-
content: '好的 {"name":"create_assistant","arguments":{"name":"FlowNL"}}',
|
|
492
|
-
},
|
|
493
|
-
}],
|
|
494
|
-
},
|
|
495
|
-
}))
|
|
496
|
-
const streamFn = createContactStreamFn(createChatCompletion)
|
|
497
|
-
const events = []
|
|
498
|
-
const stream = streamFn(
|
|
499
|
-
{ name: 'opencode-go/deepseek-v4-flash', id: 'deepseek-v4-flash', provider: 'yuri', api: 'openai-completions' },
|
|
500
|
-
{
|
|
501
|
-
messages: [{ role: 'user', content: '新建助理 FlowNL', timestamp: 1 }],
|
|
502
|
-
tools: [{ name: 'create_assistant' }],
|
|
503
|
-
},
|
|
504
|
-
)
|
|
505
|
-
for await (const event of stream) events.push(event)
|
|
506
|
-
expect(events.some((event) => event.type === 'toolcall_end' && event.toolCall?.name === 'create_assistant')).toBe(true)
|
|
507
|
-
expect(events.at(-1)).toMatchObject({ type: 'done', reason: 'toolUse' })
|
|
508
|
-
})
|
|
509
|
-
|
|
510
460
|
it('passes onTextDelta and globalEventHub into createChatCompletion and forwards real deltas', async () => {
|
|
511
461
|
const deltas = []
|
|
512
462
|
const bubbleDeltas = []
|
|
@@ -533,35 +483,37 @@ describe('createContactStreamFn', () => {
|
|
|
533
483
|
expect(bubbleDeltas).toEqual([{ index: 0, delta: 'Hello world', done: true }])
|
|
534
484
|
})
|
|
535
485
|
|
|
536
|
-
it('
|
|
486
|
+
it('keeps native tool-call narration private while publishing notify_user text', async () => {
|
|
537
487
|
const bubbleDeltas = []
|
|
538
488
|
const createChatCompletion = vi.fn(async ({ onTextDelta }) => {
|
|
539
|
-
onTextDelta?.('
|
|
540
|
-
|
|
541
|
-
return {
|
|
542
|
-
completion: {
|
|
543
|
-
choices: [{
|
|
544
|
-
message: {
|
|
545
|
-
content: 'On it.\n\n```yuri-tool\n{"name":"assign_session","arguments":{"prompt":"x"}}\n```',
|
|
546
|
-
},
|
|
547
|
-
}],
|
|
548
|
-
},
|
|
549
|
-
}
|
|
489
|
+
onTextDelta?.('我先看看目录结构。')
|
|
490
|
+
return toolBatch([notifyCall('配置不在本地,改查服务端。'), ['bash', { command: 'ls' }, 'call_1']], '我先看看目录结构。')
|
|
550
491
|
})
|
|
551
|
-
const
|
|
492
|
+
const stream = createContactStreamFn(createChatCompletion, {
|
|
552
493
|
onBubbleDelta: (index, delta, done) => bubbleDeltas.push({ index, delta, done }),
|
|
553
|
-
})
|
|
554
|
-
const stream = streamFn(
|
|
494
|
+
})(
|
|
555
495
|
{ name: 'openai/gpt-5.2', id: 'gpt-5.2', provider: 'yuri', api: 'openai-completions' },
|
|
556
|
-
{
|
|
557
|
-
messages: [{ role: 'user', content: 'assign', timestamp: 1 }],
|
|
558
|
-
tools: [{ name: 'assign_session' }],
|
|
559
|
-
},
|
|
496
|
+
{ messages: [{ role: 'user', content: 'look', timestamp: 1 }], tools: [{ name: 'bash' }, { name: 'notify_user' }] },
|
|
560
497
|
)
|
|
561
498
|
for await (const event of stream) void event
|
|
562
|
-
const
|
|
563
|
-
expect(
|
|
564
|
-
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.')
|
|
565
517
|
})
|
|
566
518
|
|
|
567
519
|
it('emits final stripped bubbles as done:true once when no live deltas arrive', async () => {
|
|
@@ -600,6 +552,7 @@ describe('createContactStreamFn', () => {
|
|
|
600
552
|
{ type: 'text', text: 'Preamble A' },
|
|
601
553
|
{ type: 'toolCall', id: 'call_1', name: 'assign_session', arguments: { prompt: 'x' } },
|
|
602
554
|
],
|
|
555
|
+
contactPublicText: true,
|
|
603
556
|
},
|
|
604
557
|
{
|
|
605
558
|
role: 'toolResult',
|
|
@@ -628,7 +581,7 @@ describe('runContactTurn', () => {
|
|
|
628
581
|
const createChatCompletion = vi.fn(async ({ signal }) => {
|
|
629
582
|
expect(signal).toBe(controller.signal)
|
|
630
583
|
controller.abort()
|
|
631
|
-
return
|
|
584
|
+
return toolCall('write', { path: 'late.txt', content: 'must not happen' })
|
|
632
585
|
})
|
|
633
586
|
try {
|
|
634
587
|
await expect(runContactTurn({
|
|
@@ -640,16 +593,14 @@ describe('runContactTurn', () => {
|
|
|
640
593
|
} finally { fs.rmSync(workspace, { recursive: true, force: true }) }
|
|
641
594
|
})
|
|
642
595
|
|
|
643
|
-
it('writes
|
|
596
|
+
it('writes tool-shaped text as data and never executes tool JSON from a final reply', async () => {
|
|
644
597
|
const workspace = fs.mkdtempSync(path.join(os.tmpdir(), 'yuri-protocol-data-'))
|
|
645
|
-
const example = '```
|
|
646
|
-
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```'
|
|
647
599
|
const replies = [
|
|
648
|
-
[
|
|
649
|
-
|
|
650
|
-
'```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 },
|
|
651
602
|
]
|
|
652
|
-
const createChatCompletion = vi.fn(async () =>
|
|
603
|
+
const createChatCompletion = vi.fn(async () => replies.shift() || { text: '' })
|
|
653
604
|
try {
|
|
654
605
|
const result = await runContactTurn({
|
|
655
606
|
assistant: { providerID: 'p', modelID: 'm', effectiveWorkspacePath: workspace },
|
|
@@ -658,7 +609,7 @@ describe('runContactTurn', () => {
|
|
|
658
609
|
expect(fs.readFileSync(path.join(workspace, 'example.md'), 'utf8')).toBe(example)
|
|
659
610
|
expect(fs.readFileSync(path.join(workspace, 'count.txt'), 'utf8')).toBe('x')
|
|
660
611
|
expect(result.text).toBe(example)
|
|
661
|
-
expect(createChatCompletion).toHaveBeenCalledTimes(
|
|
612
|
+
expect(createChatCompletion).toHaveBeenCalledTimes(2)
|
|
662
613
|
const messages = createChatCompletion.mock.calls[1][0].body.messages
|
|
663
614
|
const emptyResult = messages.find((message) => message.role === 'tool' && message.name === 'bash')
|
|
664
615
|
expect(emptyResult).toBeTruthy()
|
|
@@ -668,20 +619,19 @@ describe('runContactTurn', () => {
|
|
|
668
619
|
}
|
|
669
620
|
})
|
|
670
621
|
|
|
671
|
-
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 () => {
|
|
672
623
|
const workspace = fs.mkdtempSync(path.join(os.tmpdir(), 'yuri-skill-loop-'))
|
|
673
624
|
const skillPath = '.agents/skills/note/SKILL.md'
|
|
674
625
|
fs.mkdirSync(path.dirname(path.join(workspace, skillPath)), { recursive: true })
|
|
675
626
|
fs.writeFileSync(path.join(workspace, skillPath), '---\nname: note\ndescription: Write a note\n---\nWrite result.txt then read it to verify.\n')
|
|
676
|
-
const fence = (name, args) => '```yuri-tool\n' + JSON.stringify({ name, arguments: args }) + '\n```'
|
|
677
627
|
const replies = [
|
|
678
|
-
|
|
679
|
-
'
|
|
680
|
-
[
|
|
681
|
-
|
|
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: '已写入并验证。' },
|
|
682
632
|
]
|
|
683
633
|
const onBubbleDelta = vi.fn()
|
|
684
|
-
const createChatCompletion = vi.fn(async () =>
|
|
634
|
+
const createChatCompletion = vi.fn(async () => replies.shift() || { text: '' })
|
|
685
635
|
try {
|
|
686
636
|
const result = await runContactTurn({
|
|
687
637
|
assistant: { providerID: 'p', modelID: 'm', effectiveWorkspacePath: workspace },
|
|
@@ -689,7 +639,7 @@ describe('runContactTurn', () => {
|
|
|
689
639
|
tools: createContactTools({}), createChatCompletion, onBubbleDelta,
|
|
690
640
|
})
|
|
691
641
|
expect(fs.readFileSync(path.join(workspace, 'result.txt'), 'utf8')).toBe('verified note')
|
|
692
|
-
expect(result.
|
|
642
|
+
expect(result.bubbles).toEqual(['笔记会写入 result.txt,写完再读回验证。', '已写入并验证。'])
|
|
693
643
|
expect(createChatCompletion).toHaveBeenCalledTimes(4)
|
|
694
644
|
const lastRequest = createChatCompletion.mock.calls.at(-1)[0].body.messages
|
|
695
645
|
const calls = JSON.stringify(lastRequest.filter((m) => m.role === 'assistant'))
|
|
@@ -697,23 +647,24 @@ describe('runContactTurn', () => {
|
|
|
697
647
|
expect(calls).toContain('"name":"write"')
|
|
698
648
|
expect(lastRequest.flatMap(message => message.tool_calls ?? []).map(call => JSON.parse(call.function.arguments))).toContainEqual(expect.objectContaining({ path: 'result.txt' }))
|
|
699
649
|
const results = lastRequest.filter((m) => m.role === 'tool')
|
|
700
|
-
expect(results).
|
|
650
|
+
expect(results.map((m) => m.name)).toEqual(['read', 'notify_user', 'write', 'read'])
|
|
701
651
|
expect(results.at(-1).content).toContain('verified note')
|
|
652
|
+
expect(onBubbleDelta.mock.calls.map((call) => call[1])).toEqual(result.bubbles)
|
|
702
653
|
expect(onBubbleDelta.mock.calls.map((call) => call[1]).join('')).not.toContain('我先')
|
|
703
654
|
} finally {
|
|
704
655
|
fs.rmSync(workspace, { recursive: true, force: true })
|
|
705
656
|
}
|
|
706
657
|
})
|
|
707
658
|
|
|
708
|
-
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 () => {
|
|
709
660
|
const workspace = fs.mkdtempSync(path.join(os.tmpdir(), 'yuri-skill-stall-'))
|
|
710
|
-
const createChatCompletion = vi.fn(async () => ({ text: '
|
|
661
|
+
const createChatCompletion = vi.fn(async () => ({ text: 'Tool: write ok\nUser: 好的' }))
|
|
711
662
|
const onBubbleDelta = vi.fn()
|
|
712
663
|
try {
|
|
713
664
|
await expect(runContactTurn({
|
|
714
665
|
assistant: { providerID: 'p', modelID: 'm', effectiveWorkspacePath: workspace },
|
|
715
666
|
history: [], userText: '请写入笔记。', skillHomeDir: path.join(workspace, 'home'), createChatCompletion, onBubbleDelta,
|
|
716
|
-
})).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.')
|
|
717
668
|
expect(createChatCompletion).toHaveBeenCalledTimes(3)
|
|
718
669
|
expect(onBubbleDelta).not.toHaveBeenCalled()
|
|
719
670
|
} finally {
|
|
@@ -721,9 +672,9 @@ describe('runContactTurn', () => {
|
|
|
721
672
|
}
|
|
722
673
|
})
|
|
723
674
|
|
|
724
|
-
it('
|
|
675
|
+
it('accepts a plain blocked answer without inventing another tool operation', async () => {
|
|
725
676
|
const workspace = fs.mkdtempSync(path.join(os.tmpdir(), 'yuri-skill-blocked-'))
|
|
726
|
-
const createChatCompletion = vi.fn(async () => ({ text: '
|
|
677
|
+
const createChatCompletion = vi.fn(async () => ({ text: '缺少要记录的内容,请提供正文。' }))
|
|
727
678
|
try {
|
|
728
679
|
const result = await runContactTurn({
|
|
729
680
|
assistant: { providerID: 'p', modelID: 'm', effectiveWorkspacePath: workspace },
|
|
@@ -739,9 +690,9 @@ describe('runContactTurn', () => {
|
|
|
739
690
|
it('rejects a batch containing a terminal contact operation before running any tool', async () => {
|
|
740
691
|
const workspace = fs.mkdtempSync(path.join(os.tmpdir(), 'yuri-contact-batch-'))
|
|
741
692
|
const assignWork = vi.fn(async () => ({ sessionID: 'ses_once', directory: workspace, title: 'Work', status: 'busy' }))
|
|
742
|
-
const assign = '
|
|
743
|
-
const replies = [assign
|
|
744
|
-
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: '' })
|
|
745
696
|
try {
|
|
746
697
|
const result = await runContactTurn({
|
|
747
698
|
assistant: { providerID: 'p', modelID: 'm', effectiveWorkspacePath: workspace },
|
|
@@ -751,6 +702,8 @@ describe('runContactTurn', () => {
|
|
|
751
702
|
expect(assignWork).toHaveBeenCalledTimes(1)
|
|
752
703
|
expect(result.cards[0].sessionID).toBe('ses_once')
|
|
753
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(['任务已经交给工作会话。'])
|
|
754
707
|
} finally {
|
|
755
708
|
fs.rmSync(workspace, { recursive: true, force: true })
|
|
756
709
|
}
|
|
@@ -765,23 +718,24 @@ describe('runContactTurn', () => {
|
|
|
765
718
|
const assignWork = vi.fn(async () => ({ sessionID: 'ses_mixed', directory: workspace, title: 'Fix', status: 'busy' }))
|
|
766
719
|
const tools = createContactTools({ assignWork })
|
|
767
720
|
const replies = [
|
|
768
|
-
'
|
|
769
|
-
'Only documentation search is available.',
|
|
770
|
-
|
|
771
|
-
'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.' },
|
|
772
725
|
]
|
|
773
726
|
let call = 0
|
|
774
727
|
const createChatCompletion = vi.fn(async ({ body }) => {
|
|
775
|
-
if (call === 3) return
|
|
728
|
+
if (call === 3) return replies[call++]
|
|
776
729
|
expect(body.messages[0].content).toContain('assign_session')
|
|
777
730
|
expect(body.messages[0].content).toContain('docs')
|
|
778
|
-
expect(body.messages[0].content).toContain('
|
|
779
|
-
expect(body.messages[0].content).toContain('
|
|
780
|
-
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')
|
|
781
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']))
|
|
782
736
|
const content = replies[call++]
|
|
783
737
|
if (!content) throw new Error('Unexpected completion')
|
|
784
|
-
return
|
|
738
|
+
return content
|
|
785
739
|
})
|
|
786
740
|
try {
|
|
787
741
|
const result = await runContactTurn({
|
|
@@ -789,7 +743,7 @@ describe('runContactTurn', () => {
|
|
|
789
743
|
history: [], userText: '再建个会话去修这个问题', tools,
|
|
790
744
|
projects: [{ id: 'project', path: workspace }], skillHomeDir: home, createChatCompletion,
|
|
791
745
|
})
|
|
792
|
-
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'])
|
|
793
747
|
expect(assignWork).toHaveBeenCalledTimes(1)
|
|
794
748
|
expect(result.cards).toEqual([expect.objectContaining({ sessionID: 'ses_mixed' })])
|
|
795
749
|
// Assignment terminates mutations; a tools-disabled completion summarizes the result.
|
|
@@ -821,15 +775,7 @@ describe('runContactTurn', () => {
|
|
|
821
775
|
if (completions > 8) {
|
|
822
776
|
throw new Error('harness safety stop: too many completions without terminate')
|
|
823
777
|
}
|
|
824
|
-
return {
|
|
825
|
-
completion: {
|
|
826
|
-
choices: [{
|
|
827
|
-
message: {
|
|
828
|
-
content: '```yuri-tool\n{"name":"assign_session","arguments":{"prompt":"Fix login","projectPath":"/repo"}}\n```',
|
|
829
|
-
},
|
|
830
|
-
}],
|
|
831
|
-
},
|
|
832
|
-
}
|
|
778
|
+
return toolCall('assign_session', { prompt: 'Fix login', projectPath: '/repo' })
|
|
833
779
|
})
|
|
834
780
|
const result = await runContactTurn({
|
|
835
781
|
assistant: { providerID: 'p', modelID: 'm', defaultPrompt: '' },
|
|
@@ -868,37 +814,13 @@ describe('runContactTurn', () => {
|
|
|
868
814
|
const last = body.messages.at(-1)
|
|
869
815
|
const lastText = typeof last?.content === 'string' ? last.content : ''
|
|
870
816
|
if (body.messages.at(-1)?.name === 'list_projects' || lastText.includes('Registered projects')) {
|
|
871
|
-
return {
|
|
872
|
-
completion: {
|
|
873
|
-
choices: [{
|
|
874
|
-
message: {
|
|
875
|
-
content: '```yuri-tool\n{"name":"assign_session","arguments":{"prompt":"Fix","projectPath":"/repo"}}\n```',
|
|
876
|
-
},
|
|
877
|
-
}],
|
|
878
|
-
},
|
|
879
|
-
}
|
|
817
|
+
return toolCall('assign_session', { prompt: 'Fix', projectPath: '/repo' })
|
|
880
818
|
}
|
|
881
819
|
if (completions === 1) {
|
|
882
|
-
return {
|
|
883
|
-
completion: {
|
|
884
|
-
choices: [{
|
|
885
|
-
message: {
|
|
886
|
-
content: '```yuri-tool\n{"name":"list_projects","arguments":{"query":"repo"}}\n```',
|
|
887
|
-
},
|
|
888
|
-
}],
|
|
889
|
-
},
|
|
890
|
-
}
|
|
820
|
+
return toolCall('list_projects', { query: 'repo' })
|
|
891
821
|
}
|
|
892
822
|
// If assign did not terminate, a looping model would keep assigning — fail closed.
|
|
893
|
-
return {
|
|
894
|
-
completion: {
|
|
895
|
-
choices: [{
|
|
896
|
-
message: {
|
|
897
|
-
content: '```yuri-tool\n{"name":"assign_session","arguments":{"prompt":"Fix again","projectPath":"/repo"}}\n```',
|
|
898
|
-
},
|
|
899
|
-
}],
|
|
900
|
-
},
|
|
901
|
-
}
|
|
823
|
+
return toolCall('assign_session', { prompt: 'Fix again', projectPath: '/repo' })
|
|
902
824
|
})
|
|
903
825
|
const result = await runContactTurn({
|
|
904
826
|
assistant: { providerID: 'p', modelID: 'm', defaultPrompt: '' },
|
|
@@ -940,7 +862,7 @@ describe('runContactTurn', () => {
|
|
|
940
862
|
expect(result.bubbles).toEqual(['Only document search is available.', '已安排工作。'])
|
|
941
863
|
expect(result.bubbles.join('\n')).not.toContain('Opened session.')
|
|
942
864
|
})
|
|
943
|
-
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 () => {
|
|
944
866
|
const prompt = vi.fn(async function prompt() {
|
|
945
867
|
this.state.messages = [{
|
|
946
868
|
role: 'assistant',
|
|
@@ -949,7 +871,7 @@ describe('runContactTurn', () => {
|
|
|
949
871
|
})
|
|
950
872
|
function AgentImpl(options) {
|
|
951
873
|
expect(options.initialState.thinkingLevel).toBe('off')
|
|
952
|
-
expect(options.initialState.tools).toEqual([])
|
|
874
|
+
expect(options.initialState.tools.map((tool) => tool.name)).toEqual(['notify_user'])
|
|
953
875
|
this.state = { ...options.initialState, messages: [] }
|
|
954
876
|
this.prompt = prompt
|
|
955
877
|
}
|
|
@@ -979,7 +901,7 @@ describe('runContactTurn', () => {
|
|
|
979
901
|
fs.writeFileSync(path.join(globalAgents, 'SKILL.md'), '---\nname: global-skill\ndescription: Global agents skill\n---\nDo the global thing\n')
|
|
980
902
|
function AgentImpl(options) {
|
|
981
903
|
expect(options.initialState.thinkingLevel).toBe('off')
|
|
982
|
-
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'])
|
|
983
905
|
expect(options.initialState.systemPrompt).toContain(workspace)
|
|
984
906
|
expect(options.initialState.systemPrompt).toContain('Be terse.')
|
|
985
907
|
expect(options.initialState.systemPrompt).toContain('project-skill')
|
|
@@ -1060,17 +982,11 @@ describe('runContactTurn', () => {
|
|
|
1060
982
|
const createChatCompletion = vi.fn(async ({ body }) => {
|
|
1061
983
|
calls += 1
|
|
1062
984
|
if (calls === 1) {
|
|
1063
|
-
return {
|
|
1064
|
-
completion: {
|
|
1065
|
-
choices: [{
|
|
1066
|
-
message: { content: '```yuri-tool\n{"name":"bash","arguments":{"command":"pwd"}}\n```' },
|
|
1067
|
-
}],
|
|
1068
|
-
},
|
|
1069
|
-
}
|
|
985
|
+
return toolCall('bash', { command: 'pwd' })
|
|
1070
986
|
}
|
|
1071
987
|
const last = body.messages.at(-1)
|
|
1072
988
|
const content = typeof last?.content === 'string' ? last.content : ''
|
|
1073
|
-
return { completion: { choices: [{ message: { content:
|
|
989
|
+
return { completion: { choices: [{ message: { content: content || 'done' } }] } }
|
|
1074
990
|
})
|
|
1075
991
|
try {
|
|
1076
992
|
const result = await runContactTurn({
|
|
@@ -1104,7 +1020,7 @@ describe('runContactTurn', () => {
|
|
|
1104
1020
|
}
|
|
1105
1021
|
function AgentImpl(options) {
|
|
1106
1022
|
expect(options.initialState.thinkingLevel).toBe('off')
|
|
1107
|
-
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'])
|
|
1108
1024
|
expect(options.initialState.tools.some((tool) => ['bash', 'edit', 'read', 'write'].includes(tool.name))).toBe(false)
|
|
1109
1025
|
expect(options.initialState.systemPrompt).toContain('assign_session')
|
|
1110
1026
|
expect(options.initialState.systemPrompt).toContain('create_assistant')
|
|
@@ -1200,7 +1116,7 @@ describe('runContactTurn', () => {
|
|
|
1200
1116
|
expect(result.cards).toEqual([expect.objectContaining({ sessionID: 'ses_plan' })])
|
|
1201
1117
|
})
|
|
1202
1118
|
|
|
1203
|
-
it('keeps a short
|
|
1119
|
+
it('keeps a short notify_user preamble then the model summary', async () => {
|
|
1204
1120
|
function AgentImpl(options) {
|
|
1205
1121
|
this.state = { ...options.initialState, messages: [] }
|
|
1206
1122
|
this.prompt = async () => {
|
|
@@ -1211,6 +1127,7 @@ describe('runContactTurn', () => {
|
|
|
1211
1127
|
{ type: 'text', text: '我去找一下' },
|
|
1212
1128
|
{ type: 'toolCall', id: 'call_1', name: 'assign_session', arguments: { prompt: 'x' } },
|
|
1213
1129
|
],
|
|
1130
|
+
contactPublicText: true,
|
|
1214
1131
|
},
|
|
1215
1132
|
{
|
|
1216
1133
|
role: 'toolResult',
|
|
@@ -1254,6 +1171,7 @@ describe('runContactTurn', () => {
|
|
|
1254
1171
|
{ type: 'text', text: '我去读一下这个会话。' },
|
|
1255
1172
|
{ type: 'toolCall', id: 'call_r', name: 'read_session', arguments: { sessionID: 'ses_quote' } },
|
|
1256
1173
|
],
|
|
1174
|
+
contactPublicText: true,
|
|
1257
1175
|
},
|
|
1258
1176
|
{
|
|
1259
1177
|
role: 'toolResult',
|
|
@@ -1291,6 +1209,7 @@ describe('runContactTurn', () => {
|
|
|
1291
1209
|
{ type: 'text', text: '我去读一下这个会话。' },
|
|
1292
1210
|
{ type: 'toolCall', id: 'call_r', name: 'read_session', arguments: { sessionID: 'ses_quote' } },
|
|
1293
1211
|
],
|
|
1212
|
+
contactPublicText: true,
|
|
1294
1213
|
},
|
|
1295
1214
|
{
|
|
1296
1215
|
role: 'toolResult',
|
|
@@ -1566,16 +1485,8 @@ describe('runContactTurn', () => {
|
|
|
1566
1485
|
if (completions > 4) {
|
|
1567
1486
|
throw new Error('harness safety stop: clear_chat_history must terminate without follow-up LLM')
|
|
1568
1487
|
}
|
|
1569
|
-
// Looping model would keep emitting wipe
|
|
1570
|
-
return {
|
|
1571
|
-
completion: {
|
|
1572
|
-
choices: [{
|
|
1573
|
-
message: {
|
|
1574
|
-
content: '```yuri-tool\n{"name":"clear_chat_history","arguments":{}}\n```',
|
|
1575
|
-
},
|
|
1576
|
-
}],
|
|
1577
|
-
},
|
|
1578
|
-
}
|
|
1488
|
+
// Looping model would keep emitting wipe calls; terminate must stop after one tool run.
|
|
1489
|
+
return toolCall('clear_chat_history', {})
|
|
1579
1490
|
})
|
|
1580
1491
|
const result = await runContactTurn({
|
|
1581
1492
|
assistant: { providerID: 'p', modelID: 'm', defaultPrompt: '' },
|
|
@@ -1611,15 +1522,7 @@ describe('runContactTurn', () => {
|
|
|
1611
1522
|
if (completions > 4) {
|
|
1612
1523
|
throw new Error('harness safety stop: wipe must terminate once')
|
|
1613
1524
|
}
|
|
1614
|
-
return {
|
|
1615
|
-
completion: {
|
|
1616
|
-
choices: [{
|
|
1617
|
-
message: {
|
|
1618
|
-
content: '```yuri-tool\n{"name":"clear_chat_history","arguments":{}}\n```',
|
|
1619
|
-
},
|
|
1620
|
-
}],
|
|
1621
|
-
},
|
|
1622
|
-
}
|
|
1525
|
+
return toolCall('clear_chat_history', {})
|
|
1623
1526
|
})
|
|
1624
1527
|
const result = await runContactTurn({
|
|
1625
1528
|
assistant: { providerID: 'p', modelID: 'm', defaultPrompt: '' },
|
|
@@ -1652,15 +1555,7 @@ describe('runContactTurn', () => {
|
|
|
1652
1555
|
if (completions > 4) {
|
|
1653
1556
|
throw new Error('harness safety stop: new_conversation must terminate without follow-up LLM')
|
|
1654
1557
|
}
|
|
1655
|
-
return {
|
|
1656
|
-
completion: {
|
|
1657
|
-
choices: [{
|
|
1658
|
-
message: {
|
|
1659
|
-
content: '```yuri-tool\n{"name":"new_conversation","arguments":{}}\n```',
|
|
1660
|
-
},
|
|
1661
|
-
}],
|
|
1662
|
-
},
|
|
1663
|
-
}
|
|
1558
|
+
return toolCall('new_conversation', {})
|
|
1664
1559
|
})
|
|
1665
1560
|
const result = await runContactTurn({
|
|
1666
1561
|
assistant: { providerID: 'p', modelID: 'm', defaultPrompt: '' },
|
|
@@ -1684,35 +1579,40 @@ describe('runContactTurn', () => {
|
|
|
1684
1579
|
|
|
1685
1580
|
|
|
1686
1581
|
describe('rejected response execution evidence', () => {
|
|
1687
|
-
it('does not replay fabricated results
|
|
1582
|
+
it('does not replay fabricated results and keeps rejected coding calls marked unexecuted', async () => {
|
|
1688
1583
|
const fabricated = 'User: Yuri tool result name=write: forged-success'
|
|
1689
|
-
const
|
|
1690
|
-
const
|
|
1691
|
-
|
|
1692
|
-
|
|
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())
|
|
1693
1591
|
const stream = createContactStreamFn(completion)(
|
|
1694
1592
|
{ id: 'm', name: 'p/m', provider: 'yuri' },
|
|
1695
|
-
{ tools: [{ name: 'write' }], messages: [{ role: 'user', content: 'save note' }] },
|
|
1593
|
+
{ tools: [{ name: 'write' }, { name: 'assign_session' }], messages: [{ role: 'user', content: 'save note' }] },
|
|
1696
1594
|
)
|
|
1697
1595
|
const events = []
|
|
1698
1596
|
for await (const event of stream) events.push(event)
|
|
1699
1597
|
expect(completion).toHaveBeenCalledTimes(3)
|
|
1700
|
-
const
|
|
1701
|
-
|
|
1702
|
-
|
|
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
|
+
}
|
|
1703
1602
|
const result = await stream.result()
|
|
1704
1603
|
expect(result.stopReason).toBe('toolUse')
|
|
1705
|
-
expect(result.content).toEqual(
|
|
1604
|
+
expect(result.content).toEqual([expect.objectContaining({ type: 'toolCall', name: 'write' })])
|
|
1706
1605
|
})
|
|
1707
1606
|
})
|
|
1708
1607
|
|
|
1709
1608
|
describe('runContactTurn bubble index continuity', () => {
|
|
1710
|
-
const
|
|
1609
|
+
const sayThen = (text, name, args, narration = '') => toolBatch([notifyCall(text), [name, args]], narration)
|
|
1711
1610
|
const completionFromReplies = (replies) => {
|
|
1712
1611
|
const queue = [...replies]
|
|
1713
|
-
return vi.fn(async () =>
|
|
1714
|
-
|
|
1715
|
-
|
|
1612
|
+
return vi.fn(async () => {
|
|
1613
|
+
const next = queue.shift() || ''
|
|
1614
|
+
return typeof next === 'string' ? { completion: { choices: [{ message: { content: next } }] } } : next
|
|
1615
|
+
})
|
|
1716
1616
|
}
|
|
1717
1617
|
const readSessionTools = (sessionID = 'ses_idx') => createContactTools({
|
|
1718
1618
|
readSession: async () => ({
|
|
@@ -1724,7 +1624,7 @@ describe('runContactTurn bubble index continuity', () => {
|
|
|
1724
1624
|
it('real Agent gateway stub: preamble then read_session then multi-bubble final keeps stable SSE indices', async () => {
|
|
1725
1625
|
const bubbleDeltas = []
|
|
1726
1626
|
const createChatCompletion = completionFromReplies([
|
|
1727
|
-
|
|
1627
|
+
sayThen('我去读一下', 'read_session', { sessionID: 'ses_idx' }, '先私下确认会话 ID。'),
|
|
1728
1628
|
'办好了。\n\n还有后续说明。',
|
|
1729
1629
|
])
|
|
1730
1630
|
const result = await runContactTurn({
|
|
@@ -1743,6 +1643,7 @@ describe('runContactTurn bubble index continuity', () => {
|
|
|
1743
1643
|
{ index: 2, delta: '还有后续说明。' },
|
|
1744
1644
|
])
|
|
1745
1645
|
expect(result.bubbles).toEqual(['我去读一下', '办好了。', '还有后续说明。'])
|
|
1646
|
+
expect(result.bubbles.join('\n')).not.toContain('私下确认')
|
|
1746
1647
|
// Published stream is a stable prefix of the final array.
|
|
1747
1648
|
expect(result.bubbles.slice(0, doneBubbles.length)).toEqual(doneBubbles.map((item) => item.delta))
|
|
1748
1649
|
})
|
|
@@ -1750,8 +1651,8 @@ describe('runContactTurn bubble index continuity', () => {
|
|
|
1750
1651
|
it('real Agent: two read_session preambles keep both spoken lines plus final in bubbles', async () => {
|
|
1751
1652
|
const bubbleDeltas = []
|
|
1752
1653
|
const createChatCompletion = completionFromReplies([
|
|
1753
|
-
|
|
1754
|
-
|
|
1654
|
+
sayThen('我去读一下', 'read_session', { sessionID: 'ses_a' }),
|
|
1655
|
+
sayThen('我再读一下', 'read_session', { sessionID: 'ses_b' }),
|
|
1755
1656
|
'办好了',
|
|
1756
1657
|
])
|
|
1757
1658
|
const result = await runContactTurn({
|
|
@@ -1772,8 +1673,8 @@ describe('runContactTurn bubble index continuity', () => {
|
|
|
1772
1673
|
it('real Agent: duplicate preamble text is kept as independent bubbles', async () => {
|
|
1773
1674
|
const bubbleDeltas = []
|
|
1774
1675
|
const createChatCompletion = completionFromReplies([
|
|
1775
|
-
|
|
1776
|
-
|
|
1676
|
+
sayThen('我去读一下', 'read_session', { sessionID: 'ses_a' }),
|
|
1677
|
+
sayThen('我去读一下', 'read_session', { sessionID: 'ses_b' }),
|
|
1777
1678
|
'办好了',
|
|
1778
1679
|
])
|
|
1779
1680
|
const result = await runContactTurn({
|
|
@@ -1794,8 +1695,8 @@ describe('runContactTurn bubble index continuity', () => {
|
|
|
1794
1695
|
// Two independent short spokens (each tool turn); confirm-only tool text appends at end.
|
|
1795
1696
|
// update_default_prompt is terminate:false so a plain final closes the agent loop.
|
|
1796
1697
|
const createChatCompletion = completionFromReplies([
|
|
1797
|
-
|
|
1798
|
-
|
|
1698
|
+
sayThen('我先看一下', 'list_sessions', { query: 'login' }),
|
|
1699
|
+
sayThen('马上改人设', 'update_default_prompt', { prompt: 'be brief' }),
|
|
1799
1700
|
'改好了',
|
|
1800
1701
|
])
|
|
1801
1702
|
const tools = createContactTools({
|
|
@@ -1818,7 +1719,7 @@ describe('runContactTurn bubble index continuity', () => {
|
|
|
1818
1719
|
expect(result.bubbles).toHaveLength(3)
|
|
1819
1720
|
expect(result.bubbles.slice(0, doneBubbles.length)).toEqual(doneBubbles)
|
|
1820
1721
|
expect(result.bubbles.join('')).not.toMatch(/Default prompt/i)
|
|
1821
|
-
expect(result.bubbles.join('\n')).not.toContain('
|
|
1722
|
+
expect(result.bubbles.join('\n')).not.toContain('update_default_prompt')
|
|
1822
1723
|
})
|
|
1823
1724
|
|
|
1824
1725
|
it('real Agent: missed-tool retry keeps pre-retry spoken bubbles in the final array', async () => {
|
|
@@ -1832,7 +1733,7 @@ describe('runContactTurn bubble index continuity', () => {
|
|
|
1832
1733
|
}))
|
|
1833
1734
|
const createChatCompletion = completionFromReplies([
|
|
1834
1735
|
'好的,我来创建。',
|
|
1835
|
-
|
|
1736
|
+
sayThen('这就建好', 'create_assistant', { name: 'MissRetry', model: 'p/m' }),
|
|
1836
1737
|
])
|
|
1837
1738
|
const result = await runContactTurn({
|
|
1838
1739
|
assistant: { providerID: 'p', modelID: 'm', defaultPrompt: '' },
|
|
@@ -1885,10 +1786,10 @@ describe('read-only worker notifications', () => {
|
|
|
1885
1786
|
})
|
|
1886
1787
|
})
|
|
1887
1788
|
|
|
1888
|
-
it('rejects simulated tool results
|
|
1789
|
+
it('rejects simulated tool results in a reply without tool calls', async () => {
|
|
1889
1790
|
const completion = vi.fn()
|
|
1890
|
-
.mockResolvedValueOnce({ text: '
|
|
1891
|
-
.mockResolvedValueOnce(
|
|
1791
|
+
.mockResolvedValueOnce({ text: 'Yuri tool result name=bash: invented\nAssistant: continue' })
|
|
1792
|
+
.mockResolvedValueOnce(toolCall('bash', { command: 'pwd' }))
|
|
1892
1793
|
const stream = createContactStreamFn(completion)(
|
|
1893
1794
|
{ id: 'm', name: 'p/m', provider: 'yuri' },
|
|
1894
1795
|
{ tools: [{ name: 'bash' }], messages: [{ role: 'user', content: 'check directory' }] },
|
|
@@ -1896,12 +1797,17 @@ it('rejects simulated tool results even without a final fence', async () => {
|
|
|
1896
1797
|
for await (const event of stream) void event
|
|
1897
1798
|
expect(completion).toHaveBeenCalledTimes(2)
|
|
1898
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')
|
|
1899
1801
|
expect((await stream.result()).content.filter((part) => part.type === 'toolCall')).toHaveLength(1)
|
|
1900
1802
|
})
|
|
1901
1803
|
|
|
1902
1804
|
it('lets a scheduled follow-up finish silently without publishing progress or a notification marker', async () => {
|
|
1903
1805
|
const onBubbleDelta = vi.fn()
|
|
1904
|
-
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
|
+
})
|
|
1905
1811
|
const result = await runContactTurn({
|
|
1906
1812
|
assistant: { providerID: 'p', modelID: 'm' },
|
|
1907
1813
|
readOnly: true, allowSilent: true, history: [], userText: 'Scheduled maintenance succeeded; no report requested.',
|
|
@@ -1912,17 +1818,30 @@ it('lets a scheduled follow-up finish silently without publishing progress or a
|
|
|
1912
1818
|
expect(createChatCompletion).toHaveBeenCalledOnce()
|
|
1913
1819
|
})
|
|
1914
1820
|
|
|
1915
|
-
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) => {
|
|
1916
1825
|
await expect(runContactTurn({
|
|
1917
1826
|
assistant: { providerID: 'p', modelID: 'm' }, readOnly: true,
|
|
1918
|
-
allowSilent
|
|
1919
|
-
createChatCompletion: async () =>
|
|
1827
|
+
allowSilent, history: [], userText: 'Review the result',
|
|
1828
|
+
createChatCompletion: async () => response,
|
|
1920
1829
|
})).rejects.toMatchObject({ code: 'upstream_error' })
|
|
1921
1830
|
})
|
|
1922
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
|
+
|
|
1923
1842
|
it('rejects a background model attempt to restart a session before executing its tool', async () => {
|
|
1924
1843
|
const assignWork = vi.fn()
|
|
1925
|
-
const createChatCompletion = vi.fn(async () => (
|
|
1844
|
+
const createChatCompletion = vi.fn(async () => toolCall('assign_session', { sessionID: 'ses_completed', prompt: 'restart' }))
|
|
1926
1845
|
await expect(runContactTurn({
|
|
1927
1846
|
assistant: { providerID: 'p', modelID: 'm' },
|
|
1928
1847
|
readOnly: true, history: [], userText: 'Worker finished',
|
|
@@ -1940,7 +1859,7 @@ it('allows read_session during read-only turns and delivers actual referenced me
|
|
|
1940
1859
|
history: [], userText: 'Summarize @session:ses_ref', tools: createContactTools({ readSession }),
|
|
1941
1860
|
createChatCompletion: async (input) => {
|
|
1942
1861
|
calls += 1
|
|
1943
|
-
if (calls === 1) return
|
|
1862
|
+
if (calls === 1) return toolCall('read_session', { sessionID: 'ses_ref', limit: 5 })
|
|
1944
1863
|
expect(JSON.stringify(input)).toContain('quoted context')
|
|
1945
1864
|
return { text: '已读取引用内容。' }
|
|
1946
1865
|
},
|