@theoremjs/agents 0.3.4-next.677.g14b70fe → 0.3.4-next.693.g4ab1526
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 +4 -3
- package/esm/mod.d.ts +3 -1
- package/esm/mod.js +2 -0
- package/esm/src/cli/commands/bench.js +4 -10
- package/esm/src/cli/commands/profile.js +4 -1
- package/esm/src/guardrails/labels.d.ts +1 -1
- package/esm/src/guardrails/labels.js +3 -0
- package/esm/src/interface/blocks.js +19 -0
- package/esm/src/interface/from-profile.d.ts +2 -2
- package/esm/src/interface/from-profile.js +7 -0
- package/esm/src/interface/mod.d.ts +1 -1
- package/esm/src/interface/profile-interface.js +14 -4
- package/esm/src/interface/types.d.ts +6 -4
- package/esm/src/kernel/api-catalog.js +5 -5
- package/esm/src/kernel/auth/oauth.js +3 -1
- package/esm/src/kernel/engine/runner/mod.js +1 -0
- package/esm/src/kernel/engine/session/mod.js +1 -0
- package/esm/src/kernel/engine/session/session-trace.js +1 -0
- package/esm/src/kernel/mod.d.ts +3 -1
- package/esm/src/kernel/mod.js +2 -0
- package/esm/src/kernel/profile-presence.js +1 -0
- package/esm/src/kernel/profile-scope.js +23 -21
- package/esm/src/kernel/protocols/protocol.d.ts +1 -1
- package/esm/src/kernel/protocols/protocol.js +1 -0
- package/esm/src/kernel/registry/catalog.js +4 -1
- package/esm/src/kernel/registry/ingress.d.ts +3 -1
- package/esm/src/kernel/registry/ingress.js +12 -1
- package/esm/src/kernel/registry/profile-outputs.js +2 -1
- package/esm/src/kernel/registry/profiles.d.ts +12 -2
- package/esm/src/kernel/registry/profiles.js +37 -7
- package/esm/src/kernel/registry/resolve.js +9 -5
- package/esm/src/kernel/registry/system-prompt.d.ts +6 -1
- package/esm/src/kernel/registry/system-prompt.js +20 -13
- package/esm/src/kernel/schema.d.ts +1 -1
- package/esm/src/kernel/schema.js +12 -8
- package/esm/src/kernel/system-lines.d.ts +22 -0
- package/esm/src/kernel/system-lines.js +162 -0
- package/esm/src/kernel/tools/activity-label.d.ts +15 -0
- package/esm/src/kernel/tools/activity-label.js +12 -7
- package/esm/src/kernel/tools/agent.js +1 -1
- package/esm/src/kernel/tools/call-order.d.ts +16 -0
- package/esm/src/kernel/tools/call-order.js +48 -0
- package/esm/src/kernel/tools/registry.js +9 -6
- package/esm/src/kernel/tools/resolve.js +11 -0
- package/esm/src/kernel/tools/stage-run.d.ts +1 -1
- package/esm/src/kernel/tools/stage-run.js +57 -55
- package/esm/src/kernel/tools/types.d.ts +3 -0
- package/esm/src/kernel/types.d.ts +31 -4
- package/esm/src/observability/trace-catalog.js +3 -0
- package/esm/src/providers/google/interactions/steps.js +14 -3
- package/esm/src/providers/mod.d.ts +2 -0
- package/esm/src/providers/mod.js +1 -0
- package/esm/src/providers/openrouter/protocol.d.ts +26 -0
- package/esm/src/providers/openrouter/protocol.js +58 -2
- package/esm/src/providers/openrouter/provider.d.ts +1 -1
- package/esm/src/providers/openrouter/provider.js +3 -1
- package/esm/src/providers/openrouter/transcriptions-protocol.d.ts +10 -0
- package/esm/src/providers/openrouter/transcriptions-protocol.js +87 -0
- package/package.json +1 -1
- package/esm/src/kernel/registry/system-role.d.ts +0 -3
- package/esm/src/kernel/registry/system-role.js +0 -9
|
@@ -9,6 +9,7 @@ export const ALL_PROFILE_TYPES = [
|
|
|
9
9
|
'text',
|
|
10
10
|
'image',
|
|
11
11
|
'speech',
|
|
12
|
+
'transcription',
|
|
12
13
|
'live',
|
|
13
14
|
'decision',
|
|
14
15
|
'embedding',
|
|
@@ -18,6 +19,7 @@ const MODEL_PROFILE_TYPES = [
|
|
|
18
19
|
'text',
|
|
19
20
|
'image',
|
|
20
21
|
'speech',
|
|
22
|
+
'transcription',
|
|
21
23
|
'live',
|
|
22
24
|
'decision',
|
|
23
25
|
'embedding',
|
|
@@ -25,15 +27,15 @@ const MODEL_PROFILE_TYPES = [
|
|
|
25
27
|
const TURN_TYPES = ['text', 'image', 'speech', 'live'];
|
|
26
28
|
/** Types whose `inputs` are turn inputs (text, files, slots) rather than decision state. */
|
|
27
29
|
const TURN_INPUT_TYPES = ['text', 'image'];
|
|
28
|
-
const TURN_INPUT_REASON = 'a decision takes JSON state,
|
|
30
|
+
const TURN_INPUT_REASON = 'a decision takes JSON state, live takes its input through live.ingress, and transcription takes only a clip';
|
|
29
31
|
/** Types that take slots and context: the turn types, and a call. */
|
|
30
32
|
const SLOT_TYPES = ['text', 'image', 'live'];
|
|
31
|
-
const SLOT_REASON = 'a decision takes JSON state, and
|
|
33
|
+
const SLOT_REASON = 'a decision takes JSON state, and transcription and embedding calls take their input alone';
|
|
32
34
|
/** Guardrails a host profile may set keep `host`; the rest guard a model turn. */
|
|
33
35
|
function turnGuardrailTypes(key) {
|
|
34
36
|
return HOST_GUARDRAIL_FIELDS.includes(key)
|
|
35
|
-
? [...TURN_TYPES, 'host']
|
|
36
|
-
: TURN_TYPES;
|
|
37
|
+
? [...TURN_TYPES, 'transcription', 'host']
|
|
38
|
+
: [...TURN_TYPES, 'transcription'];
|
|
37
39
|
}
|
|
38
40
|
/**
|
|
39
41
|
* The profile's own settings, which no section holds. The catalog names each `profile.<key>`, as
|
|
@@ -77,11 +79,11 @@ export const PROFILE_FIELD_SCOPE = {
|
|
|
77
79
|
profileTypes: MODEL_PROFILE_TYPES,
|
|
78
80
|
reason: 'a host profile has no agent identity — it runs no model',
|
|
79
81
|
},
|
|
80
|
-
'identity.
|
|
82
|
+
'identity.conditions': {
|
|
81
83
|
profileTypes: ['text', 'image', 'live'],
|
|
82
84
|
reason: 'speech has no system channel (the input text is the transcript), a decision is asked only through its questions, and an embedding call embeds its input alone',
|
|
83
85
|
},
|
|
84
|
-
'identity.
|
|
86
|
+
'identity.system': {
|
|
85
87
|
profileTypes: ['text', 'image', 'live'],
|
|
86
88
|
reason: 'speech has no system channel (the input text is the transcript), a decision is asked only through its questions, and an embedding call embeds its input alone',
|
|
87
89
|
},
|
|
@@ -96,14 +98,14 @@ export const PROFILE_FIELD_SCOPE = {
|
|
|
96
98
|
},
|
|
97
99
|
'models.*.compaction': {
|
|
98
100
|
profileTypes: ['text', 'image', 'speech'],
|
|
99
|
-
reason: 'live compacts with live.contextCompression, and decision and embedding calls keep no conversation to compact',
|
|
101
|
+
reason: 'live compacts with live.contextCompression, and transcription, decision, and embedding calls keep no conversation to compact',
|
|
100
102
|
},
|
|
101
103
|
'profile.defaultModel': {
|
|
102
|
-
profileTypes: [...TURN_TYPES, 'embedding'],
|
|
104
|
+
profileTypes: [...TURN_TYPES, 'transcription', 'embedding'],
|
|
103
105
|
reason: 'a host profile runs no model and a decision declares exactly one',
|
|
104
106
|
},
|
|
105
107
|
'profile.allowModelSelect': {
|
|
106
|
-
profileTypes: [...TURN_TYPES, 'embedding'],
|
|
108
|
+
profileTypes: [...TURN_TYPES, 'transcription', 'embedding'],
|
|
107
109
|
reason: 'a host profile runs no model and a decision declares exactly one',
|
|
108
110
|
},
|
|
109
111
|
'profile.maxSteps': {
|
|
@@ -116,7 +118,7 @@ export const PROFILE_FIELD_SCOPE = {
|
|
|
116
118
|
live: { profileTypes: ['live'], reason: 'only live profiles open a realtime session' },
|
|
117
119
|
tools: {
|
|
118
120
|
profileTypes: ['text', 'image', 'live', 'host'],
|
|
119
|
-
reason: 'speech, decision, and embedding profiles call no tools',
|
|
121
|
+
reason: 'speech, transcription, decision, and embedding profiles call no tools',
|
|
120
122
|
},
|
|
121
123
|
'tools.t1Policy': {
|
|
122
124
|
profileTypes: ['text', 'image'],
|
|
@@ -127,15 +129,15 @@ export const PROFILE_FIELD_SCOPE = {
|
|
|
127
129
|
reason: 'live function declarations are fixed at session setup, and a host profile can execute every allowed tool',
|
|
128
130
|
},
|
|
129
131
|
inputs: {
|
|
130
|
-
profileTypes: ['text', 'image', 'live', 'decision', 'embedding'],
|
|
132
|
+
profileTypes: ['text', 'image', 'transcription', 'live', 'decision', 'embedding'],
|
|
131
133
|
reason: 'speech input is the transcript, and a host profile takes no turns',
|
|
132
134
|
},
|
|
133
135
|
'inputs.voice': {
|
|
134
|
-
profileTypes: ['text'],
|
|
136
|
+
profileTypes: ['text', 'transcription'],
|
|
135
137
|
reason: 'no image model reads audio, live takes audio through live.ingress, a decision takes JSON state, and an embedding call takes text and files',
|
|
136
138
|
},
|
|
137
139
|
'inputs.text': {
|
|
138
|
-
profileTypes: [...TURN_INPUT_TYPES, 'embedding'],
|
|
140
|
+
profileTypes: [...TURN_INPUT_TYPES, 'transcription', 'embedding'],
|
|
139
141
|
reason: TURN_INPUT_REASON,
|
|
140
142
|
},
|
|
141
143
|
'inputs.attachments': {
|
|
@@ -143,19 +145,19 @@ export const PROFILE_FIELD_SCOPE = {
|
|
|
143
145
|
reason: TURN_INPUT_REASON,
|
|
144
146
|
},
|
|
145
147
|
'inputs.maxFiles': {
|
|
146
|
-
profileTypes: [...TURN_INPUT_TYPES, 'embedding'],
|
|
148
|
+
profileTypes: [...TURN_INPUT_TYPES, 'transcription', 'embedding'],
|
|
147
149
|
reason: TURN_INPUT_REASON,
|
|
148
150
|
},
|
|
149
151
|
'inputs.maxBytes': {
|
|
150
|
-
profileTypes: [...TURN_INPUT_TYPES, 'embedding'],
|
|
152
|
+
profileTypes: [...TURN_INPUT_TYPES, 'transcription', 'embedding'],
|
|
151
153
|
reason: TURN_INPUT_REASON,
|
|
152
154
|
},
|
|
153
155
|
'inputs.maxTurnBytes': {
|
|
154
|
-
profileTypes: [...TURN_INPUT_TYPES, 'embedding'],
|
|
156
|
+
profileTypes: [...TURN_INPUT_TYPES, 'transcription', 'embedding'],
|
|
155
157
|
reason: TURN_INPUT_REASON,
|
|
156
158
|
},
|
|
157
159
|
'inputs.limitsByMime': {
|
|
158
|
-
profileTypes: [...TURN_INPUT_TYPES, 'embedding'],
|
|
160
|
+
profileTypes: [...TURN_INPUT_TYPES, 'transcription', 'embedding'],
|
|
159
161
|
reason: TURN_INPUT_REASON,
|
|
160
162
|
},
|
|
161
163
|
'inputs.slots': {
|
|
@@ -176,7 +178,7 @@ export const PROFILE_FIELD_SCOPE = {
|
|
|
176
178
|
},
|
|
177
179
|
outputs: {
|
|
178
180
|
profileTypes: ['text', 'image', 'speech'],
|
|
179
|
-
reason: 'live output is the realtime session, and decision, embedding, and host profiles produce no turn output',
|
|
181
|
+
reason: 'live output is the realtime session, a transcription gives back its text, and decision, embedding, and host profiles produce no turn output',
|
|
180
182
|
},
|
|
181
183
|
'outputs.structured': {
|
|
182
184
|
profileTypes: ['text'],
|
|
@@ -213,15 +215,15 @@ export const PROFILE_FIELD_SCOPE = {
|
|
|
213
215
|
},
|
|
214
216
|
'guardrails.blockedReply': {
|
|
215
217
|
profileTypes: ['text', 'image', 'live'],
|
|
216
|
-
reason: 'only a reply can be blocked, and speech, decision, embedding, and host profiles write none',
|
|
218
|
+
reason: 'only a reply can be blocked, and speech, transcription, decision, embedding, and host profiles write none',
|
|
217
219
|
},
|
|
218
220
|
'guardrails.network': {
|
|
219
221
|
profileTypes: ['text', 'image', 'live', 'host'],
|
|
220
|
-
reason: 'speech, decision, and embedding profiles call no tools',
|
|
222
|
+
reason: 'speech, transcription, decision, and embedding profiles call no tools',
|
|
221
223
|
},
|
|
222
224
|
'guardrails.taint': {
|
|
223
225
|
profileTypes: ['text', 'image', 'live'],
|
|
224
|
-
reason: 'speech, decision, and embedding profiles call no tools, and a host profile runs no turn to taint',
|
|
226
|
+
reason: 'speech, transcription, decision, and embedding profiles call no tools, and a host profile runs no turn to taint',
|
|
225
227
|
},
|
|
226
228
|
'guardrails.disclosure': {
|
|
227
229
|
profileTypes: ['decision'],
|
|
@@ -5,7 +5,7 @@ import type { ReasoningOrigin, ToolCallRequest } from '../turn-events.js';
|
|
|
5
5
|
import type { DecisionRequest, DecisionResult, EmbeddingInput, EmbeddingResult, EmbeddingTask, InteractionPart, ModelRequest, TurnContext, TurnEvent, TurnHistoryMessage, TurnResponse, TurnStop } from '../types.js';
|
|
6
6
|
import type { ProviderLimits } from './limits.js';
|
|
7
7
|
/** The kinds of profile a protocol can serve, each at its own endpoint: every type but `host`. */
|
|
8
|
-
declare const MODEL_PROFILE_TYPES: readonly ["text", "image", "speech", "live", "decision", "embedding"];
|
|
8
|
+
declare const MODEL_PROFILE_TYPES: readonly ["text", "image", "speech", "transcription", "live", "decision", "embedding"];
|
|
9
9
|
export type ModelProfileType = (typeof MODEL_PROFILE_TYPES)[number];
|
|
10
10
|
/** The turn events a protocol yields as they are. */
|
|
11
11
|
export type ProtocolContentEvent = Extract<TurnEvent, {
|
|
@@ -17,7 +17,10 @@ function mediaKindForMime(mime) {
|
|
|
17
17
|
return MEDIA_INPUT_KINDS[mimeEssence(mime)];
|
|
18
18
|
}
|
|
19
19
|
function profileInputs(profile) {
|
|
20
|
-
return profile.type === 'text' ||
|
|
20
|
+
return profile.type === 'text' ||
|
|
21
|
+
profile.type === 'image' ||
|
|
22
|
+
profile.type === 'transcription' ||
|
|
23
|
+
profile.type === 'live'
|
|
21
24
|
? profile.inputs
|
|
22
25
|
: undefined;
|
|
23
26
|
}
|
|
@@ -2,6 +2,8 @@ import type { ImageResponseFormat, InteractionPart, Profile, ProfileSpeechSpec,
|
|
|
2
2
|
/** Typed profiles already make mixed wire formats unrepresentable; this is a safety net. */
|
|
3
3
|
declare function assertOutputMode(profile: Profile, structuredId: string | null): void;
|
|
4
4
|
declare function assertSpeechRole(profile: Profile, req: TurnRequest): void;
|
|
5
|
+
/** A transcription turn has one job: a clip goes in. No system prompt reaches a model that follows none. */
|
|
6
|
+
declare function assertTranscriptionRole(profile: Profile, req: TurnRequest): void;
|
|
5
7
|
/** The profile's speech settings with this turn's laid over them. */
|
|
6
8
|
declare function resolveSpeech(profile: Profile, req: TurnRequest): ProfileSpeechSpec | undefined;
|
|
7
9
|
declare function resolveImageFormat(profile: Profile): ImageResponseFormat | null;
|
|
@@ -9,4 +11,4 @@ declare function resolveInputParts(profile: Profile, req: TurnRequest): Interact
|
|
|
9
11
|
declare function assertTurnSlots(profile: Profile, req: TurnRequest): void;
|
|
10
12
|
/** Refuses context from a sender the profile's `inputs.context` does not list, and a package over its `maxChars`. */
|
|
11
13
|
declare function assertTurnContext(profile: Profile, req: TurnRequest): void;
|
|
12
|
-
export { assertOutputMode, assertSpeechRole, assertTurnContext, assertTurnSlots, resolveImageFormat, resolveInputParts, resolveSpeech, };
|
|
14
|
+
export { assertOutputMode, assertSpeechRole, assertTranscriptionRole, assertTurnContext, assertTurnSlots, resolveImageFormat, resolveInputParts, resolveSpeech, };
|
|
@@ -41,6 +41,17 @@ function assertSpeechRole(profile, req) {
|
|
|
41
41
|
throw new TheoremError('config', `Profile ${profile.id} (speech) takes no system prompt — the input text is the transcript`);
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
+
/** A transcription turn has one job: a clip goes in. No system prompt reaches a model that follows none. */
|
|
45
|
+
function assertTranscriptionRole(profile, req) {
|
|
46
|
+
if (profile.type !== 'transcription')
|
|
47
|
+
return;
|
|
48
|
+
if (req.system) {
|
|
49
|
+
throw new TheoremError('config', `Profile ${profile.id} (transcription) takes no system prompt — the input is the clip`);
|
|
50
|
+
}
|
|
51
|
+
if (!req.input?.voice?.length) {
|
|
52
|
+
throw new TheoremError('request', `Profile ${profile.id} (transcription) requires a voice clip`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
44
55
|
/** The profile's speech settings with this turn's laid over them. */
|
|
45
56
|
function resolveSpeech(profile, req) {
|
|
46
57
|
return profile.type === 'speech'
|
|
@@ -178,4 +189,4 @@ function assertTurnContext(profile, req) {
|
|
|
178
189
|
}
|
|
179
190
|
}
|
|
180
191
|
}
|
|
181
|
-
export { assertOutputMode, assertSpeechRole, assertTurnContext, assertTurnSlots, resolveImageFormat, resolveInputParts, resolveSpeech, };
|
|
192
|
+
export { assertOutputMode, assertSpeechRole, assertTranscriptionRole, assertTurnContext, assertTurnSlots, resolveImageFormat, resolveInputParts, resolveSpeech, };
|
|
@@ -3,7 +3,7 @@ import { type DecisionGuardrailsSpec, type HostGuardrailsSpec, type ProfileGuard
|
|
|
3
3
|
import type { ProfileObservabilitySpec } from '../../observability/types.js';
|
|
4
4
|
import type { ProviderRegistry } from '../protocols/provider.js';
|
|
5
5
|
import type { ToolRegistry } from '../tools/registry.js';
|
|
6
|
-
import type { DecisionModelBinding, DecisionProfile, EmbeddingProfile, HostProfile, HostProfileToolsSpec, ImageInputsSpec, ImageProfile, LiveProfile, LiveProfileToolsSpec, MediaTurnBehaviourSpec, ModelBinding, ModelId, Profile, ProfileIdentity, ProfileInputsSpec, ProfileOutputsSpec, ProfileToolsSpec, ProfileTurnBehaviourSpec, SpeechProfile, TextProfile } from '../types.js';
|
|
6
|
+
import type { DecisionModelBinding, DecisionProfile, EmbeddingProfile, HostProfile, HostProfileToolsSpec, ImageInputsSpec, ImageProfile, LiveProfile, LiveProfileToolsSpec, MediaTurnBehaviourSpec, ModelBinding, ModelId, Profile, ProfileIdentity, ProfileInputsSpec, ProfileOutputsSpec, ProfileToolsSpec, ProfileTurnBehaviourSpec, SpeechProfile, TextProfile, TranscriptionInputsSpec, TranscriptionProfile } from '../types.js';
|
|
7
7
|
import type { SchemaRegistry } from './schemas.js';
|
|
8
8
|
/** Not shared by host profiles, which invoke tools without a model turn. */
|
|
9
9
|
export type ProfileDefinitionBase = {
|
|
@@ -47,6 +47,14 @@ export type SpeechProfileDefinition = Omit<ProfileDefinitionBase, 'identity'> &
|
|
|
47
47
|
speech: NonNullable<SpeechProfile['speech']>;
|
|
48
48
|
turnBehaviour?: MediaTurnBehaviourSpec;
|
|
49
49
|
};
|
|
50
|
+
/** What a host writes to define a transcription profile. */
|
|
51
|
+
export type TranscriptionProfileDefinition = Omit<ProfileDefinitionBase, 'identity' | 'outputs' | 'maxSteps'> & {
|
|
52
|
+
type: 'transcription';
|
|
53
|
+
identity: TranscriptionProfile['identity'];
|
|
54
|
+
inputs: TranscriptionInputsSpec & {
|
|
55
|
+
text?: false;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
50
58
|
/** What a host writes to define a live profile. */
|
|
51
59
|
export type LiveProfileDefinition = ProfileDefinitionBase & {
|
|
52
60
|
type: 'live';
|
|
@@ -80,13 +88,15 @@ export type HostProfileDefinition = {
|
|
|
80
88
|
labels?: LabelOverrides;
|
|
81
89
|
};
|
|
82
90
|
/** Any profile definition, discriminated by `type`. */
|
|
83
|
-
export type ProfileDefinition = TextProfileDefinition | ImageProfileDefinition | SpeechProfileDefinition | LiveProfileDefinition | DecisionProfileDefinition | EmbeddingProfileDefinition | HostProfileDefinition;
|
|
91
|
+
export type ProfileDefinition = TextProfileDefinition | ImageProfileDefinition | SpeechProfileDefinition | LiveProfileDefinition | DecisionProfileDefinition | TranscriptionProfileDefinition | EmbeddingProfileDefinition | HostProfileDefinition;
|
|
84
92
|
/** Validate a definition and return the profile; throws on a malformed one. */
|
|
85
93
|
declare function defineProfile(input: TextProfileDefinition): TextProfile;
|
|
86
94
|
/** Validate an image definition and return the profile. */
|
|
87
95
|
declare function defineProfile(input: ImageProfileDefinition): ImageProfile;
|
|
88
96
|
/** Validate a speech definition and return the profile. */
|
|
89
97
|
declare function defineProfile(input: SpeechProfileDefinition): SpeechProfile;
|
|
98
|
+
/** Validate a transcription definition and return the profile. */
|
|
99
|
+
declare function defineProfile(input: TranscriptionProfileDefinition): TranscriptionProfile;
|
|
90
100
|
/** Validate a live definition and return the profile. */
|
|
91
101
|
declare function defineProfile(input: LiveProfileDefinition): LiveProfile;
|
|
92
102
|
/** Validate a decision definition and return the profile. */
|
|
@@ -11,7 +11,7 @@ import { outOfScopeFields, profileKeysOf, profileTypesForField } from '../profil
|
|
|
11
11
|
import { checkBinding, decisionModelBindingSchema, modelBindingSchema, } from '../protocols/binding.js';
|
|
12
12
|
import { CONTEXT_SENDERS, IMAGE_ATTACHMENT_ACCEPT_MIMES, PROFILE_FIELDS, PROFILE_HANDLE_MAX_CHARS, PROFILE_ID_MAX_CHARS, PROFILE_TYPES, THINKING_LEVELS, } from '../schema.js';
|
|
13
13
|
import { isContinueStopKind } from '../stop.js';
|
|
14
|
-
import {
|
|
14
|
+
import { assertSystemLines, systemLinesProblem } from '../system-lines.js';
|
|
15
15
|
import { profileToolAllow, profileToolsSpec } from '../tools/resolve.js';
|
|
16
16
|
import { isTurnMediaRef } from './attachments.js';
|
|
17
17
|
import { mediaKindForMime, mimeAllowed, profileInputs } from './catalog.js';
|
|
@@ -40,6 +40,28 @@ function defineEmbeddingProfile(input) {
|
|
|
40
40
|
labels: input.labels,
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
|
+
function defineTranscriptionProfile(input) {
|
|
44
|
+
assertModelsNonEmpty(input.id, input.models);
|
|
45
|
+
assertGuardrails(input.id, input.guardrails);
|
|
46
|
+
assertObservability(input.id, input.observability);
|
|
47
|
+
for (const [modelId, binding] of Object.entries(input.models))
|
|
48
|
+
assertModelBinding(input.id, modelId, binding);
|
|
49
|
+
if ('text' in input.inputs && input.inputs.text !== false) {
|
|
50
|
+
throw new TheoremError('config', `Profile ${input.id}: a transcription takes a voice clip, so inputs.text must be false`);
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
type: 'transcription',
|
|
54
|
+
id: input.id,
|
|
55
|
+
identity: { handle: input.identity.handle },
|
|
56
|
+
...profileModelFields(input),
|
|
57
|
+
providerContinuation: undefined,
|
|
58
|
+
maxSteps: undefined,
|
|
59
|
+
inputs: { ...input.inputs, text: false },
|
|
60
|
+
guardrails: input.guardrails,
|
|
61
|
+
observability: input.observability,
|
|
62
|
+
labels: input.labels,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
43
65
|
function assertBindingData(profileId, modelId, binding, schema) {
|
|
44
66
|
const parsed = schema.safeParse(binding);
|
|
45
67
|
if (!parsed.success)
|
|
@@ -340,14 +362,19 @@ function assertIdentitySystem(input) {
|
|
|
340
362
|
if (input.type === 'host' ||
|
|
341
363
|
input.type === 'decision' ||
|
|
342
364
|
input.type === 'speech' ||
|
|
365
|
+
input.type === 'transcription' ||
|
|
343
366
|
input.type === 'embedding')
|
|
344
367
|
return;
|
|
345
|
-
const {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
assertSystemPrompt(prompt, `Profile ${input.id} identity.systemByRole.${role}`);
|
|
368
|
+
const { conditions, system } = input.identity;
|
|
369
|
+
const slots = {};
|
|
370
|
+
for (const [name, decl] of Object.entries(normalizeProfileInputsSlots(input.inputs)?.slots ?? {})) {
|
|
371
|
+
slots[name] = slotValues(decl);
|
|
350
372
|
}
|
|
373
|
+
const prompt = system ?? '';
|
|
374
|
+
assertSystemLines(prompt, `Profile ${input.id} identity.system`);
|
|
375
|
+
const problem = systemLinesProblem(prompt, conditions, slots);
|
|
376
|
+
if (problem)
|
|
377
|
+
throw new TheoremError('config', `Profile ${input.id} identity.system: ${problem}`); // labels-exempt: developer contract error
|
|
351
378
|
}
|
|
352
379
|
/** Validate any definition and return the profile. */
|
|
353
380
|
function defineProfile(input) {
|
|
@@ -377,6 +404,9 @@ function defineProfile(input) {
|
|
|
377
404
|
if (input.type === 'embedding') {
|
|
378
405
|
return defineEmbeddingProfile(input);
|
|
379
406
|
}
|
|
407
|
+
if (input.type === 'transcription') {
|
|
408
|
+
return defineTranscriptionProfile(input);
|
|
409
|
+
}
|
|
380
410
|
assertModelsNonEmpty(input.id, input.models);
|
|
381
411
|
assertTurnBehaviour(input.id, input);
|
|
382
412
|
assertGuardrails(input.id, input.guardrails);
|
|
@@ -390,8 +420,8 @@ function defineProfile(input) {
|
|
|
390
420
|
? { handle: input.identity.handle }
|
|
391
421
|
: {
|
|
392
422
|
handle: input.identity.handle,
|
|
423
|
+
conditions: input.identity.conditions,
|
|
393
424
|
system: input.identity.system,
|
|
394
|
-
systemByRole: input.identity.systemByRole,
|
|
395
425
|
};
|
|
396
426
|
const guardrails = input.guardrails;
|
|
397
427
|
const observability = input.observability;
|
|
@@ -11,8 +11,8 @@ import { profileTurnResumption } from '../stop.js';
|
|
|
11
11
|
import { projectTools } from '../tools/project.js';
|
|
12
12
|
import { resolveTurnTools } from '../tools/resolve.js';
|
|
13
13
|
import { profileInputs, requireModelBinding } from './catalog.js';
|
|
14
|
-
import { assertOutputMode, assertSpeechRole, assertTurnContext, assertTurnSlots, resolveImageFormat, resolveInputParts, resolveSpeech, } from './ingress.js';
|
|
15
|
-
import {
|
|
14
|
+
import { assertOutputMode, assertSpeechRole, assertTranscriptionRole, assertTurnContext, assertTurnSlots, resolveImageFormat, resolveInputParts, resolveSpeech, } from './ingress.js';
|
|
15
|
+
import { resolveTurnSystem } from './system-prompt.js';
|
|
16
16
|
function isModelProfile(profile) {
|
|
17
17
|
return profile.type !== 'host' && profile.type !== 'decision' && profile.type !== 'embedding';
|
|
18
18
|
}
|
|
@@ -136,11 +136,12 @@ function resolveLiveSpec(live, guardrails) {
|
|
|
136
136
|
}
|
|
137
137
|
/**
|
|
138
138
|
* A canary for the turn while `canary_leak` reads somewhere, else none. Speech
|
|
139
|
-
*
|
|
139
|
+
* and transcription have no system prompt to plant one in.
|
|
140
140
|
*/
|
|
141
141
|
function plantedCanary(profile) {
|
|
142
142
|
const { detect } = resolveGuardrailPolicy(profile.guardrails);
|
|
143
|
-
|
|
143
|
+
const noPrompt = profile.type === 'speech' || profile.type === 'transcription';
|
|
144
|
+
return !noPrompt && detects(detect, 'canary_leak') ? mintCanary() : '';
|
|
144
145
|
}
|
|
145
146
|
/**
|
|
146
147
|
* The request's `builtInArgs`. Args must name a tool the chosen model lists; the protocol that
|
|
@@ -177,10 +178,12 @@ function resolveTurnInRegistry(registry, req, model) {
|
|
|
177
178
|
throw new TheoremError('config', `Profile ${profile.id}: a structured turn answers through '${ANSWER_TOOL}', so no tool of its own may take that name`);
|
|
178
179
|
}
|
|
179
180
|
assertSpeechRole(profile, safe);
|
|
181
|
+
assertTranscriptionRole(profile, safe);
|
|
180
182
|
const builtInArgs = resolveBuiltInArgs(profile, picked, binding, safe.builtInArgs);
|
|
181
183
|
const transport = resolveTransport(profile, binding);
|
|
182
184
|
const provider = registry.providers.get(binding.provider);
|
|
183
185
|
const operationName = provider && operationNameOf(provider, binding, profile.type);
|
|
186
|
+
const system = resolveTurnSystem(profile, safe);
|
|
184
187
|
return {
|
|
185
188
|
profile,
|
|
186
189
|
generation: {
|
|
@@ -210,7 +213,8 @@ function resolveTurnInRegistry(registry, req, model) {
|
|
|
210
213
|
live: profile.type === 'live' ? resolveLiveSpec(profile.live, profile.guardrails) : undefined,
|
|
211
214
|
input: resolveInputParts(profile, safe),
|
|
212
215
|
canary: plantedCanary(profile),
|
|
213
|
-
resolvedSystem:
|
|
216
|
+
resolvedSystem: system.pieces,
|
|
217
|
+
systemLines: system.lines,
|
|
214
218
|
host: safe.host,
|
|
215
219
|
},
|
|
216
220
|
};
|
|
@@ -4,5 +4,10 @@ import type { ModelProfile, SystemPiece, TurnRequest } from '../types.js';
|
|
|
4
4
|
* keeps its own marks: a `{ private }` part in `req.system` leaves the
|
|
5
5
|
* profile's prompt as private as it was written.
|
|
6
6
|
*/
|
|
7
|
+
declare function resolveTurnSystem(profile: ModelProfile, req: TurnRequest): {
|
|
8
|
+
pieces: SystemPiece[];
|
|
9
|
+
lines: number[];
|
|
10
|
+
};
|
|
11
|
+
/** The whole prompt a turn sends, for what reads it outside a turn. */
|
|
7
12
|
declare function resolveTurnSystemPrompt(profile: ModelProfile, req: TurnRequest): SystemPiece[];
|
|
8
|
-
export { resolveTurnSystemPrompt };
|
|
13
|
+
export { resolveTurnSystem, resolveTurnSystemPrompt };
|
|
@@ -1,32 +1,39 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { pickSystemLines, turnFacts } from '../system-lines.js';
|
|
2
|
+
import { joinSystemPieces, systemPieces } from '../system-parts.js';
|
|
2
3
|
import { fillSlots } from './slot-fill.js';
|
|
3
|
-
import { pickSystemRole } from './system-role.js';
|
|
4
4
|
/**
|
|
5
5
|
* `identity.system` is trusted author-time copy and crosses no boundary: no detector reads it.
|
|
6
6
|
* A `{slot}` in it becomes the value the request chose, which is one the profile lists.
|
|
7
7
|
* `req.system` is `assembled` per turn and is read at the `system` boundary.
|
|
8
8
|
*/
|
|
9
|
-
function systemFromProfile(profile,
|
|
10
|
-
if (profile.type === 'speech') {
|
|
9
|
+
function systemFromProfile(profile, slots, req) {
|
|
10
|
+
if (profile.type === 'speech' || profile.type === 'transcription') {
|
|
11
11
|
return [];
|
|
12
12
|
}
|
|
13
|
-
const
|
|
14
|
-
const prompt = systemByRole?.[role] || system || '';
|
|
13
|
+
const prompt = profile.identity.system;
|
|
15
14
|
if (!prompt) {
|
|
16
15
|
return [];
|
|
17
16
|
}
|
|
18
|
-
|
|
17
|
+
const facts = turnFacts(profile.id, profile.identity.conditions, req, slots);
|
|
18
|
+
return pickSystemLines(prompt, facts, (text) => fillSlots(profile, text, slots, 'identity.system'));
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* Synchronous: snapshotted in `resolveTurn` before any async work. Each source
|
|
22
22
|
* keeps its own marks: a `{ private }` part in `req.system` leaves the
|
|
23
23
|
* profile's prompt as private as it was written.
|
|
24
24
|
*/
|
|
25
|
+
function resolveTurnSystem(profile, req) {
|
|
26
|
+
const kept = systemFromProfile(profile, req.input?.slots, req);
|
|
27
|
+
return {
|
|
28
|
+
pieces: joinSystemPieces([
|
|
29
|
+
...kept.map(({ pieces }) => pieces),
|
|
30
|
+
req.system === undefined ? [] : systemPieces(req.system),
|
|
31
|
+
]),
|
|
32
|
+
lines: kept.map(({ line }) => line),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/** The whole prompt a turn sends, for what reads it outside a turn. */
|
|
25
36
|
function resolveTurnSystemPrompt(profile, req) {
|
|
26
|
-
|
|
27
|
-
return joinSystemPieces([
|
|
28
|
-
systemFromProfile(profile, role, req.input?.slots),
|
|
29
|
-
req.system === undefined ? [] : systemPieces(req.system),
|
|
30
|
-
]);
|
|
37
|
+
return resolveTurnSystem(profile, req).pieces;
|
|
31
38
|
}
|
|
32
|
-
export { resolveTurnSystemPrompt };
|
|
39
|
+
export { resolveTurnSystem, resolveTurnSystemPrompt };
|
|
@@ -8,7 +8,7 @@ import "../../_dnt.polyfills.js";
|
|
|
8
8
|
import { BLOCKED_REPLY_ON_BLOCK, type BlockedReplyOnBlock } from '../guardrails/types.js';
|
|
9
9
|
export { BLOCKED_REPLY_ON_BLOCK, type BlockedReplyOnBlock };
|
|
10
10
|
/** The kinds of profile: each fixes which fields and models a profile may use. */
|
|
11
|
-
export declare const PROFILE_TYPES: readonly ["text", "image", "speech", "live", "decision", "embedding", "host"];
|
|
11
|
+
export declare const PROFILE_TYPES: readonly ["text", "image", "speech", "transcription", "live", "decision", "embedding", "host"];
|
|
12
12
|
/** One of {@linkcode PROFILE_TYPES}. */
|
|
13
13
|
export type ProfileType = (typeof PROFILE_TYPES)[number];
|
|
14
14
|
/** Reasoning effort levels, lowest to highest; a model accepts only the levels its catalog row lists. */
|
package/esm/src/kernel/schema.js
CHANGED
|
@@ -17,6 +17,7 @@ export const PROFILE_TYPES = [
|
|
|
17
17
|
'text',
|
|
18
18
|
'image',
|
|
19
19
|
'speech',
|
|
20
|
+
'transcription',
|
|
20
21
|
'live',
|
|
21
22
|
'decision',
|
|
22
23
|
'embedding',
|
|
@@ -276,7 +277,6 @@ function field(type, doc, options, optionDescriptionsOrNote, optionNote) {
|
|
|
276
277
|
export const DYNAMIC_FIELD_PARENTS = new Set([
|
|
277
278
|
'models',
|
|
278
279
|
'models.*.efforts',
|
|
279
|
-
'identity.systemByRole',
|
|
280
280
|
'labels',
|
|
281
281
|
'inputs.slots',
|
|
282
282
|
'inputs.limitsByMime',
|
|
@@ -494,20 +494,20 @@ function withScopeAndPresence(fields) {
|
|
|
494
494
|
*/
|
|
495
495
|
export const PROFILE_FIELDS = withScopeAndPresence({
|
|
496
496
|
'profile.id': field('string', 'The name this profile is registered and looked up by, at most 64 characters; registering the same id again replaces it.'),
|
|
497
|
-
'profile.type': field("'text' | 'image' | 'speech' | 'live' | 'decision' | 'embedding' | 'host'", 'What kind of agent this is, and so what each call gives back: text, image, speech, live, decision, embedding, or host.', PROFILE_TYPES, {
|
|
497
|
+
'profile.type': field("'text' | 'image' | 'speech' | 'transcription' | 'live' | 'decision' | 'embedding' | 'host'", 'What kind of agent this is, and so what each call gives back: text, image, speech, transcription, live, decision, embedding, or host.', PROFILE_TYPES, {
|
|
498
498
|
text: 'A chat or task agent. Each turn the model answers in text, or in JSON when outputs ask for a structured reply, and can call tools on the way.',
|
|
499
499
|
image: 'Makes pictures from a prompt, in the shape, size, and format the image block sets.',
|
|
500
500
|
speech: 'Gives your app a voice. Each turn reads text aloud in the voice the speech block names.',
|
|
501
|
+
transcription: 'Turns a voice clip into text. Each turn takes one clip and gives back what was said.',
|
|
501
502
|
live: 'For talking in real time. One continuous voice and video session, rather than separate turns.',
|
|
502
503
|
decision: 'For when your app needs a judgement, not a reply. It answers questions about a JSON state, each with a choice, a score, or a number.',
|
|
503
504
|
embedding: 'For when your app needs vectors from text or provider-supported media.',
|
|
504
505
|
host: 'A governed passthrough to your tool registry, with no model. It calls MCP, HTTP, and in-app function tools under the same permissions and traces as any agent, guarded by detect and network.',
|
|
505
506
|
}),
|
|
506
|
-
identity: field('{ handle,
|
|
507
|
-
'identity.handle': field('string', 'The name hosts and users see for this agent, at most 32 characters; the model never sees it.
|
|
508
|
-
'identity.
|
|
509
|
-
'identity.
|
|
510
|
-
'identity.systemByRole.*': field('string | Array<string | { private: string }>', 'The instruction that replaces identity.system when a turn names this role.'),
|
|
507
|
+
identity: field('{ handle, conditions?, system? }', "The agent's display name and the system instruction it is given."),
|
|
508
|
+
'identity.handle': field('string', 'The name hosts and users see for this agent, at most 32 characters; the model never sees it.'),
|
|
509
|
+
'identity.conditions': field('Record<string, string[]>', 'The facts every turn states, by name, with the values each can take. A line of identity.system reads them as "when plan is free: …". A condition named path reads the turn\'s path.'),
|
|
510
|
+
'identity.system': field('string | Array<string | Array<string | { private: string }>>', 'The instruction the model gets, as one string or a list of lines; some providers send it for an image profile only with includeText on. A line that opens "when plan is free: …" goes only on turns where that fits, and every line that fits is sent, a blank line apart. A line can be a list of parts; mark what must not leak as { private: text }; only that is guarded. With none, the whole prompt is.'),
|
|
511
511
|
models: field('Record<ModelId, ModelBinding | DecisionModelBinding>', 'The trained AI systems that turn input into results. Each entry binds a local name to an upstream model and its call settings.'),
|
|
512
512
|
'models.*': field('ModelBinding | DecisionModelBinding', 'One model: how to reach it and the settings sent with it.'),
|
|
513
513
|
'models.*.protocol': field('string', 'The API shape this model is spoken to in.'),
|
|
@@ -578,7 +578,7 @@ export const PROFILE_FIELDS = withScopeAndPresence({
|
|
|
578
578
|
'inputs.text': field('boolean', 'Whether a turn may send text.'),
|
|
579
579
|
'inputs.attachments': field('{ accept: string[] }', 'Lets turns send files.'),
|
|
580
580
|
'inputs.attachments.accept': field('string[]', 'The file types a turn may send, where type/* matches a whole family; image profiles take only images, video, and PDF.', ATTACHMENT_ACCEPT_MIMES, "Types the kernel knows; a listed type it doesn't know is refused when a turn sends it."),
|
|
581
|
-
'inputs.voice': field('{ accept: string[] }', 'Lets turns send voice clips.'),
|
|
581
|
+
'inputs.voice': field('{ accept: string[] }', 'Lets turns send voice clips. A transcription profile must set it.'),
|
|
582
582
|
'inputs.voice.accept': field('string[]', 'The audio types a voice clip may be; audio/* matches them all.', VOICE_ACCEPT_MIMES, 'Audio types the kernel knows.'),
|
|
583
583
|
'inputs.maxFiles': field('number', 'The most files and voice clips one turn or embedding request may send, counted together.'),
|
|
584
584
|
'inputs.maxBytes': field('number', 'The largest file or clip, in bytes, a turn or embedding request may send inline.'),
|
|
@@ -887,6 +887,10 @@ export const EXTRA_FIELDS = {
|
|
|
887
887
|
session_consent: 'Asks once; the approval lasts as long as the host keeps passing it back.',
|
|
888
888
|
always_confirm: 'Asks every time.',
|
|
889
889
|
}),
|
|
890
|
+
'registerTool.after': {
|
|
891
|
+
...field('boolean', 'Gives the model an after field on this tool: the tools called in the same step that must settle before this call starts. The kernel removes the field before the tool, the stages or a gate read the input. A name with no other call in the step fails the call wait_unknown.'),
|
|
892
|
+
unset: 'The model sets no order',
|
|
893
|
+
},
|
|
890
894
|
'registerTool.category': field('string', 'A label for grouping tools; nothing reads it yet.'),
|
|
891
895
|
'registerTool.labels': field('ToolLabels', "Transcript text for a call. {path} reads a value from the call. {results.0.name} reads a list item. {path|text} shows the text when the value is unusable. {count hit|hits} shows a number with the word for one or for any other number: '1 hit', '3 hits'. With no fallback, the label is dropped. A label is one line, or a list read top to bottom: the first line that fits is shown. A line fits when each {path} has a value and its condition holds, as in 'when status is archived: archiving {title}'. Neighbouring lines that open with '+ ' show together, joined in words. The last line of a list must always fit."),
|
|
892
896
|
'registerTool.labels.activity': {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ProfileConditions, ProfileSystem, SystemPiece, TurnRequest } from './types.js';
|
|
2
|
+
/** What is wrong with a prompt's conditions and lines, or undefined. */
|
|
3
|
+
export declare function systemLinesProblem(prompt: ProfileSystem, conditions: ProfileConditions | undefined, slots: Record<string, readonly string[]>): string | undefined;
|
|
4
|
+
/** The facts a turn's `when` reads, once the turn has stated every condition with a listed value. */
|
|
5
|
+
export declare function turnFacts(id: string, conditions: ProfileConditions | undefined, req: Pick<TurnRequest, 'path' | 'conditions'>, slots: Record<string, string> | undefined): Record<string, string>;
|
|
6
|
+
/** A line that fit a turn: its number in the prompt as written, from 1, and its pieces. */
|
|
7
|
+
export type KeptSystemLine = {
|
|
8
|
+
line: number;
|
|
9
|
+
pieces: SystemPiece[];
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Every line that fits. Whether plain text is shareable is settled on the prompt as written, so a
|
|
13
|
+
* line dropped on this turn never changes the marks of one that stayed.
|
|
14
|
+
*/
|
|
15
|
+
export declare function pickSystemLines(prompt: ProfileSystem, facts: Record<string, string>, fill: (text: string) => string): KeptSystemLine[];
|
|
16
|
+
/** `where` names the prompt in the error. A bare `{ private }` must sit inside a line's own list. */
|
|
17
|
+
export declare function assertSystemLines(prompt: unknown, where: string): asserts prompt is ProfileSystem;
|
|
18
|
+
/** The first tool in `tools` with a path `conditions.path` does not list, as a sentence. */
|
|
19
|
+
export declare function toolPathProblem(conditions: ProfileConditions | undefined, tools: readonly {
|
|
20
|
+
name: string;
|
|
21
|
+
paths?: readonly string[];
|
|
22
|
+
}[]): string | undefined;
|