Path: blob/main/src/vs/workbench/contrib/chat/common/chatUri.ts
3296 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 { encodeBase64, VSBuffer, decodeBase64 } from '../../../../base/common/buffer.js';6import { Schemas } from '../../../../base/common/network.js';7import { URI } from '../../../../base/common/uri.js';89export type ChatSessionIdentifier = {10readonly chatSessionType: string;11readonly sessionId: string;12};1314export namespace ChatSessionUri {1516export const scheme = Schemas.vscodeChatSession;1718export function forSession(chatSessionType: string, sessionId: string): URI {19const encodedId = encodeBase64(VSBuffer.wrap(new TextEncoder().encode(sessionId)), false, true);20// TODO: Do we need to encode the authority too?21return URI.from({ scheme, authority: chatSessionType, path: '/' + encodedId });22}2324export function parse(resource: URI): ChatSessionIdentifier | undefined {25if (resource.scheme !== scheme) {26return undefined;27}2829if (!resource.authority) {30return undefined;31}3233const parts = resource.path.split('/');34if (parts.length !== 2) {35return undefined;36}3738const chatSessionType = resource.authority;39const decodedSessionId = decodeBase64(parts[1]);40return { chatSessionType, sessionId: new TextDecoder().decode(decodedSessionId.buffer) };41}42}434445