@composio/core
Version:

76 lines (74 loc) • 3.38 kB
text/typescript
import { a as CustomTool, i as CreateCustomToolkitParams, m as CustomToolkit, n as CreateCustomToolParams } from "./customTool.types-B-4lZeSS.mjs";
import { z as z$1 } from "zod/v3";
import { SessionCreateResponse } from "@composio/client/resources/tool-router/session/session.mjs";
//#region src/models/CustomTool.d.ts
/**
* Create a custom tool for use in tool router sessions.
*
* The returned object is a lightweight reference containing the tool's metadata
* and execute function. Pass it to `composio.create(userId, { experimental: { customTools: [...] } })`
* to bind it to a session.
*
* Just return the result data from `execute`, or throw an error.
* The SDK wraps it into the standard response format internally.
*
* **Slug naming:** The slug you provide is automatically prefixed with `LOCAL_` when
* exposed to the agent (e.g. `'GREP'` becomes `LOCAL_GREP`). If the tool is inside a
* custom toolkit, the toolkit slug is also included (e.g. `LOCAL_DEV_TOOLS_GREP`).
* The `LOCAL_` prefix is reserved and cannot be used in your slug.
*
* @param slug - Unique tool identifier (alphanumeric, underscores, hyphens; no LOCAL_ or COMPOSIO_ prefix)
* @param options - Tool definition including name, schema, and execute function
* @returns A CustomTool to pass to session creation
*
* @example Standalone tool (no auth)
* ```typescript
* const grep = createCustomTool('GREP', {
* name: 'Grep Search',
* description: 'Search for patterns in files',
* inputParams: z.object({ pattern: z.string(), path: z.string() }),
* execute: async (input) => ({ matches: [] }),
* });
* ```
*
* @example Tool extending a Composio toolkit (inherits auth)
* ```typescript
* const getImportant = createCustomTool('GET_IMPORTANT_EMAILS', {
* name: 'Get Important Emails',
* description: 'Fetch high-priority emails',
* extendsToolkit: 'gmail',
* inputParams: z.object({ limit: z.number().default(10) }),
* execute: async (input, ctx) => {
* // Same response shape as session.execute(): { data, error, logId }
* const result = await ctx.execute('GMAIL_SEARCH', { query: 'is:important' });
* return { emails: result.data };
* },
* });
* ```
*/
declare function createCustomTool<T extends z$1.ZodType>(slug: string, options: CreateCustomToolParams<T>): CustomTool;
/**
* Create a custom toolkit that groups related tools.
*
* Tools passed here must NOT have `extendsToolkit` set — they inherit the toolkit identity instead.
*
* **Slug naming:** The toolkit slug becomes part of the final tool slug exposed to the agent.
* For example, a toolkit `'DEV_TOOLS'` with a tool `'GREP'` produces `LOCAL_DEV_TOOLS_GREP`.
* The `LOCAL_` prefix is reserved and cannot be used in your slug.
*
* @param slug - Unique toolkit identifier (alphanumeric, underscores, hyphens; no LOCAL_ or COMPOSIO_ prefix)
* @param options - Toolkit definition including name, description, and tools
* @returns A CustomToolkit to pass to session creation
*
* @example
* ```typescript
* const devTools = createCustomToolkit('DEV_TOOLS', {
* name: 'Dev Tools',
* description: 'Local dev utilities',
* tools: [grepTool, sedTool],
* });
* ```
*/
declare function createCustomToolkit(slug: string, options: CreateCustomToolkitParams): CustomToolkit;
//#endregion
export { createCustomToolkit as n, createCustomTool as t };