@theoremjs/agents 0.3.4-next.863.gb601f58 → 0.3.4-next.871.gea9bbcc
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/esm/src/guardrails/detectors.d.ts +91 -21
- package/esm/src/guardrails/host-patterns.d.ts +15 -2
- package/esm/src/guardrails/labels.d.ts +11 -3
- package/esm/src/guardrails/labels.js +42 -23
- package/esm/src/guardrails/quota.d.ts +9 -3
- package/esm/src/guardrails/quota.js +9 -3
- package/esm/src/guardrails/theorem-error.d.ts +5 -1
- package/esm/src/guardrails/theorem-error.js +8 -4
- package/esm/src/guardrails/types.d.ts +66 -18
- package/esm/src/guardrails/types.js +22 -3
- package/esm/src/kernel/api-catalog.d.ts +26 -75
- package/esm/src/kernel/api-catalog.js +37 -119
- package/esm/src/kernel/checkpoint.d.ts +5 -1
- package/esm/src/kernel/default-scope.d.ts +52 -10
- package/esm/src/kernel/default-scope.js +52 -10
- package/esm/src/kernel/engine/runner/gates.js +66 -22
- package/esm/src/kernel/engine/runner/state.d.ts +5 -2
- package/esm/src/kernel/engine/runner/steps.js +15 -15
- package/esm/src/kernel/engine/runner/stream.d.ts +5 -0
- package/esm/src/kernel/engine/runner/stream.js +12 -1
- package/esm/src/kernel/field-docs.d.ts +13 -0
- package/esm/src/kernel/field-docs.js +613 -0
- package/esm/src/kernel/protocols/binding.d.ts +56 -0
- package/esm/src/kernel/protocols/limits.d.ts +9 -0
- package/esm/src/kernel/protocols/provider.d.ts +5 -1
- package/esm/src/kernel/protocols/provider.js +5 -1
- package/esm/src/kernel/registry/profiles.d.ts +154 -5
- package/esm/src/kernel/schema.d.ts +5 -7
- package/esm/src/kernel/schema.js +511 -470
- package/esm/src/kernel/stop.d.ts +41 -17
- package/esm/src/kernel/stop.js +9 -1
- package/esm/src/kernel/tools/background.d.ts +4 -0
- package/esm/src/kernel/tools/types.d.ts +331 -43
- package/esm/src/kernel/turn-events.d.ts +4 -3
- package/esm/src/kernel/types.d.ts +482 -89
- package/esm/src/observability/destinations.d.ts +5 -1
- package/esm/src/observability/destinations.js +5 -1
- package/esm/src/observability/trace-catalog.js +62 -102
- package/esm/src/observability/types.d.ts +93 -19
- package/esm/src/providers/shared/carried-tool-files.js +9 -8
- package/package.json +1 -1
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { defaultKernelScope as scope } from './scope.js';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Stores a tool under its name, so that a profile can list it in tools.allow.
|
|
4
|
+
*
|
|
5
|
+
* @remarks Register or replace a tool in the default scope.
|
|
6
|
+
*/
|
|
3
7
|
function registerTool(def) {
|
|
4
8
|
return scope.tools.register(def);
|
|
5
9
|
}
|
|
@@ -27,7 +31,11 @@ function listTools() {
|
|
|
27
31
|
function resetTools() {
|
|
28
32
|
scope.tools.reset();
|
|
29
33
|
}
|
|
30
|
-
/**
|
|
34
|
+
/**
|
|
35
|
+
* Stores a profile under its id, so that a request can name it.
|
|
36
|
+
*
|
|
37
|
+
* @remarks Define, validate, and register a profile in the default scope.
|
|
38
|
+
*/
|
|
31
39
|
function registerProfile(profile) {
|
|
32
40
|
scope.profiles.register(profile);
|
|
33
41
|
}
|
|
@@ -51,7 +59,11 @@ function listProfiles() {
|
|
|
51
59
|
function clearProfiles() {
|
|
52
60
|
scope.profiles.clear();
|
|
53
61
|
}
|
|
54
|
-
/**
|
|
62
|
+
/**
|
|
63
|
+
* Stores a JSON Schema under an id, so that a profile can name it in outputs.structured.
|
|
64
|
+
*
|
|
65
|
+
* @remarks Register a structured-output schema in the default scope under `id`.
|
|
66
|
+
*/
|
|
55
67
|
function registerStructured(id, spec) {
|
|
56
68
|
scope.schemas.register(id, spec);
|
|
57
69
|
}
|
|
@@ -59,19 +71,36 @@ function registerStructured(id, spec) {
|
|
|
59
71
|
function getStructured(id) {
|
|
60
72
|
return scope.schemas.get(id);
|
|
61
73
|
}
|
|
62
|
-
/**
|
|
74
|
+
/**
|
|
75
|
+
* Runs one turn of a text, image, or speech profile and yields its events.
|
|
76
|
+
*
|
|
77
|
+
* @remarks Run one turn of a profile in the default scope, streaming its events.
|
|
78
|
+
*/
|
|
63
79
|
function runTurn(req, options = {}, sinkOverride) {
|
|
64
80
|
return scope.runTurn(req, options, sinkOverride);
|
|
65
81
|
}
|
|
66
|
-
/**
|
|
82
|
+
/**
|
|
83
|
+
* Runs a realtime voice or video session of a live profile.
|
|
84
|
+
*
|
|
85
|
+
* @remarks Open a live session for a live profile in the default scope.
|
|
86
|
+
*/
|
|
67
87
|
function runSession(req, options, sinkOverride) {
|
|
68
88
|
return scope.runSession(req, options, sinkOverride);
|
|
69
89
|
}
|
|
70
|
-
/**
|
|
90
|
+
/**
|
|
91
|
+
* Shortens a conversation history with the compaction the profile sets.
|
|
92
|
+
*
|
|
93
|
+
* @remarks Compact a conversation history with the model, or `undefined` when there is nothing to
|
|
94
|
+
* compact.
|
|
95
|
+
*/
|
|
71
96
|
function compactHistory(req, options = {}, sinkOverride) {
|
|
72
97
|
return scope.compactHistory(req, options, sinkOverride);
|
|
73
98
|
}
|
|
74
|
-
/**
|
|
99
|
+
/**
|
|
100
|
+
* Runs one registered tool through a profile, with no model.
|
|
101
|
+
*
|
|
102
|
+
* @remarks Run a held tool call in the default scope, streaming the events of the turn it resumes.
|
|
103
|
+
*/
|
|
75
104
|
function invokeTool(request, sinkOverride) {
|
|
76
105
|
return scope.invokeTool(request, sinkOverride);
|
|
77
106
|
}
|
|
@@ -79,7 +108,12 @@ function invokeTool(request, sinkOverride) {
|
|
|
79
108
|
function invokeToolStep(request, sinkOverride) {
|
|
80
109
|
return scope.invokeToolStep(request, sinkOverride);
|
|
81
110
|
}
|
|
82
|
-
/**
|
|
111
|
+
/**
|
|
112
|
+
* Runs one registered tool through a profile, with no model, and returns how the call settled.
|
|
113
|
+
*
|
|
114
|
+
* @remarks Run one tool call in the default scope to its end: how it settled, with every event it
|
|
115
|
+
* emitted.
|
|
116
|
+
*/
|
|
83
117
|
function runTool(request, sinkOverride) {
|
|
84
118
|
return scope.runTool(request, sinkOverride);
|
|
85
119
|
}
|
|
@@ -96,7 +130,11 @@ function resolveTurn(req) {
|
|
|
96
130
|
function projectProfile(id) {
|
|
97
131
|
return scope.projectProfile(id);
|
|
98
132
|
}
|
|
99
|
-
/**
|
|
133
|
+
/**
|
|
134
|
+
* Asks a decision profile its questions about your JSON state and returns checked answers.
|
|
135
|
+
*
|
|
136
|
+
* @remarks Answer a decision request with the profile's model in the default scope.
|
|
137
|
+
*/
|
|
100
138
|
function runDecision(request, options) {
|
|
101
139
|
return scope.runDecision(request, options);
|
|
102
140
|
}
|
|
@@ -105,7 +143,11 @@ function runEmbedding(request, options = {}) {
|
|
|
105
143
|
return scope.runEmbedding(request, options);
|
|
106
144
|
}
|
|
107
145
|
export { clearProfiles, compactHistory, getProfile, getStructured, getTool, hasProfile, hasTool, invokeTool, invokeToolStep, listProfiles, listTools, projectProfile, registerProfile, registerProfiles, registerStructured, registerTool, registerTools, requireTool, resetTools, resolveTurn, runDecision, runEmbedding, runSession, runTool, runToolStep, runTurn, };
|
|
108
|
-
/**
|
|
146
|
+
/**
|
|
147
|
+
* Registers a provider instance before profiles reference its ID.
|
|
148
|
+
*
|
|
149
|
+
* @remarks Registers a provider in the default scope, with this project's connection and key slots.
|
|
150
|
+
*/
|
|
109
151
|
export function registerProvider(provider, registration) {
|
|
110
152
|
return scope.providers.register(provider, registration);
|
|
111
153
|
}
|
|
@@ -13,6 +13,7 @@ import { resolveInputParts } from '../../registry/ingress.js';
|
|
|
13
13
|
import { turnFacts } from '../../registry/options.js';
|
|
14
14
|
import { profileTurnOutputs } from '../../registry/profile-outputs.js';
|
|
15
15
|
import { injectWouldExceedMaxSteps } from '../../stages.js';
|
|
16
|
+
import { cutOffRepairs } from '../../stop.js';
|
|
16
17
|
import { findLast } from '../../util/find-last.js';
|
|
17
18
|
import { guardrailCheckAttributes } from '../turn-trace.js';
|
|
18
19
|
import { collectItemFailures, collectValidationFailures, formatValidationFailures, itemSchemaAt, valueAt, withListAt, } from './schema-validation.js';
|
|
@@ -355,18 +356,12 @@ function startItemFix(args) {
|
|
|
355
356
|
function unparsedReply(state, generation, profile) {
|
|
356
357
|
if (!generation.structured)
|
|
357
358
|
return undefined;
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
if (
|
|
359
|
+
if (state.lastStop?.kind === 'length')
|
|
360
|
+
return cutOffReply(state, generation, profile);
|
|
361
|
+
if (answersByTool(generation))
|
|
361
362
|
return undefined;
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
text,
|
|
365
|
-
rejection: labelText('structured.cut_off', {}, profile.labels),
|
|
366
|
-
guidance: labelText('repair.cut_off_guidance', {}, profile.labels),
|
|
367
|
-
};
|
|
368
|
-
}
|
|
369
|
-
if (byTool)
|
|
363
|
+
const text = collectAttemptText(state.attemptEvents);
|
|
364
|
+
if (!text.trim())
|
|
370
365
|
return undefined;
|
|
371
366
|
const error = findLast(state.attemptEvents, (event) => event.type === 'error');
|
|
372
367
|
if (state.lastStop?.kind === 'provider_error' &&
|
|
@@ -376,6 +371,44 @@ function unparsedReply(state, generation, profile) {
|
|
|
376
371
|
}
|
|
377
372
|
return undefined;
|
|
378
373
|
}
|
|
374
|
+
/**
|
|
375
|
+
* The repair of an attempt the output limit cut off: what it wrote before the cut (a reply, a
|
|
376
|
+
* tool call's arguments, or nothing), why it stopped, and how to fit.
|
|
377
|
+
*/
|
|
378
|
+
function cutOffReply(state, generation, profile) {
|
|
379
|
+
if (state.lastStop?.kind !== 'length')
|
|
380
|
+
return undefined;
|
|
381
|
+
const labels = profile.labels;
|
|
382
|
+
const call = state.cutOffCall;
|
|
383
|
+
if (call?.name === ANSWER_TOOL && generation.structured) {
|
|
384
|
+
return {
|
|
385
|
+
text: call.text,
|
|
386
|
+
rejection: labelText('structured.cut_off', {}, labels),
|
|
387
|
+
guidance: labelText('repair.cut_off_guidance', {}, labels),
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
if (call) {
|
|
391
|
+
return {
|
|
392
|
+
text: call.text,
|
|
393
|
+
rejection: labelText('repair.call_cut_off', { tool: call.name }, labels),
|
|
394
|
+
guidance: labelText('repair.call_cut_off_guidance', { tool: call.name }, labels),
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
const text = collectAttemptText(state.attemptEvents);
|
|
398
|
+
if (!text.trim()) {
|
|
399
|
+
return {
|
|
400
|
+
text,
|
|
401
|
+
rejection: labelText('repair.nothing_written', {}, labels),
|
|
402
|
+
guidance: labelText('repair.nothing_written_guidance', {}, labels),
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
const json = generation.structured && !answersByTool(generation);
|
|
406
|
+
return {
|
|
407
|
+
text,
|
|
408
|
+
rejection: labelText(json ? 'structured.cut_off' : 'repair.reply_cut_off', {}, labels),
|
|
409
|
+
guidance: labelText('repair.cut_off_guidance', {}, labels),
|
|
410
|
+
};
|
|
411
|
+
}
|
|
379
412
|
function parsesAsJson(text) {
|
|
380
413
|
try {
|
|
381
414
|
JSON.parse(text);
|
|
@@ -460,25 +493,35 @@ held) {
|
|
|
460
493
|
return 'pass';
|
|
461
494
|
}
|
|
462
495
|
/**
|
|
463
|
-
*
|
|
464
|
-
* budget lasts, else a `bad_response` failure.
|
|
496
|
+
* An attempt the output limit cut off: a repair that sends back what it wrote, with guidance to fit,
|
|
497
|
+
* while the budget lasts, else a `bad_response` failure. It covers a reply, a tool call whose
|
|
498
|
+
* arguments were cut, and a call that wrote nothing before the limit. It runs only when the profile's
|
|
499
|
+
* `turnBehaviour.resumption.autoContinue` names `length`, and it shares that turn's `maxContinues`
|
|
500
|
+
* with the resends of failed calls.
|
|
465
501
|
*
|
|
466
|
-
* why: A cut-off reply holds no answer to check,
|
|
467
|
-
*
|
|
502
|
+
* why: A cut-off reply holds no answer to check, and a cut-off call cannot run; without a repair
|
|
503
|
+
* the turn would end with a partial answer or none, and the model would never know.
|
|
468
504
|
*/
|
|
469
505
|
function* handleCutOffReply(flow, state, profile, latestStructured,
|
|
470
506
|
/** True when the attempt's events go out at its end (`yieldBufferedAttemptEvents`). */
|
|
471
507
|
held) {
|
|
472
508
|
if (latestStructured !== undefined || flow.pendingItemFix)
|
|
473
509
|
return 'pass';
|
|
474
|
-
const
|
|
475
|
-
if (!
|
|
510
|
+
const budget = cutOffBudget(profile);
|
|
511
|
+
if (!budget && !flow.currentGen.structured)
|
|
512
|
+
return 'pass';
|
|
513
|
+
const unparsed = cutOffReply(state, flow.currentGen, profile);
|
|
514
|
+
if (!unparsed)
|
|
476
515
|
return 'pass';
|
|
477
|
-
if (
|
|
516
|
+
if (state.resumes < budget) {
|
|
517
|
+
state.resumes += 1;
|
|
478
518
|
const nextRequest = buildRepairRequest(flow.currentReq, unparsed.text, unparsed.rejection, unparsed.guidance);
|
|
479
519
|
yield updateFlowForRetry(flow, state, profile, nextRequest, 'validation');
|
|
480
520
|
return 'continue';
|
|
481
521
|
}
|
|
522
|
+
// why: A text reply cut off is still a reply, and the host's Continue (`allowContinue`) picks it up.
|
|
523
|
+
if (!flow.currentGen.structured && !state.cutOffCall && unparsed.text.trim())
|
|
524
|
+
return 'pass';
|
|
482
525
|
const failure = toErrorEvent(new TheoremError('bad_response', 'the reply was cut off at the output limit'));
|
|
483
526
|
recordStepEvent(failure, state);
|
|
484
527
|
state.lastStop = { kind: 'provider_error' };
|
|
@@ -486,10 +529,11 @@ held) {
|
|
|
486
529
|
yield failure;
|
|
487
530
|
return 'pass';
|
|
488
531
|
}
|
|
489
|
-
/** How many
|
|
532
|
+
/** How many model calls a turn may send again itself when the output limit cuts one off. */
|
|
490
533
|
function cutOffBudget(profile) {
|
|
491
|
-
|
|
492
|
-
|
|
534
|
+
if (profile.type !== 'text' && !profileTurnOutputs(profile)?.structured)
|
|
535
|
+
return 0;
|
|
536
|
+
return cutOffRepairs(profile);
|
|
493
537
|
}
|
|
494
538
|
/** Puts on the attempt's structured output the fields that still failed. */
|
|
495
539
|
function markFailed(state, failed) {
|
|
@@ -515,7 +559,7 @@ async function* executeSingleAttemptCycle(args) {
|
|
|
515
559
|
// invariant: The attempt's reply spans its before_end re-entries; only a new attempt starts it again.
|
|
516
560
|
state.replyText = '';
|
|
517
561
|
state.replyMessages = [];
|
|
518
|
-
state.
|
|
562
|
+
state.cutOffCall = undefined;
|
|
519
563
|
// invariant: The leak check's carry is the end of this attempt's reply; a retry's is read on its own.
|
|
520
564
|
state.canaryCarry = undefined;
|
|
521
565
|
let latestStructured;
|
|
@@ -59,8 +59,11 @@ interface StepExecutionState {
|
|
|
59
59
|
message: TurnHistoryMessage;
|
|
60
60
|
at: number;
|
|
61
61
|
}[];
|
|
62
|
-
/** The
|
|
63
|
-
|
|
62
|
+
/** The tool call this attempt was writing when the output limit cut its arguments off. */
|
|
63
|
+
cutOffCall?: {
|
|
64
|
+
name: string;
|
|
65
|
+
text: string;
|
|
66
|
+
};
|
|
64
67
|
/** The message `input.lateResults` opened, until the run can emit it. */
|
|
65
68
|
lateResults?: string;
|
|
66
69
|
/** The canary opening the last provider call ended on, read in front of the next call's reply. */
|
|
@@ -12,7 +12,7 @@ import { stepReplyMessages } from '../../interaction-parts.js';
|
|
|
12
12
|
import { profileTurnOutputs } from '../../registry/profile-outputs.js';
|
|
13
13
|
import { providerCompleteRequest } from '../../registry/provider-request.js';
|
|
14
14
|
import { injectWouldExceedMaxSteps } from '../../stages.js';
|
|
15
|
-
import { AUTO_CONTINUE_DELAY_MS, isFailedStopKind, profileAllowsInject, profileTurnResumption, shouldAutoContinue, stageAbortStop, } from '../../stop.js';
|
|
15
|
+
import { AUTO_CONTINUE_DELAY_MS, cutOffRepairs, isFailedStopKind, profileAllowsInject, profileTurnResumption, shouldAutoContinue, stageAbortStop, } from '../../stop.js';
|
|
16
16
|
import { failedActivity, failureEvent, toolCallRequestEvent, } from '../../tools/events.js';
|
|
17
17
|
import { executeRegisteredTool, shownToolArguments, } from '../../tools/execute.js';
|
|
18
18
|
import { formatToolFailureForModel, formatToolResult } from '../../tools/model-text.js';
|
|
@@ -144,33 +144,33 @@ async function* showAnswer(shown, tally, step) {
|
|
|
144
144
|
yield* shown.show(event);
|
|
145
145
|
}
|
|
146
146
|
/**
|
|
147
|
-
*
|
|
147
|
+
* A tool call the output limit cut off, on a profile that repairs cuts (`cutOffRepairs`): its drafts,
|
|
148
|
+
* kept on the attempt for the repair. The call
|
|
148
149
|
* stops at `length`, and the failure its broken arguments gave is not the turn's.
|
|
149
150
|
*
|
|
150
151
|
* why: A protocol hands over a call whose arguments do not parse as a bare `bad_response`, and
|
|
151
152
|
* drops the call; the stream then stops it as a `provider_error`. Its drafts are what the model
|
|
152
153
|
* wrote, and the cut is why it broke.
|
|
153
154
|
*/
|
|
154
|
-
function
|
|
155
|
-
if (!tally.cut || !
|
|
155
|
+
function keepCutOffCall(tally, state, control, profile) {
|
|
156
|
+
if (!tally.cut || !control.toolDrafts || !cutOffRepairs(profile))
|
|
156
157
|
return;
|
|
157
|
-
|
|
158
|
+
const made = new Set(tally.calls.filter((call) => !call.failure).map((call) => call.callId));
|
|
159
|
+
const cut = [...control.toolDrafts].findLast(([id, draft]) => !made.has(id) && draft.text.trim());
|
|
160
|
+
if (!cut)
|
|
158
161
|
return;
|
|
159
|
-
state.
|
|
162
|
+
state.cutOffCall = cut[1];
|
|
160
163
|
tally.failures = tally.failures.filter((failure) => failure.errorKind !== 'bad_response');
|
|
161
164
|
tally.stop = { kind: 'length' };
|
|
162
165
|
state.lastStop = tally.stop;
|
|
163
166
|
}
|
|
164
167
|
/**
|
|
165
|
-
* A tool call's preview. The answer tool's streams as the structured reply's draft
|
|
166
|
-
* keeps it, for the repair of an answer the output limit cuts off (`keepCutOffAnswer`).
|
|
168
|
+
* A tool call's preview. The answer tool's streams as the structured reply's draft.
|
|
167
169
|
*
|
|
168
170
|
* why: A preview of the call that follows, which owns the arguments: not the turn's record. It streams
|
|
169
171
|
* as the reply's text does, through its own gate, and like that text is held only when delivery is buffered.
|
|
170
172
|
*/
|
|
171
|
-
async function* showToolDraft(event, shown, generation, buffer
|
|
172
|
-
if (event.name === ANSWER_TOOL)
|
|
173
|
-
tally.answerDraft += event.text;
|
|
173
|
+
async function* showToolDraft(event, shown, generation, buffer) {
|
|
174
174
|
if (buffer.holdVisible)
|
|
175
175
|
return;
|
|
176
176
|
if (event.name === ANSWER_TOOL && answersByTool(generation))
|
|
@@ -229,7 +229,8 @@ const PASSING_ERROR_KINDS = new Set([
|
|
|
229
229
|
* A failure the same call would meet again is not sent again (`PASSING_ERROR_KINDS`).
|
|
230
230
|
*
|
|
231
231
|
* why: A failed call that gave no reply and no tool call left nothing behind, so sending it again repeats
|
|
232
|
-
* nothing. A reply cut at `length` is not
|
|
232
|
+
* nothing. A reply cut at `length` is not sent again, since the same call would be cut at the same
|
|
233
|
+
* place: the attempt gate repairs it with guidance instead (`handleCutOffReply`).
|
|
233
234
|
*/
|
|
234
235
|
function resumeOf(mayResume, profile, tally) {
|
|
235
236
|
const { stop } = tally;
|
|
@@ -280,7 +281,6 @@ async function* executeAutonomousStep(args, state, buffer = {
|
|
|
280
281
|
text: '',
|
|
281
282
|
failures: [],
|
|
282
283
|
replied: false,
|
|
283
|
-
answerDraft: '',
|
|
284
284
|
cut: false,
|
|
285
285
|
};
|
|
286
286
|
const control = {
|
|
@@ -323,7 +323,7 @@ async function* executeAutonomousStep(args, state, buffer = {
|
|
|
323
323
|
continue;
|
|
324
324
|
}
|
|
325
325
|
if (event.type === 'tool_draft') {
|
|
326
|
-
yield* showToolDraft(event, shown, generation, buffer
|
|
326
|
+
yield* showToolDraft(event, shown, generation, buffer);
|
|
327
327
|
continue;
|
|
328
328
|
}
|
|
329
329
|
// why: The model's history keeps what it wrote; only the reply the host gets is set apart.
|
|
@@ -340,7 +340,7 @@ async function* executeAutonomousStep(args, state, buffer = {
|
|
|
340
340
|
throw err;
|
|
341
341
|
}
|
|
342
342
|
yield* shown.end();
|
|
343
|
-
|
|
343
|
+
keepCutOffCall(tally, state, control, profile);
|
|
344
344
|
yield* showAnswer(shown, tally, { generation, state, control, buffer, call });
|
|
345
345
|
keepStreamCarry(state, control);
|
|
346
346
|
const resume = resumeOf(args.mayResume, profile, tally) ?? mediaResumeOf(state, profile, tally);
|
|
@@ -20,6 +20,11 @@ interface OutboundStreamControl {
|
|
|
20
20
|
promptLeaks?: GuardrailHit[];
|
|
21
21
|
/** What the turn's thoughts so far ended on (`ThoughtGuard.carryOut`): read in front of this call's, and replaced. */
|
|
22
22
|
thoughtCarry?: string;
|
|
23
|
+
/** Each tool call's arguments as this call's drafts wrote them, before any gate, by call id. */
|
|
24
|
+
toolDrafts?: ReadonlyMap<string, {
|
|
25
|
+
name: string;
|
|
26
|
+
text: string;
|
|
27
|
+
}>;
|
|
23
28
|
}
|
|
24
29
|
declare function shouldSkipStreamEvent(event: ModelEvent, profile: Profile): boolean;
|
|
25
30
|
/** Host-visible output a mid-stream block withholds. A thought is never withheld, only omitted from. */
|
|
@@ -141,6 +141,8 @@ class ToolDrafts {
|
|
|
141
141
|
tools;
|
|
142
142
|
answerTool;
|
|
143
143
|
drafts = new Map();
|
|
144
|
+
/** Each call's arguments as the model wrote them, shown or not. */
|
|
145
|
+
written = new Map();
|
|
144
146
|
constructor(policy, context, tools, answerTool) {
|
|
145
147
|
this.policy = policy;
|
|
146
148
|
this.context = context;
|
|
@@ -156,6 +158,9 @@ class ToolDrafts {
|
|
|
156
158
|
this.close(event);
|
|
157
159
|
return false;
|
|
158
160
|
}
|
|
161
|
+
const written = this.written.get(event.callId) ?? { name: event.name, text: '' };
|
|
162
|
+
written.text += event.text;
|
|
163
|
+
this.written.set(event.callId, written);
|
|
159
164
|
// why: A withheld reply is judged whole when its attempt ends; nothing more of it previews before then.
|
|
160
165
|
if (!withheld)
|
|
161
166
|
yield* this.release(event, timed);
|
|
@@ -211,6 +216,12 @@ function streamContext(args, policy) {
|
|
|
211
216
|
...(args.ownTools ? { ownTools: args.ownTools } : {}),
|
|
212
217
|
};
|
|
213
218
|
}
|
|
219
|
+
function toolDraftsFor(args, policy, context) {
|
|
220
|
+
const drafts = new ToolDrafts(policy, context, args.tools, args.answerTool === true);
|
|
221
|
+
if (args.control)
|
|
222
|
+
args.control.toolDrafts = drafts.written;
|
|
223
|
+
return drafts;
|
|
224
|
+
}
|
|
214
225
|
async function* yieldProviderEvents(args) {
|
|
215
226
|
const { profile, request, provider, call, signal, control } = args;
|
|
216
227
|
/** Runs one stream check and adds the run to the call's record of that check. */
|
|
@@ -228,7 +239,7 @@ async function* yieldProviderEvents(args) {
|
|
|
228
239
|
const { canaryCarry, thoughtCarry } = control ?? {};
|
|
229
240
|
const gate = await createOutboundProgressiveGate(policy, context, 'reply', canaryCarry);
|
|
230
241
|
const thoughts = await thoughtGuardFor(policy, context, thoughtCarry);
|
|
231
|
-
const drafts =
|
|
242
|
+
const drafts = toolDraftsFor(args, policy, context);
|
|
232
243
|
/** The streamed event whose reply sits in the gate's lookback; released tails keep its shape. */
|
|
233
244
|
let pendingStream = null;
|
|
234
245
|
let withholdVisible = false;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** labels-exempt-file: authoring field-meta docs — not runtime user or model copy (P2) */
|
|
2
|
+
/**
|
|
3
|
+
* Generated by `scripts/gen-field-docs.ts` from the JSDoc on the declarations.
|
|
4
|
+
* Do not edit: change the JSDoc and run the script.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
/** The doc of each catalog field a type declares, keyed by catalog path. */
|
|
9
|
+
export declare const FIELD_DOCS: Readonly<Record<string, string>>;
|
|
10
|
+
/** The doc of each export `API_EXPORTS` names, keyed by that name. */
|
|
11
|
+
export declare const EXPORT_DOCS: Readonly<Record<string, string>>;
|
|
12
|
+
/** The doc of each value of an `as const` list, keyed by the list's name, then by the value. */
|
|
13
|
+
export declare const OPTION_DOCS: Readonly<Record<'AUTH_UNAUTHENTICATED_POLICIES' | 'BLOCKED_REPLY_ON_BLOCK' | 'COMPACTION_METERS' | 'COMPACTION_OUTCOMES' | 'COMPACTION_TIMINGS' | 'CONTEXT_SENDERS' | 'CONTINUE_STOP_KINDS' | 'DECISION_QUESTION_TYPES' | 'DESTINATION_GATES' | 'ERROR_KINDS' | 'LIVE_ACTIVITY_HANDLINGS' | 'LIVE_END_SENSITIVITIES' | 'LIVE_START_SENSITIVITIES' | 'PROFILE_TYPES' | 'SPEECH_AUDIO_FORMATS' | 'STEP_LIMIT_MODES' | 'STREAM_MODES' | 'STUDIO_AUTH_TYPES' | 'TAINT_GATES' | 'THINKING_LEVELS' | 'TOOL_ACCESS' | 'TOOL_AUTH_TYPES' | 'TOOL_BACKGROUND_MODES' | 'TOOL_LOAD_TIERS' | 'TOOL_PERMISSION' | 'TOOL_TYPES' | 'TURN_STOP_KINDS', Readonly<Record<string, string>>>>;
|