Path: blob/main/extensions/copilot/src/platform/otel/common/sessionUtils.ts
13401 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import type { Uri } from 'vscode';67/**8* Decode a VS Code chat session resource URI to extract the raw session ID.9*10* Handles multiple URI schemes:11* - `vscode-chat-session://local/<base64EncodedSessionId>` — foreground chat sessions12* - `copilotcli://<sessionId>` — CLI in-process sessions13* - `claude-code://<sessionId>` — Claude Code sessions14*15* Used by the debug panel, span export, and other session-aware features.16*/17export function decodeSessionId(sessionResource: Uri): string {18if (sessionResource.scheme === 'copilotcli' || sessionResource.scheme === 'claude-code') {19return sessionResource.path.replace(/^\//, '');20}21const pathSegment = sessionResource.path.replace(/^\//, '').split('/').pop() || '';22if (pathSegment) {23try {24return Buffer.from(pathSegment, 'base64').toString('utf-8');25} catch { /* not base64, use as-is */ }26}27return sessionResource.toString();28}293031