Skip to content
Closed
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
36 changes: 36 additions & 0 deletions packages/client-runtime/src/operations/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import type { WsRpcProtocolClient } from "../rpc/protocol.ts";
import { v2Now, v2Projection, v2ThreadId } from "../state/orchestrationV2TestFixtures.ts";
import {
archiveThread,
editQueuedRun,
interruptThreadTurn,
revertThreadCheckpoint,
resumeThreadQueue,
Expand Down Expand Up @@ -153,6 +154,41 @@ describe("V2 environment commands", () => {
}).pipe(Effect.provide(layerTestRandom)),
);

it.effect("clears queued message context when an edit removes every context item", () =>
Effect.gen(function* () {
const commands: OrchestrationV2Command[] = [];
const supervisor = yield* makeSupervisor({ commands, projects: [] });
const threadId = ThreadId.make("thread-1");
const runId = RunId.make("run-1");
yield* editQueuedRun({
commandId: CommandId.make("edit-cleared"),
threadId,
runId,
text: "edited",
edit: { messageId: MessageId.make("message-1"), attachments: [] },
}).pipe(Effect.provideService(EnvironmentSupervisor.EnvironmentSupervisor, supervisor));
yield* editQueuedRun({
commandId: CommandId.make("edit-text"),
threadId,
runId,
text: "text only",
}).pipe(Effect.provideService(EnvironmentSupervisor.EnvironmentSupervisor, supervisor));

expect(commands).toEqual([
{
type: "queued-run.edit",
commandId: "edit-cleared",
threadId,
runId,
text: "edited",
attachments: [],
context: { version: 1, records: [] },
},
{ type: "queued-run.edit", commandId: "edit-text", threadId, runId, text: "text only" },
]);
}).pipe(Effect.provide(layerTestRandom)),
);

it.effect("preserves caller command ids for idempotent V2 commands", () =>
Effect.gen(function* () {
const commands: OrchestrationV2Command[] = [];
Expand Down
12 changes: 6 additions & 6 deletions packages/client-runtime/src/operations/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1085,16 +1085,16 @@ export const editQueuedRun = Effect.fn("EnvironmentCommands.editQueuedRun")(func
threadId: input.threadId,
runId: input.runId,
text: input.text,
...(attachments === undefined ? {} : { attachments }),
...(input.edit?.context && attachments
? {
...(input.edit === undefined || attachments === undefined
? {}
: {
attachments,
context: remapComposerContextAttachments(
input.edit.context,
input.edit.attachments,
attachments,
),
}
: {}),
) ?? { version: 1, records: [] },
}),
});
});

Expand Down
Loading