@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,589 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AtlasFlow public domain types.
|
|
3
|
+
*
|
|
4
|
+
* Independent of any underlying model/provider library. The engine adapter
|
|
5
|
+
* (engine-pi.ts) maps between these and pi-ai today; swapping in our own
|
|
6
|
+
* agentic loop later only touches the adapter, not these types.
|
|
7
|
+
*/
|
|
8
|
+
type ThinkingLevel = "off" | "minimal" | "low" | "medium" | "high" | "xhigh";
|
|
9
|
+
/** A model reference: "<provider>/<model-id>", e.g. "anthropic/claude-sonnet-4-6". */
|
|
10
|
+
type ModelConfig = string;
|
|
11
|
+
type CacheRetention = "none" | "short" | "long";
|
|
12
|
+
interface Usage {
|
|
13
|
+
inputTokens: number;
|
|
14
|
+
outputTokens: number;
|
|
15
|
+
cacheReadTokens: number;
|
|
16
|
+
cacheWriteTokens: number;
|
|
17
|
+
totalTokens: number;
|
|
18
|
+
costTotal: number;
|
|
19
|
+
}
|
|
20
|
+
declare function emptyUsage(): Usage;
|
|
21
|
+
declare function addUsage(a: Usage, b: Usage): Usage;
|
|
22
|
+
interface TextPart {
|
|
23
|
+
type: "text";
|
|
24
|
+
text: string;
|
|
25
|
+
}
|
|
26
|
+
interface ThinkingPart {
|
|
27
|
+
type: "thinking";
|
|
28
|
+
thinking: string;
|
|
29
|
+
}
|
|
30
|
+
interface ImagePart {
|
|
31
|
+
type: "image";
|
|
32
|
+
data: string;
|
|
33
|
+
mimeType: string;
|
|
34
|
+
}
|
|
35
|
+
interface ToolCallPart {
|
|
36
|
+
type: "tool_call";
|
|
37
|
+
id: string;
|
|
38
|
+
name: string;
|
|
39
|
+
arguments: Record<string, unknown>;
|
|
40
|
+
}
|
|
41
|
+
type AssistantPart = TextPart | ThinkingPart | ToolCallPart;
|
|
42
|
+
type UserPart = TextPart | ImagePart;
|
|
43
|
+
interface UserMessage {
|
|
44
|
+
role: "user";
|
|
45
|
+
content: UserPart[];
|
|
46
|
+
}
|
|
47
|
+
interface AssistantMessage {
|
|
48
|
+
role: "assistant";
|
|
49
|
+
content: AssistantPart[];
|
|
50
|
+
usage: Usage;
|
|
51
|
+
stopReason: StopReason;
|
|
52
|
+
}
|
|
53
|
+
interface ToolResultMessage {
|
|
54
|
+
role: "tool_result";
|
|
55
|
+
toolCallId: string;
|
|
56
|
+
toolName: string;
|
|
57
|
+
content: (TextPart | ImagePart)[];
|
|
58
|
+
isError?: boolean;
|
|
59
|
+
}
|
|
60
|
+
type Message = UserMessage | AssistantMessage | ToolResultMessage;
|
|
61
|
+
type StopReason = "stop" | "length" | "tool_use" | "error" | "aborted";
|
|
62
|
+
interface PromptImage {
|
|
63
|
+
data: string;
|
|
64
|
+
mimeType: string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* AtlasFlow event stream.
|
|
69
|
+
*
|
|
70
|
+
* Design note: a strict discriminated union where each event
|
|
71
|
+
* type carries exactly the fields it needs — no "optional fields that are
|
|
72
|
+
* actually required". Consumers switch on `type` with full type-narrowing.
|
|
73
|
+
*/
|
|
74
|
+
|
|
75
|
+
interface EventBase {
|
|
76
|
+
index: number;
|
|
77
|
+
timestamp: number;
|
|
78
|
+
runId?: string;
|
|
79
|
+
session?: string;
|
|
80
|
+
}
|
|
81
|
+
type AtlasEvent = (EventBase & {
|
|
82
|
+
type: "run_queued";
|
|
83
|
+
agent: string;
|
|
84
|
+
instanceId: string;
|
|
85
|
+
}) | (EventBase & {
|
|
86
|
+
type: "run_start";
|
|
87
|
+
agent: string;
|
|
88
|
+
instanceId: string;
|
|
89
|
+
}) | (EventBase & {
|
|
90
|
+
type: "run_resume";
|
|
91
|
+
agent: string;
|
|
92
|
+
instanceId: string;
|
|
93
|
+
}) | (EventBase & {
|
|
94
|
+
type: "run_end";
|
|
95
|
+
ok: boolean;
|
|
96
|
+
}) | (EventBase & {
|
|
97
|
+
type: "run_error";
|
|
98
|
+
code: string;
|
|
99
|
+
message: string;
|
|
100
|
+
}) | (EventBase & {
|
|
101
|
+
type: "agent_start";
|
|
102
|
+
agent: string;
|
|
103
|
+
}) | (EventBase & {
|
|
104
|
+
type: "agent_end";
|
|
105
|
+
}) | (EventBase & {
|
|
106
|
+
type: "operation_start";
|
|
107
|
+
operationId: string;
|
|
108
|
+
kind: OperationKind;
|
|
109
|
+
}) | (EventBase & {
|
|
110
|
+
type: "operation_end";
|
|
111
|
+
operationId: string;
|
|
112
|
+
ok: boolean;
|
|
113
|
+
}) | (EventBase & {
|
|
114
|
+
type: "turn_start";
|
|
115
|
+
turnId: string;
|
|
116
|
+
model: string;
|
|
117
|
+
}) | (EventBase & {
|
|
118
|
+
type: "turn_end";
|
|
119
|
+
turnId: string;
|
|
120
|
+
usage: Usage;
|
|
121
|
+
stopReason: string;
|
|
122
|
+
}) | (EventBase & {
|
|
123
|
+
type: "text_delta";
|
|
124
|
+
turnId: string;
|
|
125
|
+
delta: string;
|
|
126
|
+
}) | (EventBase & {
|
|
127
|
+
type: "thinking_delta";
|
|
128
|
+
turnId: string;
|
|
129
|
+
delta: string;
|
|
130
|
+
}) | (EventBase & {
|
|
131
|
+
type: "tool_call";
|
|
132
|
+
tool: string;
|
|
133
|
+
callId: string;
|
|
134
|
+
arguments: Record<string, unknown>;
|
|
135
|
+
}) | (EventBase & {
|
|
136
|
+
type: "tool_approval_requested";
|
|
137
|
+
approval: string;
|
|
138
|
+
tool: string;
|
|
139
|
+
arguments: Record<string, unknown>;
|
|
140
|
+
}) | (EventBase & {
|
|
141
|
+
type: "tool_approval_decided";
|
|
142
|
+
approval: string;
|
|
143
|
+
tool: string;
|
|
144
|
+
approved: boolean;
|
|
145
|
+
}) | (EventBase & {
|
|
146
|
+
type: "tool_result";
|
|
147
|
+
tool: string;
|
|
148
|
+
callId: string;
|
|
149
|
+
ok: boolean;
|
|
150
|
+
}) | (EventBase & {
|
|
151
|
+
type: "task_start";
|
|
152
|
+
taskId: string;
|
|
153
|
+
agent: string;
|
|
154
|
+
}) | (EventBase & {
|
|
155
|
+
type: "task_end";
|
|
156
|
+
taskId: string;
|
|
157
|
+
ok: boolean;
|
|
158
|
+
}) | (EventBase & {
|
|
159
|
+
type: "compaction";
|
|
160
|
+
freedTokens: number;
|
|
161
|
+
}) | (EventBase & {
|
|
162
|
+
type: "rule_triggered";
|
|
163
|
+
rule: string;
|
|
164
|
+
point: string;
|
|
165
|
+
action: "block" | "warn";
|
|
166
|
+
}) | (EventBase & {
|
|
167
|
+
type: "message";
|
|
168
|
+
text: string;
|
|
169
|
+
}) | (EventBase & {
|
|
170
|
+
type: "log";
|
|
171
|
+
level: "debug" | "info" | "warn" | "error";
|
|
172
|
+
message: string;
|
|
173
|
+
});
|
|
174
|
+
type OperationKind = "prompt" | "skill" | "task" | "shell" | "compact";
|
|
175
|
+
type EventSubscriber = (event: AtlasEvent) => void;
|
|
176
|
+
/** Distributive Omit so union members keep their own discriminant fields. */
|
|
177
|
+
type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never;
|
|
178
|
+
/** An event as emitted (index/timestamp injected by the bus). */
|
|
179
|
+
type EmittedEvent = DistributiveOmit<AtlasEvent, "index" | "timestamp"> & Partial<EventBase>;
|
|
180
|
+
declare class EventBus {
|
|
181
|
+
#private;
|
|
182
|
+
/**
|
|
183
|
+
* `startIndex` seeds event numbering. Recovery re-invokes a run with the same
|
|
184
|
+
* runId; seeding with the persisted event count keeps the per-run event log
|
|
185
|
+
* append-only instead of colliding with (or overwriting) attempt one.
|
|
186
|
+
*/
|
|
187
|
+
constructor(startIndex?: number);
|
|
188
|
+
subscribe(fn: EventSubscriber): () => void;
|
|
189
|
+
emit(event: EmittedEvent): void;
|
|
190
|
+
}
|
|
191
|
+
declare function observe(fn: EventSubscriber): () => void;
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Persistence interfaces + the zero-config in-memory adapter.
|
|
195
|
+
*
|
|
196
|
+
* Design note: a real in-memory adapter is the default, so
|
|
197
|
+
* `atlasflow dev` and tests need no database. Durable adapters (sqlite,
|
|
198
|
+
* postgres, Cloudflare DO) implement the same PersistenceAdapter.
|
|
199
|
+
*/
|
|
200
|
+
|
|
201
|
+
interface SessionData {
|
|
202
|
+
name: string;
|
|
203
|
+
messages: Message[];
|
|
204
|
+
metadata: Record<string, unknown>;
|
|
205
|
+
createdAt: number;
|
|
206
|
+
updatedAt: number;
|
|
207
|
+
}
|
|
208
|
+
interface SessionStore {
|
|
209
|
+
get(key: string): Promise<SessionData | null>;
|
|
210
|
+
put(key: string, data: SessionData): Promise<void>;
|
|
211
|
+
delete(key: string): Promise<void>;
|
|
212
|
+
}
|
|
213
|
+
type RunStatus = "queued" | "running" | "waiting_approval" | "success" | "failed" | "interrupted";
|
|
214
|
+
interface RunRecord {
|
|
215
|
+
runId: string;
|
|
216
|
+
agent: string;
|
|
217
|
+
instanceId: string;
|
|
218
|
+
status: RunStatus;
|
|
219
|
+
result?: unknown;
|
|
220
|
+
error?: {
|
|
221
|
+
code: string;
|
|
222
|
+
message: string;
|
|
223
|
+
};
|
|
224
|
+
startedAt: number;
|
|
225
|
+
endedAt?: number;
|
|
226
|
+
/** Stored input so an interrupted run can be replayed on recovery. */
|
|
227
|
+
message?: string;
|
|
228
|
+
payload?: unknown;
|
|
229
|
+
images?: PromptImage[];
|
|
230
|
+
/** "agent" (default) or "workflow" (an authored, gated process). */
|
|
231
|
+
kind?: "agent" | "workflow";
|
|
232
|
+
/** Executor state for workflow runs: cursor, step results, gate decisions. */
|
|
233
|
+
state?: unknown;
|
|
234
|
+
/** Current execution owner. Recovery must not re-dispatch while this lease is live. */
|
|
235
|
+
leaseOwner?: string;
|
|
236
|
+
leaseExpiresAt?: number;
|
|
237
|
+
leaseAcquiredAt?: number;
|
|
238
|
+
}
|
|
239
|
+
interface RunStore {
|
|
240
|
+
create(record: RunRecord): Promise<void>;
|
|
241
|
+
update(runId: string, patch: Partial<RunRecord>): Promise<void>;
|
|
242
|
+
get(runId: string): Promise<RunRecord | null>;
|
|
243
|
+
list(filter?: {
|
|
244
|
+
status?: RunStatus;
|
|
245
|
+
agent?: string;
|
|
246
|
+
limit?: number;
|
|
247
|
+
}): Promise<RunRecord[]>;
|
|
248
|
+
/**
|
|
249
|
+
* Claim a queued run for execution. This is the durable submission boundary:
|
|
250
|
+
* admission writes `queued`, workers atomically transition to `running`.
|
|
251
|
+
*/
|
|
252
|
+
claimQueued(runId: string, owner: string, now: number, ttlMs: number): Promise<boolean>;
|
|
253
|
+
/**
|
|
254
|
+
* Claim a running run for execution/recovery. Returns false when another
|
|
255
|
+
* live owner still holds the lease or the run is no longer running.
|
|
256
|
+
*/
|
|
257
|
+
claimLease(runId: string, owner: string, now: number, ttlMs: number): Promise<boolean>;
|
|
258
|
+
/** Extend a live lease. Returns false when the caller no longer owns it. */
|
|
259
|
+
heartbeatLease(runId: string, owner: string, now: number, ttlMs: number): Promise<boolean>;
|
|
260
|
+
/** Clear the lease if it is still owned by the caller. */
|
|
261
|
+
releaseLease(runId: string, owner: string): Promise<void>;
|
|
262
|
+
appendEvent(runId: string, event: AtlasEvent): Promise<void>;
|
|
263
|
+
events(runId: string): Promise<AtlasEvent[]>;
|
|
264
|
+
/** Number of persisted events for a run (used to seed indices on recovery). */
|
|
265
|
+
eventCount?(runId: string): Promise<number>;
|
|
266
|
+
}
|
|
267
|
+
interface PersistenceAdapter {
|
|
268
|
+
sessions: SessionStore;
|
|
269
|
+
runs: RunStore;
|
|
270
|
+
streams: StreamStore;
|
|
271
|
+
subscriptions?: SubscriptionStore;
|
|
272
|
+
}
|
|
273
|
+
interface PersistenceAdapterOptions {
|
|
274
|
+
webhooks?: WebhookDeliveryOptions;
|
|
275
|
+
}
|
|
276
|
+
interface DurableStreamRecord {
|
|
277
|
+
path: string;
|
|
278
|
+
contentType: string;
|
|
279
|
+
closed: boolean;
|
|
280
|
+
currentOffset: string;
|
|
281
|
+
lastSeq?: string;
|
|
282
|
+
createdAt: number;
|
|
283
|
+
updatedAt: number;
|
|
284
|
+
ttlSeconds?: number;
|
|
285
|
+
expiresAt?: string;
|
|
286
|
+
producers?: Record<string, DurableStreamProducerState>;
|
|
287
|
+
closedBy?: DurableStreamProducerTuple;
|
|
288
|
+
}
|
|
289
|
+
interface DurableStreamMessage {
|
|
290
|
+
index: number;
|
|
291
|
+
offset: string;
|
|
292
|
+
dataBase64: string;
|
|
293
|
+
createdAt: number;
|
|
294
|
+
}
|
|
295
|
+
interface DurableStreamProducerState {
|
|
296
|
+
epoch: number;
|
|
297
|
+
lastSeq: number;
|
|
298
|
+
lastUpdated: number;
|
|
299
|
+
}
|
|
300
|
+
interface DurableStreamProducerTuple {
|
|
301
|
+
producerId: string;
|
|
302
|
+
epoch: number;
|
|
303
|
+
seq: number;
|
|
304
|
+
}
|
|
305
|
+
type StreamProducerResult = {
|
|
306
|
+
status: "accepted";
|
|
307
|
+
isNew: boolean;
|
|
308
|
+
producerId: string;
|
|
309
|
+
proposedState: DurableStreamProducerState;
|
|
310
|
+
} | {
|
|
311
|
+
status: "duplicate";
|
|
312
|
+
lastSeq: number;
|
|
313
|
+
} | {
|
|
314
|
+
status: "stale_epoch";
|
|
315
|
+
currentEpoch: number;
|
|
316
|
+
} | {
|
|
317
|
+
status: "invalid_epoch_seq";
|
|
318
|
+
} | {
|
|
319
|
+
status: "sequence_gap";
|
|
320
|
+
expectedSeq: number;
|
|
321
|
+
receivedSeq: number;
|
|
322
|
+
} | {
|
|
323
|
+
status: "stream_closed";
|
|
324
|
+
};
|
|
325
|
+
interface StreamStore {
|
|
326
|
+
create(path: string, opts?: StreamCreateOptions): Promise<{
|
|
327
|
+
record: DurableStreamRecord;
|
|
328
|
+
created: boolean;
|
|
329
|
+
}>;
|
|
330
|
+
get(path: string): Promise<DurableStreamRecord | null>;
|
|
331
|
+
delete(path: string): Promise<boolean>;
|
|
332
|
+
append(path: string, data: Uint8Array, opts: StreamAppendOptions): Promise<{
|
|
333
|
+
record: DurableStreamRecord;
|
|
334
|
+
message: DurableStreamMessage;
|
|
335
|
+
} | null>;
|
|
336
|
+
appendWithProducer(path: string, data: Uint8Array, opts: StreamAppendOptions & {
|
|
337
|
+
producer: DurableStreamProducerTuple;
|
|
338
|
+
}): Promise<StreamProducerAppendResult | null>;
|
|
339
|
+
close(path: string): Promise<DurableStreamRecord | null>;
|
|
340
|
+
closeWithProducer(path: string, producer: DurableStreamProducerTuple): Promise<StreamProducerCloseResult | null>;
|
|
341
|
+
messages(path: string): Promise<DurableStreamMessage[]>;
|
|
342
|
+
list?(): Promise<string[]>;
|
|
343
|
+
}
|
|
344
|
+
interface StreamProducerAppendResult {
|
|
345
|
+
record: DurableStreamRecord;
|
|
346
|
+
message: DurableStreamMessage | null;
|
|
347
|
+
producerResult?: StreamProducerResult;
|
|
348
|
+
streamClosed?: boolean;
|
|
349
|
+
}
|
|
350
|
+
interface StreamProducerCloseResult {
|
|
351
|
+
record: DurableStreamRecord;
|
|
352
|
+
producerResult?: StreamProducerResult;
|
|
353
|
+
alreadyClosed: boolean;
|
|
354
|
+
}
|
|
355
|
+
interface StreamCreateOptions {
|
|
356
|
+
contentType?: string;
|
|
357
|
+
ttlSeconds?: number;
|
|
358
|
+
expiresAt?: string;
|
|
359
|
+
initialData?: Uint8Array;
|
|
360
|
+
closed?: boolean;
|
|
361
|
+
fork?: {
|
|
362
|
+
path: string;
|
|
363
|
+
offset?: string;
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
interface StreamAppendOptions {
|
|
367
|
+
contentType: string;
|
|
368
|
+
close?: boolean;
|
|
369
|
+
seq?: string;
|
|
370
|
+
}
|
|
371
|
+
type DurableStreamSubscriptionType = "pull-wake" | "webhook";
|
|
372
|
+
type DurableStreamSubscriptionStatus = "active";
|
|
373
|
+
type DurableStreamSubscriptionLinkType = "explicit" | "glob";
|
|
374
|
+
type DurableStreamSubscriptionErrorCode = "INVALID_REQUEST" | "SUBSCRIPTION_NOT_FOUND" | "SUBSCRIPTION_ALREADY_EXISTS" | "TOKEN_INVALID" | "FENCED" | "ALREADY_CLAIMED" | "NO_PENDING_WORK" | "INVALID_OFFSET";
|
|
375
|
+
interface DurableStreamSubscriptionLink {
|
|
376
|
+
path: string;
|
|
377
|
+
linkTypes: DurableStreamSubscriptionLinkType[];
|
|
378
|
+
ackedOffset: string;
|
|
379
|
+
}
|
|
380
|
+
interface DurableStreamSubscriptionRecord {
|
|
381
|
+
id: string;
|
|
382
|
+
type: DurableStreamSubscriptionType;
|
|
383
|
+
pattern?: string;
|
|
384
|
+
streams: DurableStreamSubscriptionLink[];
|
|
385
|
+
wakeStream?: string;
|
|
386
|
+
leaseTtlMs?: number;
|
|
387
|
+
webhookUrl?: string;
|
|
388
|
+
webhookHeaders?: Record<string, string>;
|
|
389
|
+
webhookLastSuccessAt?: string;
|
|
390
|
+
webhookLastError?: string;
|
|
391
|
+
description?: string;
|
|
392
|
+
createdAt: string;
|
|
393
|
+
status: DurableStreamSubscriptionStatus;
|
|
394
|
+
configHash: string;
|
|
395
|
+
generation: number;
|
|
396
|
+
wakeId?: string;
|
|
397
|
+
wakeSnapshot?: Record<string, string>;
|
|
398
|
+
token?: string;
|
|
399
|
+
holder?: string;
|
|
400
|
+
leaseExpiresAt?: number;
|
|
401
|
+
}
|
|
402
|
+
interface DurableStreamSubscriptionCreateInput {
|
|
403
|
+
type: DurableStreamSubscriptionType;
|
|
404
|
+
pattern?: string;
|
|
405
|
+
streams: string[];
|
|
406
|
+
wakeStream?: string;
|
|
407
|
+
leaseTtlMs?: number;
|
|
408
|
+
webhookUrl?: string;
|
|
409
|
+
webhookHeaders?: Record<string, string>;
|
|
410
|
+
description?: string;
|
|
411
|
+
}
|
|
412
|
+
interface DurableStreamSubscriptionAckInput {
|
|
413
|
+
wakeId?: string;
|
|
414
|
+
generation?: number;
|
|
415
|
+
acks?: Array<{
|
|
416
|
+
stream?: string;
|
|
417
|
+
path?: string;
|
|
418
|
+
offset: string;
|
|
419
|
+
}>;
|
|
420
|
+
done?: boolean;
|
|
421
|
+
}
|
|
422
|
+
interface DurableStreamSubscriptionStreamInfo {
|
|
423
|
+
path: string;
|
|
424
|
+
linkType: DurableStreamSubscriptionLinkType;
|
|
425
|
+
ackedOffset: string;
|
|
426
|
+
tailOffset: string;
|
|
427
|
+
hasPending: boolean;
|
|
428
|
+
}
|
|
429
|
+
interface DurableStreamSubscriptionError {
|
|
430
|
+
code: DurableStreamSubscriptionErrorCode;
|
|
431
|
+
message: string;
|
|
432
|
+
currentHolder?: string;
|
|
433
|
+
generation?: number;
|
|
434
|
+
}
|
|
435
|
+
interface DurableStreamSubscriptionClaim {
|
|
436
|
+
wakeId: string;
|
|
437
|
+
generation: number;
|
|
438
|
+
token: string;
|
|
439
|
+
streams: DurableStreamSubscriptionStreamInfo[];
|
|
440
|
+
leaseTtlMs: number;
|
|
441
|
+
}
|
|
442
|
+
interface DurableStreamSubscriptionAckResult {
|
|
443
|
+
ok: true;
|
|
444
|
+
nextWake: boolean;
|
|
445
|
+
}
|
|
446
|
+
type DurableStreamSubscriptionResult<T> = {
|
|
447
|
+
ok: true;
|
|
448
|
+
value: T;
|
|
449
|
+
} | {
|
|
450
|
+
ok: false;
|
|
451
|
+
status: number;
|
|
452
|
+
error: DurableStreamSubscriptionError;
|
|
453
|
+
};
|
|
454
|
+
interface SubscriptionStore {
|
|
455
|
+
createOrConfirm(id: string, input: DurableStreamSubscriptionCreateInput): Promise<DurableStreamSubscriptionResult<{
|
|
456
|
+
subscription: DurableStreamSubscriptionRecord;
|
|
457
|
+
created: boolean;
|
|
458
|
+
}>>;
|
|
459
|
+
get(id: string): Promise<DurableStreamSubscriptionRecord | null>;
|
|
460
|
+
delete(id: string): Promise<boolean>;
|
|
461
|
+
addExplicitStreams(id: string, streams: string[]): Promise<boolean>;
|
|
462
|
+
removeExplicitStream(id: string, streamPath: string): Promise<boolean>;
|
|
463
|
+
notifyStreamAppend(streamPath: string, message?: DurableStreamMessage): Promise<void>;
|
|
464
|
+
notifyStreamDelete(streamPath: string): Promise<void>;
|
|
465
|
+
claim(id: string, worker: string): Promise<DurableStreamSubscriptionResult<DurableStreamSubscriptionClaim>>;
|
|
466
|
+
ack(id: string, token: string, input: DurableStreamSubscriptionAckInput): Promise<DurableStreamSubscriptionResult<DurableStreamSubscriptionAckResult>>;
|
|
467
|
+
release(id: string, token: string, input: DurableStreamSubscriptionAckInput): Promise<DurableStreamSubscriptionResult<void>>;
|
|
468
|
+
streamInfos(subscription: DurableStreamSubscriptionRecord): Promise<DurableStreamSubscriptionStreamInfo[]>;
|
|
469
|
+
}
|
|
470
|
+
interface WebhookDeliveryOptions {
|
|
471
|
+
/** Test/dev escape hatch. Production defaults block localhost, private IPs, and plain HTTP. */
|
|
472
|
+
allowUnsafeWebhookUrls?: boolean;
|
|
473
|
+
/** Test/dev escape hatch. Production defaults reject authorization/cookie-style callback headers. */
|
|
474
|
+
allowSensitiveWebhookHeaders?: boolean;
|
|
475
|
+
/** Optional production allowlist. Entries are exact hosts or wildcard suffixes such as "*.example.com". */
|
|
476
|
+
allowedWebhookHosts?: string[];
|
|
477
|
+
/** Override DNS resolution for tests or custom runtimes. Defaults to DNS-over-HTTPS. */
|
|
478
|
+
resolveWebhookHost?: WebhookHostResolver | false;
|
|
479
|
+
dnsTimeoutMs?: number;
|
|
480
|
+
}
|
|
481
|
+
type WebhookHostResolver = (hostname: string) => Promise<string[]>;
|
|
482
|
+
declare class InMemorySessionStore implements SessionStore {
|
|
483
|
+
#private;
|
|
484
|
+
get(key: string): Promise<SessionData | null>;
|
|
485
|
+
put(key: string, data: SessionData): Promise<void>;
|
|
486
|
+
delete(key: string): Promise<void>;
|
|
487
|
+
}
|
|
488
|
+
declare class InMemoryRunStore implements RunStore {
|
|
489
|
+
#private;
|
|
490
|
+
create(record: RunRecord): Promise<void>;
|
|
491
|
+
update(runId: string, patch: Partial<RunRecord>): Promise<void>;
|
|
492
|
+
get(runId: string): Promise<RunRecord | null>;
|
|
493
|
+
list(filter?: {
|
|
494
|
+
status?: RunStatus;
|
|
495
|
+
agent?: string;
|
|
496
|
+
limit?: number;
|
|
497
|
+
}): Promise<RunRecord[]>;
|
|
498
|
+
claimLease(runId: string, owner: string, now: number, ttlMs: number): Promise<boolean>;
|
|
499
|
+
claimQueued(runId: string, owner: string, now: number, ttlMs: number): Promise<boolean>;
|
|
500
|
+
heartbeatLease(runId: string, owner: string, now: number, ttlMs: number): Promise<boolean>;
|
|
501
|
+
releaseLease(runId: string, owner: string): Promise<void>;
|
|
502
|
+
appendEvent(runId: string, event: AtlasEvent): Promise<void>;
|
|
503
|
+
events(runId: string): Promise<AtlasEvent[]>;
|
|
504
|
+
eventCount(runId: string): Promise<number>;
|
|
505
|
+
}
|
|
506
|
+
declare class InMemoryStreamStore implements StreamStore {
|
|
507
|
+
#private;
|
|
508
|
+
create(path: string, opts?: StreamCreateOptions): Promise<{
|
|
509
|
+
record: DurableStreamRecord;
|
|
510
|
+
created: boolean;
|
|
511
|
+
}>;
|
|
512
|
+
get(path: string): Promise<DurableStreamRecord | null>;
|
|
513
|
+
delete(path: string): Promise<boolean>;
|
|
514
|
+
append(path: string, data: Uint8Array, opts: StreamAppendOptions): Promise<{
|
|
515
|
+
record: DurableStreamRecord;
|
|
516
|
+
message: DurableStreamMessage;
|
|
517
|
+
} | null>;
|
|
518
|
+
appendWithProducer(path: string, data: Uint8Array, opts: StreamAppendOptions & {
|
|
519
|
+
producer: DurableStreamProducerTuple;
|
|
520
|
+
}): Promise<StreamProducerAppendResult | null>;
|
|
521
|
+
close(path: string): Promise<DurableStreamRecord | null>;
|
|
522
|
+
closeWithProducer(path: string, producer: DurableStreamProducerTuple): Promise<StreamProducerCloseResult | null>;
|
|
523
|
+
messages(path: string): Promise<DurableStreamMessage[]>;
|
|
524
|
+
list(): Promise<string[]>;
|
|
525
|
+
}
|
|
526
|
+
declare abstract class DurableStreamSubscriptionStoreBase implements SubscriptionStore {
|
|
527
|
+
private readonly streams;
|
|
528
|
+
private readonly deliveryFetch;
|
|
529
|
+
private readonly webhookOptions;
|
|
530
|
+
constructor(streams: StreamStore, deliveryFetch?: typeof fetch, webhookOptions?: WebhookDeliveryOptions);
|
|
531
|
+
protected abstract load(id: string): Promise<DurableStreamSubscriptionRecord | null>;
|
|
532
|
+
protected abstract save(record: DurableStreamSubscriptionRecord): Promise<void>;
|
|
533
|
+
protected abstract remove(id: string): Promise<boolean>;
|
|
534
|
+
protected abstract listRecords(): Promise<DurableStreamSubscriptionRecord[]>;
|
|
535
|
+
createOrConfirm(id: string, input: DurableStreamSubscriptionCreateInput): Promise<DurableStreamSubscriptionResult<{
|
|
536
|
+
subscription: DurableStreamSubscriptionRecord;
|
|
537
|
+
created: boolean;
|
|
538
|
+
}>>;
|
|
539
|
+
get(id: string): Promise<DurableStreamSubscriptionRecord | null>;
|
|
540
|
+
delete(id: string): Promise<boolean>;
|
|
541
|
+
addExplicitStreams(id: string, streams: string[]): Promise<boolean>;
|
|
542
|
+
removeExplicitStream(id: string, streamPath: string): Promise<boolean>;
|
|
543
|
+
notifyStreamAppend(streamPath: string, message?: DurableStreamMessage): Promise<void>;
|
|
544
|
+
notifyStreamDelete(streamPath: string): Promise<void>;
|
|
545
|
+
claim(id: string, worker: string): Promise<DurableStreamSubscriptionResult<DurableStreamSubscriptionClaim>>;
|
|
546
|
+
ack(id: string, token: string, input: DurableStreamSubscriptionAckInput): Promise<DurableStreamSubscriptionResult<DurableStreamSubscriptionAckResult>>;
|
|
547
|
+
release(id: string, token: string, input: DurableStreamSubscriptionAckInput): Promise<DurableStreamSubscriptionResult<void>>;
|
|
548
|
+
streamInfos(subscription: DurableStreamSubscriptionRecord): Promise<DurableStreamSubscriptionStreamInfo[]>;
|
|
549
|
+
private linkStream;
|
|
550
|
+
private createWakeIfPending;
|
|
551
|
+
private createWake;
|
|
552
|
+
private writeWakeEvent;
|
|
553
|
+
private hasPendingWork;
|
|
554
|
+
private firstPendingStream;
|
|
555
|
+
private validateWakeToken;
|
|
556
|
+
private applyAcks;
|
|
557
|
+
private clearLease;
|
|
558
|
+
private clearExpiredLease;
|
|
559
|
+
private listStreamPaths;
|
|
560
|
+
private tailOffset;
|
|
561
|
+
private deliverWebhookPending;
|
|
562
|
+
private deliverWebhookAppend;
|
|
563
|
+
private deliverWebhookDelete;
|
|
564
|
+
private postWebhook;
|
|
565
|
+
}
|
|
566
|
+
declare class InMemorySubscriptionStore extends DurableStreamSubscriptionStoreBase {
|
|
567
|
+
#private;
|
|
568
|
+
constructor(streams: StreamStore, deliveryFetch?: typeof fetch, webhookOptions?: WebhookDeliveryOptions);
|
|
569
|
+
protected load(id: string): Promise<DurableStreamSubscriptionRecord | null>;
|
|
570
|
+
protected save(record: DurableStreamSubscriptionRecord): Promise<void>;
|
|
571
|
+
protected remove(id: string): Promise<boolean>;
|
|
572
|
+
protected listRecords(): Promise<DurableStreamSubscriptionRecord[]>;
|
|
573
|
+
}
|
|
574
|
+
declare function inMemoryAdapter(options?: PersistenceAdapterOptions): PersistenceAdapter;
|
|
575
|
+
/** Minimal key/value contract — Cloudflare DurableObjectStorage satisfies this. */
|
|
576
|
+
interface KvLike {
|
|
577
|
+
get<T = unknown>(key: string): Promise<T | undefined>;
|
|
578
|
+
put(key: string, value: unknown): Promise<void>;
|
|
579
|
+
delete(key: string): Promise<unknown>;
|
|
580
|
+
list<T = unknown>(options: {
|
|
581
|
+
prefix: string;
|
|
582
|
+
}): Promise<Map<string, T>>;
|
|
583
|
+
}
|
|
584
|
+
declare function kvAdapter(kv: KvLike, options?: PersistenceAdapterOptions): PersistenceAdapter;
|
|
585
|
+
declare function normalizeStreamContentType(value: string | undefined): string;
|
|
586
|
+
declare function isJsonStreamContentType(contentType: string): boolean;
|
|
587
|
+
declare function streamMessageBytes(message: DurableStreamMessage): Uint8Array;
|
|
588
|
+
|
|
589
|
+
export { emptyUsage as $, type AtlasEvent as A, InMemorySessionStore as B, type CacheRetention as C, type DurableStreamRecord as D, EventBus as E, InMemoryStreamStore as F, InMemorySubscriptionStore as G, type PersistenceAdapterOptions as H, InMemoryRunStore as I, type RunStore as J, type KvLike as K, type StopReason as L, type ModelConfig as M, type StreamProducerResult as N, type OperationKind as O, type PersistenceAdapter as P, type StreamStore as Q, type RunRecord as R, type SessionData as S, type ThinkingLevel as T, type Usage as U, type SubscriptionStore as V, type ToolResultMessage as W, type UserMessage as X, type WebhookDeliveryOptions as Y, type WebhookHostResolver as Z, addUsage as _, type RunStatus as a, inMemoryAdapter as a0, isJsonStreamContentType as a1, kvAdapter as a2, normalizeStreamContentType as a3, observe as a4, streamMessageBytes as a5, type StreamCreateOptions as b, type StreamAppendOptions as c, type DurableStreamMessage as d, type DurableStreamProducerTuple as e, type StreamProducerAppendResult as f, type StreamProducerCloseResult as g, type DurableStreamSubscriptionCreateInput as h, type DurableStreamSubscriptionResult as i, type DurableStreamSubscriptionRecord as j, type DurableStreamSubscriptionClaim as k, type DurableStreamSubscriptionAckInput as l, type DurableStreamSubscriptionStreamInfo as m, type Message as n, type PromptImage as o, type SessionStore as p, type AssistantMessage as q, type DurableStreamProducerState as r, type DurableStreamSubscriptionError as s, type DurableStreamSubscriptionErrorCode as t, type DurableStreamSubscriptionLink as u, type DurableStreamSubscriptionLinkType as v, type DurableStreamSubscriptionStatus as w, DurableStreamSubscriptionStoreBase as x, type DurableStreamSubscriptionType as y, type EventSubscriber as z };
|