opencommand-plugin 0.0.2 → 0.0.3
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/dist/index.d.ts +43 -3
- package/dist/index.js +194 -15
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -7,15 +7,42 @@ export interface ProxyStartConfig {
|
|
|
7
7
|
commandCodeToken: string;
|
|
8
8
|
sessionCookie?: string;
|
|
9
9
|
}
|
|
10
|
+
interface CommandCodeModelDefinition {
|
|
11
|
+
id: string;
|
|
12
|
+
name: string;
|
|
13
|
+
description: string;
|
|
14
|
+
reasoning?: boolean;
|
|
15
|
+
context: number;
|
|
16
|
+
output: number;
|
|
17
|
+
cost: {
|
|
18
|
+
input: number;
|
|
19
|
+
output: number;
|
|
20
|
+
cache_read?: number;
|
|
21
|
+
cache_write?: number;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
interface OpenCodeProviderConfig {
|
|
25
|
+
npm: string;
|
|
26
|
+
name: string;
|
|
27
|
+
options: {
|
|
28
|
+
apiKey: string;
|
|
29
|
+
baseURL: string;
|
|
30
|
+
};
|
|
31
|
+
models: Record<string, unknown>;
|
|
32
|
+
}
|
|
33
|
+
interface OpenCodeConfig {
|
|
34
|
+
provider?: Record<string, OpenCodeProviderConfig>;
|
|
35
|
+
}
|
|
10
36
|
interface CookiePair {
|
|
11
37
|
name: string;
|
|
12
38
|
value: string;
|
|
13
39
|
}
|
|
40
|
+
export declare const COMMAND_CODE_GO_PLAN_MODELS: CommandCodeModelDefinition[];
|
|
14
41
|
export declare class ProxyManager {
|
|
15
42
|
private proxyProcess;
|
|
16
43
|
private config;
|
|
17
44
|
private proxyBinaryPath;
|
|
18
|
-
constructor(binaryPath
|
|
45
|
+
constructor(binaryPath?: string);
|
|
19
46
|
findAvailablePort(): Promise<number>;
|
|
20
47
|
start(startConfig: ProxyStartConfig): Promise<ProxyConfig>;
|
|
21
48
|
stop(): Promise<void>;
|
|
@@ -52,8 +79,9 @@ export declare class OpenCommandPlugin {
|
|
|
52
79
|
private readonly commandCodeTokenKey;
|
|
53
80
|
private readonly legacyTokenKey;
|
|
54
81
|
private readonly sessionCookieKey;
|
|
55
|
-
constructor(proxyBinaryPath
|
|
82
|
+
constructor(proxyBinaryPath?: string, storageDir?: string);
|
|
56
83
|
activate(): Promise<void>;
|
|
84
|
+
ensureStarted(): Promise<ProxyConfig | undefined>;
|
|
57
85
|
deactivate(): Promise<void>;
|
|
58
86
|
private loadCommandCodeToken;
|
|
59
87
|
private loadSessionCookie;
|
|
@@ -65,4 +93,16 @@ export declare class OpenCommandPlugin {
|
|
|
65
93
|
private restartIfPossible;
|
|
66
94
|
getProxyConfig(): string;
|
|
67
95
|
}
|
|
68
|
-
export
|
|
96
|
+
export declare function registerOpenCommandProvider(config: OpenCodeConfig, baseURL?: string): void;
|
|
97
|
+
export declare const OpenCommandOpenCodePlugin: () => Promise<{
|
|
98
|
+
auth: {
|
|
99
|
+
provider: string;
|
|
100
|
+
loader: () => Promise<{
|
|
101
|
+
apiKey: string;
|
|
102
|
+
baseURL: string;
|
|
103
|
+
} | null>;
|
|
104
|
+
methods: never[];
|
|
105
|
+
};
|
|
106
|
+
config: (config: OpenCodeConfig) => Promise<void>;
|
|
107
|
+
}>;
|
|
108
|
+
export default OpenCommandOpenCodePlugin;
|
package/dist/index.js
CHANGED
|
@@ -33,7 +33,8 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.OpenCommandPlugin = exports.BrowserCookieExtractor = exports.SecretStorage = exports.ProxyManager = void 0;
|
|
36
|
+
exports.OpenCommandOpenCodePlugin = exports.OpenCommandPlugin = exports.BrowserCookieExtractor = exports.SecretStorage = exports.ProxyManager = exports.COMMAND_CODE_GO_PLAN_MODELS = void 0;
|
|
37
|
+
exports.registerOpenCommandProvider = registerOpenCommandProvider;
|
|
37
38
|
const cp = __importStar(require("child_process"));
|
|
38
39
|
const crypto = __importStar(require("crypto"));
|
|
39
40
|
const fs = __importStar(require("fs"));
|
|
@@ -41,8 +42,107 @@ const fsp = __importStar(require("fs/promises"));
|
|
|
41
42
|
const net = __importStar(require("net"));
|
|
42
43
|
const os = __importStar(require("os"));
|
|
43
44
|
const path = __importStar(require("path"));
|
|
45
|
+
const PROVIDER_ID = "opencommand";
|
|
46
|
+
const PROVIDER_NAME = "CommandCode";
|
|
47
|
+
const PROVIDER_API_KEY_PLACEHOLDER = "opencommand";
|
|
48
|
+
const DEFAULT_PROXY_BASE_URL = "http://localhost:3000/v1";
|
|
49
|
+
exports.COMMAND_CODE_GO_PLAN_MODELS = [
|
|
50
|
+
{
|
|
51
|
+
id: "deepseek/deepseek-v4-pro",
|
|
52
|
+
name: "DeepSeek V4 Pro",
|
|
53
|
+
description: "Hybrid-attention long-context reasoning",
|
|
54
|
+
reasoning: true,
|
|
55
|
+
context: 1000000,
|
|
56
|
+
output: 8192,
|
|
57
|
+
cost: { input: 1.74, output: 3.48, cache_read: 0.0145 },
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
id: "deepseek/deepseek-v4-flash",
|
|
61
|
+
name: "DeepSeek V4 Flash",
|
|
62
|
+
description: "Fast hybrid-attention reasoning",
|
|
63
|
+
reasoning: true,
|
|
64
|
+
context: 1000000,
|
|
65
|
+
output: 8192,
|
|
66
|
+
cost: { input: 0.14, output: 0.28, cache_read: 0.01 },
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
id: "moonshotai/Kimi-K2.6",
|
|
70
|
+
name: "Kimi K2.6",
|
|
71
|
+
description: "Long-horizon coding with vision",
|
|
72
|
+
context: 256000,
|
|
73
|
+
output: 8192,
|
|
74
|
+
cost: { input: 0.95, output: 4.0, cache_read: 0.16 },
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
id: "moonshotai/Kimi-K2.5",
|
|
78
|
+
name: "Kimi K2.5",
|
|
79
|
+
description: "Multimodal frontend coding",
|
|
80
|
+
context: 256000,
|
|
81
|
+
output: 8192,
|
|
82
|
+
cost: { input: 0.6, output: 3.0, cache_read: 0.1 },
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
id: "zai-org/GLM-5.1",
|
|
86
|
+
name: "GLM-5.1",
|
|
87
|
+
description: "Long-horizon autonomous coding agent",
|
|
88
|
+
context: 200000,
|
|
89
|
+
output: 8192,
|
|
90
|
+
cost: { input: 1.4, output: 4.4, cache_read: 0.26 },
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
id: "zai-org/GLM-5",
|
|
94
|
+
name: "GLM-5",
|
|
95
|
+
description: "Multi-mode thinking and long-range planning",
|
|
96
|
+
context: 200000,
|
|
97
|
+
output: 8192,
|
|
98
|
+
cost: { input: 1.0, output: 3.2, cache_read: 0.2 },
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
id: "MiniMaxAI/MiniMax-M2.7",
|
|
102
|
+
name: "MiniMax M2.7",
|
|
103
|
+
description: "End-to-end software engineering agent",
|
|
104
|
+
context: 200000,
|
|
105
|
+
output: 8192,
|
|
106
|
+
cost: { input: 0.3, output: 1.2, cache_read: 0.06 },
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
id: "MiniMaxAI/MiniMax-M2.5",
|
|
110
|
+
name: "MiniMax M2.5",
|
|
111
|
+
description: "Cross-platform full-stack agentic development",
|
|
112
|
+
context: 200000,
|
|
113
|
+
output: 8192,
|
|
114
|
+
cost: { input: 0.27, output: 0.95, cache_read: 0.03 },
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
id: "Qwen/Qwen3.6-Max-Preview",
|
|
118
|
+
name: "Qwen 3.6 Max Preview",
|
|
119
|
+
description: "Vibe coding and efficient agent execution",
|
|
120
|
+
reasoning: true,
|
|
121
|
+
context: 200000,
|
|
122
|
+
output: 8192,
|
|
123
|
+
cost: { input: 1.3, output: 7.8, cache_read: 0.26, cache_write: 1.63 },
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
id: "Qwen/Qwen3.6-Plus",
|
|
127
|
+
name: "Qwen 3.6 Plus",
|
|
128
|
+
description: "Agentic coding and reasoning",
|
|
129
|
+
reasoning: true,
|
|
130
|
+
context: 200000,
|
|
131
|
+
output: 8192,
|
|
132
|
+
cost: { input: 0.5, output: 3.0, cache_read: 0.1 },
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
id: "stepfun/Step-3.5-Flash",
|
|
136
|
+
name: "Step 3.5 Flash",
|
|
137
|
+
description: "Fast sparse-MoE agentic reasoning",
|
|
138
|
+
reasoning: true,
|
|
139
|
+
context: 1000000,
|
|
140
|
+
output: 8192,
|
|
141
|
+
cost: { input: 0.1, output: 0.3, cache_read: 0.02 },
|
|
142
|
+
},
|
|
143
|
+
];
|
|
44
144
|
class ProxyManager {
|
|
45
|
-
constructor(binaryPath) {
|
|
145
|
+
constructor(binaryPath = resolveProxyBinaryPath()) {
|
|
46
146
|
this.proxyProcess = null;
|
|
47
147
|
this.config = null;
|
|
48
148
|
this.proxyBinaryPath = binaryPath;
|
|
@@ -386,7 +486,7 @@ const firefoxCookieQuery = [
|
|
|
386
486
|
"SELECT host, name, value, '' FROM moz_cookies WHERE host LIKE '%commandcode.ai%';",
|
|
387
487
|
].join("\n");
|
|
388
488
|
class OpenCommandPlugin {
|
|
389
|
-
constructor(proxyBinaryPath, storageDir) {
|
|
489
|
+
constructor(proxyBinaryPath = resolveProxyBinaryPath(), storageDir) {
|
|
390
490
|
this.commandCodeTokenKey = "opencommand.command_code_token";
|
|
391
491
|
this.legacyTokenKey = "opencommand.cc_session_token";
|
|
392
492
|
this.sessionCookieKey = "opencommand.cc_session_cookie";
|
|
@@ -397,26 +497,34 @@ class OpenCommandPlugin {
|
|
|
397
497
|
}
|
|
398
498
|
async activate() {
|
|
399
499
|
console.log("OpenCommand Plugin activating...");
|
|
500
|
+
try {
|
|
501
|
+
const config = await this.ensureStarted();
|
|
502
|
+
if (config)
|
|
503
|
+
console.log(`✓ OpenCommand proxy ready at ${config.port}`);
|
|
504
|
+
}
|
|
505
|
+
catch (error) {
|
|
506
|
+
console.error("Failed to start proxy:", error);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
async ensureStarted() {
|
|
510
|
+
const existingConfig = this.proxyManager.getConfig();
|
|
511
|
+
if (existingConfig && this.proxyManager.isRunning())
|
|
512
|
+
return existingConfig;
|
|
400
513
|
const commandCodeToken = await this.loadCommandCodeToken();
|
|
401
514
|
if (!commandCodeToken) {
|
|
402
515
|
console.warn("No COMMAND_CODE_TOKEN found. Please configure your CommandCode API key.");
|
|
403
|
-
return;
|
|
516
|
+
return undefined;
|
|
404
517
|
}
|
|
405
518
|
const sessionCookie = await this.loadSessionCookie();
|
|
406
519
|
if (!sessionCookie) {
|
|
407
520
|
console.warn("No CommandCode Studio cookie found. Inference works, but usage scraping may be unavailable.");
|
|
408
521
|
}
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
this.saveOpenCodeConfig(config);
|
|
416
|
-
}
|
|
417
|
-
catch (error) {
|
|
418
|
-
console.error("Failed to start proxy:", error);
|
|
419
|
-
}
|
|
522
|
+
const config = await this.proxyManager.start({
|
|
523
|
+
commandCodeToken,
|
|
524
|
+
sessionCookie,
|
|
525
|
+
});
|
|
526
|
+
this.saveOpenCodeConfig(config);
|
|
527
|
+
return config;
|
|
420
528
|
}
|
|
421
529
|
async deactivate() {
|
|
422
530
|
console.log("OpenCommand Plugin deactivating...");
|
|
@@ -500,3 +608,74 @@ function firstDefined(...values) {
|
|
|
500
608
|
}
|
|
501
609
|
return undefined;
|
|
502
610
|
}
|
|
611
|
+
function resolveProxyBinaryPath() {
|
|
612
|
+
const candidates = [
|
|
613
|
+
process.env.OPENCOMMAND_PROXY_PATH,
|
|
614
|
+
path.join(os.homedir(), ".opencommand", "proxy"),
|
|
615
|
+
path.join(process.cwd(), "packages", "proxy", "proxy"),
|
|
616
|
+
path.join(__dirname, "proxy"),
|
|
617
|
+
].filter((candidate) => Boolean(candidate));
|
|
618
|
+
return candidates.find((candidate) => fs.existsSync(candidate)) || candidates[candidates.length - 1];
|
|
619
|
+
}
|
|
620
|
+
function openCodeModelConfig(model) {
|
|
621
|
+
return {
|
|
622
|
+
id: model.id,
|
|
623
|
+
name: model.name,
|
|
624
|
+
description: model.description,
|
|
625
|
+
reasoning: model.reasoning ?? false,
|
|
626
|
+
tool_call: true,
|
|
627
|
+
attachment: false,
|
|
628
|
+
cost: model.cost,
|
|
629
|
+
limit: {
|
|
630
|
+
context: model.context,
|
|
631
|
+
output: model.output,
|
|
632
|
+
},
|
|
633
|
+
modalities: {
|
|
634
|
+
input: ["text"],
|
|
635
|
+
output: ["text"],
|
|
636
|
+
},
|
|
637
|
+
};
|
|
638
|
+
}
|
|
639
|
+
function registerOpenCommandProvider(config, baseURL = DEFAULT_PROXY_BASE_URL) {
|
|
640
|
+
const models = {};
|
|
641
|
+
for (const model of exports.COMMAND_CODE_GO_PLAN_MODELS) {
|
|
642
|
+
models[model.id] = openCodeModelConfig(model);
|
|
643
|
+
}
|
|
644
|
+
config.provider = {
|
|
645
|
+
...(config.provider ?? {}),
|
|
646
|
+
[PROVIDER_ID]: {
|
|
647
|
+
npm: "@ai-sdk/openai-compatible",
|
|
648
|
+
name: PROVIDER_NAME,
|
|
649
|
+
options: {
|
|
650
|
+
apiKey: PROVIDER_API_KEY_PLACEHOLDER,
|
|
651
|
+
baseURL,
|
|
652
|
+
},
|
|
653
|
+
models,
|
|
654
|
+
},
|
|
655
|
+
};
|
|
656
|
+
}
|
|
657
|
+
let runtimePlugin;
|
|
658
|
+
function getRuntimePlugin() {
|
|
659
|
+
runtimePlugin ?? (runtimePlugin = new OpenCommandPlugin());
|
|
660
|
+
return runtimePlugin;
|
|
661
|
+
}
|
|
662
|
+
const OpenCommandOpenCodePlugin = async () => ({
|
|
663
|
+
auth: {
|
|
664
|
+
provider: PROVIDER_ID,
|
|
665
|
+
loader: async () => {
|
|
666
|
+
const proxyConfig = await getRuntimePlugin().ensureStarted();
|
|
667
|
+
if (!proxyConfig)
|
|
668
|
+
return null;
|
|
669
|
+
return {
|
|
670
|
+
apiKey: PROVIDER_API_KEY_PLACEHOLDER,
|
|
671
|
+
baseURL: `http://localhost:${proxyConfig.port}/v1`,
|
|
672
|
+
};
|
|
673
|
+
},
|
|
674
|
+
methods: [],
|
|
675
|
+
},
|
|
676
|
+
config: async (config) => {
|
|
677
|
+
registerOpenCommandProvider(config);
|
|
678
|
+
},
|
|
679
|
+
});
|
|
680
|
+
exports.OpenCommandOpenCodePlugin = OpenCommandOpenCodePlugin;
|
|
681
|
+
exports.default = exports.OpenCommandOpenCodePlugin;
|