fix: resolve JSON parse error in Oracle after promptAsync refactor (#1681)

This commit is contained in:
YeonGyu-Kim
2026-02-17 01:29:17 +09:00
parent 187c6b0700
commit f4fc2fbbfd
2 changed files with 166 additions and 43 deletions
+59 -21
View File
@@ -1,10 +1,33 @@
import type { DelegateTaskArgs, OpencodeClient } from "./types"
import { isPlanFamily } from "./constants"
import { promptWithModelSuggestionRetry } from "../../shared/model-suggestion-retry"
import {
promptSyncWithModelSuggestionRetry,
promptWithModelSuggestionRetry,
} from "../../shared/model-suggestion-retry"
import { formatDetailedError } from "./error-formatting"
import { getAgentToolRestrictions } from "../../shared/agent-tool-restrictions"
import { setSessionTools } from "../../shared/session-tools-store"
type SendSyncPromptDeps = {
promptWithModelSuggestionRetry: typeof promptWithModelSuggestionRetry
promptSyncWithModelSuggestionRetry: typeof promptSyncWithModelSuggestionRetry
}
const sendSyncPromptDeps: SendSyncPromptDeps = {
promptWithModelSuggestionRetry,
promptSyncWithModelSuggestionRetry,
}
function isOracleAgent(agentToUse: string): boolean {
return agentToUse.toLowerCase() === "oracle"
}
function isUnexpectedEofError(error: unknown): boolean {
const message = error instanceof Error ? error.message : String(error)
const lowered = message.toLowerCase()
return lowered.includes("unexpected eof") || lowered.includes("json parse error")
}
export async function sendSyncPrompt(
client: OpencodeClient,
input: {
@@ -15,29 +38,44 @@ export async function sendSyncPrompt(
categoryModel: { providerID: string; modelID: string; variant?: string } | undefined
toastManager: { removeTask: (id: string) => void } | null | undefined
taskId: string | undefined
}
},
deps: SendSyncPromptDeps = sendSyncPromptDeps
): Promise<string | null> {
const allowTask = isPlanFamily(input.agentToUse)
const tools = {
task: allowTask,
call_omo_agent: true,
question: false,
...getAgentToolRestrictions(input.agentToUse),
}
setSessionTools(input.sessionID, tools)
const promptArgs = {
path: { id: input.sessionID },
body: {
agent: input.agentToUse,
system: input.systemContent,
tools,
parts: [{ type: "text", text: input.args.prompt }],
...(input.categoryModel
? { model: { providerID: input.categoryModel.providerID, modelID: input.categoryModel.modelID } }
: {}),
...(input.categoryModel?.variant ? { variant: input.categoryModel.variant } : {}),
},
}
try {
const allowTask = isPlanFamily(input.agentToUse)
const tools = {
task: allowTask,
call_omo_agent: true,
question: false,
...getAgentToolRestrictions(input.agentToUse),
}
setSessionTools(input.sessionID, tools)
await promptWithModelSuggestionRetry(client, {
path: { id: input.sessionID },
body: {
agent: input.agentToUse,
system: input.systemContent,
tools,
parts: [{ type: "text", text: input.args.prompt }],
...(input.categoryModel ? { model: { providerID: input.categoryModel.providerID, modelID: input.categoryModel.modelID } } : {}),
...(input.categoryModel?.variant ? { variant: input.categoryModel.variant } : {}),
},
})
await deps.promptWithModelSuggestionRetry(client, promptArgs)
} catch (promptError) {
if (isOracleAgent(input.agentToUse) && isUnexpectedEofError(promptError)) {
try {
await deps.promptSyncWithModelSuggestionRetry(client, promptArgs)
return null
} catch (oracleRetryError) {
promptError = oracleRetryError
}
}
if (input.toastManager && input.taskId !== undefined) {
input.toastManager.removeTask(input.taskId)
}