@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,15 @@
|
|
|
1
|
+
import { type ComposerProfileInterface } from '@theoremjs/agents/interface';
|
|
2
|
+
/** A model and effort for the next turn. */
|
|
3
|
+
export type GenerationSelection = {
|
|
4
|
+
model?: string;
|
|
5
|
+
effort?: string;
|
|
6
|
+
};
|
|
7
|
+
/** The profile's default model (its first, when it names none). */
|
|
8
|
+
export declare function defaultModel(iface: ComposerProfileInterface): string | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* The selection for `iface`, given what was `selected` under the `previous` interface (none on
|
|
11
|
+
* first load). A pick that was on the previous default follows the new one, and a pick `iface` no
|
|
12
|
+
* longer has falls back to its default; any other pick is kept. Model and effort are each judged
|
|
13
|
+
* this way, the effort against its model's default, and a new model takes its own default effort.
|
|
14
|
+
*/
|
|
15
|
+
export declare function followGenerationDefaults(iface: ComposerProfileInterface, selected: GenerationSelection, previous: ComposerProfileInterface | undefined): GenerationSelection;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { defaultInterfaceEffort } from '@theoremjs/agents/interface';
|
|
2
|
+
/** The profile's default model (its first, when it names none). */
|
|
3
|
+
export function defaultModel(iface) {
|
|
4
|
+
return iface.defaultModel ?? Object.keys(iface.models)[0];
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* The selection for `iface`, given what was `selected` under the `previous` interface (none on
|
|
8
|
+
* first load). A pick that was on the previous default follows the new one, and a pick `iface` no
|
|
9
|
+
* longer has falls back to its default; any other pick is kept. Model and effort are each judged
|
|
10
|
+
* this way, the effort against its model's default, and a new model takes its own default effort.
|
|
11
|
+
*/
|
|
12
|
+
export function followGenerationDefaults(iface, selected, previous) {
|
|
13
|
+
const keepModel = selected.model !== undefined &&
|
|
14
|
+
Object.hasOwn(iface.models, selected.model) &&
|
|
15
|
+
(previous === undefined || selected.model !== defaultModel(previous));
|
|
16
|
+
const model = keepModel ? selected.model : defaultModel(iface);
|
|
17
|
+
const efforts = model === undefined ? undefined : iface.models[model]?.efforts;
|
|
18
|
+
const keepEffort = model === selected.model &&
|
|
19
|
+
selected.effort !== undefined &&
|
|
20
|
+
efforts !== undefined &&
|
|
21
|
+
Object.hasOwn(efforts, selected.effort) &&
|
|
22
|
+
(previous === undefined || selected.effort !== defaultInterfaceEffort(previous, model));
|
|
23
|
+
return { model, effort: keepEffort ? selected.effort : defaultInterfaceEffort(iface, model) };
|
|
24
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A host call's standing, read from its folded state: the phase it's in, and
|
|
3
|
+
* what to say when it failed.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import type { TranscriptBlock } from '@theoremjs/agents/interface';
|
|
8
|
+
import type { ClientFailure } from './failure.ts';
|
|
9
|
+
import { type JsonSchema } from './schema-fields.ts';
|
|
10
|
+
export type ToolCall = Extract<TranscriptBlock, {
|
|
11
|
+
kind: 'tool';
|
|
12
|
+
}>['tool'];
|
|
13
|
+
export type HostCallStatus = 'running' | 'gate' | 'complete' | 'error' | 'cancel';
|
|
14
|
+
/** What a call's standing reads from. */
|
|
15
|
+
export type HostCallState = {
|
|
16
|
+
call: ToolCall | null;
|
|
17
|
+
failure: ClientFailure | null;
|
|
18
|
+
isRunning: boolean;
|
|
19
|
+
};
|
|
20
|
+
/** The phase a call is in; a stream that broke is an error, one that stopped short a cancel. */
|
|
21
|
+
export declare function hostCallStatus({ call, failure, isRunning }: HostCallState): HostCallStatus;
|
|
22
|
+
/** Why a call failed, as a banner reads it: it never reached its tool, or the tool failed. */
|
|
23
|
+
export declare function hostCallFailure({ call, failure, }: HostCallState): {
|
|
24
|
+
title: string;
|
|
25
|
+
description?: string;
|
|
26
|
+
} | null;
|
|
27
|
+
/** What the console shows: the picked tool, its request text, its call on show, and the calls before it. */
|
|
28
|
+
export type HostConsoleView<Tool, Call> = {
|
|
29
|
+
tool: Tool | undefined;
|
|
30
|
+
text: string;
|
|
31
|
+
shown: Call | null;
|
|
32
|
+
earlier: Call[];
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* The console's view of its state. An unknown pick falls back to the first
|
|
36
|
+
* tool; a tool's request is its draft, else a sample of its schema; the call on
|
|
37
|
+
* show is the one opened from history, else the tool's latest.
|
|
38
|
+
*/
|
|
39
|
+
export declare function hostConsoleView<Tool extends {
|
|
40
|
+
name: string;
|
|
41
|
+
inputSchema: JsonSchema;
|
|
42
|
+
}, Call extends {
|
|
43
|
+
id: string;
|
|
44
|
+
name: string;
|
|
45
|
+
}>(args: {
|
|
46
|
+
tools: readonly Tool[];
|
|
47
|
+
picked: string | undefined;
|
|
48
|
+
drafts: Readonly<Record<string, string>>;
|
|
49
|
+
calls: readonly Call[];
|
|
50
|
+
shownId: string | null;
|
|
51
|
+
}): HostConsoleView<Tool, Call>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A host call's standing, read from its folded state: the phase it's in, and
|
|
3
|
+
* what to say when it failed.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { sampleFromSchema } from "./schema-fields.js";
|
|
8
|
+
import { json } from "./shaped-data.js";
|
|
9
|
+
const SETTLED = new Set([
|
|
10
|
+
'gate',
|
|
11
|
+
'complete',
|
|
12
|
+
'error',
|
|
13
|
+
'cancel',
|
|
14
|
+
]);
|
|
15
|
+
/** The phase a call is in; a stream that broke is an error, one that stopped short a cancel. */
|
|
16
|
+
export function hostCallStatus({ call, failure, isRunning }) {
|
|
17
|
+
const phase = call?.state?.phase;
|
|
18
|
+
if (phase !== undefined && SETTLED.has(phase))
|
|
19
|
+
return phase;
|
|
20
|
+
if (failure)
|
|
21
|
+
return 'error';
|
|
22
|
+
return isRunning ? 'running' : 'cancel';
|
|
23
|
+
}
|
|
24
|
+
/** Why a call failed, as a banner reads it: it never reached its tool, or the tool failed. */
|
|
25
|
+
export function hostCallFailure({ call, failure, }) {
|
|
26
|
+
if (failure)
|
|
27
|
+
return { title: failure.error };
|
|
28
|
+
const state = call?.state;
|
|
29
|
+
if (state?.phase !== 'error')
|
|
30
|
+
return null;
|
|
31
|
+
const { error, message } = state.failure;
|
|
32
|
+
if (!error)
|
|
33
|
+
return { title: message };
|
|
34
|
+
return error === message ? { title: error } : { title: error, description: message };
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The console's view of its state. An unknown pick falls back to the first
|
|
38
|
+
* tool; a tool's request is its draft, else a sample of its schema; the call on
|
|
39
|
+
* show is the one opened from history, else the tool's latest.
|
|
40
|
+
*/
|
|
41
|
+
export function hostConsoleView(args) {
|
|
42
|
+
const tool = args.tools.find((candidate) => candidate.name === args.picked) ?? args.tools[0];
|
|
43
|
+
const text = tool ? (args.drafts[tool.name] ?? json(sampleFromSchema(tool.inputSchema))) : '';
|
|
44
|
+
const ofTool = args.calls.filter((call) => call.name === tool?.name);
|
|
45
|
+
const shown = ofTool.find((call) => call.id === args.shownId) ?? ofTool[0] ?? null;
|
|
46
|
+
return { tool, text, shown, earlier: args.calls.filter((call) => call !== shown) };
|
|
47
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The browser side of a host profile: the tools the host lets the page call,
|
|
3
|
+
* each with the schemas its request and response are drawn from, and the calls
|
|
4
|
+
* themselves, streamed as the kernel runs them.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import { type Profile, type ToolAccess, type ToolPermission, z } from '@theoremjs/agents';
|
|
9
|
+
import type { PageDispatchResult } from './page-dispatch.ts';
|
|
10
|
+
import type { TraceFeed } from './trace-feed.ts';
|
|
11
|
+
import { type HttpOptions, type TheoremInvokeRequest, type TurnEventSink } from './transport.ts';
|
|
12
|
+
/** How a tool reaches its work: a function on the host, an HTTP endpoint, or an MCP server. */
|
|
13
|
+
export declare const HOST_TOOL_KINDS: readonly ["function", "http", "mcp"];
|
|
14
|
+
export type HostToolKind = (typeof HOST_TOOL_KINDS)[number];
|
|
15
|
+
/** One tool as the page sees it. Its endpoint, headers, and credentials stay on the host. */
|
|
16
|
+
export type HostToolView = {
|
|
17
|
+
name: string;
|
|
18
|
+
description: string;
|
|
19
|
+
kind: HostToolKind;
|
|
20
|
+
access: ToolAccess;
|
|
21
|
+
permission: ToolPermission;
|
|
22
|
+
/** JSON Schema for the call's input: the form is drawn from it. */
|
|
23
|
+
inputSchema: Record<string, unknown>;
|
|
24
|
+
/** JSON Schema for the tool's output: the result is laid out from it. */
|
|
25
|
+
outputSchema: Record<string, unknown>;
|
|
26
|
+
};
|
|
27
|
+
/** What a host profile shows the page. */
|
|
28
|
+
export type HostInterface = {
|
|
29
|
+
type: 'host';
|
|
30
|
+
id: string;
|
|
31
|
+
tools: HostToolView[];
|
|
32
|
+
observability?: {
|
|
33
|
+
record: boolean;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
/** A tool as registered: the fields the page's view keeps. */
|
|
37
|
+
export type HostToolSource = {
|
|
38
|
+
type: string;
|
|
39
|
+
name: string;
|
|
40
|
+
description: string;
|
|
41
|
+
access: ToolAccess;
|
|
42
|
+
permission: ToolPermission;
|
|
43
|
+
inputSchema: Record<string, unknown>;
|
|
44
|
+
outputSchema: Record<string, unknown>;
|
|
45
|
+
};
|
|
46
|
+
/** The page's view of a host profile: its allowed tools, in the order it allows them. */
|
|
47
|
+
export declare function hostInterface(profile: Pick<Extract<Profile, {
|
|
48
|
+
type: 'host';
|
|
49
|
+
}>, 'id' | 'tools' | 'observability'>, tools: (name: string) => HostToolSource | undefined): HostInterface;
|
|
50
|
+
/** One call of one of the host's tools. */
|
|
51
|
+
export type TheoremHostCallRequest = {
|
|
52
|
+
name: string;
|
|
53
|
+
input: unknown;
|
|
54
|
+
};
|
|
55
|
+
/** A `/call` body as `createTheoremHostHandler` reads it. */
|
|
56
|
+
export declare const theoremHostCallRequestSchema: z.ZodType<TheoremHostCallRequest>;
|
|
57
|
+
export interface HostTransport {
|
|
58
|
+
pageResult?(result: PageDispatchResult, signal?: AbortSignal): Promise<void>;
|
|
59
|
+
describe(signal?: AbortSignal): Promise<HostInterface>;
|
|
60
|
+
/** Runs one tool; its events stream to `onEvent`, ending in `done`. */
|
|
61
|
+
call(request: TheoremHostCallRequest, onEvent: TurnEventSink, signal?: AbortSignal): Promise<void>;
|
|
62
|
+
/** The user's answer to a call the host paused on a gate. */
|
|
63
|
+
invoke(request: TheoremInvokeRequest, onEvent: TurnEventSink, signal?: AbortSignal): Promise<void>;
|
|
64
|
+
/** Where the host's trace records land, for the inspector. */
|
|
65
|
+
traces?: TraceFeed;
|
|
66
|
+
}
|
|
67
|
+
/** Transport for a host mounted with `createTheoremHostHandler`. Default endpoint `/api/host`. */
|
|
68
|
+
export declare function createHostTransport(options?: HttpOptions & {
|
|
69
|
+
endpoint?: string;
|
|
70
|
+
}): HostTransport;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The browser side of a host profile: the tools the host lets the page call,
|
|
3
|
+
* each with the schemas its request and response are drawn from, and the calls
|
|
4
|
+
* themselves, streamed as the kernel runs them.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import { resolveObservabilityPolicy, TOOL_ACCESS, TOOL_PERMISSION, TURN_EVENT_SCHEMAS, z, } from '@theoremjs/agents';
|
|
9
|
+
import { fetchJson, postJson, postNdjson, } from "./transport.js";
|
|
10
|
+
import { checkWire } from "./wire-line.js";
|
|
11
|
+
/** How a tool reaches its work: a function on the host, an HTTP endpoint, or an MCP server. */
|
|
12
|
+
export const HOST_TOOL_KINDS = ['function', 'http', 'mcp'];
|
|
13
|
+
function isHostToolKind(type) {
|
|
14
|
+
return HOST_TOOL_KINDS.includes(type);
|
|
15
|
+
}
|
|
16
|
+
/** The page's view of a host profile: its allowed tools, in the order it allows them. */
|
|
17
|
+
export function hostInterface(profile, tools) {
|
|
18
|
+
return {
|
|
19
|
+
type: 'host',
|
|
20
|
+
id: profile.id,
|
|
21
|
+
tools: profile.tools.allow.flatMap((name) => {
|
|
22
|
+
const tool = tools(name);
|
|
23
|
+
if (!tool || !isHostToolKind(tool.type))
|
|
24
|
+
return [];
|
|
25
|
+
return [
|
|
26
|
+
{
|
|
27
|
+
name: tool.name,
|
|
28
|
+
description: tool.description,
|
|
29
|
+
kind: tool.type,
|
|
30
|
+
access: tool.access,
|
|
31
|
+
permission: tool.permission,
|
|
32
|
+
inputSchema: tool.inputSchema,
|
|
33
|
+
outputSchema: tool.outputSchema,
|
|
34
|
+
},
|
|
35
|
+
];
|
|
36
|
+
}),
|
|
37
|
+
...(profile.observability
|
|
38
|
+
? { observability: { record: resolveObservabilityPolicy(profile.observability).record } }
|
|
39
|
+
: {}),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
const theoremHostCallRequest = z.object({ name: z.string().min(1).max(128), input: z.unknown() });
|
|
43
|
+
true;
|
|
44
|
+
/** A `/call` body as `createTheoremHostHandler` reads it. */
|
|
45
|
+
export const theoremHostCallRequestSchema = theoremHostCallRequest;
|
|
46
|
+
const schemaObject = z.record(z.string(), z.unknown());
|
|
47
|
+
const describedSchema = z.object({
|
|
48
|
+
interface: z.object({
|
|
49
|
+
type: z.literal('host'),
|
|
50
|
+
id: z.string(),
|
|
51
|
+
tools: z.array(z.object({
|
|
52
|
+
name: z.string(),
|
|
53
|
+
description: z.string(),
|
|
54
|
+
kind: z.enum(HOST_TOOL_KINDS),
|
|
55
|
+
access: z.enum(TOOL_ACCESS),
|
|
56
|
+
permission: z.enum(TOOL_PERMISSION),
|
|
57
|
+
inputSchema: schemaObject,
|
|
58
|
+
outputSchema: schemaObject,
|
|
59
|
+
})),
|
|
60
|
+
observability: z.object({ record: z.boolean() }).optional(),
|
|
61
|
+
}),
|
|
62
|
+
});
|
|
63
|
+
/** Transport for a host mounted with `createTheoremHostHandler`. Default endpoint `/api/host`. */
|
|
64
|
+
export function createHostTransport(options = {}) {
|
|
65
|
+
const base = (options.endpoint ?? '/api/host').replace(/\/$/, '');
|
|
66
|
+
return {
|
|
67
|
+
pageResult: (body, signal) => postJson(`${base}/page-result`, body, { ...options, signal }),
|
|
68
|
+
async describe(signal) {
|
|
69
|
+
// labels-exempt: internal diagnostic; the user reads error.bad_response
|
|
70
|
+
return checkWire(describedSchema, await fetchJson(base, { signal }, options), 'the host description').interface;
|
|
71
|
+
},
|
|
72
|
+
call: (body, onEvent, signal) => postNdjson(`${base}/call`, body, TURN_EVENT_SCHEMAS, onEvent, { ...options, signal }),
|
|
73
|
+
invoke: ({ replay: _replay, ...body }, onEvent, signal) => postNdjson(`${base}/invoke`, body, TURN_EVENT_SCHEMAS, onEvent, { ...options, signal }),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Display helpers for image-profile output. */
|
|
2
|
+
/**
|
|
3
|
+
* Profile `image.aspectRatio` (`"16:9"`) as width / height, for Astryx
|
|
4
|
+
* `AspectRatio`. Undefined when unset or malformed — the provider picks.
|
|
5
|
+
*/
|
|
6
|
+
export declare function parseAspectRatio(value: string | undefined): number | undefined;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Display helpers for image-profile output. */
|
|
2
|
+
/**
|
|
3
|
+
* Profile `image.aspectRatio` (`"16:9"`) as width / height, for Astryx
|
|
4
|
+
* `AspectRatio`. Undefined when unset or malformed — the provider picks.
|
|
5
|
+
*/
|
|
6
|
+
export function parseAspectRatio(value) {
|
|
7
|
+
const match = value?.trim().match(/^(\d+(?:\.\d+)?)\s*:\s*(\d+(?:\.\d+)?)$/);
|
|
8
|
+
if (!match)
|
|
9
|
+
return undefined;
|
|
10
|
+
const width = Number(match[1]);
|
|
11
|
+
const height = Number(match[2]);
|
|
12
|
+
return width > 0 && height > 0 ? width / height : undefined;
|
|
13
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export { float32Rms, float32RmsToLevel, INPUT_LEVEL_GAIN, timeDomainBytesToLevel, } from './audio-level.ts';
|
|
2
|
+
export { createDecisionTransport, type DecisionInterface, type DecisionQuestionView, type DecisionReply, type DecisionTransport, decisionAssets, decisionInterface, failedDecisionTraces, failedTraces, postDecision, readDecisionReply, withFailedTraces, } from './decision-transport.ts';
|
|
3
|
+
export { type ComposerDraftFields, composerFieldsFromDraft } from './decode-composer-draft.ts';
|
|
4
|
+
export { addUsage, checkEmbeddingInputs, checkInputs, cosineSimilarity, type EmbeddingFields, type EmbeddingInputCheck, type EmbeddingMatch, type EmbeddingMediaPart, type EmbeddingSplit, embeddingBatches, fieldsInput, inputFields, MAX_BATCH_INPUTS, rankMatches, readEmbeddingInput, readEmbeddingInputs, readsAsText, splitText, } from './embedding-input.ts';
|
|
5
|
+
export { type EmbeddingSpace, layoutSpace, layoutSpaceSoon, placeQuery, type SpaceCluster, type SpaceDocument, type SpaceLink, type SpacePoint, } from './embedding-space.ts';
|
|
6
|
+
export { createEmbeddingTransport, type EmbeddingInterface, type EmbeddingReply, type EmbeddingTransport, type EmbedOptions, embeddingInterface, postEmbedding, readEmbeddingReply, } from './embedding-transport.ts';
|
|
7
|
+
export { encodeComposerDraft } from './encode-composer-draft.ts';
|
|
8
|
+
export { filesToPending, pendingAttachmentsToFiles } from './encode-files.ts';
|
|
9
|
+
export { type ClientFailure, clientFailure, type TurnFailure } from './failure.ts';
|
|
10
|
+
export { createHostTransport, HOST_TOOL_KINDS, type HostInterface, type HostToolKind, type HostToolSource, type HostToolView, type HostTransport, hostInterface, type TheoremHostCallRequest, } from './host-transport.ts';
|
|
11
|
+
export type { LiveCallOptions, PageTool, PageToolAnswer, PageTools, } from './live/live-page-tool.ts';
|
|
12
|
+
export { type LiveConnectPhase, type LiveSessionStatus, type LiveState, liveState, } from './live/live-state.ts';
|
|
13
|
+
export type { LiveToolGatePrompt } from './live/live-tool.ts';
|
|
14
|
+
export type { LiveConnection } from './live-client.ts';
|
|
15
|
+
export { LiveSessionClient } from './live-client.ts';
|
|
16
|
+
export type { LiveSocket } from './live-messages.ts';
|
|
17
|
+
export { isOAuthComplete, notifyOAuthComplete } from './oauth-popup.ts';
|
|
18
|
+
export { type PageDispatchResult, withPageToolDispatch } from './page-dispatch.ts';
|
|
19
|
+
export { keepsConversation, type RunOutcome, resumeInterfaceTool, type StreamView, streamInterfaceDraftTurn, streamInterfaceTurn, } from './run-session.ts';
|
|
20
|
+
export { type JsonSchema, type SchemaControl, type SchemaField, sampleFromSchema, schemaControl, schemaFields, } from './schema-fields.ts';
|
|
21
|
+
export { citationsFromBlock, type SourceCitation, type SourceCitationBlock, } from './source-citations.ts';
|
|
22
|
+
export type { QueryMatch } from './space-geometry.ts';
|
|
23
|
+
export { layoutResult, type ResultChart, type ResultFigure, type ResultImage, type ResultLayout, } from './tool-result.ts';
|
|
24
|
+
export type { AnsweringGate, ToolDecisionAction, ToolGateResolution, } from './tool-resume.ts';
|
|
25
|
+
export { continueGatedToolInvocation } from './tool-resume.ts';
|
|
26
|
+
export { createTraceFeed, type TraceFeed } from './trace-feed.ts';
|
|
27
|
+
export { CHAT_LINES, type ChatLine, type ChatLineSink, type ClientTurnEvent, type ConversationLine, type ConversationView, createHttpTransport, fetchConversation, fetchRewound, type HostErrorBody, type HttpOptions, type HttpTransportOptions, hostError, isTheoremStreamError, type MalformedEvent, postJson, postNdjson, readNdjsonStream, type TheoremConversationRequest, type TheoremInvokeRequest, type TheoremReplay, type TheoremRewindRequest, type TheoremRewound, type TheoremSteerRequest, TheoremStreamError, type TheoremTransport, type TheoremTurnInput, type TheoremTurnRequest, type TurnEventSink, type UnsupportedEvent, type WireLines, } from './transport.ts';
|
|
28
|
+
export { buildInvokeRequest, buildTurnRequest, issuedOperationId, type RunScope, type WalkAway, } from './turn-client.ts';
|
package/client/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export { float32Rms, float32RmsToLevel, INPUT_LEVEL_GAIN, timeDomainBytesToLevel, } from "./audio-level.js";
|
|
2
|
+
export { createDecisionTransport, decisionAssets, decisionInterface, failedDecisionTraces, failedTraces, postDecision, readDecisionReply, withFailedTraces, } from "./decision-transport.js";
|
|
3
|
+
export { composerFieldsFromDraft } from "./decode-composer-draft.js";
|
|
4
|
+
export { addUsage, checkEmbeddingInputs, checkInputs, cosineSimilarity, embeddingBatches, fieldsInput, inputFields, MAX_BATCH_INPUTS, rankMatches, readEmbeddingInput, readEmbeddingInputs, readsAsText, splitText, } from "./embedding-input.js";
|
|
5
|
+
export { layoutSpace, layoutSpaceSoon, placeQuery, } from "./embedding-space.js";
|
|
6
|
+
export { createEmbeddingTransport, embeddingInterface, postEmbedding, readEmbeddingReply, } from "./embedding-transport.js";
|
|
7
|
+
export { encodeComposerDraft } from "./encode-composer-draft.js";
|
|
8
|
+
export { filesToPending, pendingAttachmentsToFiles } from "./encode-files.js";
|
|
9
|
+
export { clientFailure } from "./failure.js";
|
|
10
|
+
export { createHostTransport, HOST_TOOL_KINDS, hostInterface, } from "./host-transport.js";
|
|
11
|
+
export { liveState, } from "./live/live-state.js";
|
|
12
|
+
export { LiveSessionClient } from "./live-client.js";
|
|
13
|
+
export { isOAuthComplete, notifyOAuthComplete } from "./oauth-popup.js";
|
|
14
|
+
export { withPageToolDispatch } from "./page-dispatch.js";
|
|
15
|
+
export { keepsConversation, resumeInterfaceTool, streamInterfaceDraftTurn, streamInterfaceTurn, } from "./run-session.js";
|
|
16
|
+
export { sampleFromSchema, schemaControl, schemaFields, } from "./schema-fields.js";
|
|
17
|
+
export { citationsFromBlock, } from "./source-citations.js";
|
|
18
|
+
export { layoutResult, } from "./tool-result.js";
|
|
19
|
+
export { continueGatedToolInvocation } from "./tool-resume.js";
|
|
20
|
+
export { createTraceFeed } from "./trace-feed.js";
|
|
21
|
+
export { CHAT_LINES, createHttpTransport, fetchConversation, fetchRewound, hostError, isTheoremStreamError, postJson, postNdjson, readNdjsonStream, TheoremStreamError, } from "./transport.js";
|
|
22
|
+
export { buildInvokeRequest, buildTurnRequest, issuedOperationId, } from "./turn-client.js";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare const INK_WAVE_BAR_COUNT = 21;
|
|
2
|
+
export declare const INK_WAVE_HERO_BAR_COUNT = 45;
|
|
3
|
+
/** Per-bar phase offsets — stable undulation, not a fixed bell curve. */
|
|
4
|
+
export declare function inkWavePhases(count: number): number[];
|
|
5
|
+
export type InkWaveStatus = 'disconnected' | 'connecting' | 'reconnecting' | 'connected' | 'ready' | 'listening' | 'speaking' | 'working' | 'error';
|
|
6
|
+
export type InkWaveDriver = 'idle' | 'input' | 'output' | 'tool' | 'working' | 'connecting';
|
|
7
|
+
export declare function inkWaveDriver(status: InkWaveStatus, toolActive: boolean, inputLevel: number, outputLevel: number, frozen?: boolean): InkWaveDriver;
|
|
8
|
+
export declare function computeInkBarTargets(args: {
|
|
9
|
+
phases: readonly number[];
|
|
10
|
+
timeMs: number;
|
|
11
|
+
driver: InkWaveDriver;
|
|
12
|
+
inputLevel: number;
|
|
13
|
+
outputLevel: number;
|
|
14
|
+
frozen?: boolean;
|
|
15
|
+
}): number[];
|
|
16
|
+
/** Smooth toward targets each animation frame (orchid ease feel). */
|
|
17
|
+
export declare function stepInkBarHeights(current: number[], targets: number[], alpha?: number): number[];
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export const INK_WAVE_BAR_COUNT = 21;
|
|
2
|
+
export const INK_WAVE_HERO_BAR_COUNT = 45;
|
|
3
|
+
const LEVEL_FLOOR = 0.02;
|
|
4
|
+
/** Per-bar phase offsets — stable undulation, not a fixed bell curve. */
|
|
5
|
+
export function inkWavePhases(count) {
|
|
6
|
+
return Array.from({ length: count }, (_, i) => i * 0.73 + Math.sin(i * 1.17) * 0.4);
|
|
7
|
+
}
|
|
8
|
+
export function inkWaveDriver(status, toolActive, inputLevel, outputLevel, frozen = false) {
|
|
9
|
+
if (frozen)
|
|
10
|
+
return 'idle';
|
|
11
|
+
if (status === 'disconnected' || status === 'error')
|
|
12
|
+
return 'idle';
|
|
13
|
+
if (status === 'connecting' || status === 'reconnecting')
|
|
14
|
+
return 'connecting';
|
|
15
|
+
if (toolActive)
|
|
16
|
+
return 'tool';
|
|
17
|
+
if (status === 'speaking' || outputLevel > LEVEL_FLOOR)
|
|
18
|
+
return 'output';
|
|
19
|
+
if (inputLevel > LEVEL_FLOOR)
|
|
20
|
+
return 'input';
|
|
21
|
+
if (status === 'working')
|
|
22
|
+
return 'working';
|
|
23
|
+
if (status === 'listening' || status === 'ready')
|
|
24
|
+
return 'idle';
|
|
25
|
+
return 'idle';
|
|
26
|
+
}
|
|
27
|
+
export function computeInkBarTargets(args) {
|
|
28
|
+
const t = args.timeMs * 0.001;
|
|
29
|
+
if (args.frozen) {
|
|
30
|
+
return args.phases.map((phase, index) => {
|
|
31
|
+
const silhouette = 0.22 + 0.55 * (0.5 + 0.5 * Math.sin(phase * 1.7 + index * 0.41));
|
|
32
|
+
return Math.min(0.82, Math.max(0.1, silhouette));
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
const input = args.inputLevel;
|
|
36
|
+
const output = args.outputLevel;
|
|
37
|
+
let master;
|
|
38
|
+
switch (args.driver) {
|
|
39
|
+
case 'output':
|
|
40
|
+
master = 0.18 + output * 0.95;
|
|
41
|
+
break;
|
|
42
|
+
case 'input':
|
|
43
|
+
master = 0.16 + input * 0.96;
|
|
44
|
+
break;
|
|
45
|
+
case 'tool':
|
|
46
|
+
master = 0.28 + 0.18 * Math.sin(t * 5.2) + Math.max(output, input) * 0.45;
|
|
47
|
+
break;
|
|
48
|
+
case 'working':
|
|
49
|
+
master = 0.16 + 0.08 * Math.sin(t * 2.2) + Math.max(output, input) * 0.45;
|
|
50
|
+
break;
|
|
51
|
+
case 'connecting':
|
|
52
|
+
master = 0.14 + 0.1 * Math.sin(t * 3.1);
|
|
53
|
+
break;
|
|
54
|
+
default:
|
|
55
|
+
master = 0.08 + 0.04 * Math.sin(t * 1.4);
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
return args.phases.map((phase, index) => {
|
|
59
|
+
const wobble = 0.72 + 0.28 * Math.sin(t * 3.4 + phase);
|
|
60
|
+
const ripple = 0.68 + 0.32 * Math.sin(t * 5.3 + index * 0.62);
|
|
61
|
+
const height = master * wobble * ripple;
|
|
62
|
+
return Math.min(1, Math.max(0.06, height));
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/** Smooth toward targets each animation frame (orchid ease feel). */
|
|
66
|
+
export function stepInkBarHeights(current, targets, alpha = 0.14) {
|
|
67
|
+
return current.map((value, index) => value + (targets[index] - value) * alpha);
|
|
68
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { TurnEvent } from '@theoremjs/agents';
|
|
2
|
+
type LiveToolEventArgs = {
|
|
3
|
+
/** The call whose gate the user is looking at, if one is open. */
|
|
4
|
+
gateCallId: string | undefined;
|
|
5
|
+
/** Close the open gate without an answer: its call is gone. */
|
|
6
|
+
withdrawGate: () => void;
|
|
7
|
+
clearInterim: () => void;
|
|
8
|
+
clearActiveTool: () => void;
|
|
9
|
+
reportFailure: (err: unknown) => void;
|
|
10
|
+
setActiveTool: (name: string) => void;
|
|
11
|
+
};
|
|
12
|
+
export type { LiveToolEventArgs };
|
|
13
|
+
/** Apply a live turn event to active-tool / caption / error state. */
|
|
14
|
+
export declare function applyLiveTurnToolEvent(event: TurnEvent, args: LiveToolEventArgs): void;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { TheoremStreamError } from "../transport.js";
|
|
2
|
+
/**
|
|
3
|
+
* A failed tool step as the host reported it: the user reads its wording (else
|
|
4
|
+
* the labels' for its kind); the model's `message` stays builder detail.
|
|
5
|
+
*/
|
|
6
|
+
function toolStepFailure(failure) {
|
|
7
|
+
return new TheoremStreamError(failure.kind, failure.error, failure.message);
|
|
8
|
+
}
|
|
9
|
+
function clearToolUnlessGated(args) {
|
|
10
|
+
if (args.gateCallId === undefined)
|
|
11
|
+
args.clearActiveTool();
|
|
12
|
+
}
|
|
13
|
+
function applyToolPhase(tool, args) {
|
|
14
|
+
if (tool.phase === 'cancel' && tool.callId === args.gateCallId) {
|
|
15
|
+
args.withdrawGate();
|
|
16
|
+
args.clearActiveTool();
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (tool.phase === 'cancel' || tool.phase === 'complete') {
|
|
20
|
+
clearToolUnlessGated(args);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (tool.phase === 'error') {
|
|
24
|
+
args.reportFailure(toolStepFailure(tool.failure));
|
|
25
|
+
clearToolUnlessGated(args);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
args.setActiveTool(tool.name);
|
|
29
|
+
}
|
|
30
|
+
/** Apply a live turn event to active-tool / caption / error state. */
|
|
31
|
+
export function applyLiveTurnToolEvent(event, args) {
|
|
32
|
+
if (event.type === 'done') {
|
|
33
|
+
args.clearInterim();
|
|
34
|
+
clearToolUnlessGated(args);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (event.type === 'tool')
|
|
38
|
+
applyToolPhase(event.tool, args);
|
|
39
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { TurnEvent } from '@theoremjs/agents';
|
|
2
|
+
import { type TranscriptBlock } from '@theoremjs/agents/interface';
|
|
3
|
+
/** What the agent did between its lines of speech: the events the chat folds into a reply's work. */
|
|
4
|
+
export type LiveWorkEvent = Extract<TurnEvent, {
|
|
5
|
+
type: 'thought' | 'tool' | 'citation';
|
|
6
|
+
}>;
|
|
7
|
+
/** A line of speech, or the work the agent did before its next one. */
|
|
8
|
+
export type LiveCaptionTurn = {
|
|
9
|
+
id: string;
|
|
10
|
+
role: 'user' | 'agent';
|
|
11
|
+
text: string;
|
|
12
|
+
} | {
|
|
13
|
+
id: string;
|
|
14
|
+
role: 'work';
|
|
15
|
+
events: LiveWorkEvent[];
|
|
16
|
+
};
|
|
17
|
+
export type LiveCaptionState = {
|
|
18
|
+
turns: LiveCaptionTurn[];
|
|
19
|
+
interimUser: string;
|
|
20
|
+
interimAgent: string;
|
|
21
|
+
/** The agent has worked and its reply has not ended. */
|
|
22
|
+
working: boolean;
|
|
23
|
+
};
|
|
24
|
+
export type ApplyLiveTranscriptOptions = {
|
|
25
|
+
/** Commit as a new turn even when the last turn shares the same role (explicit text send). */
|
|
26
|
+
forceNew?: boolean;
|
|
27
|
+
};
|
|
28
|
+
export declare function emptyLiveCaptionState(): LiveCaptionState;
|
|
29
|
+
/** Keep this call's lines so the next call starts below a divider. A call with no lines adds nothing. */
|
|
30
|
+
export declare function stashLiveCaptionCall(past: LiveCaptionTurn[][], turns: readonly LiveCaptionTurn[]): LiveCaptionTurn[][];
|
|
31
|
+
/**
|
|
32
|
+
* Fold streaming ASR deltas into turn-by-turn caption lines.
|
|
33
|
+
* Final chunks for the same role append to the open turn; role switches start a new turn.
|
|
34
|
+
*/
|
|
35
|
+
export declare function applyLiveTranscript(state: LiveCaptionState, text: string, isUser: boolean, interim?: boolean, options?: ApplyLiveTranscriptOptions): LiveCaptionState;
|
|
36
|
+
/**
|
|
37
|
+
* Fold a live turn event into the captions. A thought, a tool call, or a citation joins the open
|
|
38
|
+
* work, else starts it; a tool call's later events go to the work that made the call. `done` ends
|
|
39
|
+
* the reply.
|
|
40
|
+
*/
|
|
41
|
+
export declare function applyLiveTurnEvent(state: LiveCaptionState, event: TurnEvent): LiveCaptionState;
|
|
42
|
+
export type LiveCaptionTranscript = {
|
|
43
|
+
blocks: TranscriptBlock[];
|
|
44
|
+
/** The first block of each call after the first: where one call's captions end and the next begin. */
|
|
45
|
+
callStarts: string[];
|
|
46
|
+
};
|
|
47
|
+
/** Captions as the chat's transcript blocks: past calls, this call, then the lines still being heard. */
|
|
48
|
+
export declare function liveCaptionTranscript(pastCalls: readonly (readonly LiveCaptionTurn[])[], { turns, interimUser, interimAgent }: LiveCaptionState): LiveCaptionTranscript;
|
|
49
|
+
/** The agent is mid-reply: a line of its speech is still arriving, or it is working. */
|
|
50
|
+
export declare function liveCaptionStreaming({ working, interimAgent }: LiveCaptionState): boolean;
|
|
51
|
+
/** Clear streaming partials when a live turn completes or is interrupted. */
|
|
52
|
+
export declare function clearLiveCaptionInterim(state: LiveCaptionState): LiveCaptionState;
|
|
53
|
+
export declare function latestLiveCaptionTurnId(state: LiveCaptionState): string | null;
|