@celljs/ta-web 4.13.1 → 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 (149) hide show
  1. package/README.en.md +3 -3
  2. package/README.md +3 -3
  3. package/esm/browser/assistant/assistant-extension.js +3 -2
  4. package/esm/browser/assistant/assistant-initiative.js +1 -1
  5. package/esm/browser/assistant/assistant-state.js +2 -2
  6. package/esm/browser/components/access-view.js +3 -2
  7. package/esm/browser/components/account-menu.js +2 -2
  8. package/esm/browser/components/app-view.js +4 -0
  9. package/esm/browser/components/auth-view.d.ts +1 -1
  10. package/esm/browser/components/auth-view.js +38 -10
  11. package/esm/browser/components/chat-asks.d.ts +8 -0
  12. package/esm/browser/components/chat-asks.js +10 -0
  13. package/esm/browser/components/chat-list.js +11 -1
  14. package/esm/browser/components/composer-box.d.ts +2 -0
  15. package/esm/browser/components/composer-box.js +2 -1
  16. package/esm/browser/components/composer.d.ts +3 -1
  17. package/esm/browser/components/composer.js +16 -4
  18. package/esm/browser/components/custom-provider-advanced.d.ts +14 -0
  19. package/esm/browser/components/custom-provider-advanced.js +50 -0
  20. package/esm/browser/components/custom-provider-util.d.ts +38 -0
  21. package/esm/browser/components/custom-provider-util.js +103 -0
  22. package/esm/browser/components/custom-provider-view.d.ts +11 -0
  23. package/esm/browser/components/custom-provider-view.js +181 -0
  24. package/esm/browser/components/face.d.ts +13 -1
  25. package/esm/browser/components/face.js +16 -1
  26. package/esm/browser/components/host-view.d.ts +1 -1
  27. package/esm/browser/components/message-list.js +20 -1
  28. package/esm/browser/components/people.d.ts +32 -0
  29. package/esm/browser/components/people.js +71 -0
  30. package/esm/browser/components/session-view.d.ts +1 -1
  31. package/esm/browser/components/session-view.js +56 -36
  32. package/esm/browser/components/settings-choices.js +2 -3
  33. package/esm/browser/components/settings-controls.d.ts +7 -1
  34. package/esm/browser/components/settings-controls.js +8 -0
  35. package/esm/browser/components/settings-parts.js +25 -8
  36. package/esm/browser/components/sign-in-setup.d.ts +16 -0
  37. package/esm/browser/components/sign-in-setup.js +118 -0
  38. package/esm/browser/components/use-seen-chats.d.ts +2 -0
  39. package/esm/browser/components/use-seen-chats.js +2 -2
  40. package/esm/browser/editor/monaco-loader.js +7 -1
  41. package/esm/browser/extension/web-api-components.d.ts +12 -0
  42. package/esm/browser/extension/web-api-contributions.d.ts +3 -0
  43. package/esm/browser/extension/web-extension-api.d.ts +9 -2
  44. package/esm/browser/extension/web-extension-context.d.ts +2 -0
  45. package/esm/browser/extension/web-extension-context.js +19 -0
  46. package/esm/browser/game/game-loader.js +22 -2
  47. package/esm/browser/game/game3d-protocol.d.ts +13 -4
  48. package/esm/browser/i18n/locales.d.ts +90 -1
  49. package/esm/browser/i18n/locales.js +25 -1
  50. package/esm/browser/i18n/messages-ja.d.ts +2 -0
  51. package/esm/browser/i18n/messages-ja.js +972 -0
  52. package/esm/browser/i18n/messages-zh-tw.d.ts +3 -0
  53. package/esm/browser/i18n/messages-zh-tw.js +973 -0
  54. package/esm/browser/i18n/messages.d.ts +85 -0
  55. package/esm/browser/i18n/messages.js +171 -1
  56. package/esm/browser/i18n/use-t.js +3 -2
  57. package/esm/browser/presence/presence-reporter.d.ts +32 -0
  58. package/esm/browser/presence/presence-reporter.js +71 -0
  59. package/esm/browser/settings/settings-protocol.d.ts +3 -2
  60. package/esm/browser/settings/settings-protocol.js +4 -3
  61. package/esm/browser/style/conversation.d.ts +1 -1
  62. package/esm/browser/style/conversation.js +24 -0
  63. package/esm/browser/style/layout.d.ts +1 -1
  64. package/esm/browser/style/layout.js +8 -0
  65. package/esm/browser/style/pages.d.ts +1 -1
  66. package/esm/browser/style/pages.js +53 -1
  67. package/esm/browser/util/desktop.d.ts +12 -1
  68. package/esm/browser/util/desktop.js +14 -0
  69. package/esm/browser/util/voice.d.ts +20 -1
  70. package/esm/browser/util/voice.js +27 -11
  71. package/esm/browser/workbench-protocol.d.ts +9 -0
  72. package/esm/browser/workbench-util.d.ts +4 -0
  73. package/esm/browser/workbench-util.js +24 -1
  74. package/esm/browser/workbench.d.ts +3 -0
  75. package/esm/browser/workbench.js +14 -4
  76. package/lib/browser/assistant/assistant-extension.js +3 -2
  77. package/lib/browser/assistant/assistant-initiative.js +1 -1
  78. package/lib/browser/assistant/assistant-state.js +1 -1
  79. package/lib/browser/components/access-view.js +3 -2
  80. package/lib/browser/components/account-menu.js +2 -2
  81. package/lib/browser/components/app-view.js +4 -0
  82. package/lib/browser/components/auth-view.d.ts +1 -1
  83. package/lib/browser/components/auth-view.js +37 -9
  84. package/lib/browser/components/chat-asks.d.ts +8 -0
  85. package/lib/browser/components/chat-asks.js +10 -0
  86. package/lib/browser/components/chat-list.js +11 -1
  87. package/lib/browser/components/composer-box.d.ts +2 -0
  88. package/lib/browser/components/composer-box.js +2 -1
  89. package/lib/browser/components/composer.d.ts +3 -1
  90. package/lib/browser/components/composer.js +16 -4
  91. package/lib/browser/components/custom-provider-advanced.d.ts +15 -0
  92. package/lib/browser/components/custom-provider-advanced.js +86 -0
  93. package/lib/browser/components/custom-provider-util.d.ts +39 -0
  94. package/lib/browser/components/custom-provider-util.js +106 -0
  95. package/lib/browser/components/custom-provider-view.d.ts +12 -0
  96. package/lib/browser/components/custom-provider-view.js +217 -0
  97. package/lib/browser/components/face.d.ts +13 -1
  98. package/lib/browser/components/face.js +16 -1
  99. package/lib/browser/components/host-view.d.ts +1 -1
  100. package/lib/browser/components/message-list.js +19 -0
  101. package/lib/browser/components/people.d.ts +33 -0
  102. package/lib/browser/components/people.js +109 -0
  103. package/lib/browser/components/session-view.d.ts +1 -1
  104. package/lib/browser/components/session-view.js +56 -36
  105. package/lib/browser/components/settings-choices.js +1 -2
  106. package/lib/browser/components/settings-controls.d.ts +7 -1
  107. package/lib/browser/components/settings-controls.js +9 -0
  108. package/lib/browser/components/settings-parts.js +24 -7
  109. package/lib/browser/components/sign-in-setup.d.ts +17 -0
  110. package/lib/browser/components/sign-in-setup.js +155 -0
  111. package/lib/browser/components/use-seen-chats.d.ts +2 -0
  112. package/lib/browser/components/use-seen-chats.js +3 -2
  113. package/lib/browser/editor/monaco-loader.js +7 -1
  114. package/lib/browser/extension/web-api-components.d.ts +12 -0
  115. package/lib/browser/extension/web-api-contributions.d.ts +3 -0
  116. package/lib/browser/extension/web-extension-api.d.ts +9 -2
  117. package/lib/browser/extension/web-extension-context.d.ts +2 -0
  118. package/lib/browser/extension/web-extension-context.js +19 -0
  119. package/lib/browser/game/game-loader.js +22 -2
  120. package/lib/browser/game/game3d-protocol.d.ts +13 -4
  121. package/lib/browser/i18n/locales.d.ts +90 -1
  122. package/lib/browser/i18n/locales.js +25 -1
  123. package/lib/browser/i18n/messages-ja.d.ts +3 -0
  124. package/lib/browser/i18n/messages-ja.js +975 -0
  125. package/lib/browser/i18n/messages-zh-tw.d.ts +4 -0
  126. package/lib/browser/i18n/messages-zh-tw.js +976 -0
  127. package/lib/browser/i18n/messages.d.ts +85 -0
  128. package/lib/browser/i18n/messages.js +174 -2
  129. package/lib/browser/i18n/use-t.js +2 -1
  130. package/lib/browser/presence/presence-reporter.d.ts +33 -0
  131. package/lib/browser/presence/presence-reporter.js +75 -0
  132. package/lib/browser/settings/settings-protocol.d.ts +3 -2
  133. package/lib/browser/settings/settings-protocol.js +4 -3
  134. package/lib/browser/style/conversation.d.ts +1 -1
  135. package/lib/browser/style/conversation.js +24 -0
  136. package/lib/browser/style/layout.d.ts +1 -1
  137. package/lib/browser/style/layout.js +8 -0
  138. package/lib/browser/style/pages.d.ts +1 -1
  139. package/lib/browser/style/pages.js +53 -1
  140. package/lib/browser/util/desktop.d.ts +12 -1
  141. package/lib/browser/util/desktop.js +14 -0
  142. package/lib/browser/util/voice.d.ts +20 -1
  143. package/lib/browser/util/voice.js +27 -11
  144. package/lib/browser/workbench-protocol.d.ts +9 -0
  145. package/lib/browser/workbench-util.d.ts +4 -0
  146. package/lib/browser/workbench-util.js +24 -1
  147. package/lib/browser/workbench.d.ts +3 -0
  148. package/lib/browser/workbench.js +14 -4
  149. package/package.json +10 -10
@@ -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
@@ -86,6 +86,7 @@ const share_dialog_1 = require("./share-dialog");
86
86
  const side_lists_1 = require("./side-lists");
87
87
  const split_pane_1 = require("./split-pane");
88
88
  const surface_flyout_1 = require("./surface-flyout");
89
+ const use_seen_chats_1 = require("./use-seen-chats");
89
90
  const workbench_toggle_1 = require("./workbench-toggle");
90
91
  const workbench_view_1 = require("./workbench-view");
91
92
  /**
@@ -303,6 +304,9 @@ function AppShell() {
303
304
  React.useEffect(() => host.setConversationShown(conversationShown), [host, conversationShown]);
304
305
  // What the user has seen is kept here, whichever list or tab is out: one read from the agents' list is seen too.
305
306
  const { seen: seenChats, looking } = (0, assistant_chat_list_1.useSeenConversations)(workbench.sessions, conversationShown ? store === null || store === void 0 ? void 0 : store.sessionId : undefined, (view === null || view === void 0 ? void 0 : view.id) === side_lists_1.DOUBLE_PAGE && settings === undefined && (!phone || screenOpen || view === tabView));
307
+ // The others in the same Ta see who looks at a conversation with them (TaSessionInfo.people), while the page is seen.
308
+ const pageVisible = (0, use_seen_chats_1.usePageVisible)();
309
+ React.useEffect(() => bench.presence.look(pageVisible ? looking : undefined), [bench, pageVisible, looking]);
306
310
  const state = (0, react_1.useInject)(state_protocol_1.TaState);
307
311
  const { pageShown } = extensions;
308
312
  // biome-ignore lint/correctness/useExhaustiveDependencies: follows the pages shown
@@ -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 }) {
@@ -29,6 +29,14 @@ export declare namespace ChatAskUtil {
29
29
  function letGo(before: LetGoAsks, file: string, at: number): LetGoAsks;
30
30
  /** What it still asks the user: none once answered or let go. */
31
31
  function asking(entry: AskingEntry, letGo: LetGoAsks): TaAsking | undefined;
32
+ /**
33
+ * What the lists know of the conversation of a session: as the server tells it while open, by its id or its file;
34
+ * from its file once closed (closed while idle, what it asked stays there, as the saved ones of the chats show).
35
+ */
36
+ function entryOf(sessions: readonly TaSessionInfo[], saved: readonly TaSavedSessionInfo[], session: {
37
+ sessionId: string;
38
+ sessionFile?: string;
39
+ }): AskingEntry | undefined;
32
40
  /** Whether it waits for the user: it asks, or a dialog of it waits. */
33
41
  function waits(entry: AskingEntry, letGo: LetGoAsks): boolean;
34
42
  /** How many of the conversations the list shows wait for the user: the count on the tab of the chats. */
@@ -56,6 +56,16 @@ var ChatAskUtil;
56
56
  return asking && asking.at > ((_a = letGo[fileOf(entry)]) !== null && _a !== void 0 ? _a : -1) ? asking : undefined;
57
57
  }
58
58
  ChatAskUtil.asking = asking;
59
+ /**
60
+ * What the lists know of the conversation of a session: as the server tells it while open, by its id or its file;
61
+ * from its file once closed (closed while idle, what it asked stays there, as the saved ones of the chats show).
62
+ */
63
+ function entryOf(sessions, saved, session) {
64
+ const { sessionId, sessionFile } = session;
65
+ const open = sessions.find(each => each.sessionId === sessionId || (!!sessionFile && each.sessionFile === sessionFile));
66
+ return open !== null && open !== void 0 ? open : (sessionFile ? saved.find(each => each.sessionFile === sessionFile) : undefined);
67
+ }
68
+ ChatAskUtil.entryOf = entryOf;
59
69
  /** Whether it waits for the user: it asks, or a dialog of it waits. */
60
70
  function waits(entry, letGo) {
61
71
  return !!entry.waiting || !!asking(entry, letGo);
@@ -53,6 +53,7 @@ const context_menu_1 = require("./context-menu");
53
53
  const empty_state_1 = require("./empty-state");
54
54
  const host_tag_1 = require("./host-tag");
55
55
  const icon_1 = require("./icon");
56
+ const people_1 = require("./people");
56
57
  const swipe_row_1 = require("./swipe-row");
57
58
  const ta_avatar_1 = require("./ta-avatar");
58
59
  /** The list by directory or package, else by day; in any browser. */
@@ -300,7 +301,8 @@ var ChatListUtil;
300
301
  a.cwd === b.cwd &&
301
302
  a.group === b.group &&
302
303
  (isOpen(a) && a.isStreaming) === (isOpen(b) && b.isStreaming) &&
303
- (isOpen(a) && !!a.waiting) === (isOpen(b) && !!b.waiting));
304
+ (isOpen(a) && !!a.waiting) === (isOpen(b) && !!b.waiting) &&
305
+ people_1.PresenceUtil.same(isOpen(a) ? a.people : undefined, isOpen(b) ? b.people : undefined));
304
306
  const x = before.source;
305
307
  const y = after.source;
306
308
  const sameSource = x === y || (x.key === y.key && x.label === y.label && x.title === y.title && x.host === y.host && x.initial === y.initial && x.tone === y.tone);
@@ -431,6 +433,11 @@ const ChatItem = React.memo(function ChatItem({ session, source, selected, time,
431
433
  const asks = waiting || (!!asking && !streaming);
432
434
  const mood = asks ? 'attention' : streaming ? 'working' : 'idle';
433
435
  const state = React.createElement(ChatState, { streaming: streaming, waiting: waiting, task: task });
436
+ // Others in the same Ta: their faces while they look at it, and whose message it answers.
437
+ const people = ChatListUtil.isOpen(session) ? session.people : undefined;
438
+ const viewers = React.createElement(people_1.PeopleFaces, { people: people_1.PresenceUtil.viewing(people), size: 14, max: 3 });
439
+ const askers = streaming ? people_1.PresenceUtil.asked(people) : [];
440
+ const replying = askers.length > 0 && (React.createElement("span", { className: "ta-chat-flag ta-replying" }, t('ta.chat.replyingFor', { names: people_1.PresenceUtil.names(askers, t('ta.presence.separator'), count => t('ta.presence.more', { count })) })));
434
441
  // As in a messaging app, the last thing said; its directory before the first, and on hover in place of its time.
435
442
  const said = ChatListUtil.preview(session, title);
436
443
  const place = who ? message_1.MessageUtil.basename(session.cwd) : source.label;
@@ -441,6 +448,7 @@ const ChatItem = React.memo(function ChatItem({ session, source, selected, time,
441
448
  who && React.createElement(ChatAvatar, { session: session, source: source, who: who, size: 20, mood: mood }),
442
449
  tag,
443
450
  React.createElement("span", { className: "ta-chat-title" }, title),
451
+ viewers,
444
452
  state,
445
453
  React.createElement(ChatDot, { unseen: !!unseen, asks: asks }),
446
454
  React.createElement("span", { className: "ta-chat-time" }, removing && handheld ? React.createElement("span", { className: "ta-spinner ta-later" }) : time)))) : (React.createElement(React.Fragment, null,
@@ -466,12 +474,14 @@ const ChatItem = React.memo(function ChatItem({ session, source, selected, time,
466
474
  "[",
467
475
  t('ta.chat.asking'),
468
476
  "]"),
477
+ replying,
469
478
  ended && !streaming && !asks && (React.createElement("span", { className: `ta-chat-flag ta-${ended}` },
470
479
  "[",
471
480
  t(ended === 'failed' ? 'ta.task.failed' : 'ta.task.stopped'),
472
481
  "]")), (_a = (asks && !waiting ? asking : said)) !== null && _a !== void 0 ? _a : (React.createElement("span", { className: "ta-chat-dir" },
473
482
  React.createElement(icon_1.Icon, { icon: lucide_react_1.Folder, size: 12 }),
474
483
  place))),
484
+ viewers,
475
485
  streaming && React.createElement("span", { className: "ta-chat-state ta-spinner" })))))),
476
486
  handheld ? null : onRestore ? (React.createElement(icon_1.IconButton, { className: "ta-chat-delete", icon: lucide_react_1.Undo2, label: t('ta.chat.restore'), onClick: onRestore })) : (React.createElement(icon_1.IconButton, { className: "ta-chat-delete", icon: lucide_react_1.Trash2, label: t('ta.sidebar.closeTitle'), busy: removing, onClick: onRemove }))));
477
487
  }, ChatListUtil.sameRow);
@@ -80,6 +80,8 @@ export interface ComposerBoxProps {
80
80
  onTalkSent?(): void;
81
81
  onListening?(listening: boolean): void;
82
82
  autoFocus?: boolean;
83
+ /** What the user typed changed: the text now. */
84
+ onTextChange?(text: string): void;
83
85
  /** The directory of the conversation: files dragged in from it become `@` references relative to it. */
84
86
  cwd?: string;
85
87
  onError(error: unknown): void;
@@ -87,7 +87,7 @@ function talkTarget(target) {
87
87
  }
88
88
  exports.ComposerBox = React.forwardRef(function ComposerBox(props, ref) {
89
89
  var _a;
90
- const { placeholder, working = false, onStop, onSend, commands = [], onMentionQuery, mentions, mentionLabel, images: takesImages, recentShots, actions = [], above, head, after, voiceSends, talkPlace, onTalkSent, onListening, autoFocus, cwd, onError, } = props;
90
+ const { placeholder, working = false, onStop, onSend, commands = [], onMentionQuery, mentions, mentionLabel, images: takesImages, recentShots, actions = [], above, head, after, voiceSends, talkPlace, onTalkSent, onListening, autoFocus, onTextChange, cwd, onError, } = props;
91
91
  const t = (0, use_t_1.useT)();
92
92
  const [text, setText] = React.useState('');
93
93
  const [caret, setCaret] = React.useState(0);
@@ -530,6 +530,7 @@ exports.ComposerBox = React.forwardRef(function ComposerBox(props, ref) {
530
530
  talkMode && React.createElement(voice_talk_1.TalkBar, { talk: talk }),
531
531
  React.createElement("textarea", { ref: input, hidden: talkMode, rows: 1, value: text, autoFocus: autoFocus, enterKeyHint: "send", "aria-label": t('ta.composer.label'), "aria-controls": items.length ? menuId : undefined, "aria-activedescendant": items.length ? `${menuId}-${selected}` : undefined, placeholder: listening ? t('ta.composer.listening') : placeholder, onChange: event => {
532
532
  setText(event.target.value);
533
+ onTextChange === null || onTextChange === void 0 ? void 0 : onTextChange(event.target.value);
533
534
  setCaret(event.target.selectionStart);
534
535
  setSelected(0);
535
536
  }, onSelect: event => setCaret(event.currentTarget.selectionStart), onKeyDown: onKeyDown, onPaste: onPaste, onFocus: () => {
@@ -1,5 +1,5 @@
1
1
  import type { SessionStore } from '@celljs/ta-client';
2
- import type { TaServer, TaSlashCommand, TaWorkspaceServer } from '@celljs/ta-protocol';
2
+ import { type TaServer, type TaSlashCommand, type TaWorkspaceServer } from '@celljs/ta-protocol';
3
3
  import * as React from 'react';
4
4
  import { type ComposerImage, type ComposerQueued } from '../util/composer';
5
5
  import { type ComposerAction, type ComposerBoxHandle } from './composer-box';
@@ -41,6 +41,8 @@ export interface ComposerProps {
41
41
  onStop?(): void;
42
42
  /** A stop of the session's run pressed here ended (or failed): how long it took (useStopTimes). */
43
43
  onStopTimed?(timing: StopTiming): void;
44
+ /** The user types (the box holds something and a key came), or no longer (it is empty, or sent). */
45
+ onTyping?(typing: boolean): void;
44
46
  onError(error: unknown): void;
45
47
  }
46
48
  /**
@@ -35,6 +35,7 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.Composer = void 0;
37
37
  exports.QueuedMessages = QueuedMessages;
38
+ const ta_protocol_1 = require("@celljs/ta-protocol");
38
39
  const lucide_react_1 = require("lucide-react");
39
40
  const React = __importStar(require("react"));
40
41
  const assistant_task_util_1 = require("../assistant/assistant-task-util");
@@ -42,8 +43,10 @@ const device_1 = require("../device/device");
42
43
  const use_t_1 = require("../i18n/use-t");
43
44
  const composer_1 = require("../util/composer");
44
45
  const composer_box_1 = require("./composer-box");
46
+ const face_1 = require("./face");
45
47
  const icon_1 = require("./icon");
46
48
  const message_list_1 = require("./message-list");
49
+ const people_1 = require("./people");
47
50
  const stop_times_1 = require("./stop-times");
48
51
  const FILE_LIMIT = 20;
49
52
  const FILE_DELAY_MS = 120;
@@ -99,7 +102,7 @@ function useQueue(store, working) {
99
102
  * and Alt+Enter queues a follow-up; Escape stops it.
100
103
  */
101
104
  exports.Composer = React.forwardRef(function Composer(props, ref) {
102
- const { store, onSubmit, head, after, voiceSends, recentShots, talkPlace, onTalkSent, onListening, server, workspace, working, commands, cwd, actions, placeholder, above, onSending, onStop, onStopTimed, onError, } = props;
105
+ const { store, onSubmit, head, after, voiceSends, recentShots, talkPlace, onTalkSent, onListening, server, workspace, working, commands, cwd, actions, placeholder, above, onSending, onStop, onStopTimed, onTyping, onError, } = props;
103
106
  // A finger: the keyboard opens on focus, over the conversation, and there are no keys to name.
104
107
  const touch = (0, device_1.useDevice)(device => device.touch);
105
108
  const t = (0, use_t_1.useT)();
@@ -139,6 +142,7 @@ exports.Composer = React.forwardRef(function Composer(props, ref) {
139
142
  const send = (message, images, followUp) => {
140
143
  var _a;
141
144
  onSending === null || onSending === void 0 ? void 0 : onSending();
145
+ onTyping === null || onTyping === void 0 ? void 0 : onTyping(false);
142
146
  const prompt = { clientMessageId: crypto.randomUUID(), message, images: images.length ? images : undefined };
143
147
  if (!store) {
144
148
  return (_a = onSubmit === null || onSubmit === void 0 ? void 0 : onSubmit(message, prompt.images)) !== null && _a !== void 0 ? _a : Promise.resolve();
@@ -174,30 +178,38 @@ exports.Composer = React.forwardRef(function Composer(props, ref) {
174
178
  }, onError);
175
179
  };
176
180
  const waiting = composer_1.ComposerUtil.queued(queue);
177
- return (React.createElement(composer_box_1.ComposerBox, { ref: box, placeholder: placeholder !== null && placeholder !== void 0 ? placeholder : t(composer_1.ComposerUtil.placeholderKey(working, touch)), working: working, onStop: stop, onSend: send, commands: listed, onMentionQuery: setQuery, mentions: files, mentionLabel: t('ta.composer.mentionFile'), images: true, recentShots: recentShots, actions: actions, head: head, after: after, voiceSends: voiceSends, talkPlace: talkPlace, onTalkSent: onTalkSent, onListening: onListening, autoFocus: !touch, cwd: cwd, onError: onError, above: React.createElement(React.Fragment, null,
181
+ return (React.createElement(composer_box_1.ComposerBox, { ref: box, placeholder: placeholder !== null && placeholder !== void 0 ? placeholder : t(composer_1.ComposerUtil.placeholderKey(working, touch)), working: working, onStop: stop, onSend: send, commands: listed, onMentionQuery: setQuery, mentions: files, mentionLabel: t('ta.composer.mentionFile'), images: true, recentShots: recentShots, actions: actions, head: head, after: after, voiceSends: voiceSends, talkPlace: talkPlace, onTalkSent: onTalkSent, onListening: onListening, autoFocus: !touch, onTextChange: onTyping && (text => onTyping(!!text.trim())), cwd: cwd, onError: onError, above: React.createElement(React.Fragment, null,
178
182
  above,
179
183
  waiting.length > 0 && React.createElement(QueuedMessages, { waiting: waiting, onTakeBack: takeBack, onRemove: remove })) }));
180
184
  });
181
185
  /** What waits to be sent, tucked on top of the box: as the conversation will show it, the package that sent it apart. */
182
186
  function QueuedMessages({ waiting, onTakeBack, onRemove, }) {
183
187
  const t = (0, use_t_1.useT)();
188
+ const { me, ownerName } = React.useContext(people_1.MessagePeople);
184
189
  return (React.createElement("div", { className: "ta-queue", "aria-live": "polite" },
185
190
  waiting.length > 1 && (React.createElement("div", { className: "ta-queue-head" },
186
191
  React.createElement("span", null, t('ta.composer.queue.count', { count: waiting.length })),
187
192
  React.createElement("button", { type: "button", className: "ta-queue-all", onClick: onTakeBack, title: t('ta.composer.queue.takeBackTitle') }, t('ta.composer.queue.takeBackAll')))),
188
193
  waiting.map(entry => {
194
+ var _a, _b, _c;
189
195
  const note = assistant_task_util_1.AssistantTaskUtil.noteOf(entry.text);
190
196
  const shown = words(entry.text);
191
197
  const text = note ? t('ta.task.ended', { title: note.title, status: t(`ta.task.${note.status}`) }) : shown.text || shown.copied;
192
198
  const kind = t(entry.kind === 'steering' ? 'ta.composer.queue.steering' : 'ta.composer.queue.followUp');
199
+ // Another's waits as theirs: they take it back, or the owner of the Ta removes it (ta serve holds to it too).
200
+ const author = ta_protocol_1.TaMessageAuthor.of(entry.text);
201
+ const mine = ((_a = author === null || author === void 0 ? void 0 : author.id) !== null && _a !== void 0 ? _a : ta_protocol_1.TA_OWNER) === me;
193
202
  return (React.createElement("div", { key: `${entry.kind}-${entry.index}-${entry.text}`, className: "ta-queue-row" },
194
203
  React.createElement("span", { className: "ta-queue-kind", title: kind },
195
204
  React.createElement(icon_1.Icon, { icon: entry.kind === 'steering' ? lucide_react_1.CornerDownRight : lucide_react_1.Clock3, size: 13 }),
196
205
  React.createElement("span", null, kind)),
206
+ !mine && (React.createElement("span", { className: "ta-origin" },
207
+ React.createElement(face_1.Face, { seed: (_b = author === null || author === void 0 ? void 0 : author.id) !== null && _b !== void 0 ? _b : ta_protocol_1.TA_OWNER, size: 14, double: !author }),
208
+ React.createElement("span", { className: "ta-origin-name" }, (_c = author === null || author === void 0 ? void 0 : author.name) !== null && _c !== void 0 ? _c : (ownerName || t('ta.presence.owner'))))),
197
209
  !note && React.createElement(message_list_1.MessageOrigin, { blocks: blocksOf(entry.text) }),
198
210
  React.createElement("span", { className: "ta-ellipsis ta-queue-text", title: text }, text),
199
- React.createElement("span", { className: "ta-queue-actions" },
200
- !note && (React.createElement("button", { type: "button", className: "ta-icon-button", onClick: () => onRemove(entry, true), title: t('ta.composer.queue.editTitle'), "aria-label": t('ta.composer.queue.editTitle') },
211
+ React.createElement("span", { className: "ta-queue-actions", hidden: !mine && me !== ta_protocol_1.TA_OWNER },
212
+ !note && mine && (React.createElement("button", { type: "button", className: "ta-icon-button", onClick: () => onRemove(entry, true), title: t('ta.composer.queue.editTitle'), "aria-label": t('ta.composer.queue.editTitle') },
201
213
  React.createElement(icon_1.Icon, { icon: lucide_react_1.PenLine, size: 13 }))),
202
214
  React.createElement("button", { type: "button", className: "ta-icon-button", onClick: () => onRemove(entry, false), title: t('ta.composer.queue.remove'), "aria-label": t('ta.composer.queue.remove') },
203
215
  React.createElement(icon_1.Icon, { icon: lucide_react_1.X, size: 13 })))));
@@ -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