fix: orch (dynamic) version
This commit is contained in:
@@ -1,9 +1,14 @@
|
|||||||
|
import { existsSync, readFileSync } from "node:fs";
|
||||||
import { homedir } from "node:os";
|
import { homedir } from "node:os";
|
||||||
import { join } from "node:path";
|
import { dirname, join } from "node:path";
|
||||||
|
import { fileURLToPath } from "node:url";
|
||||||
|
|
||||||
const CONFIG_DIR_NAME = ".pi";
|
const CONFIG_DIR_NAME = ".pi";
|
||||||
const ENV_ORCHESTRATOR_DIR = "PI_ORCHESTRATOR_DIR";
|
const ENV_ORCHESTRATOR_DIR = "PI_ORCHESTRATOR_DIR";
|
||||||
|
|
||||||
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
|
const __dirname = dirname(__filename);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Detect if we're running as a Bun compiled binary.
|
* Detect if we're running as a Bun compiled binary.
|
||||||
* Bun binaries have import.meta.url containing "$bunfs", "~BUN", or "%7EBUN" (Bun's virtual filesystem path)
|
* Bun binaries have import.meta.url containing "$bunfs", "~BUN", or "%7EBUN" (Bun's virtual filesystem path)
|
||||||
@@ -11,6 +16,32 @@ const ENV_ORCHESTRATOR_DIR = "PI_ORCHESTRATOR_DIR";
|
|||||||
export const isBunBinary =
|
export const isBunBinary =
|
||||||
import.meta.url.includes("$bunfs") || import.meta.url.includes("~BUN") || import.meta.url.includes("%7EBUN");
|
import.meta.url.includes("$bunfs") || import.meta.url.includes("~BUN") || import.meta.url.includes("%7EBUN");
|
||||||
|
|
||||||
|
interface PackageJson {
|
||||||
|
version?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPackageJsonPath(): string {
|
||||||
|
let dir = __dirname;
|
||||||
|
while (dir !== dirname(dir)) {
|
||||||
|
const packageJsonPath = join(dir, "package.json");
|
||||||
|
if (existsSync(packageJsonPath)) {
|
||||||
|
return packageJsonPath;
|
||||||
|
}
|
||||||
|
dir = dirname(dir);
|
||||||
|
}
|
||||||
|
return join(__dirname, "package.json");
|
||||||
|
}
|
||||||
|
|
||||||
|
let pkg: PackageJson = {};
|
||||||
|
try {
|
||||||
|
pkg = JSON.parse(readFileSync(getPackageJsonPath(), "utf-8")) as PackageJson;
|
||||||
|
} catch (e: unknown) {
|
||||||
|
const err = e as NodeJS.ErrnoException;
|
||||||
|
if (err.code !== "ENOENT") throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const VERSION: string = pkg.version || "0.0.0";
|
||||||
|
|
||||||
export function getOrchestratorDir(): string {
|
export function getOrchestratorDir(): string {
|
||||||
const envDir = process.env[ENV_ORCHESTRATOR_DIR];
|
const envDir = process.env[ENV_ORCHESTRATOR_DIR];
|
||||||
if (envDir) {
|
if (envDir) {
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
import { hostname, platform } from "node:os";
|
import { hostname, platform } from "node:os";
|
||||||
import { AuthStorage, type OAuthCredential } from "@earendil-works/pi-coding-agent";
|
import { AuthStorage, type OAuthCredential } from "@earendil-works/pi-coding-agent";
|
||||||
import { getOrchestratorDir, getSocketPath } from "./config.ts";
|
import { getOrchestratorDir, getSocketPath, VERSION } from "./config.ts";
|
||||||
import { loadMachine, saveMachine } from "./storage.ts";
|
import { loadMachine, saveMachine } from "./storage.ts";
|
||||||
import type { InstanceRecord, MachineRecord, RadiusRegistration } from "./types.ts";
|
import type { InstanceRecord, MachineRecord, RadiusRegistration } from "./types.ts";
|
||||||
|
|
||||||
const DEFAULT_RADIUS_URL = "https://radius.pi.dev/";
|
const DEFAULT_RADIUS_URL = "https://radius.pi.dev/";
|
||||||
const DEFAULT_ORCHESTRATOR_BASE_PATH = "/v1/";
|
const DEFAULT_ORCHESTRATOR_BASE_PATH = "/v1/";
|
||||||
const ORCHESTRATOR_VERSION = "0.79.6";
|
|
||||||
const NOT_FOUND_RETRY_THRESHOLD = 3;
|
const NOT_FOUND_RETRY_THRESHOLD = 3;
|
||||||
const HEARTBEAT_BACKOFF_BASE_MS = 1_000;
|
const HEARTBEAT_BACKOFF_BASE_MS = 1_000;
|
||||||
const HEARTBEAT_BACKOFF_MAX_MS = 30_000;
|
const HEARTBEAT_BACKOFF_MAX_MS = 30_000;
|
||||||
@@ -243,7 +242,7 @@ export class RadiusPresence {
|
|||||||
hostname: hostname(),
|
hostname: hostname(),
|
||||||
platform: platform(),
|
platform: platform(),
|
||||||
arch: process.arch,
|
arch: process.arch,
|
||||||
version: ORCHESTRATOR_VERSION,
|
version: VERSION,
|
||||||
capabilities: { spawn: true, relay: false, iroh: false },
|
capabilities: { spawn: true, relay: false, iroh: false },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user