diff --git a/docs/genaisrc/genaiscript.d.ts b/docs/genaisrc/genaiscript.d.ts index a0a2d39fdf..f4e747fb26 100644 --- a/docs/genaisrc/genaiscript.d.ts +++ b/docs/genaisrc/genaiscript.d.ts @@ -659,6 +659,67 @@ interface ChatParticipant { options: ChatParticipantOptions } +/** + * A comment thread + */ +interface CommentThread { + filename: string + source: string + line: number + comments: Comment[] + label?: string + resolved?: boolean +} + +/** + * A comment + */ +interface Comment { + /** + * The human-readable comment body + */ + body: string + + /** + * The author of the comment + */ + author: { name: string } + + /** + * Optional reactions of the comment + */ + reactions?: CommentReaction[] + + /** + * Optional label describing the comment + * Label will be rendered next to authorName if exists. + */ + label?: string + + /** + * Optional timestamp that will be displayed in comments. + * The date will be formatted according to the user's locale and settings. + */ + timestamp?: string +} + +interface CommentReaction { + /** + * The human-readable label for the reaction + */ + label: string + + /** + * The number of users who have reacted to this reaction + */ + count: number + + /** + * Whether the author of the comment has reacted to this reaction + */ + authorHasReacted: boolean +} + /** * A set of text extracted from the context of the prompt execution */ @@ -692,6 +753,11 @@ interface ExpansionVariables { * Root prompt generation context */ generator: ChatGenerationContext + + /** + * Comment threads generated in the context of this prompt + */ + comments: CommentThread[] } type MakeOptional = Partial> & Omit diff --git a/genaisrc/genaiscript.d.ts b/genaisrc/genaiscript.d.ts index a0a2d39fdf..f4e747fb26 100644 --- a/genaisrc/genaiscript.d.ts +++ b/genaisrc/genaiscript.d.ts @@ -659,6 +659,67 @@ interface ChatParticipant { options: ChatParticipantOptions } +/** + * A comment thread + */ +interface CommentThread { + filename: string + source: string + line: number + comments: Comment[] + label?: string + resolved?: boolean +} + +/** + * A comment + */ +interface Comment { + /** + * The human-readable comment body + */ + body: string + + /** + * The author of the comment + */ + author: { name: string } + + /** + * Optional reactions of the comment + */ + reactions?: CommentReaction[] + + /** + * Optional label describing the comment + * Label will be rendered next to authorName if exists. + */ + label?: string + + /** + * Optional timestamp that will be displayed in comments. + * The date will be formatted according to the user's locale and settings. + */ + timestamp?: string +} + +interface CommentReaction { + /** + * The human-readable label for the reaction + */ + label: string + + /** + * The number of users who have reacted to this reaction + */ + count: number + + /** + * Whether the author of the comment has reacted to this reaction + */ + authorHasReacted: boolean +} + /** * A set of text extracted from the context of the prompt execution */ @@ -692,6 +753,11 @@ interface ExpansionVariables { * Root prompt generation context */ generator: ChatGenerationContext + + /** + * Comment threads generated in the context of this prompt + */ + comments: CommentThread[] } type MakeOptional = Partial> & Omit diff --git a/packages/core/src/cache.ts b/packages/core/src/cache.ts index e9ddc0f408..87750aa330 100644 --- a/packages/core/src/cache.ts +++ b/packages/core/src/cache.ts @@ -27,18 +27,16 @@ export class JSONLineCache extends EventTarget { super() // Initialize EventTarget } - /** - * Factory method to create or retrieve an existing cache by name. - * Sanitizes the name to ensure it is a valid identifier. - * @param name - The name of the cache - * @returns An instance of JSONLineCache - */ - static byName(name: string): JSONLineCache { - name = name.replace(/[^a-z0-9_]/gi, "_") // Sanitize name + static byName( + name: string, + options?: { snapshot?: boolean } + ): JSONLineCache { + const { snapshot } = options || {} + name = name.replace(/[^a-z0-9_]/gi, "_") const key = "cacheKV." + name - if (host.userState[key]) return host.userState[key] // Return if exists + if (!snapshot && host.userState[key]) return host.userState[key] const r = new JSONLineCache(name) - host.userState[key] = r + if (!snapshot) host.userState[key] = r return r } diff --git a/packages/core/src/comments.ts b/packages/core/src/comments.ts new file mode 100644 index 0000000000..38af1b4631 --- /dev/null +++ b/packages/core/src/comments.ts @@ -0,0 +1,22 @@ +import { JSONLineCache } from "./cache" +import { COMMENTS_CACHE } from "./constants" + +export interface CommentKey { + uri: string + line: number + source: string +} + +export function commentsCache(options?: { snapshot?: boolean }) { + const cache = JSONLineCache.byName( + COMMENTS_CACHE, + options + ) + return cache +} + +export async function commentsForSource(source: string) { + const cache = commentsCache() + const entries = await cache.entries() + return entries.map(({ val }) => val).filter((c) => c.source === source) +} diff --git a/packages/core/src/constants.ts b/packages/core/src/constants.ts index 4fb4ee3297..a3fa3aff4d 100644 --- a/packages/core/src/constants.ts +++ b/packages/core/src/constants.ts @@ -216,6 +216,8 @@ export const GITHUB_TOKEN = "GITHUB_TOKEN" export const AI_REQUESTS_CACHE = "airequests" export const CHAT_CACHE = "chat" export const GITHUB_PULL_REQUEST_REVIEWS_CACHE = "prr" +export const GITHUB_PULLREQUEST_REVIEW_COMMENT_LINE_DISTANCE = 5 +export const COMMENTS_CACHE = "comments" export const GITHUB_PULL_REQUEST_REVIEW_COMMENT_LINE_DISTANCE = 5 export const PLACEHOLDER_API_BASE = "" diff --git a/packages/core/src/genaisrc/genaiscript.d.ts b/packages/core/src/genaisrc/genaiscript.d.ts index a0a2d39fdf..f4e747fb26 100644 --- a/packages/core/src/genaisrc/genaiscript.d.ts +++ b/packages/core/src/genaisrc/genaiscript.d.ts @@ -659,6 +659,67 @@ interface ChatParticipant { options: ChatParticipantOptions } +/** + * A comment thread + */ +interface CommentThread { + filename: string + source: string + line: number + comments: Comment[] + label?: string + resolved?: boolean +} + +/** + * A comment + */ +interface Comment { + /** + * The human-readable comment body + */ + body: string + + /** + * The author of the comment + */ + author: { name: string } + + /** + * Optional reactions of the comment + */ + reactions?: CommentReaction[] + + /** + * Optional label describing the comment + * Label will be rendered next to authorName if exists. + */ + label?: string + + /** + * Optional timestamp that will be displayed in comments. + * The date will be formatted according to the user's locale and settings. + */ + timestamp?: string +} + +interface CommentReaction { + /** + * The human-readable label for the reaction + */ + label: string + + /** + * The number of users who have reacted to this reaction + */ + count: number + + /** + * Whether the author of the comment has reacted to this reaction + */ + authorHasReacted: boolean +} + /** * A set of text extracted from the context of the prompt execution */ @@ -692,6 +753,11 @@ interface ExpansionVariables { * Root prompt generation context */ generator: ChatGenerationContext + + /** + * Comment threads generated in the context of this prompt + */ + comments: CommentThread[] } type MakeOptional = Partial> & Omit diff --git a/packages/core/src/promptrunner.ts b/packages/core/src/promptrunner.ts index a966574cf2..25ed2b917b 100644 --- a/packages/core/src/promptrunner.ts +++ b/packages/core/src/promptrunner.ts @@ -22,6 +22,7 @@ import { validateJSONWithSchema } from "./schema" import { YAMLParse } from "./yaml" import { expandTemplate } from "./expander" import { resolveLanguageModel } from "./lm" +import { commentsCache, commentsForSource } from "./comments" async function resolveExpansionVars( project: Project, @@ -57,6 +58,7 @@ async function resolveExpansionVars( secrets[secret] = value } else trace.error(`secret \`${secret}\` not found`) } + const comments = await commentsForSource(template.id) const res: Partial = { dir: ".", files, @@ -67,6 +69,7 @@ async function resolveExpansionVars( }, vars: attrs, secrets, + comments, } return res } diff --git a/packages/core/src/types/prompt_template.d.ts b/packages/core/src/types/prompt_template.d.ts index 026536bf9b..394f8fc598 100644 --- a/packages/core/src/types/prompt_template.d.ts +++ b/packages/core/src/types/prompt_template.d.ts @@ -626,6 +626,67 @@ interface ChatParticipant { options: ChatParticipantOptions } +/** + * A comment thread + */ +interface CommentThread { + filename: string + source: string + line: number + comments: Comment[] + label?: string + resolved?: boolean +} + +/** + * A comment + */ +interface Comment { + /** + * The human-readable comment body + */ + body: string + + /** + * The author of the comment + */ + author: { name: string } + + /** + * Optional reactions of the comment + */ + reactions?: CommentReaction[] + + /** + * Optional label describing the comment + * Label will be rendered next to authorName if exists. + */ + label?: string + + /** + * Optional timestamp that will be displayed in comments. + * The date will be formatted according to the user's locale and settings. + */ + timestamp?: string +} + +interface CommentReaction { + /** + * The human-readable label for the reaction + */ + label: string + + /** + * The number of users who have reacted to this reaction + */ + count: number + + /** + * Whether the author of the comment has reacted to this reaction + */ + authorHasReacted: boolean +} + /** * A set of text extracted from the context of the prompt execution */ @@ -659,6 +720,11 @@ interface ExpansionVariables { * Root prompt generation context */ generator: ChatGenerationContext + + /** + * Comment threads generated in the context of this prompt + */ + comments: CommentThread[] } type MakeOptional = Partial> & Omit diff --git a/packages/sample/genaisrc/genaiscript.d.ts b/packages/sample/genaisrc/genaiscript.d.ts index a0a2d39fdf..f4e747fb26 100644 --- a/packages/sample/genaisrc/genaiscript.d.ts +++ b/packages/sample/genaisrc/genaiscript.d.ts @@ -659,6 +659,67 @@ interface ChatParticipant { options: ChatParticipantOptions } +/** + * A comment thread + */ +interface CommentThread { + filename: string + source: string + line: number + comments: Comment[] + label?: string + resolved?: boolean +} + +/** + * A comment + */ +interface Comment { + /** + * The human-readable comment body + */ + body: string + + /** + * The author of the comment + */ + author: { name: string } + + /** + * Optional reactions of the comment + */ + reactions?: CommentReaction[] + + /** + * Optional label describing the comment + * Label will be rendered next to authorName if exists. + */ + label?: string + + /** + * Optional timestamp that will be displayed in comments. + * The date will be formatted according to the user's locale and settings. + */ + timestamp?: string +} + +interface CommentReaction { + /** + * The human-readable label for the reaction + */ + label: string + + /** + * The number of users who have reacted to this reaction + */ + count: number + + /** + * Whether the author of the comment has reacted to this reaction + */ + authorHasReacted: boolean +} + /** * A set of text extracted from the context of the prompt execution */ @@ -692,6 +753,11 @@ interface ExpansionVariables { * Root prompt generation context */ generator: ChatGenerationContext + + /** + * Comment threads generated in the context of this prompt + */ + comments: CommentThread[] } type MakeOptional = Partial> & Omit diff --git a/packages/sample/genaisrc/node/genaiscript.d.ts b/packages/sample/genaisrc/node/genaiscript.d.ts index a0a2d39fdf..f4e747fb26 100644 --- a/packages/sample/genaisrc/node/genaiscript.d.ts +++ b/packages/sample/genaisrc/node/genaiscript.d.ts @@ -659,6 +659,67 @@ interface ChatParticipant { options: ChatParticipantOptions } +/** + * A comment thread + */ +interface CommentThread { + filename: string + source: string + line: number + comments: Comment[] + label?: string + resolved?: boolean +} + +/** + * A comment + */ +interface Comment { + /** + * The human-readable comment body + */ + body: string + + /** + * The author of the comment + */ + author: { name: string } + + /** + * Optional reactions of the comment + */ + reactions?: CommentReaction[] + + /** + * Optional label describing the comment + * Label will be rendered next to authorName if exists. + */ + label?: string + + /** + * Optional timestamp that will be displayed in comments. + * The date will be formatted according to the user's locale and settings. + */ + timestamp?: string +} + +interface CommentReaction { + /** + * The human-readable label for the reaction + */ + label: string + + /** + * The number of users who have reacted to this reaction + */ + count: number + + /** + * Whether the author of the comment has reacted to this reaction + */ + authorHasReacted: boolean +} + /** * A set of text extracted from the context of the prompt execution */ @@ -692,6 +753,11 @@ interface ExpansionVariables { * Root prompt generation context */ generator: ChatGenerationContext + + /** + * Comment threads generated in the context of this prompt + */ + comments: CommentThread[] } type MakeOptional = Partial> & Omit diff --git a/packages/sample/genaisrc/python/genaiscript.d.ts b/packages/sample/genaisrc/python/genaiscript.d.ts index a0a2d39fdf..f4e747fb26 100644 --- a/packages/sample/genaisrc/python/genaiscript.d.ts +++ b/packages/sample/genaisrc/python/genaiscript.d.ts @@ -659,6 +659,67 @@ interface ChatParticipant { options: ChatParticipantOptions } +/** + * A comment thread + */ +interface CommentThread { + filename: string + source: string + line: number + comments: Comment[] + label?: string + resolved?: boolean +} + +/** + * A comment + */ +interface Comment { + /** + * The human-readable comment body + */ + body: string + + /** + * The author of the comment + */ + author: { name: string } + + /** + * Optional reactions of the comment + */ + reactions?: CommentReaction[] + + /** + * Optional label describing the comment + * Label will be rendered next to authorName if exists. + */ + label?: string + + /** + * Optional timestamp that will be displayed in comments. + * The date will be formatted according to the user's locale and settings. + */ + timestamp?: string +} + +interface CommentReaction { + /** + * The human-readable label for the reaction + */ + label: string + + /** + * The number of users who have reacted to this reaction + */ + count: number + + /** + * Whether the author of the comment has reacted to this reaction + */ + authorHasReacted: boolean +} + /** * A set of text extracted from the context of the prompt execution */ @@ -692,6 +753,11 @@ interface ExpansionVariables { * Root prompt generation context */ generator: ChatGenerationContext + + /** + * Comment threads generated in the context of this prompt + */ + comments: CommentThread[] } type MakeOptional = Partial> & Omit diff --git a/packages/sample/genaisrc/style/genaiscript.d.ts b/packages/sample/genaisrc/style/genaiscript.d.ts index a0a2d39fdf..f4e747fb26 100644 --- a/packages/sample/genaisrc/style/genaiscript.d.ts +++ b/packages/sample/genaisrc/style/genaiscript.d.ts @@ -659,6 +659,67 @@ interface ChatParticipant { options: ChatParticipantOptions } +/** + * A comment thread + */ +interface CommentThread { + filename: string + source: string + line: number + comments: Comment[] + label?: string + resolved?: boolean +} + +/** + * A comment + */ +interface Comment { + /** + * The human-readable comment body + */ + body: string + + /** + * The author of the comment + */ + author: { name: string } + + /** + * Optional reactions of the comment + */ + reactions?: CommentReaction[] + + /** + * Optional label describing the comment + * Label will be rendered next to authorName if exists. + */ + label?: string + + /** + * Optional timestamp that will be displayed in comments. + * The date will be formatted according to the user's locale and settings. + */ + timestamp?: string +} + +interface CommentReaction { + /** + * The human-readable label for the reaction + */ + label: string + + /** + * The number of users who have reacted to this reaction + */ + count: number + + /** + * Whether the author of the comment has reacted to this reaction + */ + authorHasReacted: boolean +} + /** * A set of text extracted from the context of the prompt execution */ @@ -692,6 +753,11 @@ interface ExpansionVariables { * Root prompt generation context */ generator: ChatGenerationContext + + /** + * Comment threads generated in the context of this prompt + */ + comments: CommentThread[] } type MakeOptional = Partial> & Omit diff --git a/packages/sample/src/aici/genaiscript.d.ts b/packages/sample/src/aici/genaiscript.d.ts index a0a2d39fdf..f4e747fb26 100644 --- a/packages/sample/src/aici/genaiscript.d.ts +++ b/packages/sample/src/aici/genaiscript.d.ts @@ -659,6 +659,67 @@ interface ChatParticipant { options: ChatParticipantOptions } +/** + * A comment thread + */ +interface CommentThread { + filename: string + source: string + line: number + comments: Comment[] + label?: string + resolved?: boolean +} + +/** + * A comment + */ +interface Comment { + /** + * The human-readable comment body + */ + body: string + + /** + * The author of the comment + */ + author: { name: string } + + /** + * Optional reactions of the comment + */ + reactions?: CommentReaction[] + + /** + * Optional label describing the comment + * Label will be rendered next to authorName if exists. + */ + label?: string + + /** + * Optional timestamp that will be displayed in comments. + * The date will be formatted according to the user's locale and settings. + */ + timestamp?: string +} + +interface CommentReaction { + /** + * The human-readable label for the reaction + */ + label: string + + /** + * The number of users who have reacted to this reaction + */ + count: number + + /** + * Whether the author of the comment has reacted to this reaction + */ + authorHasReacted: boolean +} + /** * A set of text extracted from the context of the prompt execution */ @@ -692,6 +753,11 @@ interface ExpansionVariables { * Root prompt generation context */ generator: ChatGenerationContext + + /** + * Comment threads generated in the context of this prompt + */ + comments: CommentThread[] } type MakeOptional = Partial> & Omit diff --git a/packages/sample/src/errors/genaiscript.d.ts b/packages/sample/src/errors/genaiscript.d.ts index a0a2d39fdf..f4e747fb26 100644 --- a/packages/sample/src/errors/genaiscript.d.ts +++ b/packages/sample/src/errors/genaiscript.d.ts @@ -659,6 +659,67 @@ interface ChatParticipant { options: ChatParticipantOptions } +/** + * A comment thread + */ +interface CommentThread { + filename: string + source: string + line: number + comments: Comment[] + label?: string + resolved?: boolean +} + +/** + * A comment + */ +interface Comment { + /** + * The human-readable comment body + */ + body: string + + /** + * The author of the comment + */ + author: { name: string } + + /** + * Optional reactions of the comment + */ + reactions?: CommentReaction[] + + /** + * Optional label describing the comment + * Label will be rendered next to authorName if exists. + */ + label?: string + + /** + * Optional timestamp that will be displayed in comments. + * The date will be formatted according to the user's locale and settings. + */ + timestamp?: string +} + +interface CommentReaction { + /** + * The human-readable label for the reaction + */ + label: string + + /** + * The number of users who have reacted to this reaction + */ + count: number + + /** + * Whether the author of the comment has reacted to this reaction + */ + authorHasReacted: boolean +} + /** * A set of text extracted from the context of the prompt execution */ @@ -692,6 +753,11 @@ interface ExpansionVariables { * Root prompt generation context */ generator: ChatGenerationContext + + /** + * Comment threads generated in the context of this prompt + */ + comments: CommentThread[] } type MakeOptional = Partial> & Omit diff --git a/packages/sample/src/makecode/genaiscript.d.ts b/packages/sample/src/makecode/genaiscript.d.ts index a0a2d39fdf..f4e747fb26 100644 --- a/packages/sample/src/makecode/genaiscript.d.ts +++ b/packages/sample/src/makecode/genaiscript.d.ts @@ -659,6 +659,67 @@ interface ChatParticipant { options: ChatParticipantOptions } +/** + * A comment thread + */ +interface CommentThread { + filename: string + source: string + line: number + comments: Comment[] + label?: string + resolved?: boolean +} + +/** + * A comment + */ +interface Comment { + /** + * The human-readable comment body + */ + body: string + + /** + * The author of the comment + */ + author: { name: string } + + /** + * Optional reactions of the comment + */ + reactions?: CommentReaction[] + + /** + * Optional label describing the comment + * Label will be rendered next to authorName if exists. + */ + label?: string + + /** + * Optional timestamp that will be displayed in comments. + * The date will be formatted according to the user's locale and settings. + */ + timestamp?: string +} + +interface CommentReaction { + /** + * The human-readable label for the reaction + */ + label: string + + /** + * The number of users who have reacted to this reaction + */ + count: number + + /** + * Whether the author of the comment has reacted to this reaction + */ + authorHasReacted: boolean +} + /** * A set of text extracted from the context of the prompt execution */ @@ -692,6 +753,11 @@ interface ExpansionVariables { * Root prompt generation context */ generator: ChatGenerationContext + + /** + * Comment threads generated in the context of this prompt + */ + comments: CommentThread[] } type MakeOptional = Partial> & Omit diff --git a/packages/sample/src/tla/genaiscript.d.ts b/packages/sample/src/tla/genaiscript.d.ts index a0a2d39fdf..f4e747fb26 100644 --- a/packages/sample/src/tla/genaiscript.d.ts +++ b/packages/sample/src/tla/genaiscript.d.ts @@ -659,6 +659,67 @@ interface ChatParticipant { options: ChatParticipantOptions } +/** + * A comment thread + */ +interface CommentThread { + filename: string + source: string + line: number + comments: Comment[] + label?: string + resolved?: boolean +} + +/** + * A comment + */ +interface Comment { + /** + * The human-readable comment body + */ + body: string + + /** + * The author of the comment + */ + author: { name: string } + + /** + * Optional reactions of the comment + */ + reactions?: CommentReaction[] + + /** + * Optional label describing the comment + * Label will be rendered next to authorName if exists. + */ + label?: string + + /** + * Optional timestamp that will be displayed in comments. + * The date will be formatted according to the user's locale and settings. + */ + timestamp?: string +} + +interface CommentReaction { + /** + * The human-readable label for the reaction + */ + label: string + + /** + * The number of users who have reacted to this reaction + */ + count: number + + /** + * Whether the author of the comment has reacted to this reaction + */ + authorHasReacted: boolean +} + /** * A set of text extracted from the context of the prompt execution */ @@ -692,6 +753,11 @@ interface ExpansionVariables { * Root prompt generation context */ generator: ChatGenerationContext + + /** + * Comment threads generated in the context of this prompt + */ + comments: CommentThread[] } type MakeOptional = Partial> & Omit diff --git a/packages/sample/src/vision/genaiscript.d.ts b/packages/sample/src/vision/genaiscript.d.ts index a0a2d39fdf..f4e747fb26 100644 --- a/packages/sample/src/vision/genaiscript.d.ts +++ b/packages/sample/src/vision/genaiscript.d.ts @@ -659,6 +659,67 @@ interface ChatParticipant { options: ChatParticipantOptions } +/** + * A comment thread + */ +interface CommentThread { + filename: string + source: string + line: number + comments: Comment[] + label?: string + resolved?: boolean +} + +/** + * A comment + */ +interface Comment { + /** + * The human-readable comment body + */ + body: string + + /** + * The author of the comment + */ + author: { name: string } + + /** + * Optional reactions of the comment + */ + reactions?: CommentReaction[] + + /** + * Optional label describing the comment + * Label will be rendered next to authorName if exists. + */ + label?: string + + /** + * Optional timestamp that will be displayed in comments. + * The date will be formatted according to the user's locale and settings. + */ + timestamp?: string +} + +interface CommentReaction { + /** + * The human-readable label for the reaction + */ + label: string + + /** + * The number of users who have reacted to this reaction + */ + count: number + + /** + * Whether the author of the comment has reacted to this reaction + */ + authorHasReacted: boolean +} + /** * A set of text extracted from the context of the prompt execution */ @@ -692,6 +753,11 @@ interface ExpansionVariables { * Root prompt generation context */ generator: ChatGenerationContext + + /** + * Comment threads generated in the context of this prompt + */ + comments: CommentThread[] } type MakeOptional = Partial> & Omit diff --git a/packages/vscode/src/comments.ts b/packages/vscode/src/comments.ts new file mode 100644 index 0000000000..f9bb853035 --- /dev/null +++ b/packages/vscode/src/comments.ts @@ -0,0 +1,58 @@ +import * as vscode from "vscode" +import { ExtensionState } from "./state" +import { TOOL_ID, TOOL_NAME } from "../../core/src/constants" +import { toRange } from "./edit" +import { commentsCache } from "../../core/src/comments" + +export interface CommentKey {} + +export interface CommentValue { + uri: string + source: string + range: [number, number] + comments: Comment[] + label?: string + resolved?: boolean +} + +function commentToVSCodeComment(comment: Comment): vscode.Comment { + const { reactions, timestamp, ...rest } = comment + return { + ...rest, + timestamp: new Date(timestamp), + reactions: reactions.map((r) => ({ ...r, iconPath: "" })), + mode: vscode.CommentMode.Preview, + } +} + +export function activateComments(state: ExtensionState) { + const { context } = state + const { subscriptions } = context + + const controller = vscode.comments.createCommentController( + TOOL_ID, + `${TOOL_NAME} comments` + ) + subscriptions.push(controller) + const threads: vscode.CommentThread[] = [] + + vscode.workspace.onDidChangeWorkspaceFolders(async () => { + const cache = commentsCache({ snapshot: true }) + const entries = await cache.entries() + for (const { val } of entries) { + const { filename, line, comments, label, resolved } = val + const thread = controller.createCommentThread( + state.host.toUri(filename), + toRange([line, line]), + comments.map(commentToVSCodeComment) + ) + subscriptions.push(thread) + threads.push(thread) + thread.label = label + thread.canReply = true + thread.state = resolved + ? vscode.CommentThreadState.Resolved + : vscode.CommentThreadState.Unresolved + } + }) +} diff --git a/packages/vscode/src/extension.ts b/packages/vscode/src/extension.ts index 1f7b0325ec..612aa4c50a 100644 --- a/packages/vscode/src/extension.ts +++ b/packages/vscode/src/extension.ts @@ -19,6 +19,7 @@ import { } from "../../core/src/constants" import type MarkdownIt from "markdown-it" import MarkdownItGitHubAlerts from "markdown-it-github-alerts" +import { activateComments } from "./comments" import { activateConnectionInfoTree } from "./connectioninfotree" import { updateConnectionConfiguration } from "../../core/src/connection" import { APIType } from "../../core/src/host" @@ -38,6 +39,7 @@ export async function activate(context: ExtensionContext) { activateTraceTreeDataProvider(state) activateStatusBar(state) activateDocsNotebook(state) + activateComments(state) activeTaskProvider(state) context.subscriptions.push( diff --git a/slides/genaisrc/genaiscript.d.ts b/slides/genaisrc/genaiscript.d.ts index a0a2d39fdf..f4e747fb26 100644 --- a/slides/genaisrc/genaiscript.d.ts +++ b/slides/genaisrc/genaiscript.d.ts @@ -659,6 +659,67 @@ interface ChatParticipant { options: ChatParticipantOptions } +/** + * A comment thread + */ +interface CommentThread { + filename: string + source: string + line: number + comments: Comment[] + label?: string + resolved?: boolean +} + +/** + * A comment + */ +interface Comment { + /** + * The human-readable comment body + */ + body: string + + /** + * The author of the comment + */ + author: { name: string } + + /** + * Optional reactions of the comment + */ + reactions?: CommentReaction[] + + /** + * Optional label describing the comment + * Label will be rendered next to authorName if exists. + */ + label?: string + + /** + * Optional timestamp that will be displayed in comments. + * The date will be formatted according to the user's locale and settings. + */ + timestamp?: string +} + +interface CommentReaction { + /** + * The human-readable label for the reaction + */ + label: string + + /** + * The number of users who have reacted to this reaction + */ + count: number + + /** + * Whether the author of the comment has reacted to this reaction + */ + authorHasReacted: boolean +} + /** * A set of text extracted from the context of the prompt execution */ @@ -692,6 +753,11 @@ interface ExpansionVariables { * Root prompt generation context */ generator: ChatGenerationContext + + /** + * Comment threads generated in the context of this prompt + */ + comments: CommentThread[] } type MakeOptional = Partial> & Omit