@celljs/ta-web 4.20.0 → 4.22.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 (153) 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 +5 -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 -22
  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/chat-home-util.d.ts +13 -2
  14. package/esm/browser/components/chat-home-util.js +29 -0
  15. package/esm/browser/components/chat-home.d.ts +16 -4
  16. package/esm/browser/components/chat-home.js +9 -2
  17. package/esm/browser/components/chat-list.js +4 -2
  18. package/esm/browser/components/cloud-sign-in-view.d.ts +1 -1
  19. package/esm/browser/components/cloud-sign-in-view.js +4 -1
  20. package/esm/browser/components/host-view.d.ts +15 -8
  21. package/esm/browser/components/host-view.js +23 -70
  22. package/esm/browser/components/me-view.d.ts +2 -2
  23. package/esm/browser/components/me-view.js +7 -6
  24. package/esm/browser/components/partner-row.d.ts +17 -0
  25. package/esm/browser/components/partner-row.js +48 -0
  26. package/esm/browser/components/profile-view.d.ts +11 -0
  27. package/esm/browser/components/profile-view.js +85 -0
  28. package/esm/browser/components/workbench-view.js +42 -7
  29. package/esm/browser/extension/web-api-components.d.ts +2 -2
  30. package/esm/browser/extension/web-api-home.d.ts +1 -0
  31. package/esm/browser/extension/web-api-partners.d.ts +95 -0
  32. package/esm/browser/extension/web-api-partners.js +2 -0
  33. package/esm/browser/extension/web-extension-api.d.ts +3 -3
  34. package/esm/browser/extension/web-extension-context.js +2 -2
  35. package/esm/browser/extension/web-extension-protocol.d.ts +8 -2
  36. package/esm/browser/extension/web-extension-run.d.ts +2 -1
  37. package/esm/browser/extension/web-extension-run.js +1 -0
  38. package/esm/browser/extension/web-extensions-running.d.ts +2 -0
  39. package/esm/browser/extension/web-extensions-running.js +3 -0
  40. package/esm/browser/extension/web-extensions.d.ts +1 -1
  41. package/esm/browser/extension/web-home.d.ts +11 -19
  42. package/esm/browser/extension/web-home.js +15 -68
  43. package/esm/browser/extension/web-partners.d.ts +8 -0
  44. package/esm/browser/extension/web-partners.js +13 -0
  45. package/esm/browser/extension/web-row-board.d.ts +38 -0
  46. package/esm/browser/extension/web-row-board.js +79 -0
  47. package/esm/browser/i18n/locales.d.ts +31 -1
  48. package/esm/browser/i18n/messages-ja.js +34 -4
  49. package/esm/browser/i18n/messages-zh-tw.js +34 -4
  50. package/esm/browser/i18n/messages.d.ts +30 -0
  51. package/esm/browser/i18n/messages.js +68 -8
  52. package/esm/browser/index.d.ts +4 -0
  53. package/esm/browser/index.js +4 -0
  54. package/esm/browser/partners/group-picker.d.ts +18 -0
  55. package/esm/browser/partners/group-picker.js +81 -0
  56. package/esm/browser/partners/partners-extension.d.ts +14 -0
  57. package/esm/browser/partners/partners-extension.js +61 -0
  58. package/esm/browser/partners/partners-util.d.ts +32 -0
  59. package/esm/browser/partners/partners-util.js +68 -0
  60. package/esm/browser/partners/partners-view.d.ts +32 -0
  61. package/esm/browser/partners/partners-view.js +103 -0
  62. package/esm/browser/style/chat-list.d.ts +1 -1
  63. package/esm/browser/style/chat-list.js +18 -0
  64. package/esm/browser/style/conversation-column.d.ts +1 -1
  65. package/esm/browser/style/conversation-column.js +2 -1
  66. package/esm/browser/style/dialogs.d.ts +1 -1
  67. package/esm/browser/style/dialogs.js +6 -0
  68. package/esm/browser/style/layout.d.ts +1 -1
  69. package/esm/browser/style/layout.js +1 -1
  70. package/esm/browser/style/pages.d.ts +1 -1
  71. package/esm/browser/style/pages.js +6 -0
  72. package/esm/browser/util/turn-end.d.ts +8 -0
  73. package/esm/browser/util/turn-end.js +78 -35
  74. package/esm/browser/workbench-hosts.d.ts +4 -1
  75. package/esm/browser/workbench-hosts.js +17 -0
  76. package/esm/browser/workbench-protocol.d.ts +8 -0
  77. package/lib/browser/account/device-account.d.ts +65 -1
  78. package/lib/browser/account/device-account.js +206 -6
  79. package/lib/browser/assistant/assistant-chat-list.js +5 -1
  80. package/lib/browser/assistant/call-turn-end.d.ts +56 -0
  81. package/lib/browser/assistant/call-turn-end.js +72 -0
  82. package/lib/browser/assistant/realtime-voice.js +3 -3
  83. package/lib/browser/assistant/voice-call.d.ts +19 -28
  84. package/lib/browser/assistant/voice-call.js +67 -54
  85. package/lib/browser/components/account-menu.d.ts +9 -4
  86. package/lib/browser/components/account-menu.js +57 -20
  87. package/lib/browser/components/account-view.d.ts +33 -7
  88. package/lib/browser/components/account-view.js +142 -77
  89. package/lib/browser/components/chat-home-util.d.ts +13 -2
  90. package/lib/browser/components/chat-home-util.js +29 -0
  91. package/lib/browser/components/chat-home.d.ts +16 -4
  92. package/lib/browser/components/chat-home.js +9 -1
  93. package/lib/browser/components/chat-list.js +4 -2
  94. package/lib/browser/components/cloud-sign-in-view.d.ts +1 -1
  95. package/lib/browser/components/cloud-sign-in-view.js +4 -1
  96. package/lib/browser/components/host-view.d.ts +15 -8
  97. package/lib/browser/components/host-view.js +22 -68
  98. package/lib/browser/components/me-view.d.ts +2 -2
  99. package/lib/browser/components/me-view.js +7 -6
  100. package/lib/browser/components/partner-row.d.ts +18 -0
  101. package/lib/browser/components/partner-row.js +84 -0
  102. package/lib/browser/components/profile-view.d.ts +12 -0
  103. package/lib/browser/components/profile-view.js +123 -0
  104. package/lib/browser/components/workbench-view.js +39 -4
  105. package/lib/browser/extension/web-api-components.d.ts +2 -2
  106. package/lib/browser/extension/web-api-home.d.ts +1 -0
  107. package/lib/browser/extension/web-api-partners.d.ts +96 -0
  108. package/lib/browser/extension/web-api-partners.js +3 -0
  109. package/lib/browser/extension/web-extension-api.d.ts +3 -3
  110. package/lib/browser/extension/web-extension-context.js +2 -2
  111. package/lib/browser/extension/web-extension-protocol.d.ts +8 -2
  112. package/lib/browser/extension/web-extension-run.d.ts +2 -1
  113. package/lib/browser/extension/web-extension-run.js +1 -0
  114. package/lib/browser/extension/web-extensions-running.d.ts +2 -0
  115. package/lib/browser/extension/web-extensions-running.js +3 -0
  116. package/lib/browser/extension/web-extensions.d.ts +1 -1
  117. package/lib/browser/extension/web-home.d.ts +11 -19
  118. package/lib/browser/extension/web-home.js +15 -68
  119. package/lib/browser/extension/web-partners.d.ts +9 -0
  120. package/lib/browser/extension/web-partners.js +17 -0
  121. package/lib/browser/extension/web-row-board.d.ts +39 -0
  122. package/lib/browser/extension/web-row-board.js +83 -0
  123. package/lib/browser/i18n/locales.d.ts +31 -1
  124. package/lib/browser/i18n/messages-ja.js +34 -4
  125. package/lib/browser/i18n/messages-zh-tw.js +34 -4
  126. package/lib/browser/i18n/messages.d.ts +30 -0
  127. package/lib/browser/i18n/messages.js +68 -8
  128. package/lib/browser/index.d.ts +4 -0
  129. package/lib/browser/index.js +4 -0
  130. package/lib/browser/partners/group-picker.d.ts +19 -0
  131. package/lib/browser/partners/group-picker.js +119 -0
  132. package/lib/browser/partners/partners-extension.d.ts +15 -0
  133. package/lib/browser/partners/partners-extension.js +97 -0
  134. package/lib/browser/partners/partners-util.d.ts +33 -0
  135. package/lib/browser/partners/partners-util.js +71 -0
  136. package/lib/browser/partners/partners-view.d.ts +33 -0
  137. package/lib/browser/partners/partners-view.js +144 -0
  138. package/lib/browser/style/chat-list.d.ts +1 -1
  139. package/lib/browser/style/chat-list.js +18 -0
  140. package/lib/browser/style/conversation-column.d.ts +1 -1
  141. package/lib/browser/style/conversation-column.js +2 -1
  142. package/lib/browser/style/dialogs.d.ts +1 -1
  143. package/lib/browser/style/dialogs.js +6 -0
  144. package/lib/browser/style/layout.d.ts +1 -1
  145. package/lib/browser/style/layout.js +1 -1
  146. package/lib/browser/style/pages.d.ts +1 -1
  147. package/lib/browser/style/pages.js +6 -0
  148. package/lib/browser/util/turn-end.d.ts +8 -0
  149. package/lib/browser/util/turn-end.js +78 -35
  150. package/lib/browser/workbench-hosts.d.ts +4 -1
  151. package/lib/browser/workbench-hosts.js +17 -0
  152. package/lib/browser/workbench-protocol.d.ts +8 -0
  153. package/package.json +7 -7
@@ -1,4 +1,4 @@
1
- import type { TaAccountInfo } from '@celljs/ta-protocol';
1
+ import type { TaAccountInfo, TaAccountServer } from '@celljs/ta-protocol';
2
2
  import { AccountAgent, type AccountKept, type AccountView, type AccountWay } from '@celljs/ta-relay';
3
3
  import type { SavedHost } from '../workbench-protocol.js';
4
4
  /** What a page does about the account: of its ta serve (a computer), or of the device itself (the app). */
@@ -14,9 +14,27 @@ export interface AccountSide {
14
14
  export interface AccountHosts {
15
15
  readonly state: {
16
16
  hosts: SavedHost[];
17
+ host?: string;
18
+ status: string;
19
+ switching?: string;
17
20
  };
21
+ /** The account of the computer in use, through its ta serve. */
22
+ readonly account: TaAccountServer;
23
+ subscribe(listener: () => void): () => void;
18
24
  addAccountHost(link: string, account: string): Promise<void>;
19
25
  forgetAccountHosts(account?: string): void;
26
+ markAccountHost(hostId: string, account: string): void;
27
+ forget(hostId: string): void;
28
+ switchTo(hostId: string): void;
29
+ parkHosts(ids: string[]): SavedHost[];
30
+ restoreHosts(hosts: SavedHost[]): void;
31
+ switchSignIn(): void;
32
+ }
33
+ /** An account this device switched away from (docs/design/ta-me.md 4): back in one tap, with its computers. */
34
+ export interface RecentAccount {
35
+ kept: AccountKept;
36
+ hosts: SavedHost[];
37
+ at: number;
20
38
  }
21
39
  /**
22
40
  * The app as a device of the user's account (docs/design/ta-account.md): its own keys in localStorage; the computers
@@ -42,12 +60,58 @@ export declare class DeviceAccount implements AccountSide {
42
60
  protected timer?: ReturnType<typeof setTimeout>;
43
61
  protected running?: Promise<void>;
44
62
  protected constructor(hosts: AccountHosts, service: () => Promise<string>, gateways: () => Promise<string[]>);
63
+ /** The computers to bring into the account, and the devices of it this device lets in once they ask. */
64
+ protected static joining(): {
65
+ hosts: string[];
66
+ devices: string[];
67
+ };
68
+ protected static keepJoining(next: {
69
+ hosts: string[];
70
+ devices: string[];
71
+ }): void;
72
+ /**
73
+ * A computer connected by its code while this device is in an account (docs/design/ta-me.md 4): it joins the account
74
+ * once connected, with a token of the account this device gets for it, and this device lets it in. Being by the
75
+ * computer to scan its code is as good as tapping Allow.
76
+ */
77
+ bringIn(hostId: string): void;
78
+ protected bringing: boolean;
79
+ /** The computers tried once in this page: one that would not join is not asked again every round. */
80
+ protected readonly tried: Set<string>;
81
+ /** 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. */
82
+ protected bringCloud(): void;
83
+ /** The computer in use, if it waits to be brought into the account: asked to join it. */
84
+ protected bringPending(): Promise<void>;
85
+ /** The computers this device brought in, let in as soon as they ask. */
86
+ protected letInBrought(view: AccountView): Promise<AccountView>;
87
+ /** The one of the page, once made. */
88
+ static current(): DeviceAccount | undefined;
45
89
  /** The one of the page. */
46
90
  static of(hosts: AccountHosts, service: () => Promise<string>, gateways: () => Promise<string[]>): DeviceAccount;
47
91
  /** What the device calls itself in the account. */
48
92
  static deviceName(agent?: string): string;
49
93
  protected static read(): AccountKept | undefined;
50
94
  protected agentOf(kept: AccountKept): AccountAgent;
95
+ /** The address of the gateway of a Ta in the cloud kept, as the account service it is. */
96
+ protected static gatewayOf(host: SavedHost): string | undefined;
97
+ /** The computers the account brought: those it paired, and the Ta in the cloud of its gateway (a company's account). */
98
+ protected ownHosts(): SavedHost[];
99
+ /** The accounts switched away from, the latest first. */
100
+ static recent(): RecentAccount[];
101
+ protected static keepRecent(recent: RecentAccount[]): void;
102
+ /** The account in use put aside, its computers with it, for another (WeChat's switching of accounts). */
103
+ protected putAside(): void;
104
+ /** Back to the sign-in, the account in use kept among those signed in to lately. */
105
+ switchAccount(): void;
106
+ /** An account switched away from, in use again, with its computers: the one of them used last opens. */
107
+ resume(account: string): void;
108
+ /** An account switched away from, no longer offered. */
109
+ forgetRecent(account: string): void;
110
+ /**
111
+ * Signed in to a Ta in the cloud: its gateway's account is this device's from now on, one account at a time
112
+ * (docs/design/ta-me.md 2); another in use is put aside, to come back to.
113
+ */
114
+ cloudSignedIn(gateway: string): void;
51
115
  /** A Ta in the cloud signed in to: its token is the account of its gateway, which this device joins by itself. */
52
116
  protected cloudToken(): {
53
117
  service: string;
@@ -3,6 +3,11 @@ import { storage } from '../workbench-util.js';
3
3
  const KEY = 'ta.account';
4
4
  /** Signed out of the account by the user: not signed in again by itself with the token of a Ta in the cloud. */
5
5
  const OFF_KEY = 'ta.account.off';
6
+ /** The accounts switched away from, the latest first. */
7
+ const RECENT_KEY = 'ta.account.recent';
8
+ const MAX_RECENT = 5;
9
+ /** The computers connected by their code while signed in, to bring into the account once connected: by host id. */
10
+ const JOINING_KEY = 'ta.account.joining';
6
11
  const SYNC_MS = 15000;
7
12
  const WAITING_SYNC_MS = 3000;
8
13
  /**
@@ -15,12 +20,111 @@ export class DeviceAccount {
15
20
  this.hosts = hosts;
16
21
  this.service = service;
17
22
  this.gateways = gateways;
23
+ this.bringing = false;
24
+ /** The computers tried once in this page: one that would not join is not asked again every round. */
25
+ this.tried = new Set();
18
26
  const kept = DeviceAccount.read();
19
27
  if (kept) {
20
28
  this.agent = this.agentOf(kept);
21
29
  }
22
30
  this.schedule(0);
23
31
  document.addEventListener('visibilitychange', () => document.visibilityState === 'visible' && this.schedule(0));
32
+ hosts.subscribe(() => void this.bringPending());
33
+ }
34
+ /** The computers to bring into the account, and the devices of it this device lets in once they ask. */
35
+ static joining() {
36
+ var _a;
37
+ var _b, _c, _d;
38
+ try {
39
+ const kept = JSON.parse((_b = (_a = storage()) === null || _a === void 0 ? void 0 : _a.getItem(JOINING_KEY)) !== null && _b !== void 0 ? _b : '{}');
40
+ return { hosts: (_c = kept.hosts) !== null && _c !== void 0 ? _c : [], devices: (_d = kept.devices) !== null && _d !== void 0 ? _d : [] };
41
+ }
42
+ catch (_e) {
43
+ return { hosts: [], devices: [] };
44
+ }
45
+ }
46
+ static keepJoining(next) {
47
+ var _a;
48
+ (_a = storage()) === null || _a === void 0 ? void 0 : _a.setItem(JOINING_KEY, JSON.stringify({ hosts: next.hosts.slice(-10), devices: next.devices.slice(-10) }));
49
+ }
50
+ /**
51
+ * A computer connected by its code while this device is in an account (docs/design/ta-me.md 4): it joins the account
52
+ * once connected, with a token of the account this device gets for it, and this device lets it in. Being by the
53
+ * computer to scan its code is as good as tapping Allow.
54
+ */
55
+ bringIn(hostId) {
56
+ var _a;
57
+ 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)) {
58
+ return;
59
+ }
60
+ const joining = DeviceAccount.joining();
61
+ DeviceAccount.keepJoining({ ...joining, hosts: [...joining.hosts.filter(one => one !== hostId), hostId] });
62
+ void this.bringPending();
63
+ }
64
+ /** 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. */
65
+ bringCloud() {
66
+ var _a;
67
+ const service = (_a = this.agent) === null || _a === void 0 ? void 0 : _a.state.service;
68
+ for (const host of this.hosts.state.hosts) {
69
+ if (service && !host.account && DeviceAccount.gatewayOf(host) === service) {
70
+ this.bringIn(host.id);
71
+ }
72
+ }
73
+ }
74
+ /** The computer in use, if it waits to be brought into the account: asked to join it. */
75
+ async bringPending() {
76
+ // While switching, the connection is still of the computer before: not the one to bring in.
77
+ const { host, status, switching } = this.hosts.state;
78
+ const joining = DeviceAccount.joining();
79
+ const agent = this.agent;
80
+ if (this.bringing || switching || !agent || !host || status !== 'online' || !joining.hosts.includes(host) || !this.view || this.view.waiting) {
81
+ return;
82
+ }
83
+ this.bringing = true;
84
+ const done = (devices) => DeviceAccount.keepJoining({ hosts: joining.hosts.filter(one => one !== host), devices });
85
+ this.tried.add(host);
86
+ try {
87
+ const saved = this.hosts.state.hosts.find(one => one.id === host);
88
+ const cloud = saved !== undefined && DeviceAccount.gatewayOf(saved) !== undefined;
89
+ const { token } = await agent.invite();
90
+ const info = await this.hosts.account.joinAccount(agent.state.service, token);
91
+ const self = info.devices.find(one => one.self);
92
+ if (cloud && (self === null || self === void 0 ? void 0 : self.kind) !== 'cloud') {
93
+ // A Ta in the cloud its gateway did not say is one (a gateway of before): out again, never a computer.
94
+ await this.hosts.account.signOut();
95
+ done(joining.devices);
96
+ return;
97
+ }
98
+ if (self) {
99
+ this.hosts.markAccountHost(host, self.id);
100
+ }
101
+ done(self && info.waiting ? [...joining.devices, self.id] : joining.devices);
102
+ this.schedule(0);
103
+ }
104
+ catch (_a) {
105
+ // Signed in to another account there, a ta serve of before, or a member who may not: it stays this device's.
106
+ done(joining.devices);
107
+ }
108
+ finally {
109
+ this.bringing = false;
110
+ }
111
+ }
112
+ /** The computers this device brought in, let in as soon as they ask. */
113
+ async letInBrought(view) {
114
+ const joining = DeviceAccount.joining();
115
+ const asking = view.devices.filter(one => one.waiting && joining.devices.includes(one.id));
116
+ let next = view;
117
+ for (const device of asking) {
118
+ next = await this.agent.approve(device.id);
119
+ }
120
+ if (asking.length > 0) {
121
+ DeviceAccount.keepJoining({ ...joining, devices: joining.devices.filter(one => !asking.some(device => device.id === one)) });
122
+ }
123
+ return next;
124
+ }
125
+ /** The one of the page, once made. */
126
+ static current() {
127
+ return DeviceAccount.instance;
24
128
  }
25
129
  /** The one of the page. */
26
130
  static of(hosts, service, gateways) {
@@ -57,14 +161,97 @@ export class DeviceAccount {
57
161
  },
58
162
  });
59
163
  }
164
+ /** The address of the gateway of a Ta in the cloud kept, as the account service it is. */
165
+ static gatewayOf(host) {
166
+ return 'token' in host.credential && host.credential.url ? host.credential.url.replace(/\/+$/, '') : undefined;
167
+ }
168
+ /** The computers the account brought: those it paired, and the Ta in the cloud of its gateway (a company's account). */
169
+ ownHosts() {
170
+ var _a;
171
+ const service = (_a = this.agent) === null || _a === void 0 ? void 0 : _a.state.service;
172
+ return this.hosts.state.hosts.filter(one => one.account || (service !== undefined && DeviceAccount.gatewayOf(one) === service));
173
+ }
174
+ /** The accounts switched away from, the latest first. */
175
+ static recent() {
176
+ var _a;
177
+ var _b;
178
+ try {
179
+ const kept = JSON.parse((_b = (_a = storage()) === null || _a === void 0 ? void 0 : _a.getItem(RECENT_KEY)) !== null && _b !== void 0 ? _b : '[]');
180
+ 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); }) : [];
181
+ }
182
+ catch (_c) {
183
+ return [];
184
+ }
185
+ }
186
+ static keepRecent(recent) {
187
+ var _a;
188
+ try {
189
+ (_a = storage()) === null || _a === void 0 ? void 0 : _a.setItem(RECENT_KEY, JSON.stringify(recent.slice(0, MAX_RECENT)));
190
+ }
191
+ catch (_b) {
192
+ // Full: not offered again.
193
+ }
194
+ }
195
+ /** The account in use put aside, its computers with it, for another (WeChat's switching of accounts). */
196
+ putAside() {
197
+ var _a, _b;
198
+ if (!this.agent) {
199
+ return;
200
+ }
201
+ const kept = this.agent.state;
202
+ const hosts = this.hosts.parkHosts(this.ownHosts().map(one => one.id));
203
+ DeviceAccount.keepRecent([{ kept, hosts, at: Date.now() }, ...DeviceAccount.recent().filter(one => one.kept.account.id !== kept.account.id)]);
204
+ (_a = storage()) === null || _a === void 0 ? void 0 : _a.removeItem(KEY);
205
+ (_b = storage()) === null || _b === void 0 ? void 0 : _b.setItem(OFF_KEY, '1');
206
+ this.agent = undefined;
207
+ this.view = undefined;
208
+ this.error = undefined;
209
+ }
210
+ /** Back to the sign-in, the account in use kept among those signed in to lately. */
211
+ switchAccount() {
212
+ this.putAside();
213
+ this.hosts.switchSignIn();
214
+ }
215
+ /** An account switched away from, in use again, with its computers: the one of them used last opens. */
216
+ resume(account) {
217
+ var _a, _b;
218
+ const record = DeviceAccount.recent().find(one => one.kept.account.id === account);
219
+ if (!record) {
220
+ return;
221
+ }
222
+ this.putAside();
223
+ DeviceAccount.keepRecent(DeviceAccount.recent().filter(one => one.kept.account.id !== account));
224
+ this.hosts.restoreHosts(record.hosts);
225
+ (_a = storage()) === null || _a === void 0 ? void 0 : _a.setItem(KEY, JSON.stringify(record.kept));
226
+ (_b = storage()) === null || _b === void 0 ? void 0 : _b.removeItem(OFF_KEY);
227
+ this.agent = this.agentOf(record.kept);
228
+ this.schedule(0);
229
+ const latest = [...record.hosts].sort((a, b) => b.usedAt - a.usedAt)[0];
230
+ if (latest) {
231
+ this.hosts.switchTo(latest.id);
232
+ }
233
+ }
234
+ /** An account switched away from, no longer offered. */
235
+ forgetRecent(account) {
236
+ DeviceAccount.keepRecent(DeviceAccount.recent().filter(one => one.kept.account.id !== account));
237
+ }
238
+ /**
239
+ * Signed in to a Ta in the cloud: its gateway's account is this device's from now on, one account at a time
240
+ * (docs/design/ta-me.md 2); another in use is put aside, to come back to.
241
+ */
242
+ cloudSignedIn(gateway) {
243
+ var _a;
244
+ const service = gateway.replace(/\/+$/, '');
245
+ if (this.agent && this.agent.state.service !== service) {
246
+ this.putAside();
247
+ }
248
+ (_a = storage()) === null || _a === void 0 ? void 0 : _a.removeItem(OFF_KEY);
249
+ this.schedule(0);
250
+ }
60
251
  /** A Ta in the cloud signed in to: its token is the account of its gateway, which this device joins by itself. */
61
252
  cloudToken() {
62
- for (const host of this.hosts.state.hosts) {
63
- if ('token' in host.credential && host.credential.url) {
64
- return { service: host.credential.url.replace(/\/+$/, ''), token: host.credential.token };
65
- }
66
- }
67
- return undefined;
253
+ const host = [...this.hosts.state.hosts].sort((a, b) => b.usedAt - a.usedAt).find(one => DeviceAccount.gatewayOf(one));
254
+ return host && 'token' in host.credential ? { service: DeviceAccount.gatewayOf(host), token: host.credential.token } : undefined;
68
255
  }
69
256
  /** Joins the account of the gateway of a Ta in the cloud of this device, unless the user left the account. */
70
257
  async adopt() {
@@ -80,6 +267,10 @@ export class DeviceAccount {
80
267
  }
81
268
  forget() {
82
269
  var _a;
270
+ // The Ta in the cloud of a company's account goes with it, as the computers it paired.
271
+ for (const host of this.ownHosts().filter(one => !one.account)) {
272
+ this.hosts.forget(host.id);
273
+ }
83
274
  (_a = storage()) === null || _a === void 0 ? void 0 : _a.removeItem(KEY);
84
275
  this.agent = undefined;
85
276
  this.view = undefined;
@@ -103,7 +294,12 @@ export class DeviceAccount {
103
294
  else if (this.agent || (await this.adopt())) {
104
295
  const agent = this.agent;
105
296
  this.view = await agent.sync();
297
+ if (!this.view.waiting) {
298
+ this.bringCloud();
299
+ this.view = await this.letInBrought(this.view);
300
+ }
106
301
  this.error = undefined;
302
+ void this.bringPending();
107
303
  if (this.view.waiting || this.view.devices.some(one => one.waiting)) {
108
304
  next = WAITING_SYNC_MS;
109
305
  }
@@ -142,6 +338,10 @@ export class DeviceAccount {
142
338
  (_b = storage()) === null || _b === void 0 ? void 0 : _b.removeItem(OFF_KEY);
143
339
  this.agent = this.agentOf(kept);
144
340
  this.view = await this.agent.sync();
341
+ // The computers connected by their code before join it too, each once it is used.
342
+ const joining = DeviceAccount.joining();
343
+ const scanned = this.hosts.state.hosts.filter(one => 'pairing' in one.credential && !one.account).map(one => one.id);
344
+ DeviceAccount.keepJoining({ ...joining, hosts: [...new Set([...joining.hosts, ...scanned])] });
145
345
  return WAITING_SYNC_MS;
146
346
  }
147
347
  async read() {
@@ -10,6 +10,7 @@ import { WebHomeUtil } from '../extension/web-home.js';
10
10
  import { WebTaskUtil } from '../extension/web-tasks.js';
11
11
  import { useNotices, useWebExtensions } from '../hooks.js';
12
12
  import { useT } from '../i18n/use-t.js';
13
+ import { PartnersUtil } from '../partners/partners-util.js';
13
14
  import { TaState } from '../state/state-protocol.js';
14
15
  import { useAssistant } from './assistant-hooks.js';
15
16
  /**
@@ -36,6 +37,8 @@ function useChatHome(onPicked) {
36
37
  const listed = SideListUtil.viewListsDouble(extensions.views);
37
38
  const tasks = React.useSyncExternalStore(host.tasks.subscribe, host.tasks.tasks, host.tasks.tasks);
38
39
  const items = React.useSyncExternalStore(host.home.subscribe, host.home.items, host.home.items);
40
+ const allPartners = React.useSyncExternalStore(host.partners.subscribe, host.partners.partners, host.partners.partners);
41
+ const partners = React.useMemo(() => PartnersUtil.chats(allPartners), [allPartners]);
39
42
  // Its preview and whether it works, as one string: the same line stays the same value.
40
43
  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]);
41
44
  const read = () => {
@@ -67,6 +70,7 @@ function useChatHome(onPicked) {
67
70
  },
68
71
  },
69
72
  items,
73
+ partners,
70
74
  shownItem,
71
75
  openItem: entry => {
72
76
  latest.current();
@@ -81,7 +85,7 @@ function useChatHome(onPicked) {
81
85
  },
82
86
  remove: removed => void WebTaskUtil.remove(removed, notices, t),
83
87
  };
84
- }, [listed, line, name, shown, view, items, shownItem, tasks, host, state, notices, t]);
88
+ }, [listed, line, name, shown, view, items, partners, shownItem, tasks, host, state, notices, t]);
85
89
  }
86
90
  /** The list of chats with what the double knows of them: its tasks marked, a conversation to hand it; its home over them. */
87
91
  export function AssistantChatList(props) {
@@ -0,0 +1,55 @@
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
+ }
@@ -0,0 +1,68 @@
1
+ import { TurnEnd } from '../util/turn-end.js';
2
+ /** Listens heard nothing this many times in a row, and for SILENT_MS: nobody is there, the call ends. */
3
+ export const SILENT_ROUNDS = 4;
4
+ /**
5
+ * How long nobody spoke, the user nor Ta, before the call ends by itself: a recognizer ends a listen after a few
6
+ * seconds of silence, and a user who waits for the work to answer is still there.
7
+ */
8
+ export const SILENT_MS = 3 * 60000;
9
+ /** After a failure of the recognizer (not a denial), before it listens again. */
10
+ export const RETRY_MS = 600;
11
+ /**
12
+ * The words heard stay the same this long: the user is done, though the recognizer goes on (it hears voices around them
13
+ * and waits for a silence that never comes).
14
+ */
15
+ export const END_MS = 1300;
16
+ /**
17
+ * What was heard holds sounds alone ("哎", "嗯", "那个", TurnEnd.sounds): Ta waits this long without new words before it
18
+ * takes the user to be done, and what they say meanwhile, in this listen or the next, goes with it as one sentence. Then
19
+ * a hesitation is dropped and a backchannel ("嗯", "好好", an answer maybe) goes as said.
20
+ */
21
+ export const FILLER_MS = 3000;
22
+ /** At most this long a turn, from the first words: talk around the user that keeps the words coming ends there too. */
23
+ export const TURN_MS = 15000;
24
+ /**
25
+ * 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
+ * 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.
28
+ */
29
+ export class CallTurnEnd {
30
+ constructor(times, done) {
31
+ this.times = times;
32
+ this.done = done;
33
+ /** When the words heard last changed: sounds alone wait FILLER_MS from it, over listens. */
34
+ this.wordsAt = 0;
35
+ }
36
+ /** The words heard are `text` now. */
37
+ heard(text) {
38
+ var _a, _b;
39
+ this.wordsAt = Date.now();
40
+ clearTimeout(this.endTimer);
41
+ this.endTimer = setTimeout(this.done, this.waitMs(text));
42
+ (_a = this.turnTimer) !== null && _a !== void 0 ? _a : (this.turnTimer = setTimeout(this.done, (_b = this.times.turnMs) !== null && _b !== void 0 ? _b : TURN_MS));
43
+ }
44
+ /** A listen goes on from sounds alone the one before ended on: done once they waited FILLER_MS, unless words come. */
45
+ hold() {
46
+ clearTimeout(this.endTimer);
47
+ this.endTimer = setTimeout(this.done, Math.max(0, this.fillerMs - (Date.now() - this.wordsAt)));
48
+ }
49
+ /** `said` is sounds alone that did not wait FILLER_MS yet: they wait on for words. */
50
+ waits(said) {
51
+ return !!TurnEnd.sounds(said) && Date.now() - this.wordsAt < this.fillerMs;
52
+ }
53
+ stop() {
54
+ clearTimeout(this.endTimer);
55
+ clearTimeout(this.turnTimer);
56
+ this.endTimer = this.turnTimer = undefined;
57
+ }
58
+ get fillerMs() {
59
+ var _a;
60
+ return (_a = this.times.fillerMs) !== null && _a !== void 0 ? _a : FILLER_MS;
61
+ }
62
+ /** How long the words heard should stay the same before the user is taken to be done. */
63
+ waitMs(text) {
64
+ var _a;
65
+ return TurnEnd.sounds(text) ? this.fillerMs : TurnEnd.waitMs(text, (_a = this.times.endMs) !== null && _a !== void 0 ? _a : END_MS);
66
+ }
67
+ }
68
+ //# sourceMappingURL=call-turn-end.js.map
@@ -270,11 +270,11 @@ export class RealtimeVoice {
270
270
  const text = TurnEnd.join((_d = hearing.before) !== null && _d !== void 0 ? _d : '', event.text);
271
271
  hearing.onText(text, event.final);
272
272
  if (event.final) {
273
- // A sentence the service ended on a word that leads on ("然后", "and"): the user is still to say
274
- // more, and the call waits for it, as long as TurnEnd.waitMs says.
273
+ // A sentence the service ended on a word that leads on ("然后", "and"), or on sounds alone ("哎",
274
+ // "嗯"): the user is still to say more, and the call waits for it, as long as it says (waitMs).
275
275
  // Nor one the user's voice went on from, a short pause (TaBargeIn.joinMs) ago at most.
276
276
  const goesOn = this.clock - this.voiceAt <= this.barge.joinMs;
277
- if (event.text.trim() && !TurnEnd.hesitates(text) && !goesOn) {
277
+ if (event.text.trim() && !TurnEnd.hesitates(text) && !TurnEnd.sounds(text) && !goesOn) {
278
278
  this.endHearing();
279
279
  hearing.onEnd();
280
280
  }
@@ -1,4 +1,5 @@
1
1
  import { Voice } from '../util/voice.js';
2
+ import { CallTurnEnd, type CallTurnTimes } from './call-turn-end.js';
2
3
  import { VoiceReopen } from './voice-reopen.js';
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. */