Skip to content

Commit 075b7aa

Browse files
committed
fix(client): use contract URLs for thread transcripts
2 parents 6ad0f56 + 0e7abea commit 075b7aa

10 files changed

Lines changed: 50 additions & 59 deletions

‎packages/client-runtime/src/state/boundedThreadSnapshotHttp.ts‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { HttpClient } from "effect/http";
88

99
import * as RemoteEnvironmentAuthorization from "../authorization/service.ts";
1010
import type { PreparedConnection } from "../connection/model.ts";
11-
import { environmentEndpointUrl } from "../environment/endpoint.ts";
1211
import * as ManagedRelay from "../relay/managedRelay.ts";
1312
import {
1413
executeAuthenticatedEnvironmentHttpRequest,
@@ -35,20 +34,19 @@ export const fetchEnvironmentBoundedThreadSnapshot = Effect.fn(
3534
>;
3635
readonly timeoutMs?: number;
3736
}) {
37+
const endpoint = {
38+
params: { threadId: input.threadId },
39+
query: { compactTurnItems: "1" },
40+
};
3841
return yield* executeAuthenticatedEnvironmentHttpRequest({
3942
...input,
4043
group: "orchestration",
4144
method: "GET",
42-
url: (httpBaseUrl) =>
43-
environmentEndpointUrl(
44-
httpBaseUrl,
45-
`/api/orchestration/threads/${encodeURIComponent(input.threadId)}/bounded`,
46-
),
45+
url: (urls) => urls.threadBoundedSnapshot(endpoint),
4746
timeoutMs: input.timeoutMs ?? DEFAULT_BOUNDED_THREAD_SNAPSHOT_TIMEOUT_MS,
4847
request: ({ client, headers }) =>
4948
client.threadBoundedSnapshot({
50-
params: { threadId: input.threadId },
51-
query: { compactTurnItems: "1" },
49+
...endpoint,
5250
headers: withOrchestrationProtocolHeader(headers),
5351
}),
5452
}).pipe(

‎packages/client-runtime/src/state/deviceHubAccess.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export const resolveDeviceHubAccess = Effect.fn("clientRuntime.state.resolveDevi
4646
remoteAuthorization,
4747
group: "auth",
4848
method: "POST",
49-
url: (httpBaseUrl) => environmentEndpointUrl(httpBaseUrl, "/api/auth/websocket-ticket"),
49+
url: (urls) => urls.webSocketTicket(),
5050
timeoutMs: TICKET_TIMEOUT_MS,
5151
request: ({ client, headers }) => client.webSocketTicket({ headers }),
5252
});

‎packages/client-runtime/src/state/environmentHttpAuth.test.ts‎

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import { v2Projection } from "./orchestrationV2TestFixtures.ts";
4646

4747
const encodeThreadSnapshot = Schema.encodeSync(OrchestrationV2ThreadDetailSnapshot);
4848
const encodeBoundedSnapshot = Schema.encodeSync(OrchestrationV2ThreadBoundedSnapshot);
49+
const encodeThreadTranscript = Schema.encodeSync(OrchestrationV2ThreadTranscript);
4950

5051
const TARGET = new RelayConnectionTarget({
5152
environmentId: EnvironmentId.make("environment-1"),
@@ -235,7 +236,7 @@ const LOADERS: ReadonlyArray<{
235236
name: "thread transcript",
236237
method: "GET",
237238
path: `/api/orchestration/threads/${TRANSCRIPT.threadId}/transcript`,
238-
response: Schema.encodeSync(OrchestrationV2ThreadTranscript)(TRANSCRIPT),
239+
response: encodeThreadTranscript(TRANSCRIPT),
239240
expected: TRANSCRIPT,
240241
load: (input: HttpInput) =>
241242
fetchEnvironmentThreadTranscript({ ...input, threadId: TRANSCRIPT.threadId }),
@@ -311,12 +312,9 @@ describe("authenticated environment HTTP requests", () => {
311312
);
312313
}
313314
expect(harness.authorizations).toEqual([{ expectedEnvironmentId: TARGET.environmentId }]);
315+
// The proof signs exactly the URL sent; signers drop the query for `htu`.
314316
expect(harness.proofs).toEqual([
315-
{
316-
method: loader.method,
317-
url: `${CURRENT_ORIGIN}${loader.path}`,
318-
accessToken: "current-token",
319-
},
317+
{ method: loader.method, url: call.url, accessToken: "current-token" },
320318
]);
321319
if (loader.name === "older thread history") {
322320
expect(url.searchParams.get("cursor")).toBe("older-page");
@@ -332,6 +330,12 @@ describe("authenticated environment HTTP requests", () => {
332330
const MCP_THREAD_LOADERS: ReadonlyArray<
333331
Pick<(typeof LOADERS)[number], "name" | "response" | "load">
334332
> = [
333+
{
334+
name: "thread transcript",
335+
response: encodeThreadTranscript(TRANSCRIPT),
336+
load: (input: HttpInput) =>
337+
fetchEnvironmentThreadTranscript({ ...input, threadId: MCP_THREAD_ID }),
338+
},
335339
{
336340
name: "thread snapshot",
337341
response: encodeThreadSnapshot(THREAD),
@@ -362,10 +366,9 @@ describe("authenticated environment HTTP requests", () => {
362366
const harness = makeHarness(() => Response.json(loader.response));
363367
yield* loader.load(harness.input).pipe(Effect.provide(harness.httpLayer));
364368

365-
const sent = new URL(harness.calls[0]!.url);
366-
expect(sent.pathname).toContain("/mcp%3A3534bc83-");
367-
sent.search = "";
368-
expect(harness.proofs.map((proof) => proof.url)).toEqual([sent.toString()]);
369+
const sent = harness.calls[0]!.url;
370+
expect(new URL(sent).pathname).toContain("/mcp%3A3534bc83-");
371+
expect(harness.proofs.map((proof) => proof.url)).toEqual([sent]);
369372
}),
370373
);
371374

@@ -425,7 +428,7 @@ describe("authenticated environment HTTP requests", () => {
425428
);
426429
expect(harness.proofs[1]).toEqual({
427430
method: "GET",
428-
url: `${RENEWED_ORIGIN}${loader.path}`,
431+
url: retried.url,
429432
accessToken: "renewed-token",
430433
});
431434
if (loader.name === "older thread history") {

‎packages/client-runtime/src/state/environmentHttpAuth.ts‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type { ManagedRelayDpopSigner } from "../relay/managedRelay.ts";
1414
import {
1515
executeEnvironmentHttpRequest,
1616
makeEnvironmentHttpApiGroupClient,
17+
makeEnvironmentHttpApiUrlBuilder,
1718
RemoteEnvironmentAuthFetchError,
1819
RemoteEnvironmentAuthTimeoutError,
1920
type RemoteEnvironmentRequestError,
@@ -131,7 +132,12 @@ const executeEnvironmentRequest = Effect.fnUntraced(function* <
131132
readonly signer: Option.Option<ManagedRelayDpopSigner["Service"]>;
132133
readonly remoteAuthorization?: Option.Option<RemoteEnvironmentAuthorization["Service"]>;
133134
readonly method: HttpMethod.HttpMethod;
134-
readonly url: (httpBaseUrl: string) => string;
135+
/**
136+
* The URL to sign, from the group's contract URL builder. It encodes path
137+
* params exactly like the request client, so the DPoP proof matches the
138+
* URL actually sent.
139+
*/
140+
readonly url: (urls: ReturnType<typeof makeEnvironmentHttpApiUrlBuilder>[Group]) => string;
135141
readonly timeoutMs: number;
136142
readonly group: Group;
137143
readonly request: (input: {
@@ -146,6 +152,8 @@ const executeEnvironmentRequest = Effect.fnUntraced(function* <
146152
Effect.Services<ReturnType<typeof makeEnvironmentHttpApiGroupClient<Group>>> | R
147153
> {
148154
let httpBaseUrl = input.prepared.httpBaseUrl;
155+
const requestUrlFor = (baseUrl: string) =>
156+
input.url(makeEnvironmentHttpApiUrlBuilder(baseUrl)[input.group]);
149157
return yield* Effect.gen(function* () {
150158
let rejectedAccessToken: string | undefined;
151159
for (;;) {
@@ -179,7 +187,7 @@ const executeEnvironmentRequest = Effect.fnUntraced(function* <
179187
authorization = current.httpAuthorization;
180188
}
181189

182-
const requestUrl = input.url(httpBaseUrl);
190+
const requestUrl = requestUrlFor(httpBaseUrl);
183191
const client = yield* makeEnvironmentHttpApiGroupClient(httpBaseUrl, input.group);
184192
const headers = yield* buildEnvironmentAuthHeaders(
185193
authorization,
@@ -225,7 +233,9 @@ const executeEnvironmentRequest = Effect.fnUntraced(function* <
225233
Effect.timeoutOrElse({
226234
duration: input.timeoutMs,
227235
orElse: () =>
228-
Effect.fail(new RemoteEnvironmentAuthTimeoutError(input.url(httpBaseUrl), input.timeoutMs)),
236+
Effect.fail(
237+
new RemoteEnvironmentAuthTimeoutError(requestUrlFor(httpBaseUrl), input.timeoutMs),
238+
),
229239
}),
230240
);
231241
});

‎packages/client-runtime/src/state/pullRequestDiffHttp.ts‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ import { HttpClient } from "effect/http";
1313
import * as RemoteEnvironmentAuthorization from "../authorization/service.ts";
1414
import type { PreparedConnection } from "../connection/model.ts";
1515
import * as ManagedRelay from "../relay/managedRelay.ts";
16-
import {
17-
makeEnvironmentHttpApiUrlBuilder,
18-
type RemoteEnvironmentRequestError,
19-
} from "../rpc/http.ts";
16+
import { type RemoteEnvironmentRequestError } from "../rpc/http.ts";
2017
import { executeAuthenticatedEnvironmentHttpRequest } from "./environmentHttpAuth.ts";
2118

2219
const DEFAULT_PULL_REQUEST_DIFF_TIMEOUT_MS = 60_000;
@@ -54,7 +51,7 @@ export const fetchEnvironmentPullRequestDiff = Effect.fn(
5451
...input,
5552
group: "pullRequests",
5653
method: "POST",
57-
url: (httpBaseUrl) => makeEnvironmentHttpApiUrlBuilder(httpBaseUrl).pullRequests.diff(),
54+
url: (urls) => urls.diff(),
5855
timeoutMs: input.timeoutMs ?? DEFAULT_PULL_REQUEST_DIFF_TIMEOUT_MS,
5956
request: ({ client, headers }) => client.diff({ payload: input.diff, headers }),
6057
}).pipe(

‎packages/client-runtime/src/state/session.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import * as RemoteEnvironmentAuthorization from "../authorization/service.ts";
1111
import * as EnvironmentRegistry from "../connection/registry.ts";
1212
import type { PreparedConnection } from "../connection/model.ts";
1313
import * as EnvironmentSupervisor from "../connection/supervisor.ts";
14-
import { environmentEndpointUrl } from "../environment/endpoint.ts";
1514
import * as ManagedRelay from "../relay/managedRelay.ts";
1615
import { safeErrorLogAttributes } from "../errors/safeLog.ts";
1716
import { executeAuthenticatedEnvironmentHttpRequest } from "./environmentHttpAuth.ts";
@@ -59,7 +58,7 @@ export const fetchEnvironmentSessionState = Effect.fn(
5958
...input,
6059
group: "auth",
6160
method: "GET",
62-
url: (httpBaseUrl) => environmentEndpointUrl(httpBaseUrl, "/api/auth/session"),
61+
url: (urls) => urls.session(),
6362
timeoutMs: input.timeoutMs ?? DEFAULT_SESSION_STATE_TIMEOUT_MS,
6463
request: ({ client, headers }) => client.session({ headers }),
6564
// This endpoint returns 200 with authenticated:false for expired credentials.

‎packages/client-runtime/src/state/shellSnapshotHttp.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { HttpClient, HttpClientError, type HttpClientResponse } from "effect/htt
99

1010
import * as RemoteEnvironmentAuthorization from "../authorization/service.ts";
1111
import type { PreparedConnection } from "../connection/model.ts";
12-
import { environmentEndpointUrl } from "../environment/endpoint.ts";
1312
import * as ManagedRelay from "../relay/managedRelay.ts";
1413
import {
1514
executeAuthenticatedEnvironmentHttpRequest,
@@ -48,7 +47,7 @@ export const fetchEnvironmentShellSnapshot = Effect.fn(
4847
...input,
4948
group: "orchestration",
5049
method: "GET",
51-
url: (httpBaseUrl) => environmentEndpointUrl(httpBaseUrl, "/api/orchestration/shell"),
50+
url: (urls) => urls.shellSnapshot(),
5251
timeoutMs: input.timeoutMs ?? DEFAULT_SHELL_SNAPSHOT_TIMEOUT_MS,
5352
// The body is decoded here so each thread's pull request links can decode after its
5453
// rows. Every declared error is an `EnvironmentHttpCommonError`, so decoding one keeps

‎packages/client-runtime/src/state/threadHistoryHttp.ts‎

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import * as Option from "effect/Option";
44

55
import type { RemoteEnvironmentAuthorization } from "../authorization/service.ts";
66
import type { PreparedConnection } from "../connection/model.ts";
7-
import { environmentEndpointUrl } from "../environment/endpoint.ts";
87
import * as ManagedRelay from "../relay/managedRelay.ts";
98
import {
109
executeAuthenticatedEnvironmentHttpRequest,
@@ -25,25 +24,21 @@ export const fetchEnvironmentThreadHistoryPage = Effect.fn(
2524
readonly remoteAuthorization?: Option.Option<RemoteEnvironmentAuthorization["Service"]>;
2625
readonly timeoutMs?: number;
2726
}) {
27+
const endpoint = {
28+
params: { threadId: input.threadId },
29+
query: {
30+
cursor: input.cursor,
31+
...(input.view === undefined ? {} : { view: input.view }),
32+
...(input.throughEntryId === undefined ? {} : { throughEntryId: input.throughEntryId }),
33+
},
34+
};
2835
return yield* executeAuthenticatedEnvironmentHttpRequest({
2936
...input,
3037
group: "orchestration",
3138
method: "GET",
32-
url: (httpBaseUrl) =>
33-
environmentEndpointUrl(
34-
httpBaseUrl,
35-
`/api/orchestration/threads/${encodeURIComponent(input.threadId)}/history`,
36-
),
39+
url: (urls) => urls.threadHistoryPage(endpoint),
3740
timeoutMs: input.timeoutMs ?? DEFAULT_THREAD_HISTORY_TIMEOUT_MS,
3841
request: ({ client, headers }) =>
39-
client.threadHistoryPage({
40-
params: { threadId: input.threadId },
41-
query: {
42-
cursor: input.cursor,
43-
...(input.view === undefined ? {} : { view: input.view }),
44-
...(input.throughEntryId === undefined ? {} : { throughEntryId: input.throughEntryId }),
45-
},
46-
headers: withOrchestrationProtocolHeader(headers),
47-
}),
42+
client.threadHistoryPage({ ...endpoint, headers: withOrchestrationProtocolHeader(headers) }),
4843
});
4944
});

‎packages/client-runtime/src/state/threadSnapshotHttp.ts‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import * as Option from "effect/Option";
55

66
import * as RemoteEnvironmentAuthorization from "../authorization/service.ts";
77
import type { PreparedConnection } from "../connection/model.ts";
8-
import { environmentEndpointUrl } from "../environment/endpoint.ts";
98
import * as ManagedRelay from "../relay/managedRelay.ts";
109
import type { RemoteEnvironmentRequestError } from "../rpc/http.ts";
1110
import {
@@ -65,11 +64,7 @@ export const fetchEnvironmentThreadSnapshot = Effect.fn(
6564
...input,
6665
group: "orchestration",
6766
method: "GET",
68-
url: (httpBaseUrl) =>
69-
environmentEndpointUrl(
70-
httpBaseUrl,
71-
`/api/orchestration/threads/${encodeURIComponent(input.threadId)}`,
72-
),
67+
url: (urls) => urls.threadSnapshot({ params: { threadId: input.threadId } }),
7368
timeoutMs: input.timeoutMs ?? DEFAULT_THREAD_SNAPSHOT_TIMEOUT_MS,
7469
request: ({ client, headers }) =>
7570
client.threadSnapshot({

‎packages/client-runtime/src/state/threadTranscriptHttp.ts‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import type * as Option from "effect/Option";
44

55
import type { RemoteEnvironmentAuthorization } from "../authorization/service.ts";
66
import type { PreparedConnection } from "../connection/model.ts";
7-
import { environmentEndpointUrl } from "../environment/endpoint.ts";
87
import type { ManagedRelayDpopSigner } from "../relay/managedRelay.ts";
98
import {
109
executeAuthenticatedEnvironmentHttpRequest,
@@ -23,11 +22,7 @@ export const fetchEnvironmentThreadTranscript = Effect.fn(
2322
...input,
2423
group: "orchestration",
2524
method: "GET",
26-
url: (httpBaseUrl) =>
27-
environmentEndpointUrl(
28-
httpBaseUrl,
29-
`/api/orchestration/threads/${input.threadId}/transcript`,
30-
),
25+
url: (urls) => urls.threadTranscript({ params: { threadId: input.threadId } }),
3126
timeoutMs: 60_000,
3227
request: ({ client, headers }) =>
3328
client.threadTranscript({

0 commit comments

Comments
 (0)