Skip to content

🀯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

4.8 KB
Raw Blame
'use client';

import { builtinTools } from '@lobechat/builtin-tools';
import { DEFAULT_INBOX_AVATAR, DEFAULT_INBOX_TITLE } from '@lobechat/const';
import type { BuiltinToolManifest, LobeChatPluginApi } from '@lobechat/types';

import type { ToolRenderFixture } from '../lifecycleMode';
import { buildSchemaSample, humanize, single, type ToolsetFixtureModule } from './_helpers';
import claudeCode from './claude-code';
import codex from './codex';
import devin from './devin';
import github from './github';
import kimiCode from './kimi-code';
import linear from './linear';
import lobeActivator from './lobe-activator';
import lobeAgent from './lobe-agent';
import lobeAgentBuilder from './lobe-agent-builder';
import lobeAgentDocuments from './lobe-agent-documents';
import lobeAgentManagement from './lobe-agent-management';
import lobeBrowser from './lobe-browser';
import lobeCloudSandbox from './lobe-cloud-sandbox';
import lobeGroupAgentBuilder from './lobe-group-agent-builder';
import lobeGroupManagement from './lobe-group-management';
import lobeImageGeneration from './lobe-image-generation';
import lobeKnowledgeBase from './lobe-knowledge-base';
import lobeLocalSystem from './lobe-local-system';
import lobeNotebook from './lobe-notebook';
import lobePageAgent from './lobe-page-agent';
import lobeSkillStore from './lobe-skill-store';
import lobeSkills from './lobe-skills';
import lobeTask from './lobe-task';
import lobeUserInteraction from './lobe-user-interaction';
import lobeUserMemory from './lobe-user-memory';
import lobeWebBrowsing from './lobe-web-browsing';
import lobeWebOnboarding from './lobe-web-onboarding';
import { lobeAuv } from './lobeAuv';

export type { ToolRenderFixture, ToolRenderFixtureVariant } from '../lifecycleMode';

export interface ToolRenderMeta {
  api?: LobeChatPluginApi;
  apiName: string;
  description?: string;
  identifier: string;
  toolsetDescription?: string;
  toolsetName: string;
}

export const DEVTOOLS_GROUP_ID = 'devtools-preview-group';

/**
 * Identity for the seeded Aggregate-preview conversation. The fixture messages
 * resolve their avatar/name through this agentId, so seeding `agentMap` with
 * this meta makes the preview turn read as "Lobe AI" instead of the
 * unresolved-agent fallback ("Unnamed Assistant").
 */
export const DEVTOOLS_AGENT_ID = 'devtools-render-gallery';

export const DEVTOOLS_AGENT_META = {
  avatar: DEFAULT_INBOX_AVATAR,
  title: DEFAULT_INBOX_TITLE,
};

export const DEVTOOLS_GROUP_DETAIL = {
  agents: [
    {
      avatar: '🧭',
      backgroundColor: '#E8F3FF',
      id: 'researcher-agent',
      title: 'Researcher',
    },
    {
      avatar: 'πŸ› ',
      backgroundColor: '#FFF3E8',
      id: 'builder-agent',
      title: 'Builder',
    },
  ],
  avatar: 'πŸ‘₯',
  backgroundColor: '#EEF2FF',
  description: 'Fixture group used by /devtools to preview grouped task renders.',
  id: DEVTOOLS_GROUP_ID,
  title: 'Devtools Preview Group',
};

const toolsetModules: ToolsetFixtureModule[] = [
  claudeCode,
  codex,
  devin,
  github,
  kimiCode,
  linear,
  lobeActivator,
  lobeAgent,
  lobeAgentBuilder,
  lobeAgentDocuments,
  lobeAgentManagement,
  lobeAuv,
  lobeBrowser,
  lobeCloudSandbox,
  lobeGroupAgentBuilder,
  lobeGroupManagement,
  lobeImageGeneration,
  lobeKnowledgeBase,
  lobeLocalSystem,
  lobeNotebook,
  lobePageAgent,
  lobeSkillStore,
  lobeSkills,
  lobeTask,
  lobeUserInteraction,
  lobeUserMemory,
  lobeWebBrowsing,
  lobeWebOnboarding,
];

const fixtureRegistry = new Map<string, ToolRenderFixture>();
const customToolsets = new Map<string, ToolsetFixtureModule>();

for (const toolset of toolsetModules) {
  customToolsets.set(toolset.identifier, toolset);
  for (const [apiName, fixture] of Object.entries(toolset.fixtures)) {
    fixtureRegistry.set(`${toolset.identifier}:${apiName}`, fixture);
  }
}

const manifestByIdentifier = new Map<string, BuiltinToolManifest>(
  builtinTools.map((tool) => [tool.identifier, tool.manifest]),
);

export const getToolRenderFixture = (
  identifier: string,
  apiName: string,
  api?: LobeChatPluginApi,
): ToolRenderFixture => {
  const fixture = fixtureRegistry.get(`${identifier}:${apiName}`);
  if (fixture) return fixture;

  return single({
    args: buildSchemaSample(api?.parameters, apiName) || {},
  });
};

export const getToolRenderMeta = (identifier: string, apiName: string): ToolRenderMeta => {
  const manifest = manifestByIdentifier.get(identifier);
  const api = manifest?.api.find((item) => item.name === apiName);
  const customToolset = customToolsets.get(identifier);
  const customApi = customToolset?.apiList?.find((item) => item.name === apiName);

  return {
    api,
    apiName,
    description: api?.description || customApi?.description,
    identifier,
    toolsetDescription: manifest?.meta.description || customToolset?.meta?.description,
    toolsetName: manifest?.meta.title || customToolset?.meta?.title || humanize(identifier),
  };
};