1
>
/*---------------------------------------------------------------------------------------------
agentHostUri.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 { decodeBase64, encodeBase64, VSBuffer } from '../../../base/common/buffer.js';
7
>
import { Schemas } from '../../../base/common/network.js';
8
>
import { URI } from '../../../base/common/uri.js';
9
>
import type { ResourceLabelFormatter } from '../../label/common/label.js';
10
>
11
>
/**
12
>
* The URI scheme for accessing files on a remote agent host.
13
>
*
14
>
* The original file path is kept verbatim as the URI path so resource
15
>
* labels, language detection, and path comparisons see a real path. The
16
>
* original scheme, authority, and query are carried in a single
17
>
* url-safe-base64 `_ah` query parameter so any remote resource can be
18
>
* represented without assuming `file://`:
19
>
*
20
>
* ```
21
>
* vscode-agent-host://[connectionAuthority][originalPath]?_ah=[meta]#[originalFragment]
22
>
* ```
23
>
*
24
>
* where `meta` is {@link IAgentHostUriMeta} as url-safe-base64-encoded
25
>
* JSON. Encoding the metadata as a single opaque parameter (rather than
26
>
* raw JSON) keeps the query a well-formed parameter list, so unrelated
27
>
* query parameters such as `vscodeLinkType` can coexist on the wrapped
28
>
* URI without corrupting the metadata. For example,
29
>
* `file:///home/user/foo.ts` on remote `my-server` becomes:
30
>
* ```
31
>
* vscode-agent-host://my-server/home/user/foo.ts?_ah=eyJzY2hlbWUiOiJmaWxlIn0
32
>
* ```
33
>
*/
34
>
export const AGENT_HOST_SCHEME = 'vscode-agent-host';
35
>
36
>
/**
37
>
* Query parameter that carries the {@link IAgentHostUriMeta} payload.
38
>
*/
39
>
const AGENT_HOST_META_PARAM = '_ah';
40
>
41
>
/**
42
>
* Metadata carried in the query of a {@link AGENT_HOST_SCHEME} URI so the
43
>
* original URI can be reconstructed while keeping the path label-friendly.
44
>
*/
45
>
interface IAgentHostUriMeta {
46
>
/** Original URI scheme (e.g. `file`, `git-blob`). */
47
>
readonly scheme: string;
48
>
/** Original URI authority, omitted when empty. */
49
>
readonly authority?: string;
50
>
/** Original URI query, omitted when empty. */
51
>
readonly query?: string;
52
>
}
53
>
54
>
/**
55
>
* Wraps a remote URI into a {@link AGENT_HOST_SCHEME} URI that can be
56
>
* resolved through the agent host filesystem provider.
57
>
*
58
>
* @param originalUri The URI on the remote (e.g. `file:///path` or
59
>
* `agenthost-content:///sessionId/...`)
60
>
* @param connectionAuthority The sanitized connection identifier used as
61
>
* the URI authority (from {@link agentHostAuthority}).
62
>
*/
63
>
export function toAgentHostUri(originalUri: URI, connectionAuthority: string): URI {
64
if (connectionAuthority === 'local' && originalUri.scheme === Schemas.file) {
65
return originalUri;