@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.
Files changed (46) hide show
  1. package/CHANGELOG.md +6 -222
  2. package/dist/_version.txt +1 -0
  3. package/dist/index.d.ts +11 -0
  4. package/dist/index.js +19 -0
  5. package/dist/manifest.json +28 -0
  6. package/dist/models.json +3334 -0
  7. package/dist/plugin-opencode2.d.ts +30 -0
  8. package/dist/plugin-opencode2.js +127 -0
  9. package/dist/plugin.d.ts +27 -0
  10. package/dist/plugin.js +192 -0
  11. package/dist/src/auth.d.ts +5 -0
  12. package/dist/src/auth.js +38 -0
  13. package/dist/src/catalog-break.d.ts +12 -0
  14. package/dist/src/catalog-break.js +33 -0
  15. package/dist/src/catalog-release-notes.d.ts +30 -0
  16. package/dist/src/catalog-release-notes.js +106 -0
  17. package/dist/src/catalog.d.ts +160 -0
  18. package/dist/src/catalog.js +786 -0
  19. package/dist/src/convert.d.ts +71 -0
  20. package/dist/src/convert.js +154 -0
  21. package/dist/src/costs-docs.d.ts +13 -0
  22. package/dist/src/costs-docs.js +170 -0
  23. package/dist/src/costs-models-dev.d.ts +68 -0
  24. package/dist/src/costs-models-dev.js +303 -0
  25. package/dist/src/cut-changelog.d.ts +1 -0
  26. package/dist/src/cut-changelog.js +43 -0
  27. package/dist/src/manifest.d.ts +72 -0
  28. package/dist/src/manifest.js +111 -0
  29. package/dist/src/model.d.ts +18 -0
  30. package/dist/src/model.js +138 -0
  31. package/dist/src/opencode2.d.ts +179 -0
  32. package/dist/src/opencode2.js +386 -0
  33. package/dist/src/pack-contract.d.ts +25 -0
  34. package/dist/src/pack-contract.js +42 -0
  35. package/dist/src/publish-policy.d.ts +18 -0
  36. package/dist/src/publish-policy.js +16 -0
  37. package/dist/src/startup.d.ts +18 -0
  38. package/dist/src/startup.js +31 -0
  39. package/dist/src/stream.d.ts +2 -0
  40. package/dist/src/stream.js +203 -0
  41. package/manifest.json +1 -1
  42. package/package.json +12 -7
  43. package/plugin.ts +14 -3
  44. package/src/cut-changelog.ts +6 -1
  45. package/src/opencode2.ts +14 -3
  46. package/src/pack-contract.ts +51 -0
@@ -0,0 +1,31 @@
1
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
2
+ import { homedir } from "os";
3
+ import { join } from "path";
4
+ export function pluginStateDir() {
5
+ const override = process.env.COMMANDCODE_PROVIDER_STATE_DIR?.trim();
6
+ if (override)
7
+ return override;
8
+ return join(homedir(), ".local/state/opencode/commandcode-provider");
9
+ }
10
+ export function readCatalogCache(dir = pluginStateDir()) {
11
+ const path = join(dir, "catalog-cache.json");
12
+ if (!existsSync(path))
13
+ return null;
14
+ try {
15
+ const parsed = JSON.parse(readFileSync(path, "utf-8"));
16
+ if (!Array.isArray(parsed) || parsed.length === 0)
17
+ return null;
18
+ return parsed;
19
+ }
20
+ catch {
21
+ return null;
22
+ }
23
+ }
24
+ export function writeCatalogCache(dir, models) {
25
+ mkdirSync(dir, { recursive: true });
26
+ writeFileSync(join(dir, "catalog-cache.json"), JSON.stringify(models) + "\n", "utf-8");
27
+ }
28
+ export function writeStartupSummary(dir, summary) {
29
+ mkdirSync(dir, { recursive: true });
30
+ writeFileSync(join(dir, "startup.json"), JSON.stringify(summary) + "\n", "utf-8");
31
+ }
@@ -0,0 +1,2 @@
1
+ import type { LanguageModelV3StreamPart } from "@ai-sdk/provider";
2
+ export declare function parseStreamEvents(body: ReadableStream<Uint8Array>): ReadableStream<LanguageModelV3StreamPart>;
@@ -0,0 +1,203 @@
1
+ function mapFinishReason(raw) {
2
+ switch (raw) {
3
+ case "stop":
4
+ case "end_turn":
5
+ return "stop";
6
+ case "tool_calls":
7
+ case "tool-calls":
8
+ return "tool-calls";
9
+ case "length":
10
+ case "max_tokens":
11
+ case "max-tokens":
12
+ case "max_output_tokens":
13
+ return "length";
14
+ case "content_filter":
15
+ return "content-filter";
16
+ default:
17
+ return "other";
18
+ }
19
+ }
20
+ function mapUsage(raw) {
21
+ const inputDetails = (raw.inputTokenDetails ?? raw.input_token_details ?? {});
22
+ const outputDetails = (raw.outputTokenDetails ?? raw.output_token_details ?? {});
23
+ return {
24
+ inputTokens: {
25
+ total: typeof raw.inputTokens === "number"
26
+ ? raw.inputTokens
27
+ : typeof raw.prompt_tokens === "number"
28
+ ? raw.prompt_tokens
29
+ : undefined,
30
+ noCache: typeof inputDetails.noCacheTokens === "number" ? inputDetails.noCacheTokens : undefined,
31
+ cacheRead: typeof inputDetails.cacheReadTokens === "number" ? inputDetails.cacheReadTokens : undefined,
32
+ cacheWrite: typeof inputDetails.cacheWriteTokens === "number"
33
+ ? inputDetails.cacheWriteTokens
34
+ : undefined,
35
+ },
36
+ outputTokens: {
37
+ total: typeof raw.outputTokens === "number"
38
+ ? raw.outputTokens
39
+ : typeof raw.completion_tokens === "number"
40
+ ? raw.completion_tokens
41
+ : undefined,
42
+ text: typeof outputDetails.textTokens === "number" ? outputDetails.textTokens : undefined,
43
+ reasoning: typeof outputDetails.reasoningTokens === "number"
44
+ ? outputDetails.reasoningTokens
45
+ : undefined,
46
+ },
47
+ };
48
+ }
49
+ function toStreamPart(event) {
50
+ switch (event.type) {
51
+ case "start":
52
+ return { type: "stream-start", warnings: [] };
53
+ case "text-start":
54
+ return { type: "text-start", id: event.id };
55
+ case "text-delta":
56
+ return {
57
+ type: "text-delta",
58
+ id: event.id,
59
+ delta: (event.text ?? event.delta ?? ""),
60
+ };
61
+ case "text-end":
62
+ return { type: "text-end", id: event.id };
63
+ case "reasoning-start":
64
+ return { type: "reasoning-start", id: event.id };
65
+ case "reasoning-delta":
66
+ return {
67
+ type: "reasoning-delta",
68
+ id: event.id,
69
+ delta: (event.text ?? event.delta ?? ""),
70
+ };
71
+ case "reasoning-end":
72
+ return { type: "reasoning-end", id: event.id };
73
+ case "tool-input-start":
74
+ return {
75
+ type: "tool-input-start",
76
+ id: event.id,
77
+ toolName: event.toolName,
78
+ dynamic: event.dynamic,
79
+ };
80
+ case "tool-input-delta":
81
+ return {
82
+ type: "tool-input-delta",
83
+ id: event.id,
84
+ delta: (event.delta ?? ""),
85
+ };
86
+ case "tool-input-end":
87
+ return { type: "tool-input-end", id: event.id };
88
+ case "tool-call": {
89
+ const input = event.input ?? event.args ?? event.arguments;
90
+ return {
91
+ type: "tool-call",
92
+ toolCallId: (event.toolCallId ?? event.id ?? ""),
93
+ toolName: event.toolName,
94
+ input: typeof input === "string" ? input : JSON.stringify(input ?? {}),
95
+ };
96
+ }
97
+ case "finish-step": {
98
+ const usage = event.usage ?? event.totalUsage ?? {};
99
+ const rawReason = (event.finishReason ?? event.rawFinishReason ?? "stop");
100
+ return {
101
+ type: "finish",
102
+ finishReason: { unified: mapFinishReason(rawReason), raw: rawReason },
103
+ usage: mapUsage(typeof usage === "object" && usage !== null ? usage : {}),
104
+ };
105
+ }
106
+ case "finish":
107
+ return null;
108
+ case "response-metadata":
109
+ return {
110
+ type: "response-metadata",
111
+ id: event.id,
112
+ modelId: event.modelId,
113
+ };
114
+ case "error":
115
+ return { type: "error", error: event.error ?? event.message ?? "Unknown error" };
116
+ default:
117
+ return null;
118
+ }
119
+ }
120
+ // Assumes line-delimited JSON over SSE: one JSON object per `data:` line.
121
+ // Multi-line `data:` fields are not supported — the buffer splits on `\n`.
122
+ export function parseStreamEvents(body) {
123
+ const reader = body.getReader();
124
+ const decoder = new TextDecoder();
125
+ let buffer = "";
126
+ return new ReadableStream({
127
+ async pull(controller) {
128
+ try {
129
+ while (true) {
130
+ const lines = buffer.split("\n");
131
+ // Strip trailing \r from Windows-style \r\n line endings
132
+ for (let i = 0; i < lines.length; i++) {
133
+ const line = lines[i];
134
+ if (line !== undefined && line.endsWith("\r"))
135
+ lines[i] = line.slice(0, -1);
136
+ }
137
+ buffer = lines.pop() ?? "";
138
+ for (const line of lines) {
139
+ const trimmed = line.trim();
140
+ if (!trimmed || trimmed.startsWith(":") || trimmed === "[DONE]")
141
+ continue;
142
+ let jsonStr = trimmed;
143
+ if (jsonStr.startsWith("data: "))
144
+ jsonStr = jsonStr.slice(6);
145
+ if (jsonStr.startsWith("data:"))
146
+ jsonStr = jsonStr.slice(5);
147
+ if (!jsonStr || jsonStr === "[DONE]")
148
+ continue;
149
+ let parsed;
150
+ try {
151
+ parsed = JSON.parse(jsonStr);
152
+ }
153
+ catch {
154
+ // intentionally silent: skip malformed SSE lines
155
+ continue;
156
+ }
157
+ if (typeof parsed !== "object" || parsed === null || typeof parsed.type !== "string")
158
+ continue;
159
+ const part = toStreamPart(parsed);
160
+ if (part)
161
+ controller.enqueue(part);
162
+ }
163
+ const { done, value } = await reader.read();
164
+ if (done) {
165
+ if (buffer.trim()) {
166
+ const trimmed = buffer.trim();
167
+ if (trimmed && trimmed !== "[DONE]" && !trimmed.startsWith(":")) {
168
+ let jsonStr = trimmed;
169
+ if (jsonStr.startsWith("data: "))
170
+ jsonStr = jsonStr.slice(6);
171
+ if (jsonStr.startsWith("data:"))
172
+ jsonStr = jsonStr.slice(5);
173
+ try {
174
+ const parsed = JSON.parse(jsonStr);
175
+ if (typeof parsed === "object" &&
176
+ parsed !== null &&
177
+ typeof parsed.type === "string") {
178
+ const part = toStreamPart(parsed);
179
+ if (part)
180
+ controller.enqueue(part);
181
+ }
182
+ }
183
+ catch {
184
+ // intentionally silent: skip malformed final buffer
185
+ }
186
+ }
187
+ }
188
+ controller.close();
189
+ return;
190
+ }
191
+ buffer += decoder.decode(value, { stream: true });
192
+ }
193
+ }
194
+ catch (err) {
195
+ controller.enqueue({ type: "error", error: err });
196
+ controller.close();
197
+ }
198
+ },
199
+ cancel() {
200
+ reader.cancel();
201
+ },
202
+ });
203
+ }
package/manifest.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
3
  "generatedAt": "2026-11-09T18:34:31.627Z",
4
- "pluginVersion": "1.2.33",
4
+ "pluginVersion": "1.2.34",
5
5
  "commandCodeVersion": "1.88.5",
6
6
  "commandCodeTarball": "https://registry.npmjs.org/command-code/-/command-code-1.88.5.tgz",
7
7
  "modelCount": 95,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telsoncc/opencode-commandcode",
3
- "version": "1.2.33",
3
+ "version": "1.2.34",
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",
@@ -29,6 +29,7 @@
29
29
  "url": "git+https://github.com/telsoncc/opencode-commandcode.git"
30
30
  },
31
31
  "files": [
32
+ "dist/",
32
33
  "index.ts",
33
34
  "plugin.ts",
34
35
  "plugin-opencode2.ts",
@@ -40,17 +41,20 @@
40
41
  "src/"
41
42
  ],
42
43
  "type": "module",
43
- "main": "index.ts",
44
- "types": "index.ts",
44
+ "main": "dist/index.js",
45
+ "types": "dist/index.d.ts",
45
46
  "exports": {
46
47
  ".": {
47
- "import": "./index.ts"
48
+ "types": "./dist/index.d.ts",
49
+ "import": "./dist/index.js"
48
50
  },
49
51
  "./server": {
50
- "import": "./plugin-opencode2.ts"
52
+ "types": "./dist/plugin-opencode2.d.ts",
53
+ "import": "./dist/plugin-opencode2.js"
51
54
  },
52
55
  "./plugin/opencode2": {
53
- "import": "./plugin-opencode2.ts"
56
+ "types": "./dist/plugin-opencode2.d.ts",
57
+ "import": "./dist/plugin-opencode2.js"
54
58
  }
55
59
  },
56
60
  "publishConfig": {
@@ -66,7 +70,8 @@
66
70
  "test:integration": "bun test tests/integration/",
67
71
  "test:all": "bun test",
68
72
  "typecheck": "tsc --noEmit",
69
- "prepack": "bun run scripts/verify-manifest-version.ts",
73
+ "build": "bun run scripts/build.ts",
74
+ "prepack": "bun run build && bun run scripts/verify-manifest-version.ts",
70
75
  "verify:release-candidate": "bun run scripts/verify-release-candidate.ts",
71
76
  "generate-readme": "bun run scripts/generate-readme.ts",
72
77
  "sync": "bun run scripts/sync-models.ts",
package/plugin.ts CHANGED
@@ -16,9 +16,20 @@ import {
16
16
  import type { CatalogManifest } from "./src/manifest.js";
17
17
 
18
18
  const __dirname = dirname(fileURLToPath(import.meta.url));
19
- const MODELS_PATH = join(__dirname, "models.json");
20
- const VERSION_PATH = join(__dirname, "_version.txt");
21
- const MANIFEST_PATH = join(__dirname, "manifest.json");
19
+
20
+ // Repo layout keeps the catalog next to plugin.ts; published builds emit
21
+ // dist/plugin.js and ship the catalog inside dist/ (and at the package root).
22
+ function resolveAsset(name: string): string {
23
+ for (const dir of [__dirname, dirname(__dirname)]) {
24
+ const candidate = join(dir, name);
25
+ if (existsSync(candidate)) return candidate;
26
+ }
27
+ return join(__dirname, name);
28
+ }
29
+
30
+ const MODELS_PATH = resolveAsset("models.json");
31
+ const VERSION_PATH = resolveAsset("_version.txt");
32
+ const MANIFEST_PATH = resolveAsset("manifest.json");
22
33
 
23
34
  interface PluginFileConfig {
24
35
  disableModelSync?: boolean;
@@ -26,11 +26,16 @@ export function cutKeepAChangelog(markdown: string, version: string, date: strin
26
26
  }
27
27
  }
28
28
 
29
- const before = lines.slice(0, start + 1).join("");
30
29
  const body = lines
31
30
  .slice(start + 1, end)
32
31
  .join("")
33
32
  .replace(/^\n+/, "\n");
33
+ // Nothing was written under [Unreleased] since the last cut: emitting a
34
+ // heading here would only add an empty version section. Releases are also
35
+ // described on GitHub (semantic-release catalog notes), so skip the cut.
36
+ if (body.trim() === "") return markdown;
37
+
38
+ const before = lines.slice(0, start + 1).join("");
34
39
  const after = lines.slice(end).join("");
35
40
  return `${before}\n## [${version}] - ${date}\n${body}${after}`;
36
41
  }
package/src/opencode2.ts CHANGED
@@ -43,9 +43,20 @@ export const COMMANDCODE_ANTHROPIC_PACKAGE = "@opencode/ai/providers/anthropic-c
43
43
  export const COMMANDCODE_ENV_NAMES = ["COMMANDCODE_API_KEY"];
44
44
 
45
45
  const MODULE_DIR = dirname(fileURLToPath(import.meta.url));
46
- const MODELS_PATH = join(MODULE_DIR, "..", "models.json");
47
- const VERSION_PATH = join(MODULE_DIR, "..", "_version.txt");
48
- const MANIFEST_PATH = join(MODULE_DIR, "..", "manifest.json");
46
+
47
+ // Repo layout: src/../ is the package root. Published builds: dist/src/../ is
48
+ // dist/ (catalog copied at build time) with the package root one level above.
49
+ function resolveAsset(name: string): string {
50
+ for (const dir of [join(MODULE_DIR, ".."), join(MODULE_DIR, "..", "..")]) {
51
+ const candidate = join(dir, name);
52
+ if (existsSync(candidate)) return candidate;
53
+ }
54
+ return join(MODULE_DIR, "..", name);
55
+ }
56
+
57
+ const MODELS_PATH = resolveAsset("models.json");
58
+ const VERSION_PATH = resolveAsset("_version.txt");
59
+ const MANIFEST_PATH = resolveAsset("manifest.json");
49
60
 
50
61
  export type V2Cost = {
51
62
  tier?: { type: "context"; size: number };
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Contract between `package.json` and the files a `npm pack` tarball actually
3
+ * ships. The published entrypoints point at compiled output (`dist/`), so a
4
+ * pack that skips the build — or a `files` list that drops `dist/` — produces
5
+ * a package whose imports fail at runtime on hosts without a TypeScript
6
+ * loader (the opencode IDE server runs plain Node inside Electron).
7
+ */
8
+
9
+ export type PackPackageJson = {
10
+ main?: string;
11
+ types?: string;
12
+ exports?: Record<string, string | { import?: string; types?: string }>;
13
+ };
14
+
15
+ /** Normalize `tar -tzf` output, which uses CRLF on Windows and LF on Linux. */
16
+ export function parseTarListing(listing: string): string[] {
17
+ return listing
18
+ .split(/\r?\n/)
19
+ .filter(Boolean)
20
+ .map((entry) => entry.replace(/^package\//, ""));
21
+ }
22
+
23
+ /**
24
+ * Every file `package.json` promises to resolve, relative to the package root.
25
+ * `main` and each `exports` target are included so a build regression cannot
26
+ * ship silently.
27
+ */
28
+ export function declaredEntrypoints(pkg: PackPackageJson): string[] {
29
+ const targets: string[] = [];
30
+ const push = (value: string | undefined): void => {
31
+ if (typeof value !== "string") return;
32
+ targets.push(value.replace(/^\.\//, ""));
33
+ };
34
+
35
+ push(pkg.main);
36
+ for (const entry of Object.values(pkg.exports ?? {})) {
37
+ if (typeof entry === "string") {
38
+ push(entry);
39
+ continue;
40
+ }
41
+ push(entry.import);
42
+ push(entry.types);
43
+ }
44
+ return [...new Set(targets)];
45
+ }
46
+
47
+ /** Entrypoints declared by `package.json` but absent from the tarball. */
48
+ export function missingEntrypoints(packageJson: PackPackageJson, packed: string[]): string[] {
49
+ const present = new Set(packed);
50
+ return declaredEntrypoints(packageJson).filter((entry) => !present.has(entry));
51
+ }