Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6811,7 +6811,7 @@ export class AgentHostSessionHandler extends Disposable implements IChatSessionC
}

resolveChatResponseUri(_sessionResource: URI, href: string, _kind: 'link' | 'image'): string {
return rewriteAgentHostLinkTarget(href, this._config.connectionAuthority);
return rewriteAgentHostLinkTarget(href, this._config.connectionAuthority, this._config.connection.resourceUris);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2126,7 +2126,7 @@ function normalizeFileUriSelection(uri: URI, href: string): URI {
}

/** Wraps an absolute path or internal URI target for the owning Agent Host connection. */
export function rewriteAgentHostLinkTarget(href: string, connectionAuthority: string): string {
export function rewriteAgentHostLinkTarget(href: string, connectionAuthority: string, resourceUris: IAgentHostResourceUriMapper = createAgentHostResourceUriMapper(connectionAuthority)): string {
let parsed = parseAbsoluteFileLinkTarget(href);
if (!parsed) {
try {
Expand All @@ -2146,7 +2146,7 @@ export function rewriteAgentHostLinkTarget(href: string, connectionAuthority: st

let agentHostUri: URI;
try {
agentHostUri = toAgentHostUri(parsed, connectionAuthority);
agentHostUri = resourceUris.fromAgentHost(parsed);
Comment thread
dileepyavan marked this conversation as resolved.
} catch {
return href;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { ILogService, NullLogService } from '../../../../../../platform/log/comm
import { IConfigurationService } from '../../../../../../platform/configuration/common/configuration.js';
import { IAgentCreateSessionConfig, IAgentHostService, IAgentSessionMetadata, AgentSession } from '../../../../../../platform/agentHost/common/agentService.js';
import type { ChatInputRequestWithPlanReview } from '../../../../../../platform/agentHost/common/agentHostPlanReview.js';
import { createAgentHostResourceUriMapper, identityAgentHostResourceUriMapper, toAgentHostUri } from '../../../../../../platform/agentHost/common/agentHostUri.js';
import { agentHostAuthority, createAgentHostResourceUriMapper, fromAgentHostUri, identityAgentHostResourceUriMapper, toAgentHostUri } from '../../../../../../platform/agentHost/common/agentHostUri.js';
import { AgentFeedbackAttachmentDisplayKind, AgentFeedbackAttachmentMetadataKey } from '../../../../../../platform/agentHost/common/meta/agentFeedbackAttachments.js';
import { VSCODE_EPHEMERAL_SESSION_META_KEY } from '../../../../../../platform/agentHost/common/meta/agentEphemeralSessionMeta.js';
import { getElementAttachmentCorrelationId, toElementAttachmentMeta } from '../../../../../../platform/agentHost/common/meta/agentElementAttachments.js';
Expand Down Expand Up @@ -1271,6 +1271,61 @@ suite('AgentHostChatContribution', () => {

});

suite('response resource links', () => {
test('uses the WSL connection for file links despite a local session authority', () => {
const { sessionHandler, agentHostService } = createContribution(disposables);
const authority = agentHostAuthority('vscode-remote://wsl+Ubuntu');
agentHostService.resourceUris = createAgentHostResourceUriMapper(authority);
const session = URI.parse('agent-host-copilot:/session');
const file = URI.file('/home/user/project/src/file.ts').with({ fragment: 'L42,7' });
const targets = [
'/home/user/project/src/file.ts:42:7',
'file:///home/user/project/src/file.ts#L42,7',
];

assert.deepStrictEqual(targets.map(href => {
const resolved = URI.parse(sessionHandler.resolveChatResponseUri(session, href, 'link'));
return { resolved: resolved.toString(), hostUri: fromAgentHostUri(resolved).toString() };
}), targets.map(() => ({
resolved: toAgentHostUri(file, authority).toString(),
hostUri: file.toString(),
})));
});

test('uses the WSL connection for image paths and preserves encoded path characters', () => {
const { sessionHandler, agentHostService } = createContribution(disposables);
const authority = agentHostAuthority('vscode-remote://wsl+Ubuntu');
agentHostService.resourceUris = createAgentHostResourceUriMapper(authority);
const session = URI.parse('agent-host-copilot:/session');
const image = URI.file('/home/user/my project/image.png');

assert.strictEqual(
sessionHandler.resolveChatResponseUri(session, '/home/user/my%20project/image.png', 'image'),
toAgentHostUri(image, authority).toString(),
);
});

test('preserves local file links and external or already mapped links', () => {
const { sessionHandler, agentHostService } = createContribution(disposables);
const session = URI.parse('agent-host-copilot:/session');
const local = sessionHandler.resolveChatResponseUri(session, '/project/file.ts:42', 'link');
const authority = agentHostAuthority('vscode-remote://wsl+Ubuntu');
agentHostService.resourceUris = createAgentHostResourceUriMapper(authority);
const mapped = toAgentHostUri(URI.file('/home/user/file.ts'), authority).toString();
const external = 'https://example.com/file.ts';

assert.deepStrictEqual({
local,
mapped: sessionHandler.resolveChatResponseUri(session, mapped, 'link'),
external: sessionHandler.resolveChatResponseUri(session, external, 'link'),
}, {
local: URI.file('/project/file.ts').with({ fragment: 'L42' }).toString(),
mapped,
external,
});
});
});

// ---- Download progress notification (editor window) -----------------

suite('download progress', () => {
Expand Down
Loading