theorum 0.1.14 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +178 -89
- package/esm/mod.d.ts +21 -11
- package/esm/mod.js +15 -8
- package/esm/src/cli/commands/bench.js +6 -3
- package/esm/src/cli/commands/fuzz-canary.d.ts +13 -0
- package/esm/src/cli/commands/fuzz-canary.js +195 -0
- package/esm/src/cli/commands/fuzz-guardrails.d.ts +3 -5
- package/esm/src/cli/commands/fuzz-guardrails.js +4 -581
- package/esm/src/cli/commands/profile.js +25 -14
- package/esm/src/cli/commands/run.d.ts +3 -0
- package/esm/src/cli/commands/run.js +22 -30
- package/esm/src/cli/commands/test.d.ts +10 -1
- package/esm/src/cli/commands/test.js +31 -31
- package/esm/src/cli/event-log.d.ts +19 -0
- package/esm/src/cli/event-log.js +147 -0
- package/esm/src/cli/index.js +45 -11
- package/esm/src/cli/matrix/synthesizer.d.ts +7 -9
- package/esm/src/cli/matrix/synthesizer.js +32 -106
- package/esm/src/guardrails/canary-gate.d.ts +20 -0
- package/esm/src/guardrails/canary-gate.js +31 -0
- package/esm/src/guardrails/canary.d.ts +26 -0
- package/esm/src/guardrails/canary.js +139 -0
- package/esm/src/guardrails/corpus/canary-egress-attacks.d.ts +16 -0
- package/esm/src/guardrails/corpus/canary-egress-attacks.js +151 -0
- package/esm/src/guardrails/corpus/fuzz-inbound.d.ts +11 -0
- package/esm/src/guardrails/corpus/fuzz-inbound.js +216 -0
- package/esm/src/guardrails/corpus/inbound-payloads.d.ts +10 -0
- package/esm/src/guardrails/corpus/inbound-payloads.js +124 -0
- package/esm/src/guardrails/corpus/live-attacks.d.ts +20 -0
- package/esm/src/guardrails/corpus/live-attacks.js +232 -0
- package/esm/src/guardrails/corpus/mod.d.ts +13 -0
- package/esm/src/guardrails/corpus/mod.js +11 -0
- package/esm/src/guardrails/corpus/secrets.d.ts +16 -0
- package/esm/src/guardrails/corpus/secrets.js +16 -0
- package/esm/src/guardrails/corpus/strings.d.ts +27 -0
- package/esm/src/guardrails/corpus/strings.js +33 -0
- package/esm/src/guardrails/corpus/types.d.ts +37 -0
- package/esm/src/guardrails/corpus/types.js +6 -0
- package/esm/src/guardrails/egress.d.ts +9 -0
- package/esm/src/guardrails/egress.js +36 -0
- package/esm/src/guardrails/error.js +6 -4
- package/esm/src/guardrails/injection.js +28 -5
- package/esm/src/guardrails/live-outbound-gate.d.ts +39 -0
- package/esm/src/guardrails/live-outbound-gate.js +180 -0
- package/esm/src/guardrails/mod.d.ts +13 -4
- package/esm/src/guardrails/mod.js +10 -4
- package/esm/src/guardrails/quota.js +1 -1
- package/esm/src/guardrails/sanitize.d.ts +11 -15
- package/esm/src/guardrails/sanitize.js +40 -49
- package/esm/src/guardrails/sensitive.js +2 -1
- package/esm/src/guardrails/testing.d.ts +10 -0
- package/esm/src/guardrails/testing.js +9 -0
- package/esm/src/host/client-turn.d.ts +19 -0
- package/esm/src/host/client-turn.js +32 -0
- package/esm/src/host/mod.d.ts +5 -3
- package/esm/src/host/mod.js +4 -3
- package/esm/src/interface/blocks.d.ts +20 -0
- package/esm/src/interface/blocks.js +180 -0
- package/esm/src/interface/from-profile.d.ts +14 -0
- package/esm/src/interface/from-profile.js +104 -0
- package/esm/src/interface/inputs.d.ts +8 -0
- package/esm/src/interface/inputs.js +127 -0
- package/esm/src/interface/mod.d.ts +10 -0
- package/esm/src/interface/mod.js +9 -0
- package/esm/src/interface/types.d.ts +153 -0
- package/esm/src/interface/types.js +13 -0
- package/esm/src/kernel/engine/delta.d.ts +24 -2
- package/esm/src/kernel/engine/delta.js +519 -29
- package/esm/src/kernel/engine/live-inbound.d.ts +9 -0
- package/esm/src/kernel/engine/live-inbound.js +17 -0
- package/esm/src/kernel/engine/repair.js +1 -1
- package/esm/src/kernel/engine/runner/gates.d.ts +1 -1
- package/esm/src/kernel/engine/runner/gates.js +7 -7
- package/esm/src/kernel/engine/runner/mod.js +13 -13
- package/esm/src/kernel/engine/runner/state.d.ts +7 -0
- package/esm/src/kernel/engine/runner/steps.d.ts +1 -1
- package/esm/src/kernel/engine/runner/steps.js +171 -37
- package/esm/src/kernel/engine/runner/stream.d.ts +1 -2
- package/esm/src/kernel/engine/runner/stream.js +66 -29
- package/esm/src/kernel/engine/session/mod.d.ts +23 -0
- package/esm/src/kernel/engine/session/mod.js +205 -0
- package/esm/src/kernel/mod.d.ts +9 -10
- package/esm/src/kernel/mod.js +6 -8
- package/esm/src/kernel/registry/attachments.d.ts +4 -2
- package/esm/src/kernel/registry/attachments.js +6 -3
- package/esm/src/kernel/registry/catalog.d.ts +3 -16
- package/esm/src/kernel/registry/catalog.js +5 -81
- package/esm/src/kernel/registry/ingress.d.ts +9 -4
- package/esm/src/kernel/registry/ingress.js +73 -63
- package/esm/src/kernel/registry/profiles.d.ts +35 -12
- package/esm/src/kernel/registry/profiles.js +159 -66
- package/esm/src/kernel/registry/provider-request.js +11 -7
- package/esm/src/kernel/registry/resolve.d.ts +5 -6
- package/esm/src/kernel/registry/resolve.js +100 -70
- package/esm/src/kernel/registry/vault.d.ts +12 -7
- package/esm/src/kernel/registry/vault.js +30 -8
- package/esm/src/kernel/schema.d.ts +145 -0
- package/esm/src/kernel/schema.js +462 -0
- package/esm/src/kernel/stop.d.ts +15 -10
- package/esm/src/kernel/stop.js +5 -5
- package/esm/src/kernel/tools/execute.d.ts +45 -0
- package/esm/src/kernel/tools/execute.js +363 -0
- package/esm/src/kernel/tools/harness.d.ts +8 -0
- package/esm/src/kernel/tools/harness.js +44 -0
- package/esm/src/kernel/tools/invoke.d.ts +10 -0
- package/esm/src/kernel/tools/invoke.js +83 -0
- package/esm/src/kernel/tools/mod.d.ts +11 -0
- package/esm/src/kernel/tools/mod.js +10 -0
- package/esm/src/kernel/tools/project.d.ts +12 -0
- package/esm/src/kernel/tools/project.js +34 -0
- package/esm/src/kernel/tools/registry.d.ts +23 -0
- package/esm/src/kernel/tools/registry.js +71 -0
- package/esm/src/kernel/tools/resolve.d.ts +29 -0
- package/esm/src/kernel/tools/resolve.js +262 -0
- package/esm/src/kernel/tools/schema.d.ts +13 -0
- package/esm/src/kernel/tools/schema.js +159 -0
- package/esm/src/kernel/tools/types.d.ts +216 -0
- package/esm/src/kernel/tools/types.js +9 -0
- package/esm/src/kernel/types.d.ts +338 -193
- package/esm/src/observability/trace-attach.d.ts +6 -4
- package/esm/src/observability/trace-attach.js +39 -25
- package/esm/src/observability/trace-record.d.ts +11 -9
- package/esm/src/observability/trace-record.js +36 -23
- package/esm/src/observability/trace-usage.d.ts +10 -3
- package/esm/src/observability/trace-usage.js +70 -17
- package/esm/src/observability/trace.d.ts +9 -1
- package/esm/src/observability/trace.js +11 -3
- package/esm/src/presets/google/speech-voices.d.ts +11 -0
- package/esm/src/presets/google/speech-voices.js +41 -0
- package/esm/src/presets/google.d.ts +36 -24
- package/esm/src/presets/google.js +50 -63
- package/esm/src/presets/mod.d.ts +2 -2
- package/esm/src/presets/mod.js +1 -1
- package/esm/src/providers/create-provider.d.ts +14 -14
- package/esm/src/providers/create-provider.js +55 -23
- package/esm/src/providers/google/interactions/framing.d.ts +15 -0
- package/esm/src/providers/google/interactions/framing.js +208 -0
- package/esm/src/providers/google/interactions/mod.d.ts +7 -0
- package/esm/src/providers/google/interactions/mod.js +7 -0
- package/esm/src/providers/google/interactions/stream.d.ts +83 -0
- package/esm/src/providers/google/interactions/stream.js +588 -0
- package/esm/src/providers/google/keys.d.ts +26 -0
- package/esm/src/providers/{keys.js → google/keys.js} +19 -31
- package/esm/src/providers/google/live/framing.d.ts +46 -0
- package/esm/src/providers/google/live/framing.js +515 -0
- package/esm/src/providers/google/live/openapi-schema.d.ts +6 -0
- package/esm/src/providers/google/live/openapi-schema.js +45 -0
- package/esm/src/providers/google/live/session.d.ts +25 -0
- package/esm/src/providers/google/live/session.js +134 -0
- package/esm/src/providers/google/live/stream.d.ts +36 -0
- package/esm/src/providers/google/live/stream.js +201 -0
- package/esm/src/providers/google/urls.d.ts +6 -0
- package/esm/src/providers/google/urls.js +6 -0
- package/esm/src/providers/local/local.d.ts +30 -0
- package/esm/src/providers/{local.js → local/local.js} +66 -126
- package/esm/src/providers/local/mod.d.ts +9 -0
- package/esm/src/providers/local/mod.js +9 -0
- package/esm/src/providers/mod.d.ts +6 -3
- package/esm/src/providers/mod.js +3 -1
- package/esm/src/providers/openrouter/chat.d.ts +87 -0
- package/esm/src/providers/{openrouter.js → openrouter/chat.js} +70 -229
- package/esm/src/providers/openrouter/image.d.ts +34 -0
- package/esm/src/providers/openrouter/image.js +286 -0
- package/esm/src/providers/openrouter/openai/chat-payload.d.ts +24 -0
- package/esm/src/providers/openrouter/openai/chat-payload.js +60 -0
- package/esm/src/providers/openrouter/openai/compat.d.ts +47 -0
- package/esm/src/providers/openrouter/openai/compat.js +194 -0
- package/esm/src/providers/openrouter/openai/image-payload.d.ts +18 -0
- package/esm/src/providers/openrouter/openai/image-payload.js +84 -0
- package/esm/src/providers/openrouter/openai/sdk-messages.d.ts +22 -0
- package/esm/src/providers/openrouter/openai/sdk-messages.js +95 -0
- package/esm/src/providers/openrouter/resolve-api-key.d.ts +9 -0
- package/esm/src/providers/openrouter/resolve-api-key.js +24 -0
- package/esm/src/providers/openrouter/speech.d.ts +23 -0
- package/esm/src/providers/{speech.js → openrouter/speech.js} +32 -55
- package/esm/src/providers/probe.d.ts +1 -0
- package/esm/src/providers/probe.js +22 -0
- package/esm/src/providers/shared/pcm.d.ts +12 -0
- package/esm/src/providers/{pcm.js → shared/pcm.js} +16 -3
- package/esm/src/providers/shared/sse.d.ts +18 -0
- package/esm/src/providers/shared/sse.js +87 -0
- package/esm/src/providers/shared/tool-args.d.ts +17 -0
- package/esm/src/providers/shared/tool-args.js +45 -0
- package/esm/src/providers/shared/upstream-tap.d.ts +5 -0
- package/esm/src/providers/{google-tap.js → shared/upstream-tap.js} +4 -7
- package/esm/src/providers/shared/upstream-tape.d.ts +6 -0
- package/esm/src/providers/{gemini-tape.js → shared/upstream-tape.js} +12 -22
- package/esm/src/providers/types.d.ts +27 -0
- package/esm/src/providers/types.js +1 -0
- package/package.json +11 -7
- package/docs/cli.md +0 -97
- package/docs/guardrails.md +0 -178
- package/docs/host.md +0 -97
- package/docs/kernel.md +0 -404
- package/docs/observability.md +0 -105
- package/docs/openrouter.md +0 -125
- package/docs/presets-google.md +0 -91
- package/docs/presets.md +0 -88
- package/docs/providers.md +0 -201
- package/docs/streaming.md +0 -96
- package/esm/src/kernel/engine/boundary.d.ts +0 -10
- package/esm/src/kernel/engine/boundary.js +0 -55
- package/esm/src/kernel/engine/runner/tools.d.ts +0 -13
- package/esm/src/kernel/engine/runner/tools.js +0 -198
- package/esm/src/kernel/registry/tools.d.ts +0 -12
- package/esm/src/kernel/registry/tools.js +0 -36
- package/esm/src/providers/expose-for-tests.d.ts +0 -1
- package/esm/src/providers/expose-for-tests.js +0 -25
- package/esm/src/providers/gemini-tape.d.ts +0 -2
- package/esm/src/providers/google-tap.d.ts +0 -3
- package/esm/src/providers/interactions.d.ts +0 -5
- package/esm/src/providers/interactions.js +0 -169
- package/esm/src/providers/keys.d.ts +0 -19
- package/esm/src/providers/local.d.ts +0 -29
- package/esm/src/providers/openrouter-mod.d.ts +0 -13
- package/esm/src/providers/openrouter-mod.js +0 -12
- package/esm/src/providers/openrouter-payload.d.ts +0 -39
- package/esm/src/providers/openrouter-payload.js +0 -195
- package/esm/src/providers/openrouter.d.ts +0 -15
- package/esm/src/providers/pcm.d.ts +0 -7
- package/esm/src/providers/provider.d.ts +0 -15
- package/esm/src/providers/provider.js +0 -176
- package/esm/src/providers/speech.d.ts +0 -23
- package/esm/src/providers/sse.d.ts +0 -7
- package/esm/src/providers/sse.js +0 -55
- package/esm/src/streaming/mod.d.ts +0 -9
- package/esm/src/streaming/mod.js +0 -8
- /package/esm/src/{streaming → host}/readStreamingJsonStringField.d.ts +0 -0
- /package/esm/src/{streaming → host}/readStreamingJsonStringField.js +0 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Profile `inputs` → UI affordances and validation.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import * as dntShim from "../../_dnt.shims.js";
|
|
7
|
+
import { fileTooLargeMessage, maxBytesForMime, resolveMediaLimits, tooManyFilesMessage, turnTooLargeMessage, } from '../kernel/registry/attachments.js';
|
|
8
|
+
import { mimeAllowed } from '../kernel/registry/catalog.js';
|
|
9
|
+
const RECORDER_CANDIDATES = [
|
|
10
|
+
'audio/webm;codecs=opus',
|
|
11
|
+
'audio/webm',
|
|
12
|
+
'audio/mp4',
|
|
13
|
+
'audio/wav',
|
|
14
|
+
'audio/mpeg',
|
|
15
|
+
];
|
|
16
|
+
function attachmentAcceptAttr(accept) {
|
|
17
|
+
return accept.join(',');
|
|
18
|
+
}
|
|
19
|
+
function inputsFromSpec(type, inputs) {
|
|
20
|
+
if (type === 'speech') {
|
|
21
|
+
return { text: true, attachments: null, voice: null };
|
|
22
|
+
}
|
|
23
|
+
const accept = inputs?.attachments?.accept;
|
|
24
|
+
const voiceAccept = inputs?.voice?.accept;
|
|
25
|
+
return {
|
|
26
|
+
text: inputs?.text !== false,
|
|
27
|
+
attachments: accept?.length ? { accept, acceptAttr: attachmentAcceptAttr(accept) } : null,
|
|
28
|
+
voice: voiceAccept?.length ? { accept: voiceAccept } : null,
|
|
29
|
+
maxFiles: inputs?.maxFiles,
|
|
30
|
+
maxBytes: inputs?.maxBytes,
|
|
31
|
+
maxTurnBytes: inputs?.maxTurnBytes,
|
|
32
|
+
limitsByMime: inputs?.limitsByMime,
|
|
33
|
+
slots: inputs?.slots,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function toProfileInputsSpec(inputs) {
|
|
37
|
+
return {
|
|
38
|
+
text: inputs.text,
|
|
39
|
+
attachments: inputs.attachments ? { accept: inputs.attachments.accept } : undefined,
|
|
40
|
+
voice: inputs.voice ? { accept: inputs.voice.accept } : undefined,
|
|
41
|
+
maxFiles: inputs.maxFiles,
|
|
42
|
+
maxBytes: inputs.maxBytes,
|
|
43
|
+
maxTurnBytes: inputs.maxTurnBytes,
|
|
44
|
+
limitsByMime: inputs.limitsByMime,
|
|
45
|
+
slots: inputs.slots,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function issue(code, message, fileName) {
|
|
49
|
+
return { code, message, fileName };
|
|
50
|
+
}
|
|
51
|
+
function validateMime(accept, files, channelLabel) {
|
|
52
|
+
const issues = [];
|
|
53
|
+
for (const file of files) {
|
|
54
|
+
if (!mimeAllowed(accept, file.mimeType)) {
|
|
55
|
+
issues.push(issue('mime_not_allowed', `${file.name}: MIME '${file.mimeType}' is not accepted for ${channelLabel} input.`, file.name));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return issues;
|
|
59
|
+
}
|
|
60
|
+
function validateLimits(files, limits) {
|
|
61
|
+
const issues = [];
|
|
62
|
+
if (files.length > limits.maxFiles) {
|
|
63
|
+
issues.push(issue('too_many_files', tooManyFilesMessage(limits.maxFiles)));
|
|
64
|
+
return issues;
|
|
65
|
+
}
|
|
66
|
+
let total = 0;
|
|
67
|
+
for (const file of files) {
|
|
68
|
+
const maxAllowed = maxBytesForMime(file.mimeType, limits);
|
|
69
|
+
if (file.sizeBytes > maxAllowed) {
|
|
70
|
+
issues.push(issue('file_too_large', fileTooLargeMessage(maxAllowed), file.name));
|
|
71
|
+
}
|
|
72
|
+
total += file.sizeBytes;
|
|
73
|
+
}
|
|
74
|
+
if (total > limits.maxTurnBytes) {
|
|
75
|
+
issues.push(issue('turn_too_large', turnTooLargeMessage(limits.maxTurnBytes)));
|
|
76
|
+
}
|
|
77
|
+
return issues;
|
|
78
|
+
}
|
|
79
|
+
/** Validate staged files against resolved profile `inputs`. */
|
|
80
|
+
function validateProfileInputs(inputs, draft) {
|
|
81
|
+
const attachments = draft.attachments ?? [];
|
|
82
|
+
const voice = draft.voice ?? [];
|
|
83
|
+
if (attachments.length === 0 && voice.length === 0) {
|
|
84
|
+
return { ok: true, issues: [] };
|
|
85
|
+
}
|
|
86
|
+
if (attachments.length > 0 && !inputs.attachments) {
|
|
87
|
+
return {
|
|
88
|
+
ok: false,
|
|
89
|
+
issues: [issue('mime_not_allowed', 'This profile does not accept file attachments.')],
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
if (voice.length > 0 && !inputs.voice) {
|
|
93
|
+
return {
|
|
94
|
+
ok: false,
|
|
95
|
+
issues: [issue('mime_not_allowed', 'This profile does not accept voice input.')],
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
const spec = toProfileInputsSpec(inputs);
|
|
99
|
+
const issues = [];
|
|
100
|
+
if (attachments.length > 0 && inputs.attachments) {
|
|
101
|
+
issues.push(...validateMime(inputs.attachments.accept, attachments, 'attachment'));
|
|
102
|
+
}
|
|
103
|
+
if (voice.length > 0 && inputs.voice) {
|
|
104
|
+
issues.push(...validateMime(inputs.voice.accept, voice, 'voice'));
|
|
105
|
+
}
|
|
106
|
+
const limits = resolveMediaLimits(spec);
|
|
107
|
+
if (!limits) {
|
|
108
|
+
issues.push(issue('limits_unconfigured', 'This profile accepts media but does not define maxFiles, maxBytes, and maxTurnBytes.'));
|
|
109
|
+
return { ok: false, issues };
|
|
110
|
+
}
|
|
111
|
+
issues.push(...validateLimits([...attachments, ...voice], limits));
|
|
112
|
+
return { ok: issues.length === 0, issues };
|
|
113
|
+
}
|
|
114
|
+
function pickMediaRecorderMime(accept) {
|
|
115
|
+
const supported = (mime) => {
|
|
116
|
+
const recorder = dntShim.dntGlobalThis
|
|
117
|
+
.MediaRecorder;
|
|
118
|
+
return recorder === undefined || recorder.isTypeSupported(mime);
|
|
119
|
+
};
|
|
120
|
+
const fromCandidates = (pool) => pool.find(supported);
|
|
121
|
+
if (accept?.length) {
|
|
122
|
+
return (fromCandidates(RECORDER_CANDIDATES.filter((mime) => mimeAllowed(accept, mime))) ??
|
|
123
|
+
accept.find(supported));
|
|
124
|
+
}
|
|
125
|
+
return fromCandidates(RECORDER_CANDIDATES);
|
|
126
|
+
}
|
|
127
|
+
export { attachmentAcceptAttr, inputsFromSpec, pickMediaRecorderMime, validateProfileInputs };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Headless profile-driven interface — spec, inputs, transcript folding.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
export { buildUserTurnBlocks, foldConversationTurn, foldTurnEvents, resetBlockIds, } from './blocks.js';
|
|
7
|
+
export { interfaceFrom, interfaceFromProfile, interfaceFromProjected } from './from-profile.js';
|
|
8
|
+
export { attachmentAcceptAttr, inputsFromSpec, pickMediaRecorderMime, validateProfileInputs, } from './inputs.js';
|
|
9
|
+
export type { AttachmentValidationCode, AttachmentValidationIssue, AttachmentValidationResult, FoldTurnEventsOptions, ImageProfileInterface, LiveProfileInterface, NormalizedModel, NormalizeModel, PendingAttachment, ProfileGuardrailsView, ProfileInputsInterface, ProfileInterface, ProfileInterfaceSource, ResolvedTools, SpeechProfileInterface, TextProfileInterface, TranscriptBlock, TranscriptBlockKind, UserTurnDraft, } from './types.js';
|
|
10
|
+
export { streamThoughtsEnabled } from './types.js';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Headless profile-driven interface — spec, inputs, transcript folding.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
export { buildUserTurnBlocks, foldConversationTurn, foldTurnEvents, resetBlockIds, } from './blocks.js';
|
|
7
|
+
export { interfaceFrom, interfaceFromProfile, interfaceFromProjected } from './from-profile.js';
|
|
8
|
+
export { attachmentAcceptAttr, inputsFromSpec, pickMediaRecorderMime, validateProfileInputs, } from './inputs.js';
|
|
9
|
+
export { streamThoughtsEnabled } from './types.js';
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Headless interface contracts — profile-driven UI spec and transcript blocks.
|
|
3
|
+
*
|
|
4
|
+
* `ProfileInterface` is `Profile` with resolved `inputs`/`tools` and a serializable
|
|
5
|
+
* `guardrails` view. No parallel schema.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import type { ProfileToolsSpec } from '../kernel/tools/types.js';
|
|
10
|
+
import type { ControlId, GroundingEvent, ImageProfile, LiveProfile, ModelId, Profile, ProfileGuardrailsSpec, ProfileModelSpec, ProfileOutputsSpec, ProjectedProfile, ProviderEvidenceEvent, RegisteredTool, SpeechProfile, TextProfile, ToolCallEvent, ToolId, TurnStop, TurnTokens } from '../kernel/types.js';
|
|
11
|
+
/** Guardrails visible to UI — egress enforcer functions are omitted. */
|
|
12
|
+
export type ProfileGuardrailsView = Pick<ProfileGuardrailsSpec, 'quota' | 'canary' | 'sanitizeInput' | 'redactSensitive'> & {
|
|
13
|
+
hasEgress: boolean;
|
|
14
|
+
};
|
|
15
|
+
/** `profile.model` with normalized `select` / `controls`. */
|
|
16
|
+
export type NormalizeModel<M extends ProfileModelSpec = ProfileModelSpec> = M & {
|
|
17
|
+
select: Record<string, ModelId> | null;
|
|
18
|
+
controls: ControlId[];
|
|
19
|
+
};
|
|
20
|
+
/** Resolved `inputs` — `ProfileInputsSpec` plus `acceptAttr` for file pickers. */
|
|
21
|
+
export interface ProfileInputsInterface {
|
|
22
|
+
text: boolean;
|
|
23
|
+
attachments: {
|
|
24
|
+
accept: string[];
|
|
25
|
+
acceptAttr: string;
|
|
26
|
+
} | null;
|
|
27
|
+
voice: {
|
|
28
|
+
accept: string[];
|
|
29
|
+
} | null;
|
|
30
|
+
maxFiles?: number;
|
|
31
|
+
maxBytes?: number;
|
|
32
|
+
maxTurnBytes?: number;
|
|
33
|
+
limitsByMime?: Record<string, number>;
|
|
34
|
+
slots?: Record<string, string[]>;
|
|
35
|
+
}
|
|
36
|
+
/** `profile.tools` plus resolved registry entries. */
|
|
37
|
+
export type ResolvedTools = ProfileToolsSpec & {
|
|
38
|
+
resolved: Array<RegisteredTool | {
|
|
39
|
+
name: ToolId;
|
|
40
|
+
missing: true;
|
|
41
|
+
}>;
|
|
42
|
+
};
|
|
43
|
+
export type NormalizedModel = NormalizeModel;
|
|
44
|
+
export type TextProfileInterface = Omit<TextProfile, 'inputs' | 'tools' | 'guardrails' | 'model'> & {
|
|
45
|
+
model: NormalizeModel<TextProfile['model']>;
|
|
46
|
+
inputs: ProfileInputsInterface;
|
|
47
|
+
tools: ResolvedTools;
|
|
48
|
+
guardrails?: ProfileGuardrailsView;
|
|
49
|
+
};
|
|
50
|
+
export type ImageProfileInterface = Omit<ImageProfile, 'inputs' | 'tools' | 'guardrails' | 'model'> & {
|
|
51
|
+
model: NormalizeModel<ImageProfile['model']>;
|
|
52
|
+
inputs: ProfileInputsInterface;
|
|
53
|
+
tools: ResolvedTools;
|
|
54
|
+
guardrails?: ProfileGuardrailsView;
|
|
55
|
+
};
|
|
56
|
+
export type SpeechProfileInterface = Omit<SpeechProfile, 'guardrails' | 'model'> & {
|
|
57
|
+
model: NormalizeModel<SpeechProfile['model']>;
|
|
58
|
+
inputs: ProfileInputsInterface;
|
|
59
|
+
guardrails?: ProfileGuardrailsView;
|
|
60
|
+
};
|
|
61
|
+
export type LiveProfileInterface = Omit<LiveProfile, 'inputs' | 'tools' | 'model' | 'guardrails'> & {
|
|
62
|
+
model: NormalizeModel<LiveProfile['model']>;
|
|
63
|
+
inputs: ProfileInputsInterface;
|
|
64
|
+
tools: ResolvedTools;
|
|
65
|
+
guardrails?: ProfileGuardrailsView;
|
|
66
|
+
};
|
|
67
|
+
export type ProfileInterface = TextProfileInterface | ImageProfileInterface | SpeechProfileInterface | LiveProfileInterface;
|
|
68
|
+
export type ProfileInterfaceSource = Profile | ProjectedProfile;
|
|
69
|
+
export type TranscriptBlockKind = 'user-text' | 'user-attachment' | 'user-voice' | 'thought' | 'text' | 'tool' | 'structured' | 'media' | 'grounding' | 'evidence' | 'error' | 'turn-done';
|
|
70
|
+
export interface TranscriptBlockBase {
|
|
71
|
+
id: string;
|
|
72
|
+
kind: TranscriptBlockKind;
|
|
73
|
+
}
|
|
74
|
+
export interface UserTextBlock extends TranscriptBlockBase {
|
|
75
|
+
kind: 'user-text';
|
|
76
|
+
text: string;
|
|
77
|
+
}
|
|
78
|
+
export interface UserAttachmentBlock extends TranscriptBlockBase {
|
|
79
|
+
kind: 'user-attachment' | 'user-voice';
|
|
80
|
+
name: string;
|
|
81
|
+
mimeType: string;
|
|
82
|
+
sizeBytes: number;
|
|
83
|
+
}
|
|
84
|
+
export interface ThoughtBlock extends TranscriptBlockBase {
|
|
85
|
+
kind: 'thought';
|
|
86
|
+
text: string;
|
|
87
|
+
}
|
|
88
|
+
export interface TextBlock extends TranscriptBlockBase {
|
|
89
|
+
kind: 'text';
|
|
90
|
+
text: string;
|
|
91
|
+
}
|
|
92
|
+
export interface ToolBlock extends TranscriptBlockBase {
|
|
93
|
+
kind: 'tool';
|
|
94
|
+
tool: ToolCallEvent & {
|
|
95
|
+
id?: string;
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
export interface StructuredBlock extends TranscriptBlockBase {
|
|
99
|
+
kind: 'structured';
|
|
100
|
+
value: unknown;
|
|
101
|
+
}
|
|
102
|
+
export interface MediaBlock extends TranscriptBlockBase {
|
|
103
|
+
kind: 'media';
|
|
104
|
+
mimeType: string;
|
|
105
|
+
data: string;
|
|
106
|
+
}
|
|
107
|
+
export interface GroundingBlock extends TranscriptBlockBase {
|
|
108
|
+
kind: 'grounding';
|
|
109
|
+
grounding: GroundingEvent;
|
|
110
|
+
}
|
|
111
|
+
export interface EvidenceBlock extends TranscriptBlockBase {
|
|
112
|
+
kind: 'evidence';
|
|
113
|
+
evidence: ProviderEvidenceEvent;
|
|
114
|
+
}
|
|
115
|
+
export interface ErrorBlock extends TranscriptBlockBase {
|
|
116
|
+
kind: 'error';
|
|
117
|
+
message: string;
|
|
118
|
+
}
|
|
119
|
+
export interface TurnDoneBlock extends TranscriptBlockBase {
|
|
120
|
+
kind: 'turn-done';
|
|
121
|
+
stop?: TurnStop;
|
|
122
|
+
tokens?: TurnTokens;
|
|
123
|
+
interactionId?: string;
|
|
124
|
+
compaction?: boolean;
|
|
125
|
+
}
|
|
126
|
+
export type TranscriptBlock = UserTextBlock | UserAttachmentBlock | ThoughtBlock | TextBlock | ToolBlock | StructuredBlock | MediaBlock | GroundingBlock | EvidenceBlock | ErrorBlock | TurnDoneBlock;
|
|
127
|
+
export interface PendingAttachment {
|
|
128
|
+
name: string;
|
|
129
|
+
mimeType: string;
|
|
130
|
+
sizeBytes: number;
|
|
131
|
+
}
|
|
132
|
+
export type AttachmentValidationCode = 'mime_not_allowed' | 'too_many_files' | 'file_too_large' | 'turn_too_large' | 'limits_unconfigured';
|
|
133
|
+
export interface AttachmentValidationIssue {
|
|
134
|
+
code: AttachmentValidationCode;
|
|
135
|
+
message: string;
|
|
136
|
+
fileName?: string;
|
|
137
|
+
}
|
|
138
|
+
export interface AttachmentValidationResult {
|
|
139
|
+
ok: boolean;
|
|
140
|
+
issues: AttachmentValidationIssue[];
|
|
141
|
+
}
|
|
142
|
+
export interface UserTurnDraft {
|
|
143
|
+
text?: string;
|
|
144
|
+
attachments?: PendingAttachment[];
|
|
145
|
+
voice?: PendingAttachment[];
|
|
146
|
+
}
|
|
147
|
+
export interface FoldTurnEventsOptions {
|
|
148
|
+
showThoughts?: boolean;
|
|
149
|
+
idPrefix?: string;
|
|
150
|
+
}
|
|
151
|
+
/** Whether `foldTurnEvents` should emit thought blocks for this profile. */
|
|
152
|
+
declare function streamThoughtsEnabled(outputs?: ProfileOutputsSpec): boolean;
|
|
153
|
+
export { streamThoughtsEnabled };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Headless interface contracts — profile-driven UI spec and transcript blocks.
|
|
3
|
+
*
|
|
4
|
+
* `ProfileInterface` is `Profile` with resolved `inputs`/`tools` and a serializable
|
|
5
|
+
* `guardrails` view. No parallel schema.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
/** Whether `foldTurnEvents` should emit thought blocks for this profile. */
|
|
10
|
+
function streamThoughtsEnabled(outputs) {
|
|
11
|
+
return outputs?.streaming?.streamThoughts !== false;
|
|
12
|
+
}
|
|
13
|
+
export { streamThoughtsEnabled };
|
|
@@ -1,8 +1,30 @@
|
|
|
1
1
|
import type { TurnEvent, TurnTokens } from '../types.js';
|
|
2
|
+
declare function isCodeExecutionType(type: string): boolean;
|
|
3
|
+
declare function isGoogleBuiltinStepType(type: string): boolean;
|
|
4
|
+
declare function googleBuiltinEvidence(raw: Record<string, unknown>): TurnEvent;
|
|
5
|
+
/** Merge a later code-exec delta/step onto an earlier snapshot (partial code/stdout). */
|
|
6
|
+
declare function mergeCodeExecutionPayload(existing: Record<string, unknown> | undefined, incoming: Record<string, unknown>): Record<string, unknown>;
|
|
7
|
+
/** Normalize a Google `code_execution_*` step/delta into an `evidence` event. */
|
|
8
|
+
declare function codeExecutionEvidence(raw: Record<string, unknown>): TurnEvent;
|
|
9
|
+
/** Stable key so streamed deltas and batched `steps[]` do not double-emit. */
|
|
10
|
+
declare function codeExecutionStepKey(raw: Record<string, unknown>, index?: number): string;
|
|
2
11
|
declare function eventsFromDelta(deltaValue: unknown): TurnEvent[];
|
|
12
|
+
/**
|
|
13
|
+
* Replay a completed Interactions `steps[]` array (non-SSE or stream tail).
|
|
14
|
+
* Emits typed code-execution evidence plus model_output text/media.
|
|
15
|
+
*/
|
|
16
|
+
declare function eventsFromInteractionSteps(steps: unknown[], alreadyText: boolean): TurnEvent[];
|
|
3
17
|
declare function groundingFromEvent(event: Record<string, unknown>): TurnEvent | undefined;
|
|
4
18
|
declare function extractUsageTokens(raw: unknown): TurnTokens | undefined;
|
|
5
19
|
declare function extractTokenEvent(event: Record<string, unknown>, interaction?: Record<string, unknown>): TurnEvent | undefined;
|
|
6
20
|
declare function eventsFromComplete(event: Record<string, unknown>, alreadyText: boolean): TurnEvent[];
|
|
7
|
-
|
|
8
|
-
|
|
21
|
+
export type ParsedStructuredOutput = {
|
|
22
|
+
ok: true;
|
|
23
|
+
structured: unknown;
|
|
24
|
+
} | {
|
|
25
|
+
ok: false;
|
|
26
|
+
error: string;
|
|
27
|
+
};
|
|
28
|
+
/** Parse model text as structured JSON. Invalid JSON is a hard failure — never silent skip. */
|
|
29
|
+
declare function parseStructuredOutput(text: string): ParsedStructuredOutput;
|
|
30
|
+
export { codeExecutionEvidence, codeExecutionStepKey, eventsFromComplete, eventsFromDelta, eventsFromInteractionSteps, extractTokenEvent, extractUsageTokens, googleBuiltinEvidence, groundingFromEvent, isCodeExecutionType, isGoogleBuiltinStepType, mergeCodeExecutionPayload, parseStructuredOutput, };
|