Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/platform/otel/common/sessionUtils.ts
13401 views
1
/*---------------------------------------------------------------------------------------------
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 { Uri } from 'vscode';
7
8
/**
9
* Decode a VS Code chat session resource URI to extract the raw session ID.
10
*
11
* Handles multiple URI schemes:
12
* - `vscode-chat-session://local/<base64EncodedSessionId>` — foreground chat sessions
13
* - `copilotcli://<sessionId>` — CLI in-process sessions
14
* - `claude-code://<sessionId>` — Claude Code sessions
15
*
16
* Used by the debug panel, span export, and other session-aware features.
17
*/
18
export function decodeSessionId(sessionResource: Uri): string {
19
if (sessionResource.scheme === 'copilotcli' || sessionResource.scheme === 'claude-code') {
20
return sessionResource.path.replace(/^\//, '');
21
}
22
const pathSegment = sessionResource.path.replace(/^\//, '').split('/').pop() || '';
23
if (pathSegment) {
24
try {
25
return Buffer.from(pathSegment, 'base64').toString('utf-8');
26
} catch { /* not base64, use as-is */ }
27
}
28
return sessionResource.toString();
29
}
30
31