@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.
- package/README.en.md +3 -3
- package/README.md +3 -3
- package/esm/browser/assistant/assistant-extension.js +3 -2
- package/esm/browser/assistant/assistant-initiative.js +1 -1
- package/esm/browser/assistant/assistant-state.js +2 -2
- package/esm/browser/components/access-view.js +3 -2
- package/esm/browser/components/account-menu.js +2 -2
- package/esm/browser/components/app-view.js +4 -0
- package/esm/browser/components/auth-view.d.ts +1 -1
- package/esm/browser/components/auth-view.js +38 -10
- package/esm/browser/components/chat-asks.d.ts +8 -0
- package/esm/browser/components/chat-asks.js +10 -0
- package/esm/browser/components/chat-list.js +11 -1
- package/esm/browser/components/composer-box.d.ts +2 -0
- package/esm/browser/components/composer-box.js +2 -1
- package/esm/browser/components/composer.d.ts +3 -1
- package/esm/browser/components/composer.js +16 -4
- package/esm/browser/components/custom-provider-advanced.d.ts +14 -0
- package/esm/browser/components/custom-provider-advanced.js +50 -0
- package/esm/browser/components/custom-provider-util.d.ts +38 -0
- package/esm/browser/components/custom-provider-util.js +103 -0
- package/esm/browser/components/custom-provider-view.d.ts +11 -0
- package/esm/browser/components/custom-provider-view.js +181 -0
- package/esm/browser/components/face.d.ts +13 -1
- package/esm/browser/components/face.js +16 -1
- package/esm/browser/components/host-view.d.ts +1 -1
- package/esm/browser/components/message-list.js +20 -1
- package/esm/browser/components/people.d.ts +32 -0
- package/esm/browser/components/people.js +71 -0
- package/esm/browser/components/session-view.d.ts +1 -1
- package/esm/browser/components/session-view.js +56 -36
- package/esm/browser/components/settings-choices.js +2 -3
- package/esm/browser/components/settings-controls.d.ts +7 -1
- package/esm/browser/components/settings-controls.js +8 -0
- package/esm/browser/components/settings-parts.js +25 -8
- package/esm/browser/components/sign-in-setup.d.ts +16 -0
- package/esm/browser/components/sign-in-setup.js +118 -0
- package/esm/browser/components/use-seen-chats.d.ts +2 -0
- package/esm/browser/components/use-seen-chats.js +2 -2
- package/esm/browser/editor/monaco-loader.js +7 -1
- package/esm/browser/extension/web-api-components.d.ts +12 -0
- package/esm/browser/extension/web-api-contributions.d.ts +3 -0
- package/esm/browser/extension/web-extension-api.d.ts +9 -2
- package/esm/browser/extension/web-extension-context.d.ts +2 -0
- package/esm/browser/extension/web-extension-context.js +19 -0
- package/esm/browser/game/game-loader.js +22 -2
- package/esm/browser/game/game3d-protocol.d.ts +13 -4
- package/esm/browser/i18n/locales.d.ts +90 -1
- package/esm/browser/i18n/locales.js +25 -1
- package/esm/browser/i18n/messages-ja.d.ts +2 -0
- package/esm/browser/i18n/messages-ja.js +972 -0
- package/esm/browser/i18n/messages-zh-tw.d.ts +3 -0
- package/esm/browser/i18n/messages-zh-tw.js +973 -0
- package/esm/browser/i18n/messages.d.ts +85 -0
- package/esm/browser/i18n/messages.js +171 -1
- package/esm/browser/i18n/use-t.js +3 -2
- package/esm/browser/presence/presence-reporter.d.ts +32 -0
- package/esm/browser/presence/presence-reporter.js +71 -0
- package/esm/browser/settings/settings-protocol.d.ts +3 -2
- package/esm/browser/settings/settings-protocol.js +4 -3
- package/esm/browser/style/conversation.d.ts +1 -1
- package/esm/browser/style/conversation.js +24 -0
- package/esm/browser/style/layout.d.ts +1 -1
- package/esm/browser/style/layout.js +8 -0
- package/esm/browser/style/pages.d.ts +1 -1
- package/esm/browser/style/pages.js +53 -1
- package/esm/browser/util/desktop.d.ts +12 -1
- package/esm/browser/util/desktop.js +14 -0
- package/esm/browser/util/voice.d.ts +20 -1
- package/esm/browser/util/voice.js +27 -11
- package/esm/browser/workbench-protocol.d.ts +9 -0
- package/esm/browser/workbench-util.d.ts +4 -0
- package/esm/browser/workbench-util.js +24 -1
- package/esm/browser/workbench.d.ts +3 -0
- package/esm/browser/workbench.js +14 -4
- package/lib/browser/assistant/assistant-extension.js +3 -2
- package/lib/browser/assistant/assistant-initiative.js +1 -1
- package/lib/browser/assistant/assistant-state.js +1 -1
- package/lib/browser/components/access-view.js +3 -2
- package/lib/browser/components/account-menu.js +2 -2
- package/lib/browser/components/app-view.js +4 -0
- package/lib/browser/components/auth-view.d.ts +1 -1
- package/lib/browser/components/auth-view.js +37 -9
- package/lib/browser/components/chat-asks.d.ts +8 -0
- package/lib/browser/components/chat-asks.js +10 -0
- package/lib/browser/components/chat-list.js +11 -1
- package/lib/browser/components/composer-box.d.ts +2 -0
- package/lib/browser/components/composer-box.js +2 -1
- package/lib/browser/components/composer.d.ts +3 -1
- package/lib/browser/components/composer.js +16 -4
- package/lib/browser/components/custom-provider-advanced.d.ts +15 -0
- package/lib/browser/components/custom-provider-advanced.js +86 -0
- package/lib/browser/components/custom-provider-util.d.ts +39 -0
- package/lib/browser/components/custom-provider-util.js +106 -0
- package/lib/browser/components/custom-provider-view.d.ts +12 -0
- package/lib/browser/components/custom-provider-view.js +217 -0
- package/lib/browser/components/face.d.ts +13 -1
- package/lib/browser/components/face.js +16 -1
- package/lib/browser/components/host-view.d.ts +1 -1
- package/lib/browser/components/message-list.js +19 -0
- package/lib/browser/components/people.d.ts +33 -0
- package/lib/browser/components/people.js +109 -0
- package/lib/browser/components/session-view.d.ts +1 -1
- package/lib/browser/components/session-view.js +56 -36
- package/lib/browser/components/settings-choices.js +1 -2
- package/lib/browser/components/settings-controls.d.ts +7 -1
- package/lib/browser/components/settings-controls.js +9 -0
- package/lib/browser/components/settings-parts.js +24 -7
- package/lib/browser/components/sign-in-setup.d.ts +17 -0
- package/lib/browser/components/sign-in-setup.js +155 -0
- package/lib/browser/components/use-seen-chats.d.ts +2 -0
- package/lib/browser/components/use-seen-chats.js +3 -2
- package/lib/browser/editor/monaco-loader.js +7 -1
- package/lib/browser/extension/web-api-components.d.ts +12 -0
- package/lib/browser/extension/web-api-contributions.d.ts +3 -0
- package/lib/browser/extension/web-extension-api.d.ts +9 -2
- package/lib/browser/extension/web-extension-context.d.ts +2 -0
- package/lib/browser/extension/web-extension-context.js +19 -0
- package/lib/browser/game/game-loader.js +22 -2
- package/lib/browser/game/game3d-protocol.d.ts +13 -4
- package/lib/browser/i18n/locales.d.ts +90 -1
- package/lib/browser/i18n/locales.js +25 -1
- package/lib/browser/i18n/messages-ja.d.ts +3 -0
- package/lib/browser/i18n/messages-ja.js +975 -0
- package/lib/browser/i18n/messages-zh-tw.d.ts +4 -0
- package/lib/browser/i18n/messages-zh-tw.js +976 -0
- package/lib/browser/i18n/messages.d.ts +85 -0
- package/lib/browser/i18n/messages.js +174 -2
- package/lib/browser/i18n/use-t.js +2 -1
- package/lib/browser/presence/presence-reporter.d.ts +33 -0
- package/lib/browser/presence/presence-reporter.js +75 -0
- package/lib/browser/settings/settings-protocol.d.ts +3 -2
- package/lib/browser/settings/settings-protocol.js +4 -3
- package/lib/browser/style/conversation.d.ts +1 -1
- package/lib/browser/style/conversation.js +24 -0
- package/lib/browser/style/layout.d.ts +1 -1
- package/lib/browser/style/layout.js +8 -0
- package/lib/browser/style/pages.d.ts +1 -1
- package/lib/browser/style/pages.js +53 -1
- package/lib/browser/util/desktop.d.ts +12 -1
- package/lib/browser/util/desktop.js +14 -0
- package/lib/browser/util/voice.d.ts +20 -1
- package/lib/browser/util/voice.js +27 -11
- package/lib/browser/workbench-protocol.d.ts +9 -0
- package/lib/browser/workbench-util.d.ts +4 -0
- package/lib/browser/workbench-util.js +24 -1
- package/lib/browser/workbench.d.ts +3 -0
- package/lib/browser/workbench.js +14 -4
- package/package.json +10 -10
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { TA_OWNER, TaMessageAuthor } from '@celljs/ta-protocol';
|
|
1
2
|
import { Clock3, CornerDownRight, PenLine, X } from 'lucide-react';
|
|
2
3
|
import * as React from 'react';
|
|
3
4
|
import { AssistantTaskUtil } from '../assistant/assistant-task-util.js';
|
|
@@ -5,8 +6,10 @@ import { useDevice } from '../device/device.js';
|
|
|
5
6
|
import { useLanguage, useT } from '../i18n/use-t.js';
|
|
6
7
|
import { ComposerUtil } from '../util/composer.js';
|
|
7
8
|
import { ComposerBox } from './composer-box.js';
|
|
9
|
+
import { Face } from './face.js';
|
|
8
10
|
import { Icon } from './icon.js';
|
|
9
11
|
import { MessageOrigin, userWords } from './message-list.js';
|
|
12
|
+
import { MessagePeople } from './people.js';
|
|
10
13
|
import { StopClock } from './stop-times.js';
|
|
11
14
|
const FILE_LIMIT = 20;
|
|
12
15
|
const FILE_DELAY_MS = 120;
|
|
@@ -62,7 +65,7 @@ function useQueue(store, working) {
|
|
|
62
65
|
* and Alt+Enter queues a follow-up; Escape stops it.
|
|
63
66
|
*/
|
|
64
67
|
export const Composer = React.forwardRef(function Composer(props, ref) {
|
|
65
|
-
const { store, onSubmit, head, after, voiceSends, recentShots, talkPlace, onTalkSent, onListening, server, workspace, working, commands, cwd, actions, placeholder, above, onSending, onStop, onStopTimed, onError, } = props;
|
|
68
|
+
const { store, onSubmit, head, after, voiceSends, recentShots, talkPlace, onTalkSent, onListening, server, workspace, working, commands, cwd, actions, placeholder, above, onSending, onStop, onStopTimed, onTyping, onError, } = props;
|
|
66
69
|
// A finger: the keyboard opens on focus, over the conversation, and there are no keys to name.
|
|
67
70
|
const touch = useDevice(device => device.touch);
|
|
68
71
|
const t = useT();
|
|
@@ -102,6 +105,7 @@ export const Composer = React.forwardRef(function Composer(props, ref) {
|
|
|
102
105
|
const send = (message, images, followUp) => {
|
|
103
106
|
var _a;
|
|
104
107
|
onSending === null || onSending === void 0 ? void 0 : onSending();
|
|
108
|
+
onTyping === null || onTyping === void 0 ? void 0 : onTyping(false);
|
|
105
109
|
const prompt = { clientMessageId: crypto.randomUUID(), message, images: images.length ? images : undefined };
|
|
106
110
|
if (!store) {
|
|
107
111
|
return (_a = onSubmit === null || onSubmit === void 0 ? void 0 : onSubmit(message, prompt.images)) !== null && _a !== void 0 ? _a : Promise.resolve();
|
|
@@ -137,30 +141,38 @@ export const Composer = React.forwardRef(function Composer(props, ref) {
|
|
|
137
141
|
}, onError);
|
|
138
142
|
};
|
|
139
143
|
const waiting = ComposerUtil.queued(queue);
|
|
140
|
-
return (React.createElement(ComposerBox, { ref: box, placeholder: placeholder !== null && placeholder !== void 0 ? placeholder : t(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,
|
|
144
|
+
return (React.createElement(ComposerBox, { ref: box, placeholder: placeholder !== null && placeholder !== void 0 ? placeholder : t(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,
|
|
141
145
|
above,
|
|
142
146
|
waiting.length > 0 && React.createElement(QueuedMessages, { waiting: waiting, onTakeBack: takeBack, onRemove: remove })) }));
|
|
143
147
|
});
|
|
144
148
|
/** What waits to be sent, tucked on top of the box: as the conversation will show it, the package that sent it apart. */
|
|
145
149
|
export function QueuedMessages({ waiting, onTakeBack, onRemove, }) {
|
|
146
150
|
const t = useT();
|
|
151
|
+
const { me, ownerName } = React.useContext(MessagePeople);
|
|
147
152
|
return (React.createElement("div", { className: "ta-queue", "aria-live": "polite" },
|
|
148
153
|
waiting.length > 1 && (React.createElement("div", { className: "ta-queue-head" },
|
|
149
154
|
React.createElement("span", null, t('ta.composer.queue.count', { count: waiting.length })),
|
|
150
155
|
React.createElement("button", { type: "button", className: "ta-queue-all", onClick: onTakeBack, title: t('ta.composer.queue.takeBackTitle') }, t('ta.composer.queue.takeBackAll')))),
|
|
151
156
|
waiting.map(entry => {
|
|
157
|
+
var _a, _b, _c;
|
|
152
158
|
const note = AssistantTaskUtil.noteOf(entry.text);
|
|
153
159
|
const shown = words(entry.text);
|
|
154
160
|
const text = note ? t('ta.task.ended', { title: note.title, status: t(`ta.task.${note.status}`) }) : shown.text || shown.copied;
|
|
155
161
|
const kind = t(entry.kind === 'steering' ? 'ta.composer.queue.steering' : 'ta.composer.queue.followUp');
|
|
162
|
+
// Another's waits as theirs: they take it back, or the owner of the Ta removes it (ta serve holds to it too).
|
|
163
|
+
const author = TaMessageAuthor.of(entry.text);
|
|
164
|
+
const mine = ((_a = author === null || author === void 0 ? void 0 : author.id) !== null && _a !== void 0 ? _a : TA_OWNER) === me;
|
|
156
165
|
return (React.createElement("div", { key: `${entry.kind}-${entry.index}-${entry.text}`, className: "ta-queue-row" },
|
|
157
166
|
React.createElement("span", { className: "ta-queue-kind", title: kind },
|
|
158
167
|
React.createElement(Icon, { icon: entry.kind === 'steering' ? CornerDownRight : Clock3, size: 13 }),
|
|
159
168
|
React.createElement("span", null, kind)),
|
|
169
|
+
!mine && (React.createElement("span", { className: "ta-origin" },
|
|
170
|
+
React.createElement(Face, { seed: (_b = author === null || author === void 0 ? void 0 : author.id) !== null && _b !== void 0 ? _b : TA_OWNER, size: 14, double: !author }),
|
|
171
|
+
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'))))),
|
|
160
172
|
!note && React.createElement(MessageOrigin, { blocks: blocksOf(entry.text) }),
|
|
161
173
|
React.createElement("span", { className: "ta-ellipsis ta-queue-text", title: text }, text),
|
|
162
|
-
React.createElement("span", { className: "ta-queue-actions" },
|
|
163
|
-
!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') },
|
|
174
|
+
React.createElement("span", { className: "ta-queue-actions", hidden: !mine && me !== TA_OWNER },
|
|
175
|
+
!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') },
|
|
164
176
|
React.createElement(Icon, { icon: PenLine, size: 13 }))),
|
|
165
177
|
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') },
|
|
166
178
|
React.createElement(Icon, { icon: X, size: 13 })))));
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { TaCustomProvider } from '@celljs/ta-protocol';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { CustomProviderFormUtil } from './custom-provider-util.js';
|
|
4
|
+
type Advanced = CustomProviderFormUtil.Advanced;
|
|
5
|
+
/**
|
|
6
|
+
* The advanced fields of a model service added by its address, folded: what its models are (context window, output,
|
|
7
|
+
* thinking, pictures), the same for each, and the headers it sends, whose values ta serve keeps.
|
|
8
|
+
*/
|
|
9
|
+
export declare function CustomProviderAdvanced({ provider, state, onChange }: {
|
|
10
|
+
provider?: TaCustomProvider;
|
|
11
|
+
state: Advanced;
|
|
12
|
+
onChange(next: Advanced): void;
|
|
13
|
+
}): React.JSX.Element;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ChevronDown, Plus, X } from 'lucide-react';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { useT } from '../i18n/use-t.js';
|
|
4
|
+
import { CustomProviderFormUtil } from './custom-provider-util.js';
|
|
5
|
+
import { Icon } from './icon.js';
|
|
6
|
+
/** pi's defaults, shown where nothing is typed. */
|
|
7
|
+
const DEFAULTS = { contextWindow: '128000', maxTokens: '16384' };
|
|
8
|
+
/**
|
|
9
|
+
* The advanced fields of a model service added by its address, folded: what its models are (context window, output,
|
|
10
|
+
* thinking, pictures), the same for each, and the headers it sends, whose values ta serve keeps.
|
|
11
|
+
*/
|
|
12
|
+
export function CustomProviderAdvanced({ provider, state, onChange }) {
|
|
13
|
+
var _a;
|
|
14
|
+
const t = useT();
|
|
15
|
+
const [open, setOpen] = React.useState(() => CustomProviderFormUtil.hasAdvanced(provider));
|
|
16
|
+
const mixed = (_a = provider === null || provider === void 0 ? void 0 : provider.mixed) !== null && _a !== void 0 ? _a : [];
|
|
17
|
+
const change = (key, value) => onChange({ ...state, [key]: value, touched: state.touched.includes(key) ? state.touched : [...state.touched, key] });
|
|
18
|
+
const placeholder = (key, fallback) => mixed.includes(key) && !state.touched.includes(key) ? t('ta.auth.custom.mixed') : fallback;
|
|
19
|
+
const rows = (headers) => onChange({ ...state, headers });
|
|
20
|
+
const number = (key, label) => (React.createElement("label", { className: "ta-store-field" },
|
|
21
|
+
React.createElement("span", { className: "ta-store-field-label" }, label),
|
|
22
|
+
React.createElement("input", { className: "ta-input", inputMode: "numeric", autoComplete: "off", spellCheck: false, placeholder: placeholder(key, DEFAULTS[key]), value: state[key], onChange: event => change(key, event.target.value) })));
|
|
23
|
+
const check = (key, label) => (React.createElement("label", { className: "ta-custom-check" },
|
|
24
|
+
React.createElement("input", { type: "checkbox", checked: state[key], onChange: event => change(key, event.target.checked) }),
|
|
25
|
+
React.createElement("span", null, label),
|
|
26
|
+
mixed.includes(key) && !state.touched.includes(key) && React.createElement("span", { className: "ta-store-field-optional" }, t('ta.auth.custom.mixed'))));
|
|
27
|
+
return (React.createElement("div", { className: `ta-custom-advanced${open ? ' ta-open' : ''}` },
|
|
28
|
+
React.createElement("button", { type: "button", className: "ta-custom-advanced-toggle", "aria-expanded": open, onClick: () => setOpen(!open) },
|
|
29
|
+
React.createElement("span", null, t('ta.auth.custom.advanced')),
|
|
30
|
+
React.createElement("span", { className: "ta-auth-note" }, t('ta.auth.custom.advancedHint')),
|
|
31
|
+
React.createElement(Icon, { icon: ChevronDown, size: 15 })),
|
|
32
|
+
open && (React.createElement("div", { className: "ta-custom-advanced-body" },
|
|
33
|
+
React.createElement("div", { className: "ta-custom-pair" },
|
|
34
|
+
number('contextWindow', t('ta.auth.custom.contextWindow')),
|
|
35
|
+
number('maxTokens', t('ta.auth.custom.maxTokens'))),
|
|
36
|
+
check('reasoning', t('ta.auth.custom.reasoning')),
|
|
37
|
+
check('images', t('ta.auth.custom.images')),
|
|
38
|
+
React.createElement("div", { className: "ta-store-field" },
|
|
39
|
+
React.createElement("span", { className: "ta-store-field-label" }, t('ta.auth.custom.headers')),
|
|
40
|
+
state.headers.map((row, index) => (React.createElement("div", { key: index, className: "ta-custom-header" },
|
|
41
|
+
React.createElement("input", { className: "ta-input", autoComplete: "off", spellCheck: false, "aria-label": t('ta.auth.custom.headerName'), placeholder: t('ta.auth.custom.headerName'), value: row.name, onChange: event => rows(state.headers.map((each, at) => (at === index ? { ...each, name: event.target.value, kept: false } : each))) }),
|
|
42
|
+
React.createElement("input", { className: "ta-input", type: "password", autoComplete: "new-password", spellCheck: false, "aria-label": t('ta.auth.custom.headerValue'), placeholder: row.kept ? t('ta.auth.custom.keyKept') : t('ta.auth.custom.headerValue'), value: row.value, onChange: event => rows(state.headers.map((each, at) => (at === index ? { ...each, value: event.target.value } : each))) }),
|
|
43
|
+
React.createElement("button", { type: "button", className: "ta-custom-header-remove", "aria-label": t('ta.auth.custom.removeHeader', { name: row.name || t('ta.auth.custom.headers') }), onClick: () => rows(state.headers.filter((_, at) => at !== index)) },
|
|
44
|
+
React.createElement(Icon, { icon: X, size: 14 }))))),
|
|
45
|
+
React.createElement("button", { type: "button", className: "ta-button ta-custom-fetch", onClick: () => rows([...state.headers, { name: '', value: '', kept: false }]) },
|
|
46
|
+
React.createElement(Icon, { icon: Plus, size: 14 }),
|
|
47
|
+
" ",
|
|
48
|
+
t('ta.auth.custom.addHeader')))))));
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=custom-provider-advanced.js.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { TaCustomModelOptions, TaCustomProvider, TaCustomProviderInput } from '@celljs/ta-protocol';
|
|
2
|
+
/** What the form of a model service added by its address (custom-provider-view) does with what is typed. */
|
|
3
|
+
export declare namespace CustomProviderFormUtil {
|
|
4
|
+
/** The ids typed or pasted at once: apart by commas, spaces or lines. */
|
|
5
|
+
function split(text: string): string[];
|
|
6
|
+
/** The models with those added, each once, in the order they came. */
|
|
7
|
+
function add(models: readonly string[], ids: readonly string[]): string[];
|
|
8
|
+
function toggle(models: readonly string[], id: string): string[];
|
|
9
|
+
/** The name a provider gets when none is typed: the host of its address, as ta serve gives it. */
|
|
10
|
+
function host(baseUrl: string): string;
|
|
11
|
+
type OptionKey = keyof TaCustomModelOptions;
|
|
12
|
+
/** A header in the form: one kept on ta serve shows its name alone, its value left empty keeping it. */
|
|
13
|
+
interface HeaderRow {
|
|
14
|
+
name: string;
|
|
15
|
+
value: string;
|
|
16
|
+
kept: boolean;
|
|
17
|
+
}
|
|
18
|
+
/** The advanced fields as typed: numbers as text, and what the user changed. */
|
|
19
|
+
interface Advanced {
|
|
20
|
+
contextWindow: string;
|
|
21
|
+
maxTokens: string;
|
|
22
|
+
reasoning: boolean;
|
|
23
|
+
images: boolean;
|
|
24
|
+
headers: HeaderRow[];
|
|
25
|
+
touched: OptionKey[];
|
|
26
|
+
}
|
|
27
|
+
function advanced(provider?: TaCustomProvider): Advanced;
|
|
28
|
+
/** Whether the provider has anything advanced: the section opens with it. */
|
|
29
|
+
function hasAdvanced(provider?: TaCustomProvider): boolean;
|
|
30
|
+
/** A number of tokens as typed: `200000`, `200k`, `1m`, `200,000`; null when empty, undefined when not one. */
|
|
31
|
+
function tokens(text: string): number | null | undefined;
|
|
32
|
+
/** The options to save: those the models have not alike stay as they are unless the user changed them. Throws the text of a number that is not one. */
|
|
33
|
+
function optionsOf(state: Advanced, mixed: readonly OptionKey[]): NonNullable<TaCustomProviderInput['options']>;
|
|
34
|
+
/** The headers to send and save, by name; an empty value keeps the one kept. */
|
|
35
|
+
function headersOf(state: Advanced): Record<string, string>;
|
|
36
|
+
/** What a service listed, narrowed by the words typed. */
|
|
37
|
+
function shown(fetched: readonly string[], words: string): string[];
|
|
38
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/** What the form of a model service added by its address (custom-provider-view) does with what is typed. */
|
|
2
|
+
export var CustomProviderFormUtil;
|
|
3
|
+
(function (CustomProviderFormUtil) {
|
|
4
|
+
/** The ids typed or pasted at once: apart by commas, spaces or lines. */
|
|
5
|
+
function split(text) {
|
|
6
|
+
return text
|
|
7
|
+
.split(/[\s,,]+/)
|
|
8
|
+
.map(id => id.trim())
|
|
9
|
+
.filter(Boolean);
|
|
10
|
+
}
|
|
11
|
+
CustomProviderFormUtil.split = split;
|
|
12
|
+
/** The models with those added, each once, in the order they came. */
|
|
13
|
+
function add(models, ids) {
|
|
14
|
+
return [...new Set([...models, ...ids])];
|
|
15
|
+
}
|
|
16
|
+
CustomProviderFormUtil.add = add;
|
|
17
|
+
function toggle(models, id) {
|
|
18
|
+
return models.includes(id) ? models.filter(model => model !== id) : [...models, id];
|
|
19
|
+
}
|
|
20
|
+
CustomProviderFormUtil.toggle = toggle;
|
|
21
|
+
/** The name a provider gets when none is typed: the host of its address, as ta serve gives it. */
|
|
22
|
+
function host(baseUrl) {
|
|
23
|
+
try {
|
|
24
|
+
return new URL(baseUrl.trim()).host;
|
|
25
|
+
}
|
|
26
|
+
catch (_a) {
|
|
27
|
+
return '';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
CustomProviderFormUtil.host = host;
|
|
31
|
+
function advanced(provider) {
|
|
32
|
+
var _a, _b;
|
|
33
|
+
const options = (_a = provider === null || provider === void 0 ? void 0 : provider.options) !== null && _a !== void 0 ? _a : {};
|
|
34
|
+
return {
|
|
35
|
+
contextWindow: options.contextWindow ? String(options.contextWindow) : '',
|
|
36
|
+
maxTokens: options.maxTokens ? String(options.maxTokens) : '',
|
|
37
|
+
reasoning: options.reasoning === true,
|
|
38
|
+
images: options.images === true,
|
|
39
|
+
headers: ((_b = provider === null || provider === void 0 ? void 0 : provider.headers) !== null && _b !== void 0 ? _b : []).map(name => ({ name, value: '', kept: true })),
|
|
40
|
+
touched: [],
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
CustomProviderFormUtil.advanced = advanced;
|
|
44
|
+
/** Whether the provider has anything advanced: the section opens with it. */
|
|
45
|
+
function hasAdvanced(provider) {
|
|
46
|
+
return !!provider && (Object.keys(provider.options).length > 0 || provider.mixed.length > 0 || provider.headers.length > 0);
|
|
47
|
+
}
|
|
48
|
+
CustomProviderFormUtil.hasAdvanced = hasAdvanced;
|
|
49
|
+
/** A number of tokens as typed: `200000`, `200k`, `1m`, `200,000`; null when empty, undefined when not one. */
|
|
50
|
+
function tokens(text) {
|
|
51
|
+
const plain = text
|
|
52
|
+
.trim()
|
|
53
|
+
.toLowerCase()
|
|
54
|
+
.replace(/[,_\s]/g, '');
|
|
55
|
+
if (!plain) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
const match = /^(\d+(?:\.\d+)?)([km]?)$/.exec(plain);
|
|
59
|
+
const value = match ? Math.round(Number(match[1]) * (match[2] === 'k' ? 1000 : match[2] === 'm' ? 1000000 : 1)) : Number.NaN;
|
|
60
|
+
return Number.isInteger(value) && value > 0 ? value : undefined;
|
|
61
|
+
}
|
|
62
|
+
CustomProviderFormUtil.tokens = tokens;
|
|
63
|
+
/** The options to save: those the models have not alike stay as they are unless the user changed them. Throws the text of a number that is not one. */
|
|
64
|
+
function optionsOf(state, mixed) {
|
|
65
|
+
const options = {};
|
|
66
|
+
const given = (key) => !mixed.includes(key) || state.touched.includes(key);
|
|
67
|
+
for (const key of ['contextWindow', 'maxTokens']) {
|
|
68
|
+
if (given(key)) {
|
|
69
|
+
const value = tokens(state[key]);
|
|
70
|
+
if (value === undefined) {
|
|
71
|
+
throw new RangeError(state[key]);
|
|
72
|
+
}
|
|
73
|
+
options[key] = value;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
for (const key of ['reasoning', 'images']) {
|
|
77
|
+
if (given(key)) {
|
|
78
|
+
options[key] = state[key];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return options;
|
|
82
|
+
}
|
|
83
|
+
CustomProviderFormUtil.optionsOf = optionsOf;
|
|
84
|
+
/** The headers to send and save, by name; an empty value keeps the one kept. */
|
|
85
|
+
function headersOf(state) {
|
|
86
|
+
const headers = {};
|
|
87
|
+
for (const row of state.headers) {
|
|
88
|
+
const name = row.name.trim();
|
|
89
|
+
if (name) {
|
|
90
|
+
headers[name] = row.value.trim();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return headers;
|
|
94
|
+
}
|
|
95
|
+
CustomProviderFormUtil.headersOf = headersOf;
|
|
96
|
+
/** What a service listed, narrowed by the words typed. */
|
|
97
|
+
function shown(fetched, words) {
|
|
98
|
+
const query = words.trim().toLowerCase();
|
|
99
|
+
return query ? fetched.filter(id => id.toLowerCase().includes(query)) : [...fetched];
|
|
100
|
+
}
|
|
101
|
+
CustomProviderFormUtil.shown = shown;
|
|
102
|
+
})(CustomProviderFormUtil || (CustomProviderFormUtil = {}));
|
|
103
|
+
//# sourceMappingURL=custom-provider-util.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type TaCustomProvider } from '@celljs/ta-protocol';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* A provider of models the user adds by its address and key, or changes: the API it speaks, where it is, its key and
|
|
5
|
+
* its models, which the service can list. ta serve keeps it in pi's models.json; the key never comes back here.
|
|
6
|
+
*/
|
|
7
|
+
export declare function CustomProviderForm({ provider, onSaved, onBack }: {
|
|
8
|
+
provider?: TaCustomProvider;
|
|
9
|
+
onSaved(saved: TaCustomProvider): void;
|
|
10
|
+
onBack(): void;
|
|
11
|
+
}): React.JSX.Element;
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { TA_CUSTOM_APIS } from '@celljs/ta-protocol';
|
|
2
|
+
import { ArrowLeft, Check, Download, ShieldCheck, Trash2, X } from 'lucide-react';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { useNotices, useWorkbench } from '../hooks.js';
|
|
5
|
+
import { useT } from '../i18n/use-t.js';
|
|
6
|
+
import { BusyMark, useBusy } from './busy.js';
|
|
7
|
+
import { Callout } from './callout.js';
|
|
8
|
+
import { CustomProviderAdvanced } from './custom-provider-advanced.js';
|
|
9
|
+
import { CustomProviderFormUtil } from './custom-provider-util.js';
|
|
10
|
+
import { Icon, IconButton } from './icon.js';
|
|
11
|
+
const API_WORDS = {
|
|
12
|
+
'openai-completions': 'ta.auth.custom.apiOpenai',
|
|
13
|
+
'openai-responses': 'ta.auth.custom.apiResponses',
|
|
14
|
+
'anthropic-messages': 'ta.auth.custom.apiAnthropic',
|
|
15
|
+
'google-generative-ai': 'ta.auth.custom.apiGoogle',
|
|
16
|
+
};
|
|
17
|
+
/** What an address of each API looks like. */
|
|
18
|
+
const ADDRESSES = {
|
|
19
|
+
'openai-completions': 'https://api.example.com/v1',
|
|
20
|
+
'openai-responses': 'https://api.example.com/v1',
|
|
21
|
+
'anthropic-messages': 'https://api.example.com',
|
|
22
|
+
'google-generative-ai': 'https://generativelanguage.googleapis.com/v1beta',
|
|
23
|
+
};
|
|
24
|
+
/** A list a service gave longer than this has a box to narrow it. */
|
|
25
|
+
const FILTER_FROM = 8;
|
|
26
|
+
/**
|
|
27
|
+
* A provider of models the user adds by its address and key, or changes: the API it speaks, where it is, its key and
|
|
28
|
+
* its models, which the service can list. ta serve keeps it in pi's models.json; the key never comes back here.
|
|
29
|
+
*/
|
|
30
|
+
export function CustomProviderForm({ provider, onSaved, onBack }) {
|
|
31
|
+
var _a, _b, _c, _d, _e;
|
|
32
|
+
const t = useT();
|
|
33
|
+
const [, bench] = useWorkbench();
|
|
34
|
+
const [, notices] = useNotices();
|
|
35
|
+
const [api, setApi] = React.useState((_a = provider === null || provider === void 0 ? void 0 : provider.api) !== null && _a !== void 0 ? _a : 'openai-completions');
|
|
36
|
+
const [baseUrl, setBaseUrl] = React.useState((_b = provider === null || provider === void 0 ? void 0 : provider.baseUrl) !== null && _b !== void 0 ? _b : '');
|
|
37
|
+
const [apiKey, setApiKey] = React.useState('');
|
|
38
|
+
const [name, setName] = React.useState((_c = provider === null || provider === void 0 ? void 0 : provider.name) !== null && _c !== void 0 ? _c : '');
|
|
39
|
+
const [models, setModels] = React.useState((_d = provider === null || provider === void 0 ? void 0 : provider.models) !== null && _d !== void 0 ? _d : []);
|
|
40
|
+
const [draft, setDraft] = React.useState('');
|
|
41
|
+
const [fetched, setFetched] = React.useState();
|
|
42
|
+
const [fetchError, setFetchError] = React.useState();
|
|
43
|
+
const [words, setWords] = React.useState('');
|
|
44
|
+
const [advanced, setAdvanced] = React.useState(() => CustomProviderFormUtil.advanced(provider));
|
|
45
|
+
const [saving, runSave] = useBusy();
|
|
46
|
+
const [fetching, runFetch] = useBusy();
|
|
47
|
+
const [removing, runRemove] = useBusy();
|
|
48
|
+
const key = apiKey.trim() || undefined;
|
|
49
|
+
const typed = () => CustomProviderFormUtil.add(models, CustomProviderFormUtil.split(draft));
|
|
50
|
+
const addDraft = () => {
|
|
51
|
+
setModels(typed());
|
|
52
|
+
setDraft('');
|
|
53
|
+
};
|
|
54
|
+
const fetchModels = () => runFetch(async () => {
|
|
55
|
+
setFetchError(undefined);
|
|
56
|
+
try {
|
|
57
|
+
const ids = await bench.auth.fetchCustomModels({
|
|
58
|
+
id: provider === null || provider === void 0 ? void 0 : provider.id,
|
|
59
|
+
api,
|
|
60
|
+
baseUrl,
|
|
61
|
+
apiKey: key,
|
|
62
|
+
headers: CustomProviderFormUtil.headersOf(advanced),
|
|
63
|
+
});
|
|
64
|
+
setFetched(ids);
|
|
65
|
+
setWords('');
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
setFetched(undefined);
|
|
69
|
+
setFetchError(error instanceof Error ? error.message : String(error));
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
const save = () => runSave(async () => {
|
|
73
|
+
var _a;
|
|
74
|
+
const chosen = typed();
|
|
75
|
+
setModels(chosen);
|
|
76
|
+
setDraft('');
|
|
77
|
+
if (chosen.length === 0) {
|
|
78
|
+
notices.notify(t('ta.auth.custom.needModel'), { level: 'warning' });
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
let options;
|
|
82
|
+
try {
|
|
83
|
+
options = CustomProviderFormUtil.optionsOf(advanced, (_a = provider === null || provider === void 0 ? void 0 : provider.mixed) !== null && _a !== void 0 ? _a : []);
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
notices.notify(t('ta.auth.custom.badNumber', { value: error instanceof Error ? error.message : String(error) }), { level: 'warning' });
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
try {
|
|
90
|
+
const headers = CustomProviderFormUtil.headersOf(advanced);
|
|
91
|
+
onSaved(await bench.auth.saveCustomProvider({ id: provider === null || provider === void 0 ? void 0 : provider.id, name, api, baseUrl, apiKey: key, models: chosen, options, headers }));
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
notices.error(error);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
const remove = () => runRemove(async () => {
|
|
98
|
+
if (!provider) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const confirmed = await notices.confirm({
|
|
102
|
+
title: t('ta.auth.custom.removeConfirm', { name: provider.name }),
|
|
103
|
+
confirmLabel: t('ta.auth.custom.remove'),
|
|
104
|
+
danger: true,
|
|
105
|
+
});
|
|
106
|
+
if (confirmed) {
|
|
107
|
+
await bench.auth.removeCustomProvider(provider.id).then(onBack, error => notices.error(error));
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
const shown = fetched ? CustomProviderFormUtil.shown(fetched, words) : [];
|
|
111
|
+
return (React.createElement("div", { className: "ta-auth-flow ta-custom-flow" },
|
|
112
|
+
React.createElement("div", { className: "ta-auth-flow-head" },
|
|
113
|
+
React.createElement(IconButton, { icon: ArrowLeft, label: t('ta.auth.back'), onClick: onBack }),
|
|
114
|
+
React.createElement("span", { className: "ta-auth-flow-title" }, (_e = provider === null || provider === void 0 ? void 0 : provider.name) !== null && _e !== void 0 ? _e : t('ta.auth.custom.title')),
|
|
115
|
+
React.createElement("span", { className: "ta-auth-kind" }, t('ta.auth.custom.kind'))),
|
|
116
|
+
React.createElement("form", { className: "ta-custom-form", onSubmit: event => {
|
|
117
|
+
event.preventDefault();
|
|
118
|
+
void save();
|
|
119
|
+
} },
|
|
120
|
+
React.createElement("label", { className: "ta-store-field" },
|
|
121
|
+
React.createElement("span", { className: "ta-store-field-label" }, t('ta.auth.custom.api')),
|
|
122
|
+
React.createElement("select", { className: "ta-input ta-select", value: api, onChange: event => setApi(event.target.value) }, TA_CUSTOM_APIS.map(each => (React.createElement("option", { key: each, value: each }, t(API_WORDS[each])))))),
|
|
123
|
+
React.createElement("label", { className: "ta-store-field" },
|
|
124
|
+
React.createElement("span", { className: "ta-store-field-label" }, t('ta.auth.custom.baseUrl')),
|
|
125
|
+
React.createElement("input", { className: "ta-input", type: "url", inputMode: "url", autoComplete: "off", spellCheck: false, required: true, placeholder: ADDRESSES[api], value: baseUrl, onChange: event => setBaseUrl(event.target.value) })),
|
|
126
|
+
React.createElement("label", { className: "ta-store-field" },
|
|
127
|
+
React.createElement("span", { className: "ta-store-field-label" },
|
|
128
|
+
t('ta.auth.custom.apiKey'),
|
|
129
|
+
React.createElement("span", { className: "ta-store-field-optional" }, t('ta.auth.custom.keyOptional'))),
|
|
130
|
+
React.createElement("input", { className: "ta-input", type: "password", autoComplete: "new-password", spellCheck: false, placeholder: (provider === null || provider === void 0 ? void 0 : provider.hasKey) ? t('ta.auth.custom.keyKept') : 'sk-…', value: apiKey, onChange: event => setApiKey(event.target.value) })),
|
|
131
|
+
React.createElement("label", { className: "ta-store-field" },
|
|
132
|
+
React.createElement("span", { className: "ta-store-field-label" },
|
|
133
|
+
t('ta.auth.custom.name'),
|
|
134
|
+
React.createElement("span", { className: "ta-store-field-optional" }, t('ta.auth.custom.optional'))),
|
|
135
|
+
React.createElement("input", { className: "ta-input", autoComplete: "off", spellCheck: false, placeholder: CustomProviderFormUtil.host(baseUrl), value: name, onChange: event => setName(event.target.value) })),
|
|
136
|
+
React.createElement("div", { className: "ta-store-field" },
|
|
137
|
+
React.createElement("span", { className: "ta-store-field-label" }, t('ta.auth.custom.models')),
|
|
138
|
+
React.createElement("div", { className: "ta-custom-models" },
|
|
139
|
+
models.map(id => (React.createElement("span", { key: id, className: "ta-custom-chip" },
|
|
140
|
+
React.createElement("span", { className: "ta-custom-chip-text" }, id),
|
|
141
|
+
React.createElement("button", { type: "button", "aria-label": t('ta.auth.custom.removeModel', { id }), onClick: () => setModels(before => before.filter(model => model !== id)) },
|
|
142
|
+
React.createElement(Icon, { icon: X, size: 12 }))))),
|
|
143
|
+
React.createElement("input", { className: "ta-custom-model-input", autoComplete: "off", spellCheck: false, "aria-label": t('ta.auth.custom.models'), placeholder: models.length ? '' : t('ta.auth.custom.modelPlaceholder'), value: draft, onChange: event => setDraft(event.target.value), onBlur: addDraft, onKeyDown: event => {
|
|
144
|
+
if ((event.key === 'Enter' || event.key === ',') && !event.nativeEvent.isComposing) {
|
|
145
|
+
event.preventDefault();
|
|
146
|
+
addDraft();
|
|
147
|
+
}
|
|
148
|
+
else if (event.key === 'Backspace' && !draft && models.length) {
|
|
149
|
+
setModels(models.slice(0, -1));
|
|
150
|
+
}
|
|
151
|
+
} })),
|
|
152
|
+
React.createElement("button", { type: "button", className: `ta-button ta-custom-fetch${fetching ? ' ta-busy' : ''}`, disabled: !baseUrl.trim() || fetching, onClick: () => void fetchModels() },
|
|
153
|
+
React.createElement(BusyMark, { busy: fetching }),
|
|
154
|
+
React.createElement(Icon, { icon: Download, size: 14 }),
|
|
155
|
+
" ",
|
|
156
|
+
t('ta.auth.custom.fetch')),
|
|
157
|
+
fetchError && React.createElement(Callout, { level: "error" }, t('ta.auth.custom.fetchFailed', { message: fetchError })),
|
|
158
|
+
fetched && (React.createElement("div", { className: "ta-custom-fetched" },
|
|
159
|
+
React.createElement("span", { className: "ta-auth-note" }, fetched.length ? t('ta.auth.custom.fetched', { count: fetched.length }) : t('ta.auth.custom.fetchedNone')),
|
|
160
|
+
fetched.length > FILTER_FROM && (React.createElement("input", { className: "ta-input", placeholder: t('ta.auth.custom.filter'), value: words, onChange: event => setWords(event.target.value) })),
|
|
161
|
+
React.createElement("div", { className: "ta-custom-fetched-list" }, shown.map(id => {
|
|
162
|
+
const picked = models.includes(id);
|
|
163
|
+
return (React.createElement("button", { key: id, type: "button", className: "ta-auth-item", "aria-pressed": picked, onClick: () => setModels(before => CustomProviderFormUtil.toggle(before, id)) },
|
|
164
|
+
React.createElement("span", { className: "ta-auth-name" }, id),
|
|
165
|
+
picked && React.createElement(Icon, { icon: Check, size: 15, className: "ta-custom-picked" })));
|
|
166
|
+
}))))),
|
|
167
|
+
React.createElement(CustomProviderAdvanced, { provider: provider, state: advanced, onChange: setAdvanced }),
|
|
168
|
+
React.createElement("p", { className: "ta-store-form-note" },
|
|
169
|
+
React.createElement(Icon, { icon: ShieldCheck, size: 13 }),
|
|
170
|
+
React.createElement("span", null, t('ta.auth.custom.note'))),
|
|
171
|
+
React.createElement("div", { className: "ta-custom-actions" },
|
|
172
|
+
provider && (React.createElement("button", { type: "button", className: `ta-button ta-danger${removing ? ' ta-busy' : ''}`, disabled: removing || saving, onClick: () => void remove() },
|
|
173
|
+
React.createElement(BusyMark, { busy: removing }),
|
|
174
|
+
React.createElement(Icon, { icon: Trash2, size: 14 }),
|
|
175
|
+
" ",
|
|
176
|
+
t('ta.auth.custom.remove'))),
|
|
177
|
+
React.createElement("button", { type: "submit", className: `ta-button ta-primary${saving ? ' ta-busy' : ''}`, disabled: !baseUrl.trim() || saving || removing },
|
|
178
|
+
React.createElement(BusyMark, { busy: saving }),
|
|
179
|
+
React.createElement("span", null, t('ta.auth.custom.save')))))));
|
|
180
|
+
}
|
|
181
|
+
//# sourceMappingURL=custom-provider-view.js.map
|
|
@@ -8,14 +8,26 @@ export interface FaceProps {
|
|
|
8
8
|
working?: boolean;
|
|
9
9
|
/** A dot at its corner: green online, grey not; none without. */
|
|
10
10
|
online?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* The owner of this Ta: the close-up of its double, the dinosaur the user picked (as the account and the navigation
|
|
13
|
+
* show it), which changes with it; `face` and `seed` stand for it where the page cannot draw it.
|
|
14
|
+
*/
|
|
15
|
+
double?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Another Ta, as its double looks (TaRoomMember.look, TaFriend.look): the close-up of that dinosaur. One this page
|
|
18
|
+
* does not know is drawn by `face` and `seed`.
|
|
19
|
+
*/
|
|
20
|
+
look?: string;
|
|
11
21
|
}
|
|
12
22
|
/** One face; the eyes, cheeks and mouth are the same on every shape. */
|
|
13
|
-
export declare function Face(
|
|
23
|
+
export declare function Face(props: FaceProps): React.JSX.Element;
|
|
14
24
|
export interface GroupFaceProps {
|
|
15
25
|
/** Those of the group, the one in front first: their faces, or their ids (`seed` of {@link Face}). */
|
|
16
26
|
members: readonly {
|
|
17
27
|
face?: number;
|
|
18
28
|
seed?: string;
|
|
29
|
+
look?: string;
|
|
30
|
+
double?: boolean;
|
|
19
31
|
working?: boolean;
|
|
20
32
|
}[];
|
|
21
33
|
size: number;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { FaceUtil } from '@celljs/ta-relay/lib/common/relay-faces';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
+
import { DinoSpecies } from '../avatar/dino-species.js';
|
|
4
|
+
import { DinoFace } from './ta-avatar.js';
|
|
3
5
|
/*
|
|
4
6
|
* The faces of those who are not Ta (agents, the people of rooms), drawn from FaceUtil.art (ta-relay, which the page of
|
|
5
7
|
* web guests draws too), so that they are told apart at a glance; Ta itself keeps the dinosaur of the logo. The styles
|
|
@@ -16,7 +18,20 @@ function draw(node, key) {
|
|
|
16
18
|
return React.createElement(node.tag, { ...props, key }, ...((_a = node.children) !== null && _a !== void 0 ? _a : []).map((child, index) => draw(child, index)));
|
|
17
19
|
}
|
|
18
20
|
/** One face; the eyes, cheeks and mouth are the same on every shape. */
|
|
19
|
-
export function Face(
|
|
21
|
+
export function Face(props) {
|
|
22
|
+
if (props.double) {
|
|
23
|
+
return React.createElement(DoubleFace, { size: props.size, online: props.online });
|
|
24
|
+
}
|
|
25
|
+
const species = DinoSpecies.IDS.find(id => id === props.look);
|
|
26
|
+
return species ? React.createElement(DoubleFace, { species: species, size: props.size, online: props.online }) : React.createElement(ShapeFace, { ...props });
|
|
27
|
+
}
|
|
28
|
+
/** A Ta as its double: the close-up of the dinosaur, as the account shows it; this Ta's own without `species`. */
|
|
29
|
+
function DoubleFace({ species, size, online }) {
|
|
30
|
+
return (React.createElement("span", { className: "ta-face", style: { width: size, height: size }, "aria-hidden": "true" },
|
|
31
|
+
React.createElement(DinoFace, { species: species, size: size }),
|
|
32
|
+
online !== undefined && React.createElement("i", { className: `ta-face-dot${online ? ' ta-face-on' : ''}` })));
|
|
33
|
+
}
|
|
34
|
+
function ShapeFace({ face: given, seed = '', size, working, online }) {
|
|
20
35
|
const face = FaceUtil.pick(given, seed);
|
|
21
36
|
const art = React.useMemo(() => draw(FaceUtil.art(face)), [face]);
|
|
22
37
|
return (React.createElement("span", { className: `ta-face${working ? ' ta-face-working' : ''}`, style: { width: size, height: size }, "data-face": face, "aria-hidden": "true" },
|