@noetic-tools/types 3.2.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.
- package/README.md +3 -3
- package/dist/errors/noetic-error.js +7 -7
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/schemas/workflow.d.ts +39 -36
- package/dist/schemas/workflow.js +42 -38
- package/dist/types/common.d.ts +6 -0
- package/dist/types/context-harness.d.ts +172 -0
- package/dist/types/context.d.ts +6 -173
- package/dist/types/error.d.ts +5 -4
- package/dist/types/harness-result.d.ts +6 -0
- package/dist/types/observability.d.ts +2 -1
- package/dist/types/output-codec.d.ts +5 -5
- package/dist/types/output-codec.js +3 -3
- package/dist/types/runtime.d.ts +31 -10
- package/dist/types/steering.d.ts +2 -1
- package/dist/types/step.d.ts +36 -35
- package/dist/types/tool-context.d.ts +0 -7
- package/dist/util/message-helpers.js +8 -1
- package/package.json +1 -1
- package/dist/deprecated.d.ts +0 -39
- /package/dist/{deprecated.js → types/context-harness.js} +0 -0
|
@@ -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 {};
|
package/dist/types/context.d.ts
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
1
|
import type { ItemSchemaRegistry } from '../schemas/item.js';
|
|
3
|
-
import type { Channel
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
6
|
-
import type { ContextData, ContextLayer
|
|
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 {
|
|
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,44 +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?: StandardSchemaV1;
|
|
45
|
-
/** Explicit non-Zod override/fallback after StandardJSONSchemaV1 conversion. */
|
|
46
|
-
outputJsonSchema?: Record<string, unknown>;
|
|
47
|
-
emit?: boolean | ((eventType: string, data: Record<string, unknown>) => boolean);
|
|
48
|
-
signal?: AbortSignal;
|
|
49
|
-
}
|
|
50
|
-
interface ContextCallModelRequestWithTools extends ContextCallModelRequestBase {
|
|
51
|
-
tools: Tool[];
|
|
52
|
-
ctx: Context;
|
|
53
|
-
layers?: ContextLayer[];
|
|
54
|
-
allowedToolNames?: string[];
|
|
55
|
-
}
|
|
56
|
-
interface ContextCallModelRequestWithoutTools extends ContextCallModelRequestBase {
|
|
57
|
-
tools?: undefined;
|
|
58
|
-
ctx?: undefined;
|
|
59
|
-
layers?: undefined;
|
|
60
|
-
}
|
|
61
|
-
export type ContextCallModelRequest = ContextCallModelRequestWithTools | ContextCallModelRequestWithoutTools;
|
|
62
|
-
export interface ContextDetachedSpawnOverrides {
|
|
63
|
-
threadId?: string;
|
|
64
|
-
resourceId?: string;
|
|
65
|
-
cwdInit?: string;
|
|
66
|
-
}
|
|
67
24
|
/**
|
|
68
25
|
* @public Caller-supplied wiring forwarded to the `createContext` call that
|
|
69
26
|
* `harness.restore()` makes internally.
|
|
@@ -88,122 +45,7 @@ export interface RestoreContextOptions {
|
|
|
88
45
|
/** Opaque per-execution state, same as `createContext({ state })`. */
|
|
89
46
|
state?: unknown;
|
|
90
47
|
/** Context layers for the restored context. Defaults to the harness's configured layers. */
|
|
91
|
-
|
|
92
|
-
/** @deprecated Renamed to `context`. */
|
|
93
|
-
memory?: ContextLayer[];
|
|
94
|
-
}
|
|
95
|
-
export interface ContextRerenderRequest {
|
|
96
|
-
layerId: string;
|
|
97
|
-
slot: number;
|
|
98
|
-
timing: 'immediate' | 'batched';
|
|
99
|
-
scope: 'self' | 'slot-after' | 'all';
|
|
100
|
-
}
|
|
101
|
-
export interface ContextAppendPipelineResult {
|
|
102
|
-
readonly items: import('./items.js').Item[];
|
|
103
|
-
readonly rerenderRequests: ContextRerenderRequest[];
|
|
104
|
-
}
|
|
105
|
-
export interface ContextRecallLayerOutput {
|
|
106
|
-
layerId: string;
|
|
107
|
-
items: import('./items.js').Item[];
|
|
108
|
-
tokenCount: number;
|
|
109
|
-
}
|
|
110
|
-
export type ContextStep<TContext = ContextData, I = unknown, O = unknown> = {
|
|
111
|
-
readonly kind: 'run';
|
|
112
|
-
readonly id: string;
|
|
113
|
-
readonly execute: (input: I, ctx: Context<TContext>) => Promise<O>;
|
|
114
|
-
} | {
|
|
115
|
-
readonly kind: 'llm';
|
|
116
|
-
readonly id: string;
|
|
117
|
-
readonly output?: StandardSchemaV1<unknown, O>;
|
|
118
|
-
} | {
|
|
119
|
-
readonly kind: 'loop';
|
|
120
|
-
readonly id: string;
|
|
121
|
-
readonly steps: ReadonlyArray<ContextStep<TContext, I, O>>;
|
|
122
|
-
readonly prepareNext?: (output: O, verdict: unknown, ctx: Context<TContext>) => I;
|
|
123
|
-
} | {
|
|
124
|
-
readonly kind: string;
|
|
125
|
-
readonly id: string;
|
|
126
|
-
};
|
|
127
|
-
/** @public Runtime surface exposed on Context without coupling Context's definition to the runtime type module. */
|
|
128
|
-
export interface ContextHarness {
|
|
129
|
-
readonly config: {
|
|
130
|
-
readonly name: string;
|
|
131
|
-
readonly params: Record<string, unknown>;
|
|
132
|
-
/** Harness-wide default projection policy; a step's `projection` overrides it. */
|
|
133
|
-
readonly projection?: ProjectionPolicy;
|
|
134
|
-
/** Tuning for prompt-cache anchoring. */
|
|
135
|
-
readonly contextCache?: ContextCacheConfig;
|
|
136
|
-
};
|
|
137
|
-
readonly fs: FsAdapter;
|
|
138
|
-
readonly shell: ShellAdapter;
|
|
139
|
-
readonly subprocess: SubprocessAdapter;
|
|
140
|
-
readonly rootCwdState: CwdState;
|
|
141
|
-
callModel(request: ContextCallModelRequest): Promise<LLMResponse>;
|
|
142
|
-
execute(input: ExecuteInput, options?: unknown): Promise<void>;
|
|
143
|
-
getAgentResponse(scope?: unknown): Promise<HarnessResponse>;
|
|
144
|
-
getItemStream(scope?: unknown): AsyncIterable<StreamingItem>;
|
|
145
|
-
getTextStream(scope?: unknown): AsyncIterable<string>;
|
|
146
|
-
getReasoningStream(scope?: unknown): AsyncIterable<string>;
|
|
147
|
-
getFullStream(scope?: unknown): AsyncIterable<StreamEvent>;
|
|
148
|
-
run<I, O>(step: ContextStep<ContextData, I, O>, input: I, ctx: Context): Promise<O>;
|
|
149
|
-
detachedSpawn<I, O>(step: unknown, input: I, parentCtx: Context, overrides?: ContextDetachedSpawnOverrides): DetachedHandle<O>;
|
|
150
|
-
createContext(opts?: {
|
|
151
|
-
parent?: Context;
|
|
152
|
-
items?: import('./items.js').Item[];
|
|
153
|
-
state?: unknown;
|
|
154
|
-
threadId?: string;
|
|
155
|
-
resourceId?: string;
|
|
156
|
-
context?: ContextLayer[];
|
|
157
|
-
/** @deprecated Renamed to `context`. */
|
|
158
|
-
memory?: ContextLayer[];
|
|
159
|
-
cwdInit?: string;
|
|
160
|
-
}): Context;
|
|
161
|
-
setRootCwd(nextCwd: string): void;
|
|
162
|
-
getLayerState<T>(executionId: string, layerId: string): T | undefined;
|
|
163
|
-
setLayerState<T>(executionId: string, layerId: string, state: T): void;
|
|
164
|
-
beforeToolCall(layers: ContextLayer[], toolName: string, toolArgs: unknown, ctx: Context): Promise<SteeringDecision>;
|
|
165
|
-
afterModelCall(layers: ContextLayer[], response: LLMResponse, ctx: Context): Promise<SteeringDecision>;
|
|
166
|
-
runAppendPipeline(layers: ContextLayer[], items: import('./items.js').Item[], ctx: Context): Promise<ContextAppendPipelineResult>;
|
|
167
|
-
/** Pinned anchor output and epoch bookkeeping for prompt-cache anchoring. Absent on a harness that predates it. */
|
|
168
|
-
readonly contextCache?: ContextCacheStore;
|
|
169
|
-
recallLayers(layers: ContextLayer[], input: string, ctx: Context): Promise<ContextRecallLayerOutput[]>;
|
|
170
|
-
recallLayersAtomic(layers: ContextLayer[], input: string, ctx: Context, budgets: Map<string, number>): Promise<ContextRecallLayerOutput[]>;
|
|
171
|
-
recallLayersEventual(layers: ContextLayer[], input: string, ctx: Context, budgets: Map<string, number>): Promise<ContextRecallLayerOutput[]>;
|
|
172
|
-
projectHistory(layers: ContextLayer[], items: ReadonlyArray<import('./items.js').Item>, ctx: Context): Promise<ReadonlyArray<import('./items.js').Item>>;
|
|
173
|
-
storeLayers(layers: ContextLayer[], response: LLMResponse, ctx: Context): Promise<void>;
|
|
174
|
-
previewRequestItems(scope?: unknown): Promise<ReadonlyArray<import('./items.js').Item>>;
|
|
175
|
-
/**
|
|
176
|
-
* Internal-sender channel write. Resolves immediately unless the target
|
|
177
|
-
* queue channel is at capacity, in which case the send parks until a
|
|
178
|
-
* consumer frees a slot (back-pressure; default 30s timeout →
|
|
179
|
-
* `channel_timeout`, abort → `cancelled`).
|
|
180
|
-
*/
|
|
181
|
-
send<T>(channel: Channel<T>, value: T, ctx: Context): Promise<void>;
|
|
182
|
-
recv<T>(channel: Channel<T>, ctx: Context, opts?: {
|
|
183
|
-
timeout?: number;
|
|
184
|
-
}): Promise<T>;
|
|
185
|
-
tryRecv<T>(channel: Channel<T>, ctx: Context): T | null;
|
|
186
|
-
getChannelHandle<T>(channel: ExternalChannel<T>, executionId: string): ChannelHandle<T>;
|
|
187
|
-
/** Read-side counterpart to `getChannelHandle` — see `AgentHarnessContract.getChannelStream`. */
|
|
188
|
-
getChannelStream<T>(channel: ExternalChannel<T>, executionId: string): AsyncIterable<T>;
|
|
189
|
-
initLayers(layers: ContextLayer[], ctx: Context, storage: StorageAdapter): Promise<void>;
|
|
190
|
-
disposeLayers(layers: ContextLayer[], ctx: Context): Promise<void>;
|
|
191
|
-
checkpoint(ctx: Context): Promise<void>;
|
|
192
|
-
restore(executionId: string, opts?: RestoreContextOptions): Promise<Context | null>;
|
|
193
|
-
/**
|
|
194
|
-
* Cancel an execution: abort `ctx` and every live descendant context, then
|
|
195
|
-
* run context-layer teardown (`onComplete` with `outcome: 'aborted'`, then
|
|
196
|
-
* `dispose`) bottom-up. A no-op on an already-cancelled context.
|
|
197
|
-
*/
|
|
198
|
-
cancel(ctx: Context, reason?: string): Promise<void>;
|
|
199
|
-
/** Trace exporter spans are flushed to. Defaults to a no-op exporter. */
|
|
200
|
-
readonly traceExporter: TraceExporter;
|
|
201
|
-
createSpan(name: string, parent: Span | null): Span;
|
|
202
|
-
abort(scope?: unknown): Promise<void>;
|
|
203
|
-
getStatus(scope?: unknown): ContextHarnessStatus;
|
|
204
|
-
getQueueSize(scope?: unknown): number;
|
|
205
|
-
seedSessionHistory(threadId: string, items: ReadonlyArray<import('./items.js').Item>): void;
|
|
206
|
-
executeRerender(requests: ContextRerenderRequest[], layers: ContextLayer[], ctx: Context, budgets: Map<string, number>, query?: string): Promise<ContextRecallLayerOutput[]>;
|
|
48
|
+
contextLayers?: ContextLayer[];
|
|
207
49
|
}
|
|
208
50
|
/** @public Execution context threaded through every step, carrying state, metrics, and channels. */
|
|
209
51
|
export interface Context<TContext = ContextData, TState = unknown> {
|
|
@@ -238,14 +80,6 @@ export interface Context<TContext = ContextData, TState = unknown> {
|
|
|
238
80
|
readonly layers?: ContextLayer[];
|
|
239
81
|
/** Layer provides keyed by layer ID. Access data/functions via `ctx.context['layerId'].prop`. */
|
|
240
82
|
readonly context: TContext;
|
|
241
|
-
/**
|
|
242
|
-
* @deprecated Renamed to `context`. Reads through to the same object.
|
|
243
|
-
*
|
|
244
|
-
* Required, not optional: pre-rename code does `ctx.memory['layerId']`, and an
|
|
245
|
-
* optional field would make that a `possibly undefined` compile error — which
|
|
246
|
-
* is exactly the break this alias exists to prevent.
|
|
247
|
-
*/
|
|
248
|
-
readonly memory: TContext;
|
|
249
83
|
/** Unified tool set collected from all LLM steps in the step tree before execution. */
|
|
250
84
|
readonly unifiedTools?: ReadonlyArray<Tool>;
|
|
251
85
|
/** Runtime item schema registry active for this context. */
|
|
@@ -282,4 +116,3 @@ export interface Context<TContext = ContextData, TState = unknown> {
|
|
|
282
116
|
*/
|
|
283
117
|
abort(reason?: string): void;
|
|
284
118
|
}
|
|
285
|
-
export {};
|
package/dist/types/error.d.ts
CHANGED
|
@@ -7,18 +7,18 @@ export type NoeticError = {
|
|
|
7
7
|
cause: Error;
|
|
8
8
|
retriesExhausted: boolean;
|
|
9
9
|
} | {
|
|
10
|
-
kind: '
|
|
10
|
+
kind: 'model_refused';
|
|
11
11
|
stepId: string;
|
|
12
12
|
refusal: string;
|
|
13
13
|
} | {
|
|
14
|
-
kind: '
|
|
14
|
+
kind: 'model_parse_error';
|
|
15
15
|
stepId: string;
|
|
16
16
|
raw: string;
|
|
17
17
|
schema: StandardSchemaV1;
|
|
18
18
|
/** Real `ZodError` for Zod schemas; synthetic `custom` issues adapted from the vendor's Standard Schema issues otherwise. */
|
|
19
19
|
zodError: ZodError;
|
|
20
20
|
} | {
|
|
21
|
-
kind: '
|
|
21
|
+
kind: 'model_rate_limit';
|
|
22
22
|
stepId: string;
|
|
23
23
|
retryAfter?: number;
|
|
24
24
|
} | {
|
|
@@ -76,5 +76,6 @@ export type NoeticError = {
|
|
|
76
76
|
kind: 'handle_evicted';
|
|
77
77
|
handleId: string;
|
|
78
78
|
stepId: string;
|
|
79
|
-
|
|
79
|
+
/** Grace period in milliseconds. */
|
|
80
|
+
gracePeriod: number;
|
|
80
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
|
-
|
|
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.
|
|
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
|
-
* `
|
|
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.
|
|
39
|
-
* in `
|
|
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 `
|
|
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.
|
|
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
|
-
* `
|
|
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 `
|
|
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
|
*/
|
package/dist/types/runtime.d.ts
CHANGED
|
@@ -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
|
-
/**
|
|
29
|
-
itemSchemas?:
|
|
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). */
|
|
@@ -111,9 +116,7 @@ export interface ExecuteOptions {
|
|
|
111
116
|
resourceId?: string;
|
|
112
117
|
state?: unknown;
|
|
113
118
|
/** Context layers to apply to the execution context. Overrides harness-level layers if provided. */
|
|
114
|
-
|
|
115
|
-
/** @deprecated Renamed to `context`. */
|
|
116
|
-
memory?: ContextLayer[];
|
|
119
|
+
contextLayers?: ContextLayer[];
|
|
117
120
|
/** Override the harness's default delivery mode for this message only. */
|
|
118
121
|
deliveryMode?: DeliveryMode;
|
|
119
122
|
/**
|
|
@@ -136,6 +139,20 @@ export type HarnessStatus = {
|
|
|
136
139
|
readonly kind: 'aborting';
|
|
137
140
|
readonly turnId: string;
|
|
138
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
|
+
}
|
|
139
156
|
/** @public Identifies which session the accessor targets. All methods fall back to the harness's default thread when omitted. */
|
|
140
157
|
export interface SessionScope {
|
|
141
158
|
threadId?: string;
|
|
@@ -184,6 +201,12 @@ export interface AgentHarnessContract<TParams extends Record<string, unknown> =
|
|
|
184
201
|
getStatus(scope?: SessionScope): HarnessStatus;
|
|
185
202
|
/** Number of messages currently queued on a session. */
|
|
186
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;
|
|
187
210
|
/**
|
|
188
211
|
* Pre-populate a session's accumulated history with prior items so the next
|
|
189
212
|
* `execute()` turn sees them as established context. Used by resume flows to
|
|
@@ -220,9 +243,7 @@ export interface AgentHarnessContract<TParams extends Record<string, unknown> =
|
|
|
220
243
|
state?: unknown;
|
|
221
244
|
threadId?: string;
|
|
222
245
|
resourceId?: string;
|
|
223
|
-
|
|
224
|
-
/** @deprecated Renamed to `context`. */
|
|
225
|
-
memory?: ContextLayer[];
|
|
246
|
+
contextLayers?: ContextLayer[];
|
|
226
247
|
/** Override the new context's initial cwd. */
|
|
227
248
|
cwdInit?: string;
|
|
228
249
|
}): Context;
|
package/dist/types/steering.d.ts
CHANGED