MCPcopy Index your code
hub / github.com/CommandCodeAI/BaseAI / createTool

Function createTool

packages/baseai/src/tool/index.ts:51–141  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

49 * @throws Will throw an error if there is an issue creating the tool file.
50 */
51export async function createTool() {
52 const allTools = await getAvailableTools();
53 p.intro(heading({ text: 'TOOL', sub: 'Create a new tool' }));
54
55 const toolInfo = await p.group(
56 {
57 name: () =>
58 p.text({
59 message: 'Name of the tool',
60 placeholder: defaultTool.function.name,
61 validate: value => {
62 const result = toolNameSchema.safeParse(value);
63 if (!result.success) {
64 return result.error.issues[0].message;
65 }
66
67 const hasTool = isToolPresent({
68 name: value,
69 allTools
70 });
71
72 if (hasTool) {
73 return `Tool with name ${value} already exists!`;
74 }
75 return;
76 }
77 }),
78 description: () =>
79 p.text({
80 message: 'Description of the tool',
81 placeholder: defaultTool.function.description,
82 validate(value) {
83 if (value.length === 0)
84 return `Tool description is required!`;
85 }
86 })
87 },
88 {
89 onCancel: () => {
90 p.cancel('Operation cancelled.');
91 process.exit(0);
92 }
93 }
94 );
95
96 const slugifiedName = slugify(toolInfo.name);
97 const camelCaseNameToolName = camelCase('tool-' + toolInfo.name);
98 const camelCaseNameFnName = camelCase(toolInfo.name);
99 const description = toolInfo.description || '';
100
101 const toolContent = `import { ToolI } from '@baseai/core';
102
103export async function ${camelCaseNameFnName}() {
104 // Add your tool logic here
105 // This function will be called when the tool is executed
106}
107
108const ${camelCaseNameToolName} = (): ToolI => ({

Callers 1

index.tsFile · 0.90

Calls 5

getAvailableToolsFunction · 0.90
headingFunction · 0.90
isToolPresentFunction · 0.90
formatCodeFunction · 0.90
cancelMethod · 0.45

Tested by

no test coverage detected