@personaai/react 0.7.6 → 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 +75 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +60 -2
- package/dist/index.d.ts +60 -2
- package/dist/index.js +74 -7
- package/dist/index.js.map +1 -1
- package/package.json +82 -82
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,
|
|
@@ -685,10 +686,14 @@ function useChat(options = {}) {
|
|
|
685
686
|
const resolvedThreadId = await (overrideOptions?.threadId ?? options.threadId);
|
|
686
687
|
chatLogger.trace("resolved threadId", { threadId: resolvedThreadId });
|
|
687
688
|
const token = getAuthToken ? await getAuthToken() : null;
|
|
689
|
+
const resolvedHookContext = typeof options.context === "function" ? options.context() : options.context;
|
|
690
|
+
const mergedContext = { ...resolvedHookContext, ...overrideOptions?.context };
|
|
691
|
+
const hasContext = Object.keys(mergedContext).length > 0;
|
|
688
692
|
chatLogger.debug("opening SSE stream", {
|
|
689
693
|
agentId: targetAgentId,
|
|
690
694
|
hasToken: !!token,
|
|
691
|
-
hasThreadId: !!resolvedThreadId
|
|
695
|
+
hasThreadId: !!resolvedThreadId,
|
|
696
|
+
hasContext
|
|
692
697
|
});
|
|
693
698
|
const stream = await openSSEStream({
|
|
694
699
|
url: `${baseUrl}/chat`,
|
|
@@ -701,7 +706,8 @@ function useChat(options = {}) {
|
|
|
701
706
|
messages: payloadMessages,
|
|
702
707
|
threadId: resolvedThreadId,
|
|
703
708
|
resume: overrideOptions?.resume,
|
|
704
|
-
contextOverride: overrideOptions?.contextOverride
|
|
709
|
+
contextOverride: overrideOptions?.contextOverride,
|
|
710
|
+
...hasContext ? { context: mergedContext } : {}
|
|
705
711
|
}),
|
|
706
712
|
signal: controller.signal
|
|
707
713
|
});
|
|
@@ -903,6 +909,18 @@ function useChat(options = {}) {
|
|
|
903
909
|
];
|
|
904
910
|
patchAssistant({});
|
|
905
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
|
+
}
|
|
906
924
|
}
|
|
907
925
|
} else if (event.type === "RUN_ERROR") {
|
|
908
926
|
chatLogger.warn("run error", {
|
|
@@ -1436,6 +1454,7 @@ function useVoice(options = {}) {
|
|
|
1436
1454
|
const agentId = options.agentId || defaultAgentId;
|
|
1437
1455
|
const threadId = options.threadId;
|
|
1438
1456
|
const contextOverride = options.contextOverride;
|
|
1457
|
+
const context = options.context;
|
|
1439
1458
|
const [state, setState] = (0, import_react5.useState)("idle");
|
|
1440
1459
|
const [isMuted, setIsMuted] = (0, import_react5.useState)(false);
|
|
1441
1460
|
const [transcript, setTranscript] = (0, import_react5.useState)(
|
|
@@ -1708,7 +1727,8 @@ function useVoice(options = {}) {
|
|
|
1708
1727
|
voiceLogger.debug("start() called", {
|
|
1709
1728
|
agentId,
|
|
1710
1729
|
threadId,
|
|
1711
|
-
hasContextOverride: !!contextOverride
|
|
1730
|
+
hasContextOverride: !!contextOverride,
|
|
1731
|
+
hasContext: !!context
|
|
1712
1732
|
});
|
|
1713
1733
|
try {
|
|
1714
1734
|
const res = await fetchWithAuth("/voice/sessions", {
|
|
@@ -1717,7 +1737,8 @@ function useVoice(options = {}) {
|
|
|
1717
1737
|
body: JSON.stringify({
|
|
1718
1738
|
agentId,
|
|
1719
1739
|
...threadId ? { threadId } : {},
|
|
1720
|
-
...contextOverride ? { contextOverride } : {}
|
|
1740
|
+
...contextOverride ? { contextOverride } : {},
|
|
1741
|
+
...context ? { context } : {}
|
|
1721
1742
|
})
|
|
1722
1743
|
});
|
|
1723
1744
|
if (!res.ok) {
|
|
@@ -1753,7 +1774,7 @@ function useVoice(options = {}) {
|
|
|
1753
1774
|
}
|
|
1754
1775
|
teardownAudio();
|
|
1755
1776
|
}
|
|
1756
|
-
}, [agentId, threadId, contextOverride, fetchWithAuth, handleMessage, teardownAudio, voiceLogger]);
|
|
1777
|
+
}, [agentId, threadId, contextOverride, context, fetchWithAuth, handleMessage, teardownAudio, voiceLogger]);
|
|
1757
1778
|
const mute = (0, import_react5.useCallback)((muted) => {
|
|
1758
1779
|
setIsMuted(muted);
|
|
1759
1780
|
streamRef.current?.getAudioTracks().forEach((track) => {
|
|
@@ -1764,6 +1785,10 @@ function useVoice(options = {}) {
|
|
|
1764
1785
|
if (!text?.trim() || wsRef.current?.readyState !== WebSocket.OPEN) return;
|
|
1765
1786
|
wsRef.current.send(JSON.stringify({ type: "voice.text", text }));
|
|
1766
1787
|
}, []);
|
|
1788
|
+
const updateContext = (0, import_react5.useCallback)((newContext) => {
|
|
1789
|
+
if (wsRef.current?.readyState !== WebSocket.OPEN) return;
|
|
1790
|
+
wsRef.current.send(JSON.stringify({ type: "voice.context", context: newContext }));
|
|
1791
|
+
}, []);
|
|
1767
1792
|
return {
|
|
1768
1793
|
state,
|
|
1769
1794
|
isMuted,
|
|
@@ -1775,7 +1800,8 @@ function useVoice(options = {}) {
|
|
|
1775
1800
|
start,
|
|
1776
1801
|
stop,
|
|
1777
1802
|
mute,
|
|
1778
|
-
sendText
|
|
1803
|
+
sendText,
|
|
1804
|
+
updateContext
|
|
1779
1805
|
};
|
|
1780
1806
|
}
|
|
1781
1807
|
|
|
@@ -2005,9 +2031,50 @@ function useMcpConnections(options = {}) {
|
|
|
2005
2031
|
};
|
|
2006
2032
|
}
|
|
2007
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
|
+
|
|
2008
2075
|
// src/index.ts
|
|
2009
2076
|
var import_logger2 = require("@personaai/logger");
|
|
2010
|
-
var VERSION = "0.7.
|
|
2077
|
+
var VERSION = "0.7.9";
|
|
2011
2078
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2012
2079
|
0 && (module.exports = {
|
|
2013
2080
|
PersonaProvider,
|
|
@@ -2023,6 +2090,7 @@ var VERSION = "0.7.3";
|
|
|
2023
2090
|
useChat,
|
|
2024
2091
|
useConnection,
|
|
2025
2092
|
useFiles,
|
|
2093
|
+
useMcp,
|
|
2026
2094
|
useMcpConnections,
|
|
2027
2095
|
useMemory,
|
|
2028
2096
|
usePersonaContext,
|