1
>
/*---------------------------------------------------------------------------------------------
chatUri.ts
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
>
import { localChatSessionType } from '../chatSessionsService.js';
10
>
11
>
type ChatSessionIdentifier = {
12
>
readonly chatSessionType: string;
13
>
readonly sessionId: string;
14
>
};
15
>
16
>
17
>
export namespace LocalChatSessionUri {
18
>
19
>
export const scheme = Schemas.vscodeLocalChatSession;
20
>
21
>
export function forSession(sessionId: string): URI {
22
const encodedId = encodeBase64(VSBuffer.wrap(new TextEncoder().encode(sessionId)), false, true);
23
return URI.from({ scheme, authority: localChatSessionType, path: '/' + encodedId });
24
}
26
>
export function getNewSessionUri(): URI {
27
const handle = Math.floor(Math.random() * 1e9);
28
return forSession(`chat-${handle}`);
29
}
31
>
export function parseLocalSessionId(resource: URI): string | undefined {
32
const parsed = parse(resource);
33
return parsed?.chatSessionType === localChatSessionType ? parsed.sessionId : undefined;
34
}
36
>
export function isLocalSession(resource: URI): boolean {
37
return !!parseLocalSessionId(resource);
38
}
40
>
function parse(resource: URI): ChatSessionIdentifier | undefined {
41
if (resource.scheme !== scheme) {
42
return undefined;