@tangle-network/agent-app 0.48.2 → 0.48.3

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.
Files changed (53) hide show
  1. package/dist/DesignCanvas-YLVDCX6H.js +11 -0
  2. package/dist/DesignCanvasEditor-4QWY2LHM.js +14 -0
  3. package/dist/app-auth/index.js +2 -2
  4. package/dist/chat-routes/completed-sandbox-turn.d.ts +3 -3
  5. package/dist/chat-routes/detached-turn.d.ts +2 -2
  6. package/dist/chat-routes/draft-persistence.d.ts +1 -1
  7. package/dist/chat-routes/index.js +33 -37
  8. package/dist/chat-routes/index.js.map +1 -1
  9. package/dist/{chunk-VHMZ3KUH.js → chunk-2WVBGQ2Y.js} +2 -2
  10. package/dist/chunk-3NM4GCAY.js +170 -0
  11. package/dist/chunk-3NM4GCAY.js.map +1 -0
  12. package/dist/{chunk-WYHFHTSQ.js → chunk-BWQPVS7D.js} +2 -2
  13. package/dist/{chunk-IAY2DMKW.js → chunk-EA4UVS4T.js} +61 -2
  14. package/dist/chunk-EA4UVS4T.js.map +1 -0
  15. package/dist/{chunk-AKMQFCDL.js → chunk-FEVVF6JJ.js} +2 -2
  16. package/dist/{chunk-JF423ASS.js → chunk-G2B23BZ6.js} +5 -5
  17. package/dist/{chunk-JAT6SOPK.js → chunk-KWN5PGXM.js} +3 -3
  18. package/dist/{chunk-SYWEMKZR.js → chunk-MFLUDFD3.js} +3 -3
  19. package/dist/chunk-MFLUDFD3.js.map +1 -0
  20. package/dist/{chunk-CSMJM7YT.js → chunk-TWTLQWES.js} +2 -2
  21. package/dist/{chunk-KX2GA3L6.js → chunk-WAMJSZYB.js} +3 -3
  22. package/dist/design-canvas/index.js +2 -2
  23. package/dist/design-canvas-react/engine.js +4 -4
  24. package/dist/design-canvas-react/index.js +7 -7
  25. package/dist/design-canvas-react/lazy.js +1 -1
  26. package/dist/platform/index.js +2 -2
  27. package/dist/preset-cloudflare/detached-turn-workflow.d.ts +6 -20
  28. package/dist/preset-cloudflare/index.js +13 -10
  29. package/dist/preset-cloudflare/index.js.map +1 -1
  30. package/dist/public-consultation/index.js +3 -3
  31. package/dist/sequences/index.js +1 -1
  32. package/dist/stream/index.d.ts +1 -0
  33. package/dist/stream/index.js +7 -1
  34. package/dist/stream/turn-observation.d.ts +32 -0
  35. package/dist/web/api-key-fetch.d.ts +12 -0
  36. package/dist/web/index.d.ts +1 -0
  37. package/dist/web/index.js +3 -1
  38. package/package.json +1 -1
  39. package/dist/DesignCanvas-MWEYD6PR.js +0 -11
  40. package/dist/DesignCanvasEditor-UZ2S6BDD.js +0 -14
  41. package/dist/chunk-IAY2DMKW.js.map +0 -1
  42. package/dist/chunk-JEZJ6HTF.js +0 -77
  43. package/dist/chunk-JEZJ6HTF.js.map +0 -1
  44. package/dist/chunk-SYWEMKZR.js.map +0 -1
  45. /package/dist/{DesignCanvas-MWEYD6PR.js.map → DesignCanvas-YLVDCX6H.js.map} +0 -0
  46. /package/dist/{DesignCanvasEditor-UZ2S6BDD.js.map → DesignCanvasEditor-4QWY2LHM.js.map} +0 -0
  47. /package/dist/{chunk-VHMZ3KUH.js.map → chunk-2WVBGQ2Y.js.map} +0 -0
  48. /package/dist/{chunk-WYHFHTSQ.js.map → chunk-BWQPVS7D.js.map} +0 -0
  49. /package/dist/{chunk-AKMQFCDL.js.map → chunk-FEVVF6JJ.js.map} +0 -0
  50. /package/dist/{chunk-JF423ASS.js.map → chunk-G2B23BZ6.js.map} +0 -0
  51. /package/dist/{chunk-JAT6SOPK.js.map → chunk-KWN5PGXM.js.map} +0 -0
  52. /package/dist/{chunk-CSMJM7YT.js.map → chunk-TWTLQWES.js.map} +0 -0
  53. /package/dist/{chunk-KX2GA3L6.js.map → chunk-WAMJSZYB.js.map} +0 -0
@@ -0,0 +1,11 @@
1
+ import {
2
+ DesignCanvas
3
+ } from "./chunk-KWN5PGXM.js";
4
+ import "./chunk-FEVVF6JJ.js";
5
+ import "./chunk-BWQPVS7D.js";
6
+ import "./chunk-EA4UVS4T.js";
7
+ import "./chunk-TXD5HXLE.js";
8
+ export {
9
+ DesignCanvas
10
+ };
11
+ //# sourceMappingURL=DesignCanvas-YLVDCX6H.js.map
@@ -0,0 +1,14 @@
1
+ import {
2
+ DesignCanvasEditor
3
+ } from "./chunk-G2B23BZ6.js";
4
+ import "./chunk-KWN5PGXM.js";
5
+ import "./chunk-Q2QKEV6J.js";
6
+ import "./chunk-2WVBGQ2Y.js";
7
+ import "./chunk-FEVVF6JJ.js";
8
+ import "./chunk-BWQPVS7D.js";
9
+ import "./chunk-EA4UVS4T.js";
10
+ import "./chunk-TXD5HXLE.js";
11
+ export {
12
+ DesignCanvasEditor
13
+ };
14
+ //# sourceMappingURL=DesignCanvasEditor-4QWY2LHM.js.map
@@ -2,9 +2,9 @@ import {
2
2
  createAuthGuard,
3
3
  createBetterAuthSessionCookieMinter,
4
4
  createTangleSsoHandlers
5
- } from "../chunk-CSMJM7YT.js";
5
+ } from "../chunk-TWTLQWES.js";
6
6
  import "../chunk-JML7WKWU.js";
7
- import "../chunk-IAY2DMKW.js";
7
+ import "../chunk-EA4UVS4T.js";
8
8
  import "../chunk-TXD5HXLE.js";
9
9
 
10
10
  // src/app-auth/index.ts
@@ -18,8 +18,8 @@ export interface ReadCompletedSandboxTurnOptions {
18
18
  log?: (message: string, meta?: Record<string, unknown>) => void;
19
19
  }
20
20
  /**
21
- * Read the exact completed turn. The session-level result is consulted only
22
- * when the matching completed assistant message is still the latest message;
23
- * otherwise that result could belong to a newer turn on the same session.
21
+ * Read the exact completed turn from its keyed cache and completed message.
22
+ * Never borrow a session-wide aggregate from a concurrently advancing session.
23
+ * Observation failure is retryable and distinct from successful absent reads.
24
24
  */
25
25
  export declare function readCompletedSandboxTurn(box: CompletedSandboxTurnSource, options: ReadCompletedSandboxTurnOptions): Promise<DetachedTurnFinal | null>;
@@ -109,8 +109,8 @@ export interface DetachedTurnOptions {
109
109
  * A crash mid-run leaves buffered rows at seqs 1..N with status `running`;
110
110
  * re-streaming restarts the tap's seq at 0 and would duplicate/interleave
111
111
  * rows. Wire this (delete `turnId`'s buffered events) so a retry is clean.
112
- * Unset, a re-stream over a `running` buffer is still attempted but logged
113
- * as a possible-duplication hazard. */
112
+ * A re-stream over an existing `running` buffer requires this operation to
113
+ * succeed. Missing or failed reset leaves the existing stream untouched. */
114
114
  resetBuffer?: (turnId: string) => Promise<void>;
115
115
  /** Own the durable assistant row for this turn instead of returning the body
116
116
  * for the caller to insert — and keep it in step with the stream.
@@ -40,7 +40,7 @@
40
40
  import { type ChatMessagePart } from '../chat-store/parts';
41
41
  import type { ChatTurnUsage } from './turn-routes';
42
42
  /** Message row shape the writer reads back when re-entering a turn. */
43
- export interface DraftStoredMessage {
43
+ export interface DraftStoredMessage extends Pick<AssistantRowValues, keyof ChatTurnUsage> {
44
44
  id: string;
45
45
  role: 'user' | 'assistant' | 'system' | 'tool';
46
46
  content: string;
@@ -61,9 +61,9 @@ import {
61
61
  rowIdOf,
62
62
  storeSupportsDraftPersistence,
63
63
  streamChatRouteAsSandboxEvents
64
- } from "../chunk-SYWEMKZR.js";
64
+ } from "../chunk-MFLUDFD3.js";
65
65
  import "../chunk-ZSSCVT6H.js";
66
- import "../chunk-IAY2DMKW.js";
66
+ import "../chunk-EA4UVS4T.js";
67
67
  import {
68
68
  attachmentInputToPart,
69
69
  attachmentKindForMime,
@@ -94,7 +94,7 @@ import {
94
94
  import {
95
95
  isWorkspaceFileExportable
96
96
  } from "../chunk-TXD5HXLE.js";
97
- import "../chunk-JEZJ6HTF.js";
97
+ import "../chunk-3NM4GCAY.js";
98
98
  import {
99
99
  asRecord,
100
100
  asString,
@@ -1307,11 +1307,26 @@ function hasUsage(usage) {
1307
1307
  return typeof usage.inputTokens === "number" && usage.inputTokens > 0;
1308
1308
  }
1309
1309
  function cachedResultFrom(final, persisted) {
1310
+ if (!final && !persisted) {
1311
+ throw new Error("Completed turn has no retained result or assistant row; retry exact recovery");
1312
+ }
1313
+ const usage = {};
1314
+ for (const key of [
1315
+ "inputTokens",
1316
+ "outputTokens",
1317
+ "reasoningTokens",
1318
+ "cacheReadTokens",
1319
+ "cacheWriteTokens",
1320
+ "costUsd"
1321
+ ]) {
1322
+ const value = final?.usage?.[key] ?? persisted?.[key];
1323
+ if (typeof value === "number" && Number.isFinite(value) && value >= 0) usage[key] = value;
1324
+ }
1310
1325
  return {
1311
1326
  state: "completed",
1312
1327
  text: final?.text ?? persisted?.content ?? "",
1313
1328
  parts: final?.parts ?? persisted?.parts ?? [],
1314
- usage: final?.usage ?? {},
1329
+ usage,
1315
1330
  cached: true
1316
1331
  };
1317
1332
  }
@@ -1399,19 +1414,9 @@ async function runDetachedTurn(opts) {
1399
1414
  };
1400
1415
  const completed = async () => {
1401
1416
  if (!opts.completedResult) return null;
1402
- try {
1403
- return await opts.completedResult() ?? null;
1404
- } catch (err) {
1405
- opts.log?.("[chat-routes] runDetachedTurn completedResult lookup failed", { turnId, err: String(err) });
1406
- return null;
1407
- }
1417
+ return await opts.completedResult() ?? null;
1408
1418
  };
1409
- let prior = null;
1410
- try {
1411
- prior = await store.getStatus(turnId);
1412
- } catch (err) {
1413
- opts.log?.("[chat-routes] runDetachedTurn getStatus failed; treating as no prior", { turnId, err: String(err) });
1414
- }
1419
+ const prior = await store.getStatus(turnId);
1415
1420
  if (prior === "complete") {
1416
1421
  const persisted = await persistedRow();
1417
1422
  return await settleRow(
@@ -1422,19 +1427,14 @@ async function runDetachedTurn(opts) {
1422
1427
  if (prior === "running") {
1423
1428
  const final = await completed();
1424
1429
  if (final) {
1425
- await store.setStatus(turnId, "complete", scopeId).catch((err) => {
1426
- opts.log?.("[chat-routes] runDetachedTurn failed to settle a completed running turn", { turnId, err: String(err) });
1427
- });
1430
+ await store.setStatus(turnId, "complete", scopeId);
1428
1431
  const persisted = await persistedRow();
1429
1432
  return await settleRow(cachedResultFrom(final, persisted), persisted);
1430
1433
  }
1431
- if (opts.resetBuffer) {
1432
- await opts.resetBuffer(turnId).catch((err) => {
1433
- opts.log?.("[chat-routes] runDetachedTurn resetBuffer failed; re-stream may duplicate rows", { turnId, err: String(err) });
1434
- });
1435
- } else {
1436
- opts.log?.("[chat-routes] runDetachedTurn re-streaming over a running buffer without resetBuffer; rows may duplicate", { turnId });
1434
+ if (!opts.resetBuffer) {
1435
+ throw new Error("Detached turn recovery requires resetBuffer before replaying an existing stream");
1437
1436
  }
1437
+ await opts.resetBuffer(turnId);
1438
1438
  }
1439
1439
  const tap = createBufferedTurnTap({
1440
1440
  store,
@@ -1612,20 +1612,16 @@ async function readCompletedSandboxTurn(box, options) {
1612
1612
  matchingCount
1613
1613
  });
1614
1614
  }
1615
- if (!cached && !message) return null;
1616
- let result = cached ? asRecord(cached.result) : void 0;
1617
- const latestConversationMessage = messages.filter((candidate) => candidate.role === "user" || candidate.role === "assistant").at(-1);
1618
- if (!result && message && latestConversationMessage === message) {
1619
- try {
1620
- result = asRecord(await session.result());
1621
- } catch (error) {
1622
- log?.("[chat-routes] completed Sandbox session result lookup failed", {
1623
- turnId,
1624
- sessionId,
1625
- error: String(error)
1626
- });
1615
+ if (!cached && !message) {
1616
+ if (cacheOutcome.status === "rejected" || messagesOutcome.status === "rejected") {
1617
+ throw new Error("Completed Sandbox turn could not be verified; retry the exact read");
1618
+ }
1619
+ if (rawCached || matchingCount > 1) {
1620
+ throw new Error("Completed Sandbox turn identity is inconsistent; reconciliation is required");
1627
1621
  }
1622
+ return null;
1628
1623
  }
1624
+ const result = cached ? asRecord(cached.result) : void 0;
1629
1625
  const recovered = message ? normalizedMessageParts(message) : null;
1630
1626
  const text = textFromResult(result) ?? recovered?.derivedText;
1631
1627
  const resultUsage = usageFromResult(result);