@cortexkit/common-auth 0.11.5 → 0.11.6

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.
@@ -1,6 +1,6 @@
1
1
  export type { AccountsSectionOptions, LimitsSectionOptions, LoginOutcome, QuotaSectionOptions, RoutingSectionOptions, } from './builtins.js';
2
2
  export { MENU_DISABLED_REASON } from './builtins.js';
3
- export type { CommandMenu, CommandMenuOptions } from './menu.js';
3
+ export type { CommandMenu, CommandMenuOptions, StoreSectionSlot, } from './menu.js';
4
4
  export { createCommandMenu, parseApplyRequest } from './menu.js';
5
5
  export type { ActionDefinition, ActionInput, ActionOutcome, CommandApplyRequest, CommandApplyResult, CommandDialogPayload, CommandInvocation, CommandMenuModel, ItemDefinition, KnobValue, KnobValues, MenuAccount, MenuAction, MenuChoice, MenuConfirmation, MenuItem, MenuKnob, MenuSection, NotifyKind, PluginExtraSection, PluginSection, SectionContent, SectionSlot, } from './model.js';
6
6
  export { SECTION_SLOTS } from './model.js';
@@ -3,12 +3,26 @@ import type { PoolLockSpec, PoolStore } from '../store/index.js';
3
3
  import { type AccountsSectionOptions, type LimitsSectionOptions, type QuotaSectionOptions, type RoutingSectionOptions } from './builtins.js';
4
4
  import type { CommandApplyRequest, CommandApplyResult, CommandDialogPayload, CommandInvocation, PluginExtraSection, PluginSection } from './model.js';
5
5
  import { type SeamLogger } from './seam.js';
6
+ /** The four slots the library can build from a pool store. */
7
+ export type StoreSectionSlot = 'accounts' | 'quota' | 'routing' | 'limits';
6
8
  export interface CommandMenuOptions {
7
9
  /** The slash command's name without the slash (`openai`, `claude`). */
8
10
  command: string;
9
11
  /** The dialog title. */
10
12
  title: string;
11
- store: PoolStore;
13
+ /**
14
+ * The pool store the built-in Accounts, Quota, Routing and Limits sections
15
+ * read and write. Required unless `replace` supplies all four.
16
+ */
17
+ store?: PoolStore;
18
+ /**
19
+ * Plugin sections that take the place of built-in ones, keeping their slot
20
+ * and the fixed order. For a plugin whose accounts are not pool rows (a
21
+ * single host login, or rows it must not expose by id), so it renders its
22
+ * own items and actions without a store. A replaced slot's built-in
23
+ * options (`accounts`, `quota`, ...) must not be given.
24
+ */
25
+ replace?: Partial<Record<StoreSectionSlot, PluginSection>>;
12
26
  /** The plugin's legacy locks, passed to every store write the menu makes. */
13
27
  extraLocks?: readonly PoolLockSpec[];
14
28
  accounts?: AccountsSectionOptions;
@@ -13,6 +13,12 @@ const BUILTIN_IDS = new Set([
13
13
  'cache',
14
14
  'diagnostics',
15
15
  ]);
16
+ const STORE_SLOTS = [
17
+ 'accounts',
18
+ 'quota',
19
+ 'routing',
20
+ 'limits',
21
+ ];
16
22
  /**
17
23
  * A private copy of the caller's context, taken before the first await. Work
18
24
  * an invocation leaves running reports through this copy, so a host that
@@ -102,6 +108,15 @@ export function createCommandMenu(options) {
102
108
  const seam = { logger, redact };
103
109
  const now = options.now ?? Date.now;
104
110
  const extras = options.extras ?? [];
111
+ const replaced = options.replace ?? {};
112
+ const builtSlots = STORE_SLOTS.filter((slot) => !replaced[slot]);
113
+ for (const slot of STORE_SLOTS) {
114
+ if (replaced[slot] && options[slot] !== undefined)
115
+ throw new Error(`the ${slot} section is replaced; its built-in options cannot also be given`);
116
+ }
117
+ const store = options.store;
118
+ if (builtSlots.length > 0 && !store)
119
+ throw new Error(`a store is required for the built-in ${builtSlots.join(', ')} section${builtSlots.length > 1 ? 's' : ''}`);
105
120
  const seen = new Set();
106
121
  for (const extra of extras) {
107
122
  if (BUILTIN_IDS.has(extra.id) || seen.has(extra.id))
@@ -134,15 +149,30 @@ export function createCommandMenu(options) {
134
149
  }
135
150
  /** Every section, in the fixed slot order. */
136
151
  async function sections(invocation) {
137
- const out = await builtinSections({
138
- store: options.store,
139
- now,
140
- ...(options.extraLocks ? { extraLocks: options.extraLocks } : {}),
141
- ...(options.accounts ? { accounts: options.accounts } : {}),
142
- ...(options.quota ? { quota: options.quota } : {}),
143
- ...(options.routing ? { routing: options.routing } : {}),
144
- ...(options.limits ? { limits: options.limits } : {}),
145
- });
152
+ // Built-in sections read the store once; a fully replaced menu never
153
+ // touches it.
154
+ const built = store && builtSlots.length > 0
155
+ ? await builtinSections({
156
+ store,
157
+ now,
158
+ ...(options.extraLocks ? { extraLocks: options.extraLocks } : {}),
159
+ ...(options.accounts ? { accounts: options.accounts } : {}),
160
+ ...(options.quota ? { quota: options.quota } : {}),
161
+ ...(options.routing ? { routing: options.routing } : {}),
162
+ ...(options.limits ? { limits: options.limits } : {}),
163
+ })
164
+ : [];
165
+ const out = [];
166
+ for (const slot of STORE_SLOTS) {
167
+ const replacement = replaced[slot];
168
+ if (replacement)
169
+ out.push(await plugin(slot, slot, replacement, invocation));
170
+ else {
171
+ const section = built.find((entry) => entry.slot === slot);
172
+ if (section)
173
+ out.push(section);
174
+ }
175
+ }
146
176
  if (options.cache)
147
177
  out.push(await plugin('cache', 'cache', options.cache, invocation));
148
178
  if (options.diagnostics)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cortexkit/common-auth",
3
- "version": "0.11.5",
3
+ "version": "0.11.6",
4
4
  "description": "Shared code for the CortexKit auth plugins: account pool, quota and routing, commands and auth menu, OpenCode 2 hooks, Claustrum custody, and plumbing (loopback RPC, file locks, logger, sidebar state, TUI preferences and build).",
5
5
  "license": "MIT",
6
6
  "repository": {