@celljs/ta-web 4.22.0 → 4.24.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 (177) hide show
  1. package/esm/browser/assistant/assistant-chat-list.js +3 -1
  2. package/esm/browser/assistant/assistant-conversation.js +1 -1
  3. package/esm/browser/assistant/assistant-initiative.d.ts +5 -1
  4. package/esm/browser/assistant/assistant-initiative.js +11 -3
  5. package/esm/browser/assistant/call-keeper.d.ts +2 -1
  6. package/esm/browser/assistant/call-keeper.js +4 -2
  7. package/esm/browser/assistant/call-screen.d.ts +1 -1
  8. package/esm/browser/assistant/call-turn-end.d.ts +11 -2
  9. package/esm/browser/assistant/call-turn-end.js +21 -5
  10. package/esm/browser/assistant/read-aloud.d.ts +1 -1
  11. package/esm/browser/assistant/realtime-voice.d.ts +1 -1
  12. package/esm/browser/assistant/voice-call-bar.d.ts +5 -2
  13. package/esm/browser/assistant/voice-call-bar.js +12 -0
  14. package/esm/browser/assistant/voice-call-protocol.d.ts +78 -0
  15. package/esm/browser/assistant/voice-call-protocol.js +2 -0
  16. package/esm/browser/assistant/voice-call.d.ts +17 -65
  17. package/esm/browser/assistant/voice-call.js +45 -1
  18. package/esm/browser/assistant/voice-reopen.d.ts +1 -1
  19. package/esm/browser/components/account-menu.js +28 -7
  20. package/esm/browser/components/app-shell-state.js +2 -1
  21. package/esm/browser/components/app-view.js +15 -7
  22. package/esm/browser/components/chat-home-util.d.ts +7 -0
  23. package/esm/browser/components/chat-home-util.js +10 -0
  24. package/esm/browser/components/chat-home.d.ts +3 -1
  25. package/esm/browser/components/chat-home.js +3 -2
  26. package/esm/browser/components/chat-list-util.d.ts +15 -3
  27. package/esm/browser/components/chat-list-util.js +26 -4
  28. package/esm/browser/components/chat-list.js +4 -3
  29. package/esm/browser/components/chat-seen.d.ts +4 -3
  30. package/esm/browser/components/chat-seen.js +6 -5
  31. package/esm/browser/components/chats-dot.d.ts +30 -0
  32. package/esm/browser/components/chats-dot.js +32 -0
  33. package/esm/browser/components/cloud-sign-in-view.d.ts +1 -1
  34. package/esm/browser/components/earlier-messages.d.ts +4 -0
  35. package/esm/browser/components/earlier-messages.js +10 -2
  36. package/esm/browser/components/host-view.d.ts +1 -1
  37. package/esm/browser/components/message-footer.d.ts +0 -2
  38. package/esm/browser/components/message-footer.js +1 -8
  39. package/esm/browser/components/message-images.d.ts +22 -0
  40. package/esm/browser/components/message-images.js +90 -1
  41. package/esm/browser/components/message-steps.js +9 -0
  42. package/esm/browser/components/message-user.js +8 -1
  43. package/esm/browser/components/partner-row-util.d.ts +28 -0
  44. package/esm/browser/components/partner-row-util.js +45 -0
  45. package/esm/browser/components/partner-row.d.ts +4 -3
  46. package/esm/browser/components/partner-row.js +21 -9
  47. package/esm/browser/components/profile-view.d.ts +2 -2
  48. package/esm/browser/components/profile-view.js +6 -3
  49. package/esm/browser/components/settings-files.d.ts +7 -0
  50. package/esm/browser/components/settings-files.js +61 -0
  51. package/esm/browser/components/settings-more.js +2 -0
  52. package/esm/browser/components/tool-view.js +23 -7
  53. package/esm/browser/components/web-composer.d.ts +5 -2
  54. package/esm/browser/components/web-composer.js +10 -5
  55. package/esm/browser/extension/extension-view.js +2 -2
  56. package/esm/browser/extension/icons.js +4 -1
  57. package/esm/browser/extension/web-api-call.d.ts +45 -0
  58. package/esm/browser/extension/web-api-call.js +2 -0
  59. package/esm/browser/extension/web-api-components.d.ts +37 -2
  60. package/esm/browser/extension/web-api-contributions.d.ts +4 -32
  61. package/esm/browser/extension/web-api-partners.d.ts +27 -2
  62. package/esm/browser/extension/web-extension-api.d.ts +9 -12
  63. package/esm/browser/extension/web-extension-context.d.ts +2 -3
  64. package/esm/browser/extension/web-extension-context.js +5 -5
  65. package/esm/browser/extension/web-view-util.d.ts +5 -0
  66. package/esm/browser/extension/web-view-util.js +8 -0
  67. package/esm/browser/i18n/locales.d.ts +18 -1
  68. package/esm/browser/i18n/messages-ja.js +17 -0
  69. package/esm/browser/i18n/messages-zh-tw.js +17 -0
  70. package/esm/browser/i18n/messages.d.ts +17 -0
  71. package/esm/browser/i18n/messages.js +34 -0
  72. package/esm/browser/partners/partners-extension.js +17 -0
  73. package/esm/browser/partners/partners-util.d.ts +6 -0
  74. package/esm/browser/partners/partners-util.js +9 -0
  75. package/esm/browser/style/chat-list.d.ts +1 -1
  76. package/esm/browser/style/chat-list.js +3 -0
  77. package/esm/browser/style/conversation-column.d.ts +1 -1
  78. package/esm/browser/style/conversation-column.js +21 -0
  79. package/esm/browser/style/conversation.d.ts +1 -1
  80. package/esm/browser/style/conversation.js +3 -2
  81. package/esm/browser/style/pages.d.ts +1 -1
  82. package/esm/browser/style/pages.js +8 -0
  83. package/esm/browser/style/shell.d.ts +1 -1
  84. package/esm/browser/style/shell.js +1 -1
  85. package/esm/browser/util/image-shrink.d.ts +26 -0
  86. package/esm/browser/util/image-shrink.js +60 -0
  87. package/esm/browser/util/process.d.ts +10 -4
  88. package/esm/browser/util/process.js +45 -18
  89. package/lib/browser/assistant/assistant-chat-list.js +3 -1
  90. package/lib/browser/assistant/assistant-conversation.js +1 -1
  91. package/lib/browser/assistant/assistant-initiative.d.ts +5 -1
  92. package/lib/browser/assistant/assistant-initiative.js +11 -3
  93. package/lib/browser/assistant/call-keeper.d.ts +2 -1
  94. package/lib/browser/assistant/call-keeper.js +4 -2
  95. package/lib/browser/assistant/call-screen.d.ts +1 -1
  96. package/lib/browser/assistant/call-turn-end.d.ts +11 -2
  97. package/lib/browser/assistant/call-turn-end.js +22 -6
  98. package/lib/browser/assistant/read-aloud.d.ts +1 -1
  99. package/lib/browser/assistant/realtime-voice.d.ts +1 -1
  100. package/lib/browser/assistant/voice-call-bar.d.ts +5 -2
  101. package/lib/browser/assistant/voice-call-bar.js +12 -0
  102. package/lib/browser/assistant/voice-call-protocol.d.ts +79 -0
  103. package/lib/browser/assistant/voice-call-protocol.js +3 -0
  104. package/lib/browser/assistant/voice-call.d.ts +17 -65
  105. package/lib/browser/assistant/voice-call.js +45 -1
  106. package/lib/browser/assistant/voice-reopen.d.ts +1 -1
  107. package/lib/browser/components/account-menu.js +27 -6
  108. package/lib/browser/components/app-shell-state.js +2 -1
  109. package/lib/browser/components/app-view.js +15 -7
  110. package/lib/browser/components/chat-home-util.d.ts +7 -0
  111. package/lib/browser/components/chat-home-util.js +10 -0
  112. package/lib/browser/components/chat-home.d.ts +3 -1
  113. package/lib/browser/components/chat-home.js +3 -2
  114. package/lib/browser/components/chat-list-util.d.ts +15 -3
  115. package/lib/browser/components/chat-list-util.js +26 -4
  116. package/lib/browser/components/chat-list.js +4 -3
  117. package/lib/browser/components/chat-seen.d.ts +4 -3
  118. package/lib/browser/components/chat-seen.js +6 -5
  119. package/lib/browser/components/chats-dot.d.ts +31 -0
  120. package/lib/browser/components/chats-dot.js +68 -0
  121. package/lib/browser/components/cloud-sign-in-view.d.ts +1 -1
  122. package/lib/browser/components/earlier-messages.d.ts +4 -0
  123. package/lib/browser/components/earlier-messages.js +10 -2
  124. package/lib/browser/components/host-view.d.ts +1 -1
  125. package/lib/browser/components/message-footer.d.ts +0 -2
  126. package/lib/browser/components/message-footer.js +0 -8
  127. package/lib/browser/components/message-images.d.ts +22 -0
  128. package/lib/browser/components/message-images.js +92 -2
  129. package/lib/browser/components/message-steps.js +9 -0
  130. package/lib/browser/components/message-user.js +7 -0
  131. package/lib/browser/components/partner-row-util.d.ts +29 -0
  132. package/lib/browser/components/partner-row-util.js +48 -0
  133. package/lib/browser/components/partner-row.d.ts +4 -3
  134. package/lib/browser/components/partner-row.js +21 -9
  135. package/lib/browser/components/profile-view.d.ts +2 -2
  136. package/lib/browser/components/profile-view.js +6 -3
  137. package/lib/browser/components/settings-files.d.ts +8 -0
  138. package/lib/browser/components/settings-files.js +97 -0
  139. package/lib/browser/components/settings-more.js +2 -0
  140. package/lib/browser/components/tool-view.js +23 -7
  141. package/lib/browser/components/web-composer.d.ts +5 -2
  142. package/lib/browser/components/web-composer.js +10 -5
  143. package/lib/browser/extension/extension-view.js +2 -2
  144. package/lib/browser/extension/icons.js +3 -0
  145. package/lib/browser/extension/web-api-call.d.ts +46 -0
  146. package/lib/browser/extension/web-api-call.js +3 -0
  147. package/lib/browser/extension/web-api-components.d.ts +37 -2
  148. package/lib/browser/extension/web-api-contributions.d.ts +4 -32
  149. package/lib/browser/extension/web-api-partners.d.ts +27 -2
  150. package/lib/browser/extension/web-extension-api.d.ts +9 -12
  151. package/lib/browser/extension/web-extension-context.d.ts +2 -3
  152. package/lib/browser/extension/web-extension-context.js +5 -5
  153. package/lib/browser/extension/web-view-util.d.ts +5 -0
  154. package/lib/browser/extension/web-view-util.js +8 -0
  155. package/lib/browser/i18n/locales.d.ts +18 -1
  156. package/lib/browser/i18n/messages-ja.js +17 -0
  157. package/lib/browser/i18n/messages-zh-tw.js +17 -0
  158. package/lib/browser/i18n/messages.d.ts +17 -0
  159. package/lib/browser/i18n/messages.js +34 -0
  160. package/lib/browser/partners/partners-extension.js +17 -0
  161. package/lib/browser/partners/partners-util.d.ts +6 -0
  162. package/lib/browser/partners/partners-util.js +9 -0
  163. package/lib/browser/style/chat-list.d.ts +1 -1
  164. package/lib/browser/style/chat-list.js +3 -0
  165. package/lib/browser/style/conversation-column.d.ts +1 -1
  166. package/lib/browser/style/conversation-column.js +21 -0
  167. package/lib/browser/style/conversation.d.ts +1 -1
  168. package/lib/browser/style/conversation.js +3 -2
  169. package/lib/browser/style/pages.d.ts +1 -1
  170. package/lib/browser/style/pages.js +8 -0
  171. package/lib/browser/style/shell.d.ts +1 -1
  172. package/lib/browser/style/shell.js +1 -1
  173. package/lib/browser/util/image-shrink.d.ts +27 -0
  174. package/lib/browser/util/image-shrink.js +63 -0
  175. package/lib/browser/util/process.d.ts +10 -4
  176. package/lib/browser/util/process.js +45 -18
  177. package/package.json +7 -7
@@ -39,6 +39,7 @@ function useChatHome(onPicked) {
39
39
  const items = React.useSyncExternalStore(host.home.subscribe, host.home.items, host.home.items);
40
40
  const allPartners = React.useSyncExternalStore(host.partners.subscribe, host.partners.partners, host.partners.partners);
41
41
  const partners = React.useMemo(() => PartnersUtil.chats(allPartners), [allPartners]);
42
+ const partnerSessions = React.useMemo(() => PartnersUtil.sessions(allPartners), [allPartners]);
42
43
  // Its preview and whether it works, as one string: the same line stays the same value.
43
44
  const watch = React.useCallback((listener) => { var _a; var _b; return (_b = (_a = view === null || view === void 0 ? void 0 : view.subscribePreview) === null || _a === void 0 ? void 0 : _a.call(view, listener)) !== null && _b !== void 0 ? _b : (() => undefined); }, [view]);
44
45
  const read = () => {
@@ -71,6 +72,7 @@ function useChatHome(onPicked) {
71
72
  },
72
73
  items,
73
74
  partners,
75
+ partnerSessions,
74
76
  shownItem,
75
77
  openItem: entry => {
76
78
  latest.current();
@@ -85,7 +87,7 @@ function useChatHome(onPicked) {
85
87
  },
86
88
  remove: removed => void WebTaskUtil.remove(removed, notices, t),
87
89
  };
88
- }, [listed, line, name, shown, view, items, partners, shownItem, tasks, host, state, notices, t]);
90
+ }, [listed, line, name, shown, view, items, partners, partnerSessions, shownItem, tasks, host, state, notices, t]);
89
91
  }
90
92
  /** The list of chats with what the double knows of them: its tasks marked, a conversation to hand it; its home over them. */
91
93
  export function AssistantChatList(props) {
@@ -26,7 +26,7 @@ const NOTE_SETTLE_MS = 5000;
26
26
  export class AssistantConversation {
27
27
  constructor() {
28
28
  /** Whether it asks before starting a task, kept with the extension of the user's trust. */
29
- this.initiative = new AssistantInitiative(() => this.extensions, () => this.settings);
29
+ this.initiative = new AssistantInitiative(() => this.extensions, () => this.settings, () => this.persisted.load(SettingsUtil.STATE));
30
30
  this.current = { ready: false, tasks: [], asks: [] };
31
31
  this.taskStores = new Map();
32
32
  this.followAgain = false;
@@ -12,12 +12,16 @@ export declare const START_TASK: WebInitiativeKind;
12
12
  export declare class AssistantInitiative {
13
13
  protected readonly extensions: () => TaWebExtensions | undefined;
14
14
  protected readonly settings: () => TaSettings;
15
+ /** Until the settings the server keeps are in: the copy of this browser may be older than the user's choice. */
16
+ protected readonly loaded: () => Promise<unknown>;
15
17
  /** Settings.confirmTasks as the level last made it: a change to another value is the user's. */
16
18
  protected synced?: boolean;
17
19
  protected current?: WebInitiative;
18
20
  protected unwatch?: () => void;
19
21
  protected unwatchProvider?: () => void;
20
- constructor(extensions: () => TaWebExtensions | undefined, settings: () => TaSettings);
22
+ constructor(extensions: () => TaWebExtensions | undefined, settings: () => TaSettings,
23
+ /** Until the settings the server keeps are in: the copy of this browser may be older than the user's choice. */
24
+ loaded?: () => Promise<unknown>);
21
25
  start(): void;
22
26
  /** The settings changed: a new value of Settings.confirmTasks not of the level is the user's, kept as their choice. */
23
27
  settingsChanged(settings: Settings): void;
@@ -12,9 +12,12 @@ export const START_TASK = {
12
12
  * one, Settings.confirmTasks alone, as before.
13
13
  */
14
14
  export class AssistantInitiative {
15
- constructor(extensions, settings) {
15
+ constructor(extensions, settings,
16
+ /** Until the settings the server keeps are in: the copy of this browser may be older than the user's choice. */
17
+ loaded = async () => undefined) {
16
18
  this.extensions = extensions;
17
19
  this.settings = settings;
20
+ this.loaded = loaded;
18
21
  }
19
22
  start() {
20
23
  const extensions = this.extensions();
@@ -55,10 +58,15 @@ export class AssistantInitiative {
55
58
  if (!provider) {
56
59
  return;
57
60
  }
58
- const asking = (await provider.level(START_TASK).catch(() => undefined)) !== 'act';
59
- if (provider !== this.current) {
61
+ if (this.synced === undefined) {
62
+ await this.loaded().catch(() => undefined);
63
+ }
64
+ const level = await provider.level(START_TASK).catch(() => undefined);
65
+ // Not known (the computer restarting, the connection gone): nothing to go by, the switch stays as it is.
66
+ if (provider !== this.current || level === undefined) {
60
67
  return;
61
68
  }
69
+ const asking = level !== 'act';
62
70
  const settings = this.settings();
63
71
  const now = settings.state.settings.confirmTasks;
64
72
  // The first time: the user turned asking on before a level was kept, which is their choice.
@@ -1,6 +1,7 @@
1
1
  import { ScreenAwake } from '../device/screen-awake.js';
2
2
  import { type StateSpec, TaState } from '../state/state-protocol.js';
3
- import type { CallPhase, VoiceCall } from './voice-call.js';
3
+ import type { VoiceCall } from './voice-call.js';
4
+ import type { CallPhase } from './voice-call-protocol.js';
4
5
  export declare const TaCallKeeper: unique symbol;
5
6
  /** A call and what its hook gives it, kept as they are while no view shows its conversation. */
6
7
  export interface HeldCall {
@@ -259,8 +259,10 @@ let TaCallKeeperImpl = class TaCallKeeperImpl {
259
259
  }
260
260
  drop() {
261
261
  var _a, _b, _c, _d;
262
- if (this.current && ((_b = (_a = this.persisted) === null || _a === void 0 ? void 0 : _a.get(CallKeeperUtil.SHARED)) === null || _b === void 0 ? void 0 : _b.page) === this.page) {
263
- this.persisted.set(CallKeeperUtil.SHARED, undefined);
262
+ const shared = (_a = this.persisted) === null || _a === void 0 ? void 0 : _a.get(CallKeeperUtil.SHARED);
263
+ if (this.current && (shared === null || shared === void 0 ? void 0 : shared.page) === this.page && !shared.end) {
264
+ // Said ended, not cleared: a page that still has it would write a value gone from the server back (TaState).
265
+ (_b = this.persisted) === null || _b === void 0 ? void 0 : _b.set(CallKeeperUtil.SHARED, { ...shared, at: Date.now(), end: true });
264
266
  }
265
267
  (_c = this.offState) === null || _c === void 0 ? void 0 : _c.call(this);
266
268
  (_d = this.offShown) === null || _d === void 0 ? void 0 : _d.call(this);
@@ -1,6 +1,6 @@
1
1
  import type { Translate } from '../i18n/use-t.js';
2
2
  import { type ScreenPartSpec, type TaScreen } from '../screen/screen-protocol.js';
3
- import type { CallPhase } from './voice-call.js';
3
+ import type { CallPhase } from './voice-call-protocol.js';
4
4
  /**
5
5
  * The call going on as Ta's agents read and work it (docs/design/ta-app-use.md 6.1): a part of the screen over every
6
6
  * page (ScreenPartSpec.floats), what the call is at and with which conversation, its buttons as they are (the bar over
@@ -18,6 +18,11 @@ export declare const END_MS = 1300;
18
18
  * a hesitation is dropped and a backchannel ("嗯", "好好", an answer maybe) goes as said.
19
19
  */
20
20
  export declare const FILLER_MS = 3000;
21
+ /**
22
+ * The words heard stay the same this long, and may be all the user says (not sounds alone, nor a word that leads on): the
23
+ * answer to them is begun (CallPartner.draft), said only once they are done (docs/design/ta-call.md 10).
24
+ */
25
+ export declare const DRAFT_MS = 400;
21
26
  /** At most this long a turn, from the first words: talk around the user that keeps the words coming ends there too. */
22
27
  export declare const TURN_MS = 15000;
23
28
  /** How long a call waits for the user, as CallOptions says. */
@@ -28,20 +33,24 @@ export interface CallTurnTimes {
28
33
  fillerMs?: number;
29
34
  /** How long the user may speak in one turn; default TURN_MS. */
30
35
  turnMs?: number;
36
+ /** How long the words heard stay the same before the answer to them is begun; default DRAFT_MS. */
37
+ draftMs?: number;
31
38
  }
32
39
  /**
33
40
  * When the user is done with their turn in a call, by the words heard as they come (TurnEnd): once they stayed the same
34
41
  * a while (END_MS, sooner after a sentence, later while they hesitate, FILLER_MS for sounds alone), and at the latest
35
- * TURN_MS from the first words. It calls `done` then.
42
+ * TURN_MS from the first words. It calls `done` then; and `suspect` sooner (DRAFT_MS), where the words may end the turn.
36
43
  */
37
44
  export declare class CallTurnEnd {
38
45
  protected readonly times: CallTurnTimes;
39
46
  protected readonly done: () => void;
47
+ protected readonly suspect?: ((text: string) => void) | undefined;
40
48
  protected endTimer?: ReturnType<typeof setTimeout>;
41
49
  protected turnTimer?: ReturnType<typeof setTimeout>;
50
+ protected draftTimer?: ReturnType<typeof setTimeout>;
42
51
  /** When the words heard last changed: sounds alone wait FILLER_MS from it, over listens. */
43
52
  protected wordsAt: number;
44
- constructor(times: CallTurnTimes, done: () => void);
53
+ constructor(times: CallTurnTimes, done: () => void, suspect?: ((text: string) => void) | undefined);
45
54
  /** The words heard are `text` now. */
46
55
  heard(text: string): void;
47
56
  /** A listen goes on from sounds alone the one before ended on: done once they waited FILLER_MS, unless words come. */
@@ -19,31 +19,46 @@ export const END_MS = 1300;
19
19
  * a hesitation is dropped and a backchannel ("嗯", "好好", an answer maybe) goes as said.
20
20
  */
21
21
  export const FILLER_MS = 3000;
22
+ /**
23
+ * The words heard stay the same this long, and may be all the user says (not sounds alone, nor a word that leads on): the
24
+ * answer to them is begun (CallPartner.draft), said only once they are done (docs/design/ta-call.md 10).
25
+ */
26
+ export const DRAFT_MS = 400;
22
27
  /** At most this long a turn, from the first words: talk around the user that keeps the words coming ends there too. */
23
28
  export const TURN_MS = 15000;
24
29
  /**
25
30
  * When the user is done with their turn in a call, by the words heard as they come (TurnEnd): once they stayed the same
26
31
  * a while (END_MS, sooner after a sentence, later while they hesitate, FILLER_MS for sounds alone), and at the latest
27
- * TURN_MS from the first words. It calls `done` then.
32
+ * TURN_MS from the first words. It calls `done` then; and `suspect` sooner (DRAFT_MS), where the words may end the turn.
28
33
  */
29
34
  export class CallTurnEnd {
30
- constructor(times, done) {
35
+ constructor(times, done, suspect) {
31
36
  this.times = times;
32
37
  this.done = done;
38
+ this.suspect = suspect;
33
39
  /** When the words heard last changed: sounds alone wait FILLER_MS from it, over listens. */
34
40
  this.wordsAt = 0;
35
41
  }
36
42
  /** The words heard are `text` now. */
37
43
  heard(text) {
38
- var _a, _b;
44
+ var _a, _b, _c;
39
45
  this.wordsAt = Date.now();
40
46
  clearTimeout(this.endTimer);
41
- this.endTimer = setTimeout(this.done, this.waitMs(text));
47
+ const wait = this.waitMs(text);
48
+ this.endTimer = setTimeout(this.done, wait);
42
49
  (_a = this.turnTimer) !== null && _a !== void 0 ? _a : (this.turnTimer = setTimeout(this.done, (_b = this.times.turnMs) !== null && _b !== void 0 ? _b : TURN_MS));
50
+ clearTimeout(this.draftTimer);
51
+ this.draftTimer = undefined;
52
+ const draftMs = (_c = this.times.draftMs) !== null && _c !== void 0 ? _c : DRAFT_MS;
53
+ const suspect = this.suspect;
54
+ if (suspect && wait > draftMs && TurnEnd.words(text) >= 2 && !TurnEnd.sounds(text) && !TurnEnd.hesitates(text)) {
55
+ this.draftTimer = setTimeout(() => suspect(text), draftMs);
56
+ }
43
57
  }
44
58
  /** A listen goes on from sounds alone the one before ended on: done once they waited FILLER_MS, unless words come. */
45
59
  hold() {
46
60
  clearTimeout(this.endTimer);
61
+ clearTimeout(this.draftTimer);
47
62
  this.endTimer = setTimeout(this.done, Math.max(0, this.fillerMs - (Date.now() - this.wordsAt)));
48
63
  }
49
64
  /** `said` is sounds alone that did not wait FILLER_MS yet: they wait on for words. */
@@ -53,7 +68,8 @@ export class CallTurnEnd {
53
68
  stop() {
54
69
  clearTimeout(this.endTimer);
55
70
  clearTimeout(this.turnTimer);
56
- this.endTimer = this.turnTimer = undefined;
71
+ clearTimeout(this.draftTimer);
72
+ this.endTimer = this.turnTimer = this.draftTimer = undefined;
57
73
  }
58
74
  get fillerMs() {
59
75
  var _a;
@@ -1,5 +1,5 @@
1
1
  import { RealtimeVoice, type RealtimeVoiceHost } from './realtime-voice.js';
2
- import type { CallVoice } from './voice-call.js';
2
+ import type { CallVoice } from './voice-call-protocol.js';
3
3
  /** How long a voice service opened to read stays open after it read, ready for the next reply. */
4
4
  export declare const READ_IDLE_MS = 60000;
5
5
  interface OpenService {
@@ -1,6 +1,6 @@
1
1
  import { TaBargeIn, type TaVoiceEvent, type TaVoiceServer, type TaVoiceSession } from '@celljs/ta-protocol';
2
2
  import { Voice } from '../util/voice.js';
3
- import type { CallVoice } from './voice-call.js';
3
+ import type { CallVoice } from './voice-call-protocol.js';
4
4
  /** What a voice of a service uses of the page's connection. */
5
5
  export interface RealtimeVoiceHost {
6
6
  readonly voice: TaVoiceServer;
@@ -1,9 +1,10 @@
1
1
  import * as React from 'react';
2
2
  import type { ComposerAction } from '../components/composer-box-protocol.js';
3
3
  import type { TalkCall } from '../components/voice-talk.js';
4
- import type { WebCallPartner, WebCallTarget } from '../extension/web-api-contributions.js';
4
+ import type { WebCallPartner, WebCallSession, WebCallTarget } from '../extension/web-api-call.js';
5
5
  import { type Translate } from '../i18n/use-t.js';
6
- import { type CallEnd, type CallOptions, type CallPartner, type CallState, VoiceCall } from './voice-call.js';
6
+ import { VoiceCall } from './voice-call.js';
7
+ import type { CallDraft, CallEnd, CallOptions, CallPartner, CallState } from './voice-call-protocol.js';
7
8
  /** What a notice says of a call that ended by itself. */
8
9
  export declare function callEndedNotice(t: Translate, reason: CallEnd, detail?: string): string;
9
10
  /**
@@ -28,6 +29,8 @@ export declare namespace CallPartnerUtil {
28
29
  * the ear); undefined when it leaves the call to the conversation.
29
30
  */
30
31
  function open(partner: WebCallPartner, target: WebCallTarget): Promise<CallPartner | undefined>;
32
+ /** An answer begun by the partner before the user was known to be done, its reply said whole. */
33
+ function draft(session: WebCallSession, text: string): CallDraft;
31
34
  /** After a failure to ask for what the partner says by itself, before it asks again. */
32
35
  const RETRY_MS = 3000;
33
36
  /** Asks for what the partner says by itself again and again, each as it comes, until the call is over. */
@@ -138,6 +138,7 @@ export var CallPartnerUtil;
138
138
  const reply = await session.say(text, options);
139
139
  return reply ? SpokenReply.whole(reply) : undefined;
140
140
  },
141
+ ...(session.draft ? { draft: (text) => CallPartnerUtil.draft(session, text) } : {}),
141
142
  news: listener => {
142
143
  if (session.next) {
143
144
  void CallPartnerUtil.follow(session.next.bind(session), () => closed, text => listener(SpokenReply.whole(text)));
@@ -151,6 +152,17 @@ export var CallPartnerUtil;
151
152
  });
152
153
  }
153
154
  CallPartnerUtil.open = open;
155
+ /** An answer begun by the partner before the user was known to be done, its reply said whole. */
156
+ function draft(session, text) {
157
+ var _a;
158
+ const begun = (_a = session.draft) === null || _a === void 0 ? void 0 : _a.call(session, text);
159
+ return {
160
+ reply: begun ? begun.reply.then(reply => (reply ? SpokenReply.whole(reply) : undefined)) : Promise.reject(new Error('No drafts.')),
161
+ keep: () => begun === null || begun === void 0 ? void 0 : begun.keep(),
162
+ drop: () => begun === null || begun === void 0 ? void 0 : begun.drop(),
163
+ };
164
+ }
165
+ CallPartnerUtil.draft = draft;
154
166
  /** After a failure to ask for what the partner says by itself, before it asks again. */
155
167
  CallPartnerUtil.RETRY_MS = 3000;
156
168
  /** Asks for what the partner says by itself again and again, each as it comes, until the call is over. */
@@ -0,0 +1,78 @@
1
+ import type { Voice } from '../util/voice.js';
2
+ import type { CallTurnTimes } from './call-turn-end.js';
3
+ /** Where a call is: Ta listens to the user, works on what they said, or says its answer. */
4
+ export type CallPhase = 'connecting' | 'listening' | 'thinking' | 'speaking';
5
+ export interface CallState {
6
+ active: boolean;
7
+ phase: CallPhase;
8
+ /** What the user has said so far, while Ta listens. */
9
+ heard: string;
10
+ /** What the user said last, kept while Ta works on it and answers, until they say more: the captions. */
11
+ said?: string;
12
+ /** The answer being read, by sentences, and the one being read now: the captions. Kept after, until the user says more. */
13
+ reading?: {
14
+ pieces: string[];
15
+ at: number;
16
+ };
17
+ /** The page is hidden (another app in front, the screen locked): Ta neither listens nor speaks until it shows again. */
18
+ paused?: boolean;
19
+ /** A partner answers in this call (CallPartner), and tells the news of the work itself. */
20
+ partnered?: boolean;
21
+ /** Its voice hears the user cut in while Ta speaks: no need to tap. */
22
+ bargeIn?: boolean;
23
+ }
24
+ /** What a call uses of the page's voice: Voice by default, a service of voices.json (RealtimeVoice), a fake in tests. */
25
+ export interface CallVoice {
26
+ listen: typeof Voice.listen;
27
+ speak(text: string, language: string, onEnd: () => void, voice?: string, onPiece?: (pieces: string[], index: number) => void): void;
28
+ hush(): void;
29
+ /** It hears the user begin to speak even while Ta reads: the call stops reading and listens (barge-in). */
30
+ onSpeech?(listener: () => void): () => void;
31
+ /** false: the user chose to stop Ta with a tap only, not by speaking (TaBargeIn.tap). */
32
+ readonly cutsIn?: boolean;
33
+ /** The call ended: it lets go of what it holds (the microphone, the service). */
34
+ stop?(): void;
35
+ }
36
+ /**
37
+ * Who answers in a call in place of the conversation itself: a front that only talks, handing the work to the
38
+ * conversation (docs/design/ta-call.md), opened as the call starts and closed as it ends.
39
+ */
40
+ export interface CallPartner {
41
+ /** What the user said; the reply, as said aloud. `sent`: it went to the conversation already (let go over 通话). */
42
+ say(text: string, options?: {
43
+ sent?: boolean;
44
+ }): Promise<string | undefined>;
45
+ /** What it says by itself (news of the work), told as it comes, until it closes: the call announces it. */
46
+ news?(listener: (text: string) => void): void;
47
+ /**
48
+ * Answers what the user said so far, as they paused where they may be done (WebCallSession.draft): said only once
49
+ * kept, as they were done with these words; dropped as they say more.
50
+ */
51
+ draft?(text: string): CallDraft;
52
+ /** Whether it ended the call (WebCallSession.ending): Ta hangs up once its reply is said. */
53
+ ending?(): boolean;
54
+ close(): void;
55
+ }
56
+ /** An answer begun before the user was known to be done (CallPartner.draft). */
57
+ export interface CallDraft {
58
+ /** The reply, as said aloud; undefined once dropped. */
59
+ reply: Promise<string | undefined>;
60
+ keep(): void;
61
+ drop(): void;
62
+ }
63
+ /** Why a call ended by itself. */
64
+ export type CallEnd = 'silent' | 'denied' | 'unavailable' | 'failed';
65
+ export interface CallOptions extends CallTurnTimes {
66
+ language(): string;
67
+ voice(): string | undefined;
68
+ /** Sends what the user said to the conversation. */
69
+ send(text: string): Promise<unknown>;
70
+ /** The call ended by itself: why, for a notice; `detail` what the voice service said. */
71
+ ended?(reason: CallEnd, detail?: string): void;
72
+ /** The voice of a service the call opens as it starts; undefined for that of the device. */
73
+ openVoice?(): Promise<CallVoice | undefined> | undefined;
74
+ /** Who answers in its place, opened as the call starts; undefined (or failing) for the conversation itself. */
75
+ openPartner?(): Promise<CallPartner | undefined> | undefined;
76
+ /** How long nobody may speak before the call ends by itself; default SILENT_MS. */
77
+ silentMs?: number;
78
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=voice-call-protocol.js.map
@@ -1,70 +1,7 @@
1
1
  import { Voice } from '../util/voice.js';
2
- import { CallTurnEnd, type CallTurnTimes } from './call-turn-end.js';
2
+ import { CallTurnEnd } from './call-turn-end.js';
3
+ import type { CallDraft, CallEnd, CallOptions, CallPartner, CallState, CallVoice } from './voice-call-protocol.js';
3
4
  import { VoiceReopen } from './voice-reopen.js';
4
- /** Where a call is: Ta listens to the user, works on what they said, or says its answer. */
5
- export type CallPhase = 'connecting' | 'listening' | 'thinking' | 'speaking';
6
- export interface CallState {
7
- active: boolean;
8
- phase: CallPhase;
9
- /** What the user has said so far, while Ta listens. */
10
- heard: string;
11
- /** What the user said last, kept while Ta works on it and answers, until they say more: the captions. */
12
- said?: string;
13
- /** The answer being read, by sentences, and the one being read now: the captions. Kept after, until the user says more. */
14
- reading?: {
15
- pieces: string[];
16
- at: number;
17
- };
18
- /** The page is hidden (another app in front, the screen locked): Ta neither listens nor speaks until it shows again. */
19
- paused?: boolean;
20
- /** A partner answers in this call (CallPartner), and tells the news of the work itself. */
21
- partnered?: boolean;
22
- /** Its voice hears the user cut in while Ta speaks: no need to tap. */
23
- bargeIn?: boolean;
24
- }
25
- /** What a call uses of the page's voice: Voice by default, a service of voices.json (RealtimeVoice), a fake in tests. */
26
- export interface CallVoice {
27
- listen: typeof Voice.listen;
28
- speak(text: string, language: string, onEnd: () => void, voice?: string, onPiece?: (pieces: string[], index: number) => void): void;
29
- hush(): void;
30
- /** It hears the user begin to speak even while Ta reads: the call stops reading and listens (barge-in). */
31
- onSpeech?(listener: () => void): () => void;
32
- /** false: the user chose to stop Ta with a tap only, not by speaking (TaBargeIn.tap). */
33
- readonly cutsIn?: boolean;
34
- /** The call ended: it lets go of what it holds (the microphone, the service). */
35
- stop?(): void;
36
- }
37
- /**
38
- * Who answers in a call in place of the conversation itself: a front that only talks, handing the work to the
39
- * conversation (docs/design/ta-call.md), opened as the call starts and closed as it ends.
40
- */
41
- export interface CallPartner {
42
- /** What the user said; the reply, as said aloud. `sent`: it went to the conversation already (let go over 通话). */
43
- say(text: string, options?: {
44
- sent?: boolean;
45
- }): Promise<string | undefined>;
46
- /** What it says by itself (news of the work), told as it comes, until it closes: the call announces it. */
47
- news?(listener: (text: string) => void): void;
48
- /** Whether it ended the call (WebCallSession.ending): Ta hangs up once its reply is said. */
49
- ending?(): boolean;
50
- close(): void;
51
- }
52
- /** Why a call ended by itself. */
53
- export type CallEnd = 'silent' | 'denied' | 'unavailable' | 'failed';
54
- export interface CallOptions extends CallTurnTimes {
55
- language(): string;
56
- voice(): string | undefined;
57
- /** Sends what the user said to the conversation. */
58
- send(text: string): Promise<unknown>;
59
- /** The call ended by itself: why, for a notice; `detail` what the voice service said. */
60
- ended?(reason: CallEnd, detail?: string): void;
61
- /** The voice of a service the call opens as it starts; undefined for that of the device. */
62
- openVoice?(): Promise<CallVoice | undefined> | undefined;
63
- /** Who answers in its place, opened as the call starts; undefined (or failing) for the conversation itself. */
64
- openPartner?(): Promise<CallPartner | undefined> | undefined;
65
- /** How long nobody may speak before the call ends by itself; default SILENT_MS. */
66
- silentMs?: number;
67
- }
68
5
  /**
69
6
  * A call with a conversation (the double's, or any other), by the voice of the page: Ta listens until the user pauses, sends what they said, reads
70
7
  * its answer out, then listens again, until the user hangs up or says nothing for a while. With the voice of the device
@@ -99,6 +36,13 @@ export declare class VoiceCall {
99
36
  protected partner?: CallPartner;
100
37
  /** Its voice service opening again (revoice). */
101
38
  protected reopening?: VoiceReopen;
39
+ /** The answer begun on what the user said so far (CallPartner.draft), and those words. */
40
+ protected drafted?: {
41
+ text: string;
42
+ draft: CallDraft;
43
+ };
44
+ /** A partner whose draft failed (an older Ta): it answers once the user is done only. */
45
+ protected draftless?: CallPartner;
102
46
  constructor(options: CallOptions, device?: CallVoice);
103
47
  subscribe(listener: () => void): () => void;
104
48
  /**
@@ -181,6 +125,14 @@ export declare class VoiceCall {
181
125
  protected heard(said: string, error: string | undefined, waited?: boolean): void;
182
126
  /** What the user said goes to the partner, or to the conversation. */
183
127
  protected take(said: string): void;
128
+ /**
129
+ * The words heard stayed the same a little, and may be all the user says: the partner begins its answer, said only
130
+ * should they be done with these words (take), dropped as they say more (docs/design/ta-call.md 10).
131
+ */
132
+ protected suspect(text: string): void;
133
+ /** The user was done with the words of the draft: its answer is the reply; failing, the partner is asked as usual. */
134
+ protected kept(draft: CallDraft, said: string): void;
135
+ protected dropDraft(): void;
184
136
  /** The voice and the partner the call opens as it starts; undefined when it opens neither. A partner that fails is none. */
185
137
  protected open(direct: boolean): Promise<[CallVoice | undefined, CallPartner | undefined]> | undefined;
186
138
  /** The partner answers what the user said; its reply is read as a turn's is. */
@@ -27,7 +27,7 @@ export class VoiceCall {
27
27
  /** What waits to be said that the user did not ask for (a dialog, a task that ended), in order. */
28
28
  this.announcements = [];
29
29
  this.voice = device;
30
- this.turnEnd = new CallTurnEnd(options, () => this.quiet());
30
+ this.turnEnd = new CallTurnEnd(options, () => this.quiet(), text => this.suspect(text));
31
31
  }
32
32
  subscribe(listener) {
33
33
  this.listeners.add(listener);
@@ -142,6 +142,7 @@ export class VoiceCall {
142
142
  if (!this.state.active) {
143
143
  return;
144
144
  }
145
+ this.dropDraft();
145
146
  (_a = this.partner) === null || _a === void 0 ? void 0 : _a.close();
146
147
  this.partner = undefined;
147
148
  this.calls++;
@@ -189,6 +190,7 @@ export class VoiceCall {
189
190
  return;
190
191
  }
191
192
  this.stopListening();
193
+ this.dropDraft();
192
194
  if (this.state.phase === 'speaking') {
193
195
  this.voice.hush();
194
196
  this.pending = this.speaking;
@@ -291,6 +293,7 @@ export class VoiceCall {
291
293
  */
292
294
  listen(announce = true, held) {
293
295
  this.stopListening();
296
+ this.dropDraft();
294
297
  if (this.state.paused) {
295
298
  return;
296
299
  }
@@ -310,6 +313,10 @@ export class VoiceCall {
310
313
  // The user says more: the captions are of what they say now, the last exchange gone.
311
314
  this.set(text.trim() ? { heard: text, said: undefined, reading: undefined } : { heard: text });
312
315
  if (more && text.trim()) {
316
+ // They say more than the answer begun was to: it goes.
317
+ if (this.drafted && this.drafted.text !== text.trim()) {
318
+ this.dropDraft();
319
+ }
313
320
  this.turnEnd.heard(text);
314
321
  }
315
322
  }
@@ -399,6 +406,13 @@ export class VoiceCall {
399
406
  this.silent = 0;
400
407
  this.spoke = Date.now();
401
408
  this.set({ phase: 'thinking', heard: said, said, reading: undefined });
409
+ const drafted = this.drafted;
410
+ this.drafted = undefined;
411
+ if (this.partner && (drafted === null || drafted === void 0 ? void 0 : drafted.text) === said) {
412
+ this.kept(drafted.draft, said);
413
+ return;
414
+ }
415
+ drafted === null || drafted === void 0 ? void 0 : drafted.draft.drop();
402
416
  if (this.partner) {
403
417
  this.ask(said);
404
418
  }
@@ -406,6 +420,36 @@ export class VoiceCall {
406
420
  this.options.send(said).catch(() => this.state.active && this.unsent());
407
421
  }
408
422
  }
423
+ /**
424
+ * The words heard stayed the same a little, and may be all the user says: the partner begins its answer, said only
425
+ * should they be done with these words (take), dropped as they say more (docs/design/ta-call.md 10).
426
+ */
427
+ suspect(text) {
428
+ var _a;
429
+ const said = text.trim();
430
+ const partner = this.partner;
431
+ if (!(partner === null || partner === void 0 ? void 0 : partner.draft) || this.draftless === partner || this.listened() !== said || ((_a = this.drafted) === null || _a === void 0 ? void 0 : _a.text) === said) {
432
+ return;
433
+ }
434
+ this.dropDraft();
435
+ const draft = partner.draft(said);
436
+ draft.reply.catch(() => {
437
+ this.draftless = partner;
438
+ });
439
+ this.drafted = { text: said, draft };
440
+ }
441
+ /** The user was done with the words of the draft: its answer is the reply; failing, the partner is asked as usual. */
442
+ kept(draft, said) {
443
+ const call = this.calls;
444
+ const partner = this.partner;
445
+ draft.keep();
446
+ draft.reply.then(reply => call === this.calls && this.turnEnded(reply), () => call === this.calls && this.state.active && this.partner === partner && this.ask(said));
447
+ }
448
+ dropDraft() {
449
+ const drafted = this.drafted;
450
+ this.drafted = undefined;
451
+ drafted === null || drafted === void 0 ? void 0 : drafted.draft.drop();
452
+ }
409
453
  /** The voice and the partner the call opens as it starts; undefined when it opens neither. A partner that fails is none. */
410
454
  open(direct) {
411
455
  var _a, _b, _c, _d, _e;
@@ -1,4 +1,4 @@
1
- import type { CallVoice } from './voice-call.js';
1
+ import type { CallVoice } from './voice-call-protocol.js';
2
2
  /**
3
3
  * Opens the voice service of a call again once it went (ta serve restarted, the connection dropped): tries until it
4
4
  * opens or MS passed, waiting RETRY_MS between tries; a voice that opens too late is let go.
@@ -4,7 +4,7 @@ import * as React from 'react';
4
4
  import { useAccountInfo, useAccountSide } from '../account/account-side.js';
5
5
  import { DeviceAccount } from '../account/device-account.js';
6
6
  import { useDevice } from '../device/device.js';
7
- import { useNotices, usePwa, useSettings, useWorkbench } from '../hooks.js';
7
+ import { useNotices, usePersisted, usePwa, useSettings, useWorkbench } from '../hooks.js';
8
8
  import { HostUtil } from '../hosts.js';
9
9
  import { useT } from '../i18n/use-t.js';
10
10
  import { WorkbenchUtil } from '../workbench-util.js';
@@ -137,25 +137,46 @@ export function AccountFigure({ size, className }) {
137
137
  return (React.createElement("span", { className: className },
138
138
  React.createElement(Face, { double: true, size: size })));
139
139
  }
140
+ /**
141
+ * The name and account last shown for each computer, so that the page opens with them rather than with the user of
142
+ * the computer and no account until they are read again.
143
+ */
144
+ const SHOWN = {
145
+ key: 'account.shown',
146
+ tier: 'device',
147
+ initial: {},
148
+ parse: value => (value && typeof value === 'object' && !Array.isArray(value) ? value : undefined),
149
+ };
140
150
  /** Who the user is (their name, their account), the machine in use (as named on this device), and whether the page is connected to it. */
141
151
  export function useAccount() {
142
- var _a, _b, _c;
152
+ var _a;
153
+ var _b, _c;
143
154
  const t = useT();
144
- const identity = useIdentity();
145
- const account = useAccountLine();
155
+ const read = (_a = useIdentity()) === null || _a === void 0 ? void 0 : _a.name;
156
+ const line = useAccountLine();
146
157
  const [{ status, server, offlineShown, hosts, host }] = useWorkbench();
158
+ const [shown, keepShown] = usePersisted(SHOWN);
159
+ const key = host !== null && host !== void 0 ? host : '';
160
+ const last = shown[key];
161
+ const name = read !== null && read !== void 0 ? read : last === null || last === void 0 ? void 0 : last.name;
162
+ const account = line === undefined ? last === null || last === void 0 ? void 0 : last.account : line;
163
+ React.useEffect(() => {
164
+ if ((read !== undefined || line !== undefined) && (name !== (last === null || last === void 0 ? void 0 : last.name) || account !== (last === null || last === void 0 ? void 0 : last.account))) {
165
+ keepShown(previous => ({ ...previous, [key]: { name, account } }));
166
+ }
167
+ }, [read, line, name, account, last, key, keepShown]);
147
168
  const online = status === 'online';
148
169
  const state = online ? t('ta.online') : t('ta.reconnecting');
149
170
  const inUse = hosts.find(one => one.id === host);
150
- const machine = ((_a = inUse === null || inUse === void 0 ? void 0 : inUse.name) !== null && _a !== void 0 ? _a : server === null || server === void 0 ? void 0 : server.host) || undefined;
171
+ const machine = ((_b = inUse === null || inUse === void 0 ? void 0 : inUse.name) !== null && _b !== void 0 ? _b : server === null || server === void 0 ? void 0 : server.host) || undefined;
151
172
  return {
152
173
  server,
153
174
  machine,
154
175
  online,
155
176
  offlineShown,
156
177
  state,
157
- name: (_c = (_b = identity === null || identity === void 0 ? void 0 : identity.name) !== null && _b !== void 0 ? _b : server === null || server === void 0 ? void 0 : server.user) !== null && _c !== void 0 ? _c : t('ta.account'),
158
- account,
178
+ name: (_c = name !== null && name !== void 0 ? name : server === null || server === void 0 ? void 0 : server.user) !== null && _c !== void 0 ? _c : t('ta.account'),
179
+ account: account !== null && account !== void 0 ? account : undefined,
159
180
  service: server && online ? `${state} · v${server.version}` : state,
160
181
  };
161
182
  }