mirror of
https://github.com/simstudioai/sim.git
synced 2026-01-09 15:07:55 -05:00
Add support for arrays in schema
This commit is contained in:
@@ -75,24 +75,52 @@ export const AgentBlock: BlockConfig<AgentResponse> = {
|
||||
properties: {
|
||||
name: {
|
||||
type: 'string',
|
||||
minLength: 1,
|
||||
description: 'Name of the field',
|
||||
},
|
||||
type: {
|
||||
type: 'string',
|
||||
enum: ['string', 'number', 'boolean', 'array', 'object'],
|
||||
description: 'Type of the field',
|
||||
},
|
||||
isArray: {
|
||||
type: 'boolean',
|
||||
description: 'Whether this field contains multiple values',
|
||||
},
|
||||
items: {
|
||||
type: 'object',
|
||||
description: 'Schema for array items (required when isArray is true)',
|
||||
properties: {
|
||||
type: {
|
||||
type: 'string',
|
||||
enum: ['string', 'number', 'boolean', 'object'],
|
||||
},
|
||||
properties: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
name: { type: 'string' },
|
||||
type: {
|
||||
type: 'string',
|
||||
enum: ['string', 'number', 'boolean'],
|
||||
},
|
||||
},
|
||||
required: ['name', 'type'],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
description: {
|
||||
type: 'string',
|
||||
description: 'Description of what this field represents',
|
||||
},
|
||||
},
|
||||
required: ['name', 'type'],
|
||||
additionalProperties: false,
|
||||
},
|
||||
minItems: 1,
|
||||
},
|
||||
},
|
||||
required: ['fields'],
|
||||
additionalProperties: false,
|
||||
},
|
||||
},
|
||||
temperature: { type: 'number', required: false },
|
||||
|
||||
@@ -296,7 +296,9 @@ export class Executor {
|
||||
const response = await executeProviderRequest(providerId, {
|
||||
model,
|
||||
systemPrompt: inputs.systemPrompt,
|
||||
context: inputs.context,
|
||||
context: Array.isArray(inputs.context)
|
||||
? JSON.stringify(inputs.context, null, 2)
|
||||
: inputs.context,
|
||||
tools: tools.length > 0 ? tools : undefined,
|
||||
temperature: inputs.temperature,
|
||||
maxTokens: inputs.maxTokens,
|
||||
@@ -512,13 +514,22 @@ export class Executor {
|
||||
|
||||
// If a valid leaf is found
|
||||
if (replacementValue !== undefined) {
|
||||
// Replace the placeholder in the string
|
||||
resolvedValue = resolvedValue.replace(
|
||||
match,
|
||||
typeof replacementValue === 'object'
|
||||
? JSON.stringify(replacementValue)
|
||||
: String(replacementValue)
|
||||
)
|
||||
// Special handling for context field to ensure proper formatting
|
||||
if (key === 'context') {
|
||||
// If it's not a string, stringify it for context
|
||||
resolvedValue =
|
||||
typeof replacementValue === 'string'
|
||||
? replacementValue
|
||||
: JSON.stringify(replacementValue, null, 2)
|
||||
} else {
|
||||
// For all other fields, use existing logic
|
||||
resolvedValue = resolvedValue.replace(
|
||||
match,
|
||||
typeof replacementValue === 'object'
|
||||
? JSON.stringify(replacementValue)
|
||||
: String(replacementValue)
|
||||
)
|
||||
}
|
||||
} else {
|
||||
throw new Error(
|
||||
`No value found at path "${path}" in block "${sourceBlock.metadata?.title}".`
|
||||
|
||||
Reference in New Issue
Block a user