@byok-sdk/cloud-do 0.0.0-stage → 0.24.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 +21 -0
- package/README.md +132 -2
- package/dist/admission.d.ts +9 -0
- package/dist/agent-do.d.ts +86 -0
- package/dist/cloud-state.d.ts +231 -0
- package/dist/errors.d.ts +41 -0
- package/dist/event-stream.d.ts +15 -0
- package/dist/identity.d.ts +15 -0
- package/dist/inbox-admission.d.ts +13 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +3915 -0
- package/dist/index.js.map +1 -0
- package/dist/input-guard.d.ts +13 -0
- package/dist/invocation-ledger.d.ts +99 -0
- package/dist/leak-guard.d.ts +13 -0
- package/dist/platform-credentials.d.ts +30 -0
- package/dist/platform-provider.d.ts +18 -0
- package/dist/provider-fetch.d.ts +11 -0
- package/dist/session-config.d.ts +20 -0
- package/dist/session-runtime.d.ts +121 -0
- package/dist/storage.d.ts +21 -0
- package/dist/tools.d.ts +68 -0
- package/dist/wake-runner.d.ts +16 -0
- package/package.json +53 -4
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type PlatformProfileId } from './platform-credentials';
|
|
2
|
+
/** Keep the existing pre-storage text guard shared by submission and tool data. */
|
|
3
|
+
export declare function admitCloudText(env: Readonly<Record<string, unknown>>, text: string, selected?: PlatformProfileId): Promise<void>;
|
|
4
|
+
/** Check decoded JSON values before any part enters pi or the invocation ledger. */
|
|
5
|
+
export declare function admitCloudPayload(env: Readonly<Record<string, unknown>>, value: unknown, selected?: PlatformProfileId): Promise<void>;
|
|
6
|
+
/** Keys belong to one operation. Dispose the guard when that operation ends. */
|
|
7
|
+
export interface CloudOperationGuard {
|
|
8
|
+
guardText(text: string): void;
|
|
9
|
+
/** Decode first. Check every key and value before admitted re-serialization. */
|
|
10
|
+
guardPayload(dataJson: string): string;
|
|
11
|
+
dispose(): void;
|
|
12
|
+
}
|
|
13
|
+
export declare function prepareCloudGuard(env: Readonly<Record<string, unknown>>, selected?: PlatformProfileId): Promise<CloudOperationGuard>;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { type CloudDoErrorCode } from './errors';
|
|
2
|
+
import type { CloudOperationGuard } from './input-guard';
|
|
3
|
+
export type InvocationState = 'accepted' | 'running' | 'succeeded' | 'failed' | 'aborted' | 'interrupted' | 'timed_out';
|
|
4
|
+
export type InvocationTerminalState = Exclude<InvocationState, 'accepted' | 'running'>;
|
|
5
|
+
export interface InvocationInput {
|
|
6
|
+
invocationId: string;
|
|
7
|
+
sessionId: string;
|
|
8
|
+
conversationId: number;
|
|
9
|
+
assistantEntryId: number;
|
|
10
|
+
toolCallId: string;
|
|
11
|
+
toolName: string;
|
|
12
|
+
argsDigest: string;
|
|
13
|
+
argsJson: string;
|
|
14
|
+
replay: 'safe' | 'unsafe';
|
|
15
|
+
deadlineAt: number;
|
|
16
|
+
}
|
|
17
|
+
export interface InvocationRow extends InvocationInput {
|
|
18
|
+
seq: number;
|
|
19
|
+
state: InvocationState;
|
|
20
|
+
attempt: number;
|
|
21
|
+
replayCount: number;
|
|
22
|
+
abortRequested: number;
|
|
23
|
+
resultJson: string | null;
|
|
24
|
+
settledAt: number | null;
|
|
25
|
+
settledEventSeq: number | null;
|
|
26
|
+
errorCode: CloudDoErrorCode | null;
|
|
27
|
+
mode: 'inline' | 'job';
|
|
28
|
+
segmentStartedAt: number | null;
|
|
29
|
+
nextSegmentAt: number | null;
|
|
30
|
+
jobStateJson: string | null;
|
|
31
|
+
progressJson: string | null;
|
|
32
|
+
deliveredState?: 'delivered' | 'undelivered';
|
|
33
|
+
taskId?: number | null;
|
|
34
|
+
resultEntryId?: number | null;
|
|
35
|
+
}
|
|
36
|
+
export interface ExecutionRow {
|
|
37
|
+
conversationId: number;
|
|
38
|
+
deadlineAt: number;
|
|
39
|
+
steps: number;
|
|
40
|
+
tools: number;
|
|
41
|
+
inputTokens: number;
|
|
42
|
+
outputTokens: number;
|
|
43
|
+
credits: number;
|
|
44
|
+
sentRequests: number;
|
|
45
|
+
fatalCode: CloudDoErrorCode | null;
|
|
46
|
+
aborted: number;
|
|
47
|
+
}
|
|
48
|
+
export interface InvocationFinishOptions {
|
|
49
|
+
/** An old attempt cannot settle an invocation claimed by recovery. */
|
|
50
|
+
attempt?: number;
|
|
51
|
+
clientConnected?: boolean;
|
|
52
|
+
/** Ledger recovery may settle after the old native conversation was aborted. */
|
|
53
|
+
recovery?: boolean;
|
|
54
|
+
creditCap?: number;
|
|
55
|
+
}
|
|
56
|
+
export interface InvocationLedgerOptions {
|
|
57
|
+
started?(row: InvocationRow, guard?: CloudOperationGuard): void;
|
|
58
|
+
startedCommitted?(row: InvocationRow): void;
|
|
59
|
+
/** Runs inside the state transaction. Errors roll back state and events together. */
|
|
60
|
+
terminal?(row: InvocationRow, recovery: boolean): {
|
|
61
|
+
seq: number;
|
|
62
|
+
createdAt: number;
|
|
63
|
+
} | void;
|
|
64
|
+
/** Post-commit notification cannot affect the invocation outcome. */
|
|
65
|
+
committed?(row: InvocationRow): void;
|
|
66
|
+
}
|
|
67
|
+
/** Host tables share the DO database with the pi_ tables. No function enters storage. */
|
|
68
|
+
export declare class InvocationLedger {
|
|
69
|
+
#private;
|
|
70
|
+
private readonly storage;
|
|
71
|
+
private readonly options;
|
|
72
|
+
constructor(storage: DurableObjectStorage, options?: InvocationLedgerOptions);
|
|
73
|
+
/** The host calls this only after credential and identity preflight. */
|
|
74
|
+
ensureSchema(): void;
|
|
75
|
+
read(id: string): InvocationRow | undefined;
|
|
76
|
+
pending(): InvocationRow[];
|
|
77
|
+
begin(input: InvocationInput, guard?: CloudOperationGuard): {
|
|
78
|
+
kind: 'started' | 'pending' | 'settled';
|
|
79
|
+
row: InvocationRow;
|
|
80
|
+
};
|
|
81
|
+
finish(id: string, state: InvocationTerminalState, result?: Record<string, unknown>, errorCode?: CloudDoErrorCode, now?: number, options?: InvocationFinishOptions): InvocationRow | undefined;
|
|
82
|
+
/** Claim before network replay. A second restart never dispatches a claimed row again. */
|
|
83
|
+
claimRecovery(now?: number): InvocationRow[];
|
|
84
|
+
forConversation(conversationId: number): InvocationRow[];
|
|
85
|
+
startExecution(conversationId: number, deadlineAt: number): ExecutionRow;
|
|
86
|
+
execution(conversationId: number): ExecutionRow | undefined;
|
|
87
|
+
failExecution(conversationId: number, code: CloudDoErrorCode): ExecutionRow | undefined;
|
|
88
|
+
abortExecution(conversationId: number, code: CloudDoErrorCode): ExecutionRow | undefined;
|
|
89
|
+
private executionRejection;
|
|
90
|
+
countModel(conversationId: number, maxSteps?: number, now?: number, budget?: {
|
|
91
|
+
inputBytes: number;
|
|
92
|
+
inputTokens: number;
|
|
93
|
+
outputTokens: number;
|
|
94
|
+
}): ExecutionRow;
|
|
95
|
+
addModelUsage(conversationId: number, input: number, output: number): void;
|
|
96
|
+
/** This mark records durable dispatch intent. It does not prove network receipt. */
|
|
97
|
+
markModelSent(conversationId: number): void;
|
|
98
|
+
countTool(conversationId: number, taskId: string, maxTools?: number, now?: number): ExecutionRow;
|
|
99
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Scans decoded model text, before any of it reaches pi or persistence. */
|
|
2
|
+
export declare class RollingLeakGuard {
|
|
3
|
+
readonly tailLength: number;
|
|
4
|
+
private readonly forms;
|
|
5
|
+
private readonly percentForms;
|
|
6
|
+
private pending;
|
|
7
|
+
private closed;
|
|
8
|
+
constructor(key: string);
|
|
9
|
+
push(text: string): string;
|
|
10
|
+
finish(): string;
|
|
11
|
+
discard(): void;
|
|
12
|
+
private scan;
|
|
13
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** The platform reads one key. It does not own a local credential store. */
|
|
2
|
+
export type ModelProviderSecretName = `model-${string}-api-key`;
|
|
3
|
+
export interface PlatformCredentialReader {
|
|
4
|
+
get(name: ModelProviderSecretName): Promise<string | undefined>;
|
|
5
|
+
}
|
|
6
|
+
export declare const PLATFORM_PROFILES: Readonly<{
|
|
7
|
+
zai_openai: Readonly<{
|
|
8
|
+
vendor: "zai";
|
|
9
|
+
baseUrl: "https://api.z.ai/api/coding/paas/v4";
|
|
10
|
+
model: "glm-5.3-flash";
|
|
11
|
+
binding: "AIPHABEE_ZAI_API_KEY";
|
|
12
|
+
secretName: "model-zai_openai-api-key";
|
|
13
|
+
}>;
|
|
14
|
+
deepseek_direct: Readonly<{
|
|
15
|
+
vendor: "deepseek";
|
|
16
|
+
baseUrl: "https://api.deepseek.com";
|
|
17
|
+
model: "deepseek-v4-flash";
|
|
18
|
+
binding: "AIPHABEE_DEEPSEEK_API_KEY";
|
|
19
|
+
secretName: "model-deepseek_direct-api-key";
|
|
20
|
+
}>;
|
|
21
|
+
}>;
|
|
22
|
+
export type PlatformProfileId = keyof typeof PLATFORM_PROFILES;
|
|
23
|
+
export type PlatformProfile = (typeof PLATFORM_PROFILES)[PlatformProfileId];
|
|
24
|
+
export declare function platformProfile(id: unknown): PlatformProfileId;
|
|
25
|
+
/** A small bounded ASCII token, never whitespace/control characters or a header fragment. */
|
|
26
|
+
export declare function requirePlatformKey(value: unknown): string;
|
|
27
|
+
/** The concrete reader returns a valid key or rejects with a fixed error. */
|
|
28
|
+
export declare function platformCredentialReader(env: Readonly<Record<string, unknown>>): {
|
|
29
|
+
get(name: ModelProviderSecretName): Promise<string>;
|
|
30
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type PlatformCredentialReader } from './platform-credentials';
|
|
2
|
+
export declare const PLATFORM_MAX_OUTPUT_TOKENS = 4096;
|
|
3
|
+
export declare const REQUEST_FRAMING_BYTES = 4096;
|
|
4
|
+
export interface CloudModelAccount {
|
|
5
|
+
sent(): void;
|
|
6
|
+
usage(usage: {
|
|
7
|
+
input?: number;
|
|
8
|
+
output?: number;
|
|
9
|
+
}): void;
|
|
10
|
+
}
|
|
11
|
+
export interface CloudModelRuntime {
|
|
12
|
+
beforeRequest(info: {
|
|
13
|
+
inputBytes: number;
|
|
14
|
+
}): void | CloudModelAccount | Promise<void | CloudModelAccount>;
|
|
15
|
+
admitToolCall(name: string, id: string, args: Record<string, unknown>): void | Promise<void>;
|
|
16
|
+
requestSignal?(signal?: AbortSignal): AbortSignal;
|
|
17
|
+
}
|
|
18
|
+
export declare function createPlatformModels(env: Readonly<Record<string, unknown>>, credentials?: PlatformCredentialReader, runtime?: CloudModelRuntime): import("@earendil-works/pi-ai").MutableModels;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { FetchFunction } from '@earendil-works/pi-ai';
|
|
2
|
+
import { type PlatformProfile } from './platform-credentials';
|
|
3
|
+
export interface CloudToolTransport {
|
|
4
|
+
readonly offeredToolNames: readonly string[];
|
|
5
|
+
admitToolCall(name: string, rawId: string, args: Record<string, unknown>): void | Promise<void>;
|
|
6
|
+
onSend?(): void;
|
|
7
|
+
onUsage?(usage: Record<string, number>): void;
|
|
8
|
+
}
|
|
9
|
+
export declare function readSseData(body: ReadableStream<Uint8Array>): AsyncGenerator<string>;
|
|
10
|
+
/** Credential only in auth headers; never follow any redirect, even same origin. */
|
|
11
|
+
export declare function createProviderFetch(profile: PlatformProfile, secret: string, fetchImpl?: FetchFunction, transport?: CloudToolTransport): FetchFunction;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { CloudDispatchContext } from './tools';
|
|
2
|
+
export interface CloudLimits {
|
|
3
|
+
readonly modelSteps: number;
|
|
4
|
+
readonly toolCalls: number;
|
|
5
|
+
readonly inlineFetches: number;
|
|
6
|
+
readonly callTimeoutMs: number;
|
|
7
|
+
readonly turnTimeoutMs: number;
|
|
8
|
+
readonly resultBytes: number;
|
|
9
|
+
}
|
|
10
|
+
export declare const CLOUD_LIMITS: Readonly<CloudLimits>;
|
|
11
|
+
export declare const CLOUD_BUDGET: Readonly<{
|
|
12
|
+
credits: 100;
|
|
13
|
+
inputTokens: 128000;
|
|
14
|
+
outputTokens: 32768;
|
|
15
|
+
}>;
|
|
16
|
+
export interface CloudSessionConfig extends Omit<CloudDispatchContext, 'call' | 'lookup'> {
|
|
17
|
+
readonly limits: CloudLimits;
|
|
18
|
+
}
|
|
19
|
+
/** The consuming platform authorizes this data. It supplies the dispatcher in code. */
|
|
20
|
+
export declare function admitSessionConfig(input: unknown): CloudSessionConfig;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { Harness, type AgentChange } from '@earendil-works/pi-durable';
|
|
2
|
+
import { type CloudDoErrorCode } from './errors';
|
|
3
|
+
import { type CloudOperationGuard } from './input-guard';
|
|
4
|
+
import { CloudState, type RunRow } from './cloud-state';
|
|
5
|
+
import { InvocationLedger, type InvocationRow, type InvocationTerminalState } from './invocation-ledger';
|
|
6
|
+
import { type PlatformProfileId } from './platform-credentials';
|
|
7
|
+
import { type CloudToolDispatcher } from './tools';
|
|
8
|
+
export declare const CLOUD_HARNESS_SETTINGS: {
|
|
9
|
+
readonly compaction: {
|
|
10
|
+
readonly enabled: false;
|
|
11
|
+
};
|
|
12
|
+
readonly retry: {
|
|
13
|
+
readonly enabled: false;
|
|
14
|
+
readonly maxRetries: 0;
|
|
15
|
+
};
|
|
16
|
+
readonly stream: {
|
|
17
|
+
readonly maxRetries: 0;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export interface ExecutionLease {
|
|
21
|
+
conversationId?: number;
|
|
22
|
+
trigger?: 'submit' | 'wake';
|
|
23
|
+
readonly profile: PlatformProfileId;
|
|
24
|
+
readonly deadlineAt: number;
|
|
25
|
+
readonly controller: AbortController;
|
|
26
|
+
connected: boolean;
|
|
27
|
+
timer?: ReturnType<typeof setTimeout>;
|
|
28
|
+
guard?: CloudOperationGuard;
|
|
29
|
+
liveOwner: boolean;
|
|
30
|
+
settled: boolean;
|
|
31
|
+
}
|
|
32
|
+
export interface CloudRenewRequest {
|
|
33
|
+
nativeRunId: number;
|
|
34
|
+
requestId: string | null;
|
|
35
|
+
kind: 'model' | 'tool';
|
|
36
|
+
toolName?: string;
|
|
37
|
+
recovery: boolean;
|
|
38
|
+
}
|
|
39
|
+
export type CloudRenewResult = {
|
|
40
|
+
ok: true;
|
|
41
|
+
} | {
|
|
42
|
+
ok: false;
|
|
43
|
+
code: CloudDoErrorCode;
|
|
44
|
+
};
|
|
45
|
+
export interface CloudRunSettlement {
|
|
46
|
+
nativeRunId: number;
|
|
47
|
+
requestId: string | null;
|
|
48
|
+
trigger: RunRow['trigger'];
|
|
49
|
+
state: 'completed' | 'failed' | 'interrupted';
|
|
50
|
+
errorCode: CloudDoErrorCode | null;
|
|
51
|
+
reservation: RunRow['reservation'];
|
|
52
|
+
admissionDigest: string | null;
|
|
53
|
+
admittedSeqs: readonly number[];
|
|
54
|
+
claimedSeqs: readonly number[];
|
|
55
|
+
usage: Readonly<{
|
|
56
|
+
steps: number;
|
|
57
|
+
sentRequests: number;
|
|
58
|
+
inputTokens: number;
|
|
59
|
+
outputTokens: number;
|
|
60
|
+
credits: number;
|
|
61
|
+
}>;
|
|
62
|
+
}
|
|
63
|
+
/** Bound consumer work even when it ignores the supplied signal. */
|
|
64
|
+
export declare function raceLease<T>(work: Promise<T>, lease: ExecutionLease): Promise<T>;
|
|
65
|
+
export interface RuntimeOptions {
|
|
66
|
+
createDispatcher(id: string): CloudToolDispatcher | undefined;
|
|
67
|
+
projectInvocation?(row: InvocationRow): {
|
|
68
|
+
key: string;
|
|
69
|
+
dataJson: string;
|
|
70
|
+
} | undefined;
|
|
71
|
+
onCommit?(): void;
|
|
72
|
+
onInvocationSettled?(id: string, state: InvocationTerminalState): void | Promise<void>;
|
|
73
|
+
instructions?(profile: PlatformProfileId): string | undefined;
|
|
74
|
+
renew?(request: CloudRenewRequest, signal: AbortSignal): CloudRenewResult | Promise<CloudRenewResult>;
|
|
75
|
+
settleRun?(run: CloudRunSettlement, signal: AbortSignal): void | Promise<void>;
|
|
76
|
+
}
|
|
77
|
+
export interface RunOutcome {
|
|
78
|
+
state: 'completed' | 'failed' | 'interrupted';
|
|
79
|
+
errorCode?: CloudDoErrorCode;
|
|
80
|
+
text?: string;
|
|
81
|
+
entryId?: number;
|
|
82
|
+
requeue?: boolean;
|
|
83
|
+
}
|
|
84
|
+
/** One physical DO owns this runtime. Native pi owns all model and task scheduling. */
|
|
85
|
+
export declare class SessionRuntime {
|
|
86
|
+
#private;
|
|
87
|
+
private readonly state;
|
|
88
|
+
private readonly env;
|
|
89
|
+
private readonly options;
|
|
90
|
+
readonly ledger: InvocationLedger;
|
|
91
|
+
readonly cloud: CloudState;
|
|
92
|
+
constructor(state: DurableObjectState, env: Readonly<Record<string, unknown>>, options: RuntimeOptions);
|
|
93
|
+
get recovering(): boolean;
|
|
94
|
+
get activeLease(): ExecutionLease | undefined;
|
|
95
|
+
get hasLiveOwner(): boolean;
|
|
96
|
+
get busy(): boolean;
|
|
97
|
+
get repairRetrying(): boolean;
|
|
98
|
+
prepareGuard(profile?: PlatformProfileId): Promise<CloudOperationGuard>;
|
|
99
|
+
/** Binding/RPC callers authorize the session before calling this immutable configuration operation. */
|
|
100
|
+
configure(input: unknown): Promise<void>;
|
|
101
|
+
open(selected?: PlatformProfileId): Promise<Harness>;
|
|
102
|
+
ready(selected?: PlatformProfileId): Promise<Harness>;
|
|
103
|
+
agentChange(profile: PlatformProfileId, guard: CloudOperationGuard): AgentChange;
|
|
104
|
+
reserve(profile: PlatformProfileId, guard?: CloudOperationGuard): ExecutionLease;
|
|
105
|
+
attach(lease: ExecutionLease, conversationId: number, trigger?: 'submit' | 'wake', guard?: CloudOperationGuard | undefined): void;
|
|
106
|
+
cancel(lease: ExecutionLease, code?: CloudDoErrorCode): void;
|
|
107
|
+
release(lease: ExecutionLease, retryCount?: number): Promise<void>;
|
|
108
|
+
recordSubmission(conversationId: number, submissionId: number): void;
|
|
109
|
+
markReservation(conversationId: number, reservation: 'pending' | 'held' | 'none', admission?: {
|
|
110
|
+
digest: string;
|
|
111
|
+
seqs: number[];
|
|
112
|
+
}): void;
|
|
113
|
+
claimWake(lease: ExecutionLease, seqs: readonly number[], profile?: "deepseek_direct" | "zai_openai"): import("./cloud-state").InboxRow[];
|
|
114
|
+
settle(lease: ExecutionLease, outcome: RunOutcome): Promise<void>;
|
|
115
|
+
cancelActive(code?: CloudDoErrorCode): boolean;
|
|
116
|
+
/** Only an owner that exited may be repaired. A live provider run is never adjudicated here. */
|
|
117
|
+
repairPendingRuns(retryCount?: number): Promise<boolean>;
|
|
118
|
+
deliverSettlementsForAlarm(retryCount?: number, providedGuard?: CloudOperationGuard): Promise<void>;
|
|
119
|
+
fatal(conversationId: number): CloudDoErrorCode | undefined;
|
|
120
|
+
readInvocation(id: string): InvocationRow | undefined;
|
|
121
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type SqliteDatabase, type SqliteExecutor, type SqliteValue } from '@earendil-works/pi-durable/storage/sqlite';
|
|
2
|
+
import type { Storage } from '@earendil-works/pi-durable';
|
|
3
|
+
/** Construction returns pi's native Storage interface. */
|
|
4
|
+
type DurableStorageFactory<Location> = (location: Location) => Promise<Storage>;
|
|
5
|
+
/** One adapter per DO database: unrelated reads, writes, transactions and close share this queue. */
|
|
6
|
+
export declare class DurableObjectSqliteDatabase implements SqliteDatabase {
|
|
7
|
+
private readonly storage;
|
|
8
|
+
private tail;
|
|
9
|
+
private closed;
|
|
10
|
+
constructor(storage: DurableObjectStorage);
|
|
11
|
+
private queued;
|
|
12
|
+
private executor;
|
|
13
|
+
exec(sql: string): Promise<void>;
|
|
14
|
+
run(sql: string, ...params: SqliteValue[]): Promise<void>;
|
|
15
|
+
get<T extends object>(sql: string, ...params: SqliteValue[]): Promise<T | undefined>;
|
|
16
|
+
all<T extends object>(sql: string, ...params: SqliteValue[]): Promise<T[]>;
|
|
17
|
+
transaction<T>(callback: (transaction: SqliteExecutor) => Promise<T>): Promise<T>;
|
|
18
|
+
close(): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
export declare const openDurableObjectStorage: DurableStorageFactory<DurableObjectStorage>;
|
|
21
|
+
export {};
|
package/dist/tools.d.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { JsonValue } from '@earendil-works/pi-ai';
|
|
2
|
+
import type { ToolRegistration } from '@earendil-works/pi-durable';
|
|
3
|
+
import { type CloudDoErrorCode } from './errors';
|
|
4
|
+
import type { SessionIdentity } from './identity';
|
|
5
|
+
export declare const CLOUD_SAFE_REPLAY_TOOLS: readonly ["load_financial_analysis_skill", "resolve_security", "guarded_screen", "search_f10_datasets", "query_f10_dataset", "get_security_profile", "get_quote_snapshot", "get_corporate_actions", "get_financial_statements", "get_financial_facts", "get_financial_ratios", "get_sdi_disclosures", "get_directorate", "get_ownership", "get_related_warrants"];
|
|
6
|
+
export declare const CLOUD_LIVE_IPO_TOOLS: readonly ["get_ipo_profile", "search_ipo_calendar", "get_ipo_timetable", "get_ipo_offering", "get_ipo_allotment", "screen_ipos", "compare_ipos"];
|
|
7
|
+
export interface CloudToolDefinition {
|
|
8
|
+
readonly name: string;
|
|
9
|
+
readonly description: string;
|
|
10
|
+
readonly parameters: ToolRegistration['parameters'];
|
|
11
|
+
readonly execution: 'read_only_live' | 'skill' | 'scaffold' | 'pure';
|
|
12
|
+
readonly resolverRpc?: string;
|
|
13
|
+
readonly mode?: 'inline' | 'job';
|
|
14
|
+
readonly requiredCapabilities?: readonly string[];
|
|
15
|
+
}
|
|
16
|
+
export interface CloudDispatchContext {
|
|
17
|
+
readonly identity: SessionIdentity;
|
|
18
|
+
readonly principal: {
|
|
19
|
+
readonly accountId: string;
|
|
20
|
+
readonly workspaceId: string;
|
|
21
|
+
readonly channel: string;
|
|
22
|
+
};
|
|
23
|
+
readonly scopes: readonly string[];
|
|
24
|
+
readonly dispatcherId: string;
|
|
25
|
+
readonly call?: {
|
|
26
|
+
readonly invocationId: string;
|
|
27
|
+
readonly conversationId: number;
|
|
28
|
+
readonly toolCallId: string;
|
|
29
|
+
readonly attempt: number;
|
|
30
|
+
};
|
|
31
|
+
/** Session-local lookup can return a non-terminal invocation. */
|
|
32
|
+
readonly lookup?: (invocationId: string) => {
|
|
33
|
+
toolName: string;
|
|
34
|
+
state: string;
|
|
35
|
+
errorCode: string | null;
|
|
36
|
+
resultJson: string | null;
|
|
37
|
+
conversationId: number;
|
|
38
|
+
toolCallId: string;
|
|
39
|
+
settledAt: number | null;
|
|
40
|
+
settledEventSeq: number | null;
|
|
41
|
+
} | undefined;
|
|
42
|
+
}
|
|
43
|
+
/** Runtime calls supply these fields. Configuration remains source compatible. */
|
|
44
|
+
export interface CloudToolCallContext extends CloudDispatchContext {
|
|
45
|
+
readonly call: NonNullable<CloudDispatchContext['call']>;
|
|
46
|
+
readonly lookup: NonNullable<CloudDispatchContext['lookup']>;
|
|
47
|
+
}
|
|
48
|
+
export type CloudToolResult = Record<string, unknown> & {
|
|
49
|
+
modelView?: JsonValue;
|
|
50
|
+
};
|
|
51
|
+
export interface CloudToolDispatcher {
|
|
52
|
+
readonly pureTools?: readonly string[];
|
|
53
|
+
readonly domainErrors?: readonly string[];
|
|
54
|
+
readonly modelViews?: boolean;
|
|
55
|
+
readonly tools: readonly CloudToolDefinition[];
|
|
56
|
+
execute(context: CloudDispatchContext, name: string, args: Record<string, unknown>, signal: AbortSignal): Promise<CloudToolResult>;
|
|
57
|
+
}
|
|
58
|
+
export declare const CLOUD_DOMAIN_ERROR_CODES: Readonly<Record<string, CloudDoErrorCode>>;
|
|
59
|
+
/** Admission does not grant resolver access. The trusted dispatcher checks access at execution. */
|
|
60
|
+
export declare function admitCloudTools(tools: readonly CloudToolDefinition[], pureTools?: readonly string[]): readonly CloudToolDefinition[];
|
|
61
|
+
/** Copy policy values so consumer mutation cannot change an installed policy. */
|
|
62
|
+
export declare function admitCloudDispatcher(dispatcher: CloudToolDispatcher): CloudToolDispatcher;
|
|
63
|
+
export declare function dispatcherDigest(dispatcher: CloudToolDispatcher): Promise<string>;
|
|
64
|
+
/** This policy is stored in the ledger only. Native pi registrations always use unsafe. */
|
|
65
|
+
export declare function replayForTool(name: string): 'safe' | 'unsafe';
|
|
66
|
+
export declare function canonicalArgs(args: Record<string, unknown>): string;
|
|
67
|
+
export declare function invocationId(conversationId: number, assistantEntryId: number, toolCallId: string): Promise<string>;
|
|
68
|
+
export declare function argsDigest(toolName: string, args: Record<string, unknown>): Promise<string>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Conversation, Harness } from '@earendil-works/pi-durable';
|
|
2
|
+
import { type AdmissionIdentity, type InboxRow, type RunHistory } from './cloud-state';
|
|
3
|
+
import { type CloudDoErrorCode } from './errors';
|
|
4
|
+
import { type RunOutcome, type SessionRuntime } from './session-runtime';
|
|
5
|
+
export type CloudWakeAdmission = {
|
|
6
|
+
accepted: true;
|
|
7
|
+
reservation: 'held' | 'none';
|
|
8
|
+
} | {
|
|
9
|
+
accepted: false;
|
|
10
|
+
code: CloudDoErrorCode;
|
|
11
|
+
};
|
|
12
|
+
export type WakeAdmission = (items: readonly InboxRow[], signal: AbortSignal, key: string, admission: AdmissionIdentity) => CloudWakeAdmission | Promise<CloudWakeAdmission>;
|
|
13
|
+
export declare function cloudRunHistory(runtime: SessionRuntime, harness: Harness): Promise<RunHistory[]>;
|
|
14
|
+
export declare function committedRunOutcome(conversation: Conversation, runtime: SessionRuntime, status: string, detail?: unknown): Promise<RunOutcome>;
|
|
15
|
+
/** Each invocation of this function owns a fresh conversation and one shared runtime lease. */
|
|
16
|
+
export declare function runCloudWake(runtime: SessionRuntime, harness: Harness, env: Readonly<Record<string, unknown>>, admit: WakeAdmission, notify: () => void, retryCount?: number): Promise<boolean>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,55 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@byok-sdk/cloud-do",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.24.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"engines": {
|
|
6
|
+
"node": ">=24.15.0"
|
|
7
|
+
},
|
|
8
|
+
"description": "Cloudflare Durable Object session host for native pi-durable storage and execution",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "tsup && tsc -p tsconfig.build.json && node scripts/check-dist.mjs && wrangler deploy --dry-run --outdir dist-worker",
|
|
11
|
+
"typecheck": "tsc --noEmit",
|
|
12
|
+
"test": "vitest run && node --test test/recovery-walltime.node.mjs test/wake-alarm-retry.node.mjs test/wake-events-walltime.node.mjs test/check-dist.node.mjs"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@earendil-works/pi-durable": "1.0.4",
|
|
16
|
+
"@earendil-works/pi-ai": "1.0.4",
|
|
17
|
+
"@earendil-works/chord": "1.0.4"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@byok-sdk/keys": "0.9.0",
|
|
21
|
+
"@cloudflare/workers-types": "5.20260811.1",
|
|
22
|
+
"miniflare": "5.20260811.1-alpha",
|
|
23
|
+
"esbuild": "0.28.1",
|
|
24
|
+
"wrangler": "4.123.0"
|
|
25
|
+
},
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "git+https://github.com/Ancienttwo/byok-sdk.git",
|
|
30
|
+
"directory": "packages/cloud-do"
|
|
31
|
+
},
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/Ancienttwo/byok-sdk/issues"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://github.com/Ancienttwo/byok-sdk#readme",
|
|
36
|
+
"sideEffects": false,
|
|
37
|
+
"main": "./dist/index.js",
|
|
38
|
+
"module": "./dist/index.js",
|
|
39
|
+
"types": "./dist/index.d.ts",
|
|
40
|
+
"exports": {
|
|
41
|
+
".": {
|
|
42
|
+
"types": "./dist/index.d.ts",
|
|
43
|
+
"import": "./dist/index.js"
|
|
44
|
+
},
|
|
45
|
+
"./package.json": "./package.json"
|
|
46
|
+
},
|
|
47
|
+
"files": [
|
|
48
|
+
"dist",
|
|
49
|
+
"README.md",
|
|
50
|
+
"LICENSE"
|
|
51
|
+
],
|
|
52
|
+
"publishConfig": {
|
|
53
|
+
"access": "public"
|
|
54
|
+
}
|
|
55
|
+
}
|