@howaboua/pi-durable-worker-code 0.0.0-stage → 0.9.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 +21 -0
- package/NOTICE +49 -0
- package/README.md +71 -2
- package/dist/QUICKJS-LICENSE +47 -0
- package/dist/execution/src/cell-contract.d.ts +49 -0
- package/dist/execution/src/cell-observation.d.ts +7 -0
- package/dist/execution/src/cell-progress.d.ts +4 -0
- package/dist/execution/src/cell-task.d.ts +17 -0
- package/dist/execution/src/cell-tools.d.ts +8 -0
- package/dist/execution/src/cells.d.ts +14 -0
- package/dist/execution/src/controls.d.ts +3 -0
- package/dist/execution/src/exec-source.d.ts +21 -0
- package/dist/execution/src/forwarded-tools.d.ts +21 -0
- package/dist/execution/src/forwarding-hook.d.ts +6 -0
- package/dist/execution/src/forwarding.d.ts +15 -0
- package/dist/execution/src/history.d.ts +14 -0
- package/dist/execution/src/invocation-state.d.ts +26 -0
- package/dist/execution/src/invocation.d.ts +35 -0
- package/dist/execution/src/native-tools.d.ts +11 -0
- package/dist/execution/src/nested-call.d.ts +26 -0
- package/dist/execution/src/nested-result.d.ts +8 -0
- package/dist/execution/src/nested.d.ts +3 -0
- package/dist/execution/src/output.d.ts +48 -0
- package/dist/execution/src/presentation.d.ts +59 -0
- package/dist/execution/src/progress.d.ts +23 -0
- package/dist/execution/src/projection.d.ts +5 -0
- package/dist/execution/src/tool-contract.d.ts +34 -0
- package/dist/execution/src/tool-origin.d.ts +11 -0
- package/dist/execution/src/tool-value.d.ts +3 -0
- package/dist/execution/src/wait-session.d.ts +6 -0
- package/dist/history.js +315 -0
- package/dist/index.js +2771 -0
- package/dist/presentation.js +201 -0
- package/dist/quickjs.wasm +0 -0
- package/dist/worker-code/src/guest.d.ts +16 -0
- package/dist/worker-code/src/history.d.ts +6 -0
- package/dist/worker-code/src/index.d.ts +47 -0
- package/dist/worker-code/src/interpreter.d.ts +20 -0
- package/dist/worker-code/src/limits.d.ts +20 -0
- package/dist/worker-code/src/modules.d.ts +13 -0
- package/dist/worker-code/src/output.d.ts +6 -0
- package/dist/worker-code/src/presentation.d.ts +22 -0
- package/dist/worker-code/src/runtime.d.ts +17 -0
- package/dist/worker-code/src/tool-result.d.ts +3 -0
- package/package.json +50 -5
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
// packages/execution/src/presentation.ts
|
|
2
|
+
function object(value) {
|
|
3
|
+
if (!value || typeof value !== "object" || Array.isArray(value) || Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null)
|
|
4
|
+
throw new TypeError("Expected execution presentation object");
|
|
5
|
+
return value;
|
|
6
|
+
}
|
|
7
|
+
function string(value) {
|
|
8
|
+
if (typeof value !== "string")
|
|
9
|
+
throw new TypeError("Expected string");
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
function json(value, ancestors = new Set) {
|
|
13
|
+
if (value === null || typeof value === "string" || typeof value === "boolean")
|
|
14
|
+
return value;
|
|
15
|
+
if (typeof value === "number" && Number.isFinite(value))
|
|
16
|
+
return value;
|
|
17
|
+
if (typeof value !== "object" || ancestors.has(value))
|
|
18
|
+
throw new TypeError("Expected finite, acyclic JSON details");
|
|
19
|
+
ancestors.add(value);
|
|
20
|
+
try {
|
|
21
|
+
if (!Array.isArray(value))
|
|
22
|
+
object(value);
|
|
23
|
+
return Array.isArray(value) ? value.map((item) => json(item, ancestors)) : Object.fromEntries(Object.entries(value).map(([key, item]) => [
|
|
24
|
+
key,
|
|
25
|
+
json(item, ancestors)
|
|
26
|
+
]));
|
|
27
|
+
} finally {
|
|
28
|
+
ancestors.delete(value);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function cell(value) {
|
|
32
|
+
if (value === null)
|
|
33
|
+
return null;
|
|
34
|
+
const fields = object(value);
|
|
35
|
+
const id = string(fields["id"]);
|
|
36
|
+
if (!/^[1-9][0-9]*$/.test(id) || !Number.isSafeInteger(Number(id)))
|
|
37
|
+
throw new TypeError("Invalid execution cell ID");
|
|
38
|
+
const status = fields["status"];
|
|
39
|
+
if (status !== "running" && status !== "completed" && status !== "failed" && status !== "aborted" && status !== "interrupted")
|
|
40
|
+
throw new TypeError("Invalid execution cell status");
|
|
41
|
+
return { id, status };
|
|
42
|
+
}
|
|
43
|
+
function parseExecutionResultReceipt(value) {
|
|
44
|
+
if (value === null)
|
|
45
|
+
return null;
|
|
46
|
+
const fields = object(value);
|
|
47
|
+
const content = fields["content"] === undefined ? [] : fields["content"];
|
|
48
|
+
const diagnostics = fields["diagnostics"] === undefined ? [] : fields["diagnostics"];
|
|
49
|
+
const isError = fields["isError"] === undefined ? false : fields["isError"];
|
|
50
|
+
if (!Array.isArray(content) || !Array.isArray(diagnostics) || typeof isError !== "boolean")
|
|
51
|
+
throw new TypeError("Invalid execution result receipt");
|
|
52
|
+
return {
|
|
53
|
+
content: content.map((value) => {
|
|
54
|
+
const item = object(value);
|
|
55
|
+
if (item["type"] === "text")
|
|
56
|
+
return { type: "text", text: string(item["text"]) };
|
|
57
|
+
if (item["type"] === "image") {
|
|
58
|
+
const mimeType = string(item["mimeType"]);
|
|
59
|
+
const data = string(item["data"]);
|
|
60
|
+
if (!/^image\/[A-Za-z0-9][A-Za-z0-9.+-]*$/.test(mimeType) || data.length % 4 !== 0 || !/^[A-Za-z0-9+/]*={0,2}$/.test(data))
|
|
61
|
+
throw new TypeError("Invalid execution image");
|
|
62
|
+
return { type: "image", data, mimeType };
|
|
63
|
+
}
|
|
64
|
+
throw new TypeError("Invalid execution content type");
|
|
65
|
+
}),
|
|
66
|
+
isError,
|
|
67
|
+
details: json(fields["details"] ?? null),
|
|
68
|
+
diagnostics: diagnostics.map((value) => {
|
|
69
|
+
const item = object(value);
|
|
70
|
+
const severity = item["severity"];
|
|
71
|
+
if (severity !== "info" && severity !== "warn" && severity !== "error")
|
|
72
|
+
throw new TypeError("Invalid execution diagnostic severity");
|
|
73
|
+
return {
|
|
74
|
+
severity,
|
|
75
|
+
message: string(item["message"]),
|
|
76
|
+
...item["code"] === undefined ? {} : { code: string(item["code"]) }
|
|
77
|
+
};
|
|
78
|
+
})
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function parseExecutionPresentationState(value) {
|
|
82
|
+
const fields = object(value);
|
|
83
|
+
return {
|
|
84
|
+
cell: cell(fields["cell"]),
|
|
85
|
+
result: parseExecutionResultReceipt(fields["result"])
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function executionCapability(id, actions) {
|
|
89
|
+
return {
|
|
90
|
+
id,
|
|
91
|
+
version: 1,
|
|
92
|
+
actions,
|
|
93
|
+
streams: ["results"],
|
|
94
|
+
presentations: ["summary", "detail"],
|
|
95
|
+
parseState: parseExecutionPresentationState
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
function executionSummary(title) {
|
|
99
|
+
return {
|
|
100
|
+
id: "summary",
|
|
101
|
+
select: (state) => ({
|
|
102
|
+
title,
|
|
103
|
+
cell: state.cell,
|
|
104
|
+
hasResult: state.result !== null,
|
|
105
|
+
isError: state.result?.isError ?? null
|
|
106
|
+
}),
|
|
107
|
+
requests: ["detail"]
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
var executionDetail = {
|
|
111
|
+
id: "detail",
|
|
112
|
+
select: (state) => state,
|
|
113
|
+
requests: []
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
// packages/execution/src/forwarded-tools.ts
|
|
117
|
+
function object2(value) {
|
|
118
|
+
if (!value || typeof value !== "object" || Array.isArray(value) || Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null)
|
|
119
|
+
throw new TypeError("Invalid forwarded tool calls object");
|
|
120
|
+
return value;
|
|
121
|
+
}
|
|
122
|
+
function string2(value) {
|
|
123
|
+
if (typeof value !== "string" || !value)
|
|
124
|
+
throw new TypeError("Invalid forwarded tool identity");
|
|
125
|
+
return value;
|
|
126
|
+
}
|
|
127
|
+
function json2(value, ancestors = new Set) {
|
|
128
|
+
if (value === null || typeof value === "string" || typeof value === "boolean")
|
|
129
|
+
return value;
|
|
130
|
+
if (typeof value === "number" && Number.isFinite(value))
|
|
131
|
+
return value;
|
|
132
|
+
if (!value || typeof value !== "object" || ancestors.has(value))
|
|
133
|
+
throw new TypeError("Invalid forwarded tool JSON");
|
|
134
|
+
ancestors.add(value);
|
|
135
|
+
try {
|
|
136
|
+
return Array.isArray(value) ? value.map((item) => json2(item, ancestors)) : Object.fromEntries(Object.entries(object2(value)).map(([key, item]) => [
|
|
137
|
+
key,
|
|
138
|
+
json2(item, ancestors)
|
|
139
|
+
]));
|
|
140
|
+
} finally {
|
|
141
|
+
ancestors.delete(value);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function parseForwardedToolCalls(details) {
|
|
145
|
+
if (!details || typeof details !== "object" || !("forwardedToolCalls" in details))
|
|
146
|
+
return null;
|
|
147
|
+
const fields = object2(details.forwardedToolCalls);
|
|
148
|
+
if (fields["version"] !== 1)
|
|
149
|
+
throw new TypeError("Unsupported forwarded tool calls version");
|
|
150
|
+
const cellId = string2(fields["cellId"]);
|
|
151
|
+
if (!/^[1-9][0-9]*$/.test(cellId) || !Number.isSafeInteger(Number(cellId)))
|
|
152
|
+
throw new TypeError("Invalid forwarded cell ID");
|
|
153
|
+
const omittedCalls = fields["omittedCalls"];
|
|
154
|
+
if (typeof omittedCalls !== "number" || !Number.isSafeInteger(omittedCalls) || omittedCalls < 0 || !Array.isArray(fields["calls"]))
|
|
155
|
+
throw new TypeError("Invalid forwarded tool call list");
|
|
156
|
+
const ids = new Set;
|
|
157
|
+
const calls = fields["calls"].map((value) => {
|
|
158
|
+
const call = object2(value);
|
|
159
|
+
const callId = string2(call["callId"]);
|
|
160
|
+
if (ids.has(callId))
|
|
161
|
+
throw new TypeError("Duplicate forwarded tool call ID");
|
|
162
|
+
ids.add(callId);
|
|
163
|
+
const status = call["status"];
|
|
164
|
+
if (status !== "pending" && status !== "running" && status !== "completed" && status !== "failed" && status !== "aborted" && status !== "interrupted")
|
|
165
|
+
throw new TypeError("Invalid forwarded tool status");
|
|
166
|
+
const omitted = call["omittedFields"];
|
|
167
|
+
if (!Array.isArray(omitted) || omitted.some((field) => field !== "arguments" && field !== "result") || new Set(omitted).size !== omitted.length)
|
|
168
|
+
throw new TypeError("Invalid forwarded omitted fields");
|
|
169
|
+
const omittedFields = omitted.map((field) => {
|
|
170
|
+
if (field === "arguments" || field === "result")
|
|
171
|
+
return field;
|
|
172
|
+
throw new TypeError("Invalid forwarded omitted field");
|
|
173
|
+
});
|
|
174
|
+
if (!("arguments" in call) !== omittedFields.includes("arguments") || omittedFields.includes("result") && call["result"] !== null)
|
|
175
|
+
throw new TypeError("Inconsistent forwarded omitted fields");
|
|
176
|
+
return {
|
|
177
|
+
callId,
|
|
178
|
+
parentCallId: string2(call["parentCallId"]),
|
|
179
|
+
name: string2(call["name"]),
|
|
180
|
+
...omittedFields.includes("arguments") ? {} : { arguments: json2(call["arguments"]) },
|
|
181
|
+
status,
|
|
182
|
+
result: parseExecutionResultReceipt(json2(call["result"])),
|
|
183
|
+
omittedFields
|
|
184
|
+
};
|
|
185
|
+
});
|
|
186
|
+
return { version: 1, cellId, calls, omittedCalls };
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// packages/worker-code/src/presentation.ts
|
|
190
|
+
var workerCodeCapability = executionCapability("worker-code", [
|
|
191
|
+
"exec",
|
|
192
|
+
"wait"
|
|
193
|
+
]);
|
|
194
|
+
var workerCodeSummary = executionSummary("Worker Code");
|
|
195
|
+
var workerCodeDetail = executionDetail;
|
|
196
|
+
export {
|
|
197
|
+
parseForwardedToolCalls,
|
|
198
|
+
workerCodeCapability,
|
|
199
|
+
workerCodeDetail,
|
|
200
|
+
workerCodeSummary
|
|
201
|
+
};
|
|
Binary file
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { JsonValue } from "@earendil-works/chord";
|
|
2
|
+
import { type WorkerCodeLimits } from "./limits.ts";
|
|
3
|
+
export interface GuestCapabilities {
|
|
4
|
+
readonly inventory?: JsonValue;
|
|
5
|
+
readonly tools?: Readonly<Record<string, (args: JsonValue, signal: AbortSignal) => Promise<unknown>>>;
|
|
6
|
+
readonly emit?: (kind: "text" | "image", value: JsonValue) => Promise<void>;
|
|
7
|
+
readonly yield?: () => Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
export interface GuestResult {
|
|
10
|
+
value: JsonValue;
|
|
11
|
+
polls: number;
|
|
12
|
+
jobs: number;
|
|
13
|
+
calls: number;
|
|
14
|
+
}
|
|
15
|
+
/** Deferred promises permit concurrent ordinary tools without Asyncify suspension limits. */
|
|
16
|
+
export declare function runGuest(wasm: WebAssembly.Module, code: string, sources: ReadonlyMap<string, string>, limits: Readonly<WorkerCodeLimits>, signal: AbortSignal, capabilities?: GuestCapabilities): Promise<GuestResult>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type { ExecutionHistoryRequest } from "../../execution/src/history.ts";
|
|
2
|
+
export declare const readForwardedToolCalls: (harness: {
|
|
3
|
+
conversation: (id: import("@earendil-works/pi-durable").ConversationId, context: import("@earendil-works/chord").Context) => Promise<import("@earendil-works/pi-durable").Conversation | undefined>;
|
|
4
|
+
getTask: <R>(id: import("@earendil-works/pi-durable").TaskId<R>, context: import("@earendil-works/chord").Context) => Promise<import("@earendil-works/pi-durable").TaskRecord<import("@earendil-works/chord").JsonValue, import("@earendil-works/chord").JsonValue, R> | undefined>;
|
|
5
|
+
commit: <T>(change: (tx: import("@earendil-works/pi-durable").Tx) => T | Promise<T>, context: import("@earendil-works/chord").Context) => Promise<T>;
|
|
6
|
+
}, request: import("../../execution/src/history.ts").ExecutionHistoryRequest, context: import("@earendil-works/chord").Context) => Promise<ReadonlyMap<string, import("./presentation.ts").ForwardedToolCalls>>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type Context } from "@earendil-works/chord";
|
|
2
|
+
import { type ToolExecutionApi, type ToolExecutionResult } from "@earendil-works/pi-durable";
|
|
3
|
+
import { Type } from "typebox";
|
|
4
|
+
import { type CellCoordinatorOptions } from "../../execution/src/cell-contract.ts";
|
|
5
|
+
import { interpreterBudget, WORKER_CODE_ISOLATE_BUDGET } from "./interpreter.ts";
|
|
6
|
+
import { type WorkerCodeLimits } from "./limits.ts";
|
|
7
|
+
import { type WorkerModuleRequest } from "./modules.ts";
|
|
8
|
+
export type { WorkerCodeLimits } from "./limits.ts";
|
|
9
|
+
export { DEFAULT_WORKER_CODE_LIMITS } from "./limits.ts";
|
|
10
|
+
export type { WorkerModuleRequest } from "./modules.ts";
|
|
11
|
+
export { WORKER_CODE_ISOLATE_BUDGET };
|
|
12
|
+
export interface WorkerCodeOptions {
|
|
13
|
+
/** Static compiled QuickJS 0.32.0 release-sync WASM, injected by the host bundler. */
|
|
14
|
+
readonly wasmModule: WebAssembly.Module;
|
|
15
|
+
readonly cancelTask: CellCoordinatorOptions["cancelTask"];
|
|
16
|
+
readonly limits?: Partial<WorkerCodeLimits>;
|
|
17
|
+
readonly modules?: Readonly<Record<string, string>> | (() => Readonly<Record<string, string>>);
|
|
18
|
+
}
|
|
19
|
+
/** Worker-native execution. Never imports shell, native Code, or host filesystem drivers. */
|
|
20
|
+
export declare function createWorkerCode(options: WorkerCodeOptions): {
|
|
21
|
+
extension: {
|
|
22
|
+
name: string;
|
|
23
|
+
hooks?: readonly import("@earendil-works/pi-durable").HookRegistration[];
|
|
24
|
+
wraps?: readonly import("@earendil-works/pi-durable").Wrap<import("@earendil-works/pi-durable").ToolRegistration>[];
|
|
25
|
+
tasks?: readonly import("@earendil-works/pi-durable").AnyTask[];
|
|
26
|
+
tools: (import("@earendil-works/pi-durable").ToolRegistration<Type.TObject<{
|
|
27
|
+
code: Type.TString;
|
|
28
|
+
}>, import("@earendil-works/chord").JsonValue> | import("@earendil-works/pi-durable").ToolRegistration<Type.TObject<{
|
|
29
|
+
cell_id: Type.TString;
|
|
30
|
+
yield_time_ms: Type.TOptional<Type.TInteger>;
|
|
31
|
+
max_tokens: Type.TOptional<Type.TInteger>;
|
|
32
|
+
terminate: Type.TOptional<Type.TBoolean>;
|
|
33
|
+
}>, import("@earendil-works/chord").JsonValue>)[];
|
|
34
|
+
sections: import("@earendil-works/pi-durable").PromptSection<import("@earendil-works/pi-durable").ToolRegistration>[];
|
|
35
|
+
};
|
|
36
|
+
/** Bind the owning Harness before execution to retain native nested display receipts. */
|
|
37
|
+
bind: (harness: Pick<import("@earendil-works/pi-durable").Harness, "conversation">) => void;
|
|
38
|
+
budget: typeof interpreterBudget;
|
|
39
|
+
evaluateModule(request: WorkerModuleRequest, invocation?: {
|
|
40
|
+
readonly signal?: AbortSignal;
|
|
41
|
+
}): Promise<import("@earendil-works/chord").JsonValue>;
|
|
42
|
+
/** Reuse the cell dispatcher under the CURRENT ordinary tool task, not another cell. */
|
|
43
|
+
executeToolModule(request: WorkerModuleRequest, api: ToolExecutionApi, context: Context, grants?: {
|
|
44
|
+
readonly allowedTools?: readonly string[];
|
|
45
|
+
}): Promise<ToolExecutionResult>;
|
|
46
|
+
close(): Promise<void>;
|
|
47
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type QuickJSRuntime } from "quickjs-emscripten";
|
|
2
|
+
export declare const WORKER_CODE_ISOLATE_BUDGET: Readonly<{
|
|
3
|
+
maxRuntimes: 4;
|
|
4
|
+
maxReservedHeapBytes: number;
|
|
5
|
+
initialWasmBytes: number;
|
|
6
|
+
maxWasmBytes: number;
|
|
7
|
+
}>;
|
|
8
|
+
export declare function admitRuntime(wasm: WebAssembly.Module, heapBytes: number, signal: AbortSignal): Promise<{
|
|
9
|
+
runtime: QuickJSRuntime;
|
|
10
|
+
release(): void;
|
|
11
|
+
}>;
|
|
12
|
+
export declare function interpreterBudget(): {
|
|
13
|
+
maxRuntimes: 4;
|
|
14
|
+
maxReservedHeapBytes: number;
|
|
15
|
+
initialWasmBytes: number;
|
|
16
|
+
maxWasmBytes: number;
|
|
17
|
+
activeRuntimes: number;
|
|
18
|
+
reservedHeapBytes: number;
|
|
19
|
+
wasmMemoryBytes: number;
|
|
20
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Trusted host limits. Guests cannot raise them through exec or module arguments. */
|
|
2
|
+
export interface WorkerCodeLimits {
|
|
3
|
+
heapBytes: number;
|
|
4
|
+
stackBytes: number;
|
|
5
|
+
fuel: number;
|
|
6
|
+
maxJobs: number;
|
|
7
|
+
maxCalls: number;
|
|
8
|
+
maxPendingCalls: number;
|
|
9
|
+
maxSourceBytes: number;
|
|
10
|
+
maxModuleBytes: number;
|
|
11
|
+
maxModules: number;
|
|
12
|
+
maxArgumentBytes: number;
|
|
13
|
+
maxResultBytes: number;
|
|
14
|
+
maxOutputBytes: number;
|
|
15
|
+
waitMs: number;
|
|
16
|
+
}
|
|
17
|
+
export declare const DEFAULT_WORKER_CODE_LIMITS: Readonly<WorkerCodeLimits>;
|
|
18
|
+
export declare function workerLimits(input?: Partial<WorkerCodeLimits>): Readonly<WorkerCodeLimits>;
|
|
19
|
+
export declare function boundedString(value: string, maxBytes: number, label: string): string;
|
|
20
|
+
export declare function boundedJson(value: unknown, maxBytes: number, label: string): string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { JsonValue } from "@earendil-works/chord";
|
|
2
|
+
import { type WorkerCodeLimits } from "./limits.ts";
|
|
3
|
+
export interface WorkerModuleRequest {
|
|
4
|
+
readonly modules: Readonly<Record<string, string>>;
|
|
5
|
+
readonly entry: string;
|
|
6
|
+
readonly exportName: string;
|
|
7
|
+
/** Present to call the export as a function. Omit to read a JSON data export. */
|
|
8
|
+
readonly args?: JsonValue;
|
|
9
|
+
}
|
|
10
|
+
/** Absolute virtual names only. Relative imports cannot escape the snapshot root. */
|
|
11
|
+
export declare function resolveModule(base: string, name: string): string;
|
|
12
|
+
export declare function moduleSnapshot(input: Readonly<Record<string, string>>, limits: Readonly<WorkerCodeLimits>): ReadonlyMap<string, string>;
|
|
13
|
+
export declare function moduleCode(request: WorkerModuleRequest, limits: Readonly<WorkerCodeLimits>, invoke: boolean): string;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type JsonValue } from "@earendil-works/chord";
|
|
2
|
+
import type { ToolExecutionResult } from "@earendil-works/pi-durable";
|
|
3
|
+
import type { CellObservation } from "../../execution/src/cell-contract.ts";
|
|
4
|
+
export declare function guestContent(kind: "text" | "image", value: JsonValue): NonNullable<ToolExecutionResult["output"]>[number];
|
|
5
|
+
/** Bound each observation separately, without repeating the same running revision. */
|
|
6
|
+
export declare function observeWorkerCell(observation: CellObservation, maxTokens: number, delivered: Map<number, number>): ToolExecutionResult;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type { ForwardedToolCall, ForwardedToolCalls, ForwardedToolStatus, } from "../../execution/src/forwarded-tools.ts";
|
|
2
|
+
export { parseForwardedToolCalls } from "../../execution/src/forwarded-tools.ts";
|
|
3
|
+
export type { ExecutionCellReference, ExecutionCellStatus, ExecutionPresentationState as WorkerCodePresentationState, ExecutionResultReceipt, ExecutionSummaryModel, } from "../../execution/src/presentation.ts";
|
|
4
|
+
/** Host binds ordinary registrations and publishes acquired observations on results. */
|
|
5
|
+
export declare const workerCodeCapability: {
|
|
6
|
+
id: string;
|
|
7
|
+
version: number;
|
|
8
|
+
actions: readonly string[];
|
|
9
|
+
streams: readonly ["results"];
|
|
10
|
+
presentations: readonly ["summary", "detail"];
|
|
11
|
+
parseState: (value: import("../../execution/src/presentation.ts").JsonValue) => import("../../execution/src/presentation.ts").ExecutionPresentationState;
|
|
12
|
+
};
|
|
13
|
+
export declare const workerCodeSummary: {
|
|
14
|
+
id: string;
|
|
15
|
+
select: (state: import("../../execution/src/presentation.ts").ExecutionPresentationState) => import("../../execution/src/presentation.ts").ExecutionSummaryModel;
|
|
16
|
+
requests: readonly ["detail"];
|
|
17
|
+
};
|
|
18
|
+
export declare const workerCodeDetail: {
|
|
19
|
+
id: string;
|
|
20
|
+
select: (state: import("../../execution/src/presentation.ts").ExecutionPresentationState) => import("../../execution/src/presentation.ts").ExecutionPresentationState;
|
|
21
|
+
requests: readonly [];
|
|
22
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type Context, type JsonValue } from "@earendil-works/chord";
|
|
2
|
+
import type { ToolExecutionResult } from "@earendil-works/pi-durable";
|
|
3
|
+
import type { CellEngine, CellEngineApi } from "../../execution/src/cell-contract.ts";
|
|
4
|
+
import { type GuestCapabilities } from "./guest.ts";
|
|
5
|
+
import { type WorkerCodeLimits } from "./limits.ts";
|
|
6
|
+
/** Own all admitted guests, including pure modules and ordinary tool-owned handlers. */
|
|
7
|
+
export declare class WorkerRuntime implements CellEngine {
|
|
8
|
+
private closed;
|
|
9
|
+
private readonly active;
|
|
10
|
+
private readonly wasm;
|
|
11
|
+
readonly limits: Readonly<WorkerCodeLimits>;
|
|
12
|
+
private readonly modules;
|
|
13
|
+
constructor(wasm: WebAssembly.Module, limits: Readonly<WorkerCodeLimits>, modules: () => ReadonlyMap<string, string>);
|
|
14
|
+
evaluate(code: string, modules: ReadonlyMap<string, string>, signal?: AbortSignal, capabilities?: GuestCapabilities): Promise<import("./guest.ts").GuestResult>;
|
|
15
|
+
run(input: Record<string, JsonValue>, api: CellEngineApi, context: Context): Promise<ToolExecutionResult>;
|
|
16
|
+
close(): Promise<void>;
|
|
17
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,51 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@howaboua/pi-durable-worker-code",
|
|
3
|
+
"version": "0.9.1",
|
|
4
|
+
"description": "Bounded Worker-native JavaScript execution for Pi Durable",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/IgorWarzocha/pi-durable-components.git",
|
|
10
|
+
"directory": "packages/worker-code"
|
|
11
|
+
},
|
|
12
|
+
"author": "Igor Warzocha",
|
|
13
|
+
"main": "./dist/index.js",
|
|
14
|
+
"types": "./dist/worker-code/src/index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
"./history": {
|
|
17
|
+
"types": "./dist/worker-code/src/history.d.ts",
|
|
18
|
+
"import": "./dist/history.js"
|
|
19
|
+
},
|
|
20
|
+
"./presentation": {
|
|
21
|
+
"types": "./dist/worker-code/src/presentation.d.ts",
|
|
22
|
+
"import": "./dist/presentation.js"
|
|
23
|
+
},
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/worker-code/src/index.d.ts",
|
|
26
|
+
"import": "./dist/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./quickjs.wasm": "./dist/quickjs.wasm"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"dist",
|
|
32
|
+
"README.md",
|
|
33
|
+
"NOTICE",
|
|
34
|
+
"LICENSE"
|
|
35
|
+
],
|
|
36
|
+
"sideEffects": false,
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@jitl/quickjs-wasmfile-release-sync": "0.32.0",
|
|
39
|
+
"quickjs-emscripten": "0.32.0",
|
|
40
|
+
"typebox": "1.3.27"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"@earendil-works/chord": "1.4.0",
|
|
44
|
+
"@earendil-works/pi-ai": "1.4.0",
|
|
45
|
+
"@earendil-works/pi-durable": "1.4.0",
|
|
46
|
+
"@modelcontextprotocol/sdk": "1.25.2"
|
|
47
|
+
},
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public"
|
|
50
|
+
}
|
|
51
|
+
}
|