@noetic-tools/types 3.1.0 → 3.2.1

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.
@@ -0,0 +1,172 @@
1
+ import type { StandardSchemaV1 } from '@standard-schema/spec';
2
+ import type { Channel, ChannelHandle, ExternalChannel } from './channel.js';
3
+ import type { LLMResponse, ModelParams } from './common.js';
4
+ import type { Context, CwdState, RestoreContextOptions } from './context.js';
5
+ import type { ContextCacheConfig, ContextCacheStore } from './context-cache.js';
6
+ import type { ContextData, ContextLayer, ProjectionPolicy, StorageAdapter } from './context-layer.js';
7
+ import type { DetachedHandle } from './detached.js';
8
+ import type { FsAdapter } from './fs-adapter.js';
9
+ import type { HarnessResponse, StreamEvent, StreamingItem } from './harness-result.js';
10
+ import type { ExecuteInput, Item } from './items.js';
11
+ import type { Span, TraceExporter } from './observability.js';
12
+ import type { ShellAdapter } from './shell-adapter.js';
13
+ import type { SteeringDecision } from './steering.js';
14
+ import type { SubprocessAdapter } from './subprocess-adapter.js';
15
+ import type { Tool } from './tool.js';
16
+ export type ContextHarnessStatus = {
17
+ readonly kind: 'idle';
18
+ } | {
19
+ readonly kind: 'generating';
20
+ readonly startedAt: number;
21
+ readonly turnId: string;
22
+ } | {
23
+ readonly kind: 'aborting';
24
+ readonly turnId: string;
25
+ };
26
+ interface ContextCallModelRequestBase {
27
+ model: string;
28
+ items: ReadonlyArray<Item>;
29
+ instructions?: string;
30
+ params?: ModelParams;
31
+ outputSchema?: StandardSchemaV1;
32
+ /** Explicit non-Zod override/fallback after StandardJSONSchemaV1 conversion. */
33
+ outputJsonSchema?: Record<string, unknown>;
34
+ emit?: boolean | ((eventType: string, data: Record<string, unknown>) => boolean);
35
+ signal?: AbortSignal;
36
+ }
37
+ interface ContextCallModelRequestWithTools extends ContextCallModelRequestBase {
38
+ tools: Tool[];
39
+ ctx: Context;
40
+ layers?: ContextLayer[];
41
+ allowedToolNames?: string[];
42
+ }
43
+ interface ContextCallModelRequestWithoutTools extends ContextCallModelRequestBase {
44
+ tools?: undefined;
45
+ ctx?: undefined;
46
+ layers?: undefined;
47
+ }
48
+ export type ContextCallModelRequest = ContextCallModelRequestWithTools | ContextCallModelRequestWithoutTools;
49
+ export interface ContextDetachedSpawnOverrides {
50
+ threadId?: string;
51
+ resourceId?: string;
52
+ cwdInit?: string;
53
+ }
54
+ export interface ContextRerenderRequest {
55
+ layerId: string;
56
+ slot: number;
57
+ timing: 'immediate' | 'batched';
58
+ scope: 'self' | 'slot-after' | 'all';
59
+ }
60
+ export interface ContextAppendPipelineResult {
61
+ readonly items: Item[];
62
+ readonly rerenderRequests: ContextRerenderRequest[];
63
+ }
64
+ export interface ContextRecallLayerOutput {
65
+ layerId: string;
66
+ items: Item[];
67
+ tokenCount: number;
68
+ }
69
+ export type ContextStep<TContext = ContextData, I = unknown, O = unknown> = {
70
+ readonly kind: 'runCode';
71
+ readonly id: string;
72
+ readonly execute: (input: I, ctx: Context<TContext>) => Promise<O>;
73
+ } | {
74
+ readonly kind: 'callModel';
75
+ readonly id: string;
76
+ readonly output?: StandardSchemaV1<unknown, O>;
77
+ } | {
78
+ readonly kind: 'loop';
79
+ readonly id: string;
80
+ readonly steps: ReadonlyArray<ContextStep<TContext, I, O>>;
81
+ readonly prepareNext?: (output: O, verdict: unknown, ctx: Context<TContext>) => I;
82
+ } | {
83
+ readonly kind: string;
84
+ readonly id: string;
85
+ };
86
+ /** @public Runtime surface exposed on Context without coupling Context's definition to the runtime type module. */
87
+ export interface ContextHarness {
88
+ readonly config: {
89
+ readonly name: string;
90
+ readonly params: Record<string, unknown>;
91
+ /** Harness-wide default projection policy; a step's `projection` overrides it. */
92
+ readonly projection?: ProjectionPolicy;
93
+ /** Tuning for prompt-cache anchoring. */
94
+ readonly contextCache?: ContextCacheConfig;
95
+ };
96
+ readonly fs: FsAdapter;
97
+ readonly shell: ShellAdapter;
98
+ readonly subprocess: SubprocessAdapter;
99
+ readonly rootCwdState: CwdState;
100
+ callModel(request: ContextCallModelRequest): Promise<LLMResponse>;
101
+ execute(input: ExecuteInput, options?: unknown): Promise<void>;
102
+ getAgentResponse(scope?: unknown): Promise<HarnessResponse>;
103
+ getItemStream(scope?: unknown): AsyncIterable<StreamingItem>;
104
+ getTextStream(scope?: unknown): AsyncIterable<string>;
105
+ getReasoningStream(scope?: unknown): AsyncIterable<string>;
106
+ getFullStream(scope?: unknown): AsyncIterable<StreamEvent>;
107
+ run<I, O>(step: ContextStep<ContextData, I, O>, input: I, ctx: Context): Promise<O>;
108
+ detachedSpawn<I, O>(step: unknown, input: I, parentCtx: Context, overrides?: ContextDetachedSpawnOverrides): DetachedHandle<O>;
109
+ createContext(opts?: {
110
+ parent?: Context;
111
+ items?: Item[];
112
+ state?: unknown;
113
+ threadId?: string;
114
+ resourceId?: string;
115
+ contextLayers?: ContextLayer[];
116
+ cwdInit?: string;
117
+ }): Context;
118
+ setRootCwd(nextCwd: string): void;
119
+ getLayerState<T>(executionId: string, layerId: string): T | undefined;
120
+ setLayerState<T>(executionId: string, layerId: string, state: T): void;
121
+ beforeToolCall(layers: ContextLayer[], toolName: string, toolArgs: unknown, ctx: Context): Promise<SteeringDecision>;
122
+ afterModelCall(layers: ContextLayer[], response: LLMResponse, ctx: Context): Promise<SteeringDecision>;
123
+ runAppendPipeline(layers: ContextLayer[], items: Item[], ctx: Context): Promise<ContextAppendPipelineResult>;
124
+ /** Pinned anchor output and epoch bookkeeping for prompt-cache anchoring. Absent on a harness that predates it. */
125
+ readonly contextCache?: ContextCacheStore;
126
+ recallLayers(layers: ContextLayer[], input: string, ctx: Context): Promise<ContextRecallLayerOutput[]>;
127
+ recallLayersAtomic(layers: ContextLayer[], input: string, ctx: Context, budgets: Map<string, number>): Promise<ContextRecallLayerOutput[]>;
128
+ recallLayersEventual(layers: ContextLayer[], input: string, ctx: Context, budgets: Map<string, number>): Promise<ContextRecallLayerOutput[]>;
129
+ projectHistory(layers: ContextLayer[], items: ReadonlyArray<Item>, ctx: Context): Promise<ReadonlyArray<Item>>;
130
+ storeLayers(layers: ContextLayer[], response: LLMResponse, ctx: Context): Promise<void>;
131
+ previewRequestItems(scope?: unknown): Promise<ReadonlyArray<Item>>;
132
+ /**
133
+ * Internal-sender channel write. Resolves immediately unless the target
134
+ * queue channel is at capacity, in which case the send parks until a
135
+ * consumer frees a slot (back-pressure; default 30s timeout →
136
+ * `channel_timeout`, abort → `cancelled`).
137
+ */
138
+ send<T>(channel: Channel<T>, value: T, ctx: Context): Promise<void>;
139
+ recv<T>(channel: Channel<T>, ctx: Context, opts?: {
140
+ timeout?: number;
141
+ }): Promise<T>;
142
+ tryRecv<T>(channel: Channel<T>, ctx: Context): T | null;
143
+ getChannelHandle<T>(channel: ExternalChannel<T>, executionId: string): ChannelHandle<T>;
144
+ /** Read-side counterpart to `getChannelHandle` — see `AgentHarnessContract.getChannelStream`. */
145
+ getChannelStream<T>(channel: ExternalChannel<T>, executionId: string): AsyncIterable<T>;
146
+ initLayers(layers: ContextLayer[], ctx: Context, storage: StorageAdapter): Promise<void>;
147
+ disposeLayers(layers: ContextLayer[], ctx: Context): Promise<void>;
148
+ checkpoint(ctx: Context): Promise<void>;
149
+ restore(executionId: string, opts?: RestoreContextOptions): Promise<Context | null>;
150
+ /**
151
+ * Cancel an execution: abort `ctx` and every live descendant context, then
152
+ * run context-layer teardown (`onComplete` with `outcome: 'aborted'`, then
153
+ * `dispose`) bottom-up. A no-op on an already-cancelled context.
154
+ */
155
+ cancel(ctx: Context, reason?: string): Promise<void>;
156
+ /** Trace exporter spans are flushed to. Defaults to a no-op exporter. */
157
+ readonly traceExporter: TraceExporter;
158
+ createSpan(name: string, parent: Span | null): Span;
159
+ abort(scope?: unknown): Promise<void>;
160
+ getStatus(scope?: unknown): ContextHarnessStatus;
161
+ getQueueSize(scope?: unknown): number;
162
+ /** Cumulative token usage and cost a session has accumulated across its turns. */
163
+ getUsage(scope?: unknown): {
164
+ readonly inputTokens: number;
165
+ readonly outputTokens: number;
166
+ readonly cachedTokens?: number;
167
+ readonly cost?: number;
168
+ };
169
+ seedSessionHistory(threadId: string, items: ReadonlyArray<Item>): void;
170
+ executeRerender(requests: ContextRerenderRequest[], layers: ContextLayer[], ctx: Context, budgets: Map<string, number>, query?: string): Promise<ContextRecallLayerOutput[]>;
171
+ }
172
+ export {};
@@ -1,18 +1,13 @@
1
- import type { ZodType } from 'zod';
2
1
  import type { ItemSchemaRegistry } from '../schemas/item.js';
3
- import type { Channel, ChannelHandle, ExternalChannel } from './channel.js';
4
- import type { LLMResponse, ModelParams, StepMeta, TokenUsage } from './common.js';
5
- import type { ContextCacheConfig, ContextCacheStore } from './context-cache.js';
6
- import type { ContextData, ContextLayer, ProjectionPolicy, StorageAdapter } from './context-layer.js';
2
+ import type { Channel } from './channel.js';
3
+ import type { StepMeta, TokenUsage } from './common.js';
4
+ import type { ContextHarness } from './context-harness.js';
5
+ import type { ContextData, ContextLayer } from './context-layer.js';
7
6
  import type { ItemLog } from './context-parts/item-log.js';
8
7
  import type { LastLayerUsage } from './context-parts/layer-usage.js';
9
- import type { DetachedHandle } from './detached.js';
10
8
  import type { FsAdapter } from './fs-adapter.js';
11
- import type { HarnessResponse, StreamEvent, StreamingItem } from './harness-result.js';
12
- import type { ExecuteInput } from './items.js';
13
- import type { Span, TraceExporter } from './observability.js';
9
+ import type { Span } from './observability.js';
14
10
  import type { ShellAdapter } from './shell-adapter.js';
15
- import type { SteeringDecision } from './steering.js';
16
11
  import type { SubprocessAdapter } from './subprocess-adapter.js';
17
12
  import type { Tool } from './tool.js';
18
13
  /**
@@ -26,42 +21,6 @@ export interface CwdState {
26
21
  cwd: string;
27
22
  previousCwd?: string;
28
23
  }
29
- export type ContextHarnessStatus = {
30
- readonly kind: 'idle';
31
- } | {
32
- readonly kind: 'generating';
33
- readonly startedAt: number;
34
- readonly turnId: string;
35
- } | {
36
- readonly kind: 'aborting';
37
- readonly turnId: string;
38
- };
39
- interface ContextCallModelRequestBase {
40
- model: string;
41
- items: ReadonlyArray<import('./items.js').Item>;
42
- instructions?: string;
43
- params?: ModelParams;
44
- outputSchema?: ZodType;
45
- emit?: boolean | ((eventType: string, data: Record<string, unknown>) => boolean);
46
- signal?: AbortSignal;
47
- }
48
- interface ContextCallModelRequestWithTools extends ContextCallModelRequestBase {
49
- tools: Tool[];
50
- ctx: Context;
51
- layers?: ContextLayer[];
52
- allowedToolNames?: string[];
53
- }
54
- interface ContextCallModelRequestWithoutTools extends ContextCallModelRequestBase {
55
- tools?: undefined;
56
- ctx?: undefined;
57
- layers?: undefined;
58
- }
59
- export type ContextCallModelRequest = ContextCallModelRequestWithTools | ContextCallModelRequestWithoutTools;
60
- export interface ContextDetachedSpawnOverrides {
61
- threadId?: string;
62
- resourceId?: string;
63
- cwdInit?: string;
64
- }
65
24
  /**
66
25
  * @public Caller-supplied wiring forwarded to the `createContext` call that
67
26
  * `harness.restore()` makes internally.
@@ -86,122 +45,7 @@ export interface RestoreContextOptions {
86
45
  /** Opaque per-execution state, same as `createContext({ state })`. */
87
46
  state?: unknown;
88
47
  /** Context layers for the restored context. Defaults to the harness's configured layers. */
89
- context?: ContextLayer[];
90
- /** @deprecated Renamed to `context`. */
91
- memory?: ContextLayer[];
92
- }
93
- export interface ContextRerenderRequest {
94
- layerId: string;
95
- slot: number;
96
- timing: 'immediate' | 'batched';
97
- scope: 'self' | 'slot-after' | 'all';
98
- }
99
- export interface ContextAppendPipelineResult {
100
- readonly items: import('./items.js').Item[];
101
- readonly rerenderRequests: ContextRerenderRequest[];
102
- }
103
- export interface ContextRecallLayerOutput {
104
- layerId: string;
105
- items: import('./items.js').Item[];
106
- tokenCount: number;
107
- }
108
- export type ContextStep<TContext = ContextData, I = unknown, O = unknown> = {
109
- readonly kind: 'run';
110
- readonly id: string;
111
- readonly execute: (input: I, ctx: Context<TContext>) => Promise<O>;
112
- } | {
113
- readonly kind: 'llm';
114
- readonly id: string;
115
- readonly output?: ZodType<O>;
116
- } | {
117
- readonly kind: 'loop';
118
- readonly id: string;
119
- readonly steps: ReadonlyArray<ContextStep<TContext, I, O>>;
120
- readonly prepareNext?: (output: O, verdict: unknown, ctx: Context<TContext>) => I;
121
- } | {
122
- readonly kind: string;
123
- readonly id: string;
124
- };
125
- /** @public Runtime surface exposed on Context without coupling Context's definition to the runtime type module. */
126
- export interface ContextHarness {
127
- readonly config: {
128
- readonly name: string;
129
- readonly params: Record<string, unknown>;
130
- /** Harness-wide default projection policy; a step's `projection` overrides it. */
131
- readonly projection?: ProjectionPolicy;
132
- /** Tuning for prompt-cache anchoring. */
133
- readonly contextCache?: ContextCacheConfig;
134
- };
135
- readonly fs: FsAdapter;
136
- readonly shell: ShellAdapter;
137
- readonly subprocess: SubprocessAdapter;
138
- readonly rootCwdState: CwdState;
139
- callModel(request: ContextCallModelRequest): Promise<LLMResponse>;
140
- execute(input: ExecuteInput, options?: unknown): Promise<void>;
141
- getAgentResponse(scope?: unknown): Promise<HarnessResponse>;
142
- getItemStream(scope?: unknown): AsyncIterable<StreamingItem>;
143
- getTextStream(scope?: unknown): AsyncIterable<string>;
144
- getReasoningStream(scope?: unknown): AsyncIterable<string>;
145
- getFullStream(scope?: unknown): AsyncIterable<StreamEvent>;
146
- run<I, O>(step: ContextStep<ContextData, I, O>, input: I, ctx: Context): Promise<O>;
147
- detachedSpawn<I, O>(step: unknown, input: I, parentCtx: Context, overrides?: ContextDetachedSpawnOverrides): DetachedHandle<O>;
148
- createContext(opts?: {
149
- parent?: Context;
150
- items?: import('./items.js').Item[];
151
- state?: unknown;
152
- threadId?: string;
153
- resourceId?: string;
154
- context?: ContextLayer[];
155
- /** @deprecated Renamed to `context`. */
156
- memory?: ContextLayer[];
157
- cwdInit?: string;
158
- }): Context;
159
- setRootCwd(nextCwd: string): void;
160
- getLayerState<T>(executionId: string, layerId: string): T | undefined;
161
- setLayerState<T>(executionId: string, layerId: string, state: T): void;
162
- beforeToolCall(layers: ContextLayer[], toolName: string, toolArgs: unknown, ctx: Context): Promise<SteeringDecision>;
163
- afterModelCall(layers: ContextLayer[], response: LLMResponse, ctx: Context): Promise<SteeringDecision>;
164
- runAppendPipeline(layers: ContextLayer[], items: import('./items.js').Item[], ctx: Context): Promise<ContextAppendPipelineResult>;
165
- /** Pinned anchor output and epoch bookkeeping for prompt-cache anchoring. Absent on a harness that predates it. */
166
- readonly contextCache?: ContextCacheStore;
167
- recallLayers(layers: ContextLayer[], input: string, ctx: Context): Promise<ContextRecallLayerOutput[]>;
168
- recallLayersAtomic(layers: ContextLayer[], input: string, ctx: Context, budgets: Map<string, number>): Promise<ContextRecallLayerOutput[]>;
169
- recallLayersEventual(layers: ContextLayer[], input: string, ctx: Context, budgets: Map<string, number>): Promise<ContextRecallLayerOutput[]>;
170
- projectHistory(layers: ContextLayer[], items: ReadonlyArray<import('./items.js').Item>, ctx: Context): Promise<ReadonlyArray<import('./items.js').Item>>;
171
- storeLayers(layers: ContextLayer[], response: LLMResponse, ctx: Context): Promise<void>;
172
- previewRequestItems(scope?: unknown): Promise<ReadonlyArray<import('./items.js').Item>>;
173
- /**
174
- * Internal-sender channel write. Resolves immediately unless the target
175
- * queue channel is at capacity, in which case the send parks until a
176
- * consumer frees a slot (back-pressure; default 30s timeout →
177
- * `channel_timeout`, abort → `cancelled`).
178
- */
179
- send<T>(channel: Channel<T>, value: T, ctx: Context): Promise<void>;
180
- recv<T>(channel: Channel<T>, ctx: Context, opts?: {
181
- timeout?: number;
182
- }): Promise<T>;
183
- tryRecv<T>(channel: Channel<T>, ctx: Context): T | null;
184
- getChannelHandle<T>(channel: ExternalChannel<T>, executionId: string): ChannelHandle<T>;
185
- /** Read-side counterpart to `getChannelHandle` — see `AgentHarnessContract.getChannelStream`. */
186
- getChannelStream<T>(channel: ExternalChannel<T>, executionId: string): AsyncIterable<T>;
187
- initLayers(layers: ContextLayer[], ctx: Context, storage: StorageAdapter): Promise<void>;
188
- disposeLayers(layers: ContextLayer[], ctx: Context): Promise<void>;
189
- checkpoint(ctx: Context): Promise<void>;
190
- restore(executionId: string, opts?: RestoreContextOptions): Promise<Context | null>;
191
- /**
192
- * Cancel an execution: abort `ctx` and every live descendant context, then
193
- * run context-layer teardown (`onComplete` with `outcome: 'aborted'`, then
194
- * `dispose`) bottom-up. A no-op on an already-cancelled context.
195
- */
196
- cancel(ctx: Context, reason?: string): Promise<void>;
197
- /** Trace exporter spans are flushed to. Defaults to a no-op exporter. */
198
- readonly traceExporter: TraceExporter;
199
- createSpan(name: string, parent: Span | null): Span;
200
- abort(scope?: unknown): Promise<void>;
201
- getStatus(scope?: unknown): ContextHarnessStatus;
202
- getQueueSize(scope?: unknown): number;
203
- seedSessionHistory(threadId: string, items: ReadonlyArray<import('./items.js').Item>): void;
204
- executeRerender(requests: ContextRerenderRequest[], layers: ContextLayer[], ctx: Context, budgets: Map<string, number>, query?: string): Promise<ContextRecallLayerOutput[]>;
48
+ contextLayers?: ContextLayer[];
205
49
  }
206
50
  /** @public Execution context threaded through every step, carrying state, metrics, and channels. */
207
51
  export interface Context<TContext = ContextData, TState = unknown> {
@@ -236,14 +80,6 @@ export interface Context<TContext = ContextData, TState = unknown> {
236
80
  readonly layers?: ContextLayer[];
237
81
  /** Layer provides keyed by layer ID. Access data/functions via `ctx.context['layerId'].prop`. */
238
82
  readonly context: TContext;
239
- /**
240
- * @deprecated Renamed to `context`. Reads through to the same object.
241
- *
242
- * Required, not optional: pre-rename code does `ctx.memory['layerId']`, and an
243
- * optional field would make that a `possibly undefined` compile error — which
244
- * is exactly the break this alias exists to prevent.
245
- */
246
- readonly memory: TContext;
247
83
  /** Unified tool set collected from all LLM steps in the step tree before execution. */
248
84
  readonly unifiedTools?: ReadonlyArray<Tool>;
249
85
  /** Runtime item schema registry active for this context. */
@@ -280,4 +116,3 @@ export interface Context<TContext = ContextData, TState = unknown> {
280
116
  */
281
117
  abort(reason?: string): void;
282
118
  }
283
- export {};
@@ -1,4 +1,5 @@
1
- import type { ZodError, ZodType } from 'zod';
1
+ import type { StandardSchemaV1 } from '@standard-schema/spec';
2
+ import type { ZodError } from 'zod';
2
3
  /** @public Discriminated union of all structured error kinds raised by the runtime. */
3
4
  export type NoeticError = {
4
5
  kind: 'step_failed';
@@ -6,17 +7,18 @@ export type NoeticError = {
6
7
  cause: Error;
7
8
  retriesExhausted: boolean;
8
9
  } | {
9
- kind: 'llm_refused';
10
+ kind: 'model_refused';
10
11
  stepId: string;
11
12
  refusal: string;
12
13
  } | {
13
- kind: 'llm_parse_error';
14
+ kind: 'model_parse_error';
14
15
  stepId: string;
15
16
  raw: string;
16
- schema: ZodType;
17
+ schema: StandardSchemaV1;
18
+ /** Real `ZodError` for Zod schemas; synthetic `custom` issues adapted from the vendor's Standard Schema issues otherwise. */
17
19
  zodError: ZodError;
18
20
  } | {
19
- kind: 'llm_rate_limit';
21
+ kind: 'model_rate_limit';
20
22
  stepId: string;
21
23
  retryAfter?: number;
22
24
  } | {
@@ -74,5 +76,6 @@ export type NoeticError = {
74
76
  kind: 'handle_evicted';
75
77
  handleId: string;
76
78
  stepId: string;
77
- gracePeriodMs: number;
79
+ /** Grace period in milliseconds. */
80
+ gracePeriod: number;
78
81
  };
@@ -30,6 +30,12 @@ export interface HarnessResponse {
30
30
  readonly usage: {
31
31
  readonly inputTokens: number;
32
32
  readonly outputTokens: number;
33
+ /**
34
+ * Prompt tokens served from the provider's cache across the turns this
35
+ * response covers. `undefined` — not `0` — while no model call has reported
36
+ * a cache figure, preserving the `RoundUsage` distinction between "nothing
37
+ * was cached" and "this provider says nothing about caching".
38
+ */
33
39
  readonly cachedTokens?: number;
34
40
  };
35
41
  readonly cost?: number;
@@ -15,7 +15,8 @@ export interface TraceExporter {
15
15
  export interface LayerTraceSpan {
16
16
  layerId: string;
17
17
  hook: 'init' | 'recall' | 'store' | 'onSpawn' | 'onReturn' | 'onComplete' | 'dispose';
18
- durationMs: number;
18
+ /** Duration in milliseconds. */
19
+ duration: number;
19
20
  status: 'ok' | 'error' | 'timeout' | 'skipped';
20
21
  budget?: {
21
22
  allocated: number;
@@ -1,8 +1,8 @@
1
1
  /**
2
- * Streaming output-dialect contracts for `step.llm`.
2
+ * Streaming output-dialect contracts for `step.callModel`.
3
3
  *
4
4
  * An `OutputCodec` is the dialect-agnostic alternative to a Zod schema in
5
- * `StepLLM.output`: instead of JSON-parsing the assistant text once at turn
5
+ * `StepCallModel.output`: instead of JSON-parsing the assistant text once at turn
6
6
  * end, a codec is fed each text delta as it streams and produces a typed
7
7
  * value when the turn finishes. OpenUI Lang is one dialect; the contract
8
8
  * lives here — next to `ContextLayer` and `SubHarness` — so `core` and
@@ -35,8 +35,8 @@ export interface OutputCodecSession<O = unknown> {
35
35
  finish(fullText: string): O;
36
36
  }
37
37
  /**
38
- * A streaming output dialect for `step.llm`. Discriminated from a Zod schema
39
- * in `StepLLM.output` by the `kind: 'codec'` tag.
38
+ * A streaming output dialect for `step.callModel`. Discriminated from a Zod schema
39
+ * in `StepCallModel.output` by the `kind: 'codec'` tag.
40
40
  * @public
41
41
  */
42
42
  export interface OutputCodec<O = unknown> {
@@ -47,7 +47,7 @@ export interface OutputCodec<O = unknown> {
47
47
  start(): OutputCodecSession<O>;
48
48
  }
49
49
  /**
50
- * Narrows a `StepLLM.output` value to an `OutputCodec`. A Zod schema has no
50
+ * Narrows a `StepCallModel.output` value to an `OutputCodec`. A Zod schema has no
51
51
  * `kind: 'codec'` tag, so the discriminant is unambiguous.
52
52
  * @public
53
53
  */
@@ -1,15 +1,15 @@
1
1
  /**
2
- * Streaming output-dialect contracts for `step.llm`.
2
+ * Streaming output-dialect contracts for `step.callModel`.
3
3
  *
4
4
  * An `OutputCodec` is the dialect-agnostic alternative to a Zod schema in
5
- * `StepLLM.output`: instead of JSON-parsing the assistant text once at turn
5
+ * `StepCallModel.output`: instead of JSON-parsing the assistant text once at turn
6
6
  * end, a codec is fed each text delta as it streams and produces a typed
7
7
  * value when the turn finishes. OpenUI Lang is one dialect; the contract
8
8
  * lives here — next to `ContextLayer` and `SubHarness` — so `core` and
9
9
  * dialect packages both depend on it without forming a cycle.
10
10
  */
11
11
  /**
12
- * Narrows a `StepLLM.output` value to an `OutputCodec`. A Zod schema has no
12
+ * Narrows a `StepCallModel.output` value to an `OutputCodec`. A Zod schema has no
13
13
  * `kind: 'codec'` tag, so the discriminant is unambiguous.
14
14
  * @public
15
15
  */
@@ -1,4 +1,4 @@
1
- import type { ZodType } from 'zod';
1
+ import type { StandardSchemaV1 } from '@standard-schema/spec';
2
2
  import type { Channel, ChannelHandle, ExternalChannel } from './channel.js';
3
3
  import type { LLMResponse, ModelParams, ServerToolSpec } from './common.js';
4
4
  import type { Context, CwdState, RestoreContextOptions } from './context.js';
@@ -19,16 +19,21 @@ export interface AgentHooks {
19
19
  beforeStep?: (step: Step, ctx: Context) => Promise<void>;
20
20
  afterStep?: (step: Step, result: unknown, ctx: Context) => Promise<void>;
21
21
  }
22
+ /** @public Item-schema configuration: extension schemas plus validation strictness. */
23
+ export interface ItemSchemaConfig {
24
+ /** Harness-wide item schema extensions used to validate emitted and returned items. */
25
+ schemas?: ItemSchemaExtensions;
26
+ /** Whether unknown extension item types must match a registered schema. Defaults to true. */
27
+ strict?: boolean;
28
+ }
22
29
  /** @public Top-level configuration object that defines an agent's model, tools, context, and behavior. */
23
30
  export interface AgentConfig<TParams extends Record<string, unknown> = Record<string, unknown>> {
24
31
  name: string;
25
32
  storage?: StorageAdapter;
26
33
  hooks?: AgentHooks;
27
34
  params: TParams;
28
- /** Harness-wide item schema extensions used to validate emitted and returned items. */
29
- itemSchemas?: ItemSchemaExtensions;
30
- /** Whether unknown extension item types must match a registered schema. Defaults to true. */
31
- strictItemSchemas?: boolean;
35
+ /** Item schema extensions and validation strictness for emitted and returned items. */
36
+ itemSchemas?: ItemSchemaConfig;
32
37
  /** Default projection policy for all LLM steps. Individual steps override via `step.projection`. */
33
38
  projection?: ProjectionPolicy;
34
39
  /** When true, every layer is recalled atomically regardless of its `recallMode` (no eventual/cached recall). */
@@ -54,7 +59,12 @@ interface CallModelRequestBase {
54
59
  instructions?: string;
55
60
  params?: ModelParams;
56
61
  /** When provided, the harness sends a JSON Schema constraint to the model so it returns structured JSON. */
57
- outputSchema?: ZodType;
62
+ outputSchema?: StandardSchemaV1;
63
+ /**
64
+ * Explicit raw JSON Schema override for the structured-output constraint.
65
+ * For non-Zod schemas, it takes precedence over StandardJSONSchemaV1 conversion.
66
+ */
67
+ outputJsonSchema?: Record<string, unknown>;
58
68
  /** Controls framework event emission. Defaults to `true`. Passed through from `StepLLM.emit`. */
59
69
  emit?: boolean | ((eventType: string, data: Record<string, unknown>) => boolean);
60
70
  /**
@@ -106,9 +116,7 @@ export interface ExecuteOptions {
106
116
  resourceId?: string;
107
117
  state?: unknown;
108
118
  /** Context layers to apply to the execution context. Overrides harness-level layers if provided. */
109
- context?: ContextLayer[];
110
- /** @deprecated Renamed to `context`. */
111
- memory?: ContextLayer[];
119
+ contextLayers?: ContextLayer[];
112
120
  /** Override the harness's default delivery mode for this message only. */
113
121
  deliveryMode?: DeliveryMode;
114
122
  /**
@@ -131,6 +139,20 @@ export type HarnessStatus = {
131
139
  readonly kind: 'aborting';
132
140
  readonly turnId: string;
133
141
  };
142
+ /** @public Cumulative token usage and cost a session has accumulated across all of its turns. */
143
+ export interface SessionUsage {
144
+ readonly inputTokens: number;
145
+ readonly outputTokens: number;
146
+ /** Undefined when no turn reported a cache figure, so callers can tell "provider says nothing about caching" from "nothing was cached". */
147
+ readonly cachedTokens?: number;
148
+ /**
149
+ * Undefined when the accumulated cost is zero. Unlike `cachedTokens` this
150
+ * cannot distinguish "no provider reported a cost" from "the work was free" —
151
+ * per-turn cost is a plain number that starts at 0, so there is no
152
+ * "unreported" signal to preserve.
153
+ */
154
+ readonly cost?: number;
155
+ }
134
156
  /** @public Identifies which session the accessor targets. All methods fall back to the harness's default thread when omitted. */
135
157
  export interface SessionScope {
136
158
  threadId?: string;
@@ -179,6 +201,12 @@ export interface AgentHarnessContract<TParams extends Record<string, unknown> =
179
201
  getStatus(scope?: SessionScope): HarnessStatus;
180
202
  /** Number of messages currently queued on a session. */
181
203
  getQueueSize(scope?: SessionScope): number;
204
+ /**
205
+ * Cumulative token usage and cost the session has accumulated across all of
206
+ * its turns, including turns that failed or were aborted after partial model
207
+ * work. Returns zeros for a session that has not run yet.
208
+ */
209
+ getUsage(scope?: SessionScope): SessionUsage;
182
210
  /**
183
211
  * Pre-populate a session's accumulated history with prior items so the next
184
212
  * `execute()` turn sees them as established context. Used by resume flows to
@@ -215,9 +243,7 @@ export interface AgentHarnessContract<TParams extends Record<string, unknown> =
215
243
  state?: unknown;
216
244
  threadId?: string;
217
245
  resourceId?: string;
218
- context?: ContextLayer[];
219
- /** @deprecated Renamed to `context`. */
220
- memory?: ContextLayer[];
246
+ contextLayers?: ContextLayer[];
221
247
  /** Override the new context's initial cwd. */
222
248
  cwdInit?: string;
223
249
  }): Context;
@@ -0,0 +1,62 @@
1
+ import type { StandardJSONSchemaV1, StandardSchemaV1 } from '@standard-schema/spec';
2
+ import type { ZodTypeAny, z } from 'zod';
3
+ import { ZodError } from 'zod';
4
+ export type { StandardJSONSchemaV1, StandardSchemaV1 } from '@standard-schema/spec';
5
+ /**
6
+ * Input type inferred from any Standard Schema. Zod schemas keep their exact
7
+ * `z.input` inference; other vendors use `StandardSchemaV1.InferInput`.
8
+ * @public
9
+ */
10
+ export type InferSchemaInput<S extends StandardSchemaV1> = S extends ZodTypeAny ? z.input<S> : StandardSchemaV1.InferInput<S>;
11
+ /**
12
+ * Output type inferred from any Standard Schema. Zod schemas keep their exact
13
+ * `z.output` inference; other vendors use `StandardSchemaV1.InferOutput`.
14
+ * @public
15
+ */
16
+ export type InferSchemaOutput<S extends StandardSchemaV1> = S extends ZodTypeAny ? z.output<S> : StandardSchemaV1.InferOutput<S>;
17
+ /**
18
+ * JSON Schema configuration for a tool input schema. Zod and Standard JSON
19
+ * Schema implementations can derive their wire schema; validation-only
20
+ * Standard Schemas require an explicit fallback.
21
+ * @public
22
+ */
23
+ export type InputSchemaConfig<S extends StandardSchemaV1> = StandardSchemaV1 extends S ? {
24
+ inputJsonSchema?: Record<string, unknown>;
25
+ } : S extends ZodTypeAny | StandardJSONSchemaV1 ? {
26
+ inputJsonSchema?: Record<string, unknown>;
27
+ } : {
28
+ inputJsonSchema: Record<string, unknown>;
29
+ };
30
+ /** @public Type guard for Zod schemas (detected via the `_zod` internals marker). */
31
+ export declare function isZodSchema(schema: StandardSchemaV1): schema is ZodTypeAny;
32
+ /** @public Type guard for schemas implementing the Standard JSON Schema v1 companion spec. */
33
+ export declare function isStandardJsonSchema(schema: StandardSchemaV1): schema is StandardSchemaV1 & StandardJSONSchemaV1;
34
+ /** @public Successful result of `validateSchema` — carries the parsed/transformed value. */
35
+ export interface SchemaValidationSuccess<T> {
36
+ success: true;
37
+ value: T;
38
+ }
39
+ /**
40
+ * Failed result of `validateSchema`. `issues` are the vendor's issues in
41
+ * Standard Schema form; `zodError` adapts them into a `ZodError` (the
42
+ * original error for Zod schemas, synthetic `custom` issues otherwise) so
43
+ * consumers like `llm_parse_error` keep a single error surface.
44
+ * @public
45
+ */
46
+ export interface SchemaValidationFailure {
47
+ success: false;
48
+ issues: readonly StandardSchemaV1.Issue[];
49
+ zodError: ZodError;
50
+ }
51
+ /** @public Result of `validateSchema`. */
52
+ export type SchemaValidationResult<T> = SchemaValidationSuccess<T> | SchemaValidationFailure;
53
+ /** @public Adapt Standard Schema issues into a synthetic `ZodError` of `custom` issues. */
54
+ export declare function standardIssuesToZodError(issues: readonly StandardSchemaV1.Issue[]): ZodError;
55
+ /**
56
+ * Validates a value against any Standard Schema. Zod schemas take the
57
+ * `safeParse` fast path; other vendors run `schema['~standard'].validate`,
58
+ * awaiting sync or Promise results. The returned success value is the
59
+ * parsed/transformed output.
60
+ * @public
61
+ */
62
+ export declare function validateSchema<S extends StandardSchemaV1>(schema: S, value: unknown): Promise<SchemaValidationResult<InferSchemaOutput<S>>>;