| 1 | import type { ThreadId } from "@t3tools/contracts"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import type * as Option from "effect/Option"; |
| 4 | |
| 5 | import type { RemoteEnvironmentAuthorization } from "../authorization/service.ts"; |
| 6 | import type { PreparedConnection } from "../connection/model.ts"; |
| 7 | import type { ManagedRelayDpopSigner } from "../relay/managedRelay.ts"; |
| 8 | import { |
| 9 | executeAuthenticatedEnvironmentHttpRequest, |
| 10 | withOrchestrationProtocolHeader, |
| 11 | } from "./environmentHttpAuth.ts"; |
| 12 | |
| 13 | export const fetchEnvironmentThreadTranscript = Effect.fn( |
| 14 | "clientRuntime.state.fetchEnvironmentThreadTranscript", |
| 15 | )(function* (input: { |
| 16 | readonly prepared: PreparedConnection; |
| 17 | readonly threadId: ThreadId; |
| 18 | readonly signer: Option.Option<ManagedRelayDpopSigner["Service"]>; |
| 19 | readonly remoteAuthorization?: Option.Option<RemoteEnvironmentAuthorization["Service"]>; |
| 20 | }) { |
| 21 | return yield* executeAuthenticatedEnvironmentHttpRequest({ |
| 22 | ...input, |
| 23 | group: "orchestration", |
| 24 | method: "GET", |
| 25 | url: (urls) => urls.threadTranscript({ params: { threadId: input.threadId } }), |
| 26 | timeoutMs: 60_000, |
| 27 | request: ({ client, headers }) => |
| 28 | client.threadTranscript({ |
| 29 | params: { threadId: input.threadId }, |
| 30 | headers: withOrchestrationProtocolHeader(headers), |
| 31 | }), |
| 32 | }); |
| 33 | }); |