@celljs/ta-web 4.33.0 → 4.35.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 (277) hide show
  1. package/README.en.md +1 -1
  2. package/README.md +1 -1
  3. package/esm/browser/apps/app-icon.d.ts +23 -0
  4. package/esm/browser/apps/app-icon.js +98 -0
  5. package/esm/browser/apps/app-settings.d.ts +6 -0
  6. package/esm/browser/apps/app-settings.js +67 -0
  7. package/esm/browser/apps/app-window-util.d.ts +23 -0
  8. package/esm/browser/apps/app-window-util.js +27 -0
  9. package/esm/browser/apps/app-window.d.ts +9 -0
  10. package/esm/browser/apps/app-window.js +90 -0
  11. package/esm/browser/apps/web-apps.d.ts +29 -0
  12. package/esm/browser/apps/web-apps.js +57 -0
  13. package/esm/browser/assistant/assistant-thread.js +3 -1
  14. package/esm/browser/assistant/assistant-view.js +8 -4
  15. package/esm/browser/assistant/call-keeper.d.ts +2 -5
  16. package/esm/browser/assistant/call-keeper.js +7 -11
  17. package/esm/browser/components/access-settings.d.ts +6 -0
  18. package/esm/browser/components/access-settings.js +52 -0
  19. package/esm/browser/components/app-root.d.ts +6 -0
  20. package/esm/browser/components/app-root.js +34 -0
  21. package/esm/browser/components/app-view.d.ts +8 -2
  22. package/esm/browser/components/app-view.js +1 -25
  23. package/esm/browser/components/cloud-sign-in-view.d.ts +1 -1
  24. package/esm/browser/components/context-act.d.ts +4 -0
  25. package/esm/browser/components/context-act.js +8 -0
  26. package/esm/browser/components/context-line.d.ts +19 -0
  27. package/esm/browser/components/context-line.js +71 -0
  28. package/esm/browser/components/host-view.d.ts +1 -1
  29. package/esm/browser/components/message-list.js +12 -6
  30. package/esm/browser/components/message-steps.js +1 -1
  31. package/esm/browser/components/session-settings.d.ts +8 -4
  32. package/esm/browser/components/session-settings.js +10 -5
  33. package/esm/browser/components/session-view.js +12 -8
  34. package/esm/browser/components/settings-more.js +6 -0
  35. package/esm/browser/device/screen-awake.d.ts +16 -0
  36. package/esm/browser/device/screen-awake.js +37 -0
  37. package/esm/browser/device/sheet-swipe.js +4 -0
  38. package/esm/browser/extension/icons.js +2 -1
  39. package/esm/browser/extension/web-access.d.ts +16 -0
  40. package/esm/browser/extension/web-access.js +75 -0
  41. package/esm/browser/extension/web-api-desktop.d.ts +23 -0
  42. package/esm/browser/extension/web-api-spec.d.ts +70 -0
  43. package/esm/browser/extension/web-api-spec.js +223 -0
  44. package/esm/browser/extension/web-extension-api.d.ts +6 -0
  45. package/esm/browser/extension/web-extension-context.js +11 -2
  46. package/esm/browser/extension/web-extension-run.d.ts +6 -1
  47. package/esm/browser/extension/web-extension-run.js +25 -0
  48. package/esm/browser/extension/web-extensions-running.d.ts +18 -1
  49. package/esm/browser/extension/web-extensions-running.js +102 -9
  50. package/esm/browser/extension/web-pages.d.ts +5 -0
  51. package/esm/browser/extension/web-pages.js +3 -0
  52. package/esm/browser/i18n/en/chat.d.ts +16 -2
  53. package/esm/browser/i18n/en/chat.js +16 -2
  54. package/esm/browser/i18n/en/common.d.ts +1 -0
  55. package/esm/browser/i18n/en/common.js +1 -0
  56. package/esm/browser/i18n/en/discover.d.ts +11 -0
  57. package/esm/browser/i18n/en/discover.js +11 -0
  58. package/esm/browser/i18n/en/settings.d.ts +54 -0
  59. package/esm/browser/i18n/en/settings.js +57 -3
  60. package/esm/browser/i18n/en/tools.d.ts +1 -0
  61. package/esm/browser/i18n/en/tools.js +1 -0
  62. package/esm/browser/i18n/ja/chat.js +16 -2
  63. package/esm/browser/i18n/ja/common.js +1 -0
  64. package/esm/browser/i18n/ja/discover.js +11 -0
  65. package/esm/browser/i18n/ja/settings.js +57 -3
  66. package/esm/browser/i18n/ja/tools.js +1 -0
  67. package/esm/browser/i18n/locales.d.ts +84 -5
  68. package/esm/browser/i18n/messages.d.ts +83 -4
  69. package/esm/browser/i18n/zh/chat.js +16 -2
  70. package/esm/browser/i18n/zh/common.js +1 -0
  71. package/esm/browser/i18n/zh/discover.js +11 -0
  72. package/esm/browser/i18n/zh/settings.js +57 -3
  73. package/esm/browser/i18n/zh/tools.js +1 -0
  74. package/esm/browser/i18n/zh-tw/chat.js +16 -2
  75. package/esm/browser/i18n/zh-tw/common.js +1 -0
  76. package/esm/browser/i18n/zh-tw/discover.js +11 -0
  77. package/esm/browser/i18n/zh-tw/settings.js +57 -3
  78. package/esm/browser/i18n/zh-tw/tools.js +1 -0
  79. package/esm/browser/index.d.ts +1 -0
  80. package/esm/browser/index.js +1 -0
  81. package/esm/browser/notices/notices.js +1 -0
  82. package/esm/browser/sandbox/channel/channel.d.ts +56 -0
  83. package/esm/browser/sandbox/channel/channel.js +124 -0
  84. package/esm/browser/sandbox/channel/codec.d.ts +80 -0
  85. package/esm/browser/sandbox/channel/codec.js +251 -0
  86. package/esm/browser/sandbox/hook-host.d.ts +23 -0
  87. package/esm/browser/sandbox/hook-host.js +61 -0
  88. package/esm/browser/sandbox/isolated-host.d.ts +105 -0
  89. package/esm/browser/sandbox/isolated-host.js +395 -0
  90. package/esm/browser/sandbox/remote/remote-copy.d.ts +56 -0
  91. package/esm/browser/sandbox/remote/remote-copy.js +302 -0
  92. package/esm/browser/sandbox/remote/remote-mirror.d.ts +61 -0
  93. package/esm/browser/sandbox/remote/remote-mirror.js +341 -0
  94. package/esm/browser/sandbox/remote/remote-protocol.d.ts +79 -0
  95. package/esm/browser/sandbox/remote/remote-protocol.js +54 -0
  96. package/esm/browser/sandbox/remote/remote-styles.d.ts +10 -0
  97. package/esm/browser/sandbox/remote/remote-styles.js +113 -0
  98. package/esm/browser/sandbox/remote-root.d.ts +11 -0
  99. package/esm/browser/sandbox/remote-root.js +81 -0
  100. package/esm/browser/sandbox/runtime/frame-api.d.ts +28 -0
  101. package/esm/browser/sandbox/runtime/frame-api.js +147 -0
  102. package/esm/browser/sandbox/runtime/frame-features.d.ts +6 -0
  103. package/esm/browser/sandbox/runtime/frame-features.js +50 -0
  104. package/esm/browser/sandbox/runtime/frame-parts.d.ts +36 -0
  105. package/esm/browser/sandbox/runtime/frame-parts.js +69 -0
  106. package/esm/browser/sandbox/runtime/frame-roots.d.ts +26 -0
  107. package/esm/browser/sandbox/runtime/frame-roots.js +76 -0
  108. package/esm/browser/sandbox/runtime/frame-store.d.ts +9 -0
  109. package/esm/browser/sandbox/runtime/frame-store.js +18 -0
  110. package/esm/browser/sandbox/runtime/sandbox-runtime.d.ts +11 -0
  111. package/esm/browser/sandbox/runtime/sandbox-runtime.js +45 -0
  112. package/esm/browser/sandbox/sandbox-features.d.ts +25 -0
  113. package/esm/browser/sandbox/sandbox-features.js +32 -0
  114. package/esm/browser/sandbox/sandbox-frame.d.ts +21 -0
  115. package/esm/browser/sandbox/sandbox-frame.js +75 -0
  116. package/esm/browser/sandbox/sandbox-guards.d.ts +19 -0
  117. package/esm/browser/sandbox/sandbox-guards.js +74 -0
  118. package/esm/browser/sandbox/sandbox-protocol.d.ts +57 -0
  119. package/esm/browser/sandbox/sandbox-protocol.js +49 -0
  120. package/esm/browser/sandbox/sandbox-runtime-code.d.ts +1 -0
  121. package/esm/browser/sandbox/sandbox-runtime-code.js +3 -0
  122. package/esm/browser/sandbox/web-sandbox.d.ts +28 -0
  123. package/esm/browser/sandbox/web-sandbox.js +44 -0
  124. package/esm/browser/settings/agent-settings.js +12 -2
  125. package/esm/browser/settings/settings-protocol.d.ts +2 -0
  126. package/esm/browser/settings/settings-protocol.js +2 -0
  127. package/esm/browser/style/conversation.d.ts +1 -1
  128. package/esm/browser/style/conversation.js +20 -1
  129. package/esm/browser/style/surfaces.d.ts +1 -1
  130. package/esm/browser/style/surfaces.js +5 -0
  131. package/esm/browser/style/tints.d.ts +2 -0
  132. package/esm/browser/style/tints.js +10 -0
  133. package/esm/browser/util/context-view.d.ts +16 -0
  134. package/esm/browser/util/context-view.js +42 -0
  135. package/esm/browser/util/desktop.d.ts +31 -1
  136. package/esm/browser/util/desktop.js +20 -0
  137. package/esm/browser/util/progress.d.ts +4 -0
  138. package/esm/browser/util/progress.js +9 -3
  139. package/esm/browser/view.js +1 -1
  140. package/lib/browser/apps/app-icon.d.ts +24 -0
  141. package/lib/browser/apps/app-icon.js +134 -0
  142. package/lib/browser/apps/app-settings.d.ts +7 -0
  143. package/lib/browser/apps/app-settings.js +103 -0
  144. package/lib/browser/apps/app-window-util.d.ts +24 -0
  145. package/lib/browser/apps/app-window-util.js +30 -0
  146. package/lib/browser/apps/app-window.d.ts +10 -0
  147. package/lib/browser/apps/app-window.js +126 -0
  148. package/lib/browser/apps/web-apps.d.ts +30 -0
  149. package/lib/browser/apps/web-apps.js +61 -0
  150. package/lib/browser/assistant/assistant-thread.js +3 -1
  151. package/lib/browser/assistant/assistant-view.js +8 -4
  152. package/lib/browser/assistant/call-keeper.d.ts +2 -5
  153. package/lib/browser/assistant/call-keeper.js +6 -10
  154. package/lib/browser/components/access-settings.d.ts +7 -0
  155. package/lib/browser/components/access-settings.js +88 -0
  156. package/lib/browser/components/app-root.d.ts +7 -0
  157. package/lib/browser/components/app-root.js +70 -0
  158. package/lib/browser/components/app-view.d.ts +8 -2
  159. package/lib/browser/components/app-view.js +1 -25
  160. package/lib/browser/components/cloud-sign-in-view.d.ts +1 -1
  161. package/lib/browser/components/context-act.d.ts +5 -0
  162. package/lib/browser/components/context-act.js +44 -0
  163. package/lib/browser/components/context-line.d.ts +20 -0
  164. package/lib/browser/components/context-line.js +109 -0
  165. package/lib/browser/components/host-view.d.ts +1 -1
  166. package/lib/browser/components/message-list.js +12 -6
  167. package/lib/browser/components/message-steps.js +1 -1
  168. package/lib/browser/components/session-settings.d.ts +8 -4
  169. package/lib/browser/components/session-settings.js +10 -5
  170. package/lib/browser/components/session-view.js +12 -8
  171. package/lib/browser/components/settings-more.js +6 -0
  172. package/lib/browser/device/screen-awake.d.ts +16 -0
  173. package/lib/browser/device/screen-awake.js +39 -1
  174. package/lib/browser/device/sheet-swipe.js +4 -0
  175. package/lib/browser/extension/icons.js +1 -0
  176. package/lib/browser/extension/web-access.d.ts +17 -0
  177. package/lib/browser/extension/web-access.js +78 -0
  178. package/lib/browser/extension/web-api-desktop.d.ts +23 -0
  179. package/lib/browser/extension/web-api-spec.d.ts +71 -0
  180. package/lib/browser/extension/web-api-spec.js +226 -0
  181. package/lib/browser/extension/web-extension-api.d.ts +6 -0
  182. package/lib/browser/extension/web-extension-context.js +11 -2
  183. package/lib/browser/extension/web-extension-run.d.ts +6 -1
  184. package/lib/browser/extension/web-extension-run.js +25 -0
  185. package/lib/browser/extension/web-extensions-running.d.ts +18 -1
  186. package/lib/browser/extension/web-extensions-running.js +102 -9
  187. package/lib/browser/extension/web-pages.d.ts +5 -0
  188. package/lib/browser/extension/web-pages.js +3 -0
  189. package/lib/browser/i18n/en/chat.d.ts +16 -2
  190. package/lib/browser/i18n/en/chat.js +16 -2
  191. package/lib/browser/i18n/en/common.d.ts +1 -0
  192. package/lib/browser/i18n/en/common.js +1 -0
  193. package/lib/browser/i18n/en/discover.d.ts +11 -0
  194. package/lib/browser/i18n/en/discover.js +11 -0
  195. package/lib/browser/i18n/en/settings.d.ts +54 -0
  196. package/lib/browser/i18n/en/settings.js +57 -3
  197. package/lib/browser/i18n/en/tools.d.ts +1 -0
  198. package/lib/browser/i18n/en/tools.js +1 -0
  199. package/lib/browser/i18n/ja/chat.js +16 -2
  200. package/lib/browser/i18n/ja/common.js +1 -0
  201. package/lib/browser/i18n/ja/discover.js +11 -0
  202. package/lib/browser/i18n/ja/settings.js +57 -3
  203. package/lib/browser/i18n/ja/tools.js +1 -0
  204. package/lib/browser/i18n/locales.d.ts +84 -5
  205. package/lib/browser/i18n/messages.d.ts +83 -4
  206. package/lib/browser/i18n/zh/chat.js +16 -2
  207. package/lib/browser/i18n/zh/common.js +1 -0
  208. package/lib/browser/i18n/zh/discover.js +11 -0
  209. package/lib/browser/i18n/zh/settings.js +57 -3
  210. package/lib/browser/i18n/zh/tools.js +1 -0
  211. package/lib/browser/i18n/zh-tw/chat.js +16 -2
  212. package/lib/browser/i18n/zh-tw/common.js +1 -0
  213. package/lib/browser/i18n/zh-tw/discover.js +11 -0
  214. package/lib/browser/i18n/zh-tw/settings.js +57 -3
  215. package/lib/browser/i18n/zh-tw/tools.js +1 -0
  216. package/lib/browser/index.d.ts +1 -0
  217. package/lib/browser/index.js +1 -0
  218. package/lib/browser/notices/notices.js +1 -0
  219. package/lib/browser/sandbox/channel/channel.d.ts +57 -0
  220. package/lib/browser/sandbox/channel/channel.js +128 -0
  221. package/lib/browser/sandbox/channel/codec.d.ts +81 -0
  222. package/lib/browser/sandbox/channel/codec.js +256 -0
  223. package/lib/browser/sandbox/hook-host.d.ts +24 -0
  224. package/lib/browser/sandbox/hook-host.js +98 -0
  225. package/lib/browser/sandbox/isolated-host.d.ts +106 -0
  226. package/lib/browser/sandbox/isolated-host.js +432 -0
  227. package/lib/browser/sandbox/remote/remote-copy.d.ts +57 -0
  228. package/lib/browser/sandbox/remote/remote-copy.js +306 -0
  229. package/lib/browser/sandbox/remote/remote-mirror.d.ts +62 -0
  230. package/lib/browser/sandbox/remote/remote-mirror.js +345 -0
  231. package/lib/browser/sandbox/remote/remote-protocol.d.ts +80 -0
  232. package/lib/browser/sandbox/remote/remote-protocol.js +57 -0
  233. package/lib/browser/sandbox/remote/remote-styles.d.ts +11 -0
  234. package/lib/browser/sandbox/remote/remote-styles.js +116 -0
  235. package/lib/browser/sandbox/remote-root.d.ts +12 -0
  236. package/lib/browser/sandbox/remote-root.js +117 -0
  237. package/lib/browser/sandbox/runtime/frame-api.d.ts +29 -0
  238. package/lib/browser/sandbox/runtime/frame-api.js +183 -0
  239. package/lib/browser/sandbox/runtime/frame-features.d.ts +7 -0
  240. package/lib/browser/sandbox/runtime/frame-features.js +53 -0
  241. package/lib/browser/sandbox/runtime/frame-parts.d.ts +37 -0
  242. package/lib/browser/sandbox/runtime/frame-parts.js +106 -0
  243. package/lib/browser/sandbox/runtime/frame-roots.d.ts +27 -0
  244. package/lib/browser/sandbox/runtime/frame-roots.js +113 -0
  245. package/lib/browser/sandbox/runtime/frame-store.d.ts +10 -0
  246. package/lib/browser/sandbox/runtime/frame-store.js +22 -0
  247. package/lib/browser/sandbox/runtime/sandbox-runtime.d.ts +12 -0
  248. package/lib/browser/sandbox/runtime/sandbox-runtime.js +47 -0
  249. package/lib/browser/sandbox/sandbox-features.d.ts +26 -0
  250. package/lib/browser/sandbox/sandbox-features.js +35 -0
  251. package/lib/browser/sandbox/sandbox-frame.d.ts +22 -0
  252. package/lib/browser/sandbox/sandbox-frame.js +79 -0
  253. package/lib/browser/sandbox/sandbox-guards.d.ts +20 -0
  254. package/lib/browser/sandbox/sandbox-guards.js +77 -0
  255. package/lib/browser/sandbox/sandbox-protocol.d.ts +58 -0
  256. package/lib/browser/sandbox/sandbox-protocol.js +52 -0
  257. package/lib/browser/sandbox/sandbox-runtime-code.d.ts +2 -0
  258. package/lib/browser/sandbox/sandbox-runtime-code.js +6 -0
  259. package/lib/browser/sandbox/web-sandbox.d.ts +29 -0
  260. package/lib/browser/sandbox/web-sandbox.js +47 -0
  261. package/lib/browser/settings/agent-settings.js +12 -2
  262. package/lib/browser/settings/settings-protocol.d.ts +2 -0
  263. package/lib/browser/settings/settings-protocol.js +2 -0
  264. package/lib/browser/style/conversation.d.ts +1 -1
  265. package/lib/browser/style/conversation.js +20 -1
  266. package/lib/browser/style/surfaces.d.ts +1 -1
  267. package/lib/browser/style/surfaces.js +5 -0
  268. package/lib/browser/style/tints.d.ts +2 -0
  269. package/lib/browser/style/tints.js +10 -0
  270. package/lib/browser/util/context-view.d.ts +17 -0
  271. package/lib/browser/util/context-view.js +45 -0
  272. package/lib/browser/util/desktop.d.ts +31 -1
  273. package/lib/browser/util/desktop.js +20 -0
  274. package/lib/browser/util/progress.d.ts +4 -0
  275. package/lib/browser/util/progress.js +9 -3
  276. package/lib/browser/view.js +2 -2
  277. package/package.json +8 -8
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Channel = exports.ChannelLimits = void 0;
4
+ var ChannelLimits;
5
+ (function (ChannelLimits) {
6
+ /** Requests of the other end answered at once, at most: more are refused, so that a sandbox cannot flood the page. */
7
+ ChannelLimits.RUNNING = 256;
8
+ })(ChannelLimits || (exports.ChannelLimits = ChannelLimits = {}));
9
+ /**
10
+ * One end of the channel between the page and a sandbox: requests answered by their id, cancelled with a signal,
11
+ * and notices that want no answer. It knows nothing of what the operations mean; both ends are this class.
12
+ */
13
+ class Channel {
14
+ constructor(port) {
15
+ this.port = port;
16
+ this.nextId = 1;
17
+ this.waiting = new Map();
18
+ this.running = new Map();
19
+ this.handlers = new Map();
20
+ this.listeners = new Map();
21
+ this.closed = false;
22
+ port.onmessage = event => this.heard(event.data);
23
+ }
24
+ request(op, body, signal) {
25
+ if (this.closed) {
26
+ return Promise.reject(new Error('The channel is closed.'));
27
+ }
28
+ const id = this.nextId++;
29
+ return new Promise((resolve, reject) => {
30
+ this.waiting.set(id, { resolve: resolve, reject });
31
+ signal === null || signal === void 0 ? void 0 : signal.addEventListener('abort', () => {
32
+ if (this.waiting.delete(id)) {
33
+ this.send({ t: 'x', id });
34
+ reject(new DOMException('Cancelled.', 'AbortError'));
35
+ }
36
+ }, { once: true });
37
+ this.send({ t: 'q', id, op, body });
38
+ });
39
+ }
40
+ notify(op, body) {
41
+ if (!this.closed) {
42
+ this.send({ t: 'n', op, body });
43
+ }
44
+ }
45
+ handle(op, handler) {
46
+ this.handlers.set(op, handler);
47
+ }
48
+ on(op, listener) {
49
+ this.listeners.set(op, listener);
50
+ }
51
+ close() {
52
+ var _a, _b;
53
+ if (this.closed) {
54
+ return;
55
+ }
56
+ this.closed = true;
57
+ for (const waiting of this.waiting.values())
58
+ waiting.reject(new Error('The channel is closed.'));
59
+ this.waiting.clear();
60
+ for (const running of this.running.values())
61
+ running.abort();
62
+ this.running.clear();
63
+ this.port.onmessage = null;
64
+ (_b = (_a = this.port).close) === null || _b === void 0 ? void 0 : _b.call(_a);
65
+ }
66
+ send(message) {
67
+ try {
68
+ this.port.postMessage(message);
69
+ }
70
+ catch (error) {
71
+ // What cannot be cloned fails the request that carried it, not the channel.
72
+ if (message.t === 'q') {
73
+ const waiting = this.waiting.get(message.id);
74
+ this.waiting.delete(message.id);
75
+ waiting === null || waiting === void 0 ? void 0 : waiting.reject(error instanceof Error ? error : new Error(String(error)));
76
+ }
77
+ else if (message.t === 'a') {
78
+ this.port.postMessage({ t: 'a', id: message.id, error: error instanceof Error ? error.message : String(error) });
79
+ }
80
+ else {
81
+ console.error(error);
82
+ }
83
+ }
84
+ }
85
+ heard(message) {
86
+ var _a, _b;
87
+ if (this.closed || !message || typeof message !== 'object') {
88
+ return;
89
+ }
90
+ switch (message.t) {
91
+ case 'a': {
92
+ const waiting = this.waiting.get(message.id);
93
+ this.waiting.delete(message.id);
94
+ if (message.error !== undefined) {
95
+ waiting === null || waiting === void 0 ? void 0 : waiting.reject(new Error(String(message.error)));
96
+ }
97
+ else {
98
+ waiting === null || waiting === void 0 ? void 0 : waiting.resolve(message.body);
99
+ }
100
+ return;
101
+ }
102
+ case 'x':
103
+ (_a = this.running.get(message.id)) === null || _a === void 0 ? void 0 : _a.abort();
104
+ this.running.delete(message.id);
105
+ return;
106
+ case 'n':
107
+ (_b = this.listeners.get(String(message.op))) === null || _b === void 0 ? void 0 : _b(message.body);
108
+ return;
109
+ case 'q':
110
+ this.answer(message.id, String(message.op), message.body);
111
+ return;
112
+ }
113
+ }
114
+ answer(id, op, body) {
115
+ const handler = this.handlers.get(op);
116
+ if (!handler || this.running.size >= ChannelLimits.RUNNING) {
117
+ this.send({ t: 'a', id, error: handler ? 'Too many requests at once.' : `Nothing here answers ${op}.` });
118
+ return;
119
+ }
120
+ const controller = new AbortController();
121
+ this.running.set(id, controller);
122
+ new Promise(resolve => resolve(handler(body, controller.signal)))
123
+ .then(value => this.running.has(id) && this.send({ t: 'a', id, body: value }), error => this.running.has(id) && this.send({ t: 'a', id, error: error instanceof Error ? error.message : String(error) }))
124
+ .finally(() => this.running.delete(id));
125
+ }
126
+ }
127
+ exports.Channel = Channel;
128
+ //# sourceMappingURL=channel.js.map
@@ -0,0 +1,81 @@
1
+ import type { WebApiShape } from '../../extension/web-api-spec';
2
+ import type { Channel } from './channel';
3
+ /** The key of what stands for a function, a component, a part of Ta or a live object as it crosses. */
4
+ export declare const MARK = "#ta";
5
+ export type CodecMark = {
6
+ [MARK]: 'f';
7
+ id: number;
8
+ } | {
9
+ [MARK]: 'c';
10
+ id: number;
11
+ } | {
12
+ [MARK]: 'part';
13
+ path: string;
14
+ } | {
15
+ [MARK]: 'live';
16
+ id: number;
17
+ values: Record<string, unknown>;
18
+ rest: unknown;
19
+ };
20
+ /** What a side of the channel makes of what only it can: the components of the other's, and the parts of Ta. */
21
+ export interface CodecSide {
22
+ /** What to draw for a component of the other side (the page: a remote root of it). */
23
+ component?(id: number): unknown;
24
+ /** The part of Ta of that path (the page: the component itself, as far as access reaches). */
25
+ part?(path: string): unknown;
26
+ /** The path of a part of Ta this side stands in for (the sandbox: its stand-ins), else undefined. */
27
+ partOf?(value: unknown): string | undefined;
28
+ }
29
+ /** Handles given out together, let go together: the props of a part, the registration of a view. */
30
+ export declare class CodecScope {
31
+ protected readonly codec: Codec;
32
+ readonly ids: Set<number>;
33
+ readonly stops: (() => void)[];
34
+ constructor(codec: Codec);
35
+ release(): void;
36
+ }
37
+ /**
38
+ * Turns what crosses into what a structured clone carries, and back (docs/design/ta-extension-access.md 3.2): a
39
+ * function becomes a handle the other side calls through the channel (its result a promise), a component one the
40
+ * other side draws, a part of Ta its path, the live methods of an object a snapshot sent again as it changes. Both
41
+ * ends have one; neither knows what the values mean.
42
+ */
43
+ export declare class Codec {
44
+ protected readonly channel: Channel;
45
+ protected readonly side: CodecSide;
46
+ protected nextId: number;
47
+ protected readonly own: Map<number, {
48
+ value: unknown;
49
+ uses: number;
50
+ kind: 'f' | 'c';
51
+ }>;
52
+ protected readonly ids: WeakMap<object, number>;
53
+ protected readonly proxies: Map<number, (...args: unknown[]) => Promise<unknown>>;
54
+ protected readonly lives: Map<number, {
55
+ values: Record<string, unknown>;
56
+ listeners: Set<() => void>;
57
+ }>;
58
+ /** What lives as long as the channel: the handles of calls, whose callbacks the other side may call any time. */
59
+ readonly forever: CodecScope;
60
+ constructor(channel: Channel, side?: CodecSide);
61
+ scope(): CodecScope;
62
+ /** A component this side handed out, by its handle. */
63
+ component(id: number): unknown;
64
+ /** The arguments of a call, each by its shape. */
65
+ encodeArgs(args: readonly unknown[], shapes: readonly (WebApiShape | null)[] | undefined, scope?: CodecScope): unknown[];
66
+ encode(value: unknown, shape?: WebApiShape, scope?: CodecScope, seen?: Set<object>): unknown;
67
+ decode(value: unknown): unknown;
68
+ release(scope: CodecScope): void;
69
+ protected componentMark(value: unknown, scope: CodecScope): unknown;
70
+ protected fields(value: Record<string, unknown>, shape: WebApiShape | undefined, scope: CodecScope, seen: Set<object>, skip?: readonly string[]): Record<string, unknown>;
71
+ /** Its live methods read now and again whenever its own `subscribe` says, the rest as fields. */
72
+ protected liveMark(value: Record<string, unknown>, shape: WebApiShape & object, scope: CodecScope, seen: Set<object>): unknown;
73
+ protected live(mark: Extract<CodecMark, {
74
+ [MARK]: 'live';
75
+ }>): unknown;
76
+ protected hold(value: unknown, kind: 'f' | 'c', scope: CodecScope): number;
77
+ protected proxy(id: number): (...args: unknown[]) => Promise<unknown>;
78
+ /** What a structured clone carries as it is. */
79
+ static cloned(value: object): boolean;
80
+ }
81
+ //# sourceMappingURL=codec.d.ts.map
@@ -0,0 +1,256 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Codec = exports.CodecScope = exports.MARK = void 0;
4
+ /** The key of what stands for a function, a component, a part of Ta or a live object as it crosses. */
5
+ exports.MARK = '#ta';
6
+ /** Handles given out together, let go together: the props of a part, the registration of a view. */
7
+ class CodecScope {
8
+ constructor(codec) {
9
+ this.codec = codec;
10
+ this.ids = new Set();
11
+ this.stops = [];
12
+ }
13
+ release() {
14
+ this.codec.release(this);
15
+ }
16
+ }
17
+ exports.CodecScope = CodecScope;
18
+ const ELEMENT = [Symbol.for('react.element'), Symbol.for('react.transitional.element')];
19
+ /**
20
+ * Turns what crosses into what a structured clone carries, and back (docs/design/ta-extension-access.md 3.2): a
21
+ * function becomes a handle the other side calls through the channel (its result a promise), a component one the
22
+ * other side draws, a part of Ta its path, the live methods of an object a snapshot sent again as it changes. Both
23
+ * ends have one; neither knows what the values mean.
24
+ */
25
+ class Codec {
26
+ constructor(channel, side = {}) {
27
+ this.channel = channel;
28
+ this.side = side;
29
+ this.nextId = 1;
30
+ this.own = new Map();
31
+ this.ids = new WeakMap();
32
+ this.proxies = new Map();
33
+ this.lives = new Map();
34
+ this.forever = new CodecScope(this);
35
+ channel.handle('fn', body => {
36
+ const { id, args } = body;
37
+ const found = this.own.get(id);
38
+ if ((found === null || found === void 0 ? void 0 : found.kind) !== 'f') {
39
+ throw new Error('That function is gone.');
40
+ }
41
+ const decoded = (Array.isArray(args) ? args : []).map(arg => this.decode(arg));
42
+ return Promise.resolve(found.value(...decoded)).then(value => this.encode(value));
43
+ });
44
+ channel.on('live', body => {
45
+ const { id, values } = body;
46
+ const live = this.lives.get(id);
47
+ if (live) {
48
+ live.values = this.decode(values);
49
+ for (const listener of live.listeners)
50
+ listener();
51
+ }
52
+ });
53
+ }
54
+ scope() {
55
+ return new CodecScope(this);
56
+ }
57
+ /** A component this side handed out, by its handle. */
58
+ component(id) {
59
+ const found = this.own.get(id);
60
+ return (found === null || found === void 0 ? void 0 : found.kind) === 'c' ? found.value : undefined;
61
+ }
62
+ /** The arguments of a call, each by its shape. */
63
+ encodeArgs(args, shapes, scope = this.forever) {
64
+ return args.map((arg, index) => { var _a; return this.encode(arg, (_a = shapes === null || shapes === void 0 ? void 0 : shapes[index]) !== null && _a !== void 0 ? _a : undefined, scope); });
65
+ }
66
+ encode(value, shape, scope = this.forever, seen = new Set()) {
67
+ var _a, _b, _c, _d, _e;
68
+ if (shape === 'X') {
69
+ return undefined;
70
+ }
71
+ if (shape === 'L') {
72
+ return typeof value === 'function' ? String(value()) : value;
73
+ }
74
+ if (shape === 'C') {
75
+ return value === undefined || value === null ? value : this.componentMark(value, scope);
76
+ }
77
+ if (typeof value === 'symbol') {
78
+ return undefined;
79
+ }
80
+ if (typeof value === 'function') {
81
+ const path = (_b = (_a = this.side).partOf) === null || _b === void 0 ? void 0 : _b.call(_a, value);
82
+ return path ? { [exports.MARK]: 'part', path } : { [exports.MARK]: 'f', id: this.hold(value, 'f', scope) };
83
+ }
84
+ if (!value || typeof value !== 'object') {
85
+ return value;
86
+ }
87
+ if (seen.has(value)) {
88
+ return undefined;
89
+ }
90
+ const kind = value.$typeof;
91
+ if (ELEMENT.includes(kind)) {
92
+ return undefined;
93
+ }
94
+ if (typeof kind === 'symbol') {
95
+ // A component of React's own kinds (memo, forwardRef): drawn where it is, as any component.
96
+ return this.componentMark(value, scope);
97
+ }
98
+ const path = (_d = (_c = this.side).partOf) === null || _d === void 0 ? void 0 : _d.call(_c, value);
99
+ if (path) {
100
+ return { [exports.MARK]: 'part', path };
101
+ }
102
+ if (Codec.cloned(value)) {
103
+ return value;
104
+ }
105
+ seen.add(value);
106
+ try {
107
+ if (Array.isArray(value)) {
108
+ const each = shape && typeof shape === 'object' ? shape.each : undefined;
109
+ return value.map(item => this.encode(item, each, scope, seen));
110
+ }
111
+ if (typeof Node !== 'undefined' && value instanceof Node) {
112
+ return undefined;
113
+ }
114
+ const fields = shape && typeof shape === 'object' ? shape : undefined;
115
+ if ((_e = fields === null || fields === void 0 ? void 0 : fields.live) === null || _e === void 0 ? void 0 : _e.length) {
116
+ return this.liveMark(value, fields, scope, seen);
117
+ }
118
+ return this.fields(value, fields, scope, seen);
119
+ }
120
+ finally {
121
+ seen.delete(value);
122
+ }
123
+ }
124
+ decode(value) {
125
+ var _a, _b, _c, _d;
126
+ if (!value || typeof value !== 'object' || Codec.cloned(value)) {
127
+ return value;
128
+ }
129
+ if (Array.isArray(value)) {
130
+ return value.map(item => this.decode(item));
131
+ }
132
+ const mark = value;
133
+ switch (mark[exports.MARK]) {
134
+ case 'f':
135
+ return this.proxy(Number(mark.id));
136
+ case 'c':
137
+ return (_b = (_a = this.side).component) === null || _b === void 0 ? void 0 : _b.call(_a, Number(mark.id));
138
+ case 'part':
139
+ return (_d = (_c = this.side).part) === null || _d === void 0 ? void 0 : _d.call(_c, String(mark.path));
140
+ case 'live':
141
+ return this.live(value);
142
+ }
143
+ const decoded = {};
144
+ for (const [key, item] of Object.entries(value)) {
145
+ decoded[key] = this.decode(item);
146
+ }
147
+ return decoded;
148
+ }
149
+ release(scope) {
150
+ for (const stop of scope.stops.splice(0))
151
+ stop();
152
+ for (const id of scope.ids) {
153
+ const found = this.own.get(id);
154
+ if (found && --found.uses <= 0) {
155
+ this.own.delete(id);
156
+ if (found.value && (typeof found.value === 'object' || typeof found.value === 'function')) {
157
+ this.ids.delete(found.value);
158
+ }
159
+ }
160
+ }
161
+ scope.ids.clear();
162
+ }
163
+ componentMark(value, scope) {
164
+ var _a, _b;
165
+ const path = (_b = (_a = this.side).partOf) === null || _b === void 0 ? void 0 : _b.call(_a, value);
166
+ return path ? { [exports.MARK]: 'part', path } : { [exports.MARK]: 'c', id: this.hold(value, 'c', scope) };
167
+ }
168
+ fields(value, shape, scope, seen, skip) {
169
+ const fields = shape && typeof shape === 'object' ? shape.fields : undefined;
170
+ const encoded = {};
171
+ for (const key of Object.keys(value)) {
172
+ if (!(skip === null || skip === void 0 ? void 0 : skip.includes(key))) {
173
+ encoded[key] = this.encode(value[key], fields === null || fields === void 0 ? void 0 : fields[key], scope, seen);
174
+ }
175
+ }
176
+ return encoded;
177
+ }
178
+ /** Its live methods read now and again whenever its own `subscribe` says, the rest as fields. */
179
+ liveMark(value, shape, scope, seen) {
180
+ var _a;
181
+ const names = (_a = shape.live) !== null && _a !== void 0 ? _a : [];
182
+ const id = this.nextId++;
183
+ // Each read in a scope of its own, the one before let go: what a menu gave out before is gone with it.
184
+ let current = this.scope();
185
+ scope.stops.push(() => current.release());
186
+ const read = () => {
187
+ const next = this.scope();
188
+ const values = {};
189
+ for (const name of names) {
190
+ const method = value[name];
191
+ if (typeof method === 'function') {
192
+ values[name] = this.encode(method.call(value), undefined, next);
193
+ }
194
+ }
195
+ current.release();
196
+ current = next;
197
+ return values;
198
+ };
199
+ const subscribe = value.subscribe;
200
+ if (typeof subscribe === 'function') {
201
+ const stop = subscribe.call(value, () => this.channel.notify('live', { id, values: read() }));
202
+ if (typeof stop === 'function') {
203
+ scope.stops.push(stop);
204
+ }
205
+ }
206
+ return { [exports.MARK]: 'live', id, values: read(), rest: this.fields(value, shape, scope, seen, [...names, 'subscribe']) };
207
+ }
208
+ live(mark) {
209
+ var _a;
210
+ const id = Number(mark.id);
211
+ const live = { values: this.decode(mark.values), listeners: new Set() };
212
+ this.lives.set(id, live);
213
+ const object = ((_a = this.decode(mark.rest)) !== null && _a !== void 0 ? _a : {});
214
+ for (const name of Object.keys(live.values)) {
215
+ object[name] = () => live.values[name];
216
+ }
217
+ object.subscribe = (listener) => {
218
+ live.listeners.add(listener);
219
+ return () => live.listeners.delete(listener);
220
+ };
221
+ return object;
222
+ }
223
+ hold(value, kind, scope) {
224
+ var _a;
225
+ const key = value;
226
+ let id = this.ids.get(key);
227
+ if (id === undefined || ((_a = this.own.get(id)) === null || _a === void 0 ? void 0 : _a.kind) !== kind) {
228
+ id = this.nextId++;
229
+ this.ids.set(key, id);
230
+ this.own.set(id, { value, uses: 0, kind });
231
+ }
232
+ if (!scope.ids.has(id)) {
233
+ scope.ids.add(id);
234
+ this.own.get(id).uses++;
235
+ }
236
+ return id;
237
+ }
238
+ proxy(id) {
239
+ let proxy = this.proxies.get(id);
240
+ if (!proxy) {
241
+ proxy = (...args) => this.channel.request('fn', { id, args: this.encodeArgs(args, undefined) }).then(value => this.decode(value));
242
+ this.proxies.set(id, proxy);
243
+ }
244
+ return proxy;
245
+ }
246
+ /** What a structured clone carries as it is. */
247
+ static cloned(value) {
248
+ return (value instanceof Date ||
249
+ value instanceof RegExp ||
250
+ value instanceof ArrayBuffer ||
251
+ ArrayBuffer.isView(value) ||
252
+ (typeof Blob !== 'undefined' && value instanceof Blob));
253
+ }
254
+ }
255
+ exports.Codec = Codec;
256
+ //# sourceMappingURL=codec.js.map
@@ -0,0 +1,24 @@
1
+ import { type Root } from 'react-dom/client';
2
+ interface Watched {
3
+ key: string;
4
+ hook: (...args: unknown[]) => unknown;
5
+ args: unknown[];
6
+ }
7
+ /**
8
+ * The hooks of the page a sandbox uses (docs/design/ta-extension-access.md 3.2), run in a root of their own, apart from
9
+ * any view: each watched by a key, its value told whenever it renders. Rendered at once (flushSync), so that a value is
10
+ * known as soon as it is watched.
11
+ */
12
+ export declare class HookHost {
13
+ protected readonly heard: (key: string, value: unknown) => void;
14
+ protected readonly root: Root;
15
+ protected readonly watched: Map<string, Watched>;
16
+ constructor(heard: (key: string, value: unknown) => void);
17
+ watch(key: string, hook: (...args: unknown[]) => unknown, args: unknown[]): void;
18
+ args(key: string, args: unknown[]): void;
19
+ unwatch(key: string): void;
20
+ dispose(): void;
21
+ protected render(): void;
22
+ }
23
+ export {};
24
+ //# sourceMappingURL=hook-host.d.ts.map
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.HookHost = void 0;
37
+ const React = __importStar(require("react"));
38
+ const react_dom_1 = require("react-dom");
39
+ const client_1 = require("react-dom/client");
40
+ class Guard extends React.Component {
41
+ constructor() {
42
+ super(...arguments);
43
+ this.state = { failed: false };
44
+ }
45
+ static getDerivedStateFromError() {
46
+ return { failed: true };
47
+ }
48
+ componentDidCatch(error) {
49
+ console.error(`A hook of a sandbox failed (${this.props.name}):`, error);
50
+ }
51
+ render() {
52
+ return this.state.failed ? null : this.props.children;
53
+ }
54
+ }
55
+ function Watch({ watched, heard }) {
56
+ const value = watched.hook(...watched.args);
57
+ React.useLayoutEffect(() => heard(watched.key, value));
58
+ return null;
59
+ }
60
+ /**
61
+ * The hooks of the page a sandbox uses (docs/design/ta-extension-access.md 3.2), run in a root of their own, apart from
62
+ * any view: each watched by a key, its value told whenever it renders. Rendered at once (flushSync), so that a value is
63
+ * known as soon as it is watched.
64
+ */
65
+ class HookHost {
66
+ constructor(heard) {
67
+ this.heard = heard;
68
+ this.watched = new Map();
69
+ this.root = (0, client_1.createRoot)(document.createElement('div'));
70
+ }
71
+ watch(key, hook, args) {
72
+ this.watched.set(key, { key, hook, args });
73
+ this.render();
74
+ }
75
+ args(key, args) {
76
+ const found = this.watched.get(key);
77
+ if (found) {
78
+ this.watched.set(key, { ...found, args });
79
+ this.render();
80
+ }
81
+ }
82
+ unwatch(key) {
83
+ if (this.watched.delete(key)) {
84
+ this.render();
85
+ }
86
+ }
87
+ dispose() {
88
+ this.watched.clear();
89
+ this.root.unmount();
90
+ }
91
+ render() {
92
+ const heard = this.heard;
93
+ (0, react_dom_1.flushSync)(() => this.root.render([...this.watched.values()].map(watched => (React.createElement(Guard, { key: watched.key, name: watched.key },
94
+ React.createElement(Watch, { watched: watched, heard: heard }))))));
95
+ }
96
+ }
97
+ exports.HookHost = HookHost;
98
+ //# sourceMappingURL=hook-host.js.map