6f32a206b4
Keeps provider credentials local while executing OpenCode shell and file tools against the selected remote workspace over SSH.
182 lines
6.7 KiB
JavaScript
182 lines
6.7 KiB
JavaScript
"use strict";
|
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
}
|
|
Object.defineProperty(o, k2, desc);
|
|
}) : (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
o[k2] = m[k];
|
|
}));
|
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
}) : function(o, v) {
|
|
o["default"] = v;
|
|
});
|
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
};
|
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
if (mod && mod.__esModule) return mod;
|
|
var result = {};
|
|
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
__setModuleDefault(result, mod);
|
|
return result;
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.GitZoneOpenCodeNodeService = void 0;
|
|
const ide_opencode_bridge_1 = require("@git.zone/ide-opencode-bridge");
|
|
const index_js_1 = require("@theia/core/shared/inversify/index.js");
|
|
const plugins = __importStar(require("./plugins.js"));
|
|
let GitZoneOpenCodeNodeService = class GitZoneOpenCodeNodeService {
|
|
client;
|
|
eventAbortController;
|
|
openCodeProcess;
|
|
initialize() {
|
|
if (this.autoStart) {
|
|
void this.ensureOpenCodeStarted();
|
|
}
|
|
}
|
|
onStop() {
|
|
this.eventAbortController?.abort();
|
|
if (this.openCodeProcess && this.openCodeProcess.exitCode === null) {
|
|
this.openCodeProcess.kill('SIGTERM');
|
|
}
|
|
}
|
|
setClient(client) {
|
|
this.client = client;
|
|
this.restartEventStream();
|
|
}
|
|
async getConnectionInfo() {
|
|
return {
|
|
baseUrl: this.baseUrl,
|
|
port: this.port,
|
|
workspacePath: this.workspacePath,
|
|
autoStart: this.autoStart,
|
|
};
|
|
}
|
|
async health() {
|
|
await this.ensureOpenCodeStarted();
|
|
return this.createClient().health();
|
|
}
|
|
async providers() {
|
|
return this.createClient().providers();
|
|
}
|
|
async agents() {
|
|
return this.createClient().agents();
|
|
}
|
|
async sessions() {
|
|
return this.createClient().sessions();
|
|
}
|
|
async createSession(title) {
|
|
return this.createClient().createSession(title ? { title } : {});
|
|
}
|
|
async messages(sessionId, limit) {
|
|
return this.createClient().messages(sessionId, limit);
|
|
}
|
|
async prompt(sessionId, body) {
|
|
return this.createClient().prompt(sessionId, body);
|
|
}
|
|
async promptAsync(sessionId, body) {
|
|
await this.createClient().promptAsync(sessionId, body);
|
|
}
|
|
async command(sessionId, command, commandArguments = '') {
|
|
return this.createClient().command(sessionId, { command, arguments: commandArguments });
|
|
}
|
|
async abort(sessionId) {
|
|
return this.createClient().abort(sessionId);
|
|
}
|
|
async diff(sessionId, messageId) {
|
|
return this.createClient().diff(sessionId, messageId);
|
|
}
|
|
async todo(sessionId) {
|
|
return this.createClient().todo(sessionId);
|
|
}
|
|
async respondToPermission(sessionId, permissionId, response, remember) {
|
|
return this.createClient().respondToPermission(sessionId, permissionId, { response, remember });
|
|
}
|
|
async ensureOpenCodeStarted() {
|
|
try {
|
|
await this.createClient().health();
|
|
return;
|
|
}
|
|
catch {
|
|
if (!this.autoStart || this.openCodeProcess) {
|
|
return;
|
|
}
|
|
}
|
|
this.openCodeProcess = plugins.childProcess.spawn('opencode', ['serve', '--hostname', '127.0.0.1', '--port', `${this.port}`], {
|
|
cwd: this.workspacePath,
|
|
env: {
|
|
...process.env,
|
|
OPENCODE_SERVER_USERNAME: this.username,
|
|
OPENCODE_SERVER_PASSWORD: this.password,
|
|
},
|
|
shell: false,
|
|
stdio: ['ignore', 'ignore', 'ignore'],
|
|
windowsHide: true,
|
|
});
|
|
this.openCodeProcess.once('error', (error) => {
|
|
console.warn(`OpenCode server autostart failed: ${error.message}`);
|
|
this.openCodeProcess = undefined;
|
|
});
|
|
this.openCodeProcess.once('exit', () => {
|
|
this.openCodeProcess = undefined;
|
|
});
|
|
}
|
|
restartEventStream() {
|
|
this.eventAbortController?.abort();
|
|
if (!this.client) {
|
|
return;
|
|
}
|
|
const abortController = new AbortController();
|
|
this.eventAbortController = abortController;
|
|
void (async () => {
|
|
try {
|
|
await this.ensureOpenCodeStarted();
|
|
for await (const event of this.createClient().events(abortController.signal)) {
|
|
this.client?.onOpenCodeEvent(event);
|
|
}
|
|
}
|
|
catch {
|
|
// The UI can explicitly call health() for detailed connection diagnostics.
|
|
}
|
|
})();
|
|
}
|
|
createClient() {
|
|
return new ide_opencode_bridge_1.OpenCodeServerClient({
|
|
baseUrl: this.baseUrl,
|
|
username: this.username,
|
|
password: this.password,
|
|
});
|
|
}
|
|
get workspacePath() {
|
|
return process.env.GITZONE_IDE_WORKSPACE || process.cwd();
|
|
}
|
|
get port() {
|
|
const port = Number(process.env.GITZONE_IDE_OPENCODE_PORT || '4096');
|
|
return Number.isInteger(port) && port > 0 ? port : 4096;
|
|
}
|
|
get baseUrl() {
|
|
return `http://127.0.0.1:${this.port}`;
|
|
}
|
|
get username() {
|
|
return process.env.OPENCODE_SERVER_USERNAME || 'opencode';
|
|
}
|
|
get password() {
|
|
return process.env.OPENCODE_SERVER_PASSWORD || '';
|
|
}
|
|
get autoStart() {
|
|
return process.env.GITZONE_IDE_DISABLE_OPENCODE_AUTOSTART !== '1';
|
|
}
|
|
};
|
|
exports.GitZoneOpenCodeNodeService = GitZoneOpenCodeNodeService;
|
|
exports.GitZoneOpenCodeNodeService = GitZoneOpenCodeNodeService = __decorate([
|
|
(0, index_js_1.injectable)()
|
|
], GitZoneOpenCodeNodeService);
|
|
//# sourceMappingURL=gitzone-opencode-node-service.js.map
|