@mastra/react 1.13.0-alpha.2 → 1.13.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. package/dist/{accumulator-BmD8-x9I.cjs → accumulator-Bjfckb5t.cjs} +5 -9
  2. package/dist/{accumulator-BmD8-x9I.cjs.map → accumulator-Bjfckb5t.cjs.map} +1 -1
  3. package/dist/{accumulator-D9jAph99.js → accumulator-DysrPe6U.js} +5 -9
  4. package/dist/{accumulator-D9jAph99.js.map → accumulator-DysrPe6U.js.map} +1 -1
  5. package/dist/chat/index.cjs +1 -1
  6. package/dist/chat/index.js +1 -1
  7. package/dist/{combine-by-ids-CcaZKGT9.js → combine-by-ids-C-0oe4eH.js} +2 -3
  8. package/dist/{combine-by-ids-CcaZKGT9.js.map → combine-by-ids-C-0oe4eH.js.map} +1 -1
  9. package/dist/{combine-by-ids-D_lp6Dvq.cjs → combine-by-ids-ERVPXXBi.cjs} +2 -3
  10. package/dist/{combine-by-ids-D_lp6Dvq.cjs.map → combine-by-ids-ERVPXXBi.cjs.map} +1 -1
  11. package/dist/{experiments-CJw1N3FB.cjs → experiments-Duv0RgkM.cjs} +12 -19
  12. package/dist/{experiments-CJw1N3FB.cjs.map → experiments-Duv0RgkM.cjs.map} +1 -1
  13. package/dist/{experiments-B7vRMK5T.js → experiments-DyecjEut.js} +12 -19
  14. package/dist/{experiments-B7vRMK5T.js.map → experiments-DyecjEut.js.map} +1 -1
  15. package/dist/{feedback-refetch-interval-XD5FVc2k.cjs → feedback-refetch-interval-BBcT9r8s.cjs} +3 -4
  16. package/dist/{feedback-refetch-interval-XD5FVc2k.cjs.map → feedback-refetch-interval-BBcT9r8s.cjs.map} +1 -1
  17. package/dist/{feedback-refetch-interval-DLHzQoVV.js → feedback-refetch-interval-C12Nzb2r.js} +3 -4
  18. package/dist/{feedback-refetch-interval-DLHzQoVV.js.map → feedback-refetch-interval-C12Nzb2r.js.map} +1 -1
  19. package/dist/hooks/agents/index.cjs +19 -37
  20. package/dist/hooks/agents/index.cjs.map +1 -1
  21. package/dist/hooks/agents/index.js +19 -37
  22. package/dist/hooks/agents/index.js.map +1 -1
  23. package/dist/hooks/auth/index.cjs +11 -21
  24. package/dist/hooks/auth/index.cjs.map +1 -1
  25. package/dist/hooks/auth/index.js +11 -21
  26. package/dist/hooks/auth/index.js.map +1 -1
  27. package/dist/hooks/capabilities/index.cjs +11 -21
  28. package/dist/hooks/capabilities/index.cjs.map +1 -1
  29. package/dist/hooks/capabilities/index.js +11 -21
  30. package/dist/hooks/capabilities/index.js.map +1 -1
  31. package/dist/hooks/configuration/index.cjs +2 -3
  32. package/dist/hooks/configuration/index.js +2 -3
  33. package/dist/hooks/datasets/index.cjs +12 -21
  34. package/dist/hooks/datasets/index.cjs.map +1 -1
  35. package/dist/hooks/datasets/index.js +12 -21
  36. package/dist/hooks/datasets/index.js.map +1 -1
  37. package/dist/hooks/embedders/index.cjs +2 -3
  38. package/dist/hooks/embedders/index.js +2 -3
  39. package/dist/hooks/experiments/index.cjs +1 -1
  40. package/dist/hooks/experiments/index.js +1 -1
  41. package/dist/hooks/feedback/index.cjs +3 -4
  42. package/dist/hooks/feedback/index.js +3 -4
  43. package/dist/hooks/llm/index.cjs +2 -3
  44. package/dist/hooks/llm/index.js +2 -3
  45. package/dist/hooks/logs/index.cjs +4 -5
  46. package/dist/hooks/logs/index.js +4 -5
  47. package/dist/hooks/mcps/index.cjs +8 -15
  48. package/dist/hooks/mcps/index.cjs.map +1 -1
  49. package/dist/hooks/mcps/index.js +8 -15
  50. package/dist/hooks/mcps/index.js.map +1 -1
  51. package/dist/hooks/memory/index.cjs +5 -9
  52. package/dist/hooks/memory/index.cjs.map +1 -1
  53. package/dist/hooks/memory/index.js +5 -9
  54. package/dist/hooks/memory/index.js.map +1 -1
  55. package/dist/hooks/metrics/index.cjs +19 -36
  56. package/dist/hooks/metrics/index.cjs.map +1 -1
  57. package/dist/hooks/metrics/index.js +19 -36
  58. package/dist/hooks/metrics/index.js.map +1 -1
  59. package/dist/hooks/processors/index.cjs +2 -3
  60. package/dist/hooks/processors/index.js +2 -3
  61. package/dist/hooks/prompt-blocks/index.cjs +3 -5
  62. package/dist/hooks/prompt-blocks/index.cjs.map +1 -1
  63. package/dist/hooks/prompt-blocks/index.js +3 -5
  64. package/dist/hooks/prompt-blocks/index.js.map +1 -1
  65. package/dist/hooks/query/index.cjs +2 -3
  66. package/dist/hooks/query/index.js +2 -3
  67. package/dist/hooks/review/index.cjs +4 -6
  68. package/dist/hooks/review/index.cjs.map +1 -1
  69. package/dist/hooks/review/index.js +4 -6
  70. package/dist/hooks/review/index.js.map +1 -1
  71. package/dist/hooks/schedules/index.cjs +6 -10
  72. package/dist/hooks/schedules/index.cjs.map +1 -1
  73. package/dist/hooks/schedules/index.js +6 -10
  74. package/dist/hooks/schedules/index.js.map +1 -1
  75. package/dist/hooks/scores/index.cjs +8 -13
  76. package/dist/hooks/scores/index.cjs.map +1 -1
  77. package/dist/hooks/scores/index.js +8 -13
  78. package/dist/hooks/scores/index.js.map +1 -1
  79. package/dist/hooks/templates/index.cjs +2 -3
  80. package/dist/hooks/templates/index.js +2 -3
  81. package/dist/hooks/tool-providers/index.cjs +10 -19
  82. package/dist/hooks/tool-providers/index.cjs.map +1 -1
  83. package/dist/hooks/tool-providers/index.js +10 -19
  84. package/dist/hooks/tool-providers/index.js.map +1 -1
  85. package/dist/hooks/tools/index.cjs +3 -5
  86. package/dist/hooks/tools/index.cjs.map +1 -1
  87. package/dist/hooks/tools/index.js +3 -5
  88. package/dist/hooks/tools/index.js.map +1 -1
  89. package/dist/hooks/traces/index.cjs +28 -51
  90. package/dist/hooks/traces/index.cjs.map +1 -1
  91. package/dist/hooks/traces/index.js +28 -51
  92. package/dist/hooks/traces/index.js.map +1 -1
  93. package/dist/hooks/vectors/index.cjs +2 -3
  94. package/dist/hooks/vectors/index.js +2 -3
  95. package/dist/hooks/voice/index.cjs +3 -4
  96. package/dist/hooks/voice/index.js +3 -4
  97. package/dist/hooks/workflows/index.cjs +7 -11
  98. package/dist/hooks/workflows/index.cjs.map +1 -1
  99. package/dist/hooks/workflows/index.js +7 -11
  100. package/dist/hooks/workflows/index.js.map +1 -1
  101. package/dist/hooks/workspace/index.cjs +12 -22
  102. package/dist/hooks/workspace/index.cjs.map +1 -1
  103. package/dist/hooks/workspace/index.js +12 -22
  104. package/dist/hooks/workspace/index.js.map +1 -1
  105. package/dist/{hooks-XYsmqFCz.cjs → hooks-Bt15IwzP.cjs} +6 -9
  106. package/dist/{hooks-XYsmqFCz.cjs.map → hooks-Bt15IwzP.cjs.map} +1 -1
  107. package/dist/{hooks-DG-Y1KFe.js → hooks-Btt7PyI-.js} +6 -9
  108. package/dist/{hooks-DG-Y1KFe.js.map → hooks-Btt7PyI-.js.map} +1 -1
  109. package/dist/{hooks-BfysjY_K.js → hooks-CEikbhrN.js} +9 -15
  110. package/dist/{hooks-BfysjY_K.js.map → hooks-CEikbhrN.js.map} +1 -1
  111. package/dist/{hooks-BbUMSab8.cjs → hooks-D6LDSEcm.cjs} +9 -15
  112. package/dist/{hooks-BbUMSab8.cjs.map → hooks-D6LDSEcm.cjs.map} +1 -1
  113. package/dist/index.cjs +7 -9
  114. package/dist/index.cjs.map +1 -1
  115. package/dist/index.js +7 -9
  116. package/dist/index.js.map +1 -1
  117. package/dist/{map-CDv4fbu4.js → map-5-4U5rwA.js} +2 -3
  118. package/dist/{map-CDv4fbu4.js.map → map-5-4U5rwA.js.map} +1 -1
  119. package/dist/{map-wjmL1y5O.cjs → map-BGoWBTGy.cjs} +2 -3
  120. package/dist/{map-wjmL1y5O.cjs.map → map-BGoWBTGy.cjs.map} +1 -1
  121. package/dist/{mastra-client-context-Bx_g84YB.js → mastra-client-context-DQ5z_ze9.js} +2 -3
  122. package/dist/{mastra-client-context-Bx_g84YB.js.map → mastra-client-context-DQ5z_ze9.js.map} +1 -1
  123. package/dist/{mastra-client-context-DzX3f0RF.cjs → mastra-client-context-DX8wJM9p.cjs} +2 -3
  124. package/dist/{mastra-client-context-DzX3f0RF.cjs.map → mastra-client-context-DX8wJM9p.cjs.map} +1 -1
  125. package/dist/{query-utils-CcrChYgz.cjs → query-utils-BVgE_xxj.cjs} +2 -3
  126. package/dist/{query-utils-CcrChYgz.cjs.map → query-utils-BVgE_xxj.cjs.map} +1 -1
  127. package/dist/{query-utils-D1NgFnWU.js → query-utils-DvMERIwf.js} +2 -3
  128. package/dist/{query-utils-D1NgFnWU.js.map → query-utils-DvMERIwf.js.map} +1 -1
  129. package/dist/ui/index.cjs +15 -30
  130. package/dist/ui/index.cjs.map +1 -1
  131. package/dist/ui/index.js +14 -28
  132. package/dist/ui/index.js.map +1 -1
  133. package/dist/{use-in-view-B6eJO9Zi.cjs → use-in-view-BxdrrnCw.cjs} +2 -3
  134. package/dist/{use-in-view-B6eJO9Zi.cjs.map → use-in-view-BxdrrnCw.cjs.map} +1 -1
  135. package/dist/{use-in-view-C9sYPGRm.js → use-in-view-CyjKdplM.js} +2 -3
  136. package/dist/{use-in-view-C9sYPGRm.js.map → use-in-view-CyjKdplM.js.map} +1 -1
  137. package/dist/{voice-BOtUdMi8.cjs → voice-Didej2E1.cjs} +5 -8
  138. package/dist/{voice-BOtUdMi8.cjs.map → voice-Didej2E1.cjs.map} +1 -1
  139. package/dist/{voice-DgirjEyH.js → voice-ugGu7VyA.js} +5 -8
  140. package/dist/{voice-DgirjEyH.js.map → voice-ugGu7VyA.js.map} +1 -1
  141. package/package.json +17 -17
@@ -1,6 +1,6 @@
1
- import { n as useMastraClient } from "../../mastra-client-context-Bx_g84YB.js";
1
+ import { n as useMastraClient } from "../../mastra-client-context-DQ5z_ze9.js";
2
2
  import { useMutation, useQuery } from "@tanstack/react-query";
3
- //#region src/hooks/mcps/use-mcp-app-html.ts
3
+ // src/hooks/mcps/use-mcp-app-html.ts
4
4
  /**
5
5
  * The HTML of an MCP tool's `ui://` app resource (from the tool's `_meta`), for rendering the tool's own UI.
6
6
  * Skips the fetch when the tool has no app resource.
@@ -21,8 +21,7 @@ const useMcpAppHtml = ({ serverId, appResourceUri, queryOptions }) => {
21
21
  ...queryOptions
22
22
  });
23
23
  };
24
- //#endregion
25
- //#region src/hooks/mcps/use-mcp-app-tools.ts
24
+ // src/hooks/mcps/use-mcp-app-tools.ts
26
25
  /**
27
26
  * Builds a map of tool names → MCP App info for tools across all registered
28
27
  * MCP servers that have `_meta.ui.resourceUri` (i.e., tools with interactive
@@ -73,8 +72,7 @@ function useMcpAppTools({ queryOptions } = {}) {
73
72
  ...queryOptions
74
73
  });
75
74
  }
76
- //#endregion
77
- //#region src/hooks/mcps/use-mcp-server-tool.ts
75
+ // src/hooks/mcps/use-mcp-server-tool.ts
78
76
  /**
79
77
  * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.
80
78
  */
@@ -104,8 +102,7 @@ const useExecuteMCPTool = ({ serverId, toolId, queryOptions }) => {
104
102
  ...queryOptions
105
103
  });
106
104
  };
107
- //#endregion
108
- //#region src/hooks/mcps/use-mcp-server-tools.ts
105
+ // src/hooks/mcps/use-mcp-server-tools.ts
109
106
  const useMCPServerTools = ({ selectedServer, queryOptions }) => {
110
107
  const client = useMastraClient();
111
108
  return useQuery({
@@ -123,8 +120,7 @@ const useMCPServerTools = ({ selectedServer, queryOptions }) => {
123
120
  ...queryOptions
124
121
  });
125
122
  };
126
- //#endregion
127
- //#region src/hooks/mcps/use-mcp-server-tools-by-id.ts
123
+ // src/hooks/mcps/use-mcp-server-tools-by-id.ts
128
124
  /**
129
125
  * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.
130
126
  */
@@ -141,8 +137,7 @@ const useMCPServerToolsById = ({ serverId, queryOptions }) => {
141
137
  ...queryOptions
142
138
  });
143
139
  };
144
- //#endregion
145
- //#region src/hooks/mcps/use-mcp-servers.ts
140
+ // src/hooks/mcps/use-mcp-servers.ts
146
141
  const useMCPServers = ({ requestContext, queryOptions } = {}) => {
147
142
  const client = useMastraClient();
148
143
  return useQuery({
@@ -153,8 +148,7 @@ const useMCPServers = ({ requestContext, queryOptions } = {}) => {
153
148
  ...queryOptions
154
149
  });
155
150
  };
156
- //#endregion
157
- //#region src/hooks/mcps/use-try-connect-mcp.ts
151
+ // src/hooks/mcps/use-try-connect-mcp.ts
158
152
  async function parseResponse(response) {
159
153
  if ((response.headers.get("content-type") ?? "").includes("text/event-stream")) {
160
154
  const lines = (await response.text()).split("\n");
@@ -224,7 +218,6 @@ const useTryConnectMcp = ({ queryOptions } = {}) => {
224
218
  ...queryOptions
225
219
  });
226
220
  };
227
- //#endregion
228
221
  export { useExecuteMCPTool, useMCPServerTool, useMCPServerTools, useMCPServerToolsById, useMCPServers, useMcpAppHtml, useMcpAppTools, useTryConnectMcp };
229
222
 
230
223
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../src/hooks/mcps/use-mcp-app-html.ts","../../../src/hooks/mcps/use-mcp-app-tools.ts","../../../src/hooks/mcps/use-mcp-server-tool.ts","../../../src/hooks/mcps/use-mcp-server-tools.ts","../../../src/hooks/mcps/use-mcp-server-tools-by-id.ts","../../../src/hooks/mcps/use-mcp-servers.ts","../../../src/hooks/mcps/use-try-connect-mcp.ts"],"sourcesContent":["import type { MastraClient } from '@mastra/client-js';\nimport { useQuery } from '@tanstack/react-query';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\n/** The app HTML, or `null` when the resource has no text. */\ntype McpAppHtml = string | null;\n\nexport type ReadMcpServerResourceResponse = Awaited<ReturnType<MastraClient['readMcpServerResource']>>;\n\n/**\n * The HTML of an MCP tool's `ui://` app resource (from the tool's `_meta`), for rendering the tool's own UI.\n * Skips the fetch when the tool has no app resource.\n */\nexport const useMcpAppHtml = <TData = McpAppHtml>({\n serverId,\n appResourceUri,\n queryOptions,\n}: {\n serverId: string;\n appResourceUri?: string;\n queryOptions?: MastraQueryOptions<McpAppHtml, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['mcp-app-resource', serverId, appResourceUri],\n queryFn: async () => {\n if (!appResourceUri) return null;\n const response = await client.readMcpServerResource(serverId, appResourceUri);\n return response.contents[0]?.text ?? null;\n },\n enabled: appResourceUri !== undefined,\n ...queryOptions,\n });\n};\n","import type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nexport interface McpAppToolInfo {\n serverId: string;\n toolId: string;\n toolName: string;\n resourceUri: string;\n}\n\n/**\n * Builds a map of tool names → MCP App info for tools across all registered\n * MCP servers that have `_meta.ui.resourceUri` (i.e., tools with interactive\n * MCP App UIs).\n *\n * For each app tool, entries are created under both the original tool name\n * and the namespaced name (`${serverId}_${toolName}`) so that agent tools\n * sourced via `MCPClient.listTools()` (which namespaces) can be resolved.\n */\nexport function useMcpAppTools<TData = Record<string, McpAppToolInfo>>({\n queryOptions,\n}: { queryOptions?: MastraQueryOptions<Record<string, McpAppToolInfo>, TData> } = {}): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['mcp-app-tools'],\n queryFn: async () => {\n const map: Record<string, McpAppToolInfo> = {};\n\n const { servers } = await client.getMcpServers();\n if (!servers?.length) return map;\n\n const results = await Promise.allSettled(\n servers.map(async server => {\n const { tools } = await client.getMcpServerTools(server.id);\n return { serverId: server.id, tools };\n }),\n );\n\n for (const result of results) {\n if (result.status !== 'fulfilled') continue;\n const { serverId, tools } = result.value;\n for (const tool of tools) {\n const meta = tool._meta as { ui?: { resourceUri?: string } } | undefined;\n const resourceUri = meta?.ui?.resourceUri;\n if (resourceUri) {\n const toolId = tool.name;\n const info: McpAppToolInfo = { serverId, toolId, toolName: tool.name, resourceUri };\n map[toolId] = info;\n if (tool.name !== toolId) {\n map[tool.name] = info;\n }\n // Also map the namespaced name used by MCPClient.listTools()\n map[`${serverId}_${tool.name}`] = info;\n }\n }\n }\n\n return map;\n },\n staleTime: 60_000,\n refetchOnWindowFocus: false,\n ...queryOptions,\n });\n}\n","import type { MastraClient } from '@mastra/client-js';\nimport type { RequestContext } from '@mastra/core/request-context';\nimport { useMutation, useQuery } from '@tanstack/react-query';\nimport type { UseMutationResult, UseQueryResult } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraMutationOptions, MastraQueryOptions } from '../shared/query-options';\n\ntype MCPServerToolDetails = Awaited<ReturnType<ReturnType<MastraClient['getMcpServerTool']>['details']>>;\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useMCPServerTool = <TData = MCPServerToolDetails>({\n serverId,\n toolId,\n requestContext,\n queryOptions,\n}: {\n serverId: string;\n toolId: string;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<MCPServerToolDetails, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['mcp-server-tool', serverId, toolId],\n queryFn: () => {\n const instance = client.getMcpServerTool(serverId, toolId);\n return instance.details(requestContext);\n },\n ...queryOptions,\n });\n};\n\nexport type ExecuteMCPToolResponse = Awaited<ReturnType<ReturnType<MastraClient['getMcpServerTool']>['execute']>>;\ntype ExecuteMCPToolVariables = { data: any; requestContext?: Record<string, any> };\n\nexport const useExecuteMCPTool = ({\n serverId,\n toolId,\n queryOptions,\n}: {\n serverId: string;\n toolId: string;\n queryOptions?: MastraMutationOptions<ExecuteMCPToolResponse, ExecuteMCPToolVariables>;\n}): UseMutationResult<ExecuteMCPToolResponse, Error, ExecuteMCPToolVariables> => {\n const client = useMastraClient();\n\n return useMutation({\n mutationFn: ({ data, requestContext }: ExecuteMCPToolVariables) => {\n const instance = client.getMcpServerTool(serverId, toolId);\n return instance.execute({ data, requestContext: requestContext as RequestContext });\n },\n ...queryOptions,\n });\n};\n","import type { McpToolInfo as SdkMcpToolInfo } from '@mastra/client-js';\nimport type { ServerInfo } from '@mastra/core/mcp';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nexport const useMCPServerTools = <TData = Record<string, SdkMcpToolInfo>>({\n selectedServer,\n queryOptions,\n}: {\n selectedServer: ServerInfo;\n queryOptions?: MastraQueryOptions<Record<string, SdkMcpToolInfo>, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['mcpserver-tools', selectedServer?.id],\n queryFn: async () => {\n const response = await client.getMcpServerTools(selectedServer?.id);\n const fetchedToolsArray: SdkMcpToolInfo[] = response.tools;\n const transformedTools: Record<string, SdkMcpToolInfo> = {};\n fetchedToolsArray.forEach((sdkToolInfo: SdkMcpToolInfo) => {\n transformedTools[sdkToolInfo.name] = sdkToolInfo;\n });\n\n return transformedTools;\n },\n retry: false,\n refetchOnWindowFocus: false,\n ...queryOptions,\n });\n};\n","import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\ntype MCPServerToolsById = Record<string, Awaited<ReturnType<MastraClient['getMcpServerTools']>>['tools'][number]>;\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useMCPServerToolsById = <TData = MCPServerToolsById>({\n serverId,\n queryOptions,\n}: {\n serverId: string | null;\n queryOptions?: MastraQueryOptions<MCPServerToolsById, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['mcpserver-tools', serverId],\n queryFn: async (): Promise<MCPServerToolsById> => {\n const response = await client.getMcpServerTools(serverId!);\n return Object.fromEntries(response.tools.map(tool => [tool.name, tool]));\n },\n retry: false,\n refetchOnWindowFocus: false,\n ...queryOptions,\n });\n};\n","import type { McpServerListResponse } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nexport const useMCPServers = <TData = McpServerListResponse['servers']>({\n requestContext,\n queryOptions,\n}: {\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<McpServerListResponse['servers'], TData>;\n} = {}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['mcp-servers'],\n queryFn: async () => {\n const mcpServers: McpServerListResponse['servers'] = (await client.getMcpServers(requestContext)).servers;\n return mcpServers;\n },\n ...queryOptions,\n });\n};\n","import { useMutation } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraMutationOptions } from '../shared/query-options';\n\ninterface McpTool {\n name: string;\n description?: string;\n inputSchema?: Record<string, unknown>;\n}\n\nexport interface TryConnectResult {\n tools: McpTool[];\n}\n\nasync function parseResponse(response: Response): Promise<unknown> {\n const contentType = response.headers.get('content-type') ?? '';\n\n if (contentType.includes('text/event-stream')) {\n const text = await response.text();\n const lines = text.split('\\n');\n\n for (const line of lines) {\n if (line.startsWith('data:')) {\n const data = line.slice('data:'.length).trim();\n if (data) {\n return JSON.parse(data);\n }\n }\n }\n\n throw new Error('No data found in SSE response');\n }\n\n return response.json();\n}\n\nasync function connectAndListTools(url: string, clientHeaders?: Record<string, string>): Promise<TryConnectResult> {\n const baseHeaders: Record<string, string> = {\n ...clientHeaders,\n 'Content-Type': 'application/json',\n Accept: 'application/json, text/event-stream',\n };\n\n // Step 1: Initialize\n const initResponse = await fetch(url, {\n method: 'POST',\n headers: baseHeaders,\n credentials: 'include',\n body: JSON.stringify({\n jsonrpc: '2.0',\n id: 1,\n method: 'initialize',\n params: {\n protocolVersion: '2025-03-26',\n capabilities: {},\n clientInfo: { name: 'mastra-playground', version: '1.0.0' },\n },\n }),\n });\n\n if (!initResponse.ok) {\n throw new Error(`Initialize failed: ${initResponse.status} ${initResponse.statusText}`);\n }\n\n const sessionId = initResponse.headers.get('Mcp-Session-Id');\n await parseResponse(initResponse);\n\n const sessionHeaders: Record<string, string> = {\n ...baseHeaders,\n };\n if (sessionId) {\n sessionHeaders['Mcp-Session-Id'] = sessionId;\n }\n\n // Step 2: Send initialized notification\n await fetch(url, {\n method: 'POST',\n headers: sessionHeaders,\n credentials: 'include',\n body: JSON.stringify({\n jsonrpc: '2.0',\n method: 'notifications/initialized',\n }),\n });\n\n // Step 3: List tools\n const toolsResponse = await fetch(url, {\n method: 'POST',\n headers: sessionHeaders,\n credentials: 'include',\n body: JSON.stringify({\n jsonrpc: '2.0',\n id: 2,\n method: 'tools/list',\n }),\n });\n\n if (!toolsResponse.ok) {\n throw new Error(`tools/list failed: ${toolsResponse.status} ${toolsResponse.statusText}`);\n }\n\n const toolsResult = (await parseResponse(toolsResponse)) as { result?: { tools?: McpTool[] } };\n\n return {\n tools: toolsResult.result?.tools ?? [],\n };\n}\n\nexport const useTryConnectMcp = ({\n queryOptions,\n}: { queryOptions?: MastraMutationOptions<TryConnectResult, string> } = {}) => {\n const client = useMastraClient();\n const clientHeaders = (client.options?.headers as Record<string, string>) ?? {};\n\n return useMutation({\n mutationFn: (url: string) => connectAndListTools(url, clientHeaders),\n ...queryOptions,\n });\n};\n\nexport type TryConnectMcpMutation = ReturnType<typeof useTryConnectMcp>;\n"],"mappings":";;;;;;;AAeA,MAAa,iBAAqC,EAChD,UACA,gBACA,mBAKkC;CAClC,MAAM,SAAS,gBAAgB;CAE/B,OAAO,SAAS;EACd,UAAU;GAAC;GAAoB;GAAU;EAAc;EACvD,SAAS,YAAY;GACnB,IAAI,CAAC,gBAAgB,OAAO;GAE5B,QAAO,MADgB,OAAO,sBAAsB,UAAU,cAAc,EAAA,CAC5D,SAAS,EAAE,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I,MAAM,sBAAsB,cAAc,OAAO,GAAG,cAAc,YAAY;CAK1F,OAAO,EACL,QAAO,MAHkB,cAAc,aAAa,EAAA,CAGjC,QAAQ,SAAS,CAAC,EACvC;AACF;AAEA,MAAa,oBAAoB,EAC/B,iBACsE,CAAC,MAAM;CAE7E,MAAM,gBADS,gBACa,CAAC,CAAC,SAAS,WAAsC,CAAC;CAE9E,OAAO,YAAY;EACjB,aAAa,QAAgB,oBAAoB,KAAK,aAAa;EACnE,GAAG;CACL,CAAC;AACH"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../src/hooks/mcps/use-mcp-app-html.ts","../../../src/hooks/mcps/use-mcp-app-tools.ts","../../../src/hooks/mcps/use-mcp-server-tool.ts","../../../src/hooks/mcps/use-mcp-server-tools.ts","../../../src/hooks/mcps/use-mcp-server-tools-by-id.ts","../../../src/hooks/mcps/use-mcp-servers.ts","../../../src/hooks/mcps/use-try-connect-mcp.ts"],"sourcesContent":["import type { MastraClient } from '@mastra/client-js';\nimport { useQuery } from '@tanstack/react-query';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\n/** The app HTML, or `null` when the resource has no text. */\ntype McpAppHtml = string | null;\n\nexport type ReadMcpServerResourceResponse = Awaited<ReturnType<MastraClient['readMcpServerResource']>>;\n\n/**\n * The HTML of an MCP tool's `ui://` app resource (from the tool's `_meta`), for rendering the tool's own UI.\n * Skips the fetch when the tool has no app resource.\n */\nexport const useMcpAppHtml = <TData = McpAppHtml>({\n serverId,\n appResourceUri,\n queryOptions,\n}: {\n serverId: string;\n appResourceUri?: string;\n queryOptions?: MastraQueryOptions<McpAppHtml, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['mcp-app-resource', serverId, appResourceUri],\n queryFn: async () => {\n if (!appResourceUri) return null;\n const response = await client.readMcpServerResource(serverId, appResourceUri);\n return response.contents[0]?.text ?? null;\n },\n enabled: appResourceUri !== undefined,\n ...queryOptions,\n });\n};\n","import type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nexport interface McpAppToolInfo {\n serverId: string;\n toolId: string;\n toolName: string;\n resourceUri: string;\n}\n\n/**\n * Builds a map of tool names → MCP App info for tools across all registered\n * MCP servers that have `_meta.ui.resourceUri` (i.e., tools with interactive\n * MCP App UIs).\n *\n * For each app tool, entries are created under both the original tool name\n * and the namespaced name (`${serverId}_${toolName}`) so that agent tools\n * sourced via `MCPClient.listTools()` (which namespaces) can be resolved.\n */\nexport function useMcpAppTools<TData = Record<string, McpAppToolInfo>>({\n queryOptions,\n}: { queryOptions?: MastraQueryOptions<Record<string, McpAppToolInfo>, TData> } = {}): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['mcp-app-tools'],\n queryFn: async () => {\n const map: Record<string, McpAppToolInfo> = {};\n\n const { servers } = await client.getMcpServers();\n if (!servers?.length) return map;\n\n const results = await Promise.allSettled(\n servers.map(async server => {\n const { tools } = await client.getMcpServerTools(server.id);\n return { serverId: server.id, tools };\n }),\n );\n\n for (const result of results) {\n if (result.status !== 'fulfilled') continue;\n const { serverId, tools } = result.value;\n for (const tool of tools) {\n const meta = tool._meta as { ui?: { resourceUri?: string } } | undefined;\n const resourceUri = meta?.ui?.resourceUri;\n if (resourceUri) {\n const toolId = tool.name;\n const info: McpAppToolInfo = { serverId, toolId, toolName: tool.name, resourceUri };\n map[toolId] = info;\n if (tool.name !== toolId) {\n map[tool.name] = info;\n }\n // Also map the namespaced name used by MCPClient.listTools()\n map[`${serverId}_${tool.name}`] = info;\n }\n }\n }\n\n return map;\n },\n staleTime: 60_000,\n refetchOnWindowFocus: false,\n ...queryOptions,\n });\n}\n","import type { MastraClient } from '@mastra/client-js';\nimport type { RequestContext } from '@mastra/core/request-context';\nimport { useMutation, useQuery } from '@tanstack/react-query';\nimport type { UseMutationResult, UseQueryResult } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraMutationOptions, MastraQueryOptions } from '../shared/query-options';\n\ntype MCPServerToolDetails = Awaited<ReturnType<ReturnType<MastraClient['getMcpServerTool']>['details']>>;\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useMCPServerTool = <TData = MCPServerToolDetails>({\n serverId,\n toolId,\n requestContext,\n queryOptions,\n}: {\n serverId: string;\n toolId: string;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<MCPServerToolDetails, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['mcp-server-tool', serverId, toolId],\n queryFn: () => {\n const instance = client.getMcpServerTool(serverId, toolId);\n return instance.details(requestContext);\n },\n ...queryOptions,\n });\n};\n\nexport type ExecuteMCPToolResponse = Awaited<ReturnType<ReturnType<MastraClient['getMcpServerTool']>['execute']>>;\ntype ExecuteMCPToolVariables = { data: any; requestContext?: Record<string, any> };\n\nexport const useExecuteMCPTool = ({\n serverId,\n toolId,\n queryOptions,\n}: {\n serverId: string;\n toolId: string;\n queryOptions?: MastraMutationOptions<ExecuteMCPToolResponse, ExecuteMCPToolVariables>;\n}): UseMutationResult<ExecuteMCPToolResponse, Error, ExecuteMCPToolVariables> => {\n const client = useMastraClient();\n\n return useMutation({\n mutationFn: ({ data, requestContext }: ExecuteMCPToolVariables) => {\n const instance = client.getMcpServerTool(serverId, toolId);\n return instance.execute({ data, requestContext: requestContext as RequestContext });\n },\n ...queryOptions,\n });\n};\n","import type { McpToolInfo as SdkMcpToolInfo } from '@mastra/client-js';\nimport type { ServerInfo } from '@mastra/core/mcp';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nexport const useMCPServerTools = <TData = Record<string, SdkMcpToolInfo>>({\n selectedServer,\n queryOptions,\n}: {\n selectedServer: ServerInfo;\n queryOptions?: MastraQueryOptions<Record<string, SdkMcpToolInfo>, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['mcpserver-tools', selectedServer?.id],\n queryFn: async () => {\n const response = await client.getMcpServerTools(selectedServer?.id);\n const fetchedToolsArray: SdkMcpToolInfo[] = response.tools;\n const transformedTools: Record<string, SdkMcpToolInfo> = {};\n fetchedToolsArray.forEach((sdkToolInfo: SdkMcpToolInfo) => {\n transformedTools[sdkToolInfo.name] = sdkToolInfo;\n });\n\n return transformedTools;\n },\n retry: false,\n refetchOnWindowFocus: false,\n ...queryOptions,\n });\n};\n","import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\ntype MCPServerToolsById = Record<string, Awaited<ReturnType<MastraClient['getMcpServerTools']>>['tools'][number]>;\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useMCPServerToolsById = <TData = MCPServerToolsById>({\n serverId,\n queryOptions,\n}: {\n serverId: string | null;\n queryOptions?: MastraQueryOptions<MCPServerToolsById, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['mcpserver-tools', serverId],\n queryFn: async (): Promise<MCPServerToolsById> => {\n const response = await client.getMcpServerTools(serverId!);\n return Object.fromEntries(response.tools.map(tool => [tool.name, tool]));\n },\n retry: false,\n refetchOnWindowFocus: false,\n ...queryOptions,\n });\n};\n","import type { McpServerListResponse } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nexport const useMCPServers = <TData = McpServerListResponse['servers']>({\n requestContext,\n queryOptions,\n}: {\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<McpServerListResponse['servers'], TData>;\n} = {}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['mcp-servers'],\n queryFn: async () => {\n const mcpServers: McpServerListResponse['servers'] = (await client.getMcpServers(requestContext)).servers;\n return mcpServers;\n },\n ...queryOptions,\n });\n};\n","import { useMutation } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraMutationOptions } from '../shared/query-options';\n\ninterface McpTool {\n name: string;\n description?: string;\n inputSchema?: Record<string, unknown>;\n}\n\nexport interface TryConnectResult {\n tools: McpTool[];\n}\n\nasync function parseResponse(response: Response): Promise<unknown> {\n const contentType = response.headers.get('content-type') ?? '';\n\n if (contentType.includes('text/event-stream')) {\n const text = await response.text();\n const lines = text.split('\\n');\n\n for (const line of lines) {\n if (line.startsWith('data:')) {\n const data = line.slice('data:'.length).trim();\n if (data) {\n return JSON.parse(data);\n }\n }\n }\n\n throw new Error('No data found in SSE response');\n }\n\n return response.json();\n}\n\nasync function connectAndListTools(url: string, clientHeaders?: Record<string, string>): Promise<TryConnectResult> {\n const baseHeaders: Record<string, string> = {\n ...clientHeaders,\n 'Content-Type': 'application/json',\n Accept: 'application/json, text/event-stream',\n };\n\n // Step 1: Initialize\n const initResponse = await fetch(url, {\n method: 'POST',\n headers: baseHeaders,\n credentials: 'include',\n body: JSON.stringify({\n jsonrpc: '2.0',\n id: 1,\n method: 'initialize',\n params: {\n protocolVersion: '2025-03-26',\n capabilities: {},\n clientInfo: { name: 'mastra-playground', version: '1.0.0' },\n },\n }),\n });\n\n if (!initResponse.ok) {\n throw new Error(`Initialize failed: ${initResponse.status} ${initResponse.statusText}`);\n }\n\n const sessionId = initResponse.headers.get('Mcp-Session-Id');\n await parseResponse(initResponse);\n\n const sessionHeaders: Record<string, string> = {\n ...baseHeaders,\n };\n if (sessionId) {\n sessionHeaders['Mcp-Session-Id'] = sessionId;\n }\n\n // Step 2: Send initialized notification\n await fetch(url, {\n method: 'POST',\n headers: sessionHeaders,\n credentials: 'include',\n body: JSON.stringify({\n jsonrpc: '2.0',\n method: 'notifications/initialized',\n }),\n });\n\n // Step 3: List tools\n const toolsResponse = await fetch(url, {\n method: 'POST',\n headers: sessionHeaders,\n credentials: 'include',\n body: JSON.stringify({\n jsonrpc: '2.0',\n id: 2,\n method: 'tools/list',\n }),\n });\n\n if (!toolsResponse.ok) {\n throw new Error(`tools/list failed: ${toolsResponse.status} ${toolsResponse.statusText}`);\n }\n\n const toolsResult = (await parseResponse(toolsResponse)) as { result?: { tools?: McpTool[] } };\n\n return {\n tools: toolsResult.result?.tools ?? [],\n };\n}\n\nexport const useTryConnectMcp = ({\n queryOptions,\n}: { queryOptions?: MastraMutationOptions<TryConnectResult, string> } = {}) => {\n const client = useMastraClient();\n const clientHeaders = (client.options?.headers as Record<string, string>) ?? {};\n\n return useMutation({\n mutationFn: (url: string) => connectAndListTools(url, clientHeaders),\n ...queryOptions,\n });\n};\n\nexport type TryConnectMcpMutation = ReturnType<typeof useTryConnectMcp>;\n"],"mappings":";;;;;;;AAeA,MAAa,iBAAqC,EAChD,UACA,gBACA,mBAKkC;CAClC,MAAM,SAAS,gBAAgB;CAE/B,OAAO,SAAS;EACd,UAAU;GAAC;GAAoB;GAAU;EAAc;EACvD,SAAS,YAAY;GACnB,IAAI,CAAC,gBAAgB,OAAO;GAE5B,QAAO,MADgB,OAAO,sBAAsB,UAAU,cAAc,EAAA,CAC5D,SAAS,EAAE,EAAE,QAAQ;EACvC;EACA,SAAS,mBAAmB,KAAA;EAC5B,GAAG;CACL,CAAC;AACH;;;;;;;;;;;ACfA,SAAgB,eAAuD,EACrE,iBACgF,CAAC,GAAiC;CAClH,MAAM,SAAS,gBAAgB;CAE/B,OAAO,SAAS;EACd,UAAU,CAAC,eAAe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AAC,CAAC,SAAS,WAAsC,CAAC;CAE9E,OAAO,YAAY;EACjB,aAAa,QAAgB,oBAAoB,KAAK,aAAa;EACnE,GAAG;CACL,CAAC;AACH"}
@@ -1,8 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_mastra_client_context = require("../../mastra-client-context-DzX3f0RF.cjs");
2
+ const require_mastra_client_context = require("../../mastra-client-context-DX8wJM9p.cjs");
3
3
  let react = require("react");
4
4
  let _tanstack_react_query = require("@tanstack/react-query");
5
- //#region src/hooks/memory/use-memory-thread-messages.ts
5
+ // src/hooks/memory/use-memory-thread-messages.ts
6
6
  const memoryThreadMessagesQueryKey = (threadId, page) => [
7
7
  "memory",
8
8
  "thread",
@@ -21,8 +21,7 @@ function useMemoryThreadMessages({ threadId, page = 0, perPage = 100, queryOptio
21
21
  ...queryOptions
22
22
  });
23
23
  }
24
- //#endregion
25
- //#region src/hooks/memory/use-observational-memory.ts
24
+ // src/hooks/memory/use-observational-memory.ts
26
25
  const observationalMemoryQueryKey = (agentId, threadId) => [
27
26
  "memory",
28
27
  "observational-memory",
@@ -42,8 +41,7 @@ function useObservationalMemory({ agentId, threadId, resourceId, queryOptions })
42
41
  ...queryOptions
43
42
  });
44
43
  }
45
- //#endregion
46
- //#region src/hooks/memory/use-memory-status.ts
44
+ // src/hooks/memory/use-memory-status.ts
47
45
  const memoryStatusQueryKey = (agentId, threadId) => [
48
46
  "memory",
49
47
  "status",
@@ -58,8 +56,7 @@ function useMemoryStatus({ agentId, threadId, queryOptions }) {
58
56
  ...queryOptions
59
57
  });
60
58
  }
61
- //#endregion
62
- //#region src/hooks/memory/use-memory.ts
59
+ // src/hooks/memory/use-memory.ts
63
60
  /**
64
61
  * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.
65
62
  */
@@ -307,7 +304,6 @@ const useMemoryWithOMStatus = ({ agentId, resourceId, threadId, pollWhenActive =
307
304
  }, [isObserving, isReflecting]);
308
305
  return query;
309
306
  };
310
- //#endregion
311
307
  exports.memoryStatusQueryKey = memoryStatusQueryKey;
312
308
  exports.memoryThreadMessagesQueryKey = memoryThreadMessagesQueryKey;
313
309
  exports.observationalMemoryQueryKey = observationalMemoryQueryKey;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["useMastraClient","useQuery","skipToken","useMastraClient","useQuery","skipToken","useMastraClient","useQuery","skipToken","useMastraClient","useQuery","useQueryClient","useMutation","useState"],"sources":["../../../src/hooks/memory/use-memory-thread-messages.ts","../../../src/hooks/memory/use-observational-memory.ts","../../../src/hooks/memory/use-memory-status.ts","../../../src/hooks/memory/use-memory.ts"],"sourcesContent":["import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { skipToken, useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nexport const memoryThreadMessagesQueryKey = (threadId: string | undefined, page?: number) =>\n ['memory', 'thread', threadId, 'messages', page ?? 0] as const;\n\ntype MemoryThreadMessagesResponse = Awaited<ReturnType<ReturnType<MastraClient['getMemoryThread']>['listMessages']>>;\n\nexport function useMemoryThreadMessages<TData = MemoryThreadMessagesResponse>({\n threadId,\n page = 0,\n perPage = 100,\n queryOptions,\n}: {\n threadId: string | undefined;\n page?: number;\n perPage?: number;\n queryOptions?: MastraQueryOptions<MemoryThreadMessagesResponse, TData>;\n}): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: memoryThreadMessagesQueryKey(threadId, page),\n queryFn: threadId ? () => client.getMemoryThread({ threadId }).listMessages({ page, perPage }) : skipToken,\n ...queryOptions,\n });\n}\n","import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { skipToken, useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nexport const observationalMemoryQueryKey = (agentId: string | undefined, threadId: string | undefined) =>\n ['memory', 'observational-memory', agentId, threadId] as const;\n\ntype ObservationalMemoryResponse = Awaited<ReturnType<MastraClient['getObservationalMemory']>>;\n\nexport function useObservationalMemory<TData = ObservationalMemoryResponse>({\n agentId,\n threadId,\n resourceId,\n queryOptions,\n}: {\n agentId: string | undefined;\n threadId: string | undefined;\n resourceId?: string;\n queryOptions?: MastraQueryOptions<ObservationalMemoryResponse, TData>;\n}): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: observationalMemoryQueryKey(agentId, threadId),\n queryFn:\n agentId && threadId\n ? () =>\n client.getObservationalMemory({\n agentId,\n threadId,\n resourceId,\n })\n : skipToken,\n // The record is read by several surfaces at once (collapsed memory bar, OM\n // section, detail panel). A short stale window lets a newly mounted consumer\n // reuse the cached record instead of refiring the request; freshness still\n // comes from the explicit refetch on stream finish/observation signals.\n staleTime: 5_000,\n ...queryOptions,\n });\n}\n","import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { skipToken, useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nexport const memoryStatusQueryKey = (agentId: string | undefined, threadId?: string) =>\n ['memory', 'status', agentId, threadId] as const;\n\ntype MemoryStatusResponse = Awaited<ReturnType<MastraClient['getMemoryStatus']>>;\n\nexport function useMemoryStatus<TData = MemoryStatusResponse>({\n agentId,\n threadId,\n queryOptions,\n}: {\n agentId: string | undefined;\n threadId?: string;\n queryOptions?: MastraQueryOptions<MemoryStatusResponse, TData>;\n}): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: memoryStatusQueryKey(agentId, threadId),\n queryFn: agentId\n ? () =>\n client.getMemoryStatus(agentId, undefined, {\n threadId,\n })\n : skipToken,\n ...queryOptions,\n });\n}\n","import type { GetObservationalMemoryResponse, GetMemoryStatusResponse, MastraClient } from '@mastra/client-js';\nimport { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';\nimport type { UseMutationResult, UseQueryResult } from '@tanstack/react-query';\nimport { useState, useEffect } from 'react';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraMutationOptions, MastraQueryOptions } from '../shared/query-options';\n\nexport interface MemorySearchParams {\n lastMessages?: number | false;\n}\n\ntype MemoryStatusResponse = Awaited<ReturnType<MastraClient['getMemoryStatus']>> | null;\ntype MemoryConfigResponse = Awaited<ReturnType<MastraClient['getMemoryConfig']>> | null;\ntype ThreadResponse = Awaited<ReturnType<ReturnType<MastraClient['getMemoryThread']>['get']>>;\ntype ThreadsResponse = Awaited<ReturnType<MastraClient['listMemoryThreads']>>['threads'] | null;\ntype UpdateThreadResponse = Awaited<ReturnType<ReturnType<MastraClient['getMemoryThread']>['update']>>;\ntype CloneThreadResponse = Awaited<ReturnType<ReturnType<MastraClient['getMemoryThread']>['clone']>>;\ntype SearchMemoryResponse = Awaited<ReturnType<MastraClient['searchMemory']>>;\ntype ThreadVariables = { threadId: string; agentId: string };\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useMemory = <TData = MemoryStatusResponse>({\n agentId,\n requestContext,\n queryOptions,\n}: {\n agentId?: string;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<MemoryStatusResponse, TData>;\n} = {}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['memory', agentId, requestContext],\n queryFn: () => (agentId ? client.getMemoryStatus(agentId, requestContext) : null),\n staleTime: 5 * 60 * 1000, // 5 minutes\n gcTime: 10 * 60 * 1000, // 10 minutes\n retry: false,\n ...queryOptions,\n });\n};\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useMemoryConfig = <TData = MemoryConfigResponse>({\n agentId,\n requestContext,\n queryOptions,\n}: {\n agentId?: string;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<MemoryConfigResponse, TData>;\n} = {}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['memory', 'config', agentId, requestContext],\n queryFn: () => (agentId ? client.getMemoryConfig({ agentId, requestContext }) : null),\n staleTime: 5 * 60 * 1000, // 5 minutes\n gcTime: 10 * 60 * 1000, // 10 minutes\n retry: false,\n refetchOnWindowFocus: false,\n ...queryOptions,\n });\n};\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useThread = <TData = ThreadResponse>({\n threadId,\n agentId,\n requestContext,\n queryOptions,\n}: {\n threadId?: string;\n agentId?: string;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<ThreadResponse, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['memory', 'thread', threadId, agentId, requestContext],\n queryFn: () => client.getMemoryThread({ threadId: threadId!, agentId }).get({ requestContext }),\n staleTime: 5 * 60 * 1000,\n gcTime: 10 * 60 * 1000,\n retry: false,\n refetchOnWindowFocus: false,\n ...queryOptions,\n });\n};\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useThreads = <TData = ThreadsResponse>({\n resourceId,\n agentId,\n isMemoryEnabled,\n requestContext,\n queryOptions,\n}: {\n resourceId: string;\n agentId: string;\n isMemoryEnabled: boolean;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<ThreadsResponse, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['memory', 'threads', resourceId, agentId, requestContext],\n queryFn: async () => {\n if (!isMemoryEnabled) return null;\n const result = await client.listMemoryThreads({ resourceId, agentId, requestContext });\n return result.threads;\n },\n staleTime: 0,\n gcTime: 0,\n retry: false,\n refetchOnWindowFocus: false,\n ...queryOptions,\n });\n};\n\nexport type DeleteThreadResponse = Awaited<ReturnType<ReturnType<MastraClient['getMemoryThread']>['delete']>>;\n\nexport const useDeleteThread = ({\n requestContext,\n queryOptions,\n}: {\n requestContext?: Record<string, any>;\n queryOptions?: MastraMutationOptions<DeleteThreadResponse, ThreadVariables>;\n} = {}): UseMutationResult<DeleteThreadResponse, Error, ThreadVariables> => {\n const client = useMastraClient();\n const queryClient = useQueryClient();\n\n return useMutation({\n mutationFn: ({ threadId, agentId }: { threadId: string; agentId: string }) => {\n const thread = client.getMemoryThread({ threadId, agentId });\n return thread.delete({ requestContext });\n },\n onSuccess: (_, variables) => {\n const { agentId } = variables;\n if (agentId) {\n void queryClient.invalidateQueries({ queryKey: ['memory', 'threads', agentId, agentId] });\n }\n },\n ...queryOptions,\n });\n};\n\nexport const useUpdateThread = ({\n requestContext,\n queryOptions,\n}: {\n requestContext?: Record<string, any>;\n queryOptions?: MastraMutationOptions<UpdateThreadResponse, ThreadVariables & { title: string }>;\n} = {}) => {\n const client = useMastraClient();\n const queryClient = useQueryClient();\n\n return useMutation({\n mutationFn: ({ threadId, agentId, title }: { threadId: string; agentId: string; title: string }) =>\n client.getMemoryThread({ threadId, agentId }).update({ title, agentId, requestContext }),\n onSuccess: () => {\n void queryClient.invalidateQueries({ queryKey: ['memory', 'threads'] });\n void queryClient.invalidateQueries({ queryKey: ['memory', 'thread'] });\n },\n ...queryOptions,\n });\n};\n\nexport const useMemorySearch = ({\n agentId,\n resourceId,\n threadId,\n requestContext,\n queryOptions,\n}: {\n agentId: string;\n resourceId: string;\n threadId?: string;\n requestContext?: Record<string, any>;\n queryOptions?: MastraMutationOptions<\n SearchMemoryResponse,\n { searchQuery: string; memoryConfig?: MemorySearchParams }\n >;\n}) => {\n const client = useMastraClient();\n return useMutation({\n mutationFn: async ({ searchQuery, memoryConfig }: { searchQuery: string; memoryConfig?: MemorySearchParams }) => {\n return client.searchMemory({ agentId, resourceId, threadId, searchQuery, memoryConfig, requestContext });\n },\n ...queryOptions,\n });\n};\n\nexport const useCloneThread = ({\n requestContext,\n queryOptions,\n}: {\n requestContext?: Record<string, any>;\n queryOptions?: MastraMutationOptions<CloneThreadResponse, ThreadVariables & { title?: string }>;\n} = {}) => {\n const client = useMastraClient();\n const queryClient = useQueryClient();\n\n return useMutation({\n mutationFn: async ({ threadId, agentId, title }: { threadId: string; agentId: string; title?: string }) => {\n const thread = client.getMemoryThread({ threadId, agentId });\n return thread.clone({ title, requestContext });\n },\n onSuccess: (_, variables) => {\n const { agentId } = variables;\n if (agentId) {\n void queryClient.invalidateQueries({ queryKey: ['memory', 'threads', agentId, agentId] });\n }\n },\n ...queryOptions,\n });\n};\n\n/**\n * Hook to fetch Observational Memory data for an agent\n * Returns the current OM record and history for a given resource/thread\n * Polls more frequently when observing/reflecting is in progress\n *\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useObservationalMemoryWithHistory = <TData = GetObservationalMemoryResponse | null>({\n agentId,\n resourceId,\n threadId,\n isActive = false,\n requestContext,\n queryOptions,\n}: {\n agentId: string;\n resourceId?: string;\n threadId?: string;\n isActive?: boolean;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<GetObservationalMemoryResponse | null, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['observational-memory', agentId, resourceId, threadId, requestContext],\n queryFn: async (): Promise<GetObservationalMemoryResponse | null> => {\n if (!resourceId && !threadId) return null;\n return client.getObservationalMemory({\n agentId,\n resourceId,\n threadId,\n requestContext,\n });\n },\n staleTime: isActive ? 1000 : 30 * 1000, // 1 second when active, 30 seconds otherwise\n gcTime: 5 * 60 * 1000, // 5 minutes\n retry: false,\n refetchOnWindowFocus: false,\n refetchInterval: isActive ? 2000 : false, // Poll every 2 seconds when active\n placeholderData: previousData => previousData, // Keep previous data during refetch to prevent skeleton flash\n ...queryOptions,\n });\n};\n\n/**\n * Hook to get OM-aware memory status\n * Extends useMemory with OM-specific status information\n * Polls more frequently when observing/reflecting is in progress\n *\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useMemoryWithOMStatus = ({\n agentId,\n resourceId,\n threadId,\n pollWhenActive = true,\n requestContext,\n queryOptions,\n}: {\n agentId?: string;\n resourceId?: string;\n threadId?: string;\n pollWhenActive?: boolean;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<GetMemoryStatusResponse | null>;\n}) => {\n const client = useMastraClient();\n const [isActive, setIsActive] = useState(false);\n\n const query = useQuery<GetMemoryStatusResponse | null>({\n queryKey: ['memory-status', agentId, resourceId, threadId, requestContext],\n queryFn: () =>\n agentId\n ? client.getMemoryStatus(agentId, requestContext, {\n resourceId,\n threadId,\n })\n : null,\n staleTime: isActive && pollWhenActive ? 1000 : 30 * 1000, // 1 second when active, 30 seconds otherwise\n gcTime: 5 * 60 * 1000, // 5 minutes\n retry: false,\n refetchOnWindowFocus: false,\n refetchInterval: isActive && pollWhenActive ? 2000 : false, // Poll every 2 seconds when active\n placeholderData: previousData => previousData, // Keep previous data during refetch to prevent skeleton flash\n ...queryOptions,\n });\n\n // Update isActive state when data changes\n const isObserving = query.data?.observationalMemory?.isObserving;\n const isReflecting = query.data?.observationalMemory?.isReflecting;\n\n useEffect(() => {\n const newIsActive = isObserving || isReflecting || false;\n setIsActive(newIsActive);\n }, [isObserving, isReflecting]);\n\n return query;\n};\n"],"mappings":";;;;;AAMA,MAAa,gCAAgC,UAA8B,SACzE;CAAC;CAAU;CAAU;CAAU;CAAY,QAAQ;AAAC;AAItD,SAAgB,wBAA8D,EAC5E,UACA,OAAO,GACP,UAAU,KACV,gBAM+B;CAC/B,MAAM,SAASA,8BAAAA,gBAAgB;CAE/B,QAAA,GAAOC,sBAAAA,SAAAA,CAAS;EACd,UAAU,6BAA6B,UAAU,IAAI;EACrD,SAAS,iBAAiB,OAAO,gBAAgB,EAAE,SAAS,CAAC,CAAC,CAAC,aAAa;GAAE;GAAM;EAAQ,CAAC,IAAIC,sBAAAA;EACjG,GAAG;CACL,CAAC;AACH;;;ACvBA,MA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["useMastraClient","useQuery","skipToken","useMastraClient","useQuery","skipToken","useMastraClient","useQuery","skipToken","useMastraClient","useQuery","useQueryClient","useMutation","useState"],"sources":["../../../src/hooks/memory/use-memory-thread-messages.ts","../../../src/hooks/memory/use-observational-memory.ts","../../../src/hooks/memory/use-memory-status.ts","../../../src/hooks/memory/use-memory.ts"],"sourcesContent":["import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { skipToken, useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nexport const memoryThreadMessagesQueryKey = (threadId: string | undefined, page?: number) =>\n ['memory', 'thread', threadId, 'messages', page ?? 0] as const;\n\ntype MemoryThreadMessagesResponse = Awaited<ReturnType<ReturnType<MastraClient['getMemoryThread']>['listMessages']>>;\n\nexport function useMemoryThreadMessages<TData = MemoryThreadMessagesResponse>({\n threadId,\n page = 0,\n perPage = 100,\n queryOptions,\n}: {\n threadId: string | undefined;\n page?: number;\n perPage?: number;\n queryOptions?: MastraQueryOptions<MemoryThreadMessagesResponse, TData>;\n}): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: memoryThreadMessagesQueryKey(threadId, page),\n queryFn: threadId ? () => client.getMemoryThread({ threadId }).listMessages({ page, perPage }) : skipToken,\n ...queryOptions,\n });\n}\n","import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { skipToken, useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nexport const observationalMemoryQueryKey = (agentId: string | undefined, threadId: string | undefined) =>\n ['memory', 'observational-memory', agentId, threadId] as const;\n\ntype ObservationalMemoryResponse = Awaited<ReturnType<MastraClient['getObservationalMemory']>>;\n\nexport function useObservationalMemory<TData = ObservationalMemoryResponse>({\n agentId,\n threadId,\n resourceId,\n queryOptions,\n}: {\n agentId: string | undefined;\n threadId: string | undefined;\n resourceId?: string;\n queryOptions?: MastraQueryOptions<ObservationalMemoryResponse, TData>;\n}): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: observationalMemoryQueryKey(agentId, threadId),\n queryFn:\n agentId && threadId\n ? () =>\n client.getObservationalMemory({\n agentId,\n threadId,\n resourceId,\n })\n : skipToken,\n // The record is read by several surfaces at once (collapsed memory bar, OM\n // section, detail panel). A short stale window lets a newly mounted consumer\n // reuse the cached record instead of refiring the request; freshness still\n // comes from the explicit refetch on stream finish/observation signals.\n staleTime: 5_000,\n ...queryOptions,\n });\n}\n","import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { skipToken, useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nexport const memoryStatusQueryKey = (agentId: string | undefined, threadId?: string) =>\n ['memory', 'status', agentId, threadId] as const;\n\ntype MemoryStatusResponse = Awaited<ReturnType<MastraClient['getMemoryStatus']>>;\n\nexport function useMemoryStatus<TData = MemoryStatusResponse>({\n agentId,\n threadId,\n queryOptions,\n}: {\n agentId: string | undefined;\n threadId?: string;\n queryOptions?: MastraQueryOptions<MemoryStatusResponse, TData>;\n}): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: memoryStatusQueryKey(agentId, threadId),\n queryFn: agentId\n ? () =>\n client.getMemoryStatus(agentId, undefined, {\n threadId,\n })\n : skipToken,\n ...queryOptions,\n });\n}\n","import type { GetObservationalMemoryResponse, GetMemoryStatusResponse, MastraClient } from '@mastra/client-js';\nimport { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';\nimport type { UseMutationResult, UseQueryResult } from '@tanstack/react-query';\nimport { useState, useEffect } from 'react';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraMutationOptions, MastraQueryOptions } from '../shared/query-options';\n\nexport interface MemorySearchParams {\n lastMessages?: number | false;\n}\n\ntype MemoryStatusResponse = Awaited<ReturnType<MastraClient['getMemoryStatus']>> | null;\ntype MemoryConfigResponse = Awaited<ReturnType<MastraClient['getMemoryConfig']>> | null;\ntype ThreadResponse = Awaited<ReturnType<ReturnType<MastraClient['getMemoryThread']>['get']>>;\ntype ThreadsResponse = Awaited<ReturnType<MastraClient['listMemoryThreads']>>['threads'] | null;\ntype UpdateThreadResponse = Awaited<ReturnType<ReturnType<MastraClient['getMemoryThread']>['update']>>;\ntype CloneThreadResponse = Awaited<ReturnType<ReturnType<MastraClient['getMemoryThread']>['clone']>>;\ntype SearchMemoryResponse = Awaited<ReturnType<MastraClient['searchMemory']>>;\ntype ThreadVariables = { threadId: string; agentId: string };\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useMemory = <TData = MemoryStatusResponse>({\n agentId,\n requestContext,\n queryOptions,\n}: {\n agentId?: string;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<MemoryStatusResponse, TData>;\n} = {}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['memory', agentId, requestContext],\n queryFn: () => (agentId ? client.getMemoryStatus(agentId, requestContext) : null),\n staleTime: 5 * 60 * 1000, // 5 minutes\n gcTime: 10 * 60 * 1000, // 10 minutes\n retry: false,\n ...queryOptions,\n });\n};\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useMemoryConfig = <TData = MemoryConfigResponse>({\n agentId,\n requestContext,\n queryOptions,\n}: {\n agentId?: string;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<MemoryConfigResponse, TData>;\n} = {}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['memory', 'config', agentId, requestContext],\n queryFn: () => (agentId ? client.getMemoryConfig({ agentId, requestContext }) : null),\n staleTime: 5 * 60 * 1000, // 5 minutes\n gcTime: 10 * 60 * 1000, // 10 minutes\n retry: false,\n refetchOnWindowFocus: false,\n ...queryOptions,\n });\n};\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useThread = <TData = ThreadResponse>({\n threadId,\n agentId,\n requestContext,\n queryOptions,\n}: {\n threadId?: string;\n agentId?: string;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<ThreadResponse, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['memory', 'thread', threadId, agentId, requestContext],\n queryFn: () => client.getMemoryThread({ threadId: threadId!, agentId }).get({ requestContext }),\n staleTime: 5 * 60 * 1000,\n gcTime: 10 * 60 * 1000,\n retry: false,\n refetchOnWindowFocus: false,\n ...queryOptions,\n });\n};\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useThreads = <TData = ThreadsResponse>({\n resourceId,\n agentId,\n isMemoryEnabled,\n requestContext,\n queryOptions,\n}: {\n resourceId: string;\n agentId: string;\n isMemoryEnabled: boolean;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<ThreadsResponse, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['memory', 'threads', resourceId, agentId, requestContext],\n queryFn: async () => {\n if (!isMemoryEnabled) return null;\n const result = await client.listMemoryThreads({ resourceId, agentId, requestContext });\n return result.threads;\n },\n staleTime: 0,\n gcTime: 0,\n retry: false,\n refetchOnWindowFocus: false,\n ...queryOptions,\n });\n};\n\nexport type DeleteThreadResponse = Awaited<ReturnType<ReturnType<MastraClient['getMemoryThread']>['delete']>>;\n\nexport const useDeleteThread = ({\n requestContext,\n queryOptions,\n}: {\n requestContext?: Record<string, any>;\n queryOptions?: MastraMutationOptions<DeleteThreadResponse, ThreadVariables>;\n} = {}): UseMutationResult<DeleteThreadResponse, Error, ThreadVariables> => {\n const client = useMastraClient();\n const queryClient = useQueryClient();\n\n return useMutation({\n mutationFn: ({ threadId, agentId }: { threadId: string; agentId: string }) => {\n const thread = client.getMemoryThread({ threadId, agentId });\n return thread.delete({ requestContext });\n },\n onSuccess: (_, variables) => {\n const { agentId } = variables;\n if (agentId) {\n void queryClient.invalidateQueries({ queryKey: ['memory', 'threads', agentId, agentId] });\n }\n },\n ...queryOptions,\n });\n};\n\nexport const useUpdateThread = ({\n requestContext,\n queryOptions,\n}: {\n requestContext?: Record<string, any>;\n queryOptions?: MastraMutationOptions<UpdateThreadResponse, ThreadVariables & { title: string }>;\n} = {}) => {\n const client = useMastraClient();\n const queryClient = useQueryClient();\n\n return useMutation({\n mutationFn: ({ threadId, agentId, title }: { threadId: string; agentId: string; title: string }) =>\n client.getMemoryThread({ threadId, agentId }).update({ title, agentId, requestContext }),\n onSuccess: () => {\n void queryClient.invalidateQueries({ queryKey: ['memory', 'threads'] });\n void queryClient.invalidateQueries({ queryKey: ['memory', 'thread'] });\n },\n ...queryOptions,\n });\n};\n\nexport const useMemorySearch = ({\n agentId,\n resourceId,\n threadId,\n requestContext,\n queryOptions,\n}: {\n agentId: string;\n resourceId: string;\n threadId?: string;\n requestContext?: Record<string, any>;\n queryOptions?: MastraMutationOptions<\n SearchMemoryResponse,\n { searchQuery: string; memoryConfig?: MemorySearchParams }\n >;\n}) => {\n const client = useMastraClient();\n return useMutation({\n mutationFn: async ({ searchQuery, memoryConfig }: { searchQuery: string; memoryConfig?: MemorySearchParams }) => {\n return client.searchMemory({ agentId, resourceId, threadId, searchQuery, memoryConfig, requestContext });\n },\n ...queryOptions,\n });\n};\n\nexport const useCloneThread = ({\n requestContext,\n queryOptions,\n}: {\n requestContext?: Record<string, any>;\n queryOptions?: MastraMutationOptions<CloneThreadResponse, ThreadVariables & { title?: string }>;\n} = {}) => {\n const client = useMastraClient();\n const queryClient = useQueryClient();\n\n return useMutation({\n mutationFn: async ({ threadId, agentId, title }: { threadId: string; agentId: string; title?: string }) => {\n const thread = client.getMemoryThread({ threadId, agentId });\n return thread.clone({ title, requestContext });\n },\n onSuccess: (_, variables) => {\n const { agentId } = variables;\n if (agentId) {\n void queryClient.invalidateQueries({ queryKey: ['memory', 'threads', agentId, agentId] });\n }\n },\n ...queryOptions,\n });\n};\n\n/**\n * Hook to fetch Observational Memory data for an agent\n * Returns the current OM record and history for a given resource/thread\n * Polls more frequently when observing/reflecting is in progress\n *\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useObservationalMemoryWithHistory = <TData = GetObservationalMemoryResponse | null>({\n agentId,\n resourceId,\n threadId,\n isActive = false,\n requestContext,\n queryOptions,\n}: {\n agentId: string;\n resourceId?: string;\n threadId?: string;\n isActive?: boolean;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<GetObservationalMemoryResponse | null, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['observational-memory', agentId, resourceId, threadId, requestContext],\n queryFn: async (): Promise<GetObservationalMemoryResponse | null> => {\n if (!resourceId && !threadId) return null;\n return client.getObservationalMemory({\n agentId,\n resourceId,\n threadId,\n requestContext,\n });\n },\n staleTime: isActive ? 1000 : 30 * 1000, // 1 second when active, 30 seconds otherwise\n gcTime: 5 * 60 * 1000, // 5 minutes\n retry: false,\n refetchOnWindowFocus: false,\n refetchInterval: isActive ? 2000 : false, // Poll every 2 seconds when active\n placeholderData: previousData => previousData, // Keep previous data during refetch to prevent skeleton flash\n ...queryOptions,\n });\n};\n\n/**\n * Hook to get OM-aware memory status\n * Extends useMemory with OM-specific status information\n * Polls more frequently when observing/reflecting is in progress\n *\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useMemoryWithOMStatus = ({\n agentId,\n resourceId,\n threadId,\n pollWhenActive = true,\n requestContext,\n queryOptions,\n}: {\n agentId?: string;\n resourceId?: string;\n threadId?: string;\n pollWhenActive?: boolean;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<GetMemoryStatusResponse | null>;\n}) => {\n const client = useMastraClient();\n const [isActive, setIsActive] = useState(false);\n\n const query = useQuery<GetMemoryStatusResponse | null>({\n queryKey: ['memory-status', agentId, resourceId, threadId, requestContext],\n queryFn: () =>\n agentId\n ? client.getMemoryStatus(agentId, requestContext, {\n resourceId,\n threadId,\n })\n : null,\n staleTime: isActive && pollWhenActive ? 1000 : 30 * 1000, // 1 second when active, 30 seconds otherwise\n gcTime: 5 * 60 * 1000, // 5 minutes\n retry: false,\n refetchOnWindowFocus: false,\n refetchInterval: isActive && pollWhenActive ? 2000 : false, // Poll every 2 seconds when active\n placeholderData: previousData => previousData, // Keep previous data during refetch to prevent skeleton flash\n ...queryOptions,\n });\n\n // Update isActive state when data changes\n const isObserving = query.data?.observationalMemory?.isObserving;\n const isReflecting = query.data?.observationalMemory?.isReflecting;\n\n useEffect(() => {\n const newIsActive = isObserving || isReflecting || false;\n setIsActive(newIsActive);\n }, [isObserving, isReflecting]);\n\n return query;\n};\n"],"mappings":";;;;;AAMA,MAAa,gCAAgC,UAA8B,SACzE;CAAC;CAAU;CAAU;CAAU;CAAY,QAAQ;AAAC;AAItD,SAAgB,wBAA8D,EAC5E,UACA,OAAO,GACP,UAAU,KACV,gBAM+B;CAC/B,MAAM,SAASA,8BAAAA,gBAAgB;CAE/B,QAAA,GAAOC,sBAAAA,SAAAA,CAAS;EACd,UAAU,6BAA6B,UAAU,IAAI;EACrD,SAAS,iBAAiB,OAAO,gBAAgB,EAAE,SAAS,CAAC,CAAC,CAAC,aAAa;GAAE;GAAM;EAAQ,CAAC,IAAIC,sBAAAA;EACjG,GAAG;CACL,CAAC;AACH;;ACvBA,MAAa,+BAA+B,SAA6B,aACvE;CAAC;CAAU;CAAwB;CAAS;AAAQ;AAItD,SAAgB,uBAA4D,EAC1E,SACA,UACA,YACA,gBAM+B;CAC/B,MAAM,SAASC,8BAAAA,gBAAgB;CAE/B,QAAA,GAAOC,sBAAAA,SAAAA,CAAS;EACd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d,UAAU;GAAC;GAAwB;GAAS;GAAY;GAAU;EAAc;EAChF,SAAS,YAA4D;GACnE,IAAI,CAAC,cAAc,CAAC,UAAU,OAAO;GACrC,OAAO,OAAO,uBAAuB;IACnC;IACA;IACA;IACA;GACF,CAAC;EACH;EACA,WAAW,WAAW,MAAO;EAC7B,QAAQ;EACR,OAAO;EACP,sBAAsB;EACtB,iBAAiB,WAAW,MAAO;EACnC,kBAAiB,iBAAgB;EACjC,GAAG;CACL,CAAC;AACH;;;;;;;;AASA,MAAa,yBAAyB,EACpC,SACA,YACA,UACA,iBAAiB,MACjB,gBACA,mBAQI;CACJ,MAAM,SAASD,8BAAAA,gBAAgB;CAC/B,MAAM,CAAC,UAAU,gBAAA,GAAeI,MAAAA,SAAAA,CAAS,KAAK;CAE9C,MAAM,SAAA,GAAQH,sBAAAA,SAAAA,CAAyC;EACrD,UAAU;GAAC;GAAiB;GAAS;GAAY;GAAU;EAAc;EACzE,eACE,UACI,OAAO,gBAAgB,SAAS,gBAAgB;GAC9C;GACA;EACF,CAAC,IACD;EACN,WAAW,YAAY,iBAAiB,MAAO;EAC/C,QAAQ;EACR,OAAO;EACP,sBAAsB;EACtB,iBAAiB,YAAY,iBAAiB,MAAO;EACrD,kBAAiB,iBAAgB;EACjC,GAAG;CACL,CAAC;CAGD,MAAM,cAAc,MAAM,MAAM,qBAAqB;CACrD,MAAM,eAAe,MAAM,MAAM,qBAAqB;CAEtD,CAAA,GAAA,MAAA,UAAA,OAAgB;EAEd,YADoB,eAAe,gBAAgB,KAC5B;CACzB,GAAG,CAAC,aAAa,YAAY,CAAC;CAE9B,OAAO;AACT"}
@@ -1,7 +1,7 @@
1
- import { n as useMastraClient } from "../../mastra-client-context-Bx_g84YB.js";
1
+ import { n as useMastraClient } from "../../mastra-client-context-DQ5z_ze9.js";
2
2
  import { useEffect, useState } from "react";
3
3
  import { skipToken, useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
4
- //#region src/hooks/memory/use-memory-thread-messages.ts
4
+ // src/hooks/memory/use-memory-thread-messages.ts
5
5
  const memoryThreadMessagesQueryKey = (threadId, page) => [
6
6
  "memory",
7
7
  "thread",
@@ -20,8 +20,7 @@ function useMemoryThreadMessages({ threadId, page = 0, perPage = 100, queryOptio
20
20
  ...queryOptions
21
21
  });
22
22
  }
23
- //#endregion
24
- //#region src/hooks/memory/use-observational-memory.ts
23
+ // src/hooks/memory/use-observational-memory.ts
25
24
  const observationalMemoryQueryKey = (agentId, threadId) => [
26
25
  "memory",
27
26
  "observational-memory",
@@ -41,8 +40,7 @@ function useObservationalMemory({ agentId, threadId, resourceId, queryOptions })
41
40
  ...queryOptions
42
41
  });
43
42
  }
44
- //#endregion
45
- //#region src/hooks/memory/use-memory-status.ts
43
+ // src/hooks/memory/use-memory-status.ts
46
44
  const memoryStatusQueryKey = (agentId, threadId) => [
47
45
  "memory",
48
46
  "status",
@@ -57,8 +55,7 @@ function useMemoryStatus({ agentId, threadId, queryOptions }) {
57
55
  ...queryOptions
58
56
  });
59
57
  }
60
- //#endregion
61
- //#region src/hooks/memory/use-memory.ts
58
+ // src/hooks/memory/use-memory.ts
62
59
  /**
63
60
  * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.
64
61
  */
@@ -306,7 +303,6 @@ const useMemoryWithOMStatus = ({ agentId, resourceId, threadId, pollWhenActive =
306
303
  }, [isObserving, isReflecting]);
307
304
  return query;
308
305
  };
309
- //#endregion
310
306
  export { memoryStatusQueryKey, memoryThreadMessagesQueryKey, observationalMemoryQueryKey, useCloneThread, useDeleteThread, useMemory, useMemoryConfig, useMemorySearch, useMemoryStatus, useMemoryThreadMessages, useMemoryWithOMStatus, useObservationalMemory, useObservationalMemoryWithHistory, useThread, useThreads, useUpdateThread };
311
307
 
312
308
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../src/hooks/memory/use-memory-thread-messages.ts","../../../src/hooks/memory/use-observational-memory.ts","../../../src/hooks/memory/use-memory-status.ts","../../../src/hooks/memory/use-memory.ts"],"sourcesContent":["import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { skipToken, useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nexport const memoryThreadMessagesQueryKey = (threadId: string | undefined, page?: number) =>\n ['memory', 'thread', threadId, 'messages', page ?? 0] as const;\n\ntype MemoryThreadMessagesResponse = Awaited<ReturnType<ReturnType<MastraClient['getMemoryThread']>['listMessages']>>;\n\nexport function useMemoryThreadMessages<TData = MemoryThreadMessagesResponse>({\n threadId,\n page = 0,\n perPage = 100,\n queryOptions,\n}: {\n threadId: string | undefined;\n page?: number;\n perPage?: number;\n queryOptions?: MastraQueryOptions<MemoryThreadMessagesResponse, TData>;\n}): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: memoryThreadMessagesQueryKey(threadId, page),\n queryFn: threadId ? () => client.getMemoryThread({ threadId }).listMessages({ page, perPage }) : skipToken,\n ...queryOptions,\n });\n}\n","import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { skipToken, useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nexport const observationalMemoryQueryKey = (agentId: string | undefined, threadId: string | undefined) =>\n ['memory', 'observational-memory', agentId, threadId] as const;\n\ntype ObservationalMemoryResponse = Awaited<ReturnType<MastraClient['getObservationalMemory']>>;\n\nexport function useObservationalMemory<TData = ObservationalMemoryResponse>({\n agentId,\n threadId,\n resourceId,\n queryOptions,\n}: {\n agentId: string | undefined;\n threadId: string | undefined;\n resourceId?: string;\n queryOptions?: MastraQueryOptions<ObservationalMemoryResponse, TData>;\n}): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: observationalMemoryQueryKey(agentId, threadId),\n queryFn:\n agentId && threadId\n ? () =>\n client.getObservationalMemory({\n agentId,\n threadId,\n resourceId,\n })\n : skipToken,\n // The record is read by several surfaces at once (collapsed memory bar, OM\n // section, detail panel). A short stale window lets a newly mounted consumer\n // reuse the cached record instead of refiring the request; freshness still\n // comes from the explicit refetch on stream finish/observation signals.\n staleTime: 5_000,\n ...queryOptions,\n });\n}\n","import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { skipToken, useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nexport const memoryStatusQueryKey = (agentId: string | undefined, threadId?: string) =>\n ['memory', 'status', agentId, threadId] as const;\n\ntype MemoryStatusResponse = Awaited<ReturnType<MastraClient['getMemoryStatus']>>;\n\nexport function useMemoryStatus<TData = MemoryStatusResponse>({\n agentId,\n threadId,\n queryOptions,\n}: {\n agentId: string | undefined;\n threadId?: string;\n queryOptions?: MastraQueryOptions<MemoryStatusResponse, TData>;\n}): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: memoryStatusQueryKey(agentId, threadId),\n queryFn: agentId\n ? () =>\n client.getMemoryStatus(agentId, undefined, {\n threadId,\n })\n : skipToken,\n ...queryOptions,\n });\n}\n","import type { GetObservationalMemoryResponse, GetMemoryStatusResponse, MastraClient } from '@mastra/client-js';\nimport { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';\nimport type { UseMutationResult, UseQueryResult } from '@tanstack/react-query';\nimport { useState, useEffect } from 'react';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraMutationOptions, MastraQueryOptions } from '../shared/query-options';\n\nexport interface MemorySearchParams {\n lastMessages?: number | false;\n}\n\ntype MemoryStatusResponse = Awaited<ReturnType<MastraClient['getMemoryStatus']>> | null;\ntype MemoryConfigResponse = Awaited<ReturnType<MastraClient['getMemoryConfig']>> | null;\ntype ThreadResponse = Awaited<ReturnType<ReturnType<MastraClient['getMemoryThread']>['get']>>;\ntype ThreadsResponse = Awaited<ReturnType<MastraClient['listMemoryThreads']>>['threads'] | null;\ntype UpdateThreadResponse = Awaited<ReturnType<ReturnType<MastraClient['getMemoryThread']>['update']>>;\ntype CloneThreadResponse = Awaited<ReturnType<ReturnType<MastraClient['getMemoryThread']>['clone']>>;\ntype SearchMemoryResponse = Awaited<ReturnType<MastraClient['searchMemory']>>;\ntype ThreadVariables = { threadId: string; agentId: string };\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useMemory = <TData = MemoryStatusResponse>({\n agentId,\n requestContext,\n queryOptions,\n}: {\n agentId?: string;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<MemoryStatusResponse, TData>;\n} = {}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['memory', agentId, requestContext],\n queryFn: () => (agentId ? client.getMemoryStatus(agentId, requestContext) : null),\n staleTime: 5 * 60 * 1000, // 5 minutes\n gcTime: 10 * 60 * 1000, // 10 minutes\n retry: false,\n ...queryOptions,\n });\n};\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useMemoryConfig = <TData = MemoryConfigResponse>({\n agentId,\n requestContext,\n queryOptions,\n}: {\n agentId?: string;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<MemoryConfigResponse, TData>;\n} = {}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['memory', 'config', agentId, requestContext],\n queryFn: () => (agentId ? client.getMemoryConfig({ agentId, requestContext }) : null),\n staleTime: 5 * 60 * 1000, // 5 minutes\n gcTime: 10 * 60 * 1000, // 10 minutes\n retry: false,\n refetchOnWindowFocus: false,\n ...queryOptions,\n });\n};\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useThread = <TData = ThreadResponse>({\n threadId,\n agentId,\n requestContext,\n queryOptions,\n}: {\n threadId?: string;\n agentId?: string;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<ThreadResponse, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['memory', 'thread', threadId, agentId, requestContext],\n queryFn: () => client.getMemoryThread({ threadId: threadId!, agentId }).get({ requestContext }),\n staleTime: 5 * 60 * 1000,\n gcTime: 10 * 60 * 1000,\n retry: false,\n refetchOnWindowFocus: false,\n ...queryOptions,\n });\n};\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useThreads = <TData = ThreadsResponse>({\n resourceId,\n agentId,\n isMemoryEnabled,\n requestContext,\n queryOptions,\n}: {\n resourceId: string;\n agentId: string;\n isMemoryEnabled: boolean;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<ThreadsResponse, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['memory', 'threads', resourceId, agentId, requestContext],\n queryFn: async () => {\n if (!isMemoryEnabled) return null;\n const result = await client.listMemoryThreads({ resourceId, agentId, requestContext });\n return result.threads;\n },\n staleTime: 0,\n gcTime: 0,\n retry: false,\n refetchOnWindowFocus: false,\n ...queryOptions,\n });\n};\n\nexport type DeleteThreadResponse = Awaited<ReturnType<ReturnType<MastraClient['getMemoryThread']>['delete']>>;\n\nexport const useDeleteThread = ({\n requestContext,\n queryOptions,\n}: {\n requestContext?: Record<string, any>;\n queryOptions?: MastraMutationOptions<DeleteThreadResponse, ThreadVariables>;\n} = {}): UseMutationResult<DeleteThreadResponse, Error, ThreadVariables> => {\n const client = useMastraClient();\n const queryClient = useQueryClient();\n\n return useMutation({\n mutationFn: ({ threadId, agentId }: { threadId: string; agentId: string }) => {\n const thread = client.getMemoryThread({ threadId, agentId });\n return thread.delete({ requestContext });\n },\n onSuccess: (_, variables) => {\n const { agentId } = variables;\n if (agentId) {\n void queryClient.invalidateQueries({ queryKey: ['memory', 'threads', agentId, agentId] });\n }\n },\n ...queryOptions,\n });\n};\n\nexport const useUpdateThread = ({\n requestContext,\n queryOptions,\n}: {\n requestContext?: Record<string, any>;\n queryOptions?: MastraMutationOptions<UpdateThreadResponse, ThreadVariables & { title: string }>;\n} = {}) => {\n const client = useMastraClient();\n const queryClient = useQueryClient();\n\n return useMutation({\n mutationFn: ({ threadId, agentId, title }: { threadId: string; agentId: string; title: string }) =>\n client.getMemoryThread({ threadId, agentId }).update({ title, agentId, requestContext }),\n onSuccess: () => {\n void queryClient.invalidateQueries({ queryKey: ['memory', 'threads'] });\n void queryClient.invalidateQueries({ queryKey: ['memory', 'thread'] });\n },\n ...queryOptions,\n });\n};\n\nexport const useMemorySearch = ({\n agentId,\n resourceId,\n threadId,\n requestContext,\n queryOptions,\n}: {\n agentId: string;\n resourceId: string;\n threadId?: string;\n requestContext?: Record<string, any>;\n queryOptions?: MastraMutationOptions<\n SearchMemoryResponse,\n { searchQuery: string; memoryConfig?: MemorySearchParams }\n >;\n}) => {\n const client = useMastraClient();\n return useMutation({\n mutationFn: async ({ searchQuery, memoryConfig }: { searchQuery: string; memoryConfig?: MemorySearchParams }) => {\n return client.searchMemory({ agentId, resourceId, threadId, searchQuery, memoryConfig, requestContext });\n },\n ...queryOptions,\n });\n};\n\nexport const useCloneThread = ({\n requestContext,\n queryOptions,\n}: {\n requestContext?: Record<string, any>;\n queryOptions?: MastraMutationOptions<CloneThreadResponse, ThreadVariables & { title?: string }>;\n} = {}) => {\n const client = useMastraClient();\n const queryClient = useQueryClient();\n\n return useMutation({\n mutationFn: async ({ threadId, agentId, title }: { threadId: string; agentId: string; title?: string }) => {\n const thread = client.getMemoryThread({ threadId, agentId });\n return thread.clone({ title, requestContext });\n },\n onSuccess: (_, variables) => {\n const { agentId } = variables;\n if (agentId) {\n void queryClient.invalidateQueries({ queryKey: ['memory', 'threads', agentId, agentId] });\n }\n },\n ...queryOptions,\n });\n};\n\n/**\n * Hook to fetch Observational Memory data for an agent\n * Returns the current OM record and history for a given resource/thread\n * Polls more frequently when observing/reflecting is in progress\n *\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useObservationalMemoryWithHistory = <TData = GetObservationalMemoryResponse | null>({\n agentId,\n resourceId,\n threadId,\n isActive = false,\n requestContext,\n queryOptions,\n}: {\n agentId: string;\n resourceId?: string;\n threadId?: string;\n isActive?: boolean;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<GetObservationalMemoryResponse | null, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['observational-memory', agentId, resourceId, threadId, requestContext],\n queryFn: async (): Promise<GetObservationalMemoryResponse | null> => {\n if (!resourceId && !threadId) return null;\n return client.getObservationalMemory({\n agentId,\n resourceId,\n threadId,\n requestContext,\n });\n },\n staleTime: isActive ? 1000 : 30 * 1000, // 1 second when active, 30 seconds otherwise\n gcTime: 5 * 60 * 1000, // 5 minutes\n retry: false,\n refetchOnWindowFocus: false,\n refetchInterval: isActive ? 2000 : false, // Poll every 2 seconds when active\n placeholderData: previousData => previousData, // Keep previous data during refetch to prevent skeleton flash\n ...queryOptions,\n });\n};\n\n/**\n * Hook to get OM-aware memory status\n * Extends useMemory with OM-specific status information\n * Polls more frequently when observing/reflecting is in progress\n *\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useMemoryWithOMStatus = ({\n agentId,\n resourceId,\n threadId,\n pollWhenActive = true,\n requestContext,\n queryOptions,\n}: {\n agentId?: string;\n resourceId?: string;\n threadId?: string;\n pollWhenActive?: boolean;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<GetMemoryStatusResponse | null>;\n}) => {\n const client = useMastraClient();\n const [isActive, setIsActive] = useState(false);\n\n const query = useQuery<GetMemoryStatusResponse | null>({\n queryKey: ['memory-status', agentId, resourceId, threadId, requestContext],\n queryFn: () =>\n agentId\n ? client.getMemoryStatus(agentId, requestContext, {\n resourceId,\n threadId,\n })\n : null,\n staleTime: isActive && pollWhenActive ? 1000 : 30 * 1000, // 1 second when active, 30 seconds otherwise\n gcTime: 5 * 60 * 1000, // 5 minutes\n retry: false,\n refetchOnWindowFocus: false,\n refetchInterval: isActive && pollWhenActive ? 2000 : false, // Poll every 2 seconds when active\n placeholderData: previousData => previousData, // Keep previous data during refetch to prevent skeleton flash\n ...queryOptions,\n });\n\n // Update isActive state when data changes\n const isObserving = query.data?.observationalMemory?.isObserving;\n const isReflecting = query.data?.observationalMemory?.isReflecting;\n\n useEffect(() => {\n const newIsActive = isObserving || isReflecting || false;\n setIsActive(newIsActive);\n }, [isObserving, isReflecting]);\n\n return query;\n};\n"],"mappings":";;;;AAMA,MAAa,gCAAgC,UAA8B,SACzE;CAAC;CAAU;CAAU;CAAU;CAAY,QAAQ;AAAC;AAItD,SAAgB,wBAA8D,EAC5E,UACA,OAAO,GACP,UAAU,KACV,gBAM+B;CAC/B,MAAM,SAAS,gBAAgB;CAE/B,OAAO,SAAS;EACd,UAAU,6BAA6B,UAAU,IAAI;EACrD,SAAS,iBAAiB,OAAO,gBAAgB,EAAE,SAAS,CAAC,CAAC,CAAC,aAAa;GAAE;GAAM;EAAQ,CAAC,IAAI;EACjG,GAAG;CACL,CAAC;AACH;;;ACvBA,MAAa,+BAA+B,SAA6B,aACvE;CAAC;CAAU;CAAwB;CAAS;AAAQ;AAItD,SAAgB,uBAA4D,EAC1E,SACA,UACA,YACA,gBAM+B;CAC/B,MAAM,SAAS,gBAAgB;CAE/B,OAAO,SAAS;EACd,UAAU,4BAA4B,SAAS,QAAQ;EACvD,SACE,WAAW,iBAEL,OAAO,uBAAuB;GAC5B;GACA;GACA;EACF,CAAC,IACH;EAKN,WAAW;EACX,GAAG;CACL,CAAC;AACH;;;ACpCA,MAAa,wBAAwB,SAA6B,aAChE;CAAC;CAAU;CAAU;CAAS;AAAQ;AAIxC,SAAgB,gBAA8C,EAC5D,SACA,UACA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AQ;EACR,OAAO;EACP,sBAAsB;EACtB,iBAAiB,YAAY,iBAAiB,MAAO;EACrD,kBAAiB,iBAAgB;EACjC,GAAG;CACL,CAAC;CAGD,MAAM,cAAc,MAAM,MAAM,qBAAqB;CACrD,MAAM,eAAe,MAAM,MAAM,qBAAqB;CAEtD,gBAAgB;EAEd,YADoB,eAAe,gBAAgB,KAC5B;CACzB,GAAG,CAAC,aAAa,YAAY,CAAC;CAE9B,OAAO;AACT"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../src/hooks/memory/use-memory-thread-messages.ts","../../../src/hooks/memory/use-observational-memory.ts","../../../src/hooks/memory/use-memory-status.ts","../../../src/hooks/memory/use-memory.ts"],"sourcesContent":["import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { skipToken, useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nexport const memoryThreadMessagesQueryKey = (threadId: string | undefined, page?: number) =>\n ['memory', 'thread', threadId, 'messages', page ?? 0] as const;\n\ntype MemoryThreadMessagesResponse = Awaited<ReturnType<ReturnType<MastraClient['getMemoryThread']>['listMessages']>>;\n\nexport function useMemoryThreadMessages<TData = MemoryThreadMessagesResponse>({\n threadId,\n page = 0,\n perPage = 100,\n queryOptions,\n}: {\n threadId: string | undefined;\n page?: number;\n perPage?: number;\n queryOptions?: MastraQueryOptions<MemoryThreadMessagesResponse, TData>;\n}): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: memoryThreadMessagesQueryKey(threadId, page),\n queryFn: threadId ? () => client.getMemoryThread({ threadId }).listMessages({ page, perPage }) : skipToken,\n ...queryOptions,\n });\n}\n","import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { skipToken, useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nexport const observationalMemoryQueryKey = (agentId: string | undefined, threadId: string | undefined) =>\n ['memory', 'observational-memory', agentId, threadId] as const;\n\ntype ObservationalMemoryResponse = Awaited<ReturnType<MastraClient['getObservationalMemory']>>;\n\nexport function useObservationalMemory<TData = ObservationalMemoryResponse>({\n agentId,\n threadId,\n resourceId,\n queryOptions,\n}: {\n agentId: string | undefined;\n threadId: string | undefined;\n resourceId?: string;\n queryOptions?: MastraQueryOptions<ObservationalMemoryResponse, TData>;\n}): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: observationalMemoryQueryKey(agentId, threadId),\n queryFn:\n agentId && threadId\n ? () =>\n client.getObservationalMemory({\n agentId,\n threadId,\n resourceId,\n })\n : skipToken,\n // The record is read by several surfaces at once (collapsed memory bar, OM\n // section, detail panel). A short stale window lets a newly mounted consumer\n // reuse the cached record instead of refiring the request; freshness still\n // comes from the explicit refetch on stream finish/observation signals.\n staleTime: 5_000,\n ...queryOptions,\n });\n}\n","import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { skipToken, useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nexport const memoryStatusQueryKey = (agentId: string | undefined, threadId?: string) =>\n ['memory', 'status', agentId, threadId] as const;\n\ntype MemoryStatusResponse = Awaited<ReturnType<MastraClient['getMemoryStatus']>>;\n\nexport function useMemoryStatus<TData = MemoryStatusResponse>({\n agentId,\n threadId,\n queryOptions,\n}: {\n agentId: string | undefined;\n threadId?: string;\n queryOptions?: MastraQueryOptions<MemoryStatusResponse, TData>;\n}): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: memoryStatusQueryKey(agentId, threadId),\n queryFn: agentId\n ? () =>\n client.getMemoryStatus(agentId, undefined, {\n threadId,\n })\n : skipToken,\n ...queryOptions,\n });\n}\n","import type { GetObservationalMemoryResponse, GetMemoryStatusResponse, MastraClient } from '@mastra/client-js';\nimport { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';\nimport type { UseMutationResult, UseQueryResult } from '@tanstack/react-query';\nimport { useState, useEffect } from 'react';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraMutationOptions, MastraQueryOptions } from '../shared/query-options';\n\nexport interface MemorySearchParams {\n lastMessages?: number | false;\n}\n\ntype MemoryStatusResponse = Awaited<ReturnType<MastraClient['getMemoryStatus']>> | null;\ntype MemoryConfigResponse = Awaited<ReturnType<MastraClient['getMemoryConfig']>> | null;\ntype ThreadResponse = Awaited<ReturnType<ReturnType<MastraClient['getMemoryThread']>['get']>>;\ntype ThreadsResponse = Awaited<ReturnType<MastraClient['listMemoryThreads']>>['threads'] | null;\ntype UpdateThreadResponse = Awaited<ReturnType<ReturnType<MastraClient['getMemoryThread']>['update']>>;\ntype CloneThreadResponse = Awaited<ReturnType<ReturnType<MastraClient['getMemoryThread']>['clone']>>;\ntype SearchMemoryResponse = Awaited<ReturnType<MastraClient['searchMemory']>>;\ntype ThreadVariables = { threadId: string; agentId: string };\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useMemory = <TData = MemoryStatusResponse>({\n agentId,\n requestContext,\n queryOptions,\n}: {\n agentId?: string;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<MemoryStatusResponse, TData>;\n} = {}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['memory', agentId, requestContext],\n queryFn: () => (agentId ? client.getMemoryStatus(agentId, requestContext) : null),\n staleTime: 5 * 60 * 1000, // 5 minutes\n gcTime: 10 * 60 * 1000, // 10 minutes\n retry: false,\n ...queryOptions,\n });\n};\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useMemoryConfig = <TData = MemoryConfigResponse>({\n agentId,\n requestContext,\n queryOptions,\n}: {\n agentId?: string;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<MemoryConfigResponse, TData>;\n} = {}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['memory', 'config', agentId, requestContext],\n queryFn: () => (agentId ? client.getMemoryConfig({ agentId, requestContext }) : null),\n staleTime: 5 * 60 * 1000, // 5 minutes\n gcTime: 10 * 60 * 1000, // 10 minutes\n retry: false,\n refetchOnWindowFocus: false,\n ...queryOptions,\n });\n};\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useThread = <TData = ThreadResponse>({\n threadId,\n agentId,\n requestContext,\n queryOptions,\n}: {\n threadId?: string;\n agentId?: string;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<ThreadResponse, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['memory', 'thread', threadId, agentId, requestContext],\n queryFn: () => client.getMemoryThread({ threadId: threadId!, agentId }).get({ requestContext }),\n staleTime: 5 * 60 * 1000,\n gcTime: 10 * 60 * 1000,\n retry: false,\n refetchOnWindowFocus: false,\n ...queryOptions,\n });\n};\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useThreads = <TData = ThreadsResponse>({\n resourceId,\n agentId,\n isMemoryEnabled,\n requestContext,\n queryOptions,\n}: {\n resourceId: string;\n agentId: string;\n isMemoryEnabled: boolean;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<ThreadsResponse, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['memory', 'threads', resourceId, agentId, requestContext],\n queryFn: async () => {\n if (!isMemoryEnabled) return null;\n const result = await client.listMemoryThreads({ resourceId, agentId, requestContext });\n return result.threads;\n },\n staleTime: 0,\n gcTime: 0,\n retry: false,\n refetchOnWindowFocus: false,\n ...queryOptions,\n });\n};\n\nexport type DeleteThreadResponse = Awaited<ReturnType<ReturnType<MastraClient['getMemoryThread']>['delete']>>;\n\nexport const useDeleteThread = ({\n requestContext,\n queryOptions,\n}: {\n requestContext?: Record<string, any>;\n queryOptions?: MastraMutationOptions<DeleteThreadResponse, ThreadVariables>;\n} = {}): UseMutationResult<DeleteThreadResponse, Error, ThreadVariables> => {\n const client = useMastraClient();\n const queryClient = useQueryClient();\n\n return useMutation({\n mutationFn: ({ threadId, agentId }: { threadId: string; agentId: string }) => {\n const thread = client.getMemoryThread({ threadId, agentId });\n return thread.delete({ requestContext });\n },\n onSuccess: (_, variables) => {\n const { agentId } = variables;\n if (agentId) {\n void queryClient.invalidateQueries({ queryKey: ['memory', 'threads', agentId, agentId] });\n }\n },\n ...queryOptions,\n });\n};\n\nexport const useUpdateThread = ({\n requestContext,\n queryOptions,\n}: {\n requestContext?: Record<string, any>;\n queryOptions?: MastraMutationOptions<UpdateThreadResponse, ThreadVariables & { title: string }>;\n} = {}) => {\n const client = useMastraClient();\n const queryClient = useQueryClient();\n\n return useMutation({\n mutationFn: ({ threadId, agentId, title }: { threadId: string; agentId: string; title: string }) =>\n client.getMemoryThread({ threadId, agentId }).update({ title, agentId, requestContext }),\n onSuccess: () => {\n void queryClient.invalidateQueries({ queryKey: ['memory', 'threads'] });\n void queryClient.invalidateQueries({ queryKey: ['memory', 'thread'] });\n },\n ...queryOptions,\n });\n};\n\nexport const useMemorySearch = ({\n agentId,\n resourceId,\n threadId,\n requestContext,\n queryOptions,\n}: {\n agentId: string;\n resourceId: string;\n threadId?: string;\n requestContext?: Record<string, any>;\n queryOptions?: MastraMutationOptions<\n SearchMemoryResponse,\n { searchQuery: string; memoryConfig?: MemorySearchParams }\n >;\n}) => {\n const client = useMastraClient();\n return useMutation({\n mutationFn: async ({ searchQuery, memoryConfig }: { searchQuery: string; memoryConfig?: MemorySearchParams }) => {\n return client.searchMemory({ agentId, resourceId, threadId, searchQuery, memoryConfig, requestContext });\n },\n ...queryOptions,\n });\n};\n\nexport const useCloneThread = ({\n requestContext,\n queryOptions,\n}: {\n requestContext?: Record<string, any>;\n queryOptions?: MastraMutationOptions<CloneThreadResponse, ThreadVariables & { title?: string }>;\n} = {}) => {\n const client = useMastraClient();\n const queryClient = useQueryClient();\n\n return useMutation({\n mutationFn: async ({ threadId, agentId, title }: { threadId: string; agentId: string; title?: string }) => {\n const thread = client.getMemoryThread({ threadId, agentId });\n return thread.clone({ title, requestContext });\n },\n onSuccess: (_, variables) => {\n const { agentId } = variables;\n if (agentId) {\n void queryClient.invalidateQueries({ queryKey: ['memory', 'threads', agentId, agentId] });\n }\n },\n ...queryOptions,\n });\n};\n\n/**\n * Hook to fetch Observational Memory data for an agent\n * Returns the current OM record and history for a given resource/thread\n * Polls more frequently when observing/reflecting is in progress\n *\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useObservationalMemoryWithHistory = <TData = GetObservationalMemoryResponse | null>({\n agentId,\n resourceId,\n threadId,\n isActive = false,\n requestContext,\n queryOptions,\n}: {\n agentId: string;\n resourceId?: string;\n threadId?: string;\n isActive?: boolean;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<GetObservationalMemoryResponse | null, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['observational-memory', agentId, resourceId, threadId, requestContext],\n queryFn: async (): Promise<GetObservationalMemoryResponse | null> => {\n if (!resourceId && !threadId) return null;\n return client.getObservationalMemory({\n agentId,\n resourceId,\n threadId,\n requestContext,\n });\n },\n staleTime: isActive ? 1000 : 30 * 1000, // 1 second when active, 30 seconds otherwise\n gcTime: 5 * 60 * 1000, // 5 minutes\n retry: false,\n refetchOnWindowFocus: false,\n refetchInterval: isActive ? 2000 : false, // Poll every 2 seconds when active\n placeholderData: previousData => previousData, // Keep previous data during refetch to prevent skeleton flash\n ...queryOptions,\n });\n};\n\n/**\n * Hook to get OM-aware memory status\n * Extends useMemory with OM-specific status information\n * Polls more frequently when observing/reflecting is in progress\n *\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useMemoryWithOMStatus = ({\n agentId,\n resourceId,\n threadId,\n pollWhenActive = true,\n requestContext,\n queryOptions,\n}: {\n agentId?: string;\n resourceId?: string;\n threadId?: string;\n pollWhenActive?: boolean;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<GetMemoryStatusResponse | null>;\n}) => {\n const client = useMastraClient();\n const [isActive, setIsActive] = useState(false);\n\n const query = useQuery<GetMemoryStatusResponse | null>({\n queryKey: ['memory-status', agentId, resourceId, threadId, requestContext],\n queryFn: () =>\n agentId\n ? client.getMemoryStatus(agentId, requestContext, {\n resourceId,\n threadId,\n })\n : null,\n staleTime: isActive && pollWhenActive ? 1000 : 30 * 1000, // 1 second when active, 30 seconds otherwise\n gcTime: 5 * 60 * 1000, // 5 minutes\n retry: false,\n refetchOnWindowFocus: false,\n refetchInterval: isActive && pollWhenActive ? 2000 : false, // Poll every 2 seconds when active\n placeholderData: previousData => previousData, // Keep previous data during refetch to prevent skeleton flash\n ...queryOptions,\n });\n\n // Update isActive state when data changes\n const isObserving = query.data?.observationalMemory?.isObserving;\n const isReflecting = query.data?.observationalMemory?.isReflecting;\n\n useEffect(() => {\n const newIsActive = isObserving || isReflecting || false;\n setIsActive(newIsActive);\n }, [isObserving, isReflecting]);\n\n return query;\n};\n"],"mappings":";;;;AAMA,MAAa,gCAAgC,UAA8B,SACzE;CAAC;CAAU;CAAU;CAAU;CAAY,QAAQ;AAAC;AAItD,SAAgB,wBAA8D,EAC5E,UACA,OAAO,GACP,UAAU,KACV,gBAM+B;CAC/B,MAAM,SAAS,gBAAgB;CAE/B,OAAO,SAAS;EACd,UAAU,6BAA6B,UAAU,IAAI;EACrD,SAAS,iBAAiB,OAAO,gBAAgB,EAAE,SAAS,CAAC,CAAC,CAAC,aAAa;GAAE;GAAM;EAAQ,CAAC,IAAI;EACjG,GAAG;CACL,CAAC;AACH;;ACvBA,MAAa,+BAA+B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