@personaai/react 0.8.1 → 0.10.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.d.ts CHANGED
@@ -197,6 +197,12 @@ interface PersonaMemoryList {
197
197
  * and `REASONING_END` rather than `REASONING_MESSAGE_END`).
198
198
  */
199
199
  type PersonaStreamingEvent = {
200
+ type: "RUN_STARTED";
201
+ threadId?: string;
202
+ runId?: string;
203
+ } | {
204
+ type: "RUN_FINISHED";
205
+ } | {
200
206
  type: "TEXT_MESSAGE_CHUNK";
201
207
  delta: string;
202
208
  messageId?: string;
@@ -272,6 +278,29 @@ type PersonaStreamingEvent = {
272
278
  resourceUri: string;
273
279
  mcpId: string;
274
280
  };
281
+ } | {
282
+ type: "CUSTOM";
283
+ name: "workflow_node_started";
284
+ value: {
285
+ nodeId: string;
286
+ nodeType: string;
287
+ nodeLabel: string;
288
+ input?: unknown;
289
+ };
290
+ } | {
291
+ type: "CUSTOM";
292
+ name: "workflow_node_completed";
293
+ value: {
294
+ nodeId: string;
295
+ output: unknown;
296
+ };
297
+ } | {
298
+ type: "CUSTOM";
299
+ name: "workflow_node_failed";
300
+ value: {
301
+ nodeId: string;
302
+ error: string;
303
+ };
275
304
  } | {
276
305
  type: "CUSTOM";
277
306
  name: string & {};
@@ -314,6 +343,28 @@ interface UseChatOptions {
314
343
  */
315
344
  context?: Record<string, unknown> | (() => Record<string, unknown>);
316
345
  }
346
+ interface UseArchitectChatOptions {
347
+ threadId?: string;
348
+ initialMessages?: PersonaMessage[];
349
+ onFinish?: (message: PersonaMessage) => void;
350
+ onError?: (error: Error) => void;
351
+ /** Hook for receiving every low-level AG-UI streaming event (tool calls, steps, subagents) */
352
+ onEvent?: (event: PersonaStreamingEvent) => void;
353
+ /** Called when a fake/ephemeral chat mints a real thread on first send. Use to sync sidebar state (e.g. setThreadId(id)). */
354
+ onThreadCreated?: (threadId: string) => void;
355
+ /** Called when the backend auto-generates a thread title (3-4 word LLM summary of first user message). */
356
+ onTitle?: (title: string) => void;
357
+ }
358
+ interface SendArchitectMessageOverride {
359
+ /**
360
+ * A plain id, or a promise/thunk for one still in flight (e.g. a thread
361
+ * being lazily created for the first message of a new conversation).
362
+ * Mirrors {@link SendMessageOverride.threadId}.
363
+ */
364
+ threadId?: string | Promise<string | undefined>;
365
+ /** Answers/approves a paused interrupt from a previous turn instead of starting a fresh one. */
366
+ resume?: PersonaResumeValue;
367
+ }
317
368
  interface SendMessageOverride {
318
369
  agentId?: string;
319
370
  /**
@@ -426,6 +477,149 @@ interface UseVoiceResult {
426
477
  */
427
478
  updateContext: (context: Record<string, unknown>) => void;
428
479
  }
480
+ type PersonaWorkflowNodeType = "trigger" | "agent" | "tool" | "condition" | "parallel" | "code" | "human_review" | (string & {});
481
+ interface PersonaWorkflowNode {
482
+ id: string;
483
+ type: PersonaWorkflowNodeType;
484
+ position: {
485
+ x: number;
486
+ y: number;
487
+ };
488
+ data: Record<string, unknown>;
489
+ }
490
+ interface PersonaWorkflowEdge {
491
+ id: string;
492
+ source: string;
493
+ target: string;
494
+ sourceHandle?: string;
495
+ targetHandle?: string;
496
+ label?: string;
497
+ }
498
+ interface PersonaWorkflowTrigger {
499
+ type: "manual" | "webhook" | "schedule" | "event" | (string & {});
500
+ config?: Record<string, unknown>;
501
+ }
502
+ interface PersonaWorkflowDraft {
503
+ nodes: PersonaWorkflowNode[];
504
+ edges: PersonaWorkflowEdge[];
505
+ triggers?: PersonaWorkflowTrigger[];
506
+ settings?: Record<string, unknown>;
507
+ }
508
+ interface PersonaWorkflowSummary {
509
+ _id: string;
510
+ name: string;
511
+ slug?: string;
512
+ description?: string;
513
+ status: "draft" | "published" | "archived";
514
+ visibility?: "private" | "public";
515
+ activeVersion?: number;
516
+ tags?: string[];
517
+ createdAt: string;
518
+ updatedAt: string;
519
+ }
520
+ interface PersonaWorkflow extends PersonaWorkflowSummary {
521
+ draft: PersonaWorkflowDraft;
522
+ triggers?: PersonaWorkflowTrigger[];
523
+ ownerId?: string;
524
+ projectId?: string;
525
+ }
526
+ interface PersonaWorkflowVersionSummary {
527
+ _id: string;
528
+ workflowId: string;
529
+ version: number;
530
+ summary?: string;
531
+ createdAt: string;
532
+ }
533
+ interface PersonaWorkflowRunSummary {
534
+ _id: string;
535
+ workflowId: string;
536
+ version: number;
537
+ status: "pending" | "running" | "completed" | "failed" | "cancelled";
538
+ startedAt?: string;
539
+ finishedAt?: string;
540
+ durationMs?: number;
541
+ error?: string;
542
+ isDryRun?: boolean;
543
+ createdAt: string;
544
+ }
545
+ interface PersonaNodeRunState {
546
+ nodeId: string;
547
+ nodeType: string;
548
+ nodeLabel: string;
549
+ status: "idle" | "running" | "completed" | "failed";
550
+ startedAt?: string;
551
+ finishedAt?: string;
552
+ input?: unknown;
553
+ output?: unknown;
554
+ error?: string;
555
+ }
556
+ interface CreateWorkflowInput {
557
+ name: string;
558
+ description?: string;
559
+ slug?: string;
560
+ draft?: PersonaWorkflowDraft;
561
+ triggers?: PersonaWorkflowTrigger[];
562
+ visibility?: "private" | "public";
563
+ tags?: string[];
564
+ }
565
+ type UpdateWorkflowInput = Partial<CreateWorkflowInput>;
566
+ interface UseWorkflowsOptions {
567
+ autoFetch?: boolean;
568
+ search?: string;
569
+ status?: string;
570
+ page?: number;
571
+ limit?: number;
572
+ }
573
+ interface UseWorkflowOptions {
574
+ autoFetch?: boolean;
575
+ }
576
+ interface UseWorkflowStreamOptions {
577
+ workflowId?: string;
578
+ onNodeStarted?: (node: {
579
+ nodeId: string;
580
+ nodeType: string;
581
+ nodeLabel: string;
582
+ input?: unknown;
583
+ }) => void;
584
+ onNodeCompleted?: (node: {
585
+ nodeId: string;
586
+ output: unknown;
587
+ }) => void;
588
+ onNodeFailed?: (node: {
589
+ nodeId: string;
590
+ error: string;
591
+ }) => void;
592
+ onFinish?: (result: {
593
+ runId: string;
594
+ output: unknown;
595
+ text: string;
596
+ }) => void;
597
+ onError?: (error: Error) => void;
598
+ onEvent?: (event: PersonaStreamingEvent) => void;
599
+ }
600
+ interface UseWorkflowStreamResult {
601
+ runId: string | null;
602
+ status: "idle" | "running" | "completed" | "failed" | "cancelled";
603
+ isRunning: boolean;
604
+ activeNodeId: string | null;
605
+ nodeRuns: Record<string, PersonaNodeRunState>;
606
+ text: string;
607
+ output: unknown;
608
+ error: Error | null;
609
+ events: PersonaStreamingEvent[];
610
+ start: (input?: unknown, options?: {
611
+ dryRun?: boolean;
612
+ workflowId?: string;
613
+ }) => Promise<unknown>;
614
+ cancel: () => Promise<void>;
615
+ resume: (runId: string, sinceSeq?: number) => Promise<void>;
616
+ reset: () => void;
617
+ }
618
+ interface UseWorkflowRunsOptions {
619
+ autoFetch?: boolean;
620
+ page?: number;
621
+ limit?: number;
622
+ }
429
623
 
430
624
  interface PersonaContextValue {
431
625
  baseUrl: string;
@@ -466,6 +660,61 @@ declare function useChat(options?: UseChatOptions): {
466
660
  loadThreadMessages: (id: string) => Promise<PersonaMessage[]>;
467
661
  };
468
662
 
663
+ /**
664
+ * The Developer Platform Architect's own reserved Agent id
665
+ * (`DEVELOPER_ARCHITECT_AGENT_ID` in agent-backend/src/modules/agents/
666
+ * architectConstants.js) — it isn't a row in the Agent collection, but the
667
+ * backend's `POST /api/v1/developer/threads` special-cases exactly this id
668
+ * past its usual Agent-existence check (see developerThread.controller.js's
669
+ * `assertAgentAccessible`), so a named Architect Thread can be created the
670
+ * same way as for a real Agent. Kept in sync with that backend constant —
671
+ * update both together if it ever changes.
672
+ */
673
+ declare const ARCHITECT_AGENT_ID = "000000000000000000000002";
674
+ /**
675
+ * Runs the Agent Architect co-pilot — a conversational tool-calling agent
676
+ * that creates/edits the caller's own Agents (`manage_agent`, `manage_skill`,
677
+ * etc.), reached over the runtime's `POST /architect` route (see
678
+ * `@personaai/runtime`'s `routes/architect.ts`). Structurally a trimmed
679
+ * `useChat`: same streaming/interrupt/reload/thread-resume mechanics, but
680
+ * with no `agentId` to pass (the Architect is a single fixed target) and no
681
+ * `voice`/`sandboxCommands` (the Architect has no voice mode and no
682
+ * `execute` tool).
683
+ *
684
+ * `threadId` resume only has an effect when the underlying credential
685
+ * asserts an external user — a bare Project credential has no Subject for a
686
+ * Thread to belong to, so the backend silently keeps its single
687
+ * deterministic per-Project conversation either way (see
688
+ * `developerArchitect.controller.js`'s doc comment).
689
+ */
690
+ declare function useArchitectChat(options?: UseArchitectChatOptions): {
691
+ messages: PersonaMessage[];
692
+ input: string;
693
+ setInput: react.Dispatch<react.SetStateAction<string>>;
694
+ handleInputChange: (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
695
+ handleSubmit: (e?: React.FormEvent) => void;
696
+ sendMessage: (contentToSend?: string, overrideOptions?: SendArchitectMessageOverride) => Promise<boolean>;
697
+ isStreaming: boolean;
698
+ isLoading: boolean;
699
+ isLoadingHistory: boolean;
700
+ error: Error | null;
701
+ interrupt: PersonaInterrupt | null;
702
+ resumeInterrupt: (resume: PersonaResumeValue, displayContent: string) => Promise<boolean>;
703
+ files: Record<string, PersonaWorkspaceFile>;
704
+ todos: PersonaTodo[];
705
+ presentedFile: PersonaPresentedFile | null;
706
+ dismissPresentedFile: () => void;
707
+ openWorkspaceFile: (path: string) => void;
708
+ stop: () => void;
709
+ reload: () => Promise<boolean>;
710
+ clear: () => void;
711
+ startNewChat: () => void;
712
+ currentThreadId: string | undefined;
713
+ isEphemeral: boolean;
714
+ setMessages: react.Dispatch<react.SetStateAction<PersonaMessage[]>>;
715
+ loadThreadMessages: (id: string) => Promise<PersonaMessage[]>;
716
+ };
717
+
469
718
  declare function useMemory(autoFetch?: boolean): {
470
719
  memory: PersonaMemoryList;
471
720
  isLoading: boolean;
@@ -633,6 +882,52 @@ declare function useMcp(options?: UseMcpOptions): {
633
882
  callTool: (name: string, args?: Record<string, unknown>, mcpId?: string) => Promise<any>;
634
883
  };
635
884
 
885
+ interface WorkflowsPagination {
886
+ page: number;
887
+ limit: number;
888
+ total: number;
889
+ totalPages: number;
890
+ }
891
+ declare function useWorkflows(options?: UseWorkflowsOptions | boolean): {
892
+ workflows: PersonaWorkflowSummary[];
893
+ pagination: WorkflowsPagination;
894
+ isLoading: boolean;
895
+ error: Error | null;
896
+ refetch: () => Promise<PersonaWorkflowSummary[]>;
897
+ createWorkflow: (input: CreateWorkflowInput) => Promise<PersonaWorkflow>;
898
+ };
899
+
900
+ declare function useWorkflow(workflowId: string, options?: UseWorkflowOptions | boolean): {
901
+ workflow: PersonaWorkflow | null;
902
+ versions: PersonaWorkflowVersionSummary[];
903
+ mermaid: string | null;
904
+ isLoading: boolean;
905
+ error: Error | null;
906
+ refetch: () => Promise<PersonaWorkflow | null>;
907
+ fetchVersions: () => Promise<PersonaWorkflowVersionSummary[]>;
908
+ fetchMermaid: () => Promise<any>;
909
+ saveDraft: (draft: PersonaWorkflowDraft) => Promise<PersonaWorkflow>;
910
+ publish: (summary?: string) => Promise<PersonaWorkflowVersionSummary>;
911
+ deleteWorkflow: () => Promise<void>;
912
+ };
913
+
914
+ declare function useWorkflowStream(workflowId?: string, options?: UseWorkflowStreamOptions): UseWorkflowStreamResult;
915
+
916
+ declare function useWorkflowRuns(workflowId?: string, options?: UseWorkflowRunsOptions | boolean): {
917
+ runs: PersonaWorkflowRunSummary[];
918
+ pagination: {
919
+ page: number;
920
+ limit: number;
921
+ total: number;
922
+ totalPages: number;
923
+ };
924
+ isLoading: boolean;
925
+ error: Error | null;
926
+ refetch: () => Promise<PersonaWorkflowRunSummary[]>;
927
+ getRun: (runId: string) => Promise<PersonaWorkflowRunSummary>;
928
+ cancelRun: (runId: string) => Promise<void>;
929
+ };
930
+
636
931
  /**
637
932
  * SSE transport for chat streams, with a React Native fallback.
638
933
  *
@@ -671,7 +966,8 @@ interface SSEStream {
671
966
  interface OpenSSEOptions {
672
967
  url: string;
673
968
  headers: Record<string, string>;
674
- body: string;
969
+ body?: string;
970
+ method?: "GET" | "POST";
675
971
  signal?: AbortSignal;
676
972
  }
677
973
  /**
@@ -689,6 +985,6 @@ declare function supportsStreamingFetch(): boolean;
689
985
  */
690
986
  declare function openSSEStream(opts: OpenSSEOptions): Promise<SSEStream>;
691
987
 
692
- declare const VERSION = "0.8.1";
988
+ declare const VERSION = "0.10.0";
693
989
 
694
- 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 };
990
+ export { ARCHITECT_AGENT_ID, type CreateWorkflowInput, 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 PersonaNodeRunState, 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 PersonaWorkflow, type PersonaWorkflowDraft, type PersonaWorkflowEdge, type PersonaWorkflowNode, type PersonaWorkflowNodeType, type PersonaWorkflowRunSummary, type PersonaWorkflowSummary, type PersonaWorkflowTrigger, type PersonaWorkflowVersionSummary, type PersonaWorkspaceFile, type SSEReader, type SSEStream, type SendArchitectMessageOverride, type SendMessageOverride, type UpdateWorkflowInput, type UseArchitectChatOptions, type UseChatOptions, type UseMcpConnectionsOptions, type UseMcpOptions, type UseVoiceOptions, type UseVoiceResult, type UseWorkflowOptions, type UseWorkflowRunsOptions, type UseWorkflowStreamOptions, type UseWorkflowStreamResult, type UseWorkflowsOptions, VERSION, type WorkflowsPagination, openSSEStream, supportsStreamingFetch, useAgents, useArchitectChat, useChat, useConnection, useFiles, useMcp, useMcpConnections, useMemory, usePersonaContext, useThreads, useVoice, useWorkflow, useWorkflowRuns, useWorkflowStream, useWorkflows };