Skip to content
Open
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
6 changes: 6 additions & 0 deletions apps/desktop/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import { isArm64HostRunningIntelBuild, resolveDesktopRuntimeInfo } from "./runti
fixPath();

const PICK_FOLDER_CHANNEL = "desktop:pick-folder";
const GET_WS_URL_CHANNEL = "desktop:get-ws-url";
const CONFIRM_CHANNEL = "desktop:confirm";
const SET_THEME_CHANNEL = "desktop:set-theme";
const CONTEXT_MENU_CHANNEL = "desktop:context-menu";
Expand Down Expand Up @@ -1086,6 +1087,11 @@ function registerIpcHandlers(): void {
return result.filePaths[0] ?? null;
});

ipcMain.removeAllListeners(GET_WS_URL_CHANNEL);
ipcMain.on(GET_WS_URL_CHANNEL, (event) => {
event.returnValue = backendWsUrl || null;
});

ipcMain.removeHandler(CONFIRM_CHANNEL);
ipcMain.handle(CONFIRM_CHANNEL, async (_event, message: unknown) => {
if (typeof message !== "string") {
Expand Down
11 changes: 10 additions & 1 deletion apps/desktop/src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { contextBridge, ipcRenderer } from "electron";
import type { DesktopBridge } from "@t3tools/contracts";

const PICK_FOLDER_CHANNEL = "desktop:pick-folder";
const GET_WS_URL_CHANNEL = "desktop:get-ws-url";
const CONFIRM_CHANNEL = "desktop:confirm";
const SET_THEME_CHANNEL = "desktop:set-theme";
const CONTEXT_MENU_CHANNEL = "desktop:context-menu";
Expand All @@ -11,7 +12,15 @@ const UPDATE_STATE_CHANNEL = "desktop:update-state";
const UPDATE_GET_STATE_CHANNEL = "desktop:update-get-state";
const UPDATE_DOWNLOAD_CHANNEL = "desktop:update-download";
const UPDATE_INSTALL_CHANNEL = "desktop:update-install";
const wsUrl = process.env.T3CODE_DESKTOP_WS_URL ?? null;
let wsUrl: string | null = null;
try {
const value = ipcRenderer.sendSync(GET_WS_URL_CHANNEL);
if (typeof value === "string" && value.length > 0) {
wsUrl = value;
}
} catch {
wsUrl = null;
}

contextBridge.exposeInMainWorld("desktopBridge", {
getWsUrl: () => wsUrl,
Expand Down
23 changes: 14 additions & 9 deletions apps/server/src/persistence/Layers/OrchestrationEventStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from "@t3tools/contracts";
import * as SqlClient from "effect/unstable/sql/SqlClient";
import * as SqlSchema from "effect/unstable/sql/SqlSchema";
import { Effect, Layer, Schema, Stream } from "effect";
import { Effect, Layer, Option, Schema, Stream } from "effect";

import {
toPersistenceDecodeError,
Expand Down Expand Up @@ -231,26 +231,31 @@ const makeEventStore = Effect.gen(function* () {
Effect.flatMap((rows) =>
Effect.forEach(rows, (row) =>
decodeEvent(row).pipe(
Effect.mapError(
toPersistenceDecodeError("OrchestrationEventStore.readFromSequence:rowToEvent"),
Effect.map(Option.some),
Effect.catch((cause) =>
Effect.logWarning(
`OrchestrationEventStore.readFromSequence: dropping event sequence=${row.sequence} due to decode error: ${String(cause)}`,
).pipe(Effect.as(Option.none<OrchestrationEvent>())),
),
),
).pipe(
Effect.map((events) => ({
events: events.flatMap((event) => (Option.isSome(event) ? [event.value] : [])),
lastSequence: rows.length > 0 ? rows[rows.length - 1]!.sequence : null,
})),
),
),
),
).pipe(
Stream.flatMap((events) => {
if (events.length === 0) {
Stream.flatMap(({ events, lastSequence }) => {
if (lastSequence === null) {
return Stream.empty;
}
const nextRemaining = remaining - events.length;
if (nextRemaining <= 0) {
return Stream.fromIterable(events);
}
return Stream.concat(
Stream.fromIterable(events),
readPage(events[events.length - 1]!.sequence, nextRemaining),
);
return Stream.concat(Stream.fromIterable(events), readPage(lastSequence, nextRemaining));
}),
);

Expand Down
12 changes: 12 additions & 0 deletions apps/server/src/provider/Layers/ProviderSessionDirectory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ const makeProviderSessionDirectory = Effect.gen(function* () {
runtimePayload: value.runtimePayload,
}),
),
Effect.catch(() =>
// Unknown providers should not poison startup; drop the binding and move on.
repository
.deleteByThreadId({ threadId: value.threadId })
.pipe(
Effect.mapError(
toPersistenceError("ProviderSessionDirectory.getBinding:cleanup"),
),
Effect.ignore,
Effect.as(Option.none<ProviderRuntimeBinding>()),
),
),
),
}),
),
Expand Down