Skip to content

Commit 12344c8

Browse files
authored
feat: tool-items-type (#39)
* Support array type properties in schema filter * Fix trailing comma in editorTypeMap * Extract array type inference logic into separate function
1 parent 6ffd783 commit 12344c8

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

src/actors.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,26 @@ export function truncateActorReadme(readme: string, limit = ACTOR_README_MAX_LEN
102102
const prunedReadme = lines.filter((line) => line.startsWith('#'));
103103
return `${readmeFirst}\n\nREADME was truncated because it was too long. Remaining headers:\n${prunedReadme.join(', ')}`;
104104
}
105+
/**
106+
* Helps determine the type of items in an array schema property.
107+
* Priority order: explicit type in items > prefill type > default value type > editor type.
108+
*/
109+
export function inferArrayItemType(property: SchemaProperties): string | null {
110+
return property.items?.type
111+
|| (property.prefill && typeof property.prefill)
112+
|| (property.default && typeof property.default)
113+
|| (property.editor && getEditorItemType(property.editor))
114+
|| null;
115+
116+
function getEditorItemType(editor: string): string | null {
117+
const editorTypeMap: Record<string, string> = {
118+
requestListSources: 'object',
119+
stringList: 'string',
120+
};
121+
return editorTypeMap[editor] || null;
122+
}
123+
}
124+
105125
/**
106126
* Filters schema properties to include only the necessary fields.
107127
* @param properties
@@ -111,6 +131,12 @@ export function filterSchemaProperties(properties: { [key: string]: SchemaProper
111131
for (const [key, property] of Object.entries(properties)) {
112132
const { title, description, enum: enumValues, type, default: defaultValue, prefill } = property;
113133
filteredProperties[key] = { title, description, enum: enumValues, type, default: defaultValue, prefill };
134+
if (type === 'array') {
135+
const itemsType = inferArrayItemType(property);
136+
if (itemsType) {
137+
filteredProperties[key].items = { type: itemsType };
138+
}
139+
}
114140
}
115141
return filteredProperties;
116142
}

src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ export interface SchemaProperties {
4343
type: string; // Data type (e.g., "string")
4444
default: string;
4545
prefill: string;
46+
items?: { type: string; }
47+
editor?: string;
4648
}
4749

4850
// ActorStoreList for actor-search tool

tests/actors-test.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, it, expect } from 'vitest';
22

3-
import { actorNameToToolName } from '../src/actors.js';
3+
import { actorNameToToolName, inferArrayItemType } from '../src/actors.js';
44

55
describe('actors', () => {
66
describe('actorNameToToolName', () => {
@@ -26,5 +26,18 @@ describe('actors', () => {
2626
const expected = 'a'.repeat(64);
2727
expect(actorNameToToolName(longName)).toBe(expected);
2828
});
29+
30+
it('infers array item type from editor', () => {
31+
const property = {
32+
type: 'array',
33+
editor: 'stringList',
34+
title: '',
35+
description: '',
36+
enum: [],
37+
default: '',
38+
prefill: '',
39+
};
40+
expect(inferArrayItemType(property)).toBe('string');
41+
});
2942
});
3043
});

0 commit comments

Comments
 (0)