@personaai/react 0.7.8 → 0.7.10
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 +97 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +40 -2
- package/dist/index.d.ts +40 -2
- package/dist/index.js +96 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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,
|
|
@@ -373,6 +374,37 @@ function parsePresentedFile(content) {
|
|
|
373
374
|
return null;
|
|
374
375
|
}
|
|
375
376
|
}
|
|
377
|
+
function parseSandboxCommand(tc) {
|
|
378
|
+
let command = tc.args ?? "";
|
|
379
|
+
try {
|
|
380
|
+
const parsedArgs = JSON.parse(tc.args || "{}");
|
|
381
|
+
if (typeof parsedArgs.command === "string") command = parsedArgs.command;
|
|
382
|
+
} catch {
|
|
383
|
+
}
|
|
384
|
+
let output;
|
|
385
|
+
let exitCode;
|
|
386
|
+
if (tc.result) {
|
|
387
|
+
try {
|
|
388
|
+
const parsedResult = JSON.parse(tc.result);
|
|
389
|
+
if (typeof parsedResult.output === "string") {
|
|
390
|
+
output = parsedResult.output;
|
|
391
|
+
exitCode = typeof parsedResult.exitCode === "number" ? parsedResult.exitCode : null;
|
|
392
|
+
} else {
|
|
393
|
+
output = tc.result;
|
|
394
|
+
}
|
|
395
|
+
} catch {
|
|
396
|
+
output = tc.result;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
return {
|
|
400
|
+
toolCallId: tc.toolCallId,
|
|
401
|
+
command,
|
|
402
|
+
output,
|
|
403
|
+
exitCode,
|
|
404
|
+
status: tc.isError ? "error" : tc.result ? "done" : "running",
|
|
405
|
+
seq: tc.seq
|
|
406
|
+
};
|
|
407
|
+
}
|
|
376
408
|
function normalizeWorkspaceFiles(raw) {
|
|
377
409
|
const normalized = {};
|
|
378
410
|
for (const [path, file] of Object.entries(raw || {})) {
|
|
@@ -433,6 +465,15 @@ function useChat(options = {}) {
|
|
|
433
465
|
const [files, setFiles] = (0, import_react2.useState)({});
|
|
434
466
|
const [todos, setTodos] = (0, import_react2.useState)([]);
|
|
435
467
|
const [presentedFile, setPresentedFile] = (0, import_react2.useState)(null);
|
|
468
|
+
const sandboxCommands = (0, import_react2.useMemo)(() => {
|
|
469
|
+
const commands = [];
|
|
470
|
+
for (const message of messages) {
|
|
471
|
+
for (const tc of message.toolCalls ?? []) {
|
|
472
|
+
if (tc.toolName === "execute") commands.push(parseSandboxCommand(tc));
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
return commands;
|
|
476
|
+
}, [messages]);
|
|
436
477
|
const abortControllerRef = (0, import_react2.useRef)(null);
|
|
437
478
|
const loadedThreadIdRef = (0, import_react2.useRef)(void 0);
|
|
438
479
|
const voiceThreadRef = (0, import_react2.useRef)(threadId);
|
|
@@ -908,6 +949,18 @@ function useChat(options = {}) {
|
|
|
908
949
|
];
|
|
909
950
|
patchAssistant({});
|
|
910
951
|
}
|
|
952
|
+
} else if (event.name === "mcp_app") {
|
|
953
|
+
const val = event.value;
|
|
954
|
+
if (val?.toolCallId && val?.resourceUri && val?.mcpId) {
|
|
955
|
+
const existing = toolCallsMap.get(val.toolCallId);
|
|
956
|
+
if (existing) {
|
|
957
|
+
existing.mcpApp = {
|
|
958
|
+
resourceUri: val.resourceUri,
|
|
959
|
+
mcpId: val.mcpId
|
|
960
|
+
};
|
|
961
|
+
patchAssistant({});
|
|
962
|
+
}
|
|
963
|
+
}
|
|
911
964
|
}
|
|
912
965
|
} else if (event.type === "RUN_ERROR") {
|
|
913
966
|
chatLogger.warn("run error", {
|
|
@@ -1096,6 +1149,7 @@ function useChat(options = {}) {
|
|
|
1096
1149
|
presentedFile,
|
|
1097
1150
|
dismissPresentedFile,
|
|
1098
1151
|
openWorkspaceFile,
|
|
1152
|
+
sandboxCommands,
|
|
1099
1153
|
stop,
|
|
1100
1154
|
reload,
|
|
1101
1155
|
clear,
|
|
@@ -2018,9 +2072,50 @@ function useMcpConnections(options = {}) {
|
|
|
2018
2072
|
};
|
|
2019
2073
|
}
|
|
2020
2074
|
|
|
2075
|
+
// src/hooks/useMcp.ts
|
|
2076
|
+
var import_react10 = require("react");
|
|
2077
|
+
function useMcp(options = {}) {
|
|
2078
|
+
const { fetchWithAuth } = usePersonaContext();
|
|
2079
|
+
const defaultMcpId = options.mcpId;
|
|
2080
|
+
const readResource = (0, import_react10.useCallback)(
|
|
2081
|
+
async (uri, mcpId) => {
|
|
2082
|
+
const id = mcpId ?? defaultMcpId;
|
|
2083
|
+
if (!id) throw new Error("MCP server ID is required to read resource");
|
|
2084
|
+
const res = await fetchWithAuth(
|
|
2085
|
+
`/mcps/${id}/resource?uri=${encodeURIComponent(uri)}`
|
|
2086
|
+
);
|
|
2087
|
+
if (!res.ok) {
|
|
2088
|
+
throw new Error(`Failed to read MCP resource: ${res.statusText}`);
|
|
2089
|
+
}
|
|
2090
|
+
return await res.json();
|
|
2091
|
+
},
|
|
2092
|
+
[fetchWithAuth, defaultMcpId]
|
|
2093
|
+
);
|
|
2094
|
+
const callTool = (0, import_react10.useCallback)(
|
|
2095
|
+
async (name, args, mcpId) => {
|
|
2096
|
+
const id = mcpId ?? defaultMcpId;
|
|
2097
|
+
if (!id) throw new Error("MCP server ID is required to call tool");
|
|
2098
|
+
const res = await fetchWithAuth(`/mcps/${id}/call-tool`, {
|
|
2099
|
+
method: "POST",
|
|
2100
|
+
headers: { "Content-Type": "application/json" },
|
|
2101
|
+
body: JSON.stringify({ name, arguments: args })
|
|
2102
|
+
});
|
|
2103
|
+
if (!res.ok) {
|
|
2104
|
+
throw new Error(`Failed to call MCP tool: ${res.statusText}`);
|
|
2105
|
+
}
|
|
2106
|
+
return await res.json();
|
|
2107
|
+
},
|
|
2108
|
+
[fetchWithAuth, defaultMcpId]
|
|
2109
|
+
);
|
|
2110
|
+
return {
|
|
2111
|
+
readResource,
|
|
2112
|
+
callTool
|
|
2113
|
+
};
|
|
2114
|
+
}
|
|
2115
|
+
|
|
2021
2116
|
// src/index.ts
|
|
2022
2117
|
var import_logger2 = require("@personaai/logger");
|
|
2023
|
-
var VERSION = "0.7.
|
|
2118
|
+
var VERSION = "0.7.10";
|
|
2024
2119
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2025
2120
|
0 && (module.exports = {
|
|
2026
2121
|
PersonaProvider,
|
|
@@ -2036,6 +2131,7 @@ var VERSION = "0.7.3";
|
|
|
2036
2131
|
useChat,
|
|
2037
2132
|
useConnection,
|
|
2038
2133
|
useFiles,
|
|
2134
|
+
useMcp,
|
|
2039
2135
|
useMcpConnections,
|
|
2040
2136
|
useMemory,
|
|
2041
2137
|
usePersonaContext,
|