@@ -12,6 +12,7 @@ import { joinSuggestions, PaperScoreResultSchema } from './agents/paper-score.sc
1212import { z } from 'zod' ;
1313import { asyncHandler } from './middleware/error-handler' ;
1414import { Server } from 'http' ;
15+ import { WeatherAgent } from './agents/weather' ;
1516
1617export const app = express ( ) ;
1718const port = process . env [ 'PORT' ] || 8000 ;
@@ -30,6 +31,7 @@ const paperClassifier = new PaperClassificationAgent();
3031const paperScoreAgent = new PaperScoreAgent ( ) ;
3132const paperMatchWeaknessSectionsAgent = new PaperMatchWeaknessSectionsAgent ( ) ;
3233const paperScoreSummaryAgent = new PaperReviewSummaryWeaknessAgent ( ) ;
34+ const weatherAgent = new WeatherAgent ( ) ;
3335
3436app . get ( '/' , ( _ : Request , res : Response ) => {
3537 res . send ( 'Hello, TypeScript Express!' ) ;
@@ -71,6 +73,11 @@ const ScorePaperRequestSchema = z.object({
7173 ] as const ) ,
7274} ) ;
7375
76+ const WeatherRequestSchema = z . object ( {
77+ city : z . string ( ) . min ( 1 , 'city is required' ) ,
78+ country : z . string ( ) . min ( 1 , 'country is required' ) ,
79+ } ) ;
80+
7481app . post (
7582 '/paper-score-comments' ,
7683 asyncHandler ( async ( req : Request , res : Response ) => {
@@ -144,6 +151,16 @@ app.post(
144151 } ) ,
145152) ;
146153
154+ // 获得天气
155+ app . get (
156+ '/weather' ,
157+ asyncHandler ( async ( req : Request , res : Response ) => {
158+ const { city, country } = WeatherRequestSchema . parse ( req . query ) ;
159+ const result = await weatherAgent . getWeather ( city , country ) ;
160+ res . send ( result ) ;
161+ } ) ,
162+ ) ;
163+
147164// Global error handler
148165app . use ( ( err : Error , _ : Request , res : Response , __ : express . NextFunction ) => {
149166 console . error ( 'Unhandled error:' , err ) ;
0 commit comments