@genflowai/opencode-autosetup 1.0.0 → 2.0.0
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/package.json +1 -1
- package/setup-opencode.js +20 -8
package/package.json
CHANGED
package/setup-opencode.js
CHANGED
|
@@ -10,7 +10,6 @@ import { spawn } from "node:child_process";
|
|
|
10
10
|
const PROVIDER_ID = "genflowai";
|
|
11
11
|
const BASE_URL = "https://genflowai.co/v1";
|
|
12
12
|
const MODELS_URL = `${BASE_URL}/models`;
|
|
13
|
-
const DEFAULT_MODEL = "gpt-5.5";
|
|
14
13
|
const CONFIG_DIR = process.env.OPENCODE_CONFIG_DIR || join(homedir(), ".config", "opencode");
|
|
15
14
|
const CONFIG_PATH = join(CONFIG_DIR, "opencode.json");
|
|
16
15
|
|
|
@@ -118,6 +117,14 @@ async function fetchAvailableModels() {
|
|
|
118
117
|
}
|
|
119
118
|
}
|
|
120
119
|
|
|
120
|
+
function getLatestModel(models) {
|
|
121
|
+
return models[0] ?? "gpt-5.5";
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function buildModelsConfig(models) {
|
|
125
|
+
return Object.fromEntries(models.map((model) => [model, { name: model }]));
|
|
126
|
+
}
|
|
127
|
+
|
|
121
128
|
function printModelHint(models) {
|
|
122
129
|
if (models.length === 0) {
|
|
123
130
|
console.log(`Daftar model: ${MODELS_URL}`);
|
|
@@ -131,7 +138,9 @@ function printModelHint(models) {
|
|
|
131
138
|
console.log(`Total model: ${models.length}. Lihat lengkap: https://genflowai.co/models`);
|
|
132
139
|
}
|
|
133
140
|
|
|
134
|
-
function buildConfig(existingConfig, apiKey, model) {
|
|
141
|
+
function buildConfig(existingConfig, apiKey, model, availableModels) {
|
|
142
|
+
const models = availableModels.length > 0 ? availableModels : [model];
|
|
143
|
+
|
|
135
144
|
return {
|
|
136
145
|
...existingConfig,
|
|
137
146
|
$schema: existingConfig.$schema ?? "https://opencode.ai/config.json",
|
|
@@ -147,9 +156,7 @@ function buildConfig(existingConfig, apiKey, model) {
|
|
|
147
156
|
},
|
|
148
157
|
models: {
|
|
149
158
|
...(existingConfig.provider?.[PROVIDER_ID]?.models ?? {}),
|
|
150
|
-
|
|
151
|
-
name: model
|
|
152
|
-
}
|
|
159
|
+
...buildModelsConfig(models)
|
|
153
160
|
}
|
|
154
161
|
}
|
|
155
162
|
}
|
|
@@ -171,15 +178,19 @@ async function main() {
|
|
|
171
178
|
const availableModels = await fetchAvailableModels();
|
|
172
179
|
printModelHint(availableModels);
|
|
173
180
|
|
|
174
|
-
const
|
|
175
|
-
const model =
|
|
181
|
+
const modelArg = getArgValue("--model").trim();
|
|
182
|
+
const model = modelArg || getLatestModel(availableModels);
|
|
183
|
+
|
|
184
|
+
if (!modelArg) {
|
|
185
|
+
console.log(`Model otomatis: ${model}`);
|
|
186
|
+
}
|
|
176
187
|
|
|
177
188
|
if (availableModels.length > 0 && !availableModels.includes(model)) {
|
|
178
189
|
throw new Error(`Model "${model}" tidak ditemukan di ${MODELS_URL}. Cek https://genflowai.co/models`);
|
|
179
190
|
}
|
|
180
191
|
|
|
181
192
|
const existingConfig = await readExistingConfig();
|
|
182
|
-
const nextConfig = buildConfig(existingConfig, apiKey, model);
|
|
193
|
+
const nextConfig = buildConfig(existingConfig, apiKey, model, availableModels);
|
|
183
194
|
|
|
184
195
|
await mkdir(CONFIG_DIR, { recursive: true });
|
|
185
196
|
await writeFile(CONFIG_PATH, `${JSON.stringify(nextConfig, null, 2)}\n`, "utf8");
|
|
@@ -187,6 +198,7 @@ async function main() {
|
|
|
187
198
|
console.log(`\nSelesai. Config opencode ditulis ke: ${CONFIG_PATH}`);
|
|
188
199
|
console.log(`Provider: ${PROVIDER_ID}`);
|
|
189
200
|
console.log(`Model: ${PROVIDER_ID}/${model}`);
|
|
201
|
+
console.log(`Total model ditambahkan: ${availableModels.length || 1}`);
|
|
190
202
|
console.log("Jalankan: opencode");
|
|
191
203
|
} finally {
|
|
192
204
|
rl.close();
|