@personaai/react 0.7.8 → 0.7.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -33,6 +33,7 @@ __export(index_exports, {
33
33
  useChat: () => useChat,
34
34
  useConnection: () => useConnection,
35
35
  useFiles: () => useFiles,
36
+ useMcp: () => useMcp,
36
37
  useMcpConnections: () => useMcpConnections,
37
38
  useMemory: () => useMemory,
38
39
  usePersonaContext: () => usePersonaContext,
@@ -908,6 +909,18 @@ function useChat(options = {}) {
908
909
  ];
909
910
  patchAssistant({});
910
911
  }
912
+ } else if (event.name === "mcp_app") {
913
+ const val = event.value;
914
+ if (val?.toolCallId && val?.resourceUri && val?.mcpId) {
915
+ const existing = toolCallsMap.get(val.toolCallId);
916
+ if (existing) {
917
+ existing.mcpApp = {
918
+ resourceUri: val.resourceUri,
919
+ mcpId: val.mcpId
920
+ };
921
+ patchAssistant({});
922
+ }
923
+ }
911
924
  }
912
925
  } else if (event.type === "RUN_ERROR") {
913
926
  chatLogger.warn("run error", {
@@ -2018,9 +2031,50 @@ function useMcpConnections(options = {}) {
2018
2031
  };
2019
2032
  }
2020
2033
 
2034
+ // src/hooks/useMcp.ts
2035
+ var import_react10 = require("react");
2036
+ function useMcp(options = {}) {
2037
+ const { fetchWithAuth } = usePersonaContext();
2038
+ const defaultMcpId = options.mcpId;
2039
+ const readResource = (0, import_react10.useCallback)(
2040
+ async (uri, mcpId) => {
2041
+ const id = mcpId ?? defaultMcpId;
2042
+ if (!id) throw new Error("MCP server ID is required to read resource");
2043
+ const res = await fetchWithAuth(
2044
+ `/mcps/${id}/resource?uri=${encodeURIComponent(uri)}`
2045
+ );
2046
+ if (!res.ok) {
2047
+ throw new Error(`Failed to read MCP resource: ${res.statusText}`);
2048
+ }
2049
+ return await res.json();
2050
+ },
2051
+ [fetchWithAuth, defaultMcpId]
2052
+ );
2053
+ const callTool = (0, import_react10.useCallback)(
2054
+ async (name, args, mcpId) => {
2055
+ const id = mcpId ?? defaultMcpId;
2056
+ if (!id) throw new Error("MCP server ID is required to call tool");
2057
+ const res = await fetchWithAuth(`/mcps/${id}/call-tool`, {
2058
+ method: "POST",
2059
+ headers: { "Content-Type": "application/json" },
2060
+ body: JSON.stringify({ name, arguments: args })
2061
+ });
2062
+ if (!res.ok) {
2063
+ throw new Error(`Failed to call MCP tool: ${res.statusText}`);
2064
+ }
2065
+ return await res.json();
2066
+ },
2067
+ [fetchWithAuth, defaultMcpId]
2068
+ );
2069
+ return {
2070
+ readResource,
2071
+ callTool
2072
+ };
2073
+ }
2074
+
2021
2075
  // src/index.ts
2022
2076
  var import_logger2 = require("@personaai/logger");
2023
- var VERSION = "0.7.3";
2077
+ var VERSION = "0.7.9";
2024
2078
  // Annotate the CommonJS export names for ESM import in node:
2025
2079
  0 && (module.exports = {
2026
2080
  PersonaProvider,
@@ -2036,6 +2090,7 @@ var VERSION = "0.7.3";
2036
2090
  useChat,
2037
2091
  useConnection,
2038
2092
  useFiles,
2093
+ useMcp,
2039
2094
  useMcpConnections,
2040
2095
  useMemory,
2041
2096
  usePersonaContext,