diff --git a/package-lock.json b/package-lock.json index ba89f07caf..371d621009 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17612,6 +17612,9 @@ "uuid": "^11.1.0", "winston": "^3.17.0" }, + "bin": { + "gemini-cli-a2a-server": "dist/a2a-server.mjs" + }, "devDependencies": { "@types/express": "^5.0.3", "@types/fs-extra": "^11.0.4", diff --git a/packages/a2a-server/package.json b/packages/a2a-server/package.json index 7b30cbecf0..f356413cd0 100644 --- a/packages/a2a-server/package.json +++ b/packages/a2a-server/package.json @@ -9,10 +9,13 @@ "directory": "packages/a2a-server" }, "type": "module", - "main": "dist/server.js", + "main": "dist/index.js", + "bin": { + "gemini-cli-a2a-server": "dist/a2a-server.mjs" + }, "scripts": { - "start": "node dist/src/http/server.js", "build": "node ../../scripts/build_package.js", + "start": "node dist/src/http/server.js", "lint": "eslint . --ext .ts,.tsx", "format": "prettier --write .", "test": "vitest run", diff --git a/packages/a2a-server/src/http/server.ts b/packages/a2a-server/src/http/server.ts index 603879daa5..c22be49331 100644 --- a/packages/a2a-server/src/http/server.ts +++ b/packages/a2a-server/src/http/server.ts @@ -1,3 +1,5 @@ +#!/usr/bin/env node + /** * @license * Copyright 2025 Google LLC @@ -10,22 +12,21 @@ import * as path from 'node:path'; import { logger } from '../utils/logger.js'; import { main } from './app.js'; -// Check if the module is the main script being run. path.resolve() creates a -// canonical, absolute path, which avoids cross-platform issues. +// Check if the module is the main script being run const isMainModule = - path.resolve(process.argv[1]) === - path.resolve(url.fileURLToPath(import.meta.url)); - -process.on('uncaughtException', (error) => { - logger.error('Unhandled exception:', error); - process.exit(1); -}); + path.basename(process.argv[1]) === + path.basename(url.fileURLToPath(import.meta.url)); if ( import.meta.url.startsWith('file:') && isMainModule && process.env['NODE_ENV'] !== 'test' ) { + process.on('uncaughtException', (error) => { + logger.error('Unhandled exception:', error); + process.exit(1); + }); + main().catch((error) => { logger.error('[CoreAgent] Unhandled error in main:', error); process.exit(1);