@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.d.cts
CHANGED
|
@@ -33,6 +33,11 @@ interface PersonaToolCall {
|
|
|
33
33
|
seq?: number;
|
|
34
34
|
/** Nested activity timeline — only present on `task` (subagent) tool calls. */
|
|
35
35
|
subagentActivity?: PersonaSubagentActivityEntry[];
|
|
36
|
+
/** Present when this tool is backed by an interactive MCP Ext App. */
|
|
37
|
+
mcpApp?: {
|
|
38
|
+
resourceUri: string;
|
|
39
|
+
mcpId: string;
|
|
40
|
+
};
|
|
36
41
|
}
|
|
37
42
|
interface PersonaMessage {
|
|
38
43
|
id: string;
|
|
@@ -107,6 +112,25 @@ interface PersonaPresentedFile {
|
|
|
107
112
|
title: string;
|
|
108
113
|
description: string;
|
|
109
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* One `execute` tool call against an Agent's sandbox (real shell execution
|
|
117
|
+
* in an isolated CodeSandbox VM — requires the Agent's `sandboxEnabled` and
|
|
118
|
+
* a `CSB_API_KEY` Project Secret; see the Agent's `sandboxEnabled` field).
|
|
119
|
+
* Derived from `PersonaToolCall`s named `execute` across every message in
|
|
120
|
+
* the conversation, in stream order — not a separate live/history-tracked
|
|
121
|
+
* state, so it's always consistent with `messages`.
|
|
122
|
+
*/
|
|
123
|
+
interface PersonaSandboxCommand {
|
|
124
|
+
toolCallId: string;
|
|
125
|
+
/** The shell command, parsed from the tool call's `args`. Falls back to the raw args string while still streaming/incomplete. */
|
|
126
|
+
command: string;
|
|
127
|
+
/** stdout/stderr, once the call finishes. */
|
|
128
|
+
output?: string;
|
|
129
|
+
/** `null` when the result parsed but didn't carry an exit code; `undefined` while still running. */
|
|
130
|
+
exitCode?: number | null;
|
|
131
|
+
status: "running" | "done" | "error";
|
|
132
|
+
seq?: number;
|
|
133
|
+
}
|
|
110
134
|
interface PersonaProviderProps {
|
|
111
135
|
/** Base URL where the Persona runtime / adapter is mounted, e.g. "http://localhost:4000/api/persona" */
|
|
112
136
|
baseUrl: string;
|
|
@@ -424,6 +448,7 @@ declare function useChat(options?: UseChatOptions): {
|
|
|
424
448
|
presentedFile: PersonaPresentedFile | null;
|
|
425
449
|
dismissPresentedFile: () => void;
|
|
426
450
|
openWorkspaceFile: (path: string) => void;
|
|
451
|
+
sandboxCommands: PersonaSandboxCommand[];
|
|
427
452
|
stop: () => void;
|
|
428
453
|
reload: () => void;
|
|
429
454
|
clear: () => void;
|
|
@@ -585,6 +610,19 @@ declare function useMcpConnections(options?: UseMcpConnectionsOptions): {
|
|
|
585
610
|
refetch: () => Promise<PersonaMcpConnection[]>;
|
|
586
611
|
};
|
|
587
612
|
|
|
613
|
+
interface UseMcpOptions {
|
|
614
|
+
/** Default MCP server ID for resource reads and tool calls */
|
|
615
|
+
mcpId?: string;
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* Hook for interacting with MCP servers connected via the Persona runtime.
|
|
619
|
+
* Provides helper functions for reading UI/data resources and calling server tools.
|
|
620
|
+
*/
|
|
621
|
+
declare function useMcp(options?: UseMcpOptions): {
|
|
622
|
+
readResource: (uri: string, mcpId?: string) => Promise<any>;
|
|
623
|
+
callTool: (name: string, args?: Record<string, unknown>, mcpId?: string) => Promise<any>;
|
|
624
|
+
};
|
|
625
|
+
|
|
588
626
|
/**
|
|
589
627
|
* SSE transport for chat streams, with a React Native fallback.
|
|
590
628
|
*
|
|
@@ -641,6 +679,6 @@ declare function supportsStreamingFetch(): boolean;
|
|
|
641
679
|
*/
|
|
642
680
|
declare function openSSEStream(opts: OpenSSEOptions): Promise<SSEStream>;
|
|
643
681
|
|
|
644
|
-
declare const VERSION = "0.7.
|
|
682
|
+
declare const VERSION = "0.7.10";
|
|
645
683
|
|
|
646
|
-
export { type OpenSSEOptions, type PersonaAgentSummary, type PersonaClarificationQuestion, type PersonaFileItem, type PersonaHealthInfo, type PersonaHitlActionRequest, type PersonaInterrupt, type PersonaMcpConnection, type PersonaMemoryAgentGroup, type PersonaMemoryFile, type PersonaMemoryList, type PersonaMessage, type PersonaPresentedFile, PersonaProvider, type PersonaProviderProps, type PersonaResumeValue, type PersonaRole, type PersonaStreamingEvent, type PersonaSubagentActivityEntry, type PersonaThread, type PersonaTodo, type PersonaToolCall, type PersonaVoiceEndReason, type PersonaVoiceState, type PersonaVoiceToolCall, type PersonaVoiceTranscriptLine, type PersonaWorkspaceFile, type SSEReader, type SSEStream, type SendMessageOverride, type UseChatOptions, type UseMcpConnectionsOptions, type UseVoiceOptions, type UseVoiceResult, VERSION, openSSEStream, supportsStreamingFetch, useAgents, useChat, useConnection, useFiles, useMcpConnections, useMemory, usePersonaContext, useThreads, useVoice };
|
|
684
|
+
export { type OpenSSEOptions, type PersonaAgentSummary, type PersonaClarificationQuestion, type PersonaFileItem, type PersonaHealthInfo, type PersonaHitlActionRequest, type PersonaInterrupt, type PersonaMcpConnection, type PersonaMemoryAgentGroup, type PersonaMemoryFile, type PersonaMemoryList, type PersonaMessage, type PersonaPresentedFile, PersonaProvider, type PersonaProviderProps, type PersonaResumeValue, type PersonaRole, type PersonaSandboxCommand, type PersonaStreamingEvent, type PersonaSubagentActivityEntry, type PersonaThread, type PersonaTodo, type PersonaToolCall, type PersonaVoiceEndReason, type PersonaVoiceState, type PersonaVoiceToolCall, type PersonaVoiceTranscriptLine, type PersonaWorkspaceFile, type SSEReader, type SSEStream, type SendMessageOverride, type UseChatOptions, type UseMcpConnectionsOptions, type UseMcpOptions, type UseVoiceOptions, type UseVoiceResult, VERSION, openSSEStream, supportsStreamingFetch, useAgents, useChat, useConnection, useFiles, useMcp, useMcpConnections, useMemory, usePersonaContext, useThreads, useVoice };
|
package/dist/index.d.ts
CHANGED
|
@@ -33,6 +33,11 @@ interface PersonaToolCall {
|
|
|
33
33
|
seq?: number;
|
|
34
34
|
/** Nested activity timeline — only present on `task` (subagent) tool calls. */
|
|
35
35
|
subagentActivity?: PersonaSubagentActivityEntry[];
|
|
36
|
+
/** Present when this tool is backed by an interactive MCP Ext App. */
|
|
37
|
+
mcpApp?: {
|
|
38
|
+
resourceUri: string;
|
|
39
|
+
mcpId: string;
|
|
40
|
+
};
|
|
36
41
|
}
|
|
37
42
|
interface PersonaMessage {
|
|
38
43
|
id: string;
|
|
@@ -107,6 +112,25 @@ interface PersonaPresentedFile {
|
|
|
107
112
|
title: string;
|
|
108
113
|
description: string;
|
|
109
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* One `execute` tool call against an Agent's sandbox (real shell execution
|
|
117
|
+
* in an isolated CodeSandbox VM — requires the Agent's `sandboxEnabled` and
|
|
118
|
+
* a `CSB_API_KEY` Project Secret; see the Agent's `sandboxEnabled` field).
|
|
119
|
+
* Derived from `PersonaToolCall`s named `execute` across every message in
|
|
120
|
+
* the conversation, in stream order — not a separate live/history-tracked
|
|
121
|
+
* state, so it's always consistent with `messages`.
|
|
122
|
+
*/
|
|
123
|
+
interface PersonaSandboxCommand {
|
|
124
|
+
toolCallId: string;
|
|
125
|
+
/** The shell command, parsed from the tool call's `args`. Falls back to the raw args string while still streaming/incomplete. */
|
|
126
|
+
command: string;
|
|
127
|
+
/** stdout/stderr, once the call finishes. */
|
|
128
|
+
output?: string;
|
|
129
|
+
/** `null` when the result parsed but didn't carry an exit code; `undefined` while still running. */
|
|
130
|
+
exitCode?: number | null;
|
|
131
|
+
status: "running" | "done" | "error";
|
|
132
|
+
seq?: number;
|
|
133
|
+
}
|
|
110
134
|
interface PersonaProviderProps {
|
|
111
135
|
/** Base URL where the Persona runtime / adapter is mounted, e.g. "http://localhost:4000/api/persona" */
|
|
112
136
|
baseUrl: string;
|
|
@@ -424,6 +448,7 @@ declare function useChat(options?: UseChatOptions): {
|
|
|
424
448
|
presentedFile: PersonaPresentedFile | null;
|
|
425
449
|
dismissPresentedFile: () => void;
|
|
426
450
|
openWorkspaceFile: (path: string) => void;
|
|
451
|
+
sandboxCommands: PersonaSandboxCommand[];
|
|
427
452
|
stop: () => void;
|
|
428
453
|
reload: () => void;
|
|
429
454
|
clear: () => void;
|
|
@@ -585,6 +610,19 @@ declare function useMcpConnections(options?: UseMcpConnectionsOptions): {
|
|
|
585
610
|
refetch: () => Promise<PersonaMcpConnection[]>;
|
|
586
611
|
};
|
|
587
612
|
|
|
613
|
+
interface UseMcpOptions {
|
|
614
|
+
/** Default MCP server ID for resource reads and tool calls */
|
|
615
|
+
mcpId?: string;
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* Hook for interacting with MCP servers connected via the Persona runtime.
|
|
619
|
+
* Provides helper functions for reading UI/data resources and calling server tools.
|
|
620
|
+
*/
|
|
621
|
+
declare function useMcp(options?: UseMcpOptions): {
|
|
622
|
+
readResource: (uri: string, mcpId?: string) => Promise<any>;
|
|
623
|
+
callTool: (name: string, args?: Record<string, unknown>, mcpId?: string) => Promise<any>;
|
|
624
|
+
};
|
|
625
|
+
|
|
588
626
|
/**
|
|
589
627
|
* SSE transport for chat streams, with a React Native fallback.
|
|
590
628
|
*
|
|
@@ -641,6 +679,6 @@ declare function supportsStreamingFetch(): boolean;
|
|
|
641
679
|
*/
|
|
642
680
|
declare function openSSEStream(opts: OpenSSEOptions): Promise<SSEStream>;
|
|
643
681
|
|
|
644
|
-
declare const VERSION = "0.7.
|
|
682
|
+
declare const VERSION = "0.7.10";
|
|
645
683
|
|
|
646
|
-
export { type OpenSSEOptions, type PersonaAgentSummary, type PersonaClarificationQuestion, type PersonaFileItem, type PersonaHealthInfo, type PersonaHitlActionRequest, type PersonaInterrupt, type PersonaMcpConnection, type PersonaMemoryAgentGroup, type PersonaMemoryFile, type PersonaMemoryList, type PersonaMessage, type PersonaPresentedFile, PersonaProvider, type PersonaProviderProps, type PersonaResumeValue, type PersonaRole, type PersonaStreamingEvent, type PersonaSubagentActivityEntry, type PersonaThread, type PersonaTodo, type PersonaToolCall, type PersonaVoiceEndReason, type PersonaVoiceState, type PersonaVoiceToolCall, type PersonaVoiceTranscriptLine, type PersonaWorkspaceFile, type SSEReader, type SSEStream, type SendMessageOverride, type UseChatOptions, type UseMcpConnectionsOptions, type UseVoiceOptions, type UseVoiceResult, VERSION, openSSEStream, supportsStreamingFetch, useAgents, useChat, useConnection, useFiles, useMcpConnections, useMemory, usePersonaContext, useThreads, useVoice };
|
|
684
|
+
export { type OpenSSEOptions, type PersonaAgentSummary, type PersonaClarificationQuestion, type PersonaFileItem, type PersonaHealthInfo, type PersonaHitlActionRequest, type PersonaInterrupt, type PersonaMcpConnection, type PersonaMemoryAgentGroup, type PersonaMemoryFile, type PersonaMemoryList, type PersonaMessage, type PersonaPresentedFile, PersonaProvider, type PersonaProviderProps, type PersonaResumeValue, type PersonaRole, type PersonaSandboxCommand, type PersonaStreamingEvent, type PersonaSubagentActivityEntry, type PersonaThread, type PersonaTodo, type PersonaToolCall, type PersonaVoiceEndReason, type PersonaVoiceState, type PersonaVoiceToolCall, type PersonaVoiceTranscriptLine, type PersonaWorkspaceFile, type SSEReader, type SSEStream, type SendMessageOverride, type UseChatOptions, type UseMcpConnectionsOptions, type UseMcpOptions, type UseVoiceOptions, type UseVoiceResult, VERSION, openSSEStream, supportsStreamingFetch, useAgents, useChat, useConnection, useFiles, useMcp, useMcpConnections, useMemory, usePersonaContext, useThreads, useVoice };
|
package/dist/index.js
CHANGED
|
@@ -330,6 +330,37 @@ function parsePresentedFile(content) {
|
|
|
330
330
|
return null;
|
|
331
331
|
}
|
|
332
332
|
}
|
|
333
|
+
function parseSandboxCommand(tc) {
|
|
334
|
+
let command = tc.args ?? "";
|
|
335
|
+
try {
|
|
336
|
+
const parsedArgs = JSON.parse(tc.args || "{}");
|
|
337
|
+
if (typeof parsedArgs.command === "string") command = parsedArgs.command;
|
|
338
|
+
} catch {
|
|
339
|
+
}
|
|
340
|
+
let output;
|
|
341
|
+
let exitCode;
|
|
342
|
+
if (tc.result) {
|
|
343
|
+
try {
|
|
344
|
+
const parsedResult = JSON.parse(tc.result);
|
|
345
|
+
if (typeof parsedResult.output === "string") {
|
|
346
|
+
output = parsedResult.output;
|
|
347
|
+
exitCode = typeof parsedResult.exitCode === "number" ? parsedResult.exitCode : null;
|
|
348
|
+
} else {
|
|
349
|
+
output = tc.result;
|
|
350
|
+
}
|
|
351
|
+
} catch {
|
|
352
|
+
output = tc.result;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
return {
|
|
356
|
+
toolCallId: tc.toolCallId,
|
|
357
|
+
command,
|
|
358
|
+
output,
|
|
359
|
+
exitCode,
|
|
360
|
+
status: tc.isError ? "error" : tc.result ? "done" : "running",
|
|
361
|
+
seq: tc.seq
|
|
362
|
+
};
|
|
363
|
+
}
|
|
333
364
|
function normalizeWorkspaceFiles(raw) {
|
|
334
365
|
const normalized = {};
|
|
335
366
|
for (const [path, file] of Object.entries(raw || {})) {
|
|
@@ -390,6 +421,15 @@ function useChat(options = {}) {
|
|
|
390
421
|
const [files, setFiles] = useState({});
|
|
391
422
|
const [todos, setTodos] = useState([]);
|
|
392
423
|
const [presentedFile, setPresentedFile] = useState(null);
|
|
424
|
+
const sandboxCommands = useMemo2(() => {
|
|
425
|
+
const commands = [];
|
|
426
|
+
for (const message of messages) {
|
|
427
|
+
for (const tc of message.toolCalls ?? []) {
|
|
428
|
+
if (tc.toolName === "execute") commands.push(parseSandboxCommand(tc));
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
return commands;
|
|
432
|
+
}, [messages]);
|
|
393
433
|
const abortControllerRef = useRef(null);
|
|
394
434
|
const loadedThreadIdRef = useRef(void 0);
|
|
395
435
|
const voiceThreadRef = useRef(threadId);
|
|
@@ -865,6 +905,18 @@ function useChat(options = {}) {
|
|
|
865
905
|
];
|
|
866
906
|
patchAssistant({});
|
|
867
907
|
}
|
|
908
|
+
} else if (event.name === "mcp_app") {
|
|
909
|
+
const val = event.value;
|
|
910
|
+
if (val?.toolCallId && val?.resourceUri && val?.mcpId) {
|
|
911
|
+
const existing = toolCallsMap.get(val.toolCallId);
|
|
912
|
+
if (existing) {
|
|
913
|
+
existing.mcpApp = {
|
|
914
|
+
resourceUri: val.resourceUri,
|
|
915
|
+
mcpId: val.mcpId
|
|
916
|
+
};
|
|
917
|
+
patchAssistant({});
|
|
918
|
+
}
|
|
919
|
+
}
|
|
868
920
|
}
|
|
869
921
|
} else if (event.type === "RUN_ERROR") {
|
|
870
922
|
chatLogger.warn("run error", {
|
|
@@ -1053,6 +1105,7 @@ function useChat(options = {}) {
|
|
|
1053
1105
|
presentedFile,
|
|
1054
1106
|
dismissPresentedFile,
|
|
1055
1107
|
openWorkspaceFile,
|
|
1108
|
+
sandboxCommands,
|
|
1056
1109
|
stop,
|
|
1057
1110
|
reload,
|
|
1058
1111
|
clear,
|
|
@@ -1975,6 +2028,47 @@ function useMcpConnections(options = {}) {
|
|
|
1975
2028
|
};
|
|
1976
2029
|
}
|
|
1977
2030
|
|
|
2031
|
+
// src/hooks/useMcp.ts
|
|
2032
|
+
import { useCallback as useCallback9 } from "react";
|
|
2033
|
+
function useMcp(options = {}) {
|
|
2034
|
+
const { fetchWithAuth } = usePersonaContext();
|
|
2035
|
+
const defaultMcpId = options.mcpId;
|
|
2036
|
+
const readResource = useCallback9(
|
|
2037
|
+
async (uri, mcpId) => {
|
|
2038
|
+
const id = mcpId ?? defaultMcpId;
|
|
2039
|
+
if (!id) throw new Error("MCP server ID is required to read resource");
|
|
2040
|
+
const res = await fetchWithAuth(
|
|
2041
|
+
`/mcps/${id}/resource?uri=${encodeURIComponent(uri)}`
|
|
2042
|
+
);
|
|
2043
|
+
if (!res.ok) {
|
|
2044
|
+
throw new Error(`Failed to read MCP resource: ${res.statusText}`);
|
|
2045
|
+
}
|
|
2046
|
+
return await res.json();
|
|
2047
|
+
},
|
|
2048
|
+
[fetchWithAuth, defaultMcpId]
|
|
2049
|
+
);
|
|
2050
|
+
const callTool = useCallback9(
|
|
2051
|
+
async (name, args, mcpId) => {
|
|
2052
|
+
const id = mcpId ?? defaultMcpId;
|
|
2053
|
+
if (!id) throw new Error("MCP server ID is required to call tool");
|
|
2054
|
+
const res = await fetchWithAuth(`/mcps/${id}/call-tool`, {
|
|
2055
|
+
method: "POST",
|
|
2056
|
+
headers: { "Content-Type": "application/json" },
|
|
2057
|
+
body: JSON.stringify({ name, arguments: args })
|
|
2058
|
+
});
|
|
2059
|
+
if (!res.ok) {
|
|
2060
|
+
throw new Error(`Failed to call MCP tool: ${res.statusText}`);
|
|
2061
|
+
}
|
|
2062
|
+
return await res.json();
|
|
2063
|
+
},
|
|
2064
|
+
[fetchWithAuth, defaultMcpId]
|
|
2065
|
+
);
|
|
2066
|
+
return {
|
|
2067
|
+
readResource,
|
|
2068
|
+
callTool
|
|
2069
|
+
};
|
|
2070
|
+
}
|
|
2071
|
+
|
|
1978
2072
|
// src/index.ts
|
|
1979
2073
|
import {
|
|
1980
2074
|
createLogger as createLogger2,
|
|
@@ -1983,7 +2077,7 @@ import {
|
|
|
1983
2077
|
getLogLevel,
|
|
1984
2078
|
isLevelEnabled
|
|
1985
2079
|
} from "@personaai/logger";
|
|
1986
|
-
var VERSION = "0.7.
|
|
2080
|
+
var VERSION = "0.7.10";
|
|
1987
2081
|
export {
|
|
1988
2082
|
PersonaProvider,
|
|
1989
2083
|
VERSION,
|
|
@@ -1998,6 +2092,7 @@ export {
|
|
|
1998
2092
|
useChat,
|
|
1999
2093
|
useConnection,
|
|
2000
2094
|
useFiles,
|
|
2095
|
+
useMcp,
|
|
2001
2096
|
useMcpConnections,
|
|
2002
2097
|
useMemory,
|
|
2003
2098
|
usePersonaContext,
|