Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/actors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> = {
requestListSources: 'object',
stringList: 'string',
};
return editorTypeMap[editor] || null;
}
}

/**
* Filters schema properties to include only the necessary fields.
* @param properties
Expand All @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion tests/actors-test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand All @@ -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');
});
});
});
Loading