- Add paginated thread history with bounded snapshots and replay limits - Trim oversized wire payloads and support progressive mobile history loading
Showing the changes to packages/client-runtime/src/state/threadHistoryHttp.ts (1 of 43 files). Show all
Unified · Split
| @@ -0,0 +1,45 @@ | ||
| 1 | +import type { ThreadId } from "@t3tools/contracts"; | |
| 2 | +import * as Effect from "effect/Effect"; | |
| 3 | +import * as Option from "effect/Option"; | |
| 4 | + | |
| 5 | +import type { PreparedConnection } from "../connection/model.ts"; | |
| 6 | +import { environmentEndpointUrl } from "../environment/endpoint.ts"; | |
| 7 | +import { ManagedRelayDpopSigner } from "../relay/managedRelay.ts"; | |
| 8 | +import { executeEnvironmentHttpRequest, makeEnvironmentHttpApiClient } from "../rpc/http.ts"; | |
| 9 | +import { buildEnvironmentAuthHeaders, withEnvironmentCredentials } from "./environmentHttpAuth.ts"; | |
| 10 | + | |
| 11 | +const DEFAULT_THREAD_HISTORY_TIMEOUT_MS = 6_000; | |
| 12 | + | |
| 13 | +export const fetchEnvironmentThreadHistoryPage = Effect.fn( | |
| 14 | + "clientRuntime.state.fetchEnvironmentThreadHistoryPage", | |
| 15 | +)(function* (input: { | |
| 16 | + readonly prepared: PreparedConnection; | |
| 17 | + readonly threadId: ThreadId; | |
| 18 | + readonly cursor: string; | |
| 19 | + readonly signer: Option.Option<ManagedRelayDpopSigner["Service"]>; | |
| 20 | + readonly timeoutMs?: number; | |
| 21 | +}) { | |
| 22 | + const requestUrl = environmentEndpointUrl( | |
| 23 | + input.prepared.httpBaseUrl, | |
| 24 | + `/api/orchestration/threads/${input.threadId}/history`, | |
| 25 | + ); | |
| 26 | + const client = yield* makeEnvironmentHttpApiClient(input.prepared.httpBaseUrl); | |
| 27 | + const headers = yield* buildEnvironmentAuthHeaders( | |
| 28 | + input.prepared.httpAuthorization, | |
| 29 | + "GET", | |
| 30 | + requestUrl, | |
| 31 | + input.signer, | |
| 32 | + ); | |
| 33 | + return yield* executeEnvironmentHttpRequest( | |
| 34 | + requestUrl, | |
| 35 | + input.timeoutMs ?? DEFAULT_THREAD_HISTORY_TIMEOUT_MS, | |
| 36 | + withEnvironmentCredentials( | |
| 37 | + input.prepared.httpAuthorization, | |
| 38 | + client.orchestration.threadHistoryPage({ | |
| 39 | + params: { threadId: input.threadId }, | |
| 40 | + query: { cursor: input.cursor }, | |
| 41 | + headers, | |
| 42 | + }), | |
| 43 | + ), | |
| 44 | + ); | |
| 45 | +}); | |