pi-commandcode-provider 0.5.1 → 0.6.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.
- package/CHANGELOG.md +30 -0
- package/CONTRIBUTING.md +10 -0
- package/README.md +38 -12
- package/index.ts +72 -36
- package/package.json +13 -4
- package/scripts/live-e2e-profile.mjs +87 -0
- package/scripts/pi-authenticated.mjs +1 -0
- package/scripts/pi-isolated.mjs +1 -0
- package/src/api-key.ts +69 -0
- package/src/auth-server.ts +7 -0
- package/src/commandcode-catalog.ts +141 -0
- package/src/converters.ts +72 -16
- package/src/core.ts +117 -23
- package/src/models.ts +50 -97
- package/src/oauth.ts +84 -22
- package/src/pricing.ts +53 -45
- package/src/quota-command.ts +66 -0
- package/src/quota-format.ts +111 -0
- package/src/quota-types.ts +47 -0
- package/src/quota.ts +335 -0
- package/src/runtime.ts +10 -5
- package/src/transport.ts +140 -0
- package/src/types.ts +9 -0
package/src/models.ts
CHANGED
|
@@ -1,58 +1,26 @@
|
|
|
1
1
|
import { mkdir, readFile, rename, rm, writeFile } from "node:fs/promises"
|
|
2
2
|
import { dirname } from "node:path"
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
import {
|
|
5
|
+
MODEL_EFFORTS,
|
|
6
|
+
MODEL_INPUT_MODALITIES,
|
|
7
|
+
MODEL_MAX_OUTPUT_TOKENS,
|
|
8
|
+
MODEL_REASONING,
|
|
9
|
+
type CommandCodeInputType,
|
|
10
|
+
type CommandCodeReasoningEffort,
|
|
11
|
+
} from "./commandcode-catalog.ts"
|
|
12
|
+
|
|
13
|
+
export { MODEL_EFFORTS, MODEL_INPUT_MODALITIES, MODEL_MAX_OUTPUT_TOKENS, MODEL_REASONING }
|
|
14
|
+
export type { CommandCodeInputType }
|
|
15
|
+
|
|
16
|
+
export const DEFAULT_PROVIDER_API_BASE = "https://api.commandcode.ai/provider/v1"
|
|
17
|
+
export const DEFAULT_MODELS_URL = `${DEFAULT_PROVIDER_API_BASE}/models`
|
|
5
18
|
export const DEFAULT_MODELS_TIMEOUT_MS = 10_000
|
|
6
19
|
|
|
7
20
|
const DEFAULT_MAX_OUTPUT_TOKENS = 65_536
|
|
8
21
|
const MODEL_CACHE_VERSION = 1
|
|
9
22
|
|
|
10
|
-
export type
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Model input modalities from the command-code@1.15.1 bundled catalog.
|
|
14
|
-
* Models omitted here remain text-only so newly discovered IDs never claim
|
|
15
|
-
* image support without upstream evidence.
|
|
16
|
-
*/
|
|
17
|
-
export const MODEL_INPUT_MODALITIES: Readonly<Record<string, readonly CommandCodeInputType[]>> = {
|
|
18
|
-
"MiniMaxAI/MiniMax-M3": ["text", "image"],
|
|
19
|
-
"Qwen/Qwen3.6-Plus": ["text", "image"],
|
|
20
|
-
"Qwen/Qwen3.7-Flash": ["text", "image"],
|
|
21
|
-
"Qwen/Qwen3.7-Plus": ["text", "image"],
|
|
22
|
-
"Qwen/Qwen3.8-Max": ["text", "image"],
|
|
23
|
-
"claude-fable-5": ["text", "image"],
|
|
24
|
-
"claude-haiku-4-5-20251001": ["text", "image"],
|
|
25
|
-
"claude-opus-4-7": ["text", "image"],
|
|
26
|
-
"claude-opus-4-8": ["text", "image"],
|
|
27
|
-
"claude-opus-5": ["text", "image"],
|
|
28
|
-
"claude-sonnet-4-6": ["text", "image"],
|
|
29
|
-
"claude-sonnet-5": ["text", "image"],
|
|
30
|
-
"google/gemini-3.1-flash-lite": ["text", "image"],
|
|
31
|
-
"google/gemini-3.5-flash": ["text", "image"],
|
|
32
|
-
"google/gemini-3.5-flash-lite": ["text", "image"],
|
|
33
|
-
"google/gemini-3.6-flash": ["text", "image"],
|
|
34
|
-
"gpt-5.3-codex": ["text", "image"],
|
|
35
|
-
"gpt-5.4": ["text", "image"],
|
|
36
|
-
"gpt-5.4-mini": ["text", "image"],
|
|
37
|
-
"gpt-5.5": ["text", "image"],
|
|
38
|
-
"gpt-5.6-luna": ["text", "image"],
|
|
39
|
-
"gpt-5.6-sol": ["text", "image"],
|
|
40
|
-
"gpt-5.6-terra": ["text", "image"],
|
|
41
|
-
"meta/muse-spark-1.1": ["text", "image"],
|
|
42
|
-
"meta/muse-spark-1.2": ["text", "image"],
|
|
43
|
-
"meta/muse-spark-1.2-contributor": ["text", "image"],
|
|
44
|
-
"moonshotai/Kimi-K2.5": ["text", "image"],
|
|
45
|
-
"moonshotai/Kimi-K2.6": ["text", "image"],
|
|
46
|
-
"moonshotai/Kimi-K2.7-Code": ["text", "image"],
|
|
47
|
-
"moonshotai/Kimi-K2.7-Code-Highspeed": ["text", "image"],
|
|
48
|
-
"moonshotai/Kimi-K3": ["text", "image"],
|
|
49
|
-
"sakana/fugu-ultra": ["text", "image"],
|
|
50
|
-
"stepfun/Step-3.7-Flash": ["text", "image"],
|
|
51
|
-
"thinkingmachines/inkling": ["text", "image"],
|
|
52
|
-
"thinkingmachines/inkling-small": ["text", "image"],
|
|
53
|
-
"xai/grok-4.5": ["text", "image"],
|
|
54
|
-
"xiaomi/mimo-v2.5": ["text", "image"],
|
|
55
|
-
}
|
|
23
|
+
export type CommandCodeApi = "openai-completions" | "anthropic-messages"
|
|
56
24
|
|
|
57
25
|
const TEXT_INPUT_ONLY = ["text"] as const
|
|
58
26
|
|
|
@@ -66,43 +34,6 @@ export function modelSupportsImageInput(modelId: string): boolean {
|
|
|
66
34
|
|
|
67
35
|
export type PiThinkingLevel = "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max"
|
|
68
36
|
|
|
69
|
-
type CommandCodeReasoningEffort = Exclude<PiThinkingLevel, "off">
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Per-model reasoning efforts supported by Command Code's generate endpoint.
|
|
73
|
-
*
|
|
74
|
-
* The Provider API does not expose reasoning metadata. This is an exact
|
|
75
|
-
* snapshot of `reasoningEfforts` from the command-code@1.15.1 model catalog
|
|
76
|
-
* (`packages/shared/src/model-catalog.ts`, also published in the generated
|
|
77
|
-
* `dist/bundled/command-code-knowledge/reference/models.md`). Models omitted
|
|
78
|
-
* here let Command Code choose their reasoning depth, matching the CLI.
|
|
79
|
-
*/
|
|
80
|
-
export const MODEL_EFFORTS: Readonly<Record<string, readonly CommandCodeReasoningEffort[]>> = {
|
|
81
|
-
"Qwen/Qwen3.8-Max": ["low", "medium", "xhigh"],
|
|
82
|
-
"claude-fable-5": ["low", "medium", "high", "xhigh", "max"],
|
|
83
|
-
"claude-opus-4-7": ["low", "medium", "high", "xhigh", "max"],
|
|
84
|
-
"claude-opus-4-8": ["low", "medium", "high", "xhigh", "max"],
|
|
85
|
-
"claude-opus-5": ["low", "medium", "high", "xhigh", "max"],
|
|
86
|
-
"claude-sonnet-4-6": ["low", "medium", "high", "xhigh", "max"],
|
|
87
|
-
"claude-sonnet-5": ["low", "medium", "high", "xhigh", "max"],
|
|
88
|
-
"deepseek/deepseek-v4-flash": ["high", "max"],
|
|
89
|
-
"deepseek/deepseek-v4-pro": ["high", "max"],
|
|
90
|
-
"gpt-5.3-codex": ["low", "medium", "high", "xhigh"],
|
|
91
|
-
"gpt-5.4": ["low", "medium", "high", "xhigh"],
|
|
92
|
-
"gpt-5.4-mini": ["low", "medium", "high"],
|
|
93
|
-
"gpt-5.5": ["low", "medium", "high", "xhigh"],
|
|
94
|
-
"gpt-5.6-luna": ["low", "medium", "high", "xhigh", "max"],
|
|
95
|
-
"gpt-5.6-sol": ["low", "medium", "high", "xhigh", "max"],
|
|
96
|
-
"gpt-5.6-terra": ["low", "medium", "high", "xhigh", "max"],
|
|
97
|
-
"google/gemini-3.1-flash-lite": ["low", "medium", "high"],
|
|
98
|
-
"google/gemini-3.5-flash": ["low", "medium", "high"],
|
|
99
|
-
"google/gemini-3.5-flash-lite": ["low", "medium", "high"],
|
|
100
|
-
"google/gemini-3.6-flash": ["low", "medium", "high"],
|
|
101
|
-
"sakana/fugu-ultra": ["high", "xhigh"],
|
|
102
|
-
"xai/grok-4.5": ["low", "medium", "high"],
|
|
103
|
-
"zai-org/GLM-5.2": ["high", "max"],
|
|
104
|
-
}
|
|
105
|
-
|
|
106
37
|
const PI_THINKING_LEVELS: readonly PiThinkingLevel[] = [
|
|
107
38
|
"off",
|
|
108
39
|
"minimal",
|
|
@@ -126,7 +57,7 @@ export function thinkingLevelMapForEfforts(
|
|
|
126
57
|
|
|
127
58
|
export interface ThinkingMetadata {
|
|
128
59
|
thinkingLevelMap: Partial<Record<PiThinkingLevel, string | null>>
|
|
129
|
-
thinking
|
|
60
|
+
thinking?: {
|
|
130
61
|
mode: "effort"
|
|
131
62
|
effortMap: Partial<Record<CommandCodeReasoningEffort, string>>
|
|
132
63
|
efforts: readonly CommandCodeReasoningEffort[]
|
|
@@ -135,19 +66,26 @@ export interface ThinkingMetadata {
|
|
|
135
66
|
|
|
136
67
|
export function thinkingMetadataForModel(modelId: string): ThinkingMetadata | undefined {
|
|
137
68
|
const efforts = MODEL_EFFORTS[modelId]
|
|
138
|
-
if (
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
69
|
+
if (efforts) {
|
|
70
|
+
return {
|
|
71
|
+
thinkingLevelMap: thinkingLevelMapForEfforts(efforts),
|
|
72
|
+
thinking: {
|
|
73
|
+
mode: "effort",
|
|
74
|
+
effortMap: Object.fromEntries(efforts.map((effort) => [effort, effort])),
|
|
75
|
+
efforts,
|
|
76
|
+
},
|
|
77
|
+
}
|
|
146
78
|
}
|
|
79
|
+
if (!isReasoningModel(modelId)) return undefined
|
|
80
|
+
return { thinkingLevelMap: thinkingLevelMapForEfforts([]) }
|
|
147
81
|
}
|
|
148
82
|
|
|
149
83
|
function isReasoningModel(modelId: string): boolean {
|
|
150
|
-
return
|
|
84
|
+
return MODEL_REASONING[modelId] === true
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function maxOutputTokensForModel(modelId: string, contextLength: number): number {
|
|
88
|
+
return Math.min(contextLength, MODEL_MAX_OUTPUT_TOKENS[modelId] ?? DEFAULT_MAX_OUTPUT_TOKENS)
|
|
151
89
|
}
|
|
152
90
|
|
|
153
91
|
interface ApiModel {
|
|
@@ -159,11 +97,22 @@ interface ApiModel {
|
|
|
159
97
|
export interface CommandCodeModel {
|
|
160
98
|
id: string
|
|
161
99
|
name: string
|
|
100
|
+
api: CommandCodeApi
|
|
162
101
|
reasoning: boolean
|
|
163
102
|
contextWindow: number
|
|
164
103
|
maxTokens: number
|
|
165
104
|
}
|
|
166
105
|
|
|
106
|
+
export function apiForModelId(id: string): CommandCodeApi {
|
|
107
|
+
return id.startsWith("claude-") ? "anthropic-messages" : "openai-completions"
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function baseUrlForModel(apiBase: string, api: CommandCodeApi): string {
|
|
111
|
+
const normalized = apiBase.replace(/\/+$/g, "")
|
|
112
|
+
if (api !== "anthropic-messages") return normalized
|
|
113
|
+
return normalized.endsWith("/v1") ? normalized.slice(0, -3) : normalized
|
|
114
|
+
}
|
|
115
|
+
|
|
167
116
|
interface FetchCommandCodeModelsOptions {
|
|
168
117
|
url?: string
|
|
169
118
|
fetchImpl?: typeof fetch
|
|
@@ -222,12 +171,15 @@ function parseCachedModel(value: unknown): CommandCodeModel {
|
|
|
222
171
|
|
|
223
172
|
const id = stringField(value, "id")
|
|
224
173
|
booleanField(value, "reasoning")
|
|
174
|
+
positiveNumberField(value, "maxTokens")
|
|
175
|
+
const contextWindow = positiveNumberField(value, "contextWindow")
|
|
225
176
|
return {
|
|
226
177
|
id,
|
|
227
178
|
name: stringField(value, "name"),
|
|
179
|
+
api: apiForModelId(id),
|
|
228
180
|
reasoning: isReasoningModel(id),
|
|
229
|
-
contextWindow
|
|
230
|
-
maxTokens:
|
|
181
|
+
contextWindow,
|
|
182
|
+
maxTokens: maxOutputTokensForModel(id, contextWindow),
|
|
231
183
|
}
|
|
232
184
|
}
|
|
233
185
|
|
|
@@ -329,9 +281,10 @@ export function commandCodeModelsFromApiResponse(value: unknown): readonly Comma
|
|
|
329
281
|
return data.map(parseApiModel).map((model) => ({
|
|
330
282
|
id: model.id,
|
|
331
283
|
name: `${model.name} (CC)`,
|
|
284
|
+
api: apiForModelId(model.id),
|
|
332
285
|
reasoning: isReasoningModel(model.id),
|
|
333
286
|
contextWindow: model.contextLength,
|
|
334
|
-
maxTokens:
|
|
287
|
+
maxTokens: maxOutputTokensForModel(model.id, model.contextLength),
|
|
335
288
|
}))
|
|
336
289
|
}
|
|
337
290
|
|
package/src/oauth.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Command Code OAuth provider for pi's /login flow.
|
|
3
3
|
*
|
|
4
|
-
* Implements
|
|
5
|
-
* 1.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
4
|
+
* Implements two API key retrieval flows:
|
|
5
|
+
* 1. Browser-assisted login opens Command Code Studio and waits for the
|
|
6
|
+
* website to POST the API key back to a local callback server.
|
|
7
|
+
* 2. Direct API key login prompts the user to paste a Studio API key.
|
|
8
|
+
*
|
|
9
|
+
* If browser transfer fails, the user can still paste the API key manually.
|
|
10
|
+
* The API key is stored in pi's auth.json as OAuth credentials.
|
|
11
11
|
*
|
|
12
12
|
* Since Command Code API keys don't expire, we store them as
|
|
13
13
|
* OAuth credentials with a far-future expiry.
|
|
@@ -18,7 +18,8 @@ import { startAuthServer } from "./auth-server.ts"
|
|
|
18
18
|
|
|
19
19
|
const STUDIO_BASE_URL = "https://commandcode.ai"
|
|
20
20
|
const TEN_YEARS_MS = 10 * 365 * 24 * 60 * 60 * 1000 // API keys don't expire
|
|
21
|
-
const DEFAULT_AUTH_TIMEOUT_MS =
|
|
21
|
+
const DEFAULT_AUTH_TIMEOUT_MS = 120_000
|
|
22
|
+
const DEFAULT_API_BASE = "https://api.commandcode.ai"
|
|
22
23
|
|
|
23
24
|
export interface OAuthLoginCallbacks {
|
|
24
25
|
onAuth(params: { url: string }): void
|
|
@@ -95,22 +96,70 @@ export function sanitizeApiKey(input: string): string {
|
|
|
95
96
|
.trim()
|
|
96
97
|
}
|
|
97
98
|
|
|
99
|
+
export async function validateApiKey(
|
|
100
|
+
apiKey: string,
|
|
101
|
+
options: { fetchImpl?: typeof fetch; apiBase?: string } = {},
|
|
102
|
+
): Promise<void> {
|
|
103
|
+
let response: Response
|
|
104
|
+
try {
|
|
105
|
+
response = await (options.fetchImpl ?? fetch)(
|
|
106
|
+
`${options.apiBase ?? DEFAULT_API_BASE}/alpha/whoami`,
|
|
107
|
+
{
|
|
108
|
+
headers: { Authorization: `Bearer ${apiKey}` },
|
|
109
|
+
},
|
|
110
|
+
)
|
|
111
|
+
} catch (error) {
|
|
112
|
+
throw new Error(
|
|
113
|
+
`Could not validate the Command Code API key: ${error instanceof Error ? error.message : String(error)}`,
|
|
114
|
+
)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (response.status === 401) throw new Error("Invalid Command Code API key")
|
|
118
|
+
if (!response.ok) {
|
|
119
|
+
throw new Error(`Could not validate the Command Code API key (${response.status})`)
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
98
123
|
async function promptForApiKey(callbacks: OAuthLoginCallbacks, message: string) {
|
|
99
124
|
const apiKey = sanitizeApiKey(await callbacks.onPrompt({ message }))
|
|
100
125
|
if (!apiKey) throw new Error("No Command Code API key provided")
|
|
126
|
+
await validateApiKey(apiKey)
|
|
101
127
|
return credentialsFromApiKey(apiKey)
|
|
102
128
|
}
|
|
103
129
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
130
|
+
type LoginChoice = { type: "browser" } | { type: "prompt" } | { type: "apiKey"; apiKey: string }
|
|
131
|
+
|
|
132
|
+
async function chooseLoginFlow(callbacks: OAuthLoginCallbacks): Promise<LoginChoice> {
|
|
133
|
+
const input = sanitizeApiKey(
|
|
134
|
+
await callbacks.onPrompt({
|
|
135
|
+
message:
|
|
136
|
+
"Command Code login: press Enter for browser login, type 'key' to paste an API key, or paste the API key directly:",
|
|
137
|
+
}),
|
|
138
|
+
)
|
|
139
|
+
const normalized = input.toLowerCase()
|
|
140
|
+
|
|
141
|
+
if (!input || normalized === "1" || normalized === "b" || normalized === "browser") {
|
|
142
|
+
return { type: "browser" }
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (
|
|
146
|
+
normalized === "2" ||
|
|
147
|
+
normalized === "k" ||
|
|
148
|
+
normalized === "key" ||
|
|
149
|
+
normalized === "api" ||
|
|
150
|
+
normalized === "paste"
|
|
151
|
+
) {
|
|
152
|
+
return { type: "prompt" }
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return { type: "apiKey", apiKey: input }
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
async function browserLogin(callbacks: OAuthLoginCallbacks): Promise<OAuthCredentials> {
|
|
159
|
+
const stateToken = generateStateToken()
|
|
111
160
|
let authServer
|
|
112
161
|
try {
|
|
113
|
-
authServer = await startAuthServer()
|
|
162
|
+
authServer = await startAuthServer({ expectedState: stateToken })
|
|
114
163
|
} catch {
|
|
115
164
|
return promptForApiKey(
|
|
116
165
|
callbacks,
|
|
@@ -118,7 +167,6 @@ export async function login(callbacks: OAuthLoginCallbacks): Promise<OAuthCreden
|
|
|
118
167
|
)
|
|
119
168
|
}
|
|
120
169
|
|
|
121
|
-
const stateToken = generateStateToken()
|
|
122
170
|
const callbackUrl = `http://localhost:${authServer.port}/callback`
|
|
123
171
|
const authUrl = `${STUDIO_BASE_URL}/studio/auth/cli?callback=${encodeURIComponent(callbackUrl)}&state=${encodeURIComponent(stateToken)}`
|
|
124
172
|
|
|
@@ -142,13 +190,27 @@ export async function login(callbacks: OAuthLoginCallbacks): Promise<OAuthCreden
|
|
|
142
190
|
throw error
|
|
143
191
|
}
|
|
144
192
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
193
|
+
return credentialsFromApiKey(callback.apiKey)
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Starts the login flow for Command Code.
|
|
198
|
+
*
|
|
199
|
+
* Returns OAuth credentials where access == refresh == the user's API key.
|
|
200
|
+
* The keys don't expire, so we set a far-future expiry.
|
|
201
|
+
*/
|
|
202
|
+
export async function login(callbacks: OAuthLoginCallbacks): Promise<OAuthCredentials> {
|
|
203
|
+
const choice = await chooseLoginFlow(callbacks)
|
|
204
|
+
|
|
205
|
+
if (choice.type === "apiKey") {
|
|
206
|
+
await validateApiKey(choice.apiKey)
|
|
207
|
+
return credentialsFromApiKey(choice.apiKey)
|
|
208
|
+
}
|
|
209
|
+
if (choice.type === "prompt") {
|
|
210
|
+
return promptForApiKey(callbacks, "Paste your Command Code API key:")
|
|
149
211
|
}
|
|
150
212
|
|
|
151
|
-
return
|
|
213
|
+
return browserLogin(callbacks)
|
|
152
214
|
}
|
|
153
215
|
|
|
154
216
|
/**
|
package/src/pricing.ts
CHANGED
|
@@ -20,7 +20,7 @@ export interface TemporaryPricing {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export const PRICING_SOURCE_URL = "https://commandcode.ai/docs/resources/pricing-limits"
|
|
23
|
-
export const PRICING_LAST_VERIFIED = "2026-08-
|
|
23
|
+
export const PRICING_LAST_VERIFIED = "2026-08-25"
|
|
24
24
|
|
|
25
25
|
export const ZERO_MODEL_COST: CommandCodeModelCost = {
|
|
26
26
|
input: 0,
|
|
@@ -40,7 +40,7 @@ export const ZERO_MODEL_COST: CommandCodeModelCost = {
|
|
|
40
40
|
export const MODEL_COSTS: Readonly<Record<string, CommandCodeModelCost>> = {
|
|
41
41
|
// Free models
|
|
42
42
|
"poolside/laguna-s-2.1-free": { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
43
|
-
"
|
|
43
|
+
"stealth/ox-alpha": { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
44
44
|
|
|
45
45
|
// Open and open-weight models
|
|
46
46
|
"tencent/hy3-paid": { input: 0.14, output: 0.58, cacheRead: 0.035, cacheWrite: 0 },
|
|
@@ -54,6 +54,7 @@ export const MODEL_COSTS: Readonly<Record<string, CommandCodeModelCost>> = {
|
|
|
54
54
|
},
|
|
55
55
|
"moonshotai/Kimi-K2.6": { input: 0.95, output: 4, cacheRead: 0.16, cacheWrite: 0 },
|
|
56
56
|
"moonshotai/Kimi-K2.5": { input: 0.6, output: 3, cacheRead: 0.1, cacheWrite: 0 },
|
|
57
|
+
"zai-org/GLM-5.3": { input: 1.4, output: 4.4, cacheRead: 0.26, cacheWrite: 0 },
|
|
57
58
|
"zai-org/GLM-5.2": { input: 1.4, output: 4.4, cacheRead: 0.26, cacheWrite: 0 },
|
|
58
59
|
"zai-org/GLM-5.2-Fast": { input: 3, output: 10.25, cacheRead: 0.5, cacheWrite: 0 },
|
|
59
60
|
"zai-org/GLM-5.1": { input: 1.4, output: 4.4, cacheRead: 0.26, cacheWrite: 0 },
|
|
@@ -61,20 +62,28 @@ export const MODEL_COSTS: Readonly<Record<string, CommandCodeModelCost>> = {
|
|
|
61
62
|
"MiniMaxAI/MiniMax-M3": { input: 0.3, output: 1.2, cacheRead: 0.06, cacheWrite: 0 },
|
|
62
63
|
"MiniMaxAI/MiniMax-M2.7": { input: 0.3, output: 1.2, cacheRead: 0.06, cacheWrite: 0 },
|
|
63
64
|
"MiniMaxAI/MiniMax-M2.5": { input: 0.3, output: 1.2, cacheRead: 0.03, cacheWrite: 0 },
|
|
64
|
-
//
|
|
65
|
+
// DeepSeek V4 uses time-dependent rates. Display the documented off-peak
|
|
66
|
+
// rates, which apply for 17 hours per day; the Usage page remains authoritative.
|
|
65
67
|
"deepseek/deepseek-v4-pro": {
|
|
66
|
-
input: 0.
|
|
67
|
-
output:
|
|
68
|
-
cacheRead: 0.
|
|
68
|
+
input: 0.66,
|
|
69
|
+
output: 1.98,
|
|
70
|
+
cacheRead: 0.022,
|
|
69
71
|
cacheWrite: 0,
|
|
70
72
|
},
|
|
71
73
|
"deepseek/deepseek-v4-flash": {
|
|
72
|
-
input: 0.
|
|
73
|
-
output: 0.
|
|
74
|
-
cacheRead: 0.
|
|
74
|
+
input: 0.22,
|
|
75
|
+
output: 0.66,
|
|
76
|
+
cacheRead: 0.007,
|
|
77
|
+
cacheWrite: 0,
|
|
78
|
+
},
|
|
79
|
+
"deepseek/deepseek-v4-flash-vision-exp": {
|
|
80
|
+
input: 0.22,
|
|
81
|
+
output: 0.66,
|
|
82
|
+
cacheRead: 0.007,
|
|
75
83
|
cacheWrite: 0,
|
|
76
84
|
},
|
|
77
85
|
"Qwen/Qwen3.8-Max": { input: 2, output: 6, cacheRead: 0.25, cacheWrite: 2.5 },
|
|
86
|
+
"Qwen/Qwen3.8-27B": { input: 0.4, output: 3, cacheRead: 0.04, cacheWrite: 0 },
|
|
78
87
|
"Qwen/Qwen3.7-Max": { input: 2.5, output: 7.5, cacheRead: 0.5, cacheWrite: 3.13 },
|
|
79
88
|
"Qwen/Qwen3.7-Plus": {
|
|
80
89
|
input: 0.4,
|
|
@@ -140,6 +149,13 @@ export const MODEL_COSTS: Readonly<Record<string, CommandCodeModelCost>> = {
|
|
|
140
149
|
cacheWrite: 0,
|
|
141
150
|
},
|
|
142
151
|
"meta/muse-spark-1.1": { input: 1.25, output: 4.25, cacheRead: 0.15, cacheWrite: 0 },
|
|
152
|
+
"meta/muse-spark-1.2": { input: 1.25, output: 4.25, cacheRead: 0.15, cacheWrite: 0 },
|
|
153
|
+
"meta/muse-spark-1.2-contributor": {
|
|
154
|
+
input: 0.1,
|
|
155
|
+
output: 0.2,
|
|
156
|
+
cacheRead: 0.002,
|
|
157
|
+
cacheWrite: 0,
|
|
158
|
+
},
|
|
143
159
|
|
|
144
160
|
// Anthropic
|
|
145
161
|
// Introductory pricing through 2026-08-31.
|
|
@@ -158,43 +174,20 @@ export const MODEL_COSTS: Readonly<Record<string, CommandCodeModelCost>> = {
|
|
|
158
174
|
|
|
159
175
|
// OpenAI
|
|
160
176
|
"gpt-5.6-sol": { input: 5, output: 30, cacheRead: 0.5, cacheWrite: 6.25 },
|
|
161
|
-
|
|
162
|
-
"gpt-5.6-
|
|
163
|
-
input: 1,
|
|
164
|
-
output: 6,
|
|
165
|
-
cacheRead: 0.1,
|
|
166
|
-
cacheWrite: 1.25,
|
|
167
|
-
tiers: [
|
|
168
|
-
{
|
|
169
|
-
inputTokensAbove: 272_000,
|
|
170
|
-
input: 2,
|
|
171
|
-
output: 9,
|
|
172
|
-
cacheRead: 0.2,
|
|
173
|
-
cacheWrite: 2.5,
|
|
174
|
-
},
|
|
175
|
-
],
|
|
176
|
-
},
|
|
177
|
-
"gpt-5.6-luna": {
|
|
178
|
-
input: 0.1,
|
|
179
|
-
output: 0.6,
|
|
180
|
-
cacheRead: 0.01,
|
|
181
|
-
cacheWrite: 0.125,
|
|
182
|
-
tiers: [
|
|
183
|
-
{
|
|
184
|
-
inputTokensAbove: 272_000,
|
|
185
|
-
input: 0.2,
|
|
186
|
-
output: 0.9,
|
|
187
|
-
cacheRead: 0.02,
|
|
188
|
-
cacheWrite: 0.25,
|
|
189
|
-
},
|
|
190
|
-
],
|
|
191
|
-
},
|
|
177
|
+
"gpt-5.6-terra": { input: 2, output: 12, cacheRead: 0.2, cacheWrite: 2.5 },
|
|
178
|
+
"gpt-5.6-luna": { input: 0.2, output: 1.2, cacheRead: 0.02, cacheWrite: 0.25 },
|
|
192
179
|
"gpt-5.5": { input: 5, output: 30, cacheRead: 0.5, cacheWrite: 0 },
|
|
193
180
|
"gpt-5.4": { input: 2.5, output: 15, cacheRead: 0.25, cacheWrite: 0 },
|
|
194
181
|
"gpt-5.3-codex": { input: 2, output: 8, cacheRead: 0.5, cacheWrite: 0 },
|
|
195
182
|
"gpt-5.4-mini": { input: 0.75, output: 4.5, cacheRead: 0.075, cacheWrite: 0 },
|
|
196
183
|
|
|
197
184
|
// Google and xAI
|
|
185
|
+
"google/gemini-3.7-flash": {
|
|
186
|
+
input: 0.75,
|
|
187
|
+
output: 3.75,
|
|
188
|
+
cacheRead: 0.075,
|
|
189
|
+
cacheWrite: 0.04167,
|
|
190
|
+
},
|
|
198
191
|
"google/gemini-3.6-flash": { input: 1.5, output: 7.5, cacheRead: 0.15, cacheWrite: 0 },
|
|
199
192
|
"google/gemini-3.5-flash": { input: 1.5, output: 9, cacheRead: 0.15, cacheWrite: 0 },
|
|
200
193
|
"google/gemini-3.5-flash-lite": {
|
|
@@ -210,17 +203,32 @@ export const MODEL_COSTS: Readonly<Record<string, CommandCodeModelCost>> = {
|
|
|
210
203
|
cacheWrite: 0,
|
|
211
204
|
},
|
|
212
205
|
"xai/grok-4.5": { input: 2, output: 6, cacheRead: 0.5, cacheWrite: 0 },
|
|
206
|
+
"xai/grok-4.6": {
|
|
207
|
+
input: 2,
|
|
208
|
+
output: 6,
|
|
209
|
+
cacheRead: 0.5,
|
|
210
|
+
cacheWrite: 0,
|
|
211
|
+
tiers: [
|
|
212
|
+
{
|
|
213
|
+
inputTokensAbove: 200_000,
|
|
214
|
+
input: 4,
|
|
215
|
+
output: 12,
|
|
216
|
+
cacheRead: 1,
|
|
217
|
+
cacheWrite: 0,
|
|
218
|
+
},
|
|
219
|
+
],
|
|
220
|
+
},
|
|
213
221
|
}
|
|
214
222
|
|
|
215
223
|
export const TEMPORARY_PRICING: readonly TemporaryPricing[] = [
|
|
216
|
-
{
|
|
217
|
-
models: ["gpt-5.6-terra", "gpt-5.6-luna"],
|
|
218
|
-
expiresOn: "2026-08-14",
|
|
219
|
-
description: "50% promotional rates",
|
|
220
|
-
},
|
|
221
224
|
{
|
|
222
225
|
models: ["claude-sonnet-5"],
|
|
223
226
|
expiresOn: "2026-08-31",
|
|
224
227
|
description: "introductory pricing",
|
|
225
228
|
},
|
|
229
|
+
{
|
|
230
|
+
models: ["google/gemini-3.7-flash"],
|
|
231
|
+
expiresOn: "2026-12-31",
|
|
232
|
+
description: "50% promotional pricing",
|
|
233
|
+
},
|
|
226
234
|
]
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { getConfiguredApiKey } from "./api-key.ts"
|
|
2
|
+
import { pickCommandCodeApiKey } from "./converters.ts"
|
|
3
|
+
import { fetchCommandCodeQuota, redactValue } from "./quota.ts"
|
|
4
|
+
import { formatQuota } from "./quota-format.ts"
|
|
5
|
+
|
|
6
|
+
export interface QuotaCommandContext {
|
|
7
|
+
waitForIdle?: () => Promise<void>
|
|
8
|
+
modelRegistry?: {
|
|
9
|
+
getApiKeyForProvider?: (provider: string) => Promise<string | undefined>
|
|
10
|
+
}
|
|
11
|
+
ui: {
|
|
12
|
+
notify(message: string, type?: "info" | "warning" | "error"): void
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface QuotaCommandApi {
|
|
17
|
+
registerCommand(
|
|
18
|
+
name: string,
|
|
19
|
+
options: {
|
|
20
|
+
description: string
|
|
21
|
+
handler: (args: string, ctx: QuotaCommandContext) => Promise<void>
|
|
22
|
+
},
|
|
23
|
+
): void
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface RegisterQuotaCommandOptions {
|
|
27
|
+
apiBase: string
|
|
28
|
+
headers?: Record<string, string>
|
|
29
|
+
getConfiguredKey?: () => string | undefined
|
|
30
|
+
fetchQuota?: typeof fetchCommandCodeQuota
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function registerCommandCodeQuota(
|
|
34
|
+
pi: QuotaCommandApi,
|
|
35
|
+
options: RegisterQuotaCommandOptions,
|
|
36
|
+
): void {
|
|
37
|
+
const getConfiguredKey = options.getConfiguredKey ?? getConfiguredApiKey
|
|
38
|
+
const fetchQuota = options.fetchQuota ?? fetchCommandCodeQuota
|
|
39
|
+
|
|
40
|
+
pi.registerCommand("commandcode-quota", {
|
|
41
|
+
description: "Show Command Code account usage and quota",
|
|
42
|
+
handler: async (_args, ctx) => {
|
|
43
|
+
await ctx.waitForIdle?.()
|
|
44
|
+
const registryKey = await ctx.modelRegistry?.getApiKeyForProvider?.("commandcode")
|
|
45
|
+
const apiKey = pickCommandCodeApiKey(registryKey, getConfiguredKey())
|
|
46
|
+
if (!apiKey) {
|
|
47
|
+
ctx.ui.notify(
|
|
48
|
+
"Command Code quota requires an API key. Run /login and select Command Code, or set COMMAND_CODE_API_KEY.",
|
|
49
|
+
"warning",
|
|
50
|
+
)
|
|
51
|
+
return
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const result = await fetchQuota({
|
|
55
|
+
apiKey,
|
|
56
|
+
baseUrl: options.apiBase,
|
|
57
|
+
extraHeaders: options.headers,
|
|
58
|
+
})
|
|
59
|
+
if (!result.ok) {
|
|
60
|
+
ctx.ui.notify(redactValue(result.error.message), "error")
|
|
61
|
+
return
|
|
62
|
+
}
|
|
63
|
+
ctx.ui.notify(formatQuota(result.quota), "info")
|
|
64
|
+
},
|
|
65
|
+
})
|
|
66
|
+
}
|