Skip to content

Commit 4f9262c

Browse files
authored
Publish agent (Part 1) (#224)
1 parent b0679fd commit 4f9262c

File tree

22 files changed

+884
-183
lines changed

22 files changed

+884
-183
lines changed

backend/src/templates/agent-registry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export async function getAllAgentTemplates({
1818
}> {
1919
// Load dynamic agents using the service
2020
const { templates: dynamicTemplates, validationErrors } =
21-
await dynamicAgentService.loadAgents(fileContext)
21+
await dynamicAgentService.loadAgents(fileContext.agentTemplates || {})
2222

2323
// Combine static and dynamic templates
2424
const agentRegistry = { ...staticTemplates, ...dynamicTemplates }

common/src/__tests__/dynamic-agent-loader.test.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ describe('Dynamic Agent Loader', () => {
9191
},
9292
}
9393

94-
const result = await dynamicAgentService.loadAgents(fileContext)
94+
const result = await dynamicAgentService.loadAgents(
95+
fileContext.agentTemplates || {}
96+
)
9597

9698
expect(result.validationErrors).toHaveLength(0)
9799
expect(result.templates).toHaveProperty('brainstormer')
@@ -120,7 +122,9 @@ describe('Dynamic Agent Loader', () => {
120122
},
121123
}
122124

123-
const result = await dynamicAgentService.loadAgents(fileContext)
125+
const result = await dynamicAgentService.loadAgents(
126+
fileContext.agentTemplates || {}
127+
)
124128

125129
expect(result.validationErrors).toHaveLength(1)
126130
expect(result.validationErrors[0].message).toContain(
@@ -149,7 +153,9 @@ describe('Dynamic Agent Loader', () => {
149153
},
150154
}
151155

152-
const result = await dynamicAgentService.loadAgents(fileContext)
156+
const result = await dynamicAgentService.loadAgents(
157+
fileContext.agentTemplates || {}
158+
)
153159

154160
// Should have dynamic templates
155161
expect(result.templates).toHaveProperty('custom_agent') // Dynamic
@@ -191,7 +197,9 @@ describe('Dynamic Agent Loader', () => {
191197
},
192198
}
193199

194-
const result = await testService.loadAgents(fileContext)
200+
const result = await testService.loadAgents(
201+
fileContext.agentTemplates || {}
202+
)
195203

196204
expect(result.validationErrors).toHaveLength(0)
197205
expect(result.templates).toHaveProperty('schema_agent')
@@ -228,7 +236,9 @@ describe('Dynamic Agent Loader', () => {
228236
},
229237
}
230238

231-
const result = await testService.loadAgents(fileContext)
239+
const result = await testService.loadAgents(
240+
fileContext.agentTemplates || {}
241+
)
232242

233243
expect(result.validationErrors).toHaveLength(1)
234244
expect(result.validationErrors[0].message).toContain(
@@ -264,7 +274,9 @@ describe('Dynamic Agent Loader', () => {
264274
},
265275
}
266276

267-
const result = await testService.loadAgents(fileContext)
277+
const result = await testService.loadAgents(
278+
fileContext.agentTemplates || {}
279+
)
268280

269281
expect(result.validationErrors).toHaveLength(0)
270282
expect(result.templates).toHaveProperty('no_override_agent')
@@ -307,7 +319,9 @@ describe('Dynamic Agent Loader', () => {
307319
},
308320
}
309321

310-
const result = await testService.loadAgents(fileContext)
322+
const result = await testService.loadAgents(
323+
fileContext.agentTemplates || {}
324+
)
311325

312326
expect(result.validationErrors).toHaveLength(0)
313327
expect(result.templates).toHaveProperty('CodebuffAI/git-committer')

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe('Dynamic Agent Schema Validation', () => {
5757
},
5858
}
5959

60-
const result = await service.loadAgents(fileContext)
60+
const result = await service.loadAgents(fileContext.agentTemplates || {})
6161

6262
expect(result.validationErrors).toHaveLength(0)
6363
expect(result.templates).toHaveProperty('no_prompt_schema_agent')
@@ -89,7 +89,7 @@ describe('Dynamic Agent Schema Validation', () => {
8989
},
9090
}
9191

92-
const result = await service.loadAgents(fileContext)
92+
const result = await service.loadAgents(fileContext.agentTemplates || {})
9393

9494
expect(result.validationErrors).toHaveLength(0)
9595
expect(result.templates).toHaveProperty('no_params_schema_agent')
@@ -145,7 +145,7 @@ describe('Dynamic Agent Schema Validation', () => {
145145
},
146146
}
147147

148-
const result = await service.loadAgents(fileContext)
148+
const result = await service.loadAgents(fileContext.agentTemplates || {})
149149

150150
expect(result.validationErrors).toHaveLength(0)
151151
expect(result.templates).toHaveProperty('both_schemas_agent')
@@ -217,7 +217,7 @@ describe('Dynamic Agent Schema Validation', () => {
217217
},
218218
}
219219

220-
const result = await service.loadAgents(fileContext)
220+
const result = await service.loadAgents(fileContext.agentTemplates || {})
221221

222222
expect(result.validationErrors).toHaveLength(0)
223223
expect(result.templates).toHaveProperty('complex_schema_agent')
@@ -278,7 +278,7 @@ describe('Dynamic Agent Schema Validation', () => {
278278
},
279279
}
280280

281-
const result = await service.loadAgents(fileContext)
281+
const result = await service.loadAgents(fileContext.agentTemplates || {})
282282

283283
expect(result.validationErrors).toHaveLength(1)
284284
expect(result.validationErrors[0].message).toContain('in error-context')
@@ -325,7 +325,7 @@ describe('Dynamic Agent Schema Validation', () => {
325325
},
326326
}
327327

328-
const result = await service.loadAgents(fileContext)
328+
const result = await service.loadAgents(fileContext.agentTemplates || {})
329329

330330
expect(result.validationErrors).toHaveLength(0)
331331
expect(result.templates).toHaveProperty('CodebuffAI/git-committer')
@@ -371,7 +371,7 @@ describe('Dynamic Agent Schema Validation', () => {
371371
},
372372
}
373373

374-
const result = await service.loadAgents(fileContext)
374+
const result = await service.loadAgents(fileContext.agentTemplates || {})
375375

376376
expect(result.validationErrors).toHaveLength(0)
377377
expect(result.templates).toHaveProperty('empty_schema_agent')

common/src/__tests__/handlesteps-parsing.test.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ describe('handleSteps Parsing Tests', () => {
125125
agentTemplates,
126126
}
127127

128-
const result = await dynamicAgentService.loadAgents(fileContext)
128+
const result = await dynamicAgentService.loadAgents(
129+
fileContext.agentTemplates || {}
130+
)
129131

130132
expect(result.validationErrors).toHaveLength(0)
131133
expect(result.templates['test-agent']).toBeDefined()
@@ -175,7 +177,9 @@ describe('handleSteps Parsing Tests', () => {
175177
agentTemplates,
176178
}
177179

178-
const result = await dynamicAgentService.loadAgents(fileContext)
180+
const result = await dynamicAgentService.loadAgents(
181+
fileContext.agentTemplates || {}
182+
)
179183

180184
expect(result.validationErrors.length).toBeGreaterThan(0)
181185
expect(result.validationErrors[0].message).toContain('generator function')
@@ -216,7 +220,9 @@ describe('handleSteps Parsing Tests', () => {
216220
}
217221

218222
// Load agents through the service
219-
const result = await dynamicAgentService.loadAgents(fileContext)
223+
const result = await dynamicAgentService.loadAgents(
224+
fileContext.agentTemplates || {}
225+
)
220226

221227
// Verify no validation errors
222228
expect(result.validationErrors).toHaveLength(0)

common/src/db/migrations/0022_graceful_titanium_man.sql

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
CREATE TABLE IF NOT EXISTS "agent_config" (
2+
"id" text NOT NULL,
3+
"version" text NOT NULL,
4+
"publisher_id" text NOT NULL,
5+
"major" integer GENERATED ALWAYS AS (CAST(SPLIT_PART("agent_config"."version", '.', 1) AS INTEGER)) STORED,
6+
"minor" integer GENERATED ALWAYS AS (CAST(SPLIT_PART("agent_config"."version", '.', 2) AS INTEGER)) STORED,
7+
"patch" integer GENERATED ALWAYS AS (CAST(SPLIT_PART("agent_config"."version", '.', 3) AS INTEGER)) STORED,
8+
"data" jsonb NOT NULL,
9+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
10+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
11+
CONSTRAINT "agent_config_id_version_pk" PRIMARY KEY("id","version")
12+
);
13+
--> statement-breakpoint
14+
CREATE TABLE IF NOT EXISTS "publisher" (
15+
"id" text PRIMARY KEY NOT NULL,
16+
"name" text NOT NULL,
17+
"email" text,
18+
"verified" boolean DEFAULT false NOT NULL,
19+
"bio" text,
20+
"avatar_url" text,
21+
"user_id" text NOT NULL,
22+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
23+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
24+
);
25+
--> statement-breakpoint
26+
DO $$ BEGIN
27+
ALTER TABLE "agent_config" ADD CONSTRAINT "agent_config_publisher_id_publisher_id_fk" FOREIGN KEY ("publisher_id") REFERENCES "public"."publisher"("id") ON DELETE no action ON UPDATE no action;
28+
EXCEPTION
29+
WHEN duplicate_object THEN null;
30+
END $$;
31+
--> statement-breakpoint
32+
DO $$ BEGIN
33+
ALTER TABLE "publisher" ADD CONSTRAINT "publisher_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;
34+
EXCEPTION
35+
WHEN duplicate_object THEN null;
36+
END $$;
37+
--> statement-breakpoint
38+
CREATE INDEX IF NOT EXISTS "idx_agent_config_publisher" ON "agent_config" USING btree ("publisher_id");

0 commit comments

Comments
 (0)