chrome-devtools-frontend
Version:
Chrome DevTools UI
63 lines (52 loc) • 2.28 kB
text/typescript
// Copyright 2026 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import * as SDK from '../../../core/sdk/sdk.js';
import type * as Bindings from '../../bindings/bindings.js';
import type * as Workspace from '../../workspace/workspace.js';
import {type ContextDetail, ConversationContext} from '../agents/AiAgent.js';
import {FileFormatter} from '../data_formatters/FileFormatter.js';
export class FileContext extends ConversationContext<Workspace.UISourceCode.UISourceCode> {
constructor(file: Workspace.UISourceCode.UISourceCode,
debuggerWorkspaceBinding?: Bindings.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding) {
super();
this.
this.
}
/**
* Resolves the security origin of a given UISourceCode.
* Prefers the project security origin, falling back to the origin of the file URL.
*/
static originForUISourceCode(file: Workspace.UISourceCode.UISourceCode): SDK.SecurityOrigin.SecurityOrigin {
return file.project()?.securityOrigin?.() ?? SDK.SecurityOrigin.SecurityOrigin.create(file.url());
}
/**
* Returns the security origin of the project containing the file, falling
* back to the origin derived from the file URL.
*/
override getOrigin(): SDK.SecurityOrigin.SecurityOrigin {
return FileContext.originForUISourceCode(this.
}
override getItem(): Workspace.UISourceCode.UISourceCode {
return this.
}
override getTitle(): string {
return this.
}
override async getPromptDetails(): Promise<string|null> {
return `
}
override async getUserFacingDetails(): Promise<[ContextDetail, ...ContextDetail[]]|null> {
return [
{
title: 'Selected file',
text: new FileFormatter(this.
},
];
}
override async refresh(): Promise<void> {
await this.
}
}