+36
![github-actions[bot]](/assets/img/avatar_default.png)








Julius Marminge
maria-rcks
Bilal Bakr
shivam
Vitalii Yehorov
Jake Leventhal
Claude Opus 5
Alex Southwell
github-actions[bot]
Nicholas Wasmiller
PB
Exotic
Yash Singh
Devin
Theo Browne
Gabriel De Andrade
Dara Adedeji
scratchyone
Dominic Roy
chukfinley
Primož Ajdišek
benthecarman
NaveDanan
aaditagrawal
Aditya Garud
Nick Anisimov
MacKinley Smith
Yordis Prieto
t3-code[bot]
AKolenda
Guillermo Casanova
Otavio Salvador
Shirish Pothi
Ishaan Kothari
Bob Fowler
Anton Bezdenezhnykh
ValeraZSD
Ephraim
Ryan Ilano
Alex
maco
Cursor
Tristan Knight
PR Batch Tester
oliver
kamkm
de34391427
Co-authored-by: maria-rcks <[email protected]> Co-authored-by: Bilal Bakr <[email protected]> Co-authored-by: shivam <[email protected]> Co-authored-by: Vitalii Yehorov <[email protected]> Co-authored-by: Jake Leventhal <[email protected]> Co-authored-by: Claude Opus 5 (1M context) <[email protected]> Co-authored-by: Alex Southwell <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Nicholas Wasmiller <[email protected]> Co-authored-by: PB <[email protected]> Co-authored-by: Exotic <[email protected]> Co-authored-by: Yash Singh <[email protected]> Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Theo Browne <[email protected]> Co-authored-by: Gabriel De Andrade <[email protected]> Co-authored-by: Dara Adedeji <[email protected]> Co-authored-by: scratchyone <[email protected]> Co-authored-by: Dominic Roy <[email protected]> Co-authored-by: chukfinley <[email protected]> Co-authored-by: Primož Ajdišek <[email protected]> Co-authored-by: benthecarman <[email protected]> Co-authored-by: NaveDanan <[email protected]> Co-authored-by: aaditagrawal <[email protected]> Co-authored-by: Aditya Garud <[email protected]> Co-authored-by: Nick Anisimov <[email protected]> Co-authored-by: MacKinley Smith <[email protected]> Co-authored-by: Yordis Prieto <[email protected]> Co-authored-by: t3-code[bot] <269035359+t3-code[bot]@users.noreply.github.com> Co-authored-by: AKolenda <[email protected]> Co-authored-by: Guillermo Casanova <[email protected]> Co-authored-by: Otavio Salvador <[email protected]> Co-authored-by: Shirish Pothi <[email protected]> Co-authored-by: Ishaan Kothari <[email protected]> Co-authored-by: Bob Fowler <[email protected]> Co-authored-by: Anton Bezdenezhnykh <[email protected]> Co-authored-by: ValeraZSD <[email protected]> Co-authored-by: Ephraim <[email protected]> Co-authored-by: Ryan Ilano <[email protected]> Co-authored-by: Alex <[email protected]> Co-authored-by: maco <[email protected]> Co-authored-by: Cursor <[email protected]> Co-authored-by: Tristan Knight <[email protected]> Co-authored-by: PR Batch Tester <[email protected]> Co-authored-by: oliver <[email protected]> Co-authored-by: kamkm <[email protected]> Signed-off-by: Yordis Prieto <[email protected]>
499 lines
18 KiB
TypeScript
499 lines
18 KiB
TypeScript
import {
|
|
OrchestrationV2ContextHandoff,
|
|
type OrchestrationV2TurnItem,
|
|
type OrchestrationV2Run,
|
|
ProviderInstanceId,
|
|
ProviderThreadId,
|
|
RunId,
|
|
ThreadId,
|
|
} from "@t3tools/contracts";
|
|
import * as Context from "effect/Context";
|
|
import * as DateTime from "effect/DateTime";
|
|
import * as Effect from "effect/Effect";
|
|
import * as Layer from "effect/Layer";
|
|
import * as Schema from "effect/Schema";
|
|
|
|
import {
|
|
DEFAULT_HANDOFF_TOKEN_CAP,
|
|
handoffTokenCapConfig,
|
|
handoffCoverage,
|
|
historicalMessage,
|
|
renderHistory,
|
|
selectHistory,
|
|
} from "./ContextHandoffBudget.ts";
|
|
import * as IdAllocator from "./IdAllocator.ts";
|
|
|
|
export class ContextHandoffPrepareError extends Schema.TaggedError<ContextHandoffPrepareError>()(
|
|
"ContextHandoffPrepareError",
|
|
{
|
|
threadId: ThreadId,
|
|
targetRunId: RunId,
|
|
fromProviderThreadIds: Schema.Array(ProviderThreadId),
|
|
toProviderThreadId: ProviderThreadId,
|
|
cause: Schema.optional(Schema.Defect()),
|
|
},
|
|
) {
|
|
override get message(): string {
|
|
return `Failed to prepare context handoff for run ${this.targetRunId} in thread ${this.threadId}.`;
|
|
}
|
|
}
|
|
|
|
export const ContextHandoffServiceV2Error = Schema.Union([ContextHandoffPrepareError]);
|
|
export type ContextHandoffServiceV2Error = typeof ContextHandoffServiceV2Error.Type;
|
|
|
|
export interface ContextHandoffServiceV2Shape {
|
|
readonly prepareLegacyImport: (input: {
|
|
readonly threadId: ThreadId;
|
|
readonly targetRunId: RunId;
|
|
readonly toProviderThreadId: ProviderThreadId;
|
|
readonly toProviderInstanceId: ProviderInstanceId;
|
|
readonly items: ReadonlyArray<OrchestrationV2TurnItem>;
|
|
readonly createdAt: DateTime.Utc;
|
|
}) => Effect.Effect<OrchestrationV2ContextHandoff, ContextHandoffServiceV2Error>;
|
|
readonly prepare: (input: {
|
|
readonly threadId: ThreadId;
|
|
readonly targetRunId: RunId;
|
|
readonly fromProviderThreadIds: ReadonlyArray<ProviderThreadId>;
|
|
readonly toProviderThreadId: ProviderThreadId;
|
|
}) => Effect.Effect<OrchestrationV2ContextHandoff, ContextHandoffServiceV2Error>;
|
|
readonly prepareForkDelta: (input: {
|
|
readonly sourceThreadId: ThreadId;
|
|
readonly targetThreadId: ThreadId;
|
|
readonly targetRunId: RunId;
|
|
readonly transferId: OrchestrationV2ContextHandoff["transferId"];
|
|
readonly fromProviderThreadIds: ReadonlyArray<ProviderThreadId>;
|
|
readonly toProviderThreadId: ProviderThreadId;
|
|
readonly fromProviderInstanceId: ProviderInstanceId;
|
|
readonly toProviderInstanceId: ProviderInstanceId;
|
|
readonly coveredRunOrdinals: OrchestrationV2ContextHandoff["coveredRunOrdinals"];
|
|
readonly deltaItems: ReadonlyArray<OrchestrationV2TurnItem>;
|
|
readonly createdAt: DateTime.Utc;
|
|
}) => Effect.Effect<OrchestrationV2ContextHandoff, ContextHandoffServiceV2Error>;
|
|
readonly prepareProviderHandoff: (input: {
|
|
readonly threadId: ThreadId;
|
|
readonly targetRunId: RunId;
|
|
readonly transferId: OrchestrationV2ContextHandoff["transferId"];
|
|
readonly fromProviderThreadIds: ReadonlyArray<ProviderThreadId>;
|
|
readonly toProviderThreadId: ProviderThreadId;
|
|
readonly fromProviderInstanceId: ProviderInstanceId;
|
|
readonly toProviderInstanceId: ProviderInstanceId;
|
|
readonly coveredRunOrdinals: OrchestrationV2ContextHandoff["coveredRunOrdinals"];
|
|
readonly runs?: ReadonlyArray<OrchestrationV2Run>;
|
|
readonly strategy: Extract<
|
|
OrchestrationV2ContextHandoff["strategy"],
|
|
"delta_since_target_last_seen" | "full_thread_summary"
|
|
>;
|
|
readonly items: ReadonlyArray<OrchestrationV2TurnItem>;
|
|
readonly createdAt: DateTime.Utc;
|
|
}) => Effect.Effect<OrchestrationV2ContextHandoff, ContextHandoffServiceV2Error>;
|
|
}
|
|
|
|
export class ContextHandoffServiceV2 extends Context.Service<
|
|
ContextHandoffServiceV2,
|
|
ContextHandoffServiceV2Shape
|
|
>()("t3/orchestration-v2/ContextHandoffService/ContextHandoffServiceV2") {}
|
|
|
|
function compactText(text: string, maxLength = 240): string {
|
|
const compacted = text.replace(/\s+/g, " ").trim();
|
|
if (compacted.length <= maxLength) {
|
|
return compacted;
|
|
}
|
|
return `${compacted.slice(0, maxLength - 3)}...`;
|
|
}
|
|
|
|
function summarizeDeltaItem(item: OrchestrationV2TurnItem): string | null {
|
|
switch (item.type) {
|
|
case "user_message":
|
|
return `- User: ${compactText(item.text)}`;
|
|
case "assistant_message":
|
|
return `- Assistant: ${compactText(item.text)}`;
|
|
case "command_execution":
|
|
return `- Command: ${compactText(item.input)}`;
|
|
case "file_change":
|
|
return `- File change: ${item.fileName}`;
|
|
case "checkpoint":
|
|
return `- Checkpoint: ${item.files.length} files`;
|
|
case "handoff":
|
|
return `- Handoff: ${compactText(item.summary ?? item.strategy)}`;
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
|
|
function makeForkDeltaSummary(input: {
|
|
readonly sourceThreadId: ThreadId;
|
|
readonly targetThreadId: ThreadId;
|
|
readonly coveredRunOrdinals: OrchestrationV2ContextHandoff["coveredRunOrdinals"];
|
|
readonly deltaItems: ReadonlyArray<OrchestrationV2TurnItem>;
|
|
}): string {
|
|
const itemLines = input.deltaItems.flatMap((item) => {
|
|
const line = summarizeDeltaItem(item);
|
|
return line === null ? [] : [line];
|
|
});
|
|
return [
|
|
"Merge-back context from forked conversation.",
|
|
`Source thread: ${input.sourceThreadId}`,
|
|
`Target thread: ${input.targetThreadId}`,
|
|
`Covered fork runs: ${input.coveredRunOrdinals.from}-${input.coveredRunOrdinals.to}`,
|
|
"",
|
|
"Fork delta:",
|
|
...(itemLines.length === 0 ? ["- No user-visible delta items."] : itemLines),
|
|
].join("\n");
|
|
}
|
|
|
|
function makeLegacyImportSummary(items: ReadonlyArray<OrchestrationV2TurnItem>): string {
|
|
const sections = items.flatMap((item) => {
|
|
switch (item.type) {
|
|
case "user_message":
|
|
return [{ label: "User", body: item.text }];
|
|
case "assistant_message":
|
|
return [{ label: "Assistant", body: item.text }];
|
|
default:
|
|
return [];
|
|
}
|
|
});
|
|
const header =
|
|
"Imported conversation history from the previous T3 Code orchestrator. Use it as context; do not repeat it unless the user asks.";
|
|
const maxChars = 32_000;
|
|
const selected: Array<string> = [];
|
|
let remaining = maxChars - header.length - 2;
|
|
for (const section of sections.toReversed()) {
|
|
if (remaining <= 0) break;
|
|
const fullSection = `${section.label}:\n${section.body}`;
|
|
if (fullSection.length <= remaining) {
|
|
selected.unshift(fullSection);
|
|
remaining -= fullSection.length + 2;
|
|
continue;
|
|
}
|
|
|
|
const prefix = `${section.label}:\n... `;
|
|
const bodyBudget = remaining - prefix.length;
|
|
if (bodyBudget <= 0) continue;
|
|
|
|
const initialStart = section.body.length - bodyBudget;
|
|
let bodyStart = Math.max(0, initialStart);
|
|
if (
|
|
bodyStart > 0 &&
|
|
!/\s/.test(section.body[bodyStart - 1] ?? "") &&
|
|
!/\s/.test(section.body[bodyStart] ?? "")
|
|
) {
|
|
const nextWhitespace = section.body.slice(bodyStart).search(/\s/);
|
|
if (nextWhitespace !== -1) {
|
|
bodyStart += nextWhitespace;
|
|
}
|
|
}
|
|
const codeUnitAtStart = section.body.charCodeAt(bodyStart);
|
|
const codeUnitBeforeStart = section.body.charCodeAt(bodyStart - 1);
|
|
if (
|
|
codeUnitAtStart >= 0xdc00 &&
|
|
codeUnitAtStart <= 0xdfff &&
|
|
codeUnitBeforeStart >= 0xd800 &&
|
|
codeUnitBeforeStart <= 0xdbff
|
|
) {
|
|
bodyStart += 1;
|
|
}
|
|
const bodySuffix = section.body.slice(bodyStart).trimStart();
|
|
if (bodySuffix.length === 0) continue;
|
|
|
|
const suffix = `${prefix}${bodySuffix}`;
|
|
selected.unshift(suffix);
|
|
remaining -= suffix.length + 2;
|
|
}
|
|
return [header, ...selected].join("\n\n");
|
|
}
|
|
|
|
export function providerMessageWithContextHandoff(input: {
|
|
readonly handoff: OrchestrationV2ContextHandoff;
|
|
readonly userText: string;
|
|
}): string {
|
|
return providerMessageWithContextHandoffs({
|
|
handoffs: [input.handoff],
|
|
userText: input.userText,
|
|
});
|
|
}
|
|
|
|
function providerMessageWithContextHandoffs(input: {
|
|
readonly handoffs: ReadonlyArray<OrchestrationV2ContextHandoff>;
|
|
readonly userText: string;
|
|
}): string {
|
|
const handoffSections = input.handoffs.flatMap((handoff) => {
|
|
const label =
|
|
handoff.strategy === "fork_delta_summary"
|
|
? "merge_back / fork_delta_summary"
|
|
: handoff.strategy;
|
|
return [`Context handoff (${label}):`, handoff.summaryText, ""];
|
|
});
|
|
return [...handoffSections, "User message:", input.userText].join("\n");
|
|
}
|
|
|
|
const makeContextHandoffService = Effect.fn("orchestrationV2.ContextHandoffService.layer")(
|
|
function* () {
|
|
const idAllocator = yield* IdAllocator.IdAllocatorV2;
|
|
const tokenCap = yield* handoffTokenCapConfig.pipe(
|
|
Effect.orElseSucceed(() => DEFAULT_HANDOFF_TOKEN_CAP),
|
|
);
|
|
|
|
const prepareLegacyImport = Effect.fn("orchestrationV2.contextHandoff.prepareLegacyImport")(
|
|
function* (input: {
|
|
readonly threadId: ThreadId;
|
|
readonly targetRunId: RunId;
|
|
readonly toProviderThreadId: ProviderThreadId;
|
|
readonly toProviderInstanceId: ProviderInstanceId;
|
|
readonly items: ReadonlyArray<OrchestrationV2TurnItem>;
|
|
readonly createdAt: DateTime.Utc;
|
|
}) {
|
|
const handoffId = yield* idAllocator.allocate
|
|
.contextHandoff({
|
|
threadId: input.threadId,
|
|
fromProviderInstanceId: ProviderInstanceId.make("legacy"),
|
|
toProviderInstanceId: input.toProviderInstanceId,
|
|
})
|
|
.pipe(
|
|
Effect.mapError(
|
|
(cause) =>
|
|
new ContextHandoffPrepareError({
|
|
threadId: input.threadId,
|
|
targetRunId: input.targetRunId,
|
|
fromProviderThreadIds: [],
|
|
toProviderThreadId: input.toProviderThreadId,
|
|
cause,
|
|
}),
|
|
),
|
|
);
|
|
const coverage = handoffCoverage({ ...input, coveredRunOrdinals: { from: 1, to: 1 } });
|
|
const selected = selectHistory({
|
|
messages: input.items.flatMap((item) => {
|
|
const message = historicalMessage(item);
|
|
return message === null ? [] : [message];
|
|
}),
|
|
coverage,
|
|
budget: tokenCap,
|
|
});
|
|
return {
|
|
id: handoffId,
|
|
transferId: null,
|
|
threadId: input.threadId,
|
|
targetRunId: input.targetRunId,
|
|
fromProviderThreadIds: [],
|
|
toProviderThreadId: input.toProviderThreadId,
|
|
coveredRunOrdinals: { from: 1, to: 1 },
|
|
strategy: "manual_context",
|
|
status: "ready",
|
|
summaryMessageId: null,
|
|
summaryText: makeLegacyImportSummary(input.items),
|
|
history: {
|
|
messages: selected.messages,
|
|
coverage,
|
|
omittedItems: selected.omittedItems,
|
|
omittedItemIds: selected.omittedItemIds,
|
|
},
|
|
createdByProviderInstanceId: null,
|
|
createdAt: input.createdAt,
|
|
updatedAt: input.createdAt,
|
|
} satisfies OrchestrationV2ContextHandoff;
|
|
},
|
|
);
|
|
|
|
const prepare = Effect.fn("orchestrationV2.contextHandoff.prepare")(function* (input: {
|
|
readonly threadId: ThreadId;
|
|
readonly targetRunId: RunId;
|
|
readonly fromProviderThreadIds: ReadonlyArray<ProviderThreadId>;
|
|
readonly toProviderThreadId: ProviderThreadId;
|
|
}) {
|
|
const now = yield* DateTime.now;
|
|
const handoffId = yield* idAllocator.allocate
|
|
.contextHandoff({
|
|
threadId: input.threadId,
|
|
fromProviderInstanceId: ProviderInstanceId.make("manual"),
|
|
toProviderInstanceId: ProviderInstanceId.make("manual"),
|
|
})
|
|
.pipe(
|
|
Effect.mapError(
|
|
(cause) =>
|
|
new ContextHandoffPrepareError({
|
|
threadId: input.threadId,
|
|
targetRunId: input.targetRunId,
|
|
fromProviderThreadIds: Array.from(input.fromProviderThreadIds),
|
|
toProviderThreadId: input.toProviderThreadId,
|
|
cause,
|
|
}),
|
|
),
|
|
);
|
|
return {
|
|
id: handoffId,
|
|
transferId: null,
|
|
threadId: input.threadId,
|
|
targetRunId: input.targetRunId,
|
|
fromProviderThreadIds: Array.from(input.fromProviderThreadIds),
|
|
toProviderThreadId: input.toProviderThreadId,
|
|
coveredRunOrdinals: { from: 1, to: 1 },
|
|
strategy: "manual_context",
|
|
status: "ready",
|
|
summaryMessageId: null,
|
|
summaryText: "Manual context handoff.",
|
|
createdByProviderInstanceId: null,
|
|
createdAt: now,
|
|
updatedAt: now,
|
|
} satisfies OrchestrationV2ContextHandoff;
|
|
});
|
|
|
|
const prepareForkDelta = Effect.fn("orchestrationV2.contextHandoff.prepareForkDelta")(
|
|
function* (input: {
|
|
readonly sourceThreadId: ThreadId;
|
|
readonly targetThreadId: ThreadId;
|
|
readonly targetRunId: RunId;
|
|
readonly transferId: OrchestrationV2ContextHandoff["transferId"];
|
|
readonly fromProviderThreadIds: ReadonlyArray<ProviderThreadId>;
|
|
readonly toProviderThreadId: ProviderThreadId;
|
|
readonly fromProviderInstanceId: ProviderInstanceId;
|
|
readonly toProviderInstanceId: ProviderInstanceId;
|
|
readonly coveredRunOrdinals: OrchestrationV2ContextHandoff["coveredRunOrdinals"];
|
|
readonly deltaItems: ReadonlyArray<OrchestrationV2TurnItem>;
|
|
readonly createdAt: DateTime.Utc;
|
|
}) {
|
|
const handoffId = yield* idAllocator.allocate
|
|
.contextHandoff({
|
|
threadId: input.targetThreadId,
|
|
fromProviderInstanceId: input.fromProviderInstanceId,
|
|
toProviderInstanceId: input.toProviderInstanceId,
|
|
})
|
|
.pipe(
|
|
Effect.mapError(
|
|
(cause) =>
|
|
new ContextHandoffPrepareError({
|
|
threadId: input.targetThreadId,
|
|
targetRunId: input.targetRunId,
|
|
fromProviderThreadIds: Array.from(input.fromProviderThreadIds),
|
|
toProviderThreadId: input.toProviderThreadId,
|
|
cause,
|
|
}),
|
|
),
|
|
);
|
|
const coverage = handoffCoverage({
|
|
threadId: input.sourceThreadId,
|
|
coveredRunOrdinals: input.coveredRunOrdinals,
|
|
items: input.deltaItems,
|
|
});
|
|
const selected = selectHistory({
|
|
messages: input.deltaItems.flatMap((item) => {
|
|
const message = historicalMessage(item);
|
|
return message === null ? [] : [message];
|
|
}),
|
|
coverage,
|
|
budget: tokenCap,
|
|
});
|
|
return {
|
|
id: handoffId,
|
|
transferId: input.transferId,
|
|
threadId: input.targetThreadId,
|
|
targetRunId: input.targetRunId,
|
|
fromProviderThreadIds: Array.from(input.fromProviderThreadIds),
|
|
toProviderThreadId: input.toProviderThreadId,
|
|
coveredRunOrdinals: input.coveredRunOrdinals,
|
|
strategy: "fork_delta_summary",
|
|
status: "ready",
|
|
summaryMessageId: null,
|
|
summaryText: makeForkDeltaSummary(input),
|
|
history: {
|
|
messages: selected.messages,
|
|
coverage,
|
|
omittedItems: selected.omittedItems,
|
|
omittedItemIds: selected.omittedItemIds,
|
|
},
|
|
createdByProviderInstanceId: null,
|
|
createdAt: input.createdAt,
|
|
updatedAt: input.createdAt,
|
|
} satisfies OrchestrationV2ContextHandoff;
|
|
},
|
|
);
|
|
|
|
const prepareProviderHandoff = Effect.fn(
|
|
"orchestrationV2.contextHandoff.prepareProviderHandoff",
|
|
)(function* (input: {
|
|
readonly threadId: ThreadId;
|
|
readonly targetRunId: RunId;
|
|
readonly transferId: OrchestrationV2ContextHandoff["transferId"];
|
|
readonly fromProviderThreadIds: ReadonlyArray<ProviderThreadId>;
|
|
readonly toProviderThreadId: ProviderThreadId;
|
|
readonly fromProviderInstanceId: ProviderInstanceId;
|
|
readonly toProviderInstanceId: ProviderInstanceId;
|
|
readonly coveredRunOrdinals: OrchestrationV2ContextHandoff["coveredRunOrdinals"];
|
|
readonly runs?: ReadonlyArray<OrchestrationV2Run>;
|
|
readonly strategy: Extract<
|
|
OrchestrationV2ContextHandoff["strategy"],
|
|
"delta_since_target_last_seen" | "full_thread_summary"
|
|
>;
|
|
readonly items: ReadonlyArray<OrchestrationV2TurnItem>;
|
|
readonly createdAt: DateTime.Utc;
|
|
}) {
|
|
const handoffId = yield* idAllocator.allocate
|
|
.contextHandoff({
|
|
threadId: input.threadId,
|
|
fromProviderInstanceId: input.fromProviderInstanceId,
|
|
toProviderInstanceId: input.toProviderInstanceId,
|
|
})
|
|
.pipe(
|
|
Effect.mapError(
|
|
(cause) =>
|
|
new ContextHandoffPrepareError({
|
|
threadId: input.threadId,
|
|
targetRunId: input.targetRunId,
|
|
fromProviderThreadIds: Array.from(input.fromProviderThreadIds),
|
|
toProviderThreadId: input.toProviderThreadId,
|
|
cause,
|
|
}),
|
|
),
|
|
);
|
|
const runStatuses = new Map(input.runs?.map((run) => [run.id, run.status]));
|
|
const coverage = handoffCoverage(input);
|
|
const selected = selectHistory({
|
|
messages: input.items.flatMap((item) => {
|
|
const message = historicalMessage(item);
|
|
return message === null
|
|
? []
|
|
: [
|
|
{
|
|
...message,
|
|
...(item.runId === null ? {} : { runStatus: runStatuses.get(item.runId) }),
|
|
},
|
|
];
|
|
}),
|
|
coverage,
|
|
budget: tokenCap,
|
|
});
|
|
return {
|
|
id: handoffId,
|
|
transferId: input.transferId,
|
|
threadId: input.threadId,
|
|
targetRunId: input.targetRunId,
|
|
fromProviderThreadIds: Array.from(input.fromProviderThreadIds),
|
|
toProviderThreadId: input.toProviderThreadId,
|
|
coveredRunOrdinals: input.coveredRunOrdinals,
|
|
strategy: input.strategy,
|
|
status: "ready",
|
|
summaryMessageId: null,
|
|
summaryText: renderHistory(selected.messages, selected.context),
|
|
history: {
|
|
messages: selected.messages,
|
|
coverage,
|
|
omittedItems: selected.omittedItems,
|
|
omittedItemIds: selected.omittedItemIds,
|
|
},
|
|
createdByProviderInstanceId: null,
|
|
createdAt: input.createdAt,
|
|
updatedAt: input.createdAt,
|
|
} satisfies OrchestrationV2ContextHandoff;
|
|
});
|
|
|
|
return ContextHandoffServiceV2.of({
|
|
prepareLegacyImport,
|
|
prepare,
|
|
prepareForkDelta,
|
|
prepareProviderHandoff,
|
|
});
|
|
},
|
|
);
|
|
|
|
export const layer: Layer.Layer<ContextHandoffServiceV2, never, IdAllocator.IdAllocatorV2> =
|
|
Layer.effect(ContextHandoffServiceV2, makeContextHandoffService());
|