ace914f1ef
- Fix #1991 crash: optional chaining for task-history sessionID access - Fix #1992 think-mode: add antigravity entries to HIGH_VARIANT_MAP - Fix #1949 Copilot premium misattribution: use createInternalAgentTextPart - Fix #1982 load_skills: pass directory to discoverSkills for project-level skills - Fix command priority: sort scopePriority before .find(), project-first return - Fix Google provider transform: apply in userFallbackModels path - Fix ralph-loop TUI: optional chaining for event handler - Fix runtime-fallback: unify dual fallback engines, remove HTTP 400 from retry, fix pendingFallbackModel stuck state, add priority gate to skip model-fallback when runtime-fallback is active - Fix Prometheus task system: exempt from todowrite/todoread deny - Fix background_output: default full_session to true - Remove orphan hooks: hashline-edit-diff-enhancer (redundant with hashline_edit built-in diff), task-reminder (dead code) - Remove orphan config entries: 3 stale hook names from Zod schema - Fix disabled_hooks schema: accept arbitrary strings for forward compatibility - Register json-error-recovery hook in tool-guard pipeline - Add disabled_hooks gating for question-label-truncator, task-resume-info, claude-code-hooks - Update test expectations to match new behavior
104 lines
3.5 KiB
TypeScript
104 lines
3.5 KiB
TypeScript
import type { DelegateTaskArgs, OpencodeClient } from "./types"
|
|
import { isPlanFamily } from "./constants"
|
|
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"
|
|
import { createInternalAgentTextPart } from "../../shared/internal-initiator-marker"
|
|
|
|
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: {
|
|
sessionID: string
|
|
agentToUse: string
|
|
args: DelegateTaskArgs
|
|
systemContent: string | undefined
|
|
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: [createInternalAgentTextPart(input.args.prompt)],
|
|
...(input.categoryModel
|
|
? { model: { providerID: input.categoryModel.providerID, modelID: input.categoryModel.modelID } }
|
|
: {}),
|
|
...(input.categoryModel?.variant ? { variant: input.categoryModel.variant } : {}),
|
|
},
|
|
}
|
|
|
|
try {
|
|
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)
|
|
}
|
|
const errorMessage = promptError instanceof Error ? promptError.message : String(promptError)
|
|
if (errorMessage.includes("agent.name") || errorMessage.includes("undefined")) {
|
|
return formatDetailedError(new Error(`Agent "${input.agentToUse}" not found. Make sure the agent is registered in your opencode.json or provided by a plugin.`), {
|
|
operation: "Send prompt to agent",
|
|
args: input.args,
|
|
sessionID: input.sessionID,
|
|
agent: input.agentToUse,
|
|
category: input.args.category,
|
|
})
|
|
}
|
|
return formatDetailedError(promptError, {
|
|
operation: "Send prompt",
|
|
args: input.args,
|
|
sessionID: input.sessionID,
|
|
agent: input.agentToUse,
|
|
category: input.args.category,
|
|
})
|
|
}
|
|
|
|
return null
|
|
}
|