@ainetwork/adk-provider-memory-mongodb 0.1.6 → 0.1.8

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 (39) hide show
  1. package/dist/chunk-GPOFS7ZT.js +42 -0
  2. package/dist/chunk-GPOFS7ZT.js.map +1 -0
  3. package/dist/chunk-MLPXPX2L.js +50 -0
  4. package/dist/chunk-MLPXPX2L.js.map +1 -0
  5. package/dist/index.cjs +107 -87
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.d.cts +10 -14
  8. package/dist/index.d.ts +10 -14
  9. package/dist/index.js +85 -69
  10. package/dist/index.js.map +1 -1
  11. package/dist/models/intent.model.d.cts +2 -2
  12. package/dist/models/intent.model.d.ts +2 -2
  13. package/dist/models/{chats.model.cjs → messages.model.cjs} +29 -50
  14. package/dist/models/messages.model.cjs.map +1 -0
  15. package/dist/models/messages.model.d.cts +75 -0
  16. package/dist/models/messages.model.d.ts +75 -0
  17. package/dist/models/messages.model.js +11 -0
  18. package/dist/models/threads.model.cjs +77 -0
  19. package/dist/models/threads.model.cjs.map +1 -0
  20. package/dist/models/threads.model.d.cts +44 -0
  21. package/dist/models/threads.model.d.ts +44 -0
  22. package/dist/models/threads.model.js +9 -0
  23. package/dist/models/threads.model.js.map +1 -0
  24. package/implements/base.memory.ts +9 -9
  25. package/implements/intent.memory.ts +18 -6
  26. package/implements/thread.memory.ts +115 -0
  27. package/index.ts +1 -1
  28. package/models/messages.model.ts +61 -0
  29. package/models/threads.model.ts +46 -0
  30. package/package.json +7 -5
  31. package/dist/chunk-N5FAVJ4Z.js +0 -80
  32. package/dist/chunk-N5FAVJ4Z.js.map +0 -1
  33. package/dist/models/chats.model.cjs.map +0 -1
  34. package/dist/models/chats.model.d.cts +0 -105
  35. package/dist/models/chats.model.d.ts +0 -105
  36. package/dist/models/chats.model.js +0 -13
  37. package/implements/session.memory.ts +0 -104
  38. package/models/chats.model.ts +0 -99
  39. /package/dist/models/{chats.model.js.map → messages.model.js.map} +0 -0
@@ -1,105 +0,0 @@
1
- import * as mongoose from 'mongoose';
2
- import { Schema, Document } from 'mongoose';
3
-
4
- declare enum ChatRole {
5
- USER = "USER",
6
- SYSTEM = "SYSTEM",
7
- MODEL = "MODEL"
8
- }
9
- declare const SessionObjectSchema: Schema<any, mongoose.Model<any, any, any, any, any, any>, {}, {}, {}, {}, mongoose.DefaultSchemaOptions, {
10
- sessionId: string;
11
- userId: string;
12
- created_at: number;
13
- updated_at: number;
14
- title?: string | null | undefined;
15
- }, Document<unknown, {}, mongoose.FlatRecord<{
16
- sessionId: string;
17
- userId: string;
18
- created_at: number;
19
- updated_at: number;
20
- title?: string | null | undefined;
21
- }>, {}> & mongoose.FlatRecord<{
22
- sessionId: string;
23
- userId: string;
24
- created_at: number;
25
- updated_at: number;
26
- title?: string | null | undefined;
27
- }> & {
28
- _id: mongoose.Types.ObjectId;
29
- } & {
30
- __v: number;
31
- }>;
32
- interface SessionDocument extends Document {
33
- sessionId: string;
34
- userId: string;
35
- title?: string;
36
- created_at: number;
37
- updated_at: number;
38
- }
39
- declare const ChatContentObjectSchema: Schema<any, mongoose.Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
40
- _id: false;
41
- }, {
42
- type: string;
43
- parts: any[];
44
- }, Document<unknown, {}, mongoose.FlatRecord<{
45
- type: string;
46
- parts: any[];
47
- }>, {}> & mongoose.FlatRecord<{
48
- type: string;
49
- parts: any[];
50
- }> & {
51
- _id: mongoose.Types.ObjectId;
52
- } & {
53
- __v: number;
54
- }>;
55
- declare const ChatObjectSchema: Schema<any, mongoose.Model<any, any, any, any, any, any>, {}, {}, {}, {}, mongoose.DefaultSchemaOptions, {
56
- sessionId: string;
57
- userId: string;
58
- role: ChatRole;
59
- content: {
60
- type: string;
61
- parts: any[];
62
- };
63
- timestamp: number;
64
- metadata: any;
65
- }, Document<unknown, {}, mongoose.FlatRecord<{
66
- sessionId: string;
67
- userId: string;
68
- role: ChatRole;
69
- content: {
70
- type: string;
71
- parts: any[];
72
- };
73
- timestamp: number;
74
- metadata: any;
75
- }>, {}> & mongoose.FlatRecord<{
76
- sessionId: string;
77
- userId: string;
78
- role: ChatRole;
79
- content: {
80
- type: string;
81
- parts: any[];
82
- };
83
- timestamp: number;
84
- metadata: any;
85
- }> & {
86
- _id: mongoose.Types.ObjectId;
87
- } & {
88
- __v: number;
89
- }>;
90
- interface ChatDocument extends Document {
91
- sessionId: string;
92
- role: ChatRole;
93
- content: {
94
- type: string;
95
- parts: any[];
96
- };
97
- timestamp: number;
98
- metadata?: {
99
- [key: string]: unknown;
100
- };
101
- createdAt: Date;
102
- updatedAt: Date;
103
- }
104
-
105
- export { ChatContentObjectSchema, type ChatDocument, ChatObjectSchema, ChatRole, type SessionDocument, SessionObjectSchema };
@@ -1,105 +0,0 @@
1
- import * as mongoose from 'mongoose';
2
- import { Schema, Document } from 'mongoose';
3
-
4
- declare enum ChatRole {
5
- USER = "USER",
6
- SYSTEM = "SYSTEM",
7
- MODEL = "MODEL"
8
- }
9
- declare const SessionObjectSchema: Schema<any, mongoose.Model<any, any, any, any, any, any>, {}, {}, {}, {}, mongoose.DefaultSchemaOptions, {
10
- sessionId: string;
11
- userId: string;
12
- created_at: number;
13
- updated_at: number;
14
- title?: string | null | undefined;
15
- }, Document<unknown, {}, mongoose.FlatRecord<{
16
- sessionId: string;
17
- userId: string;
18
- created_at: number;
19
- updated_at: number;
20
- title?: string | null | undefined;
21
- }>, {}> & mongoose.FlatRecord<{
22
- sessionId: string;
23
- userId: string;
24
- created_at: number;
25
- updated_at: number;
26
- title?: string | null | undefined;
27
- }> & {
28
- _id: mongoose.Types.ObjectId;
29
- } & {
30
- __v: number;
31
- }>;
32
- interface SessionDocument extends Document {
33
- sessionId: string;
34
- userId: string;
35
- title?: string;
36
- created_at: number;
37
- updated_at: number;
38
- }
39
- declare const ChatContentObjectSchema: Schema<any, mongoose.Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
40
- _id: false;
41
- }, {
42
- type: string;
43
- parts: any[];
44
- }, Document<unknown, {}, mongoose.FlatRecord<{
45
- type: string;
46
- parts: any[];
47
- }>, {}> & mongoose.FlatRecord<{
48
- type: string;
49
- parts: any[];
50
- }> & {
51
- _id: mongoose.Types.ObjectId;
52
- } & {
53
- __v: number;
54
- }>;
55
- declare const ChatObjectSchema: Schema<any, mongoose.Model<any, any, any, any, any, any>, {}, {}, {}, {}, mongoose.DefaultSchemaOptions, {
56
- sessionId: string;
57
- userId: string;
58
- role: ChatRole;
59
- content: {
60
- type: string;
61
- parts: any[];
62
- };
63
- timestamp: number;
64
- metadata: any;
65
- }, Document<unknown, {}, mongoose.FlatRecord<{
66
- sessionId: string;
67
- userId: string;
68
- role: ChatRole;
69
- content: {
70
- type: string;
71
- parts: any[];
72
- };
73
- timestamp: number;
74
- metadata: any;
75
- }>, {}> & mongoose.FlatRecord<{
76
- sessionId: string;
77
- userId: string;
78
- role: ChatRole;
79
- content: {
80
- type: string;
81
- parts: any[];
82
- };
83
- timestamp: number;
84
- metadata: any;
85
- }> & {
86
- _id: mongoose.Types.ObjectId;
87
- } & {
88
- __v: number;
89
- }>;
90
- interface ChatDocument extends Document {
91
- sessionId: string;
92
- role: ChatRole;
93
- content: {
94
- type: string;
95
- parts: any[];
96
- };
97
- timestamp: number;
98
- metadata?: {
99
- [key: string]: unknown;
100
- };
101
- createdAt: Date;
102
- updatedAt: Date;
103
- }
104
-
105
- export { ChatContentObjectSchema, type ChatDocument, ChatObjectSchema, ChatRole, type SessionDocument, SessionObjectSchema };
@@ -1,13 +0,0 @@
1
- import {
2
- ChatContentObjectSchema,
3
- ChatObjectSchema,
4
- ChatRole,
5
- SessionObjectSchema
6
- } from "../chunk-N5FAVJ4Z.js";
7
- export {
8
- ChatContentObjectSchema,
9
- ChatObjectSchema,
10
- ChatRole,
11
- SessionObjectSchema
12
- };
13
- //# sourceMappingURL=chats.model.js.map
@@ -1,104 +0,0 @@
1
- import { randomUUID } from "node:crypto";
2
- import type { ChatObject, SessionMetadata, SessionObject } from "@ainetwork/adk/types/memory";
3
- import { ISessionMemory } from "@ainetwork/adk/modules";
4
- import { MongoDBMemory } from "./base.memory";
5
- import {
6
- ChatDocument,
7
- ChatRole,
8
- ChatObjectSchema,
9
- SessionObjectSchema,
10
- SessionDocument
11
- } from "../models/chats.model";
12
- import { loggers } from "@ainetwork/adk/utils/logger";
13
- import { Model } from "mongoose";
14
-
15
- export class MongoDBSession extends MongoDBMemory implements ISessionMemory {
16
- private chatModel: Model<ChatDocument>;
17
- private sessionModel: Model<SessionDocument>;
18
-
19
- constructor(uri: string) {
20
- super(uri);
21
- const _mongoose = super.getInstance();
22
- this.chatModel = _mongoose.model<ChatDocument>("Chat", ChatObjectSchema);
23
- this.sessionModel = _mongoose.model<SessionDocument>("Session", SessionObjectSchema);
24
- }
25
-
26
- public async getSession(userId: string, sessionId: string): Promise<SessionObject | undefined> {
27
- const chats = await this.chatModel.find({ sessionId, userId }).sort({
28
- timestamp: 1,
29
- });
30
- const session = await this.sessionModel.findOne({ sessionId, userId });
31
-
32
- loggers.agent.debug(`Found ${chats.length} chats for session ${sessionId}`);
33
-
34
- const sessionObject: SessionObject = { chats: {} };
35
- sessionObject.title = session?.title;
36
- chats.forEach((chat: ChatDocument) => {
37
- const chatId = chat._id?.toString() || chat.id;
38
- sessionObject.chats[chatId] = {
39
- role: chat.role as ChatRole,
40
- content: chat.content,
41
- timestamp: chat.timestamp,
42
- metadata: chat.metadata,
43
- };
44
- });
45
-
46
- return sessionObject;
47
- };
48
-
49
- public async createSession(userId: string, sessionId: string, title: string): Promise<SessionMetadata> {
50
- const now = Date.now();
51
- await this.sessionModel.create({
52
- sessionId,
53
- userId,
54
- title,
55
- updated_at: now,
56
- created_at: now,
57
- });
58
-
59
- return { title, sessionId, updatedAt: now };
60
- };
61
-
62
- public async addChatToSession(userId: string, sessionId: string, chat: ChatObject): Promise<void> {
63
- const newId = randomUUID();
64
- await this.sessionModel.updateOne({ sessionId, userId }, {
65
- updated_at: Date.now(),
66
- });
67
- await this.chatModel.create({
68
- sessionId,
69
- chatId: newId,
70
- userId,
71
- role: chat.role,
72
- content: chat.content,
73
- timestamp: chat.timestamp,
74
- metadata: chat.metadata,
75
- });
76
- };
77
-
78
- public async deleteSession(userId: string, sessionId: string): Promise<void> {
79
- const chats = await this.chatModel.find({ userId, sessionId }).sort({
80
- timestamp: 1,
81
- });
82
-
83
- chats?.forEach((chat: ChatDocument) => {
84
- chat.deleteOne();
85
- });
86
-
87
- const session = await this.sessionModel.findOne({ sessionId, userId });
88
- session?.deleteOne();
89
- };
90
-
91
- public async listSessions(userId: string): Promise<SessionMetadata[]> {
92
- const sessions = await this.sessionModel.find({ userId }).sort({
93
- updated_at: -1,
94
- });
95
- const data: SessionMetadata[] = sessions.map((session: SessionDocument) => {
96
- return {
97
- sessionId: session.sessionId,
98
- title: session.title,
99
- updatedAt: session.updated_at
100
- } as SessionMetadata;
101
- })
102
- return data;
103
- };
104
- }
@@ -1,99 +0,0 @@
1
- import { type Document, Schema } from "mongoose";
2
-
3
- // ChatRole enum
4
- export enum ChatRole {
5
- USER = "USER",
6
- SYSTEM = "SYSTEM",
7
- MODEL = "MODEL",
8
- }
9
-
10
- export const SessionObjectSchema = new Schema(
11
- {
12
- sessionId: {
13
- type: String,
14
- required: true,
15
- index: true,
16
- },
17
- userId: {
18
- type: String,
19
- required: true,
20
- index: true,
21
- },
22
- title: {
23
- type: String,
24
- required: false,
25
- },
26
- created_at: {
27
- type: Number,
28
- required: true,
29
- },
30
- updated_at: {
31
- type: Number,
32
- required: true,
33
- }
34
- },
35
- );
36
-
37
- export interface SessionDocument extends Document {
38
- sessionId: string;
39
- userId: string;
40
- title?: string;
41
- created_at: number;
42
- updated_at: number;
43
- }
44
-
45
- // ChatContentObject schema
46
- export const ChatContentObjectSchema = new Schema(
47
- {
48
- type: { type: String, required: true },
49
- parts: { type: [Schema.Types.Mixed], required: true },
50
- },
51
- { _id: false },
52
- );
53
-
54
- // ChatObject schema - 개별 문서로 저장
55
- export const ChatObjectSchema = new Schema(
56
- {
57
- sessionId: {
58
- type: String,
59
- required: true,
60
- index: true,
61
- },
62
- userId: {
63
- type: String,
64
- required: true,
65
- index: true,
66
- },
67
- role: {
68
- type: String,
69
- enum: Object.values(ChatRole),
70
- required: true,
71
- },
72
- content: {
73
- type: ChatContentObjectSchema,
74
- required: true,
75
- },
76
- timestamp: {
77
- type: Number,
78
- required: true,
79
- },
80
- metadata: {
81
- type: Schema.Types.Mixed,
82
- default: {},
83
- },
84
- },
85
- );
86
-
87
- // Chat Document interface
88
- export interface ChatDocument extends Document {
89
- sessionId: string;
90
- role: ChatRole;
91
- content: {
92
- type: string;
93
- parts: any[];
94
- };
95
- timestamp: number;
96
- metadata?: { [key: string]: unknown };
97
- createdAt: Date;
98
- updatedAt: Date;
99
- }