@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.
Files changed (89) 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 +2 -2
  6. package/esm/browser/components/auth-view.d.ts +1 -1
  7. package/esm/browser/components/auth-view.js +38 -10
  8. package/esm/browser/components/custom-provider-advanced.d.ts +14 -0
  9. package/esm/browser/components/custom-provider-advanced.js +50 -0
  10. package/esm/browser/components/custom-provider-util.d.ts +38 -0
  11. package/esm/browser/components/custom-provider-util.js +103 -0
  12. package/esm/browser/components/custom-provider-view.d.ts +11 -0
  13. package/esm/browser/components/custom-provider-view.js +181 -0
  14. package/esm/browser/components/host-view.d.ts +1 -1
  15. package/esm/browser/components/settings-choices.js +2 -3
  16. package/esm/browser/components/settings-controls.d.ts +7 -1
  17. package/esm/browser/components/settings-controls.js +8 -0
  18. package/esm/browser/components/settings-parts.js +11 -5
  19. package/esm/browser/components/sign-in-setup.js +3 -1
  20. package/esm/browser/editor/monaco-loader.js +7 -1
  21. package/esm/browser/extension/web-api-contributions.d.ts +3 -0
  22. package/esm/browser/extension/web-extension-api.d.ts +7 -0
  23. package/esm/browser/extension/web-extension-context.d.ts +2 -0
  24. package/esm/browser/extension/web-extension-context.js +19 -0
  25. package/esm/browser/game/game-loader.js +22 -2
  26. package/esm/browser/game/game3d-protocol.d.ts +13 -4
  27. package/esm/browser/i18n/locales.d.ts +56 -1
  28. package/esm/browser/i18n/locales.js +25 -1
  29. package/esm/browser/i18n/messages-ja.d.ts +2 -0
  30. package/esm/browser/i18n/messages-ja.js +972 -0
  31. package/esm/browser/i18n/messages-zh-tw.d.ts +3 -0
  32. package/esm/browser/i18n/messages-zh-tw.js +973 -0
  33. package/esm/browser/i18n/messages.d.ts +51 -0
  34. package/esm/browser/i18n/messages.js +102 -1
  35. package/esm/browser/i18n/use-t.js +3 -2
  36. package/esm/browser/settings/settings-protocol.d.ts +3 -2
  37. package/esm/browser/settings/settings-protocol.js +4 -3
  38. package/esm/browser/style/pages.d.ts +1 -1
  39. package/esm/browser/style/pages.js +45 -1
  40. package/esm/browser/util/desktop.d.ts +12 -1
  41. package/esm/browser/util/desktop.js +14 -0
  42. package/esm/browser/util/voice.d.ts +20 -1
  43. package/esm/browser/util/voice.js +27 -11
  44. package/esm/browser/workbench-util.d.ts +2 -0
  45. package/esm/browser/workbench-util.js +6 -1
  46. package/lib/browser/assistant/assistant-initiative.js +1 -1
  47. package/lib/browser/components/access-view.js +3 -2
  48. package/lib/browser/components/account-menu.js +2 -2
  49. package/lib/browser/components/auth-view.d.ts +1 -1
  50. package/lib/browser/components/auth-view.js +37 -9
  51. package/lib/browser/components/custom-provider-advanced.d.ts +15 -0
  52. package/lib/browser/components/custom-provider-advanced.js +86 -0
  53. package/lib/browser/components/custom-provider-util.d.ts +39 -0
  54. package/lib/browser/components/custom-provider-util.js +106 -0
  55. package/lib/browser/components/custom-provider-view.d.ts +12 -0
  56. package/lib/browser/components/custom-provider-view.js +217 -0
  57. package/lib/browser/components/host-view.d.ts +1 -1
  58. package/lib/browser/components/settings-choices.js +1 -2
  59. package/lib/browser/components/settings-controls.d.ts +7 -1
  60. package/lib/browser/components/settings-controls.js +9 -0
  61. package/lib/browser/components/settings-parts.js +10 -4
  62. package/lib/browser/components/sign-in-setup.js +3 -1
  63. package/lib/browser/editor/monaco-loader.js +7 -1
  64. package/lib/browser/extension/web-api-contributions.d.ts +3 -0
  65. package/lib/browser/extension/web-extension-api.d.ts +7 -0
  66. package/lib/browser/extension/web-extension-context.d.ts +2 -0
  67. package/lib/browser/extension/web-extension-context.js +19 -0
  68. package/lib/browser/game/game-loader.js +22 -2
  69. package/lib/browser/game/game3d-protocol.d.ts +13 -4
  70. package/lib/browser/i18n/locales.d.ts +56 -1
  71. package/lib/browser/i18n/locales.js +25 -1
  72. package/lib/browser/i18n/messages-ja.d.ts +3 -0
  73. package/lib/browser/i18n/messages-ja.js +975 -0
  74. package/lib/browser/i18n/messages-zh-tw.d.ts +4 -0
  75. package/lib/browser/i18n/messages-zh-tw.js +976 -0
  76. package/lib/browser/i18n/messages.d.ts +51 -0
  77. package/lib/browser/i18n/messages.js +105 -2
  78. package/lib/browser/i18n/use-t.js +2 -1
  79. package/lib/browser/settings/settings-protocol.d.ts +3 -2
  80. package/lib/browser/settings/settings-protocol.js +4 -3
  81. package/lib/browser/style/pages.d.ts +1 -1
  82. package/lib/browser/style/pages.js +45 -1
  83. package/lib/browser/util/desktop.d.ts +12 -1
  84. package/lib/browser/util/desktop.js +14 -0
  85. package/lib/browser/util/voice.d.ts +20 -1
  86. package/lib/browser/util/voice.js +27 -11
  87. package/lib/browser/workbench-util.d.ts +2 -0
  88. package/lib/browser/workbench-util.js +6 -1
  89. package/package.json +7 -7
@@ -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
- /** The recognizer of the Ta app on iOS, Apple's own: WebKit's repeats what it heard and leaves out punctuation. */
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
- return (_b = (_a = globalThis.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b.taSpeech;
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 onEvent = (event) => {
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
- globalThis.removeEventListener(Voice.NATIVE_EVENT, onEvent);
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
- globalThis.addEventListener(Voice.NATIVE_EVENT, onEvent);
172
- native.postMessage({ id, action: 'start', language, continuous: options.continuous === true, hints: hints(options.hints) });
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
- return /[\u4e00-\u9fff]/.test(text) ? 'zh-CN' : language;
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. */
@@ -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 ')) || !['localhost', '127.0.0.1', '[::1]', '::1'].includes(hostname);
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;
@@ -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
- const here = !workbench_util_1.WorkbenchUtil.isApp() && workbench.host === workbench_util_1.WorkbenchUtil.serverOf({ token: '' }, location.host);
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");
@@ -61,8 +62,7 @@ const THEMES = [
61
62
  ];
62
63
  const LANGUAGES = [
63
64
  ['system', 'ta.settings.language.system'],
64
- ['zh-CN', '简体中文'],
65
- ['en-US', 'English'],
65
+ ...ta_protocol_1.TaLanguageUtil.ALL.map(language => [language, ta_protocol_1.TaLanguageUtil.NAMES[language]]),
66
66
  ];
67
67
  /**
68
68
  * 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 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[];
@@ -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 first (subscriptions before the rest), then keys; by name. */
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.type === 'api_key' ? t('ta.auth.apiKey') : provider.subscription ? t('ta.auth.subscription') : t('ta.auth.account');
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
- list.map(provider => (React.createElement(ProviderRow, { key: AuthUtil.key(provider), provider: provider, plain: kind !== undefined, onPick: () => setPicked(provider), onSignOut: () => void signOut(provider) })))));
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
@@ -0,0 +1,39 @@
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
+ }
39
+ //# sourceMappingURL=custom-provider-util.d.ts.map
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CustomProviderFormUtil = void 0;
4
+ /** What the form of a model service added by its address (custom-provider-view) does with what is typed. */
5
+ var CustomProviderFormUtil;
6
+ (function (CustomProviderFormUtil) {
7
+ /** The ids typed or pasted at once: apart by commas, spaces or lines. */
8
+ function split(text) {
9
+ return text
10
+ .split(/[\s,,]+/)
11
+ .map(id => id.trim())
12
+ .filter(Boolean);
13
+ }
14
+ CustomProviderFormUtil.split = split;
15
+ /** The models with those added, each once, in the order they came. */
16
+ function add(models, ids) {
17
+ return [...new Set([...models, ...ids])];
18
+ }
19
+ CustomProviderFormUtil.add = add;
20
+ function toggle(models, id) {
21
+ return models.includes(id) ? models.filter(model => model !== id) : [...models, id];
22
+ }
23
+ CustomProviderFormUtil.toggle = toggle;
24
+ /** The name a provider gets when none is typed: the host of its address, as ta serve gives it. */
25
+ function host(baseUrl) {
26
+ try {
27
+ return new URL(baseUrl.trim()).host;
28
+ }
29
+ catch (_a) {
30
+ return '';
31
+ }
32
+ }
33
+ CustomProviderFormUtil.host = host;
34
+ function advanced(provider) {
35
+ var _a, _b;
36
+ const options = (_a = provider === null || provider === void 0 ? void 0 : provider.options) !== null && _a !== void 0 ? _a : {};
37
+ return {
38
+ contextWindow: options.contextWindow ? String(options.contextWindow) : '',
39
+ maxTokens: options.maxTokens ? String(options.maxTokens) : '',
40
+ reasoning: options.reasoning === true,
41
+ images: options.images === true,
42
+ headers: ((_b = provider === null || provider === void 0 ? void 0 : provider.headers) !== null && _b !== void 0 ? _b : []).map(name => ({ name, value: '', kept: true })),
43
+ touched: [],
44
+ };
45
+ }
46
+ CustomProviderFormUtil.advanced = advanced;
47
+ /** Whether the provider has anything advanced: the section opens with it. */
48
+ function hasAdvanced(provider) {
49
+ return !!provider && (Object.keys(provider.options).length > 0 || provider.mixed.length > 0 || provider.headers.length > 0);
50
+ }
51
+ CustomProviderFormUtil.hasAdvanced = hasAdvanced;
52
+ /** A number of tokens as typed: `200000`, `200k`, `1m`, `200,000`; null when empty, undefined when not one. */
53
+ function tokens(text) {
54
+ const plain = text
55
+ .trim()
56
+ .toLowerCase()
57
+ .replace(/[,_\s]/g, '');
58
+ if (!plain) {
59
+ return null;
60
+ }
61
+ const match = /^(\d+(?:\.\d+)?)([km]?)$/.exec(plain);
62
+ const value = match ? Math.round(Number(match[1]) * (match[2] === 'k' ? 1000 : match[2] === 'm' ? 1000000 : 1)) : Number.NaN;
63
+ return Number.isInteger(value) && value > 0 ? value : undefined;
64
+ }
65
+ CustomProviderFormUtil.tokens = tokens;
66
+ /** 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. */
67
+ function optionsOf(state, mixed) {
68
+ const options = {};
69
+ const given = (key) => !mixed.includes(key) || state.touched.includes(key);
70
+ for (const key of ['contextWindow', 'maxTokens']) {
71
+ if (given(key)) {
72
+ const value = tokens(state[key]);
73
+ if (value === undefined) {
74
+ throw new RangeError(state[key]);
75
+ }
76
+ options[key] = value;
77
+ }
78
+ }
79
+ for (const key of ['reasoning', 'images']) {
80
+ if (given(key)) {
81
+ options[key] = state[key];
82
+ }
83
+ }
84
+ return options;
85
+ }
86
+ CustomProviderFormUtil.optionsOf = optionsOf;
87
+ /** The headers to send and save, by name; an empty value keeps the one kept. */
88
+ function headersOf(state) {
89
+ const headers = {};
90
+ for (const row of state.headers) {
91
+ const name = row.name.trim();
92
+ if (name) {
93
+ headers[name] = row.value.trim();
94
+ }
95
+ }
96
+ return headers;
97
+ }
98
+ CustomProviderFormUtil.headersOf = headersOf;
99
+ /** What a service listed, narrowed by the words typed. */
100
+ function shown(fetched, words) {
101
+ const query = words.trim().toLowerCase();
102
+ return query ? fetched.filter(id => id.toLowerCase().includes(query)) : [...fetched];
103
+ }
104
+ CustomProviderFormUtil.shown = shown;
105
+ })(CustomProviderFormUtil || (exports.CustomProviderFormUtil = CustomProviderFormUtil = {}));
106
+ //# sourceMappingURL=custom-provider-util.js.map
@@ -0,0 +1,12 @@
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;
12
+ //# sourceMappingURL=custom-provider-view.d.ts.map