@mastra/server 0.0.0-vnext-inngest-20250508131921 → 0.0.0-vnext-20251104230439
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 +4403 -0
- package/LICENSE.md +11 -42
- package/README.md +1 -6
- package/dist/chunk-2PLXW4ZX.cjs +2777 -0
- package/dist/chunk-2PLXW4ZX.cjs.map +1 -0
- package/dist/chunk-46Z2KDQL.js +124 -0
- package/dist/chunk-46Z2KDQL.js.map +1 -0
- package/dist/{chunk-FV45V6WC.cjs → chunk-64ITUOXI.cjs} +3 -7
- package/dist/chunk-64ITUOXI.cjs.map +1 -0
- package/dist/{chunk-TRDNDNGQ.js → chunk-6QWQZI4Q.js} +4 -7
- package/dist/chunk-6QWQZI4Q.js.map +1 -0
- package/dist/chunk-73PAWDM5.js +83 -0
- package/dist/chunk-73PAWDM5.js.map +1 -0
- package/dist/chunk-AEVI2HIU.cjs +651 -0
- package/dist/chunk-AEVI2HIU.cjs.map +1 -0
- package/dist/chunk-ALOLTNSO.js +477 -0
- package/dist/chunk-ALOLTNSO.js.map +1 -0
- package/dist/chunk-B6NK4KI5.cjs +128 -0
- package/dist/chunk-B6NK4KI5.cjs.map +1 -0
- package/dist/chunk-BANGX6SC.cjs +200 -0
- package/dist/chunk-BANGX6SC.cjs.map +1 -0
- package/dist/chunk-BHQH5QXD.cjs +172 -0
- package/dist/chunk-BHQH5QXD.cjs.map +1 -0
- package/dist/chunk-BTWIR2B7.cjs +28 -0
- package/dist/chunk-BTWIR2B7.cjs.map +1 -0
- package/dist/chunk-DNUO33HF.js +129 -0
- package/dist/chunk-DNUO33HF.js.map +1 -0
- package/dist/chunk-FKZVCLOY.js +527 -0
- package/dist/chunk-FKZVCLOY.js.map +1 -0
- package/dist/chunk-GTZOYEAU.cjs +130 -0
- package/dist/chunk-GTZOYEAU.cjs.map +1 -0
- package/dist/chunk-GU4EWMZB.cjs +769 -0
- package/dist/chunk-GU4EWMZB.cjs.map +1 -0
- package/dist/chunk-IGOWG5V5.js +192 -0
- package/dist/chunk-IGOWG5V5.js.map +1 -0
- package/dist/chunk-JIIVA4BA.cjs +23087 -0
- package/dist/chunk-JIIVA4BA.cjs.map +1 -0
- package/dist/chunk-JO2AZFJN.js +165 -0
- package/dist/chunk-JO2AZFJN.js.map +1 -0
- package/dist/chunk-JZ65BJ6H.cjs +678 -0
- package/dist/chunk-JZ65BJ6H.cjs.map +1 -0
- package/dist/chunk-KCP6I5F3.js +23047 -0
- package/dist/chunk-KCP6I5F3.js.map +1 -0
- package/dist/{chunk-4JINXASC.js → chunk-KWH5QBXP.js} +7 -4
- package/dist/chunk-KWH5QBXP.js.map +1 -0
- package/dist/chunk-LF2ZLOFP.js +767 -0
- package/dist/chunk-LF2ZLOFP.js.map +1 -0
- package/dist/{chunk-Q6SHQECN.js → chunk-LPCK5MAF.js} +47 -13
- package/dist/chunk-LPCK5MAF.js.map +1 -0
- package/dist/chunk-LPM6BBAX.cjs +1043 -0
- package/dist/chunk-LPM6BBAX.cjs.map +1 -0
- package/dist/chunk-LWLSQ2W4.cjs +133 -0
- package/dist/chunk-LWLSQ2W4.cjs.map +1 -0
- package/dist/chunk-O7I5CWRX.cjs +44 -0
- package/dist/chunk-O7I5CWRX.cjs.map +1 -0
- package/dist/chunk-PPMIB3FQ.cjs +88 -0
- package/dist/chunk-PPMIB3FQ.cjs.map +1 -0
- package/dist/chunk-PR4QN5HX.js +39 -0
- package/dist/chunk-PR4QN5HX.js.map +1 -0
- package/dist/chunk-QFGNUBOA.cjs +543 -0
- package/dist/chunk-QFGNUBOA.cjs.map +1 -0
- package/dist/chunk-QU6N55W6.cjs +256 -0
- package/dist/chunk-QU6N55W6.cjs.map +1 -0
- package/dist/chunk-R6OQFR47.js +630 -0
- package/dist/chunk-R6OQFR47.js.map +1 -0
- package/dist/chunk-RQK4FQUD.js +1012 -0
- package/dist/chunk-RQK4FQUD.js.map +1 -0
- package/dist/{chunk-M56ECCHK.cjs → chunk-S54HNARD.cjs} +22 -19
- package/dist/chunk-S54HNARD.cjs.map +1 -0
- package/dist/chunk-SHWNNZBL.js +254 -0
- package/dist/chunk-SHWNNZBL.js.map +1 -0
- package/dist/{chunk-L7XE5QTW.js → chunk-SZIFSF4T.js} +11 -2
- package/dist/chunk-SZIFSF4T.js.map +1 -0
- package/dist/chunk-TOCYBDP2.js +46 -0
- package/dist/chunk-TOCYBDP2.js.map +1 -0
- package/dist/chunk-UXGQZUYZ.js +16 -0
- package/dist/chunk-UXGQZUYZ.js.map +1 -0
- package/dist/chunk-V5WWQN7P.cjs +18 -0
- package/dist/chunk-V5WWQN7P.cjs.map +1 -0
- package/dist/chunk-VYR3SAFM.js +658 -0
- package/dist/chunk-VYR3SAFM.js.map +1 -0
- package/dist/chunk-X6C7BUWN.cjs +48 -0
- package/dist/chunk-X6C7BUWN.cjs.map +1 -0
- package/dist/chunk-XXGID4PQ.cjs +485 -0
- package/dist/chunk-XXGID4PQ.cjs.map +1 -0
- package/dist/chunk-ZULZ2752.js +2774 -0
- package/dist/chunk-ZULZ2752.js.map +1 -0
- package/dist/dist-4MVGNSRL.cjs +1150 -0
- package/dist/dist-4MVGNSRL.cjs.map +1 -0
- package/dist/dist-FZYCV3VB.cjs +940 -0
- package/dist/dist-FZYCV3VB.cjs.map +1 -0
- package/dist/dist-G2BYZJOC.cjs +928 -0
- package/dist/dist-G2BYZJOC.cjs.map +1 -0
- package/dist/dist-P4MXBQ3U.cjs +16 -0
- package/dist/dist-P4MXBQ3U.cjs.map +1 -0
- package/dist/dist-PQZUVLPC.js +937 -0
- package/dist/dist-PQZUVLPC.js.map +1 -0
- package/dist/dist-R7WYX6LC.js +925 -0
- package/dist/dist-R7WYX6LC.js.map +1 -0
- package/dist/dist-RFMYFILX.cjs +764 -0
- package/dist/dist-RFMYFILX.cjs.map +1 -0
- package/dist/dist-X7XR3M3Z.js +1147 -0
- package/dist/dist-X7XR3M3Z.js.map +1 -0
- package/dist/dist-XVBSOGFK.js +761 -0
- package/dist/dist-XVBSOGFK.js.map +1 -0
- package/dist/dist-YREX2TJT.js +3 -0
- package/dist/dist-YREX2TJT.js.map +1 -0
- package/dist/index.cjs +6 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/server/a2a/protocol.d.ts +8 -0
- package/dist/server/a2a/protocol.d.ts.map +1 -0
- package/dist/server/a2a/store.cjs +25 -0
- package/dist/server/a2a/store.cjs.map +1 -0
- package/dist/server/a2a/store.d.ts +14 -0
- package/dist/server/a2a/store.d.ts.map +1 -0
- package/dist/server/a2a/store.js +23 -0
- package/dist/server/a2a/store.js.map +1 -0
- package/dist/server/a2a/tasks.d.ts +20 -0
- package/dist/server/a2a/tasks.d.ts.map +1 -0
- package/dist/server/handlers/a2a.cjs +32 -0
- package/dist/server/handlers/a2a.cjs.map +1 -0
- package/dist/server/handlers/a2a.d.ts +68 -0
- package/dist/server/handlers/a2a.d.ts.map +1 -0
- package/dist/server/handlers/a2a.js +3 -0
- package/dist/server/handlers/a2a.js.map +1 -0
- package/dist/server/handlers/agent-builder.cjs +84 -0
- package/dist/server/handlers/agent-builder.cjs.map +1 -0
- package/dist/server/handlers/agent-builder.d.ts +91 -0
- package/dist/server/handlers/agent-builder.d.ts.map +1 -0
- package/dist/server/handlers/agent-builder.js +3 -0
- package/dist/server/handlers/agent-builder.js.map +1 -0
- package/dist/server/handlers/agents.cjs +60 -10
- package/dist/server/handlers/agents.cjs.map +1 -0
- package/dist/server/handlers/agents.d.ts +194 -6
- package/dist/server/handlers/agents.d.ts.map +1 -0
- package/dist/server/handlers/agents.js +3 -1
- package/dist/server/handlers/agents.js.map +1 -0
- package/dist/server/handlers/error.cjs +4 -2
- package/dist/server/handlers/error.cjs.map +1 -0
- package/dist/server/handlers/error.d.ts +2 -1
- package/dist/server/handlers/error.d.ts.map +1 -0
- package/dist/server/handlers/error.js +3 -1
- package/dist/server/handlers/error.js.map +1 -0
- package/dist/server/handlers/logs.cjs +9 -7
- package/dist/server/handlers/logs.cjs.map +1 -0
- package/dist/server/handlers/logs.d.ts +34 -3
- package/dist/server/handlers/logs.d.ts.map +1 -0
- package/dist/server/handlers/logs.js +3 -1
- package/dist/server/handlers/logs.js.map +1 -0
- package/dist/server/handlers/memory.cjs +36 -10
- package/dist/server/handlers/memory.cjs.map +1 -0
- package/dist/server/handlers/memory.d.ts +116 -8
- package/dist/server/handlers/memory.d.ts.map +1 -0
- package/dist/server/handlers/memory.js +3 -1
- package/dist/server/handlers/memory.js.map +1 -0
- package/dist/server/handlers/observability.cjs +24 -0
- package/dist/server/handlers/observability.cjs.map +1 -0
- package/dist/server/handlers/observability.d.ts +49 -0
- package/dist/server/handlers/observability.d.ts.map +1 -0
- package/dist/server/handlers/observability.js +3 -0
- package/dist/server/handlers/observability.js.map +1 -0
- package/dist/server/handlers/scores.cjs +32 -0
- package/dist/server/handlers/scores.cjs.map +1 -0
- package/dist/server/handlers/scores.d.ts +152 -0
- package/dist/server/handlers/scores.d.ts.map +1 -0
- package/dist/server/handlers/scores.js +3 -0
- package/dist/server/handlers/scores.js.map +1 -0
- package/dist/server/handlers/tools.cjs +12 -6
- package/dist/server/handlers/tools.cjs.map +1 -0
- package/dist/server/handlers/tools.d.ts +25 -4
- package/dist/server/handlers/tools.d.ts.map +1 -0
- package/dist/server/handlers/tools.js +3 -1
- package/dist/server/handlers/tools.js.map +1 -0
- package/dist/server/handlers/utils.cjs +8 -2
- package/dist/server/handlers/utils.cjs.map +1 -0
- package/dist/server/handlers/utils.d.ts +8 -1
- package/dist/server/handlers/utils.d.ts.map +1 -0
- package/dist/server/handlers/utils.js +3 -1
- package/dist/server/handlers/utils.js.map +1 -0
- package/dist/server/handlers/vector.cjs +9 -7
- package/dist/server/handlers/vector.cjs.map +1 -0
- package/dist/server/handlers/vector.d.ts +51 -6
- package/dist/server/handlers/vector.d.ts.map +1 -0
- package/dist/server/handlers/vector.js +3 -1
- package/dist/server/handlers/vector.js.map +1 -0
- package/dist/server/handlers/voice.cjs +10 -4
- package/dist/server/handlers/voice.cjs.map +1 -0
- package/dist/server/handlers/voice.d.ts +41 -3
- package/dist/server/handlers/voice.d.ts.map +1 -0
- package/dist/server/handlers/voice.js +3 -1
- package/dist/server/handlers/voice.js.map +1 -0
- package/dist/server/handlers/workflows.cjs +54 -16
- package/dist/server/handlers/workflows.cjs.map +1 -0
- package/dist/server/handlers/workflows.d.ts +94 -10
- package/dist/server/handlers/workflows.d.ts.map +1 -0
- package/dist/server/handlers/workflows.js +3 -1
- package/dist/server/handlers/workflows.js.map +1 -0
- package/dist/server/handlers.cjs +37 -30
- package/dist/server/handlers.cjs.map +1 -0
- package/dist/server/handlers.d.ts +12 -10
- package/dist/server/handlers.d.ts.map +1 -0
- package/dist/server/handlers.js +13 -10
- package/dist/server/handlers.js.map +1 -0
- package/dist/server/http-exception.d.ts +82 -0
- package/dist/server/http-exception.d.ts.map +1 -0
- package/dist/server/types.d.ts +10 -0
- package/dist/server/types.d.ts.map +1 -0
- package/dist/server/utils.d.ts +44 -0
- package/dist/server/utils.d.ts.map +1 -0
- package/dist/token-375W3LEI.cjs +64 -0
- package/dist/token-375W3LEI.cjs.map +1 -0
- package/dist/token-C3IMNCC4.js +62 -0
- package/dist/token-C3IMNCC4.js.map +1 -0
- package/dist/token-util-CV3RRG6K.cjs +9 -0
- package/dist/token-util-CV3RRG6K.cjs.map +1 -0
- package/dist/token-util-E5QO2RCL.js +7 -0
- package/dist/token-util-E5QO2RCL.js.map +1 -0
- package/package.json +43 -19
- package/dist/_tsup-dts-rollup.d.cts +0 -670
- package/dist/_tsup-dts-rollup.d.ts +0 -670
- package/dist/chunk-2FJURXCL.cjs +0 -213
- package/dist/chunk-3AHQ5RGN.js +0 -11
- package/dist/chunk-3EJZQ6TQ.js +0 -49
- package/dist/chunk-3XTEV33Q.js +0 -317
- package/dist/chunk-55HTWX4C.cjs +0 -93
- package/dist/chunk-5JNVY6DU.js +0 -120
- package/dist/chunk-5SWCVTNL.cjs +0 -5579
- package/dist/chunk-5YGDYMRB.cjs +0 -147
- package/dist/chunk-6Q7UXAYJ.cjs +0 -198
- package/dist/chunk-AMVOS7YB.cjs +0 -141
- package/dist/chunk-BPL2CBLV.js +0 -137
- package/dist/chunk-CHFORQ7J.cjs +0 -329
- package/dist/chunk-D3G23FP3.cjs +0 -126
- package/dist/chunk-GVBJ5I2S.js +0 -190
- package/dist/chunk-M2RXDCPV.cjs +0 -324
- package/dist/chunk-OMN3UI6X.js +0 -5576
- package/dist/chunk-OWNA6I2H.js +0 -312
- package/dist/chunk-QJ3AHN64.js +0 -141
- package/dist/chunk-QN4KF3BH.cjs +0 -18
- package/dist/chunk-RBQASTUP.js +0 -203
- package/dist/chunk-SKBVVI24.cjs +0 -54
- package/dist/chunk-ZLBRQFDD.cjs +0 -13
- package/dist/index.d.cts +0 -1
- package/dist/server/handlers/agents.d.cts +0 -6
- package/dist/server/handlers/error.d.cts +0 -1
- package/dist/server/handlers/logs.d.cts +0 -3
- package/dist/server/handlers/memory.d.cts +0 -8
- package/dist/server/handlers/network.cjs +0 -22
- package/dist/server/handlers/network.d.cts +0 -4
- package/dist/server/handlers/network.d.ts +0 -4
- package/dist/server/handlers/network.js +0 -1
- package/dist/server/handlers/telemetry.cjs +0 -14
- package/dist/server/handlers/telemetry.d.cts +0 -2
- package/dist/server/handlers/telemetry.d.ts +0 -2
- package/dist/server/handlers/telemetry.js +0 -1
- package/dist/server/handlers/tools.d.cts +0 -4
- package/dist/server/handlers/utils.d.cts +0 -1
- package/dist/server/handlers/vNextWorkflows.cjs +0 -46
- package/dist/server/handlers/vNextWorkflows.d.cts +0 -10
- package/dist/server/handlers/vNextWorkflows.d.ts +0 -10
- package/dist/server/handlers/vNextWorkflows.js +0 -1
- package/dist/server/handlers/vector.d.cts +0 -6
- package/dist/server/handlers/voice.d.cts +0 -3
- package/dist/server/handlers/workflows.d.cts +0 -10
- package/dist/server/handlers.d.cts +0 -10
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { stringify } from './chunk-LF2ZLOFP.js';
|
|
2
|
+
import { zodToJsonSchema } from '@mastra/core/utils/zod-to-json';
|
|
3
|
+
|
|
4
|
+
function getSteps(steps, path) {
|
|
5
|
+
return Object.entries(steps).reduce((acc, [key, step]) => {
|
|
6
|
+
const fullKey = path ? `${path}.${key}` : key;
|
|
7
|
+
acc[fullKey] = {
|
|
8
|
+
id: step.id,
|
|
9
|
+
description: step.description,
|
|
10
|
+
inputSchema: step.inputSchema ? stringify(zodToJsonSchema(step.inputSchema)) : void 0,
|
|
11
|
+
outputSchema: step.outputSchema ? stringify(zodToJsonSchema(step.outputSchema)) : void 0,
|
|
12
|
+
resumeSchema: step.resumeSchema ? stringify(zodToJsonSchema(step.resumeSchema)) : void 0,
|
|
13
|
+
suspendSchema: step.suspendSchema ? stringify(zodToJsonSchema(step.suspendSchema)) : void 0,
|
|
14
|
+
isWorkflow: step.component === "WORKFLOW",
|
|
15
|
+
component: step.component
|
|
16
|
+
};
|
|
17
|
+
if (step.component === "WORKFLOW" && step.steps) {
|
|
18
|
+
const nestedSteps = getSteps(step.steps, fullKey) || {};
|
|
19
|
+
acc = { ...acc, ...nestedSteps };
|
|
20
|
+
}
|
|
21
|
+
return acc;
|
|
22
|
+
}, {});
|
|
23
|
+
}
|
|
24
|
+
function getWorkflowInfo(workflow) {
|
|
25
|
+
return {
|
|
26
|
+
name: workflow.name,
|
|
27
|
+
description: workflow.description,
|
|
28
|
+
steps: Object.entries(workflow.steps).reduce((acc, [key, step]) => {
|
|
29
|
+
acc[key] = {
|
|
30
|
+
id: step.id,
|
|
31
|
+
description: step.description,
|
|
32
|
+
inputSchema: step.inputSchema ? stringify(zodToJsonSchema(step.inputSchema)) : void 0,
|
|
33
|
+
outputSchema: step.outputSchema ? stringify(zodToJsonSchema(step.outputSchema)) : void 0,
|
|
34
|
+
resumeSchema: step.resumeSchema ? stringify(zodToJsonSchema(step.resumeSchema)) : void 0,
|
|
35
|
+
suspendSchema: step.suspendSchema ? stringify(zodToJsonSchema(step.suspendSchema)) : void 0,
|
|
36
|
+
component: step.component
|
|
37
|
+
};
|
|
38
|
+
return acc;
|
|
39
|
+
}, {}),
|
|
40
|
+
allSteps: getSteps(workflow.steps) || {},
|
|
41
|
+
stepGraph: workflow.serializedStepGraph,
|
|
42
|
+
inputSchema: workflow.inputSchema ? stringify(zodToJsonSchema(workflow.inputSchema)) : void 0,
|
|
43
|
+
outputSchema: workflow.outputSchema ? stringify(zodToJsonSchema(workflow.outputSchema)) : void 0
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
var WorkflowRegistry = class {
|
|
47
|
+
static additionalWorkflows = {};
|
|
48
|
+
/**
|
|
49
|
+
* Register a workflow temporarily
|
|
50
|
+
*/
|
|
51
|
+
static registerTemporaryWorkflow(id, workflow) {
|
|
52
|
+
this.additionalWorkflows[id] = workflow;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Register all workflows from map
|
|
56
|
+
*/
|
|
57
|
+
static registerTemporaryWorkflows(workflows, mastra) {
|
|
58
|
+
for (const [id, workflow] of Object.entries(workflows)) {
|
|
59
|
+
if (mastra) {
|
|
60
|
+
workflow.__registerMastra(mastra);
|
|
61
|
+
workflow.__registerPrimitives({
|
|
62
|
+
logger: mastra.getLogger(),
|
|
63
|
+
storage: mastra.getStorage(),
|
|
64
|
+
agents: mastra.listAgents(),
|
|
65
|
+
tts: mastra.getTTS(),
|
|
66
|
+
vectors: mastra.getVectors()
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
this.additionalWorkflows[id] = workflow;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Get a workflow by ID from the registry (returns undefined if not found)
|
|
74
|
+
*/
|
|
75
|
+
static getWorkflow(workflowId) {
|
|
76
|
+
return this.additionalWorkflows[workflowId];
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Get all workflows from the registry
|
|
80
|
+
*/
|
|
81
|
+
static getAllWorkflows() {
|
|
82
|
+
return { ...this.additionalWorkflows };
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Clean up a temporary workflow
|
|
86
|
+
*/
|
|
87
|
+
static cleanupTemporaryWorkflow(workflowId) {
|
|
88
|
+
delete this.additionalWorkflows[workflowId];
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Clean up all registered workflows
|
|
92
|
+
*/
|
|
93
|
+
static cleanup() {
|
|
94
|
+
this.additionalWorkflows = {};
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Check if a workflow ID is a valid agent-builder workflow
|
|
98
|
+
*/
|
|
99
|
+
static isAgentBuilderWorkflow(workflowId) {
|
|
100
|
+
return workflowId in this.additionalWorkflows;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Get all registered temporary workflow IDs (for debugging)
|
|
104
|
+
*/
|
|
105
|
+
static getRegisteredWorkflowIds() {
|
|
106
|
+
return Object.keys(this.additionalWorkflows);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
function convertInstructionsToString(message) {
|
|
110
|
+
if (!message) {
|
|
111
|
+
return "";
|
|
112
|
+
}
|
|
113
|
+
if (typeof message === "string") {
|
|
114
|
+
return message;
|
|
115
|
+
}
|
|
116
|
+
if (Array.isArray(message)) {
|
|
117
|
+
return message.map((m) => {
|
|
118
|
+
if (typeof m === "string") {
|
|
119
|
+
return m;
|
|
120
|
+
}
|
|
121
|
+
return typeof m.content === "string" ? m.content : "";
|
|
122
|
+
}).filter((content) => content).join("\n");
|
|
123
|
+
}
|
|
124
|
+
return typeof message.content === "string" ? message.content : "";
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export { WorkflowRegistry, convertInstructionsToString, getWorkflowInfo };
|
|
128
|
+
//# sourceMappingURL=chunk-DNUO33HF.js.map
|
|
129
|
+
//# sourceMappingURL=chunk-DNU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5C;AAAA;AAAA;AAAA;AAAA,EAIA,OAAO,OAAA,GAAgB;AAErB,IAAA,IAAA,CAAK,sBAAsB,EAAC;AAAA,EAC9B;AAAA;AAAA;AAAA;AAAA,EAKA,OAAO,uBAAuB,UAAA,EAA6B;AACzD,IAAA,OAAO,cAAc,IAAA,CAAK,mBAAA;AAAA,EAC5B;AAAA;AAAA;AAAA;AAAA,EAKA,OAAO,wBAAA,GAAqC;AAC1C,IAAA,OAAO,MAAA,CAAO,IAAA,CAAK,IAAA,CAAK,mBAAmB,CAAA;AAAA,EAC7C;AACF;AAEO,SAAS,4BAA4B,OAAA,EAAgC;AAC1E,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,OAAO,EAAA;AAAA,EACT;AAEA,EAAA,IAAI,OAAO,YAAY,QAAA,EAAU;AAC/B,IAAA,OAAO,OAAA;AAAA,EACT;AAEA,EAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,OAAO,CAAA,EAAG;AAC1B,IAAA,OAAO,OAAA,CACJ,IAAI,CAAA,CAAA,KAAK;AACR,MAAA,IAAI,OAAO,MAAM,QAAA,EAAU;AACzB,QAAA,OAAO,CAAA;AAAA,MACT;AAEA,MAAA,OAAO,OAAO,CAAA,CAAE,OAAA,KAAY,QAAA,GAAW,EAAE,OAAA,GAAU,EAAA;AAAA,IACrD,CAAC,CAAA,CACA,MAAA,CAAO,aAAW,OAAO,CAAA,CACzB,KAAK,IAAI,CAAA;AAAA,EACd;AAGA,EAAA,OAAO,OAAO,OAAA,CAAQ,OAAA,KAAY,QAAA,GAAW,QAAQ,OAAA,GAAU,EAAA;AACjE","file":"chunk-DNUO33HF.js","sourcesContent":["import type { SystemMessage } from '@mastra/core/llm';\nimport { zodToJsonSchema } from '@mastra/core/utils/zod-to-json';\nimport type { StepWithComponent, Workflow, WorkflowInfo } from '@mastra/core/workflows';\nimport { stringify } from 'superjson';\n\nfunction getSteps(steps: Record<string, StepWithComponent>, path?: string) {\n return Object.entries(steps).reduce<any>((acc, [key, step]) => {\n const fullKey = path ? `${path}.${key}` : key;\n acc[fullKey] = {\n id: step.id,\n description: step.description,\n inputSchema: step.inputSchema ? stringify(zodToJsonSchema(step.inputSchema)) : undefined,\n outputSchema: step.outputSchema ? stringify(zodToJsonSchema(step.outputSchema)) : undefined,\n resumeSchema: step.resumeSchema ? stringify(zodToJsonSchema(step.resumeSchema)) : undefined,\n suspendSchema: step.suspendSchema ? stringify(zodToJsonSchema(step.suspendSchema)) : undefined,\n isWorkflow: step.component === 'WORKFLOW',\n component: step.component,\n };\n\n if (step.component === 'WORKFLOW' && step.steps) {\n const nestedSteps = getSteps(step.steps, fullKey) || {};\n acc = { ...acc, ...nestedSteps };\n }\n\n return acc;\n }, {});\n}\n\nexport function getWorkflowInfo(workflow: Workflow): WorkflowInfo {\n return {\n name: workflow.name,\n description: workflow.description,\n steps: Object.entries(workflow.steps).reduce<any>((acc, [key, step]) => {\n acc[key] = {\n id: step.id,\n description: step.description,\n inputSchema: step.inputSchema ? stringify(zodToJsonSchema(step.inputSchema)) : undefined,\n outputSchema: step.outputSchema ? stringify(zodToJsonSchema(step.outputSchema)) : undefined,\n resumeSchema: step.resumeSchema ? stringify(zodToJsonSchema(step.resumeSchema)) : undefined,\n suspendSchema: step.suspendSchema ? stringify(zodToJsonSchema(step.suspendSchema)) : undefined,\n component: step.component,\n };\n return acc;\n }, {}),\n allSteps: getSteps(workflow.steps) || {},\n stepGraph: workflow.serializedStepGraph,\n inputSchema: workflow.inputSchema ? stringify(zodToJsonSchema(workflow.inputSchema)) : undefined,\n outputSchema: workflow.outputSchema ? stringify(zodToJsonSchema(workflow.outputSchema)) : undefined,\n };\n}\n\n/**\n * Workflow Registry for temporarily registering additional workflows\n * that are not part of the user's Mastra instance (e.g., internal template workflows)\n */\nexport class WorkflowRegistry {\n private static additionalWorkflows: Record<string, Workflow> = {};\n\n /**\n * Register a workflow temporarily\n */\n static registerTemporaryWorkflow(id: string, workflow: Workflow): void {\n this.additionalWorkflows[id] = workflow;\n }\n\n /**\n * Register all workflows from map\n */\n static registerTemporaryWorkflows(workflows: Record<string, Workflow>, mastra?: any): void {\n for (const [id, workflow] of Object.entries(workflows)) {\n // Register Mastra instance with the workflow if provided\n if (mastra) {\n workflow.__registerMastra(mastra);\n workflow.__registerPrimitives({\n logger: mastra.getLogger(),\n storage: mastra.getStorage(),\n agents: mastra.listAgents(),\n tts: mastra.getTTS(),\n vectors: mastra.getVectors(),\n });\n }\n this.additionalWorkflows[id] = workflow;\n }\n }\n\n /**\n * Get a workflow by ID from the registry (returns undefined if not found)\n */\n static getWorkflow(workflowId: string): Workflow | undefined {\n return this.additionalWorkflows[workflowId];\n }\n\n /**\n * Get all workflows from the registry\n */\n static getAllWorkflows(): Record<string, Workflow> {\n return { ...this.additionalWorkflows };\n }\n\n /**\n * Clean up a temporary workflow\n */\n static cleanupTemporaryWorkflow(workflowId: string): void {\n delete this.additionalWorkflows[workflowId];\n }\n /**\n * Clean up all registered workflows\n */\n static cleanup(): void {\n // Clear all workflows (since we register all agent-builder workflows each time)\n this.additionalWorkflows = {};\n }\n\n /**\n * Check if a workflow ID is a valid agent-builder workflow\n */\n static isAgentBuilderWorkflow(workflowId: string): boolean {\n return workflowId in this.additionalWorkflows;\n }\n\n /**\n * Get all registered temporary workflow IDs (for debugging)\n */\n static getRegisteredWorkflowIds(): string[] {\n return Object.keys(this.additionalWorkflows);\n }\n}\n\nexport function convertInstructionsToString(message: SystemMessage): string {\n if (!message) {\n return '';\n }\n\n if (typeof message === 'string') {\n return message;\n }\n\n if (Array.isArray(message)) {\n return message\n .map(m => {\n if (typeof m === 'string') {\n return m;\n }\n // Safely extract content from message objects\n return typeof m.content === 'string' ? m.content : '';\n })\n .filter(content => content) // Remove empty strings\n .join('\\n');\n }\n\n // Handle single message object - safely extract content\n return typeof message.content === 'string' ? message.content : '';\n}\n"]}
|
|
@@ -0,0 +1,527 @@
|
|
|
1
|
+
import { validateBody } from './chunk-SZIFSF4T.js';
|
|
2
|
+
import { handleError } from './chunk-UXGQZUYZ.js';
|
|
3
|
+
import { HTTPException } from './chunk-6QWQZI4Q.js';
|
|
4
|
+
import { __export } from './chunk-PR4QN5HX.js';
|
|
5
|
+
import { convertMessages } from '@mastra/core/agent';
|
|
6
|
+
import { RequestContext } from '@mastra/core/di';
|
|
7
|
+
import { generateEmptyFromSchema } from '@mastra/core/utils';
|
|
8
|
+
|
|
9
|
+
// src/server/handlers/memory.ts
|
|
10
|
+
var memory_exports = {};
|
|
11
|
+
__export(memory_exports, {
|
|
12
|
+
createThreadHandler: () => createThreadHandler,
|
|
13
|
+
deleteMessagesHandler: () => deleteMessagesHandler,
|
|
14
|
+
deleteThreadHandler: () => deleteThreadHandler,
|
|
15
|
+
getMemoryConfigHandler: () => getMemoryConfigHandler,
|
|
16
|
+
getMemoryStatusHandler: () => getMemoryStatusHandler,
|
|
17
|
+
getMessagesHandler: () => getMessagesHandler,
|
|
18
|
+
getThreadByIdHandler: () => getThreadByIdHandler,
|
|
19
|
+
getWorkingMemoryHandler: () => getWorkingMemoryHandler,
|
|
20
|
+
listMessagesHandler: () => listMessagesHandler,
|
|
21
|
+
listThreadsHandler: () => listThreadsHandler,
|
|
22
|
+
saveMessagesHandler: () => saveMessagesHandler,
|
|
23
|
+
searchMemoryHandler: () => searchMemoryHandler,
|
|
24
|
+
updateThreadHandler: () => updateThreadHandler,
|
|
25
|
+
updateWorkingMemoryHandler: () => updateWorkingMemoryHandler
|
|
26
|
+
});
|
|
27
|
+
async function getMemoryFromContext({
|
|
28
|
+
mastra,
|
|
29
|
+
agentId,
|
|
30
|
+
requestContext
|
|
31
|
+
}) {
|
|
32
|
+
const logger = mastra.getLogger();
|
|
33
|
+
let agent;
|
|
34
|
+
if (agentId) {
|
|
35
|
+
try {
|
|
36
|
+
agent = mastra.getAgent(agentId);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
logger.debug("Error getting agent from mastra, searching agents for agent", error);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (agentId && !agent) {
|
|
42
|
+
logger.debug("Agent not found, searching agents for agent", { agentId });
|
|
43
|
+
const agents = mastra.listAgents();
|
|
44
|
+
if (Object.keys(agents || {}).length) {
|
|
45
|
+
for (const [_, ag] of Object.entries(agents)) {
|
|
46
|
+
try {
|
|
47
|
+
const agents2 = await ag.listAgents();
|
|
48
|
+
if (agents2[agentId]) {
|
|
49
|
+
agent = agents2[agentId];
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
} catch (error) {
|
|
53
|
+
logger.debug("Error getting agent from agent", error);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (!agent) {
|
|
58
|
+
throw new HTTPException(404, { message: "Agent not found" });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (agent) {
|
|
62
|
+
return await agent?.getMemory({
|
|
63
|
+
requestContext: requestContext ?? new RequestContext()
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
async function getMemoryStatusHandler({
|
|
68
|
+
mastra,
|
|
69
|
+
agentId,
|
|
70
|
+
requestContext
|
|
71
|
+
}) {
|
|
72
|
+
try {
|
|
73
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
74
|
+
if (!memory) {
|
|
75
|
+
return { result: false };
|
|
76
|
+
}
|
|
77
|
+
return { result: true };
|
|
78
|
+
} catch (error) {
|
|
79
|
+
return handleError(error, "Error getting memory status");
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
async function getMemoryConfigHandler({
|
|
83
|
+
mastra,
|
|
84
|
+
agentId,
|
|
85
|
+
requestContext
|
|
86
|
+
}) {
|
|
87
|
+
try {
|
|
88
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
89
|
+
if (!memory) {
|
|
90
|
+
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
91
|
+
}
|
|
92
|
+
const config = memory.getMergedThreadConfig({});
|
|
93
|
+
return { config };
|
|
94
|
+
} catch (error) {
|
|
95
|
+
return handleError(error, "Error getting memory configuration");
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
async function listThreadsHandler({
|
|
99
|
+
mastra,
|
|
100
|
+
agentId,
|
|
101
|
+
resourceId,
|
|
102
|
+
requestContext,
|
|
103
|
+
page,
|
|
104
|
+
perPage,
|
|
105
|
+
orderBy
|
|
106
|
+
}) {
|
|
107
|
+
try {
|
|
108
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
109
|
+
if (!memory) {
|
|
110
|
+
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
111
|
+
}
|
|
112
|
+
validateBody({ resourceId });
|
|
113
|
+
const result = await memory.listThreadsByResourceId({
|
|
114
|
+
resourceId,
|
|
115
|
+
page,
|
|
116
|
+
perPage,
|
|
117
|
+
orderBy
|
|
118
|
+
});
|
|
119
|
+
return result;
|
|
120
|
+
} catch (error) {
|
|
121
|
+
return handleError(error, "Error listing threads");
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
async function getThreadByIdHandler({
|
|
125
|
+
mastra,
|
|
126
|
+
agentId,
|
|
127
|
+
threadId,
|
|
128
|
+
requestContext
|
|
129
|
+
}) {
|
|
130
|
+
try {
|
|
131
|
+
validateBody({ threadId });
|
|
132
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
133
|
+
if (!memory) {
|
|
134
|
+
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
135
|
+
}
|
|
136
|
+
const thread = await memory.getThreadById({ threadId });
|
|
137
|
+
if (!thread) {
|
|
138
|
+
throw new HTTPException(404, { message: "Thread not found" });
|
|
139
|
+
}
|
|
140
|
+
return thread;
|
|
141
|
+
} catch (error) {
|
|
142
|
+
return handleError(error, "Error getting thread");
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
async function saveMessagesHandler({
|
|
146
|
+
mastra,
|
|
147
|
+
agentId,
|
|
148
|
+
body,
|
|
149
|
+
requestContext
|
|
150
|
+
}) {
|
|
151
|
+
try {
|
|
152
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
153
|
+
if (!memory) {
|
|
154
|
+
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
155
|
+
}
|
|
156
|
+
if (!body?.messages) {
|
|
157
|
+
throw new HTTPException(400, { message: "Messages are required" });
|
|
158
|
+
}
|
|
159
|
+
if (!Array.isArray(body.messages)) {
|
|
160
|
+
throw new HTTPException(400, { message: "Messages should be an array" });
|
|
161
|
+
}
|
|
162
|
+
const invalidMessages = body.messages.filter((message) => !message.threadId || !message.resourceId);
|
|
163
|
+
if (invalidMessages.length > 0) {
|
|
164
|
+
throw new HTTPException(400, {
|
|
165
|
+
message: `All messages must have threadId and resourceId fields. Found ${invalidMessages.length} invalid message(s).`
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
const processedMessages = body.messages.map((message) => ({
|
|
169
|
+
...message,
|
|
170
|
+
id: message.id || memory.generateId(),
|
|
171
|
+
createdAt: message.createdAt ? new Date(message.createdAt) : /* @__PURE__ */ new Date()
|
|
172
|
+
}));
|
|
173
|
+
const result = await memory.saveMessages({ messages: processedMessages, memoryConfig: {} });
|
|
174
|
+
return result;
|
|
175
|
+
} catch (error) {
|
|
176
|
+
return handleError(error, "Error saving messages");
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
async function createThreadHandler({
|
|
180
|
+
mastra,
|
|
181
|
+
agentId,
|
|
182
|
+
body,
|
|
183
|
+
requestContext
|
|
184
|
+
}) {
|
|
185
|
+
try {
|
|
186
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
187
|
+
if (!memory) {
|
|
188
|
+
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
189
|
+
}
|
|
190
|
+
validateBody({ resourceId: body?.resourceId });
|
|
191
|
+
const result = await memory.createThread({
|
|
192
|
+
resourceId: body?.resourceId,
|
|
193
|
+
title: body?.title,
|
|
194
|
+
metadata: body?.metadata,
|
|
195
|
+
threadId: body?.threadId
|
|
196
|
+
});
|
|
197
|
+
return result;
|
|
198
|
+
} catch (error) {
|
|
199
|
+
return handleError(error, "Error saving thread to memory");
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
async function updateThreadHandler({
|
|
203
|
+
mastra,
|
|
204
|
+
agentId,
|
|
205
|
+
threadId,
|
|
206
|
+
body,
|
|
207
|
+
requestContext
|
|
208
|
+
}) {
|
|
209
|
+
try {
|
|
210
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
211
|
+
if (!body) {
|
|
212
|
+
throw new HTTPException(400, { message: "Body is required" });
|
|
213
|
+
}
|
|
214
|
+
const { title, metadata, resourceId } = body;
|
|
215
|
+
const updatedAt = /* @__PURE__ */ new Date();
|
|
216
|
+
validateBody({ threadId });
|
|
217
|
+
if (!memory) {
|
|
218
|
+
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
219
|
+
}
|
|
220
|
+
const thread = await memory.getThreadById({ threadId });
|
|
221
|
+
if (!thread) {
|
|
222
|
+
throw new HTTPException(404, { message: "Thread not found" });
|
|
223
|
+
}
|
|
224
|
+
const updatedThread = {
|
|
225
|
+
...thread,
|
|
226
|
+
title: title || thread.title,
|
|
227
|
+
metadata: metadata || thread.metadata,
|
|
228
|
+
resourceId: resourceId || thread.resourceId,
|
|
229
|
+
createdAt: thread.createdAt,
|
|
230
|
+
updatedAt
|
|
231
|
+
};
|
|
232
|
+
const result = await memory.saveThread({ thread: updatedThread });
|
|
233
|
+
return result;
|
|
234
|
+
} catch (error) {
|
|
235
|
+
return handleError(error, "Error updating thread");
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
async function deleteThreadHandler({
|
|
239
|
+
mastra,
|
|
240
|
+
agentId,
|
|
241
|
+
threadId,
|
|
242
|
+
requestContext
|
|
243
|
+
}) {
|
|
244
|
+
try {
|
|
245
|
+
validateBody({ threadId });
|
|
246
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
247
|
+
if (!memory) {
|
|
248
|
+
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
249
|
+
}
|
|
250
|
+
const thread = await memory.getThreadById({ threadId });
|
|
251
|
+
if (!thread) {
|
|
252
|
+
throw new HTTPException(404, { message: "Thread not found" });
|
|
253
|
+
}
|
|
254
|
+
await memory.deleteThread(threadId);
|
|
255
|
+
return { result: "Thread deleted" };
|
|
256
|
+
} catch (error) {
|
|
257
|
+
return handleError(error, "Error deleting thread");
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
async function listMessagesHandler({
|
|
261
|
+
mastra,
|
|
262
|
+
threadId,
|
|
263
|
+
resourceId,
|
|
264
|
+
perPage,
|
|
265
|
+
page,
|
|
266
|
+
orderBy,
|
|
267
|
+
include,
|
|
268
|
+
filter
|
|
269
|
+
}) {
|
|
270
|
+
try {
|
|
271
|
+
validateBody({ threadId });
|
|
272
|
+
const storage = mastra.getStorage();
|
|
273
|
+
if (!storage) {
|
|
274
|
+
throw new HTTPException(400, { message: "Storage is not initialized" });
|
|
275
|
+
}
|
|
276
|
+
const thread = await storage.getThreadById({ threadId });
|
|
277
|
+
if (!thread) {
|
|
278
|
+
throw new HTTPException(404, { message: "Thread not found" });
|
|
279
|
+
}
|
|
280
|
+
const result = await storage.listMessages({
|
|
281
|
+
threadId,
|
|
282
|
+
resourceId,
|
|
283
|
+
perPage,
|
|
284
|
+
page,
|
|
285
|
+
orderBy,
|
|
286
|
+
include,
|
|
287
|
+
filter
|
|
288
|
+
});
|
|
289
|
+
return result;
|
|
290
|
+
} catch (error) {
|
|
291
|
+
return handleError(error, "Error getting messages");
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
async function getMessagesHandler({
|
|
295
|
+
mastra,
|
|
296
|
+
agentId,
|
|
297
|
+
threadId,
|
|
298
|
+
limit,
|
|
299
|
+
requestContext
|
|
300
|
+
}) {
|
|
301
|
+
if (limit !== void 0 && (!Number.isInteger(limit) || limit <= 0)) {
|
|
302
|
+
throw new HTTPException(400, { message: "Invalid limit: must be a positive integer" });
|
|
303
|
+
}
|
|
304
|
+
try {
|
|
305
|
+
validateBody({ threadId });
|
|
306
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
307
|
+
if (!memory) {
|
|
308
|
+
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
309
|
+
}
|
|
310
|
+
if (!threadId) {
|
|
311
|
+
throw new HTTPException(400, { message: "No threadId found" });
|
|
312
|
+
}
|
|
313
|
+
const thread = await memory.getThreadById({ threadId });
|
|
314
|
+
if (!thread) {
|
|
315
|
+
throw new HTTPException(404, { message: "Thread not found" });
|
|
316
|
+
}
|
|
317
|
+
const result = await memory.query({
|
|
318
|
+
threadId,
|
|
319
|
+
...limit && { selectBy: { last: limit } }
|
|
320
|
+
});
|
|
321
|
+
const uiMessages = convertMessages(result.messages).to("AIV5.UI");
|
|
322
|
+
return { messages: result.messages, uiMessages };
|
|
323
|
+
} catch (error) {
|
|
324
|
+
return handleError(error, "Error getting messages");
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
async function getWorkingMemoryHandler({
|
|
328
|
+
mastra,
|
|
329
|
+
agentId,
|
|
330
|
+
threadId,
|
|
331
|
+
resourceId,
|
|
332
|
+
requestContext,
|
|
333
|
+
memoryConfig
|
|
334
|
+
}) {
|
|
335
|
+
try {
|
|
336
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
337
|
+
validateBody({ threadId });
|
|
338
|
+
if (!memory) {
|
|
339
|
+
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
340
|
+
}
|
|
341
|
+
const thread = await memory.getThreadById({ threadId });
|
|
342
|
+
const threadExists = !!thread;
|
|
343
|
+
const template = await memory.getWorkingMemoryTemplate({ memoryConfig });
|
|
344
|
+
const workingMemoryTemplate = template?.format === "json" ? { ...template, content: JSON.stringify(generateEmptyFromSchema(template.content)) } : template;
|
|
345
|
+
const workingMemory = await memory.getWorkingMemory({ threadId, resourceId, memoryConfig });
|
|
346
|
+
const config = memory.getMergedThreadConfig(memoryConfig || {});
|
|
347
|
+
const source = config.workingMemory?.scope !== "thread" && resourceId ? "resource" : "thread";
|
|
348
|
+
return { workingMemory, source, workingMemoryTemplate, threadExists };
|
|
349
|
+
} catch (error) {
|
|
350
|
+
return handleError(error, "Error getting working memory");
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
async function updateWorkingMemoryHandler({
|
|
354
|
+
mastra,
|
|
355
|
+
agentId,
|
|
356
|
+
threadId,
|
|
357
|
+
body,
|
|
358
|
+
requestContext
|
|
359
|
+
}) {
|
|
360
|
+
try {
|
|
361
|
+
validateBody({ threadId });
|
|
362
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
363
|
+
const { resourceId, memoryConfig, workingMemory } = body;
|
|
364
|
+
if (!memory) {
|
|
365
|
+
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
366
|
+
}
|
|
367
|
+
const thread = await memory.getThreadById({ threadId });
|
|
368
|
+
if (!thread) {
|
|
369
|
+
throw new HTTPException(404, { message: "Thread not found" });
|
|
370
|
+
}
|
|
371
|
+
await memory.updateWorkingMemory({ threadId, resourceId, workingMemory, memoryConfig });
|
|
372
|
+
return { success: true };
|
|
373
|
+
} catch (error) {
|
|
374
|
+
return handleError(error, "Error updating working memory");
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
async function deleteMessagesHandler({
|
|
378
|
+
mastra,
|
|
379
|
+
agentId,
|
|
380
|
+
messageIds,
|
|
381
|
+
requestContext
|
|
382
|
+
}) {
|
|
383
|
+
try {
|
|
384
|
+
if (messageIds === void 0 || messageIds === null) {
|
|
385
|
+
throw new HTTPException(400, { message: "messageIds is required" });
|
|
386
|
+
}
|
|
387
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
388
|
+
if (!memory) {
|
|
389
|
+
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
390
|
+
}
|
|
391
|
+
await memory.deleteMessages(messageIds);
|
|
392
|
+
let count = 1;
|
|
393
|
+
if (Array.isArray(messageIds)) {
|
|
394
|
+
count = messageIds.length;
|
|
395
|
+
}
|
|
396
|
+
return { success: true, message: `${count} message${count === 1 ? "" : "s"} deleted successfully` };
|
|
397
|
+
} catch (error) {
|
|
398
|
+
return handleError(error, "Error deleting messages");
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
async function searchMemoryHandler({
|
|
402
|
+
mastra,
|
|
403
|
+
agentId,
|
|
404
|
+
searchQuery,
|
|
405
|
+
resourceId,
|
|
406
|
+
threadId,
|
|
407
|
+
limit = 20,
|
|
408
|
+
requestContext,
|
|
409
|
+
memoryConfig
|
|
410
|
+
}) {
|
|
411
|
+
try {
|
|
412
|
+
validateBody({ searchQuery, resourceId });
|
|
413
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
414
|
+
if (!memory) {
|
|
415
|
+
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
416
|
+
}
|
|
417
|
+
const config = memory.getMergedThreadConfig(memoryConfig || {});
|
|
418
|
+
const hasSemanticRecall = !!config?.semanticRecall;
|
|
419
|
+
const resourceScope = typeof config?.semanticRecall === "object" ? config?.semanticRecall?.scope !== "thread" : true;
|
|
420
|
+
if (threadId && !resourceScope) {
|
|
421
|
+
const thread = await memory.getThreadById({ threadId });
|
|
422
|
+
if (!thread) {
|
|
423
|
+
throw new HTTPException(404, { message: "Thread not found" });
|
|
424
|
+
}
|
|
425
|
+
if (thread.resourceId !== resourceId) {
|
|
426
|
+
throw new HTTPException(403, { message: "Thread does not belong to the specified resource" });
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
const searchResults = [];
|
|
430
|
+
if (threadId && !resourceScope) {
|
|
431
|
+
const thread = await memory.getThreadById({ threadId });
|
|
432
|
+
if (!thread) {
|
|
433
|
+
return {
|
|
434
|
+
results: [],
|
|
435
|
+
count: 0,
|
|
436
|
+
query: searchQuery,
|
|
437
|
+
searchScope: resourceScope ? "resource" : "thread",
|
|
438
|
+
searchType: hasSemanticRecall ? "semantic" : "text"
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
if (!threadId) {
|
|
443
|
+
const { threads } = await memory.listThreadsByResourceId({
|
|
444
|
+
resourceId,
|
|
445
|
+
page: 0,
|
|
446
|
+
perPage: 1,
|
|
447
|
+
orderBy: { field: "updatedAt", direction: "DESC" }
|
|
448
|
+
});
|
|
449
|
+
if (threads.length === 0) {
|
|
450
|
+
return {
|
|
451
|
+
results: [],
|
|
452
|
+
count: 0,
|
|
453
|
+
query: searchQuery,
|
|
454
|
+
searchScope: resourceScope ? "resource" : "thread",
|
|
455
|
+
searchType: hasSemanticRecall ? "semantic" : "text"
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
threadId = threads[0].id;
|
|
459
|
+
}
|
|
460
|
+
const beforeRange = typeof config.semanticRecall === `boolean` ? 2 : typeof config.semanticRecall?.messageRange === `number` ? config.semanticRecall.messageRange : config.semanticRecall?.messageRange.before || 2;
|
|
461
|
+
const afterRange = typeof config.semanticRecall === `boolean` ? 2 : typeof config.semanticRecall?.messageRange === `number` ? config.semanticRecall.messageRange : config.semanticRecall?.messageRange.after || 2;
|
|
462
|
+
if (resourceScope && config.semanticRecall) {
|
|
463
|
+
config.semanticRecall = typeof config.semanticRecall === `boolean` ? (
|
|
464
|
+
// make message range 0 so we can highlight the matches in search, message range will include other messages, not the matching ones
|
|
465
|
+
// and we add prev/next messages in a special section on each message anyway
|
|
466
|
+
{ messageRange: 0, topK: 2, scope: "resource" }
|
|
467
|
+
) : { ...config.semanticRecall, messageRange: 0 };
|
|
468
|
+
}
|
|
469
|
+
const result = await memory.rememberMessages({
|
|
470
|
+
threadId,
|
|
471
|
+
resourceId,
|
|
472
|
+
vectorMessageSearch: searchQuery,
|
|
473
|
+
config
|
|
474
|
+
});
|
|
475
|
+
const threadIds = Array.from(
|
|
476
|
+
new Set(result.messages.map((m) => m.threadId || threadId).filter(Boolean))
|
|
477
|
+
);
|
|
478
|
+
const fetched = await Promise.all(threadIds.map((id) => memory.getThreadById({ threadId: id })));
|
|
479
|
+
const threadMap = new Map(fetched.filter(Boolean).map((t) => [t.id, t]));
|
|
480
|
+
for (const msg of result.messages) {
|
|
481
|
+
const content = typeof msg.content.content === `string` ? msg.content.content : msg.content.parts?.map((p) => p.type === "text" ? p.text : "").join(" ") || "";
|
|
482
|
+
const msgThreadId = msg.threadId || threadId;
|
|
483
|
+
const thread = threadMap.get(msgThreadId);
|
|
484
|
+
const threadMessages = (await memory.query({ threadId: msgThreadId })).messages;
|
|
485
|
+
const messageIndex = threadMessages.findIndex((m) => m.id === msg.id);
|
|
486
|
+
const searchResult = {
|
|
487
|
+
id: msg.id,
|
|
488
|
+
role: msg.role,
|
|
489
|
+
content,
|
|
490
|
+
createdAt: msg.createdAt,
|
|
491
|
+
threadId: msgThreadId,
|
|
492
|
+
threadTitle: thread?.title || msgThreadId
|
|
493
|
+
};
|
|
494
|
+
if (messageIndex !== -1) {
|
|
495
|
+
searchResult.context = {
|
|
496
|
+
before: threadMessages.slice(Math.max(0, messageIndex - beforeRange), messageIndex).map((m) => ({
|
|
497
|
+
id: m.id,
|
|
498
|
+
role: m.role,
|
|
499
|
+
content: m.content,
|
|
500
|
+
createdAt: m.createdAt || /* @__PURE__ */ new Date()
|
|
501
|
+
})),
|
|
502
|
+
after: threadMessages.slice(messageIndex + 1, messageIndex + afterRange + 1).map((m) => ({
|
|
503
|
+
id: m.id,
|
|
504
|
+
role: m.role,
|
|
505
|
+
content: m.content,
|
|
506
|
+
createdAt: m.createdAt || /* @__PURE__ */ new Date()
|
|
507
|
+
}))
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
searchResults.push(searchResult);
|
|
511
|
+
}
|
|
512
|
+
const sortedResults = searchResults.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()).slice(0, limit);
|
|
513
|
+
return {
|
|
514
|
+
results: sortedResults,
|
|
515
|
+
count: sortedResults.length,
|
|
516
|
+
query: searchQuery,
|
|
517
|
+
searchScope: resourceScope ? "resource" : "thread",
|
|
518
|
+
searchType: hasSemanticRecall ? "semantic" : "text"
|
|
519
|
+
};
|
|
520
|
+
} catch (error) {
|
|
521
|
+
return handleError(error, "Error searching memory");
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
export { createThreadHandler, deleteMessagesHandler, deleteThreadHandler, getMemoryConfigHandler, getMemoryStatusHandler, getMessagesHandler, getThreadByIdHandler, getWorkingMemoryHandler, listMessagesHandler, listThreadsHandler, memory_exports, saveMessagesHandler, searchMemoryHandler, updateThreadHandler, updateWorkingMemoryHandler };
|
|
526
|
+
//# sourceMappingURL=chunk-FKZVCLOY.js.map
|
|
527
|
+
//# sourceMappingURL=chunk-FKZVCLOY.js.map
|