@celljs/ta-web 4.37.0 → 4.39.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 (237) hide show
  1. package/README.en.md +1 -1
  2. package/README.md +1 -1
  3. package/esm/browser/assistant/assistant-thread.d.ts +1 -1
  4. package/esm/browser/assistant/chat-task-source.js +2 -1
  5. package/esm/browser/components/app-contexts.js +11 -9
  6. package/esm/browser/components/chat-asks.d.ts +4 -1
  7. package/esm/browser/components/chat-asks.js +10 -0
  8. package/esm/browser/components/chat-list-row.js +5 -3
  9. package/esm/browser/components/cloud-network.d.ts +17 -0
  10. package/esm/browser/components/cloud-network.js +105 -0
  11. package/esm/browser/components/cloud-sign-in-view.d.ts +1 -1
  12. package/esm/browser/components/composer-box-protocol.d.ts +5 -0
  13. package/esm/browser/components/composer-box.js +11 -14
  14. package/esm/browser/components/composer-media.d.ts +26 -0
  15. package/esm/browser/components/composer-media.js +37 -0
  16. package/esm/browser/components/composer-target.d.ts +2 -2
  17. package/esm/browser/components/composer-target.js +3 -3
  18. package/esm/browser/components/composer.js +1 -0
  19. package/esm/browser/components/folder-picker.d.ts +3 -3
  20. package/esm/browser/components/folder-picker.js +5 -15
  21. package/esm/browser/components/host-view.d.ts +1 -1
  22. package/esm/browser/components/link.d.ts +7 -1
  23. package/esm/browser/components/link.js +24 -5
  24. package/esm/browser/components/markdown.d.ts +2 -2
  25. package/esm/browser/components/markdown.js +77 -5
  26. package/esm/browser/components/relay-services.d.ts +0 -2
  27. package/esm/browser/components/relay-services.js +1 -11
  28. package/esm/browser/components/remote-hosts.d.ts +11 -7
  29. package/esm/browser/components/remote-hosts.js +94 -50
  30. package/esm/browser/components/remote-machines.d.ts +21 -0
  31. package/esm/browser/components/remote-machines.js +56 -0
  32. package/esm/browser/components/remote-prompts.d.ts +2 -3
  33. package/esm/browser/components/remote-prompts.js +3 -15
  34. package/esm/browser/components/remote-steps.d.ts +19 -0
  35. package/esm/browser/components/remote-steps.js +26 -0
  36. package/esm/browser/components/session-view.js +10 -6
  37. package/esm/browser/components/settings-controls.d.ts +3 -1
  38. package/esm/browser/components/settings-controls.js +2 -2
  39. package/esm/browser/components/web-composer.d.ts +1 -1
  40. package/esm/browser/components/web-composer.js +12 -3
  41. package/esm/browser/device/photo-picker.d.ts +11 -3
  42. package/esm/browser/device/photo-picker.js +26 -9
  43. package/esm/browser/device/video-picks.d.ts +24 -0
  44. package/esm/browser/device/video-picks.js +104 -0
  45. package/esm/browser/extension/icons.js +3 -1
  46. package/esm/browser/extension/web-access.js +4 -1
  47. package/esm/browser/extension/web-api-code.d.ts +36 -0
  48. package/esm/browser/extension/web-api-code.js +3 -0
  49. package/esm/browser/extension/web-api-components.d.ts +22 -0
  50. package/esm/browser/extension/web-api-contributions.d.ts +0 -31
  51. package/esm/browser/extension/web-api-menus.d.ts +29 -3
  52. package/esm/browser/extension/web-api-play.d.ts +29 -0
  53. package/esm/browser/extension/web-api-play.js +2 -0
  54. package/esm/browser/extension/web-api-services.d.ts +6 -0
  55. package/esm/browser/extension/web-api-spec.js +5 -0
  56. package/esm/browser/extension/web-api-terminal.d.ts +20 -0
  57. package/esm/browser/extension/web-extension-api.d.ts +12 -17
  58. package/esm/browser/extension/web-extension-context.d.ts +1 -1
  59. package/esm/browser/extension/web-extension-context.js +6 -3
  60. package/esm/browser/extension/web-extension-protocol.d.ts +5 -1
  61. package/esm/browser/extension/web-extension-protocol.js +2 -0
  62. package/esm/browser/extension/web-extension-run.d.ts +6 -4
  63. package/esm/browser/extension/web-extension-run.js +18 -9
  64. package/esm/browser/extension/web-extensions-running.js +38 -7
  65. package/esm/browser/extension/web-on-demand.d.ts +5 -0
  66. package/esm/browser/extension/web-on-demand.js +11 -0
  67. package/esm/browser/i18n/en/assistant.d.ts +3 -0
  68. package/esm/browser/i18n/en/assistant.js +3 -0
  69. package/esm/browser/i18n/en/chat.d.ts +1 -0
  70. package/esm/browser/i18n/en/chat.js +1 -0
  71. package/esm/browser/i18n/en/common.d.ts +1 -0
  72. package/esm/browser/i18n/en/common.js +1 -0
  73. package/esm/browser/i18n/en/discover.d.ts +2 -0
  74. package/esm/browser/i18n/en/discover.js +2 -0
  75. package/esm/browser/i18n/en/service.d.ts +26 -2
  76. package/esm/browser/i18n/en/service.js +34 -10
  77. package/esm/browser/i18n/ja/assistant.js +3 -0
  78. package/esm/browser/i18n/ja/chat.js +1 -0
  79. package/esm/browser/i18n/ja/common.js +1 -0
  80. package/esm/browser/i18n/ja/discover.js +2 -0
  81. package/esm/browser/i18n/ja/service.js +34 -10
  82. package/esm/browser/i18n/locales.d.ts +34 -3
  83. package/esm/browser/i18n/messages.d.ts +33 -2
  84. package/esm/browser/i18n/zh/assistant.js +3 -0
  85. package/esm/browser/i18n/zh/chat.js +1 -0
  86. package/esm/browser/i18n/zh/common.js +1 -0
  87. package/esm/browser/i18n/zh/discover.js +2 -0
  88. package/esm/browser/i18n/zh/service.js +34 -10
  89. package/esm/browser/i18n/zh-tw/assistant.js +3 -0
  90. package/esm/browser/i18n/zh-tw/chat.js +1 -0
  91. package/esm/browser/i18n/zh-tw/common.js +1 -0
  92. package/esm/browser/i18n/zh-tw/discover.js +2 -0
  93. package/esm/browser/i18n/zh-tw/service.js +34 -10
  94. package/esm/browser/markdown/code-renderers.d.ts +6 -1
  95. package/esm/browser/markdown/code-renderers.js +4 -0
  96. package/esm/browser/sandbox/sandbox-runtime-code.js +1 -1
  97. package/esm/browser/sandbox/work/work-api.d.ts +113 -0
  98. package/esm/browser/sandbox/work/work-api.js +95 -0
  99. package/esm/browser/sandbox/work/work-docs.d.ts +18 -0
  100. package/esm/browser/sandbox/work/work-docs.js +66 -0
  101. package/esm/browser/sandbox/work/work-frame.d.ts +27 -0
  102. package/esm/browser/sandbox/work/work-frame.js +124 -0
  103. package/esm/browser/share/shared-extensions.d.ts +2 -1
  104. package/esm/browser/style/conversation.d.ts +1 -1
  105. package/esm/browser/style/conversation.js +10 -0
  106. package/esm/browser/style/dialogs.d.ts +1 -1
  107. package/esm/browser/style/dialogs.js +1 -4
  108. package/esm/browser/style/pages.d.ts +1 -1
  109. package/esm/browser/style/pages.js +10 -1
  110. package/esm/browser/terminal/terminal-osc.d.ts +15 -0
  111. package/esm/browser/terminal/terminal-osc.js +91 -0
  112. package/esm/browser/terminal/web-terminal.d.ts +4 -7
  113. package/esm/browser/terminal/web-terminal.js +22 -26
  114. package/esm/browser/util/link.d.ts +6 -1
  115. package/esm/browser/util/link.js +11 -0
  116. package/esm/browser/workbench-protocol.d.ts +2 -0
  117. package/esm/browser/workbench-services.d.ts +2 -0
  118. package/esm/browser/workbench-services.js +5 -0
  119. package/esm/browser/workbench.js +3 -0
  120. package/lib/browser/assistant/assistant-thread.d.ts +1 -1
  121. package/lib/browser/assistant/chat-task-source.js +2 -1
  122. package/lib/browser/components/app-contexts.js +10 -8
  123. package/lib/browser/components/chat-asks.d.ts +4 -1
  124. package/lib/browser/components/chat-asks.js +10 -0
  125. package/lib/browser/components/chat-list-row.js +5 -3
  126. package/lib/browser/components/cloud-network.d.ts +18 -0
  127. package/lib/browser/components/cloud-network.js +142 -0
  128. package/lib/browser/components/cloud-sign-in-view.d.ts +1 -1
  129. package/lib/browser/components/composer-box-protocol.d.ts +5 -0
  130. package/lib/browser/components/composer-box.js +9 -12
  131. package/lib/browser/components/composer-media.d.ts +27 -0
  132. package/lib/browser/components/composer-media.js +74 -0
  133. package/lib/browser/components/composer-target.d.ts +2 -2
  134. package/lib/browser/components/composer-target.js +3 -3
  135. package/lib/browser/components/composer.js +1 -0
  136. package/lib/browser/components/folder-picker.d.ts +3 -3
  137. package/lib/browser/components/folder-picker.js +5 -15
  138. package/lib/browser/components/host-view.d.ts +1 -1
  139. package/lib/browser/components/link.d.ts +7 -1
  140. package/lib/browser/components/link.js +25 -6
  141. package/lib/browser/components/markdown.d.ts +2 -2
  142. package/lib/browser/components/markdown.js +75 -3
  143. package/lib/browser/components/relay-services.d.ts +0 -2
  144. package/lib/browser/components/relay-services.js +1 -11
  145. package/lib/browser/components/remote-hosts.d.ts +11 -7
  146. package/lib/browser/components/remote-hosts.js +92 -48
  147. package/lib/browser/components/remote-machines.d.ts +22 -0
  148. package/lib/browser/components/remote-machines.js +59 -0
  149. package/lib/browser/components/remote-prompts.d.ts +2 -3
  150. package/lib/browser/components/remote-prompts.js +3 -15
  151. package/lib/browser/components/remote-steps.d.ts +20 -0
  152. package/lib/browser/components/remote-steps.js +63 -0
  153. package/lib/browser/components/session-view.js +8 -4
  154. package/lib/browser/components/settings-controls.d.ts +3 -1
  155. package/lib/browser/components/settings-controls.js +2 -2
  156. package/lib/browser/components/web-composer.d.ts +1 -1
  157. package/lib/browser/components/web-composer.js +12 -3
  158. package/lib/browser/device/photo-picker.d.ts +11 -3
  159. package/lib/browser/device/photo-picker.js +26 -9
  160. package/lib/browser/device/video-picks.d.ts +25 -0
  161. package/lib/browser/device/video-picks.js +107 -0
  162. package/lib/browser/extension/icons.js +2 -0
  163. package/lib/browser/extension/web-access.js +4 -1
  164. package/lib/browser/extension/web-api-code.d.ts +37 -0
  165. package/lib/browser/extension/web-api-code.js +4 -0
  166. package/lib/browser/extension/web-api-components.d.ts +22 -0
  167. package/lib/browser/extension/web-api-contributions.d.ts +0 -31
  168. package/lib/browser/extension/web-api-menus.d.ts +29 -3
  169. package/lib/browser/extension/web-api-play.d.ts +30 -0
  170. package/lib/browser/extension/web-api-play.js +3 -0
  171. package/lib/browser/extension/web-api-services.d.ts +6 -0
  172. package/lib/browser/extension/web-api-spec.js +5 -0
  173. package/lib/browser/extension/web-api-terminal.d.ts +20 -0
  174. package/lib/browser/extension/web-extension-api.d.ts +12 -17
  175. package/lib/browser/extension/web-extension-context.d.ts +1 -1
  176. package/lib/browser/extension/web-extension-context.js +6 -3
  177. package/lib/browser/extension/web-extension-protocol.d.ts +5 -1
  178. package/lib/browser/extension/web-extension-protocol.js +2 -0
  179. package/lib/browser/extension/web-extension-run.d.ts +6 -4
  180. package/lib/browser/extension/web-extension-run.js +18 -9
  181. package/lib/browser/extension/web-extensions-running.js +38 -7
  182. package/lib/browser/extension/web-on-demand.d.ts +5 -0
  183. package/lib/browser/extension/web-on-demand.js +11 -0
  184. package/lib/browser/i18n/en/assistant.d.ts +3 -0
  185. package/lib/browser/i18n/en/assistant.js +3 -0
  186. package/lib/browser/i18n/en/chat.d.ts +1 -0
  187. package/lib/browser/i18n/en/chat.js +1 -0
  188. package/lib/browser/i18n/en/common.d.ts +1 -0
  189. package/lib/browser/i18n/en/common.js +1 -0
  190. package/lib/browser/i18n/en/discover.d.ts +2 -0
  191. package/lib/browser/i18n/en/discover.js +2 -0
  192. package/lib/browser/i18n/en/service.d.ts +26 -2
  193. package/lib/browser/i18n/en/service.js +34 -10
  194. package/lib/browser/i18n/ja/assistant.js +3 -0
  195. package/lib/browser/i18n/ja/chat.js +1 -0
  196. package/lib/browser/i18n/ja/common.js +1 -0
  197. package/lib/browser/i18n/ja/discover.js +2 -0
  198. package/lib/browser/i18n/ja/service.js +34 -10
  199. package/lib/browser/i18n/locales.d.ts +34 -3
  200. package/lib/browser/i18n/messages.d.ts +33 -2
  201. package/lib/browser/i18n/zh/assistant.js +3 -0
  202. package/lib/browser/i18n/zh/chat.js +1 -0
  203. package/lib/browser/i18n/zh/common.js +1 -0
  204. package/lib/browser/i18n/zh/discover.js +2 -0
  205. package/lib/browser/i18n/zh/service.js +34 -10
  206. package/lib/browser/i18n/zh-tw/assistant.js +3 -0
  207. package/lib/browser/i18n/zh-tw/chat.js +1 -0
  208. package/lib/browser/i18n/zh-tw/common.js +1 -0
  209. package/lib/browser/i18n/zh-tw/discover.js +2 -0
  210. package/lib/browser/i18n/zh-tw/service.js +34 -10
  211. package/lib/browser/markdown/code-renderers.d.ts +6 -1
  212. package/lib/browser/markdown/code-renderers.js +5 -1
  213. package/lib/browser/sandbox/sandbox-runtime-code.js +1 -1
  214. package/lib/browser/sandbox/work/work-api.d.ts +114 -0
  215. package/lib/browser/sandbox/work/work-api.js +99 -0
  216. package/lib/browser/sandbox/work/work-docs.d.ts +19 -0
  217. package/lib/browser/sandbox/work/work-docs.js +69 -0
  218. package/lib/browser/sandbox/work/work-frame.d.ts +28 -0
  219. package/lib/browser/sandbox/work/work-frame.js +160 -0
  220. package/lib/browser/share/shared-extensions.d.ts +2 -1
  221. package/lib/browser/style/conversation.d.ts +1 -1
  222. package/lib/browser/style/conversation.js +10 -0
  223. package/lib/browser/style/dialogs.d.ts +1 -1
  224. package/lib/browser/style/dialogs.js +1 -4
  225. package/lib/browser/style/pages.d.ts +1 -1
  226. package/lib/browser/style/pages.js +10 -1
  227. package/lib/browser/terminal/terminal-osc.d.ts +16 -0
  228. package/lib/browser/terminal/terminal-osc.js +94 -0
  229. package/lib/browser/terminal/web-terminal.d.ts +4 -7
  230. package/lib/browser/terminal/web-terminal.js +25 -29
  231. package/lib/browser/util/link.d.ts +6 -1
  232. package/lib/browser/util/link.js +11 -0
  233. package/lib/browser/workbench-protocol.d.ts +2 -0
  234. package/lib/browser/workbench-services.d.ts +2 -0
  235. package/lib/browser/workbench-services.js +5 -0
  236. package/lib/browser/workbench.js +3 -0
  237. package/package.json +12 -12
@@ -0,0 +1,113 @@
1
+ /**
2
+ * The `ta` of an HTML work (docs/design/ta-works.md 7.2): what a document a model wrote reaches of Ta, from its frame of
3
+ * no origin and no network (WorkDocs). One table, WORK_API: the bridge in the frame is made from it, and the page checks
4
+ * by it what crosses (WorkFrame). The games of ta-play are the first works; what a work may do more (its model, its
5
+ * data) is added here, once.
6
+ */
7
+ /** What a work reads as it starts (`ta.me`, `ta.state`…), and again when its document loads again. */
8
+ export interface WorkValues {
9
+ me: unknown;
10
+ players: unknown[];
11
+ state: Record<string, unknown>;
12
+ solo: boolean;
13
+ saved: unknown;
14
+ /** What it keeps of its own, by key (`ta.put`): the same through its versions, on this device's Ta. */
15
+ data: Record<string, unknown>;
16
+ /** The asks (WorkAsks) the page answers here: the bridge takes the others away, for `ta.ai?.(…)` to tell. */
17
+ can: string[];
18
+ }
19
+ /** What a work does: `ta.set(key, value)`… Each returns nothing to it. */
20
+ export interface WorkCalls {
21
+ set(key: string, value: unknown): void;
22
+ send(data: unknown, to?: string): void;
23
+ save(value: unknown): void;
24
+ /** Keeps a value of its own under a key (`ta.data[key]`); null removes it. */
25
+ put(key: string, value: unknown): void;
26
+ finish(result: unknown): void;
27
+ }
28
+ /**
29
+ * What a work asks and waits for: `await ta.ai('…')`. Each resolves with what the page answers, or rejects with an
30
+ * error of a line (not allowed, a limit reached, no model); where the page answers none, the work has none.
31
+ */
32
+ export interface WorkAsks {
33
+ /** A model of the one who plays (TaWorkPrompt: a text, or { prompt, system, history, maxTokens }): its text. */
34
+ ai(prompt: unknown): Promise<string>;
35
+ }
36
+ /** What a work hears: `ta.on('state', (key, value, by) => …)`… */
37
+ export interface WorkEvents {
38
+ state(key: string, value: unknown, by?: string): void;
39
+ message(data: unknown, from?: string): void;
40
+ players(players: unknown[]): void;
41
+ }
42
+ /**
43
+ * An argument as the page takes it: `key` text of WorkLimits.KEY characters at most; `value` JSON of WorkLimits.VALUE
44
+ * at most; `text` text or nothing; `any` as it is, for the host to read.
45
+ */
46
+ export type WorkArg = 'key' | 'value' | 'text' | 'any';
47
+ /** What changes in the frame's `ta` as a call is made or an event heard: `patch` sets a key of a value (null deletes it), `assign` a value. */
48
+ export interface WorkEffect {
49
+ readonly patch?: keyof WorkValues;
50
+ readonly assign?: keyof WorkValues;
51
+ }
52
+ export interface WorkCallSpec extends WorkEffect {
53
+ readonly args: readonly WorkArg[];
54
+ /** Counted with the others of this name, WorkLimits.PER_SECOND a second (WorkLimits.ASKS for asks), the rest dropped or refused. */
55
+ readonly rate?: 'writes' | 'sends' | 'asks';
56
+ }
57
+ export interface WorkSpec {
58
+ /** Each value, as the frame has it before the page answered. */
59
+ readonly values: {
60
+ readonly [K in keyof WorkValues]: WorkValues[K];
61
+ };
62
+ readonly calls: {
63
+ readonly [K in keyof WorkCalls]: WorkCallSpec;
64
+ };
65
+ readonly asks: {
66
+ readonly [K in keyof WorkAsks]: WorkCallSpec;
67
+ };
68
+ readonly events: {
69
+ readonly [K in keyof WorkEvents]: WorkEffect;
70
+ };
71
+ }
72
+ export declare const WORK_API: WorkSpec;
73
+ /** What the page tells a work: an event, by its name and arguments. */
74
+ export type WorkEmit = <K extends keyof WorkEvents>(name: K, ...args: Parameters<WorkEvents[K]>) => void;
75
+ /**
76
+ * Where a work runs, as its frame's page gives it: what it starts with and, from then on, what it hears (`open`, again
77
+ * each time its document loads), and what it does, checked by WORK_API first. A call the host has not is dropped; an ask
78
+ * it has not, the work has not (WorkValues.can).
79
+ */
80
+ export interface WorkHost extends Partial<WorkCalls>, Partial<WorkAsks> {
81
+ open(emit: WorkEmit): Promise<{
82
+ values: Partial<WorkValues>;
83
+ stop(): void;
84
+ }>;
85
+ }
86
+ export declare namespace WorkLimits {
87
+ /** A key, in characters. */
88
+ const KEY = 64;
89
+ /** A value or a message, as JSON, in characters. */
90
+ const VALUE = 16000;
91
+ /** Writes, and messages, a second each: a work written badly (or on purpose) floods neither the page nor a room. */
92
+ const PER_SECOND = 20;
93
+ /** An error it reports, in characters. */
94
+ const ERROR = 300;
95
+ /** Asks a second: each waits for a model, so a few. */
96
+ const ASKS = 3;
97
+ /** Asks waiting at once; one more is refused. */
98
+ const WAITING = 4;
99
+ }
100
+ /** How many a second: a window of a second, the rest refused. */
101
+ export declare class WorkRate {
102
+ protected readonly perSecond: number;
103
+ protected start: number;
104
+ protected count: number;
105
+ constructor(perSecond?: number);
106
+ allow(now?: number): boolean;
107
+ }
108
+ export declare namespace WorkCheck {
109
+ /** A value a work may keep or send: JSON of WorkLimits.VALUE characters at most; undefined when it is not. */
110
+ function value(input: unknown): unknown;
111
+ /** The arguments of a call as WORK_API takes them; undefined when one is not as it says. */
112
+ function args(spec: WorkCallSpec, given: readonly unknown[]): unknown[] | undefined;
113
+ }
@@ -0,0 +1,95 @@
1
+ /**
2
+ * The `ta` of an HTML work (docs/design/ta-works.md 7.2): what a document a model wrote reaches of Ta, from its frame of
3
+ * no origin and no network (WorkDocs). One table, WORK_API: the bridge in the frame is made from it, and the page checks
4
+ * by it what crosses (WorkFrame). The games of ta-play are the first works; what a work may do more (its model, its
5
+ * data) is added here, once.
6
+ */
7
+ export const WORK_API = {
8
+ values: { me: null, players: [], state: {}, solo: true, saved: null, data: {}, can: [] },
9
+ calls: {
10
+ set: { args: ['key', 'value'], rate: 'writes', patch: 'state' },
11
+ send: { args: ['value', 'text'], rate: 'sends' },
12
+ save: { args: ['value'], rate: 'writes', assign: 'saved' },
13
+ put: { args: ['key', 'value'], rate: 'writes', patch: 'data' },
14
+ finish: { args: ['any'] },
15
+ },
16
+ asks: { ai: { args: ['any'], rate: 'asks' } },
17
+ events: { state: { patch: 'state' }, message: {}, players: { assign: 'players' } },
18
+ };
19
+ export var WorkLimits;
20
+ (function (WorkLimits) {
21
+ /** A key, in characters. */
22
+ WorkLimits.KEY = 64;
23
+ /** A value or a message, as JSON, in characters. */
24
+ WorkLimits.VALUE = 16000;
25
+ /** Writes, and messages, a second each: a work written badly (or on purpose) floods neither the page nor a room. */
26
+ WorkLimits.PER_SECOND = 20;
27
+ /** An error it reports, in characters. */
28
+ WorkLimits.ERROR = 300;
29
+ /** Asks a second: each waits for a model, so a few. */
30
+ WorkLimits.ASKS = 3;
31
+ /** Asks waiting at once; one more is refused. */
32
+ WorkLimits.WAITING = 4;
33
+ })(WorkLimits || (WorkLimits = {}));
34
+ /** How many a second: a window of a second, the rest refused. */
35
+ export class WorkRate {
36
+ constructor(perSecond = WorkLimits.PER_SECOND) {
37
+ this.perSecond = perSecond;
38
+ this.start = 0;
39
+ this.count = 0;
40
+ }
41
+ allow(now = Date.now()) {
42
+ if (now - this.start >= 1000) {
43
+ this.start = now;
44
+ this.count = 0;
45
+ }
46
+ if (this.count >= this.perSecond) {
47
+ return false;
48
+ }
49
+ this.count++;
50
+ return true;
51
+ }
52
+ }
53
+ export var WorkCheck;
54
+ (function (WorkCheck) {
55
+ /** A value a work may keep or send: JSON of WorkLimits.VALUE characters at most; undefined when it is not. */
56
+ function value(input) {
57
+ try {
58
+ const json = JSON.stringify(input !== null && input !== void 0 ? input : null);
59
+ return json.length <= WorkLimits.VALUE ? JSON.parse(json) : undefined;
60
+ }
61
+ catch (_a) {
62
+ return undefined;
63
+ }
64
+ }
65
+ WorkCheck.value = value;
66
+ /** The arguments of a call as WORK_API takes them; undefined when one is not as it says. */
67
+ function args(spec, given) {
68
+ const out = [];
69
+ for (const [index, kind] of spec.args.entries()) {
70
+ const input = given[index];
71
+ if (kind === 'key') {
72
+ if (typeof input !== 'string' || !input || input.length > WorkLimits.KEY) {
73
+ return undefined;
74
+ }
75
+ out.push(input);
76
+ }
77
+ else if (kind === 'value') {
78
+ const checked = value(input);
79
+ if (checked === undefined) {
80
+ return undefined;
81
+ }
82
+ out.push(checked);
83
+ }
84
+ else if (kind === 'text') {
85
+ out.push(typeof input === 'string' ? input.slice(0, WorkLimits.KEY * 4) : undefined);
86
+ }
87
+ else {
88
+ out.push(input);
89
+ }
90
+ }
91
+ return out;
92
+ }
93
+ WorkCheck.args = args;
94
+ })(WorkCheck || (WorkCheck = {}));
95
+ //# sourceMappingURL=work-api.js.map
@@ -0,0 +1,18 @@
1
+ import { type WorkSpec } from './work-api.js';
2
+ /**
3
+ * The document of an HTML work (docs/design/ta-works.md 7.6): it reaches nothing but what it carries. No network (a work
4
+ * cannot send what it was shown anywhere), no forms, no frames; inline scripts and styles, pictures and sounds of data.
5
+ * With the sandbox of its frame (scripts alone: no origin, no storage, no popups, no navigation of the page), it is a
6
+ * page apart from Ta's. Unlike the sandbox of extensions (SandboxDocs.CSP), not even https.
7
+ */
8
+ export declare namespace WorkDocs {
9
+ const CSP = "default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; img-src data: blob:; media-src data: blob:; font-src data:; connect-src 'none'; form-action 'none'; frame-src 'none'; base-uri 'none'";
10
+ const SANDBOX = "allow-scripts";
11
+ /** How the document sits in its frame: a `game` fills it, neither scrolled nor selected; a `page` scrolls as a page does. */
12
+ type Kind = 'game' | 'page';
13
+ /**
14
+ * The document of the frame: the policy and the bridge first, then the work, whose own doctype, html and head the
15
+ * parser folds into these (what it puts in its head still goes to the head).
16
+ */
17
+ function document(html: string, kind?: Kind, spec?: WorkSpec): string;
18
+ }
@@ -0,0 +1,66 @@
1
+ import { SandboxDocs } from '../sandbox-protocol.js';
2
+ import { WORK_API } from './work-api.js';
3
+ /**
4
+ * The document of an HTML work (docs/design/ta-works.md 7.6): it reaches nothing but what it carries. No network (a work
5
+ * cannot send what it was shown anywhere), no forms, no frames; inline scripts and styles, pictures and sounds of data.
6
+ * With the sandbox of its frame (scripts alone: no origin, no storage, no popups, no navigation of the page), it is a
7
+ * page apart from Ta's. Unlike the sandbox of extensions (SandboxDocs.CSP), not even https.
8
+ */
9
+ export var WorkDocs;
10
+ (function (WorkDocs) {
11
+ WorkDocs.CSP = "default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; img-src data: blob:; media-src data: blob:; font-src data:; connect-src 'none'; form-action 'none'; frame-src 'none'; base-uri 'none'";
12
+ WorkDocs.SANDBOX = SandboxDocs.SANDBOX;
13
+ /**
14
+ * What runs in the frame before the work: `window.ta`, made from the spec it is given (WORK_API), talking to the
15
+ * page by messages. ES5, as it is written into every work; it must never throw. An ask (`ta.ai`) is a promise the page
16
+ * answers by its id; one the page does not answer here (`ta.can`) is not there at all. While the page asks (`point`), what
17
+ * the user taps is not the work's: it is outlined, and told to the page as a part they pointed at (TaWorkPoint). Without an origin the frame has no
18
+ * storage: `localStorage` is one of memory, gone with it (`ta.save` keeps what lasts).
19
+ */
20
+ const BRIDGE = `function(S){
21
+ var on={},ready,ta={ready:new Promise(function(r){ready=r}),on:function(t,f){(on[t]=on[t]||[]).push(f)}};
22
+ Object.keys(S.values).forEach(function(k){ta[k]=S.values[k]});
23
+ function put(s,a){if(s.patch){var o=ta[s.patch]||(ta[s.patch]={});if(a[1]===null||a[1]===undefined)delete o[a[0]];else o[a[0]]=a[1]}else if(s.assign)ta[s.assign]=a[0]===undefined?null:a[0]}
24
+ function post(m){m.ta='work';try{parent.postMessage(m,'*')}catch(e){}}
25
+ function emit(t,a){(on[t]||[]).forEach(function(f){try{f.apply(null,a)}catch(e){console.error(e)}})}
26
+ Object.keys(S.calls).forEach(function(n){var s=S.calls[n];ta[n]=function(){var a=[].slice.call(arguments);put(s,a);post({type:'call',name:n,args:a})}});
27
+ var asked={},nid=0;function can(){Object.keys(S.asks).forEach(function(n){if((ta.can||[]).indexOf(n)<0)delete ta[n];else ta[n]=function(){var a=[].slice.call(arguments),id=++nid;return new Promise(function(ok,no){asked[id]=[ok,no];post({type:'ask',id:id,name:n,args:a})})}})}can();
28
+ addEventListener('message',function(e){var m=e.data;if(e.source!==parent||!m||m.ta!=='work')return;
29
+ if(m.type==='init'){Object.keys(S.values).forEach(function(k){if(m.values&&k in m.values)ta[k]=m.values[k]});can();ready(ta);emit('ready',[ta])}
30
+ else if(m.type==='answer'&&asked[m.id]){var w=asked[m.id];delete asked[m.id];if(m.error!==undefined)w[1](new Error(String(m.error)));else w[0](m.value)}
31
+ else if(m.type==='event'&&S.events.hasOwnProperty(m.name)){put(S.events[m.name],m.args||[]);emit(m.name,m.args||[])}
32
+ else if(m.type==='point')point(!!m.on)});
33
+ var pk=null,EAT=['pointerdown','mousedown','mouseup','touchstart','touchend','click','dblclick','contextmenu','keydown','wheel'];
34
+ function path(el){var p=[];while(el&&el.nodeType===1&&el!==document.documentElement){if(el.id&&/^[A-Za-z][A-Za-z0-9_-]*$/.test(el.id)){p.unshift('#'+el.id);break}var i=1,s=el.previousElementSibling;for(;s;s=s.previousElementSibling)if(s.tagName===el.tagName)i++;p.unshift(el.tagName.toLowerCase()+(i>1?':nth-of-type('+i+')':''));el=el.parentElement}return p.join('>')}
35
+ function show(t){var r=t.getBoundingClientRect(),b=pk.box.style;b.display='block';b.left=r.left+'px';b.top=r.top+'px';b.width=r.width+'px';b.height=r.height+'px'}
36
+ function point(on){if(on===!!pk)return;if(!on){EAT.forEach(function(n){removeEventListener(n,pk.eat,true)});removeEventListener('pointermove',pk.over,true);removeEventListener('pointerup',pk.tap,true);pk.box.remove();pk=null;return}
37
+ var b=document.createElement('div');b.setAttribute('style','position:fixed;z-index:2147483647;pointer-events:none;display:none;box-sizing:border-box;border:2px solid #3b82f6;border-radius:4px;background:rgba(59,130,246,.14)');document.documentElement.appendChild(b);
38
+ pk={box:b,eat:function(e){e.preventDefault();e.stopImmediatePropagation()},over:function(e){var t=e.target;if(t&&t.nodeType===1&&t!==b)show(t)},
39
+ tap:function(e){pk.eat(e);var t=e.target;if(!t||t.nodeType!==1||t===b)return;show(t);var tag=t.tagName.toLowerCase(),a=path(t),l;
40
+ if(tag==='canvas'){var r=t.getBoundingClientRect(),x=Math.round((e.clientX-r.left)/(r.width||1)*100),y=Math.round((e.clientY-r.top)/(r.height||1)*100);a+='@'+x+'%,'+y+'%';l='canvas ('+x+'%, '+y+'%)'}
41
+ else{var w=String(t.innerText||t.getAttribute('aria-label')||t.getAttribute('alt')||t.value||'').replace(/\\s+/g,' ').trim().slice(0,40);l=w?tag+' "'+w+'"':tag}
42
+ post({type:'point',anchor:a,label:l,source:String(t.outerHTML).slice(0,4000)})}};
43
+ EAT.forEach(function(n){addEventListener(n,pk.eat,{capture:true,passive:false})});addEventListener('pointermove',pk.over,true);addEventListener('pointerup',pk.tap,true)}
44
+ addEventListener('error',function(e){post({type:'error',message:String(e.message||e.type)})});
45
+ addEventListener('unhandledrejection',function(e){post({type:'error',message:String(e.reason&&e.reason.message||e.reason)})});
46
+ try{var m={},s={getItem:function(k){return k in m?m[k]:null},setItem:function(k,v){m[k]=String(v)},removeItem:function(k){delete m[k]},clear:function(){m={}},key:function(i){return Object.keys(m)[i]||null}};Object.defineProperty(s,'length',{get:function(){return Object.keys(m).length}});
47
+ Object.defineProperty(window,'localStorage',{value:s,configurable:true});Object.defineProperty(window,'sessionStorage',{value:s,configurable:true})}catch(e){}
48
+ window.ta=ta;post({type:'hello'});
49
+ }`;
50
+ const STYLE = {
51
+ game: 'html,body{margin:0;height:100%;overflow:hidden;touch-action:manipulation;-webkit-user-select:none;user-select:none}',
52
+ page: 'html,body{margin:0}',
53
+ };
54
+ /**
55
+ * The document of the frame: the policy and the bridge first, then the work, whose own doctype, html and head the
56
+ * parser folds into these (what it puts in its head still goes to the head).
57
+ */
58
+ function document(html, kind = 'game', spec = WORK_API) {
59
+ const zoom = kind === 'game' ? ', user-scalable=no' : '';
60
+ // In a script: `</` of the spec's JSON would end it.
61
+ const given = JSON.stringify(spec).replace(/</g, '\\u003c');
62
+ return `<!doctype html><html><head><meta charset="utf-8"><meta http-equiv="Content-Security-Policy" content="${WorkDocs.CSP}"><meta name="viewport" content="width=device-width, initial-scale=1${zoom}"><style>${STYLE[kind]}</style><script>(${BRIDGE})(${given});</script></head>${html}`;
63
+ }
64
+ WorkDocs.document = document;
65
+ })(WorkDocs || (WorkDocs = {}));
66
+ //# sourceMappingURL=work-docs.js.map
@@ -0,0 +1,27 @@
1
+ import { TaWorkPoint } from '@celljs/ta-protocol';
2
+ import * as React from 'react';
3
+ import { type WorkHost } from './work-api.js';
4
+ import { WorkDocs } from './work-docs.js';
5
+ export interface WorkFrameProps {
6
+ /** The work's document, as written. */
7
+ html: string;
8
+ title: string;
9
+ /** What it reaches of Ta (WorkHost): give the same one while nothing it holds changes, or it starts again. */
10
+ host: WorkHost;
11
+ kind?: WorkDocs.Kind;
12
+ className?: string;
13
+ style?: React.CSSProperties;
14
+ /** An error of its scripts, a line. */
15
+ onError?(message: string): void;
16
+ /**
17
+ * Set while the user points at a part of it (WebCodeRendererProps.point): what they tap is outlined and given here,
18
+ * not to the work.
19
+ */
20
+ onPoint?(point: TaWorkPoint): void;
21
+ }
22
+ /**
23
+ * An HTML work in a frame the user sees (docs/design/ta-works.md 7.1, L3): a document apart (WorkDocs) that talks to the
24
+ * page by messages alone, only those of its own window heard; what it does checked by WORK_API before it reaches the
25
+ * host. Give it another React `key` to start it again.
26
+ */
27
+ export declare function WorkFrame({ html, title, host, kind, className, style, onError, onPoint }: WorkFrameProps): React.JSX.Element;
@@ -0,0 +1,124 @@
1
+ import { TaWorkPoint } from '@celljs/ta-protocol';
2
+ import * as React from 'react';
3
+ import { WORK_API, WorkCheck, WorkLimits, WorkRate } from './work-api.js';
4
+ import { WorkDocs } from './work-docs.js';
5
+ /**
6
+ * An HTML work in a frame the user sees (docs/design/ta-works.md 7.1, L3): a document apart (WorkDocs) that talks to the
7
+ * page by messages alone, only those of its own window heard; what it does checked by WORK_API before it reaches the
8
+ * host. Give it another React `key` to start it again.
9
+ */
10
+ export function WorkFrame({ html, title, host, kind = 'game', className, style, onError, onPoint }) {
11
+ const frame = React.useRef(null);
12
+ const document = React.useMemo(() => WorkDocs.document(html, kind), [html, kind]);
13
+ const errors = React.useRef(onError);
14
+ errors.current = onError;
15
+ const points = React.useRef(onPoint);
16
+ points.current = onPoint;
17
+ const pointing = !!onPoint;
18
+ React.useEffect(() => {
19
+ var _a, _b;
20
+ (_b = (_a = frame.current) === null || _a === void 0 ? void 0 : _a.contentWindow) === null || _b === void 0 ? void 0 : _b.postMessage({ type: 'point', on: pointing, ta: 'work' }, '*');
21
+ }, [pointing]);
22
+ React.useEffect(() => {
23
+ const element = frame.current;
24
+ if (!element) {
25
+ return;
26
+ }
27
+ const rates = { writes: new WorkRate(), sends: new WorkRate(), asks: new WorkRate(WorkLimits.ASKS) };
28
+ let waiting = 0;
29
+ const toWork = (message) => { var _a; return (_a = element.contentWindow) === null || _a === void 0 ? void 0 : _a.postMessage({ ...message, ta: 'work' }, '*'); };
30
+ let opened;
31
+ let load = 0;
32
+ const start = () => {
33
+ opened === null || opened === void 0 ? void 0 : opened.stop();
34
+ opened = undefined;
35
+ const now = ++load;
36
+ // What it hears before it has what it starts with waits, so that it is not undone by the values.
37
+ let queue = [];
38
+ const emit = (name, ...args) => {
39
+ const event = { type: 'event', name, args };
40
+ queue ? queue.push(event) : toWork(event);
41
+ };
42
+ host.open(emit).then(({ values, stop }) => {
43
+ if (now !== load) {
44
+ stop();
45
+ return;
46
+ }
47
+ opened = { stop };
48
+ // What it may ask is what the host answers, no more: of those, what the host says it answers here.
49
+ const can = Object.keys(WORK_API.asks).filter(name => typeof host[name] === 'function' && (!values.can || values.can.includes(name)));
50
+ toWork({ type: 'init', values: { ...values, can } });
51
+ for (const event of queue !== null && queue !== void 0 ? queue : []) {
52
+ toWork(event);
53
+ }
54
+ queue = undefined;
55
+ }, error => { var _a; return (_a = errors.current) === null || _a === void 0 ? void 0 : _a.call(errors, String(error instanceof Error ? error.message : error).slice(0, WorkLimits.ERROR)); });
56
+ };
57
+ const heard = (event) => {
58
+ var _a, _b, _c;
59
+ var _d;
60
+ if (!element.contentWindow || event.source !== element.contentWindow) {
61
+ return;
62
+ }
63
+ const message = event.data;
64
+ if ((message === null || message === void 0 ? void 0 : message.ta) !== 'work') {
65
+ return;
66
+ }
67
+ if (message.type === 'hello') {
68
+ // Again when the work loaded itself again: heard from now on, as new.
69
+ start();
70
+ if (points.current) {
71
+ toWork({ type: 'point', on: true });
72
+ }
73
+ }
74
+ else if (message.type === 'point') {
75
+ // Heard only while the page asked; what it says is text cut short, for the user to read before it goes anywhere.
76
+ const point = points.current && TaWorkPoint.check(message);
77
+ if (point) {
78
+ (_a = points.current) === null || _a === void 0 ? void 0 : _a.call(points, point);
79
+ }
80
+ }
81
+ else if (message.type === 'error') {
82
+ (_b = errors.current) === null || _b === void 0 ? void 0 : _b.call(errors, String((_d = message.message) !== null && _d !== void 0 ? _d : '').slice(0, WorkLimits.ERROR));
83
+ }
84
+ else if (message.type === 'ask') {
85
+ const id = typeof message.id === 'number' ? message.id : undefined;
86
+ const name = typeof message.name === 'string' && Object.keys(WORK_API.asks).includes(message.name) ? message.name : undefined;
87
+ const answer = (reply) => toWork({ type: 'answer', id, ...reply });
88
+ const ask = name ? host[name] : undefined;
89
+ if (id === undefined) {
90
+ return;
91
+ }
92
+ const args = name ? WorkCheck.args(WORK_API.asks[name], Array.isArray(message.args) ? message.args : []) : undefined;
93
+ if (!ask || !args) {
94
+ answer({ error: 'Not here.' });
95
+ }
96
+ else if (waiting >= WorkLimits.WAITING || !rates.asks.allow()) {
97
+ answer({ error: 'Too many at once: wait for the answers.' });
98
+ }
99
+ else {
100
+ waiting++;
101
+ ask(...args)
102
+ .then(value => { var _a; return answer({ value: (_a = WorkCheck.value(value)) !== null && _a !== void 0 ? _a : null }); }, error => answer({ error: String(error instanceof Error ? error.message : error).slice(0, WorkLimits.ERROR) }))
103
+ .finally(() => waiting--);
104
+ }
105
+ }
106
+ else if (message.type === 'call' && typeof message.name === 'string' && Object.keys(WORK_API.calls).includes(message.name)) {
107
+ const name = message.name;
108
+ const spec = WORK_API.calls[name];
109
+ const args = WorkCheck.args(spec, Array.isArray(message.args) ? message.args : []);
110
+ if (args && (!spec.rate || rates[spec.rate].allow())) {
111
+ (_c = host[name]) === null || _c === void 0 ? void 0 : _c.call(host, ...args);
112
+ }
113
+ }
114
+ };
115
+ window.addEventListener('message', heard);
116
+ return () => {
117
+ window.removeEventListener('message', heard);
118
+ load++;
119
+ opened === null || opened === void 0 ? void 0 : opened.stop();
120
+ };
121
+ }, [host]);
122
+ return (React.createElement("iframe", { ref: frame, className: className, title: title, sandbox: WorkDocs.SANDBOX, srcDoc: document, referrerPolicy: "no-referrer", style: style, "data-own-gestures": "" }));
123
+ }
124
+ //# sourceMappingURL=work-frame.js.map
@@ -1,5 +1,6 @@
1
1
  import * as React from 'react';
2
- import type { WebCodeRendererProps, WebToolRendererResolver } from '../extension/web-api-contributions.js';
2
+ import type { WebCodeRendererProps } from '../extension/web-api-code.js';
3
+ import type { WebToolRendererResolver } from '../extension/web-api-contributions.js';
3
4
  import type { WebCustomMessage, WebExtensionAPI } from '../extension/web-extension-api.js';
4
5
  import type { TaSettings } from '../settings/settings-protocol.js';
5
6
  /** What the web extensions that draw in conversations registered: by language, by type of message, for tools. */