@ainetwork/adk-provider-memory-mongodb 0.2.4 → 0.3.2

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.
@@ -0,0 +1,23 @@
1
+ import mongoose, { Schema, Document } from 'mongoose';
2
+
3
+ declare const AgentObjectSchema: Schema<any, mongoose.Model<any, any, any, any, any, any>, {}, {}, {}, {}, mongoose.DefaultSchemaOptions, {
4
+ agent_prompt?: string | null | undefined;
5
+ }, Document<unknown, {}, mongoose.FlatRecord<{
6
+ agent_prompt?: string | null | undefined;
7
+ }>, {}> & mongoose.FlatRecord<{
8
+ agent_prompt?: string | null | undefined;
9
+ }> & {
10
+ _id: mongoose.Types.ObjectId;
11
+ } & {
12
+ __v: number;
13
+ }>;
14
+ interface AgentDocument extends Document {
15
+ agent_prompt: string;
16
+ }
17
+ declare const AgentModel: mongoose.Model<AgentDocument, {}, {}, {}, Document<unknown, {}, AgentDocument, {}> & AgentDocument & Required<{
18
+ _id: unknown;
19
+ }> & {
20
+ __v: number;
21
+ }, any>;
22
+
23
+ export { type AgentDocument, AgentModel, AgentObjectSchema };
@@ -0,0 +1,9 @@
1
+ import {
2
+ AgentModel,
3
+ AgentObjectSchema
4
+ } from "../chunk-OWGGE5EW.js";
5
+ export {
6
+ AgentModel,
7
+ AgentObjectSchema
8
+ };
9
+ //# sourceMappingURL=agent.model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,46 @@
1
+ import { IAgentMemory } from "@ainetwork/adk/modules";
2
+ import { AgentModel } from "../models/agent.model";
3
+
4
+ export type ExecuteWithRetryFn = <T>(
5
+ operation: () => Promise<T>,
6
+ operationName?: string
7
+ ) => Promise<T>;
8
+
9
+ export type GetOperationTimeoutFn = () => number;
10
+
11
+ type AgentMetadata = {
12
+ agent_prompt: string;
13
+ }
14
+
15
+ export class MongoDBAgent implements IAgentMemory {
16
+ private executeWithRetry: ExecuteWithRetryFn;
17
+ private getOperationTimeout: GetOperationTimeoutFn;
18
+
19
+ constructor(
20
+ executeWithRetry: ExecuteWithRetryFn,
21
+ getOperationTimeout: GetOperationTimeoutFn
22
+ ) {
23
+ this.executeWithRetry = executeWithRetry;
24
+ this.getOperationTimeout = getOperationTimeout;
25
+ }
26
+
27
+ public async getAgentPrompt(): Promise<string> {
28
+ return this.executeWithRetry(async () => {
29
+ const timeout = this.getOperationTimeout();
30
+ const metadata = await AgentModel.findOne({
31
+ id: "agent_metadata"
32
+ }).maxTimeMS(timeout)
33
+ .lean<AgentMetadata>();
34
+ return metadata?.agent_prompt || "";
35
+ }, "getAgentPrompt()");
36
+ };
37
+
38
+ public async updateAgentPrompt(prompt: string): Promise<void> {
39
+ return this.executeWithRetry(async () => {
40
+ const timeout = this.getOperationTimeout();
41
+ await AgentModel.updateOne({
42
+ id: "agent_metadata",
43
+ }, { "agent_prompt": prompt }).maxTimeMS(timeout);
44
+ }, "updateAgentPrompt()");
45
+ };
46
+ }
@@ -1,6 +1,9 @@
1
- import { IMemory } from "node_modules/@ainetwork/adk/dist/esm/modules/memory/base.memory";
1
+ import { IAgentMemory, IIntentMemory, IMemory, IThreadMemory } from "node_modules/@ainetwork/adk/dist/esm/modules/memory/base.memory";
2
2
  import mongoose from "mongoose";
3
3
  import { loggers } from "@ainetwork/adk/utils/logger";
4
+ import { MongoDBAgent } from "./agent.memory";
5
+ import { MongoDBIntent } from "./intent.memory";
6
+ import { MongoDBThread } from "./thread.memory";
4
7
 
5
8
  export interface MongoDBMemoryConfig {
6
9
  uri: string;
@@ -25,6 +28,10 @@ export class MongoDBMemory implements IMemory {
25
28
  private eventListenersSetup: boolean = false;
26
29
  private operationTimeoutMS: number;
27
30
 
31
+ private agentMemory: MongoDBAgent;
32
+ private intentMemory: MongoDBIntent;
33
+ private threadMemory: MongoDBThread;
34
+
28
35
  constructor(config: string | MongoDBMemoryConfig) {
29
36
  const cfg = typeof config === 'string' ? { uri: config } : config;
30
37
 
@@ -48,6 +55,33 @@ export class MongoDBMemory implements IMemory {
48
55
  this.connected = MongoDBMemory.instance.connected;
49
56
  this.operationTimeoutMS = MongoDBMemory.instance.operationTimeoutMS;
50
57
  }
58
+
59
+ this.agentMemory = new MongoDBAgent(
60
+ this.executeWithRetry.bind(this),
61
+ this.getOperationTimeout.bind(this)
62
+ );
63
+
64
+ this.threadMemory = new MongoDBThread(
65
+ this.executeWithRetry.bind(this),
66
+ this.getOperationTimeout.bind(this)
67
+ );
68
+
69
+ this.intentMemory = new MongoDBIntent(
70
+ this.executeWithRetry.bind(this),
71
+ this.getOperationTimeout.bind(this)
72
+ );
73
+ }
74
+
75
+ public getAgentMemory(): IAgentMemory {
76
+ return this.agentMemory;
77
+ }
78
+
79
+ public getThreadMemory(): IThreadMemory {
80
+ return this.threadMemory;
81
+ }
82
+
83
+ public getIntentMemory(): IIntentMemory {
84
+ return this.intentMemory;
51
85
  }
52
86
 
53
87
  private setupMongooseEventListeners(): void {
@@ -1,9 +1,26 @@
1
1
  import type { Intent } from "@ainetwork/adk/types/memory";
2
2
  import { IIntentMemory } from "@ainetwork/adk/modules";
3
- import { MongoDBMemory } from "./base.memory";
4
3
  import { IntentModel } from "../models/intent.model";
5
4
 
6
- export class MongoDBIntent extends MongoDBMemory implements IIntentMemory {
5
+ export type ExecuteWithRetryFn = <T>(
6
+ operation: () => Promise<T>,
7
+ operationName?: string
8
+ ) => Promise<T>;
9
+
10
+ export type GetOperationTimeoutFn = () => number;
11
+
12
+ export class MongoDBIntent implements IIntentMemory {
13
+ private executeWithRetry: ExecuteWithRetryFn;
14
+ private getOperationTimeout: GetOperationTimeoutFn;
15
+
16
+ constructor(
17
+ executeWithRetry: ExecuteWithRetryFn,
18
+ getOperationTimeout: GetOperationTimeoutFn
19
+ ) {
20
+ this.executeWithRetry = executeWithRetry;
21
+ this.getOperationTimeout = getOperationTimeout;
22
+ }
23
+
7
24
  public async getIntent(intentId: string): Promise<Intent | undefined> {
8
25
  return this.executeWithRetry(async () => {
9
26
  const timeout = this.getOperationTimeout();
@@ -1,14 +1,27 @@
1
1
  import type { MessageObject, ThreadMetadata, ThreadObject, ThreadType } from "@ainetwork/adk/types/memory";
2
2
  import { MessageRole } from "@ainetwork/adk/types/memory";
3
3
  import { IThreadMemory } from "@ainetwork/adk/modules";
4
- import { MongoDBMemory } from "./base.memory";
5
4
  import { ThreadDocument, ThreadModel } from "../models/threads.model";
6
5
  import { MessageDocument, MessageModel } from "../models/messages.model";
7
6
  import { loggers } from "@ainetwork/adk/utils/logger";
8
7
 
9
- export class MongoDBThread extends MongoDBMemory implements IThreadMemory {
10
- constructor(uri: string) {
11
- super(uri);
8
+ export type ExecuteWithRetryFn = <T>(
9
+ operation: () => Promise<T>,
10
+ operationName?: string
11
+ ) => Promise<T>;
12
+
13
+ export type GetOperationTimeoutFn = () => number;
14
+
15
+ export class MongoDBThread implements IThreadMemory {
16
+ private executeWithRetry: ExecuteWithRetryFn;
17
+ private getOperationTimeout: GetOperationTimeoutFn;
18
+
19
+ constructor(
20
+ executeWithRetry: ExecuteWithRetryFn,
21
+ getOperationTimeout: GetOperationTimeoutFn
22
+ ) {
23
+ this.executeWithRetry = executeWithRetry;
24
+ this.getOperationTimeout = getOperationTimeout;
12
25
  }
13
26
 
14
27
  public async getThread(
package/index.ts CHANGED
@@ -1,4 +1,2 @@
1
- export { MongoDBThread } from "./implements/thread.memory";
2
- export { MongoDBIntent } from "./implements/intent.memory";
3
1
  export { MongoDBMemory } from "./implements/base.memory";
4
2
  export type { MongoDBMemoryConfig } from "./implements/base.memory";
@@ -0,0 +1,16 @@
1
+ import { type Document, Schema } from "mongoose";
2
+ import mongoose from "mongoose";
3
+
4
+ export const AgentObjectSchema = new Schema(
5
+ {
6
+ agent_prompt: {
7
+ type: String,
8
+ },
9
+ },
10
+ );
11
+
12
+ export interface AgentDocument extends Document {
13
+ agent_prompt: string;
14
+ }
15
+
16
+ export const AgentModel = mongoose.model<AgentDocument>("Agent", AgentObjectSchema);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ainetwork/adk-provider-memory-mongodb",
3
- "version": "0.2.4",
3
+ "version": "0.3.2",
4
4
  "author": "AI Network (https://ainetwork.ai)",
5
5
  "type": "module",
6
6
  "engines": {
@@ -28,7 +28,7 @@
28
28
  "clean": "rm -rf dist"
29
29
  },
30
30
  "dependencies": {
31
- "@ainetwork/adk": "0.2.9",
31
+ "@ainetwork/adk": "^0.3.2",
32
32
  "mongoose": "^8.16.5"
33
33
  },
34
34
  "devDependencies": {
@@ -38,5 +38,5 @@
38
38
  "publishConfig": {
39
39
  "access": "public"
40
40
  },
41
- "gitHead": "f1315510a23dd44492dc20737c4be71188d01e26"
41
+ "gitHead": "4bfa5afae29304e6cb5f106c7327f5f2092f6601"
42
42
  }