@once-agent/sdk 0.1.6 → 0.1.8

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.
@@ -0,0 +1,310 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.LocalProtectionError = void 0;
40
+ exports.protectLocal = protectLocal;
41
+ const node_crypto_1 = require("node:crypto");
42
+ const node_fs_1 = require("node:fs");
43
+ const node_path_1 = __importDefault(require("node:path"));
44
+ const node_util_1 = require("node:util");
45
+ const binding_js_1 = require("./connect/binding.js");
46
+ class LocalProtectionError extends Error {
47
+ code;
48
+ constructor(code, message, options) {
49
+ super(message, options);
50
+ this.code = code;
51
+ this.name = "LocalProtectionError";
52
+ }
53
+ }
54
+ exports.LocalProtectionError = LocalProtectionError;
55
+ // Local mode accepts JSON-like data with no hidden behavior. Callable/provider
56
+ // handles may travel through arguments by identity, but cannot be payloads or
57
+ // receipts. The caller must keep their effect-bearing state stable.
58
+ function copyData(value, allowHandles = false, seen = new Set(), location = "$", freeze = false) {
59
+ if (value === null || typeof value === "string" || typeof value === "boolean")
60
+ return value;
61
+ if (typeof value === "number" && Number.isFinite(value) && !Object.is(value, -0))
62
+ return value;
63
+ if (allowHandles && (value === undefined || typeof value === "bigint" || typeof value === "symbol"))
64
+ return value;
65
+ if (allowHandles && typeof value === "function")
66
+ return value;
67
+ if (typeof value !== "object") {
68
+ throw new LocalProtectionError("UNSUPPORTED_VALUE", `Unsupported local data at ${location}.`);
69
+ }
70
+ if (node_util_1.types.isProxy(value)) {
71
+ throw new LocalProtectionError("UNSUPPORTED_VALUE", `Proxy at ${location} is unsupported.`);
72
+ }
73
+ const prototype = Object.getPrototypeOf(value);
74
+ if (prototype !== Object.prototype && prototype !== null && prototype !== Array.prototype) {
75
+ if (allowHandles)
76
+ return value;
77
+ throw new LocalProtectionError("UNSUPPORTED_VALUE", `Unsupported object at ${location}.`);
78
+ }
79
+ const descriptors = Object.getOwnPropertyDescriptors(value);
80
+ const keys = Reflect.ownKeys(descriptors);
81
+ if (keys.includes("toJSON")) {
82
+ throw new LocalProtectionError("UNSUPPORTED_VALUE", `Serialization hook at ${location} is unsupported.`);
83
+ }
84
+ if (keys.some(key => typeof key === "symbol")) {
85
+ throw new LocalProtectionError("UNSUPPORTED_VALUE", `Symbol property at ${location} is unsupported.`);
86
+ }
87
+ if (keys.some(key => !("value" in descriptors[key]) ||
88
+ (!(Array.isArray(value) && key === "length") && !descriptors[key].enumerable))) {
89
+ throw new LocalProtectionError("UNSUPPORTED_VALUE", `Accessor or hidden property at ${location} is unsupported.`);
90
+ }
91
+ if (allowHandles && !Array.isArray(value) &&
92
+ keys.some(key => typeof descriptors[key].value === "function"))
93
+ return value;
94
+ if (seen.has(value)) {
95
+ throw new LocalProtectionError("UNSUPPORTED_VALUE", `Cyclic local data at ${location} is unsupported.`);
96
+ }
97
+ seen.add(value);
98
+ try {
99
+ if (Array.isArray(value)) {
100
+ if (prototype !== Array.prototype) {
101
+ throw new LocalProtectionError("UNSUPPORTED_VALUE", `Unsupported array at ${location}.`);
102
+ }
103
+ const array = value;
104
+ if (keys.length !== array.length + 1 ||
105
+ Array.from({ length: array.length }, (_, index) => String(index))
106
+ .some(index => !Object.prototype.hasOwnProperty.call(descriptors, index))) {
107
+ throw new LocalProtectionError("UNSUPPORTED_VALUE", `Sparse or extended array at ${location} is unsupported.`);
108
+ }
109
+ const result = array.map((_, index) => copyData(descriptors[String(index)].value, allowHandles, seen, `${location}[${index}]`, freeze));
110
+ return freeze ? Object.freeze(result) : result;
111
+ }
112
+ const result = {};
113
+ for (const key of keys) {
114
+ Object.defineProperty(result, key, {
115
+ value: copyData(descriptors[key].value, allowHandles, seen, `${location}.${key}`, freeze),
116
+ enumerable: true,
117
+ writable: true,
118
+ configurable: true,
119
+ });
120
+ }
121
+ return freeze ? Object.freeze(result) : result;
122
+ }
123
+ finally {
124
+ seen.delete(value);
125
+ }
126
+ }
127
+ function encodeResult(value) {
128
+ const envelope = value === undefined
129
+ ? { hasValue: false }
130
+ : { hasValue: true, value: copyData(value) };
131
+ return (0, binding_js_1.canonicalizeConnectPayload)(envelope);
132
+ }
133
+ function decodeResult(encoded) {
134
+ try {
135
+ const envelope = JSON.parse(encoded);
136
+ if (envelope === null || typeof envelope !== "object" || Array.isArray(envelope) ||
137
+ typeof envelope.hasValue !== "boolean" ||
138
+ (envelope.hasValue && !Object.prototype.hasOwnProperty.call(envelope, "value")) ||
139
+ (!envelope.hasValue && Object.prototype.hasOwnProperty.call(envelope, "value")) ||
140
+ Object.keys(envelope).length !== (envelope.hasValue ? 2 : 1)) {
141
+ throw new Error("Malformed receipt envelope.");
142
+ }
143
+ const validated = copyData(envelope);
144
+ return (validated.hasValue ? validated.value : undefined);
145
+ }
146
+ catch (cause) {
147
+ throw new LocalProtectionError("STATE_UNAVAILABLE", "The stored local receipt is malformed. No operation was dispatched.", { cause });
148
+ }
149
+ }
150
+ /**
151
+ * Protect an existing async operation on one machine while keeping its call
152
+ * shape and dynamic receiver. Ordinary data arguments are snapshotted and
153
+ * frozen; opaque handles keep their identity. SQLite coordinates processes
154
+ * sharing the same durable local file.
155
+ * Uncertain outcomes remain blocked; this wrapper never redispatches after
156
+ * an ambiguous attempt, even if a lookup reports ABSENT.
157
+ */
158
+ function protectLocal(operation, options) {
159
+ if (typeof operation !== "function" || typeof options?.id !== "function" || typeof options.payload !== "function") {
160
+ throw new LocalProtectionError("INVALID_CONFIGURATION", "protectLocal requires an async operation plus id and payload functions. The id must survive retries; payload must include every effect-bearing input.");
161
+ }
162
+ const statePath = node_path_1.default.resolve(options.statePath ?? node_path_1.default.join(process.cwd(), ".once", "operations.sqlite"));
163
+ const leaseMs = options.leaseMs ?? 30_000;
164
+ if (!Number.isSafeInteger(leaseMs) || leaseMs <= 0) {
165
+ throw new LocalProtectionError("INVALID_LEASE", "leaseMs must be a positive integer in milliseconds.");
166
+ }
167
+ return async function (...args) {
168
+ const callArgs = copyData(args, true, new Set(), "$args", true);
169
+ const id = options.id(...callArgs);
170
+ if (typeof id !== "string" || id.trim() === "") {
171
+ throw new LocalProtectionError("INVALID_ID", "A stable nonempty logical action id is required. Reuse it for retries and choose a new one for a separate intentional action.");
172
+ }
173
+ const payload = copyData(options.payload(...callArgs));
174
+ const fingerprint = (0, binding_js_1.fingerprintConnectPayload)(payload);
175
+ if (Number(process.versions.node.split(".")[0]) < 24 ||
176
+ (Number(process.versions.node.split(".")[0]) === 24 && Number(process.versions.node.split(".")[1]) < 15)) {
177
+ throw new LocalProtectionError("UNSUPPORTED_RUNTIME", "Local SQLite protection requires Node.js 24.15 or later. Use a supported Node runtime or the hosted Once execution path.");
178
+ }
179
+ let DatabaseSync;
180
+ try {
181
+ ({ DatabaseSync } = await Promise.resolve().then(() => __importStar(require("node:sqlite"))));
182
+ }
183
+ catch (cause) {
184
+ throw new LocalProtectionError("SQLITE_UNAVAILABLE", "Node SQLite is unavailable. Enable node:sqlite or use the hosted Once execution path; the operation was not dispatched.", { cause });
185
+ }
186
+ let db;
187
+ try {
188
+ (0, node_fs_1.mkdirSync)(node_path_1.default.dirname(statePath), { recursive: true });
189
+ db = new DatabaseSync(statePath, { timeout: 30_000 });
190
+ db.exec("PRAGMA journal_mode=WAL; PRAGMA synchronous=FULL; CREATE TABLE IF NOT EXISTS local_operations (id TEXT PRIMARY KEY, fingerprint TEXT NOT NULL, state TEXT NOT NULL CHECK(state IN ('CLAIMED','UNKNOWN','CONFIRMED')), result_json TEXT, owner TEXT, lease_until INTEGER);");
191
+ }
192
+ catch (cause) {
193
+ if (db) {
194
+ try {
195
+ db.close();
196
+ }
197
+ catch { /* Preserve the initialization error. */ }
198
+ }
199
+ throw new LocalProtectionError("STATE_UNAVAILABLE", `Cannot open durable Once state at ${statePath}. The operation was not dispatched. Restore access to this same file before retrying.`, { cause });
200
+ }
201
+ const owner = (0, node_crypto_1.randomUUID)();
202
+ let shouldDispatch = false;
203
+ let row;
204
+ try {
205
+ db.exec("BEGIN IMMEDIATE");
206
+ row = db.prepare("SELECT fingerprint,state,result_json,owner,lease_until FROM local_operations WHERE id=?").get(id);
207
+ if (!row) {
208
+ db.prepare("INSERT INTO local_operations(id,fingerprint,state,result_json,owner,lease_until) VALUES(?,?,'CLAIMED',NULL,?,?)")
209
+ .run(id, fingerprint, owner, Date.now() + leaseMs);
210
+ shouldDispatch = true;
211
+ }
212
+ db.exec("COMMIT");
213
+ }
214
+ catch (cause) {
215
+ if (db.isTransaction)
216
+ db.exec("ROLLBACK");
217
+ db.close();
218
+ throw new LocalProtectionError("STATE_UNAVAILABLE", "Could not atomically claim durable Once state. The operation was not dispatched; retry with the same id after restoring state access.", { cause });
219
+ }
220
+ try {
221
+ if (!shouldDispatch) {
222
+ if (row.fingerprint !== fingerprint) {
223
+ throw new LocalProtectionError("CONFLICT", `Logical action ${id} has a different effect-bearing payload. Choose a new id only for a genuinely new action; no write was dispatched.`);
224
+ }
225
+ if (row.state === "CONFIRMED")
226
+ return decodeResult(row.result_json);
227
+ if (row.state === "CLAIMED" && row.lease_until > Date.now()) {
228
+ throw new LocalProtectionError("IN_FLIGHT", `Logical action ${id} is still in flight. Wait and retry with the same id; do not call the underlying operation directly.`);
229
+ }
230
+ // Persist uncertainty before any fallible external lookup.
231
+ db.prepare("UPDATE local_operations SET state='UNKNOWN',owner=NULL,lease_until=NULL WHERE id=? AND state='CLAIMED'").run(id);
232
+ if (!options.reconcile) {
233
+ throw new LocalProtectionError("UNKNOWN", `Outcome of ${id} is unknown. Supply an authoritative reconcile callback or investigate provider truth; no second write was dispatched.`);
234
+ }
235
+ let observation;
236
+ try {
237
+ observation = await options.reconcile({ id, payload: copyData(payload) });
238
+ }
239
+ catch (cause) {
240
+ throw new LocalProtectionError("UNKNOWN", `Provider truth for ${id} is unavailable. No second write was dispatched.`, { cause });
241
+ }
242
+ if (observation?.state !== "CONFIRMED") {
243
+ throw new LocalProtectionError("UNKNOWN", `Provider truth for ${id} did not confirm an effect. Local mode will not redispatch after an ambiguous attempt; investigate or use a provider idempotency integration.`);
244
+ }
245
+ if (!Object.prototype.hasOwnProperty.call(observation, "result")) {
246
+ throw new LocalProtectionError("INVALID_TRUTH", "CONFIRMED provider truth must include a result; the outcome remains UNKNOWN and no second write was dispatched.");
247
+ }
248
+ let resultJson;
249
+ try {
250
+ resultJson = encodeResult(observation.result);
251
+ }
252
+ catch (cause) {
253
+ throw new LocalProtectionError("INVALID_TRUTH", "CONFIRMED provider truth needs a JSON-safe result. No second write was dispatched.", { cause });
254
+ }
255
+ const confirmation = db.prepare("UPDATE local_operations SET state='CONFIRMED',result_json=? WHERE id=? AND state='UNKNOWN'").run(resultJson, id);
256
+ if (confirmation.changes !== 1) {
257
+ const latest = db.prepare("SELECT fingerprint,state,result_json,owner,lease_until FROM local_operations WHERE id=?").get(id);
258
+ if (latest?.fingerprint === fingerprint && latest.state === "CONFIRMED" && latest.result_json !== null) {
259
+ return decodeResult(latest.result_json);
260
+ }
261
+ throw new LocalProtectionError("UNKNOWN", `State changed while reconciling ${id}. Retry with the same id; no second write was dispatched.`);
262
+ }
263
+ return decodeResult(resultJson);
264
+ }
265
+ // Recheck handles whose state the selectors might have read while the
266
+ // claim was being established. A changed claim stays uncertain.
267
+ let currentFingerprint;
268
+ try {
269
+ if (options.id(...callArgs) !== id) {
270
+ throw new Error("Logical action id changed.");
271
+ }
272
+ currentFingerprint = (0, binding_js_1.fingerprintConnectPayload)(copyData(options.payload(...callArgs)));
273
+ }
274
+ catch (cause) {
275
+ db.prepare("UPDATE local_operations SET state='UNKNOWN',owner=NULL,lease_until=NULL WHERE id=? AND state='CLAIMED' AND owner=?").run(id, owner);
276
+ throw new LocalProtectionError("PAYLOAD_DRIFT", `Payload of ${id} changed before dispatch. No operation was dispatched.`, { cause });
277
+ }
278
+ if (currentFingerprint !== fingerprint) {
279
+ db.prepare("UPDATE local_operations SET state='UNKNOWN',owner=NULL,lease_until=NULL WHERE id=? AND state='CLAIMED' AND owner=?").run(id, owner);
280
+ throw new LocalProtectionError("PAYLOAD_DRIFT", `Payload of ${id} changed before dispatch. No operation was dispatched.`);
281
+ }
282
+ let result;
283
+ try {
284
+ result = await operation.apply(this, callArgs);
285
+ }
286
+ catch (cause) {
287
+ db.prepare("UPDATE local_operations SET state='UNKNOWN',owner=NULL,lease_until=NULL WHERE id=? AND state='CLAIMED' AND owner=?").run(id, owner);
288
+ throw new LocalProtectionError("UNKNOWN", `Operation ${id} threw after dispatch; its external outcome may be unknown. Reconcile provider truth before retrying.`, { cause });
289
+ }
290
+ let resultJson;
291
+ try {
292
+ resultJson = encodeResult(result);
293
+ }
294
+ catch (cause) {
295
+ db.prepare("UPDATE local_operations SET state='UNKNOWN',owner=NULL,lease_until=NULL WHERE id=? AND state='CLAIMED' AND owner=?").run(id, owner);
296
+ throw new LocalProtectionError("UNREPLAYABLE_RESULT", `Operation ${id} returned a non-JSON-safe result. Outcome is UNKNOWN; return a JSON-safe receipt and reconcile before retrying.`, { cause });
297
+ }
298
+ const update = db.prepare("UPDATE local_operations SET state='CONFIRMED',result_json=?,owner=NULL,lease_until=NULL WHERE id=? AND state='CLAIMED' AND owner=?")
299
+ .run(resultJson, id, owner);
300
+ if (update.changes !== 1) {
301
+ throw new LocalProtectionError("EXECUTION_RIGHT_LOST", `Operation ${id} completed after its claim changed. Reconcile provider truth before retrying.`);
302
+ }
303
+ return decodeResult(resultJson);
304
+ }
305
+ finally {
306
+ db.close();
307
+ }
308
+ };
309
+ }
310
+ //# sourceMappingURL=local.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local.js","sourceRoot":"","sources":["../src/local.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0IA,oCAkJC;AA5RD,6CAAyC;AACzC,qCAAoC;AACpC,0DAA6B;AAC7B,yCAAkC;AAClC,qDAA6F;AAqB7F,MAAa,oBAAqB,SAAQ,KAAK;IACxB;IAArB,YAAqB,IAAY,EAAE,OAAe,EAAE,OAAsB;QACxE,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QADL,SAAI,GAAJ,IAAI,CAAQ;QAE/B,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACrC,CAAC;CACF;AALD,oDAKC;AAUD,+EAA+E;AAC/E,8EAA8E;AAC9E,oEAAoE;AACpE,SAAS,QAAQ,CAAC,KAAc,EAAE,YAAY,GAAG,KAAK,EAAE,OAAO,IAAI,GAAG,EAAU,EAAE,QAAQ,GAAG,GAAG,EAAE,MAAM,GAAG,KAAK;IAC9G,IA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OAAO,KAAK,EAAE,CAAC;gBACf,EAAE,CAAC,OAAO,CAAC,oHAAoH,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;gBAChJ,MAAM,IAAI,oBAAoB,CAAC,qBAAqB,EAAE,aAAa,EAAE,iHAAiH,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;YACrM,CAAC;YACD,MAAM,MAAM,GAAG,EAAE,CAAC,OAAO,CAAC,oIAAoI,CAAC;iBAC5J,GAAG,CAAC,UAAU,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC;YAC9B,IAAI,MAAM,CAAC,OAAO,KAAK,CAAC,EAAE,CAAC;gBACzB,MAAM,IAAI,oBAAoB,CAAC,sBAAsB,EAAE,aAAa,EAAE,+EAA+E,CAAC,CAAC;YACzJ,CAAC;YACD,OAAO,YAAY,CAAI,UAAU,CAAC,CAAC;QACrC,CAAC;gBAAS,CAAC;YACT,EAAE,CAAC,KAAK,EAAE,CAAC;QACb,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@once-agent/sdk",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "Execution safety for side-effecting AI agent tools.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -26,11 +26,13 @@
26
26
  "test:dataset-seal": "npm run build && node ./scripts/dataset-seal-regression.mjs",
27
27
  "test:dataset-progress": "npm run build && node ./scripts/dataset-progress-regression.mjs",
28
28
  "test:agent-discovery": "node ./scripts/agent-discovery-regression.mjs",
29
+ "test:doctor": "npm run build && node ./scripts/doctor-adoption-regression.mjs",
29
30
  "routing:check": "node ./scripts/agent-routing-conformance.mjs",
30
31
  "routing:cases": "node ./scripts/agent-routing-conformance.mjs --emit-cases",
31
32
  "test:routing-conformance": "node ./scripts/agent-routing-conformance-regression.mjs",
32
33
  "test:contract": "npm run build && tsc --noEmit --target ES2022 --module NodeNext --moduleResolution NodeNext --strict --types node ./scripts/sdk-contract-types.ts && node ./scripts/sdk-contract-runtime.mjs",
33
- "test:release": "npm run benchmark:scan && npm run test:benchmark && npm run test:trace && npm run test:dataset-seal && npm run test:dataset-progress && npm run test:agent-discovery && npm run test:routing-conformance && npm run test:scanner-declarations && npm run test:contract && npm run test:protect && npm run test:capabilities && npm run test:transformer && npm run test:binding && npm run test:patch-planner && npm run test:transformer-protect && npm run test:apply && npm run test:id-conformance && npm run test:consumer && npm run test:activation && npm run test:package && npm run test:runtime-setup && npm run test:connect",
34
+ "test:release": "npm run benchmark:scan && npm run test:benchmark && npm run test:trace && npm run test:dataset-seal && npm run test:dataset-progress && npm run test:agent-discovery && npm run test:doctor && npm run test:routing-conformance && npm run test:scanner-declarations && npm run test:contract && npm run test:protect && npm run test:capabilities && npm run test:transformer && npm run test:binding && npm run test:patch-planner && npm run test:transformer-protect && npm run test:apply && npm run test:id-conformance && npm run test:consumer && npm run test:activation && npm run test:package && npm run test:runtime-setup && npm run test:connect",
35
+ "test:local": "npm run build && node --test ./test/local.test.mjs",
34
36
  "test:connect": "npm run build && node --test ./test/connect/*.test.mjs",
35
37
  "test:protect": "npm run build && node ./scripts/protect-regression.mjs",
36
38
  "test:capabilities": "npm run build && node ./scripts/capability-regression.mjs",
@@ -47,7 +49,8 @@
47
49
  "build:cjs": "tsc -p tsconfig.cjs.json && node ./scripts/write-cjs-package.mjs",
48
50
  "test:runtime-setup": "npm run build && node ./scripts/runtime-setup-regression.mjs",
49
51
  "test:activation": "npm run build && node ./scripts/activation-regression.mjs",
50
- "test:setup-persistence": "npm run build && node ./scripts/setup-persistence-regression.mjs"
52
+ "test:setup-persistence": "npm run build && node ./scripts/setup-persistence-regression.mjs",
53
+ "prepack": "npm run build"
51
54
  },
52
55
  "keywords": [
53
56
  "ai",