1
>
/*---------------------------------------------------------------------------------------------
agentClientUri.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 { URI } from '../../../base/common/uri.js';
7
>
8
>
/**
9
>
* The URI scheme for accessing client-side files from the agent host.
10
>
*
11
>
* This is the inverse of {@link AGENT_HOST_SCHEME}: the agent host uses
12
>
* this scheme to address files that live on the connected client.
13
>
*
14
>
* ```
15
>
* vscode-agent-client://[clientId]/[originalScheme]/[originalAuthority]/[originalPath]
16
>
* ```
17
>
*
18
>
* For example, `file:///Users/user/plugins/my-plugin` on client `client-1` becomes:
19
>
* ```
20
>
* vscode-agent-client://client-1/file/-/Users/user/plugins/my-plugin
21
>
* ```
22
>
*/
23
>
export const AGENT_CLIENT_SCHEME = 'vscode-agent-client';
24
>
25
>
/**
26
>
* Wraps a client-side URI into a {@link AGENT_CLIENT_SCHEME} URI that
27
>
* can be resolved through the agent host's client filesystem provider.
28
>
*
29
>
* Opaque-path URIs (e.g. `untitled:Untitled-1`, where `path` has no
30
>
* leading `/`) are marked with a `!` suffix on the encoded scheme slot
31
>
* so the decoder can restore them faithfully. Scheme names are
32
>
* alphanumeric + `+.-` per RFC 3986, so `!` cannot collide.
33
>
*
34
>
* @param originalUri The URI on the client (e.g. `file:///path`)
35
>
* @param clientId The client identifier (from the protocol `clientId`)
36
>
*/
37
>
export function toAgentClientUri(originalUri: URI, clientId: string): URI {
38
const originalAuthority = originalUri.authority || '-';
39
const isOpaque = originalUri.path.length > 0 && !originalUri.path.startsWith('/');