diff --git a/bun.lockb b/bun.lockb index a24a245..216cbd2 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/lib/utils/computerLogger.ts b/lib/utils/computerLogger.ts index 6745117..349e512 100644 --- a/lib/utils/computerLogger.ts +++ b/lib/utils/computerLogger.ts @@ -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, @@ -39,12 +46,12 @@ 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 }); } /** @@ -52,7 +59,7 @@ export class ComputerLogger { * @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'); } /** @@ -69,7 +76,7 @@ export class ComputerLogger { } messageDict.tool_result.base64_image = null; - fs.appendFileSync( + appendFileSync( this.conversationLogFile, JSON.stringify(messageDict) + '\n' ); @@ -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; @@ -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); } } diff --git a/lib/utils/logger.ts b/lib/utils/logger.ts index 764a092..99c9e16 100644 --- a/lib/utils/logger.ts +++ b/lib/utils/logger.ts @@ -1,26 +1,16 @@ 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', }, + // Remove the transport config to avoid worker threads }); -export const logger = pino( - { - level: process.env.LOG_LEVEL || 'info', - base: { - env: process.env.NODE_ENV || 'development', - }, - }, - transport -); - // Create child loggers for different modules export const createModuleLogger = (module: string) => { return logger.child({ module }); }; + +export { logger }; diff --git a/lib/utils/urls.ts b/lib/utils/urls.ts index 369bbca..942fae4 100644 --- a/lib/utils/urls.ts +++ b/lib/utils/urls.ts @@ -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`; } diff --git a/package-lock.json b/package-lock.json index e274fc2..dbb23b2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,16 +1,18 @@ { "name": "@hdr/sdk-preview", - "version": "0.1.0", + "version": "0.3.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@hdr/sdk-preview", - "version": "0.1.0", + "version": "0.3.2", "dependencies": { "@anthropic-ai/sdk": "^0.33.1", "@modelcontextprotocol/sdk": "^1.1.0", "dotenv": "^16.4.7", + "esbuild": "^0.24.2", + "eventsource": "^3.0.2", "husky": "^9.1.7", "lint-staged": "^15.2.10", "pino": "^9.5.0", @@ -22,7 +24,6 @@ "@eslint/js": "^9.16.0", "@trivago/prettier-plugin-sort-imports": "^5.1.0", "@types/bun": "latest", - "@types/node": "^22.10.5", "eslint": "^9.16.0", "eslint-config-prettier": "^9.1.0", "eslint-plugin-prettier": "^5.2.1", @@ -171,6 +172,381 @@ "node": ">=6.9.0" } }, + "node_modules/@esbuild/aix-ppc64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.24.2.tgz", + "integrity": "sha512-thpVCb/rhxE/BnMLQ7GReQLLN8q9qbHmI55F4489/ByVg2aQaQ6kbcLb6FHkocZzQhxc4gx0sCk0tJkKBFzDhA==", + "cpu": [ + "ppc64" + ], + "optional": true, + "os": [ + "aix" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.24.2.tgz", + "integrity": "sha512-tmwl4hJkCfNHwFB3nBa8z1Uy3ypZpxqxfTQOcHX+xRByyYgunVbZ9MzUUfb0RxaHIMnbHagwAxuTL+tnNM+1/Q==", + "cpu": [ + "arm" + ], + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.24.2.tgz", + "integrity": "sha512-cNLgeqCqV8WxfcTIOeL4OAtSmL8JjcN6m09XIgro1Wi7cF4t/THaWEa7eL5CMoMBdjoHOTh/vwTO/o2TRXIyzg==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-x64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.24.2.tgz", + "integrity": "sha512-B6Q0YQDqMx9D7rvIcsXfmJfvUYLoP722bgfBlO5cGvNVb5V/+Y7nhBE3mHV9OpxBf4eAS2S68KZztiPaWq4XYw==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-arm64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.24.2.tgz", + "integrity": "sha512-kj3AnYWc+CekmZnS5IPu9D+HWtUI49hbnyqk0FLEJDbzCIQt7hg7ucF1SQAilhtYpIujfaHr6O0UHlzzSPdOeA==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-x64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.24.2.tgz", + "integrity": "sha512-WeSrmwwHaPkNR5H3yYfowhZcbriGqooyu3zI/3GGpF8AyUdsrrP0X6KumITGA9WOyiJavnGZUwPGvxvwfWPHIA==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-arm64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.24.2.tgz", + "integrity": "sha512-UN8HXjtJ0k/Mj6a9+5u6+2eZ2ERD7Edt1Q9IZiB5UZAIdPnVKDoG7mdTVGhHJIeEml60JteamR3qhsr1r8gXvg==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-x64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.24.2.tgz", + "integrity": "sha512-TvW7wE/89PYW+IevEJXZ5sF6gJRDY/14hyIGFXdIucxCsbRmLUcjseQu1SyTko+2idmCw94TgyaEZi9HUSOe3Q==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.24.2.tgz", + "integrity": "sha512-n0WRM/gWIdU29J57hJyUdIsk0WarGd6To0s+Y+LwvlC55wt+GT/OgkwoXCXvIue1i1sSNWblHEig00GBWiJgfA==", + "cpu": [ + "arm" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.24.2.tgz", + "integrity": "sha512-7HnAD6074BW43YvvUmE/35Id9/NB7BeX5EoNkK9obndmZBUk8xmJJeU7DwmUeN7tkysslb2eSl6CTrYz6oEMQg==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ia32": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.24.2.tgz", + "integrity": "sha512-sfv0tGPQhcZOgTKO3oBE9xpHuUqguHvSo4jl+wjnKwFpapx+vUDcawbwPNuBIAYdRAvIDBfZVvXprIj3HA+Ugw==", + "cpu": [ + "ia32" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-loong64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.24.2.tgz", + "integrity": "sha512-CN9AZr8kEndGooS35ntToZLTQLHEjtVB5n7dl8ZcTZMonJ7CCfStrYhrzF97eAecqVbVJ7APOEe18RPI4KLhwQ==", + "cpu": [ + "loong64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-mips64el": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.24.2.tgz", + "integrity": "sha512-iMkk7qr/wl3exJATwkISxI7kTcmHKE+BlymIAbHO8xanq/TjHaaVThFF6ipWzPHryoFsesNQJPE/3wFJw4+huw==", + "cpu": [ + "mips64el" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ppc64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.24.2.tgz", + "integrity": "sha512-shsVrgCZ57Vr2L8mm39kO5PPIb+843FStGt7sGGoqiiWYconSxwTiuswC1VJZLCjNiMLAMh34jg4VSEQb+iEbw==", + "cpu": [ + "ppc64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-riscv64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.24.2.tgz", + "integrity": "sha512-4eSFWnU9Hhd68fW16GD0TINewo1L6dRrB+oLNNbYyMUAeOD2yCK5KXGK1GH4qD/kT+bTEXjsyTCiJGHPZ3eM9Q==", + "cpu": [ + "riscv64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-s390x": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.24.2.tgz", + "integrity": "sha512-S0Bh0A53b0YHL2XEXC20bHLuGMOhFDO6GN4b3YjRLK//Ep3ql3erpNcPlEFed93hsQAjAQDNsvcK+hV90FubSw==", + "cpu": [ + "s390x" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-x64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.24.2.tgz", + "integrity": "sha512-8Qi4nQcCTbLnK9WoMjdC9NiTG6/E38RNICU6sUNqK0QFxCYgoARqVqxdFmWkdonVsvGqWhmm7MO0jyTqLqwj0Q==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-arm64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.24.2.tgz", + "integrity": "sha512-wuLK/VztRRpMt9zyHSazyCVdCXlpHkKm34WUyinD2lzK07FAHTq0KQvZZlXikNWkDGoT6x3TD51jKQ7gMVpopw==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-x64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.24.2.tgz", + "integrity": "sha512-VefFaQUc4FMmJuAxmIHgUmfNiLXY438XrL4GDNV1Y1H/RW3qow68xTwjZKfj/+Plp9NANmzbH5R40Meudu8mmw==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-arm64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.24.2.tgz", + "integrity": "sha512-YQbi46SBct6iKnszhSvdluqDmxCJA+Pu280Av9WICNwQmMxV7nLRHZfjQzwbPs3jeWnuAhE9Jy0NrnJ12Oz+0A==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-x64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.24.2.tgz", + "integrity": "sha512-+iDS6zpNM6EnJyWv0bMGLWSWeXGN/HTaF/LXHXHwejGsVi+ooqDfMCCTerNFxEkM3wYVcExkeGXNqshc9iMaOA==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/sunos-x64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.24.2.tgz", + "integrity": "sha512-hTdsW27jcktEvpwNHJU4ZwWFGkz2zRJUz8pvddmXPtXDzVKTTINmlmga3ZzwcuMpUvLw7JkLy9QLKyGpD2Yxig==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-arm64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.24.2.tgz", + "integrity": "sha512-LihEQ2BBKVFLOC9ZItT9iFprsE9tqjDjnbulhHoFxYQtQfai7qfluVODIYxt1PgdoyQkz23+01rzwNwYfutxUQ==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-ia32": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.24.2.tgz", + "integrity": "sha512-q+iGUwfs8tncmFC9pcnD5IvRHAzmbwQ3GPS5/ceCyHdjXubwQWI12MKWSNSMYLJMq23/IUCvJMS76PDqXe1fxA==", + "cpu": [ + "ia32" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-x64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.24.2.tgz", + "integrity": "sha512-7VTgWzgMGvup6aSqDPLiW5zHaxYJGTO4OokMjIlrCtf+VpEL+cXKtCvg723iguPYI5oaUNdS+/V7OU2gvXVWEg==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, "node_modules/@eslint-community/eslint-utils": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.4.1.tgz", @@ -1135,6 +1511,45 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/esbuild": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.24.2.tgz", + "integrity": "sha512-+9egpBW8I3CD5XPe0n6BfT5fxLzxrlDzqydF3aviG+9ni1lDC/OvMHcxqEFV0+LANZG5R1bFMWfUrjVsdwxJvA==", + "hasInstallScript": true, + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "@esbuild/aix-ppc64": "0.24.2", + "@esbuild/android-arm": "0.24.2", + "@esbuild/android-arm64": "0.24.2", + "@esbuild/android-x64": "0.24.2", + "@esbuild/darwin-arm64": "0.24.2", + "@esbuild/darwin-x64": "0.24.2", + "@esbuild/freebsd-arm64": "0.24.2", + "@esbuild/freebsd-x64": "0.24.2", + "@esbuild/linux-arm": "0.24.2", + "@esbuild/linux-arm64": "0.24.2", + "@esbuild/linux-ia32": "0.24.2", + "@esbuild/linux-loong64": "0.24.2", + "@esbuild/linux-mips64el": "0.24.2", + "@esbuild/linux-ppc64": "0.24.2", + "@esbuild/linux-riscv64": "0.24.2", + "@esbuild/linux-s390x": "0.24.2", + "@esbuild/linux-x64": "0.24.2", + "@esbuild/netbsd-arm64": "0.24.2", + "@esbuild/netbsd-x64": "0.24.2", + "@esbuild/openbsd-arm64": "0.24.2", + "@esbuild/openbsd-x64": "0.24.2", + "@esbuild/sunos-x64": "0.24.2", + "@esbuild/win32-arm64": "0.24.2", + "@esbuild/win32-ia32": "0.24.2", + "@esbuild/win32-x64": "0.24.2" + } + }, "node_modules/escape-string-regexp": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", @@ -1348,6 +1763,25 @@ "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-5.0.1.tgz", "integrity": "sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA==" }, + "node_modules/eventsource": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/eventsource/-/eventsource-3.0.2.tgz", + "integrity": "sha512-YolzkJNxsTL3tCJMWFxpxtG2sCjbZ4LQUBUrkdaJK0ub0p6lmJt+2+1SwhKjLc652lpH9L/79Ptez972H9tphw==", + "dependencies": { + "eventsource-parser": "^3.0.0" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/eventsource-parser": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/eventsource-parser/-/eventsource-parser-3.0.0.tgz", + "integrity": "sha512-T1C0XCUimhxVQzW4zFipdx0SficT651NnkR0ZSH3yQwh+mFMdLfgjABVi4YtMTtaL4s168593DaoaRLMqryavA==", + "engines": { + "node": ">=18.0.0" + } + }, "node_modules/execa": { "version": "8.0.1", "resolved": "https://registry.npmjs.org/execa/-/execa-8.0.1.tgz", diff --git a/package.json b/package.json index 358697c..ce80cb9 100644 --- a/package.json +++ b/package.json @@ -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" ], @@ -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 bun --format esm && 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" diff --git a/tests/bun-dist.test.ts b/tests/bun-dist.test.ts new file mode 100644 index 0000000..b9bade0 --- /dev/null +++ b/tests/bun-dist.test.ts @@ -0,0 +1,39 @@ +import { describe, test, expect } from 'bun:test'; +import { Computer } from '../dist/bun'; + +describe('Computer SDK Bun Distribution Test', () => { + test('should load built distribution', () => { + const computer = new Computer(); + expect(computer).toBeDefined(); + expect(computer.isConnected()).toBe(false); + }); + + test('should connect using built distribution', async () => { + const apiKey = process.env.HDR_API_KEY; + if (!apiKey) { + console.log( + 'No HDR_API_KEY found in environment, skipping connection test' + ); + return; + } + + const computer = new Computer({ + apiKey, + }); + + try { + await computer.connect(); + expect(computer.isConnected()).toBe(true); + + const metadata = await computer.getMetadata(); + expect(metadata).toBeDefined(); + expect(metadata.machine_id).toBeDefined(); + + await computer.close(); + expect(computer.isConnected()).toBe(false); + } catch (error) { + console.error('Test failed:', error); + throw error; + } + }); +}); diff --git a/tests/bun-test.ts b/tests/bun-test.ts new file mode 100644 index 0000000..d0f849a --- /dev/null +++ b/tests/bun-test.ts @@ -0,0 +1,46 @@ +import { describe, test, expect } from 'bun:test'; +import { Computer } from '../lib'; + +describe('Computer SDK Bun Integration', () => { + test('should create Computer instance', () => { + const computer = new Computer(); + expect(computer).toBeDefined(); + expect(computer.isConnected()).toBe(false); + }); + + test('should handle missing API key gracefully', () => { + const computer = new Computer({ + apiKey: undefined, + }); + expect(computer).toBeDefined(); + }); + + test('should connect with valid API key', async () => { + const apiKey = process.env.HDR_API_KEY; + if (!apiKey) { + console.log( + 'No HDR_API_KEY found in environment, skipping connection test' + ); + return; + } + + const computer = new Computer({ + apiKey, + }); + + try { + await computer.connect(); + expect(computer.isConnected()).toBe(true); + + const metadata = await computer.getMetadata(); + expect(metadata).toBeDefined(); + expect(metadata.machine_id).toBeDefined(); + + await computer.close(); + expect(computer.isConnected()).toBe(false); + } catch (error) { + console.error('Test failed:', error); + throw error; + } + }); +}); diff --git a/tests/bun.test.ts b/tests/bun.test.ts new file mode 100644 index 0000000..d0f849a --- /dev/null +++ b/tests/bun.test.ts @@ -0,0 +1,46 @@ +import { describe, test, expect } from 'bun:test'; +import { Computer } from '../lib'; + +describe('Computer SDK Bun Integration', () => { + test('should create Computer instance', () => { + const computer = new Computer(); + expect(computer).toBeDefined(); + expect(computer.isConnected()).toBe(false); + }); + + test('should handle missing API key gracefully', () => { + const computer = new Computer({ + apiKey: undefined, + }); + expect(computer).toBeDefined(); + }); + + test('should connect with valid API key', async () => { + const apiKey = process.env.HDR_API_KEY; + if (!apiKey) { + console.log( + 'No HDR_API_KEY found in environment, skipping connection test' + ); + return; + } + + const computer = new Computer({ + apiKey, + }); + + try { + await computer.connect(); + expect(computer.isConnected()).toBe(true); + + const metadata = await computer.getMetadata(); + expect(metadata).toBeDefined(); + expect(metadata.machine_id).toBeDefined(); + + await computer.close(); + expect(computer.isConnected()).toBe(false); + } catch (error) { + console.error('Test failed:', error); + throw error; + } + }); +}); diff --git a/tests/node-test.ts b/tests/node-test.ts new file mode 100644 index 0000000..897629f --- /dev/null +++ b/tests/node-test.ts @@ -0,0 +1,36 @@ +import { Computer } from '../lib'; + +async function testNodeComputer() { + console.log('Testing Computer SDK with Node.js...'); + + const computer = new Computer({ + apiKey: process.env.HDR_API_KEY, + }); + + try { + console.log('Connecting to computer...'); + await computer.connect(); + + console.log('Getting metadata...'); + const metadata = await computer.getMetadata(); + console.log('Metadata:', metadata); + + await computer.close(); + console.log('Test completed successfully'); + } catch (error) { + console.error('Test failed:', error); + if (error instanceof Error) { + console.error('Error details:', { + name: error.name, + message: error.message, + stack: error.stack, + }); + } + process.exit(1); + } +} + +testNodeComputer().catch((error) => { + console.error('Unhandled error:', error); + process.exit(1); +});