(
sessionId: string,
sourceView: RuntimeReadModelSessionView,
copied: StoredMessage[],
input: BranchFromTurnInput,
)
| 4995 | } |
| 4996 | |
| 4997 | private async createBranchSession( |
| 4998 | sessionId: string, |
| 4999 | sourceView: RuntimeReadModelSessionView, |
| 5000 | copied: StoredMessage[], |
| 5001 | input: BranchFromTurnInput, |
| 5002 | ): Promise<SessionSummary> { |
| 5003 | const plan = await this.prepareConversationRuntimeLedgerClone(sessionId, sourceView, copied); |
| 5004 | const [header, boundary] = await Promise.all([ |
| 5005 | this.deps.store.readHeader(sessionId), |
| 5006 | this.deps.store.readExecutionBoundary(sessionId), |
| 5007 | ]); |
| 5008 | const next = await this.deps.store.create( |
| 5009 | { |
| 5010 | cwd: header.cwd, |
| 5011 | ...(header.projectId !== undefined ? { projectId: header.projectId } : {}), |
| 5012 | backend: header.backend, |
| 5013 | llmConnectionSlug: header.llmConnectionSlug, |
| 5014 | model: header.model, |
| 5015 | thinkingLevel: header.thinkingLevel, |
| 5016 | permissionMode: header.permissionMode, |
| 5017 | collaborationMode: header.collaborationMode, |
| 5018 | orchestrationMode: header.orchestrationMode ?? 'default', |
| 5019 | name: input.name ?? `${header.name} · 分支`, |
| 5020 | labels: input.sideConversation |
| 5021 | ? [...new Set([...header.labels, SIDE_CONVERSATION_SESSION_LABEL])] |
| 5022 | : header.labels, |
| 5023 | parentSessionId: sessionId, |
| 5024 | branchOfTurnId: input.sourceTurnId, |
| 5025 | status: 'active', |
| 5026 | }, |
| 5027 | boundary, |
| 5028 | ); |
| 5029 | try { |
| 5030 | const rewritten = await this.cloneConversationRuntimeLedger(next.id, copied, plan); |
| 5031 | if (rewritten.length > 0) await this.deps.store.appendMessages(next.id, [...rewritten]); |
| 5032 | await this.deps.store.appendMessage(next.id, { |
| 5033 | type: 'system_note', |
| 5034 | id: this.deps.newId(), |
| 5035 | ts: this.deps.now(), |
| 5036 | kind: 'session_start', |
| 5037 | data: { parentSessionId: sessionId, branchOfTurnId: input.sourceTurnId }, |
| 5038 | }); |
| 5039 | return headerToSummary(await this.deps.store.readHeader(next.id)); |
| 5040 | } catch (error) { |
| 5041 | return this.rollbackLegacyConversationCopy(next.id, error); |
| 5042 | } |
| 5043 | } |
| 5044 | |
| 5045 | async respondToSandboxBoundary( |
| 5046 | sessionId: string, |
no test coverage detected