@brainervirus/opencode-commandcode 0.9.0 → 0.10.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brainervirus/opencode-commandcode",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "description": "Command Code API provider for opencode — use Claude, GPT, Gemini, DeepSeek, Qwen, Kimi, GLM, MiniMax, and Step models via Command Code",
5
5
  "keywords": [
6
6
  "ai",
@@ -66,7 +66,7 @@
66
66
  "test:integration": "bun test tests/integration/",
67
67
  "test:all": "bun test",
68
68
  "typecheck": "tsc --noEmit",
69
- "prepack": "bun run scripts/verify-manifest-version.ts",
69
+ "prepack": "bun run build && bun run scripts/verify-manifest-version.ts",
70
70
  "verify:release-candidate": "bun run scripts/verify-release-candidate.ts",
71
71
  "generate-readme": "bun run scripts/generate-readme.ts",
72
72
  "sync": "bun run scripts/sync-models.ts",
package/plugin.ts CHANGED
@@ -289,7 +289,7 @@ export async function server() {
289
289
  };
290
290
  }
291
291
 
292
- /** V2 setup: provider inventory + models through transforms. Auth stays V1-only for now. */
292
+ /** V2 setup: provider inventory, models, and API-key integration through transforms. */
293
293
  async function setup(ctx: any): Promise<void> {
294
294
  const pluginCfg = loadPluginConfig();
295
295
  const debug = pluginCfg.debugStartupLogs === true;
@@ -304,11 +304,12 @@ async function setup(ctx: any): Promise<void> {
304
304
  info: {
305
305
  id: "commandcode",
306
306
  name: "Command Code",
307
- activation: "enabled",
307
+ activation: "auto",
308
+ integrationID: "commandcode",
309
+ env: ["COMMANDCODE_API_KEY"],
308
310
  package: `aisdk:${PROVIDER_SDK_NPM}`,
309
311
  settings: {
310
312
  baseURL: PROVIDER_API_BASE_URL,
311
- apiKey: "{env:COMMANDCODE_API_KEY}",
312
313
  },
313
314
  },
314
315
  models: v2models,
@@ -317,14 +318,27 @@ async function setup(ctx: any): Promise<void> {
317
318
  }
318
319
  editor.update("commandcode", (provider: any) => {
319
320
  provider.name = provider.name ?? "Command Code";
321
+ provider.activation = provider.activation ?? "auto";
322
+ provider.integrationID = provider.integrationID ?? "commandcode";
323
+ provider.env = provider.env ?? ["COMMANDCODE_API_KEY"];
320
324
  provider.settings = provider.settings ?? {};
321
325
  if (typeof provider.settings === "object") {
322
326
  if (!provider.settings.baseURL) provider.settings.baseURL = PROVIDER_API_BASE_URL;
323
- if (!provider.settings.apiKey) provider.settings.apiKey = "{env:COMMANDCODE_API_KEY}";
324
327
  }
325
328
  });
326
329
  editor.models.set("commandcode", v2models);
327
330
  });
331
+
332
+ await ctx.integration.transform((editor: any) => {
333
+ editor.method.update({
334
+ integrationID: "commandcode",
335
+ method: { type: "key", label: "API Key" },
336
+ });
337
+ editor.method.update({
338
+ integrationID: "commandcode",
339
+ method: { type: "env", names: ["COMMANDCODE_API_KEY"] },
340
+ });
341
+ });
328
342
  }
329
343
 
330
344
  const definition = { id: "commandcode", setup };
package/src/catalog.ts CHANGED
@@ -456,6 +456,7 @@ export function buildCostMap(costs: Record<string, CostEntry[]>): Map<string, Co
456
456
  export function buildModelEntry(
457
457
  entry: SnEntry,
458
458
  costMap: Map<string, CostEntry>,
459
+ vendorContextLength?: number,
459
460
  ): ModelEntry | null {
460
461
  const provider = entry.provider || "unknown";
461
462
  const tier = TIER_MAP[provider] ?? "open-source";
@@ -475,8 +476,12 @@ export function buildModelEntry(
475
476
  }
476
477
 
477
478
  const fallback = FALLBACK_LIMITS[entry.id];
479
+ const context = entry.contextWindow ?? fallback?.context ?? 200000;
478
480
  const limit = {
479
- context: entry.contextWindow ?? fallback?.context ?? 200000,
481
+ context:
482
+ entry.contextWindow === undefined && vendorContextLength !== undefined
483
+ ? Math.min(context, vendorContextLength)
484
+ : context,
480
485
  output: entry.maxOutputTokens ?? fallback?.output ?? 65536,
481
486
  };
482
487
 
@@ -535,7 +540,10 @@ export function sortModelEntries(entries: ModelEntry[]): ModelEntry[] {
535
540
  });
536
541
  }
537
542
 
538
- export function loadCatalogFromBundle(source: string): ModelEntry[] {
543
+ export function loadCatalogFromBundle(
544
+ source: string,
545
+ vendorContextLengths?: ReadonlyMap<string, number>,
546
+ ): ModelEntry[] {
539
547
  const models = extractModelCatalog(source);
540
548
  let costMap = new Map<string, CostEntry>();
541
549
  try {
@@ -547,13 +555,21 @@ export function loadCatalogFromBundle(source: string): ModelEntry[] {
547
555
  const entries: ModelEntry[] = [];
548
556
  for (const model of Object.values(models)) {
549
557
  if (!model || typeof model !== "object" || typeof model.id !== "string") continue;
550
- const entry = buildModelEntry(model, costMap);
558
+ const entry = buildModelEntry(
559
+ model,
560
+ costMap,
561
+ vendorContextLengths?.get(model.id.toLowerCase()),
562
+ );
551
563
  if (entry) entries.push(entry);
552
564
  }
553
565
 
554
566
  for (const extra of HARDCODED_EXTRAS) {
555
567
  if (!entries.some((e) => e.id === extra.id)) {
556
- const entry = buildModelEntry(extra, costMap);
568
+ const entry = buildModelEntry(
569
+ extra,
570
+ costMap,
571
+ vendorContextLengths?.get(extra.id.toLowerCase()),
572
+ );
557
573
  if (entry) entries.push(entry);
558
574
  }
559
575
  }
@@ -718,6 +734,7 @@ export function resolveCommandCodePackage(
718
734
  export function loadCatalogFromLocalCommandCodeResult(
719
735
  options?: {
720
736
  packagePath?: string;
737
+ vendorContextLengths?: ReadonlyMap<string, number>;
721
738
  },
722
739
  deps: EnvDeps = liveEnv,
723
740
  ): LoadResult<LocalCatalogResult | null> {
@@ -734,7 +751,7 @@ export function loadCatalogFromLocalCommandCodeResult(
734
751
  }
735
752
  let models: ModelEntry[];
736
753
  try {
737
- models = loadCatalogFromBundle(source);
754
+ models = loadCatalogFromBundle(source, options?.vendorContextLengths);
738
755
  } catch (error) {
739
756
  return errResult(`local command-code catalog failed to evaluate: ${causeMessage(error)}`);
740
757
  }
@@ -753,6 +770,7 @@ export function loadCatalogFromLocalCommandCodeResult(
753
770
  /** Compat wrapper: value-or-null for callers that only need fail-open. */
754
771
  export function loadCatalogFromLocalCommandCode(options?: {
755
772
  packagePath?: string;
773
+ vendorContextLengths?: ReadonlyMap<string, number>;
756
774
  }): LocalCatalogResult | null {
757
775
  const result = loadCatalogFromLocalCommandCodeResult(options);
758
776
  return result.ok ? result.value : null;
@@ -765,14 +783,49 @@ export function toConfigKey(id: string): string {
765
783
  return short.toLowerCase();
766
784
  }
767
785
 
786
+ export function usesAnthropicMessagesApi(id: string): boolean {
787
+ return /(?:^|[/:])claude-/i.test(id);
788
+ }
789
+
790
+ export type ModelApi = "chat" | "responses" | "messages";
791
+
792
+ export function modelApi(entry: Pick<ModelEntry, "id" | "supported_endpoints">): ModelApi {
793
+ const endpoints = entry.supported_endpoints;
794
+ const supports = (route: string) =>
795
+ endpoints?.some((endpoint) => {
796
+ const path = (endpoint.split(/[?#]/, 1)[0] ?? "").replace(/\/+$/, "");
797
+ return path === route || path.endsWith(`/${route}`);
798
+ }) ?? false;
799
+
800
+ if (supports("responses")) return "responses";
801
+ if (supports("messages")) return "messages";
802
+ if (supports("chat/completions")) return "chat";
803
+ return usesAnthropicMessagesApi(entry.id) ? "messages" : "chat";
804
+ }
805
+
768
806
  export function generateOpencodeModels(entries: ModelEntry[]): Record<string, unknown> {
769
807
  const models: Record<string, unknown> = {};
770
808
  for (const entry of entries) {
771
809
  // Map key = short UI id; `id` on the model = Command Code wire id (same split as V2 modelID).
772
810
  const key = toConfigKey(entry.id);
773
- const costObj: Record<string, number> = { input: entry.cost.input, output: entry.cost.output };
811
+ const costObj: Record<string, unknown> = { input: entry.cost.input, output: entry.cost.output };
774
812
  if (entry.cost.cache_read !== undefined) costObj.cache_read = entry.cost.cache_read;
775
813
  if (entry.cost.cache_write !== undefined) costObj.cache_write = entry.cost.cache_write;
814
+ const contextOver200k =
815
+ entry.cost.context_over_200k ??
816
+ entry.cost.tiers?.find((tier) => tier.tier.type === "context" && tier.tier.size === 200000);
817
+ if (contextOver200k) {
818
+ costObj.context_over_200k = {
819
+ input: contextOver200k.input,
820
+ output: contextOver200k.output,
821
+ ...(contextOver200k.cache_read !== undefined
822
+ ? { cache_read: contextOver200k.cache_read }
823
+ : {}),
824
+ ...(contextOver200k.cache_write !== undefined
825
+ ? { cache_write: contextOver200k.cache_write }
826
+ : {}),
827
+ };
828
+ }
776
829
 
777
830
  const model: Record<string, unknown> = {
778
831
  id: entry.id,
@@ -783,8 +836,19 @@ export function generateOpencodeModels(entries: ModelEntry[]): Record<string, un
783
836
  modalities: entry.modalities ?? { input: ["text"], output: ["text"] },
784
837
  cost: costObj,
785
838
  limit: entry.limit,
839
+ status: entry.status ?? "active",
786
840
  };
787
841
 
842
+ if (entry.family !== undefined) model.family = entry.family;
843
+ if (entry.release_date !== undefined) model.release_date = entry.release_date;
844
+
845
+ const api = modelApi(entry);
846
+ if (api === "responses") {
847
+ model.provider = { npm: "@ai-sdk/openai" };
848
+ } else if (api === "messages") {
849
+ model.provider = { npm: "@ai-sdk/anthropic" };
850
+ }
851
+
788
852
  if (entry.reasoningEfforts && entry.reasoningEfforts.length > 0) {
789
853
  model.reasoningEfforts = entry.reasoningEfforts;
790
854
  const variants: Record<string, Record<string, unknown>> = {};
@@ -801,6 +865,12 @@ export function generateOpencodeModels(entries: ModelEntry[]): Record<string, un
801
865
 
802
866
  export const MODELS_API_URL = "https://api.commandcode.ai/provider/v1/models";
803
867
 
868
+ export type ProviderModelMetadata = {
869
+ id: string;
870
+ context_length?: number;
871
+ supported_endpoints?: string[];
872
+ };
873
+
804
874
  export interface FilteredCatalog<T extends { id: string }> {
805
875
  retained: T[];
806
876
  unavailable: string[];
@@ -808,12 +878,17 @@ export interface FilteredCatalog<T extends { id: string }> {
808
878
 
809
879
  /** Validate the OpenAI-style `{ object: "list", data: [{ id }] }` availability payload. */
810
880
  export function parseAvailabilityIds(payload: unknown): string[] {
881
+ return parseAvailabilityModels(payload).map((model) => model.id);
882
+ }
883
+
884
+ /** Parse the vendor model inventory, retaining its context limit when present. */
885
+ export function parseAvailabilityModels(payload: unknown): ProviderModelMetadata[] {
811
886
  const parsed = AvailabilityPayloadSchema.safeParse(payload);
812
887
  if (!parsed.success) {
813
888
  const detail = parsed.error.issues.map((issue) => issue.message).join("; ");
814
889
  throw new Error(`invalid availability response: ${detail}`);
815
890
  }
816
- return parsed.data.data.map((item) => item.id);
891
+ return parsed.data.data;
817
892
  }
818
893
 
819
894
  /** Retain only candidates whose exact ID is callable; collect sorted excluded IDs. */
@@ -4,20 +4,49 @@ export const MODELS_DEV_URL = "https://models.dev/api.json";
4
4
  export const FREE_COST = { input: 0, output: 0 } as const;
5
5
  export const TEXT_ONLY_MODALITIES = { input: ["text"], output: ["text"] } as const;
6
6
 
7
+ export type ModelsDevPrice = {
8
+ input: number;
9
+ output: number;
10
+ cache_read?: number;
11
+ cache_write?: number;
12
+ };
13
+
14
+ export type ModelsDevContextTier = ModelsDevPrice & {
15
+ tier: { type: "context"; size: number };
16
+ };
17
+
18
+ export type ModelsDevCost = ModelsDevPrice & {
19
+ context_over_200k?: ModelsDevPrice;
20
+ tiers?: ModelsDevContextTier[];
21
+ };
22
+
7
23
  export type ModelsDevRow = {
8
24
  id: string;
9
25
  name: string;
10
- cost: { input: number; output: number; cache_read?: number; cache_write?: number };
26
+ cost?: ModelsDevCost;
11
27
  attachment?: boolean;
12
28
  modalities?: { input: string[]; output: string[] };
29
+ family?: string;
30
+ release_date?: string;
31
+ status?: "beta" | "deprecated";
32
+ limit?: { input?: number };
13
33
  };
14
34
 
35
+ type ModelsDevPriceInput = Partial<ModelsDevPrice>;
36
+
15
37
  type ModelsDevModel = {
16
38
  id?: string;
17
39
  name?: string;
18
- cost?: { input?: number; output?: number; cache_read?: number; cache_write?: number };
40
+ cost?: ModelsDevPriceInput & {
41
+ context_over_200k?: ModelsDevPriceInput;
42
+ tiers?: Array<ModelsDevPriceInput & { tier?: { type?: string; size?: number } }>;
43
+ };
19
44
  attachment?: boolean;
20
45
  modalities?: { input?: string[]; output?: string[] };
46
+ family?: string;
47
+ release_date?: string;
48
+ status?: string;
49
+ limit?: { input?: number };
21
50
  };
22
51
 
23
52
  type ModelsDevProvider = { models?: Record<string, ModelsDevModel> };
@@ -35,19 +64,32 @@ export function isFreeSku(model: { id: string; name: string }): boolean {
35
64
  export function parseModelsDev(json: string): ModelsDevRow[] {
36
65
  const data = JSON.parse(json) as Record<string, ModelsDevProvider>;
37
66
  const rows: ModelsDevRow[] = [];
38
- const seen = new Set<string>();
39
67
  for (const provider of Object.keys(data).sort()) {
40
68
  const models = data[provider]?.models ?? {};
41
69
  for (const model of Object.values(models)) {
42
- if (!model?.id || model.cost?.input === undefined || model.cost?.output === undefined)
43
- continue;
44
- const key = model.id.toLowerCase();
45
- if (seen.has(key)) continue;
46
- seen.add(key);
47
- const cost: ModelsDevRow["cost"] = { input: model.cost.input, output: model.cost.output };
48
- if (model.cost.cache_read !== undefined) cost.cache_read = model.cost.cache_read;
49
- if (model.cost.cache_write !== undefined) cost.cache_write = model.cost.cache_write;
50
- const row: ModelsDevRow = { id: model.id, name: model.name ?? model.id, cost };
70
+ if (!model?.id) continue;
71
+ const row: ModelsDevRow = { id: model.id, name: model.name ?? model.id };
72
+ const baseCost = parsePrice(model.cost);
73
+ if (baseCost) {
74
+ const cost: ModelsDevCost = baseCost;
75
+ const over = parsePrice(model.cost?.context_over_200k);
76
+ if (over) cost.context_over_200k = over;
77
+ const tiers = model.cost?.tiers?.flatMap((item) => {
78
+ if (
79
+ item.tier?.type !== "context" ||
80
+ !Number.isInteger(item.tier.size) ||
81
+ !item.tier.size
82
+ ) {
83
+ return [];
84
+ }
85
+ const price = parsePrice(item);
86
+ return price
87
+ ? [{ ...price, tier: { type: "context" as const, size: item.tier.size! } }]
88
+ : [];
89
+ });
90
+ if (tiers?.length) cost.tiers = tiers;
91
+ row.cost = cost;
92
+ }
51
93
  if (typeof model.attachment === "boolean") row.attachment = model.attachment;
52
94
  const input = model.modalities?.input?.filter((x) => typeof x === "string");
53
95
  const output = model.modalities?.output?.filter((x) => typeof x === "string");
@@ -57,16 +99,62 @@ export function parseModelsDev(json: string): ModelsDevRow[] {
57
99
  output: output?.length ? output : [...TEXT_ONLY_MODALITIES.output],
58
100
  };
59
101
  }
102
+ if (typeof model.family === "string" && model.family.trim()) row.family = model.family;
103
+ if (
104
+ typeof model.release_date === "string" &&
105
+ /^\d{4}-\d{2}-\d{2}$/.test(model.release_date)
106
+ ) {
107
+ const date = new Date(`${model.release_date}T00:00:00.000Z`);
108
+ if (!Number.isNaN(date.valueOf()) && date.toISOString().startsWith(model.release_date)) {
109
+ row.release_date = model.release_date;
110
+ }
111
+ }
112
+ if (model.status === "beta" || model.status === "deprecated") row.status = model.status;
113
+ if (
114
+ typeof model.limit?.input === "number" &&
115
+ Number.isInteger(model.limit.input) &&
116
+ model.limit.input > 0
117
+ ) {
118
+ row.limit = { input: model.limit.input };
119
+ }
60
120
  rows.push(row);
61
121
  }
62
122
  }
63
123
  return rows;
64
124
  }
65
125
 
126
+ function parsePrice(value: ModelsDevPriceInput | undefined): ModelsDevPrice | undefined {
127
+ if (
128
+ !value ||
129
+ typeof value.input !== "number" ||
130
+ !Number.isFinite(value.input) ||
131
+ typeof value.output !== "number" ||
132
+ !Number.isFinite(value.output)
133
+ ) {
134
+ return undefined;
135
+ }
136
+ const price: ModelsDevPrice = { input: value.input, output: value.output };
137
+ if (typeof value.cache_read === "number" && Number.isFinite(value.cache_read)) {
138
+ price.cache_read = value.cache_read;
139
+ }
140
+ if (typeof value.cache_write === "number" && Number.isFinite(value.cache_write)) {
141
+ price.cache_write = value.cache_write;
142
+ }
143
+ return price;
144
+ }
145
+
66
146
  function indexRows(rows: ModelsDevRow[]) {
67
147
  const byId = new Map<string, ModelsDevRow>();
68
148
  const bySegment = new Map<string, ModelsDevRow>();
69
149
  const byName = new Map<string, ModelsDevRow>();
150
+ const tiersById = new Map<string, ModelsDevRow[]>();
151
+ const tiersBySegment = new Map<string, ModelsDevRow[]>();
152
+ const tiersByName = new Map<string, ModelsDevRow[]>();
153
+ const add = (index: Map<string, ModelsDevRow[]>, key: string, row: ModelsDevRow) => {
154
+ const matches = index.get(key);
155
+ if (matches) matches.push(row);
156
+ else index.set(key, [row]);
157
+ };
70
158
  for (const row of rows) {
71
159
  const idKey = row.id.toLowerCase();
72
160
  if (!byId.has(idKey)) byId.set(idKey, row);
@@ -74,8 +162,13 @@ function indexRows(rows: ModelsDevRow[]) {
74
162
  if (!bySegment.has(segment)) bySegment.set(segment, row);
75
163
  const nameKey = row.name.toLowerCase();
76
164
  if (!byName.has(nameKey)) byName.set(nameKey, row);
165
+ if (row.cost?.tiers?.length || row.cost?.context_over_200k) {
166
+ add(tiersById, idKey, row);
167
+ add(tiersBySegment, segment, row);
168
+ add(tiersByName, nameKey, row);
169
+ }
77
170
  }
78
- return { byId, bySegment, byName };
171
+ return { byId, bySegment, byName, tiersById, tiersBySegment, tiersByName };
79
172
  }
80
173
 
81
174
  function findRow(model: ModelEntry, index: ReturnType<typeof indexRows>): ModelsDevRow | undefined {
@@ -138,6 +231,60 @@ export function applyModelsDevModalities(models: ModelEntry[], rows: ModelsDevRo
138
231
  return filled;
139
232
  }
140
233
 
234
+ export function applyModelsDevMetadata(models: ModelEntry[], rows: ModelsDevRow[]): number {
235
+ const index = indexRows(rows);
236
+ let filled = 0;
237
+ for (const model of models) {
238
+ const row = findRow(model, index);
239
+ if (!row) continue;
240
+ let changed = false;
241
+ if (row.family !== undefined) {
242
+ model.family = row.family;
243
+ changed = true;
244
+ }
245
+ if (row.release_date !== undefined) {
246
+ model.release_date = row.release_date;
247
+ changed = true;
248
+ }
249
+ if (row.status !== undefined) {
250
+ model.status = row.status;
251
+ changed = true;
252
+ }
253
+ if (row.limit?.input !== undefined) {
254
+ model.limit.input = row.limit.input;
255
+ changed = true;
256
+ }
257
+ if (changed) filled++;
258
+ }
259
+ return filled;
260
+ }
261
+
262
+ export function applyModelsDevCostTiers(models: ModelEntry[], rows: ModelsDevRow[]): number {
263
+ const index = indexRows(rows);
264
+ let filled = 0;
265
+ for (const model of models) {
266
+ const sameBasePrice = (row: ModelsDevRow) =>
267
+ row.cost?.input === model.cost.input && row.cost.output === model.cost.output;
268
+ const costRow =
269
+ index.tiersById.get(model.id.toLowerCase())?.find(sameBasePrice) ??
270
+ index.tiersBySegment.get(lastSegment(model.id).toLowerCase())?.find(sameBasePrice) ??
271
+ index.tiersByName.get(model.name.toLowerCase())?.find(sameBasePrice);
272
+ const cost = costRow?.cost;
273
+ if (!cost) continue;
274
+ let changed = false;
275
+ if (cost.tiers?.length) {
276
+ model.cost.tiers = cost.tiers.map((tier) => ({ ...tier, tier: { ...tier.tier } }));
277
+ changed = true;
278
+ }
279
+ if (cost.context_over_200k) {
280
+ model.cost.context_over_200k = { ...cost.context_over_200k };
281
+ changed = true;
282
+ }
283
+ if (changed) filled++;
284
+ }
285
+ return filled;
286
+ }
287
+
141
288
  export function applyModelsDevCosts(
142
289
  models: ModelEntry[],
143
290
  rows: ModelsDevRow[],
@@ -149,7 +296,7 @@ export function applyModelsDevCosts(
149
296
  for (const model of models) {
150
297
  if (skipIds.has(model.id) || isFreeSku(model)) continue;
151
298
  const row = findRow(model, index);
152
- if (!row) continue;
299
+ if (!row?.cost) continue;
153
300
  model.cost = { input: row.cost.input, output: row.cost.output };
154
301
  if (row.cost.cache_read !== undefined) model.cost.cache_read = row.cost.cache_read;
155
302
  if (row.cost.cache_write !== undefined) model.cost.cache_write = row.cost.cache_write;
@@ -1,7 +1,6 @@
1
1
  export type CatalogSyncDecision = {
2
2
  extract: boolean;
3
3
  publishRetry: boolean;
4
- exit: boolean;
5
4
  };
6
5
 
7
6
  export type PublishDecision = "publish" | "skip-no-token" | "skip-already-published";
@@ -15,10 +14,10 @@ export function decideCatalogSync(input: {
15
14
  }): CatalogSyncDecision {
16
15
  const published = input.publishedPluginVersions.includes(input.pluginVersion);
17
16
  if (input.force || input.latestCommandCodeVersion !== input.bundledCommandCodeVersion) {
18
- return { extract: true, publishRetry: false, exit: false };
17
+ return { extract: true, publishRetry: false };
19
18
  }
20
- if (!published) return { extract: false, publishRetry: true, exit: false };
21
- return { extract: false, publishRetry: false, exit: true };
19
+ if (!published) return { extract: false, publishRetry: true };
20
+ return { extract: true, publishRetry: false };
22
21
  }
23
22
 
24
23
  export function decidePublish(input: {
package/src/schemas.ts CHANGED
@@ -13,11 +13,35 @@ export const ModelEntrySchema = z.strictObject({
13
13
  output: z.number(),
14
14
  cache_read: z.number().optional(),
15
15
  cache_write: z.number().optional(),
16
+ context_over_200k: z
17
+ .strictObject({
18
+ input: z.number(),
19
+ output: z.number(),
20
+ cache_read: z.number().optional(),
21
+ cache_write: z.number().optional(),
22
+ })
23
+ .optional(),
24
+ tiers: z
25
+ .array(
26
+ z.strictObject({
27
+ input: z.number(),
28
+ output: z.number(),
29
+ cache_read: z.number().optional(),
30
+ cache_write: z.number().optional(),
31
+ tier: z.strictObject({ type: z.literal("context"), size: z.number().int().positive() }),
32
+ }),
33
+ )
34
+ .optional(),
16
35
  }),
17
36
  limit: z.strictObject({
18
37
  context: z.number().int(),
38
+ input: z.number().int().optional(),
19
39
  output: z.number().int(),
20
40
  }),
41
+ family: z.string().min(1).optional(),
42
+ supported_endpoints: z.array(z.string().min(1)).optional(),
43
+ release_date: z.iso.date().optional(),
44
+ status: z.enum(["active", "beta", "deprecated"]).optional(),
21
45
  attachment: z.boolean().optional(),
22
46
  modalities: z
23
47
  .strictObject({
@@ -75,7 +99,15 @@ export const ManifestSchema = z.strictObject({
75
99
  export const AvailabilityPayloadSchema = z
76
100
  .object({
77
101
  object: z.literal("list"),
78
- data: z.array(z.object({ id: z.string().min(1) })).min(1),
102
+ data: z
103
+ .array(
104
+ z.object({
105
+ id: z.string().min(1),
106
+ context_length: z.number().int().positive().optional().catch(undefined),
107
+ supported_endpoints: z.array(z.string().min(1)).optional().catch(undefined),
108
+ }),
109
+ )
110
+ .min(1),
79
111
  })
80
112
  .superRefine((payload, ctx) => {
81
113
  const seen = new Set<string>();
package/src/v2models.ts CHANGED
@@ -1,16 +1,23 @@
1
- import { toConfigKey, type ModelEntry } from "./catalog.js";
1
+ import { modelApi, toConfigKey, type ModelEntry } from "./catalog.js";
2
2
 
3
3
  /** Minimal V2 model shape (structural subset of Model.Info). */
4
4
  export interface V2Model {
5
5
  id: string;
6
6
  modelID: string;
7
7
  providerID: string;
8
+ package?: string;
8
9
  name: string;
10
+ family?: string;
9
11
  capabilities: { tools: boolean; input: string[]; output: string[] };
10
- cost: Array<{ input: number; output: number; cache: { read: number; write: number } }>;
11
- limit: { context: number; output: number };
12
+ cost: Array<{
13
+ input: number;
14
+ output: number;
15
+ cache: { read: number; write: number };
16
+ tier?: { type: "context"; size: number };
17
+ }>;
18
+ limit: { context: number; input?: number; output: number };
12
19
  variants: Array<{ id: string; settings: Record<string, unknown> }>;
13
- status: "active";
20
+ status: "active" | "beta" | "deprecated";
14
21
  enabled: boolean;
15
22
  time: { released: number };
16
23
  }
@@ -32,11 +39,22 @@ export function toV2Model(entry: ModelEntry): V2Model {
32
39
  // UI / OpenCode selection key stays short (commandcode/deepseek-v4.1-flash).
33
40
  // modelID is the Command Code wire id — bare names 400 as unsupported_model.
34
41
  const id = toConfigKey(entry.id);
35
- return {
42
+ const costTiers = [...(entry.cost.tiers ?? [])];
43
+ if (
44
+ entry.cost.context_over_200k &&
45
+ !costTiers.some((tier) => tier.tier.type === "context" && tier.tier.size === 200000)
46
+ ) {
47
+ costTiers.push({
48
+ ...entry.cost.context_over_200k,
49
+ tier: { type: "context", size: 200000 },
50
+ });
51
+ }
52
+ const model: V2Model = {
36
53
  id,
37
54
  modelID: entry.id,
38
55
  providerID: "commandcode",
39
56
  name: entry.name,
57
+ ...(entry.family !== undefined ? { family: entry.family } : {}),
40
58
  capabilities: {
41
59
  tools: entry.tool_call,
42
60
  input: v2Input(entry),
@@ -51,16 +69,32 @@ export function toV2Model(entry: ModelEntry): V2Model {
51
69
  write: entry.cost.cache_write ?? 0,
52
70
  },
53
71
  },
72
+ ...costTiers.map((tier) => ({
73
+ input: tier.input,
74
+ output: tier.output,
75
+ cache: { read: tier.cache_read ?? 0, write: tier.cache_write ?? 0 },
76
+ tier: { ...tier.tier },
77
+ })),
54
78
  ],
55
- limit: { context: entry.limit.context, output: entry.limit.output },
79
+ limit: {
80
+ context: entry.limit.context,
81
+ ...(entry.limit.input !== undefined ? { input: entry.limit.input } : {}),
82
+ output: entry.limit.output,
83
+ },
56
84
  variants: (entry.reasoningEfforts ?? []).map((effort) => ({
57
85
  id: effort,
58
86
  settings: { reasoningEffort: effort },
59
87
  })),
60
- status: "active",
88
+ status: entry.status ?? "active",
61
89
  enabled: true,
62
- time: { released: 0 },
90
+ time: {
91
+ released: entry.release_date ? Date.parse(`${entry.release_date}T00:00:00.000Z`) : 0,
92
+ },
63
93
  };
94
+ const api = modelApi(entry);
95
+ if (api === "responses") model.package = "aisdk:@ai-sdk/openai";
96
+ else if (api === "messages") model.package = "aisdk:@ai-sdk/anthropic";
97
+ return model;
64
98
  }
65
99
 
66
100
  export function generateV2Models(entries: ModelEntry[]): V2Model[] {