@tangle-network/agent-app 0.62.3 → 0.63.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 +1 -1
- package/dist/agent-profiles/d1.js +1 -1
- package/dist/agent-profiles/index.d.ts +4 -1
- package/dist/agent-profiles/index.js +1 -1
- package/dist/app-auth/index.js +2 -2
- package/dist/assistant/index.js +7 -7
- package/dist/chat-react/index.js +3 -3
- package/dist/chat-routes/cancellation.d.ts +61 -0
- package/dist/chat-routes/dispatch-first.d.ts +14 -25
- package/dist/chat-routes/early-turn-work.d.ts +10 -0
- package/dist/chat-routes/hybrid-producer.d.ts +4 -3
- package/dist/chat-routes/index.d.ts +2 -1
- package/dist/chat-routes/index.js +86 -1874
- package/dist/chat-routes/index.js.map +1 -1
- package/dist/chat-routes/native-turn-timing.d.ts +15 -0
- package/dist/chat-routes/producer-stream.d.ts +5 -0
- package/dist/chat-routes/route-producer.d.ts +3 -0
- package/dist/chat-routes/route-storage.d.ts +7 -0
- package/dist/chat-routes/router-producer.d.ts +31 -5
- package/dist/chat-routes/turn-admission.d.ts +2 -1
- package/dist/chat-routes/turn-execution.d.ts +6 -11
- package/dist/chat-routes/turn-ownership.d.ts +22 -0
- package/dist/chat-routes/turn-route-contracts.d.ts +112 -105
- package/dist/chat-routes/turn-routes.d.ts +4 -4
- package/dist/chat-routes/wire.d.ts +0 -7
- package/dist/chat-store/index.d.ts +1 -1
- package/dist/chat-store/index.js +21 -3
- package/dist/chat-store/index.js.map +1 -1
- package/dist/chat-store/schema.d.ts +3 -2
- package/dist/chat-store/store.d.ts +8 -0
- package/dist/{chunk-GIEUZBQQ.js → chunk-4CALWPN5.js} +3 -7
- package/dist/chunk-4CALWPN5.js.map +1 -0
- package/dist/chunk-4DBHC63F.js +54 -0
- package/dist/chunk-4DBHC63F.js.map +1 -0
- package/dist/{chunk-G7M2C72Q.js → chunk-5TSRFF5W.js} +1 -1
- package/dist/chunk-5TSRFF5W.js.map +1 -0
- package/dist/chunk-A2NQMVMF.js +485 -0
- package/dist/chunk-A2NQMVMF.js.map +1 -0
- package/dist/{chunk-PCAY23GS.js → chunk-AVBNS64P.js} +172 -2
- package/dist/chunk-AVBNS64P.js.map +1 -0
- package/dist/{chunk-4P5NFBWX.js → chunk-BI5AZAOO.js} +4 -4
- package/dist/chunk-BV3VZEKB.js +483 -0
- package/dist/chunk-BV3VZEKB.js.map +1 -0
- package/dist/{chunk-UW2DKTEM.js → chunk-IDG2XR5O.js} +20 -10
- package/dist/chunk-IDG2XR5O.js.map +1 -0
- package/dist/{chunk-KS4I7KVC.js → chunk-JRTWTADT.js} +184 -123
- package/dist/chunk-JRTWTADT.js.map +1 -0
- package/dist/chunk-KG2Y44XT.js +1 -0
- package/dist/chunk-KG2Y44XT.js.map +1 -0
- package/dist/chunk-MM3GOLHO.js +3365 -0
- package/dist/chunk-MM3GOLHO.js.map +1 -0
- package/dist/chunk-N6URQ6DM.js +225 -0
- package/dist/chunk-N6URQ6DM.js.map +1 -0
- package/dist/{chunk-ISRPOPMM.js → chunk-ND5XWLRU.js} +21 -18
- package/dist/chunk-ND5XWLRU.js.map +1 -0
- package/dist/{chunk-IUVDR3KJ.js → chunk-NHVSO47Q.js} +2 -2
- package/dist/{chunk-FAXSYC2C.js → chunk-RZLCBWGG.js} +2 -2
- package/dist/{chunk-MRZP65DZ.js → chunk-SRWQCWLR.js} +14 -3
- package/dist/chunk-SRWQCWLR.js.map +1 -0
- package/dist/{chunk-JRW6LCIA.js → chunk-V6YGLAQC.js} +2 -2
- package/dist/{chunk-54YIL7WM.js → chunk-WPPDNS63.js} +4 -4
- package/dist/{chunk-CQZVJVME.js → chunk-YCMVNXAX.js} +2 -2
- package/dist/design-canvas/index.js +3 -3
- package/dist/openui/index.js +3 -3
- package/dist/operator/index.js +2 -2
- package/dist/platform/billable-turn-admission.d.ts +13 -9
- package/dist/platform/delegated-keys.d.ts +4 -3
- package/dist/platform/delegated-turn-keys.d.ts +17 -6
- package/dist/platform/index.js +80 -23
- package/dist/platform/index.js.map +1 -1
- package/dist/preset-cloudflare/index.d.ts +2 -0
- package/dist/preset-cloudflare/index.js +344 -0
- package/dist/preset-cloudflare/index.js.map +1 -1
- package/dist/preset-cloudflare/native-completion-owner.d.ts +90 -0
- package/dist/preset-cloudflare/native-completion-store.d.ts +56 -0
- package/dist/preset-cloudflare/native-completion-workflow.d.ts +10 -0
- package/dist/public-consultation/index.js +28 -7
- package/dist/public-consultation/index.js.map +1 -1
- package/dist/rollout/d1.d.ts +103 -3
- package/dist/rollout/d1.js +152 -5
- package/dist/rollout/d1.js.map +1 -1
- package/dist/runtime/index.js +3 -4
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/router-turn.d.ts +4 -0
- package/dist/runtime/router-turn.js +2 -3
- package/dist/sandbox/index.js +3 -4
- package/dist/sandbox/sandbox-run-tool.d.ts +5 -0
- package/dist/sequences/index.js +5 -5
- package/dist/signoff/cli.js +15 -3
- package/dist/signoff/cli.js.map +1 -1
- package/dist/signoff/config.d.ts +3 -1
- package/dist/signoff/index.d.ts +2 -1
- package/dist/signoff/index.js +3 -1
- package/dist/signoff/phases.d.ts +3 -0
- package/dist/signoff/proof.js +3 -0
- package/dist/signoff/proof.js.map +1 -1
- package/dist/signoff/run.d.ts +3 -1
- package/dist/signoff/types.d.ts +13 -0
- package/dist/skills-placement/box.js +5 -5
- package/dist/skills-placement/index.js +2 -2
- package/dist/tools/index.js +1 -1
- package/dist/turn-stream/adapters.d.ts +10 -4
- package/dist/turn-stream/index.js +33 -356
- package/dist/turn-stream/index.js.map +1 -1
- package/dist/turn-trace/index.d.ts +1 -0
- package/dist/turn-trace/index.js +4 -5
- package/dist/turn-trace/phase-timing.d.ts +20 -0
- package/dist/turn-trace/recorder.d.ts +3 -0
- package/dist/turn-trace/turn-facts.d.ts +17 -0
- package/dist/web-react/agent-profile-editor.js +1 -1
- package/dist/web-react/chat-stream.d.ts +0 -7
- package/dist/web-react/index.js +7 -9
- package/dist/work-product/index.js +7 -7
- package/package.json +1 -1
- package/dist/chat-routes/minted-thread.d.ts +0 -63
- package/dist/chunk-6R73V3Y5.js +0 -17
- package/dist/chunk-6R73V3Y5.js.map +0 -1
- package/dist/chunk-CCVWR33L.js +0 -99
- package/dist/chunk-CCVWR33L.js.map +0 -1
- package/dist/chunk-EFQUAWWF.js +0 -1749
- package/dist/chunk-EFQUAWWF.js.map +0 -1
- package/dist/chunk-G7M2C72Q.js.map +0 -1
- package/dist/chunk-GIEUZBQQ.js.map +0 -1
- package/dist/chunk-ISRPOPMM.js.map +0 -1
- package/dist/chunk-KS4I7KVC.js.map +0 -1
- package/dist/chunk-MRZP65DZ.js.map +0 -1
- package/dist/chunk-PCAY23GS.js.map +0 -1
- package/dist/chunk-UW2DKTEM.js.map +0 -1
- package/dist/chunk-VK3F4N4U.js +0 -133
- package/dist/chunk-VK3F4N4U.js.map +0 -1
- /package/dist/{chunk-4P5NFBWX.js.map → chunk-BI5AZAOO.js.map} +0 -0
- /package/dist/{chunk-IUVDR3KJ.js.map → chunk-NHVSO47Q.js.map} +0 -0
- /package/dist/{chunk-FAXSYC2C.js.map → chunk-RZLCBWGG.js.map} +0 -0
- /package/dist/{chunk-JRW6LCIA.js.map → chunk-V6YGLAQC.js.map} +0 -0
- /package/dist/{chunk-54YIL7WM.js.map → chunk-WPPDNS63.js.map} +0 -0
- /package/dist/{chunk-CQZVJVME.js.map → chunk-YCMVNXAX.js.map} +0 -0
package/dist/platform/index.js
CHANGED
|
@@ -21,21 +21,21 @@ import {
|
|
|
21
21
|
resolveTangleSsoAccount,
|
|
22
22
|
signSessionCookieValue,
|
|
23
23
|
verifySignedSsoState
|
|
24
|
-
} from "../chunk-
|
|
25
|
-
import {
|
|
26
|
-
createWarmCache
|
|
27
|
-
} from "../chunk-F4TUZYMX.js";
|
|
24
|
+
} from "../chunk-BI5AZAOO.js";
|
|
28
25
|
import {
|
|
29
26
|
assertWorkspaceKeyCryptoUsable
|
|
30
27
|
} from "../chunk-VGS2NXLB.js";
|
|
31
|
-
import {
|
|
32
|
-
resolveTangleExecutionEnvironment
|
|
33
|
-
} from "../chunk-D6UJEOZQ.js";
|
|
34
28
|
import "../chunk-CQGEGPY7.js";
|
|
35
29
|
import "../chunk-RN4WPTBH.js";
|
|
36
30
|
import {
|
|
37
31
|
parseJsonObjectBody
|
|
38
32
|
} from "../chunk-WP2GYFZ4.js";
|
|
33
|
+
import {
|
|
34
|
+
createWarmCache
|
|
35
|
+
} from "../chunk-F4TUZYMX.js";
|
|
36
|
+
import {
|
|
37
|
+
resolveTangleExecutionEnvironment
|
|
38
|
+
} from "../chunk-D6UJEOZQ.js";
|
|
39
39
|
import {
|
|
40
40
|
sha256Hex
|
|
41
41
|
} from "../chunk-HY57QRRW.js";
|
|
@@ -873,8 +873,16 @@ function childProblem(data, request, name, serviceName, nowMs) {
|
|
|
873
873
|
function createPlatformDelegatedKeyClient(options) {
|
|
874
874
|
const fetchImpl = options.fetch ?? fetch;
|
|
875
875
|
const now = options.now ?? Date.now;
|
|
876
|
-
const
|
|
877
|
-
const
|
|
876
|
+
const env = () => globalThis.process?.env;
|
|
877
|
+
const origin = options.platformUrl ?? env()?.TANGLE_PLATFORM_URL ?? env()?.TANGLE_SSO_URL;
|
|
878
|
+
if (!origin) throw new Error("TANGLE_PLATFORM_URL is required for delegated product keys");
|
|
879
|
+
const base = options.platformUrl ? origin.replace(/\/+$/, "") : new URL(origin).origin;
|
|
880
|
+
const serviceToken = () => {
|
|
881
|
+
if (options.serviceToken !== void 0) return typeof options.serviceToken === "function" ? options.serviceToken() : options.serviceToken;
|
|
882
|
+
const token = env()?.PLATFORM_SERVICE_TOKEN?.trim();
|
|
883
|
+
if (!token) throw new Error("PLATFORM_SERVICE_TOKEN is required for delegated product keys");
|
|
884
|
+
return token;
|
|
885
|
+
};
|
|
878
886
|
async function call(path, init) {
|
|
879
887
|
try {
|
|
880
888
|
const response = await fetchImpl(`${base}${path}`, {
|
|
@@ -1176,7 +1184,7 @@ function createDelegatedTurnKeys(options) {
|
|
|
1176
1184
|
const expiresAt = new Date(Math.min(now() + input.ttlMs, input.notAfter?.getTime() ?? Infinity));
|
|
1177
1185
|
const outcome = await options.client.delegate({
|
|
1178
1186
|
...input.scope,
|
|
1179
|
-
name: `turn:${input.turnId}`,
|
|
1187
|
+
name: `turn:${input.turnId}:${crypto.randomUUID()}`,
|
|
1180
1188
|
expiresAt,
|
|
1181
1189
|
...input.retryUnavailable ? { retryUnavailable: input.retryUnavailable } : {}
|
|
1182
1190
|
});
|
|
@@ -1197,6 +1205,42 @@ function createDelegatedTurnKeys(options) {
|
|
|
1197
1205
|
} } : {}
|
|
1198
1206
|
}).catch(() => null);
|
|
1199
1207
|
}
|
|
1208
|
+
function lease(input, key) {
|
|
1209
|
+
const turn = { ...input, scope: {
|
|
1210
|
+
...input.scope,
|
|
1211
|
+
...input.scope.allowedModels ? { allowedModels: [...input.scope.allowedModels] } : {},
|
|
1212
|
+
...input.scope.budget ? { budget: { ...input.scope.budget } } : {},
|
|
1213
|
+
...input.scope.resource ? { resource: { ...input.scope.resource } } : {},
|
|
1214
|
+
...input.scope.expect ? { expect: { ...input.scope.expect } } : {}
|
|
1215
|
+
}, ...input.notAfter ? { notAfter: new Date(input.notAfter) } : {} };
|
|
1216
|
+
const held = /* @__PURE__ */ new Set([key.id]);
|
|
1217
|
+
const closed = { succeeded: false, error: {
|
|
1218
|
+
status: 409,
|
|
1219
|
+
code: "delegated_key.refused",
|
|
1220
|
+
message: "The turn key lease is closed."
|
|
1221
|
+
} };
|
|
1222
|
+
let released = false;
|
|
1223
|
+
let replacement;
|
|
1224
|
+
let retirement;
|
|
1225
|
+
const fetchImpl = delegatedKeyFallbackFetch({
|
|
1226
|
+
key,
|
|
1227
|
+
fetch: (resource, init) => released ? Promise.reject(new Error(closed.error.message)) : fetch(resource, init),
|
|
1228
|
+
remint: () => {
|
|
1229
|
+
if (released) return Promise.resolve(closed);
|
|
1230
|
+
return replacement ??= mint(turn, false).then((outcome) => {
|
|
1231
|
+
if (outcome.succeeded) held.add(outcome.value.id);
|
|
1232
|
+
return released ? closed : outcome;
|
|
1233
|
+
});
|
|
1234
|
+
}
|
|
1235
|
+
});
|
|
1236
|
+
return { ...key, fetchImpl, revoke() {
|
|
1237
|
+
released = true;
|
|
1238
|
+
return retirement ??= (async () => {
|
|
1239
|
+
await replacement?.catch(() => void 0);
|
|
1240
|
+
await Promise.all([...held].map((id) => retire(turn, id)));
|
|
1241
|
+
})();
|
|
1242
|
+
} };
|
|
1243
|
+
}
|
|
1200
1244
|
async function claim(input, timing) {
|
|
1201
1245
|
if (!db) return null;
|
|
1202
1246
|
const { slot, scope } = input;
|
|
@@ -1204,8 +1248,8 @@ function createDelegatedTurnKeys(options) {
|
|
|
1204
1248
|
const digest = await scopeDigest(scope);
|
|
1205
1249
|
timing.digestMs = Date.now() - at;
|
|
1206
1250
|
at = Date.now();
|
|
1207
|
-
const row = await db.prepare(`DELETE FROM ${table} WHERE slot = ?1 AND scope = ?2 AND expires_at > ?3
|
|
1208
|
-
RETURNING turn_id, key_id, key_encrypted, expires_at`).bind(slot, digest, now() + minRemainingMs).first();
|
|
1251
|
+
const row = await db.prepare(`DELETE FROM ${table} WHERE slot = ?1 AND scope = ?2 AND expires_at > ?3 AND expires_at <= ?4
|
|
1252
|
+
RETURNING turn_id, key_id, key_encrypted, expires_at`).bind(slot, digest, now() + minRemainingMs, input.notAfter?.getTime() ?? Number.MAX_SAFE_INTEGER).first();
|
|
1209
1253
|
timing.storeMs = Date.now() - at;
|
|
1210
1254
|
if (!row) return null;
|
|
1211
1255
|
try {
|
|
@@ -1224,7 +1268,7 @@ RETURNING turn_id, key_id, key_encrypted, expires_at`).bind(slot, digest, now()
|
|
|
1224
1268
|
try {
|
|
1225
1269
|
scope = await scopeDigest(input.scope);
|
|
1226
1270
|
const held = await db.prepare(`SELECT scope, expires_at FROM ${table} WHERE slot = ?1`).bind(input.slot).first();
|
|
1227
|
-
if (held?.scope === scope && held.expires_at > now() + minRemainingMs + PREMINT_KEEP_SLACK_MS) {
|
|
1271
|
+
if (held?.scope === scope && held.expires_at > now() + minRemainingMs + PREMINT_KEEP_SLACK_MS && held.expires_at <= (input.notAfter?.getTime() ?? Infinity)) {
|
|
1228
1272
|
emit({ type: "park_kept", slot: input.slot });
|
|
1229
1273
|
return true;
|
|
1230
1274
|
}
|
|
@@ -1238,7 +1282,10 @@ RETURNING turn_id, key_id, key_encrypted, expires_at`).bind(slot, digest, now()
|
|
|
1238
1282
|
emit({ type: "park_failed", slot: input.slot, code: "premint_crypto_unusable" });
|
|
1239
1283
|
return false;
|
|
1240
1284
|
}
|
|
1241
|
-
const minted = await mint({ ...input, turnId: crypto.randomUUID() }, true)
|
|
1285
|
+
const minted = await mint({ ...input, turnId: crypto.randomUUID() }, true).catch(() => ({
|
|
1286
|
+
succeeded: false,
|
|
1287
|
+
error: { status: 502, code: "delegated_key.failed", message: "Background turn-key mint failed." }
|
|
1288
|
+
}));
|
|
1242
1289
|
if (!minted.succeeded) {
|
|
1243
1290
|
emit({ type: "park_failed", slot: input.slot, code: minted.error.code });
|
|
1244
1291
|
return false;
|
|
@@ -1281,9 +1328,18 @@ VALUES (?1, ?2, ?3, ?4, ?5, ?6) ON CONFLICT(slot) DO NOTHING RETURNING slot`).bi
|
|
|
1281
1328
|
slot: input.slot,
|
|
1282
1329
|
...timing.digestMs !== void 0 && timing.storeMs !== void 0 ? { timing } : {}
|
|
1283
1330
|
});
|
|
1284
|
-
|
|
1331
|
+
const outcome = claimed ? { succeeded: true, value: claimed } : await mint(input, false);
|
|
1332
|
+
return outcome.succeeded ? { succeeded: true, value: lease(input, outcome.value) } : outcome;
|
|
1285
1333
|
},
|
|
1286
1334
|
park,
|
|
1335
|
+
async forget(input) {
|
|
1336
|
+
if (!db) return;
|
|
1337
|
+
try {
|
|
1338
|
+
const row = await db.prepare(`DELETE FROM ${table} WHERE slot = ?1 AND scope = ?2 RETURNING key_id`).bind(input.slot, await scopeDigest(input.scope)).first();
|
|
1339
|
+
if (row) await retire(input, row.key_id);
|
|
1340
|
+
} catch {
|
|
1341
|
+
}
|
|
1342
|
+
},
|
|
1287
1343
|
mint: (input) => mint(input, false)
|
|
1288
1344
|
};
|
|
1289
1345
|
}
|
|
@@ -1326,12 +1382,13 @@ function delegatedKeyFallbackFetch(input) {
|
|
|
1326
1382
|
|
|
1327
1383
|
// src/platform/billable-turn-admission.ts
|
|
1328
1384
|
function createBillableTurnAdmission(options) {
|
|
1329
|
-
|
|
1385
|
+
const windowMs = options.windowMs ?? 5 * 6e4;
|
|
1386
|
+
if (!(Number.isFinite(windowMs) && windowMs > 0)) {
|
|
1330
1387
|
throw new Error("createBillableTurnAdmission: windowMs must be a positive number of milliseconds");
|
|
1331
1388
|
}
|
|
1332
1389
|
const verdicts = createWarmCache(options.namespace, { isolate: false, env: options.env });
|
|
1333
1390
|
const keyOf = options.key ?? ((input) => input.userId);
|
|
1334
|
-
const heldMs = (paidThrough) => Math.min(
|
|
1391
|
+
const heldMs = (paidThrough) => Math.min(windowMs, paidThrough ? Date.parse(paidThrough) - Date.now() : Infinity);
|
|
1335
1392
|
return {
|
|
1336
1393
|
heldMs,
|
|
1337
1394
|
forget: (key) => verdicts.forget(key),
|
|
@@ -1339,7 +1396,7 @@ function createBillableTurnAdmission(options) {
|
|
|
1339
1396
|
const key = keyOf(input);
|
|
1340
1397
|
const warm = input.refresh ? null : await verdicts.read(key);
|
|
1341
1398
|
if (warm && (warm.value.paidThrough === null || Date.parse(warm.value.paidThrough) > Date.now())) {
|
|
1342
|
-
return { source: warm.source };
|
|
1399
|
+
return { source: warm.source, allowed: true, paidThrough: warm.value.paidThrough };
|
|
1343
1400
|
}
|
|
1344
1401
|
const track = input.track ?? ((_name, work) => work);
|
|
1345
1402
|
const mapError = input.mapError ?? ((error) => {
|
|
@@ -1347,24 +1404,24 @@ function createBillableTurnAdmission(options) {
|
|
|
1347
1404
|
});
|
|
1348
1405
|
const [seatSettled, balanceSettled] = await Promise.allSettled([
|
|
1349
1406
|
track("gate_seat", options.readSeat(input).catch(mapError)),
|
|
1350
|
-
track("gate_balance", options.readBalance(input).catch(mapError))
|
|
1407
|
+
options.readBalance ? track("gate_balance", options.readBalance(input).catch(mapError)) : Promise.resolve(void 0)
|
|
1351
1408
|
]);
|
|
1352
1409
|
if (seatSettled.status === "rejected") throw seatSettled.reason;
|
|
1353
1410
|
const seat = seatSettled.value;
|
|
1354
1411
|
if (!seat.allowed) {
|
|
1355
1412
|
await verdicts.forget(key);
|
|
1356
|
-
return { source: "platform", seat };
|
|
1413
|
+
return { source: "platform", allowed: false, paidThrough: seat.paidThrough ?? null, seat };
|
|
1357
1414
|
}
|
|
1358
1415
|
if (balanceSettled.status === "rejected") throw balanceSettled.reason;
|
|
1359
1416
|
const balance = balanceSettled.value;
|
|
1360
|
-
if (!balance.allowed) {
|
|
1417
|
+
if (options.readBalance && !balance.allowed) {
|
|
1361
1418
|
await verdicts.forget(key);
|
|
1362
|
-
return { source: "platform", seat, balance };
|
|
1419
|
+
return { source: "platform", allowed: false, paidThrough: seat.paidThrough ?? null, seat, balance };
|
|
1363
1420
|
}
|
|
1364
1421
|
const paidThrough = seat.paidThrough ?? null;
|
|
1365
1422
|
const ttlMs = heldMs(paidThrough);
|
|
1366
1423
|
if (ttlMs > 0) await verdicts.write(key, { paidThrough }, ttlMs);
|
|
1367
|
-
return { source: "platform", seat, balance };
|
|
1424
|
+
return { source: "platform", allowed: true, paidThrough, seat, balance };
|
|
1368
1425
|
}
|
|
1369
1426
|
};
|
|
1370
1427
|
}
|