@tangle-network/agent-app 0.58.7 → 0.58.9

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.
@@ -1,6 +1,6 @@
1
1
  export { HubConnectCallbackPage, type HubConnectCallbackPageProps } from './callback';
2
2
  export { createHubIntegrationsClient, type HubIntegrationsClient, type HubIntegrationsIdentity, type HubSettingsRequest, type HubSettingsRequestFn } from './client';
3
- export { HubIntegrationsPanel, type HubIntegrationsPanelProps } from './panel';
3
+ export { HubIntegrationsPanel, type HubAccountStatus, type HubIntegrationsAccounts, type HubIntegrationsPanelProps } from './panel';
4
4
  export { HUB_CONNECT_CHANNEL, HUB_CONNECTED_MESSAGE_TYPE, HUB_CONNECT_FAILED_MESSAGE_TYPE, POPUP_TIMEOUT_MS } from './popup';
5
5
  export { useHubIntegrations, type HubWriteReceipt, type UseHubIntegrationsOptions } from './use-hub-integrations';
6
6
  export { type HubIntegrationCapabilities, type HubIntegrationCapability } from './projection';
@@ -307,9 +307,10 @@ import {
307
307
  ApiKeyConnectDialog,
308
308
  IntegrationConnectionDetail,
309
309
  IntegrationsCatalog,
310
- OAuthConnectionParameterDialog
310
+ OAuthConnectionParameterDialog,
311
+ ProviderIcon
311
312
  } from "@tangle-network/sandbox-ui/integrations";
312
- import { Button } from "@tangle-network/ui/primitives";
313
+ import { Button, StatusPill } from "@tangle-network/ui/primitives";
313
314
  import { useEffect as useEffect3, useMemo as useMemo2, useRef as useRef2, useState as useState3 } from "react";
314
315
 
315
316
  // src/integrations-react/projection.ts
@@ -638,6 +639,82 @@ function catalogHref() {
638
639
  url.searchParams.delete("connection");
639
640
  return `${url.pathname}${url.search}${url.hash}`;
640
641
  }
642
+ function accountName(connection, providerTitle) {
643
+ return connection.accountDisplay?.trim() || connection.displayName?.trim() || providerTitle;
644
+ }
645
+ function AccountStatus({ connection, accounts }) {
646
+ const status = accounts.getStatus?.(connection);
647
+ return status ? /* @__PURE__ */ jsx2(StatusPill, { tone: status.tone ?? "neutral", size: "sm", className: "shrink-0", children: status.label }) : null;
648
+ }
649
+ function AccountPrimaryAction({ connection, accounts, busy }) {
650
+ const primary = accounts.getPrimaryAction?.(connection);
651
+ return primary ? /* @__PURE__ */ jsx2(
652
+ Button,
653
+ {
654
+ type: "button",
655
+ variant: "outline",
656
+ size: "sm",
657
+ disabled: busy || primary.disabled,
658
+ onClick: primary.onSelect,
659
+ children: primary.label
660
+ }
661
+ ) : null;
662
+ }
663
+ function HubAccountList({ accounts, connections, providers, loading, error, busy, onRetry, onManage, canManage }) {
664
+ const titles = new Map(providers.map((provider) => [provider.providerId, provider.title]));
665
+ const title = (connection) => titles.get(connection.providerId) ?? connection.displayName ?? connection.providerId;
666
+ const rows = connections.filter((connection) => connection.status !== "revoked").map((connection) => ({ connection, provider: title(connection), name: accountName(connection, title(connection)) })).sort((a, b) => a.provider.localeCompare(b.provider) || a.name.localeCompare(b.name) || a.connection.id.localeCompare(b.connection.id));
667
+ return /* @__PURE__ */ jsxs2("section", { className: "mb-8 min-w-0 space-y-3", "aria-labelledby": "hub-accounts-heading", "aria-busy": loading || void 0, children: [
668
+ /* @__PURE__ */ jsxs2("header", { children: [
669
+ /* @__PURE__ */ jsx2("h2", { id: "hub-accounts-heading", className: "text-lg font-semibold", children: accounts.title }),
670
+ accounts.description ? /* @__PURE__ */ jsx2("p", { className: "mt-1 text-sm text-muted-foreground", children: accounts.description }) : null
671
+ ] }),
672
+ error ? /* @__PURE__ */ jsxs2("div", { role: "alert", className: "flex flex-wrap items-center gap-3 rounded-xl border border-destructive/40 bg-card p-4 text-sm text-destructive", children: [
673
+ /* @__PURE__ */ jsx2("p", { className: "min-w-0 flex-1 break-words", children: error }),
674
+ /* @__PURE__ */ jsx2(Button, { type: "button", variant: "outline", size: "sm", onClick: onRetry, children: "Retry" })
675
+ ] }) : loading && rows.length === 0 ? /* @__PURE__ */ jsx2("p", { role: "status", className: "rounded-xl border border-border bg-card p-4 text-sm text-muted-foreground", children: "Loading connected accounts\u2026" }) : rows.length === 0 ? /* @__PURE__ */ jsx2("p", { className: "rounded-xl border border-dashed border-border p-4 text-sm text-muted-foreground", children: accounts.emptyLabel ?? "No accounts connected yet. Connect one below." }) : /* @__PURE__ */ jsx2("ul", { className: "divide-y divide-border overflow-hidden rounded-xl border border-border bg-card", "aria-label": accounts.title, children: rows.map(({ connection, provider, name }) => {
676
+ const health = connection.status !== "active" ? connection.status.replaceAll("_", " ") : connection.health === "unhealthy" ? "needs attention" : null;
677
+ return /* @__PURE__ */ jsxs2(
678
+ "li",
679
+ {
680
+ "data-testid": `hub-account-${connection.id}`,
681
+ className: "flex min-w-0 flex-wrap items-center gap-x-4 gap-y-2 px-4 py-3",
682
+ children: [
683
+ /* @__PURE__ */ jsxs2("div", { className: "flex min-w-0 flex-1 basis-56 items-center gap-3", children: [
684
+ /* @__PURE__ */ jsx2(ProviderIcon, { id: connection.providerId, displayName: provider, size: 32, className: "shrink-0 rounded-lg" }),
685
+ /* @__PURE__ */ jsxs2("div", { className: "min-w-0", children: [
686
+ /* @__PURE__ */ jsx2("p", { className: "truncate text-sm font-medium", title: name, children: name }),
687
+ /* @__PURE__ */ jsxs2("p", { className: "truncate text-xs text-muted-foreground", children: [
688
+ provider,
689
+ health ? ` \xB7 ${health}` : ""
690
+ ] })
691
+ ] })
692
+ ] }),
693
+ /* @__PURE__ */ jsxs2("div", { className: "flex min-w-0 flex-wrap items-center gap-2 sm:justify-end", children: [
694
+ /* @__PURE__ */ jsx2(AccountStatus, { connection, accounts }),
695
+ /* @__PURE__ */ jsxs2("div", { className: "flex shrink-0 items-center gap-1", children: [
696
+ /* @__PURE__ */ jsx2(AccountPrimaryAction, { connection, accounts, busy }),
697
+ canManage(connection) ? /* @__PURE__ */ jsx2(
698
+ Button,
699
+ {
700
+ type: "button",
701
+ variant: "ghost",
702
+ size: "sm",
703
+ "aria-label": `Manage ${provider} account ${name}`,
704
+ onClick: () => onManage(connection),
705
+ children: "Manage"
706
+ }
707
+ ) : null
708
+ ] })
709
+ ] })
710
+ ]
711
+ },
712
+ connection.id
713
+ );
714
+ }) }),
715
+ accounts.footer
716
+ ] });
717
+ }
641
718
  function HubIntegrationsPanel(props) {
642
719
  const hub = useHubIntegrations(props);
643
720
  const scope = contextKey(props.identity);
@@ -684,6 +761,9 @@ function HubIntegrationsPanel(props) {
684
761
  };
685
762
  });
686
763
  const selectedRow = rows.find((row) => row.providerId === hub.provider?.providerId);
764
+ const catalogRows2 = props.accounts ? rows.filter((row) => row.connections.length === 0) : rows;
765
+ const connectionList = hub.connections.status === "ready" ? hub.connections.value : [];
766
+ const selectedConnection = hub.connection;
687
767
  const detailError = hub.detail.status === "error" ? hub.detail.message : hub.detail.status === "ready" && hub.detail.value.truncated ? `Showing at most ${hub.detail.value.tools.length} actions. The provider catalog may be incomplete.` : null;
688
768
  const detailsByConnectionId = useMemo2(() => hub.connection ? {
689
769
  [hub.connection.id]: {
@@ -710,16 +790,33 @@ function HubIntegrationsPanel(props) {
710
790
  writeMessage ? /* @__PURE__ */ jsx2("p", { role: writeWarning ? "alert" : "status", children: writeMessage }) : null,
711
791
  hub.connectStatus.message && hub.provider ? /* @__PURE__ */ jsx2("p", { role: hub.connectStatus.status === "failed" ? "alert" : "status", children: hub.connectStatus.message }) : null,
712
792
  hub.provider ? /* @__PURE__ */ jsxs2(Fragment, { children: [
713
- selectedRow?.canConnect ? /* @__PURE__ */ jsx2("div", { className: "mb-4 flex justify-end", children: /* @__PURE__ */ jsx2(
714
- Button,
715
- {
716
- type: "button",
717
- variant: "outline",
718
- disabled: pending,
719
- onClick: () => hub.beginConnect(hub.provider),
720
- children: "Connect another account"
721
- }
722
- ) }) : null,
793
+ props.accounts && selectedConnection || selectedRow?.canConnect ? /* @__PURE__ */ jsxs2("div", { className: "mb-4 flex min-w-0 flex-wrap items-center gap-2", children: [
794
+ props.accounts && selectedConnection ? /* @__PURE__ */ jsxs2(
795
+ "div",
796
+ {
797
+ className: "flex min-w-0 flex-1 flex-wrap items-center gap-2",
798
+ "data-testid": "hub-account-access",
799
+ "aria-label": `Access for ${accountName(selectedConnection, hub.provider.title)}`,
800
+ role: "group",
801
+ children: [
802
+ /* @__PURE__ */ jsx2("span", { className: "min-w-0 max-w-full truncate text-sm font-medium", children: accountName(selectedConnection, hub.provider.title) }),
803
+ /* @__PURE__ */ jsx2(AccountStatus, { connection: selectedConnection, accounts: props.accounts }),
804
+ /* @__PURE__ */ jsx2(AccountPrimaryAction, { connection: selectedConnection, accounts: props.accounts, busy: pending })
805
+ ]
806
+ }
807
+ ) : null,
808
+ selectedRow?.canConnect ? /* @__PURE__ */ jsx2(
809
+ Button,
810
+ {
811
+ type: "button",
812
+ variant: "outline",
813
+ className: "ml-auto",
814
+ disabled: pending,
815
+ onClick: () => hub.beginConnect(hub.provider),
816
+ children: "Connect another account"
817
+ }
818
+ ) : null
819
+ ] }) : null,
723
820
  /* @__PURE__ */ jsx2(
724
821
  IntegrationConnectionDetail,
725
822
  {
@@ -747,39 +844,59 @@ function HubIntegrationsPanel(props) {
747
844
  }
748
845
  }
749
846
  )
750
- ] }) : /* @__PURE__ */ jsx2(
751
- IntegrationsCatalog,
752
- {
753
- title: props.title ?? "Integrations",
754
- rows,
755
- query,
756
- onQueryChange: setQuery,
757
- categoryFilter: category,
758
- onCategoryFilterChange: setCategory,
759
- sort,
760
- onSortChange: setSort,
761
- onSelectConnection: (providerId, connectionId) => setCatalogSelection((current) => ({
762
- scope,
763
- ids: { ...current.scope === scope ? current.ids : {}, [providerId]: connectionId }
764
- })),
765
- onConnect: (row) => {
766
- const provider = hub.providers.status === "ready" ? hub.providers.value.find((item) => item.providerId === row.providerId) : null;
767
- if (provider) hub.beginConnect(provider);
768
- },
769
- onManage: (connection, row) => hub.selectConnection(row.providerId, connection.id),
770
- onDisconnect: (connection) => {
771
- void hub.revoke(connection.id);
772
- },
773
- onRequestIntegration: props.onRequestIntegration,
774
- onRetry: () => hub.refresh(),
775
- loading: hub.providers.status === "loading" || hub.connections.status === "loading",
776
- error,
777
- actionError: mutationError,
778
- connectError: hub.connectStatus.status === "failed" ? hub.connectStatus.message : null,
779
- busyProviderId: hub.connectStatus.status === "pending" ? hub.connectStatus.providerId ?? null : null,
780
- reserveConnectionContext: true
781
- }
782
- ),
847
+ ] }) : /* @__PURE__ */ jsxs2(Fragment, { children: [
848
+ props.accounts ? /* @__PURE__ */ jsxs2(Fragment, { children: [
849
+ hub.connectStatus.status === "connected" && hub.connectStatus.message ? /* @__PURE__ */ jsx2("p", { role: "status", className: "mb-3 text-sm", children: hub.connectStatus.message }) : null,
850
+ /* @__PURE__ */ jsx2(
851
+ HubAccountList,
852
+ {
853
+ accounts: props.accounts,
854
+ connections: connectionList,
855
+ providers: hub.providers.status === "ready" ? hub.providers.value : [],
856
+ loading: hub.connections.status === "loading",
857
+ error: hub.connections.status === "error" ? hub.connections.message : null,
858
+ busy: pending,
859
+ onRetry: () => hub.refresh(),
860
+ onManage: (connection) => hub.selectConnection(connection.providerId, connection.id),
861
+ canManage: (connection) => props.can({ operation: "policies.list", connectionId: connection.id })
862
+ }
863
+ )
864
+ ] }) : null,
865
+ props.accounts && hub.connections.status === "error" ? null : /* @__PURE__ */ jsx2(
866
+ IntegrationsCatalog,
867
+ {
868
+ title: props.title ?? "Integrations",
869
+ rows: catalogRows2,
870
+ query,
871
+ onQueryChange: setQuery,
872
+ categoryFilter: category,
873
+ onCategoryFilterChange: setCategory,
874
+ sort,
875
+ onSortChange: setSort,
876
+ onSelectConnection: (providerId, connectionId) => setCatalogSelection((current) => ({
877
+ scope,
878
+ ids: { ...current.scope === scope ? current.ids : {}, [providerId]: connectionId }
879
+ })),
880
+ onConnect: (row) => {
881
+ const provider = hub.providers.status === "ready" ? hub.providers.value.find((item) => item.providerId === row.providerId) : null;
882
+ if (provider) hub.beginConnect(provider);
883
+ },
884
+ onManage: (connection, row) => hub.selectConnection(row.providerId, connection.id),
885
+ onDisconnect: (connection) => {
886
+ void hub.revoke(connection.id);
887
+ },
888
+ onRequestIntegration: props.onRequestIntegration,
889
+ onRetry: () => hub.refresh(),
890
+ loading: hub.providers.status === "loading" || hub.connections.status === "loading",
891
+ error,
892
+ actionError: mutationError,
893
+ connectError: hub.connectStatus.status === "failed" ? hub.connectStatus.message : null,
894
+ busyProviderId: hub.connectStatus.status === "pending" ? hub.connectStatus.providerId ?? null : null,
895
+ reserveConnectionContext: true,
896
+ emptyCatalogLabel: props.accounts && rows.length > 0 ? "Every available integration already has a connected account above." : void 0
897
+ }
898
+ )
899
+ ] }),
783
900
  hub.dialog?.kind === "api-key" ? /* @__PURE__ */ jsx2(
784
901
  ApiKeyConnectDialog,
785
902
  {