Add warnings to lume implementation, get set up for cloud implementation of computer

This commit is contained in:
Morgan Dean
2025-06-18 10:21:36 -07:00
parent 4fb45edc7f
commit affe9d5878
9 changed files with 22 additions and 112 deletions
@@ -7,7 +7,7 @@ import type { BaseComputerConfig, Display } from "./types";
export const DEFAULT_CONFIG: Partial<BaseComputerConfig> = {
name: "",
osType: OSType.MACOS,
vmProvider: VMProviderType.LUME,
vmProvider: VMProviderType.CLOUD,
display: "1024x768",
memory: "8GB",
cpu: 4,
@@ -1,4 +1,3 @@
import { LumierComputer } from "./providers/lumier";
import type { BaseComputer } from "./providers/base";
import { CloudComputer } from "./providers/cloud";
import { LumeComputer } from "./providers/lume";
@@ -7,7 +6,6 @@ import {
type BaseComputerConfig,
type CloudComputerConfig,
type LumeComputerConfig,
type LumierComputerConfig,
} from "./types";
import { applyDefaults } from "./defaults";
@@ -25,7 +23,6 @@ export class Computer {
| Partial<BaseComputerConfig>
| Partial<CloudComputerConfig>
| Partial<LumeComputerConfig>
| Partial<LumierComputerConfig>
): BaseComputer {
// Apply defaults to the configuration
const fullConfig = applyDefaults(config);
@@ -36,8 +33,6 @@ export class Computer {
return new CloudComputer(fullConfig as CloudComputerConfig);
case VMProviderType.LUME:
return new LumeComputer(fullConfig as LumeComputerConfig);
case VMProviderType.LUMIER:
return new LumierComputer(fullConfig as LumierComputerConfig);
default:
throw new Error(
`Unsupported VM provider type: ${fullConfig.vmProvider}`
@@ -1,6 +1,8 @@
import { BaseComputer } from "./base";
import type { CloudComputerConfig } from "../types";
import { computerLogger } from "../../util/logger";
import pino from "pino";
const logger = pino({ name: "cloud" });
/**
* Cloud-specific computer implementation
@@ -14,7 +16,7 @@ export class CloudComputer extends BaseComputer {
* Cloud-specific method to deploy the computer
*/
async deploy(): Promise<void> {
computerLogger.info(`Deploying cloud computer ${this.name}`);
logger.info(`Deploying cloud computer ${this.name}`);
// Cloud-specific implementation
}
@@ -1,3 +1,8 @@
/**
* WARNING: This file was created as a test/example implementation and is not maintained or expected to work.
* It serves as a reference for how a provider might be implemented but should not be used in production.
*/
import type { Display, LumeComputerConfig } from "../types";
import { BaseComputer } from "./base";
import { applyDefaults } from "../defaults";
@@ -1,60 +0,0 @@
import { BaseComputer } from "./base";
import { applyDefaults } from "../defaults";
import type { Display, LumierComputerConfig } from "../types";
import { computerLogger } from "../../util/logger";
/**
* Lumier-specific computer implementation
*/
export class LumierComputer extends BaseComputer {
private display: string | Display;
private memory: string;
private cpu: number;
private image: string;
private sharedDirectories?: string[];
private noVNCPort?: number;
private storage?: string;
private ephemeral: boolean;
constructor(config: LumierComputerConfig) {
super(config);
const defaultConfig = applyDefaults(config);
this.display = defaultConfig.display;
this.memory = defaultConfig.memory;
this.cpu = defaultConfig.cpu;
this.image = defaultConfig.image;
this.sharedDirectories = defaultConfig.sharedDirectories;
this.noVNCPort = defaultConfig.noVNCPort;
this.storage = defaultConfig.storage;
this.ephemeral = defaultConfig.ephemeral;
}
/**
* Lumier-specific method to start the container
*/
async startContainer(): Promise<void> {
computerLogger.info(
`Starting Lumier container ${this.name} with ${this.memory} memory and ${this.cpu} CPUs`
);
computerLogger.info(
`Using image ${this.image} with display ${
typeof this.display === "string"
? this.display
: `${this.display.width}x${this.display.height}`
}`
);
// Lumier-specific implementation
}
/**
* Lumier-specific method to execute a command in the container
*/
async execCommand(command: string): Promise<string> {
computerLogger.info(
`Executing command in Lumier container ${this.name}: ${command}`
);
return "command output"; // Example implementation
}
}
+3 -11
View File
@@ -24,7 +24,7 @@ export interface BaseComputerConfig {
osType: OSType;
/**
* The VM provider type to use (lume, lumier, cloud)
* The VM provider type to use (lume, cloud)
* @default VMProviderType.LUME
*/
vmProvider: VMProviderType;
@@ -80,7 +80,7 @@ export interface BaseComputerConfig {
port?: number;
/**
* Optional port for the noVNC web interface (Lumier provider)
* Optional port for the noVNC web interface
* @default 8006
*/
noVNCPort?: number;
@@ -92,7 +92,7 @@ export interface BaseComputerConfig {
host?: string;
/**
* Optional path for persistent VM storage (Lumier provider)
* Optional path for persistent VM storage
*/
storage?: string;
@@ -132,17 +132,9 @@ export interface LumeComputerConfig extends BaseComputerConfig {
vmProvider: VMProviderType.LUME;
}
/**
* The Lumier VM provider type
*/
export interface LumierComputerConfig extends BaseComputerConfig {
vmProvider: VMProviderType.LUMIER;
}
export enum VMProviderType {
CLOUD = "cloud",
LUME = "lume",
LUMIER = "lumier",
}
export enum OSType {
@@ -1,7 +0,0 @@
/**
* Shared logger module for the computer library
*/
import pino from "pino";
// Create and export default loggers for common components
export const computerLogger = pino({ name: "computer" });
+8 -3
View File
@@ -1,8 +1,11 @@
/**
* Shared API utilities for Lume and Lumier providers.
* Shared API utilities for Lume providers.
*
* This module contains shared functions for interacting with the Lume API,
* used by both the LumeProvider and LumierProvider classes.
* used by LumeProvider.
*
* WARNING: This file was created as a test/example implementation and is not maintained or expected to work.
* It serves as a reference for how a provider might be implemented but should not be used in production.
*/
import pino from "pino";
@@ -73,7 +76,9 @@ export async function lumeApiGet(
}
// Construct API URL with encoded storage parameter if needed
const apiUrl = `http://${host}:${port}/lume/vms${vmName ? `/${vmName}` : ""}${storageParam}`;
const apiUrl = `http://${host}:${port}/lume/vms${
vmName ? `/${vmName}` : ""
}${storageParam}`;
// Only print the fetch URL when debug is enabled
logger.info(`Executing API request: ${apiUrl}`);
+1 -23
View File
@@ -1,7 +1,7 @@
import { describe, expect, it } from "vitest";
import { Computer, OSType, VMProviderType } from "../src/index";
describe("Create Computer Instances", () => {
describe("Cloud Interface", () => {
it("should create a cloud computer", () => {
const computer = Computer.create({
vmProvider: VMProviderType.CLOUD,
@@ -11,26 +11,4 @@ describe("Create Computer Instances", () => {
apiKey: "asdf",
});
});
it("should create a lume computer", () => {
const computer = Computer.create({
vmProvider: VMProviderType.LUME,
display: { width: 1000, height: 1000, scale_factor: 1 },
image: "computer-image",
memory: "5GB",
cpu: 2,
name: "computer-name",
osType: OSType.MACOS,
});
});
it("should create a lumier computer", () => {
const computer = Computer.create({
vmProvider: VMProviderType.LUMIER,
display: { width: 1000, height: 1000, scale_factor: 1 },
image: "computer-image",
memory: "5GB",
cpu: 2,
name: "computer-name",
osType: OSType.MACOS,
});
});
});