mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-09-06 08:16:03 +00:00
fix: add biome-ignore comments for AI SDK internal types and fix formatting
The AI SDK middleware requires `any` types because the SDK's internal call options and prompt types are not exported. Added biome-ignore comments to suppress noExplicitAny warnings and ran format-lint to fix formatting issues. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
244f924c04
commit
46d97b624c
6 changed files with 82 additions and 35 deletions
|
|
@ -71,10 +71,12 @@ export function MemoryGraph({
|
|||
maxNodes={maxNodes}
|
||||
canvasRef={canvasRef}
|
||||
totalCount={totalCount}
|
||||
colors={{
|
||||
bg: "transparent",
|
||||
edgeDerives: "#9ca3af",
|
||||
} as any}
|
||||
colors={
|
||||
{
|
||||
bg: "transparent",
|
||||
edgeDerives: "#9ca3af",
|
||||
} as any
|
||||
}
|
||||
{...rest}
|
||||
>
|
||||
{children}
|
||||
|
|
|
|||
|
|
@ -197,7 +197,11 @@ export function MemoryGraph({
|
|||
setViewportVersion((v) => v + 1)
|
||||
}
|
||||
|
||||
const { hasMore: more, isLoadingMore: loading, onLoadMore: load } = loadMoreRef.current
|
||||
const {
|
||||
hasMore: more,
|
||||
isLoadingMore: loading,
|
||||
onLoadMore: load,
|
||||
} = loadMoreRef.current
|
||||
if (!more || loading || !load || !viewportRef.current) return
|
||||
|
||||
const vp = viewportRef.current
|
||||
|
|
@ -205,14 +209,17 @@ export function MemoryGraph({
|
|||
if (currentNodes.length === 0) return
|
||||
|
||||
const topLeft = vp.screenToWorld(0, 0)
|
||||
const bottomRight = vp.screenToWorld(containerSize.width, containerSize.height)
|
||||
const bottomRight = vp.screenToWorld(
|
||||
containerSize.width,
|
||||
containerSize.height,
|
||||
)
|
||||
const viewW = bottomRight.x - topLeft.x
|
||||
const viewH = bottomRight.y - topLeft.y
|
||||
|
||||
let minX = Infinity
|
||||
let minY = Infinity
|
||||
let maxX = -Infinity
|
||||
let maxY = -Infinity
|
||||
let minX = Number.POSITIVE_INFINITY
|
||||
let minY = Number.POSITIVE_INFINITY
|
||||
let maxX = Number.NEGATIVE_INFINITY
|
||||
let maxY = Number.NEGATIVE_INFINITY
|
||||
for (const n of currentNodes) {
|
||||
if (n.x < minX) minX = n.x
|
||||
if (n.y < minY) minY = n.y
|
||||
|
|
@ -613,7 +620,6 @@ export function MemoryGraph({
|
|||
colors={colors}
|
||||
/>
|
||||
|
||||
|
||||
{!isLoading && !nodes.some((n) => n.type === "document") && children && (
|
||||
<div style={emptyStateStyle}>{children}</div>
|
||||
)}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,9 @@ import type { FunctionReference } from "convex/server"
|
|||
* a direct dependency on @ai-sdk/provider.
|
||||
*/
|
||||
interface WrappableLanguageModel {
|
||||
// biome-ignore lint/suspicious/noExplicitAny: AI SDK internal types not exported
|
||||
doGenerate: (options: any) => Promise<any>
|
||||
// biome-ignore lint/suspicious/noExplicitAny: AI SDK internal types not exported
|
||||
doStream: (options: any) => Promise<any>
|
||||
[key: string]: unknown
|
||||
}
|
||||
|
|
@ -49,7 +51,7 @@ export interface SupermemoryOptions {
|
|||
export interface MemoryPromptData {
|
||||
userMemories: string
|
||||
generalSearchMemories: string
|
||||
searchResults: any[]
|
||||
searchResults: unknown[]
|
||||
}
|
||||
|
||||
const DEFAULT_PROMPT_TEMPLATE = (data: MemoryPromptData) =>
|
||||
|
|
@ -119,10 +121,12 @@ export function withSupermemory<T extends WrappableLanguageModel>(
|
|||
|
||||
return {
|
||||
...model,
|
||||
// biome-ignore lint/suspicious/noExplicitAny: AI SDK internal types not exported
|
||||
doGenerate: async (callOptions: any) => {
|
||||
try {
|
||||
// Extract user's last message for query-based search
|
||||
const lastUserMessage = callOptions.prompt
|
||||
// biome-ignore lint/suspicious/noExplicitAny: AI SDK internal types not exported
|
||||
.filter((msg: any) => msg.role === "user")
|
||||
.slice(-1)[0]
|
||||
|
||||
|
|
@ -131,13 +135,14 @@ export function withSupermemory<T extends WrappableLanguageModel>(
|
|||
? typeof lastUserMessage.content === "string"
|
||||
? lastUserMessage.content
|
||||
: lastUserMessage.content
|
||||
// biome-ignore lint/suspicious/noExplicitAny: AI SDK internal types not exported
|
||||
.map((c: any) => (c.type === "text" ? c.text : ""))
|
||||
.join(" ")
|
||||
: ""
|
||||
|
||||
let userMemories = ""
|
||||
let generalSearchMemories = ""
|
||||
let searchResults: any[] = []
|
||||
let searchResults: unknown[] = []
|
||||
|
||||
// Fetch profile if needed
|
||||
if (mode === "profile" || mode === "full") {
|
||||
|
|
@ -175,6 +180,7 @@ export function withSupermemory<T extends WrappableLanguageModel>(
|
|||
searchResults = searchResult.results
|
||||
generalSearchMemories = searchResults
|
||||
.map(
|
||||
// biome-ignore lint/suspicious/noExplicitAny: search result types not exported
|
||||
(r: any) =>
|
||||
`- ${r.memory || r.chunk} (similarity: ${r.similarity.toFixed(2)})`,
|
||||
)
|
||||
|
|
@ -204,11 +210,15 @@ export function withSupermemory<T extends WrappableLanguageModel>(
|
|||
if (addMemory === "always" && userQuery) {
|
||||
if (verbose) console.log("[Supermemory] Auto-saving user message...")
|
||||
|
||||
convexClient.action(addAction, {
|
||||
content: userQuery,
|
||||
containerTag,
|
||||
metadata: { source: "ai-middleware", auto: true },
|
||||
}).catch((e) => console.error("[Supermemory] Failed to auto-save:", e))
|
||||
convexClient
|
||||
.action(addAction, {
|
||||
content: userQuery,
|
||||
containerTag,
|
||||
metadata: { source: "ai-middleware", auto: true },
|
||||
})
|
||||
.catch((e) =>
|
||||
console.error("[Supermemory] Failed to auto-save:", e),
|
||||
)
|
||||
}
|
||||
|
||||
// Call original model with enhanced context
|
||||
|
|
@ -223,10 +233,12 @@ export function withSupermemory<T extends WrappableLanguageModel>(
|
|||
}
|
||||
},
|
||||
|
||||
// biome-ignore lint/suspicious/noExplicitAny: AI SDK internal types not exported
|
||||
doStream: async (callOptions: any) => {
|
||||
// For streaming, we inject context upfront then stream normally
|
||||
try {
|
||||
const lastUserMessage = callOptions.prompt
|
||||
// biome-ignore lint/suspicious/noExplicitAny: AI SDK internal types not exported
|
||||
.filter((msg: any) => msg.role === "user")
|
||||
.slice(-1)[0]
|
||||
|
||||
|
|
@ -235,13 +247,14 @@ export function withSupermemory<T extends WrappableLanguageModel>(
|
|||
? typeof lastUserMessage.content === "string"
|
||||
? lastUserMessage.content
|
||||
: lastUserMessage.content
|
||||
// biome-ignore lint/suspicious/noExplicitAny: AI SDK internal types not exported
|
||||
.map((c: any) => (c.type === "text" ? c.text : ""))
|
||||
.join(" ")
|
||||
: ""
|
||||
|
||||
let userMemories = ""
|
||||
let generalSearchMemories = ""
|
||||
let searchResults: any[] = []
|
||||
let searchResults: unknown[] = []
|
||||
|
||||
if (mode === "profile" || mode === "full") {
|
||||
const profile = await convexClient.action(profileAction, {
|
||||
|
|
@ -265,6 +278,7 @@ export function withSupermemory<T extends WrappableLanguageModel>(
|
|||
|
||||
searchResults = searchResult.results
|
||||
generalSearchMemories = searchResults
|
||||
// biome-ignore lint/suspicious/noExplicitAny: search result types not exported
|
||||
.map((r: any) => `- ${r.memory || r.chunk}`)
|
||||
.join("\n")
|
||||
}
|
||||
|
|
@ -281,11 +295,15 @@ export function withSupermemory<T extends WrappableLanguageModel>(
|
|||
]
|
||||
|
||||
if (addMemory === "always" && userQuery) {
|
||||
convexClient.action(addAction, {
|
||||
content: userQuery,
|
||||
containerTag,
|
||||
metadata: { source: "ai-middleware", auto: true },
|
||||
}).catch((e) => console.error("[Supermemory] Failed to auto-save:", e))
|
||||
convexClient
|
||||
.action(addAction, {
|
||||
content: userQuery,
|
||||
containerTag,
|
||||
metadata: { source: "ai-middleware", auto: true },
|
||||
})
|
||||
.catch((e) =>
|
||||
console.error("[Supermemory] Failed to auto-save:", e),
|
||||
)
|
||||
}
|
||||
|
||||
return await model.doStream({
|
||||
|
|
|
|||
|
|
@ -145,7 +145,12 @@ export const search = action({
|
|||
})
|
||||
|
||||
// Log API call
|
||||
const logBody = { q: args.q, containerTag: args.containerTag, searchMode: args.searchMode, limit: args.limit }
|
||||
const logBody = {
|
||||
q: args.q,
|
||||
containerTag: args.containerTag,
|
||||
searchMode: args.searchMode,
|
||||
limit: args.limit,
|
||||
}
|
||||
await ctx.runMutation(internal.mutations.logApiCall, {
|
||||
endpoint: "search",
|
||||
containerTag: args.containerTag,
|
||||
|
|
@ -159,7 +164,12 @@ export const search = action({
|
|||
const responseTime = Date.now() - startTime
|
||||
|
||||
try {
|
||||
const logBody = { q: args.q, containerTag: args.containerTag, searchMode: args.searchMode, limit: args.limit }
|
||||
const logBody = {
|
||||
q: args.q,
|
||||
containerTag: args.containerTag,
|
||||
searchMode: args.searchMode,
|
||||
limit: args.limit,
|
||||
}
|
||||
await ctx.runMutation(internal.mutations.logApiCall, {
|
||||
endpoint: "search",
|
||||
containerTag: args.containerTag,
|
||||
|
|
|
|||
|
|
@ -153,7 +153,6 @@ export function listMemories(
|
|||
return useQuery(query, args) as Memory[] | undefined
|
||||
}
|
||||
|
||||
|
||||
// Export all types
|
||||
export type {
|
||||
AddMemoryArgs,
|
||||
|
|
|
|||
|
|
@ -119,10 +119,16 @@ export async function realClaudeMemoryExample() {
|
|||
const toolResults = []
|
||||
|
||||
if (responseData.content) {
|
||||
const memoryToolCalls = responseData.content.filter(
|
||||
(block: any): block is { type: 'tool_use'; id: string; name: 'memory'; input: { command: MemoryCommand; path: string } } =>
|
||||
block.type === "tool_use" && block.name === "memory",
|
||||
)
|
||||
const memoryToolCalls = responseData.content.filter(
|
||||
(
|
||||
block: any,
|
||||
): block is {
|
||||
type: "tool_use"
|
||||
id: string
|
||||
name: "memory"
|
||||
input: { command: MemoryCommand; path: string }
|
||||
} => block.type === "tool_use" && block.name === "memory",
|
||||
)
|
||||
|
||||
const results = await Promise.all(
|
||||
memoryToolCalls.map((block: any) => {
|
||||
|
|
@ -196,10 +202,16 @@ export async function processClaudeResponse(
|
|||
const toolResults = []
|
||||
|
||||
if (claudeResponseData.content) {
|
||||
const memoryToolCalls = claudeResponseData.content.filter(
|
||||
(block: any): block is { type: 'tool_use'; id: string; name: 'memory'; input: { command: MemoryCommand; path: string } } =>
|
||||
block.type === "tool_use" && block.name === "memory",
|
||||
)
|
||||
const memoryToolCalls = claudeResponseData.content.filter(
|
||||
(
|
||||
block: any,
|
||||
): block is {
|
||||
type: "tool_use"
|
||||
id: string
|
||||
name: "memory"
|
||||
input: { command: MemoryCommand; path: string }
|
||||
} => block.type === "tool_use" && block.name === "memory",
|
||||
)
|
||||
|
||||
const results = await Promise.all(
|
||||
memoryToolCalls.map((block: any) =>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue