@itssimplereally/opencode-kimicode-auth 0.1.0

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 (115) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +87 -0
  3. package/dist/index.d.ts +4 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +3 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/src/constants.d.ts +69 -0
  8. package/dist/src/constants.d.ts.map +1 -0
  9. package/dist/src/constants.js +207 -0
  10. package/dist/src/constants.js.map +1 -0
  11. package/dist/src/kimi/oauth.d.ts +64 -0
  12. package/dist/src/kimi/oauth.d.ts.map +1 -0
  13. package/dist/src/kimi/oauth.js +130 -0
  14. package/dist/src/kimi/oauth.js.map +1 -0
  15. package/dist/src/plugin/accounts.d.ts +167 -0
  16. package/dist/src/plugin/accounts.d.ts.map +1 -0
  17. package/dist/src/plugin/accounts.js +843 -0
  18. package/dist/src/plugin/accounts.js.map +1 -0
  19. package/dist/src/plugin/auth.d.ts +13 -0
  20. package/dist/src/plugin/auth.d.ts.map +1 -0
  21. package/dist/src/plugin/auth.js +26 -0
  22. package/dist/src/plugin/auth.js.map +1 -0
  23. package/dist/src/plugin/cache.d.ts +14 -0
  24. package/dist/src/plugin/cache.d.ts.map +1 -0
  25. package/dist/src/plugin/cache.js +56 -0
  26. package/dist/src/plugin/cache.js.map +1 -0
  27. package/dist/src/plugin/cli.d.ts +21 -0
  28. package/dist/src/plugin/cli.d.ts.map +1 -0
  29. package/dist/src/plugin/cli.js +98 -0
  30. package/dist/src/plugin/cli.js.map +1 -0
  31. package/dist/src/plugin/config/index.d.ts +16 -0
  32. package/dist/src/plugin/config/index.d.ts.map +1 -0
  33. package/dist/src/plugin/config/index.js +16 -0
  34. package/dist/src/plugin/config/index.js.map +1 -0
  35. package/dist/src/plugin/config/loader.d.ts +36 -0
  36. package/dist/src/plugin/config/loader.d.ts.map +1 -0
  37. package/dist/src/plugin/config/loader.js +182 -0
  38. package/dist/src/plugin/config/loader.js.map +1 -0
  39. package/dist/src/plugin/config/models.d.ts +18 -0
  40. package/dist/src/plugin/config/models.d.ts.map +1 -0
  41. package/dist/src/plugin/config/models.js +26 -0
  42. package/dist/src/plugin/config/models.js.map +1 -0
  43. package/dist/src/plugin/config/schema.d.ts +107 -0
  44. package/dist/src/plugin/config/schema.d.ts.map +1 -0
  45. package/dist/src/plugin/config/schema.js +282 -0
  46. package/dist/src/plugin/config/schema.js.map +1 -0
  47. package/dist/src/plugin/config/updater.d.ts +55 -0
  48. package/dist/src/plugin/config/updater.d.ts.map +1 -0
  49. package/dist/src/plugin/config/updater.js +154 -0
  50. package/dist/src/plugin/config/updater.js.map +1 -0
  51. package/dist/src/plugin/debug.d.ts +92 -0
  52. package/dist/src/plugin/debug.d.ts.map +1 -0
  53. package/dist/src/plugin/debug.js +406 -0
  54. package/dist/src/plugin/debug.js.map +1 -0
  55. package/dist/src/plugin/errors.d.ts +28 -0
  56. package/dist/src/plugin/errors.d.ts.map +1 -0
  57. package/dist/src/plugin/errors.js +42 -0
  58. package/dist/src/plugin/errors.js.map +1 -0
  59. package/dist/src/plugin/fingerprint.d.ts +41 -0
  60. package/dist/src/plugin/fingerprint.d.ts.map +1 -0
  61. package/dist/src/plugin/fingerprint.js +94 -0
  62. package/dist/src/plugin/fingerprint.js.map +1 -0
  63. package/dist/src/plugin/logger.d.ts +54 -0
  64. package/dist/src/plugin/logger.d.ts.map +1 -0
  65. package/dist/src/plugin/logger.js +120 -0
  66. package/dist/src/plugin/logger.js.map +1 -0
  67. package/dist/src/plugin/recovery/constants.d.ts +26 -0
  68. package/dist/src/plugin/recovery/constants.d.ts.map +1 -0
  69. package/dist/src/plugin/recovery/constants.js +47 -0
  70. package/dist/src/plugin/recovery/constants.js.map +1 -0
  71. package/dist/src/plugin/recovery/index.d.ts +16 -0
  72. package/dist/src/plugin/recovery/index.d.ts.map +1 -0
  73. package/dist/src/plugin/recovery/index.js +16 -0
  74. package/dist/src/plugin/recovery/index.js.map +1 -0
  75. package/dist/src/plugin/recovery/storage.d.ts +24 -0
  76. package/dist/src/plugin/recovery/storage.d.ts.map +1 -0
  77. package/dist/src/plugin/recovery/storage.js +354 -0
  78. package/dist/src/plugin/recovery/storage.js.map +1 -0
  79. package/dist/src/plugin/recovery/types.d.ts +116 -0
  80. package/dist/src/plugin/recovery/types.d.ts.map +1 -0
  81. package/dist/src/plugin/recovery/types.js +6 -0
  82. package/dist/src/plugin/recovery/types.js.map +1 -0
  83. package/dist/src/plugin/recovery.d.ts +63 -0
  84. package/dist/src/plugin/recovery.d.ts.map +1 -0
  85. package/dist/src/plugin/recovery.js +331 -0
  86. package/dist/src/plugin/recovery.js.map +1 -0
  87. package/dist/src/plugin/refresh-queue.d.ts +101 -0
  88. package/dist/src/plugin/refresh-queue.d.ts.map +1 -0
  89. package/dist/src/plugin/refresh-queue.js +248 -0
  90. package/dist/src/plugin/refresh-queue.js.map +1 -0
  91. package/dist/src/plugin/rotation.d.ts +169 -0
  92. package/dist/src/plugin/rotation.d.ts.map +1 -0
  93. package/dist/src/plugin/rotation.js +328 -0
  94. package/dist/src/plugin/rotation.js.map +1 -0
  95. package/dist/src/plugin/storage.d.ts +90 -0
  96. package/dist/src/plugin/storage.d.ts.map +1 -0
  97. package/dist/src/plugin/storage.js +450 -0
  98. package/dist/src/plugin/storage.js.map +1 -0
  99. package/dist/src/plugin/token.d.ts +19 -0
  100. package/dist/src/plugin/token.d.ts.map +1 -0
  101. package/dist/src/plugin/token.js +112 -0
  102. package/dist/src/plugin/token.js.map +1 -0
  103. package/dist/src/plugin/types.d.ts +97 -0
  104. package/dist/src/plugin/types.d.ts.map +1 -0
  105. package/dist/src/plugin/types.js +1 -0
  106. package/dist/src/plugin/types.js.map +1 -0
  107. package/dist/src/plugin/version.d.ts +14 -0
  108. package/dist/src/plugin/version.d.ts.map +1 -0
  109. package/dist/src/plugin/version.js +20 -0
  110. package/dist/src/plugin/version.js.map +1 -0
  111. package/dist/src/plugin.d.ts +5 -0
  112. package/dist/src/plugin.d.ts.map +1 -0
  113. package/dist/src/plugin.js +1077 -0
  114. package/dist/src/plugin.js.map +1 -0
  115. package/package.json +55 -0
@@ -0,0 +1,26 @@
1
+ const TEXT_ONLY = {
2
+ input: ["text"],
3
+ output: ["text"],
4
+ };
5
+ const MULTIMODAL = {
6
+ input: ["text", "image"],
7
+ output: ["text"],
8
+ };
9
+ export const OPENCODE_MODEL_DEFINITIONS = {
10
+ // Kimi Code OAuth models are additive-only under the Moonshot provider.
11
+ // Prefix with "kimicode-" to keep them distinct from Moonshot API-key models.
12
+ //
13
+ // Two modes matching the kimi-cli / web GUI: thinking off and thinking on.
14
+ // kimi-cli default max_tokens is 32000; context reported by /models is 262144.
15
+ "kimicode-kimi-k2.5": {
16
+ name: "Kimi Code (K2.5)",
17
+ limit: { context: 262144, output: 32000 },
18
+ modalities: MULTIMODAL,
19
+ },
20
+ "kimicode-kimi-k2.5-thinking": {
21
+ name: "Kimi Code (K2.5) Thinking",
22
+ limit: { context: 262144, output: 32000 },
23
+ modalities: MULTIMODAL,
24
+ },
25
+ };
26
+ //# sourceMappingURL=models.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"models.js","sourceRoot":"","sources":["../../../../src/plugin/config/models.ts"],"names":[],"mappings":"AAsBA,MAAM,SAAS,GAAoB;IACjC,KAAK,EAAE,CAAC,MAAM,CAAC;IACf,MAAM,EAAE,CAAC,MAAM,CAAC;CACjB,CAAA;AAED,MAAM,UAAU,GAAoB;IAClC,KAAK,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC;IACxB,MAAM,EAAE,CAAC,MAAM,CAAC;CACjB,CAAA;AAED,MAAM,CAAC,MAAM,0BAA0B,GAA6B;IAClE,wEAAwE;IACxE,8EAA8E;IAC9E,EAAE;IACF,2EAA2E;IAC3E,+EAA+E;IAC/E,oBAAoB,EAAE;QACpB,IAAI,EAAE,kBAAkB;QACxB,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE;QACzC,UAAU,EAAE,UAAU;KACvB;IACD,6BAA6B,EAAE;QAC7B,IAAI,EAAE,2BAA2B;QACjC,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE;QACzC,UAAU,EAAE,UAAU;KACvB;CACF,CAAA"}
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Configuration schema for opencode-kimicode-auth plugin.
3
+ *
4
+ * Config file locations (in priority order, highest wins):
5
+ * - Project: .opencode/kimicode.json
6
+ * - User: ~/.config/opencode/kimicode.json (Linux/Mac)
7
+ * %APPDATA%\opencode\kimicode.json (Windows)
8
+ *
9
+ * Environment variables always override config file values.
10
+ */
11
+ import { z } from "zod";
12
+ /**
13
+ * Account selection strategy for distributing requests across accounts.
14
+ *
15
+ * - `sticky`: Use same account until rate-limited. Preserves prompt cache.
16
+ * - `round-robin`: Rotate to next account on every request. Maximum throughput.
17
+ * - `hybrid` (default): Deterministic selection based on health score + token bucket + LRU freshness.
18
+ */
19
+ export declare const AccountSelectionStrategySchema: z.ZodEnum<{
20
+ sticky: "sticky";
21
+ "round-robin": "round-robin";
22
+ hybrid: "hybrid";
23
+ }>;
24
+ export type AccountSelectionStrategy = z.infer<typeof AccountSelectionStrategySchema>;
25
+ /**
26
+ * Toast notification scope for controlling which sessions show toasts.
27
+ *
28
+ * - `root_only` (default): Only show toasts for root sessions (no parentID).
29
+ * Subagents and background tasks won't show toast notifications.
30
+ * - `all`: Show toasts for all sessions including subagents and background tasks.
31
+ */
32
+ export declare const ToastScopeSchema: z.ZodEnum<{
33
+ root_only: "root_only";
34
+ all: "all";
35
+ }>;
36
+ export type ToastScope = z.infer<typeof ToastScopeSchema>;
37
+ /**
38
+ * Scheduling mode for rate limit behavior.
39
+ *
40
+ * - `cache_first`: Wait for same account to recover (preserves prompt cache). Default.
41
+ * - `balance`: Switch account immediately on rate limit. Maximum availability.
42
+ * - `performance_first`: Round-robin distribution for maximum throughput.
43
+ */
44
+ export declare const SchedulingModeSchema: z.ZodEnum<{
45
+ cache_first: "cache_first";
46
+ balance: "balance";
47
+ performance_first: "performance_first";
48
+ }>;
49
+ export type SchedulingMode = z.infer<typeof SchedulingModeSchema>;
50
+ /**
51
+ * Main configuration schema for the Kimi Code plugin.
52
+ */
53
+ export declare const KimicodeConfigSchema: z.ZodObject<{
54
+ $schema: z.ZodOptional<z.ZodString>;
55
+ quiet_mode: z.ZodDefault<z.ZodBoolean>;
56
+ toast_scope: z.ZodDefault<z.ZodEnum<{
57
+ root_only: "root_only";
58
+ all: "all";
59
+ }>>;
60
+ debug: z.ZodDefault<z.ZodBoolean>;
61
+ log_dir: z.ZodOptional<z.ZodString>;
62
+ session_recovery: z.ZodDefault<z.ZodBoolean>;
63
+ auto_resume: z.ZodDefault<z.ZodBoolean>;
64
+ resume_text: z.ZodDefault<z.ZodString>;
65
+ proactive_token_refresh: z.ZodDefault<z.ZodBoolean>;
66
+ proactive_refresh_buffer_seconds: z.ZodDefault<z.ZodNumber>;
67
+ proactive_refresh_check_interval_seconds: z.ZodDefault<z.ZodNumber>;
68
+ max_rate_limit_wait_seconds: z.ZodDefault<z.ZodNumber>;
69
+ account_selection_strategy: z.ZodDefault<z.ZodEnum<{
70
+ sticky: "sticky";
71
+ "round-robin": "round-robin";
72
+ hybrid: "hybrid";
73
+ }>>;
74
+ pid_offset_enabled: z.ZodDefault<z.ZodBoolean>;
75
+ switch_on_first_rate_limit: z.ZodDefault<z.ZodBoolean>;
76
+ scheduling_mode: z.ZodDefault<z.ZodEnum<{
77
+ cache_first: "cache_first";
78
+ balance: "balance";
79
+ performance_first: "performance_first";
80
+ }>>;
81
+ max_cache_first_wait_seconds: z.ZodDefault<z.ZodNumber>;
82
+ failure_ttl_seconds: z.ZodDefault<z.ZodNumber>;
83
+ default_retry_after_seconds: z.ZodDefault<z.ZodNumber>;
84
+ max_backoff_seconds: z.ZodDefault<z.ZodNumber>;
85
+ request_jitter_max_ms: z.ZodDefault<z.ZodNumber>;
86
+ health_score: z.ZodOptional<z.ZodObject<{
87
+ initial: z.ZodDefault<z.ZodNumber>;
88
+ success_reward: z.ZodDefault<z.ZodNumber>;
89
+ rate_limit_penalty: z.ZodDefault<z.ZodNumber>;
90
+ failure_penalty: z.ZodDefault<z.ZodNumber>;
91
+ recovery_rate_per_hour: z.ZodDefault<z.ZodNumber>;
92
+ min_usable: z.ZodDefault<z.ZodNumber>;
93
+ max_score: z.ZodDefault<z.ZodNumber>;
94
+ }, z.core.$strip>>;
95
+ token_bucket: z.ZodOptional<z.ZodObject<{
96
+ max_tokens: z.ZodDefault<z.ZodNumber>;
97
+ regeneration_rate_per_minute: z.ZodDefault<z.ZodNumber>;
98
+ initial_tokens: z.ZodDefault<z.ZodNumber>;
99
+ }, z.core.$strip>>;
100
+ auto_update: z.ZodDefault<z.ZodBoolean>;
101
+ }, z.core.$strip>;
102
+ export type KimicodeConfig = z.infer<typeof KimicodeConfigSchema>;
103
+ /**
104
+ * Default configuration values.
105
+ */
106
+ export declare const DEFAULT_CONFIG: KimicodeConfig;
107
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../src/plugin/config/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;GAMG;AACH,eAAO,MAAM,8BAA8B;;;;EAA8C,CAAC;AAC1F,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,8BAA8B,CAAC,CAAC;AAEtF;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB;;;EAA+B,CAAC;AAC7D,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE1D;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB;;;;EAA0D,CAAC;AAC5F,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAElE;;GAEG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA0O/B,CAAC;AAEH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAElE;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,cAmC5B,CAAC"}
@@ -0,0 +1,282 @@
1
+ /**
2
+ * Configuration schema for opencode-kimicode-auth plugin.
3
+ *
4
+ * Config file locations (in priority order, highest wins):
5
+ * - Project: .opencode/kimicode.json
6
+ * - User: ~/.config/opencode/kimicode.json (Linux/Mac)
7
+ * %APPDATA%\opencode\kimicode.json (Windows)
8
+ *
9
+ * Environment variables always override config file values.
10
+ */
11
+ import { z } from "zod";
12
+ /**
13
+ * Account selection strategy for distributing requests across accounts.
14
+ *
15
+ * - `sticky`: Use same account until rate-limited. Preserves prompt cache.
16
+ * - `round-robin`: Rotate to next account on every request. Maximum throughput.
17
+ * - `hybrid` (default): Deterministic selection based on health score + token bucket + LRU freshness.
18
+ */
19
+ export const AccountSelectionStrategySchema = z.enum(['sticky', 'round-robin', 'hybrid']);
20
+ /**
21
+ * Toast notification scope for controlling which sessions show toasts.
22
+ *
23
+ * - `root_only` (default): Only show toasts for root sessions (no parentID).
24
+ * Subagents and background tasks won't show toast notifications.
25
+ * - `all`: Show toasts for all sessions including subagents and background tasks.
26
+ */
27
+ export const ToastScopeSchema = z.enum(['root_only', 'all']);
28
+ /**
29
+ * Scheduling mode for rate limit behavior.
30
+ *
31
+ * - `cache_first`: Wait for same account to recover (preserves prompt cache). Default.
32
+ * - `balance`: Switch account immediately on rate limit. Maximum availability.
33
+ * - `performance_first`: Round-robin distribution for maximum throughput.
34
+ */
35
+ export const SchedulingModeSchema = z.enum(['cache_first', 'balance', 'performance_first']);
36
+ /**
37
+ * Main configuration schema for the Kimi Code plugin.
38
+ */
39
+ export const KimicodeConfigSchema = z.object({
40
+ /** JSON Schema reference for IDE support */
41
+ $schema: z.string().optional(),
42
+ // =========================================================================
43
+ // General Settings
44
+ // =========================================================================
45
+ /**
46
+ * Suppress most toast notifications (rate limit, account switching, etc.)
47
+ * Recovery toasts are always shown regardless of this setting.
48
+ * Env override: OPENCODE_KIMICODE_QUIET=1
49
+ * @default false
50
+ */
51
+ quiet_mode: z.boolean().default(false),
52
+ /**
53
+ * Control which sessions show toast notifications.
54
+ *
55
+ * - `root_only` (default): Only root sessions show toasts.
56
+ * Subagents and background tasks will be silent (less spam).
57
+ * - `all`: All sessions show toasts including subagents and background tasks.
58
+ *
59
+ * Debug logging captures all toasts regardless of this setting.
60
+ * Env override: OPENCODE_KIMICODE_TOAST_SCOPE=all
61
+ * @default "root_only"
62
+ */
63
+ toast_scope: ToastScopeSchema.default('root_only'),
64
+ /**
65
+ * Enable debug logging to file.
66
+ * Env override: OPENCODE_KIMICODE_DEBUG=1
67
+ * @default false
68
+ */
69
+ debug: z.boolean().default(false),
70
+ /**
71
+ * Custom directory for debug logs.
72
+ * Env override: OPENCODE_KIMICODE_LOG_DIR=/path/to/logs
73
+ * @default OS-specific config dir + "/kimicode-logs"
74
+ */
75
+ log_dir: z.string().optional(),
76
+ // =========================================================================
77
+ // Session Recovery
78
+ // =========================================================================
79
+ /**
80
+ * Enable automatic session recovery from tool_result_missing errors.
81
+ * When enabled, shows a toast notification when recoverable errors occur.
82
+ *
83
+ * @default true
84
+ */
85
+ session_recovery: z.boolean().default(true),
86
+ /**
87
+ * Automatically send a "continue" prompt after successful recovery.
88
+ * Only applies when session_recovery is enabled.
89
+ *
90
+ * When false: Only shows toast notification, user must manually continue.
91
+ * When true: Automatically sends "continue" to resume the session.
92
+ *
93
+ * @default false
94
+ */
95
+ auto_resume: z.boolean().default(false),
96
+ /**
97
+ * Custom text to send when auto-resuming after recovery.
98
+ * Only used when auto_resume is enabled.
99
+ *
100
+ * @default "continue"
101
+ */
102
+ resume_text: z.string().default("continue"),
103
+ // =========================================================================
104
+ // Proactive Token Refresh
105
+ // =========================================================================
106
+ /**
107
+ * Enable proactive background token refresh.
108
+ * When enabled, tokens are refreshed in the background before they expire,
109
+ * ensuring requests never block on token refresh.
110
+ *
111
+ * @default true
112
+ */
113
+ proactive_token_refresh: z.boolean().default(true),
114
+ /**
115
+ * Seconds before token expiry to trigger proactive refresh.
116
+ * Default is 30 minutes (1800 seconds).
117
+ *
118
+ * @default 1800
119
+ */
120
+ proactive_refresh_buffer_seconds: z.number().min(60).max(7200).default(1800),
121
+ /**
122
+ * Interval between proactive refresh checks in seconds.
123
+ * Default is 5 minutes (300 seconds).
124
+ *
125
+ * @default 300
126
+ */
127
+ proactive_refresh_check_interval_seconds: z.number().min(30).max(1800).default(300),
128
+ // =========================================================================
129
+ // Rate Limiting
130
+ // =========================================================================
131
+ /**
132
+ * Maximum time in seconds to wait when all accounts are rate-limited.
133
+ * If the minimum wait time across all accounts exceeds this threshold,
134
+ * the plugin fails fast with an error instead of hanging.
135
+ *
136
+ * Set to 0 to disable (wait indefinitely).
137
+ *
138
+ * @default 300 (5 minutes)
139
+ */
140
+ max_rate_limit_wait_seconds: z.number().min(0).max(3600).default(300),
141
+ /**
142
+ * Strategy for selecting accounts when making requests.
143
+ * Env override: OPENCODE_KIMICODE_ACCOUNT_SELECTION_STRATEGY
144
+ * @default "hybrid"
145
+ */
146
+ account_selection_strategy: AccountSelectionStrategySchema.default('hybrid'),
147
+ /**
148
+ * Enable PID-based account offset for multi-session distribution.
149
+ *
150
+ * When enabled, different sessions (PIDs) will prefer different starting
151
+ * accounts, which helps distribute load when running multiple parallel agents.
152
+ *
153
+ * When disabled (default), accounts start from the same index.
154
+ *
155
+ * Env override: OPENCODE_KIMICODE_PID_OFFSET_ENABLED=1
156
+ * @default false
157
+ */
158
+ pid_offset_enabled: z.boolean().default(false),
159
+ /**
160
+ * Switch to another account immediately on first rate limit (after 1s delay).
161
+ * When disabled, retries same account first, then switches on second rate limit.
162
+ *
163
+ * @default true
164
+ */
165
+ switch_on_first_rate_limit: z.boolean().default(true),
166
+ /**
167
+ * Scheduling mode for rate limit behavior.
168
+ *
169
+ * - `cache_first`: Wait for same account to recover (preserves prompt cache). Default.
170
+ * - `balance`: Switch account immediately on rate limit. Maximum availability.
171
+ * - `performance_first`: Round-robin distribution for maximum throughput.
172
+ *
173
+ * Env override: OPENCODE_KIMICODE_SCHEDULING_MODE
174
+ * @default "cache_first"
175
+ */
176
+ scheduling_mode: SchedulingModeSchema.default('cache_first'),
177
+ /**
178
+ * Maximum seconds to wait for same account in cache_first mode.
179
+ * If the account's rate limit reset time exceeds this, switch accounts.
180
+ *
181
+ * @default 60
182
+ */
183
+ max_cache_first_wait_seconds: z.number().min(5).max(300).default(60),
184
+ /**
185
+ * TTL in seconds for failure count expiration.
186
+ * After this period of no failures, consecutiveFailures resets to 0.
187
+ * This prevents old failures from permanently penalizing an account.
188
+ *
189
+ * @default 3600 (1 hour)
190
+ */
191
+ failure_ttl_seconds: z.number().min(60).max(7200).default(3600),
192
+ /**
193
+ * Default retry delay in seconds when API doesn't return a retry-after header.
194
+ * Lower values allow faster retries but may trigger more 429 errors.
195
+ *
196
+ * @default 60
197
+ */
198
+ default_retry_after_seconds: z.number().min(1).max(300).default(60),
199
+ /**
200
+ * Maximum backoff delay in seconds for exponential retry.
201
+ * This caps how long the exponential backoff can grow.
202
+ *
203
+ * @default 60
204
+ */
205
+ max_backoff_seconds: z.number().min(5).max(300).default(60),
206
+ /**
207
+ * Maximum random delay in milliseconds before each API request.
208
+ * Adds timing jitter to break predictable request cadence patterns.
209
+ * Set to 0 to disable request jitter.
210
+ *
211
+ * @default 0
212
+ */
213
+ request_jitter_max_ms: z.number().min(0).max(5000).default(0),
214
+ // =========================================================================
215
+ // Health Score (used by hybrid strategy)
216
+ // =========================================================================
217
+ health_score: z.object({
218
+ initial: z.number().min(0).max(100).default(70),
219
+ success_reward: z.number().min(0).max(10).default(1),
220
+ rate_limit_penalty: z.number().min(-50).max(0).default(-10),
221
+ failure_penalty: z.number().min(-100).max(0).default(-20),
222
+ recovery_rate_per_hour: z.number().min(0).max(20).default(2),
223
+ min_usable: z.number().min(0).max(100).default(50),
224
+ max_score: z.number().min(50).max(100).default(100),
225
+ }).optional(),
226
+ // =========================================================================
227
+ // Token Bucket (for hybrid strategy)
228
+ // =========================================================================
229
+ token_bucket: z.object({
230
+ max_tokens: z.number().min(1).max(1000).default(50),
231
+ regeneration_rate_per_minute: z.number().min(0.1).max(60).default(6),
232
+ initial_tokens: z.number().min(1).max(1000).default(50),
233
+ }).optional(),
234
+ // =========================================================================
235
+ // Auto-Update
236
+ // =========================================================================
237
+ /**
238
+ * Enable automatic plugin updates.
239
+ * @default true
240
+ */
241
+ auto_update: z.boolean().default(true),
242
+ });
243
+ /**
244
+ * Default configuration values.
245
+ */
246
+ export const DEFAULT_CONFIG = {
247
+ quiet_mode: false,
248
+ toast_scope: 'root_only',
249
+ debug: false,
250
+ session_recovery: true,
251
+ auto_resume: true,
252
+ resume_text: "continue",
253
+ proactive_token_refresh: true,
254
+ proactive_refresh_buffer_seconds: 1800,
255
+ proactive_refresh_check_interval_seconds: 300,
256
+ max_rate_limit_wait_seconds: 300,
257
+ account_selection_strategy: 'hybrid',
258
+ pid_offset_enabled: false,
259
+ switch_on_first_rate_limit: true,
260
+ scheduling_mode: 'cache_first',
261
+ max_cache_first_wait_seconds: 60,
262
+ failure_ttl_seconds: 3600,
263
+ default_retry_after_seconds: 60,
264
+ max_backoff_seconds: 60,
265
+ request_jitter_max_ms: 0,
266
+ auto_update: true,
267
+ health_score: {
268
+ initial: 70,
269
+ success_reward: 1,
270
+ rate_limit_penalty: -10,
271
+ failure_penalty: -20,
272
+ recovery_rate_per_hour: 2,
273
+ min_usable: 50,
274
+ max_score: 100,
275
+ },
276
+ token_bucket: {
277
+ max_tokens: 50,
278
+ regeneration_rate_per_minute: 6,
279
+ initial_tokens: 50,
280
+ },
281
+ };
282
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../../src/plugin/config/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,aAAa,EAAE,QAAQ,CAAC,CAAC,CAAC;AAG1F;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC;AAG7D;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,aAAa,EAAE,SAAS,EAAE,mBAAmB,CAAC,CAAC,CAAC;AAG5F;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC3C,4CAA4C;IAC5C,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAE9B,4EAA4E;IAC5E,mBAAmB;IACnB,4EAA4E;IAE5E;;;;;OAKG;IACH,UAAU,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;IAEtC;;;;;;;;;;OAUG;IACH,WAAW,EAAE,gBAAgB,CAAC,OAAO,CAAC,WAAW,CAAC;IAElD;;;;OAIG;IACH,KAAK,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;IAEjC;;;;OAIG;IACH,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAE9B,4EAA4E;IAC5E,mBAAmB;IACnB,4EAA4E;IAE5E;;;;;OAKG;IACH,gBAAgB,EAAE,CAAC,CAAC,OA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CAAC,CAAC;AAIH;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAmB;IAC5C,UAAU,EAAE,KAAK;IACjB,WAAW,EAAE,WAAW;IACxB,KAAK,EAAE,KAAK;IACZ,gBAAgB,EAAE,IAAI;IACtB,WAAW,EAAE,IAAI;IACjB,WAAW,EAAE,UAAU;IACvB,uBAAuB,EAAE,IAAI;IAC7B,gCAAgC,EAAE,IAAI;IACtC,wCAAwC,EAAE,GAAG;IAC7C,2BAA2B,EAAE,GAAG;IAChC,0BAA0B,EAAE,QAAQ;IACpC,kBAAkB,EAAE,KAAK;IACzB,0BAA0B,EAAE,IAAI;IAChC,eAAe,EAAE,aAAa;IAC9B,4BAA4B,EAAE,EAAE;IAChC,mBAAmB,EAAE,IAAI;IACzB,2BAA2B,EAAE,EAAE;IAC/B,mBAAmB,EAAE,EAAE;IACvB,qBAAqB,EAAE,CAAC;IACxB,WAAW,EAAE,IAAI;IACjB,YAAY,EAAE;QACZ,OAAO,EAAE,EAAE;QACX,cAAc,EAAE,CAAC;QACjB,kBAAkB,EAAE,CAAC,EAAE;QACvB,eAAe,EAAE,CAAC,EAAE;QACpB,sBAAsB,EAAE,CAAC;QACzB,UAAU,EAAE,EAAE;QACd,SAAS,EAAE,GAAG;KACf;IACD,YAAY,EAAE;QACZ,UAAU,EAAE,EAAE;QACd,4BAA4B,EAAE,CAAC;QAC/B,cAAc,EAAE,EAAE;KACnB;CACF,CAAC"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * OpenCode configuration file updater.
3
+ *
4
+ * Updates ~/.config/opencode/opencode.json(c) with plugin models.
5
+ */
6
+ export interface UpdateConfigResult {
7
+ success: boolean;
8
+ configPath: string;
9
+ error?: string;
10
+ }
11
+ export interface OpencodeConfig {
12
+ $schema?: string;
13
+ plugin?: string[];
14
+ provider?: {
15
+ moonshotai?: {
16
+ models?: Record<string, unknown>;
17
+ [key: string]: unknown;
18
+ };
19
+ [key: string]: unknown;
20
+ };
21
+ [key: string]: unknown;
22
+ }
23
+ export interface UpdateConfigOptions {
24
+ /** Override the config file path (for testing) */
25
+ configPath?: string;
26
+ }
27
+ /**
28
+ * Get the opencode config directory path.
29
+ */
30
+ export declare function getOpencodeConfigDir(): string;
31
+ /**
32
+ * Get the opencode config file path.
33
+ *
34
+ * Prefers opencode.jsonc when present so we update the active config file
35
+ * instead of creating a new opencode.json.
36
+ */
37
+ export declare function getOpencodeConfigPath(): string;
38
+ /**
39
+ * Updates the opencode configuration file with plugin models.
40
+ *
41
+ * This function:
42
+ * 1. Reads existing opencode.json/opencode.jsonc (or creates default structure)
43
+ * 2. Replaces `provider.moonshotai.models` with plugin models
44
+ * 3. Writes back to disk with proper formatting
45
+ *
46
+ * Preserves:
47
+ * - $schema and other top-level config keys
48
+ * - Non-moonshotai provider sections
49
+ * - Other settings within moonshotai provider (except models)
50
+ *
51
+ * @param options - Optional configuration (e.g., custom configPath for testing)
52
+ * @returns UpdateConfigResult with success status and path
53
+ */
54
+ export declare function updateOpencodeConfig(options?: UpdateConfigOptions): Promise<UpdateConfigResult>;
55
+ //# sourceMappingURL=updater.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"updater.d.ts","sourceRoot":"","sources":["../../../../src/plugin/config/updater.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAWH,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,CAAC,EAAE;QACT,UAAU,CAAC,EAAE;YACX,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YACjC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;SACxB,CAAC;QACF,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACxB,CAAC;IACF,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,mBAAmB;IAClC,kDAAkD;IAClD,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAgCD;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,CAG7C;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,CAa9C;AAMD;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,kBAAkB,CAAC,CAgG7B"}
@@ -0,0 +1,154 @@
1
+ /**
2
+ * OpenCode configuration file updater.
3
+ *
4
+ * Updates ~/.config/opencode/opencode.json(c) with plugin models.
5
+ */
6
+ import { existsSync, readFileSync, writeFileSync, mkdirSync } from "node:fs";
7
+ import { join, dirname } from "node:path";
8
+ import { homedir } from "node:os";
9
+ import { OPENCODE_MODEL_DEFINITIONS } from "./models";
10
+ // =============================================================================
11
+ // Constants
12
+ // =============================================================================
13
+ const PLUGIN_NAME = "opencode-kimicode-auth@latest";
14
+ const SCHEMA_URL = "https://opencode.ai/config.json";
15
+ const OPENCODE_JSON_FILENAME = "opencode.json";
16
+ const OPENCODE_JSONC_FILENAME = "opencode.jsonc";
17
+ function isLegacyKimicodeModelDefinition(value, expectedName) {
18
+ if (!value || typeof value !== "object")
19
+ return false;
20
+ const v = value;
21
+ return (v.name === expectedName &&
22
+ v.limit &&
23
+ typeof v.limit === "object" &&
24
+ v.limit.context === 131072 &&
25
+ v.limit.output === 16384);
26
+ }
27
+ function stripJsonCommentsAndTrailingCommas(json) {
28
+ return json
29
+ .replace(/\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g, (match, group) => (group ? "" : match))
30
+ .replace(/,(\s*[}\]])/g, "$1");
31
+ }
32
+ /**
33
+ * Get the opencode config directory path.
34
+ */
35
+ export function getOpencodeConfigDir() {
36
+ const xdgConfig = process.env.XDG_CONFIG_HOME || join(homedir(), ".config");
37
+ return join(xdgConfig, "opencode");
38
+ }
39
+ /**
40
+ * Get the opencode config file path.
41
+ *
42
+ * Prefers opencode.jsonc when present so we update the active config file
43
+ * instead of creating a new opencode.json.
44
+ */
45
+ export function getOpencodeConfigPath() {
46
+ const configDir = getOpencodeConfigDir();
47
+ const jsoncPath = join(configDir, OPENCODE_JSONC_FILENAME);
48
+ const jsonPath = join(configDir, OPENCODE_JSON_FILENAME);
49
+ if (existsSync(jsoncPath)) {
50
+ return jsoncPath;
51
+ }
52
+ if (existsSync(jsonPath)) {
53
+ return jsonPath;
54
+ }
55
+ return jsonPath;
56
+ }
57
+ // =============================================================================
58
+ // Main Function
59
+ // =============================================================================
60
+ /**
61
+ * Updates the opencode configuration file with plugin models.
62
+ *
63
+ * This function:
64
+ * 1. Reads existing opencode.json/opencode.jsonc (or creates default structure)
65
+ * 2. Replaces `provider.moonshotai.models` with plugin models
66
+ * 3. Writes back to disk with proper formatting
67
+ *
68
+ * Preserves:
69
+ * - $schema and other top-level config keys
70
+ * - Non-moonshotai provider sections
71
+ * - Other settings within moonshotai provider (except models)
72
+ *
73
+ * @param options - Optional configuration (e.g., custom configPath for testing)
74
+ * @returns UpdateConfigResult with success status and path
75
+ */
76
+ export async function updateOpencodeConfig(options = {}) {
77
+ const configPath = options.configPath ?? getOpencodeConfigPath();
78
+ try {
79
+ let config;
80
+ // Read existing config or create default
81
+ if (existsSync(configPath)) {
82
+ const content = readFileSync(configPath, "utf-8");
83
+ config = JSON.parse(stripJsonCommentsAndTrailingCommas(content));
84
+ }
85
+ else {
86
+ // Create default config structure
87
+ config = {
88
+ $schema: SCHEMA_URL,
89
+ plugin: [],
90
+ provider: {},
91
+ };
92
+ }
93
+ // Ensure $schema is set
94
+ if (!config.$schema) {
95
+ config.$schema = SCHEMA_URL;
96
+ }
97
+ // Ensure plugin array exists and contains our plugin
98
+ if (!Array.isArray(config.plugin)) {
99
+ config.plugin = [];
100
+ }
101
+ // Check if plugin is already in the list (any version)
102
+ const hasPlugin = config.plugin.some((p) => p.includes("opencode-kimicode-auth"));
103
+ if (!hasPlugin) {
104
+ config.plugin.push(PLUGIN_NAME);
105
+ }
106
+ // Ensure provider.moonshotai structure exists
107
+ if (!config.provider) {
108
+ config.provider = {};
109
+ }
110
+ if (!config.provider.moonshotai) {
111
+ config.provider.moonshotai = {};
112
+ }
113
+ // Additive-only: keep existing Moonshot API-key models and merge in
114
+ // kimicode-* models for the OAuth flow.
115
+ const existingModels = config.provider.moonshotai.models && typeof config.provider.moonshotai.models === "object"
116
+ ? config.provider.moonshotai.models
117
+ : {};
118
+ // Remove legacy pre-prefix keys we may have written in older versions.
119
+ // These collide with Moonshot API-key models and should not be managed by this plugin.
120
+ const cleanedModels = { ...existingModels };
121
+ if (isLegacyKimicodeModelDefinition(cleanedModels["kimi-for-coding"], "Kimi for Coding")) {
122
+ delete cleanedModels["kimi-for-coding"];
123
+ }
124
+ if (isLegacyKimicodeModelDefinition(cleanedModels["kimi-k2.5"], "Kimi K2.5")) {
125
+ delete cleanedModels["kimi-k2.5"];
126
+ }
127
+ if (isLegacyKimicodeModelDefinition(cleanedModels["kimi-k2-thinking"], "Kimi K2 Thinking")) {
128
+ delete cleanedModels["kimi-k2-thinking"];
129
+ }
130
+ config.provider.moonshotai.models = {
131
+ ...cleanedModels,
132
+ ...OPENCODE_MODEL_DEFINITIONS,
133
+ };
134
+ // Ensure config directory exists
135
+ const configDir = dirname(configPath);
136
+ if (!existsSync(configDir)) {
137
+ mkdirSync(configDir, { recursive: true });
138
+ }
139
+ // Write config with proper formatting (2-space indent)
140
+ writeFileSync(configPath, JSON.stringify(config, null, 2), "utf-8");
141
+ return {
142
+ success: true,
143
+ configPath,
144
+ };
145
+ }
146
+ catch (error) {
147
+ return {
148
+ success: false,
149
+ configPath,
150
+ error: error instanceof Error ? error.message : String(error),
151
+ };
152
+ }
153
+ }
154
+ //# sourceMappingURL=updater.js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