@cortexkit/opencode-openai-auth 1.13.0 → 1.14.1

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/bin.js +9 -9
  2. package/dist/{codex-request-Bu2sjxQn.d.ts → codex-request-Cl6zEfsR.d.ts} +20 -3
  3. package/dist/{index-p8v28mh9.js → index-2f330s35.js} +2 -2
  4. package/dist/index-3mbw88h7.js +91 -0
  5. package/dist/{index-r8y79mzp.js → index-94b345dw.js} +1 -1
  6. package/dist/{index-khqwa7g2.js → index-999nwa9p.js} +20 -20
  7. package/dist/{index-tzrf3ax2.js → index-cxnrd85v.js} +1 -1
  8. package/dist/{index-cs0tey1r.js → index-gkye2xh1.js} +2 -2
  9. package/dist/{index-zmerz2yv.js → index-k5av4j8p.js} +2 -2
  10. package/dist/{index-rhe4jm5t.js → index-pc4vrrex.js} +2 -2
  11. package/dist/{index-4s50rsec.js → index-snq7bwr6.js} +2 -2
  12. package/dist/{index-th0bzvpn.js → index-wma2ggn9.js} +2 -2
  13. package/dist/{index-2g95z7kb.js → index-xk7f1aef.js} +21 -21
  14. package/dist/{index-2ccfywax.js → index-yygzbxjk.js} +1 -1
  15. package/dist/{index-0bh5fs56.js → index-z9cj13z7.js} +1 -1
  16. package/dist/index.d.ts +1 -1
  17. package/dist/index.js +1 -1
  18. package/dist/rpc/port-file.js +1 -1
  19. package/dist/rpc/protocol.js +1 -1
  20. package/dist/rpc/rpc-client.js +1 -1
  21. package/dist/rpc/rpc-dir.js +1 -1
  22. package/dist/sidebar-state.js +1 -1
  23. package/dist/{token-2qht8n50.js → token-sgwxn4xg.js} +1 -1
  24. package/dist/token-util-8mrnmkge.js +1 -0
  25. package/dist/tui-preferences.js +1 -1
  26. package/dist/v2/server.d.ts +1 -1
  27. package/dist/v2/server.js +2 -2
  28. package/package.json +7 -7
  29. package/src/tui-compiled/raw/shared/abd062d633e29fd2-pool-routing.js +21 -15
  30. package/src/tui-compiled/raw/shared/b9588ad4725c1d10-enrollment.js +81 -4
  31. package/src/tui-compiled/raw/shared/e8d3c8da776ef9cd-index.js +1 -1
  32. package/src/tui-compiled/runtime/shared/abd062d633e29fd2-pool-routing.js +21 -15
  33. package/src/tui-compiled/runtime/shared/b9588ad4725c1d10-enrollment.js +81 -4
  34. package/src/tui-compiled/runtime/shared/e8d3c8da776ef9cd-index.js +1 -1
  35. package/dist/index-7s8g79dd.js +0 -91
  36. package/dist/token-util-20g3fwxd.js +0 -1
@@ -75,6 +75,35 @@ export function validEnrollmentDisplayName(displayName) {
75
75
  length <= 40 &&
76
76
  !/[\p{Cc}\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069\u200b-\u200d\u2060\ufeff]/u.test(displayName));
77
77
  }
78
+ /** Reject malformed permissions before a compatibility retry can omit them. */
79
+ export function validEnrollmentRequestedGrants(grants) {
80
+ return (Array.isArray(grants) &&
81
+ grants.length >= 1 &&
82
+ grants.length <= 4 &&
83
+ Array.from(grants).every((grant) => {
84
+ if (!isRecord(grant) ||
85
+ Object.keys(grant).length !== 2 ||
86
+ (grant.operation !== 'read' && grant.operation !== 'list') ||
87
+ !isRecord(grant.selector))
88
+ return false;
89
+ const keys = Object.keys(grant.selector);
90
+ const key = keys[0];
91
+ return (keys.length === 1 &&
92
+ (key === 'category' || key === 'exact') &&
93
+ typeof grant.selector[key] === 'string' &&
94
+ grant.selector[key].trim().length > 0);
95
+ }));
96
+ }
97
+ function grantProposal(state) {
98
+ return {
99
+ ...(state.requestedGrants !== undefined && {
100
+ requestedGrants: state.requestedGrants,
101
+ }),
102
+ ...(state.requestedGrantsStatus !== undefined && {
103
+ requestedGrantsStatus: state.requestedGrantsStatus,
104
+ }),
105
+ };
106
+ }
78
107
  /**
79
108
  * Connect the enrollment ceremony. Setup calls this; the request path never
80
109
  * does. `connectionFile` is required because this library reads no
@@ -129,6 +158,7 @@ function decodeEnrollmentState(value) {
129
158
  throw invalidState();
130
159
  }
131
160
  if (value.phase === 'pending') {
161
+ const grants = decodeGrantProposal(value);
132
162
  if (!TOKEN_RE.test(String(value.requestSecret ?? '')) ||
133
163
  (value.requestId !== undefined &&
134
164
  (typeof value.requestId !== 'string' ||
@@ -147,9 +177,11 @@ function decodeEnrollmentState(value) {
147
177
  }),
148
178
  createdAt: value.createdAt,
149
179
  updatedAt: value.updatedAt,
180
+ ...grants,
150
181
  };
151
182
  }
152
183
  if (value.phase === 'approved') {
184
+ const grants = decodeGrantProposal(value);
153
185
  if ((value.approvedName !== undefined &&
154
186
  (typeof value.approvedName !== 'string' ||
155
187
  value.approvedName.length === 0)) ||
@@ -166,6 +198,7 @@ function decodeEnrollmentState(value) {
166
198
  }),
167
199
  tokenGeneration: value.tokenGeneration,
168
200
  updatedAt: value.updatedAt,
201
+ ...grants,
169
202
  };
170
203
  }
171
204
  if (value.phase === 'denied' || value.phase === 'blocked') {
@@ -185,6 +218,18 @@ function decodeEnrollmentState(value) {
185
218
  }
186
219
  throw invalidState();
187
220
  }
221
+ function decodeGrantProposal(value) {
222
+ // Optional proposal metadata from a newer version must not invalidate an
223
+ // existing enrollment when a plugin is downgraded. Never infer access from it.
224
+ if ((value.requestedGrants !== undefined &&
225
+ !validEnrollmentRequestedGrants(value.requestedGrants)) ||
226
+ (value.requestedGrantsStatus !== undefined &&
227
+ (value.requestedGrants === undefined ||
228
+ (value.requestedGrantsStatus !== 'sent' &&
229
+ value.requestedGrantsStatus !== 'dropped'))))
230
+ return {};
231
+ return grantProposal(value);
232
+ }
188
233
  function decodeTokenFile(value) {
189
234
  if (!isRecord(value) ||
190
235
  !TOKEN_RE.test(String(value.token ?? '')) ||
@@ -452,6 +497,9 @@ async function readEnrollmentStatus(paths, proposedName) {
452
497
  approvedName: state.approvedName,
453
498
  }),
454
499
  tokenGeneration: token.token_generation,
500
+ ...(state &&
501
+ (state.phase === 'approved' || state.phase === 'pending') &&
502
+ grantProposal(state)),
455
503
  },
456
504
  };
457
505
  }
@@ -534,6 +582,7 @@ function statusFromState(state) {
534
582
  state: 'pending',
535
583
  proposedName: state.proposedName,
536
584
  ...(state.requestId !== undefined && { requestId: state.requestId }),
585
+ ...grantProposal(state),
537
586
  };
538
587
  }
539
588
  if (state.phase === 'approved') {
@@ -544,6 +593,7 @@ function statusFromState(state) {
544
593
  approvedName: state.approvedName,
545
594
  }),
546
595
  tokenGeneration: state.tokenGeneration,
596
+ ...grantProposal(state),
547
597
  };
548
598
  }
549
599
  if (state.phase === 'denied')
@@ -567,6 +617,7 @@ export class ClaustrumEnrollmentManager {
567
617
  #paths;
568
618
  #proposedName;
569
619
  #displayName;
620
+ #requestedGrants;
570
621
  #now;
571
622
  #mintSecret;
572
623
  #writeTokenFile;
@@ -575,6 +626,13 @@ export class ClaustrumEnrollmentManager {
575
626
  if (options.displayName !== undefined &&
576
627
  !validEnrollmentDisplayName(options.displayName))
577
628
  throw new ClaustrumConsumerError('invalid-state', 'invalid Claustrum enrollment display name');
629
+ if (options.requestedGrants !== undefined &&
630
+ !validEnrollmentRequestedGrants(options.requestedGrants))
631
+ throw new ClaustrumConsumerError('invalid-state', 'invalid Claustrum enrollment requested grants');
632
+ this.#requestedGrants = options.requestedGrants?.map((grant) => ({
633
+ selector: { ...grant.selector },
634
+ operation: grant.operation,
635
+ }));
578
636
  this.#ancestorOptions = options.ancestorOptions ?? {};
579
637
  this.#client = options.client;
580
638
  this.#paths = options.paths;
@@ -627,6 +685,7 @@ export class ClaustrumEnrollmentManager {
627
685
  phase: 'approved',
628
686
  proposedName: state?.proposedName ?? this.#proposedName,
629
687
  tokenGeneration: token.token_generation,
688
+ ...(state && grantProposal(state)),
630
689
  updatedAt: this.#now(),
631
690
  };
632
691
  await writeStateAtomic(this.#paths.statePath, approved, this.#ancestorOptions);
@@ -640,6 +699,7 @@ export class ClaustrumEnrollmentManager {
640
699
  approvedName: state.approvedName,
641
700
  }),
642
701
  tokenGeneration: token.token_generation,
702
+ ...(state.phase === 'approved' && grantProposal(state)),
643
703
  };
644
704
  }
645
705
  if (state?.phase === 'approved') {
@@ -664,6 +724,9 @@ export class ClaustrumEnrollmentManager {
664
724
  requestSecret: this.#mintSecret(),
665
725
  createdAt: now,
666
726
  updatedAt: now,
727
+ ...(this.#requestedGrants !== undefined && {
728
+ requestedGrants: this.#requestedGrants,
729
+ }),
667
730
  };
668
731
  if (!TOKEN_RE.test(state.requestSecret))
669
732
  throw new ClaustrumConsumerError('invalid-state', 'invalid minted Claustrum enrollment secret');
@@ -682,28 +745,39 @@ export class ClaustrumEnrollmentManager {
682
745
  requestSecretHash,
683
746
  };
684
747
  let proposed;
748
+ let requestedGrantsStatus = state.requestedGrantsStatus;
685
749
  try {
686
750
  proposed = await this.#client.enrollPropose({
687
751
  ...proposal,
688
752
  ...(this.#displayName !== undefined && {
689
753
  displayName: this.#displayName,
690
754
  }),
755
+ ...(state.requestedGrants !== undefined && {
756
+ requestedGrants: state.requestedGrants,
757
+ }),
691
758
  });
759
+ if (state.requestedGrants !== undefined)
760
+ requestedGrantsStatus = 'sent';
692
761
  }
693
762
  catch (error) {
694
- if (this.#displayName === undefined ||
763
+ if ((this.#displayName === undefined &&
764
+ state.requestedGrants === undefined) ||
695
765
  !(error instanceof ClaustrumCredentialError) ||
696
766
  error.code !== 'invalid_params')
697
767
  throw error;
698
- // Locally validated names can only be refused by vaults that do
699
- // not support displayName. A refused proposal stores nothing, so
700
- // retry once with the same hash and let normal handling decide.
768
+ // Both optional fields were validated locally. Older vaults reject
769
+ // either field without storing a proposal, so retry the plain shape once.
701
770
  proposed = await this.#client.enrollPropose(proposal);
771
+ if (state.requestedGrants !== undefined)
772
+ requestedGrantsStatus = 'dropped';
702
773
  }
703
774
  state = {
704
775
  ...state,
705
776
  requestId: proposed.requestId,
706
777
  updatedAt: this.#now(),
778
+ ...(requestedGrantsStatus !== undefined && {
779
+ requestedGrantsStatus,
780
+ }),
707
781
  };
708
782
  await writeStateAtomic(this.#paths.statePath, state, this.#ancestorOptions);
709
783
  }
@@ -716,6 +790,7 @@ export class ClaustrumEnrollmentManager {
716
790
  state: 'pending',
717
791
  proposedName: state.proposedName,
718
792
  retryCode: refusal.code,
793
+ ...grantProposal(state),
719
794
  };
720
795
  }
721
796
  // A vault without the ceremony cannot hold a request for this
@@ -772,6 +847,7 @@ export class ClaustrumEnrollmentManager {
772
847
  proposedName: state.proposedName,
773
848
  approvedName: outcome.name,
774
849
  tokenGeneration: outcome.tokenGeneration,
850
+ ...grantProposal(state),
775
851
  updatedAt: this.#now(),
776
852
  };
777
853
  await writeStateAtomic(this.#paths.statePath, approved, this.#ancestorOptions);
@@ -787,6 +863,7 @@ export class ClaustrumEnrollmentManager {
787
863
  proposedName: state.proposedName,
788
864
  requestId,
789
865
  retryCode: refusal.code,
866
+ ...grantProposal(state),
790
867
  };
791
868
  }
792
869
  return this.#block(state, refusal.code);
@@ -10,7 +10,7 @@ export { ClaustrumCredentialError, } from "@cortexkit/claustrum-client";
10
10
  export { ClaustrumUnreachableError, classifyVaultFailure, VAULT_FAILURE_CLASSES, } from "./94f53cfd572ba4bb-availability.js";
11
11
  export { ClaustrumConsumer, DEFAULT_CONNECT_TIMEOUT_MS, } from "./169b2b4bf30909bc-consumer.js";
12
12
  export { ClaustrumScopedCustody, decideScopedRetryAfter401, isScopedCredentialRotation, KEPT_RECEIPT_MARGIN_MS, SERVING_MARGIN_MS, } from "./0f77ebc3c914c9c6-custody.js";
13
- export { ClaustrumEnrollmentManager, classifyEnrollmentError, connectClaustrumEnrollmentClient, disconnectClaustrumEnrollment, enrollmentAuthority, enrollmentName, getClaustrumEnrollmentPaths, hostEnrollmentPaths, RETRYABLE_ENROLLMENT_CODES, readClaustrumEnrollmentStatus, readClaustrumEnrollmentToken, resetClaustrumEnrollmentState, TERMINAL_ENROLLMENT_CODES, validEnrollmentDisplayName, vaultAuthority, } from "./b9588ad4725c1d10-enrollment.js";
13
+ export { ClaustrumEnrollmentManager, classifyEnrollmentError, connectClaustrumEnrollmentClient, disconnectClaustrumEnrollment, enrollmentAuthority, enrollmentName, getClaustrumEnrollmentPaths, hostEnrollmentPaths, RETRYABLE_ENROLLMENT_CODES, readClaustrumEnrollmentStatus, readClaustrumEnrollmentToken, resetClaustrumEnrollmentState, TERMINAL_ENROLLMENT_CODES, validEnrollmentDisplayName, validEnrollmentRequestedGrants, vaultAuthority, } from "./b9588ad4725c1d10-enrollment.js";
14
14
  export { ClaustrumConsumerError, } from "./ca0fccaba1d87af4-errors.js";
15
15
  export { connectVaultHost, hasVaultHost, VAULT_HOST_CONNECT_REFUSAL, VAULT_HOST_STATUS, } from "./c97089ed4243981c-host.js";
16
16
  export { assertHostSlotMatchesMode, assertNotCustodyPlaceholder, CUSTODY_PLACEHOLDER_PREFIX, classifyHostSlot, custodyPlaceholder, custodyPlaceholderKey, isCustodyPlaceholder, isCustodyPlaceholderValue, } from "./d9d2892a4c371301-host-slot.js";
@@ -166,34 +166,38 @@ export function planOrdered(input) {
166
166
  refreshBackoff: input.refreshBackoff,
167
167
  now: input.now,
168
168
  requestPull: input.requestPull
169
- }), ids = orderForPlacement(input.rows.map((row) => row.id), placement, mainId), confirmed = new Set(route.admission.refused.filter((refusal) => isConfirmedExhaustion(refusal) && input.killswitch.get(refusal.id) !== !1).map((refusal) => refusal.id)), lastPath = ids.filter((id) => confirmed.has(id)), tiers = creditsTiers(input.rows, input, route.admission), free = route.order.filter((id) => tiers.free.has(id)), credits = ids.filter((id) => tiers.credits.includes(id));
169
+ }), ids = orderForPlacement(input.rows.map((row) => row.id), placement, mainId), confirmed = new Set(route.admission.refused.filter((refusal) => isConfirmedExhaustion(refusal) && input.killswitch.get(refusal.id) !== !1).map((refusal) => refusal.id)), lastPath = ids.filter((id) => confirmed.has(id)), tiers = creditsTiers(input.rows, input, route.admission), free = route.order.filter((id) => tiers.free.has(id)), credits = ids.filter((id) => tiers.credits.includes(id)), send = (order, lastPath) => ({
170
+ kind: "send",
171
+ order,
172
+ lastPath,
173
+ tiers: Object.fromEntries(order.map((id) => [
174
+ id,
175
+ tiers.free.has(id) ? "free" : tiers.credits.includes(id) ? "credits" : "last-path"
176
+ ]))
177
+ });
170
178
  if (!replayable) {
171
179
  const hasMain = ids.includes(mainId), target = hasMain ? mainId : free[0] ?? credits[0] ?? route.order[0] ?? lastPath[0];
172
180
  if (target !== void 0 && route.order.includes(target))
173
- return { kind: "send", order: [target], lastPath: !1 };
181
+ return send([target], !1);
174
182
  if (target !== void 0 && credits.includes(target))
175
- return { kind: "send", order: [target], lastPath: !1 };
183
+ return send([target], !1);
176
184
  if (target !== void 0 && confirmed.has(target))
177
- return { kind: "send", order: [target], lastPath: !0 };
185
+ return send([target], !0);
178
186
  return {
179
187
  kind: "block",
180
188
  block: hasMain ? blockFor(mainId, route.admission, input.killswitch) : routeBlock(ids, route.admission, input.killswitch)
181
189
  };
182
190
  }
183
191
  if (free.length > 0)
184
- return { kind: "send", order: free, lastPath: !1 };
192
+ return send(free, !1);
185
193
  if (credits.length > 0) {
186
194
  const rest = route.order.length > 0 ? route.order : lastPath;
187
- return {
188
- kind: "send",
189
- order: [...credits, ...rest.filter((id) => !credits.includes(id))],
190
- lastPath: !1
191
- };
195
+ return send([...credits, ...rest.filter((id) => !credits.includes(id))], !1);
192
196
  }
193
197
  if (route.order.length > 0)
194
- return { kind: "send", order: route.order, lastPath: !1 };
198
+ return send(route.order, !1);
195
199
  if (lastPath.length > 0)
196
- return { kind: "send", order: lastPath, lastPath: !0 };
200
+ return send(lastPath, !0);
197
201
  return {
198
202
  kind: "block",
199
203
  block: routeBlock(ids, route.admission, input.killswitch)
@@ -244,6 +248,7 @@ export function selectStickyRow(input, options, exclude, pendingBytes) {
244
248
  const route = routePoolSticky(input, options, { exclude, pendingBytes }), rows = input.rows.filter((row) => !exclude.has(row.id)), tiers = creditsTiers(rows, input, route.admission), selected = route.outcome === "dispatch" && route.source !== "pin" ? {
245
249
  accountId: route.accountId,
246
250
  source: route.source,
251
+ tier: tiers.free.has(route.accountId) ? "free" : "last-path",
247
252
  ...route.quotaCheckedAt === void 0 ? {} : { quotaCheckedAt: route.quotaCheckedAt }
248
253
  } : void 0;
249
254
  if (selected && tiers.free.has(selected.accountId))
@@ -255,6 +260,7 @@ export function selectStickyRow(input, options, exclude, pendingBytes) {
255
260
  return {
256
261
  accountId: credits,
257
262
  source: "mode-fallback",
263
+ tier: "credits",
258
264
  ...checkedAt === void 0 ? {} : { quotaCheckedAt: checkedAt }
259
265
  };
260
266
  }
@@ -267,18 +273,18 @@ export function routePinnedRow(input, options, id) {
267
273
  const toLastPath = !tiers.free.has(route.accountId);
268
274
  if (route.pin.action === "assign") {
269
275
  if (toLastPath && onCredits)
270
- return { kind: "serve" };
276
+ return { kind: "serve", tier: "credits" };
271
277
  return move;
272
278
  }
273
279
  if (route.accountId !== id)
274
280
  return { kind: "detour" };
275
281
  if (toLastPath && othersOnCredits)
276
282
  return move;
277
- return { kind: "serve" };
283
+ return { kind: "serve", tier: toLastPath ? "last-path" : "free" };
278
284
  }
279
285
  const refusal = route.admission.refused.find((entry) => entry.id === id), confirmed = killed || refusal !== void 0 && isConfirmedExhaustion(refusal);
280
286
  if (onCredits)
281
- return { kind: "serve" };
287
+ return { kind: "serve", tier: "credits" };
282
288
  if (othersOnCredits)
283
289
  return confirmed ? move : { kind: "detour" };
284
290
  if (!killed && refusal && isConfirmedExhaustion(refusal))
@@ -75,6 +75,35 @@ export function validEnrollmentDisplayName(displayName) {
75
75
  length <= 40 &&
76
76
  !/[\p{Cc}\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069\u200b-\u200d\u2060\ufeff]/u.test(displayName));
77
77
  }
78
+ /** Reject malformed permissions before a compatibility retry can omit them. */
79
+ export function validEnrollmentRequestedGrants(grants) {
80
+ return (Array.isArray(grants) &&
81
+ grants.length >= 1 &&
82
+ grants.length <= 4 &&
83
+ Array.from(grants).every((grant) => {
84
+ if (!isRecord(grant) ||
85
+ Object.keys(grant).length !== 2 ||
86
+ (grant.operation !== 'read' && grant.operation !== 'list') ||
87
+ !isRecord(grant.selector))
88
+ return false;
89
+ const keys = Object.keys(grant.selector);
90
+ const key = keys[0];
91
+ return (keys.length === 1 &&
92
+ (key === 'category' || key === 'exact') &&
93
+ typeof grant.selector[key] === 'string' &&
94
+ grant.selector[key].trim().length > 0);
95
+ }));
96
+ }
97
+ function grantProposal(state) {
98
+ return {
99
+ ...(state.requestedGrants !== undefined && {
100
+ requestedGrants: state.requestedGrants,
101
+ }),
102
+ ...(state.requestedGrantsStatus !== undefined && {
103
+ requestedGrantsStatus: state.requestedGrantsStatus,
104
+ }),
105
+ };
106
+ }
78
107
  /**
79
108
  * Connect the enrollment ceremony. Setup calls this; the request path never
80
109
  * does. `connectionFile` is required because this library reads no
@@ -129,6 +158,7 @@ function decodeEnrollmentState(value) {
129
158
  throw invalidState();
130
159
  }
131
160
  if (value.phase === 'pending') {
161
+ const grants = decodeGrantProposal(value);
132
162
  if (!TOKEN_RE.test(String(value.requestSecret ?? '')) ||
133
163
  (value.requestId !== undefined &&
134
164
  (typeof value.requestId !== 'string' ||
@@ -147,9 +177,11 @@ function decodeEnrollmentState(value) {
147
177
  }),
148
178
  createdAt: value.createdAt,
149
179
  updatedAt: value.updatedAt,
180
+ ...grants,
150
181
  };
151
182
  }
152
183
  if (value.phase === 'approved') {
184
+ const grants = decodeGrantProposal(value);
153
185
  if ((value.approvedName !== undefined &&
154
186
  (typeof value.approvedName !== 'string' ||
155
187
  value.approvedName.length === 0)) ||
@@ -166,6 +198,7 @@ function decodeEnrollmentState(value) {
166
198
  }),
167
199
  tokenGeneration: value.tokenGeneration,
168
200
  updatedAt: value.updatedAt,
201
+ ...grants,
169
202
  };
170
203
  }
171
204
  if (value.phase === 'denied' || value.phase === 'blocked') {
@@ -185,6 +218,18 @@ function decodeEnrollmentState(value) {
185
218
  }
186
219
  throw invalidState();
187
220
  }
221
+ function decodeGrantProposal(value) {
222
+ // Optional proposal metadata from a newer version must not invalidate an
223
+ // existing enrollment when a plugin is downgraded. Never infer access from it.
224
+ if ((value.requestedGrants !== undefined &&
225
+ !validEnrollmentRequestedGrants(value.requestedGrants)) ||
226
+ (value.requestedGrantsStatus !== undefined &&
227
+ (value.requestedGrants === undefined ||
228
+ (value.requestedGrantsStatus !== 'sent' &&
229
+ value.requestedGrantsStatus !== 'dropped'))))
230
+ return {};
231
+ return grantProposal(value);
232
+ }
188
233
  function decodeTokenFile(value) {
189
234
  if (!isRecord(value) ||
190
235
  !TOKEN_RE.test(String(value.token ?? '')) ||
@@ -452,6 +497,9 @@ async function readEnrollmentStatus(paths, proposedName) {
452
497
  approvedName: state.approvedName,
453
498
  }),
454
499
  tokenGeneration: token.token_generation,
500
+ ...(state &&
501
+ (state.phase === 'approved' || state.phase === 'pending') &&
502
+ grantProposal(state)),
455
503
  },
456
504
  };
457
505
  }
@@ -534,6 +582,7 @@ function statusFromState(state) {
534
582
  state: 'pending',
535
583
  proposedName: state.proposedName,
536
584
  ...(state.requestId !== undefined && { requestId: state.requestId }),
585
+ ...grantProposal(state),
537
586
  };
538
587
  }
539
588
  if (state.phase === 'approved') {
@@ -544,6 +593,7 @@ function statusFromState(state) {
544
593
  approvedName: state.approvedName,
545
594
  }),
546
595
  tokenGeneration: state.tokenGeneration,
596
+ ...grantProposal(state),
547
597
  };
548
598
  }
549
599
  if (state.phase === 'denied')
@@ -567,6 +617,7 @@ export class ClaustrumEnrollmentManager {
567
617
  #paths;
568
618
  #proposedName;
569
619
  #displayName;
620
+ #requestedGrants;
570
621
  #now;
571
622
  #mintSecret;
572
623
  #writeTokenFile;
@@ -575,6 +626,13 @@ export class ClaustrumEnrollmentManager {
575
626
  if (options.displayName !== undefined &&
576
627
  !validEnrollmentDisplayName(options.displayName))
577
628
  throw new ClaustrumConsumerError('invalid-state', 'invalid Claustrum enrollment display name');
629
+ if (options.requestedGrants !== undefined &&
630
+ !validEnrollmentRequestedGrants(options.requestedGrants))
631
+ throw new ClaustrumConsumerError('invalid-state', 'invalid Claustrum enrollment requested grants');
632
+ this.#requestedGrants = options.requestedGrants?.map((grant) => ({
633
+ selector: { ...grant.selector },
634
+ operation: grant.operation,
635
+ }));
578
636
  this.#ancestorOptions = options.ancestorOptions ?? {};
579
637
  this.#client = options.client;
580
638
  this.#paths = options.paths;
@@ -627,6 +685,7 @@ export class ClaustrumEnrollmentManager {
627
685
  phase: 'approved',
628
686
  proposedName: state?.proposedName ?? this.#proposedName,
629
687
  tokenGeneration: token.token_generation,
688
+ ...(state && grantProposal(state)),
630
689
  updatedAt: this.#now(),
631
690
  };
632
691
  await writeStateAtomic(this.#paths.statePath, approved, this.#ancestorOptions);
@@ -640,6 +699,7 @@ export class ClaustrumEnrollmentManager {
640
699
  approvedName: state.approvedName,
641
700
  }),
642
701
  tokenGeneration: token.token_generation,
702
+ ...(state.phase === 'approved' && grantProposal(state)),
643
703
  };
644
704
  }
645
705
  if (state?.phase === 'approved') {
@@ -664,6 +724,9 @@ export class ClaustrumEnrollmentManager {
664
724
  requestSecret: this.#mintSecret(),
665
725
  createdAt: now,
666
726
  updatedAt: now,
727
+ ...(this.#requestedGrants !== undefined && {
728
+ requestedGrants: this.#requestedGrants,
729
+ }),
667
730
  };
668
731
  if (!TOKEN_RE.test(state.requestSecret))
669
732
  throw new ClaustrumConsumerError('invalid-state', 'invalid minted Claustrum enrollment secret');
@@ -682,28 +745,39 @@ export class ClaustrumEnrollmentManager {
682
745
  requestSecretHash,
683
746
  };
684
747
  let proposed;
748
+ let requestedGrantsStatus = state.requestedGrantsStatus;
685
749
  try {
686
750
  proposed = await this.#client.enrollPropose({
687
751
  ...proposal,
688
752
  ...(this.#displayName !== undefined && {
689
753
  displayName: this.#displayName,
690
754
  }),
755
+ ...(state.requestedGrants !== undefined && {
756
+ requestedGrants: state.requestedGrants,
757
+ }),
691
758
  });
759
+ if (state.requestedGrants !== undefined)
760
+ requestedGrantsStatus = 'sent';
692
761
  }
693
762
  catch (error) {
694
- if (this.#displayName === undefined ||
763
+ if ((this.#displayName === undefined &&
764
+ state.requestedGrants === undefined) ||
695
765
  !(error instanceof ClaustrumCredentialError) ||
696
766
  error.code !== 'invalid_params')
697
767
  throw error;
698
- // Locally validated names can only be refused by vaults that do
699
- // not support displayName. A refused proposal stores nothing, so
700
- // retry once with the same hash and let normal handling decide.
768
+ // Both optional fields were validated locally. Older vaults reject
769
+ // either field without storing a proposal, so retry the plain shape once.
701
770
  proposed = await this.#client.enrollPropose(proposal);
771
+ if (state.requestedGrants !== undefined)
772
+ requestedGrantsStatus = 'dropped';
702
773
  }
703
774
  state = {
704
775
  ...state,
705
776
  requestId: proposed.requestId,
706
777
  updatedAt: this.#now(),
778
+ ...(requestedGrantsStatus !== undefined && {
779
+ requestedGrantsStatus,
780
+ }),
707
781
  };
708
782
  await writeStateAtomic(this.#paths.statePath, state, this.#ancestorOptions);
709
783
  }
@@ -716,6 +790,7 @@ export class ClaustrumEnrollmentManager {
716
790
  state: 'pending',
717
791
  proposedName: state.proposedName,
718
792
  retryCode: refusal.code,
793
+ ...grantProposal(state),
719
794
  };
720
795
  }
721
796
  // A vault without the ceremony cannot hold a request for this
@@ -772,6 +847,7 @@ export class ClaustrumEnrollmentManager {
772
847
  proposedName: state.proposedName,
773
848
  approvedName: outcome.name,
774
849
  tokenGeneration: outcome.tokenGeneration,
850
+ ...grantProposal(state),
775
851
  updatedAt: this.#now(),
776
852
  };
777
853
  await writeStateAtomic(this.#paths.statePath, approved, this.#ancestorOptions);
@@ -787,6 +863,7 @@ export class ClaustrumEnrollmentManager {
787
863
  proposedName: state.proposedName,
788
864
  requestId,
789
865
  retryCode: refusal.code,
866
+ ...grantProposal(state),
790
867
  };
791
868
  }
792
869
  return this.#block(state, refusal.code);
@@ -10,7 +10,7 @@ export { ClaustrumCredentialError, } from "@cortexkit/claustrum-client";
10
10
  export { ClaustrumUnreachableError, classifyVaultFailure, VAULT_FAILURE_CLASSES, } from "./94f53cfd572ba4bb-availability.js";
11
11
  export { ClaustrumConsumer, DEFAULT_CONNECT_TIMEOUT_MS, } from "./169b2b4bf30909bc-consumer.js";
12
12
  export { ClaustrumScopedCustody, decideScopedRetryAfter401, isScopedCredentialRotation, KEPT_RECEIPT_MARGIN_MS, SERVING_MARGIN_MS, } from "./0f77ebc3c914c9c6-custody.js";
13
- export { ClaustrumEnrollmentManager, classifyEnrollmentError, connectClaustrumEnrollmentClient, disconnectClaustrumEnrollment, enrollmentAuthority, enrollmentName, getClaustrumEnrollmentPaths, hostEnrollmentPaths, RETRYABLE_ENROLLMENT_CODES, readClaustrumEnrollmentStatus, readClaustrumEnrollmentToken, resetClaustrumEnrollmentState, TERMINAL_ENROLLMENT_CODES, validEnrollmentDisplayName, vaultAuthority, } from "./b9588ad4725c1d10-enrollment.js";
13
+ export { ClaustrumEnrollmentManager, classifyEnrollmentError, connectClaustrumEnrollmentClient, disconnectClaustrumEnrollment, enrollmentAuthority, enrollmentName, getClaustrumEnrollmentPaths, hostEnrollmentPaths, RETRYABLE_ENROLLMENT_CODES, readClaustrumEnrollmentStatus, readClaustrumEnrollmentToken, resetClaustrumEnrollmentState, TERMINAL_ENROLLMENT_CODES, validEnrollmentDisplayName, validEnrollmentRequestedGrants, vaultAuthority, } from "./b9588ad4725c1d10-enrollment.js";
14
14
  export { ClaustrumConsumerError, } from "./ca0fccaba1d87af4-errors.js";
15
15
  export { connectVaultHost, hasVaultHost, VAULT_HOST_CONNECT_REFUSAL, VAULT_HOST_STATUS, } from "./c97089ed4243981c-host.js";
16
16
  export { assertHostSlotMatchesMode, assertNotCustodyPlaceholder, CUSTODY_PLACEHOLDER_PREFIX, classifyHostSlot, custodyPlaceholder, custodyPlaceholderKey, isCustodyPlaceholder, isCustodyPlaceholderValue, } from "./d9d2892a4c371301-host-slot.js";