@personaai/react 0.10.0 → 0.11.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.js CHANGED
@@ -2453,20 +2453,38 @@ function useFiles(autoFetch = true) {
2453
2453
 
2454
2454
  // src/hooks/useAgents.ts
2455
2455
  import { useCallback as useCallback7, useEffect as useEffect7, useState as useState7 } from "react";
2456
- function useAgents(autoFetch = true) {
2456
+ function useAgents(options = true) {
2457
+ const opts = typeof options === "boolean" ? { autoFetch: options } : options;
2458
+ const { autoFetch = true, page, limit, search, category, scope } = opts;
2457
2459
  const { fetchWithAuth } = usePersonaContext();
2458
2460
  const [agents, setAgents] = useState7([]);
2461
+ const [pagination, setPagination] = useState7({
2462
+ total: 0,
2463
+ page: page ?? 1,
2464
+ limit: limit ?? 20,
2465
+ pages: 0
2466
+ });
2459
2467
  const [isLoading, setIsLoading] = useState7(false);
2460
2468
  const [error, setError] = useState7(null);
2461
2469
  const fetchAgents = useCallback7(async () => {
2462
2470
  setIsLoading(true);
2463
2471
  setError(null);
2464
2472
  try {
2465
- const res = await fetchWithAuth("/agents");
2473
+ const query = new URLSearchParams();
2474
+ if (page) query.set("page", String(page));
2475
+ if (limit) query.set("limit", String(limit));
2476
+ if (search) query.set("search", search);
2477
+ if (category) query.set("category", category);
2478
+ if (scope) query.set("scope", scope);
2479
+ const queryStr = query.toString() ? `?${query.toString()}` : "";
2480
+ const res = await fetchWithAuth(`/agents${queryStr}`);
2466
2481
  if (!res.ok) throw new Error(`Failed to list agents: ${res.statusText}`);
2467
2482
  const data = await res.json();
2468
- const items = Array.isArray(data) ? data : data?.items || data?.agents || [];
2483
+ const items = Array.isArray(data) ? data : data?.items ?? [];
2469
2484
  setAgents(items);
2485
+ setPagination(
2486
+ data?.pagination ?? { total: items.length, page: 1, limit: items.length, pages: 1 }
2487
+ );
2470
2488
  return items;
2471
2489
  } catch (err) {
2472
2490
  const errorObj = err instanceof Error ? err : new Error(String(err));
@@ -2475,17 +2493,120 @@ function useAgents(autoFetch = true) {
2475
2493
  } finally {
2476
2494
  setIsLoading(false);
2477
2495
  }
2478
- }, [fetchWithAuth]);
2496
+ }, [fetchWithAuth, page, limit, search, category, scope]);
2497
+ const getAgent = useCallback7(
2498
+ async (agentId) => {
2499
+ const res = await fetchWithAuth(`/agents/${agentId}`);
2500
+ if (!res.ok) throw new Error(`Failed to fetch agent: ${res.statusText}`);
2501
+ return res.json();
2502
+ },
2503
+ [fetchWithAuth]
2504
+ );
2505
+ const createAgent = useCallback7(
2506
+ async (input) => {
2507
+ setError(null);
2508
+ try {
2509
+ const res = await fetchWithAuth("/agents", {
2510
+ method: "POST",
2511
+ headers: { "Content-Type": "application/json" },
2512
+ body: JSON.stringify(input)
2513
+ });
2514
+ if (!res.ok) {
2515
+ const errText = await res.text().catch(() => res.statusText);
2516
+ throw new Error(`Failed to create agent (${res.status}): ${errText}`);
2517
+ }
2518
+ const created = await res.json();
2519
+ setAgents((prev) => [created, ...prev]);
2520
+ return created;
2521
+ } catch (err) {
2522
+ const errorObj = err instanceof Error ? err : new Error(String(err));
2523
+ setError(errorObj);
2524
+ throw errorObj;
2525
+ }
2526
+ },
2527
+ [fetchWithAuth]
2528
+ );
2529
+ const updateAgent = useCallback7(
2530
+ async (agentId, input) => {
2531
+ setError(null);
2532
+ try {
2533
+ const res = await fetchWithAuth(`/agents/${agentId}`, {
2534
+ method: "PATCH",
2535
+ headers: { "Content-Type": "application/json" },
2536
+ body: JSON.stringify(input)
2537
+ });
2538
+ if (!res.ok) {
2539
+ const errText = await res.text().catch(() => res.statusText);
2540
+ throw new Error(`Failed to update agent (${res.status}): ${errText}`);
2541
+ }
2542
+ const updated = await res.json();
2543
+ setAgents((prev) => prev.map((a) => a._id === agentId ? updated : a));
2544
+ return updated;
2545
+ } catch (err) {
2546
+ const errorObj = err instanceof Error ? err : new Error(String(err));
2547
+ setError(errorObj);
2548
+ throw errorObj;
2549
+ }
2550
+ },
2551
+ [fetchWithAuth]
2552
+ );
2553
+ const deleteAgent = useCallback7(
2554
+ async (agentId) => {
2555
+ setError(null);
2556
+ try {
2557
+ const res = await fetchWithAuth(`/agents/${agentId}`, { method: "DELETE" });
2558
+ if (!res.ok) {
2559
+ const errText = await res.text().catch(() => res.statusText);
2560
+ throw new Error(`Failed to delete agent (${res.status}): ${errText}`);
2561
+ }
2562
+ setAgents((prev) => prev.filter((a) => a._id !== agentId));
2563
+ } catch (err) {
2564
+ const errorObj = err instanceof Error ? err : new Error(String(err));
2565
+ setError(errorObj);
2566
+ throw errorObj;
2567
+ }
2568
+ },
2569
+ [fetchWithAuth]
2570
+ );
2571
+ const bulkDeleteAgents = useCallback7(
2572
+ async (ids) => {
2573
+ setError(null);
2574
+ try {
2575
+ const res = await fetchWithAuth("/agents/bulk-delete", {
2576
+ method: "POST",
2577
+ headers: { "Content-Type": "application/json" },
2578
+ body: JSON.stringify({ ids })
2579
+ });
2580
+ if (!res.ok) {
2581
+ const errText = await res.text().catch(() => res.statusText);
2582
+ throw new Error(`Failed to bulk-delete agents (${res.status}): ${errText}`);
2583
+ }
2584
+ const result = await res.json();
2585
+ const deletedSet = new Set(result.deleted);
2586
+ setAgents((prev) => prev.filter((a) => !deletedSet.has(a._id)));
2587
+ return result;
2588
+ } catch (err) {
2589
+ const errorObj = err instanceof Error ? err : new Error(String(err));
2590
+ setError(errorObj);
2591
+ throw errorObj;
2592
+ }
2593
+ },
2594
+ [fetchWithAuth]
2595
+ );
2479
2596
  useEffect7(() => {
2480
- if (autoFetch) {
2481
- void fetchAgents();
2482
- }
2597
+ if (autoFetch) void fetchAgents();
2483
2598
  }, [autoFetch, fetchAgents]);
2484
2599
  return {
2485
2600
  agents,
2601
+ pagination,
2486
2602
  isLoading,
2487
2603
  error,
2488
- refetch: fetchAgents
2604
+ refetch: fetchAgents,
2605
+ getAgent,
2606
+ createAgent,
2607
+ updateAgent,
2608
+ deleteAgent,
2609
+ bulkDeleteAgents
2489
2610
  };
2490
2611
  }
2491
2612
 
@@ -2561,6 +2682,33 @@ function useMcpConnections(options = {}) {
2561
2682
  setIsLoading(false);
2562
2683
  }
2563
2684
  }, [agentId, fetchWithAuth, options.returnTo]);
2685
+ const [isDisconnecting, setIsDisconnecting] = useState9(false);
2686
+ const disconnect = useCallback9(
2687
+ async (mcpId) => {
2688
+ setIsDisconnecting(true);
2689
+ setError(null);
2690
+ try {
2691
+ const res = await fetchWithAuth(`/mcps/${mcpId}/oauth/user/connection`, {
2692
+ method: "DELETE"
2693
+ });
2694
+ if (!res.ok)
2695
+ throw new Error(`Failed to disconnect MCP: ${res.statusText}`);
2696
+ setConnections(
2697
+ (prev) => prev.map(
2698
+ (c) => c.mcpId === mcpId ? { ...c, connected: false, authorizeUrl: null } : c
2699
+ )
2700
+ );
2701
+ void fetchConnections();
2702
+ } catch (err) {
2703
+ const errorObj = err instanceof Error ? err : new Error(String(err));
2704
+ setError(errorObj);
2705
+ throw errorObj;
2706
+ } finally {
2707
+ setIsDisconnecting(false);
2708
+ }
2709
+ },
2710
+ [fetchWithAuth, fetchConnections]
2711
+ );
2564
2712
  useEffect9(() => {
2565
2713
  if (autoFetch) void fetchConnections();
2566
2714
  }, [autoFetch, fetchConnections]);
@@ -2570,7 +2718,9 @@ function useMcpConnections(options = {}) {
2570
2718
  unconnected: connections.filter((c) => !c.connected),
2571
2719
  isLoading,
2572
2720
  error,
2573
- refetch: fetchConnections
2721
+ refetch: fetchConnections,
2722
+ disconnect,
2723
+ isDisconnecting
2574
2724
  };
2575
2725
  }
2576
2726
 
@@ -2615,22 +2765,378 @@ function useMcp(options = {}) {
2615
2765
  };
2616
2766
  }
2617
2767
 
2618
- // src/hooks/useWorkflows.ts
2768
+ // src/hooks/useSkills.ts
2619
2769
  import { useCallback as useCallback11, useEffect as useEffect10, useState as useState10 } from "react";
2770
+ function useSkills(options = {}) {
2771
+ const { autoFetch = true, page, limit, search, scope } = options;
2772
+ const { fetchWithAuth } = usePersonaContext();
2773
+ const [skills, setSkills] = useState10([]);
2774
+ const [pagination, setPagination] = useState10({
2775
+ total: 0,
2776
+ page: page ?? 1,
2777
+ limit: limit ?? 20,
2778
+ pages: 0
2779
+ });
2780
+ const [isLoading, setIsLoading] = useState10(false);
2781
+ const [error, setError] = useState10(null);
2782
+ const fetchSkills = useCallback11(async () => {
2783
+ setIsLoading(true);
2784
+ setError(null);
2785
+ try {
2786
+ const query = new URLSearchParams();
2787
+ if (page) query.set("page", String(page));
2788
+ if (limit) query.set("limit", String(limit));
2789
+ if (search) query.set("search", search);
2790
+ if (scope) query.set("scope", scope);
2791
+ const queryStr = query.toString() ? `?${query.toString()}` : "";
2792
+ const res = await fetchWithAuth(`/skills${queryStr}`);
2793
+ if (!res.ok) throw new Error(`Failed to list skills: ${res.statusText}`);
2794
+ const data = await res.json();
2795
+ const items = Array.isArray(data) ? data : data?.items ?? [];
2796
+ setSkills(items);
2797
+ setPagination(
2798
+ data?.pagination ?? { total: items.length, page: 1, limit: items.length, pages: 1 }
2799
+ );
2800
+ return items;
2801
+ } catch (err) {
2802
+ const errorObj = err instanceof Error ? err : new Error(String(err));
2803
+ setError(errorObj);
2804
+ return [];
2805
+ } finally {
2806
+ setIsLoading(false);
2807
+ }
2808
+ }, [fetchWithAuth, page, limit, search, scope]);
2809
+ const getSkill = useCallback11(
2810
+ async (skillId) => {
2811
+ const res = await fetchWithAuth(`/skills/${skillId}`);
2812
+ if (!res.ok) throw new Error(`Failed to fetch skill: ${res.statusText}`);
2813
+ return res.json();
2814
+ },
2815
+ [fetchWithAuth]
2816
+ );
2817
+ const createSkill = useCallback11(
2818
+ async (input) => {
2819
+ setError(null);
2820
+ try {
2821
+ const res = await fetchWithAuth("/skills", {
2822
+ method: "POST",
2823
+ headers: { "Content-Type": "application/json" },
2824
+ body: JSON.stringify(input)
2825
+ });
2826
+ if (!res.ok) {
2827
+ const errText = await res.text().catch(() => res.statusText);
2828
+ throw new Error(`Failed to create skill (${res.status}): ${errText}`);
2829
+ }
2830
+ const created = await res.json();
2831
+ setSkills((prev) => [created, ...prev]);
2832
+ return created;
2833
+ } catch (err) {
2834
+ const errorObj = err instanceof Error ? err : new Error(String(err));
2835
+ setError(errorObj);
2836
+ throw errorObj;
2837
+ }
2838
+ },
2839
+ [fetchWithAuth]
2840
+ );
2841
+ const updateSkill = useCallback11(
2842
+ async (skillId, input) => {
2843
+ setError(null);
2844
+ try {
2845
+ const res = await fetchWithAuth(`/skills/${skillId}`, {
2846
+ method: "PATCH",
2847
+ headers: { "Content-Type": "application/json" },
2848
+ body: JSON.stringify(input)
2849
+ });
2850
+ if (!res.ok) {
2851
+ const errText = await res.text().catch(() => res.statusText);
2852
+ throw new Error(`Failed to update skill (${res.status}): ${errText}`);
2853
+ }
2854
+ const updated = await res.json();
2855
+ setSkills((prev) => prev.map((s) => s._id === skillId ? updated : s));
2856
+ return updated;
2857
+ } catch (err) {
2858
+ const errorObj = err instanceof Error ? err : new Error(String(err));
2859
+ setError(errorObj);
2860
+ throw errorObj;
2861
+ }
2862
+ },
2863
+ [fetchWithAuth]
2864
+ );
2865
+ const deleteSkill = useCallback11(
2866
+ async (skillId) => {
2867
+ setError(null);
2868
+ try {
2869
+ const res = await fetchWithAuth(`/skills/${skillId}`, { method: "DELETE" });
2870
+ if (!res.ok) {
2871
+ const errText = await res.text().catch(() => res.statusText);
2872
+ throw new Error(`Failed to delete skill (${res.status}): ${errText}`);
2873
+ }
2874
+ setSkills((prev) => prev.filter((s) => s._id !== skillId));
2875
+ } catch (err) {
2876
+ const errorObj = err instanceof Error ? err : new Error(String(err));
2877
+ setError(errorObj);
2878
+ throw errorObj;
2879
+ }
2880
+ },
2881
+ [fetchWithAuth]
2882
+ );
2883
+ const bulkDeleteSkills = useCallback11(
2884
+ async (ids) => {
2885
+ setError(null);
2886
+ try {
2887
+ const res = await fetchWithAuth("/skills/bulk-delete", {
2888
+ method: "POST",
2889
+ headers: { "Content-Type": "application/json" },
2890
+ body: JSON.stringify({ ids })
2891
+ });
2892
+ if (!res.ok) {
2893
+ const errText = await res.text().catch(() => res.statusText);
2894
+ throw new Error(`Failed to bulk-delete skills (${res.status}): ${errText}`);
2895
+ }
2896
+ const result = await res.json();
2897
+ const deletedSet = new Set(result.deleted);
2898
+ setSkills((prev) => prev.filter((s) => !deletedSet.has(s._id)));
2899
+ return result;
2900
+ } catch (err) {
2901
+ const errorObj = err instanceof Error ? err : new Error(String(err));
2902
+ setError(errorObj);
2903
+ throw errorObj;
2904
+ }
2905
+ },
2906
+ [fetchWithAuth]
2907
+ );
2908
+ const getSkillUsage = useCallback11(
2909
+ async (skillId) => {
2910
+ const res = await fetchWithAuth(`/skills/${skillId}/usage`);
2911
+ if (!res.ok) throw new Error(`Failed to fetch skill usage: ${res.statusText}`);
2912
+ return res.json();
2913
+ },
2914
+ [fetchWithAuth]
2915
+ );
2916
+ useEffect10(() => {
2917
+ if (autoFetch) void fetchSkills();
2918
+ }, [autoFetch, fetchSkills]);
2919
+ return {
2920
+ skills,
2921
+ pagination,
2922
+ isLoading,
2923
+ error,
2924
+ refetch: fetchSkills,
2925
+ getSkill,
2926
+ createSkill,
2927
+ updateSkill,
2928
+ deleteSkill,
2929
+ bulkDeleteSkills,
2930
+ getSkillUsage
2931
+ };
2932
+ }
2933
+
2934
+ // src/hooks/useRcpSources.ts
2935
+ import { useCallback as useCallback12, useEffect as useEffect11, useState as useState11 } from "react";
2936
+ function useRcpSources(options = {}) {
2937
+ const { autoFetch = true, page, limit, search } = options;
2938
+ const { fetchWithAuth } = usePersonaContext();
2939
+ const [rcpSources, setRcpSources] = useState11([]);
2940
+ const [pagination, setPagination] = useState11({
2941
+ total: 0,
2942
+ page: page ?? 1,
2943
+ limit: limit ?? 20,
2944
+ pages: 0
2945
+ });
2946
+ const [isLoading, setIsLoading] = useState11(false);
2947
+ const [error, setError] = useState11(null);
2948
+ const fetchRcpSources = useCallback12(async () => {
2949
+ setIsLoading(true);
2950
+ setError(null);
2951
+ try {
2952
+ const query = new URLSearchParams();
2953
+ if (page) query.set("page", String(page));
2954
+ if (limit) query.set("limit", String(limit));
2955
+ if (search) query.set("search", search);
2956
+ const queryStr = query.toString() ? `?${query.toString()}` : "";
2957
+ const res = await fetchWithAuth(`/rcp-sources${queryStr}`);
2958
+ if (!res.ok) throw new Error(`Failed to list RCP sources: ${res.statusText}`);
2959
+ const data = await res.json();
2960
+ const items = Array.isArray(data) ? data : data?.items ?? [];
2961
+ setRcpSources(items);
2962
+ setPagination(
2963
+ data?.pagination ?? { total: items.length, page: 1, limit: items.length, pages: 1 }
2964
+ );
2965
+ return items;
2966
+ } catch (err) {
2967
+ const errorObj = err instanceof Error ? err : new Error(String(err));
2968
+ setError(errorObj);
2969
+ return [];
2970
+ } finally {
2971
+ setIsLoading(false);
2972
+ }
2973
+ }, [fetchWithAuth, page, limit, search]);
2974
+ const getRcpSource = useCallback12(
2975
+ async (sourceId) => {
2976
+ const res = await fetchWithAuth(`/rcp-sources/${sourceId}`);
2977
+ if (!res.ok) throw new Error(`Failed to fetch RCP source: ${res.statusText}`);
2978
+ return res.json();
2979
+ },
2980
+ [fetchWithAuth]
2981
+ );
2982
+ const createRcpSource = useCallback12(
2983
+ async (input) => {
2984
+ setError(null);
2985
+ try {
2986
+ const res = await fetchWithAuth("/rcp-sources", {
2987
+ method: "POST",
2988
+ headers: { "Content-Type": "application/json" },
2989
+ body: JSON.stringify(input)
2990
+ });
2991
+ if (!res.ok) {
2992
+ const errText = await res.text().catch(() => res.statusText);
2993
+ throw new Error(`Failed to create RCP source (${res.status}): ${errText}`);
2994
+ }
2995
+ const created = await res.json();
2996
+ setRcpSources((prev) => [created, ...prev]);
2997
+ return created;
2998
+ } catch (err) {
2999
+ const errorObj = err instanceof Error ? err : new Error(String(err));
3000
+ setError(errorObj);
3001
+ throw errorObj;
3002
+ }
3003
+ },
3004
+ [fetchWithAuth]
3005
+ );
3006
+ const updateRcpSource = useCallback12(
3007
+ async (sourceId, input) => {
3008
+ setError(null);
3009
+ try {
3010
+ const res = await fetchWithAuth(`/rcp-sources/${sourceId}`, {
3011
+ method: "PATCH",
3012
+ headers: { "Content-Type": "application/json" },
3013
+ body: JSON.stringify(input)
3014
+ });
3015
+ if (!res.ok) {
3016
+ const errText = await res.text().catch(() => res.statusText);
3017
+ throw new Error(`Failed to update RCP source (${res.status}): ${errText}`);
3018
+ }
3019
+ const updated = await res.json();
3020
+ setRcpSources((prev) => prev.map((s) => s._id === sourceId ? updated : s));
3021
+ return updated;
3022
+ } catch (err) {
3023
+ const errorObj = err instanceof Error ? err : new Error(String(err));
3024
+ setError(errorObj);
3025
+ throw errorObj;
3026
+ }
3027
+ },
3028
+ [fetchWithAuth]
3029
+ );
3030
+ const deleteRcpSource = useCallback12(
3031
+ async (sourceId) => {
3032
+ setError(null);
3033
+ try {
3034
+ const res = await fetchWithAuth(`/rcp-sources/${sourceId}`, { method: "DELETE" });
3035
+ if (!res.ok) {
3036
+ const errText = await res.text().catch(() => res.statusText);
3037
+ throw new Error(`Failed to delete RCP source (${res.status}): ${errText}`);
3038
+ }
3039
+ setRcpSources((prev) => prev.filter((s) => s._id !== sourceId));
3040
+ } catch (err) {
3041
+ const errorObj = err instanceof Error ? err : new Error(String(err));
3042
+ setError(errorObj);
3043
+ throw errorObj;
3044
+ }
3045
+ },
3046
+ [fetchWithAuth]
3047
+ );
3048
+ const bulkDeleteRcpSources = useCallback12(
3049
+ async (ids) => {
3050
+ setError(null);
3051
+ try {
3052
+ const res = await fetchWithAuth("/rcp-sources/bulk-delete", {
3053
+ method: "POST",
3054
+ headers: { "Content-Type": "application/json" },
3055
+ body: JSON.stringify({ ids })
3056
+ });
3057
+ if (!res.ok) {
3058
+ const errText = await res.text().catch(() => res.statusText);
3059
+ throw new Error(`Failed to bulk-delete RCP sources (${res.status}): ${errText}`);
3060
+ }
3061
+ const result = await res.json();
3062
+ const deletedSet = new Set(result.deleted);
3063
+ setRcpSources((prev) => prev.filter((s) => !deletedSet.has(s._id)));
3064
+ return result;
3065
+ } catch (err) {
3066
+ const errorObj = err instanceof Error ? err : new Error(String(err));
3067
+ setError(errorObj);
3068
+ throw errorObj;
3069
+ }
3070
+ },
3071
+ [fetchWithAuth]
3072
+ );
3073
+ const getRcpSourceUsage = useCallback12(
3074
+ async (sourceId) => {
3075
+ const res = await fetchWithAuth(`/rcp-sources/${sourceId}/usage`);
3076
+ if (!res.ok) throw new Error(`Failed to fetch RCP source usage: ${res.statusText}`);
3077
+ return res.json();
3078
+ },
3079
+ [fetchWithAuth]
3080
+ );
3081
+ const testRcpSourceConnection = useCallback12(
3082
+ async (sourceId) => {
3083
+ setError(null);
3084
+ try {
3085
+ const res = await fetchWithAuth(`/rcp-sources/${sourceId}/test`, { method: "POST" });
3086
+ if (!res.ok) {
3087
+ const errText = await res.text().catch(() => res.statusText);
3088
+ throw new Error(`Failed to test RCP source connection (${res.status}): ${errText}`);
3089
+ }
3090
+ const result = await res.json();
3091
+ setRcpSources(
3092
+ (prev) => prev.map(
3093
+ (s) => s._id === sourceId ? { ...s, tools: result.tools, lastTestedAt: (/* @__PURE__ */ new Date()).toISOString() } : s
3094
+ )
3095
+ );
3096
+ return result;
3097
+ } catch (err) {
3098
+ const errorObj = err instanceof Error ? err : new Error(String(err));
3099
+ setError(errorObj);
3100
+ throw errorObj;
3101
+ }
3102
+ },
3103
+ [fetchWithAuth]
3104
+ );
3105
+ useEffect11(() => {
3106
+ if (autoFetch) void fetchRcpSources();
3107
+ }, [autoFetch, fetchRcpSources]);
3108
+ return {
3109
+ rcpSources,
3110
+ pagination,
3111
+ isLoading,
3112
+ error,
3113
+ refetch: fetchRcpSources,
3114
+ getRcpSource,
3115
+ createRcpSource,
3116
+ updateRcpSource,
3117
+ deleteRcpSource,
3118
+ bulkDeleteRcpSources,
3119
+ getRcpSourceUsage,
3120
+ testRcpSourceConnection
3121
+ };
3122
+ }
3123
+
3124
+ // src/hooks/useWorkflows.ts
3125
+ import { useCallback as useCallback13, useEffect as useEffect12, useState as useState12 } from "react";
2620
3126
  function useWorkflows(options) {
2621
3127
  const opts = typeof options === "boolean" ? { autoFetch: options } : options ?? {};
2622
3128
  const { autoFetch = true, search, status, page, limit } = opts;
2623
3129
  const { fetchWithAuth } = usePersonaContext();
2624
- const [workflows, setWorkflows] = useState10([]);
2625
- const [pagination, setPagination] = useState10({
3130
+ const [workflows, setWorkflows] = useState12([]);
3131
+ const [pagination, setPagination] = useState12({
2626
3132
  page: page ?? 1,
2627
3133
  limit: limit ?? 20,
2628
3134
  total: 0,
2629
3135
  totalPages: 0
2630
3136
  });
2631
- const [isLoading, setIsLoading] = useState10(false);
2632
- const [error, setError] = useState10(null);
2633
- const fetchWorkflows = useCallback11(async () => {
3137
+ const [isLoading, setIsLoading] = useState12(false);
3138
+ const [error, setError] = useState12(null);
3139
+ const fetchWorkflows = useCallback13(async () => {
2634
3140
  setIsLoading(true);
2635
3141
  setError(null);
2636
3142
  try {
@@ -2652,7 +3158,10 @@ function useWorkflows(options) {
2652
3158
  page: data.pagination.page ?? 1,
2653
3159
  limit: data.pagination.limit ?? items.length,
2654
3160
  total: data.pagination.total ?? items.length,
2655
- totalPages: data.pagination.totalPages ?? 1
3161
+ // Backend's paginationEnvelope() names this field `pages`, not
3162
+ // `totalPages` — this used to always fall through to the `?? 1`
3163
+ // default.
3164
+ totalPages: data.pagination.pages ?? 1
2656
3165
  });
2657
3166
  } else {
2658
3167
  setPagination({
@@ -2671,7 +3180,7 @@ function useWorkflows(options) {
2671
3180
  setIsLoading(false);
2672
3181
  }
2673
3182
  }, [fetchWithAuth, search, status, page, limit]);
2674
- const createWorkflow = useCallback11(
3183
+ const createWorkflow = useCallback13(
2675
3184
  async (input) => {
2676
3185
  setError(null);
2677
3186
  try {
@@ -2695,7 +3204,7 @@ function useWorkflows(options) {
2695
3204
  },
2696
3205
  [fetchWithAuth]
2697
3206
  );
2698
- useEffect10(() => {
3207
+ useEffect12(() => {
2699
3208
  if (autoFetch) {
2700
3209
  void fetchWorkflows();
2701
3210
  }
@@ -2711,17 +3220,17 @@ function useWorkflows(options) {
2711
3220
  }
2712
3221
 
2713
3222
  // src/hooks/useWorkflow.ts
2714
- import { useCallback as useCallback12, useEffect as useEffect11, useState as useState11 } from "react";
3223
+ import { useCallback as useCallback14, useEffect as useEffect13, useState as useState13 } from "react";
2715
3224
  function useWorkflow(workflowId, options) {
2716
3225
  const opts = typeof options === "boolean" ? { autoFetch: options } : options ?? {};
2717
3226
  const { autoFetch = true } = opts;
2718
3227
  const { fetchWithAuth } = usePersonaContext();
2719
- const [workflow, setWorkflow] = useState11(null);
2720
- const [versions, setVersions] = useState11([]);
2721
- const [mermaid, setMermaid] = useState11(null);
2722
- const [isLoading, setIsLoading] = useState11(false);
2723
- const [error, setError] = useState11(null);
2724
- const fetchWorkflow = useCallback12(async () => {
3228
+ const [workflow, setWorkflow] = useState13(null);
3229
+ const [versions, setVersions] = useState13([]);
3230
+ const [mermaid, setMermaid] = useState13(null);
3231
+ const [isLoading, setIsLoading] = useState13(false);
3232
+ const [error, setError] = useState13(null);
3233
+ const fetchWorkflow = useCallback14(async () => {
2725
3234
  if (!workflowId) return null;
2726
3235
  setIsLoading(true);
2727
3236
  setError(null);
@@ -2741,7 +3250,7 @@ function useWorkflow(workflowId, options) {
2741
3250
  setIsLoading(false);
2742
3251
  }
2743
3252
  }, [fetchWithAuth, workflowId]);
2744
- const fetchVersions = useCallback12(async () => {
3253
+ const fetchVersions = useCallback14(async () => {
2745
3254
  if (!workflowId) return [];
2746
3255
  try {
2747
3256
  const res = await fetchWithAuth(`/workflows/${workflowId}/versions`);
@@ -2754,7 +3263,7 @@ function useWorkflow(workflowId, options) {
2754
3263
  return [];
2755
3264
  }
2756
3265
  }, [fetchWithAuth, workflowId]);
2757
- const fetchMermaid = useCallback12(async () => {
3266
+ const fetchMermaid = useCallback14(async () => {
2758
3267
  if (!workflowId) return "";
2759
3268
  try {
2760
3269
  const res = await fetchWithAuth(`/workflows/${workflowId}/mermaid`);
@@ -2767,7 +3276,7 @@ function useWorkflow(workflowId, options) {
2767
3276
  return "";
2768
3277
  }
2769
3278
  }, [fetchWithAuth, workflowId]);
2770
- const saveDraft = useCallback12(
3279
+ const saveDraft = useCallback14(
2771
3280
  async (draft) => {
2772
3281
  if (!workflowId) throw new Error("Workflow ID is required");
2773
3282
  setError(null);
@@ -2786,7 +3295,7 @@ function useWorkflow(workflowId, options) {
2786
3295
  },
2787
3296
  [fetchWithAuth, workflowId]
2788
3297
  );
2789
- const publish = useCallback12(
3298
+ const publish = useCallback14(
2790
3299
  async (summary) => {
2791
3300
  if (!workflowId) throw new Error("Workflow ID is required");
2792
3301
  setError(null);
@@ -2806,7 +3315,7 @@ function useWorkflow(workflowId, options) {
2806
3315
  },
2807
3316
  [fetchWithAuth, workflowId, fetchWorkflow, fetchVersions]
2808
3317
  );
2809
- const deleteWorkflow = useCallback12(async () => {
3318
+ const deleteWorkflow = useCallback14(async () => {
2810
3319
  if (!workflowId) throw new Error("Workflow ID is required");
2811
3320
  setError(null);
2812
3321
  const res = await fetchWithAuth(`/workflows/${workflowId}`, {
@@ -2817,7 +3326,7 @@ function useWorkflow(workflowId, options) {
2817
3326
  }
2818
3327
  setWorkflow(null);
2819
3328
  }, [fetchWithAuth, workflowId]);
2820
- useEffect11(() => {
3329
+ useEffect13(() => {
2821
3330
  if (autoFetch && workflowId) {
2822
3331
  void fetchWorkflow();
2823
3332
  }
@@ -2838,25 +3347,25 @@ function useWorkflow(workflowId, options) {
2838
3347
  }
2839
3348
 
2840
3349
  // src/hooks/useWorkflowStream.ts
2841
- import { useCallback as useCallback13, useEffect as useEffect12, useRef as useRef4, useState as useState12 } from "react";
3350
+ import { useCallback as useCallback15, useEffect as useEffect14, useRef as useRef4, useState as useState14 } from "react";
2842
3351
  function useWorkflowStream(workflowId, options) {
2843
3352
  const { baseUrl, getAuthToken, fetchWithAuth, logger } = usePersonaContext();
2844
- const [status, setStatus] = useState12("idle");
2845
- const [runId, setRunId] = useState12(null);
2846
- const [activeNodeId, setActiveNodeId] = useState12(null);
2847
- const [nodeRuns, setNodeRuns] = useState12(
3353
+ const [status, setStatus] = useState14("idle");
3354
+ const [runId, setRunId] = useState14(null);
3355
+ const [activeNodeId, setActiveNodeId] = useState14(null);
3356
+ const [nodeRuns, setNodeRuns] = useState14(
2848
3357
  {}
2849
3358
  );
2850
- const [text, setText] = useState12("");
2851
- const [output, setOutput] = useState12(null);
2852
- const [error, setError] = useState12(null);
2853
- const [events, setEvents] = useState12([]);
3359
+ const [text, setText] = useState14("");
3360
+ const [output, setOutput] = useState14(null);
3361
+ const [error, setError] = useState14(null);
3362
+ const [events, setEvents] = useState14([]);
2854
3363
  const abortControllerRef = useRef4(null);
2855
3364
  const currentRunIdRef = useRef4(null);
2856
3365
  currentRunIdRef.current = runId;
2857
3366
  const optionsRef = useRef4(options);
2858
3367
  optionsRef.current = options;
2859
- const cancel = useCallback13(async () => {
3368
+ const cancel = useCallback15(async () => {
2860
3369
  if (abortControllerRef.current) {
2861
3370
  abortControllerRef.current.abort();
2862
3371
  abortControllerRef.current = null;
@@ -2877,7 +3386,7 @@ function useWorkflowStream(workflowId, options) {
2877
3386
  setStatus("cancelled");
2878
3387
  setActiveNodeId(null);
2879
3388
  }, [fetchWithAuth, logger]);
2880
- const reset = useCallback13(() => {
3389
+ const reset = useCallback15(() => {
2881
3390
  if (abortControllerRef.current) {
2882
3391
  abortControllerRef.current.abort();
2883
3392
  abortControllerRef.current = null;
@@ -2891,7 +3400,7 @@ function useWorkflowStream(workflowId, options) {
2891
3400
  setError(null);
2892
3401
  setEvents([]);
2893
3402
  }, []);
2894
- const processStream = useCallback13(
3403
+ const processStream = useCallback15(
2895
3404
  async (url, method, body, targetRunId) => {
2896
3405
  if (abortControllerRef.current) {
2897
3406
  abortControllerRef.current.abort();
@@ -3056,7 +3565,7 @@ function useWorkflowStream(workflowId, options) {
3056
3565
  },
3057
3566
  [getAuthToken]
3058
3567
  );
3059
- const start = useCallback13(
3568
+ const start = useCallback15(
3060
3569
  async (input, opts) => {
3061
3570
  const targetWfId = opts?.workflowId || workflowId;
3062
3571
  if (!targetWfId) {
@@ -3077,7 +3586,7 @@ function useWorkflowStream(workflowId, options) {
3077
3586
  },
3078
3587
  [workflowId, baseUrl, processStream]
3079
3588
  );
3080
- const resume = useCallback13(
3589
+ const resume = useCallback15(
3081
3590
  async (targetRunId, sinceSeq) => {
3082
3591
  if (!targetRunId) {
3083
3592
  throw new Error("Run ID is required to resume stream");
@@ -3090,7 +3599,7 @@ function useWorkflowStream(workflowId, options) {
3090
3599
  },
3091
3600
  [baseUrl, processStream]
3092
3601
  );
3093
- useEffect12(() => {
3602
+ useEffect14(() => {
3094
3603
  return () => {
3095
3604
  if (abortControllerRef.current) {
3096
3605
  abortControllerRef.current.abort();
@@ -3115,21 +3624,21 @@ function useWorkflowStream(workflowId, options) {
3115
3624
  }
3116
3625
 
3117
3626
  // src/hooks/useWorkflowRuns.ts
3118
- import { useCallback as useCallback14, useEffect as useEffect13, useState as useState13 } from "react";
3627
+ import { useCallback as useCallback16, useEffect as useEffect15, useState as useState15 } from "react";
3119
3628
  function useWorkflowRuns(workflowId, options) {
3120
3629
  const opts = typeof options === "boolean" ? { autoFetch: options } : options ?? {};
3121
3630
  const { autoFetch = true, page = 1, limit = 20 } = opts;
3122
3631
  const { fetchWithAuth } = usePersonaContext();
3123
- const [runs, setRuns] = useState13([]);
3124
- const [pagination, setPagination] = useState13({
3632
+ const [runs, setRuns] = useState15([]);
3633
+ const [pagination, setPagination] = useState15({
3125
3634
  page,
3126
3635
  limit,
3127
3636
  total: 0,
3128
3637
  totalPages: 0
3129
3638
  });
3130
- const [isLoading, setIsLoading] = useState13(false);
3131
- const [error, setError] = useState13(null);
3132
- const fetchRuns = useCallback14(async () => {
3639
+ const [isLoading, setIsLoading] = useState15(false);
3640
+ const [error, setError] = useState15(null);
3641
+ const fetchRuns = useCallback16(async () => {
3133
3642
  if (!workflowId) return [];
3134
3643
  setIsLoading(true);
3135
3644
  setError(null);
@@ -3159,7 +3668,7 @@ function useWorkflowRuns(workflowId, options) {
3159
3668
  setIsLoading(false);
3160
3669
  }
3161
3670
  }, [fetchWithAuth, workflowId, page, limit]);
3162
- const getRun = useCallback14(
3671
+ const getRun = useCallback16(
3163
3672
  async (runId) => {
3164
3673
  if (!runId) throw new Error("Run ID is required");
3165
3674
  const res = await fetchWithAuth(`/workflows/runs/${runId}`);
@@ -3170,7 +3679,7 @@ function useWorkflowRuns(workflowId, options) {
3170
3679
  },
3171
3680
  [fetchWithAuth]
3172
3681
  );
3173
- const cancelRun = useCallback14(
3682
+ const cancelRun = useCallback16(
3174
3683
  async (runId) => {
3175
3684
  if (!runId) throw new Error("Run ID is required");
3176
3685
  const res = await fetchWithAuth(`/workflows/runs/${runId}/cancel`, {
@@ -3185,7 +3694,7 @@ function useWorkflowRuns(workflowId, options) {
3185
3694
  },
3186
3695
  [fetchWithAuth]
3187
3696
  );
3188
- useEffect13(() => {
3697
+ useEffect15(() => {
3189
3698
  if (autoFetch && workflowId) {
3190
3699
  void fetchRuns();
3191
3700
  }
@@ -3230,6 +3739,8 @@ export {
3230
3739
  useMcpConnections,
3231
3740
  useMemory,
3232
3741
  usePersonaContext,
3742
+ useRcpSources,
3743
+ useSkills,
3233
3744
  useThreads,
3234
3745
  useVoice,
3235
3746
  useWorkflow,