@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.cjs CHANGED
@@ -39,6 +39,8 @@ __export(index_exports, {
39
39
  useMcpConnections: () => useMcpConnections,
40
40
  useMemory: () => useMemory,
41
41
  usePersonaContext: () => usePersonaContext,
42
+ useRcpSources: () => useRcpSources,
43
+ useSkills: () => useSkills,
42
44
  useThreads: () => useThreads,
43
45
  useVoice: () => useVoice,
44
46
  useWorkflow: () => useWorkflow,
@@ -2503,20 +2505,38 @@ function useFiles(autoFetch = true) {
2503
2505
 
2504
2506
  // src/hooks/useAgents.ts
2505
2507
  var import_react8 = require("react");
2506
- function useAgents(autoFetch = true) {
2508
+ function useAgents(options = true) {
2509
+ const opts = typeof options === "boolean" ? { autoFetch: options } : options;
2510
+ const { autoFetch = true, page, limit, search, category, scope } = opts;
2507
2511
  const { fetchWithAuth } = usePersonaContext();
2508
2512
  const [agents, setAgents] = (0, import_react8.useState)([]);
2513
+ const [pagination, setPagination] = (0, import_react8.useState)({
2514
+ total: 0,
2515
+ page: page ?? 1,
2516
+ limit: limit ?? 20,
2517
+ pages: 0
2518
+ });
2509
2519
  const [isLoading, setIsLoading] = (0, import_react8.useState)(false);
2510
2520
  const [error, setError] = (0, import_react8.useState)(null);
2511
2521
  const fetchAgents = (0, import_react8.useCallback)(async () => {
2512
2522
  setIsLoading(true);
2513
2523
  setError(null);
2514
2524
  try {
2515
- const res = await fetchWithAuth("/agents");
2525
+ const query = new URLSearchParams();
2526
+ if (page) query.set("page", String(page));
2527
+ if (limit) query.set("limit", String(limit));
2528
+ if (search) query.set("search", search);
2529
+ if (category) query.set("category", category);
2530
+ if (scope) query.set("scope", scope);
2531
+ const queryStr = query.toString() ? `?${query.toString()}` : "";
2532
+ const res = await fetchWithAuth(`/agents${queryStr}`);
2516
2533
  if (!res.ok) throw new Error(`Failed to list agents: ${res.statusText}`);
2517
2534
  const data = await res.json();
2518
- const items = Array.isArray(data) ? data : data?.items || data?.agents || [];
2535
+ const items = Array.isArray(data) ? data : data?.items ?? [];
2519
2536
  setAgents(items);
2537
+ setPagination(
2538
+ data?.pagination ?? { total: items.length, page: 1, limit: items.length, pages: 1 }
2539
+ );
2520
2540
  return items;
2521
2541
  } catch (err) {
2522
2542
  const errorObj = err instanceof Error ? err : new Error(String(err));
@@ -2525,17 +2545,120 @@ function useAgents(autoFetch = true) {
2525
2545
  } finally {
2526
2546
  setIsLoading(false);
2527
2547
  }
2528
- }, [fetchWithAuth]);
2548
+ }, [fetchWithAuth, page, limit, search, category, scope]);
2549
+ const getAgent = (0, import_react8.useCallback)(
2550
+ async (agentId) => {
2551
+ const res = await fetchWithAuth(`/agents/${agentId}`);
2552
+ if (!res.ok) throw new Error(`Failed to fetch agent: ${res.statusText}`);
2553
+ return res.json();
2554
+ },
2555
+ [fetchWithAuth]
2556
+ );
2557
+ const createAgent = (0, import_react8.useCallback)(
2558
+ async (input) => {
2559
+ setError(null);
2560
+ try {
2561
+ const res = await fetchWithAuth("/agents", {
2562
+ method: "POST",
2563
+ headers: { "Content-Type": "application/json" },
2564
+ body: JSON.stringify(input)
2565
+ });
2566
+ if (!res.ok) {
2567
+ const errText = await res.text().catch(() => res.statusText);
2568
+ throw new Error(`Failed to create agent (${res.status}): ${errText}`);
2569
+ }
2570
+ const created = await res.json();
2571
+ setAgents((prev) => [created, ...prev]);
2572
+ return created;
2573
+ } catch (err) {
2574
+ const errorObj = err instanceof Error ? err : new Error(String(err));
2575
+ setError(errorObj);
2576
+ throw errorObj;
2577
+ }
2578
+ },
2579
+ [fetchWithAuth]
2580
+ );
2581
+ const updateAgent = (0, import_react8.useCallback)(
2582
+ async (agentId, input) => {
2583
+ setError(null);
2584
+ try {
2585
+ const res = await fetchWithAuth(`/agents/${agentId}`, {
2586
+ method: "PATCH",
2587
+ headers: { "Content-Type": "application/json" },
2588
+ body: JSON.stringify(input)
2589
+ });
2590
+ if (!res.ok) {
2591
+ const errText = await res.text().catch(() => res.statusText);
2592
+ throw new Error(`Failed to update agent (${res.status}): ${errText}`);
2593
+ }
2594
+ const updated = await res.json();
2595
+ setAgents((prev) => prev.map((a) => a._id === agentId ? updated : a));
2596
+ return updated;
2597
+ } catch (err) {
2598
+ const errorObj = err instanceof Error ? err : new Error(String(err));
2599
+ setError(errorObj);
2600
+ throw errorObj;
2601
+ }
2602
+ },
2603
+ [fetchWithAuth]
2604
+ );
2605
+ const deleteAgent = (0, import_react8.useCallback)(
2606
+ async (agentId) => {
2607
+ setError(null);
2608
+ try {
2609
+ const res = await fetchWithAuth(`/agents/${agentId}`, { method: "DELETE" });
2610
+ if (!res.ok) {
2611
+ const errText = await res.text().catch(() => res.statusText);
2612
+ throw new Error(`Failed to delete agent (${res.status}): ${errText}`);
2613
+ }
2614
+ setAgents((prev) => prev.filter((a) => a._id !== agentId));
2615
+ } catch (err) {
2616
+ const errorObj = err instanceof Error ? err : new Error(String(err));
2617
+ setError(errorObj);
2618
+ throw errorObj;
2619
+ }
2620
+ },
2621
+ [fetchWithAuth]
2622
+ );
2623
+ const bulkDeleteAgents = (0, import_react8.useCallback)(
2624
+ async (ids) => {
2625
+ setError(null);
2626
+ try {
2627
+ const res = await fetchWithAuth("/agents/bulk-delete", {
2628
+ method: "POST",
2629
+ headers: { "Content-Type": "application/json" },
2630
+ body: JSON.stringify({ ids })
2631
+ });
2632
+ if (!res.ok) {
2633
+ const errText = await res.text().catch(() => res.statusText);
2634
+ throw new Error(`Failed to bulk-delete agents (${res.status}): ${errText}`);
2635
+ }
2636
+ const result = await res.json();
2637
+ const deletedSet = new Set(result.deleted);
2638
+ setAgents((prev) => prev.filter((a) => !deletedSet.has(a._id)));
2639
+ return result;
2640
+ } catch (err) {
2641
+ const errorObj = err instanceof Error ? err : new Error(String(err));
2642
+ setError(errorObj);
2643
+ throw errorObj;
2644
+ }
2645
+ },
2646
+ [fetchWithAuth]
2647
+ );
2529
2648
  (0, import_react8.useEffect)(() => {
2530
- if (autoFetch) {
2531
- void fetchAgents();
2532
- }
2649
+ if (autoFetch) void fetchAgents();
2533
2650
  }, [autoFetch, fetchAgents]);
2534
2651
  return {
2535
2652
  agents,
2653
+ pagination,
2536
2654
  isLoading,
2537
2655
  error,
2538
- refetch: fetchAgents
2656
+ refetch: fetchAgents,
2657
+ getAgent,
2658
+ createAgent,
2659
+ updateAgent,
2660
+ deleteAgent,
2661
+ bulkDeleteAgents
2539
2662
  };
2540
2663
  }
2541
2664
 
@@ -2611,6 +2734,33 @@ function useMcpConnections(options = {}) {
2611
2734
  setIsLoading(false);
2612
2735
  }
2613
2736
  }, [agentId, fetchWithAuth, options.returnTo]);
2737
+ const [isDisconnecting, setIsDisconnecting] = (0, import_react10.useState)(false);
2738
+ const disconnect = (0, import_react10.useCallback)(
2739
+ async (mcpId) => {
2740
+ setIsDisconnecting(true);
2741
+ setError(null);
2742
+ try {
2743
+ const res = await fetchWithAuth(`/mcps/${mcpId}/oauth/user/connection`, {
2744
+ method: "DELETE"
2745
+ });
2746
+ if (!res.ok)
2747
+ throw new Error(`Failed to disconnect MCP: ${res.statusText}`);
2748
+ setConnections(
2749
+ (prev) => prev.map(
2750
+ (c) => c.mcpId === mcpId ? { ...c, connected: false, authorizeUrl: null } : c
2751
+ )
2752
+ );
2753
+ void fetchConnections();
2754
+ } catch (err) {
2755
+ const errorObj = err instanceof Error ? err : new Error(String(err));
2756
+ setError(errorObj);
2757
+ throw errorObj;
2758
+ } finally {
2759
+ setIsDisconnecting(false);
2760
+ }
2761
+ },
2762
+ [fetchWithAuth, fetchConnections]
2763
+ );
2614
2764
  (0, import_react10.useEffect)(() => {
2615
2765
  if (autoFetch) void fetchConnections();
2616
2766
  }, [autoFetch, fetchConnections]);
@@ -2620,7 +2770,9 @@ function useMcpConnections(options = {}) {
2620
2770
  unconnected: connections.filter((c) => !c.connected),
2621
2771
  isLoading,
2622
2772
  error,
2623
- refetch: fetchConnections
2773
+ refetch: fetchConnections,
2774
+ disconnect,
2775
+ isDisconnecting
2624
2776
  };
2625
2777
  }
2626
2778
 
@@ -2665,22 +2817,378 @@ function useMcp(options = {}) {
2665
2817
  };
2666
2818
  }
2667
2819
 
2668
- // src/hooks/useWorkflows.ts
2820
+ // src/hooks/useSkills.ts
2669
2821
  var import_react12 = require("react");
2822
+ function useSkills(options = {}) {
2823
+ const { autoFetch = true, page, limit, search, scope } = options;
2824
+ const { fetchWithAuth } = usePersonaContext();
2825
+ const [skills, setSkills] = (0, import_react12.useState)([]);
2826
+ const [pagination, setPagination] = (0, import_react12.useState)({
2827
+ total: 0,
2828
+ page: page ?? 1,
2829
+ limit: limit ?? 20,
2830
+ pages: 0
2831
+ });
2832
+ const [isLoading, setIsLoading] = (0, import_react12.useState)(false);
2833
+ const [error, setError] = (0, import_react12.useState)(null);
2834
+ const fetchSkills = (0, import_react12.useCallback)(async () => {
2835
+ setIsLoading(true);
2836
+ setError(null);
2837
+ try {
2838
+ const query = new URLSearchParams();
2839
+ if (page) query.set("page", String(page));
2840
+ if (limit) query.set("limit", String(limit));
2841
+ if (search) query.set("search", search);
2842
+ if (scope) query.set("scope", scope);
2843
+ const queryStr = query.toString() ? `?${query.toString()}` : "";
2844
+ const res = await fetchWithAuth(`/skills${queryStr}`);
2845
+ if (!res.ok) throw new Error(`Failed to list skills: ${res.statusText}`);
2846
+ const data = await res.json();
2847
+ const items = Array.isArray(data) ? data : data?.items ?? [];
2848
+ setSkills(items);
2849
+ setPagination(
2850
+ data?.pagination ?? { total: items.length, page: 1, limit: items.length, pages: 1 }
2851
+ );
2852
+ return items;
2853
+ } catch (err) {
2854
+ const errorObj = err instanceof Error ? err : new Error(String(err));
2855
+ setError(errorObj);
2856
+ return [];
2857
+ } finally {
2858
+ setIsLoading(false);
2859
+ }
2860
+ }, [fetchWithAuth, page, limit, search, scope]);
2861
+ const getSkill = (0, import_react12.useCallback)(
2862
+ async (skillId) => {
2863
+ const res = await fetchWithAuth(`/skills/${skillId}`);
2864
+ if (!res.ok) throw new Error(`Failed to fetch skill: ${res.statusText}`);
2865
+ return res.json();
2866
+ },
2867
+ [fetchWithAuth]
2868
+ );
2869
+ const createSkill = (0, import_react12.useCallback)(
2870
+ async (input) => {
2871
+ setError(null);
2872
+ try {
2873
+ const res = await fetchWithAuth("/skills", {
2874
+ method: "POST",
2875
+ headers: { "Content-Type": "application/json" },
2876
+ body: JSON.stringify(input)
2877
+ });
2878
+ if (!res.ok) {
2879
+ const errText = await res.text().catch(() => res.statusText);
2880
+ throw new Error(`Failed to create skill (${res.status}): ${errText}`);
2881
+ }
2882
+ const created = await res.json();
2883
+ setSkills((prev) => [created, ...prev]);
2884
+ return created;
2885
+ } catch (err) {
2886
+ const errorObj = err instanceof Error ? err : new Error(String(err));
2887
+ setError(errorObj);
2888
+ throw errorObj;
2889
+ }
2890
+ },
2891
+ [fetchWithAuth]
2892
+ );
2893
+ const updateSkill = (0, import_react12.useCallback)(
2894
+ async (skillId, input) => {
2895
+ setError(null);
2896
+ try {
2897
+ const res = await fetchWithAuth(`/skills/${skillId}`, {
2898
+ method: "PATCH",
2899
+ headers: { "Content-Type": "application/json" },
2900
+ body: JSON.stringify(input)
2901
+ });
2902
+ if (!res.ok) {
2903
+ const errText = await res.text().catch(() => res.statusText);
2904
+ throw new Error(`Failed to update skill (${res.status}): ${errText}`);
2905
+ }
2906
+ const updated = await res.json();
2907
+ setSkills((prev) => prev.map((s) => s._id === skillId ? updated : s));
2908
+ return updated;
2909
+ } catch (err) {
2910
+ const errorObj = err instanceof Error ? err : new Error(String(err));
2911
+ setError(errorObj);
2912
+ throw errorObj;
2913
+ }
2914
+ },
2915
+ [fetchWithAuth]
2916
+ );
2917
+ const deleteSkill = (0, import_react12.useCallback)(
2918
+ async (skillId) => {
2919
+ setError(null);
2920
+ try {
2921
+ const res = await fetchWithAuth(`/skills/${skillId}`, { method: "DELETE" });
2922
+ if (!res.ok) {
2923
+ const errText = await res.text().catch(() => res.statusText);
2924
+ throw new Error(`Failed to delete skill (${res.status}): ${errText}`);
2925
+ }
2926
+ setSkills((prev) => prev.filter((s) => s._id !== skillId));
2927
+ } catch (err) {
2928
+ const errorObj = err instanceof Error ? err : new Error(String(err));
2929
+ setError(errorObj);
2930
+ throw errorObj;
2931
+ }
2932
+ },
2933
+ [fetchWithAuth]
2934
+ );
2935
+ const bulkDeleteSkills = (0, import_react12.useCallback)(
2936
+ async (ids) => {
2937
+ setError(null);
2938
+ try {
2939
+ const res = await fetchWithAuth("/skills/bulk-delete", {
2940
+ method: "POST",
2941
+ headers: { "Content-Type": "application/json" },
2942
+ body: JSON.stringify({ ids })
2943
+ });
2944
+ if (!res.ok) {
2945
+ const errText = await res.text().catch(() => res.statusText);
2946
+ throw new Error(`Failed to bulk-delete skills (${res.status}): ${errText}`);
2947
+ }
2948
+ const result = await res.json();
2949
+ const deletedSet = new Set(result.deleted);
2950
+ setSkills((prev) => prev.filter((s) => !deletedSet.has(s._id)));
2951
+ return result;
2952
+ } catch (err) {
2953
+ const errorObj = err instanceof Error ? err : new Error(String(err));
2954
+ setError(errorObj);
2955
+ throw errorObj;
2956
+ }
2957
+ },
2958
+ [fetchWithAuth]
2959
+ );
2960
+ const getSkillUsage = (0, import_react12.useCallback)(
2961
+ async (skillId) => {
2962
+ const res = await fetchWithAuth(`/skills/${skillId}/usage`);
2963
+ if (!res.ok) throw new Error(`Failed to fetch skill usage: ${res.statusText}`);
2964
+ return res.json();
2965
+ },
2966
+ [fetchWithAuth]
2967
+ );
2968
+ (0, import_react12.useEffect)(() => {
2969
+ if (autoFetch) void fetchSkills();
2970
+ }, [autoFetch, fetchSkills]);
2971
+ return {
2972
+ skills,
2973
+ pagination,
2974
+ isLoading,
2975
+ error,
2976
+ refetch: fetchSkills,
2977
+ getSkill,
2978
+ createSkill,
2979
+ updateSkill,
2980
+ deleteSkill,
2981
+ bulkDeleteSkills,
2982
+ getSkillUsage
2983
+ };
2984
+ }
2985
+
2986
+ // src/hooks/useRcpSources.ts
2987
+ var import_react13 = require("react");
2988
+ function useRcpSources(options = {}) {
2989
+ const { autoFetch = true, page, limit, search } = options;
2990
+ const { fetchWithAuth } = usePersonaContext();
2991
+ const [rcpSources, setRcpSources] = (0, import_react13.useState)([]);
2992
+ const [pagination, setPagination] = (0, import_react13.useState)({
2993
+ total: 0,
2994
+ page: page ?? 1,
2995
+ limit: limit ?? 20,
2996
+ pages: 0
2997
+ });
2998
+ const [isLoading, setIsLoading] = (0, import_react13.useState)(false);
2999
+ const [error, setError] = (0, import_react13.useState)(null);
3000
+ const fetchRcpSources = (0, import_react13.useCallback)(async () => {
3001
+ setIsLoading(true);
3002
+ setError(null);
3003
+ try {
3004
+ const query = new URLSearchParams();
3005
+ if (page) query.set("page", String(page));
3006
+ if (limit) query.set("limit", String(limit));
3007
+ if (search) query.set("search", search);
3008
+ const queryStr = query.toString() ? `?${query.toString()}` : "";
3009
+ const res = await fetchWithAuth(`/rcp-sources${queryStr}`);
3010
+ if (!res.ok) throw new Error(`Failed to list RCP sources: ${res.statusText}`);
3011
+ const data = await res.json();
3012
+ const items = Array.isArray(data) ? data : data?.items ?? [];
3013
+ setRcpSources(items);
3014
+ setPagination(
3015
+ data?.pagination ?? { total: items.length, page: 1, limit: items.length, pages: 1 }
3016
+ );
3017
+ return items;
3018
+ } catch (err) {
3019
+ const errorObj = err instanceof Error ? err : new Error(String(err));
3020
+ setError(errorObj);
3021
+ return [];
3022
+ } finally {
3023
+ setIsLoading(false);
3024
+ }
3025
+ }, [fetchWithAuth, page, limit, search]);
3026
+ const getRcpSource = (0, import_react13.useCallback)(
3027
+ async (sourceId) => {
3028
+ const res = await fetchWithAuth(`/rcp-sources/${sourceId}`);
3029
+ if (!res.ok) throw new Error(`Failed to fetch RCP source: ${res.statusText}`);
3030
+ return res.json();
3031
+ },
3032
+ [fetchWithAuth]
3033
+ );
3034
+ const createRcpSource = (0, import_react13.useCallback)(
3035
+ async (input) => {
3036
+ setError(null);
3037
+ try {
3038
+ const res = await fetchWithAuth("/rcp-sources", {
3039
+ method: "POST",
3040
+ headers: { "Content-Type": "application/json" },
3041
+ body: JSON.stringify(input)
3042
+ });
3043
+ if (!res.ok) {
3044
+ const errText = await res.text().catch(() => res.statusText);
3045
+ throw new Error(`Failed to create RCP source (${res.status}): ${errText}`);
3046
+ }
3047
+ const created = await res.json();
3048
+ setRcpSources((prev) => [created, ...prev]);
3049
+ return created;
3050
+ } catch (err) {
3051
+ const errorObj = err instanceof Error ? err : new Error(String(err));
3052
+ setError(errorObj);
3053
+ throw errorObj;
3054
+ }
3055
+ },
3056
+ [fetchWithAuth]
3057
+ );
3058
+ const updateRcpSource = (0, import_react13.useCallback)(
3059
+ async (sourceId, input) => {
3060
+ setError(null);
3061
+ try {
3062
+ const res = await fetchWithAuth(`/rcp-sources/${sourceId}`, {
3063
+ method: "PATCH",
3064
+ headers: { "Content-Type": "application/json" },
3065
+ body: JSON.stringify(input)
3066
+ });
3067
+ if (!res.ok) {
3068
+ const errText = await res.text().catch(() => res.statusText);
3069
+ throw new Error(`Failed to update RCP source (${res.status}): ${errText}`);
3070
+ }
3071
+ const updated = await res.json();
3072
+ setRcpSources((prev) => prev.map((s) => s._id === sourceId ? updated : s));
3073
+ return updated;
3074
+ } catch (err) {
3075
+ const errorObj = err instanceof Error ? err : new Error(String(err));
3076
+ setError(errorObj);
3077
+ throw errorObj;
3078
+ }
3079
+ },
3080
+ [fetchWithAuth]
3081
+ );
3082
+ const deleteRcpSource = (0, import_react13.useCallback)(
3083
+ async (sourceId) => {
3084
+ setError(null);
3085
+ try {
3086
+ const res = await fetchWithAuth(`/rcp-sources/${sourceId}`, { method: "DELETE" });
3087
+ if (!res.ok) {
3088
+ const errText = await res.text().catch(() => res.statusText);
3089
+ throw new Error(`Failed to delete RCP source (${res.status}): ${errText}`);
3090
+ }
3091
+ setRcpSources((prev) => prev.filter((s) => s._id !== sourceId));
3092
+ } catch (err) {
3093
+ const errorObj = err instanceof Error ? err : new Error(String(err));
3094
+ setError(errorObj);
3095
+ throw errorObj;
3096
+ }
3097
+ },
3098
+ [fetchWithAuth]
3099
+ );
3100
+ const bulkDeleteRcpSources = (0, import_react13.useCallback)(
3101
+ async (ids) => {
3102
+ setError(null);
3103
+ try {
3104
+ const res = await fetchWithAuth("/rcp-sources/bulk-delete", {
3105
+ method: "POST",
3106
+ headers: { "Content-Type": "application/json" },
3107
+ body: JSON.stringify({ ids })
3108
+ });
3109
+ if (!res.ok) {
3110
+ const errText = await res.text().catch(() => res.statusText);
3111
+ throw new Error(`Failed to bulk-delete RCP sources (${res.status}): ${errText}`);
3112
+ }
3113
+ const result = await res.json();
3114
+ const deletedSet = new Set(result.deleted);
3115
+ setRcpSources((prev) => prev.filter((s) => !deletedSet.has(s._id)));
3116
+ return result;
3117
+ } catch (err) {
3118
+ const errorObj = err instanceof Error ? err : new Error(String(err));
3119
+ setError(errorObj);
3120
+ throw errorObj;
3121
+ }
3122
+ },
3123
+ [fetchWithAuth]
3124
+ );
3125
+ const getRcpSourceUsage = (0, import_react13.useCallback)(
3126
+ async (sourceId) => {
3127
+ const res = await fetchWithAuth(`/rcp-sources/${sourceId}/usage`);
3128
+ if (!res.ok) throw new Error(`Failed to fetch RCP source usage: ${res.statusText}`);
3129
+ return res.json();
3130
+ },
3131
+ [fetchWithAuth]
3132
+ );
3133
+ const testRcpSourceConnection = (0, import_react13.useCallback)(
3134
+ async (sourceId) => {
3135
+ setError(null);
3136
+ try {
3137
+ const res = await fetchWithAuth(`/rcp-sources/${sourceId}/test`, { method: "POST" });
3138
+ if (!res.ok) {
3139
+ const errText = await res.text().catch(() => res.statusText);
3140
+ throw new Error(`Failed to test RCP source connection (${res.status}): ${errText}`);
3141
+ }
3142
+ const result = await res.json();
3143
+ setRcpSources(
3144
+ (prev) => prev.map(
3145
+ (s) => s._id === sourceId ? { ...s, tools: result.tools, lastTestedAt: (/* @__PURE__ */ new Date()).toISOString() } : s
3146
+ )
3147
+ );
3148
+ return result;
3149
+ } catch (err) {
3150
+ const errorObj = err instanceof Error ? err : new Error(String(err));
3151
+ setError(errorObj);
3152
+ throw errorObj;
3153
+ }
3154
+ },
3155
+ [fetchWithAuth]
3156
+ );
3157
+ (0, import_react13.useEffect)(() => {
3158
+ if (autoFetch) void fetchRcpSources();
3159
+ }, [autoFetch, fetchRcpSources]);
3160
+ return {
3161
+ rcpSources,
3162
+ pagination,
3163
+ isLoading,
3164
+ error,
3165
+ refetch: fetchRcpSources,
3166
+ getRcpSource,
3167
+ createRcpSource,
3168
+ updateRcpSource,
3169
+ deleteRcpSource,
3170
+ bulkDeleteRcpSources,
3171
+ getRcpSourceUsage,
3172
+ testRcpSourceConnection
3173
+ };
3174
+ }
3175
+
3176
+ // src/hooks/useWorkflows.ts
3177
+ var import_react14 = require("react");
2670
3178
  function useWorkflows(options) {
2671
3179
  const opts = typeof options === "boolean" ? { autoFetch: options } : options ?? {};
2672
3180
  const { autoFetch = true, search, status, page, limit } = opts;
2673
3181
  const { fetchWithAuth } = usePersonaContext();
2674
- const [workflows, setWorkflows] = (0, import_react12.useState)([]);
2675
- const [pagination, setPagination] = (0, import_react12.useState)({
3182
+ const [workflows, setWorkflows] = (0, import_react14.useState)([]);
3183
+ const [pagination, setPagination] = (0, import_react14.useState)({
2676
3184
  page: page ?? 1,
2677
3185
  limit: limit ?? 20,
2678
3186
  total: 0,
2679
3187
  totalPages: 0
2680
3188
  });
2681
- const [isLoading, setIsLoading] = (0, import_react12.useState)(false);
2682
- const [error, setError] = (0, import_react12.useState)(null);
2683
- const fetchWorkflows = (0, import_react12.useCallback)(async () => {
3189
+ const [isLoading, setIsLoading] = (0, import_react14.useState)(false);
3190
+ const [error, setError] = (0, import_react14.useState)(null);
3191
+ const fetchWorkflows = (0, import_react14.useCallback)(async () => {
2684
3192
  setIsLoading(true);
2685
3193
  setError(null);
2686
3194
  try {
@@ -2702,7 +3210,10 @@ function useWorkflows(options) {
2702
3210
  page: data.pagination.page ?? 1,
2703
3211
  limit: data.pagination.limit ?? items.length,
2704
3212
  total: data.pagination.total ?? items.length,
2705
- totalPages: data.pagination.totalPages ?? 1
3213
+ // Backend's paginationEnvelope() names this field `pages`, not
3214
+ // `totalPages` — this used to always fall through to the `?? 1`
3215
+ // default.
3216
+ totalPages: data.pagination.pages ?? 1
2706
3217
  });
2707
3218
  } else {
2708
3219
  setPagination({
@@ -2721,7 +3232,7 @@ function useWorkflows(options) {
2721
3232
  setIsLoading(false);
2722
3233
  }
2723
3234
  }, [fetchWithAuth, search, status, page, limit]);
2724
- const createWorkflow = (0, import_react12.useCallback)(
3235
+ const createWorkflow = (0, import_react14.useCallback)(
2725
3236
  async (input) => {
2726
3237
  setError(null);
2727
3238
  try {
@@ -2745,7 +3256,7 @@ function useWorkflows(options) {
2745
3256
  },
2746
3257
  [fetchWithAuth]
2747
3258
  );
2748
- (0, import_react12.useEffect)(() => {
3259
+ (0, import_react14.useEffect)(() => {
2749
3260
  if (autoFetch) {
2750
3261
  void fetchWorkflows();
2751
3262
  }
@@ -2761,17 +3272,17 @@ function useWorkflows(options) {
2761
3272
  }
2762
3273
 
2763
3274
  // src/hooks/useWorkflow.ts
2764
- var import_react13 = require("react");
3275
+ var import_react15 = require("react");
2765
3276
  function useWorkflow(workflowId, options) {
2766
3277
  const opts = typeof options === "boolean" ? { autoFetch: options } : options ?? {};
2767
3278
  const { autoFetch = true } = opts;
2768
3279
  const { fetchWithAuth } = usePersonaContext();
2769
- const [workflow, setWorkflow] = (0, import_react13.useState)(null);
2770
- const [versions, setVersions] = (0, import_react13.useState)([]);
2771
- const [mermaid, setMermaid] = (0, import_react13.useState)(null);
2772
- const [isLoading, setIsLoading] = (0, import_react13.useState)(false);
2773
- const [error, setError] = (0, import_react13.useState)(null);
2774
- const fetchWorkflow = (0, import_react13.useCallback)(async () => {
3280
+ const [workflow, setWorkflow] = (0, import_react15.useState)(null);
3281
+ const [versions, setVersions] = (0, import_react15.useState)([]);
3282
+ const [mermaid, setMermaid] = (0, import_react15.useState)(null);
3283
+ const [isLoading, setIsLoading] = (0, import_react15.useState)(false);
3284
+ const [error, setError] = (0, import_react15.useState)(null);
3285
+ const fetchWorkflow = (0, import_react15.useCallback)(async () => {
2775
3286
  if (!workflowId) return null;
2776
3287
  setIsLoading(true);
2777
3288
  setError(null);
@@ -2791,7 +3302,7 @@ function useWorkflow(workflowId, options) {
2791
3302
  setIsLoading(false);
2792
3303
  }
2793
3304
  }, [fetchWithAuth, workflowId]);
2794
- const fetchVersions = (0, import_react13.useCallback)(async () => {
3305
+ const fetchVersions = (0, import_react15.useCallback)(async () => {
2795
3306
  if (!workflowId) return [];
2796
3307
  try {
2797
3308
  const res = await fetchWithAuth(`/workflows/${workflowId}/versions`);
@@ -2804,7 +3315,7 @@ function useWorkflow(workflowId, options) {
2804
3315
  return [];
2805
3316
  }
2806
3317
  }, [fetchWithAuth, workflowId]);
2807
- const fetchMermaid = (0, import_react13.useCallback)(async () => {
3318
+ const fetchMermaid = (0, import_react15.useCallback)(async () => {
2808
3319
  if (!workflowId) return "";
2809
3320
  try {
2810
3321
  const res = await fetchWithAuth(`/workflows/${workflowId}/mermaid`);
@@ -2817,7 +3328,7 @@ function useWorkflow(workflowId, options) {
2817
3328
  return "";
2818
3329
  }
2819
3330
  }, [fetchWithAuth, workflowId]);
2820
- const saveDraft = (0, import_react13.useCallback)(
3331
+ const saveDraft = (0, import_react15.useCallback)(
2821
3332
  async (draft) => {
2822
3333
  if (!workflowId) throw new Error("Workflow ID is required");
2823
3334
  setError(null);
@@ -2836,7 +3347,7 @@ function useWorkflow(workflowId, options) {
2836
3347
  },
2837
3348
  [fetchWithAuth, workflowId]
2838
3349
  );
2839
- const publish = (0, import_react13.useCallback)(
3350
+ const publish = (0, import_react15.useCallback)(
2840
3351
  async (summary) => {
2841
3352
  if (!workflowId) throw new Error("Workflow ID is required");
2842
3353
  setError(null);
@@ -2856,7 +3367,7 @@ function useWorkflow(workflowId, options) {
2856
3367
  },
2857
3368
  [fetchWithAuth, workflowId, fetchWorkflow, fetchVersions]
2858
3369
  );
2859
- const deleteWorkflow = (0, import_react13.useCallback)(async () => {
3370
+ const deleteWorkflow = (0, import_react15.useCallback)(async () => {
2860
3371
  if (!workflowId) throw new Error("Workflow ID is required");
2861
3372
  setError(null);
2862
3373
  const res = await fetchWithAuth(`/workflows/${workflowId}`, {
@@ -2867,7 +3378,7 @@ function useWorkflow(workflowId, options) {
2867
3378
  }
2868
3379
  setWorkflow(null);
2869
3380
  }, [fetchWithAuth, workflowId]);
2870
- (0, import_react13.useEffect)(() => {
3381
+ (0, import_react15.useEffect)(() => {
2871
3382
  if (autoFetch && workflowId) {
2872
3383
  void fetchWorkflow();
2873
3384
  }
@@ -2888,25 +3399,25 @@ function useWorkflow(workflowId, options) {
2888
3399
  }
2889
3400
 
2890
3401
  // src/hooks/useWorkflowStream.ts
2891
- var import_react14 = require("react");
3402
+ var import_react16 = require("react");
2892
3403
  function useWorkflowStream(workflowId, options) {
2893
3404
  const { baseUrl, getAuthToken, fetchWithAuth, logger } = usePersonaContext();
2894
- const [status, setStatus] = (0, import_react14.useState)("idle");
2895
- const [runId, setRunId] = (0, import_react14.useState)(null);
2896
- const [activeNodeId, setActiveNodeId] = (0, import_react14.useState)(null);
2897
- const [nodeRuns, setNodeRuns] = (0, import_react14.useState)(
3405
+ const [status, setStatus] = (0, import_react16.useState)("idle");
3406
+ const [runId, setRunId] = (0, import_react16.useState)(null);
3407
+ const [activeNodeId, setActiveNodeId] = (0, import_react16.useState)(null);
3408
+ const [nodeRuns, setNodeRuns] = (0, import_react16.useState)(
2898
3409
  {}
2899
3410
  );
2900
- const [text, setText] = (0, import_react14.useState)("");
2901
- const [output, setOutput] = (0, import_react14.useState)(null);
2902
- const [error, setError] = (0, import_react14.useState)(null);
2903
- const [events, setEvents] = (0, import_react14.useState)([]);
2904
- const abortControllerRef = (0, import_react14.useRef)(null);
2905
- const currentRunIdRef = (0, import_react14.useRef)(null);
3411
+ const [text, setText] = (0, import_react16.useState)("");
3412
+ const [output, setOutput] = (0, import_react16.useState)(null);
3413
+ const [error, setError] = (0, import_react16.useState)(null);
3414
+ const [events, setEvents] = (0, import_react16.useState)([]);
3415
+ const abortControllerRef = (0, import_react16.useRef)(null);
3416
+ const currentRunIdRef = (0, import_react16.useRef)(null);
2906
3417
  currentRunIdRef.current = runId;
2907
- const optionsRef = (0, import_react14.useRef)(options);
3418
+ const optionsRef = (0, import_react16.useRef)(options);
2908
3419
  optionsRef.current = options;
2909
- const cancel = (0, import_react14.useCallback)(async () => {
3420
+ const cancel = (0, import_react16.useCallback)(async () => {
2910
3421
  if (abortControllerRef.current) {
2911
3422
  abortControllerRef.current.abort();
2912
3423
  abortControllerRef.current = null;
@@ -2927,7 +3438,7 @@ function useWorkflowStream(workflowId, options) {
2927
3438
  setStatus("cancelled");
2928
3439
  setActiveNodeId(null);
2929
3440
  }, [fetchWithAuth, logger]);
2930
- const reset = (0, import_react14.useCallback)(() => {
3441
+ const reset = (0, import_react16.useCallback)(() => {
2931
3442
  if (abortControllerRef.current) {
2932
3443
  abortControllerRef.current.abort();
2933
3444
  abortControllerRef.current = null;
@@ -2941,7 +3452,7 @@ function useWorkflowStream(workflowId, options) {
2941
3452
  setError(null);
2942
3453
  setEvents([]);
2943
3454
  }, []);
2944
- const processStream = (0, import_react14.useCallback)(
3455
+ const processStream = (0, import_react16.useCallback)(
2945
3456
  async (url, method, body, targetRunId) => {
2946
3457
  if (abortControllerRef.current) {
2947
3458
  abortControllerRef.current.abort();
@@ -3106,7 +3617,7 @@ function useWorkflowStream(workflowId, options) {
3106
3617
  },
3107
3618
  [getAuthToken]
3108
3619
  );
3109
- const start = (0, import_react14.useCallback)(
3620
+ const start = (0, import_react16.useCallback)(
3110
3621
  async (input, opts) => {
3111
3622
  const targetWfId = opts?.workflowId || workflowId;
3112
3623
  if (!targetWfId) {
@@ -3127,7 +3638,7 @@ function useWorkflowStream(workflowId, options) {
3127
3638
  },
3128
3639
  [workflowId, baseUrl, processStream]
3129
3640
  );
3130
- const resume = (0, import_react14.useCallback)(
3641
+ const resume = (0, import_react16.useCallback)(
3131
3642
  async (targetRunId, sinceSeq) => {
3132
3643
  if (!targetRunId) {
3133
3644
  throw new Error("Run ID is required to resume stream");
@@ -3140,7 +3651,7 @@ function useWorkflowStream(workflowId, options) {
3140
3651
  },
3141
3652
  [baseUrl, processStream]
3142
3653
  );
3143
- (0, import_react14.useEffect)(() => {
3654
+ (0, import_react16.useEffect)(() => {
3144
3655
  return () => {
3145
3656
  if (abortControllerRef.current) {
3146
3657
  abortControllerRef.current.abort();
@@ -3165,21 +3676,21 @@ function useWorkflowStream(workflowId, options) {
3165
3676
  }
3166
3677
 
3167
3678
  // src/hooks/useWorkflowRuns.ts
3168
- var import_react15 = require("react");
3679
+ var import_react17 = require("react");
3169
3680
  function useWorkflowRuns(workflowId, options) {
3170
3681
  const opts = typeof options === "boolean" ? { autoFetch: options } : options ?? {};
3171
3682
  const { autoFetch = true, page = 1, limit = 20 } = opts;
3172
3683
  const { fetchWithAuth } = usePersonaContext();
3173
- const [runs, setRuns] = (0, import_react15.useState)([]);
3174
- const [pagination, setPagination] = (0, import_react15.useState)({
3684
+ const [runs, setRuns] = (0, import_react17.useState)([]);
3685
+ const [pagination, setPagination] = (0, import_react17.useState)({
3175
3686
  page,
3176
3687
  limit,
3177
3688
  total: 0,
3178
3689
  totalPages: 0
3179
3690
  });
3180
- const [isLoading, setIsLoading] = (0, import_react15.useState)(false);
3181
- const [error, setError] = (0, import_react15.useState)(null);
3182
- const fetchRuns = (0, import_react15.useCallback)(async () => {
3691
+ const [isLoading, setIsLoading] = (0, import_react17.useState)(false);
3692
+ const [error, setError] = (0, import_react17.useState)(null);
3693
+ const fetchRuns = (0, import_react17.useCallback)(async () => {
3183
3694
  if (!workflowId) return [];
3184
3695
  setIsLoading(true);
3185
3696
  setError(null);
@@ -3209,7 +3720,7 @@ function useWorkflowRuns(workflowId, options) {
3209
3720
  setIsLoading(false);
3210
3721
  }
3211
3722
  }, [fetchWithAuth, workflowId, page, limit]);
3212
- const getRun = (0, import_react15.useCallback)(
3723
+ const getRun = (0, import_react17.useCallback)(
3213
3724
  async (runId) => {
3214
3725
  if (!runId) throw new Error("Run ID is required");
3215
3726
  const res = await fetchWithAuth(`/workflows/runs/${runId}`);
@@ -3220,7 +3731,7 @@ function useWorkflowRuns(workflowId, options) {
3220
3731
  },
3221
3732
  [fetchWithAuth]
3222
3733
  );
3223
- const cancelRun = (0, import_react15.useCallback)(
3734
+ const cancelRun = (0, import_react17.useCallback)(
3224
3735
  async (runId) => {
3225
3736
  if (!runId) throw new Error("Run ID is required");
3226
3737
  const res = await fetchWithAuth(`/workflows/runs/${runId}/cancel`, {
@@ -3235,7 +3746,7 @@ function useWorkflowRuns(workflowId, options) {
3235
3746
  },
3236
3747
  [fetchWithAuth]
3237
3748
  );
3238
- (0, import_react15.useEffect)(() => {
3749
+ (0, import_react17.useEffect)(() => {
3239
3750
  if (autoFetch && workflowId) {
3240
3751
  void fetchRuns();
3241
3752
  }
@@ -3275,6 +3786,8 @@ var VERSION = "0.10.0";
3275
3786
  useMcpConnections,
3276
3787
  useMemory,
3277
3788
  usePersonaContext,
3789
+ useRcpSources,
3790
+ useSkills,
3278
3791
  useThreads,
3279
3792
  useVoice,
3280
3793
  useWorkflow,