mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-22 17:48:56 +01:00
Revert "Revert "Debug Panel: oTel data source support and Import/export (#299…"
This reverts commit 11246017b6.
This commit is contained in:
@@ -4,12 +4,13 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import type * as vscode from 'vscode';
|
||||
import { VSBuffer } from '../../../base/common/buffer.js';
|
||||
import { CancellationToken } from '../../../base/common/cancellation.js';
|
||||
import { Emitter } from '../../../base/common/event.js';
|
||||
import { Disposable, DisposableStore, toDisposable } from '../../../base/common/lifecycle.js';
|
||||
import { URI, UriComponents } from '../../../base/common/uri.js';
|
||||
import { ExtHostChatDebugShape, IChatDebugEventDto, IChatDebugResolvedEventContentDto, MainContext, MainThreadChatDebugShape } from './extHost.protocol.js';
|
||||
import { ChatDebugMessageContentType, ChatDebugSubagentStatus, ChatDebugToolCallResult } from './extHostTypes.js';
|
||||
import { ChatDebugGenericEvent, ChatDebugLogLevel, ChatDebugMessageContentType, ChatDebugMessageSection, ChatDebugModelTurnEvent, ChatDebugSubagentInvocationEvent, ChatDebugSubagentStatus, ChatDebugToolCallEvent, ChatDebugToolCallResult, ChatDebugUserMessageEvent, ChatDebugAgentResponseEvent } from './extHostTypes.js';
|
||||
import { IExtHostRpcService } from './extHostRpcService.js';
|
||||
|
||||
export class ExtHostChatDebug extends Disposable implements ExtHostChatDebugShape {
|
||||
@@ -291,6 +292,106 @@ export class ExtHostChatDebug extends Disposable implements ExtHostChatDebugShap
|
||||
}
|
||||
}
|
||||
|
||||
private _deserializeEvent(dto: IChatDebugEventDto): vscode.ChatDebugEvent | undefined {
|
||||
const created = new Date(dto.created);
|
||||
const sessionResource = dto.sessionResource ? URI.revive(dto.sessionResource) : undefined;
|
||||
switch (dto.kind) {
|
||||
case 'toolCall': {
|
||||
const evt = new ChatDebugToolCallEvent(dto.toolName, created);
|
||||
evt.id = dto.id;
|
||||
evt.sessionResource = sessionResource;
|
||||
evt.parentEventId = dto.parentEventId;
|
||||
evt.toolCallId = dto.toolCallId;
|
||||
evt.input = dto.input;
|
||||
evt.output = dto.output;
|
||||
evt.result = dto.result === 'success' ? ChatDebugToolCallResult.Success
|
||||
: dto.result === 'error' ? ChatDebugToolCallResult.Error
|
||||
: undefined;
|
||||
evt.durationInMillis = dto.durationInMillis;
|
||||
return evt;
|
||||
}
|
||||
case 'modelTurn': {
|
||||
const evt = new ChatDebugModelTurnEvent(created);
|
||||
evt.id = dto.id;
|
||||
evt.sessionResource = sessionResource;
|
||||
evt.parentEventId = dto.parentEventId;
|
||||
evt.model = dto.model;
|
||||
evt.inputTokens = dto.inputTokens;
|
||||
evt.outputTokens = dto.outputTokens;
|
||||
evt.totalTokens = dto.totalTokens;
|
||||
evt.durationInMillis = dto.durationInMillis;
|
||||
return evt;
|
||||
}
|
||||
case 'generic': {
|
||||
const evt = new ChatDebugGenericEvent(dto.name, dto.level as ChatDebugLogLevel, created);
|
||||
evt.id = dto.id;
|
||||
evt.sessionResource = sessionResource;
|
||||
evt.parentEventId = dto.parentEventId;
|
||||
evt.details = dto.details;
|
||||
evt.category = dto.category;
|
||||
return evt;
|
||||
}
|
||||
case 'subagentInvocation': {
|
||||
const evt = new ChatDebugSubagentInvocationEvent(dto.agentName, created);
|
||||
evt.id = dto.id;
|
||||
evt.sessionResource = sessionResource;
|
||||
evt.parentEventId = dto.parentEventId;
|
||||
evt.description = dto.description;
|
||||
evt.status = dto.status === 'running' ? ChatDebugSubagentStatus.Running
|
||||
: dto.status === 'completed' ? ChatDebugSubagentStatus.Completed
|
||||
: dto.status === 'failed' ? ChatDebugSubagentStatus.Failed
|
||||
: undefined;
|
||||
evt.durationInMillis = dto.durationInMillis;
|
||||
evt.toolCallCount = dto.toolCallCount;
|
||||
evt.modelTurnCount = dto.modelTurnCount;
|
||||
return evt;
|
||||
}
|
||||
case 'userMessage': {
|
||||
const evt = new ChatDebugUserMessageEvent(dto.message, created);
|
||||
evt.id = dto.id;
|
||||
evt.sessionResource = sessionResource;
|
||||
evt.parentEventId = dto.parentEventId;
|
||||
evt.sections = dto.sections.map(s => new ChatDebugMessageSection(s.name, s.content));
|
||||
return evt;
|
||||
}
|
||||
case 'agentResponse': {
|
||||
const evt = new ChatDebugAgentResponseEvent(dto.message, created);
|
||||
evt.id = dto.id;
|
||||
evt.sessionResource = sessionResource;
|
||||
evt.parentEventId = dto.parentEventId;
|
||||
evt.sections = dto.sections.map(s => new ChatDebugMessageSection(s.name, s.content));
|
||||
return evt;
|
||||
}
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
async $exportChatDebugLog(_handle: number, sessionResource: UriComponents, coreEventDtos: IChatDebugEventDto[], sessionTitle: string | undefined, token: CancellationToken): Promise<VSBuffer | undefined> {
|
||||
if (!this._provider?.provideChatDebugLogExport) {
|
||||
return undefined;
|
||||
}
|
||||
const sessionUri = URI.revive(sessionResource);
|
||||
const coreEvents = coreEventDtos.map(dto => this._deserializeEvent(dto)).filter((e): e is vscode.ChatDebugEvent => e !== undefined);
|
||||
const options: vscode.ChatDebugLogExportOptions = { coreEvents, sessionTitle };
|
||||
const result = await this._provider.provideChatDebugLogExport(sessionUri, options, token);
|
||||
if (!result) {
|
||||
return undefined;
|
||||
}
|
||||
return VSBuffer.wrap(result);
|
||||
}
|
||||
|
||||
async $importChatDebugLog(_handle: number, data: VSBuffer, token: CancellationToken): Promise<{ uri: UriComponents; sessionTitle?: string } | undefined> {
|
||||
if (!this._provider?.resolveChatDebugLogImport) {
|
||||
return undefined;
|
||||
}
|
||||
const result = await this._provider.resolveChatDebugLogImport(data.buffer, token);
|
||||
if (!result) {
|
||||
return undefined;
|
||||
}
|
||||
return { uri: result.uri, sessionTitle: result.sessionTitle };
|
||||
}
|
||||
|
||||
override dispose(): void {
|
||||
for (const store of this._activeProgress.values()) {
|
||||
store.dispose();
|
||||
|
||||
Reference in New Issue
Block a user