1
>
/*---------------------------------------------------------------------------------------------
openSessionLink.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
>
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 {
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);
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);
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);
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);
57
const rawId = AgentSession.id(backendSession);