@celljs/ta-web 4.14.0 → 4.15.1
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 +1 -1
- package/README.md +1 -1
- package/esm/browser/assistant/assistant-initiative.js +1 -1
- package/esm/browser/components/access-view.js +3 -2
- package/esm/browser/components/account-menu.js +10 -3
- package/esm/browser/components/app-view.js +4 -1
- package/esm/browser/components/auth-view.d.ts +1 -1
- package/esm/browser/components/auth-view.js +38 -10
- package/esm/browser/components/custom-provider-advanced.d.ts +14 -0
- package/esm/browser/components/custom-provider-advanced.js +50 -0
- package/esm/browser/components/custom-provider-util.d.ts +38 -0
- package/esm/browser/components/custom-provider-util.js +103 -0
- package/esm/browser/components/custom-provider-view.d.ts +11 -0
- package/esm/browser/components/custom-provider-view.js +181 -0
- package/esm/browser/components/face.js +7 -2
- package/esm/browser/components/gallery.d.ts +9 -0
- package/esm/browser/components/gallery.js +57 -0
- package/esm/browser/components/host-view.d.ts +1 -1
- package/esm/browser/components/lightbox.d.ts +8 -1
- package/esm/browser/components/lightbox.js +4 -1
- package/esm/browser/components/markdown.js +6 -1
- package/esm/browser/components/media.d.ts +12 -2
- package/esm/browser/components/media.js +55 -13
- package/esm/browser/components/message-list.js +3 -2
- package/esm/browser/components/notice-center.js +6 -2
- package/esm/browser/components/serve-restart.d.ts +26 -0
- package/esm/browser/components/serve-restart.js +91 -0
- package/esm/browser/components/session-view.js +19 -11
- package/esm/browser/components/settings-choices.js +2 -3
- package/esm/browser/components/settings-controls.d.ts +7 -1
- package/esm/browser/components/settings-controls.js +8 -0
- package/esm/browser/components/settings-parts.js +25 -10
- package/esm/browser/components/sign-in-setup.js +3 -1
- package/esm/browser/editor/monaco-loader.js +7 -1
- package/esm/browser/extension/icons.js +3 -1
- package/esm/browser/extension/web-api-contributions.d.ts +3 -0
- package/esm/browser/extension/web-extension-api.d.ts +7 -0
- package/esm/browser/extension/web-extension-context.d.ts +2 -0
- package/esm/browser/extension/web-extension-context.js +19 -0
- package/esm/browser/game/game-loader.js +22 -2
- package/esm/browser/game/game3d-protocol.d.ts +13 -4
- package/esm/browser/i18n/locales.d.ts +68 -1
- package/esm/browser/i18n/locales.js +25 -1
- package/esm/browser/i18n/messages-ja.d.ts +2 -0
- package/esm/browser/i18n/messages-ja.js +984 -0
- package/esm/browser/i18n/messages-zh-tw.d.ts +3 -0
- package/esm/browser/i18n/messages-zh-tw.js +985 -0
- package/esm/browser/i18n/messages.d.ts +63 -0
- package/esm/browser/i18n/messages.js +126 -1
- package/esm/browser/i18n/use-t.js +3 -2
- package/esm/browser/settings/settings-protocol.d.ts +3 -2
- package/esm/browser/settings/settings-protocol.js +4 -3
- package/esm/browser/style/conversation.d.ts +1 -1
- package/esm/browser/style/conversation.js +18 -0
- package/esm/browser/style/layout.d.ts +1 -1
- package/esm/browser/style/layout.js +2 -0
- package/esm/browser/style/pages.d.ts +1 -1
- package/esm/browser/style/pages.js +45 -1
- package/esm/browser/style/shell.d.ts +1 -1
- package/esm/browser/style/shell.js +2 -0
- package/esm/browser/style/surfaces.d.ts +1 -1
- package/esm/browser/style/surfaces.js +1 -0
- package/esm/browser/util/desktop.d.ts +17 -1
- package/esm/browser/util/desktop.js +24 -0
- package/esm/browser/util/gallery.d.ts +18 -0
- package/esm/browser/util/gallery.js +123 -0
- package/esm/browser/util/link.d.ts +8 -0
- package/esm/browser/util/link.js +14 -0
- package/esm/browser/util/markdown.d.ts +11 -0
- package/esm/browser/util/markdown.js +4 -0
- package/esm/browser/util/thumbnail.d.ts +18 -0
- package/esm/browser/util/thumbnail.js +26 -0
- package/esm/browser/util/voice.d.ts +20 -1
- package/esm/browser/util/voice.js +27 -11
- package/esm/browser/workbench-protocol.d.ts +8 -0
- package/esm/browser/workbench-util.d.ts +2 -0
- package/esm/browser/workbench-util.js +6 -1
- package/esm/browser/workbench.d.ts +16 -0
- package/esm/browser/workbench.js +67 -0
- package/lib/browser/assistant/assistant-initiative.js +1 -1
- package/lib/browser/components/access-view.js +3 -2
- package/lib/browser/components/account-menu.js +9 -2
- package/lib/browser/components/app-view.js +4 -1
- package/lib/browser/components/auth-view.d.ts +1 -1
- package/lib/browser/components/auth-view.js +37 -9
- package/lib/browser/components/custom-provider-advanced.d.ts +15 -0
- package/lib/browser/components/custom-provider-advanced.js +86 -0
- package/lib/browser/components/custom-provider-util.d.ts +39 -0
- package/lib/browser/components/custom-provider-util.js +106 -0
- package/lib/browser/components/custom-provider-view.d.ts +12 -0
- package/lib/browser/components/custom-provider-view.js +217 -0
- package/lib/browser/components/face.js +7 -2
- package/lib/browser/components/gallery.d.ts +10 -0
- package/lib/browser/components/gallery.js +93 -0
- package/lib/browser/components/host-view.d.ts +1 -1
- package/lib/browser/components/lightbox.d.ts +8 -1
- package/lib/browser/components/lightbox.js +4 -1
- package/lib/browser/components/markdown.js +6 -1
- package/lib/browser/components/media.d.ts +12 -2
- package/lib/browser/components/media.js +57 -13
- package/lib/browser/components/message-list.js +3 -2
- package/lib/browser/components/notice-center.js +6 -2
- package/lib/browser/components/serve-restart.d.ts +27 -0
- package/lib/browser/components/serve-restart.js +129 -0
- package/lib/browser/components/session-view.js +21 -13
- package/lib/browser/components/settings-choices.js +1 -2
- package/lib/browser/components/settings-controls.d.ts +7 -1
- package/lib/browser/components/settings-controls.js +9 -0
- package/lib/browser/components/settings-parts.js +23 -8
- package/lib/browser/components/sign-in-setup.js +3 -1
- package/lib/browser/editor/monaco-loader.js +7 -1
- package/lib/browser/extension/icons.js +2 -0
- package/lib/browser/extension/web-api-contributions.d.ts +3 -0
- package/lib/browser/extension/web-extension-api.d.ts +7 -0
- package/lib/browser/extension/web-extension-context.d.ts +2 -0
- package/lib/browser/extension/web-extension-context.js +19 -0
- package/lib/browser/game/game-loader.js +22 -2
- package/lib/browser/game/game3d-protocol.d.ts +13 -4
- package/lib/browser/i18n/locales.d.ts +68 -1
- package/lib/browser/i18n/locales.js +25 -1
- package/lib/browser/i18n/messages-ja.d.ts +3 -0
- package/lib/browser/i18n/messages-ja.js +987 -0
- package/lib/browser/i18n/messages-zh-tw.d.ts +4 -0
- package/lib/browser/i18n/messages-zh-tw.js +988 -0
- package/lib/browser/i18n/messages.d.ts +63 -0
- package/lib/browser/i18n/messages.js +129 -2
- package/lib/browser/i18n/use-t.js +2 -1
- package/lib/browser/settings/settings-protocol.d.ts +3 -2
- package/lib/browser/settings/settings-protocol.js +4 -3
- package/lib/browser/style/conversation.d.ts +1 -1
- package/lib/browser/style/conversation.js +18 -0
- package/lib/browser/style/layout.d.ts +1 -1
- package/lib/browser/style/layout.js +2 -0
- package/lib/browser/style/pages.d.ts +1 -1
- package/lib/browser/style/pages.js +45 -1
- package/lib/browser/style/shell.d.ts +1 -1
- package/lib/browser/style/shell.js +2 -0
- package/lib/browser/style/surfaces.d.ts +1 -1
- package/lib/browser/style/surfaces.js +1 -0
- package/lib/browser/util/desktop.d.ts +17 -1
- package/lib/browser/util/desktop.js +24 -0
- package/lib/browser/util/gallery.d.ts +19 -0
- package/lib/browser/util/gallery.js +126 -0
- package/lib/browser/util/link.d.ts +8 -0
- package/lib/browser/util/link.js +14 -0
- package/lib/browser/util/markdown.d.ts +11 -0
- package/lib/browser/util/markdown.js +4 -0
- package/lib/browser/util/thumbnail.d.ts +19 -0
- package/lib/browser/util/thumbnail.js +29 -0
- package/lib/browser/util/voice.d.ts +20 -1
- package/lib/browser/util/voice.js +27 -11
- package/lib/browser/workbench-protocol.d.ts +8 -0
- package/lib/browser/workbench-util.d.ts +2 -0
- package/lib/browser/workbench-util.js +6 -1
- package/lib/browser/workbench.d.ts +16 -0
- package/lib/browser/workbench.js +67 -0
- package/package.json +7 -7
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
/** What the page tells Apple's recognizer: of the Ta app on iOS (TaSpeech.swift of apps/ta-mobile) or of Ta Desktop on macOS. */
|
|
2
|
+
export type NativeSpeechMessage = {
|
|
3
|
+
id: string;
|
|
4
|
+
action: 'start';
|
|
5
|
+
language: string;
|
|
6
|
+
continuous: boolean;
|
|
7
|
+
hints: string[];
|
|
8
|
+
} | {
|
|
9
|
+
id: string;
|
|
10
|
+
action: 'stop';
|
|
11
|
+
};
|
|
12
|
+
/** What it answers: the words so far of a listening, or its end. */
|
|
13
|
+
export interface NativeSpeechEvent {
|
|
14
|
+
id: string;
|
|
15
|
+
text?: string;
|
|
16
|
+
final?: boolean;
|
|
17
|
+
end?: boolean;
|
|
18
|
+
error?: string;
|
|
19
|
+
}
|
|
1
20
|
/** Talking to ta and hearing it, with what the browser or the app has: no service, no dependency. */
|
|
2
21
|
export declare namespace Voice {
|
|
3
22
|
/** The window event the Ta app on iOS answers a listening with. */
|
|
@@ -40,7 +59,7 @@ export declare namespace Voice {
|
|
|
40
59
|
function spoken(markdown: string): string;
|
|
41
60
|
/** What a text is read in: its sentences and lines, a long one in pieces at its commas. */
|
|
42
61
|
function sentences(text: string): string[];
|
|
43
|
-
/** The language a text is read in: Chinese for Chinese, whatever the page's. */
|
|
62
|
+
/** The language a text is read in: Japanese for kana, Chinese for other Han (the page's, if Chinese or Japanese), whatever the page's. */
|
|
44
63
|
function languageOf(text: string, language: string): string;
|
|
45
64
|
/**
|
|
46
65
|
* How natural a voice sounds, from what its name and address say: the neural voices of Edge and the premium
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DesktopUtil } from './desktop.js';
|
|
1
2
|
/** Talking to ta and hearing it, with what the browser or the app has: no service, no dependency. */
|
|
2
3
|
export var Voice;
|
|
3
4
|
(function (Voice) {
|
|
@@ -63,10 +64,24 @@ export var Voice;
|
|
|
63
64
|
const scope = globalThis;
|
|
64
65
|
return (_a = scope.SpeechRecognition) !== null && _a !== void 0 ? _a : scope.webkitSpeechRecognition;
|
|
65
66
|
}
|
|
66
|
-
/**
|
|
67
|
+
/**
|
|
68
|
+
* Apple's recognizer: of the Ta app on iOS, where WebKit's repeats what it heard and leaves out punctuation, and of
|
|
69
|
+
* Ta Desktop on macOS, where Chrome's, which Electron has, always fails with `network` (only Chrome may use its service).
|
|
70
|
+
*/
|
|
67
71
|
function nativeSpeech() {
|
|
68
72
|
var _a, _b;
|
|
69
|
-
|
|
73
|
+
const ios = (_b = (_a = globalThis.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b.taSpeech;
|
|
74
|
+
if (ios) {
|
|
75
|
+
return {
|
|
76
|
+
post: message => ios.postMessage(message),
|
|
77
|
+
onAnswer: listener => {
|
|
78
|
+
const heard = (event) => listener(event.detail);
|
|
79
|
+
globalThis.addEventListener(Voice.NATIVE_EVENT, heard);
|
|
80
|
+
return () => globalThis.removeEventListener(Voice.NATIVE_EVENT, heard);
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
return DesktopUtil.speech();
|
|
70
85
|
}
|
|
71
86
|
function canListen() {
|
|
72
87
|
return nativeSpeech() !== undefined || recognitionClass() !== undefined;
|
|
@@ -154,23 +169,21 @@ export var Voice;
|
|
|
154
169
|
function listenNatively(native, language, onText, onEnd, options) {
|
|
155
170
|
const id = crypto.randomUUID();
|
|
156
171
|
let ended = false;
|
|
157
|
-
const
|
|
158
|
-
const answer = event.detail;
|
|
172
|
+
const stopHearing = native.onAnswer(answer => {
|
|
159
173
|
if (ended || (answer === null || answer === void 0 ? void 0 : answer.id) !== id) {
|
|
160
174
|
return;
|
|
161
175
|
}
|
|
162
176
|
if (answer.end) {
|
|
163
177
|
ended = true;
|
|
164
|
-
|
|
178
|
+
stopHearing();
|
|
165
179
|
onEnd(answer.error === 'no-speech' ? undefined : answer.error);
|
|
166
180
|
}
|
|
167
181
|
else if (typeof answer.text === 'string') {
|
|
168
182
|
onText(answer.text, answer.final === true);
|
|
169
183
|
}
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
native.
|
|
173
|
-
return { stop: () => !ended && native.postMessage({ id, action: 'stop' }) };
|
|
184
|
+
});
|
|
185
|
+
native.post({ id, action: 'start', language, continuous: options.continuous === true, hints: hints(options.hints) });
|
|
186
|
+
return { stop: () => !ended && native.post({ id, action: 'stop' }) };
|
|
174
187
|
}
|
|
175
188
|
function canSpeak() {
|
|
176
189
|
return typeof speechSynthesis !== 'undefined';
|
|
@@ -225,9 +238,12 @@ export var Voice;
|
|
|
225
238
|
return pieces;
|
|
226
239
|
}
|
|
227
240
|
Voice.sentences = sentences;
|
|
228
|
-
/** The language a text is read in: Chinese for Chinese, whatever the page's. */
|
|
241
|
+
/** The language a text is read in: Japanese for kana, Chinese for other Han (the page's, if Chinese or Japanese), whatever the page's. */
|
|
229
242
|
function languageOf(text, language) {
|
|
230
|
-
|
|
243
|
+
if (/[\u3040-\u30ff]/.test(text)) {
|
|
244
|
+
return 'ja-JP';
|
|
245
|
+
}
|
|
246
|
+
return /[\u4e00-\u9fff]/.test(text) && !/^(zh|ja)\b/i.test(language) ? 'zh-CN' : language;
|
|
231
247
|
}
|
|
232
248
|
Voice.languageOf = languageOf;
|
|
233
249
|
/** Toys and the voices of a screen reader of old (Eloquence), which sound as machines. */
|
|
@@ -49,6 +49,8 @@ export interface WorkbenchState {
|
|
|
49
49
|
*/
|
|
50
50
|
offlineShown?: boolean;
|
|
51
51
|
server?: TaServerInfo;
|
|
52
|
+
/** Ta restarts at the user's word (restartServer), until the page is connected to the one that started again. */
|
|
53
|
+
restarting?: boolean;
|
|
52
54
|
/**
|
|
53
55
|
* The server tells the open sessions as they change (TaServer.watchSessions): the lists are read again
|
|
54
56
|
* only now and then. Not by a Ta service of before, whose lists are read again every few seconds.
|
|
@@ -128,6 +130,12 @@ export interface TaWorkbench {
|
|
|
128
130
|
* what names no directory opens. Open conversations stay in theirs.
|
|
129
131
|
*/
|
|
130
132
|
setWorkingDirectory(cwd: string): Promise<void>;
|
|
133
|
+
/**
|
|
134
|
+
* Restarts Ta: Ta Desktop as a whole when it started the Ta service, else the Ta service (TaServer.restartServer),
|
|
135
|
+
* which then runs the build installed now (TaServerInfo.update). What runs goes on after it. `restarting` until the
|
|
136
|
+
* page is connected again, when it loads again if it was of the build before.
|
|
137
|
+
*/
|
|
138
|
+
restartServer(): Promise<void>;
|
|
131
139
|
/**
|
|
132
140
|
* A store of a session on this connection; the caller attaches and detaches it. It can be made before
|
|
133
141
|
* there is a connection, to show a conversation kept on the device (SessionStoreOptions.initial): it is
|
|
@@ -47,6 +47,8 @@ export declare namespace WorkbenchUtil {
|
|
|
47
47
|
* the app, or at an address that is not this machine's. A sign-in there cannot come back to it by itself.
|
|
48
48
|
*/
|
|
49
49
|
function elsewhere(hostId: string | undefined, hostname?: string): boolean;
|
|
50
|
+
/** An address of this machine alone (`localhost`, `127.0.0.1`, `::1`), which no provider of accounts sends a browser back to. */
|
|
51
|
+
function loopback(hostname?: string): boolean;
|
|
50
52
|
/** In the Ta app on a phone, where no ta serve serves the page: it reaches one through a relay. */
|
|
51
53
|
function isApp(): boolean;
|
|
52
54
|
function readPairing(text: string | null): RelayPairing | undefined;
|
|
@@ -75,9 +75,14 @@ export var WorkbenchUtil;
|
|
|
75
75
|
* the app, or at an address that is not this machine's. A sign-in there cannot come back to it by itself.
|
|
76
76
|
*/
|
|
77
77
|
function elsewhere(hostId, hostname = typeof location === 'undefined' ? '' : location.hostname) {
|
|
78
|
-
return isApp() || Boolean(hostId === null || hostId === void 0 ? void 0 : hostId.startsWith('relay ')) || !
|
|
78
|
+
return isApp() || Boolean(hostId === null || hostId === void 0 ? void 0 : hostId.startsWith('relay ')) || !loopback(hostname);
|
|
79
79
|
}
|
|
80
80
|
WorkbenchUtil.elsewhere = elsewhere;
|
|
81
|
+
/** An address of this machine alone (`localhost`, `127.0.0.1`, `::1`), which no provider of accounts sends a browser back to. */
|
|
82
|
+
function loopback(hostname = typeof location === 'undefined' ? '' : location.hostname) {
|
|
83
|
+
return ['localhost', '127.0.0.1', '[::1]', '::1'].includes(hostname);
|
|
84
|
+
}
|
|
85
|
+
WorkbenchUtil.loopback = loopback;
|
|
81
86
|
/** In the Ta app on a phone, where no ta serve serves the page: it reaches one through a relay. */
|
|
82
87
|
function isApp() {
|
|
83
88
|
var _a, _b;
|
|
@@ -12,6 +12,12 @@ export declare class TaWorkbenchImpl implements TaWorkbench {
|
|
|
12
12
|
/** On the connection of the time, only while it is open: what it was at goes again once it opens (resend). */
|
|
13
13
|
readonly presence: PresenceReporter;
|
|
14
14
|
protected retryTimer?: ReturnType<typeof setTimeout>;
|
|
15
|
+
/** A restart asked for: whether a build was installed over the one running, and whether its connection closed yet. */
|
|
16
|
+
protected restart?: {
|
|
17
|
+
update: boolean;
|
|
18
|
+
closed: boolean;
|
|
19
|
+
timer: ReturnType<typeof setTimeout>;
|
|
20
|
+
};
|
|
15
21
|
/** While ta serve is not running: the next attempt, which `reconnect` makes at once. */
|
|
16
22
|
protected retry?: () => void;
|
|
17
23
|
protected attempts: number;
|
|
@@ -76,6 +82,14 @@ export declare class TaWorkbenchImpl implements TaWorkbench {
|
|
|
76
82
|
messages?: boolean;
|
|
77
83
|
state?: string[];
|
|
78
84
|
}): () => void;
|
|
85
|
+
restartServer(): Promise<void>;
|
|
86
|
+
/** A restart that failed, or did not come back: no longer waited for. */
|
|
87
|
+
protected restarted(): void;
|
|
88
|
+
/**
|
|
89
|
+
* Once the connection of a restart closed, the server read again is the Ta that started again: the restart is over,
|
|
90
|
+
* and a page of the build before loads again for the new one (the app on a phone has its own).
|
|
91
|
+
*/
|
|
92
|
+
protected followRestart(change: Partial<WorkbenchState>, next: WorkbenchState): void;
|
|
79
93
|
setWorkingDirectory(cwd: string): Promise<void>;
|
|
80
94
|
subscribe(listener: (state: WorkbenchState) => void): () => void;
|
|
81
95
|
start(): Promise<void>;
|
|
@@ -140,6 +154,8 @@ export declare class TaWorkbenchImpl implements TaWorkbench {
|
|
|
140
154
|
* page was not seen gets its grace from now.
|
|
141
155
|
*/
|
|
142
156
|
protected watchWake(): void;
|
|
157
|
+
/** Whether another build of Ta was installed since (TaServerInfo.update), read while the page is seen. */
|
|
158
|
+
protected checkUpdate(): Promise<void>;
|
|
143
159
|
protected update(change: Partial<WorkbenchState>): void;
|
|
144
160
|
protected keepLists(of: string): void;
|
|
145
161
|
}
|
package/esm/browser/workbench.js
CHANGED
|
@@ -13,9 +13,14 @@ import { deviceValues, OfflineKeys } from './offline/device-values.js';
|
|
|
13
13
|
import { PresenceReporter } from './presence/presence-reporter.js';
|
|
14
14
|
import { DEFAULT_SETTINGS } from './settings/settings-protocol.js';
|
|
15
15
|
import { StateUtil } from './state/state-protocol.js';
|
|
16
|
+
import { DesktopUtil } from './util/desktop.js';
|
|
16
17
|
import { WorkbenchCalls } from './workbench-calls.js';
|
|
17
18
|
import { TaWorkbench } from './workbench-protocol.js';
|
|
18
19
|
import { GRACE_MS, PAGE_BYTES, PROBE_MS, pageHost, SWITCH_MS, storage, WorkbenchError, WorkbenchUtil, } from './workbench-util.js';
|
|
20
|
+
/** How often a page that is seen reads again which build of Ta is installed (TaServerInfo.update). */
|
|
21
|
+
const UPDATE_CHECK_MS = 60000;
|
|
22
|
+
/** A restart not back in this long is no longer waited for: the row of the connection says what is wrong. */
|
|
23
|
+
const RESTART_WAIT_MS = 120000;
|
|
19
24
|
let TaWorkbenchImpl = class TaWorkbenchImpl {
|
|
20
25
|
constructor() {
|
|
21
26
|
this.list = WorkbenchUtil.readHosts(storage());
|
|
@@ -136,6 +141,54 @@ let TaWorkbenchImpl = class TaWorkbenchImpl {
|
|
|
136
141
|
}
|
|
137
142
|
};
|
|
138
143
|
}
|
|
144
|
+
async restartServer() {
|
|
145
|
+
var _a;
|
|
146
|
+
if (this.restart) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
const timer = setTimeout(() => this.restarted(), RESTART_WAIT_MS);
|
|
150
|
+
this.restart = { update: Boolean((_a = this.current.server) === null || _a === void 0 ? void 0 : _a.update), closed: false, timer };
|
|
151
|
+
this.update({ restarting: true });
|
|
152
|
+
try {
|
|
153
|
+
const desktop = DesktopUtil.restart();
|
|
154
|
+
if (!(desktop && (await desktop()))) {
|
|
155
|
+
await this.server.restartServer();
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
this.restarted();
|
|
160
|
+
throw error;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/** A restart that failed, or did not come back: no longer waited for. */
|
|
164
|
+
restarted() {
|
|
165
|
+
if (this.restart) {
|
|
166
|
+
clearTimeout(this.restart.timer);
|
|
167
|
+
this.restart = undefined;
|
|
168
|
+
this.update({ restarting: false });
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Once the connection of a restart closed, the server read again is the Ta that started again: the restart is over,
|
|
173
|
+
* and a page of the build before loads again for the new one (the app on a phone has its own).
|
|
174
|
+
*/
|
|
175
|
+
followRestart(change, next) {
|
|
176
|
+
const restart = this.restart;
|
|
177
|
+
if (!restart) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
if (next.status !== 'online') {
|
|
181
|
+
restart.closed = true;
|
|
182
|
+
}
|
|
183
|
+
else if (restart.closed && change.server) {
|
|
184
|
+
clearTimeout(restart.timer);
|
|
185
|
+
this.restart = undefined;
|
|
186
|
+
next.restarting = false;
|
|
187
|
+
if (restart.update && !WorkbenchUtil.isApp()) {
|
|
188
|
+
this.reload();
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
139
192
|
async setWorkingDirectory(cwd) {
|
|
140
193
|
this.update({ server: await this.server.setWorkingDirectory(cwd) });
|
|
141
194
|
}
|
|
@@ -606,15 +659,29 @@ let TaWorkbenchImpl = class TaWorkbenchImpl {
|
|
|
606
659
|
}
|
|
607
660
|
else {
|
|
608
661
|
(_a = this.connection) === null || _a === void 0 ? void 0 : _a.wake();
|
|
662
|
+
void this.checkUpdate();
|
|
609
663
|
}
|
|
610
664
|
this.update({});
|
|
611
665
|
};
|
|
612
666
|
document.addEventListener('visibilitychange', wake);
|
|
613
667
|
window.addEventListener('online', wake);
|
|
614
668
|
window.addEventListener('pageshow', wake);
|
|
669
|
+
setInterval(() => void this.checkUpdate(), UPDATE_CHECK_MS);
|
|
670
|
+
}
|
|
671
|
+
/** Whether another build of Ta was installed since (TaServerInfo.update), read while the page is seen. */
|
|
672
|
+
async checkUpdate() {
|
|
673
|
+
const connection = this.connection;
|
|
674
|
+
if (!connection || this.current.status !== 'online' || this.restart || document.visibilityState === 'hidden') {
|
|
675
|
+
return;
|
|
676
|
+
}
|
|
677
|
+
const server = await connection.server.getServerInfo().catch(() => undefined);
|
|
678
|
+
if (server && connection === this.connection && !this.restart) {
|
|
679
|
+
this.update({ server: WorkbenchUtil.same(this.current.server, server) });
|
|
680
|
+
}
|
|
615
681
|
}
|
|
616
682
|
update(change) {
|
|
617
683
|
const next = { ...this.current, ...change };
|
|
684
|
+
this.followRestart(change, next);
|
|
618
685
|
if (next.status !== 'offline') {
|
|
619
686
|
clearTimeout(this.graceTimer);
|
|
620
687
|
this.graceTimer = undefined;
|
|
@@ -4,7 +4,7 @@ exports.AssistantInitiative = exports.START_TASK = void 0;
|
|
|
4
4
|
/** The double starting a task it hands out: by default without asking, as pi asks nothing (Settings.confirmTasks). */
|
|
5
5
|
exports.START_TASK = {
|
|
6
6
|
id: 'double.start-task',
|
|
7
|
-
title: { en: 'The double starts the tasks it hands out', zh: '分身开始它交出的任务' },
|
|
7
|
+
title: { en: 'The double starts the tasks it hands out', zh: '分身开始它交出的任务', tw: '分身開始它交出的任務', ja: '分身が割り当てたタスクを開始' },
|
|
8
8
|
reversible: true,
|
|
9
9
|
level: 'act',
|
|
10
10
|
};
|
|
@@ -96,8 +96,9 @@ function AccessSettings({ info, onChange }) {
|
|
|
96
96
|
await onChange().catch(() => undefined);
|
|
97
97
|
}
|
|
98
98
|
};
|
|
99
|
-
// The sign-in goes through the page's own ta serve: not from the app, nor for another computer
|
|
100
|
-
|
|
99
|
+
// The sign-in goes through the page's own ta serve: not from the app, nor for another computer, nor at an address of
|
|
100
|
+
// this machine alone (the desktop app's), which the provider sends no one back to and where the token lets in anyway.
|
|
101
|
+
const here = !workbench_util_1.WorkbenchUtil.isApp() && !workbench_util_1.WorkbenchUtil.loopback() && workbench.host === workbench_util_1.WorkbenchUtil.serverOf({ token: '' }, location.host);
|
|
101
102
|
// Behind a gateway, only its administrators let accounts in; everyone sees the browsers of their own.
|
|
102
103
|
const manage = info.canManage !== false;
|
|
103
104
|
const bind = (provider) => run(async () => {
|
|
@@ -38,6 +38,7 @@ exports.AccountDialogs = AccountDialogs;
|
|
|
38
38
|
exports.AccountFigure = AccountFigure;
|
|
39
39
|
exports.useAccount = useAccount;
|
|
40
40
|
exports.AccountMenu = AccountMenu;
|
|
41
|
+
const ta_protocol_1 = require("@celljs/ta-protocol");
|
|
41
42
|
const lucide_react_1 = require("lucide-react");
|
|
42
43
|
const React = __importStar(require("react"));
|
|
43
44
|
const device_1 = require("../device/device");
|
|
@@ -51,6 +52,7 @@ const dismiss_1 = require("./dismiss");
|
|
|
51
52
|
const host_view_1 = require("./host-view");
|
|
52
53
|
const icon_1 = require("./icon");
|
|
53
54
|
const relay_view_1 = require("./relay-view");
|
|
55
|
+
const serve_restart_1 = require("./serve-restart");
|
|
54
56
|
const settings_controls_1 = require("./settings-controls");
|
|
55
57
|
const ta_avatar_1 = require("./ta-avatar");
|
|
56
58
|
const working_directory_1 = require("./working-directory");
|
|
@@ -61,8 +63,7 @@ const THEMES = [
|
|
|
61
63
|
];
|
|
62
64
|
const LANGUAGES = [
|
|
63
65
|
['system', 'ta.settings.language.system'],
|
|
64
|
-
[
|
|
65
|
-
['en-US', 'English'],
|
|
66
|
+
...ta_protocol_1.TaLanguageUtil.ALL.map(language => [language, ta_protocol_1.TaLanguageUtil.NAMES[language]]),
|
|
66
67
|
];
|
|
67
68
|
/**
|
|
68
69
|
* The entries of the account and of the settings, in groups: the settings, the packages and the keys; the model
|
|
@@ -76,6 +77,7 @@ function useAccountEntries(onSettings, onDialog) {
|
|
|
76
77
|
const [{ installable, standalone }, pwa] = (0, hooks_1.usePwa)();
|
|
77
78
|
// A finger has no keys to learn; a phone is not the computer that pairs phones.
|
|
78
79
|
const { touch, handheld } = (0, device_1.useDevice)();
|
|
80
|
+
const restartTa = (0, serve_restart_1.useRestartTa)();
|
|
79
81
|
const entry = (key, label, icon, run, more = {}) => ({
|
|
80
82
|
key,
|
|
81
83
|
label,
|
|
@@ -116,6 +118,11 @@ function useAccountEntries(onSettings, onDialog) {
|
|
|
116
118
|
],
|
|
117
119
|
[
|
|
118
120
|
...(installable && !standalone ? [entry('install', t('ta.pwa.install'), lucide_react_1.Download, () => void pwa.install())] : []),
|
|
121
|
+
...(restartTa.can
|
|
122
|
+
? [
|
|
123
|
+
entry('restart', restartTa.update ? t('ta.update.restartTo', { version: serve_restart_1.ServeRestartUtil.label(restartTa.update) }) : t('ta.restart'), lucide_react_1.RotateCw, () => void restartTa.restart()),
|
|
124
|
+
]
|
|
125
|
+
: []),
|
|
119
126
|
entry('about', t('ta.manage.about'), lucide_react_1.Info, () => onSettings('about')),
|
|
120
127
|
entry('signOut', t('ta.settings.signOut'), lucide_react_1.LogOut, () => workbench.signOut(), { danger: true }),
|
|
121
128
|
],
|
|
@@ -50,6 +50,7 @@ const use_t_1 = require("../i18n/use-t");
|
|
|
50
50
|
const code_renderers_1 = require("../markdown/code-renderers");
|
|
51
51
|
const notices_1 = require("../notices/notices");
|
|
52
52
|
const state_protocol_1 = require("../state/state-protocol");
|
|
53
|
+
const thumbnail_1 = require("../util/thumbnail");
|
|
53
54
|
const voice_1 = require("../util/voice");
|
|
54
55
|
const workbench_util_1 = require("../workbench-util");
|
|
55
56
|
const app_nav_1 = require("./app-nav");
|
|
@@ -81,6 +82,7 @@ const notice_center_1 = require("./notice-center");
|
|
|
81
82
|
const phone_shell_1 = require("./phone-shell");
|
|
82
83
|
const remote_prompts_1 = require("./remote-prompts");
|
|
83
84
|
const scan_screen_1 = require("./scan-screen");
|
|
85
|
+
const serve_restart_1 = require("./serve-restart");
|
|
84
86
|
const settings_view_1 = require("./settings-view");
|
|
85
87
|
const share_dialog_1 = require("./share-dialog");
|
|
86
88
|
const side_lists_1 = require("./side-lists");
|
|
@@ -154,7 +156,7 @@ function AppShell() {
|
|
|
154
156
|
const online = workbench.status === 'online';
|
|
155
157
|
// Files named in replies outside a conversation (channels, pages) are in the server's directory.
|
|
156
158
|
const files = (0, react_1.useInject)(files_protocol_1.TaFiles);
|
|
157
|
-
const fileUrl = React.useCallback(async (path) => files.loadable(await bench.workspace.fileUrl(path)), [bench, files]);
|
|
159
|
+
const fileUrl = React.useCallback(async (path, box) => files.loadable(thumbnail_1.ThumbnailUtil.boxed(await bench.workspace.fileUrl(path), box)), [bench, files]);
|
|
158
160
|
const openLink = (0, hooks_1.useOpenLink)(undefined);
|
|
159
161
|
(0, workbench_view_1.useDocument)();
|
|
160
162
|
(0, app_shell_hooks_1.useRefresh)(online);
|
|
@@ -464,6 +466,7 @@ function AppShell() {
|
|
|
464
466
|
React.createElement(notice_center_1.NoticeCenter, null),
|
|
465
467
|
React.createElement(link_dialog_1.LinkDialog, null),
|
|
466
468
|
React.createElement(remote_prompts_1.RemotePrompts, null),
|
|
469
|
+
React.createElement(serve_restart_1.ServeRestartNotices, null),
|
|
467
470
|
React.createElement(host_view_1.SwitchingVeil, null),
|
|
468
471
|
codeScan && React.createElement(scan_screen_1.ScanHost, { onCode: text => void codeScan.open(text), onAsk: askDouble }),
|
|
469
472
|
React.createElement(share_dialog_1.ShareHost, null),
|
|
@@ -4,7 +4,7 @@ export declare namespace AuthUtil {
|
|
|
4
4
|
function key(provider: TaAuthProvider): string;
|
|
5
5
|
/** Some provider is signed in, one way or another: Ta has models. */
|
|
6
6
|
function signedIn(providers: TaAuthProvider[]): boolean;
|
|
7
|
-
/** What can be signed in to from here, matching `words`: accounts
|
|
7
|
+
/** What can be signed in to from here, matching `words`: accounts, then keys; in each those the user added, then subscriptions, then by name. */
|
|
8
8
|
function offered(providers: TaAuthProvider[], words?: string): {
|
|
9
9
|
accounts: TaAuthProvider[];
|
|
10
10
|
keys: TaAuthProvider[];
|
|
@@ -46,6 +46,7 @@ const use_t_1 = require("../i18n/use-t");
|
|
|
46
46
|
const workbench_util_1 = require("../workbench-util");
|
|
47
47
|
const auth_pictures_1 = require("./auth-pictures");
|
|
48
48
|
const callout_1 = require("./callout");
|
|
49
|
+
const custom_provider_view_1 = require("./custom-provider-view");
|
|
49
50
|
const empty_state_1 = require("./empty-state");
|
|
50
51
|
const icon_1 = require("./icon");
|
|
51
52
|
const picture_1 = require("./picture");
|
|
@@ -61,11 +62,11 @@ var AuthUtil;
|
|
|
61
62
|
return providers.some(provider => provider.configured);
|
|
62
63
|
}
|
|
63
64
|
AuthUtil.signedIn = signedIn;
|
|
64
|
-
/** What can be signed in to from here, matching `words`: accounts
|
|
65
|
+
/** What can be signed in to from here, matching `words`: accounts, then keys; in each those the user added, then subscriptions, then by name. */
|
|
65
66
|
function offered(providers, words = '') {
|
|
66
67
|
const query = words.trim().toLowerCase();
|
|
67
68
|
const shown = providers.filter(provider => provider.interactive && (!query || `${provider.name} ${provider.id}`.toLowerCase().includes(query)));
|
|
68
|
-
const byName = (a, b) => Number(b.subscription) - Number(a.subscription) || a.name.localeCompare(b.name);
|
|
69
|
+
const byName = (a, b) => Number(!!b.custom) - Number(!!a.custom) || Number(b.subscription) - Number(a.subscription) || a.name.localeCompare(b.name);
|
|
69
70
|
return {
|
|
70
71
|
accounts: shown.filter(provider => provider.type === 'oauth').sort(byName),
|
|
71
72
|
keys: shown.filter(provider => provider.type === 'api_key').sort(byName),
|
|
@@ -241,17 +242,23 @@ function AuthFlow({ provider, onDone, onBack }) {
|
|
|
241
242
|
function ProviderRow({ provider, onPick, onSignOut, plain }) {
|
|
242
243
|
var _a, _b;
|
|
243
244
|
const t = (0, use_t_1.useT)();
|
|
244
|
-
const kind = provider.
|
|
245
|
+
const kind = provider.custom
|
|
246
|
+
? t('ta.auth.custom.kind')
|
|
247
|
+
: provider.type === 'api_key'
|
|
248
|
+
? t('ta.auth.apiKey')
|
|
249
|
+
: provider.subscription
|
|
250
|
+
? t('ta.auth.subscription')
|
|
251
|
+
: t('ta.auth.account');
|
|
245
252
|
const signedIn = ((_a = provider.configured) === null || _a === void 0 ? void 0 : _a.type) === provider.type;
|
|
246
253
|
const source = (_b = provider.configured) === null || _b === void 0 ? void 0 : _b.source;
|
|
247
254
|
return (React.createElement("div", { className: "ta-auth-row" },
|
|
248
255
|
React.createElement("button", { type: "button", className: "ta-auth-item", onClick: onPick },
|
|
249
256
|
React.createElement("span", { className: "ta-auth-name" }, provider.name),
|
|
250
|
-
(!plain || provider.subscription) && React.createElement("span", { className: "ta-auth-kind" }, kind),
|
|
257
|
+
(!plain || provider.subscription || provider.custom) && React.createElement("span", { className: "ta-auth-kind" }, kind),
|
|
251
258
|
signedIn && (React.createElement("span", { className: "ta-auth-on", title: source },
|
|
252
259
|
React.createElement(icon_1.Icon, { icon: lucide_react_1.Check, size: 13 }),
|
|
253
260
|
" ",
|
|
254
|
-
source && !/credential|OAuth/i.test(source) ? source : t('ta.auth.signedIn'))),
|
|
261
|
+
source && !provider.custom && !/credential|OAuth/i.test(source) ? source : t('ta.auth.signedIn'))),
|
|
255
262
|
React.createElement(icon_1.Icon, { icon: lucide_react_1.ChevronRight, size: 15 })),
|
|
256
263
|
onSignOut && provider.stored && signedIn && React.createElement(icon_1.IconButton, { icon: lucide_react_1.LogOut, label: t('ta.auth.signOut'), onClick: onSignOut })));
|
|
257
264
|
}
|
|
@@ -265,6 +272,8 @@ function AuthPanel({ onSignedIn, kinds }) {
|
|
|
265
272
|
const [words, setWords] = React.useState('');
|
|
266
273
|
/** On the first page: which way the user chose, before the providers of that way. */
|
|
267
274
|
const [kind, setKind] = React.useState();
|
|
275
|
+
/** A provider the user adds by its address (`new`), or one added so, being changed. */
|
|
276
|
+
const [editing, setEditing] = React.useState();
|
|
268
277
|
const back = React.useCallback(() => setPicked(undefined), []);
|
|
269
278
|
const done = React.useCallback(() => {
|
|
270
279
|
if (picked) {
|
|
@@ -274,6 +283,17 @@ function AuthPanel({ onSignedIn, kinds }) {
|
|
|
274
283
|
reload();
|
|
275
284
|
onSignedIn === null || onSignedIn === void 0 ? void 0 : onSignedIn();
|
|
276
285
|
}, [picked, notices, t, reload, onSignedIn]);
|
|
286
|
+
if (editing) {
|
|
287
|
+
return (React.createElement(custom_provider_view_1.CustomProviderForm, { provider: editing === 'new' ? undefined : editing, onBack: () => {
|
|
288
|
+
setEditing(undefined);
|
|
289
|
+
reload();
|
|
290
|
+
}, onSaved: saved => {
|
|
291
|
+
notices.notify(t('ta.auth.custom.saved', { name: saved.name }), { level: 'success' });
|
|
292
|
+
setEditing(undefined);
|
|
293
|
+
reload();
|
|
294
|
+
onSignedIn === null || onSignedIn === void 0 ? void 0 : onSignedIn();
|
|
295
|
+
} }));
|
|
296
|
+
}
|
|
277
297
|
if (picked) {
|
|
278
298
|
return React.createElement(AuthFlow, { provider: picked, onDone: done, onBack: back });
|
|
279
299
|
}
|
|
@@ -297,12 +317,20 @@ function AuthPanel({ onSignedIn, kinds }) {
|
|
|
297
317
|
});
|
|
298
318
|
return (React.createElement(picture_1.PictureCards, { cards: [card('oauth', t('ta.auth.accounts'), t('ta.auth.accountsExample')), card('api_key', t('ta.auth.keys'), t('ta.auth.keysExample'))] }));
|
|
299
319
|
}
|
|
320
|
+
const edit = (provider) => void bench.auth.listCustomProviders().then(list => { var _a; return setEditing((_a = list.find(each => each.id === provider.id)) !== null && _a !== void 0 ? _a : 'new'); }, error => notices.error(error));
|
|
300
321
|
const offered = AuthUtil.offered(providers, words);
|
|
301
322
|
const accounts = kind === 'api_key' ? [] : offered.accounts;
|
|
302
323
|
const keys = kind === 'oauth' ? [] : offered.keys;
|
|
303
|
-
const group = (title, list) => list.length > 0 && (React.createElement("section", { className: "ta-auth-group" },
|
|
324
|
+
const group = (title, list, first) => (list.length > 0 || first) && (React.createElement("section", { className: "ta-auth-group" },
|
|
304
325
|
title && React.createElement("h3", null, title),
|
|
305
|
-
|
|
326
|
+
first,
|
|
327
|
+
list.map(provider => (React.createElement(ProviderRow, { key: AuthUtil.key(provider), provider: provider, plain: kind !== undefined, onPick: () => (provider.custom ? edit(provider) : setPicked(provider)), onSignOut: () => void signOut(provider) })))));
|
|
328
|
+
// Whatever is searched: a service not in the list is one to add.
|
|
329
|
+
const add = kind !== 'oauth' && (React.createElement("button", { type: "button", className: "ta-auth-item ta-custom-add", onClick: () => setEditing('new') },
|
|
330
|
+
React.createElement(icon_1.Icon, { icon: lucide_react_1.Plus, size: 15 }),
|
|
331
|
+
React.createElement("span", { className: "ta-auth-name" }, t('ta.auth.custom.add')),
|
|
332
|
+
React.createElement("span", { className: "ta-auth-note" }, t('ta.auth.custom.addHint')),
|
|
333
|
+
React.createElement(icon_1.Icon, { icon: lucide_react_1.ChevronRight, size: 15 })));
|
|
306
334
|
return (React.createElement("div", { className: "ta-auth-panel" },
|
|
307
335
|
kind && (React.createElement("div", { className: "ta-auth-flow-head" },
|
|
308
336
|
React.createElement(icon_1.IconButton, { icon: lucide_react_1.ArrowLeft, label: t('ta.auth.back'), onClick: () => setKind(undefined) }),
|
|
@@ -312,8 +340,8 @@ function AuthPanel({ onSignedIn, kinds }) {
|
|
|
312
340
|
React.createElement("input", { placeholder: t('ta.auth.search'), value: words, onChange: event => setWords(event.target.value) })),
|
|
313
341
|
React.createElement("div", { className: "ta-auth-list" },
|
|
314
342
|
group(kind ? '' : t('ta.auth.accounts'), accounts),
|
|
315
|
-
group(kind ? '' : t('ta.auth.keys'), keys),
|
|
316
|
-
accounts.length + keys.length === 0 && React.createElement(empty_state_1.EmptyState, { compact: true, title: t('ta.auth.none') }))));
|
|
343
|
+
group(kind ? '' : t('ta.auth.keys'), keys, add),
|
|
344
|
+
accounts.length + keys.length === 0 && !add && React.createElement(empty_state_1.EmptyState, { compact: true, title: t('ta.auth.none') }))));
|
|
317
345
|
}
|
|
318
346
|
/** The model accounts, over the page (the gear menu). */
|
|
319
347
|
function AuthDialog({ onClose }) {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { TaCustomProvider } from '@celljs/ta-protocol';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { CustomProviderFormUtil } from './custom-provider-util';
|
|
4
|
+
type Advanced = CustomProviderFormUtil.Advanced;
|
|
5
|
+
/**
|
|
6
|
+
* The advanced fields of a model service added by its address, folded: what its models are (context window, output,
|
|
7
|
+
* thinking, pictures), the same for each, and the headers it sends, whose values ta serve keeps.
|
|
8
|
+
*/
|
|
9
|
+
export declare function CustomProviderAdvanced({ provider, state, onChange }: {
|
|
10
|
+
provider?: TaCustomProvider;
|
|
11
|
+
state: Advanced;
|
|
12
|
+
onChange(next: Advanced): void;
|
|
13
|
+
}): React.JSX.Element;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=custom-provider-advanced.d.ts.map
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.CustomProviderAdvanced = CustomProviderAdvanced;
|
|
37
|
+
const lucide_react_1 = require("lucide-react");
|
|
38
|
+
const React = __importStar(require("react"));
|
|
39
|
+
const use_t_1 = require("../i18n/use-t");
|
|
40
|
+
const custom_provider_util_1 = require("./custom-provider-util");
|
|
41
|
+
const icon_1 = require("./icon");
|
|
42
|
+
/** pi's defaults, shown where nothing is typed. */
|
|
43
|
+
const DEFAULTS = { contextWindow: '128000', maxTokens: '16384' };
|
|
44
|
+
/**
|
|
45
|
+
* The advanced fields of a model service added by its address, folded: what its models are (context window, output,
|
|
46
|
+
* thinking, pictures), the same for each, and the headers it sends, whose values ta serve keeps.
|
|
47
|
+
*/
|
|
48
|
+
function CustomProviderAdvanced({ provider, state, onChange }) {
|
|
49
|
+
var _a;
|
|
50
|
+
const t = (0, use_t_1.useT)();
|
|
51
|
+
const [open, setOpen] = React.useState(() => custom_provider_util_1.CustomProviderFormUtil.hasAdvanced(provider));
|
|
52
|
+
const mixed = (_a = provider === null || provider === void 0 ? void 0 : provider.mixed) !== null && _a !== void 0 ? _a : [];
|
|
53
|
+
const change = (key, value) => onChange({ ...state, [key]: value, touched: state.touched.includes(key) ? state.touched : [...state.touched, key] });
|
|
54
|
+
const placeholder = (key, fallback) => mixed.includes(key) && !state.touched.includes(key) ? t('ta.auth.custom.mixed') : fallback;
|
|
55
|
+
const rows = (headers) => onChange({ ...state, headers });
|
|
56
|
+
const number = (key, label) => (React.createElement("label", { className: "ta-store-field" },
|
|
57
|
+
React.createElement("span", { className: "ta-store-field-label" }, label),
|
|
58
|
+
React.createElement("input", { className: "ta-input", inputMode: "numeric", autoComplete: "off", spellCheck: false, placeholder: placeholder(key, DEFAULTS[key]), value: state[key], onChange: event => change(key, event.target.value) })));
|
|
59
|
+
const check = (key, label) => (React.createElement("label", { className: "ta-custom-check" },
|
|
60
|
+
React.createElement("input", { type: "checkbox", checked: state[key], onChange: event => change(key, event.target.checked) }),
|
|
61
|
+
React.createElement("span", null, label),
|
|
62
|
+
mixed.includes(key) && !state.touched.includes(key) && React.createElement("span", { className: "ta-store-field-optional" }, t('ta.auth.custom.mixed'))));
|
|
63
|
+
return (React.createElement("div", { className: `ta-custom-advanced${open ? ' ta-open' : ''}` },
|
|
64
|
+
React.createElement("button", { type: "button", className: "ta-custom-advanced-toggle", "aria-expanded": open, onClick: () => setOpen(!open) },
|
|
65
|
+
React.createElement("span", null, t('ta.auth.custom.advanced')),
|
|
66
|
+
React.createElement("span", { className: "ta-auth-note" }, t('ta.auth.custom.advancedHint')),
|
|
67
|
+
React.createElement(icon_1.Icon, { icon: lucide_react_1.ChevronDown, size: 15 })),
|
|
68
|
+
open && (React.createElement("div", { className: "ta-custom-advanced-body" },
|
|
69
|
+
React.createElement("div", { className: "ta-custom-pair" },
|
|
70
|
+
number('contextWindow', t('ta.auth.custom.contextWindow')),
|
|
71
|
+
number('maxTokens', t('ta.auth.custom.maxTokens'))),
|
|
72
|
+
check('reasoning', t('ta.auth.custom.reasoning')),
|
|
73
|
+
check('images', t('ta.auth.custom.images')),
|
|
74
|
+
React.createElement("div", { className: "ta-store-field" },
|
|
75
|
+
React.createElement("span", { className: "ta-store-field-label" }, t('ta.auth.custom.headers')),
|
|
76
|
+
state.headers.map((row, index) => (React.createElement("div", { key: index, className: "ta-custom-header" },
|
|
77
|
+
React.createElement("input", { className: "ta-input", autoComplete: "off", spellCheck: false, "aria-label": t('ta.auth.custom.headerName'), placeholder: t('ta.auth.custom.headerName'), value: row.name, onChange: event => rows(state.headers.map((each, at) => (at === index ? { ...each, name: event.target.value, kept: false } : each))) }),
|
|
78
|
+
React.createElement("input", { className: "ta-input", type: "password", autoComplete: "new-password", spellCheck: false, "aria-label": t('ta.auth.custom.headerValue'), placeholder: row.kept ? t('ta.auth.custom.keyKept') : t('ta.auth.custom.headerValue'), value: row.value, onChange: event => rows(state.headers.map((each, at) => (at === index ? { ...each, value: event.target.value } : each))) }),
|
|
79
|
+
React.createElement("button", { type: "button", className: "ta-custom-header-remove", "aria-label": t('ta.auth.custom.removeHeader', { name: row.name || t('ta.auth.custom.headers') }), onClick: () => rows(state.headers.filter((_, at) => at !== index)) },
|
|
80
|
+
React.createElement(icon_1.Icon, { icon: lucide_react_1.X, size: 14 }))))),
|
|
81
|
+
React.createElement("button", { type: "button", className: "ta-button ta-custom-fetch", onClick: () => rows([...state.headers, { name: '', value: '', kept: false }]) },
|
|
82
|
+
React.createElement(icon_1.Icon, { icon: lucide_react_1.Plus, size: 14 }),
|
|
83
|
+
" ",
|
|
84
|
+
t('ta.auth.custom.addHeader')))))));
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=custom-provider-advanced.js.map
|