Skip to content

Commit e4e5a9e

Browse files
authored
fix: add enum values and examples to schema property descriptions (#42)
Add enum values and examples to schema property descriptions
1 parent 4077603 commit e4e5a9e

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/actors.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,23 @@ export function inferArrayItemType(property: SchemaProperties): string | null {
122122
}
123123
}
124124

125+
/**
126+
* Add enum values as string to property descriptions.
127+
* @param properties
128+
*/
129+
export function addEnumsToDescriptionsWithExamples(properties: { [key: string]: SchemaProperties }): { [key: string]: SchemaProperties } {
130+
for (const property of Object.values(properties)) {
131+
if (property.enum && property.enum.length > 0) {
132+
property.description = `${property.description}\nPossible values: ${property.enum.join(',')}`;
133+
}
134+
const value = property.prefill ?? property.default;
135+
if (value && !(Array.isArray(value) && value.length === 0)) {
136+
property.examples = Array.isArray(value) ? value : [value];
137+
}
138+
}
139+
return properties;
140+
}
141+
125142
/**
126143
* Filters schema properties to include only the necessary fields.
127144
* @param properties
@@ -160,7 +177,8 @@ export async function getActorsAsTools(actors: string[]): Promise<Tool[]> {
160177
if (result) {
161178
if (result.input && 'properties' in result.input && result.input) {
162179
const properties = filterSchemaProperties(result.input.properties as { [key: string]: SchemaProperties });
163-
result.input.properties = shortenProperties(properties);
180+
const propertiesShortened = shortenProperties(properties);
181+
result.input.properties = addEnumsToDescriptionsWithExamples(propertiesShortened);
164182
}
165183
try {
166184
const memoryMbytes = result.defaultRunOptions?.memoryMbytes || defaults.maxMemoryMbytes;

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export interface SchemaProperties {
4545
prefill: string;
4646
items?: { type: string; }
4747
editor?: string;
48+
examples?: unknown[];
4849
}
4950

5051
// ActorStoreList for actor-search tool

0 commit comments

Comments
 (0)