@tangle-network/agent-app 0.55.6 → 0.56.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.
Files changed (36) hide show
  1. package/dist/assistant/index.js +4 -4
  2. package/dist/chat-routes/detached-turn.d.ts +3 -9
  3. package/dist/chat-routes/index.d.ts +1 -0
  4. package/dist/chat-routes/index.js +177 -9
  5. package/dist/chat-routes/index.js.map +1 -1
  6. package/dist/chat-routes/plan-follow-up.d.ts +108 -0
  7. package/dist/chat-store/index.js +3 -3
  8. package/dist/{chunk-RSTPXLC3.js → chunk-3LOTQCW7.js} +3 -3
  9. package/dist/{chunk-OXDA7G4E.js → chunk-73WE4UQG.js} +21 -5
  10. package/dist/chunk-73WE4UQG.js.map +1 -0
  11. package/dist/{chunk-HXTJXODG.js → chunk-GBOHTAQH.js} +11 -2
  12. package/dist/chunk-GBOHTAQH.js.map +1 -0
  13. package/dist/{chunk-V4JZ5OYC.js → chunk-HTAFI247.js} +2 -2
  14. package/dist/{chunk-YJMCRXQQ.js → chunk-LQYIBL3G.js} +3 -3
  15. package/dist/{chunk-YJMCRXQQ.js.map → chunk-LQYIBL3G.js.map} +1 -1
  16. package/dist/{chunk-UII4YDYS.js → chunk-N56FWDSP.js} +2 -2
  17. package/dist/{chunk-2HEFK764.js → chunk-TNDBW5XG.js} +3 -3
  18. package/dist/peer-floors/cli.js +123 -3
  19. package/dist/peer-floors/cli.js.map +1 -1
  20. package/dist/peer-floors/durability-owners.d.ts +23 -0
  21. package/dist/plans/index.d.ts +6 -2
  22. package/dist/plans/index.js +1 -1
  23. package/dist/public-consultation/index.js +5 -5
  24. package/dist/sandbox/index.d.ts +1 -0
  25. package/dist/sandbox/index.js +1 -1
  26. package/dist/stream/index.js +5 -3
  27. package/dist/stream/turn-buffer.d.ts +8 -1
  28. package/dist/turn-stream/index.js +1 -1
  29. package/dist/web-react/index.js +4 -4
  30. package/package.json +1 -1
  31. package/dist/chunk-HXTJXODG.js.map +0 -1
  32. package/dist/chunk-OXDA7G4E.js.map +0 -1
  33. /package/dist/{chunk-RSTPXLC3.js.map → chunk-3LOTQCW7.js.map} +0 -0
  34. /package/dist/{chunk-V4JZ5OYC.js.map → chunk-HTAFI247.js.map} +0 -0
  35. /package/dist/{chunk-UII4YDYS.js.map → chunk-N56FWDSP.js.map} +0 -0
  36. /package/dist/{chunk-2HEFK764.js.map → chunk-TNDBW5XG.js.map} +0 -0
@@ -0,0 +1,108 @@
1
+ import type { SandboxEvent, SandboxInstance } from '@tangle-network/sandbox';
2
+ /** The decision a follow-up continues. */
3
+ export type PlanFollowUpOutcome = 'approved' | 'rejected';
4
+ /** The descriptor a decided plan card sends back to the chat route. */
5
+ export interface PlanFollowUpAttach {
6
+ planId: string;
7
+ revision: number;
8
+ outcome: PlanFollowUpOutcome;
9
+ turnId: string;
10
+ }
11
+ /** Result of checking a follow-up descriptor against the session's persisted plans. */
12
+ export type PlanFollowUpResolution = {
13
+ ok: true;
14
+ attach: PlanFollowUpAttach;
15
+ executionId: string;
16
+ } | {
17
+ ok: false;
18
+ status: 400 | 409;
19
+ code: string;
20
+ error: string;
21
+ };
22
+ /** Result of one exclusive follow-up claim. */
23
+ export type PlanFollowUpAdmission = {
24
+ admitted: true;
25
+ lease: string;
26
+ } | {
27
+ admitted: false;
28
+ reason: 'in_flight' | 'completed';
29
+ };
30
+ /** Result of settling a claim. `lease_lost` means a stale reclaim superseded it. */
31
+ export type PlanFollowUpSettlement = {
32
+ settled: true;
33
+ } | {
34
+ settled: false;
35
+ reason: 'lease_lost';
36
+ };
37
+ /** A bound D1 statement used by the follow-up gate. */
38
+ export interface D1BoundForPlanFollowUps {
39
+ run(): Promise<unknown>;
40
+ }
41
+ /**
42
+ * Structural D1 contract for the follow-up gate. `batch` is required: it is
43
+ * D1's atomic boundary, and the gate confirms ownership from the row read in
44
+ * the same batch instead of from a driver-specific affected-row count.
45
+ */
46
+ export interface D1LikeForPlanFollowUps {
47
+ prepare(sql: string): {
48
+ bind(...values: unknown[]): D1BoundForPlanFollowUps;
49
+ };
50
+ batch(statements: D1BoundForPlanFollowUps[]): Promise<unknown[]>;
51
+ }
52
+ /** Configure the follow-up gate. Clock and lease are injectable for tests. */
53
+ export interface PlanFollowUpGateOptions {
54
+ now?: () => Date;
55
+ createLease?: () => string;
56
+ /** How long a `running` claim may sit before another isolate may reclaim it. Default one hour. */
57
+ staleAfterMs?: number;
58
+ }
59
+ /** Exclusive claim over one follow-up execution's `turn_status` row. */
60
+ export interface PlanFollowUpGate {
61
+ admit(executionId: string, scopeId: string): Promise<PlanFollowUpAdmission>;
62
+ /** Record a completed attach. Only the current lease may settle. */
63
+ settle(executionId: string, scopeId: string, lease: string): Promise<PlanFollowUpSettlement>;
64
+ /** Record a failed attach so a retry is admitted immediately. */
65
+ abandon(executionId: string, scopeId: string, lease: string): Promise<PlanFollowUpSettlement>;
66
+ }
67
+ /** The Sidecar's execution id for a follow-up turn. Keep it byte-identical to the Sidecar. */
68
+ export declare function planFollowUpExecutionId(sessionId: string, turnId: string): string;
69
+ /** Parse a follow-up descriptor. The turn id is derived, never trusted. */
70
+ export declare function parsePlanFollowUpAttach(value: unknown): PlanFollowUpAttach | null;
71
+ /**
72
+ * Validate a follow-up request against what the session actually persisted:
73
+ * the plan must be in this session at this revision and must already carry the
74
+ * claimed decision.
75
+ */
76
+ export declare function resolvePlanFollowUpRequest(input: {
77
+ sessionId: string;
78
+ planFollowUp: unknown;
79
+ messages: ReadonlyArray<{
80
+ role: string;
81
+ parts?: unknown;
82
+ }>;
83
+ }): PlanFollowUpResolution;
84
+ /**
85
+ * Session events carry two payload shapes: replayed events hold the stream
86
+ * event under `data`, while live events nest it under `data.properties`.
87
+ * Downstream reads `data.<field>`, so a live event is unwrapped.
88
+ */
89
+ export declare function unwrapSessionEventPayload(event: SandboxEvent): SandboxEvent;
90
+ /**
91
+ * Attach to the already-enqueued follow-up execution: replay its buffered
92
+ * events from the start, then follow it live to completion. It never sends a
93
+ * new prompt. The session-events iterator has no reconnect, so a stream that
94
+ * ends without a terminal event fails instead of persisting a partial turn.
95
+ */
96
+ export declare function streamPlanFollowUpEvents(box: SandboxInstance, sessionId: string, executionId: string, options?: {
97
+ timeoutMs?: number;
98
+ }): AsyncGenerator<SandboxEvent>;
99
+ /**
100
+ * Exclusive claim over a follow-up execution in the shared `turn_status`
101
+ * table. Every claim writes a random lease and confirms ownership from the
102
+ * row returned by the same D1 batch. A running claim older than
103
+ * `staleAfterMs` may be reclaimed; the superseded holder then settles into
104
+ * `lease_lost` instead of overwriting the newer claim. The table needs the
105
+ * `leaseToken` column from `TURN_EVENTS_MIGRATION_SQL` or, for an older table,
106
+ * `TURN_STATUS_LEASE_MIGRATION_SQL` (both in `/stream`).
107
+ */
108
+ export declare function createD1PlanFollowUpGate(db: D1LikeForPlanFollowUps, options?: PlanFollowUpGateOptions): PlanFollowUpGate;
@@ -14,15 +14,15 @@ import {
14
14
  mentionInputToPart,
15
15
  mentionPartsFromMessageParts,
16
16
  toChatMessageParts
17
- } from "../chunk-V4JZ5OYC.js";
17
+ } from "../chunk-HTAFI247.js";
18
18
  import "../chunk-ZVEEWGDK.js";
19
19
  import "../chunk-GYDFGEJ2.js";
20
20
  import "../chunk-TXD5HXLE.js";
21
21
  import {
22
22
  attachmentPartKey
23
- } from "../chunk-UII4YDYS.js";
23
+ } from "../chunk-N56FWDSP.js";
24
24
  import "../chunk-FCON65I2.js";
25
- import "../chunk-YJMCRXQQ.js";
25
+ import "../chunk-LQYIBL3G.js";
26
26
 
27
27
  // src/chat-store/core.ts
28
28
  var BULK_DELETE_MAX_THREADS = 200;
@@ -7,7 +7,7 @@ import {
7
7
  import {
8
8
  mentionInputToPart,
9
9
  toChatMessageParts
10
- } from "./chunk-V4JZ5OYC.js";
10
+ } from "./chunk-HTAFI247.js";
11
11
  import {
12
12
  ChatTurnInputError,
13
13
  assertPromptPartsWithinCap,
@@ -24,7 +24,7 @@ import {
24
24
  createBufferedTurnTap,
25
25
  replayTurnEvents,
26
26
  stampReplaySeq
27
- } from "./chunk-HXTJXODG.js";
27
+ } from "./chunk-GBOHTAQH.js";
28
28
 
29
29
  // src/chat-routes/draft-persistence.ts
30
30
  var CONTENT_EVENT_TYPES = /* @__PURE__ */ new Set([
@@ -1082,4 +1082,4 @@ export {
1082
1082
  createChatTurnRoutes,
1083
1083
  streamChatRouteAsSandboxEvents
1084
1084
  };
1085
- //# sourceMappingURL=chunk-RSTPXLC3.js.map
1085
+ //# sourceMappingURL=chunk-3LOTQCW7.js.map
@@ -1770,16 +1770,32 @@ function stoppedBoxResumeError(box, cause) {
1770
1770
  async function resumeStoppedBox(box, timeoutMs, runtimeEnv, onProgress) {
1771
1771
  try {
1772
1772
  livenessVerifiedAt.delete(box.id);
1773
- await box.resume({
1774
- timeoutMs,
1775
- ...Object.keys(runtimeEnv).length > 0 ? { env: runtimeEnv } : {}
1776
- });
1773
+ await resumeWithRequiredRuntimeEnv(box, timeoutMs, runtimeEnv);
1777
1774
  await box.waitFor("running", { timeoutMs, ...onProgress ? { onProgress } : {} });
1778
1775
  return ok(box);
1779
1776
  } catch (cause) {
1780
1777
  return fail(stoppedBoxResumeError(box, cause));
1781
1778
  }
1782
1779
  }
1780
+ async function resumeWithRequiredRuntimeEnv(box, timeoutMs, runtimeEnv) {
1781
+ const deadline = Date.now() + timeoutMs;
1782
+ try {
1783
+ await box.resume({ timeoutMs });
1784
+ } catch (cause) {
1785
+ const missingEnvKeys = resumeEnvRequiredKeys(cause);
1786
+ if (!missingEnvKeys?.length || missingEnvKeys.some((key) => runtimeEnv[key] === void 0)) throw cause;
1787
+ await box.resume({
1788
+ timeoutMs: Math.max(1, deadline - Date.now()),
1789
+ env: Object.fromEntries(missingEnvKeys.map((key) => [key, runtimeEnv[key]]))
1790
+ });
1791
+ }
1792
+ }
1793
+ function resumeEnvRequiredKeys(cause) {
1794
+ if (typeof cause !== "object" || cause === null) return void 0;
1795
+ const { code, missingEnvKeys } = cause;
1796
+ if (code !== "RESUME_ENV_REQUIRED" || !Array.isArray(missingEnvKeys)) return void 0;
1797
+ return missingEnvKeys.filter((key) => typeof key === "string");
1798
+ }
1783
1799
  async function recoverUnresponsiveBox(client, box, probe, stage, name, resumeTimeout, runtimeEnv, onProgress) {
1784
1800
  try {
1785
1801
  await box.stop();
@@ -2853,4 +2869,4 @@ export {
2853
2869
  isTerminalPromptEvent,
2854
2870
  detectInteractiveQuestion
2855
2871
  };
2856
- //# sourceMappingURL=chunk-OXDA7G4E.js.map
2872
+ //# sourceMappingURL=chunk-73WE4UQG.js.map