Files
vscode/src/vs/platform/agentHost/test/node/copilotTestEvents.ts
T
roblourensandCopilot 24bfcea255 Restore persisted agent request errors (#329828)
* Restore persisted agent request errors

(Written by Copilot)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Restore errors on subagent turns

(Written by Copilot)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Remove obsolete proxy error reference

(Written by Copilot)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-08-09 18:56:29 +00:00

165 lines
5.8 KiB
TypeScript

/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import type { Attachment, SessionEvent, SessionEventPayload, SkillInvokedData, ToolExecutionCompleteContent } from '@github/copilot-sdk';
// =============================================================================
// Minimal session-event shapes for tests
// =============================================================================
// Production (`node/copilot/mapSessionEvents.ts`) consumes the real SDK
// `SessionEvent` union. The SDK members require envelope fields the mapper
// never reads (`parentId`, `timestamp`, `ephemeral`, …) plus stricter `data`
// shapes, which makes hand-written event literals noisy. These ergonomic
// subsets let tests construct only the fields the mapper actually reads; feed
// them to the production mapper via {@link toSessionEvents}.
export interface ISessionEventToolStart {
type: 'tool.execution_start';
/** Envelope-level sub-agent instance id; resolved to the parent tool call id via `subagent.started`. */
agentId?: string;
/** ISO 8601 envelope timestamp; the mapper uses it to restore turn timing. */
timestamp?: string;
data: {
toolCallId: string;
toolName: string;
arguments?: unknown;
mcpServerName?: string;
mcpToolName?: string;
toolDescription?: unknown;
/** @deprecated Use the envelope-level {@link ISessionEventToolStart.agentId} instead. */
parentToolCallId?: string;
};
}
export interface ISessionEventToolComplete {
type: 'tool.execution_complete';
/** Envelope-level sub-agent instance id. See {@link ISessionEventToolStart.agentId}. */
agentId?: string;
/** ISO 8601 envelope timestamp; the mapper uses it to restore turn timing. */
timestamp?: string;
data: {
toolCallId: string;
success: boolean;
result?: {
/** `content` is result text; `contents` are typed SDK result blocks such as `shell_exit`. */
content?: string;
contents?: ToolExecutionCompleteContent[];
};
error?: { message: string; code?: string };
isUserRequested?: boolean;
toolTelemetry?: unknown;
mcpServerName?: string;
mcpToolName?: string;
toolDescription?: unknown;
/** @deprecated Use the envelope-level {@link ISessionEventToolComplete.agentId} instead. */
parentToolCallId?: string;
};
}
export interface ISessionEventMessage {
type: 'assistant.message' | 'user.message';
/** SDK envelope-level event id, used as the protocol turn id. */
id?: string;
/** Envelope-level sub-agent instance id. See {@link ISessionEventToolStart.agentId}. */
agentId?: string;
/** ISO 8601 envelope timestamp; the mapper uses it to restore turn timing. */
timestamp?: string;
data: {
messageId?: string;
interactionId?: string;
content?: string;
toolRequests?: readonly { toolCallId: string; name: string; arguments?: unknown; type?: 'function' | 'custom'; mcpServerName?: string; mcpToolName?: string; toolDescription?: unknown }[];
reasoningOpaque?: string;
reasoningText?: string;
encryptedContent?: string;
/** @deprecated Use the envelope-level {@link ISessionEventMessage.agentId} instead. */
parentToolCallId?: string;
/** Origin of the message; a non-`'user'` value marks an SDK-injected message that should be hidden. */
source?: string;
attachments?: readonly Attachment[];
};
}
export interface ISessionEventSkillInvoked {
type: 'skill.invoked';
id?: string;
/** Envelope-level sub-agent instance id. */
agentId?: string;
data: SkillInvokedData;
}
export interface ISessionEventSubagentStarted {
type: 'subagent.started';
/** Envelope-level sub-agent instance id resolved back to {@link ISessionEventSubagentStarted.data.toolCallId}. */
agentId?: string;
data: {
toolCallId: string;
agentName: string;
agentDisplayName: string;
agentDescription: string;
};
}
export interface ISessionEventAbort {
type: 'abort';
/** Envelope-level sub-agent instance id. */
agentId?: string;
data: {
reason: string;
};
}
export interface ISessionEventAssistantTurn {
type: 'assistant.turn_start' | 'assistant.turn_end';
agentId?: string;
/** ISO 8601 envelope timestamp; the mapper uses it to restore turn timing. */
timestamp?: string;
data: {
turnId: string;
interactionId?: string;
};
}
export interface ISessionEventSystemNotification {
type: 'system.notification';
id?: string;
/** ISO 8601 envelope timestamp; the mapper uses it to restore turn timing. */
timestamp?: string;
data: SessionEventPayload<'system.notification'>['data'];
}
export interface ISessionEventError {
type: 'session.error';
id?: string;
agentId?: string;
/** ISO 8601 envelope timestamp; the mapper uses it to restore turn timing. */
timestamp?: string;
data: SessionEventPayload<'session.error'>['data'];
}
/** Minimal event shape for session history mapping. */
export type ISessionEvent =
| ISessionEventToolStart
| ISessionEventToolComplete
| ISessionEventMessage
| ISessionEventSubagentStarted
| ISessionEventSkillInvoked
| ISessionEventAbort
| ISessionEventAssistantTurn
| ISessionEventSystemNotification
| ISessionEventError
| { type: string; timestamp?: string; data?: unknown };
/**
* Widens ergonomic {@link ISessionEvent} test fixtures to the real SDK
* {@link SessionEvent} union so they can be fed to the production
* `mapSessionEvents`. The test shapes deliberately omit envelope fields the
* mapper ignores (`parentId`, …), so this is a safe deliberate widening
* rather than a representation of real SDK events.
*/
export function toSessionEvents(events: readonly ISessionEvent[]): SessionEvent[] {
return events as unknown as SessionEvent[];
}