@agent-native/dispatch 0.14.3 → 0.14.4

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.
Files changed (127) hide show
  1. package/README.md +114 -128
  2. package/dist/actions/list_apps.d.ts +1 -0
  3. package/dist/actions/list_apps.js +16 -8
  4. package/dist/actions/list_apps.js.map +1 -1
  5. package/dist/actions/set-mcp-app-access.js +1 -4
  6. package/dist/actions/set-mcp-app-access.js.map +1 -1
  7. package/dist/components/action-query-error.d.ts +8 -0
  8. package/dist/components/action-query-error.d.ts.map +1 -0
  9. package/dist/components/action-query-error.js +10 -0
  10. package/dist/components/action-query-error.js.map +1 -0
  11. package/dist/components/app-keys-popover.d.ts +4 -0
  12. package/dist/components/app-keys-popover.d.ts.map +1 -1
  13. package/dist/components/app-keys-popover.js +26 -14
  14. package/dist/components/app-keys-popover.js.map +1 -1
  15. package/dist/components/dispatch-control-plane.d.ts.map +1 -1
  16. package/dist/components/dispatch-control-plane.js +31 -27
  17. package/dist/components/dispatch-control-plane.js.map +1 -1
  18. package/dist/components/index.d.ts +1 -0
  19. package/dist/components/index.d.ts.map +1 -1
  20. package/dist/components/index.js +1 -0
  21. package/dist/components/index.js.map +1 -1
  22. package/dist/components/layout/Layout.d.ts +1 -0
  23. package/dist/components/layout/Layout.d.ts.map +1 -1
  24. package/dist/components/layout/Layout.js +19 -21
  25. package/dist/components/layout/Layout.js.map +1 -1
  26. package/dist/components/ui/sheet.js +1 -1
  27. package/dist/components/ui/sheet.js.map +1 -1
  28. package/dist/components/ui/toast.js +1 -1
  29. package/dist/components/ui/toast.js.map +1 -1
  30. package/dist/components/workspace-app-card.d.ts.map +1 -1
  31. package/dist/components/workspace-app-card.js +8 -5
  32. package/dist/components/workspace-app-card.js.map +1 -1
  33. package/dist/components/workspace-resource-effective-stack.d.ts.map +1 -1
  34. package/dist/components/workspace-resource-effective-stack.js +6 -1
  35. package/dist/components/workspace-resource-effective-stack.js.map +1 -1
  36. package/dist/components/workspace-resource-impact-preview.d.ts.map +1 -1
  37. package/dist/components/workspace-resource-impact-preview.js +6 -1
  38. package/dist/components/workspace-resource-impact-preview.js.map +1 -1
  39. package/dist/routes/pages/$appId.d.ts.map +1 -1
  40. package/dist/routes/pages/$appId.js +6 -1
  41. package/dist/routes/pages/$appId.js.map +1 -1
  42. package/dist/routes/pages/agents.d.ts.map +1 -1
  43. package/dist/routes/pages/agents.js +5 -8
  44. package/dist/routes/pages/agents.js.map +1 -1
  45. package/dist/routes/pages/approval.d.ts.map +1 -1
  46. package/dist/routes/pages/approval.js +6 -1
  47. package/dist/routes/pages/approval.js.map +1 -1
  48. package/dist/routes/pages/approvals.d.ts.map +1 -1
  49. package/dist/routes/pages/approvals.js +8 -5
  50. package/dist/routes/pages/approvals.js.map +1 -1
  51. package/dist/routes/pages/apps.$appId.d.ts.map +1 -1
  52. package/dist/routes/pages/apps.$appId.js +4 -2
  53. package/dist/routes/pages/apps.$appId.js.map +1 -1
  54. package/dist/routes/pages/apps.d.ts.map +1 -1
  55. package/dist/routes/pages/apps.js +9 -3
  56. package/dist/routes/pages/apps.js.map +1 -1
  57. package/dist/routes/pages/audit.d.ts.map +1 -1
  58. package/dist/routes/pages/audit.js +4 -2
  59. package/dist/routes/pages/audit.js.map +1 -1
  60. package/dist/routes/pages/chat.d.ts.map +1 -1
  61. package/dist/routes/pages/chat.js +16 -2
  62. package/dist/routes/pages/chat.js.map +1 -1
  63. package/dist/routes/pages/destinations.d.ts.map +1 -1
  64. package/dist/routes/pages/destinations.js +5 -3
  65. package/dist/routes/pages/destinations.js.map +1 -1
  66. package/dist/routes/pages/identities.d.ts.map +1 -1
  67. package/dist/routes/pages/identities.js +5 -3
  68. package/dist/routes/pages/identities.js.map +1 -1
  69. package/dist/routes/pages/integrations.d.ts.map +1 -1
  70. package/dist/routes/pages/integrations.js +9 -3
  71. package/dist/routes/pages/integrations.js.map +1 -1
  72. package/dist/routes/pages/thread-debug.d.ts.map +1 -1
  73. package/dist/routes/pages/thread-debug.js +7 -6
  74. package/dist/routes/pages/thread-debug.js.map +1 -1
  75. package/dist/routes/pages/vault.d.ts.map +1 -1
  76. package/dist/routes/pages/vault.js +23 -7
  77. package/dist/routes/pages/vault.js.map +1 -1
  78. package/dist/routes/pages/workspace.d.ts.map +1 -1
  79. package/dist/routes/pages/workspace.js +9 -3
  80. package/dist/routes/pages/workspace.js.map +1 -1
  81. package/dist/server/lib/dispatch-store.d.ts.map +1 -1
  82. package/dist/server/lib/dispatch-store.js +2 -2
  83. package/dist/server/lib/dispatch-store.js.map +1 -1
  84. package/dist/server/lib/mcp-access-store.d.ts.map +1 -1
  85. package/dist/server/lib/mcp-access-store.js +30 -2
  86. package/dist/server/lib/mcp-access-store.js.map +1 -1
  87. package/dist/server/plugins/agent-chat.d.ts +1 -1
  88. package/package.json +2 -2
  89. package/src/actions/list_apps.spec.ts +52 -0
  90. package/src/actions/list_apps.ts +16 -8
  91. package/src/actions/set-mcp-app-access.spec.ts +73 -0
  92. package/src/actions/set-mcp-app-access.ts +1 -5
  93. package/src/components/action-query-error.spec.tsx +56 -0
  94. package/src/components/action-query-error.tsx +32 -0
  95. package/src/components/app-keys-popover.spec.tsx +85 -0
  96. package/src/components/app-keys-popover.tsx +76 -50
  97. package/src/components/dispatch-control-plane.spec.tsx +106 -0
  98. package/src/components/dispatch-control-plane.tsx +71 -115
  99. package/src/components/index.ts +1 -0
  100. package/src/components/layout/Layout.spec.tsx +42 -2
  101. package/src/components/layout/Layout.tsx +22 -27
  102. package/src/components/ui/sheet.tsx +1 -1
  103. package/src/components/ui/toast.tsx +1 -1
  104. package/src/components/workspace-app-card.spec.tsx +80 -0
  105. package/src/components/workspace-app-card.tsx +36 -25
  106. package/src/components/workspace-resource-effective-stack.tsx +13 -1
  107. package/src/components/workspace-resource-impact-preview.tsx +12 -1
  108. package/src/routes/pages/$appId.tsx +17 -1
  109. package/src/routes/pages/agents.tsx +24 -11
  110. package/src/routes/pages/approval.tsx +16 -4
  111. package/src/routes/pages/approvals.tsx +108 -89
  112. package/src/routes/pages/apps.$appId.tsx +9 -2
  113. package/src/routes/pages/apps.tsx +20 -7
  114. package/src/routes/pages/audit.tsx +29 -20
  115. package/src/routes/pages/chat.spec.tsx +94 -0
  116. package/src/routes/pages/chat.tsx +30 -10
  117. package/src/routes/pages/destinations.tsx +75 -62
  118. package/src/routes/pages/identities.tsx +74 -63
  119. package/src/routes/pages/integrations.tsx +17 -10
  120. package/src/routes/pages/thread-debug.tsx +18 -12
  121. package/src/routes/pages/vault.tsx +59 -26
  122. package/src/routes/pages/workspace.tsx +69 -55
  123. package/src/server/lib/approval-fencing.spec.ts +113 -2
  124. package/src/server/lib/dispatch-store.ts +2 -0
  125. package/src/server/lib/mcp-access-store.spec.ts +116 -4
  126. package/src/server/lib/mcp-access-store.ts +37 -2
  127. package/src/server/lib/mcp-gateway.spec.ts +79 -3
@@ -11,6 +11,7 @@ import { useQueryClient } from "@tanstack/react-query";
11
11
  import { useMemo, useState } from "react";
12
12
  import { toast } from "sonner";
13
13
 
14
+ import { ActionQueryError } from "../../components/action-query-error";
14
15
  import { DispatchShell } from "../../components/dispatch-shell";
15
16
  import { Badge } from "../../components/ui/badge";
16
17
  import { Button } from "../../components/ui/button";
@@ -319,14 +320,10 @@ function PerAppDetailRow({ app }: { app: CatalogApp }) {
319
320
  }
320
321
 
321
322
  export default function ConnectionsRoute() {
322
- const { data: catalog, isLoading } = useActionQuery(
323
- "list-integrations-catalog",
324
- {},
325
- );
326
- const { data: accessSettings } = useActionQuery(
327
- "get-vault-access-settings",
328
- {},
329
- );
323
+ const catalogQuery = useActionQuery("list-integrations-catalog", {});
324
+ const accessQuery = useActionQuery("get-vault-access-settings", {});
325
+ const { data: catalog, isLoading } = catalogQuery;
326
+ const { data: accessSettings } = accessQuery;
330
327
  const apps = (catalog as CatalogApp[]) || [];
331
328
  const accessMode =
332
329
  (accessSettings as any)?.mode === "manual" ? "manual" : "all-apps";
@@ -365,13 +362,23 @@ export default function ConnectionsRoute() {
365
362
  title="Connections"
366
363
  description="Connect services once. Apps that need them pick up the key automatically."
367
364
  >
368
- {isLoading && services.length === 0 && (
365
+ {catalogQuery.isError || accessQuery.isError ? (
366
+ <ActionQueryError
367
+ error={catalogQuery.error ?? accessQuery.error}
368
+ onRetry={() => {
369
+ void catalogQuery.refetch();
370
+ void accessQuery.refetch();
371
+ }}
372
+ />
373
+ ) : null}
374
+
375
+ {!catalogQuery.isError && isLoading && services.length === 0 && (
369
376
  <div className="rounded-2xl border border-dashed px-6 py-12 text-center text-sm text-muted-foreground">
370
377
  Discovering apps and credentials…
371
378
  </div>
372
379
  )}
373
380
 
374
- {!isLoading && services.length === 0 && (
381
+ {!catalogQuery.isError && !isLoading && services.length === 0 && (
375
382
  <div className="rounded-2xl border border-dashed px-6 py-12 text-center text-sm text-muted-foreground">
376
383
  No apps with declared integrations are reachable yet.
377
384
  </div>
@@ -7,8 +7,8 @@ import {
7
7
  } from "@tabler/icons-react";
8
8
  import { useEffect, useMemo, useState } from "react";
9
9
 
10
+ import { ActionQueryError } from "../../components/action-query-error";
10
11
  import { DispatchShell } from "../../components/dispatch-shell";
11
- import { Alert, AlertDescription, AlertTitle } from "../../components/ui/alert";
12
12
  import { Badge } from "../../components/ui/badge";
13
13
  import { Button } from "../../components/ui/button";
14
14
  import { Input } from "../../components/ui/input";
@@ -430,7 +430,7 @@ export default function ThreadDebugRoute() {
430
430
  ownerEmail?: string;
431
431
  } | null>(null);
432
432
 
433
- const { data: sourcesData, isLoading: sourcesLoading } = useActionQuery<{
433
+ const sourcesQuery = useActionQuery<{
434
434
  access: {
435
435
  viewerEmail: string;
436
436
  orgId: string | null;
@@ -441,6 +441,7 @@ export default function ThreadDebugRoute() {
441
441
  };
442
442
  sources: ThreadDebugSource[];
443
443
  }>("list-agent-thread-sources", {});
444
+ const { data: sourcesData, isLoading: sourcesLoading } = sourcesQuery;
444
445
 
445
446
  const sources: ThreadDebugSource[] = sourcesData?.sources ?? [];
446
447
  const searchParams = useMemo(
@@ -480,6 +481,7 @@ export default function ThreadDebugRoute() {
480
481
  data: detail,
481
482
  isLoading: detailLoading,
482
483
  error: detailError,
484
+ refetch: refetchDetail,
483
485
  } = useActionQuery<ThreadDebugResponse>(
484
486
  "get-agent-thread-debug",
485
487
  detailParams,
@@ -515,6 +517,12 @@ export default function ThreadDebugRoute() {
515
517
  description="Inspect persisted agent chat threads, run events, and AI internals."
516
518
  >
517
519
  <div className="space-y-4">
520
+ {sourcesQuery.isError ? (
521
+ <ActionQueryError
522
+ error={sourcesQuery.error}
523
+ onRetry={() => void sourcesQuery.refetch()}
524
+ />
525
+ ) : null}
518
526
  <section className="rounded-lg border bg-card p-4">
519
527
  <div className="grid gap-3 lg:grid-cols-[220px_1fr_260px_auto]">
520
528
  <Select value={sourceId} onValueChange={setSourceId}>
@@ -600,10 +608,10 @@ export default function ThreadDebugRoute() {
600
608
  </section>
601
609
 
602
610
  {searchError ? (
603
- <Alert variant="destructive">
604
- <AlertTitle>Search failed</AlertTitle>
605
- <AlertDescription>{String(searchError.message)}</AlertDescription>
606
- </Alert>
611
+ <ActionQueryError
612
+ error={searchError}
613
+ onRetry={() => void refetchSearch()}
614
+ />
607
615
  ) : null}
608
616
 
609
617
  <div className="grid gap-4 xl:grid-cols-[380px_1fr]">
@@ -661,12 +669,10 @@ export default function ThreadDebugRoute() {
661
669
 
662
670
  <section className="min-w-0">
663
671
  {detailError ? (
664
- <Alert variant="destructive">
665
- <AlertTitle>Thread lookup failed</AlertTitle>
666
- <AlertDescription>
667
- {String(detailError.message)}
668
- </AlertDescription>
669
- </Alert>
672
+ <ActionQueryError
673
+ error={detailError}
674
+ onRetry={() => void refetchDetail()}
675
+ />
670
676
  ) : null}
671
677
  {detailLoading ? (
672
678
  <div className="rounded-lg border bg-card p-4">
@@ -14,6 +14,7 @@ import {
14
14
  import { useState } from "react";
15
15
  import { toast } from "sonner";
16
16
 
17
+ import { ActionQueryError } from "../../components/action-query-error";
17
18
  import { DispatchShell } from "../../components/dispatch-shell";
18
19
  import {
19
20
  AlertDialog,
@@ -736,17 +737,16 @@ function RequestRow({ request }: { request: any }) {
736
737
  }
737
738
 
738
739
  export default function VaultRoute() {
739
- const { data: secrets, isLoading: secretsLoading } = useActionQuery(
740
- "list-vault-secrets",
741
- {},
742
- );
743
- const { data: grants } = useActionQuery("list-vault-grants", {});
744
- const { data: requests } = useActionQuery("list-vault-requests", {});
745
- const { data: audit } = useActionQuery("list-vault-audit", { limit: 20 });
746
- const { data: accessSettings } = useActionQuery(
747
- "get-vault-access-settings",
748
- {},
749
- );
740
+ const secretsQuery = useActionQuery("list-vault-secrets", {});
741
+ const grantsQuery = useActionQuery("list-vault-grants", {});
742
+ const requestsQuery = useActionQuery("list-vault-requests", {});
743
+ const auditQuery = useActionQuery("list-vault-audit", { limit: 20 });
744
+ const accessQuery = useActionQuery("get-vault-access-settings", {});
745
+ const { data: secrets, isLoading: secretsLoading } = secretsQuery;
746
+ const { data: grants } = grantsQuery;
747
+ const { data: requests } = requestsQuery;
748
+ const { data: audit } = auditQuery;
749
+ const { data: accessSettings } = accessQuery;
750
750
  const accessMode: VaultAccessMode =
751
751
  (accessSettings as any)?.mode === "manual" ? "manual" : "all-apps";
752
752
 
@@ -788,6 +788,20 @@ export default function VaultRoute() {
788
788
  </TabsList>
789
789
 
790
790
  <TabsContent value="secrets" className="mt-4 space-y-3">
791
+ {secretsQuery.isError ||
792
+ grantsQuery.isError ||
793
+ accessQuery.isError ? (
794
+ <ActionQueryError
795
+ error={
796
+ secretsQuery.error ?? grantsQuery.error ?? accessQuery.error
797
+ }
798
+ onRetry={() => {
799
+ void secretsQuery.refetch();
800
+ void grantsQuery.refetch();
801
+ void accessQuery.refetch();
802
+ }}
803
+ />
804
+ ) : null}
791
805
  <VaultAccessSettingsCard mode={accessMode} />
792
806
 
793
807
  <div className="flex items-center justify-between">
@@ -804,7 +818,9 @@ export default function VaultRoute() {
804
818
  <AddSecretDialog />
805
819
  </div>
806
820
 
807
- {secretsLoading && (secrets ?? []).length === 0
821
+ {!secretsQuery.isError &&
822
+ secretsLoading &&
823
+ (secrets ?? []).length === 0
808
824
  ? Array.from({ length: 3 }).map((_, index) => (
809
825
  <div
810
826
  key={index}
@@ -823,25 +839,36 @@ export default function VaultRoute() {
823
839
  />
824
840
  ))}
825
841
 
826
- {!secretsLoading && (secrets?.length || 0) === 0 && (
827
- <div className="rounded-2xl border border-dashed px-6 py-12 text-center">
828
- <IconKey size={32} className="mx-auto text-muted-foreground/50" />
829
- <h3 className="mt-3 text-sm font-medium text-foreground">
830
- No secrets yet
831
- </h3>
832
- <p className="mt-1 text-sm text-muted-foreground">
833
- Add your first secret to start sharing credentials across
834
- workspace apps.
835
- </p>
836
- </div>
837
- )}
842
+ {!secretsQuery.isError &&
843
+ !secretsLoading &&
844
+ (secrets?.length || 0) === 0 && (
845
+ <div className="rounded-2xl border border-dashed px-6 py-12 text-center">
846
+ <IconKey
847
+ size={32}
848
+ className="mx-auto text-muted-foreground/50"
849
+ />
850
+ <h3 className="mt-3 text-sm font-medium text-foreground">
851
+ No secrets yet
852
+ </h3>
853
+ <p className="mt-1 text-sm text-muted-foreground">
854
+ Add your first secret to start sharing credentials across
855
+ workspace apps.
856
+ </p>
857
+ </div>
858
+ )}
838
859
  </TabsContent>
839
860
 
840
861
  <TabsContent value="requests" className="mt-4 space-y-3">
862
+ {requestsQuery.isError ? (
863
+ <ActionQueryError
864
+ error={requestsQuery.error}
865
+ onRetry={() => void requestsQuery.refetch()}
866
+ />
867
+ ) : null}
841
868
  {(requests || []).map((request: any) => (
842
869
  <RequestRow key={request.id} request={request} />
843
870
  ))}
844
- {(requests?.length || 0) === 0 && (
871
+ {!requestsQuery.isError && (requests?.length || 0) === 0 && (
845
872
  <div className="rounded-2xl border border-dashed px-6 py-12 text-center text-sm text-muted-foreground">
846
873
  No secret requests yet.
847
874
  </div>
@@ -849,6 +876,12 @@ export default function VaultRoute() {
849
876
  </TabsContent>
850
877
 
851
878
  <TabsContent value="audit" className="mt-4 space-y-2">
879
+ {auditQuery.isError ? (
880
+ <ActionQueryError
881
+ error={auditQuery.error}
882
+ onRetry={() => void auditQuery.refetch()}
883
+ />
884
+ ) : null}
852
885
  {(audit || []).map((event: any) => (
853
886
  <div
854
887
  key={event.id}
@@ -862,7 +895,7 @@ export default function VaultRoute() {
862
895
  </div>
863
896
  </div>
864
897
  ))}
865
- {(audit?.length || 0) === 0 && (
898
+ {!auditQuery.isError && (audit?.length || 0) === 0 && (
866
899
  <div className="rounded-2xl border border-dashed px-6 py-12 text-center text-sm text-muted-foreground">
867
900
  No vault activity yet.
868
901
  </div>
@@ -17,6 +17,7 @@ import {
17
17
  import { useEffect, useState, type ReactNode } from "react";
18
18
  import { toast } from "sonner";
19
19
 
20
+ import { ActionQueryError } from "../../components/action-query-error";
20
21
  import { DispatchShell } from "../../components/dispatch-shell";
21
22
  import {
22
23
  AlertDialog,
@@ -1014,11 +1015,10 @@ function GlobalContextSection({ resources }: { resources: any[] }) {
1014
1015
  }
1015
1016
 
1016
1017
  export default function WorkspaceRoute() {
1017
- const { data: resources, isLoading } = useActionQuery(
1018
- "list-workspace-resources",
1019
- {},
1020
- );
1021
- const { data: grants } = useActionQuery("list-workspace-resource-grants", {});
1018
+ const resourcesQuery = useActionQuery("list-workspace-resources", {});
1019
+ const grantsQuery = useActionQuery("list-workspace-resource-grants", {});
1020
+ const { data: resources, isLoading } = resourcesQuery;
1021
+ const { data: grants } = grantsQuery;
1022
1022
 
1023
1023
  const grantsByResource = (grants || []).reduce(
1024
1024
  (acc: Record<string, any[]>, g: any) => {
@@ -1088,6 +1088,15 @@ export default function WorkspaceRoute() {
1088
1088
  title="Workspace Resources"
1089
1089
  description="Manage inherited workspace skills, guardrail instructions, agent profiles, reference resources, and MCP servers. All-app resources are available to every app without syncing."
1090
1090
  >
1091
+ {resourcesQuery.isError || grantsQuery.isError ? (
1092
+ <ActionQueryError
1093
+ error={resourcesQuery.error ?? grantsQuery.error}
1094
+ onRetry={() => {
1095
+ void resourcesQuery.refetch();
1096
+ void grantsQuery.refetch();
1097
+ }}
1098
+ />
1099
+ ) : null}
1091
1100
  <div className="flex items-center justify-between">
1092
1101
  <div className="text-sm text-muted-foreground">
1093
1102
  {isLoading ? (
@@ -1101,62 +1110,67 @@ export default function WorkspaceRoute() {
1101
1110
  </div>
1102
1111
  </div>
1103
1112
 
1104
- <GlobalContextSection resources={resources || []} />
1113
+ {!resourcesQuery.isError ? (
1114
+ <GlobalContextSection resources={resources || []} />
1115
+ ) : null}
1105
1116
 
1106
- <Tabs defaultValue="skills">
1107
- <TabsList>
1108
- <TabsTrigger value="skills">
1109
- Skills {skills.length > 0 && `(${skills.length})`}
1110
- </TabsTrigger>
1111
- <TabsTrigger value="instructions">
1112
- Instructions {instructions.length > 0 && `(${instructions.length})`}
1113
- </TabsTrigger>
1114
- <TabsTrigger value="agents">
1115
- Agents {agents.length > 0 && `(${agents.length})`}
1116
- </TabsTrigger>
1117
- <TabsTrigger value="knowledge">
1118
- Knowledge {knowledge.length > 0 && `(${knowledge.length})`}
1119
- </TabsTrigger>
1120
- <TabsTrigger value="mcp">
1121
- MCP {mcpServers.length > 0 && `(${mcpServers.length})`}
1122
- </TabsTrigger>
1123
- </TabsList>
1117
+ {!resourcesQuery.isError && !grantsQuery.isError ? (
1118
+ <Tabs defaultValue="skills">
1119
+ <TabsList>
1120
+ <TabsTrigger value="skills">
1121
+ Skills {skills.length > 0 && `(${skills.length})`}
1122
+ </TabsTrigger>
1123
+ <TabsTrigger value="instructions">
1124
+ Instructions{" "}
1125
+ {instructions.length > 0 && `(${instructions.length})`}
1126
+ </TabsTrigger>
1127
+ <TabsTrigger value="agents">
1128
+ Agents {agents.length > 0 && `(${agents.length})`}
1129
+ </TabsTrigger>
1130
+ <TabsTrigger value="knowledge">
1131
+ Knowledge {knowledge.length > 0 && `(${knowledge.length})`}
1132
+ </TabsTrigger>
1133
+ <TabsTrigger value="mcp">
1134
+ MCP {mcpServers.length > 0 && `(${mcpServers.length})`}
1135
+ </TabsTrigger>
1136
+ </TabsList>
1124
1137
 
1125
- <TabsContent value="skills" className="mt-4">
1126
- <ResourceList
1127
- items={skills}
1128
- emptyText="No workspace skills yet. Add a skill to share agent guidance across apps."
1129
- />
1130
- </TabsContent>
1138
+ <TabsContent value="skills" className="mt-4">
1139
+ <ResourceList
1140
+ items={skills}
1141
+ emptyText="No workspace skills yet. Add a skill to share agent guidance across apps."
1142
+ />
1143
+ </TabsContent>
1131
1144
 
1132
- <TabsContent value="instructions" className="mt-4">
1133
- <ResourceList
1134
- items={instructions}
1135
- emptyText="No workspace instructions yet. Add instructions to set behavioral rules across apps."
1136
- />
1137
- </TabsContent>
1145
+ <TabsContent value="instructions" className="mt-4">
1146
+ <ResourceList
1147
+ items={instructions}
1148
+ emptyText="No workspace instructions yet. Add instructions to set behavioral rules across apps."
1149
+ />
1150
+ </TabsContent>
1138
1151
 
1139
- <TabsContent value="agents" className="mt-4">
1140
- <ResourceList
1141
- items={agents}
1142
- emptyText="No workspace agents yet. Add a reusable agent profile to share specialist agents across apps."
1143
- />
1144
- </TabsContent>
1152
+ <TabsContent value="agents" className="mt-4">
1153
+ <ResourceList
1154
+ items={agents}
1155
+ emptyText="No workspace agents yet. Add a reusable agent profile to share specialist agents across apps."
1156
+ />
1157
+ </TabsContent>
1145
1158
 
1146
- <TabsContent value="knowledge" className="mt-4">
1147
- <ResourceList
1148
- items={knowledge}
1149
- emptyText="No knowledge packs yet. Add GTM, product, or domain context that apps can reuse."
1150
- />
1151
- </TabsContent>
1159
+ <TabsContent value="knowledge" className="mt-4">
1160
+ <ResourceList
1161
+ items={knowledge}
1162
+ emptyText="No knowledge packs yet. Add GTM, product, or domain context that apps can reuse."
1163
+ />
1164
+ </TabsContent>
1152
1165
 
1153
- <TabsContent value="mcp" className="mt-4">
1154
- <ResourceList
1155
- items={mcpServers}
1156
- emptyText="No workspace MCP servers yet. Add an HTTP MCP server to share external tools across apps."
1157
- />
1158
- </TabsContent>
1159
- </Tabs>
1166
+ <TabsContent value="mcp" className="mt-4">
1167
+ <ResourceList
1168
+ items={mcpServers}
1169
+ emptyText="No workspace MCP servers yet. Add an HTTP MCP server to share external tools across apps."
1170
+ />
1171
+ </TabsContent>
1172
+ </Tabs>
1173
+ ) : null}
1160
1174
  </DispatchShell>
1161
1175
  );
1162
1176
  }
@@ -5,11 +5,15 @@ import path from "node:path";
5
5
  import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
6
6
 
7
7
  // Each test runs real migrations against a fresh SQLite file; under full
8
- // workspace concurrency that setup can exceed the 5s default timeout.
9
- vi.setConfig({ testTimeout: 30_000 });
8
+ // workspace concurrency (and a shared machine running other suites) that
9
+ // setup can far exceed the 5s default, so give it generous headroom. The
10
+ // tests themselves complete in a few seconds uncontended.
11
+ vi.setConfig({ testTimeout: 60_000, hookTimeout: 60_000 });
10
12
 
11
13
  const ownerEmail = "owner+approval-fencing@example.test";
12
14
  const orgId = "org_approval_fencing";
15
+ const otherOwnerEmail = "owner+approval-fencing-other@example.test";
16
+ const otherOrgId = "org_approval_fencing_other";
13
17
 
14
18
  const originalEnv = {
15
19
  APP_NAME: process.env.APP_NAME,
@@ -210,6 +214,113 @@ describe("dispatch approval request status fencing", () => {
210
214
  expect(await rejectedAuditCount()).toBe(1);
211
215
  });
212
216
  });
217
+
218
+ it("does not let a caller from a different tenant approve another tenant's request", async () => {
219
+ const [{ runWithRequestContext }, { getDbExec }, dispatchStore] =
220
+ await Promise.all([
221
+ import("@agent-native/core/server"),
222
+ import("@agent-native/core/db"),
223
+ import("./dispatch-store.js"),
224
+ ]);
225
+ const exec = getDbExec();
226
+
227
+ const requestId = await runWithRequestContext(
228
+ { userEmail: ownerEmail, orgId },
229
+ async () => {
230
+ const created = await dispatchStore.createApprovalRequest({
231
+ changeType: "approval-policy.update",
232
+ targetType: "dispatch-settings",
233
+ targetId: "dispatch-approval-policy",
234
+ summary: "Enable approval policy for tenant A",
235
+ payload: { enabled: true, approverEmails: ["reviewer@example.test"] },
236
+ });
237
+ return (created as any).id as string;
238
+ },
239
+ );
240
+
241
+ await runWithRequestContext(
242
+ { userEmail: otherOwnerEmail, orgId: otherOrgId },
243
+ async () => {
244
+ await expect(dispatchStore.approveRequest(requestId)).rejects.toThrow(
245
+ "Approval request not found",
246
+ );
247
+ },
248
+ );
249
+
250
+ const rows = await exec.execute({
251
+ sql: "SELECT status, reviewed_by, reviewed_at FROM dispatch_approval_requests WHERE id = ?",
252
+ args: [requestId],
253
+ });
254
+ expect(rows.rows[0]).toMatchObject({
255
+ status: "pending",
256
+ reviewed_by: null,
257
+ reviewed_at: null,
258
+ });
259
+
260
+ const approvedAuditRows = await exec.execute({
261
+ sql: "SELECT COUNT(*) as count FROM dispatch_audit_events WHERE action = 'approval.approved' AND target_id = ?",
262
+ args: [requestId],
263
+ });
264
+ expect(Number((approvedAuditRows.rows[0] as any).count)).toBe(0);
265
+
266
+ // Confirm no side effect landed either: the policy change must not have
267
+ // been applied to tenant A's org settings by the foreign-tenant attempt.
268
+ await runWithRequestContext({ userEmail: ownerEmail, orgId }, async () => {
269
+ expect(await dispatchStore.getApprovalPolicy()).toEqual({
270
+ enabled: false,
271
+ approverEmails: [],
272
+ });
273
+ });
274
+ });
275
+
276
+ it("does not let a caller from a different tenant reject another tenant's request", async () => {
277
+ const [{ runWithRequestContext }, { getDbExec }, dispatchStore] =
278
+ await Promise.all([
279
+ import("@agent-native/core/server"),
280
+ import("@agent-native/core/db"),
281
+ import("./dispatch-store.js"),
282
+ ]);
283
+ const exec = getDbExec();
284
+
285
+ const requestId = await runWithRequestContext(
286
+ { userEmail: ownerEmail, orgId },
287
+ async () => {
288
+ const created = await dispatchStore.createApprovalRequest({
289
+ changeType: "approval-policy.update",
290
+ targetType: "dispatch-settings",
291
+ targetId: "dispatch-approval-policy",
292
+ summary: "Enable approval policy for tenant A (reject case)",
293
+ payload: { enabled: true, approverEmails: ["reviewer@example.test"] },
294
+ });
295
+ return (created as any).id as string;
296
+ },
297
+ );
298
+
299
+ await runWithRequestContext(
300
+ { userEmail: otherOwnerEmail, orgId: otherOrgId },
301
+ async () => {
302
+ await expect(
303
+ dispatchStore.rejectRequest(requestId, "not my call"),
304
+ ).rejects.toThrow("Approval request not found");
305
+ },
306
+ );
307
+
308
+ const rows = await exec.execute({
309
+ sql: "SELECT status, reviewed_by, reviewed_at FROM dispatch_approval_requests WHERE id = ?",
310
+ args: [requestId],
311
+ });
312
+ expect(rows.rows[0]).toMatchObject({
313
+ status: "pending",
314
+ reviewed_by: null,
315
+ reviewed_at: null,
316
+ });
317
+
318
+ const rejectedAuditRows = await exec.execute({
319
+ sql: "SELECT COUNT(*) as count FROM dispatch_audit_events WHERE action = 'approval.rejected' AND target_id = ?",
320
+ args: [requestId],
321
+ });
322
+ expect(Number((rejectedAuditRows.rows[0] as any).count)).toBe(0);
323
+ });
213
324
  });
214
325
 
215
326
  describe("vault request status fencing", () => {
@@ -681,6 +681,7 @@ export async function approveRequest(requestId: string) {
681
681
  .where(
682
682
  and(
683
683
  eq(schema.dispatchApprovalRequests.id, requestId),
684
+ ctxScope(schema.dispatchApprovalRequests, ctx),
684
685
  eq(schema.dispatchApprovalRequests.status, "applying"),
685
686
  ),
686
687
  )
@@ -714,6 +715,7 @@ export async function rejectRequest(requestId: string, reason?: string | null) {
714
715
  .where(
715
716
  and(
716
717
  eq(schema.dispatchApprovalRequests.id, requestId),
718
+ ctxScope(schema.dispatchApprovalRequests, ctx),
717
719
  eq(schema.dispatchApprovalRequests.status, "pending"),
718
720
  ),
719
721
  )