@celljs/ta-web 4.32.1 → 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 (37) 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.d.ts +7 -2
  10. package/esm/browser/assistant/assistant.js +39 -8
  11. package/esm/browser/assistant/web-voice.d.ts +14 -0
  12. package/esm/browser/assistant/web-voice.js +36 -0
  13. package/esm/browser/components/chat-home-util.d.ts +5 -2
  14. package/esm/browser/components/chat-home-util.js +6 -3
  15. package/esm/browser/components/chat-list.js +1 -1
  16. package/esm/browser/extension/web-api-components.d.ts +19 -0
  17. package/esm/browser/extension/web-extension-context.js +2 -8
  18. package/esm/browser/util/transcription.d.ts +29 -0
  19. package/esm/browser/util/transcription.js +83 -0
  20. package/lib/browser/assistant/assistant-ask-book.d.ts +10 -17
  21. package/lib/browser/assistant/assistant-ask-book.js +24 -61
  22. package/lib/browser/assistant/assistant-conversation.js +0 -2
  23. package/lib/browser/assistant/assistant-protocol.d.ts +4 -2
  24. package/lib/browser/assistant/assistant-role.d.ts +1 -1
  25. package/lib/browser/assistant/assistant-role.js +1 -1
  26. package/lib/browser/assistant/assistant.d.ts +7 -2
  27. package/lib/browser/assistant/assistant.js +39 -8
  28. package/lib/browser/assistant/web-voice.d.ts +15 -0
  29. package/lib/browser/assistant/web-voice.js +40 -0
  30. package/lib/browser/components/chat-home-util.d.ts +5 -2
  31. package/lib/browser/components/chat-home-util.js +6 -3
  32. package/lib/browser/components/chat-list.js +1 -1
  33. package/lib/browser/extension/web-api-components.d.ts +19 -0
  34. package/lib/browser/extension/web-extension-context.js +2 -8
  35. package/lib/browser/util/transcription.d.ts +30 -0
  36. package/lib/browser/util/transcription.js +86 -0
  37. package/package.json +7 -7
@@ -309,6 +309,25 @@ export interface WebVoice {
309
309
  speak(text: string, onEnd?: () => void): void;
310
310
  /** Stops reading. */
311
311
  hush(): void;
312
+ /**
313
+ * Writes down what is said until stopped, as long as a meeting: with the service of Settings → Voice when one is
314
+ * chosen (ta serve hears, its key stays there), else with the recognizer of the device. `onText` gets the words
315
+ * of a stretch of speech as they grow, then once with `final` as it ended; `onEnd` follows once, stopped or
316
+ * failed (`error`). Undefined where the page cannot listen. Newer than some Ta apps: `voice.transcribe?.(…)`.
317
+ */
318
+ transcribe(listener: WebTranscribeListener): Promise<WebTranscribing | undefined>;
319
+ }
320
+ export interface WebTranscribeListener {
321
+ onText(text: string, final: boolean): void;
322
+ onEnd(error?: string): void;
323
+ /** Words to expect: names, terms of the meeting. */
324
+ hints?: readonly string[];
325
+ }
326
+ export interface WebTranscribing {
327
+ /** It hears through the service of Settings → Voice, not the recognizer of the device. */
328
+ readonly service: boolean;
329
+ /** Ends it: the words heard so far come as final, then `onEnd`. */
330
+ stop(): void;
312
331
  }
313
332
  export interface WebComposerProps {
314
333
  placeholder?: string;
@@ -1,7 +1,7 @@
1
1
  import { TaMessageSource, } from '@celljs/ta-protocol';
2
2
  import * as React from 'react';
3
- import { ReadAloud } from '../assistant/read-aloud.js';
4
3
  import { TaskIcon } from '../assistant/task-views.js';
4
+ import { webVoice } from '../assistant/web-voice.js';
5
5
  import { useBusy } from '../components/busy.js';
6
6
  import { ChatAskUtil, LET_GO_ASKS } from '../components/chat-asks.js';
7
7
  import { PINNED } from '../components/chat-list-util.js';
@@ -45,7 +45,6 @@ import { ScreenUtil } from '../screen/screen-protocol.js';
45
45
  import { DefaultWebTerminal } from '../terminal/web-terminal.js';
46
46
  import { DesktopUtil } from '../util/desktop.js';
47
47
  import { FileDragUtil } from '../util/file-drag.js';
48
- import { Voice } from '../util/voice.js';
49
48
  import { WEB_ICONS } from './icons.js';
50
49
  import { WebCwdUtil, WebLabelUtil } from './web-extension-protocol.js';
51
50
  import { WebExtensionRunUtil } from './web-extension-run.js';
@@ -74,12 +73,7 @@ export class WebExtensionContext {
74
73
  remote: this.host.workbench,
75
74
  }); };
76
75
  this.holdToTalk = (props) => React.createElement(HoldToTalk, { ...props, notices: this.host.notices });
77
- this.voice = {
78
- canListen: () => Voice.canListen(),
79
- canSpeak: () => Voice.canSpeak(),
80
- speak: (text, onEnd) => ReadAloud.of(this.host.workbench).speak(text, this.host.settings.state.language, onEnd !== null && onEnd !== void 0 ? onEnd : (() => undefined), this.host.settings.state.settings.voice),
81
- hush: () => ReadAloud.of(this.host.workbench).hush(),
82
- };
76
+ this.voice = webVoice(this.host);
83
77
  this.shareSheet = (props) => React.createElement(ShareSheet, { ...props, notices: this.host.notices, rooms: this.host.workbench.rooms });
84
78
  this.modelPicker = (props) => React.createElement(SettingsModelPicker, { ...props, settings: this.host.workbench.settings });
85
79
  this.folderPicker = ({ initial, onPick, onClose }) => { var _a; return React.createElement(FolderPicker, {
@@ -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.
@@ -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
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.webVoice = webVoice;
4
+ exports.transcribeSpeech = transcribeSpeech;
5
+ const transcription_1 = require("../util/transcription");
6
+ const voice_1 = require("../util/voice");
7
+ const read_aloud_1 = require("./read-aloud");
8
+ const realtime_voice_1 = require("./realtime-voice");
9
+ /** `ui.voice` of web extensions: the recognizer of the page, the voice of the settings, what is said written down. */
10
+ function webVoice(host) {
11
+ return {
12
+ canListen: () => voice_1.Voice.canListen(),
13
+ canSpeak: () => voice_1.Voice.canSpeak(),
14
+ speak: (text, onEnd) => read_aloud_1.ReadAloud.of(host.workbench).speak(text, host.settings.state.language, onEnd !== null && onEnd !== void 0 ? onEnd : (() => undefined), host.settings.state.settings.voice),
15
+ hush: () => read_aloud_1.ReadAloud.of(host.workbench).hush(),
16
+ transcribe: listener => transcribeSpeech(host.workbench, host.settings.state.language, listener),
17
+ };
18
+ }
19
+ /**
20
+ * WebVoice.transcribe: what is said written down until stopped, as a meeting. With the service calls use when one is
21
+ * chosen in Settings → Voice (it only hears, nothing answers; docs/design/ta-voice.md), else with the recognizer of
22
+ * the device; undefined where neither can listen.
23
+ */
24
+ async function transcribeSpeech(host, language, listener) {
25
+ const voices = await host.voice.listVoices().catch(() => undefined);
26
+ const service = (voices === null || voices === void 0 ? void 0 : voices.use) ? await new realtime_voice_1.RealtimeVoice(host).open(language).catch(() => undefined) : undefined;
27
+ const transcribing = transcription_1.Transcription.start(service !== null && service !== void 0 ? service : (voice_1.Voice.canListen() ? voice_1.Voice : { listen: () => undefined }), language, {
28
+ onText: (text, final) => listener.onText(text, final),
29
+ onEnd: error => {
30
+ service === null || service === void 0 ? void 0 : service.stop();
31
+ listener.onEnd(error);
32
+ },
33
+ }, { hints: listener.hints });
34
+ if (!transcribing) {
35
+ service === null || service === void 0 ? void 0 : service.stop();
36
+ return undefined;
37
+ }
38
+ return { service: !!service, stop: () => transcribing.stop() };
39
+ }
40
+ //# sourceMappingURL=web-voice.js.map
@@ -90,9 +90,12 @@ export declare namespace ChatHomeUtil {
90
90
  function standIns(items: readonly WebHomeEntry[]): ReadonlySet<string>;
91
91
  /**
92
92
  * The rows of the list for tasks: those that are no conversation, and those whose conversation the list does not
93
- * have (gone, or not read yet), not lost; split as `archive` does.
93
+ * have (gone, or not read yet), not lost; split as `archive` does. One whose conversation the user took out of the
94
+ * list (`removed`) goes with it, to Removed.
94
95
  */
95
- function rows(home: ChatHomeTasks | undefined, all: readonly WebTaskEntry[] | undefined, listed: (file: string) => boolean, query: string, since: number | undefined, archived: readonly string[]): {
96
+ function rows(home: ChatHomeTasks | undefined, all: readonly WebTaskEntry[] | undefined, listed: {
97
+ has(file: string): boolean;
98
+ }, query: string, since: number | undefined, archived: readonly string[], removed?: readonly string[]): {
96
99
  listed: ChatTaskRow[];
97
100
  archived: ChatTaskRow[];
98
101
  };
@@ -72,10 +72,13 @@ var ChatHomeUtil;
72
72
  ChatHomeUtil.standIns = standIns;
73
73
  /**
74
74
  * The rows of the list for tasks: those that are no conversation, and those whose conversation the list does not
75
- * have (gone, or not read yet), not lost; split as `archive` does.
75
+ * have (gone, or not read yet), not lost; split as `archive` does. One whose conversation the user took out of the
76
+ * list (`removed`) goes with it, to Removed.
76
77
  */
77
- function rows(home, all, listed, query, since, archived) {
78
- const tasks = home ? [...home.rows, ...(all !== null && all !== void 0 ? all : []).filter(task => task.status !== 'waiting' && !!task.session && !listed(task.session))] : [];
78
+ function rows(home, all, listed, query, since, archived, removed = []) {
79
+ const out = new Set(removed);
80
+ const lost = (task) => task.status !== 'waiting' && !!task.session && !listed.has(task.session) && !out.has(task.session);
81
+ const tasks = home ? [...home.rows, ...(all !== null && all !== void 0 ? all : []).filter(lost)] : [];
79
82
  return archive(tasks.filter(task => matches(query, task.title, task.detail)).map(row), since, new Set(archived));
80
83
  }
81
84
  ChatHomeUtil.rows = rows;
@@ -162,7 +162,7 @@ function ChatList({ sessions, saved, removed: removedFiles, archived: archivedSa
162
162
  ...(chat_list_util_1.ChatListUtil.isOpen(entry) ? [[entry.sessionId, entry]] : []),
163
163
  ])), [listed]);
164
164
  // A task whose conversation the list does not have is a row of its own; those that ended before the archive's bound are archived.
165
- const { listed: taskRows, archived: archivedTasks } = React.useMemo(() => chat_home_util_1.ChatHomeUtil.rows(homeTasks, allTasks, file => byFile.has(file), query, searching ? undefined : since, archived.map(chat_list_util_1.ChatListUtil.file)), [homeTasks, allTasks, byFile, query, searching, since, archived]);
165
+ const { listed: taskRows, archived: archivedTasks } = React.useMemo(() => chat_home_util_1.ChatHomeUtil.rows(homeTasks, allTasks, byFile, query, searching ? undefined : since, archived.map(chat_list_util_1.ChatListUtil.file), removedFiles), [homeTasks, allTasks, byFile, query, searching, since, archived, removedFiles]);
166
166
  const shownRemoved = React.useMemo(() => chat_list_util_1.ChatListUtil.filter(removed, query, t), [removed, query, t]);
167
167
  // Those pinned at the top, whatever their day or directory. Those that wait for the user to decide stay where they
168
168
  // are, marked by a blue ?: the double's home gathers them (docs/design/ta-decide.md).
@@ -309,6 +309,25 @@ export interface WebVoice {
309
309
  speak(text: string, onEnd?: () => void): void;
310
310
  /** Stops reading. */
311
311
  hush(): void;
312
+ /**
313
+ * Writes down what is said until stopped, as long as a meeting: with the service of Settings → Voice when one is
314
+ * chosen (ta serve hears, its key stays there), else with the recognizer of the device. `onText` gets the words
315
+ * of a stretch of speech as they grow, then once with `final` as it ended; `onEnd` follows once, stopped or
316
+ * failed (`error`). Undefined where the page cannot listen. Newer than some Ta apps: `voice.transcribe?.(…)`.
317
+ */
318
+ transcribe(listener: WebTranscribeListener): Promise<WebTranscribing | undefined>;
319
+ }
320
+ export interface WebTranscribeListener {
321
+ onText(text: string, final: boolean): void;
322
+ onEnd(error?: string): void;
323
+ /** Words to expect: names, terms of the meeting. */
324
+ hints?: readonly string[];
325
+ }
326
+ export interface WebTranscribing {
327
+ /** It hears through the service of Settings → Voice, not the recognizer of the device. */
328
+ readonly service: boolean;
329
+ /** Ends it: the words heard so far come as final, then `onEnd`. */
330
+ stop(): void;
312
331
  }
313
332
  export interface WebComposerProps {
314
333
  placeholder?: string;