1
>
/*---------------------------------------------------------------------------------------------
agentHostSessionType.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 { type AgentProvider } from './agentService.js';
7
>
8
>
const REMOTE_AGENT_HOST_SESSION_TYPE_PREFIX = 'remote-';
9
>
10
>
/**
11
>
* Builds the unique per-connection identifier for a remote agent host.
12
>
*
13
>
* This string is used as the resource URI scheme registered via
14
>
* `registerChatSessionContentProvider` and as the language model vendor /
15
>
* `targetChatSessionType` published by `AgentHostLanguageModelProvider`.
16
>
*/
17
>
export function remoteAgentHostSessionTypeId(connectionAuthority: string, agentProvider: AgentProvider): string {
18
return `${remoteAgentHostSessionTypeAuthorityPrefix(connectionAuthority)}${agentProvider}`;
19
}
21
>
/**
22
>
* Builds the authority-specific prefix for remote agent host session types.
23
>
*/
24
>
export function remoteAgentHostSessionTypeAuthorityPrefix(connectionAuthority: string): string {
25
return `${REMOTE_AGENT_HOST_SESSION_TYPE_PREFIX}${connectionAuthority}-`;
26
}
28
>
/**
29
>
* Returns whether the given session type uses the remote agent host scheme.
30
>
*/
31
>
export function isRemoteAgentHostSessionType(sessionType: string): boolean {
32
return sessionType.startsWith(REMOTE_AGENT_HOST_SESSION_TYPE_PREFIX);
33
}
35
>
/**
36
>
* Finds the best matching remote agent host authority from a known candidate set.
37
>
*
38
>
* Remote session types are formatted as `remote-{authority}-{provider}` and
39
>
* authorities may contain `-`, so callers should match against the full set of
40
>
* known authorities instead of splitting the session type.
41
>
*/
42
>
export function findRemoteAgentHostSessionTypeAuthority(sessionType: string, connectionAuthorities: Iterable<string>): string | undefined {
43
if (!isRemoteAgentHostSessionType(sessionType)) {
44
return undefined;