-
Notifications
You must be signed in to change notification settings - Fork 2
fix: harden opencode webui flows #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,6 @@ config | |
| opencode-src | ||
| temp | ||
|
|
||
| .git | ||
| .github | ||
| .gitignore | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import { readFileSync } from 'fs' | ||
| import path from 'path' | ||
|
|
||
| type BuildInfo = { | ||
| packageVersion: string | ||
| buildTime: string | ||
| git: { | ||
| sha: string | ||
| shortSha: string | ||
| dirty: boolean | ||
| } | ||
| } | ||
|
|
||
| const DEFAULT_BUILD_INFO: BuildInfo = { | ||
| packageVersion: 'unknown', | ||
| buildTime: 'unknown', | ||
| git: { | ||
| sha: 'unknown', | ||
| shortSha: 'unknown', | ||
| dirty: false, | ||
| }, | ||
| } | ||
|
|
||
| let cachedBuildInfo: BuildInfo | null = null | ||
|
|
||
| export function getBuildInfo(): BuildInfo { | ||
| if (cachedBuildInfo) { | ||
| return cachedBuildInfo | ||
| } | ||
|
|
||
| const buildInfoPath = path.join(process.cwd(), 'build-info.json') | ||
|
|
||
| try { | ||
| const parsed = JSON.parse(readFileSync(buildInfoPath, 'utf8')) | ||
| cachedBuildInfo = { | ||
| packageVersion: typeof parsed.packageVersion === 'string' ? parsed.packageVersion : DEFAULT_BUILD_INFO.packageVersion, | ||
| buildTime: typeof parsed.buildTime === 'string' ? parsed.buildTime : DEFAULT_BUILD_INFO.buildTime, | ||
| git: { | ||
| sha: typeof parsed.git?.sha === 'string' ? parsed.git.sha : DEFAULT_BUILD_INFO.git.sha, | ||
| shortSha: typeof parsed.git?.shortSha === 'string' ? parsed.git.shortSha : DEFAULT_BUILD_INFO.git.shortSha, | ||
| dirty: typeof parsed.git?.dirty === 'boolean' ? parsed.git.dirty : DEFAULT_BUILD_INFO.git.dirty, | ||
| }, | ||
| } | ||
| } catch { | ||
| cachedBuildInfo = DEFAULT_BUILD_INFO | ||
| } | ||
|
|
||
| return cachedBuildInfo | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,32 @@ import { ENV } from '@opencode-webui/shared' | |
|
|
||
| const OPENCODE_SERVER_URL = `http://127.0.0.1:${ENV.OPENCODE.PORT}` | ||
|
|
||
| function enrichProviderPayload(payload: unknown) { | ||
| if (!payload || typeof payload !== 'object' || !Array.isArray((payload as { providers?: unknown[] }).providers)) { | ||
| return payload | ||
| } | ||
|
|
||
| return { | ||
| ...(payload as Record<string, unknown>), | ||
| providers: (payload as { providers: Array<Record<string, unknown>> }).providers.map((provider) => { | ||
| const authMethod = provider.id === 'github-copilot' ? 'oauth' : 'apiKey' | ||
| const options = provider.options && typeof provider.options === 'object' | ||
| ? { ...(provider.options as Record<string, unknown>) } | ||
| : undefined | ||
|
|
||
| if (authMethod === 'oauth' && options) { | ||
| delete options.apiKey | ||
| } | ||
|
|
||
| return { | ||
| ...provider, | ||
| authMethod, | ||
| ...(options ? { options } : {}), | ||
| } | ||
| }), | ||
| } | ||
| } | ||
|
|
||
| export async function patchOpenCodeConfig(config: Record<string, unknown>): Promise<boolean> { | ||
| try { | ||
| const response = await fetch(`${OPENCODE_SERVER_URL}/config`, { | ||
|
|
@@ -53,6 +79,18 @@ export async function proxyRequest(request: Request) { | |
| } | ||
| }) | ||
|
|
||
| if (request.method === 'GET' && cleanPath === '/config/providers') { | ||
| const payload = await response.json() | ||
| return new Response(JSON.stringify(enrichProviderPayload(payload)), { | ||
| status: response.status, | ||
| statusText: response.statusText, | ||
| headers: { | ||
| ...responseHeaders, | ||
| 'content-type': 'application/json', | ||
| }, | ||
| }) | ||
| } | ||
|
Comment on lines
+82
to
+92
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This calls Fix it with Roo Code or mention @roomote and request a fix. |
||
|
|
||
| return new Response(response.body, { | ||
| status: response.status, | ||
| statusText: response.statusText, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.gitis no longer ignored in the Docker build context. This can significantly increase build time/context size and risks shipping repository history (and potentially sensitive data) into intermediate build layers/caches. Prefer keeping.gitignored and pass git SHA/dirty state via build args/labels (or CI env) to generate build-info.json without including the full repo history in the context.