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