import { IPosition } from "../../../../../editor/common/core/position.js"; import { IRange, Range } from "../../../../../editor/common/core/range.js"; import { OffsetRange } from "../../../../../editor/common/core/ranges/offsetRange.js"; import { IParsedChatRequest, IParsedChatRequestPart } from "../requestParser/chatParserTypes.js"; import { IChatRequestVariableEntry } from "./chatVariableEntries.js"; import { IDynamicVariable } from "./chatVariables.js"; /** * The character that stands for an inline attachment pill in the chat input. * A pill occupies exactly one character of the input text, so moving the * cursor, selecting, and deleting treat it like any other character. */ export declare const INLINE_ATTACHMENT_ANCHOR = "\uFFFC"; /** * The prefix of the text that stands for an attachment that has no text of its * own, such as a dropped file or a pasted image. It matches the text that * mentioning an attachment with `#` inserts. */ export declare const INLINE_ATTACHMENT_REFERENCE_PREFIX = "attachment:"; /** The prefix of the id of an attachment for a GitHub issue or pull request, which the link to it follows. */ export declare const GITHUB_CONTEXT_ATTACHMENT_ID_PREFIX = "github-context:"; /** * The text that mentions an attachment in the prompt, such as * `#attachment:index.ts`. A reference cannot span lines, so line breaks in the * name, as of a multi-line terminal command, become spaces. */ export declare function getAttachmentMention(name: string, leader?: string): string; /** An inline attachment pill in the chat input. */ export interface IInlineAttachmentAnchor { /** The offset of the pill's {@link INLINE_ATTACHMENT_ANCHOR} in the input. */ readonly offset: number; /** The text the pill stands for in the prompt, such as `#file:index.ts`. */ readonly text: string; /** The reference to {@link text}, if any. Its range is ignored. */ readonly reference?: IDynamicVariable; /** * What the prompt sent to the model says in place of the pill, see * {@link getAttachmentPromptText}. It is the {@link IDynamicVariable.promptText} * of the pill's reference, and is unset for the prompt that is persisted. */ readonly promptText?: string; } /** * The prompt that a chat input with inline attachment pills represents: the * input with every pill replaced by the text it stands for, exactly as if that * text had been typed. The prompt is what is submitted and persisted, so its * consumers never encounter an {@link INLINE_ATTACHMENT_ANCHOR}. */ export interface IInlineAttachmentProjection { /** The prompt text. */ readonly text: string; /** The input's references followed by the pills' references, with ranges in {@link text}. */ readonly references: readonly IDynamicVariable[]; /** The text that replaces each anchor in the input, in order, to turn the input into the prompt. */ readonly replacements: readonly { readonly inputOffset: number; readonly text: string; }[]; /** Maps an offset in the input to the prompt. Offsets on either side of a pill map to either side of its text. */ toPromptOffset(inputOffset: number): number; /** Maps a range in the input to the prompt. */ toPromptRange(inputRange: IRange): Range; /** Maps a range in the prompt back to the input. A range that ends inside a pill's text covers the pill. */ toInputRange(promptRange: IRange): Range; } /** * Projects a chat input with inline attachment pills onto the prompt it * represents. A pill's text is separated from adjacent text with a space so it * parses as its own token. An {@link INLINE_ATTACHMENT_ANCHOR} without a pill * is dropped from the prompt. * * @returns `undefined` when the input contains no anchor, in which case the * input already is the prompt. */ export declare function projectInlineAttachments(input: string, anchors: readonly IInlineAttachmentAnchor[], references: readonly IDynamicVariable[]): IInlineAttachmentProjection | undefined; /** Makes a range relative to `origin`, as when the text that starts at `origin` is copied. */ export declare function toRelativeRange(range: IRange, origin: IPosition): Range; /** Makes a range made relative by {@link toRelativeRange} absolute again, as when copied text is pasted at `origin`. */ export declare function fromRelativeRange(range: IRange, origin: IPosition): Range; /** Whether an attachment can be shown as a pill inline with the prompt. */ export declare function canShowAttachmentInline(attachment: IChatRequestVariableEntry): boolean; /** * What the prompt sent to the model says in place of the pill of an attachment: * the attachment's name and, when it has one, its location, as a Markdown link * such as `[index.ts](file:///src/index.ts)`. The attachment itself is attached * to the request once, however many pills mention it. */ export declare function getAttachmentPromptText(attachment: IChatRequestVariableEntry): string; /** The name of an attachment, as its pill shows it. */ export declare function getAttachmentLabel(attachment: IChatRequestVariableEntry): string; /** * Whether an attachment without a pill gets one inserted into the prompt when * inline attachments are enabled. An attachment with a range is derived from * text in the prompt, which is what becomes its pill. */ export declare function isInlineAttachmentCandidate(attachment: IChatRequestVariableEntry): boolean; /** * Whether the pill of an attachment opens something when it is activated, such * as a file, a folder, a commit, or the Problems view. This matches the pills * shown above the prompt: tools only have a hover, and context items, such as * pull requests, open only when their provider gives them a command. */ export declare function canOpenAttachment(attachment: IChatRequestVariableEntry): boolean; /** * The attachments of a submitted request that are shown as pills inline with * its text, by the index of the part of the request that stands for them. * Parts that stand for no attachment are left out, as are parts in code, where * Markdown renders them as text. * * @param text The text of the request, which tells where its code is. */ export declare function getInlineRequestAttachments(parts: readonly IParsedChatRequestPart[], variables: readonly IChatRequestVariableEntry[], text?: string): Map; /** * Recovers the mentions of a request's attachments from its text, for a * request whose history kept its text and attachments but not its references, * as an agent host's history does, which keeps the prompt sent to the model. * A mention of an attachment that is outside code becomes a reference to the * attachment again: what the prompt says in its place, see * {@link getAttachmentPromptText}, its mention by name, see * {@link getAttachmentMention}, the reference that a completion inserts for a * file or folder, or the link of a GitHub issue or pull request. Mentions of * attachments that share a name are bound to them in order. */ export declare function recoverAttachmentMentions(message: IParsedChatRequest, variables: readonly IChatRequestVariableEntry[]): IParsedChatRequest; /** * The ranges of a prompt that Markdown renders as code: code blocks and code * spans, in which a mention renders as its text rather than as a pill. */ export declare function getMarkdownCodeRanges(text: string): OffsetRange[];