src/vs/platform/agentHost/common/openSessionLink.ts

92 LOC · 90 covered · 2 uncovered · 22 ranges · 2809 concepts · 14 introducers · 1297 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 > /*--------------------------------------------------------------------------------------------- openSessionLink.ts ×7
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 > import { AgentSession } from './agentService.js';
8 >
9 > /**
10 > * Dedicated URI scheme for "open this session" links surfaced in agent/tool
11 > * output (e.g. the `create_session` server tool result). A single stable
12 > * scheme keeps the chat markdown allow-list minimal and lets the Agents window
13 > * register one opener, rather than allow-listing every dynamic provider scheme.
14 > *
15 > * Shape: `agent-host-session://<provider>/<rawSessionId>` — the backend session
16 > * URI (`<provider>:/<rawSessionId>`) rearranged so the provider is the
17 > * authority and the id is the path.
18 > */
19 > export const AGENT_HOST_SESSION_LINK_SCHEME = 'agent-host-session';
20 >
21 > /** Name of the `create_session` server tool. */
22 > export const CREATE_SESSION_TOOL_NAME = 'create_session';
23 >
24 > /** Name of the `create_chat` server tool. */
25 > export const CREATE_CHAT_TOOL_NAME = 'create_chat';
26 >
27 > /** Name of the `send_message` server tool. */
28 > export const SEND_MESSAGE_TOOL_NAME = 'send_message';
29 >
30 > /**
31 > * Whether {@link toolName} (as seen on a tool call) matches {@link bareName}.
32 > * Accepts the bare name and a transport prefix such as Claude's
33 > * `mcp__<server>__<name>` (matched as a `__`-delimited suffix).
34 > */
35 > function matchesToolName(toolName: string, bareName: string): boolean { openSessionLink.ts ×1
36 > return toolName === bareName || toolName.endsWith(`__${bareName}`);
37 > }
39 > /** Whether {@link toolName} refers to the `create_session` server tool. */
40 > export function isCreateSessionTool(toolName: string): boolean {
41 > return matchesToolName(toolName, CREATE_SESSION_TOOL_NAME); openSessionLink.ts ×1
42 > }
44 > /** Whether {@link toolName} refers to the `create_chat` server tool. */
45 > export function isCreateChatTool(toolName: string): boolean {
46 > return matchesToolName(toolName, CREATE_CHAT_TOOL_NAME); openSessionLink.ts ×1
47 > }
49 > /** Whether {@link toolName} refers to the `send_message` server tool. */
50 > export function isSendMessageTool(toolName: string): boolean {
51 > return matchesToolName(toolName, SEND_MESSAGE_TOOL_NAME); openSessionLink.ts ×1
52 > }
54 > /** Builds an {@link AGENT_HOST_SESSION_LINK_SCHEME} link for a backend session URI. */
55 > export function buildOpenSessionLinkUri(backendSession: URI | string, chatId?: string): string {
56 > const provider = AgentSession.provider(backendSession); openSessionLink.ts ×2
57 > const rawId = AgentSession.id(backendSession);
58 > if (!provider) {
59 throw new Error(`Cannot build open-session link: missing provider in ${backendSession.toString()}`);
60 }
61 > const base = URI.from({ scheme: AGENT_HOST_SESSION_LINK_SCHEME, authority: provider, path: `/${rawId}` }).toString(); openSessionLink.ts ×2
62 > return chatId ? `${base}?chat=${encodeURIComponent(chatId)}` : base;
63 > }
65 > /**
66 > * Recovers the backend session URI from an {@link AGENT_HOST_SESSION_LINK_SCHEME}
67 > * link, or `undefined` when the URI is not such a link.
68 > */
69 > export function parseOpenSessionLinkUri(uri: URI | string): URI | undefined {
70 > const parsed = typeof uri === 'string' ? URI.parse(uri) : uri; openSessionLink.ts ×1
71 > if (parsed.scheme !== AGENT_HOST_SESSION_LINK_SCHEME || !parsed.authority) {
72 > return undefined; openSessionLink.ts ×1
73 > }
74 > const rawId = parsed.path.replace(/^\//, ''); openSessionLink.ts ×1
75 > if (!rawId) {
76 > return undefined; openSessionLink.ts ×1
77 > }
78 > return AgentSession.uri(parsed.authority, rawId); openSessionLink.ts ×1
79 > }
81 > /**
82 > * Recovers the target chat id carried by an {@link AGENT_HOST_SESSION_LINK_SCHEME}
83 > * link (from `create_chat`), or `undefined` when the link targets a whole session.
84 > */
85 > export function parseOpenSessionLinkChatId(uri: URI | string): string | undefined {
86 > const parsed = typeof uri === 'string' ? URI.parse(uri) : uri; openSessionLink.ts ×2
87 > if (parsed.scheme !== AGENT_HOST_SESSION_LINK_SCHEME) {
88 > return undefined; openSessionLink.ts ×1
89 > }
90 > const match = /(?:^|&)chat=([^&]+)/.exec(parsed.query); openSessionLink.ts ×1
91 > return match ? decodeURIComponent(match[1]) : undefined; openSessionLink.ts ×2
92 > }