@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
@@ -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
@@ -0,0 +1,217 @@
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.CustomProviderForm = CustomProviderForm;
37
+ const ta_protocol_1 = require("@celljs/ta-protocol");
38
+ const lucide_react_1 = require("lucide-react");
39
+ const React = __importStar(require("react"));
40
+ const hooks_1 = require("../hooks");
41
+ const use_t_1 = require("../i18n/use-t");
42
+ const busy_1 = require("./busy");
43
+ const callout_1 = require("./callout");
44
+ const custom_provider_advanced_1 = require("./custom-provider-advanced");
45
+ const custom_provider_util_1 = require("./custom-provider-util");
46
+ const icon_1 = require("./icon");
47
+ const API_WORDS = {
48
+ 'openai-completions': 'ta.auth.custom.apiOpenai',
49
+ 'openai-responses': 'ta.auth.custom.apiResponses',
50
+ 'anthropic-messages': 'ta.auth.custom.apiAnthropic',
51
+ 'google-generative-ai': 'ta.auth.custom.apiGoogle',
52
+ };
53
+ /** What an address of each API looks like. */
54
+ const ADDRESSES = {
55
+ 'openai-completions': 'https://api.example.com/v1',
56
+ 'openai-responses': 'https://api.example.com/v1',
57
+ 'anthropic-messages': 'https://api.example.com',
58
+ 'google-generative-ai': 'https://generativelanguage.googleapis.com/v1beta',
59
+ };
60
+ /** A list a service gave longer than this has a box to narrow it. */
61
+ const FILTER_FROM = 8;
62
+ /**
63
+ * A provider of models the user adds by its address and key, or changes: the API it speaks, where it is, its key and
64
+ * its models, which the service can list. ta serve keeps it in pi's models.json; the key never comes back here.
65
+ */
66
+ function CustomProviderForm({ provider, onSaved, onBack }) {
67
+ var _a, _b, _c, _d, _e;
68
+ const t = (0, use_t_1.useT)();
69
+ const [, bench] = (0, hooks_1.useWorkbench)();
70
+ const [, notices] = (0, hooks_1.useNotices)();
71
+ const [api, setApi] = React.useState((_a = provider === null || provider === void 0 ? void 0 : provider.api) !== null && _a !== void 0 ? _a : 'openai-completions');
72
+ const [baseUrl, setBaseUrl] = React.useState((_b = provider === null || provider === void 0 ? void 0 : provider.baseUrl) !== null && _b !== void 0 ? _b : '');
73
+ const [apiKey, setApiKey] = React.useState('');
74
+ const [name, setName] = React.useState((_c = provider === null || provider === void 0 ? void 0 : provider.name) !== null && _c !== void 0 ? _c : '');
75
+ const [models, setModels] = React.useState((_d = provider === null || provider === void 0 ? void 0 : provider.models) !== null && _d !== void 0 ? _d : []);
76
+ const [draft, setDraft] = React.useState('');
77
+ const [fetched, setFetched] = React.useState();
78
+ const [fetchError, setFetchError] = React.useState();
79
+ const [words, setWords] = React.useState('');
80
+ const [advanced, setAdvanced] = React.useState(() => custom_provider_util_1.CustomProviderFormUtil.advanced(provider));
81
+ const [saving, runSave] = (0, busy_1.useBusy)();
82
+ const [fetching, runFetch] = (0, busy_1.useBusy)();
83
+ const [removing, runRemove] = (0, busy_1.useBusy)();
84
+ const key = apiKey.trim() || undefined;
85
+ const typed = () => custom_provider_util_1.CustomProviderFormUtil.add(models, custom_provider_util_1.CustomProviderFormUtil.split(draft));
86
+ const addDraft = () => {
87
+ setModels(typed());
88
+ setDraft('');
89
+ };
90
+ const fetchModels = () => runFetch(async () => {
91
+ setFetchError(undefined);
92
+ try {
93
+ const ids = await bench.auth.fetchCustomModels({
94
+ id: provider === null || provider === void 0 ? void 0 : provider.id,
95
+ api,
96
+ baseUrl,
97
+ apiKey: key,
98
+ headers: custom_provider_util_1.CustomProviderFormUtil.headersOf(advanced),
99
+ });
100
+ setFetched(ids);
101
+ setWords('');
102
+ }
103
+ catch (error) {
104
+ setFetched(undefined);
105
+ setFetchError(error instanceof Error ? error.message : String(error));
106
+ }
107
+ });
108
+ const save = () => runSave(async () => {
109
+ var _a;
110
+ const chosen = typed();
111
+ setModels(chosen);
112
+ setDraft('');
113
+ if (chosen.length === 0) {
114
+ notices.notify(t('ta.auth.custom.needModel'), { level: 'warning' });
115
+ return;
116
+ }
117
+ let options;
118
+ try {
119
+ options = custom_provider_util_1.CustomProviderFormUtil.optionsOf(advanced, (_a = provider === null || provider === void 0 ? void 0 : provider.mixed) !== null && _a !== void 0 ? _a : []);
120
+ }
121
+ catch (error) {
122
+ notices.notify(t('ta.auth.custom.badNumber', { value: error instanceof Error ? error.message : String(error) }), { level: 'warning' });
123
+ return;
124
+ }
125
+ try {
126
+ const headers = custom_provider_util_1.CustomProviderFormUtil.headersOf(advanced);
127
+ onSaved(await bench.auth.saveCustomProvider({ id: provider === null || provider === void 0 ? void 0 : provider.id, name, api, baseUrl, apiKey: key, models: chosen, options, headers }));
128
+ }
129
+ catch (error) {
130
+ notices.error(error);
131
+ }
132
+ });
133
+ const remove = () => runRemove(async () => {
134
+ if (!provider) {
135
+ return;
136
+ }
137
+ const confirmed = await notices.confirm({
138
+ title: t('ta.auth.custom.removeConfirm', { name: provider.name }),
139
+ confirmLabel: t('ta.auth.custom.remove'),
140
+ danger: true,
141
+ });
142
+ if (confirmed) {
143
+ await bench.auth.removeCustomProvider(provider.id).then(onBack, error => notices.error(error));
144
+ }
145
+ });
146
+ const shown = fetched ? custom_provider_util_1.CustomProviderFormUtil.shown(fetched, words) : [];
147
+ return (React.createElement("div", { className: "ta-auth-flow ta-custom-flow" },
148
+ React.createElement("div", { className: "ta-auth-flow-head" },
149
+ React.createElement(icon_1.IconButton, { icon: lucide_react_1.ArrowLeft, label: t('ta.auth.back'), onClick: onBack }),
150
+ React.createElement("span", { className: "ta-auth-flow-title" }, (_e = provider === null || provider === void 0 ? void 0 : provider.name) !== null && _e !== void 0 ? _e : t('ta.auth.custom.title')),
151
+ React.createElement("span", { className: "ta-auth-kind" }, t('ta.auth.custom.kind'))),
152
+ React.createElement("form", { className: "ta-custom-form", onSubmit: event => {
153
+ event.preventDefault();
154
+ void save();
155
+ } },
156
+ React.createElement("label", { className: "ta-store-field" },
157
+ React.createElement("span", { className: "ta-store-field-label" }, t('ta.auth.custom.api')),
158
+ React.createElement("select", { className: "ta-input ta-select", value: api, onChange: event => setApi(event.target.value) }, ta_protocol_1.TA_CUSTOM_APIS.map(each => (React.createElement("option", { key: each, value: each }, t(API_WORDS[each])))))),
159
+ React.createElement("label", { className: "ta-store-field" },
160
+ React.createElement("span", { className: "ta-store-field-label" }, t('ta.auth.custom.baseUrl')),
161
+ React.createElement("input", { className: "ta-input", type: "url", inputMode: "url", autoComplete: "off", spellCheck: false, required: true, placeholder: ADDRESSES[api], value: baseUrl, onChange: event => setBaseUrl(event.target.value) })),
162
+ React.createElement("label", { className: "ta-store-field" },
163
+ React.createElement("span", { className: "ta-store-field-label" },
164
+ t('ta.auth.custom.apiKey'),
165
+ React.createElement("span", { className: "ta-store-field-optional" }, t('ta.auth.custom.keyOptional'))),
166
+ React.createElement("input", { className: "ta-input", type: "password", autoComplete: "new-password", spellCheck: false, placeholder: (provider === null || provider === void 0 ? void 0 : provider.hasKey) ? t('ta.auth.custom.keyKept') : 'sk-…', value: apiKey, onChange: event => setApiKey(event.target.value) })),
167
+ React.createElement("label", { className: "ta-store-field" },
168
+ React.createElement("span", { className: "ta-store-field-label" },
169
+ t('ta.auth.custom.name'),
170
+ React.createElement("span", { className: "ta-store-field-optional" }, t('ta.auth.custom.optional'))),
171
+ React.createElement("input", { className: "ta-input", autoComplete: "off", spellCheck: false, placeholder: custom_provider_util_1.CustomProviderFormUtil.host(baseUrl), value: name, onChange: event => setName(event.target.value) })),
172
+ React.createElement("div", { className: "ta-store-field" },
173
+ React.createElement("span", { className: "ta-store-field-label" }, t('ta.auth.custom.models')),
174
+ React.createElement("div", { className: "ta-custom-models" },
175
+ models.map(id => (React.createElement("span", { key: id, className: "ta-custom-chip" },
176
+ React.createElement("span", { className: "ta-custom-chip-text" }, id),
177
+ React.createElement("button", { type: "button", "aria-label": t('ta.auth.custom.removeModel', { id }), onClick: () => setModels(before => before.filter(model => model !== id)) },
178
+ React.createElement(icon_1.Icon, { icon: lucide_react_1.X, size: 12 }))))),
179
+ React.createElement("input", { className: "ta-custom-model-input", autoComplete: "off", spellCheck: false, "aria-label": t('ta.auth.custom.models'), placeholder: models.length ? '' : t('ta.auth.custom.modelPlaceholder'), value: draft, onChange: event => setDraft(event.target.value), onBlur: addDraft, onKeyDown: event => {
180
+ if ((event.key === 'Enter' || event.key === ',') && !event.nativeEvent.isComposing) {
181
+ event.preventDefault();
182
+ addDraft();
183
+ }
184
+ else if (event.key === 'Backspace' && !draft && models.length) {
185
+ setModels(models.slice(0, -1));
186
+ }
187
+ } })),
188
+ React.createElement("button", { type: "button", className: `ta-button ta-custom-fetch${fetching ? ' ta-busy' : ''}`, disabled: !baseUrl.trim() || fetching, onClick: () => void fetchModels() },
189
+ React.createElement(busy_1.BusyMark, { busy: fetching }),
190
+ React.createElement(icon_1.Icon, { icon: lucide_react_1.Download, size: 14 }),
191
+ " ",
192
+ t('ta.auth.custom.fetch')),
193
+ fetchError && React.createElement(callout_1.Callout, { level: "error" }, t('ta.auth.custom.fetchFailed', { message: fetchError })),
194
+ fetched && (React.createElement("div", { className: "ta-custom-fetched" },
195
+ React.createElement("span", { className: "ta-auth-note" }, fetched.length ? t('ta.auth.custom.fetched', { count: fetched.length }) : t('ta.auth.custom.fetchedNone')),
196
+ fetched.length > FILTER_FROM && (React.createElement("input", { className: "ta-input", placeholder: t('ta.auth.custom.filter'), value: words, onChange: event => setWords(event.target.value) })),
197
+ React.createElement("div", { className: "ta-custom-fetched-list" }, shown.map(id => {
198
+ const picked = models.includes(id);
199
+ return (React.createElement("button", { key: id, type: "button", className: "ta-auth-item", "aria-pressed": picked, onClick: () => setModels(before => custom_provider_util_1.CustomProviderFormUtil.toggle(before, id)) },
200
+ React.createElement("span", { className: "ta-auth-name" }, id),
201
+ picked && React.createElement(icon_1.Icon, { icon: lucide_react_1.Check, size: 15, className: "ta-custom-picked" })));
202
+ }))))),
203
+ React.createElement(custom_provider_advanced_1.CustomProviderAdvanced, { provider: provider, state: advanced, onChange: setAdvanced }),
204
+ React.createElement("p", { className: "ta-store-form-note" },
205
+ React.createElement(icon_1.Icon, { icon: lucide_react_1.ShieldCheck, size: 13 }),
206
+ React.createElement("span", null, t('ta.auth.custom.note'))),
207
+ React.createElement("div", { className: "ta-custom-actions" },
208
+ provider && (React.createElement("button", { type: "button", className: `ta-button ta-danger${removing ? ' ta-busy' : ''}`, disabled: removing || saving, onClick: () => void remove() },
209
+ React.createElement(busy_1.BusyMark, { busy: removing }),
210
+ React.createElement(icon_1.Icon, { icon: lucide_react_1.Trash2, size: 14 }),
211
+ " ",
212
+ t('ta.auth.custom.remove'))),
213
+ React.createElement("button", { type: "submit", className: `ta-button ta-primary${saving ? ' ta-busy' : ''}`, disabled: !baseUrl.trim() || saving || removing },
214
+ React.createElement(busy_1.BusyMark, { busy: saving }),
215
+ React.createElement("span", null, t('ta.auth.custom.save')))))));
216
+ }
217
+ //# sourceMappingURL=custom-provider-view.js.map
@@ -62,10 +62,15 @@ function Face(props) {
62
62
  const species = dino_species_1.DinoSpecies.IDS.find(id => id === props.look);
63
63
  return species ? React.createElement(DoubleFace, { species: species, size: props.size, online: props.online }) : React.createElement(ShapeFace, { ...props });
64
64
  }
65
+ /**
66
+ * How wide the disc of a double is in its box: as wide as the shapes, which leave a margin in their 40 × 40 grid (the
67
+ * round one is 29 wide), so that a double among them in a row is no bigger than they are.
68
+ */
69
+ const DOUBLE_DISC = 0.75;
65
70
  /** A Ta as its double: the close-up of the dinosaur, as the account shows it; this Ta's own without `species`. */
66
71
  function DoubleFace({ species, size, online }) {
67
- return (React.createElement("span", { className: "ta-face", style: { width: size, height: size }, "aria-hidden": "true" },
68
- React.createElement(ta_avatar_1.DinoFace, { species: species, size: size }),
72
+ return (React.createElement("span", { className: "ta-face ta-face-double", style: { width: size, height: size }, "aria-hidden": "true" },
73
+ React.createElement(ta_avatar_1.DinoFace, { species: species, size: Math.round(size * DOUBLE_DISC) }),
69
74
  online !== undefined && React.createElement("i", { className: `ta-face-dot${online ? ' ta-face-on' : ''}` })));
70
75
  }
71
76
  function ShapeFace({ face: given, seed = '', size, working, online }) {
@@ -0,0 +1,10 @@
1
+ import * as React from 'react';
2
+ import type { MarkdownPicture } from '../util/markdown';
3
+ /**
4
+ * Pictures of a reply shown together (GalleryUtil): square tiles in columns as many as suit their number, the words
5
+ * that name each under it, and a click on one opens it over the page, where ← → and its side buttons go through all.
6
+ */
7
+ export declare function Gallery({ items }: {
8
+ items: readonly MarkdownPicture[];
9
+ }): React.JSX.Element;
10
+ //# sourceMappingURL=gallery.d.ts.map
@@ -0,0 +1,93 @@
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.Gallery = Gallery;
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 gallery_1 = require("../util/gallery");
41
+ const thumbnail_1 = require("../util/thumbnail");
42
+ const icon_1 = require("./icon");
43
+ const lightbox_1 = require("./lightbox");
44
+ const media_1 = require("./media");
45
+ /** A tile: the picture cut to a square, a place that shimmers while it loads, and on the last one how many more there are. */
46
+ /** The CSS side of a tile at most (--ta-gallery-tile, style/conversation.ts). */
47
+ const TILE = 168;
48
+ const TILE_BOX = { width: thumbnail_1.ThumbnailUtil.side(TILE), height: thumbnail_1.ThumbnailUtil.side(TILE), cover: true };
49
+ function Tile({ url, picture, more, onOpen }) {
50
+ const t = (0, use_t_1.useT)();
51
+ const [failed, setFailed] = React.useState();
52
+ const [loaded, setLoaded] = React.useState();
53
+ if (url === null || (url && failed === url)) {
54
+ return (React.createElement("span", { className: "ta-gallery-tile ta-gallery-missing", title: picture.src },
55
+ React.createElement(icon_1.Icon, { icon: lucide_react_1.ImageOff, size: 18 })));
56
+ }
57
+ return (React.createElement("button", { type: "button", className: `ta-gallery-tile${url && loaded === url ? '' : ' ta-gallery-pending'}`, title: picture.caption || picture.alt || t('ta.markdown.enlarge'), disabled: !url, onClick: onOpen },
58
+ url && React.createElement("img", { src: url, alt: picture.alt, loading: "lazy", onLoad: () => setLoaded(url), onError: () => setFailed(url) }),
59
+ more > 0 && React.createElement("span", { className: "ta-gallery-more" },
60
+ "+",
61
+ more)));
62
+ }
63
+ /**
64
+ * Pictures of a reply shown together (GalleryUtil): square tiles in columns as many as suit their number, the words
65
+ * that name each under it, and a click on one opens it over the page, where ← → and its side buttons go through all.
66
+ */
67
+ function Gallery({ items }) {
68
+ // A picture of the workspace loads as large as its tile (ThumbnailUtil); enlarged, as it is.
69
+ const urls = (0, media_1.useMediaUrls)(React.useMemo(() => items.map(item => item.src), [items]), TILE_BOX);
70
+ const [open, setOpen] = React.useState();
71
+ const full = (0, media_1.useMediaUrl)(open !== undefined && urls[open] ? items[open].src : undefined);
72
+ const shown = items.slice(0, gallery_1.GalleryUtil.TILES);
73
+ const more = items.length - shown.length;
74
+ const named = items.some(item => item.caption);
75
+ const style = { '--ta-gallery-columns': gallery_1.GalleryUtil.columns(items.length) };
76
+ const step = (from, by) => {
77
+ for (let at = from + by; at >= 0 && at < items.length; at += by) {
78
+ if (urls[at]) {
79
+ return at;
80
+ }
81
+ }
82
+ return undefined;
83
+ };
84
+ const current = open !== undefined ? urls[open] : undefined;
85
+ const previous = open !== undefined ? step(open, -1) : undefined;
86
+ const next = open !== undefined ? step(open, 1) : undefined;
87
+ return (React.createElement("div", { className: "ta-gallery", style: style },
88
+ shown.map((item, index) => { var _a; return (React.createElement("figure", { key: index, className: "ta-gallery-item" },
89
+ React.createElement(Tile, { url: urls[index], picture: item, more: index === shown.length - 1 ? more : 0, onOpen: () => setOpen(index) }),
90
+ named && React.createElement("figcaption", { className: "ta-gallery-caption" }, (_a = item.caption) !== null && _a !== void 0 ? _a : '\u00a0'))); }),
91
+ open !== undefined && current && (React.createElement(lightbox_1.Lightbox, { src: full || current, alt: items[open].alt, caption: items[open].caption, count: { at: open, of: items.length }, onClose: () => setOpen(undefined), onPrevious: previous !== undefined ? () => setOpen(previous) : undefined, onNext: next !== undefined ? () => setOpen(next) : undefined }))));
92
+ }
93
+ //# sourceMappingURL=gallery.js.map