( toolConfig: ToolConfig, userProvidedParams: Record<string, unknown> )
| 539 | } |
| 540 | |
| 541 | export async function createLLMToolSchema( |
| 542 | toolConfig: ToolConfig, |
| 543 | userProvidedParams: Record<string, unknown> |
| 544 | ): Promise<LLMToolSchemaResult> { |
| 545 | const schema: ToolSchema = { |
| 546 | type: 'object', |
| 547 | properties: {}, |
| 548 | required: [], |
| 549 | } |
| 550 | |
| 551 | for (const [paramId, param] of Object.entries(toolConfig.params)) { |
| 552 | const enrichmentConfig = toolConfig.schemaEnrichment?.[paramId] |
| 553 | |
| 554 | const isWorkflowInputMapping = |
| 555 | toolConfig.id === 'workflow_executor' && paramId === 'inputMapping' |
| 556 | |
| 557 | if (enrichmentConfig) { |
| 558 | const dependencyValue = userProvidedParams[enrichmentConfig.dependsOn] as string |
| 559 | if (!dependencyValue) { |
| 560 | continue |
| 561 | } |
| 562 | |
| 563 | const propertySchema = buildParameterSchema(toolConfig.id, paramId, param) |
| 564 | const enrichedSchema = await enrichmentConfig.enrichSchema(dependencyValue) |
| 565 | |
| 566 | if (enrichedSchema) { |
| 567 | safeAssign(propertySchema, enrichedSchema as Record<string, unknown>) |
| 568 | schema.properties[paramId] = propertySchema |
| 569 | |
| 570 | if (param.required) { |
| 571 | schema.required.push(paramId) |
| 572 | } |
| 573 | } |
| 574 | continue |
| 575 | } |
| 576 | |
| 577 | if (!isWorkflowInputMapping) { |
| 578 | if (isNonEmpty(userProvidedParams[paramId])) { |
| 579 | continue |
| 580 | } |
| 581 | |
| 582 | if (param.visibility === 'user-only') { |
| 583 | continue |
| 584 | } |
| 585 | |
| 586 | if (param.visibility === 'hidden') { |
| 587 | continue |
| 588 | } |
| 589 | } |
| 590 | |
| 591 | const propertySchema = buildParameterSchema(toolConfig.id, paramId, param) |
| 592 | |
| 593 | if (isWorkflowInputMapping) { |
| 594 | const workflowId = userProvidedParams.workflowId as string |
| 595 | if (workflowId) { |
| 596 | await applyDynamicSchemaForWorkflow(propertySchema, workflowId) |
| 597 | } |
| 598 | } |
no test coverage detected