@celljs/ta-web 4.32.0 → 4.33.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 (73) hide show
  1. package/README.en.md +1 -1
  2. package/README.md +1 -1
  3. package/esm/browser/assistant/assistant-ask-book.d.ts +10 -17
  4. package/esm/browser/assistant/assistant-ask-book.js +24 -61
  5. package/esm/browser/assistant/assistant-conversation.js +0 -2
  6. package/esm/browser/assistant/assistant-protocol.d.ts +4 -2
  7. package/esm/browser/assistant/assistant-role.d.ts +1 -1
  8. package/esm/browser/assistant/assistant-role.js +1 -1
  9. package/esm/browser/assistant/assistant-thread.js +15 -14
  10. package/esm/browser/assistant/assistant.d.ts +7 -2
  11. package/esm/browser/assistant/assistant.js +39 -8
  12. package/esm/browser/assistant/web-voice.d.ts +14 -0
  13. package/esm/browser/assistant/web-voice.js +36 -0
  14. package/esm/browser/components/chat-home-util.d.ts +5 -2
  15. package/esm/browser/components/chat-home-util.js +6 -3
  16. package/esm/browser/components/chat-list.js +1 -1
  17. package/esm/browser/components/cloud-sign-in-view.d.ts +1 -1
  18. package/esm/browser/components/host-view.d.ts +1 -1
  19. package/esm/browser/components/markdown.js +3 -2
  20. package/esm/browser/components/session-view.js +3 -2
  21. package/esm/browser/extension/web-api-components.d.ts +19 -0
  22. package/esm/browser/extension/web-api-contributions.d.ts +1 -0
  23. package/esm/browser/extension/web-extension-context.js +2 -8
  24. package/esm/browser/i18n/en/tools.d.ts +21 -0
  25. package/esm/browser/i18n/en/tools.js +21 -0
  26. package/esm/browser/i18n/ja/tools.js +21 -0
  27. package/esm/browser/i18n/locales.d.ts +22 -1
  28. package/esm/browser/i18n/messages.d.ts +21 -0
  29. package/esm/browser/i18n/zh/tools.js +21 -0
  30. package/esm/browser/i18n/zh-tw/tools.js +21 -0
  31. package/esm/browser/markdown/code-renderers.d.ts +2 -0
  32. package/esm/browser/markdown/code-renderers.js +2 -0
  33. package/esm/browser/util/mcp-words.d.ts +15 -0
  34. package/esm/browser/util/mcp-words.js +99 -0
  35. package/esm/browser/util/tool.js +13 -2
  36. package/esm/browser/util/transcription.d.ts +29 -0
  37. package/esm/browser/util/transcription.js +83 -0
  38. package/lib/browser/assistant/assistant-ask-book.d.ts +10 -17
  39. package/lib/browser/assistant/assistant-ask-book.js +24 -61
  40. package/lib/browser/assistant/assistant-conversation.js +0 -2
  41. package/lib/browser/assistant/assistant-protocol.d.ts +4 -2
  42. package/lib/browser/assistant/assistant-role.d.ts +1 -1
  43. package/lib/browser/assistant/assistant-role.js +1 -1
  44. package/lib/browser/assistant/assistant-thread.js +14 -13
  45. package/lib/browser/assistant/assistant.d.ts +7 -2
  46. package/lib/browser/assistant/assistant.js +39 -8
  47. package/lib/browser/assistant/web-voice.d.ts +15 -0
  48. package/lib/browser/assistant/web-voice.js +40 -0
  49. package/lib/browser/components/chat-home-util.d.ts +5 -2
  50. package/lib/browser/components/chat-home-util.js +6 -3
  51. package/lib/browser/components/chat-list.js +1 -1
  52. package/lib/browser/components/cloud-sign-in-view.d.ts +1 -1
  53. package/lib/browser/components/host-view.d.ts +1 -1
  54. package/lib/browser/components/markdown.js +2 -1
  55. package/lib/browser/components/session-view.js +2 -1
  56. package/lib/browser/extension/web-api-components.d.ts +19 -0
  57. package/lib/browser/extension/web-api-contributions.d.ts +1 -0
  58. package/lib/browser/extension/web-extension-context.js +2 -8
  59. package/lib/browser/i18n/en/tools.d.ts +21 -0
  60. package/lib/browser/i18n/en/tools.js +21 -0
  61. package/lib/browser/i18n/ja/tools.js +21 -0
  62. package/lib/browser/i18n/locales.d.ts +22 -1
  63. package/lib/browser/i18n/messages.d.ts +21 -0
  64. package/lib/browser/i18n/zh/tools.js +21 -0
  65. package/lib/browser/i18n/zh-tw/tools.js +21 -0
  66. package/lib/browser/markdown/code-renderers.d.ts +2 -0
  67. package/lib/browser/markdown/code-renderers.js +3 -1
  68. package/lib/browser/util/mcp-words.d.ts +16 -0
  69. package/lib/browser/util/mcp-words.js +102 -0
  70. package/lib/browser/util/tool.js +13 -2
  71. package/lib/browser/util/transcription.d.ts +30 -0
  72. package/lib/browser/util/transcription.js +86 -0
  73. package/package.json +7 -7
@@ -0,0 +1,99 @@
1
+ const MODIFIERS = {
2
+ cmd: '⌘',
3
+ command: '⌘',
4
+ meta: '⌘',
5
+ shift: '⇧',
6
+ option: '⌥',
7
+ alt: '⌥',
8
+ ctrl: '⌃',
9
+ control: '⌃',
10
+ fn: 'fn ',
11
+ };
12
+ function text(value) {
13
+ return typeof value === 'string' ? value.trim() : '';
14
+ }
15
+ function num(value) {
16
+ return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
17
+ }
18
+ /** A key as it is printed on the keyboard: `return` Return, `c` C, `cmd` ⌘. */
19
+ function key(name) {
20
+ const lower = name.toLowerCase();
21
+ if (MODIFIERS[lower]) {
22
+ return MODIFIERS[lower];
23
+ }
24
+ return name.length === 1 ? name.toUpperCase() : name.charAt(0).toUpperCase() + name.slice(1);
25
+ }
26
+ /** Keys pressed together: modifiers first, as a menu prints them (⌘⇧ S). */
27
+ function keys(names) {
28
+ const parts = names.filter(Boolean).map(key);
29
+ const mods = parts.filter(part => Object.values(MODIFIERS).includes(part)).join('');
30
+ const rest = parts.filter(part => !Object.values(MODIFIERS).includes(part)).join(' ');
31
+ return [mods, rest].filter(Boolean).join(' ');
32
+ }
33
+ /** Where a call points: an element of the last look at the window (`[12]`), else a point of it. */
34
+ function at(args) {
35
+ var _a;
36
+ const index = (_a = num(args.element_index)) !== null && _a !== void 0 ? _a : num(args.ref);
37
+ if (index !== undefined) {
38
+ return `[${index}]`;
39
+ }
40
+ const x = num(args.x);
41
+ const y = num(args.y);
42
+ return x !== undefined && y !== undefined ? `${Math.round(x)}, ${Math.round(y)}` : text(args.element) || text(args.selector);
43
+ }
44
+ const ARROWS = { up: '↑', down: '↓', left: '←', right: '→' };
45
+ function said(verb, target = '', code = false) {
46
+ return { verb, target, code };
47
+ }
48
+ /**
49
+ * The tools of MCP servers agents commonly use to work a computer or a browser (Cua Driver and its kind,
50
+ * Playwright), by the tool's own name whatever the server is called: `mcp__cua-driver__press_key` of
51
+ * another agent and `mcp__cua_driver__press_key` of Ta's scripts read the same. A tool of its own
52
+ * that a web extension draws goes by its renderer; one not here reads as its name in words.
53
+ */
54
+ const TOOLS = {
55
+ click: args => said(args.button === 'right' ? 'ta.tool.verb.rightClick' : num(args.count) === 2 ? 'ta.tool.verb.doubleClick' : 'ta.tool.verb.click', at(args)),
56
+ double_click: args => said('ta.tool.verb.doubleClick', at(args)),
57
+ right_click: args => said('ta.tool.verb.rightClick', at(args)),
58
+ set_value: args => said('ta.tool.verb.fill', text(args.value)),
59
+ type_text: args => said('ta.tool.verb.type', text(args.text)),
60
+ press_key: args => said('ta.tool.verb.pressKey', keys([...(Array.isArray(args.modifiers) ? args.modifiers.map(text) : []), text(args.key)]), true),
61
+ hotkey: args => said('ta.tool.verb.pressKey', keys(Array.isArray(args.keys) ? args.keys.map(text) : []), true),
62
+ scroll: args => { var _a; return said('ta.tool.verb.scroll', [(_a = ARROWS[text(args.direction)]) !== null && _a !== void 0 ? _a : '', at(args)].filter(Boolean).join(' ')); },
63
+ drag: args => {
64
+ const from = [num(args.from_x), num(args.from_y)];
65
+ const to = [num(args.to_x), num(args.to_y)];
66
+ const point = (xy) => (xy.every(value => value !== undefined) ? xy.map(value => Math.round(value)).join(', ') : '');
67
+ return said('ta.tool.verb.drag', [point(from), point(to)].filter(Boolean).join(' → '));
68
+ },
69
+ move_cursor: () => said('ta.tool.verb.moveCursor'),
70
+ get_window_state: () => said('ta.tool.verb.lookWindow'),
71
+ get_accessibility_tree: () => said('ta.tool.verb.lookDesktop'),
72
+ get_desktop_state: () => said('ta.tool.verb.screenshot'),
73
+ zoom: () => said('ta.tool.verb.zoom'),
74
+ list_apps: () => said('ta.tool.verb.listApps'),
75
+ list_windows: () => said('ta.tool.verb.listWindows'),
76
+ launch_app: args => said('ta.tool.verb.launchApp', text(args.name) || text(args.bundle_id) || (Array.isArray(args.urls) ? text(args.urls[0]) : '')),
77
+ bring_to_front: () => said('ta.tool.verb.bringToFront'),
78
+ kill_app: () => said('ta.tool.verb.quitApp'),
79
+ page: args => said('ta.tool.verb.workPage', text(args.url) || text(args.css_selector) || text(args.action)),
80
+ check_permissions: () => said('ta.tool.verb.checkPermissions'),
81
+ // Playwright
82
+ browser_navigate: args => said('ta.tool.verb.fetch', text(args.url)),
83
+ browser_click: args => said(args.doubleClick ? 'ta.tool.verb.doubleClick' : 'ta.tool.verb.click', at(args)),
84
+ browser_type: args => said('ta.tool.verb.type', text(args.text)),
85
+ browser_press_key: args => said('ta.tool.verb.pressKey', keys(text(args.key).split('+')), true),
86
+ browser_snapshot: () => said('ta.tool.verb.lookPage'),
87
+ browser_take_screenshot: () => said('ta.tool.verb.screenshot'),
88
+ };
89
+ /** What calls of known MCP tools do, in words: `press_key { key: 'return' }` reads "Press key Return". */
90
+ export var McpWords;
91
+ (function (McpWords) {
92
+ /** `tool`: the name the server gave it, without `mcp__server__`. */
93
+ function describe(tool, args) {
94
+ var _a;
95
+ return (_a = TOOLS[tool]) === null || _a === void 0 ? void 0 : _a.call(TOOLS, args);
96
+ }
97
+ McpWords.describe = describe;
98
+ })(McpWords || (McpWords = {}));
99
+ //# sourceMappingURL=mcp-words.js.map
@@ -1,3 +1,4 @@
1
+ import { McpWords } from './mcp-words.js';
1
2
  import { MessageUtil } from './message.js';
2
3
  import { ShellWords } from './shell-words.js';
3
4
  const VERBS = {
@@ -155,10 +156,15 @@ export var ToolUtil;
155
156
  // One of Ta's own tools, called through MCP: read as Ta's call of it, by what it was given;
156
157
  // before the agent says (while it runs), by what it was on.
157
158
  const own = summary(via.tool, input !== null && input !== void 0 ? input : {}, resolvers);
158
- return own.label || own.verb ? { ...own, name: tool, target: own.target || target } : { name: via.tool, target, code: false };
159
+ return own.label || own.verb ? { ...own, name: tool, target: own.target || target } : { name: tool, target, code: false };
159
160
  }
160
161
  if (via) {
161
- return { name: via.tool, target: target === tool ? '' : target, code: false };
162
+ // A tool of another server: in words when Ta knows it (McpWords), by what it was given.
163
+ const on = target === tool ? '' : target;
164
+ const said = McpWords.describe(via.tool, input !== null && input !== void 0 ? input : {});
165
+ return said
166
+ ? { verb: said.verb, name: tool, target: line(said.target) || on, code: !!said.target && said.code }
167
+ : { name: tool, target: on, code: false };
162
168
  }
163
169
  if (kind === 'execute') {
164
170
  return { ...command(tool, str(args.target) || str(args.title)), name: tool };
@@ -179,6 +185,11 @@ export var ToolUtil;
179
185
  case 'message_task':
180
186
  return { verb, name, target: line(str(args.message)) || str(args.id), code: false };
181
187
  default: {
188
+ const via = mcp(name);
189
+ const said = via && McpWords.describe(via.tool, args);
190
+ if (said) {
191
+ return { verb: said.verb, name, target: line(said.target), code: said.code };
192
+ }
182
193
  const value = Object.values(args).find(candidate => typeof candidate === 'string' && candidate.trim());
183
194
  return { verb, name, target: line(str(value)), code: false };
184
195
  }
@@ -0,0 +1,29 @@
1
+ import type { Voice } from './voice.js';
2
+ /** What hears: the recognizer of the device (Voice) or a voice of a service of voices.json (RealtimeVoice). */
3
+ export interface TranscriptionVoice {
4
+ listen(language: string, onText: (text: string, final: boolean) => void, onEnd: (error?: string) => void, options?: Voice.ListenOptions): Voice.Listening | undefined;
5
+ }
6
+ /**
7
+ * Writes down what is said until stopped, a meeting long (WebVoice.transcribe): a listening after another, each the
8
+ * words of a stretch of speech. A recognizer ends a listening on a silence, an utterance or a limit of its own; the
9
+ * next starts at once. The words of a listening come as they grow (`final` false), then once as they ended.
10
+ */
11
+ export declare namespace Transcription {
12
+ /** A listening that ends this soon having heard nothing counts as a quick one. */
13
+ const QUICK_MS = 1000;
14
+ /** Quick ones this many in a row end it: the recognizer cannot hear, and would be started again without end. */
15
+ const QUICK_TIMES = 5;
16
+ interface Events {
17
+ onText(text: string, final: boolean): void;
18
+ /** Once: stopped (no error), or the recognizer failed. */
19
+ onEnd(error?: string): void;
20
+ }
21
+ interface Transcribing {
22
+ /** Ends it, the words of the listening going on taken as they are. */
23
+ stop(): void;
24
+ }
25
+ /** Starts it; undefined when the voice cannot listen. */
26
+ function start(voice: TranscriptionVoice, language: string, events: Events, options?: {
27
+ hints?: readonly string[];
28
+ }, now?: () => number): Transcribing | undefined;
29
+ }
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Writes down what is said until stopped, a meeting long (WebVoice.transcribe): a listening after another, each the
3
+ * words of a stretch of speech. A recognizer ends a listening on a silence, an utterance or a limit of its own; the
4
+ * next starts at once. The words of a listening come as they grow (`final` false), then once as they ended.
5
+ */
6
+ export var Transcription;
7
+ (function (Transcription) {
8
+ /** A listening that ends this soon having heard nothing counts as a quick one. */
9
+ Transcription.QUICK_MS = 1000;
10
+ /** Quick ones this many in a row end it: the recognizer cannot hear, and would be started again without end. */
11
+ Transcription.QUICK_TIMES = 5;
12
+ /** Starts it; undefined when the voice cannot listen. */
13
+ function start(voice, language, events, options = {}, now = Date.now) {
14
+ let ended = false;
15
+ let listening;
16
+ let heard = '';
17
+ let quick = 0;
18
+ const end = (error) => {
19
+ if (!ended) {
20
+ ended = true;
21
+ events.onEnd(error);
22
+ }
23
+ };
24
+ const commit = () => {
25
+ const text = heard.trim();
26
+ heard = '';
27
+ if (text) {
28
+ events.onText(text, true);
29
+ }
30
+ return text !== '';
31
+ };
32
+ const next = () => {
33
+ const at = now();
34
+ heard = '';
35
+ let done = false;
36
+ listening = voice.listen(language, text => {
37
+ if (!ended && !done) {
38
+ heard = text;
39
+ events.onText(text, false);
40
+ }
41
+ }, error => {
42
+ if (ended || done) {
43
+ return;
44
+ }
45
+ done = true;
46
+ listening = undefined;
47
+ if (commit()) {
48
+ quick = 0;
49
+ }
50
+ else {
51
+ quick = now() - at < Transcription.QUICK_MS ? quick + 1 : 0;
52
+ }
53
+ if (error) {
54
+ end(error);
55
+ }
56
+ else if (quick >= Transcription.QUICK_TIMES) {
57
+ end('no-speech');
58
+ }
59
+ else if (!next()) {
60
+ end('unavailable');
61
+ }
62
+ }, { continuous: true, ...(options.hints ? { hints: options.hints } : {}) });
63
+ return listening !== undefined;
64
+ };
65
+ if (!next()) {
66
+ return undefined;
67
+ }
68
+ return {
69
+ stop: () => {
70
+ if (ended) {
71
+ return;
72
+ }
73
+ commit();
74
+ const stopping = listening;
75
+ listening = undefined;
76
+ end();
77
+ stopping === null || stopping === void 0 ? void 0 : stopping.stop();
78
+ },
79
+ };
80
+ }
81
+ Transcription.start = start;
82
+ })(Transcription || (Transcription = {}));
83
+ //# sourceMappingURL=transcription.js.map
@@ -1,34 +1,27 @@
1
1
  import type { TaState } from '../state/state-protocol';
2
2
  import type { AssistantAsk } from './assistant-protocol';
3
3
  /**
4
- * The tasks the double waits to start, as every page of the user keeps them together (AssistantStates.ASKS):
5
- * the page that runs start_task asks, the user answers on any page (the phone too), and the page that asked
6
- * starts the task or not. An ask has the id of its call of start_task and shows while that call waits: the ask
7
- * of a run stopped meanwhile, or of a page that went away (its call then runs again on another page, which asks
8
- * under the same id), shows no more.
4
+ * The tasks the double asked the user to let start, as every page of the user keeps them together
5
+ * (AssistantStates.ASKS), deferred (docs/design/ta-always-on.md 3.10): the double's turn ended as it asked, nothing
6
+ * waits in its conversation, and the page the user answers on (the phone too) starts the task or not and tells the
7
+ * double, as a message of its conversation.
9
8
  */
10
9
  export declare class AssistantAskBook {
11
10
  protected readonly persisted: TaState;
12
11
  /** The asks to show changed. */
13
12
  protected readonly changed: (asks: AssistantAsk[]) => void;
14
- /** The answers this page waits for, by ask id. */
15
- protected readonly waiting: Map<string, (start: boolean) => void>;
16
- /** The calls of the double's conversation that wait. */
17
- protected calls: ReadonlySet<string>;
13
+ protected readonly now: () => number;
18
14
  protected kept?: AssistantAsk[];
19
15
  protected shown: AssistantAsk[];
20
16
  constructor(persisted: TaState,
21
17
  /** The asks to show changed. */
22
- changed: (asks: AssistantAsk[]) => void);
18
+ changed: (asks: AssistantAsk[]) => void, now?: () => number);
23
19
  /** Follows what other pages write: an ask of another, an answer given on another. */
24
20
  watch(): () => void;
25
- /** The calls that wait now; one this page asked for that stopped waiting (its run was stopped) is not answered any more. */
26
- waitingCalls(ids: readonly string[]): void;
27
- /** Waits for the user's go; already answered (on another page, before the page that asked first went away), at once. */
28
- ask(ask: AssistantAsk): Promise<boolean>;
29
- /** The user's answer: here, to what this page waits for; else to the page that asked. */
30
- answer(id: string, start: boolean): void;
31
- protected settle(id: string, start: boolean): void;
21
+ /** Kept for the user to answer, on any page; one of the same id is replaced. */
22
+ ask(ask: AssistantAsk): void;
23
+ /** The ask the user answers, taken out so that no other page answers it too; undefined when it went. */
24
+ take(id: string): AssistantAsk | undefined;
32
25
  protected list(): AssistantAsk[];
33
26
  protected write(asks: AssistantAsk[]): void;
34
27
  protected refresh(): void;
@@ -3,77 +3,48 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AssistantAskBook = void 0;
4
4
  const assistant_state_1 = require("./assistant-state");
5
5
  const { ASKS } = assistant_state_1.AssistantStates;
6
+ /** An ask the user did not answer in this long goes: the work it was for is long gone. */
7
+ const KEEP_MS = 7 * 86400000;
6
8
  /**
7
- * The tasks the double waits to start, as every page of the user keeps them together (AssistantStates.ASKS):
8
- * the page that runs start_task asks, the user answers on any page (the phone too), and the page that asked
9
- * starts the task or not. An ask has the id of its call of start_task and shows while that call waits: the ask
10
- * of a run stopped meanwhile, or of a page that went away (its call then runs again on another page, which asks
11
- * under the same id), shows no more.
9
+ * The tasks the double asked the user to let start, as every page of the user keeps them together
10
+ * (AssistantStates.ASKS), deferred (docs/design/ta-always-on.md 3.10): the double's turn ended as it asked, nothing
11
+ * waits in its conversation, and the page the user answers on (the phone too) starts the task or not and tells the
12
+ * double, as a message of its conversation.
12
13
  */
13
14
  class AssistantAskBook {
14
15
  constructor(persisted,
15
16
  /** The asks to show changed. */
16
- changed) {
17
+ changed, now = Date.now) {
17
18
  this.persisted = persisted;
18
19
  this.changed = changed;
19
- /** The answers this page waits for, by ask id. */
20
- this.waiting = new Map();
21
- /** The calls of the double's conversation that wait. */
22
- this.calls = new Set();
20
+ this.now = now;
23
21
  this.shown = [];
24
22
  }
25
23
  /** Follows what other pages write: an ask of another, an answer given on another. */
26
24
  watch() {
25
+ this.refresh();
27
26
  return this.persisted.subscribe(() => {
28
27
  if (this.persisted.get(ASKS) !== this.kept) {
29
28
  this.refresh();
30
29
  }
31
30
  });
32
31
  }
33
- /** The calls that wait now; one this page asked for that stopped waiting (its run was stopped) is not answered any more. */
34
- waitingCalls(ids) {
35
- if (ids.length === this.calls.size && ids.every(id => this.calls.has(id))) {
36
- return;
37
- }
38
- this.calls = new Set(ids);
39
- for (const id of [...this.waiting.keys()]) {
40
- if (!this.calls.has(id)) {
41
- this.settle(id, false);
42
- }
43
- }
44
- this.refresh();
45
- }
46
- /** Waits for the user's go; already answered (on another page, before the page that asked first went away), at once. */
32
+ /** Kept for the user to answer, on any page; one of the same id is replaced. */
47
33
  ask(ask) {
48
- var _a;
49
- const asks = this.list();
50
- const answered = (_a = asks.find(each => each.id === ask.id)) === null || _a === void 0 ? void 0 : _a.answer;
51
- if (answered !== undefined) {
52
- this.write(asks.filter(each => each.id !== ask.id));
53
- return Promise.resolve(answered);
54
- }
55
- return new Promise(resolve => {
56
- this.waiting.set(ask.id, resolve);
57
- // Those of calls that no longer wait go.
58
- this.write([...asks.filter(each => each.id !== ask.id && this.calls.has(each.id)), ask]);
59
- });
34
+ this.write([...this.list().filter(each => each.id !== ask.id), ask]);
60
35
  }
61
- /** The user's answer: here, to what this page waits for; else to the page that asked. */
62
- answer(id, start) {
63
- if (this.waiting.has(id)) {
64
- this.settle(id, start);
65
- return;
36
+ /** The ask the user answers, taken out so that no other page answers it too; undefined when it went. */
37
+ take(id) {
38
+ const asks = this.list();
39
+ const found = asks.find(ask => ask.id === id);
40
+ if (found) {
41
+ this.write(asks.filter(ask => ask !== found));
66
42
  }
67
- this.write(this.list().map(ask => (ask.id === id ? { ...ask, answer: start } : ask)));
68
- }
69
- settle(id, start) {
70
- const resolve = this.waiting.get(id);
71
- this.waiting.delete(id);
72
- this.write(this.list().filter(ask => ask.id !== id));
73
- resolve === null || resolve === void 0 ? void 0 : resolve(start);
43
+ return found;
74
44
  }
75
45
  list() {
76
- return this.persisted.get(ASKS);
46
+ const now = this.now();
47
+ return this.persisted.get(ASKS).filter(ask => now - ask.at < KEEP_MS);
77
48
  }
78
49
  write(asks) {
79
50
  this.persisted.set(ASKS, asks);
@@ -81,18 +52,10 @@ class AssistantAskBook {
81
52
  }
82
53
  refresh() {
83
54
  const asks = this.list();
84
- this.kept = asks;
85
- // Answered on another page: what this page waits for is settled.
86
- for (const ask of asks) {
87
- if (ask.answer !== undefined && this.waiting.has(ask.id)) {
88
- this.settle(ask.id, ask.answer);
89
- return;
90
- }
91
- }
92
- const shown = asks.filter(ask => ask.answer === undefined && this.calls.has(ask.id));
93
- if (shown.length !== this.shown.length || shown.some((ask, index) => ask !== this.shown[index])) {
94
- this.shown = shown;
95
- this.changed(shown);
55
+ this.kept = this.persisted.get(ASKS);
56
+ if (asks.length !== this.shown.length || asks.some((ask, index) => ask !== this.shown[index])) {
57
+ this.shown = asks;
58
+ this.changed(asks);
96
59
  }
97
60
  }
98
61
  }
@@ -295,7 +295,6 @@ class AssistantConversation {
295
295
  if (this.assistant !== store) {
296
296
  return;
297
297
  }
298
- this.asks.waitingCalls(state.pendingClientTools.map(request => request.id));
299
298
  if (!state.working) {
300
299
  this.flushNotes();
301
300
  }
@@ -304,7 +303,6 @@ class AssistantConversation {
304
303
  this.preview = undefined;
305
304
  this.keep(store);
306
305
  this.update({ ready: true, error: undefined });
307
- this.asks.waitingCalls(store.state.pendingClientTools.map(request => request.id));
308
306
  this.flushNotes();
309
307
  await this.followRunning(sessions);
310
308
  }
@@ -47,8 +47,10 @@ export interface AssistantAsk {
47
47
  cwd: string;
48
48
  /** When the double asked. */
49
49
  at: number;
50
- /** What the user answered on a page that did not ask, for the page that did. */
51
- answer?: boolean;
50
+ /** The rest of what start_task was given, to start it with once the user lets it. */
51
+ isolate?: boolean;
52
+ verify?: string;
53
+ verifies?: string;
52
54
  }
53
55
  export interface AssistantState {
54
56
  /** The conversation with ta is open. */
@@ -7,7 +7,7 @@ export declare const ASSISTANT_PROMPT = "You are Ta, the user's personal agent:
7
7
  * system prompt to ask before they build a team: keep them as they are.
8
8
  */
9
9
  export declare const ASK_FIRST_MARK = "Ask the user before you hand out work";
10
- export declare const ASK_FIRST_PROMPT = "- Ask the user before you hand out work you start of your own accord (a next step, a check, a guess the user did not ask for): start it without asked, and the user agrees to it on their screen; you need not ask in words first. Work they asked for in their message (asked: true) starts at once. A start they turn down is not to be tried again unasked.";
10
+ export declare const ASK_FIRST_PROMPT = "- Ask the user before you hand out work you start of your own accord (a next step, a check, a guess the user did not ask for): start it without asked: the user is asked on their screen, your turn ends, and a message tells you whether they let it start; you need not ask in words first. Work they asked for in their message (asked: true) starts at once. A start they turn down is not to be tried again unasked.";
11
11
  /**
12
12
  * How much the double hands out (Settings.delegate), each with its mark (TaDelegateUtil.mark), which the guard of ta
13
13
  * serve reads to turn down what the level leaves to tasks.
@@ -26,7 +26,7 @@ exports.ASSISTANT_PROMPT = `You are Ta, the user's personal agent: a little gree
26
26
  * system prompt to ask before they build a team: keep them as they are.
27
27
  */
28
28
  exports.ASK_FIRST_MARK = 'Ask the user before you hand out work';
29
- exports.ASK_FIRST_PROMPT = `- ${exports.ASK_FIRST_MARK} you start of your own accord (a next step, a check, a guess the user did not ask for): start it without asked, and the user agrees to it on their screen; you need not ask in words first. Work they asked for in their message (asked: true) starts at once. A start they turn down is not to be tried again unasked.`;
29
+ exports.ASK_FIRST_PROMPT = `- ${exports.ASK_FIRST_MARK} you start of your own accord (a next step, a check, a guess the user did not ask for): start it without asked: the user is asked on their screen, your turn ends, and a message tells you whether they let it start; you need not ask in words first. Work they asked for in their message (asked: true) starts at once. A start they turn down is not to be tried again unasked.`;
30
30
  /**
31
31
  * How much the double hands out (Settings.delegate), each with its mark (TaDelegateUtil.mark), which the guard of ta
32
32
  * serve reads to turn down what the level leaves to tasks.
@@ -168,18 +168,19 @@ exports.AssistantThread = React.memo(function AssistantThread({ state, reply, ta
168
168
  // The cards of the tasks the last turn handed out come after its steps.
169
169
  const inSteps = (0, message_list_1.endsInSteps)(last) && !web_tasks_1.WebTaskUtil.startedIn(own, origin, starts[items.length - 1], Number.POSITIVE_INFINITY).length;
170
170
  return (React.createElement(code_renderers_1.CodeReply.Provider, { value: reply },
171
- items.map((item, index) => {
172
- var _a;
173
- if (index < shown.from) {
174
- return null;
175
- }
176
- const turn = item.kind === 'turn';
177
- const started = turn ? web_tasks_1.WebTaskUtil.startedIn(own, origin, starts[index], (_a = starts[index + 1]) !== null && _a !== void 0 ? _a : Number.POSITIVE_INFINITY) : NO_TASKS;
178
- return (React.createElement("div", { key: item.key, "data-row": item.key, className: shown.className(index, asks[index] && conversation_scroll_util_1.ASK_CLASS) },
179
- breaks[index] !== undefined && React.createElement(message_footer_1.TimeBreak, { timestamp: breaks[index] }),
180
- React.createElement(code_renderers_1.CodeAnswer.Provider, { value: answers[index] },
181
- React.createElement(DoubleRow, { item: item, tools: state.tools, mood: turn ? process_1.ProcessUtil.mood(item, index === lastTurn, waiting) : 'idle', status: onHead && item === last ? status : undefined, latest: index === lastTurn, started: started, onTask: onTask, t: t }))));
182
- }),
183
- status && !onHead && React.createElement("div", { className: `ta-run-line ${inSteps ? 'ta-run-steps' : ''}` }, status)));
171
+ React.createElement(code_renderers_1.CodeConversation.Provider, { value: origin },
172
+ items.map((item, index) => {
173
+ var _a;
174
+ if (index < shown.from) {
175
+ return null;
176
+ }
177
+ const turn = item.kind === 'turn';
178
+ const started = turn ? web_tasks_1.WebTaskUtil.startedIn(own, origin, starts[index], (_a = starts[index + 1]) !== null && _a !== void 0 ? _a : Number.POSITIVE_INFINITY) : NO_TASKS;
179
+ return (React.createElement("div", { key: item.key, "data-row": item.key, className: shown.className(index, asks[index] && conversation_scroll_util_1.ASK_CLASS) },
180
+ breaks[index] !== undefined && React.createElement(message_footer_1.TimeBreak, { timestamp: breaks[index] }),
181
+ React.createElement(code_renderers_1.CodeAnswer.Provider, { value: answers[index] },
182
+ React.createElement(DoubleRow, { item: item, tools: state.tools, mood: turn ? process_1.ProcessUtil.mood(item, index === lastTurn, waiting) : 'idle', status: onHead && item === last ? status : undefined, latest: index === lastTurn, started: started, onTask: onTask, t: t }))));
183
+ }),
184
+ status && !onHead && React.createElement("div", { className: `ta-run-line ${inSteps ? 'ta-run-steps' : ''}` }, status))));
184
185
  });
185
186
  //# sourceMappingURL=assistant-thread.js.map
@@ -2,7 +2,7 @@ import type { ClientTool, SessionState, SessionStore } from '@celljs/ta-client';
2
2
  import { type TaSessionInfo } from '@celljs/ta-protocol';
3
3
  import { AssistantAskBook } from './assistant-ask-book';
4
4
  import { AssistantConversation } from './assistant-conversation';
5
- import { type AssistantTask, TaAssistant } from './assistant-protocol';
5
+ import { type AssistantAsk, type AssistantTask, TaAssistant } from './assistant-protocol';
6
6
  import { AssistantTaskBook } from './assistant-task-book';
7
7
  export declare class TaAssistantImpl extends AssistantConversation implements TaAssistant {
8
8
  loadTasks(): Promise<void>;
@@ -29,7 +29,12 @@ export declare class TaAssistantImpl extends AssistantConversation implements Ta
29
29
  * does not run (it ended unseen, or closed) stops here: an abort would change nothing.
30
30
  */
31
31
  stopTask(taskId: string): Promise<void>;
32
+ /**
33
+ * The user lets a task the double asked for start, or not: started here, and the double told, as a message of its
34
+ * conversation; its turn ended when it asked (deferred, docs/design/ta-always-on.md 3.10).
35
+ */
32
36
  answer(askId: string, start: boolean): void;
37
+ protected answered(ask: AssistantAsk, start: boolean): Promise<void>;
33
38
  takeOver(taskId: string): Promise<string>;
34
39
  adopt({ sessionId, title, cwd }: {
35
40
  sessionId: string;
@@ -72,7 +77,7 @@ export declare class TaAssistantImpl extends AssistantConversation implements Ta
72
77
  verify?: string;
73
78
  verifies?: string;
74
79
  asked?: boolean;
75
- }, call: string): Promise<string>;
80
+ }, call: string, confirmed?: boolean): Promise<string>;
76
81
  /**
77
82
  * A git worktree for a task, beside the repository of `where`, on a branch of its own from what the repository
78
83
  * has checked out; the task works in the same folder of it as `where` is of the repository.
@@ -130,8 +130,32 @@ let TaAssistantImpl = class TaAssistantImpl extends assistant_conversation_1.Ass
130
130
  this.book.change(task, { status: 'stopped', endedAt: Date.now() });
131
131
  }
132
132
  }
133
+ /**
134
+ * The user lets a task the double asked for start, or not: started here, and the double told, as a message of its
135
+ * conversation; its turn ended when it asked (deferred, docs/design/ta-always-on.md 3.10).
136
+ */
133
137
  answer(askId, start) {
134
- this.asks.answer(askId, start);
138
+ const ask = this.asks.take(askId);
139
+ if (!ask) {
140
+ return;
141
+ }
142
+ this.initiative.record(start ? 'accepted' : 'declined', ask.title);
143
+ void this.answered(ask, start).catch(error => console.error(`The task ${ask.title} could not start: ${error instanceof Error ? error.message : error}`));
144
+ }
145
+ async answered(ask, start) {
146
+ let told;
147
+ if (start) {
148
+ try {
149
+ told = `The user let task "${ask.title}" start. ${await this.startTask({ ...ask, asked: true }, ask.id, true)}`;
150
+ }
151
+ catch (error) {
152
+ told = `The user let task "${ask.title}" start, but it could not: ${error instanceof Error ? error.message : String(error)}`;
153
+ }
154
+ }
155
+ else {
156
+ told = `The user did not let task "${ask.title}" start. Ask them what they want instead; do not start it again unasked.`;
157
+ }
158
+ await this.send(ta_protocol_1.TaMessageSource.mark(told, ta_protocol_1.TaMessageSource.DOUBLE, 'start_task'), 'followUp', `answer_${ask.id}`);
135
159
  }
136
160
  async takeOver(taskId) {
137
161
  var _a;
@@ -290,7 +314,7 @@ let TaAssistantImpl = class TaAssistantImpl extends assistant_conversation_1.Ass
290
314
  });
291
315
  }
292
316
  /** `call`: the id of the call of start_task, which an ask of it has. */
293
- async startTask({ title, instructions, cwd, isolate, verify, verifies, asked, }, call) {
317
+ async startTask({ title, instructions, cwd, isolate, verify, verifies, asked, }, call, confirmed = false) {
294
318
  var _a, _b;
295
319
  var _c, _d;
296
320
  const { confirmTasks, maxTasks } = this.settings.state.settings;
@@ -301,12 +325,19 @@ let TaAssistantImpl = class TaAssistantImpl extends assistant_conversation_1.Ass
301
325
  const where = cwd || ((_a = this.workbench.state.server) === null || _a === void 0 ? void 0 : _a.cwd) || '.';
302
326
  // Work the user asked for in the message this run answers is started at once: the card is for what the double
303
327
  // starts of its own accord (docs/design/ta-double.md, 听懂与派活), never a second question after their go.
304
- if (confirmTasks && !(asked === true && assistant_task_util_1.AssistantTaskUtil.askedByUser((_c = (_b = this.store()) === null || _b === void 0 ? void 0 : _b.state.messages) !== null && _c !== void 0 ? _c : []))) {
305
- const started = await this.asks.ask({ id: call, title, instructions, cwd: where, at: Date.now() });
306
- this.initiative.record(started ? 'accepted' : 'declined', title);
307
- if (!started) {
308
- return `The user did not let task "${title}" start. Ask them what they want instead; do not start it again unasked.`;
309
- }
328
+ // Deferred: the user answers on any page, later; the turn ends now rather than wait in it.
329
+ if (!confirmed && confirmTasks && !(asked === true && assistant_task_util_1.AssistantTaskUtil.askedByUser((_c = (_b = this.store()) === null || _b === void 0 ? void 0 : _b.state.messages) !== null && _c !== void 0 ? _c : []))) {
330
+ this.asks.ask({
331
+ id: call,
332
+ title,
333
+ instructions,
334
+ cwd: where,
335
+ at: Date.now(),
336
+ ...(isolate ? { isolate } : {}),
337
+ ...(verify ? { verify } : {}),
338
+ ...(verifies ? { verifies } : {}),
339
+ });
340
+ return `Asked the user on their screen whether to start task "${title}": it starts once they agree, and you are told then. End your turn now; do not ask again in words, nor wait.`;
310
341
  }
311
342
  if (verifies) {
312
343
  // Throws for a task there is not.
@@ -0,0 +1,15 @@
1
+ import type { WebTranscribeListener, WebTranscribing, WebVoice } from '../extension/web-api-components';
2
+ import type { TaSettings } from '../settings/settings-protocol';
3
+ import type { RealtimeVoiceHost } from './realtime-voice-protocol';
4
+ /** `ui.voice` of web extensions: the recognizer of the page, the voice of the settings, what is said written down. */
5
+ export declare function webVoice(host: {
6
+ readonly workbench: RealtimeVoiceHost;
7
+ readonly settings: TaSettings;
8
+ }): WebVoice;
9
+ /**
10
+ * WebVoice.transcribe: what is said written down until stopped, as a meeting. With the service calls use when one is
11
+ * chosen in Settings → Voice (it only hears, nothing answers; docs/design/ta-voice.md), else with the recognizer of
12
+ * the device; undefined where neither can listen.
13
+ */
14
+ export declare function transcribeSpeech(host: RealtimeVoiceHost, language: string, listener: WebTranscribeListener): Promise<WebTranscribing | undefined>;
15
+ //# sourceMappingURL=web-voice.d.ts.map