@noetic-tools/core 0.0.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/LICENSE +201 -0
- package/README.md +38 -0
- package/dist/adapters/in-memory-fs-adapter.d.ts +3 -0
- package/dist/adapters/in-memory-fs-adapter.js +245 -0
- package/dist/adapters/in-memory-shell-adapter.d.ts +9 -0
- package/dist/adapters/in-memory-shell-adapter.js +20 -0
- package/dist/adapters/in-memory-subprocess-adapter.d.ts +5 -0
- package/dist/adapters/in-memory-subprocess-adapter.js +126 -0
- package/dist/adapters/local-fs-adapter.d.ts +3 -0
- package/dist/adapters/local-fs-adapter.js +43 -0
- package/dist/adapters/local-shell-adapter.d.ts +51 -0
- package/dist/adapters/local-shell-adapter.js +167 -0
- package/dist/adapters/local-subprocess-adapter.d.ts +16 -0
- package/dist/adapters/local-subprocess-adapter.js +187 -0
- package/dist/adapters/openrouter.d.ts +57 -0
- package/dist/adapters/openrouter.js +248 -0
- package/dist/builders/channel-builder.d.ts +36 -0
- package/dist/builders/channel-builder.js +15 -0
- package/dist/builders/control-flow-builders.d.ts +79 -0
- package/dist/builders/control-flow-builders.js +53 -0
- package/dist/builders/every.d.ts +45 -0
- package/dist/builders/every.js +60 -0
- package/dist/builders/layer-provides-builders.d.ts +32 -0
- package/dist/builders/layer-provides-builders.js +33 -0
- package/dist/builders/loop-builder.d.ts +23 -0
- package/dist/builders/loop-builder.js +46 -0
- package/dist/builders/memory-builder.d.ts +11 -0
- package/dist/builders/memory-builder.js +15 -0
- package/dist/builders/provide-builder.d.ts +20 -0
- package/dist/builders/provide-builder.js +34 -0
- package/dist/builders/spawn-builder.d.ts +20 -0
- package/dist/builders/spawn-builder.js +33 -0
- package/dist/builders/step-builders.d.ts +62 -0
- package/dist/builders/step-builders.js +99 -0
- package/dist/builders/tool-builder.d.ts +52 -0
- package/dist/builders/tool-builder.js +59 -0
- package/dist/conditions/conditions.d.ts +114 -0
- package/dist/conditions/conditions.js +271 -0
- package/dist/conditions/cosine-similarity.d.ts +11 -0
- package/dist/conditions/cosine-similarity.js +28 -0
- package/dist/conditions/index.d.ts +3 -0
- package/dist/conditions/index.js +2 -0
- package/dist/errors/noetic-config-error.d.ts +41 -0
- package/dist/errors/noetic-config-error.js +44 -0
- package/dist/errors/noetic-error.d.ts +18 -0
- package/dist/errors/noetic-error.js +52 -0
- package/dist/index.d.ts +152 -0
- package/dist/index.js +112 -0
- package/dist/internal-test.d.ts +11 -0
- package/dist/internal-test.js +11 -0
- package/dist/interpreter/clone-guard.d.ts +4 -0
- package/dist/interpreter/clone-guard.js +18 -0
- package/dist/interpreter/collect-tools.d.ts +12 -0
- package/dist/interpreter/collect-tools.js +70 -0
- package/dist/interpreter/execute-branch.d.ts +3 -0
- package/dist/interpreter/execute-branch.js +10 -0
- package/dist/interpreter/execute-every.d.ts +15 -0
- package/dist/interpreter/execute-every.js +143 -0
- package/dist/interpreter/execute-fork.d.ts +3 -0
- package/dist/interpreter/execute-fork.js +215 -0
- package/dist/interpreter/execute-llm.d.ts +4 -0
- package/dist/interpreter/execute-llm.js +217 -0
- package/dist/interpreter/execute-loop.d.ts +3 -0
- package/dist/interpreter/execute-loop.js +171 -0
- package/dist/interpreter/execute-provide.d.ts +10 -0
- package/dist/interpreter/execute-provide.js +64 -0
- package/dist/interpreter/execute-run.d.ts +3 -0
- package/dist/interpreter/execute-run.js +39 -0
- package/dist/interpreter/execute-spawn.d.ts +11 -0
- package/dist/interpreter/execute-spawn.js +113 -0
- package/dist/interpreter/execute-tool.d.ts +5 -0
- package/dist/interpreter/execute-tool.js +81 -0
- package/dist/interpreter/execute.d.ts +14 -0
- package/dist/interpreter/execute.js +119 -0
- package/dist/interpreter/framework-cast.d.ts +10 -0
- package/dist/interpreter/framework-cast.js +16 -0
- package/dist/interpreter/message-helpers.d.ts +9 -0
- package/dist/interpreter/message-helpers.js +42 -0
- package/dist/interpreter/typeguards.d.ts +25 -0
- package/dist/interpreter/typeguards.js +50 -0
- package/dist/memory/budget.d.ts +23 -0
- package/dist/memory/budget.js +117 -0
- package/dist/memory/function-call-utils.d.ts +6 -0
- package/dist/memory/function-call-utils.js +25 -0
- package/dist/memory/layer-api.d.ts +14 -0
- package/dist/memory/layer-api.js +91 -0
- package/dist/memory/layer-lifecycle.d.ts +160 -0
- package/dist/memory/layer-lifecycle.js +552 -0
- package/dist/memory/layer-usage.d.ts +15 -0
- package/dist/memory/layer-usage.js +48 -0
- package/dist/memory/layers/durable-task-state.d.ts +79 -0
- package/dist/memory/layers/durable-task-state.js +118 -0
- package/dist/memory/layers/file-reference.d.ts +55 -0
- package/dist/memory/layers/file-reference.js +538 -0
- package/dist/memory/layers/history-window.d.ts +29 -0
- package/dist/memory/layers/history-window.js +114 -0
- package/dist/memory/layers/observational-memory.d.ts +53 -0
- package/dist/memory/layers/observational-memory.js +110 -0
- package/dist/memory/layers/plan.d.ts +55 -0
- package/dist/memory/layers/plan.js +369 -0
- package/dist/memory/layers/static-content.d.ts +27 -0
- package/dist/memory/layers/static-content.js +35 -0
- package/dist/memory/layers/steering.d.ts +51 -0
- package/dist/memory/layers/steering.js +258 -0
- package/dist/memory/layers/tool-memory-layer.d.ts +16 -0
- package/dist/memory/layers/tool-memory-layer.js +43 -0
- package/dist/memory/layers/working-memory.d.ts +44 -0
- package/dist/memory/layers/working-memory.js +92 -0
- package/dist/memory/projector.d.ts +10 -0
- package/dist/memory/projector.js +19 -0
- package/dist/memory/scope.d.ts +3 -0
- package/dist/memory/scope.js +31 -0
- package/dist/memory/strip-unresolved.d.ts +13 -0
- package/dist/memory/strip-unresolved.js +35 -0
- package/dist/observability/genai-attributes.d.ts +11 -0
- package/dist/observability/genai-attributes.js +12 -0
- package/dist/observability/span-impl.d.ts +20 -0
- package/dist/observability/span-impl.js +33 -0
- package/dist/observability/trace-exporter.d.ts +15 -0
- package/dist/observability/trace-exporter.js +26 -0
- package/dist/patterns/flow.d.ts +52 -0
- package/dist/patterns/flow.js +103 -0
- package/dist/patterns/interview.d.ts +53 -0
- package/dist/patterns/interview.js +113 -0
- package/dist/patterns/plans.d.ts +45 -0
- package/dist/patterns/plans.js +125 -0
- package/dist/patterns/ralph-wiggum.d.ts +20 -0
- package/dist/patterns/ralph-wiggum.js +37 -0
- package/dist/patterns/react.d.ts +18 -0
- package/dist/patterns/react.js +39 -0
- package/dist/portable.d.ts +26 -0
- package/dist/portable.js +34 -0
- package/dist/runtime/agent-harness.d.ts +206 -0
- package/dist/runtime/agent-harness.js +1170 -0
- package/dist/runtime/broadcaster-utils.d.ts +30 -0
- package/dist/runtime/broadcaster-utils.js +53 -0
- package/dist/runtime/channel-store.d.ts +18 -0
- package/dist/runtime/channel-store.js +187 -0
- package/dist/runtime/context-impl.d.ts +80 -0
- package/dist/runtime/context-impl.js +140 -0
- package/dist/runtime/cwd-helpers.d.ts +42 -0
- package/dist/runtime/cwd-helpers.js +68 -0
- package/dist/runtime/detached-handle.d.ts +14 -0
- package/dist/runtime/detached-handle.js +56 -0
- package/dist/runtime/event-broadcaster.d.ts +61 -0
- package/dist/runtime/event-broadcaster.js +187 -0
- package/dist/runtime/exec-context-factory.d.ts +25 -0
- package/dist/runtime/exec-context-factory.js +30 -0
- package/dist/runtime/in-memory-storage.d.ts +9 -0
- package/dist/runtime/in-memory-storage.js +33 -0
- package/dist/runtime/item-log-impl.d.ts +11 -0
- package/dist/runtime/item-log-impl.js +25 -0
- package/dist/runtime/message-queue.d.ts +30 -0
- package/dist/runtime/message-queue.js +46 -0
- package/dist/runtime/session-runner.d.ts +77 -0
- package/dist/runtime/session-runner.js +253 -0
- package/dist/runtime/session-streams.d.ts +11 -0
- package/dist/runtime/session-streams.js +204 -0
- package/dist/runtime/tool-memory.d.ts +6 -0
- package/dist/runtime/tool-memory.js +22 -0
- package/dist/schemas/item.d.ts +35 -0
- package/dist/schemas/item.js +155 -0
- package/dist/types/channel.d.ts +29 -0
- package/dist/types/channel.js +1 -0
- package/dist/types/common.d.ts +111 -0
- package/dist/types/common.js +1 -0
- package/dist/types/context.d.ts +93 -0
- package/dist/types/context.js +1 -0
- package/dist/types/detached.d.ts +17 -0
- package/dist/types/detached.js +7 -0
- package/dist/types/embed.d.ts +5 -0
- package/dist/types/embed.js +1 -0
- package/dist/types/error.d.ts +51 -0
- package/dist/types/error.js +1 -0
- package/dist/types/fs-adapter.d.ts +51 -0
- package/dist/types/fs-adapter.js +3 -0
- package/dist/types/harness-result.d.ts +43 -0
- package/dist/types/harness-result.js +2 -0
- package/dist/types/items.d.ts +115 -0
- package/dist/types/items.js +2 -0
- package/dist/types/memory.d.ts +336 -0
- package/dist/types/memory.js +13 -0
- package/dist/types/mutable-context.d.ts +13 -0
- package/dist/types/mutable-context.js +1 -0
- package/dist/types/observability.d.ts +30 -0
- package/dist/types/observability.js +1 -0
- package/dist/types/runtime.d.ts +255 -0
- package/dist/types/runtime.js +1 -0
- package/dist/types/shell-adapter.d.ts +34 -0
- package/dist/types/shell-adapter.js +10 -0
- package/dist/types/steering.d.ts +89 -0
- package/dist/types/steering.js +14 -0
- package/dist/types/step.d.ts +206 -0
- package/dist/types/step.js +1 -0
- package/dist/types/subprocess-adapter.d.ts +41 -0
- package/dist/types/subprocess-adapter.js +1 -0
- package/dist/types/tool-context.d.ts +34 -0
- package/dist/types/tool-context.js +1 -0
- package/dist/unstable.d.ts +28 -0
- package/dist/unstable.js +24 -0
- package/dist/until/combinators.d.ts +17 -0
- package/dist/until/combinators.js +49 -0
- package/dist/until/never.d.ts +9 -0
- package/dist/until/never.js +12 -0
- package/dist/until/predicates.d.ts +43 -0
- package/dist/until/predicates.js +126 -0
- package/package.json +81 -0
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import type { ZodTypeAny, z } from 'zod';
|
|
2
|
+
import type { FunctionCallItem, FunctionCallOutputItem, Item, ItemSchemaExtensions, ToolResultExtensionItem } from './items';
|
|
3
|
+
import type { ToolExecutionContext } from './tool-context';
|
|
4
|
+
type ToolExecutionResult<O extends ZodTypeAny> = Promise<z.infer<O>> | AsyncGenerator<unknown, z.infer<O>>;
|
|
5
|
+
/**
|
|
6
|
+
* Policy controlling automatic retry behavior on step failure.
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export interface RetryPolicy {
|
|
10
|
+
/** Maximum number of execution attempts (including the initial try). */
|
|
11
|
+
maxAttempts: number;
|
|
12
|
+
/** Backoff strategy between retries. */
|
|
13
|
+
backoff: 'fixed' | 'linear' | 'exponential';
|
|
14
|
+
/** Delay in ms before the first retry. */
|
|
15
|
+
initialDelay: number;
|
|
16
|
+
/** Upper bound in ms for the computed delay (caps exponential/linear growth). */
|
|
17
|
+
maxDelay?: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Optional parameters forwarded to the model provider during an LLM step.
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
export interface ModelParams {
|
|
24
|
+
/** Sampling temperature (0 = deterministic, higher = more creative). */
|
|
25
|
+
temperature?: number;
|
|
26
|
+
/** Nucleus sampling threshold (alternative to temperature). */
|
|
27
|
+
topP?: number;
|
|
28
|
+
/** Maximum number of tokens the model may generate. */
|
|
29
|
+
maxTokens?: number;
|
|
30
|
+
/** Sequences that cause the model to stop generating. */
|
|
31
|
+
stopSequences?: string[];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Declares tool-owned memory that the runtime materializes into a MemoryLayer.
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
export interface ToolMemoryDeclaration<TState = unknown> {
|
|
38
|
+
/** Shared id — tools with the same id share state. Defaults to `tool.name`. */
|
|
39
|
+
id?: string;
|
|
40
|
+
/** Factory for the initial state. */
|
|
41
|
+
init: () => TState;
|
|
42
|
+
/** Project state into the LLM context. Return null to omit. */
|
|
43
|
+
recall: (state: TState) => string | null;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* A tool definition that an LLM can invoke during execution.
|
|
47
|
+
* @public
|
|
48
|
+
*/
|
|
49
|
+
export interface Tool<I extends ZodTypeAny = ZodTypeAny, O extends ZodTypeAny = ZodTypeAny> {
|
|
50
|
+
/** Unique tool name used by the LLM for selection. */
|
|
51
|
+
name: string;
|
|
52
|
+
/** Human-readable description shown to the LLM. */
|
|
53
|
+
description: string;
|
|
54
|
+
/** Zod schema validating tool input arguments. */
|
|
55
|
+
input: I;
|
|
56
|
+
/** Zod schema validating tool return value. */
|
|
57
|
+
output: O;
|
|
58
|
+
/** Optional Zod schema validating streaming events yielded during execution. */
|
|
59
|
+
event?: ZodTypeAny;
|
|
60
|
+
/** Optional item schemas contributed by this tool for tool call/result extensions. */
|
|
61
|
+
itemSchemas?: Pick<ItemSchemaExtensions, 'toolCalls' | 'toolResults' | 'items'>;
|
|
62
|
+
/** Decorate the harness-created tool result item before it is appended/emitted. */
|
|
63
|
+
decorateResultItem?(params: {
|
|
64
|
+
baseItem: FunctionCallOutputItem;
|
|
65
|
+
callItem: FunctionCallItem;
|
|
66
|
+
args: z.infer<I>;
|
|
67
|
+
result: z.infer<O> | undefined;
|
|
68
|
+
output: string;
|
|
69
|
+
error?: boolean;
|
|
70
|
+
}): Item | ToolResultExtensionItem;
|
|
71
|
+
/** Async function that performs the tool's work. */
|
|
72
|
+
execute(args: z.infer<I>, toolCtx: ToolExecutionContext): ToolExecutionResult<O>;
|
|
73
|
+
/** When true, execution pauses for human approval before running. */
|
|
74
|
+
needsApproval?: boolean;
|
|
75
|
+
/** Optional memory declaration — the runtime generates a MemoryLayer from this. */
|
|
76
|
+
memory?: ToolMemoryDeclaration;
|
|
77
|
+
}
|
|
78
|
+
/** @public Aggregate token counts for an execution (input, output, total, cached). */
|
|
79
|
+
export interface TokenUsage {
|
|
80
|
+
input: number;
|
|
81
|
+
output: number;
|
|
82
|
+
total: number;
|
|
83
|
+
cached?: number;
|
|
84
|
+
}
|
|
85
|
+
/** @public Metadata captured from the most recent step execution. */
|
|
86
|
+
export interface StepMeta {
|
|
87
|
+
toolCalls?: FunctionCallItem[];
|
|
88
|
+
usage?: {
|
|
89
|
+
inputTokens: number;
|
|
90
|
+
outputTokens: number;
|
|
91
|
+
cachedTokens?: number;
|
|
92
|
+
};
|
|
93
|
+
cost?: number;
|
|
94
|
+
responseItems?: ReadonlyArray<Item>;
|
|
95
|
+
}
|
|
96
|
+
/** @public Structured response returned by a model adapter after an LLM call. */
|
|
97
|
+
export interface LLMResponse {
|
|
98
|
+
items: Item[];
|
|
99
|
+
usage: {
|
|
100
|
+
inputTokens: number;
|
|
101
|
+
outputTokens: number;
|
|
102
|
+
cachedTokens?: number;
|
|
103
|
+
};
|
|
104
|
+
cost?: number;
|
|
105
|
+
}
|
|
106
|
+
/** @public Configuration for the LLM provider used by the agent harness. */
|
|
107
|
+
export interface LlmProviderConfig {
|
|
108
|
+
provider: 'openrouter';
|
|
109
|
+
apiKey?: string;
|
|
110
|
+
}
|
|
111
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { ItemSchemaRegistry } from '../schemas/item';
|
|
2
|
+
import type { Channel } from './channel';
|
|
3
|
+
import type { StepMeta, TokenUsage, Tool } from './common';
|
|
4
|
+
import type { FsAdapter } from './fs-adapter';
|
|
5
|
+
import type { Item } from './items';
|
|
6
|
+
import type { ContextMemory, MemoryLayer } from './memory';
|
|
7
|
+
import type { Span } from './observability';
|
|
8
|
+
import type { AgentHarnessContract } from './runtime';
|
|
9
|
+
import type { ShellAdapter } from './shell-adapter';
|
|
10
|
+
import type { SubprocessAdapter } from './subprocess-adapter';
|
|
11
|
+
/** @public Append-only log of conversation items accumulated during execution. */
|
|
12
|
+
export interface ItemLog {
|
|
13
|
+
readonly items: ReadonlyArray<Item>;
|
|
14
|
+
append(item: Item): void;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* @public Mutable working-directory state shared among the tools attached to a
|
|
18
|
+
* single Context. The reference is fixed for the Context's lifetime; mutate
|
|
19
|
+
* via `setToolCwd` so that all tools observe the new value at execution time.
|
|
20
|
+
*
|
|
21
|
+
* Spawned children receive a snapshot — child mutations do not affect the parent.
|
|
22
|
+
*/
|
|
23
|
+
export interface CwdState {
|
|
24
|
+
cwd: string;
|
|
25
|
+
previousCwd?: string;
|
|
26
|
+
}
|
|
27
|
+
/** @public Per-layer contribution to the context window on the most recent LLM call. */
|
|
28
|
+
export interface LayerUsageEntry {
|
|
29
|
+
readonly layerId: string;
|
|
30
|
+
readonly tokenCount: number;
|
|
31
|
+
/** Items this layer contributed to the context view for the last LLM call. */
|
|
32
|
+
readonly items: ReadonlyArray<Item>;
|
|
33
|
+
}
|
|
34
|
+
/** @public Breakdown of the context window as of the most recent LLM call in an execution. */
|
|
35
|
+
export interface LastLayerUsage {
|
|
36
|
+
readonly executionId: string;
|
|
37
|
+
readonly modelId: string;
|
|
38
|
+
readonly layers: ReadonlyArray<LayerUsageEntry>;
|
|
39
|
+
readonly systemPromptTokens: number;
|
|
40
|
+
readonly toolsTokens: number;
|
|
41
|
+
readonly historyTokens: number;
|
|
42
|
+
readonly totalUsedTokens: number;
|
|
43
|
+
}
|
|
44
|
+
/** @public Execution context threaded through every step, carrying state, metrics, and channels. */
|
|
45
|
+
export interface Context<TMemory = ContextMemory, TState = unknown> {
|
|
46
|
+
readonly id: string;
|
|
47
|
+
readonly stepCount: number;
|
|
48
|
+
readonly tokens: TokenUsage;
|
|
49
|
+
readonly elapsed: number;
|
|
50
|
+
readonly cost: number;
|
|
51
|
+
state: TState;
|
|
52
|
+
readonly parent: Context<ContextMemory> | null;
|
|
53
|
+
readonly depth: number;
|
|
54
|
+
readonly span: Span;
|
|
55
|
+
readonly threadId: string;
|
|
56
|
+
readonly resourceId?: string;
|
|
57
|
+
readonly itemLog: ItemLog;
|
|
58
|
+
readonly lastStepMeta: StepMeta | null;
|
|
59
|
+
/** Per-layer breakdown of the context window as of the most recent callModel. Undefined until the first LLM call completes. */
|
|
60
|
+
readonly lastLayerUsage?: LastLayerUsage;
|
|
61
|
+
readonly harness: AgentHarnessContract;
|
|
62
|
+
/** Filesystem adapter for virtual or real filesystem access. */
|
|
63
|
+
readonly fs: FsAdapter;
|
|
64
|
+
/** Shell adapter for virtual or real shell command execution. */
|
|
65
|
+
readonly shell: ShellAdapter;
|
|
66
|
+
/** Subprocess adapter for virtual, same-process, or host process execution. */
|
|
67
|
+
readonly subprocess: SubprocessAdapter;
|
|
68
|
+
/**
|
|
69
|
+
* Mutable cwd state shared with the tools bound to this context. Tools
|
|
70
|
+
* resolve relative paths from `cwdState.cwd` at execution time so that an
|
|
71
|
+
* agent `cd` propagates to subsequent tool calls.
|
|
72
|
+
*/
|
|
73
|
+
readonly cwdState: CwdState;
|
|
74
|
+
readonly layers?: MemoryLayer[];
|
|
75
|
+
/** Layer provides keyed by layer ID. Access data/functions via `ctx.memory['layerId'].prop`. */
|
|
76
|
+
readonly memory: TMemory;
|
|
77
|
+
/** Unified tool set collected from all LLM steps in the step tree before execution. */
|
|
78
|
+
readonly unifiedTools?: ReadonlyArray<Tool>;
|
|
79
|
+
/** Runtime item schema registry active for this context. */
|
|
80
|
+
readonly itemSchemas?: ItemSchemaRegistry;
|
|
81
|
+
recv<T>(channel: Channel<T>, opts?: {
|
|
82
|
+
timeout?: number;
|
|
83
|
+
}): Promise<T>;
|
|
84
|
+
send<T>(channel: Channel<T>, value: T): void;
|
|
85
|
+
tryRecv<T>(channel: Channel<T>): T | null;
|
|
86
|
+
checkpoint(): Promise<void>;
|
|
87
|
+
complete<T>(value: T): void;
|
|
88
|
+
readonly completed: boolean;
|
|
89
|
+
readonly completionValue: unknown;
|
|
90
|
+
readonly aborted: boolean;
|
|
91
|
+
readonly abortReason?: string;
|
|
92
|
+
abort(reason?: string): void;
|
|
93
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** @public Lifecycle states for a detached (background) execution. */
|
|
2
|
+
declare const DetachedStatus: {
|
|
3
|
+
readonly Running: "running";
|
|
4
|
+
readonly Completed: "completed";
|
|
5
|
+
readonly Failed: "failed";
|
|
6
|
+
};
|
|
7
|
+
type DetachedStatus = (typeof DetachedStatus)[keyof typeof DetachedStatus];
|
|
8
|
+
/** @public Handle returned by `detachedSpawn`, used to poll or await a background execution. */
|
|
9
|
+
interface DetachedHandle<O> {
|
|
10
|
+
readonly id: string;
|
|
11
|
+
readonly status: DetachedStatus;
|
|
12
|
+
readonly result: O | undefined;
|
|
13
|
+
readonly error: string | undefined;
|
|
14
|
+
await(timeout?: number): Promise<O>;
|
|
15
|
+
}
|
|
16
|
+
export type { DetachedHandle };
|
|
17
|
+
export { DetachedStatus };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { ZodError, ZodType } from 'zod';
|
|
2
|
+
/** @public Discriminated union of all structured error kinds raised by the runtime. */
|
|
3
|
+
export type NoeticError = {
|
|
4
|
+
kind: 'step_failed';
|
|
5
|
+
stepId: string;
|
|
6
|
+
cause: Error;
|
|
7
|
+
retriesExhausted: boolean;
|
|
8
|
+
} | {
|
|
9
|
+
kind: 'llm_refused';
|
|
10
|
+
stepId: string;
|
|
11
|
+
refusal: string;
|
|
12
|
+
} | {
|
|
13
|
+
kind: 'llm_parse_error';
|
|
14
|
+
stepId: string;
|
|
15
|
+
raw: string;
|
|
16
|
+
schema: ZodType;
|
|
17
|
+
zodError: ZodError;
|
|
18
|
+
} | {
|
|
19
|
+
kind: 'llm_rate_limit';
|
|
20
|
+
stepId: string;
|
|
21
|
+
retryAfter?: number;
|
|
22
|
+
} | {
|
|
23
|
+
kind: 'fork_partial';
|
|
24
|
+
stepId: string;
|
|
25
|
+
succeeded: Array<{
|
|
26
|
+
stepId: string;
|
|
27
|
+
value: unknown;
|
|
28
|
+
}>;
|
|
29
|
+
failed: Array<{
|
|
30
|
+
stepId: string;
|
|
31
|
+
error: NoeticError;
|
|
32
|
+
}>;
|
|
33
|
+
} | {
|
|
34
|
+
kind: 'channel_timeout';
|
|
35
|
+
channelName: string;
|
|
36
|
+
timeout: number;
|
|
37
|
+
} | {
|
|
38
|
+
kind: 'channel_closed';
|
|
39
|
+
channelName: string;
|
|
40
|
+
} | {
|
|
41
|
+
kind: 'cancelled';
|
|
42
|
+
reason?: string;
|
|
43
|
+
} | {
|
|
44
|
+
kind: 'budget_exceeded';
|
|
45
|
+
field: 'cost' | 'steps' | 'duration';
|
|
46
|
+
limit: number;
|
|
47
|
+
actual: number;
|
|
48
|
+
} | {
|
|
49
|
+
kind: 'steering_denied';
|
|
50
|
+
guidance?: string;
|
|
51
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** @public Minimal stat result returned by the filesystem adapter. */
|
|
2
|
+
export interface FsStats {
|
|
3
|
+
size: number;
|
|
4
|
+
isDirectory(): boolean;
|
|
5
|
+
isSymbolicLink(): boolean;
|
|
6
|
+
isFile(): boolean;
|
|
7
|
+
}
|
|
8
|
+
/** @public Filesystem abstraction for agent runtime operations. */
|
|
9
|
+
export interface FsAdapter {
|
|
10
|
+
/** Read file contents as a Buffer. */
|
|
11
|
+
readFile(path: string): Promise<Buffer>;
|
|
12
|
+
/** Read file contents as a UTF-8 string. */
|
|
13
|
+
readFileText(path: string): Promise<string>;
|
|
14
|
+
/** Write string content to a file (UTF-8). */
|
|
15
|
+
writeFile(path: string, content: string): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Write raw bytes to a file. Use this when content may not be valid
|
|
18
|
+
* UTF-8 (binary attachments, images, etc.). Round-tripping through
|
|
19
|
+
* `writeFile` corrupts non-UTF-8 sequences.
|
|
20
|
+
*/
|
|
21
|
+
writeFileBytes(path: string, content: Buffer): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Append string content to a file (UTF-8). Creates the file if it does
|
|
24
|
+
* not exist. On POSIX, the underlying write uses `O_APPEND`, which is
|
|
25
|
+
* atomic for sub-`PIPE_BUF` writes — multiple concurrent writers can
|
|
26
|
+
* append without interleaving as long as each call's payload stays
|
|
27
|
+
* under that ceiling (4 KiB on Linux/macOS).
|
|
28
|
+
*/
|
|
29
|
+
appendFile(path: string, content: string): Promise<void>;
|
|
30
|
+
/** Create directories recursively. */
|
|
31
|
+
mkdir(dir: string): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Atomically rename a file or directory. On POSIX, this is the atomic
|
|
34
|
+
* swap used by write-temp + rename to publish a new file version
|
|
35
|
+
* without exposing readers to a half-written state.
|
|
36
|
+
*/
|
|
37
|
+
rename(oldPath: string, newPath: string): Promise<void>;
|
|
38
|
+
/** Remove a file or directory. With `recursive: true`, removes a directory tree. */
|
|
39
|
+
rm(path: string, options?: {
|
|
40
|
+
recursive?: boolean;
|
|
41
|
+
force?: boolean;
|
|
42
|
+
}): Promise<void>;
|
|
43
|
+
/** Check file accessibility (throws on failure). */
|
|
44
|
+
access(path: string, mode?: number): Promise<void>;
|
|
45
|
+
/** Get file/directory stats (follows symlinks). */
|
|
46
|
+
stat(path: string): Promise<FsStats>;
|
|
47
|
+
/** Get file/directory stats (does NOT follow symlinks). */
|
|
48
|
+
lstat(path: string): Promise<FsStats>;
|
|
49
|
+
/** Read directory entries (file names). */
|
|
50
|
+
readdir(path: string): Promise<string[]>;
|
|
51
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { LastLayerUsage } from './context';
|
|
2
|
+
import type { Item } from './items';
|
|
3
|
+
/** @public SDK-originated event from the OpenResponses streaming API. */
|
|
4
|
+
export interface SdkStreamEvent {
|
|
5
|
+
readonly source: 'sdk';
|
|
6
|
+
/** OpenResponses SSE event type string (e.g., 'response.output_text.delta'). */
|
|
7
|
+
readonly type: string;
|
|
8
|
+
readonly data: Record<string, unknown>;
|
|
9
|
+
readonly outputIndex?: number;
|
|
10
|
+
readonly contentIndex?: number;
|
|
11
|
+
}
|
|
12
|
+
/** @public Framework-originated event, prefixed with the harness config.name. */
|
|
13
|
+
export interface FrameworkStreamEvent {
|
|
14
|
+
readonly source: 'framework';
|
|
15
|
+
/** Prefixed event type (e.g., 'myagent:step_started'). */
|
|
16
|
+
readonly type: `${string}:${string}`;
|
|
17
|
+
readonly data: Record<string, unknown>;
|
|
18
|
+
}
|
|
19
|
+
/** @public Union of all stream event types emitted during execution. */
|
|
20
|
+
export type StreamEvent = SdkStreamEvent | FrameworkStreamEvent;
|
|
21
|
+
/** @public Final accumulated result of an execution, including all items, usage, cost, and extracted text.
|
|
22
|
+
*
|
|
23
|
+
* Returned from `AgentHarness.getAgentResponse()`. Resolves once the session's
|
|
24
|
+
* message queue drains and the runner goes idle. When multiple turns run in a
|
|
25
|
+
* burst (e.g. queued inbox messages), the response covers the span from the
|
|
26
|
+
* last-idle point through the point at which idle is reached again.
|
|
27
|
+
*/
|
|
28
|
+
export interface HarnessResponse {
|
|
29
|
+
readonly items: ReadonlyArray<Item>;
|
|
30
|
+
readonly usage: {
|
|
31
|
+
readonly inputTokens: number;
|
|
32
|
+
readonly outputTokens: number;
|
|
33
|
+
readonly cachedTokens?: number;
|
|
34
|
+
};
|
|
35
|
+
readonly cost?: number;
|
|
36
|
+
readonly text: string;
|
|
37
|
+
/** Per-memory-layer context window breakdown captured at the last callModel of this execution. */
|
|
38
|
+
readonly lastLayerUsage?: LastLayerUsage;
|
|
39
|
+
}
|
|
40
|
+
/** @public An Item snapshot with a completion flag, emitted from getItemStream(). */
|
|
41
|
+
export type StreamingItem = Item & {
|
|
42
|
+
readonly isComplete: boolean;
|
|
43
|
+
};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type * as OpenRouterAgent from '@openrouter/agent';
|
|
2
|
+
import type { ZodTypeAny, z } from 'zod';
|
|
3
|
+
type ResponseOutputText = OpenRouterAgent.ResponseOutputText;
|
|
4
|
+
type ResponsesImageGenerationCall = OpenRouterAgent.OutputImageGenerationCallItem;
|
|
5
|
+
type ResponsesOutputItemFileSearchCall = OpenRouterAgent.OutputFileSearchCallItem;
|
|
6
|
+
type ResponsesOutputItemFunctionCall = OpenRouterAgent.OutputFunctionCallItem;
|
|
7
|
+
type ResponsesOutputItemReasoning = OpenRouterAgent.OutputReasoningItem;
|
|
8
|
+
type ResponsesOutputMessage = OpenRouterAgent.OutputMessage;
|
|
9
|
+
type ResponsesWebSearchCallOutput = OpenRouterAgent.OutputWebSearchCallItem;
|
|
10
|
+
type ResponsesServerToolOutput = Exclude<OpenRouterAgent.OpenResponsesResult['output'][number], OpenRouterAgent.OutputMessage | OpenRouterAgent.OutputFunctionCallItem | OpenRouterAgent.OutputReasoningItem | OpenRouterAgent.OutputWebSearchCallItem | OpenRouterAgent.OutputFileSearchCallItem | OpenRouterAgent.OutputImageGenerationCallItem>;
|
|
11
|
+
type OutputMessageContentPart = OpenRouterAgent.OutputMessage['content'][number];
|
|
12
|
+
type OpenAIResponsesRefusalContent = Extract<OutputMessageContentPart, {
|
|
13
|
+
type: 'refusal';
|
|
14
|
+
}>;
|
|
15
|
+
type ReasoningContentPart = NonNullable<OpenRouterAgent.OutputReasoningItem['content']>[number];
|
|
16
|
+
type SummaryContentPart = NonNullable<OpenRouterAgent.OutputReasoningItem['summary']>[number];
|
|
17
|
+
type ReasoningTextContent = Extract<ReasoningContentPart, {
|
|
18
|
+
type: 'reasoning_text';
|
|
19
|
+
}>;
|
|
20
|
+
type ReasoningSummaryText = Extract<SummaryContentPart, {
|
|
21
|
+
type: 'summary_text';
|
|
22
|
+
}>;
|
|
23
|
+
/** @public Model-generated text content with optional annotations and logprobs. */
|
|
24
|
+
export type OutputTextPart = ResponseOutputText;
|
|
25
|
+
/** @public Model refusal content. */
|
|
26
|
+
export type RefusalPart = OpenAIResponsesRefusalContent;
|
|
27
|
+
/** @public User/developer input text (framework-created, not from SDK). */
|
|
28
|
+
export interface InputTextPart {
|
|
29
|
+
readonly type: 'input_text';
|
|
30
|
+
readonly text: string;
|
|
31
|
+
}
|
|
32
|
+
/** @public Reasoning trace content. */
|
|
33
|
+
export type ReasoningTextPart = ReasoningTextContent;
|
|
34
|
+
/** @public Reasoning summary content. */
|
|
35
|
+
export type SummaryTextPart = ReasoningSummaryText;
|
|
36
|
+
/** @public Content part variants for message items. */
|
|
37
|
+
export type ContentPart = OutputTextPart | RefusalPart | InputTextPart;
|
|
38
|
+
/** @public Assistant message output item. */
|
|
39
|
+
export type MessageItem = ResponsesOutputMessage;
|
|
40
|
+
/** @public Function call requested by the model. */
|
|
41
|
+
export type FunctionCallItem = ResponsesOutputItemFunctionCall;
|
|
42
|
+
/** @public Reasoning trace from the model. */
|
|
43
|
+
export type ReasoningItem = ResponsesOutputItemReasoning;
|
|
44
|
+
/** @public Web search call result. */
|
|
45
|
+
export type WebSearchItem = ResponsesWebSearchCallOutput;
|
|
46
|
+
/** @public File search call result. */
|
|
47
|
+
export type FileSearchItem = ResponsesOutputItemFileSearchCall;
|
|
48
|
+
/** @public Image generation call result. */
|
|
49
|
+
export type ImageGenerationItem = ResponsesImageGenerationCall;
|
|
50
|
+
/**
|
|
51
|
+
* @public Server tool output (vendor-prefixed type like `openrouter:datetime`).
|
|
52
|
+
* Constrains provider output items to the vendor-prefixed subset so discriminant narrowing works in Item unions.
|
|
53
|
+
*/
|
|
54
|
+
export type ServerToolItem = Omit<ResponsesServerToolOutput, 'type'> & {
|
|
55
|
+
readonly type: `${string}:${string}`;
|
|
56
|
+
};
|
|
57
|
+
/** @public Base shape required for framework and extension items. */
|
|
58
|
+
export interface ItemBase {
|
|
59
|
+
readonly type: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* @public Input message created by the framework (user, system, or developer role).
|
|
63
|
+
* Status includes `failed` as a Noetic extension beyond the Open Responses spec
|
|
64
|
+
* (which only defines `in_progress | completed | incomplete` for items).
|
|
65
|
+
*/
|
|
66
|
+
export interface InputMessageItem {
|
|
67
|
+
readonly id: string;
|
|
68
|
+
readonly type: 'message';
|
|
69
|
+
readonly role: 'user' | 'system' | 'developer';
|
|
70
|
+
readonly status: 'in_progress' | 'completed' | 'incomplete' | 'failed';
|
|
71
|
+
readonly content: InputTextPart[];
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* @public Tool execution output created by the harness during the tool loop.
|
|
75
|
+
* This is an input-only item type in Open Responses (sent by the developer, not the model).
|
|
76
|
+
*/
|
|
77
|
+
export interface FunctionCallOutputItem {
|
|
78
|
+
readonly id: string;
|
|
79
|
+
readonly type: 'function_call_output';
|
|
80
|
+
readonly status: 'in_progress' | 'completed' | 'incomplete' | 'failed';
|
|
81
|
+
readonly callId: string;
|
|
82
|
+
readonly output: string;
|
|
83
|
+
}
|
|
84
|
+
/** @public Item produced by an extension schema registered by a tool, memory layer, or harness. */
|
|
85
|
+
export type ExtensionItem = ItemBase & Record<string, unknown>;
|
|
86
|
+
/** @public Developer-role message item refined by a memory-layer extension schema. */
|
|
87
|
+
export type DeveloperMessageExtensionItem = InputMessageItem & {
|
|
88
|
+
readonly role: 'developer';
|
|
89
|
+
} & Record<string, unknown>;
|
|
90
|
+
/** @public Function-call item refined by a tool extension schema. */
|
|
91
|
+
export type ToolCallExtensionItem = FunctionCallItem & Record<string, unknown>;
|
|
92
|
+
/** @public Function-call output item refined by a tool extension schema. */
|
|
93
|
+
export type ToolResultExtensionItem = FunctionCallOutputItem & Record<string, unknown>;
|
|
94
|
+
/** @public Zod schemas that extend the runtime `Item` union. */
|
|
95
|
+
export interface ItemSchemaExtensions {
|
|
96
|
+
/** Harness-wide schemas. Any item matching one of these schemas is accepted. */
|
|
97
|
+
readonly items?: ReadonlyArray<ZodTypeAny>;
|
|
98
|
+
/** Schemas for memory-layer developer message items. */
|
|
99
|
+
readonly developerMessages?: ReadonlyArray<ZodTypeAny>;
|
|
100
|
+
/** Schemas for tool call items emitted by the model or a harness adapter. */
|
|
101
|
+
readonly toolCalls?: ReadonlyArray<ZodTypeAny>;
|
|
102
|
+
/** Schemas for tool result items emitted by the harness or a tool adapter. */
|
|
103
|
+
readonly toolResults?: ReadonlyArray<ZodTypeAny>;
|
|
104
|
+
}
|
|
105
|
+
/** @public Type inferred from an `ItemSchemaExtensions` declaration. */
|
|
106
|
+
export type InferExtendedItem<TExtensions extends ItemSchemaExtensions | undefined> = TExtensions extends ItemSchemaExtensions ? (TExtensions['items'] extends ReadonlyArray<infer S extends ZodTypeAny> ? z.infer<S> : never) | (TExtensions['developerMessages'] extends ReadonlyArray<infer S extends ZodTypeAny> ? z.infer<S> : never) | (TExtensions['toolCalls'] extends ReadonlyArray<infer S extends ZodTypeAny> ? z.infer<S> : never) | (TExtensions['toolResults'] extends ReadonlyArray<infer S extends ZodTypeAny> ? z.infer<S> : never) : never;
|
|
107
|
+
/** @public Item union extended by a concrete `ItemSchemaExtensions` declaration. */
|
|
108
|
+
export type ExtendedItem<TExtensions extends ItemSchemaExtensions | undefined> = Item | InferExtendedItem<TExtensions>;
|
|
109
|
+
/** @public All output item types from the model (Open Responses compliant). */
|
|
110
|
+
export type OutputItem = MessageItem | FunctionCallItem | ReasoningItem | WebSearchItem | FileSearchItem | ImageGenerationItem | ServerToolItem;
|
|
111
|
+
/** @public All item types that can appear in an ItemLog. */
|
|
112
|
+
export type Item = OutputItem | InputMessageItem | FunctionCallOutputItem;
|
|
113
|
+
/** @public Accepted input types for `AgentHarness.execute()`: a plain string, a single Item, or an array of Items. */
|
|
114
|
+
export type ExecuteInput = string | Item | Item[];
|
|
115
|
+
export {};
|