(value: unknown)
| 13472 | } |
| 13473 | |
| 13474 | function parseAgentJobPatch(value: unknown): { patch: AgentJobPatch; invalidFields: string[] } { |
| 13475 | const parsed = value && typeof value === 'object' && !Array.isArray(value) |
| 13476 | ? value as Record<string, unknown> |
| 13477 | : {} as Record<string, unknown>; |
| 13478 | const patch: AgentJobPatch = {}; |
| 13479 | const invalidFields: string[] = []; |
| 13480 | const title = compactWhitespace(parsed.title ?? ''); |
| 13481 | if (title) { |
| 13482 | patch.title = truncateText(title, 40); |
| 13483 | } |
| 13484 | const goal = compactWhitespace(parsed.goal ?? ''); |
| 13485 | if (goal) { |
| 13486 | patch.goal = goal; |
| 13487 | } |
| 13488 | const expectedOutput = compactWhitespace(parsed.expectedOutput ?? parsed.expected_output ?? ''); |
| 13489 | if (expectedOutput) { |
| 13490 | patch.expectedOutput = expectedOutput; |
| 13491 | } |
| 13492 | const plan = Array.isArray(parsed.plan) |
| 13493 | ? parsed.plan.map((line) => compactWhitespace(line)).filter(Boolean).slice(0, 8) |
| 13494 | : []; |
| 13495 | if (plan.length > 0) { |
| 13496 | patch.plan = plan; |
| 13497 | } |
| 13498 | if (parsed.category !== undefined) { |
| 13499 | const category = parseAgentCategoryValue(parsed.category); |
| 13500 | if (category) { |
| 13501 | patch.category = category; |
| 13502 | } else { |
| 13503 | invalidFields.push('category'); |
| 13504 | } |
| 13505 | } |
| 13506 | const riskValue = parsed.riskLevel ?? parsed.risk_level; |
| 13507 | if (riskValue !== undefined) { |
| 13508 | const riskLevel = parseAgentRiskValue(riskValue); |
| 13509 | if (riskLevel) { |
| 13510 | patch.riskLevel = riskLevel; |
| 13511 | } else { |
| 13512 | invalidFields.push('riskLevel'); |
| 13513 | } |
| 13514 | } |
| 13515 | if (parsed.mode !== undefined) { |
| 13516 | const mode = parseAgentModeValue(parsed.mode); |
| 13517 | if (mode) { |
| 13518 | patch.mode = mode; |
| 13519 | } else { |
| 13520 | invalidFields.push('mode'); |
| 13521 | } |
| 13522 | } |
| 13523 | return { |
| 13524 | patch, |
| 13525 | invalidFields, |
| 13526 | }; |
| 13527 | } |
| 13528 | |
| 13529 | function parseAgentDraftCandidate(value: unknown): AgentDraftCandidate | null { |
| 13530 | const parsed = parseJsonObject(value); |
no test coverage detected