1
>
/*---------------------------------------------------------------------------------------------
historyRecordFixtures.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { URI } from '../../../../base/common/uri.js';
7
>
import { generateUuid } from '../../../../base/common/uuid.js';
8
>
import { isString } from '../../../../base/common/types.js';
9
>
import { stripRedundantCdPrefix } from '../../common/commandLineHelpers.js';
10
>
import { IFileEditRecord, ISessionDatabase } from '../../common/sessionDataService.js';
11
>
import { MessageKind, ResponsePartKind, ToolCallConfirmationReason, ToolCallStatus, ToolResultContentType, TurnState, buildSubagentSessionUri, type Message, type ResponsePart, type StringOrMarkdown, type ToolCallCompletedState, type ToolResultContent, type Turn } from '../../common/state/sessionState.js';
12
>
import { getInvocationMessage, getPastTenseMessage, getShellLanguage, getSubagentMetadata, getToolDisplayName, getToolInputString, getToolKind, isEditTool, isHiddenTool, synthesizeSkillToolCall } from '../../node/copilot/copilotToolDisplay.js';
13
>
import { buildSessionDbUri } from '../../node/shared/fileEditTracker.js';
14
>
import type { ISessionEvent, ISessionEventMessage, ISessionEventSkillInvoked, ISessionEventSubagentStarted, ISessionEventToolComplete, ISessionEventToolStart } from './copilotTestEvents.js';
15
>
16
>
// =============================================================================
17
>
// History-record test fixtures
18
>
//
19
>
// Flat, declarative DSL used by mock agents and unit tests to build session
20
>
// history without manually constructing `Turn[]`. Records mirror the wire
21
>
// shape of an SDK event stream — `message`, `tool_start`, `tool_complete`,
22
>
// `subagent_started` — so transcripts read like the protocol they're
23
>
// emulating.
24
>
//
25
>
// Production code does NOT depend on this module. The real
26
>
// SDK-events-to-Turn[] pipeline in `node/copilot/mapSessionEvents.ts` runs
27
>
// in a single pass without producing the intermediate record shape.
28
>
// =============================================================================
29
>
30
>
interface IHistoryRecordBase {
31
>
readonly session: URI;
32
>
}
33
>
34
>
interface IHistoryMessageRecord extends IHistoryRecordBase {
35
>
readonly type: 'message';
36
>
readonly role: 'user' | 'assistant';
37
>
readonly messageId: string;
38
>
readonly content: string;
39
>
readonly toolRequests?: readonly {
40
>
readonly toolCallId: string;
41
>
readonly name: string;
42
>
readonly arguments?: string;
43
>
readonly type?: 'function' | 'custom';
44
>
}[];
45
>
readonly reasoningOpaque?: string;
46
>
readonly reasoningText?: string;
47
>
readonly encryptedContent?: string;
48
>
readonly parentToolCallId?: string;
49
>
}
50
>
51
>
export interface IHistoryToolStartRecord extends IHistoryRecordBase {
52
>
readonly type: 'tool_start';
53
>
readonly toolCallId: string;
54
>
readonly toolName: string;
55
>
readonly displayName: string;
56
>
readonly invocationMessage: StringOrMarkdown;
57
>
readonly toolInput?: string;
58
>
readonly toolKind?: 'terminal' | 'subagent' | 'search';
59
>
readonly language?: string;
60
>
readonly toolArguments?: string;
61
>
readonly subagentAgentName?: string;
62
>
readonly subagentDescription?: string;
63
>
readonly mcpServerName?: string;
64
>
readonly mcpToolName?: string;
65
>
readonly parentToolCallId?: string;
66
>
}
67
>
68
>
interface IHistoryToolCompleteRecord extends IHistoryRecordBase {
69
>
readonly type: 'tool_complete';
70
>
readonly toolCallId: string;
71
>
readonly result: {
72
>
readonly success: boolean;
73
>
readonly pastTenseMessage: StringOrMarkdown;
74
>
readonly content?: ToolResultContent[];
75
>
readonly error?: { readonly message: string; readonly code?: string };
76
>
};
77
>
readonly isUserRequested?: boolean;
78
>
readonly toolTelemetry?: string;
79
>
readonly parentToolCallId?: string;
80
>
}
81
>
82
>
interface IHistorySubagentStartedRecord extends IHistoryRecordBase {
83
>
readonly type: 'subagent_started';
84
>
readonly toolCallId: string;
85
>
readonly agentName: string;
86
>
readonly agentDisplayName: string;
87
>
readonly agentDescription?: string;
88
>
}
89
>
90
>
/** Test fixture record. Hand-constructed by tests to seed mock session histories. */
91
>
export type IHistoryRecord =
92
>
| IHistoryMessageRecord
93
>
| IHistoryToolStartRecord
94
>
| IHistoryToolCompleteRecord
95
>
| IHistorySubagentStartedRecord;
96
>
97
function extractSubagentMeta(start: IHistoryToolStartRecord | undefined): { subagentDescription?: string; subagentAgentName?: string } {
98
if (!start) {