Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion ts/packages/agentServer/client/src/agentServerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export async function connectDispatcher(
clientIO: ClientIO,
url: string | URL,
options?: DispatcherConnectOptions,
onDisconnect?: () => void,
): Promise<Dispatcher> {
return new Promise((resolve, reject: (e: Error) => void) => {
const ws = new WebSocket(url); // Replace with the actual WebSocket server URL
Expand Down Expand Up @@ -74,7 +75,9 @@ export async function connectDispatcher(
ws.onclose = (event: WebSocket.CloseEvent) => {
debug("WebSocket connection closed", event.code, event.reason);
channel.notifyDisconnected();
if (!resolved) {
if (resolved) {
onDisconnect?.();
} else {
reject(new Error(`Failed to connect to dispatcher at ${url}`));
}
};
Expand Down
5 changes: 5 additions & 0 deletions ts/packages/cli/src/commands/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ export default class Connect extends Command {
const dispatcher = await connectDispatcher(
clientIO,
`ws://localhost:${flags.port}`,
undefined,
() => {
console.error("Disconnected from dispatcher");
process.exit(1);
},
);
try {
let processed = false;
Expand Down
8 changes: 8 additions & 0 deletions ts/packages/shell/src/main/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ async function initializeDispatcher(
newDispatcher = await connectDispatcher(
clientIO,
`ws://localhost:${connect}`,
undefined,
() => {
dialog.showErrorBox(
"Disconnected",
"The connection to the dispatcher was lost.",
);
app.quit();
},
);
debugShellInit(
"Connected to remote dispatcher",
Expand Down