Skip to content

Commit d641e73

Browse files
github-actions[bot]claude
authored andcommitted
fix: resolve biome lint errors in voltagent integration
Replace explicit `any` types with proper type annotations and fix non-null assertion by using proper null checking. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 0cbf5e7 commit d641e73

File tree

4 files changed

+61
-39
lines changed

4 files changed

+61
-39
lines changed

packages/tools/src/voltagent/hooks.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type {
1010
HookPrepareMessagesArgs,
1111
HookEndArgs,
1212
VoltAgentMessage,
13-
SupermemoryVoltAgentOptions,
13+
SupermemoryVoltAgent,
1414
} from "./types"
1515
import {
1616
createSupermemoryContext,
@@ -49,7 +49,7 @@ import {
4949
*/
5050
export function createSupermemoryHooks(
5151
containerTag: string,
52-
options: SupermemoryVoltAgentOptions = {},
52+
options: SupermemoryVoltAgent = {},
5353
): VoltAgentHooks {
5454
const ctx = createSupermemoryContext(containerTag, options)
5555

@@ -60,7 +60,10 @@ export function createSupermemoryHooks(
6060
try {
6161
// VoltAgent passes user messages in args.context.input.messages
6262
// and the prepared messages (system + conversation) in args.messages
63-
const inputMessages = (args.context as any)?.input?.messages || []
63+
const contextInput = args.context?.input as
64+
| { messages?: VoltAgentMessage[] }
65+
| undefined
66+
const inputMessages = contextInput?.messages || []
6467

6568
ctx.logger.debug("onPrepareMessages called", {
6669
messageCount: args.messages.length,
@@ -99,13 +102,19 @@ export function createSupermemoryHooks(
99102
let messages: VoltAgentMessage[] = []
100103

101104
if (args.context?.input && args.output) {
102-
const inputData = args.context.input as any
105+
const inputData = args.context.input as
106+
| { messages?: VoltAgentMessage[] }
107+
| undefined
103108
const inputMessages = inputData?.messages || []
104109

105-
const outputData = args.output as any
106-
const outputText = typeof outputData === "string"
107-
? outputData
108-
: outputData?.text || outputData?.content
110+
const outputData = args.output as
111+
| string
112+
| { text?: string; content?: string }
113+
| undefined
114+
const outputText =
115+
typeof outputData === "string"
116+
? outputData
117+
: outputData?.text || outputData?.content
109118

110119
if (inputMessages.length > 0 && outputText) {
111120
messages = [
@@ -158,7 +167,8 @@ export function mergeHooks(
158167

159168
mergedHooks.onPrepareMessages = async (args) => {
160169
const resultAfterExisting = await existingOnPrepareMessages(args)
161-
const messagesAfterExisting = resultAfterExisting?.messages || args.messages
170+
const messagesAfterExisting =
171+
resultAfterExisting?.messages || args.messages
162172

163173
return await supermemoryOnPrepareMessages({
164174
...args,

packages/tools/src/voltagent/index.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@
99

1010
import { validateApiKey } from "../shared"
1111
import { createSupermemoryHooks, mergeHooks } from "./hooks"
12-
import type {
13-
VoltAgentConfig,
14-
SupermemoryVoltAgentOptions,
15-
} from "./types"
12+
import type { VoltAgentConfig, SupermemoryVoltAgent } from "./types"
1613

1714
/**
1815
* Enhances a VoltAgent agent configuration with Supermemory memory capabilities.
@@ -139,7 +136,7 @@ import type {
139136
*/
140137
export function withSupermemory<T extends VoltAgentConfig>(
141138
config: T,
142-
options: SupermemoryVoltAgentOptions & { containerTag: string },
139+
options: SupermemoryVoltAgent & { containerTag: string },
143140
): T {
144141
const { containerTag, ...supermemoryOptions } = options
145142

@@ -164,7 +161,7 @@ export function withSupermemory<T extends VoltAgentConfig>(
164161

165162
// Export types for consumers
166163
export type {
167-
SupermemoryVoltAgentOptions,
164+
SupermemoryVoltAgent,
168165
VoltAgentConfig,
169166
VoltAgentMessage,
170167
VoltAgentHooks,

packages/tools/src/voltagent/middleware.ts

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ import {
1818
type Logger,
1919
type MemoryMode,
2020
} from "../shared"
21-
import type {
22-
SupermemoryVoltAgent,
23-
VoltAgentMessage,
24-
} from "./types"
21+
import type { SupermemoryVoltAgent, VoltAgentMessage } from "./types"
2522

2623
/**
2724
* Context for Supermemory middleware operations.
@@ -212,7 +209,11 @@ export const enhanceMessagesWithMemories = async (
212209
const cachedMemories = ctx.memoryCache.get(turnKey)
213210
if (!isNewTurn && cachedMemories) {
214211
ctx.logger.debug("Using cached memories", { turnKey })
215-
return injectMemoriesIntoMessages(messagesToEnhance, cachedMemories, ctx.logger)
212+
return injectMemoriesIntoMessages(
213+
messagesToEnhance,
214+
cachedMemories,
215+
ctx.logger,
216+
)
216217
}
217218

218219
ctx.logger.info("Starting memory search", {
@@ -277,8 +278,13 @@ export const enhanceMessagesWithMemories = async (
277278

278279
// Hybrid search returns both memory entries (`memory` field) and
279280
// document chunks (`chunk` field). Handle both.
281+
type SearchResult = {
282+
memory?: string
283+
chunk?: string
284+
metadata?: Record<string, unknown>
285+
}
280286
const formattedMemories = response.results
281-
.map((result: any) => {
287+
.map((result: SearchResult) => {
282288
const text = result.memory || result.chunk
283289
return text ? `- ${text}` : null
284290
})
@@ -289,7 +295,10 @@ export const enhanceMessagesWithMemories = async (
289295
? ctx.promptTemplate({
290296
userMemories: "",
291297
generalSearchMemories: formattedMemories,
292-
searchResults: response.results as any,
298+
searchResults: response.results as Array<{
299+
memory: string
300+
metadata?: Record<string, unknown>
301+
}>,
293302
})
294303
: `The following are relevant memories and context about this user retrieved from previous interactions. Use these to personalize your response:\n\n${formattedMemories}`
295304
} else {
@@ -328,12 +337,20 @@ const injectMemoriesIntoMessages = (
328337
if (systemMessageIndex !== -1) {
329338
logger.debug("Added memories to existing system message")
330339
const newMessages = [...messages]
331-
const systemMessage = newMessages[systemMessageIndex]!
340+
const systemMessage = newMessages[systemMessageIndex]
341+
if (!systemMessage) {
342+
return messages
343+
}
332344

333345
// Extract existing text from parts (UIMessage format) or content fallback
334-
const parts = (systemMessage as any).parts as Array<{ type: string; text?: string }> | undefined
346+
const parts = (
347+
systemMessage as { parts?: Array<{ type: string; text?: string }> }
348+
).parts
335349
const existingContent = parts
336-
? parts.filter((p) => p.type === "text").map((p) => p.text || "").join("\n")
350+
? parts
351+
.filter((p) => p.type === "text")
352+
.map((p) => p.text || "")
353+
.join("\n")
337354
: typeof systemMessage.content === "string"
338355
? systemMessage.content
339356
: ""
@@ -345,7 +362,7 @@ const injectMemoriesIntoMessages = (
345362
content: newContent,
346363
// Update parts array to match - this is what the LLM actually reads
347364
parts: [{ type: "text", text: newContent }],
348-
} as any
365+
} as VoltAgentMessage
349366
return newMessages
350367
}
351368

@@ -356,7 +373,7 @@ const injectMemoriesIntoMessages = (
356373
role: "system" as const,
357374
content: memories,
358375
parts: [{ type: "text", text: memories }],
359-
} as any,
376+
} as VoltAgentMessage,
360377
...messages,
361378
]
362379
}

packages/tools/src/voltagent/types.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import type {
1717
* Configuration options for the Supermemory VoltAgent integration.
1818
* Extends base options with VoltAgent-specific settings.
1919
*/
20-
export interface SupermemoryVoltAgentOptions extends Omit<SupermemoryBaseOptions, 'verbose'> {
20+
export interface SupermemoryVoltAgent
21+
extends Omit<SupermemoryBaseOptions, "verbose"> {
2122
/**
2223
* When using memory storage, set this to enable automatic conversation saving.
2324
* The threadId is used to group messages into a single conversation.
@@ -91,9 +92,7 @@ export interface SupermemoryVoltAgentOptions extends Omit<SupermemoryBaseOptions
9192
/**
9293
* Advanced search filters using AND/OR logic
9394
*/
94-
export type SearchFilters =
95-
| { OR: Array<unknown> }
96-
| { AND: Array<unknown> }
95+
export type SearchFilters = { OR: Array<unknown> } | { AND: Array<unknown> }
9796

9897
/**
9998
* Options for including additional data in search results
@@ -133,7 +132,9 @@ export interface IncludeOptions {
133132
*/
134133
export interface VoltAgentMessage {
135134
role: "system" | "user" | "assistant" | "tool"
136-
content: string | Array<{ type: string; text?: string; [key: string]: unknown }>
135+
content:
136+
| string
137+
| Array<{ type: string; text?: string; [key: string]: unknown }>
137138
[key: string]: unknown
138139
}
139140

@@ -158,7 +159,9 @@ export interface VoltAgentHooks {
158159
onStart?: (args: HookStartArgs) => void | Promise<void>
159160
onPrepareMessages?: (
160161
args: HookPrepareMessagesArgs,
161-
) => { messages?: VoltAgentMessage[] } | Promise<{ messages?: VoltAgentMessage[] }>
162+
) =>
163+
| { messages?: VoltAgentMessage[] }
164+
| Promise<{ messages?: VoltAgentMessage[] }>
162165
onEnd?: (args: HookEndArgs) => void | Promise<void>
163166
[key: string]: unknown
164167
}
@@ -210,9 +213,4 @@ export interface HookEndArgs {
210213
}
211214

212215
// Re-export shared types for convenience
213-
export type {
214-
PromptTemplate,
215-
MemoryMode,
216-
AddMemoryMode,
217-
MemoryPromptData,
218-
}
216+
export type { PromptTemplate, MemoryMode, AddMemoryMode, MemoryPromptData }

0 commit comments

Comments
 (0)