Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

orchestration.ts

31 lines1.1 KB

1import {
2 OrchestrationDispatchCommandError,
3 OrchestrationV2DispatchCommandError,
4} from "@t3tools/contracts";
5import * as Schema from "effect/Schema";
6​
7const isOrchestrationDispatchCommandError = Schema.is(OrchestrationDispatchCommandError);
8const isOrchestrationV2DispatchCommandError = Schema.is(OrchestrationV2DispatchCommandError);
9​
10/**
11 * A conditional discard kept the thread: a message landed first, or it was
12 * promoted out of being a side chat. Expected, not a failure.
13 */
14export function wasDiscardRefused(error: unknown): boolean {
15 return (
16 isOrchestrationV2DispatchCommandError(error) &&
17 (error.reason === "thread_not_empty" || error.reason === "thread_not_side_chat")
18 );
20​
21export function wasBootstrapThreadDeleted(error: unknown): boolean {
22 return (
23 isOrchestrationDispatchCommandError(error) && error.bootstrapThreadDisposition === "deleted"
24 );
26​
27export function wasBootstrapThreadNotCreated(error: unknown): boolean {
28 return (
29 isOrchestrationDispatchCommandError(error) && error.bootstrapThreadDisposition === "not-created"
30 );