chat-agent-toolkit 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/README.md +234 -0
  2. package/package.json +101 -0
  3. package/src/config/config-manager.ts +319 -0
  4. package/src/config/config-types.ts +65 -0
  5. package/src/config/environment-variables.ts +8 -0
  6. package/src/config/index.ts +26 -0
  7. package/src/config/language-models-database.ts +1426 -0
  8. package/src/config/mcp-server-registry.ts +24 -0
  9. package/src/config/model-registry.ts +256 -0
  10. package/src/config/model-tester.ts +211 -0
  11. package/src/config/model-utils.ts +193 -0
  12. package/src/config/provider-ui-config.ts +196 -0
  13. package/src/connectors/composio.json +154 -0
  14. package/src/index.ts +22 -0
  15. package/src/memory/ARCHITECTURE.md +302 -0
  16. package/src/memory/MASTRA_INTEGRATION.md +106 -0
  17. package/src/memory/README.md +224 -0
  18. package/src/memory/agent-memory-manager.ts +416 -0
  19. package/src/memory/example.ts +343 -0
  20. package/src/memory/index.ts +47 -0
  21. package/src/memory/mastra-integration.ts +609 -0
  22. package/src/memory/storage/drizzle-storage.ts +205 -0
  23. package/src/memory/storage/in-memory-storage.ts +551 -0
  24. package/src/memory/storage/storage-interface.ts +68 -0
  25. package/src/memory/types.ts +125 -0
  26. package/src/models/providers.ts +5 -0
  27. package/src/models/registry.ts +4 -0
  28. package/src/models/types.ts +4 -0
  29. package/src/search.ts +5 -0
  30. package/src/tools/composio-mastra.ts +305 -0
  31. package/src/tools/composio-mcp.ts +205 -0
  32. package/src/tools/index.ts +13 -0
  33. package/src/tools/qwksearch-api-tools.ts +327 -0
  34. package/src/tools/search/doc-utils.ts +75 -0
  35. package/src/tools/search/document.ts +47 -0
  36. package/src/tools/search/index.ts +13 -0
  37. package/src/tools/search/link-summarizer.ts +112 -0
  38. package/src/tools/search/meta-search-types.ts +62 -0
  39. package/src/tools/search/metaSearchAgent.ts +454 -0
  40. package/src/tools/search/search-handlers.ts +85 -0
  41. package/src/tools/search/suggestionGeneratorAgent.ts +54 -0
  42. package/src/types.d.ts +137 -0
  43. package/src/utils/README.md +98 -0
  44. package/src/utils/chat-helpers.ts +18 -0
  45. package/src/utils/index.ts +2 -0
  46. package/src/utils/markdown-to-html.ts +53 -0
  47. package/src/utils/outputParser.ts +73 -0
  48. package/src/utils/provider-image-cropper.ts +130 -0
@@ -0,0 +1,205 @@
1
+ /**
2
+ * Drizzle Storage Adapter
3
+ *
4
+ * Implementation of IMemoryStorage using Drizzle ORM
5
+ */
6
+
7
+ import { sql, eq, and, desc, or, like } from "drizzle-orm";
8
+ import type { IMemoryStorage } from "./storage-interface";
9
+ import type {
10
+ MemoryRecord,
11
+ MemoryType,
12
+ MemorySearchOptions,
13
+ MemoryUpdate,
14
+ } from "../types";
15
+
16
+ /**
17
+ * Drizzle-based storage adapter
18
+ */
19
+ export class DrizzleMemoryStorage implements IMemoryStorage {
20
+ private db: any;
21
+ private tableName: string;
22
+
23
+ constructor(db: any, tableName: string = "user_memories") {
24
+ this.db = db;
25
+ this.tableName = tableName;
26
+ }
27
+
28
+ /**
29
+ * Insert a new memory record
30
+ */
31
+ async insertMemory(
32
+ userId: string,
33
+ memoryType: MemoryType,
34
+ content: string,
35
+ importance: number,
36
+ metadata?: Record<string, any>,
37
+ ): Promise<string> {
38
+ const result = await this.db
39
+ .insert(this.tableName)
40
+ .values({
41
+ user_id: userId,
42
+ memory_type: memoryType,
43
+ content: content,
44
+ importance: importance,
45
+ access_count: 0,
46
+ metadata: metadata || {},
47
+ created_at: new Date(),
48
+ updated_at: new Date(),
49
+ })
50
+ .returning({ id: "id" });
51
+
52
+ return result[0]?.id;
53
+ }
54
+
55
+ /**
56
+ * Find memories by user ID and optional filters
57
+ */
58
+ async findMemories(
59
+ userId: string,
60
+ query?: string,
61
+ limit: number = 10,
62
+ options: MemorySearchOptions = {},
63
+ ): Promise<MemoryRecord[]> {
64
+ const conditions = [eq("user_id", userId)];
65
+
66
+ if (query && query.trim()) {
67
+ conditions.push(like("content", `%${query}%`));
68
+ }
69
+
70
+ if (options.memoryType) {
71
+ conditions.push(eq("memory_type", options.memoryType));
72
+ }
73
+
74
+ const results = await this.db
75
+ .select({
76
+ id: "id",
77
+ user_id: "user_id",
78
+ memory_type: "memory_type",
79
+ content: "content",
80
+ importance: "importance",
81
+ access_count: "access_count",
82
+ metadata: "metadata",
83
+ created_at: "created_at",
84
+ updated_at: "updated_at",
85
+ })
86
+ .from(this.tableName)
87
+ .where(and(...conditions))
88
+ .orderBy(desc("importance"), desc("access_count"), desc("updated_at"))
89
+ .limit(Math.min(limit, 50)); // Cap at 50 for performance
90
+
91
+ return results as MemoryRecord[];
92
+ }
93
+
94
+ /**
95
+ * Find similar memories based on content
96
+ */
97
+ async findSimilarMemories(
98
+ userId: string,
99
+ content: string,
100
+ limit: number = 5,
101
+ ): Promise<MemoryRecord[]> {
102
+ // Simple similarity check using keywords
103
+ const words = content
104
+ .toLowerCase()
105
+ .split(/\s+/)
106
+ .filter((w) => w.length > 2);
107
+ const searchTerms = words.slice(0, 3); // Use first 3 words
108
+
109
+ if (searchTerms.length === 0) {
110
+ return [];
111
+ }
112
+
113
+ const conditions = searchTerms.map((term) => like("content", `%${term}%`));
114
+
115
+ const results = await this.db
116
+ .select()
117
+ .from(this.tableName)
118
+ .where(and(eq("user_id", userId), or(...conditions)))
119
+ .orderBy(desc("importance"), desc("updated_at"))
120
+ .limit(limit);
121
+
122
+ return results as MemoryRecord[];
123
+ }
124
+
125
+ /**
126
+ * Update a memory record
127
+ */
128
+ async updateMemory(id: string, updates: MemoryUpdate): Promise<void> {
129
+ const updateData: any = {};
130
+
131
+ if (updates.importance !== undefined) {
132
+ updateData.importance = updates.importance;
133
+ }
134
+
135
+ if (updates.access_count !== undefined) {
136
+ if (typeof updates.access_count === "object" && updates.access_count.increment) {
137
+ updateData.access_count = sql`access_count + ${updates.access_count.increment}`;
138
+ } else {
139
+ updateData.access_count = updates.access_count;
140
+ }
141
+ }
142
+
143
+ if (updates.updated_at !== undefined) {
144
+ updateData.updated_at = updates.updated_at;
145
+ }
146
+
147
+ if (updates.metadata !== undefined) {
148
+ updateData.metadata = updates.metadata;
149
+ }
150
+
151
+ await this.db.update(this.tableName).set(updateData).where(eq("id", id));
152
+ }
153
+
154
+ /**
155
+ * Delete a memory record
156
+ */
157
+ async deleteMemory(id: string): Promise<void> {
158
+ await this.db.delete(this.tableName).where(eq("id", id));
159
+ }
160
+
161
+ /**
162
+ * Get memory by ID
163
+ */
164
+ async getMemoryById(id: string): Promise<MemoryRecord | null> {
165
+ const results = await this.db
166
+ .select()
167
+ .from(this.tableName)
168
+ .where(eq("id", id))
169
+ .limit(1);
170
+
171
+ return (results[0] as MemoryRecord) || null;
172
+ }
173
+
174
+ /**
175
+ * Batch update memories
176
+ */
177
+ async batchUpdateMemories(
178
+ updates: Array<{ id: string; updates: MemoryUpdate }>,
179
+ ): Promise<void> {
180
+ const promises = updates.map(({ id, updates: updateData }) =>
181
+ this.updateMemory(id, updateData),
182
+ );
183
+ await Promise.allSettled(promises);
184
+ }
185
+ }
186
+
187
+ /**
188
+ * Database schema for memory system
189
+ * This is kept here for reference but should be managed by your migration system
190
+ */
191
+ export function createMemorySchema(db: any) {
192
+ return {
193
+ user_memories: {
194
+ id: "uuid",
195
+ user_id: "string",
196
+ memory_type: "string",
197
+ content: "text",
198
+ importance: "number",
199
+ access_count: "number",
200
+ metadata: "jsonb",
201
+ created_at: "timestamp",
202
+ updated_at: "timestamp",
203
+ },
204
+ };
205
+ }