Fix type errors

This commit is contained in:
cte 2025-02-24 15:55:04 -08:00
parent b2b135c05c
commit 22391e5011
7 changed files with 16 additions and 33 deletions

View file

@ -193,6 +193,8 @@ export function convertToAnthropicMessage(
usage: {
input_tokens: streamEvent.metadata.usage.inputTokens || 0,
output_tokens: streamEvent.metadata.usage.outputTokens || 0,
cache_creation_input_tokens: null,
cache_read_input_tokens: null,
},
}
}
@ -203,7 +205,7 @@ export function convertToAnthropicMessage(
return {
type: "message",
role: "assistant",
content: [{ type: "text", text: text }],
content: [{ type: "text", text: text, citations: null }],
model: modelId,
}
}

View file

@ -11,16 +11,7 @@ import {
TextPart,
} from "@google/generative-ai"
export function convertAnthropicContentToGemini(
content:
| string
| Array<
| Anthropic.Messages.TextBlockParam
| Anthropic.Messages.ImageBlockParam
| Anthropic.Messages.ToolUseBlockParam
| Anthropic.Messages.ToolResultBlockParam
>,
): Part[] {
export function convertAnthropicContentToGemini(content: Anthropic.Messages.MessageParam["content"]): Part[] {
if (typeof content === "string") {
return [{ text: content } as TextPart]
}
@ -140,7 +131,7 @@ export function convertGeminiResponseToAnthropic(
// Add the main text response
const text = response.text()
if (text) {
content.push({ type: "text", text })
content.push({ type: "text", text, citations: null })
}
// Add function calls as tool_use blocks
@ -190,6 +181,8 @@ export function convertGeminiResponseToAnthropic(
usage: {
input_tokens: response.usageMetadata?.promptTokenCount ?? 0,
output_tokens: response.usageMetadata?.candidatesTokenCount ?? 0,
cache_creation_input_tokens: null,
cache_read_input_tokens: null,
},
}
}

View file

@ -158,6 +158,7 @@ export function convertToAnthropicMessage(
{
type: "text",
text: openAiMessage.content || "",
citations: null,
},
],
model: completion.model,
@ -178,6 +179,8 @@ export function convertToAnthropicMessage(
usage: {
input_tokens: completion.usage?.prompt_tokens || 0,
output_tokens: completion.usage?.completion_tokens || 0,
cache_creation_input_tokens: null,
cache_read_input_tokens: null,
},
}

View file

@ -3,16 +3,7 @@ import { Anthropic } from "@anthropic-ai/sdk"
/**
* Convert complex content blocks to simple string content
*/
export function convertToSimpleContent(
content:
| string
| Array<
| Anthropic.Messages.TextBlockParam
| Anthropic.Messages.ImageBlockParam
| Anthropic.Messages.ToolUseBlockParam
| Anthropic.Messages.ToolResultBlockParam
>,
): string {
export function convertToSimpleContent(content: Anthropic.Messages.MessageParam["content"]): string {
if (typeof content === "string") {
return content
}

View file

@ -175,6 +175,7 @@ export async function convertToAnthropicMessage(
return {
type: "text",
text: part.value,
citations: null,
}
}
@ -195,6 +196,8 @@ export async function convertToAnthropicMessage(
usage: {
input_tokens: 0,
output_tokens: 0,
cache_creation_input_tokens: null,
cache_read_input_tokens: null,
},
}
}

View file

@ -69,9 +69,7 @@ const cwd =
vscode.workspace.workspaceFolders?.map((folder) => folder.uri.fsPath).at(0) ?? path.join(os.homedir(), "Desktop") // may or may not exist but fs checking existence would immediately ask for permission which would be bad UX, need to come up with a better solution
type ToolResponse = string | Array<Anthropic.TextBlockParam | Anthropic.ImageBlockParam>
type UserContent = Array<
Anthropic.TextBlockParam | Anthropic.ImageBlockParam | Anthropic.ToolUseBlockParam | Anthropic.ToolResultBlockParam
>
type UserContent = Array<Anthropic.Messages.ContentBlockParam>
export type ClineOptions = {
provider: ClineProvider

View file

@ -41,14 +41,7 @@ export async function downloadTask(dateTs: number, conversationHistory: Anthropi
}
}
export function formatContentBlockToMarkdown(
block:
| Anthropic.TextBlockParam
| Anthropic.ImageBlockParam
| Anthropic.ToolUseBlockParam
| Anthropic.ToolResultBlockParam,
// messages: Anthropic.MessageParam[]
): string {
export function formatContentBlockToMarkdown(block: Anthropic.Messages.ContentBlockParam): string {
switch (block.type) {
case "text":
return block.text