@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.
Files changed (157) hide show
  1. package/README.en.md +1 -1
  2. package/README.md +1 -1
  3. package/esm/browser/assistant/assistant-initiative.js +1 -1
  4. package/esm/browser/components/access-view.js +3 -2
  5. package/esm/browser/components/account-menu.js +10 -3
  6. package/esm/browser/components/app-view.js +4 -1
  7. package/esm/browser/components/auth-view.d.ts +1 -1
  8. package/esm/browser/components/auth-view.js +38 -10
  9. package/esm/browser/components/custom-provider-advanced.d.ts +14 -0
  10. package/esm/browser/components/custom-provider-advanced.js +50 -0
  11. package/esm/browser/components/custom-provider-util.d.ts +38 -0
  12. package/esm/browser/components/custom-provider-util.js +103 -0
  13. package/esm/browser/components/custom-provider-view.d.ts +11 -0
  14. package/esm/browser/components/custom-provider-view.js +181 -0
  15. package/esm/browser/components/face.js +7 -2
  16. package/esm/browser/components/gallery.d.ts +9 -0
  17. package/esm/browser/components/gallery.js +57 -0
  18. package/esm/browser/components/host-view.d.ts +1 -1
  19. package/esm/browser/components/lightbox.d.ts +8 -1
  20. package/esm/browser/components/lightbox.js +4 -1
  21. package/esm/browser/components/markdown.js +6 -1
  22. package/esm/browser/components/media.d.ts +12 -2
  23. package/esm/browser/components/media.js +55 -13
  24. package/esm/browser/components/message-list.js +3 -2
  25. package/esm/browser/components/notice-center.js +6 -2
  26. package/esm/browser/components/serve-restart.d.ts +26 -0
  27. package/esm/browser/components/serve-restart.js +91 -0
  28. package/esm/browser/components/session-view.js +19 -11
  29. package/esm/browser/components/settings-choices.js +2 -3
  30. package/esm/browser/components/settings-controls.d.ts +7 -1
  31. package/esm/browser/components/settings-controls.js +8 -0
  32. package/esm/browser/components/settings-parts.js +25 -10
  33. package/esm/browser/components/sign-in-setup.js +3 -1
  34. package/esm/browser/editor/monaco-loader.js +7 -1
  35. package/esm/browser/extension/icons.js +3 -1
  36. package/esm/browser/extension/web-api-contributions.d.ts +3 -0
  37. package/esm/browser/extension/web-extension-api.d.ts +7 -0
  38. package/esm/browser/extension/web-extension-context.d.ts +2 -0
  39. package/esm/browser/extension/web-extension-context.js +19 -0
  40. package/esm/browser/game/game-loader.js +22 -2
  41. package/esm/browser/game/game3d-protocol.d.ts +13 -4
  42. package/esm/browser/i18n/locales.d.ts +68 -1
  43. package/esm/browser/i18n/locales.js +25 -1
  44. package/esm/browser/i18n/messages-ja.d.ts +2 -0
  45. package/esm/browser/i18n/messages-ja.js +984 -0
  46. package/esm/browser/i18n/messages-zh-tw.d.ts +3 -0
  47. package/esm/browser/i18n/messages-zh-tw.js +985 -0
  48. package/esm/browser/i18n/messages.d.ts +63 -0
  49. package/esm/browser/i18n/messages.js +126 -1
  50. package/esm/browser/i18n/use-t.js +3 -2
  51. package/esm/browser/settings/settings-protocol.d.ts +3 -2
  52. package/esm/browser/settings/settings-protocol.js +4 -3
  53. package/esm/browser/style/conversation.d.ts +1 -1
  54. package/esm/browser/style/conversation.js +18 -0
  55. package/esm/browser/style/layout.d.ts +1 -1
  56. package/esm/browser/style/layout.js +2 -0
  57. package/esm/browser/style/pages.d.ts +1 -1
  58. package/esm/browser/style/pages.js +45 -1
  59. package/esm/browser/style/shell.d.ts +1 -1
  60. package/esm/browser/style/shell.js +2 -0
  61. package/esm/browser/style/surfaces.d.ts +1 -1
  62. package/esm/browser/style/surfaces.js +1 -0
  63. package/esm/browser/util/desktop.d.ts +17 -1
  64. package/esm/browser/util/desktop.js +24 -0
  65. package/esm/browser/util/gallery.d.ts +18 -0
  66. package/esm/browser/util/gallery.js +123 -0
  67. package/esm/browser/util/link.d.ts +8 -0
  68. package/esm/browser/util/link.js +14 -0
  69. package/esm/browser/util/markdown.d.ts +11 -0
  70. package/esm/browser/util/markdown.js +4 -0
  71. package/esm/browser/util/thumbnail.d.ts +18 -0
  72. package/esm/browser/util/thumbnail.js +26 -0
  73. package/esm/browser/util/voice.d.ts +20 -1
  74. package/esm/browser/util/voice.js +27 -11
  75. package/esm/browser/workbench-protocol.d.ts +8 -0
  76. package/esm/browser/workbench-util.d.ts +2 -0
  77. package/esm/browser/workbench-util.js +6 -1
  78. package/esm/browser/workbench.d.ts +16 -0
  79. package/esm/browser/workbench.js +67 -0
  80. package/lib/browser/assistant/assistant-initiative.js +1 -1
  81. package/lib/browser/components/access-view.js +3 -2
  82. package/lib/browser/components/account-menu.js +9 -2
  83. package/lib/browser/components/app-view.js +4 -1
  84. package/lib/browser/components/auth-view.d.ts +1 -1
  85. package/lib/browser/components/auth-view.js +37 -9
  86. package/lib/browser/components/custom-provider-advanced.d.ts +15 -0
  87. package/lib/browser/components/custom-provider-advanced.js +86 -0
  88. package/lib/browser/components/custom-provider-util.d.ts +39 -0
  89. package/lib/browser/components/custom-provider-util.js +106 -0
  90. package/lib/browser/components/custom-provider-view.d.ts +12 -0
  91. package/lib/browser/components/custom-provider-view.js +217 -0
  92. package/lib/browser/components/face.js +7 -2
  93. package/lib/browser/components/gallery.d.ts +10 -0
  94. package/lib/browser/components/gallery.js +93 -0
  95. package/lib/browser/components/host-view.d.ts +1 -1
  96. package/lib/browser/components/lightbox.d.ts +8 -1
  97. package/lib/browser/components/lightbox.js +4 -1
  98. package/lib/browser/components/markdown.js +6 -1
  99. package/lib/browser/components/media.d.ts +12 -2
  100. package/lib/browser/components/media.js +57 -13
  101. package/lib/browser/components/message-list.js +3 -2
  102. package/lib/browser/components/notice-center.js +6 -2
  103. package/lib/browser/components/serve-restart.d.ts +27 -0
  104. package/lib/browser/components/serve-restart.js +129 -0
  105. package/lib/browser/components/session-view.js +21 -13
  106. package/lib/browser/components/settings-choices.js +1 -2
  107. package/lib/browser/components/settings-controls.d.ts +7 -1
  108. package/lib/browser/components/settings-controls.js +9 -0
  109. package/lib/browser/components/settings-parts.js +23 -8
  110. package/lib/browser/components/sign-in-setup.js +3 -1
  111. package/lib/browser/editor/monaco-loader.js +7 -1
  112. package/lib/browser/extension/icons.js +2 -0
  113. package/lib/browser/extension/web-api-contributions.d.ts +3 -0
  114. package/lib/browser/extension/web-extension-api.d.ts +7 -0
  115. package/lib/browser/extension/web-extension-context.d.ts +2 -0
  116. package/lib/browser/extension/web-extension-context.js +19 -0
  117. package/lib/browser/game/game-loader.js +22 -2
  118. package/lib/browser/game/game3d-protocol.d.ts +13 -4
  119. package/lib/browser/i18n/locales.d.ts +68 -1
  120. package/lib/browser/i18n/locales.js +25 -1
  121. package/lib/browser/i18n/messages-ja.d.ts +3 -0
  122. package/lib/browser/i18n/messages-ja.js +987 -0
  123. package/lib/browser/i18n/messages-zh-tw.d.ts +4 -0
  124. package/lib/browser/i18n/messages-zh-tw.js +988 -0
  125. package/lib/browser/i18n/messages.d.ts +63 -0
  126. package/lib/browser/i18n/messages.js +129 -2
  127. package/lib/browser/i18n/use-t.js +2 -1
  128. package/lib/browser/settings/settings-protocol.d.ts +3 -2
  129. package/lib/browser/settings/settings-protocol.js +4 -3
  130. package/lib/browser/style/conversation.d.ts +1 -1
  131. package/lib/browser/style/conversation.js +18 -0
  132. package/lib/browser/style/layout.d.ts +1 -1
  133. package/lib/browser/style/layout.js +2 -0
  134. package/lib/browser/style/pages.d.ts +1 -1
  135. package/lib/browser/style/pages.js +45 -1
  136. package/lib/browser/style/shell.d.ts +1 -1
  137. package/lib/browser/style/shell.js +2 -0
  138. package/lib/browser/style/surfaces.d.ts +1 -1
  139. package/lib/browser/style/surfaces.js +1 -0
  140. package/lib/browser/util/desktop.d.ts +17 -1
  141. package/lib/browser/util/desktop.js +24 -0
  142. package/lib/browser/util/gallery.d.ts +19 -0
  143. package/lib/browser/util/gallery.js +126 -0
  144. package/lib/browser/util/link.d.ts +8 -0
  145. package/lib/browser/util/link.js +14 -0
  146. package/lib/browser/util/markdown.d.ts +11 -0
  147. package/lib/browser/util/markdown.js +4 -0
  148. package/lib/browser/util/thumbnail.d.ts +19 -0
  149. package/lib/browser/util/thumbnail.js +29 -0
  150. package/lib/browser/util/voice.d.ts +20 -1
  151. package/lib/browser/util/voice.js +27 -11
  152. package/lib/browser/workbench-protocol.d.ts +8 -0
  153. package/lib/browser/workbench-util.d.ts +2 -0
  154. package/lib/browser/workbench-util.js +6 -1
  155. package/lib/browser/workbench.d.ts +16 -0
  156. package/lib/browser/workbench.js +67 -0
  157. 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`,不回到浏览器。没有可用的模型时(`CELL_TA_NOT_SIGNED_IN`),页面直接打开登录页,而不是显示 pi 关于 `/login` 的提示;桌面应用第一次启动时也一样。
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
- const here = !WorkbenchUtil.isApp() && workbench.host === WorkbenchUtil.serverOf({ token: '' }, location.host);
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,4 +1,5 @@
1
- import { Check, ChevronRight, Download, FolderOpen, Info, Keyboard, KeyRound, Languages, LogOut, Monitor, Palette, Puzzle, Settings2, Smartphone, Sparkles, } from 'lucide-react';
1
+ import { TaLanguageUtil } from '@celljs/ta-protocol';
2
+ import { Check, ChevronRight, Download, FolderOpen, Info, Keyboard, KeyRound, Languages, LogOut, Monitor, Palette, Puzzle, RotateCw, Settings2, Smartphone, Sparkles, } from 'lucide-react';
2
3
  import * as React from 'react';
3
4
  import { useDevice } from '../device/device.js';
4
5
  import { usePwa, useSettings, useWorkbench } from '../hooks.js';
@@ -11,6 +12,7 @@ import { useDismiss } from './dismiss.js';
11
12
  import { HostsDialog } from './host-view.js';
12
13
  import { Icon } from './icon.js';
13
14
  import { RelayDialog } from './relay-view.js';
15
+ import { ServeRestartUtil, useRestartTa } from './serve-restart.js';
14
16
  import { Keys } from './settings-controls.js';
15
17
  import { DinoFace } from './ta-avatar.js';
16
18
  import { WorkingDirectoryPicker } from './working-directory.js';
@@ -21,8 +23,7 @@ const THEMES = [
21
23
  ];
22
24
  const LANGUAGES = [
23
25
  ['system', 'ta.settings.language.system'],
24
- ['zh-CN', '简体中文'],
25
- ['en-US', 'English'],
26
+ ...TaLanguageUtil.ALL.map(language => [language, TaLanguageUtil.NAMES[language]]),
26
27
  ];
27
28
  /**
28
29
  * The entries of the account and of the settings, in groups: the settings, the packages and the keys; the model
@@ -36,6 +37,7 @@ export function useAccountEntries(onSettings, onDialog) {
36
37
  const [{ installable, standalone }, pwa] = usePwa();
37
38
  // A finger has no keys to learn; a phone is not the computer that pairs phones.
38
39
  const { touch, handheld } = useDevice();
40
+ const restartTa = useRestartTa();
39
41
  const entry = (key, label, icon, run, more = {}) => ({
40
42
  key,
41
43
  label,
@@ -76,6 +78,11 @@ export function useAccountEntries(onSettings, onDialog) {
76
78
  ],
77
79
  [
78
80
  ...(installable && !standalone ? [entry('install', t('ta.pwa.install'), Download, () => void pwa.install())] : []),
81
+ ...(restartTa.can
82
+ ? [
83
+ entry('restart', restartTa.update ? t('ta.update.restartTo', { version: ServeRestartUtil.label(restartTa.update) }) : t('ta.restart'), RotateCw, () => void restartTa.restart()),
84
+ ]
85
+ : []),
79
86
  entry('about', t('ta.manage.about'), Info, () => onSettings('about')),
80
87
  entry('signOut', t('ta.settings.signOut'), LogOut, () => workbench.signOut(), { danger: true }),
81
88
  ],
@@ -14,6 +14,7 @@ import { useT } from '../i18n/use-t.js';
14
14
  import { CodeRenderers } from '../markdown/code-renderers.js';
15
15
  import { SIGN_IN_EVENT } from '../notices/notices.js';
16
16
  import { TaState } from '../state/state-protocol.js';
17
+ import { ThumbnailUtil } from '../util/thumbnail.js';
17
18
  import { Voice } from '../util/voice.js';
18
19
  import { WorkbenchUtil } from '../workbench-util.js';
19
20
  import { PageView, Rail, SidebarView, useNavigation } from './app-nav.js';
@@ -45,6 +46,7 @@ import { NoticeCenter } from './notice-center.js';
45
46
  import { PhoneShell } from './phone-shell.js';
46
47
  import { RemotePrompts } from './remote-prompts.js';
47
48
  import { ScanHost } from './scan-screen.js';
49
+ import { ServeRestartNotices } from './serve-restart.js';
48
50
  import { SettingsView } from './settings-view.js';
49
51
  import { ShareHost } from './share-dialog.js';
50
52
  import { DOUBLE_PAGE, SideListUtil } from './side-lists.js';
@@ -118,7 +120,7 @@ function AppShell() {
118
120
  const online = workbench.status === 'online';
119
121
  // Files named in replies outside a conversation (channels, pages) are in the server's directory.
120
122
  const files = useInject(TaFiles);
121
- const fileUrl = React.useCallback(async (path) => files.loadable(await bench.workspace.fileUrl(path)), [bench, files]);
123
+ const fileUrl = React.useCallback(async (path, box) => files.loadable(ThumbnailUtil.boxed(await bench.workspace.fileUrl(path), box)), [bench, files]);
122
124
  const openLink = useOpenLink(undefined);
123
125
  useDocument();
124
126
  useRefresh(online);
@@ -428,6 +430,7 @@ function AppShell() {
428
430
  React.createElement(NoticeCenter, null),
429
431
  React.createElement(LinkDialog, null),
430
432
  React.createElement(RemotePrompts, null),
433
+ React.createElement(ServeRestartNotices, null),
431
434
  React.createElement(SwitchingVeil, null),
432
435
  codeScan && React.createElement(ScanHost, { onCode: text => void codeScan.open(text), onAsk: askDouble }),
433
436
  React.createElement(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 first (subscriptions before the rest), then keys; by name. */
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 first (subscriptions before the rest), then keys; by name. */
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.type === 'api_key' ? t('ta.auth.apiKey') : provider.subscription ? t('ta.auth.subscription') : t('ta.auth.account');
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
- list.map(provider => (React.createElement(ProviderRow, { key: AuthUtil.key(provider), provider: provider, plain: kind !== undefined, onPick: () => setPicked(provider), onSignOut: () => void signOut(provider) })))));
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;