@telsoncc/opencode-commandcode 1.2.33 → 1.2.34
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 +6 -222
- package/dist/_version.txt +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +19 -0
- package/dist/manifest.json +28 -0
- package/dist/models.json +3334 -0
- package/dist/plugin-opencode2.d.ts +30 -0
- package/dist/plugin-opencode2.js +127 -0
- package/dist/plugin.d.ts +27 -0
- package/dist/plugin.js +192 -0
- package/dist/src/auth.d.ts +5 -0
- package/dist/src/auth.js +38 -0
- package/dist/src/catalog-break.d.ts +12 -0
- package/dist/src/catalog-break.js +33 -0
- package/dist/src/catalog-release-notes.d.ts +30 -0
- package/dist/src/catalog-release-notes.js +106 -0
- package/dist/src/catalog.d.ts +160 -0
- package/dist/src/catalog.js +786 -0
- package/dist/src/convert.d.ts +71 -0
- package/dist/src/convert.js +154 -0
- package/dist/src/costs-docs.d.ts +13 -0
- package/dist/src/costs-docs.js +170 -0
- package/dist/src/costs-models-dev.d.ts +68 -0
- package/dist/src/costs-models-dev.js +303 -0
- package/dist/src/cut-changelog.d.ts +1 -0
- package/dist/src/cut-changelog.js +43 -0
- package/dist/src/manifest.d.ts +72 -0
- package/dist/src/manifest.js +111 -0
- package/dist/src/model.d.ts +18 -0
- package/dist/src/model.js +138 -0
- package/dist/src/opencode2.d.ts +179 -0
- package/dist/src/opencode2.js +386 -0
- package/dist/src/pack-contract.d.ts +25 -0
- package/dist/src/pack-contract.js +42 -0
- package/dist/src/publish-policy.d.ts +18 -0
- package/dist/src/publish-policy.js +16 -0
- package/dist/src/startup.d.ts +18 -0
- package/dist/src/startup.js +31 -0
- package/dist/src/stream.d.ts +2 -0
- package/dist/src/stream.js +203 -0
- package/manifest.json +1 -1
- package/package.json +12 -7
- package/plugin.ts +14 -3
- package/src/cut-changelog.ts +6 -1
- package/src/opencode2.ts +14 -3
- package/src/pack-contract.ts +51 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { LanguageModelV3CallOptions } from "@ai-sdk/provider";
|
|
2
|
+
type CCMessage = {
|
|
3
|
+
role: "user";
|
|
4
|
+
content: string | unknown[];
|
|
5
|
+
} | {
|
|
6
|
+
role: "assistant";
|
|
7
|
+
content: CCAssistantContent[];
|
|
8
|
+
} | {
|
|
9
|
+
role: "tool";
|
|
10
|
+
content: CCToolResultContent[];
|
|
11
|
+
};
|
|
12
|
+
type CCAssistantContent = {
|
|
13
|
+
type: "text";
|
|
14
|
+
text: string;
|
|
15
|
+
} | {
|
|
16
|
+
type: "reasoning";
|
|
17
|
+
text: string;
|
|
18
|
+
} | {
|
|
19
|
+
type: "tool-call";
|
|
20
|
+
toolCallId: string;
|
|
21
|
+
toolName: string;
|
|
22
|
+
input: unknown;
|
|
23
|
+
};
|
|
24
|
+
type CCToolResultContent = {
|
|
25
|
+
type: "tool-result";
|
|
26
|
+
toolCallId: string;
|
|
27
|
+
toolName: string;
|
|
28
|
+
output: {
|
|
29
|
+
type: "text";
|
|
30
|
+
value: string;
|
|
31
|
+
} | {
|
|
32
|
+
type: "error-text";
|
|
33
|
+
value: string;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
type CCTool = {
|
|
37
|
+
type: "function";
|
|
38
|
+
name: string;
|
|
39
|
+
description?: string;
|
|
40
|
+
input_schema: unknown;
|
|
41
|
+
};
|
|
42
|
+
interface CCRequestEnvelope {
|
|
43
|
+
config: {
|
|
44
|
+
workingDir: string;
|
|
45
|
+
date: string;
|
|
46
|
+
environment: string;
|
|
47
|
+
structure: unknown[];
|
|
48
|
+
isGitRepo: boolean;
|
|
49
|
+
currentBranch: string;
|
|
50
|
+
mainBranch: string;
|
|
51
|
+
gitStatus: string;
|
|
52
|
+
recentCommits: unknown[];
|
|
53
|
+
};
|
|
54
|
+
memory: string;
|
|
55
|
+
taste: string;
|
|
56
|
+
skills: null;
|
|
57
|
+
permissionMode: string;
|
|
58
|
+
params: {
|
|
59
|
+
model: string;
|
|
60
|
+
messages: CCMessage[];
|
|
61
|
+
tools: CCTool[];
|
|
62
|
+
system: string;
|
|
63
|
+
max_tokens: number;
|
|
64
|
+
stream: true;
|
|
65
|
+
temperature?: number;
|
|
66
|
+
top_p?: number;
|
|
67
|
+
top_k?: number;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
export declare function buildRequest(modelId: string, options: LanguageModelV3CallOptions): CCRequestEnvelope;
|
|
71
|
+
export {};
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
function hasType(p, type) {
|
|
2
|
+
return typeof p === "object" && p !== null && p.type === type;
|
|
3
|
+
}
|
|
4
|
+
function isTextPart(p) {
|
|
5
|
+
return hasType(p, "text");
|
|
6
|
+
}
|
|
7
|
+
function isReasoningPart(p) {
|
|
8
|
+
return hasType(p, "reasoning");
|
|
9
|
+
}
|
|
10
|
+
function isToolCallPart(p) {
|
|
11
|
+
return hasType(p, "tool-call");
|
|
12
|
+
}
|
|
13
|
+
function isToolResultPart(p) {
|
|
14
|
+
return hasType(p, "tool-result");
|
|
15
|
+
}
|
|
16
|
+
function extractText(content) {
|
|
17
|
+
if (typeof content === "string")
|
|
18
|
+
return content;
|
|
19
|
+
if (Array.isArray(content)) {
|
|
20
|
+
const textParts = content.filter(isTextPart);
|
|
21
|
+
const nonTextParts = content.filter((p) => !isTextPart(p));
|
|
22
|
+
if (nonTextParts.length > 0 && textParts.length === 0) {
|
|
23
|
+
console.warn(`Command Code provider: dropped ${nonTextParts.length} non-text part(s) in user message`);
|
|
24
|
+
}
|
|
25
|
+
return textParts.map((p) => p.text).join("\n");
|
|
26
|
+
}
|
|
27
|
+
return "";
|
|
28
|
+
}
|
|
29
|
+
function convertToolResultOutput(output) {
|
|
30
|
+
switch (output.type) {
|
|
31
|
+
case "text":
|
|
32
|
+
return { type: "text", value: output.value };
|
|
33
|
+
case "error-text":
|
|
34
|
+
return { type: "error-text", value: output.value };
|
|
35
|
+
case "json":
|
|
36
|
+
return { type: "text", value: JSON.stringify(output.value) };
|
|
37
|
+
case "execution-denied":
|
|
38
|
+
return { type: "error-text", value: output.reason ?? "Execution denied" };
|
|
39
|
+
case "error-json":
|
|
40
|
+
return { type: "error-text", value: JSON.stringify(output.value) };
|
|
41
|
+
case "content":
|
|
42
|
+
return {
|
|
43
|
+
type: "text",
|
|
44
|
+
value: output.value
|
|
45
|
+
.map((v) => ("text" in v ? v.text : JSON.stringify(v)))
|
|
46
|
+
.join("\n"),
|
|
47
|
+
};
|
|
48
|
+
default:
|
|
49
|
+
return { type: "text", value: JSON.stringify(output) };
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function convertMessage(msg) {
|
|
53
|
+
switch (msg.role) {
|
|
54
|
+
case "user": {
|
|
55
|
+
const text = extractText(msg.content);
|
|
56
|
+
return { role: "user", content: text };
|
|
57
|
+
}
|
|
58
|
+
case "assistant": {
|
|
59
|
+
const parts = [];
|
|
60
|
+
for (const part of msg.content) {
|
|
61
|
+
if (isTextPart(part)) {
|
|
62
|
+
parts.push({ type: "text", text: part.text });
|
|
63
|
+
}
|
|
64
|
+
else if (isReasoningPart(part)) {
|
|
65
|
+
parts.push({ type: "reasoning", text: part.text });
|
|
66
|
+
}
|
|
67
|
+
else if (isToolCallPart(part)) {
|
|
68
|
+
parts.push({
|
|
69
|
+
type: "tool-call",
|
|
70
|
+
toolCallId: part.toolCallId,
|
|
71
|
+
toolName: part.toolName,
|
|
72
|
+
input: part.input,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return { role: "assistant", content: parts };
|
|
77
|
+
}
|
|
78
|
+
case "tool": {
|
|
79
|
+
const parts = [];
|
|
80
|
+
for (const part of msg.content) {
|
|
81
|
+
if (isToolResultPart(part)) {
|
|
82
|
+
parts.push({
|
|
83
|
+
type: "tool-result",
|
|
84
|
+
toolCallId: part.toolCallId,
|
|
85
|
+
toolName: part.toolName,
|
|
86
|
+
output: convertToolResultOutput(part.output),
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return { role: "tool", content: parts };
|
|
91
|
+
}
|
|
92
|
+
default:
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function convertTools(tools) {
|
|
97
|
+
if (!tools)
|
|
98
|
+
return [];
|
|
99
|
+
return tools
|
|
100
|
+
.filter((t) => t.type === "function")
|
|
101
|
+
.map((t) => ({
|
|
102
|
+
type: "function",
|
|
103
|
+
name: t.name,
|
|
104
|
+
description: t.description,
|
|
105
|
+
input_schema: t.inputSchema,
|
|
106
|
+
}));
|
|
107
|
+
}
|
|
108
|
+
export function buildRequest(modelId, options) {
|
|
109
|
+
let systemPrompt = "";
|
|
110
|
+
const messages = [];
|
|
111
|
+
for (const msg of options.prompt) {
|
|
112
|
+
if (msg.role === "system") {
|
|
113
|
+
systemPrompt += (systemPrompt ? "\n\n" : "") + msg.content;
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
const converted = convertMessage(msg);
|
|
117
|
+
if (converted)
|
|
118
|
+
messages.push(converted);
|
|
119
|
+
}
|
|
120
|
+
const params = {
|
|
121
|
+
model: modelId,
|
|
122
|
+
messages,
|
|
123
|
+
tools: convertTools(options.tools),
|
|
124
|
+
system: systemPrompt,
|
|
125
|
+
max_tokens: options.maxOutputTokens ?? 16384,
|
|
126
|
+
stream: true,
|
|
127
|
+
};
|
|
128
|
+
if (options.temperature !== undefined)
|
|
129
|
+
params.temperature = options.temperature;
|
|
130
|
+
if (options.topP !== undefined)
|
|
131
|
+
params.top_p = options.topP;
|
|
132
|
+
if (options.topK !== undefined)
|
|
133
|
+
params.top_k = options.topK;
|
|
134
|
+
return {
|
|
135
|
+
config: {
|
|
136
|
+
workingDir: process.cwd() ?? "/",
|
|
137
|
+
date: new Date().toISOString().split("T")[0] ?? "",
|
|
138
|
+
environment: `${process.platform}-${process.arch}`,
|
|
139
|
+
// Stub: opencode does not expose project structure context
|
|
140
|
+
structure: [],
|
|
141
|
+
isGitRepo: false,
|
|
142
|
+
currentBranch: "",
|
|
143
|
+
mainBranch: "",
|
|
144
|
+
gitStatus: "",
|
|
145
|
+
recentCommits: [],
|
|
146
|
+
},
|
|
147
|
+
memory: "",
|
|
148
|
+
// Stub: taste/memory/permissionMode are Command Code CLI features not exposed via provider API
|
|
149
|
+
taste: "",
|
|
150
|
+
skills: null,
|
|
151
|
+
permissionMode: "standard",
|
|
152
|
+
params,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ModelEntry } from "./catalog.js";
|
|
2
|
+
export type DocCostRow = {
|
|
3
|
+
name: string;
|
|
4
|
+
id?: string;
|
|
5
|
+
input: number;
|
|
6
|
+
output: number;
|
|
7
|
+
cache_read?: number;
|
|
8
|
+
cache_write?: number;
|
|
9
|
+
};
|
|
10
|
+
export declare function parseMoneyCell(cell: string): number | undefined;
|
|
11
|
+
export declare function parseModelsTable(markdown: string): DocCostRow[];
|
|
12
|
+
export declare function applyDocCosts(models: ModelEntry[], rows: DocCostRow[], cliIds?: Set<string>, filledIds?: Set<string>): number;
|
|
13
|
+
export declare function fetchOfficialModelsMarkdown(): Promise<string>;
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
export function parseMoneyCell(cell) {
|
|
2
|
+
const trimmed = cell.trim();
|
|
3
|
+
if (!trimmed || trimmed === "—" || trimmed === "-")
|
|
4
|
+
return undefined;
|
|
5
|
+
if (/^free$/i.test(trimmed))
|
|
6
|
+
return 0;
|
|
7
|
+
const amounts = [...trimmed.matchAll(/\$([0-9]+(?:\.[0-9]+)?)/g)].map((m) => Number(m[1]));
|
|
8
|
+
if (amounts.length === 0)
|
|
9
|
+
return undefined;
|
|
10
|
+
return amounts[amounts.length - 1];
|
|
11
|
+
}
|
|
12
|
+
function decodeEntities(text) {
|
|
13
|
+
return text
|
|
14
|
+
.replace(/&/g, "&")
|
|
15
|
+
.replace(/</g, "<")
|
|
16
|
+
.replace(/>/g, ">")
|
|
17
|
+
.replace(/"/g, '"')
|
|
18
|
+
.replace(/'/g, "'")
|
|
19
|
+
.replace(/ /g, " ");
|
|
20
|
+
}
|
|
21
|
+
function stripTags(html) {
|
|
22
|
+
return decodeEntities(html.replace(/<[^>]+>/g, " "))
|
|
23
|
+
.replace(/\s+/g, " ")
|
|
24
|
+
.trim();
|
|
25
|
+
}
|
|
26
|
+
function visibleCellText(innerHtml) {
|
|
27
|
+
const trunc = innerHtml.match(/<span class="truncate[^"]*"[^>]*>([^<]*)<\/span>/i);
|
|
28
|
+
if (trunc?.[1])
|
|
29
|
+
return decodeEntities(trunc[1]).trim();
|
|
30
|
+
return stripTags(innerHtml);
|
|
31
|
+
}
|
|
32
|
+
function headerName(cell) {
|
|
33
|
+
return cell.replace(/↕/g, "").replace(/\s+/g, " ").trim().toLowerCase();
|
|
34
|
+
}
|
|
35
|
+
function colIndex(headers, name) {
|
|
36
|
+
return headers.findIndex((h) => h === name || h.startsWith(`${name} `) || h.startsWith(name));
|
|
37
|
+
}
|
|
38
|
+
function pipeRows(markdown) {
|
|
39
|
+
const rows = [];
|
|
40
|
+
for (const line of markdown.split("\n")) {
|
|
41
|
+
if (!line.includes("|"))
|
|
42
|
+
continue;
|
|
43
|
+
const cells = line
|
|
44
|
+
.split("|")
|
|
45
|
+
.map((c) => c.trim())
|
|
46
|
+
.filter((c, i, arr) => !(i === 0 && c === "") && !(i === arr.length - 1 && c === ""));
|
|
47
|
+
if (cells.length)
|
|
48
|
+
rows.push({ cells });
|
|
49
|
+
}
|
|
50
|
+
return rows;
|
|
51
|
+
}
|
|
52
|
+
function htmlTableRows(html) {
|
|
53
|
+
const rows = [];
|
|
54
|
+
const tables = html.match(/<table[\s\S]*?<\/table>/gi) ?? [];
|
|
55
|
+
for (const table of tables) {
|
|
56
|
+
const trs = table.match(/<tr[\s\S]*?<\/tr>/gi) ?? [];
|
|
57
|
+
for (const tr of trs) {
|
|
58
|
+
const rawCells = [...tr.matchAll(/<t[dh]\b[\s\S]*?<\/t[dh]>/gi)].map((m) => m[0]);
|
|
59
|
+
if (rawCells.length === 0)
|
|
60
|
+
continue;
|
|
61
|
+
const cells = rawCells.map((raw) => {
|
|
62
|
+
const inner = raw.replace(/^<t[dh]\b[^>]*>/i, "").replace(/<\/t[dh]>$/i, "");
|
|
63
|
+
return visibleCellText(inner);
|
|
64
|
+
});
|
|
65
|
+
const href = tr.match(/href="\/models\/([^"?#]+)"/i)?.[1];
|
|
66
|
+
rows.push({ cells, ...(href ? { id: href } : {}) });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return rows;
|
|
70
|
+
}
|
|
71
|
+
function rowsFromGroup(group) {
|
|
72
|
+
if (group.length === 0)
|
|
73
|
+
return [];
|
|
74
|
+
let modelI = 0;
|
|
75
|
+
let inputI = 2;
|
|
76
|
+
let outputI = 3;
|
|
77
|
+
let cacheReadI = 4;
|
|
78
|
+
let cacheWriteI = 5;
|
|
79
|
+
let start = 0;
|
|
80
|
+
const headerIdx = group.findIndex((r) => /^model\b/i.test(headerName(r.cells[0] ?? "")));
|
|
81
|
+
if (headerIdx >= 0) {
|
|
82
|
+
const headers = group[headerIdx].cells.map(headerName);
|
|
83
|
+
const foundInput = colIndex(headers, "input");
|
|
84
|
+
const foundOutput = colIndex(headers, "output");
|
|
85
|
+
if (foundInput >= 0 && foundOutput >= 0) {
|
|
86
|
+
const foundModel = colIndex(headers, "model");
|
|
87
|
+
if (foundModel >= 0)
|
|
88
|
+
modelI = foundModel;
|
|
89
|
+
inputI = foundInput;
|
|
90
|
+
outputI = foundOutput;
|
|
91
|
+
cacheReadI = colIndex(headers, "cache read");
|
|
92
|
+
cacheWriteI = colIndex(headers, "cache write");
|
|
93
|
+
start = headerIdx + 1;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const rows = [];
|
|
97
|
+
for (let i = start; i < group.length; i++) {
|
|
98
|
+
const { cells, id } = group[i];
|
|
99
|
+
if (cells.length < 2)
|
|
100
|
+
continue;
|
|
101
|
+
const first = headerName(cells[0] ?? "");
|
|
102
|
+
if (first === "model" || (cells[0] ?? "").startsWith("---"))
|
|
103
|
+
continue;
|
|
104
|
+
const input = parseMoneyCell(cells[inputI] ?? "");
|
|
105
|
+
const output = parseMoneyCell(cells[outputI] ?? "");
|
|
106
|
+
if (input === undefined || output === undefined)
|
|
107
|
+
continue;
|
|
108
|
+
const name = (cells[modelI] ?? "").trim();
|
|
109
|
+
if (!name)
|
|
110
|
+
continue;
|
|
111
|
+
const row = { name, input, output };
|
|
112
|
+
if (id)
|
|
113
|
+
row.id = id;
|
|
114
|
+
if (cacheReadI >= 0) {
|
|
115
|
+
const cacheRead = parseMoneyCell(cells[cacheReadI] ?? "");
|
|
116
|
+
if (cacheRead !== undefined)
|
|
117
|
+
row.cache_read = cacheRead;
|
|
118
|
+
}
|
|
119
|
+
if (cacheWriteI >= 0) {
|
|
120
|
+
const cacheWrite = parseMoneyCell(cells[cacheWriteI] ?? "");
|
|
121
|
+
if (cacheWrite !== undefined)
|
|
122
|
+
row.cache_write = cacheWrite;
|
|
123
|
+
}
|
|
124
|
+
rows.push(row);
|
|
125
|
+
}
|
|
126
|
+
return rows;
|
|
127
|
+
}
|
|
128
|
+
export function parseModelsTable(markdown) {
|
|
129
|
+
return [...rowsFromGroup(pipeRows(markdown)), ...rowsFromGroup(htmlTableRows(markdown))];
|
|
130
|
+
}
|
|
131
|
+
export function applyDocCosts(models, rows, cliIds = new Set(), filledIds) {
|
|
132
|
+
const byName = new Map(rows.map((r) => [r.name.toLowerCase(), r]));
|
|
133
|
+
const byId = new Map(rows.filter((r) => r.id).map((r) => [r.id.toLowerCase(), r]));
|
|
134
|
+
let filled = 0;
|
|
135
|
+
for (const model of models) {
|
|
136
|
+
if (cliIds.has(model.id))
|
|
137
|
+
continue;
|
|
138
|
+
const row = byId.get(model.id.toLowerCase()) ?? byName.get(model.name.toLowerCase());
|
|
139
|
+
if (!row)
|
|
140
|
+
continue;
|
|
141
|
+
model.cost = { input: row.input, output: row.output };
|
|
142
|
+
if (row.cache_read !== undefined)
|
|
143
|
+
model.cost.cache_read = row.cache_read;
|
|
144
|
+
if (row.cache_write !== undefined)
|
|
145
|
+
model.cost.cache_write = row.cache_write;
|
|
146
|
+
filledIds?.add(model.id);
|
|
147
|
+
filled++;
|
|
148
|
+
}
|
|
149
|
+
return filled;
|
|
150
|
+
}
|
|
151
|
+
export async function fetchOfficialModelsMarkdown() {
|
|
152
|
+
const urls = [
|
|
153
|
+
"https://commandcode.ai/models",
|
|
154
|
+
"https://commandcode.ai/docs/resources/pricing-limits",
|
|
155
|
+
];
|
|
156
|
+
for (const url of urls) {
|
|
157
|
+
try {
|
|
158
|
+
const resp = await fetch(url);
|
|
159
|
+
if (!resp.ok)
|
|
160
|
+
continue;
|
|
161
|
+
const text = await resp.text();
|
|
162
|
+
if (parseModelsTable(text).length > 0)
|
|
163
|
+
return text;
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
// try next
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return "";
|
|
170
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { ModelEntry } from "./catalog.js";
|
|
2
|
+
export declare const MODELS_DEV_URL = "https://models.dev/api.json";
|
|
3
|
+
export declare const MODELS_DEV_TIMEOUT_MS = 30000;
|
|
4
|
+
export declare const MODELS_DEV_CACHE_TTL_MS: number;
|
|
5
|
+
export declare const MODELS_DEV_CACHE_FILE = "models-dev-cache.json";
|
|
6
|
+
export declare const ESTIMATED_CONTEXT_TOKENS = 200000;
|
|
7
|
+
export declare const ESTIMATED_OUTPUT_TOKENS = 65536;
|
|
8
|
+
export declare const FREE_COST: {
|
|
9
|
+
readonly input: 0;
|
|
10
|
+
readonly output: 0;
|
|
11
|
+
};
|
|
12
|
+
export declare const TEXT_ONLY_MODALITIES: {
|
|
13
|
+
readonly input: readonly ["text"];
|
|
14
|
+
readonly output: readonly ["text"];
|
|
15
|
+
};
|
|
16
|
+
export type ModelsDevRow = {
|
|
17
|
+
id: string;
|
|
18
|
+
name: string;
|
|
19
|
+
cost: {
|
|
20
|
+
input: number;
|
|
21
|
+
output: number;
|
|
22
|
+
cache_read?: number;
|
|
23
|
+
cache_write?: number;
|
|
24
|
+
};
|
|
25
|
+
attachment?: boolean;
|
|
26
|
+
modalities?: {
|
|
27
|
+
input: string[];
|
|
28
|
+
output: string[];
|
|
29
|
+
};
|
|
30
|
+
reasoning?: boolean;
|
|
31
|
+
reasoningEfforts?: string[];
|
|
32
|
+
toolCall?: boolean;
|
|
33
|
+
limit?: {
|
|
34
|
+
context: number;
|
|
35
|
+
output: number;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
export declare function isFreeSku(model: {
|
|
39
|
+
id: string;
|
|
40
|
+
name: string;
|
|
41
|
+
}): boolean;
|
|
42
|
+
export declare function parseModelsDev(json: string): ModelsDevRow[];
|
|
43
|
+
export declare function applyFreeCosts(models: ModelEntry[], skipIds: Set<string>, filledIds?: Set<string>): number;
|
|
44
|
+
/** Match a models.dev row by exact id, last path segment, or display name. */
|
|
45
|
+
export declare function findModelsDevRow(rows: ModelsDevRow[], id: string, name?: string): ModelsDevRow | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Build a provisional catalog entry for a remote id missing locally.
|
|
48
|
+
* Costs/capabilities come from models.dev (list prices, close to but not
|
|
49
|
+
* equal to Command Code billing); the entry is replaced on the next catalog
|
|
50
|
+
* sync. Returns null when nothing can ground an estimate.
|
|
51
|
+
*/
|
|
52
|
+
export declare function buildEstimatedEntry(id: string, rows: ModelsDevRow[]): ModelEntry | null;
|
|
53
|
+
export interface ModelsDevCache {
|
|
54
|
+
fetchedAt: number;
|
|
55
|
+
json: string;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Load models.dev rows, cached on disk for a day. Falls back to stale cache
|
|
59
|
+
* when the network fails; returns [] only when nothing is available.
|
|
60
|
+
*/
|
|
61
|
+
export declare function loadModelsDevRows(options?: {
|
|
62
|
+
timeoutMs?: number;
|
|
63
|
+
maxAgeMs?: number;
|
|
64
|
+
cacheDir?: string;
|
|
65
|
+
}): Promise<ModelsDevRow[]>;
|
|
66
|
+
export declare function applyModelsDevModalities(models: ModelEntry[], rows: ModelsDevRow[]): number;
|
|
67
|
+
export declare function applyModelsDevCosts(models: ModelEntry[], rows: ModelsDevRow[], skipIds: Set<string>, filledIds?: Set<string>): number;
|
|
68
|
+
export declare function fetchModelsDevJson(signal?: AbortSignal): Promise<string>;
|