aboutsummaryrefslogtreecommitdiff
path: root/packages/docs-test/tests/integrations/claude-memory.ts
blob: 9256e8724d6fc6e27aea23379fc63034719187cb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import "dotenv/config"
import { createClaudeMemoryTool } from "@supermemory/tools/claude-memory"

async function testConfiguration() {
	console.log("=== Configuration ===")

	// Basic
	const tool = createClaudeMemoryTool(process.env.SUPERMEMORY_API_KEY!, {
		projectId: "my-app",
	})
	console.log("✓ Basic config")

	// Full options
	const toolFull = createClaudeMemoryTool(process.env.SUPERMEMORY_API_KEY!, {
		projectId: "my-app",
		containerTags: ["user-123", "project-alpha"],
		memoryContainerTag: "my_memory_prefix",
	})
	console.log("✓ Full config")

	return tool
}

async function testMethods(tool: ReturnType<typeof createClaudeMemoryTool>) {
	console.log("\n=== Methods ===")

	console.log(
		`✓ handleCommand exists: ${typeof tool.handleCommand === "function"}`,
	)
	console.log(
		`✓ handleCommandForToolResult exists: ${typeof tool.handleCommandForToolResult === "function"}`,
	)
}

async function testCommands(tool: ReturnType<typeof createClaudeMemoryTool>) {
	console.log("\n=== Commands ===")

	// View (list)
	const listResult = await tool.handleCommand({
		command: "view",
		path: "/memories/",
	})
	console.log(`✓ view (list): ${listResult.success}`)

	// Create
	const createResult = await tool.handleCommand({
		command: "create",
		path: "/memories/test-file.txt",
		file_text: "User prefers dark mode\nFavorite language: TypeScript",
	})
	console.log(`✓ create: ${createResult.success}`)

	// Wait for indexing
	await new Promise((r) => setTimeout(r, 3000))

	// str_replace
	const replaceResult = await tool.handleCommand({
		command: "str_replace",
		path: "/memories/test-file.txt",
		old_str: "dark mode",
		new_str: "light mode",
	})
	console.log(`✓ str_replace: ${replaceResult.success}`)

	// Delete
	const deleteResult = await tool.handleCommand({
		command: "delete",
		path: "/memories/test-file.txt",
	})
	console.log(`✓ delete: ${deleteResult.success}`)
}

async function testToolResultFormat(
	tool: ReturnType<typeof createClaudeMemoryTool>,
) {
	console.log("\n=== Tool Result Format ===")

	const toolResult = await tool.handleCommandForToolResult(
		{ command: "view", path: "/memories/" },
		"test-tool-id-123",
	)

	const hasCorrectStructure =
		toolResult.type === "tool_result" &&
		toolResult.tool_use_id === "test-tool-id-123" &&
		typeof toolResult.content === "string" &&
		typeof toolResult.is_error === "boolean"

	console.log(`✓ Tool result structure: ${hasCorrectStructure}`)
}

async function main() {
	console.log("Claude Memory Tool Tests")
	console.log("========================\n")

	const tool = await testConfiguration()
	await testMethods(tool)
	await testCommands(tool)
	await testToolResultFormat(tool)

	console.log("\n========================")
	console.log("✅ All Claude Memory tests passed!")
}

main().catch(console.error)