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
19 changes: 19 additions & 0 deletions apps/web/src/hooks/useThreadActions.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { EnvironmentId, ThreadId } from "@t3tools/contracts";
import { describe, expect, it } from "vite-plus/test";

import { ThreadArchiveBlockedError } from "./useThreadActions";

describe("ThreadArchiveBlockedError", () => {
it("keeps the blocked thread context with the fixed message", () => {
const error = new ThreadArchiveBlockedError({
environmentId: EnvironmentId.make("environment-1"),
threadId: ThreadId.make("thread-1"),
});

expect(error).toMatchObject({
environmentId: "environment-1",
threadId: "thread-1",
});
expect(error.message).toBe("Cannot archive a running thread.");
});
});
21 changes: 15 additions & 6 deletions apps/web/src/hooks/useThreadActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {
scopeThreadRef,
} from "@t3tools/client-runtime/environment";
import { settlePromise, squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
import { type ScopedThreadRef, ThreadId } from "@t3tools/contracts";
import { EnvironmentId, type ScopedThreadRef, ThreadId } from "@t3tools/contracts";
import * as Cause from "effect/Cause";
import * as Data from "effect/Data";
import * as Schema from "effect/Schema";
import { AsyncResult } from "effect/unstable/reactivity";
import { useRouter } from "@tanstack/react-router";
import { useCallback, useMemo, useRef } from "react";
Expand All @@ -27,9 +27,17 @@ import { stackedThreadToast, toastManager } from "../components/ui/toast";
import { useClientSettings } from "./useSettings";
import { useAtomCommand } from "../state/use-atom-command";

export class ThreadArchiveBlockedError extends Data.TaggedError("ThreadArchiveBlockedError")<{
readonly message: string;
}> {}
export class ThreadArchiveBlockedError extends Schema.TaggedErrorClass<ThreadArchiveBlockedError>()(
"ThreadArchiveBlockedError",
{
environmentId: EnvironmentId,
threadId: ThreadId,
},
) {
override get message(): string {
return "Cannot archive a running thread.";
}
}

export function useThreadActions() {
const closeTerminal = useAtomCommand(terminalEnvironment.close);
Expand Down Expand Up @@ -89,7 +97,8 @@ export function useThreadActions() {
return AsyncResult.failure(
Cause.fail(
new ThreadArchiveBlockedError({
message: "Cannot archive a running thread.",
environmentId: threadRef.environmentId,
threadId: threadRef.threadId,
}),
),
);
Expand Down
Loading