/**
 * OpenCode provider implementation
 */
import { callOpenCode, callOpenCodeCustom } from '../opencode/index.js';
import { resolveOpencodeApiKey } from '../config/index.js';
function toOpenCodeOptions(options) {
    if (!options.model) {
        throw new Error("OpenCode provider requires model in 'provider/model' format (e.g. 'opencode/big-pickle').");
    }
    return {
        cwd: options.cwd,
        abortSignal: options.abortSignal,
        sessionId: options.sessionId,
        model: options.model,
        allowedTools: options.allowedTools,
        permissionMode: options.permissionMode,
        networkAccess: options.providerOptions?.opencode?.networkAccess,
        variant: options.providerOptions?.opencode?.variant,
        onStream: options.onStream,
        onAskUserQuestion: options.onAskUserQuestion,
        opencodeApiKey: options.opencodeApiKey ?? resolveOpencodeApiKey(),
        outputSchema: options.outputSchema,
    };
}
/** OpenCode provider — delegates to OpenCode SDK */
export class OpenCodeProvider {
    supportsStructuredOutput = true;
    setup(config) {
        const { name, systemPrompt } = config;
        if (systemPrompt) {
            return {
                call: async (prompt, options) => {
                    return callOpenCodeCustom(name, prompt, systemPrompt, toOpenCodeOptions(options));
                },
            };
        }
        return {
            call: async (prompt, options) => {
                return callOpenCode(name, prompt, toOpenCodeOptions(options));
            },
        };
    }
}
//# sourceMappingURL=opencode.js.map