n8n/packages/@n8n/instance-ai/evaluations/utils/user-proxy/deterministic.ts
José Braulio González Valido 81ea56fa6b
test(ai-builder): Add multi-turn capability for IAI evals (no-changelog) (#30586)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-21 13:03:35 +00:00

41 lines
1.4 KiB
TypeScript

// Deterministic shortcuts that bypass the LLM for events with no user-intent signal.
import type { InstanceAiConfirmRequest } from '@n8n/api-types';
import type { CapturedEvent } from '../../types';
import { getEventPayload, tryInfrastructureResponse } from '../confirmation-payload';
export function tryDeterministicConfirmationResponse(
event: CapturedEvent,
): InstanceAiConfirmRequest | undefined {
const infra = tryInfrastructureResponse(event);
if (infra) return infra;
const payload = getEventPayload(event);
// Setup wizard with credentials-only requests: skip. The eval has no
// credentials and applying an empty payload loops the agent ("partial 0/N").
// Mixed (credential + parameter issues, or parameter-only) → LLM fills params.
if (Array.isArray(payload.setupRequests)) {
if (
payload.setupRequests.length > 0 &&
payload.setupRequests.every(isCredentialOnlySetupRequest)
) {
return { kind: 'approval', approved: false };
}
return undefined;
}
// inputType=questions, text, plan-review, or default approval — LLM handles.
return undefined;
}
function isCredentialOnlySetupRequest(value: unknown): boolean {
if (typeof value !== 'object' || value === null) return false;
const req = value as Record<string, unknown>;
if (typeof req.credentialType !== 'string') return false;
const issues = req.parameterIssues;
if (issues && typeof issues === 'object' && Object.keys(issues).length > 0) return false;
return true;
}