@celljs/ta-web 4.35.0 → 4.36.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 (173) hide show
  1. package/esm/browser/assistant/assistant-thread.js +2 -2
  2. package/esm/browser/assistant/mic-capture.d.ts +34 -0
  3. package/esm/browser/assistant/mic-capture.js +87 -0
  4. package/esm/browser/assistant/realtime-voice.d.ts +2 -2
  5. package/esm/browser/assistant/realtime-voice.js +6 -15
  6. package/esm/browser/components/board.d.ts +2 -2
  7. package/esm/browser/components/board.js +2 -2
  8. package/esm/browser/components/cloud-sign-in-view.d.ts +1 -1
  9. package/esm/browser/components/composer-box-hooks.d.ts +12 -0
  10. package/esm/browser/components/composer-box-hooks.js +12 -0
  11. package/esm/browser/components/composer-box-protocol.d.ts +12 -1
  12. package/esm/browser/components/composer-box.js +14 -11
  13. package/esm/browser/components/composer.js +69 -3
  14. package/esm/browser/components/extension-settings.d.ts +7 -0
  15. package/esm/browser/components/extension-settings.js +32 -0
  16. package/esm/browser/components/host-view.d.ts +1 -1
  17. package/esm/browser/components/message-list.js +3 -3
  18. package/esm/browser/components/message-steps.js +3 -3
  19. package/esm/browser/components/phone-shell.d.ts +2 -2
  20. package/esm/browser/components/request-error.d.ts +9 -0
  21. package/esm/browser/components/request-error.js +21 -0
  22. package/esm/browser/components/settings-more.js +7 -24
  23. package/esm/browser/components/storage-settings.d.ts +17 -0
  24. package/esm/browser/components/storage-settings.js +145 -0
  25. package/esm/browser/extension/web-api-contributions.d.ts +6 -7
  26. package/esm/browser/extension/web-api-spec.js +2 -0
  27. package/esm/browser/extension/web-api-targets.d.ts +11 -0
  28. package/esm/browser/extension/web-api-targets.js +2 -0
  29. package/esm/browser/extension/web-extension-api.d.ts +5 -1
  30. package/esm/browser/extension/web-extension-context.d.ts +3 -2
  31. package/esm/browser/extension/web-extension-context.js +11 -15
  32. package/esm/browser/extension/web-extension-run.d.ts +2 -0
  33. package/esm/browser/extension/web-extension-run.js +12 -0
  34. package/esm/browser/extension/web-extensions-running.d.ts +2 -0
  35. package/esm/browser/extension/web-extensions-running.js +5 -0
  36. package/esm/browser/extension/web-extensions.js +1 -0
  37. package/esm/browser/game/game-control.d.ts +6 -0
  38. package/esm/browser/game/game-control.js +28 -0
  39. package/esm/browser/game/game-host.d.ts +9 -2
  40. package/esm/browser/game/game-host.js +5 -1
  41. package/esm/browser/game/game-protocol.d.ts +8 -0
  42. package/esm/browser/game/game-runner.d.ts +7 -1
  43. package/esm/browser/game/game-runner.js +24 -2
  44. package/esm/browser/game/game-target.d.ts +22 -0
  45. package/esm/browser/game/game-target.js +84 -0
  46. package/esm/browser/game/game-util.d.ts +2 -0
  47. package/esm/browser/game/game-util.js +2 -0
  48. package/esm/browser/game/game-view.d.ts +5 -2
  49. package/esm/browser/game/game-view.js +4 -4
  50. package/esm/browser/game/game3d-protocol.d.ts +3 -1
  51. package/esm/browser/game/game3d-runner.d.ts +6 -1
  52. package/esm/browser/game/game3d-runner.js +26 -2
  53. package/esm/browser/i18n/en/chat.d.ts +4 -0
  54. package/esm/browser/i18n/en/chat.js +4 -0
  55. package/esm/browser/i18n/en/settings.d.ts +15 -0
  56. package/esm/browser/i18n/en/settings.js +15 -0
  57. package/esm/browser/i18n/ja/chat.js +4 -0
  58. package/esm/browser/i18n/ja/settings.js +15 -0
  59. package/esm/browser/i18n/locales.d.ts +20 -1
  60. package/esm/browser/i18n/messages.d.ts +19 -0
  61. package/esm/browser/i18n/zh/chat.js +4 -0
  62. package/esm/browser/i18n/zh/settings.js +15 -0
  63. package/esm/browser/i18n/zh-tw/chat.js +4 -0
  64. package/esm/browser/i18n/zh-tw/settings.js +15 -0
  65. package/esm/browser/index.d.ts +2 -0
  66. package/esm/browser/index.js +2 -0
  67. package/esm/browser/sandbox/remote/remote-copy.d.ts +1 -0
  68. package/esm/browser/sandbox/remote/remote-copy.js +16 -0
  69. package/esm/browser/sandbox/sandbox-runtime-code.js +1 -1
  70. package/esm/browser/settings/agent-settings.js +5 -1
  71. package/esm/browser/style/pages.d.ts +1 -1
  72. package/esm/browser/style/pages.js +2 -0
  73. package/esm/browser/style/surfaces.d.ts +1 -1
  74. package/esm/browser/style/surfaces.js +2 -3
  75. package/esm/browser/targets/targets-protocol.d.ts +54 -0
  76. package/esm/browser/targets/targets-protocol.js +34 -0
  77. package/esm/browser/targets/targets.d.ts +13 -0
  78. package/esm/browser/targets/targets.js +64 -0
  79. package/esm/browser/util/composer.d.ts +4 -2
  80. package/esm/browser/util/composer.js +7 -1
  81. package/esm/browser/util/message.d.ts +6 -0
  82. package/esm/browser/util/message.js +21 -0
  83. package/esm/browser/util/process.d.ts +1 -0
  84. package/esm/browser/util/process.js +6 -1
  85. package/esm/browser/util/progress.d.ts +2 -1
  86. package/esm/browser/util/progress.js +2 -11
  87. package/lib/browser/assistant/assistant-thread.js +2 -2
  88. package/lib/browser/assistant/mic-capture.d.ts +35 -0
  89. package/lib/browser/assistant/mic-capture.js +91 -0
  90. package/lib/browser/assistant/realtime-voice.d.ts +2 -2
  91. package/lib/browser/assistant/realtime-voice.js +6 -15
  92. package/lib/browser/components/board.d.ts +2 -2
  93. package/lib/browser/components/board.js +2 -2
  94. package/lib/browser/components/cloud-sign-in-view.d.ts +1 -1
  95. package/lib/browser/components/composer-box-hooks.d.ts +12 -0
  96. package/lib/browser/components/composer-box-hooks.js +13 -0
  97. package/lib/browser/components/composer-box-protocol.d.ts +12 -1
  98. package/lib/browser/components/composer-box.js +13 -10
  99. package/lib/browser/components/composer.js +69 -3
  100. package/lib/browser/components/extension-settings.d.ts +8 -0
  101. package/lib/browser/components/extension-settings.js +69 -0
  102. package/lib/browser/components/host-view.d.ts +1 -1
  103. package/lib/browser/components/message-list.js +3 -3
  104. package/lib/browser/components/message-steps.js +3 -3
  105. package/lib/browser/components/phone-shell.d.ts +2 -2
  106. package/lib/browser/components/request-error.d.ts +10 -0
  107. package/lib/browser/components/request-error.js +57 -0
  108. package/lib/browser/components/settings-more.js +6 -23
  109. package/lib/browser/components/storage-settings.d.ts +18 -0
  110. package/lib/browser/components/storage-settings.js +182 -0
  111. package/lib/browser/extension/web-api-contributions.d.ts +6 -7
  112. package/lib/browser/extension/web-api-spec.js +2 -0
  113. package/lib/browser/extension/web-api-targets.d.ts +12 -0
  114. package/lib/browser/extension/web-api-targets.js +3 -0
  115. package/lib/browser/extension/web-extension-api.d.ts +5 -1
  116. package/lib/browser/extension/web-extension-context.d.ts +3 -2
  117. package/lib/browser/extension/web-extension-context.js +11 -15
  118. package/lib/browser/extension/web-extension-run.d.ts +2 -0
  119. package/lib/browser/extension/web-extension-run.js +12 -0
  120. package/lib/browser/extension/web-extensions-running.d.ts +2 -0
  121. package/lib/browser/extension/web-extensions-running.js +5 -0
  122. package/lib/browser/extension/web-extensions.js +1 -0
  123. package/lib/browser/game/game-control.d.ts +6 -0
  124. package/lib/browser/game/game-control.js +28 -0
  125. package/lib/browser/game/game-host.d.ts +9 -2
  126. package/lib/browser/game/game-host.js +5 -1
  127. package/lib/browser/game/game-protocol.d.ts +8 -0
  128. package/lib/browser/game/game-runner.d.ts +7 -1
  129. package/lib/browser/game/game-runner.js +24 -2
  130. package/lib/browser/game/game-target.d.ts +23 -0
  131. package/lib/browser/game/game-target.js +87 -0
  132. package/lib/browser/game/game-util.d.ts +2 -0
  133. package/lib/browser/game/game-util.js +2 -0
  134. package/lib/browser/game/game-view.d.ts +5 -2
  135. package/lib/browser/game/game-view.js +4 -4
  136. package/lib/browser/game/game3d-protocol.d.ts +3 -1
  137. package/lib/browser/game/game3d-runner.d.ts +6 -1
  138. package/lib/browser/game/game3d-runner.js +26 -2
  139. package/lib/browser/i18n/en/chat.d.ts +4 -0
  140. package/lib/browser/i18n/en/chat.js +4 -0
  141. package/lib/browser/i18n/en/settings.d.ts +15 -0
  142. package/lib/browser/i18n/en/settings.js +15 -0
  143. package/lib/browser/i18n/ja/chat.js +4 -0
  144. package/lib/browser/i18n/ja/settings.js +15 -0
  145. package/lib/browser/i18n/locales.d.ts +20 -1
  146. package/lib/browser/i18n/messages.d.ts +19 -0
  147. package/lib/browser/i18n/zh/chat.js +4 -0
  148. package/lib/browser/i18n/zh/settings.js +15 -0
  149. package/lib/browser/i18n/zh-tw/chat.js +4 -0
  150. package/lib/browser/i18n/zh-tw/settings.js +15 -0
  151. package/lib/browser/index.d.ts +2 -0
  152. package/lib/browser/index.js +2 -0
  153. package/lib/browser/sandbox/remote/remote-copy.d.ts +1 -0
  154. package/lib/browser/sandbox/remote/remote-copy.js +16 -0
  155. package/lib/browser/sandbox/sandbox-runtime-code.js +1 -1
  156. package/lib/browser/settings/agent-settings.js +5 -1
  157. package/lib/browser/style/pages.d.ts +1 -1
  158. package/lib/browser/style/pages.js +2 -0
  159. package/lib/browser/style/surfaces.d.ts +1 -1
  160. package/lib/browser/style/surfaces.js +2 -3
  161. package/lib/browser/targets/targets-protocol.d.ts +55 -0
  162. package/lib/browser/targets/targets-protocol.js +37 -0
  163. package/lib/browser/targets/targets.d.ts +14 -0
  164. package/lib/browser/targets/targets.js +67 -0
  165. package/lib/browser/util/composer.d.ts +4 -2
  166. package/lib/browser/util/composer.js +7 -1
  167. package/lib/browser/util/message.d.ts +6 -0
  168. package/lib/browser/util/message.js +21 -0
  169. package/lib/browser/util/process.d.ts +1 -0
  170. package/lib/browser/util/process.js +6 -1
  171. package/lib/browser/util/progress.d.ts +2 -1
  172. package/lib/browser/util/progress.js +2 -11
  173. package/package.json +7 -7
@@ -0,0 +1,182 @@
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.StorageSettingsUtil = void 0;
37
+ exports.useStorageSection = useStorageSection;
38
+ const ta_protocol_1 = require("@celljs/ta-protocol");
39
+ const lucide_react_1 = require("lucide-react");
40
+ const React = __importStar(require("react"));
41
+ const hooks_1 = require("../hooks");
42
+ const use_t_1 = require("../i18n/use-t");
43
+ const busy_1 = require("./busy");
44
+ const extension_settings_1 = require("./extension-settings");
45
+ const icon_1 = require("./icon");
46
+ const settings_controls_1 = require("./settings-controls");
47
+ var StorageSettingsUtil;
48
+ (function (StorageSettingsUtil) {
49
+ /** 512 KB, 300 MB, 1.2 GB: as a person reads what a store takes. */
50
+ function size(bytes) {
51
+ if (bytes < 1024 * 1024) {
52
+ return `${Math.max(bytes > 0 ? 1 : 0, Math.round(bytes / 1024))} KB`;
53
+ }
54
+ if (bytes < 1024 ** 3) {
55
+ return `${Math.round(bytes / 1024 ** 2)} MB`;
56
+ }
57
+ return `${(bytes / 1024 ** 3).toFixed(bytes < 10 * 1024 ** 3 ? 1 : 0)} GB`;
58
+ }
59
+ StorageSettingsUtil.size = size;
60
+ /** A limit of megabytes as chosen: 500 MB, 2 GB. */
61
+ function megabytes(mb) {
62
+ return mb >= 1024 && mb % 1024 === 0 ? `${mb / 1024} GB` : `${mb} MB`;
63
+ }
64
+ StorageSettingsUtil.megabytes = megabytes;
65
+ /** What all the stores take, those whose usage was read. */
66
+ function total(stores) {
67
+ return stores.reduce((sum, store) => { var _a; return sum + ((_a = store.bytes) !== null && _a !== void 0 ? _a : 0); }, 0);
68
+ }
69
+ StorageSettingsUtil.total = total;
70
+ })(StorageSettingsUtil || (exports.StorageSettingsUtil = StorageSettingsUtil = {}));
71
+ /** The stores of ta serve (TaSettingsServer.listStorage): undefined while read, null from a Ta service of before. */
72
+ function useStores() {
73
+ const server = (0, hooks_1.useSettingsServer)();
74
+ const [, notices] = (0, hooks_1.useNotices)();
75
+ const [stores, setStores] = React.useState();
76
+ const read = React.useCallback(() => {
77
+ Promise.resolve()
78
+ .then(() => (server.listStorage ? server.listStorage() : null))
79
+ .then(setStores, () => setStores(null));
80
+ }, [server]);
81
+ React.useEffect(read, [read]);
82
+ const setLimit = async (store, kind, value) => {
83
+ var _a;
84
+ // The default again is no setting of the user's: it follows the default if that changes.
85
+ const next = await ((_a = server.setStorageLimits) === null || _a === void 0 ? void 0 : _a.call(server, store.id, { [kind]: value === store.defaults[kind] ? null : value }));
86
+ if (next) {
87
+ setStores(all => all === null || all === void 0 ? void 0 : all.map(each => (each.id === next.id ? next : each)));
88
+ }
89
+ };
90
+ const clear = async (store) => {
91
+ var _a;
92
+ var _b;
93
+ const freed = (_b = (await ((_a = server.clearStorage) === null || _a === void 0 ? void 0 : _a.call(server, store.id)))) !== null && _b !== void 0 ? _b : 0;
94
+ read();
95
+ return freed;
96
+ };
97
+ return { stores, setLimit, clear, notices };
98
+ }
99
+ /** A limit of a store as a choice of its own words: "Keep 30 days", "Keep all". */
100
+ function LimitSelect({ store, kind, onChange }) {
101
+ var _a;
102
+ const t = (0, use_t_1.useT)();
103
+ const [busy, setBusy] = React.useState(false);
104
+ const value = (_a = store.limits[kind]) !== null && _a !== void 0 ? _a : 0;
105
+ const list = ta_protocol_1.TaStorageUtil.choices(kind === 'keepDays' ? store.choices.days : store.choices.mb, value);
106
+ const label = (n) => kind === 'keepDays'
107
+ ? n
108
+ ? t('ta.storage.keep', { days: n })
109
+ : t('ta.storage.keepAll')
110
+ : n
111
+ ? t('ta.storage.max', { size: StorageSettingsUtil.megabytes(n) })
112
+ : t('ta.storage.maxNone');
113
+ return (React.createElement("select", { className: "ta-input ta-select ta-storage-select", "aria-label": t(kind === 'keepDays' ? 'ta.storage.keepLabel' : 'ta.storage.maxLabel'), value: value, disabled: busy, onChange: event => {
114
+ setBusy(true);
115
+ void onChange(Number(event.target.value)).finally(() => setBusy(false));
116
+ } }, list.map(n => (React.createElement("option", { key: n, value: n }, label(n))))));
117
+ }
118
+ /** Clears a store, once the user said so; busy while it runs. */
119
+ function ClearButton({ label, onClear }) {
120
+ const [busy, run] = (0, busy_1.useBusy)();
121
+ return React.createElement(icon_1.IconButton, { icon: lucide_react_1.Trash2, label: label, busy: busy, onClick: () => void run(onClear) });
122
+ }
123
+ /**
124
+ * Settings → Storage (docs/design/ta-storage.md): what Ta and its packages keep on this computer, each store with what it
125
+ * takes, the limits it is kept to (days, size) as the user sets them, and clearing it; the rows of extensions that are a
126
+ * detail of a store (WebSettingsSection.storage) under it, those of a store not listed at the end.
127
+ */
128
+ function useStorageSection(details) {
129
+ const t = (0, use_t_1.useT)();
130
+ const language = (0, use_t_1.useLanguage)();
131
+ const { stores, setLimit, clear, notices } = useStores();
132
+ if (stores === null && details.length === 0) {
133
+ return undefined;
134
+ }
135
+ const words = (text) => ta_protocol_1.TaLanguageUtil.pick(language, text);
136
+ const failed = (error) => {
137
+ notices.error(error);
138
+ };
139
+ const onClear = async (store) => {
140
+ const name = words(store.title);
141
+ const sure = await notices.confirm({
142
+ title: t('ta.storage.clearConfirm', { name }),
143
+ message: store.hint && words(store.hint),
144
+ confirmLabel: t('ta.storage.clear'),
145
+ danger: true,
146
+ });
147
+ if (!sure) {
148
+ return;
149
+ }
150
+ try {
151
+ notices.notify(t('ta.storage.freed', { size: StorageSettingsUtil.size(await clear(store)) }), { level: 'success' });
152
+ }
153
+ catch (error) {
154
+ failed(error);
155
+ }
156
+ };
157
+ const storeRow = (store) => {
158
+ const title = words(store.title);
159
+ const hint = store.hint && words(store.hint);
160
+ const usage = store.bytes === undefined ? undefined : t('ta.storage.usage', { size: StorageSettingsUtil.size(store.bytes) });
161
+ const kinds = ['keepDays', 'maxMB'].filter(kind => store.defaults[kind] !== undefined);
162
+ return (0, settings_controls_1.row)(`storage:${store.id}`, [title, hint, t('ta.storage.title')], React.createElement(settings_controls_1.Row, { label: title, description: [usage, hint].filter(Boolean).join(' · ') },
163
+ kinds.map(kind => (React.createElement(LimitSelect, { key: kind, store: store, kind: kind, onChange: value => setLimit(store, kind, value).catch(failed) }))),
164
+ store.clearable && React.createElement(ClearButton, { label: t('ta.storage.clear'), onClear: () => onClear(store) })));
165
+ };
166
+ const listed = new Set((stores !== null && stores !== void 0 ? stores : []).map(store => store.id));
167
+ const rows = stores
168
+ ? [
169
+ (0, settings_controls_1.row)('storage', [t('ta.storage.title'), t('ta.storage.hint'), 'storage', 'disk'], React.createElement(settings_controls_1.Row, { label: t('ta.storage.total', { size: StorageSettingsUtil.size(StorageSettingsUtil.total(stores)) }), description: t('ta.storage.hint') })),
170
+ ...stores.flatMap(store => [storeRow(store), ...details.filter(entry => entry.section.storage === store.id).flatMap(extension_settings_1.extensionRows)]),
171
+ ]
172
+ : [];
173
+ return {
174
+ id: 'storage',
175
+ title: t('ta.storage.title'),
176
+ icon: lucide_react_1.HardDrive,
177
+ // Last of General but for the keys and About.
178
+ order: 800,
179
+ rows: [...rows, ...(stores === undefined ? [] : details.filter(entry => { var _a; return !listed.has((_a = entry.section.storage) !== null && _a !== void 0 ? _a : ''); }).flatMap(extension_settings_1.extensionRows))],
180
+ };
181
+ }
182
+ //# sourceMappingURL=storage-settings.js.map
@@ -35,11 +35,13 @@ export interface WebSettingsSection {
35
35
  /** Smaller first among those of extensions in its group, then as registered; default 100 (negative: before Ta's). */
36
36
  order?: number;
37
37
  rows: WebSettingRow[];
38
+ /** A store of Settings → Storage (TaStorageInfo.id): its rows show under it there; older Ta apps list it as a section. */
39
+ storage?: string;
38
40
  /**
39
41
  * Models without signing in to a service (coding agents to install): the first page, which asks to sign in, shows the
40
42
  * section as a card beside accounts and API keys, `hint` under its title naming examples as theirs do
41
- * (`CodeBuddy · Codex`); picked, its rows are there, and the page goes on by itself once Ta has models.
42
- * Newer than some Ta apps, which do not show it there.
43
+ * (`CodeBuddy · Codex`); picked, its rows are there, and the page goes on by itself once Ta has models. Newer than
44
+ * some Ta apps, which do not show it there.
43
45
  */
44
46
  signIn?: {
45
47
  hint: WebLabel;
@@ -148,16 +150,13 @@ export interface WebView {
148
150
  * chats. `panel`: a tool of the workbench beside the conversation, as the explorer or the terminal
149
151
  * of an IDE: its `+` and its empty state list it, and it opens as one of its tabs. `launcher`: a
150
152
  * section of what a phone pulls down over its first tab (a button of the rail elsewhere), as Recent and
151
- * Mine. `board`: a card of the board a phone brings out with a swipe to the left over its first tab (a
153
+ * Mine. `board`: a card of the board a phone brings in from the left with a swipe to the right over its first tab (a
152
154
  * button of the rail elsewhere), which the user takes off, puts back and orders (ta-launcher.md).
153
155
  */
154
156
  location?: WebViewLocation;
155
157
  /** Smaller first among those of its location; default 100. */
156
158
  order?: number;
157
- /**
158
- * A page: its … where a list shows it (the sidebar view that leads to it), in sections set apart by
159
- * a line; read each time the menu opens, so it can say what holds now.
160
- */
159
+ /** A page: its … where a list shows it (the sidebar view that leads to it), in sections set apart by a line; read as it opens. */
161
160
  menu?(): WebMenuItem[][];
162
161
  /**
163
162
  * Its top bar, in place of the title: for a sidebar view, the row above it (a search, a button
@@ -60,6 +60,7 @@ exports.WEB_UI_SPEC = {
60
60
  doubleInChats: value(B),
61
61
  useDevice: peek(B),
62
62
  showView: call(B),
63
+ openSettings: fire(B),
63
64
  showChats: fire(B),
64
65
  custom: hold(B, ['C']),
65
66
  openEditor: fire(B, [EDITOR]),
@@ -193,6 +194,7 @@ exports.WEB_API_SPEC = {
193
194
  files: page,
194
195
  remote: page,
195
196
  screenShare: page,
197
+ targets: page,
196
198
  onScreenShareEvent: page,
197
199
  settings: page,
198
200
  rooms: page,
@@ -0,0 +1,12 @@
1
+ /** Part of the web extension API (web-extension-api.ts, which exports it all): what a program may work on the page. */
2
+ import type { WebTargets } from '../targets/targets-protocol';
3
+ export type { TargetEvent, TargetSpec, WebTargets } from '../targets/targets-protocol';
4
+ export interface WebTargetsAPI {
5
+ /**
6
+ * What a program may work on its own clock (docs/design/ta-reflex.md): register a canvas, an editor, anything that
7
+ * says what is on it (`observe`) and takes actions (`act`), while it is there; the games of `ui.Game` and
8
+ * `ui.Game3D` are registered by the page. Newer than some Ta apps: `pi.targets?.…`.
9
+ */
10
+ readonly targets?: WebTargets;
11
+ }
12
+ //# sourceMappingURL=web-api-targets.d.ts.map
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=web-api-targets.js.map
@@ -14,6 +14,7 @@ import type { WebHomeUI, WebPartnersAPI, WebPartnersUI } from './web-api-home';
14
14
  import type { WebFileRef, WebMenus } from './web-api-menus';
15
15
  import type { WebServices } from './web-api-services';
16
16
  import type { WebPackageStorage } from './web-api-storage';
17
+ import type { WebTargetsAPI } from './web-api-targets';
17
18
  import type { WebTerminal, WebTerminalOptions } from './web-api-terminal';
18
19
  import type { WebPageInfo } from './web-pages';
19
20
  export type { Mood } from '../avatar/dino-avatar';
@@ -30,13 +31,14 @@ export type * from './web-api-home';
30
31
  export type * from './web-api-menus';
31
32
  export type * from './web-api-services';
32
33
  export type * from './web-api-storage';
34
+ export type * from './web-api-targets';
33
35
  export type * from './web-api-terminal';
34
36
  export type { WebPageInfo, WebPageState } from './web-pages';
35
37
  /**
36
38
  * What a web extension gets: the web client's side of pi's extension API, its names where they mean the same. A web
37
39
  * extension is one ES module without imports, the `web` part of a pi package (TaWebExtensionInfo): a {@link WebExtensionFactory}.
38
40
  */
39
- export interface WebExtensionAPI extends WebServices, WebPartnersAPI, WebMenus, WebCallsAPI, WebChatTagsAPI {
41
+ export interface WebExtensionAPI extends WebServices, WebPartnersAPI, WebMenus, WebCallsAPI, WebChatTagsAPI, WebTargetsAPI {
40
42
  /** The React of the page: an extension brings no React of its own. */
41
43
  readonly React: typeof React;
42
44
  readonly ui: WebExtensionUI;
@@ -316,6 +318,8 @@ export interface WebExtensionUI extends WebHomeUI, WebPartnersUI, WebEditorsUI,
316
318
  * The name of an extension alone opens its first page. Resolves whether there was such a view.
317
319
  */
318
320
  showView(id: string): Promise<boolean>;
321
+ /** Opens the settings at a section of Ta's (`storage`, `navigation`) or none. Newer than some Ta apps: `pi.ui.openSettings?.(…)`. */
322
+ openSettings?(section?: string): void;
319
323
  /**
320
324
  * Shows the list of chats (on a phone its tab); with `busy`, only the conversations of the user's own going on
321
325
  * (those that wait for them, answer now, or said something unseen), until the user clears it; on a phone these are
@@ -7,6 +7,7 @@ import type { TaSessionNotices } from '../notices/session-notices';
7
7
  import { type TaScreen } from '../screen/screen-protocol';
8
8
  import type { TaSettings } from '../settings/settings-protocol';
9
9
  import type { TaState } from '../state/state-protocol';
10
+ import { type TaTargets } from '../targets/targets-protocol';
10
11
  import type { TaWorkbench } from '../workbench-protocol';
11
12
  import type { WebCodeRendererProps } from './web-api-contributions';
12
13
  import type { WebEditorTabs } from './web-editor-tabs';
@@ -29,6 +30,8 @@ export interface WebExtensionContextHost {
29
30
  readonly persisted: TaState;
30
31
  /** The parts of the screen and where the shell is (docs/design/ta-app-use.md 3). */
31
32
  readonly screen: TaScreen;
33
+ /** What programs may work on the page (docs/design/ta-reflex.md 4). */
34
+ readonly targets: TaTargets;
32
35
  /** What the extensions registered changed: the page shows it. */
33
36
  publish(): void;
34
37
  /** Runs what the extension gave, its failure logged rather than thrown. */
@@ -50,8 +53,6 @@ export declare class WebExtensionContext {
50
53
  static marked(server: TaServer, mark: (text: string) => string): TaServer;
51
54
  /** A renderer of code whose `send` (a choice tapped in it) says it came from the extension. */
52
55
  static replying(Renderer: React.ComponentType<WebCodeRendererProps>, mark: (text: string) => string): React.ComponentType<WebCodeRendererProps>;
53
- /** A path of a file of a package, relative to it and inside it (`./models/rex.glb`, `models\rex.glb`: `models/rex.glb`). */
54
- static packagePath(path: string): string;
55
56
  /** Monaco and the games in the theme and language of the settings, the same component for every extension. */
56
57
  protected readonly codeEditor: (props: CodeEditorProps) => React.FunctionComponentElement<CodeEditorProps & {
57
58
  settings: TaSettings;
@@ -80,6 +80,7 @@ const game_view_1 = require("../game/game-view");
80
80
  const messages_1 = require("../i18n/messages");
81
81
  const use_t_1 = require("../i18n/use-t");
82
82
  const screen_protocol_1 = require("../screen/screen-protocol");
83
+ const targets_protocol_1 = require("../targets/targets-protocol");
83
84
  const web_terminal_1 = require("../terminal/web-terminal");
84
85
  const desktop_1 = require("../util/desktop");
85
86
  const file_drag_1 = require("../util/file-drag");
@@ -144,24 +145,13 @@ class WebExtensionContext {
144
145
  return React.createElement(Renderer, { ...props, send: marked });
145
146
  };
146
147
  }
147
- /** A path of a file of a package, relative to it and inside it (`./models/rex.glb`, `models\rex.glb`: `models/rex.glb`). */
148
- static packagePath(path) {
149
- const parts = path
150
- .replace(/\\/g, '/')
151
- .split('/')
152
- .filter(part => part !== '' && part !== '.');
153
- if (/^([a-z]:)?[\\/]/i.test(path) || parts.length === 0 || parts.includes('..')) {
154
- throw new Error(`Not a file inside the package: ${path}`);
155
- }
156
- return parts.join('/');
157
- }
158
148
  /** The games of an extension, which Ta calls by its package's title on the screen unless they are given one. */
159
149
  gamesOf(run) {
160
- const { settings, screen } = this.host;
150
+ const { settings, screen, targets } = this.host;
161
151
  const title = () => (run.loaded.info ? web_pages_1.WebPagesUtil.title(run.loaded.info, settings.state.language) : run.loaded.name);
162
152
  return {
163
- Game: (props) => { var _a; return React.createElement(game_view_1.GameView, { ...props, title: (_a = props.title) !== null && _a !== void 0 ? _a : title(), settings, screen }); },
164
- Game3D: (props) => { var _a; return React.createElement(game_view_1.Game3DView, { ...props, title: (_a = props.title) !== null && _a !== void 0 ? _a : title(), settings, screen }); },
153
+ Game: (props) => { var _a; return React.createElement(game_view_1.GameView, { ...props, title: (_a = props.title) !== null && _a !== void 0 ? _a : title(), settings, screen, targets }); },
154
+ Game3D: (props) => { var _a; return React.createElement(game_view_1.Game3DView, { ...props, title: (_a = props.title) !== null && _a !== void 0 ? _a : title(), settings, screen, targets }); },
165
155
  };
166
156
  }
167
157
  /** The message box of an extension: its drafts under its name, apart from those of the others. */
@@ -214,7 +204,7 @@ class WebExtensionContext {
214
204
  if (!root) {
215
205
  throw new Error(`The web extension ${run.loaded.name} has no files of its own here.`);
216
206
  }
217
- return files.loadable(await workbench.workspace.fileUrl(WebExtensionContext.packagePath(path), root));
207
+ return files.loadable(await workbench.workspace.fileUrl(web_extension_run_1.WebExtensionRunUtil.packagePath(path), root));
218
208
  }),
219
209
  get remote() {
220
210
  return workbench.remote;
@@ -222,6 +212,7 @@ class WebExtensionContext {
222
212
  get screenShare() {
223
213
  return workbench.screenShare;
224
214
  },
215
+ targets: targets_protocol_1.TargetsUtil.forExtension(host.targets, () => run.stopped, subscribe => web_extension_run_1.WebExtensionRunUtil.track(run, subscribe)),
225
216
  onScreenShareEvent: listener => hear(workbench.onScreenShareEvent.bind(workbench), listener),
226
217
  get settings() {
227
218
  return workbench.settings;
@@ -379,6 +370,11 @@ class WebExtensionContext {
379
370
  },
380
371
  useDevice: device_1.useDevice,
381
372
  showView: id => (run.stopped ? Promise.resolve(false) : host.extensions.showView(id)),
373
+ openSettings: section => {
374
+ if (!run.stopped) {
375
+ host.extensions.openSettings(section);
376
+ }
377
+ },
382
378
  showChats: options => {
383
379
  if (!run.stopped) {
384
380
  host.extensions.showChats(!!(options === null || options === void 0 ? void 0 : options.busy));
@@ -58,6 +58,8 @@ export declare namespace WebExtensionRunUtil {
58
58
  function create(loaded: LoadedWebExtension, hash?: string): WebExtensionRun;
59
59
  /** Stops what it registered and subscribed to; it registers nothing more. */
60
60
  function clear(run: WebExtensionRun): void;
61
+ /** A path of a file of a package, relative to it and inside it (`./models/rex.glb`, `models\rex.glb`: `models/rex.glb`). */
62
+ function packagePath(path: string): string;
61
63
  /** Subscribes for the extension: undone when it stops, or by the function returned. */
62
64
  function track(run: WebExtensionRun, subscribe: () => () => void): () => void;
63
65
  /**
@@ -62,6 +62,18 @@ var WebExtensionRunUtil;
62
62
  }
63
63
  }
64
64
  WebExtensionRunUtil.clear = clear;
65
+ /** A path of a file of a package, relative to it and inside it (`./models/rex.glb`, `models\rex.glb`: `models/rex.glb`). */
66
+ function packagePath(path) {
67
+ const parts = path
68
+ .replace(/\\/g, '/')
69
+ .split('/')
70
+ .filter(part => part !== '' && part !== '.');
71
+ if (/^([a-z]:)?[\\/]/i.test(path) || parts.length === 0 || parts.includes('..')) {
72
+ throw new Error(`Not a file inside the package: ${path}`);
73
+ }
74
+ return parts.join('/');
75
+ }
76
+ WebExtensionRunUtil.packagePath = packagePath;
65
77
  /** Subscribes for the extension: undone when it stops, or by the function returned. */
66
78
  function track(run, subscribe) {
67
79
  if (run.stopped) {
@@ -6,6 +6,7 @@ import { TaSessionNotices } from '../notices/session-notices';
6
6
  import { TaScreen } from '../screen/screen-protocol';
7
7
  import { TaSettings } from '../settings/settings-protocol';
8
8
  import { TaState } from '../state/state-protocol';
9
+ import { TaTargets } from '../targets/targets-protocol';
9
10
  import { TaWorkbench } from '../workbench-protocol';
10
11
  import { WebEditorTabs } from './web-editor-tabs';
11
12
  import type { WebExtensionFactory } from './web-extension-api';
@@ -33,6 +34,7 @@ export declare abstract class WebExtensionsRunning {
33
34
  protected readonly persisted: TaState;
34
35
  protected readonly sessionNotices: TaSessionNotices;
35
36
  protected readonly screen: TaScreen;
37
+ protected readonly targets: TaTargets;
36
38
  readonly builtins: BuiltinWebExtension[];
37
39
  readonly tasks: WebTaskBoard;
38
40
  readonly home: WebHomeBoard;
@@ -22,6 +22,7 @@ const web_sandbox_1 = require("../sandbox/web-sandbox");
22
22
  const screen_protocol_1 = require("../screen/screen-protocol");
23
23
  const settings_protocol_1 = require("../settings/settings-protocol");
24
24
  const state_protocol_1 = require("../state/state-protocol");
25
+ const targets_protocol_1 = require("../targets/targets-protocol");
25
26
  const workbench_protocol_1 = require("../workbench-protocol");
26
27
  const web_access_1 = require("./web-access");
27
28
  const web_editor_tabs_1 = require("./web-editor-tabs");
@@ -438,6 +439,10 @@ __decorate([
438
439
  (0, core_1.Autowired)(screen_protocol_1.TaScreen),
439
440
  __metadata("design:type", Object)
440
441
  ], WebExtensionsRunning.prototype, "screen", void 0);
442
+ __decorate([
443
+ (0, core_1.Autowired)(targets_protocol_1.TaTargets),
444
+ __metadata("design:type", Object)
445
+ ], WebExtensionsRunning.prototype, "targets", void 0);
441
446
  __decorate([
442
447
  (0, core_1.Autowired)(web_extension_protocol_1.BuiltinWebExtension),
443
448
  (0, core_1.Optional)(),
@@ -262,6 +262,7 @@ let TaWebExtensionsImpl = class TaWebExtensionsImpl extends web_extensions_runni
262
262
  sessionNotices: this.sessionNotices,
263
263
  persisted: this.persisted,
264
264
  screen: this.screen,
265
+ targets: this.targets,
265
266
  };
266
267
  }
267
268
  };
@@ -93,6 +93,12 @@ export declare class GameControl {
93
93
  press(at: GamePoint, ms: number): Promise<void>;
94
94
  /** Presses a key for `ms`, on the game's element. */
95
95
  key(key: GameKey, ms?: number): Promise<void>;
96
+ /** Half a tap, the pointer pressed (`down`) or let go there: for a program that times its own presses. */
97
+ pointerPress(at: GamePoint, down: boolean): void;
98
+ /** The pointer moved by `dx`, `dy` CSS pixels where it is, as a locked pointer turns a view (`movementX`, `movementY`). */
99
+ nudge(dx: number, dy: number): void;
100
+ /** Half a key press, down or up, on the game's element. */
101
+ keyPress(key: GameKey, down: boolean): void;
96
102
  /** Where Ta's pointer is on the canvas, once it was there. */
97
103
  get at(): GamePoint | undefined;
98
104
  /**
@@ -188,6 +188,34 @@ class GameControl {
188
188
  this.keyEvent('keyup', key);
189
189
  }
190
190
  }
191
+ /** Half a tap, the pointer pressed (`down`) or let go there: for a program that times its own presses. */
192
+ pointerPress(at, down) {
193
+ if (down) {
194
+ this.down(at);
195
+ }
196
+ else {
197
+ this.up(at, true);
198
+ }
199
+ }
200
+ /** The pointer moved by `dx`, `dy` CSS pixels where it is, as a locked pointer turns a view (`movementX`, `movementY`). */
201
+ nudge(dx, dy) {
202
+ var _a, _b;
203
+ const at = (_a = this.last) !== null && _a !== void 0 ? _a : { x: 0.5, y: 0.5 };
204
+ const canvas = this.canvas();
205
+ const view = this.view();
206
+ const init = { ...this.init(canvas, at, 0), movementX: dx, movementY: dy };
207
+ canvas.dispatchEvent(new ((_b = view.PointerEvent) !== null && _b !== void 0 ? _b : view.MouseEvent)('pointermove', {
208
+ ...init,
209
+ pointerId: GameControlUtil.POINTER_ID,
210
+ pointerType: 'mouse',
211
+ isPrimary: true,
212
+ }));
213
+ canvas.dispatchEvent(new view.MouseEvent('mousemove', init));
214
+ }
215
+ /** Half a key press, down or up, on the game's element. */
216
+ keyPress(key, down) {
217
+ this.keyEvent(down ? 'keydown' : 'keyup', key);
218
+ }
191
219
  /** Where Ta's pointer is on the canvas, once it was there. */
192
220
  get at() {
193
221
  return this.last;
@@ -1,7 +1,8 @@
1
1
  import * as React from 'react';
2
2
  import { type TaScreen } from '../screen/screen-protocol';
3
3
  import type { TaSettings } from '../settings/settings-protocol';
4
- import type { GamePage, GameState } from './game-protocol';
4
+ import type { TaTargets } from '../targets/targets-protocol';
5
+ import type { GameObservation, GamePage, GameState } from './game-protocol';
5
6
  /** What GameHost drives of a game of either engine (GameRunner, Game3DRunner). */
6
7
  export interface GameHostRunner {
7
8
  setPage(page: GamePage): void;
@@ -12,6 +13,10 @@ export interface GameHostRunner {
12
13
  readonly sleeping?: boolean;
13
14
  /** What the game says of its round (GameState). */
14
15
  state?(): GameState | undefined;
16
+ /** What is in it now, for a program that plays it (GameObservation). */
17
+ observe?(): GameObservation | undefined;
18
+ /** Waits for a slow player, and goes on. */
19
+ setPaused?(paused: boolean): void;
15
20
  dispose(): void;
16
21
  }
17
22
  /** Starts the game in `element` once its engine is loaded; `fail` for what goes wrong after it started. */
@@ -23,6 +28,8 @@ export interface GameHostProps {
23
28
  title?: string;
24
29
  /** The screen it is a part of, for Ta to see and play it; none on a page Ta does not work (a shared page). */
25
30
  screen?: TaScreen;
31
+ /** The targets of the page, for a program to play it frame by frame (docs/design/ta-reflex.md); none where none plays. */
32
+ targets?: TaTargets;
26
33
  className?: string;
27
34
  style?: React.CSSProperties;
28
35
  }
@@ -36,5 +43,5 @@ export interface GameHostProps {
36
43
  * It is a part of the screen (`game`, GameControl): Ta sees how it stands and taps, moves, presses keys and holds on it
37
44
  * for the user, by events on its canvas that no gesture of the shell starts from.
38
45
  */
39
- export declare function GameHost({ settings: store, start, title, screen, className, style }: GameHostProps): React.JSX.Element;
46
+ export declare function GameHost({ settings: store, start, title, screen, targets, className, style }: GameHostProps): React.JSX.Element;
40
47
  //# sourceMappingURL=game-host.d.ts.map
@@ -42,6 +42,7 @@ const own_gestures_1 = require("../device/own-gestures");
42
42
  const use_t_1 = require("../i18n/use-t");
43
43
  const screen_protocol_1 = require("../screen/screen-protocol");
44
44
  const game_control_1 = require("./game-control");
45
+ const game_target_1 = require("./game-target");
45
46
  const game_util_1 = require("./game-util");
46
47
  /**
47
48
  * The element of a game of a web extension (`ui.Game`, `ui.Game3D`): it fills its parent, starts the game
@@ -53,7 +54,7 @@ const game_util_1 = require("./game-util");
53
54
  * It is a part of the screen (`game`, GameControl): Ta sees how it stands and taps, moves, presses keys and holds on it
54
55
  * for the user, by events on its canvas that no gesture of the shell starts from.
55
56
  */
56
- function GameHost({ settings: store, start, title, screen, className, style }) {
57
+ function GameHost({ settings: store, start, title, screen, targets, className, style }) {
57
58
  var _a;
58
59
  const t = (0, use_t_1.useT)();
59
60
  const settings = React.useSyncExternalStore(listener => store.subscribe(listener), () => store.state);
@@ -76,6 +77,9 @@ function GameHost({ settings: store, start, title, screen, className, style }) {
76
77
  (_a = partId.current) !== null && _a !== void 0 ? _a : (partId.current = game_control_1.GameControlUtil.partId());
77
78
  part.current = game_control_1.GameControl.spec(partId.current, title || t('ta.game.label'), { point: t('ta.game.point'), move: t('ta.game.move'), key: t('ta.game.key'), hold: t('ta.game.hold') }, () => { var _a, _b, _c; return ({ started: !!runner.current, sleeping: (_a = runner.current) === null || _a === void 0 ? void 0 : _a.sleeping, error: errorOf.current, state: (_c = (_b = runner.current) === null || _b === void 0 ? void 0 : _b.state) === null || _c === void 0 ? void 0 : _c.call(_b) }); }, () => control.current);
78
79
  React.useEffect(() => screen === null || screen === void 0 ? void 0 : screen.register(() => part.current), [screen]);
80
+ const named = React.useRef(title);
81
+ named.current = title || t('ta.game.label');
82
+ React.useEffect(() => targets === null || targets === void 0 ? void 0 : targets.register(game_target_1.GameTarget.spec(partId.current, () => named.current, () => runner.current, () => control.current)), [targets]);
79
83
  React.useEffect(() => {
80
84
  const element = host.current;
81
85
  if (!element) {
@@ -1,3 +1,4 @@
1
+ import type { TargetObservation } from '@celljs/ta-protocol';
1
2
  import type * as PhaserModule from 'phaser';
2
3
  import type { Theme } from '../settings/settings-protocol';
3
4
  /**
@@ -43,6 +44,13 @@ export interface GameState {
43
44
  score?: number;
44
45
  over?: boolean;
45
46
  }
47
+ /**
48
+ * What is in a game now, for a program to play it frame by frame (docs/design/ta-reflex.md 4): its things as entities
49
+ * (`{ id, type, box }`, a box from 0 to 1 across and down the canvas, as the player sees it) and what else it says
50
+ * (`data`: the score, the round). A Phaser game sets a function giving it in its registry (GameUtil.OBSERVE_KEY), a
51
+ * 3D one returns it from `observe` of its loop. Read every frame while a program plays: cheap, no allocation it can spare.
52
+ */
53
+ export type GameObservation = Omit<TargetObservation, 't'>;
46
54
  /** A point of the canvas: `x` 0 at its left and 1 at its right, `y` 0 at its top and 1 at its bottom (GameControl). */
47
55
  export interface GamePoint {
48
56
  x: number;
@@ -1,4 +1,4 @@
1
- import type { GameConfig, GameEngine, GameInstance, GamePage, GameState } from './game-protocol';
1
+ import type { GameConfig, GameEngine, GameInstance, GameObservation, GamePage, GameState } from './game-protocol';
2
2
  /**
3
3
  * One game in an element of the page, from its start to its end: Phaser's Game made with the config of the
4
4
  * extension (GameUtil.config), asleep while the element is out of sight, destroyed with it.
@@ -12,15 +12,21 @@ export declare class GameRunner {
12
12
  readonly game: GameInstance;
13
13
  protected page?: GamePage;
14
14
  protected asleep: boolean;
15
+ protected paused: boolean;
15
16
  protected disposed: boolean;
16
17
  constructor(engine: GameEngine, config: GameConfig, element: HTMLElement, page: GamePage, fail?: (error: unknown) => void);
17
18
  /** Sets the page in the game's registry when it changed: scenes hear `changedata-page`. */
18
19
  setPage(page: GamePage): void;
19
20
  /** What the game set of its round in its registry (GameUtil.SCORE_KEY, GameUtil.OVER_KEY). */
20
21
  state(): GameState | undefined;
22
+ /** What the game says is in it now (GameUtil.OBSERVE_KEY); nothing when it says nothing or that throws. */
23
+ observe(): GameObservation | undefined;
21
24
  get sleeping(): boolean;
22
25
  /** Whether the element can be seen: the game sleeps while not. */
23
26
  setVisible(visible: boolean): void;
27
+ /** Waits for a slow player (a program's commander thinking): asleep as out of sight, till it goes on. */
28
+ setPaused(paused: boolean): void;
29
+ protected apply(): void;
24
30
  /**
25
31
  * Destroys the game and takes its canvas out. Phaser destroys it at the end of its next frame: a loop
26
32
  * asleep is woken for it, and a game not booted yet is destroyed as it boots.