@multiplayer-app/ai-agent-mongo 0.1.0-beta.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.
- package/README.md +330 -0
- package/dist/__tests__/helpers.d.ts +22 -0
- package/dist/__tests__/helpers.d.ts.map +1 -0
- package/dist/__tests__/helpers.js +75 -0
- package/dist/__tests__/helpers.js.map +1 -0
- package/dist/__tests__/repositories/MongoAgentChatRepository.test.d.ts +2 -0
- package/dist/__tests__/repositories/MongoAgentChatRepository.test.d.ts.map +1 -0
- package/dist/__tests__/repositories/MongoAgentChatRepository.test.js +249 -0
- package/dist/__tests__/repositories/MongoAgentChatRepository.test.js.map +1 -0
- package/dist/__tests__/repositories/MongoAgentMessageRepository.test.d.ts +2 -0
- package/dist/__tests__/repositories/MongoAgentMessageRepository.test.d.ts.map +1 -0
- package/dist/__tests__/repositories/MongoAgentMessageRepository.test.js +311 -0
- package/dist/__tests__/repositories/MongoAgentMessageRepository.test.js.map +1 -0
- package/dist/__tests__/schemas/AgentChatSchema.test.d.ts +2 -0
- package/dist/__tests__/schemas/AgentChatSchema.test.d.ts.map +1 -0
- package/dist/__tests__/schemas/AgentChatSchema.test.js +120 -0
- package/dist/__tests__/schemas/AgentChatSchema.test.js.map +1 -0
- package/dist/__tests__/schemas/AgentMessageSchema.test.d.ts +2 -0
- package/dist/__tests__/schemas/AgentMessageSchema.test.d.ts.map +1 -0
- package/dist/__tests__/schemas/AgentMessageSchema.test.js +293 -0
- package/dist/__tests__/schemas/AgentMessageSchema.test.js.map +1 -0
- package/dist/__tests__/setup.d.ts +2 -0
- package/dist/__tests__/setup.d.ts.map +1 -0
- package/dist/__tests__/setup.js +25 -0
- package/dist/__tests__/setup.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/mongo/config.d.ts +10 -0
- package/dist/mongo/config.d.ts.map +1 -0
- package/dist/mongo/config.js +10 -0
- package/dist/mongo/config.js.map +1 -0
- package/dist/mongo/encryption.d.ts +66 -0
- package/dist/mongo/encryption.d.ts.map +1 -0
- package/dist/mongo/encryption.js +140 -0
- package/dist/mongo/encryption.js.map +1 -0
- package/dist/mongo/index.d.ts +25 -0
- package/dist/mongo/index.d.ts.map +1 -0
- package/dist/mongo/index.js +72 -0
- package/dist/mongo/index.js.map +1 -0
- package/dist/mongo/logger.d.ts +31 -0
- package/dist/mongo/logger.d.ts.map +1 -0
- package/dist/mongo/logger.js +36 -0
- package/dist/mongo/logger.js.map +1 -0
- package/dist/repositories/MongoAgentChatRepository.d.ts +37 -0
- package/dist/repositories/MongoAgentChatRepository.d.ts.map +1 -0
- package/dist/repositories/MongoAgentChatRepository.js +235 -0
- package/dist/repositories/MongoAgentChatRepository.js.map +1 -0
- package/dist/repositories/MongoAgentMessageRepository.d.ts +24 -0
- package/dist/repositories/MongoAgentMessageRepository.d.ts.map +1 -0
- package/dist/repositories/MongoAgentMessageRepository.js +140 -0
- package/dist/repositories/MongoAgentMessageRepository.js.map +1 -0
- package/dist/repositories/index.d.ts +3 -0
- package/dist/repositories/index.d.ts.map +1 -0
- package/dist/repositories/index.js +3 -0
- package/dist/repositories/index.js.map +1 -0
- package/dist/schemas/AgentChatSchema.d.ts +29 -0
- package/dist/schemas/AgentChatSchema.d.ts.map +1 -0
- package/dist/schemas/AgentChatSchema.js +26 -0
- package/dist/schemas/AgentChatSchema.js.map +1 -0
- package/dist/schemas/AgentMessageSchema.d.ts +30 -0
- package/dist/schemas/AgentMessageSchema.d.ts.map +1 -0
- package/dist/schemas/AgentMessageSchema.js +54 -0
- package/dist/schemas/AgentMessageSchema.js.map +1 -0
- package/dist/schemas/index.d.ts +3 -0
- package/dist/schemas/index.d.ts.map +1 -0
- package/dist/schemas/index.js +3 -0
- package/dist/schemas/index.js.map +1 -0
- package/package.json +37 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { AgentMessageModel } from '../schemas/AgentMessageSchema';
|
|
2
|
+
/**
|
|
3
|
+
* Helper function to convert Mongoose document to AgentMessage type
|
|
4
|
+
*/
|
|
5
|
+
function toAgentMessage(doc) {
|
|
6
|
+
if (!doc)
|
|
7
|
+
return null;
|
|
8
|
+
// Use toObject with proper options to ensure all fields are included
|
|
9
|
+
const message = doc.toObject ? doc.toObject({ getters: true, virtuals: false }) : doc;
|
|
10
|
+
return {
|
|
11
|
+
id: doc._id.toString(),
|
|
12
|
+
chat: doc.chat.toString(),
|
|
13
|
+
role: message.role,
|
|
14
|
+
content: message.content,
|
|
15
|
+
createdAt: message.createdAt,
|
|
16
|
+
reasoning: message.reasoning,
|
|
17
|
+
toolCalls: message.toolCalls || [],
|
|
18
|
+
attachments: message.attachments || [],
|
|
19
|
+
annotations: message.annotations,
|
|
20
|
+
tokens: message.tokens,
|
|
21
|
+
agentName: message.agentName,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* MongoDB implementation of AgentMessageRepository
|
|
26
|
+
*/
|
|
27
|
+
export class MongoAgentMessageRepository {
|
|
28
|
+
async findById(id) {
|
|
29
|
+
const doc = await AgentMessageModel.findById(id).exec();
|
|
30
|
+
return toAgentMessage(doc);
|
|
31
|
+
}
|
|
32
|
+
async find(filter) {
|
|
33
|
+
const query = {};
|
|
34
|
+
if (filter) {
|
|
35
|
+
if (filter.id) {
|
|
36
|
+
query._id = filter.id;
|
|
37
|
+
delete filter.id;
|
|
38
|
+
}
|
|
39
|
+
Object.assign(query, filter);
|
|
40
|
+
}
|
|
41
|
+
const docs = await AgentMessageModel.find(query).exec();
|
|
42
|
+
return docs.map(doc => toAgentMessage(doc)).filter(Boolean);
|
|
43
|
+
}
|
|
44
|
+
async findOne(filter) {
|
|
45
|
+
const query = {};
|
|
46
|
+
if (filter.id) {
|
|
47
|
+
query._id = filter.id;
|
|
48
|
+
delete filter.id;
|
|
49
|
+
}
|
|
50
|
+
Object.assign(query, filter);
|
|
51
|
+
const doc = await AgentMessageModel.findOne(query).exec();
|
|
52
|
+
return toAgentMessage(doc);
|
|
53
|
+
}
|
|
54
|
+
async create(entity, id) {
|
|
55
|
+
const now = new Date().toISOString();
|
|
56
|
+
const doc = new AgentMessageModel({
|
|
57
|
+
...entity,
|
|
58
|
+
...(id ? { _id: id } : {}),
|
|
59
|
+
createdAt: now
|
|
60
|
+
});
|
|
61
|
+
const saved = await doc.save();
|
|
62
|
+
const result = toAgentMessage(saved);
|
|
63
|
+
if (!result) {
|
|
64
|
+
throw new Error('Failed to create message');
|
|
65
|
+
}
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
async update(id, updates) {
|
|
69
|
+
const doc = await AgentMessageModel.findByIdAndUpdate(id, { $set: updates }, { new: true }).exec();
|
|
70
|
+
return toAgentMessage(doc);
|
|
71
|
+
}
|
|
72
|
+
async delete(id) {
|
|
73
|
+
const result = await AgentMessageModel.findByIdAndDelete(id).exec();
|
|
74
|
+
return !!result;
|
|
75
|
+
}
|
|
76
|
+
async exists(id) {
|
|
77
|
+
const count = await AgentMessageModel.countDocuments({ _id: id }).exec();
|
|
78
|
+
return count > 0;
|
|
79
|
+
}
|
|
80
|
+
async count(filter) {
|
|
81
|
+
const query = {};
|
|
82
|
+
if (filter) {
|
|
83
|
+
if (filter.id) {
|
|
84
|
+
query._id = filter.id;
|
|
85
|
+
delete filter.id;
|
|
86
|
+
}
|
|
87
|
+
Object.assign(query, filter);
|
|
88
|
+
}
|
|
89
|
+
return AgentMessageModel.countDocuments(query).exec();
|
|
90
|
+
}
|
|
91
|
+
async findByChatId(chatId) {
|
|
92
|
+
const docs = await AgentMessageModel.find({ chat: chatId }).exec();
|
|
93
|
+
return docs.map(doc => toAgentMessage(doc)).filter(Boolean);
|
|
94
|
+
}
|
|
95
|
+
async findByRole(role) {
|
|
96
|
+
const docs = await AgentMessageModel.find({ role }).exec();
|
|
97
|
+
return docs.map(doc => toAgentMessage(doc)).filter(Boolean);
|
|
98
|
+
}
|
|
99
|
+
async findByChatIdAndRole(chatId, role) {
|
|
100
|
+
const query = { chat: chatId };
|
|
101
|
+
if (role) {
|
|
102
|
+
query.role = role;
|
|
103
|
+
}
|
|
104
|
+
const docs = await AgentMessageModel.find(query).exec();
|
|
105
|
+
return docs.map(doc => toAgentMessage(doc)).filter(Boolean);
|
|
106
|
+
}
|
|
107
|
+
async findWithToolCalls(chatId) {
|
|
108
|
+
const query = {
|
|
109
|
+
toolCalls: { $exists: true, $ne: [] }
|
|
110
|
+
};
|
|
111
|
+
if (chatId) {
|
|
112
|
+
query.chat = chatId;
|
|
113
|
+
}
|
|
114
|
+
const docs = await AgentMessageModel.find(query).exec();
|
|
115
|
+
return docs.map(doc => toAgentMessage(doc)).filter(Boolean);
|
|
116
|
+
}
|
|
117
|
+
async findWithAttachments(chatId) {
|
|
118
|
+
const query = {
|
|
119
|
+
attachments: { $exists: true, $ne: [] }
|
|
120
|
+
};
|
|
121
|
+
if (chatId) {
|
|
122
|
+
query.chat = chatId;
|
|
123
|
+
}
|
|
124
|
+
const docs = await AgentMessageModel.find(query).exec();
|
|
125
|
+
return docs.map(doc => toAgentMessage(doc)).filter(Boolean);
|
|
126
|
+
}
|
|
127
|
+
async deleteByChatId(chatId) {
|
|
128
|
+
const result = await AgentMessageModel.deleteMany({ chat: chatId }).exec();
|
|
129
|
+
return result.deletedCount || 0;
|
|
130
|
+
}
|
|
131
|
+
async deleteByRole(role) {
|
|
132
|
+
const result = await AgentMessageModel.deleteMany({ role }).exec();
|
|
133
|
+
return result.deletedCount || 0;
|
|
134
|
+
}
|
|
135
|
+
async deleteByChatIdAndRole(chatId, role) {
|
|
136
|
+
const result = await AgentMessageModel.deleteMany({ chat: chatId, role }).exec();
|
|
137
|
+
return result.deletedCount || 0;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=MongoAgentMessageRepository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MongoAgentMessageRepository.js","sour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CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QACjF,OAAO,MAAM,CAAC,YAAY,IAAI,CAAC,CAAC;IAClC,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/repositories/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,+BAA+B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/repositories/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,+BAA+B,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type ObjectId, type Document } from '../mongo';
|
|
2
|
+
import type { AgentChat } from '@multiplayer-app/ai-agent-types';
|
|
3
|
+
/**
|
|
4
|
+
* Mongoose document interface for AgentChat
|
|
5
|
+
*/
|
|
6
|
+
export interface AgentChatDocument extends Omit<AgentChat, 'id'>, Omit<Document, 'model'> {
|
|
7
|
+
_id: ObjectId;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Mongoose schema for AgentChat
|
|
11
|
+
*/
|
|
12
|
+
export declare const AgentChatSchema: import("mongoose").Schema<AgentChatDocument, import("mongoose").Model<AgentChatDocument, any, any, any, Document<unknown, any, AgentChatDocument, any, {}> & AgentChatDocument & Required<{
|
|
13
|
+
_id: import("mongoose").Types.ObjectId;
|
|
14
|
+
}> & {
|
|
15
|
+
__v: number;
|
|
16
|
+
}, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, AgentChatDocument, Document<unknown, {}, import("mongoose").FlatRecord<AgentChatDocument>, {}, import("mongoose").ResolveSchemaOptions<import("mongoose").DefaultSchemaOptions>> & import("mongoose").FlatRecord<AgentChatDocument> & Required<{
|
|
17
|
+
_id: import("mongoose").Types.ObjectId;
|
|
18
|
+
}> & {
|
|
19
|
+
__v: number;
|
|
20
|
+
}>;
|
|
21
|
+
/**
|
|
22
|
+
* Mongoose model for AgentChat
|
|
23
|
+
*/
|
|
24
|
+
export declare const AgentChatModel: import("mongoose").Model<AgentChatDocument, {}, {}, {}, Document<unknown, {}, AgentChatDocument, {}, {}> & AgentChatDocument & Required<{
|
|
25
|
+
_id: import("mongoose").Types.ObjectId;
|
|
26
|
+
}> & {
|
|
27
|
+
__v: number;
|
|
28
|
+
}, any>;
|
|
29
|
+
//# sourceMappingURL=AgentChatSchema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentChatSchema.d.ts","sourceRoot":"","sources":["../../src/schemas/AgentChatSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,QAAQ,EAAE,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAC;AAC1E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAGjE;;GAEG;AACH,MAAM,WAAW,iBAAkB,SAAQ,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC;IACvF,GAAG,EAAE,QAAQ,CAAC;CACf;AAED;;GAEG;AACH,eAAO,MAAM,eAAe;;;;;;;;EAa1B,CAAC;AAKH;;GAEG;AACH,eAAO,MAAM,cAAc;;;;OAAkE,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { mongoose, Schema } from '../mongo';
|
|
2
|
+
import { ChatType, AgentStatus } from '@multiplayer-app/ai-agent-types';
|
|
3
|
+
/**
|
|
4
|
+
* Mongoose schema for AgentChat
|
|
5
|
+
*/
|
|
6
|
+
export const AgentChatSchema = new Schema({
|
|
7
|
+
title: { type: String, required: false },
|
|
8
|
+
type: { type: String, required: false, enum: Object.values(ChatType), default: ChatType.Chat },
|
|
9
|
+
status: { type: String, required: false, enum: Object.values(AgentStatus) },
|
|
10
|
+
contextKey: { type: String, required: true, index: true },
|
|
11
|
+
model: { type: String },
|
|
12
|
+
createdAt: { type: String, required: true },
|
|
13
|
+
updatedAt: { type: String, required: true },
|
|
14
|
+
metadata: { type: Schema.Types.Mixed },
|
|
15
|
+
userId: { type: String, index: true, sparse: true }
|
|
16
|
+
}, {
|
|
17
|
+
timestamps: false,
|
|
18
|
+
_id: true,
|
|
19
|
+
});
|
|
20
|
+
// Create indexes for common queries
|
|
21
|
+
AgentChatSchema.index({ userId: 1, contextKey: 1 });
|
|
22
|
+
/**
|
|
23
|
+
* Mongoose model for AgentChat
|
|
24
|
+
*/
|
|
25
|
+
export const AgentChatModel = mongoose.model('AgentChat', AgentChatSchema);
|
|
26
|
+
//# sourceMappingURL=AgentChatSchema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentChatSchema.js","sourceRoot":"","sources":["../../src/schemas/AgentChatSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAgC,MAAM,UAAU,CAAC;AAE1E,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AASxE;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,MAAM,CAAoB;IAC3D,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE;IACxC,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,IAAI,EAAE;IAC9F,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE;IAC3E,UAAU,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE;IACzD,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;IACvB,SAAS,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;IAC3C,SAAS,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;IAC3C,QAAQ,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE;IACtC,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE;CACpD,EAAE;IACD,UAAU,EAAE,KAAK;IACjB,GAAG,EAAE,IAAI;CACV,CAAC,CAAC;AAEH,oCAAoC;AACpC,eAAe,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,CAAC,CAAC;AAEpD;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,QAAQ,CAAC,KAAK,CAAoB,WAAW,EAAE,eAAe,CAAC,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type ObjectId, type Document } from '../mongo';
|
|
2
|
+
import type { AgentMessage } from '@multiplayer-app/ai-agent-types';
|
|
3
|
+
/**
|
|
4
|
+
* Mongoose document interface for AgentMessage
|
|
5
|
+
*/
|
|
6
|
+
export interface AgentMessageDocument extends Omit<AgentMessage, 'id' | 'chat'>, Document {
|
|
7
|
+
_id: ObjectId;
|
|
8
|
+
chat: ObjectId;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Mongoose schema for AgentMessage
|
|
12
|
+
*/
|
|
13
|
+
export declare const AgentMessageSchema: import("mongoose").Schema<AgentMessageDocument, import("mongoose").Model<AgentMessageDocument, any, any, any, Document<unknown, any, AgentMessageDocument, any, {}> & AgentMessageDocument & Required<{
|
|
14
|
+
_id: import("mongoose").Types.ObjectId;
|
|
15
|
+
}> & {
|
|
16
|
+
__v: number;
|
|
17
|
+
}, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, AgentMessageDocument, Document<unknown, {}, import("mongoose").FlatRecord<AgentMessageDocument>, {}, import("mongoose").ResolveSchemaOptions<import("mongoose").DefaultSchemaOptions>> & import("mongoose").FlatRecord<AgentMessageDocument> & Required<{
|
|
18
|
+
_id: import("mongoose").Types.ObjectId;
|
|
19
|
+
}> & {
|
|
20
|
+
__v: number;
|
|
21
|
+
}>;
|
|
22
|
+
/**
|
|
23
|
+
* Mongoose model for AgentMessage
|
|
24
|
+
*/
|
|
25
|
+
export declare const AgentMessageModel: import("mongoose").Model<AgentMessageDocument, {}, {}, {}, Document<unknown, {}, AgentMessageDocument, {}, {}> & AgentMessageDocument & Required<{
|
|
26
|
+
_id: import("mongoose").Types.ObjectId;
|
|
27
|
+
}> & {
|
|
28
|
+
__v: number;
|
|
29
|
+
}, any>;
|
|
30
|
+
//# sourceMappingURL=AgentMessageSchema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentMessageSchema.d.ts","sourceRoot":"","sources":["../../src/schemas/AgentMessageSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,QAAQ,EAAE,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAC;AAC1E,OAAO,KAAK,EAAE,YAAY,EAAkC,MAAM,iCAAiC,CAAC;AAGpG;;GAEG;AACH,MAAM,WAAW,oBAAqB,SAAQ,IAAI,CAAC,YAAY,EAAE,IAAI,GAAG,MAAM,CAAC,EAAE,QAAQ;IACvF,GAAG,EAAE,QAAQ,CAAC;IACd,IAAI,EAAE,QAAQ,CAAC;CAChB;AAgCD;;GAEG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;EAa7B,CAAC;AAKH;;GAEG;AACH,eAAO,MAAM,iBAAiB;;;;OAA2E,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { mongoose, Schema } from '../mongo';
|
|
2
|
+
import { MessageRole, AgentToolCallStatus, AgentAttachmentType } from '@multiplayer-app/ai-agent-types';
|
|
3
|
+
/**
|
|
4
|
+
* Schema for AgentToolCall subdocument
|
|
5
|
+
*/
|
|
6
|
+
const AgentToolCallSchema = new Schema({
|
|
7
|
+
id: { type: String, required: true },
|
|
8
|
+
name: { type: String, required: true },
|
|
9
|
+
input: { type: Schema.Types.Mixed, required: true },
|
|
10
|
+
status: { type: String, enum: Object.values(AgentToolCallStatus), required: true },
|
|
11
|
+
output: { type: Schema.Types.Mixed },
|
|
12
|
+
error: { type: String },
|
|
13
|
+
requiresConfirmation: { type: Boolean },
|
|
14
|
+
approved: { type: Boolean },
|
|
15
|
+
approvalId: { type: String },
|
|
16
|
+
reason: { type: String },
|
|
17
|
+
}, { _id: false });
|
|
18
|
+
/**
|
|
19
|
+
* Schema for AgentAttachment subdocument
|
|
20
|
+
*/
|
|
21
|
+
const AgentAttachmentSchema = new Schema({
|
|
22
|
+
id: { type: String, required: true },
|
|
23
|
+
type: { type: String, enum: Object.values(AgentAttachmentType), required: true },
|
|
24
|
+
name: { type: String, required: true },
|
|
25
|
+
url: { type: String },
|
|
26
|
+
mimeType: { type: String },
|
|
27
|
+
// File attachment specific fields
|
|
28
|
+
size: { type: Number },
|
|
29
|
+
metadata: { type: Schema.Types.Mixed }
|
|
30
|
+
}, { _id: false });
|
|
31
|
+
/**
|
|
32
|
+
* Mongoose schema for AgentMessage
|
|
33
|
+
*/
|
|
34
|
+
export const AgentMessageSchema = new Schema({
|
|
35
|
+
chat: { type: Schema.Types.ObjectId, ref: 'AgentChat', required: true },
|
|
36
|
+
role: { type: String, enum: Object.values(MessageRole), required: true },
|
|
37
|
+
content: { type: String, required: true },
|
|
38
|
+
reasoning: { type: String },
|
|
39
|
+
toolCalls: { type: [AgentToolCallSchema], default: [] },
|
|
40
|
+
attachments: { type: [AgentAttachmentSchema], default: [] },
|
|
41
|
+
annotations: { type: Schema.Types.Mixed },
|
|
42
|
+
tokens: { type: Number, default: 0 },
|
|
43
|
+
agentName: { type: String },
|
|
44
|
+
}, {
|
|
45
|
+
timestamps: true,
|
|
46
|
+
_id: true
|
|
47
|
+
});
|
|
48
|
+
// Create index for common queries
|
|
49
|
+
AgentMessageSchema.index({ chat: 1 });
|
|
50
|
+
/**
|
|
51
|
+
* Mongoose model for AgentMessage
|
|
52
|
+
*/
|
|
53
|
+
export const AgentMessageModel = mongoose.model('AgentMessage', AgentMessageSchema);
|
|
54
|
+
//# sourceMappingURL=AgentMessageSchema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentMessageSchema.js","sourceRoot":"","sources":["../../src/schemas/AgentMessageSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAgC,MAAM,UAAU,CAAC;AAE1E,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAUxG;;GAEG;AACH,MAAM,mBAAmB,GAAG,IAAI,MAAM,CAAgB;IACpD,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;IACpC,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;IACtC,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE;IACnD,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE;IAClF,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE;IACpC,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;IACvB,oBAAoB,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE;IACvC,QAAQ,EAAE,EAAE,IAAI,EAAE,O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AC3B,SAAS,EAAE,EAAE,IAAI,EAAE,CAAC,mBAAmB,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE;IACvD,WAAW,EAAE,EAAE,IAAI,EAAE,CAAC,qBAAqB,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE;IAC3D,WAAW,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE;IACzC,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE;IACpC,SAAS,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;CAC5B,EAAE;IACD,UAAU,EAAE,IAAI;IAChB,GAAG,EAAE,IAAI;CACV,CAAC,CAAC;AAEH,kCAAkC;AAClC,kBAAkB,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC;AAEtC;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,QAAQ,CAAC,KAAK,CAAuB,cAAc,EAAE,kBAAkB,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/schemas/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/schemas/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@multiplayer-app/ai-agent-mongo",
|
|
3
|
+
"version": "0.1.0-beta.1",
|
|
4
|
+
"description": "Shared MongoDB schemas and connection for Multiplayer AI agent services",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"README.md"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsc -p tsconfig.json",
|
|
14
|
+
"test": "vitest run",
|
|
15
|
+
"test:watch": "vitest",
|
|
16
|
+
"test:coverage": "vitest run --coverage"
|
|
17
|
+
},
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@multiplayer-app/ai-agent-types": "0.0.1",
|
|
21
|
+
"@multiplayer-app/ai-agent-db": "0.1.0",
|
|
22
|
+
"mongoose": "^8.0.0",
|
|
23
|
+
"mongodb": "^6.0.0",
|
|
24
|
+
"mongodb-client-encryption": "^6.0.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"typescript": "5.9.3",
|
|
28
|
+
"@types/mongoose": "^5.11.97",
|
|
29
|
+
"vitest": "^2.0.0",
|
|
30
|
+
"@vitest/coverage-v8": "^2.0.0",
|
|
31
|
+
"mongodb-memory-server": "^10.1.0",
|
|
32
|
+
"@types/node": "^20.16.0"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
}
|
|
37
|
+
}
|