1225
createOptions = { ...options, fork: undefined };
1226
} else {
1228
>
const turnIdMapping = new Map<string, string>();
1229
>
for (const t of slice) {
1230
>
turnIdMapping.set(t.id, generateUuid());
1231
>
}
1232
>
forkedTurns = slice.map(t => ({ ...t, id: turnIdMapping.get(t.id) ?? generateUuid() }));
1233
>
1234
>
// Carry forked host-injected local turns (`/rename`, `!command`)
1235
>
// into the new chat so they survive reload and anchor future
1236
>
// fork/truncate.
1237
>
this._persistForkedLocalTurns(sessionKey, sourceChatUri, chat.toString(), slice, forkedTurns, turnIdMapping);
1238
>
1239
>
const forkedTitlePrefix = localize('agentHost.forkedTitlePrefix', "Forked: ");
1240
>
forkedSourceTitle = sourceState?.title || this._stateManager.getSessionState(sessionKey)?.title;
1241
>
forkedTitle = forkedSourceTitle
1242
? (forkedSourceTitle.startsWith(forkedTitlePrefix) ? forkedSourceTitle : `${forkedTitlePrefix}${forkedSourceTitle}`)
1243
: localize('agentHost.forkedChatFallback', "Forked Chat");
1244
>
// The SDK fork boundary must be a concrete (SDK-backed) turn. When
agentService.ts
1245
>
// the client forked at a host-injected local turn, redirect the
1246
>
// agent to the preceding concrete turn (the local turns are still
1247
>
// seeded into the new chat's protocol state above).
1248
>
const concreteForkTurnId = this._localTurns.resolveConcreteTurnId(sourceChatUri, options.fork.turnId);
1249
>
createOptions = { ...options, fork: { ...options.fork, turnIdMapping, ...(concreteForkTurnId !== undefined ? { turnId: concreteForkTurnId } : {}) } };
1250
>
}
1251
}
1252