Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/opencode/src/global/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ if (version !== CACHE_VERSION) {
}),
),
)
} catch (e) {}
} catch (e) {
// Log cache cleanup failure but continue - non-critical operation
console.warn("Failed to clean cache directory:", e)
}
await Filesystem.write(path.join(Global.Path.cache, "version"), CACHE_VERSION)
}
9 changes: 8 additions & 1 deletion packages/opencode/src/provider/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1372,7 +1372,14 @@ export namespace Provider {

const mod = await import(installedPath)

const fn = mod[Object.keys(mod).find((key) => key.startsWith("create"))!]
const createKey = Object.keys(mod).find((key) => key.startsWith("create"))
if (!createKey) {
throw new InitError(
{ providerID: model.providerID },
{ cause: new Error(`No create function found in module ${installedPath}`) },
)
}
const fn = mod[createKey]
const loaded = fn({
name: model.providerID,
...options,
Expand Down
29 changes: 25 additions & 4 deletions packages/opencode/src/util/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,31 @@ export namespace Rpc {

export function listen(rpc: Definition) {
onmessage = async (evt) => {
const parsed = JSON.parse(evt.data)
if (parsed.type === "rpc.request") {
const result = await rpc[parsed.method](parsed.input)
postMessage(JSON.stringify({ type: "rpc.result", result, id: parsed.id }))
try {
const parsed = JSON.parse(evt.data)
if (parsed.type === "rpc.request") {
const method = rpc[parsed.method]
if (!method) {
postMessage(
JSON.stringify({
type: "rpc.error",
id: parsed.id,
error: `Unknown method: ${parsed.method}`,
}),
)
return
}
const result = await method(parsed.input)
postMessage(JSON.stringify({ type: "rpc.result", result, id: parsed.id }))
}
} catch (e) {
// Send error response for JSON parse errors or method execution failures
postMessage(
JSON.stringify({
type: "rpc.error",
error: e instanceof Error ? e.message : String(e),
}),
)
}
}
}
Expand Down
Loading