@personaai/react 0.11.0 → 0.14.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
@@ -35,7 +35,9 @@ __export(index_exports, {
35
35
  useChat: () => useChat,
36
36
  useConnection: () => useConnection,
37
37
  useFiles: () => useFiles,
38
+ useKnowledgeBases: () => useKnowledgeBases,
38
39
  useMcp: () => useMcp,
40
+ useMcpAdmin: () => useMcpAdmin,
39
41
  useMcpConnections: () => useMcpConnections,
40
42
  useMemory: () => useMemory,
41
43
  usePersonaContext: () => usePersonaContext,
@@ -3173,28 +3175,475 @@ function useRcpSources(options = {}) {
3173
3175
  };
3174
3176
  }
3175
3177
 
3176
- // src/hooks/useWorkflows.ts
3178
+ // src/hooks/useKnowledgeBases.ts
3177
3179
  var import_react14 = require("react");
3180
+ function useKnowledgeBases(options = {}) {
3181
+ const { autoFetch = true, page, limit, search, scope } = options;
3182
+ const { fetchWithAuth } = usePersonaContext();
3183
+ const [knowledgeBases, setKnowledgeBases] = (0, import_react14.useState)([]);
3184
+ const [pagination, setPagination] = (0, import_react14.useState)({
3185
+ total: 0,
3186
+ page: page ?? 1,
3187
+ limit: limit ?? 20,
3188
+ pages: 0
3189
+ });
3190
+ const [isLoading, setIsLoading] = (0, import_react14.useState)(false);
3191
+ const [isUploading, setIsUploading] = (0, import_react14.useState)(false);
3192
+ const [error, setError] = (0, import_react14.useState)(null);
3193
+ const fetchKnowledgeBases = (0, import_react14.useCallback)(async () => {
3194
+ setIsLoading(true);
3195
+ setError(null);
3196
+ try {
3197
+ const query = new URLSearchParams();
3198
+ if (page) query.set("page", String(page));
3199
+ if (limit) query.set("limit", String(limit));
3200
+ if (search) query.set("search", search);
3201
+ if (scope) query.set("scope", scope);
3202
+ const queryStr = query.toString() ? `?${query.toString()}` : "";
3203
+ const res = await fetchWithAuth(`/knowledge${queryStr}`);
3204
+ if (!res.ok) throw new Error(`Failed to list knowledge bases: ${res.statusText}`);
3205
+ const data = await res.json();
3206
+ const items = Array.isArray(data) ? data : data?.items ?? [];
3207
+ setKnowledgeBases(items);
3208
+ setPagination(
3209
+ data?.pagination ?? { total: items.length, page: 1, limit: items.length, pages: 1 }
3210
+ );
3211
+ return items;
3212
+ } catch (err) {
3213
+ const errorObj = err instanceof Error ? err : new Error(String(err));
3214
+ setError(errorObj);
3215
+ return [];
3216
+ } finally {
3217
+ setIsLoading(false);
3218
+ }
3219
+ }, [fetchWithAuth, page, limit, search, scope]);
3220
+ const getKnowledgeBase = (0, import_react14.useCallback)(
3221
+ async (kbId) => {
3222
+ const res = await fetchWithAuth(`/knowledge/${kbId}`);
3223
+ if (!res.ok) throw new Error(`Failed to fetch knowledge base: ${res.statusText}`);
3224
+ return res.json();
3225
+ },
3226
+ [fetchWithAuth]
3227
+ );
3228
+ const createKnowledgeBase = (0, import_react14.useCallback)(
3229
+ async (input) => {
3230
+ setError(null);
3231
+ try {
3232
+ const res = await fetchWithAuth("/knowledge", {
3233
+ method: "POST",
3234
+ headers: { "Content-Type": "application/json" },
3235
+ body: JSON.stringify(input)
3236
+ });
3237
+ if (!res.ok) {
3238
+ const errText = await res.text().catch(() => res.statusText);
3239
+ throw new Error(`Failed to create knowledge base (${res.status}): ${errText}`);
3240
+ }
3241
+ const created = await res.json();
3242
+ setKnowledgeBases((prev) => [created, ...prev]);
3243
+ return created;
3244
+ } catch (err) {
3245
+ const errorObj = err instanceof Error ? err : new Error(String(err));
3246
+ setError(errorObj);
3247
+ throw errorObj;
3248
+ }
3249
+ },
3250
+ [fetchWithAuth]
3251
+ );
3252
+ const updateKnowledgeBase = (0, import_react14.useCallback)(
3253
+ async (kbId, input) => {
3254
+ setError(null);
3255
+ try {
3256
+ const res = await fetchWithAuth(`/knowledge/${kbId}`, {
3257
+ method: "PATCH",
3258
+ headers: { "Content-Type": "application/json" },
3259
+ body: JSON.stringify(input)
3260
+ });
3261
+ if (!res.ok) {
3262
+ const errText = await res.text().catch(() => res.statusText);
3263
+ throw new Error(`Failed to update knowledge base (${res.status}): ${errText}`);
3264
+ }
3265
+ const updated = await res.json();
3266
+ setKnowledgeBases((prev) => prev.map((kb) => kb._id === kbId ? updated : kb));
3267
+ return updated;
3268
+ } catch (err) {
3269
+ const errorObj = err instanceof Error ? err : new Error(String(err));
3270
+ setError(errorObj);
3271
+ throw errorObj;
3272
+ }
3273
+ },
3274
+ [fetchWithAuth]
3275
+ );
3276
+ const deleteKnowledgeBase = (0, import_react14.useCallback)(
3277
+ async (kbId) => {
3278
+ setError(null);
3279
+ try {
3280
+ const res = await fetchWithAuth(`/knowledge/${kbId}`, { method: "DELETE" });
3281
+ if (!res.ok) {
3282
+ const errText = await res.text().catch(() => res.statusText);
3283
+ throw new Error(`Failed to delete knowledge base (${res.status}): ${errText}`);
3284
+ }
3285
+ setKnowledgeBases((prev) => prev.filter((kb) => kb._id !== kbId));
3286
+ } catch (err) {
3287
+ const errorObj = err instanceof Error ? err : new Error(String(err));
3288
+ setError(errorObj);
3289
+ throw errorObj;
3290
+ }
3291
+ },
3292
+ [fetchWithAuth]
3293
+ );
3294
+ const bulkDeleteKnowledgeBases = (0, import_react14.useCallback)(
3295
+ async (ids) => {
3296
+ setError(null);
3297
+ try {
3298
+ const res = await fetchWithAuth("/knowledge/bulk-delete", {
3299
+ method: "POST",
3300
+ headers: { "Content-Type": "application/json" },
3301
+ body: JSON.stringify({ ids })
3302
+ });
3303
+ if (!res.ok) {
3304
+ const errText = await res.text().catch(() => res.statusText);
3305
+ throw new Error(`Failed to bulk-delete knowledge bases (${res.status}): ${errText}`);
3306
+ }
3307
+ const result = await res.json();
3308
+ const deletedSet = new Set(result.deleted);
3309
+ setKnowledgeBases((prev) => prev.filter((kb) => !deletedSet.has(kb._id)));
3310
+ return result;
3311
+ } catch (err) {
3312
+ const errorObj = err instanceof Error ? err : new Error(String(err));
3313
+ setError(errorObj);
3314
+ throw errorObj;
3315
+ }
3316
+ },
3317
+ [fetchWithAuth]
3318
+ );
3319
+ const getKnowledgeBaseUsage = (0, import_react14.useCallback)(
3320
+ async (kbId) => {
3321
+ const res = await fetchWithAuth(`/knowledge/${kbId}/usage`);
3322
+ if (!res.ok) throw new Error(`Failed to fetch knowledge base usage: ${res.statusText}`);
3323
+ return res.json();
3324
+ },
3325
+ [fetchWithAuth]
3326
+ );
3327
+ const uploadDocuments = (0, import_react14.useCallback)(
3328
+ async (kbId, files) => {
3329
+ setIsUploading(true);
3330
+ setError(null);
3331
+ try {
3332
+ const body = new FormData();
3333
+ for (const file of files) {
3334
+ if (file.content instanceof Blob) {
3335
+ body.append("files", file.content, file.filename);
3336
+ } else {
3337
+ body.append("files", {
3338
+ uri: file.content.uri,
3339
+ name: file.content.name ?? file.filename,
3340
+ type: file.content.type ?? file.contentType
3341
+ });
3342
+ }
3343
+ }
3344
+ const res = await fetchWithAuth(`/knowledge/${kbId}/documents`, {
3345
+ method: "POST",
3346
+ body
3347
+ });
3348
+ if (!res.ok) {
3349
+ const errText = await res.text().catch(() => res.statusText);
3350
+ throw new Error(`Failed to upload documents (${res.status}): ${errText}`);
3351
+ }
3352
+ const result = await res.json();
3353
+ setKnowledgeBases(
3354
+ (prev) => prev.map(
3355
+ (kb) => kb._id === kbId ? { ...kb, documentCount: result.documentCount, chunkCount: result.chunkCount } : kb
3356
+ )
3357
+ );
3358
+ return result;
3359
+ } catch (err) {
3360
+ const errorObj = err instanceof Error ? err : new Error(String(err));
3361
+ setError(errorObj);
3362
+ throw errorObj;
3363
+ } finally {
3364
+ setIsUploading(false);
3365
+ }
3366
+ },
3367
+ [fetchWithAuth]
3368
+ );
3369
+ const listDocuments = (0, import_react14.useCallback)(
3370
+ async (kbId) => {
3371
+ const res = await fetchWithAuth(`/knowledge/${kbId}/documents`);
3372
+ if (!res.ok) throw new Error(`Failed to list documents: ${res.statusText}`);
3373
+ return res.json();
3374
+ },
3375
+ [fetchWithAuth]
3376
+ );
3377
+ const deleteDocument = (0, import_react14.useCallback)(
3378
+ async (kbId, sourceName) => {
3379
+ setError(null);
3380
+ try {
3381
+ const res = await fetchWithAuth(
3382
+ `/knowledge/${kbId}/documents/${encodeURIComponent(sourceName)}`,
3383
+ { method: "DELETE" }
3384
+ );
3385
+ if (!res.ok) {
3386
+ const errText = await res.text().catch(() => res.statusText);
3387
+ throw new Error(`Failed to delete document (${res.status}): ${errText}`);
3388
+ }
3389
+ const result = await res.json();
3390
+ setKnowledgeBases(
3391
+ (prev) => prev.map(
3392
+ (kb) => kb._id === kbId ? { ...kb, documentCount: result.remainingDocuments, chunkCount: result.remainingChunks } : kb
3393
+ )
3394
+ );
3395
+ return result;
3396
+ } catch (err) {
3397
+ const errorObj = err instanceof Error ? err : new Error(String(err));
3398
+ setError(errorObj);
3399
+ throw errorObj;
3400
+ }
3401
+ },
3402
+ [fetchWithAuth]
3403
+ );
3404
+ const searchKnowledgeBase = (0, import_react14.useCallback)(
3405
+ async (kbId, query, opts) => {
3406
+ const res = await fetchWithAuth(`/knowledge/${kbId}/search`, {
3407
+ method: "POST",
3408
+ headers: { "Content-Type": "application/json" },
3409
+ body: JSON.stringify({ query, topK: opts?.topK })
3410
+ });
3411
+ if (!res.ok) {
3412
+ const errText = await res.text().catch(() => res.statusText);
3413
+ throw new Error(`Failed to search knowledge base (${res.status}): ${errText}`);
3414
+ }
3415
+ return res.json();
3416
+ },
3417
+ [fetchWithAuth]
3418
+ );
3419
+ (0, import_react14.useEffect)(() => {
3420
+ if (autoFetch) void fetchKnowledgeBases();
3421
+ }, [autoFetch, fetchKnowledgeBases]);
3422
+ return {
3423
+ knowledgeBases,
3424
+ pagination,
3425
+ isLoading,
3426
+ isUploading,
3427
+ error,
3428
+ refetch: fetchKnowledgeBases,
3429
+ getKnowledgeBase,
3430
+ createKnowledgeBase,
3431
+ updateKnowledgeBase,
3432
+ deleteKnowledgeBase,
3433
+ bulkDeleteKnowledgeBases,
3434
+ getKnowledgeBaseUsage,
3435
+ uploadDocuments,
3436
+ listDocuments,
3437
+ deleteDocument,
3438
+ search: searchKnowledgeBase
3439
+ };
3440
+ }
3441
+
3442
+ // src/hooks/useMcpAdmin.ts
3443
+ var import_react15 = require("react");
3444
+ function useMcpAdmin(options = {}) {
3445
+ const { autoFetch = true, page, limit, search } = options;
3446
+ const { fetchWithAuth } = usePersonaContext();
3447
+ const [mcps, setMcps] = (0, import_react15.useState)([]);
3448
+ const [pagination, setPagination] = (0, import_react15.useState)({
3449
+ total: 0,
3450
+ page: page ?? 1,
3451
+ limit: limit ?? 20,
3452
+ pages: 0
3453
+ });
3454
+ const [isLoading, setIsLoading] = (0, import_react15.useState)(false);
3455
+ const [error, setError] = (0, import_react15.useState)(null);
3456
+ const fetchMcps = (0, import_react15.useCallback)(async () => {
3457
+ setIsLoading(true);
3458
+ setError(null);
3459
+ try {
3460
+ const query = new URLSearchParams();
3461
+ if (page) query.set("page", String(page));
3462
+ if (limit) query.set("limit", String(limit));
3463
+ if (search) query.set("search", search);
3464
+ query.set("scope", "mine");
3465
+ const res = await fetchWithAuth(`/mcps?${query.toString()}`);
3466
+ if (!res.ok) throw new Error(`Failed to list MCPs: ${res.statusText}`);
3467
+ const data = await res.json();
3468
+ const items = Array.isArray(data) ? data : data?.items ?? [];
3469
+ setMcps(items);
3470
+ setPagination(
3471
+ data?.pagination ?? { total: items.length, page: 1, limit: items.length, pages: 1 }
3472
+ );
3473
+ return items;
3474
+ } catch (err) {
3475
+ const errorObj = err instanceof Error ? err : new Error(String(err));
3476
+ setError(errorObj);
3477
+ return [];
3478
+ } finally {
3479
+ setIsLoading(false);
3480
+ }
3481
+ }, [fetchWithAuth, page, limit, search]);
3482
+ const getMcp = (0, import_react15.useCallback)(
3483
+ async (mcpId) => {
3484
+ const res = await fetchWithAuth(`/mcps/${mcpId}`);
3485
+ if (!res.ok) throw new Error(`Failed to fetch MCP: ${res.statusText}`);
3486
+ return res.json();
3487
+ },
3488
+ [fetchWithAuth]
3489
+ );
3490
+ const createMcp = (0, import_react15.useCallback)(
3491
+ async (input) => {
3492
+ setError(null);
3493
+ try {
3494
+ const res = await fetchWithAuth("/mcps", {
3495
+ method: "POST",
3496
+ headers: { "Content-Type": "application/json" },
3497
+ body: JSON.stringify(input)
3498
+ });
3499
+ if (!res.ok) {
3500
+ const errText = await res.text().catch(() => res.statusText);
3501
+ throw new Error(`Failed to create MCP (${res.status}): ${errText}`);
3502
+ }
3503
+ const created = await res.json();
3504
+ setMcps((prev) => [created, ...prev]);
3505
+ return created;
3506
+ } catch (err) {
3507
+ const errorObj = err instanceof Error ? err : new Error(String(err));
3508
+ setError(errorObj);
3509
+ throw errorObj;
3510
+ }
3511
+ },
3512
+ [fetchWithAuth]
3513
+ );
3514
+ const updateMcp = (0, import_react15.useCallback)(
3515
+ async (mcpId, input) => {
3516
+ setError(null);
3517
+ try {
3518
+ const res = await fetchWithAuth(`/mcps/${mcpId}`, {
3519
+ method: "PATCH",
3520
+ headers: { "Content-Type": "application/json" },
3521
+ body: JSON.stringify(input)
3522
+ });
3523
+ if (!res.ok) {
3524
+ const errText = await res.text().catch(() => res.statusText);
3525
+ throw new Error(`Failed to update MCP (${res.status}): ${errText}`);
3526
+ }
3527
+ const updated = await res.json();
3528
+ setMcps((prev) => prev.map((m) => m._id === mcpId ? updated : m));
3529
+ return updated;
3530
+ } catch (err) {
3531
+ const errorObj = err instanceof Error ? err : new Error(String(err));
3532
+ setError(errorObj);
3533
+ throw errorObj;
3534
+ }
3535
+ },
3536
+ [fetchWithAuth]
3537
+ );
3538
+ const deleteMcp = (0, import_react15.useCallback)(
3539
+ async (mcpId) => {
3540
+ setError(null);
3541
+ try {
3542
+ const res = await fetchWithAuth(`/mcps/${mcpId}`, { method: "DELETE" });
3543
+ if (!res.ok) {
3544
+ const errText = await res.text().catch(() => res.statusText);
3545
+ throw new Error(`Failed to delete MCP (${res.status}): ${errText}`);
3546
+ }
3547
+ setMcps((prev) => prev.filter((m) => m._id !== mcpId));
3548
+ } catch (err) {
3549
+ const errorObj = err instanceof Error ? err : new Error(String(err));
3550
+ setError(errorObj);
3551
+ throw errorObj;
3552
+ }
3553
+ },
3554
+ [fetchWithAuth]
3555
+ );
3556
+ const bulkDeleteMcps = (0, import_react15.useCallback)(
3557
+ async (ids) => {
3558
+ setError(null);
3559
+ try {
3560
+ const res = await fetchWithAuth("/mcps/bulk-delete", {
3561
+ method: "POST",
3562
+ headers: { "Content-Type": "application/json" },
3563
+ body: JSON.stringify({ ids })
3564
+ });
3565
+ if (!res.ok) {
3566
+ const errText = await res.text().catch(() => res.statusText);
3567
+ throw new Error(`Failed to bulk-delete MCPs (${res.status}): ${errText}`);
3568
+ }
3569
+ const result = await res.json();
3570
+ const deletedSet = new Set(result.deleted);
3571
+ setMcps((prev) => prev.filter((m) => !deletedSet.has(m._id)));
3572
+ return result;
3573
+ } catch (err) {
3574
+ const errorObj = err instanceof Error ? err : new Error(String(err));
3575
+ setError(errorObj);
3576
+ throw errorObj;
3577
+ }
3578
+ },
3579
+ [fetchWithAuth]
3580
+ );
3581
+ const testConnection = (0, import_react15.useCallback)(
3582
+ async (mcpId) => {
3583
+ setError(null);
3584
+ try {
3585
+ const res = await fetchWithAuth(`/mcps/${mcpId}/test`, { method: "POST" });
3586
+ if (!res.ok) {
3587
+ const errText = await res.text().catch(() => res.statusText);
3588
+ throw new Error(`Failed to test MCP connection (${res.status}): ${errText}`);
3589
+ }
3590
+ const result = await res.json();
3591
+ setMcps(
3592
+ (prev) => prev.map(
3593
+ (m) => m._id === mcpId ? { ...m, tools: result.tools, resources: result.resources, resourceTemplates: result.resourceTemplates } : m
3594
+ )
3595
+ );
3596
+ return result;
3597
+ } catch (err) {
3598
+ const errorObj = err instanceof Error ? err : new Error(String(err));
3599
+ setError(errorObj);
3600
+ throw errorObj;
3601
+ }
3602
+ },
3603
+ [fetchWithAuth]
3604
+ );
3605
+ (0, import_react15.useEffect)(() => {
3606
+ if (autoFetch) void fetchMcps();
3607
+ }, [autoFetch, fetchMcps]);
3608
+ return {
3609
+ mcps,
3610
+ pagination,
3611
+ isLoading,
3612
+ error,
3613
+ refetch: fetchMcps,
3614
+ getMcp,
3615
+ createMcp,
3616
+ updateMcp,
3617
+ deleteMcp,
3618
+ bulkDeleteMcps,
3619
+ testConnection
3620
+ };
3621
+ }
3622
+
3623
+ // src/hooks/useWorkflows.ts
3624
+ var import_react16 = require("react");
3178
3625
  function useWorkflows(options) {
3179
3626
  const opts = typeof options === "boolean" ? { autoFetch: options } : options ?? {};
3180
- const { autoFetch = true, search, status, page, limit } = opts;
3627
+ const { autoFetch = true, search, scope, visibility, isEnabled, page, limit } = opts;
3181
3628
  const { fetchWithAuth } = usePersonaContext();
3182
- const [workflows, setWorkflows] = (0, import_react14.useState)([]);
3183
- const [pagination, setPagination] = (0, import_react14.useState)({
3629
+ const [workflows, setWorkflows] = (0, import_react16.useState)([]);
3630
+ const [pagination, setPagination] = (0, import_react16.useState)({
3184
3631
  page: page ?? 1,
3185
3632
  limit: limit ?? 20,
3186
3633
  total: 0,
3187
3634
  totalPages: 0
3188
3635
  });
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 () => {
3636
+ const [isLoading, setIsLoading] = (0, import_react16.useState)(false);
3637
+ const [error, setError] = (0, import_react16.useState)(null);
3638
+ const fetchWorkflows = (0, import_react16.useCallback)(async () => {
3192
3639
  setIsLoading(true);
3193
3640
  setError(null);
3194
3641
  try {
3195
3642
  const params = new URLSearchParams();
3196
3643
  if (search) params.set("search", search);
3197
- if (status) params.set("status", status);
3644
+ if (scope) params.set("scope", scope);
3645
+ if (visibility) params.set("visibility", visibility);
3646
+ if (isEnabled !== void 0) params.set("isEnabled", String(isEnabled));
3198
3647
  if (page) params.set("page", String(page));
3199
3648
  if (limit) params.set("limit", String(limit));
3200
3649
  const queryStr = params.toString() ? `?${params.toString()}` : "";
@@ -3203,7 +3652,7 @@ function useWorkflows(options) {
3203
3652
  throw new Error(`Failed to list workflows: ${res.statusText}`);
3204
3653
  }
3205
3654
  const data = await res.json();
3206
- const items = Array.isArray(data) ? data : data?.items || data?.workflows || [];
3655
+ const items = Array.isArray(data) ? data : data?.items ?? [];
3207
3656
  setWorkflows(items);
3208
3657
  if (data?.pagination) {
3209
3658
  setPagination({
@@ -3231,8 +3680,8 @@ function useWorkflows(options) {
3231
3680
  } finally {
3232
3681
  setIsLoading(false);
3233
3682
  }
3234
- }, [fetchWithAuth, search, status, page, limit]);
3235
- const createWorkflow = (0, import_react14.useCallback)(
3683
+ }, [fetchWithAuth, search, scope, visibility, isEnabled, page, limit]);
3684
+ const createWorkflow = (0, import_react16.useCallback)(
3236
3685
  async (input) => {
3237
3686
  setError(null);
3238
3687
  try {
@@ -3256,7 +3705,7 @@ function useWorkflows(options) {
3256
3705
  },
3257
3706
  [fetchWithAuth]
3258
3707
  );
3259
- (0, import_react14.useEffect)(() => {
3708
+ (0, import_react16.useEffect)(() => {
3260
3709
  if (autoFetch) {
3261
3710
  void fetchWorkflows();
3262
3711
  }
@@ -3272,17 +3721,17 @@ function useWorkflows(options) {
3272
3721
  }
3273
3722
 
3274
3723
  // src/hooks/useWorkflow.ts
3275
- var import_react15 = require("react");
3724
+ var import_react17 = require("react");
3276
3725
  function useWorkflow(workflowId, options) {
3277
3726
  const opts = typeof options === "boolean" ? { autoFetch: options } : options ?? {};
3278
3727
  const { autoFetch = true } = opts;
3279
3728
  const { fetchWithAuth } = usePersonaContext();
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 () => {
3729
+ const [workflow, setWorkflow] = (0, import_react17.useState)(null);
3730
+ const [versions, setVersions] = (0, import_react17.useState)([]);
3731
+ const [mermaid, setMermaid] = (0, import_react17.useState)(null);
3732
+ const [isLoading, setIsLoading] = (0, import_react17.useState)(false);
3733
+ const [error, setError] = (0, import_react17.useState)(null);
3734
+ const fetchWorkflow = (0, import_react17.useCallback)(async () => {
3286
3735
  if (!workflowId) return null;
3287
3736
  setIsLoading(true);
3288
3737
  setError(null);
@@ -3302,20 +3751,31 @@ function useWorkflow(workflowId, options) {
3302
3751
  setIsLoading(false);
3303
3752
  }
3304
3753
  }, [fetchWithAuth, workflowId]);
3305
- const fetchVersions = (0, import_react15.useCallback)(async () => {
3754
+ const fetchVersions = (0, import_react17.useCallback)(async () => {
3306
3755
  if (!workflowId) return [];
3307
3756
  try {
3308
3757
  const res = await fetchWithAuth(`/workflows/${workflowId}/versions`);
3309
3758
  if (!res.ok) return [];
3310
3759
  const data = await res.json();
3311
- const items = Array.isArray(data) ? data : data?.items || [];
3760
+ const items = Array.isArray(data) ? data : data?.items ?? [];
3312
3761
  setVersions(items);
3313
3762
  return items;
3314
3763
  } catch {
3315
3764
  return [];
3316
3765
  }
3317
3766
  }, [fetchWithAuth, workflowId]);
3318
- const fetchMermaid = (0, import_react15.useCallback)(async () => {
3767
+ const getVersion = (0, import_react17.useCallback)(
3768
+ async (version) => {
3769
+ if (!workflowId) throw new Error("Workflow ID is required");
3770
+ const res = await fetchWithAuth(`/workflows/${workflowId}/versions/${version}`);
3771
+ if (!res.ok) {
3772
+ throw new Error(`Failed to fetch workflow version (${res.status}): ${res.statusText}`);
3773
+ }
3774
+ return await res.json();
3775
+ },
3776
+ [fetchWithAuth, workflowId]
3777
+ );
3778
+ const fetchMermaid = (0, import_react17.useCallback)(async () => {
3319
3779
  if (!workflowId) return "";
3320
3780
  try {
3321
3781
  const res = await fetchWithAuth(`/workflows/${workflowId}/mermaid`);
@@ -3328,18 +3788,18 @@ function useWorkflow(workflowId, options) {
3328
3788
  return "";
3329
3789
  }
3330
3790
  }, [fetchWithAuth, workflowId]);
3331
- const saveDraft = (0, import_react15.useCallback)(
3332
- async (draft) => {
3791
+ const updateWorkflow = (0, import_react17.useCallback)(
3792
+ async (input) => {
3333
3793
  if (!workflowId) throw new Error("Workflow ID is required");
3334
3794
  setError(null);
3335
- const res = await fetchWithAuth(`/workflows/${workflowId}/draft`, {
3336
- method: "POST",
3795
+ const res = await fetchWithAuth(`/workflows/${workflowId}`, {
3796
+ method: "PATCH",
3337
3797
  headers: { "Content-Type": "application/json" },
3338
- body: JSON.stringify({ draft })
3798
+ body: JSON.stringify(input)
3339
3799
  });
3340
3800
  if (!res.ok) {
3341
3801
  const errText = await res.text().catch(() => res.statusText);
3342
- throw new Error(`Failed to save draft (${res.status}): ${errText}`);
3802
+ throw new Error(`Failed to update workflow (${res.status}): ${errText}`);
3343
3803
  }
3344
3804
  const updated = await res.json();
3345
3805
  setWorkflow(updated);
@@ -3347,27 +3807,41 @@ function useWorkflow(workflowId, options) {
3347
3807
  },
3348
3808
  [fetchWithAuth, workflowId]
3349
3809
  );
3350
- const publish = (0, import_react15.useCallback)(
3351
- async (summary) => {
3810
+ const saveDraft = (0, import_react17.useCallback)(
3811
+ async (draft) => {
3352
3812
  if (!workflowId) throw new Error("Workflow ID is required");
3353
3813
  setError(null);
3354
- const res = await fetchWithAuth(`/workflows/${workflowId}/publish`, {
3355
- method: "POST",
3814
+ const res = await fetchWithAuth(`/workflows/${workflowId}/draft`, {
3815
+ method: "PUT",
3356
3816
  headers: { "Content-Type": "application/json" },
3357
- body: JSON.stringify(summary ? { summary } : {})
3817
+ body: JSON.stringify(draft)
3358
3818
  });
3359
3819
  if (!res.ok) {
3360
3820
  const errText = await res.text().catch(() => res.statusText);
3361
- throw new Error(`Failed to publish workflow (${res.status}): ${errText}`);
3821
+ throw new Error(`Failed to save draft (${res.status}): ${errText}`);
3362
3822
  }
3363
- const versionResult = await res.json();
3364
- void fetchWorkflow();
3365
- void fetchVersions();
3366
- return versionResult;
3823
+ const updated = await res.json();
3824
+ setWorkflow(updated);
3825
+ return updated;
3367
3826
  },
3368
- [fetchWithAuth, workflowId, fetchWorkflow, fetchVersions]
3827
+ [fetchWithAuth, workflowId]
3369
3828
  );
3370
- const deleteWorkflow = (0, import_react15.useCallback)(async () => {
3829
+ const publish = (0, import_react17.useCallback)(async () => {
3830
+ if (!workflowId) throw new Error("Workflow ID is required");
3831
+ setError(null);
3832
+ const res = await fetchWithAuth(`/workflows/${workflowId}/publish`, {
3833
+ method: "POST"
3834
+ });
3835
+ if (!res.ok) {
3836
+ const errText = await res.text().catch(() => res.statusText);
3837
+ throw new Error(`Failed to publish workflow (${res.status}): ${errText}`);
3838
+ }
3839
+ const versionResult = await res.json();
3840
+ void fetchWorkflow();
3841
+ void fetchVersions();
3842
+ return versionResult;
3843
+ }, [fetchWithAuth, workflowId, fetchWorkflow, fetchVersions]);
3844
+ const deleteWorkflow = (0, import_react17.useCallback)(async () => {
3371
3845
  if (!workflowId) throw new Error("Workflow ID is required");
3372
3846
  setError(null);
3373
3847
  const res = await fetchWithAuth(`/workflows/${workflowId}`, {
@@ -3378,7 +3852,7 @@ function useWorkflow(workflowId, options) {
3378
3852
  }
3379
3853
  setWorkflow(null);
3380
3854
  }, [fetchWithAuth, workflowId]);
3381
- (0, import_react15.useEffect)(() => {
3855
+ (0, import_react17.useEffect)(() => {
3382
3856
  if (autoFetch && workflowId) {
3383
3857
  void fetchWorkflow();
3384
3858
  }
@@ -3391,7 +3865,9 @@ function useWorkflow(workflowId, options) {
3391
3865
  error,
3392
3866
  refetch: fetchWorkflow,
3393
3867
  fetchVersions,
3868
+ getVersion,
3394
3869
  fetchMermaid,
3870
+ updateWorkflow,
3395
3871
  saveDraft,
3396
3872
  publish,
3397
3873
  deleteWorkflow
@@ -3399,25 +3875,25 @@ function useWorkflow(workflowId, options) {
3399
3875
  }
3400
3876
 
3401
3877
  // src/hooks/useWorkflowStream.ts
3402
- var import_react16 = require("react");
3878
+ var import_react18 = require("react");
3403
3879
  function useWorkflowStream(workflowId, options) {
3404
3880
  const { baseUrl, getAuthToken, fetchWithAuth, logger } = usePersonaContext();
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)(
3881
+ const [status, setStatus] = (0, import_react18.useState)("idle");
3882
+ const [runId, setRunId] = (0, import_react18.useState)(null);
3883
+ const [activeNodeId, setActiveNodeId] = (0, import_react18.useState)(null);
3884
+ const [nodeRuns, setNodeRuns] = (0, import_react18.useState)(
3409
3885
  {}
3410
3886
  );
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);
3887
+ const [text, setText] = (0, import_react18.useState)("");
3888
+ const [output, setOutput] = (0, import_react18.useState)(null);
3889
+ const [error, setError] = (0, import_react18.useState)(null);
3890
+ const [events, setEvents] = (0, import_react18.useState)([]);
3891
+ const abortControllerRef = (0, import_react18.useRef)(null);
3892
+ const currentRunIdRef = (0, import_react18.useRef)(null);
3417
3893
  currentRunIdRef.current = runId;
3418
- const optionsRef = (0, import_react16.useRef)(options);
3894
+ const optionsRef = (0, import_react18.useRef)(options);
3419
3895
  optionsRef.current = options;
3420
- const cancel = (0, import_react16.useCallback)(async () => {
3896
+ const cancel = (0, import_react18.useCallback)(async () => {
3421
3897
  if (abortControllerRef.current) {
3422
3898
  abortControllerRef.current.abort();
3423
3899
  abortControllerRef.current = null;
@@ -3438,7 +3914,7 @@ function useWorkflowStream(workflowId, options) {
3438
3914
  setStatus("cancelled");
3439
3915
  setActiveNodeId(null);
3440
3916
  }, [fetchWithAuth, logger]);
3441
- const reset = (0, import_react16.useCallback)(() => {
3917
+ const reset = (0, import_react18.useCallback)(() => {
3442
3918
  if (abortControllerRef.current) {
3443
3919
  abortControllerRef.current.abort();
3444
3920
  abortControllerRef.current = null;
@@ -3452,7 +3928,7 @@ function useWorkflowStream(workflowId, options) {
3452
3928
  setError(null);
3453
3929
  setEvents([]);
3454
3930
  }, []);
3455
- const processStream = (0, import_react16.useCallback)(
3931
+ const processStream = (0, import_react18.useCallback)(
3456
3932
  async (url, method, body, targetRunId) => {
3457
3933
  if (abortControllerRef.current) {
3458
3934
  abortControllerRef.current.abort();
@@ -3617,7 +4093,7 @@ function useWorkflowStream(workflowId, options) {
3617
4093
  },
3618
4094
  [getAuthToken]
3619
4095
  );
3620
- const start = (0, import_react16.useCallback)(
4096
+ const start = (0, import_react18.useCallback)(
3621
4097
  async (input, opts) => {
3622
4098
  const targetWfId = opts?.workflowId || workflowId;
3623
4099
  if (!targetWfId) {
@@ -3638,7 +4114,7 @@ function useWorkflowStream(workflowId, options) {
3638
4114
  },
3639
4115
  [workflowId, baseUrl, processStream]
3640
4116
  );
3641
- const resume = (0, import_react16.useCallback)(
4117
+ const resume = (0, import_react18.useCallback)(
3642
4118
  async (targetRunId, sinceSeq) => {
3643
4119
  if (!targetRunId) {
3644
4120
  throw new Error("Run ID is required to resume stream");
@@ -3651,7 +4127,7 @@ function useWorkflowStream(workflowId, options) {
3651
4127
  },
3652
4128
  [baseUrl, processStream]
3653
4129
  );
3654
- (0, import_react16.useEffect)(() => {
4130
+ (0, import_react18.useEffect)(() => {
3655
4131
  return () => {
3656
4132
  if (abortControllerRef.current) {
3657
4133
  abortControllerRef.current.abort();
@@ -3676,21 +4152,21 @@ function useWorkflowStream(workflowId, options) {
3676
4152
  }
3677
4153
 
3678
4154
  // src/hooks/useWorkflowRuns.ts
3679
- var import_react17 = require("react");
4155
+ var import_react19 = require("react");
3680
4156
  function useWorkflowRuns(workflowId, options) {
3681
4157
  const opts = typeof options === "boolean" ? { autoFetch: options } : options ?? {};
3682
4158
  const { autoFetch = true, page = 1, limit = 20 } = opts;
3683
4159
  const { fetchWithAuth } = usePersonaContext();
3684
- const [runs, setRuns] = (0, import_react17.useState)([]);
3685
- const [pagination, setPagination] = (0, import_react17.useState)({
4160
+ const [runs, setRuns] = (0, import_react19.useState)([]);
4161
+ const [pagination, setPagination] = (0, import_react19.useState)({
3686
4162
  page,
3687
4163
  limit,
3688
4164
  total: 0,
3689
4165
  totalPages: 0
3690
4166
  });
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 () => {
4167
+ const [isLoading, setIsLoading] = (0, import_react19.useState)(false);
4168
+ const [error, setError] = (0, import_react19.useState)(null);
4169
+ const fetchRuns = (0, import_react19.useCallback)(async () => {
3694
4170
  if (!workflowId) return [];
3695
4171
  setIsLoading(true);
3696
4172
  setError(null);
@@ -3701,14 +4177,16 @@ function useWorkflowRuns(workflowId, options) {
3701
4177
  throw new Error(`Failed to list workflow runs: ${res.statusText}`);
3702
4178
  }
3703
4179
  const data = await res.json();
3704
- const items = Array.isArray(data) ? data : data?.items || data?.runs || [];
4180
+ const items = Array.isArray(data) ? data : data?.items ?? [];
3705
4181
  setRuns(items);
3706
4182
  if (data?.pagination) {
3707
4183
  setPagination({
3708
4184
  page: data.pagination.page ?? page,
3709
4185
  limit: data.pagination.limit ?? limit,
3710
4186
  total: data.pagination.total ?? items.length,
3711
- totalPages: data.pagination.totalPages ?? 1
4187
+ // Backend's paginationEnvelope() names this field `pages`, not
4188
+ // `totalPages`.
4189
+ totalPages: data.pagination.pages ?? 1
3712
4190
  });
3713
4191
  }
3714
4192
  return items;
@@ -3720,7 +4198,7 @@ function useWorkflowRuns(workflowId, options) {
3720
4198
  setIsLoading(false);
3721
4199
  }
3722
4200
  }, [fetchWithAuth, workflowId, page, limit]);
3723
- const getRun = (0, import_react17.useCallback)(
4201
+ const getRun = (0, import_react19.useCallback)(
3724
4202
  async (runId) => {
3725
4203
  if (!runId) throw new Error("Run ID is required");
3726
4204
  const res = await fetchWithAuth(`/workflows/runs/${runId}`);
@@ -3731,7 +4209,7 @@ function useWorkflowRuns(workflowId, options) {
3731
4209
  },
3732
4210
  [fetchWithAuth]
3733
4211
  );
3734
- const cancelRun = (0, import_react17.useCallback)(
4212
+ const cancelRun = (0, import_react19.useCallback)(
3735
4213
  async (runId) => {
3736
4214
  if (!runId) throw new Error("Run ID is required");
3737
4215
  const res = await fetchWithAuth(`/workflows/runs/${runId}/cancel`, {
@@ -3746,7 +4224,7 @@ function useWorkflowRuns(workflowId, options) {
3746
4224
  },
3747
4225
  [fetchWithAuth]
3748
4226
  );
3749
- (0, import_react17.useEffect)(() => {
4227
+ (0, import_react19.useEffect)(() => {
3750
4228
  if (autoFetch && workflowId) {
3751
4229
  void fetchRuns();
3752
4230
  }
@@ -3782,7 +4260,9 @@ var VERSION = "0.10.0";
3782
4260
  useChat,
3783
4261
  useConnection,
3784
4262
  useFiles,
4263
+ useKnowledgeBases,
3785
4264
  useMcp,
4265
+ useMcpAdmin,
3786
4266
  useMcpConnections,
3787
4267
  useMemory,
3788
4268
  usePersonaContext,