Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/chat/common/chatUri.ts
3296 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 { encodeBase64, VSBuffer, decodeBase64 } from '../../../../base/common/buffer.js';
7
import { Schemas } from '../../../../base/common/network.js';
8
import { URI } from '../../../../base/common/uri.js';
9
10
export type ChatSessionIdentifier = {
11
readonly chatSessionType: string;
12
readonly sessionId: string;
13
};
14
15
export namespace ChatSessionUri {
16
17
export const scheme = Schemas.vscodeChatSession;
18
19
export function forSession(chatSessionType: string, sessionId: string): URI {
20
const encodedId = encodeBase64(VSBuffer.wrap(new TextEncoder().encode(sessionId)), false, true);
21
// TODO: Do we need to encode the authority too?
22
return URI.from({ scheme, authority: chatSessionType, path: '/' + encodedId });
23
}
24
25
export function parse(resource: URI): ChatSessionIdentifier | undefined {
26
if (resource.scheme !== scheme) {
27
return undefined;
28
}
29
30
if (!resource.authority) {
31
return undefined;
32
}
33
34
const parts = resource.path.split('/');
35
if (parts.length !== 2) {
36
return undefined;
37
}
38
39
const chatSessionType = resource.authority;
40
const decodedSessionId = decodeBase64(parts[1]);
41
return { chatSessionType, sessionId: new TextDecoder().decode(decodedSessionId.buffer) };
42
}
43
}
44
45