mirror of
https://github.com/simstudioai/sim.git
synced 2026-04-06 03:00:16 -04:00
improvement(copilot): tool configs to show nested props (#2936)
This commit is contained in:
committed by
GitHub
parent
2f0f246002
commit
42159c23b9
@@ -123,6 +123,8 @@ function resolveSubBlockOptions(sb: SubBlockConfig): string[] | undefined {
|
||||
interface OutputFieldSchema {
|
||||
type: string
|
||||
description?: string
|
||||
properties?: Record<string, OutputFieldSchema>
|
||||
items?: { type: string }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -256,6 +258,42 @@ function mapSubBlockTypeToSchemaType(type: string): string {
|
||||
return typeMap[type] || 'string'
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts a single output field schema, including nested properties
|
||||
*/
|
||||
function extractOutputField(def: any): OutputFieldSchema {
|
||||
if (typeof def === 'string') {
|
||||
return { type: def }
|
||||
}
|
||||
|
||||
if (typeof def !== 'object' || def === null) {
|
||||
return { type: 'any' }
|
||||
}
|
||||
|
||||
const field: OutputFieldSchema = {
|
||||
type: def.type || 'any',
|
||||
}
|
||||
|
||||
if (def.description) {
|
||||
field.description = def.description
|
||||
}
|
||||
|
||||
// Include nested properties if present
|
||||
if (def.properties && typeof def.properties === 'object') {
|
||||
field.properties = {}
|
||||
for (const [propKey, propDef] of Object.entries(def.properties)) {
|
||||
field.properties[propKey] = extractOutputField(propDef)
|
||||
}
|
||||
}
|
||||
|
||||
// Include items schema for arrays
|
||||
if (def.items && typeof def.items === 'object') {
|
||||
field.items = { type: def.items.type || 'any' }
|
||||
}
|
||||
|
||||
return field
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts trigger outputs from the first available trigger
|
||||
*/
|
||||
@@ -272,15 +310,7 @@ function extractTriggerOutputs(blockConfig: any): Record<string, OutputFieldSche
|
||||
const trigger = getTrigger(triggerId)
|
||||
if (trigger.outputs) {
|
||||
for (const [key, def] of Object.entries(trigger.outputs)) {
|
||||
if (typeof def === 'string') {
|
||||
outputs[key] = { type: def }
|
||||
} else if (typeof def === 'object' && def !== null) {
|
||||
const typedDef = def as { type?: string; description?: string }
|
||||
outputs[key] = {
|
||||
type: typedDef.type || 'any',
|
||||
description: typedDef.description,
|
||||
}
|
||||
}
|
||||
outputs[key] = extractOutputField(def)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -312,11 +342,7 @@ function extractOutputs(
|
||||
const tool = toolsRegistry[toolId]
|
||||
if (tool?.outputs) {
|
||||
for (const [key, def] of Object.entries(tool.outputs)) {
|
||||
const typedDef = def as { type: string; description?: string }
|
||||
outputs[key] = {
|
||||
type: typedDef.type || 'any',
|
||||
description: typedDef.description,
|
||||
}
|
||||
outputs[key] = extractOutputField(def)
|
||||
}
|
||||
return outputs
|
||||
}
|
||||
@@ -329,15 +355,7 @@ function extractOutputs(
|
||||
// Use block-level outputs
|
||||
if (blockConfig.outputs) {
|
||||
for (const [key, def] of Object.entries(blockConfig.outputs)) {
|
||||
if (typeof def === 'string') {
|
||||
outputs[key] = { type: def }
|
||||
} else if (typeof def === 'object' && def !== null) {
|
||||
const typedDef = def as { type?: string; description?: string }
|
||||
outputs[key] = {
|
||||
type: typedDef.type || 'any',
|
||||
description: typedDef.description,
|
||||
}
|
||||
}
|
||||
outputs[key] = extractOutputField(def)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user