Skip to content

Commit 8ec60d6

Browse files
committed
Refactor handlers to improve type handling and move Express request type augmentation to a separate definition file.
1 parent a38ef1a commit 8ec60d6

File tree

8 files changed

+21
-18
lines changed

8 files changed

+21
-18
lines changed

src/core/agents/handlers/createEvaluatorHandler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ export const createEvaluatorHandler = ({
7171
},
7272
];
7373

74-
const evaluatorOutput: EvaluatorOutput = await think({
74+
const evaluatorOutput = (await think({
7575
name: config.name,
7676
messages: chatCompletionMessages,
77-
});
77+
})) as EvaluatorOutput;
7878

7979
if (!evaluatorOutput) {
8080
logger.error(`[${config.name}] Error evaluating:`);

src/core/agents/handlers/createPlannerHandler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ export const createPlannerHandler = ({
7474
},
7575
];
7676

77-
const plannerOutput: PlannerOutput = await think({
77+
const plannerOutput = (await think({
7878
name: config.name,
7979
messages: chatCompletionMessages,
80-
});
80+
})) as PlannerOutput;
8181

8282
if (!plannerOutput) {
8383
logger.error(`[${config.name}] Error planning:`);

src/core/agents/handlers/createReporterHandler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ export const createReporterHandler = ({
5555
},
5656
];
5757

58-
const summary = await think({
58+
const summary = (await think({
5959
name: config.name,
6060
messages: chatCompletionMessages,
61-
});
61+
})) as string;
6262

6363
if (!summary) {
6464
logger.error(`[${config.name}] Error summarizing`);

src/core/agents/handlers/createWorkerHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export const createWorkerHandler = ({
6262
},
6363
];
6464

65-
const llmOutput = await think({ name: config.name, messages: chatCompletionMessages });
65+
const llmOutput = (await think({ name: config.name, messages: chatCompletionMessages })) as string;
6666

6767
if (!llmOutput) {
6868
logger.error(`[${config.name}] Error thinking:`);

src/core/llm/createAiProcessor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const createAiProcessor = ({
2424
}: {
2525
name: string;
2626
messages: ChatCompletionMessageParam[];
27-
}): Promise<z.infer<typeof schema> | string | null> => {
27+
}): Promise<unknown> => {
2828
logger.info(`[${name}] thinking...`);
2929

3030
const completionMessages = [

src/middlewares/authenticate.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,6 @@ import { NextFunction, Request, Response } from 'express';
22
import jwt from 'jsonwebtoken';
33
import { env, logger } from '../config';
44

5-
declare module 'express-serve-static-core' {
6-
interface Request {
7-
user?: {
8-
userId: string;
9-
username: string;
10-
role: string;
11-
};
12-
}
13-
}
14-
155
export const authenticate = (req: Request, res: Response, next: NextFunction): void => {
166
try {
177
const authHeader = req.headers.authorization;

src/types/express.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import 'express';
2+
3+
declare module 'express-serve-static-core' {
4+
interface Request {
5+
user?: {
6+
userId: string;
7+
username: string;
8+
role: string;
9+
};
10+
}
11+
}

tests/setup.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ jest.setTimeout(10000);
55
beforeAll(() => {
66
process.env.NODE_ENV = 'test';
77
process.env.LOG_LEVEL = 'error';
8+
process.env.JWT_SECRET = 'test-secret-key';
9+
process.env.JWT_EXPIRES_IN = '7d';
810
});
911

1012
afterEach(() => {

0 commit comments

Comments
 (0)