( responseFormat: any, vars?: Record<string, VarValue>, )
| 434 | * @returns The processed response_format with all files loaded |
| 435 | */ |
| 436 | export function maybeLoadResponseFormatFromExternalFile( |
| 437 | responseFormat: any, |
| 438 | vars?: Record<string, VarValue>, |
| 439 | ): any { |
| 440 | if (responseFormat === undefined || responseFormat === null) { |
| 441 | return responseFormat; |
| 442 | } |
| 443 | |
| 444 | // First, render variables and load the outer response_format |
| 445 | const rendered = renderVarsInObject(responseFormat, vars); |
| 446 | const loaded = maybeLoadFromExternalFile(rendered); |
| 447 | |
| 448 | if (!loaded || typeof loaded !== 'object') { |
| 449 | return loaded; |
| 450 | } |
| 451 | |
| 452 | // For json_schema type, check if the nested schema is a file reference |
| 453 | if (loaded.type === 'json_schema') { |
| 454 | const nestedSchema = loaded.schema || loaded.json_schema?.schema; |
| 455 | |
| 456 | if (nestedSchema) { |
| 457 | // Render and load the nested schema |
| 458 | const loadedSchema = maybeLoadFromExternalFile(renderVarsInObject(nestedSchema, vars)); |
| 459 | |
| 460 | // Return with the loaded schema in place |
| 461 | if (loaded.schema !== undefined) { |
| 462 | return { ...loaded, schema: loadedSchema }; |
| 463 | } else if (loaded.json_schema?.schema !== undefined) { |
| 464 | return { |
| 465 | ...loaded, |
| 466 | json_schema: { ...loaded.json_schema, schema: loadedSchema }, |
| 467 | }; |
| 468 | } |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | return loaded; |
| 473 | } |
| 474 | |
| 475 | /** |
| 476 | * Renders variables in a tools object and loads from external file if applicable. |
no test coverage detected
searching dependent graphs…