| ... | @@ -4,6 +4,7 @@ import { useAtomValue } from "@effect/atom-react"; | ... | @@ -4,6 +4,7 @@ import { useAtomValue } from "@effect/atom-react"; |
| 4 | import { parseScopedThreadKey, scopedThreadKey } from "@t3tools/client-runtime/environment"; | 4 | import { parseScopedThreadKey, scopedThreadKey } from "@t3tools/client-runtime/environment"; |
| 5 | import { runAtomCommand } from "@t3tools/client-runtime/state/runtime"; | 5 | import { runAtomCommand } from "@t3tools/client-runtime/state/runtime"; |
| 6 | import type { ScopedThreadRef } from "@t3tools/contracts"; | 6 | import type { ScopedThreadRef } from "@t3tools/contracts"; |
| | 7 | import * as Schema from "effect/Schema"; |
| 7 | import { AsyncResult, Atom } from "effect/unstable/reactivity"; | 8 | import { AsyncResult, Atom } from "effect/unstable/reactivity"; |
| 8 | | 9 | |
| 9 | import { | 10 | import { |
| ... | @@ -13,10 +14,19 @@ import { | ... | @@ -13,10 +14,19 @@ import { |
| 13 | } from "~/previewStateStore"; | 14 | } from "~/previewStateStore"; |
| 14 | import { previewEnvironment } from "~/state/preview"; | 15 | import { previewEnvironment } from "~/state/preview"; |
| 15 | | 16 | |
| | 17 | class PreviewSessionThreadKeyParseError extends Schema.TaggedErrorClass<PreviewSessionThreadKeyParseError>()( |
| | 18 | "PreviewSessionThreadKeyParseError", |
| | 19 | { threadKey: Schema.String }, |
| | 20 | ) { |
| | 21 | override get message(): string { |
| | 22 | return `Invalid scoped preview thread key: ${this.threadKey}`; |
| | 23 | } |
| | 24 | } |
| | 25 | |
| 16 | const previewSessionSyncAtom = Atom.family((threadKey: string) => { | 26 | const previewSessionSyncAtom = Atom.family((threadKey: string) => { |
| 17 | const threadRef = parseScopedThreadKey(threadKey); | 27 | const threadRef = parseScopedThreadKey(threadKey); |
| 18 | if (!threadRef) { | 28 | if (threadRef === null) { |
| 19 | throw new Error(`Invalid scoped preview thread key: ${threadKey}`); | 29 | throw new PreviewSessionThreadKeyParseError({ threadKey }); |
| 20 | } | 30 | } |
| 21 | | 31 | |
| 22 | const sessionsAtom = previewEnvironment.list({ | 32 | const sessionsAtom = previewEnvironment.list({ |