export const keyboardEmulationDependencyDeclarations = [
    {
        dependencyId: "runtime.execEngine.computeruse.keyboardAction",
        kind: "runtime",
        required: true,
        description: "Runtime-owned keyboard action support exposed through BaseToolExecutorPort.computeruse.keyboardAction.",
    },
    {
        dependencyId: "runtime.governancePlane.toolInvocationGrant",
        kind: "permission",
        required: true,
        description: "dryRun:false requires an affirmative runtime guard before keyboard event dispatch.",
    },
    {
        dependencyId: "runtime.focusManager.keyboardTarget",
        kind: "runtime",
        required: true,
        description: "Runtime owns focus, active target resolution, platform input backend, event emission, and cleanup.",
    },
];
function runtimeActionKind(action) {
    if (action.kind === "key-press")
        return "press";
    if (action.kind === "text")
        return "type";
    return "shortcut";
}
export function createRuntimeKeyboardEmulationProvider(executor) {
    const keyboardAction = executor?.computeruse?.keyboardAction;
    if (keyboardAction === undefined)
        return undefined;
    return async (request) => {
        const result = await keyboardAction({
            action: runtimeActionKind(request.action),
            text: request.action.kind === "text" ? request.action.text : undefined,
            keys: request.action.kind === "shortcut"
                ? request.action.keys
                : request.action.kind === "key-press"
                    ? [request.action.key]
                    : undefined,
            metadata: {
                runtimeId: request.context.runtimeId,
                sessionId: request.context.sessionId,
                invocationId: request.context.invocationId,
                targetHint: request.targetHint,
                actionIndex: request.actionIndex,
                actionKind: request.action.kind,
                repeat: request.action.kind === "key-press" ? request.action.repeat : undefined,
                textCharacters: request.action.kind === "text" ? request.action.text.length : undefined,
                runtimeGuardAccepted: true,
                auditMetadata: request.context.auditMetadata,
            },
        });
        if (!result.ok) {
            throw new Error(`PUBLIC_SAFE_PROVIDER_FAILURE:${result.error.message}`);
        }
        return {
            actionId: result.output.actionId,
            metadata: {
                ...(result.output.metadata ?? {}),
                ...(result.metadata ?? {}),
            },
        };
    };
}
