-
Notifications
You must be signed in to change notification settings - Fork 906
Cloud workspace plan #711
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Cloud workspace plan #711
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
87ad435
Cloud workspace plan
Kitenite 6ea098f
Update docs
Kitenite 7a74922
Simplify plan
Kitenite c90489f
Add impl plan
Kitenite a17eeda
implement plan
Kitenite 9b1d9f9
Merge main into cloud-ws
Kitenite fc38eb3
feat(desktop): add cloud workspace UI components and testing plan
Kitenite File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
182 changes: 182 additions & 0 deletions
182
apps/desktop/src/lib/trpc/routers/cloud-terminal/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,182 @@ | ||
| import { cloudWorkspaces } from "@superset/local-db"; | ||
| import { observable } from "@trpc/server/observable"; | ||
| import { eq } from "drizzle-orm"; | ||
| import { cloudTerminalManager } from "main/lib/cloud-terminal"; | ||
| import { localDb } from "main/lib/local-db"; | ||
| import { z } from "zod"; | ||
| import { publicProcedure, router } from "../.."; | ||
|
|
||
| /** | ||
| * Cloud Terminal router for managing remote terminal sessions on cloud workspaces | ||
| * | ||
| * Uses the Freestyle SDK to connect to cloud VMs and establish WebSocket-based | ||
| * terminal sessions. Sessions are keyed by paneId and linked to cloud workspaces. | ||
| */ | ||
| export const createCloudTerminalRouter = () => { | ||
| return router({ | ||
| /** | ||
| * Create or attach to a cloud terminal session | ||
| */ | ||
| createOrAttach: publicProcedure | ||
| .input( | ||
| z.object({ | ||
| paneId: z.string(), | ||
| tabId: z.string(), | ||
| cloudWorkspaceId: z.string(), | ||
| cols: z.number().optional(), | ||
| rows: z.number().optional(), | ||
| }), | ||
| ) | ||
| .mutation(async ({ input }) => { | ||
| const { paneId, tabId, cloudWorkspaceId, cols, rows } = input; | ||
|
|
||
| // Get cloud workspace to find the VM ID | ||
| const cloudWorkspace = localDb | ||
| .select() | ||
| .from(cloudWorkspaces) | ||
| .where(eq(cloudWorkspaces.id, cloudWorkspaceId)) | ||
| .get(); | ||
|
|
||
| if (!cloudWorkspace) { | ||
| throw new Error(`Cloud workspace ${cloudWorkspaceId} not found`); | ||
| } | ||
|
|
||
| if (!cloudWorkspace.provider_vm_id) { | ||
| throw new Error( | ||
| `Cloud workspace ${cloudWorkspaceId} does not have a VM assigned`, | ||
| ); | ||
| } | ||
|
|
||
| if (cloudWorkspace.status !== "running") { | ||
| throw new Error( | ||
| `Cloud workspace ${cloudWorkspaceId} is not running (status: ${cloudWorkspace.status})`, | ||
| ); | ||
| } | ||
|
|
||
| const result = await cloudTerminalManager.createOrAttach({ | ||
| paneId, | ||
| tabId, | ||
| cloudWorkspaceId, | ||
| vmId: cloudWorkspace.provider_vm_id, | ||
| cols, | ||
| rows, | ||
| }); | ||
|
|
||
| return { | ||
| paneId, | ||
| isNew: result.isNew, | ||
| scrollback: result.scrollback, | ||
| wasRecovered: result.wasRecovered, | ||
| viewportY: result.viewportY, | ||
| }; | ||
| }), | ||
|
|
||
| /** | ||
| * Write data to cloud terminal | ||
| */ | ||
| write: publicProcedure | ||
| .input( | ||
| z.object({ | ||
| paneId: z.string(), | ||
| data: z.string(), | ||
| }), | ||
| ) | ||
| .mutation(({ input }) => { | ||
| cloudTerminalManager.write(input); | ||
| }), | ||
|
|
||
| /** | ||
| * Resize cloud terminal | ||
| */ | ||
| resize: publicProcedure | ||
| .input( | ||
| z.object({ | ||
| paneId: z.string(), | ||
| cols: z.number(), | ||
| rows: z.number(), | ||
| }), | ||
| ) | ||
| .mutation(({ input }) => { | ||
| cloudTerminalManager.resize(input); | ||
| }), | ||
|
|
||
| /** | ||
| * Kill cloud terminal session | ||
| */ | ||
| kill: publicProcedure | ||
| .input( | ||
| z.object({ | ||
| paneId: z.string(), | ||
| }), | ||
| ) | ||
| .mutation(async ({ input }) => { | ||
| await cloudTerminalManager.kill(input); | ||
| }), | ||
|
|
||
| /** | ||
| * Detach from cloud terminal (keep session alive) | ||
| */ | ||
| detach: publicProcedure | ||
| .input( | ||
| z.object({ | ||
| paneId: z.string(), | ||
| viewportY: z.number().optional(), | ||
| }), | ||
| ) | ||
| .mutation(({ input }) => { | ||
| cloudTerminalManager.detach(input); | ||
| }), | ||
|
|
||
| /** | ||
| * Clear scrollback buffer for cloud terminal | ||
| */ | ||
| clearScrollback: publicProcedure | ||
| .input( | ||
| z.object({ | ||
| paneId: z.string(), | ||
| }), | ||
| ) | ||
| .mutation(({ input }) => { | ||
| cloudTerminalManager.clearScrollback(input); | ||
| }), | ||
|
|
||
| /** | ||
| * Get cloud terminal session info | ||
| */ | ||
| getSession: publicProcedure | ||
| .input(z.string()) | ||
| .query(({ input: paneId }) => { | ||
| return cloudTerminalManager.getSession(paneId); | ||
| }), | ||
|
|
||
| /** | ||
| * Stream data from cloud terminal | ||
| */ | ||
| stream: publicProcedure | ||
| .input(z.string()) | ||
| .subscription(({ input: paneId }) => { | ||
| return observable< | ||
| | { type: "data"; data: string } | ||
| | { type: "exit"; exitCode: number; signal?: number } | ||
| >((emit) => { | ||
| const onData = (data: string) => { | ||
| emit.next({ type: "data", data }); | ||
| }; | ||
|
|
||
| const onExit = (exitCode: number, signal?: number) => { | ||
| emit.next({ type: "exit", exitCode, signal }); | ||
| emit.complete(); | ||
| }; | ||
|
|
||
| cloudTerminalManager.on(`data:${paneId}`, onData); | ||
| cloudTerminalManager.on(`exit:${paneId}`, onExit); | ||
|
|
||
| // Cleanup on unsubscribe | ||
| return () => { | ||
| cloudTerminalManager.off(`data:${paneId}`, onData); | ||
| cloudTerminalManager.off(`exit:${paneId}`, onExit); | ||
| }; | ||
| }); | ||
| }), | ||
| }); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export { cloudTerminalManager, CloudTerminalManager } from "./manager"; | ||
| export * from "./types"; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add error handling to manager calls.
These mutations delegate to
cloudTerminalManagerwithout error handling. Per coding guidelines, errors should not be swallowed silently. If the manager throws, the error should be caught and logged with context.♻️ Example fix for write mutation
write: publicProcedure .input( z.object({ paneId: z.string(), data: z.string(), }), ) .mutation(({ input }) => { - cloudTerminalManager.write(input); + try { + cloudTerminalManager.write(input); + } catch (error) { + console.error("[cloud-terminal/write] Failed to write data:", error); + throw error; + } }),Also applies to: 91-101, 119-128, 133-141
🤖 Prompt for AI Agents