@personaai/react 0.1.0 → 0.2.0
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 +793 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +341 -0
- package/dist/index.d.ts +341 -0
- package/dist/index.js +758 -0
- package/dist/index.js.map +1 -0
- package/package.json +1 -1
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import react__default, { ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
type PersonaRole = 'user' | 'assistant' | 'system';
|
|
5
|
+
/** One live update on a running `task` (subagent) tool call's timeline. */
|
|
6
|
+
interface PersonaSubagentActivityEntry {
|
|
7
|
+
kind: 'text' | 'tool_start' | 'tool_result';
|
|
8
|
+
toolName?: string;
|
|
9
|
+
args?: string;
|
|
10
|
+
result?: string;
|
|
11
|
+
delta?: string;
|
|
12
|
+
}
|
|
13
|
+
interface PersonaToolCall {
|
|
14
|
+
toolCallId: string;
|
|
15
|
+
toolName: string;
|
|
16
|
+
args?: string;
|
|
17
|
+
result?: string;
|
|
18
|
+
isError?: boolean;
|
|
19
|
+
/** Nested activity timeline — only present on `task` (subagent) tool calls. */
|
|
20
|
+
subagentActivity?: PersonaSubagentActivityEntry[];
|
|
21
|
+
}
|
|
22
|
+
interface PersonaMessage {
|
|
23
|
+
id: string;
|
|
24
|
+
role: PersonaRole;
|
|
25
|
+
content: string;
|
|
26
|
+
createdAt: Date;
|
|
27
|
+
isStreaming?: boolean;
|
|
28
|
+
toolCalls?: PersonaToolCall[];
|
|
29
|
+
/** Model reasoning/thinking text streamed ahead of the final answer, when the provider exposes it. */
|
|
30
|
+
reasoning?: string;
|
|
31
|
+
isReasoning?: boolean;
|
|
32
|
+
}
|
|
33
|
+
interface PersonaHitlActionRequest {
|
|
34
|
+
name: string;
|
|
35
|
+
args?: unknown;
|
|
36
|
+
}
|
|
37
|
+
interface PersonaClarificationQuestion {
|
|
38
|
+
id: string;
|
|
39
|
+
text: string;
|
|
40
|
+
options: string[];
|
|
41
|
+
required: boolean;
|
|
42
|
+
allowCustom: boolean;
|
|
43
|
+
}
|
|
44
|
+
/** A paused human-in-the-loop tool approval, or a paused clarification question. */
|
|
45
|
+
type PersonaInterrupt = {
|
|
46
|
+
kind: 'hitl';
|
|
47
|
+
actionRequests: PersonaHitlActionRequest[];
|
|
48
|
+
reviewConfigs: unknown[];
|
|
49
|
+
} | {
|
|
50
|
+
kind: 'clarification';
|
|
51
|
+
questions: PersonaClarificationQuestion[];
|
|
52
|
+
};
|
|
53
|
+
/** What to send back in `sendMessage(content, { resume })` to unpause a paused run. */
|
|
54
|
+
type PersonaResumeValue = {
|
|
55
|
+
decisions: Array<{
|
|
56
|
+
type: 'approve' | 'reject';
|
|
57
|
+
message?: string;
|
|
58
|
+
}>;
|
|
59
|
+
} | {
|
|
60
|
+
answers: unknown[];
|
|
61
|
+
text?: string;
|
|
62
|
+
};
|
|
63
|
+
interface PersonaProviderProps {
|
|
64
|
+
/** Base URL where the Persona runtime / adapter is mounted, e.g. "http://localhost:4000/api/persona" */
|
|
65
|
+
baseUrl: string;
|
|
66
|
+
/** Async or sync getter for the user's Bearer JWT authentication token */
|
|
67
|
+
getAuthToken?: () => Promise<string | null | undefined> | string | null | undefined;
|
|
68
|
+
/** Default Agent ID to direct chat conversations to */
|
|
69
|
+
defaultAgentId?: string;
|
|
70
|
+
children: ReactNode;
|
|
71
|
+
}
|
|
72
|
+
interface PersonaThread {
|
|
73
|
+
_id: string;
|
|
74
|
+
/** A bare id string on create()/get(); populated as an object on list(). */
|
|
75
|
+
agentId: string | {
|
|
76
|
+
_id: string;
|
|
77
|
+
name: string;
|
|
78
|
+
avatar?: string;
|
|
79
|
+
slug: string;
|
|
80
|
+
};
|
|
81
|
+
title?: string;
|
|
82
|
+
isArchived?: boolean;
|
|
83
|
+
createdAt: string;
|
|
84
|
+
updatedAt: string;
|
|
85
|
+
}
|
|
86
|
+
/** Mirrors the wire shape of `GET/POST /files` — `id`, not `_id`. */
|
|
87
|
+
interface PersonaFileItem {
|
|
88
|
+
id: string;
|
|
89
|
+
originalName: string;
|
|
90
|
+
mimeType: string;
|
|
91
|
+
/** Bytes. */
|
|
92
|
+
size: number;
|
|
93
|
+
agentId: string | null;
|
|
94
|
+
threadId: string | null;
|
|
95
|
+
createdAt: string;
|
|
96
|
+
}
|
|
97
|
+
interface PersonaMemoryFile {
|
|
98
|
+
scope?: 'user' | 'agent';
|
|
99
|
+
agentId?: string;
|
|
100
|
+
path: string;
|
|
101
|
+
content: string;
|
|
102
|
+
mimeType?: string;
|
|
103
|
+
createdAt?: string;
|
|
104
|
+
updatedAt?: string;
|
|
105
|
+
}
|
|
106
|
+
/** One agent's group of agent-scoped memory files, as returned by `GET /memory`. */
|
|
107
|
+
interface PersonaMemoryAgentGroup {
|
|
108
|
+
agentId: string;
|
|
109
|
+
/** `null` if the agent no longer exists. */
|
|
110
|
+
agentName: string | null;
|
|
111
|
+
files: PersonaMemoryFile[];
|
|
112
|
+
}
|
|
113
|
+
interface PersonaMemoryList {
|
|
114
|
+
userFiles: PersonaMemoryFile[];
|
|
115
|
+
agentMemories: PersonaMemoryAgentGroup[];
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* AG-UI protocol events emitted during streaming — mirrors exactly what
|
|
119
|
+
* `aguiTranslator.js` produces server-side (verified against that file, not
|
|
120
|
+
* guessed from the AG-UI spec: this backend only emits a subset, and uses
|
|
121
|
+
* `TOOL_CALL_CHUNK` rather than separate START/ARGS events for tool calls,
|
|
122
|
+
* and `REASONING_END` rather than `REASONING_MESSAGE_END`).
|
|
123
|
+
*/
|
|
124
|
+
type PersonaStreamingEvent = {
|
|
125
|
+
type: 'TEXT_MESSAGE_CHUNK';
|
|
126
|
+
delta: string;
|
|
127
|
+
messageId?: string;
|
|
128
|
+
role?: 'assistant';
|
|
129
|
+
} | {
|
|
130
|
+
type: 'TOOL_CALL_CHUNK';
|
|
131
|
+
toolCallId?: string;
|
|
132
|
+
toolCallName?: string;
|
|
133
|
+
delta?: string;
|
|
134
|
+
parentMessageId?: string;
|
|
135
|
+
} | {
|
|
136
|
+
type: 'TOOL_CALL_RESULT';
|
|
137
|
+
toolCallId: string;
|
|
138
|
+
content: string;
|
|
139
|
+
messageId?: string;
|
|
140
|
+
role?: 'tool';
|
|
141
|
+
structuredContent?: unknown;
|
|
142
|
+
} | {
|
|
143
|
+
type: 'REASONING_MESSAGE_START';
|
|
144
|
+
messageId: string;
|
|
145
|
+
} | {
|
|
146
|
+
type: 'REASONING_MESSAGE_CONTENT';
|
|
147
|
+
messageId: string;
|
|
148
|
+
delta: string;
|
|
149
|
+
} | {
|
|
150
|
+
type: 'REASONING_END';
|
|
151
|
+
} | {
|
|
152
|
+
type: 'STATE_SNAPSHOT';
|
|
153
|
+
snapshot: {
|
|
154
|
+
files: Record<string, unknown>;
|
|
155
|
+
todos: Array<{
|
|
156
|
+
content: string;
|
|
157
|
+
status: string;
|
|
158
|
+
}>;
|
|
159
|
+
};
|
|
160
|
+
} | {
|
|
161
|
+
type: 'RUN_ERROR';
|
|
162
|
+
code: string;
|
|
163
|
+
message: string;
|
|
164
|
+
retryable?: boolean;
|
|
165
|
+
providerName?: string;
|
|
166
|
+
} | {
|
|
167
|
+
type: 'CUSTOM';
|
|
168
|
+
name: 'hitl_request';
|
|
169
|
+
value: {
|
|
170
|
+
actionRequests: PersonaHitlActionRequest[];
|
|
171
|
+
reviewConfigs: unknown[];
|
|
172
|
+
};
|
|
173
|
+
} | {
|
|
174
|
+
type: 'CUSTOM';
|
|
175
|
+
name: 'clarification_request';
|
|
176
|
+
value: {
|
|
177
|
+
questions: PersonaClarificationQuestion[];
|
|
178
|
+
currentIndex: number;
|
|
179
|
+
};
|
|
180
|
+
} | {
|
|
181
|
+
type: 'CUSTOM';
|
|
182
|
+
name: 'subagent_activity';
|
|
183
|
+
value: {
|
|
184
|
+
toolCallId: string;
|
|
185
|
+
} & PersonaSubagentActivityEntry;
|
|
186
|
+
} | {
|
|
187
|
+
type: 'CUSTOM';
|
|
188
|
+
name: 'mcp_app';
|
|
189
|
+
value: {
|
|
190
|
+
toolCallId: string;
|
|
191
|
+
resourceUri: string;
|
|
192
|
+
mcpId: string;
|
|
193
|
+
};
|
|
194
|
+
} | {
|
|
195
|
+
type: 'CUSTOM';
|
|
196
|
+
name: string & {};
|
|
197
|
+
value: unknown;
|
|
198
|
+
};
|
|
199
|
+
interface UseChatOptions {
|
|
200
|
+
agentId?: string;
|
|
201
|
+
threadId?: string;
|
|
202
|
+
initialMessages?: PersonaMessage[];
|
|
203
|
+
onFinish?: (message: PersonaMessage) => void;
|
|
204
|
+
onError?: (error: Error) => void;
|
|
205
|
+
/** Hook for receiving every low-level AG-UI streaming event (tool calls, steps, subagents) */
|
|
206
|
+
onEvent?: (event: PersonaStreamingEvent) => void;
|
|
207
|
+
}
|
|
208
|
+
interface SendMessageOverride {
|
|
209
|
+
agentId?: string;
|
|
210
|
+
threadId?: string;
|
|
211
|
+
/** Answers/approves a paused interrupt from a previous turn instead of starting a fresh one. */
|
|
212
|
+
resume?: PersonaResumeValue;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
interface PersonaContextValue {
|
|
216
|
+
baseUrl: string;
|
|
217
|
+
getAuthToken?: () => Promise<string | null | undefined> | string | null | undefined;
|
|
218
|
+
defaultAgentId?: string;
|
|
219
|
+
fetchWithAuth: (path: string, init?: RequestInit) => Promise<Response>;
|
|
220
|
+
}
|
|
221
|
+
declare function PersonaProvider({ baseUrl, getAuthToken, defaultAgentId, children, }: PersonaProviderProps): react__default.JSX.Element;
|
|
222
|
+
declare function usePersonaContext(): PersonaContextValue;
|
|
223
|
+
|
|
224
|
+
declare function useChat(options?: UseChatOptions): {
|
|
225
|
+
messages: PersonaMessage[];
|
|
226
|
+
input: string;
|
|
227
|
+
setInput: react.Dispatch<react.SetStateAction<string>>;
|
|
228
|
+
handleInputChange: (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
|
|
229
|
+
handleSubmit: (e?: React.FormEvent) => void;
|
|
230
|
+
sendMessage: (contentToSend?: string, overrideOptions?: SendMessageOverride) => Promise<void>;
|
|
231
|
+
isStreaming: boolean;
|
|
232
|
+
isLoading: boolean;
|
|
233
|
+
isLoadingHistory: boolean;
|
|
234
|
+
error: Error | null;
|
|
235
|
+
interrupt: PersonaInterrupt | null;
|
|
236
|
+
resumeInterrupt: (resume: PersonaResumeValue, displayContent: string) => Promise<void>;
|
|
237
|
+
stop: () => void;
|
|
238
|
+
reload: () => void;
|
|
239
|
+
clear: () => void;
|
|
240
|
+
setMessages: react.Dispatch<react.SetStateAction<PersonaMessage[]>>;
|
|
241
|
+
loadThreadMessages: (id: string) => Promise<PersonaMessage[]>;
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
declare function useMemory(autoFetch?: boolean): {
|
|
245
|
+
memory: PersonaMemoryList;
|
|
246
|
+
isLoading: boolean;
|
|
247
|
+
error: Error | null;
|
|
248
|
+
refetch: () => Promise<PersonaMemoryList>;
|
|
249
|
+
getFile: (params: {
|
|
250
|
+
path: string;
|
|
251
|
+
scope?: "user" | "agent";
|
|
252
|
+
agentId?: string;
|
|
253
|
+
}) => Promise<PersonaMemoryFile>;
|
|
254
|
+
writeFile: (params: {
|
|
255
|
+
path: string;
|
|
256
|
+
content: string;
|
|
257
|
+
scope?: "user" | "agent";
|
|
258
|
+
agentId?: string;
|
|
259
|
+
}) => Promise<PersonaMemoryFile>;
|
|
260
|
+
deleteFile: (params: {
|
|
261
|
+
path: string;
|
|
262
|
+
scope?: "user" | "agent";
|
|
263
|
+
agentId?: string;
|
|
264
|
+
}) => Promise<void>;
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
declare function useThreads(autoFetch?: boolean): {
|
|
268
|
+
threads: PersonaThread[];
|
|
269
|
+
isLoading: boolean;
|
|
270
|
+
error: Error | null;
|
|
271
|
+
refetch: () => Promise<PersonaThread[]>;
|
|
272
|
+
createThread: (agentId?: string) => Promise<PersonaThread>;
|
|
273
|
+
deleteThread: (threadId: string) => Promise<void>;
|
|
274
|
+
bulkDeleteThreads: (threadIds: string[]) => Promise<{
|
|
275
|
+
deleted: string[];
|
|
276
|
+
failed: Array<{
|
|
277
|
+
id: string;
|
|
278
|
+
reason: string;
|
|
279
|
+
}>;
|
|
280
|
+
}>;
|
|
281
|
+
deleteAllThreads: () => Promise<void>;
|
|
282
|
+
updateThread: (threadId: string, input: {
|
|
283
|
+
title?: string;
|
|
284
|
+
isArchived?: boolean;
|
|
285
|
+
}) => Promise<PersonaThread>;
|
|
286
|
+
renameThread: (threadId: string, title: string) => Promise<PersonaThread>;
|
|
287
|
+
getThread: (threadId: string) => Promise<PersonaThread>;
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
declare function useFiles(autoFetch?: boolean): {
|
|
291
|
+
files: PersonaFileItem[];
|
|
292
|
+
isLoading: boolean;
|
|
293
|
+
isUploading: boolean;
|
|
294
|
+
error: Error | null;
|
|
295
|
+
refetch: () => Promise<PersonaFileItem[]>;
|
|
296
|
+
uploadFile: (fileOrFormData: FormData | {
|
|
297
|
+
name: string;
|
|
298
|
+
uri: string;
|
|
299
|
+
type?: string;
|
|
300
|
+
}) => Promise<PersonaFileItem>;
|
|
301
|
+
deleteFile: (fileId: string) => Promise<void>;
|
|
302
|
+
bulkDeleteFiles: (fileIds: string[]) => Promise<{
|
|
303
|
+
deleted: string[];
|
|
304
|
+
failed: Array<{
|
|
305
|
+
id: string;
|
|
306
|
+
reason: string;
|
|
307
|
+
}>;
|
|
308
|
+
}>;
|
|
309
|
+
getDownloadUrl: (fileId: string) => string;
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
interface PersonaAgentSummary {
|
|
313
|
+
_id: string;
|
|
314
|
+
name: string;
|
|
315
|
+
slug: string;
|
|
316
|
+
description?: string;
|
|
317
|
+
tagline?: string;
|
|
318
|
+
avatar?: string;
|
|
319
|
+
}
|
|
320
|
+
declare function useAgents(autoFetch?: boolean): {
|
|
321
|
+
agents: PersonaAgentSummary[];
|
|
322
|
+
isLoading: boolean;
|
|
323
|
+
error: Error | null;
|
|
324
|
+
refetch: () => Promise<PersonaAgentSummary[]>;
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
interface PersonaHealthInfo {
|
|
328
|
+
status: string;
|
|
329
|
+
version?: string;
|
|
330
|
+
capabilities?: Record<string, boolean>;
|
|
331
|
+
}
|
|
332
|
+
declare function useConnection(autoCheck?: boolean): {
|
|
333
|
+
isConnected: boolean;
|
|
334
|
+
health: PersonaHealthInfo | null;
|
|
335
|
+
isLoading: boolean;
|
|
336
|
+
checkHealth: () => Promise<PersonaHealthInfo | null>;
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
declare const VERSION = "0.2.0";
|
|
340
|
+
|
|
341
|
+
export { type PersonaAgentSummary, type PersonaClarificationQuestion, type PersonaFileItem, type PersonaHealthInfo, type PersonaHitlActionRequest, type PersonaInterrupt, type PersonaMemoryAgentGroup, type PersonaMemoryFile, type PersonaMemoryList, type PersonaMessage, PersonaProvider, type PersonaProviderProps, type PersonaResumeValue, type PersonaRole, type PersonaStreamingEvent, type PersonaSubagentActivityEntry, type PersonaThread, type PersonaToolCall, type SendMessageOverride, type UseChatOptions, VERSION, useAgents, useChat, useConnection, useFiles, useMemory, usePersonaContext, useThreads };
|