Skip to content

Commit 4985a32

Browse files
refactor: deduplicate agent-template.ts by importing base types from the user-facing template; update Logger parameter in handleSteps to ensure correct step logging.
🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
1 parent 901ebb5 commit 4985a32

File tree

4 files changed

+32
-22
lines changed

4 files changed

+32
-22
lines changed

backend/src/__tests__/run-programmatic-step.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,9 @@ describe('runProgrammaticStep', () => {
8484
)
8585

8686
// Mock sendAction
87-
sendActionSpy = spyOn(
88-
websocketAction,
89-
'sendAction',
90-
).mockImplementation(() => {})
87+
sendActionSpy = spyOn(websocketAction, 'sendAction').mockImplementation(
88+
() => {},
89+
)
9190

9291
// Mock crypto.randomUUID
9392
spyOn(crypto, 'randomUUID').mockImplementation(
@@ -118,7 +117,8 @@ describe('runProgrammaticStep', () => {
118117
mockAgentState = {
119118
...sessionState.mainAgentState,
120119
agentId: 'test-agent-id',
121-
runId: 'test-run-id' as `${string}-${string}-${string}-${string}-${string}`,
120+
runId:
121+
'test-run-id' as `${string}-${string}-${string}-${string}-${string}`,
122122
messageHistory: [
123123
{ role: 'user', content: 'Initial message' },
124124
{ role: 'assistant', content: 'Initial response' },

common/src/templates/agent-validation.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ export function validateSingleAgent(
284284
stepPrompt: validatedConfig.stepPrompt ?? '',
285285
outputSchema,
286286
inputSchema,
287+
287288
}
288289

289290
return {

common/src/templates/initial-agents-dir/types/agent-definition.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -196,15 +196,17 @@ export interface AgentDefinition {
196196
handleSteps?: (
197197
context: AgentStepContext,
198198
logger: Logger,
199-
) => Generator<
200-
ToolCall | 'STEP' | 'STEP_ALL',
201-
void,
202-
{
203-
agentState: AgentState
204-
toolResult: ToolResultOutput[] | undefined
205-
stepsComplete: boolean
206-
}
207-
>
199+
) =>
200+
| Generator<
201+
ToolCall | 'STEP' | 'STEP_ALL',
202+
void,
203+
{
204+
agentState: AgentState
205+
toolResult: ToolResultOutput[] | undefined
206+
stepsComplete: boolean
207+
}
208+
>
209+
| string
208210
}
209211

210212
// ============================================================================

common/src/types/agent-template.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
1+
/**
2+
* Backend Agent Template Types
3+
*
4+
* This file provides backend-compatible agent template types with strict validation.
5+
* It imports base types from the user-facing template to eliminate duplication.
6+
*/
7+
18
import type { Model } from '../old-constants'
29
import type { ToolResultOutput } from './messages/content-part'
310
import type { AgentState, AgentTemplateType } from './session-state'
411
import type {
12+
AgentDefinition,
513
ToolCall,
614
AgentState as PublicAgentState,
15+
Logger,
16+
AgentStepContext,
717
} from '../templates/initial-agents-dir/types/agent-definition'
818
import type { ToolName } from '../tools/constants'
919
import type { OpenRouterProviderOptions } from '@codebuff/internal/openrouter-ai-sdk'
1020
import type { z } from 'zod/v4'
1121

1222
export type AgentId = `${string}/${string}@${number}.${number}.${number}`
1323

24+
/**
25+
* Backend agent template with strict validation and Zod schemas
26+
* Extends the user-facing AgentDefinition but with backend-specific requirements
27+
*/
1428
export type AgentTemplate<
1529
P = string | undefined,
1630
T = Record<string, any> | undefined,
@@ -59,11 +73,4 @@ export type StepHandler<
5973
logger: Logger,
6074
) => StepGenerator
6175

62-
export interface Logger {
63-
debug: (data: any, msg?: string) => void
64-
info: (data: any, msg?: string) => void
65-
warn: (data: any, msg?: string) => void
66-
error: (data: any, msg?: string) => void
67-
}
68-
69-
export { PublicAgentState }
76+
export { Logger, PublicAgentState }

0 commit comments

Comments
 (0)