@agent-compose/sdk 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +145 -33
- package/dist/agent/agent-loop.d.ts +83 -5
- package/dist/agent/run-agent.d.ts +34 -9
- package/dist/client.d.ts +247 -99
- package/dist/index.d.ts +26 -11
- package/dist/index.js +1967 -745
- package/dist/processors/builtins.d.ts +35 -0
- package/dist/processors/index.d.ts +4 -0
- package/dist/processors/processor.d.ts +91 -0
- package/dist/processors/processor.test.d.ts +1 -0
- package/dist/processors/runner.d.ts +19 -0
- package/dist/request-context/index.d.ts +2 -0
- package/dist/request-context/request-context.d.ts +159 -0
- package/dist/request-context/request-context.test.d.ts +1 -0
- package/dist/runtimes/claude.d.ts +27 -50
- package/dist/runtimes/openai-desktop.js +1918 -741
- package/dist/runtimes/vercel.d.ts +34 -0
- package/dist/runtimes/vercel.js +474 -0
- package/dist/sandbox.d.ts +29 -25
- package/dist/step-invocation/__tests__/invoker.test.d.ts +1 -0
- package/dist/step-invocation/__tests__/protocol.test.d.ts +1 -0
- package/dist/step-invocation/__tests__/server.test.d.ts +1 -0
- package/dist/step-invocation/index.d.ts +25 -0
- package/dist/step-invocation/invoker.d.ts +65 -0
- package/dist/step-invocation/protocol.d.ts +44 -0
- package/dist/step-invocation/server.d.ts +63 -0
- package/dist/step-invocation/types.d.ts +72 -0
- package/dist/tools/coding.d.ts +49 -0
- package/dist/tools/coding.test.d.ts +1 -0
- package/dist/tools/index.d.ts +2 -0
- package/dist/types/events.d.ts +36 -0
- package/dist/types/execution-context.d.ts +22 -0
- package/dist/types/runtime.d.ts +32 -0
- package/dist/types/sandbox-environment.d.ts +5 -2
- package/dist/types/sandbox.d.ts +14 -12
- package/dist/types/workflow-metadata.d.ts +51 -0
- package/dist/types/workflow-plan.d.ts +19 -0
- package/dist/types/workflow.d.ts +57 -17
- package/dist/utils/bundler.d.ts +62 -3
- package/dist/workflow-steps/__tests__/observability.test.d.ts +1 -0
- package/dist/workflow-steps/index.d.ts +10 -0
- package/dist/workflow-steps/observability.d.ts +58 -0
- package/dist/workflow-steps/runner.d.ts +96 -0
- package/dist/workflow-steps/step.d.ts +25 -0
- package/dist/workflow-steps/types.d.ts +135 -0
- package/dist/workflow-steps/workflow-steps.test.d.ts +1 -0
- package/dist/workflow-steps/workflow.d.ts +50 -0
- package/dist/workflows/engine.d.ts +27 -13
- package/dist/workflows/invoke-child.d.ts +10 -0
- package/package.json +25 -15
- package/src/agent/agent-loop.ts +197 -26
- package/src/agent/run-agent.ts +40 -15
- package/src/client.ts +326 -76
- package/src/index.ts +124 -10
- package/src/processors/builtins.ts +72 -0
- package/src/processors/index.ts +15 -0
- package/src/processors/processor.ts +103 -0
- package/src/processors/runner.ts +42 -0
- package/src/request-context/index.ts +17 -0
- package/src/request-context/request-context.ts +302 -0
- package/src/runtimes/claude.ts +123 -254
- package/src/runtimes/vercel.ts +180 -0
- package/src/sandbox.ts +53 -21
- package/src/step-invocation/index.ts +33 -0
- package/src/step-invocation/invoker.ts +204 -0
- package/src/step-invocation/protocol.ts +57 -0
- package/src/step-invocation/server.ts +184 -0
- package/src/step-invocation/types.ts +70 -0
- package/src/tools/coding.ts +126 -0
- package/src/tools/index.ts +8 -0
- package/src/types/events.ts +40 -0
- package/src/types/execution-context.ts +30 -0
- package/src/types/runtime.ts +24 -0
- package/src/types/sandbox-environment.ts +7 -5
- package/src/types/sandbox.ts +16 -12
- package/src/types/workflow-metadata.ts +84 -0
- package/src/types/workflow-plan.ts +24 -0
- package/src/types/workflow.ts +139 -25
- package/src/utils/bundler.ts +198 -18
- package/src/utils/source-loader.ts +2 -2
- package/src/workflow-steps/index.ts +30 -0
- package/src/workflow-steps/observability.ts +103 -0
- package/src/workflow-steps/runner.ts +244 -0
- package/src/workflow-steps/step.ts +38 -0
- package/src/workflow-steps/types.ts +134 -0
- package/src/workflow-steps/workflow.ts +95 -0
- package/src/workflows/engine.ts +69 -40
- package/src/workflows/invoke-child.ts +29 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in processors — minimal set that exercises all three hooks and
|
|
3
|
+
* covers the most common gating needs. More can be authored by users; these
|
|
4
|
+
* exist as load-bearing examples and as defaults for common policies.
|
|
5
|
+
*/
|
|
6
|
+
import type { Processor } from "./processor.js";
|
|
7
|
+
/**
|
|
8
|
+
* Reject any tool call whose name appears in `names`. The reason is returned
|
|
9
|
+
* to the model as the tool result, so the model can react and try a
|
|
10
|
+
* different approach.
|
|
11
|
+
*
|
|
12
|
+
* Dormant in runtimes that don't support pre-tool gating (current Claude CLI
|
|
13
|
+
* runtime). Becomes active when a runtime that wires `processToolCall` lands
|
|
14
|
+
* (candidate #1).
|
|
15
|
+
*/
|
|
16
|
+
export declare function denyTools(names: readonly string[]): Processor;
|
|
17
|
+
/**
|
|
18
|
+
* Require the calling API key to carry every scope in `required`. Aborts the
|
|
19
|
+
* agent loop with a clear reason if any are missing — defence-in-depth on
|
|
20
|
+
* top of the server's per-call scope checks.
|
|
21
|
+
*
|
|
22
|
+
* Runs as `processInput` so the violation is caught before the model is
|
|
23
|
+
* invoked, not after work has happened.
|
|
24
|
+
*/
|
|
25
|
+
export declare function requireScope(required: readonly string[]): Processor;
|
|
26
|
+
/**
|
|
27
|
+
* Redact substrings matching `pattern` from each emitted text/thinking
|
|
28
|
+
* message before downstream observability sees it. Useful for stripping
|
|
29
|
+
* accidental secret echoes (e.g. a model that pasted an env var into its
|
|
30
|
+
* reasoning).
|
|
31
|
+
*
|
|
32
|
+
* Tool result and tool use messages are passed through unchanged — those
|
|
33
|
+
* paths have their own redaction story (network policy + secret brokering).
|
|
34
|
+
*/
|
|
35
|
+
export declare function redactPattern(pattern: RegExp, replacement?: string): Processor;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Processor — typed pre/post pipeline around the agent loop.
|
|
3
|
+
*
|
|
4
|
+
* One generic shape across three hook points:
|
|
5
|
+
*
|
|
6
|
+
* - processInput(prompt, ctx) → before each iteration's model call
|
|
7
|
+
* - processOutput(message, ctx) → after each emitted message
|
|
8
|
+
* - processToolCall(call, ctx) → before each tool call (runtime-driven)
|
|
9
|
+
*
|
|
10
|
+
* Why this exists: the user's "pre-tool-use hook", "policy", "falsifier", and
|
|
11
|
+
* "classifier" requirements are all the same shape — a typed step around the
|
|
12
|
+
* agent loop with access to RequestContext, an abort channel, and the
|
|
13
|
+
* ability to mutate or reject. Inventing four parallel APIs is the smell;
|
|
14
|
+
* one Processor interface is the cure.
|
|
15
|
+
*
|
|
16
|
+
* Verdict semantics differ by hook:
|
|
17
|
+
*
|
|
18
|
+
* processInput deny → agent loop ends with WorkflowError(reason)
|
|
19
|
+
* processOutput deny → message dropped; loop continues
|
|
20
|
+
* processToolCall deny → tool short-circuited; reason returned to the
|
|
21
|
+
* model as the tool result; loop continues
|
|
22
|
+
*
|
|
23
|
+
* abort (any hook) → whole agent loop ends with WorkflowError(reason)
|
|
24
|
+
*
|
|
25
|
+
* Composition: workflow-level processors run first, then agent-level. First
|
|
26
|
+
* non-`continue` verdict short-circuits the chain for that hook target.
|
|
27
|
+
*
|
|
28
|
+
* Built-ins live in ./builtins.ts; chain executor lives in ./runner.ts.
|
|
29
|
+
*/
|
|
30
|
+
import type { AgentMessage } from "../types/protocol.js";
|
|
31
|
+
import type { RequestContext } from "../request-context/request-context.js";
|
|
32
|
+
/** Proposed tool call. Mirrors the relevant fields of AgentMessageToolUse but
|
|
33
|
+
* lives as its own type so runtime adapters (candidate #1) can populate it
|
|
34
|
+
* from their internal call shape without coupling to the agent message protocol. */
|
|
35
|
+
export interface ToolCall {
|
|
36
|
+
toolName: string;
|
|
37
|
+
toolInput: Record<string, unknown>;
|
|
38
|
+
toolUseId: string;
|
|
39
|
+
}
|
|
40
|
+
/** Per-hook context. Minimal by design — observability sinks and stream
|
|
41
|
+
* writers are NOT shipped in v1; add when concrete need shows up. */
|
|
42
|
+
export interface ProcessorContext {
|
|
43
|
+
/** Per-run typed bag (tenant identity + freeform). */
|
|
44
|
+
requestContext: RequestContext;
|
|
45
|
+
/** Parent-loop cancellation — long-running processors should pass to fetch/etc. */
|
|
46
|
+
abortSignal: AbortSignal;
|
|
47
|
+
/** How many times processors have triggered retry for this generation. */
|
|
48
|
+
retryCount: number;
|
|
49
|
+
/** Which agent loop triggered this hook. */
|
|
50
|
+
agentId: string;
|
|
51
|
+
/** Iteration of the agent loop (1-based). */
|
|
52
|
+
iteration: number;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Verdict returned by every processor method.
|
|
56
|
+
* `continue` carries the (possibly mutated) value forward.
|
|
57
|
+
* `deny` and `abort` short-circuit the chain; their loop-level effect is
|
|
58
|
+
* defined per hook (see file header).
|
|
59
|
+
*/
|
|
60
|
+
export type ProcessorVerdict<T> = {
|
|
61
|
+
kind: "continue";
|
|
62
|
+
value: T;
|
|
63
|
+
} | {
|
|
64
|
+
kind: "deny";
|
|
65
|
+
reason: string;
|
|
66
|
+
} | {
|
|
67
|
+
kind: "abort";
|
|
68
|
+
reason: string;
|
|
69
|
+
};
|
|
70
|
+
/** Construction helpers — keep call sites readable. */
|
|
71
|
+
export declare const Verdict: {
|
|
72
|
+
readonly continue: <T>(value: T) => ProcessorVerdict<T>;
|
|
73
|
+
readonly deny: <T = never>(reason: string) => ProcessorVerdict<T>;
|
|
74
|
+
readonly abort: <T = never>(reason: string) => ProcessorVerdict<T>;
|
|
75
|
+
};
|
|
76
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
77
|
+
/**
|
|
78
|
+
* A Processor implements zero or more of the three hook methods. Methods
|
|
79
|
+
* may be sync or async. Omit a method to opt out of that hook.
|
|
80
|
+
*
|
|
81
|
+
* Processors should be cheap and deterministic where possible — the chain
|
|
82
|
+
* runs sequentially and gating is order-sensitive.
|
|
83
|
+
*/
|
|
84
|
+
export interface Processor {
|
|
85
|
+
/** Stable name for logging / metrics. Defaults to constructor / class name. */
|
|
86
|
+
readonly name?: string;
|
|
87
|
+
processInput?(prompt: string, ctx: ProcessorContext): MaybePromise<ProcessorVerdict<string>>;
|
|
88
|
+
processOutput?(message: AgentMessage, ctx: ProcessorContext): MaybePromise<ProcessorVerdict<AgentMessage>>;
|
|
89
|
+
processToolCall?(call: ToolCall, ctx: ProcessorContext): MaybePromise<ProcessorVerdict<ToolCall>>;
|
|
90
|
+
}
|
|
91
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Processor chain runner — sequentially applies a list of processors to a
|
|
3
|
+
* value at one hook point, threading the (possibly mutated) value through
|
|
4
|
+
* each step. First non-`continue` verdict short-circuits the rest of the
|
|
5
|
+
* chain for that target.
|
|
6
|
+
*
|
|
7
|
+
* The chain is hook-agnostic: caller passes a `select` function that picks
|
|
8
|
+
* the relevant method off each Processor. Returns the final verdict — the
|
|
9
|
+
* agent loop interprets it per-hook semantics.
|
|
10
|
+
*/
|
|
11
|
+
import type { Processor, ProcessorContext, ProcessorVerdict } from "./processor.js";
|
|
12
|
+
type HookSelector<T> = (p: Processor) => ((value: T, ctx: ProcessorContext) => ProcessorVerdict<T> | Promise<ProcessorVerdict<T>>) | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Run a chain of processors against `initial`. Skips processors that don't
|
|
15
|
+
* implement the selected hook. Returns the final verdict; for `continue`
|
|
16
|
+
* the `value` is the threaded-through (possibly mutated) result.
|
|
17
|
+
*/
|
|
18
|
+
export declare function runProcessorChain<T>(processors: readonly Processor[], selectHook: HookSelector<T>, initial: T, ctx: ProcessorContext): Promise<ProcessorVerdict<T>>;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { RequestContext, ReservedKeyError, NonSerialisableValueError, AC_RESERVED_PREFIX, AC_TEAM_ID, AC_RUN_ID, AC_WORKFLOW_ID, AC_FACTORY_ID, AC_API_KEY_SCOPES, AC_PARENT_RUN_ID, AC_ABORT_SIGNAL, } from "./request-context.js";
|
|
2
|
+
export type { RequestContextReserved, RequestContextWire, } from "./request-context.js";
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RequestContext — one typed bag carrying tenant identity + freeform
|
|
3
|
+
* per-run state across the boundary between server, dispatch, runner,
|
|
4
|
+
* workflow body, agent loop, and (future) processors.
|
|
5
|
+
*
|
|
6
|
+
* Two halves:
|
|
7
|
+
*
|
|
8
|
+
* - **Reserved keys** are tenant identity + run identity. They are
|
|
9
|
+
* authoritative once the server's auth middleware sets them and
|
|
10
|
+
* CANNOT be mutated downstream — `set()` on a reserved key throws.
|
|
11
|
+
* This is the same multi-tenancy hijack defence we apply at the RLS
|
|
12
|
+
* layer: the runner never gets to claim a different `teamId`.
|
|
13
|
+
*
|
|
14
|
+
* - **Freeform user namespace** is plain `set/get/has/delete` for any
|
|
15
|
+
* JSON-serialisable values the caller wants to thread through. Used
|
|
16
|
+
* by application code (workflows, processors) for their own state.
|
|
17
|
+
*
|
|
18
|
+
* Reserved-key authority:
|
|
19
|
+
*
|
|
20
|
+
* ac__teamId server (auth middleware)
|
|
21
|
+
* ac__runId server (dispatch)
|
|
22
|
+
* ac__workflowId server (dispatch)
|
|
23
|
+
* ac__factoryId server (auth) -- nullable
|
|
24
|
+
* ac__apiKeyScopes server (auth)
|
|
25
|
+
* ac__parentRunId server (dispatch) -- nullable
|
|
26
|
+
* ac__abortSignal runner (per-process) -- not serialised
|
|
27
|
+
*
|
|
28
|
+
* Cross-process flow (server → runner):
|
|
29
|
+
*
|
|
30
|
+
* 1. Server constructs `RequestContext` at the auth boundary using the
|
|
31
|
+
* reserved key authorities listed above.
|
|
32
|
+
* 2. `serialise()` → JSON shape `{ reserved, user }` (abortSignal stripped).
|
|
33
|
+
* 3. Dispatch hands the JSON to the runner sandbox via env (or future
|
|
34
|
+
* transport).
|
|
35
|
+
* 4. Runner calls `RequestContext.deserialise(json)` and attaches its
|
|
36
|
+
* own `AbortSignal`. Reserved keys are re-frozen on materialisation.
|
|
37
|
+
*
|
|
38
|
+
* `invokeChild` propagation: only reserved keys flow to the child; freeform
|
|
39
|
+
* is per-run by design (cross-run state must be explicit via `input`).
|
|
40
|
+
*/
|
|
41
|
+
/** Reserved key namespace prefix — anything starting with this is platform-owned. */
|
|
42
|
+
export declare const AC_RESERVED_PREFIX = "ac__";
|
|
43
|
+
export declare const AC_TEAM_ID: "ac__teamId";
|
|
44
|
+
export declare const AC_RUN_ID: "ac__runId";
|
|
45
|
+
export declare const AC_WORKFLOW_ID: "ac__workflowId";
|
|
46
|
+
export declare const AC_FACTORY_ID: "ac__factoryId";
|
|
47
|
+
export declare const AC_API_KEY_SCOPES: "ac__apiKeyScopes";
|
|
48
|
+
export declare const AC_PARENT_RUN_ID: "ac__parentRunId";
|
|
49
|
+
export declare const AC_ABORT_SIGNAL: "ac__abortSignal";
|
|
50
|
+
/** Reserved keys, as a runtime set for guardrails. Includes all keys above. */
|
|
51
|
+
declare const RESERVED_KEYS: ReadonlySet<string>;
|
|
52
|
+
/** Reserved keys that cross the dispatch boundary as JSON. Excludes `abortSignal`. */
|
|
53
|
+
declare const SERIALISABLE_RESERVED_KEYS: ReadonlySet<string>;
|
|
54
|
+
/**
|
|
55
|
+
* Required reserved values to construct a context. `factoryId` and
|
|
56
|
+
* `parentRunId` are nullable (factory-scoped key absent → null; root run → null).
|
|
57
|
+
* `abortSignal` is optional and runner-set; not serialised.
|
|
58
|
+
*/
|
|
59
|
+
export interface RequestContextReserved {
|
|
60
|
+
teamId: string;
|
|
61
|
+
runId: string;
|
|
62
|
+
workflowId: string;
|
|
63
|
+
factoryId: string | null;
|
|
64
|
+
apiKeyScopes: readonly string[];
|
|
65
|
+
parentRunId: string | null;
|
|
66
|
+
abortSignal?: AbortSignal;
|
|
67
|
+
}
|
|
68
|
+
/** Wire shape for crossing the dispatch boundary. `abortSignal` is stripped. */
|
|
69
|
+
export interface RequestContextWire {
|
|
70
|
+
reserved: {
|
|
71
|
+
teamId: string;
|
|
72
|
+
runId: string;
|
|
73
|
+
workflowId: string;
|
|
74
|
+
factoryId: string | null;
|
|
75
|
+
apiKeyScopes: readonly string[];
|
|
76
|
+
parentRunId: string | null;
|
|
77
|
+
};
|
|
78
|
+
user: Record<string, unknown>;
|
|
79
|
+
}
|
|
80
|
+
/** Thrown when a caller tries to `set` or `delete` a reserved key downstream. */
|
|
81
|
+
export declare class ReservedKeyError extends Error {
|
|
82
|
+
readonly key: string;
|
|
83
|
+
constructor(key: string);
|
|
84
|
+
}
|
|
85
|
+
/** Thrown when freeform `set` receives a non-JSON-serialisable value. */
|
|
86
|
+
export declare class NonSerialisableValueError extends Error {
|
|
87
|
+
constructor(key: string, cause: unknown);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Per-run request context. Construct via `RequestContext.fromReserved(...)`
|
|
91
|
+
* at the auth boundary; downstream code receives an instance and calls
|
|
92
|
+
* `.get` / `.set` on it.
|
|
93
|
+
*
|
|
94
|
+
* Type parameter `U` lets callers narrow the freeform user namespace shape
|
|
95
|
+
* for `.get`/`.set` typing — defaults to `unknown` (truly freeform).
|
|
96
|
+
*/
|
|
97
|
+
export declare class RequestContext<U extends Record<string, unknown> = Record<string, unknown>> {
|
|
98
|
+
private readonly reserved;
|
|
99
|
+
private readonly user;
|
|
100
|
+
private constructor();
|
|
101
|
+
/**
|
|
102
|
+
* Build a context at the auth/dispatch boundary. Callers (server auth
|
|
103
|
+
* middleware, dispatch) own the reserved values and pass them in once.
|
|
104
|
+
*/
|
|
105
|
+
static fromReserved(reserved: RequestContextReserved): RequestContext;
|
|
106
|
+
/**
|
|
107
|
+
* Materialise from the wire shape produced by `serialise()`.
|
|
108
|
+
* Used by the runner after receiving the JSON via env. The runner attaches
|
|
109
|
+
* its own `AbortSignal` separately via `withAbortSignal()`.
|
|
110
|
+
*/
|
|
111
|
+
static deserialise(wire: RequestContextWire): RequestContext;
|
|
112
|
+
/**
|
|
113
|
+
* Return a new instance with the given abort signal attached. Used by the
|
|
114
|
+
* runner once it owns a per-process signal.
|
|
115
|
+
*/
|
|
116
|
+
withAbortSignal(signal: AbortSignal): RequestContext;
|
|
117
|
+
get teamId(): string;
|
|
118
|
+
get runId(): string;
|
|
119
|
+
get workflowId(): string;
|
|
120
|
+
get factoryId(): string | null;
|
|
121
|
+
get apiKeyScopes(): readonly string[];
|
|
122
|
+
get parentRunId(): string | null;
|
|
123
|
+
get abortSignal(): AbortSignal | undefined;
|
|
124
|
+
/** True if the calling key has the given scope. Read-only convenience. */
|
|
125
|
+
hasScope(scope: string): boolean;
|
|
126
|
+
/**
|
|
127
|
+
* Set a freeform key. Throws `ReservedKeyError` if `key` collides with the
|
|
128
|
+
* reserved namespace, and `NonSerialisableValueError` if `value` cannot be
|
|
129
|
+
* JSON-serialised (so cross-process behaviour matches in-process behaviour).
|
|
130
|
+
*/
|
|
131
|
+
set<K extends keyof U & string>(key: K, value: U[K]): void;
|
|
132
|
+
set(key: string, value: unknown): void;
|
|
133
|
+
get<K extends keyof U & string>(key: K): U[K] | undefined;
|
|
134
|
+
get(key: string): unknown;
|
|
135
|
+
has(key: string): boolean;
|
|
136
|
+
delete(key: string): boolean;
|
|
137
|
+
/** Iterate freeform entries only. Reserved keys are not iterable. */
|
|
138
|
+
entries(): IterableIterator<[string, unknown]>;
|
|
139
|
+
/**
|
|
140
|
+
* Produce the wire shape for crossing the dispatch boundary. `abortSignal`
|
|
141
|
+
* is stripped; freeform values are passed through (they were validated as
|
|
142
|
+
* JSON-serialisable on `set`).
|
|
143
|
+
*/
|
|
144
|
+
serialise(): RequestContextWire;
|
|
145
|
+
/**
|
|
146
|
+
* Build a child context for an `invokeChild` call: reserved keys propagate
|
|
147
|
+
* (with `parentRunId` rewritten to the parent's `runId` and `runId`/`workflowId`
|
|
148
|
+
* supplied by the caller for the child run); freeform DOES NOT propagate.
|
|
149
|
+
*
|
|
150
|
+
* Used server-side when dispatch resolves a child invocation; the freeform
|
|
151
|
+
* namespace is intentionally per-run to keep cross-run state explicit.
|
|
152
|
+
*/
|
|
153
|
+
forChild(opts: {
|
|
154
|
+
runId: string;
|
|
155
|
+
workflowId: string;
|
|
156
|
+
}): RequestContext;
|
|
157
|
+
}
|
|
158
|
+
/** Re-export reserved key set for callers that need to filter env or headers. */
|
|
159
|
+
export { SERIALISABLE_RESERVED_KEYS, RESERVED_KEYS };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,63 +1,40 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* selected via SANDBOX_PROVIDER env var, not the runtime definition.
|
|
6
|
-
*
|
|
7
|
-
* Usage:
|
|
8
|
-
* import { createClaudeRuntime } from "@agent-compose/sdk";
|
|
9
|
-
* export default createClaudeRuntime({ claudeMdContent: "..." }); // optional global instructions
|
|
10
|
-
*/
|
|
11
|
-
import type { SandboxProvider, AgentMessage, ModelExecutionContract, RuntimeOptions } from "../index.js";
|
|
12
|
-
export declare class ClaudeRunner implements ModelExecutionContract {
|
|
13
|
-
private sandbox;
|
|
14
|
-
private options;
|
|
15
|
-
private claudeMdContent;
|
|
16
|
-
private configEnv;
|
|
17
|
-
private configModel?;
|
|
18
|
-
private configMcpServers?;
|
|
19
|
-
private claudeMdWritten;
|
|
20
|
-
private homeDir;
|
|
21
|
-
private label;
|
|
22
|
-
constructor(sandbox: SandboxProvider, options?: RuntimeOptions, claudeMdContent?: string, configEnv?: Record<string, string>, configModel?: string | undefined, configMcpServers?: Record<string, {
|
|
23
|
-
command: string;
|
|
24
|
-
args?: string[];
|
|
25
|
-
env?: Record<string, string>;
|
|
26
|
-
}> | undefined);
|
|
27
|
-
private getHomeDir;
|
|
28
|
-
private deployGlobalConfig;
|
|
29
|
-
/** Stream one CLI invocation, yielding AgentMessages. Resolves when the process exits. */
|
|
30
|
-
private _runCli;
|
|
31
|
-
sendMessage(opts: {
|
|
32
|
-
prompt: string;
|
|
33
|
-
sessionId?: string;
|
|
34
|
-
signal?: AbortSignal;
|
|
35
|
-
}): AsyncGenerator<AgentMessage>;
|
|
36
|
-
}
|
|
1
|
+
/** Claude Agent SDK runtime — replaces the old Claude CLI subprocess runtime. */
|
|
2
|
+
import { type ThinkingConfig } from "@anthropic-ai/claude-agent-sdk";
|
|
3
|
+
import type { AgentMessage, ModelExecutionContract, RuntimeOptions, SandboxProvider, ToolCallGateResult } from "../index.js";
|
|
4
|
+
import type { ProcessorContext, ToolCall } from "../processors/processor.js";
|
|
37
5
|
export interface ClaudeRuntimeConfig {
|
|
38
|
-
/** Global instructions
|
|
6
|
+
/** Global instructions appended to the Claude Code system prompt. */
|
|
39
7
|
claudeMdContent?: string;
|
|
40
|
-
/**
|
|
41
|
-
* Environment variables set before each CLI invocation.
|
|
42
|
-
* Use to configure API provider routing (e.g. OpenRouter):
|
|
43
|
-
* env: { ANTHROPIC_BASE_URL: "https://openrouter.ai/api", ANTHROPIC_AUTH_TOKEN: "$OPENROUTER_API_KEY", ANTHROPIC_API_KEY: "" }
|
|
44
|
-
*/
|
|
8
|
+
/** Env overrides for Agent SDK provider routing. */
|
|
45
9
|
env?: Record<string, string>;
|
|
46
|
-
/** Model to use
|
|
10
|
+
/** Model to use. Defaults to DEFAULT_CLAUDE_MODEL. */
|
|
47
11
|
model?: string;
|
|
48
|
-
/** MCP servers to configure
|
|
12
|
+
/** MCP servers to configure for the Agent SDK. */
|
|
49
13
|
mcpServers?: Record<string, {
|
|
50
14
|
command: string;
|
|
51
15
|
args?: string[];
|
|
52
16
|
env?: Record<string, string>;
|
|
53
17
|
}>;
|
|
18
|
+
/** Claude Code executable. Defaults to `claude` from PATH inside the sandbox. */
|
|
19
|
+
pathToClaudeCodeExecutable?: string;
|
|
20
|
+
/** Controls Claude's extended thinking behavior when supported by the model. */
|
|
21
|
+
thinking?: ThinkingConfig;
|
|
22
|
+
/** Reasoning effort hint for models that support adaptive thinking. */
|
|
23
|
+
effort?: "low" | "medium" | "high" | "xhigh" | "max";
|
|
24
|
+
}
|
|
25
|
+
export declare class ClaudeRunner implements ModelExecutionContract {
|
|
26
|
+
private readonly options;
|
|
27
|
+
private readonly config;
|
|
28
|
+
supportsToolCallProcessor: boolean;
|
|
29
|
+
constructor(_sandbox: SandboxProvider, options?: RuntimeOptions, config?: ClaudeRuntimeConfig);
|
|
30
|
+
gateToolCall(call: ToolCall, ctx: ProcessorContext): Promise<ToolCallGateResult>;
|
|
31
|
+
sendMessage(opts: {
|
|
32
|
+
prompt: string;
|
|
33
|
+
sessionId?: string;
|
|
34
|
+
iteration?: number;
|
|
35
|
+
signal?: AbortSignal;
|
|
36
|
+
}): AsyncGenerator<AgentMessage>;
|
|
54
37
|
}
|
|
55
|
-
/**
|
|
56
|
-
* Create a Claude CLI runtime.
|
|
57
|
-
*
|
|
58
|
-
* Encapsulates everything about how the Claude CLI runs in a sandbox:
|
|
59
|
-
* API provider routing, MCP server configuration, and global instructions.
|
|
60
|
-
*/
|
|
61
38
|
export declare function createClaudeRuntime(config?: ClaudeRuntimeConfig): import("../index.js").AgentRuntime<SandboxProvider>;
|
|
62
39
|
declare const _default: import("../index.js").AgentRuntime<SandboxProvider>;
|
|
63
40
|
export default _default;
|