1+ import { execSync } from "child_process" ;
12import * as dotenv from "dotenv" ;
23import * as fs from "fs" ;
34import * as path from "path" ;
45import prompts from "prompts" ;
56
67import * as out from "../utils/output" ;
8+ import { detectPackageManager } from "../utils/packageManager" ;
79import { getGlobalTokenPath } from "../utils/token" ;
10+ import { handleSSEStream } from "../utils/sse" ;
811
912interface GenerateOptions {
1013 dir : string ;
@@ -175,6 +178,7 @@ export async function generateCommand(options: GenerateOptions) {
175178 method : "POST" ,
176179 headers : {
177180 "Content-Type" : "application/json" ,
181+ Accept : "text/event-stream" ,
178182 Authorization : `Bearer ${ deployToken } ` ,
179183 } ,
180184 body : JSON . stringify ( { spec : specContent } ) ,
@@ -189,7 +193,12 @@ export async function generateCommand(options: GenerateOptions) {
189193 process . exit ( 1 ) ;
190194 }
191195
192- const source = ( await response . json ( ) ) as AgentSource ;
196+ // Handle SSE stream with progress updates
197+ const source = ( await handleSSEStream ( response , {
198+ onProgress : ( message ) => {
199+ out . progress ( message ) ;
200+ } ,
201+ } ) ) as AgentSource ;
193202
194203 // Create agent directory if it doesn't exist
195204 if ( ! fs . existsSync ( agentPath ) ) {
@@ -295,6 +304,41 @@ export async function generateCommand(options: GenerateOptions) {
295304 writeFile ( filePath , content ) ;
296305 }
297306
307+ out . blank ( ) ;
308+
309+ // Detect package manager and install dependencies
310+ const packageManager = detectPackageManager ( ) ;
311+
312+ // Update @plotday /sdk to latest and install packages
313+ try {
314+ out . progress ( "Updating @plotday/sdk to latest version..." ) ;
315+
316+ const updateCommand =
317+ packageManager === "npm" ? "npm install @plotday/sdk@latest" :
318+ packageManager === "pnpm" ? "pnpm add @plotday/sdk@latest" :
319+ "yarn add @plotday/sdk@latest" ;
320+
321+ execSync ( updateCommand , { cwd : agentPath , stdio : "ignore" } ) ;
322+
323+ out . progress ( "Installing dependencies..." ) ;
324+
325+ const installCommand =
326+ packageManager === "yarn" ? "yarn" :
327+ `${ packageManager } install` ;
328+
329+ execSync ( installCommand , { cwd : agentPath , stdio : "ignore" } ) ;
330+
331+ out . success ( "Dependencies installed successfully!" ) ;
332+ } catch ( error ) {
333+ out . warning (
334+ "Couldn't install dependencies" ,
335+ [
336+ `Run '${ packageManager === "npm" ? "npm install @plotday/sdk@latest" : packageManager === "pnpm" ? "pnpm add @plotday/sdk@latest" : "yarn add @plotday/sdk@latest" } ' in ${ options . dir } ` ,
337+ `Then run '${ packageManager === "yarn" ? "yarn" : `${ packageManager } install` } '`
338+ ]
339+ ) ;
340+ }
341+
298342 out . blank ( ) ;
299343 out . success ( "Agent generated successfully!" ) ;
300344
0 commit comments