feat: add multi-session desktop workspace
This commit is contained in:
+52
-1
@@ -1,5 +1,9 @@
|
||||
import path from "node:path";
|
||||
import { createAgentRegistry, UnknownAgentError } from "./agent-registry.js";
|
||||
import {
|
||||
createAgentRegistry,
|
||||
UnknownAgentError,
|
||||
UnknownRuntimeError,
|
||||
} from "./agent-registry.js";
|
||||
import { startPiRpcAdapter } from "./pi-rpc-adapter.js";
|
||||
import { ProtocolError } from "../protocol/index.js";
|
||||
import { createRuntimePaths, startBridgeServer } from "./runtime.js";
|
||||
@@ -32,6 +36,35 @@ export async function startBridgeService({
|
||||
};
|
||||
case "forget_directory":
|
||||
return registry.forgetDirectory(request.payload.worktreePath);
|
||||
case "get_workspace":
|
||||
return registry.getWorkspace();
|
||||
case "get_workspace_summary":
|
||||
return registry.getWorkspaceSummary();
|
||||
case "create_session_runtime":
|
||||
return {
|
||||
runtime: await registry.createSessionRuntime(
|
||||
request.payload.worktreePath,
|
||||
),
|
||||
};
|
||||
case "open_session_runtime":
|
||||
return {
|
||||
runtime: await registry.openSessionRuntime(
|
||||
request.payload.worktreePath,
|
||||
request.payload.sessionPath,
|
||||
),
|
||||
};
|
||||
case "close_session_runtime":
|
||||
return registry.closeSessionRuntime(request.payload.runtimeId);
|
||||
case "list_directory_sessions":
|
||||
return {
|
||||
sessions: await registry.listDirectorySessions(
|
||||
request.payload.worktreePath,
|
||||
),
|
||||
};
|
||||
case "get_session_runtime_snapshot":
|
||||
return registry.getSessionRuntimeSnapshot(request.payload.runtimeId);
|
||||
case "subscribe_workspace":
|
||||
return registry.workspaceEventsAfter(request.payload.cursor ?? 0);
|
||||
case "subscribe":
|
||||
return {
|
||||
events: registry.eventsAfter(
|
||||
@@ -51,6 +84,8 @@ export async function startBridgeService({
|
||||
} catch (error) {
|
||||
if (error instanceof UnknownAgentError)
|
||||
throw new ProtocolError("unknown_agent", error.message);
|
||||
if (error instanceof UnknownRuntimeError)
|
||||
throw new ProtocolError("unknown_runtime", error.message);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -59,6 +94,22 @@ export async function startBridgeService({
|
||||
runtimeDir,
|
||||
handleRequest: dispatch,
|
||||
subscribe: (request, notify) => {
|
||||
if (request.op === "subscribe_workspace") {
|
||||
const subscription = registry.subscribeWorkspace(
|
||||
request.payload.cursor ?? 0,
|
||||
notify,
|
||||
);
|
||||
return {
|
||||
result: {
|
||||
bridgeInstanceId: subscription.bridgeInstanceId,
|
||||
firstAvailableSeq: subscription.firstAvailableSeq,
|
||||
latestSeq: subscription.latestSeq,
|
||||
truncated: subscription.truncated,
|
||||
events: subscription.events,
|
||||
},
|
||||
unsubscribe: subscription.unsubscribe,
|
||||
};
|
||||
}
|
||||
const subscription = registry.subscribe(
|
||||
request.agentId,
|
||||
request.payload.cursor ?? 0,
|
||||
|
||||
Reference in New Issue
Block a user