@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.
- package/README.md +3 -3
- package/dist/errors/noetic-error.js +7 -7
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -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 -171
- package/dist/types/error.d.ts +9 -6
- 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 +38 -12
- package/dist/types/schema.d.ts +62 -0
- package/dist/types/schema.js +63 -0
- package/dist/types/steering.d.ts +2 -1
- package/dist/types/step.d.ts +49 -42
- package/dist/types/tool-context.d.ts +0 -7
- package/dist/types/tool.d.ts +26 -14
- package/dist/util/message-helpers.js +8 -1
- package/package.json +2 -1
- package/dist/deprecated.d.ts +0 -39
- /package/dist/{deprecated.js → types/context-harness.js} +0 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { ZodError } from 'zod';
|
|
2
|
+
import { frameworkCast } from '../util/framework-cast.js';
|
|
3
|
+
/** @public Type guard for Zod schemas (detected via the `_zod` internals marker). */
|
|
4
|
+
export function isZodSchema(schema) {
|
|
5
|
+
return '_zod' in schema;
|
|
6
|
+
}
|
|
7
|
+
/** @public Type guard for schemas implementing the Standard JSON Schema v1 companion spec. */
|
|
8
|
+
export function isStandardJsonSchema(schema) {
|
|
9
|
+
const standard = frameworkCast(schema['~standard']);
|
|
10
|
+
return typeof standard.jsonSchema?.input === 'function';
|
|
11
|
+
}
|
|
12
|
+
function issuePathToPropertyKeys(path) {
|
|
13
|
+
if (!path) {
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
return path.map((segment) => typeof segment === 'object' && segment !== null && 'key' in segment ? segment.key : segment);
|
|
17
|
+
}
|
|
18
|
+
/** @public Adapt Standard Schema issues into a synthetic `ZodError` of `custom` issues. */
|
|
19
|
+
export function standardIssuesToZodError(issues) {
|
|
20
|
+
return new ZodError(issues.map((issue) => ({
|
|
21
|
+
code: 'custom',
|
|
22
|
+
message: issue.message,
|
|
23
|
+
path: issuePathToPropertyKeys(issue.path),
|
|
24
|
+
})));
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Validates a value against any Standard Schema. Zod schemas take the
|
|
28
|
+
* `safeParse` fast path; other vendors run `schema['~standard'].validate`,
|
|
29
|
+
* awaiting sync or Promise results. The returned success value is the
|
|
30
|
+
* parsed/transformed output.
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
export async function validateSchema(schema, value) {
|
|
34
|
+
if (isZodSchema(schema)) {
|
|
35
|
+
const result = schema.safeParse(value);
|
|
36
|
+
if (result.success) {
|
|
37
|
+
return {
|
|
38
|
+
success: true,
|
|
39
|
+
value: frameworkCast(result.data),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
success: false,
|
|
44
|
+
issues: result.error.issues.map((issue) => ({
|
|
45
|
+
message: issue.message,
|
|
46
|
+
path: issue.path,
|
|
47
|
+
})),
|
|
48
|
+
zodError: result.error,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
const result = await schema['~standard'].validate(value);
|
|
52
|
+
if (result.issues) {
|
|
53
|
+
return {
|
|
54
|
+
success: false,
|
|
55
|
+
issues: result.issues,
|
|
56
|
+
zodError: standardIssuesToZodError(result.issues),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
success: true,
|
|
61
|
+
value: frameworkCast(result.value),
|
|
62
|
+
};
|
|
63
|
+
}
|
package/dist/types/steering.d.ts
CHANGED
package/dist/types/step.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
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';
|
|
@@ -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>;
|
|
@@ -104,11 +105,17 @@ export interface StepLLM<TContext = ContextData, _I = unknown, O = unknown> {
|
|
|
104
105
|
*/
|
|
105
106
|
tools?: Lazy<(Tool | ServerToolSpec)[] | undefined, TContext>;
|
|
106
107
|
/**
|
|
107
|
-
* Structured output: a
|
|
108
|
+
* Structured output: a Standard Schema (assistant text is JSON-parsed and
|
|
108
109
|
* validated) or a streaming `OutputCodec` (fed each text delta, produces
|
|
109
|
-
* the typed value at turn end).
|
|
110
|
+
* the typed value at turn end). Non-Zod schemas can derive the model
|
|
111
|
+
* constraint through StandardJSONSchemaV1 or provide `outputJsonSchema`.
|
|
110
112
|
*/
|
|
111
|
-
output?:
|
|
113
|
+
output?: StandardSchemaV1<unknown, O> | OutputCodec<O>;
|
|
114
|
+
/**
|
|
115
|
+
* Explicit raw JSON Schema override sent to the model. For non-Zod schemas,
|
|
116
|
+
* it takes precedence over StandardJSONSchemaV1 conversion.
|
|
117
|
+
*/
|
|
118
|
+
outputJsonSchema?: Record<string, unknown>;
|
|
112
119
|
params?: ModelParams;
|
|
113
120
|
/** Controls framework event emission for this step. Defaults to `true`. Set `false` to suppress all framework events. A filter function receives `(eventType, data)` and returns `boolean`. */
|
|
114
121
|
emit?: boolean | ((eventType: string, data: Record<string, unknown>) => boolean);
|
|
@@ -138,41 +145,41 @@ export interface StepSubHarness<TContext = ContextData, _I = unknown, O = unknow
|
|
|
138
145
|
settings?: SubHarnessSettings;
|
|
139
146
|
/** System instructions applied on the first message of a fresh session. */
|
|
140
147
|
instructions?: Lazy<string | undefined, TContext>;
|
|
141
|
-
/** When set, the assistant text is JSON-parsed and validated against this
|
|
142
|
-
output?:
|
|
148
|
+
/** When set, the assistant text is JSON-parsed and validated against this Standard Schema. */
|
|
149
|
+
output?: StandardSchemaV1<unknown, O>;
|
|
143
150
|
/** Session reuse + teardown policy across steps. */
|
|
144
151
|
session?: SubHarnessSessionPolicy;
|
|
145
152
|
/** Controls framework event emission for this step. Defaults to `true`. */
|
|
146
153
|
emit?: boolean | ((eventType: string, data: Record<string, unknown>) => boolean);
|
|
147
154
|
}
|
|
148
|
-
/** @public A step that invokes a single tool directly, bypassing the
|
|
149
|
-
export interface
|
|
150
|
-
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';
|
|
151
158
|
id: string;
|
|
152
|
-
tool: Tool<
|
|
159
|
+
tool: Tool<StandardSchemaV1<unknown, I>, StandardSchemaV1<unknown, O>>;
|
|
153
160
|
args?: Partial<I>;
|
|
154
161
|
}
|
|
155
162
|
/** @public A step that dynamically selects and executes one of several possible sub-steps. */
|
|
156
|
-
export interface
|
|
157
|
-
kind: '
|
|
163
|
+
export interface StepConditional<TContext = ContextData, I = unknown, O = unknown> {
|
|
164
|
+
kind: 'conditional';
|
|
158
165
|
id: string;
|
|
159
166
|
route: (input: I, ctx: Context<TContext>) => Step<TContext, I, O> | null | Promise<Step<TContext, I, O> | null>;
|
|
160
167
|
_optimizable?: Step<TContext>[];
|
|
161
168
|
}
|
|
162
|
-
/** @public Union of
|
|
163
|
-
export type
|
|
164
|
-
/** @public
|
|
165
|
-
export interface
|
|
166
|
-
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';
|
|
167
174
|
id: string;
|
|
168
175
|
mode: 'race';
|
|
169
176
|
paths: (input: I, ctx: Context<TContext>) => Step<TContext, I, O>[];
|
|
170
177
|
concurrency?: number;
|
|
171
178
|
_optimizable?: Step<TContext>[];
|
|
172
179
|
}
|
|
173
|
-
/** @public
|
|
174
|
-
export interface
|
|
175
|
-
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';
|
|
176
183
|
id: string;
|
|
177
184
|
mode: 'all';
|
|
178
185
|
paths: (input: I, ctx: Context<TContext>) => Step<TContext, I, O>[];
|
|
@@ -180,9 +187,9 @@ export interface StepForkAll<TContext = ContextData, I = unknown, O = unknown> {
|
|
|
180
187
|
concurrency?: number;
|
|
181
188
|
_optimizable?: Step<TContext>[];
|
|
182
189
|
}
|
|
183
|
-
/** @public
|
|
184
|
-
export interface
|
|
185
|
-
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';
|
|
186
193
|
id: string;
|
|
187
194
|
mode: 'settle';
|
|
188
195
|
paths: (input: I, ctx: Context<TContext>) => Step<TContext, I, O>[];
|
|
@@ -196,8 +203,8 @@ export interface StepForkSettle<TContext = ContextData, I = unknown, O = unknown
|
|
|
196
203
|
* Spawn and detachedSpawn break the inheritance chain.
|
|
197
204
|
* @public
|
|
198
205
|
*/
|
|
199
|
-
export interface
|
|
200
|
-
kind: '
|
|
206
|
+
export interface StepWithContext<TContext = ContextData, I = unknown, O = unknown> {
|
|
207
|
+
kind: 'withContext';
|
|
201
208
|
id: string;
|
|
202
209
|
child: Step<TContext, I, O>;
|
|
203
210
|
context: ContextConfig | ContextLayer[];
|
|
@@ -242,33 +249,33 @@ export interface StepLoop<TContext = ContextData, I = unknown, O = unknown> {
|
|
|
242
249
|
onError?: (error: NoeticError, ctx: Context<TContext>) => 'retry' | 'skip' | 'abort';
|
|
243
250
|
}
|
|
244
251
|
/**
|
|
245
|
-
* Error policy for the `
|
|
252
|
+
* Error policy for the `schedule` operator when its body step throws.
|
|
246
253
|
* - `'continue'` (default): emit a span event recording the error and continue parking.
|
|
247
254
|
* - `'fail'`: re-throw, terminating the operator.
|
|
248
255
|
* @public
|
|
249
256
|
*/
|
|
250
|
-
export type
|
|
257
|
+
export type ScheduleErrorPolicy = 'continue' | 'fail';
|
|
251
258
|
/**
|
|
252
259
|
* A step that runs a body step on a fixed-interval schedule, optionally woken
|
|
253
|
-
* sooner by
|
|
260
|
+
* sooner by an inbox channel. Runs forever until the executing context is cancelled.
|
|
254
261
|
*
|
|
255
|
-
* The operator output is `void` — `
|
|
262
|
+
* The operator output is `void` — `schedule` does not accumulate iteration outputs.
|
|
256
263
|
* The `O` type parameter exists only to anchor the body step's output type.
|
|
257
264
|
*
|
|
258
265
|
* @public
|
|
259
266
|
*/
|
|
260
|
-
export interface
|
|
261
|
-
kind: '
|
|
267
|
+
export interface StepSchedule<TContext = ContextData, I = unknown, O = unknown> {
|
|
268
|
+
kind: 'schedule';
|
|
262
269
|
/** Unique step identifier used in traces and error messages. */
|
|
263
270
|
id: string;
|
|
264
271
|
/** Body step executed on each iteration. */
|
|
265
272
|
step: Step<TContext, I, O>;
|
|
266
273
|
/** Park duration between iterations in milliseconds. Must be >= 0. */
|
|
267
|
-
|
|
274
|
+
interval: number;
|
|
268
275
|
/** Optional channel that wakes the parking interval when any value arrives. */
|
|
269
|
-
|
|
276
|
+
inbox?: Channel<unknown>;
|
|
270
277
|
/** Behavior when `step` throws. Defaults to `'continue'`. */
|
|
271
|
-
onError?:
|
|
278
|
+
onError?: ScheduleErrorPolicy;
|
|
272
279
|
/** Random jitter applied to the park duration in milliseconds. Must be >= 0. Default 0. */
|
|
273
280
|
jitter?: number;
|
|
274
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.). */
|
package/dist/types/tool.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
2
|
import type { FunctionCallItem, FunctionCallOutputItem, Item, ItemSchemaExtensions, ToolResultExtensionItem } from './items.js';
|
|
3
|
-
type
|
|
3
|
+
import type { InferSchemaOutput } from './schema.js';
|
|
4
|
+
type ToolExecutionResult<O extends StandardSchemaV1> = Promise<InferSchemaOutput<O>> | AsyncGenerator<unknown, InferSchemaOutput<O>>;
|
|
4
5
|
/**
|
|
5
6
|
* Declares tool-owned state that the runtime materializes into a ContextLayer.
|
|
6
7
|
* @public
|
|
@@ -39,44 +40,55 @@ export interface UiFragment {
|
|
|
39
40
|
* `tool()` builder and runtime consume.
|
|
40
41
|
* @public
|
|
41
42
|
*/
|
|
42
|
-
export interface ToolUiDeclaration<I extends
|
|
43
|
+
export interface ToolUiDeclaration<I extends StandardSchemaV1 = StandardSchemaV1, O extends StandardSchemaV1 = StandardSchemaV1, E = unknown> {
|
|
43
44
|
/** Rendered as soon as the call streams in — args may be partial. */
|
|
44
|
-
call?(args: Partial<
|
|
45
|
+
call?(args: Partial<InferSchemaOutput<I>>): UiFragment | null;
|
|
45
46
|
/** Re-rendered on each event an AsyncGenerator `execute` yields. Receives all events so far. */
|
|
46
47
|
progress?(events: E[]): UiFragment | null;
|
|
47
48
|
/** Replaces the tool's region on successful completion. */
|
|
48
|
-
result?(output:
|
|
49
|
+
result?(output: InferSchemaOutput<O>, args: InferSchemaOutput<I>): UiFragment | null;
|
|
49
50
|
/** Replaces the tool's region when execution throws. */
|
|
50
|
-
error?(err: unknown, args:
|
|
51
|
+
error?(err: unknown, args: InferSchemaOutput<I>): UiFragment | null;
|
|
51
52
|
}
|
|
52
53
|
/**
|
|
53
54
|
* A tool definition that an LLM can invoke during execution.
|
|
54
55
|
*
|
|
56
|
+
* Input and output schemas accept any Standard Schema v1 implementation
|
|
57
|
+
* (Zod, Valibot, ArkType, …). Zod remains the fast path; other validators
|
|
58
|
+
* can provide JSON Schema through the Standard JSON Schema v1 companion
|
|
59
|
+
* trait or an explicit `inputJsonSchema` override.
|
|
60
|
+
*
|
|
55
61
|
* The runtime passes a `ToolExecutionContext` (from `./tool-context`) as
|
|
56
62
|
* the second argument to `execute`. Callers that need the concrete type
|
|
57
63
|
* should import `Tool` from the package root (`@noetic-tools/core`), which
|
|
58
64
|
* re-exports it with `ToolExecutionContext` substituted in.
|
|
59
65
|
* @public
|
|
60
66
|
*/
|
|
61
|
-
export interface Tool<I extends
|
|
67
|
+
export interface Tool<I extends StandardSchemaV1 = StandardSchemaV1, O extends StandardSchemaV1 = StandardSchemaV1> {
|
|
62
68
|
/** Unique tool name used by the LLM for selection. */
|
|
63
69
|
name: string;
|
|
64
70
|
/** Human-readable description shown to the LLM. */
|
|
65
71
|
description: string;
|
|
66
|
-
/**
|
|
72
|
+
/** Schema validating tool input arguments (any Standard Schema v1). */
|
|
67
73
|
input: I;
|
|
68
|
-
/**
|
|
74
|
+
/** Schema validating tool return value (any Standard Schema v1). */
|
|
69
75
|
output: O;
|
|
70
|
-
/**
|
|
71
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Explicit raw JSON Schema for the tool input, sent to the LLM wire format.
|
|
78
|
+
* For non-Zod schemas, overrides StandardJSONSchemaV1 conversion and serves
|
|
79
|
+
* as the required fallback for validation-only schemas.
|
|
80
|
+
*/
|
|
81
|
+
inputJsonSchema?: Record<string, unknown>;
|
|
82
|
+
/** Optional schema validating streaming events yielded during execution. */
|
|
83
|
+
event?: StandardSchemaV1;
|
|
72
84
|
/** Optional item schemas contributed by this tool for tool call/result extensions. */
|
|
73
85
|
itemSchemas?: Pick<ItemSchemaExtensions, 'toolCalls' | 'toolResults' | 'items'>;
|
|
74
86
|
/** Decorate the harness-created tool result item before it is appended/emitted. */
|
|
75
87
|
decorateResultItem?(params: {
|
|
76
88
|
baseItem: FunctionCallOutputItem;
|
|
77
89
|
callItem: FunctionCallItem;
|
|
78
|
-
args:
|
|
79
|
-
result:
|
|
90
|
+
args: InferSchemaOutput<I>;
|
|
91
|
+
result: InferSchemaOutput<O> | undefined;
|
|
80
92
|
output: string;
|
|
81
93
|
error?: boolean;
|
|
82
94
|
}): Item | ToolResultExtensionItem;
|
|
@@ -86,7 +98,7 @@ export interface Tool<I extends ZodTypeAny = ZodTypeAny, O extends ZodTypeAny =
|
|
|
86
98
|
* this type a dependency leaf. Use `tool()` from `builders/` or cast at
|
|
87
99
|
* the call site to get a typed handle.
|
|
88
100
|
*/
|
|
89
|
-
execute(args:
|
|
101
|
+
execute(args: InferSchemaOutput<I>, toolCtx: unknown): ToolExecutionResult<O>;
|
|
90
102
|
/** When true, execution pauses for human approval before running. */
|
|
91
103
|
needsApproval?: boolean;
|
|
92
104
|
/** Optional context declaration — the runtime generates a ContextLayer from this. */
|
|
@@ -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.1
|
|
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",
|
|
@@ -55,6 +55,7 @@
|
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
57
|
"@openrouter/agent": "^0.6.0",
|
|
58
|
+
"@standard-schema/spec": "1.1.0",
|
|
58
59
|
"zod": "^4.0.0"
|
|
59
60
|
},
|
|
60
61
|
"scripts": {
|
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
|