@brainervirus/opencode-commandcode 0.8.0 → 0.9.1
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 +4 -0
- package/README.md +41 -26
- package/dist/index.d.ts +12 -0
- package/dist/plugin.d.ts +45 -0
- package/dist/plugin.js +21018 -0
- package/dist/src/auth.d.ts +5 -0
- package/dist/src/catalog-break.d.ts +12 -0
- package/dist/src/catalog-release-notes.d.ts +30 -0
- package/dist/src/catalog.d.ts +104 -0
- package/dist/src/convert.d.ts +71 -0
- package/dist/src/costs-docs.d.ts +13 -0
- package/dist/src/costs-models-dev.d.ts +34 -0
- package/dist/src/cut-changelog.d.ts +1 -0
- package/dist/src/entry.d.ts +3 -0
- package/dist/src/env.d.ts +13 -0
- package/dist/src/load-result.d.ts +17 -0
- package/dist/src/manifest.d.ts +54 -0
- package/dist/src/model.d.ts +18 -0
- package/dist/src/paths.d.ts +14 -0
- package/dist/src/publish-policy.d.ts +18 -0
- package/dist/src/schemas.d.ts +96 -0
- package/dist/src/startup.d.ts +22 -0
- package/dist/src/stream.d.ts +2 -0
- package/dist/src/v2models.d.ts +36 -0
- package/manifest.json +1 -1
- package/package.json +13 -10
- package/plugin.ts +142 -65
- package/src/catalog.ts +65 -73
- package/src/env.ts +25 -0
- package/src/load-result.ts +22 -0
- package/src/manifest.ts +3 -25
- package/src/schemas.ts +103 -0
- package/src/startup.ts +27 -13
- package/src/v2models.ts +3 -1
package/src/schemas.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
/** Canonical catalog model entry. Single source of truth — src/catalog.ts derives its ModelEntry type from here via z.infer; never redeclare the shape there. */
|
|
4
|
+
export const ModelEntrySchema = z.strictObject({
|
|
5
|
+
id: z.string().min(1),
|
|
6
|
+
name: z.string().min(1),
|
|
7
|
+
tier: z.enum(["premium", "open-source"]),
|
|
8
|
+
reasoning: z.boolean(),
|
|
9
|
+
reasoningEfforts: z.array(z.string()).optional(),
|
|
10
|
+
tool_call: z.boolean(),
|
|
11
|
+
cost: z.strictObject({
|
|
12
|
+
input: z.number(),
|
|
13
|
+
output: z.number(),
|
|
14
|
+
cache_read: z.number().optional(),
|
|
15
|
+
cache_write: z.number().optional(),
|
|
16
|
+
}),
|
|
17
|
+
limit: z.strictObject({
|
|
18
|
+
context: z.number().int(),
|
|
19
|
+
output: z.number().int(),
|
|
20
|
+
}),
|
|
21
|
+
attachment: z.boolean().optional(),
|
|
22
|
+
modalities: z
|
|
23
|
+
.strictObject({
|
|
24
|
+
input: z.array(z.string()),
|
|
25
|
+
output: z.array(z.string()),
|
|
26
|
+
})
|
|
27
|
+
.optional(),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
/** Canonical catalog manifest. Single source of truth — src/manifest.ts derives its CatalogManifest type from here via z.infer; never redeclare the shape there. */
|
|
31
|
+
export const ManifestSchema = z.strictObject({
|
|
32
|
+
schemaVersion: z.literal(1),
|
|
33
|
+
generatedAt: z.string(),
|
|
34
|
+
pluginVersion: z.string(),
|
|
35
|
+
commandCodeVersion: z.string(),
|
|
36
|
+
commandCodeTarball: z.string(),
|
|
37
|
+
modelCount: z.number().int(),
|
|
38
|
+
reasoningModelCount: z.number().int(),
|
|
39
|
+
extraction: z.strictObject({
|
|
40
|
+
modelCatalog: z.enum(["ok", "failed"]),
|
|
41
|
+
costCatalog: z.enum(["cli", "docs", "thirdParty", "free", "fallback", "missing"]),
|
|
42
|
+
costCatalogError: z.string().nullable(),
|
|
43
|
+
}),
|
|
44
|
+
costSources: z.strictObject({
|
|
45
|
+
cli: z.number().int(),
|
|
46
|
+
officialDocs: z.number().int(),
|
|
47
|
+
thirdParty: z.number().int(),
|
|
48
|
+
free: z.number().int(),
|
|
49
|
+
fallback: z.number().int(),
|
|
50
|
+
unmatched: z.number().int(),
|
|
51
|
+
}),
|
|
52
|
+
review: z
|
|
53
|
+
.strictObject({
|
|
54
|
+
thirdParty: z.array(z.string()),
|
|
55
|
+
free: z.array(z.string()),
|
|
56
|
+
unmatched: z.array(z.string()),
|
|
57
|
+
unavailable: z
|
|
58
|
+
.array(
|
|
59
|
+
z.strictObject({
|
|
60
|
+
id: z.string(),
|
|
61
|
+
reason: z.literal("not-listed-by-provider-api"),
|
|
62
|
+
}),
|
|
63
|
+
)
|
|
64
|
+
.optional(),
|
|
65
|
+
})
|
|
66
|
+
.optional(),
|
|
67
|
+
status: z.enum(["healthy", "degraded", "broken"]),
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* OpenAI-style `{ object: "list", data: [{ id }] }` availability payload.
|
|
72
|
+
* Items stay lenient (the provider API returns extra per-model fields);
|
|
73
|
+
* duplicate ids are rejected.
|
|
74
|
+
*/
|
|
75
|
+
export const AvailabilityPayloadSchema = z
|
|
76
|
+
.object({
|
|
77
|
+
object: z.literal("list"),
|
|
78
|
+
data: z.array(z.object({ id: z.string().min(1) })).min(1),
|
|
79
|
+
})
|
|
80
|
+
.superRefine((payload, ctx) => {
|
|
81
|
+
const seen = new Set<string>();
|
|
82
|
+
for (const item of payload.data) {
|
|
83
|
+
if (seen.has(item.id)) {
|
|
84
|
+
ctx.addIssue({
|
|
85
|
+
code: "custom",
|
|
86
|
+
message: `duplicate availability id: ${item.id}`,
|
|
87
|
+
});
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
seen.add(item.id);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Plugin file config (`~/.config/opencode/opencode-commandcode.json`).
|
|
96
|
+
* Deliberately lenient: user config files may carry extra keys, so unknown
|
|
97
|
+
* keys are stripped and every field falls back to its default.
|
|
98
|
+
*/
|
|
99
|
+
export const PluginFileConfigSchema = z.object({
|
|
100
|
+
disableModelSync: z.boolean().optional().default(false),
|
|
101
|
+
commandCodePackagePath: z.string().optional().default(""),
|
|
102
|
+
debugStartupLogs: z.boolean().optional().default(false),
|
|
103
|
+
});
|
package/src/startup.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
2
|
-
import { homedir } from "os";
|
|
3
2
|
import { join } from "path";
|
|
4
3
|
import type { ModelEntry } from "./catalog.js";
|
|
4
|
+
import { liveEnv, resolveStateDir, type EnvDeps } from "./env.js";
|
|
5
|
+
import { causeMessage, errResult, okResult, type LoadResult } from "./load-result.js";
|
|
5
6
|
|
|
6
7
|
export type { ModelEntry } from "./catalog.js";
|
|
7
8
|
|
|
@@ -14,22 +15,35 @@ export type StartupSummary = {
|
|
|
14
15
|
degradedReason: string | null;
|
|
15
16
|
};
|
|
16
17
|
|
|
17
|
-
export function pluginStateDir(): string {
|
|
18
|
-
|
|
19
|
-
if (override) return override;
|
|
20
|
-
return join(homedir(), ".local/state/opencode/commandcode-provider");
|
|
18
|
+
export function pluginStateDir(deps: EnvDeps = liveEnv): string {
|
|
19
|
+
return resolveStateDir(deps);
|
|
21
20
|
}
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Explicit cache read: hit yields the models, anything else yields the
|
|
24
|
+
* reason (missing file, empty/invalid content, unreadable JSON).
|
|
25
|
+
*/
|
|
26
|
+
export function readCatalogCacheResult(
|
|
27
|
+
dir?: string,
|
|
28
|
+
deps: EnvDeps = liveEnv,
|
|
29
|
+
): LoadResult<ModelEntry[]> {
|
|
30
|
+
const cacheDir = dir ?? resolveStateDir(deps);
|
|
31
|
+
const path = join(cacheDir, "catalog-cache.json");
|
|
32
|
+
if (!existsSync(path)) return errResult("catalog cache missing");
|
|
33
|
+
let parsed: unknown;
|
|
26
34
|
try {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return
|
|
30
|
-
} catch {
|
|
31
|
-
return null;
|
|
35
|
+
parsed = JSON.parse(readFileSync(path, "utf-8")) as unknown;
|
|
36
|
+
} catch (error) {
|
|
37
|
+
return errResult(`catalog cache unreadable: ${causeMessage(error)}`);
|
|
32
38
|
}
|
|
39
|
+
if (!Array.isArray(parsed) || parsed.length === 0) return errResult("catalog cache empty");
|
|
40
|
+
return okResult(parsed as ModelEntry[]);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Compat wrapper: explicit-dir callers that only need value-or-null. */
|
|
44
|
+
export function readCatalogCache(dir?: string, deps: EnvDeps = liveEnv): ModelEntry[] | null {
|
|
45
|
+
const result = readCatalogCacheResult(dir, deps);
|
|
46
|
+
return result.ok ? result.value : null;
|
|
33
47
|
}
|
|
34
48
|
|
|
35
49
|
export function writeCatalogCache(dir: string, models: ModelEntry[]): void {
|
package/src/v2models.ts
CHANGED
|
@@ -29,10 +29,12 @@ function v2Output(entry: ModelEntry): string[] {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
export function toV2Model(entry: ModelEntry): V2Model {
|
|
32
|
+
// UI / OpenCode selection key stays short (commandcode/deepseek-v4.1-flash).
|
|
33
|
+
// modelID is the Command Code wire id — bare names 400 as unsupported_model.
|
|
32
34
|
const id = toConfigKey(entry.id);
|
|
33
35
|
return {
|
|
34
36
|
id,
|
|
35
|
-
modelID: id,
|
|
37
|
+
modelID: entry.id,
|
|
36
38
|
providerID: "commandcode",
|
|
37
39
|
name: entry.name,
|
|
38
40
|
capabilities: {
|