Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

chore: remove redundant logics

Louise03a6c29b4ab
diff --git a/web-app/src/containers/MessageItem.tsx b/web-app/src/containers/MessageItem.tsx
index 0e61eaf63..7b83c46c7 100644
--- a/web-app/src/containers/MessageItem.tsx
+++ b/web-app/src/containers/MessageItem.tsx
@@ -299,7 +299,7 @@ export const MessageItem = memo(
// Check if message has tool invocations
const hasToolCalls = message.parts.some(
- (part) => part.type === 'tool-invocation'
+ (part) => part.type.startsWith('tool')
)
return (
diff --git a/web-app/src/lib/custom-chat-transport.ts b/web-app/src/lib/custom-chat-transport.ts
index 189471d9c..7b88a0dec 100644
--- a/web-app/src/lib/custom-chat-transport.ts
+++ b/web-app/src/lib/custom-chat-transport.ts
@@ -44,21 +44,6 @@ export type ServiceHub = {
startModel(provider: ProviderObject, model: string): Promise<unknown>
}
}
-// import { mcpService } from "@/services/mcp-service";
-
-/**
- * Custom download function that returns null for all URLs.
- * This tells the AI SDK to pass URLs directly to the model
- * instead of downloading and converting to base64.
- *
- * This avoids CORS issues with presigned S3 URLs and reduces payload size.
- */
-async function passUrlsDirectly(
- options: Array<{ url: URL; isUrlSupportedByModel: boolean }>
-): Promise<Array<{ data: Uint8Array; mediaType: string | undefined } | null>> {
- // Return null for all URLs to pass them directly to the model
- return options.map(() => null)
-}
/**
* Convert file parts to custom image_url format for the API.
@@ -92,89 +77,6 @@ function convertToImageUrlFormat(messages: CoreMessage[]): CoreMessage[] {
}) as CoreMessage[]
}
-/**
- * Filter out base64 image data from tool messages to reduce payload size.
- * Browser MCP tools return screenshots as base64 which are very large.
- * We replace them with a placeholder to avoid sending huge payloads to the API.
- */
-function filterBase64FromMessages(messages: CoreMessage[]): CoreMessage[] {
- const base64Pattern = /data:image\/[^;]+;base64,[A-Za-z0-9+/=]{100,}/g
-
- return messages.map((message) => {
- if (message.role === 'tool') {
- // Tool messages have content as array of ToolResultPart
- if (Array.isArray(message.content)) {
- return {
- ...message,
- content: message.content.map((part) => {
- // ToolResultPart has type 'tool-result' with a result property
- // The result can contain text with embedded base64
- if ('result' in part && part.result) {
- const resultStr =
- typeof part.result === 'string'
- ? part.result
- : JSON.stringify(part.result)
-
- if (base64Pattern.test(resultStr)) {
- return {
- ...part,
- result: resultStr.replace(
- base64Pattern,
- '[base64 image data removed]'
- ),
- }
- }
- }
- return part
- }),
- }
- }
- }
-
- // Handle user messages with image parts
- if (message.role === 'user' && Array.isArray(message.content)) {
- return {
- ...message,
- content: message.content.map((part) => {
- // Check for image parts with base64 data
- if (part.type === 'image') {
- const imageData = 'image' in part ? part.image : null
- if (
- typeof imageData === 'string' &&
- (imageData.startsWith('data:') || imageData.length > 10000)
- ) {
- // Replace with placeholder text
- return {
- type: 'text',
- text: `[Image: screenshot captured]`,
- }
- }
- }
- // Check for text parts with embedded base64
- if (
- part.type === 'text' &&
- 'text' in part &&
- typeof part.text === 'string'
- ) {
- if (base64Pattern.test(part.text)) {
- return {
- ...part,
- text: part.text.replace(
- base64Pattern,
- '[base64 image data removed]'
- ),
- }
- }
- }
- return part
- }),
- }
- }
-
- return message
- })
-}
-
export class CustomChatTransport implements ChatTransport<UIMessage> {
public model: LanguageModel | null
private tools: Record<string, Tool> = {}
@@ -335,12 +237,6 @@ export class CustomChatTransport implements ChatTransport<UIMessage> {
// Convert UI messages to model messages
const modelMessages = convertToModelMessages(options.messages)
- // Filter out base64 data from tool results
- const filteredMessages = filterBase64FromMessages(modelMessages)
-
- // Convert image parts to image_url format for the API
- const messagesWithImageUrls = convertToImageUrlFormat(filteredMessages)
-
// Include tools only if we have tools loaded AND model supports them
const hasTools = Object.keys(this.tools).length > 0
const shouldEnableTools = hasTools && this.modelSupportsTools
@@ -351,11 +247,8 @@ export class CustomChatTransport implements ChatTransport<UIMessage> {
const result = streamText({
model: this.model,
- messages: messagesWithImageUrls,
+ messages: modelMessages,
abortSignal: options.abortSignal,
- // Pass URLs directly to the model instead of downloading
- // This avoids CORS issues with presigned S3 URLs
- experimental_download: passUrlsDirectly,
tools: shouldEnableTools ? this.tools : undefined,
toolChoice: shouldEnableTools ? 'auto' : undefined,
system: this.systemMessage,
diff --git a/web-app/src/lib/messages.ts b/web-app/src/lib/messages.ts
index 1586206e1..7281abbbe 100644
--- a/web-app/src/lib/messages.ts
+++ b/web-app/src/lib/messages.ts
@@ -57,9 +57,6 @@ export function convertUIMessageToThreadMessage(
},
})
}
- } else if (part.type === 'tool-invocation') {
- // Tool calls are stored in metadata, not content
- // We'll handle this below
}
}
@@ -76,7 +73,7 @@ export function convertUIMessageToThreadMessage(
// Extract tool calls from parts
const toolCalls = (uiMessage.parts as any[])
- .filter((part) => part.type === 'tool-invocation')
+ .filter((part) => part.type.startsWith('tool'))
.map((part) => {
return {
tool: {