@herouucn/opencode-commandcode 0.1.5 → 0.1.7

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 (2) hide show
  1. package/package.json +1 -1
  2. package/plugin.ts +14 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@herouucn/opencode-commandcode",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "Inject Command Code API provider into opencode — access Claude, GPT, Gemini, DeepSeek, Qwen, Kimi, GLM, MiniMax & Step via unified Command Code API. / 将 Command Code API provider 注入 opencode —— 通过统一的 Command Code API 使用 Claude、GPT、Gemini、DeepSeek、Qwen、Kimi、GLM、MiniMax 和 Step 模型。",
5
5
  "keywords": [
6
6
  "ai",
package/plugin.ts CHANGED
@@ -34,13 +34,13 @@ interface PluginFileConfig {
34
34
  const DEFAULT_REMOTE_CATALOG_URL =
35
35
  "https://raw.githubusercontent.com/herouu/opencode-commandcode/main/models.json";
36
36
 
37
+ // 默认 OpenAI 兼容端点:与 @ai-sdk/openai-compatible 搭配,等价于 README 手动配置推荐值。
38
+ const DEFAULT_BASE_URL = "https://api.commandcode.ai/provider/v1/";
39
+
37
40
  function loadPluginConfig(): PluginFileConfig {
38
41
  const dir = join(homedir(), ".config", "opencode");
39
- const configPath = [
40
- join(dir, "opencode-commandcode.json"),
41
- join(dir, "commandcode-go-opencode-provider.json"),
42
- ].find((p) => existsSync(p));
43
- if (!configPath) return {};
42
+ const configPath = join(dir, "opencode-commandcode.json");
43
+ if (!existsSync(configPath)) return {};
44
44
  try {
45
45
  return JSON.parse(readFileSync(configPath, "utf-8"));
46
46
  } catch {
@@ -108,13 +108,11 @@ function readBundledVersion(): string | null {
108
108
  export default async function commandcodePlugin() {
109
109
  return {
110
110
  config: async (config: Record<string, unknown>) => {
111
- if (!(config as Record<string, unknown>).provider) {
112
- (config as Record<string, unknown>).provider = { commandcode: {} };
113
- }
114
- const cc = (
115
- (config as Record<string, unknown>).provider as Record<string, Record<string, unknown>>
116
- )?.commandcode as Record<string, unknown> | undefined;
117
- if (!cc) return;
111
+ const providers = ((config as Record<string, unknown>).provider ??= {}) as Record<
112
+ string,
113
+ Record<string, unknown>
114
+ >;
115
+ const cc = (providers.commandcode ??= {}) as Record<string, unknown>;
118
116
 
119
117
  const pluginCfg = loadPluginConfig();
120
118
  const debug = pluginCfg.debugStartupLogs === true;
@@ -123,9 +121,12 @@ export default async function commandcodePlugin() {
123
121
  process.env.COMMANDCODE_PACKAGE_PATH?.trim() ||
124
122
  "";
125
123
 
126
- if (!cc.npm) cc.npm = "commandcode-go-opencode-provider";
124
+ if (!cc.npm) cc.npm = "@ai-sdk/openai-compatible";
127
125
  if (!cc.name) cc.name = "Command Code";
128
126
  if (!cc.env) cc.env = ["COMMANDCODE_API_KEY"];
127
+ const options = (cc.options as Record<string, unknown> | undefined) ?? {};
128
+ cc.options = options;
129
+ if (typeof options.baseURL !== "string") options.baseURL = DEFAULT_BASE_URL;
129
130
 
130
131
  if (cc.models) return;
131
132