@celljs/ta-web 4.21.0 → 4.23.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 (191) hide show
  1. package/esm/browser/assistant/assistant-chat-list.js +5 -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/chat-home-util.d.ts +13 -2
  21. package/esm/browser/components/chat-home-util.js +29 -0
  22. package/esm/browser/components/chat-home.d.ts +18 -4
  23. package/esm/browser/components/chat-home.js +11 -3
  24. package/esm/browser/components/chat-list.js +4 -2
  25. package/esm/browser/components/cloud-sign-in-view.d.ts +1 -1
  26. package/esm/browser/components/earlier-messages.d.ts +4 -0
  27. package/esm/browser/components/earlier-messages.js +10 -2
  28. package/esm/browser/components/host-view.d.ts +1 -1
  29. package/esm/browser/components/message-footer.d.ts +0 -2
  30. package/esm/browser/components/message-footer.js +1 -8
  31. package/esm/browser/components/message-images.d.ts +22 -0
  32. package/esm/browser/components/message-images.js +90 -1
  33. package/esm/browser/components/message-steps.js +9 -0
  34. package/esm/browser/components/message-user.js +8 -1
  35. package/esm/browser/components/partner-row-util.d.ts +28 -0
  36. package/esm/browser/components/partner-row-util.js +45 -0
  37. package/esm/browser/components/partner-row.d.ts +18 -0
  38. package/esm/browser/components/partner-row.js +60 -0
  39. package/esm/browser/components/profile-view.d.ts +2 -2
  40. package/esm/browser/components/profile-view.js +6 -3
  41. package/esm/browser/components/web-composer.d.ts +5 -2
  42. package/esm/browser/components/web-composer.js +10 -5
  43. package/esm/browser/extension/extension-view.js +2 -2
  44. package/esm/browser/extension/icons.js +4 -1
  45. package/esm/browser/extension/web-api-call.d.ts +45 -0
  46. package/esm/browser/extension/web-api-call.js +2 -0
  47. package/esm/browser/extension/web-api-components.d.ts +37 -2
  48. package/esm/browser/extension/web-api-contributions.d.ts +2 -31
  49. package/esm/browser/extension/web-api-home.d.ts +1 -0
  50. package/esm/browser/extension/web-api-partners.d.ts +112 -0
  51. package/esm/browser/extension/web-api-partners.js +2 -0
  52. package/esm/browser/extension/web-extension-api.d.ts +12 -15
  53. package/esm/browser/extension/web-extension-context.d.ts +2 -3
  54. package/esm/browser/extension/web-extension-context.js +7 -7
  55. package/esm/browser/extension/web-extension-protocol.d.ts +8 -2
  56. package/esm/browser/extension/web-extension-run.d.ts +2 -1
  57. package/esm/browser/extension/web-extension-run.js +1 -0
  58. package/esm/browser/extension/web-extensions-running.d.ts +2 -0
  59. package/esm/browser/extension/web-extensions-running.js +3 -0
  60. package/esm/browser/extension/web-extensions.d.ts +1 -1
  61. package/esm/browser/extension/web-home.d.ts +11 -19
  62. package/esm/browser/extension/web-home.js +15 -68
  63. package/esm/browser/extension/web-partners.d.ts +8 -0
  64. package/esm/browser/extension/web-partners.js +13 -0
  65. package/esm/browser/extension/web-row-board.d.ts +38 -0
  66. package/esm/browser/extension/web-row-board.js +79 -0
  67. package/esm/browser/i18n/locales.d.ts +28 -1
  68. package/esm/browser/i18n/messages-ja.js +27 -0
  69. package/esm/browser/i18n/messages-zh-tw.js +27 -0
  70. package/esm/browser/i18n/messages.d.ts +27 -0
  71. package/esm/browser/i18n/messages.js +54 -0
  72. package/esm/browser/index.d.ts +4 -0
  73. package/esm/browser/index.js +4 -0
  74. package/esm/browser/partners/group-picker.d.ts +18 -0
  75. package/esm/browser/partners/group-picker.js +81 -0
  76. package/esm/browser/partners/partners-extension.d.ts +14 -0
  77. package/esm/browser/partners/partners-extension.js +78 -0
  78. package/esm/browser/partners/partners-util.d.ts +32 -0
  79. package/esm/browser/partners/partners-util.js +68 -0
  80. package/esm/browser/partners/partners-view.d.ts +32 -0
  81. package/esm/browser/partners/partners-view.js +103 -0
  82. package/esm/browser/style/chat-list.d.ts +1 -1
  83. package/esm/browser/style/chat-list.js +21 -0
  84. package/esm/browser/style/conversation-column.d.ts +1 -1
  85. package/esm/browser/style/conversation-column.js +21 -0
  86. package/esm/browser/style/conversation.d.ts +1 -1
  87. package/esm/browser/style/conversation.js +2 -2
  88. package/esm/browser/style/layout.d.ts +1 -1
  89. package/esm/browser/style/layout.js +1 -1
  90. package/esm/browser/style/shell.d.ts +1 -1
  91. package/esm/browser/style/shell.js +1 -1
  92. package/esm/browser/util/image-shrink.d.ts +26 -0
  93. package/esm/browser/util/image-shrink.js +60 -0
  94. package/esm/browser/util/process.d.ts +7 -3
  95. package/esm/browser/util/process.js +18 -18
  96. package/lib/browser/assistant/assistant-chat-list.js +5 -1
  97. package/lib/browser/assistant/assistant-conversation.js +1 -1
  98. package/lib/browser/assistant/assistant-initiative.d.ts +5 -1
  99. package/lib/browser/assistant/assistant-initiative.js +11 -3
  100. package/lib/browser/assistant/call-keeper.d.ts +2 -1
  101. package/lib/browser/assistant/call-keeper.js +4 -2
  102. package/lib/browser/assistant/call-screen.d.ts +1 -1
  103. package/lib/browser/assistant/call-turn-end.d.ts +11 -2
  104. package/lib/browser/assistant/call-turn-end.js +22 -6
  105. package/lib/browser/assistant/read-aloud.d.ts +1 -1
  106. package/lib/browser/assistant/realtime-voice.d.ts +1 -1
  107. package/lib/browser/assistant/voice-call-bar.d.ts +5 -2
  108. package/lib/browser/assistant/voice-call-bar.js +12 -0
  109. package/lib/browser/assistant/voice-call-protocol.d.ts +79 -0
  110. package/lib/browser/assistant/voice-call-protocol.js +3 -0
  111. package/lib/browser/assistant/voice-call.d.ts +17 -65
  112. package/lib/browser/assistant/voice-call.js +45 -1
  113. package/lib/browser/assistant/voice-reopen.d.ts +1 -1
  114. package/lib/browser/components/account-menu.js +27 -6
  115. package/lib/browser/components/chat-home-util.d.ts +13 -2
  116. package/lib/browser/components/chat-home-util.js +29 -0
  117. package/lib/browser/components/chat-home.d.ts +18 -4
  118. package/lib/browser/components/chat-home.js +12 -3
  119. package/lib/browser/components/chat-list.js +4 -2
  120. package/lib/browser/components/cloud-sign-in-view.d.ts +1 -1
  121. package/lib/browser/components/earlier-messages.d.ts +4 -0
  122. package/lib/browser/components/earlier-messages.js +10 -2
  123. package/lib/browser/components/host-view.d.ts +1 -1
  124. package/lib/browser/components/message-footer.d.ts +0 -2
  125. package/lib/browser/components/message-footer.js +0 -8
  126. package/lib/browser/components/message-images.d.ts +22 -0
  127. package/lib/browser/components/message-images.js +92 -2
  128. package/lib/browser/components/message-steps.js +9 -0
  129. package/lib/browser/components/message-user.js +7 -0
  130. package/lib/browser/components/partner-row-util.d.ts +29 -0
  131. package/lib/browser/components/partner-row-util.js +48 -0
  132. package/lib/browser/components/partner-row.d.ts +19 -0
  133. package/lib/browser/components/partner-row.js +96 -0
  134. package/lib/browser/components/profile-view.d.ts +2 -2
  135. package/lib/browser/components/profile-view.js +6 -3
  136. package/lib/browser/components/web-composer.d.ts +5 -2
  137. package/lib/browser/components/web-composer.js +10 -5
  138. package/lib/browser/extension/extension-view.js +2 -2
  139. package/lib/browser/extension/icons.js +3 -0
  140. package/lib/browser/extension/web-api-call.d.ts +46 -0
  141. package/lib/browser/extension/web-api-call.js +3 -0
  142. package/lib/browser/extension/web-api-components.d.ts +37 -2
  143. package/lib/browser/extension/web-api-contributions.d.ts +2 -31
  144. package/lib/browser/extension/web-api-home.d.ts +1 -0
  145. package/lib/browser/extension/web-api-partners.d.ts +113 -0
  146. package/lib/browser/extension/web-api-partners.js +3 -0
  147. package/lib/browser/extension/web-extension-api.d.ts +12 -15
  148. package/lib/browser/extension/web-extension-context.d.ts +2 -3
  149. package/lib/browser/extension/web-extension-context.js +7 -7
  150. package/lib/browser/extension/web-extension-protocol.d.ts +8 -2
  151. package/lib/browser/extension/web-extension-run.d.ts +2 -1
  152. package/lib/browser/extension/web-extension-run.js +1 -0
  153. package/lib/browser/extension/web-extensions-running.d.ts +2 -0
  154. package/lib/browser/extension/web-extensions-running.js +3 -0
  155. package/lib/browser/extension/web-extensions.d.ts +1 -1
  156. package/lib/browser/extension/web-home.d.ts +11 -19
  157. package/lib/browser/extension/web-home.js +15 -68
  158. package/lib/browser/extension/web-partners.d.ts +9 -0
  159. package/lib/browser/extension/web-partners.js +17 -0
  160. package/lib/browser/extension/web-row-board.d.ts +39 -0
  161. package/lib/browser/extension/web-row-board.js +83 -0
  162. package/lib/browser/i18n/locales.d.ts +28 -1
  163. package/lib/browser/i18n/messages-ja.js +27 -0
  164. package/lib/browser/i18n/messages-zh-tw.js +27 -0
  165. package/lib/browser/i18n/messages.d.ts +27 -0
  166. package/lib/browser/i18n/messages.js +54 -0
  167. package/lib/browser/index.d.ts +4 -0
  168. package/lib/browser/index.js +4 -0
  169. package/lib/browser/partners/group-picker.d.ts +19 -0
  170. package/lib/browser/partners/group-picker.js +119 -0
  171. package/lib/browser/partners/partners-extension.d.ts +15 -0
  172. package/lib/browser/partners/partners-extension.js +114 -0
  173. package/lib/browser/partners/partners-util.d.ts +33 -0
  174. package/lib/browser/partners/partners-util.js +71 -0
  175. package/lib/browser/partners/partners-view.d.ts +33 -0
  176. package/lib/browser/partners/partners-view.js +144 -0
  177. package/lib/browser/style/chat-list.d.ts +1 -1
  178. package/lib/browser/style/chat-list.js +21 -0
  179. package/lib/browser/style/conversation-column.d.ts +1 -1
  180. package/lib/browser/style/conversation-column.js +21 -0
  181. package/lib/browser/style/conversation.d.ts +1 -1
  182. package/lib/browser/style/conversation.js +2 -2
  183. package/lib/browser/style/layout.d.ts +1 -1
  184. package/lib/browser/style/layout.js +1 -1
  185. package/lib/browser/style/shell.d.ts +1 -1
  186. package/lib/browser/style/shell.js +1 -1
  187. package/lib/browser/util/image-shrink.d.ts +27 -0
  188. package/lib/browser/util/image-shrink.js +63 -0
  189. package/lib/browser/util/process.d.ts +7 -3
  190. package/lib/browser/util/process.js +18 -18
  191. package/package.json +7 -7
@@ -0,0 +1,26 @@
1
+ import type { ComposerImage } from './composer.js';
2
+ /** How a picture of the box is shrunk for an extension (WebComposerProps.images): its longest side, its bytes. */
3
+ export interface ImageShrinkLimits {
4
+ side: number;
5
+ bytes: number;
6
+ }
7
+ /** A picture as an extension gets it from the box: its type, base64 and size in pixels. */
8
+ export interface ShrunkImage extends ComposerImage {
9
+ width: number;
10
+ height: number;
11
+ }
12
+ /** Pictures of the box made lighter in the page, for what keeps them or sends them on (a group chat, its agents). */
13
+ export declare namespace ImageShrink {
14
+ /** Width and height within `side`, the proportions kept, never larger than they are. */
15
+ function fit(width: number, height: number, side: number): {
16
+ width: number;
17
+ height: number;
18
+ };
19
+ /** The bytes of base64. */
20
+ function bytes(base64: string): number;
21
+ /**
22
+ * The picture as it is when it already fits (a GIF moves on so), else a JPEG as large and as good as fits within
23
+ * the limits; a transparent one on white, as JPEG has no transparency.
24
+ */
25
+ function shrink(image: ComposerImage, limits: ImageShrinkLimits): Promise<ShrunkImage>;
26
+ }
@@ -0,0 +1,60 @@
1
+ const QUALITIES = [0.85, 0.75, 0.65];
2
+ /** Each try a side this much shorter than the last, while the picture is too heavy. */
3
+ const STEP = 0.8;
4
+ const TRIES = 6;
5
+ /** Pictures of the box made lighter in the page, for what keeps them or sends them on (a group chat, its agents). */
6
+ export var ImageShrink;
7
+ (function (ImageShrink) {
8
+ /** Width and height within `side`, the proportions kept, never larger than they are. */
9
+ function fit(width, height, side) {
10
+ const scale = Math.min(1, side / Math.max(width, height, 1));
11
+ return { width: Math.max(1, Math.round(width * scale)), height: Math.max(1, Math.round(height * scale)) };
12
+ }
13
+ ImageShrink.fit = fit;
14
+ /** The bytes of base64. */
15
+ function bytes(base64) {
16
+ const padding = base64.endsWith('==') ? 2 : base64.endsWith('=') ? 1 : 0;
17
+ return Math.floor((base64.length * 3) / 4) - padding;
18
+ }
19
+ ImageShrink.bytes = bytes;
20
+ /**
21
+ * The picture as it is when it already fits (a GIF moves on so), else a JPEG as large and as good as fits within
22
+ * the limits; a transparent one on white, as JPEG has no transparency.
23
+ */
24
+ async function shrink(image, limits) {
25
+ const blob = await (await fetch(`data:${image.mimeType};base64,${image.data}`)).blob();
26
+ const bitmap = await createImageBitmap(blob);
27
+ try {
28
+ const natural = { width: bitmap.width, height: bitmap.height };
29
+ if (Math.max(natural.width, natural.height) <= limits.side && bytes(image.data) <= limits.bytes) {
30
+ return { ...image, ...natural };
31
+ }
32
+ let side = limits.side;
33
+ for (let tries = 0; tries < TRIES; tries++, side = Math.round(side * STEP)) {
34
+ const size = fit(natural.width, natural.height, side);
35
+ const canvas = document.createElement('canvas');
36
+ canvas.width = size.width;
37
+ canvas.height = size.height;
38
+ const context = canvas.getContext('2d');
39
+ if (!context) {
40
+ break;
41
+ }
42
+ context.fillStyle = '#fff';
43
+ context.fillRect(0, 0, size.width, size.height);
44
+ context.drawImage(bitmap, 0, 0, size.width, size.height);
45
+ for (const quality of QUALITIES) {
46
+ const data = canvas.toDataURL('image/jpeg', quality).replace(/^data:[^,]*,/, '');
47
+ if (bytes(data) <= limits.bytes) {
48
+ return { type: 'image', data, mimeType: 'image/jpeg', ...size };
49
+ }
50
+ }
51
+ }
52
+ throw new Error('The picture is too large.');
53
+ }
54
+ finally {
55
+ bitmap.close();
56
+ }
57
+ }
58
+ ImageShrink.shrink = shrink;
59
+ })(ImageShrink || (ImageShrink = {}));
60
+ //# sourceMappingURL=image-shrink.js.map
@@ -32,6 +32,11 @@ export type ProcessStep = {
32
32
  kind: 'said';
33
33
  key: string;
34
34
  message: SessionMessage;
35
+ }
36
+ /** Ta restarted in the middle of the work and it went on from there (TA_RESUME_MESSAGE). */
37
+ | {
38
+ kind: 'resumed';
39
+ key: string;
35
40
  };
36
41
  /**
37
42
  * A thing ta did, as one line of the work: a call of a tool, with the thoughts that led to it and, for a script of
@@ -77,8 +82,6 @@ export interface TurnItem {
77
82
  last?: SessionMessage;
78
83
  /** The agent is still at it. */
79
84
  active: boolean;
80
- /** Ta restarted in the middle of it and the work went on (TA_RESUME_MESSAGE next): not cut off, as the user sees it. */
81
- resumed?: boolean;
82
85
  }
83
86
  export type ThreadItem = MessageItem | TurnItem;
84
87
  /** While the agent works, only the latest steps show; the earlier ones fold into one row. */
@@ -97,7 +100,8 @@ export declare namespace ProcessUtil {
97
100
  * the keys stay as earlier messages come in front. A message not shown (see `hidden`) in the middle of
98
101
  * the work stays in its turn: an external agent that goes on on its own, with the files it changed
99
102
  * noted between, reads as one turn, not as a turn for each time it went on. So does a message of the user it was
100
- * given on the way (`steered`): a step of the turn, not the start of another. `head`: when `messages` start in
103
+ * given on the way (`steered`): a step of the turn, not the start of another, and so does the note that Ta restarted
104
+ * in the middle of it and went on (`resumed`): the work goes on in the same turn. `head`: when `messages` start in
101
105
  * the middle of a turn, the message that asked for it, first, with the key it has once loaded.
102
106
  */
103
107
  function items(messages: SessionMessage[], working: boolean, offset?: number, renderers?: Readonly<Record<string, unknown>>, head?: {
@@ -18,11 +18,12 @@ export var ProcessUtil;
18
18
  * the keys stay as earlier messages come in front. A message not shown (see `hidden`) in the middle of
19
19
  * the work stays in its turn: an external agent that goes on on its own, with the files it changed
20
20
  * noted between, reads as one turn, not as a turn for each time it went on. So does a message of the user it was
21
- * given on the way (`steered`): a step of the turn, not the start of another. `head`: when `messages` start in
21
+ * given on the way (`steered`): a step of the turn, not the start of another, and so does the note that Ta restarted
22
+ * in the middle of it and went on (`resumed`): the work goes on in the same turn. `head`: when `messages` start in
22
23
  * the middle of a turn, the message that asked for it, first, with the key it has once loaded.
23
24
  */
24
25
  function items(messages, working, offset = 0, renderers = {}, head) {
25
- var _a, _b;
26
+ var _a;
26
27
  const items = [];
27
28
  if (head && head.index < offset) {
28
29
  items.push({ kind: 'message', key: `m${head.index}`, message: head.message });
@@ -30,7 +31,7 @@ export var ProcessUtil;
30
31
  let index = 0;
31
32
  while (index < messages.length) {
32
33
  const role = messages[index].role;
33
- if (!TURN_ROLES.has(role)) {
34
+ if (!TURN_ROLES.has(role) && !resumed(messages[index])) {
34
35
  const item = { kind: 'message', key: `m${offset + index}`, message: messages[index] };
35
36
  if (index > 0 && writtenBefore(messages[index], messages[index - 1])) {
36
37
  item.queued = true;
@@ -41,16 +42,15 @@ export var ProcessUtil;
41
42
  }
42
43
  const start = index;
43
44
  while (index < messages.length &&
44
- (TURN_ROLES.has(messages[index].role) || hidden(messages[index], renderers) || steered(messages, index))) {
45
+ (TURN_ROLES.has(messages[index].role) ||
46
+ resumed(messages[index]) ||
47
+ hidden(messages[index], renderers) ||
48
+ steered(messages, index))) {
45
49
  index++;
46
50
  }
47
- const item = turn(messages.slice(start, index), offset + start, working && index === messages.length);
48
- if (((_a = messages[index]) === null || _a === void 0 ? void 0 : _a.customType) === TA_RESUME_MESSAGE) {
49
- item.resumed = true;
50
- }
51
- items.push(item);
51
+ items.push(turn(messages.slice(start, index), offset + start, working && index === messages.length));
52
52
  }
53
- if (working && ((_b = items[items.length - 1]) === null || _b === void 0 ? void 0 : _b.kind) !== 'turn') {
53
+ if (working && ((_a = items[items.length - 1]) === null || _a === void 0 ? void 0 : _a.kind) !== 'turn') {
54
54
  items.push({ kind: 'turn', key: `t${offset + messages.length}`, messages: [], steps: [], reply: [], active: true });
55
55
  }
56
56
  return items;
@@ -78,6 +78,10 @@ export var ProcessUtil;
78
78
  return false;
79
79
  }
80
80
  ProcessUtil.steered = steered;
81
+ /** The note that Ta restarted in the middle of a run and went on with it (TaSessionResume). */
82
+ function resumed(message) {
83
+ return message.customType === TA_RESUME_MESSAGE;
84
+ }
81
85
  /** `message`, of the user, was written before `previous`, of the agent, came: while the agent worked. */
82
86
  function writtenBefore(message, previous) {
83
87
  const { role, timestamp } = message;
@@ -97,6 +101,9 @@ export var ProcessUtil;
97
101
  if (role === 'user') {
98
102
  steps.push({ kind: 'said', key: `${start + offset}.u`, message });
99
103
  }
104
+ if (resumed(message)) {
105
+ steps.push({ kind: 'resumed', key: `${start + offset}.r` });
106
+ }
100
107
  if (role !== 'assistant') {
101
108
  return;
102
109
  }
@@ -158,10 +165,6 @@ export var ProcessUtil;
158
165
  if (stopReason === 'error') {
159
166
  return stopReason;
160
167
  }
161
- // Cut off by a restart of Ta and gone on with after it, which the mark of it under the turn says.
162
- if (item.resumed) {
163
- return undefined;
164
- }
165
168
  if (stopReason === 'aborted') {
166
169
  return stopReason;
167
170
  }
@@ -391,10 +394,7 @@ export var ProcessUtil;
391
394
  if (a.kind === 'message' || b.kind === 'message') {
392
395
  return a.kind === b.kind && a.message === b.message && a.queued === b.queued;
393
396
  }
394
- return (a.active === b.active &&
395
- a.resumed === b.resumed &&
396
- a.messages.length === b.messages.length &&
397
- a.messages.every((message, index) => message === b.messages[index]));
397
+ return a.active === b.active && a.messages.length === b.messages.length && a.messages.every((message, index) => message === b.messages[index]);
398
398
  }
399
399
  ProcessUtil.same = same;
400
400
  })(ProcessUtil || (ProcessUtil = {}));
@@ -47,6 +47,7 @@ const web_home_1 = require("../extension/web-home");
47
47
  const web_tasks_1 = require("../extension/web-tasks");
48
48
  const hooks_1 = require("../hooks");
49
49
  const use_t_1 = require("../i18n/use-t");
50
+ const partners_util_1 = require("../partners/partners-util");
50
51
  const state_protocol_1 = require("../state/state-protocol");
51
52
  const assistant_hooks_1 = require("./assistant-hooks");
52
53
  /**
@@ -73,6 +74,8 @@ function useChatHome(onPicked) {
73
74
  const listed = side_lists_1.SideListUtil.viewListsDouble(extensions.views);
74
75
  const tasks = React.useSyncExternalStore(host.tasks.subscribe, host.tasks.tasks, host.tasks.tasks);
75
76
  const items = React.useSyncExternalStore(host.home.subscribe, host.home.items, host.home.items);
77
+ const allPartners = React.useSyncExternalStore(host.partners.subscribe, host.partners.partners, host.partners.partners);
78
+ const partners = React.useMemo(() => partners_util_1.PartnersUtil.chats(allPartners), [allPartners]);
76
79
  // Its preview and whether it works, as one string: the same line stays the same value.
77
80
  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]);
78
81
  const read = () => {
@@ -104,6 +107,7 @@ function useChatHome(onPicked) {
104
107
  },
105
108
  },
106
109
  items,
110
+ partners,
107
111
  shownItem,
108
112
  openItem: entry => {
109
113
  latest.current();
@@ -118,7 +122,7 @@ function useChatHome(onPicked) {
118
122
  },
119
123
  remove: removed => void web_tasks_1.WebTaskUtil.remove(removed, notices, t),
120
124
  };
121
- }, [listed, line, name, shown, view, items, shownItem, tasks, host, state, notices, t]);
125
+ }, [listed, line, name, shown, view, items, partners, shownItem, tasks, host, state, notices, t]);
122
126
  }
123
127
  /** The list of chats with what the double knows of them: its tasks marked, a conversation to hand it; its home over them. */
124
128
  function AssistantChatList(props) {
@@ -29,7 +29,7 @@ const NOTE_SETTLE_MS = 5000;
29
29
  class AssistantConversation {
30
30
  constructor() {
31
31
  /** Whether it asks before starting a task, kept with the extension of the user's trust. */
32
- this.initiative = new assistant_initiative_1.AssistantInitiative(() => this.extensions, () => this.settings);
32
+ this.initiative = new assistant_initiative_1.AssistantInitiative(() => this.extensions, () => this.settings, () => this.persisted.load(settings_protocol_1.SettingsUtil.STATE));
33
33
  this.current = { ready: false, tasks: [], asks: [] };
34
34
  this.taskStores = new Map();
35
35
  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;
@@ -15,9 +15,12 @@ exports.START_TASK = {
15
15
  * one, Settings.confirmTasks alone, as before.
16
16
  */
17
17
  class AssistantInitiative {
18
- constructor(extensions, settings) {
18
+ constructor(extensions, settings,
19
+ /** Until the settings the server keeps are in: the copy of this browser may be older than the user's choice. */
20
+ loaded = async () => undefined) {
19
21
  this.extensions = extensions;
20
22
  this.settings = settings;
23
+ this.loaded = loaded;
21
24
  }
22
25
  start() {
23
26
  const extensions = this.extensions();
@@ -58,10 +61,15 @@ class AssistantInitiative {
58
61
  if (!provider) {
59
62
  return;
60
63
  }
61
- const asking = (await provider.level(exports.START_TASK).catch(() => undefined)) !== 'act';
62
- if (provider !== this.current) {
64
+ if (this.synced === undefined) {
65
+ await this.loaded().catch(() => undefined);
66
+ }
67
+ const level = await provider.level(exports.START_TASK).catch(() => undefined);
68
+ // Not known (the computer restarting, the connection gone): nothing to go by, the switch stays as it is.
69
+ if (provider !== this.current || level === undefined) {
63
70
  return;
64
71
  }
72
+ const asking = level !== 'act';
65
73
  const settings = this.settings();
66
74
  const now = settings.state.settings.confirmTasks;
67
75
  // 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';
2
2
  import { type StateSpec, TaState } from '../state/state-protocol';
3
- import type { CallPhase, VoiceCall } from './voice-call';
3
+ import type { VoiceCall } from './voice-call';
4
+ import type { CallPhase } from './voice-call-protocol';
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 {
@@ -262,8 +262,10 @@ let TaCallKeeperImpl = class TaCallKeeperImpl {
262
262
  }
263
263
  drop() {
264
264
  var _a, _b, _c, _d;
265
- 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) {
266
- this.persisted.set(CallKeeperUtil.SHARED, undefined);
265
+ const shared = (_a = this.persisted) === null || _a === void 0 ? void 0 : _a.get(CallKeeperUtil.SHARED);
266
+ if (this.current && (shared === null || shared === void 0 ? void 0 : shared.page) === this.page && !shared.end) {
267
+ // Said ended, not cleared: a page that still has it would write a value gone from the server back (TaState).
268
+ (_b = this.persisted) === null || _b === void 0 ? void 0 : _b.set(CallKeeperUtil.SHARED, { ...shared, at: Date.now(), end: true });
267
269
  }
268
270
  (_c = this.offState) === null || _c === void 0 ? void 0 : _c.call(this);
269
271
  (_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';
2
2
  import { type ScreenPartSpec, type TaScreen } from '../screen/screen-protocol';
3
- import type { CallPhase } from './voice-call';
3
+ import type { CallPhase } from './voice-call-protocol';
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. */
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CallTurnEnd = exports.TURN_MS = exports.FILLER_MS = exports.END_MS = exports.RETRY_MS = exports.SILENT_MS = exports.SILENT_ROUNDS = void 0;
3
+ exports.CallTurnEnd = exports.TURN_MS = exports.DRAFT_MS = exports.FILLER_MS = exports.END_MS = exports.RETRY_MS = exports.SILENT_MS = exports.SILENT_ROUNDS = void 0;
4
4
  const turn_end_1 = require("../util/turn-end");
5
5
  /** Listens heard nothing this many times in a row, and for SILENT_MS: nobody is there, the call ends. */
6
6
  exports.SILENT_ROUNDS = 4;
@@ -22,31 +22,46 @@ exports.END_MS = 1300;
22
22
  * a hesitation is dropped and a backchannel ("嗯", "好好", an answer maybe) goes as said.
23
23
  */
24
24
  exports.FILLER_MS = 3000;
25
+ /**
26
+ * 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
27
+ * answer to them is begun (CallPartner.draft), said only once they are done (docs/design/ta-call.md 10).
28
+ */
29
+ exports.DRAFT_MS = 400;
25
30
  /** At most this long a turn, from the first words: talk around the user that keeps the words coming ends there too. */
26
31
  exports.TURN_MS = 15000;
27
32
  /**
28
33
  * When the user is done with their turn in a call, by the words heard as they come (TurnEnd): once they stayed the same
29
34
  * a while (END_MS, sooner after a sentence, later while they hesitate, FILLER_MS for sounds alone), and at the latest
30
- * TURN_MS from the first words. It calls `done` then.
35
+ * TURN_MS from the first words. It calls `done` then; and `suspect` sooner (DRAFT_MS), where the words may end the turn.
31
36
  */
32
37
  class CallTurnEnd {
33
- constructor(times, done) {
38
+ constructor(times, done, suspect) {
34
39
  this.times = times;
35
40
  this.done = done;
41
+ this.suspect = suspect;
36
42
  /** When the words heard last changed: sounds alone wait FILLER_MS from it, over listens. */
37
43
  this.wordsAt = 0;
38
44
  }
39
45
  /** The words heard are `text` now. */
40
46
  heard(text) {
41
- var _a, _b;
47
+ var _a, _b, _c;
42
48
  this.wordsAt = Date.now();
43
49
  clearTimeout(this.endTimer);
44
- this.endTimer = setTimeout(this.done, this.waitMs(text));
50
+ const wait = this.waitMs(text);
51
+ this.endTimer = setTimeout(this.done, wait);
45
52
  (_a = this.turnTimer) !== null && _a !== void 0 ? _a : (this.turnTimer = setTimeout(this.done, (_b = this.times.turnMs) !== null && _b !== void 0 ? _b : exports.TURN_MS));
53
+ clearTimeout(this.draftTimer);
54
+ this.draftTimer = undefined;
55
+ const draftMs = (_c = this.times.draftMs) !== null && _c !== void 0 ? _c : exports.DRAFT_MS;
56
+ const suspect = this.suspect;
57
+ if (suspect && wait > draftMs && turn_end_1.TurnEnd.words(text) >= 2 && !turn_end_1.TurnEnd.sounds(text) && !turn_end_1.TurnEnd.hesitates(text)) {
58
+ this.draftTimer = setTimeout(() => suspect(text), draftMs);
59
+ }
46
60
  }
47
61
  /** A listen goes on from sounds alone the one before ended on: done once they waited FILLER_MS, unless words come. */
48
62
  hold() {
49
63
  clearTimeout(this.endTimer);
64
+ clearTimeout(this.draftTimer);
50
65
  this.endTimer = setTimeout(this.done, Math.max(0, this.fillerMs - (Date.now() - this.wordsAt)));
51
66
  }
52
67
  /** `said` is sounds alone that did not wait FILLER_MS yet: they wait on for words. */
@@ -56,7 +71,8 @@ class CallTurnEnd {
56
71
  stop() {
57
72
  clearTimeout(this.endTimer);
58
73
  clearTimeout(this.turnTimer);
59
- this.endTimer = this.turnTimer = undefined;
74
+ clearTimeout(this.draftTimer);
75
+ this.endTimer = this.turnTimer = this.draftTimer = undefined;
60
76
  }
61
77
  get fillerMs() {
62
78
  var _a;
@@ -1,5 +1,5 @@
1
1
  import { RealtimeVoice, type RealtimeVoiceHost } from './realtime-voice';
2
- import type { CallVoice } from './voice-call';
2
+ import type { CallVoice } from './voice-call-protocol';
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';
3
- import type { CallVoice } from './voice-call';
3
+ import type { CallVoice } from './voice-call-protocol';
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';
3
3
  import type { TalkCall } from '../components/voice-talk';
4
- import type { WebCallPartner, WebCallTarget } from '../extension/web-api-contributions';
4
+ import type { WebCallPartner, WebCallSession, WebCallTarget } from '../extension/web-api-call';
5
5
  import { type Translate } from '../i18n/use-t';
6
- import { type CallEnd, type CallOptions, type CallPartner, type CallState, VoiceCall } from './voice-call';
6
+ import { VoiceCall } from './voice-call';
7
+ import type { CallDraft, CallEnd, CallOptions, CallPartner, CallState } from './voice-call-protocol';
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. */
@@ -184,6 +184,7 @@ var CallPartnerUtil;
184
184
  const reply = await session.say(text, options);
185
185
  return reply ? spoken_1.SpokenReply.whole(reply) : undefined;
186
186
  },
187
+ ...(session.draft ? { draft: (text) => CallPartnerUtil.draft(session, text) } : {}),
187
188
  news: listener => {
188
189
  if (session.next) {
189
190
  void CallPartnerUtil.follow(session.next.bind(session), () => closed, text => listener(spoken_1.SpokenReply.whole(text)));
@@ -197,6 +198,17 @@ var CallPartnerUtil;
197
198
  });
198
199
  }
199
200
  CallPartnerUtil.open = open;
201
+ /** An answer begun by the partner before the user was known to be done, its reply said whole. */
202
+ function draft(session, text) {
203
+ var _a;
204
+ const begun = (_a = session.draft) === null || _a === void 0 ? void 0 : _a.call(session, text);
205
+ return {
206
+ reply: begun ? begun.reply.then(reply => (reply ? spoken_1.SpokenReply.whole(reply) : undefined)) : Promise.reject(new Error('No drafts.')),
207
+ keep: () => begun === null || begun === void 0 ? void 0 : begun.keep(),
208
+ drop: () => begun === null || begun === void 0 ? void 0 : begun.drop(),
209
+ };
210
+ }
211
+ CallPartnerUtil.draft = draft;
200
212
  /** After a failure to ask for what the partner says by itself, before it asks again. */
201
213
  CallPartnerUtil.RETRY_MS = 3000;
202
214
  /** Asks for what the partner says by itself again and again, each as it comes, until the call is over. */
@@ -0,0 +1,79 @@
1
+ import type { Voice } from '../util/voice';
2
+ import type { CallTurnTimes } from './call-turn-end';
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
+ }
79
+ //# sourceMappingURL=voice-call-protocol.d.ts.map
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=voice-call-protocol.js.map