Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 21, 04:45 UTC
| 1 | import { Effect } from 'effect'; |
| 2 | import { ComposioToolkitsRepository } from 'src/services/composio-clients'; |
| 3 | import { printFailure, ReportedFailure } from 'src/effects/report-failure'; |
| 4 | import { TerminalUI } from 'src/services/terminal-ui'; |
| 5 | import { clampLimit } from 'src/ui/clamp-limit'; |
| 6 | import { extractMessage } from 'src/utils/api-error-extraction'; |
| 7 | import { formatToolkitsJson, formatToolkitsTable, mergeToolkitData } from '../format'; |
| 8 | |
| 9 | export type ToolkitsSearchParams = { |
| 10 | readonly query: string; |
| 11 | readonly limit: number; |
| 12 | }; |
| 13 | |
| 14 | // TODO(tool-router-migration): migrate to Tool Router when the session toolkits endpoint |
| 15 | // supports text search. Currently SessionToolsParams has no search capability. |
| 16 | |
| 17 | /** |
| 18 | * Searches the toolkit catalog by use case. A failed search prints the error, writes `[]` to |
| 19 | * stdout, and exits 1. |
| 20 | */ |
| 21 | export const runToolkitsSearch = ({ query, limit }: ToolkitsSearchParams) => |
| 22 | Effect.gen(function* () { |
| 23 | const ui = yield* TerminalUI; |
| 24 | const repo = yield* ComposioToolkitsRepository; |
| 25 | |
| 26 | const result = yield* ui.withSpinner( |
| 27 | `Searching toolkits for "${query}"...`, |
| 28 | repo.searchToolkits({ search: query, limit: clampLimit(limit) }) |
| 29 | ); |
| 30 | |
| 31 | if (result.items.length === 0) { |
| 32 | yield* ui.log.warn(`No toolkits found matching "${query}". Try broadening your search.`); |
| 33 | yield* ui.output('[]'); |
| 34 | return; |
| 35 | } |
| 36 | |
| 37 | const rows = mergeToolkitData(result.items); |
| 38 | |
| 39 | yield* ui.log.info( |
| 40 | `Found ${result.items.length} of ${result.total_items} toolkits\n\n${formatToolkitsTable(rows)}` |
| 41 | ); |
| 42 | |
| 43 | const firstSlug = rows[0]?.slug; |
| 44 | if (firstSlug) { |
| 45 | yield* ui.log.step(`To view details:\n> composio dev toolkits info "${firstSlug}"`); |
| 46 | } |
| 47 | |
| 48 | yield* ui.output(formatToolkitsJson(rows)); |
| 49 | }).pipe( |
| 50 | Effect.catch(error => |
| 51 | Effect.gen(function* () { |
| 52 | const ui = yield* TerminalUI; |
| 53 | const message = extractMessage(error) ?? 'An error occurred while searching toolkits.'; |
| 54 | yield* printFailure(ui, message); |
| 55 | yield* ui.output('[]'); |
| 56 | return yield* new ReportedFailure({ message }); |
| 57 | }) |
| 58 | ) |
| 59 | ); |