Skip to content

Commit

Permalink
fix: custom tool bundle not showing up & oauth custom tool still disa…
Browse files Browse the repository at this point in the history
…bled on agent fix (obot-platform#1309)
  • Loading branch information
ivyjeong13 authored Jan 17, 2025
1 parent 51b2280 commit a5a277a
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 37 deletions.
2 changes: 1 addition & 1 deletion ui/admin/app/components/tools/ToolCatalog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export function ToolCatalog({
!app.noGatewayIntegration ||
(app.noGatewayIntegration && app.appOverride)
)
.map((app) => app.type)
.map((app) => app.appOverride?.integration ?? app.type)
);
}, [oauthApps]);

Expand Down
112 changes: 79 additions & 33 deletions ui/admin/app/components/tools/toolGrid/ToolGrid.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { useMemo } from "react";

import {
CustomToolsToolCategory,
ToolCategory,
ToolReference,
} from "~/lib/model/toolReferences";

import { BundleToolList } from "~/components/tools/toolGrid/BundleToolList";
Expand All @@ -11,29 +14,43 @@ export function ToolGrid({
}: {
toolCategories: [string, ToolCategory][];
}) {
const { customTools, builtinTools } = useMemo(() => {
return separateCustomAndBuiltinTools(toolCategories);
}, [toolCategories]);

const sortedCustomTools =
toolCategories
.find(([category]) => category === CustomToolsToolCategory)?.[1]
.tools?.sort((a, b) => {
// sort by created date descending
return new Date(b.created).getTime() - new Date(a.created).getTime();
}) ?? [];
customTools.sort((a, b) => {
// Sort by created descending for custom tools
const aCreatedAt =
"bundleTool" in a
? a.bundleTool?.created
: (a as ToolReference).created;
const bCreatedAt =
"bundleTool" in b
? b.bundleTool?.created
: (b as ToolReference).created;

const sortedBuiltinTools = toolCategories
.filter(([category]) => category !== CustomToolsToolCategory)
.sort((a, b) => {
return a[0].localeCompare(b[0]);
});
return (
new Date(bCreatedAt ?? "").getTime() -
new Date(aCreatedAt ?? "").getTime()
);
}) ?? [];

const sortedBuiltinTools = builtinTools.sort((a, b) => {
const aName =
"bundleTool" in a ? a.bundleTool?.name : (a as ToolReference).name;
const bName =
"bundleTool" in b ? b.bundleTool?.name : (b as ToolReference).name;
return (aName ?? "").localeCompare(bName ?? "");
});

return (
<div className="flex flex-col gap-8">
{sortedCustomTools.length > 0 && (
<div className="flex flex-col gap-4">
<h3>Custom Tools</h3>
<h3>{CustomToolsToolCategory}</h3>
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3 2xl:grid-cols-4">
{sortedCustomTools.map((tool) => (
<ToolCard key={tool.id} tool={tool} />
))}
{sortedCustomTools.map(renderToolCard)}
</div>
</div>
)}
Expand All @@ -42,27 +59,56 @@ export function ToolGrid({
<div className="flex flex-col gap-4">
<h3>Built-in Tools</h3>
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3 2xl:grid-cols-4">
{sortedBuiltinTools.map(([, { tools, bundleTool }]) => {
if (bundleTool) {
return (
<ToolCard
key={bundleTool.id}
HeaderRightContent={
tools.length > 0 ? (
<BundleToolList tools={tools} bundle={bundleTool} />
) : null
}
tool={bundleTool}
/>
);
}
return tools.map((tool) => (
<ToolCard key={tool.id} tool={tool} />
));
})}
{sortedBuiltinTools.map(renderToolCard)}
</div>
</div>
)}
</div>
);

function renderToolCard(item: ToolCategory | ToolReference) {
if ("bundleTool" in item && item.bundleTool) {
return (
<ToolCard
key={item.bundleTool.id}
HeaderRightContent={
item.tools.length > 0 ? (
<BundleToolList tools={item.tools} bundle={item.bundleTool} />
) : null
}
tool={item.bundleTool}
/>
);
}

if ("name" in item) return <ToolCard key={item.name} tool={item} />;

return null;
}

function separateCustomAndBuiltinTools(
toolCategories: [string, ToolCategory][]
) {
return toolCategories.reduce<{
customTools: (ToolCategory | ToolReference)[];
builtinTools: (ToolCategory | ToolReference)[];
}>(
(acc, [, { bundleTool, tools }]) => {
if (bundleTool) {
const key = bundleTool.builtin ? "builtinTools" : "customTools";
acc[key].push({ bundleTool, tools });
} else {
tools.forEach((tool) => {
if (tool.builtin) {
acc.builtinTools.push(tool);
} else {
acc.customTools.push(tool);
}
});
}
return acc;
},
{ customTools: [], builtinTools: [] }
);
}
}
5 changes: 2 additions & 3 deletions ui/admin/app/lib/model/toolReferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ export function convertToolReferencesToCategoryMap(
continue;
}

const category = !toolReference.builtin
? CustomToolsToolCategory
: toolReference.metadata?.category || UncategorizedToolCategory;
const category =
toolReference.metadata?.category || UncategorizedToolCategory;

if (!result[category]) {
result[category] = {
Expand Down

0 comments on commit a5a277a

Please sign in to comment.