@micha.bigler/ui-core-micha 4.21.0 → 4.22.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/CHANGELOG.md +11 -0
- package/README.md +12 -0
- package/dist/chat/ChatComposer.js +22 -7
- package/dist/chat/ChatThread.js +6 -4
- package/dist/chat/ChatWorkspace.js +37 -7
- package/dist/chat/MarkdownReply.js +33 -2
- package/dist/chat/ModelPicker.js +4 -1
- package/dist/chat/api.js +1 -0
- package/dist/chat/kitSxRegistry.js +4 -2
- package/dist/chat/wire.js +1 -1
- package/dist/i18n/chatTranslations.js +6 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 4.22.0 - UCM-CHAT-9
|
|
4
|
+
|
|
5
|
+
Chat pieces for the DCM-CHAT-16 server data; without that data nothing changes. `ChatWorkspace` reads the per-user
|
|
6
|
+
period limit (`api.getLimit()`, `GET <apiBase>limit/`; a missing route counts as no limit) and passes it to
|
|
7
|
+
`ChatComposer`'s new `usageLimit` prop: a usage meter ("<used> of <limit> USD") below the limit, and at the limit a
|
|
8
|
+
disabled composer with "Monthly/Daily limit reached" and the reset date. Answers keep their stored tool steps
|
|
9
|
+
(`turn.tool_steps`) as chips after reload. The model picker shows "≈ <cost> USD per answer" from
|
|
10
|
+
`average_cost_usd_micros`. Visible change in every app: Markdown links in answers are links now. App links
|
|
11
|
+
(same origin) go through the new `ChatWorkspace` / `MarkdownReply` prop `onNavigate(path)` when given, external http(s)
|
|
12
|
+
links open in a new tab, and every other scheme stays text as before.
|
|
13
|
+
|
|
3
14
|
## 4.21.0 - UCM-SHELL-9
|
|
4
15
|
|
|
5
16
|
`AccountPage` accepts an optional `groups` declaration (`[{ key, label, order?, tabs?, visible? }]`) that replaces the
|
package/README.md
CHANGED
|
@@ -196,6 +196,18 @@ closed for that chat until the page reloads, and another chat shows it again. `r
|
|
|
196
196
|
above the composer. Without `composerLayout` the composer is unchanged. `ChatComposer` takes the same `layout`,
|
|
197
197
|
`context` and `notice` props directly; `ModelPicker` takes `shortLabel`.
|
|
198
198
|
|
|
199
|
+
## Shared chat: limit, links, tool steps, estimates
|
|
200
|
+
|
|
201
|
+
Since 4.22.0, with django-core-micha's DCM-CHAT-16 data:
|
|
202
|
+
|
|
203
|
+
- `ChatWorkspace` shows the per-user period limit (`GET <apiBase>limit/`) as a meter in the composer and disables the
|
|
204
|
+
composer at the limit with the reset date. Without a limit, or against an older backend, the composer is unchanged.
|
|
205
|
+
- Answers show their stored tool steps after reload.
|
|
206
|
+
- The model picker adds "≈ <cost> USD per answer" when the catalogue sends `average_cost_usd_micros`.
|
|
207
|
+
- Links in answers are clickable. Pass `onNavigate={(path) => navigate(path)}` to route same-origin links through the
|
|
208
|
+
app's router, which keeps the chat panel open. External http(s) links open in a new tab, and other schemes stay text.
|
|
209
|
+
`MarkdownReply` takes the same `onNavigate`.
|
|
210
|
+
|
|
199
211
|
## Shared chat: host controls
|
|
200
212
|
|
|
201
213
|
`ChatWorkspace` (from `@micha.bigler/ui-core-micha/chat`) takes optional props for apps that put UI around the surface;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import { Box, Button, IconButton, Stack, TextField } from '@mui/material';
|
|
3
|
+
import { Box, Button, IconButton, LinearProgress, Stack, TextField, Typography } from '@mui/material';
|
|
4
4
|
import SendIcon from '@mui/icons-material/Send';
|
|
5
5
|
import StopIcon from '@mui/icons-material/Stop';
|
|
6
6
|
import CloseIcon from '@mui/icons-material/Close';
|
|
@@ -27,6 +27,7 @@ export const CHAT_COMPOSER_NOTICE_SX = { display: 'flex', alignItems: 'center',
|
|
|
27
27
|
export const CHAT_COMPOSER_NOTICE_TEXT_SX = { minWidth: 0, flex: '1 1 auto', overflow: 'hidden', whiteSpace: 'nowrap', textOverflow: 'ellipsis' };
|
|
28
28
|
export const CHAT_COMPOSER_NOTICE_ACTION_SX = { flex: '0 0 auto', minWidth: 0, p: 0.25, whiteSpace: 'nowrap' };
|
|
29
29
|
export const CHAT_COMPOSER_NOTICE_CLOSE_SX = { width: 28, height: 28, flex: '0 0 28px' };
|
|
30
|
+
export const CHAT_COMPOSER_USAGE_METER_SX = { height: 3 };
|
|
30
31
|
function CompactNotice({ notice, t }) {
|
|
31
32
|
if (!notice)
|
|
32
33
|
return null;
|
|
@@ -35,9 +36,23 @@ function CompactNotice({ notice, t }) {
|
|
|
35
36
|
return notice;
|
|
36
37
|
return (_jsxs(Box, { role: "status", sx: CHAT_COMPOSER_NOTICE_SX, children: [_jsx(Box, { component: "span", sx: CHAT_COMPOSER_NOTICE_TEXT_SX, children: details.text || details.content }), details.action ? _jsx(Button, { size: "small", color: "inherit", sx: CHAT_COMPOSER_NOTICE_ACTION_SX, onClick: details.onAction, children: details.action }) : null, _jsx(IconButton, { "aria-label": t('Chat.dismissNotice'), size: "small", sx: CHAT_COMPOSER_NOTICE_CLOSE_SX, onClick: details.onDismiss, children: _jsx(CloseIcon, { fontSize: "small" }) })] }));
|
|
37
38
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
function UsageLimit({ usageLimit, t, language }) {
|
|
40
|
+
if (!usageLimit)
|
|
41
|
+
return null;
|
|
42
|
+
const format = (micros) => new Intl.NumberFormat(language, { minimumFractionDigits: 2, maximumFractionDigits: 2 }).format(micros / 1000000);
|
|
43
|
+
const reached = usageLimit.usedUsdMicros >= usageLimit.limitUsdMicros;
|
|
44
|
+
const date = new Date(usageLimit.resetsAt);
|
|
45
|
+
const resetDate = Number.isNaN(date.getTime()) ? usageLimit.resetsAt : new Intl.DateTimeFormat(language, { dateStyle: 'medium' }).format(date);
|
|
46
|
+
const usageText = t('Chat.limitUsage', { used: format(usageLimit.usedUsdMicros), limit: format(usageLimit.limitUsdMicros) });
|
|
47
|
+
return _jsxs(Stack, { spacing: 0.5, children: [reached
|
|
48
|
+
? _jsxs(_Fragment, { children: [_jsx(Typography, { variant: "caption", color: "text.secondary", children: t(`Chat.limitReached.${usageLimit.period}`) }), _jsx(Typography, { variant: "caption", color: "text.secondary", children: t('Chat.limitResets', { date: resetDate }) })] })
|
|
49
|
+
: _jsx(Typography, { variant: "caption", color: "text.secondary", children: usageText }), _jsx(LinearProgress, { variant: "determinate", "aria-label": usageText, value: reached ? 100 : Math.min(100, (usageLimit.usedUsdMicros / usageLimit.limitUsdMicros) * 100), sx: CHAT_COMPOSER_USAGE_METER_SX })] });
|
|
50
|
+
}
|
|
51
|
+
export function ChatComposer({ value = '', onChange, onSend, onStop, running = false, archived = false, connected = true, inputRef, sx, actions, layout = 'standard', context, notice, usageLimit = null }) {
|
|
52
|
+
const { t, i18n } = useTranslation();
|
|
53
|
+
const limitReached = Boolean(usageLimit && usageLimit.usedUsdMicros >= usageLimit.limitUsdMicros);
|
|
54
|
+
const blocked = archived || !connected || limitReached;
|
|
55
|
+
const language = typeof (i18n === null || i18n === void 0 ? void 0 : i18n.language) === 'string' ? i18n.language.split('_')[0] || undefined : undefined;
|
|
41
56
|
const canSend = !running && !blocked && value.trim().length > 0;
|
|
42
57
|
const submit = () => { if (canSend)
|
|
43
58
|
onSend === null || onSend === void 0 ? void 0 : onSend(); };
|
|
@@ -49,9 +64,9 @@ export function ChatComposer({ value = '', onChange, onSend, onStop, running = f
|
|
|
49
64
|
}
|
|
50
65
|
};
|
|
51
66
|
if (layout === 'compact')
|
|
52
|
-
return (_jsxs(Stack, { sx: sx ? [CHAT_COMPOSER_COMPACT_ROOT_SX, sx] : CHAT_COMPOSER_COMPACT_ROOT_SX, children: [_jsx(CompactNotice, { notice: notice, t: t }), _jsxs(Stack, { direction: "row", alignItems: "center", sx: CHAT_COMPOSER_CONTEXT_ROW_SX, children: [_jsx(Box, { sx: CHAT_COMPOSER_CONTEXT_SX, children: context }), actions ? _jsx(Box, { sx: CHAT_COMPOSER_CONTEXT_ACTIONS_SX, children: actions }) : null] }), _jsxs(Stack, { direction: "row", alignItems: "flex-end", sx: CHAT_COMPOSER_INPUT_ROW_SX, children: [_jsx(TextField, { multiline: true, maxRows: 5, variant: "outlined", sx: CHAT_COMPOSER_COMPACT_FIELD_SX, size: "small", value: value, inputRef: inputRef, disabled: blocked, placeholder: t('Chat.message'), slotProps: { htmlInput: { 'aria-label': t('Chat.message') } }, onChange: (event) => onChange === null || onChange === void 0 ? void 0 : onChange(event.target.value), onKeyDown: handleKeyDown }), running
|
|
67
|
+
return (_jsxs(Stack, { sx: sx ? [CHAT_COMPOSER_COMPACT_ROOT_SX, sx] : CHAT_COMPOSER_COMPACT_ROOT_SX, children: [_jsx(CompactNotice, { notice: notice, t: t }), _jsx(UsageLimit, { usageLimit: usageLimit, t: t, language: language }), _jsxs(Stack, { direction: "row", alignItems: "center", sx: CHAT_COMPOSER_CONTEXT_ROW_SX, children: [_jsx(Box, { sx: CHAT_COMPOSER_CONTEXT_SX, children: context }), actions ? _jsx(Box, { sx: CHAT_COMPOSER_CONTEXT_ACTIONS_SX, children: actions }) : null] }), _jsxs(Stack, { direction: "row", alignItems: "flex-end", sx: CHAT_COMPOSER_INPUT_ROW_SX, children: [_jsx(TextField, { multiline: true, maxRows: 5, variant: "outlined", sx: CHAT_COMPOSER_COMPACT_FIELD_SX, size: "small", value: value, inputRef: inputRef, disabled: blocked, placeholder: t('Chat.message'), slotProps: { htmlInput: { 'aria-label': t('Chat.message') } }, onChange: (event) => onChange === null || onChange === void 0 ? void 0 : onChange(event.target.value), onKeyDown: handleKeyDown }), running
|
|
53
68
|
? _jsx(IconButton, { "aria-label": t('Chat.stopAnswer'), title: t('Chat.stopAnswer'), sx: CHAT_COMPOSER_ACTION_SX, onClick: onStop, children: _jsx(StopIcon, {}) })
|
|
54
69
|
: _jsx(IconButton, { "aria-label": t('Chat.send'), sx: CHAT_COMPOSER_SEND_SX, onClick: submit, disabled: !canSend, children: _jsx(SendIcon, { fontSize: "small" }) })] })] }));
|
|
55
|
-
return (_jsxs(Stack, { direction: "row", alignItems: "flex-end", flexWrap: "wrap", gap: 1, sx: Object.assign({ p: { xs: 1, md: 2 }, borderTop: 1, borderColor: 'divider' }, sx), children: [_jsx(TextField, { multiline: true, maxRows: 6, sx: CHAT_COMPOSER_INPUT_SX, size: "small", value: value, inputRef: inputRef, disabled: blocked, placeholder: t('Chat.message'), slotProps: { htmlInput: { 'aria-label': t('Chat.message') } }, onChange: (event) => onChange === null || onChange === void 0 ? void 0 : onChange(event.target.value), onKeyDown: handleKeyDown }), actions ? _jsx(Stack, { direction: "row", alignItems: "flex-end", children: actions }) : null, running ? _jsx(Button, { variant: "outlined", onClick: onStop, children: t('Chat.stop') }) : null, _jsx(Button, { variant: "contained", onClick: submit, disabled: !canSend, children: t('Chat.send') })] }));
|
|
70
|
+
return (_jsxs(Stack, { direction: "row", alignItems: "flex-end", flexWrap: "wrap", gap: 1, sx: Object.assign({ p: { xs: 1, md: 2 }, borderTop: 1, borderColor: 'divider' }, sx), children: [usageLimit ? _jsx(Stack, { flexBasis: "100%", children: _jsx(UsageLimit, { usageLimit: usageLimit, t: t, language: language }) }) : null, _jsx(TextField, { multiline: true, maxRows: 6, sx: CHAT_COMPOSER_INPUT_SX, size: "small", value: value, inputRef: inputRef, disabled: blocked, placeholder: t('Chat.message'), slotProps: { htmlInput: { 'aria-label': t('Chat.message') } }, onChange: (event) => onChange === null || onChange === void 0 ? void 0 : onChange(event.target.value), onKeyDown: handleKeyDown }), actions ? _jsx(Stack, { direction: "row", alignItems: "flex-end", children: actions }) : null, running ? _jsx(Button, { variant: "outlined", onClick: onStop, children: t('Chat.stop') }) : null, _jsx(Button, { variant: "contained", onClick: submit, disabled: !canSend, children: t('Chat.send') })] }));
|
|
56
71
|
}
|
|
57
72
|
export default ChatComposer;
|
package/dist/chat/ChatThread.js
CHANGED
|
@@ -6,6 +6,7 @@ import MarkdownReply from './MarkdownReply';
|
|
|
6
6
|
export const CHAT_THREAD_TOOL_CHIP_SX = { alignSelf: 'flex-start' };
|
|
7
7
|
export const CHAT_THREAD_NOTICE_SX = { mb: 2 };
|
|
8
8
|
export const CHAT_THREAD_TRIMMED_SX = { mb: 1.5 };
|
|
9
|
+
export const CHAT_THREAD_TOOL_STEPS_SX = { alignItems: 'flex-start' };
|
|
9
10
|
const selectionLine = (turn, t) => [turn.model, turn.effort && t(`Chat.effort.${turn.effort}`)].filter(Boolean).join(' · ');
|
|
10
11
|
const sameSelection = (a, b) => a.driver === b.driver && a.model === b.model && a.effort === b.effort;
|
|
11
12
|
function SourceChips({ sources }) {
|
|
@@ -14,8 +15,9 @@ function SourceChips({ sources }) {
|
|
|
14
15
|
return null;
|
|
15
16
|
return (_jsx(Stack, { direction: "row", flexWrap: "wrap", gap: 0.75, role: "list", "aria-label": t('Chat.sources'), children: sources.map((source, index) => (_jsx(Tooltip, { title: source.reference || '', describeChild: true, children: _jsx(Chip, { role: "listitem", size: "small", variant: "outlined", label: source.label }) }, `${source.label}-${index}`))) }));
|
|
16
17
|
}
|
|
17
|
-
function Answer({ turn, tool, onRetry, chat, renderAnswerExtra, usageToTokens }) {
|
|
18
|
+
function Answer({ turn, tool, onRetry, chat, renderAnswerExtra, usageToTokens, onNavigate }) {
|
|
18
19
|
var _a;
|
|
20
|
+
var _b;
|
|
19
21
|
const { t, i18n } = useTranslation();
|
|
20
22
|
const generating = turn.state === 'generating';
|
|
21
23
|
const failed = ['failed', 'cancelled'].includes(turn.state) && turn.error_code;
|
|
@@ -27,13 +29,13 @@ function Answer({ turn, tool, onRetry, chat, renderAnswerExtra, usageToTokens })
|
|
|
27
29
|
}
|
|
28
30
|
return selectionLine(turn, t);
|
|
29
31
|
};
|
|
30
|
-
return (_jsxs(Stack, { spacing: 1, "aria-busy": generating, children: [turn.assistant_text ? _jsx(MarkdownReply, { text: turn.assistant_text }) : null, generating && !turn.assistant_text && !tool ? _jsx(Typography, { variant: "body2", color: "text.secondary", children: t('Chat.typing') }) : null, generating && tool ? _jsx(Chip, { size: "small", color: "primary", variant: "outlined", label: tool.label, sx: CHAT_THREAD_TOOL_CHIP_SX }) : null, _jsx(SourceChips, { sources: turn.sources }), !generating && replyCaption(turn) ? _jsx(Typography, { variant: "caption", color: "text.secondary", children: replyCaption(turn) }) : null, renderAnswerExtra ? _jsx(React.Fragment, { children: renderAnswerExtra({ turn, chat, appFrames: (
|
|
32
|
+
return (_jsxs(Stack, { spacing: 1, "aria-busy": generating, children: [turn.assistant_text ? _jsx(MarkdownReply, { text: turn.assistant_text, onNavigate: onNavigate }) : null, generating && !turn.assistant_text && !tool ? _jsx(Typography, { variant: "body2", color: "text.secondary", children: t('Chat.typing') }) : null, generating && tool ? _jsx(Chip, { size: "small", color: "primary", variant: "outlined", label: tool.label, sx: CHAT_THREAD_TOOL_CHIP_SX }) : null, !generating && ((_a = turn.tool_steps) === null || _a === void 0 ? void 0 : _a.length) ? _jsx(Stack, { direction: "row", flexWrap: "wrap", gap: 0.75, role: "list", "aria-label": t('Chat.toolSteps'), sx: CHAT_THREAD_TOOL_STEPS_SX, children: turn.tool_steps.map((step, index) => _jsx(Chip, { role: "listitem", size: "small", variant: "outlined", label: step.label, sx: CHAT_THREAD_TOOL_CHIP_SX }, `${step.name || step.label}-${index}`)) }) : null, _jsx(SourceChips, { sources: turn.sources }), !generating && replyCaption(turn) ? _jsx(Typography, { variant: "caption", color: "text.secondary", children: replyCaption(turn) }) : null, renderAnswerExtra ? _jsx(React.Fragment, { children: renderAnswerExtra({ turn, chat, appFrames: (_b = turn.appFrames) !== null && _b !== void 0 ? _b : [] }) }, chat === null || chat === void 0 ? void 0 : chat.id) : null, turn.state === 'interrupted' ? (_jsxs(Stack, { direction: "row", alignItems: "center", gap: 1, children: [_jsx(Chip, { size: "small", color: "warning", label: t('Chat.interrupted') }), onRetry ? _jsx(Button, { size: "small", onClick: () => onRetry(turn), children: t('Chat.retry') }) : null] })) : null, failed ? (_jsx(Alert, { severity: "error", action: onRetry ? _jsx(Button, { color: "inherit", size: "small", onClick: () => onRetry(turn), children: t('Chat.retry') }) : null, children: t('Chat.answerIncomplete') })) : null] }));
|
|
31
33
|
}
|
|
32
34
|
/**
|
|
33
35
|
* The turns of one chat. The streaming answer is simply the last turn in state `generating`; the caller keeps its text
|
|
34
36
|
* up to date. `notice` is a connection or limit message shown under the last turn. `readOnly` (an archived chat) hides Retry.
|
|
35
37
|
*/
|
|
36
|
-
export function ChatThread({ turns = [], tool = null, notice = null, hasOlder = false, olderBusy = false, onLoadOlder, onRetry, readOnly = false, sx, chat, renderAnswerExtra, trimmedCount, summary = null, usageToTokens }) {
|
|
38
|
+
export function ChatThread({ turns = [], tool = null, notice = null, hasOlder = false, olderBusy = false, onLoadOlder, onRetry, readOnly = false, sx, chat, renderAnswerExtra, trimmedCount, summary = null, usageToTokens, onNavigate }) {
|
|
37
39
|
var _a, _b;
|
|
38
40
|
const { t } = useTranslation();
|
|
39
41
|
const end = useRef(null);
|
|
@@ -79,7 +81,7 @@ export function ChatThread({ turns = [], tool = null, notice = null, hasOlder =
|
|
|
79
81
|
}, role: "log", "aria-live": "polite", "aria-label": t('Chat.thread'), sx: Object.assign({ minHeight: 0, flex: 1, overflowY: 'auto', p: { xs: 1.5, md: 2.5 } }, sx), children: [hasOlder ? (_jsx(Box, { sx: { textAlign: 'center', mb: 2 }, children: _jsx(Button, { size: "small", onClick: loadOlder, disabled: olderBusy, children: t('Chat.loadOlder') }) })) : null, turns.length === 0 ? (_jsx(Typography, { variant: "h6", color: "text.secondary", align: "center", sx: { mt: 6 }, children: t('Chat.emptyTitle') })) : null, turns.map((turn, index) => {
|
|
80
82
|
var _a;
|
|
81
83
|
const previous = turns[index - 1];
|
|
82
|
-
return (_jsxs(Box, { sx: { mb: 3 }, children: [!summaryRendered && summaryVisible && turn.seq > summary.up_to_seq ? (summaryRendered = true, renderSummary()) : null, previous && !sameSelection(previous, turn) ? (_jsxs(Stack, { direction: "row", alignItems: "center", gap: 1, sx: { mb: 2, color: 'text.secondary' }, role: "separator", children: [_jsx(Box, { sx: { flex: 1, borderTop: 1, borderColor: 'divider' } }), _jsx(Typography, { variant: "caption", children: t('Chat.modelChanged', { model: selectionLine(turn, t) }) }), _jsx(Box, { sx: { flex: 1, borderTop: 1, borderColor: 'divider' } })] })) : null, _jsx(Box, { sx: { display: 'flex', justifyContent: 'flex-end', mb: 1.5 }, children: _jsx(Typography, { sx: { maxWidth: '85%', whiteSpace: 'pre-wrap', overflowWrap: 'anywhere', bgcolor: 'action.hover', borderRadius: 2, px: 1.5, py: 1 }, children: turn.user_text }) }), _jsx(Answer, { turn: turn, tool: index === turns.length - 1 ? tool : null, onRetry: readOnly ? undefined : onRetry, chat: chat, renderAnswerExtra: renderAnswerExtra, usageToTokens: usageToTokens })] }, (_a = turn.id) !== null && _a !== void 0 ? _a : index));
|
|
84
|
+
return (_jsxs(Box, { sx: { mb: 3 }, children: [!summaryRendered && summaryVisible && turn.seq > summary.up_to_seq ? (summaryRendered = true, renderSummary()) : null, previous && !sameSelection(previous, turn) ? (_jsxs(Stack, { direction: "row", alignItems: "center", gap: 1, sx: { mb: 2, color: 'text.secondary' }, role: "separator", children: [_jsx(Box, { sx: { flex: 1, borderTop: 1, borderColor: 'divider' } }), _jsx(Typography, { variant: "caption", children: t('Chat.modelChanged', { model: selectionLine(turn, t) }) }), _jsx(Box, { sx: { flex: 1, borderTop: 1, borderColor: 'divider' } })] })) : null, _jsx(Box, { sx: { display: 'flex', justifyContent: 'flex-end', mb: 1.5 }, children: _jsx(Typography, { sx: { maxWidth: '85%', whiteSpace: 'pre-wrap', overflowWrap: 'anywhere', bgcolor: 'action.hover', borderRadius: 2, px: 1.5, py: 1 }, children: turn.user_text }) }), _jsx(Answer, { turn: turn, tool: index === turns.length - 1 ? tool : null, onRetry: readOnly ? undefined : onRetry, chat: chat, renderAnswerExtra: renderAnswerExtra, usageToTokens: usageToTokens, onNavigate: onNavigate })] }, (_a = turn.id) !== null && _a !== void 0 ? _a : index));
|
|
83
85
|
}), !summaryRendered ? renderSummary() : null, trimmedCount ? _jsx(Chip, { size: "small", variant: "outlined", label: t(trimmedCount === 1 ? 'Chat.historyTrimmed_one' : 'Chat.historyTrimmed_other', { count: trimmedCount }), sx: CHAT_THREAD_TRIMMED_SX }) : null, notice ? (_jsx(Alert, { severity: notice.severity || 'warning', sx: CHAT_THREAD_NOTICE_SX, action: notice.action ? _jsx(Button, { color: "inherit", size: "small", onClick: notice.action.onClick, children: notice.action.label }) : null, children: notice.text })) : null, _jsx("div", { ref: end })] }));
|
|
84
86
|
}
|
|
85
87
|
export default ChatThread;
|
|
@@ -63,7 +63,7 @@ const appendDelta = (turns, text) => {
|
|
|
63
63
|
* calls; every function not given keeps its default), `scope` (passed when creating a chat),
|
|
64
64
|
* `preloadedChats` (optional active-list response `{ scope, results, next }` already loaded for that exact scope), `sx`.
|
|
65
65
|
*/
|
|
66
|
-
export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, preloadedChats, sx, unavailableReasonText, sidePanel, sidePanelLabel, renderAnswerExtra, renderComposerExtra, composerLayout = 'standard', renderComposerContext, onAppFrame, activeChatId, onActiveChatChange, composerPrefill, getSendContext, sendRequest, onSendRequestHandled, layout = 'viewport', compactBelow = 720, tokenBalance = null, usageToTokens, longChatTokens = 40000 }) {
|
|
66
|
+
export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, preloadedChats, sx, unavailableReasonText, sidePanel, sidePanelLabel, renderAnswerExtra, renderComposerExtra, composerLayout = 'standard', renderComposerContext, onAppFrame, onNavigate, activeChatId, onActiveChatChange, composerPrefill, getSendContext, sendRequest, onSendRequestHandled, layout = 'viewport', compactBelow = 720, tokenBalance = null, usageToTokens, longChatTokens = 40000 }) {
|
|
67
67
|
var _a;
|
|
68
68
|
const { t } = useTranslation();
|
|
69
69
|
const theme = useTheme();
|
|
@@ -89,6 +89,7 @@ export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, preloa
|
|
|
89
89
|
const api = useMemo(() => createChatApi(apiOverrides, { apiBase }), [apiOverrides, apiBase]);
|
|
90
90
|
const [catalogue, setCatalogue] = useState({ entries: [], default: null });
|
|
91
91
|
const [summary, setSummary] = useState(null);
|
|
92
|
+
const [usageLimit, setUsageLimit] = useState(null);
|
|
92
93
|
// The chat the current catalogue was requested for: a general catalogue must never drive the stored selection of a chat.
|
|
93
94
|
const [catalogueChatId, setCatalogueChatId] = useState(null);
|
|
94
95
|
const [chats, setChats] = useState([]);
|
|
@@ -131,6 +132,7 @@ export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, preloa
|
|
|
131
132
|
const [dismissedComposerNotices, setDismissedComposerNotices] = useState(() => new Set());
|
|
132
133
|
const running = turns.some(isGenerating);
|
|
133
134
|
const isArchived = Boolean(chat === null || chat === void 0 ? void 0 : chat.archived_at);
|
|
135
|
+
const usageLimitReached = Boolean(usageLimit && usageLimit.usedUsdMicros >= usageLimit.limitUsdMicros);
|
|
134
136
|
const selection = (chat === null || chat === void 0 ? void 0 : chat.selection) || catalogue.default;
|
|
135
137
|
const activeEntry = catalogue.entries.find((entry) => entry.id === (selection === null || selection === void 0 ? void 0 : selection.entry));
|
|
136
138
|
const latestUsageTurn = [...turns].reverse().find((turn) => turn.usage);
|
|
@@ -165,7 +167,31 @@ export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, preloa
|
|
|
165
167
|
const shownChatId = useRef(null);
|
|
166
168
|
// Bumped on every scope change so that a list response of the previous scope is dropped.
|
|
167
169
|
const scopeVersion = useRef(0);
|
|
168
|
-
|
|
170
|
+
const limitRequest = useRef(0);
|
|
171
|
+
const refreshLimit = useCallback(async (chatId) => {
|
|
172
|
+
const request = ++limitRequest.current;
|
|
173
|
+
const version = scopeVersion.current;
|
|
174
|
+
const current = () => request === limitRequest.current && version === scopeVersion.current
|
|
175
|
+
&& (chatId === undefined || String(shownChatId.current) === String(chatId));
|
|
176
|
+
try {
|
|
177
|
+
const data = await api.getLimit();
|
|
178
|
+
if (!current())
|
|
179
|
+
return;
|
|
180
|
+
if (!data || !['day', 'month'].includes(data.period)
|
|
181
|
+
|| !Number.isInteger(data.limit_usd_micros) || data.limit_usd_micros < 0
|
|
182
|
+
|| !Number.isInteger(data.used_usd_micros) || data.used_usd_micros < 0
|
|
183
|
+
|| typeof data.resets_at !== 'string') {
|
|
184
|
+
setUsageLimit(null);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
setUsageLimit({ period: data.period, limitUsdMicros: data.limit_usd_micros, usedUsdMicros: data.used_usd_micros, resetsAt: data.resets_at });
|
|
188
|
+
}
|
|
189
|
+
catch (_a) {
|
|
190
|
+
if (current())
|
|
191
|
+
setUsageLimit(null);
|
|
192
|
+
}
|
|
193
|
+
}, [api]);
|
|
194
|
+
useEffect(() => { scopeVersion.current += 1; limitRequest.current += 1; setUsageLimit(null); setChat(null); setListsLoaded(false); appliedId.current = undefined; unloadableIds.current.clear(); }, [scope]);
|
|
169
195
|
const loadLists = useCallback(async ({ initial = false, preloaded } = {}) => {
|
|
170
196
|
const version = scopeVersion.current;
|
|
171
197
|
// Without a scope the api is called exactly as before the scope existed.
|
|
@@ -208,6 +234,7 @@ export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, preloa
|
|
|
208
234
|
setUnavailableReason(state.reason || null);
|
|
209
235
|
return;
|
|
210
236
|
}
|
|
237
|
+
refreshLimit();
|
|
211
238
|
Promise.all([catalogueRequest, listsRequest]).then(([entries, lists]) => {
|
|
212
239
|
if (!live || lists === undefined)
|
|
213
240
|
return;
|
|
@@ -225,7 +252,7 @@ export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, preloa
|
|
|
225
252
|
.catch(() => { if (live)
|
|
226
253
|
setStatus('error'); });
|
|
227
254
|
return () => { live = false; };
|
|
228
|
-
}, [api, loadLists, scope]);
|
|
255
|
+
}, [api, loadLists, refreshLimit, scope]);
|
|
229
256
|
useEffect(() => { if ((chat === null || chat === void 0 ? void 0 : chat.id) !== undefined)
|
|
230
257
|
refreshCatalogue(chat.id); }, [chat === null || chat === void 0 ? void 0 : chat.id, refreshCatalogue]);
|
|
231
258
|
useEffect(() => { if (pickerOpen)
|
|
@@ -331,6 +358,7 @@ export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, preloa
|
|
|
331
358
|
setTool(null);
|
|
332
359
|
setTurns((current) => { const pending = current.findLast(isGenerating); return settleTurn(current, Object.assign(Object.assign({}, frame.turn), { appFrames: (pending === null || pending === void 0 ? void 0 : pending.appFrames) || [] })); });
|
|
333
360
|
refreshCatalogue(chatId);
|
|
361
|
+
refreshLimit(chatId);
|
|
334
362
|
if (frame.turn.error_code === 'quota_exceeded')
|
|
335
363
|
setProblem('quota_exceeded');
|
|
336
364
|
}
|
|
@@ -340,8 +368,10 @@ export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, preloa
|
|
|
340
368
|
setProblem(frame.code);
|
|
341
369
|
if (frame.code === 'unavailable')
|
|
342
370
|
setUnavailableReason(frame.reason || unavailableReason);
|
|
371
|
+
if (frame.code === 'quota_exceeded')
|
|
372
|
+
refreshLimit(chatId);
|
|
343
373
|
}
|
|
344
|
-
}, [chat === null || chat === void 0 ? void 0 : chat.id, api, refreshCatalogue]);
|
|
374
|
+
}, [chat === null || chat === void 0 ? void 0 : chat.id, api, refreshCatalogue, refreshLimit]);
|
|
345
375
|
const onOpen = useCallback((chatId) => { connectedChatId.current = String(chatId); setOpenedOnce(true); setProblem((current) => (current === 'connection_lost' ? null : current)); }, []);
|
|
346
376
|
const onClose = useCallback(({ reason, retrying }) => { connectedChatId.current = null; if (!retrying)
|
|
347
377
|
setProblem(reason); }, []);
|
|
@@ -527,7 +557,7 @@ export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, preloa
|
|
|
527
557
|
session_ended: 'Chat.sessionEnded', access_lost: 'Chat.accessLost', rate_limited: 'Chat.rateLimited',
|
|
528
558
|
load_error: 'Chat.loadError', action_error: 'Chat.actionError',
|
|
529
559
|
};
|
|
530
|
-
if (problem === 'quota_exceeded') {
|
|
560
|
+
if (problem === 'quota_exceeded' && !usageLimitReached) {
|
|
531
561
|
return { text: t('Chat.usageLimit', { model: (activeEntry === null || activeEntry === void 0 ? void 0 : activeEntry.label) || (activeEntry === null || activeEntry === void 0 ? void 0 : activeEntry.model) || '' }), action: { label: t('Chat.changeModel'), onClick: () => setPickerOpen(true) } };
|
|
532
562
|
}
|
|
533
563
|
if (problem === 'connection_lost')
|
|
@@ -552,9 +582,9 @@ export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, preloa
|
|
|
552
582
|
if (unavailable) {
|
|
553
583
|
return (_jsx(Stack, { alignItems: "center", justifyContent: "center", spacing: 1, sx: Object.assign({ minHeight: 320, p: 3, textAlign: 'center' }, sx), children: _jsx(Typography, { color: "text.secondary", children: unavailableText || t('Chat.notAvailableHere') }) }));
|
|
554
584
|
}
|
|
555
|
-
return (_jsxs(Box, { ref: rootRef, sx: Object.assign({ display: 'grid', gridTemplateColumns: narrow ? 'minmax(0, 1fr)' : `minmax(240px, 320px) minmax(0, 1fr)${chat && sidePanel ? ' minmax(240px, 320px)' : ''}`, height: '100%', minHeight: 480, border: 1, borderColor: 'divider', borderRadius: 1, overflow: 'hidden', bgcolor: 'background.paper' }, sx), children: [narrow ? null : _jsx(Box, { sx: { borderRight: 1, borderColor: 'divider', minHeight: 0 }, children: list }), _jsxs(Stack, { sx: { minWidth: 0, minHeight: 0 }, children: [_jsxs(Stack, { direction: "row", alignItems: "center", gap: 1, sx: { px: 1.5, py: 0.5, borderBottom: 1, borderColor: 'divider', minHeight: 56 }, children: [narrow ? _jsx(Button, { color: "inherit", onClick: () => setListOpen(true), children: t('Chat.chats') }) : null, _jsx(Typography, { noWrap: true, sx: { flex: 1, fontWeight: 600 }, children: chat ? (chat.title || t('Chat.untitled')) : '' }), socket.status === 'connecting' && openedOnce ? _jsx(Chip, { size: "small", color: "warning", variant: "outlined", label: t('Chat.reconnecting') }) : null, isArchived ? _jsx(Chip, { size: "small", label: t('Chat.archived') }) : null, isArchived ? _jsx(Button, { size: "small", onClick: () => updateChat(chat, { archived: false }), children: t('Chat.restore') }) : null, chat && sidePanel && narrow ? _jsx(Button, { color: "inherit", onClick: () => setSidePanelOpen(true), children: sidePanelLabel || t('Chat.sidePanel') }) : null] }), chat ? (_jsxs(_Fragment, { children: [_jsx(ChatThread, { turns: turns, chat: chat, renderAnswerExtra: answerExtra, trimmedCount: trimmedCount, tool: tool, notice: noticeFor(), hasOlder: Boolean(olderCursor), olderBusy: olderBusy, onLoadOlder: loadOlder, onRetry: retry, readOnly: isArchived, summary: summary, usageToTokens: usageToTokens }), isArchived ? _jsx(Typography, { variant: "caption", color: "text.secondary", sx: { px: 2, pb: 1 }, children: t('Chat.archivedReadOnly') }) : null, renderComposerExtra ? _jsx(Box, { children: renderComposerExtra({ chat }) }, chat.id) : null, composerLayout !== 'compact' && longChat ? _jsx(Alert, { severity: "info", action: _jsx(Button, { color: "inherit", size: "small", onClick: createChat, children: t('Chat.newConversation') }), children: t('Chat.longChat') }) : null, _jsx(ChatComposer, { layout: composerLayout, context: composerLayout === 'compact' ? renderComposerContext === null || renderComposerContext === void 0 ? void 0 : renderComposerContext({ chat }) : undefined, notice: composerLayout === 'compact' && longChat && !dismissedComposerNotices.has(`${chat.id}:long-chat`) ? {
|
|
585
|
+
return (_jsxs(Box, { ref: rootRef, sx: Object.assign({ display: 'grid', gridTemplateColumns: narrow ? 'minmax(0, 1fr)' : `minmax(240px, 320px) minmax(0, 1fr)${chat && sidePanel ? ' minmax(240px, 320px)' : ''}`, height: '100%', minHeight: 480, border: 1, borderColor: 'divider', borderRadius: 1, overflow: 'hidden', bgcolor: 'background.paper' }, sx), children: [narrow ? null : _jsx(Box, { sx: { borderRight: 1, borderColor: 'divider', minHeight: 0 }, children: list }), _jsxs(Stack, { sx: { minWidth: 0, minHeight: 0 }, children: [_jsxs(Stack, { direction: "row", alignItems: "center", gap: 1, sx: { px: 1.5, py: 0.5, borderBottom: 1, borderColor: 'divider', minHeight: 56 }, children: [narrow ? _jsx(Button, { color: "inherit", onClick: () => setListOpen(true), children: t('Chat.chats') }) : null, _jsx(Typography, { noWrap: true, sx: { flex: 1, fontWeight: 600 }, children: chat ? (chat.title || t('Chat.untitled')) : '' }), socket.status === 'connecting' && openedOnce ? _jsx(Chip, { size: "small", color: "warning", variant: "outlined", label: t('Chat.reconnecting') }) : null, isArchived ? _jsx(Chip, { size: "small", label: t('Chat.archived') }) : null, isArchived ? _jsx(Button, { size: "small", onClick: () => updateChat(chat, { archived: false }), children: t('Chat.restore') }) : null, chat && sidePanel && narrow ? _jsx(Button, { color: "inherit", onClick: () => setSidePanelOpen(true), children: sidePanelLabel || t('Chat.sidePanel') }) : null] }), chat ? (_jsxs(_Fragment, { children: [_jsx(ChatThread, { turns: turns, chat: chat, renderAnswerExtra: answerExtra, trimmedCount: trimmedCount, tool: tool, notice: noticeFor(), hasOlder: Boolean(olderCursor), olderBusy: olderBusy, onLoadOlder: loadOlder, onRetry: retry, readOnly: isArchived, summary: summary, usageToTokens: usageToTokens, onNavigate: onNavigate }), isArchived ? _jsx(Typography, { variant: "caption", color: "text.secondary", sx: { px: 2, pb: 1 }, children: t('Chat.archivedReadOnly') }) : null, renderComposerExtra ? _jsx(Box, { children: renderComposerExtra({ chat }) }, chat.id) : null, composerLayout !== 'compact' && longChat ? _jsx(Alert, { severity: "info", action: _jsx(Button, { color: "inherit", size: "small", onClick: createChat, children: t('Chat.newConversation') }), children: t('Chat.longChat') }) : null, _jsx(ChatComposer, { layout: composerLayout, context: composerLayout === 'compact' ? renderComposerContext === null || renderComposerContext === void 0 ? void 0 : renderComposerContext({ chat }) : undefined, notice: composerLayout === 'compact' && longChat && !dismissedComposerNotices.has(`${chat.id}:long-chat`) ? {
|
|
556
586
|
id: 'long-chat', text: t('Chat.longChatShort'), action: t('Chat.newChat'), onAction: createChat,
|
|
557
587
|
onDismiss: () => setDismissedComposerNotices((current) => new Set(current).add(`${chat.id}:long-chat`)),
|
|
558
|
-
} : null, value: draft, onChange: setDraft, onSend: send, onStop: () => socket.send({ type: 'stop' }), running: running, archived: isArchived, connected: socket.connected, inputRef: composerInputRef, actions: _jsx(ModelPicker, { entries: catalogue.entries, selection: selection, disabled: isArchived || running || (catalogueLoading && catalogueChatId !== chat.id), open: pickerOpen, onOpenChange: setPickerOpen, onChange: (next) => updateChat(chat, { selection: next }), sheet: narrow, balance: tokenBalance, longChat: longChat, onNewChat: createChat, shortLabel: composerLayout === 'compact' }) })] })) : (_jsxs(Stack, { alignItems: "center", justifyContent: "center", spacing: 2, sx: { flex: 1, p: 3 }, children: [_jsx(Typography, { color: "text.secondary", align: "center", children: t('Chat.selectChat') }), _jsx(Button, { variant: "contained", onClick: createChat, children: t('Chat.newChat') })] }))] }), chat && sidePanel && !narrow ? _jsx(Box, { sx: { borderLeft: 1, borderColor: 'divider', minHeight: 0, overflow: 'auto' }, children: sidePanel(chat) }, chat.id) : null, narrow && chat && sidePanel ? _jsx(Drawer, { anchor: "right", open: sidePanelOpen, onClose: () => setSidePanelOpen(false), slotProps: { paper: { 'aria-label': sidePanelLabel || t('Chat.sidePanel') } }, children: _jsx(Box, { children: sidePanel(chat) }, chat.id) }) : null, narrow ? _jsx(Drawer, { open: listOpen, onClose: () => setListOpen(false), slotProps: { paper: { sx: { width: 'min(320px, 86vw)' } } }, children: list }) : null] }));
|
|
588
|
+
} : null, value: draft, onChange: setDraft, onSend: send, onStop: () => socket.send({ type: 'stop' }), running: running, archived: isArchived, connected: socket.connected, inputRef: composerInputRef, usageLimit: usageLimit, actions: _jsx(ModelPicker, { entries: catalogue.entries, selection: selection, disabled: isArchived || running || (catalogueLoading && catalogueChatId !== chat.id), open: pickerOpen, onOpenChange: setPickerOpen, onChange: (next) => updateChat(chat, { selection: next }), sheet: narrow, balance: tokenBalance, longChat: longChat, onNewChat: createChat, shortLabel: composerLayout === 'compact' }) })] })) : (_jsxs(Stack, { alignItems: "center", justifyContent: "center", spacing: 2, sx: { flex: 1, p: 3 }, children: [_jsx(Typography, { color: "text.secondary", align: "center", children: t('Chat.selectChat') }), _jsx(Button, { variant: "contained", onClick: createChat, children: t('Chat.newChat') })] }))] }), chat && sidePanel && !narrow ? _jsx(Box, { sx: { borderLeft: 1, borderColor: 'divider', minHeight: 0, overflow: 'auto' }, children: sidePanel(chat) }, chat.id) : null, narrow && chat && sidePanel ? _jsx(Drawer, { anchor: "right", open: sidePanelOpen, onClose: () => setSidePanelOpen(false), slotProps: { paper: { 'aria-label': sidePanelLabel || t('Chat.sidePanel') } }, children: _jsx(Box, { children: sidePanel(chat) }, chat.id) }) : null, narrow ? _jsx(Drawer, { open: listOpen, onClose: () => setListOpen(false), slotProps: { paper: { sx: { width: 'min(320px, 86vw)' } } }, children: list }) : null] }));
|
|
559
589
|
}
|
|
560
590
|
export default ChatWorkspace;
|
|
@@ -7,12 +7,43 @@ import remarkGfm from 'remark-gfm';
|
|
|
7
7
|
export const MARKDOWN_LIMIT = 200000;
|
|
8
8
|
const allowed = ['p', 'br', 'hr', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'strong', 'em', 'del', 'ul', 'ol', 'li', 'blockquote', 'code', 'pre', 'table', 'thead', 'tbody', 'tr', 'th', 'td', 'a', 'img'];
|
|
9
9
|
const plainText = (children) => (Array.isArray(children) ? children : [children]).map((child) => typeof child === 'string' ? child : '').join('');
|
|
10
|
-
function
|
|
10
|
+
function classifyHref(href) {
|
|
11
|
+
if (typeof href !== 'string' || !href || typeof window === 'undefined')
|
|
12
|
+
return null;
|
|
13
|
+
try {
|
|
14
|
+
const url = new URL(href, window.location.origin);
|
|
15
|
+
if (url.protocol !== 'http:' && url.protocol !== 'https:')
|
|
16
|
+
return null;
|
|
17
|
+
const absolute = /^https?:\/\//i.test(href);
|
|
18
|
+
// Decide by the resolved origin, never by the raw prefix: "/\host" resolves to another host in browsers.
|
|
19
|
+
if (url.origin === window.location.origin && (absolute || (href.startsWith('/') && !href.startsWith('//')))) {
|
|
20
|
+
const path = url.pathname + url.search + url.hash;
|
|
21
|
+
return { type: 'app', href: path, path };
|
|
22
|
+
}
|
|
23
|
+
if (absolute)
|
|
24
|
+
return { type: 'external', href: url.href };
|
|
25
|
+
}
|
|
26
|
+
catch (_a) { /* Render malformed URLs as plain text. */ }
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
function MarkdownReply({ text = '', onNavigate }) {
|
|
11
30
|
const { t } = useTranslation();
|
|
12
31
|
if (text.length > MARKDOWN_LIMIT)
|
|
13
32
|
return _jsx(Box, { sx: { whiteSpace: 'pre-wrap', overflowWrap: 'anywhere' }, children: text });
|
|
14
33
|
return _jsx(Box, { sx: { minWidth: 0, overflowWrap: 'anywhere', '& p': { my: 1 }, '& table': { borderCollapse: 'collapse' }, '& th,& td': { border: 1, borderColor: 'divider', p: 1 }, '& pre': { overflowX: 'auto', bgcolor: 'action.hover', p: 1, borderRadius: 1 }, '& blockquote': { borderLeft: 2, borderColor: 'divider', pl: 1, color: 'text.secondary' } }, children: _jsx(ReactMarkdown, { remarkPlugins: [remarkGfm], allowedElements: allowed, unwrapDisallowed: true, components: {
|
|
15
|
-
a: ({ href, children }) => {
|
|
34
|
+
a: ({ href, children }) => {
|
|
35
|
+
const label = plainText(children);
|
|
36
|
+
const link = classifyHref(href);
|
|
37
|
+
if (!link)
|
|
38
|
+
return _jsxs("span", { children: [children, href && href !== label ? ' (' + href + ')' : ''] });
|
|
39
|
+
const handleClick = (event) => {
|
|
40
|
+
if (link.type === 'app' && onNavigate && event.button === 0 && !event.metaKey && !event.ctrlKey && !event.shiftKey && !event.altKey) {
|
|
41
|
+
event.preventDefault();
|
|
42
|
+
onNavigate(link.path);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
return _jsx("a", Object.assign({ href: link.href, onClick: handleClick }, (link.type === 'external' ? { target: '_blank', rel: 'noopener noreferrer' } : {}), { children: children }));
|
|
46
|
+
},
|
|
16
47
|
img: ({ alt, src }) => _jsx("span", { children: alt || src || '' }),
|
|
17
48
|
table: ({ children }) => _jsx(Box, { role: "region", tabIndex: 0, "aria-label": t('Chat.markdownTable'), sx: { overflowX: 'auto', maxWidth: '100%' }, children: _jsx("table", { children: children }) }),
|
|
18
49
|
pre: ({ children }) => _jsx("pre", { tabIndex: 0, "aria-label": t('Chat.markdownCode'), children: children }),
|
package/dist/chat/ModelPicker.js
CHANGED
|
@@ -64,9 +64,12 @@ export function ModelPicker({ entries = [], selection, onChange, disabled = fals
|
|
|
64
64
|
var _a;
|
|
65
65
|
const shown = supported(entry, effort) ? effort : (_a = entry.efforts) === null || _a === void 0 ? void 0 : _a[0];
|
|
66
66
|
const estimate = estimateText(entry, shown, t, language);
|
|
67
|
+
const averageCost = Number.isInteger(entry.average_cost_usd_micros) && entry.average_cost_usd_micros >= 0
|
|
68
|
+
? t('Chat.estimatePerAnswer', { cost: new Intl.NumberFormat(language, { maximumSignificantDigits: 2 }).format(entry.average_cost_usd_micros / 1000000) })
|
|
69
|
+
: null;
|
|
67
70
|
const provider = providerName(entry);
|
|
68
71
|
const checked = entry.id === (active === null || active === void 0 ? void 0 : active.id);
|
|
69
|
-
return _jsx(ListItemButton, { role: "radio", "aria-checked": checked, tabIndex: checked ? 0 : -1, "data-model-entry": entry.id, selected: checked, sx: CHAT_MODEL_ENTRY_SX, onClick: () => selectEntry(entry), children: _jsx(ListItemText, { primary: _jsx(Typography, { variant: "body2", sx: { fontWeight: 600 }, children: entry.label || entry.model }), secondary: _jsxs(_Fragment, { children: [provider ? t('Chat.by', { provider }) : null, estimate ? _jsx(Box, { component: "span", sx: { display: 'block' }, children: estimate }) : null] }) }) }, entry.id);
|
|
72
|
+
return _jsx(ListItemButton, { role: "radio", "aria-checked": checked, tabIndex: checked ? 0 : -1, "data-model-entry": entry.id, selected: checked, sx: CHAT_MODEL_ENTRY_SX, onClick: () => selectEntry(entry), children: _jsx(ListItemText, { primary: _jsx(Typography, { variant: "body2", sx: { fontWeight: 600 }, children: entry.label || entry.model }), secondary: _jsxs(_Fragment, { children: [provider ? t('Chat.by', { provider }) : null, estimate ? _jsx(Box, { component: "span", sx: { display: 'block' }, children: estimate }) : null, averageCost ? _jsx(Box, { component: "span", sx: { display: 'block' }, children: averageCost }) : null] }) }) }, entry.id);
|
|
70
73
|
};
|
|
71
74
|
// Radio-group keyboard behaviour: arrows move the focus and the choice, only the checked row is a tab stop.
|
|
72
75
|
const moveSelection = (event) => {
|
package/dist/chat/api.js
CHANGED
|
@@ -11,6 +11,7 @@ export function createChatApi(overrides = {}, { apiBase = '/api/assistant/' } =
|
|
|
11
11
|
deleteChat: (id) => data(apiClient.delete(urls.chat(id))),
|
|
12
12
|
listTurns: (id, { cursor } = {}) => data(apiClient.get(urls.turns(id), { params: cursor ? { cursor } : {} })),
|
|
13
13
|
getStatus: ({ scope } = {}) => data(scope !== undefined ? apiClient.get(urls.status, { params: { scope } }) : apiClient.get(urls.status)),
|
|
14
|
+
getLimit: () => data(apiClient.get(urls.limit)),
|
|
14
15
|
};
|
|
15
16
|
return Object.assign(Object.assign({}, defaults), overrides);
|
|
16
17
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createKitSxEntry } from '../theme/kitSxEntry';
|
|
2
|
-
import { CHAT_COMPOSER_INPUT_SX, CHAT_COMPOSER_COMPACT_ROOT_SX, CHAT_COMPOSER_CONTEXT_ROW_SX, CHAT_COMPOSER_CONTEXT_SX, CHAT_COMPOSER_CONTEXT_ACTIONS_SX, CHAT_COMPOSER_INPUT_ROW_SX, CHAT_COMPOSER_COMPACT_FIELD_SX, CHAT_COMPOSER_ACTION_SX, CHAT_COMPOSER_SEND_SX, CHAT_COMPOSER_NOTICE_SX, CHAT_COMPOSER_NOTICE_TEXT_SX, CHAT_COMPOSER_NOTICE_ACTION_SX, CHAT_COMPOSER_NOTICE_CLOSE_SX, } from './ChatComposer';
|
|
2
|
+
import { CHAT_COMPOSER_INPUT_SX, CHAT_COMPOSER_COMPACT_ROOT_SX, CHAT_COMPOSER_CONTEXT_ROW_SX, CHAT_COMPOSER_CONTEXT_SX, CHAT_COMPOSER_CONTEXT_ACTIONS_SX, CHAT_COMPOSER_INPUT_ROW_SX, CHAT_COMPOSER_COMPACT_FIELD_SX, CHAT_COMPOSER_ACTION_SX, CHAT_COMPOSER_SEND_SX, CHAT_COMPOSER_NOTICE_SX, CHAT_COMPOSER_NOTICE_TEXT_SX, CHAT_COMPOSER_NOTICE_ACTION_SX, CHAT_COMPOSER_NOTICE_CLOSE_SX, CHAT_COMPOSER_USAGE_METER_SX, } from './ChatComposer';
|
|
3
3
|
import { CHAT_LIST_ARCHIVED_ACTION_SX, CHAT_LIST_ROW_ACTION_SX } from './ChatList';
|
|
4
|
-
import { CHAT_THREAD_NOTICE_SX, CHAT_THREAD_TOOL_CHIP_SX, CHAT_THREAD_TRIMMED_SX } from './ChatThread';
|
|
4
|
+
import { CHAT_THREAD_NOTICE_SX, CHAT_THREAD_TOOL_CHIP_SX, CHAT_THREAD_TOOL_STEPS_SX, CHAT_THREAD_TRIMMED_SX } from './ChatThread';
|
|
5
5
|
import { CHAT_MODEL_TRIGGER_SX, CHAT_MODEL_TRIGGER_SHORT_SX, CHAT_MODEL_ENTRY_SX, CHAT_MODEL_EFFORT_SX, CHAT_MODEL_CLOSE_SX } from './ModelPicker';
|
|
6
6
|
export const CHAT_KIT_SX_REGISTRY = [
|
|
7
7
|
createKitSxEntry('ChatComposer.input', 'MuiTextField', CHAT_COMPOSER_INPUT_SX, 'CHAT_COMPOSER_INPUT_SX'),
|
|
@@ -17,6 +17,7 @@ export const CHAT_KIT_SX_REGISTRY = [
|
|
|
17
17
|
createKitSxEntry('ChatComposer.noticeText', 'MuiBox', CHAT_COMPOSER_NOTICE_TEXT_SX, 'CHAT_COMPOSER_NOTICE_TEXT_SX'),
|
|
18
18
|
createKitSxEntry('ChatComposer.noticeAction', 'MuiButton', CHAT_COMPOSER_NOTICE_ACTION_SX, 'CHAT_COMPOSER_NOTICE_ACTION_SX'),
|
|
19
19
|
createKitSxEntry('ChatComposer.noticeClose', 'MuiIconButton', CHAT_COMPOSER_NOTICE_CLOSE_SX, 'CHAT_COMPOSER_NOTICE_CLOSE_SX'),
|
|
20
|
+
createKitSxEntry('ChatComposer.usageMeter', 'MuiLinearProgress', CHAT_COMPOSER_USAGE_METER_SX, 'CHAT_COMPOSER_USAGE_METER_SX'),
|
|
20
21
|
createKitSxEntry('ModelPicker.trigger', 'MuiButton', CHAT_MODEL_TRIGGER_SX, 'CHAT_MODEL_TRIGGER_SX'),
|
|
21
22
|
createKitSxEntry('ModelPicker.triggerShort', 'MuiButton', CHAT_MODEL_TRIGGER_SHORT_SX, 'CHAT_MODEL_TRIGGER_SHORT_SX'),
|
|
22
23
|
createKitSxEntry('ModelPicker.entry', 'MuiListItemButton', CHAT_MODEL_ENTRY_SX, 'CHAT_MODEL_ENTRY_SX'),
|
|
@@ -25,6 +26,7 @@ export const CHAT_KIT_SX_REGISTRY = [
|
|
|
25
26
|
createKitSxEntry('ChatList.rowAction', 'MuiIconButton', CHAT_LIST_ROW_ACTION_SX, 'CHAT_LIST_ROW_ACTION_SX'),
|
|
26
27
|
createKitSxEntry('ChatList.archivedAction', 'MuiButton', CHAT_LIST_ARCHIVED_ACTION_SX, 'CHAT_LIST_ARCHIVED_ACTION_SX'),
|
|
27
28
|
createKitSxEntry('ChatThread.toolChip', 'MuiChip', CHAT_THREAD_TOOL_CHIP_SX, 'CHAT_THREAD_TOOL_CHIP_SX'),
|
|
29
|
+
createKitSxEntry('ChatThread.toolSteps', 'MuiStack', CHAT_THREAD_TOOL_STEPS_SX, 'CHAT_THREAD_TOOL_STEPS_SX'),
|
|
28
30
|
createKitSxEntry('ChatThread.trimmed', 'MuiChip', CHAT_THREAD_TRIMMED_SX, 'CHAT_THREAD_TRIMMED_SX'),
|
|
29
31
|
createKitSxEntry('ChatThread.notice', 'MuiAlert', CHAT_THREAD_NOTICE_SX, 'CHAT_THREAD_NOTICE_SX'),
|
|
30
32
|
];
|
package/dist/chat/wire.js
CHANGED
|
@@ -2,7 +2,7 @@ export const CHAT_CLOSE_CODES = { 4401: 'session_ended', 4403: 'access_lost', 44
|
|
|
2
2
|
export const CHAT_ERROR_CODES = ['quota_exceeded', 'provider_error', 'timeout', 'prompt_too_long', 'invalid_output', 'security_violation', 'not_configured', 'rate_limited', 'invalid_selection', 'archived', 'turn_active', 'invalid_frame', 'unavailable'];
|
|
3
3
|
export const chatApiUrls = (base = '/api/assistant/') => {
|
|
4
4
|
const root = base.replace(/\/$/, '') + '/';
|
|
5
|
-
return { catalogue: root + 'catalogue/', chats: root + 'chats/', chat: (id) => root + 'chats/' + encodeURIComponent(id) + '/', turns: (id) => root + 'chats/' + encodeURIComponent(id) + '/turns/', status: root + 'status/' };
|
|
5
|
+
return { catalogue: root + 'catalogue/', chats: root + 'chats/', chat: (id) => root + 'chats/' + encodeURIComponent(id) + '/', turns: (id) => root + 'chats/' + encodeURIComponent(id) + '/turns/', status: root + 'status/', limit: root + 'limit/' };
|
|
6
6
|
};
|
|
7
7
|
export const defaultChatWsUrl = (chatId) => (window.location.protocol === 'https:' ? 'wss:' : 'ws:') + '//' + window.location.host + '/ws/assistant/chats/' + encodeURIComponent(chatId) + '/';
|
|
8
8
|
export const CHAT_FRAME_TYPES = { APP: 'app', NOTICE: 'notice' };
|
|
@@ -55,6 +55,12 @@ export const chatTranslations = {
|
|
|
55
55
|
'Chat.markdownCode': { de: 'Codeblock', en: 'Code block', fr: 'Bloc de code', sw: 'Kizuizi cha msimbo' },
|
|
56
56
|
'Chat.changeModel': { de: 'Modell ändern', en: 'Change model', fr: 'Changer de modèle', sw: 'Badilisha modeli' },
|
|
57
57
|
'Chat.usageLimit': { de: 'Nutzungslimit für {{model}} erreicht. Wählen Sie ein anderes Modell oder versuchen Sie es später erneut.', en: 'Usage limit reached for {{model}}. Choose another model or try again later.', fr: 'Limite d’utilisation atteinte pour {{model}}. Choisissez un autre modèle ou réessayez plus tard.', sw: 'Kikomo cha matumizi kimefikiwa kwa {{model}}. Chagua modeli nyingine au jaribu tena baadaye.' },
|
|
58
|
+
'Chat.limitUsage': { de: '{{used}} von {{limit}} USD', en: '{{used}} of {{limit}} USD', fr: '{{used}} sur {{limit}} USD', sw: '{{used}} kati ya {{limit}} USD' },
|
|
59
|
+
'Chat.limitReached.month': { de: 'Monatslimit erreicht', en: 'Monthly limit reached', fr: 'Limite mensuelle atteinte', sw: 'Kikomo cha mwezi kimefikiwa' },
|
|
60
|
+
'Chat.limitReached.day': { de: 'Tageslimit erreicht', en: 'Daily limit reached', fr: 'Limite journalière atteinte', sw: 'Kikomo cha siku kimefikiwa' },
|
|
61
|
+
'Chat.limitResets': { de: 'Zurückgesetzt am {{date}}', en: 'Resets {{date}}', fr: 'Réinitialisation le {{date}}', sw: 'Huwekwa upya {{date}}' },
|
|
62
|
+
'Chat.estimatePerAnswer': { de: '≈ {{cost}} USD pro Antwort', en: '≈ {{cost}} USD per answer', fr: '≈ {{cost}} USD par réponse', sw: '≈ {{cost}} USD kwa jibu' },
|
|
63
|
+
'Chat.toolSteps': { de: 'Verwendete Werkzeuge', en: 'Tools used', fr: 'Outils utilisés', sw: 'Zana zilizotumika' },
|
|
58
64
|
'Chat.answerIncomplete': { de: 'Die Antwort konnte nicht abgeschlossen werden.', en: 'The answer could not be completed.', fr: 'La réponse n’a pas pu être terminée.', sw: 'Jibu halikuweza kukamilishwa.' },
|
|
59
65
|
'Chat.notAvailableHere': { de: 'Der Assistent ist hier nicht verfügbar.', en: 'The assistant is not available here.', fr: 'L’assistant n’est pas disponible ici.', sw: 'Msaidizi hapatikani hapa.' },
|
|
60
66
|
'Chat.historyTrimmed_one': { de: '{{count}} frühere Nachricht wurde ausgelassen', en: '{{count}} earlier message left out', fr: '{{count}} message précédent omis', sw: 'Ujumbe {{count}} wa awali umeachwa' },
|