opencommand-plugin 0.0.4 → 0.0.5
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/README.md +5 -0
- package/bin/opencode-plugin.js +3 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +35 -68
- package/package.json +17 -3
package/README.md
CHANGED
|
@@ -46,3 +46,8 @@ npm run build
|
|
|
46
46
|
```bash
|
|
47
47
|
npm test -- --runInBand
|
|
48
48
|
```
|
|
49
|
+
|
|
50
|
+
## v0.0.5 OpenCode loading fix
|
|
51
|
+
|
|
52
|
+
`opencommand-plugin@0.0.5` publishes an explicit ESM wrapper at `bin/opencode-plugin.js` and should be pinned in `opencode.jsonc` as `opencommand-plugin@0.0.5` (or newer). This avoids stale `@latest` cache entries and ensures OpenCode sees the plugin default export as a function.
|
|
53
|
+
|
package/dist/index.d.ts
CHANGED
|
@@ -100,6 +100,19 @@ export declare function fetchCommandCodePlanModels(commandCodeToken: string, api
|
|
|
100
100
|
export declare function parseCommandCodePlanID(body: unknown): string | undefined;
|
|
101
101
|
export declare function registerOpenCommandProvider(config: OpenCodeConfig, baseURL?: string, modelDefinitions?: CommandCodeModelDefinition[]): void;
|
|
102
102
|
export declare const OpenCommandOpenCodePlugin: () => Promise<{
|
|
103
|
+
provider: {
|
|
104
|
+
opencommand: {
|
|
105
|
+
npm: string;
|
|
106
|
+
name: string;
|
|
107
|
+
options: {
|
|
108
|
+
apiKey: string;
|
|
109
|
+
baseURL: string;
|
|
110
|
+
};
|
|
111
|
+
models: {
|
|
112
|
+
[k: string]: Record<string, unknown>;
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
};
|
|
103
116
|
auth: {
|
|
104
117
|
provider: string;
|
|
105
118
|
loader: () => Promise<{
|
|
@@ -111,3 +124,4 @@ export declare const OpenCommandOpenCodePlugin: () => Promise<{
|
|
|
111
124
|
config: (config: OpenCodeConfig) => Promise<void>;
|
|
112
125
|
}>;
|
|
113
126
|
export default OpenCommandOpenCodePlugin;
|
|
127
|
+
export { OpenCommandOpenCodePlugin as opencommandPlugin };
|
package/dist/index.js
CHANGED
|
@@ -1,57 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.OpenCommandOpenCodePlugin = exports.OpenCommandPlugin = exports.BrowserCookieExtractor = exports.SecretStorage = exports.ProxyManager = exports.COMMAND_CODE_GO_PLAN_MODELS = void 0;
|
|
37
|
-
exports.fetchOpenCommandModels = fetchOpenCommandModels;
|
|
38
|
-
exports.commandCodeModelsForPlan = commandCodeModelsForPlan;
|
|
39
|
-
exports.fetchCommandCodePlanModels = fetchCommandCodePlanModels;
|
|
40
|
-
exports.parseCommandCodePlanID = parseCommandCodePlanID;
|
|
41
|
-
exports.registerOpenCommandProvider = registerOpenCommandProvider;
|
|
42
|
-
const cp = __importStar(require("child_process"));
|
|
43
|
-
const crypto = __importStar(require("crypto"));
|
|
44
|
-
const fs = __importStar(require("fs"));
|
|
45
|
-
const fsp = __importStar(require("fs/promises"));
|
|
46
|
-
const net = __importStar(require("net"));
|
|
47
|
-
const os = __importStar(require("os"));
|
|
48
|
-
const path = __importStar(require("path"));
|
|
1
|
+
import * as cp from "child_process";
|
|
2
|
+
import * as crypto from "crypto";
|
|
3
|
+
import * as fs from "fs";
|
|
4
|
+
import * as fsp from "fs/promises";
|
|
5
|
+
import * as net from "net";
|
|
6
|
+
import * as os from "os";
|
|
7
|
+
import * as path from "path";
|
|
49
8
|
const PROVIDER_ID = "opencommand";
|
|
50
9
|
const PROVIDER_NAME = "CommandCode";
|
|
51
10
|
const PROVIDER_API_KEY_PLACEHOLDER = "opencommand";
|
|
52
11
|
const DEFAULT_PROXY_BASE_URL = "http://localhost:3000/v1";
|
|
53
12
|
const COMMAND_CODE_API_BASE_URL = "https://api.commandcode.ai";
|
|
54
|
-
|
|
13
|
+
export const COMMAND_CODE_GO_PLAN_MODELS = [
|
|
55
14
|
{
|
|
56
15
|
id: "deepseek/deepseek-v4-pro",
|
|
57
16
|
name: "DeepSeek V4 Pro",
|
|
@@ -226,7 +185,7 @@ const COMMAND_CODE_PREMIUM_MODELS = [
|
|
|
226
185
|
cost: { input: 0, output: 0 },
|
|
227
186
|
},
|
|
228
187
|
];
|
|
229
|
-
class ProxyManager {
|
|
188
|
+
export class ProxyManager {
|
|
230
189
|
constructor(binaryPath = resolveProxyBinaryPath()) {
|
|
231
190
|
this.proxyProcess = null;
|
|
232
191
|
this.config = null;
|
|
@@ -347,8 +306,7 @@ class ProxyManager {
|
|
|
347
306
|
return this.proxyProcess !== null && !this.proxyProcess.killed;
|
|
348
307
|
}
|
|
349
308
|
}
|
|
350
|
-
|
|
351
|
-
class SecretStorage {
|
|
309
|
+
export class SecretStorage {
|
|
352
310
|
constructor(storageDir = `${process.env.HOME || "/tmp"}/.opencommand`) {
|
|
353
311
|
this.filePath = `${storageDir}/opencommand-secrets.json`;
|
|
354
312
|
}
|
|
@@ -386,8 +344,7 @@ class SecretStorage {
|
|
|
386
344
|
await this.writeStore(store);
|
|
387
345
|
}
|
|
388
346
|
}
|
|
389
|
-
|
|
390
|
-
class BrowserCookieExtractor {
|
|
347
|
+
export class BrowserCookieExtractor {
|
|
391
348
|
constructor(homeDir = os.homedir()) {
|
|
392
349
|
this.homeDir = homeDir;
|
|
393
350
|
}
|
|
@@ -481,7 +438,8 @@ class BrowserCookieExtractor {
|
|
|
481
438
|
try {
|
|
482
439
|
fs.copyFileSync(profile.cookieDatabase, tmpDb);
|
|
483
440
|
const query = profile.browser === "Firefox" ? firefoxCookieQuery : chromiumCookieQuery;
|
|
484
|
-
const output = cp.execFileSync("/usr/bin/sqlite3", [tmpDb
|
|
441
|
+
const output = cp.execFileSync("/usr/bin/sqlite3", [tmpDb], {
|
|
442
|
+
input: query,
|
|
485
443
|
encoding: "utf8",
|
|
486
444
|
timeout: 5000,
|
|
487
445
|
});
|
|
@@ -548,7 +506,6 @@ class BrowserCookieExtractor {
|
|
|
548
506
|
}
|
|
549
507
|
}
|
|
550
508
|
}
|
|
551
|
-
exports.BrowserCookieExtractor = BrowserCookieExtractor;
|
|
552
509
|
function decryptMacChromiumCookie(encryptedValue, safeStoragePassword) {
|
|
553
510
|
try {
|
|
554
511
|
const payload = encryptedValue.subarray(0, 3).toString() === "v10"
|
|
@@ -570,7 +527,7 @@ const firefoxCookieQuery = [
|
|
|
570
527
|
".mode tabs",
|
|
571
528
|
"SELECT host, name, value, '' FROM moz_cookies WHERE host LIKE '%commandcode.ai%';",
|
|
572
529
|
].join("\n");
|
|
573
|
-
class OpenCommandPlugin {
|
|
530
|
+
export class OpenCommandPlugin {
|
|
574
531
|
constructor(proxyBinaryPath = resolveProxyBinaryPath(), storageDir) {
|
|
575
532
|
this.commandCodeTokenKey = "opencommand.command_code_token";
|
|
576
533
|
this.legacyTokenKey = "opencommand.cc_session_token";
|
|
@@ -684,7 +641,6 @@ class OpenCommandPlugin {
|
|
|
684
641
|
return JSON.stringify(config, null, 2);
|
|
685
642
|
}
|
|
686
643
|
}
|
|
687
|
-
exports.OpenCommandPlugin = OpenCommandPlugin;
|
|
688
644
|
function firstDefined(...values) {
|
|
689
645
|
for (const value of values) {
|
|
690
646
|
const trimmed = value?.trim();
|
|
@@ -736,7 +692,7 @@ function modelFromProxy(model) {
|
|
|
736
692
|
cost: model.cost ?? { input: 0, output: 0 },
|
|
737
693
|
};
|
|
738
694
|
}
|
|
739
|
-
async function fetchOpenCommandModels(baseURL) {
|
|
695
|
+
export async function fetchOpenCommandModels(baseURL) {
|
|
740
696
|
try {
|
|
741
697
|
const response = await fetch(`${baseURL.replace(/\/$/, "")}/models`, {
|
|
742
698
|
headers: { Authorization: `Bearer ${PROVIDER_API_KEY_PLACEHOLDER}` },
|
|
@@ -754,8 +710,8 @@ async function fetchOpenCommandModels(baseURL) {
|
|
|
754
710
|
return undefined;
|
|
755
711
|
}
|
|
756
712
|
}
|
|
757
|
-
function commandCodeModelsForPlan(planID) {
|
|
758
|
-
const models = [...
|
|
713
|
+
export function commandCodeModelsForPlan(planID) {
|
|
714
|
+
const models = [...COMMAND_CODE_GO_PLAN_MODELS];
|
|
759
715
|
if (!planCanUsePremium(planID))
|
|
760
716
|
return models;
|
|
761
717
|
for (const model of COMMAND_CODE_PREMIUM_MODELS) {
|
|
@@ -765,7 +721,7 @@ function commandCodeModelsForPlan(planID) {
|
|
|
765
721
|
}
|
|
766
722
|
return models;
|
|
767
723
|
}
|
|
768
|
-
async function fetchCommandCodePlanModels(commandCodeToken, apiBaseURL = COMMAND_CODE_API_BASE_URL) {
|
|
724
|
+
export async function fetchCommandCodePlanModels(commandCodeToken, apiBaseURL = COMMAND_CODE_API_BASE_URL) {
|
|
769
725
|
try {
|
|
770
726
|
const response = await fetch(`${apiBaseURL.replace(/\/$/, "")}/alpha/billing/subscriptions`, {
|
|
771
727
|
headers: {
|
|
@@ -784,7 +740,7 @@ async function fetchCommandCodePlanModels(commandCodeToken, apiBaseURL = COMMAND
|
|
|
784
740
|
return undefined;
|
|
785
741
|
}
|
|
786
742
|
}
|
|
787
|
-
function parseCommandCodePlanID(body) {
|
|
743
|
+
export function parseCommandCodePlanID(body) {
|
|
788
744
|
const root = body;
|
|
789
745
|
if (typeof root?.planId === "string" && root.planId.trim())
|
|
790
746
|
return root.planId.trim();
|
|
@@ -813,7 +769,7 @@ function planCanUseOpus(planID) {
|
|
|
813
769
|
function isOpusModel(modelID) {
|
|
814
770
|
return modelID.toLowerCase().includes("opus");
|
|
815
771
|
}
|
|
816
|
-
function registerOpenCommandProvider(config, baseURL = DEFAULT_PROXY_BASE_URL, modelDefinitions =
|
|
772
|
+
export function registerOpenCommandProvider(config, baseURL = DEFAULT_PROXY_BASE_URL, modelDefinitions = COMMAND_CODE_GO_PLAN_MODELS) {
|
|
817
773
|
const models = {};
|
|
818
774
|
for (const model of modelDefinitions) {
|
|
819
775
|
models[model.id] = openCodeModelConfig(model);
|
|
@@ -836,7 +792,18 @@ function getRuntimePlugin() {
|
|
|
836
792
|
runtimePlugin ?? (runtimePlugin = new OpenCommandPlugin());
|
|
837
793
|
return runtimePlugin;
|
|
838
794
|
}
|
|
839
|
-
const OpenCommandOpenCodePlugin = async () => ({
|
|
795
|
+
export const OpenCommandOpenCodePlugin = async () => ({
|
|
796
|
+
provider: {
|
|
797
|
+
[PROVIDER_ID]: {
|
|
798
|
+
npm: "@ai-sdk/openai-compatible",
|
|
799
|
+
name: PROVIDER_NAME,
|
|
800
|
+
options: {
|
|
801
|
+
apiKey: PROVIDER_API_KEY_PLACEHOLDER,
|
|
802
|
+
baseURL: DEFAULT_PROXY_BASE_URL,
|
|
803
|
+
},
|
|
804
|
+
models: Object.fromEntries(COMMAND_CODE_GO_PLAN_MODELS.map((model) => [model.id, openCodeModelConfig(model)])),
|
|
805
|
+
},
|
|
806
|
+
},
|
|
840
807
|
auth: {
|
|
841
808
|
provider: PROVIDER_ID,
|
|
842
809
|
loader: async () => {
|
|
@@ -860,8 +827,8 @@ const OpenCommandOpenCodePlugin = async () => ({
|
|
|
860
827
|
(await fetchCommandCodePlanModels(proxyConfig.commandCodeToken)) ??
|
|
861
828
|
(await fetchOpenCommandModels(baseURL));
|
|
862
829
|
}
|
|
863
|
-
registerOpenCommandProvider(config, baseURL, models ??
|
|
830
|
+
registerOpenCommandProvider(config, baseURL, models ?? COMMAND_CODE_GO_PLAN_MODELS);
|
|
864
831
|
},
|
|
865
832
|
});
|
|
866
|
-
|
|
867
|
-
|
|
833
|
+
export default OpenCommandOpenCodePlugin;
|
|
834
|
+
export { OpenCommandOpenCodePlugin as opencommandPlugin };
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencommand-plugin",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "OpenCommand - CommandCode API Plugin for OpenCode",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "./bin/opencode-plugin.js",
|
|
6
|
+
"module": "./bin/opencode-plugin.js",
|
|
6
7
|
"scripts": {
|
|
7
8
|
"build": "tsc",
|
|
8
9
|
"test": "jest",
|
|
@@ -30,7 +31,20 @@
|
|
|
30
31
|
},
|
|
31
32
|
"files": [
|
|
32
33
|
"dist/**",
|
|
34
|
+
"bin/**",
|
|
33
35
|
"README.md",
|
|
34
36
|
"package.json"
|
|
35
|
-
]
|
|
37
|
+
],
|
|
38
|
+
"type": "module",
|
|
39
|
+
"types": "./dist/index.d.ts",
|
|
40
|
+
"exports": {
|
|
41
|
+
".": {
|
|
42
|
+
"types": "./dist/index.d.ts",
|
|
43
|
+
"import": "./bin/opencode-plugin.js"
|
|
44
|
+
},
|
|
45
|
+
"./dist/index.js": {
|
|
46
|
+
"types": "./dist/index.d.ts",
|
|
47
|
+
"import": "./dist/index.js"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
36
50
|
}
|