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
@@ -15,18 +15,19 @@ export declare const quotaWindowSchema: z.ZodObject<{
15
15
  }, z.core.$strip>;
16
16
  export declare const quotaFailureKindSchema: z.ZodEnum<{
17
17
  unknown: "unknown";
18
- rate_limit: "rate_limit";
19
18
  auth: "auth";
20
19
  network: "network";
20
+ rate_limit: "rate_limit";
21
21
  server: "server";
22
22
  }>;
23
23
  export declare const quotaProviderIdSchema: z.ZodEnum<{
24
24
  "claude-code": "claude-code";
25
25
  codex: "codex";
26
+ zai: "zai";
26
27
  }>;
27
28
  export declare const quotaSourceSchema: z.ZodEnum<{
28
- session: "session";
29
29
  api: "api";
30
+ session: "session";
30
31
  cache: "cache";
31
32
  }>;
32
33
  export declare const quotaStateSchema: z.ZodObject<{
@@ -42,9 +43,9 @@ export declare const quotaStateSchema: z.ZodObject<{
42
43
  error: z.ZodOptional<z.ZodString>;
43
44
  failureKind: z.ZodOptional<z.ZodEnum<{
44
45
  unknown: "unknown";
45
- rate_limit: "rate_limit";
46
46
  auth: "auth";
47
47
  network: "network";
48
+ rate_limit: "rate_limit";
48
49
  server: "server";
49
50
  }>>;
50
51
  httpStatus: z.ZodOptional<z.ZodNumber>;
@@ -54,10 +55,11 @@ export declare const quotaStateSchema: z.ZodObject<{
54
55
  providerId: z.ZodOptional<z.ZodEnum<{
55
56
  "claude-code": "claude-code";
56
57
  codex: "codex";
58
+ zai: "zai";
57
59
  }>>;
58
60
  source: z.ZodOptional<z.ZodEnum<{
59
- session: "session";
60
61
  api: "api";
62
+ session: "session";
61
63
  cache: "cache";
62
64
  }>>;
63
65
  capturedAt: z.ZodOptional<z.ZodString>;
@@ -94,8 +96,8 @@ export declare const peakHoursStateSchema: z.ZodObject<{
94
96
  export declare const quotaFailureDescriptorSchema: z.ZodObject<{
95
97
  severity: z.ZodEnum<{
96
98
  error: "error";
97
- info: "info";
98
99
  warning: "warning";
100
+ info: "info";
99
101
  }>;
100
102
  title: z.ZodString;
101
103
  message: z.ZodString;
@@ -106,6 +108,7 @@ export declare const quotaFailureDescriptorSchema: z.ZodObject<{
106
108
  export declare const runtimeQuotaProviderSchema: z.ZodEnum<{
107
109
  codex: "codex";
108
110
  claude: "claude";
111
+ zai: "zai";
109
112
  }>;
110
113
  export declare const providerQuotaStateSchema: z.ZodObject<{
111
114
  fiveHour: z.ZodObject<{
@@ -120,9 +123,9 @@ export declare const providerQuotaStateSchema: z.ZodObject<{
120
123
  error: z.ZodOptional<z.ZodString>;
121
124
  failureKind: z.ZodOptional<z.ZodEnum<{
122
125
  unknown: "unknown";
123
- rate_limit: "rate_limit";
124
126
  auth: "auth";
125
127
  network: "network";
128
+ rate_limit: "rate_limit";
126
129
  server: "server";
127
130
  }>>;
128
131
  httpStatus: z.ZodOptional<z.ZodNumber>;
@@ -132,10 +135,11 @@ export declare const providerQuotaStateSchema: z.ZodObject<{
132
135
  providerId: z.ZodOptional<z.ZodEnum<{
133
136
  "claude-code": "claude-code";
134
137
  codex: "codex";
138
+ zai: "zai";
135
139
  }>>;
136
140
  source: z.ZodOptional<z.ZodEnum<{
137
- session: "session";
138
141
  api: "api";
142
+ session: "session";
139
143
  cache: "cache";
140
144
  }>>;
141
145
  capturedAt: z.ZodOptional<z.ZodString>;
@@ -173,8 +177,8 @@ export declare const providerQuotaStateSchema: z.ZodObject<{
173
177
  failure: z.ZodOptional<z.ZodNullable<z.ZodObject<{
174
178
  severity: z.ZodEnum<{
175
179
  error: "error";
176
- info: "info";
177
180
  warning: "warning";
181
+ info: "info";
178
182
  }>;
179
183
  title: z.ZodString;
180
184
  message: z.ZodString;
@@ -185,6 +189,7 @@ export declare const providerQuotaStateSchema: z.ZodObject<{
185
189
  runtimeProvider: z.ZodEnum<{
186
190
  codex: "codex";
187
191
  claude: "claude";
192
+ zai: "zai";
188
193
  }>;
189
194
  }, z.core.$strip>;
190
195
  export declare const claudeProviderQuotaStateSchema: z.ZodObject<{
@@ -200,9 +205,9 @@ export declare const claudeProviderQuotaStateSchema: z.ZodObject<{
200
205
  error: z.ZodOptional<z.ZodString>;
201
206
  failureKind: z.ZodOptional<z.ZodEnum<{
202
207
  unknown: "unknown";
203
- rate_limit: "rate_limit";
204
208
  auth: "auth";
205
209
  network: "network";
210
+ rate_limit: "rate_limit";
206
211
  server: "server";
207
212
  }>>;
208
213
  httpStatus: z.ZodOptional<z.ZodNumber>;
@@ -212,10 +217,11 @@ export declare const claudeProviderQuotaStateSchema: z.ZodObject<{
212
217
  providerId: z.ZodOptional<z.ZodEnum<{
213
218
  "claude-code": "claude-code";
214
219
  codex: "codex";
220
+ zai: "zai";
215
221
  }>>;
216
222
  source: z.ZodOptional<z.ZodEnum<{
217
- session: "session";
218
223
  api: "api";
224
+ session: "session";
219
225
  cache: "cache";
220
226
  }>>;
221
227
  capturedAt: z.ZodOptional<z.ZodString>;
@@ -253,8 +259,8 @@ export declare const claudeProviderQuotaStateSchema: z.ZodObject<{
253
259
  failure: z.ZodOptional<z.ZodNullable<z.ZodObject<{
254
260
  severity: z.ZodEnum<{
255
261
  error: "error";
256
- info: "info";
257
262
  warning: "warning";
263
+ info: "info";
258
264
  }>;
259
265
  title: z.ZodString;
260
266
  message: z.ZodString;
@@ -277,9 +283,9 @@ export declare const codexProviderQuotaStateSchema: z.ZodObject<{
277
283
  error: z.ZodOptional<z.ZodString>;
278
284
  failureKind: z.ZodOptional<z.ZodEnum<{
279
285
  unknown: "unknown";
280
- rate_limit: "rate_limit";
281
286
  auth: "auth";
282
287
  network: "network";
288
+ rate_limit: "rate_limit";
283
289
  server: "server";
284
290
  }>>;
285
291
  httpStatus: z.ZodOptional<z.ZodNumber>;
@@ -289,10 +295,11 @@ export declare const codexProviderQuotaStateSchema: z.ZodObject<{
289
295
  providerId: z.ZodOptional<z.ZodEnum<{
290
296
  "claude-code": "claude-code";
291
297
  codex: "codex";
298
+ zai: "zai";
292
299
  }>>;
293
300
  source: z.ZodOptional<z.ZodEnum<{
294
- session: "session";
295
301
  api: "api";
302
+ session: "session";
296
303
  cache: "cache";
297
304
  }>>;
298
305
  capturedAt: z.ZodOptional<z.ZodString>;
@@ -330,8 +337,8 @@ export declare const codexProviderQuotaStateSchema: z.ZodObject<{
330
337
  failure: z.ZodOptional<z.ZodNullable<z.ZodObject<{
331
338
  severity: z.ZodEnum<{
332
339
  error: "error";
333
- info: "info";
334
340
  warning: "warning";
341
+ info: "info";
335
342
  }>;
336
343
  title: z.ZodString;
337
344
  message: z.ZodString;
@@ -341,6 +348,84 @@ export declare const codexProviderQuotaStateSchema: z.ZodObject<{
341
348
  }, z.core.$strip>>>;
342
349
  runtimeProvider: z.ZodLiteral<"codex">;
343
350
  }, z.core.$strip>;
351
+ export declare const zaiProviderQuotaStateSchema: z.ZodObject<{
352
+ fiveHour: z.ZodObject<{
353
+ utilization: z.ZodNumber;
354
+ resetsAt: z.ZodString;
355
+ }, z.core.$strip>;
356
+ sevenDay: z.ZodObject<{
357
+ utilization: z.ZodNumber;
358
+ resetsAt: z.ZodString;
359
+ }, z.core.$strip>;
360
+ available: z.ZodBoolean;
361
+ error: z.ZodOptional<z.ZodString>;
362
+ failureKind: z.ZodOptional<z.ZodEnum<{
363
+ unknown: "unknown";
364
+ auth: "auth";
365
+ network: "network";
366
+ rate_limit: "rate_limit";
367
+ server: "server";
368
+ }>>;
369
+ httpStatus: z.ZodOptional<z.ZodNumber>;
370
+ retryAfterMs: z.ZodOptional<z.ZodNumber>;
371
+ projectedFiveHour: z.ZodOptional<z.ZodNumber>;
372
+ projectedSevenDay: z.ZodOptional<z.ZodNumber>;
373
+ providerId: z.ZodOptional<z.ZodEnum<{
374
+ "claude-code": "claude-code";
375
+ codex: "codex";
376
+ zai: "zai";
377
+ }>>;
378
+ source: z.ZodOptional<z.ZodEnum<{
379
+ api: "api";
380
+ session: "session";
381
+ cache: "cache";
382
+ }>>;
383
+ capturedAt: z.ZodOptional<z.ZodString>;
384
+ stale: z.ZodOptional<z.ZodBoolean>;
385
+ fiveHourLabel: z.ZodOptional<z.ZodString>;
386
+ sevenDayLabel: z.ZodOptional<z.ZodString>;
387
+ limitId: z.ZodOptional<z.ZodString>;
388
+ limitName: z.ZodOptional<z.ZodString>;
389
+ credits: z.ZodOptional<z.ZodUnknown>;
390
+ planType: z.ZodOptional<z.ZodString>;
391
+ rateLimitReachedType: z.ZodOptional<z.ZodString>;
392
+ accountLabel: z.ZodOptional<z.ZodString>;
393
+ accountDetail: z.ZodOptional<z.ZodString>;
394
+ peakHours: z.ZodOptional<z.ZodNullable<z.ZodObject<{
395
+ status: z.ZodEnum<{
396
+ unknown: "unknown";
397
+ peak: "peak";
398
+ off_peak: "off_peak";
399
+ }>;
400
+ isPeak: z.ZodBoolean;
401
+ sessionLimitSpeed: z.ZodEnum<{
402
+ unknown: "unknown";
403
+ normal: "normal";
404
+ faster: "faster";
405
+ }>;
406
+ label: z.ZodString;
407
+ peakHoursDescription: z.ZodString;
408
+ nextChange: z.ZodNullable<z.ZodString>;
409
+ minutesUntilChange: z.ZodNullable<z.ZodNumber>;
410
+ note: z.ZodString;
411
+ updatedAt: z.ZodString;
412
+ unavailable: z.ZodBoolean;
413
+ notApplicable: z.ZodOptional<z.ZodBoolean>;
414
+ }, z.core.$strip>>>;
415
+ failure: z.ZodOptional<z.ZodNullable<z.ZodObject<{
416
+ severity: z.ZodEnum<{
417
+ error: "error";
418
+ warning: "warning";
419
+ info: "info";
420
+ }>;
421
+ title: z.ZodString;
422
+ message: z.ZodString;
423
+ detail: z.ZodOptional<z.ZodString>;
424
+ alertKey: z.ZodString;
425
+ isRetryable: z.ZodBoolean;
426
+ }, z.core.$strip>>>;
427
+ runtimeProvider: z.ZodLiteral<"zai">;
428
+ }, z.core.$strip>;
344
429
  export declare const providerQuotaMapSchema: z.ZodObject<{
345
430
  claude: z.ZodOptional<z.ZodObject<{
346
431
  fiveHour: z.ZodObject<{
@@ -355,9 +440,9 @@ export declare const providerQuotaMapSchema: z.ZodObject<{
355
440
  error: z.ZodOptional<z.ZodString>;
356
441
  failureKind: z.ZodOptional<z.ZodEnum<{
357
442
  unknown: "unknown";
358
- rate_limit: "rate_limit";
359
443
  auth: "auth";
360
444
  network: "network";
445
+ rate_limit: "rate_limit";
361
446
  server: "server";
362
447
  }>>;
363
448
  httpStatus: z.ZodOptional<z.ZodNumber>;
@@ -367,10 +452,11 @@ export declare const providerQuotaMapSchema: z.ZodObject<{
367
452
  providerId: z.ZodOptional<z.ZodEnum<{
368
453
  "claude-code": "claude-code";
369
454
  codex: "codex";
455
+ zai: "zai";
370
456
  }>>;
371
457
  source: z.ZodOptional<z.ZodEnum<{
372
- session: "session";
373
458
  api: "api";
459
+ session: "session";
374
460
  cache: "cache";
375
461
  }>>;
376
462
  capturedAt: z.ZodOptional<z.ZodString>;
@@ -408,8 +494,8 @@ export declare const providerQuotaMapSchema: z.ZodObject<{
408
494
  failure: z.ZodOptional<z.ZodNullable<z.ZodObject<{
409
495
  severity: z.ZodEnum<{
410
496
  error: "error";
411
- info: "info";
412
497
  warning: "warning";
498
+ info: "info";
413
499
  }>;
414
500
  title: z.ZodString;
415
501
  message: z.ZodString;
@@ -432,9 +518,9 @@ export declare const providerQuotaMapSchema: z.ZodObject<{
432
518
  error: z.ZodOptional<z.ZodString>;
433
519
  failureKind: z.ZodOptional<z.ZodEnum<{
434
520
  unknown: "unknown";
435
- rate_limit: "rate_limit";
436
521
  auth: "auth";
437
522
  network: "network";
523
+ rate_limit: "rate_limit";
438
524
  server: "server";
439
525
  }>>;
440
526
  httpStatus: z.ZodOptional<z.ZodNumber>;
@@ -444,10 +530,11 @@ export declare const providerQuotaMapSchema: z.ZodObject<{
444
530
  providerId: z.ZodOptional<z.ZodEnum<{
445
531
  "claude-code": "claude-code";
446
532
  codex: "codex";
533
+ zai: "zai";
447
534
  }>>;
448
535
  source: z.ZodOptional<z.ZodEnum<{
449
- session: "session";
450
536
  api: "api";
537
+ session: "session";
451
538
  cache: "cache";
452
539
  }>>;
453
540
  capturedAt: z.ZodOptional<z.ZodString>;
@@ -485,8 +572,8 @@ export declare const providerQuotaMapSchema: z.ZodObject<{
485
572
  failure: z.ZodOptional<z.ZodNullable<z.ZodObject<{
486
573
  severity: z.ZodEnum<{
487
574
  error: "error";
488
- info: "info";
489
575
  warning: "warning";
576
+ info: "info";
490
577
  }>;
491
578
  title: z.ZodString;
492
579
  message: z.ZodString;
@@ -496,4 +583,82 @@ export declare const providerQuotaMapSchema: z.ZodObject<{
496
583
  }, z.core.$strip>>>;
497
584
  runtimeProvider: z.ZodLiteral<"codex">;
498
585
  }, z.core.$strip>>;
586
+ zai: z.ZodOptional<z.ZodObject<{
587
+ fiveHour: z.ZodObject<{
588
+ utilization: z.ZodNumber;
589
+ resetsAt: z.ZodString;
590
+ }, z.core.$strip>;
591
+ sevenDay: z.ZodObject<{
592
+ utilization: z.ZodNumber;
593
+ resetsAt: z.ZodString;
594
+ }, z.core.$strip>;
595
+ available: z.ZodBoolean;
596
+ error: z.ZodOptional<z.ZodString>;
597
+ failureKind: z.ZodOptional<z.ZodEnum<{
598
+ unknown: "unknown";
599
+ auth: "auth";
600
+ network: "network";
601
+ rate_limit: "rate_limit";
602
+ server: "server";
603
+ }>>;
604
+ httpStatus: z.ZodOptional<z.ZodNumber>;
605
+ retryAfterMs: z.ZodOptional<z.ZodNumber>;
606
+ projectedFiveHour: z.ZodOptional<z.ZodNumber>;
607
+ projectedSevenDay: z.ZodOptional<z.ZodNumber>;
608
+ providerId: z.ZodOptional<z.ZodEnum<{
609
+ "claude-code": "claude-code";
610
+ codex: "codex";
611
+ zai: "zai";
612
+ }>>;
613
+ source: z.ZodOptional<z.ZodEnum<{
614
+ api: "api";
615
+ session: "session";
616
+ cache: "cache";
617
+ }>>;
618
+ capturedAt: z.ZodOptional<z.ZodString>;
619
+ stale: z.ZodOptional<z.ZodBoolean>;
620
+ fiveHourLabel: z.ZodOptional<z.ZodString>;
621
+ sevenDayLabel: z.ZodOptional<z.ZodString>;
622
+ limitId: z.ZodOptional<z.ZodString>;
623
+ limitName: z.ZodOptional<z.ZodString>;
624
+ credits: z.ZodOptional<z.ZodUnknown>;
625
+ planType: z.ZodOptional<z.ZodString>;
626
+ rateLimitReachedType: z.ZodOptional<z.ZodString>;
627
+ accountLabel: z.ZodOptional<z.ZodString>;
628
+ accountDetail: z.ZodOptional<z.ZodString>;
629
+ peakHours: z.ZodOptional<z.ZodNullable<z.ZodObject<{
630
+ status: z.ZodEnum<{
631
+ unknown: "unknown";
632
+ peak: "peak";
633
+ off_peak: "off_peak";
634
+ }>;
635
+ isPeak: z.ZodBoolean;
636
+ sessionLimitSpeed: z.ZodEnum<{
637
+ unknown: "unknown";
638
+ normal: "normal";
639
+ faster: "faster";
640
+ }>;
641
+ label: z.ZodString;
642
+ peakHoursDescription: z.ZodString;
643
+ nextChange: z.ZodNullable<z.ZodString>;
644
+ minutesUntilChange: z.ZodNullable<z.ZodNumber>;
645
+ note: z.ZodString;
646
+ updatedAt: z.ZodString;
647
+ unavailable: z.ZodBoolean;
648
+ notApplicable: z.ZodOptional<z.ZodBoolean>;
649
+ }, z.core.$strip>>>;
650
+ failure: z.ZodOptional<z.ZodNullable<z.ZodObject<{
651
+ severity: z.ZodEnum<{
652
+ error: "error";
653
+ warning: "warning";
654
+ info: "info";
655
+ }>;
656
+ title: z.ZodString;
657
+ message: z.ZodString;
658
+ detail: z.ZodOptional<z.ZodString>;
659
+ alertKey: z.ZodString;
660
+ isRetryable: z.ZodBoolean;
661
+ }, z.core.$strip>>>;
662
+ runtimeProvider: z.ZodLiteral<"zai">;
663
+ }, z.core.$strip>>;
499
664
  }, z.core.$strip>;
@@ -10,7 +10,7 @@
10
10
  * @module schemas/quota
11
11
  */
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.providerQuotaMapSchema = exports.codexProviderQuotaStateSchema = exports.claudeProviderQuotaStateSchema = exports.providerQuotaStateSchema = exports.runtimeQuotaProviderSchema = exports.quotaFailureDescriptorSchema = exports.peakHoursStateSchema = exports.quotaStateSchema = exports.quotaSourceSchema = exports.quotaProviderIdSchema = exports.quotaFailureKindSchema = exports.quotaWindowSchema = void 0;
13
+ exports.providerQuotaMapSchema = exports.zaiProviderQuotaStateSchema = exports.codexProviderQuotaStateSchema = exports.claudeProviderQuotaStateSchema = exports.providerQuotaStateSchema = exports.runtimeQuotaProviderSchema = exports.quotaFailureDescriptorSchema = exports.peakHoursStateSchema = exports.quotaStateSchema = exports.quotaSourceSchema = exports.quotaProviderIdSchema = exports.quotaFailureKindSchema = exports.quotaWindowSchema = void 0;
14
14
  const zod_1 = require("zod");
15
15
  // ── QuotaWindow ──
16
16
  exports.quotaWindowSchema = zod_1.z.object({
@@ -28,6 +28,7 @@ exports.quotaFailureKindSchema = zod_1.z.enum([
28
28
  exports.quotaProviderIdSchema = zod_1.z.enum([
29
29
  'claude-code',
30
30
  'codex',
31
+ 'zai',
31
32
  ]);
32
33
  exports.quotaSourceSchema = zod_1.z.enum([
33
34
  'api',
@@ -83,6 +84,7 @@ exports.quotaFailureDescriptorSchema = zod_1.z.object({
83
84
  exports.runtimeQuotaProviderSchema = zod_1.z.enum([
84
85
  'claude',
85
86
  'codex',
87
+ 'zai',
86
88
  ]);
87
89
  /** Fields ProviderQuotaState adds on top of QuotaState, minus the provider tag. */
88
90
  const providerQuotaExtensionShape = {
@@ -103,7 +105,12 @@ exports.codexProviderQuotaStateSchema = exports.quotaStateSchema.extend({
103
105
  runtimeProvider: zod_1.z.literal('codex'),
104
106
  ...providerQuotaExtensionShape,
105
107
  });
108
+ exports.zaiProviderQuotaStateSchema = exports.quotaStateSchema.extend({
109
+ runtimeProvider: zod_1.z.literal('zai'),
110
+ ...providerQuotaExtensionShape,
111
+ });
106
112
  exports.providerQuotaMapSchema = zod_1.z.object({
107
113
  claude: exports.claudeProviderQuotaStateSchema.optional(),
108
114
  codex: exports.codexProviderQuotaStateSchema.optional(),
115
+ zai: exports.zaiProviderQuotaStateSchema.optional(),
109
116
  });
@@ -12,12 +12,14 @@ import { z } from 'zod';
12
12
  export declare const quotaHistoryRuntimeProviderSchema: z.ZodEnum<{
13
13
  codex: "codex";
14
14
  claude: "claude";
15
+ zai: "zai";
15
16
  }>;
16
17
  export declare const quotaHistorySampleSchema: z.ZodObject<{
17
18
  timestamp: z.ZodString;
18
19
  runtimeProvider: z.ZodEnum<{
19
20
  codex: "codex";
20
21
  claude: "claude";
22
+ zai: "zai";
21
23
  }>;
22
24
  providerId: z.ZodString;
23
25
  workspaceId: z.ZodString;
@@ -32,8 +34,8 @@ export declare const quotaHistorySampleSchema: z.ZodObject<{
32
34
  available: z.ZodBoolean;
33
35
  error: z.ZodOptional<z.ZodString>;
34
36
  source: z.ZodOptional<z.ZodEnum<{
35
- session: "session";
36
37
  api: "api";
38
+ session: "session";
37
39
  cache: "cache";
38
40
  }>>;
39
41
  stale: z.ZodOptional<z.ZodBoolean>;
@@ -16,6 +16,7 @@ const zod_1 = require("zod");
16
16
  exports.quotaHistoryRuntimeProviderSchema = zod_1.z.enum([
17
17
  'claude',
18
18
  'codex',
19
+ 'zai',
19
20
  ]);
20
21
  // ── QuotaHistorySample ──
21
22
  exports.quotaHistorySampleSchema = zod_1.z.object({
@@ -0,0 +1,7 @@
1
+ import { type AccountProviderId } from './accountRegistry';
2
+ export declare function setTerminalActiveProfile(provider: AccountProviderId, home: string | null): void;
3
+ export declare function installShellHook(): void;
4
+ export declare function uninstallShellHook(): void;
5
+ export declare function isShellHookInstalled(): boolean;
6
+ export declare function writeLauncher(name: string, provider: AccountProviderId, profileHome: string): void;
7
+ export declare function removeLauncher(name: string): void;
@@ -0,0 +1,202 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.setTerminalActiveProfile = setTerminalActiveProfile;
37
+ exports.installShellHook = installShellHook;
38
+ exports.uninstallShellHook = uninstallShellHook;
39
+ exports.isShellHookInstalled = isShellHookInstalled;
40
+ exports.writeLauncher = writeLauncher;
41
+ exports.removeLauncher = removeLauncher;
42
+ const fs = __importStar(require("fs"));
43
+ const os = __importStar(require("os"));
44
+ const path = __importStar(require("path"));
45
+ const accountRegistry_1 = require("./accountRegistry");
46
+ const HOOK_START = '# >>> sidekick >>>';
47
+ const HOOK_END = '# <<< sidekick <<<';
48
+ const LAUNCHER_MARKER = '# sidekick-launcher v1';
49
+ const LAUNCHER_NAME_PATTERN = /^[a-zA-Z0-9_-]+$/;
50
+ function providerPointerName(provider) {
51
+ return provider === 'claude-code' ? 'claude' : 'codex';
52
+ }
53
+ function providerEnvVar(provider) {
54
+ return provider === 'claude-code' ? 'CLAUDE_CONFIG_DIR' : 'CODEX_HOME';
55
+ }
56
+ function providerBinary(provider) {
57
+ return provider === 'claude-code' ? 'claude' : 'codex';
58
+ }
59
+ function getActiveProfilesDir() {
60
+ return path.join((0, accountRegistry_1.getAccountsDir)(), 'active');
61
+ }
62
+ function getActiveProfilePath(provider) {
63
+ return path.join(getActiveProfilesDir(), `${providerPointerName(provider)}.profile`);
64
+ }
65
+ function atomicWriteFile(filePath, content, mode = 0o600) {
66
+ fs.mkdirSync(path.dirname(filePath), { recursive: true, mode: 0o700 });
67
+ const tmp = `${filePath}.tmp`;
68
+ try {
69
+ fs.writeFileSync(tmp, content, { encoding: 'utf8', mode });
70
+ fs.renameSync(tmp, filePath);
71
+ }
72
+ catch (err) {
73
+ try {
74
+ fs.rmSync(tmp, { force: true });
75
+ }
76
+ catch { /* nothing to clean up */ }
77
+ throw err;
78
+ }
79
+ }
80
+ function setTerminalActiveProfile(provider, home) {
81
+ const pointerPath = getActiveProfilePath(provider);
82
+ if (home === null) {
83
+ fs.rmSync(pointerPath, { force: true });
84
+ return;
85
+ }
86
+ atomicWriteFile(pointerPath, `${home}\n`);
87
+ }
88
+ function shellQuote(value) {
89
+ return `'${value.replace(/'/g, `'\\''`)}'`;
90
+ }
91
+ function buildShellHookBlock() {
92
+ const claudePointer = getActiveProfilePath('claude-code');
93
+ const codexPointer = getActiveProfilePath('codex');
94
+ return [
95
+ HOOK_START,
96
+ 'sidekick_sync() {',
97
+ ` if [ -r ${shellQuote(claudePointer)} ]; then export CLAUDE_CONFIG_DIR="$(cat ${shellQuote(claudePointer)})"; else unset CLAUDE_CONFIG_DIR; fi`,
98
+ ` if [ -r ${shellQuote(codexPointer)} ]; then export CODEX_HOME="$(cat ${shellQuote(codexPointer)})"; else unset CODEX_HOME; fi`,
99
+ '}',
100
+ 'sidekick_sync >/dev/null 2>&1',
101
+ HOOK_END,
102
+ '',
103
+ ].join('\n');
104
+ }
105
+ function getShellRcPaths() {
106
+ const zshrc = path.join(os.homedir(), '.zshrc');
107
+ const bashrc = path.join(os.homedir(), '.bashrc');
108
+ const paths = [zshrc];
109
+ if (fs.existsSync(bashrc))
110
+ paths.push(bashrc);
111
+ return paths;
112
+ }
113
+ function stripShellHook(content) {
114
+ const pattern = new RegExp(`${HOOK_START}[\\s\\S]*?${HOOK_END}\\n?`, 'g');
115
+ return content.replace(pattern, '').replace(/\n{3,}/g, '\n\n');
116
+ }
117
+ function installHookInFile(filePath) {
118
+ const existing = fs.existsSync(filePath) ? fs.readFileSync(filePath, 'utf8') : '';
119
+ const cleaned = stripShellHook(existing).replace(/\s*$/, '');
120
+ const next = cleaned ? `${cleaned}\n\n${buildShellHookBlock()}` : buildShellHookBlock();
121
+ atomicWriteFile(filePath, next, 0o600);
122
+ }
123
+ function installShellHook() {
124
+ for (const rcPath of getShellRcPaths()) {
125
+ installHookInFile(rcPath);
126
+ }
127
+ }
128
+ function uninstallHookInFile(filePath) {
129
+ if (!fs.existsSync(filePath))
130
+ return;
131
+ atomicWriteFile(filePath, stripShellHook(fs.readFileSync(filePath, 'utf8')), 0o600);
132
+ }
133
+ function uninstallShellHook() {
134
+ for (const rcPath of getShellRcPaths()) {
135
+ uninstallHookInFile(rcPath);
136
+ }
137
+ }
138
+ function isShellHookInstalled() {
139
+ return getShellRcPaths().some(rcPath => {
140
+ try {
141
+ const content = fs.readFileSync(rcPath, 'utf8');
142
+ return content.includes(HOOK_START) && content.includes(HOOK_END);
143
+ }
144
+ catch {
145
+ return false;
146
+ }
147
+ });
148
+ }
149
+ function getLauncherDir() {
150
+ return path.join(os.homedir(), '.local', 'bin');
151
+ }
152
+ function getLauncherPath(name) {
153
+ return path.join(getLauncherDir(), name);
154
+ }
155
+ function assertValidLauncherName(name) {
156
+ if (!LAUNCHER_NAME_PATTERN.test(name)) {
157
+ throw new Error(`Invalid launcher name "${name}". Use letters, numbers, underscores, and hyphens only.`);
158
+ }
159
+ }
160
+ function isSidekickLauncher(filePath) {
161
+ try {
162
+ return fs.readFileSync(filePath, 'utf8').includes(LAUNCHER_MARKER);
163
+ }
164
+ catch {
165
+ return false;
166
+ }
167
+ }
168
+ function assertNoLauncherCollision(name, targetPath) {
169
+ if (fs.existsSync(targetPath) && !isSidekickLauncher(targetPath)) {
170
+ throw new Error(`Launcher "${name}" already exists and is not managed by sidekick.`);
171
+ }
172
+ for (const dir of (process.env.PATH ?? '').split(path.delimiter).filter(Boolean)) {
173
+ const candidate = path.join(dir, name);
174
+ if (path.resolve(candidate) === path.resolve(targetPath))
175
+ continue;
176
+ if (fs.existsSync(candidate)) {
177
+ throw new Error(`Launcher "${name}" collides with an existing command on PATH.`);
178
+ }
179
+ }
180
+ }
181
+ function writeLauncher(name, provider, profileHome) {
182
+ assertValidLauncherName(name);
183
+ const launcherPath = getLauncherPath(name);
184
+ assertNoLauncherCollision(name, launcherPath);
185
+ const envVar = providerEnvVar(provider);
186
+ const binary = providerBinary(provider);
187
+ const script = [
188
+ '#!/bin/sh',
189
+ LAUNCHER_MARKER,
190
+ `export ${envVar}=${JSON.stringify(profileHome)}`,
191
+ `exec ${binary} "$@"`,
192
+ '',
193
+ ].join('\n');
194
+ atomicWriteFile(launcherPath, script, 0o755);
195
+ }
196
+ function removeLauncher(name) {
197
+ assertValidLauncherName(name);
198
+ const launcherPath = getLauncherPath(name);
199
+ if (!isSidekickLauncher(launcherPath))
200
+ return;
201
+ fs.rmSync(launcherPath, { force: true });
202
+ }