Skip to content

Commit d942c68

Browse files
committed
agent id: lowercase letters, numbers, hyphens
1 parent bb7748c commit d942c68

File tree

3 files changed

+61
-8
lines changed

3 files changed

+61
-8
lines changed

common/src/__tests__/dynamic-agent-template-schema.test.ts

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010

1111
describe('DynamicAgentConfigSchema', () => {
1212
const validBaseTemplate = {
13-
id: 'test_agent',
13+
id: 'test-agent',
1414
version: '1.0.0',
1515
displayName: 'Test Agent',
1616
parentPrompt: 'A test agent',
@@ -143,7 +143,7 @@ describe('DynamicAgentConfigSchema', () => {
143143
describe('Invalid Templates', () => {
144144
it('should reject template with missing required fields', () => {
145145
const template = {
146-
id: 'test_agent',
146+
id: 'test-agent',
147147
// Missing other required fields
148148
}
149149

@@ -201,6 +201,55 @@ describe('DynamicAgentConfigSchema', () => {
201201
expect(result.success).toBe(false)
202202
})
203203

204+
it('should reject template with invalid agent ID format', () => {
205+
const invalidIds = [
206+
'Test_Agent', // uppercase and underscore
207+
'test agent', // space
208+
'test.agent', // dot
209+
'test@agent', // special character
210+
'Test-Agent', // uppercase
211+
'123_test', // underscore
212+
'test/agent', // slash
213+
]
214+
215+
invalidIds.forEach((id) => {
216+
const template = {
217+
...validBaseTemplate,
218+
id,
219+
}
220+
221+
const result = DynamicAgentConfigSchema.safeParse(template)
222+
expect(result.success).toBe(false)
223+
if (!result.success) {
224+
expect(result.error.issues[0].message).toContain(
225+
'lowercase letters, numbers, and hyphens'
226+
)
227+
}
228+
})
229+
})
230+
231+
it('should accept template with valid agent ID format', () => {
232+
const validIds = [
233+
'test-agent',
234+
'test123',
235+
'agent-v2',
236+
'my-custom-agent-123',
237+
'a',
238+
'123',
239+
'test-agent-with-many-hyphens',
240+
]
241+
242+
validIds.forEach((id) => {
243+
const template = {
244+
...validBaseTemplate,
245+
id,
246+
}
247+
248+
const result = DynamicAgentConfigSchema.safeParse(template)
249+
expect(result.success).toBe(true)
250+
})
251+
})
252+
204253
it('should accept template with any parentInstructions agent ID at schema level', () => {
205254
const template = {
206255
...validBaseTemplate,
@@ -359,4 +408,4 @@ describe('DynamicAgentConfigSchema', () => {
359408
)
360409
})
361410
})
362-
})
411+
})

common/src/types/dynamic-agent-template.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ const JsonSchemaSchema: z.ZodType<any> = z.lazy(() =>
4646
const InputSchemaObjectSchema = z
4747
.object({
4848
prompt: z
49-
.object({
50-
type: z.literal('string'),
49+
.object({
50+
type: z.literal('string'),
5151
description: z.string().optional(),
5252
})
5353
.passthrough()
@@ -82,7 +82,12 @@ const HandleStepsSchema = z
8282

8383
// Validates the Typescript template file.
8484
export const DynamicAgentConfigSchema = z.object({
85-
id: z.string(), // The unique identifier for this agent
85+
id: z
86+
.string()
87+
.regex(
88+
/^[a-z0-9-]+$/,
89+
'Agent ID must contain only lowercase letters, numbers, and hyphens'
90+
), // The unique identifier for this agent
8691
version: z.string().optional(),
8792

8893
// Required fields for new agents

common/src/util/agent-config.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type ToolName = Tools.ToolName
2121
// ============================================================================
2222

2323
export interface AgentConfig {
24-
/** Unique identifier for this agent. Use alphanumeric characters and hyphens only, e.g. 'code-reviewer' */
24+
/** Unique identifier for this agent. Must contain only lowercase letters, numbers, and hyphens, e.g. 'code-reviewer' */
2525
id: string
2626

2727
/** Version string (if not provided, will default to '0.0.1' and be bumped on each publish) */
@@ -259,7 +259,6 @@ export type FileEditingTools = FileTools | 'end_turn'
259259
export type ResearchTools = WebTools | 'write_file' | 'end_turn'
260260
export type CodeAnalysisToolSet = FileTools | CodeAnalysisTools | 'end_turn'
261261

262-
263262
// ============================================================================
264263
// Available Models (see: https://openrouter.ai/models)
265264
// ============================================================================

0 commit comments

Comments
 (0)