Path: blob/main/src/vs/platform/agentHost/node/copilot/pendingEditContentStore.ts
13399 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 { encodeHex, VSBuffer } from '../../../../base/common/buffer.js';6import { IDisposable } from '../../../../base/common/lifecycle.js';7import { URI } from '../../../../base/common/uri.js';8import { IFileService } from '../../../files/common/files.js';9import { InMemoryFileSystemProvider } from '../../../files/common/inMemoryFilesystemProvider.js';1011/**12* URI scheme for transient file content backing tool-call write-permission13* previews. Files under this scheme live in an in-memory provider registered14* on the agent host's file service; content can be read/written through the15* file service just like any other resource.16*/17export const PENDING_EDIT_CONTENT_SCHEME = 'pending-edit-content';1819/**20* Builds a `pending-edit-content:` URI identifying the proposed "after"21* content for a write permission request. The authority is a hex-encoded22* session URI so multiple concurrent sessions don't collide.23*/24export function buildPendingEditContentUri(sessionUri: string, toolCallId: string, filePath: string): URI {25return URI.from({26scheme: PENDING_EDIT_CONTENT_SCHEME,27authority: encodeHex(VSBuffer.fromString(sessionUri)).toString(),28path: `/${encodeURIComponent(toolCallId)}/${encodeHex(VSBuffer.fromString(filePath))}`,29});30}3132/**33* Registers a fresh {@link InMemoryFileSystemProvider} for the34* `pending-edit-content:` scheme on the given file service. Callers use the35* returned disposable to unregister the provider.36*/37export function registerPendingEditContentProvider(fileService: IFileService): IDisposable {38const provider = new InMemoryFileSystemProvider();39const registration = fileService.registerProvider(PENDING_EDIT_CONTENT_SCHEME, provider);40return {41dispose() {42registration.dispose();43provider.dispose();44},45};46}47484950