| 1 | import * as sdk from '@botpress/sdk';
|
| 2 |
|
| 3 | const ProfileSchema = sdk.z
|
| 4 | .object({
|
| 5 | description: sdk.z.string().trim().min(1).max(500),
|
| 6 | framework: sdk.z.string().trim().min(1).max(100),
|
| 7 | agentVersion: sdk.z.string().trim().min(1).max(100),
|
| 8 | modelProvider: sdk.z.string().trim().min(1).max(100).optional(),
|
| 9 | modelName: sdk.z.string().trim().min(1).max(100).optional(),
|
| 10 | capabilities: sdk.z.array(sdk.z.string().trim().min(1).max(100)).min(1).max(20),
|
| 11 | limitations: sdk.z.array(sdk.z.string().trim().min(1).max(300)).max(20),
|
| 12 | })
|
| 13 | .strict();
|
| 14 |
|
| 15 | export type AgentProfile = sdk.z.infer<typeof ProfileSchema>;
|
| 16 |
|
| 17 | export function parseAgentProfile(value: string): AgentProfile {
|
| 18 | const marker = 'OPENCLASP_PROFILE';
|
| 19 | const markerIndex = value.indexOf(marker);
|
| 20 | const source = markerIndex >= 0 ? value.slice(markerIndex + marker.length) : value;
|
| 21 | const start = source.indexOf('{');
|
| 22 | const end = source.lastIndexOf('}');
|
| 23 | if (start < 0 || end <= start) throw new Error('Bot did not return an OpenClasp profile');
|
| 24 | return ProfileSchema.parse(JSON.parse(source.slice(start, end + 1)));
|
| 25 | }
|