sidekick-shared 0.20.0 → 0.21.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 (44) hide show
  1. package/README.md +14 -2
  2. package/dist/accountManager.d.ts +52 -0
  3. package/dist/accountManager.js +344 -0
  4. package/dist/accounts.d.ts +3 -0
  5. package/dist/accounts.js +180 -40
  6. package/dist/autoSwitch.d.ts +70 -0
  7. package/dist/autoSwitch.js +160 -0
  8. package/dist/claudeProfiles.d.ts +12 -0
  9. package/dist/claudeProfiles.js +96 -0
  10. package/dist/codexProfiles.d.ts +6 -2
  11. package/dist/codexProfiles.js +6 -1
  12. package/dist/credentialIO.d.ts +3 -2
  13. package/dist/credentialIO.js +11 -9
  14. package/dist/ensureDefaultAccounts.js +6 -0
  15. package/dist/index.d.ts +16 -3
  16. package/dist/index.js +60 -5
  17. package/dist/multiProviderQuotaService.d.ts +10 -0
  18. package/dist/multiProviderQuotaService.js +34 -0
  19. package/dist/providerQuota.d.ts +2 -1
  20. package/dist/providers/detect.js +3 -13
  21. package/dist/providers/openCode.d.ts +31 -0
  22. package/dist/providers/openCode.js +108 -2
  23. package/dist/providers/openCodeDatabase.d.ts +19 -0
  24. package/dist/providers/openCodeDatabase.js +28 -0
  25. package/dist/quota.d.ts +1 -1
  26. package/dist/quotaHistory.d.ts +1 -1
  27. package/dist/quotaHistory.js +14 -2
  28. package/dist/quotaSnapshots.d.ts +8 -2
  29. package/dist/schemas/accountManager.d.ts +104 -0
  30. package/dist/schemas/accountManager.js +84 -0
  31. package/dist/schemas/assistantTurn.d.ts +5 -5
  32. package/dist/schemas/index.d.ts +5 -1
  33. package/dist/schemas/index.js +10 -1
  34. package/dist/schemas/quota.d.ts +185 -20
  35. package/dist/schemas/quota.js +8 -1
  36. package/dist/schemas/quotaHistory.d.ts +3 -1
  37. package/dist/schemas/quotaHistory.js +1 -0
  38. package/dist/terminalSync.d.ts +7 -0
  39. package/dist/terminalSync.js +202 -0
  40. package/dist/zaiQuota.d.ts +209 -0
  41. package/dist/zaiQuota.js +290 -0
  42. package/dist/zaiQuotaWatcher.d.ts +97 -0
  43. package/dist/zaiQuotaWatcher.js +259 -0
  44. package/package.json +1 -1
@@ -51,6 +51,7 @@ var __importStar = (this && this.__importStar) || (function () {
51
51
  })();
52
52
  Object.defineProperty(exports, "__esModule", { value: true });
53
53
  exports.OpenCodeProvider = void 0;
54
+ exports.getOpenCodeDataDir = getOpenCodeDataDir;
54
55
  const fs = __importStar(require("fs"));
55
56
  const os = __importStar(require("os"));
56
57
  const path = __importStar(require("path"));
@@ -58,19 +59,42 @@ const child_process_1 = require("child_process");
58
59
  const sessionContext_1 = require("../context/sessionContext");
59
60
  const openCodeParser_1 = require("../parsers/openCodeParser");
60
61
  const openCodeDatabase_1 = require("./openCodeDatabase");
62
+ const zaiQuota_1 = require("../zaiQuota");
61
63
  const modelContext_1 = require("../modelContext");
62
64
  // ---------------------------------------------------------------------------
63
65
  // Helper functions
64
66
  // ---------------------------------------------------------------------------
65
67
  /**
66
68
  * Gets the OpenCode data directory.
67
- * Respects XDG_DATA_HOME if set, otherwise uses ~/.local/share/opencode/
69
+ *
70
+ * Resolves in priority order: `XDG_DATA_HOME` (if set), then whichever of
71
+ * the platform-default candidates actually contains an `opencode.db` file.
72
+ * OpenCode's CLI has historically used the Linux-style `~/.local/share/opencode`
73
+ * path even on macOS, so we probe both and pick whichever exists — falling
74
+ * back to the platform default when neither is present yet.
68
75
  */
69
76
  function getOpenCodeDataDir() {
70
77
  const xdg = process.env.XDG_DATA_HOME;
71
- if (xdg) {
78
+ if (xdg)
72
79
  return path.join(xdg, 'opencode');
80
+ const candidates = [path.join(os.homedir(), '.local', 'share', 'opencode')];
81
+ if (process.platform === 'darwin') {
82
+ candidates.push(path.join(os.homedir(), 'Library', 'Application Support', 'opencode'));
83
+ }
84
+ else if (process.platform === 'win32') {
85
+ candidates.push(path.join(process.env.LOCALAPPDATA || process.env.APPDATA || path.join(os.homedir(), 'AppData', 'Local'), 'opencode'));
86
+ }
87
+ for (const candidate of candidates) {
88
+ try {
89
+ if (fs.existsSync(path.join(candidate, 'opencode.db')))
90
+ return candidate;
91
+ }
92
+ catch {
93
+ // ignore — try the next candidate.
94
+ }
73
95
  }
96
+ // Nothing found yet — return the platform default so a fresh OpenCode
97
+ // install gets detected at the conventional location for this OS.
74
98
  if (process.platform === 'darwin') {
75
99
  return path.join(os.homedir(), 'Library', 'Application Support', 'opencode');
76
100
  }
@@ -1548,5 +1572,87 @@ class OpenCodeProvider {
1548
1572
  this.sessionMetaCache.clear();
1549
1573
  this.dynamicContextWindowLimit = null;
1550
1574
  }
1575
+ // --- z.ai (GLM Coding Plan) quota derivation ---
1576
+ /**
1577
+ * Derives a z.ai coding-plan `QuotaState` from OpenCode assistant turns
1578
+ * tagged with `providerID ∈ {zai, zai-coding-plan}`.
1579
+ *
1580
+ * z.ai does not expose a quota API (verified vs. docs.z.ai/openapi.json),
1581
+ * so this method accumulates observed per-turn tokens from OpenCode's DB
1582
+ * into 5-hour / 7-day rolling windows and infers utilization against the
1583
+ * configured tier budget. Returns null when no z.ai routing is detected.
1584
+ *
1585
+ * @param tier Plan tier; `'auto'` infers from observed weekly volume.
1586
+ * When the caller has no opinion, the heuristic falls back to
1587
+ * `'max'` (conservative — small overcount rather than large).
1588
+ */
1589
+ getZaiQuotaState(tier = 'auto') {
1590
+ const db = this.ensureDb();
1591
+ if (!db)
1592
+ return null;
1593
+ const sinceMs = Date.now() - 7 * 86_400_000;
1594
+ let rawRows = [];
1595
+ try {
1596
+ rawRows = db.getAssistantMessagesByProviderId([...zaiQuota_1.ZAI_PROVIDER_IDS], sinceMs);
1597
+ }
1598
+ catch {
1599
+ return null;
1600
+ }
1601
+ if (rawRows.length === 0)
1602
+ return null;
1603
+ const turns = rawRows.map(row => ({
1604
+ timestampMs: row.timeCreated,
1605
+ model: row.modelId,
1606
+ inputTokens: row.inputTokens || 0,
1607
+ outputTokens: row.outputTokens || 0,
1608
+ cacheReadTokens: row.cacheReadTokens || 0,
1609
+ cacheWriteTokens: row.cacheWriteTokens || 0,
1610
+ reasoningTokens: row.reasoningTokens || 0,
1611
+ }));
1612
+ const accumulated = (0, zaiQuota_1.accumulateZaiUsage)(turns, Date.now());
1613
+ // Default to 'max' on auto when usage is non-zero — overestimating the
1614
+ // tier gives a lower (safer) utilization % until calibration runs.
1615
+ const resolvedTier = tier === 'auto'
1616
+ ? (accumulated.weeklyTurns > 0 ? 'max' : 'lite')
1617
+ : tier;
1618
+ // Walk rows again to trap any captured z.ai business errors.
1619
+ let authoritativeFiveHourResetAt;
1620
+ let authoritativeWeeklyResetAt;
1621
+ for (const row of rawRows) {
1622
+ if (row.errorCode == null && !row.errorMessage)
1623
+ continue;
1624
+ const parsed = (0, zaiQuota_1.parseZaiQuotaError)({
1625
+ code: row.errorCode ?? undefined,
1626
+ message: row.errorMessage ?? undefined,
1627
+ });
1628
+ if (!parsed?.resetsAt)
1629
+ continue;
1630
+ if (parsed.kind === 'exhausted') {
1631
+ authoritativeFiveHourResetAt = parsed.resetsAt;
1632
+ if (String(parsed.code) === '1310')
1633
+ authoritativeWeeklyResetAt = parsed.resetsAt;
1634
+ }
1635
+ }
1636
+ return (0, zaiQuota_1.inferZaiQuotaState)(accumulated, resolvedTier, {
1637
+ authoritativeFiveHourResetAt,
1638
+ authoritativeWeeklyResetAt,
1639
+ });
1640
+ }
1641
+ /**
1642
+ * Cheap boolean: does the local OpenCode install currently route at z.ai?
1643
+ * Used by callers to decide whether to render a z.ai quota surface.
1644
+ */
1645
+ isZaiRoutingActive() {
1646
+ const db = this.ensureDb();
1647
+ if (!db)
1648
+ return false;
1649
+ try {
1650
+ const rows = db.getAssistantMessagesByProviderId([...zaiQuota_1.ZAI_PROVIDER_IDS], Date.now() - 7 * 86_400_000);
1651
+ return rows.length > 0;
1652
+ }
1653
+ catch {
1654
+ return false;
1655
+ }
1656
+ }
1551
1657
  }
1552
1658
  exports.OpenCodeProvider = OpenCodeProvider;
@@ -91,6 +91,25 @@ export declare class OpenCodeDatabase {
91
91
  sessionCount: number;
92
92
  maxTimeUpdated: number;
93
93
  }>;
94
+ /**
95
+ * Returns assistant messages tagged with the given providerID(s), completed
96
+ * within `sinceMs`. Used by the z.ai quota accumulator to walk OpenCode's
97
+ * per-turn token records without re-deriving the session filter.
98
+ *
99
+ * Results are ordered oldest-first by `time_created`.
100
+ */
101
+ getAssistantMessagesByProviderId(providerIds: readonly string[], sinceMs: number): Array<{
102
+ timeCreated: number;
103
+ modelId: string;
104
+ providerId: string;
105
+ inputTokens: number;
106
+ outputTokens: number;
107
+ cacheReadTokens: number;
108
+ cacheWriteTokens: number;
109
+ reasoningTokens: number;
110
+ errorMessage: string | null;
111
+ errorCode: string | null;
112
+ }>;
94
113
  /** Get the database file's mtime (ms epoch). Returns 0 if unavailable. */
95
114
  getDbMtime(): number;
96
115
  }
@@ -249,6 +249,34 @@ class OpenCodeDatabase {
249
249
  getProjectSessionStats() {
250
250
  return this.query('SELECT project_id AS projectId, COUNT(*) AS sessionCount, MAX(time_updated) AS maxTimeUpdated FROM session GROUP BY project_id');
251
251
  }
252
+ /**
253
+ * Returns assistant messages tagged with the given providerID(s), completed
254
+ * within `sinceMs`. Used by the z.ai quota accumulator to walk OpenCode's
255
+ * per-turn token records without re-deriving the session filter.
256
+ *
257
+ * Results are ordered oldest-first by `time_created`.
258
+ */
259
+ getAssistantMessagesByProviderId(providerIds, sinceMs) {
260
+ if (providerIds.length === 0)
261
+ return [];
262
+ const providerClauses = providerIds.map(() => 'json_extract(data, \'$.providerID\') = ?').join(' OR ');
263
+ return this.query(`SELECT
264
+ time_created AS timeCreated,
265
+ COALESCE(json_extract(data, '$.modelID'), 'unknown') AS modelId,
266
+ COALESCE(json_extract(data, '$.providerID'), '') AS providerId,
267
+ COALESCE(json_extract(data, '$.tokens.input'), 0) AS inputTokens,
268
+ COALESCE(json_extract(data, '$.tokens.output'), 0) AS outputTokens,
269
+ COALESCE(json_extract(data, '$.tokens.cache.read'), 0) AS cacheReadTokens,
270
+ COALESCE(json_extract(data, '$.tokens.cache.write'), 0) AS cacheWriteTokens,
271
+ COALESCE(json_extract(data, '$.tokens.reasoning'), 0) AS reasoningTokens,
272
+ json_extract(data, '$.error.message') AS errorMessage,
273
+ json_extract(data, '$.error.code') AS errorCode
274
+ FROM message
275
+ WHERE time_created >= ?
276
+ AND json_extract(data, '$.role') = 'assistant'
277
+ AND (${providerClauses})
278
+ ORDER BY time_created ASC`, [sinceMs, ...providerIds]);
279
+ }
252
280
  /** Get the database file's mtime (ms epoch). Returns 0 if unavailable. */
253
281
  getDbMtime() {
254
282
  try {
package/dist/quota.d.ts CHANGED
@@ -28,7 +28,7 @@ export interface QuotaState {
28
28
  /** Projected 7-day utilization at reset (percentage, capped at 200) */
29
29
  projectedSevenDay?: number;
30
30
  /** Provider that produced this quota sample */
31
- providerId?: 'claude-code' | 'codex';
31
+ providerId?: 'claude-code' | 'codex' | 'zai';
32
32
  /** Source of the sample */
33
33
  source?: 'api' | 'session' | 'cache';
34
34
  /** ISO timestamp when the sample was captured */
@@ -6,7 +6,7 @@
6
6
  * dashboard, the `sidekick quota history` CLI, contextful_desktop) can render heatmaps and
7
7
  * trend visualisations over a 13-week window.
8
8
  */
9
- export type QuotaHistoryRuntimeProvider = 'claude' | 'codex';
9
+ export type QuotaHistoryRuntimeProvider = 'claude' | 'codex' | 'zai';
10
10
  export interface QuotaHistorySample {
11
11
  timestamp: string;
12
12
  runtimeProvider: QuotaHistoryRuntimeProvider;
@@ -201,7 +201,7 @@ function pruneFileSync(filePath, retentionDays) {
201
201
  return { kept: keptLines.length, pruned };
202
202
  }
203
203
  function sampleToQuotaState(sample) {
204
- const providerId = sample.runtimeProvider === 'claude' ? 'claude-code' : 'codex';
204
+ const providerId = runtimeProviderToSnapshotProvider(sample.runtimeProvider);
205
205
  return {
206
206
  fiveHour: { utilization: sample.fiveHour.utilization, resetsAt: sample.fiveHour.resetsAt },
207
207
  sevenDay: { utilization: sample.sevenDay.utilization, resetsAt: sample.sevenDay.resetsAt },
@@ -213,6 +213,18 @@ function sampleToQuotaState(sample) {
213
213
  stale: sample.stale,
214
214
  };
215
215
  }
216
+ /**
217
+ * Maps a runtime provider to the snapshot storage key.
218
+ * `'zai'` is allowed at the storage layer even though it is not part of
219
+ * `AccountProviderId` (z.ai has no full account management in v1).
220
+ */
221
+ function runtimeProviderToSnapshotProvider(runtime) {
222
+ if (runtime === 'claude')
223
+ return 'claude-code';
224
+ if (runtime === 'zai')
225
+ return 'zai';
226
+ return 'codex';
227
+ }
216
228
  async function runAppend(sample, filePath, options) {
217
229
  let lastTs = lastWriteCache.get(filePath);
218
230
  if (lastTs === undefined) {
@@ -243,7 +255,7 @@ async function runAppend(sample, filePath, options) {
243
255
  // Backwards-compat: keep the latest-snapshot store hot so existing callers (DashboardViewProvider,
244
256
  // codex session provider, contextful_desktop) don't have to query history for "latest".
245
257
  try {
246
- const providerId = sample.runtimeProvider === 'claude' ? 'claude-code' : 'codex';
258
+ const providerId = runtimeProviderToSnapshotProvider(sample.runtimeProvider);
247
259
  (0, quotaSnapshots_1.writeQuotaSnapshot)(providerId, sample.providerId, sampleToQuotaState(sample));
248
260
  }
249
261
  catch {
@@ -1,4 +1,10 @@
1
1
  import type { QuotaState } from './quota';
2
2
  import type { AccountProviderId } from './accountRegistry';
3
- export declare function writeQuotaSnapshot(providerId: AccountProviderId, accountId: string, quota: QuotaState): void;
4
- export declare function readQuotaSnapshot(providerId: AccountProviderId, accountId: string): QuotaState | null;
3
+ /**
4
+ * Storage key for a quota snapshot. Extends `AccountProviderId` with `'zai'`
5
+ * because z.ai has no full account-management surface in v1, but the snapshot
6
+ * store still needs a stable key for the derived z.ai quota cache.
7
+ */
8
+ export type QuotaSnapshotProviderId = AccountProviderId | 'zai';
9
+ export declare function writeQuotaSnapshot(providerId: QuotaSnapshotProviderId, accountId: string, quota: QuotaState): void;
10
+ export declare function readQuotaSnapshot(providerId: QuotaSnapshotProviderId, accountId: string): QuotaState | null;
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Zod schemas for runtime validation of account management payloads.
3
+ *
4
+ * These schemas mirror the TypeScript interfaces in `accounts.ts`,
5
+ * `accountRegistry.ts`, and `accountManager.ts` (keep in sync when those
6
+ * change). They let consumers validate account-management IPC payloads
7
+ * without hand-mirroring the interfaces.
8
+ *
9
+ * @module schemas/accountManager
10
+ */
11
+ import { z } from 'zod';
12
+ export declare const accountProviderIdSchema: z.ZodEnum<{
13
+ "claude-code": "claude-code";
14
+ codex: "codex";
15
+ }>;
16
+ export declare const accountManagerResultSchema: z.ZodObject<{
17
+ success: z.ZodBoolean;
18
+ error: z.ZodOptional<z.ZodString>;
19
+ warning: z.ZodOptional<z.ZodString>;
20
+ needsLogin: z.ZodOptional<z.ZodBoolean>;
21
+ profileId: z.ZodOptional<z.ZodString>;
22
+ codexHome: z.ZodOptional<z.ZodString>;
23
+ }, z.core.$strip>;
24
+ export declare const beginAccountLoginResultSchema: z.ZodUnion<readonly [z.ZodObject<{
25
+ success: z.ZodLiteral<true>;
26
+ loginId: z.ZodString;
27
+ alreadyComplete: z.ZodOptional<z.ZodBoolean>;
28
+ command: z.ZodOptional<z.ZodString>;
29
+ args: z.ZodOptional<z.ZodArray<z.ZodString>>;
30
+ env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
31
+ configDir: z.ZodOptional<z.ZodString>;
32
+ }, z.core.$strip>, z.ZodObject<{
33
+ success: z.ZodLiteral<false>;
34
+ error: z.ZodString;
35
+ }, z.core.$strip>]>;
36
+ export declare const accountLoginStatusSchema: z.ZodObject<{
37
+ state: z.ZodEnum<{
38
+ pending: "pending";
39
+ authenticated: "authenticated";
40
+ failed: "failed";
41
+ }>;
42
+ email: z.ZodOptional<z.ZodString>;
43
+ error: z.ZodOptional<z.ZodString>;
44
+ }, z.core.$strip>;
45
+ export declare const accountEntrySchema: z.ZodObject<{
46
+ uuid: z.ZodString;
47
+ email: z.ZodString;
48
+ label: z.ZodOptional<z.ZodString>;
49
+ addedAt: z.ZodString;
50
+ }, z.core.$strip>;
51
+ export declare const savedAccountProfileSchema: z.ZodObject<{
52
+ id: z.ZodString;
53
+ providerId: z.ZodEnum<{
54
+ "claude-code": "claude-code";
55
+ codex: "codex";
56
+ }>;
57
+ addedAt: z.ZodString;
58
+ label: z.ZodOptional<z.ZodString>;
59
+ email: z.ZodOptional<z.ZodString>;
60
+ providerAccountId: z.ZodOptional<z.ZodString>;
61
+ metadata: z.ZodOptional<z.ZodObject<{
62
+ email: z.ZodOptional<z.ZodString>;
63
+ workspaceId: z.ZodOptional<z.ZodString>;
64
+ planType: z.ZodOptional<z.ZodString>;
65
+ authMode: z.ZodOptional<z.ZodEnum<{
66
+ chatgpt: "chatgpt";
67
+ "api-key": "api-key";
68
+ unknown: "unknown";
69
+ }>>;
70
+ }, z.core.$strip>>;
71
+ }, z.core.$strip>;
72
+ export declare const listAllAccountsResultSchema: z.ZodObject<{
73
+ claude: z.ZodArray<z.ZodObject<{
74
+ uuid: z.ZodString;
75
+ email: z.ZodString;
76
+ label: z.ZodOptional<z.ZodString>;
77
+ addedAt: z.ZodString;
78
+ }, z.core.$strip>>;
79
+ codex: z.ZodArray<z.ZodObject<{
80
+ id: z.ZodString;
81
+ providerId: z.ZodEnum<{
82
+ "claude-code": "claude-code";
83
+ codex: "codex";
84
+ }>;
85
+ addedAt: z.ZodString;
86
+ label: z.ZodOptional<z.ZodString>;
87
+ email: z.ZodOptional<z.ZodString>;
88
+ providerAccountId: z.ZodOptional<z.ZodString>;
89
+ metadata: z.ZodOptional<z.ZodObject<{
90
+ email: z.ZodOptional<z.ZodString>;
91
+ workspaceId: z.ZodOptional<z.ZodString>;
92
+ planType: z.ZodOptional<z.ZodString>;
93
+ authMode: z.ZodOptional<z.ZodEnum<{
94
+ chatgpt: "chatgpt";
95
+ "api-key": "api-key";
96
+ unknown: "unknown";
97
+ }>>;
98
+ }, z.core.$strip>>;
99
+ }, z.core.$strip>>;
100
+ activeByProvider: z.ZodObject<{
101
+ 'claude-code': z.ZodNullable<z.ZodString>;
102
+ codex: z.ZodNullable<z.ZodString>;
103
+ }, z.core.$strip>;
104
+ }, z.core.$strip>;
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ /**
3
+ * Zod schemas for runtime validation of account management payloads.
4
+ *
5
+ * These schemas mirror the TypeScript interfaces in `accounts.ts`,
6
+ * `accountRegistry.ts`, and `accountManager.ts` (keep in sync when those
7
+ * change). They let consumers validate account-management IPC payloads
8
+ * without hand-mirroring the interfaces.
9
+ *
10
+ * @module schemas/accountManager
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.listAllAccountsResultSchema = exports.savedAccountProfileSchema = exports.accountEntrySchema = exports.accountLoginStatusSchema = exports.beginAccountLoginResultSchema = exports.accountManagerResultSchema = exports.accountProviderIdSchema = void 0;
14
+ const zod_1 = require("zod");
15
+ // ── AccountProviderId ──
16
+ exports.accountProviderIdSchema = zod_1.z.enum([
17
+ 'claude-code',
18
+ 'codex',
19
+ ]);
20
+ // ── AccountManagerResult ──
21
+ exports.accountManagerResultSchema = zod_1.z.object({
22
+ success: zod_1.z.boolean(),
23
+ error: zod_1.z.string().optional(),
24
+ warning: zod_1.z.string().optional(),
25
+ needsLogin: zod_1.z.boolean().optional(),
26
+ profileId: zod_1.z.string().optional(),
27
+ codexHome: zod_1.z.string().optional(),
28
+ });
29
+ // ── BeginAccountLoginResult ──
30
+ const beginAccountLoginSuccessSchema = zod_1.z.object({
31
+ success: zod_1.z.literal(true),
32
+ loginId: zod_1.z.string(),
33
+ alreadyComplete: zod_1.z.boolean().optional(),
34
+ command: zod_1.z.string().optional(),
35
+ args: zod_1.z.array(zod_1.z.string()).optional(),
36
+ env: zod_1.z.record(zod_1.z.string(), zod_1.z.string()).optional(),
37
+ configDir: zod_1.z.string().optional(),
38
+ });
39
+ const beginAccountLoginFailureSchema = zod_1.z.object({
40
+ success: zod_1.z.literal(false),
41
+ error: zod_1.z.string(),
42
+ });
43
+ exports.beginAccountLoginResultSchema = zod_1.z.union([
44
+ beginAccountLoginSuccessSchema,
45
+ beginAccountLoginFailureSchema,
46
+ ]);
47
+ // ── AccountLoginStatus ──
48
+ exports.accountLoginStatusSchema = zod_1.z.object({
49
+ state: zod_1.z.enum(['pending', 'authenticated', 'failed']),
50
+ email: zod_1.z.string().optional(),
51
+ error: zod_1.z.string().optional(),
52
+ });
53
+ // ── AccountEntry ──
54
+ exports.accountEntrySchema = zod_1.z.object({
55
+ uuid: zod_1.z.string(),
56
+ email: zod_1.z.string(),
57
+ label: zod_1.z.string().optional(),
58
+ addedAt: zod_1.z.string(),
59
+ });
60
+ // ── SavedAccountProfile ──
61
+ const accountIdentityMetadataSchema = zod_1.z.object({
62
+ email: zod_1.z.string().optional(),
63
+ workspaceId: zod_1.z.string().optional(),
64
+ planType: zod_1.z.string().optional(),
65
+ authMode: zod_1.z.enum(['chatgpt', 'api-key', 'unknown']).optional(),
66
+ });
67
+ exports.savedAccountProfileSchema = zod_1.z.object({
68
+ id: zod_1.z.string(),
69
+ providerId: exports.accountProviderIdSchema,
70
+ addedAt: zod_1.z.string(),
71
+ label: zod_1.z.string().optional(),
72
+ email: zod_1.z.string().optional(),
73
+ providerAccountId: zod_1.z.string().optional(),
74
+ metadata: accountIdentityMetadataSchema.optional(),
75
+ });
76
+ // ── ListAllAccountsResult ──
77
+ exports.listAllAccountsResultSchema = zod_1.z.object({
78
+ claude: zod_1.z.array(exports.accountEntrySchema),
79
+ codex: zod_1.z.array(exports.savedAccountProfileSchema),
80
+ activeByProvider: zod_1.z.object({
81
+ 'claude-code': zod_1.z.string().nullable(),
82
+ codex: zod_1.z.string().nullable(),
83
+ }),
84
+ });
@@ -7,9 +7,9 @@
7
7
  import { z } from 'zod';
8
8
  export declare const assistantTurnEventTypeSchema: z.ZodEnum<{
9
9
  status: "status";
10
+ error: "error";
10
11
  tool_use: "tool_use";
11
12
  tool_result: "tool_result";
12
- error: "error";
13
13
  text: "text";
14
14
  progress: "progress";
15
15
  thinking: "thinking";
@@ -18,9 +18,9 @@ export declare const assistantTurnEventTypeSchema: z.ZodEnum<{
18
18
  export declare const assistantTurnEventSchema: z.ZodObject<{
19
19
  eventType: z.ZodEnum<{
20
20
  status: "status";
21
+ error: "error";
21
22
  tool_use: "tool_use";
22
23
  tool_result: "tool_result";
23
- error: "error";
24
24
  text: "text";
25
25
  progress: "progress";
26
26
  thinking: "thinking";
@@ -96,8 +96,8 @@ export declare const assistantTurnProcessSchema: z.ZodObject<{
96
96
  }, z.core.$strip>], "kind">>;
97
97
  }, z.core.$strip>;
98
98
  export declare const assistantTurnSubagentStatusSchema: z.ZodEnum<{
99
- completed: "completed";
100
99
  failed: "failed";
100
+ completed: "completed";
101
101
  running: "running";
102
102
  }>;
103
103
  export declare const assistantTurnSubagentSchema: z.ZodObject<{
@@ -105,8 +105,8 @@ export declare const assistantTurnSubagentSchema: z.ZodObject<{
105
105
  label: z.ZodString;
106
106
  agentType: z.ZodOptional<z.ZodString>;
107
107
  status: z.ZodEnum<{
108
- completed: "completed";
109
108
  failed: "failed";
109
+ completed: "completed";
110
110
  running: "running";
111
111
  }>;
112
112
  }, z.core.$strip>;
@@ -147,8 +147,8 @@ export declare const assistantTurnProjectionSchema: z.ZodObject<{
147
147
  label: z.ZodString;
148
148
  agentType: z.ZodOptional<z.ZodString>;
149
149
  status: z.ZodEnum<{
150
- completed: "completed";
151
150
  failed: "failed";
151
+ completed: "completed";
152
152
  running: "running";
153
153
  }>;
154
154
  }, z.core.$strip>>;
@@ -12,7 +12,7 @@
12
12
  */
13
13
  export { messageUsageSchema, sessionMessageSchema, sessionEventSchema, permissionModeSchema, extractSessionEvents, } from './sessionEvent';
14
14
  export type { MessageUsage, SessionMessage, SessionEvent, PermissionMode, } from '../types/sessionEvent';
15
- export { quotaWindowSchema, quotaStateSchema, quotaFailureKindSchema, quotaProviderIdSchema, quotaSourceSchema, peakHoursStateSchema, quotaFailureDescriptorSchema, runtimeQuotaProviderSchema, providerQuotaStateSchema, claudeProviderQuotaStateSchema, codexProviderQuotaStateSchema, providerQuotaMapSchema, } from './quota';
15
+ export { quotaWindowSchema, quotaStateSchema, quotaFailureKindSchema, quotaProviderIdSchema, quotaSourceSchema, peakHoursStateSchema, quotaFailureDescriptorSchema, runtimeQuotaProviderSchema, providerQuotaStateSchema, claudeProviderQuotaStateSchema, codexProviderQuotaStateSchema, zaiProviderQuotaStateSchema, providerQuotaMapSchema, } from './quota';
16
16
  export type { QuotaWindow, QuotaState } from '../quota';
17
17
  export type { PeakHoursState } from '../peakHours';
18
18
  export type { QuotaFailureDescriptor } from '../quotaPresentation';
@@ -21,5 +21,9 @@ export { quotaHistoryRuntimeProviderSchema, quotaHistorySampleSchema, quotaHisto
21
21
  export type { QuotaHistoryRuntimeProvider, QuotaHistorySample, QuotaHistoryDailyBucket, } from '../quotaHistory';
22
22
  export { activeProviderAccountStatusSchema, activeAccountStatusSchema, } from './accountStatus';
23
23
  export type { ActiveProviderAccountStatus, ActiveAccountStatus, } from '../accountStatus';
24
+ export { accountProviderIdSchema, accountManagerResultSchema, beginAccountLoginResultSchema, accountLoginStatusSchema, accountEntrySchema, savedAccountProfileSchema, listAllAccountsResultSchema, } from './accountManager';
25
+ export type { AccountEntry, AccountManagerResult } from '../accounts';
26
+ export type { AccountProviderId, SavedAccountProfile, } from '../accountRegistry';
27
+ export type { AccountLoginStatus, BeginAccountLoginResult, ListAllAccountsResult, } from '../accountManager';
24
28
  export { assistantTurnEventSchema, assistantTurnEventTypeSchema, assistantTurnNarrationStepSchema, assistantTurnProcessSchema, assistantTurnProcessStepSchema, assistantTurnProjectionSchema, assistantTurnReasoningTimelineItemSchema, assistantTurnSubagentSchema, assistantTurnSubagentStatusSchema, assistantTurnTimelineItemSchema, assistantTurnToolGroupStepSchema, assistantTurnToolRefSchema, } from './assistantTurn';
25
29
  export type { AssistantTurnEvent, AssistantTurnEventType, AssistantTurnProcess, AssistantTurnProcessStep, AssistantTurnProjection, AssistantTurnSubagent, AssistantTurnSubagentStatus, AssistantTurnTimelineItem, AssistantTurnToolRef, } from '../turns/assistantTurn';
@@ -12,7 +12,7 @@
12
12
  * subpath is self-sufficient for boundary-validation modules.
13
13
  */
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.assistantTurnToolRefSchema = exports.assistantTurnToolGroupStepSchema = exports.assistantTurnTimelineItemSchema = exports.assistantTurnSubagentStatusSchema = exports.assistantTurnSubagentSchema = exports.assistantTurnReasoningTimelineItemSchema = exports.assistantTurnProjectionSchema = exports.assistantTurnProcessStepSchema = exports.assistantTurnProcessSchema = exports.assistantTurnNarrationStepSchema = exports.assistantTurnEventTypeSchema = exports.assistantTurnEventSchema = exports.activeAccountStatusSchema = exports.activeProviderAccountStatusSchema = exports.quotaHistoryDailyBucketSchema = exports.quotaHistorySampleSchema = exports.quotaHistoryRuntimeProviderSchema = exports.providerQuotaMapSchema = exports.codexProviderQuotaStateSchema = exports.claudeProviderQuotaStateSchema = exports.providerQuotaStateSchema = exports.runtimeQuotaProviderSchema = exports.quotaFailureDescriptorSchema = exports.peakHoursStateSchema = exports.quotaSourceSchema = exports.quotaProviderIdSchema = exports.quotaFailureKindSchema = exports.quotaStateSchema = exports.quotaWindowSchema = exports.extractSessionEvents = exports.permissionModeSchema = exports.sessionEventSchema = exports.sessionMessageSchema = exports.messageUsageSchema = void 0;
15
+ exports.assistantTurnToolRefSchema = exports.assistantTurnToolGroupStepSchema = exports.assistantTurnTimelineItemSchema = exports.assistantTurnSubagentStatusSchema = exports.assistantTurnSubagentSchema = exports.assistantTurnReasoningTimelineItemSchema = exports.assistantTurnProjectionSchema = exports.assistantTurnProcessStepSchema = exports.assistantTurnProcessSchema = exports.assistantTurnNarrationStepSchema = exports.assistantTurnEventTypeSchema = exports.assistantTurnEventSchema = exports.listAllAccountsResultSchema = exports.savedAccountProfileSchema = exports.accountEntrySchema = exports.accountLoginStatusSchema = exports.beginAccountLoginResultSchema = exports.accountManagerResultSchema = exports.accountProviderIdSchema = exports.activeAccountStatusSchema = exports.activeProviderAccountStatusSchema = exports.quotaHistoryDailyBucketSchema = exports.quotaHistorySampleSchema = exports.quotaHistoryRuntimeProviderSchema = exports.providerQuotaMapSchema = exports.zaiProviderQuotaStateSchema = exports.codexProviderQuotaStateSchema = exports.claudeProviderQuotaStateSchema = exports.providerQuotaStateSchema = exports.runtimeQuotaProviderSchema = exports.quotaFailureDescriptorSchema = exports.peakHoursStateSchema = exports.quotaSourceSchema = exports.quotaProviderIdSchema = exports.quotaFailureKindSchema = exports.quotaStateSchema = exports.quotaWindowSchema = exports.extractSessionEvents = exports.permissionModeSchema = exports.sessionEventSchema = exports.sessionMessageSchema = exports.messageUsageSchema = void 0;
16
16
  var sessionEvent_1 = require("./sessionEvent");
17
17
  Object.defineProperty(exports, "messageUsageSchema", { enumerable: true, get: function () { return sessionEvent_1.messageUsageSchema; } });
18
18
  Object.defineProperty(exports, "sessionMessageSchema", { enumerable: true, get: function () { return sessionEvent_1.sessionMessageSchema; } });
@@ -31,6 +31,7 @@ Object.defineProperty(exports, "runtimeQuotaProviderSchema", { enumerable: true,
31
31
  Object.defineProperty(exports, "providerQuotaStateSchema", { enumerable: true, get: function () { return quota_1.providerQuotaStateSchema; } });
32
32
  Object.defineProperty(exports, "claudeProviderQuotaStateSchema", { enumerable: true, get: function () { return quota_1.claudeProviderQuotaStateSchema; } });
33
33
  Object.defineProperty(exports, "codexProviderQuotaStateSchema", { enumerable: true, get: function () { return quota_1.codexProviderQuotaStateSchema; } });
34
+ Object.defineProperty(exports, "zaiProviderQuotaStateSchema", { enumerable: true, get: function () { return quota_1.zaiProviderQuotaStateSchema; } });
34
35
  Object.defineProperty(exports, "providerQuotaMapSchema", { enumerable: true, get: function () { return quota_1.providerQuotaMapSchema; } });
35
36
  var quotaHistory_1 = require("./quotaHistory");
36
37
  Object.defineProperty(exports, "quotaHistoryRuntimeProviderSchema", { enumerable: true, get: function () { return quotaHistory_1.quotaHistoryRuntimeProviderSchema; } });
@@ -39,6 +40,14 @@ Object.defineProperty(exports, "quotaHistoryDailyBucketSchema", { enumerable: tr
39
40
  var accountStatus_1 = require("./accountStatus");
40
41
  Object.defineProperty(exports, "activeProviderAccountStatusSchema", { enumerable: true, get: function () { return accountStatus_1.activeProviderAccountStatusSchema; } });
41
42
  Object.defineProperty(exports, "activeAccountStatusSchema", { enumerable: true, get: function () { return accountStatus_1.activeAccountStatusSchema; } });
43
+ var accountManager_1 = require("./accountManager");
44
+ Object.defineProperty(exports, "accountProviderIdSchema", { enumerable: true, get: function () { return accountManager_1.accountProviderIdSchema; } });
45
+ Object.defineProperty(exports, "accountManagerResultSchema", { enumerable: true, get: function () { return accountManager_1.accountManagerResultSchema; } });
46
+ Object.defineProperty(exports, "beginAccountLoginResultSchema", { enumerable: true, get: function () { return accountManager_1.beginAccountLoginResultSchema; } });
47
+ Object.defineProperty(exports, "accountLoginStatusSchema", { enumerable: true, get: function () { return accountManager_1.accountLoginStatusSchema; } });
48
+ Object.defineProperty(exports, "accountEntrySchema", { enumerable: true, get: function () { return accountManager_1.accountEntrySchema; } });
49
+ Object.defineProperty(exports, "savedAccountProfileSchema", { enumerable: true, get: function () { return accountManager_1.savedAccountProfileSchema; } });
50
+ Object.defineProperty(exports, "listAllAccountsResultSchema", { enumerable: true, get: function () { return accountManager_1.listAllAccountsResultSchema; } });
42
51
  var assistantTurn_1 = require("./assistantTurn");
43
52
  Object.defineProperty(exports, "assistantTurnEventSchema", { enumerable: true, get: function () { return assistantTurn_1.assistantTurnEventSchema; } });
44
53
  Object.defineProperty(exports, "assistantTurnEventTypeSchema", { enumerable: true, get: function () { return assistantTurn_1.assistantTurnEventTypeSchema; } });