(
rawSpec: unknown,
options: { allowMissingOutputSchema: boolean }
)
| 3060 | } |
| 3061 | |
| 3062 | function parseWorkflowAgentSpec( |
| 3063 | rawSpec: unknown, |
| 3064 | options: { allowMissingOutputSchema: boolean } |
| 3065 | ): WorkflowAgentSpec { |
| 3066 | assert(rawSpec != null && typeof rawSpec === "object", "agent requires a spec object"); |
| 3067 | const spec = rawSpec as Record<string, unknown>; |
| 3068 | assert(typeof spec.id === "string", "agent replay boundary requires a stable id"); |
| 3069 | assert( |
| 3070 | typeof spec.prompt === "string" && spec.prompt.length > 0, |
| 3071 | "agent requires a non-empty prompt" |
| 3072 | ); |
| 3073 | const parsed: WorkflowAgentSpec = { |
| 3074 | id: spec.id, |
| 3075 | prompt: spec.prompt, |
| 3076 | }; |
| 3077 | if (typeof spec.title === "string" && spec.title.length > 0) { |
| 3078 | parsed.title = spec.title; |
| 3079 | } |
| 3080 | if (typeof spec.agentId === "string" && spec.agentId.length > 0) { |
| 3081 | parsed.agentId = spec.agentId; |
| 3082 | } |
| 3083 | const modelString = parseWorkflowAgentModelString(spec.modelString); |
| 3084 | if (modelString !== undefined) { |
| 3085 | parsed.modelString = modelString; |
| 3086 | } |
| 3087 | const thinkingLevel = parseWorkflowAgentThinkingLevel(spec.thinkingLevel); |
| 3088 | if (thinkingLevel !== undefined) { |
| 3089 | parsed.thinkingLevel = thinkingLevel; |
| 3090 | } |
| 3091 | if (spec.isolation !== undefined) { |
| 3092 | assert( |
| 3093 | spec.isolation === "fork" || spec.isolation === "none", |
| 3094 | 'agent isolation must be "fork" or "none"' |
| 3095 | ); |
| 3096 | parsed.isolation = spec.isolation; |
| 3097 | } |
| 3098 | const timeout = parseWorkflowAgentTimeoutSpec(spec.timeout); |
| 3099 | if (timeout !== undefined) { |
| 3100 | parsed.timeout = timeout; |
| 3101 | } |
| 3102 | if (spec.markdownOnly !== undefined) { |
| 3103 | assert(spec.markdownOnly === true, "agent markdownOnly must be true when provided"); |
| 3104 | parsed.markdownOnly = true; |
| 3105 | } |
| 3106 | if (spec.outputSchema === undefined) { |
| 3107 | assert( |
| 3108 | options.allowMissingOutputSchema || parsed.markdownOnly === true, |
| 3109 | `Workflow agent step ${parsed.id} must declare outputSchema` |
| 3110 | ); |
| 3111 | } else { |
| 3112 | if (!options.allowMissingOutputSchema) { |
| 3113 | validateWorkflowAgentOutputSchema(parsed.id, spec.outputSchema); |
| 3114 | } |
| 3115 | parsed.outputSchema = spec.outputSchema; |
| 3116 | } |
| 3117 | if (spec.onRefusal !== undefined) { |
| 3118 | assert( |
| 3119 | spec.onRefusal === "fail" || spec.onRefusal === "fallback", |
no test coverage detected