Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 59 additions & 1 deletion apps/server/src/mcp/OrchestratorMcpService.activity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { OrchestratorDispatchError } from "../orchestration-v2/Orchestrator.ts";
import * as ThreadManagementService from "../orchestration-v2/ThreadManagementService.ts";
import type * as McpInvocationContext from "./McpInvocationContext.ts";
import * as OrchestratorMcpService from "./OrchestratorMcpService.ts";
import { liveThreadShell } from "./McpToolAccess.testkit.ts";
import { idleThreadProjection, liveThreadShell } from "./McpToolAccess.testkit.ts";

const layerOrchestratorService = OrchestratorMcpService.layer.pipe(
Layer.provide(Layer.mock(ThreadLaunchService.ThreadLaunchService)({})),
Expand Down Expand Up @@ -686,3 +686,61 @@ it("sendToThread reports why the orchestrator refused the message", async () =>
);
}).pipe(Effect.provide(layer), Effect.runPromise);
});

it("readThread exposes the stored sender thread only for thread-sent messages", async () => {
const shell = liveThreadShell(parentThreadId);
const messages = [
{ id: "message-from-child", text: "Child reporting in", senderThreadId: childThreadId },
{ id: "message-from-user", text: "Thanks" },
];
const projection = {
...idleThreadProjection(shell),
messages,
visibleTurnItems: messages.map((message, position) => ({
position,
visibility: "local",
sourceThreadId: parentThreadId,
sourceItemId: `item-${message.id}`,
item: {
id: `item-${message.id}`,
type: "user_message",
messageId: message.id,
runId: activeRunId,
status: "completed",
title: null,
text: message.text,
updatedAt: now,
},
})),
} as unknown as OrchestrationV2ThreadProjection;
const layer = layerOrchestratorService.pipe(
Layer.provide(
Layer.mergeAll(
Layer.mock(ThreadManagementService.ThreadManagementService)({
getThreadShell: () => Effect.succeed(shell),
getThreadRecords: () => Effect.succeed(projection),
getProjectThreadRecords: () => Effect.succeed(projection),
getTimelinePage: () =>
Effect.succeed({ items: projection.visibleTurnItems, totalItems: 2, hasMore: false }),
}),
ServerSettings.layerTest(),
Layer.mock(ProviderRegistry.ProviderRegistry)({ getProviders: Effect.succeed([]) }),
Layer.mock(ProjectService.ProjectService)({}),
Layer.mock(SecretRequests.SecretRequests)({}),
Layer.mock(ScheduledTaskService.ScheduledTaskService)({}),
Layer.mock(ProviderAdapterRegistry.ProviderAdapterRegistryV2)({}),
NodeCrypto.layer,
),
),
);

await Effect.gen(function* () {
const service = yield* OrchestratorMcpService.OrchestratorMcpService;
const result = yield* service.readThread(makeScope(), { threadId: parentThreadId });
expect(result.items).toMatchObject([
{ messageId: "message-from-child", senderThreadId: childThreadId },
{ messageId: "message-from-user" },
]);
expect(result.items[1]).not.toHaveProperty("senderThreadId");
}).pipe(Effect.provide(layer), Effect.runPromise);
});
1 change: 1 addition & 0 deletions apps/server/src/mcp/OrchestratorMcpService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,7 @@ function timelineItem(input: {
messageId,
createdBy: message?.createdBy ?? null,
creationSource: message?.creationSource ?? null,
...(message?.senderThreadId === undefined ? {} : { senderThreadId: message.senderThreadId }),
type: input.row.item.type,
status: input.row.item.status,
title: input.row.item.title,
Expand Down
1 change: 1 addition & 0 deletions packages/contracts/src/orchestratorMcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ export const OrchestratorMcpThreadTimelineItem = Schema.Struct({
messageId: Schema.NullOr(MessageId),
createdBy: Schema.NullOr(OrchestrationV2Actor),
creationSource: Schema.NullOr(OrchestrationV2CreationSource),
senderThreadId: Schema.optional(ThreadId),
type: Schema.String,
status: OrchestrationV2TurnItemStatus,
title: Schema.NullOr(Schema.String),
Expand Down
Loading