chore: Prettier fix formatting
This commit is contained in:
1 parent
9de7253998
commit
25cd7cc8e2
106 files changed
+1624
-5278
No files matched your search
@@ -3,10 +3,7 @@ import os from "os"
|
||||
import * as path from "path"
|
||||
import * as vscode from "vscode"
|
||||
|
||||
export async function downloadTask(
|
||||
dateTs: number,
|
||||
conversationHistory: Anthropic.MessageParam[],
|
||||
) {
|
||||
export async function downloadTask(dateTs: number, conversationHistory: Anthropic.MessageParam[]) {
|
||||
// File name
|
||||
const date = new Date(dateTs)
|
||||
const month = date.toLocaleString("en-US", { month: "short" }).toLowerCase()
|
||||
@@ -23,12 +20,9 @@ export async function downloadTask(
|
||||
// Generate markdown
|
||||
const markdownContent = conversationHistory
|
||||
.map((message) => {
|
||||
const role =
|
||||
message.role === "user" ? "**User:**" : "**Assistant:**"
|
||||
const role = message.role === "user" ? "**User:**" : "**Assistant:**"
|
||||
const content = Array.isArray(message.content)
|
||||
? message.content
|
||||
.map((block) => formatContentBlockToMarkdown(block))
|
||||
.join("\n")
|
||||
? message.content.map((block) => formatContentBlockToMarkdown(block)).join("\n")
|
||||
: message.content
|
||||
return `${role}\n\n${content}\n\n`
|
||||
})
|
||||
@@ -37,27 +31,18 @@ export async function downloadTask(
|
||||
// Prompt user for save location
|
||||
const saveUri = await vscode.window.showSaveDialog({
|
||||
filters: { Markdown: ["md"] },
|
||||
defaultUri: vscode.Uri.file(
|
||||
path.join(os.homedir(), "Downloads", fileName),
|
||||
),
|
||||
defaultUri: vscode.Uri.file(path.join(os.homedir(), "Downloads", fileName)),
|
||||
})
|
||||
|
||||
if (saveUri) {
|
||||
// Write content to the selected location
|
||||
await vscode.workspace.fs.writeFile(
|
||||
saveUri,
|
||||
Buffer.from(markdownContent),
|
||||
)
|
||||
await vscode.workspace.fs.writeFile(saveUri, Buffer.from(markdownContent))
|
||||
vscode.window.showTextDocument(saveUri, { preview: true })
|
||||
}
|
||||
}
|
||||
|
||||
export function formatContentBlockToMarkdown(
|
||||
block:
|
||||
| Anthropic.TextBlockParam
|
||||
| Anthropic.ImageBlockParam
|
||||
| Anthropic.ToolUseBlockParam
|
||||
| Anthropic.ToolResultBlockParam,
|
||||
block: Anthropic.TextBlockParam | Anthropic.ImageBlockParam | Anthropic.ToolUseBlockParam | Anthropic.ToolResultBlockParam,
|
||||
// messages: Anthropic.MessageParam[]
|
||||
): string {
|
||||
switch (block.type) {
|
||||
@@ -69,10 +54,7 @@ export function formatContentBlockToMarkdown(
|
||||
let input: string
|
||||
if (typeof block.input === "object" && block.input !== null) {
|
||||
input = Object.entries(block.input)
|
||||
.map(
|
||||
([key, value]) =>
|
||||
`${key.charAt(0).toUpperCase() + key.slice(1)}: ${value}`,
|
||||
)
|
||||
.map(([key, value]) => `${key.charAt(0).toUpperCase() + key.slice(1)}: ${value}`)
|
||||
.join("\n")
|
||||
} else {
|
||||
input = String(block.input)
|
||||
@@ -86,9 +68,7 @@ export function formatContentBlockToMarkdown(
|
||||
return `[${toolName}${block.is_error ? " (Error)" : ""}]\n${block.content}`
|
||||
} else if (Array.isArray(block.content)) {
|
||||
return `[${toolName}${block.is_error ? " (Error)" : ""}]\n${block.content
|
||||
.map((contentBlock) =>
|
||||
formatContentBlockToMarkdown(contentBlock),
|
||||
)
|
||||
.map((contentBlock) => formatContentBlockToMarkdown(contentBlock))
|
||||
.join("\n")}`
|
||||
} else {
|
||||
return `[${toolName}${block.is_error ? " (Error)" : ""}]`
|
||||
@@ -98,10 +78,7 @@ export function formatContentBlockToMarkdown(
|
||||
}
|
||||
}
|
||||
|
||||
export function findToolName(
|
||||
toolCallId: string,
|
||||
messages: Anthropic.MessageParam[],
|
||||
): string {
|
||||
export function findToolName(toolCallId: string, messages: Anthropic.MessageParam[]): string {
|
||||
for (const message of messages) {
|
||||
if (Array.isArray(message.content)) {
|
||||
for (const block of message.content) {
|
||||
|
||||
@@ -24,9 +24,7 @@ export async function extractTextFromFile(filePath: string): Promise<string> {
|
||||
if (!isBinary) {
|
||||
return await fs.readFile(filePath, "utf8")
|
||||
} else {
|
||||
throw new Error(
|
||||
`Cannot read text for file type: ${fileExtension}`,
|
||||
)
|
||||
throw new Error(`Cannot read text for file type: ${fileExtension}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -48,10 +46,7 @@ async function extractTextFromIPYNB(filePath: string): Promise<string> {
|
||||
let extractedText = ""
|
||||
|
||||
for (const cell of notebook.cells) {
|
||||
if (
|
||||
(cell.cell_type === "markdown" || cell.cell_type === "code") &&
|
||||
cell.source
|
||||
) {
|
||||
if ((cell.cell_type === "markdown" || cell.cell_type === "code") && cell.source) {
|
||||
extractedText += cell.source.join("\n") + "\n"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,19 +11,10 @@ export async function openImage(dataUri: string) {
|
||||
}
|
||||
const [, format, base64Data] = matches
|
||||
const imageBuffer = Buffer.from(base64Data, "base64")
|
||||
const tempFilePath = path.join(
|
||||
os.tmpdir(),
|
||||
`temp_image_${Date.now()}.${format}`,
|
||||
)
|
||||
const tempFilePath = path.join(os.tmpdir(), `temp_image_${Date.now()}.${format}`)
|
||||
try {
|
||||
await vscode.workspace.fs.writeFile(
|
||||
vscode.Uri.file(tempFilePath),
|
||||
imageBuffer,
|
||||
)
|
||||
await vscode.commands.executeCommand(
|
||||
"vscode.open",
|
||||
vscode.Uri.file(tempFilePath),
|
||||
)
|
||||
await vscode.workspace.fs.writeFile(vscode.Uri.file(tempFilePath), imageBuffer)
|
||||
await vscode.commands.executeCommand("vscode.open", vscode.Uri.file(tempFilePath))
|
||||
} catch (error) {
|
||||
vscode.window.showErrorMessage(`Error opening image: ${error}`)
|
||||
}
|
||||
@@ -37,21 +28,12 @@ export async function openFile(absolutePath: string) {
|
||||
try {
|
||||
for (const group of vscode.window.tabGroups.all) {
|
||||
const existingTab = group.tabs.find(
|
||||
(tab) =>
|
||||
tab.input instanceof vscode.TabInputText &&
|
||||
arePathsEqual(tab.input.uri.fsPath, uri.fsPath),
|
||||
(tab) => tab.input instanceof vscode.TabInputText && arePathsEqual(tab.input.uri.fsPath, uri.fsPath),
|
||||
)
|
||||
if (existingTab) {
|
||||
const activeColumn =
|
||||
vscode.window.activeTextEditor?.viewColumn
|
||||
const tabColumn = vscode.window.tabGroups.all.find(
|
||||
(group) => group.tabs.includes(existingTab),
|
||||
)?.viewColumn
|
||||
if (
|
||||
activeColumn &&
|
||||
activeColumn !== tabColumn &&
|
||||
!existingTab.isDirty
|
||||
) {
|
||||
const activeColumn = vscode.window.activeTextEditor?.viewColumn
|
||||
const tabColumn = vscode.window.tabGroups.all.find((group) => group.tabs.includes(existingTab))?.viewColumn
|
||||
if (activeColumn && activeColumn !== tabColumn && !existingTab.isDirty) {
|
||||
await vscode.window.tabGroups.close(existingTab)
|
||||
}
|
||||
break
|
||||
|
||||
Reference in new issue
Block a user