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 { environmentEndpointUrl } from "../environment/endpoint.ts";
8import { ManagedRelayDpopSigner } 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 signer: Option.Option<ManagedRelayDpopSigner["Service"]>;
23 readonly remoteAuthorization?: Option.Option<RemoteEnvironmentAuthorization["Service"]>;
24 readonly timeoutMs?: number;
25}) {
26 return yield* executeAuthenticatedEnvironmentHttpRequest({
27 ...input,
28 method: "GET",
29 url: (httpBaseUrl) =>
30 environmentEndpointUrl(httpBaseUrl, `/api/orchestration/threads/${input.threadId}/history`),
31 timeoutMs: input.timeoutMs ?? DEFAULT_THREAD_HISTORY_TIMEOUT_MS,
32 request: ({ client, headers }) =>
33 client.orchestration.threadHistoryPage({
34 params: { threadId: input.threadId },
35 query: { cursor: input.cursor },
36 headers: withOrchestrationProtocolHeader(headers),
37 }),
38 });
39});