@@ -60,7 +60,7 @@ import {
6060 RuntimeMode ,
6161 ThreadLinkedPullRequest ,
6262 ThreadId ,
63- type TurnItemId ,
63+ TurnItemId ,
6464} from "@t3tools/contracts" ;
6565import { modelSelectionsEqual } from "@t3tools/shared/model" ;
6666import {
@@ -2272,6 +2272,9 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
22722272 branch : command . branch ,
22732273 worktreePath : command . worktreePath ,
22742274 activeProviderThreadId : null ,
2275+ ...( command . importedConversation === undefined
2276+ ? { }
2277+ : { historyOrigin : "v1_import" as const } ) ,
22752278 ...( command . linkOrigin === undefined ? { } : { linkOrigin : command . linkOrigin } ) ,
22762279 pullRequests : [ ] ,
22772280 lineage : {
@@ -5384,7 +5387,11 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
53845387 const latestHandoffRun = projection . runs . findLast ( isHandoffSourceRun ) ;
53855388 const legacyImportItems =
53865389 projection . thread . historyOrigin === "v1_import"
5387- ? yield * readHandoffItems ( command . threadId , [ null ] )
5390+ ? ( yield * Ref . get ( events ) ) . some (
5391+ ( event ) => event . threadId === command . threadId && event . type === "thread.created" ,
5392+ )
5393+ ? projection . turnItems . filter ( ( item ) => item . runId === null )
5394+ : yield * readHandoffItems ( command . threadId , [ null ] )
53885395 : [ ] ;
53895396 const isProviderSwitch =
53905397 activeProviderThread !== undefined &&
@@ -10977,6 +10984,95 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
1097710984 switch ( command . type ) {
1097810985 case "thread.create" :
1097910986 yield * dispatchThreadCreate ( command , events ) ;
10987+ if ( command . importedConversation !== undefined ) {
10988+ const importedAt = yield * DateTime . now ;
10989+ for ( const [ index , message ] of command . importedConversation . messages . entries ( ) ) {
10990+ const messageId = MessageId . make ( `${ command . threadId } :history:${ index } ` ) ;
10991+ const at = DateTime . makeUnsafe ( message . createdAt ) ;
10992+ const common = {
10993+ id : TurnItemId . make ( `${ command . threadId } :history:${ index } ` ) ,
10994+ threadId : command . threadId ,
10995+ runId : null ,
10996+ nodeId : null ,
10997+ providerThreadId : null ,
10998+ providerTurnId : null ,
10999+ nativeItemRef : null ,
11000+ parentItemId : null ,
11001+ ordinal : index + 1 ,
11002+ status : "completed" as const ,
11003+ title : null ,
11004+ startedAt : at ,
11005+ completedAt : at ,
11006+ updatedAt : importedAt ,
11007+ } ;
11008+ yield * emit (
11009+ events ,
11010+ command ,
11011+ ) ( {
11012+ type : "message.updated" ,
11013+ threadId : command . threadId ,
11014+ occurredAt : importedAt ,
11015+ payload : {
11016+ id : messageId ,
11017+ threadId : command . threadId ,
11018+ runId : null ,
11019+ nodeId : null ,
11020+ createdBy : message . role === "user" ? "user" : "agent" ,
11021+ creationSource : "server" ,
11022+ role : message . role ,
11023+ text : message . text ,
11024+ attachments : [ ] ,
11025+ streaming : false ,
11026+ createdAt : at ,
11027+ updatedAt : importedAt ,
11028+ } ,
11029+ } ) ;
11030+ yield * emit (
11031+ events ,
11032+ command ,
11033+ ) ( {
11034+ type : "turn-item.updated" ,
11035+ threadId : command . threadId ,
11036+ occurredAt : importedAt ,
11037+ payload :
11038+ message . role === "user"
11039+ ? {
11040+ ...common ,
11041+ type : "user_message" ,
11042+ messageId,
11043+ text : message . text ,
11044+ attachments : [ ] ,
11045+ createdBy : "user" ,
11046+ creationSource : "server" ,
11047+ inputIntent : "turn_start" ,
11048+ }
11049+ : {
11050+ ...common ,
11051+ type : "assistant_message" ,
11052+ messageId,
11053+ text : message . text ,
11054+ streaming : false ,
11055+ } ,
11056+ } ) ;
11057+ }
11058+ if ( command . importedConversation . continuationPrompt !== undefined ) {
11059+ yield * dispatchMessage (
11060+ {
11061+ type : "message.dispatch" ,
11062+ commandId : command . commandId ,
11063+ threadId : command . threadId ,
11064+ messageId : MessageId . make ( `${ command . threadId } :continuation` ) ,
11065+ text : command . importedConversation . continuationPrompt ,
11066+ attachments : [ ] ,
11067+ dispatchMode : { type : "start_immediately" } ,
11068+ createdBy : command . createdBy ,
11069+ creationSource : command . creationSource ,
11070+ } ,
11071+ events ,
11072+ effects ,
11073+ ) ;
11074+ }
11075+ }
1098011076 break ;
1098111077 case "thread.visit" :
1098211078 yield * dispatchThreadVisit ( command , events ) ;
0 commit comments