Add merge-back context handoff support
- Map fork and merge-back turns into stored handoffs and transfer resolutions - Add shell snapshot projection support plus coverage tests - Update replay fixtures and web contracts for the new turn flow
This commit is contained in:
1 parent
74f73e39ea
commit
7cfdb4e79e
36 files changed
+2921
-301
No files matched your search
@@ -86,6 +86,7 @@ import type {
|
||||
OrchestrationV2Command,
|
||||
OrchestrationV2DispatchCommandResult,
|
||||
OrchestrationV2GetThreadProjectionInput,
|
||||
OrchestrationV2ShellStreamItem,
|
||||
OrchestrationV2ThreadProjection,
|
||||
OrchestrationV2ThreadStreamItem,
|
||||
} from "./orchestrationV2.ts";
|
||||
@@ -1189,6 +1190,7 @@ export interface EnvironmentApi {
|
||||
callback: (status: VcsStatusResult) => void,
|
||||
options?: {
|
||||
onResubscribe?: () => void;
|
||||
onError?: (message: string) => void;
|
||||
},
|
||||
) => () => void;
|
||||
};
|
||||
@@ -1212,6 +1214,7 @@ export interface EnvironmentApi {
|
||||
callback: (event: OrchestrationShellStreamItem) => void,
|
||||
options?: {
|
||||
onResubscribe?: () => void;
|
||||
onError?: (message: string) => void;
|
||||
},
|
||||
) => () => void;
|
||||
subscribeThread: (
|
||||
@@ -1219,6 +1222,7 @@ export interface EnvironmentApi {
|
||||
callback: (event: OrchestrationThreadStreamItem) => void,
|
||||
options?: {
|
||||
onResubscribe?: () => void;
|
||||
onError?: (message: string) => void;
|
||||
},
|
||||
) => () => void;
|
||||
};
|
||||
@@ -1229,11 +1233,19 @@ export interface EnvironmentApi {
|
||||
getThreadProjection: (
|
||||
input: OrchestrationV2GetThreadProjectionInput,
|
||||
) => Promise<OrchestrationV2ThreadProjection>;
|
||||
subscribeShell: (
|
||||
callback: (event: OrchestrationV2ShellStreamItem) => void,
|
||||
options?: {
|
||||
onResubscribe?: () => void;
|
||||
onError?: (message: string) => void;
|
||||
},
|
||||
) => () => void;
|
||||
subscribeThread: (
|
||||
input: OrchestrationV2GetThreadProjectionInput,
|
||||
callback: (event: OrchestrationV2ThreadStreamItem) => void,
|
||||
options?: {
|
||||
onResubscribe?: () => void;
|
||||
onError?: (message: string) => void;
|
||||
},
|
||||
) => () => void;
|
||||
};
|
||||
|
||||
@@ -94,6 +94,10 @@ export const OrchestrationV2ContextTransferResolution = Schema.Union([
|
||||
strategy: Schema.Literal("delta_context"),
|
||||
contextHandoffId: ContextHandoffId,
|
||||
}),
|
||||
Schema.Struct({
|
||||
strategy: Schema.Literal("fork_delta_context"),
|
||||
contextHandoffId: ContextHandoffId,
|
||||
}),
|
||||
Schema.Struct({
|
||||
strategy: Schema.Literal("checkpoint_context"),
|
||||
contextHandoffId: ContextHandoffId,
|
||||
@@ -450,6 +454,7 @@ export const OrchestrationV2ContextHandoff = Schema.Struct({
|
||||
}),
|
||||
strategy: Schema.Literals([
|
||||
"delta_since_target_last_seen",
|
||||
"fork_delta_summary",
|
||||
"full_thread_summary",
|
||||
"checkpoint_summary",
|
||||
"manual_context",
|
||||
@@ -594,6 +599,15 @@ export const OrchestrationV2TurnItemStatus = Schema.Literals([
|
||||
]);
|
||||
export type OrchestrationV2TurnItemStatus = typeof OrchestrationV2TurnItemStatus.Type;
|
||||
|
||||
export const OrchestrationV2UserMessageInputIntent = Schema.Literals([
|
||||
"turn_start",
|
||||
"queued_turn",
|
||||
"steer",
|
||||
"promoted_queued_to_steer",
|
||||
]);
|
||||
export type OrchestrationV2UserMessageInputIntent =
|
||||
typeof OrchestrationV2UserMessageInputIntent.Type;
|
||||
|
||||
const OrchestrationV2TurnItemBaseFields = {
|
||||
id: TurnItemId,
|
||||
threadId: ThreadId,
|
||||
@@ -631,6 +645,7 @@ export const OrchestrationV2TurnItem = Schema.Union([
|
||||
...OrchestrationV2TurnItemBaseFields,
|
||||
type: Schema.Literal("user_message"),
|
||||
messageId: MessageId,
|
||||
inputIntent: OrchestrationV2UserMessageInputIntent,
|
||||
text: Schema.String,
|
||||
attachments: Schema.Array(ChatAttachment),
|
||||
}),
|
||||
@@ -738,6 +753,7 @@ export const OrchestrationV2TurnItem = Schema.Union([
|
||||
toProvider: ProviderKind,
|
||||
strategy: Schema.Literals([
|
||||
"delta_since_target_last_seen",
|
||||
"fork_delta_summary",
|
||||
"full_thread_summary",
|
||||
"checkpoint_summary",
|
||||
"manual_context",
|
||||
@@ -769,6 +785,15 @@ export const OrchestrationV2TurnItem = Schema.Union([
|
||||
]);
|
||||
export type OrchestrationV2TurnItem = typeof OrchestrationV2TurnItem.Type;
|
||||
|
||||
export const OrchestrationV2ProjectedTurnItem = Schema.Struct({
|
||||
position: NonNegativeInt,
|
||||
visibility: Schema.Literals(["local", "inherited", "synthetic"]),
|
||||
sourceThreadId: ThreadId,
|
||||
sourceItemId: TurnItemId,
|
||||
item: OrchestrationV2TurnItem,
|
||||
});
|
||||
export type OrchestrationV2ProjectedTurnItem = typeof OrchestrationV2ProjectedTurnItem.Type;
|
||||
|
||||
export const OrchestrationV2RawProviderEvent = Schema.Struct({
|
||||
id: RawEventId,
|
||||
provider: ProviderKind,
|
||||
@@ -903,10 +928,54 @@ export const OrchestrationV2ThreadProjection = Schema.Struct({
|
||||
checkpoints: Schema.Array(OrchestrationV2Checkpoint),
|
||||
contextHandoffs: Schema.Array(OrchestrationV2ContextHandoff),
|
||||
contextTransfers: Schema.Array(OrchestrationV2ContextTransfer),
|
||||
visibleTurnItems: Schema.Array(OrchestrationV2ProjectedTurnItem),
|
||||
updatedAt: Schema.DateTimeUtc,
|
||||
});
|
||||
export type OrchestrationV2ThreadProjection = typeof OrchestrationV2ThreadProjection.Type;
|
||||
|
||||
export const OrchestrationV2ShellThreadStatus = Schema.Union([
|
||||
Schema.Literal("idle"),
|
||||
OrchestrationV2RunStatus,
|
||||
]);
|
||||
export type OrchestrationV2ShellThreadStatus = typeof OrchestrationV2ShellThreadStatus.Type;
|
||||
|
||||
export const OrchestrationV2ThreadShell = Schema.Struct({
|
||||
id: ThreadId,
|
||||
projectId: ProjectId,
|
||||
title: Schema.String,
|
||||
defaultProvider: ProviderKind,
|
||||
modelSelection: ModelSelection,
|
||||
runtimeMode: RuntimeMode,
|
||||
interactionMode: ProviderInteractionMode,
|
||||
lineage: OrchestrationV2AppThreadLineage,
|
||||
forkedFrom: Schema.NullOr(OrchestrationV2AppThread.fields.forkedFrom),
|
||||
activeProviderThreadId: Schema.NullOr(ProviderThreadId),
|
||||
latestRunId: Schema.NullOr(RunId),
|
||||
status: OrchestrationV2ShellThreadStatus,
|
||||
itemCount: NonNegativeInt,
|
||||
visibleItemCount: NonNegativeInt,
|
||||
createdAt: Schema.DateTimeUtc,
|
||||
updatedAt: Schema.DateTimeUtc,
|
||||
});
|
||||
export type OrchestrationV2ThreadShell = typeof OrchestrationV2ThreadShell.Type;
|
||||
|
||||
export const OrchestrationV2ShellSnapshot = Schema.Struct({
|
||||
threads: Schema.Array(OrchestrationV2ThreadShell),
|
||||
});
|
||||
export type OrchestrationV2ShellSnapshot = typeof OrchestrationV2ShellSnapshot.Type;
|
||||
|
||||
export const OrchestrationV2ShellStreamItem = Schema.Union([
|
||||
Schema.Struct({
|
||||
kind: Schema.Literal("snapshot"),
|
||||
snapshot: OrchestrationV2ShellSnapshot,
|
||||
}),
|
||||
Schema.Struct({
|
||||
kind: Schema.Literal("thread.updated"),
|
||||
thread: OrchestrationV2ThreadShell,
|
||||
}),
|
||||
]);
|
||||
export type OrchestrationV2ShellStreamItem = typeof OrchestrationV2ShellStreamItem.Type;
|
||||
|
||||
export const OrchestrationV2StoredEvent = Schema.Struct({
|
||||
sequence: NonNegativeInt,
|
||||
commandId: Schema.NullOr(CommandId),
|
||||
@@ -1036,6 +1105,7 @@ export const OrchestrationV2TurnItemJson = Schema.Union([
|
||||
...OrchestrationV2TurnItemJsonBaseFields,
|
||||
type: Schema.Literal("user_message"),
|
||||
messageId: MessageId,
|
||||
inputIntent: OrchestrationV2UserMessageInputIntent,
|
||||
text: Schema.String,
|
||||
attachments: Schema.Array(ChatAttachment),
|
||||
}),
|
||||
@@ -1143,6 +1213,7 @@ export const OrchestrationV2TurnItemJson = Schema.Union([
|
||||
toProvider: ProviderKind,
|
||||
strategy: Schema.Literals([
|
||||
"delta_since_target_last_seen",
|
||||
"fork_delta_summary",
|
||||
"full_thread_summary",
|
||||
"checkpoint_summary",
|
||||
"manual_context",
|
||||
@@ -1360,6 +1431,14 @@ export const OrchestrationV2Command = Schema.Union([
|
||||
title: Schema.optional(TrimmedNonEmptyString),
|
||||
createdAt: Schema.optional(Schema.DateTimeUtc),
|
||||
}),
|
||||
Schema.Struct({
|
||||
type: Schema.Literal("thread.merge_back"),
|
||||
commandId: CommandId,
|
||||
sourceThreadId: ThreadId,
|
||||
targetThreadId: ThreadId,
|
||||
sourcePoint: OrchestrationV2ThreadForkSourcePoint,
|
||||
createdAt: Schema.optional(Schema.DateTimeUtc),
|
||||
}),
|
||||
Schema.Struct({
|
||||
type: Schema.Literal("provider.switch"),
|
||||
commandId: CommandId,
|
||||
@@ -1373,6 +1452,7 @@ export type OrchestrationV2Command = typeof OrchestrationV2Command.Type;
|
||||
export const ORCHESTRATION_V2_WS_METHODS = {
|
||||
dispatchCommand: "orchestrationV2.dispatchCommand",
|
||||
getThreadProjection: "orchestrationV2.getThreadProjection",
|
||||
subscribeShell: "orchestrationV2.subscribeShell",
|
||||
subscribeThread: "orchestrationV2.subscribeThread",
|
||||
} as const;
|
||||
|
||||
@@ -1420,9 +1500,18 @@ export class OrchestrationV2GetThreadProjectionError extends Schema.TaggedErrorC
|
||||
},
|
||||
) {}
|
||||
|
||||
export class OrchestrationV2GetShellSnapshotError extends Schema.TaggedErrorClass<OrchestrationV2GetShellSnapshotError>()(
|
||||
"OrchestrationV2GetShellSnapshotError",
|
||||
{
|
||||
message: Schema.String,
|
||||
cause: Schema.optional(Schema.Defect),
|
||||
},
|
||||
) {}
|
||||
|
||||
export const OrchestrationV2RpcError = Schema.Union([
|
||||
OrchestrationV2DispatchCommandError,
|
||||
OrchestrationV2GetThreadProjectionError,
|
||||
OrchestrationV2GetShellSnapshotError,
|
||||
]);
|
||||
export type OrchestrationV2RpcError = typeof OrchestrationV2RpcError.Type;
|
||||
|
||||
@@ -1435,6 +1524,10 @@ export const OrchestrationV2RpcSchemas = {
|
||||
input: OrchestrationV2GetThreadProjectionInput,
|
||||
output: OrchestrationV2ThreadProjection,
|
||||
},
|
||||
subscribeShell: {
|
||||
input: Schema.Struct({}),
|
||||
output: OrchestrationV2ShellStreamItem,
|
||||
},
|
||||
subscribeThread: {
|
||||
input: OrchestrationV2GetThreadProjectionInput,
|
||||
output: OrchestrationV2ThreadStreamItem,
|
||||
|
||||
@@ -67,6 +67,7 @@ import { ProviderInstanceId } from "./providerInstance.ts";
|
||||
import {
|
||||
ORCHESTRATION_V2_WS_METHODS,
|
||||
OrchestrationV2DispatchCommandError,
|
||||
OrchestrationV2GetShellSnapshotError,
|
||||
OrchestrationV2GetThreadProjectionError,
|
||||
OrchestrationV2RpcSchemas,
|
||||
} from "./orchestrationV2.ts";
|
||||
@@ -744,6 +745,16 @@ export const WsOrchestrationV2GetThreadProjectionRpc = Rpc.make(
|
||||
},
|
||||
);
|
||||
|
||||
export const WsOrchestrationV2SubscribeShellRpc = Rpc.make(
|
||||
ORCHESTRATION_V2_WS_METHODS.subscribeShell,
|
||||
{
|
||||
payload: OrchestrationV2RpcSchemas.subscribeShell.input,
|
||||
success: OrchestrationV2RpcSchemas.subscribeShell.output,
|
||||
error: OrchestrationV2GetShellSnapshotError,
|
||||
stream: true,
|
||||
},
|
||||
);
|
||||
|
||||
export const WsOrchestrationV2SubscribeThreadRpc = Rpc.make(
|
||||
ORCHESTRATION_V2_WS_METHODS.subscribeThread,
|
||||
{
|
||||
@@ -885,5 +896,6 @@ export const WsRpcGroup = RpcGroup.make(
|
||||
WsOrchestrationSubscribeThreadRpc,
|
||||
WsOrchestrationV2DispatchCommandRpc,
|
||||
WsOrchestrationV2GetThreadProjectionRpc,
|
||||
WsOrchestrationV2SubscribeShellRpc,
|
||||
WsOrchestrationV2SubscribeThreadRpc,
|
||||
);
|
||||
Reference in new issue
Block a user