fix(composer): read dropped threads across environments (#15210)
This commit is contained in:
1 parent
ec1313c8f8
commit
55dfc5fc4d
21 files changed
+1164
-108
No files matched your search
@@ -9,6 +9,7 @@ import {
|
||||
type OrchestrationV2ShellSnapshot,
|
||||
OrchestrationV2ThreadDetailSnapshot,
|
||||
OrchestrationV2ThreadBoundedSnapshot,
|
||||
OrchestrationV2ThreadTranscript,
|
||||
type OrchestrationV2ThreadHistoryPage,
|
||||
} from "@t3tools/contracts";
|
||||
import { RelayClientTracer } from "@t3tools/shared/relayTracing";
|
||||
@@ -37,6 +38,7 @@ import { withOrchestrationProtocolHeader } from "./environmentHttpAuth.ts";
|
||||
import { fetchEnvironmentSessionState } from "./session.ts";
|
||||
import { fetchEnvironmentShellSnapshot } from "./shellSnapshotHttp.ts";
|
||||
import * as ThreadSnapshotLoader from "./threadSnapshotHttp.ts";
|
||||
import { fetchEnvironmentThreadTranscript } from "./threadTranscriptHttp.ts";
|
||||
import { fetchEnvironmentBoundedThreadSnapshot } from "./boundedThreadSnapshotHttp.ts";
|
||||
import * as BoundedThreadSnapshotHttp from "./boundedThreadSnapshotHttp.ts";
|
||||
import { fetchEnvironmentThreadHistoryPage } from "./threadHistoryHttp.ts";
|
||||
@@ -44,6 +46,7 @@ import { v2Projection } from "./orchestrationV2TestFixtures.ts";
|
||||
|
||||
const encodeThreadSnapshot = Schema.encodeSync(OrchestrationV2ThreadDetailSnapshot);
|
||||
const encodeBoundedSnapshot = Schema.encodeSync(OrchestrationV2ThreadBoundedSnapshot);
|
||||
const encodeThreadTranscript = Schema.encodeSync(OrchestrationV2ThreadTranscript);
|
||||
|
||||
const TARGET = new RelayConnectionTarget({
|
||||
environmentId: EnvironmentId.make("environment-1"),
|
||||
@@ -89,6 +92,12 @@ const THREAD = {
|
||||
snapshotSequence: 2,
|
||||
projection: v2Projection,
|
||||
} satisfies OrchestrationV2ThreadDetailSnapshot;
|
||||
const TRANSCRIPT = {
|
||||
threadId: v2Projection.thread.id,
|
||||
title: v2Projection.thread.title,
|
||||
updatedAt: v2Projection.updatedAt,
|
||||
items: v2Projection.visibleTurnItems,
|
||||
} satisfies OrchestrationV2ThreadTranscript;
|
||||
const BOUNDED_THREAD = {
|
||||
...THREAD,
|
||||
historyCursor: "older-page",
|
||||
@@ -223,6 +232,15 @@ const LOADERS: ReadonlyArray<{
|
||||
threadId: THREAD.projection.thread.id,
|
||||
}),
|
||||
},
|
||||
{
|
||||
name: "thread transcript",
|
||||
method: "GET",
|
||||
path: `/api/orchestration/threads/${TRANSCRIPT.threadId}/transcript`,
|
||||
response: encodeThreadTranscript(TRANSCRIPT),
|
||||
expected: TRANSCRIPT,
|
||||
load: (input: HttpInput) =>
|
||||
fetchEnvironmentThreadTranscript({ ...input, threadId: TRANSCRIPT.threadId }),
|
||||
},
|
||||
{
|
||||
name: "bounded thread snapshot",
|
||||
method: "GET",
|
||||
@@ -312,6 +330,12 @@ describe("authenticated environment HTTP requests", () => {
|
||||
const MCP_THREAD_LOADERS: ReadonlyArray<
|
||||
Pick<(typeof LOADERS)[number], "name" | "response" | "load">
|
||||
> = [
|
||||
{
|
||||
name: "thread transcript",
|
||||
response: encodeThreadTranscript(TRANSCRIPT),
|
||||
load: (input: HttpInput) =>
|
||||
fetchEnvironmentThreadTranscript({ ...input, threadId: MCP_THREAD_ID }),
|
||||
},
|
||||
{
|
||||
name: "thread snapshot",
|
||||
response: encodeThreadSnapshot(THREAD),
|
||||
|
||||
@@ -1,17 +1,49 @@
|
||||
import { ORCHESTRATION_V2_WS_METHODS } from "@t3tools/contracts";
|
||||
import { ORCHESTRATION_V2_WS_METHODS, type ThreadId } from "@t3tools/contracts";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Option from "effect/Option";
|
||||
import * as SubscriptionRef from "effect/SubscriptionRef";
|
||||
import type { HttpClient } from "effect/http";
|
||||
import { Atom } from "effect/reactivity";
|
||||
|
||||
import {
|
||||
createEnvironmentRpcCommand,
|
||||
createEnvironmentRpcQueryAtomFamily,
|
||||
createEnvironmentRpcSubscriptionAtomFamily,
|
||||
createEnvironmentCommand,
|
||||
} from "./runtime.ts";
|
||||
import type { EnvironmentRegistry } from "../connection/registry.ts";
|
||||
import * as EnvironmentSupervisor from "../connection/supervisor.ts";
|
||||
import * as RemoteEnvironmentAuthorization from "../authorization/service.ts";
|
||||
import * as ManagedRelayDpopSigner from "../relay/managedRelay.ts";
|
||||
import { EnvironmentRpcUnavailableError } from "../rpc/client.ts";
|
||||
import { fetchEnvironmentThreadTranscript } from "./threadTranscriptHttp.ts";
|
||||
|
||||
export function createOrchestrationEnvironmentAtoms<R, E>(
|
||||
runtime: Atom.AtomRuntime<EnvironmentRegistry | R, E>,
|
||||
runtime: Atom.AtomRuntime<EnvironmentRegistry | HttpClient.HttpClient | R, E>,
|
||||
) {
|
||||
return {
|
||||
threadTranscript: createEnvironmentCommand(runtime, {
|
||||
label: "environment-data:orchestration:thread-transcript",
|
||||
execute: (input: { readonly threadId: ThreadId }) =>
|
||||
Effect.gen(function* () {
|
||||
const supervisor = yield* EnvironmentSupervisor.EnvironmentSupervisor;
|
||||
const prepared = yield* SubscriptionRef.get(supervisor.prepared);
|
||||
if (Option.isNone(prepared)) {
|
||||
return yield* new EnvironmentRpcUnavailableError({
|
||||
environmentId: supervisor.target.environmentId,
|
||||
message: "The source environment is not connected.",
|
||||
});
|
||||
}
|
||||
return yield* fetchEnvironmentThreadTranscript({
|
||||
prepared: prepared.value,
|
||||
threadId: input.threadId,
|
||||
signer: yield* Effect.serviceOption(ManagedRelayDpopSigner.ManagedRelayDpopSigner),
|
||||
remoteAuthorization: yield* Effect.serviceOption(
|
||||
RemoteEnvironmentAuthorization.RemoteEnvironmentAuthorization,
|
||||
),
|
||||
});
|
||||
}),
|
||||
}),
|
||||
v2: {
|
||||
dispatchCommand: createEnvironmentRpcCommand(runtime, {
|
||||
label: "environment-data:orchestration-v2:dispatch-command",
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import type { ThreadId } from "@t3tools/contracts";
|
||||
import * as Effect from "effect/Effect";
|
||||
import type * as Option from "effect/Option";
|
||||
|
||||
import type { RemoteEnvironmentAuthorization } from "../authorization/service.ts";
|
||||
import type { PreparedConnection } from "../connection/model.ts";
|
||||
import type { ManagedRelayDpopSigner } from "../relay/managedRelay.ts";
|
||||
import {
|
||||
executeAuthenticatedEnvironmentHttpRequest,
|
||||
withOrchestrationProtocolHeader,
|
||||
} from "./environmentHttpAuth.ts";
|
||||
|
||||
export const fetchEnvironmentThreadTranscript = Effect.fn(
|
||||
"clientRuntime.state.fetchEnvironmentThreadTranscript",
|
||||
)(function* (input: {
|
||||
readonly prepared: PreparedConnection;
|
||||
readonly threadId: ThreadId;
|
||||
readonly signer: Option.Option<ManagedRelayDpopSigner["Service"]>;
|
||||
readonly remoteAuthorization?: Option.Option<RemoteEnvironmentAuthorization["Service"]>;
|
||||
}) {
|
||||
return yield* executeAuthenticatedEnvironmentHttpRequest({
|
||||
...input,
|
||||
group: "orchestration",
|
||||
method: "GET",
|
||||
url: (urls) => urls.threadTranscript({ params: { threadId: input.threadId } }),
|
||||
timeoutMs: 60_000,
|
||||
request: ({ client, headers }) =>
|
||||
client.threadTranscript({
|
||||
params: { threadId: input.threadId },
|
||||
headers: withOrchestrationProtocolHeader(headers),
|
||||
}),
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user