@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,32 +0,0 @@
|
|
|
1
|
-
import type { ZodType } from 'zod';
|
|
2
|
-
import type { ExecutionContext, LayerDataDecl, LayerFunctionDecl } from '../types/memory.js';
|
|
3
|
-
/**
|
|
4
|
-
* Creates a read-only data declaration for a memory layer's `provides` map.
|
|
5
|
-
*
|
|
6
|
-
* @public
|
|
7
|
-
* @param opts.read - Function that projects a value from the layer's current state.
|
|
8
|
-
* @returns A `LayerDataDecl` to include in a layer's `provides`.
|
|
9
|
-
*/
|
|
10
|
-
export declare function layerData<T, TState>(opts: {
|
|
11
|
-
read: (state: TState) => T;
|
|
12
|
-
}): LayerDataDecl<T, TState>;
|
|
13
|
-
/**
|
|
14
|
-
* Creates a callable function declaration for a memory layer's `provides` map.
|
|
15
|
-
* Functions are accessible via `ctx.memory['layerId'].fn()` and automatically exposed as LLM tools.
|
|
16
|
-
*
|
|
17
|
-
* @public
|
|
18
|
-
* @param opts.description - Human-readable description used as tool description for LLM.
|
|
19
|
-
* @param opts.input - Zod schema validating input arguments.
|
|
20
|
-
* @param opts.output - Zod schema validating the return value.
|
|
21
|
-
* @param opts.execute - Async function receiving args, current state, and execution context.
|
|
22
|
-
* @returns A `LayerFunctionDecl` to include in a layer's `provides`.
|
|
23
|
-
*/
|
|
24
|
-
export declare function layerFn<TInput, TOutput, TState>(opts: {
|
|
25
|
-
description: string;
|
|
26
|
-
input: ZodType<TInput>;
|
|
27
|
-
output: ZodType<TOutput>;
|
|
28
|
-
execute: (args: TInput, state: TState, ctx: ExecutionContext) => Promise<{
|
|
29
|
-
result: TOutput;
|
|
30
|
-
state?: TState;
|
|
31
|
-
}>;
|
|
32
|
-
}): LayerFunctionDecl<TInput, TOutput, TState>;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Creates a read-only data declaration for a memory layer's `provides` map.
|
|
3
|
-
*
|
|
4
|
-
* @public
|
|
5
|
-
* @param opts.read - Function that projects a value from the layer's current state.
|
|
6
|
-
* @returns A `LayerDataDecl` to include in a layer's `provides`.
|
|
7
|
-
*/
|
|
8
|
-
export function layerData(opts) {
|
|
9
|
-
return {
|
|
10
|
-
kind: 'data',
|
|
11
|
-
read: opts.read,
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Creates a callable function declaration for a memory layer's `provides` map.
|
|
16
|
-
* Functions are accessible via `ctx.memory['layerId'].fn()` and automatically exposed as LLM tools.
|
|
17
|
-
*
|
|
18
|
-
* @public
|
|
19
|
-
* @param opts.description - Human-readable description used as tool description for LLM.
|
|
20
|
-
* @param opts.input - Zod schema validating input arguments.
|
|
21
|
-
* @param opts.output - Zod schema validating the return value.
|
|
22
|
-
* @param opts.execute - Async function receiving args, current state, and execution context.
|
|
23
|
-
* @returns A `LayerFunctionDecl` to include in a layer's `provides`.
|
|
24
|
-
*/
|
|
25
|
-
export function layerFn(opts) {
|
|
26
|
-
return {
|
|
27
|
-
kind: 'function',
|
|
28
|
-
description: opts.description,
|
|
29
|
-
input: opts.input,
|
|
30
|
-
output: opts.output,
|
|
31
|
-
execute: opts.execute,
|
|
32
|
-
};
|
|
33
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { Context } from '../types/context.js';
|
|
2
|
-
import type { LastLayerUsage } from '../types/context-parts/layer-usage.js';
|
|
3
|
-
import type { RecallLayerOutput } from '../types/runtime.js';
|
|
4
|
-
import type { Tool } from '../types/tool.js';
|
|
5
|
-
interface ComputeLayerUsageParams {
|
|
6
|
-
ctx: Context;
|
|
7
|
-
modelId: string;
|
|
8
|
-
instructions?: string;
|
|
9
|
-
tools?: ReadonlyArray<Tool>;
|
|
10
|
-
/** Per-layer recall output assembled into the context view for this LLM call. */
|
|
11
|
-
recallResults: ReadonlyArray<RecallLayerOutput>;
|
|
12
|
-
}
|
|
13
|
-
export declare function computeLayerUsage({ ctx, modelId, instructions, tools, recallResults, }: ComputeLayerUsageParams): LastLayerUsage;
|
|
14
|
-
/** Commit computed usage to the Context, replacing any prior snapshot. */
|
|
15
|
-
export declare function commitLayerUsage(ctx: Context, usage: LastLayerUsage): void;
|
|
16
|
-
export {};
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { estimateTokens } from '../util/message-helpers.js';
|
|
2
|
-
function canWriteLayerUsage(ctx) {
|
|
3
|
-
const desc = Object.getOwnPropertyDescriptor(ctx, 'lastLayerUsage');
|
|
4
|
-
if (desc === undefined) {
|
|
5
|
-
return false;
|
|
6
|
-
}
|
|
7
|
-
return desc.writable !== false;
|
|
8
|
-
}
|
|
9
|
-
//#endregion
|
|
10
|
-
//#region Helpers
|
|
11
|
-
function estimateJsonTokens(value) {
|
|
12
|
-
try {
|
|
13
|
-
return estimateTokens(JSON.stringify(value));
|
|
14
|
-
}
|
|
15
|
-
catch {
|
|
16
|
-
return 0;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
//#endregion
|
|
20
|
-
//#region Public API
|
|
21
|
-
export function computeLayerUsage({ ctx, modelId, instructions, tools, recallResults, }) {
|
|
22
|
-
const layers = recallResults
|
|
23
|
-
.map((r) => ({
|
|
24
|
-
layerId: r.layerId,
|
|
25
|
-
tokenCount: r.tokenCount,
|
|
26
|
-
items: r.items,
|
|
27
|
-
}))
|
|
28
|
-
.sort((a, b) => a.layerId.localeCompare(b.layerId));
|
|
29
|
-
let historyTokens = 0;
|
|
30
|
-
for (const item of ctx.itemLog.items) {
|
|
31
|
-
historyTokens += estimateJsonTokens(item);
|
|
32
|
-
}
|
|
33
|
-
const systemPromptTokens = instructions ? estimateTokens(instructions) : 0;
|
|
34
|
-
const toolsTokens = tools && tools.length > 0 ? estimateJsonTokens(tools) : 0;
|
|
35
|
-
const layerTotal = layers.reduce((sum, l) => sum + l.tokenCount, 0);
|
|
36
|
-
const totalUsedTokens = systemPromptTokens + toolsTokens + historyTokens + layerTotal;
|
|
37
|
-
return {
|
|
38
|
-
executionId: ctx.id,
|
|
39
|
-
modelId,
|
|
40
|
-
layers,
|
|
41
|
-
systemPromptTokens,
|
|
42
|
-
toolsTokens,
|
|
43
|
-
historyTokens,
|
|
44
|
-
totalUsedTokens,
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
/** Commit computed usage to the Context, replacing any prior snapshot. */
|
|
48
|
-
export function commitLayerUsage(ctx, usage) {
|
|
49
|
-
if (!canWriteLayerUsage(ctx)) {
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
ctx.lastLayerUsage = usage;
|
|
53
|
-
}
|
|
54
|
-
//#endregion
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import type { ZodType } from 'zod';
|
|
2
|
-
export interface DurableTaskState {
|
|
3
|
-
checkpoints: Array<{
|
|
4
|
-
timestamp: number;
|
|
5
|
-
depth: number;
|
|
6
|
-
}>;
|
|
7
|
-
files: string[];
|
|
8
|
-
data: Record<string, unknown>;
|
|
9
|
-
}
|
|
10
|
-
export interface DurableTaskStateSerializer {
|
|
11
|
-
serialize(state: DurableTaskState): string;
|
|
12
|
-
deserialize(data: string): DurableTaskState;
|
|
13
|
-
}
|
|
14
|
-
export interface DurableTaskStateConfig {
|
|
15
|
-
baseDir?: string;
|
|
16
|
-
gitCommit?: boolean;
|
|
17
|
-
schema?: ZodType;
|
|
18
|
-
serializer?: DurableTaskStateSerializer;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Creates a memory layer that persists task checkpoints, files, and arbitrary data across iterations.
|
|
22
|
-
*
|
|
23
|
-
* @public
|
|
24
|
-
* @param _config - Optional configuration for base directory, git commit behavior, schema, and serializer.
|
|
25
|
-
* @returns A `MemoryLayer` scoped to the execution with durable task state.
|
|
26
|
-
*/
|
|
27
|
-
export declare function durableTaskState(_config?: DurableTaskStateConfig): {
|
|
28
|
-
id: "durable-task-state";
|
|
29
|
-
name: string;
|
|
30
|
-
slot: number;
|
|
31
|
-
scope: "execution";
|
|
32
|
-
budget: {
|
|
33
|
-
min: number;
|
|
34
|
-
max: number;
|
|
35
|
-
};
|
|
36
|
-
timeouts: {
|
|
37
|
-
store: number;
|
|
38
|
-
};
|
|
39
|
-
hooks: {
|
|
40
|
-
init({ storage }: import("../../index.js").InitParams): Promise<{
|
|
41
|
-
state: DurableTaskState;
|
|
42
|
-
}>;
|
|
43
|
-
recall({ state }: import("../../index.js").RecallParams<DurableTaskState>): Promise<{
|
|
44
|
-
items: import("../../index.js").InputMessageItem[];
|
|
45
|
-
tokenCount: number;
|
|
46
|
-
} | null>;
|
|
47
|
-
store({ state, ctx }: import("../../index.js").StoreParams<DurableTaskState>): Promise<{
|
|
48
|
-
state: DurableTaskState;
|
|
49
|
-
}>;
|
|
50
|
-
onSpawn({ parentState }: import("../../index.js").SpawnParams<DurableTaskState>): Promise<{
|
|
51
|
-
childState: DurableTaskState;
|
|
52
|
-
items: never[];
|
|
53
|
-
}>;
|
|
54
|
-
onReturn({ childState, parentState }: import("../../index.js").ReturnParams<DurableTaskState>): Promise<{
|
|
55
|
-
parentState: {
|
|
56
|
-
checkpoints: {
|
|
57
|
-
timestamp: number;
|
|
58
|
-
depth: number;
|
|
59
|
-
}[];
|
|
60
|
-
files: string[];
|
|
61
|
-
data: {
|
|
62
|
-
[x: string]: unknown;
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
}>;
|
|
66
|
-
onComplete({ state, outcome }: import("../../index.js").CompleteParams<DurableTaskState>): Promise<{
|
|
67
|
-
state: {
|
|
68
|
-
data: {
|
|
69
|
-
__outcome: import("../../index.js").ExecutionOutcome;
|
|
70
|
-
};
|
|
71
|
-
checkpoints: {
|
|
72
|
-
timestamp: number;
|
|
73
|
-
depth: number;
|
|
74
|
-
}[];
|
|
75
|
-
files: string[];
|
|
76
|
-
};
|
|
77
|
-
} | undefined>;
|
|
78
|
-
};
|
|
79
|
-
};
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { Slot } from '../../types/memory.js';
|
|
2
|
-
import { createMessage, estimateTokens } from '../../util/message-helpers.js';
|
|
3
|
-
/**
|
|
4
|
-
* Creates a memory layer that persists task checkpoints, files, and arbitrary data across iterations.
|
|
5
|
-
*
|
|
6
|
-
* @public
|
|
7
|
-
* @param _config - Optional configuration for base directory, git commit behavior, schema, and serializer.
|
|
8
|
-
* @returns A `MemoryLayer` scoped to the execution with durable task state.
|
|
9
|
-
*/
|
|
10
|
-
export function durableTaskState(_config) {
|
|
11
|
-
return {
|
|
12
|
-
id: 'durable-task-state',
|
|
13
|
-
name: 'Durable Task State',
|
|
14
|
-
slot: Slot.WORKING_MEMORY + 10, // 110
|
|
15
|
-
scope: 'execution',
|
|
16
|
-
budget: {
|
|
17
|
-
min: 100,
|
|
18
|
-
max: 800,
|
|
19
|
-
},
|
|
20
|
-
timeouts: {
|
|
21
|
-
store: 30_000,
|
|
22
|
-
},
|
|
23
|
-
hooks: {
|
|
24
|
-
async init({ storage }) {
|
|
25
|
-
const saved = await storage.get('state');
|
|
26
|
-
return {
|
|
27
|
-
state: saved ?? {
|
|
28
|
-
checkpoints: [],
|
|
29
|
-
files: [],
|
|
30
|
-
data: {},
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
},
|
|
34
|
-
async recall({ state }) {
|
|
35
|
-
if (!state) {
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
const text = `<task_state>\n${JSON.stringify(state, null, 2)}\n</task_state>`;
|
|
39
|
-
return {
|
|
40
|
-
items: [
|
|
41
|
-
createMessage(text, 'developer'),
|
|
42
|
-
],
|
|
43
|
-
tokenCount: estimateTokens(text),
|
|
44
|
-
};
|
|
45
|
-
},
|
|
46
|
-
async store({ state, ctx }) {
|
|
47
|
-
const currentState = state ?? {
|
|
48
|
-
checkpoints: [],
|
|
49
|
-
files: [],
|
|
50
|
-
data: {},
|
|
51
|
-
};
|
|
52
|
-
// Add a checkpoint for each store call
|
|
53
|
-
const newState = {
|
|
54
|
-
...currentState,
|
|
55
|
-
checkpoints: [
|
|
56
|
-
...currentState.checkpoints,
|
|
57
|
-
{
|
|
58
|
-
timestamp: Date.now(),
|
|
59
|
-
depth: ctx.depth,
|
|
60
|
-
},
|
|
61
|
-
],
|
|
62
|
-
};
|
|
63
|
-
return {
|
|
64
|
-
state: newState,
|
|
65
|
-
};
|
|
66
|
-
},
|
|
67
|
-
async onSpawn({ parentState }) {
|
|
68
|
-
// ALWAYS provides child state (unlike other layers)
|
|
69
|
-
return {
|
|
70
|
-
childState: structuredClone(parentState),
|
|
71
|
-
items: [],
|
|
72
|
-
};
|
|
73
|
-
},
|
|
74
|
-
async onReturn({ childState, parentState }) {
|
|
75
|
-
// Merge child artifacts back to parent
|
|
76
|
-
return {
|
|
77
|
-
parentState: {
|
|
78
|
-
checkpoints: [
|
|
79
|
-
...parentState.checkpoints,
|
|
80
|
-
...childState.checkpoints,
|
|
81
|
-
],
|
|
82
|
-
files: [
|
|
83
|
-
...new Set([
|
|
84
|
-
...parentState.files,
|
|
85
|
-
...childState.files,
|
|
86
|
-
]),
|
|
87
|
-
],
|
|
88
|
-
data: {
|
|
89
|
-
...parentState.data,
|
|
90
|
-
...childState.data,
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
};
|
|
94
|
-
},
|
|
95
|
-
async onComplete({ state, outcome }) {
|
|
96
|
-
if (!state) {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
return {
|
|
100
|
-
state: {
|
|
101
|
-
...state,
|
|
102
|
-
data: {
|
|
103
|
-
...state.data,
|
|
104
|
-
__outcome: outcome,
|
|
105
|
-
},
|
|
106
|
-
checkpoints: [
|
|
107
|
-
...state.checkpoints,
|
|
108
|
-
{
|
|
109
|
-
timestamp: Date.now(),
|
|
110
|
-
depth: 0,
|
|
111
|
-
},
|
|
112
|
-
],
|
|
113
|
-
},
|
|
114
|
-
};
|
|
115
|
-
},
|
|
116
|
-
},
|
|
117
|
-
};
|
|
118
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import type { MemoryLayer } from '../../types/memory.js';
|
|
2
|
-
interface TrackedFile {
|
|
3
|
-
/** Absolute path to the file */
|
|
4
|
-
absolutePath: string;
|
|
5
|
-
/** Original reference path (as written by user) */
|
|
6
|
-
referencePath: string;
|
|
7
|
-
/** File content (null if deleted or error) */
|
|
8
|
-
content: string | null;
|
|
9
|
-
/** LLM-assigned priority score (0-100, higher = more relevant) */
|
|
10
|
-
priority: number;
|
|
11
|
-
/** Content hash for change detection */
|
|
12
|
-
contentHash: string;
|
|
13
|
-
/** Whether the file has been deleted */
|
|
14
|
-
deleted: boolean;
|
|
15
|
-
/** Estimated token count */
|
|
16
|
-
tokenCount: number;
|
|
17
|
-
/** Error message if file couldn't be read (security, size, permission) */
|
|
18
|
-
error?: string;
|
|
19
|
-
}
|
|
20
|
-
interface FileReferenceState {
|
|
21
|
-
/** Map of reference path to tracked file info */
|
|
22
|
-
files: Map<string, TrackedFile>;
|
|
23
|
-
/** Base directory for resolving relative paths */
|
|
24
|
-
baseDir: string;
|
|
25
|
-
}
|
|
26
|
-
interface FileReferenceOptions {
|
|
27
|
-
/** Base directory for resolving relative paths (defaults to cwd) */
|
|
28
|
-
baseDir?: string;
|
|
29
|
-
/** Slot position (defaults to Slot.RAG) */
|
|
30
|
-
slot?: number;
|
|
31
|
-
/** Model to use for priority scoring */
|
|
32
|
-
scoringModel?: string;
|
|
33
|
-
/** Maximum file size in bytes (defaults to 1MB) */
|
|
34
|
-
maxFileSize?: number;
|
|
35
|
-
/** Whether to follow symlinks (defaults to false for security) */
|
|
36
|
-
followSymlinks?: boolean;
|
|
37
|
-
/** Allowed file extensions (defaults to common code/text extensions) */
|
|
38
|
-
allowedExtensions?: string[];
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Creates a memory layer that tracks file references in user messages.
|
|
42
|
-
*
|
|
43
|
-
* Syntax: `#path/to/file` in user messages
|
|
44
|
-
*
|
|
45
|
-
* Behavior:
|
|
46
|
-
* - Transforms references to markdown anchor links `[#path/to/file](#path-to-file)`
|
|
47
|
-
* - Scores file relevance using LLM when first referenced
|
|
48
|
-
* - Injects file contents into context via recall(), ordered by priority
|
|
49
|
-
* - Detects file changes on each new message, triggers immediate re-render
|
|
50
|
-
* - Shows warning for deleted files
|
|
51
|
-
*
|
|
52
|
-
* @public
|
|
53
|
-
*/
|
|
54
|
-
export declare function fileReference(opts?: FileReferenceOptions): MemoryLayer<FileReferenceState>;
|
|
55
|
-
export {};
|