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

threadHistoryHttp.ts

46 lines1.8 KB

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 { environmentEndpointUrl } from "../environment/endpoint.ts";
8import * as ManagedRelay from "../relay/managedRelay.ts";
9import {
10 executeAuthenticatedEnvironmentHttpRequest,
11 withOrchestrationProtocolHeader,
12} from "./environmentHttpAuth.ts";
13​
14const DEFAULT_THREAD_HISTORY_TIMEOUT_MS = 6_000;
15​
16export const fetchEnvironmentThreadHistoryPage = Effect.fn(
17 "clientRuntime.state.fetchEnvironmentThreadHistoryPage",
18)(function* (input: {
19 readonly prepared: PreparedConnection;
20 readonly threadId: ThreadId;
21 readonly cursor: string;
22 readonly throughEntryId?: string | undefined;
23 readonly view?: "conversation" | "activity" | undefined;
24 readonly signer: Option.Option<ManagedRelay.ManagedRelayDpopSigner["Service"]>;
25 readonly remoteAuthorization?: Option.Option<RemoteEnvironmentAuthorization["Service"]>;
26 readonly timeoutMs?: number;
27}) {
28 return yield* executeAuthenticatedEnvironmentHttpRequest({
29 ...input,
30 group: "orchestration",
31 method: "GET",
32 url: (httpBaseUrl) =>
33 environmentEndpointUrl(httpBaseUrl, `/api/orchestration/threads/${input.threadId}/history`),
34 timeoutMs: input.timeoutMs ?? DEFAULT_THREAD_HISTORY_TIMEOUT_MS,
35 request: ({ client, headers }) =>
36 client.threadHistoryPage({
37 params: { threadId: input.threadId },
38 query: {
39 cursor: input.cursor,
40 ...(input.view === undefined ? {} : { view: input.view }),
41 ...(input.throughEntryId === undefined ? {} : { throughEntryId: input.throughEntryId }),
42 },
43 headers: withOrchestrationProtocolHeader(headers),
44 }),
45 });
46});