add workspace mode to gadget-drone process
Read docs/gadget-workspace.md for more information
This commit is contained in:
parent
1b8044a8a7
commit
c88081b2ba
@ -16,17 +16,32 @@ import PlatformService, {
|
||||
} from "./services/platform.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 {
|
||||
email: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
enum WorkspaceMode {
|
||||
Idle = "idle",
|
||||
Syncing = "syncing",
|
||||
User = "user",
|
||||
Agent = "agent",
|
||||
}
|
||||
|
||||
type ClientSocket = Socket<ServerToClientEvents, ClientToServerEvents>;
|
||||
|
||||
class GadgetDrone extends GadgetProcess {
|
||||
private registration: PlatformRegistration | undefined;
|
||||
private workspaceMode: WorkspaceMode = WorkspaceMode.Syncing;
|
||||
private socket: ClientSocket | undefined;
|
||||
private isShuttingDown: boolean = false;
|
||||
|
||||
@ -140,9 +155,32 @@ class GadgetDrone extends GadgetProcess {
|
||||
this.log.info("connected to Gadget Code platform.");
|
||||
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 {
|
||||
process.title = this.name;
|
||||
|
||||
|
||||
@ -6,11 +6,16 @@ import { IChatSession } from "../interfaces/chat-session.ts";
|
||||
import { IDroneRegistration } from "../interfaces/drone-registration.ts";
|
||||
import { IProject } from "../interfaces/project.ts";
|
||||
|
||||
export type RequestSessionLockCallback = (
|
||||
success: boolean,
|
||||
chatSessionId: string,
|
||||
) => void;
|
||||
|
||||
export type RequestSessionLockMessage = (
|
||||
registration: IDroneRegistration,
|
||||
project: IProject,
|
||||
chatSession: IChatSession,
|
||||
cb: (success: boolean, chatSessionId: string) => void,
|
||||
cb: RequestSessionLockCallback,
|
||||
) => void;
|
||||
|
||||
export type SubmitPromptMessage = (prompt: string) => void;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user