@cybernetyx1/atlasflow-runtime 0.1.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/LICENSE +18 -0
- package/README.md +56 -0
- package/dist/adapter/index.d.ts +1 -0
- package/dist/adapter/index.js +0 -0
- package/dist/channel-Dv3Hv1ee.d.ts +634 -0
- package/dist/chunk-4DU4GJ2X.js +347 -0
- package/dist/chunk-HO6QHSUS.js +85 -0
- package/dist/chunk-M4JW76IL.js +1161 -0
- package/dist/chunk-RF6W3TKJ.js +2762 -0
- package/dist/chunk-S7RZJMCF.js +47 -0
- package/dist/cloudflare/index.d.ts +109 -0
- package/dist/cloudflare/index.js +212 -0
- package/dist/command-kxrqWIH7.d.ts +204 -0
- package/dist/index-UFTgKRK4.d.ts +589 -0
- package/dist/index.d.ts +739 -0
- package/dist/index.js +965 -0
- package/dist/node/index.d.ts +65 -0
- package/dist/node/index.js +251 -0
- package/dist/providers.d.ts +40 -0
- package/dist/providers.js +26 -0
- package/dist/routing/index.d.ts +256 -0
- package/dist/routing/index.js +2184 -0
- package/package.json +68 -0
- package/schemas/persona-manifest.v1.schema.json +258 -0
|
@@ -0,0 +1,634 @@
|
|
|
1
|
+
import * as v from 'valibot';
|
|
2
|
+
import { GenericSchema, InferOutput } from 'valibot';
|
|
3
|
+
import { b as SandboxFactory, C as Command } from './command-kxrqWIH7.js';
|
|
4
|
+
import { M as ModelConfig, n as Message, T as ThinkingLevel, C as CacheRetention, E as EventBus, U as Usage, o as PromptImage, P as PersistenceAdapter, A as AtlasEvent, R as RunRecord } from './index-UFTgKRK4.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The AgentEngine seam — the single swap boundary for the model/agentic layer.
|
|
8
|
+
*
|
|
9
|
+
* pi-ai implements this today (engine-pi.ts). Nothing outside the adapter
|
|
10
|
+
* imports pi-ai. When we replace pi-ai with our own agentic loop, we implement
|
|
11
|
+
* this same interface and swap one reference in runtime.ts — every harness,
|
|
12
|
+
* session, tool, and event keeps working unchanged. Keep this vendor-free.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
type ToolChoice = "auto" | "required" | "none";
|
|
16
|
+
interface ToolApprovalPolicy {
|
|
17
|
+
required: true;
|
|
18
|
+
reason?: string;
|
|
19
|
+
}
|
|
20
|
+
interface EngineTool {
|
|
21
|
+
name: string;
|
|
22
|
+
description: string;
|
|
23
|
+
/** JSON Schema object describing the tool's arguments. */
|
|
24
|
+
parameters: Record<string, unknown>;
|
|
25
|
+
/** Human approval required before the tool side effect executes. */
|
|
26
|
+
approval?: ToolApprovalPolicy;
|
|
27
|
+
execute: (args: Record<string, unknown>, signal?: AbortSignal) => Promise<string>;
|
|
28
|
+
}
|
|
29
|
+
interface EngineRunInput {
|
|
30
|
+
model: ModelConfig;
|
|
31
|
+
instructions?: string;
|
|
32
|
+
messages: Message[];
|
|
33
|
+
tools: EngineTool[];
|
|
34
|
+
thinkingLevel?: ThinkingLevel;
|
|
35
|
+
toolChoice?: ToolChoice;
|
|
36
|
+
/** Explicit API key for this model's provider; overrides env resolution. */
|
|
37
|
+
apiKey?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Environment to resolve provider credentials from (e.g. ANTHROPIC_API_KEY,
|
|
40
|
+
* OPENAI_API_KEY). On Node this is typically process.env; on Workers it is
|
|
41
|
+
* the per-request env bindings (values may be non-string bindings — the
|
|
42
|
+
* engine only reads string entries). The engine picks the variable matching
|
|
43
|
+
* the model's provider — never a hardcoded vendor default.
|
|
44
|
+
*/
|
|
45
|
+
env?: Record<string, unknown>;
|
|
46
|
+
/** Per-provider endpoint overrides (gateways, proxies, self-hosted). */
|
|
47
|
+
providers?: Record<string, {
|
|
48
|
+
baseUrl?: string;
|
|
49
|
+
headers?: Record<string, string>;
|
|
50
|
+
apiKey?: string;
|
|
51
|
+
}>;
|
|
52
|
+
signal?: AbortSignal;
|
|
53
|
+
/** Stable id for prompt caching / session affinity. */
|
|
54
|
+
sessionId?: string;
|
|
55
|
+
cacheRetention?: CacheRetention;
|
|
56
|
+
}
|
|
57
|
+
interface EngineRunResult {
|
|
58
|
+
appended: Message[];
|
|
59
|
+
text: string;
|
|
60
|
+
usage: Usage;
|
|
61
|
+
}
|
|
62
|
+
interface EngineHooks {
|
|
63
|
+
bus: EventBus;
|
|
64
|
+
runId?: string;
|
|
65
|
+
session?: string;
|
|
66
|
+
}
|
|
67
|
+
interface AgentEngine {
|
|
68
|
+
run(input: EngineRunInput, hooks: EngineHooks): Promise<EngineRunResult>;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Tools.
|
|
73
|
+
*
|
|
74
|
+
* Design note: authors describe parameters once as a Valibot
|
|
75
|
+
* schema; we infer the JSON Schema the model needs. No hand-written JSON Schema.
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
interface ToolDefinition<TSchema extends GenericSchema = GenericSchema> {
|
|
79
|
+
name: string;
|
|
80
|
+
description: string;
|
|
81
|
+
parameters: TSchema;
|
|
82
|
+
/** Require an explicit human approval before this tool executes. */
|
|
83
|
+
approval?: boolean | ToolApprovalPolicy;
|
|
84
|
+
execute: (args: InferOutput<TSchema>, signal?: AbortSignal) => Promise<string> | string;
|
|
85
|
+
}
|
|
86
|
+
declare function defineTool<TSchema extends GenericSchema>(def: ToolDefinition<TSchema>): ToolDefinition<TSchema>;
|
|
87
|
+
/**
|
|
88
|
+
* A tool whose parameters are already a JSON Schema (e.g. an MCP tool), rather
|
|
89
|
+
* than a Valibot schema. Branded so the runtime can pass it through directly.
|
|
90
|
+
*/
|
|
91
|
+
interface RawTool extends EngineTool {
|
|
92
|
+
readonly __atlasflowRawTool: true;
|
|
93
|
+
}
|
|
94
|
+
declare function rawTool(tool: EngineTool): RawTool;
|
|
95
|
+
declare function isRawTool(tool: unknown): tool is RawTool;
|
|
96
|
+
type AnyTool = ToolDefinition | RawTool;
|
|
97
|
+
/** Lower a public ToolDefinition into the vendor-neutral EngineTool. */
|
|
98
|
+
declare function resolveTool(def: ToolDefinition): EngineTool;
|
|
99
|
+
/** Resolve either a Valibot-schema tool or a raw JSON-schema tool. */
|
|
100
|
+
declare function resolveAnyTool(tool: AnyTool): EngineTool;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Agent authoring API — `createAgent`. Declarative: an agent file
|
|
104
|
+
* default-exports `createAgent(initialize)`, where `initialize` returns the
|
|
105
|
+
* runtime config (optionally async, optionally reading the invocation context).
|
|
106
|
+
*/
|
|
107
|
+
|
|
108
|
+
interface Skill {
|
|
109
|
+
name: string;
|
|
110
|
+
description: string;
|
|
111
|
+
body: string;
|
|
112
|
+
allowedTools?: string[];
|
|
113
|
+
/** Files packaged alongside an imported SKILL.md, keyed by path relative to the skill directory. */
|
|
114
|
+
files?: Record<string, PackagedSkillFile>;
|
|
115
|
+
}
|
|
116
|
+
interface PackagedSkillFile {
|
|
117
|
+
kind: "text" | "binary";
|
|
118
|
+
encoding: "base64";
|
|
119
|
+
content: string;
|
|
120
|
+
}
|
|
121
|
+
interface AgentProfile {
|
|
122
|
+
name: string;
|
|
123
|
+
model?: ModelConfig;
|
|
124
|
+
instructions?: string;
|
|
125
|
+
tools?: ToolDefinition[];
|
|
126
|
+
thinkingLevel?: ThinkingLevel;
|
|
127
|
+
}
|
|
128
|
+
interface AgentRuntimeConfig {
|
|
129
|
+
name?: string;
|
|
130
|
+
description?: string;
|
|
131
|
+
/** Default model; `false` requires a per-call model override. */
|
|
132
|
+
model?: ModelConfig | false;
|
|
133
|
+
instructions?: string;
|
|
134
|
+
tools?: AnyTool[];
|
|
135
|
+
skills?: Skill[];
|
|
136
|
+
/**
|
|
137
|
+
* How authored skills are exposed to the model. "callable" preserves the
|
|
138
|
+
* historical `skill_<name>` subcall tools; "load" exposes a context-economical
|
|
139
|
+
* `load_skill` tool and an index, leaving skill bodies out of the base prompt.
|
|
140
|
+
*/
|
|
141
|
+
skillLoading?: "callable" | "load";
|
|
142
|
+
/**
|
|
143
|
+
* Named personas the agent can delegate to via the built-in `task` tool:
|
|
144
|
+
* each runs in its own fresh session with its own model/instructions.
|
|
145
|
+
* (Atlas Brain terminology; `subagents` remains as a deprecated alias.)
|
|
146
|
+
*/
|
|
147
|
+
personas?: AgentProfile[];
|
|
148
|
+
/** @deprecated Use `personas`. */
|
|
149
|
+
subagents?: AgentProfile[];
|
|
150
|
+
/**
|
|
151
|
+
* Declarative knowledge units (Atlas Brain "context packs"). Packs with
|
|
152
|
+
* mount "context" (default for small packs) join the system context; packs
|
|
153
|
+
* with mount "sandbox" are written into the sandbox under packs/<name>/
|
|
154
|
+
* where the built-in read/grep tools reach them.
|
|
155
|
+
*/
|
|
156
|
+
contextPacks?: ContextPack[];
|
|
157
|
+
/**
|
|
158
|
+
* How context packs are exposed. "eager" preserves the historical behavior:
|
|
159
|
+
* context-mounted pack bodies join the system prompt. "lazy" exposes an index
|
|
160
|
+
* plus `load_context`, keeping bodies out of the base prompt until requested.
|
|
161
|
+
*/
|
|
162
|
+
contextLoading?: "eager" | "lazy";
|
|
163
|
+
/**
|
|
164
|
+
* Binding rules (Atlas Brain normative·binding): declarative interceptors
|
|
165
|
+
* enforced at before_prompt / before_tool / after_tool. `block` stops the
|
|
166
|
+
* action with the rule's message; `warn` logs and proceeds.
|
|
167
|
+
*/
|
|
168
|
+
rules?: Rule[];
|
|
169
|
+
/** Programmatic enforcement hooks (rules compile to these internally). */
|
|
170
|
+
hooks?: AgentHooks;
|
|
171
|
+
thinkingLevel?: ThinkingLevel;
|
|
172
|
+
/** Provider-neutral tool policy. Currently honored by the Workers AI binding path. */
|
|
173
|
+
toolChoice?: ToolChoice;
|
|
174
|
+
/** Execution environment; defaults to an in-memory virtual sandbox. `false` disables filesystem/shell tools. */
|
|
175
|
+
sandbox?: false | SandboxFactory;
|
|
176
|
+
/**
|
|
177
|
+
* Built-in sandbox tools (read, write, edit, bash, grep, glob, task).
|
|
178
|
+
* Enabled automatically when a sandbox is configured; `false` to opt out,
|
|
179
|
+
* or a list of names to enable a subset.
|
|
180
|
+
*/
|
|
181
|
+
builtinTools?: boolean | string[];
|
|
182
|
+
/**
|
|
183
|
+
* Host-implemented commands registered into scoped just-bash operations.
|
|
184
|
+
* Use these for privileged CLIs or SDK-backed commands without exposing
|
|
185
|
+
* secrets to the sandbox environment.
|
|
186
|
+
*/
|
|
187
|
+
commands?: Command[];
|
|
188
|
+
cwd?: string;
|
|
189
|
+
profile?: AgentProfile;
|
|
190
|
+
/** Validate the agent's final reply against this schema; exposed as `result`. */
|
|
191
|
+
result?: GenericSchema;
|
|
192
|
+
/**
|
|
193
|
+
* Per-provider overrides for gateways, proxies, or self-hosted endpoints:
|
|
194
|
+
* keyed by provider name (e.g. "anthropic", "openai").
|
|
195
|
+
*/
|
|
196
|
+
providers?: Record<string, ProviderSettings>;
|
|
197
|
+
/** Durability for workflow runs: retry on failure, wall-clock timeout. */
|
|
198
|
+
durability?: DurabilityConfig;
|
|
199
|
+
/** Automatic context-window management; ON by default, `false` to disable. */
|
|
200
|
+
compaction?: false | CompactionConfig;
|
|
201
|
+
/** Append an autonomy directive (work without asking questions). */
|
|
202
|
+
headless?: boolean;
|
|
203
|
+
/**
|
|
204
|
+
* Release per-invocation resources created during initialization, such as
|
|
205
|
+
* request-scoped MCP connections. The runtime calls this after the run
|
|
206
|
+
* settles, including background runs kept alive with waitUntil.
|
|
207
|
+
*/
|
|
208
|
+
cleanup?: () => void | Promise<void>;
|
|
209
|
+
}
|
|
210
|
+
interface CompactionConfig {
|
|
211
|
+
/** Compact once a session exceeds this many messages (off unless set). */
|
|
212
|
+
threshold?: number;
|
|
213
|
+
/** Compact once estimated history tokens exceed this (default 120000). */
|
|
214
|
+
thresholdTokens?: number;
|
|
215
|
+
/** Messages to keep verbatim after compaction (default 10). */
|
|
216
|
+
keepRecent?: number;
|
|
217
|
+
/** Model used to summarize; defaults to the agent's model. */
|
|
218
|
+
model?: ModelConfig;
|
|
219
|
+
}
|
|
220
|
+
interface ContextPackItem {
|
|
221
|
+
name: string;
|
|
222
|
+
content: string;
|
|
223
|
+
}
|
|
224
|
+
interface ContextPack {
|
|
225
|
+
name: string;
|
|
226
|
+
description?: string;
|
|
227
|
+
version?: string;
|
|
228
|
+
/** "context" injects into the system context; "sandbox" mounts files under packs/<name>/. */
|
|
229
|
+
mount?: "context" | "sandbox";
|
|
230
|
+
items: ContextPackItem[];
|
|
231
|
+
/** Atlas Brain trust axis — carried as metadata, never judged here. */
|
|
232
|
+
provenance?: string;
|
|
233
|
+
}
|
|
234
|
+
type RuleEnforcePoint = "before_prompt" | "before_tool" | "after_tool";
|
|
235
|
+
interface Rule {
|
|
236
|
+
name: string;
|
|
237
|
+
enforce: RuleEnforcePoint;
|
|
238
|
+
/** Restrict tool rules to these tool names (default: all tools). */
|
|
239
|
+
tools?: string[];
|
|
240
|
+
/** Regex tested against the prompt text / JSON-encoded tool args / tool result. */
|
|
241
|
+
pattern?: string;
|
|
242
|
+
/** "block" stops the action with `message`; "warn" emits an event and proceeds. */
|
|
243
|
+
action?: "block" | "warn";
|
|
244
|
+
message: string;
|
|
245
|
+
provenance?: string;
|
|
246
|
+
}
|
|
247
|
+
type HookDecision = {
|
|
248
|
+
allow: true;
|
|
249
|
+
} | {
|
|
250
|
+
allow: false;
|
|
251
|
+
message: string;
|
|
252
|
+
};
|
|
253
|
+
interface AgentHooks {
|
|
254
|
+
beforePrompt?: (text: string) => HookDecision | Promise<HookDecision>;
|
|
255
|
+
beforeTool?: (tool: string, args: Record<string, unknown>) => HookDecision | Promise<HookDecision>;
|
|
256
|
+
afterTool?: (tool: string, result: string) => HookDecision | Promise<HookDecision>;
|
|
257
|
+
}
|
|
258
|
+
interface ProviderSettings {
|
|
259
|
+
/** Override the provider's API base URL. */
|
|
260
|
+
baseUrl?: string;
|
|
261
|
+
/** Extra headers sent with every request to this provider. */
|
|
262
|
+
headers?: Record<string, string>;
|
|
263
|
+
/** API key for this provider (overrides env resolution). */
|
|
264
|
+
apiKey?: string;
|
|
265
|
+
/** Cloudflare account id used to expand {CLOUDFLARE_ACCOUNT_ID} in Workers AI URLs. */
|
|
266
|
+
accountId?: string;
|
|
267
|
+
/** Default API implementation for custom models from this provider. */
|
|
268
|
+
api?: string;
|
|
269
|
+
/** Custom model definitions for providers not present in pi-ai's generated catalog. */
|
|
270
|
+
models?: Record<string, ProviderModelSettings>;
|
|
271
|
+
}
|
|
272
|
+
interface ProviderModelSettings {
|
|
273
|
+
api?: string;
|
|
274
|
+
name?: string;
|
|
275
|
+
baseUrl?: string;
|
|
276
|
+
headers?: Record<string, string>;
|
|
277
|
+
reasoning?: boolean;
|
|
278
|
+
thinkingLevelMap?: Record<string, string | null>;
|
|
279
|
+
input?: ("text" | "image")[];
|
|
280
|
+
cost?: Partial<{
|
|
281
|
+
input: number;
|
|
282
|
+
output: number;
|
|
283
|
+
cacheRead: number;
|
|
284
|
+
cacheWrite: number;
|
|
285
|
+
}>;
|
|
286
|
+
contextWindow?: number;
|
|
287
|
+
maxTokens?: number;
|
|
288
|
+
compat?: unknown;
|
|
289
|
+
}
|
|
290
|
+
interface DurabilityConfig {
|
|
291
|
+
/** Max retry attempts after the first failure (default 0). */
|
|
292
|
+
retry?: number;
|
|
293
|
+
/** Per-attempt wall-clock timeout in milliseconds. */
|
|
294
|
+
timeoutMs?: number;
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* `env` carries strings (Node process.env) AND platform bindings (Cloudflare
|
|
298
|
+
* R2/D1/Vectorize/Durable Object namespaces) — type it per-agent via TEnv.
|
|
299
|
+
*/
|
|
300
|
+
interface AgentCreateContext<TPayload = unknown, TEnv = Record<string, unknown>> {
|
|
301
|
+
id: string;
|
|
302
|
+
env: TEnv;
|
|
303
|
+
payload?: TPayload;
|
|
304
|
+
}
|
|
305
|
+
type AgentInitialize<TPayload, TEnv> = (ctx: AgentCreateContext<TPayload, TEnv>) => AgentRuntimeConfig | Promise<AgentRuntimeConfig>;
|
|
306
|
+
type AgentDefinition<TPayload = unknown, TEnv = Record<string, unknown>> = AgentRuntimeConfig | AgentInitialize<TPayload, TEnv>;
|
|
307
|
+
interface CreatedAgent<TPayload = unknown, TEnv = Record<string, unknown>> {
|
|
308
|
+
readonly __atlasflowAgent: true;
|
|
309
|
+
initialize: AgentInitialize<TPayload, TEnv>;
|
|
310
|
+
}
|
|
311
|
+
declare function createAgent<TPayload = unknown, TEnv = Record<string, unknown>>(initialize: AgentInitialize<TPayload, TEnv>): CreatedAgent<TPayload, TEnv>;
|
|
312
|
+
declare function defineAgent<TPayload = unknown, TEnv = Record<string, unknown>>(definition: AgentDefinition<TPayload, TEnv>): CreatedAgent<TPayload, TEnv>;
|
|
313
|
+
declare function isCreatedAgent(value: unknown): value is CreatedAgent;
|
|
314
|
+
declare function defineAgentProfile(profile: AgentProfile): AgentProfile;
|
|
315
|
+
/** Merge a profile baseline under an explicit config (config wins). */
|
|
316
|
+
declare function applyProfile(config: AgentRuntimeConfig): AgentRuntimeConfig;
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Runtime orchestrator: turn a CreatedAgent + an invocation into a result.
|
|
320
|
+
*
|
|
321
|
+
* The declarative agent config (model, instructions, tools, skills, sandbox) IS
|
|
322
|
+
* the behavior. On invocation we build the harness and drive the default
|
|
323
|
+
* session with the incoming message/payload; the agentic loop (engine) handles
|
|
324
|
+
* multi-step autonomy via tools.
|
|
325
|
+
*/
|
|
326
|
+
|
|
327
|
+
declare const defaultEngine: AgentEngine;
|
|
328
|
+
declare function getDefaultPersistence(): PersistenceAdapter;
|
|
329
|
+
interface InvokeOptions {
|
|
330
|
+
agent: CreatedAgent;
|
|
331
|
+
agentName: string;
|
|
332
|
+
instanceId: string;
|
|
333
|
+
message?: string;
|
|
334
|
+
payload?: unknown;
|
|
335
|
+
images?: PromptImage[];
|
|
336
|
+
env?: Record<string, unknown>;
|
|
337
|
+
engine?: AgentEngine;
|
|
338
|
+
persistence?: PersistenceAdapter;
|
|
339
|
+
onEvent?: (event: AtlasEvent) => void;
|
|
340
|
+
/** Explicit API key for the agent's model provider (overrides env lookup). */
|
|
341
|
+
apiKey?: string;
|
|
342
|
+
/** Use this run id instead of generating one (for dispatch/recovery). */
|
|
343
|
+
runId?: string;
|
|
344
|
+
/** Internal execution lease owner for durable/background runs. */
|
|
345
|
+
runLeaseOwner?: string;
|
|
346
|
+
/** Internal execution lease TTL. Defaults to five minutes. */
|
|
347
|
+
runLeaseTtlMs?: number;
|
|
348
|
+
/** Internal marker for replaying a stale running run during recovery. */
|
|
349
|
+
runResume?: boolean;
|
|
350
|
+
/** Wrap durable/background execution in a platform primitive such as Cloudflare runFiber(). */
|
|
351
|
+
durability?: DurableExecutionRunner;
|
|
352
|
+
/** Abort the invocation (e.g. when an HTTP client disconnects). */
|
|
353
|
+
signal?: AbortSignal;
|
|
354
|
+
/** Prepended to the agent's instructions (e.g. workspace AGENTS.md). */
|
|
355
|
+
baseInstructions?: string;
|
|
356
|
+
/** Personas available to every agent's task tool (e.g. workspace roles/). */
|
|
357
|
+
sharedPersonas?: AgentProfile[];
|
|
358
|
+
/** @deprecated Use `sharedPersonas`. */
|
|
359
|
+
sharedSubagents?: AgentProfile[];
|
|
360
|
+
}
|
|
361
|
+
interface DurableExecutionMeta {
|
|
362
|
+
runId: string;
|
|
363
|
+
agentName: string;
|
|
364
|
+
instanceId: string;
|
|
365
|
+
resume: boolean;
|
|
366
|
+
}
|
|
367
|
+
type DurableExecutionRunner = (meta: DurableExecutionMeta, run: () => Promise<void>) => Promise<void> | void;
|
|
368
|
+
interface InvokeResult {
|
|
369
|
+
runId: string;
|
|
370
|
+
text: string;
|
|
371
|
+
data: unknown;
|
|
372
|
+
usage: Usage;
|
|
373
|
+
}
|
|
374
|
+
declare function genId(prefix: string): string;
|
|
375
|
+
/**
|
|
376
|
+
* Dispatch a durable workflow run: persist a queued submission, then execute it
|
|
377
|
+
* in the background after atomically claiming the queued record. Returns once
|
|
378
|
+
* the record exists, so a poller can immediately `runs.get(runId)`. Failures
|
|
379
|
+
* are recorded on the run record.
|
|
380
|
+
*
|
|
381
|
+
* `done` resolves when the background run finishes (never rejects). On
|
|
382
|
+
* Cloudflare Workers it MUST be passed to `ctx.waitUntil`, or the runtime
|
|
383
|
+
* cancels the work as soon as the HTTP response is sent.
|
|
384
|
+
*/
|
|
385
|
+
declare function dispatchWorkflow(options: InvokeOptions): Promise<{
|
|
386
|
+
runId: string;
|
|
387
|
+
done: Promise<void>;
|
|
388
|
+
}>;
|
|
389
|
+
/**
|
|
390
|
+
* Recover interrupted runs: execute any queued submission, and handle any
|
|
391
|
+
* still-running run according to the recovery policy. Queued submissions are
|
|
392
|
+
* safe to run by default because no attempt has claimed/executed them yet.
|
|
393
|
+
* Already-running runs default to automatic replay only when the persisted
|
|
394
|
+
* journal and event log prove no side-effecting work or output happened.
|
|
395
|
+
*/
|
|
396
|
+
declare function recoverRuns(agents: Record<string, CreatedAgent>, opts?: {
|
|
397
|
+
persistence?: PersistenceAdapter;
|
|
398
|
+
engine?: AgentEngine;
|
|
399
|
+
env?: Record<string, unknown>;
|
|
400
|
+
leaseTtlMs?: number;
|
|
401
|
+
/**
|
|
402
|
+
* Restrict recovery to specific run ids. This is used by platform recovery
|
|
403
|
+
* callbacks that know exactly which durable execution was interrupted.
|
|
404
|
+
*/
|
|
405
|
+
runIds?: string[];
|
|
406
|
+
/**
|
|
407
|
+
* Expire a matching running run's lease before attempting recovery. Use
|
|
408
|
+
* only when an external runtime signal proves the original execution died.
|
|
409
|
+
*/
|
|
410
|
+
forceLeaseExpiration?: boolean;
|
|
411
|
+
/**
|
|
412
|
+
* Safe default ("auto"): replay stale agent runs only when the session
|
|
413
|
+
* journal proves the accepted input can be resumed and the event log has no
|
|
414
|
+
* tool calls, deltas, or other side-effect/output evidence. Use "replay" to
|
|
415
|
+
* force replay for explicitly idempotent agents, or "interrupt" to always
|
|
416
|
+
* terminalize stale running runs.
|
|
417
|
+
*/
|
|
418
|
+
agentRecovery?: "auto" | "interrupt" | "replay";
|
|
419
|
+
/** Wrap recovered durable/background execution in a platform primitive. */
|
|
420
|
+
durability?: DurableExecutionRunner;
|
|
421
|
+
}): Promise<string[]>;
|
|
422
|
+
declare function invokeAgent(options: InvokeOptions): Promise<InvokeResult>;
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Authored workflows — the Atlas Brain procedural·binding primitive: a
|
|
426
|
+
* declarative sequence of steps with human GATES and persona ROLE SLOTS.
|
|
427
|
+
*
|
|
428
|
+
* Execution model: chained runs. The workflow has a parent run record holding
|
|
429
|
+
* the executor state (cursor, step results, gate decisions); every prompt or
|
|
430
|
+
* skill step executes as its own child run. Gates park the parent in
|
|
431
|
+
* "waiting_approval" — durable across restarts, resumable days later via
|
|
432
|
+
* `approveGate` (surfaced as POST /runs/:runId/approve; the Brain owns the
|
|
433
|
+
* approval UX).
|
|
434
|
+
*
|
|
435
|
+
* NOTE: "workflow" here means this authored primitive. The dispatched-run
|
|
436
|
+
* invocation mode formerly called "workflows" is now "runs" (§19/§20).
|
|
437
|
+
*/
|
|
438
|
+
|
|
439
|
+
declare const WorkflowStepSchema: v.VariantSchema<"kind", [v.ObjectSchema<{
|
|
440
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
441
|
+
readonly kind: v.LiteralSchema<"prompt", undefined>;
|
|
442
|
+
/** May reference prior steps: {{steps.<id>.text}}. */
|
|
443
|
+
readonly prompt: v.StringSchema<undefined>;
|
|
444
|
+
/** Role slot or persona name executing this step (default: workflow default persona). */
|
|
445
|
+
readonly persona: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
446
|
+
readonly model: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
447
|
+
}, undefined>, v.ObjectSchema<{
|
|
448
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
449
|
+
readonly kind: v.LiteralSchema<"skill", undefined>;
|
|
450
|
+
/** Name of a skill in the executing persona's loadout. */
|
|
451
|
+
readonly skill: v.StringSchema<undefined>;
|
|
452
|
+
/** Input text; may reference prior steps: {{steps.<id>.text}}. */
|
|
453
|
+
readonly input: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
454
|
+
readonly persona: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
455
|
+
}, undefined>, v.ObjectSchema<{
|
|
456
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
457
|
+
readonly kind: v.LiteralSchema<"gate", undefined>;
|
|
458
|
+
readonly title: v.StringSchema<undefined>;
|
|
459
|
+
readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
460
|
+
}, undefined>], undefined>;
|
|
461
|
+
declare const WorkflowDefSchema: v.ObjectSchema<{
|
|
462
|
+
readonly name: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
463
|
+
readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
464
|
+
readonly steps: v.SchemaWithPipe<readonly [v.ArraySchema<v.VariantSchema<"kind", [v.ObjectSchema<{
|
|
465
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
466
|
+
readonly kind: v.LiteralSchema<"prompt", undefined>;
|
|
467
|
+
/** May reference prior steps: {{steps.<id>.text}}. */
|
|
468
|
+
readonly prompt: v.StringSchema<undefined>;
|
|
469
|
+
/** Role slot or persona name executing this step (default: workflow default persona). */
|
|
470
|
+
readonly persona: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
471
|
+
readonly model: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
472
|
+
}, undefined>, v.ObjectSchema<{
|
|
473
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
474
|
+
readonly kind: v.LiteralSchema<"skill", undefined>;
|
|
475
|
+
/** Name of a skill in the executing persona's loadout. */
|
|
476
|
+
readonly skill: v.StringSchema<undefined>;
|
|
477
|
+
/** Input text; may reference prior steps: {{steps.<id>.text}}. */
|
|
478
|
+
readonly input: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
479
|
+
readonly persona: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
480
|
+
}, undefined>, v.ObjectSchema<{
|
|
481
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
482
|
+
readonly kind: v.LiteralSchema<"gate", undefined>;
|
|
483
|
+
readonly title: v.StringSchema<undefined>;
|
|
484
|
+
readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
485
|
+
}, undefined>], undefined>, undefined>, v.MinLengthAction<({
|
|
486
|
+
id: string;
|
|
487
|
+
kind: "prompt";
|
|
488
|
+
prompt: string;
|
|
489
|
+
persona?: string | undefined;
|
|
490
|
+
model?: string | undefined;
|
|
491
|
+
} | {
|
|
492
|
+
id: string;
|
|
493
|
+
kind: "skill";
|
|
494
|
+
skill: string;
|
|
495
|
+
input?: string | undefined;
|
|
496
|
+
persona?: string | undefined;
|
|
497
|
+
} | {
|
|
498
|
+
id: string;
|
|
499
|
+
kind: "gate";
|
|
500
|
+
title: string;
|
|
501
|
+
description?: string | undefined;
|
|
502
|
+
})[], 1, undefined>]>;
|
|
503
|
+
/** Role slot → default persona name; rebindable at deploy. */
|
|
504
|
+
readonly roleSlots: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.StringSchema<undefined>, undefined>, undefined>;
|
|
505
|
+
}, undefined>;
|
|
506
|
+
type WorkflowStep = v.InferOutput<typeof WorkflowStepSchema>;
|
|
507
|
+
type WorkflowDef = v.InferOutput<typeof WorkflowDefSchema>;
|
|
508
|
+
declare function parseWorkflowDef(value: unknown): WorkflowDef;
|
|
509
|
+
interface WorkflowState {
|
|
510
|
+
cursor: number;
|
|
511
|
+
results: Record<string, {
|
|
512
|
+
text: string;
|
|
513
|
+
runId?: string;
|
|
514
|
+
}>;
|
|
515
|
+
gates: Record<string, {
|
|
516
|
+
approved: boolean;
|
|
517
|
+
note?: string;
|
|
518
|
+
at: number;
|
|
519
|
+
}>;
|
|
520
|
+
}
|
|
521
|
+
interface WorkflowContext {
|
|
522
|
+
/** Personas executing steps: registered agents win, then profiles. */
|
|
523
|
+
agents?: Record<string, Parameters<typeof invokeAgent>[0]["agent"]>;
|
|
524
|
+
profiles?: AgentProfile[];
|
|
525
|
+
/** Default model for steps with no persona/model of their own. */
|
|
526
|
+
defaultModel?: string;
|
|
527
|
+
/**
|
|
528
|
+
* Persona executing steps that name no role slot — a persona's workflows
|
|
529
|
+
* run AS that persona (its identity, packs, rules) unless a step overrides.
|
|
530
|
+
*/
|
|
531
|
+
defaultPersona?: string;
|
|
532
|
+
/** Skills resolvable by skill steps. */
|
|
533
|
+
skills?: {
|
|
534
|
+
name: string;
|
|
535
|
+
description: string;
|
|
536
|
+
body: string;
|
|
537
|
+
}[];
|
|
538
|
+
/** Deploy-time role-slot rebinding (overrides def.roleSlots). */
|
|
539
|
+
bindings?: Record<string, string>;
|
|
540
|
+
persistence?: PersistenceAdapter;
|
|
541
|
+
engine?: AgentEngine;
|
|
542
|
+
env?: Record<string, unknown>;
|
|
543
|
+
baseInstructions?: string;
|
|
544
|
+
onEvent?: InvokeOptions["onEvent"];
|
|
545
|
+
}
|
|
546
|
+
interface WorkflowRunResult {
|
|
547
|
+
runId: string;
|
|
548
|
+
status: "success" | "failed" | "waiting_approval";
|
|
549
|
+
/** Final step's text when status is success. */
|
|
550
|
+
text?: string;
|
|
551
|
+
/** The gate currently waiting, when status is waiting_approval. */
|
|
552
|
+
gate?: {
|
|
553
|
+
id: string;
|
|
554
|
+
title: string;
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
/**
|
|
558
|
+
* Start a workflow run (or resume one from persisted state). Creates the
|
|
559
|
+
* parent run record (`kind: "workflow"`), then executes steps as chained
|
|
560
|
+
* child runs until done or a gate parks it.
|
|
561
|
+
*/
|
|
562
|
+
declare function startWorkflow(def: WorkflowDef, ctx?: WorkflowContext, opts?: {
|
|
563
|
+
runId?: string;
|
|
564
|
+
payload?: unknown;
|
|
565
|
+
}): Promise<WorkflowRunResult>;
|
|
566
|
+
/** Run steps from the persisted cursor until completion or a gate. */
|
|
567
|
+
declare function advanceWorkflow(def: WorkflowDef, ctx: WorkflowContext, runId: string): Promise<WorkflowRunResult>;
|
|
568
|
+
/**
|
|
569
|
+
* Record a human decision on the gate a workflow is parked at, then resume
|
|
570
|
+
* (approve) or terminate (reject). Returns the post-decision result.
|
|
571
|
+
*/
|
|
572
|
+
declare function approveGate(def: WorkflowDef, ctx: WorkflowContext, runId: string, decision: {
|
|
573
|
+
gate: string;
|
|
574
|
+
approved: boolean;
|
|
575
|
+
note?: string;
|
|
576
|
+
}): Promise<WorkflowRunResult>;
|
|
577
|
+
/**
|
|
578
|
+
* Resume interrupted workflow runs after a restart: anything still "running"
|
|
579
|
+
* re-executes from its persisted cursor (the in-flight step re-runs);
|
|
580
|
+
* "waiting_approval" runs stay parked — they are waiting on a human, not us.
|
|
581
|
+
*/
|
|
582
|
+
declare function recoverWorkflows(defs: Record<string, WorkflowDef>, ctx?: WorkflowContext): Promise<string[]>;
|
|
583
|
+
/** Find the gate a parked workflow run is waiting at. */
|
|
584
|
+
declare function waitingGate(def: WorkflowDef, record: RunRecord): {
|
|
585
|
+
id: string;
|
|
586
|
+
title: string;
|
|
587
|
+
} | undefined;
|
|
588
|
+
|
|
589
|
+
type ChannelMode = "background" | "sync";
|
|
590
|
+
interface ChannelContext {
|
|
591
|
+
channel: string;
|
|
592
|
+
request: Request;
|
|
593
|
+
url: URL;
|
|
594
|
+
env: Record<string, string | undefined>;
|
|
595
|
+
json(): Promise<unknown>;
|
|
596
|
+
text(): Promise<string>;
|
|
597
|
+
}
|
|
598
|
+
interface ChannelDispatch {
|
|
599
|
+
/** Stable platform thread identifier; AtlasFlow maps it to the agent session id. */
|
|
600
|
+
continuationToken: string;
|
|
601
|
+
/** Defaults to the only deployed agent when the app has exactly one agent. */
|
|
602
|
+
agent?: string;
|
|
603
|
+
message?: string;
|
|
604
|
+
payload?: unknown;
|
|
605
|
+
images?: PromptImage[];
|
|
606
|
+
runId?: string;
|
|
607
|
+
mode?: ChannelMode;
|
|
608
|
+
}
|
|
609
|
+
interface ChannelAccepted {
|
|
610
|
+
dispatch: ChannelDispatch;
|
|
611
|
+
response?: unknown;
|
|
612
|
+
status?: number;
|
|
613
|
+
}
|
|
614
|
+
type ChannelResult = Response | ChannelDispatch | ChannelAccepted;
|
|
615
|
+
interface ChannelDefinition {
|
|
616
|
+
name?: string;
|
|
617
|
+
/** Defaults to /channels/<name>. Relative paths are mounted under /channels/. */
|
|
618
|
+
path?: string;
|
|
619
|
+
/** Defaults to POST. */
|
|
620
|
+
methods?: string[];
|
|
621
|
+
handle(ctx: ChannelContext): ChannelResult | Promise<ChannelResult>;
|
|
622
|
+
}
|
|
623
|
+
declare function defineChannel(channel: ChannelDefinition): ChannelDefinition;
|
|
624
|
+
declare function isChannelDefinition(value: unknown): value is ChannelDefinition;
|
|
625
|
+
interface SlackRequestSignatureOptions {
|
|
626
|
+
/** Defaults to five minutes, matching Slack's replay-window guidance. */
|
|
627
|
+
toleranceMs?: number;
|
|
628
|
+
/** Primarily for tests; defaults to Date.now(). */
|
|
629
|
+
now?: number;
|
|
630
|
+
}
|
|
631
|
+
declare function verifyGithubWebhookSignature(secret: string, body: string, header: string | null | undefined): Promise<boolean>;
|
|
632
|
+
declare function verifySlackRequestSignature(secret: string, body: string, timestamp: string | null | undefined, signature: string | null | undefined, options?: SlackRequestSignatureOptions): Promise<boolean>;
|
|
633
|
+
|
|
634
|
+
export { genId as $, type AgentEngine as A, type ToolApprovalPolicy as B, type CreatedAgent as C, type DurableExecutionRunner as D, type EngineTool as E, type WorkflowContext as F, WorkflowDefSchema as G, type HookDecision as H, type InvokeResult as I, type WorkflowRunResult as J, type WorkflowState as K, type WorkflowStep as L, advanceWorkflow as M, applyProfile as N, approveGate as O, type ProviderModelSettings as P, createAgent as Q, type Rule as R, type Skill as S, type ToolDefinition as T, defaultEngine as U, defineAgent as V, type WorkflowDef as W, defineAgentProfile as X, defineChannel as Y, defineTool as Z, dispatchWorkflow as _, type AgentProfile as a, getDefaultPersistence as a0, invokeAgent as a1, isChannelDefinition as a2, isCreatedAgent as a3, isRawTool as a4, parseWorkflowDef as a5, rawTool as a6, recoverRuns as a7, recoverWorkflows as a8, resolveAnyTool as a9, resolveTool as aa, startWorkflow as ab, verifyGithubWebhookSignature as ac, verifySlackRequestSignature as ad, waitingGate as ae, type ChannelDefinition as b, type AnyTool as c, type AgentRuntimeConfig as d, type AgentHooks as e, type RawTool as f, type ToolChoice as g, type CompactionConfig as h, type EngineRunInput as i, type EngineHooks as j, type EngineRunResult as k, type AgentCreateContext as l, type AgentDefinition as m, type ChannelAccepted as n, type ChannelContext as o, type ChannelDispatch as p, type ChannelMode as q, type ChannelResult as r, type ContextPack as s, type ContextPackItem as t, type DurabilityConfig as u, type DurableExecutionMeta as v, type InvokeOptions as w, type ProviderSettings as x, type RuleEnforcePoint as y, type SlackRequestSignatureOptions as z };
|