@theoremjs/agents 0.3.4-next.711.g78e504a → 0.3.4-next.715.geef22fd
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/interface/mod.d.ts +1 -1
- package/esm/src/interface/mod.js +1 -1
- package/esm/src/interface/tool-invoke.d.ts +11 -3
- package/esm/src/interface/tool-invoke.js +11 -4
- package/esm/src/kernel/api-catalog.js +4 -0
- package/esm/src/kernel/engine/runner/gates.js +4 -3
- package/esm/src/kernel/engine/runner/mod.js +1 -0
- package/esm/src/kernel/engine/runner/steps.js +4 -0
- package/esm/src/kernel/turn-events.d.ts +2 -0
- package/esm/src/kernel/turn-events.js +1 -0
- package/esm/src/kernel/types.d.ts +5 -0
- package/package.json +1 -1
|
@@ -26,7 +26,7 @@ export type { WordedStopKind } from './stop.js';
|
|
|
26
26
|
export { stopText, WORDED_STOP_KINDS } from './stop.js';
|
|
27
27
|
export type { SettledToolCallEvent } from './tool-calls.js';
|
|
28
28
|
export { argumentsSoFar, settlesToolCall, toolCallRanWith, toolCallsOf } from './tool-calls.js';
|
|
29
|
-
export { promotedToolIdsFromEvents,
|
|
29
|
+
export { promotedToolIdsFromEvents, type ReplyCarried, replyCarriedFromEvents, toolSnapshotFromEvents, } from './tool-invoke.js';
|
|
30
30
|
export type { PromotedToolMedia } from './tool-media.js';
|
|
31
31
|
export { collectPromotedMediaFromToolOutput, promotedMediaFromUrlString, } from './tool-media.js';
|
|
32
32
|
export type { AttachmentValidationResult, ComposerInterfaceFields, ComposerProfileInterface, FoldTurnEventsOptions, ImageProfileInterface, LiveProfileInterface, ModelBindingView, PendingAttachment, ProfileGuardrailsView, ProfileInputsInterface, ProfileInterface, ProfileObservabilityView, ProfileOutputsView, ProfileToolsView, SpeechProfileInterface, TextProfileInterface, TranscriptBlock, TranscriptBlockKind, TranscriptionProfileInterface, UserTurnDraft, } from './types.js';
|
package/esm/src/interface/mod.js
CHANGED
|
@@ -17,6 +17,6 @@ export { profileInterfaceSchema } from './profile-interface.js';
|
|
|
17
17
|
export { applyTurnEventsToSession, awaitingFromEvents, branchInterfaceTurnSession, emptyInterfaceTurnSession, gatedToolFromEvents, gatedToolsFromEvents, } from './session.js';
|
|
18
18
|
export { stopText, WORDED_STOP_KINDS } from './stop.js';
|
|
19
19
|
export { argumentsSoFar, settlesToolCall, toolCallRanWith, toolCallsOf } from './tool-calls.js';
|
|
20
|
-
export { promotedToolIdsFromEvents,
|
|
20
|
+
export { promotedToolIdsFromEvents, replyCarriedFromEvents, toolSnapshotFromEvents, } from './tool-invoke.js';
|
|
21
21
|
export { collectPromotedMediaFromToolOutput, promotedMediaFromUrlString, } from './tool-media.js';
|
|
22
22
|
export { streamThoughtsEnabled } from './types.js';
|
|
@@ -3,6 +3,14 @@ import type { ToolId, TurnEvent, TurnToolSnapshot } from '../kernel/types.js';
|
|
|
3
3
|
declare function promotedToolIdsFromEvents(events: readonly TurnEvent[]): ToolId[];
|
|
4
4
|
/** The tool snapshot on the last `done` event that carries one, which only a turn stopped on a tool or gate does. */
|
|
5
5
|
declare function toolSnapshotFromEvents(events: readonly TurnEvent[]): TurnToolSnapshot | undefined;
|
|
6
|
-
/**
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
/** What a reply that goes on after a pause carries into its next run. */
|
|
7
|
+
export type ReplyCarried = {
|
|
8
|
+
promoted: ToolId[];
|
|
9
|
+
stepsTaken: number;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* What a paused reply holds: the tools on the list it paused with, those a call has loaded since,
|
|
13
|
+
* and the steps its last run counted.
|
|
14
|
+
*/
|
|
15
|
+
declare function replyCarriedFromEvents(events: readonly TurnEvent[]): ReplyCarried;
|
|
16
|
+
export { promotedToolIdsFromEvents, replyCarriedFromEvents, toolSnapshotFromEvents };
|
|
@@ -19,9 +19,16 @@ function toolSnapshotFromEvents(events) {
|
|
|
19
19
|
const done = findLast(events, (event) => event.type === 'done' && event.tools !== undefined);
|
|
20
20
|
return done?.type === 'done' ? done.tools : undefined;
|
|
21
21
|
}
|
|
22
|
-
/**
|
|
23
|
-
|
|
22
|
+
/**
|
|
23
|
+
* What a paused reply holds: the tools on the list it paused with, those a call has loaded since,
|
|
24
|
+
* and the steps its last run counted.
|
|
25
|
+
*/
|
|
26
|
+
function replyCarriedFromEvents(events) {
|
|
24
27
|
const visible = toolSnapshotFromEvents(events)?.visible ?? [];
|
|
25
|
-
|
|
28
|
+
const done = findLast(events, (event) => event.type === 'done' && event.steps !== undefined);
|
|
29
|
+
return {
|
|
30
|
+
promoted: [...new Set([...visible, ...promotedToolIdsFromEvents(events)])],
|
|
31
|
+
stepsTaken: done?.type === 'done' ? (done.steps ?? 0) : 0,
|
|
32
|
+
};
|
|
26
33
|
}
|
|
27
|
-
export { promotedToolIdsFromEvents,
|
|
34
|
+
export { promotedToolIdsFromEvents, replyCarriedFromEvents, toolSnapshotFromEvents };
|
|
@@ -141,6 +141,10 @@ export const REQUEST_FIELDS = {
|
|
|
141
141
|
type: 'ToolId[]',
|
|
142
142
|
doc: 'Tools this reply already had when an earlier run of it paused; the turn opens with them on its list.',
|
|
143
143
|
},
|
|
144
|
+
'runTurn.stepsTaken': {
|
|
145
|
+
type: 'number',
|
|
146
|
+
doc: 'Steps this reply already took when an earlier run of it paused; they count against maxSteps.',
|
|
147
|
+
},
|
|
144
148
|
'runTurn.speech': {
|
|
145
149
|
type: 'TurnSpeech',
|
|
146
150
|
doc: "This turn's voice, style, and speed; each one given replaces the profile's speech field of that name. Refused on a profile that is not speech.",
|
|
@@ -462,9 +462,10 @@ function gateStatusToAction(status) {
|
|
|
462
462
|
}
|
|
463
463
|
async function* executeSingleAttemptCycle(args) {
|
|
464
464
|
const { flow, state, profile, system, provider } = args;
|
|
465
|
-
// invariant: Fresh maxSteps budget per validation/egress attempt
|
|
466
|
-
// re-entry inside this cycle still accumulates stepCount
|
|
467
|
-
|
|
465
|
+
// invariant: Fresh maxSteps budget per validation/egress attempt, past the steps an earlier run
|
|
466
|
+
// of this reply took. before_end inject re-entry inside this cycle still accumulates stepCount
|
|
467
|
+
// (do not reset there).
|
|
468
|
+
state.stepCount = flow.currentReq.stepsTaken ?? 0;
|
|
468
469
|
// invariant: The attempt's reply spans its before_end re-entries; only a new attempt starts it again.
|
|
469
470
|
state.replyText = '';
|
|
470
471
|
state.replyMessages = [];
|
|
@@ -283,6 +283,7 @@ async function* emitTurn(args) {
|
|
|
283
283
|
const tokens = sumTurnTokens(state.allEmittedEvents);
|
|
284
284
|
const done = turnDoneOf({
|
|
285
285
|
stop: state.lastStop ?? { kind: 'completed' },
|
|
286
|
+
steps: state.stepCount,
|
|
286
287
|
...(state.providerState &&
|
|
287
288
|
!cutConversation(state) &&
|
|
288
289
|
!('providerContinuation' in profile && profile.providerContinuation?.history === 'stateless') &&
|
|
@@ -568,6 +568,10 @@ async function* executeAttempt(args) {
|
|
|
568
568
|
replyIsJudged(resolveGuardrailPolicy(profile.guardrails), TURN_REPLY);
|
|
569
569
|
// why: Buffered delivery holds each attempt's text and media until it passes; streamed delivery shows them live.
|
|
570
570
|
const holdVisible = validation !== undefined && generation.stream === false;
|
|
571
|
+
// why: A reply that spent its steps before it paused has no step left to read the answered call.
|
|
572
|
+
if (isStepLimitReached(state.stepCount, generation.maxSteps ?? 0)) {
|
|
573
|
+
state.lastStop = { kind: 'step_limit' };
|
|
574
|
+
}
|
|
571
575
|
// why: Ceiling is cumulative `state.stepCount` across before_end inject re-entries
|
|
572
576
|
// within this attempt. Validation/egress repair resets stepCount at the start
|
|
573
577
|
// of each attempt cycle.
|
|
@@ -569,6 +569,8 @@ export interface DoneBase {
|
|
|
569
569
|
tokens?: TurnTokens;
|
|
570
570
|
/** The turn's root span as a W3C `traceparent`, for a later request's `links`. */
|
|
571
571
|
traceparent?: string;
|
|
572
|
+
/** The model calls that count against `maxSteps` so far, those of `stepsTaken` included. */
|
|
573
|
+
steps?: number;
|
|
572
574
|
compaction?: CompactionSignal;
|
|
573
575
|
/** A user utterance interrupted an in-flight live response (barge-in). */
|
|
574
576
|
interrupted?: boolean;
|
|
@@ -360,6 +360,7 @@ const doneBase = {
|
|
|
360
360
|
type: z.literal('done'),
|
|
361
361
|
tokens: turnTokens.optional(),
|
|
362
362
|
traceparent: z.string().optional(),
|
|
363
|
+
steps: z.number().int().nonnegative().optional(),
|
|
363
364
|
compaction: compactionSignal.optional(),
|
|
364
365
|
interrupted: z.boolean().optional(),
|
|
365
366
|
interactionId: z.string().optional(),
|
|
@@ -828,6 +828,11 @@ export interface TurnRequest {
|
|
|
828
828
|
* path does not grant is left out, as for `tools.t1Policy`.
|
|
829
829
|
*/
|
|
830
830
|
promoted?: ToolId[];
|
|
831
|
+
/**
|
|
832
|
+
* Steps this reply already took when an earlier run of it paused. They count against `maxSteps`,
|
|
833
|
+
* so an answered call does not give the reply its steps back. Read `done.steps`.
|
|
834
|
+
*/
|
|
835
|
+
stepsTaken?: number;
|
|
831
836
|
input?: TurnInput;
|
|
832
837
|
/** Credentials for authenticated HTTP / MCP tools, read by auth slot when a tool needs one. */
|
|
833
838
|
credentials?: ToolCredentialSource;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theoremjs/agents",
|
|
3
|
-
"version": "0.3.4-next.
|
|
3
|
+
"version": "0.3.4-next.715.geef22fd",
|
|
4
4
|
"description": "A flat TypeScript agent kernel for typed profiles, deterministic turn execution, registered tools, provider adapters, guardrails, and host-injected traces.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agent",
|