Skip to content

fix bun builds + malformed mcp url #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions lib/utils/computerLogger.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import fs from 'fs';
import path from 'path';
import {
mkdirSync,
appendFileSync,
writeFileSync,
readdirSync,
unlinkSync,
rmdirSync,
} from 'node:fs';
import { join } from 'node:path';
import {
LogConfig,
type ComputerMessage,
Expand Down Expand Up @@ -39,20 +46,20 @@ export class ComputerLogger {
const parsedOptions = LogConfig.parse(options);
this.logDir = parsedOptions.logDir;
this.conversationFile = 'conversation.jsonl';
this.runDir = path.join(this.logDir, parsedOptions.runDir);
this.runDir = join(this.logDir, parsedOptions.runDir);
logger.debug(`Creating run directory: ${this.runDir}`);
this.conversationLogFile = path.join(this.runDir, this.conversationFile);
this.conversationLogFile = join(this.runDir, this.conversationFile);

fs.mkdirSync(this.logDir, { recursive: true });
fs.mkdirSync(this.runDir, { recursive: true });
mkdirSync(this.logDir, { recursive: true });
mkdirSync(this.runDir, { recursive: true });
}

/**
* Logs an outgoing command to the conversation log file
* @param command - The command action to log
*/
public logSend(command: Action): void {
fs.appendFileSync(this.conversationLogFile, JSON.stringify(command) + '\n');
appendFileSync(this.conversationLogFile, JSON.stringify(command) + '\n');
}

/**
Expand All @@ -69,7 +76,7 @@ export class ComputerLogger {
}
messageDict.tool_result.base64_image = null;

fs.appendFileSync(
appendFileSync(
this.conversationLogFile,
JSON.stringify(messageDict) + '\n'
);
Expand All @@ -84,16 +91,13 @@ export class ComputerLogger {
private logScreenshot(message: ComputerMessage): string | null {
if (message.tool_result.base64_image) {
const timestamp = message.metadata.request_timestamp.toISOString();
const screenshot_file = path.join(
this.runDir,
`screenshot_${timestamp}.png`
);
const screenshot_file = join(this.runDir, `screenshot_${timestamp}.png`);
logger.debug(`Logging screenshot to: ${screenshot_file}`);
const imageBuffer = Buffer.from(
message.tool_result.base64_image,
'base64'
);
fs.writeFileSync(screenshot_file, new Uint8Array(imageBuffer));
writeFileSync(screenshot_file, new Uint8Array(imageBuffer));
return screenshot_file;
}
return null;
Expand All @@ -104,9 +108,9 @@ export class ComputerLogger {
*/
public cleanup(): void {
logger.debug(`Cleaning up run directory: ${this.runDir}`);
fs.readdirSync(this.runDir).forEach((file) => {
fs.unlinkSync(path.join(this.runDir, file));
readdirSync(this.runDir).forEach((file) => {
unlinkSync(join(this.runDir, file));
});
fs.rmdirSync(this.runDir);
rmdirSync(this.runDir);
}
}
30 changes: 14 additions & 16 deletions lib/utils/logger.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
import pino from 'pino';

const transport = pino.transport({
target: 'pino-pretty',
options: {
translateTime: 'HH:MM:ss Z',
ignore: 'pid,hostname',
colorize: true,
levelFirst: true,
const logger = pino({
level: process.env.LOG_LEVEL || 'info',
base: {
env: process.env.NODE_ENV || 'development',
},
});

export const logger = pino(
{
level: process.env.LOG_LEVEL || 'info',
base: {
env: process.env.NODE_ENV || 'development',
transport: {
target: 'pino-pretty',
options: {
translateTime: 'HH:MM:ss Z',
ignore: 'pid,hostname',
colorize: true,
levelFirst: true,
},
},
transport
);
});

// Create child loggers for different modules
export const createModuleLogger = (module: string) => {
return logger.child({ module });
};

export { logger };
2 changes: 1 addition & 1 deletion lib/utils/urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ export function getStreamUrl(baseURL: string, machineId: string): string {
export function getMcpUrl(baseURL: string, machineId: string | null): string {
if (machineId === null)
throw new Error('Unable to get MCP Url: machineId is null.');
return `${baseURL}/compute/${machineId}/mcp`;
return `${baseURL}${machineId}/mcp`;
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@hdr/sdk-preview",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"version": "0.3.1",
"version": "0.3.2",
"files": [
"dist"
],
Expand Down Expand Up @@ -46,12 +46,13 @@
]
},
"scripts": {
"build": "bun build ./lib/index.ts --outdir ./dist --target node --format esm && mv ./dist/index.js ./dist/index.mjs && tsc --emitDeclarationOnly --outDir dist",
"build": "bun build ./lib/index.ts --outdir ./dist --target node --format esm --external fs --external path && mv ./dist/index.js ./dist/index.mjs && tsc --emitDeclarationOnly --outDir dist",
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,css,scss,md}\"",
"format:check": "prettier --check \"**/*.{js,jsx,ts,tsx,json,css,scss,md}\"",
"lint": "eslint ./lib",
"lint:fix": "eslint ./lib --fix",
"prepare": "husky",
"clean": "rm -rf dist",
"publish": "npm publish"
},
"type": "module"
Expand Down