Files
paseo/packages/server/src/server/agent/providers/opencode/test-server-manager.ts
T
Mohamed Boudra 99dc8ddda5 Free resources from idle agents automatically (#2203)
* fix(server): release resources held by idle agents

Keep unarchived agents resumable while closing their provider runtimes after two minutes. Active agent schedules keep runtimes resident.

* fix(server): preserve resumable agent state

* fix(server): resume agents when listing commands

* fix(server): preserve collected agent interactions
2026-07-18 21:21:05 +02:00

56 lines
1.7 KiB
TypeScript

import type { OpenCodeServerAcquisition, OpenCodeServerManagerLike } from "./server-manager.js";
export interface TestOpenCodeServerAcquisition {
kind: "current" | "new" | "dedicated" | "existing";
env?: Record<string, string>;
url?: string;
released: boolean;
}
export class TestOpenCodeServerManager implements OpenCodeServerManagerLike {
readonly acquisitions: TestOpenCodeServerAcquisition[] = [];
readonly server = { port: 1234, url: "http://127.0.0.1:1234" };
async acquireCurrent(): Promise<OpenCodeServerAcquisition> {
return this.recordAcquisition({ kind: "current" });
}
async acquireNew(): Promise<OpenCodeServerAcquisition> {
return this.recordAcquisition({ kind: "new" });
}
async acquireDedicated(env: Record<string, string>): Promise<OpenCodeServerAcquisition> {
return this.recordAcquisition({ kind: "dedicated", env });
}
acquireExisting(url: string): OpenCodeServerAcquisition | null {
return url === this.server.url ? this.recordAcquisition({ kind: "existing", url }) : null;
}
private recordAcquisition(input: {
kind: TestOpenCodeServerAcquisition["kind"];
env?: Record<string, string>;
url?: string;
}): OpenCodeServerAcquisition {
const acquisition: TestOpenCodeServerAcquisition = {
kind: input.kind,
released: false,
...(input.env ? { env: input.env } : {}),
...(input.url ? { url: input.url } : {}),
};
this.acquisitions.push(acquisition);
return {
server: this.server,
release: async () => {
acquisition.released = true;
},
};
}
async shutdown(): Promise<void> {}
}
export function createTestOpenCodeServerManager(): TestOpenCodeServerManager {
return new TestOpenCodeServerManager();
}