@noetic-tools/core 0.2.0 → 0.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/adapters/in-memory-fs-adapter.d.ts +1 -1
- package/dist/adapters/in-memory-fs-adapter.js +1 -1
- package/dist/adapters/in-memory-shell-adapter.d.ts +1 -1
- package/dist/adapters/in-memory-subprocess/manifest-persistence.d.ts +2 -2
- package/dist/adapters/in-memory-subprocess/metadata.d.ts +1 -1
- package/dist/adapters/in-memory-subprocess/types.d.ts +2 -2
- package/dist/adapters/in-memory-subprocess-adapter.d.ts +1 -1
- package/dist/adapters/openrouter.d.ts +2 -6
- package/dist/adapters/openrouter.js +1 -4
- package/dist/builders/channel-builder.d.ts +1 -1
- package/dist/builders/control-flow-builders.d.ts +2 -3
- package/dist/builders/control-flow-builders.js +1 -2
- package/dist/builders/every.d.ts +2 -3
- package/dist/builders/every.js +1 -1
- package/dist/builders/layer-provides-builders.d.ts +1 -1
- package/dist/builders/layer-provides-builders.js +1 -1
- package/dist/builders/loop-builder.d.ts +2 -2
- package/dist/builders/loop-builder.js +1 -1
- package/dist/builders/memory-builder.d.ts +1 -1
- package/dist/builders/memory-builder.js +1 -1
- package/dist/builders/provide-builder.d.ts +2 -2
- package/dist/builders/provide-builder.js +1 -1
- package/dist/builders/spawn-builder.d.ts +2 -3
- package/dist/builders/spawn-builder.js +1 -1
- package/dist/builders/step-builders.d.ts +2 -6
- package/dist/builders/step-builders.js +1 -1
- package/dist/builders/tool-builder.d.ts +1 -3
- package/dist/builders/tool-builder.js +1 -1
- package/dist/builders/workflow-hydrator.d.ts +2 -3
- package/dist/builders/workflow-hydrator.js +1 -2
- package/dist/conditions/conditions.d.ts +2 -3
- package/dist/conditions/conditions.js +1 -1
- package/dist/harness/agent-harness.d.ts +13 -3
- package/dist/harness/agent-harness.js +48 -5
- package/dist/harness/deps/memory.d.ts +2 -5
- package/dist/harness/deps/memory.js +1 -4
- package/dist/harness/deps/types.d.ts +3 -16
- package/dist/harness/deps/types.js +1 -1
- package/dist/harness/model-call.d.ts +1 -3
- package/dist/harness/model-call.js +1 -2
- package/dist/harness/model-schema.d.ts +2 -4
- package/dist/harness/model-schema.js +1 -1
- package/dist/index.d.ts +28 -49
- package/dist/index.js +9 -27
- package/dist/interpreter/action-deps.d.ts +4 -8
- package/dist/interpreter/action-deps.js +2 -6
- package/dist/interpreter/action-types.d.ts +3 -8
- package/dist/interpreter/action-types.js +1 -1
- package/dist/interpreter/collect-tools.d.ts +1 -2
- package/dist/interpreter/collect-tools.js +1 -1
- package/dist/interpreter/execute-action.js +104 -26
- package/dist/interpreter/execute-control.d.ts +1 -2
- package/dist/interpreter/execute-control.js +1 -3
- package/dist/interpreter/execute.d.ts +2 -3
- package/dist/interpreter/execute.js +1 -2
- package/dist/interpreter/message-helpers.d.ts +1 -1
- package/dist/interpreter/message-helpers.js +1 -1
- package/dist/interpreter/step-dispatcher.d.ts +2 -5
- package/dist/interpreter/typeguards.d.ts +3 -4
- package/dist/interpreter/typeguards.js +1 -1
- package/dist/observability/span-impl.d.ts +1 -1
- package/dist/observability/trace-exporter.d.ts +1 -1
- package/dist/patterns/dynamic-workflow.d.ts +2 -5
- package/dist/patterns/dynamic-workflow.js +1 -2
- package/dist/patterns/flow.d.ts +2 -2
- package/dist/patterns/flow.js +1 -1
- package/dist/patterns/interview.d.ts +2 -2
- package/dist/patterns/interview.js +1 -1
- package/dist/patterns/plans.d.ts +2 -3
- package/dist/patterns/plans.js +1 -1
- package/dist/patterns/ralph-wiggum.d.ts +2 -3
- package/dist/patterns/react.d.ts +2 -3
- package/dist/portable/memory-layers.d.ts +1 -7
- package/dist/portable/memory-layers.js +1 -7
- package/dist/portable.d.ts +2 -2
- package/dist/portable.js +2 -2
- package/dist/runtime/broadcaster-utils.d.ts +1 -1
- package/dist/runtime/channel-store.d.ts +1 -1
- package/dist/runtime/channel-store.js +1 -2
- package/dist/runtime/context-deps.d.ts +3 -3
- package/dist/runtime/context-deps.js +2 -2
- package/dist/runtime/context-type-deps.d.ts +2 -11
- package/dist/runtime/cwd-helpers.d.ts +1 -1
- package/dist/runtime/detached-handle.d.ts +2 -3
- package/dist/runtime/detached-handle.js +1 -3
- package/dist/runtime/durable/checkpoint-store.d.ts +1 -1
- package/dist/runtime/durable/checkpoint-store.js +1 -1
- package/dist/runtime/durable/harness-checkpoints.d.ts +2 -5
- package/dist/runtime/durable/runnable-loop.d.ts +1 -3
- package/dist/runtime/durable/session-seed.d.ts +1 -1
- package/dist/runtime/durable/stall-nudge.d.ts +1 -1
- package/dist/runtime/event-broadcaster.d.ts +1 -1
- package/dist/runtime/in-memory-storage.d.ts +1 -1
- package/dist/runtime/in-memory-storage.js +1 -1
- package/dist/runtime/item-log-impl.d.ts +1 -3
- package/dist/runtime/item-log-impl.js +1 -1
- package/dist/runtime/message-queue.d.ts +1 -2
- package/dist/runtime/session-runner.d.ts +1 -4
- package/dist/runtime/session-streams.d.ts +1 -2
- package/dist/runtime/session-streams.js +1 -1
- package/dist/runtime/step-registry.d.ts +2 -2
- package/dist/runtime/step-registry.js +1 -2
- package/dist/runtime/tool-memory.d.ts +1 -3
- package/dist/types/mutable-context.d.ts +2 -3
- package/dist/types/step-registrar.d.ts +1 -1
- package/dist/unstable.d.ts +5 -9
- package/dist/unstable.js +3 -6
- package/dist/until/combinators.d.ts +1 -1
- package/dist/until/never.d.ts +1 -1
- package/dist/until/predicates.d.ts +2 -2
- package/package.json +6 -4
- package/dist/errors/noetic-config-error.d.ts +0 -41
- package/dist/errors/noetic-config-error.js +0 -44
- package/dist/errors/noetic-error.d.ts +0 -18
- package/dist/errors/noetic-error.js +0 -54
- package/dist/memory/budget.d.ts +0 -23
- package/dist/memory/budget.js +0 -117
- package/dist/memory/exec-context-factory.d.ts +0 -25
- package/dist/memory/exec-context-factory.js +0 -30
- package/dist/memory/flow-schema.d.ts +0 -52
- package/dist/memory/flow-schema.js +0 -102
- package/dist/memory/function-call-utils.d.ts +0 -6
- package/dist/memory/function-call-utils.js +0 -27
- package/dist/memory/layer-api.d.ts +0 -14
- package/dist/memory/layer-api.js +0 -91
- package/dist/memory/layer-lifecycle.d.ts +0 -160
- package/dist/memory/layer-lifecycle.js +0 -552
- package/dist/memory/layer-provides.d.ts +0 -32
- package/dist/memory/layer-provides.js +0 -33
- package/dist/memory/layer-usage.d.ts +0 -16
- package/dist/memory/layer-usage.js +0 -54
- package/dist/memory/layers/durable-task-state.d.ts +0 -79
- package/dist/memory/layers/durable-task-state.js +0 -118
- package/dist/memory/layers/file-reference.d.ts +0 -55
- package/dist/memory/layers/file-reference.js +0 -594
- package/dist/memory/layers/history-window.d.ts +0 -29
- package/dist/memory/layers/history-window.js +0 -114
- package/dist/memory/layers/observational-memory.d.ts +0 -53
- package/dist/memory/layers/observational-memory.js +0 -109
- package/dist/memory/layers/plan.d.ts +0 -55
- package/dist/memory/layers/plan.js +0 -374
- package/dist/memory/layers/static-content.d.ts +0 -27
- package/dist/memory/layers/static-content.js +0 -35
- package/dist/memory/layers/steering.d.ts +0 -51
- package/dist/memory/layers/steering.js +0 -258
- package/dist/memory/layers/temporal.d.ts +0 -91
- package/dist/memory/layers/temporal.js +0 -245
- package/dist/memory/layers/tool-memory-layer.d.ts +0 -16
- package/dist/memory/layers/tool-memory-layer.js +0 -43
- package/dist/memory/layers/working-memory.d.ts +0 -44
- package/dist/memory/layers/working-memory.js +0 -92
- package/dist/memory/projector.d.ts +0 -10
- package/dist/memory/projector.js +0 -19
- package/dist/memory/scope.d.ts +0 -3
- package/dist/memory/scope.js +0 -31
- package/dist/memory/strip-unresolved.d.ts +0 -13
- package/dist/memory/strip-unresolved.js +0 -35
- package/dist/schemas/item.d.ts +0 -35
- package/dist/schemas/item.js +0 -155
- package/dist/types/channel.d.ts +0 -29
- package/dist/types/channel.js +0 -1
- package/dist/types/common.d.ts +0 -68
- package/dist/types/common.js +0 -1
- package/dist/types/context-parts/item-log.d.ts +0 -6
- package/dist/types/context-parts/item-log.js +0 -1
- package/dist/types/context-parts/layer-usage.d.ts +0 -18
- package/dist/types/context-parts/layer-usage.js +0 -1
- package/dist/types/context.d.ts +0 -202
- package/dist/types/context.js +0 -1
- package/dist/types/detached.d.ts +0 -17
- package/dist/types/detached.js +0 -7
- package/dist/types/error.d.ts +0 -66
- package/dist/types/error.js +0 -1
- package/dist/types/fs-adapter.d.ts +0 -51
- package/dist/types/fs-adapter.js +0 -3
- package/dist/types/harness-result.d.ts +0 -43
- package/dist/types/harness-result.js +0 -2
- package/dist/types/items.d.ts +0 -131
- package/dist/types/items.js +0 -2
- package/dist/types/memory-context.d.ts +0 -39
- package/dist/types/memory-context.js +0 -1
- package/dist/types/memory.d.ts +0 -306
- package/dist/types/memory.js +0 -13
- package/dist/types/observability.d.ts +0 -30
- package/dist/types/observability.js +0 -1
- package/dist/types/runtime.d.ts +0 -256
- package/dist/types/runtime.js +0 -1
- package/dist/types/shell-adapter.d.ts +0 -34
- package/dist/types/shell-adapter.js +0 -10
- package/dist/types/steering.d.ts +0 -89
- package/dist/types/steering.js +0 -14
- package/dist/types/step.d.ts +0 -231
- package/dist/types/step.js +0 -1
- package/dist/types/subprocess-adapter.d.ts +0 -157
- package/dist/types/subprocess-adapter.js +0 -3
- package/dist/types/tool-context.d.ts +0 -34
- package/dist/types/tool-context.js +0 -1
- package/dist/types/tool.d.ts +0 -64
- package/dist/types/tool.js +0 -1
- package/dist/util/framework-cast.d.ts +0 -10
- package/dist/util/framework-cast.js +0 -16
- package/dist/util/message-helpers.d.ts +0 -17
- package/dist/util/message-helpers.js +0 -64
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { Slot } from '../../types/memory.js';
|
|
3
|
-
import { createMessage, estimateTokens } from '../../util/message-helpers.js';
|
|
4
|
-
import { findFunctionCall } from '../function-call-utils.js';
|
|
5
|
-
import { layerData, layerFn } from '../layer-provides.js';
|
|
6
|
-
function safeMerge(state, args) {
|
|
7
|
-
const { __proto__: _p, constructor: _c, ...safeArgs } = args;
|
|
8
|
-
if (typeof state === 'object' && state !== null) {
|
|
9
|
-
return {
|
|
10
|
-
...state,
|
|
11
|
-
...safeArgs,
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
return safeArgs;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Creates a mutable working memory layer that the model can update via the `working-memory/update` tool.
|
|
18
|
-
*
|
|
19
|
-
* @public
|
|
20
|
-
* @param config - Optional configuration for scope, Zod schema, template, and read-only mode.
|
|
21
|
-
* @returns A `MemoryLayer` providing scratchpad state the model can read and write.
|
|
22
|
-
*/
|
|
23
|
-
export function workingMemory(config) {
|
|
24
|
-
const scope = config?.scope ?? 'thread';
|
|
25
|
-
return {
|
|
26
|
-
id: 'working-memory',
|
|
27
|
-
name: 'Working Memory',
|
|
28
|
-
slot: Slot.WORKING_MEMORY,
|
|
29
|
-
scope,
|
|
30
|
-
budget: {
|
|
31
|
-
min: 200,
|
|
32
|
-
max: 1_500,
|
|
33
|
-
},
|
|
34
|
-
provides: {
|
|
35
|
-
snapshot: layerData({
|
|
36
|
-
read: (state) => state,
|
|
37
|
-
}),
|
|
38
|
-
update: layerFn({
|
|
39
|
-
description: 'Update the agent working memory with new key-value pairs.',
|
|
40
|
-
input: z.record(z.string(), z.unknown()),
|
|
41
|
-
output: z.void(),
|
|
42
|
-
execute: async (args, state) => ({
|
|
43
|
-
result: undefined,
|
|
44
|
-
state: safeMerge(state, args),
|
|
45
|
-
}),
|
|
46
|
-
}),
|
|
47
|
-
},
|
|
48
|
-
hooks: {
|
|
49
|
-
async init({ storage }) {
|
|
50
|
-
const saved = await storage.get('state');
|
|
51
|
-
const state = saved ?? (config?.schema ? {} : '');
|
|
52
|
-
return {
|
|
53
|
-
state,
|
|
54
|
-
};
|
|
55
|
-
},
|
|
56
|
-
async recall({ state }) {
|
|
57
|
-
if (!state || (typeof state === 'object' && Object.keys(state).length === 0)) {
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
const text = typeof state === 'string' ? state : JSON.stringify(state, null, 2);
|
|
61
|
-
const content = `<working_memory>\n${text}\n</working_memory>`;
|
|
62
|
-
return {
|
|
63
|
-
items: [
|
|
64
|
-
createMessage(content, 'developer'),
|
|
65
|
-
],
|
|
66
|
-
tokenCount: estimateTokens(content),
|
|
67
|
-
};
|
|
68
|
-
},
|
|
69
|
-
async store({ newItems, state }) {
|
|
70
|
-
if (config?.readOnly) {
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
// Backward compat: detect implicit updateWorkingMemory calls from LLMs
|
|
74
|
-
const args = findFunctionCall(newItems, 'updateWorkingMemory');
|
|
75
|
-
if (!args) {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
return {
|
|
79
|
-
state: safeMerge(state, args),
|
|
80
|
-
};
|
|
81
|
-
},
|
|
82
|
-
async onSpawn({ parentState }) {
|
|
83
|
-
if (scope === 'resource') {
|
|
84
|
-
return {
|
|
85
|
-
childState: structuredClone(parentState),
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
return null;
|
|
89
|
-
},
|
|
90
|
-
},
|
|
91
|
-
};
|
|
92
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { Item } from '../types/items.js';
|
|
2
|
-
import type { ProjectionPolicy } from '../types/memory.js';
|
|
3
|
-
interface AssembleViewParams {
|
|
4
|
-
systemPromptItems: Item[];
|
|
5
|
-
layerOutputItems: Item[];
|
|
6
|
-
historyItems: Item[];
|
|
7
|
-
policy?: ProjectionPolicy;
|
|
8
|
-
}
|
|
9
|
-
export declare function assembleView({ systemPromptItems, layerOutputItems, historyItems, policy, }: AssembleViewParams): Item[];
|
|
10
|
-
export {};
|
package/dist/memory/projector.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
//#endregion
|
|
2
|
-
//#region Public API
|
|
3
|
-
export function assembleView({ systemPromptItems, layerOutputItems, historyItems, policy, }) {
|
|
4
|
-
const view = [];
|
|
5
|
-
// Add system prompt items
|
|
6
|
-
view.push(...systemPromptItems);
|
|
7
|
-
// Add layer output items (sorted by slot already from recall)
|
|
8
|
-
view.push(...layerOutputItems);
|
|
9
|
-
// Add history items (with overflow handling if policy specified)
|
|
10
|
-
if (policy?.overflow === 'sliding_window' && policy.windowSize) {
|
|
11
|
-
const windowItems = historyItems.slice(-policy.windowSize);
|
|
12
|
-
view.push(...windowItems);
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
view.push(...historyItems);
|
|
16
|
-
}
|
|
17
|
-
return view;
|
|
18
|
-
}
|
|
19
|
-
//#endregion
|
package/dist/memory/scope.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { ExecutionContext, MemoryScope, ScopedStorage, StorageAdapter } from '../types/memory.js';
|
|
2
|
-
export declare function resolveScopeKey(scope: MemoryScope, ctx: ExecutionContext): string;
|
|
3
|
-
export declare function createScopedStorage(storage: StorageAdapter, layerId: string, scopeKey: string): ScopedStorage;
|
package/dist/memory/scope.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
export function resolveScopeKey(scope, ctx) {
|
|
2
|
-
switch (scope) {
|
|
3
|
-
case 'thread':
|
|
4
|
-
return ctx.threadId;
|
|
5
|
-
case 'resource':
|
|
6
|
-
return ctx.resourceId ?? ctx.threadId;
|
|
7
|
-
case 'global':
|
|
8
|
-
return '__global__';
|
|
9
|
-
case 'execution':
|
|
10
|
-
return ctx.executionId;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
export function createScopedStorage(storage, layerId, scopeKey) {
|
|
14
|
-
const prefix = `layers/${layerId}/${scopeKey}/`;
|
|
15
|
-
return {
|
|
16
|
-
async get(key) {
|
|
17
|
-
return storage.get(`${prefix}${key}`);
|
|
18
|
-
},
|
|
19
|
-
async set(key, value) {
|
|
20
|
-
return storage.set(`${prefix}${key}`, value);
|
|
21
|
-
},
|
|
22
|
-
async delete(key) {
|
|
23
|
-
return storage.delete(`${prefix}${key}`);
|
|
24
|
-
},
|
|
25
|
-
async list(keyPrefix) {
|
|
26
|
-
const fullPrefix = keyPrefix ? `${prefix}${keyPrefix}` : prefix;
|
|
27
|
-
const keys = await storage.list(fullPrefix);
|
|
28
|
-
return keys.map((k) => (k.startsWith(prefix) ? k.slice(prefix.length) : k));
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Drop dangling tool-call state from an item list. A `function_call` without a
|
|
3
|
-
* matching `function_call_output` (or vice-versa) wedges the model on the next
|
|
4
|
-
* round (it typically fabricates an output), so we filter both sides of any
|
|
5
|
-
* incomplete pair. Order-preserving and pure — safe to run after a slice.
|
|
6
|
-
*
|
|
7
|
-
* Mirrors Claude Code's `filterUnresolvedToolUses`. Used by the CLI's
|
|
8
|
-
* session-resume path to drop dangling pairs left by a crash, and by the
|
|
9
|
-
* `historyWindow` memory layer to clean orphans at the slice boundary.
|
|
10
|
-
*/
|
|
11
|
-
import type { Item } from '../types/items.js';
|
|
12
|
-
/** @public */
|
|
13
|
-
export declare function stripUnresolvedToolCalls(items: ReadonlyArray<Item>): Item[];
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Drop dangling tool-call state from an item list. A `function_call` without a
|
|
3
|
-
* matching `function_call_output` (or vice-versa) wedges the model on the next
|
|
4
|
-
* round (it typically fabricates an output), so we filter both sides of any
|
|
5
|
-
* incomplete pair. Order-preserving and pure — safe to run after a slice.
|
|
6
|
-
*
|
|
7
|
-
* Mirrors Claude Code's `filterUnresolvedToolUses`. Used by the CLI's
|
|
8
|
-
* session-resume path to drop dangling pairs left by a crash, and by the
|
|
9
|
-
* `historyWindow` memory layer to clean orphans at the slice boundary.
|
|
10
|
-
*/
|
|
11
|
-
/** @public */
|
|
12
|
-
export function stripUnresolvedToolCalls(items) {
|
|
13
|
-
const outputCallIds = new Set();
|
|
14
|
-
const callCallIds = new Set();
|
|
15
|
-
for (const item of items) {
|
|
16
|
-
if (item.type === 'function_call_output') {
|
|
17
|
-
outputCallIds.add(item.callId);
|
|
18
|
-
continue;
|
|
19
|
-
}
|
|
20
|
-
if (item.type === 'function_call') {
|
|
21
|
-
callCallIds.add(item.callId);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
const keep = [];
|
|
25
|
-
for (const item of items) {
|
|
26
|
-
if (item.type === 'function_call' && !outputCallIds.has(item.callId)) {
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
29
|
-
if (item.type === 'function_call_output' && !callCallIds.has(item.callId)) {
|
|
30
|
-
continue;
|
|
31
|
-
}
|
|
32
|
-
keep.push(item);
|
|
33
|
-
}
|
|
34
|
-
return keep;
|
|
35
|
-
}
|
package/dist/schemas/item.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Runtime schema for the `Item` union.
|
|
3
|
-
*
|
|
4
|
-
* The `Item` type is a discriminated union of framework-created items
|
|
5
|
-
* (`InputMessageItem`, `FunctionCallOutputItem`) and provider-shaped items
|
|
6
|
-
* from `@openrouter/agent` whose shapes are defined by the SDK's generated
|
|
7
|
-
* types. Mirroring those provider shapes as Zod schemas would drift as the
|
|
8
|
-
* SDK evolves, so the runtime schema validates only the structural invariant
|
|
9
|
-
* every `Item` shares: an object with a non-empty string `type` discriminant.
|
|
10
|
-
*
|
|
11
|
-
* Use this at trust boundaries (loading persisted session files, accepting
|
|
12
|
-
* externally-supplied transcripts) where we need to reject garbage JSON but
|
|
13
|
-
* don't need to re-validate every provider field TypeScript already types.
|
|
14
|
-
*/
|
|
15
|
-
import { z } from 'zod';
|
|
16
|
-
import type { Item, ItemSchemaExtensions } from '../types/items.js';
|
|
17
|
-
/** @public Structural validator for `Item`. Asserts non-empty string `type` discriminant. */
|
|
18
|
-
export declare const ItemSchema: z.ZodCustom<Item, Item>;
|
|
19
|
-
type ItemSchemaCategory = keyof Required<ItemSchemaExtensions>;
|
|
20
|
-
export declare function mergeExtensions(a: ItemSchemaExtensions | undefined, b: ItemSchemaExtensions | undefined): ItemSchemaExtensions;
|
|
21
|
-
/** @public Runtime item validator with optional tool, memory-layer, and harness extension schemas. */
|
|
22
|
-
export declare class ItemSchemaRegistry {
|
|
23
|
-
readonly extensions: ItemSchemaExtensions;
|
|
24
|
-
readonly strictUnknownExtensions: boolean;
|
|
25
|
-
constructor(extensions?: ItemSchemaExtensions, opts?: {
|
|
26
|
-
strictUnknownExtensions?: boolean;
|
|
27
|
-
});
|
|
28
|
-
extend(extensions?: ItemSchemaExtensions): ItemSchemaRegistry;
|
|
29
|
-
parse(value: unknown): Item;
|
|
30
|
-
parseMany(values: Iterable<unknown>): Item[];
|
|
31
|
-
parseWithCategory(value: unknown, category: ItemSchemaCategory): Item;
|
|
32
|
-
}
|
|
33
|
-
/** @public Default item schema registry. */
|
|
34
|
-
export declare const defaultItemSchemaRegistry: ItemSchemaRegistry;
|
|
35
|
-
export {};
|
package/dist/schemas/item.js
DELETED
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Runtime schema for the `Item` union.
|
|
3
|
-
*
|
|
4
|
-
* The `Item` type is a discriminated union of framework-created items
|
|
5
|
-
* (`InputMessageItem`, `FunctionCallOutputItem`) and provider-shaped items
|
|
6
|
-
* from `@openrouter/agent` whose shapes are defined by the SDK's generated
|
|
7
|
-
* types. Mirroring those provider shapes as Zod schemas would drift as the
|
|
8
|
-
* SDK evolves, so the runtime schema validates only the structural invariant
|
|
9
|
-
* every `Item` shares: an object with a non-empty string `type` discriminant.
|
|
10
|
-
*
|
|
11
|
-
* Use this at trust boundaries (loading persisted session files, accepting
|
|
12
|
-
* externally-supplied transcripts) where we need to reject garbage JSON but
|
|
13
|
-
* don't need to re-validate every provider field TypeScript already types.
|
|
14
|
-
*/
|
|
15
|
-
import { z } from 'zod';
|
|
16
|
-
function isItemLike(value) {
|
|
17
|
-
if (typeof value !== 'object' || value === null) {
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
if (!('type' in value)) {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
const { type } = value;
|
|
24
|
-
return typeof type === 'string' && type.length > 0;
|
|
25
|
-
}
|
|
26
|
-
/** @public Structural validator for `Item`. Asserts non-empty string `type` discriminant. */
|
|
27
|
-
export const ItemSchema = z.custom(isItemLike, {
|
|
28
|
-
message: 'Expected an Item object with a non-empty string "type" discriminant.',
|
|
29
|
-
});
|
|
30
|
-
function hasSchemas(extensions) {
|
|
31
|
-
return Boolean(extensions.items?.length ||
|
|
32
|
-
extensions.developerMessages?.length ||
|
|
33
|
-
extensions.toolCalls?.length ||
|
|
34
|
-
extensions.toolResults?.length);
|
|
35
|
-
}
|
|
36
|
-
export function mergeExtensions(a, b) {
|
|
37
|
-
return {
|
|
38
|
-
items: [
|
|
39
|
-
...(a?.items ?? []),
|
|
40
|
-
...(b?.items ?? []),
|
|
41
|
-
],
|
|
42
|
-
developerMessages: [
|
|
43
|
-
...(a?.developerMessages ?? []),
|
|
44
|
-
...(b?.developerMessages ?? []),
|
|
45
|
-
],
|
|
46
|
-
toolCalls: [
|
|
47
|
-
...(a?.toolCalls ?? []),
|
|
48
|
-
...(b?.toolCalls ?? []),
|
|
49
|
-
],
|
|
50
|
-
toolResults: [
|
|
51
|
-
...(a?.toolResults ?? []),
|
|
52
|
-
...(b?.toolResults ?? []),
|
|
53
|
-
],
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
function schemasForCategory(extensions, category) {
|
|
57
|
-
return extensions[category] ?? [];
|
|
58
|
-
}
|
|
59
|
-
function isRecord(value) {
|
|
60
|
-
return typeof value === 'object' && value !== null;
|
|
61
|
-
}
|
|
62
|
-
function relevantCategories(value) {
|
|
63
|
-
const categories = [
|
|
64
|
-
'items',
|
|
65
|
-
];
|
|
66
|
-
if (isRecord(value) && value.type === 'message' && value.role === 'developer') {
|
|
67
|
-
categories.push('developerMessages');
|
|
68
|
-
}
|
|
69
|
-
if (isRecord(value) && value.type === 'function_call') {
|
|
70
|
-
categories.push('toolCalls');
|
|
71
|
-
}
|
|
72
|
-
if (isRecord(value) && value.type === 'function_call_output') {
|
|
73
|
-
categories.push('toolResults');
|
|
74
|
-
}
|
|
75
|
-
return categories;
|
|
76
|
-
}
|
|
77
|
-
function isKnownBaseType(type) {
|
|
78
|
-
return (type === 'message' ||
|
|
79
|
-
type === 'function_call' ||
|
|
80
|
-
type === 'function_call_output' ||
|
|
81
|
-
type === 'reasoning' ||
|
|
82
|
-
type === 'web_search_call' ||
|
|
83
|
-
type === 'file_search_call' ||
|
|
84
|
-
type === 'image_generation_call' ||
|
|
85
|
-
type.startsWith('openrouter:'));
|
|
86
|
-
}
|
|
87
|
-
function schemaMismatch(category) {
|
|
88
|
-
return new z.ZodError([
|
|
89
|
-
{
|
|
90
|
-
code: 'custom',
|
|
91
|
-
message: `Item did not match any registered ${category} extension schema.`,
|
|
92
|
-
path: [],
|
|
93
|
-
},
|
|
94
|
-
]);
|
|
95
|
-
}
|
|
96
|
-
/** @public Runtime item validator with optional tool, memory-layer, and harness extension schemas. */
|
|
97
|
-
export class ItemSchemaRegistry {
|
|
98
|
-
extensions;
|
|
99
|
-
strictUnknownExtensions;
|
|
100
|
-
constructor(extensions, opts) {
|
|
101
|
-
this.extensions = mergeExtensions(undefined, extensions);
|
|
102
|
-
this.strictUnknownExtensions = opts?.strictUnknownExtensions ?? true;
|
|
103
|
-
}
|
|
104
|
-
extend(extensions) {
|
|
105
|
-
if (!extensions || !hasSchemas(extensions)) {
|
|
106
|
-
return this;
|
|
107
|
-
}
|
|
108
|
-
return new ItemSchemaRegistry(mergeExtensions(this.extensions, extensions), {
|
|
109
|
-
strictUnknownExtensions: this.strictUnknownExtensions,
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
parse(value) {
|
|
113
|
-
const base = ItemSchema.parse(value);
|
|
114
|
-
const categories = relevantCategories(base);
|
|
115
|
-
const schemas = categories.flatMap((category) => schemasForCategory(this.extensions, category));
|
|
116
|
-
for (const schema of schemas) {
|
|
117
|
-
const parsed = schema.safeParse(value);
|
|
118
|
-
if (parsed.success) {
|
|
119
|
-
return ItemSchema.parse(parsed.data);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
if (this.strictUnknownExtensions && !isKnownBaseType(base.type)) {
|
|
123
|
-
throw new z.ZodError([
|
|
124
|
-
{
|
|
125
|
-
code: 'custom',
|
|
126
|
-
message: `Item type '${base.type}' did not match any registered item extension schema.`,
|
|
127
|
-
path: [
|
|
128
|
-
'type',
|
|
129
|
-
],
|
|
130
|
-
},
|
|
131
|
-
]);
|
|
132
|
-
}
|
|
133
|
-
return base;
|
|
134
|
-
}
|
|
135
|
-
parseMany(values) {
|
|
136
|
-
return Array.from(values, (value) => this.parse(value));
|
|
137
|
-
}
|
|
138
|
-
parseWithCategory(value, category) {
|
|
139
|
-
const schemas = schemasForCategory(this.extensions, category);
|
|
140
|
-
if (schemas.length === 0) {
|
|
141
|
-
return this.parse(value);
|
|
142
|
-
}
|
|
143
|
-
for (const schema of schemas) {
|
|
144
|
-
const parsed = schema.safeParse(value);
|
|
145
|
-
if (parsed.success) {
|
|
146
|
-
return ItemSchema.parse(parsed.data);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
throw schemaMismatch(category);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
/** @public Default item schema registry. */
|
|
153
|
-
export const defaultItemSchemaRegistry = new ItemSchemaRegistry(undefined, {
|
|
154
|
-
strictUnknownExtensions: true,
|
|
155
|
-
});
|
package/dist/types/channel.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { ZodType } from 'zod';
|
|
2
|
-
/**
|
|
3
|
-
* A typed communication channel between steps within an execution tree.
|
|
4
|
-
* @public
|
|
5
|
-
*/
|
|
6
|
-
export interface Channel<T> {
|
|
7
|
-
/** Channel name for identification and debugging. */
|
|
8
|
-
readonly name: string;
|
|
9
|
-
/** Zod schema used to validate every message sent through the channel. */
|
|
10
|
-
readonly schema: ZodType<T>;
|
|
11
|
-
/** Delivery semantics: `'value'` (last-write-wins), `'queue'` (FIFO), `'topic'` (pub/sub). */
|
|
12
|
-
readonly mode: 'value' | 'queue' | 'topic';
|
|
13
|
-
/** Buffer size for queue mode (default: 1000). Ignored for value/topic modes. */
|
|
14
|
-
readonly capacity?: number;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* A channel that is writable from outside the execution tree (e.g. user input).
|
|
18
|
-
* @public
|
|
19
|
-
*/
|
|
20
|
-
export interface ExternalChannel<T> extends Channel<T> {
|
|
21
|
-
/** Marker indicating the channel accepts writes from external callers. */
|
|
22
|
-
readonly external: true;
|
|
23
|
-
}
|
|
24
|
-
/** @public Handle for sending messages to a channel and checking its closed state. */
|
|
25
|
-
export interface ChannelHandle<T> {
|
|
26
|
-
send(value: T): void;
|
|
27
|
-
readonly closed: boolean;
|
|
28
|
-
readonly channel: Channel<T>;
|
|
29
|
-
}
|
package/dist/types/channel.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/types/common.d.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import type { FunctionCallItem, Item } from './items.js';
|
|
2
|
-
/**
|
|
3
|
-
* Policy controlling automatic retry behavior on step failure.
|
|
4
|
-
* @public
|
|
5
|
-
*/
|
|
6
|
-
export interface RetryPolicy {
|
|
7
|
-
/** Maximum number of execution attempts (including the initial try). */
|
|
8
|
-
maxAttempts: number;
|
|
9
|
-
/** Backoff strategy between retries. */
|
|
10
|
-
backoff: 'fixed' | 'linear' | 'exponential';
|
|
11
|
-
/** Delay in ms before the first retry. */
|
|
12
|
-
initialDelay: number;
|
|
13
|
-
/** Upper bound in ms for the computed delay (caps exponential/linear growth). */
|
|
14
|
-
maxDelay?: number;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Optional parameters forwarded to the model provider during an LLM step.
|
|
18
|
-
* @public
|
|
19
|
-
*/
|
|
20
|
-
export interface ModelParams {
|
|
21
|
-
/** Sampling temperature (0 = deterministic, higher = more creative). */
|
|
22
|
-
temperature?: number;
|
|
23
|
-
/** Nucleus sampling threshold (alternative to temperature). */
|
|
24
|
-
topP?: number;
|
|
25
|
-
/** Maximum number of tokens the model may generate. */
|
|
26
|
-
maxTokens?: number;
|
|
27
|
-
/** Sequences that cause the model to stop generating. */
|
|
28
|
-
stopSequences?: string[];
|
|
29
|
-
}
|
|
30
|
-
/** @public Aggregate token counts for an execution (input, output, total, cached). */
|
|
31
|
-
export interface TokenUsage {
|
|
32
|
-
input: number;
|
|
33
|
-
output: number;
|
|
34
|
-
total: number;
|
|
35
|
-
cached?: number;
|
|
36
|
-
}
|
|
37
|
-
/** @public Metadata captured from the most recent step execution. */
|
|
38
|
-
export interface StepMeta {
|
|
39
|
-
toolCalls?: FunctionCallItem[];
|
|
40
|
-
usage?: {
|
|
41
|
-
inputTokens: number;
|
|
42
|
-
outputTokens: number;
|
|
43
|
-
cachedTokens?: number;
|
|
44
|
-
};
|
|
45
|
-
cost?: number;
|
|
46
|
-
responseItems?: ReadonlyArray<Item>;
|
|
47
|
-
}
|
|
48
|
-
/** @public Structured response returned by a model adapter after an LLM call. */
|
|
49
|
-
export interface LLMResponse {
|
|
50
|
-
items: Item[];
|
|
51
|
-
usage: {
|
|
52
|
-
inputTokens: number;
|
|
53
|
-
outputTokens: number;
|
|
54
|
-
cachedTokens?: number;
|
|
55
|
-
};
|
|
56
|
-
cost?: number;
|
|
57
|
-
}
|
|
58
|
-
/** @public Configuration for the LLM provider used by the agent harness. */
|
|
59
|
-
export interface LlmProviderConfig {
|
|
60
|
-
provider: 'openrouter';
|
|
61
|
-
apiKey?: string;
|
|
62
|
-
/**
|
|
63
|
-
* When true, sends the `X-OpenRouter-Cache: true` request header on every
|
|
64
|
-
* model call. OpenRouter then serves identical requests from cache without
|
|
65
|
-
* re-billing — useful for deterministic re-runs (evals, regression suites).
|
|
66
|
-
*/
|
|
67
|
-
cache?: boolean;
|
|
68
|
-
}
|
package/dist/types/common.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { Item } from '../items.js';
|
|
2
|
-
/** @public Per-layer contribution to the context window on the most recent LLM call. */
|
|
3
|
-
export interface LayerUsageEntry {
|
|
4
|
-
readonly layerId: string;
|
|
5
|
-
readonly tokenCount: number;
|
|
6
|
-
/** Items this layer contributed to the context view for the last LLM call. */
|
|
7
|
-
readonly items: ReadonlyArray<Item>;
|
|
8
|
-
}
|
|
9
|
-
/** @public Breakdown of the context window as of the most recent LLM call in an execution. */
|
|
10
|
-
export interface LastLayerUsage {
|
|
11
|
-
readonly executionId: string;
|
|
12
|
-
readonly modelId: string;
|
|
13
|
-
readonly layers: ReadonlyArray<LayerUsageEntry>;
|
|
14
|
-
readonly systemPromptTokens: number;
|
|
15
|
-
readonly toolsTokens: number;
|
|
16
|
-
readonly historyTokens: number;
|
|
17
|
-
readonly totalUsedTokens: number;
|
|
18
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|