@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
package/dist/types/step.d.ts
CHANGED
|
@@ -52,13 +52,14 @@ export interface Verdict {
|
|
|
52
52
|
export type Until = (snapshot: Snapshot) => Verdict | Promise<Verdict>;
|
|
53
53
|
/**
|
|
54
54
|
* Field type that accepts either an eager value or a `(ctx) => value` getter.
|
|
55
|
-
* Used by `step.
|
|
56
|
-
* tool list). The getter runs at step execution time with the
|
|
55
|
+
* Used by `step.callModel` for params that may vary per execution (model,
|
|
56
|
+
* instructions, tool list). The getter runs at step execution time with the
|
|
57
|
+
* live context.
|
|
57
58
|
* @public
|
|
58
59
|
*/
|
|
59
60
|
export type Lazy<T, TContext = ContextData> = T | ((ctx: Context<TContext>) => T | Promise<T>);
|
|
60
61
|
/**
|
|
61
|
-
* Outcome of a single path in a `settle`-mode
|
|
62
|
+
* Outcome of a single path in a `settle`-mode inParallel step (mirrors `Promise.allSettled`).
|
|
62
63
|
* @public
|
|
63
64
|
*/
|
|
64
65
|
export interface SettleResult<O> {
|
|
@@ -72,10 +73,10 @@ export interface SettleResult<O> {
|
|
|
72
73
|
error?: NoeticError;
|
|
73
74
|
}
|
|
74
75
|
/** @public Discriminated union of all step kinds that can be composed into an execution tree. */
|
|
75
|
-
export type Step<TContext = ContextData, I = unknown, O = unknown> =
|
|
76
|
+
export type Step<TContext = ContextData, I = unknown, O = unknown> = StepRunCode<TContext, I, O> | StepCallModel<TContext, I, O> | StepSubHarness<TContext, I, O> | StepInvokeTool<TContext, I, O> | StepConditional<TContext, I, O> | StepInParallel<TContext, I, O> | StepSpawn<TContext, I, O> | StepWithContext<TContext, I, O> | StepLoop<TContext, I, O> | StepSchedule<TContext, I, O>;
|
|
76
77
|
/** @public A step that executes arbitrary async logic via a user-supplied function. */
|
|
77
|
-
export interface
|
|
78
|
-
kind: '
|
|
78
|
+
export interface StepRunCode<TContext = ContextData, I = unknown, O = unknown> {
|
|
79
|
+
kind: 'runCode';
|
|
79
80
|
id: string;
|
|
80
81
|
execute: (input: I, ctx: Context<TContext>) => Promise<O>;
|
|
81
82
|
retry?: RetryPolicy;
|
|
@@ -88,8 +89,8 @@ export interface StepRun<TContext = ContextData, I = unknown, O = unknown> {
|
|
|
88
89
|
subprocess?: SubprocessAdapter;
|
|
89
90
|
}
|
|
90
91
|
/** @public A step that sends a prompt to a language model and returns its response. */
|
|
91
|
-
export interface
|
|
92
|
-
kind: '
|
|
92
|
+
export interface StepCallModel<TContext = ContextData, _I = unknown, O = unknown> {
|
|
93
|
+
kind: 'callModel';
|
|
93
94
|
id: string;
|
|
94
95
|
/** Model id. Accepts either an eager string or a `(ctx) => string` getter. */
|
|
95
96
|
model: Lazy<string, TContext>;
|
|
@@ -151,34 +152,34 @@ export interface StepSubHarness<TContext = ContextData, _I = unknown, O = unknow
|
|
|
151
152
|
/** Controls framework event emission for this step. Defaults to `true`. */
|
|
152
153
|
emit?: boolean | ((eventType: string, data: Record<string, unknown>) => boolean);
|
|
153
154
|
}
|
|
154
|
-
/** @public A step that invokes a single tool directly, bypassing the
|
|
155
|
-
export interface
|
|
156
|
-
kind: '
|
|
155
|
+
/** @public A step that invokes a single tool directly, bypassing the model. */
|
|
156
|
+
export interface StepInvokeTool<_TContext = ContextData, I = unknown, O = unknown> {
|
|
157
|
+
kind: 'invokeTool';
|
|
157
158
|
id: string;
|
|
158
159
|
tool: Tool<StandardSchemaV1<unknown, I>, StandardSchemaV1<unknown, O>>;
|
|
159
160
|
args?: Partial<I>;
|
|
160
161
|
}
|
|
161
162
|
/** @public A step that dynamically selects and executes one of several possible sub-steps. */
|
|
162
|
-
export interface
|
|
163
|
-
kind: '
|
|
163
|
+
export interface StepConditional<TContext = ContextData, I = unknown, O = unknown> {
|
|
164
|
+
kind: 'conditional';
|
|
164
165
|
id: string;
|
|
165
166
|
route: (input: I, ctx: Context<TContext>) => Step<TContext, I, O> | null | Promise<Step<TContext, I, O> | null>;
|
|
166
167
|
_optimizable?: Step<TContext>[];
|
|
167
168
|
}
|
|
168
|
-
/** @public Union of
|
|
169
|
-
export type
|
|
170
|
-
/** @public
|
|
171
|
-
export interface
|
|
172
|
-
kind: '
|
|
169
|
+
/** @public Union of inParallel step variants (`race`, `all`, `settle`) for concurrent path execution. */
|
|
170
|
+
export type StepInParallel<TContext = ContextData, I = unknown, O = unknown> = StepInParallelRace<TContext, I, O> | StepInParallelAll<TContext, I, O> | StepInParallelSettle<TContext, I, O>;
|
|
171
|
+
/** @public An inParallel step that returns the result of the first path to complete. */
|
|
172
|
+
export interface StepInParallelRace<TContext = ContextData, I = unknown, O = unknown> {
|
|
173
|
+
kind: 'inParallel';
|
|
173
174
|
id: string;
|
|
174
175
|
mode: 'race';
|
|
175
176
|
paths: (input: I, ctx: Context<TContext>) => Step<TContext, I, O>[];
|
|
176
177
|
concurrency?: number;
|
|
177
178
|
_optimizable?: Step<TContext>[];
|
|
178
179
|
}
|
|
179
|
-
/** @public
|
|
180
|
-
export interface
|
|
181
|
-
kind: '
|
|
180
|
+
/** @public An inParallel step that runs all paths and merges their results. */
|
|
181
|
+
export interface StepInParallelAll<TContext = ContextData, I = unknown, O = unknown> {
|
|
182
|
+
kind: 'inParallel';
|
|
182
183
|
id: string;
|
|
183
184
|
mode: 'all';
|
|
184
185
|
paths: (input: I, ctx: Context<TContext>) => Step<TContext, I, O>[];
|
|
@@ -186,9 +187,9 @@ export interface StepForkAll<TContext = ContextData, I = unknown, O = unknown> {
|
|
|
186
187
|
concurrency?: number;
|
|
187
188
|
_optimizable?: Step<TContext>[];
|
|
188
189
|
}
|
|
189
|
-
/** @public
|
|
190
|
-
export interface
|
|
191
|
-
kind: '
|
|
190
|
+
/** @public An inParallel step that runs all paths and collects fulfilled/rejected outcomes. */
|
|
191
|
+
export interface StepInParallelSettle<TContext = ContextData, I = unknown, O = unknown> {
|
|
192
|
+
kind: 'inParallel';
|
|
192
193
|
id: string;
|
|
193
194
|
mode: 'settle';
|
|
194
195
|
paths: (input: I, ctx: Context<TContext>) => Step<TContext, I, O>[];
|
|
@@ -202,8 +203,8 @@ export interface StepForkSettle<TContext = ContextData, I = unknown, O = unknown
|
|
|
202
203
|
* Spawn and detachedSpawn break the inheritance chain.
|
|
203
204
|
* @public
|
|
204
205
|
*/
|
|
205
|
-
export interface
|
|
206
|
-
kind: '
|
|
206
|
+
export interface StepWithContext<TContext = ContextData, I = unknown, O = unknown> {
|
|
207
|
+
kind: 'withContext';
|
|
207
208
|
id: string;
|
|
208
209
|
child: Step<TContext, I, O>;
|
|
209
210
|
context: ContextConfig | ContextLayer[];
|
|
@@ -248,33 +249,33 @@ export interface StepLoop<TContext = ContextData, I = unknown, O = unknown> {
|
|
|
248
249
|
onError?: (error: NoeticError, ctx: Context<TContext>) => 'retry' | 'skip' | 'abort';
|
|
249
250
|
}
|
|
250
251
|
/**
|
|
251
|
-
* Error policy for the `
|
|
252
|
+
* Error policy for the `schedule` operator when its body step throws.
|
|
252
253
|
* - `'continue'` (default): emit a span event recording the error and continue parking.
|
|
253
254
|
* - `'fail'`: re-throw, terminating the operator.
|
|
254
255
|
* @public
|
|
255
256
|
*/
|
|
256
|
-
export type
|
|
257
|
+
export type ScheduleErrorPolicy = 'continue' | 'fail';
|
|
257
258
|
/**
|
|
258
259
|
* A step that runs a body step on a fixed-interval schedule, optionally woken
|
|
259
|
-
* sooner by
|
|
260
|
+
* sooner by an inbox channel. Runs forever until the executing context is cancelled.
|
|
260
261
|
*
|
|
261
|
-
* The operator output is `void` — `
|
|
262
|
+
* The operator output is `void` — `schedule` does not accumulate iteration outputs.
|
|
262
263
|
* The `O` type parameter exists only to anchor the body step's output type.
|
|
263
264
|
*
|
|
264
265
|
* @public
|
|
265
266
|
*/
|
|
266
|
-
export interface
|
|
267
|
-
kind: '
|
|
267
|
+
export interface StepSchedule<TContext = ContextData, I = unknown, O = unknown> {
|
|
268
|
+
kind: 'schedule';
|
|
268
269
|
/** Unique step identifier used in traces and error messages. */
|
|
269
270
|
id: string;
|
|
270
271
|
/** Body step executed on each iteration. */
|
|
271
272
|
step: Step<TContext, I, O>;
|
|
272
273
|
/** Park duration between iterations in milliseconds. Must be >= 0. */
|
|
273
|
-
|
|
274
|
+
interval: number;
|
|
274
275
|
/** Optional channel that wakes the parking interval when any value arrives. */
|
|
275
|
-
|
|
276
|
+
inbox?: Channel<unknown>;
|
|
276
277
|
/** Behavior when `step` throws. Defaults to `'continue'`. */
|
|
277
|
-
onError?:
|
|
278
|
+
onError?: ScheduleErrorPolicy;
|
|
278
279
|
/** Random jitter applied to the park duration in milliseconds. Must be >= 0. Default 0. */
|
|
279
280
|
jitter?: number;
|
|
280
281
|
}
|
|
@@ -25,13 +25,6 @@ export interface ToolExecutionContext {
|
|
|
25
25
|
readonly shell: ShellAdapter;
|
|
26
26
|
/** Per-layer state accessor for reading/writing tool-specific state. */
|
|
27
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;
|
|
35
28
|
/** The fully assembled conversation view at the point of tool invocation. */
|
|
36
29
|
readonly assembledView: ReadonlyArray<Item>;
|
|
37
30
|
/** Metadata from the most recent step execution (token usage, tool calls, etc.). */
|
|
@@ -98,7 +98,14 @@ export function trackUsage(ctx, response) {
|
|
|
98
98
|
ctx.tokens.input += response.usage.inputTokens;
|
|
99
99
|
ctx.tokens.output += response.usage.outputTokens;
|
|
100
100
|
ctx.tokens.total += response.usage.inputTokens + response.usage.outputTokens;
|
|
101
|
-
|
|
101
|
+
// Only write `cached` when the response actually carried a figure. Defaulting
|
|
102
|
+
// a missing report to 0 would erase the `RoundUsage` invariant that
|
|
103
|
+
// `undefined` means "this provider says nothing about caching" — callers that
|
|
104
|
+
// steer on cache behaviour could no longer tell that from "nothing was
|
|
105
|
+
// cached". Mirrors the child→parent merge in execute-action.
|
|
106
|
+
if (response.usage.cachedTokens !== undefined) {
|
|
107
|
+
ctx.tokens.cached = (ctx.tokens.cached ?? 0) + response.usage.cachedTokens;
|
|
108
|
+
}
|
|
102
109
|
if (response.cost) {
|
|
103
110
|
ctx.cost = ctx.cost + response.cost;
|
|
104
111
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noetic-tools/types",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.1",
|
|
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",
|
package/dist/deprecated.d.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Deprecated aliases from the "memory layer" era of the framework.
|
|
3
|
-
*
|
|
4
|
-
* The layer system assembles the model's *context window* — recall, budget
|
|
5
|
-
* allocation, history projection, the item-append pipeline — so it is named
|
|
6
|
-
* after context, not memory. Every name below still resolves to its
|
|
7
|
-
* replacement; nothing here changes behaviour.
|
|
8
|
-
*
|
|
9
|
-
* These are scheduled for removal in the next major of `@noetic-tools/types`.
|
|
10
|
-
*/
|
|
11
|
-
import type { ContextConfig, ContextData, ContextLayer, ContextLayerHooks, InferContext, InferContextShape } from './types/context-layer.js';
|
|
12
|
-
import type { ContextScope, LayerCallModelRequest } from './types/context-scope.js';
|
|
13
|
-
import type { LayerTraceSpan } from './types/observability.js';
|
|
14
|
-
import type { ToolContextDeclaration } from './types/tool.js';
|
|
15
|
-
import type { ToolContext } from './types/tool-context.js';
|
|
16
|
-
/** @public @deprecated Renamed to {@link ContextLayer}. */
|
|
17
|
-
export type MemoryLayer<TState = unknown> = ContextLayer<TState>;
|
|
18
|
-
/** @public @deprecated Renamed to {@link ContextLayerHooks}. */
|
|
19
|
-
export type MemoryHooks<TState = unknown> = ContextLayerHooks<TState>;
|
|
20
|
-
/** @public @deprecated Renamed to {@link ContextConfig}. */
|
|
21
|
-
export type MemoryConfig<TLayers extends readonly ContextLayer[] = readonly ContextLayer[]> = ContextConfig<TLayers>;
|
|
22
|
-
/** @public @deprecated Renamed to {@link ContextData}. */
|
|
23
|
-
export type ContextMemory = ContextData;
|
|
24
|
-
/** @public @deprecated Renamed to {@link InferContext}. */
|
|
25
|
-
export type InferMemory<T extends {
|
|
26
|
-
readonly _shape: unknown;
|
|
27
|
-
}> = InferContext<T>;
|
|
28
|
-
/** @public @deprecated Renamed to {@link InferContextShape}. */
|
|
29
|
-
export type InferMemoryShape<T extends readonly ContextLayer[]> = InferContextShape<T>;
|
|
30
|
-
/** @public @deprecated Renamed to {@link ContextScope}. */
|
|
31
|
-
export type MemoryScope = ContextScope;
|
|
32
|
-
/** @public @deprecated Renamed to {@link LayerCallModelRequest}. */
|
|
33
|
-
export type MemoryCallModelRequest = LayerCallModelRequest;
|
|
34
|
-
/** @public @deprecated Renamed to {@link LayerTraceSpan}. */
|
|
35
|
-
export type MemoryTraceSpan = LayerTraceSpan;
|
|
36
|
-
/** @public @deprecated Renamed to {@link ToolContext}. */
|
|
37
|
-
export type ToolMemory = ToolContext;
|
|
38
|
-
/** @public @deprecated Renamed to {@link ToolContextDeclaration}. */
|
|
39
|
-
export type ToolMemoryDeclaration<TState = unknown> = ToolContextDeclaration<TState>;
|
|
File without changes
|