@ainetwork/adk-provider-memory-mongodb 0.4.1 → 0.5.0
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/dist/{chunk-EPJZT2YE.js → chunk-2XJ6S2W5.js} +6 -1
- package/dist/chunk-2XJ6S2W5.js.map +1 -0
- package/dist/{chunk-T5WRFXBY.js → chunk-QULDFKGZ.js} +2 -1
- package/dist/chunk-QULDFKGZ.js.map +1 -0
- package/dist/chunk-RC275GLE.js +70 -0
- package/dist/chunk-RC275GLE.js.map +1 -0
- package/dist/{chunk-ENGJ6NTO.js → chunk-SJ2FHHN6.js} +10 -10
- package/dist/chunk-SJ2FHHN6.js.map +1 -0
- package/dist/index.cjs +235 -67
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.js +155 -55
- package/dist/index.js.map +1 -1
- package/dist/models/messages.model.cjs +1 -0
- package/dist/models/messages.model.cjs.map +1 -1
- package/dist/models/messages.model.js +1 -1
- package/dist/models/threads.model.cjs +5 -0
- package/dist/models/threads.model.cjs.map +1 -1
- package/dist/models/threads.model.d.cts +4 -0
- package/dist/models/threads.model.d.ts +4 -0
- package/dist/models/threads.model.js +1 -1
- package/dist/models/user-workflow.model.cjs +105 -0
- package/dist/models/user-workflow.model.cjs.map +1 -0
- package/dist/models/user-workflow.model.d.cts +92 -0
- package/dist/models/user-workflow.model.d.ts +92 -0
- package/dist/models/user-workflow.model.js +9 -0
- package/dist/models/{workflow.model.cjs → workflow-template.model.cjs} +15 -15
- package/dist/models/workflow-template.model.cjs.map +1 -0
- package/dist/models/{workflow.model.d.ts → workflow-template.model.d.cts} +10 -13
- package/dist/models/{workflow.model.d.cts → workflow-template.model.d.ts} +10 -13
- package/dist/models/workflow-template.model.js +9 -0
- package/dist/models/workflow-template.model.js.map +1 -0
- package/implements/base.memory.ts +49 -12
- package/implements/thread.memory.ts +31 -16
- package/implements/user-workflow.memory.ts +87 -0
- package/implements/workflow-template.memory.ts +69 -0
- package/models/messages.model.ts +2 -0
- package/models/threads.model.ts +6 -0
- package/models/user-workflow.model.ts +91 -0
- package/models/{workflow.model.ts → workflow-template.model.ts} +10 -10
- package/package.json +3 -3
- package/dist/chunk-ENGJ6NTO.js.map +0 -1
- package/dist/chunk-EPJZT2YE.js.map +0 -1
- package/dist/chunk-T5WRFXBY.js.map +0 -1
- package/dist/models/workflow.model.cjs.map +0 -1
- package/dist/models/workflow.model.js +0 -9
- package/implements/workflow.memory.ts +0 -78
- /package/dist/models/{workflow.model.js.map → user-workflow.model.js.map} +0 -0
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import type { IWorkflowMemory } from "@ainetwork/adk/modules";
|
|
2
|
-
import type { Workflow } from "@ainetwork/adk/types/memory";
|
|
3
|
-
import { WorkflowModel } from "../models/workflow.model";
|
|
4
|
-
|
|
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 MongoDBWorkflow implements IWorkflowMemory {
|
|
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
|
-
|
|
24
|
-
public async createWorkflow(workflow: Workflow): Promise<Workflow> {
|
|
25
|
-
return this.executeWithRetry(async () => {
|
|
26
|
-
const timeout = this.getOperationTimeout();
|
|
27
|
-
const created = await WorkflowModel.create(workflow);
|
|
28
|
-
return created.toObject() as Workflow;
|
|
29
|
-
}, "createWorkflow()");
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
public async getWorkflow(workflowId: string): Promise<Workflow | undefined> {
|
|
33
|
-
return this.executeWithRetry(async () => {
|
|
34
|
-
const timeout = this.getOperationTimeout();
|
|
35
|
-
const workflow = await WorkflowModel.findOne({
|
|
36
|
-
workflowId
|
|
37
|
-
}).maxTimeMS(timeout).lean<Workflow>();
|
|
38
|
-
return workflow || undefined;
|
|
39
|
-
}, "getWorkflow()");
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
public async updateWorkflow(workflowId: string, updates: Partial<Workflow>): Promise<void> {
|
|
43
|
-
if (!updates.userId) {
|
|
44
|
-
throw new Error("userId is required for updateWorkflow");
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return this.executeWithRetry(async () => {
|
|
48
|
-
const timeout = this.getOperationTimeout();
|
|
49
|
-
// userId를 조건에 포함하여 소유자만 수정 가능하도록 함
|
|
50
|
-
await WorkflowModel.updateOne(
|
|
51
|
-
{ workflowId, userId: updates.userId },
|
|
52
|
-
{ $set: updates }
|
|
53
|
-
).maxTimeMS(timeout);
|
|
54
|
-
}, "updateWorkflow()");
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
public async deleteWorkflow(workflowId: string, userId: string): Promise<void> {
|
|
58
|
-
return this.executeWithRetry(async () => {
|
|
59
|
-
const timeout = this.getOperationTimeout();
|
|
60
|
-
await WorkflowModel.deleteOne({ workflowId, userId }).maxTimeMS(timeout);
|
|
61
|
-
}, "deleteWorkflow()");
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
public async listWorkflows(userId?: string): Promise<Workflow[]> {
|
|
65
|
-
return this.executeWithRetry(async () => {
|
|
66
|
-
const timeout = this.getOperationTimeout();
|
|
67
|
-
// userId가 있으면: 해당 유저 소유 + 템플릿(userId 없음)
|
|
68
|
-
// userId가 없으면: 템플릿만 반환
|
|
69
|
-
const query = userId
|
|
70
|
-
? { $or: [{ userId }, { userId: { $exists: false } }, { userId: null }] }
|
|
71
|
-
: { $or: [{ userId: { $exists: false } }, { userId: null }] };
|
|
72
|
-
const workflows = await WorkflowModel.find(query)
|
|
73
|
-
.maxTimeMS(timeout)
|
|
74
|
-
.lean<Workflow[]>();
|
|
75
|
-
return workflows;
|
|
76
|
-
}, "listWorkflows()");
|
|
77
|
-
}
|
|
78
|
-
}
|
|
File without changes
|