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?: "conversation" | "activity" | "work" | undefined;
23 readonly signer: Option.Option<ManagedRelay.ManagedRelayDpopSigner["Service"]>;
24 readonly remoteAuthorization?: Option.Option<RemoteEnvironmentAuthorization["Service"]>;
25 readonly timeoutMs?: number;
26}) {
27 const endpoint = {
28 params: { threadId: input.threadId },
29 query: {
30 cursor: input.cursor,
31 compactIds: "1",
32 ...(input.throughEntryId === undefined ? { deferWork: "1" } : {}),
33 ...(input.view === undefined ? {} : { view: input.view }),
34 ...(input.throughEntryId === undefined ? {} : { throughEntryId: input.throughEntryId }),
35 },
36 };
37 return yield* executeAuthenticatedEnvironmentHttpRequest({
38 ...input,
39 group: "orchestration",
40 method: "GET",
41 url: (urls) => urls.threadHistoryPage(endpoint),
42 timeoutMs: input.timeoutMs ?? DEFAULT_THREAD_HISTORY_TIMEOUT_MS,
43 request: ({ client, headers }) =>
44 client.threadHistoryPage({ ...endpoint, headers: withOrchestrationProtocolHeader(headers) }),
45 });
46});