@noetic-tools/types 3.4.1 → 3.6.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/dist/schemas/workflow.d.ts +34 -20
- package/dist/schemas/workflow.js +3 -0
- package/dist/types/acp.d.ts +6 -6
- package/dist/types/common.d.ts +26 -0
- package/dist/types/common.js +14 -0
- package/dist/types/context-harness.d.ts +3 -1
- package/dist/types/context.d.ts +23 -1
- package/dist/types/detached.d.ts +3 -3
- package/dist/types/runtime.d.ts +7 -1
- package/dist/types/step.d.ts +51 -18
- package/dist/util/message-helpers.d.ts +19 -1
- package/dist/util/message-helpers.js +41 -14
- package/package.json +1 -1
|
@@ -47,23 +47,32 @@ export type UntilPredicate = {
|
|
|
47
47
|
export declare const UntilPredicateSchema: z.ZodType<UntilPredicate>;
|
|
48
48
|
/** @public ESM literal enum for merge strategies. */
|
|
49
49
|
export declare const MergeStrategy: {
|
|
50
|
-
readonly Last:
|
|
51
|
-
readonly First:
|
|
52
|
-
readonly Concat:
|
|
50
|
+
readonly Last: "last";
|
|
51
|
+
readonly First: "first";
|
|
52
|
+
readonly Concat: "concat";
|
|
53
53
|
};
|
|
54
54
|
/** @public Named merge strategy for inParallel nodes. */
|
|
55
55
|
export type MergeStrategy = (typeof MergeStrategy)[keyof typeof MergeStrategy];
|
|
56
56
|
/** @public Zod schema for the named merge strategy used by `inParallel` nodes. */
|
|
57
57
|
export declare const MergeStrategySchema: z.ZodEnum<{
|
|
58
58
|
concat: "concat";
|
|
59
|
-
first: "first";
|
|
60
59
|
last: "last";
|
|
60
|
+
first: "first";
|
|
61
61
|
}>;
|
|
62
62
|
declare const ModelParamsSchema: z.ZodObject<{
|
|
63
63
|
temperature: z.ZodOptional<z.ZodNumber>;
|
|
64
64
|
topP: z.ZodOptional<z.ZodNumber>;
|
|
65
65
|
maxTokens: z.ZodOptional<z.ZodNumber>;
|
|
66
66
|
stopSequences: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
67
|
+
serviceTier: z.ZodOptional<z.ZodEnum<{
|
|
68
|
+
readonly Auto: "auto";
|
|
69
|
+
readonly Default: "default";
|
|
70
|
+
readonly Fast: "fast";
|
|
71
|
+
readonly Flex: "flex";
|
|
72
|
+
readonly Priority: "priority";
|
|
73
|
+
readonly Scale: "scale";
|
|
74
|
+
readonly Ultrafast: "ultrafast";
|
|
75
|
+
}>>;
|
|
67
76
|
}, z.core.$strip>;
|
|
68
77
|
/**
|
|
69
78
|
* A uniform tool entry on a `callModel` node. Every entry is an object keyed by
|
|
@@ -87,9 +96,9 @@ declare const CallModelToolEntrySchema: z.ZodObject<{
|
|
|
87
96
|
declare const RetryPolicySchema: z.ZodObject<{
|
|
88
97
|
maxAttempts: z.ZodNumber;
|
|
89
98
|
backoff: z.ZodEnum<{
|
|
90
|
-
exponential: "exponential";
|
|
91
99
|
fixed: "fixed";
|
|
92
100
|
linear: "linear";
|
|
101
|
+
exponential: "exponential";
|
|
93
102
|
}>;
|
|
94
103
|
initialDelay: z.ZodNumber;
|
|
95
104
|
maxDelay: z.ZodOptional<z.ZodNumber>;
|
|
@@ -97,36 +106,36 @@ declare const RetryPolicySchema: z.ZodObject<{
|
|
|
97
106
|
declare const AcpPermissionPolicySchema: z.ZodObject<{
|
|
98
107
|
default: z.ZodOptional<z.ZodEnum<{
|
|
99
108
|
allow: "allow";
|
|
100
|
-
cancel: "cancel";
|
|
101
109
|
deny: "deny";
|
|
110
|
+
cancel: "cancel";
|
|
102
111
|
}>>;
|
|
103
112
|
allow: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
104
113
|
kind: z.ZodOptional<z.ZodEnum<{
|
|
114
|
+
read: "read";
|
|
105
115
|
delete: "delete";
|
|
106
|
-
|
|
116
|
+
search: "search";
|
|
107
117
|
execute: "execute";
|
|
108
|
-
|
|
118
|
+
edit: "edit";
|
|
109
119
|
move: "move";
|
|
110
|
-
other: "other";
|
|
111
|
-
read: "read";
|
|
112
|
-
search: "search";
|
|
113
|
-
switch_mode: "switch_mode";
|
|
114
120
|
think: "think";
|
|
121
|
+
fetch: "fetch";
|
|
122
|
+
switch_mode: "switch_mode";
|
|
123
|
+
other: "other";
|
|
115
124
|
}>>;
|
|
116
125
|
title: z.ZodOptional<z.ZodString>;
|
|
117
126
|
}, z.core.$strip>>>;
|
|
118
127
|
deny: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
119
128
|
kind: z.ZodOptional<z.ZodEnum<{
|
|
129
|
+
read: "read";
|
|
120
130
|
delete: "delete";
|
|
121
|
-
|
|
131
|
+
search: "search";
|
|
122
132
|
execute: "execute";
|
|
123
|
-
|
|
133
|
+
edit: "edit";
|
|
124
134
|
move: "move";
|
|
125
|
-
other: "other";
|
|
126
|
-
read: "read";
|
|
127
|
-
search: "search";
|
|
128
|
-
switch_mode: "switch_mode";
|
|
129
135
|
think: "think";
|
|
136
|
+
fetch: "fetch";
|
|
137
|
+
switch_mode: "switch_mode";
|
|
138
|
+
other: "other";
|
|
130
139
|
}>>;
|
|
131
140
|
title: z.ZodOptional<z.ZodString>;
|
|
132
141
|
}, z.core.$strip>>>;
|
|
@@ -166,14 +175,19 @@ declare const AcpMcpServerSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
166
175
|
declare const AcpSessionPolicySchema: z.ZodObject<{
|
|
167
176
|
reuse: z.ZodOptional<z.ZodString>;
|
|
168
177
|
keepAlive: z.ZodOptional<z.ZodEnum<{
|
|
169
|
-
harness: "harness";
|
|
170
|
-
run: "run";
|
|
171
178
|
step: "step";
|
|
179
|
+
run: "run";
|
|
180
|
+
harness: "harness";
|
|
172
181
|
}>>;
|
|
173
182
|
load: z.ZodOptional<z.ZodString>;
|
|
174
183
|
}, z.core.$strip>;
|
|
175
184
|
interface WorkflowNodeBase {
|
|
176
185
|
id: string;
|
|
186
|
+
/**
|
|
187
|
+
* Whether a resumed run replays this node's recorded output. Defaults to `true`;
|
|
188
|
+
* `false` makes the node run again on every resume. See spec 23a § Identity.
|
|
189
|
+
*/
|
|
190
|
+
durable?: boolean;
|
|
177
191
|
}
|
|
178
192
|
/**
|
|
179
193
|
* A reference to a streaming `OutputCodec` for a `callModel` node's structured
|
package/dist/schemas/workflow.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
* document back into live `Step` objects via the existing builders.
|
|
10
10
|
*/
|
|
11
11
|
import { z } from 'zod';
|
|
12
|
+
import { ServiceTier } from '../types/common.js';
|
|
12
13
|
import { DecideQuestionsSchema, routeOutcomes } from '../types/decide.js';
|
|
13
14
|
//#endregion
|
|
14
15
|
//#region Until Predicate Schemas
|
|
@@ -90,6 +91,7 @@ const ModelParamsSchema = z.object({
|
|
|
90
91
|
topP: z.number().min(0).max(1).optional(),
|
|
91
92
|
maxTokens: z.number().int().positive().optional(),
|
|
92
93
|
stopSequences: z.array(z.string()).optional(),
|
|
94
|
+
serviceTier: z.enum(ServiceTier).optional(),
|
|
93
95
|
});
|
|
94
96
|
//#endregion
|
|
95
97
|
//#region Tool Entries
|
|
@@ -209,6 +211,7 @@ const AcpSessionPolicySchema = z.object({
|
|
|
209
211
|
const WorkflowNodeRef = z.lazy(() => WorkflowNodeSchema);
|
|
210
212
|
const SHARED_FIELDS = {
|
|
211
213
|
id: z.string().min(1),
|
|
214
|
+
durable: z.boolean().optional(),
|
|
212
215
|
};
|
|
213
216
|
const OutputCodecRefSchema = z.object({
|
|
214
217
|
codec: z.literal('openui'),
|
package/dist/types/acp.d.ts
CHANGED
|
@@ -66,9 +66,9 @@ export interface AcpTransportOptions {
|
|
|
66
66
|
export type AcpTransportFactory = (opts: AcpTransportOptions) => Promise<AcpTransport>;
|
|
67
67
|
/** @public How a permission request was resolved. */
|
|
68
68
|
export declare const AcpPermissionDecision: {
|
|
69
|
-
readonly Allow:
|
|
70
|
-
readonly Deny:
|
|
71
|
-
readonly Cancel:
|
|
69
|
+
readonly Allow: "allow";
|
|
70
|
+
readonly Deny: "deny";
|
|
71
|
+
readonly Cancel: "cancel";
|
|
72
72
|
};
|
|
73
73
|
/** @public Union of permission decisions. */
|
|
74
74
|
export type AcpPermissionDecision = (typeof AcpPermissionDecision)[keyof typeof AcpPermissionDecision];
|
|
@@ -416,11 +416,11 @@ export interface AcpAgent {
|
|
|
416
416
|
*/
|
|
417
417
|
export declare const AcpKeepAlive: {
|
|
418
418
|
/** Closed when the step finishes. The default. */
|
|
419
|
-
readonly Step:
|
|
419
|
+
readonly Step: "step";
|
|
420
420
|
/** Kept for the rest of the root run, then closed by the harness. */
|
|
421
|
-
readonly Run:
|
|
421
|
+
readonly Run: "run";
|
|
422
422
|
/** Kept until {@link AcpSessionDisposer.closeAcpSessions} is called. Nothing closes it for you. */
|
|
423
|
-
readonly Harness:
|
|
423
|
+
readonly Harness: "harness";
|
|
424
424
|
};
|
|
425
425
|
/** @public Union of connection keep-alive scopes. */
|
|
426
426
|
export type AcpKeepAlive = (typeof AcpKeepAlive)[keyof typeof AcpKeepAlive];
|
package/dist/types/common.d.ts
CHANGED
|
@@ -36,6 +36,22 @@ export interface ServerToolSpec {
|
|
|
36
36
|
* @public
|
|
37
37
|
*/
|
|
38
38
|
export declare function isServerToolSpec(value: unknown): value is ServerToolSpec;
|
|
39
|
+
/**
|
|
40
|
+
* @public OpenRouter service tiers. `fast` is an alias for `priority`;
|
|
41
|
+
* `ultrafast` prefers ultrafast endpoints and falls back to `priority`, then
|
|
42
|
+
* default endpoints.
|
|
43
|
+
*/
|
|
44
|
+
export declare const ServiceTier: {
|
|
45
|
+
readonly Auto: "auto";
|
|
46
|
+
readonly Default: "default";
|
|
47
|
+
readonly Fast: "fast";
|
|
48
|
+
readonly Flex: "flex";
|
|
49
|
+
readonly Priority: "priority";
|
|
50
|
+
readonly Scale: "scale";
|
|
51
|
+
readonly Ultrafast: "ultrafast";
|
|
52
|
+
};
|
|
53
|
+
/** @public Union of OpenRouter service tiers. */
|
|
54
|
+
export type ServiceTier = (typeof ServiceTier)[keyof typeof ServiceTier];
|
|
39
55
|
/**
|
|
40
56
|
* Optional parameters forwarded to the model provider during an LLM step.
|
|
41
57
|
* @public
|
|
@@ -49,6 +65,8 @@ export interface ModelParams {
|
|
|
49
65
|
maxTokens?: number;
|
|
50
66
|
/** Sequences that cause the model to stop generating. */
|
|
51
67
|
stopSequences?: string[];
|
|
68
|
+
/** OpenRouter service tier to request. Omit to use the provider default. */
|
|
69
|
+
serviceTier?: ServiceTier;
|
|
52
70
|
}
|
|
53
71
|
/** @public Aggregate token counts for an execution (input, output, total, cached). */
|
|
54
72
|
export interface TokenUsage {
|
|
@@ -84,6 +102,8 @@ export interface StepMeta {
|
|
|
84
102
|
toolCalls?: FunctionCallItem[];
|
|
85
103
|
usage?: RoundUsage;
|
|
86
104
|
cost?: number;
|
|
105
|
+
/** Tier the provider served an `llm` step on; see `LLMResponse.serviceTier`. */
|
|
106
|
+
serviceTier?: string;
|
|
87
107
|
responseItems?: ReadonlyArray<Item>;
|
|
88
108
|
/**
|
|
89
109
|
* Why an ACP agent stopped its turn. Set only by `acp-agent` steps, and the
|
|
@@ -107,6 +127,12 @@ export interface LLMResponse {
|
|
|
107
127
|
*/
|
|
108
128
|
rounds?: ReadonlyArray<RoundUsage>;
|
|
109
129
|
cost?: number;
|
|
130
|
+
/**
|
|
131
|
+
* The tier the provider reports it served, from the last round. Absent when
|
|
132
|
+
* the provider reports none — it is never an echo of the requested tier, so
|
|
133
|
+
* a difference from `params.serviceTier` means a fallback happened.
|
|
134
|
+
*/
|
|
135
|
+
serviceTier?: string;
|
|
110
136
|
}
|
|
111
137
|
/** @public Configuration for the LLM provider used by the agent harness. */
|
|
112
138
|
export interface LlmProviderConfig {
|
package/dist/types/common.js
CHANGED
|
@@ -17,3 +17,17 @@ export function isServerToolSpec(value) {
|
|
|
17
17
|
const { type } = value;
|
|
18
18
|
return type === 'openrouter:web_search' || type === 'openrouter:web_fetch';
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* @public OpenRouter service tiers. `fast` is an alias for `priority`;
|
|
22
|
+
* `ultrafast` prefers ultrafast endpoints and falls back to `priority`, then
|
|
23
|
+
* default endpoints.
|
|
24
|
+
*/
|
|
25
|
+
export const ServiceTier = {
|
|
26
|
+
Auto: 'auto',
|
|
27
|
+
Default: 'default',
|
|
28
|
+
Fast: 'fast',
|
|
29
|
+
Flex: 'flex',
|
|
30
|
+
Priority: 'priority',
|
|
31
|
+
Scale: 'scale',
|
|
32
|
+
Ultrafast: 'ultrafast',
|
|
33
|
+
};
|
|
@@ -120,6 +120,8 @@ export interface ContextHarness {
|
|
|
120
120
|
detachedSpawn<I, O>(step: unknown, input: I, parentCtx: Context, overrides?: ContextDetachedSpawnOverrides): DetachedHandle<O>;
|
|
121
121
|
createContext(opts?: {
|
|
122
122
|
parent?: Context;
|
|
123
|
+
/** Charge this context's usage to `parent` as it is spent. Default `true`. */
|
|
124
|
+
rollUpUsage?: boolean;
|
|
123
125
|
items?: Item[];
|
|
124
126
|
state?: unknown;
|
|
125
127
|
threadId?: string;
|
|
@@ -147,7 +149,7 @@ export interface ContextHarness {
|
|
|
147
149
|
* consumer frees a slot (back-pressure; default 30s timeout →
|
|
148
150
|
* `channel_timeout`, abort → `cancelled`).
|
|
149
151
|
*/
|
|
150
|
-
send<T>(channel: Channel<T>, value: T
|
|
152
|
+
send<T>(channel: Channel<T>, value: NoInfer<T>, ctx: Context): Promise<void>;
|
|
151
153
|
recv<T>(channel: Channel<T>, ctx: Context, opts?: {
|
|
152
154
|
timeout?: number;
|
|
153
155
|
}): Promise<T>;
|
package/dist/types/context.d.ts
CHANGED
|
@@ -42,6 +42,8 @@ export interface CwdState {
|
|
|
42
42
|
export interface RestoreContextOptions {
|
|
43
43
|
/** Live parent context, when the restored execution hangs under one. */
|
|
44
44
|
parent?: Context;
|
|
45
|
+
/** Charge the restored context's usage to `parent`, same as `createContext({ rollUpUsage })`. Default `true`. */
|
|
46
|
+
rollUpUsage?: boolean;
|
|
45
47
|
/** Opaque per-execution state, same as `createContext({ state })`. */
|
|
46
48
|
state?: unknown;
|
|
47
49
|
/** Context layers for the restored context. Defaults to the harness's configured layers. */
|
|
@@ -56,6 +58,17 @@ export interface Context<TContext = ContextData, TState = unknown> {
|
|
|
56
58
|
readonly cost: number;
|
|
57
59
|
state: TState;
|
|
58
60
|
readonly parent: Context<ContextData> | null;
|
|
61
|
+
/**
|
|
62
|
+
* Where this context's token/cost usage is also charged. Every charge
|
|
63
|
+
* recorded here is added to this context and then to each ancestor along
|
|
64
|
+
* this chain, so `tokens` / `cost` cover this context plus every descendant,
|
|
65
|
+
* live — whether the descendant succeeds, fails, or is abandoned.
|
|
66
|
+
*
|
|
67
|
+
* Equals `parent` unless the context was created with `rollUpUsage: false`,
|
|
68
|
+
* in which case it is `null` and the context keeps its spend to itself. When
|
|
69
|
+
* absent (a hand-rolled `Context` implementation), `parent` is used.
|
|
70
|
+
*/
|
|
71
|
+
readonly usageParent?: Context<ContextData> | null;
|
|
59
72
|
readonly depth: number;
|
|
60
73
|
readonly span: Span;
|
|
61
74
|
readonly threadId: string;
|
|
@@ -84,6 +97,15 @@ export interface Context<TContext = ContextData, TState = unknown> {
|
|
|
84
97
|
readonly unifiedTools?: ReadonlyArray<Tool>;
|
|
85
98
|
/** Runtime item schema registry active for this context. */
|
|
86
99
|
readonly itemSchemas?: ItemSchemaRegistry;
|
|
100
|
+
/**
|
|
101
|
+
* Receive a value from a channel. Waits up to `opts.timeout` ms (default
|
|
102
|
+
* 30s) before rejecting with `channel_timeout`; `timeout: 0` waits with no
|
|
103
|
+
* timeout in every mode and records an `unbounded_wait` channel warning.
|
|
104
|
+
* Aborting the context rejects the wait with `cancelled`.
|
|
105
|
+
*
|
|
106
|
+
* @throws `NoeticConfigError` with code `INVALID_CHANNEL_TIMEOUT` (as a
|
|
107
|
+
* rejection) when `opts.timeout` is negative.
|
|
108
|
+
*/
|
|
87
109
|
recv<T>(channel: Channel<T>, opts?: {
|
|
88
110
|
timeout?: number;
|
|
89
111
|
}): Promise<T>;
|
|
@@ -94,7 +116,7 @@ export interface Context<TContext = ContextData, TState = unknown> {
|
|
|
94
116
|
* (back-pressure): after the default 30s timeout it rejects with
|
|
95
117
|
* `channel_timeout`, and aborting the context rejects it with `cancelled`.
|
|
96
118
|
*/
|
|
97
|
-
send<T>(channel: Channel<T>, value: T): Promise<void>;
|
|
119
|
+
send<T>(channel: Channel<T>, value: NoInfer<T>): Promise<void>;
|
|
98
120
|
tryRecv<T>(channel: Channel<T>): T | null;
|
|
99
121
|
checkpoint(): Promise<void>;
|
|
100
122
|
complete<T>(value: T): void;
|
package/dist/types/detached.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/** @public Lifecycle states for a detached (background) execution. */
|
|
2
2
|
declare const DetachedStatus: {
|
|
3
|
-
readonly Running:
|
|
4
|
-
readonly Completed:
|
|
5
|
-
readonly Failed:
|
|
3
|
+
readonly Running: "running";
|
|
4
|
+
readonly Completed: "completed";
|
|
5
|
+
readonly Failed: "failed";
|
|
6
6
|
};
|
|
7
7
|
type DetachedStatus = (typeof DetachedStatus)[keyof typeof DetachedStatus];
|
|
8
8
|
/** @public Handle returned by `detachedSpawn`, used to poll or await a background execution. */
|
package/dist/types/runtime.d.ts
CHANGED
|
@@ -253,6 +253,12 @@ export interface AgentHarnessContract<TParams extends Record<string, unknown> =
|
|
|
253
253
|
}): DetachedHandle<O>;
|
|
254
254
|
createContext(opts?: {
|
|
255
255
|
parent?: Context;
|
|
256
|
+
/**
|
|
257
|
+
* Charge this context's token/cost usage to `parent` as it is spent, so
|
|
258
|
+
* the parent's `tokens` / `cost` include it. Default `true`; pass `false`
|
|
259
|
+
* to keep the child's spend off the parent.
|
|
260
|
+
*/
|
|
261
|
+
rollUpUsage?: boolean;
|
|
256
262
|
items?: Item[];
|
|
257
263
|
state?: unknown;
|
|
258
264
|
threadId?: string;
|
|
@@ -273,7 +279,7 @@ export interface AgentHarnessContract<TParams extends Record<string, unknown> =
|
|
|
273
279
|
* consumer frees a slot (30s default timeout → `channel_timeout`; context
|
|
274
280
|
* abort → `cancelled`).
|
|
275
281
|
*/
|
|
276
|
-
send<T>(channel: Channel<T>, value: T
|
|
282
|
+
send<T>(channel: Channel<T>, value: NoInfer<T>, ctx: Context): Promise<void>;
|
|
277
283
|
recv<T>(channel: Channel<T>, ctx: Context, opts?: {
|
|
278
284
|
timeout?: number;
|
|
279
285
|
}): Promise<T>;
|
package/dist/types/step.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ export interface Snapshot {
|
|
|
30
30
|
lastOutput: unknown;
|
|
31
31
|
/** Stringified text of the most recent iteration output. */
|
|
32
32
|
lastText: string;
|
|
33
|
-
/**
|
|
33
|
+
/** Prior iteration outputs, oldest first; bounded by `maxHistorySize` (default 100, oldest dropped first). */
|
|
34
34
|
history: unknown[];
|
|
35
35
|
/** Nesting depth of the current execution context. */
|
|
36
36
|
depth: number;
|
|
@@ -44,7 +44,7 @@ export interface Snapshot {
|
|
|
44
44
|
export interface Verdict {
|
|
45
45
|
/** When true, the loop terminates after this iteration. */
|
|
46
46
|
stop: boolean;
|
|
47
|
-
/**
|
|
47
|
+
/** Why the loop stopped or continued; recorded on the `loop.verdict` span event. */
|
|
48
48
|
reason?: string;
|
|
49
49
|
/** Feedback string injected into the next iteration's context (ignored when `stop` is true). */
|
|
50
50
|
feedback?: string;
|
|
@@ -73,10 +73,43 @@ export interface SettleResult<O> {
|
|
|
73
73
|
/** The error that caused rejection (present when `status` is `'rejected'`). */
|
|
74
74
|
error?: NoeticError;
|
|
75
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Combines inParallel path results into one output. `R` is the element type of
|
|
78
|
+
* `results`: `O` in `all` mode, `SettleResult<O>` in `settle` mode.
|
|
79
|
+
* @public
|
|
80
|
+
*/
|
|
81
|
+
export type MergeFn<TContext = ContextData, O = unknown, R = O> = (results: R[], ctx: Context<TContext>) => O;
|
|
82
|
+
/**
|
|
83
|
+
* Replay controls shared by every step kind (spec 23a § Identity).
|
|
84
|
+
*
|
|
85
|
+
* A resumed execution replays a recorded step's output in place of running it.
|
|
86
|
+
* By default the ledger keys that record by the step's execution path, so replay
|
|
87
|
+
* identity is positional. These fields change that per step.
|
|
88
|
+
* @public
|
|
89
|
+
*/
|
|
90
|
+
export interface StepReplay<TContext = ContextData, I = unknown> {
|
|
91
|
+
/**
|
|
92
|
+
* Whether the ledger records and replays this step. Defaults to `true`. With
|
|
93
|
+
* `false` the step always runs again on resume, so its side effects and state
|
|
94
|
+
* changes happen again too. Use it for cheap orchestration steps whose work is
|
|
95
|
+
* timing-dependent (which batch a worker picked) or lives in state rather than
|
|
96
|
+
* output. Applies to this step only: its children keep their own setting.
|
|
97
|
+
* `schedule` steps are never recorded, whatever this says.
|
|
98
|
+
*/
|
|
99
|
+
durable?: boolean;
|
|
100
|
+
/**
|
|
101
|
+
* Content key that replaces the positional path as this step's ledger key, so a
|
|
102
|
+
* step that may run at a different position on resume (a concurrent worker's
|
|
103
|
+
* call) still finds its own output. Two dispatches with the same key in one
|
|
104
|
+
* execution share one entry. A key that throws skips the ledger for that
|
|
105
|
+
* dispatch with a warning; it never fails the step.
|
|
106
|
+
*/
|
|
107
|
+
replayKey?(input: I, ctx: Context<TContext>): string;
|
|
108
|
+
}
|
|
76
109
|
/** @public Discriminated union of all step kinds that can be composed into an execution tree. */
|
|
77
110
|
export type Step<TContext = ContextData, I = unknown, O = unknown> = StepRunCode<TContext, I, O> | StepCallModel<TContext, I, O> | StepAcpAgent<TContext, I, O> | StepInvokeTool<TContext, I, O> | StepDecide<TContext, I, O> | StepConditional<TContext, I, O> | StepInParallel<TContext, I, O> | StepSpawn<TContext, I, O> | StepWithContext<TContext, I, O> | StepLoop<TContext, I, O> | StepSchedule<TContext, I, O>;
|
|
78
111
|
/** @public A step that executes arbitrary async logic via a user-supplied function. */
|
|
79
|
-
export interface StepRunCode<TContext = ContextData, I = unknown, O = unknown> {
|
|
112
|
+
export interface StepRunCode<TContext = ContextData, I = unknown, O = unknown> extends StepReplay<TContext, I> {
|
|
80
113
|
kind: 'runCode';
|
|
81
114
|
id: string;
|
|
82
115
|
execute: (input: I, ctx: Context<TContext>) => Promise<O>;
|
|
@@ -90,7 +123,7 @@ export interface StepRunCode<TContext = ContextData, I = unknown, O = unknown> {
|
|
|
90
123
|
subprocess?: SubprocessAdapter;
|
|
91
124
|
}
|
|
92
125
|
/** @public A step that sends a prompt to a language model and returns its response. */
|
|
93
|
-
export interface StepCallModel<TContext = ContextData,
|
|
126
|
+
export interface StepCallModel<TContext = ContextData, I = unknown, O = unknown> extends StepReplay<TContext, I> {
|
|
94
127
|
kind: 'callModel';
|
|
95
128
|
id: string;
|
|
96
129
|
/** Model id. Accepts either an eager string or a `(ctx) => string` getter. */
|
|
@@ -129,7 +162,7 @@ export interface StepCallModel<TContext = ContextData, _I = unknown, O = unknown
|
|
|
129
162
|
* itself is supplied as an adapter, so the set of supported agents is open.
|
|
130
163
|
* @public
|
|
131
164
|
*/
|
|
132
|
-
export interface StepAcpAgent<TContext = ContextData,
|
|
165
|
+
export interface StepAcpAgent<TContext = ContextData, I = unknown, O = unknown> extends StepReplay<TContext, I> {
|
|
133
166
|
kind: 'acp-agent';
|
|
134
167
|
id: string;
|
|
135
168
|
/**
|
|
@@ -168,7 +201,7 @@ export interface StepAcpAgent<TContext = ContextData, _I = unknown, O = unknown>
|
|
|
168
201
|
emit?: boolean | ((eventType: string, data: Record<string, unknown>) => boolean);
|
|
169
202
|
}
|
|
170
203
|
/** @public A step that invokes a single tool directly, bypassing the model. */
|
|
171
|
-
export interface StepInvokeTool<
|
|
204
|
+
export interface StepInvokeTool<TContext = ContextData, I = unknown, O = unknown> extends StepReplay<TContext, I> {
|
|
172
205
|
kind: 'invokeTool';
|
|
173
206
|
id: string;
|
|
174
207
|
tool: Tool<StandardSchemaV1<unknown, I>, StandardSchemaV1<unknown, O>>;
|
|
@@ -180,7 +213,7 @@ export interface StepInvokeTool<_TContext = ContextData, I = unknown, O = unknow
|
|
|
180
213
|
* to it, and runs no steering hooks. See spec 32.
|
|
181
214
|
* @public
|
|
182
215
|
*/
|
|
183
|
-
export interface StepDecide<TContext = ContextData,
|
|
216
|
+
export interface StepDecide<TContext = ContextData, I = unknown, O = unknown> extends StepReplay<TContext, I> {
|
|
184
217
|
kind: 'decide';
|
|
185
218
|
/** Phantom field carrying the answers type for inference. Never set at runtime. */
|
|
186
219
|
readonly _answers?: O;
|
|
@@ -216,7 +249,7 @@ export type DecideStep<TContext, I, Q extends DecideQuestions> = StepDecide<TCon
|
|
|
216
249
|
*/
|
|
217
250
|
export type DecideView = 'full' | 'layers' | 'none';
|
|
218
251
|
/** @public A step that dynamically selects and executes one of several possible sub-steps. */
|
|
219
|
-
export interface StepConditional<TContext = ContextData, I = unknown, O = unknown> {
|
|
252
|
+
export interface StepConditional<TContext = ContextData, I = unknown, O = unknown> extends StepReplay<TContext, I> {
|
|
220
253
|
kind: 'conditional';
|
|
221
254
|
id: string;
|
|
222
255
|
/**
|
|
@@ -235,7 +268,7 @@ export interface StepConditional<TContext = ContextData, I = unknown, O = unknow
|
|
|
235
268
|
/** @public Union of inParallel step variants (`race`, `all`, `settle`) for concurrent path execution. */
|
|
236
269
|
export type StepInParallel<TContext = ContextData, I = unknown, O = unknown> = StepInParallelRace<TContext, I, O> | StepInParallelAll<TContext, I, O> | StepInParallelSettle<TContext, I, O>;
|
|
237
270
|
/** @public An inParallel step that returns the result of the first path to complete. */
|
|
238
|
-
export interface StepInParallelRace<TContext = ContextData, I = unknown, O = unknown> {
|
|
271
|
+
export interface StepInParallelRace<TContext = ContextData, I = unknown, O = unknown> extends StepReplay<TContext, I> {
|
|
239
272
|
kind: 'inParallel';
|
|
240
273
|
id: string;
|
|
241
274
|
mode: 'race';
|
|
@@ -244,22 +277,22 @@ export interface StepInParallelRace<TContext = ContextData, I = unknown, O = unk
|
|
|
244
277
|
_optimizable?: Step<TContext>[];
|
|
245
278
|
}
|
|
246
279
|
/** @public An inParallel step that runs all paths and merges their results. */
|
|
247
|
-
export interface StepInParallelAll<TContext = ContextData, I = unknown, O = unknown> {
|
|
280
|
+
export interface StepInParallelAll<TContext = ContextData, I = unknown, O = unknown> extends StepReplay<TContext, I> {
|
|
248
281
|
kind: 'inParallel';
|
|
249
282
|
id: string;
|
|
250
283
|
mode: 'all';
|
|
251
284
|
paths: (input: I, ctx: Context<TContext>) => Step<TContext, I, O>[];
|
|
252
|
-
merge:
|
|
285
|
+
merge: MergeFn<TContext, O>;
|
|
253
286
|
concurrency?: number;
|
|
254
287
|
_optimizable?: Step<TContext>[];
|
|
255
288
|
}
|
|
256
289
|
/** @public An inParallel step that runs all paths and collects fulfilled/rejected outcomes. */
|
|
257
|
-
export interface StepInParallelSettle<TContext = ContextData, I = unknown, O = unknown> {
|
|
290
|
+
export interface StepInParallelSettle<TContext = ContextData, I = unknown, O = unknown> extends StepReplay<TContext, I> {
|
|
258
291
|
kind: 'inParallel';
|
|
259
292
|
id: string;
|
|
260
293
|
mode: 'settle';
|
|
261
294
|
paths: (input: I, ctx: Context<TContext>) => Step<TContext, I, O>[];
|
|
262
|
-
merge:
|
|
295
|
+
merge: MergeFn<TContext, O, SettleResult<O>>;
|
|
263
296
|
concurrency?: number;
|
|
264
297
|
_optimizable?: Step<TContext>[];
|
|
265
298
|
}
|
|
@@ -269,14 +302,14 @@ export interface StepInParallelSettle<TContext = ContextData, I = unknown, O = u
|
|
|
269
302
|
* Spawn and detachedSpawn break the inheritance chain.
|
|
270
303
|
* @public
|
|
271
304
|
*/
|
|
272
|
-
export interface StepWithContext<TContext = ContextData, I = unknown, O = unknown> {
|
|
305
|
+
export interface StepWithContext<TContext = ContextData, I = unknown, O = unknown> extends StepReplay<TContext, I> {
|
|
273
306
|
kind: 'withContext';
|
|
274
307
|
id: string;
|
|
275
308
|
child: Step<TContext, I, O>;
|
|
276
309
|
context: ContextConfig | ContextLayer[];
|
|
277
310
|
}
|
|
278
311
|
/** @public A step that launches a child execution with its own context scope. */
|
|
279
|
-
export interface StepSpawn<TContext = ContextData, I = unknown, O = unknown> {
|
|
312
|
+
export interface StepSpawn<TContext = ContextData, I = unknown, O = unknown> extends StepReplay<TContext, I> {
|
|
280
313
|
kind: 'spawn';
|
|
281
314
|
id: string;
|
|
282
315
|
child: Step<TContext, I, O>;
|
|
@@ -293,7 +326,7 @@ export interface StepSpawn<TContext = ContextData, I = unknown, O = unknown> {
|
|
|
293
326
|
* A loop step that iterates a body step until a termination predicate is satisfied.
|
|
294
327
|
* @public
|
|
295
328
|
*/
|
|
296
|
-
export interface StepLoop<TContext = ContextData, I = unknown, O = unknown> {
|
|
329
|
+
export interface StepLoop<TContext = ContextData, I = unknown, O = unknown> extends StepReplay<TContext, I> {
|
|
297
330
|
kind: 'loop';
|
|
298
331
|
/** Unique step identifier used in traces and error messages. */
|
|
299
332
|
id: string;
|
|
@@ -303,7 +336,7 @@ export interface StepLoop<TContext = ContextData, I = unknown, O = unknown> {
|
|
|
303
336
|
until: Until;
|
|
304
337
|
/** Hard safety cap on iterations (default: 1000). */
|
|
305
338
|
maxIterations?: number;
|
|
306
|
-
/** Maximum
|
|
339
|
+
/** Maximum entries kept in the snapshot history array (default: 100); oldest drop first. */
|
|
307
340
|
maxHistorySize?: number;
|
|
308
341
|
/** Optional channel for injecting messages into the loop mid-execution. */
|
|
309
342
|
inbox?: Channel<string>;
|
|
@@ -330,7 +363,7 @@ export type ScheduleErrorPolicy = 'continue' | 'fail';
|
|
|
330
363
|
*
|
|
331
364
|
* @public
|
|
332
365
|
*/
|
|
333
|
-
export interface StepSchedule<TContext = ContextData, I = unknown, O = unknown> {
|
|
366
|
+
export interface StepSchedule<TContext = ContextData, I = unknown, O = unknown> extends StepReplay<TContext, I> {
|
|
334
367
|
kind: 'schedule';
|
|
335
368
|
/** Unique step identifier used in traces and error messages. */
|
|
336
369
|
id: string;
|
|
@@ -33,5 +33,23 @@ export declare function createMessage(text: string, role: 'user' | 'developer'):
|
|
|
33
33
|
export declare function extractAssistantText(items: ReadonlyArray<Item>): string;
|
|
34
34
|
/** Naive token estimate: ~4 chars per token */
|
|
35
35
|
export declare function estimateTokens(text: string): number;
|
|
36
|
-
/**
|
|
36
|
+
/** @public One unit of spend to charge to a context: a model call, or any other billed work. */
|
|
37
|
+
export interface UsageCharge {
|
|
38
|
+
inputTokens: number;
|
|
39
|
+
outputTokens: number;
|
|
40
|
+
cachedTokens?: number;
|
|
41
|
+
/** USD. */
|
|
42
|
+
cost?: number;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* @public Charge `charge` to `ctx` and to every ancestor on its `usageParent`
|
|
46
|
+
* chain. Charging at the moment of spend — rather than merging a child's
|
|
47
|
+
* totals into its parent when the child settles — is what keeps spend from a
|
|
48
|
+
* failed spawn, a fork path, or an abandoned `race` loser from being lost, and
|
|
49
|
+
* lets `until.maxCost` / `checkBudget` on an ancestor see siblings' spend live.
|
|
50
|
+
* Use this, not direct writes to `ctx.cost`, for any billed work outside a
|
|
51
|
+
* model call; a direct write stays on that one context.
|
|
52
|
+
*/
|
|
53
|
+
export declare function recordUsage(ctx: Context, charge: UsageCharge): void;
|
|
54
|
+
/** Accumulate token usage and cost from an LLM response onto a context and its usage ancestors. */
|
|
37
55
|
export declare function trackUsage(ctx: Context, response: LLMResponse): void;
|
|
@@ -90,23 +90,50 @@ export function extractAssistantText(items) {
|
|
|
90
90
|
export function estimateTokens(text) {
|
|
91
91
|
return Math.ceil(text.length / 4);
|
|
92
92
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
ctx.tokens.input += response.usage.inputTokens;
|
|
99
|
-
ctx.tokens.output += response.usage.outputTokens;
|
|
100
|
-
ctx.tokens.total += response.usage.inputTokens + response.usage.outputTokens;
|
|
101
|
-
// Only write `cached` when the response actually carried a figure. Defaulting
|
|
93
|
+
function addCharge(ctx, charge) {
|
|
94
|
+
ctx.tokens.input += charge.inputTokens;
|
|
95
|
+
ctx.tokens.output += charge.outputTokens;
|
|
96
|
+
ctx.tokens.total += charge.inputTokens + charge.outputTokens;
|
|
97
|
+
// Only write `cached` when the charge actually carried a figure. Defaulting
|
|
102
98
|
// a missing report to 0 would erase the `RoundUsage` invariant that
|
|
103
99
|
// `undefined` means "this provider says nothing about caching" — callers that
|
|
104
100
|
// steer on cache behaviour could no longer tell that from "nothing was
|
|
105
|
-
// cached".
|
|
106
|
-
if (
|
|
107
|
-
ctx.tokens.cached = (ctx.tokens.cached ?? 0) +
|
|
101
|
+
// cached".
|
|
102
|
+
if (charge.cachedTokens !== undefined) {
|
|
103
|
+
ctx.tokens.cached = (ctx.tokens.cached ?? 0) + charge.cachedTokens;
|
|
104
|
+
}
|
|
105
|
+
if (charge.cost) {
|
|
106
|
+
ctx.cost = ctx.cost + charge.cost;
|
|
108
107
|
}
|
|
109
|
-
|
|
110
|
-
|
|
108
|
+
}
|
|
109
|
+
function usageParentOf(ctx) {
|
|
110
|
+
return ctx.usageParent !== undefined ? ctx.usageParent : ctx.parent;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* @public Charge `charge` to `ctx` and to every ancestor on its `usageParent`
|
|
114
|
+
* chain. Charging at the moment of spend — rather than merging a child's
|
|
115
|
+
* totals into its parent when the child settles — is what keeps spend from a
|
|
116
|
+
* failed spawn, a fork path, or an abandoned `race` loser from being lost, and
|
|
117
|
+
* lets `until.maxCost` / `checkBudget` on an ancestor see siblings' spend live.
|
|
118
|
+
* Use this, not direct writes to `ctx.cost`, for any billed work outside a
|
|
119
|
+
* model call; a direct write stays on that one context.
|
|
120
|
+
*/
|
|
121
|
+
export function recordUsage(ctx, charge) {
|
|
122
|
+
// The chain is acyclic for every ContextImpl (parents are fixed at
|
|
123
|
+
// construction); the guard only protects against a hand-rolled Context.
|
|
124
|
+
const seen = new Set();
|
|
125
|
+
for (let current = ctx; current && !seen.has(current);) {
|
|
126
|
+
seen.add(current);
|
|
127
|
+
if (canTrackUsage(current)) {
|
|
128
|
+
addCharge(current, charge);
|
|
129
|
+
}
|
|
130
|
+
current = usageParentOf(current);
|
|
111
131
|
}
|
|
112
132
|
}
|
|
133
|
+
/** Accumulate token usage and cost from an LLM response onto a context and its usage ancestors. */
|
|
134
|
+
export function trackUsage(ctx, response) {
|
|
135
|
+
recordUsage(ctx, {
|
|
136
|
+
...response.usage,
|
|
137
|
+
cost: response.cost,
|
|
138
|
+
});
|
|
139
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noetic-tools/types",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Foundational type contracts and primitives shared across the Noetic framework (items, LLM config, adapters, steering, errors).",
|
|
6
6
|
"license": "Apache-2.0",
|