@unicity-astrid/sdk 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/README.md +120 -0
- package/dist/approval.d.ts +23 -0
- package/dist/approval.d.ts.map +1 -0
- package/dist/approval.js +29 -0
- package/dist/approval.js.map +1 -0
- package/dist/capabilities.d.ts +14 -0
- package/dist/capabilities.d.ts.map +1 -0
- package/dist/capabilities.js +19 -0
- package/dist/capabilities.js.map +1 -0
- package/dist/capsule.d.ts +39 -0
- package/dist/capsule.d.ts.map +1 -0
- package/dist/capsule.js +67 -0
- package/dist/capsule.js.map +1 -0
- package/dist/contracts.d.ts +1104 -0
- package/dist/contracts.d.ts.map +1 -0
- package/dist/contracts.js +4 -0
- package/dist/contracts.js.map +1 -0
- package/dist/elicit.d.ts +30 -0
- package/dist/elicit.d.ts.map +1 -0
- package/dist/elicit.js +103 -0
- package/dist/elicit.js.map +1 -0
- package/dist/env.d.ts +19 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +27 -0
- package/dist/env.js.map +1 -0
- package/dist/errors.d.ts +46 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +108 -0
- package/dist/errors.js.map +1 -0
- package/dist/fs.d.ts +135 -0
- package/dist/fs.d.ts.map +1 -0
- package/dist/fs.js +257 -0
- package/dist/fs.js.map +1 -0
- package/dist/http.d.ts +90 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +276 -0
- package/dist/http.js.map +1 -0
- package/dist/identity.d.ts +46 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +69 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/interceptors.d.ts +21 -0
- package/dist/interceptors.d.ts.map +1 -0
- package/dist/interceptors.js +22 -0
- package/dist/interceptors.js.map +1 -0
- package/dist/ipc.d.ts +143 -0
- package/dist/ipc.d.ts.map +1 -0
- package/dist/ipc.js +261 -0
- package/dist/ipc.js.map +1 -0
- package/dist/kv.d.ts +45 -0
- package/dist/kv.d.ts.map +1 -0
- package/dist/kv.js +91 -0
- package/dist/kv.js.map +1 -0
- package/dist/log.d.ts +17 -0
- package/dist/log.d.ts.map +1 -0
- package/dist/log.js +40 -0
- package/dist/log.js.map +1 -0
- package/dist/net.d.ts +154 -0
- package/dist/net.d.ts.map +1 -0
- package/dist/net.js +421 -0
- package/dist/net.js.map +1 -0
- package/dist/process.d.ts +77 -0
- package/dist/process.d.ts.map +1 -0
- package/dist/process.js +128 -0
- package/dist/process.js.map +1 -0
- package/dist/runtime/bridge.d.ts +34 -0
- package/dist/runtime/bridge.d.ts.map +1 -0
- package/dist/runtime/bridge.js +326 -0
- package/dist/runtime/bridge.js.map +1 -0
- package/dist/runtime/index.d.ts +3 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +3 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/registry.d.ts +58 -0
- package/dist/runtime/registry.d.ts.map +1 -0
- package/dist/runtime/registry.js +129 -0
- package/dist/runtime/registry.js.map +1 -0
- package/dist/runtime.d.ts +36 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +50 -0
- package/dist/runtime.js.map +1 -0
- package/dist/time.d.ts +29 -0
- package/dist/time.d.ts.map +1 -0
- package/dist/time.js +43 -0
- package/dist/time.js.map +1 -0
- package/dist/tool.d.ts +48 -0
- package/dist/tool.d.ts.map +1 -0
- package/dist/tool.js +86 -0
- package/dist/tool.js.map +1 -0
- package/dist/uplink.d.ts +27 -0
- package/dist/uplink.d.ts.map +1 -0
- package/dist/uplink.js +36 -0
- package/dist/uplink.js.map +1 -0
- package/package.json +38 -0
- package/src/approval.ts +38 -0
- package/src/capabilities.ts +22 -0
- package/src/capsule.ts +90 -0
- package/src/contracts.ts +1189 -0
- package/src/elicit.ts +136 -0
- package/src/env.ts +31 -0
- package/src/errors.ts +122 -0
- package/src/fs.ts +357 -0
- package/src/http.ts +345 -0
- package/src/identity.ts +101 -0
- package/src/index.ts +83 -0
- package/src/interceptors.ts +25 -0
- package/src/ipc.ts +354 -0
- package/src/kv.ts +123 -0
- package/src/log.ts +43 -0
- package/src/net.ts +545 -0
- package/src/process.ts +205 -0
- package/src/runtime/bridge.ts +374 -0
- package/src/runtime/index.ts +11 -0
- package/src/runtime/registry.ts +178 -0
- package/src/runtime.ts +70 -0
- package/src/time.ts +48 -0
- package/src/tool.ts +125 -0
- package/src/uplink.ts +49 -0
- package/src/wit-imports.d.ts +689 -0
- package/wit-contracts/astrid-contracts.wit +1266 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bridge runtime — implements the four WIT guest exports
|
|
3
|
+
* (`astrid-hook-trigger`, `run`, `astrid-install`, `astrid-upgrade`) on top
|
|
4
|
+
* of the registry the decorators populated.
|
|
5
|
+
*
|
|
6
|
+
* The Rust SDK's `#[capsule]` macro generates this same logic at compile
|
|
7
|
+
* time. We do it at runtime: walk the registry, dispatch the action,
|
|
8
|
+
* load/save state for mutable handlers, publish results to IPC, and
|
|
9
|
+
* produce the `capsule-result` the kernel expects.
|
|
10
|
+
*
|
|
11
|
+
* Dispatch table mirrors `sdk-rust/astrid-sdk-macros/src/lib.rs:600–660`:
|
|
12
|
+
* - `tool_describe`: aggregate schemas + descriptions, return as `data`.
|
|
13
|
+
* Built lazily on first invocation, cached thereafter.
|
|
14
|
+
* - `tool_execute_<name>`: parse `ToolExecuteRequest`, optionally load
|
|
15
|
+
* state, run handler, publish result to `tool.v1.execute.<name>.result`,
|
|
16
|
+
* optionally save state, return `{ action: "continue", data: undefined }`.
|
|
17
|
+
* - any other action: check the interceptors map THEN the commands map.
|
|
18
|
+
* Their results flow back via `capsule-result.data` directly (no IPC
|
|
19
|
+
* publish), matching the Rust macro's behaviour for these paths.
|
|
20
|
+
*
|
|
21
|
+
* State key matches Rust: `__state`, JSON-encoded.
|
|
22
|
+
*/
|
|
23
|
+
export interface CapsuleResult {
|
|
24
|
+
action: string;
|
|
25
|
+
data: string | undefined;
|
|
26
|
+
}
|
|
27
|
+
export interface Bridge {
|
|
28
|
+
astridHookTrigger(action: string, payload: Uint8Array): CapsuleResult;
|
|
29
|
+
run(): void;
|
|
30
|
+
astridInstall(): void;
|
|
31
|
+
astridUpgrade(): void;
|
|
32
|
+
}
|
|
33
|
+
export declare function createBridge(): Bridge;
|
|
34
|
+
//# sourceMappingURL=bridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../../src/runtime/bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAgBH,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1B;AAED,MAAM,WAAW,MAAM;IACrB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,GAAG,aAAa,CAAC;IACtE,GAAG,IAAI,IAAI,CAAC;IACZ,aAAa,IAAI,IAAI,CAAC;IACtB,aAAa,IAAI,IAAI,CAAC;CACvB;AAkBD,wBAAgB,YAAY,IAAI,MAAM,CAyNrC"}
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bridge runtime — implements the four WIT guest exports
|
|
3
|
+
* (`astrid-hook-trigger`, `run`, `astrid-install`, `astrid-upgrade`) on top
|
|
4
|
+
* of the registry the decorators populated.
|
|
5
|
+
*
|
|
6
|
+
* The Rust SDK's `#[capsule]` macro generates this same logic at compile
|
|
7
|
+
* time. We do it at runtime: walk the registry, dispatch the action,
|
|
8
|
+
* load/save state for mutable handlers, publish results to IPC, and
|
|
9
|
+
* produce the `capsule-result` the kernel expects.
|
|
10
|
+
*
|
|
11
|
+
* Dispatch table mirrors `sdk-rust/astrid-sdk-macros/src/lib.rs:600–660`:
|
|
12
|
+
* - `tool_describe`: aggregate schemas + descriptions, return as `data`.
|
|
13
|
+
* Built lazily on first invocation, cached thereafter.
|
|
14
|
+
* - `tool_execute_<name>`: parse `ToolExecuteRequest`, optionally load
|
|
15
|
+
* state, run handler, publish result to `tool.v1.execute.<name>.result`,
|
|
16
|
+
* optionally save state, return `{ action: "continue", data: undefined }`.
|
|
17
|
+
* - any other action: check the interceptors map THEN the commands map.
|
|
18
|
+
* Their results flow back via `capsule-result.data` directly (no IPC
|
|
19
|
+
* publish), matching the Rust macro's behaviour for these paths.
|
|
20
|
+
*
|
|
21
|
+
* State key matches Rust: `__state`, JSON-encoded.
|
|
22
|
+
*/
|
|
23
|
+
import { getRegistration, } from "./registry.js";
|
|
24
|
+
import * as kv from "../kv.js";
|
|
25
|
+
import * as ipc from "../ipc.js";
|
|
26
|
+
import * as log from "../log.js";
|
|
27
|
+
import { getConfig } from "astrid:sys/host@1.0.0";
|
|
28
|
+
const STATE_KEY = "__state";
|
|
29
|
+
const decoder = new TextDecoder();
|
|
30
|
+
function denied(reason) {
|
|
31
|
+
return { action: "deny", data: reason };
|
|
32
|
+
}
|
|
33
|
+
function cont(data) {
|
|
34
|
+
return { action: "continue", data };
|
|
35
|
+
}
|
|
36
|
+
export function createBridge() {
|
|
37
|
+
let toolDescribeCache;
|
|
38
|
+
function reg() {
|
|
39
|
+
const r = getRegistration();
|
|
40
|
+
if (r === undefined) {
|
|
41
|
+
throw new Error("No @capsule class registered. The build pipeline emits the entry " +
|
|
42
|
+
"module after the user's source so decorators have already fired — " +
|
|
43
|
+
"this means the user code never imported the SDK or never declared " +
|
|
44
|
+
"a @capsule class.");
|
|
45
|
+
}
|
|
46
|
+
return r;
|
|
47
|
+
}
|
|
48
|
+
function buildToolDescribe() {
|
|
49
|
+
const r = reg();
|
|
50
|
+
const tools = Array.from(r.tools.values()).map(toolToDescribeEntry);
|
|
51
|
+
return JSON.stringify({
|
|
52
|
+
tools,
|
|
53
|
+
description: r.description ?? "",
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
function loadInstance(r) {
|
|
57
|
+
const instance = new r.ctor();
|
|
58
|
+
const persisted = kv.get(STATE_KEY);
|
|
59
|
+
if (persisted !== undefined && typeof persisted === "object" && persisted !== null) {
|
|
60
|
+
Object.assign(instance, persisted);
|
|
61
|
+
}
|
|
62
|
+
return instance;
|
|
63
|
+
}
|
|
64
|
+
function persistInstance(instance) {
|
|
65
|
+
const snapshot = {};
|
|
66
|
+
for (const [key, value] of Object.entries(instance)) {
|
|
67
|
+
snapshot[key] = value;
|
|
68
|
+
}
|
|
69
|
+
kv.set(STATE_KEY, snapshot);
|
|
70
|
+
}
|
|
71
|
+
function getInstance(entry) {
|
|
72
|
+
const r = reg();
|
|
73
|
+
if (entry.mutable) {
|
|
74
|
+
return { instance: loadInstance(r), persist: true };
|
|
75
|
+
}
|
|
76
|
+
return { instance: new r.ctor(), persist: false };
|
|
77
|
+
}
|
|
78
|
+
function executeTool(entry, payload) {
|
|
79
|
+
let req;
|
|
80
|
+
try {
|
|
81
|
+
req = JSON.parse(decoder.decode(payload));
|
|
82
|
+
}
|
|
83
|
+
catch (e) {
|
|
84
|
+
return denied(`failed to parse tool execute payload: ${e.message}`);
|
|
85
|
+
}
|
|
86
|
+
const callId = req.call_id ?? "";
|
|
87
|
+
let instance;
|
|
88
|
+
let persist;
|
|
89
|
+
try {
|
|
90
|
+
({ instance, persist } = getInstance(entry));
|
|
91
|
+
}
|
|
92
|
+
catch (e) {
|
|
93
|
+
publishToolError(entry.name, callId, `failed to load state: ${e.message}`);
|
|
94
|
+
return cont();
|
|
95
|
+
}
|
|
96
|
+
let resultPayload;
|
|
97
|
+
try {
|
|
98
|
+
const raw = invoke(instance, entry.methodName, req.arguments);
|
|
99
|
+
resultPayload = { content: stringifyResult(raw), isError: false };
|
|
100
|
+
}
|
|
101
|
+
catch (e) {
|
|
102
|
+
resultPayload = { content: e.message ?? String(e), isError: true };
|
|
103
|
+
}
|
|
104
|
+
if (persist && !resultPayload.isError) {
|
|
105
|
+
try {
|
|
106
|
+
persistInstance(instance);
|
|
107
|
+
}
|
|
108
|
+
catch (e) {
|
|
109
|
+
publishToolError(entry.name, callId, `failed to save state: ${e.message}`);
|
|
110
|
+
return cont();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
publishToolResult(entry.name, callId, resultPayload.content, resultPayload.isError);
|
|
114
|
+
return cont();
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Dispatch interceptor / command actions. Both kinds share the same
|
|
118
|
+
* return path: the handler's JSON-serialized result becomes
|
|
119
|
+
* `capsule-result.data`, the kernel reads it from the hook-trigger
|
|
120
|
+
* return value. `null` results yield `{ action: "continue", data: undefined }`
|
|
121
|
+
* so the interceptor chain keeps the original payload (mirrors Rust).
|
|
122
|
+
*/
|
|
123
|
+
function executeHookHandler(entry, payload) {
|
|
124
|
+
let parsed = undefined;
|
|
125
|
+
if (payload.length > 0) {
|
|
126
|
+
try {
|
|
127
|
+
parsed = JSON.parse(decoder.decode(payload));
|
|
128
|
+
}
|
|
129
|
+
catch (e) {
|
|
130
|
+
return denied(`failed to parse payload: ${e.message}`);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
let instance;
|
|
134
|
+
let persist;
|
|
135
|
+
try {
|
|
136
|
+
({ instance, persist } = getInstance(entry));
|
|
137
|
+
}
|
|
138
|
+
catch (e) {
|
|
139
|
+
return denied(`failed to load state: ${e.message}`);
|
|
140
|
+
}
|
|
141
|
+
let resultJson;
|
|
142
|
+
try {
|
|
143
|
+
const raw = invoke(instance, entry.methodName, parsed);
|
|
144
|
+
resultJson = stringifyResult(raw);
|
|
145
|
+
}
|
|
146
|
+
catch (e) {
|
|
147
|
+
return denied(e.message ?? String(e));
|
|
148
|
+
}
|
|
149
|
+
if (persist) {
|
|
150
|
+
try {
|
|
151
|
+
persistInstance(instance);
|
|
152
|
+
}
|
|
153
|
+
catch (e) {
|
|
154
|
+
return denied(`failed to save state: ${e.message}`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (resultJson === "null")
|
|
158
|
+
return cont();
|
|
159
|
+
return cont(resultJson);
|
|
160
|
+
}
|
|
161
|
+
return {
|
|
162
|
+
astridHookTrigger(action, payload) {
|
|
163
|
+
try {
|
|
164
|
+
if (action === "tool_describe") {
|
|
165
|
+
toolDescribeCache ??= buildToolDescribe();
|
|
166
|
+
return cont(toolDescribeCache);
|
|
167
|
+
}
|
|
168
|
+
if (action.startsWith("tool_execute_")) {
|
|
169
|
+
const name = action.slice("tool_execute_".length);
|
|
170
|
+
const r = reg();
|
|
171
|
+
const entry = r.tools.get(name);
|
|
172
|
+
if (entry === undefined)
|
|
173
|
+
return denied(`unknown tool: ${name}`);
|
|
174
|
+
return executeTool(entry, payload);
|
|
175
|
+
}
|
|
176
|
+
const r = reg();
|
|
177
|
+
const interceptor = r.interceptors.get(action);
|
|
178
|
+
if (interceptor !== undefined) {
|
|
179
|
+
return executeHookHandler(interceptor, payload);
|
|
180
|
+
}
|
|
181
|
+
const command = r.commands.get(action);
|
|
182
|
+
if (command !== undefined) {
|
|
183
|
+
return executeHookHandler(command, payload);
|
|
184
|
+
}
|
|
185
|
+
return denied(`unknown hook action: ${action}`);
|
|
186
|
+
}
|
|
187
|
+
catch (e) {
|
|
188
|
+
return denied(`bridge panic in astridHookTrigger: ${e.message ?? String(e)}`);
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
run() {
|
|
192
|
+
try {
|
|
193
|
+
const r = reg();
|
|
194
|
+
if (r.runMethod === undefined) {
|
|
195
|
+
// Non-runnable capsule: WIT requires the export, but it must
|
|
196
|
+
// return immediately so the kernel doesn't think we're a daemon.
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
// Runnable capsule. Per Rust macro semantics, run() loads state but
|
|
200
|
+
// does NOT auto-persist (loops are infinite; explicit kv.set is
|
|
201
|
+
// the user's responsibility for runnable state).
|
|
202
|
+
const instance = loadInstance(r);
|
|
203
|
+
const raw = invoke(instance, r.runMethod, undefined);
|
|
204
|
+
// For a daemon-style loop, the handler should never resolve. If it
|
|
205
|
+
// does (or throws), surface via log and return.
|
|
206
|
+
if (raw instanceof Promise) {
|
|
207
|
+
syncWait(raw);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
catch (e) {
|
|
211
|
+
log.error(`run loop exited with error: ${e.message ?? String(e)}`);
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
astridInstall() {
|
|
215
|
+
try {
|
|
216
|
+
const r = reg();
|
|
217
|
+
if (r.installMethod === undefined)
|
|
218
|
+
return;
|
|
219
|
+
const instance = new r.ctor();
|
|
220
|
+
invoke(instance, r.installMethod, undefined);
|
|
221
|
+
persistInstance(instance);
|
|
222
|
+
}
|
|
223
|
+
catch (e) {
|
|
224
|
+
log.error(`install hook failed: ${e.message ?? String(e)}`);
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
astridUpgrade() {
|
|
228
|
+
try {
|
|
229
|
+
const r = reg();
|
|
230
|
+
if (r.upgradeMethod === undefined)
|
|
231
|
+
return;
|
|
232
|
+
const prevVersion = safeGetConfig("prev_version");
|
|
233
|
+
const instance = loadInstance(r);
|
|
234
|
+
invoke(instance, r.upgradeMethod, prevVersion);
|
|
235
|
+
persistInstance(instance);
|
|
236
|
+
}
|
|
237
|
+
catch (e) {
|
|
238
|
+
log.error(`upgrade hook failed: ${e.message ?? String(e)}`);
|
|
239
|
+
}
|
|
240
|
+
},
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Call a registered method on an instance. The bridge always passes
|
|
245
|
+
* either zero or one argument; method signatures with more parameters
|
|
246
|
+
* are rejected at decorator time.
|
|
247
|
+
*/
|
|
248
|
+
function invoke(instance, methodName, arg) {
|
|
249
|
+
const method = instance[methodName];
|
|
250
|
+
if (typeof method !== "function") {
|
|
251
|
+
throw new Error(`method ${methodName} not found on capsule instance`);
|
|
252
|
+
}
|
|
253
|
+
const raw = arg === undefined
|
|
254
|
+
? method.call(instance)
|
|
255
|
+
: method.call(instance, arg);
|
|
256
|
+
return raw instanceof Promise ? syncWait(raw) : raw;
|
|
257
|
+
}
|
|
258
|
+
function toolToDescribeEntry(entry) {
|
|
259
|
+
const schema = entry.inputSchema ?? { type: "object", properties: {} };
|
|
260
|
+
// Mirror schemars: `mutable` is a schema extension, not a top-level field.
|
|
261
|
+
const inputSchema = { ...schema, mutable: entry.mutable };
|
|
262
|
+
return {
|
|
263
|
+
name: entry.name,
|
|
264
|
+
description: entry.description ?? "",
|
|
265
|
+
input_schema: inputSchema,
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
function publishToolResult(name, callId, content, isError) {
|
|
269
|
+
const topic = `tool.v1.execute.${name}.result`;
|
|
270
|
+
ipc.publishJson(topic, {
|
|
271
|
+
type: "tool_execute_result",
|
|
272
|
+
call_id: callId,
|
|
273
|
+
result: { call_id: callId, content, is_error: isError },
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
function publishToolError(name, callId, message) {
|
|
277
|
+
publishToolResult(name, callId, message, true);
|
|
278
|
+
}
|
|
279
|
+
function stringifyResult(value) {
|
|
280
|
+
if (typeof value === "string")
|
|
281
|
+
return value;
|
|
282
|
+
if (value === undefined)
|
|
283
|
+
return "null";
|
|
284
|
+
try {
|
|
285
|
+
return JSON.stringify(value);
|
|
286
|
+
}
|
|
287
|
+
catch (e) {
|
|
288
|
+
throw new Error(`failed to serialize tool result: ${e.message}`);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
function safeGetConfig(key) {
|
|
292
|
+
try {
|
|
293
|
+
return getConfig(key) ?? "";
|
|
294
|
+
}
|
|
295
|
+
catch {
|
|
296
|
+
return "";
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* StarlingMonkey runs the JS event loop to settle promises returned from
|
|
301
|
+
* exported functions before returning to the host. Sync handlers
|
|
302
|
+
* pass-through; async handlers whose promise hasn't resolved by the
|
|
303
|
+
* engine's microtask drain are surfaced as a clear error.
|
|
304
|
+
*/
|
|
305
|
+
function syncWait(promise) {
|
|
306
|
+
let settled = false;
|
|
307
|
+
let value;
|
|
308
|
+
let error;
|
|
309
|
+
promise.then((v) => {
|
|
310
|
+
settled = true;
|
|
311
|
+
value = v;
|
|
312
|
+
}, (e) => {
|
|
313
|
+
settled = true;
|
|
314
|
+
error = e;
|
|
315
|
+
});
|
|
316
|
+
if (!settled) {
|
|
317
|
+
throw new Error("Handler returned a Promise that did not settle synchronously. " +
|
|
318
|
+
"ComponentizeJS syncifies awaits backed by host imports it knows " +
|
|
319
|
+
"how to drive — pure setTimeout/setInterval will hang. Use only " +
|
|
320
|
+
"Astrid SDK calls inside handlers, or make the handler sync.");
|
|
321
|
+
}
|
|
322
|
+
if (error !== undefined)
|
|
323
|
+
throw error;
|
|
324
|
+
return value;
|
|
325
|
+
}
|
|
326
|
+
//# sourceMappingURL=bridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge.js","sourceRoot":"","sources":["../../src/runtime/bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EACL,eAAe,GAKhB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,KAAK,GAAG,MAAM,WAAW,CAAC;AACjC,OAAO,KAAK,GAAG,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAElD,MAAM,SAAS,GAAG,SAAS,CAAC;AAoB5B,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAElC,SAAS,MAAM,CAAC,MAAc;IAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;AAC1C,CAAC;AAED,SAAS,IAAI,CAAC,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AC;IACZ,CAAC,CACF,CAAC;IACF,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,gEAAgE;YAC9D,kEAAkE;YAClE,iEAAiE;YACjE,6DAA6D,CAChE,CAAC;IACJ,CAAC;IACD,IAAI,KAAK,KAAK,SAAS;QAAE,MAAM,KAAK,CAAC;IACrC,OAAO,KAAU,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { createBridge, type Bridge, type CapsuleResult } from "./bridge.js";
|
|
2
|
+
export { registerCapsule, recordTool, recordInstall, recordUpgrade, getRegistration, __resetRegistry, type CapsuleRegistration, type ToolEntry, } from "./registry.js";
|
|
3
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,KAAK,MAAM,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,EACL,eAAe,EACf,UAAU,EACV,aAAa,EACb,aAAa,EACb,eAAe,EACf,eAAe,EACf,KAAK,mBAAmB,EACxB,KAAK,SAAS,GACf,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAmC,MAAM,aAAa,CAAC;AAC5E,OAAO,EACL,eAAe,EACf,UAAU,EACV,aAAa,EACb,aAAa,EACb,eAAe,EACf,eAAe,GAGhB,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Module-scoped registry populated by the @capsule, @tool, @install,
|
|
3
|
+
* @upgrade, @interceptor, @command, @run decorators. The bridge reads from
|
|
4
|
+
* this registry to dispatch host export calls.
|
|
5
|
+
*
|
|
6
|
+
* Decorators run during class evaluation, which happens at module init.
|
|
7
|
+
* The bridge is constructed AFTER all decorators have populated the
|
|
8
|
+
* registry, so reads are safe.
|
|
9
|
+
*/
|
|
10
|
+
export type CapsuleConstructor = new () => object;
|
|
11
|
+
export interface ToolEntry {
|
|
12
|
+
/** Name exposed to the LLM / kernel — matches `tool_execute_<name>` action. */
|
|
13
|
+
name: string;
|
|
14
|
+
/** TS method name on the class. */
|
|
15
|
+
methodName: string;
|
|
16
|
+
/** If true, the bridge loads state before and saves after on success. */
|
|
17
|
+
mutable: boolean;
|
|
18
|
+
/** Human-readable description from decorator or TSDoc. */
|
|
19
|
+
description: string | undefined;
|
|
20
|
+
/** JSON Schema for the tool's input. Built-time codegen fills this in. */
|
|
21
|
+
inputSchema: Record<string, unknown> | undefined;
|
|
22
|
+
}
|
|
23
|
+
export interface InterceptorEntry {
|
|
24
|
+
/** Topic pattern the interceptor reacts to (also the hook action name). */
|
|
25
|
+
topic: string;
|
|
26
|
+
methodName: string;
|
|
27
|
+
mutable: boolean;
|
|
28
|
+
}
|
|
29
|
+
export interface CommandEntry {
|
|
30
|
+
/** Command name (= hook action name, registered alongside interceptors). */
|
|
31
|
+
name: string;
|
|
32
|
+
methodName: string;
|
|
33
|
+
mutable: boolean;
|
|
34
|
+
}
|
|
35
|
+
export interface CapsuleRegistration {
|
|
36
|
+
ctor: CapsuleConstructor;
|
|
37
|
+
tools: Map<string, ToolEntry>;
|
|
38
|
+
interceptors: Map<string, InterceptorEntry>;
|
|
39
|
+
commands: Map<string, CommandEntry>;
|
|
40
|
+
installMethod: string | undefined;
|
|
41
|
+
upgradeMethod: string | undefined;
|
|
42
|
+
runMethod: string | undefined;
|
|
43
|
+
description: string | undefined;
|
|
44
|
+
}
|
|
45
|
+
export declare function registerCapsule(ctor: CapsuleConstructor, description?: string): void;
|
|
46
|
+
/** Adopt any decorator entries buffered before @capsule fired. */
|
|
47
|
+
export declare function adoptPending(ctor: CapsuleConstructor): void;
|
|
48
|
+
export declare function recordTool(ctor: CapsuleConstructor, entry: ToolEntry): void;
|
|
49
|
+
export declare function recordInterceptor(ctor: CapsuleConstructor, entry: InterceptorEntry): void;
|
|
50
|
+
export declare function recordCommand(ctor: CapsuleConstructor, entry: CommandEntry): void;
|
|
51
|
+
export declare function recordInstall(ctor: CapsuleConstructor, methodName: string): void;
|
|
52
|
+
export declare function recordUpgrade(ctor: CapsuleConstructor, methodName: string): void;
|
|
53
|
+
export declare function recordRun(ctor: CapsuleConstructor, methodName: string): void;
|
|
54
|
+
/** Returns the registered capsule, or undefined if none has been declared. */
|
|
55
|
+
export declare function getRegistration(): CapsuleRegistration | undefined;
|
|
56
|
+
/** Test-only: reset the registry to a clean state. */
|
|
57
|
+
export declare function __resetRegistry(): void;
|
|
58
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/runtime/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,MAAM,kBAAkB,GAAG,UAAU,MAAM,CAAC;AAElD,MAAM,WAAW,SAAS;IACxB,+EAA+E;IAC/E,IAAI,EAAE,MAAM,CAAC;IACb,mCAAmC;IACnC,UAAU,EAAE,MAAM,CAAC;IACnB,yEAAyE;IACzE,OAAO,EAAE,OAAO,CAAC;IACjB,0DAA0D;IAC1D,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,0EAA0E;IAC1E,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;CAClD;AAED,MAAM,WAAW,gBAAgB;IAC/B,2EAA2E;IAC3E,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,YAAY;IAC3B,4EAA4E;IAC5E,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IAC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S,CAEjE;AAED,sDAAsD;AACtD,wBAAgB,eAAe,IAAI,IAAI,CAEtC"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Module-scoped registry populated by the @capsule, @tool, @install,
|
|
3
|
+
* @upgrade, @interceptor, @command, @run decorators. The bridge reads from
|
|
4
|
+
* this registry to dispatch host export calls.
|
|
5
|
+
*
|
|
6
|
+
* Decorators run during class evaluation, which happens at module init.
|
|
7
|
+
* The bridge is constructed AFTER all decorators have populated the
|
|
8
|
+
* registry, so reads are safe.
|
|
9
|
+
*/
|
|
10
|
+
let registration;
|
|
11
|
+
function newRegistration(ctor, description) {
|
|
12
|
+
return {
|
|
13
|
+
ctor,
|
|
14
|
+
tools: new Map(),
|
|
15
|
+
interceptors: new Map(),
|
|
16
|
+
commands: new Map(),
|
|
17
|
+
installMethod: undefined,
|
|
18
|
+
upgradeMethod: undefined,
|
|
19
|
+
runMethod: undefined,
|
|
20
|
+
description,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export function registerCapsule(ctor, description) {
|
|
24
|
+
if (registration !== undefined && registration.ctor !== ctor) {
|
|
25
|
+
throw new Error(`Only one @capsule class may be registered per WASM module. ` +
|
|
26
|
+
`Already have ${registration.ctor.name}; refusing to register ${ctor.name}.`);
|
|
27
|
+
}
|
|
28
|
+
if (registration === undefined) {
|
|
29
|
+
registration = newRegistration(ctor, description);
|
|
30
|
+
}
|
|
31
|
+
else if (description !== undefined && registration.description === undefined) {
|
|
32
|
+
registration.description = description;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Decorators may run before `@capsule` if class fields appear before the
|
|
37
|
+
* class itself in source. Buffer pending entries on the constructor so the
|
|
38
|
+
* eventual @capsule call picks them up.
|
|
39
|
+
*/
|
|
40
|
+
const pendingByCtor = new WeakMap();
|
|
41
|
+
function ensureRegistration(ctor) {
|
|
42
|
+
if (registration !== undefined && registration.ctor === ctor) {
|
|
43
|
+
return registration;
|
|
44
|
+
}
|
|
45
|
+
let pending = pendingByCtor.get(ctor);
|
|
46
|
+
if (pending === undefined) {
|
|
47
|
+
pending = newRegistration(ctor, undefined);
|
|
48
|
+
pendingByCtor.set(ctor, pending);
|
|
49
|
+
}
|
|
50
|
+
return pending;
|
|
51
|
+
}
|
|
52
|
+
/** Adopt any decorator entries buffered before @capsule fired. */
|
|
53
|
+
export function adoptPending(ctor) {
|
|
54
|
+
if (registration === undefined || registration.ctor !== ctor)
|
|
55
|
+
return;
|
|
56
|
+
const pending = pendingByCtor.get(ctor);
|
|
57
|
+
if (pending === undefined)
|
|
58
|
+
return;
|
|
59
|
+
for (const [name, entry] of pending.tools)
|
|
60
|
+
registration.tools.set(name, entry);
|
|
61
|
+
for (const [topic, entry] of pending.interceptors)
|
|
62
|
+
registration.interceptors.set(topic, entry);
|
|
63
|
+
for (const [name, entry] of pending.commands)
|
|
64
|
+
registration.commands.set(name, entry);
|
|
65
|
+
if (pending.installMethod !== undefined && registration.installMethod === undefined) {
|
|
66
|
+
registration.installMethod = pending.installMethod;
|
|
67
|
+
}
|
|
68
|
+
if (pending.upgradeMethod !== undefined && registration.upgradeMethod === undefined) {
|
|
69
|
+
registration.upgradeMethod = pending.upgradeMethod;
|
|
70
|
+
}
|
|
71
|
+
if (pending.runMethod !== undefined && registration.runMethod === undefined) {
|
|
72
|
+
registration.runMethod = pending.runMethod;
|
|
73
|
+
}
|
|
74
|
+
if (pending.description !== undefined && registration.description === undefined) {
|
|
75
|
+
registration.description = pending.description;
|
|
76
|
+
}
|
|
77
|
+
pendingByCtor.delete(ctor);
|
|
78
|
+
}
|
|
79
|
+
export function recordTool(ctor, entry) {
|
|
80
|
+
const target = ensureRegistration(ctor);
|
|
81
|
+
if (target.tools.has(entry.name)) {
|
|
82
|
+
throw new Error(`@tool("${entry.name}") declared twice on ${ctor.name}.`);
|
|
83
|
+
}
|
|
84
|
+
target.tools.set(entry.name, entry);
|
|
85
|
+
}
|
|
86
|
+
export function recordInterceptor(ctor, entry) {
|
|
87
|
+
const target = ensureRegistration(ctor);
|
|
88
|
+
if (target.interceptors.has(entry.topic)) {
|
|
89
|
+
throw new Error(`@interceptor("${entry.topic}") declared twice on ${ctor.name}.`);
|
|
90
|
+
}
|
|
91
|
+
target.interceptors.set(entry.topic, entry);
|
|
92
|
+
}
|
|
93
|
+
export function recordCommand(ctor, entry) {
|
|
94
|
+
const target = ensureRegistration(ctor);
|
|
95
|
+
if (target.commands.has(entry.name)) {
|
|
96
|
+
throw new Error(`@command("${entry.name}") declared twice on ${ctor.name}.`);
|
|
97
|
+
}
|
|
98
|
+
target.commands.set(entry.name, entry);
|
|
99
|
+
}
|
|
100
|
+
export function recordInstall(ctor, methodName) {
|
|
101
|
+
const target = ensureRegistration(ctor);
|
|
102
|
+
if (target.installMethod !== undefined) {
|
|
103
|
+
throw new Error(`Only one @install method allowed on ${ctor.name}.`);
|
|
104
|
+
}
|
|
105
|
+
target.installMethod = methodName;
|
|
106
|
+
}
|
|
107
|
+
export function recordUpgrade(ctor, methodName) {
|
|
108
|
+
const target = ensureRegistration(ctor);
|
|
109
|
+
if (target.upgradeMethod !== undefined) {
|
|
110
|
+
throw new Error(`Only one @upgrade method allowed on ${ctor.name}.`);
|
|
111
|
+
}
|
|
112
|
+
target.upgradeMethod = methodName;
|
|
113
|
+
}
|
|
114
|
+
export function recordRun(ctor, methodName) {
|
|
115
|
+
const target = ensureRegistration(ctor);
|
|
116
|
+
if (target.runMethod !== undefined) {
|
|
117
|
+
throw new Error(`Only one @run method allowed on ${ctor.name}.`);
|
|
118
|
+
}
|
|
119
|
+
target.runMethod = methodName;
|
|
120
|
+
}
|
|
121
|
+
/** Returns the registered capsule, or undefined if none has been declared. */
|
|
122
|
+
export function getRegistration() {
|
|
123
|
+
return registration;
|
|
124
|
+
}
|
|
125
|
+
/** Test-only: reset the registry to a clean state. */
|
|
126
|
+
export function __resetRegistry() {
|
|
127
|
+
registration = undefined;
|
|
128
|
+
}
|
|
129
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,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,eAAe;IAC7B,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,sDAAsD;AACtD,MAAM,UAAU,eAAe;IAC7B,YAAY,GAAG,SAAS,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OS runtime introspection + signaling. Mirrors `astrid_sdk::runtime`.
|
|
3
|
+
*
|
|
4
|
+
* Also surfaces {@link randomBytes} (cryptographically secure host entropy
|
|
5
|
+
* via `sys::random-bytes`) for capsules that need an audit-traced CSPRNG —
|
|
6
|
+
* `globalThis.crypto.getRandomValues` works inside StarlingMonkey but
|
|
7
|
+
* bypasses the host audit trail.
|
|
8
|
+
*/
|
|
9
|
+
/** Information about the caller that triggered the current execution. */
|
|
10
|
+
export interface CallerContext {
|
|
11
|
+
/** UUID of the capsule that originated the IPC message. */
|
|
12
|
+
sourceId: string;
|
|
13
|
+
/** The acting principal (user ID), if available. */
|
|
14
|
+
principal: string | undefined;
|
|
15
|
+
/** ISO 8601 timestamp of the originating message. */
|
|
16
|
+
timestamp: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Signal that the capsule's run loop is ready. Call after setting up IPC
|
|
20
|
+
* subscriptions inside `@run`; the kernel waits for this before loading
|
|
21
|
+
* dependent capsules.
|
|
22
|
+
*/
|
|
23
|
+
export declare function signalReady(): void;
|
|
24
|
+
/** Caller context for the current invocation. */
|
|
25
|
+
export declare function caller(): CallerContext;
|
|
26
|
+
/**
|
|
27
|
+
* Fill `length` bytes with cryptographically secure random data from the
|
|
28
|
+
* host's OS-level CSPRNG. Capped at 4096 bytes per call.
|
|
29
|
+
*/
|
|
30
|
+
export declare function randomBytes(length: number): Uint8Array;
|
|
31
|
+
/**
|
|
32
|
+
* Kernel's Unix domain socket path, injected via the well-known
|
|
33
|
+
* `ASTRID_SOCKET_PATH` config key.
|
|
34
|
+
*/
|
|
35
|
+
export declare function socketPath(): string;
|
|
36
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAUH,yEAAyE;AACzE,MAAM,WAAW,aAAa;IAC5B,2DAA2D;IAC3D,QAAQ,EAAE,MAAM,CAAC;IACjB,oDAAoD;IACpD,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,qDAAqD;IACrD,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;GAIG;AACH,wBAAgB,WAAW,IAAI,IAAI,CAElC;AAED,iDAAiD;AACjD,wBAAgB,MAAM,IAAI,aAAa,CAOtC;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAItD;AAED;;;GAGG;AACH,wBAAgB,UAAU,IAAI,MAAM,CASnC"}
|