diff --git a/src/actors.ts b/src/actors.ts index 092adf4e..f07ee969 100644 --- a/src/actors.ts +++ b/src/actors.ts @@ -102,6 +102,26 @@ export function truncateActorReadme(readme: string, limit = ACTOR_README_MAX_LEN const prunedReadme = lines.filter((line) => line.startsWith('#')); return `${readmeFirst}\n\nREADME was truncated because it was too long. Remaining headers:\n${prunedReadme.join(', ')}`; } +/** + * Helps determine the type of items in an array schema property. + * Priority order: explicit type in items > prefill type > default value type > editor type. + */ +export function inferArrayItemType(property: SchemaProperties): string | null { + return property.items?.type + || (property.prefill && typeof property.prefill) + || (property.default && typeof property.default) + || (property.editor && getEditorItemType(property.editor)) + || null; + + function getEditorItemType(editor: string): string | null { + const editorTypeMap: Record = { + requestListSources: 'object', + stringList: 'string', + }; + return editorTypeMap[editor] || null; + } +} + /** * Filters schema properties to include only the necessary fields. * @param properties @@ -111,6 +131,12 @@ export function filterSchemaProperties(properties: { [key: string]: SchemaProper for (const [key, property] of Object.entries(properties)) { const { title, description, enum: enumValues, type, default: defaultValue, prefill } = property; filteredProperties[key] = { title, description, enum: enumValues, type, default: defaultValue, prefill }; + if (type === 'array') { + const itemsType = inferArrayItemType(property); + if (itemsType) { + filteredProperties[key].items = { type: itemsType }; + } + } } return filteredProperties; } diff --git a/src/types.ts b/src/types.ts index bcfa34ae..5a0509d9 100644 --- a/src/types.ts +++ b/src/types.ts @@ -43,6 +43,8 @@ export interface SchemaProperties { type: string; // Data type (e.g., "string") default: string; prefill: string; + items?: { type: string; } + editor?: string; } // ActorStoreList for actor-search tool diff --git a/tests/actors-test.ts b/tests/actors-test.ts index a58689c4..a7238fef 100644 --- a/tests/actors-test.ts +++ b/tests/actors-test.ts @@ -1,6 +1,6 @@ import { describe, it, expect } from 'vitest'; -import { actorNameToToolName } from '../src/actors.js'; +import { actorNameToToolName, inferArrayItemType } from '../src/actors.js'; describe('actors', () => { describe('actorNameToToolName', () => { @@ -26,5 +26,18 @@ describe('actors', () => { const expected = 'a'.repeat(64); expect(actorNameToToolName(longName)).toBe(expected); }); + + it('infers array item type from editor', () => { + const property = { + type: 'array', + editor: 'stringList', + title: '', + description: '', + enum: [], + default: '', + prefill: '', + }; + expect(inferArrayItemType(property)).toBe('string'); + }); }); });