dsh-world 0.7.6 → 0.8.0

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.
Files changed (102) hide show
  1. package/CHANGELOG.md +541 -479
  2. package/CONTRIBUTING.md +174 -174
  3. package/INSTALL.md +314 -314
  4. package/NOTES.md +57 -3
  5. package/README.md +332 -259
  6. package/client/index.js +1126 -991
  7. package/lib/compaction.d.ts +1 -0
  8. package/lib/compaction.js +1 -1
  9. package/lib/console/routes.d.ts +11 -3
  10. package/lib/console/routes.js +12 -7
  11. package/lib/console/snapshot.d.ts +2 -0
  12. package/lib/console/snapshot.js +1 -0
  13. package/lib/ecosystem/computer/browser/browser.d.ts +34 -0
  14. package/lib/ecosystem/computer/browser/browser.js +101 -0
  15. package/lib/ecosystem/computer/browser/cdp.d.ts +22 -0
  16. package/lib/ecosystem/computer/browser/cdp.js +91 -0
  17. package/lib/ecosystem/computer/browser/edge.d.ts +15 -0
  18. package/lib/ecosystem/computer/browser/edge.js +80 -0
  19. package/lib/ecosystem/computer/browser/page.d.ts +41 -0
  20. package/lib/ecosystem/computer/browser/page.js +140 -0
  21. package/lib/ecosystem/computer/browser/pageLib.d.ts +7 -0
  22. package/lib/ecosystem/computer/browser/pageLib.js +106 -0
  23. package/lib/ecosystem/computer/desktop/desktop.d.ts +91 -0
  24. package/lib/ecosystem/computer/desktop/desktop.js +322 -0
  25. package/lib/ecosystem/computer/desktop/driver.d.ts +34 -0
  26. package/lib/ecosystem/computer/desktop/driver.js +197 -0
  27. package/lib/ecosystem/computer/desktop/processes.d.ts +5 -0
  28. package/lib/ecosystem/computer/desktop/processes.js +15 -0
  29. package/lib/ecosystem/computer/desktop/recording.d.ts +77 -0
  30. package/lib/ecosystem/computer/desktop/recording.js +187 -0
  31. package/lib/ecosystem/computer/desktop/screen.d.ts +33 -0
  32. package/lib/ecosystem/computer/desktop/screen.js +182 -0
  33. package/lib/ecosystem/computer/desktop/turns.d.ts +58 -0
  34. package/lib/ecosystem/computer/desktop/turns.js +94 -0
  35. package/lib/ecosystem/computer/desktop/watching.d.ts +25 -0
  36. package/lib/ecosystem/computer/desktop/watching.js +81 -0
  37. package/lib/ecosystem/computer/inbox/inbox.d.ts +32 -0
  38. package/lib/ecosystem/computer/inbox/inbox.js +142 -0
  39. package/lib/ecosystem/computer/index.d.ts +82 -0
  40. package/lib/ecosystem/computer/index.js +133 -0
  41. package/lib/ecosystem/computer/procedures/alarm.d.ts +13 -0
  42. package/lib/ecosystem/computer/procedures/alarm.js +46 -0
  43. package/lib/ecosystem/computer/procedures/archive.d.ts +32 -0
  44. package/lib/ecosystem/computer/procedures/archive.js +68 -0
  45. package/lib/ecosystem/computer/procedures/catalog.d.ts +7 -0
  46. package/lib/ecosystem/computer/procedures/catalog.js +75 -0
  47. package/lib/ecosystem/computer/procedures/format.d.ts +167 -0
  48. package/lib/ecosystem/computer/procedures/format.js +332 -0
  49. package/lib/ecosystem/computer/procedures/library.d.ts +53 -0
  50. package/lib/ecosystem/computer/procedures/library.js +178 -0
  51. package/lib/ecosystem/computer/procedures/run.d.ts +80 -0
  52. package/lib/ecosystem/computer/procedures/run.js +245 -0
  53. package/lib/ecosystem/computer/tools.d.ts +21 -0
  54. package/lib/ecosystem/computer/tools.js +197 -0
  55. package/lib/ecosystem/qq-native/images.d.ts +3 -0
  56. package/lib/ecosystem/qq-native/images.js +18 -6
  57. package/lib/ecosystem/qq-native/index.js +2 -2
  58. package/lib/ecosystem/shared/turn.d.ts +3 -0
  59. package/lib/ecosystem/shared/turn.js +13 -3
  60. package/lib/ecosystem/wechat/home.d.ts +1 -0
  61. package/lib/ecosystem/wechat/home.js +9 -3
  62. package/lib/ecosystem/wechat/images.js +3 -5
  63. package/lib/ecosystem/wechat/index.d.ts +1 -0
  64. package/lib/ecosystem/wechat/reading.d.ts +1 -1
  65. package/lib/ecosystem/wechat/reading.js +2 -2
  66. package/lib/history.js +2 -1
  67. package/lib/images.d.ts +30 -0
  68. package/lib/images.js +101 -0
  69. package/lib/index.d.ts +4 -0
  70. package/lib/index.js +90 -5
  71. package/lib/life/photoTools.js +4 -15
  72. package/lib/life/runtime.d.ts +12 -2
  73. package/lib/life/runtime.js +93 -12
  74. package/lib/life/toolRegistry.d.ts +9 -3
  75. package/lib/life/toolRegistry.js +46 -27
  76. package/lib/life/turnCost.d.ts +16 -0
  77. package/lib/life/turnCost.js +44 -0
  78. package/lib/life/types.d.ts +17 -0
  79. package/lib/memoryTools.d.ts +2 -1
  80. package/lib/memoryTools.js +16 -3
  81. package/lib/promptSection.d.ts +1 -0
  82. package/lib/promptSection.js +29 -42
  83. package/lib/runtime.js +1 -1
  84. package/lib/types.d.ts +4 -0
  85. package/lib/worldAdd.d.ts +9 -0
  86. package/lib/worldAdd.js +39 -0
  87. package/lib/worldPrompt.d.ts +3 -2
  88. package/lib/worldPrompt.js +3 -2
  89. package/lib/worldRoutes.d.ts +5 -2
  90. package/lib/worldRoutes.js +29 -4
  91. package/lib/worldSwitch.d.ts +8 -2
  92. package/lib/worldSwitch.js +11 -5
  93. package/package.json +132 -129
  94. package/src/ecosystem/README.md +2 -1
  95. package/src/ecosystem/computer/NOTICE.md +27 -0
  96. package/src/ecosystem/computer/README.md +244 -0
  97. package/src/ecosystem/computer/desktop/win32.ps1 +858 -0
  98. package/src/ecosystem/wechat/windows/README.md +4 -2
  99. package/src/ecosystem/wechat/windows/engine/NOTICE.md +6 -0
  100. package/src/ecosystem/wechat/windows/engine/profiles.json +28 -0
  101. package/templates/world-prompt-memory.md +10 -10
  102. package/templates/world-prompt.md +65 -65
@@ -0,0 +1,245 @@
1
+ // src/ecosystem/computer/procedures/run.ts
2
+ import { errorText } from "../../../faults.js";
3
+ import { describeAnchor } from "../browser/page.js";
4
+ import { isOpenTooSoon, isWebAddress, procedurePath, substitute, WEB_ONLY } from "./format.js";
5
+ /** How long a `check` waits for the page a step led to, so a check right after sending sees the page it opened. */
6
+ const CHECK_MS = 3000;
7
+ /** Kept versions tried after the newest fails, so a long repair history cannot make one call run for minutes. */
8
+ export const MAX_FALLBACK = 2;
9
+ export function checkArgs(procedure, input) {
10
+ const out = {};
11
+ for (const key of Object.keys(input))
12
+ if (!(key in procedure.params))
13
+ throw new Error(`不认识的参数 ${key}`);
14
+ for (const [name, param] of Object.entries(procedure.params)) {
15
+ const value = input[name];
16
+ if (value === undefined) {
17
+ if (param.required)
18
+ throw new Error(`缺少参数 ${name}`);
19
+ continue;
20
+ }
21
+ if (typeof value !== param.type)
22
+ throw new Error(`参数 ${name} 应该是 ${param.type}`);
23
+ out[name] = value;
24
+ }
25
+ return out;
26
+ }
27
+ const fill = (anchor, args) => Object.fromEntries(Object.entries(anchor).map(([key, value]) => [key, typeof value === 'string' ? substitute(value, args) : value]));
28
+ const fillExtract = (spec, args) => ({
29
+ ...spec, list: fill(spec.list, args),
30
+ fields: Object.fromEntries(Object.entries(spec.fields).map(([name, field]) => [name, fill(field, args)])),
31
+ });
32
+ const fillCondition = (condition, args) => ({
33
+ ...(condition.text === undefined ? {} : { text: substitute(condition.text, args) }),
34
+ ...(condition.url === undefined ? {} : { url: substitute(condition.url, args) }),
35
+ ...(condition.anchor === undefined ? {} : { anchor: fill(condition.anchor, args) }),
36
+ });
37
+ const describeCondition = (condition) => [condition.text && `文字「${condition.text}」`, condition.url && `地址含 ${condition.url}`, condition.anchor && describeAnchor(condition.anchor)].filter(Boolean).join('、');
38
+ const isEmpty = (value) => value === null || value === undefined || value === ''
39
+ || (Array.isArray(value) ? value.every(isEmpty) : typeof value === 'object' ? Object.values(value).every(isEmpty) : false);
40
+ const EMPTY_HINT = '(页面可能改了;本来就可能为空的,在这一步加 allowEmpty: true)';
41
+ /** An extract that finds nothing, or a field blank in every row, is far likelier a changed page than an empty one. */
42
+ function emptyRows(spec, rows) {
43
+ if (!rows.length)
44
+ return `一条都没有提取到${EMPTY_HINT}`;
45
+ const blank = Object.keys(spec.fields).find(name => rows.every(row => isEmpty(row[name])));
46
+ return blank === undefined ? undefined : `提取到 ${rows.length} 条,但字段 ${blank} 每一条都是空的${EMPTY_HINT}`;
47
+ }
48
+ const at = (point) => point.x === undefined ? '' : `(${point.x}, ${point.y})`;
49
+ export function describeStep(step) {
50
+ if ('open' in step)
51
+ return `打开 ${step.open}`;
52
+ if ('click' in step)
53
+ return 'x' in step.click ? `点${at(step.click)}` : `点 ${describeAnchor(step.click)}`;
54
+ if ('type' in step)
55
+ return 'into' in step.type ? `在 ${describeAnchor(step.type.into)} 输入` : `输入${at(step.type)}`;
56
+ if ('drag' in step)
57
+ return `从${at(step.drag)}拖到${at({ x: step.drag.x2, y: step.drag.y2 })}`;
58
+ if ('press' in step)
59
+ return `按 ${step.press}`;
60
+ if ('scroll' in step)
61
+ return `往 ${step.scroll.direction} 滚${at(step.scroll)}`;
62
+ if ('wait' in step)
63
+ return 'seconds' in step.wait && !('text' in step.wait || 'url' in step.wait || 'anchor' in step.wait) ? `等 ${step.wait.seconds} 秒` : `等 ${describeCondition(step.wait)}`;
64
+ if ('check' in step)
65
+ return `确认 ${describeCondition(step.check)}`;
66
+ if ('extract' in step)
67
+ return `提取 ${describeAnchor(step.extract.list)}`;
68
+ return '页面脚本';
69
+ }
70
+ /**
71
+ * Replays her steps without the model: the first one that fails stops the run and says where, never retried. Coming up
72
+ * empty is failing too, unless the step allows it, so a broken tool is never read as "nothing new".
73
+ */
74
+ export async function runProcedure(procedure, args, driver, signal) {
75
+ if (procedure.where !== undefined) {
76
+ if (!('act' in driver))
77
+ throw new Error(`${procedurePath(procedure)} 是伙伴电脑上的操作,要在「她用电脑」里跑`);
78
+ return runDesktop(procedure, args, driver, signal);
79
+ }
80
+ if (!('open' in driver))
81
+ throw new Error(`${procedurePath(procedure)} 是网页上的操作,要在我的浏览器里跑`);
82
+ let rows = [], outwardDone = false;
83
+ const values = {};
84
+ for (const [index, step] of procedure.steps.entries()) {
85
+ signal?.throwIfAborted();
86
+ const outward = 'outward' in step && step.outward === true;
87
+ try {
88
+ if ('open' in step) {
89
+ const url = substitute(step.open, args);
90
+ if (!isWebAddress(url))
91
+ throw new Error(WEB_ONLY);
92
+ await driver.open(url);
93
+ }
94
+ else if ('click' in step)
95
+ await driver.click({ anchor: fill(step.click, args) });
96
+ else if ('type' in step)
97
+ await driver.type({ anchor: fill(step.type.into, args) }, substitute(step.type.text, args));
98
+ else if ('press' in step)
99
+ await driver.press(step.press);
100
+ else if ('wait' in step)
101
+ await driver.wait(fillCondition(step.wait, args), (step.wait.seconds ?? 10) * 1000, signal);
102
+ else if ('check' in step) {
103
+ const condition = fillCondition(step.check, args);
104
+ try {
105
+ await driver.wait(condition, CHECK_MS, signal);
106
+ }
107
+ catch (error) {
108
+ if (signal?.aborted)
109
+ throw error;
110
+ throw new Error(`等了 ${CHECK_MS / 1000} 秒,页面上还是没有${describeCondition(condition)}`);
111
+ }
112
+ }
113
+ else if ('extract' in step) {
114
+ rows = await driver.extract(fillExtract(step.extract, args));
115
+ const empty = step.allowEmpty ? undefined : emptyRows(step.extract, rows);
116
+ if (empty)
117
+ throw new Error(empty);
118
+ }
119
+ else {
120
+ const value = await driver.evaluate(step.script, args);
121
+ if (step.as) {
122
+ if (!step.allowEmpty && isEmpty(value))
123
+ throw new Error(`页面脚本的结果 ${step.as} 是空的${EMPTY_HINT}`);
124
+ values[step.as] = value;
125
+ }
126
+ }
127
+ if (outward)
128
+ outwardDone = true;
129
+ }
130
+ catch (error) {
131
+ if (signal?.aborted)
132
+ throw error;
133
+ const page = await driver.brief().catch(() => '(读不到当前页面)');
134
+ // A failed outward step may still have gone out: it counts as done.
135
+ return { ok: false, step: index + 1, action: describeStep(step), error: errorText(error), outwardDone: outwardDone || outward, page };
136
+ }
137
+ }
138
+ return { ok: true, rows, values };
139
+ }
140
+ function desktopInput(step, args) {
141
+ if ('open' in step)
142
+ return { action: 'open', app: substitute(step.open, args) };
143
+ if ('click' in step)
144
+ return { action: 'click', ...step.click };
145
+ if ('drag' in step)
146
+ return { action: 'drag', ...step.drag };
147
+ if ('type' in step)
148
+ return { action: 'type', ...step.type, text: substitute(step.type.text, args) };
149
+ if ('press' in step)
150
+ return { action: 'press', key: step.press, ...(step.hold === undefined ? {} : { hold: step.hold }) };
151
+ return { action: 'scroll', ...step.scroll };
152
+ }
153
+ const sleep = (ms, signal) => new Promise((resolve, reject) => {
154
+ const timer = setTimeout(resolve, ms);
155
+ signal?.addEventListener('abort', () => { clearTimeout(timer); reject(signal.reason); }, { once: true });
156
+ });
157
+ /**
158
+ * Her desktop steps through her own hands. Each step answers with a picture, which the caller keeps through `driver`,
159
+ * so she sees where it ended; positions are pixels of the picture, so they follow the window's size, not its place.
160
+ */
161
+ async function runDesktop(procedure, args, hands, signal) {
162
+ let outwardDone = false;
163
+ // On the whole screen her positions are pixels of a picture of it: one is taken first, so they are measured on this screen.
164
+ if (procedure.where === 'screen')
165
+ await hands.act({ action: 'shot' });
166
+ for (const [index, step] of procedure.steps.entries()) {
167
+ signal?.throwIfAborted();
168
+ const outward = 'outward' in step && step.outward === true;
169
+ try {
170
+ if ('wait' in step)
171
+ await sleep(step.wait.seconds * 1000, signal);
172
+ else
173
+ await hands.act(desktopInput(step, args));
174
+ if (outward)
175
+ outwardDone = true;
176
+ }
177
+ catch (error) {
178
+ if (signal?.aborted)
179
+ throw error;
180
+ const early = isOpenTooSoon(procedure.steps, index) ? '(回放时步与步之间不停,可能是窗口还没出来;在这一步前面加 wait)' : '';
181
+ return { ok: false, step: index + 1, action: describeStep(step), error: errorText(error) + early, outwardDone: outwardDone || outward, page: '(最后一张截图附在下一条消息里)' };
182
+ }
183
+ }
184
+ return { ok: true, rows: [], values: {} };
185
+ }
186
+ /**
187
+ * Runs her newest version; when it fails before anything went out, her kept versions newest first, since a site may
188
+ * serve its old and new page side by side and a repair for one must not lose the other. The newest's failure is the
189
+ * one reported when none works. A kept version whose parameters no longer fit the call is skipped.
190
+ */
191
+ export async function runVersions(newest, kept, input, driver, signal) {
192
+ const result = await runProcedure(newest, checkArgs(newest, input), driver, signal);
193
+ if (result.ok || result.outwardDone)
194
+ return { result, ran: newest };
195
+ for (const { procedure, version } of kept.slice(0, MAX_FALLBACK)) {
196
+ let args;
197
+ try {
198
+ args = checkArgs(procedure, input);
199
+ }
200
+ catch {
201
+ continue;
202
+ }
203
+ const older = await runProcedure(procedure, args, driver, signal);
204
+ if (older.ok)
205
+ return { result: older, ran: procedure, fallback: { version, newest: result } };
206
+ if (older.outwardDone)
207
+ break; // something may have gone out: no other version gets a turn
208
+ }
209
+ return { result, ran: newest };
210
+ }
211
+ /** Told after a result that came from a kept version, so she knows her newest one is broken. */
212
+ export const fallbackText = ({ version, newest }) => `最新版第 ${newest.step} 步(${newest.action})没跑通:${cut(newest.error, 80)};这次退回第 ${version} 版跑通了。`;
213
+ /** Said at the moment it breaks, when the task is still in front of her: doing it by hand is how the new version gets made. */
214
+ export const REPAIR_NOW = '现在就修:先用 page_* 或 desktop 把这件事做完,再把走通的步骤用原来的名字 procedure_save 成新版(不另起一个新的),存完跑一次确认。';
215
+ export function failureText(path, result) {
216
+ return `${path} 没跑通:第 ${result.step} 步(${result.action})${result.error}。`
217
+ + (result.outwardDone ? `这一步或之前有向外的动作,可能已经发出,先看页面确认,不要直接重跑;确认之后再把它修好存成新版。` : `还没有任何向外的动作。${REPAIR_NOW}`)
218
+ + `\n当前页面:\n${result.page}`;
219
+ }
220
+ /** Cuts by characters, not UTF-16 units, so an emoji is never split. */
221
+ export const cut = (text, max) => { const chars = [...text]; return chars.length > max ? chars.slice(0, max).join('') + '…(截断)' : text; };
222
+ /** What her tool hands back: the rows of its last extract and the values its scripts kept, cut to 2000 characters. */
223
+ export function resultText(result) {
224
+ const out = { ...(result.rows.length ? { rows: result.rows } : {}), ...(Object.keys(result.values).length ? { values: result.values } : {}) };
225
+ const text = Object.keys(out).length ? JSON.stringify(out) : '完成。';
226
+ return cut(text, 2000);
227
+ }
228
+ /** One line after her alarm: the tool's own summary, or its result; a failure is said as a failure, never as nothing. */
229
+ export function summaryLine(procedure, result) {
230
+ if (!result.ok)
231
+ return `${procedurePath(procedure)} 没跑通(第 ${result.step} 步:${cut(result.error, 60)})`;
232
+ const values = { ...Object.fromEntries(Object.entries(result.values).map(([key, value]) => [key, typeof value === 'string' ? value : JSON.stringify(value)])), count: String(result.rows.length) };
233
+ const body = procedure.summary ? substitute(procedure.summary, values) : resultText(result);
234
+ return `${procedurePath(procedure)}:${cut(body, 200)}`;
235
+ }
236
+ /** The one place a run, or the error that cut it off, becomes the note the catalog and the console show. */
237
+ export function noteRun(library, path, outcome) {
238
+ if ('thrown' in outcome)
239
+ return library.note(path, false, cut(errorText(outcome.thrown), 200));
240
+ const { result, fallback } = outcome;
241
+ if (result.ok)
242
+ library.note(path, true, fallback && cut(fallbackText(fallback), 200));
243
+ else
244
+ library.note(path, false, cut(`第 ${result.step} 步:${result.error}`, 200));
245
+ }
@@ -0,0 +1,21 @@
1
+ import type { Agent } from '@deepseek-ai/dsh-agent';
2
+ import type { AttachmentStore } from '@deepseek-ai/dsh-attachment';
3
+ import { type ToolDefinition } from '@deepseek-ai/dsh-tools';
4
+ import type { Browser } from './browser/browser.ts';
5
+ import type { ComputerRecorder } from './procedures/archive.ts';
6
+ import type { ProcedureLibrary } from './procedures/library.ts';
7
+ import { type Desktop } from './desktop/desktop.ts';
8
+ /**
9
+ * Her page tools and her catalog: what she learns is found with `computer_use` and run with `procedure_run`, so the tool
10
+ * list stays the same however much she learns. Home only (see `toolRegistry`).
11
+ */
12
+ export declare function computerTools(deps: {
13
+ agent: Agent;
14
+ browser: Pick<Browser, 'run'>;
15
+ library: ProcedureLibrary;
16
+ recorder: Pick<ComputerRecorder, 'record'>;
17
+ attachments(): AttachmentStore | undefined;
18
+ desktop?: Pick<Desktop, 'act'>;
19
+ /** Foreground mode is on: the desktop tool works the whole screen through these instead; saved operations still replay through `desktop`. */
20
+ screen?: Pick<Desktop, 'act'>;
21
+ }): ToolDefinition[];
@@ -0,0 +1,197 @@
1
+ import { defineTool } from '@deepseek-ai/dsh-tools';
2
+ import { errorText } from "../../faults.js";
3
+ import { imagesMessage, keepImages, shownImage } from "../../images.js";
4
+ import { PAGE_KEYS } from "./browser/page.js";
5
+ import { catalogText } from "./procedures/catalog.js";
6
+ import { checkArgs, cut, failureText, fallbackText, noteRun, resultText, runVersions } from "./procedures/run.js";
7
+ import { desktopAdvice, isWebAddress, WEB_ONLY } from "./procedures/format.js";
8
+ import { DESKTOP_KEYS } from "./desktop/desktop.js";
9
+ const output = { schema: { type: 'string' }, render: (_args, value) => [{ type: 'text', text: value }] };
10
+ const DESKTOP_NOTE = `用伙伴的电脑(后台模式):看当前窗口的截图,按图上的像素操作;输入直接投给那个窗口,不动伙伴的鼠标、不抢焦点,伙伴用着电脑我也能用。学会的操作先用 computer_use 找。以管理员权限运行的程序(很多游戏)后台够不着,要用就请伙伴切到前台模式。action 取一种:open(app 写程序名,打开它当作当前窗口,托盘里的会点开;不写就列出开着的窗口)|shot(再截一张)|click(x、y 是截图上的像素;double 双击,right 右键,hold 按住几秒是长按)|drag(从 x、y 按住拖到 x2、y2 松开;hold 先按住几秒再拖,right 用右键)|type(text;给 x、y 就先点那里;submit 再回车)|press(key:${DESKTOP_KEYS};hold 按住几秒)|scroll(direction 为 up/down/left/right,可加 x、y)|zoom(截图上 x、y 到 x2、y2 放大看)|record(看视频这类会动的:先让它播起来,录 seconds 秒,最多 600;every 每几秒一帧,默认 1;pause 为 false 时录完不暂停)|stop(停下正在录的)|review(看录好的:不带参数看全片,from、to 细看一段,at 看某一秒)。每步之后都有新截图,自己看做对了没有;没反应就换个办法,别重复同一下。`;
11
+ /** Foreground mode: the same actions over the whole screen with the real mouse and keyboard. */
12
+ const SCREEN_NOTE = `用伙伴的电脑(前台模式):伙伴把电脑交给了我。看整个屏幕的截图,用真的鼠标键盘按图上的像素操作,游戏和管理员程序也能用;伙伴的鼠标会跟着动。伙伴连按两下 Esc 或点屏幕顶上的「停下」,我就停。action 和后台模式一样:open(把程序放到最前面,没开的会启动;不写 app 就列出窗口)|shot|click(x、y,double、right,hold 长按几秒)|drag(x、y 拖到 x2、y2;hold 先按住几秒,right)|type(text,可先给 x、y,submit)|press(key:${DESKTOP_KEYS};hold 按住几秒,比如游戏里按住 w 走路)|scroll(direction,可加 x、y)|zoom(x、y 到 x2、y2)|record(seconds、every、pause)|stop|review(from、to 或 at)。走通的步骤可以 procedure_save 存成 where:"screen" 的操作,以后在前台模式下用 procedure_run 回放。`;
13
+ const FORMAT_NOTE = '格式不对时保存会被拒绝并说明哪里不对。文件是 JSON:name(操作名,中文也行,不含 / 和 .)、category(分类,比如 wechat、bilibili)、description、params({名字:{type,required?}})、steps。步骤各取一种:open|click|type {into,text}|press|wait {text|anchor|url,seconds?}|check|extract {list,fields,limit?}|script(可 return,as 存成值)。锚点 {role?,name?,text?,css?,nth?(从 0 数)},role、name 用 page_read 里看到的;extract 的字段可以只写 attr,读列表项自己。文字里的 {{参数}} 会代入。会向外发出的步骤标 outward:true。extract 一条都没有、某个字段每条都空、带 as 的 script 结果为空,都算没跑通;本来就可能为空的(比如没有未读)在那一步加 allowEmpty:true。check 最多等 3 秒。没跑通而且还没有向外的动作时,会依次试最近 2 个旧版本。onAlarm:true 表示闹钟前自动跑(不能有必填参数和 outward 步骤);summary 可用 {{as 名}} 和 {{count}}。messages 把 extract 的字段写进归档:channel、conversationType 写死,其余是 {{字段}} 模板,outgoing 算出 true 表示是你自己说的。\n伙伴电脑上用 desktop 走通的:后台模式写 where:"desktop",前台模式写 where:"screen"(只能在前台模式下跑)。步骤各取一种:open(程序名或窗口标题,比如「微信」「朋友圈」)|click {x,y,double?,right?,hold?}|drag {x,y,x2,y2,right?,hold?}|type {text,x?,y?}|press(同 desktop 的按键,可加 hold)|scroll {direction,x?,y?}|wait {seconds}。x、y 是 desktop 截图上的像素(desktop 是窗口的截图,screen 是整个屏幕的截图),大小变了会按比例跟着变。回放时步与步之间不停,手动做时等过的地方(点完才弹出的窗口)要写 wait。不能用 onAlarm、summary、messages。跑完会给最后一张截图,自己看做成了没有。';
14
+ /**
15
+ * Her page tools and her catalog: what she learns is found with `computer_use` and run with `procedure_run`, so the tool
16
+ * list stays the same however much she learns. Home only (see `toolRegistry`).
17
+ */
18
+ export function computerTools(deps) {
19
+ const run = (work) => deps.browser.run(work);
20
+ // Checked before anything is queued, so a bad argument never launches or waits on the browser.
21
+ const whole = (value, message) => { if (!Number.isSafeInteger(value) || value < 1)
22
+ throw new Error(message); return value; };
23
+ const REF = 'ref 是 page_read 里方括号中的编号';
24
+ const ref = (value) => ({ ref: whole(value, REF) });
25
+ const where = (page) => page.brief().then(text => text.split('\n')[0]);
26
+ const page = [
27
+ defineTool({ name: 'page_open', description: '在我自己的浏览器里打开一个地址(浏览器没开会先打开它,窗口在桌面上,不用伙伴的鼠标键盘),返回页面上的元素和文字,同 page_read。登录要扫码时在那个窗口里扫。', parameters: { url: { type: 'string', required: true } }, output,
28
+ execute: async ({ url }) => { if (!isWebAddress(url))
29
+ throw new Error(WEB_ONLY); return run(async (p) => { await p.open(url); return p.read(); }); } }),
30
+ defineTool({ name: 'page_read', description: '读当前页面:每个可操作元素一行,[编号] 角色 名称;编号在页面不跳转时一直有效。page 翻看更多元素,ref 只看某个元素里面。之后附可见文字(截断)。', parameters: { page: { type: 'integer' }, ref: { type: 'integer' } }, output,
31
+ execute: async ({ page: index, ref: scope }) => {
32
+ const options = { ...(index === undefined ? {} : { page: whole(index, 'page 应该是 1 以上的整数') }), ...(scope === undefined ? {} : ref(scope)) };
33
+ return run(p => p.read(options));
34
+ } }),
35
+ defineTool({ name: 'page_click', description: '点 page_read 给出的编号。', parameters: { ref: { type: 'integer', required: true } }, output,
36
+ execute: async (args) => { const target = ref(args.ref); return run(async (p) => { await p.click(target); return `已点击 [${args.ref}],现在:${await where(p)}`; }); } }),
37
+ defineTool({ name: 'page_type', description: '在编号对应的输入框里输入文字(整段输入,中文也行),框里原有的内容会被替换;submit 为 true 时再按回车。', parameters: { ref: { type: 'integer', required: true }, text: { type: 'string', required: true }, submit: { type: 'boolean' } }, output,
38
+ execute: async (args) => { const target = ref(args.ref); return run(async (p) => { await p.type(target, args.text); if (args.submit)
39
+ await p.press('Enter'); return `已输入,现在:${await where(p)}`; }); } }),
40
+ defineTool({ name: 'page_press', description: `按一个键:${PAGE_KEYS.join('、')}。`, parameters: { key: { type: 'string', required: true } }, output,
41
+ execute: async ({ key }) => run(async (p) => { await p.press(key); return `已按 ${key},现在:${await where(p)}`; }) }),
42
+ defineTool({ name: 'page_scroll', description: '滚动一屏左右:direction 为 up 或 down;给 ref 就在那个元素上滚。', parameters: { direction: { type: 'string', required: true }, ref: { type: 'integer' } }, output,
43
+ execute: async (args) => {
44
+ if (args.direction !== 'up' && args.direction !== 'down')
45
+ throw new Error('direction 只能是 up 或 down');
46
+ const target = args.ref === undefined ? undefined : ref(args.ref);
47
+ return run(async (p) => { await p.scroll(args.direction, target); return '已滚动。'; });
48
+ } }),
49
+ defineTool({ name: 'page_wait', description: '等某段文字出现(text,最多等 seconds 秒,默认 10);或检查某个编号的元素还在(ref,立即返回)。seconds 最多 60。', parameters: { text: { type: 'string' }, ref: { type: 'integer' }, seconds: { type: 'number' } }, output,
50
+ execute: async ({ text, ref: id, seconds = 10 }) => {
51
+ if (text === undefined && id === undefined)
52
+ throw new Error('要给 text 或 ref');
53
+ if (text !== undefined && !text.trim())
54
+ throw new Error('text 不能是空的');
55
+ const target = id === undefined ? undefined : whole(id, REF);
56
+ if (typeof seconds !== 'number' || seconds <= 0 || seconds > 60)
57
+ throw new Error('seconds 应该在 0 到 60 之间');
58
+ return run(async (p, signal) => {
59
+ if (target !== undefined) {
60
+ await p.read({ ref: target });
61
+ return `[${target}] 还在。`;
62
+ }
63
+ await p.wait({ text: text }, seconds * 1000, signal);
64
+ return `等到了「${text}」。`;
65
+ });
66
+ } }),
67
+ defineTool({ name: 'page_shot', description: '截当前页面一张图附在下一条消息里;只在读文字看不明白时用,图片很占地方。', parameters: {}, output,
68
+ execute: async (_args, context) => {
69
+ const attachments = imageStore();
70
+ await attach(attachments, { data: await run(p => p.shot()), mediaType: 'image/png' }, '我的浏览器.png', '这是我浏览器当前页面的截图。', context);
71
+ return '截图附在下一条消息里。';
72
+ } }),
73
+ defineTool({ name: 'page_eval', description: '在当前页面里执行一段 JS(可 return 一个能转成 JSON 的值),只在我的浏览器页面里,碰不到电脑上的文件。十秒超时,结果截到 2000 字。', parameters: { script: { type: 'string', required: true } }, output,
74
+ execute: async ({ script }) => run(async (p) => cut(JSON.stringify(await p.evaluate(script, {})) ?? 'null', 2000)) }),
75
+ ];
76
+ const procedures = [
77
+ defineTool({ name: 'computer_use', description: '用电脑之前先说这次要用的程序或网站(target 只写对象,比如「微信」「B站」,不写要做的事),返回我写的这一类的说明、操作名和文件所在的文件夹;要看某个操作的参数和步骤就读它的文件。不说就列出我现在能用的模块和学会的操作有哪些分类。', parameters: { target: { type: 'string' } }, output,
78
+ // Asked without naming anything, she is first told which of her modules she has right now: a name each, no instructions.
79
+ execute: async ({ target }) => target?.trim() ? catalogText(deps.library, target) : `${modules()}\n${catalogText(deps.library)}` }),
80
+ defineTool({ name: 'procedure_run', description: '跑一个学会的操作:path 写「分类/操作」,args 是它声明的参数。不调模型,直接回放;没跑通会说第几步、为什么。', parameters: { path: { type: 'string', required: true }, args: { type: 'object', additionalProperties: true } }, output,
81
+ execute: async ({ path, args }, context) => runStored(path, (args ?? {}), context) }),
82
+ // The format is long and only needed when she writes one, so it is handed over on asking rather than sent with every step.
83
+ defineTool({ name: 'procedure_save', description: `把用 page_* 或 desktop 走通的步骤存成一个操作,以后用 procedure_run 直接跑;同名覆盖、留下旧版本。文件在 ${deps.library.dir},也可以直接改。json 是整份操作;第一次写或记不清格式,就不带 json 调一次,会给出完整的格式说明。`, parameters: { json: { type: 'string' } }, output,
84
+ execute: async ({ json }) => {
85
+ if (typeof json !== 'string' || !json.trim())
86
+ return `操作文件的格式:\n${FORMAT_NOTE}`;
87
+ try {
88
+ const { path, version } = deps.library.save(json);
89
+ const advice = desktopAdvice(deps.library.get(path));
90
+ return `已保存 ${path}(第 ${version} 版),可以用 procedure_run 跑了。${advice.length ? `\n先看看这几处:\n${advice.map(line => `- ${line}`).join('\n')}` : ''}`;
91
+ }
92
+ catch (error) {
93
+ throw new Error(`没有保存:${errorText(error)}(完整格式:不带 json 调一次 procedure_save)`);
94
+ }
95
+ } }),
96
+ defineTool({ name: 'procedure_note', description: '写某一类操作的说明:这一类对应哪个程序或网站(写上程序名、网址和别称,computer_use 靠它找到这一类)、要注意什么。整份替换,旧的留作版本,最多 1000 字。', parameters: { category: { type: 'string', required: true }, text: { type: 'string', required: true } }, output,
97
+ execute: async ({ category, text }) => {
98
+ try {
99
+ return `已写好 ${category} 的说明(第 ${deps.library.saveGuide(category, text)} 版)。`;
100
+ }
101
+ catch (error) {
102
+ throw new Error(`没有保存:${errorText(error)}`);
103
+ }
104
+ } }),
105
+ ];
106
+ const live = deps.screen ?? deps.desktop;
107
+ const desktop = !live ? [] : [
108
+ defineTool({ name: 'desktop', description: deps.screen ? SCREEN_NOTE : DESKTOP_NOTE, output, parameters: {
109
+ action: { type: 'string', required: true }, app: { type: 'string' }, x: { type: 'number' }, y: { type: 'number' }, x2: { type: 'number' }, y2: { type: 'number' },
110
+ double: { type: 'boolean' }, right: { type: 'boolean' }, hold: { type: 'number' }, text: { type: 'string' }, submit: { type: 'boolean' }, key: { type: 'string' }, direction: { type: 'string' },
111
+ seconds: { type: 'number' }, every: { type: 'number' }, from: { type: 'number' }, to: { type: 'number' }, at: { type: 'number' }, pause: { type: 'boolean' },
112
+ }, execute: async (input, context) => {
113
+ context.signal.throwIfAborted();
114
+ const result = await live.act(input);
115
+ if (!result.image)
116
+ return result.text;
117
+ // The action already happened, so a missing image store costs her the picture, never the result.
118
+ const attachments = deps.attachments();
119
+ if (!attachments)
120
+ return `${result.text}(宿主图片存储不可用,看不到截图)`;
121
+ await attach(attachments, result.image, result.image.caption ? '录下的画面.jpg' : '伙伴的电脑.png', result.image.caption ?? (deps.screen ? '这是伙伴电脑整个屏幕的截图。' : '这是伙伴电脑上当前窗口的截图。'), context);
122
+ return result.text;
123
+ } }),
124
+ ];
125
+ return [...page, ...procedures, ...desktop];
126
+ /** The modules she can use now; the desktop line follows its switch and mode. */
127
+ function modules() {
128
+ const desktop = deps.screen ? 'desktop(伙伴的电脑,前台模式:整个屏幕,真的鼠标键盘)' : deps.desktop ? 'desktop(伙伴的电脑,后台模式:一个窗口,不动伙伴的鼠标)' : '';
129
+ return `现在能用:page_*(你自己的浏览器)、${desktop ? `${desktop}、` : ''}procedure_*(学会的操作)。`;
130
+ }
131
+ function imageStore() {
132
+ const attachments = deps.attachments();
133
+ if (!attachments)
134
+ throw new Error('宿主图片存储不可用');
135
+ return attachments;
136
+ }
137
+ /** Tool results carry text only, so an image goes to her in the next message. */
138
+ async function attach(attachments, image, name, caption, context) {
139
+ const [attachment] = await keepImages(attachments, [{ data: image.data, mediaType: image.mediaType, name }]);
140
+ context.signal.throwIfAborted();
141
+ context.deferContext(imagesMessage(shownImage(caption, attachment)));
142
+ }
143
+ /** The picture a desktop run ended on; a missing image store costs her the picture, never the result. */
144
+ async function lastPicture(image, context) {
145
+ const attachments = deps.attachments();
146
+ if (!attachments)
147
+ return '\n(宿主图片存储不可用,看不到最后的截图)';
148
+ await attach(attachments, image, '伙伴的电脑.png', '这是操作跑完时伙伴电脑上当前窗口的截图。', context);
149
+ return '\n最后一张截图附在下一条消息里,看看做成了没有。';
150
+ }
151
+ /** Filing what she read must never cost her the read itself, so a failure is a line after the result. */
152
+ async function archiveNote(map, rows, args) {
153
+ try {
154
+ const archived = await deps.recorder.record(deps.agent, map, rows, args);
155
+ return archived.outOfScope ? '\n(这个会话不在归档范围里,没有记)' : `\n新记进归档 ${archived.written} 条${archived.skipped ? `,跳过 ${archived.skipped} 条缺字段的` : ''}。`;
156
+ }
157
+ catch (error) {
158
+ return `\n(没能记进归档:${errorText(error)})`;
159
+ }
160
+ }
161
+ /** One of her operations, newest version first, falling back to the ones it replaced. */
162
+ async function runStored(path, input, context) {
163
+ const procedure = deps.library.get(path);
164
+ if (!procedure)
165
+ throw new Error(`没有 ${path} 这个操作,先用 computer_use 看看有哪些`);
166
+ checkArgs(procedure, input);
167
+ const kept = deps.library.kept(path);
168
+ // Each mode replays what was found in it: one window in the background, the whole screen in the foreground.
169
+ const live = procedure.where === 'screen' ? deps.screen : procedure.where === 'desktop' ? deps.desktop : undefined;
170
+ if (procedure.where === 'desktop' && !live)
171
+ throw new Error(`${path} 是伙伴电脑上的操作(后台模式),要先打开「她用电脑」`);
172
+ if (procedure.where === 'screen' && !live)
173
+ throw new Error(`${path} 是在整个屏幕上做的操作(前台模式),要请伙伴把「她用电脑」切到「前台」`);
174
+ let outcome, last;
175
+ // On the desktop every step answers with a picture; the last one is what she checks the run by.
176
+ const hands = live && { act: async (input) => { const result = await live.act(input); last = result.image ?? last; return result; } };
177
+ try {
178
+ outcome = procedure.where !== undefined
179
+ ? await runVersions(procedure, kept, input, hands, context.signal)
180
+ : await run((p, signal) => runVersions(procedure, kept, input, p, AbortSignal.any([signal, context.signal])));
181
+ }
182
+ catch (error) {
183
+ noteRun(deps.library, path, { thrown: error });
184
+ throw error;
185
+ }
186
+ noteRun(deps.library, path, outcome);
187
+ const { result, ran, fallback } = outcome;
188
+ const seen = last ? await lastPicture(last, context) : '';
189
+ if (!result.ok)
190
+ return failureText(path, result) + seen;
191
+ if (procedure.where !== undefined)
192
+ return '做完了。' + (fallback ? `(${fallbackText(fallback)}趁现在用 desktop 把最新版走通再存。)` : '') + (seen || '(没有截图,用 desktop shot 看看结果)');
193
+ // The version that ran declares what it read, and its own arguments are what fill the records.
194
+ const archived = ran.messages && result.rows.length ? await archiveNote(ran.messages, result.rows, checkArgs(ran, input)) : '';
195
+ return resultText(result) + archived + (fallback ? `\n(${fallbackText(fallback)}页面可能改了,或新旧页面并存。趁现在修:用 page_* 看看现在的页面,改好再 procedure_save,新旧页面都要能跑。)` : '');
196
+ }
197
+ }
@@ -1,7 +1,10 @@
1
1
  import type { Context } from '@deepseek-ai/cordis';
2
2
  import type { ContentBlock } from '@deepseek-ai/dsh-llm';
3
3
  import type { SpeakerIdentity } from '../shared/identity.ts';
4
+ /** Pictures of one batch put in front of her at once. */
4
5
  export declare const MAX_BATCH_IMAGES = 4;
6
+ /** Pictures of one batch that are fetched and kept: QQ's links expire, so one not fetched on arrival is gone. */
7
+ export declare const MAX_KEPT_IMAGES = 12;
5
8
  /** One image segment as QQ sent it: the id get_image takes, and the link some images (shop stickers, animated ones) carry instead. */
6
9
  export interface QqImageSegment {
7
10
  file: unknown;
@@ -1,4 +1,8 @@
1
+ import { keepImages, keptLines, shownImage } from "../../images.js";
2
+ /** Pictures of one batch put in front of her at once. */
1
3
  export const MAX_BATCH_IMAGES = 4;
4
+ /** Pictures of one batch that are fetched and kept: QQ's links expire, so one not fetched on arrival is gone. */
5
+ export const MAX_KEPT_IMAGES = 12;
2
6
  const DOWNLOAD_TIMEOUT_MS = 10_000;
3
7
  // QQ's own image hosts: the CDN behind get_image (multimedia.nt.qq.com.cn) and the sticker shop (gxh.vip.qq.com) (#44).
4
8
  const QQ_IMAGE_DOMAINS = ['qq.com', 'qq.com.cn'];
@@ -51,25 +55,33 @@ export async function admitQqImages(ctx, images, getImage) {
51
55
  if (!store)
52
56
  return [unavailable];
53
57
  const limits = store.imageLimits;
54
- const selected = images.slice(0, Math.min(MAX_BATCH_IMAGES, limits.maxImagesPerMessage));
58
+ const selected = images.slice(0, MAX_KEPT_IMAGES), shownMax = Math.min(MAX_BATCH_IMAGES, limits.maxImagesPerMessage);
55
59
  const downloads = await Promise.allSettled(selected.map(image => fetchQqImage(image, limits, getImage)));
56
60
  const content = [];
61
+ const kept = [];
57
62
  let remainingBytes = limits.maxMessageImageBytes;
58
- let saved = 0;
63
+ let saved = 0, shown = 0;
59
64
  for (const [index, result] of downloads.entries()) {
60
- if (result.status === 'rejected' || result.value.data.byteLength > remainingBytes)
65
+ if (result.status === 'rejected')
61
66
  continue;
62
67
  try {
63
- const [attachment] = await store.saveImages([result.value]);
68
+ const [attachment] = await keepImages(store, [result.value]);
64
69
  if (!attachment)
65
70
  continue;
71
+ saved++;
72
+ // Every picture sent to her is kept; only as many as one message may carry are put in front of her now.
73
+ if (shown >= shownMax || result.value.data.byteLength > remainingBytes) {
74
+ kept.push(attachment);
75
+ continue;
76
+ }
66
77
  const { platformMessageId, speakerId, speakerName } = selected[index].identity;
67
- content.push({ type: 'text', text: `下面是本次收到的第 ${index + 1} 张 QQ 图片,来源:${JSON.stringify({ messageId: platformMessageId, speakerId, speakerName })}。` }, { type: 'image', attachment });
78
+ content.push(...shownImage(`下面是本次收到的第 ${index + 1} 张 QQ 图片,来源:${JSON.stringify({ messageId: platformMessageId, speakerId, speakerName })}。`, attachment));
68
79
  remainingBytes -= result.value.data.byteLength;
69
- saved++;
80
+ shown++;
70
81
  }
71
82
  catch { /* 一张无法保存时仍交付同批的其他图片和文字。 */ }
72
83
  }
84
+ content.push(...keptLines(`这次还有 ${kept.length} 张 QQ 图片存下了,没有直接附上:`, kept));
73
85
  if (saved < images.length)
74
86
  content.push(unavailable);
75
87
  return content;
@@ -4,7 +4,7 @@ import { dirname, join } from 'node:path';
4
4
  import { speakerIdentity, conversationKey } from "../shared/identity.js";
5
5
  import { createBridge } from "./snowluma.js";
6
6
  import { createQqHome } from "./home.js";
7
- import { admitQqImages, MAX_BATCH_IMAGES } from "./images.js";
7
+ import { admitQqImages, MAX_KEPT_IMAGES } from "./images.js";
8
8
  import { createBatcher } from "./batch.js";
9
9
  import { createOutbox } from "./outbox.js";
10
10
  import { planReply, stripHostNoise } from "./replies.js";
@@ -220,7 +220,7 @@ export function createQqNativeModule(deps) {
220
220
  return;
221
221
  }
222
222
  const images = (message.segments ?? []).filter(segment => segment?.type === 'image')
223
- .slice(0, MAX_BATCH_IMAGES + 1).map(segment => ({ file: segment.data?.file, url: segment.data?.url }));
223
+ .slice(0, MAX_KEPT_IMAGES + 1).map(segment => ({ file: segment.data?.file, url: segment.data?.url }));
224
224
  batches.add(key, { text, identity, who: speakerName, images });
225
225
  }
226
226
  async function answer(key, gathered) {
@@ -12,6 +12,7 @@ export declare function createChannelQueue(name: string, options: {
12
12
  limit: number;
13
13
  timeoutMs: number;
14
14
  timers?: LifeTimers | undefined;
15
+ timeoutMessage?: string;
15
16
  }): {
16
17
  run: <T>(work: (cancelled: Promise<never>) => Promise<T>) => Promise<T>;
17
18
  readonly stopped: boolean;
@@ -37,4 +38,6 @@ export declare function askTurn(ctx: Context, agent: Agent, words: UserMessage,
37
38
  context?: UserMessage | undefined;
38
39
  cancelled?: Promise<never> | undefined;
39
40
  answered?: ((source: UserMessage['source']) => boolean) | undefined;
41
+ steer?: boolean | undefined;
42
+ untilTaken?: boolean | undefined;
40
43
  }): Promise<string>;
@@ -26,7 +26,7 @@ export function createChannelQueue(name, options) {
26
26
  let cancel;
27
27
  const cancelled = new Promise((_resolve, reject) => {
28
28
  cancel = () => reject(stoppedError());
29
- timer = timers.set(() => reject(new Error(`${name} home reply timed out`)), options.timeoutMs);
29
+ timer = timers.set(() => reject(new Error(options.timeoutMessage ?? `${name} home reply timed out`)), options.timeoutMs);
30
30
  });
31
31
  cancelled.catch(() => { });
32
32
  cancellations.add(cancel);
@@ -77,8 +77,14 @@ export async function askTurn(ctx, agent, words, options) {
77
77
  if (event.type === 'turn/end')
78
78
  last = `end/${event.data.reason.kind}`;
79
79
  if (event.type === 'user/message') {
80
- if (event.data.id === words.id)
80
+ if (event.data.id === words.id) {
81
81
  admitted = true;
82
+ // The door only needed her to have the words; her answer leaves by its own tool, whenever she gives it.
83
+ if (options.untilTaken) {
84
+ finish();
85
+ return;
86
+ }
87
+ }
82
88
  else {
83
89
  last = `inject/${event.data.source.kind}`;
84
90
  if (admitted && event.data.source.kind === 'user') {
@@ -112,7 +118,11 @@ export async function askTurn(ctx, agent, words, options) {
112
118
  admit(options.inWorld, agent);
113
119
  if (options.context)
114
120
  agent.inject(options.context);
115
- agent.followup(words);
121
+ // Steered words are taken in at her next step, in the turn under way, as the partner's words in DSH are.
122
+ if (options.steer)
123
+ agent.steer(words);
124
+ else
125
+ agent.followup(words);
116
126
  await Promise.race([finished, cancelled]).catch((error) => { throw new Error(`${error.message}(${trace()})`, { cause: error }); });
117
127
  if (!admitted || failed || (cut && !reply.trim()))
118
128
  throw new Error(`${options.name} home request did not finish(${trace()})`);
@@ -15,6 +15,7 @@ export declare function createWechatHome(deps: {
15
15
  home(identity: SpeakerIdentity): Promise<Agent>;
16
16
  inWorld?: InWorld;
17
17
  timers?: LifeTimers;
18
+ midTurn?(agent: Agent): boolean;
18
19
  images?(identity: SpeakerIdentity, context: ChannelContextMessage[], reference?: ChannelReference): Promise<ContentBlock[]>;
19
20
  }): {
20
21
  ask: (text: string, suppliedIdentity: SpeakerIdentity, suppliedContext?: ChannelContextMessage[], suppliedMedia?: ChannelContextMessage[], suppliedReference?: ChannelReference) => Promise<{