@theoremjs/react 0.3.5-next.1025.g5523d8f → 0.3.5-next.1026.g24f0c43
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.md +16 -0
- package/client/transcript-groups.d.ts +3 -1
- package/client/transcript-groups.js +11 -4
- package/package.json +3 -3
- package/ui/ChatComposerRow.js +4 -2
- package/ui/ChatTranscript.js +2 -2
- package/ui/SchemaFields.js +6 -3
- package/ui/ShapedData.js +8 -4
- package/ui/StateFields.js +6 -4
- package/ui/TheoremDecision.js +3 -1
- package/ui/TheoremHost.js +5 -3
- package/ui/ToolGateCard.js +5 -2
- package/ui/ToolResult.js +2 -1
- package/ui/TraceCharts.js +7 -9
- package/ui/TraceValues.d.ts +4 -0
- package/ui/TraceValues.js +7 -0
- package/ui/approval-heading.d.ts +1 -1
- package/ui/approval-heading.js +4 -1
- package/ui/labels.d.ts +21 -0
- package/ui/labels.js +34 -1
package/README.md
CHANGED
|
@@ -702,6 +702,22 @@ Use `labels` to replace any message, for each locale:
|
|
|
702
702
|
- a key is not in `@theorem.*` or `@astryx.*`
|
|
703
703
|
- Labels are shown as text. They are never shown as HTML.
|
|
704
704
|
|
|
705
|
+
Two messages word names that come from your code or your data. Use ICU `select` to replace some of them:
|
|
706
|
+
|
|
707
|
+
```tsx
|
|
708
|
+
labels={{
|
|
709
|
+
en: {
|
|
710
|
+
'@theorem.tool.name': '{tool, select, search_web {web search} other {{words}}}',
|
|
711
|
+
'@theorem.data.field': '{field, select, due_at {Deadline} other {{words}}}',
|
|
712
|
+
},
|
|
713
|
+
}}
|
|
714
|
+
```
|
|
715
|
+
|
|
716
|
+
- `@theorem.tool.name` words a tool where it has no activity label. `{words}` is the name in words.
|
|
717
|
+
- `@theorem.data.field` words a key of a value that has no schema `title`: in tool results, data views, request forms, and the list of missing fields.
|
|
718
|
+
- In a `select` case, write `_` for each character of the name that is not a letter, a digit, or `_`. A tool named `search-web` is the case `search_web`.
|
|
719
|
+
- The sign-in card says why it asks with `@theorem.gate.auth.detail`. It does not show the challenge's `message`, which is for your logs.
|
|
720
|
+
|
|
705
721
|
## More documentation
|
|
706
722
|
|
|
707
723
|
- [The wire](https://github.com/masudl-hub/theoremai/blob/main/react/docs/wire.md): the requests and events between the browser and the server, and the checks on each side.
|
|
@@ -168,11 +168,13 @@ export declare function assistantTurnTiming(args: {
|
|
|
168
168
|
}): AssistantTurnTiming;
|
|
169
169
|
export declare function toolCallLabel(tool: Extract<TranscriptBlock, {
|
|
170
170
|
kind: 'tool';
|
|
171
|
-
}>['tool']): string;
|
|
171
|
+
}>['tool'], nameOf?: (name: string) => string): string;
|
|
172
172
|
/** A tool call still running in the background, as the composer's pill row shows it. */
|
|
173
173
|
export type BackgroundJob = {
|
|
174
174
|
callId: string;
|
|
175
175
|
label: string;
|
|
176
|
+
/** The tool's name, when no activity label words the call, so `label` is that name in words. */
|
|
177
|
+
unlabelledTool?: string;
|
|
176
178
|
};
|
|
177
179
|
/**
|
|
178
180
|
* The calls still running in the background, oldest first: each tool call whose last phase is
|
|
@@ -260,12 +260,15 @@ export function assistantTurnTiming(args) {
|
|
|
260
260
|
const startedAt = prompt?.kind === 'user' ? args.replyStart(prompt) : undefined;
|
|
261
261
|
return startedAt === undefined ? { key, live } : { key, live, startedAt };
|
|
262
262
|
}
|
|
263
|
-
export function toolCallLabel(tool) {
|
|
263
|
+
export function toolCallLabel(tool, nameOf = humanize) {
|
|
264
|
+
return activityOf(tool) ?? nameOf(tool.name);
|
|
265
|
+
}
|
|
266
|
+
function activityOf(tool) {
|
|
264
267
|
const phase = tool.state?.phase;
|
|
265
268
|
if (phase === 'cancel')
|
|
266
|
-
return
|
|
269
|
+
return undefined;
|
|
267
270
|
const settled = phase === 'complete' || phase === 'error';
|
|
268
|
-
return
|
|
271
|
+
return settled ? tool.activityPast : tool.activity;
|
|
269
272
|
}
|
|
270
273
|
/**
|
|
271
274
|
* The calls still running in the background, oldest first: each tool call whose last phase is
|
|
@@ -285,7 +288,11 @@ export function backgroundJobs(blocks) {
|
|
|
285
288
|
const { operationId } = block.tool;
|
|
286
289
|
if (operationId && landed.has(operationId))
|
|
287
290
|
continue;
|
|
288
|
-
jobs.push({
|
|
291
|
+
jobs.push({
|
|
292
|
+
callId: block.tool.callId,
|
|
293
|
+
label: toolCallLabel(block.tool),
|
|
294
|
+
...(activityOf(block.tool) === undefined ? { unlabelledTool: block.tool.name } : {}),
|
|
295
|
+
});
|
|
289
296
|
}
|
|
290
297
|
return jobs;
|
|
291
298
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theoremjs/react",
|
|
3
|
-
"version": "0.3.5-next.
|
|
3
|
+
"version": "0.3.5-next.1026.g24f0c43",
|
|
4
4
|
"description": "React bindings for Theorem: headless hooks + transport, an Astryx chat UI, and a Web-standard server handler.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -60,8 +60,8 @@
|
|
|
60
60
|
"@stylexjs/stylex": "0.19.0",
|
|
61
61
|
"react": "^19.0.0",
|
|
62
62
|
"react-dom": "^19.0.0",
|
|
63
|
-
"@theoremjs/agents": "^0.3.5-next.
|
|
64
|
-
"@theoremjs/web": "^0.3.5-next.
|
|
63
|
+
"@theoremjs/agents": "^0.3.5-next.1026.g24f0c43",
|
|
64
|
+
"@theoremjs/web": "^0.3.5-next.1026.g24f0c43"
|
|
65
65
|
},
|
|
66
66
|
"peerDependenciesMeta": {
|
|
67
67
|
"@astryxdesign/core": {
|
package/ui/ChatComposerRow.js
CHANGED
|
@@ -13,7 +13,7 @@ import { VStack } from '@astryxdesign/core/VStack';
|
|
|
13
13
|
import { IconChevronDown, IconChevronUp, IconPlayerStopFilled } from '@tabler/icons-react';
|
|
14
14
|
import { useId, useLayoutEffect, useState, } from 'react';
|
|
15
15
|
import { useSecondTicker } from "../hooks/use-second-ticker.js";
|
|
16
|
-
import { liveDuration } from "./labels.js";
|
|
16
|
+
import { liveDuration, toolNameLabel } from "./labels.js";
|
|
17
17
|
import { useLabels } from "./labels-provider.js";
|
|
18
18
|
/**
|
|
19
19
|
* A `--theorem-composer-*` property, or Theorem's value when the page sets none.
|
|
@@ -105,7 +105,9 @@ function PillRow(props) {
|
|
|
105
105
|
const t = useLabels();
|
|
106
106
|
const pills = [
|
|
107
107
|
props.isWorking ? (_jsx(WorkingPill, { since: props.workingSince, icons: props.icons, onStop: props.onStop }, "working")) : null,
|
|
108
|
-
...props.backgroundJobs.map((job) => (_jsx(Token, { size: "lg", className: "theorem-composer-pill", "data-pill": "background", style: PILL, label: job.
|
|
108
|
+
...props.backgroundJobs.map((job) => (_jsx(Token, { size: "lg", className: "theorem-composer-pill", "data-pill": "background", style: PILL, label: job.unlabelledTool === undefined
|
|
109
|
+
? job.label
|
|
110
|
+
: toolNameLabel(t, job.unlabelledTool, job.label), description: t('@theorem.composer.pill.background'), icon: props.icons?.backgroundJob ?? (_jsx(Spinner, { size: "sm", shade: "inherit", "aria-label": t('@theorem.composer.pill.background') })) }, job.callId))),
|
|
109
111
|
...(props.pills ?? []).map((pill) => (_jsx(Token, { size: "lg", className: "theorem-composer-pill", "data-pill": "app", style: PILL, label: pill.label, icon: pill.icon, onClick: pill.onSelect }, pill.id))),
|
|
110
112
|
].filter(Boolean);
|
|
111
113
|
if (pills.length === 0 && !props.hint)
|
package/ui/ChatTranscript.js
CHANGED
|
@@ -26,7 +26,7 @@ import { assistantTurnCopyText, assistantTurnTiming, composeAssistantTurn, group
|
|
|
26
26
|
import { useSecondTicker } from "../hooks/use-second-ticker.js";
|
|
27
27
|
import { useTurnClock } from "../hooks/use-turn-clock.js";
|
|
28
28
|
import { useDisclosureMotion } from "./disclosure-motion.js";
|
|
29
|
-
import { usageLine, workDuration, workStatusLabel } from "./labels.js";
|
|
29
|
+
import { toolNameLabel, usageLine, workDuration, workStatusLabel, } from "./labels.js";
|
|
30
30
|
import { TheoremLabelsProvider, useLabels } from "./labels-provider.js";
|
|
31
31
|
import { useMarkdownPlugins } from "./markdown-plugins.js";
|
|
32
32
|
import { useMediaViewer } from "./media-viewer.js";
|
|
@@ -531,7 +531,7 @@ function failedToolItem(t, base, tool, state, shows) {
|
|
|
531
531
|
};
|
|
532
532
|
}
|
|
533
533
|
function toolCallItem(t, id, tool, shows) {
|
|
534
|
-
const base = { key: id, name: toolCallLabel(tool) };
|
|
534
|
+
const base = { key: id, name: toolCallLabel(tool, (name) => toolNameLabel(t, name)) };
|
|
535
535
|
const { state } = tool;
|
|
536
536
|
switch (state?.phase) {
|
|
537
537
|
case 'error':
|
package/ui/SchemaFields.js
CHANGED
|
@@ -16,6 +16,7 @@ import { Tokenizer } from '@astryxdesign/core/Tokenizer';
|
|
|
16
16
|
import { VStack } from '@astryxdesign/core/VStack';
|
|
17
17
|
import { blankRow, branchField, branchSample, branchValue, chosenBranch, inBranch, isRow, json, schemaControl, schemaFields, withField, } from '@theoremjs/web/client';
|
|
18
18
|
import { useState } from 'react';
|
|
19
|
+
import { keyNamer } from "./labels.js";
|
|
19
20
|
import { useLabels } from "./labels-provider.js";
|
|
20
21
|
import { useKeyedRows } from "./row-keys.js";
|
|
21
22
|
import { AddRow, Group, Labelled, RemoveRow } from "./StateFields.js";
|
|
@@ -103,6 +104,7 @@ function FieldGroup({ field, children }) {
|
|
|
103
104
|
}
|
|
104
105
|
/** Which shape a value takes, then what that shape asks for. Picking one starts it at its sample. */
|
|
105
106
|
function BranchFields({ label, branches, isMenu, value, onChange, }) {
|
|
107
|
+
const nameOf = keyNamer(useLabels());
|
|
106
108
|
const chosen = chosenBranch(branches, value);
|
|
107
109
|
const pick = (next) => {
|
|
108
110
|
const branch = branches.find((each) => each.label === next);
|
|
@@ -112,7 +114,7 @@ function BranchFields({ label, branches, isMenu, value, onChange, }) {
|
|
|
112
114
|
const picker = (_jsx(BranchPicker, { label: label, labels: branches.map((branch) => branch.label), isMenu: isMenu, value: chosen?.label, onPick: pick }));
|
|
113
115
|
if (!chosen)
|
|
114
116
|
return picker;
|
|
115
|
-
const body = branchField(chosen);
|
|
117
|
+
const body = branchField(chosen, nameOf);
|
|
116
118
|
const edit = (next) => onChange(inBranch(chosen, next));
|
|
117
119
|
const current = branchValue(chosen, value);
|
|
118
120
|
return (_jsxs(VStack, { gap: 3, children: [picker, body.control.kind === 'group' ? (_jsx(ObjectFields, { schema: body.control.schema, value: isRow(current) ? current : {}, onChange: edit })) : (_jsx(Field, { field: body, value: current, onChange: edit }))] }));
|
|
@@ -183,7 +185,8 @@ function isShort({ control }) {
|
|
|
183
185
|
}
|
|
184
186
|
}
|
|
185
187
|
function ObjectFields({ schema, value, onChange, }) {
|
|
186
|
-
|
|
188
|
+
const nameOf = keyNamer(useLabels());
|
|
189
|
+
return (_jsx(Grid, { columns: { minWidth: SHORT_FIELD_PX, repeat: 'fill' }, gap: 3, children: schemaFields(schema, nameOf).map((field) => (_jsx("div", { style: isShort(field)
|
|
187
190
|
? { minWidth: 0, alignSelf: 'start' }
|
|
188
191
|
: { gridColumn: '1 / -1', minWidth: 0 }, children: _jsx(Field, { field: field, value: value[field.key], onChange: (next) => onChange(withField(value, field.key, next)) }) }, field.key))) }));
|
|
189
192
|
}
|
|
@@ -194,7 +197,7 @@ function ObjectFields({ schema, value, onChange, }) {
|
|
|
194
197
|
*/
|
|
195
198
|
export function SchemaFields({ schema, value, onChange, }) {
|
|
196
199
|
const t = useLabels();
|
|
197
|
-
const control = schemaControl(schema);
|
|
200
|
+
const control = schemaControl(schema, keyNamer(t));
|
|
198
201
|
if (control.kind === 'branches') {
|
|
199
202
|
return (_jsx(BranchFields, { label: t('@theorem.decision.shape'), branches: control.branches, isMenu: control.isMenu, value: value, onChange: (next) => onChange(isRow(next) ? next : {}) }));
|
|
200
203
|
}
|
package/ui/ShapedData.js
CHANGED
|
@@ -18,6 +18,7 @@ import { IconCode, IconEye } from '@tabler/icons-react';
|
|
|
18
18
|
import { fieldLabel, fieldReading, isPlain, isProse, isRow, json, layoutChars, MAX_ROWS, plainReading, rowHeading, shapeOf, splitFields, unpacked, withUnit, } from '@theoremjs/web/client';
|
|
19
19
|
import { Component, useMemo, useState } from 'react';
|
|
20
20
|
import { Arrive, useArrive } from "./arrive.js";
|
|
21
|
+
import { keyNamer } from "./labels.js";
|
|
21
22
|
import { useLabels } from "./labels-provider.js";
|
|
22
23
|
import { useMarkdownPlugins } from "./markdown-plugins.js";
|
|
23
24
|
import { useMediaViewer } from "./media-viewer.js";
|
|
@@ -65,8 +66,9 @@ function More({ total }) {
|
|
|
65
66
|
return (_jsx(Text, { type: "supporting", color: "secondary", children: t('@theorem.data.more', { count: String(total - MAX_ROWS) }) }));
|
|
66
67
|
}
|
|
67
68
|
function DataTable({ columns, rows, units, }) {
|
|
69
|
+
const nameOf = keyNamer(useLabels());
|
|
68
70
|
const tableColumns = columns.map((key, index) => {
|
|
69
|
-
const { label, unit } = fieldLabel(key, units);
|
|
71
|
+
const { label, unit } = fieldLabel(key, units, nameOf);
|
|
70
72
|
return {
|
|
71
73
|
key: `c${String(index)}`,
|
|
72
74
|
header: unit ? `${label} (${unit})` : label,
|
|
@@ -78,10 +80,11 @@ function DataTable({ columns, rows, units, }) {
|
|
|
78
80
|
}
|
|
79
81
|
/** A list row's extra fields and tags, at its end. */
|
|
80
82
|
function ListRowEnd({ row }) {
|
|
83
|
+
const nameOf = keyNamer(useLabels());
|
|
81
84
|
if (row.tags.length + row.extras.length === 0)
|
|
82
85
|
return undefined;
|
|
83
86
|
return (_jsxs(HStack, { gap: 2, vAlign: "center", children: [row.extras.map(([key, value]) => {
|
|
84
|
-
const { label, unit } = fieldReading(key, value);
|
|
87
|
+
const { label, unit } = fieldReading(key, value, undefined, nameOf);
|
|
85
88
|
return (_jsxs(Text, { type: "supporting", color: "secondary", children: [label, " ", _jsx(Plain, { value: value, unit: unit })] }, key));
|
|
86
89
|
}), row.tags.map((tag) => (_jsx(Token, { label: tag, size: "sm" }, tag)))] }));
|
|
87
90
|
}
|
|
@@ -124,9 +127,10 @@ function ArrivingFieldSection({ shown, depth }) {
|
|
|
124
127
|
return (_jsx(FieldSection, { shown: shown, depth: depth, className: arrive?.className, style: arrive?.style }));
|
|
125
128
|
}
|
|
126
129
|
function Fields({ row, depth, units }) {
|
|
127
|
-
const
|
|
130
|
+
const nameOf = keyNamer(useLabels());
|
|
131
|
+
const { plain, sections } = splitFields(row, nameOf);
|
|
128
132
|
const fields = plain.length > 0 && (_jsx(MetadataList, { label: { position: 'start', width: '40%' }, children: plain.map(([key, value]) => {
|
|
129
|
-
const { label, unit } = fieldReading(key, value, units);
|
|
133
|
+
const { label, unit } = fieldReading(key, value, units, nameOf);
|
|
130
134
|
return (_jsx(MetadataListItem, { label: label, children: Array.isArray(unpacked(value)) ? (_jsx(Node, { value: value, depth: depth + 1 })) : (_jsx(Plain, { value: value, unit: unit })) }, key));
|
|
131
135
|
}) }));
|
|
132
136
|
return (_jsxs(VStack, { gap: 2, children: [depth > 0 && fields, sections.length > 0 && (_jsx(CollapsibleGroup, { type: "multiple", hasDividers: true, density: "compact",
|
package/ui/StateFields.js
CHANGED
|
@@ -14,11 +14,12 @@ import { Thumbnail } from '@astryxdesign/core/Thumbnail';
|
|
|
14
14
|
import { Tokenizer } from '@astryxdesign/core/Tokenizer';
|
|
15
15
|
import { VStack } from '@astryxdesign/core/VStack';
|
|
16
16
|
import { IconPlus, IconX } from '@tabler/icons-react';
|
|
17
|
-
import {
|
|
17
|
+
import { isPlain } from '@theoremjs/web/client';
|
|
18
18
|
import { createContext, useContext, useId, useState } from 'react';
|
|
19
19
|
import { IMAGE_ACCEPT, imageSrc } from "../client/decision-images.js";
|
|
20
20
|
import { blankLike, isWordList, tableColumns } from "../client/state-fields.js";
|
|
21
21
|
import { useImageReader } from "./DecisionImages.js";
|
|
22
|
+
import { fieldNameLabel } from "./labels.js";
|
|
22
23
|
import { useLabels } from "./labels-provider.js";
|
|
23
24
|
import { useMediaViewer } from "./media-viewer.js";
|
|
24
25
|
import { useKeyedRows } from "./row-keys.js";
|
|
@@ -85,7 +86,8 @@ export function RemoveRow({ index, onRemove }) {
|
|
|
85
86
|
}), size: "sm", variant: "ghost", icon: _jsx(IconX, { size: 14 }), onClick: onRemove }));
|
|
86
87
|
}
|
|
87
88
|
function ObjectFields({ value, onChange }) {
|
|
88
|
-
|
|
89
|
+
const t = useLabels();
|
|
90
|
+
return (_jsx(VStack, { gap: 3, children: Object.entries(value).map(([key, entry]) => (_jsx(Field, { label: fieldNameLabel(t, key), value: entry, onChange: (next) => onChange({ ...value, [key]: next }) }, key))) }));
|
|
89
91
|
}
|
|
90
92
|
/** A list of words as tokens; any other list as rows, each removable, with one more shaped like the last. */
|
|
91
93
|
function ListField({ value, onChange, label }) {
|
|
@@ -108,9 +110,9 @@ function ListField({ value, onChange, label }) {
|
|
|
108
110
|
gridTemplateColumns: `${columns.map((column) => `minmax(0, ${String(column.weight)}fr)`).join(' ')} auto`,
|
|
109
111
|
};
|
|
110
112
|
const rows = value;
|
|
111
|
-
return (_jsxs(Labelled, { label: label, children: [_jsxs("div", { style: grid, "aria-hidden": true, children: [columns.map((column) => (_jsx(Text, { type: "supporting", color: "secondary", maxLines: 1, children:
|
|
113
|
+
return (_jsxs(Labelled, { label: label, children: [_jsxs("div", { style: grid, "aria-hidden": true, children: [columns.map((column) => (_jsx(Text, { type: "supporting", color: "secondary", maxLines: 1, children: fieldNameLabel(t, column.key) }, column.key))), _jsx("span", { style: { width: 28 } })] }), keyed.rows.map(({ index, key }) => {
|
|
112
114
|
const row = rows[index];
|
|
113
|
-
return (_jsxs("div", { style: grid, children: [columns.map((column) => (_jsx(PlainField, { label: `${
|
|
115
|
+
return (_jsxs("div", { style: grid, children: [columns.map((column) => (_jsx(PlainField, { label: `${fieldNameLabel(t, column.key)} ${String(index + 1)}`, isLabelHidden: true, value: row[column.key] ?? null, onChange: (next) => onChange(rows.map((old, at) => (at === index ? { ...old, [column.key]: next } : old))) }, column.key))), remove(index)] }, key));
|
|
114
116
|
}), add] }));
|
|
115
117
|
}
|
|
116
118
|
return (_jsx(Group, { label: label, children: _jsxs(VStack, { gap: 3, children: [keyed.rows.map(({ item: entry, index, key }) => {
|
package/ui/TheoremDecision.js
CHANGED
|
@@ -7,6 +7,7 @@ import { useTheoremDecision } from "../hooks/use-theorem-decision.js";
|
|
|
7
7
|
import { ConsoleFrame, JsonRequest, RequestCard, ResponseColumn, RunBar, useBytes, } from "./ConsoleFrame.js";
|
|
8
8
|
import { TheoremDecisionAnswers } from "./DecisionAnswers.js";
|
|
9
9
|
import { ImageDrop } from "./DecisionImages.js";
|
|
10
|
+
import { keyNamer } from "./labels.js";
|
|
10
11
|
import { TheoremLabelsProvider, useLabels } from "./labels-provider.js";
|
|
11
12
|
import { PaneFailure, PaneLoading } from "./PaneState.js";
|
|
12
13
|
import { SchemaFields } from "./SchemaFields.js";
|
|
@@ -58,7 +59,8 @@ function useDecisionState(defaultState, maxStateBytes) {
|
|
|
58
59
|
/** What the host's question builder takes beside the state, and the fields it still needs. */
|
|
59
60
|
function useBuildInput(schema) {
|
|
60
61
|
const [input, setInput] = useState(() => schema ? sampleFromSchema(schema) : {});
|
|
61
|
-
const
|
|
62
|
+
const t = useLabels();
|
|
63
|
+
const missing = schema ? missingFields(schema, input, '', keyNamer(t)) : [];
|
|
62
64
|
return { schema, input, setInput, missing };
|
|
63
65
|
}
|
|
64
66
|
/** The builder's input, then the state, as fields or JSON, and Decide. */
|
package/ui/TheoremHost.js
CHANGED
|
@@ -18,7 +18,7 @@ import { useSecondTicker } from "../hooks/use-second-ticker.js";
|
|
|
18
18
|
import { useTheoremHost } from "../hooks/use-theorem-host.js";
|
|
19
19
|
import { Arrive, Stream } from "./arrive.js";
|
|
20
20
|
import { ConsoleFrame, JsonRequest, RequestCard, ResponseColumn, RunBar, } from "./ConsoleFrame.js";
|
|
21
|
-
import { liveDuration, workDuration } from "./labels.js";
|
|
21
|
+
import { keyNamer, liveDuration, toolNameLabel, workDuration, } from "./labels.js";
|
|
22
22
|
import { useLabels } from "./labels-provider.js";
|
|
23
23
|
import { IconMcp } from "./mcp-icon.js";
|
|
24
24
|
import { PaneFailure, PaneLoading } from "./PaneState.js";
|
|
@@ -48,7 +48,7 @@ function checkRequest(t, tool, text) {
|
|
|
48
48
|
}
|
|
49
49
|
if (!isRow(input))
|
|
50
50
|
return { ok: false, note: t('@theorem.decision.invalid_json') };
|
|
51
|
-
const missing = missingFields(tool.inputSchema, input);
|
|
51
|
+
const missing = missingFields(tool.inputSchema, input, '', keyNamer(t));
|
|
52
52
|
if (missing.length > 0)
|
|
53
53
|
return { ok: false, note: t('@theorem.host.missing', { fields: missing.join(', ') }), input };
|
|
54
54
|
return { ok: true, input };
|
|
@@ -77,7 +77,9 @@ function ToolTokens({ tool }) {
|
|
|
77
77
|
}
|
|
78
78
|
/** The tool's activity while it runs, and its activityPast once it has finished, with the clock beside it. */
|
|
79
79
|
function callActivity(t, call, now) {
|
|
80
|
-
const label = call.call
|
|
80
|
+
const label = call.call
|
|
81
|
+
? toolCallLabel(call.call, (name) => toolNameLabel(t, name))
|
|
82
|
+
: toolNameLabel(t, call.name, call.name);
|
|
81
83
|
const duration = call.isRunning
|
|
82
84
|
? liveDuration(t, now - call.startedAt)
|
|
83
85
|
: call.elapsedMs == null
|
package/ui/ToolGateCard.js
CHANGED
|
@@ -14,6 +14,7 @@ import { IconEye, IconFlame, IconPencil } from '@tabler/icons-react';
|
|
|
14
14
|
import { humanize, isOAuthComplete } from '@theoremjs/web/client';
|
|
15
15
|
import { useCallback, useEffect, useState } from 'react';
|
|
16
16
|
import { approvalHeading } from "./approval-heading.js";
|
|
17
|
+
import { toolNameLabel } from "./labels.js";
|
|
17
18
|
import { TheoremLabelsProvider, useLabels } from "./labels-provider.js";
|
|
18
19
|
/** The widest a gate card gets, in pixels. */
|
|
19
20
|
export const GATE_CARD_WIDTH = 400;
|
|
@@ -49,7 +50,7 @@ function ApprovalBody({ gate, toolName, agent, input, decided = null, onDecision
|
|
|
49
50
|
}
|
|
50
51
|
function AuthChallengeDetails({ challenge }) {
|
|
51
52
|
const t = useLabels();
|
|
52
|
-
return (_jsxs(_Fragment, { children: [_jsx(Text, { color: "secondary", children: challenge.
|
|
53
|
+
return (_jsxs(_Fragment, { children: [_jsx(Text, { color: "secondary", children: t('@theorem.gate.auth.detail', { service: challenge.service }) }), challenge.resource ? (_jsx(Text, { type: "supporting", color: "secondary", children: t('@theorem.gate.auth.resource', { resource: challenge.resource }) })) : null, challenge.requiredScopes?.length ? (_jsx(HStack, { gap: 1, wrap: "wrap", children: challenge.requiredScopes.map((scope) => (_jsx(Token, { label: scope, size: "sm" }, scope))) })) : null] }));
|
|
53
54
|
}
|
|
54
55
|
export function AuthChallengeCard(props) {
|
|
55
56
|
return (_jsx(TheoremLabelsProvider, { children: _jsx(AuthChallengeBody, { ...props }) }));
|
|
@@ -86,7 +87,9 @@ function AuthChallengeBody({ gate, toolName, onAuthenticated, submitted = false,
|
|
|
86
87
|
setSecret('');
|
|
87
88
|
onAuthenticated?.(value);
|
|
88
89
|
}
|
|
89
|
-
return (_jsxs(GateCard, { heading: t('@theorem.gate.auth.title', {
|
|
90
|
+
return (_jsxs(GateCard, { heading: t('@theorem.gate.auth.title', {
|
|
91
|
+
tool: toolNameLabel(t, toolName, humanize(toolName).toLowerCase()),
|
|
92
|
+
}), tag: _jsx(Text, { type: "supporting", textWrap: "nowrap", children: t(`@theorem.gate.tag.${authType}`) }), children: [_jsx(AuthChallengeDetails, { challenge: challenge }), _jsx(AuthAction, { authType: authType, authUrl: challenge.authorizationUrl, slot: slot, secret: secret, submitted: submitted, onSecretChange: setSecret, onSubmit: submit, onOpenSignIn: openSignIn })] }));
|
|
90
93
|
}
|
|
91
94
|
function AuthAction(props) {
|
|
92
95
|
const t = useLabels();
|
package/ui/ToolResult.js
CHANGED
|
@@ -9,6 +9,7 @@ import { lazy, Suspense, useMemo, useState } from 'react';
|
|
|
9
9
|
import { Arrive } from "./arrive.js";
|
|
10
10
|
import { CardWall } from "./CardWall.js";
|
|
11
11
|
import { ReferencedMedia } from "./ChatTranscript.js";
|
|
12
|
+
import { keyNamer } from "./labels.js";
|
|
12
13
|
import { useLabels } from "./labels-provider.js";
|
|
13
14
|
import { PageMediaViewer } from "./media-viewer.js";
|
|
14
15
|
import { keyedByContent } from "./row-keys.js";
|
|
@@ -46,7 +47,7 @@ function ResultLead({ layout, parts = [], }) {
|
|
|
46
47
|
*/
|
|
47
48
|
export function ToolResult({ output, parts }) {
|
|
48
49
|
const t = useLabels();
|
|
49
|
-
const layout = useMemo(() => layoutResult(output), [output]);
|
|
50
|
+
const layout = useMemo(() => layoutResult(output, keyNamer(t)), [output, t]);
|
|
50
51
|
// why: A figure's card is its reading: the fields below don't repeat it.
|
|
51
52
|
const ledKeys = useMemo(() => layout.figures.map((figure) => figure.key), [layout]);
|
|
52
53
|
return (_jsx(ShapedData, { value: output, title: t('@theorem.host.response'), lead: _jsx(ResultLead, { layout: layout, parts: parts }), ledKeys: ledKeys }));
|
package/ui/TraceCharts.js
CHANGED
|
@@ -40,8 +40,6 @@ const TOKEN_FILL = {
|
|
|
40
40
|
cached: 'hatch',
|
|
41
41
|
output: 'shade1',
|
|
42
42
|
};
|
|
43
|
-
const compact = new Intl.NumberFormat(undefined, { notation: 'compact', maximumFractionDigits: 1 });
|
|
44
|
-
const percent = new Intl.NumberFormat(undefined, { style: 'percent' });
|
|
45
43
|
function numberAt(node, key) {
|
|
46
44
|
const value = node.span.attributes[key];
|
|
47
45
|
return typeof value === 'number' ? value : undefined;
|
|
@@ -62,8 +60,8 @@ function ShareBar({ parts, }) {
|
|
|
62
60
|
return (_jsx(ChartFrame, { children: _jsx(ResponsiveContainer, { width: "100%", height: SHARE_PX, initialDimension: { width: FIRST_WIDTH_PX, height: SHARE_PX }, children: _jsxs(BarChart, { data: [Object.fromEntries(parts.map((part) => [part.key, part.value]))], layout: "vertical", margin: { top: 0, right: 0, bottom: 0, left: 0 }, barCategoryGap: 0, accessibilityLayer: false, children: [_jsx(XAxis, { type: "number", domain: [0, total], hide: true }), _jsx(YAxis, { type: "category", hide: true }), parts.map((part) => (_jsx(Bar, { dataKey: part.key, stackId: "share", fill: traceFill(part.fill), ...BAR }, part.key)))] }) }) }));
|
|
63
61
|
}
|
|
64
62
|
/** A share as a legend reads it; a sliver too thin to round up still says it is there. */
|
|
65
|
-
function shareText(share) {
|
|
66
|
-
return share > 0 && share < 0.01 ? `<${percent
|
|
63
|
+
function shareText(share, percent) {
|
|
64
|
+
return share > 0 && share < 0.01 ? `<${percent(0.01)}` : percent(share);
|
|
67
65
|
}
|
|
68
66
|
function sumOf(split) {
|
|
69
67
|
return SPLIT_KEYS.reduce((total, key) => total + split[key], 0);
|
|
@@ -75,7 +73,7 @@ function SplitLegend({ split, total }) {
|
|
|
75
73
|
return (_jsx(Legend, { items: SPLIT_KEYS.filter((key) => split[key] > 0).map((key) => ({
|
|
76
74
|
fill: SPLIT_FILL[key],
|
|
77
75
|
label: t(`@theorem.panel.trace.time.${key}`),
|
|
78
|
-
value: [format.duration(split[key]), shareText(split[key] / total)].join(t('@theorem.panel.trace.separator')),
|
|
76
|
+
value: [format.duration(split[key]), shareText(split[key] / total, format.percent)].join(t('@theorem.panel.trace.separator')),
|
|
79
77
|
})) }));
|
|
80
78
|
}
|
|
81
79
|
/** A turn's time by where it went: what share went to the model, the bar, and each share. */
|
|
@@ -89,7 +87,7 @@ function TimeCard({ split }) {
|
|
|
89
87
|
const keys = SPLIT_KEYS.filter((key) => split[key] / total >= 0.005);
|
|
90
88
|
return (_jsxs(ChartCard, { title: t('@theorem.panel.trace.time'), value: format.duration(total), note: split.model > 0
|
|
91
89
|
? t('@theorem.panel.trace.charts.modelShare', {
|
|
92
|
-
share: percent
|
|
90
|
+
share: format.percent(split.model / total),
|
|
93
91
|
})
|
|
94
92
|
: undefined, children: [_jsx(ShareBar, { parts: keys.map((key) => ({ key, fill: SPLIT_FILL[key], value: split[key] })) }), _jsx(SplitLegend, { split: split, total: total })] }));
|
|
95
93
|
}
|
|
@@ -137,12 +135,12 @@ function TokensCard({ title, rows }) {
|
|
|
137
135
|
const labels = { fresh: 'input', cached: 'cached', output: 'output' };
|
|
138
136
|
return (_jsxs(ChartCard, { title: title, value: format.number(total), ...(sums.cached > 0 && {
|
|
139
137
|
note: t('@theorem.panel.trace.charts.cachedShare', {
|
|
140
|
-
share: percent
|
|
138
|
+
share: format.percent(sums.cached / input),
|
|
141
139
|
}),
|
|
142
140
|
}), children: [_jsx(Columns, { rows: rows, keys: TOKEN_KEYS.filter((key) => sums[key] > 0), fills: TOKEN_FILL, tip: (props) => _jsx(TokenTip, { ...props }) }), _jsx(Legend, { items: TOKEN_KEYS.filter((key) => sums[key] > 0).map((key) => ({
|
|
143
141
|
fill: TOKEN_FILL[key],
|
|
144
142
|
label: t(`@theorem.panel.trace.charts.${labels[key]}`),
|
|
145
|
-
value: compact
|
|
143
|
+
value: format.compact(sums[key]),
|
|
146
144
|
})) })] }));
|
|
147
145
|
}
|
|
148
146
|
/** A turn's model calls as token rows. */
|
|
@@ -219,7 +217,7 @@ function TurnTimeCard({ rows, isCalls }) {
|
|
|
219
217
|
return null;
|
|
220
218
|
return (_jsxs(ChartCard, { title: t(isCalls ? '@theorem.panel.trace.charts.callTime' : '@theorem.panel.trace.charts.turnTime'), value: format.duration(total), note: sums.model > 0
|
|
221
219
|
? t('@theorem.panel.trace.charts.modelShare', {
|
|
222
|
-
share: percent
|
|
220
|
+
share: format.percent(sums.model / total),
|
|
223
221
|
})
|
|
224
222
|
: undefined, children: [_jsx(Columns, { rows: rows, keys: SPLIT_KEYS, fills: SPLIT_FILL, tip: (props) => _jsx(TurnTimeTip, { ...props }) }), _jsx(SplitLegend, { split: sums, total: total })] }));
|
|
225
223
|
}
|
package/ui/TraceValues.d.ts
CHANGED
|
@@ -13,6 +13,10 @@ export declare function attributeSections(attributes: Readonly<Record<string, un
|
|
|
13
13
|
export interface TraceFormat {
|
|
14
14
|
t: LabelText;
|
|
15
15
|
number(value: number): string;
|
|
16
|
+
/** A count shortened, as `1.2K`. */
|
|
17
|
+
compact(value: number): string;
|
|
18
|
+
/** A share of one as a percentage. */
|
|
19
|
+
percent(share: number): string;
|
|
16
20
|
usd(value: number): string;
|
|
17
21
|
duration(ms: number): string;
|
|
18
22
|
list(items: readonly string[]): string;
|
package/ui/TraceValues.js
CHANGED
|
@@ -42,9 +42,16 @@ export function useTraceFormat() {
|
|
|
42
42
|
maximumFractionDigits: 6,
|
|
43
43
|
});
|
|
44
44
|
const list = new Intl.ListFormat(locale, { type: 'conjunction' });
|
|
45
|
+
const compact = new Intl.NumberFormat(locale, {
|
|
46
|
+
notation: 'compact',
|
|
47
|
+
maximumFractionDigits: 1,
|
|
48
|
+
});
|
|
49
|
+
const percent = new Intl.NumberFormat(locale, { style: 'percent' });
|
|
45
50
|
return {
|
|
46
51
|
t,
|
|
47
52
|
number: (value) => number.format(value),
|
|
53
|
+
compact: (value) => compact.format(value),
|
|
54
|
+
percent: (share) => percent.format(share),
|
|
48
55
|
usd: (value) => usd.format(value),
|
|
49
56
|
duration: (ms) => workDuration(t, ms),
|
|
50
57
|
list: (items) => list.format(items),
|
package/ui/approval-heading.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { ToolGate } from '@theoremjs/agents/kernel';
|
|
2
|
-
import type
|
|
2
|
+
import { type LabelText } from './labels.js';
|
|
3
3
|
/** "@concierge wants to check the weather": the tool's `labels.request`, else its name in words. */
|
|
4
4
|
export declare function approvalHeading(t: LabelText, gate: ToolGate, toolName: string, agent?: string): string;
|
package/ui/approval-heading.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { humanize } from '@theoremjs/web/client';
|
|
2
|
+
import { toolNameLabel } from "./labels.js";
|
|
2
3
|
/** "@concierge wants to check the weather": the tool's `labels.request`, else its name in words. */
|
|
3
4
|
export function approvalHeading(t, gate, toolName, agent) {
|
|
4
5
|
const request = gate.request ??
|
|
5
|
-
t('@theorem.gate.approval.use_tool', {
|
|
6
|
+
t('@theorem.gate.approval.use_tool', {
|
|
7
|
+
tool: toolNameLabel(t, toolName, humanize(toolName).toLowerCase()),
|
|
8
|
+
});
|
|
6
9
|
return agent
|
|
7
10
|
? t('@theorem.gate.approval.title', { agent, request })
|
|
8
11
|
: t('@theorem.gate.approval.title_no_agent', { request });
|
package/ui/labels.d.ts
CHANGED
|
@@ -443,6 +443,21 @@ export declare const THEOREM_UI_CATALOG: {
|
|
|
443
443
|
readonly defaultMessage: "oauth2";
|
|
444
444
|
readonly description: "Credential type tag.";
|
|
445
445
|
};
|
|
446
|
+
readonly '@theorem.tool.name': {
|
|
447
|
+
readonly defaultMessage: "{words}";
|
|
448
|
+
readonly description: "A tool's name where no activity label of its own says it. {tool} is the tool's name with each character other than a letter, digit, or _ written as _, for `select`; {words} is that name in words.";
|
|
449
|
+
readonly params: readonly ["tool", "words"];
|
|
450
|
+
};
|
|
451
|
+
readonly '@theorem.data.field': {
|
|
452
|
+
readonly defaultMessage: "{words}";
|
|
453
|
+
readonly description: "A field of a value drawn from its keys, with no schema title. {field} is the key with each character other than a letter, digit, or _ written as _, for `select`; {words} is the key in words.";
|
|
454
|
+
readonly params: readonly ["field", "words"];
|
|
455
|
+
};
|
|
456
|
+
readonly '@theorem.gate.auth.detail': {
|
|
457
|
+
readonly defaultMessage: "This needs your {service} account.";
|
|
458
|
+
readonly description: "Why the credential card asks. {service} is the service the tool signs in to.";
|
|
459
|
+
readonly params: readonly ["service"];
|
|
460
|
+
};
|
|
446
461
|
readonly '@theorem.gate.auth.title': {
|
|
447
462
|
readonly defaultMessage: "Sign in to use {tool}";
|
|
448
463
|
readonly description: "Credential card heading. {tool} is the tool's name in words.";
|
|
@@ -1518,6 +1533,12 @@ export type TheoremLabelOverrides = {
|
|
|
1518
1533
|
export type TheoremLabels = {
|
|
1519
1534
|
readonly [locale: string]: TheoremLabelOverrides | undefined;
|
|
1520
1535
|
};
|
|
1536
|
+
/** A tool's name as the person reads it: `@theorem.tool.name`, else `words`. */
|
|
1537
|
+
export declare function toolNameLabel(t: LabelText, tool: string, words?: string): string;
|
|
1538
|
+
/** Names the data keys the client words, through `@theorem.data.field`. */
|
|
1539
|
+
export declare function keyNamer(t: LabelText): (key: string, words: string) => string;
|
|
1540
|
+
/** A data key as a field's name: `@theorem.data.field`, else `words`. */
|
|
1541
|
+
export declare function fieldNameLabel(t: LabelText, field: string, words?: string): string;
|
|
1521
1542
|
/** A single kind is just its word ("queued"); a mix spells out each count ("2 queued · 1 attached"). */
|
|
1522
1543
|
export declare function composerDrawerLabel(t: LabelText, summary: ComposerDrawerSummary): string;
|
|
1523
1544
|
/** What a reply or a called agent used: its tokens, then its cost when the provider gave one. */
|
package/ui/labels.js
CHANGED
|
@@ -406,6 +406,21 @@ export const THEOREM_UI_CATALOG = {
|
|
|
406
406
|
'@theorem.gate.tag.bearer': { defaultMessage: 'bearer', description: 'Credential type tag.' },
|
|
407
407
|
'@theorem.gate.tag.api_key': { defaultMessage: 'api_key', description: 'Credential type tag.' },
|
|
408
408
|
'@theorem.gate.tag.oauth2': { defaultMessage: 'oauth2', description: 'Credential type tag.' },
|
|
409
|
+
'@theorem.tool.name': {
|
|
410
|
+
defaultMessage: '{words}',
|
|
411
|
+
description: "A tool's name where no activity label of its own says it. {tool} is the tool's name with each character other than a letter, digit, or _ written as _, for `select`; {words} is that name in words.",
|
|
412
|
+
params: ['tool', 'words'],
|
|
413
|
+
},
|
|
414
|
+
'@theorem.data.field': {
|
|
415
|
+
defaultMessage: '{words}',
|
|
416
|
+
description: 'A field of a value drawn from its keys, with no schema title. {field} is the key with each character other than a letter, digit, or _ written as _, for `select`; {words} is the key in words.',
|
|
417
|
+
params: ['field', 'words'],
|
|
418
|
+
},
|
|
419
|
+
'@theorem.gate.auth.detail': {
|
|
420
|
+
defaultMessage: 'This needs your {service} account.',
|
|
421
|
+
description: 'Why the credential card asks. {service} is the service the tool signs in to.',
|
|
422
|
+
params: ['service'],
|
|
423
|
+
},
|
|
409
424
|
'@theorem.gate.auth.title': {
|
|
410
425
|
defaultMessage: 'Sign in to use {tool}',
|
|
411
426
|
description: "Credential card heading. {tool} is the tool's name in words.",
|
|
@@ -1404,6 +1419,22 @@ export const THEOREM_UI_CATALOG = {
|
|
|
1404
1419
|
'@theorem.live.state.error': { defaultMessage: 'error', description: 'Call status.' },
|
|
1405
1420
|
'@theorem.live.state.ended': { defaultMessage: 'ended', description: 'Call status.' },
|
|
1406
1421
|
};
|
|
1422
|
+
// why: An ICU `select` case cannot hold punctuation such as `-` or `.`.
|
|
1423
|
+
function selectorOf(name) {
|
|
1424
|
+
return name.replace(/[^\p{L}\p{N}_]/gu, '_');
|
|
1425
|
+
}
|
|
1426
|
+
/** A tool's name as the person reads it: `@theorem.tool.name`, else `words`. */
|
|
1427
|
+
export function toolNameLabel(t, tool, words = humanize(tool)) {
|
|
1428
|
+
return t('@theorem.tool.name', { tool: selectorOf(tool), words });
|
|
1429
|
+
}
|
|
1430
|
+
/** Names the data keys the client words, through `@theorem.data.field`. */
|
|
1431
|
+
export function keyNamer(t) {
|
|
1432
|
+
return (key, words) => fieldNameLabel(t, key, words);
|
|
1433
|
+
}
|
|
1434
|
+
/** A data key as a field's name: `@theorem.data.field`, else `words`. */
|
|
1435
|
+
export function fieldNameLabel(t, field, words = humanize(field)) {
|
|
1436
|
+
return t('@theorem.data.field', { field: selectorOf(field), words });
|
|
1437
|
+
}
|
|
1407
1438
|
/** A single kind is just its word ("queued"); a mix spells out each count ("2 queued · 1 attached"). */
|
|
1408
1439
|
export function composerDrawerLabel(t, summary) {
|
|
1409
1440
|
const [only] = summary.parts;
|
|
@@ -1487,7 +1518,9 @@ export function workStatusLabel(t, status) {
|
|
|
1487
1518
|
export function liveStateLabel(t, state, tool) {
|
|
1488
1519
|
if (state === 'calling_tool') {
|
|
1489
1520
|
return (tool?.activity ??
|
|
1490
|
-
t('@theorem.live.state.calling_tool', {
|
|
1521
|
+
t('@theorem.live.state.calling_tool', {
|
|
1522
|
+
tool: toolNameLabel(t, tool?.name ?? '', humanize(tool?.name ?? '').toLowerCase()),
|
|
1523
|
+
}));
|
|
1491
1524
|
}
|
|
1492
1525
|
return t(`@theorem.live.state.${state}`);
|
|
1493
1526
|
}
|