Open History to see the last commit
1import type { ThreadId } from "@t3tools/contracts";
2import * as Effect from "effect/Effect";
3import * as Option from "effect/Option";
4
5import type { RemoteEnvironmentAuthorization } from "../authorization/service.ts";
6import type { PreparedConnection } from "../connection/model.ts";
7import * as ManagedRelay from "../relay/managedRelay.ts";
8import {
9 executeAuthenticatedEnvironmentHttpRequest,
10 withOrchestrationProtocolHeader,
11} from "./environmentHttpAuth.ts";
12
13const DEFAULT_THREAD_HISTORY_TIMEOUT_MS = 6_000;
14
15export const fetchEnvironmentThreadHistoryPage = Effect.fn(
16 "clientRuntime.state.fetchEnvironmentThreadHistoryPage",
17)(function* (input: {
18 readonly prepared: PreparedConnection;
19 readonly threadId: ThreadId;
20 readonly cursor: string;
21 readonly throughEntryId?: string | undefined;
22 readonly view?: "work" | undefined;
23 readonly detach?: boolean | undefined;
24 readonly signer: Option.Option<ManagedRelay.ManagedRelayDpopSigner["Service"]>;
25 readonly remoteAuthorization?: Option.Option<RemoteEnvironmentAuthorization["Service"]>;
26 readonly timeoutMs?: number;
27}) {
28 const endpoint = {
29 params: { threadId: input.threadId },
30 query: {
31 cursor: input.cursor,
32 compactIds: "1",
33 ...(input.view === undefined ? { deferWork: "1" } : {}),
34 ...(input.detach === true ? { detach: "1" } : {}),
35 ...(input.view === undefined ? {} : { view: input.view }),
36 ...(input.throughEntryId === undefined ? {} : { throughEntryId: input.throughEntryId }),
37 },
38 };
39 return yield* executeAuthenticatedEnvironmentHttpRequest({
40 ...input,
41 group: "orchestration",
42 method: "GET",
43 url: (urls) => urls.threadHistoryPage(endpoint),
44 timeoutMs: input.timeoutMs ?? DEFAULT_THREAD_HISTORY_TIMEOUT_MS,
45 request: ({ client, headers }) =>
46 client.threadHistoryPage({ ...endpoint, headers: withOrchestrationProtocolHeader(headers) }),
47 });
48});