1
>
/*---------------------------------------------------------------------------------------------
copilotTestEvents.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 type { Attachment, SessionEvent, SessionEventPayload, ToolExecutionCompleteContent } from '@github/copilot-sdk';
7
>
8
>
// =============================================================================
9
>
// Minimal session-event shapes for tests
10
>
// =============================================================================
11
>
// Production (`node/copilot/mapSessionEvents.ts`) consumes the real SDK
12
>
// `SessionEvent` union. The SDK members require envelope fields the mapper
13
>
// never reads (`parentId`, `timestamp`, `ephemeral`, …) plus stricter `data`
14
>
// shapes, which makes hand-written event literals noisy. These ergonomic
15
>
// subsets let tests construct only the fields the mapper actually reads; feed
16
>
// them to the production mapper via {@link toSessionEvents}.
17
>
18
>
export interface ISessionEventToolStart {
19
>
type: 'tool.execution_start';
20
>
/** Envelope-level sub-agent instance id; resolved to the parent tool call id via `subagent.started`. */
21
>
agentId?: string;
22
>
data: {
23
>
toolCallId: string;
24
>
toolName: string;
25
>
arguments?: unknown;
26
>
mcpServerName?: string;
27
>
mcpToolName?: string;
28
>
toolDescription?: unknown;
29
>
/** @deprecated Use the envelope-level {@link ISessionEventToolStart.agentId} instead. */
30
>
parentToolCallId?: string;
31
>
};
32
>
}
33
>
34
>
export interface ISessionEventToolComplete {
35
>
type: 'tool.execution_complete';
36
>
/** Envelope-level sub-agent instance id. See {@link ISessionEventToolStart.agentId}. */
37
>
agentId?: string;
38
>
data: {
39
>
toolCallId: string;
40
>
success: boolean;
41
>
result?: {
42
>
/** `content` is result text; `contents` are typed SDK result blocks such as `shell_exit`. */
43
>
content?: string;
44
>
contents?: ToolExecutionCompleteContent[];
45
>
};
46
>
error?: { message: string; code?: string };
47
>
isUserRequested?: boolean;
48
>
toolTelemetry?: unknown;
49
>
mcpServerName?: string;
50
>
mcpToolName?: string;
51
>
toolDescription?: unknown;
52
>
/** @deprecated Use the envelope-level {@link ISessionEventToolComplete.agentId} instead. */
53
>
parentToolCallId?: string;
54
>
};
55
>
}
56
>
57
>
export interface ISessionEventMessage {
58
>
type: 'assistant.message' | 'user.message';
59
>
/** SDK envelope-level event id, used as the protocol turn id. */
60
>
id?: string;
61
>
/** Envelope-level sub-agent instance id. See {@link ISessionEventToolStart.agentId}. */
62
>
agentId?: string;
63
>
data: {
64
>
messageId?: string;
65
>
interactionId?: string;
66
>
content?: string;
67
>
toolRequests?: readonly { toolCallId: string; name: string; arguments?: unknown; type?: 'function' | 'custom'; mcpServerName?: string; mcpToolName?: string; toolDescription?: unknown }[];
68
>
reasoningOpaque?: string;
69
>
reasoningText?: string;
70
>
encryptedContent?: string;
71
>
/** @deprecated Use the envelope-level {@link ISessionEventMessage.agentId} instead. */
72
>
parentToolCallId?: string;
73
>
/** Origin of the message; a non-`'user'` value marks an SDK-injected message that should be hidden. */
74
>
source?: string;
75
>
attachments?: readonly Attachment[];
76
>
};
77
>
}
78
>
79
>
/** Minimal event shape for `skill.invoked`, used to synthesize a tool-style render. */
80
>
export interface ISessionEventSkillInvoked {
81
>
type: 'skill.invoked';
82
>
id?: string;
83
>
/** Envelope-level sub-agent instance id. */
84
>
agentId?: string;
85
>
data: {
86
>
name: string;
87
>
path?: string;
88
>
description?: string;
89
>
};
90
>
}
91
>
92
>
export interface ISessionEventSubagentStarted {
93
>
type: 'subagent.started';
94
>
/** Envelope-level sub-agent instance id resolved back to {@link ISessionEventSubagentStarted.data.toolCallId}. */
95
>
agentId?: string;
96
>
data: {
97
>
toolCallId: string;
98
>
agentName: string;
99
>
agentDisplayName: string;
100
>
agentDescription: string;
101
>
};
102
>
}
103
>
104
>
export interface ISessionEventAbort {
105
>
type: 'abort';
106
>
/** Envelope-level sub-agent instance id. */
107
>
agentId?: string;
108
>
data: {
109
>
reason: string;
110
>
};
111
>
}
112
>
113
>
export interface ISessionEventAssistantTurn {
114
>
type: 'assistant.turn_start' | 'assistant.turn_end';
115
>
agentId?: string;
116
>
data: {
117
>
turnId: string;
118
>
interactionId?: string;
119
>
};
120
>
}
121
>
122
>
export interface ISessionEventSystemNotification {
123
>
type: 'system.notification';
124
>
id?: string;
125
>
data: SessionEventPayload<'system.notification'>['data'];
126
>
}
127
>
128
>
/** Minimal event shape for session history mapping. */
129
>
export type ISessionEvent =
130
>
| ISessionEventToolStart
131
>
| ISessionEventToolComplete
132
>
| ISessionEventMessage
133
>
| ISessionEventSubagentStarted
134
>
| ISessionEventSkillInvoked
135
>
| ISessionEventAbort
136
>
| ISessionEventAssistantTurn
137
>
| ISessionEventSystemNotification
138
>
| { type: string; data?: unknown };
139
>
140
>
/**
141
>
* Widens ergonomic {@link ISessionEvent} test fixtures to the real SDK
142
>
* {@link SessionEvent} union so they can be fed to the production
143
>
* `mapSessionEvents`. The test shapes deliberately omit envelope fields the
144
>
* mapper ignores (`parentId`, `timestamp`, …), so this is a safe deliberate
145
>
* widening rather than a representation of real SDK events.
146
>
*/
147
>
export function toSessionEvents(events: readonly ISessionEvent[]): SessionEvent[] {
148
return events as unknown as SessionEvent[];
149
}