@mastra/server 0.0.0-sidebar-window-undefined-fix-20251029233656 → 0.0.0-span-scorring-test-20251124132129
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 +713 -3
- package/README.md +1 -1
- package/dist/chunk-2NW6POYK.cjs +89 -0
- package/dist/chunk-2NW6POYK.cjs.map +1 -0
- package/dist/chunk-35NT4TMQ.cjs +201 -0
- package/dist/chunk-35NT4TMQ.cjs.map +1 -0
- package/dist/{chunk-MN2TZQ7I.js → chunk-3R5EV3HV.js} +218 -31
- package/dist/chunk-3R5EV3HV.js.map +1 -0
- package/dist/{chunk-K5T5A3AL.cjs → chunk-4ECGVOJZ.cjs} +224 -31
- package/dist/chunk-4ECGVOJZ.cjs.map +1 -0
- package/dist/chunk-5PONYNYP.cjs +125 -0
- package/dist/chunk-5PONYNYP.cjs.map +1 -0
- package/dist/chunk-5W4RPVTK.cjs +49 -0
- package/dist/chunk-5W4RPVTK.cjs.map +1 -0
- package/dist/{chunk-7NADHFD2.cjs → chunk-64ITUOXI.cjs} +2 -2
- package/dist/chunk-64ITUOXI.cjs.map +1 -0
- package/dist/{chunk-7HCPO76Z.js → chunk-6BISSAIF.js} +5096 -1150
- package/dist/chunk-6BISSAIF.js.map +1 -0
- package/dist/chunk-6DTV6NEW.js +116 -0
- package/dist/chunk-6DTV6NEW.js.map +1 -0
- package/dist/{chunk-MMROOK5J.js → chunk-6QWQZI4Q.js} +2 -2
- package/dist/{chunk-7NADHFD2.cjs.map → chunk-6QWQZI4Q.js.map} +1 -1
- package/dist/chunk-AEO6IHLK.cjs +368 -0
- package/dist/chunk-AEO6IHLK.cjs.map +1 -0
- package/dist/chunk-ASZUOBKV.js +310 -0
- package/dist/chunk-ASZUOBKV.js.map +1 -0
- package/dist/chunk-ECIVTQ4E.js +354 -0
- package/dist/chunk-ECIVTQ4E.js.map +1 -0
- package/dist/chunk-FAQICBMH.js +164 -0
- package/dist/chunk-FAQICBMH.js.map +1 -0
- package/dist/chunk-FXDZLX2Y.js +192 -0
- package/dist/chunk-FXDZLX2Y.js.map +1 -0
- package/dist/{chunk-KSFLUEWV.js → chunk-G7BPNX2V.js} +6 -6
- package/dist/chunk-G7BPNX2V.js.map +1 -0
- package/dist/chunk-I5VZ5SKG.js +328 -0
- package/dist/chunk-I5VZ5SKG.js.map +1 -0
- package/dist/chunk-ICANWSEW.js +204 -0
- package/dist/chunk-ICANWSEW.js.map +1 -0
- package/dist/chunk-KB5NSROG.cjs +211 -0
- package/dist/chunk-KB5NSROG.cjs.map +1 -0
- package/dist/chunk-MWQQRVQC.cjs +259 -0
- package/dist/chunk-MWQQRVQC.cjs.map +1 -0
- package/dist/chunk-NDFAQBQD.cjs +792 -0
- package/dist/chunk-NDFAQBQD.cjs.map +1 -0
- package/dist/chunk-PKRHEXX7.js +74 -0
- package/dist/chunk-PKRHEXX7.js.map +1 -0
- package/dist/chunk-QGWCNTG6.cjs +797 -0
- package/dist/chunk-QGWCNTG6.cjs.map +1 -0
- package/dist/chunk-R4M3BSUG.js +226 -0
- package/dist/chunk-R4M3BSUG.js.map +1 -0
- package/dist/{chunk-KDUHLUK4.cjs → chunk-TBVUN4XN.cjs} +5944 -1992
- package/dist/chunk-TBVUN4XN.cjs.map +1 -0
- package/dist/chunk-UJNHKFBR.cjs +167 -0
- package/dist/chunk-UJNHKFBR.cjs.map +1 -0
- package/dist/chunk-UOFV2ZCI.js +878 -0
- package/dist/chunk-UOFV2ZCI.js.map +1 -0
- package/dist/{chunk-CY4TP3FK.js → chunk-UXGQZUYZ.js} +3 -3
- package/dist/{chunk-CY4TP3FK.js.map → chunk-UXGQZUYZ.js.map} +1 -1
- package/dist/{chunk-CJFKRVED.cjs → chunk-UZ6CYAOG.cjs} +6 -6
- package/dist/chunk-UZ6CYAOG.cjs.map +1 -0
- package/dist/{chunk-RE4RPXT2.cjs → chunk-V5WWQN7P.cjs} +4 -4
- package/dist/{chunk-RE4RPXT2.cjs.map → chunk-V5WWQN7P.cjs.map} +1 -1
- package/dist/chunk-VQAT5HX6.js +756 -0
- package/dist/chunk-VQAT5HX6.js.map +1 -0
- package/dist/chunk-XWGAT2DA.js +44 -0
- package/dist/chunk-XWGAT2DA.js.map +1 -0
- package/dist/chunk-YJ3VDL3Z.cjs +346 -0
- package/dist/chunk-YJ3VDL3Z.cjs.map +1 -0
- package/dist/chunk-Z36N2OQA.cjs +907 -0
- package/dist/chunk-Z36N2OQA.cjs.map +1 -0
- package/dist/chunk-ZLRTFRL4.js +773 -0
- package/dist/chunk-ZLRTFRL4.js.map +1 -0
- package/dist/chunk-ZODCSH2W.cjs +322 -0
- package/dist/chunk-ZODCSH2W.cjs.map +1 -0
- package/dist/server/handlers/a2a.cjs +15 -7
- package/dist/server/handlers/a2a.d.ts +492 -10
- package/dist/server/handlers/a2a.d.ts.map +1 -1
- package/dist/server/handlers/a2a.js +1 -1
- package/dist/server/handlers/agent-builder.cjs +43 -31
- package/dist/server/handlers/agent-builder.d.ts +592 -84
- package/dist/server/handlers/agent-builder.d.ts.map +1 -1
- package/dist/server/handlers/agent-builder.js +1 -1
- package/dist/server/handlers/agents.cjs +51 -39
- package/dist/server/handlers/agents.d.ts +3277 -148
- package/dist/server/handlers/agents.d.ts.map +1 -1
- package/dist/server/handlers/agents.js +1 -1
- package/dist/server/handlers/error.cjs +2 -2
- package/dist/server/handlers/error.js +1 -1
- package/dist/server/handlers/logs.cjs +7 -7
- package/dist/server/handlers/logs.d.ts +135 -27
- package/dist/server/handlers/logs.d.ts.map +1 -1
- package/dist/server/handlers/logs.js +1 -1
- package/dist/server/handlers/memory.cjs +63 -31
- package/dist/server/handlers/memory.d.ts +934 -103
- package/dist/server/handlers/memory.d.ts.map +1 -1
- package/dist/server/handlers/memory.js +1 -1
- package/dist/server/handlers/observability.cjs +24 -8
- package/dist/server/handlers/observability.d.ts +128 -21
- package/dist/server/handlers/observability.d.ts.map +1 -1
- package/dist/server/handlers/observability.js +1 -1
- package/dist/server/handlers/scores.cjs +13 -13
- package/dist/server/handlers/scores.d.ts +110 -141
- package/dist/server/handlers/scores.d.ts.map +1 -1
- package/dist/server/handlers/scores.js +1 -1
- package/dist/server/handlers/test-utils.cjs +15 -0
- package/dist/server/handlers/test-utils.cjs.map +1 -0
- package/dist/server/handlers/test-utils.d.ts +6 -0
- package/dist/server/handlers/test-utils.d.ts.map +1 -0
- package/dist/server/handlers/test-utils.js +13 -0
- package/dist/server/handlers/test-utils.js.map +1 -0
- package/dist/server/handlers/tools.cjs +11 -11
- package/dist/server/handlers/tools.d.ts +69 -23
- package/dist/server/handlers/tools.d.ts.map +1 -1
- package/dist/server/handlers/tools.js +1 -1
- package/dist/server/handlers/utils.cjs +11 -3
- package/dist/server/handlers/utils.d.ts +5 -0
- package/dist/server/handlers/utils.d.ts.map +1 -1
- package/dist/server/handlers/utils.js +1 -1
- package/dist/server/handlers/vector.cjs +31 -7
- package/dist/server/handlers/vector.d.ts +93 -9
- package/dist/server/handlers/vector.d.ts.map +1 -1
- package/dist/server/handlers/vector.js +1 -1
- package/dist/server/handlers/voice.cjs +21 -9
- package/dist/server/handlers/voice.d.ts +81 -40
- package/dist/server/handlers/voice.d.ts.map +1 -1
- package/dist/server/handlers/voice.js +1 -1
- package/dist/server/handlers/workflows.cjs +37 -45
- package/dist/server/handlers/workflows.d.ts +597 -83
- package/dist/server/handlers/workflows.d.ts.map +1 -1
- package/dist/server/handlers/workflows.js +1 -1
- package/dist/server/handlers.cjs +23 -28
- package/dist/server/handlers.d.ts +0 -1
- package/dist/server/handlers.d.ts.map +1 -1
- package/dist/server/handlers.js +11 -12
- package/dist/server/http-exception.d.ts +0 -5
- package/dist/server/http-exception.d.ts.map +1 -1
- package/dist/server/schemas/a2a.d.ts +786 -0
- package/dist/server/schemas/a2a.d.ts.map +1 -0
- package/dist/server/schemas/agent-builder.d.ts +195 -0
- package/dist/server/schemas/agent-builder.d.ts.map +1 -0
- package/dist/server/schemas/agents.d.ts +1375 -0
- package/dist/server/schemas/agents.d.ts.map +1 -0
- package/dist/server/schemas/common.d.ts +165 -0
- package/dist/server/schemas/common.d.ts.map +1 -0
- package/dist/server/schemas/logs.d.ts +124 -0
- package/dist/server/schemas/logs.d.ts.map +1 -0
- package/dist/server/schemas/memory.d.ts +998 -0
- package/dist/server/schemas/memory.d.ts.map +1 -0
- package/dist/server/schemas/observability.d.ts +402 -0
- package/dist/server/schemas/observability.d.ts.map +1 -0
- package/dist/server/schemas/scores.d.ts +259 -0
- package/dist/server/schemas/scores.d.ts.map +1 -0
- package/dist/server/schemas/vectors.d.ts +107 -0
- package/dist/server/schemas/vectors.d.ts.map +1 -0
- package/dist/server/schemas/workflows.d.ts +505 -0
- package/dist/server/schemas/workflows.d.ts.map +1 -0
- package/dist/server/server-adapter/index.cjs +323 -0
- package/dist/server/server-adapter/index.cjs.map +1 -0
- package/dist/server/server-adapter/index.d.ts +52 -0
- package/dist/server/server-adapter/index.d.ts.map +1 -0
- package/dist/server/server-adapter/index.js +309 -0
- package/dist/server/server-adapter/index.js.map +1 -0
- package/dist/server/server-adapter/openapi-utils.d.ts +59 -0
- package/dist/server/server-adapter/openapi-utils.d.ts.map +1 -0
- package/dist/server/server-adapter/routes/a2a.d.ts +3 -0
- package/dist/server/server-adapter/routes/a2a.d.ts.map +1 -0
- package/dist/server/server-adapter/routes/agent-builder.d.ts +3 -0
- package/dist/server/server-adapter/routes/agent-builder.d.ts.map +1 -0
- package/dist/server/server-adapter/routes/agents.d.ts +3 -0
- package/dist/server/server-adapter/routes/agents.d.ts.map +1 -0
- package/dist/server/server-adapter/routes/index.d.ts +41 -0
- package/dist/server/server-adapter/routes/index.d.ts.map +1 -0
- package/dist/server/server-adapter/routes/legacy.d.ts +7 -0
- package/dist/server/server-adapter/routes/legacy.d.ts.map +1 -0
- package/dist/server/server-adapter/routes/logs.d.ts +3 -0
- package/dist/server/server-adapter/routes/logs.d.ts.map +1 -0
- package/dist/server/server-adapter/routes/memory.d.ts +3 -0
- package/dist/server/server-adapter/routes/memory.d.ts.map +1 -0
- package/dist/server/server-adapter/routes/observability.d.ts +3 -0
- package/dist/server/server-adapter/routes/observability.d.ts.map +1 -0
- package/dist/server/server-adapter/routes/route-builder.d.ts +52 -0
- package/dist/server/server-adapter/routes/route-builder.d.ts.map +1 -0
- package/dist/server/server-adapter/routes/scorers.d.ts +3 -0
- package/dist/server/server-adapter/routes/scorers.d.ts.map +1 -0
- package/dist/server/server-adapter/routes/stream-types.d.ts +10 -0
- package/dist/server/server-adapter/routes/stream-types.d.ts.map +1 -0
- package/dist/server/server-adapter/routes/tools.d.ts +3 -0
- package/dist/server/server-adapter/routes/tools.d.ts.map +1 -0
- package/dist/server/server-adapter/routes/vectors.d.ts +3 -0
- package/dist/server/server-adapter/routes/vectors.d.ts.map +1 -0
- package/dist/server/server-adapter/routes/workflows.d.ts +3 -0
- package/dist/server/server-adapter/routes/workflows.d.ts.map +1 -0
- package/dist/server/utils.d.ts +3 -2
- package/dist/server/utils.d.ts.map +1 -1
- package/package.json +26 -8
- package/dist/chunk-2P4VRXBT.js +0 -533
- package/dist/chunk-2P4VRXBT.js.map +0 -1
- package/dist/chunk-2S4IMB6E.cjs +0 -130
- package/dist/chunk-2S4IMB6E.cjs.map +0 -1
- package/dist/chunk-3SNGNFUJ.cjs +0 -128
- package/dist/chunk-3SNGNFUJ.cjs.map +0 -1
- package/dist/chunk-4QCXUEAT.js +0 -25
- package/dist/chunk-4QCXUEAT.js.map +0 -1
- package/dist/chunk-6VPAV4ZV.js +0 -692
- package/dist/chunk-6VPAV4ZV.js.map +0 -1
- package/dist/chunk-7HCPO76Z.js.map +0 -1
- package/dist/chunk-ABRFV4XP.js +0 -83
- package/dist/chunk-ABRFV4XP.js.map +0 -1
- package/dist/chunk-AHB4JCIQ.js +0 -160
- package/dist/chunk-AHB4JCIQ.js.map +0 -1
- package/dist/chunk-AW5BU3RQ.js +0 -192
- package/dist/chunk-AW5BU3RQ.js.map +0 -1
- package/dist/chunk-B7QWVGQQ.cjs +0 -729
- package/dist/chunk-B7QWVGQQ.cjs.map +0 -1
- package/dist/chunk-BATEJLED.js +0 -124
- package/dist/chunk-BATEJLED.js.map +0 -1
- package/dist/chunk-CJFKRVED.cjs.map +0 -1
- package/dist/chunk-EP3JQDPD.cjs +0 -131
- package/dist/chunk-EP3JQDPD.cjs.map +0 -1
- package/dist/chunk-G4PUALCE.cjs +0 -28
- package/dist/chunk-G4PUALCE.cjs.map +0 -1
- package/dist/chunk-GDUKGVFI.cjs +0 -550
- package/dist/chunk-GDUKGVFI.cjs.map +0 -1
- package/dist/chunk-I3C4ODGV.cjs +0 -335
- package/dist/chunk-I3C4ODGV.cjs.map +0 -1
- package/dist/chunk-K5T5A3AL.cjs.map +0 -1
- package/dist/chunk-KDUHLUK4.cjs.map +0 -1
- package/dist/chunk-KSFLUEWV.js.map +0 -1
- package/dist/chunk-LLUOPR3J.js +0 -323
- package/dist/chunk-LLUOPR3J.js.map +0 -1
- package/dist/chunk-MMROOK5J.js.map +0 -1
- package/dist/chunk-MN2TZQ7I.js.map +0 -1
- package/dist/chunk-MYR4PVGN.js +0 -123
- package/dist/chunk-MYR4PVGN.js.map +0 -1
- package/dist/chunk-QQXMIP6C.js +0 -122
- package/dist/chunk-QQXMIP6C.js.map +0 -1
- package/dist/chunk-SPRRK3P7.cjs +0 -200
- package/dist/chunk-SPRRK3P7.cjs.map +0 -1
- package/dist/chunk-TRGAMKHX.cjs +0 -167
- package/dist/chunk-TRGAMKHX.cjs.map +0 -1
- package/dist/chunk-XN74I6VW.cjs +0 -88
- package/dist/chunk-XN74I6VW.cjs.map +0 -1
- package/dist/chunk-YSHNCC6F.cjs +0 -713
- package/dist/chunk-YSHNCC6F.cjs.map +0 -1
- package/dist/chunk-ZLBL4NQC.js +0 -707
- package/dist/chunk-ZLBL4NQC.js.map +0 -1
- package/dist/server/handlers/legacyWorkflows.cjs +0 -48
- package/dist/server/handlers/legacyWorkflows.cjs.map +0 -1
- package/dist/server/handlers/legacyWorkflows.d.ts +0 -59
- package/dist/server/handlers/legacyWorkflows.d.ts.map +0 -1
- package/dist/server/handlers/legacyWorkflows.js +0 -3
- package/dist/server/handlers/legacyWorkflows.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../../../src/server/server-adapter/routes/tools.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,GAAG,CAAC;AAErC,eAAO,MAAM,YAAY,EAAE,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAAiE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vectors.d.ts","sourceRoot":"","sources":["../../../../src/server/server-adapter/routes/vectors.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,GAAG,CAAC;AAErC,eAAO,MAAM,cAAc,EAAE,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAOtD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflows.d.ts","sourceRoot":"","sources":["../../../../src/server/server-adapter/routes/workflows.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,GAAG,CAAC;AAErC,eAAO,MAAM,gBAAgB,EAAE,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAiBxD,CAAC"}
|
package/dist/server/utils.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Mastra } from '@mastra/core';
|
|
2
|
+
import type { SystemMessage } from '@mastra/core/llm';
|
|
2
3
|
import type { Workflow, WorkflowInfo } from '@mastra/core/workflows';
|
|
3
4
|
export declare function getWorkflowInfo(workflow: Workflow): WorkflowInfo;
|
|
4
5
|
/**
|
|
@@ -14,7 +15,7 @@ export declare class WorkflowRegistry {
|
|
|
14
15
|
/**
|
|
15
16
|
* Register all workflows from map
|
|
16
17
|
*/
|
|
17
|
-
static registerTemporaryWorkflows(workflows: Record<string, Workflow>, mastra?: any): void;
|
|
18
|
+
static registerTemporaryWorkflows(workflows: Record<string, Workflow>, mastra?: Mastra<any, any, any, any, any, any, any, any, any>): void;
|
|
18
19
|
/**
|
|
19
20
|
* Get a workflow by ID from the registry (returns undefined if not found)
|
|
20
21
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/server/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/server/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEtD,OAAO,KAAK,EAAqB,QAAQ,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AA0BxF,wBAAgB,eAAe,CAAC,QAAQ,EAAE,QAAQ,GAAG,YAAY,CAsBhE;AAED;;;GAGG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,MAAM,CAAC,mBAAmB,CAAgC;IAElE;;OAEG;IACH,MAAM,CAAC,yBAAyB,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,IAAI;IAItE;;OAEG;IACH,MAAM,CAAC,0BAA0B,CAC/B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,EACnC,MAAM,CAAC,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,GAC3D,IAAI;IAiBP;;OAEG;IACH,MAAM,CAAC,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS;IAI5D;;OAEG;IACH,MAAM,CAAC,eAAe,IAAI,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC;IAIlD;;OAEG;IACH,MAAM,CAAC,wBAAwB,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAGzD;;OAEG;IACH,MAAM,CAAC,OAAO,IAAI,IAAI;IAKtB;;OAEG;IACH,MAAM,CAAC,sBAAsB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO;IAI1D;;OAEG;IACH,MAAM,CAAC,wBAAwB,IAAI,MAAM,EAAE;CAG5C;AAED,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM,CAwB1E"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/server",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-span-scorring-test-20251124132129",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -40,6 +40,16 @@
|
|
|
40
40
|
"default": "./dist/server/handlers/*.cjs"
|
|
41
41
|
}
|
|
42
42
|
},
|
|
43
|
+
"./server-adapter": {
|
|
44
|
+
"import": {
|
|
45
|
+
"types": "./dist/server/server-adapter/index.d.ts",
|
|
46
|
+
"default": "./dist/server/server-adapter/index.js"
|
|
47
|
+
},
|
|
48
|
+
"require": {
|
|
49
|
+
"types": "./dist/server/server-adapter/index.d.ts",
|
|
50
|
+
"default": "./dist/server/server-adapter/index.cjs"
|
|
51
|
+
}
|
|
52
|
+
},
|
|
43
53
|
"./a2a/store": {
|
|
44
54
|
"import": {
|
|
45
55
|
"types": "./dist/server/a2a/store.d.ts",
|
|
@@ -57,24 +67,26 @@
|
|
|
57
67
|
"license": "Apache-2.0",
|
|
58
68
|
"peerDependencies": {
|
|
59
69
|
"zod": "^3.25.0 || ^4.0.0",
|
|
60
|
-
"@mastra/core": "0.0.0-
|
|
70
|
+
"@mastra/core": "0.0.0-span-scorring-test-20251124132129"
|
|
61
71
|
},
|
|
62
72
|
"devDependencies": {
|
|
63
73
|
"@ai-sdk/openai": "^1.3.24",
|
|
64
74
|
"@ai-sdk/openai-v5": "npm:@ai-sdk/openai@2.0.42",
|
|
65
75
|
"@microsoft/api-extractor": "^7.52.8",
|
|
66
|
-
"@types/node": "
|
|
76
|
+
"@types/node": "22.13.17",
|
|
77
|
+
"@vitest/coverage-v8": "4.0.12",
|
|
78
|
+
"@vitest/ui": "4.0.12",
|
|
67
79
|
"eslint": "^9.37.0",
|
|
68
80
|
"superjson": "^2.2.2",
|
|
69
81
|
"tsup": "^8.5.0",
|
|
70
82
|
"typescript": "^5.8.3",
|
|
71
|
-
"vitest": "
|
|
83
|
+
"vitest": "4.0.12",
|
|
72
84
|
"zod": "^3.25.76",
|
|
73
|
-
"@internal/lint": "0.0.0-
|
|
85
|
+
"@internal/lint": "0.0.0-span-scorring-test-20251124132129",
|
|
74
86
|
"@internal/storage-test-utils": "0.0.49",
|
|
75
|
-
"@internal/types-builder": "0.0.0-
|
|
76
|
-
"@mastra/agent-builder": "0.0.0-
|
|
77
|
-
"@mastra/core": "0.0.0-
|
|
87
|
+
"@internal/types-builder": "0.0.0-span-scorring-test-20251124132129",
|
|
88
|
+
"@mastra/agent-builder": "0.0.0-span-scorring-test-20251124132129",
|
|
89
|
+
"@mastra/core": "0.0.0-span-scorring-test-20251124132129"
|
|
78
90
|
},
|
|
79
91
|
"homepage": "https://mastra.ai",
|
|
80
92
|
"repository": {
|
|
@@ -85,6 +97,12 @@
|
|
|
85
97
|
"bugs": {
|
|
86
98
|
"url": "https://github.com/mastra-ai/mastra/issues"
|
|
87
99
|
},
|
|
100
|
+
"engines": {
|
|
101
|
+
"node": ">=22.13.0"
|
|
102
|
+
},
|
|
103
|
+
"dependencies": {
|
|
104
|
+
"hono": "^4.10.5"
|
|
105
|
+
},
|
|
88
106
|
"scripts": {
|
|
89
107
|
"build": "tsup --silent --config tsup.config.ts",
|
|
90
108
|
"build:watch": "pnpm build --watch",
|
package/dist/chunk-2P4VRXBT.js
DELETED
|
@@ -1,533 +0,0 @@
|
|
|
1
|
-
import { validateBody } from './chunk-4QCXUEAT.js';
|
|
2
|
-
import { handleError } from './chunk-CY4TP3FK.js';
|
|
3
|
-
import { HTTPException } from './chunk-MMROOK5J.js';
|
|
4
|
-
import { __export } from './chunk-PR4QN5HX.js';
|
|
5
|
-
import { convertMessages } from '@mastra/core/agent';
|
|
6
|
-
import { RuntimeContext } 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
|
-
getMessagesPaginatedHandler: () => getMessagesPaginatedHandler,
|
|
19
|
-
getThreadByIdHandler: () => getThreadByIdHandler,
|
|
20
|
-
getThreadsHandler: () => getThreadsHandler,
|
|
21
|
-
getThreadsPaginatedHandler: () => getThreadsPaginatedHandler,
|
|
22
|
-
getWorkingMemoryHandler: () => getWorkingMemoryHandler,
|
|
23
|
-
saveMessagesHandler: () => saveMessagesHandler,
|
|
24
|
-
searchMemoryHandler: () => searchMemoryHandler,
|
|
25
|
-
updateThreadHandler: () => updateThreadHandler,
|
|
26
|
-
updateWorkingMemoryHandler: () => updateWorkingMemoryHandler
|
|
27
|
-
});
|
|
28
|
-
async function getMemoryFromContext({
|
|
29
|
-
mastra,
|
|
30
|
-
agentId,
|
|
31
|
-
runtimeContext
|
|
32
|
-
}) {
|
|
33
|
-
const logger = mastra.getLogger();
|
|
34
|
-
let agent;
|
|
35
|
-
if (agentId) {
|
|
36
|
-
try {
|
|
37
|
-
agent = mastra.getAgent(agentId);
|
|
38
|
-
} catch (error) {
|
|
39
|
-
logger.debug("Error getting agent from mastra, searching agents for agent", error);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
if (agentId && !agent) {
|
|
43
|
-
logger.debug("Agent not found, searching agents for agent", { agentId });
|
|
44
|
-
const agents = mastra.getAgents();
|
|
45
|
-
if (Object.keys(agents || {}).length) {
|
|
46
|
-
for (const [_, ag] of Object.entries(agents)) {
|
|
47
|
-
try {
|
|
48
|
-
const agents2 = await ag.listAgents();
|
|
49
|
-
if (agents2[agentId]) {
|
|
50
|
-
agent = agents2[agentId];
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
} catch (error) {
|
|
54
|
-
logger.debug("Error getting agent from agent", error);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
if (!agent) {
|
|
59
|
-
throw new HTTPException(404, { message: "Agent not found" });
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
if (agent) {
|
|
63
|
-
return await agent?.getMemory({
|
|
64
|
-
runtimeContext: runtimeContext ?? new RuntimeContext()
|
|
65
|
-
}) || mastra.getMemory();
|
|
66
|
-
}
|
|
67
|
-
return mastra.getMemory();
|
|
68
|
-
}
|
|
69
|
-
async function getMemoryStatusHandler({
|
|
70
|
-
mastra,
|
|
71
|
-
agentId,
|
|
72
|
-
runtimeContext
|
|
73
|
-
}) {
|
|
74
|
-
try {
|
|
75
|
-
const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });
|
|
76
|
-
if (!memory) {
|
|
77
|
-
return { result: false };
|
|
78
|
-
}
|
|
79
|
-
return { result: true };
|
|
80
|
-
} catch (error) {
|
|
81
|
-
return handleError(error, "Error getting memory status");
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
async function getMemoryConfigHandler({
|
|
85
|
-
mastra,
|
|
86
|
-
agentId,
|
|
87
|
-
runtimeContext
|
|
88
|
-
}) {
|
|
89
|
-
try {
|
|
90
|
-
const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });
|
|
91
|
-
if (!memory) {
|
|
92
|
-
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
93
|
-
}
|
|
94
|
-
const config = memory.getMergedThreadConfig({});
|
|
95
|
-
return { config };
|
|
96
|
-
} catch (error) {
|
|
97
|
-
return handleError(error, "Error getting memory configuration");
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
async function getThreadsHandler({
|
|
101
|
-
mastra,
|
|
102
|
-
agentId,
|
|
103
|
-
resourceId,
|
|
104
|
-
runtimeContext,
|
|
105
|
-
orderBy,
|
|
106
|
-
sortDirection
|
|
107
|
-
}) {
|
|
108
|
-
try {
|
|
109
|
-
const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });
|
|
110
|
-
if (!memory) {
|
|
111
|
-
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
112
|
-
}
|
|
113
|
-
validateBody({ resourceId });
|
|
114
|
-
const threads = await memory.getThreadsByResourceId({
|
|
115
|
-
resourceId,
|
|
116
|
-
orderBy,
|
|
117
|
-
sortDirection
|
|
118
|
-
});
|
|
119
|
-
return threads;
|
|
120
|
-
} catch (error) {
|
|
121
|
-
return handleError(error, "Error getting threads");
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
async function getThreadsPaginatedHandler({
|
|
125
|
-
mastra,
|
|
126
|
-
agentId,
|
|
127
|
-
resourceId,
|
|
128
|
-
runtimeContext,
|
|
129
|
-
page,
|
|
130
|
-
perPage,
|
|
131
|
-
orderBy,
|
|
132
|
-
sortDirection
|
|
133
|
-
}) {
|
|
134
|
-
try {
|
|
135
|
-
const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });
|
|
136
|
-
if (!memory) {
|
|
137
|
-
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
138
|
-
}
|
|
139
|
-
validateBody({ resourceId });
|
|
140
|
-
const result = await memory.getThreadsByResourceIdPaginated({
|
|
141
|
-
resourceId,
|
|
142
|
-
page,
|
|
143
|
-
perPage,
|
|
144
|
-
orderBy,
|
|
145
|
-
sortDirection
|
|
146
|
-
});
|
|
147
|
-
return result;
|
|
148
|
-
} catch (error) {
|
|
149
|
-
return handleError(error, "Error getting paginated threads");
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
async function getThreadByIdHandler({
|
|
153
|
-
mastra,
|
|
154
|
-
agentId,
|
|
155
|
-
threadId,
|
|
156
|
-
runtimeContext
|
|
157
|
-
}) {
|
|
158
|
-
try {
|
|
159
|
-
validateBody({ threadId });
|
|
160
|
-
const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });
|
|
161
|
-
if (!memory) {
|
|
162
|
-
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
163
|
-
}
|
|
164
|
-
const thread = await memory.getThreadById({ threadId });
|
|
165
|
-
if (!thread) {
|
|
166
|
-
throw new HTTPException(404, { message: "Thread not found" });
|
|
167
|
-
}
|
|
168
|
-
return thread;
|
|
169
|
-
} catch (error) {
|
|
170
|
-
return handleError(error, "Error getting thread");
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
async function saveMessagesHandler({
|
|
174
|
-
mastra,
|
|
175
|
-
agentId,
|
|
176
|
-
body,
|
|
177
|
-
runtimeContext
|
|
178
|
-
}) {
|
|
179
|
-
try {
|
|
180
|
-
const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });
|
|
181
|
-
if (!memory) {
|
|
182
|
-
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
183
|
-
}
|
|
184
|
-
if (!body?.messages) {
|
|
185
|
-
throw new HTTPException(400, { message: "Messages are required" });
|
|
186
|
-
}
|
|
187
|
-
if (!Array.isArray(body.messages)) {
|
|
188
|
-
throw new HTTPException(400, { message: "Messages should be an array" });
|
|
189
|
-
}
|
|
190
|
-
const invalidMessages = body.messages.filter((message) => !message.threadId || !message.resourceId);
|
|
191
|
-
if (invalidMessages.length > 0) {
|
|
192
|
-
throw new HTTPException(400, {
|
|
193
|
-
message: `All messages must have threadId and resourceId fields. Found ${invalidMessages.length} invalid message(s).`
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
const processedMessages = body.messages.map((message) => ({
|
|
197
|
-
...message,
|
|
198
|
-
id: message.id || memory.generateId(),
|
|
199
|
-
createdAt: message.createdAt ? new Date(message.createdAt) : /* @__PURE__ */ new Date()
|
|
200
|
-
}));
|
|
201
|
-
const result = await memory.saveMessages({ messages: processedMessages, memoryConfig: {} });
|
|
202
|
-
return result;
|
|
203
|
-
} catch (error) {
|
|
204
|
-
return handleError(error, "Error saving messages");
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
async function createThreadHandler({
|
|
208
|
-
mastra,
|
|
209
|
-
agentId,
|
|
210
|
-
body,
|
|
211
|
-
runtimeContext
|
|
212
|
-
}) {
|
|
213
|
-
try {
|
|
214
|
-
const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });
|
|
215
|
-
if (!memory) {
|
|
216
|
-
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
217
|
-
}
|
|
218
|
-
validateBody({ resourceId: body?.resourceId });
|
|
219
|
-
const result = await memory.createThread({
|
|
220
|
-
resourceId: body?.resourceId,
|
|
221
|
-
title: body?.title,
|
|
222
|
-
metadata: body?.metadata,
|
|
223
|
-
threadId: body?.threadId
|
|
224
|
-
});
|
|
225
|
-
return result;
|
|
226
|
-
} catch (error) {
|
|
227
|
-
return handleError(error, "Error saving thread to memory");
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
async function updateThreadHandler({
|
|
231
|
-
mastra,
|
|
232
|
-
agentId,
|
|
233
|
-
threadId,
|
|
234
|
-
body,
|
|
235
|
-
runtimeContext
|
|
236
|
-
}) {
|
|
237
|
-
try {
|
|
238
|
-
const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });
|
|
239
|
-
if (!body) {
|
|
240
|
-
throw new HTTPException(400, { message: "Body is required" });
|
|
241
|
-
}
|
|
242
|
-
const { title, metadata, resourceId } = body;
|
|
243
|
-
const updatedAt = /* @__PURE__ */ new Date();
|
|
244
|
-
validateBody({ threadId });
|
|
245
|
-
if (!memory) {
|
|
246
|
-
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
247
|
-
}
|
|
248
|
-
const thread = await memory.getThreadById({ threadId });
|
|
249
|
-
if (!thread) {
|
|
250
|
-
throw new HTTPException(404, { message: "Thread not found" });
|
|
251
|
-
}
|
|
252
|
-
const updatedThread = {
|
|
253
|
-
...thread,
|
|
254
|
-
title: title || thread.title,
|
|
255
|
-
metadata: metadata || thread.metadata,
|
|
256
|
-
resourceId: resourceId || thread.resourceId,
|
|
257
|
-
createdAt: thread.createdAt,
|
|
258
|
-
updatedAt
|
|
259
|
-
};
|
|
260
|
-
const result = await memory.saveThread({ thread: updatedThread });
|
|
261
|
-
return result;
|
|
262
|
-
} catch (error) {
|
|
263
|
-
return handleError(error, "Error updating thread");
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
async function deleteThreadHandler({
|
|
267
|
-
mastra,
|
|
268
|
-
agentId,
|
|
269
|
-
threadId,
|
|
270
|
-
runtimeContext
|
|
271
|
-
}) {
|
|
272
|
-
try {
|
|
273
|
-
validateBody({ threadId });
|
|
274
|
-
const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });
|
|
275
|
-
if (!memory) {
|
|
276
|
-
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
277
|
-
}
|
|
278
|
-
const thread = await memory.getThreadById({ threadId });
|
|
279
|
-
if (!thread) {
|
|
280
|
-
throw new HTTPException(404, { message: "Thread not found" });
|
|
281
|
-
}
|
|
282
|
-
await memory.deleteThread(threadId);
|
|
283
|
-
return { result: "Thread deleted" };
|
|
284
|
-
} catch (error) {
|
|
285
|
-
return handleError(error, "Error deleting thread");
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
async function getMessagesPaginatedHandler({
|
|
289
|
-
mastra,
|
|
290
|
-
threadId,
|
|
291
|
-
resourceId,
|
|
292
|
-
selectBy,
|
|
293
|
-
format
|
|
294
|
-
}) {
|
|
295
|
-
try {
|
|
296
|
-
validateBody({ threadId });
|
|
297
|
-
const storage = mastra.getStorage();
|
|
298
|
-
if (!storage) {
|
|
299
|
-
throw new HTTPException(400, { message: "Storage is not initialized" });
|
|
300
|
-
}
|
|
301
|
-
const thread = await storage.getThreadById({ threadId });
|
|
302
|
-
if (!thread) {
|
|
303
|
-
throw new HTTPException(404, { message: "Thread not found" });
|
|
304
|
-
}
|
|
305
|
-
const result = await storage.getMessagesPaginated({ threadId, resourceId, selectBy, format });
|
|
306
|
-
return result;
|
|
307
|
-
} catch (error) {
|
|
308
|
-
return handleError(error, "Error getting messages");
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
async function getMessagesHandler({
|
|
312
|
-
mastra,
|
|
313
|
-
agentId,
|
|
314
|
-
threadId,
|
|
315
|
-
limit,
|
|
316
|
-
runtimeContext
|
|
317
|
-
}) {
|
|
318
|
-
if (limit !== void 0 && (!Number.isInteger(limit) || limit <= 0)) {
|
|
319
|
-
throw new HTTPException(400, { message: "Invalid limit: must be a positive integer" });
|
|
320
|
-
}
|
|
321
|
-
try {
|
|
322
|
-
validateBody({ threadId });
|
|
323
|
-
const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });
|
|
324
|
-
if (!memory) {
|
|
325
|
-
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
326
|
-
}
|
|
327
|
-
const thread = await memory.getThreadById({ threadId });
|
|
328
|
-
if (!thread) {
|
|
329
|
-
throw new HTTPException(404, { message: "Thread not found" });
|
|
330
|
-
}
|
|
331
|
-
const result = await memory.query({
|
|
332
|
-
threadId,
|
|
333
|
-
...limit && { selectBy: { last: limit } }
|
|
334
|
-
});
|
|
335
|
-
const uiMessages = convertMessages(result.messagesV2).to("AIV5.UI");
|
|
336
|
-
return { messages: result.messages, uiMessages, legacyMessages: result.uiMessages };
|
|
337
|
-
} catch (error) {
|
|
338
|
-
return handleError(error, "Error getting messages");
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
async function getWorkingMemoryHandler({
|
|
342
|
-
mastra,
|
|
343
|
-
agentId,
|
|
344
|
-
threadId,
|
|
345
|
-
resourceId,
|
|
346
|
-
runtimeContext,
|
|
347
|
-
memoryConfig
|
|
348
|
-
}) {
|
|
349
|
-
try {
|
|
350
|
-
const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });
|
|
351
|
-
validateBody({ threadId });
|
|
352
|
-
if (!memory) {
|
|
353
|
-
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
354
|
-
}
|
|
355
|
-
const thread = await memory.getThreadById({ threadId });
|
|
356
|
-
const threadExists = !!thread;
|
|
357
|
-
const template = await memory.getWorkingMemoryTemplate({ memoryConfig });
|
|
358
|
-
const workingMemoryTemplate = template?.format === "json" ? { ...template, content: JSON.stringify(generateEmptyFromSchema(template.content)) } : template;
|
|
359
|
-
const workingMemory = await memory.getWorkingMemory({ threadId, resourceId, memoryConfig });
|
|
360
|
-
const config = memory.getMergedThreadConfig(memoryConfig || {});
|
|
361
|
-
const source = config.workingMemory?.scope !== "thread" && resourceId ? "resource" : "thread";
|
|
362
|
-
return { workingMemory, source, workingMemoryTemplate, threadExists };
|
|
363
|
-
} catch (error) {
|
|
364
|
-
return handleError(error, "Error getting working memory");
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
async function updateWorkingMemoryHandler({
|
|
368
|
-
mastra,
|
|
369
|
-
agentId,
|
|
370
|
-
threadId,
|
|
371
|
-
body,
|
|
372
|
-
runtimeContext
|
|
373
|
-
}) {
|
|
374
|
-
try {
|
|
375
|
-
validateBody({ threadId });
|
|
376
|
-
const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });
|
|
377
|
-
const { resourceId, memoryConfig, workingMemory } = body;
|
|
378
|
-
if (!memory) {
|
|
379
|
-
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
380
|
-
}
|
|
381
|
-
const thread = await memory.getThreadById({ threadId });
|
|
382
|
-
if (!thread) {
|
|
383
|
-
throw new HTTPException(404, { message: "Thread not found" });
|
|
384
|
-
}
|
|
385
|
-
await memory.updateWorkingMemory({ threadId, resourceId, workingMemory, memoryConfig });
|
|
386
|
-
return { success: true };
|
|
387
|
-
} catch (error) {
|
|
388
|
-
return handleError(error, "Error updating working memory");
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
async function deleteMessagesHandler({
|
|
392
|
-
mastra,
|
|
393
|
-
agentId,
|
|
394
|
-
messageIds,
|
|
395
|
-
runtimeContext
|
|
396
|
-
}) {
|
|
397
|
-
try {
|
|
398
|
-
if (messageIds === void 0 || messageIds === null) {
|
|
399
|
-
throw new HTTPException(400, { message: "messageIds is required" });
|
|
400
|
-
}
|
|
401
|
-
const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });
|
|
402
|
-
if (!memory) {
|
|
403
|
-
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
404
|
-
}
|
|
405
|
-
await memory.deleteMessages(messageIds);
|
|
406
|
-
let count = 1;
|
|
407
|
-
if (Array.isArray(messageIds)) {
|
|
408
|
-
count = messageIds.length;
|
|
409
|
-
}
|
|
410
|
-
return { success: true, message: `${count} message${count === 1 ? "" : "s"} deleted successfully` };
|
|
411
|
-
} catch (error) {
|
|
412
|
-
return handleError(error, "Error deleting messages");
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
async function searchMemoryHandler({
|
|
416
|
-
mastra,
|
|
417
|
-
agentId,
|
|
418
|
-
searchQuery,
|
|
419
|
-
resourceId,
|
|
420
|
-
threadId,
|
|
421
|
-
limit = 20,
|
|
422
|
-
runtimeContext,
|
|
423
|
-
memoryConfig
|
|
424
|
-
}) {
|
|
425
|
-
try {
|
|
426
|
-
validateBody({ searchQuery, resourceId });
|
|
427
|
-
const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });
|
|
428
|
-
if (!memory) {
|
|
429
|
-
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
430
|
-
}
|
|
431
|
-
const config = memory.getMergedThreadConfig(memoryConfig || {});
|
|
432
|
-
const hasSemanticRecall = !!config?.semanticRecall;
|
|
433
|
-
const resourceScope = typeof config?.semanticRecall === "object" ? config?.semanticRecall?.scope !== "thread" : true;
|
|
434
|
-
if (threadId && !resourceScope) {
|
|
435
|
-
const thread = await memory.getThreadById({ threadId });
|
|
436
|
-
if (!thread) {
|
|
437
|
-
throw new HTTPException(404, { message: "Thread not found" });
|
|
438
|
-
}
|
|
439
|
-
if (thread.resourceId !== resourceId) {
|
|
440
|
-
throw new HTTPException(403, { message: "Thread does not belong to the specified resource" });
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
const searchResults = [];
|
|
444
|
-
if (threadId && !resourceScope) {
|
|
445
|
-
const thread = await memory.getThreadById({ threadId });
|
|
446
|
-
if (!thread) {
|
|
447
|
-
return {
|
|
448
|
-
results: [],
|
|
449
|
-
count: 0,
|
|
450
|
-
query: searchQuery,
|
|
451
|
-
searchScope: resourceScope ? "resource" : "thread",
|
|
452
|
-
searchType: hasSemanticRecall ? "semantic" : "text"
|
|
453
|
-
};
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
if (!threadId) {
|
|
457
|
-
const threads2 = await memory.getThreadsByResourceId({ resourceId });
|
|
458
|
-
if (threads2.length === 0) {
|
|
459
|
-
return {
|
|
460
|
-
results: [],
|
|
461
|
-
count: 0,
|
|
462
|
-
query: searchQuery,
|
|
463
|
-
searchScope: resourceScope ? "resource" : "thread",
|
|
464
|
-
searchType: hasSemanticRecall ? "semantic" : "text"
|
|
465
|
-
};
|
|
466
|
-
}
|
|
467
|
-
threadId = threads2[0].id;
|
|
468
|
-
}
|
|
469
|
-
const beforeRange = typeof config.semanticRecall === `boolean` ? 2 : typeof config.semanticRecall?.messageRange === `number` ? config.semanticRecall.messageRange : config.semanticRecall?.messageRange.before || 2;
|
|
470
|
-
const afterRange = typeof config.semanticRecall === `boolean` ? 2 : typeof config.semanticRecall?.messageRange === `number` ? config.semanticRecall.messageRange : config.semanticRecall?.messageRange.after || 2;
|
|
471
|
-
if (resourceScope && config.semanticRecall) {
|
|
472
|
-
config.semanticRecall = typeof config.semanticRecall === `boolean` ? (
|
|
473
|
-
// make message range 0 so we can highlight the matches in search, message range will include other messages, not the matching ones
|
|
474
|
-
// and we add prev/next messages in a special section on each message anyway
|
|
475
|
-
{ messageRange: 0, topK: 2, scope: "resource" }
|
|
476
|
-
) : { ...config.semanticRecall, messageRange: 0 };
|
|
477
|
-
}
|
|
478
|
-
const result = await memory.rememberMessages({
|
|
479
|
-
threadId,
|
|
480
|
-
resourceId,
|
|
481
|
-
vectorMessageSearch: searchQuery,
|
|
482
|
-
config
|
|
483
|
-
});
|
|
484
|
-
const threads = await memory.getThreadsByResourceId({ resourceId });
|
|
485
|
-
const threadMap = new Map(threads.map((t) => [t.id, t]));
|
|
486
|
-
for (const msg of result.messagesV2) {
|
|
487
|
-
const content = typeof msg.content.content === `string` ? msg.content.content : msg.content.parts?.map((p) => p.type === "text" ? p.text : "").join(" ") || "";
|
|
488
|
-
const msgThreadId = msg.threadId || threadId;
|
|
489
|
-
const thread = threadMap.get(msgThreadId);
|
|
490
|
-
const threadMessages = (await memory.query({ threadId: msgThreadId })).uiMessages;
|
|
491
|
-
const messageIndex = threadMessages.findIndex((m) => m.id === msg.id);
|
|
492
|
-
const searchResult = {
|
|
493
|
-
id: msg.id,
|
|
494
|
-
role: msg.role,
|
|
495
|
-
content,
|
|
496
|
-
createdAt: msg.createdAt,
|
|
497
|
-
threadId: msgThreadId,
|
|
498
|
-
threadTitle: thread?.title || msgThreadId
|
|
499
|
-
};
|
|
500
|
-
if (messageIndex !== -1) {
|
|
501
|
-
searchResult.context = {
|
|
502
|
-
before: threadMessages.slice(Math.max(0, messageIndex - beforeRange), messageIndex).map((m) => ({
|
|
503
|
-
id: m.id,
|
|
504
|
-
role: m.role,
|
|
505
|
-
content: m.content,
|
|
506
|
-
createdAt: m.createdAt || /* @__PURE__ */ new Date()
|
|
507
|
-
})),
|
|
508
|
-
after: threadMessages.slice(messageIndex + 1, messageIndex + afterRange + 1).map((m) => ({
|
|
509
|
-
id: m.id,
|
|
510
|
-
role: m.role,
|
|
511
|
-
content: m.content,
|
|
512
|
-
createdAt: m.createdAt || /* @__PURE__ */ new Date()
|
|
513
|
-
}))
|
|
514
|
-
};
|
|
515
|
-
}
|
|
516
|
-
searchResults.push(searchResult);
|
|
517
|
-
}
|
|
518
|
-
const sortedResults = searchResults.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()).slice(0, limit);
|
|
519
|
-
return {
|
|
520
|
-
results: sortedResults,
|
|
521
|
-
count: sortedResults.length,
|
|
522
|
-
query: searchQuery,
|
|
523
|
-
searchScope: resourceScope ? "resource" : "thread",
|
|
524
|
-
searchType: hasSemanticRecall ? "semantic" : "text"
|
|
525
|
-
};
|
|
526
|
-
} catch (error) {
|
|
527
|
-
return handleError(error, "Error searching memory");
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
export { createThreadHandler, deleteMessagesHandler, deleteThreadHandler, getMemoryConfigHandler, getMemoryStatusHandler, getMessagesHandler, getMessagesPaginatedHandler, getThreadByIdHandler, getThreadsHandler, getThreadsPaginatedHandler, getWorkingMemoryHandler, memory_exports, saveMessagesHandler, searchMemoryHandler, updateThreadHandler, updateWorkingMemoryHandler };
|
|
532
|
-
//# sourceMappingURL=chunk-2P4VRXBT.js.map
|
|
533
|
-
//# sourceMappingURL=chunk-2P4VRXBT.js.map
|