@theoremjs/react 0.0.0-stage → 0.3.1
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/LICENSE +21 -0
- package/README.md +772 -2
- package/client/attachment-hover-preview.d.ts +11 -0
- package/client/attachment-hover-preview.js +36 -0
- package/client/audio-level.d.ts +5 -0
- package/client/audio-level.js +24 -0
- package/client/composer-attachments.d.ts +30 -0
- package/client/composer-attachments.js +33 -0
- package/client/composer-drawer.d.ts +19 -0
- package/client/composer-drawer.js +15 -0
- package/client/composer-hints.d.ts +25 -0
- package/client/composer-hints.js +20 -0
- package/client/composer-primary.d.ts +16 -0
- package/client/composer-primary.js +25 -0
- package/client/decision-images.d.ts +76 -0
- package/client/decision-images.js +139 -0
- package/client/decision-transport.d.ts +70 -0
- package/client/decision-transport.js +175 -0
- package/client/decode-composer-draft.d.ts +11 -0
- package/client/decode-composer-draft.js +12 -0
- package/client/embedding-input.d.ts +84 -0
- package/client/embedding-input.js +194 -0
- package/client/embedding-space.d.ts +82 -0
- package/client/embedding-space.js +389 -0
- package/client/embedding-transport.d.ts +40 -0
- package/client/embedding-transport.js +71 -0
- package/client/encode-composer-draft.d.ts +9 -0
- package/client/encode-composer-draft.js +34 -0
- package/client/encode-files.d.ts +18 -0
- package/client/encode-files.js +54 -0
- package/client/failure.d.ts +29 -0
- package/client/failure.js +34 -0
- package/client/generation-selection.d.ts +15 -0
- package/client/generation-selection.js +24 -0
- package/client/host-call.d.ts +51 -0
- package/client/host-call.js +47 -0
- package/client/host-transport.d.ts +70 -0
- package/client/host-transport.js +75 -0
- package/client/image-output.d.ts +6 -0
- package/client/image-output.js +13 -0
- package/client/index.d.ts +28 -0
- package/client/index.js +22 -0
- package/client/ink-waveform.d.ts +17 -0
- package/client/ink-waveform.js +68 -0
- package/client/live/apply-live-turn-tool-event.d.ts +14 -0
- package/client/live/apply-live-turn-tool-event.js +39 -0
- package/client/live/live-captions.d.ts +53 -0
- package/client/live/live-captions.js +174 -0
- package/client/live/live-mic-forward.d.ts +30 -0
- package/client/live/live-mic-forward.js +46 -0
- package/client/live/live-page-tool.d.ts +34 -0
- package/client/live/live-page-tool.js +11 -0
- package/client/live/live-state.d.ts +13 -0
- package/client/live/live-state.js +22 -0
- package/client/live/live-tool.d.ts +11 -0
- package/client/live/live-tool.js +1 -0
- package/client/live/live-video.d.ts +10 -0
- package/client/live/live-video.js +71 -0
- package/client/live/run-live-tool-call.d.ts +22 -0
- package/client/live/run-live-tool-call.js +70 -0
- package/client/live/use-live-caption-log.d.ts +17 -0
- package/client/live/use-live-caption-log.js +51 -0
- package/client/live-client.d.ts +189 -0
- package/client/live-client.js +829 -0
- package/client/live-errors.d.ts +2 -0
- package/client/live-errors.js +9 -0
- package/client/live-messages.d.ts +148 -0
- package/client/live-messages.js +100 -0
- package/client/mic-capture.d.ts +4 -0
- package/client/mic-capture.js +6 -0
- package/client/oauth-popup.d.ts +26 -0
- package/client/oauth-popup.js +30 -0
- package/client/page-dispatch.d.ts +15 -0
- package/client/page-dispatch.js +63 -0
- package/client/pcm-downsample.d.ts +4 -0
- package/client/pcm-downsample.js +45 -0
- package/client/run-commit.d.ts +34 -0
- package/client/run-commit.js +49 -0
- package/client/run-session.d.ts +79 -0
- package/client/run-session.js +207 -0
- package/client/schema-fields.d.ts +63 -0
- package/client/schema-fields.js +199 -0
- package/client/shaped-data.d.ts +118 -0
- package/client/shaped-data.js +343 -0
- package/client/source-citations.d.ts +13 -0
- package/client/source-citations.js +56 -0
- package/client/space-geometry.d.ts +39 -0
- package/client/space-geometry.js +183 -0
- package/client/state-fields.d.ts +16 -0
- package/client/state-fields.js +44 -0
- package/client/tool-result.d.ts +78 -0
- package/client/tool-result.js +293 -0
- package/client/tool-resume.d.ts +50 -0
- package/client/tool-resume.js +14 -0
- package/client/trace-feed.d.ts +13 -0
- package/client/trace-feed.js +18 -0
- package/client/trace-story.d.ts +163 -0
- package/client/trace-story.js +440 -0
- package/client/trace-view.d.ts +130 -0
- package/client/trace-view.js +333 -0
- package/client/transcript-groups.d.ts +140 -0
- package/client/transcript-groups.js +217 -0
- package/client/transcript-schema.d.ts +10 -0
- package/client/transcript-schema.js +120 -0
- package/client/transcript-scroll.d.ts +7 -0
- package/client/transcript-scroll.js +6 -0
- package/client/transport.d.ts +264 -0
- package/client/transport.js +330 -0
- package/client/turn-client.d.ts +44 -0
- package/client/turn-client.js +88 -0
- package/client/voice-label.d.ts +2 -0
- package/client/voice-label.js +15 -0
- package/client/voice-recorder.d.ts +27 -0
- package/client/voice-recorder.js +162 -0
- package/client/wire-line.d.ts +56 -0
- package/client/wire-line.js +90 -0
- package/client/worklets/mic-capture.js +16 -0
- package/components/InkWaveform.d.ts +21 -0
- package/components/InkWaveform.js +131 -0
- package/components/live/use-live-runner-controls.d.ts +47 -0
- package/components/live/use-live-runner-controls.js +96 -0
- package/components/live/use-live-runner-model.d.ts +49 -0
- package/components/live/use-live-runner-model.js +190 -0
- package/components/live/use-live-runner-ui.d.ts +67 -0
- package/components/live/use-live-runner-ui.js +167 -0
- package/components/live/use-live-session-client.d.ts +41 -0
- package/components/live/use-live-session-client.js +126 -0
- package/components/use-composer-voice.d.ts +28 -0
- package/components/use-composer-voice.js +90 -0
- package/components/use-editor-selection.d.ts +3 -0
- package/components/use-editor-selection.js +19 -0
- package/components/use-voice-playback.d.ts +17 -0
- package/components/use-voice-playback.js +68 -0
- package/hooks/use-described.d.ts +12 -0
- package/hooks/use-described.js +25 -0
- package/hooks/use-embedding-index.d.ts +27 -0
- package/hooks/use-embedding-index.js +43 -0
- package/hooks/use-one-call.d.ts +31 -0
- package/hooks/use-one-call.js +76 -0
- package/hooks/use-page-tool-warnings.d.ts +6 -0
- package/hooks/use-page-tool-warnings.js +25 -0
- package/hooks/use-second-ticker.d.ts +2 -0
- package/hooks/use-second-ticker.js +13 -0
- package/hooks/use-theorem-chat-actions.d.ts +79 -0
- package/hooks/use-theorem-chat-actions.js +287 -0
- package/hooks/use-theorem-chat-state.d.ts +66 -0
- package/hooks/use-theorem-chat-state.js +122 -0
- package/hooks/use-theorem-chat.d.ts +97 -0
- package/hooks/use-theorem-chat.js +528 -0
- package/hooks/use-theorem-decision.d.ts +18 -0
- package/hooks/use-theorem-decision.js +12 -0
- package/hooks/use-theorem-embedding.d.ts +18 -0
- package/hooks/use-theorem-embedding.js +12 -0
- package/hooks/use-theorem-host.d.ts +45 -0
- package/hooks/use-theorem-host.js +135 -0
- package/hooks/use-theorem-interface.d.ts +22 -0
- package/hooks/use-theorem-interface.js +15 -0
- package/hooks/use-trace-records.d.ts +4 -0
- package/hooks/use-trace-records.js +7 -0
- package/index.d.ts +17 -0
- package/index.js +17 -0
- package/live.d.ts +9 -0
- package/live.js +10 -0
- package/package.json +74 -4
- package/server/checkpoint-ownership.d.ts +6 -0
- package/server/checkpoint-ownership.js +42 -0
- package/server/conversation-store.d.ts +92 -0
- package/server/conversation-store.js +131 -0
- package/server/conversation.d.ts +193 -0
- package/server/conversation.js +552 -0
- package/server/credential-store.d.ts +24 -0
- package/server/credential-store.js +14 -0
- package/server/decision-handler.d.ts +42 -0
- package/server/decision-handler.js +46 -0
- package/server/embedding-handler.d.ts +33 -0
- package/server/embedding-handler.js +45 -0
- package/server/handler.d.ts +152 -0
- package/server/handler.js +771 -0
- package/server/json-response.d.ts +2 -0
- package/server/json-response.js +7 -0
- package/server/mod.d.ts +25 -0
- package/server/mod.js +23 -0
- package/server/page-dispatch.d.ts +22 -0
- package/server/page-dispatch.js +127 -0
- package/server/request-body.d.ts +2 -0
- package/server/request-body.js +42 -0
- package/server/request-check.d.ts +21 -0
- package/server/request-check.js +49 -0
- package/server/session-authority.d.ts +8 -0
- package/server/session-authority.js +78 -0
- package/server/session-boundary.d.ts +26 -0
- package/server/session-boundary.js +64 -0
- package/server/session-identity.d.ts +16 -0
- package/server/session-identity.js +41 -0
- package/server/session-limits.d.ts +12 -0
- package/server/session-limits.js +59 -0
- package/server/session-store.d.ts +123 -0
- package/server/session-store.js +264 -0
- package/server/single-action.d.ts +21 -0
- package/server/single-action.js +30 -0
- package/server/steer-inbox.d.ts +35 -0
- package/server/steer-inbox.js +52 -0
- package/server/tool-operations.d.ts +6 -0
- package/server/tool-operations.js +132 -0
- package/server/turn-input.d.ts +10 -0
- package/server/turn-input.js +29 -0
- package/styles/ink-controls.css +134 -0
- package/ui/CardWall.d.ts +10 -0
- package/ui/CardWall.js +61 -0
- package/ui/ChatComposerBar.d.ts +62 -0
- package/ui/ChatComposerBar.js +306 -0
- package/ui/ChatTranscript.d.ts +43 -0
- package/ui/ChatTranscript.js +527 -0
- package/ui/ConsoleFrame.d.ts +104 -0
- package/ui/ConsoleFrame.js +146 -0
- package/ui/DecisionAnswers.d.ts +53 -0
- package/ui/DecisionAnswers.js +233 -0
- package/ui/DecisionImages.d.ts +16 -0
- package/ui/DecisionImages.js +46 -0
- package/ui/EmbeddingDocuments.d.ts +78 -0
- package/ui/EmbeddingDocuments.js +278 -0
- package/ui/EmbeddingQuery.d.ts +27 -0
- package/ui/EmbeddingQuery.js +95 -0
- package/ui/EmbeddingResults.d.ts +41 -0
- package/ui/EmbeddingResults.js +165 -0
- package/ui/EmbeddingSpace.d.ts +26 -0
- package/ui/EmbeddingSpace.js +106 -0
- package/ui/LiveCaptionsPanel.d.ts +22 -0
- package/ui/LiveCaptionsPanel.js +27 -0
- package/ui/LiveRunner.d.ts +30 -0
- package/ui/LiveRunner.js +180 -0
- package/ui/PaneState.d.ts +33 -0
- package/ui/PaneState.js +50 -0
- package/ui/SchemaFields.d.ts +10 -0
- package/ui/SchemaFields.js +150 -0
- package/ui/ShapedData.d.ts +11 -0
- package/ui/ShapedData.js +196 -0
- package/ui/SidePanel.d.ts +126 -0
- package/ui/SidePanel.js +123 -0
- package/ui/StateFields.d.ts +44 -0
- package/ui/StateFields.js +139 -0
- package/ui/TheoremChat.d.ts +122 -0
- package/ui/TheoremChat.js +134 -0
- package/ui/TheoremDecision.d.ts +30 -0
- package/ui/TheoremDecision.js +130 -0
- package/ui/TheoremEmbedding.d.ts +27 -0
- package/ui/TheoremEmbedding.js +122 -0
- package/ui/TheoremHost.d.ts +55 -0
- package/ui/TheoremHost.js +240 -0
- package/ui/ToolGateCard.d.ts +32 -0
- package/ui/ToolGateCard.js +107 -0
- package/ui/ToolResult.d.ts +10 -0
- package/ui/ToolResult.js +62 -0
- package/ui/ToolResultCharts.d.ts +5 -0
- package/ui/ToolResultCharts.js +103 -0
- package/ui/TraceCharts.d.ts +13 -0
- package/ui/TraceCharts.js +266 -0
- package/ui/TraceGuardrails.d.ts +11 -0
- package/ui/TraceGuardrails.js +74 -0
- package/ui/TraceInspector.d.ts +16 -0
- package/ui/TraceInspector.js +206 -0
- package/ui/TraceInspectorPanel.d.ts +46 -0
- package/ui/TraceInspectorPanel.js +95 -0
- package/ui/TraceOverview.d.ts +38 -0
- package/ui/TraceOverview.js +126 -0
- package/ui/TraceSpanDetail.d.ts +10 -0
- package/ui/TraceSpanDetail.js +190 -0
- package/ui/TraceStory.d.ts +20 -0
- package/ui/TraceStory.js +108 -0
- package/ui/TraceValues.d.ts +36 -0
- package/ui/TraceValues.js +123 -0
- package/ui/TraceWaterfall.d.ts +13 -0
- package/ui/TraceWaterfall.js +135 -0
- package/ui/VoiceNote.d.ts +12 -0
- package/ui/VoiceNote.js +28 -0
- package/ui/approval-heading.d.ts +4 -0
- package/ui/approval-heading.js +9 -0
- package/ui/arrive.d.ts +18 -0
- package/ui/arrive.js +46 -0
- package/ui/built/theme.css +792 -0
- package/ui/built/theme.css.d.ts +9 -0
- package/ui/built/theorem.d.ts +13 -0
- package/ui/built/theorem.js +660 -0
- package/ui/built/theorem.variants.d.ts +22 -0
- package/ui/code-language.d.ts +12 -0
- package/ui/code-language.js +50 -0
- package/ui/disclosure-motion.d.ts +6 -0
- package/ui/disclosure-motion.js +207 -0
- package/ui/embedding-space-gl.d.ts +37 -0
- package/ui/embedding-space-gl.js +663 -0
- package/ui/embedding-space-view.d.ts +8 -0
- package/ui/embedding-space-view.js +8 -0
- package/ui/glide.d.ts +7 -0
- package/ui/glide.js +44 -0
- package/ui/icons.d.ts +4 -0
- package/ui/icons.js +38 -0
- package/ui/index.d.ts +36 -0
- package/ui/index.js +39 -0
- package/ui/labels-provider.d.ts +16 -0
- package/ui/labels-provider.js +64 -0
- package/ui/labels.d.ts +1442 -0
- package/ui/labels.js +1443 -0
- package/ui/markdown-plugins.d.ts +9 -0
- package/ui/markdown-plugins.js +13 -0
- package/ui/mcp-icon.d.ts +6 -0
- package/ui/mcp-icon.js +8 -0
- package/ui/row-keys.d.ts +19 -0
- package/ui/row-keys.js +33 -0
- package/ui/theme.d.ts +10 -0
- package/ui/theme.js +13 -0
- package/ui/theorem-theme.d.ts +10 -0
- package/ui/theorem-theme.js +105 -0
- package/ui/trace-palette.d.ts +10 -0
- package/ui/trace-palette.js +10 -0
- package/ui/trace-patterns.d.ts +40 -0
- package/ui/trace-patterns.js +57 -0
- package/ui/transcript-copy-text.d.ts +4 -0
- package/ui/transcript-copy-text.js +40 -0
- package/ui/wall-columns.d.ts +8 -0
- package/ui/wall-columns.js +19 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The transcript's blocks as the wire carries them: the host stores them, and
|
|
3
|
+
* the browser reads the host's conversation back through this schema.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { z } from '@theoremjs/agents';
|
|
8
|
+
import type { TranscriptBlock } from '@theoremjs/agents/interface';
|
|
9
|
+
/** One transcript block, as a host stores it and the browser reads it back. */
|
|
10
|
+
export declare const transcriptBlockSchema: z.ZodType<TranscriptBlock>;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The transcript's blocks as the wire carries them: the host stores them, and
|
|
3
|
+
* the browser reads the host's conversation back through this schema.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { reasoningPartSchema, TURN_STOP_KINDS, turnEventSchema, z, } from '@theoremjs/agents';
|
|
8
|
+
import { guardrailEventSchema } from '@theoremjs/agents/guardrails';
|
|
9
|
+
// why: The block shapes' event parts have one schema, the turn event's; a probe event reuses it.
|
|
10
|
+
function eventPart(probe) {
|
|
11
|
+
return z.custom((value) => turnEventSchema.safeParse(probe(value)).success);
|
|
12
|
+
}
|
|
13
|
+
const TOOL_CALL_STATE_PHASES = [
|
|
14
|
+
'running',
|
|
15
|
+
'gate',
|
|
16
|
+
'complete',
|
|
17
|
+
'error',
|
|
18
|
+
'cancel',
|
|
19
|
+
];
|
|
20
|
+
const toolCallState = z.custom((value) => {
|
|
21
|
+
const parsed = turnEventSchema.safeParse({ type: 'tool', tool: value });
|
|
22
|
+
if (!parsed.success || parsed.data.type !== 'tool' || !('phase' in parsed.data.tool)) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
const { phase } = parsed.data.tool;
|
|
26
|
+
return TOOL_CALL_STATE_PHASES.some((statePhase) => statePhase === phase);
|
|
27
|
+
});
|
|
28
|
+
const argumentsRecord = z.record(z.string(), z.unknown());
|
|
29
|
+
const toolCall = z.object({
|
|
30
|
+
operationId: z.string().optional(),
|
|
31
|
+
name: z.string(),
|
|
32
|
+
callId: z.string(),
|
|
33
|
+
arguments: argumentsRecord,
|
|
34
|
+
draft: z.string().optional(),
|
|
35
|
+
reasoning: z.array(reasoningPartSchema).optional(),
|
|
36
|
+
stepId: z.string().optional(),
|
|
37
|
+
edited: z.object({ from: argumentsRecord, to: argumentsRecord }).optional(),
|
|
38
|
+
activity: z.string().optional(),
|
|
39
|
+
activityPast: z.string().optional(),
|
|
40
|
+
outputDraft: z.string().optional(),
|
|
41
|
+
state: toolCallState.optional(),
|
|
42
|
+
startedAt: z.number().optional(),
|
|
43
|
+
endedAt: z.number().optional(),
|
|
44
|
+
artifacts: z.array(z.unknown()),
|
|
45
|
+
});
|
|
46
|
+
true;
|
|
47
|
+
const turnStop = z.object({ kind: z.enum(TURN_STOP_KINDS), native: z.string().optional() });
|
|
48
|
+
true;
|
|
49
|
+
const blockId = { id: z.string() };
|
|
50
|
+
const transcriptBlock = z.discriminatedUnion('kind', [
|
|
51
|
+
z.object({ ...blockId, kind: z.literal('user-text'), text: z.string() }),
|
|
52
|
+
z.object({
|
|
53
|
+
...blockId,
|
|
54
|
+
kind: z.enum(['user-attachment', 'user-voice']),
|
|
55
|
+
name: z.string(),
|
|
56
|
+
mimeType: z.string(),
|
|
57
|
+
sizeBytes: z.number(),
|
|
58
|
+
data: z.string().optional(),
|
|
59
|
+
}),
|
|
60
|
+
z.object({ ...blockId, kind: z.literal('thought'), text: z.string() }),
|
|
61
|
+
z.object({ ...blockId, kind: z.literal('text'), text: z.string() }),
|
|
62
|
+
z.object({ ...blockId, kind: z.literal('tool'), tool: toolCall }),
|
|
63
|
+
z.object({
|
|
64
|
+
...blockId,
|
|
65
|
+
kind: z.literal('structured'),
|
|
66
|
+
value: z.unknown(),
|
|
67
|
+
draft: z.string().optional(),
|
|
68
|
+
}),
|
|
69
|
+
z.object({
|
|
70
|
+
...blockId,
|
|
71
|
+
kind: z.literal('media'),
|
|
72
|
+
mimeType: z.string(),
|
|
73
|
+
data: z.string().optional(),
|
|
74
|
+
url: z.string().optional(),
|
|
75
|
+
previewUrl: z.string().optional(),
|
|
76
|
+
}),
|
|
77
|
+
z.object({
|
|
78
|
+
...blockId,
|
|
79
|
+
kind: z.literal('grounding'),
|
|
80
|
+
grounding: eventPart((grounding) => ({
|
|
81
|
+
type: 'grounding',
|
|
82
|
+
grounding,
|
|
83
|
+
})),
|
|
84
|
+
}),
|
|
85
|
+
z.object({
|
|
86
|
+
...blockId,
|
|
87
|
+
kind: z.literal('citation'),
|
|
88
|
+
sources: eventPart((sources) => ({
|
|
89
|
+
type: 'citation',
|
|
90
|
+
sources,
|
|
91
|
+
})),
|
|
92
|
+
callId: z.string().optional(),
|
|
93
|
+
}),
|
|
94
|
+
z.object({
|
|
95
|
+
...blockId,
|
|
96
|
+
kind: z.literal('evidence'),
|
|
97
|
+
evidence: eventPart((evidence) => ({
|
|
98
|
+
type: 'evidence',
|
|
99
|
+
evidence,
|
|
100
|
+
})),
|
|
101
|
+
}),
|
|
102
|
+
z.object({ ...blockId, kind: z.literal('guardrail'), guardrail: guardrailEventSchema }),
|
|
103
|
+
z.object({ ...blockId, kind: z.literal('error'), message: z.string() }),
|
|
104
|
+
z.object({
|
|
105
|
+
...blockId,
|
|
106
|
+
kind: z.literal('turn-done'),
|
|
107
|
+
stop: turnStop.optional(),
|
|
108
|
+
tokens: eventPart((tokens) => ({
|
|
109
|
+
type: 'tokens',
|
|
110
|
+
tokens,
|
|
111
|
+
})).optional(),
|
|
112
|
+
interactionId: z.string().optional(),
|
|
113
|
+
compaction: z.boolean().optional(),
|
|
114
|
+
workedMs: z.number().optional(),
|
|
115
|
+
endedAt: z.number().optional(),
|
|
116
|
+
}),
|
|
117
|
+
]);
|
|
118
|
+
true;
|
|
119
|
+
/** One transcript block, as a host stores it and the browser reads it back. */
|
|
120
|
+
export const transcriptBlockSchema = transcriptBlock;
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import { type GateReference, type ToolGate } from '@theoremjs/agents';
|
|
2
|
+
import type { PageDispatchResult } from './page-dispatch.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Transport contract between a Theorem chat UI and the host that runs turns.
|
|
5
|
+
*
|
|
6
|
+
* The browser never holds the profile: it asks the transport to `describe` the
|
|
7
|
+
* profile's client-safe interface, then streams turns / tool invokes through it.
|
|
8
|
+
* `createHttpTransport` speaks to `createTheoremHandler` (`@theoremjs/react/server`);
|
|
9
|
+
* hosts with their own wire format implement {@link TheoremTransport} directly.
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
import { type ErrorKind, type TurnEvent, type TurnHistoryMessage, type TurnToolSnapshot, z } from '@theoremjs/agents';
|
|
14
|
+
import { type ErrorCopies } from '@theoremjs/agents/guardrails';
|
|
15
|
+
import { type ProfileInterface, type TranscriptBlock } from '@theoremjs/agents/interface';
|
|
16
|
+
import type { PagePart } from './tool-resume.ts';
|
|
17
|
+
import type { TraceFeed } from './trace-feed.ts';
|
|
18
|
+
import { type MalformedEvent, type UnsupportedEvent, type WireLines } from './wire-line.ts';
|
|
19
|
+
export type { MalformedEvent, UnsupportedEvent, WireLines } from './wire-line.ts';
|
|
20
|
+
export type EncodedBlob = {
|
|
21
|
+
name: string;
|
|
22
|
+
mimeType: string;
|
|
23
|
+
data: string;
|
|
24
|
+
};
|
|
25
|
+
/** Turn input as sent over the wire (media is base64-encoded). */
|
|
26
|
+
export type TheoremTurnInput = {
|
|
27
|
+
text?: string;
|
|
28
|
+
attachments?: EncodedBlob[];
|
|
29
|
+
voice?: EncodedBlob[];
|
|
30
|
+
/** The value chosen for each of the profile's `inputs.slots`. */
|
|
31
|
+
slots?: Record<string, string>;
|
|
32
|
+
/** What the page wants the agent to know: any JSON. The host reads it as untrusted. */
|
|
33
|
+
context?: unknown;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* State only the client holds, for hosts whose profile also lives in the browser
|
|
37
|
+
* (the studio). `createHttpTransport` never sends it: `createTheoremHandler`
|
|
38
|
+
* keeps permissions, paused calls, and tool snapshots in its own session.
|
|
39
|
+
*/
|
|
40
|
+
export type TheoremReplay = {
|
|
41
|
+
gateKind?: ToolGate['kind'];
|
|
42
|
+
sessionPermissions?: string[];
|
|
43
|
+
name?: string;
|
|
44
|
+
input?: unknown;
|
|
45
|
+
snapshot?: TurnToolSnapshot;
|
|
46
|
+
promoted?: string[];
|
|
47
|
+
model?: string;
|
|
48
|
+
effort?: string;
|
|
49
|
+
};
|
|
50
|
+
/** For a host that reads the studio's client-held state. */
|
|
51
|
+
export declare const theoremReplaySchema: z.ZodType<TheoremReplay>;
|
|
52
|
+
/**
|
|
53
|
+
* One message. The host resolves the profile and owns the conversation: the
|
|
54
|
+
* client sends only the message and the ref of the conversation it continues.
|
|
55
|
+
*
|
|
56
|
+
* A message sent while the reply waits on gates walks away from them: `abandon`
|
|
57
|
+
* names the waiting calls. The host settles each one cancelled, streams those
|
|
58
|
+
* events first, and gives the model each call's answer before the message.
|
|
59
|
+
*/
|
|
60
|
+
export type TheoremTurnRequest = {
|
|
61
|
+
input: TheoremTurnInput;
|
|
62
|
+
/** The ref of the conversation this message continues; none starts one. */
|
|
63
|
+
conversation?: string;
|
|
64
|
+
model?: string;
|
|
65
|
+
effort?: string;
|
|
66
|
+
/** Client-generated id so mid-turn steers can find this turn's inbox. */
|
|
67
|
+
turnId?: string;
|
|
68
|
+
/** invariant: Both issued IDs identify each paused action that this message abandons. */
|
|
69
|
+
abandon?: GateReference[];
|
|
70
|
+
/** The tools the person allowed for the page, for a host without a session (the studio). */
|
|
71
|
+
replay?: Pick<TheoremReplay, 'sessionPermissions'>;
|
|
72
|
+
/**
|
|
73
|
+
* The page's transcript before this message, sent only after the host answered that it can no
|
|
74
|
+
* longer open `conversation` (`session.conversation_unknown`). A host that restores from it (the
|
|
75
|
+
* studio) goes on from it under a new ref; `createTheoremHandler` keeps the conversation its own
|
|
76
|
+
* and does not.
|
|
77
|
+
*/
|
|
78
|
+
transcript?: TranscriptBlock[];
|
|
79
|
+
};
|
|
80
|
+
/** A `/turn` body as `createTheoremHandler` reads it. */
|
|
81
|
+
export declare const theoremTurnRequestSchema: z.ZodType<TheoremTurnRequest>;
|
|
82
|
+
/** What the user answers a gate with; walking away rides on the next message (`TheoremTurnRequest.abandon`). */
|
|
83
|
+
declare const INVOKE_DECISIONS: readonly ["approve", "deny"];
|
|
84
|
+
/**
|
|
85
|
+
* The user's answer to a tool call the host paused on a gate. `approve` runs it
|
|
86
|
+
* (with `input` when the user edited it); `deny` refuses it. The host settles
|
|
87
|
+
* each one, so the model and the trace read what the user chose. The tool's
|
|
88
|
+
* registered permission decides how long an approval lasts, not the client.
|
|
89
|
+
*/
|
|
90
|
+
export type TheoremInvokeRequest = {
|
|
91
|
+
/** Call id of the paused tool call (`tool.callId` on its gate event). */
|
|
92
|
+
gateId: string;
|
|
93
|
+
operationId: string;
|
|
94
|
+
decision: (typeof INVOKE_DECISIONS)[number];
|
|
95
|
+
/** The user's edit of the model's input; only with `approve`. */
|
|
96
|
+
input?: unknown;
|
|
97
|
+
/**
|
|
98
|
+
* The key or token the user typed at a bearer or API-key sign-in gate, only
|
|
99
|
+
* with `approve`. The server saves it for the session and never sends it
|
|
100
|
+
* back; an OAuth gate resumes with the gate id alone, once the host's
|
|
101
|
+
* callback saved the token.
|
|
102
|
+
*/
|
|
103
|
+
secret?: string;
|
|
104
|
+
/** The page's answer to a `page` gate, only with `approve`: the tool's output schema checks it. */
|
|
105
|
+
page?: PagePart;
|
|
106
|
+
/** The ref of the conversation whose reply waits on the gate. */
|
|
107
|
+
conversation?: string;
|
|
108
|
+
/** Client-generated id so steers sent while the reply goes on find its inbox. */
|
|
109
|
+
turnId?: string;
|
|
110
|
+
replay?: TheoremReplay;
|
|
111
|
+
};
|
|
112
|
+
/** An `/invoke` body as `createTheoremHandler` reads it. */
|
|
113
|
+
export declare const theoremInvokeRequestSchema: z.ZodType<TheoremInvokeRequest>;
|
|
114
|
+
/** Inject user messages into an in-flight turn. */
|
|
115
|
+
export type TheoremSteerRequest = {
|
|
116
|
+
turnId: string;
|
|
117
|
+
/** The client's id for this steer; the turn's `stage` event names it in `injected` once it lands. */
|
|
118
|
+
id: string;
|
|
119
|
+
inject: TurnHistoryMessage[];
|
|
120
|
+
};
|
|
121
|
+
/** A `/steer` body as `createTheoremHandler` reads it. */
|
|
122
|
+
export declare const theoremSteerRequestSchema: z.ZodType<TheoremSteerRequest>;
|
|
123
|
+
/**
|
|
124
|
+
* The ref the store issued for the conversation a run wrote: the client sends
|
|
125
|
+
* it with its next request. It comes before the run's error, which ends the stream.
|
|
126
|
+
* `posted` marks the write that holds the person's new message: a run that
|
|
127
|
+
* fails before it leaves the message unsent.
|
|
128
|
+
*/
|
|
129
|
+
export type ConversationLine = {
|
|
130
|
+
type: 'conversation';
|
|
131
|
+
ref: string;
|
|
132
|
+
posted?: true;
|
|
133
|
+
};
|
|
134
|
+
/** The lines a chat's reply streams: turn events, and the conversation's ref. */
|
|
135
|
+
export declare const CHAT_LINES: WireLines<TurnEvent | ConversationLine>;
|
|
136
|
+
/** What the browser draws: the transcript, and the reply that waits on gates. */
|
|
137
|
+
export type ConversationView = {
|
|
138
|
+
transcript: TranscriptBlock[];
|
|
139
|
+
/** The reply that waits on gates: its events, and its blocks as the transcript will keep them. */
|
|
140
|
+
paused?: {
|
|
141
|
+
events: TurnEvent[];
|
|
142
|
+
blocks: TranscriptBlock[];
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
/** Read a conversation: a `/conversation` body. */
|
|
146
|
+
export type TheoremConversationRequest = {
|
|
147
|
+
conversation: string;
|
|
148
|
+
};
|
|
149
|
+
/** A `/conversation` body as `createTheoremHandler` reads it. */
|
|
150
|
+
export declare const theoremConversationRequestSchema: z.ZodType<TheoremConversationRequest>;
|
|
151
|
+
/**
|
|
152
|
+
* Cut the conversation after transcript block `at` (-1 empties it): a
|
|
153
|
+
* `/rewind` body. A reply waiting on gates is walked away from first.
|
|
154
|
+
*/
|
|
155
|
+
export type TheoremRewindRequest = {
|
|
156
|
+
conversation: string;
|
|
157
|
+
at: number;
|
|
158
|
+
};
|
|
159
|
+
/** A `/rewind` body as `createTheoremHandler` reads it. */
|
|
160
|
+
export declare const theoremRewindRequestSchema: z.ZodType<TheoremRewindRequest>;
|
|
161
|
+
/** A rewound conversation: its new ref, and what the browser draws. */
|
|
162
|
+
export type TheoremRewound = {
|
|
163
|
+
conversation: string;
|
|
164
|
+
view: ConversationView;
|
|
165
|
+
};
|
|
166
|
+
/** A turn event, one of a kind this client does not know (`unsupported`), or one that failed its check (`malformed`). */
|
|
167
|
+
export type ClientTurnEvent = TurnEvent | UnsupportedEvent | MalformedEvent;
|
|
168
|
+
export type TurnEventSink = (event: ClientTurnEvent) => void;
|
|
169
|
+
/** A line of a chat's reply: a turn event, or the ref of the conversation it wrote. */
|
|
170
|
+
export type ChatLine = ClientTurnEvent | ConversationLine;
|
|
171
|
+
export type ChatLineSink = (line: ChatLine) => void;
|
|
172
|
+
export interface TheoremTransport {
|
|
173
|
+
/** Client-safe interface for the host's profile (inputs, models, guardrail view). */
|
|
174
|
+
describe(signal?: AbortSignal): Promise<ProfileInterface>;
|
|
175
|
+
turn(request: TheoremTurnRequest, onLine: ChatLineSink, signal?: AbortSignal): Promise<void>;
|
|
176
|
+
invoke(request: TheoremInvokeRequest, onLine: ChatLineSink, signal?: AbortSignal): Promise<void>;
|
|
177
|
+
steer(request: TheoremSteerRequest): Promise<void>;
|
|
178
|
+
/** The conversation under `ref`, as the host shows it. */
|
|
179
|
+
conversation(request: TheoremConversationRequest, signal?: AbortSignal): Promise<ConversationView>;
|
|
180
|
+
/** The conversation cut after a transcript block, under the ref the host issued for it. */
|
|
181
|
+
rewind(request: TheoremRewindRequest, signal?: AbortSignal): Promise<TheoremRewound>;
|
|
182
|
+
pageResult?(result: PageDispatchResult, signal?: AbortSignal): Promise<void>;
|
|
183
|
+
/** Trace records the host sends back, when it delivers them (the studio does). */
|
|
184
|
+
traces?: TraceFeed;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* A failure the host reported: its kind, the host's wording when it sent one
|
|
188
|
+
* (the profile's labels, applied on the host), and raw detail when the host
|
|
189
|
+
* exposes it. `clientFailure` words it for the user.
|
|
190
|
+
*/
|
|
191
|
+
export declare class TheoremStreamError extends Error {
|
|
192
|
+
readonly kind: ErrorKind;
|
|
193
|
+
readonly publicMessage?: string;
|
|
194
|
+
readonly internalMessage?: string;
|
|
195
|
+
/** The labels key behind `publicMessage`, when the host gave one: what failed, more exactly than `kind`. */
|
|
196
|
+
readonly copy?: ErrorCopies;
|
|
197
|
+
constructor(kind: ErrorKind, publicMessage?: string, internalMessage?: string, copy?: ErrorCopies);
|
|
198
|
+
}
|
|
199
|
+
export declare function isTheoremStreamError(err: unknown): err is TheoremStreamError;
|
|
200
|
+
/** A host error reply's body (JSON reply or `{ type: 'error' }` stream line). */
|
|
201
|
+
export type HostErrorBody = {
|
|
202
|
+
error?: string;
|
|
203
|
+
errorKind?: ErrorKind;
|
|
204
|
+
/** The labels key behind `error`, when more specific than the kind's. */
|
|
205
|
+
errorCopy?: ErrorCopies;
|
|
206
|
+
errorInternal?: string;
|
|
207
|
+
};
|
|
208
|
+
/** A host's error body, as the transport and the live client read it. */
|
|
209
|
+
export declare const hostErrorBodySchema: z.ZodType<HostErrorBody>;
|
|
210
|
+
/** A host's error body as a failure: its kind (else `fallbackKind`), wording, and detail. */
|
|
211
|
+
export declare function hostError(body: HostErrorBody, fallbackKind: ErrorKind): TheoremStreamError;
|
|
212
|
+
/** The host could not open the message's conversation (`session.conversation_unknown`). */
|
|
213
|
+
export declare function isUnknownConversation(err: unknown): boolean;
|
|
214
|
+
/**
|
|
215
|
+
* Read an NDJSON reply, checking each line against `lines`: a kind it doesn't
|
|
216
|
+
* list reaches `onLine` as `unsupported`, and a line that fails its check as
|
|
217
|
+
* `malformed`; the stream goes on. An `error` line ends it.
|
|
218
|
+
*/
|
|
219
|
+
export declare function readNdjsonStream<Line extends {
|
|
220
|
+
type: string;
|
|
221
|
+
}>(response: Response, lines: WireLines<Line>, onLine: (line: Line | UnsupportedEvent | MalformedEvent) => void, signal?: AbortSignal): Promise<void>;
|
|
222
|
+
export type HttpOptions = {
|
|
223
|
+
fetch?: typeof fetch;
|
|
224
|
+
/** Extra request headers (auth tokens, CSRF). A function is re-read per request. */
|
|
225
|
+
headers?: HeadersInit | (() => HeadersInit | Promise<HeadersInit>);
|
|
226
|
+
/** Cookie policy. Default `same-origin`; use `include` when the handler is on another origin. */
|
|
227
|
+
credentials?: RequestCredentials;
|
|
228
|
+
};
|
|
229
|
+
/**
|
|
230
|
+
* POST JSON and stream NDJSON lines back, each checked against `lines`: turn
|
|
231
|
+
* events ({@link TURN_EVENT_SCHEMAS}), or a host's own schema beside them.
|
|
232
|
+
*/
|
|
233
|
+
export declare function postNdjson<Line extends {
|
|
234
|
+
type: string;
|
|
235
|
+
}>(url: string, body: unknown, lines: WireLines<Line>, onLine: (line: Line | UnsupportedEvent | MalformedEvent) => void, options?: HttpOptions & {
|
|
236
|
+
signal?: AbortSignal;
|
|
237
|
+
}): Promise<void>;
|
|
238
|
+
/** POST JSON; a non-OK reply throws its failure. The OK reply's body is not read. */
|
|
239
|
+
export declare function postJson(url: string, body: unknown, options?: HttpOptions & {
|
|
240
|
+
signal?: AbortSignal;
|
|
241
|
+
}): Promise<void>;
|
|
242
|
+
/**
|
|
243
|
+
* GET, or POST `body` as JSON, and read the JSON reply; a non-OK reply throws its failure, after
|
|
244
|
+
* `failed` has read whatever else its JSON body carries.
|
|
245
|
+
*/
|
|
246
|
+
export declare function fetchJson(url: string, init: {
|
|
247
|
+
body?: unknown;
|
|
248
|
+
signal?: AbortSignal;
|
|
249
|
+
failed?: (body: unknown) => void;
|
|
250
|
+
}, options?: HttpOptions): Promise<unknown>;
|
|
251
|
+
/** POST a conversation's read to `url`, and check the view the host answers. */
|
|
252
|
+
export declare function fetchConversation(url: string, body: unknown, options?: HttpOptions & {
|
|
253
|
+
signal?: AbortSignal;
|
|
254
|
+
}): Promise<ConversationView>;
|
|
255
|
+
/** POST a rewind to `url`, and check the rewound conversation the host answers. */
|
|
256
|
+
export declare function fetchRewound(url: string, body: unknown, options?: HttpOptions & {
|
|
257
|
+
signal?: AbortSignal;
|
|
258
|
+
}): Promise<TheoremRewound>;
|
|
259
|
+
export type HttpTransportOptions = HttpOptions & {
|
|
260
|
+
/** Base URL where `createTheoremHandler` is mounted. Default `/api/theorem`. */
|
|
261
|
+
endpoint?: string;
|
|
262
|
+
};
|
|
263
|
+
/** Transport for a host mounted with `createTheoremHandler`. */
|
|
264
|
+
export declare function createHttpTransport(options?: HttpTransportOptions): TheoremTransport;
|