feat: add main features
Agents for developpement added + frontend add + backend added. Git viewer created + agent and template creator + layout and project creator
This commit is contained in:
65
frontend/src/adapters/terminal.ts
Normal file
65
frontend/src/adapters/terminal.ts
Normal file
@ -0,0 +1,65 @@
|
||||
/**
|
||||
* Tauri adapter for {@link TerminalGateway} (L3). The single place that uses a
|
||||
* {@link Channel} for the high-frequency PTY byte stream and `invoke()` for the
|
||||
* control commands. Components reach it exclusively through the port.
|
||||
*
|
||||
* Flow (ARCHITECTURE §2 "Tauri Channels"):
|
||||
* - `openTerminal` creates a `Channel<number[]>`, passes it to the
|
||||
* `open_terminal` command, and forwards every chunk to `onData` as a
|
||||
* `Uint8Array`. The backend pumps PTY output into that channel via the
|
||||
* `PtyBridge`.
|
||||
* - keystrokes go out through `write_terminal`, resize through
|
||||
* `resize_terminal`, teardown through `close_terminal`.
|
||||
*
|
||||
* Commands and payload keys are camelCase, matching the backend DTO convention.
|
||||
*/
|
||||
|
||||
import { Channel, invoke } from "@tauri-apps/api/core";
|
||||
|
||||
import type {
|
||||
OpenTerminalOptions,
|
||||
TerminalGateway,
|
||||
TerminalHandle,
|
||||
} from "@/ports";
|
||||
|
||||
/** Wire shape returned by the `open_terminal` command. */
|
||||
interface OpenTerminalResponse {
|
||||
sessionId: string;
|
||||
cwd: string;
|
||||
rows: number;
|
||||
cols: number;
|
||||
}
|
||||
|
||||
export class TauriTerminalGateway implements TerminalGateway {
|
||||
async openTerminal(
|
||||
options: OpenTerminalOptions,
|
||||
onData: (bytes: Uint8Array) => void,
|
||||
): Promise<TerminalHandle> {
|
||||
// Per-session output channel. The backend serialises chunks as byte arrays.
|
||||
const channel = new Channel<number[]>();
|
||||
channel.onmessage = (chunk) => onData(Uint8Array.from(chunk));
|
||||
|
||||
const res = await invoke<OpenTerminalResponse>("open_terminal", {
|
||||
request: { cwd: options.cwd, rows: options.rows, cols: options.cols },
|
||||
onOutput: channel,
|
||||
});
|
||||
|
||||
const sessionId = res.sessionId;
|
||||
return {
|
||||
sessionId,
|
||||
async write(data: Uint8Array): Promise<void> {
|
||||
await invoke("write_terminal", {
|
||||
request: { sessionId, data: Array.from(data) },
|
||||
});
|
||||
},
|
||||
async resize(rows: number, cols: number): Promise<void> {
|
||||
await invoke("resize_terminal", {
|
||||
request: { sessionId, rows, cols },
|
||||
});
|
||||
},
|
||||
async close(): Promise<void> {
|
||||
await invoke("close_terminal", { sessionId });
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user