@noetic-tools/types 2.2.0 → 3.0.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 +3 -2
- package/dist/index.js +3 -2
- package/dist/schemas/item.d.ts +1 -1
- package/dist/schemas/item.js +1 -1
- package/dist/types/channel.d.ts +4 -2
- 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 +42 -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 +39 -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
|
@@ -0,0 +1,39 @@
|
|
|
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>;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* @noetic-tools/types — foundational type contracts and primitives shared
|
|
3
3
|
* across the Noetic framework.
|
|
4
4
|
*/
|
|
5
|
+
export * from './deprecated.js';
|
|
5
6
|
export * from './errors/noetic-config-error.js';
|
|
6
7
|
export * from './errors/noetic-error.js';
|
|
7
8
|
export * from './schemas/item.js';
|
|
@@ -9,15 +10,15 @@ export * from './schemas/workflow.js';
|
|
|
9
10
|
export * from './types/channel.js';
|
|
10
11
|
export * from './types/common.js';
|
|
11
12
|
export * from './types/context.js';
|
|
13
|
+
export * from './types/context-layer.js';
|
|
12
14
|
export * from './types/context-parts/item-log.js';
|
|
13
15
|
export * from './types/context-parts/layer-usage.js';
|
|
16
|
+
export * from './types/context-scope.js';
|
|
14
17
|
export * from './types/detached.js';
|
|
15
18
|
export * from './types/error.js';
|
|
16
19
|
export * from './types/fs-adapter.js';
|
|
17
20
|
export * from './types/harness-result.js';
|
|
18
21
|
export * from './types/items.js';
|
|
19
|
-
export * from './types/memory.js';
|
|
20
|
-
export * from './types/memory-context.js';
|
|
21
22
|
export * from './types/observability.js';
|
|
22
23
|
export * from './types/output-codec.js';
|
|
23
24
|
export * from './types/runtime.js';
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* @noetic-tools/types — foundational type contracts and primitives shared
|
|
3
3
|
* across the Noetic framework.
|
|
4
4
|
*/
|
|
5
|
+
export * from './deprecated.js';
|
|
5
6
|
export * from './errors/noetic-config-error.js';
|
|
6
7
|
export * from './errors/noetic-error.js';
|
|
7
8
|
export * from './schemas/item.js';
|
|
@@ -9,15 +10,15 @@ export * from './schemas/workflow.js';
|
|
|
9
10
|
export * from './types/channel.js';
|
|
10
11
|
export * from './types/common.js';
|
|
11
12
|
export * from './types/context.js';
|
|
13
|
+
export * from './types/context-layer.js';
|
|
12
14
|
export * from './types/context-parts/item-log.js';
|
|
13
15
|
export * from './types/context-parts/layer-usage.js';
|
|
16
|
+
export * from './types/context-scope.js';
|
|
14
17
|
export * from './types/detached.js';
|
|
15
18
|
export * from './types/error.js';
|
|
16
19
|
export * from './types/fs-adapter.js';
|
|
17
20
|
export * from './types/harness-result.js';
|
|
18
21
|
export * from './types/items.js';
|
|
19
|
-
export * from './types/memory.js';
|
|
20
|
-
export * from './types/memory-context.js';
|
|
21
22
|
export * from './types/observability.js';
|
|
22
23
|
export * from './types/output-codec.js';
|
|
23
24
|
export * from './types/runtime.js';
|
package/dist/schemas/item.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ export declare const ItemSchema: z.ZodCustom<Item, Item>;
|
|
|
24
24
|
type ItemSchemaCategory = keyof Required<ItemSchemaExtensions>;
|
|
25
25
|
export declare function mergeExtensions(a: ItemSchemaExtensions | undefined, b: ItemSchemaExtensions | undefined): ItemSchemaExtensions;
|
|
26
26
|
/**
|
|
27
|
-
* @public Runtime item validator with optional tool,
|
|
27
|
+
* @public Runtime item validator with optional tool, context-layer, and harness extension schemas.
|
|
28
28
|
*
|
|
29
29
|
* Extension schemas are pure shape validators (gate, not normalizer): on
|
|
30
30
|
* match the original value is returned unchanged, including fields the schema
|
package/dist/schemas/item.js
CHANGED
|
@@ -97,7 +97,7 @@ function schemaMismatch(category) {
|
|
|
97
97
|
});
|
|
98
98
|
}
|
|
99
99
|
/**
|
|
100
|
-
* @public Runtime item validator with optional tool,
|
|
100
|
+
* @public Runtime item validator with optional tool, context-layer, and harness extension schemas.
|
|
101
101
|
*
|
|
102
102
|
* Extension schemas are pure shape validators (gate, not normalizer): on
|
|
103
103
|
* match the original value is returned unchanged, including fields the schema
|
package/dist/types/channel.d.ts
CHANGED
|
@@ -14,11 +14,13 @@ export interface Channel<T> {
|
|
|
14
14
|
readonly capacity?: number;
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
|
-
* A channel
|
|
17
|
+
* A channel reachable from outside the execution tree: writable via
|
|
18
|
+
* `getChannelHandle` (e.g. user input) and readable via `getChannelStream`
|
|
19
|
+
* (e.g. approval requests posted to a chat platform).
|
|
18
20
|
* @public
|
|
19
21
|
*/
|
|
20
22
|
export interface ExternalChannel<T> extends Channel<T> {
|
|
21
|
-
/** Marker indicating the channel accepts
|
|
23
|
+
/** Marker indicating the channel accepts external readers and writers. */
|
|
22
24
|
readonly external: true;
|
|
23
25
|
}
|
|
24
26
|
/** @public Handle for sending messages to a channel and checking its closed state. */
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type { ZodType } from 'zod';
|
|
2
2
|
import type { LLMResponse } from './common.js';
|
|
3
3
|
import type { ItemLog } from './context-parts/item-log.js';
|
|
4
|
+
import type { ContextScope, ExecutionContext, ExecutionOutcome } from './context-scope.js';
|
|
4
5
|
import type { Item, ItemSchemaExtensions } from './items.js';
|
|
5
|
-
import type { ExecutionContext, ExecutionOutcome, MemoryScope } from './memory-context.js';
|
|
6
6
|
import type { AfterModelCallParams, AfterModelCallResult, BeforeToolCallParams, BeforeToolCallResult } from './steering.js';
|
|
7
|
-
/** @public Isolation scope controlling how a
|
|
7
|
+
/** @public Isolation scope controlling how a context layer's state is keyed and shared. */
|
|
8
8
|
export type BudgetConfig = number | {
|
|
9
9
|
min: number;
|
|
10
10
|
max: number;
|
|
11
11
|
} | 'auto';
|
|
12
|
-
/** @public Per-hook timeout overrides in milliseconds for a
|
|
12
|
+
/** @public Per-hook timeout overrides in milliseconds for a context layer. */
|
|
13
13
|
export interface LayerTimeouts {
|
|
14
14
|
init?: number;
|
|
15
15
|
recall?: number;
|
|
@@ -23,13 +23,13 @@ export interface LayerTimeouts {
|
|
|
23
23
|
onItemAppend?: number;
|
|
24
24
|
projectHistory?: number;
|
|
25
25
|
}
|
|
26
|
-
/** @public A read-only data projection from layer state, accessible via `ctx.
|
|
26
|
+
/** @public A read-only data projection from layer state, accessible via `ctx.context['layerId'].prop`. */
|
|
27
27
|
export interface LayerDataDecl<T = unknown, TState = unknown> {
|
|
28
28
|
kind: 'data';
|
|
29
29
|
/** Project a value from the layer's current state. Method syntax enables bivariant assignability. */
|
|
30
30
|
read(state: TState): T;
|
|
31
31
|
}
|
|
32
|
-
/** @public A callable function backed by layer state, accessible via `ctx.
|
|
32
|
+
/** @public A callable function backed by layer state, accessible via `ctx.context['layerId'].fn()` or as an LLM tool. */
|
|
33
33
|
export interface LayerFunctionDecl<TInput = unknown, TOutput = unknown, TState = unknown> {
|
|
34
34
|
kind: 'function';
|
|
35
35
|
/** Human-readable description (used as tool description when exposed to LLM). */
|
|
@@ -44,26 +44,26 @@ export interface LayerFunctionDecl<TInput = unknown, TOutput = unknown, TState =
|
|
|
44
44
|
state?: TState;
|
|
45
45
|
}>;
|
|
46
46
|
}
|
|
47
|
-
/** @public Map of named data and function declarations exposed by a
|
|
47
|
+
/** @public Map of named data and function declarations exposed by a context layer. */
|
|
48
48
|
export type LayerProvides = Record<string, LayerDataDecl | LayerFunctionDecl>;
|
|
49
49
|
/**
|
|
50
50
|
* Mapped type that produces a flat handle from a layer's `provides` declaration.
|
|
51
51
|
* Data entries become direct property reads; function entries become callable async methods.
|
|
52
52
|
* @public
|
|
53
53
|
*/
|
|
54
|
-
export type LayerHandle<T extends
|
|
54
|
+
export type LayerHandle<T extends ContextLayer> = T extends {
|
|
55
55
|
provides: infer P;
|
|
56
56
|
} ? {
|
|
57
57
|
[K in keyof P]: P[K] extends LayerDataDecl<infer D, unknown> ? D : P[K] extends LayerFunctionDecl<infer I, infer O, unknown> ? (args: I) => Promise<O> : never;
|
|
58
58
|
} : Record<string, never>;
|
|
59
59
|
/** @public Object keyed by layer ID, where each value is a resolved handle for that layer's provides. */
|
|
60
|
-
export type
|
|
60
|
+
export type ContextData = Readonly<Record<string, Record<string, unknown>>>;
|
|
61
61
|
/**
|
|
62
|
-
* Maps a tuple of
|
|
62
|
+
* Maps a tuple of context layers to a typed object keyed by layer ID.
|
|
63
63
|
* Each layer's `provides` is flattened: data → value type, function → async callable.
|
|
64
64
|
* @public
|
|
65
65
|
*/
|
|
66
|
-
export type
|
|
66
|
+
export type InferContextShape<T extends readonly ContextLayer[]> = {
|
|
67
67
|
[L in T[number] as L extends {
|
|
68
68
|
readonly id: infer Id extends string;
|
|
69
69
|
} ? Id : never]: L extends {
|
|
@@ -73,29 +73,29 @@ export type InferMemoryShape<T extends readonly MemoryLayer[]> = {
|
|
|
73
73
|
} : Record<string, never>;
|
|
74
74
|
};
|
|
75
75
|
/**
|
|
76
|
-
* Typed wrapper around a tuple of
|
|
77
|
-
* for compile-time inference via `
|
|
76
|
+
* Typed wrapper around a tuple of context layers. Preserves individual layer types
|
|
77
|
+
* for compile-time inference via `InferContext<typeof config>`.
|
|
78
78
|
* @public
|
|
79
79
|
*/
|
|
80
|
-
export interface
|
|
80
|
+
export interface ContextConfig<TLayers extends readonly ContextLayer[] = readonly ContextLayer[]> {
|
|
81
81
|
readonly layers: TLayers;
|
|
82
|
-
/** Phantom field carrying the inferred
|
|
83
|
-
readonly _shape:
|
|
82
|
+
/** Phantom field carrying the inferred context shape. Never accessed at runtime. */
|
|
83
|
+
readonly _shape: InferContextShape<TLayers>;
|
|
84
84
|
}
|
|
85
85
|
/**
|
|
86
|
-
* Extract the typed
|
|
86
|
+
* Extract the typed context shape from a ContextConfig.
|
|
87
87
|
* Constrains structurally on the phantom `_shape` field rather than on
|
|
88
|
-
* `
|
|
88
|
+
* `ContextConfig` itself: `ContextConfig` is invariant in `TLayers` (the `_shape`
|
|
89
89
|
* field carries it in an invariant position), so a concrete
|
|
90
|
-
* `
|
|
91
|
-
* `
|
|
92
|
-
* `_shape`, this constraint accepts any config the `
|
|
93
|
-
* @public Usage: `type Mem =
|
|
90
|
+
* `ContextConfig<readonly [SomeLayer]>` does not satisfy the defaulted
|
|
91
|
+
* `ContextConfig<readonly ContextLayer[]>`. Since `InferContext` only reads
|
|
92
|
+
* `_shape`, this constraint accepts any config the `context()` builder produces.
|
|
93
|
+
* @public Usage: `type Mem = InferContext<typeof config>`
|
|
94
94
|
*/
|
|
95
|
-
export type
|
|
95
|
+
export type InferContext<T extends {
|
|
96
96
|
readonly _shape: unknown;
|
|
97
97
|
}> = T['_shape'];
|
|
98
|
-
/** @public Well-known ordering slots for positioning
|
|
98
|
+
/** @public Well-known ordering slots for positioning context layers in the recall/store pipeline. */
|
|
99
99
|
export declare const Slot: {
|
|
100
100
|
readonly REMINDER: 80;
|
|
101
101
|
readonly STEERING: 90;
|
|
@@ -107,7 +107,7 @@ export declare const Slot: {
|
|
|
107
107
|
readonly RAG: 350;
|
|
108
108
|
readonly SEMANTIC_RECALL: 400;
|
|
109
109
|
};
|
|
110
|
-
/** @public Low-level key-value persistence backend used by scoped storage and
|
|
110
|
+
/** @public Low-level key-value persistence backend used by scoped storage and context layers. */
|
|
111
111
|
export interface StorageAdapter {
|
|
112
112
|
get<T>(key: string): Promise<T | null>;
|
|
113
113
|
set<T>(key: string, value: T): Promise<void>;
|
|
@@ -129,7 +129,7 @@ export interface StorageAdapter {
|
|
|
129
129
|
*/
|
|
130
130
|
getMany?<T>(keys: string[]): Promise<Map<string, T>>;
|
|
131
131
|
}
|
|
132
|
-
/** @public Scope-namespaced storage interface provided to
|
|
132
|
+
/** @public Scope-namespaced storage interface provided to context layer init hooks. */
|
|
133
133
|
export interface ScopedStorage {
|
|
134
134
|
get<T>(key: string): Promise<T | null>;
|
|
135
135
|
set<T>(key: string, value: T): Promise<void>;
|
|
@@ -143,17 +143,17 @@ export interface ScopedStorage {
|
|
|
143
143
|
*/
|
|
144
144
|
getMany<T>(keys: string[]): Promise<Map<string, T>>;
|
|
145
145
|
}
|
|
146
|
-
/** @public Parameters passed to a
|
|
146
|
+
/** @public Parameters passed to a context layer's `init` hook. */
|
|
147
147
|
export interface InitParams {
|
|
148
148
|
storage: ScopedStorage;
|
|
149
149
|
scopeKey: string;
|
|
150
150
|
ctx: ExecutionContext;
|
|
151
151
|
}
|
|
152
|
-
/** @public Value returned by a
|
|
152
|
+
/** @public Value returned by a context layer's `init` hook, carrying the initial state. */
|
|
153
153
|
export interface InitResult<TState> {
|
|
154
154
|
state: TState;
|
|
155
155
|
}
|
|
156
|
-
/** @public Parameters passed to a
|
|
156
|
+
/** @public Parameters passed to a context layer's `recall` hook before each LLM call. */
|
|
157
157
|
export interface RecallParams<TState> {
|
|
158
158
|
log: ItemLog;
|
|
159
159
|
query: string;
|
|
@@ -161,13 +161,13 @@ export interface RecallParams<TState> {
|
|
|
161
161
|
state: TState;
|
|
162
162
|
budget: number;
|
|
163
163
|
}
|
|
164
|
-
/** @public Value returned by a
|
|
164
|
+
/** @public Value returned by a context layer's `recall` hook, containing items and token count. */
|
|
165
165
|
export interface RecallResult<TState = unknown> {
|
|
166
166
|
items: Item[];
|
|
167
167
|
tokenCount: number;
|
|
168
168
|
state?: TState;
|
|
169
169
|
}
|
|
170
|
-
/** @public Parameters passed to a
|
|
170
|
+
/** @public Parameters passed to a context layer's `store` hook after each LLM response. */
|
|
171
171
|
export interface StoreParams<TState> {
|
|
172
172
|
newItems: Item[];
|
|
173
173
|
log: ItemLog;
|
|
@@ -175,21 +175,21 @@ export interface StoreParams<TState> {
|
|
|
175
175
|
ctx: ExecutionContext;
|
|
176
176
|
state: TState;
|
|
177
177
|
}
|
|
178
|
-
/** @public Value returned by a
|
|
178
|
+
/** @public Value returned by a context layer's `store` hook, carrying the updated state. */
|
|
179
179
|
export interface StoreResult<TState> {
|
|
180
180
|
state: TState;
|
|
181
181
|
}
|
|
182
|
-
/** @public Parameters passed to a
|
|
182
|
+
/** @public Parameters passed to a context layer's `onSpawn` hook when a child execution starts. */
|
|
183
183
|
export interface SpawnParams<TState> {
|
|
184
184
|
parentState: TState;
|
|
185
185
|
childCtx: ExecutionContext;
|
|
186
186
|
}
|
|
187
|
-
/** @public Value returned by a
|
|
187
|
+
/** @public Value returned by a context layer's `onSpawn` hook with the child's initial state. */
|
|
188
188
|
export interface SpawnResult<TState> {
|
|
189
189
|
childState: TState | null;
|
|
190
190
|
items?: Item[];
|
|
191
191
|
}
|
|
192
|
-
/** @public Parameters passed to a
|
|
192
|
+
/** @public Parameters passed to a context layer's `onReturn` hook when a child execution completes. */
|
|
193
193
|
export interface ReturnParams<TState> {
|
|
194
194
|
childState: TState;
|
|
195
195
|
childLog: ItemLog;
|
|
@@ -203,23 +203,23 @@ export interface ReturnParams<TState> {
|
|
|
203
203
|
*/
|
|
204
204
|
childCtx: ExecutionContext;
|
|
205
205
|
}
|
|
206
|
-
/** @public Value returned by a
|
|
206
|
+
/** @public Value returned by a context layer's `onReturn` hook with the merged parent state. */
|
|
207
207
|
export interface ReturnResult<TState> {
|
|
208
208
|
parentState: TState;
|
|
209
209
|
result?: unknown;
|
|
210
210
|
}
|
|
211
|
-
/** @public Parameters passed to a
|
|
211
|
+
/** @public Parameters passed to a context layer's `onComplete` hook at execution end. */
|
|
212
212
|
export interface CompleteParams<TState> {
|
|
213
213
|
log: ItemLog;
|
|
214
214
|
ctx: ExecutionContext;
|
|
215
215
|
state: TState;
|
|
216
216
|
outcome: ExecutionOutcome;
|
|
217
217
|
}
|
|
218
|
-
/** @public Parameters passed to a
|
|
218
|
+
/** @public Parameters passed to a context layer's `dispose` hook during teardown. */
|
|
219
219
|
export interface DisposeParams<TState> {
|
|
220
220
|
state: TState;
|
|
221
221
|
}
|
|
222
|
-
/** @public Parameters passed to a
|
|
222
|
+
/** @public Parameters passed to a context layer's `projectHistory` hook to project the history portion of the LLM context window. */
|
|
223
223
|
export interface ProjectHistoryParams<TState> {
|
|
224
224
|
/** Full historical items from the item log, uncapped. */
|
|
225
225
|
items: ReadonlyArray<Item>;
|
|
@@ -228,14 +228,14 @@ export interface ProjectHistoryParams<TState> {
|
|
|
228
228
|
/** Layer's current state snapshot. */
|
|
229
229
|
state: TState;
|
|
230
230
|
}
|
|
231
|
-
/** @public Value returned by a
|
|
231
|
+
/** @public Value returned by a context layer's `projectHistory` hook, carrying the projected items. */
|
|
232
232
|
export interface ProjectHistoryResult {
|
|
233
233
|
/** Items to send to the LLM as history. Typically a subset of the input. */
|
|
234
234
|
items: ReadonlyArray<Item>;
|
|
235
235
|
}
|
|
236
236
|
/** @public Controls which layers re-run recall() when a re-render is triggered. */
|
|
237
237
|
export type RerenderScope = 'self' | 'slot-after' | 'all';
|
|
238
|
-
/** @public Parameters passed to a
|
|
238
|
+
/** @public Parameters passed to a context layer's `onItemAppend` hook when input items are about to be appended. */
|
|
239
239
|
export interface OnItemAppendParams<TState> {
|
|
240
240
|
/** Items to be appended (may have been transformed by prior layers in the pipeline). */
|
|
241
241
|
items: Item[];
|
|
@@ -246,7 +246,7 @@ export interface OnItemAppendParams<TState> {
|
|
|
246
246
|
/** Layer's current state snapshot. */
|
|
247
247
|
state: TState;
|
|
248
248
|
}
|
|
249
|
-
/** @public Value returned by a
|
|
249
|
+
/** @public Value returned by a context layer's `onItemAppend` hook. */
|
|
250
250
|
export interface OnItemAppendResult<TState> {
|
|
251
251
|
/**
|
|
252
252
|
* Items to actually append to the log.
|
|
@@ -265,8 +265,8 @@ export interface OnItemAppendResult<TState> {
|
|
|
265
265
|
/** Which layers to re-recall (default: 'slot-after'). */
|
|
266
266
|
scope?: RerenderScope;
|
|
267
267
|
}
|
|
268
|
-
/** @public Lifecycle hook implementations for a
|
|
269
|
-
export interface
|
|
268
|
+
/** @public Lifecycle hook implementations for a context layer. Method syntax enables bivariant assignability for typed layers. */
|
|
269
|
+
export interface ContextLayerHooks<TState = unknown> {
|
|
270
270
|
init?(params: InitParams): Promise<InitResult<TState>>;
|
|
271
271
|
recall?(params: RecallParams<TState>): Promise<RecallResult<TState> | string | null>;
|
|
272
272
|
store?(params: StoreParams<TState>): Promise<StoreResult<TState> | undefined>;
|
|
@@ -299,10 +299,10 @@ export interface MemoryHooks<TState = unknown> {
|
|
|
299
299
|
projectHistory?(params: ProjectHistoryParams<TState>): Promise<ProjectHistoryResult>;
|
|
300
300
|
}
|
|
301
301
|
/**
|
|
302
|
-
* A composable
|
|
302
|
+
* A composable context layer that participates in the recall/store lifecycle.
|
|
303
303
|
* @public
|
|
304
304
|
*/
|
|
305
|
-
export interface
|
|
305
|
+
export interface ContextLayer<TState = unknown> {
|
|
306
306
|
/** Unique identifier for this layer instance. */
|
|
307
307
|
id: string;
|
|
308
308
|
/** Human-readable name for debugging and trace output. */
|
|
@@ -310,16 +310,16 @@ export interface MemoryLayer<TState = unknown> {
|
|
|
310
310
|
/** Ordering slot (lower = recalled first). Use `Slot` constants for well-known positions. */
|
|
311
311
|
slot: number;
|
|
312
312
|
/** Scope controlling state isolation: `'thread'`, `'resource'`, `'global'`, or `'execution'`. */
|
|
313
|
-
scope:
|
|
313
|
+
scope: ContextScope;
|
|
314
314
|
/** Token budget: a fixed number, a `{ min, max }` range, or `'auto'` for dynamic allocation. */
|
|
315
315
|
budget?: BudgetConfig;
|
|
316
316
|
/** Lifecycle hooks invoked by the runtime at each phase (init, recall, store, etc.). */
|
|
317
|
-
hooks:
|
|
317
|
+
hooks: ContextLayerHooks<TState>;
|
|
318
318
|
/** Per-hook timeout overrides in ms. */
|
|
319
319
|
timeouts?: Partial<LayerTimeouts>;
|
|
320
320
|
/**
|
|
321
321
|
* What to do when this layer's `init` hook throws.
|
|
322
|
-
* - `'throw'` (default): surface the error and abort the execution —
|
|
322
|
+
* - `'throw'` (default): surface the error and abort the execution — context is
|
|
323
323
|
* load-bearing, and silent disabling hides failures (and, for the steering
|
|
324
324
|
* layer, would fail *open*).
|
|
325
325
|
* - `'disable'`: log a diagnostic and run the execution without this layer
|
|
@@ -337,9 +337,9 @@ export interface MemoryLayer<TState = unknown> {
|
|
|
337
337
|
* ignoring this field.
|
|
338
338
|
*/
|
|
339
339
|
recallMode?: 'atomic' | 'eventual';
|
|
340
|
-
/** Typed functions and data exposed to code steps via `ctx.
|
|
340
|
+
/** Typed functions and data exposed to code steps via `ctx.context['layerId']` and automatically as LLM tools. */
|
|
341
341
|
provides?: LayerProvides;
|
|
342
|
-
/** Optional item schemas contributed by this layer, primarily for developer-role
|
|
342
|
+
/** Optional item schemas contributed by this layer, primarily for developer-role context items. */
|
|
343
343
|
itemSchemas?: Pick<ItemSchemaExtensions, 'developerMessages' | 'items'>;
|
|
344
344
|
/** Default re-render timing when `onItemAppend` requests a re-render. */
|
|
345
345
|
rerenderTiming?: 'immediate' | 'batched';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//#endregion
|
|
2
|
-
/** @public Well-known ordering slots for positioning
|
|
2
|
+
/** @public Well-known ordering slots for positioning context layers in the recall/store pipeline. */
|
|
3
3
|
export const Slot = {
|
|
4
4
|
REMINDER: 80,
|
|
5
5
|
STEERING: 90,
|
|
@@ -2,17 +2,17 @@ import type { LLMResponse } from './common.js';
|
|
|
2
2
|
import type { FsAdapter } from './fs-adapter.js';
|
|
3
3
|
import type { Item } from './items.js';
|
|
4
4
|
import type { ShellAdapter } from './shell-adapter.js';
|
|
5
|
-
/** @public Isolation scope controlling how a
|
|
6
|
-
export type
|
|
7
|
-
/** @public Terminal outcome of an execution run, reported to
|
|
5
|
+
/** @public Isolation scope controlling how a context layer's state is keyed and shared. */
|
|
6
|
+
export type ContextScope = 'thread' | 'resource' | 'global' | 'execution';
|
|
7
|
+
/** @public Terminal outcome of an execution run, reported to context layers on completion. */
|
|
8
8
|
export type ExecutionOutcome = 'success' | 'failure' | 'aborted';
|
|
9
|
-
/** @public Minimal model-call surface exposed to
|
|
10
|
-
export interface
|
|
9
|
+
/** @public Minimal model-call surface exposed to context-layer hooks. */
|
|
10
|
+
export interface LayerCallModelRequest {
|
|
11
11
|
model: string;
|
|
12
12
|
items: ReadonlyArray<Item>;
|
|
13
13
|
instructions?: string;
|
|
14
14
|
}
|
|
15
|
-
/** @public Runtime metadata available to
|
|
15
|
+
/** @public Runtime metadata available to context layer hooks during each lifecycle phase. */
|
|
16
16
|
export interface ExecutionContext {
|
|
17
17
|
executionId: string;
|
|
18
18
|
threadId: string;
|
|
@@ -28,12 +28,12 @@ export interface ExecutionContext {
|
|
|
28
28
|
fs: FsAdapter;
|
|
29
29
|
/** Shell adapter for virtual or real shell command execution. */
|
|
30
30
|
shell: ShellAdapter;
|
|
31
|
-
callModel?: (request:
|
|
31
|
+
callModel?: (request: LayerCallModelRequest) => Promise<LLMResponse>;
|
|
32
32
|
tokenize(text: string): number;
|
|
33
33
|
trace: {
|
|
34
34
|
setAttribute(key: string, value: string | number | boolean): void;
|
|
35
35
|
addEvent(name: string, attributes?: Record<string, string | number | boolean>): void;
|
|
36
36
|
};
|
|
37
|
-
/** Snapshot a sibling
|
|
37
|
+
/** Snapshot a sibling context layer's state by its `layer.id`. */
|
|
38
38
|
readLayerState<T>(layerId: string): T | undefined;
|
|
39
39
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|