@theoremjs/react 0.3.5-next.985.g0bae771 → 0.3.5-next.987.ge2681d2
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/package.json +3 -3
- package/ui/ChatTranscript.d.ts +6 -0
- package/ui/ChatTranscript.js +28 -17
- package/ui/TheoremChat.d.ts +1 -1
- package/ui/TheoremChat.js +2 -2
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.987.ge2681d2",
|
|
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.987.ge2681d2",
|
|
64
|
+
"@theoremjs/web": "^0.3.5-next.987.ge2681d2"
|
|
65
65
|
},
|
|
66
66
|
"peerDependenciesMeta": {
|
|
67
67
|
"@astryxdesign/core": {
|
package/ui/ChatTranscript.d.ts
CHANGED
|
@@ -40,6 +40,12 @@ export type ChatTranscriptProps = {
|
|
|
40
40
|
* on an agent tool's call row what the agent it ran used. Off by default.
|
|
41
41
|
*/
|
|
42
42
|
usage?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* The profile's `tools.showData` (`iface.tools.showData`): whether a tool call's row opens on its
|
|
45
|
+
* detail, what it ran with, the calls its agent made, and what came back. On by default. Off, each
|
|
46
|
+
* call is its labelled row only, and an approval shows no input: the server sent none.
|
|
47
|
+
*/
|
|
48
|
+
showToolData?: boolean;
|
|
43
49
|
/**
|
|
44
50
|
* Where body kinds sit in a reply. Default puts `citation` last (Sources under
|
|
45
51
|
* the prose). Pass `{}` to keep stream order for inline citations.
|
package/ui/ChatTranscript.js
CHANGED
|
@@ -38,6 +38,12 @@ import { transcriptBlockCopyText } from "./transcript-copy-text.js";
|
|
|
38
38
|
import { VoiceNote } from "./VoiceNote.js";
|
|
39
39
|
/** Whether the transcript shows usage (`ChatTranscriptProps.usage`). */
|
|
40
40
|
const ShowUsage = createContext(false);
|
|
41
|
+
/** Whether a tool call's row opens on its detail (`ChatTranscriptProps.showToolData`). */
|
|
42
|
+
const ShowToolData = createContext(true);
|
|
43
|
+
/** What the transcript's props say a tool call's row shows. */
|
|
44
|
+
function useToolRowShows() {
|
|
45
|
+
return { usage: useContext(ShowUsage), detail: useContext(ShowToolData) };
|
|
46
|
+
}
|
|
41
47
|
/** Largest a generated image renders in the transcript. */
|
|
42
48
|
const GENERATED_IMAGE_MAX_WIDTH = 512;
|
|
43
49
|
function CopyButton({ text }) {
|
|
@@ -423,8 +429,8 @@ function toolDetail(t, tool, result) {
|
|
|
423
429
|
/** The calls an agent tool's agent made, each a call row of its own. */
|
|
424
430
|
function ToolSteps({ steps }) {
|
|
425
431
|
const t = useLabels();
|
|
426
|
-
const
|
|
427
|
-
return (_jsxs(VStack, { gap: 2, children: [_jsx(Text, { type: "supporting", color: "secondary", children: t('@theorem.transcript.tool_steps') }), _jsx(ToolCalls, { calls: steps.map((step) => toolCallItem(t, step.operationId ?? step.callId, step,
|
|
432
|
+
const shows = useToolRowShows();
|
|
433
|
+
return (_jsxs(VStack, { gap: 2, children: [_jsx(Text, { type: "supporting", color: "secondary", children: t('@theorem.transcript.tool_steps') }), _jsx(ToolCalls, { calls: steps.map((step) => toolCallItem(t, step.operationId ?? step.callId, step, shows)) })] }));
|
|
428
434
|
}
|
|
429
435
|
/** How long a finished call ran, when both ends were seen. */
|
|
430
436
|
function toolDuration(t, tool) {
|
|
@@ -433,8 +439,8 @@ function toolDuration(t, tool) {
|
|
|
433
439
|
return { duration: workDuration(t, tool.endedAt - tool.startedAt) };
|
|
434
440
|
}
|
|
435
441
|
/** What the agent an agent tool ran used, after the call's name. Only agent tools report it. */
|
|
436
|
-
function toolUsageStats(state,
|
|
437
|
-
return
|
|
442
|
+
function toolUsageStats(state, shows) {
|
|
443
|
+
return shows.usage && state.tokens ? { stats: _jsx(Usage, { tokens: state.tokens }) } : {};
|
|
438
444
|
}
|
|
439
445
|
// why: The row already reads the failure's message, and `error` is the person's wording of the
|
|
440
446
|
// same failure, so the detail holds only what the row does not say.
|
|
@@ -445,7 +451,11 @@ function failureDetail(failure) {
|
|
|
445
451
|
...(failure.details === undefined ? {} : { details: failure.details }),
|
|
446
452
|
};
|
|
447
453
|
}
|
|
448
|
-
|
|
454
|
+
/** A call's detail as its row takes it: none when the transcript shows no tool detail. */
|
|
455
|
+
function rowDetail(t, tool, shows, result) {
|
|
456
|
+
return shows.detail ? { resultDetail: toolDetail(t, tool, result) } : {};
|
|
457
|
+
}
|
|
458
|
+
function toolCallItem(t, id, tool, shows) {
|
|
449
459
|
const base = { key: id, name: toolCallLabel(tool) };
|
|
450
460
|
const { state } = tool;
|
|
451
461
|
switch (state?.phase) {
|
|
@@ -454,29 +464,29 @@ function toolCallItem(t, id, tool, showUsage) {
|
|
|
454
464
|
...base,
|
|
455
465
|
status: 'error',
|
|
456
466
|
target: state.failure.message,
|
|
457
|
-
...toolUsageStats(state,
|
|
467
|
+
...toolUsageStats(state, shows),
|
|
458
468
|
errorMessage: state.failure.message,
|
|
459
|
-
|
|
469
|
+
...rowDetail(t, tool, shows, _jsx(ShapedData, { value: failureDetail(state.failure), title: t('@theorem.transcript.tool_error') })),
|
|
460
470
|
};
|
|
461
471
|
case 'complete':
|
|
462
472
|
return {
|
|
463
473
|
...base,
|
|
464
474
|
status: 'complete',
|
|
465
475
|
...toolDuration(t, tool),
|
|
466
|
-
...toolUsageStats(state,
|
|
467
|
-
|
|
476
|
+
...toolUsageStats(state, shows),
|
|
477
|
+
...rowDetail(t, tool, shows, state.output === undefined ? undefined : (_jsx(ShapedData, { value: state.output, title: t('@theorem.transcript.tool_output') }))),
|
|
468
478
|
};
|
|
469
479
|
case 'running':
|
|
470
480
|
case 'background':
|
|
471
|
-
return { ...base, status: 'running',
|
|
481
|
+
return { ...base, status: 'running', ...rowDetail(t, tool, shows) };
|
|
472
482
|
default:
|
|
473
|
-
return { ...base, status: 'pending',
|
|
483
|
+
return { ...base, status: 'pending', ...rowDetail(t, tool, shows) };
|
|
474
484
|
}
|
|
475
485
|
}
|
|
476
486
|
function ToolCall({ tool }) {
|
|
477
487
|
const t = useLabels();
|
|
478
|
-
const
|
|
479
|
-
return _jsx(ToolCalls, { calls: [toolCallItem(t, tool.name, tool,
|
|
488
|
+
const shows = useToolRowShows();
|
|
489
|
+
return _jsx(ToolCalls, { calls: [toolCallItem(t, tool.name, tool, shows)] });
|
|
480
490
|
}
|
|
481
491
|
/**
|
|
482
492
|
* Thinking reads as quieter text than the reply. Astryx has no reasoning
|
|
@@ -494,7 +504,7 @@ const THOUGHT_TEXT = {
|
|
|
494
504
|
};
|
|
495
505
|
function TraceList({ items, streaming }) {
|
|
496
506
|
const t = useLabels();
|
|
497
|
-
const
|
|
507
|
+
const shows = useToolRowShows();
|
|
498
508
|
const rows = [];
|
|
499
509
|
let tools = [];
|
|
500
510
|
const flush = () => {
|
|
@@ -505,7 +515,7 @@ function TraceList({ items, streaming }) {
|
|
|
505
515
|
};
|
|
506
516
|
for (const [i, item] of items.entries()) {
|
|
507
517
|
if (item.kind === 'tool') {
|
|
508
|
-
tools.push(toolCallItem(t, item.id, item.block.tool,
|
|
518
|
+
tools.push(toolCallItem(t, item.id, item.block.tool, shows));
|
|
509
519
|
continue;
|
|
510
520
|
}
|
|
511
521
|
flush();
|
|
@@ -527,6 +537,7 @@ function answerSent(answering, tool) {
|
|
|
527
537
|
}
|
|
528
538
|
function GateCard({ block, handle, handlers, }) {
|
|
529
539
|
const { tool } = block;
|
|
540
|
+
const shows = useToolRowShows();
|
|
530
541
|
const gate = personGate(tool);
|
|
531
542
|
if (!gate)
|
|
532
543
|
return null;
|
|
@@ -535,7 +546,7 @@ function GateCard({ block, handle, handlers, }) {
|
|
|
535
546
|
if (gate.kind === 'auth') {
|
|
536
547
|
return (_jsx(AuthChallengeCard, { gate: gate, toolName: tool.name, submitted: answer === 'auth', onAuthenticated: (secret) => handlers.onAuthenticated?.(index, secret) }));
|
|
537
548
|
}
|
|
538
|
-
return (_jsx(ApprovalCard, { gate: gate, toolName: tool.name, agent: handle, input: tool.arguments, decided: answer === 'auth' ? null : answer, onDecision: (action) => handlers.onToolDecision?.(index, action) }));
|
|
549
|
+
return (_jsx(ApprovalCard, { gate: gate, toolName: tool.name, agent: handle, ...(shows.detail ? { input: tool.arguments } : {}), decided: answer === 'auth' ? null : answer, onDecision: (action) => handlers.onToolDecision?.(index, action) }));
|
|
539
550
|
}
|
|
540
551
|
/** Live elapsed time while the turn streams; its final duration once it ends. */
|
|
541
552
|
/** Live: counted from the start. Stopped: the work its blocks record. */
|
|
@@ -625,7 +636,7 @@ function isBareFailure(group) {
|
|
|
625
636
|
}
|
|
626
637
|
/** Theorem transcript blocks rendered as Astryx chat messages. */
|
|
627
638
|
export function ChatTranscript(props) {
|
|
628
|
-
return (_jsx(TheoremLabelsProvider, { children: _jsx(ShowUsage.Provider, { value: props.usage === true, children: _jsx(ChatTranscriptBody, { ...props }) }) }));
|
|
639
|
+
return (_jsx(TheoremLabelsProvider, { children: _jsx(ShowUsage.Provider, { value: props.usage === true, children: _jsx(ShowToolData.Provider, { value: props.showToolData !== false, children: _jsx(ChatTranscriptBody, { ...props }) }) }) }));
|
|
629
640
|
}
|
|
630
641
|
function ChatTranscriptBody({ blocks, handle, streaming = false, delivery, onToolDecision, answering = null, onAuthenticated, emptyState, dividers, imageOutput, bodyKindPlacement, labels, clock, }) {
|
|
631
642
|
const groups = useMemo(() => groupTranscriptBlocks(blocks, dividers && new Set(Object.keys(dividers))), [blocks, dividers]);
|
package/ui/TheoremChat.d.ts
CHANGED
|
@@ -180,7 +180,7 @@ export type TheoremChatComposerProps = {
|
|
|
180
180
|
* `TheoremChatTranscript`.
|
|
181
181
|
*/
|
|
182
182
|
export declare function TheoremChatComposer({ chat, iface, placeholder, inputRef, layout, icons, }: TheoremChatComposerProps): import("react").JSX.Element;
|
|
183
|
-
export type TheoremChatTranscriptProps = Omit<ChatTranscriptProps, 'blocks' | 'handle' | 'streaming' | 'delivery' | 'answering' | 'clock' | 'onToolDecision' | 'onAuthenticated' | 'imageOutput' | 'labels'> & {
|
|
183
|
+
export type TheoremChatTranscriptProps = Omit<ChatTranscriptProps, 'blocks' | 'handle' | 'streaming' | 'delivery' | 'answering' | 'clock' | 'onToolDecision' | 'onAuthenticated' | 'imageOutput' | 'labels' | 'showToolData'> & {
|
|
184
184
|
/** The chat it shows (`useTheoremChat`). */
|
|
185
185
|
chat: TheoremChatState;
|
|
186
186
|
/** The profile's interface (`useTheoremInterface`). */
|
package/ui/TheoremChat.js
CHANGED
|
@@ -5,7 +5,7 @@ import { ChatLayout } from '@astryxdesign/core/Chat';
|
|
|
5
5
|
import { Layout, LayoutContent } from '@astryxdesign/core/Layout';
|
|
6
6
|
import { Text } from '@astryxdesign/core/Text';
|
|
7
7
|
import { VStack } from '@astryxdesign/core/VStack';
|
|
8
|
-
import { removeComposerPendingMessage, } from '@theoremjs/agents/interface';
|
|
8
|
+
import { interfaceShowsToolData, removeComposerPendingMessage, } from '@theoremjs/agents/interface';
|
|
9
9
|
import { createHttpTransport, } from '@theoremjs/web/client';
|
|
10
10
|
import { useImperativeHandle, useMemo, useRef, } from 'react';
|
|
11
11
|
import { parseAspectRatio } from "../client/image-output.js";
|
|
@@ -130,7 +130,7 @@ function ChatThread({ composer, composerRef, maxWidth, chat, iface, handle, dens
|
|
|
130
130
|
*/
|
|
131
131
|
export function TheoremChatTranscript({ chat, iface, handle, ...props }) {
|
|
132
132
|
const t = useLabels();
|
|
133
|
-
return (_jsx(ChatTranscript, { ...props, handle: handle ?? t('@theorem.agent.handle', { handle: iface.identity.handle }), blocks: chat.shownBlocks, streaming: chat.streaming, delivery: chat.delivery, answering: chat.answering, clock: chat.turnClock, labels: iface.labels, imageOutput: iface.type === 'image' ? { ratio: parseAspectRatio(iface.image.aspectRatio) } : undefined, onToolDecision: (index, action) => {
|
|
133
|
+
return (_jsx(ChatTranscript, { ...props, handle: handle ?? t('@theorem.agent.handle', { handle: iface.identity.handle }), blocks: chat.shownBlocks, streaming: chat.streaming, delivery: chat.delivery, answering: chat.answering, clock: chat.turnClock, labels: iface.labels, showToolData: interfaceShowsToolData(iface), imageOutput: iface.type === 'image' ? { ratio: parseAspectRatio(iface.image.aspectRatio) } : undefined, onToolDecision: (index, action) => {
|
|
134
134
|
void chat.handleToolDecision(index, action);
|
|
135
135
|
}, onAuthenticated: (index, secret) => {
|
|
136
136
|
void chat.handleAuthenticated(index, secret);
|