@lobehub/lobehub 2.0.0-next.110 → 2.0.0-next.111
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.
- package/CHANGELOG.md +26 -0
- package/changelog/v1.json +9 -0
- package/docs/development/database-schema.dbml +2 -1
- package/package.json +1 -1
- package/packages/context-engine/src/index.ts +1 -1
- package/packages/context-engine/src/providers/KnowledgeInjector.ts +78 -0
- package/packages/context-engine/src/providers/index.ts +2 -0
- package/packages/database/migrations/0047_add_slug_document.sql +1 -5
- package/packages/database/migrations/meta/0047_snapshot.json +30 -14
- package/packages/database/migrations/meta/_journal.json +1 -1
- package/packages/database/src/core/migrations.json +3 -3
- package/packages/database/src/models/__tests__/agent.test.ts +172 -3
- package/packages/database/src/models/__tests__/userMemories.test.ts +1382 -0
- package/packages/database/src/models/agent.ts +17 -0
- package/packages/database/src/models/userMemory.ts +993 -0
- package/packages/database/src/schemas/userMemories.ts +22 -5
- package/packages/prompts/src/prompts/files/__snapshots__/knowledgeBase.test.ts.snap +103 -0
- package/packages/prompts/src/prompts/files/index.ts +3 -0
- package/packages/prompts/src/prompts/files/knowledgeBase.test.ts +167 -0
- package/packages/prompts/src/prompts/files/knowledgeBase.ts +85 -0
- package/packages/types/src/files/index.ts +1 -0
- package/packages/types/src/index.ts +1 -0
- package/packages/types/src/knowledgeBase/index.ts +1 -0
- package/packages/types/src/userMemory/index.ts +3 -0
- package/packages/types/src/userMemory/layers.ts +54 -0
- package/packages/types/src/userMemory/shared.ts +64 -0
- package/packages/types/src/userMemory/tools.ts +240 -0
- package/src/features/ChatList/Messages/index.tsx +16 -19
- package/src/features/ChatList/components/ContextMenu.tsx +23 -16
- package/src/helpers/toolEngineering/index.ts +5 -9
- package/src/hooks/useQueryParam.ts +24 -22
- package/src/server/routers/async/file.ts +2 -7
- package/src/services/chat/contextEngineering.ts +19 -0
- package/src/store/agent/slices/chat/selectors/agent.ts +4 -0
- package/src/store/chat/slices/builtinTool/actions/knowledgeBase.ts +5 -15
- package/src/tools/knowledge-base/ExecutionRuntime/index.ts +3 -3
|
@@ -17,7 +17,7 @@ export const userMemories = pgTable(
|
|
|
17
17
|
memoryCategory: varchar255('memory_category'),
|
|
18
18
|
memoryLayer: varchar255('memory_layer'),
|
|
19
19
|
memoryType: varchar255('memory_type'),
|
|
20
|
-
metadata: jsonb('metadata'),
|
|
20
|
+
metadata: jsonb('metadata').$type<Record<string, unknown>>(),
|
|
21
21
|
tags: text('tags').array(),
|
|
22
22
|
|
|
23
23
|
title: varchar255('title'),
|
|
@@ -55,7 +55,7 @@ export const userMemoriesContexts = pgTable(
|
|
|
55
55
|
userId: text('user_id').references(() => users.id, { onDelete: 'cascade' }),
|
|
56
56
|
userMemoryIds: jsonb('user_memory_ids'),
|
|
57
57
|
|
|
58
|
-
metadata: jsonb('metadata'),
|
|
58
|
+
metadata: jsonb('metadata').$type<Record<string, unknown>>(),
|
|
59
59
|
tags: text('tags').array(),
|
|
60
60
|
|
|
61
61
|
associatedObjects: jsonb('associated_objects'),
|
|
@@ -99,7 +99,7 @@ export const userMemoriesPreferences = pgTable(
|
|
|
99
99
|
onDelete: 'cascade',
|
|
100
100
|
}),
|
|
101
101
|
|
|
102
|
-
metadata: jsonb('metadata'),
|
|
102
|
+
metadata: jsonb('metadata').$type<Record<string, unknown>>(),
|
|
103
103
|
tags: text('tags').array(),
|
|
104
104
|
|
|
105
105
|
conclusionDirectives: text('conclusion_directives'),
|
|
@@ -132,7 +132,7 @@ export const userMemoriesIdentities = pgTable(
|
|
|
132
132
|
onDelete: 'cascade',
|
|
133
133
|
}),
|
|
134
134
|
|
|
135
|
-
metadata: jsonb('metadata'),
|
|
135
|
+
metadata: jsonb('metadata').$type<Record<string, unknown>>(),
|
|
136
136
|
tags: text('tags').array(),
|
|
137
137
|
|
|
138
138
|
type: varchar255('type'),
|
|
@@ -165,7 +165,7 @@ export const userMemoriesExperiences = pgTable(
|
|
|
165
165
|
onDelete: 'cascade',
|
|
166
166
|
}),
|
|
167
167
|
|
|
168
|
-
metadata: jsonb('metadata'),
|
|
168
|
+
metadata: jsonb('metadata').$type<Record<string, unknown>>(),
|
|
169
169
|
tags: text('tags').array(),
|
|
170
170
|
|
|
171
171
|
type: varchar255('type'),
|
|
@@ -200,16 +200,33 @@ export const userMemoriesExperiences = pgTable(
|
|
|
200
200
|
);
|
|
201
201
|
|
|
202
202
|
export type UserMemoryItem = typeof userMemories.$inferSelect;
|
|
203
|
+
export type UserMemoryItemWithoutVectors = Omit<
|
|
204
|
+
UserMemoryItem,
|
|
205
|
+
'summaryVector1024' | 'detailsVector1024'
|
|
206
|
+
>;
|
|
203
207
|
export type NewUserMemory = typeof userMemories.$inferInsert;
|
|
204
208
|
|
|
205
209
|
export type UserMemoryPreference = typeof userMemoriesPreferences.$inferSelect;
|
|
210
|
+
export type UserMemoryPreferencesWithoutVectors = Omit<
|
|
211
|
+
UserMemoryPreference,
|
|
212
|
+
'conclusionDirectivesVector'
|
|
213
|
+
>;
|
|
206
214
|
export type NewUserMemoryPreference = typeof userMemoriesPreferences.$inferInsert;
|
|
207
215
|
|
|
208
216
|
export type UserMemoryContext = typeof userMemoriesContexts.$inferSelect;
|
|
217
|
+
export type UserMemoryContextsWithoutVectors = Omit<
|
|
218
|
+
UserMemoryContext,
|
|
219
|
+
'titleVector' | 'descriptionVector'
|
|
220
|
+
>;
|
|
209
221
|
export type NewUserMemoryContext = typeof userMemoriesContexts.$inferInsert;
|
|
210
222
|
|
|
211
223
|
export type UserMemoryIdentity = typeof userMemoriesIdentities.$inferSelect;
|
|
224
|
+
export type UserMemoryIdentitiesWithoutVectors = Omit<UserMemoryIdentity, 'descriptionVector'>;
|
|
212
225
|
export type NewUserMemoryIdentity = typeof userMemoriesIdentities.$inferInsert;
|
|
213
226
|
|
|
214
227
|
export type UserMemoryExperience = typeof userMemoriesExperiences.$inferSelect;
|
|
228
|
+
export type UserMemoryExperiencesWithoutVectors = Omit<
|
|
229
|
+
UserMemoryExperience,
|
|
230
|
+
'situationVector' | 'actionVector' | 'keyLearningVector'
|
|
231
|
+
>;
|
|
215
232
|
export type NewUserMemoryExperience = typeof userMemoriesExperiences.$inferInsert;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
+
|
|
3
|
+
exports[`promptAgentKnowledge > should format both files and knowledge bases 1`] = `
|
|
4
|
+
"<agent_knowledge>
|
|
5
|
+
<instruction>The following files and knowledge bases are available. For files, refer to their content directly. For knowledge bases, use the searchKnowledgeBase tool to find relevant information.</instruction>
|
|
6
|
+
<files totalCount="1">
|
|
7
|
+
<file id="file1" name="readme.md">
|
|
8
|
+
File content here
|
|
9
|
+
</file>
|
|
10
|
+
</files>
|
|
11
|
+
<knowledge_bases totalCount="1">
|
|
12
|
+
<knowledge_base id="kb1" name="Internal Docs" description="Company knowledge base" />
|
|
13
|
+
</knowledge_bases>
|
|
14
|
+
</agent_knowledge>"
|
|
15
|
+
`;
|
|
16
|
+
|
|
17
|
+
exports[`promptAgentKnowledge > should format only files when no knowledge bases 1`] = `
|
|
18
|
+
"<agent_knowledge>
|
|
19
|
+
<instruction>The following files are available. Refer to their content directly to answer questions. No knowledge bases are associated.</instruction>
|
|
20
|
+
<files totalCount="2">
|
|
21
|
+
<file id="file1" name="doc1.txt">
|
|
22
|
+
This is the content of document 1
|
|
23
|
+
</file>
|
|
24
|
+
<file id="file2" name="doc2.md">
|
|
25
|
+
This is the content of document 2
|
|
26
|
+
</file>
|
|
27
|
+
</files>
|
|
28
|
+
</agent_knowledge>"
|
|
29
|
+
`;
|
|
30
|
+
|
|
31
|
+
exports[`promptAgentKnowledge > should format only knowledge bases when no files 1`] = `
|
|
32
|
+
"<agent_knowledge>
|
|
33
|
+
<instruction>The following knowledge bases are available for semantic search. Use the searchKnowledgeBase tool to find relevant information.</instruction>
|
|
34
|
+
<knowledge_bases totalCount="2">
|
|
35
|
+
<knowledge_base id="kb1" name="Documentation" description="API documentation" />
|
|
36
|
+
<knowledge_base id="kb2" name="FAQs" />
|
|
37
|
+
</knowledge_bases>
|
|
38
|
+
</agent_knowledge>"
|
|
39
|
+
`;
|
|
40
|
+
|
|
41
|
+
exports[`promptAgentKnowledge > should handle file with error 1`] = `
|
|
42
|
+
"<agent_knowledge>
|
|
43
|
+
<instruction>The following files are available. Refer to their content directly to answer questions. No knowledge bases are associated.</instruction>
|
|
44
|
+
<files totalCount="1">
|
|
45
|
+
<file id="file1" name="missing.txt" error="File not found" />
|
|
46
|
+
</files>
|
|
47
|
+
</agent_knowledge>"
|
|
48
|
+
`;
|
|
49
|
+
|
|
50
|
+
exports[`promptAgentKnowledge > should handle file with multiline content 1`] = `
|
|
51
|
+
"<agent_knowledge>
|
|
52
|
+
<instruction>The following files are available. Refer to their content directly to answer questions. No knowledge bases are associated.</instruction>
|
|
53
|
+
<files totalCount="1">
|
|
54
|
+
<file id="file1" name="multiline.txt">
|
|
55
|
+
Line 1
|
|
56
|
+
Line 2
|
|
57
|
+
Line 3
|
|
58
|
+
|
|
59
|
+
Line 5 with gap
|
|
60
|
+
</file>
|
|
61
|
+
</files>
|
|
62
|
+
</agent_knowledge>"
|
|
63
|
+
`;
|
|
64
|
+
|
|
65
|
+
exports[`promptAgentKnowledge > should handle file with special characters in filename 1`] = `
|
|
66
|
+
"<agent_knowledge>
|
|
67
|
+
<instruction>The following files are available. Refer to their content directly to answer questions. No knowledge bases are associated.</instruction>
|
|
68
|
+
<files totalCount="1">
|
|
69
|
+
<file id="file1" name="file with spaces & special-chars.txt">
|
|
70
|
+
Special content
|
|
71
|
+
</file>
|
|
72
|
+
</files>
|
|
73
|
+
</agent_knowledge>"
|
|
74
|
+
`;
|
|
75
|
+
|
|
76
|
+
exports[`promptAgentKnowledge > should handle knowledge base without description 1`] = `
|
|
77
|
+
"<agent_knowledge>
|
|
78
|
+
<instruction>The following knowledge bases are available for semantic search. Use the searchKnowledgeBase tool to find relevant information.</instruction>
|
|
79
|
+
<knowledge_bases totalCount="1">
|
|
80
|
+
<knowledge_base id="kb1" name="Simple KB" />
|
|
81
|
+
</knowledge_bases>
|
|
82
|
+
</agent_knowledge>"
|
|
83
|
+
`;
|
|
84
|
+
|
|
85
|
+
exports[`promptAgentKnowledge > should handle multiple files and multiple knowledge bases 1`] = `
|
|
86
|
+
"<agent_knowledge>
|
|
87
|
+
<instruction>The following files and knowledge bases are available. For files, refer to their content directly. For knowledge bases, use the searchKnowledgeBase tool to find relevant information.</instruction>
|
|
88
|
+
<files totalCount="3">
|
|
89
|
+
<file id="file1" name="first.txt">
|
|
90
|
+
Content of first file
|
|
91
|
+
</file>
|
|
92
|
+
<file id="file2" name="second.md">
|
|
93
|
+
Content of second file
|
|
94
|
+
</file>
|
|
95
|
+
<file id="file3" name="broken.pdf" error="Parse error" />
|
|
96
|
+
</files>
|
|
97
|
+
<knowledge_bases totalCount="3">
|
|
98
|
+
<knowledge_base id="kb1" name="Tech Docs" description="Technical documentation" />
|
|
99
|
+
<knowledge_base id="kb2" name="User Guides" />
|
|
100
|
+
<knowledge_base id="kb3" name="FAQ Database" description="Frequently asked questions" />
|
|
101
|
+
</knowledge_bases>
|
|
102
|
+
</agent_knowledge>"
|
|
103
|
+
`;
|
|
@@ -4,6 +4,9 @@ import { filePrompts } from './file';
|
|
|
4
4
|
import { imagesPrompts } from './image';
|
|
5
5
|
import { videosPrompts } from './video';
|
|
6
6
|
|
|
7
|
+
export type { KnowledgeBaseInfo, PromptKnowledgeOptions } from './knowledgeBase';
|
|
8
|
+
export { promptAgentKnowledge } from './knowledgeBase';
|
|
9
|
+
|
|
7
10
|
export const filesPrompts = ({
|
|
8
11
|
imageList,
|
|
9
12
|
fileList,
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import type { FileContent } from '../knowledgeBaseQA';
|
|
4
|
+
import { promptAgentKnowledge } from './knowledgeBase';
|
|
5
|
+
import type { KnowledgeBaseInfo } from './knowledgeBase';
|
|
6
|
+
|
|
7
|
+
describe('promptAgentKnowledge', () => {
|
|
8
|
+
it('should return empty string when no files and no knowledge bases', () => {
|
|
9
|
+
const result = promptAgentKnowledge({});
|
|
10
|
+
expect(result).toBe('');
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('should format only files when no knowledge bases', () => {
|
|
14
|
+
const fileContents: FileContent[] = [
|
|
15
|
+
{
|
|
16
|
+
content: 'This is the content of document 1',
|
|
17
|
+
fileId: 'file1',
|
|
18
|
+
filename: 'doc1.txt',
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
content: 'This is the content of document 2',
|
|
22
|
+
fileId: 'file2',
|
|
23
|
+
filename: 'doc2.md',
|
|
24
|
+
},
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
const result = promptAgentKnowledge({ fileContents });
|
|
28
|
+
expect(result).toMatchSnapshot();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('should format only knowledge bases when no files', () => {
|
|
32
|
+
const knowledgeBases: KnowledgeBaseInfo[] = [
|
|
33
|
+
{
|
|
34
|
+
description: 'API documentation',
|
|
35
|
+
id: 'kb1',
|
|
36
|
+
name: 'Documentation',
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
description: null,
|
|
40
|
+
id: 'kb2',
|
|
41
|
+
name: 'FAQs',
|
|
42
|
+
},
|
|
43
|
+
];
|
|
44
|
+
|
|
45
|
+
const result = promptAgentKnowledge({ knowledgeBases });
|
|
46
|
+
expect(result).toMatchSnapshot();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('should format both files and knowledge bases', () => {
|
|
50
|
+
const fileContents: FileContent[] = [
|
|
51
|
+
{
|
|
52
|
+
content: 'File content here',
|
|
53
|
+
fileId: 'file1',
|
|
54
|
+
filename: 'readme.md',
|
|
55
|
+
},
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
const knowledgeBases: KnowledgeBaseInfo[] = [
|
|
59
|
+
{
|
|
60
|
+
description: 'Company knowledge base',
|
|
61
|
+
id: 'kb1',
|
|
62
|
+
name: 'Internal Docs',
|
|
63
|
+
},
|
|
64
|
+
];
|
|
65
|
+
|
|
66
|
+
const result = promptAgentKnowledge({ fileContents, knowledgeBases });
|
|
67
|
+
expect(result).toMatchSnapshot();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('should handle file with error', () => {
|
|
71
|
+
const fileContents: FileContent[] = [
|
|
72
|
+
{
|
|
73
|
+
content: '',
|
|
74
|
+
error: 'File not found',
|
|
75
|
+
fileId: 'file1',
|
|
76
|
+
filename: 'missing.txt',
|
|
77
|
+
},
|
|
78
|
+
];
|
|
79
|
+
|
|
80
|
+
const result = promptAgentKnowledge({ fileContents });
|
|
81
|
+
expect(result).toMatchSnapshot();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('should handle multiple files and multiple knowledge bases', () => {
|
|
85
|
+
const fileContents: FileContent[] = [
|
|
86
|
+
{
|
|
87
|
+
content: 'Content of first file',
|
|
88
|
+
fileId: 'file1',
|
|
89
|
+
filename: 'first.txt',
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
content: 'Content of second file',
|
|
93
|
+
fileId: 'file2',
|
|
94
|
+
filename: 'second.md',
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
content: '',
|
|
98
|
+
error: 'Parse error',
|
|
99
|
+
fileId: 'file3',
|
|
100
|
+
filename: 'broken.pdf',
|
|
101
|
+
},
|
|
102
|
+
];
|
|
103
|
+
|
|
104
|
+
const knowledgeBases: KnowledgeBaseInfo[] = [
|
|
105
|
+
{
|
|
106
|
+
description: 'Technical documentation',
|
|
107
|
+
id: 'kb1',
|
|
108
|
+
name: 'Tech Docs',
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
description: null,
|
|
112
|
+
id: 'kb2',
|
|
113
|
+
name: 'User Guides',
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
description: 'Frequently asked questions',
|
|
117
|
+
id: 'kb3',
|
|
118
|
+
name: 'FAQ Database',
|
|
119
|
+
},
|
|
120
|
+
];
|
|
121
|
+
|
|
122
|
+
const result = promptAgentKnowledge({ fileContents, knowledgeBases });
|
|
123
|
+
expect(result).toMatchSnapshot();
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('should handle knowledge base without description', () => {
|
|
127
|
+
const knowledgeBases: KnowledgeBaseInfo[] = [
|
|
128
|
+
{
|
|
129
|
+
id: 'kb1',
|
|
130
|
+
name: 'Simple KB',
|
|
131
|
+
},
|
|
132
|
+
];
|
|
133
|
+
|
|
134
|
+
const result = promptAgentKnowledge({ knowledgeBases });
|
|
135
|
+
expect(result).toMatchSnapshot();
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('should handle file with special characters in filename', () => {
|
|
139
|
+
const fileContents: FileContent[] = [
|
|
140
|
+
{
|
|
141
|
+
content: 'Special content',
|
|
142
|
+
fileId: 'file1',
|
|
143
|
+
filename: 'file with spaces & special-chars.txt',
|
|
144
|
+
},
|
|
145
|
+
];
|
|
146
|
+
|
|
147
|
+
const result = promptAgentKnowledge({ fileContents });
|
|
148
|
+
expect(result).toMatchSnapshot();
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('should handle file with multiline content', () => {
|
|
152
|
+
const fileContents: FileContent[] = [
|
|
153
|
+
{
|
|
154
|
+
content: `Line 1
|
|
155
|
+
Line 2
|
|
156
|
+
Line 3
|
|
157
|
+
|
|
158
|
+
Line 5 with gap`,
|
|
159
|
+
fileId: 'file1',
|
|
160
|
+
filename: 'multiline.txt',
|
|
161
|
+
},
|
|
162
|
+
];
|
|
163
|
+
|
|
164
|
+
const result = promptAgentKnowledge({ fileContents });
|
|
165
|
+
expect(result).toMatchSnapshot();
|
|
166
|
+
});
|
|
167
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { FileContent } from '../knowledgeBaseQA';
|
|
2
|
+
|
|
3
|
+
export interface KnowledgeBaseInfo {
|
|
4
|
+
description?: string | null;
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface PromptKnowledgeOptions {
|
|
10
|
+
/** File contents to inject */
|
|
11
|
+
fileContents?: FileContent[];
|
|
12
|
+
/** Knowledge bases to include */
|
|
13
|
+
knowledgeBases?: KnowledgeBaseInfo[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Formats a single file content with XML tags
|
|
18
|
+
*/
|
|
19
|
+
const formatFileContent = (file: FileContent): string => {
|
|
20
|
+
if (file.error) {
|
|
21
|
+
return `<file id="${file.fileId}" name="${file.filename}" error="${file.error}" />`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return `<file id="${file.fileId}" name="${file.filename}">
|
|
25
|
+
${file.content}
|
|
26
|
+
</file>`;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Format agent knowledge (files + knowledge bases) as unified XML prompt
|
|
31
|
+
*/
|
|
32
|
+
export const promptAgentKnowledge = ({
|
|
33
|
+
fileContents = [],
|
|
34
|
+
knowledgeBases = [],
|
|
35
|
+
}: PromptKnowledgeOptions) => {
|
|
36
|
+
const hasFiles = fileContents.length > 0;
|
|
37
|
+
const hasKnowledgeBases = knowledgeBases.length > 0;
|
|
38
|
+
|
|
39
|
+
// If no knowledge at all, return empty
|
|
40
|
+
if (!hasFiles && !hasKnowledgeBases) {
|
|
41
|
+
return '';
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const contentParts: string[] = [];
|
|
45
|
+
|
|
46
|
+
// Add instruction based on what's available
|
|
47
|
+
if (hasFiles && hasKnowledgeBases) {
|
|
48
|
+
contentParts.push(
|
|
49
|
+
'<instruction>The following files and knowledge bases are available. For files, refer to their content directly. For knowledge bases, use the searchKnowledgeBase tool to find relevant information.</instruction>',
|
|
50
|
+
);
|
|
51
|
+
} else if (hasFiles) {
|
|
52
|
+
contentParts.push(
|
|
53
|
+
'<instruction>The following files are available. Refer to their content directly to answer questions. No knowledge bases are associated.</instruction>',
|
|
54
|
+
);
|
|
55
|
+
} else {
|
|
56
|
+
contentParts.push(
|
|
57
|
+
'<instruction>The following knowledge bases are available for semantic search. Use the searchKnowledgeBase tool to find relevant information.</instruction>',
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Add files section
|
|
62
|
+
if (hasFiles) {
|
|
63
|
+
const filesXml = fileContents.map((file) => formatFileContent(file)).join('\n');
|
|
64
|
+
contentParts.push(`<files totalCount="${fileContents.length}">
|
|
65
|
+
${filesXml}
|
|
66
|
+
</files>`);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Add knowledge bases section
|
|
70
|
+
if (hasKnowledgeBases) {
|
|
71
|
+
const kbItems = knowledgeBases
|
|
72
|
+
.map(
|
|
73
|
+
(kb) =>
|
|
74
|
+
`<knowledge_base id="${kb.id}" name="${kb.name}"${kb.description ? ` description="${kb.description}"` : ''} />`,
|
|
75
|
+
)
|
|
76
|
+
.join('\n');
|
|
77
|
+
contentParts.push(`<knowledge_bases totalCount="${knowledgeBases.length}">
|
|
78
|
+
${kbItems}
|
|
79
|
+
</knowledge_bases>`);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return `<agent_knowledge>
|
|
83
|
+
${contentParts.join('\n')}
|
|
84
|
+
</agent_knowledge>`;
|
|
85
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export interface UserMemoryTimestamps {
|
|
2
|
+
accessedAt: Date;
|
|
3
|
+
createdAt: Date;
|
|
4
|
+
updatedAt: Date;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface UserMemoryContext extends UserMemoryTimestamps {
|
|
8
|
+
associatedObjects: Record<string, unknown>[] | null;
|
|
9
|
+
associatedSubjects: Record<string, unknown>[] | null;
|
|
10
|
+
currentStatus: string | null;
|
|
11
|
+
description: string | null;
|
|
12
|
+
descriptionVector: number[] | null;
|
|
13
|
+
id: string;
|
|
14
|
+
metadata: Record<string, unknown> | null;
|
|
15
|
+
scoreImpact: number | null;
|
|
16
|
+
scoreUrgency: number | null;
|
|
17
|
+
tags: string[] | null;
|
|
18
|
+
title: string | null;
|
|
19
|
+
titleVector: number[] | null;
|
|
20
|
+
type: string | null;
|
|
21
|
+
userId: string | null;
|
|
22
|
+
userMemoryIds: string[] | null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface UserMemoryExperience extends UserMemoryTimestamps {
|
|
26
|
+
action: string | null;
|
|
27
|
+
actionVector: number[] | null;
|
|
28
|
+
id: string;
|
|
29
|
+
keyLearning: string | null;
|
|
30
|
+
keyLearningVector: number[] | null;
|
|
31
|
+
metadata: Record<string, unknown> | null;
|
|
32
|
+
possibleOutcome: string | null;
|
|
33
|
+
reasoning: string | null;
|
|
34
|
+
scoreConfidence: number | null;
|
|
35
|
+
situation: string | null;
|
|
36
|
+
situationVector: number[] | null;
|
|
37
|
+
tags: string[] | null;
|
|
38
|
+
type: string | null;
|
|
39
|
+
userId: string | null;
|
|
40
|
+
userMemoryId: string | null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface UserMemoryPreference extends UserMemoryTimestamps {
|
|
44
|
+
conclusionDirectives: string | null;
|
|
45
|
+
conclusionDirectivesVector: number[] | null;
|
|
46
|
+
id: string;
|
|
47
|
+
metadata: Record<string, unknown> | null;
|
|
48
|
+
scorePriority: number | null;
|
|
49
|
+
suggestions: string | null;
|
|
50
|
+
tags: string[] | null;
|
|
51
|
+
type: string | null;
|
|
52
|
+
userId: string | null;
|
|
53
|
+
userMemoryId: string | null;
|
|
54
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export enum RelationshipEnum {
|
|
2
|
+
Aunt = 'aunt',
|
|
3
|
+
Brother = 'brother',
|
|
4
|
+
Classmate = 'classmate',
|
|
5
|
+
Colleague = 'colleague',
|
|
6
|
+
Couple = 'couple',
|
|
7
|
+
Coworker = 'coworker',
|
|
8
|
+
Daughter = 'daughter',
|
|
9
|
+
Father = 'father',
|
|
10
|
+
Friend = 'friend',
|
|
11
|
+
Granddaughter = 'granddaughter',
|
|
12
|
+
Grandfather = 'grandfather',
|
|
13
|
+
Grandmother = 'grandmother',
|
|
14
|
+
Grandson = 'grandson',
|
|
15
|
+
Husband = 'husband',
|
|
16
|
+
Manager = 'manager',
|
|
17
|
+
Mentee = 'mentee',
|
|
18
|
+
Mentor = 'mentor',
|
|
19
|
+
Mother = 'mother',
|
|
20
|
+
Nephew = 'nephew',
|
|
21
|
+
Niece = 'niece',
|
|
22
|
+
Other = 'other',
|
|
23
|
+
Partner = 'partner',
|
|
24
|
+
Self = 'self',
|
|
25
|
+
Sibling = 'sibling',
|
|
26
|
+
Sister = 'sister',
|
|
27
|
+
Son = 'son',
|
|
28
|
+
Spouse = 'spouse',
|
|
29
|
+
Teammate = 'teammate',
|
|
30
|
+
Uncle = 'uncle',
|
|
31
|
+
Wife = 'wife',
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export enum MergeStrategyEnum {
|
|
35
|
+
Merge = 'merge',
|
|
36
|
+
Replace = 'replace',
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export enum IdentityTypeEnum {
|
|
40
|
+
Demographic = 'demographic',
|
|
41
|
+
Personal = 'personal',
|
|
42
|
+
Professional = 'professional',
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export enum LayersEnum {
|
|
46
|
+
Activity = 'activity',
|
|
47
|
+
Context = 'context',
|
|
48
|
+
Experience = 'experience',
|
|
49
|
+
Identity = 'identity',
|
|
50
|
+
Preference = 'preference',
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export enum TypesEnum {
|
|
54
|
+
Activity = 'activity',
|
|
55
|
+
Context = 'context',
|
|
56
|
+
Event = 'event',
|
|
57
|
+
Fact = 'fact',
|
|
58
|
+
Location = 'location',
|
|
59
|
+
Other = 'other',
|
|
60
|
+
People = 'people',
|
|
61
|
+
Preference = 'preference',
|
|
62
|
+
Technology = 'technology',
|
|
63
|
+
Topic = 'topic',
|
|
64
|
+
}
|