From 8475406c38ac74f894045218721e661d07157d4a Mon Sep 17 00:00:00 2001 From: MQ Date: Thu, 13 Mar 2025 11:33:05 +0100 Subject: [PATCH 1/3] Support array type properties in schema filter --- src/actors.ts | 21 +++++++++++++++++++++ src/types.ts | 2 ++ 2 files changed, 23 insertions(+) diff --git a/src/actors.ts b/src/actors.ts index 092adf4e..e477d605 100644 --- a/src/actors.ts +++ b/src/actors.ts @@ -111,6 +111,27 @@ 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: string | null = property.items?.type + || (property.prefill && typeof property.prefill) + || (property.default && typeof property.default) + || (property.editor && getEditorItemType(property.editor)) + || null; + + if (itemsType) { + filteredProperties[key].items = { + type: itemsType, + }; + } + + function getEditorItemType(editor: string): string | null { + const editorTypeMap: Record = { + requestListSources: 'object', + stringList: 'string' + }; + return editorTypeMap[editor] || null; + } + } } 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 From 911d1361ce0e873cc3d95f851b7bcd299aace467 Mon Sep 17 00:00:00 2001 From: MQ Date: Thu, 13 Mar 2025 12:09:44 +0100 Subject: [PATCH 2/3] Fix trailing comma in editorTypeMap --- src/actors.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/actors.ts b/src/actors.ts index e477d605..6c3ad098 100644 --- a/src/actors.ts +++ b/src/actors.ts @@ -127,7 +127,7 @@ export function filterSchemaProperties(properties: { [key: string]: SchemaProper function getEditorItemType(editor: string): string | null { const editorTypeMap: Record = { requestListSources: 'object', - stringList: 'string' + stringList: 'string', }; return editorTypeMap[editor] || null; } From c3aa666889b20fa6d1d640bad500e00c39674ae3 Mon Sep 17 00:00:00 2001 From: MQ Date: Thu, 13 Mar 2025 12:21:40 +0100 Subject: [PATCH 3/3] Extract array type inference logic into separate function --- src/actors.ts | 39 ++++++++++++++++++++++----------------- tests/actors-test.ts | 15 ++++++++++++++- 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/src/actors.ts b/src/actors.ts index 6c3ad098..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 @@ -112,24 +132,9 @@ export function filterSchemaProperties(properties: { [key: string]: SchemaProper 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: string | null = property.items?.type - || (property.prefill && typeof property.prefill) - || (property.default && typeof property.default) - || (property.editor && getEditorItemType(property.editor)) - || null; - + const itemsType = inferArrayItemType(property); if (itemsType) { - filteredProperties[key].items = { - type: itemsType, - }; - } - - function getEditorItemType(editor: string): string | null { - const editorTypeMap: Record = { - requestListSources: 'object', - stringList: 'string', - }; - return editorTypeMap[editor] || null; + filteredProperties[key].items = { type: itemsType }; } } } 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'); + }); }); });