Show connector apps on the tools button
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "cobble",
|
||||
"version": "0.27.1",
|
||||
"version": "0.27.2",
|
||||
"module": "index.ts",
|
||||
"type": "module",
|
||||
"private": true,
|
||||
|
||||
@@ -2,6 +2,7 @@ import BunSQLite from "@moduletrace/bun-sqlite";
|
||||
import type { BotExtensionsPayload } from "@/src/types";
|
||||
import grabCrewRole from "../access/grab-crew-role";
|
||||
import countBotConnectors from "../connectors/count-bot-connectors";
|
||||
import grabBotConnectors from "../connectors/grab-bot-connectors";
|
||||
import grabExtensionsOverview from "./grab-extensions-overview";
|
||||
|
||||
type Params = {
|
||||
@@ -32,14 +33,27 @@ export default async function grabBotExtensionsOverview({
|
||||
BunSQLite.sql<{ kind: string }>({ sql: `SELECT kind FROM bots WHERE id = ?`, values: [bot_id] }),
|
||||
]);
|
||||
|
||||
const [overview, connector_count] = await Promise.all([
|
||||
const [overview, connector_count, connector_entries] = await Promise.all([
|
||||
grabExtensionsOverview({
|
||||
can_manage: role == "super_admin" || (role == "admin" && bot.payload?.[0]?.kind != "coordinator"),
|
||||
bot_id,
|
||||
workspace_id,
|
||||
}),
|
||||
countBotConnectors({ user_id, bot_id, workspace_id }),
|
||||
grabBotConnectors({ user_id, bot_id, workspace_id }),
|
||||
]);
|
||||
|
||||
return { ...overview, connector_count };
|
||||
/**
|
||||
* One icon per app, for the ones a connected account actually reaches
|
||||
* here: a pending sign-in has nothing to use yet.
|
||||
*/
|
||||
const connector_apps = connector_entries
|
||||
.filter((entry) => entry.accounts.some((account) => account.status == "connected"))
|
||||
.map((entry) => ({
|
||||
id: Number(entry.connector.id),
|
||||
name: entry.connector.name,
|
||||
logo: entry.connector.logo,
|
||||
}));
|
||||
|
||||
return { ...overview, connector_count, connector_apps };
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import Stack from "@moduletrace/twui/layout/Stack";
|
||||
import fetchApi from "@moduletrace/twui/utils/fetch/fetchApi";
|
||||
import { Plus } from "lucide-react";
|
||||
import type { APIResponseObject } from "@moduletrace/bunext/types";
|
||||
import type { BotConnectorEntry } from "@/src/types";
|
||||
import type { BotConnectorEntry, ConnectorAppIcon } from "@/src/types";
|
||||
import postAdminApi from "@/src/layouts/bots/(functions)/post-admin-api";
|
||||
import ComposerConnectorPicker from "./composer-connector-picker";
|
||||
import ComposerConnectorRow from "./composer-connector-row";
|
||||
@@ -25,6 +25,11 @@ type Props = {
|
||||
* count follows an add or a remove without a reload.
|
||||
*/
|
||||
onCount?: (count: number) => void;
|
||||
/**
|
||||
* The apps a connected account reaches here, told to the composer for the
|
||||
* icons on its tools button.
|
||||
*/
|
||||
onApps?: (apps: ConnectorAppIcon[]) => void;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -38,6 +43,7 @@ export default function ComposerConnectorsSection({
|
||||
workspace_id,
|
||||
open,
|
||||
onCount,
|
||||
onApps,
|
||||
}: Props) {
|
||||
const [items, setItems] = useState<BotConnectorEntry[]>();
|
||||
const [error, setError] = useState<string>();
|
||||
@@ -93,12 +99,23 @@ export default function ComposerConnectorsSection({
|
||||
|
||||
setItems(entries);
|
||||
onCount?.(entries.length);
|
||||
onApps?.(
|
||||
entries
|
||||
.filter((entry) =>
|
||||
entry.accounts.some((account) => account.status == "connected"),
|
||||
)
|
||||
.map((entry) => ({
|
||||
id: Number(entry.connector.id),
|
||||
name: entry.connector.name,
|
||||
logo: entry.connector.logo,
|
||||
})),
|
||||
);
|
||||
})();
|
||||
|
||||
return () => {
|
||||
live = false;
|
||||
};
|
||||
}, [open, bot_id, workspace_id, tick, onCount]);
|
||||
}, [open, bot_id, workspace_id, tick, onCount, onApps]);
|
||||
|
||||
return (
|
||||
<Stack className="w-full mt-4 pt-4 items-stretch border-0 border-t border-solid border-hairline">
|
||||
|
||||
@@ -2,6 +2,8 @@ import { useState } from "react";
|
||||
import Modal from "@moduletrace/twui/elements/Modal";
|
||||
import Button from "@moduletrace/twui/layout/Button";
|
||||
import H2 from "@moduletrace/twui/layout/H2";
|
||||
import Img from "@moduletrace/twui/layout/Img";
|
||||
import Row from "@moduletrace/twui/layout/Row";
|
||||
import Span from "@moduletrace/twui/layout/Span";
|
||||
import Stack from "@moduletrace/twui/layout/Stack";
|
||||
import { CircleAlert, type LucideIcon } from "lucide-react";
|
||||
@@ -10,6 +12,7 @@ import type {
|
||||
BotExtension,
|
||||
BotExtensionKind,
|
||||
BotExtensionsPayload,
|
||||
ConnectorAppIcon,
|
||||
} from "@/src/types";
|
||||
import ComposerConnectorsSection from "./composer-connectors-section";
|
||||
import ComposerToolRow from "./composer-tool-row";
|
||||
@@ -74,6 +77,13 @@ type Props = {
|
||||
* number follows an add or a remove without a reload.
|
||||
*/
|
||||
onConnectorCount?: (count: number) => void;
|
||||
/**
|
||||
* The apps a connector account reaches here, drawn as small circles
|
||||
* before the spanner (5 at most). Read with the count, so adding or
|
||||
* removing one shows without a reload.
|
||||
*/
|
||||
connector_apps?: ConnectorAppIcon[];
|
||||
onConnectorApps?: (apps: ConnectorAppIcon[]) => void;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -94,6 +104,8 @@ export default function ComposerToolsModal({
|
||||
connectors,
|
||||
connector_count = 0,
|
||||
onConnectorCount,
|
||||
connector_apps = [],
|
||||
onConnectorApps,
|
||||
}: Props) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const count = attached.length;
|
||||
@@ -102,6 +114,7 @@ export default function ComposerToolsModal({
|
||||
(item) => !item.enabled || item.state == "error",
|
||||
);
|
||||
const TriggerIcon = has_problem ? CircleAlert : copy.Icon;
|
||||
const app_icons = connector_apps.filter((app) => app.logo).slice(0, 5);
|
||||
const label = total
|
||||
? `${total} ${total == 1 ? copy.one : copy.many}`
|
||||
: copy.empty_label;
|
||||
@@ -115,7 +128,22 @@ export default function ComposerToolsModal({
|
||||
variant="ghost"
|
||||
color="gray"
|
||||
size="small"
|
||||
beforeIcon={<TriggerIcon size={12} aria-hidden />}
|
||||
beforeIcon={
|
||||
<Row className="items-center gap-1! flex-nowrap">
|
||||
{app_icons.map((app) => (
|
||||
<Img
|
||||
key={app.id}
|
||||
src={app.logo}
|
||||
alt={app.name}
|
||||
title={app.name}
|
||||
size={16}
|
||||
circle
|
||||
className="shrink-0 border border-hairline bg-white object-contain"
|
||||
/>
|
||||
))}
|
||||
<TriggerIcon size={12} aria-hidden />
|
||||
</Row>
|
||||
}
|
||||
className="shrink-0 gap-1! px-2! py-0.5! text-[12px] leading-4 text-ink-secondary"
|
||||
>
|
||||
{label}
|
||||
@@ -181,6 +209,7 @@ export default function ComposerToolsModal({
|
||||
workspace_id={connectors.workspace_id}
|
||||
open={open}
|
||||
onCount={onConnectorCount}
|
||||
onApps={onConnectorApps}
|
||||
/>
|
||||
) : null}
|
||||
</Modal>
|
||||
|
||||
@@ -2,7 +2,11 @@ import { useContext, useEffect, useState } from "react";
|
||||
import Row from "@moduletrace/twui/layout/Row";
|
||||
import Span from "@moduletrace/twui/layout/Span";
|
||||
import useExtensions from "@/src/hooks/use-extensions";
|
||||
import type { BotExtensionsPayload, BotWithLastMessage } from "@/src/types";
|
||||
import type {
|
||||
BotExtensionsPayload,
|
||||
BotWithLastMessage,
|
||||
ConnectorAppIcon,
|
||||
} from "@/src/types";
|
||||
import { BotComputersContext } from "../(data)/bot-computers-context";
|
||||
import { composerKnowledgebasesCopy, composerToolsCopy } from "../(data)/composer-extensions-copy";
|
||||
import ComposerBrowserButton from "./composer-browser-button";
|
||||
@@ -66,11 +70,18 @@ export default function ComposerTools({
|
||||
const [connector_count, set_connector_count] = useState(
|
||||
Number(initial?.connector_count || 0),
|
||||
);
|
||||
const [connector_apps, set_connector_apps] = useState<ConnectorAppIcon[]>(
|
||||
initial?.connector_apps || [],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
set_connector_count(Number(initial?.connector_count || 0));
|
||||
}, [initial?.connector_count]);
|
||||
|
||||
useEffect(() => {
|
||||
set_connector_apps(initial?.connector_apps || []);
|
||||
}, [initial?.connector_apps]);
|
||||
|
||||
const has_tools = Boolean(
|
||||
tools.attached.length || connector_count || (extensions.can_manage && tools.addable.length),
|
||||
);
|
||||
@@ -95,6 +106,8 @@ export default function ComposerTools({
|
||||
connectors={{ bot_id: bot.id || 0, workspace_id }}
|
||||
connector_count={connector_count}
|
||||
onConnectorCount={set_connector_count}
|
||||
connector_apps={connector_apps}
|
||||
onConnectorApps={set_connector_apps}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
|
||||
@@ -1756,6 +1756,22 @@ export type BotExtensionsPayload = {
|
||||
* composer's tools count includes them without reading them all.
|
||||
*/
|
||||
connector_count?: number;
|
||||
/**
|
||||
* The last few apps a connector account reaches here, for the composer's
|
||||
* tools button: their logo beside the spanner, so a glance says which
|
||||
* apps a message can use. Never repeats an app.
|
||||
*/
|
||||
connector_apps?: ConnectorAppIcon[];
|
||||
};
|
||||
|
||||
/**
|
||||
* One app a connector account reaches, as the composer's tools button shows
|
||||
* it.
|
||||
*/
|
||||
export type ConnectorAppIcon = {
|
||||
id: number;
|
||||
name: string;
|
||||
logo: string;
|
||||
};
|
||||
|
||||
export type McpServersOverviewPayload = ExtensionTargets & {
|
||||
|
||||
Reference in New Issue
Block a user