@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,30 @@
|
|
|
1
|
+
import commandcodePlugin from "./plugin.js";
|
|
2
|
+
import { type V2SetupContext } from "./src/opencode2.js";
|
|
3
|
+
/**
|
|
4
|
+
* OpenCode 2.0 entrypoint (`@telsoncc/opencode-commandcode/server` and
|
|
5
|
+
* `@telsoncc/opencode-commandcode/plugin/opencode2`).
|
|
6
|
+
*
|
|
7
|
+
* Models register in memory via `ctx.provider.transform` + `editor.add` +
|
|
8
|
+
* `reload()` — nothing is written into `opencode.json`. Auth registers a
|
|
9
|
+
* `commandcode` integration (API key via `/connect`, `COMMANDCODE_API_KEY`
|
|
10
|
+
* env fallback). After startup the inventory refreshes itself from the live
|
|
11
|
+
* availability API every 6h (opt out with `disableModelSync` in
|
|
12
|
+
* `~/.config/opencode/opencode-commandcode.json`).
|
|
13
|
+
*
|
|
14
|
+
* Dual export: `{ id, setup, server }`. OpenCode 2.0 loads this module and
|
|
15
|
+
* calls `setup()`; OpenCode 1.18.29+ prefers `exports["./server"]` and calls
|
|
16
|
+
* `server()`, which is the classic V1 plugin in `plugin.ts` (unchanged).
|
|
17
|
+
* OpenCode <1.18.29 needs the pre-dual package version.
|
|
18
|
+
*
|
|
19
|
+
* Do not load this entrypoint together with the bare V1 `plugin.ts` shape in
|
|
20
|
+
* the same host.
|
|
21
|
+
*/
|
|
22
|
+
export declare const id = "commandcode";
|
|
23
|
+
export declare function setup(ctx: V2SetupContext): Promise<() => Promise<void>>;
|
|
24
|
+
export declare const server: typeof commandcodePlugin;
|
|
25
|
+
declare const _default: {
|
|
26
|
+
id: string;
|
|
27
|
+
setup: typeof setup;
|
|
28
|
+
server: typeof commandcodePlugin;
|
|
29
|
+
};
|
|
30
|
+
export default _default;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import commandcodePlugin from "./plugin.js";
|
|
2
|
+
import { COMMANDCODE_INTEGRATION_ID, applyIntegration, applyProviderInventory, attachRemoteRefreshRunner, isRemoteSyncDisabled, loadCatalogForV2, persistRefreshedModels, refreshCatalogFromRemote, writeRemoteRefreshSummary, } from "./src/opencode2.js";
|
|
3
|
+
/**
|
|
4
|
+
* OpenCode 2.0 entrypoint (`@telsoncc/opencode-commandcode/server` and
|
|
5
|
+
* `@telsoncc/opencode-commandcode/plugin/opencode2`).
|
|
6
|
+
*
|
|
7
|
+
* Models register in memory via `ctx.provider.transform` + `editor.add` +
|
|
8
|
+
* `reload()` — nothing is written into `opencode.json`. Auth registers a
|
|
9
|
+
* `commandcode` integration (API key via `/connect`, `COMMANDCODE_API_KEY`
|
|
10
|
+
* env fallback). After startup the inventory refreshes itself from the live
|
|
11
|
+
* availability API every 6h (opt out with `disableModelSync` in
|
|
12
|
+
* `~/.config/opencode/opencode-commandcode.json`).
|
|
13
|
+
*
|
|
14
|
+
* Dual export: `{ id, setup, server }`. OpenCode 2.0 loads this module and
|
|
15
|
+
* calls `setup()`; OpenCode 1.18.29+ prefers `exports["./server"]` and calls
|
|
16
|
+
* `server()`, which is the classic V1 plugin in `plugin.ts` (unchanged).
|
|
17
|
+
* OpenCode <1.18.29 needs the pre-dual package version.
|
|
18
|
+
*
|
|
19
|
+
* Do not load this entrypoint together with the bare V1 `plugin.ts` shape in
|
|
20
|
+
* the same host.
|
|
21
|
+
*/
|
|
22
|
+
export const id = "commandcode";
|
|
23
|
+
export async function setup(ctx) {
|
|
24
|
+
const registrations = [];
|
|
25
|
+
// Credentials first so the provider inventory can bind to the connection.
|
|
26
|
+
registrations.push(await ctx.integration.transform((draft) => {
|
|
27
|
+
applyIntegration(draft);
|
|
28
|
+
}));
|
|
29
|
+
const catalog = loadCatalogForV2();
|
|
30
|
+
// Reassigned by the remote refresh below; the provider transform closure
|
|
31
|
+
// replays against the current value on every reload().
|
|
32
|
+
let inventory = catalog.models;
|
|
33
|
+
let sourceConnection;
|
|
34
|
+
const refreshConnection = async () => {
|
|
35
|
+
try {
|
|
36
|
+
sourceConnection = await ctx.integration.connection.active(COMMANDCODE_INTEGRATION_ID);
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
sourceConnection = undefined;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
await refreshConnection();
|
|
43
|
+
registrations.push(await ctx.provider.transform((editor) => {
|
|
44
|
+
applyProviderInventory(editor, inventory, sourceConnection);
|
|
45
|
+
}));
|
|
46
|
+
try {
|
|
47
|
+
await ctx.provider.reload();
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
// Keep the last-good inventory when the reload fails.
|
|
51
|
+
}
|
|
52
|
+
// Live availability refresh: prune ids the API retired and publish new
|
|
53
|
+
// ones with models.dev cost estimates until a catalog sync replaces them.
|
|
54
|
+
// The bundled catalog stays as the offline fallback; ids with no
|
|
55
|
+
// estimable data stay reported as pending.
|
|
56
|
+
const sameInventory = (next) => next.length === inventory.length && next.every((m, i) => m.id === inventory[i]?.id);
|
|
57
|
+
const syncFromRemote = async () => {
|
|
58
|
+
if (isRemoteSyncDisabled())
|
|
59
|
+
return;
|
|
60
|
+
let result;
|
|
61
|
+
try {
|
|
62
|
+
result = await refreshCatalogFromRemote(loadCatalogForV2().models);
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
writeRemoteRefreshSummary(result, catalog.commandCodeVersion);
|
|
68
|
+
if (result.models.length === 0 || sameInventory(result.models))
|
|
69
|
+
return;
|
|
70
|
+
inventory = result.models;
|
|
71
|
+
persistRefreshedModels(inventory);
|
|
72
|
+
try {
|
|
73
|
+
await ctx.provider.reload();
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
// Keep serving the last-good inventory; the next tick retries.
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
let detachRefresh = null;
|
|
80
|
+
if (!isRemoteSyncDisabled()) {
|
|
81
|
+
detachRefresh = attachRemoteRefreshRunner(() => syncFromRemote());
|
|
82
|
+
void syncFromRemote().catch(() => {
|
|
83
|
+
// Startup already published the bundled inventory.
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
// Rebind the inventory when credentials switch; the transform closure reads
|
|
87
|
+
// the current `inventory`/`sourceConnection` on every replay.
|
|
88
|
+
let stopped = false;
|
|
89
|
+
try {
|
|
90
|
+
const stream = ctx.event?.subscribe();
|
|
91
|
+
if (stream && typeof stream[Symbol.asyncIterator] === "function") {
|
|
92
|
+
void (async () => {
|
|
93
|
+
for await (const event of stream) {
|
|
94
|
+
if (stopped)
|
|
95
|
+
break;
|
|
96
|
+
const type = event?.type;
|
|
97
|
+
if (type === "credential.switched" || type === "credential.updated") {
|
|
98
|
+
await refreshConnection();
|
|
99
|
+
try {
|
|
100
|
+
await ctx.provider.reload();
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
// ignore reload failure; next replay retries
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
})().catch(() => { });
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
// The event stream is optional; inventory still works without it.
|
|
112
|
+
}
|
|
113
|
+
return async () => {
|
|
114
|
+
stopped = true;
|
|
115
|
+
detachRefresh?.();
|
|
116
|
+
for (const registration of registrations.reverse()) {
|
|
117
|
+
try {
|
|
118
|
+
await registration.dispose();
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
// ignore disposal failure
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
export const server = commandcodePlugin;
|
|
127
|
+
export default { id, setup, server };
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type ModelEntry } from "./src/catalog.js";
|
|
2
|
+
export type { ModelEntry };
|
|
3
|
+
export default function commandcodePlugin(): Promise<{
|
|
4
|
+
config: (config: Record<string, unknown>) => Promise<void>;
|
|
5
|
+
auth: {
|
|
6
|
+
provider: string;
|
|
7
|
+
methods: {
|
|
8
|
+
type: string;
|
|
9
|
+
label: string;
|
|
10
|
+
authorize: (inputs: Record<string, unknown> | undefined) => Promise<{
|
|
11
|
+
type: "failed";
|
|
12
|
+
key?: undefined;
|
|
13
|
+
} | {
|
|
14
|
+
type: "success";
|
|
15
|
+
key: string;
|
|
16
|
+
}>;
|
|
17
|
+
}[];
|
|
18
|
+
loader: (getAuth: () => Promise<{
|
|
19
|
+
type: string;
|
|
20
|
+
key?: string;
|
|
21
|
+
} | null>) => Promise<{
|
|
22
|
+
apiKey?: undefined;
|
|
23
|
+
} | {
|
|
24
|
+
apiKey: string;
|
|
25
|
+
}>;
|
|
26
|
+
};
|
|
27
|
+
}>;
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { readFileSync, existsSync } from "fs";
|
|
2
|
+
import { homedir } from "os";
|
|
3
|
+
import { join, dirname } from "path";
|
|
4
|
+
import { fileURLToPath } from "url";
|
|
5
|
+
import { generateOpencodeModels, loadCatalogFromLocalCommandCode, } from "./src/catalog.js";
|
|
6
|
+
import { readCatalogCache, writeCatalogCache, writeStartupSummary, pluginStateDir, } from "./src/startup.js";
|
|
7
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
// Repo layout keeps the catalog next to plugin.ts; published builds emit
|
|
9
|
+
// dist/plugin.js and ship the catalog inside dist/ (and at the package root).
|
|
10
|
+
function resolveAsset(name) {
|
|
11
|
+
for (const dir of [__dirname, dirname(__dirname)]) {
|
|
12
|
+
const candidate = join(dir, name);
|
|
13
|
+
if (existsSync(candidate))
|
|
14
|
+
return candidate;
|
|
15
|
+
}
|
|
16
|
+
return join(__dirname, name);
|
|
17
|
+
}
|
|
18
|
+
const MODELS_PATH = resolveAsset("models.json");
|
|
19
|
+
const VERSION_PATH = resolveAsset("_version.txt");
|
|
20
|
+
const MANIFEST_PATH = resolveAsset("manifest.json");
|
|
21
|
+
function loadPluginConfig() {
|
|
22
|
+
const dir = join(homedir(), ".config", "opencode");
|
|
23
|
+
const configPath = [
|
|
24
|
+
join(dir, "opencode-commandcode.json"),
|
|
25
|
+
join(dir, "commandcode-go-opencode-provider.json"),
|
|
26
|
+
].find((p) => existsSync(p));
|
|
27
|
+
if (!configPath)
|
|
28
|
+
return {};
|
|
29
|
+
try {
|
|
30
|
+
return JSON.parse(readFileSync(configPath, "utf-8"));
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return {};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function loadBundledModels() {
|
|
37
|
+
try {
|
|
38
|
+
return JSON.parse(readFileSync(MODELS_PATH, "utf-8"));
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function readBundledManifest() {
|
|
45
|
+
if (!existsSync(MANIFEST_PATH))
|
|
46
|
+
return null;
|
|
47
|
+
try {
|
|
48
|
+
return JSON.parse(readFileSync(MANIFEST_PATH, "utf-8"));
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function readBundledVersion() {
|
|
55
|
+
const manifest = readBundledManifest();
|
|
56
|
+
if (manifest?.commandCodeVersion)
|
|
57
|
+
return manifest.commandCodeVersion;
|
|
58
|
+
if (!existsSync(VERSION_PATH))
|
|
59
|
+
return null;
|
|
60
|
+
try {
|
|
61
|
+
const parts = readFileSync(VERSION_PATH, "utf-8").split("\n");
|
|
62
|
+
const first = parts[0]?.trim();
|
|
63
|
+
return first || null;
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
export default async function commandcodePlugin() {
|
|
70
|
+
return {
|
|
71
|
+
config: async (config) => {
|
|
72
|
+
if (!config.provider) {
|
|
73
|
+
config.provider = { commandcode: {} };
|
|
74
|
+
}
|
|
75
|
+
const cc = config.provider?.commandcode;
|
|
76
|
+
if (!cc)
|
|
77
|
+
return;
|
|
78
|
+
const pluginCfg = loadPluginConfig();
|
|
79
|
+
const debug = pluginCfg.debugStartupLogs === true;
|
|
80
|
+
const override = pluginCfg.commandCodePackagePath?.trim() ||
|
|
81
|
+
process.env.COMMANDCODE_PACKAGE_PATH?.trim() ||
|
|
82
|
+
"";
|
|
83
|
+
if (!cc.npm)
|
|
84
|
+
cc.npm = "commandcode-go-opencode-provider";
|
|
85
|
+
if (!cc.name)
|
|
86
|
+
cc.name = "Command Code";
|
|
87
|
+
if (!cc.env)
|
|
88
|
+
cc.env = ["COMMANDCODE_API_KEY"];
|
|
89
|
+
if (cc.models)
|
|
90
|
+
return;
|
|
91
|
+
let models = [];
|
|
92
|
+
let catalogSource = "bundled";
|
|
93
|
+
let commandCodeVersion = null;
|
|
94
|
+
let degraded = false;
|
|
95
|
+
let degradedReason = null;
|
|
96
|
+
if (override) {
|
|
97
|
+
const localCatalog = loadCatalogFromLocalCommandCode({ packagePath: override });
|
|
98
|
+
if (localCatalog && localCatalog.models.length > 0) {
|
|
99
|
+
models = localCatalog.models;
|
|
100
|
+
catalogSource = "opt-in-local";
|
|
101
|
+
commandCodeVersion = localCatalog.version;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (models.length === 0) {
|
|
105
|
+
const bundled = loadBundledModels();
|
|
106
|
+
if (bundled) {
|
|
107
|
+
models = bundled;
|
|
108
|
+
catalogSource = "bundled";
|
|
109
|
+
commandCodeVersion = readBundledVersion();
|
|
110
|
+
const manifest = readBundledManifest();
|
|
111
|
+
if (manifest?.status === "degraded" || manifest?.status === "broken") {
|
|
112
|
+
degraded = true;
|
|
113
|
+
degradedReason =
|
|
114
|
+
manifest.status === "broken"
|
|
115
|
+
? "bundled catalog marked broken"
|
|
116
|
+
: "bundled catalog has models with no listed price";
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
const cached = readCatalogCache();
|
|
121
|
+
if (cached) {
|
|
122
|
+
models = cached;
|
|
123
|
+
catalogSource = "cache";
|
|
124
|
+
degraded = true;
|
|
125
|
+
degradedReason = "bundled models.json unreadable; using last-good cache";
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
degraded = true;
|
|
129
|
+
degradedReason = "no bundled catalog and no cache";
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (models.length > 0) {
|
|
134
|
+
try {
|
|
135
|
+
writeCatalogCache(pluginStateDir(), models);
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
// ignore cache write
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
cc.models = generateOpencodeModels(models);
|
|
142
|
+
const summary = {
|
|
143
|
+
catalogSource,
|
|
144
|
+
commandCodeVersion,
|
|
145
|
+
modelCount: models.length,
|
|
146
|
+
reasoningModelCount: models.filter((m) => m.reasoning).length,
|
|
147
|
+
degraded,
|
|
148
|
+
degradedReason,
|
|
149
|
+
};
|
|
150
|
+
try {
|
|
151
|
+
writeStartupSummary(pluginStateDir(), summary);
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
// ignore
|
|
155
|
+
}
|
|
156
|
+
if (debug) {
|
|
157
|
+
console.warn("[commandcode]", JSON.stringify(summary));
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
auth: {
|
|
161
|
+
provider: "commandcode",
|
|
162
|
+
methods: [
|
|
163
|
+
{
|
|
164
|
+
type: "api",
|
|
165
|
+
label: "API Key",
|
|
166
|
+
authorize: async (inputs) => {
|
|
167
|
+
const rawKey = inputs?.key;
|
|
168
|
+
if (typeof rawKey !== "string")
|
|
169
|
+
return { type: "failed" };
|
|
170
|
+
const key = rawKey.trim();
|
|
171
|
+
if (!key)
|
|
172
|
+
return { type: "failed" };
|
|
173
|
+
return { type: "success", key };
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
],
|
|
177
|
+
loader: async (getAuth) => {
|
|
178
|
+
try {
|
|
179
|
+
const auth = await getAuth();
|
|
180
|
+
if (!auth)
|
|
181
|
+
return {};
|
|
182
|
+
if (auth.type === "api" && auth.key)
|
|
183
|
+
return { apiKey: auth.key };
|
|
184
|
+
return {};
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
return {};
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
};
|
|
192
|
+
}
|
package/dist/src/auth.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { readFileSync, existsSync } from "fs";
|
|
2
|
+
import { homedir } from "os";
|
|
3
|
+
import { join } from "path";
|
|
4
|
+
export function resolveApiKey(options) {
|
|
5
|
+
if (options.apiKey)
|
|
6
|
+
return options.apiKey;
|
|
7
|
+
const envKey = options.env?.COMMANDCODE_API_KEY ?? process.env.COMMANDCODE_API_KEY;
|
|
8
|
+
if (envKey)
|
|
9
|
+
return envKey;
|
|
10
|
+
const authPaths = options.authPaths ?? [
|
|
11
|
+
join(homedir(), ".commandcode", "auth.json"),
|
|
12
|
+
join(homedir(), ".pi", "agent", "auth.json"),
|
|
13
|
+
];
|
|
14
|
+
for (const p of authPaths) {
|
|
15
|
+
if (!existsSync(p))
|
|
16
|
+
continue;
|
|
17
|
+
try {
|
|
18
|
+
const parsed = JSON.parse(readFileSync(p, "utf-8"));
|
|
19
|
+
if (typeof parsed === "object" && parsed !== null) {
|
|
20
|
+
if (typeof parsed.apiKey === "string")
|
|
21
|
+
return parsed.apiKey;
|
|
22
|
+
if (typeof parsed.commandcode === "string")
|
|
23
|
+
return parsed.commandcode;
|
|
24
|
+
if (typeof parsed.commandcode === "object" &&
|
|
25
|
+
parsed.commandcode !== null &&
|
|
26
|
+
parsed.commandcode.type === "oauth" &&
|
|
27
|
+
typeof parsed.commandcode.access === "string") {
|
|
28
|
+
return parsed.commandcode.access;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
// intentionally silent: skip unreadable or malformed auth files
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare function catalogBreakTitle(commandCodeVersion: string): string;
|
|
2
|
+
export declare function renderCatalogBreakBody(input: {
|
|
3
|
+
commandCodeVersion: string;
|
|
4
|
+
error: string;
|
|
5
|
+
workflowUrl: string;
|
|
6
|
+
bundledCommandCodeVersion: string | null;
|
|
7
|
+
}): string;
|
|
8
|
+
export declare function catalogBreakResolvedComment(input: {
|
|
9
|
+
commit: string;
|
|
10
|
+
tag: string;
|
|
11
|
+
}): string;
|
|
12
|
+
export declare const CATALOG_BREAK_LABEL = "catalog-break";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export function catalogBreakTitle(commandCodeVersion) {
|
|
2
|
+
const version = commandCodeVersion.trim().replace(/^v/, "");
|
|
3
|
+
return `[catalog-break] command-code@${version} — model extraction failed`;
|
|
4
|
+
}
|
|
5
|
+
export function renderCatalogBreakBody(input) {
|
|
6
|
+
const bundled = input.bundledCommandCodeVersion ?? "(none)";
|
|
7
|
+
return `Model catalog extraction failed for \`command-code@${input.commandCodeVersion}\`.
|
|
8
|
+
|
|
9
|
+
## Error
|
|
10
|
+
|
|
11
|
+
\`\`\`
|
|
12
|
+
${input.error}
|
|
13
|
+
\`\`\`
|
|
14
|
+
|
|
15
|
+
## Workflow
|
|
16
|
+
|
|
17
|
+
${input.workflowUrl}
|
|
18
|
+
|
|
19
|
+
## Still serving
|
|
20
|
+
|
|
21
|
+
Bundled catalog is still \`command-code@${bundled}\`. No npm release was published.
|
|
22
|
+
|
|
23
|
+
## Manual fix
|
|
24
|
+
|
|
25
|
+
- [ ] Check extraction anchors in \`src/catalog.ts\`
|
|
26
|
+
- [ ] Add/adjust unit fixtures under \`tests/fixtures/command-code/\`
|
|
27
|
+
- [ ] Re-run **Catalog sync** with \`force=true\`
|
|
28
|
+
`;
|
|
29
|
+
}
|
|
30
|
+
export function catalogBreakResolvedComment(input) {
|
|
31
|
+
return `Catalog sync recovered. Fix commit: \`${input.commit}\`. Release: \`${input.tag}\`.`;
|
|
32
|
+
}
|
|
33
|
+
export const CATALOG_BREAK_LABEL = "catalog-break";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { CatalogManifest, CatalogReview, CatalogStatus, CostSources } from "./manifest.js";
|
|
2
|
+
export type PricedModel = {
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
cost: {
|
|
6
|
+
input: number;
|
|
7
|
+
output: number;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
export type CatalogReleaseInput = {
|
|
11
|
+
pluginVersion: string;
|
|
12
|
+
commandCodeVersion: string;
|
|
13
|
+
modelCount: number;
|
|
14
|
+
reasoningModelCount: number;
|
|
15
|
+
status: CatalogStatus;
|
|
16
|
+
costSources: CostSources;
|
|
17
|
+
models: PricedModel[];
|
|
18
|
+
review?: CatalogReview;
|
|
19
|
+
};
|
|
20
|
+
export declare function partitionPrices(models: PricedModel[], review: CatalogReview | undefined): {
|
|
21
|
+
thirdParty: PricedModel[];
|
|
22
|
+
free: PricedModel[];
|
|
23
|
+
unmatched: PricedModel[];
|
|
24
|
+
};
|
|
25
|
+
export declare function renderCatalogReleaseNotes(input: CatalogReleaseInput): string;
|
|
26
|
+
export declare function catalogReleaseNotesFromFiles(input: {
|
|
27
|
+
manifest: CatalogManifest;
|
|
28
|
+
models: PricedModel[];
|
|
29
|
+
pluginVersion?: string;
|
|
30
|
+
}): string;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
const DEFAULT_COST = { input: 0.5, output: 2 };
|
|
2
|
+
export function partitionPrices(models, review) {
|
|
3
|
+
const byId = new Map(models.map((m) => [m.id, m]));
|
|
4
|
+
if (review) {
|
|
5
|
+
return {
|
|
6
|
+
thirdParty: review.thirdParty.flatMap((id) => (byId.get(id) ? [byId.get(id)] : [])),
|
|
7
|
+
free: review.free.flatMap((id) => (byId.get(id) ? [byId.get(id)] : [])),
|
|
8
|
+
unmatched: review.unmatched.flatMap((id) => (byId.get(id) ? [byId.get(id)] : [])),
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
const thirdParty = [];
|
|
12
|
+
const free = [];
|
|
13
|
+
const unmatched = [];
|
|
14
|
+
for (const model of models) {
|
|
15
|
+
if (model.cost.input === 0 && model.cost.output === 0)
|
|
16
|
+
free.push(model);
|
|
17
|
+
else if (model.cost.input === DEFAULT_COST.input && model.cost.output === DEFAULT_COST.output) {
|
|
18
|
+
unmatched.push(model);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return { thirdParty, free, unmatched };
|
|
22
|
+
}
|
|
23
|
+
function n(count, one, many) {
|
|
24
|
+
return `${count} ${count === 1 ? one : many}`;
|
|
25
|
+
}
|
|
26
|
+
function headline(status) {
|
|
27
|
+
if (status === "healthy") {
|
|
28
|
+
return "**Catalog is complete.** Prices come from Command Code, official docs, models.dev, or free SKUs.";
|
|
29
|
+
}
|
|
30
|
+
if (status === "broken") {
|
|
31
|
+
return "**Do not use this catalog.** Model extraction failed; OpenCode would not get a current model list.";
|
|
32
|
+
}
|
|
33
|
+
return "**Safe to use.** Every model is listed. Some prices have no listed source — expand the sections below to review them.";
|
|
34
|
+
}
|
|
35
|
+
function priceSummary(sources) {
|
|
36
|
+
const parts = [];
|
|
37
|
+
if (sources.cli > 0)
|
|
38
|
+
parts.push(`${sources.cli} CLI`);
|
|
39
|
+
if (sources.officialDocs > 0)
|
|
40
|
+
parts.push(`${sources.officialDocs} official docs`);
|
|
41
|
+
if (sources.thirdParty > 0)
|
|
42
|
+
parts.push(`${sources.thirdParty} models.dev`);
|
|
43
|
+
if (sources.free > 0)
|
|
44
|
+
parts.push(`${sources.free} free`);
|
|
45
|
+
if (sources.fallback > 0)
|
|
46
|
+
parts.push(`${sources.fallback} hardcoded fallback${sources.fallback === 1 ? "" : "s"}`);
|
|
47
|
+
if (sources.unmatched > 0)
|
|
48
|
+
parts.push(`${sources.unmatched} no listed price`);
|
|
49
|
+
return parts.join(" · ") || "none";
|
|
50
|
+
}
|
|
51
|
+
function money(n) {
|
|
52
|
+
return `$${n}`;
|
|
53
|
+
}
|
|
54
|
+
function modelTable(models) {
|
|
55
|
+
const rows = models
|
|
56
|
+
.map((m) => `| ${m.name} | \`${m.id}\` | ${money(m.cost.input)} / ${money(m.cost.output)} |`)
|
|
57
|
+
.join("\n");
|
|
58
|
+
return `| Model | Id | In / out per 1M |\n| --- | --- | --- |\n${rows}`;
|
|
59
|
+
}
|
|
60
|
+
function details(summary, body) {
|
|
61
|
+
return `<details>\n<summary>${summary}</summary>\n\n${body}\n\n</details>`;
|
|
62
|
+
}
|
|
63
|
+
export function renderCatalogReleaseNotes(input) {
|
|
64
|
+
const { thirdParty, free, unmatched } = partitionPrices(input.models, input.review);
|
|
65
|
+
const sections = [
|
|
66
|
+
headline(input.status),
|
|
67
|
+
"",
|
|
68
|
+
`| Plugin | ${input.pluginVersion} |`,
|
|
69
|
+
"| --- | --- |",
|
|
70
|
+
`| Command Code | ${input.commandCodeVersion} |`,
|
|
71
|
+
`| Models | ${input.modelCount} (${input.reasoningModelCount} with reasoning) |`,
|
|
72
|
+
`| Prices | ${priceSummary(input.costSources)} |`,
|
|
73
|
+
];
|
|
74
|
+
if (thirdParty.length > 0) {
|
|
75
|
+
sections.push("", details(n(thirdParty.length, "model with a models.dev reference price", "models with models.dev reference prices"), modelTable(thirdParty)));
|
|
76
|
+
}
|
|
77
|
+
if (free.length > 0) {
|
|
78
|
+
sections.push("", details(n(free.length, "free model ($0)", "free models ($0)"), modelTable(free)));
|
|
79
|
+
}
|
|
80
|
+
if (unmatched.length > 0) {
|
|
81
|
+
sections.push("", details(n(unmatched.length, "model with no listed price ($0.50 / $2)", "models with no listed price ($0.50 / $2)"), modelTable(unmatched)));
|
|
82
|
+
}
|
|
83
|
+
sections.push("", details("Machine-readable catalog", "```json\n" +
|
|
84
|
+
JSON.stringify({
|
|
85
|
+
status: input.status,
|
|
86
|
+
pluginVersion: input.pluginVersion,
|
|
87
|
+
commandCodeVersion: input.commandCodeVersion,
|
|
88
|
+
modelCount: input.modelCount,
|
|
89
|
+
reasoningModelCount: input.reasoningModelCount,
|
|
90
|
+
costSources: input.costSources,
|
|
91
|
+
}, null, 2) +
|
|
92
|
+
"\n```"));
|
|
93
|
+
return sections.join("\n") + "\n";
|
|
94
|
+
}
|
|
95
|
+
export function catalogReleaseNotesFromFiles(input) {
|
|
96
|
+
return renderCatalogReleaseNotes({
|
|
97
|
+
pluginVersion: input.pluginVersion ?? input.manifest.pluginVersion,
|
|
98
|
+
commandCodeVersion: input.manifest.commandCodeVersion,
|
|
99
|
+
modelCount: input.manifest.modelCount,
|
|
100
|
+
reasoningModelCount: input.manifest.reasoningModelCount,
|
|
101
|
+
status: input.manifest.status,
|
|
102
|
+
costSources: input.manifest.costSources,
|
|
103
|
+
models: input.models,
|
|
104
|
+
review: input.manifest.review,
|
|
105
|
+
});
|
|
106
|
+
}
|