add workspace mode to gadget-drone process

Read docs/gadget-workspace.md for more information
This commit is contained in:
Rob Colbert 2026-04-29 13:40:19 -04:00
parent 1b8044a8a7
commit c88081b2ba
2 changed files with 45 additions and 2 deletions

View File

@ -16,17 +16,32 @@ import PlatformService, {
} from "./services/platform.ts"; } from "./services/platform.ts";
import { GadgetProcess } from "./lib/process.ts"; import { GadgetProcess } from "./lib/process.ts";
import { ClientToServerEvents, ServerToClientEvents } from "@gadget/api"; import {
ClientToServerEvents,
IChatSession,
IDroneRegistration,
IProject,
RequestSessionLockCallback,
ServerToClientEvents,
} from "@gadget/api";
interface UserCredentials { interface UserCredentials {
email: string; email: string;
password: string; password: string;
} }
enum WorkspaceMode {
Idle = "idle",
Syncing = "syncing",
User = "user",
Agent = "agent",
}
type ClientSocket = Socket<ServerToClientEvents, ClientToServerEvents>; type ClientSocket = Socket<ServerToClientEvents, ClientToServerEvents>;
class GadgetDrone extends GadgetProcess { class GadgetDrone extends GadgetProcess {
private registration: PlatformRegistration | undefined; private registration: PlatformRegistration | undefined;
private workspaceMode: WorkspaceMode = WorkspaceMode.Syncing;
private socket: ClientSocket | undefined; private socket: ClientSocket | undefined;
private isShuttingDown: boolean = false; private isShuttingDown: boolean = false;
@ -140,9 +155,32 @@ class GadgetDrone extends GadgetProcess {
this.log.info("connected to Gadget Code platform."); this.log.info("connected to Gadget Code platform.");
resolve(); resolve();
}); });
this.socket.on(
"requestSessionLock",
this.onRequestSessionLock.bind(this),
);
}); });
} }
async onRequestSessionLock(
registration: IDroneRegistration,
project: IProject,
chatSession: IChatSession,
cb: RequestSessionLockCallback,
) {
this.log.info(`requestSessionLock`, { registration, project, chatSession });
if (!this.registration) {
return cb(false, "not registered");
}
if (!registration._id.equals(this.registration._id)) {
return cb(false, "invalid registration");
}
this.workspaceMode = WorkspaceMode.User;
cb(true, chatSession._id.toHexString());
}
hookProcessSignals(): void { hookProcessSignals(): void {
process.title = this.name; process.title = this.name;

View File

@ -6,11 +6,16 @@ import { IChatSession } from "../interfaces/chat-session.ts";
import { IDroneRegistration } from "../interfaces/drone-registration.ts"; import { IDroneRegistration } from "../interfaces/drone-registration.ts";
import { IProject } from "../interfaces/project.ts"; import { IProject } from "../interfaces/project.ts";
export type RequestSessionLockCallback = (
success: boolean,
chatSessionId: string,
) => void;
export type RequestSessionLockMessage = ( export type RequestSessionLockMessage = (
registration: IDroneRegistration, registration: IDroneRegistration,
project: IProject, project: IProject,
chatSession: IChatSession, chatSession: IChatSession,
cb: (success: boolean, chatSessionId: string) => void, cb: RequestSessionLockCallback,
) => void; ) => void;
export type SubmitPromptMessage = (prompt: string) => void; export type SubmitPromptMessage = (prompt: string) => void;