@ktkid/kmh-codex-cli 0.0.0-stage → 0.1.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 (87) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +295 -2
  3. package/bin/README.md +25 -0
  4. package/bin/codex +36 -0
  5. package/bin/runtime-receipt.json +9 -0
  6. package/bin/version +1 -0
  7. package/cordis.patch.yml +7 -0
  8. package/lib/browser-types/src/account-status.d.ts +9 -0
  9. package/lib/browser-types/src/client/ComposerQuota.d.ts +10 -0
  10. package/lib/browser-types/src/client/DetailCard.d.ts +12 -0
  11. package/lib/browser-types/src/client/LiveBall.d.ts +19 -0
  12. package/lib/browser-types/src/client/QuotaCard.d.ts +20 -0
  13. package/lib/browser-types/src/client/QuotaDisplaySettings.d.ts +6 -0
  14. package/lib/browser-types/src/client/index.d.ts +18 -0
  15. package/lib/browser-types/src/client/locales.d.ts +54 -0
  16. package/lib/browser-types/src/client/quota-store.d.ts +56 -0
  17. package/lib/browser-types/src/live-state.d.ts +31 -0
  18. package/lib/browser-types/src/quota-protocol.d.ts +135 -0
  19. package/lib/browser-types/src/quota-rules.d.ts +18 -0
  20. package/lib/browser-types/src/tool-switches.d.ts +63 -0
  21. package/lib/client.js +21396 -0
  22. package/lib/src/account-status.d.ts +9 -0
  23. package/lib/src/account-status.js +1 -0
  24. package/lib/src/account.d.ts +35 -0
  25. package/lib/src/account.js +173 -0
  26. package/lib/src/adapter.d.ts +22 -0
  27. package/lib/src/adapter.js +221 -0
  28. package/lib/src/approval.d.ts +48 -0
  29. package/lib/src/approval.js +235 -0
  30. package/lib/src/capabilities.d.ts +40 -0
  31. package/lib/src/capabilities.js +85 -0
  32. package/lib/src/config.d.ts +69 -0
  33. package/lib/src/config.js +75 -0
  34. package/lib/src/connection.d.ts +65 -0
  35. package/lib/src/connection.js +178 -0
  36. package/lib/src/cursor.d.ts +54 -0
  37. package/lib/src/cursor.js +325 -0
  38. package/lib/src/image-delivery.d.ts +36 -0
  39. package/lib/src/image-delivery.js +65 -0
  40. package/lib/src/imagegen.d.ts +21 -0
  41. package/lib/src/imagegen.js +132 -0
  42. package/lib/src/index.d.ts +141 -0
  43. package/lib/src/index.js +534 -0
  44. package/lib/src/isolation.d.ts +61 -0
  45. package/lib/src/isolation.js +298 -0
  46. package/lib/src/live-state.d.ts +31 -0
  47. package/lib/src/live-state.js +14 -0
  48. package/lib/src/models.d.ts +24 -0
  49. package/lib/src/models.js +98 -0
  50. package/lib/src/native-items.d.ts +59 -0
  51. package/lib/src/native-items.js +122 -0
  52. package/lib/src/native-tools/catalog.d.ts +29 -0
  53. package/lib/src/native-tools/catalog.js +197 -0
  54. package/lib/src/probe.d.ts +17 -0
  55. package/lib/src/probe.js +54 -0
  56. package/lib/src/protocol.d.ts +508 -0
  57. package/lib/src/protocol.js +511 -0
  58. package/lib/src/quota-protocol.d.ts +135 -0
  59. package/lib/src/quota-protocol.js +97 -0
  60. package/lib/src/quota-rules.d.ts +18 -0
  61. package/lib/src/quota-rules.js +49 -0
  62. package/lib/src/quota.d.ts +32 -0
  63. package/lib/src/quota.js +227 -0
  64. package/lib/src/session-store.d.ts +592 -0
  65. package/lib/src/session-store.js +275 -0
  66. package/lib/src/status.d.ts +19 -0
  67. package/lib/src/status.js +69 -0
  68. package/lib/src/tool-policy.d.ts +47 -0
  69. package/lib/src/tool-policy.js +454 -0
  70. package/lib/src/tool-registry.d.ts +42 -0
  71. package/lib/src/tool-registry.js +70 -0
  72. package/lib/src/tool-selection.d.ts +88 -0
  73. package/lib/src/tool-selection.js +60 -0
  74. package/lib/src/tool-switches-service.d.ts +24 -0
  75. package/lib/src/tool-switches-service.js +129 -0
  76. package/lib/src/tool-switches.d.ts +63 -0
  77. package/lib/src/tool-switches.js +43 -0
  78. package/lib/src/turn.d.ts +200 -0
  79. package/lib/src/turn.js +1012 -0
  80. package/lib/src/web.d.ts +9 -0
  81. package/lib/src/web.js +143 -0
  82. package/package.json +171 -4
  83. package/vendor/codex/LICENSE +201 -0
  84. package/vendor/codex/NOTICE +4 -0
  85. package/vendor/codex/models.json +1613 -0
  86. package/vendor/native-tools/0.162.0-alpha.17.2.json +143 -0
  87. package/vendor/native-tools/0.163.0-alpha.10.2.json +128 -0
@@ -0,0 +1,31 @@
1
+ /** Host 与 Client 共用的会话连接状态响应。 */
2
+ import { z } from "zod";
3
+ /** CLI 连接状态;重试期间 streaming 保持 true。 */
4
+ export declare const SessionLiveState: z.ZodObject<{
5
+ color: z.ZodEnum<{
6
+ green: "green";
7
+ gray: "gray";
8
+ red: "red";
9
+ }>;
10
+ streaming: z.ZodBoolean;
11
+ retrying: z.ZodDefault<z.ZodBoolean>;
12
+ detail: z.ZodString;
13
+ updatedAt: z.ZodNumber;
14
+ }, z.core.$strip>;
15
+ /** 已校验的 CLI 连接状态。 */
16
+ export type SessionLiveState = z.infer<typeof SessionLiveState>;
17
+ /** /api/codex-cli/live 响应;旧 Host 缺少 retrying 时按空闲重试状态读取。 */
18
+ export declare const LiveSnapshot: z.ZodObject<{
19
+ sessions: z.ZodArray<z.ZodObject<{
20
+ color: z.ZodEnum<{
21
+ green: "green";
22
+ gray: "gray";
23
+ red: "red";
24
+ }>;
25
+ streaming: z.ZodBoolean;
26
+ retrying: z.ZodDefault<z.ZodBoolean>;
27
+ detail: z.ZodString;
28
+ updatedAt: z.ZodNumber;
29
+ sessionId: z.ZodString;
30
+ }, z.core.$strip>>;
31
+ }, z.core.$strip>;
@@ -0,0 +1,135 @@
1
+ /** 浏览器与宿主共用的只读额度协议;时间统一为毫秒。 */
2
+ import { z } from "zod";
3
+ /** 传输层校验字段类型,范围与默认值由宿主 Config 定义。 */
4
+ export declare const QuotaPreferences: z.ZodObject<{
5
+ quotaDisplayMode: z.ZodEnum<{
6
+ percent: "percent";
7
+ bar: "bar";
8
+ off: "off";
9
+ }>;
10
+ quotaAlertsEnabled: z.ZodBoolean;
11
+ quotaShortThresholdPercent: z.ZodNumber;
12
+ quotaWeeklyThresholdPercent: z.ZodNumber;
13
+ }, z.core.$strip>;
14
+ export type QuotaPreferences = z.infer<typeof QuotaPreferences>;
15
+ export declare const QuotaContext: z.ZodObject<{
16
+ settingsNamespace: z.ZodNullable<z.ZodString>;
17
+ preferences: z.ZodObject<{
18
+ quotaDisplayMode: z.ZodEnum<{
19
+ percent: "percent";
20
+ bar: "bar";
21
+ off: "off";
22
+ }>;
23
+ quotaAlertsEnabled: z.ZodBoolean;
24
+ quotaShortThresholdPercent: z.ZodNumber;
25
+ quotaWeeklyThresholdPercent: z.ZodNumber;
26
+ }, z.core.$strip>;
27
+ }, z.core.$strip>;
28
+ export declare const QuotaQuery: z.ZodObject<{
29
+ detail: z.ZodDefault<z.ZodEnum<{
30
+ summary: "summary";
31
+ full: "full";
32
+ }>>;
33
+ force: z.ZodDefault<z.ZodEnum<{
34
+ 0: "0";
35
+ 1: "1";
36
+ }>>;
37
+ }, z.core.$strict>;
38
+ export declare const QuotaWindow: z.ZodObject<{
39
+ usedPercent: z.ZodNumber;
40
+ remainingPercent: z.ZodNumber;
41
+ windowMinutes: z.ZodNullable<z.ZodNumber>;
42
+ resetsAtMs: z.ZodNullable<z.ZodNumber>;
43
+ }, z.core.$strip>;
44
+ export type QuotaWindow = z.infer<typeof QuotaWindow>;
45
+ export declare const QuotaGroup: z.ZodObject<{
46
+ id: z.ZodString;
47
+ name: z.ZodNullable<z.ZodString>;
48
+ windows: z.ZodArray<z.ZodObject<{
49
+ usedPercent: z.ZodNumber;
50
+ remainingPercent: z.ZodNumber;
51
+ windowMinutes: z.ZodNullable<z.ZodNumber>;
52
+ resetsAtMs: z.ZodNullable<z.ZodNumber>;
53
+ }, z.core.$strip>>;
54
+ }, z.core.$strip>;
55
+ export type QuotaGroup = z.infer<typeof QuotaGroup>;
56
+ export declare const QuotaError: z.ZodObject<{
57
+ area: z.ZodEnum<{
58
+ windows: "windows";
59
+ account: "account";
60
+ credits: "credits";
61
+ spend: "spend";
62
+ resets: "resets";
63
+ }>;
64
+ code: z.ZodEnum<{
65
+ "read-failed": "read-failed";
66
+ "invalid-data": "invalid-data";
67
+ unsupported: "unsupported";
68
+ }>;
69
+ message: z.ZodString;
70
+ }, z.core.$strip>;
71
+ export type QuotaError = z.infer<typeof QuotaError>;
72
+ export declare const QuotaView: z.ZodObject<{
73
+ accountEpoch: z.ZodNumber;
74
+ state: z.ZodEnum<{
75
+ error: "error";
76
+ unsupported: "unsupported";
77
+ loading: "loading";
78
+ ready: "ready";
79
+ "signed-out": "signed-out";
80
+ }>;
81
+ fetchedAtMs: z.ZodNullable<z.ZodNumber>;
82
+ nextRefreshAtMs: z.ZodNumber;
83
+ groups: z.ZodArray<z.ZodObject<{
84
+ id: z.ZodString;
85
+ name: z.ZodNullable<z.ZodString>;
86
+ windows: z.ZodArray<z.ZodObject<{
87
+ usedPercent: z.ZodNumber;
88
+ remainingPercent: z.ZodNumber;
89
+ windowMinutes: z.ZodNullable<z.ZodNumber>;
90
+ resetsAtMs: z.ZodNullable<z.ZodNumber>;
91
+ }, z.core.$strip>>;
92
+ }, z.core.$strip>>;
93
+ credits: z.ZodNullable<z.ZodObject<{
94
+ hasCredits: z.ZodBoolean;
95
+ unlimited: z.ZodBoolean;
96
+ balance: z.ZodNullable<z.ZodString>;
97
+ }, z.core.$strip>>;
98
+ creditsAtMs: z.ZodNullable<z.ZodNumber>;
99
+ spend: z.ZodNullable<z.ZodObject<{
100
+ limit: z.ZodString;
101
+ used: z.ZodString;
102
+ remainingPercent: z.ZodNumber;
103
+ resetsAtMs: z.ZodNumber;
104
+ }, z.core.$strip>>;
105
+ spendAtMs: z.ZodNullable<z.ZodNumber>;
106
+ resets: z.ZodNullable<z.ZodObject<{
107
+ availableCount: z.ZodNumber;
108
+ cards: z.ZodNullable<z.ZodArray<z.ZodObject<{
109
+ id: z.ZodString;
110
+ title: z.ZodNullable<z.ZodString>;
111
+ description: z.ZodNullable<z.ZodString>;
112
+ status: z.ZodString;
113
+ expiresAtMs: z.ZodNullable<z.ZodNumber>;
114
+ }, z.core.$strip>>>;
115
+ }, z.core.$strip>>;
116
+ resetsAtMs: z.ZodNullable<z.ZodNumber>;
117
+ errors: z.ZodArray<z.ZodObject<{
118
+ area: z.ZodEnum<{
119
+ windows: "windows";
120
+ account: "account";
121
+ credits: "credits";
122
+ spend: "spend";
123
+ resets: "resets";
124
+ }>;
125
+ code: z.ZodEnum<{
126
+ "read-failed": "read-failed";
127
+ "invalid-data": "invalid-data";
128
+ unsupported: "unsupported";
129
+ }>;
130
+ message: z.ZodString;
131
+ }, z.core.$strip>>;
132
+ }, z.core.$strip>;
133
+ export type QuotaView = z.infer<typeof QuotaView>;
134
+ /** 初始化或账号失效时清空所有区域,保留共享冷却时间。 */
135
+ export declare function emptyQuota(accountEpoch?: number, nextRefreshAtMs?: number): QuotaView;
@@ -0,0 +1,18 @@
1
+ /** 额度展示的纯规则;模型匹配依据参考插件 sidebar-quota.js 的精确、Spark、Reserve 规则。 */
2
+ import type { QuotaGroup, QuotaPreferences, QuotaWindow } from "./quota-protocol.ts";
3
+ export declare const QUOTA_MIN_INTERVAL_MS = 300000;
4
+ /** 覆盖响应头与正文读取,给宿主15秒中止和进程收尾保留余量。 */
5
+ export declare const QUOTA_HTTP_TIMEOUT_MS = 30000;
6
+ export declare const QUOTA_HTTP_TIMEOUT_ERROR = "QUOTA_HTTP_TIMEOUT";
7
+ export declare const QUOTA_REFRESH_INTERVAL_MS = 300000;
8
+ export declare const QUOTA_ERROR_BACKOFF_MS = 300000;
9
+ export declare const QUOTA_STALE_AFTER_MS = 300000;
10
+ export declare const QUOTA_DETAIL_CACHE_MS = 300000;
11
+ /** 已确认的周期分类;其他时长保留实际值。 */
12
+ export declare function windowKind(window: QuotaWindow): "short" | "weekly" | "other";
13
+ /** 仅新鲜且重置时间仍有效的结果可以触发颜色提醒。 */
14
+ export declare function windowFresh(window: QuotaWindow, at: number | null, now: number): boolean;
15
+ /** 阈值采用原始百分比严格小于比较,显示舍入保持独立。 */
16
+ export declare function windowLow(window: QuotaWindow, at: number | null, now: number, settings: QuotaPreferences | null): boolean;
17
+ /** 缺失独立额度组保留未知状态,普通模型共享 codex 主组。 */
18
+ export declare function modelQuota(groups: readonly QuotaGroup[], model: string): QuotaWindow[];
@@ -0,0 +1,63 @@
1
+ /**
2
+ * CLI 工具开关契约:详情页选择器与本插件之间共用的清单与切换载荷。
3
+ * 纯 zod 与推导类型,不依赖 node,可随客户端打包;类型只从 schema 推导。
4
+ */
5
+ import { z } from "zod";
6
+ /** 原生能力开关的固定身份;KMH 工具开关的 id 为 `kmh:<工具名>`。 */
7
+ export declare const NativeSwitchId: z.ZodEnum<{
8
+ "native:command-execution": "native:command-execution";
9
+ "native:file-change": "native:file-change";
10
+ "native:view-image": "native:view-image";
11
+ "native:web-search": "native:web-search";
12
+ }>;
13
+ export type NativeSwitchId = z.infer<typeof NativeSwitchId>;
14
+ /** 一个开关:KMH 工具一行,或原生能力一行。 */
15
+ export declare const ToolSwitchSchema: z.ZodObject<{
16
+ id: z.ZodString;
17
+ name: z.ZodString;
18
+ description: z.ZodString;
19
+ enabled: z.ZodBoolean;
20
+ covers: z.ZodArray<z.ZodString>;
21
+ }, z.core.$strip>;
22
+ export type ToolSwitch = z.infer<typeof ToolSwitchSchema>;
23
+ /** 原生目录核实状态:失败时携带原因,前端据此降级并提供重新读取。 */
24
+ export declare const NativeStatusSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
25
+ ok: z.ZodLiteral<true>;
26
+ }, z.core.$strip>, z.ZodObject<{
27
+ ok: z.ZodLiteral<false>;
28
+ reason: z.ZodString;
29
+ }, z.core.$strip>], "ok">;
30
+ export type NativeStatus = z.infer<typeof NativeStatusSchema>;
31
+ /** 详情页一次读取得到的完整清单。 */
32
+ export declare const ToolSwitchListSchema: z.ZodObject<{
33
+ target: z.ZodLiteral<"codex-cli">;
34
+ revision: z.ZodNumber;
35
+ kmh: z.ZodArray<z.ZodObject<{
36
+ id: z.ZodString;
37
+ name: z.ZodString;
38
+ description: z.ZodString;
39
+ enabled: z.ZodBoolean;
40
+ covers: z.ZodArray<z.ZodString>;
41
+ }, z.core.$strip>>;
42
+ native: z.ZodArray<z.ZodObject<{
43
+ id: z.ZodString;
44
+ name: z.ZodString;
45
+ description: z.ZodString;
46
+ enabled: z.ZodBoolean;
47
+ covers: z.ZodArray<z.ZodString>;
48
+ }, z.core.$strip>>;
49
+ nativeStatus: z.ZodDiscriminatedUnion<[z.ZodObject<{
50
+ ok: z.ZodLiteral<true>;
51
+ }, z.core.$strip>, z.ZodObject<{
52
+ ok: z.ZodLiteral<false>;
53
+ reason: z.ZodString;
54
+ }, z.core.$strip>], "ok">;
55
+ }, z.core.$strip>;
56
+ export type ToolSwitchList = z.infer<typeof ToolSwitchListSchema>;
57
+ /** 一次切换请求。 */
58
+ export declare const ToolSwitchUpdateSchema: z.ZodObject<{
59
+ id: z.ZodString;
60
+ enabled: z.ZodBoolean;
61
+ revision: z.ZodNumber;
62
+ }, z.core.$strip>;
63
+ export type ToolSwitchUpdate = z.infer<typeof ToolSwitchUpdateSchema>;