@tangle-network/agent-app 3.0.36 → 4.0.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/dist/agent-profiles/d1.js +1 -1
- package/dist/agent-profiles/index.d.ts +11 -0
- package/dist/agent-profiles/index.js +1 -1
- package/dist/chat-routes/index.js +3 -3
- package/dist/chat-routes/native-completion.d.ts +6 -7
- package/dist/{chunk-KYF6YK3C.js → chunk-BRQ2SC6V.js} +17 -9
- package/dist/chunk-BRQ2SC6V.js.map +1 -0
- package/dist/{chunk-X2NXWJ6P.js → chunk-HES3IABJ.js} +6 -60
- package/dist/chunk-HES3IABJ.js.map +1 -0
- package/dist/{chunk-5DG2LO3T.js → chunk-JFBJ7MGK.js} +223 -213
- package/dist/{chunk-5DG2LO3T.js.map → chunk-JFBJ7MGK.js.map} +1 -1
- package/dist/{chunk-VG27P322.js → chunk-JSWBJBPM.js} +2 -2
- package/dist/preset-cloudflare/index.d.ts +1 -1
- package/dist/preset-cloudflare/index.js +79 -10
- package/dist/preset-cloudflare/index.js.map +1 -1
- package/dist/preset-cloudflare/native-completion-owner.d.ts +2 -0
- package/dist/preset-cloudflare/native-completion-workflow.d.ts +26 -4
- package/dist/public-consultation/index.js +2 -2
- package/dist/sandbox/existing-box.d.ts +6 -0
- package/dist/sandbox/index.d.ts +1 -0
- package/dist/sandbox/index.js +3 -1
- package/package.json +1 -1
- package/dist/chunk-KYF6YK3C.js.map +0 -1
- package/dist/chunk-X2NXWJ6P.js.map +0 -1
- /package/dist/{chunk-VG27P322.js.map → chunk-JSWBJBPM.js.map} +0 -0
|
@@ -31,7 +31,7 @@ import {
|
|
|
31
31
|
sandboxRunFailureDetail,
|
|
32
32
|
streamSandboxPrompt,
|
|
33
33
|
turnStorageBindings
|
|
34
|
-
} from "./chunk-
|
|
34
|
+
} from "./chunk-JFBJ7MGK.js";
|
|
35
35
|
import {
|
|
36
36
|
redactErrorMessage
|
|
37
37
|
} from "./chunk-MH74DY2I.js";
|
|
@@ -4227,4 +4227,4 @@ export {
|
|
|
4227
4227
|
createChatTurnRoutes,
|
|
4228
4228
|
streamChatRouteAsSandboxEvents
|
|
4229
4229
|
};
|
|
4230
|
-
//# sourceMappingURL=chunk-
|
|
4230
|
+
//# sourceMappingURL=chunk-JSWBJBPM.js.map
|
|
@@ -31,7 +31,7 @@ import type { AppToolHandlers } from '../tools/index.js';
|
|
|
31
31
|
import type { KvLike } from '../web/index.js';
|
|
32
32
|
export { ensureCloudflareWorkflowInstance, type CloudflareWorkflowBindingLike, type CloudflareWorkflowInstanceLike, type EnsureCloudflareWorkflowInstanceResult, } from './workflow-instance.js';
|
|
33
33
|
export { runDetachedTurnWorkflowTick, SANDBOX_TRANSIENT_TICK_POLICY, type DetachedTurnTransientPolicy, type CloudflareWorkflowEventLike, type CloudflareWorkflowSleepDuration, type CloudflareWorkflowStepLike, type DetachedTurnDriveOutcome, type DetachedTurnDriveState, type DetachedTurnTerminalResult, type DetachedTurnWorkflowIdentity, type DetachedTurnWorkflowTickOptions, } from './detached-turn-workflow.js';
|
|
34
|
-
export { runNativeCompletionWorkflow, type NativeCompletionWorkflowOptions, type NativeCompletionWorkflowPayload, } from './native-completion-workflow.js';
|
|
34
|
+
export { runNativeCompletionWorkflow, type NativeCompletionWorkflowOptions, type NativeCompletionWorkflowPayload, type NativeCompletionWorkflowResult, type NativeCompletionTranscriptReference, } from './native-completion-workflow.js';
|
|
35
35
|
export * from './native-completion-store.js';
|
|
36
36
|
export * from './native-completion-owner.js';
|
|
37
37
|
export { renderCloudflareHeadersFile, type CloudflareHeadersRule, } from './headers.js';
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import "../chunk-KG2Y44XT.js";
|
|
2
2
|
import {
|
|
3
|
+
NATIVE_COMPLETION_RECEIPT_MAX_BYTES,
|
|
3
4
|
observeNativeCompletion
|
|
4
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-HES3IABJ.js";
|
|
5
6
|
import {
|
|
6
7
|
createFieldCrypto
|
|
7
8
|
} from "../chunk-AWIQQEFP.js";
|
|
@@ -41,7 +42,9 @@ import "../chunk-R32MULDK.js";
|
|
|
41
42
|
import {
|
|
42
43
|
createTurnTrace
|
|
43
44
|
} from "../chunk-YYA2CVOY.js";
|
|
44
|
-
import
|
|
45
|
+
import {
|
|
46
|
+
sha256Hex
|
|
47
|
+
} from "../chunk-HY57QRRW.js";
|
|
45
48
|
import "../chunk-F4XBNR5L.js";
|
|
46
49
|
import "../chunk-T3C2BX7N.js";
|
|
47
50
|
import "../chunk-TXD5HXLE.js";
|
|
@@ -151,6 +154,13 @@ async function runDetachedTurnWorkflowTick(options) {
|
|
|
151
154
|
}
|
|
152
155
|
|
|
153
156
|
// src/preset-cloudflare/native-completion-workflow.ts
|
|
157
|
+
var encoder = new TextEncoder();
|
|
158
|
+
function serializedBytes(value) {
|
|
159
|
+
return encoder.encode(JSON.stringify(value)).byteLength;
|
|
160
|
+
}
|
|
161
|
+
function receiptBody(receipt) {
|
|
162
|
+
return JSON.stringify({ text: receipt.text, parts: receipt.parts }, (_key, value) => value !== null && typeof value === "object" && !Array.isArray(value) ? Object.fromEntries(Object.keys(value).sort().map((key) => [key, value[key]])) : value);
|
|
163
|
+
}
|
|
154
164
|
function nativeCompletionPollDelay(attempt) {
|
|
155
165
|
if (attempt < 24) return "5 seconds";
|
|
156
166
|
if (attempt < 136) return "15 seconds";
|
|
@@ -163,22 +173,65 @@ function validObservation(value) {
|
|
|
163
173
|
if (value.state !== "running" && !value.receipt) {
|
|
164
174
|
throw new Error("native completion observer returned a terminal state without a receipt");
|
|
165
175
|
}
|
|
176
|
+
if (value.state !== "running" && value.receipt.state !== value.state) {
|
|
177
|
+
throw new Error("native completion observation contradicts its receipt state");
|
|
178
|
+
}
|
|
166
179
|
return value;
|
|
167
180
|
}
|
|
168
181
|
async function runNativeCompletionWorkflow(options) {
|
|
169
182
|
const name = options.stepName ?? "native-completion";
|
|
170
|
-
let
|
|
183
|
+
let observedReceipt;
|
|
184
|
+
const checkpoint = await runDetachedTurnWorkflowTick({
|
|
171
185
|
event: options.event,
|
|
172
186
|
step: options.step,
|
|
173
187
|
pollDelay: options.pollDelay ?? nativeCompletionPollDelay,
|
|
174
188
|
stepName: `${name}:observe`,
|
|
175
189
|
drive: async (payload) => {
|
|
176
190
|
const observation = validObservation(await options.observe(payload));
|
|
177
|
-
if (observation.state
|
|
191
|
+
if (observation.state === "running") return { succeeded: true, value: observation };
|
|
192
|
+
if (!("receipt" in observation)) throw new Error("native completion observer returned a reference instead of a receipt");
|
|
193
|
+
if (serializedBytes(observation) > NATIVE_COMPLETION_RECEIPT_MAX_BYTES) {
|
|
194
|
+
if (!options.readReceipt) throw new Error("Oversized native completion requires a read-only exact receipt reader");
|
|
195
|
+
const { text: _text, parts: _parts, ...metadata } = observation.receipt;
|
|
196
|
+
const serialized = receiptBody(observation.receipt);
|
|
197
|
+
const reference = {
|
|
198
|
+
state: observation.state,
|
|
199
|
+
receiptReference: {
|
|
200
|
+
sessionId: payload.sessionId,
|
|
201
|
+
turnId: payload.turnId,
|
|
202
|
+
turnIds: observation.receipt.completedTurnIds,
|
|
203
|
+
contentSha256: await sha256Hex(serialized),
|
|
204
|
+
bytes: encoder.encode(serialized).byteLength
|
|
205
|
+
},
|
|
206
|
+
metadata
|
|
207
|
+
};
|
|
208
|
+
if (serializedBytes(reference) > NATIVE_COMPLETION_RECEIPT_MAX_BYTES) {
|
|
209
|
+
throw new Error("Native completion reference metadata exceeds the checkpoint byte budget");
|
|
210
|
+
}
|
|
211
|
+
observedReceipt = observation.receipt;
|
|
212
|
+
return { succeeded: true, value: reference };
|
|
213
|
+
}
|
|
214
|
+
await options.persistTranscript(payload, observation.receipt);
|
|
178
215
|
return { succeeded: true, value: observation };
|
|
179
216
|
},
|
|
180
|
-
settle: async (_payload,
|
|
217
|
+
settle: async (_payload, result2) => "receipt" in result2 ? result2.receipt : result2
|
|
181
218
|
});
|
|
219
|
+
let receipt;
|
|
220
|
+
if ("receiptReference" in checkpoint) {
|
|
221
|
+
const reference = checkpoint.receiptReference;
|
|
222
|
+
if (reference.sessionId !== options.event.payload.sessionId || reference.turnId !== options.event.payload.turnId) {
|
|
223
|
+
throw new Error("Native completion reference belongs to another admission");
|
|
224
|
+
}
|
|
225
|
+
const retained = observedReceipt ?? await options.readReceipt?.(options.event.payload);
|
|
226
|
+
if (!retained) throw new Error("Native completion referenced receipt is unavailable; retry the exact native read");
|
|
227
|
+
const serialized = receiptBody(retained);
|
|
228
|
+
if (retained.state !== checkpoint.metadata.state || JSON.stringify(retained.completedTurnIds) !== JSON.stringify(reference.turnIds) || encoder.encode(serialized).byteLength !== reference.bytes || await sha256Hex(serialized) !== reference.contentSha256) {
|
|
229
|
+
throw new Error("Native completion referenced receipt changed; reconciliation is required");
|
|
230
|
+
}
|
|
231
|
+
receipt = { ...checkpoint.metadata, text: retained.text, parts: retained.parts };
|
|
232
|
+
} else {
|
|
233
|
+
receipt = checkpoint;
|
|
234
|
+
}
|
|
182
235
|
if (options.prepare) receipt = await options.prepare(options.event.payload, receipt);
|
|
183
236
|
const messageId = await options.step.do(`${name}:persist-transcript`, () => options.persistTranscript(options.event.payload, receipt));
|
|
184
237
|
const settledReceipt = await options.settle(options.event.payload, receipt, messageId);
|
|
@@ -186,6 +239,14 @@ async function runNativeCompletionWorkflow(options) {
|
|
|
186
239
|
receipt = settledReceipt;
|
|
187
240
|
await options.step.do(`${name}:persist-final-transcript`, () => options.persistTranscript(options.event.payload, receipt, messageId));
|
|
188
241
|
}
|
|
242
|
+
let result = receipt;
|
|
243
|
+
if (serializedBytes(receipt) > NATIVE_COMPLETION_RECEIPT_MAX_BYTES) {
|
|
244
|
+
const { text: _text, parts: _parts, ...metadata } = receipt;
|
|
245
|
+
result = { ...metadata, transcriptReference: { messageId, omitted: ["text", "parts"] } };
|
|
246
|
+
if (serializedBytes(result) > NATIVE_COMPLETION_RECEIPT_MAX_BYTES) {
|
|
247
|
+
throw new Error("Native completion transcript reference metadata exceeds the output byte budget");
|
|
248
|
+
}
|
|
249
|
+
}
|
|
189
250
|
if (options.recordTiming) {
|
|
190
251
|
await options.step.do(`${name}:record-timing`, () => options.recordTiming(options.event.payload, receipt, { settledAt: Date.now() }));
|
|
191
252
|
}
|
|
@@ -194,7 +255,7 @@ async function runNativeCompletionWorkflow(options) {
|
|
|
194
255
|
}
|
|
195
256
|
await options.step.do(`${name}:release-lock`, () => options.releaseLock(options.event.payload));
|
|
196
257
|
await options.afterRelease?.(options.event.payload, receipt);
|
|
197
|
-
return
|
|
258
|
+
return result;
|
|
198
259
|
}
|
|
199
260
|
|
|
200
261
|
// src/preset-cloudflare/native-completion-store.ts
|
|
@@ -282,7 +343,7 @@ function createD1NativeCompletionStore(db, table) {
|
|
|
282
343
|
|
|
283
344
|
// src/preset-cloudflare/native-completion-owner.ts
|
|
284
345
|
var NATIVE_CHECKPOINT_MAX_BYTES = 256 * 1024;
|
|
285
|
-
var
|
|
346
|
+
var encoder2 = new TextEncoder();
|
|
286
347
|
async function nativeCompletionWorkflowId(executionId, prefix) {
|
|
287
348
|
const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(executionId));
|
|
288
349
|
return `${prefix}-${Array.from(new Uint8Array(digest), (b) => b.toString(16).padStart(2, "0")).join("")}`;
|
|
@@ -319,9 +380,9 @@ function nativeCompletionCheckpoint(trace, timing, turnStartedAt) {
|
|
|
319
380
|
queries: timing.queries()
|
|
320
381
|
};
|
|
321
382
|
const spans = trace.spans(now);
|
|
322
|
-
let bytes =
|
|
383
|
+
let bytes = encoder2.encode(JSON.stringify(checkpoint)).byteLength + 1024;
|
|
323
384
|
for (const span of spans) {
|
|
324
|
-
const size =
|
|
385
|
+
const size = encoder2.encode(JSON.stringify(span)).byteLength + 1;
|
|
325
386
|
if (bytes + size > NATIVE_CHECKPOINT_MAX_BYTES) break;
|
|
326
387
|
checkpoint.trace.spans.push(span);
|
|
327
388
|
bytes += size;
|
|
@@ -330,7 +391,7 @@ function nativeCompletionCheckpoint(trace, timing, turnStartedAt) {
|
|
|
330
391
|
checkpoint.trace.truncatedSpans = truncated;
|
|
331
392
|
checkpoint.trace.summary.dropped += truncated;
|
|
332
393
|
if (truncated) checkpoint.checkpointTruncated = true;
|
|
333
|
-
if (
|
|
394
|
+
if (encoder2.encode(JSON.stringify(checkpoint)).byteLength > NATIVE_CHECKPOINT_MAX_BYTES) {
|
|
334
395
|
throw new Error("Native completion checkpoint metadata exceeds its byte budget");
|
|
335
396
|
}
|
|
336
397
|
return checkpoint;
|
|
@@ -430,6 +491,14 @@ function createNativeCompletionOwner(options) {
|
|
|
430
491
|
const { payload } = await required();
|
|
431
492
|
return input.observe ? input.observe(payload) : observe(payload, await input.source(payload));
|
|
432
493
|
},
|
|
494
|
+
readReceipt: async () => {
|
|
495
|
+
const row = await required();
|
|
496
|
+
if (input.readReceipt) return input.readReceipt(row.payload);
|
|
497
|
+
if (input.observe) throw new Error("Custom native completion observation requires its read-only receipt reader");
|
|
498
|
+
if (row.state !== "closed") return null;
|
|
499
|
+
const observation = await observe(row.payload, await input.source(row.payload), true);
|
|
500
|
+
return observation.state === "running" ? null : observation.receipt;
|
|
501
|
+
},
|
|
433
502
|
prepare: async (_initial, receipt) => {
|
|
434
503
|
if ((await required()).vaultReconciledAt) return receipt;
|
|
435
504
|
for (let pass = 0; ; pass++) {
|