From 15352448d5d74251b9035c1bd76a164034301b3c Mon Sep 17 00:00:00 2001 From: Jason Woltje Date: Thu, 12 Mar 2026 20:43:08 -0500 Subject: [PATCH] fix: switch gateway to ESM + explicit @Inject for tsx compatibility MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pi SDK is ESM-only. tsx (esbuild) doesn't emit decorator metadata, so NestJS constructor injection fails without explicit @Inject(). - Set "type": "module" in gateway package.json - Switch tsconfig to NodeNext module resolution - Add @Inject(AgentService) to ChatController and ChatGateway Tested end-to-end: REST /api/chat → Pi SDK → Anthropic → response OK. Co-Authored-By: Claude Opus 4.6 --- apps/gateway/package.json | 1 + apps/gateway/src/chat/chat.controller.ts | 4 ++-- apps/gateway/src/chat/chat.gateway.ts | 4 ++-- apps/gateway/tsconfig.json | 4 ++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/apps/gateway/package.json b/apps/gateway/package.json index 9b83ded..2b5ac50 100644 --- a/apps/gateway/package.json +++ b/apps/gateway/package.json @@ -2,6 +2,7 @@ "name": "@mosaic/gateway", "version": "0.0.0", "private": true, + "type": "module", "main": "dist/main.js", "scripts": { "build": "tsc", diff --git a/apps/gateway/src/chat/chat.controller.ts b/apps/gateway/src/chat/chat.controller.ts index 108a165..44fd5a3 100644 --- a/apps/gateway/src/chat/chat.controller.ts +++ b/apps/gateway/src/chat/chat.controller.ts @@ -1,4 +1,4 @@ -import { Controller, Post, Body, Logger, HttpException, HttpStatus } from '@nestjs/common'; +import { Controller, Post, Body, Logger, HttpException, HttpStatus, Inject } from '@nestjs/common'; import type { AgentSessionEvent } from '@mariozechner/pi-coding-agent'; import { AgentService } from '../agent/agent.service.js'; import { v4 as uuid } from 'uuid'; @@ -17,7 +17,7 @@ interface ChatResponse { export class ChatController { private readonly logger = new Logger(ChatController.name); - constructor(private readonly agentService: AgentService) {} + constructor(@Inject(AgentService) private readonly agentService: AgentService) {} @Post() async chat(@Body() body: ChatRequest): Promise { diff --git a/apps/gateway/src/chat/chat.gateway.ts b/apps/gateway/src/chat/chat.gateway.ts index f217191..43a7a3c 100644 --- a/apps/gateway/src/chat/chat.gateway.ts +++ b/apps/gateway/src/chat/chat.gateway.ts @@ -1,4 +1,4 @@ -import { Logger } from '@nestjs/common'; +import { Inject, Logger } from '@nestjs/common'; import { WebSocketGateway, WebSocketServer, @@ -33,7 +33,7 @@ export class ChatGateway implements OnGatewayInit, OnGatewayConnection, OnGatewa { conversationId: string; cleanup: () => void } >(); - constructor(private readonly agentService: AgentService) {} + constructor(@Inject(AgentService) private readonly agentService: AgentService) {} afterInit(): void { this.logger.log('Chat WebSocket gateway initialized'); diff --git a/apps/gateway/tsconfig.json b/apps/gateway/tsconfig.json index 119fbee..b6f1494 100644 --- a/apps/gateway/tsconfig.json +++ b/apps/gateway/tsconfig.json @@ -5,8 +5,8 @@ "rootDir": "src", "experimentalDecorators": true, "emitDecoratorMetadata": true, - "module": "CommonJS", - "moduleResolution": "Node" + "module": "NodeNext", + "moduleResolution": "NodeNext" }, "include": ["src/**/*"], "exclude": ["node_modules", "dist"]