fix: rpc-entry and bun support
This commit is contained in:
@@ -15,6 +15,9 @@
|
|||||||
".": {
|
".": {
|
||||||
"types": "./dist/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
"import": "./dist/index.js"
|
"import": "./dist/index.js"
|
||||||
|
},
|
||||||
|
"./rpc-entry": {
|
||||||
|
"import": "./dist/rpc-entry.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
@@ -27,7 +30,7 @@
|
|||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "shx rm -rf dist",
|
"clean": "shx rm -rf dist",
|
||||||
"build": "tsgo -p tsconfig.build.json && shx chmod +x dist/cli.js && npm run copy-assets",
|
"build": "tsgo -p tsconfig.build.json && shx chmod +x dist/cli.js dist/rpc-entry.js && npm run copy-assets",
|
||||||
"build:binary": "npm --prefix ../tui run build && npm --prefix ../ai run build && npm --prefix ../agent run build && npm run build && bun build --compile ./dist/bun/cli.js ./src/utils/image-resize-worker.ts --outfile dist/pi && npm run copy-binary-assets",
|
"build:binary": "npm --prefix ../tui run build && npm --prefix ../ai run build && npm --prefix ../agent run build && npm run build && bun build --compile ./dist/bun/cli.js ./src/utils/image-resize-worker.ts --outfile dist/pi && npm run copy-binary-assets",
|
||||||
"copy-assets": "shx mkdir -p dist/modes/interactive/theme && shx cp src/modes/interactive/theme/*.json dist/modes/interactive/theme/ && shx mkdir -p dist/modes/interactive/assets && shx cp src/modes/interactive/assets/*.png dist/modes/interactive/assets/ && shx mkdir -p dist/core/export-html/vendor && shx cp src/core/export-html/template.html src/core/export-html/template.css src/core/export-html/template.js dist/core/export-html/ && shx cp src/core/export-html/vendor/*.js dist/core/export-html/vendor/",
|
"copy-assets": "shx mkdir -p dist/modes/interactive/theme && shx cp src/modes/interactive/theme/*.json dist/modes/interactive/theme/ && shx mkdir -p dist/modes/interactive/assets && shx cp src/modes/interactive/assets/*.png dist/modes/interactive/assets/ && shx mkdir -p dist/core/export-html/vendor && shx cp src/core/export-html/template.html src/core/export-html/template.css src/core/export-html/template.js dist/core/export-html/ && shx cp src/core/export-html/vendor/*.js dist/core/export-html/vendor/",
|
||||||
"copy-binary-assets": "shx cp package.json dist/ && shx cp README.md dist/ && shx cp CHANGELOG.md dist/ && shx mkdir -p dist/theme && shx cp src/modes/interactive/theme/*.json dist/theme/ && shx mkdir -p dist/assets && shx cp src/modes/interactive/assets/*.png dist/assets/ && shx mkdir -p dist/export-html/vendor && shx cp src/core/export-html/template.html dist/export-html/ && shx cp src/core/export-html/vendor/*.js dist/export-html/vendor/ && shx cp -r docs dist/ && shx cp -r examples dist/ && shx cp ../../node_modules/@silvia-odwyer/photon-node/photon_rs_bg.wasm dist/",
|
"copy-binary-assets": "shx cp package.json dist/ && shx cp README.md dist/ && shx cp CHANGELOG.md dist/ && shx mkdir -p dist/theme && shx cp src/modes/interactive/theme/*.json dist/theme/ && shx mkdir -p dist/assets && shx cp src/modes/interactive/assets/*.png dist/assets/ && shx mkdir -p dist/export-html/vendor && shx cp src/core/export-html/template.html dist/export-html/ && shx cp src/core/export-html/vendor/*.js dist/export-html/vendor/ && shx cp -r docs dist/ && shx cp -r examples dist/ && shx cp ../../node_modules/@silvia-odwyer/photon-node/photon_rs_bg.wasm dist/",
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
import { APP_NAME } from "./config.ts";
|
||||||
|
import { configureHttpDispatcher } from "./core/http-dispatcher.ts";
|
||||||
|
import { main } from "./main.ts";
|
||||||
|
|
||||||
|
process.title = `${APP_NAME}-rpc`;
|
||||||
|
process.env.PI_CODING_AGENT = "true";
|
||||||
|
process.emitWarning = (() => {}) as typeof process.emitWarning;
|
||||||
|
|
||||||
|
configureHttpDispatcher();
|
||||||
|
|
||||||
|
main(["--mode", "rpc", ...process.argv.slice(2)]);
|
||||||
@@ -3,9 +3,6 @@
|
|||||||
"version": "0.80.2",
|
"version": "0.80.2",
|
||||||
"description": "experimental orchestrator package for pi",
|
"description": "experimental orchestrator package for pi",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"bin": {
|
|
||||||
"orchestrator": "dist/cli.js"
|
|
||||||
},
|
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
"types": "./dist/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
"exports": {
|
"exports": {
|
||||||
|
|||||||
@@ -4,6 +4,13 @@ import { join } from "node:path";
|
|||||||
const CONFIG_DIR_NAME = ".pi";
|
const CONFIG_DIR_NAME = ".pi";
|
||||||
const ENV_ORCHESTRATOR_DIR = "PI_ORCHESTRATOR_DIR";
|
const ENV_ORCHESTRATOR_DIR = "PI_ORCHESTRATOR_DIR";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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)
|
||||||
|
*/
|
||||||
|
export const isBunBinary =
|
||||||
|
import.meta.url.includes("$bunfs") || import.meta.url.includes("~BUN") || import.meta.url.includes("%7EBUN");
|
||||||
|
|
||||||
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,8 +1,7 @@
|
|||||||
import { type ChildProcess, spawn } from "node:child_process";
|
import { type ChildProcess, spawn } from "node:child_process";
|
||||||
import { randomUUID } from "node:crypto";
|
import { randomUUID } from "node:crypto";
|
||||||
import { existsSync } from "node:fs";
|
import { createRequire } from "node:module";
|
||||||
import { dirname, join } from "node:path";
|
import { dirname, join } from "node:path";
|
||||||
import { fileURLToPath } from "node:url";
|
|
||||||
import type {
|
import type {
|
||||||
AgentSessionEvent,
|
AgentSessionEvent,
|
||||||
RpcCommand,
|
RpcCommand,
|
||||||
@@ -10,6 +9,7 @@ import type {
|
|||||||
RpcExtensionUIResponse,
|
RpcExtensionUIResponse,
|
||||||
RpcResponse,
|
RpcResponse,
|
||||||
} from "@earendil-works/pi-coding-agent";
|
} from "@earendil-works/pi-coding-agent";
|
||||||
|
import { isBunBinary } from "./config.ts";
|
||||||
|
|
||||||
interface PendingRequest {
|
interface PendingRequest {
|
||||||
resolve(response: RpcResponse): void;
|
resolve(response: RpcResponse): void;
|
||||||
@@ -26,13 +26,19 @@ export interface RpcProcessInstance {
|
|||||||
dispose(): Promise<void>;
|
dispose(): Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveCodingAgentCli(): string {
|
const require = createRequire(import.meta.url);
|
||||||
const packageDir = dirname(fileURLToPath(import.meta.url));
|
|
||||||
const workspaceCli = join(packageDir, "../../coding-agent/dist/cli.js");
|
function getRpcSpawnCommand(): { command: string; args: string[] } {
|
||||||
if (existsSync(workspaceCli)) {
|
if (isBunBinary) {
|
||||||
return workspaceCli;
|
return {
|
||||||
|
command: join(dirname(process.execPath), process.platform === "win32" ? "pi.exe" : "pi"),
|
||||||
|
args: ["--mode", "rpc"],
|
||||||
|
};
|
||||||
}
|
}
|
||||||
throw new Error(`Unable to find coding-agent RPC CLI: ${workspaceCli}`);
|
return {
|
||||||
|
command: process.execPath,
|
||||||
|
args: [require.resolve("@earendil-works/pi-coding-agent/rpc-entry")],
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function toError(error: unknown): Error {
|
function toError(error: unknown): Error {
|
||||||
@@ -40,8 +46,8 @@ function toError(error: unknown): Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function createRpcProcessInstance(options: { cwd: string }): RpcProcessInstance {
|
export function createRpcProcessInstance(options: { cwd: string }): RpcProcessInstance {
|
||||||
const cliPath = resolveCodingAgentCli();
|
const rpcCommand = getRpcSpawnCommand();
|
||||||
const child = spawn(process.execPath, [cliPath, "--mode", "rpc"], {
|
const child = spawn(rpcCommand.command, rpcCommand.args, {
|
||||||
cwd: options.cwd,
|
cwd: options.cwd,
|
||||||
env: process.env,
|
env: process.env,
|
||||||
stdio: ["pipe", "pipe", "pipe"],
|
stdio: ["pipe", "pipe", "pipe"],
|
||||||
|
|||||||
Reference in New Issue
Block a user