@theoremjs/react 0.3.5-next.1024.g444d79c → 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 +27 -3
- 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/composer-refs.js +222 -22
- package/ui/labels.d.ts +21 -0
- package/ui/labels.js +34 -1
package/README.md
CHANGED
|
@@ -252,14 +252,22 @@ import { refToken, TheoremChat } from '@theoremjs/react/ui';
|
|
|
252
252
|
| `renderRef` | Draws a ref, as a chip in the composer and in the person's message. Without it, the chip is a badge and the message shows as text. |
|
|
253
253
|
| `refText` | Writes a ref into the message's text. Default: the id. Give the server the same one. |
|
|
254
254
|
|
|
255
|
-
To put a ref in the field from your own button, hold an `inputRef` and call `inputRef.current.insertToken(refToken({ kind, id }))`. Only a chip that `refToken` made is a ref. Typed text is never read as one. A click on a chip can leave the caret inside it. `insertToken` and `insertText` on your `inputRef` then
|
|
255
|
+
To put a ref in the field from your own button, hold an `inputRef` and call `inputRef.current.insertToken(refToken({ kind, id }))`. Only a chip that `refToken` made is a ref. Typed text is never read as one. A click on a chip can leave the caret inside it. Typing, pasting, and `insertToken` and `insertText` on your `inputRef` then land just after that chip, never inside it.
|
|
256
256
|
|
|
257
|
-
The draft keeps its refs, so a composer drawn again from a saved draft shows its chips again. This holds for a stashed or queued message that you restore.
|
|
257
|
+
The draft keeps its refs, so a composer drawn again from a saved draft shows its chips again. This holds for a stashed or queued message that you restore.
|
|
258
|
+
|
|
259
|
+
Chips also stay in these two cases:
|
|
260
|
+
|
|
261
|
+
- The up arrow brings back a sent message with its chips. The down arrow brings back your draft with its chips.
|
|
262
|
+
- Text that you copy or cut in a composer, and paste in a composer on the same page, keeps its chips. A paste from anywhere else is plain text.
|
|
263
|
+
|
|
264
|
+
Your own input must keep the markup of Astryx's tokens (`data-astryx-token`) and its handle.
|
|
258
265
|
|
|
259
266
|
Limits:
|
|
260
267
|
|
|
261
268
|
- A call sends a typed line as text. Its refs reach the model as that text.
|
|
262
|
-
- The up
|
|
269
|
+
- The up arrow brings back the messages that the field itself keeps: those you send with Enter. It matches them by their words: if two have the same words, both come back with the later one's refs.
|
|
270
|
+
- A paste in another tab or another app is plain text.
|
|
263
271
|
|
|
264
272
|
### Tool media
|
|
265
273
|
|
|
@@ -694,6 +702,22 @@ Use `labels` to replace any message, for each locale:
|
|
|
694
702
|
- a key is not in `@theorem.*` or `@astryx.*`
|
|
695
703
|
- Labels are shown as text. They are never shown as HTML.
|
|
696
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
|
+
|
|
697
721
|
## More documentation
|
|
698
722
|
|
|
699
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/composer-refs.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Badge } from '@astryxdesign/core/Badge';
|
|
3
|
-
import { hasRef, refIdText, textOfParts, } from '@theoremjs/agents/interface';
|
|
3
|
+
import { hasRef, messageParts, refIdText, textOfParts, } from '@theoremjs/agents/interface';
|
|
4
4
|
import { createContext, useCallback, useContext, useEffect, useLayoutEffect, useRef, } from 'react';
|
|
5
5
|
// invariant: This file is the one that reads the input's own markup, which a host's input keeps.
|
|
6
6
|
const TOKEN = '[data-astryx-token]';
|
|
@@ -39,7 +39,7 @@ function addWords(parts, text) {
|
|
|
39
39
|
else if (text)
|
|
40
40
|
parts.push({ type: 'text', text });
|
|
41
41
|
}
|
|
42
|
-
function readElement(element, parts) {
|
|
42
|
+
function readElement(element, parts, range) {
|
|
43
43
|
if (element.matches(TOKEN)) {
|
|
44
44
|
const ref = tokenRefs.get(element);
|
|
45
45
|
if (ref)
|
|
@@ -50,26 +50,34 @@ function readElement(element, parts) {
|
|
|
50
50
|
else if (element.tagName === 'BR')
|
|
51
51
|
addWords(parts, '\n');
|
|
52
52
|
else
|
|
53
|
-
readInto(element, parts);
|
|
53
|
+
readInto(element, parts, range);
|
|
54
54
|
}
|
|
55
|
-
|
|
55
|
+
/** The text of `node`, cut to what `range` selects of it. */
|
|
56
|
+
function textIn(node, range) {
|
|
57
|
+
const text = node.textContent ?? '';
|
|
58
|
+
const from = range?.startContainer === node ? range.startOffset : 0;
|
|
59
|
+
const to = range?.endContainer === node ? range.endOffset : text.length;
|
|
60
|
+
return text.slice(from, to);
|
|
61
|
+
}
|
|
62
|
+
/** Reads `node` into `parts`; with a `range`, only what it selects. */
|
|
63
|
+
function readInto(node, parts, range) {
|
|
56
64
|
for (const child of node.childNodes) {
|
|
65
|
+
if (range && !range.intersectsNode(child))
|
|
66
|
+
continue;
|
|
57
67
|
if (child.nodeType === 3)
|
|
58
|
-
addWords(parts, child
|
|
68
|
+
addWords(parts, textIn(child, range));
|
|
59
69
|
else if (child.nodeType === 1)
|
|
60
|
-
readElement(child, parts);
|
|
70
|
+
readElement(child, parts, range);
|
|
61
71
|
}
|
|
62
72
|
}
|
|
63
73
|
/** The editor's words and refs, as the input's own value reads them; undefined with no ref. */
|
|
64
|
-
function readEditorParts(editor) {
|
|
74
|
+
function readEditorParts(editor, range) {
|
|
65
75
|
const parts = [];
|
|
66
|
-
readInto(editor, parts);
|
|
76
|
+
readInto(editor, parts, range);
|
|
67
77
|
return hasRef(parts) ? parts : undefined;
|
|
68
78
|
}
|
|
69
|
-
/**
|
|
70
|
-
function
|
|
71
|
-
const focused = editor.ownerDocument.activeElement === editor;
|
|
72
|
-
editor.textContent = '';
|
|
79
|
+
/** Puts `parts` in at the caret through the input's handle, each ref a chip again. */
|
|
80
|
+
function insertParts(editor, handle, parts, options) {
|
|
73
81
|
for (const part of parts) {
|
|
74
82
|
if (part.type === 'text') {
|
|
75
83
|
handle.insertText(part.text);
|
|
@@ -80,9 +88,15 @@ function writeEditorParts(editor, handle, parts, options) {
|
|
|
80
88
|
if (!token)
|
|
81
89
|
continue;
|
|
82
90
|
tokenRefs.set(token, part);
|
|
83
|
-
// why: The input adds a space after each token; the
|
|
91
|
+
// why: The input adds a space after each token; the parts' own words already hold theirs.
|
|
84
92
|
token.nextSibling?.remove();
|
|
85
93
|
}
|
|
94
|
+
}
|
|
95
|
+
/** Fills an empty editor with `parts`, leaving focus where it was. */
|
|
96
|
+
function writeEditorParts(editor, handle, parts, options) {
|
|
97
|
+
const focused = editor.ownerDocument.activeElement === editor;
|
|
98
|
+
editor.textContent = '';
|
|
99
|
+
insertParts(editor, handle, parts, options);
|
|
86
100
|
if (!focused)
|
|
87
101
|
editor.blur();
|
|
88
102
|
}
|
|
@@ -134,6 +148,172 @@ function outsideChips(input, editor) {
|
|
|
134
148
|
getValue: () => input.getValue(),
|
|
135
149
|
};
|
|
136
150
|
}
|
|
151
|
+
/** The editor's selection, when it has one. */
|
|
152
|
+
function selectionIn(editor) {
|
|
153
|
+
const selection = editor.ownerDocument.defaultView?.getSelection();
|
|
154
|
+
if (!selection?.rangeCount)
|
|
155
|
+
return undefined;
|
|
156
|
+
const range = selection.getRangeAt(0);
|
|
157
|
+
return editor.contains(range.commonAncestorContainer) ? range : undefined;
|
|
158
|
+
}
|
|
159
|
+
function selectAll(editor) {
|
|
160
|
+
const selection = editor.ownerDocument.defaultView?.getSelection();
|
|
161
|
+
const range = editor.ownerDocument.createRange();
|
|
162
|
+
range.selectNodeContents(editor);
|
|
163
|
+
selection?.removeAllRanges();
|
|
164
|
+
selection?.addRange(range);
|
|
165
|
+
}
|
|
166
|
+
// invariant: The clipboard carries only a key; the refs stay in memory, so a paste can make no ref
|
|
167
|
+
// that was not copied from a composer on this page.
|
|
168
|
+
const CLIP = 'application/x-theorem-parts';
|
|
169
|
+
let clipped;
|
|
170
|
+
/** What the editor has selected, as a range holding any chip it touches whole. */
|
|
171
|
+
function wholeChips(editor) {
|
|
172
|
+
const selected = selectionIn(editor);
|
|
173
|
+
if (!selected || selected.collapsed)
|
|
174
|
+
return undefined;
|
|
175
|
+
const range = selected.cloneRange();
|
|
176
|
+
const start = chipAround(editor, range.startContainer);
|
|
177
|
+
const end = chipAround(editor, range.endContainer);
|
|
178
|
+
if (start)
|
|
179
|
+
range.setStartBefore(start);
|
|
180
|
+
if (end)
|
|
181
|
+
range.setEndAfter(end);
|
|
182
|
+
return range;
|
|
183
|
+
}
|
|
184
|
+
/** Copies a selection that holds a chip; any other is left to the browser. */
|
|
185
|
+
function copyChips(editor, event, refText) {
|
|
186
|
+
const range = wholeChips(editor);
|
|
187
|
+
const parts = range && readEditorParts(editor, range);
|
|
188
|
+
if (!range || !parts || !event.clipboardData)
|
|
189
|
+
return;
|
|
190
|
+
// why: Not `randomUUID`, which a page served over plain HTTP lacks.
|
|
191
|
+
clipped = { key: `${Date.now()}-${Math.random()}`, parts };
|
|
192
|
+
event.clipboardData.setData('text/plain', textOfParts(parts, refText));
|
|
193
|
+
event.clipboardData.setData(CLIP, clipped.key);
|
|
194
|
+
event.preventDefault();
|
|
195
|
+
event.stopPropagation();
|
|
196
|
+
if (event.type !== 'cut' || editor.getAttribute('contenteditable') === 'false')
|
|
197
|
+
return;
|
|
198
|
+
range.deleteContents();
|
|
199
|
+
editor.dispatchEvent(new Event('input', { bubbles: true }));
|
|
200
|
+
}
|
|
201
|
+
/** The parts a paste brings from a composer; undefined for anything from elsewhere. */
|
|
202
|
+
function pastedParts(event) {
|
|
203
|
+
const key = event.clipboardData?.getData(CLIP);
|
|
204
|
+
return key && key === clipped?.key ? clipped.parts : undefined;
|
|
205
|
+
}
|
|
206
|
+
/** Pastes a composer's copy as chips; an outside paste goes on to the input, past any chip. */
|
|
207
|
+
function pasteChips(editor, event, field) {
|
|
208
|
+
leaveChips(editor);
|
|
209
|
+
const parts = pastedParts(event);
|
|
210
|
+
const handle = field.handle();
|
|
211
|
+
if (!parts || !handle)
|
|
212
|
+
return;
|
|
213
|
+
event.preventDefault();
|
|
214
|
+
event.stopPropagation();
|
|
215
|
+
if (editor.getAttribute('contenteditable') === 'false')
|
|
216
|
+
return;
|
|
217
|
+
insertParts(editor, handle, parts, field.options());
|
|
218
|
+
field.read();
|
|
219
|
+
}
|
|
220
|
+
/** Typing with the caret in a chip goes after it, never inside. */
|
|
221
|
+
function typePastChips(editor, event, field) {
|
|
222
|
+
if (event.isComposing || !event.inputType.startsWith('insert'))
|
|
223
|
+
return;
|
|
224
|
+
const at = selectionIn(editor)?.startContainer;
|
|
225
|
+
if (!at || !chipAround(editor, at))
|
|
226
|
+
return;
|
|
227
|
+
if (event.inputType !== 'insertText' || !event.data) {
|
|
228
|
+
leaveChips(editor);
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
event.preventDefault();
|
|
232
|
+
event.stopPropagation();
|
|
233
|
+
field.handle()?.insertText(event.data);
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Moves the caret out of a chip before a key writes: a chip takes no input, so the browser would
|
|
237
|
+
* drop the character.
|
|
238
|
+
*/
|
|
239
|
+
function keyPastChips(editor, event) {
|
|
240
|
+
const writes = event.key.length === 1 || event.key === 'Process' || event.key === 'Unidentified';
|
|
241
|
+
if (writes && !event.ctrlKey && !event.metaKey)
|
|
242
|
+
leaveChips(editor);
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Hears the field's own events before the input does. On the document, so a field drawn again
|
|
246
|
+
* needs no new listeners.
|
|
247
|
+
*/
|
|
248
|
+
function listenToField(field) {
|
|
249
|
+
const heard = [
|
|
250
|
+
['copy', (editor, e) => copyChips(editor, e, field.options().refText)],
|
|
251
|
+
['cut', (editor, e) => copyChips(editor, e, field.options().refText)],
|
|
252
|
+
['paste', (editor, e) => pasteChips(editor, e, field)],
|
|
253
|
+
['beforeinput', (editor, e) => typePastChips(editor, e, field)],
|
|
254
|
+
[
|
|
255
|
+
'keydown',
|
|
256
|
+
(editor, e) => {
|
|
257
|
+
const event = e;
|
|
258
|
+
keyPastChips(editor, event);
|
|
259
|
+
field.key(event.key, event.shiftKey);
|
|
260
|
+
},
|
|
261
|
+
],
|
|
262
|
+
['keyup', () => field.released()],
|
|
263
|
+
];
|
|
264
|
+
const page = field.editor()?.ownerDocument ?? document;
|
|
265
|
+
const added = heard.map(([type, act]) => {
|
|
266
|
+
const listener = (event) => {
|
|
267
|
+
const editor = field.editor();
|
|
268
|
+
if (editor && event.composedPath().includes(editor))
|
|
269
|
+
act(editor, event);
|
|
270
|
+
};
|
|
271
|
+
page.addEventListener(type, listener, true);
|
|
272
|
+
return () => page.removeEventListener(type, listener, true);
|
|
273
|
+
});
|
|
274
|
+
return () => {
|
|
275
|
+
for (const remove of added)
|
|
276
|
+
remove();
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* The refs of messages sent from the field, by their words: the input's ↑ history keeps words
|
|
281
|
+
* alone. Two sent with the same words give back the later one's refs.
|
|
282
|
+
*/
|
|
283
|
+
function useRecall(editor, words) {
|
|
284
|
+
const kept = useRef(new Map());
|
|
285
|
+
const recalling = useRef(false);
|
|
286
|
+
const reselect = useRef(false);
|
|
287
|
+
return useRef({
|
|
288
|
+
key(key, shift) {
|
|
289
|
+
recalling.current = key === 'ArrowUp' || key === 'ArrowDown';
|
|
290
|
+
const sends = key === 'Enter' && !shift;
|
|
291
|
+
const field = editor();
|
|
292
|
+
if (!field || !(sends || recalling.current))
|
|
293
|
+
return;
|
|
294
|
+
const parts = messageParts(readEditorParts(field));
|
|
295
|
+
if (parts)
|
|
296
|
+
kept.current.set(words().trim(), parts);
|
|
297
|
+
else if (sends)
|
|
298
|
+
kept.current.delete(words().trim());
|
|
299
|
+
},
|
|
300
|
+
released() {
|
|
301
|
+
recalling.current = false;
|
|
302
|
+
},
|
|
303
|
+
/** The refs of `text`, when an arrow key has just brought it back. */
|
|
304
|
+
recalled(text) {
|
|
305
|
+
const parts = recalling.current ? kept.current.get(text.trim()) : undefined;
|
|
306
|
+
reselect.current = Boolean(parts);
|
|
307
|
+
return parts;
|
|
308
|
+
},
|
|
309
|
+
/** Selects a recalled message again, so the next ↑ steps on as the input's own recall does. */
|
|
310
|
+
written(field) {
|
|
311
|
+
if (reselect.current)
|
|
312
|
+
selectAll(field);
|
|
313
|
+
reselect.current = false;
|
|
314
|
+
},
|
|
315
|
+
}).current;
|
|
316
|
+
}
|
|
137
317
|
/**
|
|
138
318
|
* Keeps a draft's refs with its input: reads them as the person edits, and makes their chips again
|
|
139
319
|
* when the input is drawn from a saved draft, which it would otherwise show as plain text.
|
|
@@ -144,27 +324,46 @@ export function useEditorRefs(args) {
|
|
|
144
324
|
const handle = useRef(null);
|
|
145
325
|
const writing = useRef(false);
|
|
146
326
|
const drawnAs = useRef(args.drawn);
|
|
327
|
+
const editor = useCallback(() => editorIn(latest.current.rootRef.current), []);
|
|
147
328
|
const { inputRef } = args;
|
|
148
329
|
const handleRef = useCallback((input) => {
|
|
149
330
|
// why: An insert with the caret in a chip, as after a click on it, would nest a chip in it.
|
|
150
|
-
const node = input && outsideChips(input,
|
|
331
|
+
const node = input && outsideChips(input, editor);
|
|
151
332
|
handle.current = node;
|
|
152
333
|
if (typeof inputRef === 'function')
|
|
153
334
|
inputRef(node);
|
|
154
335
|
else if (inputRef)
|
|
155
336
|
inputRef.current = node;
|
|
156
|
-
}, [inputRef]);
|
|
337
|
+
}, [inputRef, editor]);
|
|
157
338
|
const report = useCallback(() => {
|
|
158
|
-
const
|
|
159
|
-
if (
|
|
160
|
-
latest.current.onParts?.(readEditorParts(
|
|
161
|
-
}, []);
|
|
339
|
+
const field = editor();
|
|
340
|
+
if (field && !writing.current)
|
|
341
|
+
latest.current.onParts?.(readEditorParts(field));
|
|
342
|
+
}, [editor]);
|
|
343
|
+
const recall = useRecall(editor, () => handle.current?.getValue() ?? '');
|
|
162
344
|
const onChange = useCallback((text) => {
|
|
163
345
|
if (writing.current)
|
|
164
346
|
return;
|
|
165
347
|
latest.current.onChange(text);
|
|
166
|
-
|
|
167
|
-
|
|
348
|
+
const parts = recall.recalled(text);
|
|
349
|
+
if (parts)
|
|
350
|
+
latest.current.onParts?.(parts);
|
|
351
|
+
else
|
|
352
|
+
report();
|
|
353
|
+
}, [report, recall]);
|
|
354
|
+
useEffect(() => listenToField({
|
|
355
|
+
editor,
|
|
356
|
+
handle: () => handle.current,
|
|
357
|
+
options: () => latest.current,
|
|
358
|
+
read: () => {
|
|
359
|
+
const text = handle.current?.getValue();
|
|
360
|
+
if (text !== undefined && text !== latest.current.value)
|
|
361
|
+
latest.current.onChange(text);
|
|
362
|
+
report();
|
|
363
|
+
},
|
|
364
|
+
key: recall.key,
|
|
365
|
+
released: recall.released,
|
|
366
|
+
}), [editor, report, recall]);
|
|
168
367
|
const { value, parts, drawn } = args;
|
|
169
368
|
useEffect(() => {
|
|
170
369
|
const editor = editorIn(latest.current.rootRef.current);
|
|
@@ -189,7 +388,8 @@ export function useEditorRefs(args) {
|
|
|
189
388
|
if (written !== value)
|
|
190
389
|
latest.current.onChange(written);
|
|
191
390
|
report();
|
|
192
|
-
|
|
391
|
+
recall.written(editor);
|
|
392
|
+
}, [value, parts, drawn, report, recall]);
|
|
193
393
|
return {
|
|
194
394
|
handleRef,
|
|
195
395
|
handle,
|
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
|
}
|