Skip to content

Commit 6ecd011

Browse files
committed
tui: allow specifying custom models file path via OPENCODE_MODELS_PATH
Users can now configure their own models configuration file by setting the OPENCODE_MODELS_PATH environment variable, providing more flexibility for testing and configuration.
1 parent 8e5db30 commit 6ecd011

4 files changed

Lines changed: 4 additions & 6 deletions

File tree

.github/workflows/test.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,6 @@ jobs:
6161
printf '%s\n' "XDG_STATE_HOME=${{ runner.temp }}/opencode-e2e/state" >> "$GITHUB_ENV"
6262
fi
6363
64-
- name: Copy models fixture
65-
run: |
66-
cp "${{ github.workspace }}/packages/opencode/test/tool/fixtures/models-api.json" "${{ github.workspace }}/packages/opencode/src/provider/models-snapshot.ts"
67-
6864
- name: Seed opencode data
6965
if: matrix.settings.name != 'windows'
7066
working-directory: packages/opencode

packages/opencode/src/flag/flag.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export namespace Flag {
4747
export const OPENCODE_EXPERIMENTAL_PLAN_MODE = OPENCODE_EXPERIMENTAL || truthy("OPENCODE_EXPERIMENTAL_PLAN_MODE")
4848
export const OPENCODE_EXPERIMENTAL_MARKDOWN = truthy("OPENCODE_EXPERIMENTAL_MARKDOWN")
4949
export const OPENCODE_MODELS_URL = process.env["OPENCODE_MODELS_URL"]
50+
export const OPENCODE_MODELS_PATH = process.env["OPENCODE_MODELS_PATH"]
5051

5152
function number(key: string) {
5253
const value = process.env[key]

packages/opencode/src/provider/models.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ export namespace ModelsDev {
8585
}
8686

8787
export const Data = lazy(async () => {
88-
const file = Bun.file(filepath)
88+
const file = Bun.file(Flag.OPENCODE_MODELS_PATH ?? filepath)
8989
const result = await file.json().catch(() => {})
90-
if (result && typeof result === "object" && Object.keys(result).length > 0) return result
90+
if (result) return result
9191
// @ts-ignore
9292
const snapshot = await import("./models-snapshot")
9393
.then((m) => m.snapshot as Record<string, unknown>)

packages/opencode/test/preload.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ process.env["XDG_DATA_HOME"] = path.join(dir, "share")
2525
process.env["XDG_CACHE_HOME"] = path.join(dir, "cache")
2626
process.env["XDG_CONFIG_HOME"] = path.join(dir, "config")
2727
process.env["XDG_STATE_HOME"] = path.join(dir, "state")
28+
process.env["OPENCODE_MODELS_PATH"] = path.join(import.meta.dir, "tool", "fixtures", "models-api.json")
2829

2930
// Write the cache version file to prevent global/index.ts from clearing the cache
3031
const cacheDir = path.join(dir, "cache", "opencode")

0 commit comments

Comments
 (0)