@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
|
@@ -8,7 +8,9 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
10
|
import { Autowired, Component } from '@celljs/core';
|
|
11
|
+
import { TaRemoteError } from '@celljs/ta-client';
|
|
11
12
|
import { TaErrorCode, TaErrorUtil } from '@celljs/ta-protocol';
|
|
13
|
+
import { TaKeptChats } from '../offline/kept-chats-protocol.js';
|
|
12
14
|
import { SettingsUtil, TaSettings } from '../settings/settings-protocol.js';
|
|
13
15
|
import { TaState } from '../state/state-protocol.js';
|
|
14
16
|
import { TaWorkbench } from '../workbench-protocol.js';
|
|
@@ -59,6 +61,11 @@ let TaAssistantImpl = class TaAssistantImpl {
|
|
|
59
61
|
(_a = this.unwatchSettings) !== null && _a !== void 0 ? _a : (this.unwatchSettings = this.settings.subscribe(state => this.settingsChanged(state.settings)));
|
|
60
62
|
(_b = this.starting) !== null && _b !== void 0 ? _b : (this.starting = this.open().catch(error => {
|
|
61
63
|
this.starting = undefined;
|
|
64
|
+
if (TaRemoteError.isConnectionLost(error)) {
|
|
65
|
+
// No failure to show: it wakes once the connection is back (a moment after, not in a loop).
|
|
66
|
+
setTimeout(() => void this.workbench.connected().then(() => (this.starting || this.assistant ? undefined : this.start()), () => undefined), 1000);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
62
69
|
this.update({ error: error instanceof Error ? error.message : String(error) });
|
|
63
70
|
}));
|
|
64
71
|
return this.starting;
|
|
@@ -69,7 +76,17 @@ let TaAssistantImpl = class TaAssistantImpl {
|
|
|
69
76
|
}
|
|
70
77
|
}
|
|
71
78
|
store() {
|
|
72
|
-
|
|
79
|
+
var _a;
|
|
80
|
+
return (_a = this.assistant) !== null && _a !== void 0 ? _a : this.preview;
|
|
81
|
+
}
|
|
82
|
+
async showKept() {
|
|
83
|
+
const file = this.assistant || this.preview ? undefined : await this.persisted.load(FILE);
|
|
84
|
+
const initial = file ? await this.kept.read(file).catch(() => undefined) : undefined;
|
|
85
|
+
if (initial && !this.assistant && !this.preview) {
|
|
86
|
+
// Under its file: it is of no session until the conversation opens, which takes over what it shows.
|
|
87
|
+
this.preview = this.workbench.createStore(file, { initial });
|
|
88
|
+
this.update({});
|
|
89
|
+
}
|
|
73
90
|
}
|
|
74
91
|
async loadTasks() {
|
|
75
92
|
this.watchTasks();
|
|
@@ -151,6 +168,9 @@ let TaAssistantImpl = class TaAssistantImpl {
|
|
|
151
168
|
// Opening (again, after a reconnect found it gone): sent once it is open.
|
|
152
169
|
await this.starting;
|
|
153
170
|
const store = this.assistant;
|
|
171
|
+
if (!store && this.workbench.state.status !== 'online') {
|
|
172
|
+
throw TaRemoteError.notConnected();
|
|
173
|
+
}
|
|
154
174
|
if (!store) {
|
|
155
175
|
throw new Error('Ta is not ready yet.');
|
|
156
176
|
}
|
|
@@ -302,6 +322,18 @@ let TaAssistantImpl = class TaAssistantImpl {
|
|
|
302
322
|
this.persisted.set(FILE, sessionFile);
|
|
303
323
|
}
|
|
304
324
|
}
|
|
325
|
+
/** Keeps the conversation on the device as it changes, under its file of the time (`restart` gives it another). */
|
|
326
|
+
keep(store) {
|
|
327
|
+
var _a;
|
|
328
|
+
(_a = this.unkeep) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
329
|
+
let file = this.sessionFile;
|
|
330
|
+
this.unkeep = this.kept.follow(store, () => {
|
|
331
|
+
if (this.assistant === store) {
|
|
332
|
+
file = this.sessionFile;
|
|
333
|
+
}
|
|
334
|
+
return file;
|
|
335
|
+
});
|
|
336
|
+
}
|
|
305
337
|
/** The role of ta, whether it asks first, and what the user added to it. */
|
|
306
338
|
systemPrompt() {
|
|
307
339
|
return assistantRole(this.settings.state.settings.confirmTasks, this.prompt);
|
|
@@ -334,8 +366,8 @@ let TaAssistantImpl = class TaAssistantImpl {
|
|
|
334
366
|
* trip to ta serve, which over a relay or a phone's network takes long.
|
|
335
367
|
*/
|
|
336
368
|
async open() {
|
|
337
|
-
var _a;
|
|
338
|
-
var
|
|
369
|
+
var _a, _b;
|
|
370
|
+
var _c;
|
|
339
371
|
this.watchTasks();
|
|
340
372
|
const clientTools = this.clientTools();
|
|
341
373
|
const [tasks, file, wasAsking, sessions] = await Promise.all([
|
|
@@ -360,7 +392,7 @@ let TaAssistantImpl = class TaAssistantImpl {
|
|
|
360
392
|
if (!info) {
|
|
361
393
|
this.persisted.set(ASKING, asking);
|
|
362
394
|
const options = {
|
|
363
|
-
cwd: (
|
|
395
|
+
cwd: (_c = (_a = this.workbench.state.server) === null || _a === void 0 ? void 0 : _a.cwd) !== null && _c !== void 0 ? _c : '.',
|
|
364
396
|
appendSystemPrompt: this.systemPrompt(),
|
|
365
397
|
clientTools: clientTools.map(tool => tool.definition),
|
|
366
398
|
};
|
|
@@ -378,7 +410,8 @@ let TaAssistantImpl = class TaAssistantImpl {
|
|
|
378
410
|
}
|
|
379
411
|
const { sessionId } = info;
|
|
380
412
|
this.cwd = info.cwd;
|
|
381
|
-
|
|
413
|
+
// What the device kept shows on: the messages that are the same keep their objects.
|
|
414
|
+
const store = this.workbench.createStore(sessionId, { clientTools, initial: (_b = this.preview) === null || _b === void 0 ? void 0 : _b.state });
|
|
382
415
|
await Promise.all([named ? this.server.setSessionName(sessionId, 'Ta') : undefined, this.applyModel(sessionId, info.model), store.attach()]);
|
|
383
416
|
store.onGone(() => void this.recover(store));
|
|
384
417
|
store.subscribe(state => {
|
|
@@ -387,6 +420,8 @@ let TaAssistantImpl = class TaAssistantImpl {
|
|
|
387
420
|
}
|
|
388
421
|
});
|
|
389
422
|
this.assistant = store;
|
|
423
|
+
this.preview = undefined;
|
|
424
|
+
this.keep(store);
|
|
390
425
|
this.update({ ready: true, error: undefined });
|
|
391
426
|
this.flushNotes();
|
|
392
427
|
await this.followRunning(sessions);
|
|
@@ -597,6 +632,10 @@ __decorate([
|
|
|
597
632
|
Autowired(TaSettings),
|
|
598
633
|
__metadata("design:type", Object)
|
|
599
634
|
], TaAssistantImpl.prototype, "settings", void 0);
|
|
635
|
+
__decorate([
|
|
636
|
+
Autowired(TaKeptChats),
|
|
637
|
+
__metadata("design:type", Object)
|
|
638
|
+
], TaAssistantImpl.prototype, "kept", void 0);
|
|
600
639
|
TaAssistantImpl = __decorate([
|
|
601
640
|
Component(TaAssistant)
|
|
602
641
|
], TaAssistantImpl);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { SessionStore } from '@celljs/ta-client';
|
|
2
|
+
import type { TaWebExtensions } from '../extension/web-extension-protocol.js';
|
|
3
|
+
import type { TaWorkbench } from '../workbench-protocol.js';
|
|
4
|
+
import type { ChatStores } from './chat-stores.js';
|
|
5
|
+
/** What ChatPackages needs of the conversation shown (TaChat). */
|
|
6
|
+
export interface PackagesHost {
|
|
7
|
+
shown(): SessionStore | undefined;
|
|
8
|
+
/** One change of the conversation shown at a time. */
|
|
9
|
+
enqueue(change: () => Promise<void>): Promise<void>;
|
|
10
|
+
/** The same conversation, from its file, with the tools of now. */
|
|
11
|
+
reopen(store: SessionStore): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The packages of the conversation shown, after a run in which ta may have made or changed one: the web
|
|
15
|
+
* extensions load again; new or removed web tools open the conversation again with them; a changed package
|
|
16
|
+
* has its pi extensions loaded again. A new run in the meantime puts both off to its end.
|
|
17
|
+
*/
|
|
18
|
+
export declare class ChatPackages {
|
|
19
|
+
protected readonly extensions: TaWebExtensions;
|
|
20
|
+
protected readonly workbench: TaWorkbench;
|
|
21
|
+
protected readonly stores: ChatStores;
|
|
22
|
+
protected readonly host: PackagesHost;
|
|
23
|
+
/** The runs of tools of the conversation shown, seen before: only those after are its edits. */
|
|
24
|
+
protected readonly seen: Set<string>;
|
|
25
|
+
/** A web extension changed packages during a run: its end loads them again. */
|
|
26
|
+
protected pending: boolean;
|
|
27
|
+
constructor(extensions: TaWebExtensions, workbench: TaWorkbench, stores: ChatStores, host: PackagesHost);
|
|
28
|
+
/** The runs of a store so far are not edits of a run to come; `fresh`: a store shown in place of another. */
|
|
29
|
+
saw(store: SessionStore, fresh?: boolean): void;
|
|
30
|
+
/**
|
|
31
|
+
* A run ended, in which ta may have made or changed a package. The web extensions load again. New or
|
|
32
|
+
* removed web tools need the conversation opened again with them; a changed package needs its pi
|
|
33
|
+
* extensions loaded again. A new run in the meantime puts both off to its end.
|
|
34
|
+
*/
|
|
35
|
+
settled(store: SessionStore): Promise<void>;
|
|
36
|
+
/** A web extension changed packages (reloadExtensions): as at the end of a run, or at the end of the one under way. */
|
|
37
|
+
reload(store: SessionStore): Promise<void>;
|
|
38
|
+
protected load(store: SessionStore, changed: boolean): Promise<void>;
|
|
39
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { ChatUtil } from './chat-util.js';
|
|
2
|
+
/**
|
|
3
|
+
* The packages of the conversation shown, after a run in which ta may have made or changed one: the web
|
|
4
|
+
* extensions load again; new or removed web tools open the conversation again with them; a changed package
|
|
5
|
+
* has its pi extensions loaded again. A new run in the meantime puts both off to its end.
|
|
6
|
+
*/
|
|
7
|
+
export class ChatPackages {
|
|
8
|
+
constructor(extensions, workbench, stores, host) {
|
|
9
|
+
this.extensions = extensions;
|
|
10
|
+
this.workbench = workbench;
|
|
11
|
+
this.stores = stores;
|
|
12
|
+
this.host = host;
|
|
13
|
+
/** The runs of tools of the conversation shown, seen before: only those after are its edits. */
|
|
14
|
+
this.seen = new Set();
|
|
15
|
+
/** A web extension changed packages during a run: its end loads them again. */
|
|
16
|
+
this.pending = false;
|
|
17
|
+
}
|
|
18
|
+
/** The runs of a store so far are not edits of a run to come; `fresh`: a store shown in place of another. */
|
|
19
|
+
saw(store, fresh = false) {
|
|
20
|
+
if (fresh) {
|
|
21
|
+
this.seen.clear();
|
|
22
|
+
}
|
|
23
|
+
for (const id of Object.keys(store.state.tools)) {
|
|
24
|
+
this.seen.add(id);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* A run ended, in which ta may have made or changed a package. The web extensions load again. New or
|
|
29
|
+
* removed web tools need the conversation opened again with them; a changed package needs its pi
|
|
30
|
+
* extensions loaded again. A new run in the meantime puts both off to its end.
|
|
31
|
+
*/
|
|
32
|
+
settled(store) {
|
|
33
|
+
return this.host.enqueue(ChatUtil.quietly(async () => {
|
|
34
|
+
const changed = await this.extensions.refresh();
|
|
35
|
+
const edits = ChatUtil.packageEdits(store.state, this.seen);
|
|
36
|
+
for (const id of edits) {
|
|
37
|
+
this.seen.add(id);
|
|
38
|
+
}
|
|
39
|
+
if (store !== this.host.shown() || store.state.working) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const pending = this.pending;
|
|
43
|
+
this.pending = false;
|
|
44
|
+
await this.load(store, changed || edits.length > 0 || pending);
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
/** A web extension changed packages (reloadExtensions): as at the end of a run, or at the end of the one under way. */
|
|
48
|
+
reload(store) {
|
|
49
|
+
return this.host.enqueue(async () => {
|
|
50
|
+
if (store !== this.host.shown()) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (store.state.working) {
|
|
54
|
+
this.pending = true;
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
await this.load(store, true);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
async load(store, changed) {
|
|
61
|
+
const tools = this.stores.openedWith(store.sessionId);
|
|
62
|
+
if (tools !== undefined && tools !== this.stores.toolNames()) {
|
|
63
|
+
await this.host.reopen(store);
|
|
64
|
+
}
|
|
65
|
+
else if (changed) {
|
|
66
|
+
await this.workbench.server.reload(store.sessionId);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=chat-packages.js.map
|
|
@@ -10,11 +10,23 @@ export interface ChatDraft {
|
|
|
10
10
|
cwd: string;
|
|
11
11
|
/** `<provider>/<model id>` it will start on; none: the default model of the settings. */
|
|
12
12
|
model?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Its first message, shown at once while its session opens, or `failed` to open it. `heldAt`: when the
|
|
15
|
+
* connection was lost opening it; it opens once the connection is back, and fails only after HOLD_MS.
|
|
16
|
+
*/
|
|
17
|
+
sending?: {
|
|
18
|
+
message: string;
|
|
19
|
+
images?: ImageContent[];
|
|
20
|
+
failed?: string;
|
|
21
|
+
heldAt?: number;
|
|
22
|
+
};
|
|
13
23
|
}
|
|
14
24
|
/** What a conversation still opening says of itself, before the server has it (TaChat.show of a session on its way). */
|
|
15
25
|
export interface ChatOpening {
|
|
16
26
|
title?: string;
|
|
17
27
|
cwd?: string;
|
|
28
|
+
/** Its file, when known: what this device kept of it shows while it opens, without the computer too. */
|
|
29
|
+
sessionFile?: string;
|
|
18
30
|
}
|
|
19
31
|
export interface ChatState {
|
|
20
32
|
/** The conversation shown, once there is one. */
|
|
@@ -49,8 +61,18 @@ export interface TaChat {
|
|
|
49
61
|
setDraftCwd(cwd: string): Promise<void>;
|
|
50
62
|
/** The model the new conversation starts on; none: the default one. */
|
|
51
63
|
setDraftModel(model: string | undefined): void;
|
|
52
|
-
/**
|
|
64
|
+
/**
|
|
65
|
+
* Opens the session of the new conversation and sends its first message. When that fails the message
|
|
66
|
+
* stays, marked failed (`ChatDraft.sending`), to send again or take back. Another message while it
|
|
67
|
+
* opens follows the first.
|
|
68
|
+
*/
|
|
53
69
|
submit(message: string, images?: ImageContent[]): Promise<void>;
|
|
70
|
+
/** Sends again the first message that failed. */
|
|
71
|
+
resendDraft(): Promise<void>;
|
|
72
|
+
/** Takes back the first message that failed. */
|
|
73
|
+
discardDraft(): void;
|
|
74
|
+
/** Stops the run of the conversation still opening, once it is there. */
|
|
75
|
+
stopDraft(): void;
|
|
54
76
|
/**
|
|
55
77
|
* Shows an open session; one the service closed meanwhile opens again from its file. A session still on its
|
|
56
78
|
* way (a promise of its id) has its place at once, said by `opening`, and shows when it comes; it fails as it fails.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { ClientTool, SessionSnapshot, SessionStore } from '@celljs/ta-client';
|
|
2
|
+
import type { TaOpenSessionOptions, TaSessionInfo } from '@celljs/ta-protocol';
|
|
3
|
+
import type { TaWebExtensions } from '../extension/web-extension-protocol.js';
|
|
4
|
+
import type { TaKeptChats } from '../offline/kept-chats-protocol.js';
|
|
5
|
+
import type { TaWorkbench } from '../workbench-protocol.js';
|
|
6
|
+
import { RecentStores } from './recent-stores.js';
|
|
7
|
+
/**
|
|
8
|
+
* The sessions and stores of the conversations TaChat shows. Sessions open, and stores are made, with the
|
|
9
|
+
* web tools of now (each kept with their names, to tell when they changed); a store starts
|
|
10
|
+
* from what the device kept of its conversation when it has it, and knows whether it is attached. One that is
|
|
11
|
+
* not shows a conversation as the device kept it, until the connection is there: it is not kept among the
|
|
12
|
+
* recent ones, the device has it.
|
|
13
|
+
*/
|
|
14
|
+
export declare class ChatStores {
|
|
15
|
+
protected readonly workbench: TaWorkbench;
|
|
16
|
+
protected readonly kept: TaKeptChats;
|
|
17
|
+
protected readonly extensions: TaWebExtensions;
|
|
18
|
+
/** The conversations shown before, to show again at once. */
|
|
19
|
+
readonly recent: RecentStores;
|
|
20
|
+
protected readonly tools: WeakMap<SessionStore, string>;
|
|
21
|
+
/** The tools of the sessions this page opened, by session: only those are opened again when the tools change. */
|
|
22
|
+
protected readonly opened: Map<string, string>;
|
|
23
|
+
protected readonly attached: WeakSet<SessionStore>;
|
|
24
|
+
/** The file of the conversation a store not attached shows: the store that attaches for it takes on what failed to go there. */
|
|
25
|
+
protected readonly files: WeakMap<SessionStore, string>;
|
|
26
|
+
constructor(workbench: TaWorkbench, kept: TaKeptChats, extensions: TaWebExtensions);
|
|
27
|
+
/** The names of the web tools of now. */
|
|
28
|
+
toolNames(): string;
|
|
29
|
+
/** Opens a session with the web tools of now. */
|
|
30
|
+
open(options: Partial<TaOpenSessionOptions>): Promise<string>;
|
|
31
|
+
/** The names of the tools this page opened a session with; none for one it did not open. */
|
|
32
|
+
openedWith(sessionId: string): string | undefined;
|
|
33
|
+
/** The session closed. */
|
|
34
|
+
closed(sessionId: string): void;
|
|
35
|
+
/** A store of the session with the web tools of now, showing `initial` until it attaches. */
|
|
36
|
+
create(sessionId: string, initial?: SessionSnapshot): SessionStore;
|
|
37
|
+
/** A store, not attached, of the conversation of `sessionFile` as the device kept it, under `key`; none if it kept none. */
|
|
38
|
+
fromDevice(key: string, sessionFile: string | undefined): Promise<SessionStore | undefined>;
|
|
39
|
+
/** The conversation under `key` as this page or else this device had it, not attached: one shown lately, else the one of its file (else the list's). */
|
|
40
|
+
shown(key: string, sessionFile: string | undefined): Promise<SessionStore | undefined>;
|
|
41
|
+
/** What the device kept of the conversation of a file. */
|
|
42
|
+
read(sessionFile: string | undefined): Promise<SessionSnapshot | undefined>;
|
|
43
|
+
/** Whether the list has the session open. */
|
|
44
|
+
listed(sessionId: string): boolean;
|
|
45
|
+
/** The open session of a file. */
|
|
46
|
+
openOf(sessionFile: string): TaSessionInfo | undefined;
|
|
47
|
+
/** The file of an open session of the list. */
|
|
48
|
+
fileOf(sessionId: string): string | undefined;
|
|
49
|
+
/** The names of the web tools a store runs. */
|
|
50
|
+
toolsOf(store: SessionStore): string | undefined;
|
|
51
|
+
isAttached(store: SessionStore): boolean;
|
|
52
|
+
setAttached(store: SessionStore): void;
|
|
53
|
+
/** It is detached: whether it was attached. */
|
|
54
|
+
setDetached(store: SessionStore): boolean;
|
|
55
|
+
/** Whether `store`, not attached, shows the conversation of `sessionFile`. */
|
|
56
|
+
standsFor(store: SessionStore, sessionFile: string | undefined): boolean;
|
|
57
|
+
/** Runs the web tool of the name that is loaded when the model calls it: a changed one runs as it is now. */
|
|
58
|
+
protected clientTool(name: string): ClientTool;
|
|
59
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { ChatUtil } from './chat-util.js';
|
|
2
|
+
import { RecentStores } from './recent-stores.js';
|
|
3
|
+
/**
|
|
4
|
+
* The sessions and stores of the conversations TaChat shows. Sessions open, and stores are made, with the
|
|
5
|
+
* web tools of now (each kept with their names, to tell when they changed); a store starts
|
|
6
|
+
* from what the device kept of its conversation when it has it, and knows whether it is attached. One that is
|
|
7
|
+
* not shows a conversation as the device kept it, until the connection is there: it is not kept among the
|
|
8
|
+
* recent ones, the device has it.
|
|
9
|
+
*/
|
|
10
|
+
export class ChatStores {
|
|
11
|
+
constructor(workbench, kept, extensions) {
|
|
12
|
+
this.workbench = workbench;
|
|
13
|
+
this.kept = kept;
|
|
14
|
+
this.extensions = extensions;
|
|
15
|
+
/** The conversations shown before, to show again at once. */
|
|
16
|
+
this.recent = new RecentStores();
|
|
17
|
+
this.tools = new WeakMap();
|
|
18
|
+
/** The tools of the sessions this page opened, by session: only those are opened again when the tools change. */
|
|
19
|
+
this.opened = new Map();
|
|
20
|
+
this.attached = new WeakSet();
|
|
21
|
+
/** The file of the conversation a store not attached shows: the store that attaches for it takes on what failed to go there. */
|
|
22
|
+
this.files = new WeakMap();
|
|
23
|
+
}
|
|
24
|
+
/** The names of the web tools of now. */
|
|
25
|
+
toolNames() {
|
|
26
|
+
return ChatUtil.toolNames(this.extensions.state.tools);
|
|
27
|
+
}
|
|
28
|
+
/** Opens a session with the web tools of now. */
|
|
29
|
+
async open(options) {
|
|
30
|
+
var _a, _b;
|
|
31
|
+
const tools = this.extensions.state.tools;
|
|
32
|
+
const { sessionId } = await this.workbench.server.openSession({
|
|
33
|
+
...options,
|
|
34
|
+
cwd: ((_a = options.cwd) === null || _a === void 0 ? void 0 : _a.trim()) || ((_b = this.workbench.state.server) === null || _b === void 0 ? void 0 : _b.cwd) || '.',
|
|
35
|
+
clientTools: tools.map(({ name, description, parameters }) => ({ name, description, parameters })),
|
|
36
|
+
});
|
|
37
|
+
this.opened.set(sessionId, ChatUtil.toolNames(tools));
|
|
38
|
+
return sessionId;
|
|
39
|
+
}
|
|
40
|
+
/** The names of the tools this page opened a session with; none for one it did not open. */
|
|
41
|
+
openedWith(sessionId) {
|
|
42
|
+
return this.opened.get(sessionId);
|
|
43
|
+
}
|
|
44
|
+
/** The session closed. */
|
|
45
|
+
closed(sessionId) {
|
|
46
|
+
this.opened.delete(sessionId);
|
|
47
|
+
}
|
|
48
|
+
/** A store of the session with the web tools of now, showing `initial` until it attaches. */
|
|
49
|
+
create(sessionId, initial) {
|
|
50
|
+
const store = this.workbench.createStore(sessionId, { clientTools: this.extensions.state.tools.map(tool => this.clientTool(tool.name)), initial });
|
|
51
|
+
this.tools.set(store, this.toolNames());
|
|
52
|
+
return store;
|
|
53
|
+
}
|
|
54
|
+
/** A store, not attached, of the conversation of `sessionFile` as the device kept it, under `key`; none if it kept none. */
|
|
55
|
+
async fromDevice(key, sessionFile) {
|
|
56
|
+
const initial = await this.read(sessionFile);
|
|
57
|
+
if (!sessionFile || !initial) {
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
const store = this.create(key, initial);
|
|
61
|
+
this.files.set(store, sessionFile);
|
|
62
|
+
return store;
|
|
63
|
+
}
|
|
64
|
+
/** The conversation under `key` as this page or else this device had it, not attached: one shown lately, else the one of its file (else the list's). */
|
|
65
|
+
async shown(key, sessionFile) {
|
|
66
|
+
var _a;
|
|
67
|
+
return (_a = this.recent.take(key, this.toolNames())) !== null && _a !== void 0 ? _a : (await this.fromDevice(key, sessionFile !== null && sessionFile !== void 0 ? sessionFile : this.fileOf(key)));
|
|
68
|
+
}
|
|
69
|
+
/** What the device kept of the conversation of a file. */
|
|
70
|
+
read(sessionFile) {
|
|
71
|
+
return sessionFile ? this.kept.read(sessionFile).catch(() => undefined) : Promise.resolve(undefined);
|
|
72
|
+
}
|
|
73
|
+
/** Whether the list has the session open. */
|
|
74
|
+
listed(sessionId) {
|
|
75
|
+
return this.workbench.state.sessions.some(session => session.sessionId === sessionId);
|
|
76
|
+
}
|
|
77
|
+
/** The open session of a file. */
|
|
78
|
+
openOf(sessionFile) {
|
|
79
|
+
return this.workbench.state.sessions.find(session => session.sessionFile === sessionFile);
|
|
80
|
+
}
|
|
81
|
+
/** The file of an open session of the list. */
|
|
82
|
+
fileOf(sessionId) {
|
|
83
|
+
var _a;
|
|
84
|
+
return (_a = this.workbench.state.sessions.find(session => session.sessionId === sessionId)) === null || _a === void 0 ? void 0 : _a.sessionFile;
|
|
85
|
+
}
|
|
86
|
+
/** The names of the web tools a store runs. */
|
|
87
|
+
toolsOf(store) {
|
|
88
|
+
return this.tools.get(store);
|
|
89
|
+
}
|
|
90
|
+
isAttached(store) {
|
|
91
|
+
return this.attached.has(store);
|
|
92
|
+
}
|
|
93
|
+
setAttached(store) {
|
|
94
|
+
this.attached.add(store);
|
|
95
|
+
}
|
|
96
|
+
/** It is detached: whether it was attached. */
|
|
97
|
+
setDetached(store) {
|
|
98
|
+
return this.attached.delete(store);
|
|
99
|
+
}
|
|
100
|
+
/** Whether `store`, not attached, shows the conversation of `sessionFile`. */
|
|
101
|
+
standsFor(store, sessionFile) {
|
|
102
|
+
return !!sessionFile && !this.attached.has(store) && this.files.get(store) === sessionFile;
|
|
103
|
+
}
|
|
104
|
+
/** Runs the web tool of the name that is loaded when the model calls it: a changed one runs as it is now. */
|
|
105
|
+
clientTool(name) {
|
|
106
|
+
var _a;
|
|
107
|
+
const tool = () => this.extensions.state.tools.find(candidate => candidate.name === name);
|
|
108
|
+
const { description = '', parameters = {} } = (_a = tool()) !== null && _a !== void 0 ? _a : {};
|
|
109
|
+
return {
|
|
110
|
+
definition: { name, description, parameters },
|
|
111
|
+
run: async (input, request) => {
|
|
112
|
+
const current = tool();
|
|
113
|
+
if (!current) {
|
|
114
|
+
throw new Error(`The web extension of the tool ${name} is no longer loaded.`);
|
|
115
|
+
}
|
|
116
|
+
return current.execute(request.id, (input !== null && input !== void 0 ? input : {}));
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=chat-stores.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type SessionState } from '@celljs/ta-client';
|
|
2
|
+
import type { WebTool } from '../extension/web-extension-api.js';
|
|
3
|
+
export declare namespace ChatUtil {
|
|
4
|
+
function toolNames(tools: WebTool[]): string;
|
|
5
|
+
/** Ids of the runs of `write` and `edit` in a directory of packages that are not in `seen`. */
|
|
6
|
+
function packageEdits(state: SessionState, seen: Set<string>): string[];
|
|
7
|
+
function message(error: unknown): string;
|
|
8
|
+
/** Only the connection was lost: it mends itself, and what it cut off goes again once it is back. */
|
|
9
|
+
function lost(error: unknown): boolean;
|
|
10
|
+
/** A change nobody asked for now (after a run): a lost connection is no failure to tell, the next run does it again. */
|
|
11
|
+
function quietly(change: () => Promise<void>): () => Promise<void>;
|
|
12
|
+
/**
|
|
13
|
+
* Runs `run` again each time the connection is lost under it and comes back, while `wanted` (a few times
|
|
14
|
+
* at most): opening a conversation on a network that drops goes on, rather than failing.
|
|
15
|
+
*/
|
|
16
|
+
function untilConnected(run: () => Promise<void>, connected: () => Promise<void>, wanted: () => boolean): Promise<void>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { TaRemoteError } from '@celljs/ta-client';
|
|
2
|
+
/** A file in a directory of packages: `extensions/<name>/...`, of the user or a project. */
|
|
3
|
+
const PACKAGE_FILE = /(^|[\\/])extensions[\\/][^\\/]+[\\/]/;
|
|
4
|
+
export var ChatUtil;
|
|
5
|
+
(function (ChatUtil) {
|
|
6
|
+
function toolNames(tools) {
|
|
7
|
+
return tools
|
|
8
|
+
.map(tool => tool.name)
|
|
9
|
+
.sort()
|
|
10
|
+
.join(',');
|
|
11
|
+
}
|
|
12
|
+
ChatUtil.toolNames = toolNames;
|
|
13
|
+
/** Ids of the runs of `write` and `edit` in a directory of packages that are not in `seen`. */
|
|
14
|
+
function packageEdits(state, seen) {
|
|
15
|
+
return Object.entries(state.tools)
|
|
16
|
+
.filter(([id, run]) => {
|
|
17
|
+
var _a;
|
|
18
|
+
const path = (_a = run.args) === null || _a === void 0 ? void 0 : _a.path;
|
|
19
|
+
return !seen.has(id) && (run.toolName === 'write' || run.toolName === 'edit') && typeof path === 'string' && PACKAGE_FILE.test(path);
|
|
20
|
+
})
|
|
21
|
+
.map(([id]) => id);
|
|
22
|
+
}
|
|
23
|
+
ChatUtil.packageEdits = packageEdits;
|
|
24
|
+
function message(error) {
|
|
25
|
+
return error instanceof Error ? error.message : String(error);
|
|
26
|
+
}
|
|
27
|
+
ChatUtil.message = message;
|
|
28
|
+
/** Only the connection was lost: it mends itself, and what it cut off goes again once it is back. */
|
|
29
|
+
function lost(error) {
|
|
30
|
+
return TaRemoteError.isConnectionLost(error);
|
|
31
|
+
}
|
|
32
|
+
ChatUtil.lost = lost;
|
|
33
|
+
/** A change nobody asked for now (after a run): a lost connection is no failure to tell, the next run does it again. */
|
|
34
|
+
function quietly(change) {
|
|
35
|
+
return () => change().catch(error => {
|
|
36
|
+
if (!lost(error)) {
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
ChatUtil.quietly = quietly;
|
|
42
|
+
/**
|
|
43
|
+
* Runs `run` again each time the connection is lost under it and comes back, while `wanted` (a few times
|
|
44
|
+
* at most): opening a conversation on a network that drops goes on, rather than failing.
|
|
45
|
+
*/
|
|
46
|
+
async function untilConnected(run, connected, wanted) {
|
|
47
|
+
for (let tries = 1;; tries++) {
|
|
48
|
+
try {
|
|
49
|
+
return await run();
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
if (!lost(error) || tries >= 5 || !wanted()) {
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
55
|
+
await connected();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
ChatUtil.untilConnected = untilConnected;
|
|
60
|
+
})(ChatUtil || (ChatUtil = {}));
|
|
61
|
+
//# sourceMappingURL=chat-util.js.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useInject } from '@celljs/react';
|
|
2
|
+
import { SessionReducer, SessionStore } from '@celljs/ta-client';
|
|
2
3
|
import { ChevronLeft } from 'lucide-react';
|
|
3
4
|
import * as React from 'react';
|
|
4
5
|
import { Callout } from '../components/callout.js';
|
|
@@ -7,6 +8,7 @@ import { ConnectionBanner } from '../components/connection-bar.js';
|
|
|
7
8
|
import { DirectoryButton } from '../components/folder-picker.js';
|
|
8
9
|
import { HeroCards } from '../components/hero-cards.js';
|
|
9
10
|
import { IconButton, SidebarLeft } from '../components/icon.js';
|
|
11
|
+
import { MessageList } from '../components/message-list.js';
|
|
10
12
|
import { useScreenArriving } from '../components/phone-shell.js';
|
|
11
13
|
import { SessionView } from '../components/session-view.js';
|
|
12
14
|
import { TaAvatar } from '../components/ta-avatar.js';
|
|
@@ -53,24 +55,40 @@ function DraftView({ draft, menu, aboveComposer, belowComposer }) {
|
|
|
53
55
|
const list = React.useCallback((directory) => workbench.workspace.listDirectory('.', directory), [workbench]);
|
|
54
56
|
const pickModel = React.useCallback((model) => chat.setDraftModel(model), [chat]);
|
|
55
57
|
const model = useDraftModel(workbench.settings, draft, pickModel, t);
|
|
58
|
+
const { sending } = draft;
|
|
59
|
+
const going = !!sending && !sending.failed;
|
|
60
|
+
// Its first message, as the conversation will show it, while the session opens.
|
|
61
|
+
const sent = React.useMemo(() => {
|
|
62
|
+
var _a;
|
|
63
|
+
if (!sending) {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
const message = {
|
|
67
|
+
role: 'user',
|
|
68
|
+
content: [{ type: 'text', text: sending.message }, ...((_a = sending.images) !== null && _a !== void 0 ? _a : [])],
|
|
69
|
+
timestamp: Date.now(),
|
|
70
|
+
};
|
|
71
|
+
return SessionStore.withSent(SessionReducer.initial(), [{ id: 'draft', message, failed: sending.failed }]);
|
|
72
|
+
}, [sending]);
|
|
73
|
+
const outbox = React.useMemo(() => ({ resend: () => void chat.resendDraft(), discard: () => chat.discardDraft() }), [chat]);
|
|
56
74
|
return (React.createElement("section", { className: "ta-session" },
|
|
57
75
|
React.createElement("header", { className: "ta-session-header" },
|
|
58
76
|
menu,
|
|
59
|
-
React.createElement("div", { className: "ta-session-title" },
|
|
60
|
-
React.createElement("span", { className: "ta-title" }, t('ta.
|
|
77
|
+
React.createElement("div", { className: "ta-session-title" }, going ? (React.createElement(React.Fragment, null,
|
|
78
|
+
React.createElement("span", { className: "ta-title" }, MessageUtil.basename(draft.cwd) || t('ta.session.title')),
|
|
79
|
+
React.createElement("span", { className: "ta-muted ta-path", title: draft.cwd }, MessageUtil.shortPath(draft.cwd)))) : (React.createElement("span", { className: "ta-title" }, t('ta.chat.new')))),
|
|
61
80
|
React.createElement(WorkbenchToggle, null)),
|
|
62
|
-
React.createElement("div", { className:
|
|
63
|
-
React.createElement("div", { className: "ta-thread" },
|
|
64
|
-
React.createElement(Hero, { cwd: draft.cwd, onPick: text => void submit(text).catch(fail) }))),
|
|
81
|
+
React.createElement("div", { className: sent ? 'ta-scroll ta-conversation' : 'ta-scroll' },
|
|
82
|
+
React.createElement("div", { className: "ta-thread" }, sent ? React.createElement(MessageList, { state: sent, outbox: outbox }) : React.createElement(Hero, { cwd: draft.cwd, onPick: text => void submit(text).catch(fail) }))),
|
|
65
83
|
React.createElement("div", { className: "ta-bottom" },
|
|
66
84
|
aboveComposer,
|
|
67
|
-
React.createElement(Composer, { server: workbench.server, workspace: workbench.workspace, working:
|
|
85
|
+
React.createElement(Composer, { server: workbench.server, workspace: workbench.workspace, working: going, onStop: () => chat.stopDraft(), commands: [], cwd: draft.cwd || undefined, onSubmit: submit, onError: fail, talkPlace: "draft", actions: model ? [[model]] : undefined, beside: going ? undefined : React.createElement(DirectoryButton, { cwd: draft.cwd, list: list, remote: workbench, onPick: cwd => chat.setDraftCwd(cwd) }) }),
|
|
68
86
|
belowComposer)));
|
|
69
87
|
}
|
|
70
88
|
/** A conversation picked that is still loading, laid out as it will be: its head, a spinner, a message box that waits. */
|
|
71
89
|
function OpeningView({ info, menu }) {
|
|
72
90
|
const t = useT();
|
|
73
|
-
const [, workbench] = useWorkbench();
|
|
91
|
+
const [{ offlineShown }, workbench] = useWorkbench();
|
|
74
92
|
return (React.createElement("section", { className: "ta-session", "aria-busy": "true" },
|
|
75
93
|
React.createElement("header", { className: "ta-session-header" },
|
|
76
94
|
menu,
|
|
@@ -78,16 +96,16 @@ function OpeningView({ info, menu }) {
|
|
|
78
96
|
React.createElement("span", { className: "ta-title" }, (info === null || info === void 0 ? void 0 : info.title) || ((info === null || info === void 0 ? void 0 : info.cwd) ? MessageUtil.basename(info.cwd) : t('ta.session.title'))),
|
|
79
97
|
(info === null || info === void 0 ? void 0 : info.cwd) && (React.createElement("span", { className: "ta-muted ta-path", title: info.cwd }, MessageUtil.shortPath(info.cwd)))),
|
|
80
98
|
React.createElement(WorkbenchToggle, null)),
|
|
81
|
-
React.createElement("div", { className: "ta-empty" },
|
|
99
|
+
React.createElement("div", { className: "ta-empty" }, offlineShown ? (React.createElement("span", { className: "ta-muted" }, t('ta.chat.openingOffline'))) : (React.createElement(React.Fragment, null,
|
|
82
100
|
React.createElement("span", { className: "ta-spinner" }),
|
|
83
101
|
" ",
|
|
84
|
-
t('ta.chat.opening')),
|
|
102
|
+
t('ta.chat.opening')))),
|
|
85
103
|
React.createElement("div", { className: "ta-bottom", inert: true },
|
|
86
104
|
React.createElement(Composer, { server: workbench.server, workspace: workbench.workspace, working: false, commands: [], cwd: info === null || info === void 0 ? void 0 : info.cwd, onError: () => undefined }))));
|
|
87
105
|
}
|
|
88
106
|
/** The conversation shown, with the widgets of web extensions around its message box. */
|
|
89
107
|
export function ChatView({ widgets, onMenu, back }) {
|
|
90
|
-
var _a, _b;
|
|
108
|
+
var _a, _b, _c, _d;
|
|
91
109
|
const t = useT();
|
|
92
110
|
const [{ sessions, saved }, workbench] = useWorkbench();
|
|
93
111
|
const [{ store, draft, pending, opening, error }] = useChat();
|
|
@@ -123,7 +141,10 @@ export function ChatView({ widgets, onMenu, back }) {
|
|
|
123
141
|
" ",
|
|
124
142
|
t('ta.chat.opening'))))));
|
|
125
143
|
}
|
|
126
|
-
|
|
127
|
-
|
|
144
|
+
// One shown from the device under what is pending (a saved conversation, an agent's on its way) is said by what opens.
|
|
145
|
+
const info = (_b = sessions.find(session => session.sessionId === store.sessionId)) !== null && _b !== void 0 ? _b : (opening && pending === store.sessionId
|
|
146
|
+
? { sessionId: store.sessionId, sessionName: opening.title, cwd: (_c = opening.cwd) !== null && _c !== void 0 ? _c : '', sessionFile: opening.sessionFile }
|
|
147
|
+
: undefined);
|
|
148
|
+
return (React.createElement(SessionView, { key: store.sessionId, store: store, server: workbench.server, workspace: workbench.workspace, info: info, onClosed: refresh, onActivity: refresh, leading: menu, trailing: React.createElement(WorkbenchToggle, null), empty: React.createElement(Hero, { cwd: (_d = info === null || info === void 0 ? void 0 : info.cwd) !== null && _d !== void 0 ? _d : '', onPick: text => store.send(text).catch(() => undefined) }), aboveComposer: aboveComposer, belowComposer: around('belowEditor') }));
|
|
128
149
|
}
|
|
129
150
|
//# sourceMappingURL=chat-view.js.map
|