@celljs/ta-web 4.19.0 → 4.21.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 (145) hide show
  1. package/esm/browser/account/device-account.d.ts +65 -1
  2. package/esm/browser/account/device-account.js +206 -6
  3. package/esm/browser/assistant/assistant-chat-list.js +2 -1
  4. package/esm/browser/assistant/call-turn-end.d.ts +55 -0
  5. package/esm/browser/assistant/call-turn-end.js +68 -0
  6. package/esm/browser/assistant/realtime-voice.js +3 -3
  7. package/esm/browser/assistant/voice-call.d.ts +19 -28
  8. package/esm/browser/assistant/voice-call.js +64 -51
  9. package/esm/browser/components/account-menu.d.ts +9 -4
  10. package/esm/browser/components/account-menu.js +59 -20
  11. package/esm/browser/components/account-view.d.ts +33 -7
  12. package/esm/browser/components/account-view.js +140 -79
  13. package/esm/browser/components/app-view.js +2 -2
  14. package/esm/browser/components/cloud-sign-in-view.d.ts +1 -1
  15. package/esm/browser/components/cloud-sign-in-view.js +4 -1
  16. package/esm/browser/components/dino-look.d.ts +9 -1
  17. package/esm/browser/components/dino-look.js +46 -1
  18. package/esm/browser/components/environment-view.js +12 -1
  19. package/esm/browser/components/face-pictures.d.ts +10 -0
  20. package/esm/browser/components/face-pictures.js +24 -0
  21. package/esm/browser/components/face.d.ts +4 -1
  22. package/esm/browser/components/face.js +16 -1
  23. package/esm/browser/components/host-view.d.ts +15 -8
  24. package/esm/browser/components/host-view.js +23 -70
  25. package/esm/browser/components/me-view.d.ts +2 -2
  26. package/esm/browser/components/me-view.js +7 -6
  27. package/esm/browser/components/picture-dialog.d.ts +18 -0
  28. package/esm/browser/components/picture-dialog.js +116 -0
  29. package/esm/browser/components/profile-view.d.ts +11 -0
  30. package/esm/browser/components/profile-view.js +85 -0
  31. package/esm/browser/components/workbench-view.js +42 -7
  32. package/esm/browser/extension/icons.js +2 -1
  33. package/esm/browser/extension/web-api-components.d.ts +2 -2
  34. package/esm/browser/extension/web-api-home.d.ts +13 -0
  35. package/esm/browser/extension/web-api-home.js +2 -0
  36. package/esm/browser/extension/web-extension-api.d.ts +4 -4
  37. package/esm/browser/extension/web-extension-context.js +2 -1
  38. package/esm/browser/extension/web-home.d.ts +8 -0
  39. package/esm/browser/extension/web-home.js +20 -0
  40. package/esm/browser/gateway/console-limits.d.ts +15 -0
  41. package/esm/browser/gateway/console-limits.js +2 -2
  42. package/esm/browser/gateway/console-tenant.js +33 -2
  43. package/esm/browser/gateway/console-updates.d.ts +12 -0
  44. package/esm/browser/gateway/console-updates.js +76 -0
  45. package/esm/browser/gateway/console-util.d.ts +7 -1
  46. package/esm/browser/gateway/console-util.js +18 -0
  47. package/esm/browser/gateway/console-view.js +9 -2
  48. package/esm/browser/i18n/locales.d.ts +55 -3
  49. package/esm/browser/i18n/locales.js +9 -3
  50. package/esm/browser/i18n/messages-all.d.ts +7 -0
  51. package/esm/browser/i18n/messages-all.js +14 -0
  52. package/esm/browser/i18n/messages-ja.js +54 -4
  53. package/esm/browser/i18n/messages-zh-tw.js +54 -4
  54. package/esm/browser/i18n/messages.d.ts +56 -8
  55. package/esm/browser/i18n/messages.js +141 -19
  56. package/esm/browser/i18n/use-t.js +4 -3
  57. package/esm/browser/settings/settings.js +3 -1
  58. package/esm/browser/style/conversation-column.d.ts +1 -1
  59. package/esm/browser/style/conversation-column.js +2 -1
  60. package/esm/browser/style/dialogs.d.ts +1 -1
  61. package/esm/browser/style/dialogs.js +6 -0
  62. package/esm/browser/style/pages.d.ts +1 -1
  63. package/esm/browser/style/pages.js +11 -0
  64. package/esm/browser/style/surfaces.d.ts +1 -1
  65. package/esm/browser/style/surfaces.js +1 -0
  66. package/esm/browser/util/picture.d.ts +5 -0
  67. package/esm/browser/util/picture.js +43 -0
  68. package/esm/browser/util/turn-end.d.ts +8 -0
  69. package/esm/browser/util/turn-end.js +78 -35
  70. package/esm/browser/workbench-hosts.d.ts +4 -1
  71. package/esm/browser/workbench-hosts.js +17 -0
  72. package/esm/browser/workbench-protocol.d.ts +8 -0
  73. package/lib/browser/account/device-account.d.ts +65 -1
  74. package/lib/browser/account/device-account.js +206 -6
  75. package/lib/browser/assistant/assistant-chat-list.js +2 -1
  76. package/lib/browser/assistant/call-turn-end.d.ts +56 -0
  77. package/lib/browser/assistant/call-turn-end.js +72 -0
  78. package/lib/browser/assistant/realtime-voice.js +3 -3
  79. package/lib/browser/assistant/voice-call.d.ts +19 -28
  80. package/lib/browser/assistant/voice-call.js +67 -54
  81. package/lib/browser/components/account-menu.d.ts +9 -4
  82. package/lib/browser/components/account-menu.js +57 -18
  83. package/lib/browser/components/account-view.d.ts +33 -7
  84. package/lib/browser/components/account-view.js +142 -77
  85. package/lib/browser/components/app-view.js +1 -1
  86. package/lib/browser/components/cloud-sign-in-view.d.ts +1 -1
  87. package/lib/browser/components/cloud-sign-in-view.js +4 -1
  88. package/lib/browser/components/dino-look.d.ts +9 -1
  89. package/lib/browser/components/dino-look.js +48 -1
  90. package/lib/browser/components/environment-view.js +11 -0
  91. package/lib/browser/components/face-pictures.d.ts +11 -0
  92. package/lib/browser/components/face-pictures.js +60 -0
  93. package/lib/browser/components/face.d.ts +4 -1
  94. package/lib/browser/components/face.js +16 -1
  95. package/lib/browser/components/host-view.d.ts +15 -8
  96. package/lib/browser/components/host-view.js +22 -68
  97. package/lib/browser/components/me-view.d.ts +2 -2
  98. package/lib/browser/components/me-view.js +7 -6
  99. package/lib/browser/components/picture-dialog.d.ts +19 -0
  100. package/lib/browser/components/picture-dialog.js +153 -0
  101. package/lib/browser/components/profile-view.d.ts +12 -0
  102. package/lib/browser/components/profile-view.js +123 -0
  103. package/lib/browser/components/workbench-view.js +39 -4
  104. package/lib/browser/extension/icons.js +1 -0
  105. package/lib/browser/extension/web-api-components.d.ts +2 -2
  106. package/lib/browser/extension/web-api-home.d.ts +14 -0
  107. package/lib/browser/extension/web-api-home.js +3 -0
  108. package/lib/browser/extension/web-extension-api.d.ts +4 -4
  109. package/lib/browser/extension/web-extension-context.js +2 -1
  110. package/lib/browser/extension/web-home.d.ts +8 -0
  111. package/lib/browser/extension/web-home.js +54 -1
  112. package/lib/browser/gateway/console-limits.d.ts +15 -0
  113. package/lib/browser/gateway/console-limits.js +2 -0
  114. package/lib/browser/gateway/console-tenant.js +32 -1
  115. package/lib/browser/gateway/console-updates.d.ts +13 -0
  116. package/lib/browser/gateway/console-updates.js +113 -0
  117. package/lib/browser/gateway/console-util.d.ts +7 -1
  118. package/lib/browser/gateway/console-util.js +18 -0
  119. package/lib/browser/gateway/console-view.js +9 -2
  120. package/lib/browser/i18n/locales.d.ts +55 -3
  121. package/lib/browser/i18n/locales.js +8 -2
  122. package/lib/browser/i18n/messages-all.d.ts +8 -0
  123. package/lib/browser/i18n/messages-all.js +17 -0
  124. package/lib/browser/i18n/messages-ja.js +54 -4
  125. package/lib/browser/i18n/messages-zh-tw.js +54 -4
  126. package/lib/browser/i18n/messages.d.ts +56 -8
  127. package/lib/browser/i18n/messages.js +143 -21
  128. package/lib/browser/i18n/use-t.js +4 -3
  129. package/lib/browser/settings/settings.js +3 -1
  130. package/lib/browser/style/conversation-column.d.ts +1 -1
  131. package/lib/browser/style/conversation-column.js +2 -1
  132. package/lib/browser/style/dialogs.d.ts +1 -1
  133. package/lib/browser/style/dialogs.js +6 -0
  134. package/lib/browser/style/pages.d.ts +1 -1
  135. package/lib/browser/style/pages.js +11 -0
  136. package/lib/browser/style/surfaces.d.ts +1 -1
  137. package/lib/browser/style/surfaces.js +1 -0
  138. package/lib/browser/util/picture.d.ts +6 -0
  139. package/lib/browser/util/picture.js +46 -0
  140. package/lib/browser/util/turn-end.d.ts +8 -0
  141. package/lib/browser/util/turn-end.js +78 -35
  142. package/lib/browser/workbench-hosts.d.ts +4 -1
  143. package/lib/browser/workbench-hosts.js +17 -0
  144. package/lib/browser/workbench-protocol.d.ts +8 -0
  145. package/package.json +7 -7
@@ -6,6 +6,11 @@ const workbench_util_1 = require("../workbench-util");
6
6
  const KEY = 'ta.account';
7
7
  /** Signed out of the account by the user: not signed in again by itself with the token of a Ta in the cloud. */
8
8
  const OFF_KEY = 'ta.account.off';
9
+ /** The accounts switched away from, the latest first. */
10
+ const RECENT_KEY = 'ta.account.recent';
11
+ const MAX_RECENT = 5;
12
+ /** The computers connected by their code while signed in, to bring into the account once connected: by host id. */
13
+ const JOINING_KEY = 'ta.account.joining';
9
14
  const SYNC_MS = 15000;
10
15
  const WAITING_SYNC_MS = 3000;
11
16
  /**
@@ -18,12 +23,111 @@ class DeviceAccount {
18
23
  this.hosts = hosts;
19
24
  this.service = service;
20
25
  this.gateways = gateways;
26
+ this.bringing = false;
27
+ /** The computers tried once in this page: one that would not join is not asked again every round. */
28
+ this.tried = new Set();
21
29
  const kept = DeviceAccount.read();
22
30
  if (kept) {
23
31
  this.agent = this.agentOf(kept);
24
32
  }
25
33
  this.schedule(0);
26
34
  document.addEventListener('visibilitychange', () => document.visibilityState === 'visible' && this.schedule(0));
35
+ hosts.subscribe(() => void this.bringPending());
36
+ }
37
+ /** The computers to bring into the account, and the devices of it this device lets in once they ask. */
38
+ static joining() {
39
+ var _a;
40
+ var _b, _c, _d;
41
+ try {
42
+ const kept = JSON.parse((_b = (_a = (0, workbench_util_1.storage)()) === null || _a === void 0 ? void 0 : _a.getItem(JOINING_KEY)) !== null && _b !== void 0 ? _b : '{}');
43
+ return { hosts: (_c = kept.hosts) !== null && _c !== void 0 ? _c : [], devices: (_d = kept.devices) !== null && _d !== void 0 ? _d : [] };
44
+ }
45
+ catch (_e) {
46
+ return { hosts: [], devices: [] };
47
+ }
48
+ }
49
+ static keepJoining(next) {
50
+ var _a;
51
+ (_a = (0, workbench_util_1.storage)()) === null || _a === void 0 ? void 0 : _a.setItem(JOINING_KEY, JSON.stringify({ hosts: next.hosts.slice(-10), devices: next.devices.slice(-10) }));
52
+ }
53
+ /**
54
+ * A computer connected by its code while this device is in an account (docs/design/ta-me.md 4): it joins the account
55
+ * once connected, with a token of the account this device gets for it, and this device lets it in. Being by the
56
+ * computer to scan its code is as good as tapping Allow.
57
+ */
58
+ bringIn(hostId) {
59
+ var _a;
60
+ if (!this.agent || this.tried.has(hostId) || ((_a = this.hosts.state.hosts.find(one => one.id === hostId)) === null || _a === void 0 ? void 0 : _a.account)) {
61
+ return;
62
+ }
63
+ const joining = DeviceAccount.joining();
64
+ DeviceAccount.keepJoining({ ...joining, hosts: [...joining.hosts.filter(one => one !== hostId), hostId] });
65
+ void this.bringPending();
66
+ }
67
+ /** The Ta in the cloud of the account's gateway, in the account too (docs/design/ta-me.md 2): brought in as a scanned computer. */
68
+ bringCloud() {
69
+ var _a;
70
+ const service = (_a = this.agent) === null || _a === void 0 ? void 0 : _a.state.service;
71
+ for (const host of this.hosts.state.hosts) {
72
+ if (service && !host.account && DeviceAccount.gatewayOf(host) === service) {
73
+ this.bringIn(host.id);
74
+ }
75
+ }
76
+ }
77
+ /** The computer in use, if it waits to be brought into the account: asked to join it. */
78
+ async bringPending() {
79
+ // While switching, the connection is still of the computer before: not the one to bring in.
80
+ const { host, status, switching } = this.hosts.state;
81
+ const joining = DeviceAccount.joining();
82
+ const agent = this.agent;
83
+ if (this.bringing || switching || !agent || !host || status !== 'online' || !joining.hosts.includes(host) || !this.view || this.view.waiting) {
84
+ return;
85
+ }
86
+ this.bringing = true;
87
+ const done = (devices) => DeviceAccount.keepJoining({ hosts: joining.hosts.filter(one => one !== host), devices });
88
+ this.tried.add(host);
89
+ try {
90
+ const saved = this.hosts.state.hosts.find(one => one.id === host);
91
+ const cloud = saved !== undefined && DeviceAccount.gatewayOf(saved) !== undefined;
92
+ const { token } = await agent.invite();
93
+ const info = await this.hosts.account.joinAccount(agent.state.service, token);
94
+ const self = info.devices.find(one => one.self);
95
+ if (cloud && (self === null || self === void 0 ? void 0 : self.kind) !== 'cloud') {
96
+ // A Ta in the cloud its gateway did not say is one (a gateway of before): out again, never a computer.
97
+ await this.hosts.account.signOut();
98
+ done(joining.devices);
99
+ return;
100
+ }
101
+ if (self) {
102
+ this.hosts.markAccountHost(host, self.id);
103
+ }
104
+ done(self && info.waiting ? [...joining.devices, self.id] : joining.devices);
105
+ this.schedule(0);
106
+ }
107
+ catch (_a) {
108
+ // Signed in to another account there, a ta serve of before, or a member who may not: it stays this device's.
109
+ done(joining.devices);
110
+ }
111
+ finally {
112
+ this.bringing = false;
113
+ }
114
+ }
115
+ /** The computers this device brought in, let in as soon as they ask. */
116
+ async letInBrought(view) {
117
+ const joining = DeviceAccount.joining();
118
+ const asking = view.devices.filter(one => one.waiting && joining.devices.includes(one.id));
119
+ let next = view;
120
+ for (const device of asking) {
121
+ next = await this.agent.approve(device.id);
122
+ }
123
+ if (asking.length > 0) {
124
+ DeviceAccount.keepJoining({ ...joining, devices: joining.devices.filter(one => !asking.some(device => device.id === one)) });
125
+ }
126
+ return next;
127
+ }
128
+ /** The one of the page, once made. */
129
+ static current() {
130
+ return DeviceAccount.instance;
27
131
  }
28
132
  /** The one of the page. */
29
133
  static of(hosts, service, gateways) {
@@ -60,14 +164,97 @@ class DeviceAccount {
60
164
  },
61
165
  });
62
166
  }
167
+ /** The address of the gateway of a Ta in the cloud kept, as the account service it is. */
168
+ static gatewayOf(host) {
169
+ return 'token' in host.credential && host.credential.url ? host.credential.url.replace(/\/+$/, '') : undefined;
170
+ }
171
+ /** The computers the account brought: those it paired, and the Ta in the cloud of its gateway (a company's account). */
172
+ ownHosts() {
173
+ var _a;
174
+ const service = (_a = this.agent) === null || _a === void 0 ? void 0 : _a.state.service;
175
+ return this.hosts.state.hosts.filter(one => one.account || (service !== undefined && DeviceAccount.gatewayOf(one) === service));
176
+ }
177
+ /** The accounts switched away from, the latest first. */
178
+ static recent() {
179
+ var _a;
180
+ var _b;
181
+ try {
182
+ const kept = JSON.parse((_b = (_a = (0, workbench_util_1.storage)()) === null || _a === void 0 ? void 0 : _a.getItem(RECENT_KEY)) !== null && _b !== void 0 ? _b : '[]');
183
+ return Array.isArray(kept) ? kept.filter(one => { var _a, _b; return ((_a = one === null || one === void 0 ? void 0 : one.kept) === null || _a === void 0 ? void 0 : _a.token) && ((_b = one.kept.self) === null || _b === void 0 ? void 0 : _b.signKey); }) : [];
184
+ }
185
+ catch (_c) {
186
+ return [];
187
+ }
188
+ }
189
+ static keepRecent(recent) {
190
+ var _a;
191
+ try {
192
+ (_a = (0, workbench_util_1.storage)()) === null || _a === void 0 ? void 0 : _a.setItem(RECENT_KEY, JSON.stringify(recent.slice(0, MAX_RECENT)));
193
+ }
194
+ catch (_b) {
195
+ // Full: not offered again.
196
+ }
197
+ }
198
+ /** The account in use put aside, its computers with it, for another (WeChat's switching of accounts). */
199
+ putAside() {
200
+ var _a, _b;
201
+ if (!this.agent) {
202
+ return;
203
+ }
204
+ const kept = this.agent.state;
205
+ const hosts = this.hosts.parkHosts(this.ownHosts().map(one => one.id));
206
+ DeviceAccount.keepRecent([{ kept, hosts, at: Date.now() }, ...DeviceAccount.recent().filter(one => one.kept.account.id !== kept.account.id)]);
207
+ (_a = (0, workbench_util_1.storage)()) === null || _a === void 0 ? void 0 : _a.removeItem(KEY);
208
+ (_b = (0, workbench_util_1.storage)()) === null || _b === void 0 ? void 0 : _b.setItem(OFF_KEY, '1');
209
+ this.agent = undefined;
210
+ this.view = undefined;
211
+ this.error = undefined;
212
+ }
213
+ /** Back to the sign-in, the account in use kept among those signed in to lately. */
214
+ switchAccount() {
215
+ this.putAside();
216
+ this.hosts.switchSignIn();
217
+ }
218
+ /** An account switched away from, in use again, with its computers: the one of them used last opens. */
219
+ resume(account) {
220
+ var _a, _b;
221
+ const record = DeviceAccount.recent().find(one => one.kept.account.id === account);
222
+ if (!record) {
223
+ return;
224
+ }
225
+ this.putAside();
226
+ DeviceAccount.keepRecent(DeviceAccount.recent().filter(one => one.kept.account.id !== account));
227
+ this.hosts.restoreHosts(record.hosts);
228
+ (_a = (0, workbench_util_1.storage)()) === null || _a === void 0 ? void 0 : _a.setItem(KEY, JSON.stringify(record.kept));
229
+ (_b = (0, workbench_util_1.storage)()) === null || _b === void 0 ? void 0 : _b.removeItem(OFF_KEY);
230
+ this.agent = this.agentOf(record.kept);
231
+ this.schedule(0);
232
+ const latest = [...record.hosts].sort((a, b) => b.usedAt - a.usedAt)[0];
233
+ if (latest) {
234
+ this.hosts.switchTo(latest.id);
235
+ }
236
+ }
237
+ /** An account switched away from, no longer offered. */
238
+ forgetRecent(account) {
239
+ DeviceAccount.keepRecent(DeviceAccount.recent().filter(one => one.kept.account.id !== account));
240
+ }
241
+ /**
242
+ * Signed in to a Ta in the cloud: its gateway's account is this device's from now on, one account at a time
243
+ * (docs/design/ta-me.md 2); another in use is put aside, to come back to.
244
+ */
245
+ cloudSignedIn(gateway) {
246
+ var _a;
247
+ const service = gateway.replace(/\/+$/, '');
248
+ if (this.agent && this.agent.state.service !== service) {
249
+ this.putAside();
250
+ }
251
+ (_a = (0, workbench_util_1.storage)()) === null || _a === void 0 ? void 0 : _a.removeItem(OFF_KEY);
252
+ this.schedule(0);
253
+ }
63
254
  /** A Ta in the cloud signed in to: its token is the account of its gateway, which this device joins by itself. */
64
255
  cloudToken() {
65
- for (const host of this.hosts.state.hosts) {
66
- if ('token' in host.credential && host.credential.url) {
67
- return { service: host.credential.url.replace(/\/+$/, ''), token: host.credential.token };
68
- }
69
- }
70
- return undefined;
256
+ const host = [...this.hosts.state.hosts].sort((a, b) => b.usedAt - a.usedAt).find(one => DeviceAccount.gatewayOf(one));
257
+ return host && 'token' in host.credential ? { service: DeviceAccount.gatewayOf(host), token: host.credential.token } : undefined;
71
258
  }
72
259
  /** Joins the account of the gateway of a Ta in the cloud of this device, unless the user left the account. */
73
260
  async adopt() {
@@ -83,6 +270,10 @@ class DeviceAccount {
83
270
  }
84
271
  forget() {
85
272
  var _a;
273
+ // The Ta in the cloud of a company's account goes with it, as the computers it paired.
274
+ for (const host of this.ownHosts().filter(one => !one.account)) {
275
+ this.hosts.forget(host.id);
276
+ }
86
277
  (_a = (0, workbench_util_1.storage)()) === null || _a === void 0 ? void 0 : _a.removeItem(KEY);
87
278
  this.agent = undefined;
88
279
  this.view = undefined;
@@ -106,7 +297,12 @@ class DeviceAccount {
106
297
  else if (this.agent || (await this.adopt())) {
107
298
  const agent = this.agent;
108
299
  this.view = await agent.sync();
300
+ if (!this.view.waiting) {
301
+ this.bringCloud();
302
+ this.view = await this.letInBrought(this.view);
303
+ }
109
304
  this.error = undefined;
305
+ void this.bringPending();
110
306
  if (this.view.waiting || this.view.devices.some(one => one.waiting)) {
111
307
  next = WAITING_SYNC_MS;
112
308
  }
@@ -145,6 +341,10 @@ class DeviceAccount {
145
341
  (_b = (0, workbench_util_1.storage)()) === null || _b === void 0 ? void 0 : _b.removeItem(OFF_KEY);
146
342
  this.agent = this.agentOf(kept);
147
343
  this.view = await this.agent.sync();
344
+ // The computers connected by their code before join it too, each once it is used.
345
+ const joining = DeviceAccount.joining();
346
+ const scanned = this.hosts.state.hosts.filter(one => 'pairing' in one.credential && !one.account).map(one => one.id);
347
+ DeviceAccount.keepJoining({ ...joining, hosts: [...new Set([...joining.hosts, ...scanned])] });
148
348
  return WAITING_SYNC_MS;
149
349
  }
150
350
  async read() {
@@ -43,6 +43,7 @@ const connection_bar_1 = require("../components/connection-bar");
43
43
  const side_lists_1 = require("../components/side-lists");
44
44
  const use_seen_chats_1 = require("../components/use-seen-chats");
45
45
  const web_extension_protocol_1 = require("../extension/web-extension-protocol");
46
+ const web_home_1 = require("../extension/web-home");
46
47
  const web_tasks_1 = require("../extension/web-tasks");
47
48
  const hooks_1 = require("../hooks");
48
49
  const use_t_1 = require("../i18n/use-t");
@@ -84,7 +85,7 @@ function useChatHome(onPicked) {
84
85
  latest.current = onPicked;
85
86
  const name = view ? web_extension_protocol_1.WebLabelUtil.text(view.title) : t('ta.builtin.assistant');
86
87
  const shown = extensions.page === side_lists_1.DOUBLE_PAGE;
87
- const shownItem = extensions.page && !extensions.pageHidden ? extensions.pageFrom : undefined;
88
+ const shownItem = web_home_1.WebHomeUtil.shown(extensions);
88
89
  return React.useMemo(() => {
89
90
  if (listed) {
90
91
  return undefined;
@@ -0,0 +1,56 @@
1
+ /** Listens heard nothing this many times in a row, and for SILENT_MS: nobody is there, the call ends. */
2
+ export declare const SILENT_ROUNDS = 4;
3
+ /**
4
+ * How long nobody spoke, the user nor Ta, before the call ends by itself: a recognizer ends a listen after a few
5
+ * seconds of silence, and a user who waits for the work to answer is still there.
6
+ */
7
+ export declare const SILENT_MS: number;
8
+ /** After a failure of the recognizer (not a denial), before it listens again. */
9
+ export declare const RETRY_MS = 600;
10
+ /**
11
+ * The words heard stay the same this long: the user is done, though the recognizer goes on (it hears voices around them
12
+ * and waits for a silence that never comes).
13
+ */
14
+ export declare const END_MS = 1300;
15
+ /**
16
+ * What was heard holds sounds alone ("哎", "嗯", "那个", TurnEnd.sounds): Ta waits this long without new words before it
17
+ * takes the user to be done, and what they say meanwhile, in this listen or the next, goes with it as one sentence. Then
18
+ * a hesitation is dropped and a backchannel ("嗯", "好好", an answer maybe) goes as said.
19
+ */
20
+ export declare const FILLER_MS = 3000;
21
+ /** At most this long a turn, from the first words: talk around the user that keeps the words coming ends there too. */
22
+ export declare const TURN_MS = 15000;
23
+ /** How long a call waits for the user, as CallOptions says. */
24
+ export interface CallTurnTimes {
25
+ /** How long the words heard stay the same before the user is taken to be done; default END_MS. */
26
+ endMs?: number;
27
+ /** How long sounds alone ("哎", "嗯", "那个") wait for words to follow; default FILLER_MS. */
28
+ fillerMs?: number;
29
+ /** How long the user may speak in one turn; default TURN_MS. */
30
+ turnMs?: number;
31
+ }
32
+ /**
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
34
+ * 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.
36
+ */
37
+ export declare class CallTurnEnd {
38
+ protected readonly times: CallTurnTimes;
39
+ protected readonly done: () => void;
40
+ protected endTimer?: ReturnType<typeof setTimeout>;
41
+ protected turnTimer?: ReturnType<typeof setTimeout>;
42
+ /** When the words heard last changed: sounds alone wait FILLER_MS from it, over listens. */
43
+ protected wordsAt: number;
44
+ constructor(times: CallTurnTimes, done: () => void);
45
+ /** The words heard are `text` now. */
46
+ heard(text: string): void;
47
+ /** A listen goes on from sounds alone the one before ended on: done once they waited FILLER_MS, unless words come. */
48
+ hold(): void;
49
+ /** `said` is sounds alone that did not wait FILLER_MS yet: they wait on for words. */
50
+ waits(said: string): boolean;
51
+ stop(): void;
52
+ protected get fillerMs(): number;
53
+ /** How long the words heard should stay the same before the user is taken to be done. */
54
+ protected waitMs(text: string): number;
55
+ }
56
+ //# sourceMappingURL=call-turn-end.d.ts.map
@@ -0,0 +1,72 @@
1
+ "use strict";
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;
4
+ const turn_end_1 = require("../util/turn-end");
5
+ /** Listens heard nothing this many times in a row, and for SILENT_MS: nobody is there, the call ends. */
6
+ exports.SILENT_ROUNDS = 4;
7
+ /**
8
+ * How long nobody spoke, the user nor Ta, before the call ends by itself: a recognizer ends a listen after a few
9
+ * seconds of silence, and a user who waits for the work to answer is still there.
10
+ */
11
+ exports.SILENT_MS = 3 * 60000;
12
+ /** After a failure of the recognizer (not a denial), before it listens again. */
13
+ exports.RETRY_MS = 600;
14
+ /**
15
+ * The words heard stay the same this long: the user is done, though the recognizer goes on (it hears voices around them
16
+ * and waits for a silence that never comes).
17
+ */
18
+ exports.END_MS = 1300;
19
+ /**
20
+ * What was heard holds sounds alone ("哎", "嗯", "那个", TurnEnd.sounds): Ta waits this long without new words before it
21
+ * takes the user to be done, and what they say meanwhile, in this listen or the next, goes with it as one sentence. Then
22
+ * a hesitation is dropped and a backchannel ("嗯", "好好", an answer maybe) goes as said.
23
+ */
24
+ exports.FILLER_MS = 3000;
25
+ /** At most this long a turn, from the first words: talk around the user that keeps the words coming ends there too. */
26
+ exports.TURN_MS = 15000;
27
+ /**
28
+ * 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
+ * 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.
31
+ */
32
+ class CallTurnEnd {
33
+ constructor(times, done) {
34
+ this.times = times;
35
+ this.done = done;
36
+ /** When the words heard last changed: sounds alone wait FILLER_MS from it, over listens. */
37
+ this.wordsAt = 0;
38
+ }
39
+ /** The words heard are `text` now. */
40
+ heard(text) {
41
+ var _a, _b;
42
+ this.wordsAt = Date.now();
43
+ clearTimeout(this.endTimer);
44
+ this.endTimer = setTimeout(this.done, this.waitMs(text));
45
+ (_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));
46
+ }
47
+ /** A listen goes on from sounds alone the one before ended on: done once they waited FILLER_MS, unless words come. */
48
+ hold() {
49
+ clearTimeout(this.endTimer);
50
+ this.endTimer = setTimeout(this.done, Math.max(0, this.fillerMs - (Date.now() - this.wordsAt)));
51
+ }
52
+ /** `said` is sounds alone that did not wait FILLER_MS yet: they wait on for words. */
53
+ waits(said) {
54
+ return !!turn_end_1.TurnEnd.sounds(said) && Date.now() - this.wordsAt < this.fillerMs;
55
+ }
56
+ stop() {
57
+ clearTimeout(this.endTimer);
58
+ clearTimeout(this.turnTimer);
59
+ this.endTimer = this.turnTimer = undefined;
60
+ }
61
+ get fillerMs() {
62
+ var _a;
63
+ return (_a = this.times.fillerMs) !== null && _a !== void 0 ? _a : exports.FILLER_MS;
64
+ }
65
+ /** How long the words heard should stay the same before the user is taken to be done. */
66
+ waitMs(text) {
67
+ var _a;
68
+ return turn_end_1.TurnEnd.sounds(text) ? this.fillerMs : turn_end_1.TurnEnd.waitMs(text, (_a = this.times.endMs) !== null && _a !== void 0 ? _a : exports.END_MS);
69
+ }
70
+ }
71
+ exports.CallTurnEnd = CallTurnEnd;
72
+ //# sourceMappingURL=call-turn-end.js.map
@@ -273,11 +273,11 @@ class RealtimeVoice {
273
273
  const text = turn_end_1.TurnEnd.join((_d = hearing.before) !== null && _d !== void 0 ? _d : '', event.text);
274
274
  hearing.onText(text, event.final);
275
275
  if (event.final) {
276
- // A sentence the service ended on a word that leads on ("然后", "and"): the user is still to say
277
- // more, and the call waits for it, as long as TurnEnd.waitMs says.
276
+ // A sentence the service ended on a word that leads on ("然后", "and"), or on sounds alone ("哎",
277
+ // "嗯"): the user is still to say more, and the call waits for it, as long as it says (waitMs).
278
278
  // Nor one the user's voice went on from, a short pause (TaBargeIn.joinMs) ago at most.
279
279
  const goesOn = this.clock - this.voiceAt <= this.barge.joinMs;
280
- if (event.text.trim() && !turn_end_1.TurnEnd.hesitates(text) && !goesOn) {
280
+ if (event.text.trim() && !turn_end_1.TurnEnd.hesitates(text) && !turn_end_1.TurnEnd.sounds(text) && !goesOn) {
281
281
  this.endHearing();
282
282
  hearing.onEnd();
283
283
  }
@@ -1,4 +1,5 @@
1
1
  import { Voice } from '../util/voice';
2
+ import { CallTurnEnd, type CallTurnTimes } from './call-turn-end';
2
3
  import { VoiceReopen } from './voice-reopen';
3
4
  /** Where a call is: Ta listens to the user, works on what they said, or says its answer. */
4
5
  export type CallPhase = 'connecting' | 'listening' | 'thinking' | 'speaking';
@@ -50,7 +51,7 @@ export interface CallPartner {
50
51
  }
51
52
  /** Why a call ended by itself. */
52
53
  export type CallEnd = 'silent' | 'denied' | 'unavailable' | 'failed';
53
- export interface CallOptions {
54
+ export interface CallOptions extends CallTurnTimes {
54
55
  language(): string;
55
56
  voice(): string | undefined;
56
57
  /** Sends what the user said to the conversation. */
@@ -61,27 +62,9 @@ export interface CallOptions {
61
62
  openVoice?(): Promise<CallVoice | undefined> | undefined;
62
63
  /** Who answers in its place, opened as the call starts; undefined (or failing) for the conversation itself. */
63
64
  openPartner?(): Promise<CallPartner | undefined> | undefined;
64
- /** How long the words heard stay the same before the user is taken to be done; default END_MS. */
65
- endMs?: number;
66
- /** How long the user may speak in one turn; default TURN_MS. */
67
- turnMs?: number;
68
65
  /** How long nobody may speak before the call ends by itself; default SILENT_MS. */
69
66
  silentMs?: number;
70
67
  }
71
- /** Listens heard nothing this many times in a row, and for SILENT_MS: nobody is there, the call ends. */
72
- export declare const SILENT_ROUNDS = 4;
73
- /**
74
- * How long nobody spoke, the user nor Ta, before the call ends by itself: a recognizer ends a listen after a few
75
- * seconds of silence, and a user who waits for the work to answer is still there.
76
- */
77
- export declare const SILENT_MS: number;
78
- /**
79
- * The words heard stay the same this long: the user is done, though the recognizer goes on (it hears voices around them
80
- * and waits for a silence that never comes).
81
- */
82
- export declare const END_MS = 1300;
83
- /** At most this long a turn, from the first words: talk around the user that keeps the words coming ends there too. */
84
- export declare const TURN_MS = 15000;
85
68
  /**
86
69
  * 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
87
70
  * its answer out, then listens again, until the user hangs up or says nothing for a while. With the voice of the device
@@ -100,9 +83,8 @@ export declare class VoiceCall {
100
83
  /** When someone last spoke (the user, or Ta): the silence that ends the call counts from it. */
101
84
  protected spoke: number;
102
85
  protected retry?: ReturnType<typeof setTimeout>;
103
- /** The user is done when it fires (END_MS), and at the latest when the other does (TURN_MS). */
104
- protected endTimer?: ReturnType<typeof setTimeout>;
105
- protected turnTimer?: ReturnType<typeof setTimeout>;
86
+ /** When the user is done with what they say. */
87
+ protected readonly turnEnd: CallTurnEnd;
106
88
  /** An answer that came while paused: read once the page shows again. */
107
89
  protected pending?: string;
108
90
  /** The voice of this call: the device's, or a service's opened as it started. */
@@ -181,15 +163,24 @@ export declare class VoiceCall {
181
163
  /** What is being read now, to read again after a pause. */
182
164
  protected speaking?: string;
183
165
  protected read(said: string): void;
184
- /** Listens; first says what waits to be said, unless the user just cut in to speak (`announce` false). */
185
- protected listen(announce?: boolean): void;
186
166
  /**
187
- * The user is done speaking (a pause after their words, or the mark of the bar tapped): what was heard goes now,
188
- * the recognizer stopped, whatever it would still hear.
167
+ * Listens; first says what waits to be said, unless the user just cut in to speak (`announce` false). `held`: sounds
168
+ * alone a listen ended on, which what is heard now follows, gone or sent once it waited FILLER_MS for words.
189
169
  */
170
+ protected listen(announce?: boolean, held?: string): void;
171
+ /** The user says they are done (the mark of the bar tapped): what was heard goes now as it is, sounds alone too. */
190
172
  endTurn(): void;
191
- /** A listen ended: what was said goes to the double; nothing, Ta listens again, a few times. */
192
- protected heard(said: string, error: string | undefined): void;
173
+ /** The words heard stayed the same a while, or the turn is at its longest (CallTurnEnd): the user is done. */
174
+ protected quiet(): void;
175
+ /** What was heard of a listen going on, while Ta listens; undefined else. */
176
+ protected listened(): string | undefined;
177
+ /**
178
+ * A listen ended: what was said goes to the double; nothing, Ta listens again, a few times. Sounds alone wait on in
179
+ * the next listen until they waited FILLER_MS (`waited`); then a hesitation is dropped and a backchannel goes.
180
+ */
181
+ protected heard(said: string, error: string | undefined, waited?: boolean): void;
182
+ /** What the user said goes to the partner, or to the conversation. */
183
+ protected take(said: string): void;
193
184
  /** The voice and the partner the call opens as it starts; undefined when it opens neither. A partner that fails is none. */
194
185
  protected open(direct: boolean): Promise<[CallVoice | undefined, CallPartner | undefined]> | undefined;
195
186
  /** The partner answers what the user said; its reply is read as a turn's is. */