36
*/
37
export function toAgentClientUri(originalUri: URI, clientId: string): URI {
39
>
const isOpaque = originalUri.path.length > 0 && !originalUri.path.startsWith('/');
40
>
const schemeSlot = isOpaque ? `${originalUri.scheme}!` : originalUri.scheme;
41
>
// Insert a synthetic '/' for opaque paths so the encoded URI is well-formed.
42
>
// The decoder strips it after detecting the opaque marker on the scheme slot.
43
>
const pathBody = isOpaque ? `/${originalUri.path}` : originalUri.path;
44
>
return URI.from({
45
>
scheme: AGENT_CLIENT_SCHEME,
46
>
authority: clientId,
47
>
path: `/${schemeSlot}/${originalAuthority}${pathBody}`,
48
>
query: originalUri.query || undefined,
49
>
fragment: originalUri.fragment || undefined,
50
>
});
51
>
}
52
53
/**