377
* available. Test-fixture-only.
378
*/
380
>
session: URI,
381
>
db: ISessionDatabase | undefined,
382
>
events: readonly ISessionEvent[],
383
>
workingDirectory?: URI,
384
>
): Promise<IHistoryRecord[]> {
385
>
const result: IHistoryRecord[] = [];
386
>
const toolInfoByCallId = new Map<string, { toolName: string; parameters: Record<string, unknown> | undefined; rewrittenArgs?: string }>();
387
>
const editToolCallIds: string[] = [];
388
>
389
>
// The SDK tags sub-agent events with an envelope-level `agentId` (the
390
>
// `data.parentToolCallId` field is deprecated). `subagent.started` maps the
391
>
// sub-agent's `agentId` to the parent tool call id; resolve later events
392
>
// through it so the produced records carry the right `parentToolCallId`.
393
>
const parentToolCallIdByAgentId = new Map<string, string>();
394
>
const resolveParentToolCallId = (agentId: string | undefined, deprecatedParentToolCallId: string | undefined): string | undefined => {
395
const mapped = agentId ? parentToolCallIdByAgentId.get(agentId) : undefined;
396
return mapped ?? deprecatedParentToolCallId;
397
};
399
>
for (const e of events) {
400
>
if (e.type === 'subagent.started') {
401
const sub = e as ISessionEventSubagentStarted;
402
if (sub.agentId) {