Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

next
ts 30 lines 732 Bytes
Raw
1 import type { BasicBuilder } from './BasicBuilder';
2 import { TypeContext } from './OperatorPrecedence';
3 import { TypeBuilder } from './TypeBuilder';
4 import { Writer } from './Writer';
5
6 export class Parameter implements BasicBuilder {
7 private isOptional = false;
8 constructor(
9 private name: string,
10 private type: TypeBuilder
11 ) {}
12
13 optional(): this {
14 this.isOptional = true;
15 return this;
16 }
17
18 write(writer: Writer): void {
19 writer.write(this.name);
20 if (this.isOptional) {
21 writer.write('?');
22 }
23 writer.write(': ');
24 this.type.writeInContext(writer, TypeContext.FunctionParameter);
25 }
26 }
27
28 export function parameter(name: string, type: TypeBuilder) {
29 return new Parameter(name, type);
30 }