@celljs/ta-web 4.9.1 → 4.10.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.
- package/README.en.md +4 -3
- package/README.md +4 -3
- package/esm/browser/assistant/assistant-chat-list.js +8 -2
- package/esm/browser/assistant/assistant-extension.d.ts +8 -1
- package/esm/browser/assistant/assistant-extension.js +20 -0
- package/esm/browser/assistant/assistant-protocol.d.ts +3 -1
- package/esm/browser/assistant/assistant-task-util.d.ts +2 -0
- package/esm/browser/assistant/assistant-task-util.js +5 -3
- package/esm/browser/assistant/assistant-view.js +81 -56
- package/esm/browser/assistant/assistant.d.ts +10 -1
- package/esm/browser/assistant/assistant.js +44 -5
- package/esm/browser/chat/chat-packages.d.ts +39 -0
- package/esm/browser/chat/chat-packages.js +70 -0
- package/esm/browser/chat/chat-protocol.d.ts +23 -1
- package/esm/browser/chat/chat-stores.d.ts +59 -0
- package/esm/browser/chat/chat-stores.js +121 -0
- package/esm/browser/chat/chat-util.d.ts +17 -0
- package/esm/browser/chat/chat-util.js +61 -0
- package/esm/browser/chat/chat-view.js +33 -12
- package/esm/browser/chat/chat.d.ts +31 -39
- package/esm/browser/chat/chat.js +226 -175
- package/esm/browser/components/app-nav.d.ts +6 -3
- package/esm/browser/components/app-nav.js +19 -10
- package/esm/browser/components/app-shell-hooks.d.ts +2 -2
- package/esm/browser/components/app-shell-hooks.js +7 -3
- package/esm/browser/components/app-view.js +75 -21
- package/esm/browser/components/chat-list.d.ts +20 -2
- package/esm/browser/components/chat-list.js +138 -22
- package/esm/browser/components/composer-box.d.ts +5 -5
- package/esm/browser/components/composer-box.js +111 -4
- package/esm/browser/components/composer.d.ts +7 -0
- package/esm/browser/components/composer.js +5 -4
- package/esm/browser/components/connection-bar.js +50 -17
- package/esm/browser/components/context-menu.d.ts +30 -4
- package/esm/browser/components/context-menu.js +199 -37
- package/esm/browser/components/conversation-scroll.d.ts +129 -6
- package/esm/browser/components/conversation-scroll.js +429 -109
- package/esm/browser/components/earlier-messages.d.ts +2 -1
- package/esm/browser/components/earlier-messages.js +2 -17
- package/esm/browser/components/editor-area.d.ts +3 -1
- package/esm/browser/components/editor-area.js +6 -5
- package/esm/browser/components/empty-pictures.d.ts +0 -2
- package/esm/browser/components/empty-pictures.js +0 -16
- package/esm/browser/components/folder-picker.d.ts +5 -2
- package/esm/browser/components/folder-picker.js +26 -8
- package/esm/browser/components/held-talk.d.ts +28 -0
- package/esm/browser/components/held-talk.js +76 -0
- package/esm/browser/components/host-view.d.ts +1 -1
- package/esm/browser/components/icon.d.ts +2 -2
- package/esm/browser/components/icon.js +5 -6
- package/esm/browser/components/image-viewer.d.ts +124 -0
- package/esm/browser/components/image-viewer.js +397 -0
- package/esm/browser/components/lightbox.d.ts +11 -0
- package/esm/browser/components/lightbox.js +24 -0
- package/esm/browser/components/markdown.d.ts +6 -2
- package/esm/browser/components/markdown.js +24 -10
- package/esm/browser/components/media.js +1 -10
- package/esm/browser/components/message-footer.d.ts +16 -2
- package/esm/browser/components/message-footer.js +29 -12
- package/esm/browser/components/message-list.d.ts +24 -3
- package/esm/browser/components/message-list.js +149 -20
- package/esm/browser/components/message-menu.d.ts +3 -1
- package/esm/browser/components/message-menu.js +18 -3
- package/esm/browser/components/nav-places.d.ts +16 -1
- package/esm/browser/components/nav-places.js +12 -3
- package/esm/browser/components/phone-shell.d.ts +4 -1
- package/esm/browser/components/phone-shell.js +3 -1
- package/esm/browser/components/run-status.js +3 -3
- package/esm/browser/components/session-settings.d.ts +6 -0
- package/esm/browser/components/session-settings.js +14 -1
- package/esm/browser/components/session-view.js +8 -4
- package/esm/browser/components/settings-parts.d.ts +2 -2
- package/esm/browser/components/settings-parts.js +24 -1
- package/esm/browser/components/swipe-row.d.ts +2 -2
- package/esm/browser/components/swipe-row.js +7 -3
- package/esm/browser/components/tool-view.js +14 -12
- package/esm/browser/components/voice-button.d.ts +1 -1
- package/esm/browser/components/voice-button.js +1 -1
- package/esm/browser/components/voice-talk.d.ts +43 -0
- package/esm/browser/components/voice-talk.js +222 -0
- package/esm/browser/device/device.d.ts +3 -0
- package/esm/browser/device/device.js +11 -1
- package/esm/browser/device/hold.d.ts +42 -0
- package/esm/browser/device/hold.js +136 -0
- package/esm/browser/device/launch-screen.d.ts +1 -1
- package/esm/browser/device/launch-screen.js +1 -1
- package/esm/browser/device/long-press.d.ts +2 -0
- package/esm/browser/device/long-press.js +16 -1
- package/esm/browser/device/pull-down.d.ts +4 -2
- package/esm/browser/device/pull-down.js +64 -76
- package/esm/browser/device/row-swipe.d.ts +35 -10
- package/esm/browser/device/row-swipe.js +149 -71
- package/esm/browser/device/shake-undo.d.ts +16 -0
- package/esm/browser/device/shake-undo.js +59 -0
- package/esm/browser/device/sheet-swipe.d.ts +118 -18
- package/esm/browser/device/sheet-swipe.js +406 -107
- package/esm/browser/extension/web-extension-api.d.ts +97 -1
- package/esm/browser/extension/web-extension-code.d.ts +6 -0
- package/esm/browser/extension/web-extension-code.js +24 -0
- package/esm/browser/extension/web-extension-protocol.d.ts +23 -1
- package/esm/browser/extension/web-extension-protocol.js +8 -0
- package/esm/browser/extension/web-extensions.d.ts +14 -1
- package/esm/browser/extension/web-extensions.js +122 -23
- package/esm/browser/files/files-protocol.d.ts +25 -0
- package/esm/browser/files/files-protocol.js +2 -0
- package/esm/browser/files/files.d.ts +35 -0
- package/esm/browser/files/files.js +119 -0
- package/esm/browser/i18n/locales.d.ts +24 -2
- package/esm/browser/i18n/messages.d.ts +23 -1
- package/esm/browser/i18n/messages.js +48 -4
- package/esm/browser/index.d.ts +6 -0
- package/esm/browser/index.js +6 -0
- package/esm/browser/notices/notices-protocol.d.ts +9 -1
- package/esm/browser/notices/notices.d.ts +2 -0
- package/esm/browser/notices/notices.js +20 -10
- package/esm/browser/offline/device-values.d.ts +55 -0
- package/esm/browser/offline/device-values.js +142 -0
- package/esm/browser/offline/kept-chats-protocol.d.ts +17 -0
- package/esm/browser/offline/kept-chats-protocol.js +2 -0
- package/esm/browser/offline/kept-chats.d.ts +47 -0
- package/esm/browser/offline/kept-chats.js +146 -0
- package/esm/browser/offline/offline-reads.d.ts +44 -0
- package/esm/browser/offline/offline-reads.js +107 -0
- package/esm/browser/settings/settings-protocol.d.ts +2 -0
- package/esm/browser/settings/settings-protocol.js +2 -0
- package/esm/browser/style/conversation.d.ts +1 -1
- package/esm/browser/style/conversation.js +57 -17
- package/esm/browser/style/device.js +27 -4
- package/esm/browser/style/layout.d.ts +1 -1
- package/esm/browser/style/layout.js +67 -15
- package/esm/browser/style/pages.d.ts +1 -1
- package/esm/browser/style/pages.js +2 -1
- package/esm/browser/style/shell.d.ts +1 -1
- package/esm/browser/style/shell.js +46 -3
- package/esm/browser/util/frame.d.ts +5 -4
- package/esm/browser/util/frame.js +5 -4
- package/esm/browser/util/markdown.d.ts +18 -1
- package/esm/browser/util/markdown.js +119 -5
- package/esm/browser/util/process.d.ts +21 -0
- package/esm/browser/util/process.js +45 -1
- package/esm/browser/util/voice.d.ts +5 -2
- package/esm/browser/util/voice.js +6 -3
- package/esm/browser/util/zoom.d.ts +46 -0
- package/esm/browser/util/zoom.js +96 -0
- package/esm/browser/workbench-calls.d.ts +59 -0
- package/esm/browser/workbench-calls.js +141 -0
- package/esm/browser/workbench-protocol.d.ts +5 -1
- package/esm/browser/workbench-util.d.ts +7 -0
- package/esm/browser/workbench-util.js +9 -2
- package/esm/browser/workbench.d.ts +14 -5
- package/esm/browser/workbench.js +51 -31
- package/lib/browser/assistant/assistant-chat-list.js +8 -2
- package/lib/browser/assistant/assistant-extension.d.ts +8 -1
- package/lib/browser/assistant/assistant-extension.js +20 -0
- package/lib/browser/assistant/assistant-protocol.d.ts +3 -1
- package/lib/browser/assistant/assistant-task-util.d.ts +2 -0
- package/lib/browser/assistant/assistant-task-util.js +5 -3
- package/lib/browser/assistant/assistant-view.js +78 -53
- package/lib/browser/assistant/assistant.d.ts +10 -1
- package/lib/browser/assistant/assistant.js +44 -5
- package/lib/browser/chat/chat-packages.d.ts +40 -0
- package/lib/browser/chat/chat-packages.js +74 -0
- package/lib/browser/chat/chat-protocol.d.ts +23 -1
- package/lib/browser/chat/chat-stores.d.ts +60 -0
- package/lib/browser/chat/chat-stores.js +125 -0
- package/lib/browser/chat/chat-util.d.ts +18 -0
- package/lib/browser/chat/chat-util.js +64 -0
- package/lib/browser/chat/chat-view.js +33 -12
- package/lib/browser/chat/chat.d.ts +31 -39
- package/lib/browser/chat/chat.js +227 -176
- package/lib/browser/components/app-nav.d.ts +6 -3
- package/lib/browser/components/app-nav.js +17 -8
- package/lib/browser/components/app-shell-hooks.d.ts +2 -2
- package/lib/browser/components/app-shell-hooks.js +7 -3
- package/lib/browser/components/app-view.js +74 -20
- package/lib/browser/components/chat-list.d.ts +20 -2
- package/lib/browser/components/chat-list.js +137 -21
- package/lib/browser/components/composer-box.d.ts +5 -5
- package/lib/browser/components/composer-box.js +111 -4
- package/lib/browser/components/composer.d.ts +7 -0
- package/lib/browser/components/composer.js +5 -4
- package/lib/browser/components/connection-bar.js +48 -15
- package/lib/browser/components/context-menu.d.ts +30 -4
- package/lib/browser/components/context-menu.js +198 -36
- package/lib/browser/components/conversation-scroll.d.ts +129 -6
- package/lib/browser/components/conversation-scroll.js +431 -110
- package/lib/browser/components/earlier-messages.d.ts +2 -1
- package/lib/browser/components/earlier-messages.js +2 -17
- package/lib/browser/components/editor-area.d.ts +3 -1
- package/lib/browser/components/editor-area.js +5 -4
- package/lib/browser/components/empty-pictures.d.ts +0 -2
- package/lib/browser/components/empty-pictures.js +0 -17
- package/lib/browser/components/folder-picker.d.ts +5 -2
- package/lib/browser/components/folder-picker.js +26 -8
- package/lib/browser/components/held-talk.d.ts +29 -0
- package/lib/browser/components/held-talk.js +79 -0
- package/lib/browser/components/host-view.d.ts +1 -1
- package/lib/browser/components/icon.d.ts +2 -2
- package/lib/browser/components/icon.js +7 -6
- package/lib/browser/components/image-viewer.d.ts +125 -0
- package/lib/browser/components/image-viewer.js +435 -0
- package/lib/browser/components/lightbox.d.ts +12 -0
- package/lib/browser/components/lightbox.js +60 -0
- package/lib/browser/components/markdown.d.ts +6 -2
- package/lib/browser/components/markdown.js +24 -10
- package/lib/browser/components/media.js +2 -11
- package/lib/browser/components/message-footer.d.ts +16 -2
- package/lib/browser/components/message-footer.js +31 -12
- package/lib/browser/components/message-list.d.ts +24 -3
- package/lib/browser/components/message-list.js +146 -16
- package/lib/browser/components/message-menu.d.ts +3 -1
- package/lib/browser/components/message-menu.js +17 -2
- package/lib/browser/components/nav-places.d.ts +16 -1
- package/lib/browser/components/nav-places.js +13 -3
- package/lib/browser/components/phone-shell.d.ts +4 -1
- package/lib/browser/components/phone-shell.js +3 -1
- package/lib/browser/components/run-status.js +3 -3
- package/lib/browser/components/session-settings.d.ts +6 -0
- package/lib/browser/components/session-settings.js +14 -1
- package/lib/browser/components/session-view.js +7 -3
- package/lib/browser/components/settings-parts.d.ts +2 -2
- package/lib/browser/components/settings-parts.js +24 -1
- package/lib/browser/components/swipe-row.d.ts +2 -2
- package/lib/browser/components/swipe-row.js +7 -3
- package/lib/browser/components/tool-view.js +14 -12
- package/lib/browser/components/voice-button.d.ts +1 -1
- package/lib/browser/components/voice-button.js +1 -1
- package/lib/browser/components/voice-talk.d.ts +44 -0
- package/lib/browser/components/voice-talk.js +260 -0
- package/lib/browser/device/device.d.ts +3 -0
- package/lib/browser/device/device.js +11 -1
- package/lib/browser/device/hold.d.ts +43 -0
- package/lib/browser/device/hold.js +173 -0
- package/lib/browser/device/launch-screen.d.ts +1 -1
- package/lib/browser/device/launch-screen.js +1 -1
- package/lib/browser/device/long-press.d.ts +2 -0
- package/lib/browser/device/long-press.js +16 -1
- package/lib/browser/device/pull-down.d.ts +4 -2
- package/lib/browser/device/pull-down.js +63 -75
- package/lib/browser/device/row-swipe.d.ts +35 -10
- package/lib/browser/device/row-swipe.js +148 -70
- package/lib/browser/device/shake-undo.d.ts +17 -0
- package/lib/browser/device/shake-undo.js +63 -0
- package/lib/browser/device/sheet-swipe.d.ts +118 -18
- package/lib/browser/device/sheet-swipe.js +410 -108
- package/lib/browser/extension/web-extension-api.d.ts +97 -1
- package/lib/browser/extension/web-extension-code.d.ts +6 -0
- package/lib/browser/extension/web-extension-code.js +24 -0
- package/lib/browser/extension/web-extension-protocol.d.ts +23 -1
- package/lib/browser/extension/web-extension-protocol.js +9 -1
- package/lib/browser/extension/web-extensions.d.ts +14 -1
- package/lib/browser/extension/web-extensions.js +120 -21
- package/lib/browser/files/files-protocol.d.ts +26 -0
- package/lib/browser/files/files-protocol.js +5 -0
- package/lib/browser/files/files.d.ts +36 -0
- package/lib/browser/files/files.js +122 -0
- package/lib/browser/i18n/locales.d.ts +24 -2
- package/lib/browser/i18n/messages.d.ts +23 -1
- package/lib/browser/i18n/messages.js +48 -4
- package/lib/browser/index.d.ts +6 -0
- package/lib/browser/index.js +6 -0
- package/lib/browser/notices/notices-protocol.d.ts +9 -1
- package/lib/browser/notices/notices.d.ts +2 -0
- package/lib/browser/notices/notices.js +20 -10
- package/lib/browser/offline/device-values.d.ts +56 -0
- package/lib/browser/offline/device-values.js +148 -0
- package/lib/browser/offline/kept-chats-protocol.d.ts +18 -0
- package/lib/browser/offline/kept-chats-protocol.js +5 -0
- package/lib/browser/offline/kept-chats.d.ts +48 -0
- package/lib/browser/offline/kept-chats.js +149 -0
- package/lib/browser/offline/offline-reads.d.ts +45 -0
- package/lib/browser/offline/offline-reads.js +111 -0
- package/lib/browser/settings/settings-protocol.d.ts +2 -0
- package/lib/browser/settings/settings-protocol.js +2 -0
- package/lib/browser/style/conversation.d.ts +1 -1
- package/lib/browser/style/conversation.js +57 -17
- package/lib/browser/style/device.js +27 -4
- package/lib/browser/style/layout.d.ts +1 -1
- package/lib/browser/style/layout.js +67 -15
- package/lib/browser/style/pages.d.ts +1 -1
- package/lib/browser/style/pages.js +2 -1
- package/lib/browser/style/shell.d.ts +1 -1
- package/lib/browser/style/shell.js +46 -3
- package/lib/browser/util/frame.d.ts +5 -4
- package/lib/browser/util/frame.js +5 -4
- package/lib/browser/util/markdown.d.ts +18 -1
- package/lib/browser/util/markdown.js +119 -5
- package/lib/browser/util/process.d.ts +21 -0
- package/lib/browser/util/process.js +46 -2
- package/lib/browser/util/voice.d.ts +5 -2
- package/lib/browser/util/voice.js +6 -3
- package/lib/browser/util/zoom.d.ts +47 -0
- package/lib/browser/util/zoom.js +99 -0
- package/lib/browser/workbench-calls.d.ts +60 -0
- package/lib/browser/workbench-calls.js +145 -0
- package/lib/browser/workbench-protocol.d.ts +5 -1
- package/lib/browser/workbench-util.d.ts +7 -0
- package/lib/browser/workbench-util.js +10 -3
- package/lib/browser/workbench.d.ts +14 -5
- package/lib/browser/workbench.js +51 -31
- package/package.json +10 -10
- package/public/launch.svg +46 -42
|
@@ -40,6 +40,17 @@ const BEFORE_URL = /[\w/.@:-]/;
|
|
|
40
40
|
/** `$x$`: no space inside the dollars, no digit after the closing one, so that `$5 and $10` stays text. */
|
|
41
41
|
const INLINE_MATH = /^\$(?=[^\s$])([^$]*?[^\s$\\])\$(?!\d)/;
|
|
42
42
|
const PUNCTUATION = /[!-/:-@[-`{-~]/;
|
|
43
|
+
/**
|
|
44
|
+
* The last line of a reply still coming that may yet turn into something else: the start of a fence, a
|
|
45
|
+
* heading, a list, a rule or a row of a table. It shows once the next character tells what it is.
|
|
46
|
+
*/
|
|
47
|
+
const PENDING_LINE = /^\s*(?:`{1,2}|~{1,2}|#{1,6}|[-*+_]{1,2}|\d{1,9}[.)]?|\|.*)$/;
|
|
48
|
+
/** A link or an image the last line has begun: its text, then its target, before the `)` that ends it. */
|
|
49
|
+
const PENDING_LINK = /!?\[[^\]]*(?:\](?:\([^)]*)?)?$/;
|
|
50
|
+
/** Inline TeX begun and not closed: `$` before something that is not a space or a digit (`$5` is a price), or `\\(`. */
|
|
51
|
+
const PENDING_MATH = /(?:(?<![\\$])\$(?=[^\s$\d])[^$]*|\\\((?![\s\S]*\\\)).*)$/;
|
|
52
|
+
/** Cells of a table longer than this (a CJK character counts twice) wrap; shorter ones keep to one line. */
|
|
53
|
+
const LONG_CELL = 24;
|
|
43
54
|
/**
|
|
44
55
|
* The markdown models write: fenced code, headings, lists, quotes, tables, emphasis, code spans, links,
|
|
45
56
|
* images and videos, and TeX between `$`, `$$`, `\\(\\)` or `\\[\\]`. Its output is data for React to
|
|
@@ -133,12 +144,15 @@ export var MarkdownUtil;
|
|
|
133
144
|
}
|
|
134
145
|
if (line.includes('|') && TABLE_SEPARATOR.test((_b = lines[i + 1]) !== null && _b !== void 0 ? _b : '') && !paragraph.length) {
|
|
135
146
|
const header = cells(line);
|
|
147
|
+
const marks = cells(lines[i + 1]);
|
|
148
|
+
const align = header.map((_, column) => { var _a; return alignOf((_a = marks[column]) !== null && _a !== void 0 ? _a : ''); });
|
|
136
149
|
const rows = [];
|
|
137
150
|
for (i += 2; i < lines.length && lines[i].includes('|') && lines[i].trim(); i++) {
|
|
138
|
-
|
|
151
|
+
const row = cells(lines[i]);
|
|
152
|
+
rows.push(header.map((_, column) => { var _a; return (_a = row[column]) !== null && _a !== void 0 ? _a : ''; }));
|
|
139
153
|
}
|
|
140
154
|
i--;
|
|
141
|
-
blocks.push({ type: 'table', header, rows });
|
|
155
|
+
blocks.push({ type: 'table', header, rows, align });
|
|
142
156
|
continue;
|
|
143
157
|
}
|
|
144
158
|
paragraph.push(line);
|
|
@@ -147,6 +161,100 @@ export var MarkdownUtil;
|
|
|
147
161
|
return blocks;
|
|
148
162
|
}
|
|
149
163
|
MarkdownUtil.blocks = blocks;
|
|
164
|
+
/**
|
|
165
|
+
* The blocks of a reply while it streams: what is shown only grows, never shows a mark that is about to
|
|
166
|
+
* turn into something else. The last line waits while it may still start a structure (`PENDING_LINE`);
|
|
167
|
+
* a link or a formula on it begun and not closed waits for its end; `**` and `\`` opened on it are closed
|
|
168
|
+
* for now; a table shows from its separator on, a row once it is whole; a formula on lines of its own once
|
|
169
|
+
* it is closed. Code in an open fence streams as it comes.
|
|
170
|
+
*/
|
|
171
|
+
function streaming(source) {
|
|
172
|
+
const text = source.replace(/\r\n?/g, '\n');
|
|
173
|
+
const blocks = MarkdownUtil.blocks(settled(text));
|
|
174
|
+
const last = blocks[blocks.length - 1];
|
|
175
|
+
if ((last === null || last === void 0 ? void 0 : last.type) === 'math' && !last.closed) {
|
|
176
|
+
blocks.pop();
|
|
177
|
+
}
|
|
178
|
+
else if ((last === null || last === void 0 ? void 0 : last.type) === 'paragraph' && last.text.trimStart().startsWith('|') && !last.text.includes('\n')) {
|
|
179
|
+
// The head of a table whose separator has not come yet.
|
|
180
|
+
blocks.pop();
|
|
181
|
+
}
|
|
182
|
+
return blocks;
|
|
183
|
+
}
|
|
184
|
+
MarkdownUtil.streaming = streaming;
|
|
185
|
+
function settled(text) {
|
|
186
|
+
var _a, _b;
|
|
187
|
+
var _c, _d;
|
|
188
|
+
if (openFence(text)) {
|
|
189
|
+
return text;
|
|
190
|
+
}
|
|
191
|
+
const start = text.lastIndexOf('\n') + 1;
|
|
192
|
+
let line = text.slice(start);
|
|
193
|
+
if (PENDING_LINE.test(line)) {
|
|
194
|
+
return text.slice(0, start);
|
|
195
|
+
}
|
|
196
|
+
line = line.replace(PENDING_LINK, '').replace(PENDING_MATH, '');
|
|
197
|
+
// A mark cut in two at the end (one `*` of `**`): as if it had not come.
|
|
198
|
+
line = line.replace(/[*`]+$/, '');
|
|
199
|
+
if (((_c = (_a = line.match(/`/g)) === null || _a === void 0 ? void 0 : _a.length) !== null && _c !== void 0 ? _c : 0) % 2) {
|
|
200
|
+
line += '`';
|
|
201
|
+
}
|
|
202
|
+
if (((_d = (_b = line.replace(/`[^`]*`/g, '').match(/\*\*/g)) === null || _b === void 0 ? void 0 : _b.length) !== null && _d !== void 0 ? _d : 0) % 2) {
|
|
203
|
+
line += '**';
|
|
204
|
+
}
|
|
205
|
+
return text.slice(0, start) + line;
|
|
206
|
+
}
|
|
207
|
+
/** A fence opened and not closed: the reply is in the middle of code. */
|
|
208
|
+
function openFence(text) {
|
|
209
|
+
let fence;
|
|
210
|
+
for (const line of text.split('\n')) {
|
|
211
|
+
const open = FENCE.exec(line);
|
|
212
|
+
if (!fence) {
|
|
213
|
+
fence = open === null || open === void 0 ? void 0 : open[1];
|
|
214
|
+
}
|
|
215
|
+
else if (new RegExp(`^\\s*${fence[0]}{${fence.length},}\\s*$`).test(line)) {
|
|
216
|
+
fence = undefined;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return fence !== undefined;
|
|
220
|
+
}
|
|
221
|
+
/** The two blocks show the same: one may stand for the other. */
|
|
222
|
+
function same(a, b) {
|
|
223
|
+
if (a === b) {
|
|
224
|
+
return true;
|
|
225
|
+
}
|
|
226
|
+
if (!a || a.type !== b.type) {
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
switch (b.type) {
|
|
230
|
+
case 'list':
|
|
231
|
+
return a.type === 'list' && a.ordered === b.ordered && sameStrings(a.items, b.items);
|
|
232
|
+
case 'table':
|
|
233
|
+
return (a.type === 'table' &&
|
|
234
|
+
sameStrings(a.header, b.header) &&
|
|
235
|
+
sameStrings(a.align, b.align) &&
|
|
236
|
+
a.rows.length === b.rows.length &&
|
|
237
|
+
a.rows.every((row, index) => sameStrings(row, b.rows[index])));
|
|
238
|
+
default:
|
|
239
|
+
return Object.keys(b).every(key => a[key] === b[key]);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
MarkdownUtil.same = same;
|
|
243
|
+
function sameStrings(a, b) {
|
|
244
|
+
return a.length === b.length && a.every((value, index) => value === b[index]);
|
|
245
|
+
}
|
|
246
|
+
/** A cell long enough to wrap; shorter cells keep to one line, so that a narrow table scrolls rather than squeezes them. */
|
|
247
|
+
function longCell(text) {
|
|
248
|
+
let width = 0;
|
|
249
|
+
for (const char of text) {
|
|
250
|
+
width += char.charCodeAt(0) >= 0x2e80 ? 2 : 1;
|
|
251
|
+
if (width > LONG_CELL) {
|
|
252
|
+
return true;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
MarkdownUtil.longCell = longCell;
|
|
150
258
|
function inline(text) {
|
|
151
259
|
var _a, _b, _c, _d, _e;
|
|
152
260
|
const out = [];
|
|
@@ -318,13 +426,19 @@ export var MarkdownUtil;
|
|
|
318
426
|
}
|
|
319
427
|
return { block: { type: 'math', tex: tex.join('\n').trim(), closed: false }, end: lines.length - 1 };
|
|
320
428
|
}
|
|
429
|
+
/** The cells of a row; `\\|` is a `|` in a cell. */
|
|
321
430
|
function cells(row) {
|
|
322
431
|
return row
|
|
323
432
|
.trim()
|
|
324
433
|
.replace(/^\|/, '')
|
|
325
|
-
.replace(
|
|
326
|
-
.split(
|
|
327
|
-
.map(cell => cell.trim());
|
|
434
|
+
.replace(/(?<!\\)\|$/, '')
|
|
435
|
+
.split(/(?<!\\)\|/)
|
|
436
|
+
.map(cell => cell.trim().replace(/\\\|/g, '|'));
|
|
437
|
+
}
|
|
438
|
+
function alignOf(mark) {
|
|
439
|
+
const left = mark.startsWith(':');
|
|
440
|
+
const right = mark.endsWith(':');
|
|
441
|
+
return left && right ? 'center' : right ? 'right' : left ? 'left' : '';
|
|
328
442
|
}
|
|
329
443
|
})(MarkdownUtil || (MarkdownUtil = {}));
|
|
330
444
|
//# sourceMappingURL=markdown.js.map
|
|
@@ -10,6 +10,12 @@ export type ProcessStep = {
|
|
|
10
10
|
kind: 'text';
|
|
11
11
|
key: string;
|
|
12
12
|
text: string;
|
|
13
|
+
}
|
|
14
|
+
/** An agent that compacts its own context said its summary of the conversation. */
|
|
15
|
+
| {
|
|
16
|
+
kind: 'summary';
|
|
17
|
+
key: string;
|
|
18
|
+
text: string;
|
|
13
19
|
} | {
|
|
14
20
|
kind: 'tool';
|
|
15
21
|
key: string;
|
|
@@ -41,6 +47,8 @@ export interface TurnItem {
|
|
|
41
47
|
export type ThreadItem = MessageItem | TurnItem;
|
|
42
48
|
/** While the agent works, only the latest steps show; the earlier ones fold into one row. */
|
|
43
49
|
export declare const VISIBLE_STEPS = 8;
|
|
50
|
+
/** A time shows between two items of the conversation this long apart, as in WeChat. */
|
|
51
|
+
export declare const TIME_BREAK_MS: number;
|
|
44
52
|
/**
|
|
45
53
|
* How the conversation is laid out (thinking and tool calls folded into steps): pure functions over pi's
|
|
46
54
|
* messages, so that a component only draws what they return.
|
|
@@ -69,6 +77,19 @@ export declare namespace ProcessUtil {
|
|
|
69
77
|
* waits), then done for the last turn, needing you after an error, and calm for the rest.
|
|
70
78
|
*/
|
|
71
79
|
function mood(item: TurnItem, last: boolean, waiting: boolean): Mood;
|
|
80
|
+
/** When each item began: its first message; one still empty (a turn about to come), when the one before did. */
|
|
81
|
+
function starts(items: ThreadItem[]): number[];
|
|
82
|
+
/**
|
|
83
|
+
* The item draws something: not a custom message the model sees and the user does not (`display`
|
|
84
|
+
* false), unless a web extension registered a renderer for its type (`renderers`).
|
|
85
|
+
*/
|
|
86
|
+
function shown(item: ThreadItem, renderers: Readonly<Record<string, unknown>>): boolean;
|
|
87
|
+
/**
|
|
88
|
+
* The time to show above each item, as WeChat does between messages: above the first item with a time,
|
|
89
|
+
* and above one that began `TIME_BREAK_MS` or more after the one shown before it; else undefined. An
|
|
90
|
+
* item not `shown` has none and is not the one before: two times would else stand one on the other.
|
|
91
|
+
*/
|
|
92
|
+
function timeBreaks(starts: number[], shown?: (index: number) => boolean): (number | undefined)[];
|
|
72
93
|
/** The two items show the same: their messages are the same objects, and so is whether it works. */
|
|
73
94
|
function same(a: ThreadItem, b: ThreadItem): boolean;
|
|
74
95
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { TaAgentSummary } from '@celljs/ta-protocol';
|
|
1
2
|
import { MessageUtil } from './message.js';
|
|
2
3
|
/** While the agent works, only the latest steps show; the earlier ones fold into one row. */
|
|
3
4
|
export const VISIBLE_STEPS = 8;
|
|
5
|
+
/** A time shows between two items of the conversation this long apart, as in WeChat. */
|
|
6
|
+
export const TIME_BREAK_MS = 5 * 60000;
|
|
4
7
|
const TURN_ROLES = new Set(['assistant', 'toolResult']);
|
|
5
8
|
/**
|
|
6
9
|
* How the conversation is laid out (thinking and tool calls folded into steps): pure functions over pi's
|
|
@@ -52,7 +55,8 @@ export var ProcessUtil;
|
|
|
52
55
|
steps.push({ kind: 'thinking', key, text: block.thinking });
|
|
53
56
|
}
|
|
54
57
|
else if (block.type === 'text' && ((_b = block.text) === null || _b === void 0 ? void 0 : _b.trim())) {
|
|
55
|
-
|
|
58
|
+
const summary = TaAgentSummary.read(block.text);
|
|
59
|
+
steps.push(summary === undefined ? { kind: 'text', key, text: block.text } : { kind: 'summary', key, text: summary });
|
|
56
60
|
}
|
|
57
61
|
else if (block.type === 'toolCall') {
|
|
58
62
|
steps.push({ kind: 'tool', key: block.id || key, call: block });
|
|
@@ -123,6 +127,46 @@ export var ProcessUtil;
|
|
|
123
127
|
return last && stopReason !== 'aborted' ? 'done' : 'idle';
|
|
124
128
|
}
|
|
125
129
|
ProcessUtil.mood = mood;
|
|
130
|
+
/** When each item began: its first message; one still empty (a turn about to come), when the one before did. */
|
|
131
|
+
function starts(items) {
|
|
132
|
+
let last = Number.NEGATIVE_INFINITY;
|
|
133
|
+
return items.map(item => {
|
|
134
|
+
const first = item.kind === 'turn' ? item.messages[0] : item.message;
|
|
135
|
+
const at = first === null || first === void 0 ? void 0 : first.timestamp;
|
|
136
|
+
last = typeof at === 'number' ? at : last;
|
|
137
|
+
return last;
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
ProcessUtil.starts = starts;
|
|
141
|
+
/**
|
|
142
|
+
* The item draws something: not a custom message the model sees and the user does not (`display`
|
|
143
|
+
* false), unless a web extension registered a renderer for its type (`renderers`).
|
|
144
|
+
*/
|
|
145
|
+
function shown(item, renderers) {
|
|
146
|
+
if (item.kind === 'turn' || item.message.role !== 'custom') {
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
const { display, customType } = item.message;
|
|
150
|
+
return !!display || (customType !== undefined && renderers[customType] !== undefined);
|
|
151
|
+
}
|
|
152
|
+
ProcessUtil.shown = shown;
|
|
153
|
+
/**
|
|
154
|
+
* The time to show above each item, as WeChat does between messages: above the first item with a time,
|
|
155
|
+
* and above one that began `TIME_BREAK_MS` or more after the one shown before it; else undefined. An
|
|
156
|
+
* item not `shown` has none and is not the one before: two times would else stand one on the other.
|
|
157
|
+
*/
|
|
158
|
+
function timeBreaks(starts, shown = () => true) {
|
|
159
|
+
let before = Number.NEGATIVE_INFINITY;
|
|
160
|
+
return starts.map((at, index) => {
|
|
161
|
+
if (!shown(index)) {
|
|
162
|
+
return undefined;
|
|
163
|
+
}
|
|
164
|
+
const time = Number.isFinite(at) && (!Number.isFinite(before) || at - before >= TIME_BREAK_MS) ? at : undefined;
|
|
165
|
+
before = at;
|
|
166
|
+
return time;
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
ProcessUtil.timeBreaks = timeBreaks;
|
|
126
170
|
/** The two items show the same: their messages are the same objects, and so is whether it works. */
|
|
127
171
|
function same(a, b) {
|
|
128
172
|
if (a.kind === 'message' || b.kind === 'message') {
|
|
@@ -7,8 +7,11 @@ export declare namespace Voice {
|
|
|
7
7
|
interface Listening {
|
|
8
8
|
stop(): void;
|
|
9
9
|
}
|
|
10
|
-
/**
|
|
11
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Listens for one utterance: `onText` gets the words so far, then the final ones with `final` set. `continuous`
|
|
12
|
+
* goes on past a pause, until it is stopped: what a finger held on the box says, not one thing said to it.
|
|
13
|
+
*/
|
|
14
|
+
function listen(language: string, onText: (text: string, final: boolean) => void, onEnd: (error?: string) => void, continuous?: boolean): Listening | undefined;
|
|
12
15
|
/** Text for the ear: no markdown marks, no code. */
|
|
13
16
|
function spoken(markdown: string): string;
|
|
14
17
|
function speak(markdown: string, language: string, onEnd: () => void): void;
|
|
@@ -19,8 +19,11 @@ export var Voice;
|
|
|
19
19
|
return typeof speechSynthesis !== 'undefined';
|
|
20
20
|
}
|
|
21
21
|
Voice.canSpeak = canSpeak;
|
|
22
|
-
/**
|
|
23
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Listens for one utterance: `onText` gets the words so far, then the final ones with `final` set. `continuous`
|
|
24
|
+
* goes on past a pause, until it is stopped: what a finger held on the box says, not one thing said to it.
|
|
25
|
+
*/
|
|
26
|
+
function listen(language, onText, onEnd, continuous = false) {
|
|
24
27
|
const Recognition = recognitionClass();
|
|
25
28
|
if (!Recognition) {
|
|
26
29
|
return undefined;
|
|
@@ -28,7 +31,7 @@ export var Voice;
|
|
|
28
31
|
const recognition = new Recognition();
|
|
29
32
|
recognition.lang = language;
|
|
30
33
|
recognition.interimResults = true;
|
|
31
|
-
recognition.continuous =
|
|
34
|
+
recognition.continuous = continuous;
|
|
32
35
|
let text = '';
|
|
33
36
|
recognition.onresult = event => {
|
|
34
37
|
let final = false;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/** The size of a picture or of the box it is shown in, in CSS pixels. */
|
|
2
|
+
export interface ZoomSize {
|
|
3
|
+
width: number;
|
|
4
|
+
height: number;
|
|
5
|
+
}
|
|
6
|
+
/** How far a picture may be zoomed in its box: `base` it shows at first, between `min` and `max`. */
|
|
7
|
+
export interface ZoomLimits {
|
|
8
|
+
base: number;
|
|
9
|
+
min: number;
|
|
10
|
+
max: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A picture zoomed in a box that scrolls: how big it is drawn, where it is in what scrolls, and how far that
|
|
14
|
+
* scrolls so that a point of the picture stays under the fingers or the pointer. Pure, for the tests.
|
|
15
|
+
*/
|
|
16
|
+
export declare namespace ZoomUtil {
|
|
17
|
+
/** Space around the picture at every scale, so that its edges never touch the box. */
|
|
18
|
+
const PAD = 16;
|
|
19
|
+
/** The steps of the + and − buttons and keys. */
|
|
20
|
+
const STOPS: number[];
|
|
21
|
+
/** At this scale and over, its pixels are drawn as squares, as the viewers of pictures do. */
|
|
22
|
+
const PIXELATED = 4;
|
|
23
|
+
/** The scale at which all of the picture shows in the box: what it shows at first unless that is larger than its own pixels. */
|
|
24
|
+
function contain(image: ZoomSize, box: ZoomSize): number;
|
|
25
|
+
/** All of it in the box, never larger than its own pixels; no smaller than that, and in to at least LEAST_MAX. */
|
|
26
|
+
function limits(image: ZoomSize, box: ZoomSize): ZoomLimits;
|
|
27
|
+
function clamp(scale: number, limits: ZoomLimits): number;
|
|
28
|
+
/** What a pinch past the limits draws: it goes on, ever less far. */
|
|
29
|
+
function rubber(scale: number, limits: ZoomLimits): number;
|
|
30
|
+
/** Where the picture starts along an axis of `box` pixels, `size` pixels drawn: centred while smaller, else after PAD. */
|
|
31
|
+
function offset(size: number, box: number): number;
|
|
32
|
+
/** How long what scrolls is along an axis: the box, or the picture and PAD on both sides. */
|
|
33
|
+
function extent(size: number, box: number): number;
|
|
34
|
+
/** Where in the picture (its own pixels) a point of the box is, along an axis, the picture `natural` pixels long at `scale`. */
|
|
35
|
+
function at(point: number, scroll: number, natural: number, scale: number, box: number): number;
|
|
36
|
+
/** How far to scroll along an axis so that `spot` of the picture (its own pixels) is under `point` of the box, at `scale`. */
|
|
37
|
+
function scrollTo(spot: number, point: number, natural: number, scale: number, box: number): number;
|
|
38
|
+
/** The next step in (`way` 1) or out (-1) from `scale`; `base` is a step too. */
|
|
39
|
+
function step(scale: number, way: 1 | -1, limits: ZoomLimits): number;
|
|
40
|
+
/** Whether it shows as at first. */
|
|
41
|
+
function fitted(scale: number, limits: ZoomLimits): boolean;
|
|
42
|
+
/** A double tap or click: back to `base` when zoomed, else in, to its own pixels when that is a few times nearer. */
|
|
43
|
+
function toggle(scale: number, limits: ZoomLimits): number;
|
|
44
|
+
/** How much a turn of the wheel or a pinch of the trackpad (a wheel with Ctrl) zooms: `deltaY` in `deltaMode`'s unit. */
|
|
45
|
+
function wheel(deltaY: number, deltaMode: number): number;
|
|
46
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A picture zoomed in a box that scrolls: how big it is drawn, where it is in what scrolls, and how far that
|
|
3
|
+
* scrolls so that a point of the picture stays under the fingers or the pointer. Pure, for the tests.
|
|
4
|
+
*/
|
|
5
|
+
export var ZoomUtil;
|
|
6
|
+
(function (ZoomUtil) {
|
|
7
|
+
/** Space around the picture at every scale, so that its edges never touch the box. */
|
|
8
|
+
ZoomUtil.PAD = 16;
|
|
9
|
+
/** The steps of the + and − buttons and keys. */
|
|
10
|
+
ZoomUtil.STOPS = [0.05, 0.1, 0.15, 0.25, 0.33, 0.5, 0.67, 0.75, 1, 1.25, 1.5, 2, 3, 4, 6, 8, 12, 16, 24, 32];
|
|
11
|
+
/** At least this far in, however big the picture. */
|
|
12
|
+
const LEAST_MAX = 8;
|
|
13
|
+
/** At this scale and over, its pixels are drawn as squares, as the viewers of pictures do. */
|
|
14
|
+
ZoomUtil.PIXELATED = 4;
|
|
15
|
+
/** A pinch past the limits goes on this much less far (a rubber band), then comes back. */
|
|
16
|
+
const RUBBER = 0.35;
|
|
17
|
+
/** The scale at which all of the picture shows in the box: what it shows at first unless that is larger than its own pixels. */
|
|
18
|
+
function contain(image, box) {
|
|
19
|
+
const width = Math.max(1, box.width - 2 * ZoomUtil.PAD);
|
|
20
|
+
const height = Math.max(1, box.height - 2 * ZoomUtil.PAD);
|
|
21
|
+
return Math.min(width / Math.max(1, image.width), height / Math.max(1, image.height));
|
|
22
|
+
}
|
|
23
|
+
ZoomUtil.contain = contain;
|
|
24
|
+
/** All of it in the box, never larger than its own pixels; no smaller than that, and in to at least LEAST_MAX. */
|
|
25
|
+
function limits(image, box) {
|
|
26
|
+
const whole = contain(image, box);
|
|
27
|
+
const base = Math.min(1, whole);
|
|
28
|
+
return { base, min: base, max: Math.max(LEAST_MAX, whole * 2) };
|
|
29
|
+
}
|
|
30
|
+
ZoomUtil.limits = limits;
|
|
31
|
+
function clamp(scale, limits) {
|
|
32
|
+
return Math.min(limits.max, Math.max(limits.min, scale));
|
|
33
|
+
}
|
|
34
|
+
ZoomUtil.clamp = clamp;
|
|
35
|
+
/** What a pinch past the limits draws: it goes on, ever less far. */
|
|
36
|
+
function rubber(scale, limits) {
|
|
37
|
+
if (scale < limits.min) {
|
|
38
|
+
return limits.min * (scale / limits.min) ** RUBBER;
|
|
39
|
+
}
|
|
40
|
+
if (scale > limits.max) {
|
|
41
|
+
return limits.max * (scale / limits.max) ** RUBBER;
|
|
42
|
+
}
|
|
43
|
+
return scale;
|
|
44
|
+
}
|
|
45
|
+
ZoomUtil.rubber = rubber;
|
|
46
|
+
/** Where the picture starts along an axis of `box` pixels, `size` pixels drawn: centred while smaller, else after PAD. */
|
|
47
|
+
function offset(size, box) {
|
|
48
|
+
return Math.max(ZoomUtil.PAD, (box - size) / 2);
|
|
49
|
+
}
|
|
50
|
+
ZoomUtil.offset = offset;
|
|
51
|
+
/** How long what scrolls is along an axis: the box, or the picture and PAD on both sides. */
|
|
52
|
+
function extent(size, box) {
|
|
53
|
+
return Math.max(box, size + 2 * ZoomUtil.PAD);
|
|
54
|
+
}
|
|
55
|
+
ZoomUtil.extent = extent;
|
|
56
|
+
/** Where in the picture (its own pixels) a point of the box is, along an axis, the picture `natural` pixels long at `scale`. */
|
|
57
|
+
function at(point, scroll, natural, scale, box) {
|
|
58
|
+
return (scroll + point - offset(natural * scale, box)) / scale;
|
|
59
|
+
}
|
|
60
|
+
ZoomUtil.at = at;
|
|
61
|
+
/** How far to scroll along an axis so that `spot` of the picture (its own pixels) is under `point` of the box, at `scale`. */
|
|
62
|
+
function scrollTo(spot, point, natural, scale, box) {
|
|
63
|
+
const size = natural * scale;
|
|
64
|
+
const most = extent(size, box) - box;
|
|
65
|
+
return Math.min(most, Math.max(0, spot * scale + offset(size, box) - point));
|
|
66
|
+
}
|
|
67
|
+
ZoomUtil.scrollTo = scrollTo;
|
|
68
|
+
/** The next step in (`way` 1) or out (-1) from `scale`; `base` is a step too. */
|
|
69
|
+
function step(scale, way, limits) {
|
|
70
|
+
const stops = [...ZoomUtil.STOPS, limits.base].sort((a, b) => a - b);
|
|
71
|
+
const next = way > 0 ? stops.find(stop => stop > scale * 1.01) : [...stops].reverse().find(stop => stop < scale * 0.99);
|
|
72
|
+
return clamp(next !== null && next !== void 0 ? next : (way > 0 ? limits.max : limits.min), limits);
|
|
73
|
+
}
|
|
74
|
+
ZoomUtil.step = step;
|
|
75
|
+
/** Whether it shows as at first. */
|
|
76
|
+
function fitted(scale, limits) {
|
|
77
|
+
return Math.abs(scale - limits.base) < limits.base * 0.01;
|
|
78
|
+
}
|
|
79
|
+
ZoomUtil.fitted = fitted;
|
|
80
|
+
/** A double tap or click: back to `base` when zoomed, else in, to its own pixels when that is a few times nearer. */
|
|
81
|
+
function toggle(scale, limits) {
|
|
82
|
+
if (!fitted(scale, limits)) {
|
|
83
|
+
return limits.base;
|
|
84
|
+
}
|
|
85
|
+
const target = limits.base < 1 ? Math.max(limits.base * 2, Math.min(1, limits.base * 4)) : limits.base * 2.5;
|
|
86
|
+
return clamp(target, limits);
|
|
87
|
+
}
|
|
88
|
+
ZoomUtil.toggle = toggle;
|
|
89
|
+
/** How much a turn of the wheel or a pinch of the trackpad (a wheel with Ctrl) zooms: `deltaY` in `deltaMode`'s unit. */
|
|
90
|
+
function wheel(deltaY, deltaMode) {
|
|
91
|
+
const pixels = deltaY * (deltaMode === 1 ? 16 : deltaMode === 2 ? 400 : 1);
|
|
92
|
+
return Math.exp(-Math.min(40, Math.max(-40, pixels)) * 0.01);
|
|
93
|
+
}
|
|
94
|
+
ZoomUtil.wheel = wheel;
|
|
95
|
+
})(ZoomUtil || (ZoomUtil = {}));
|
|
96
|
+
//# sourceMappingURL=zoom.js.map
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type SessionConnection, type TaConnection } from '@celljs/ta-client';
|
|
2
|
+
import { OfflineReads } from './offline/offline-reads.js';
|
|
3
|
+
import type { ConnectionStatus, WorkbenchState } from './workbench-protocol.js';
|
|
4
|
+
import { type ServiceName } from './workbench-util.js';
|
|
5
|
+
/** What the calls need of the workbench. */
|
|
6
|
+
export interface CallsOwner {
|
|
7
|
+
status(): ConnectionStatus;
|
|
8
|
+
/** The connection of now, if there is one. */
|
|
9
|
+
connection(): TaConnection | undefined;
|
|
10
|
+
connected(): Promise<void>;
|
|
11
|
+
subscribe(listener: (state: WorkbenchState) => void): () => void;
|
|
12
|
+
/** Tells web extensions that keys of their data changed. */
|
|
13
|
+
dataChanged(name: string, keys: string[], cwd?: string): void;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The calls of the page to its computer: those of the workbench's services, and those of its stores
|
|
17
|
+
* (`link`). Each goes to the connection of the time; before there is one, it waits for it. A call that
|
|
18
|
+
* reads (OFFLINE_READS) answers as it did last time while the computer cannot be reached, rather than
|
|
19
|
+
* waiting: what was shown shows again, web extensions started from the device too.
|
|
20
|
+
*/
|
|
21
|
+
export declare class WorkbenchCalls {
|
|
22
|
+
protected readonly owner: CallsOwner;
|
|
23
|
+
/** The answers of the calls that read, of the computer in use. */
|
|
24
|
+
readonly reads: OfflineReads;
|
|
25
|
+
/** The services, the same across connections. */
|
|
26
|
+
protected readonly services: Map<ServiceName, object>;
|
|
27
|
+
/**
|
|
28
|
+
* The data of web extensions answered from the device (by call): read again once online, as the server
|
|
29
|
+
* tells of changes only to what a connection read, and it may have changed meanwhile.
|
|
30
|
+
*/
|
|
31
|
+
protected readonly keptData: Map<string, {
|
|
32
|
+
name: string;
|
|
33
|
+
key: string;
|
|
34
|
+
cwd?: string;
|
|
35
|
+
}>;
|
|
36
|
+
constructor(owner: CallsOwner, host: string | undefined);
|
|
37
|
+
/** A service of the page, its methods the same each time too: what is given them is not drawn again for nothing. */
|
|
38
|
+
service<K extends ServiceName>(name: K): TaConnection[K];
|
|
39
|
+
/**
|
|
40
|
+
* What stores use of the connection, there before it is (a conversation kept on the device shows without
|
|
41
|
+
* one): their calls wait for it as on a connection that dropped, then fail; they attach once connected.
|
|
42
|
+
*/
|
|
43
|
+
readonly link: SessionConnection;
|
|
44
|
+
/** As `connected`, failing as a call on a connection that dropped does once it is not back within `ms`. */
|
|
45
|
+
connectedWithin(ms: number): Promise<void>;
|
|
46
|
+
/** Online again: the web extensions that were given kept data hear that it changed, and read it from the computer. */
|
|
47
|
+
online(): void;
|
|
48
|
+
protected call(name: ServiceName, method: string, params: unknown[]): Promise<unknown>;
|
|
49
|
+
/**
|
|
50
|
+
* The answer kept of a call, once the connection is not there to give it: at once while offline, after a
|
|
51
|
+
* moment while connecting (a start through a relay is online within it); none online, or with none kept.
|
|
52
|
+
*/
|
|
53
|
+
protected keptAnswer(name: ServiceName, method: string, params: unknown[]): Promise<{
|
|
54
|
+
value: unknown;
|
|
55
|
+
} | undefined>;
|
|
56
|
+
/** Resolves once the status is no longer `connecting`, or after `ms`. */
|
|
57
|
+
protected leavesConnecting(ms: number): Promise<void>;
|
|
58
|
+
protected signedIn(): TaConnection;
|
|
59
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { TaRemoteError } from '@celljs/ta-client';
|
|
2
|
+
import { deviceValues } from './offline/device-values.js';
|
|
3
|
+
import { OfflineReads } from './offline/offline-reads.js';
|
|
4
|
+
import { KEPT_AFTER_MS, STORE_WAIT_MS } from './workbench-util.js';
|
|
5
|
+
/**
|
|
6
|
+
* The calls of the page to its computer: those of the workbench's services, and those of its stores
|
|
7
|
+
* (`link`). Each goes to the connection of the time; before there is one, it waits for it. A call that
|
|
8
|
+
* reads (OFFLINE_READS) answers as it did last time while the computer cannot be reached, rather than
|
|
9
|
+
* waiting: what was shown shows again, web extensions started from the device too.
|
|
10
|
+
*/
|
|
11
|
+
export class WorkbenchCalls {
|
|
12
|
+
constructor(owner, host) {
|
|
13
|
+
this.owner = owner;
|
|
14
|
+
/** The services, the same across connections. */
|
|
15
|
+
this.services = new Map();
|
|
16
|
+
/**
|
|
17
|
+
* The data of web extensions answered from the device (by call): read again once online, as the server
|
|
18
|
+
* tells of changes only to what a connection read, and it may have changed meanwhile.
|
|
19
|
+
*/
|
|
20
|
+
this.keptData = new Map();
|
|
21
|
+
/**
|
|
22
|
+
* What stores use of the connection, there before it is (a conversation kept on the device shows without
|
|
23
|
+
* one): their calls wait for it as on a connection that dropped, then fail; they attach once connected.
|
|
24
|
+
*/
|
|
25
|
+
this.link = {
|
|
26
|
+
server: new Proxy({}, {
|
|
27
|
+
get: (_target, method) => typeof method !== 'string' || method === 'then'
|
|
28
|
+
? undefined
|
|
29
|
+
: async (...params) => {
|
|
30
|
+
if (!this.owner.connection()) {
|
|
31
|
+
await this.connectedWithin(STORE_WAIT_MS);
|
|
32
|
+
}
|
|
33
|
+
return this.signedIn().server[method](...params);
|
|
34
|
+
},
|
|
35
|
+
}),
|
|
36
|
+
onEvents: listener => this.signedIn().onEvents(listener),
|
|
37
|
+
onOpen: listener => this.signedIn().onOpen(listener),
|
|
38
|
+
};
|
|
39
|
+
this.reads = new OfflineReads(deviceValues()).use(host);
|
|
40
|
+
}
|
|
41
|
+
/** A service of the page, its methods the same each time too: what is given them is not drawn again for nothing. */
|
|
42
|
+
service(name) {
|
|
43
|
+
const known = this.services.get(name);
|
|
44
|
+
if (known) {
|
|
45
|
+
return known;
|
|
46
|
+
}
|
|
47
|
+
const methods = new Map();
|
|
48
|
+
const service = new Proxy({}, {
|
|
49
|
+
get: (_target, method) => {
|
|
50
|
+
// Not a promise itself.
|
|
51
|
+
if (typeof method !== 'string' || method === 'then') {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
let call = methods.get(method);
|
|
55
|
+
if (!call) {
|
|
56
|
+
call = (...params) => this.call(name, method, params);
|
|
57
|
+
methods.set(method, call);
|
|
58
|
+
}
|
|
59
|
+
return call;
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
this.services.set(name, service);
|
|
63
|
+
return service;
|
|
64
|
+
}
|
|
65
|
+
/** As `connected`, failing as a call on a connection that dropped does once it is not back within `ms`. */
|
|
66
|
+
connectedWithin(ms) {
|
|
67
|
+
let timer;
|
|
68
|
+
const late = new Promise((_, reject) => {
|
|
69
|
+
timer = setTimeout(() => reject(TaRemoteError.notConnected()), ms);
|
|
70
|
+
});
|
|
71
|
+
return Promise.race([this.owner.connected(), late]).finally(() => clearTimeout(timer));
|
|
72
|
+
}
|
|
73
|
+
/** Online again: the web extensions that were given kept data hear that it changed, and read it from the computer. */
|
|
74
|
+
online() {
|
|
75
|
+
var _a;
|
|
76
|
+
const changed = new Map();
|
|
77
|
+
for (const { name, key, cwd } of this.keptData.values()) {
|
|
78
|
+
const of = `${name}\n${cwd !== null && cwd !== void 0 ? cwd : ''}`;
|
|
79
|
+
const entry = (_a = changed.get(of)) !== null && _a !== void 0 ? _a : { name, keys: [], cwd };
|
|
80
|
+
entry.keys.push(key);
|
|
81
|
+
changed.set(of, entry);
|
|
82
|
+
}
|
|
83
|
+
this.keptData.clear();
|
|
84
|
+
for (const { name, keys, cwd } of changed.values()) {
|
|
85
|
+
this.owner.dataChanged(name, keys, cwd);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
async call(name, method, params) {
|
|
89
|
+
const reads = OfflineReads.reads(name, method);
|
|
90
|
+
if (reads && this.owner.status() !== 'online') {
|
|
91
|
+
const kept = await this.keptAnswer(name, method, params);
|
|
92
|
+
if (kept) {
|
|
93
|
+
if (name === 'packages' && method === 'getExtensionData') {
|
|
94
|
+
const [extension, key, cwd] = params;
|
|
95
|
+
this.keptData.set(OfflineReads.call(name, method, params), { name: extension, key, cwd });
|
|
96
|
+
}
|
|
97
|
+
return kept.value;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (!this.owner.connection()) {
|
|
101
|
+
await this.owner.connected();
|
|
102
|
+
}
|
|
103
|
+
const answer = await this.signedIn()[name][method](...params);
|
|
104
|
+
if (reads) {
|
|
105
|
+
this.reads.keep(name, method, params, answer);
|
|
106
|
+
}
|
|
107
|
+
return answer;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* The answer kept of a call, once the connection is not there to give it: at once while offline, after a
|
|
111
|
+
* moment while connecting (a start through a relay is online within it); none online, or with none kept.
|
|
112
|
+
*/
|
|
113
|
+
async keptAnswer(name, method, params) {
|
|
114
|
+
const kept = await this.reads.answer(name, method, params);
|
|
115
|
+
if (kept && this.owner.status() === 'connecting') {
|
|
116
|
+
await this.leavesConnecting(KEPT_AFTER_MS);
|
|
117
|
+
}
|
|
118
|
+
const status = this.owner.status();
|
|
119
|
+
return status === 'offline' || status === 'connecting' ? kept : undefined;
|
|
120
|
+
}
|
|
121
|
+
/** Resolves once the status is no longer `connecting`, or after `ms`. */
|
|
122
|
+
leavesConnecting(ms) {
|
|
123
|
+
return new Promise(resolve => {
|
|
124
|
+
const done = () => {
|
|
125
|
+
clearTimeout(timer);
|
|
126
|
+
unsubscribe();
|
|
127
|
+
resolve();
|
|
128
|
+
};
|
|
129
|
+
const timer = setTimeout(done, ms);
|
|
130
|
+
const unsubscribe = this.owner.subscribe(state => state.status !== 'connecting' && done());
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
signedIn() {
|
|
134
|
+
const connection = this.owner.connection();
|
|
135
|
+
if (!connection) {
|
|
136
|
+
throw new Error('Not signed in to ta serve.');
|
|
137
|
+
}
|
|
138
|
+
return connection;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=workbench-calls.js.map
|
|
@@ -99,7 +99,11 @@ export interface TaWorkbench {
|
|
|
99
99
|
* what names no directory opens. Open conversations stay in theirs.
|
|
100
100
|
*/
|
|
101
101
|
setWorkingDirectory(cwd: string): Promise<void>;
|
|
102
|
-
/**
|
|
102
|
+
/**
|
|
103
|
+
* A store of a session on this connection; the caller attaches and detaches it. It can be made before
|
|
104
|
+
* there is a connection, to show a conversation kept on the device (SessionStoreOptions.initial): it is
|
|
105
|
+
* attached once connected, and its calls meanwhile fail as on a connection that dropped.
|
|
106
|
+
*/
|
|
103
107
|
createStore(sessionId: string, options?: SessionStoreOptions): SessionStore;
|
|
104
108
|
/** Output of the terminals of this connection; the listener stays across reconnections and sign-ins. */
|
|
105
109
|
onTerminalData(listener: (terminalId: string, data: string, exitCode?: number) => void): () => void;
|