@tangle-network/agent-app 4.0.12 → 4.0.14

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.
@@ -27,12 +27,13 @@ export interface DurableWorkspaceKeyRecord {
27
27
  platformUserId: string;
28
28
  sourceKeyId: string | null;
29
29
  sourceKeyFingerprint: string;
30
- /** The persisted name used to recover a remote create after a crash. Null only for pre-name rows. */
30
+ /** The remote name, used to recover a create after a crash. A store may return null: the placeholder id carries it. */
31
31
  name: string | null;
32
32
  /** The persisted retry identity for the remote create. Absent on legacy rows without a persisted create identity. */
33
33
  idempotencyKey?: string | null;
34
34
  keyId: string;
35
35
  keyEncrypted: string;
36
+ /** 0 for a spend-through child: it has no budget of its own and spends its source's cap. */
36
37
  budgetUsd: number;
37
38
  expiresAt: Date;
38
39
  status: WorkspaceKeyStatus;
@@ -47,7 +48,6 @@ export interface DurableWorkspaceKeyProvisioningRecord extends DurableWorkspaceK
47
48
  }
48
49
  type DurableWorkspaceKeyCreateResult = Awaited<ReturnType<KeyProvisioner['createKey']>> & {
49
50
  budgetUsd?: number | null;
50
- budgetRemaining?: number;
51
51
  expiresAt?: string | null;
52
52
  };
53
53
  /** The exact request identity that must be reused when recovering a create. */
@@ -55,6 +55,8 @@ export interface DurableWorkspaceKeyCreateInput {
55
55
  name: string;
56
56
  product: string;
57
57
  budgetUsd: number;
58
+ /** Mint a child that spends the source's cap and reserves nothing. A provisioner that ignores it mints `budgetUsd`. */
59
+ spendThrough?: true;
58
60
  expiresAt: string;
59
61
  /** Stable across process restarts for one persisted provisioning row. */
60
62
  idempotencyKey: string;
@@ -65,9 +67,11 @@ export interface DurableWorkspaceKeyProvisioner {
65
67
  supportsIdempotentCreate?: true;
66
68
  /** Create one child key. Non-idempotent providers recover through stable-name discovery only. */
67
69
  createKey(input: DurableWorkspaceKeyCreateInput): Promise<DurableWorkspaceKeyCreateResult>;
70
+ /** `budgetRemaining` is what the key can still spend; for a spend-through child, its source's remainder. */
68
71
  getKey(id: string): Promise<{
69
72
  budgetUsd?: number | null;
70
73
  budgetSpent?: number;
74
+ budgetRemaining?: number;
71
75
  expiresAt?: string | null;
72
76
  }>;
73
77
  /**
@@ -172,9 +176,14 @@ export interface WorkspaceRuntimeKey {
172
176
  }
173
177
  /** Identity-bound durable key manager API. */
174
178
  export interface DurableWorkspaceKeyManager {
175
- /** Reuse a matching active key or reconcile and mint one under a lease. */
179
+ /**
180
+ * Reuse a matching active key or reconcile and mint one under a lease. Pass `spendThrough` when Platform reports a
181
+ * budget on the source: the child then reserves nothing, so live children never hold the source's cap several times
182
+ * over, and Platform refuses each request once that cap is spent. `budgetUsd` is then the remainder reported at mint.
183
+ */
176
184
  ensureKey(identity: WorkspaceKeyIdentity, options?: {
177
185
  budgetUsd?: number;
186
+ spendThrough?: boolean;
178
187
  }): Promise<WorkspaceRuntimeKey>;
179
188
  /** Read usage without returning the child secret. */
180
189
  getUsage(identity: WorkspaceKeyIdentity): Promise<WorkspaceKeyUsage | null>;
@@ -220,7 +229,7 @@ export interface DurableWorkspaceKeyManagerOptions {
220
229
  revocationRetryMaxMs?: number;
221
230
  /** Remote name; the mint's operation id is appended when absent, as a create under a held name revokes its key. */
222
231
  nameForIdentity?: (identity: WorkspaceKeyIdentity, operationId: string) => string;
223
- /** Resolve names for rows written before `name` became durable. Null blocks issuance safely. */
232
+ /** Resolve names for rows written before a mint stored its name. Null blocks issuance safely. */
224
233
  legacyNameForRecord?: (record: DurableWorkspaceKeyRecord) => string | null | undefined;
225
234
  /** Recognize a missing remote key without depending on a provider SDK. */
226
235
  isRemoteMissing?: (error: unknown) => boolean;
@@ -5,7 +5,7 @@ import {
5
5
  createTcloudKeyProvisioner,
6
6
  createWorkspaceKeyManager,
7
7
  readSharedBillingState
8
- } from "../chunk-Z5KJ7WM3.js";
8
+ } from "../chunk-UXVSX5N6.js";
9
9
  import "../chunk-VGS2NXLB.js";
10
10
  export {
11
11
  DEFAULT_MIN_REMAINING_KEY_LIFETIME_MS,
@@ -43,7 +43,7 @@ import {
43
43
  } from "../chunk-TMWUWKLU.js";
44
44
  import {
45
45
  runProtectedRouterTurn
46
- } from "../chunk-GWATTXFR.js";
46
+ } from "../chunk-FYF564KJ.js";
47
47
  import {
48
48
  HYBRID_TURN_GUIDANCE,
49
49
  INTENT_LINE_HISTORY_MESSAGES,
@@ -74,7 +74,7 @@ import {
74
74
  turnPromptText,
75
75
  valueRedactor,
76
76
  withProducerStream
77
- } from "../chunk-CD4SJXYC.js";
77
+ } from "../chunk-FAI54DBZ.js";
78
78
  import "../chunk-SBHFMDR7.js";
79
79
  import "../chunk-H6BRJU5M.js";
80
80
  import "../chunk-4DBHC63F.js";
@@ -185,7 +185,7 @@ import "../chunk-S5SRJJQG.js";
185
185
  import "../chunk-GD4ONMKJ.js";
186
186
  import "../chunk-UGWQLQDS.js";
187
187
  import "../chunk-R32MULDK.js";
188
- import "../chunk-XCUT2I52.js";
188
+ import "../chunk-5QQBQS7W.js";
189
189
  import "../chunk-D6UJEOZQ.js";
190
190
  import "../chunk-YYA2CVOY.js";
191
191
  import "../chunk-KSLTD4FI.js";
@@ -907,7 +907,13 @@ async function runRouterTurn(options) {
907
907
  });
908
908
  }
909
909
  const detail = error instanceof Error ? error.message.match(/\(HTTP \d+\): ([\s\S]*)$/)?.[1]?.slice(0, 1e3) : void 0;
910
- return outcome(typeof status === "number" ? { code: `model_http_${status}`, status, message: "The model service did not answer.", ...detail ? { detail } : {} } : { code: "model_unavailable", message: "The model service did not answer." });
910
+ const spent = status === 402 && /budget_(exhausted|exceeded)/i.test(detail ?? "");
911
+ return outcome(typeof status === "number" ? {
912
+ code: `model_http_${status}`,
913
+ status,
914
+ ...detail ? { detail } : {},
915
+ message: spent ? "The paying key has spent its budget. Top it up or raise its cap, then retry." : "The model service did not answer."
916
+ } : { code: "model_unavailable", message: "The model service did not answer." });
911
917
  }
912
918
  if (placementFailure) return outcome(placementFailure);
913
919
  if (stop === "deadline" && checkpoint) {
@@ -998,4 +1004,4 @@ export {
998
1004
  composeRouterTurnPrompt,
999
1005
  runRouterTurn
1000
1006
  };
1001
- //# sourceMappingURL=chunk-XCUT2I52.js.map
1007
+ //# sourceMappingURL=chunk-5QQBQS7W.js.map