@byok-sdk/cloud-do 0.0.0-stage → 0.25.0-rc.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ancienttwo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,134 @@
1
- # Temporary Holding Version
1
+ # @byok-sdk/cloud-do
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ This package hosts a pi-durable session in a Cloudflare Durable Object.
4
+ It provides native SQLite storage, inline tools, wake and inbox processing,
5
+ usage limits, settlement hooks, and transcript reads.
6
+
7
+ The current source candidate is the prerelease 0.25.0-rc.1, in the nine-package
8
+ release set with keys 0.10.0-rc.1, under the npm dist-tag `rc`. `latest` stays
9
+ 0.24.0. npm publication of the candidate is pending; source preparation does not
10
+ establish registry or live-Host acceptance. See the
11
+ [release notes](../../docs/releases/v0.25.0.md#version-set-and-channel).
12
+ The package needs Node 24.15.0 or later for build tooling.
13
+
14
+ ## Install and subclass
15
+
16
+ The following install example names the current source version, which is pending
17
+ publication. Install an exact approved version only after registry readback, or
18
+ use verified accepted CI tarballs for pre-publication integration. Do not use a
19
+ workspace source import as installed-package acceptance evidence.
20
+
21
+ ~~~sh
22
+ npm install @byok-sdk/cloud-do@0.25.0-rc.1
23
+ npm install --save-dev @cloudflare/workers-types
24
+ ~~~
25
+
26
+ The package is ESM. Its root entry imports cloudflare:workers.
27
+ Run it in workerd. It cannot load in a Node process.
28
+
29
+ ~~~ts
30
+ import { AgentDO, getAgentObject, getSessionObject } from '@byok-sdk/cloud-do';
31
+
32
+ export class ProductAgentDO extends AgentDO {
33
+ protected instructions(): string {
34
+ return 'Use the configured platform tools.';
35
+ }
36
+ }
37
+
38
+ export default {
39
+ fetch(): Response {
40
+ return new Response('Not found', { status: 404 });
41
+ },
42
+ };
43
+ ~~~
44
+
45
+ Configure the subclass binding and SQLite migration in wrangler.jsonc:
46
+
47
+ ~~~json
48
+ {
49
+ "name": "product-agent",
50
+ "main": "src/index.ts",
51
+ "compatibility_date": "2026-08-18",
52
+ "compatibility_flags": ["no_nodejs_compat", "no_nodejs_compat_v2"],
53
+ "durable_objects": {
54
+ "bindings": [{ "name": "AGENTS", "class_name": "ProductAgentDO" }]
55
+ },
56
+ "migrations": [
57
+ { "tag": "v1", "new_sqlite_classes": ["ProductAgentDO"] }
58
+ ]
59
+ }
60
+ ~~~
61
+
62
+ Consumers need @cloudflare/workers-types to resolve the ambient Workers
63
+ module and the Durable Object types. Use ES2022 and Bundler module resolution.
64
+ The installed-package smoke uses skipLibCheck: true, as the SDK does.
65
+ Node compatibility is off in the tested configuration. A consumer with other
66
+ flags must verify its complete Worker graph.
67
+
68
+ ## Identity and caller access
69
+
70
+ The platform must authorize the tenant, workspace, agent, and session before
71
+ it calls getSessionObject(). It must authorize the three agent identity
72
+ fields before it calls getAgentObject().
73
+
74
+ Names route storage. They do not authorize callers. The helper names use
75
+ SHA-256 over JSON identity tuples. One session owns one named Durable Object.
76
+ Public HTTP routing and caller access checks belong to the consumer.
77
+ The default Worker returns HTTP 404.
78
+
79
+ ## Platform keys and execution
80
+
81
+ Set AIPHABEE_ZAI_API_KEY and AIPHABEE_DEEPSEEK_API_KEY as Worker secrets
82
+ for the profiles your platform uses. Each environment has its own secrets
83
+ and Durable Object namespace. Never put key values in source or request data.
84
+
85
+ The supported profiles are zai_openai and deepseek_direct. The model URLs
86
+ and model names are fixed in this package. Cloud execution uses platform keys.
87
+ Local BYOK keys do not enter this runtime.
88
+
89
+ Configure the session and supply a dispatcher before tool execution.
90
+ The subclass can supply instructions, createDispatcher, admitWake,
91
+ renew, settleRun, projectInvocation, and onInvocationSettled hooks.
92
+ The platform owns entitlement checks, billing, and external settlement.
93
+ A terminal run precedes the settlement hook. Failed settlement is retried
94
+ through the Durable Object alarm. The consumer must make settlement idempotent.
95
+
96
+ The provider transport guards text before it enters durable storage.
97
+ Keys are used only in auth headers. The transport rejects redirects.
98
+ The guard checks exact keys and defined encodings. It cannot detect every
99
+ obfuscation or short fragment. Do not treat it as caller authorization.
100
+
101
+ ## Storage and the public types
102
+
103
+ DurableObjectSqliteDatabase adapts the Durable Object SQLite connection.
104
+ openDurableObjectStorage has the local structural factory type
105
+ (location: DurableObjectStorage) => Promise<Storage>.
106
+ Storage is pi-durable's native interface. The package does not import client
107
+ source or keys types. Its three runtime dependencies are pi-durable, pi-ai,
108
+ and chord, each pinned to 1.0.4.
109
+
110
+ The Durable Object owns the physical connection. Closing the adapter
111
+ invalidates that adapter. It does not close the Durable Object database.
112
+
113
+ This follows the async adapter in [Cloudflare Agents d6656161](https://github.com/cloudflare/agents/blob/d6656161/packages/agents/src/harness/pi/session-store.ts).
114
+ Current upstream uses a different synchronous pi contract. Pinned pi 1.0.4 takes
115
+ async callbacks, so `transactionSync()` cannot host its transaction callback.
116
+ Cloudflare documents async SQL transactions on the
117
+ [SQLite storage API](https://developers.cloudflare.com/durable-objects/api/sqlite-storage-api/).
118
+
119
+ RunRow and InboxRow are public as they are. They include internal state,
120
+ revision, admission, settlement, usage, and text-handoff fields. The API
121
+ golden locks these types. A later breaking type cut requires a MINOR release
122
+ under the SDK's pre-1.0 policy.
123
+
124
+ ## Package checks
125
+
126
+ The library build emits dist/index.js and a local declaration closure.
127
+ The dist check rejects Node builtins, missing or escaped declaration paths,
128
+ and undeclared external type imports. A separate Wrangler dry run writes
129
+ dist-worker. That Worker output is not in the npm package.
130
+
131
+ Release verification installs a real tarball in a temporary consumer.
132
+ It typechecks the subclass, bundles it with Wrangler, and runs its hook,
133
+ Durable Object RPC, identity helper, and SQLite adapter in real workerd.
134
+ The same smoke runs in the Linux, macOS, and Windows release-pack jobs.
@@ -0,0 +1,9 @@
1
+ import { type PlatformProfileId } from './platform-credentials';
2
+ export interface CloudSubmission {
3
+ readonly instruction: string;
4
+ readonly profile: PlatformProfileId;
5
+ }
6
+ /** Best effort, not a claim that arbitrary or obfuscated keys can be recognized. */
7
+ export declare function hasUserKeyShape(text: string): boolean;
8
+ /** Frozen schema for the only 4b operation. No open metadata/config bags, no stripping. */
9
+ export declare function admitCloudSubmission(input: unknown): CloudSubmission;
@@ -0,0 +1,86 @@
1
+ import { DurableObject } from 'cloudflare:workers';
2
+ import { type PlatformProfileId } from './platform-credentials';
3
+ import { SessionRuntime, type CloudRenewRequest, type CloudRenewResult, type CloudRunSettlement } from './session-runtime';
4
+ import type { CloudToolDispatcher } from './tools';
5
+ import type { InvocationTerminalState, InvocationRow } from './invocation-ledger';
6
+ import { type AdmissionIdentity, type InboxRow, type TranscriptCursor, type TranscriptRun } from './cloud-state';
7
+ import { type CloudWakeAdmission } from './wake-runner';
8
+ export { CLOUD_HARNESS_SETTINGS } from './session-runtime';
9
+ /** One named DO owns one Harness; 4b adds platform-only text model submissions. */
10
+ export declare class AgentDO extends DurableObject<Record<string, unknown>> {
11
+ #private;
12
+ /** The consuming Worker supplies trusted code. No executable function is persisted. */
13
+ protected createDispatcher(_id: string): CloudToolDispatcher | undefined;
14
+ /** Post-commit notification. Consumer failures never change the invocation outcome. */
15
+ protected onInvocationSettled(_id: string, _state: InvocationTerminalState): void | Promise<void>;
16
+ protected projectInvocation(_row: InvocationRow): {
17
+ key: string;
18
+ dataJson: string;
19
+ } | undefined;
20
+ /** The consumer owns billing truth and fences every pending admission key on release. */
21
+ protected admitWake(_items: readonly InboxRow[], _signal: AbortSignal, _key: string, _admission: AdmissionIdentity): CloudWakeAdmission | Promise<CloudWakeAdmission>;
22
+ protected instructions(_profile: PlatformProfileId): string | undefined;
23
+ protected renew(_request: CloudRenewRequest, _signal: AbortSignal): CloudRenewResult | Promise<CloudRenewResult>;
24
+ protected settleRun(_run: CloudRunSettlement, _signal: AbortSignal): void | Promise<void>;
25
+ protected sessionRuntime(): SessionRuntime;
26
+ configureSession(input: unknown): Promise<Response>;
27
+ readInvocation(id: string): Promise<InvocationRow | undefined>;
28
+ enqueue(input: unknown): Promise<Response>;
29
+ /** The platform supplies retryCount. This handler never replaces a live owner. */
30
+ alarm(info?: AlarmInvocationInfo): Promise<void>;
31
+ events(input?: {
32
+ after?: number;
33
+ }): Promise<Response>;
34
+ readSnapshot(): Promise<{
35
+ highWater: number;
36
+ trimmedThrough: number;
37
+ inbox: InboxRow[];
38
+ runs: import("./cloud-state").RunRow[];
39
+ invocations: Array<Pick<InvocationRow, 'seq' | 'invocationId' | 'toolName' | 'state' | 'errorCode'>>;
40
+ }>;
41
+ readRuns(input?: {
42
+ after?: number;
43
+ limit?: number;
44
+ }): Promise<import("./cloud-state").RunRow[]>;
45
+ readInbox(input?: {
46
+ after?: number;
47
+ limit?: number;
48
+ }): Promise<InboxRow[]>;
49
+ readInvocations(input?: {
50
+ after?: number;
51
+ limit?: number;
52
+ }): Promise<Pick<InvocationRow, "errorCode" | "invocationId" | "seq" | "state" | "toolName">[]>;
53
+ readTranscript(input?: {
54
+ after?: TranscriptCursor;
55
+ limit?: number;
56
+ }): Promise<{
57
+ runs: TranscriptRun[];
58
+ items: import("./cloud-state").TranscriptItem[];
59
+ next: TranscriptCursor;
60
+ }>;
61
+ readRunOutput(conversationId: number, input?: {
62
+ entryId?: number;
63
+ offset?: number;
64
+ }): Promise<{
65
+ entryId: import("@earendil-works/pi-durable").EntryId;
66
+ offset: number;
67
+ nextOffset: number;
68
+ done: boolean;
69
+ text: string;
70
+ }>;
71
+ cancelActiveRun(): Promise<Response>;
72
+ cancelInboxItem(seq: number): Promise<Response>;
73
+ open(): Promise<{
74
+ scheduling: "closing" | "paused" | "running";
75
+ }>;
76
+ /** D1: every call allocates a new ownerless conversation, including after a restart. */
77
+ openExecution(): Promise<{
78
+ conversationId: number;
79
+ }>;
80
+ /** Passive native pi entries prove storage without starting a model or tool task. */
81
+ appendExecution(conversationId: number, text: string): Promise<void>;
82
+ readExecution(conversationId: number): Promise<string[]>;
83
+ /** Binding/RPC-only. The consumer authorizes identity before obtaining this stub.
84
+ * Errors are structured Responses so the same code/status survive DO RPC. */
85
+ submit(input: unknown): Promise<Response>;
86
+ }
@@ -0,0 +1,231 @@
1
+ import { type CloudDoErrorCode } from './errors';
2
+ import { type CloudInboxAdmission, type InboxSource } from './inbox-admission';
3
+ import type { CloudOperationGuard } from './input-guard';
4
+ import type { ExecutionRow, InvocationRow } from './invocation-ledger';
5
+ import type { PlatformProfileId } from './platform-credentials';
6
+ export type InboxState = 'queued' | 'running' | 'done' | 'failed' | 'interrupted' | 'cancelled' | 'expired';
7
+ export interface InboxRow {
8
+ seq: number;
9
+ dedupKey: string;
10
+ payloadDigest: string;
11
+ source: InboxSource;
12
+ profile: PlatformProfileId;
13
+ payloadJson: string | null;
14
+ availableAt: number;
15
+ expiresAt: number;
16
+ state: InboxState;
17
+ runId: number | null;
18
+ attempts: number;
19
+ errorCode: CloudDoErrorCode | null;
20
+ createdAt: number;
21
+ settledAt: number | null;
22
+ inputDurable: number;
23
+ revision: number | null;
24
+ }
25
+ export interface RunRow extends ExecutionRow {
26
+ trigger: 'submit' | 'wake';
27
+ requestId: string | null;
28
+ submissionId: number | null;
29
+ state: 'starting' | 'running' | 'completed' | 'failed' | 'interrupted';
30
+ errorCode: CloudDoErrorCode | null;
31
+ startedAt: number | null;
32
+ settledAt: number | null;
33
+ reservation: 'none' | 'pending' | 'held' | 'released';
34
+ eligibilityJson: string | null;
35
+ admissionDigest: string | null;
36
+ admittedSeqs: string | null;
37
+ settlementAck: number | null;
38
+ revision: number | null;
39
+ membershipPending: number | null;
40
+ }
41
+ export interface TranscriptCursor {
42
+ horizon: number;
43
+ run: number | null;
44
+ item: number | null;
45
+ }
46
+ export interface TranscriptTurn {
47
+ seq: number;
48
+ runId: number | null;
49
+ state: InboxState | null;
50
+ errorCode: CloudDoErrorCode | null;
51
+ revision: number | null;
52
+ text: string | null;
53
+ }
54
+ export interface TranscriptItem {
55
+ seq: number;
56
+ dedupKey: string;
57
+ state: InboxState;
58
+ errorCode: CloudDoErrorCode | null;
59
+ runId: number | null;
60
+ attempts: number;
61
+ revision: number | null;
62
+ text: string | null;
63
+ }
64
+ export interface TranscriptInvocation {
65
+ invocationId: string;
66
+ toolName: string;
67
+ state: InvocationRow['state'];
68
+ errorCode: CloudDoErrorCode | null;
69
+ revision: number | null;
70
+ }
71
+ export interface TranscriptRun {
72
+ nativeRunId: number;
73
+ revision: number | null;
74
+ state: RunRow['state'];
75
+ errorCode: CloudDoErrorCode | null;
76
+ trigger: RunRow['trigger'];
77
+ settlementAck: boolean;
78
+ claimedSeqs: number[];
79
+ turns: TranscriptTurn[];
80
+ text?: string;
81
+ truncated?: boolean;
82
+ invocations: TranscriptInvocation[];
83
+ }
84
+ export interface TranscriptPlan {
85
+ runs: Array<{
86
+ run: RunRow;
87
+ turns: TranscriptTurn[];
88
+ invocations: TranscriptInvocation[];
89
+ }>;
90
+ items: TranscriptItem[];
91
+ next: TranscriptCursor;
92
+ }
93
+ export interface AdmissionIdentity {
94
+ digest: string;
95
+ seqs: number[];
96
+ }
97
+ export interface CloudEventRow {
98
+ seq: number;
99
+ eventKey: string;
100
+ type: string;
101
+ conversationId: number | null;
102
+ ref: string | null;
103
+ dataJson: string;
104
+ createdAt: number;
105
+ }
106
+ export interface CloudEventInput {
107
+ eventKey: string;
108
+ type: string;
109
+ conversationId?: number;
110
+ ref?: string;
111
+ data: Record<string, unknown>;
112
+ createdAt?: number;
113
+ }
114
+ export interface CloudEventMeta {
115
+ trimmedThrough: number;
116
+ highWater: number;
117
+ }
118
+ export interface SchedulingState {
119
+ busy?: boolean;
120
+ repairRetrying?: boolean;
121
+ }
122
+ export interface RunSettlement {
123
+ state: 'completed' | 'failed' | 'interrupted';
124
+ errorCode?: CloudDoErrorCode;
125
+ text?: string;
126
+ entryId?: number;
127
+ /** The caller derives this only from the durable pre-recovery eligibility snapshot. */
128
+ requeue?: boolean;
129
+ }
130
+ export interface RunHistory {
131
+ input: unknown;
132
+ reply: string;
133
+ }
134
+ export interface InboxInput {
135
+ seq: number;
136
+ source: InboxSource;
137
+ text: string;
138
+ }
139
+ export type InvocationProjection = (row: InvocationRow) => {
140
+ key: string;
141
+ dataJson: string;
142
+ } | undefined;
143
+ export declare const CLOUD_CONTEXT_BYTES = 48000;
144
+ export declare function inboxInput(rows: readonly InboxRow[]): InboxInput[];
145
+ export declare function admissionIdentity(rows: readonly InboxRow[]): AdmissionIdentity;
146
+ /** Accept only the committed native wake input shape. */
147
+ export declare function runInputSeqs(entries: readonly unknown[]): number[];
148
+ /** Fit inbox first. Add the newest history prefix, then emit it in chronological order. */
149
+ export declare function composeCloudInput(rows: readonly InboxRow[], historyNewestFirst?: readonly RunHistory[]): string;
150
+ export declare function utf8Prefix(text: string, maxBytes: number): string;
151
+ /** Visible SQL state. Sync helpers can participate in the caller's transaction. */
152
+ export declare class CloudState {
153
+ private readonly storage;
154
+ private scheduling;
155
+ constructor(storage: DurableObjectStorage);
156
+ private rows;
157
+ ensureSchema(): void;
158
+ private migrate;
159
+ readInboxItem(seq: number): InboxRow | undefined;
160
+ run(conversationId: number): RunRow | undefined;
161
+ unsettledRuns(): RunRow[];
162
+ completedRuns(): RunRow[];
163
+ invocationRowsForRun(id: number): InvocationRow[];
164
+ private stamp;
165
+ claimedSeqs(id: number): number[];
166
+ markInputDurable(id: number, seqs: readonly number[]): void;
167
+ pendingBackfills(before?: number): RunRow[];
168
+ applyBackfill(id: number, seqs: readonly number[]): void;
169
+ unackedRuns(): RunRow[];
170
+ ackSettlement(id: number, guard: CloudOperationGuard, now?: number): boolean;
171
+ /** Read-only preflight also works before this DO has initialized its schema. */
172
+ validateEnqueue(input: CloudInboxAdmission, guard: CloudOperationGuard, now?: number): void;
173
+ private enqueueIdentity;
174
+ enqueue(input: CloudInboxAdmission, guard: CloudOperationGuard, now?: number, options?: SchedulingState): Promise<{
175
+ accepted: boolean;
176
+ row: InboxRow;
177
+ }>;
178
+ /** Selection never skips another profile or a prefix item that exceeds the budget. */
179
+ selectBatch(now?: number, guard?: CloudOperationGuard): InboxRow[];
180
+ startRun(id: number, trigger: 'submit' | 'wake', deadlineAt: number, guard: CloudOperationGuard, now?: number): RunRow;
181
+ markRunning(id: number, guard: CloudOperationGuard, now?: number): void;
182
+ recordSubmission(id: number, submissionId: number): void;
183
+ markReservation(id: number, reservation: RunRow['reservation'], guard: CloudOperationGuard, now?: number, admission?: AdmissionIdentity): void;
184
+ captureEligibility(originalStale?: ReadonlySet<number>): RunRow[];
185
+ claim(id: number, seqs: readonly number[], profile: PlatformProfileId, guard: CloudOperationGuard, now?: number): InboxRow[];
186
+ private settleItem;
187
+ failQueued(seqs: readonly number[], code: CloudDoErrorCode, guard: CloudOperationGuard, now?: number): void;
188
+ cancelQueued(seq: number, guard: CloudOperationGuard, now?: number): InboxRow | undefined;
189
+ expireQueued(guard: CloudOperationGuard, now?: number): number;
190
+ settleRun(id: number, outcome: RunSettlement, guard: CloudOperationGuard, now?: number): RunRow | undefined;
191
+ /** The caller must wrap this and its state write in one transaction. */
192
+ appendEvent(event: CloudEventInput, guard: CloudOperationGuard): CloudEventRow;
193
+ eventMeta(): CloudEventMeta;
194
+ eventPage(after: number, limit?: number): CloudEventRow[];
195
+ private pageLimit;
196
+ /** Capture ownership and payloads before any asynchronous pi context read. */
197
+ planTranscript(after: TranscriptCursor | undefined, limit: number): TranscriptPlan;
198
+ readRun(id: number): RunRow | undefined;
199
+ readRuns(options?: {
200
+ after?: number;
201
+ limit?: number;
202
+ }): RunRow[];
203
+ readInbox(options?: {
204
+ after?: number;
205
+ limit?: number;
206
+ }): InboxRow[];
207
+ readInvocations(options?: {
208
+ after?: number;
209
+ limit?: number;
210
+ }): Array<Pick<InvocationRow, 'seq' | 'invocationId' | 'toolName' | 'state' | 'errorCode'>>;
211
+ private pageAfter;
212
+ snapshot(): {
213
+ highWater: number;
214
+ trimmedThrough: number;
215
+ inbox: InboxRow[];
216
+ runs: RunRow[];
217
+ invocations: Array<Pick<InvocationRow, 'seq' | 'invocationId' | 'toolName' | 'state' | 'errorCode'>>;
218
+ };
219
+ setDelivery(id: string, state: 'delivered' | 'undelivered', taskId: number | null, entryId: number | null, guard: CloudOperationGuard, now?: number): void;
220
+ projectInvocation(row: InvocationRow, project: InvocationProjection | undefined, guard: CloudOperationGuard, now?: number): void;
221
+ private projectionFailed;
222
+ private trimPrefix;
223
+ retention(now?: number): {
224
+ events: number;
225
+ inbox: number;
226
+ };
227
+ setSchedulingState(options: SchedulingState): void;
228
+ nextAlarm(now?: number, busy?: boolean): number | null;
229
+ /** This is the only alarm mutation path. Async enqueue calls it inside its storage transaction. */
230
+ rearmAlarm(options?: SchedulingState, now?: number): Promise<void>;
231
+ }
@@ -0,0 +1,41 @@
1
+ declare const status: {
2
+ readonly CLOUD_REQUEST_INVALID: 400;
3
+ readonly CLOUD_INBOX_FULL: 429;
4
+ readonly CLOUD_INBOX_CONFLICT: 409;
5
+ readonly CLOUD_INBOX_EXPIRED: 409;
6
+ readonly CLOUD_INBOX_TOO_LARGE: 400;
7
+ readonly CLOUD_WAKE_EXHAUSTED: 409;
8
+ readonly CLOUD_WAKE_EMPTY: 409;
9
+ readonly CLOUD_EVENT_CURSOR_EXPIRED: 410;
10
+ readonly CLOUD_EVENTS_BUSY: 429;
11
+ readonly CLOUD_USER_CREDENTIAL_REJECTED: 400;
12
+ readonly CLOUD_MODEL_CREDENTIAL_UNAVAILABLE: 503;
13
+ readonly CLOUD_MODEL_RESPONSE_REJECTED: 502;
14
+ readonly CLOUD_MODEL_REQUEST_FAILED: 502;
15
+ readonly CLOUD_SESSION_CONFLICT: 409;
16
+ readonly CLOUD_TOOL_NOT_AVAILABLE: 400;
17
+ readonly CLOUD_TOOL_INVOCATION_CONFLICT: 409;
18
+ readonly CLOUD_TOOL_ARGUMENT_INVALID: 400;
19
+ readonly CLOUD_TOOL_LIMIT: 400;
20
+ readonly CLOUD_STEP_LIMIT: 400;
21
+ readonly CLOUD_BUDGET_EXCEEDED: 400;
22
+ readonly CLOUD_TOOL_RESULT_LIMIT: 502;
23
+ readonly CLOUD_TOOL_USAGE_INVALID: 502;
24
+ readonly CLOUD_TOOL_BUSY: 409;
25
+ readonly CLOUD_TOOL_TIMEOUT: 504;
26
+ readonly CLOUD_EXECUTION_TIMEOUT: 504;
27
+ readonly CLOUD_EXECUTION_INTERRUPTED: 409;
28
+ readonly CLOUD_EXECUTION_ABORTED: 409;
29
+ readonly CLOUD_TOOL_FAILED: 502;
30
+ };
31
+ export type CloudDoErrorCode = keyof typeof status;
32
+ /** Never attach an upstream exception, request, response, env, or credential. */
33
+ export declare class CloudDoError extends Error {
34
+ readonly code: CloudDoErrorCode;
35
+ readonly status: number;
36
+ readonly retryable = false;
37
+ constructor(code: CloudDoErrorCode);
38
+ }
39
+ export declare function safeCloudError(error: unknown): CloudDoError;
40
+ export declare function cloudErrorResponse(error: unknown): Response;
41
+ export {};
@@ -0,0 +1,15 @@
1
+ import type { CloudState } from './cloud-state';
2
+ /** A doorbell is advisory. Every delivery reads the durable SQL cursor again. */
3
+ export declare class CloudEventDoorbell {
4
+ private generation;
5
+ private listeners;
6
+ ring(): void;
7
+ get version(): number;
8
+ wait(version: number, signal: AbortSignal, duration?: number): Promise<void>;
9
+ }
10
+ export declare class CloudEventStreams {
11
+ private readonly bell;
12
+ private readers;
13
+ constructor(bell: CloudEventDoorbell);
14
+ open(state: CloudState, after: number | undefined, waitUntil: (work: Promise<unknown>) => void): Response;
15
+ }
@@ -0,0 +1,15 @@
1
+ import type { AgentDO } from './agent-do';
2
+ export interface AgentIdentity {
3
+ readonly tenantId: string;
4
+ readonly workspaceId: string;
5
+ readonly agentId: string;
6
+ }
7
+ export interface SessionIdentity extends AgentIdentity {
8
+ readonly sessionId: string;
9
+ }
10
+ export declare function agentObjectName(identity: AgentIdentity): Promise<string>;
11
+ /** Call only after the platform has authorized the tenant/workspace/agent identity. */
12
+ export declare function getAgentObject(namespace: DurableObjectNamespace<AgentDO>, identity: AgentIdentity): Promise<DurableObjectStub<AgentDO>>;
13
+ export declare function sessionObjectName(identity: SessionIdentity): Promise<string>;
14
+ /** The consuming platform authorizes all four identity fields before this lookup. */
15
+ export declare function getSessionObject(namespace: DurableObjectNamespace<AgentDO>, identity: SessionIdentity): Promise<DurableObjectStub<AgentDO>>;
@@ -0,0 +1,13 @@
1
+ import { type PlatformProfileId } from './platform-credentials';
2
+ export type InboxSource = 'message' | 'schedule' | 'invocation';
3
+ export interface CloudInboxAdmission {
4
+ readonly dedupKey: string;
5
+ readonly source: InboxSource;
6
+ readonly text: string;
7
+ readonly profile: PlatformProfileId;
8
+ readonly availableAt?: number;
9
+ readonly expiresAt?: number;
10
+ }
11
+ export declare const INBOX_DAY = 86400000;
12
+ /** Freeze the wire schema before credential reads or storage writes. */
13
+ export declare function admitCloudInbox(input: unknown, now?: number): CloudInboxAdmission;
@@ -0,0 +1,13 @@
1
+ export { AgentDO } from './agent-do';
2
+ export type { CloudWakeAdmission } from './wake-runner';
3
+ export type { InboxRow, RunRow, CloudEventRow, CloudEventMeta } from './cloud-state';
4
+ export type { TranscriptCursor, TranscriptRun, TranscriptTurn, TranscriptItem } from './cloud-state';
5
+ export type { CloudRenewRequest, CloudRenewResult, CloudRunSettlement } from './session-runtime';
6
+ export { agentObjectName, getAgentObject, type AgentIdentity } from './identity';
7
+ export { sessionObjectName, getSessionObject, type SessionIdentity } from './identity';
8
+ export { CLOUD_SAFE_REPLAY_TOOLS, CLOUD_LIVE_IPO_TOOLS, type CloudToolResult, type CloudToolDefinition, type CloudToolDispatcher, type CloudDispatchContext, type CloudToolCallContext } from './tools';
9
+ export { DurableObjectSqliteDatabase, openDurableObjectStorage } from './storage';
10
+ declare const _default: {
11
+ fetch: () => Response;
12
+ };
13
+ export default _default;