@noetic-tools/types 2.1.1 → 2.3.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/deprecated.d.ts +39 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +4 -2
- package/dist/schemas/item.d.ts +1 -1
- package/dist/schemas/item.js +1 -1
- package/dist/schemas/workflow.d.ts +297 -0
- package/dist/schemas/workflow.js +401 -0
- package/dist/types/{memory.d.ts → context-layer.d.ts} +50 -50
- package/dist/types/{memory.js → context-layer.js} +1 -1
- package/dist/types/{memory-context.d.ts → context-scope.d.ts} +8 -8
- package/dist/types/context-scope.js +1 -0
- package/dist/types/context.d.ts +40 -28
- package/dist/types/harness-result.d.ts +1 -1
- package/dist/types/items.d.ts +3 -3
- package/dist/types/observability.d.ts +2 -2
- package/dist/types/output-codec.d.ts +1 -1
- package/dist/types/output-codec.js +1 -1
- package/dist/types/runtime.d.ts +28 -24
- package/dist/types/steering.d.ts +2 -2
- package/dist/types/step.d.ts +44 -44
- package/dist/types/sub-harness.d.ts +1 -1
- package/dist/types/sub-harness.js +1 -1
- package/dist/types/tool-context.d.ts +10 -3
- package/dist/types/tool.d.ts +8 -8
- package/dist/util/message-helpers.d.ts +2 -2
- package/dist/util/message-helpers.js +2 -2
- package/package.json +3 -3
- /package/dist/{types/memory-context.js → deprecated.js} +0 -0
package/dist/types/runtime.d.ts
CHANGED
|
@@ -2,11 +2,11 @@ import type { ZodType } from 'zod';
|
|
|
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';
|
|
5
|
+
import type { ContextData, ContextLayer, ProjectionPolicy, StorageAdapter } from './context-layer.js';
|
|
5
6
|
import type { DetachedHandle } from './detached.js';
|
|
6
7
|
import type { FsAdapter } from './fs-adapter.js';
|
|
7
8
|
import type { HarnessResponse, StreamEvent, StreamingItem } from './harness-result.js';
|
|
8
9
|
import type { ExecuteInput, Item, ItemSchemaExtensions } from './items.js';
|
|
9
|
-
import type { ContextMemory, MemoryLayer, ProjectionPolicy, StorageAdapter } from './memory.js';
|
|
10
10
|
import type { Span, TraceExporter } from './observability.js';
|
|
11
11
|
import type { ShellAdapter } from './shell-adapter.js';
|
|
12
12
|
import type { SteeringDecision } from './steering.js';
|
|
@@ -18,7 +18,7 @@ export interface AgentHooks {
|
|
|
18
18
|
beforeStep?: (step: Step, ctx: Context) => Promise<void>;
|
|
19
19
|
afterStep?: (step: Step, result: unknown, ctx: Context) => Promise<void>;
|
|
20
20
|
}
|
|
21
|
-
/** @public Top-level configuration object that defines an agent's model, tools,
|
|
21
|
+
/** @public Top-level configuration object that defines an agent's model, tools, context, and behavior. */
|
|
22
22
|
export interface AgentConfig<TParams extends Record<string, unknown> = Record<string, unknown>> {
|
|
23
23
|
name: string;
|
|
24
24
|
storage?: StorageAdapter;
|
|
@@ -84,7 +84,7 @@ interface CallModelRequestBase {
|
|
|
84
84
|
interface CallModelRequestWithTools extends CallModelRequestBase {
|
|
85
85
|
tools: Tool[];
|
|
86
86
|
ctx: Context;
|
|
87
|
-
layers?:
|
|
87
|
+
layers?: ContextLayer[];
|
|
88
88
|
/** When set, restricts which tools the model may invoke for this call. */
|
|
89
89
|
allowedToolNames?: string[];
|
|
90
90
|
}
|
|
@@ -102,8 +102,10 @@ export interface ExecuteOptions {
|
|
|
102
102
|
threadId?: string;
|
|
103
103
|
resourceId?: string;
|
|
104
104
|
state?: unknown;
|
|
105
|
-
/**
|
|
106
|
-
|
|
105
|
+
/** Context layers to apply to the execution context. Overrides harness-level layers if provided. */
|
|
106
|
+
context?: ContextLayer[];
|
|
107
|
+
/** @deprecated Renamed to `context`. */
|
|
108
|
+
memory?: ContextLayer[];
|
|
107
109
|
/** Override the harness's default delivery mode for this message only. */
|
|
108
110
|
deliveryMode?: DeliveryMode;
|
|
109
111
|
/**
|
|
@@ -130,7 +132,7 @@ export type HarnessStatus = {
|
|
|
130
132
|
export interface SessionScope {
|
|
131
133
|
threadId?: string;
|
|
132
134
|
}
|
|
133
|
-
/** @public Type-level contract for the agent runtime. Used for type annotations throughout the interpreter,
|
|
135
|
+
/** @public Type-level contract for the agent runtime. Used for type annotations throughout the interpreter, context layers, and context. Implemented by `AgentHarness`. */
|
|
134
136
|
export interface AgentHarnessContract<TParams extends Record<string, unknown> = Record<string, unknown>> {
|
|
135
137
|
readonly config: AgentConfig<TParams>;
|
|
136
138
|
/** Filesystem adapter for virtual or real filesystem access. */
|
|
@@ -182,7 +184,7 @@ export interface AgentHarnessContract<TParams extends Record<string, unknown> =
|
|
|
182
184
|
* already exist. Replaces any previously-accumulated items for the session.
|
|
183
185
|
*/
|
|
184
186
|
seedSessionHistory(threadId: string, items: ReadonlyArray<Item>): void;
|
|
185
|
-
run<I, O>(step: Step<
|
|
187
|
+
run<I, O>(step: Step<ContextData, I, O>, input: I, ctx: Context): Promise<O>;
|
|
186
188
|
/**
|
|
187
189
|
* Launch `step` as a fire-and-forget background execution.
|
|
188
190
|
*
|
|
@@ -194,11 +196,11 @@ export interface AgentHarnessContract<TParams extends Record<string, unknown> =
|
|
|
194
196
|
*
|
|
195
197
|
* @param step Step to execute in a fresh child context.
|
|
196
198
|
* @param input Initial input passed to `step`.
|
|
197
|
-
* @param parentCtx Parent context (the child inherits
|
|
199
|
+
* @param parentCtx Parent context (the child inherits context layers and,
|
|
198
200
|
* by default, threadId/resourceId).
|
|
199
201
|
* @param overrides Optional: override threadId or resourceId on the child.
|
|
200
202
|
*/
|
|
201
|
-
detachedSpawn<I, O>(step: Step<
|
|
203
|
+
detachedSpawn<I, O>(step: Step<ContextData, I, O>, input: I, parentCtx: Context, overrides?: {
|
|
202
204
|
threadId?: string;
|
|
203
205
|
resourceId?: string;
|
|
204
206
|
/** Override the child's initial cwd. Used by worktree isolation to root the child at the worktree path. */
|
|
@@ -210,7 +212,9 @@ export interface AgentHarnessContract<TParams extends Record<string, unknown> =
|
|
|
210
212
|
state?: unknown;
|
|
211
213
|
threadId?: string;
|
|
212
214
|
resourceId?: string;
|
|
213
|
-
|
|
215
|
+
context?: ContextLayer[];
|
|
216
|
+
/** @deprecated Renamed to `context`. */
|
|
217
|
+
memory?: ContextLayer[];
|
|
214
218
|
/** Override the new context's initial cwd. */
|
|
215
219
|
cwdInit?: string;
|
|
216
220
|
}): Context;
|
|
@@ -230,20 +234,20 @@ export interface AgentHarnessContract<TParams extends Record<string, unknown> =
|
|
|
230
234
|
}): Promise<T>;
|
|
231
235
|
tryRecv<T>(channel: Channel<T>, ctx: Context): T | null;
|
|
232
236
|
getChannelHandle<T>(channel: ExternalChannel<T>, executionId: string): ChannelHandle<T>;
|
|
233
|
-
initLayers(layers:
|
|
234
|
-
recallLayers(layers:
|
|
237
|
+
initLayers(layers: ContextLayer[], ctx: Context, storage: StorageAdapter): Promise<void>;
|
|
238
|
+
recallLayers(layers: ContextLayer[], input: string, ctx: Context): Promise<RecallLayerOutput[]>;
|
|
235
239
|
/** Recall only atomic layers (or all layers when the harness forces atomic recall). Blocks until complete. */
|
|
236
|
-
recallLayersAtomic(layers:
|
|
240
|
+
recallLayersAtomic(layers: ContextLayer[], input: string, ctx: Context, budgets: Map<string, number>): Promise<RecallLayerOutput[]>;
|
|
237
241
|
/** Recall eventual layers from cache (non-blocking); returns nothing when the harness forces atomic recall. */
|
|
238
|
-
recallLayersEventual(layers:
|
|
242
|
+
recallLayersEventual(layers: ContextLayer[], input: string, ctx: Context, budgets: Map<string, number>): Promise<RecallLayerOutput[]>;
|
|
239
243
|
/**
|
|
240
244
|
* Compute the items that would be sent to the model on the next turn for a
|
|
241
|
-
* session — its accumulated history plus the harness's
|
|
245
|
+
* session — its accumulated history plus the harness's context-layer recall
|
|
242
246
|
* outputs assembled in the same order `executeLLM` produces.
|
|
243
247
|
*/
|
|
244
248
|
previewRequestItems(scope?: SessionScope): Promise<ReadonlyArray<Item>>;
|
|
245
|
-
storeLayers(layers:
|
|
246
|
-
disposeLayers(layers:
|
|
249
|
+
storeLayers(layers: ContextLayer[], response: LLMResponse, ctx: Context): Promise<void>;
|
|
250
|
+
disposeLayers(layers: ContextLayer[], ctx: Context): Promise<void>;
|
|
247
251
|
checkpoint(ctx: Context): Promise<void>;
|
|
248
252
|
/**
|
|
249
253
|
* Rebuild a `Context` from a persisted snapshot. `opts` carries the wiring
|
|
@@ -253,7 +257,7 @@ export interface AgentHarnessContract<TParams extends Record<string, unknown> =
|
|
|
253
257
|
restore(executionId: string, opts?: RestoreContextOptions): Promise<Context | null>;
|
|
254
258
|
/**
|
|
255
259
|
* Cancel an execution. Aborts `ctx` and — cascading down the execution tree —
|
|
256
|
-
* every live fork path and spawn child, then runs
|
|
260
|
+
* every live fork path and spawn child, then runs context-layer teardown
|
|
257
261
|
* (`onComplete` with `outcome: 'aborted'`, then `dispose`) bottom-up.
|
|
258
262
|
*
|
|
259
263
|
* Blocked channel operations reject with `cancelled`, the in-flight model
|
|
@@ -267,27 +271,27 @@ export interface AgentHarnessContract<TParams extends Record<string, unknown> =
|
|
|
267
271
|
createSpan(name: string, parent: Span | null): Span;
|
|
268
272
|
getLayerState<T>(executionId: string, layerId: string): T | undefined;
|
|
269
273
|
setLayerState<T>(executionId: string, layerId: string, state: T): void;
|
|
270
|
-
beforeToolCall(layers:
|
|
271
|
-
afterModelCall(layers:
|
|
274
|
+
beforeToolCall(layers: ContextLayer[], toolName: string, toolArgs: unknown, ctx: Context): Promise<SteeringDecision>;
|
|
275
|
+
afterModelCall(layers: ContextLayer[], response: LLMResponse, ctx: Context): Promise<SteeringDecision>;
|
|
272
276
|
/**
|
|
273
277
|
* Project the history items through every layer's `projectHistory` hook in
|
|
274
278
|
* slot order. Pure read-side projection — `itemLog` is never mutated.
|
|
275
279
|
* Returns the input unchanged if no layer registers the hook.
|
|
276
280
|
*/
|
|
277
|
-
projectHistory(layers:
|
|
281
|
+
projectHistory(layers: ContextLayer[], items: ReadonlyArray<Item>, ctx: Context): Promise<ReadonlyArray<Item>>;
|
|
278
282
|
/**
|
|
279
283
|
* Run items through the onItemAppend pipeline before appending.
|
|
280
284
|
* Each layer can filter, transform, or inject items.
|
|
281
285
|
* Returns final items to append and any re-render requests.
|
|
282
286
|
*/
|
|
283
|
-
runAppendPipeline(layers:
|
|
287
|
+
runAppendPipeline(layers: ContextLayer[], items: Item[], ctx: Context): Promise<AppendPipelineResult>;
|
|
284
288
|
/**
|
|
285
289
|
* Execute re-render based on collected requests.
|
|
286
290
|
* Determines which layers need re-recall based on scope and runs them.
|
|
287
291
|
*/
|
|
288
|
-
executeRerender(requests: RerenderRequest[], layers:
|
|
292
|
+
executeRerender(requests: RerenderRequest[], layers: ContextLayer[], ctx: Context, budgets: Map<string, number>, query?: string): Promise<RecallLayerOutput[]>;
|
|
289
293
|
}
|
|
290
|
-
/** @public Output from a single
|
|
294
|
+
/** @public Output from a single context layer's recall phase, including items and token budget used. */
|
|
291
295
|
export interface RecallLayerOutput {
|
|
292
296
|
layerId: string;
|
|
293
297
|
items: Item[];
|
package/dist/types/steering.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { LLMResponse } from './common.js';
|
|
2
|
-
import type {
|
|
2
|
+
import type { ContextScope, ExecutionContext } from './context-scope.js';
|
|
3
3
|
/** @public Enumeration of actions a steering rule can take on a tool call or model response. */
|
|
4
4
|
export declare const SteeringAction: {
|
|
5
5
|
Allow: string;
|
|
@@ -77,7 +77,7 @@ export interface SteeringConfig {
|
|
|
77
77
|
rules: SteeringRule[];
|
|
78
78
|
maxLedgerEntries?: number;
|
|
79
79
|
maxRetries?: number;
|
|
80
|
-
scope?:
|
|
80
|
+
scope?: ContextScope;
|
|
81
81
|
}
|
|
82
82
|
/** @public Mutable runtime state maintained by the steering layer across an execution. */
|
|
83
83
|
export interface SteeringState {
|
package/dist/types/step.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import type { ZodType } from 'zod';
|
|
|
2
2
|
import type { Channel } from './channel.js';
|
|
3
3
|
import type { ModelParams, RetryPolicy, ServerToolSpec, StepMeta } from './common.js';
|
|
4
4
|
import type { Context } from './context.js';
|
|
5
|
+
import type { ContextConfig, ContextData, ContextLayer, ProjectionPolicy } from './context-layer.js';
|
|
5
6
|
import type { NoeticError } from './error.js';
|
|
6
|
-
import type { ContextMemory, MemoryConfig, MemoryLayer, ProjectionPolicy } from './memory.js';
|
|
7
7
|
import type { OutputCodec } from './output-codec.js';
|
|
8
8
|
import type { SubHarness, SubHarnessKind, SubHarnessSessionPolicy, SubHarnessSettings } from './sub-harness.js';
|
|
9
9
|
import type { SubprocessAdapter } from './subprocess-adapter.js';
|
|
@@ -56,7 +56,7 @@ export type Until = (snapshot: Snapshot) => Verdict | Promise<Verdict>;
|
|
|
56
56
|
* tool list). The getter runs at step execution time with the live context.
|
|
57
57
|
* @public
|
|
58
58
|
*/
|
|
59
|
-
export type Lazy<T,
|
|
59
|
+
export type Lazy<T, TContext = ContextData> = T | ((ctx: Context<TContext>) => T | Promise<T>);
|
|
60
60
|
/**
|
|
61
61
|
* Outcome of a single path in a `settle`-mode fork (mirrors `Promise.allSettled`).
|
|
62
62
|
* @public
|
|
@@ -72,12 +72,12 @@ export interface SettleResult<O> {
|
|
|
72
72
|
error?: NoeticError;
|
|
73
73
|
}
|
|
74
74
|
/** @public Discriminated union of all step kinds that can be composed into an execution tree. */
|
|
75
|
-
export type Step<
|
|
75
|
+
export type Step<TContext = ContextData, I = unknown, O = unknown> = StepRun<TContext, I, O> | StepLLM<TContext, I, O> | StepSubHarness<TContext, I, O> | StepTool<TContext, I, O> | StepBranch<TContext, I, O> | StepFork<TContext, I, O> | StepSpawn<TContext, I, O> | StepProvide<TContext, I, O> | StepLoop<TContext, I, O> | StepEvery<TContext, I, O>;
|
|
76
76
|
/** @public A step that executes arbitrary async logic via a user-supplied function. */
|
|
77
|
-
export interface StepRun<
|
|
77
|
+
export interface StepRun<TContext = ContextData, I = unknown, O = unknown> {
|
|
78
78
|
kind: 'run';
|
|
79
79
|
id: string;
|
|
80
|
-
execute: (input: I, ctx: Context<
|
|
80
|
+
execute: (input: I, ctx: Context<TContext>) => Promise<O>;
|
|
81
81
|
retry?: RetryPolicy;
|
|
82
82
|
/**
|
|
83
83
|
* Per-step subprocess adapter override. When set, the interpreter
|
|
@@ -88,13 +88,13 @@ export interface StepRun<TMemory = ContextMemory, I = unknown, O = unknown> {
|
|
|
88
88
|
subprocess?: SubprocessAdapter;
|
|
89
89
|
}
|
|
90
90
|
/** @public A step that sends a prompt to a language model and returns its response. */
|
|
91
|
-
export interface StepLLM<
|
|
91
|
+
export interface StepLLM<TContext = ContextData, _I = unknown, O = unknown> {
|
|
92
92
|
kind: 'llm';
|
|
93
93
|
id: string;
|
|
94
94
|
/** Model id. Accepts either an eager string or a `(ctx) => string` getter. */
|
|
95
|
-
model: Lazy<string,
|
|
95
|
+
model: Lazy<string, TContext>;
|
|
96
96
|
/** System instructions. Eager string or `(ctx) => string | undefined` getter. */
|
|
97
|
-
instructions?: Lazy<string | undefined,
|
|
97
|
+
instructions?: Lazy<string | undefined, TContext>;
|
|
98
98
|
/**
|
|
99
99
|
* Tools exposed to the LLM. Eager array or `(ctx) => (...)[] | undefined` getter.
|
|
100
100
|
* Entries are either a client `Tool` or an inline `ServerToolSpec` (an
|
|
@@ -102,7 +102,7 @@ export interface StepLLM<TMemory = ContextMemory, _I = unknown, O = unknown> {
|
|
|
102
102
|
* Function-form tools do not contribute to the pre-computed `ctx.unifiedTools`;
|
|
103
103
|
* they are resolved per execution.
|
|
104
104
|
*/
|
|
105
|
-
tools?: Lazy<(Tool | ServerToolSpec)[] | undefined,
|
|
105
|
+
tools?: Lazy<(Tool | ServerToolSpec)[] | undefined, TContext>;
|
|
106
106
|
/**
|
|
107
107
|
* Structured output: a Zod schema (assistant text is JSON-parsed and
|
|
108
108
|
* validated) or a streaming `OutputCodec` (fed each text delta, produces
|
|
@@ -122,7 +122,7 @@ export interface StepLLM<TMemory = ContextMemory, _I = unknown, O = unknown> {
|
|
|
122
122
|
* interpreter handler.
|
|
123
123
|
* @public
|
|
124
124
|
*/
|
|
125
|
-
export interface StepSubHarness<
|
|
125
|
+
export interface StepSubHarness<TContext = ContextData, _I = unknown, O = unknown> {
|
|
126
126
|
/** The harness kind, equal to the backing adapter's `harnessId`. */
|
|
127
127
|
kind: SubHarnessKind;
|
|
128
128
|
id: string;
|
|
@@ -131,13 +131,13 @@ export interface StepSubHarness<TMemory = ContextMemory, _I = unknown, O = unkno
|
|
|
131
131
|
* Programmatic builders take it inline; the JSON hydrator resolves it from
|
|
132
132
|
* the workflow's harness registry and inlines it here.
|
|
133
133
|
*/
|
|
134
|
-
harness: Lazy<SubHarness,
|
|
134
|
+
harness: Lazy<SubHarness, TContext>;
|
|
135
135
|
/** Turn prompt. Eager string or `(ctx) => string` getter. */
|
|
136
|
-
prompt: Lazy<string,
|
|
136
|
+
prompt: Lazy<string, TContext>;
|
|
137
137
|
/** Shared harness settings (model, permission mode, …). */
|
|
138
138
|
settings?: SubHarnessSettings;
|
|
139
139
|
/** System instructions applied on the first message of a fresh session. */
|
|
140
|
-
instructions?: Lazy<string | undefined,
|
|
140
|
+
instructions?: Lazy<string | undefined, TContext>;
|
|
141
141
|
/** When set, the assistant text is JSON-parsed and validated against this schema. */
|
|
142
142
|
output?: ZodType<O>;
|
|
143
143
|
/** Session reuse + teardown policy across steps. */
|
|
@@ -146,68 +146,68 @@ export interface StepSubHarness<TMemory = ContextMemory, _I = unknown, O = unkno
|
|
|
146
146
|
emit?: boolean | ((eventType: string, data: Record<string, unknown>) => boolean);
|
|
147
147
|
}
|
|
148
148
|
/** @public A step that invokes a single tool directly, bypassing the LLM. */
|
|
149
|
-
export interface StepTool<
|
|
149
|
+
export interface StepTool<_TContext = ContextData, I = unknown, O = unknown> {
|
|
150
150
|
kind: 'tool';
|
|
151
151
|
id: string;
|
|
152
152
|
tool: Tool<ZodType<I>, ZodType<O>>;
|
|
153
153
|
args?: Partial<I>;
|
|
154
154
|
}
|
|
155
155
|
/** @public A step that dynamically selects and executes one of several possible sub-steps. */
|
|
156
|
-
export interface StepBranch<
|
|
156
|
+
export interface StepBranch<TContext = ContextData, I = unknown, O = unknown> {
|
|
157
157
|
kind: 'branch';
|
|
158
158
|
id: string;
|
|
159
|
-
route: (input: I, ctx: Context<
|
|
160
|
-
_optimizable?: Step<
|
|
159
|
+
route: (input: I, ctx: Context<TContext>) => Step<TContext, I, O> | null | Promise<Step<TContext, I, O> | null>;
|
|
160
|
+
_optimizable?: Step<TContext>[];
|
|
161
161
|
}
|
|
162
162
|
/** @public Union of fork step variants (`race`, `all`, `settle`) for concurrent path execution. */
|
|
163
|
-
export type StepFork<
|
|
163
|
+
export type StepFork<TContext = ContextData, I = unknown, O = unknown> = StepForkRace<TContext, I, O> | StepForkAll<TContext, I, O> | StepForkSettle<TContext, I, O>;
|
|
164
164
|
/** @public A fork step that returns the result of the first path to complete. */
|
|
165
|
-
export interface StepForkRace<
|
|
165
|
+
export interface StepForkRace<TContext = ContextData, I = unknown, O = unknown> {
|
|
166
166
|
kind: 'fork';
|
|
167
167
|
id: string;
|
|
168
168
|
mode: 'race';
|
|
169
|
-
paths: (input: I, ctx: Context<
|
|
169
|
+
paths: (input: I, ctx: Context<TContext>) => Step<TContext, I, O>[];
|
|
170
170
|
concurrency?: number;
|
|
171
|
-
_optimizable?: Step<
|
|
171
|
+
_optimizable?: Step<TContext>[];
|
|
172
172
|
}
|
|
173
173
|
/** @public A fork step that runs all paths and merges their results. */
|
|
174
|
-
export interface StepForkAll<
|
|
174
|
+
export interface StepForkAll<TContext = ContextData, I = unknown, O = unknown> {
|
|
175
175
|
kind: 'fork';
|
|
176
176
|
id: string;
|
|
177
177
|
mode: 'all';
|
|
178
|
-
paths: (input: I, ctx: Context<
|
|
179
|
-
merge: (results: O[], ctx: Context<
|
|
178
|
+
paths: (input: I, ctx: Context<TContext>) => Step<TContext, I, O>[];
|
|
179
|
+
merge: (results: O[], ctx: Context<TContext>) => O;
|
|
180
180
|
concurrency?: number;
|
|
181
|
-
_optimizable?: Step<
|
|
181
|
+
_optimizable?: Step<TContext>[];
|
|
182
182
|
}
|
|
183
183
|
/** @public A fork step that runs all paths and collects fulfilled/rejected outcomes. */
|
|
184
|
-
export interface StepForkSettle<
|
|
184
|
+
export interface StepForkSettle<TContext = ContextData, I = unknown, O = unknown> {
|
|
185
185
|
kind: 'fork';
|
|
186
186
|
id: string;
|
|
187
187
|
mode: 'settle';
|
|
188
|
-
paths: (input: I, ctx: Context<
|
|
189
|
-
merge: (results: SettleResult<O>[], ctx: Context<
|
|
188
|
+
paths: (input: I, ctx: Context<TContext>) => Step<TContext, I, O>[];
|
|
189
|
+
merge: (results: SettleResult<O>[], ctx: Context<TContext>) => O;
|
|
190
190
|
concurrency?: number;
|
|
191
|
-
_optimizable?: Step<
|
|
191
|
+
_optimizable?: Step<TContext>[];
|
|
192
192
|
}
|
|
193
193
|
/**
|
|
194
|
-
* A step that provides
|
|
194
|
+
* A step that provides context layers to its child without creating an isolated context.
|
|
195
195
|
* Like React's Context.Provider — layers are available to all descendant steps.
|
|
196
196
|
* Spawn and detachedSpawn break the inheritance chain.
|
|
197
197
|
* @public
|
|
198
198
|
*/
|
|
199
|
-
export interface StepProvide<
|
|
199
|
+
export interface StepProvide<TContext = ContextData, I = unknown, O = unknown> {
|
|
200
200
|
kind: 'provide';
|
|
201
201
|
id: string;
|
|
202
|
-
child: Step<
|
|
203
|
-
|
|
202
|
+
child: Step<TContext, I, O>;
|
|
203
|
+
context: ContextConfig | ContextLayer[];
|
|
204
204
|
}
|
|
205
|
-
/** @public A step that launches a child execution with its own
|
|
206
|
-
export interface StepSpawn<
|
|
205
|
+
/** @public A step that launches a child execution with its own context scope. */
|
|
206
|
+
export interface StepSpawn<TContext = ContextData, I = unknown, O = unknown> {
|
|
207
207
|
kind: 'spawn';
|
|
208
208
|
id: string;
|
|
209
|
-
child: Step<
|
|
210
|
-
|
|
209
|
+
child: Step<TContext, I, O>;
|
|
210
|
+
context?: ContextConfig | ContextLayer[];
|
|
211
211
|
timeout?: number;
|
|
212
212
|
/**
|
|
213
213
|
* Per-step subprocess adapter override applied when the interpreter
|
|
@@ -220,12 +220,12 @@ export interface StepSpawn<TMemory = ContextMemory, I = unknown, O = unknown> {
|
|
|
220
220
|
* A loop step that iterates a body step until a termination predicate is satisfied.
|
|
221
221
|
* @public
|
|
222
222
|
*/
|
|
223
|
-
export interface StepLoop<
|
|
223
|
+
export interface StepLoop<TContext = ContextData, I = unknown, O = unknown> {
|
|
224
224
|
kind: 'loop';
|
|
225
225
|
/** Unique step identifier used in traces and error messages. */
|
|
226
226
|
id: string;
|
|
227
227
|
/** Steps to execute sequentially on each iteration. */
|
|
228
|
-
steps: ReadonlyArray<Step<
|
|
228
|
+
steps: ReadonlyArray<Step<TContext, I, O>>;
|
|
229
229
|
/** Termination predicate evaluated after each iteration with a cumulative snapshot. */
|
|
230
230
|
until: Until;
|
|
231
231
|
/** Hard safety cap on iterations (default: 1000). */
|
|
@@ -237,9 +237,9 @@ export interface StepLoop<TMemory = ContextMemory, I = unknown, O = unknown> {
|
|
|
237
237
|
/** Ms to wait on inbox before the loop parks itself (default: 0 = no parking). */
|
|
238
238
|
parkTimeout?: number;
|
|
239
239
|
/** Transforms the previous iteration's output into the next iteration's input. */
|
|
240
|
-
prepareNext?: (output: O, verdict: Verdict, ctx: Context<
|
|
240
|
+
prepareNext?: (output: O, verdict: Verdict, ctx: Context<TContext>) => I;
|
|
241
241
|
/** Per-iteration error handler: retry the iteration, skip it, or abort the loop. */
|
|
242
|
-
onError?: (error: NoeticError, ctx: Context<
|
|
242
|
+
onError?: (error: NoeticError, ctx: Context<TContext>) => 'retry' | 'skip' | 'abort';
|
|
243
243
|
}
|
|
244
244
|
/**
|
|
245
245
|
* Error policy for the `every` operator when its body step throws.
|
|
@@ -257,12 +257,12 @@ export type EveryErrorPolicy = 'continue' | 'fail';
|
|
|
257
257
|
*
|
|
258
258
|
* @public
|
|
259
259
|
*/
|
|
260
|
-
export interface StepEvery<
|
|
260
|
+
export interface StepEvery<TContext = ContextData, I = unknown, O = unknown> {
|
|
261
261
|
kind: 'every';
|
|
262
262
|
/** Unique step identifier used in traces and error messages. */
|
|
263
263
|
id: string;
|
|
264
264
|
/** Body step executed on each iteration. */
|
|
265
|
-
step: Step<
|
|
265
|
+
step: Step<TContext, I, O>;
|
|
266
266
|
/** Park duration between iterations in milliseconds. Must be >= 0. */
|
|
267
267
|
ms: number;
|
|
268
268
|
/** Optional channel that wakes the parking interval when any value arrives. */
|
|
@@ -273,4 +273,4 @@ export interface StepEvery<TMemory = ContextMemory, I = unknown, O = unknown> {
|
|
|
273
273
|
jitter?: number;
|
|
274
274
|
}
|
|
275
275
|
/** @public Function signature used by the interpreter to recursively execute a step. */
|
|
276
|
-
export type ExecuteStepFn = <
|
|
276
|
+
export type ExecuteStepFn = <TContext, I, O>(step: Step<TContext, I, O>, input: I, ctx: Context<TContext>) => Promise<O>;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* A "harness" here is a pluggable backend that drives an external agentic
|
|
5
5
|
* coding tool — Claude Code, Codex, opencode, pi — as a Noetic step. It is the
|
|
6
|
-
* direct analogue of the `
|
|
6
|
+
* direct analogue of the `ContextLayer` contract: defined in the dependency-free
|
|
7
7
|
* `@noetic-tools/types` foundation so both `@noetic-tools/core` (which executes
|
|
8
8
|
* harness steps) and the per-tool `@noetic-tools/sub-harness-*` packages (which
|
|
9
9
|
* implement them) can depend on it without forming a cycle.
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* A "harness" here is a pluggable backend that drives an external agentic
|
|
5
5
|
* coding tool — Claude Code, Codex, opencode, pi — as a Noetic step. It is the
|
|
6
|
-
* direct analogue of the `
|
|
6
|
+
* direct analogue of the `ContextLayer` contract: defined in the dependency-free
|
|
7
7
|
* `@noetic-tools/types` foundation so both `@noetic-tools/core` (which executes
|
|
8
8
|
* harness steps) and the per-tool `@noetic-tools/sub-harness-*` packages (which
|
|
9
9
|
* implement them) can depend on it without forming a cycle.
|
|
@@ -6,7 +6,7 @@ import type { Item } from './items.js';
|
|
|
6
6
|
import type { AgentHarnessContract } from './runtime.js';
|
|
7
7
|
import type { ShellAdapter } from './shell-adapter.js';
|
|
8
8
|
/** @public Accessor for reading and writing per-layer state from within a tool execution. */
|
|
9
|
-
export interface
|
|
9
|
+
export interface ToolContext {
|
|
10
10
|
get<T>(layerId: string): T | undefined;
|
|
11
11
|
set<T>(layerId: string, state: T): void;
|
|
12
12
|
}
|
|
@@ -23,8 +23,15 @@ export interface ToolExecutionContext {
|
|
|
23
23
|
readonly fs: FsAdapter;
|
|
24
24
|
/** Shell adapter for virtual or real shell command execution. */
|
|
25
25
|
readonly shell: ShellAdapter;
|
|
26
|
-
/** Per-layer
|
|
27
|
-
readonly
|
|
26
|
+
/** Per-layer state accessor for reading/writing tool-specific state. */
|
|
27
|
+
readonly context: ToolContext;
|
|
28
|
+
/**
|
|
29
|
+
* @deprecated Renamed to `context`. Returns the same accessor.
|
|
30
|
+
*
|
|
31
|
+
* Required for the same reason as `Context.memory` — pre-rename code calls
|
|
32
|
+
* `toolCtx.memory.get(...)` directly.
|
|
33
|
+
*/
|
|
34
|
+
readonly memory: ToolContext;
|
|
28
35
|
/** The fully assembled conversation view at the point of tool invocation. */
|
|
29
36
|
readonly assembledView: ReadonlyArray<Item>;
|
|
30
37
|
/** Metadata from the most recent step execution (token usage, tool calls, etc.). */
|
package/dist/types/tool.d.ts
CHANGED
|
@@ -2,10 +2,10 @@ import type { ZodTypeAny, z } from 'zod';
|
|
|
2
2
|
import type { FunctionCallItem, FunctionCallOutputItem, Item, ItemSchemaExtensions, ToolResultExtensionItem } from './items.js';
|
|
3
3
|
type ToolExecutionResult<O extends ZodTypeAny> = Promise<z.infer<O>> | AsyncGenerator<unknown, z.infer<O>>;
|
|
4
4
|
/**
|
|
5
|
-
* Declares tool-owned
|
|
5
|
+
* Declares tool-owned state that the runtime materializes into a ContextLayer.
|
|
6
6
|
* @public
|
|
7
7
|
*/
|
|
8
|
-
export interface
|
|
8
|
+
export interface ToolContextDeclaration<TState = unknown> {
|
|
9
9
|
/** Shared id — tools with the same id share state. Defaults to `tool.name`. */
|
|
10
10
|
id?: string;
|
|
11
11
|
/** Factory for the initial state. */
|
|
@@ -13,8 +13,8 @@ export interface ToolMemoryDeclaration<TState = unknown> {
|
|
|
13
13
|
/**
|
|
14
14
|
* Project state into the LLM context. Return null to omit.
|
|
15
15
|
* Declared as a method (bivariant params) so a concrete
|
|
16
|
-
* `
|
|
17
|
-
* `
|
|
16
|
+
* `ToolContextDeclaration<MyState>` assigns to the erased
|
|
17
|
+
* `ToolContextDeclaration` the `tool()` builder and runtime consume.
|
|
18
18
|
*/
|
|
19
19
|
recall(state: TState): string | null;
|
|
20
20
|
}
|
|
@@ -22,7 +22,7 @@ export interface ToolMemoryDeclaration<TState = unknown> {
|
|
|
22
22
|
* A renderable UI fragment in a named dialect (e.g. `'openui-lang/0.5'`).
|
|
23
23
|
* The framework never interprets `source` — it forwards fragments as
|
|
24
24
|
* `openui.fragment` framework events and attaches them to items; a UI
|
|
25
|
-
* surface (
|
|
25
|
+
* surface (context layer + transport) composes and renders them.
|
|
26
26
|
* @public
|
|
27
27
|
*/
|
|
28
28
|
export interface UiFragment {
|
|
@@ -34,7 +34,7 @@ export interface UiFragment {
|
|
|
34
34
|
/**
|
|
35
35
|
* Declares tool-owned UI: programmatic render functions invoked at tool
|
|
36
36
|
* lifecycle points. All methods are optional — an omitted point renders
|
|
37
|
-
* nothing (mirrors `
|
|
37
|
+
* nothing (mirrors `ToolContextDeclaration`). Declared as methods (bivariant
|
|
38
38
|
* params) so a concretely-typed declaration assigns to the erased form the
|
|
39
39
|
* `tool()` builder and runtime consume.
|
|
40
40
|
* @public
|
|
@@ -89,8 +89,8 @@ export interface Tool<I extends ZodTypeAny = ZodTypeAny, O extends ZodTypeAny =
|
|
|
89
89
|
execute(args: z.infer<I>, toolCtx: unknown): ToolExecutionResult<O>;
|
|
90
90
|
/** When true, execution pauses for human approval before running. */
|
|
91
91
|
needsApproval?: boolean;
|
|
92
|
-
/** Optional
|
|
93
|
-
|
|
92
|
+
/** Optional context declaration — the runtime generates a ContextLayer from this. */
|
|
93
|
+
context?: ToolContextDeclaration;
|
|
94
94
|
/** Optional UI declaration — the runtime emits the rendered fragments at call/progress/result points. */
|
|
95
95
|
ui?: ToolUiDeclaration<I, O>;
|
|
96
96
|
}
|
|
@@ -20,10 +20,10 @@ export declare function isTextPart(part: {
|
|
|
20
20
|
type: string;
|
|
21
21
|
text: string;
|
|
22
22
|
};
|
|
23
|
-
/** Extracts assistant/output text from items for
|
|
23
|
+
/** Extracts assistant/output text from items for context buffering (one string per message). */
|
|
24
24
|
export declare function collectOutputText(items: ReadonlyArray<Item>): string[];
|
|
25
25
|
/**
|
|
26
|
-
* Extracts text from INPUT items for
|
|
26
|
+
* Extracts text from INPUT items for context buffering: concatenates the text
|
|
27
27
|
* content parts of message items (user `input_text` and any text parts) and
|
|
28
28
|
* appends the `output` of `function_call_output` (tool result) items. Empty
|
|
29
29
|
* strings are dropped.
|
|
@@ -25,7 +25,7 @@ export function isOutputText(part) {
|
|
|
25
25
|
export function isTextPart(part) {
|
|
26
26
|
return 'text' in part && typeof part.text === 'string';
|
|
27
27
|
}
|
|
28
|
-
/** Extracts assistant/output text from items for
|
|
28
|
+
/** Extracts assistant/output text from items for context buffering (one string per message). */
|
|
29
29
|
export function collectOutputText(items) {
|
|
30
30
|
return items
|
|
31
31
|
.filter(isAssistantMessage)
|
|
@@ -36,7 +36,7 @@ export function collectOutputText(items) {
|
|
|
36
36
|
.filter((t) => t.length > 0);
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
39
|
-
* Extracts text from INPUT items for
|
|
39
|
+
* Extracts text from INPUT items for context buffering: concatenates the text
|
|
40
40
|
* content parts of message items (user `input_text` and any text parts) and
|
|
41
41
|
* appends the `output` of `function_call_output` (tool result) items. Empty
|
|
42
42
|
* strings are dropped.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noetic-tools/types",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.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",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"default": "./dist/index.js"
|
|
28
28
|
},
|
|
29
29
|
"./contract": {
|
|
30
|
-
"types": "./dist/types/
|
|
31
|
-
"default": "./dist/types/
|
|
30
|
+
"types": "./dist/types/context-layer.d.ts",
|
|
31
|
+
"default": "./dist/types/context-layer.js"
|
|
32
32
|
},
|
|
33
33
|
"./package.json": "./package.json"
|
|
34
34
|
},
|
|
File without changes
|