@celljs/ta-web 4.14.0 → 4.15.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 +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 +2 -2
- 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/host-view.d.ts +1 -1
- 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 +11 -5
- package/esm/browser/components/sign-in-setup.js +3 -1
- package/esm/browser/editor/monaco-loader.js +7 -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 +56 -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 +972 -0
- package/esm/browser/i18n/messages-zh-tw.d.ts +3 -0
- package/esm/browser/i18n/messages-zh-tw.js +973 -0
- package/esm/browser/i18n/messages.d.ts +51 -0
- package/esm/browser/i18n/messages.js +102 -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/pages.d.ts +1 -1
- package/esm/browser/style/pages.js +45 -1
- package/esm/browser/util/desktop.d.ts +12 -1
- package/esm/browser/util/desktop.js +14 -0
- package/esm/browser/util/voice.d.ts +20 -1
- package/esm/browser/util/voice.js +27 -11
- package/esm/browser/workbench-util.d.ts +2 -0
- package/esm/browser/workbench-util.js +6 -1
- 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 +2 -2
- 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/host-view.d.ts +1 -1
- 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 +10 -4
- package/lib/browser/components/sign-in-setup.js +3 -1
- package/lib/browser/editor/monaco-loader.js +7 -1
- 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 +56 -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 +975 -0
- package/lib/browser/i18n/messages-zh-tw.d.ts +4 -0
- package/lib/browser/i18n/messages-zh-tw.js +976 -0
- package/lib/browser/i18n/messages.d.ts +51 -0
- package/lib/browser/i18n/messages.js +105 -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/pages.d.ts +1 -1
- package/lib/browser/style/pages.js +45 -1
- package/lib/browser/util/desktop.d.ts +12 -1
- package/lib/browser/util/desktop.js +14 -0
- package/lib/browser/util/voice.d.ts +20 -1
- package/lib/browser/util/voice.js +27 -11
- package/lib/browser/workbench-util.d.ts +2 -0
- package/lib/browser/workbench-util.js +6 -1
- package/package.json +7 -7
package/README.en.md
CHANGED
|
@@ -51,7 +51,7 @@ The gear above the avatar (`ManageMenu`) is a two-level menu: Settings (⌘/Ctrl
|
|
|
51
51
|
|
|
52
52
|
### Sign In to Model Service, Working Directory and Phone
|
|
53
53
|
|
|
54
|
-
- **Model accounts**: similar to pi's `/login` in the terminal, you can sign in with an account (OAuth, Claude, ChatGPT subscriptions) or API Key. Sign-in occurs on ta serve (`TaAuthServer`): the login page to open, device code, and key to fill are sent only to the requesting page; credentials are stored in `auth.json` on the ta serve machine, not in the browser. When no model is available (`CELL_TA_NOT_SIGNED_IN`), the page opens the login page directly instead of pi's `/login` prompt; the same applies to the desktop app on first launch.
|
|
54
|
+
- **Model accounts**: similar to pi's `/login` in the terminal, you can sign in with an account (OAuth, Claude, ChatGPT subscriptions) or API Key. Sign-in occurs on ta serve (`TaAuthServer`): the login page to open, device code, and key to fill are sent only to the requesting page; credentials are stored in `auth.json` on the ta serve machine, not in the browser. Add a custom model service, at the top of API key, takes the API it speaks (OpenAI Chat Completions / Responses, Anthropic Messages, Google Gemini), its address, a key (not needed for a local server) and its models, which can be read from the service and picked; Advanced, folded, applies to every model of the service: context window, max output (200k, 1m are taken), thinks before answering, takes pictures, and the headers it sends (their values stay on ta serve; left blank, kept); a field the models had apart stays so unless changed. Once saved they are in the + menu, and its row changes or deletes it. When no model is available (`CELL_TA_NOT_SIGNED_IN`), the page opens the login page directly instead of pi's `/login` prompt; the same applies to the desktop app on first launch.
|
|
55
55
|
- **Working directory**: when no directory is specified, new conversations and doubles open in ta serve's working directory. "Open working directory…" (`TaServer.setWorkingDirectory`) affects all clients and persists across restarts; already open conversations are not changed.
|
|
56
56
|
- **Sign-in page**: when ta serve takes accounts (GitHub, Google, WeChat, OpenID Connect), the sign-in page lists them first (`GET /sign-in`), the token can still be pasted below; an account not let in comes back to a note that the owner has to let it in. When ta serve is not on this computer (an address of the network, through a relay, the phone app), the OAuth sign-in of model accounts asks for the `localhost` address the browser ended on.
|
|
57
57
|
- **Use on your phone**: pair a device via Relay ([@celljs/ta-relay](../ta-relay/README.md)); the pairing link is displayed as a QR code (drawn by `QrCode` of ta-relay, with no dependencies) and shown only once. Below, it lists paired devices and whether ta serve is connected to Relay. The default Relay is `https://relay.cellbang.com`.
|
package/README.md
CHANGED
|
@@ -51,7 +51,7 @@ Web 客户端可以装成桌面或手机上的应用:Chrome / Edge 地址栏
|
|
|
51
51
|
|
|
52
52
|
### 登录模型服务、工作目录与手机
|
|
53
53
|
|
|
54
|
-
- **模型账号**:和终端里 pi 的 `/login` 一样,可以用账号(OAuth,Claude、ChatGPT 这类订阅)或 API Key 登录模型服务。登录在 ta serve 上进行(`TaAuthServer`):要打开的登录页、设备码、要填的 Key 只发给发起登录的页面;凭据存在 ta serve 所在电脑的 `auth.json
|
|
54
|
+
- **模型账号**:和终端里 pi 的 `/login` 一样,可以用账号(OAuth,Claude、ChatGPT 这类订阅)或 API Key 登录模型服务。登录在 ta serve 上进行(`TaAuthServer`):要打开的登录页、设备码、要填的 Key 只发给发起登录的页面;凭据存在 ta serve 所在电脑的 `auth.json`,不回到浏览器。API Key 一组最上面的“添加自定义模型服务”填接口格式(OpenAI Chat Completions / Responses、Anthropic Messages、Google Gemini)、服务地址、Key(本机服务可不填)和模型,模型可以从服务读取后点选;折叠的“高级设置”对这个服务的所有模型生效:上下文窗口、最大输出(可写 200k、1m)、会先思考、能看图片,以及请求头(值只保存在 ta serve,不改就留空);各模型原本不同的字段不改就各自保留。保存后在 + 菜单里就能选,点这一行可修改或删除。没有可用的模型时(`CELL_TA_NOT_SIGNED_IN`),页面直接打开登录页,而不是显示 pi 关于 `/login` 的提示;桌面应用第一次启动时也一样。
|
|
55
55
|
- **工作目录**:没指定目录时,新对话和分身在 ta serve 的工作目录里打开。"打开工作目录…"(`TaServer.setWorkingDirectory`)对所有客户端生效,跨重启保留;已经打开的对话不动。
|
|
56
56
|
- **登录页**:ta serve 配了账号登录(GitHub、Google、微信、OpenID Connect)时,登录页先列出这些按钮(`GET /sign-in`),下面仍可以粘贴 token;没被允许的账号回来后显示要等主人允许。ta serve 不在这台电脑上时(远程地址、经 Relay、手机应用),模型账号的 OAuth 登录提示把浏览器最后打开的 `localhost` 地址粘贴回来。
|
|
57
57
|
- **在手机上使用**:经 Relay 配对一台设备([@celljs/ta-relay](../ta-relay/README.md)),配对链接显示成二维码(ta-relay 的 `QrCode` 自己画,没有依赖),只显示一次;下面列出已配对的设备和 ta serve 是否连着 Relay,可以取消配对。默认 Relay 是 `https://relay.cellbang.com`。
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** The double starting a task it hands out: by default without asking, as pi asks nothing (Settings.confirmTasks). */
|
|
2
2
|
export const START_TASK = {
|
|
3
3
|
id: 'double.start-task',
|
|
4
|
-
title: { en: 'The double starts the tasks it hands out', zh: '分身开始它交出的任务' },
|
|
4
|
+
title: { en: 'The double starts the tasks it hands out', zh: '分身开始它交出的任务', tw: '分身開始它交出的任務', ja: '分身が割り当てたタスクを開始' },
|
|
5
5
|
reversible: true,
|
|
6
6
|
level: 'act',
|
|
7
7
|
};
|
|
@@ -59,8 +59,9 @@ export function AccessSettings({ info, onChange }) {
|
|
|
59
59
|
await onChange().catch(() => undefined);
|
|
60
60
|
}
|
|
61
61
|
};
|
|
62
|
-
// The sign-in goes through the page's own ta serve: not from the app, nor for another computer
|
|
63
|
-
|
|
62
|
+
// The sign-in goes through the page's own ta serve: not from the app, nor for another computer, nor at an address of
|
|
63
|
+
// this machine alone (the desktop app's), which the provider sends no one back to and where the token lets in anyway.
|
|
64
|
+
const here = !WorkbenchUtil.isApp() && !WorkbenchUtil.loopback() && workbench.host === WorkbenchUtil.serverOf({ token: '' }, location.host);
|
|
64
65
|
// Behind a gateway, only its administrators let accounts in; everyone sees the browsers of their own.
|
|
65
66
|
const manage = info.canManage !== false;
|
|
66
67
|
const bind = (provider) => run(async () => {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { TaLanguageUtil } from '@celljs/ta-protocol';
|
|
1
2
|
import { Check, ChevronRight, Download, FolderOpen, Info, Keyboard, KeyRound, Languages, LogOut, Monitor, Palette, Puzzle, Settings2, Smartphone, Sparkles, } from 'lucide-react';
|
|
2
3
|
import * as React from 'react';
|
|
3
4
|
import { useDevice } from '../device/device.js';
|
|
@@ -21,8 +22,7 @@ const THEMES = [
|
|
|
21
22
|
];
|
|
22
23
|
const LANGUAGES = [
|
|
23
24
|
['system', 'ta.settings.language.system'],
|
|
24
|
-
[
|
|
25
|
-
['en-US', 'English'],
|
|
25
|
+
...TaLanguageUtil.ALL.map(language => [language, TaLanguageUtil.NAMES[language]]),
|
|
26
26
|
];
|
|
27
27
|
/**
|
|
28
28
|
* The entries of the account and of the settings, in groups: the settings, the packages and the keys; the model
|
|
@@ -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[];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ArrowLeft, Check, ChevronRight, Copy, ExternalLink, KeyRound, LogOut, Search, X } from 'lucide-react';
|
|
1
|
+
import { ArrowLeft, Check, ChevronRight, Copy, ExternalLink, KeyRound, LogOut, Plus, Search, X } from 'lucide-react';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { createPortal } from 'react-dom';
|
|
4
4
|
import { useNotices, useWorkbench } from '../hooks.js';
|
|
@@ -6,6 +6,7 @@ import { useT } from '../i18n/use-t.js';
|
|
|
6
6
|
import { WorkbenchUtil } from '../workbench-util.js';
|
|
7
7
|
import { AuthPicture } from './auth-pictures.js';
|
|
8
8
|
import { Callout } from './callout.js';
|
|
9
|
+
import { CustomProviderForm } from './custom-provider-view.js';
|
|
9
10
|
import { EmptyState } from './empty-state.js';
|
|
10
11
|
import { Icon, IconButton } from './icon.js';
|
|
11
12
|
import { PictureCards } from './picture.js';
|
|
@@ -21,11 +22,11 @@ export var AuthUtil;
|
|
|
21
22
|
return providers.some(provider => provider.configured);
|
|
22
23
|
}
|
|
23
24
|
AuthUtil.signedIn = signedIn;
|
|
24
|
-
/** What can be signed in to from here, matching `words`: accounts
|
|
25
|
+
/** What can be signed in to from here, matching `words`: accounts, then keys; in each those the user added, then subscriptions, then by name. */
|
|
25
26
|
function offered(providers, words = '') {
|
|
26
27
|
const query = words.trim().toLowerCase();
|
|
27
28
|
const shown = providers.filter(provider => provider.interactive && (!query || `${provider.name} ${provider.id}`.toLowerCase().includes(query)));
|
|
28
|
-
const byName = (a, b) => Number(b.subscription) - Number(a.subscription) || a.name.localeCompare(b.name);
|
|
29
|
+
const byName = (a, b) => Number(!!b.custom) - Number(!!a.custom) || Number(b.subscription) - Number(a.subscription) || a.name.localeCompare(b.name);
|
|
29
30
|
return {
|
|
30
31
|
accounts: shown.filter(provider => provider.type === 'oauth').sort(byName),
|
|
31
32
|
keys: shown.filter(provider => provider.type === 'api_key').sort(byName),
|
|
@@ -201,17 +202,23 @@ function AuthFlow({ provider, onDone, onBack }) {
|
|
|
201
202
|
function ProviderRow({ provider, onPick, onSignOut, plain }) {
|
|
202
203
|
var _a, _b;
|
|
203
204
|
const t = useT();
|
|
204
|
-
const kind = provider.
|
|
205
|
+
const kind = provider.custom
|
|
206
|
+
? t('ta.auth.custom.kind')
|
|
207
|
+
: provider.type === 'api_key'
|
|
208
|
+
? t('ta.auth.apiKey')
|
|
209
|
+
: provider.subscription
|
|
210
|
+
? t('ta.auth.subscription')
|
|
211
|
+
: t('ta.auth.account');
|
|
205
212
|
const signedIn = ((_a = provider.configured) === null || _a === void 0 ? void 0 : _a.type) === provider.type;
|
|
206
213
|
const source = (_b = provider.configured) === null || _b === void 0 ? void 0 : _b.source;
|
|
207
214
|
return (React.createElement("div", { className: "ta-auth-row" },
|
|
208
215
|
React.createElement("button", { type: "button", className: "ta-auth-item", onClick: onPick },
|
|
209
216
|
React.createElement("span", { className: "ta-auth-name" }, provider.name),
|
|
210
|
-
(!plain || provider.subscription) && React.createElement("span", { className: "ta-auth-kind" }, kind),
|
|
217
|
+
(!plain || provider.subscription || provider.custom) && React.createElement("span", { className: "ta-auth-kind" }, kind),
|
|
211
218
|
signedIn && (React.createElement("span", { className: "ta-auth-on", title: source },
|
|
212
219
|
React.createElement(Icon, { icon: Check, size: 13 }),
|
|
213
220
|
" ",
|
|
214
|
-
source && !/credential|OAuth/i.test(source) ? source : t('ta.auth.signedIn'))),
|
|
221
|
+
source && !provider.custom && !/credential|OAuth/i.test(source) ? source : t('ta.auth.signedIn'))),
|
|
215
222
|
React.createElement(Icon, { icon: ChevronRight, size: 15 })),
|
|
216
223
|
onSignOut && provider.stored && signedIn && React.createElement(IconButton, { icon: LogOut, label: t('ta.auth.signOut'), onClick: onSignOut })));
|
|
217
224
|
}
|
|
@@ -225,6 +232,8 @@ export function AuthPanel({ onSignedIn, kinds }) {
|
|
|
225
232
|
const [words, setWords] = React.useState('');
|
|
226
233
|
/** On the first page: which way the user chose, before the providers of that way. */
|
|
227
234
|
const [kind, setKind] = React.useState();
|
|
235
|
+
/** A provider the user adds by its address (`new`), or one added so, being changed. */
|
|
236
|
+
const [editing, setEditing] = React.useState();
|
|
228
237
|
const back = React.useCallback(() => setPicked(undefined), []);
|
|
229
238
|
const done = React.useCallback(() => {
|
|
230
239
|
if (picked) {
|
|
@@ -234,6 +243,17 @@ export function AuthPanel({ onSignedIn, kinds }) {
|
|
|
234
243
|
reload();
|
|
235
244
|
onSignedIn === null || onSignedIn === void 0 ? void 0 : onSignedIn();
|
|
236
245
|
}, [picked, notices, t, reload, onSignedIn]);
|
|
246
|
+
if (editing) {
|
|
247
|
+
return (React.createElement(CustomProviderForm, { provider: editing === 'new' ? undefined : editing, onBack: () => {
|
|
248
|
+
setEditing(undefined);
|
|
249
|
+
reload();
|
|
250
|
+
}, onSaved: saved => {
|
|
251
|
+
notices.notify(t('ta.auth.custom.saved', { name: saved.name }), { level: 'success' });
|
|
252
|
+
setEditing(undefined);
|
|
253
|
+
reload();
|
|
254
|
+
onSignedIn === null || onSignedIn === void 0 ? void 0 : onSignedIn();
|
|
255
|
+
} }));
|
|
256
|
+
}
|
|
237
257
|
if (picked) {
|
|
238
258
|
return React.createElement(AuthFlow, { provider: picked, onDone: done, onBack: back });
|
|
239
259
|
}
|
|
@@ -257,12 +277,20 @@ export function AuthPanel({ onSignedIn, kinds }) {
|
|
|
257
277
|
});
|
|
258
278
|
return (React.createElement(PictureCards, { cards: [card('oauth', t('ta.auth.accounts'), t('ta.auth.accountsExample')), card('api_key', t('ta.auth.keys'), t('ta.auth.keysExample'))] }));
|
|
259
279
|
}
|
|
280
|
+
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));
|
|
260
281
|
const offered = AuthUtil.offered(providers, words);
|
|
261
282
|
const accounts = kind === 'api_key' ? [] : offered.accounts;
|
|
262
283
|
const keys = kind === 'oauth' ? [] : offered.keys;
|
|
263
|
-
const group = (title, list) => list.length > 0 && (React.createElement("section", { className: "ta-auth-group" },
|
|
284
|
+
const group = (title, list, first) => (list.length > 0 || first) && (React.createElement("section", { className: "ta-auth-group" },
|
|
264
285
|
title && React.createElement("h3", null, title),
|
|
265
|
-
|
|
286
|
+
first,
|
|
287
|
+
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) })))));
|
|
288
|
+
// Whatever is searched: a service not in the list is one to add.
|
|
289
|
+
const add = kind !== 'oauth' && (React.createElement("button", { type: "button", className: "ta-auth-item ta-custom-add", onClick: () => setEditing('new') },
|
|
290
|
+
React.createElement(Icon, { icon: Plus, size: 15 }),
|
|
291
|
+
React.createElement("span", { className: "ta-auth-name" }, t('ta.auth.custom.add')),
|
|
292
|
+
React.createElement("span", { className: "ta-auth-note" }, t('ta.auth.custom.addHint')),
|
|
293
|
+
React.createElement(Icon, { icon: ChevronRight, size: 15 })));
|
|
266
294
|
return (React.createElement("div", { className: "ta-auth-panel" },
|
|
267
295
|
kind && (React.createElement("div", { className: "ta-auth-flow-head" },
|
|
268
296
|
React.createElement(IconButton, { icon: ArrowLeft, label: t('ta.auth.back'), onClick: () => setKind(undefined) }),
|
|
@@ -272,8 +300,8 @@ export function AuthPanel({ onSignedIn, kinds }) {
|
|
|
272
300
|
React.createElement("input", { placeholder: t('ta.auth.search'), value: words, onChange: event => setWords(event.target.value) })),
|
|
273
301
|
React.createElement("div", { className: "ta-auth-list" },
|
|
274
302
|
group(kind ? '' : t('ta.auth.accounts'), accounts),
|
|
275
|
-
group(kind ? '' : t('ta.auth.keys'), keys),
|
|
276
|
-
accounts.length + keys.length === 0 && React.createElement(EmptyState, { compact: true, title: t('ta.auth.none') }))));
|
|
303
|
+
group(kind ? '' : t('ta.auth.keys'), keys, add),
|
|
304
|
+
accounts.length + keys.length === 0 && !add && React.createElement(EmptyState, { compact: true, title: t('ta.auth.none') }))));
|
|
277
305
|
}
|
|
278
306
|
/** The model accounts, over the page (the gear menu). */
|
|
279
307
|
export function AuthDialog({ onClose }) {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { TaCustomProvider } from '@celljs/ta-protocol';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { CustomProviderFormUtil } from './custom-provider-util.js';
|
|
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 {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ChevronDown, Plus, X } from 'lucide-react';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { useT } from '../i18n/use-t.js';
|
|
4
|
+
import { CustomProviderFormUtil } from './custom-provider-util.js';
|
|
5
|
+
import { Icon } from './icon.js';
|
|
6
|
+
/** pi's defaults, shown where nothing is typed. */
|
|
7
|
+
const DEFAULTS = { contextWindow: '128000', maxTokens: '16384' };
|
|
8
|
+
/**
|
|
9
|
+
* The advanced fields of a model service added by its address, folded: what its models are (context window, output,
|
|
10
|
+
* thinking, pictures), the same for each, and the headers it sends, whose values ta serve keeps.
|
|
11
|
+
*/
|
|
12
|
+
export function CustomProviderAdvanced({ provider, state, onChange }) {
|
|
13
|
+
var _a;
|
|
14
|
+
const t = useT();
|
|
15
|
+
const [open, setOpen] = React.useState(() => CustomProviderFormUtil.hasAdvanced(provider));
|
|
16
|
+
const mixed = (_a = provider === null || provider === void 0 ? void 0 : provider.mixed) !== null && _a !== void 0 ? _a : [];
|
|
17
|
+
const change = (key, value) => onChange({ ...state, [key]: value, touched: state.touched.includes(key) ? state.touched : [...state.touched, key] });
|
|
18
|
+
const placeholder = (key, fallback) => mixed.includes(key) && !state.touched.includes(key) ? t('ta.auth.custom.mixed') : fallback;
|
|
19
|
+
const rows = (headers) => onChange({ ...state, headers });
|
|
20
|
+
const number = (key, label) => (React.createElement("label", { className: "ta-store-field" },
|
|
21
|
+
React.createElement("span", { className: "ta-store-field-label" }, label),
|
|
22
|
+
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) })));
|
|
23
|
+
const check = (key, label) => (React.createElement("label", { className: "ta-custom-check" },
|
|
24
|
+
React.createElement("input", { type: "checkbox", checked: state[key], onChange: event => change(key, event.target.checked) }),
|
|
25
|
+
React.createElement("span", null, label),
|
|
26
|
+
mixed.includes(key) && !state.touched.includes(key) && React.createElement("span", { className: "ta-store-field-optional" }, t('ta.auth.custom.mixed'))));
|
|
27
|
+
return (React.createElement("div", { className: `ta-custom-advanced${open ? ' ta-open' : ''}` },
|
|
28
|
+
React.createElement("button", { type: "button", className: "ta-custom-advanced-toggle", "aria-expanded": open, onClick: () => setOpen(!open) },
|
|
29
|
+
React.createElement("span", null, t('ta.auth.custom.advanced')),
|
|
30
|
+
React.createElement("span", { className: "ta-auth-note" }, t('ta.auth.custom.advancedHint')),
|
|
31
|
+
React.createElement(Icon, { icon: ChevronDown, size: 15 })),
|
|
32
|
+
open && (React.createElement("div", { className: "ta-custom-advanced-body" },
|
|
33
|
+
React.createElement("div", { className: "ta-custom-pair" },
|
|
34
|
+
number('contextWindow', t('ta.auth.custom.contextWindow')),
|
|
35
|
+
number('maxTokens', t('ta.auth.custom.maxTokens'))),
|
|
36
|
+
check('reasoning', t('ta.auth.custom.reasoning')),
|
|
37
|
+
check('images', t('ta.auth.custom.images')),
|
|
38
|
+
React.createElement("div", { className: "ta-store-field" },
|
|
39
|
+
React.createElement("span", { className: "ta-store-field-label" }, t('ta.auth.custom.headers')),
|
|
40
|
+
state.headers.map((row, index) => (React.createElement("div", { key: index, className: "ta-custom-header" },
|
|
41
|
+
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))) }),
|
|
42
|
+
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))) }),
|
|
43
|
+
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)) },
|
|
44
|
+
React.createElement(Icon, { icon: X, size: 14 }))))),
|
|
45
|
+
React.createElement("button", { type: "button", className: "ta-button ta-custom-fetch", onClick: () => rows([...state.headers, { name: '', value: '', kept: false }]) },
|
|
46
|
+
React.createElement(Icon, { icon: Plus, size: 14 }),
|
|
47
|
+
" ",
|
|
48
|
+
t('ta.auth.custom.addHeader')))))));
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=custom-provider-advanced.js.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { TaCustomModelOptions, TaCustomProvider, TaCustomProviderInput } from '@celljs/ta-protocol';
|
|
2
|
+
/** What the form of a model service added by its address (custom-provider-view) does with what is typed. */
|
|
3
|
+
export declare namespace CustomProviderFormUtil {
|
|
4
|
+
/** The ids typed or pasted at once: apart by commas, spaces or lines. */
|
|
5
|
+
function split(text: string): string[];
|
|
6
|
+
/** The models with those added, each once, in the order they came. */
|
|
7
|
+
function add(models: readonly string[], ids: readonly string[]): string[];
|
|
8
|
+
function toggle(models: readonly string[], id: string): string[];
|
|
9
|
+
/** The name a provider gets when none is typed: the host of its address, as ta serve gives it. */
|
|
10
|
+
function host(baseUrl: string): string;
|
|
11
|
+
type OptionKey = keyof TaCustomModelOptions;
|
|
12
|
+
/** A header in the form: one kept on ta serve shows its name alone, its value left empty keeping it. */
|
|
13
|
+
interface HeaderRow {
|
|
14
|
+
name: string;
|
|
15
|
+
value: string;
|
|
16
|
+
kept: boolean;
|
|
17
|
+
}
|
|
18
|
+
/** The advanced fields as typed: numbers as text, and what the user changed. */
|
|
19
|
+
interface Advanced {
|
|
20
|
+
contextWindow: string;
|
|
21
|
+
maxTokens: string;
|
|
22
|
+
reasoning: boolean;
|
|
23
|
+
images: boolean;
|
|
24
|
+
headers: HeaderRow[];
|
|
25
|
+
touched: OptionKey[];
|
|
26
|
+
}
|
|
27
|
+
function advanced(provider?: TaCustomProvider): Advanced;
|
|
28
|
+
/** Whether the provider has anything advanced: the section opens with it. */
|
|
29
|
+
function hasAdvanced(provider?: TaCustomProvider): boolean;
|
|
30
|
+
/** A number of tokens as typed: `200000`, `200k`, `1m`, `200,000`; null when empty, undefined when not one. */
|
|
31
|
+
function tokens(text: string): number | null | undefined;
|
|
32
|
+
/** The options to save: those the models have not alike stay as they are unless the user changed them. Throws the text of a number that is not one. */
|
|
33
|
+
function optionsOf(state: Advanced, mixed: readonly OptionKey[]): NonNullable<TaCustomProviderInput['options']>;
|
|
34
|
+
/** The headers to send and save, by name; an empty value keeps the one kept. */
|
|
35
|
+
function headersOf(state: Advanced): Record<string, string>;
|
|
36
|
+
/** What a service listed, narrowed by the words typed. */
|
|
37
|
+
function shown(fetched: readonly string[], words: string): string[];
|
|
38
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/** What the form of a model service added by its address (custom-provider-view) does with what is typed. */
|
|
2
|
+
export var CustomProviderFormUtil;
|
|
3
|
+
(function (CustomProviderFormUtil) {
|
|
4
|
+
/** The ids typed or pasted at once: apart by commas, spaces or lines. */
|
|
5
|
+
function split(text) {
|
|
6
|
+
return text
|
|
7
|
+
.split(/[\s,,]+/)
|
|
8
|
+
.map(id => id.trim())
|
|
9
|
+
.filter(Boolean);
|
|
10
|
+
}
|
|
11
|
+
CustomProviderFormUtil.split = split;
|
|
12
|
+
/** The models with those added, each once, in the order they came. */
|
|
13
|
+
function add(models, ids) {
|
|
14
|
+
return [...new Set([...models, ...ids])];
|
|
15
|
+
}
|
|
16
|
+
CustomProviderFormUtil.add = add;
|
|
17
|
+
function toggle(models, id) {
|
|
18
|
+
return models.includes(id) ? models.filter(model => model !== id) : [...models, id];
|
|
19
|
+
}
|
|
20
|
+
CustomProviderFormUtil.toggle = toggle;
|
|
21
|
+
/** The name a provider gets when none is typed: the host of its address, as ta serve gives it. */
|
|
22
|
+
function host(baseUrl) {
|
|
23
|
+
try {
|
|
24
|
+
return new URL(baseUrl.trim()).host;
|
|
25
|
+
}
|
|
26
|
+
catch (_a) {
|
|
27
|
+
return '';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
CustomProviderFormUtil.host = host;
|
|
31
|
+
function advanced(provider) {
|
|
32
|
+
var _a, _b;
|
|
33
|
+
const options = (_a = provider === null || provider === void 0 ? void 0 : provider.options) !== null && _a !== void 0 ? _a : {};
|
|
34
|
+
return {
|
|
35
|
+
contextWindow: options.contextWindow ? String(options.contextWindow) : '',
|
|
36
|
+
maxTokens: options.maxTokens ? String(options.maxTokens) : '',
|
|
37
|
+
reasoning: options.reasoning === true,
|
|
38
|
+
images: options.images === true,
|
|
39
|
+
headers: ((_b = provider === null || provider === void 0 ? void 0 : provider.headers) !== null && _b !== void 0 ? _b : []).map(name => ({ name, value: '', kept: true })),
|
|
40
|
+
touched: [],
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
CustomProviderFormUtil.advanced = advanced;
|
|
44
|
+
/** Whether the provider has anything advanced: the section opens with it. */
|
|
45
|
+
function hasAdvanced(provider) {
|
|
46
|
+
return !!provider && (Object.keys(provider.options).length > 0 || provider.mixed.length > 0 || provider.headers.length > 0);
|
|
47
|
+
}
|
|
48
|
+
CustomProviderFormUtil.hasAdvanced = hasAdvanced;
|
|
49
|
+
/** A number of tokens as typed: `200000`, `200k`, `1m`, `200,000`; null when empty, undefined when not one. */
|
|
50
|
+
function tokens(text) {
|
|
51
|
+
const plain = text
|
|
52
|
+
.trim()
|
|
53
|
+
.toLowerCase()
|
|
54
|
+
.replace(/[,_\s]/g, '');
|
|
55
|
+
if (!plain) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
const match = /^(\d+(?:\.\d+)?)([km]?)$/.exec(plain);
|
|
59
|
+
const value = match ? Math.round(Number(match[1]) * (match[2] === 'k' ? 1000 : match[2] === 'm' ? 1000000 : 1)) : Number.NaN;
|
|
60
|
+
return Number.isInteger(value) && value > 0 ? value : undefined;
|
|
61
|
+
}
|
|
62
|
+
CustomProviderFormUtil.tokens = tokens;
|
|
63
|
+
/** The options to save: those the models have not alike stay as they are unless the user changed them. Throws the text of a number that is not one. */
|
|
64
|
+
function optionsOf(state, mixed) {
|
|
65
|
+
const options = {};
|
|
66
|
+
const given = (key) => !mixed.includes(key) || state.touched.includes(key);
|
|
67
|
+
for (const key of ['contextWindow', 'maxTokens']) {
|
|
68
|
+
if (given(key)) {
|
|
69
|
+
const value = tokens(state[key]);
|
|
70
|
+
if (value === undefined) {
|
|
71
|
+
throw new RangeError(state[key]);
|
|
72
|
+
}
|
|
73
|
+
options[key] = value;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
for (const key of ['reasoning', 'images']) {
|
|
77
|
+
if (given(key)) {
|
|
78
|
+
options[key] = state[key];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return options;
|
|
82
|
+
}
|
|
83
|
+
CustomProviderFormUtil.optionsOf = optionsOf;
|
|
84
|
+
/** The headers to send and save, by name; an empty value keeps the one kept. */
|
|
85
|
+
function headersOf(state) {
|
|
86
|
+
const headers = {};
|
|
87
|
+
for (const row of state.headers) {
|
|
88
|
+
const name = row.name.trim();
|
|
89
|
+
if (name) {
|
|
90
|
+
headers[name] = row.value.trim();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return headers;
|
|
94
|
+
}
|
|
95
|
+
CustomProviderFormUtil.headersOf = headersOf;
|
|
96
|
+
/** What a service listed, narrowed by the words typed. */
|
|
97
|
+
function shown(fetched, words) {
|
|
98
|
+
const query = words.trim().toLowerCase();
|
|
99
|
+
return query ? fetched.filter(id => id.toLowerCase().includes(query)) : [...fetched];
|
|
100
|
+
}
|
|
101
|
+
CustomProviderFormUtil.shown = shown;
|
|
102
|
+
})(CustomProviderFormUtil || (CustomProviderFormUtil = {}));
|
|
103
|
+
//# sourceMappingURL=custom-provider-util.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type TaCustomProvider } from '@celljs/ta-protocol';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* A provider of models the user adds by its address and key, or changes: the API it speaks, where it is, its key and
|
|
5
|
+
* its models, which the service can list. ta serve keeps it in pi's models.json; the key never comes back here.
|
|
6
|
+
*/
|
|
7
|
+
export declare function CustomProviderForm({ provider, onSaved, onBack }: {
|
|
8
|
+
provider?: TaCustomProvider;
|
|
9
|
+
onSaved(saved: TaCustomProvider): void;
|
|
10
|
+
onBack(): void;
|
|
11
|
+
}): React.JSX.Element;
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { TA_CUSTOM_APIS } from '@celljs/ta-protocol';
|
|
2
|
+
import { ArrowLeft, Check, Download, ShieldCheck, Trash2, X } from 'lucide-react';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { useNotices, useWorkbench } from '../hooks.js';
|
|
5
|
+
import { useT } from '../i18n/use-t.js';
|
|
6
|
+
import { BusyMark, useBusy } from './busy.js';
|
|
7
|
+
import { Callout } from './callout.js';
|
|
8
|
+
import { CustomProviderAdvanced } from './custom-provider-advanced.js';
|
|
9
|
+
import { CustomProviderFormUtil } from './custom-provider-util.js';
|
|
10
|
+
import { Icon, IconButton } from './icon.js';
|
|
11
|
+
const API_WORDS = {
|
|
12
|
+
'openai-completions': 'ta.auth.custom.apiOpenai',
|
|
13
|
+
'openai-responses': 'ta.auth.custom.apiResponses',
|
|
14
|
+
'anthropic-messages': 'ta.auth.custom.apiAnthropic',
|
|
15
|
+
'google-generative-ai': 'ta.auth.custom.apiGoogle',
|
|
16
|
+
};
|
|
17
|
+
/** What an address of each API looks like. */
|
|
18
|
+
const ADDRESSES = {
|
|
19
|
+
'openai-completions': 'https://api.example.com/v1',
|
|
20
|
+
'openai-responses': 'https://api.example.com/v1',
|
|
21
|
+
'anthropic-messages': 'https://api.example.com',
|
|
22
|
+
'google-generative-ai': 'https://generativelanguage.googleapis.com/v1beta',
|
|
23
|
+
};
|
|
24
|
+
/** A list a service gave longer than this has a box to narrow it. */
|
|
25
|
+
const FILTER_FROM = 8;
|
|
26
|
+
/**
|
|
27
|
+
* A provider of models the user adds by its address and key, or changes: the API it speaks, where it is, its key and
|
|
28
|
+
* its models, which the service can list. ta serve keeps it in pi's models.json; the key never comes back here.
|
|
29
|
+
*/
|
|
30
|
+
export function CustomProviderForm({ provider, onSaved, onBack }) {
|
|
31
|
+
var _a, _b, _c, _d, _e;
|
|
32
|
+
const t = useT();
|
|
33
|
+
const [, bench] = useWorkbench();
|
|
34
|
+
const [, notices] = useNotices();
|
|
35
|
+
const [api, setApi] = React.useState((_a = provider === null || provider === void 0 ? void 0 : provider.api) !== null && _a !== void 0 ? _a : 'openai-completions');
|
|
36
|
+
const [baseUrl, setBaseUrl] = React.useState((_b = provider === null || provider === void 0 ? void 0 : provider.baseUrl) !== null && _b !== void 0 ? _b : '');
|
|
37
|
+
const [apiKey, setApiKey] = React.useState('');
|
|
38
|
+
const [name, setName] = React.useState((_c = provider === null || provider === void 0 ? void 0 : provider.name) !== null && _c !== void 0 ? _c : '');
|
|
39
|
+
const [models, setModels] = React.useState((_d = provider === null || provider === void 0 ? void 0 : provider.models) !== null && _d !== void 0 ? _d : []);
|
|
40
|
+
const [draft, setDraft] = React.useState('');
|
|
41
|
+
const [fetched, setFetched] = React.useState();
|
|
42
|
+
const [fetchError, setFetchError] = React.useState();
|
|
43
|
+
const [words, setWords] = React.useState('');
|
|
44
|
+
const [advanced, setAdvanced] = React.useState(() => CustomProviderFormUtil.advanced(provider));
|
|
45
|
+
const [saving, runSave] = useBusy();
|
|
46
|
+
const [fetching, runFetch] = useBusy();
|
|
47
|
+
const [removing, runRemove] = useBusy();
|
|
48
|
+
const key = apiKey.trim() || undefined;
|
|
49
|
+
const typed = () => CustomProviderFormUtil.add(models, CustomProviderFormUtil.split(draft));
|
|
50
|
+
const addDraft = () => {
|
|
51
|
+
setModels(typed());
|
|
52
|
+
setDraft('');
|
|
53
|
+
};
|
|
54
|
+
const fetchModels = () => runFetch(async () => {
|
|
55
|
+
setFetchError(undefined);
|
|
56
|
+
try {
|
|
57
|
+
const ids = await bench.auth.fetchCustomModels({
|
|
58
|
+
id: provider === null || provider === void 0 ? void 0 : provider.id,
|
|
59
|
+
api,
|
|
60
|
+
baseUrl,
|
|
61
|
+
apiKey: key,
|
|
62
|
+
headers: CustomProviderFormUtil.headersOf(advanced),
|
|
63
|
+
});
|
|
64
|
+
setFetched(ids);
|
|
65
|
+
setWords('');
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
setFetched(undefined);
|
|
69
|
+
setFetchError(error instanceof Error ? error.message : String(error));
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
const save = () => runSave(async () => {
|
|
73
|
+
var _a;
|
|
74
|
+
const chosen = typed();
|
|
75
|
+
setModels(chosen);
|
|
76
|
+
setDraft('');
|
|
77
|
+
if (chosen.length === 0) {
|
|
78
|
+
notices.notify(t('ta.auth.custom.needModel'), { level: 'warning' });
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
let options;
|
|
82
|
+
try {
|
|
83
|
+
options = CustomProviderFormUtil.optionsOf(advanced, (_a = provider === null || provider === void 0 ? void 0 : provider.mixed) !== null && _a !== void 0 ? _a : []);
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
notices.notify(t('ta.auth.custom.badNumber', { value: error instanceof Error ? error.message : String(error) }), { level: 'warning' });
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
try {
|
|
90
|
+
const headers = CustomProviderFormUtil.headersOf(advanced);
|
|
91
|
+
onSaved(await bench.auth.saveCustomProvider({ id: provider === null || provider === void 0 ? void 0 : provider.id, name, api, baseUrl, apiKey: key, models: chosen, options, headers }));
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
notices.error(error);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
const remove = () => runRemove(async () => {
|
|
98
|
+
if (!provider) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const confirmed = await notices.confirm({
|
|
102
|
+
title: t('ta.auth.custom.removeConfirm', { name: provider.name }),
|
|
103
|
+
confirmLabel: t('ta.auth.custom.remove'),
|
|
104
|
+
danger: true,
|
|
105
|
+
});
|
|
106
|
+
if (confirmed) {
|
|
107
|
+
await bench.auth.removeCustomProvider(provider.id).then(onBack, error => notices.error(error));
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
const shown = fetched ? CustomProviderFormUtil.shown(fetched, words) : [];
|
|
111
|
+
return (React.createElement("div", { className: "ta-auth-flow ta-custom-flow" },
|
|
112
|
+
React.createElement("div", { className: "ta-auth-flow-head" },
|
|
113
|
+
React.createElement(IconButton, { icon: ArrowLeft, label: t('ta.auth.back'), onClick: onBack }),
|
|
114
|
+
React.createElement("span", { className: "ta-auth-flow-title" }, (_e = provider === null || provider === void 0 ? void 0 : provider.name) !== null && _e !== void 0 ? _e : t('ta.auth.custom.title')),
|
|
115
|
+
React.createElement("span", { className: "ta-auth-kind" }, t('ta.auth.custom.kind'))),
|
|
116
|
+
React.createElement("form", { className: "ta-custom-form", onSubmit: event => {
|
|
117
|
+
event.preventDefault();
|
|
118
|
+
void save();
|
|
119
|
+
} },
|
|
120
|
+
React.createElement("label", { className: "ta-store-field" },
|
|
121
|
+
React.createElement("span", { className: "ta-store-field-label" }, t('ta.auth.custom.api')),
|
|
122
|
+
React.createElement("select", { className: "ta-input ta-select", value: api, onChange: event => setApi(event.target.value) }, TA_CUSTOM_APIS.map(each => (React.createElement("option", { key: each, value: each }, t(API_WORDS[each])))))),
|
|
123
|
+
React.createElement("label", { className: "ta-store-field" },
|
|
124
|
+
React.createElement("span", { className: "ta-store-field-label" }, t('ta.auth.custom.baseUrl')),
|
|
125
|
+
React.createElement("input", { className: "ta-input", type: "url", inputMode: "url", autoComplete: "off", spellCheck: false, required: true, placeholder: ADDRESSES[api], value: baseUrl, onChange: event => setBaseUrl(event.target.value) })),
|
|
126
|
+
React.createElement("label", { className: "ta-store-field" },
|
|
127
|
+
React.createElement("span", { className: "ta-store-field-label" },
|
|
128
|
+
t('ta.auth.custom.apiKey'),
|
|
129
|
+
React.createElement("span", { className: "ta-store-field-optional" }, t('ta.auth.custom.keyOptional'))),
|
|
130
|
+
React.createElement("input", { className: "ta-input", type: "password", autoComplete: "new-password", spellCheck: false, placeholder: (provider === null || provider === void 0 ? void 0 : provider.hasKey) ? t('ta.auth.custom.keyKept') : 'sk-…', value: apiKey, onChange: event => setApiKey(event.target.value) })),
|
|
131
|
+
React.createElement("label", { className: "ta-store-field" },
|
|
132
|
+
React.createElement("span", { className: "ta-store-field-label" },
|
|
133
|
+
t('ta.auth.custom.name'),
|
|
134
|
+
React.createElement("span", { className: "ta-store-field-optional" }, t('ta.auth.custom.optional'))),
|
|
135
|
+
React.createElement("input", { className: "ta-input", autoComplete: "off", spellCheck: false, placeholder: CustomProviderFormUtil.host(baseUrl), value: name, onChange: event => setName(event.target.value) })),
|
|
136
|
+
React.createElement("div", { className: "ta-store-field" },
|
|
137
|
+
React.createElement("span", { className: "ta-store-field-label" }, t('ta.auth.custom.models')),
|
|
138
|
+
React.createElement("div", { className: "ta-custom-models" },
|
|
139
|
+
models.map(id => (React.createElement("span", { key: id, className: "ta-custom-chip" },
|
|
140
|
+
React.createElement("span", { className: "ta-custom-chip-text" }, id),
|
|
141
|
+
React.createElement("button", { type: "button", "aria-label": t('ta.auth.custom.removeModel', { id }), onClick: () => setModels(before => before.filter(model => model !== id)) },
|
|
142
|
+
React.createElement(Icon, { icon: X, size: 12 }))))),
|
|
143
|
+
React.createElement("input", { className: "ta-custom-model-input", autoComplete: "off", spellCheck: false, "aria-label": t('ta.auth.custom.models'), placeholder: models.length ? '' : t('ta.auth.custom.modelPlaceholder'), value: draft, onChange: event => setDraft(event.target.value), onBlur: addDraft, onKeyDown: event => {
|
|
144
|
+
if ((event.key === 'Enter' || event.key === ',') && !event.nativeEvent.isComposing) {
|
|
145
|
+
event.preventDefault();
|
|
146
|
+
addDraft();
|
|
147
|
+
}
|
|
148
|
+
else if (event.key === 'Backspace' && !draft && models.length) {
|
|
149
|
+
setModels(models.slice(0, -1));
|
|
150
|
+
}
|
|
151
|
+
} })),
|
|
152
|
+
React.createElement("button", { type: "button", className: `ta-button ta-custom-fetch${fetching ? ' ta-busy' : ''}`, disabled: !baseUrl.trim() || fetching, onClick: () => void fetchModels() },
|
|
153
|
+
React.createElement(BusyMark, { busy: fetching }),
|
|
154
|
+
React.createElement(Icon, { icon: Download, size: 14 }),
|
|
155
|
+
" ",
|
|
156
|
+
t('ta.auth.custom.fetch')),
|
|
157
|
+
fetchError && React.createElement(Callout, { level: "error" }, t('ta.auth.custom.fetchFailed', { message: fetchError })),
|
|
158
|
+
fetched && (React.createElement("div", { className: "ta-custom-fetched" },
|
|
159
|
+
React.createElement("span", { className: "ta-auth-note" }, fetched.length ? t('ta.auth.custom.fetched', { count: fetched.length }) : t('ta.auth.custom.fetchedNone')),
|
|
160
|
+
fetched.length > FILTER_FROM && (React.createElement("input", { className: "ta-input", placeholder: t('ta.auth.custom.filter'), value: words, onChange: event => setWords(event.target.value) })),
|
|
161
|
+
React.createElement("div", { className: "ta-custom-fetched-list" }, shown.map(id => {
|
|
162
|
+
const picked = models.includes(id);
|
|
163
|
+
return (React.createElement("button", { key: id, type: "button", className: "ta-auth-item", "aria-pressed": picked, onClick: () => setModels(before => CustomProviderFormUtil.toggle(before, id)) },
|
|
164
|
+
React.createElement("span", { className: "ta-auth-name" }, id),
|
|
165
|
+
picked && React.createElement(Icon, { icon: Check, size: 15, className: "ta-custom-picked" })));
|
|
166
|
+
}))))),
|
|
167
|
+
React.createElement(CustomProviderAdvanced, { provider: provider, state: advanced, onChange: setAdvanced }),
|
|
168
|
+
React.createElement("p", { className: "ta-store-form-note" },
|
|
169
|
+
React.createElement(Icon, { icon: ShieldCheck, size: 13 }),
|
|
170
|
+
React.createElement("span", null, t('ta.auth.custom.note'))),
|
|
171
|
+
React.createElement("div", { className: "ta-custom-actions" },
|
|
172
|
+
provider && (React.createElement("button", { type: "button", className: `ta-button ta-danger${removing ? ' ta-busy' : ''}`, disabled: removing || saving, onClick: () => void remove() },
|
|
173
|
+
React.createElement(BusyMark, { busy: removing }),
|
|
174
|
+
React.createElement(Icon, { icon: Trash2, size: 14 }),
|
|
175
|
+
" ",
|
|
176
|
+
t('ta.auth.custom.remove'))),
|
|
177
|
+
React.createElement("button", { type: "submit", className: `ta-button ta-primary${saving ? ' ta-busy' : ''}`, disabled: !baseUrl.trim() || saving || removing },
|
|
178
|
+
React.createElement(BusyMark, { busy: saving }),
|
|
179
|
+
React.createElement("span", null, t('ta.auth.custom.save')))))));
|
|
180
|
+
}
|
|
181
|
+
//# sourceMappingURL=custom-provider-view.js.map
|