@robota-sdk/agent-tools 3.0.0-beta.73 → 3.0.0-beta.75

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { IEventService, IFunctionTool, IOpenAPIToolConfig, IParameterValidationResult, ITool, IToolExecutionContext, IToolRegistry, IToolResult, IToolSchema, TToolExecutor, TToolParameters, TUniversalValue } from "@robota-sdk/agent-core";
1
+ import { IEventService, IFunctionTool, IParameterValidationResult, ITool, IToolExecutionContext, IToolRegistry, IToolResult, IToolSchema, TToolExecutor, TToolParameters, TUniversalValue } from "@robota-sdk/agent-core";
2
2
 
3
3
  //#region src/types/tool-result.d.ts
4
4
  /**
@@ -183,70 +183,11 @@ declare function createFunctionTool(name: string, description: string, parameter
183
183
  */
184
184
  declare function createZodFunctionTool(name: string, description: string, zodSchema: IZodSchema, fn: TToolExecutor): FunctionTool;
185
185
  //#endregion
186
- //#region src/implementations/openapi-tool.d.ts
187
- /**
188
- * OpenAPI tool implementation
189
- * Executes API calls based on OpenAPI 3.0 specifications
190
- *
191
- * Implements ITool without extending AbstractTool to avoid
192
- * circular runtime dependency (tools → agents → tools).
193
- */
194
- declare class OpenAPITool implements ITool {
195
- readonly schema: IToolSchema;
196
- private readonly apiSpec;
197
- private readonly operationId;
198
- private readonly baseURL;
199
- private readonly config;
200
- private eventService;
201
- constructor(config: IOpenAPIToolConfig);
202
- /**
203
- * Execute the OpenAPI tool
204
- */
205
- execute(parameters: TToolParameters, context?: IToolExecutionContext): Promise<IToolResult>;
206
- /**
207
- * Validate tool parameters
208
- */
209
- validate(parameters: TToolParameters): boolean;
210
- /**
211
- * Validate tool parameters with detailed result
212
- */
213
- validateParameters(parameters: TToolParameters): IParameterValidationResult;
214
- /**
215
- * Get tool name
216
- */
217
- getName(): string;
218
- /**
219
- * Set EventService for post-construction injection.
220
- */
221
- setEventService(eventService: IEventService | undefined): void;
222
- /**
223
- * Get tool description
224
- */
225
- getDescription(): string;
226
- /**
227
- * Execute the actual API call
228
- * @private
229
- */
230
- private executeAPICall;
231
- /**
232
- * Build HTTP request configuration from OpenAPI operation and parameters
233
- */
234
- private buildRequestConfig;
235
- /**
236
- * Create tool schema from OpenAPI operation specification
237
- */
238
- private createSchemaFromOpenAPI;
239
- }
240
- /**
241
- * Factory function to create OpenAPI tools from specification
242
- */
243
- declare function createOpenAPITool(config: IOpenAPIToolConfig): OpenAPITool;
244
- //#endregion
245
186
  //#region src/implementations/function-tool/schema-converter.d.ts
246
187
  /**
247
188
  * Convert Zod schema to JSON Schema format with safe undefined handling
248
189
  */
249
190
  declare function zodToJsonSchema(schema: IZodSchema, options?: ISchemaConversionOptions): IToolSchema['parameters'];
250
191
  //#endregion
251
- export { FunctionTool, type IFunctionToolExecutionMetadata, type IFunctionToolResult, type IFunctionToolValidationOptions, type ISchemaConversionOptions, type IZodParseResult, type IZodSchema, type IZodSchemaDef, OpenAPITool, type TToolResult, ToolRegistry, createFunctionTool, createOpenAPITool, createZodFunctionTool, zodToJsonSchema };
192
+ export { FunctionTool, type IFunctionToolExecutionMetadata, type IFunctionToolResult, type IFunctionToolValidationOptions, type ISchemaConversionOptions, type IZodParseResult, type IZodSchema, type IZodSchemaDef, type TToolResult, ToolRegistry, createFunctionTool, createZodFunctionTool, zodToJsonSchema };
252
193
  //# sourceMappingURL=browser.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"browser.d.ts","names":[],"sources":["../../src/types/tool-result.ts","../../src/registry/tool-registry.ts","../../src/implementations/function-tool/types.ts","../../src/implementations/function-tool.ts","../../src/implementations/openapi-tool.ts","../../src/implementations/function-tool/schema-converter.ts"],"mappings":";;;;;;UAGiB,WAAA;EACf,OAAA;EACA,MAAA;EACA,KAAA;EACA,QAAA;EAFA;EAIA,SAAA;AAAA;;;;AANF;;;cCOa,YAAA,YAAwB,aAAA;EAAA,QAC3B,KAAA;EDNR;;;ECWA,QAAA,CAAS,IAAA,EAAM,KAAA;EDPN;A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GAAqB,WAAW;;;;;;iBCjQ1D,eAAA,CACd,MAAA,EAAQ,UAAA,EACR,OAAA,GAAS,wBAAA,GACR,WAAA"}
1
+ {"version":3,"file":"browser.d.ts","names":[],"sources":["../../src/types/tool-result.ts","../../src/registry/tool-registry.ts","../../src/implementations/function-tool/types.ts","../../src/implementations/function-tool.ts","../../src/implementations/function-tool/schema-converter.ts"],"mappings":";;;;;;UAGiB,WAAA;EACf,OAAA;EACA,MAAA;EACA,KAAA;EACA,QAAA;EAFA;EAIA,SAAA;AAAA;;;;AANF;;;cCOa,YAAA,YAAwB,aAAA;EAAA,QAC3B,KAAA;EDNR;;;ECWA,QAAA,CAAS,IAAA,EAAM,KAAA;EDPN;AAAA;;ECoCT,UAAA,CAAW,IAAA;;AAnCb;;EAgDE,GAAA,CAAI,IAAA,WAAe,KAAA;EA1CJ;;;EAiDf,MAAA,IAAU,KAAA;EAkD0B;;;EA3CpC,UAAA,IAAc,WAAA;EA9DkC;;;EAkFhD,GAAA,CAAI,IAAA;EA5EW;;;EAmFf,KAAA;EAzCA;;;EAkDA,YAAA;EA3CU;;;EAkDV,iBAAA,CAAkB,OAAA,WAAkB,MAAA,GAAS,KAAA;EAvBzC;;;EA+BJ,IAAA;EARoC;;;EAAA,QAe5B,kBAAA;AAAA;;;;;AD/HV;;;;UEKiB,eAAA;EACf,OAAA;EACA,IAAA;EACA,KAAA;AAAA;AAAA,UAGe,aAAA;EACf,QAAA;EACA,SAAA,GAAY,UAAA;EACZ,SAAA,GAAY,UAAA;EACZ,MAAA,GAAS,KAAA;IAAQ,IAAA;IAAc,KAAA,GAAQ,eAAA;EAAA;EACvC,KAAA,SAAc,MAAA,SAAe,UAAA;EAC7B,IAAA,GAAO,UAAA;EACP,MAAA,GAAS,eAAA;EACT,WAAA;EACA,WAAA;AAAA;AAAA,UAGe,UAAA;EACf,KAAA,CAAM,KAAA;EACN,SAAA,CAAU,KAAA,YAAiB,eAAA;EAC3B,IAAA,GAAO,aAAa;AAAA;;;;UAML,8BAAA;EACf,MAAA;EACA,YAAA;EACA,aAAA;AAAA;;;;UAMe,wBAAA;EACf,kBAAA;EACA,WAAA;EACA,yBAAA;AAAA;;;;UAMe,8BAAA;EACf,aAAA;EACA,QAAA;EACA,UAAA,EAAY,eAAe;AAAA;;;;UAMZ,mBAAA;EACf,OAAA;EACA,IAAA,EAAM,eAAA;EACN,QAAA,GAAW,8BAA8B;AAAA;;;AF9D3C;;;;;;;AAAA,cGwBa,YAAA,YAAwB,aAAA;EAAA,SAC1B,MAAA,EAAQ,WAAA;EAAA,SACR,EAAA,EAAI,aAAA;EAAA,QACL,YAAA;cAEI,MAAA,EAAQ,WAAA,EAAa,EAAA,EAAI,aAAA;;;AFtBvC;EE+BE,OAAA;;;;;;EASA,eAAA,CAAgB,YAAA,EAAc,aAAA;EFiEe;;;EE1DvC,OAAA,CACJ,UAAA,EAAY,eAAA,EACZ,OAAA,GAAU,qBAAA,GACT,OAAA,CAAQ,WAAA;EFlDwB;;;EEqGnC,QAAA,CAAS,UAAA,EAAY,eAAA;EF/FZ;;;EE6GT,kBAAA,CAAmB,UAAA,EAAY,eAAA,GAAkB,0BAAA;EFnE7C;;;EE+EJ,cAAA;EFjEA;;;EAAA,QEwEQ,yBAAA;AAAA;;;;iBAkBM,kBAAA,CACd,IAAA,UACA,WAAA,UACA,UAAA,EAAY,WAAA,gBACZ,EAAA,EAAI,aAAA,GACH,YAAA;;;;iBAaa,qBAAA,CACd,IAAA,UACA,WAAA,UACA,SAAA,EAAW,UAAA,EACX,EAAA,EAAI,aAAA,GACH,YAAA;;;;;;iBCjKa,eAAA,CACd,MAAA,EAAQ,UAAA,EACR,OAAA,GAAS,wBAAA,GACR,WAAA"}
@@ -1,2 +1,2 @@
1
- import{ToolExecutionError as e,ValidationError as t,logger as n}from"@robota-sdk/agent-core";var r=class{tools=new Map;register(e){if(!e.schema?.name)throw new t(`Tool must have a valid schema with name`);let r=e.schema.name;this.validateToolSchema(e.schema),this.tools.has(r)&&n.warn(`Tool "${r}" is already registered, overriding`,{toolName:r,existingTool:this.tools.get(r)?.constructor.name}),this.tools.set(r,e),n.debug(`Tool "${r}" registered successfully`,{toolName:r,toolType:e.constructor.name,parameters:Object.keys(e.schema.parameters?.properties||{})})}unregister(e){if(!this.tools.has(e)){n.warn(`Attempted to unregister non-existent tool "${e}"`);return}this.tools.delete(e),n.debug(`Tool "${e}" unregistered successfully`)}get(e){return this.tools.get(e)}getAll(){return Array.from(this.tools.values())}getSchemas(){let e=this.getAll();return n.debug(`[TOOL-FLOW] ToolRegistry.getSchemas() - Tools before schema extraction`,{count:e.length,tools:e.map(e=>({name:e.schema?.name??`unnamed`,hasSchema:!!e.schema,schemaType:typeof e.schema,toolType:e.constructor?.name||`unknown`}))}),this.getAll().map(e=>e.schema)}has(e){return this.tools.has(e)}clear(){let e=this.tools.size;this.tools.clear(),n.debug(`Cleared ${e} tools from registry`)}getToolNames(){return Array.from(this.tools.keys())}getToolsByPattern(e){let t=typeof e==`string`?new RegExp(e):e;return this.getAll().filter(e=>t.test(e.schema.name))}size(){return this.tools.size}validateToolSchema(e){if(!e.name||typeof e.name!=`string`)throw new t(`Tool schema must have a valid name`);if(!e.description||typeof e.description!=`string`)throw new t(`Tool schema must have a description`);if(!e.parameters||typeof e.parameters!=`object`||e.parameters===null||Array.isArray(e.parameters))throw new t(`Tool schema must have parameters object`);if(e.parameters.type!==`object`)throw new t(`Tool parameters type must be "object"`);if(e.parameters.properties)for(let n of Object.keys(e.parameters.properties)){let r=e.parameters.properties[n];if(!r?.type)throw new t(`Parameter "${n}" must have a type`);if(![`string`,`number`,`boolean`,`array`,`object`].includes(r.type))throw new t(`Parameter "${n}" has invalid type "${r.type}"`)}if(e.parameters.required){let n=e.parameters.properties||{};for(let r of e.parameters.required)if(!n[r])throw new t(`Required parameter "${r}" is not defined in properties`)}}};function i(e,t,n){switch(n.type){case`string`:if(typeof t!=`string`)return`Parameter "${e}" must be a string, got ${typeof t}`;break;case`number`:if(typeof t!=`number`||isNaN(t))return`Parameter "${e}" must be a number, got ${typeof t}`;break;case`boolean`:if(typeof t!=`boolean`)return`Parameter "${e}" must be a boolean, got ${typeof t}`;break;case`array`:if(!Array.isArray(t))return`Parameter "${e}" must be an array, got ${typeof t}`;if(n.items)for(let r=0;r<t.length;r++){let a=i(`${e}[${r}]`,t[r],n.items);if(a)return a}break;case`object`:if(typeof t!=`object`||!t||Array.isArray(t))return`Parameter "${e}" must be an object, got ${typeof t}`;break}if(n.enum&&n.enum.length>0){let r=n.enum,i=!1;for(let e of r)if(t===e){i=!0;break}if(!i)return`Parameter "${e}" must be one of: ${r.join(`, `)}, got ${t}`}}function a(e,t,n,r){let a=[];for(let n of t)n in e||a.push(`Missing required parameter: ${n}`);for(let[t,o]of Object.entries(e)){let e=n[t];if(!e){if(r===!0)continue;if(r&&typeof r==`object`){let e=i(t,o,r);e&&a.push(e);continue}a.push(`Unknown parameter: ${t}`);continue}let s=i(t,o,e);s&&a.push(s)}return a}function o(e,t,n,r){let i=a(e,t,n,r);return{isValid:i.length===0,errors:i}}function s(e,t={}){let n={},r=[],i=e._def;if(!i)throw Error(`Zod schema is missing _def; cannot convert to JSON schema.`);if(i.typeName===`ZodObject`&&i.shape){let e=typeof i.shape==`function`?i.shape():i.shape;for(let[t,i]of Object.entries(e))n[t]=c(i),l(i)&&r.push(t)}return{type:`object`,properties:n,required:r,...(t.allowAdditionalProperties||i.unknownKeys===`passthrough`)&&{additionalProperties:!0}}}function c(e){let t=e._def;if(!t)throw Error(`Zod type is missing _def; cannot convert to JSON schema.`);let n={};switch(t.description&&(n.description=t.description),t.typeName){case`ZodString`:return{type:`string`,...n};case`ZodNumber`:return{type:`number`,...n};case`ZodBoolean`:return{type:`boolean`,...n};case`ZodArray`:if(!t.type)throw Error(`ZodArray is missing item type; cannot convert to JSON schema.`);return{type:`array`,items:c(t.type),...n};case`ZodObject`:return{type:`object`,...n};case`ZodEnum`:{let e=t.values;if(!e||!Array.isArray(e))throw Error(`ZodEnum is missing enum values; cannot convert to JSON schema.`);return{type:`string`,enum:e,...n}}case`ZodOptional`:if(t.innerType)return{...c(t.innerType),...n};throw Error(`ZodOptional is missing innerType; cannot convert to JSON schema.`);case`ZodNullable`:if(t.innerType)return{...c(t.innerType),...n};throw Error(`ZodNullable is missing innerType; cannot convert to JSON schema.`);case`ZodDefault`:if(t.innerType)return{...c(t.innerType),...n};throw Error(`ZodDefault is missing innerType; cannot convert to JSON schema.`);case`ZodRecord`:return t.valueType?{type:`object`,additionalProperties:c(t.valueType),...n}:{type:`object`,additionalProperties:{type:`string`},...n};default:throw Error(`Unsupported Zod type: ${String(t.typeName)}`)}}function l(e){let t=e._def;if(!t)throw Error(`Zod schema is missing _def; cannot determine required fields.`);return t.typeName!==`ZodOptional`&&t.typeName!==`ZodNullable`&&t.typeName!==`ZodDefault`}var u=class{schema;fn;eventService;constructor(e,t){this.schema=e,this.fn=t,this.validateConstructorInputs()}getName(){return this.schema.name}setEventService(e){this.eventService=e}async execute(n,r){let i=this.schema.name;if(!this.validate(n))throw new t(`Invalid parameters for tool "${i}": ${a(n,this.schema.parameters.required||[],this.schema.parameters.properties||{},this.schema.parameters.additionalProperties).join(`, `)}`);let o=Date.now(),s;try{s=await this.fn(n,r)}catch(a){throw a instanceof e||a instanceof t?a:new e(`Function tool execution failed: ${a instanceof Error?a.message:String(a)}`,i,a instanceof Error?a:Error(String(a)),{parameterCount:Object.keys(n||{}).length,hasContext:!!r})}let c=Date.now()-o;return{success:!0,data:s,metadata:{executionTime:c,toolName:i,parameters:n}}}validate(e){return a(e,this.schema.parameters.required||[],this.schema.parameters.properties||{},this.schema.parameters.additionalProperties).length===0}validateParameters(e){return o(e,this.schema.parameters.required||[],this.schema.parameters.properties||{},this.schema.parameters.additionalProperties)}getDescription(){return this.schema.description}validateConstructorInputs(){if(!this.schema)throw new t(`Tool schema is required`);if(!this.fn||typeof this.fn!=`function`)throw new t(`Tool function is required and must be a function`);if(!this.schema.name)throw new t(`Tool schema must have a name`)}};function d(e,t,n,r){return new u({name:e,description:t,parameters:n},r)}function f(e,n,r,i){return new u({name:e,description:n,parameters:s(r)},async(e,n)=>{let a=r.safeParse(e);if(!a.success)throw new t(`Zod validation failed: ${a.error}`);let o=await i(a.data||e,n);return typeof o==`string`?o:JSON.stringify(o)})}const p=[`get`,`post`,`put`,`delete`,`patch`,`head`,`options`];function m(e,t){for(let[n,r]of Object.entries(e.paths||{}))if(r)for(let e of p){let i=r[e];if(i?.operationId===t)return{method:e,path:n,operation:i}}}function h(e){switch(e){case`string`:return`string`;case`number`:return`number`;case`integer`:return`integer`;case`boolean`:return`boolean`;case`array`:return`array`;case`object`:return`object`;default:return`string`}}function g(e){if(`$ref`in e)return{type:`object`};let t={type:h(e.type)};if(e.description&&(t.description=e.description),e.enum&&(t.enum=e.enum),e.minimum!==void 0&&(t.minimum=e.minimum),e.maximum!==void 0&&(t.maximum=e.maximum),e.pattern&&(t.pattern=e.pattern),e.format&&(t.format=e.format),e.default!==void 0&&(t.default=e.default),e.type===`array`&&e.items&&(t.items=g(e.items)),e.type===`object`&&e.properties){t.properties={};for(let[n,r]of Object.entries(e.properties))t.properties[n]=g(r);e.required&&e.required.length>0&&(t.required=e.required)}return t}function _(e){let t=e.schema;return g(t)}function v(e,t){let n={},r=[],i=t.parameters||[];for(let e of i)n[e.name]=_(e),e.required&&r.push(e.name);if(t.requestBody){let e=t.requestBody.content?.[`application/json`];if(e?.schema){let t=g(e.schema);if(t.type===`object`&&t.properties){Object.assign(n,t.properties);let e=t;e.required&&r.push(...e.required)}}}let a={type:`object`,properties:n};return r.length>0&&(a.required=r),{name:e,description:t.summary||t.description||`OpenAPI operation: ${e}`,parameters:a}}var y=class{schema;apiSpec;operationId;baseURL;config;eventService;constructor(e){if(this.config=e,typeof e.spec!=`object`||e.spec===null||typeof e.spec.openapi!=`string`||typeof e.spec.paths!=`object`)throw Error(`Invalid OpenAPI spec: must contain "openapi" (string) and "paths" (object) fields`);this.apiSpec=e.spec,this.operationId=e.operationId,this.baseURL=e.baseURL,this.schema=this.createSchemaFromOpenAPI()}async execute(n,r){let i=this.schema.name,a=this.validateParameters(n);if(!a.isValid)throw new t(`Invalid parameters for OpenAPI tool "${i}": ${a.errors.join(`, `)}`);try{let e=Date.now();return{success:!0,data:await this.executeAPICall(n,r),metadata:{executionTime:Date.now()-e,toolName:i,operationId:this.operationId,baseURL:this.baseURL}}}catch(r){if(r instanceof e||r instanceof t)throw r;let a=r instanceof Error?r:Error(String(r));throw new e(`OpenAPI tool execution failed: ${a.message}`,i,a,{operationId:this.operationId,baseURL:this.baseURL,parametersCount:Object.keys(n).length})}}validate(e){return this.validateParameters(e).isValid}validateParameters(e){let t=this.schema.parameters.required||[],n=[];for(let r of t)r in e||n.push(`Missing required parameter: ${r}`);return{isValid:n.length===0,errors:n}}getName(){return this.schema.name}setEventService(e){this.eventService=e}getDescription(){return this.schema.description}async executeAPICall(e,t){let n=m(this.apiSpec,this.operationId);throw n?(this.buildRequestConfig(n,e),Error(`Not implemented: actual API execution is not yet available`)):Error(`Operation ${this.operationId} not found in OpenAPI spec`)}buildRequestConfig(e,t){let{method:n,path:r,operation:i}=e,a=this.baseURL+r,o={},s,c=i.parameters||[];for(let e of c){let n=t[e.name];if(n===void 0&&e.required)throw Error(`Required parameter ${e.name} is missing`);if(n!==void 0)switch(e.in){case`path`:a=a.replace(`{${e.name}}`,encodeURIComponent(String(n)));break;case`query`:{let t=a.includes(`?`)?`&`:`?`;a+=`${t}${e.name}=${encodeURIComponent(String(n))}`;break}case`header`:o[e.name]=String(n);break}}if([`post`,`put`,`patch`].includes(n)&&i.requestBody&&i.requestBody.content?.[`application/json`]){o[`Content-Type`]=`application/json`;let e={};for(let[n,r]of Object.entries(t))c.some(e=>e.name===n)||(e[n]=r);s=JSON.stringify(e)}if(this.config.auth)switch(this.config.auth.type){case`bearer`:o.Authorization=`Bearer ${this.config.auth.token}`;break;case`apiKey`:{let e=this.config.auth.header||`X-API-Key`;o[e]=this.config.auth.apiKey||``;break}}let l={method:n,url:a,headers:o};return s!==void 0&&(l.body=s),l}createSchemaFromOpenAPI(){let e=m(this.apiSpec,this.operationId);if(!e)throw Error(`[STRICT-POLICY][EMITTER-CONTRACT] OpenAPI operation not found: ${this.operationId}. Emitter contract must provide a valid operationId present in the OpenAPI document.`);return v(this.operationId,e.operation)}};function b(e){return new y(e)}export{u as FunctionTool,y as OpenAPITool,r as ToolRegistry,d as createFunctionTool,b as createOpenAPITool,f as createZodFunctionTool,s as zodToJsonSchema};
1
+ import{ToolExecutionError as e,ValidationError as t,logger as n}from"@robota-sdk/agent-core";var r=class{tools=new Map;register(e){if(!e.schema?.name)throw new t(`Tool must have a valid schema with name`);let r=e.schema.name;this.validateToolSchema(e.schema),this.tools.has(r)&&n.warn(`Tool "${r}" is already registered, overriding`,{toolName:r,existingTool:this.tools.get(r)?.constructor.name}),this.tools.set(r,e),n.debug(`Tool "${r}" registered successfully`,{toolName:r,toolType:e.constructor.name,parameters:Object.keys(e.schema.parameters?.properties||{})})}unregister(e){if(!this.tools.has(e)){n.warn(`Attempted to unregister non-existent tool "${e}"`);return}this.tools.delete(e),n.debug(`Tool "${e}" unregistered successfully`)}get(e){return this.tools.get(e)}getAll(){return Array.from(this.tools.values())}getSchemas(){let e=this.getAll();return n.debug(`[TOOL-FLOW] ToolRegistry.getSchemas() - Tools before schema extraction`,{count:e.length,tools:e.map(e=>({name:e.schema?.name??`unnamed`,hasSchema:!!e.schema,schemaType:typeof e.schema,toolType:e.constructor?.name||`unknown`}))}),this.getAll().map(e=>e.schema)}has(e){return this.tools.has(e)}clear(){let e=this.tools.size;this.tools.clear(),n.debug(`Cleared ${e} tools from registry`)}getToolNames(){return Array.from(this.tools.keys())}getToolsByPattern(e){let t=typeof e==`string`?new RegExp(e):e;return this.getAll().filter(e=>t.test(e.schema.name))}size(){return this.tools.size}validateToolSchema(e){if(!e.name||typeof e.name!=`string`)throw new t(`Tool schema must have a valid name`);if(!e.description||typeof e.description!=`string`)throw new t(`Tool schema must have a description`);if(!e.parameters||typeof e.parameters!=`object`||e.parameters===null||Array.isArray(e.parameters))throw new t(`Tool schema must have parameters object`);if(e.parameters.type!==`object`)throw new t(`Tool parameters type must be "object"`);if(e.parameters.properties)for(let n of Object.keys(e.parameters.properties)){let r=e.parameters.properties[n];if(!r?.type)throw new t(`Parameter "${n}" must have a type`);if(![`string`,`number`,`boolean`,`array`,`object`].includes(r.type))throw new t(`Parameter "${n}" has invalid type "${r.type}"`)}if(e.parameters.required){let n=e.parameters.properties||{};for(let r of e.parameters.required)if(!n[r])throw new t(`Required parameter "${r}" is not defined in properties`)}}};function i(e,t,n){switch(n.type){case`string`:if(typeof t!=`string`)return`Parameter "${e}" must be a string, got ${typeof t}`;break;case`number`:if(typeof t!=`number`||isNaN(t))return`Parameter "${e}" must be a number, got ${typeof t}`;break;case`boolean`:if(typeof t!=`boolean`)return`Parameter "${e}" must be a boolean, got ${typeof t}`;break;case`array`:if(!Array.isArray(t))return`Parameter "${e}" must be an array, got ${typeof t}`;if(n.items)for(let r=0;r<t.length;r++){let a=i(`${e}[${r}]`,t[r],n.items);if(a)return a}break;case`object`:if(typeof t!=`object`||!t||Array.isArray(t))return`Parameter "${e}" must be an object, got ${typeof t}`;break}if(n.enum&&n.enum.length>0){let r=n.enum,i=!1;for(let e of r)if(t===e){i=!0;break}if(!i)return`Parameter "${e}" must be one of: ${r.join(`, `)}, got ${t}`}}function a(e,t,n,r){let a=[];for(let n of t)n in e||a.push(`Missing required parameter: ${n}`);for(let[t,o]of Object.entries(e)){let e=n[t];if(!e){if(r===!0)continue;if(r&&typeof r==`object`){let e=i(t,o,r);e&&a.push(e);continue}a.push(`Unknown parameter: ${t}`);continue}let s=i(t,o,e);s&&a.push(s)}return a}function o(e,t,n,r){let i=a(e,t,n,r);return{isValid:i.length===0,errors:i}}function s(e,t={}){let n={},r=[],i=e._def;if(!i)throw Error(`Zod schema is missing _def; cannot convert to JSON schema.`);if(i.typeName===`ZodObject`&&i.shape){let e=typeof i.shape==`function`?i.shape():i.shape;for(let[t,i]of Object.entries(e))n[t]=c(i),l(i)&&r.push(t)}return{type:`object`,properties:n,required:r,...(t.allowAdditionalProperties||i.unknownKeys===`passthrough`)&&{additionalProperties:!0}}}function c(e){let t=e._def;if(!t)throw Error(`Zod type is missing _def; cannot convert to JSON schema.`);let n={};switch(t.description&&(n.description=t.description),t.typeName){case`ZodString`:return{type:`string`,...n};case`ZodNumber`:return{type:`number`,...n};case`ZodBoolean`:return{type:`boolean`,...n};case`ZodArray`:if(!t.type)throw Error(`ZodArray is missing item type; cannot convert to JSON schema.`);return{type:`array`,items:c(t.type),...n};case`ZodObject`:return{type:`object`,...n};case`ZodEnum`:{let e=t.values;if(!e||!Array.isArray(e))throw Error(`ZodEnum is missing enum values; cannot convert to JSON schema.`);return{type:`string`,enum:e,...n}}case`ZodOptional`:if(t.innerType)return{...c(t.innerType),...n};throw Error(`ZodOptional is missing innerType; cannot convert to JSON schema.`);case`ZodNullable`:if(t.innerType)return{...c(t.innerType),...n};throw Error(`ZodNullable is missing innerType; cannot convert to JSON schema.`);case`ZodDefault`:if(t.innerType)return{...c(t.innerType),...n};throw Error(`ZodDefault is missing innerType; cannot convert to JSON schema.`);case`ZodRecord`:return t.valueType?{type:`object`,additionalProperties:c(t.valueType),...n}:{type:`object`,additionalProperties:{type:`string`},...n};default:throw Error(`Unsupported Zod type: ${String(t.typeName)}`)}}function l(e){let t=e._def;if(!t)throw Error(`Zod schema is missing _def; cannot determine required fields.`);return t.typeName!==`ZodOptional`&&t.typeName!==`ZodNullable`&&t.typeName!==`ZodDefault`}var u=class{schema;fn;eventService;constructor(e,t){this.schema=e,this.fn=t,this.validateConstructorInputs()}getName(){return this.schema.name}setEventService(e){this.eventService=e}async execute(n,r){let i=this.schema.name;if(!this.validate(n))throw new t(`Invalid parameters for tool "${i}": ${a(n,this.schema.parameters.required||[],this.schema.parameters.properties||{},this.schema.parameters.additionalProperties).join(`, `)}`);let o=Date.now(),s;try{s=await this.fn(n,r)}catch(a){throw a instanceof e||a instanceof t?a:new e(`Function tool execution failed: ${a instanceof Error?a.message:String(a)}`,i,a instanceof Error?a:Error(String(a)),{parameterCount:Object.keys(n||{}).length,hasContext:!!r})}let c=Date.now()-o;return{success:!0,data:s,metadata:{executionTime:c,toolName:i,parameters:n}}}validate(e){return a(e,this.schema.parameters.required||[],this.schema.parameters.properties||{},this.schema.parameters.additionalProperties).length===0}validateParameters(e){return o(e,this.schema.parameters.required||[],this.schema.parameters.properties||{},this.schema.parameters.additionalProperties)}getDescription(){return this.schema.description}validateConstructorInputs(){if(!this.schema)throw new t(`Tool schema is required`);if(!this.fn||typeof this.fn!=`function`)throw new t(`Tool function is required and must be a function`);if(!this.schema.name)throw new t(`Tool schema must have a name`)}};function d(e,t,n,r){return new u({name:e,description:t,parameters:n},r)}function f(e,n,r,i){return new u({name:e,description:n,parameters:s(r)},async(e,n)=>{let a=r.safeParse(e);if(!a.success)throw new t(`Zod validation failed: ${a.error}`);let o=await i(a.data||e,n);return typeof o==`string`?o:JSON.stringify(o)})}export{u as FunctionTool,r as ToolRegistry,d as createFunctionTool,f as createZodFunctionTool,s as zodToJsonSchema};
2
2
  //# sourceMappingURL=browser.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"browser.js","names":[],"sources":["../../src/registry/tool-registry.ts","../../src/implementations/function-tool/parameter-validator.ts","../../src/implementations/function-tool/schema-converter.ts","../../src/implementations/function-tool.ts","../../src/implementations/openapi-schema-converter.ts","../../src/implementations/openapi-tool.ts"],"sourcesContent":["import { ValidationError } from '@robota-sdk/agent-core';\nimport { logger } from '@robota-sdk/agent-core';\n\nimport type { ITool, IToolRegistry } from '@robota-sdk/agent-core';\nimport type { IToolSchema } from '@robota-sdk/agent-core';\n\n/**\n * Tool registry implementation\n * Manages tool registration, validation, and retrieval\n */\nexport class ToolRegistry implements IToolRegistry {\n private tools = new Map<string, ITool>();\n\n /**\n * Register a tool\n */\n register(tool: ITool): void {\n if (!tool.schema?.name) {\n throw new ValidationError('Tool must have a valid schema with name');\n }\n\n const toolName = tool.schema.name;\n\n // Validate tool schema\n this.validateToolSchema(tool.schema);\n\n // Check for duplicate registration\n if (this.tools.has(toolName)) {\n logger.warn(`Tool \"${toolName}\" is already registered, overriding`, {\n toolName,\n existingTool: this.tools.get(toolName)?.constructor.name,\n });\n }\n\n this.tools.set(toolName, tool);\n logger.debug(`Tool \"${toolName}\" registered successfully`, {\n toolName,\n toolType: tool.constructor.name,\n parameters: Object.keys(tool.schema.parameters?.properties || {}),\n });\n }\n\n /**\n * Unregister a tool\n */\n unregister(name: string): void {\n if (!this.tools.has(name)) {\n logger.warn(`Attempted to unregister non-existent tool \"${name}\"`);\n return;\n }\n\n this.tools.delete(name);\n logger.debug(`Tool \"${name}\" unregistered successfully`);\n }\n\n /**\n * Get tool by name\n */\n get(name: string): ITool | undefined {\n return this.tools.get(name);\n }\n\n /**\n * Get all registered tools\n */\n getAll(): ITool[] {\n return Array.from(this.tools.values());\n }\n\n /**\n * Get tool schemas\n */\n getSchemas(): IToolSchema[] {\n const tools = this.getAll();\n\n // 🔍 [TOOL-FLOW] ToolRegistry.getSchemas() - Extracting schemas from tools\n logger.debug('[TOOL-FLOW] ToolRegistry.getSchemas() - Tools before schema extraction', {\n count: tools.length,\n tools: tools.map((t) => ({\n name: t.schema?.name ?? 'unnamed',\n hasSchema: !!t.schema,\n schemaType: typeof t.schema,\n toolType: t.constructor?.name || 'unknown',\n })),\n });\n\n return this.getAll().map((tool) => tool.schema);\n }\n\n /**\n * Check if tool exists\n */\n has(name: string): boolean {\n return this.tools.has(name);\n }\n\n /**\n * Clear all tools\n */\n clear(): void {\n const toolCount = this.tools.size;\n this.tools.clear();\n logger.debug(`Cleared ${toolCount} tools from registry`);\n }\n\n /**\n * Get tool names\n */\n getToolNames(): string[] {\n return Array.from(this.tools.keys());\n }\n\n /**\n * Get tools by pattern\n */\n getToolsByPattern(pattern: string | RegExp): ITool[] {\n const regex = typeof pattern === 'string' ? new RegExp(pattern) : pattern;\n return this.getAll().filter((tool) => regex.test(tool.schema.name));\n }\n\n /**\n * Get tool count\n */\n size(): number {\n return this.tools.size;\n }\n\n /**\n * Validate tool schema\n */\n private validateToolSchema(schema: IToolSchema): void {\n if (!schema.name || typeof schema.name !== 'string') {\n throw new ValidationError('Tool schema must have a valid name');\n }\n\n if (!schema.description || typeof schema.description !== 'string') {\n throw new ValidationError('Tool schema must have a description');\n }\n\n if (\n !schema.parameters ||\n typeof schema.parameters !== 'object' ||\n schema.parameters === null ||\n Array.isArray(schema.parameters)\n ) {\n throw new ValidationError('Tool schema must have parameters object');\n }\n\n if (schema.parameters.type !== 'object') {\n throw new ValidationError('Tool parameters type must be \"object\"');\n }\n\n // Validate parameter properties\n if (schema.parameters.properties) {\n for (const propName of Object.keys(schema.parameters.properties)) {\n const propSchema = schema.parameters.properties[propName];\n if (!propSchema?.type) {\n throw new ValidationError(`Parameter \"${propName}\" must have a type`);\n }\n\n const validTypes = ['string', 'number', 'boolean', 'array', 'object'];\n if (!validTypes.includes(propSchema.type)) {\n throw new ValidationError(\n `Parameter \"${propName}\" has invalid type \"${propSchema.type}\"`,\n );\n }\n }\n }\n\n // Validate required fields exist in properties\n if (schema.parameters.required) {\n const properties = schema.parameters.properties || {};\n for (const requiredField of schema.parameters.required) {\n if (!properties[requiredField]) {\n throw new ValidationError(\n `Required parameter \"${requiredField}\" is not defined in properties`,\n );\n }\n }\n }\n }\n}\n","import type {\n IParameterSchema,\n TToolParameters,\n IParameterValidationResult,\n} from '@robota-sdk/agent-core';\nimport type { TUniversalValue } from '@robota-sdk/agent-core';\n\n/**\n * Validate individual parameter type against its schema.\n * Returns an error string if invalid, undefined if valid.\n */\nexport function validateParameterType(\n key: string,\n value: TUniversalValue,\n schema: IParameterSchema,\n): string | undefined {\n const expectedType = schema['type'];\n\n switch (expectedType) {\n case 'string':\n if (typeof value !== 'string') {\n return `Parameter \"${key}\" must be a string, got ${typeof value}`;\n }\n break;\n\n case 'number':\n if (typeof value !== 'number' || isNaN(value)) {\n return `Parameter \"${key}\" must be a number, got ${typeof value}`;\n }\n break;\n\n case 'boolean':\n if (typeof value !== 'boolean') {\n return `Parameter \"${key}\" must be a boolean, got ${typeof value}`;\n }\n break;\n\n case 'array':\n if (!Array.isArray(value)) {\n return `Parameter \"${key}\" must be an array, got ${typeof value}`;\n }\n // Check array items if specified\n if (schema.items) {\n for (let i = 0; i < value.length; i++) {\n const itemError = validateParameterType(`${key}[${i}]`, value[i], schema.items);\n if (itemError) {\n return itemError;\n }\n }\n }\n break;\n\n case 'object':\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n return `Parameter \"${key}\" must be an object, got ${typeof value}`;\n }\n break;\n }\n\n // Check enum constraints\n if (schema.enum && schema.enum.length > 0) {\n const enumValues = schema.enum;\n let isValidEnum = false;\n\n // Type-safe enum checking based on JSONSchemaEnum type\n for (const enumValue of enumValues) {\n if (value === enumValue) {\n isValidEnum = true;\n break;\n }\n }\n\n if (!isValidEnum) {\n return `Parameter \"${key}\" must be one of: ${enumValues.join(', ')}, got ${value}`;\n }\n }\n\n return undefined;\n}\n\n/**\n * Collect all validation errors for the given parameters against a schema.\n */\nexport function getValidationErrors(\n parameters: TToolParameters,\n schemaRequired: string[],\n schemaProperties: Record<string, IParameterSchema>,\n additionalProperties?: boolean | IParameterSchema,\n): string[] {\n const errors: string[] = [];\n\n // Check required parameters\n for (const field of schemaRequired) {\n if (!(field in parameters)) {\n errors.push(`Missing required parameter: ${field}`);\n }\n }\n\n // Check parameter types and constraints\n for (const [key, value] of Object.entries(parameters)) {\n const paramSchema = schemaProperties[key];\n if (!paramSchema) {\n if (additionalProperties === true) {\n continue;\n }\n if (additionalProperties && typeof additionalProperties === 'object') {\n const additionalTypeError = validateParameterType(key, value, additionalProperties);\n if (additionalTypeError) errors.push(additionalTypeError);\n continue;\n }\n errors.push(`Unknown parameter: ${key}`);\n continue;\n }\n\n const typeError = validateParameterType(key, value, paramSchema);\n if (typeError) {\n errors.push(typeError);\n }\n }\n\n return errors;\n}\n\n/**\n * Validate parameters and return a structured result.\n */\nexport function validateToolParameters(\n parameters: TToolParameters,\n schemaRequired: string[],\n schemaProperties: Record<string, IParameterSchema>,\n additionalProperties?: boolean | IParameterSchema,\n): IParameterValidationResult {\n const errors = getValidationErrors(\n parameters,\n schemaRequired,\n schemaProperties,\n additionalProperties,\n );\n return {\n isValid: errors.length === 0,\n errors,\n };\n}\n","/**\n * FunctionTool - Schema conversion utilities for Facade pattern\n *\n * REASON: Complex Zod to JSON schema conversion requires isolated utility functions\n * ALTERNATIVES_CONSIDERED:\n * 1. Keep conversion logic in main class (violates single responsibility)\n * 2. Use third-party library (adds external dependency)\n * 3. Manual conversion each time (code duplication)\n * 4. Runtime type checking only (loses compile-time safety)\n * 5. Remove Zod support (breaks backward compatibility)\n * TODO: Consider caching conversion results for performance\n */\n\nimport type { IZodSchema, ISchemaConversionOptions } from './types';\nimport type {\n IToolSchema,\n IParameterSchema,\n TJSONSchemaEnum,\n TUniversalValue,\n} from '@robota-sdk/agent-core';\n\n/**\n * Convert Zod schema to JSON Schema format with safe undefined handling\n */\nexport function zodToJsonSchema(\n schema: IZodSchema,\n options: ISchemaConversionOptions = {},\n): IToolSchema['parameters'] {\n const properties: Record<string, IParameterSchema> = {};\n const required: string[] = [];\n\n // Safe access to schema definition (no fallback).\n const schemaDef = schema._def;\n if (!schemaDef) {\n throw new Error('Zod schema is missing _def; cannot convert to JSON schema.');\n }\n\n // Handle object schemas with shape\n if (schemaDef.typeName === 'ZodObject' && schemaDef.shape) {\n // In Zod v3, shape is a property, not a function\n const shape = typeof schemaDef.shape === 'function' ? schemaDef.shape() : schemaDef.shape;\n\n for (const [key, typeObj] of Object.entries(shape)) {\n const property = convertZodTypeToProperty(typeObj);\n properties[key] = property;\n\n // Check if field is required (not optional/nullable)\n if (isRequiredField(typeObj)) {\n required.push(key);\n }\n }\n }\n\n return {\n type: 'object',\n properties,\n required,\n ...((options.allowAdditionalProperties || schemaDef.unknownKeys === 'passthrough') && {\n additionalProperties: true,\n }),\n };\n}\n\n/**\n * Convert individual Zod type to parameter schema with safe undefined handling\n */\nfunction convertZodTypeToProperty(typeObj: IZodSchema): IParameterSchema {\n // Safe access to type definition\n const typeDef = typeObj._def;\n if (!typeDef) {\n throw new Error('Zod type is missing _def; cannot convert to JSON schema.');\n }\n\n const base: Partial<IParameterSchema> = {};\n\n // Add description if available\n if (typeDef.description) {\n base.description = typeDef.description;\n }\n\n // Handle different Zod types\n switch (typeDef.typeName) {\n case 'ZodString':\n return { type: 'string', ...base };\n\n case 'ZodNumber':\n return { type: 'number', ...base };\n\n case 'ZodBoolean':\n return { type: 'boolean', ...base };\n\n case 'ZodArray': {\n if (!typeDef.type) {\n throw new Error('ZodArray is missing item type; cannot convert to JSON schema.');\n }\n const arrayItems = convertZodTypeToProperty(typeDef.type);\n return {\n type: 'array',\n items: arrayItems,\n ...base,\n };\n }\n\n case 'ZodObject':\n return { type: 'object', ...base };\n\n case 'ZodEnum': {\n const enumValues = typeDef.values;\n if (!enumValues || !Array.isArray(enumValues)) {\n throw new Error('ZodEnum is missing enum values; cannot convert to JSON schema.');\n }\n return {\n type: 'string',\n enum: enumValues as TJSONSchemaEnum,\n ...base,\n };\n }\n\n case 'ZodOptional':\n // Handle optional types by recursion\n if (typeDef.innerType) {\n const innerProperty = convertZodTypeToProperty(typeDef.innerType);\n return { ...innerProperty, ...base };\n }\n throw new Error('ZodOptional is missing innerType; cannot convert to JSON schema.');\n\n case 'ZodNullable':\n // Handle nullable types\n if (typeDef.innerType) {\n const innerProperty = convertZodTypeToProperty(typeDef.innerType);\n return { ...innerProperty, ...base };\n }\n throw new Error('ZodNullable is missing innerType; cannot convert to JSON schema.');\n\n case 'ZodDefault':\n // Handle default values by processing the inner type\n if (typeDef.innerType) {\n const innerProperty = convertZodTypeToProperty(typeDef.innerType);\n return { ...innerProperty, ...base };\n }\n throw new Error('ZodDefault is missing innerType; cannot convert to JSON schema.');\n\n case 'ZodRecord':\n // Handle Record<string, T> → JSON Schema additionalProperties\n if (typeDef.valueType) {\n const valueProperty = convertZodTypeToProperty(typeDef.valueType);\n return { type: 'object', additionalProperties: valueProperty, ...base };\n }\n return { type: 'object', additionalProperties: { type: 'string' }, ...base };\n\n default:\n throw new Error(`Unsupported Zod type: ${String(typeDef.typeName)}`);\n }\n}\n\n/**\n * Check if a Zod field is required (not optional or nullable)\n */\nfunction isRequiredField(typeObj: IZodSchema): boolean {\n const typeDef = typeObj._def;\n if (!typeDef) {\n throw new Error('Zod schema is missing _def; cannot determine required fields.');\n }\n\n // Field is optional if it's ZodOptional, ZodNullable, or ZodDefault\n return (\n typeDef.typeName !== 'ZodOptional' &&\n typeDef.typeName !== 'ZodNullable' &&\n typeDef.typeName !== 'ZodDefault'\n );\n}\n\n/**\n * Safely extract enum values from Zod schema\n */\nexport function extractEnumValues(schema: IZodSchema): TUniversalValue[] {\n const typeDef = schema._def;\n if (!typeDef) {\n throw new Error('Zod schema is missing _def; cannot extract enum values.');\n }\n if (!typeDef.values || !Array.isArray(typeDef.values)) {\n throw new Error('ZodEnum schema is missing enum values; cannot extract enum values.');\n }\n return typeDef.values;\n}\n\n/**\n * Check if schema has validation constraints\n */\nexport function hasValidationConstraints(schema: IZodSchema): boolean {\n const typeDef = schema._def;\n if (!typeDef) {\n throw new Error('Zod schema is missing _def; cannot determine validation constraints.');\n }\n\n return !!(typeDef.checks && typeDef.checks.length > 0);\n}\n\n/**\n * Safe schema type name extraction\n */\nexport function getSchemaTypeName(schema: IZodSchema): string {\n const typeDef = schema._def;\n if (!typeDef) {\n throw new Error('Zod schema is missing _def; cannot determine schema type name.');\n }\n if (!typeDef.typeName) {\n throw new Error('Zod schema has empty typeName; cannot determine schema type name.');\n }\n return typeDef.typeName;\n}\n","import { ToolExecutionError, ValidationError } from '@robota-sdk/agent-core';\n\nimport { getValidationErrors, validateToolParameters } from './function-tool/parameter-validator';\nimport { zodToJsonSchema } from './function-tool/schema-converter';\n\nimport type { IZodSchema } from './function-tool/types';\nimport type {\n IFunctionTool,\n IToolResult,\n IToolExecutionContext,\n IParameterValidationResult,\n TToolExecutor,\n TToolParameters,\n IEventService,\n} from '@robota-sdk/agent-core';\nimport type { IToolSchema } from '@robota-sdk/agent-core';\nimport type { TUniversalValue } from '@robota-sdk/agent-core';\n\n// Import from Facade pattern modules for type safety\n\n/**\n * Function tool implementation\n * Wraps a JavaScript function as a tool with schema validation\n *\n * Implements IFunctionTool without extending AbstractTool to avoid\n * circular runtime dependency (tools → agents → tools).\n */\nexport class FunctionTool implements IFunctionTool {\n readonly schema: IToolSchema;\n readonly fn: TToolExecutor;\n private eventService: IEventService | undefined;\n\n constructor(schema: IToolSchema, fn: TToolExecutor) {\n this.schema = schema;\n this.fn = fn;\n this.validateConstructorInputs();\n }\n\n /**\n * Get tool name\n */\n getName(): string {\n return this.schema.name;\n }\n\n /**\n * Set EventService for post-construction injection.\n * Accepts EventService as-is without transformation.\n * Caller is responsible for providing properly configured EventService.\n */\n setEventService(eventService: IEventService | undefined): void {\n this.eventService = eventService;\n }\n\n /**\n * Execute the function tool\n */\n async execute(\n parameters: TToolParameters,\n context?: IToolExecutionContext,\n ): Promise<IToolResult> {\n const toolName = this.schema.name;\n\n // Validate parameters before execution\n if (!this.validate(parameters)) {\n const errors = getValidationErrors(\n parameters,\n this.schema.parameters.required || [],\n this.schema.parameters.properties || {},\n this.schema.parameters.additionalProperties,\n );\n throw new ValidationError(`Invalid parameters for tool \"${toolName}\": ${errors.join(', ')}`);\n }\n\n // Execute the function\n const startTime = Date.now();\n let result: TUniversalValue;\n try {\n result = await this.fn(parameters, context);\n } catch (error) {\n if (error instanceof ToolExecutionError || error instanceof ValidationError) {\n throw error;\n }\n\n throw new ToolExecutionError(\n `Function tool execution failed: ${error instanceof Error ? error.message : String(error)}`,\n toolName,\n error instanceof Error ? error : new Error(String(error)),\n {\n parameterCount: Object.keys(parameters || {}).length,\n hasContext: !!context,\n },\n );\n }\n\n const executionTime = Date.now() - startTime;\n\n return {\n success: true,\n data: result,\n metadata: {\n executionTime,\n toolName,\n parameters,\n },\n };\n }\n\n /**\n * Validate parameters (simple boolean result)\n */\n validate(parameters: TToolParameters): boolean {\n return (\n getValidationErrors(\n parameters,\n this.schema.parameters.required || [],\n this.schema.parameters.properties || {},\n this.schema.parameters.additionalProperties,\n ).length === 0\n );\n }\n\n /**\n * Validate tool parameters with detailed result\n */\n validateParameters(parameters: TToolParameters): IParameterValidationResult {\n return validateToolParameters(\n parameters,\n this.schema.parameters.required || [],\n this.schema.parameters.properties || {},\n this.schema.parameters.additionalProperties,\n );\n }\n\n /**\n * Get tool description\n */\n getDescription(): string {\n return this.schema.description;\n }\n\n /**\n * Validate constructor inputs\n */\n private validateConstructorInputs(): void {\n if (!this.schema) {\n throw new ValidationError('Tool schema is required');\n }\n\n if (!this.fn || typeof this.fn !== 'function') {\n throw new ValidationError('Tool function is required and must be a function');\n }\n\n if (!this.schema.name) {\n throw new ValidationError('Tool schema must have a name');\n }\n }\n}\n\n/**\n * Helper function to create a function tool from a simple function\n */\nexport function createFunctionTool(\n name: string,\n description: string,\n parameters: IToolSchema['parameters'],\n fn: TToolExecutor,\n): FunctionTool {\n const schema: IToolSchema = {\n name,\n description,\n parameters,\n };\n\n return new FunctionTool(schema, fn);\n}\n\n/**\n * Helper function to create a function tool from Zod schema\n */\nexport function createZodFunctionTool(\n name: string,\n description: string,\n zodSchema: IZodSchema,\n fn: TToolExecutor,\n): FunctionTool {\n // Use comprehensive Zod to JSON schema conversion\n const parameters = zodToJsonSchema(zodSchema);\n\n const schema: IToolSchema = {\n name,\n description,\n parameters,\n };\n\n // Wrap the function with validation and ensure proper parameter handling\n const wrappedFn: TToolExecutor = async (\n parameters: TToolParameters,\n context?: IToolExecutionContext,\n ): Promise<TUniversalValue> => {\n // Use Zod for runtime validation\n const parseResult = zodSchema.safeParse(parameters);\n if (!parseResult.success) {\n throw new ValidationError(`Zod validation failed: ${parseResult.error}`);\n }\n\n const result = await fn((parseResult.data as TToolParameters) || parameters, context);\n // Ensure result is always a string for consistency with core package\n return typeof result === 'string' ? result : JSON.stringify(result);\n };\n\n return new FunctionTool(schema, wrappedFn);\n}\n\n// zodToJsonSchema function moved to Facade pattern schema-converter module\n","import type { IParameterSchema } from '@robota-sdk/agent-core';\nimport type { IToolSchema } from '@robota-sdk/agent-core';\nimport type { OpenAPIV3 } from 'openapi-types';\n\n/**\n * OpenAPI operation method types\n */\nexport type THTTPMethod = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'head' | 'options';\n\n/**\n * HTTP methods to search when scanning OpenAPI paths\n */\nexport const HTTP_METHODS: THTTPMethod[] = [\n 'get',\n 'post',\n 'put',\n 'delete',\n 'patch',\n 'head',\n 'options',\n];\n\n/**\n * Find an operation in the OpenAPI spec by operationId\n */\nexport function findOperation(\n apiSpec: OpenAPIV3.Document,\n operationId: string,\n): { method: THTTPMethod; path: string; operation: OpenAPIV3.OperationObject } | undefined {\n for (const [path, pathItem] of Object.entries(apiSpec.paths || {})) {\n if (!pathItem) continue;\n\n for (const method of HTTP_METHODS) {\n const operation = (pathItem as Record<string, OpenAPIV3.OperationObject | undefined>)[method];\n if (operation?.operationId === operationId) {\n return { method, path, operation };\n }\n }\n }\n return undefined;\n}\n\n/**\n * Map OpenAPI type to JSON schema type\n */\nexport function mapOpenAPIType(type: string | undefined): IParameterSchema['type'] {\n switch (type) {\n case 'string':\n return 'string';\n case 'number':\n return 'number';\n case 'integer':\n return 'integer';\n case 'boolean':\n return 'boolean';\n case 'array':\n return 'array';\n case 'object':\n return 'object';\n default:\n return 'string';\n }\n}\n\n/**\n * Convert OpenAPI schema to parameter schema\n */\nexport function convertOpenAPISchemaToParameterSchema(\n schema: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject,\n): IParameterSchema {\n // Handle reference objects\n if ('$ref' in schema) {\n // For now, treat references as generic objects\n return { type: 'object' };\n }\n\n const result: IParameterSchema = {\n type: mapOpenAPIType(schema.type),\n };\n\n if (schema.description) {\n result.description = schema.description;\n }\n\n if (schema.enum) {\n result.enum = schema.enum as (string | number | boolean)[];\n }\n\n if (schema.minimum !== undefined) {\n result.minimum = schema.minimum;\n }\n\n if (schema.maximum !== undefined) {\n result.maximum = schema.maximum;\n }\n\n if (schema.pattern) {\n result.pattern = schema.pattern;\n }\n\n if (schema.format) {\n result.format = schema.format;\n }\n\n if (schema.default !== undefined) {\n result.default = schema.default;\n }\n\n // Handle array items\n if (schema.type === 'array' && schema.items) {\n result.items = convertOpenAPISchemaToParameterSchema(schema.items);\n }\n\n // Handle object properties\n if (schema.type === 'object' && schema.properties) {\n result.properties = {};\n for (const [propName, propSchema] of Object.entries(schema.properties)) {\n result.properties[propName] = convertOpenAPISchemaToParameterSchema(propSchema);\n }\n\n if (schema.required && schema.required.length > 0) {\n (result as { required?: string[] }).required = schema.required;\n }\n }\n\n return result;\n}\n\n/**\n * Convert OpenAPI parameter object to tool parameter schema\n */\nexport function convertOpenAPIParamToSchema(param: OpenAPIV3.ParameterObject): IParameterSchema {\n const schema = param.schema as OpenAPIV3.SchemaObject;\n return convertOpenAPISchemaToParameterSchema(schema);\n}\n\n/**\n * Create a tool schema from an OpenAPI operation specification\n */\nexport function createSchemaFromOperation(\n operationId: string,\n opSpec: OpenAPIV3.OperationObject,\n): IToolSchema {\n const properties: Record<string, IParameterSchema> = {};\n const required: string[] = [];\n\n // Convert OpenAPI parameters to tool schema\n const params = (opSpec.parameters as OpenAPIV3.ParameterObject[]) || [];\n for (const param of params) {\n properties[param.name] = convertOpenAPIParamToSchema(param);\n if (param.required) {\n required.push(param.name);\n }\n }\n\n // Handle request body for POST/PUT/PATCH operations\n if (opSpec.requestBody) {\n const requestBody = opSpec.requestBody as OpenAPIV3.RequestBodyObject;\n const jsonContent = requestBody.content?.['application/json'];\n if (jsonContent?.schema) {\n const bodySchema = convertOpenAPISchemaToParameterSchema(jsonContent.schema);\n if (bodySchema.type === 'object' && bodySchema.properties) {\n Object.assign(properties, bodySchema.properties);\n // Handle required properties for object schemas\n const schemaWithRequired = bodySchema as IParameterSchema & { required?: string[] };\n if (schemaWithRequired.required) {\n required.push(...schemaWithRequired.required);\n }\n }\n }\n }\n\n const schemaParams: {\n type: 'object';\n properties: Record<string, IParameterSchema>;\n required?: string[];\n } = {\n type: 'object',\n properties,\n };\n\n if (required.length > 0) {\n schemaParams.required = required;\n }\n\n return {\n name: operationId,\n description: opSpec.summary || opSpec.description || `OpenAPI operation: ${operationId}`,\n parameters: schemaParams,\n };\n}\n","import { ToolExecutionError, ValidationError } from '@robota-sdk/agent-core';\n\nimport {\n type THTTPMethod,\n findOperation,\n createSchemaFromOperation,\n} from './openapi-schema-converter';\n\nimport type {\n ITool,\n IToolResult,\n IToolExecutionContext,\n IOpenAPIToolConfig,\n TToolParameters,\n IParameterValidationResult,\n IEventService,\n} from '@robota-sdk/agent-core';\nimport type { IToolSchema } from '@robota-sdk/agent-core';\nimport type { OpenAPIV3 } from 'openapi-types';\n\n/**\n * OpenAPI tool implementation\n * Executes API calls based on OpenAPI 3.0 specifications\n *\n * Implements ITool without extending AbstractTool to avoid\n * circular runtime dependency (tools → agents → tools).\n */\nexport class OpenAPITool implements ITool {\n readonly schema: IToolSchema;\n private readonly apiSpec: OpenAPIV3.Document;\n private readonly operationId: string;\n private readonly baseURL: string;\n private readonly config: IOpenAPIToolConfig;\n private eventService: IEventService | undefined;\n\n constructor(config: IOpenAPIToolConfig) {\n this.config = config;\n // Runtime validation of required OpenAPI 3.x fields before cast\n if (\n typeof config.spec !== 'object' ||\n config.spec === null ||\n typeof config.spec.openapi !== 'string' ||\n typeof config.spec.paths !== 'object'\n ) {\n throw new Error(\n 'Invalid OpenAPI spec: must contain \"openapi\" (string) and \"paths\" (object) fields',\n );\n }\n this.apiSpec = config.spec as OpenAPIV3.Document;\n this.operationId = config.operationId;\n this.baseURL = config.baseURL;\n this.schema = this.createSchemaFromOpenAPI();\n }\n\n /**\n * Execute the OpenAPI tool\n */\n async execute(\n parameters: TToolParameters,\n context?: IToolExecutionContext,\n ): Promise<IToolResult> {\n const toolName = this.schema.name;\n\n // Validate parameters\n const validation = this.validateParameters(parameters);\n if (!validation.isValid) {\n throw new ValidationError(\n `Invalid parameters for OpenAPI tool \"${toolName}\": ${validation.errors.join(', ')}`,\n );\n }\n\n try {\n // Execute the API call\n const startTime = Date.now();\n const result = await this.executeAPICall(parameters, context);\n const executionTime = Date.now() - startTime;\n\n return {\n success: true,\n data: result,\n metadata: {\n executionTime,\n toolName,\n operationId: this.operationId,\n baseURL: this.baseURL,\n },\n };\n } catch (error) {\n if (error instanceof ToolExecutionError || error instanceof ValidationError) {\n throw error;\n }\n\n const safeError = error instanceof Error ? error : new Error(String(error));\n throw new ToolExecutionError(\n `OpenAPI tool execution failed: ${safeError.message}`,\n toolName,\n safeError,\n {\n operationId: this.operationId,\n baseURL: this.baseURL,\n parametersCount: Object.keys(parameters).length,\n },\n );\n }\n }\n\n /**\n * Validate tool parameters\n */\n validate(parameters: TToolParameters): boolean {\n return this.validateParameters(parameters).isValid;\n }\n\n /**\n * Validate tool parameters with detailed result\n */\n validateParameters(parameters: TToolParameters): IParameterValidationResult {\n const required = this.schema.parameters.required || [];\n const errors: string[] = [];\n\n for (const field of required) {\n if (!(field in parameters)) {\n errors.push(`Missing required parameter: ${field}`);\n }\n }\n\n return {\n isValid: errors.length === 0,\n errors,\n };\n }\n\n /**\n * Get tool name\n */\n getName(): string {\n return this.schema.name;\n }\n\n /**\n * Set EventService for post-construction injection.\n */\n setEventService(eventService: IEventService | undefined): void {\n this.eventService = eventService;\n }\n\n /**\n * Get tool description\n */\n getDescription(): string {\n return this.schema.description;\n }\n\n /**\n * Execute the actual API call\n * @private\n */\n private async executeAPICall(\n parameters: TToolParameters,\n _context?: IToolExecutionContext,\n ): Promise<never> {\n // Find the operation in the OpenAPI spec\n const operation = findOperation(this.apiSpec, this.operationId);\n if (!operation) {\n throw new Error(`Operation ${this.operationId} not found in OpenAPI spec`);\n }\n\n // Build the HTTP request\n this.buildRequestConfig(operation, parameters);\n\n throw new Error('Not implemented: actual API execution is not yet available');\n }\n\n /**\n * Build HTTP request configuration from OpenAPI operation and parameters\n */\n private buildRequestConfig(\n opInfo: { method: THTTPMethod; path: string; operation: OpenAPIV3.OperationObject },\n parameters: TToolParameters,\n ): { method: THTTPMethod; url: string; headers: Record<string, string>; body?: string } {\n const { method, path, operation } = opInfo;\n\n let url = this.baseURL + path;\n const headers: Record<string, string> = {};\n let body: string | undefined;\n\n // Process parameters based on their location\n const params = (operation.parameters as OpenAPIV3.ParameterObject[]) || [];\n\n for (const param of params) {\n const value = parameters[param.name];\n if (value === undefined && param.required) {\n throw new Error(`Required parameter ${param.name} is missing`);\n }\n\n if (value !== undefined) {\n switch (param.in) {\n case 'path':\n url = url.replace(`{${param.name}}`, encodeURIComponent(String(value)));\n break;\n case 'query': {\n const separator = url.includes('?') ? '&' : '?';\n url += `${separator}${param.name}=${encodeURIComponent(String(value))}`;\n break;\n }\n case 'header':\n headers[param.name] = String(value);\n break;\n }\n }\n }\n\n // Handle request body for POST/PUT/PATCH operations\n if (['post', 'put', 'patch'].includes(method) && operation.requestBody) {\n const requestBody = operation.requestBody as OpenAPIV3.RequestBodyObject;\n const jsonContent = requestBody.content?.['application/json'];\n if (jsonContent) {\n headers['Content-Type'] = 'application/json';\n // Extract body parameters (those not in path/query/header)\n const bodyParams: TToolParameters = {};\n for (const [key, value] of Object.entries(parameters)) {\n const isParamUsed = params.some((p) => p.name === key);\n if (!isParamUsed) {\n bodyParams[key] = value;\n }\n }\n body = JSON.stringify(bodyParams);\n }\n }\n\n // Add authentication headers if configured\n if (this.config.auth) {\n switch (this.config.auth.type) {\n case 'bearer':\n headers['Authorization'] = `Bearer ${this.config.auth.token}`;\n break;\n case 'apiKey': {\n const headerName = this.config.auth.header || 'X-API-Key';\n headers[headerName] = this.config.auth.apiKey || '';\n break;\n }\n }\n }\n\n const result: {\n method: THTTPMethod;\n url: string;\n headers: Record<string, string>;\n body?: string;\n } = {\n method,\n url,\n headers,\n };\n\n if (body !== undefined) {\n result.body = body;\n }\n\n return result;\n }\n\n /**\n * Create tool schema from OpenAPI operation specification\n */\n private createSchemaFromOpenAPI(): IToolSchema {\n const operation = findOperation(this.apiSpec, this.operationId);\n if (!operation) {\n throw new Error(\n `[STRICT-POLICY][EMITTER-CONTRACT] OpenAPI operation not found: ${this.operationId}. ` +\n `Emitter contract must provide a valid operationId present in the OpenAPI document.`,\n );\n }\n\n return createSchemaFromOperation(this.operationId, operation.operation);\n }\n}\n\n/**\n * Factory function to create OpenAPI tools from specification\n */\nexport function createOpenAPITool(config: IOpenAPIToolConfig): OpenAPITool {\n return new OpenAPITool(config);\n}\n"],"mappings":"6FAUA,IAAa,EAAb,KAAmD,CACjD,MAAgB,IAAI,IAKpB,SAAS,EAAmB,CAC1B,GAAI,CAAC,EAAK,QAAQ,KAChB,MAAM,IAAI,EAAgB,yCAAyC,EAGrE,IAAM,EAAW,EAAK,OAAO,KAG7B,KAAK,mBAAmB,EAAK,MAAM,EAG/B,KAAK,MAAM,IAAI,CAAQ,GACzB,EAAO,KAAK,SAAS,EAAS,qCAAsC,CAClE,WACA,aAAc,KAAK,MAAM,IAAI,CAAQ,GAAG,YAAY,IACtD,CAAC,EAGH,KAAK,MAAM,IAAI,EAAU,CAAI,EAC7B,EAAO,MAAM,SAAS,EAAS,2BAA4B,CACzD,WACA,SAAU,EAAK,YAAY,KAC3B,WAAY,OAAO,KAAK,EAAK,OAAO,YAAY,YAAc,CAAC,CAAC,CAClE,CAAC,CACH,CAKA,WAAW,EAAoB,CAC7B,GAAI,CAAC,KAAK,MAAM,IAAI,CAAI,EAAG,CACzB,EAAO,KAAK,8CAA8C,EAAK,EAAE,EACjE,MACF,CAEA,KAAK,MAAM,OAAO,CAAI,EACtB,EAAO,MAAM,SAAS,EAAK,4BAA4B,CACzD,CAKA,IAAI,EAAiC,CACnC,OAAO,KAAK,MAAM,IAAI,CAAI,CAC5B,CAKA,QAAkB,CAChB,OAAO,MAAM,KAAK,KAAK,MAAM,OAA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C9D,GAAI,CAAC,EACH,MAAU,MACR,kEAAkE,KAAK,YAAY,qFAErF,EAGF,OAAO,EAA0B,KAAK,YAAa,EAAU,SAAS,CACxE,CACF,EAKA,SAAgB,EAAkB,EAAyC,CACzE,OAAO,IAAI,EAAY,CAAM,CAC/B"}
1
+ {"version":3,"file":"browser.js","names":[],"sources":["../../src/registry/tool-registry.ts","../../src/implementations/function-tool/parameter-validator.ts","../../src/implementations/function-tool/schema-converter.ts","../../src/implementations/function-tool.ts"],"sourcesContent":["import { ValidationError } from '@robota-sdk/agent-core';\nimport { logger } from '@robota-sdk/agent-core';\n\nimport type { ITool, IToolRegistry } from '@robota-sdk/agent-core';\nimport type { IToolSchema } from '@robota-sdk/agent-core';\n\n/**\n * Tool registry implementation\n * Manages tool registration, validation, and retrieval\n */\nexport class ToolRegistry implements IToolRegistry {\n private tools = new Map<string, ITool>();\n\n /**\n * Register a tool\n */\n register(tool: ITool): void {\n if (!tool.schema?.name) {\n throw new ValidationError('Tool must have a valid schema with name');\n }\n\n const toolName = tool.schema.name;\n\n // Validate tool schema\n this.validateToolSchema(tool.schema);\n\n // Check for duplicate registration\n if (this.tools.has(toolName)) {\n logger.warn(`Tool \"${toolName}\" is already registered, overriding`, {\n toolName,\n existingTool: this.tools.get(toolName)?.constructor.name,\n });\n }\n\n this.tools.set(toolName, tool);\n logger.debug(`Tool \"${toolName}\" registered successfully`, {\n toolName,\n toolType: tool.constructor.name,\n parameters: Object.keys(tool.schema.parameters?.properties || {}),\n });\n }\n\n /**\n * Unregister a tool\n */\n unregister(name: string): void {\n if (!this.tools.has(name)) {\n logger.warn(`Attempted to unregister non-existent tool \"${name}\"`);\n return;\n }\n\n this.tools.delete(name);\n logger.debug(`Tool \"${name}\" unregistered successfully`);\n }\n\n /**\n * Get tool by name\n */\n get(name: string): ITool | undefined {\n return this.tools.get(name);\n }\n\n /**\n * Get all registered tools\n */\n getAll(): ITool[] {\n return Array.from(this.tools.values());\n }\n\n /**\n * Get tool schemas\n */\n getSchemas(): IToolSchema[] {\n const tools = this.getAll();\n\n // 🔍 [TOOL-FLOW] ToolRegistry.getSchemas() - Extracting schemas from tools\n logger.debug('[TOOL-FLOW] ToolRegistry.getSchemas() - Tools before schema extraction', {\n count: tools.length,\n tools: tools.map((t) => ({\n name: t.schema?.name ?? 'unnamed',\n hasSchema: !!t.schema,\n schemaType: typeof t.schema,\n toolType: t.constructor?.name || 'unknown',\n })),\n });\n\n return this.getAll().map((tool) => tool.schema);\n }\n\n /**\n * Check if tool exists\n */\n has(name: string): boolean {\n return this.tools.has(name);\n }\n\n /**\n * Clear all tools\n */\n clear(): void {\n const toolCount = this.tools.size;\n this.tools.clear();\n logger.debug(`Cleared ${toolCount} tools from registry`);\n }\n\n /**\n * Get tool names\n */\n getToolNames(): string[] {\n return Array.from(this.tools.keys());\n }\n\n /**\n * Get tools by pattern\n */\n getToolsByPattern(pattern: string | RegExp): ITool[] {\n const regex = typeof pattern === 'string' ? new RegExp(pattern) : pattern;\n return this.getAll().filter((tool) => regex.test(tool.schema.name));\n }\n\n /**\n * Get tool count\n */\n size(): number {\n return this.tools.size;\n }\n\n /**\n * Validate tool schema\n */\n private validateToolSchema(schema: IToolSchema): void {\n if (!schema.name || typeof schema.name !== 'string') {\n throw new ValidationError('Tool schema must have a valid name');\n }\n\n if (!schema.description || typeof schema.description !== 'string') {\n throw new ValidationError('Tool schema must have a description');\n }\n\n if (\n !schema.parameters ||\n typeof schema.parameters !== 'object' ||\n schema.parameters === null ||\n Array.isArray(schema.parameters)\n ) {\n throw new ValidationError('Tool schema must have parameters object');\n }\n\n if (schema.parameters.type !== 'object') {\n throw new ValidationError('Tool parameters type must be \"object\"');\n }\n\n // Validate parameter properties\n if (schema.parameters.properties) {\n for (const propName of Object.keys(schema.parameters.properties)) {\n const propSchema = schema.parameters.properties[propName];\n if (!propSchema?.type) {\n throw new ValidationError(`Parameter \"${propName}\" must have a type`);\n }\n\n const validTypes = ['string', 'number', 'boolean', 'array', 'object'];\n if (!validTypes.includes(propSchema.type)) {\n throw new ValidationError(\n `Parameter \"${propName}\" has invalid type \"${propSchema.type}\"`,\n );\n }\n }\n }\n\n // Validate required fields exist in properties\n if (schema.parameters.required) {\n const properties = schema.parameters.properties || {};\n for (const requiredField of schema.parameters.required) {\n if (!properties[requiredField]) {\n throw new ValidationError(\n `Required parameter \"${requiredField}\" is not defined in properties`,\n );\n }\n }\n }\n }\n}\n","import type {\n IParameterSchema,\n TToolParameters,\n IParameterValidationResult,\n} from '@robota-sdk/agent-core';\nimport type { TUniversalValue } from '@robota-sdk/agent-core';\n\n/**\n * Validate individual parameter type against its schema.\n * Returns an error string if invalid, undefined if valid.\n */\nexport function validateParameterType(\n key: string,\n value: TUniversalValue,\n schema: IParameterSchema,\n): string | undefined {\n const expectedType = schema['type'];\n\n switch (expectedType) {\n case 'string':\n if (typeof value !== 'string') {\n return `Parameter \"${key}\" must be a string, got ${typeof value}`;\n }\n break;\n\n case 'number':\n if (typeof value !== 'number' || isNaN(value)) {\n return `Parameter \"${key}\" must be a number, got ${typeof value}`;\n }\n break;\n\n case 'boolean':\n if (typeof value !== 'boolean') {\n return `Parameter \"${key}\" must be a boolean, got ${typeof value}`;\n }\n break;\n\n case 'array':\n if (!Array.isArray(value)) {\n return `Parameter \"${key}\" must be an array, got ${typeof value}`;\n }\n // Check array items if specified\n if (schema.items) {\n for (let i = 0; i < value.length; i++) {\n const itemError = validateParameterType(`${key}[${i}]`, value[i], schema.items);\n if (itemError) {\n return itemError;\n }\n }\n }\n break;\n\n case 'object':\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n return `Parameter \"${key}\" must be an object, got ${typeof value}`;\n }\n break;\n }\n\n // Check enum constraints\n if (schema.enum && schema.enum.length > 0) {\n const enumValues = schema.enum;\n let isValidEnum = false;\n\n // Type-safe enum checking based on JSONSchemaEnum type\n for (const enumValue of enumValues) {\n if (value === enumValue) {\n isValidEnum = true;\n break;\n }\n }\n\n if (!isValidEnum) {\n return `Parameter \"${key}\" must be one of: ${enumValues.join(', ')}, got ${value}`;\n }\n }\n\n return undefined;\n}\n\n/**\n * Collect all validation errors for the given parameters against a schema.\n */\nexport function getValidationErrors(\n parameters: TToolParameters,\n schemaRequired: string[],\n schemaProperties: Record<string, IParameterSchema>,\n additionalProperties?: boolean | IParameterSchema,\n): string[] {\n const errors: string[] = [];\n\n // Check required parameters\n for (const field of schemaRequired) {\n if (!(field in parameters)) {\n errors.push(`Missing required parameter: ${field}`);\n }\n }\n\n // Check parameter types and constraints\n for (const [key, value] of Object.entries(parameters)) {\n const paramSchema = schemaProperties[key];\n if (!paramSchema) {\n if (additionalProperties === true) {\n continue;\n }\n if (additionalProperties && typeof additionalProperties === 'object') {\n const additionalTypeError = validateParameterType(key, value, additionalProperties);\n if (additionalTypeError) errors.push(additionalTypeError);\n continue;\n }\n errors.push(`Unknown parameter: ${key}`);\n continue;\n }\n\n const typeError = validateParameterType(key, value, paramSchema);\n if (typeError) {\n errors.push(typeError);\n }\n }\n\n return errors;\n}\n\n/**\n * Validate parameters and return a structured result.\n */\nexport function validateToolParameters(\n parameters: TToolParameters,\n schemaRequired: string[],\n schemaProperties: Record<string, IParameterSchema>,\n additionalProperties?: boolean | IParameterSchema,\n): IParameterValidationResult {\n const errors = getValidationErrors(\n parameters,\n schemaRequired,\n schemaProperties,\n additionalProperties,\n );\n return {\n isValid: errors.length === 0,\n errors,\n };\n}\n","/**\n * FunctionTool - Schema conversion utilities for Facade pattern\n *\n * REASON: Complex Zod to JSON schema conversion requires isolated utility functions\n * ALTERNATIVES_CONSIDERED:\n * 1. Keep conversion logic in main class (violates single responsibility)\n * 2. Use third-party library (adds external dependency)\n * 3. Manual conversion each time (code duplication)\n * 4. Runtime type checking only (loses compile-time safety)\n * 5. Remove Zod support (breaks backward compatibility)\n * TODO: Consider caching conversion results for performance\n */\n\nimport type { IZodSchema, ISchemaConversionOptions } from './types';\nimport type {\n IToolSchema,\n IParameterSchema,\n TJSONSchemaEnum,\n TUniversalValue,\n} from '@robota-sdk/agent-core';\n\n/**\n * Convert Zod schema to JSON Schema format with safe undefined handling\n */\nexport function zodToJsonSchema(\n schema: IZodSchema,\n options: ISchemaConversionOptions = {},\n): IToolSchema['parameters'] {\n const properties: Record<string, IParameterSchema> = {};\n const required: string[] = [];\n\n // Safe access to schema definition (no fallback).\n const schemaDef = schema._def;\n if (!schemaDef) {\n throw new Error('Zod schema is missing _def; cannot convert to JSON schema.');\n }\n\n // Handle object schemas with shape\n if (schemaDef.typeName === 'ZodObject' && schemaDef.shape) {\n // In Zod v3, shape is a property, not a function\n const shape = typeof schemaDef.shape === 'function' ? schemaDef.shape() : schemaDef.shape;\n\n for (const [key, typeObj] of Object.entries(shape)) {\n const property = convertZodTypeToProperty(typeObj);\n properties[key] = property;\n\n // Check if field is required (not optional/nullable)\n if (isRequiredField(typeObj)) {\n required.push(key);\n }\n }\n }\n\n return {\n type: 'object',\n properties,\n required,\n ...((options.allowAdditionalProperties || schemaDef.unknownKeys === 'passthrough') && {\n additionalProperties: true,\n }),\n };\n}\n\n/**\n * Convert individual Zod type to parameter schema with safe undefined handling\n */\nfunction convertZodTypeToProperty(typeObj: IZodSchema): IParameterSchema {\n // Safe access to type definition\n const typeDef = typeObj._def;\n if (!typeDef) {\n throw new Error('Zod type is missing _def; cannot convert to JSON schema.');\n }\n\n const base: Partial<IParameterSchema> = {};\n\n // Add description if available\n if (typeDef.description) {\n base.description = typeDef.description;\n }\n\n // Handle different Zod types\n switch (typeDef.typeName) {\n case 'ZodString':\n return { type: 'string', ...base };\n\n case 'ZodNumber':\n return { type: 'number', ...base };\n\n case 'ZodBoolean':\n return { type: 'boolean', ...base };\n\n case 'ZodArray': {\n if (!typeDef.type) {\n throw new Error('ZodArray is missing item type; cannot convert to JSON schema.');\n }\n const arrayItems = convertZodTypeToProperty(typeDef.type);\n return {\n type: 'array',\n items: arrayItems,\n ...base,\n };\n }\n\n case 'ZodObject':\n return { type: 'object', ...base };\n\n case 'ZodEnum': {\n const enumValues = typeDef.values;\n if (!enumValues || !Array.isArray(enumValues)) {\n throw new Error('ZodEnum is missing enum values; cannot convert to JSON schema.');\n }\n return {\n type: 'string',\n enum: enumValues as TJSONSchemaEnum,\n ...base,\n };\n }\n\n case 'ZodOptional':\n // Handle optional types by recursion\n if (typeDef.innerType) {\n const innerProperty = convertZodTypeToProperty(typeDef.innerType);\n return { ...innerProperty, ...base };\n }\n throw new Error('ZodOptional is missing innerType; cannot convert to JSON schema.');\n\n case 'ZodNullable':\n // Handle nullable types\n if (typeDef.innerType) {\n const innerProperty = convertZodTypeToProperty(typeDef.innerType);\n return { ...innerProperty, ...base };\n }\n throw new Error('ZodNullable is missing innerType; cannot convert to JSON schema.');\n\n case 'ZodDefault':\n // Handle default values by processing the inner type\n if (typeDef.innerType) {\n const innerProperty = convertZodTypeToProperty(typeDef.innerType);\n return { ...innerProperty, ...base };\n }\n throw new Error('ZodDefault is missing innerType; cannot convert to JSON schema.');\n\n case 'ZodRecord':\n // Handle Record<string, T> → JSON Schema additionalProperties\n if (typeDef.valueType) {\n const valueProperty = convertZodTypeToProperty(typeDef.valueType);\n return { type: 'object', additionalProperties: valueProperty, ...base };\n }\n return { type: 'object', additionalProperties: { type: 'string' }, ...base };\n\n default:\n throw new Error(`Unsupported Zod type: ${String(typeDef.typeName)}`);\n }\n}\n\n/**\n * Check if a Zod field is required (not optional or nullable)\n */\nfunction isRequiredField(typeObj: IZodSchema): boolean {\n const typeDef = typeObj._def;\n if (!typeDef) {\n throw new Error('Zod schema is missing _def; cannot determine required fields.');\n }\n\n // Field is optional if it's ZodOptional, ZodNullable, or ZodDefault\n return (\n typeDef.typeName !== 'ZodOptional' &&\n typeDef.typeName !== 'ZodNullable' &&\n typeDef.typeName !== 'ZodDefault'\n );\n}\n\n/**\n * Safely extract enum values from Zod schema\n */\nexport function extractEnumValues(schema: IZodSchema): TUniversalValue[] {\n const typeDef = schema._def;\n if (!typeDef) {\n throw new Error('Zod schema is missing _def; cannot extract enum values.');\n }\n if (!typeDef.values || !Array.isArray(typeDef.values)) {\n throw new Error('ZodEnum schema is missing enum values; cannot extract enum values.');\n }\n return typeDef.values;\n}\n\n/**\n * Check if schema has validation constraints\n */\nexport function hasValidationConstraints(schema: IZodSchema): boolean {\n const typeDef = schema._def;\n if (!typeDef) {\n throw new Error('Zod schema is missing _def; cannot determine validation constraints.');\n }\n\n return !!(typeDef.checks && typeDef.checks.length > 0);\n}\n\n/**\n * Safe schema type name extraction\n */\nexport function getSchemaTypeName(schema: IZodSchema): string {\n const typeDef = schema._def;\n if (!typeDef) {\n throw new Error('Zod schema is missing _def; cannot determine schema type name.');\n }\n if (!typeDef.typeName) {\n throw new Error('Zod schema has empty typeName; cannot determine schema type name.');\n }\n return typeDef.typeName;\n}\n","import { ToolExecutionError, ValidationError } from '@robota-sdk/agent-core';\n\nimport { getValidationErrors, validateToolParameters } from './function-tool/parameter-validator';\nimport { zodToJsonSchema } from './function-tool/schema-converter';\n\nimport type { IZodSchema } from './function-tool/types';\nimport type {\n IFunctionTool,\n IToolResult,\n IToolExecutionContext,\n IParameterValidationResult,\n TToolExecutor,\n TToolParameters,\n IEventService,\n} from '@robota-sdk/agent-core';\nimport type { IToolSchema } from '@robota-sdk/agent-core';\nimport type { TUniversalValue } from '@robota-sdk/agent-core';\n\n// Import from Facade pattern modules for type safety\n\n/**\n * Function tool implementation\n * Wraps a JavaScript function as a tool with schema validation\n *\n * Implements IFunctionTool without extending AbstractTool to avoid\n * circular runtime dependency (tools → agents → tools).\n */\nexport class FunctionTool implements IFunctionTool {\n readonly schema: IToolSchema;\n readonly fn: TToolExecutor;\n private eventService: IEventService | undefined;\n\n constructor(schema: IToolSchema, fn: TToolExecutor) {\n this.schema = schema;\n this.fn = fn;\n this.validateConstructorInputs();\n }\n\n /**\n * Get tool name\n */\n getName(): string {\n return this.schema.name;\n }\n\n /**\n * Set EventService for post-construction injection.\n * Accepts EventService as-is without transformation.\n * Caller is responsible for providing properly configured EventService.\n */\n setEventService(eventService: IEventService | undefined): void {\n this.eventService = eventService;\n }\n\n /**\n * Execute the function tool\n */\n async execute(\n parameters: TToolParameters,\n context?: IToolExecutionContext,\n ): Promise<IToolResult> {\n const toolName = this.schema.name;\n\n // Validate parameters before execution\n if (!this.validate(parameters)) {\n const errors = getValidationErrors(\n parameters,\n this.schema.parameters.required || [],\n this.schema.parameters.properties || {},\n this.schema.parameters.additionalProperties,\n );\n throw new ValidationError(`Invalid parameters for tool \"${toolName}\": ${errors.join(', ')}`);\n }\n\n // Execute the function\n const startTime = Date.now();\n let result: TUniversalValue;\n try {\n result = await this.fn(parameters, context);\n } catch (error) {\n if (error instanceof ToolExecutionError || error instanceof ValidationError) {\n throw error;\n }\n\n throw new ToolExecutionError(\n `Function tool execution failed: ${error instanceof Error ? error.message : String(error)}`,\n toolName,\n error instanceof Error ? error : new Error(String(error)),\n {\n parameterCount: Object.keys(parameters || {}).length,\n hasContext: !!context,\n },\n );\n }\n\n const executionTime = Date.now() - startTime;\n\n return {\n success: true,\n data: result,\n metadata: {\n executionTime,\n toolName,\n parameters,\n },\n };\n }\n\n /**\n * Validate parameters (simple boolean result)\n */\n validate(parameters: TToolParameters): boolean {\n return (\n getValidationErrors(\n parameters,\n this.schema.parameters.required || [],\n this.schema.parameters.properties || {},\n this.schema.parameters.additionalProperties,\n ).length === 0\n );\n }\n\n /**\n * Validate tool parameters with detailed result\n */\n validateParameters(parameters: TToolParameters): IParameterValidationResult {\n return validateToolParameters(\n parameters,\n this.schema.parameters.required || [],\n this.schema.parameters.properties || {},\n this.schema.parameters.additionalProperties,\n );\n }\n\n /**\n * Get tool description\n */\n getDescription(): string {\n return this.schema.description;\n }\n\n /**\n * Validate constructor inputs\n */\n private validateConstructorInputs(): void {\n if (!this.schema) {\n throw new ValidationError('Tool schema is required');\n }\n\n if (!this.fn || typeof this.fn !== 'function') {\n throw new ValidationError('Tool function is required and must be a function');\n }\n\n if (!this.schema.name) {\n throw new ValidationError('Tool schema must have a name');\n }\n }\n}\n\n/**\n * Helper function to create a function tool from a simple function\n */\nexport function createFunctionTool(\n name: string,\n description: string,\n parameters: IToolSchema['parameters'],\n fn: TToolExecutor,\n): FunctionTool {\n const schema: IToolSchema = {\n name,\n description,\n parameters,\n };\n\n return new FunctionTool(schema, fn);\n}\n\n/**\n * Helper function to create a function tool from Zod schema\n */\nexport function createZodFunctionTool(\n name: string,\n description: string,\n zodSchema: IZodSchema,\n fn: TToolExecutor,\n): FunctionTool {\n // Use comprehensive Zod to JSON schema conversion\n const parameters = zodToJsonSchema(zodSchema);\n\n const schema: IToolSchema = {\n name,\n description,\n parameters,\n };\n\n // Wrap the function with validation and ensure proper parameter handling\n const wrappedFn: TToolExecutor = async (\n parameters: TToolParameters,\n context?: IToolExecutionContext,\n ): Promise<TUniversalValue> => {\n // Use Zod for runtime validation\n const parseResult = zodSchema.safeParse(parameters);\n if (!parseResult.success) {\n throw new ValidationError(`Zod validation failed: ${parseResult.error}`);\n }\n\n const result = await fn((parseResult.data as TToolParameters) || parameters, context);\n // Ensure result is always a string for consistency with core package\n return typeof result === 'string' ? result : JSON.stringify(result);\n };\n\n return new FunctionTool(schema, wrappedFn);\n}\n\n// zodToJsonSchema function moved to Facade pattern schema-converter module\n"],"mappings":"6FAUA,IAAa,EAAb,KAAmD,CACjD,MAAgB,IAAI,IAKpB,SAAS,EAAmB,CAC1B,GAAI,CAAC,EAAK,QAAQ,KAChB,MAAM,IAAI,EAAgB,yCAAyC,EAGrE,IAAM,EAAW,EAAK,OAAO,KAG7B,KAAK,mBAAmB,EAAK,MAAM,EAG/B,KAAK,MAAM,IAAI,CAAQ,GACzB,EAAO,KAAK,SAAS,EAAS,qCAAsC,CAClE,WACA,aAAc,KAAK,MAAM,IAAI,CAAQ,CAAC,EAAE,YAAY,IACtD,CAAC,EAGH,KAAK,MAAM,IAAI,EAAU,CAAI,EAC7B,EAAO,MAAM,SAAS,EAAS,2BAA4B,CACzD,WACA,SAAU,EAAK,YAAY,KAC3B,WAAY,OAAO,KAAK,EAAK,OAA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ACd,EACA,EACA,EACA,EACc,CA0Bd,OAAO,IAAI,EAAa,CArBtB,OACA,cACA,WALiB,EAAgB,CAKxB,CAmBa,EAAQ,MAd9B,EACA,IAC6B,CAE7B,IAAM,EAAc,EAAU,UAAU,CAAU,EAClD,GAAI,CAAC,EAAY,QACf,MAAM,IAAI,EAAgB,0BAA0B,EAAY,OAAO,EAGzE,IAAM,EAAS,MAAM,EAAI,EAAY,MAA4B,EAAY,CAAO,EAEpF,OAAO,OAAO,GAAW,SAAW,EAAS,KAAK,UAAU,CAAM,CACpE,CAEyC,CAC3C"}
@@ -1145,16 +1145,24 @@ const globTool = createZodFunctionTool("Glob", "Fast file pattern matching tool
1145
1145
  /**
1146
1146
  * GrepTool — recursive regex content search.
1147
1147
  *
1148
- * Supports two output modes:
1148
+ * Supports three output modes:
1149
1149
  * - files_with_matches (default): return only file paths that contain a match
1150
1150
  * - content: return matching lines with optional context lines
1151
+ * - count: return per-file match counts as "path:count" rows
1152
+ *
1153
+ * headLimit caps the number of result lines; excess is truncated with a marker.
1151
1154
  */
1152
1155
  const GrepSchema = zod.z.object({
1153
1156
  pattern: zod.z.string().describe("The regular expression pattern to search for in file contents"),
1154
1157
  path: zod.z.string().optional().describe("File or directory to search in. Defaults to the current working directory"),
1155
1158
  glob: zod.z.string().optional().describe("Glob pattern to filter files (e.g. \"*.ts\", \"*.{ts,tsx}\"). Only files matching this pattern will be searched"),
1156
1159
  contextLines: zod.z.number().optional().describe("Number of context lines to show before and after each match. Only applies when outputMode is \"content\". Default: 0"),
1157
- outputMode: zod.z.enum(["files_with_matches", "content"]).optional().describe("Output mode: \"files_with_matches\" shows only file paths (default), \"content\" shows matching lines with context")
1160
+ outputMode: zod.z.enum([
1161
+ "files_with_matches",
1162
+ "content",
1163
+ "count"
1164
+ ]).optional().describe("Output mode: \"files_with_matches\" shows only file paths (default), \"content\" shows matching lines with context, \"count\" shows per-file match counts"),
1165
+ headLimit: zod.z.number().int().positive().optional().describe("Maximum number of result lines (file paths, content lines, or count rows) to return. Excess results are truncated with a marker line")
1158
1166
  });
1159
1167
  /** Convert a simple glob to a RegExp for file name filtering. */
1160
1168
  function globToRegex(glob) {
@@ -1201,6 +1209,7 @@ function searchFile(content, filePath, regex, contextLines, outputMode) {
1201
1209
  for (let i = 0; i < lines.length; i++) if (regex.test(lines[i])) matchingIndices.push(i);
1202
1210
  if (matchingIndices.length === 0) return [];
1203
1211
  if (outputMode === "files_with_matches") return [filePath];
1212
+ if (outputMode === "count") return [`${filePath}:${matchingIndices.length}`];
1204
1213
  const includedIndices = /* @__PURE__ */ new Set();
1205
1214
  for (const idx of matchingIndices) for (let c = Math.max(0, idx - contextLines); c <= Math.min(lines.length - 1, idx + contextLines); c++) includedIndices.add(c);
1206
1215
  const outputLines = [];
@@ -1216,7 +1225,7 @@ function searchFile(content, filePath, regex, contextLines, outputMode) {
1216
1225
  return outputLines;
1217
1226
  }
1218
1227
  async function grepFileTool(args) {
1219
- const { pattern, path: searchPath, glob, contextLines = 0, outputMode = "files_with_matches" } = args;
1228
+ const { pattern, path: searchPath, glob, contextLines = 0, outputMode = "files_with_matches", headLimit } = args;
1220
1229
  const targetPath = searchPath ? (0, node_path.resolve)(searchPath) : process.cwd();
1221
1230
  let regex;
1222
1231
  try {
@@ -1262,16 +1271,21 @@ async function grepFileTool(args) {
1262
1271
  const fileMatches = searchFile(content, filePath, regex, contextLines, outputMode);
1263
1272
  allOutputLines.push(...fileMatches);
1264
1273
  }
1274
+ let outputLines = allOutputLines;
1275
+ if (headLimit !== void 0 && outputLines.length > headLimit) {
1276
+ const truncatedCount = outputLines.length - headLimit;
1277
+ outputLines = [...outputLines.slice(0, headLimit), `(+${truncatedCount} more results truncated by headLimit)`];
1278
+ }
1265
1279
  const result = {
1266
1280
  success: true,
1267
- output: allOutputLines.length > 0 ? allOutputLines.join("\n") : "(no matches)"
1281
+ output: outputLines.length > 0 ? outputLines.join("\n") : "(no matches)"
1268
1282
  };
1269
1283
  return JSON.stringify(result);
1270
1284
  }
1271
1285
  /**
1272
1286
  * GrepTool instance — register with Robota agent tools registry.
1273
1287
  */
1274
- const grepTool = createZodFunctionTool("Grep", "A powerful search tool built on regex matching.\n\nSupports full regex syntax (e.g., 'log.*Error', 'function\\\\s+\\\\w+'). Filter files with glob parameter (e.g., '*.js', '**/*.tsx').\n\nOutput modes: 'content' shows matching lines with context, 'files_with_matches' shows only file paths (default), 'count' shows match counts.\n\nUse this tool for ALL search tasks. NEVER invoke grep or rg as a Bash command.\n\nUse head_limit to control result size and save context space.", GrepSchema, async (params) => {
1288
+ const grepTool = createZodFunctionTool("Grep", "A powerful search tool built on regex matching.\n\nSupports full regex syntax (e.g., 'log.*Error', 'function\\\\s+\\\\w+'). Filter files with glob parameter (e.g., '*.js', '**/*.tsx').\n\nOutput modes: 'content' shows matching lines with context, 'files_with_matches' shows only file paths (default), 'count' shows per-file match counts.\n\nUse this tool for ALL search tasks. NEVER invoke grep or rg as a Bash command.\n\nUse headLimit to control result size and save context space.", GrepSchema, async (params) => {
1275
1289
  return grepFileTool(params);
1276
1290
  });
1277
1291
  //#endregion
@@ -412,9 +412,12 @@ declare const globTool: FunctionTool;
412
412
  /**
413
413
  * GrepTool — recursive regex content search.
414
414
  *
415
- * Supports two output modes:
415
+ * Supports three output modes:
416
416
  * - files_with_matches (default): return only file paths that contain a match
417
417
  * - content: return matching lines with optional context lines
418
+ * - count: return per-file match counts as "path:count" rows
419
+ *
420
+ * headLimit caps the number of result lines; excess is truncated with a marker.
418
421
  */
419
422
  /**
420
423
  * GrepTool instance — register with Robota agent tools registry.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/types/tool-result.ts","../../src/sandbox/types.ts","../../src/sandbox/e2b-sandbox-client.ts","../../src/sandbox/in-memory-sandbox-client.ts","../../src/sandbox/workspace-manifest.ts","../../src/registry/tool-registry.ts","../../src/implementations/function-tool/types.ts","../../src/implementations/function-tool.ts","../../src/implementations/function-tool/schema-converter.ts","../../src/builtins/bash-tool.ts","../../src/builtins/read-tool.ts","../../src/builtins/write-tool.ts","../../src/builtins/edit-tool.ts","../../src/builtins/glob-tool.ts","../../src/builtins/grep-tool.ts","../../src/builtins/web-fetch-tool.ts","../../src/builtins/web-search-tool.ts"],"mappings":";;;;;;UAGiB,WAAA;EACf,OAAA;EACA,MAAA;EACA,KAAA;EACA,QAAA;EAFA;EAIA,SAAA;AAAA;;;UCTe,kBAAA;EACf,SAAA;EACA,gBAAgB;AAAA;AAAA,UAGD,iBAAA;EACf,MAAA;EACA,MAAA;EACA,QAAA;AAAA;AAAA,UAGe,2BAAA;EACf,IAAA;EACA,OAAA;EACA,QAAA;AAAA;AAAA,UAGe,gCAAA;EACf,IAAI;AAAA;AAAA,UAGW,gCAAA;EACf,IAAA;EACA,GAAG;AAAA;AAAA,UAGY,qCAAA;EACf,IAAA;EACA,GAAG;AAAA;AAAA,UAGY,oCAAA;EACf,IAAA;EACA,GAAA;EACA,GAAA;EACA,OAAA;AAAA;AAAA,UAGe,8BAAA;EACf,IAAA;EACA,MAAA;EACA,MAAA;EACA,MAAA;AAAA;AAAA,UAGe,+BAAA;EACf,IAAA;EACA,MAAA;EACA,MAAA;AAAA;AAAA,UAGe,8BAAA;EACf,IAAA;EACA,MAAA;EACA,SAAA;EACA,MAAA;AAAA;AAAA,UAGe,qCAAA;EACf,IAAA;EACA,SAAA;EACA,OAAA;EACA,MAAA;AAAA;AAAA,KAGU,uBAAA,GACR,2BAAA,GACA,gCAAA,GACA,gCAAA,GACA,qCAAA,GACA,oCAAA,GACA,8BAAA,GACA,+BAAA,GACA,8BAAA,GACA,qCAAA;AAAA,UAEa,6BAAA;EACf,IAAA;EACA,KAAK;AAAA;AAAA,UAGU,kBAAA;EACf,OAAA,EAAS,MAAA,SAAe,uBAAA;EACxB,WAAA,GAAc,MAAA;EACd,WAAA,GAAc,6BAAA;AAAA;AAAA,UAGC,8BAAA;EACf,UAAA;EACA,QAAQ;AAAA;AAAA,KAGE,6BAAA;AAAA,UA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xC;;;;;;cauGa,QAAA,EAOZ,YAAA;;;;;;Ab9GD;;;;;;;cc+Na,QAAA,EAOZ,YAAA;;;cChGY,YAAA,EAKZ,YAAA;;;;;;Af3ID;;;cgB+Fa,aAAA,EAKZ,YAAA"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/types/tool-result.ts","../../src/sandbox/types.ts","../../src/sandbox/e2b-sandbox-client.ts","../../src/sandbox/in-memory-sandbox-client.ts","../../src/sandbox/workspace-manifest.ts","../../src/registry/tool-registry.ts","../../src/implementations/function-tool/types.ts","../../src/implementations/function-tool.ts","../../src/implementations/function-tool/schema-converter.ts","../../src/builtins/bash-tool.ts","../../src/builtins/read-tool.ts","../../src/builtins/write-tool.ts","../../src/builtins/edit-tool.ts","../../src/builtins/glob-tool.ts","../../src/builtins/grep-tool.ts","../../src/builtins/web-fetch-tool.ts","../../src/builtins/web-search-tool.ts"],"mappings":";;;;;;UAGiB,WAAA;EACf,OAAA;EACA,MAAA;EACA,KAAA;EACA,QAAA;EAFA;EAIA,SAAA;AAAA;;;UCTe,kBAAA;EACf,SAAA;EACA,gBAAgB;AAAA;AAAA,UAGD,iBAAA;EACf,MAAA;EACA,MAAA;EACA,QAAA;AAAA;AAAA,UAGe,2BAAA;EACf,IAAA;EACA,OAAA;EACA,QAAA;AAAA;AAAA,UAGe,gCAAA;EACf,IAAI;AAAA;AAAA,UAGW,gCAAA;EACf,IAAA;EACA,GAAG;AAAA;AAAA,UAGY,qCAAA;EACf,IAAA;EACA,GAAG;AAAA;AAAA,UAGY,oCAAA;EACf,IAAA;EACA,GAAA;EACA,GAAA;EACA,OAAA;AAAA;AAAA,UAGe,8BAAA;EACf,IAAA;EACA,MAAA;EACA,MAAA;EACA,MAAA;AAAA;AAAA,UAGe,+BAAA;EACf,IAAA;EACA,MAAA;EACA,MAAA;AAAA;AAAA,UAGe,8BAAA;EACf,IAAA;EACA,MAAA;EACA,SAAA;EACA,MAAA;AAAA;AAAA,UAGe,qCAAA;EAC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A2B,YAAY;ATtIpE;;;AAAA,cSqJE,QAAA,EAAQ,YAAmB;;;;;;iBCWxB,cAAA,CAAe,OAAA,GAAS,mBAAA,GAA2B,YAAY;;AVhKpE;;cU8KE,QAAA,EAAQ,YAAmB;;;;;;iBChIxB,eAAA,CAAgB,OAAA,GAAS,mBAAA,GAA2B,YAAY;;;;cAcnE,SAAA,EAAS,YAAoB;;;;;;iBCoD1B,cAAA,CAAe,OAAA,GAAS,mBAAA,GAA2B,YAAY;;AZhHpE;;cY8HE,QAAA,EAAQ,YAAmB;;;;;;AZpIxC;;;;;;cauGa,QAAA,EAOZ,YAAA;;;;;;Ab9GD;;;;;;;;;;ccwPa,QAAA,EAOZ,YAAA;;;cCzHY,YAAA,EAKZ,YAAA;;;;;;Af3ID;;;cgB+Fa,aAAA,EAKZ,YAAA"}
@@ -1120,16 +1120,24 @@ const globTool = createZodFunctionTool("Glob", "Fast file pattern matching tool
1120
1120
  /**
1121
1121
  * GrepTool — recursive regex content search.
1122
1122
  *
1123
- * Supports two output modes:
1123
+ * Supports three output modes:
1124
1124
  * - files_with_matches (default): return only file paths that contain a match
1125
1125
  * - content: return matching lines with optional context lines
1126
+ * - count: return per-file match counts as "path:count" rows
1127
+ *
1128
+ * headLimit caps the number of result lines; excess is truncated with a marker.
1126
1129
  */
1127
1130
  const GrepSchema = z.object({
1128
1131
  pattern: z.string().describe("The regular expression pattern to search for in file contents"),
1129
1132
  path: z.string().optional().describe("File or directory to search in. Defaults to the current working directory"),
1130
1133
  glob: z.string().optional().describe("Glob pattern to filter files (e.g. \"*.ts\", \"*.{ts,tsx}\"). Only files matching this pattern will be searched"),
1131
1134
  contextLines: z.number().optional().describe("Number of context lines to show before and after each match. Only applies when outputMode is \"content\". Default: 0"),
1132
- outputMode: z.enum(["files_with_matches", "content"]).optional().describe("Output mode: \"files_with_matches\" shows only file paths (default), \"content\" shows matching lines with context")
1135
+ outputMode: z.enum([
1136
+ "files_with_matches",
1137
+ "content",
1138
+ "count"
1139
+ ]).optional().describe("Output mode: \"files_with_matches\" shows only file paths (default), \"content\" shows matching lines with context, \"count\" shows per-file match counts"),
1140
+ headLimit: z.number().int().positive().optional().describe("Maximum number of result lines (file paths, content lines, or count rows) to return. Excess results are truncated with a marker line")
1133
1141
  });
1134
1142
  /** Convert a simple glob to a RegExp for file name filtering. */
1135
1143
  function globToRegex(glob) {
@@ -1176,6 +1184,7 @@ function searchFile(content, filePath, regex, contextLines, outputMode) {
1176
1184
  for (let i = 0; i < lines.length; i++) if (regex.test(lines[i])) matchingIndices.push(i);
1177
1185
  if (matchingIndices.length === 0) return [];
1178
1186
  if (outputMode === "files_with_matches") return [filePath];
1187
+ if (outputMode === "count") return [`${filePath}:${matchingIndices.length}`];
1179
1188
  const includedIndices = /* @__PURE__ */ new Set();
1180
1189
  for (const idx of matchingIndices) for (let c = Math.max(0, idx - contextLines); c <= Math.min(lines.length - 1, idx + contextLines); c++) includedIndices.add(c);
1181
1190
  const outputLines = [];
@@ -1191,7 +1200,7 @@ function searchFile(content, filePath, regex, contextLines, outputMode) {
1191
1200
  return outputLines;
1192
1201
  }
1193
1202
  async function grepFileTool(args) {
1194
- const { pattern, path: searchPath, glob, contextLines = 0, outputMode = "files_with_matches" } = args;
1203
+ const { pattern, path: searchPath, glob, contextLines = 0, outputMode = "files_with_matches", headLimit } = args;
1195
1204
  const targetPath = searchPath ? resolve(searchPath) : process.cwd();
1196
1205
  let regex;
1197
1206
  try {
@@ -1237,16 +1246,21 @@ async function grepFileTool(args) {
1237
1246
  const fileMatches = searchFile(content, filePath, regex, contextLines, outputMode);
1238
1247
  allOutputLines.push(...fileMatches);
1239
1248
  }
1249
+ let outputLines = allOutputLines;
1250
+ if (headLimit !== void 0 && outputLines.length > headLimit) {
1251
+ const truncatedCount = outputLines.length - headLimit;
1252
+ outputLines = [...outputLines.slice(0, headLimit), `(+${truncatedCount} more results truncated by headLimit)`];
1253
+ }
1240
1254
  const result = {
1241
1255
  success: true,
1242
- output: allOutputLines.length > 0 ? allOutputLines.join("\n") : "(no matches)"
1256
+ output: outputLines.length > 0 ? outputLines.join("\n") : "(no matches)"
1243
1257
  };
1244
1258
  return JSON.stringify(result);
1245
1259
  }
1246
1260
  /**
1247
1261
  * GrepTool instance — register with Robota agent tools registry.
1248
1262
  */
1249
- const grepTool = createZodFunctionTool("Grep", "A powerful search tool built on regex matching.\n\nSupports full regex syntax (e.g., 'log.*Error', 'function\\\\s+\\\\w+'). Filter files with glob parameter (e.g., '*.js', '**/*.tsx').\n\nOutput modes: 'content' shows matching lines with context, 'files_with_matches' shows only file paths (default), 'count' shows match counts.\n\nUse this tool for ALL search tasks. NEVER invoke grep or rg as a Bash command.\n\nUse head_limit to control result size and save context space.", GrepSchema, async (params) => {
1263
+ const grepTool = createZodFunctionTool("Grep", "A powerful search tool built on regex matching.\n\nSupports full regex syntax (e.g., 'log.*Error', 'function\\\\s+\\\\w+'). Filter files with glob parameter (e.g., '*.js', '**/*.tsx').\n\nOutput modes: 'content' shows matching lines with context, 'files_with_matches' shows only file paths (default), 'count' shows per-file match counts.\n\nUse this tool for ALL search tasks. NEVER invoke grep or rg as a Bash command.\n\nUse headLimit to control result size and save context space.", GrepSchema, async (params) => {
1250
1264
  return grepFileTool(params);
1251
1265
  });
1252
1266
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["DEFAULT_TIMEOUT_MS","DEFAULT_LIMIT","DEFAULT_TIMEOUT_MS"],"sources":["../../src/sandbox/e2b-sandbox-client.ts","../../src/sandbox/in-memory-sandbox-client.ts","../../src/sandbox/workspace-manifest.ts","../../src/registry/tool-registry.ts","../../src/implementations/function-tool/parameter-validator.ts","../../src/implementations/function-tool/schema-converter.ts","../../src/implementations/function-tool.ts","../../src/builtins/bash-tool.ts","../../src/builtins/path-guard.ts","../../src/builtins/read-tool.ts","../../src/builtins/atomic-file-write.ts","../../src/builtins/write-tool.ts","../../src/builtins/edit-tool.ts","../../src/builtins/glob-tool.ts","../../src/builtins/grep-tool.ts","../../src/builtins/web-fetch-tool.ts","../../src/builtins/web-search-tool.ts"],"sourcesContent":["import type { ISandboxClient, ISandboxRunOptions, ISandboxRunResult } from './types.js';\n\ninterface IE2BCommandStartOptions {\n timeoutMs?: number;\n cwd?: string;\n background?: false;\n}\n\ninterface IE2BCommandResult {\n stdout?: string;\n stderr?: string;\n exitCode?: number;\n exit_code?: number;\n}\n\ninterface IE2BCommands {\n run(command: string, options?: IE2BCommandStartOptions): Promise<IE2BCommandResult>;\n}\n\ninterface IE2BFiles {\n read(path: string): Promise<string | Uint8Array>;\n write(path: string, content: string): Promise<void>;\n}\n\ninterface IE2BSnapshot {\n snapshotId?: string;\n id?: string;\n}\n\nexport interface IE2BSandboxAdapter {\n sandboxId?: string;\n commands: IE2BCommands;\n files: IE2BFiles;\n pause?(): Promise<boolean | string | void>;\n connect?(): Promise<IE2BSandboxAdapter>;\n createSnapshot?(): Promise<IE2BSnapshot>;\n}\n\nexport interface IE2BSandboxClientOptions {\n sandbox: IE2BSandboxAdapter;\n connectSandbox?: (sandboxId: string) => Promise<IE2BSandboxAdapter>;\n createSandboxFromSnapshot?: (snapshotId: string) => Promise<IE2BSandboxAdapter>;\n}\n\nexport class E2BSandboxClient implements ISandboxClient {\n private sandbox: IE2BSandboxAdapter;\n private readonly connectSandbox?: (sandboxId: string) => Promise<IE2BSandboxAdapter>;\n private readonly createSandboxFromSnapshot?: (snapshotId: string) => Promise<IE2BSandboxAdapter>;\n\n constructor(options: IE2BSandboxClientOptions) {\n this.sandbox = options.sandbox;\n this.connectSandbox = options.connectSandbox;\n this.createSandboxFromSnapshot = options.createSandboxFromSnapshot;\n }\n\n async run(command: string, options?: ISandboxRunOptions): Promise<ISandboxRunResult> {\n const result = await this.sandbox.commands.run(command, {\n background: false,\n timeoutMs: options?.timeoutMs,\n cwd: options?.workingDirectory,\n });\n\n return {\n stdout: result.stdout ?? '',\n stderr: result.stderr ?? '',\n exitCode: result.exitCode ?? result.exit_code ?? 0,\n };\n }\n\n async readFile(path: string): Promise<string> {\n const content = await this.sandbox.files.read(path);\n return typeof content === 'string' ? content : Buffer.from(content).toString('utf8');\n }\n\n async writeFile(path: string, content: string): Promise<void> {\n await this.sandbox.files.write(path, content);\n }\n\n async snapshot(): Promise<string> {\n if (this.sandbox.createSnapshot) {\n const snapshot = await this.sandbox.createSnapshot();\n const snapshotId = snapshot.snapshotId ?? snapshot.id;\n if (!snapshotId) {\n throw new Error('E2B createSnapshot() did not return a snapshot id.');\n }\n return snapshotId;\n }\n const sandboxId = this.sandbox.sandboxId;\n if (!sandboxId) {\n throw new Error('E2B sandboxId is required to create a resumable sandbox snapshot.');\n }\n if (!this.sandbox.pause) {\n throw new Error('E2B sandbox adapter does not expose pause().');\n }\n await this.sandbox.pause();\n return sandboxId;\n }\n\n async restore(snapshotId: string): Promise<void> {\n if (this.createSandboxFromSnapshot) {\n this.sandbox = await this.createSandboxFromSnapshot(snapshotId);\n return;\n }\n if (this.connectSandbox) {\n this.sandbox = await this.connectSandbox(snapshotId);\n return;\n }\n if (this.sandbox.sandboxId === snapshotId && this.sandbox.connect) {\n this.sandbox = await this.sandbox.connect();\n return;\n }\n throw new Error(\n 'E2B sandbox restore requires connectSandbox(snapshotId) or sandbox.connect().',\n );\n }\n}\n","import type { ISandboxClient, ISandboxRunOptions, ISandboxRunResult } from './types.js';\n\nexport type TInMemorySandboxRunHandler = (\n command: string,\n options: ISandboxRunOptions | undefined,\n files: ReadonlyMap<string, string>,\n) => Promise<ISandboxRunResult> | ISandboxRunResult;\n\nexport interface IInMemorySandboxClientOptions {\n files?: Record<string, string>;\n runHandler?: TInMemorySandboxRunHandler;\n}\n\nexport class InMemorySandboxClient implements ISandboxClient {\n private readonly files = new Map<string, string>();\n private readonly snapshots = new Map<string, Map<string, string>>();\n private readonly runHandler?: TInMemorySandboxRunHandler;\n private snapshotSequence = 0;\n\n constructor(options: IInMemorySandboxClientOptions = {}) {\n for (const [path, content] of Object.entries(options.files ?? {})) {\n this.files.set(path, content);\n }\n this.runHandler = options.runHandler;\n }\n\n async run(command: string, options?: ISandboxRunOptions): Promise<ISandboxRunResult> {\n if (this.runHandler) {\n return this.runHandler(command, options, this.files);\n }\n return { stdout: '', stderr: '', exitCode: 0 };\n }\n\n async readFile(path: string): Promise<string> {\n const content = this.files.get(path);\n if (content === undefined) {\n throw new Error(`Sandbox file not found: ${path}`);\n }\n return content;\n }\n\n async writeFile(path: string, content: string): Promise<void> {\n this.files.set(path, content);\n }\n\n async snapshot(): Promise<string> {\n const snapshotId = `snapshot-${++this.snapshotSequence}`;\n this.snapshots.set(snapshotId, new Map(this.files));\n return snapshotId;\n }\n\n async restore(snapshotId: string): Promise<void> {\n const snapshot = this.snapshots.get(snapshotId);\n if (!snapshot) {\n throw new Error(`Sandbox snapshot not found: ${snapshotId}`);\n }\n this.files.clear();\n for (const [path, content] of snapshot.entries()) {\n this.files.set(path, content);\n }\n }\n\n getFile(path: string): string | undefined {\n return this.files.get(path);\n }\n}\n","import { readdir, readFile } from 'node:fs/promises';\nimport { isAbsolute, join, posix, resolve } from 'node:path';\n\nimport type {\n ISandboxClient,\n IWorkspaceManifest,\n IWorkspaceManifestAppliedEntry,\n IWorkspaceManifestApplyOptions,\n IWorkspaceManifestApplyResult,\n TWorkspaceManifestEntry,\n} from './types.js';\n\nconst DEFAULT_TARGET_ROOT = '/workspace';\nconst WINDOWS_ABSOLUTE_PATH_PATTERN = /^[A-Za-z]:[\\\\/]/;\nconst SHELL_QUOTE_PATTERN = /'/g;\n\nexport async function applyWorkspaceManifest(\n sandboxClient: ISandboxClient,\n manifest: IWorkspaceManifest,\n options: IWorkspaceManifestApplyOptions = {},\n): Promise<IWorkspaceManifestApplyResult> {\n if (sandboxClient.applyManifest) {\n return sandboxClient.applyManifest(manifest, options);\n }\n\n const targetRoot = normalizeSandboxRoot(options.targetRoot ?? DEFAULT_TARGET_ROOT);\n const appliedEntries: IWorkspaceManifestAppliedEntry[] = [];\n\n for (const [rawPath, entry] of Object.entries(manifest.entries)) {\n const path = validateWorkspaceManifestPath(rawPath);\n const targetPath = joinSandboxPath(targetRoot, path);\n appliedEntries.push(\n await applyManifestEntry(sandboxClient, path, targetPath, targetRoot, entry, options),\n );\n }\n\n return { entries: appliedEntries };\n}\n\nexport function validateWorkspaceManifestPath(path: string): string {\n if (path.length === 0) {\n throw new Error('workspace manifest path must not be empty');\n }\n if (path.includes('\\0')) {\n throw new Error('workspace manifest path must not contain NUL bytes');\n }\n if (path.startsWith('/') || path.startsWith('\\\\') || WINDOWS_ABSOLUTE_PATH_PATTERN.test(path)) {\n throw new Error('workspace manifest path must be workspace-relative');\n }\n\n const parts = path.replace(/\\\\/g, '/').split('/').filter(Boolean);\n if (parts.length === 0) {\n throw new Error('workspace manifest path must not resolve to the workspace root');\n }\n if (parts.some((part) => part === '..')) {\n throw new Error('workspace manifest path cannot contain traversal segments');\n }\n\n const normalizedParts = parts.filter((part) => part !== '.');\n if (normalizedParts.length === 0) {\n throw new Error('workspace manifest path must not resolve to the workspace root');\n }\n\n return normalizedParts.join('/');\n}\n\nasync function applyManifestEntry(\n sandboxClient: ISandboxClient,\n path: string,\n targetPath: string,\n targetRoot: string,\n entry: TWorkspaceManifestEntry,\n options: IWorkspaceManifestApplyOptions,\n): Promise<IWorkspaceManifestAppliedEntry> {\n switch (entry.type) {\n case 'file':\n await writeSandboxFile(sandboxClient, targetPath, targetRoot, entry.content);\n return createAppliedEntry(path, entry.type);\n case 'dir':\n await createSandboxDirectory(sandboxClient, targetPath);\n return createAppliedEntry(path, entry.type);\n case 'localFile':\n await copyLocalFile(sandboxClient, entry.src, targetPath, targetRoot, options);\n return createAppliedEntry(path, entry.type);\n case 'localDir':\n await copyLocalDirectory(sandboxClient, entry.src, targetPath, options);\n return createAppliedEntry(path, entry.type);\n case 'gitRepo':\n await cloneGitRepository(sandboxClient, entry, targetPath);\n return createAppliedEntry(path, entry.type);\n case 's3Mount':\n case 'gcsMount':\n case 'r2Mount':\n case 'azureBlobMount':\n return {\n path,\n type: entry.type,\n status: 'unsupported',\n message: `${entry.type} requires a provider-specific sandbox adapter.`,\n };\n default:\n return assertUnreachable(entry);\n }\n}\n\nfunction createAppliedEntry(\n path: string,\n type: TWorkspaceManifestEntry['type'],\n): IWorkspaceManifestAppliedEntry {\n return { path, type, status: 'applied' };\n}\n\nasync function copyLocalFile(\n sandboxClient: ISandboxClient,\n source: string,\n targetPath: string,\n targetRoot: string,\n options: IWorkspaceManifestApplyOptions,\n): Promise<void> {\n const hostSourcePath = resolveHostSourcePath(source, options.hostRoot);\n const content = await readFile(hostSourcePath, 'utf8');\n await writeSandboxFile(sandboxClient, targetPath, targetRoot, content);\n}\n\nasync function copyLocalDirectory(\n sandboxClient: ISandboxClient,\n source: string,\n targetPath: string,\n options: IWorkspaceManifestApplyOptions,\n): Promise<void> {\n const hostSourcePath = resolveHostSourcePath(source, options.hostRoot);\n await copyLocalDirectoryRecursive(sandboxClient, hostSourcePath, targetPath);\n}\n\nasync function copyLocalDirectoryRecursive(\n sandboxClient: ISandboxClient,\n sourcePath: string,\n targetPath: string,\n): Promise<void> {\n await createSandboxDirectory(sandboxClient, targetPath);\n const entries = await readdir(sourcePath, { withFileTypes: true });\n\n for (const entry of entries) {\n const childSourcePath = join(sourcePath, entry.name);\n const childTargetPath = joinSandboxPath(targetPath, entry.name);\n if (entry.isDirectory()) {\n await copyLocalDirectoryRecursive(sandboxClient, childSourcePath, childTargetPath);\n continue;\n }\n if (entry.isFile()) {\n const content = await readFile(childSourcePath, 'utf8');\n await sandboxClient.writeFile(childTargetPath, content);\n }\n }\n}\n\nasync function cloneGitRepository(\n sandboxClient: ISandboxClient,\n entry: Extract<TWorkspaceManifestEntry, { type: 'gitRepo' }>,\n targetPath: string,\n): Promise<void> {\n const shallowArgs = entry.shallow === false ? '' : ' --depth 1';\n const refArgs = entry.ref ? ` --branch ${quoteShellArg(entry.ref)}` : '';\n await runSandboxCommand(\n sandboxClient,\n `git clone${shallowArgs}${refArgs} ${quoteShellArg(entry.url)} ${quoteShellArg(targetPath)}`,\n );\n}\n\nasync function writeSandboxFile(\n sandboxClient: ISandboxClient,\n targetPath: string,\n targetRoot: string,\n content: string,\n): Promise<void> {\n const parentPath = posix.dirname(targetPath);\n if (parentPath !== targetRoot) {\n await createSandboxDirectory(sandboxClient, parentPath);\n }\n await sandboxClient.writeFile(targetPath, content);\n}\n\nasync function createSandboxDirectory(\n sandboxClient: ISandboxClient,\n targetPath: string,\n): Promise<void> {\n await runSandboxCommand(sandboxClient, `mkdir -p ${quoteShellArg(targetPath)}`);\n}\n\nasync function runSandboxCommand(sandboxClient: ISandboxClient, command: string): Promise<void> {\n const result = await sandboxClient.run(command);\n if (result.exitCode !== 0) {\n throw new Error(\n `workspace manifest command failed: ${command}\\n${result.stderr ?? result.stdout}`,\n );\n }\n}\n\nfunction resolveHostSourcePath(source: string, hostRoot: string | undefined): string {\n return isAbsolute(source) ? resolve(source) : resolve(hostRoot ?? process.cwd(), source);\n}\n\nfunction normalizeSandboxRoot(root: string): string {\n const normalized = root.replace(/\\\\/g, '/').replace(/\\/+$/, '');\n if (!normalized.startsWith('/')) {\n throw new Error('workspace manifest targetRoot must be an absolute sandbox path');\n }\n return normalized.length === 0 ? '/' : normalized;\n}\n\nfunction joinSandboxPath(root: string, path: string): string {\n const normalizedRoot = normalizeSandboxRoot(root);\n if (normalizedRoot === '/') {\n return `/${path}`;\n }\n return `${normalizedRoot}/${path}`;\n}\n\nfunction quoteShellArg(value: string): string {\n return `'${value.replace(SHELL_QUOTE_PATTERN, \"'\\\\''\")}'`;\n}\n\nfunction assertUnreachable(value: never): never {\n throw new Error(`unsupported workspace manifest entry: ${JSON.stringify(value)}`);\n}\n","import { ValidationError } from '@robota-sdk/agent-core';\nimport { logger } from '@robota-sdk/agent-core';\n\nimport type { ITool, IToolRegistry } from '@robota-sdk/agent-core';\nimport type { IToolSchema } from '@robota-sdk/agent-core';\n\n/**\n * Tool registry implementation\n * Manages tool registration, validation, and retrieval\n */\nexport class ToolRegistry implements IToolRegistry {\n private tools = new Map<string, ITool>();\n\n /**\n * Register a tool\n */\n register(tool: ITool): void {\n if (!tool.schema?.name) {\n throw new ValidationError('Tool must have a valid schema with name');\n }\n\n const toolName = tool.schema.name;\n\n // Validate tool schema\n this.validateToolSchema(tool.schema);\n\n // Check for duplicate registration\n if (this.tools.has(toolName)) {\n logger.warn(`Tool \"${toolName}\" is already registered, overriding`, {\n toolName,\n existingTool: this.tools.get(toolName)?.constructor.name,\n });\n }\n\n this.tools.set(toolName, tool);\n logger.debug(`Tool \"${toolName}\" registered successfully`, {\n toolName,\n toolType: tool.constructor.name,\n parameters: Object.keys(tool.schema.parameters?.properties || {}),\n });\n }\n\n /**\n * Unregister a tool\n */\n unregister(name: string): void {\n if (!this.tools.has(name)) {\n logger.warn(`Attempted to unregister non-existent tool \"${name}\"`);\n return;\n }\n\n this.tools.delete(name);\n logger.debug(`Tool \"${name}\" unregistered successfully`);\n }\n\n /**\n * Get tool by name\n */\n get(name: string): ITool | undefined {\n return this.tools.get(name);\n }\n\n /**\n * Get all registered tools\n */\n getAll(): ITool[] {\n return Array.from(this.tools.values());\n }\n\n /**\n * Get tool schemas\n */\n getSchemas(): IToolSchema[] {\n const tools = this.getAll();\n\n // 🔍 [TOOL-FLOW] ToolRegistry.getSchemas() - Extracting schemas from tools\n logger.debug('[TOOL-FLOW] ToolRegistry.getSchemas() - Tools before schema extraction', {\n count: tools.length,\n tools: tools.map((t) => ({\n name: t.schema?.name ?? 'unnamed',\n hasSchema: !!t.schema,\n schemaType: typeof t.schema,\n toolType: t.constructor?.name || 'unknown',\n })),\n });\n\n return this.getAll().map((tool) => tool.schema);\n }\n\n /**\n * Check if tool exists\n */\n has(name: string): boolean {\n return this.tools.has(name);\n }\n\n /**\n * Clear all tools\n */\n clear(): void {\n const toolCount = this.tools.size;\n this.tools.clear();\n logger.debug(`Cleared ${toolCount} tools from registry`);\n }\n\n /**\n * Get tool names\n */\n getToolNames(): string[] {\n return Array.from(this.tools.keys());\n }\n\n /**\n * Get tools by pattern\n */\n getToolsByPattern(pattern: string | RegExp): ITool[] {\n const regex = typeof pattern === 'string' ? new RegExp(pattern) : pattern;\n return this.getAll().filter((tool) => regex.test(tool.schema.name));\n }\n\n /**\n * Get tool count\n */\n size(): number {\n return this.tools.size;\n }\n\n /**\n * Validate tool schema\n */\n private validateToolSchema(schema: IToolSchema): void {\n if (!schema.name || typeof schema.name !== 'string') {\n throw new ValidationError('Tool schema must have a valid name');\n }\n\n if (!schema.description || typeof schema.description !== 'string') {\n throw new ValidationError('Tool schema must have a description');\n }\n\n if (\n !schema.parameters ||\n typeof schema.parameters !== 'object' ||\n schema.parameters === null ||\n Array.isArray(schema.parameters)\n ) {\n throw new ValidationError('Tool schema must have parameters object');\n }\n\n if (schema.parameters.type !== 'object') {\n throw new ValidationError('Tool parameters type must be \"object\"');\n }\n\n // Validate parameter properties\n if (schema.parameters.properties) {\n for (const propName of Object.keys(schema.parameters.properties)) {\n const propSchema = schema.parameters.properties[propName];\n if (!propSchema?.type) {\n throw new ValidationError(`Parameter \"${propName}\" must have a type`);\n }\n\n const validTypes = ['string', 'number', 'boolean', 'array', 'object'];\n if (!validTypes.includes(propSchema.type)) {\n throw new ValidationError(\n `Parameter \"${propName}\" has invalid type \"${propSchema.type}\"`,\n );\n }\n }\n }\n\n // Validate required fields exist in properties\n if (schema.parameters.required) {\n const properties = schema.parameters.properties || {};\n for (const requiredField of schema.parameters.required) {\n if (!properties[requiredField]) {\n throw new ValidationError(\n `Required parameter \"${requiredField}\" is not defined in properties`,\n );\n }\n }\n }\n }\n}\n","import type {\n IParameterSchema,\n TToolParameters,\n IParameterValidationResult,\n} from '@robota-sdk/agent-core';\nimport type { TUniversalValue } from '@robota-sdk/agent-core';\n\n/**\n * Validate individual parameter type against its schema.\n * Returns an error string if invalid, undefined if valid.\n */\nexport function validateParameterType(\n key: string,\n value: TUniversalValue,\n schema: IParameterSchema,\n): string | undefined {\n const expectedType = schema['type'];\n\n switch (expectedType) {\n case 'string':\n if (typeof value !== 'string') {\n return `Parameter \"${key}\" must be a string, got ${typeof value}`;\n }\n break;\n\n case 'number':\n if (typeof value !== 'number' || isNaN(value)) {\n return `Parameter \"${key}\" must be a number, got ${typeof value}`;\n }\n break;\n\n case 'boolean':\n if (typeof value !== 'boolean') {\n return `Parameter \"${key}\" must be a boolean, got ${typeof value}`;\n }\n break;\n\n case 'array':\n if (!Array.isArray(value)) {\n return `Parameter \"${key}\" must be an array, got ${typeof value}`;\n }\n // Check array items if specified\n if (schema.items) {\n for (let i = 0; i < value.length; i++) {\n const itemError = validateParameterType(`${key}[${i}]`, value[i], schema.items);\n if (itemError) {\n return itemError;\n }\n }\n }\n break;\n\n case 'object':\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n return `Parameter \"${key}\" must be an object, got ${typeof value}`;\n }\n break;\n }\n\n // Check enum constraints\n if (schema.enum && schema.enum.length > 0) {\n const enumValues = schema.enum;\n let isValidEnum = false;\n\n // Type-safe enum checking based on JSONSchemaEnum type\n for (const enumValue of enumValues) {\n if (value === enumValue) {\n isValidEnum = true;\n break;\n }\n }\n\n if (!isValidEnum) {\n return `Parameter \"${key}\" must be one of: ${enumValues.join(', ')}, got ${value}`;\n }\n }\n\n return undefined;\n}\n\n/**\n * Collect all validation errors for the given parameters against a schema.\n */\nexport function getValidationErrors(\n parameters: TToolParameters,\n schemaRequired: string[],\n schemaProperties: Record<string, IParameterSchema>,\n additionalProperties?: boolean | IParameterSchema,\n): string[] {\n const errors: string[] = [];\n\n // Check required parameters\n for (const field of schemaRequired) {\n if (!(field in parameters)) {\n errors.push(`Missing required parameter: ${field}`);\n }\n }\n\n // Check parameter types and constraints\n for (const [key, value] of Object.entries(parameters)) {\n const paramSchema = schemaProperties[key];\n if (!paramSchema) {\n if (additionalProperties === true) {\n continue;\n }\n if (additionalProperties && typeof additionalProperties === 'object') {\n const additionalTypeError = validateParameterType(key, value, additionalProperties);\n if (additionalTypeError) errors.push(additionalTypeError);\n continue;\n }\n errors.push(`Unknown parameter: ${key}`);\n continue;\n }\n\n const typeError = validateParameterType(key, value, paramSchema);\n if (typeError) {\n errors.push(typeError);\n }\n }\n\n return errors;\n}\n\n/**\n * Validate parameters and return a structured result.\n */\nexport function validateToolParameters(\n parameters: TToolParameters,\n schemaRequired: string[],\n schemaProperties: Record<string, IParameterSchema>,\n additionalProperties?: boolean | IParameterSchema,\n): IParameterValidationResult {\n const errors = getValidationErrors(\n parameters,\n schemaRequired,\n schemaProperties,\n additionalProperties,\n );\n return {\n isValid: errors.length === 0,\n errors,\n };\n}\n","/**\n * FunctionTool - Schema conversion utilities for Facade pattern\n *\n * REASON: Complex Zod to JSON schema conversion requires isolated utility functions\n * ALTERNATIVES_CONSIDERED:\n * 1. Keep conversion logic in main class (violates single responsibility)\n * 2. Use third-party library (adds external dependency)\n * 3. Manual conversion each time (code duplication)\n * 4. Runtime type checking only (loses compile-time safety)\n * 5. Remove Zod support (breaks backward compatibility)\n * TODO: Consider caching conversion results for performance\n */\n\nimport type { IZodSchema, ISchemaConversionOptions } from './types';\nimport type {\n IToolSchema,\n IParameterSchema,\n TJSONSchemaEnum,\n TUniversalValue,\n} from '@robota-sdk/agent-core';\n\n/**\n * Convert Zod schema to JSON Schema format with safe undefined handling\n */\nexport function zodToJsonSchema(\n schema: IZodSchema,\n options: ISchemaConversionOptions = {},\n): IToolSchema['parameters'] {\n const properties: Record<string, IParameterSchema> = {};\n const required: string[] = [];\n\n // Safe access to schema definition (no fallback).\n const schemaDef = schema._def;\n if (!schemaDef) {\n throw new Error('Zod schema is missing _def; cannot convert to JSON schema.');\n }\n\n // Handle object schemas with shape\n if (schemaDef.typeName === 'ZodObject' && schemaDef.shape) {\n // In Zod v3, shape is a property, not a function\n const shape = typeof schemaDef.shape === 'function' ? schemaDef.shape() : schemaDef.shape;\n\n for (const [key, typeObj] of Object.entries(shape)) {\n const property = convertZodTypeToProperty(typeObj);\n properties[key] = property;\n\n // Check if field is required (not optional/nullable)\n if (isRequiredField(typeObj)) {\n required.push(key);\n }\n }\n }\n\n return {\n type: 'object',\n properties,\n required,\n ...((options.allowAdditionalProperties || schemaDef.unknownKeys === 'passthrough') && {\n additionalProperties: true,\n }),\n };\n}\n\n/**\n * Convert individual Zod type to parameter schema with safe undefined handling\n */\nfunction convertZodTypeToProperty(typeObj: IZodSchema): IParameterSchema {\n // Safe access to type definition\n const typeDef = typeObj._def;\n if (!typeDef) {\n throw new Error('Zod type is missing _def; cannot convert to JSON schema.');\n }\n\n const base: Partial<IParameterSchema> = {};\n\n // Add description if available\n if (typeDef.description) {\n base.description = typeDef.description;\n }\n\n // Handle different Zod types\n switch (typeDef.typeName) {\n case 'ZodString':\n return { type: 'string', ...base };\n\n case 'ZodNumber':\n return { type: 'number', ...base };\n\n case 'ZodBoolean':\n return { type: 'boolean', ...base };\n\n case 'ZodArray': {\n if (!typeDef.type) {\n throw new Error('ZodArray is missing item type; cannot convert to JSON schema.');\n }\n const arrayItems = convertZodTypeToProperty(typeDef.type);\n return {\n type: 'array',\n items: arrayItems,\n ...base,\n };\n }\n\n case 'ZodObject':\n return { type: 'object', ...base };\n\n case 'ZodEnum': {\n const enumValues = typeDef.values;\n if (!enumValues || !Array.isArray(enumValues)) {\n throw new Error('ZodEnum is missing enum values; cannot convert to JSON schema.');\n }\n return {\n type: 'string',\n enum: enumValues as TJSONSchemaEnum,\n ...base,\n };\n }\n\n case 'ZodOptional':\n // Handle optional types by recursion\n if (typeDef.innerType) {\n const innerProperty = convertZodTypeToProperty(typeDef.innerType);\n return { ...innerProperty, ...base };\n }\n throw new Error('ZodOptional is missing innerType; cannot convert to JSON schema.');\n\n case 'ZodNullable':\n // Handle nullable types\n if (typeDef.innerType) {\n const innerProperty = convertZodTypeToProperty(typeDef.innerType);\n return { ...innerProperty, ...base };\n }\n throw new Error('ZodNullable is missing innerType; cannot convert to JSON schema.');\n\n case 'ZodDefault':\n // Handle default values by processing the inner type\n if (typeDef.innerType) {\n const innerProperty = convertZodTypeToProperty(typeDef.innerType);\n return { ...innerProperty, ...base };\n }\n throw new Error('ZodDefault is missing innerType; cannot convert to JSON schema.');\n\n case 'ZodRecord':\n // Handle Record<string, T> → JSON Schema additionalProperties\n if (typeDef.valueType) {\n const valueProperty = convertZodTypeToProperty(typeDef.valueType);\n return { type: 'object', additionalProperties: valueProperty, ...base };\n }\n return { type: 'object', additionalProperties: { type: 'string' }, ...base };\n\n default:\n throw new Error(`Unsupported Zod type: ${String(typeDef.typeName)}`);\n }\n}\n\n/**\n * Check if a Zod field is required (not optional or nullable)\n */\nfunction isRequiredField(typeObj: IZodSchema): boolean {\n const typeDef = typeObj._def;\n if (!typeDef) {\n throw new Error('Zod schema is missing _def; cannot determine required fields.');\n }\n\n // Field is optional if it's ZodOptional, ZodNullable, or ZodDefault\n return (\n typeDef.typeName !== 'ZodOptional' &&\n typeDef.typeName !== 'ZodNullable' &&\n typeDef.typeName !== 'ZodDefault'\n );\n}\n\n/**\n * Safely extract enum values from Zod schema\n */\nexport function extractEnumValues(schema: IZodSchema): TUniversalValue[] {\n const typeDef = schema._def;\n if (!typeDef) {\n throw new Error('Zod schema is missing _def; cannot extract enum values.');\n }\n if (!typeDef.values || !Array.isArray(typeDef.values)) {\n throw new Error('ZodEnum schema is missing enum values; cannot extract enum values.');\n }\n return typeDef.values;\n}\n\n/**\n * Check if schema has validation constraints\n */\nexport function hasValidationConstraints(schema: IZodSchema): boolean {\n const typeDef = schema._def;\n if (!typeDef) {\n throw new Error('Zod schema is missing _def; cannot determine validation constraints.');\n }\n\n return !!(typeDef.checks && typeDef.checks.length > 0);\n}\n\n/**\n * Safe schema type name extraction\n */\nexport function getSchemaTypeName(schema: IZodSchema): string {\n const typeDef = schema._def;\n if (!typeDef) {\n throw new Error('Zod schema is missing _def; cannot determine schema type name.');\n }\n if (!typeDef.typeName) {\n throw new Error('Zod schema has empty typeName; cannot determine schema type name.');\n }\n return typeDef.typeName;\n}\n","import { ToolExecutionError, ValidationError } from '@robota-sdk/agent-core';\n\nimport { getValidationErrors, validateToolParameters } from './function-tool/parameter-validator';\nimport { zodToJsonSchema } from './function-tool/schema-converter';\n\nimport type { IZodSchema } from './function-tool/types';\nimport type {\n IFunctionTool,\n IToolResult,\n IToolExecutionContext,\n IParameterValidationResult,\n TToolExecutor,\n TToolParameters,\n IEventService,\n} from '@robota-sdk/agent-core';\nimport type { IToolSchema } from '@robota-sdk/agent-core';\nimport type { TUniversalValue } from '@robota-sdk/agent-core';\n\n// Import from Facade pattern modules for type safety\n\n/**\n * Function tool implementation\n * Wraps a JavaScript function as a tool with schema validation\n *\n * Implements IFunctionTool without extending AbstractTool to avoid\n * circular runtime dependency (tools → agents → tools).\n */\nexport class FunctionTool implements IFunctionTool {\n readonly schema: IToolSchema;\n readonly fn: TToolExecutor;\n private eventService: IEventService | undefined;\n\n constructor(schema: IToolSchema, fn: TToolExecutor) {\n this.schema = schema;\n this.fn = fn;\n this.validateConstructorInputs();\n }\n\n /**\n * Get tool name\n */\n getName(): string {\n return this.schema.name;\n }\n\n /**\n * Set EventService for post-construction injection.\n * Accepts EventService as-is without transformation.\n * Caller is responsible for providing properly configured EventService.\n */\n setEventService(eventService: IEventService | undefined): void {\n this.eventService = eventService;\n }\n\n /**\n * Execute the function tool\n */\n async execute(\n parameters: TToolParameters,\n context?: IToolExecutionContext,\n ): Promise<IToolResult> {\n const toolName = this.schema.name;\n\n // Validate parameters before execution\n if (!this.validate(parameters)) {\n const errors = getValidationErrors(\n parameters,\n this.schema.parameters.required || [],\n this.schema.parameters.properties || {},\n this.schema.parameters.additionalProperties,\n );\n throw new ValidationError(`Invalid parameters for tool \"${toolName}\": ${errors.join(', ')}`);\n }\n\n // Execute the function\n const startTime = Date.now();\n let result: TUniversalValue;\n try {\n result = await this.fn(parameters, context);\n } catch (error) {\n if (error instanceof ToolExecutionError || error instanceof ValidationError) {\n throw error;\n }\n\n throw new ToolExecutionError(\n `Function tool execution failed: ${error instanceof Error ? error.message : String(error)}`,\n toolName,\n error instanceof Error ? error : new Error(String(error)),\n {\n parameterCount: Object.keys(parameters || {}).length,\n hasContext: !!context,\n },\n );\n }\n\n const executionTime = Date.now() - startTime;\n\n return {\n success: true,\n data: result,\n metadata: {\n executionTime,\n toolName,\n parameters,\n },\n };\n }\n\n /**\n * Validate parameters (simple boolean result)\n */\n validate(parameters: TToolParameters): boolean {\n return (\n getValidationErrors(\n parameters,\n this.schema.parameters.required || [],\n this.schema.parameters.properties || {},\n this.schema.parameters.additionalProperties,\n ).length === 0\n );\n }\n\n /**\n * Validate tool parameters with detailed result\n */\n validateParameters(parameters: TToolParameters): IParameterValidationResult {\n return validateToolParameters(\n parameters,\n this.schema.parameters.required || [],\n this.schema.parameters.properties || {},\n this.schema.parameters.additionalProperties,\n );\n }\n\n /**\n * Get tool description\n */\n getDescription(): string {\n return this.schema.description;\n }\n\n /**\n * Validate constructor inputs\n */\n private validateConstructorInputs(): void {\n if (!this.schema) {\n throw new ValidationError('Tool schema is required');\n }\n\n if (!this.fn || typeof this.fn !== 'function') {\n throw new ValidationError('Tool function is required and must be a function');\n }\n\n if (!this.schema.name) {\n throw new ValidationError('Tool schema must have a name');\n }\n }\n}\n\n/**\n * Helper function to create a function tool from a simple function\n */\nexport function createFunctionTool(\n name: string,\n description: string,\n parameters: IToolSchema['parameters'],\n fn: TToolExecutor,\n): FunctionTool {\n const schema: IToolSchema = {\n name,\n description,\n parameters,\n };\n\n return new FunctionTool(schema, fn);\n}\n\n/**\n * Helper function to create a function tool from Zod schema\n */\nexport function createZodFunctionTool(\n name: string,\n description: string,\n zodSchema: IZodSchema,\n fn: TToolExecutor,\n): FunctionTool {\n // Use comprehensive Zod to JSON schema conversion\n const parameters = zodToJsonSchema(zodSchema);\n\n const schema: IToolSchema = {\n name,\n description,\n parameters,\n };\n\n // Wrap the function with validation and ensure proper parameter handling\n const wrappedFn: TToolExecutor = async (\n parameters: TToolParameters,\n context?: IToolExecutionContext,\n ): Promise<TUniversalValue> => {\n // Use Zod for runtime validation\n const parseResult = zodSchema.safeParse(parameters);\n if (!parseResult.success) {\n throw new ValidationError(`Zod validation failed: ${parseResult.error}`);\n }\n\n const result = await fn((parseResult.data as TToolParameters) || parameters, context);\n // Ensure result is always a string for consistency with core package\n return typeof result === 'string' ? result : JSON.stringify(result);\n };\n\n return new FunctionTool(schema, wrappedFn);\n}\n\n// zodToJsonSchema function moved to Facade pattern schema-converter module\n","/**\n * BashTool — execute shell commands via child_process.spawn\n *\n * Returns TToolResult JSON string. Non-zero exit is returned as success:true\n * with exitCode set, matching Claude Code behaviour (the command ran, it just\n * exited non-zero — the LLM can decide what to do with that information).\n */\n\nimport { spawn } from 'node:child_process';\n\nimport { z } from 'zod';\n\nimport { createZodFunctionTool } from '../implementations/function-tool';\n\nimport type { FunctionTool } from '../implementations/function-tool';\nimport type { ISandboxToolOptions } from '../sandbox/types.js';\nimport type { TToolResult } from '../types/tool-result.js';\n\nconst DEFAULT_TIMEOUT_MS = 120_000; // 2 minutes\n\nconst BashSchema = z.object({\n command: z.string().describe('The bash command to execute'),\n timeout: z\n .number()\n .optional()\n .describe('Optional timeout in milliseconds (max 600000). Default is 120000 (2 minutes)'),\n workingDirectory: z\n .string()\n .optional()\n .describe('Working directory for the command. Defaults to the current working directory'),\n});\n\ntype TBashArgs = z.infer<typeof BashSchema>;\n\n/**\n * Run a shell command and return stdout + stderr.\n * Resolves with the TToolResult JSON string.\n */\nasync function runBash(args: TBashArgs, options: ISandboxToolOptions = {}): Promise<string> {\n const { command, timeout: rawTimeout = DEFAULT_TIMEOUT_MS, workingDirectory } = args;\n const timeout = Math.min(rawTimeout, 600_000);\n if (options.sandboxClient) {\n try {\n const sandboxResult = await options.sandboxClient.run(command, {\n timeoutMs: timeout,\n workingDirectory,\n });\n const output = sandboxResult.stderr\n ? `${sandboxResult.stdout}\\nstderr:\\n${sandboxResult.stderr}`\n : sandboxResult.stdout;\n const result: TToolResult = {\n success: true,\n output,\n exitCode: sandboxResult.exitCode,\n };\n return JSON.stringify(result);\n } catch (err) {\n const result: TToolResult = {\n success: false,\n output: '',\n error: err instanceof Error ? err.message : String(err),\n };\n return JSON.stringify(result);\n }\n }\n\n return new Promise<string>((resolve) => {\n const stdoutChunks: Buffer[] = [];\n const stderrChunks: Buffer[] = [];\n\n let timedOut = false;\n let settled = false;\n\n const child = spawn('sh', ['-c', command], {\n cwd: workingDirectory ?? process.cwd(),\n env: process.env,\n stdio: ['pipe', 'pipe', 'pipe'],\n });\n\n child.stdout.on('data', (chunk: Buffer) => {\n stdoutChunks.push(chunk);\n });\n\n child.stderr.on('data', (chunk: Buffer) => {\n stderrChunks.push(chunk);\n });\n\n const timer = setTimeout(() => {\n timedOut = true;\n child.kill('SIGTERM');\n // Resolve immediately on timeout — don't wait for close event.\n // The child process cleanup happens in the background.\n settle({\n success: false,\n output: Buffer.concat(stdoutChunks).toString('utf8'),\n error: `Command timed out after ${timeout}ms`,\n });\n }, timeout);\n\n function settle(result: TToolResult): void {\n if (settled) return;\n settled = true;\n clearTimeout(timer);\n resolve(JSON.stringify(result));\n }\n\n child.on('error', (err: Error) => {\n settle({\n success: false,\n output: '',\n error: err.message,\n });\n });\n\n child.on('close', (code: number | null) => {\n if (timedOut) {\n settle({\n success: false,\n output: Buffer.concat(stdoutChunks).toString('utf8'),\n error: `Command timed out after ${timeout}ms`,\n exitCode: code ?? undefined,\n });\n return;\n }\n\n const stdout = Buffer.concat(stdoutChunks).toString('utf8');\n const stderr = Buffer.concat(stderrChunks).toString('utf8');\n\n const exitCode = code ?? 0;\n const output = stderr ? `${stdout}\\nstderr:\\n${stderr}` : stdout;\n\n settle({\n success: true,\n output,\n exitCode,\n });\n });\n });\n}\n\n/**\n * Create a BashTool instance — register with Robota agent tools registry.\n */\nexport function createBashTool(options: ISandboxToolOptions = {}): FunctionTool {\n return createZodFunctionTool(\n 'Bash',\n 'Executes a given bash command and returns its output.\\n\\nThe working directory persists between commands, but shell state does not.\\n\\nIMPORTANT: Avoid using this tool to run `find`, `grep`, `cat`, `head`, `tail`, `sed`, `awk`, or `echo` commands. Instead, use the appropriate dedicated tool:\\n - File search: Use Glob (NOT find or ls)\\n - Content search: Use Grep (NOT grep or rg)\\n - Read files: Use Read (NOT cat/head/tail)\\n - Edit files: Use Edit (NOT sed/awk)\\n\\nFor simple commands, keep the description brief (5-10 words). For complex commands, include enough context to clarify what the command does.\\n\\nOutput is limited to 30,000 characters. Longer output will be middle-truncated.',\n BashSchema,\n async (params) => {\n // createZodFunctionTool passes validated params; cast is safe\n return runBash(params as TBashArgs, options);\n },\n );\n}\n\n/**\n * BashTool instance — register with Robota agent tools registry.\n */\nexport const bashTool = createBashTool();\n","import { resolve, sep } from 'node:path';\n\nimport type { TToolResult } from '../types/tool-result.js';\n\n/**\n * Returns a JSON-serialized TToolResult error when filePath is outside cwd.\n * Returns undefined when the path is within cwd or cwd is not set.\n */\nexport function checkPathWithinCwd(filePath: string, cwd: string | undefined): string | undefined {\n if (cwd === undefined) return undefined;\n\n const resolved = resolve(filePath);\n const cwdResolved = resolve(cwd);\n\n if (resolved !== cwdResolved && !resolved.startsWith(cwdResolved + sep)) {\n const result: TToolResult = {\n success: false,\n output: '',\n error: `Access denied: \"${filePath}\" is outside the working directory`,\n };\n return JSON.stringify(result);\n }\n\n return undefined;\n}\n","/**\n * ReadTool — read a file and return its contents with line numbers (cat -n style).\n *\n * Supports offset/limit for partial reads. Detects binary files and refuses to\n * return their raw bytes. Default limit is 2000 lines.\n */\n\nimport { readFile, stat } from 'node:fs/promises';\n\nimport { z } from 'zod';\n\nimport { checkPathWithinCwd } from './path-guard.js';\nimport { createZodFunctionTool } from '../implementations/function-tool';\n\nimport type { FunctionTool } from '../implementations/function-tool';\nimport type { ISandboxToolOptions } from '../sandbox/types.js';\nimport type { TToolResult } from '../types/tool-result.js';\n\nconst DEFAULT_LIMIT = 2000;\n\nconst ReadSchema = z.object({\n filePath: z.string().describe('The absolute path to the file to read'),\n offset: z\n .number()\n .optional()\n .describe(\n 'The line number to start reading from (1-based). Only provide if the file is too large to read at once',\n ),\n limit: z\n .number()\n .optional()\n .describe(\n `The number of lines to read (default: ${DEFAULT_LIMIT}). Only provide if the file is too large to read at once`,\n ),\n});\n\ntype TReadArgs = z.infer<typeof ReadSchema>;\n\n/**\n * Heuristic binary detection: scan the first 8 KB for null bytes.\n */\nfunction isBinary(buffer: Buffer): boolean {\n const checkLength = Math.min(buffer.length, 8192);\n for (let i = 0; i < checkLength; i++) {\n if (buffer[i] === 0) return true;\n }\n return false;\n}\n\n/**\n * Format lines with 1-based line numbers in cat -n style.\n * Pads line number to the width of the highest line number.\n */\nfunction formatWithLineNumbers(lines: string[], startLine: number): string {\n const lastLineNum = startLine + lines.length - 1;\n const width = String(lastLineNum).length;\n return lines\n .map((line, idx) => {\n const lineNum = String(startLine + idx).padStart(width, ' ');\n return `${lineNum}\\t${line}`;\n })\n .join('\\n');\n}\n\nfunction formatReadResult(\n filePath: string,\n content: string,\n startLine: number,\n limit: number,\n): string {\n const allLines = content.split('\\n');\n\n // Remove trailing empty line if file ends with newline (common in Unix files)\n if (allLines[allLines.length - 1] === '') {\n allLines.pop();\n }\n\n const zeroBasedStart = startLine - 1;\n const selectedLines = allLines.slice(zeroBasedStart, zeroBasedStart + limit);\n\n const output = formatWithLineNumbers(selectedLines, startLine);\n\n const totalLines = allLines.length;\n const returnedLines = selectedLines.length;\n const header =\n returnedLines < totalLines\n ? `[File: ${filePath} (lines ${startLine}-${startLine + returnedLines - 1} of ${totalLines})]\\n`\n : `[File: ${filePath} (${totalLines} lines)]\\n`;\n\n const result: TToolResult = {\n success: true,\n output: header + output,\n };\n return JSON.stringify(result);\n}\n\nasync function readFileTool(args: TReadArgs, options: ISandboxToolOptions = {}): Promise<string> {\n const { filePath, offset, limit = DEFAULT_LIMIT } = args;\n const startLine = offset !== undefined && offset > 0 ? offset : 1;\n\n if (options.sandboxClient) {\n try {\n const content = await options.sandboxClient.readFile(filePath);\n return formatReadResult(filePath, content, startLine, limit);\n } catch (err) {\n // allow-fallback: sandbox read failure → surface as TToolResult error\n const result: TToolResult = {\n success: false,\n output: '',\n error: err instanceof Error ? err.message : String(err),\n };\n return JSON.stringify(result);\n }\n }\n\n const pathError = checkPathWithinCwd(filePath, options.cwd);\n if (pathError !== undefined) return pathError;\n\n let fileStats: Awaited<ReturnType<typeof stat>> | undefined;\n try {\n fileStats = await stat(filePath);\n } catch (err) {\n // allow-fallback: stat failure means file not found → TToolResult error\n const result: TToolResult = {\n success: false,\n output: '',\n error: `File not found: ${filePath}`,\n };\n return JSON.stringify(result);\n }\n\n if (!fileStats.isFile()) {\n const result: TToolResult = {\n success: false,\n output: '',\n error: `Path is not a file: ${filePath}`,\n };\n return JSON.stringify(result);\n }\n\n let buffer: Buffer;\n try {\n buffer = await readFile(filePath);\n } catch (err) {\n // allow-fallback: read failure → TToolResult error (permissions, locks)\n const result: TToolResult = {\n success: false,\n output: '',\n error: err instanceof Error ? err.message : String(err),\n };\n return JSON.stringify(result);\n }\n\n if (isBinary(buffer)) {\n const result: TToolResult = {\n success: false,\n output: '',\n error: `Binary file not supported: ${filePath}`,\n };\n return JSON.stringify(result);\n }\n\n const content = buffer.toString('utf8');\n return formatReadResult(filePath, content, startLine, limit);\n}\n\n/**\n * Create a ReadTool instance — register with Robota agent tools registry.\n */\nexport function createReadTool(options: ISandboxToolOptions = {}): FunctionTool {\n return createZodFunctionTool(\n 'Read',\n 'Reads a file from the local filesystem.\\n\\nBy default, reads up to 2000 lines from the beginning of the file. You can optionally specify offset and limit for partial reads.\\n\\nResults are returned using cat -n format, with line numbers starting at 1.\\n\\nThe file_path parameter must be an absolute path, not a relative path.',\n ReadSchema,\n async (params) => {\n return readFileTool(params as TReadArgs, options);\n },\n );\n}\n\n/**\n * ReadTool instance — register with Robota agent tools registry.\n */\nexport const readTool = createReadTool();\n","import { randomBytes } from 'node:crypto';\nimport { chmod, mkdir, rename, rm, stat, writeFile } from 'node:fs/promises';\nimport { basename, dirname, join } from 'node:path';\n\nconst TEMP_RANDOM_BYTES = 6;\nconst PRESERVED_MODE_BITS = 0o7777;\nconst MISSING_FILE_ERROR_CODE = 'ENOENT';\n\nfunction createTempFilePath(filePath: string): string {\n const dir = dirname(filePath);\n const name = basename(filePath);\n const suffix = randomBytes(TEMP_RANDOM_BYTES).toString('hex');\n return join(dir, `.${name}.robota-tmp-${process.pid}-${Date.now()}-${suffix}`);\n}\n\nasync function readExistingMode(filePath: string): Promise<number | undefined> {\n try {\n const fileStats = await stat(filePath);\n return fileStats.mode & PRESERVED_MODE_BITS;\n } catch (error) {\n if (error instanceof Error && hasErrorCode(error, MISSING_FILE_ERROR_CODE)) return undefined;\n throw error;\n }\n}\n\nfunction hasErrorCode(error: Error, code: string): boolean {\n return 'code' in error && error.code === code;\n}\n\nexport async function atomicWriteUtf8File(filePath: string, content: string): Promise<void> {\n const dir = dirname(filePath);\n await mkdir(dir, { recursive: true });\n\n const existingMode = await readExistingMode(filePath);\n const tempFilePath = createTempFilePath(filePath);\n try {\n await writeFile(tempFilePath, content, 'utf8');\n if (existingMode !== undefined) {\n await chmod(tempFilePath, existingMode);\n }\n await rename(tempFilePath, filePath);\n } catch (error) {\n await rm(tempFilePath, { force: true }).catch(() => undefined);\n throw error;\n }\n}\n","/**\n * WriteTool — write content to a file, auto-creating parent directories.\n */\n\nimport { z } from 'zod';\n\nimport { atomicWriteUtf8File } from './atomic-file-write.js';\nimport { checkPathWithinCwd } from './path-guard.js';\nimport { createZodFunctionTool } from '../implementations/function-tool';\n\nimport type { FunctionTool } from '../implementations/function-tool';\nimport type { ISandboxToolOptions } from '../sandbox/types.js';\nimport type { TToolResult } from '../types/tool-result.js';\n\nconst WriteSchema = z.object({\n filePath: z.string().describe('The absolute path to the file to write'),\n content: z.string().describe('The content to write to the file'),\n});\n\ntype TWriteArgs = z.infer<typeof WriteSchema>;\n\nasync function writeFileTool(args: TWriteArgs, options: ISandboxToolOptions = {}): Promise<string> {\n const { filePath, content } = args;\n\n if (!options.sandboxClient) {\n const pathError = checkPathWithinCwd(filePath, options.cwd);\n if (pathError !== undefined) return pathError;\n }\n\n try {\n if (options.sandboxClient) {\n await options.sandboxClient.writeFile(filePath, content);\n } else {\n await atomicWriteUtf8File(filePath, content);\n }\n\n const result: TToolResult = {\n success: true,\n output: `Written ${Buffer.byteLength(content, 'utf8')} bytes to ${filePath}`,\n };\n return JSON.stringify(result);\n } catch (err) {\n // allow-fallback: write failure → TToolResult error (disk full, permissions)\n const result: TToolResult = {\n success: false,\n output: '',\n error: err instanceof Error ? err.message : String(err),\n };\n return JSON.stringify(result);\n }\n}\n\n/**\n * Create a WriteTool instance — register with Robota agent tools registry.\n */\nexport function createWriteTool(options: ISandboxToolOptions = {}): FunctionTool {\n return createZodFunctionTool(\n 'Write',\n 'Writes a file to the local filesystem. This will overwrite an existing file if one exists.\\n\\nALWAYS prefer the Edit tool for modifying existing files — it only sends the diff. Only use this tool to create new files or for complete rewrites.\\n\\nNEVER create documentation files (*.md) or README files unless explicitly requested by the user.',\n WriteSchema,\n async (params) => {\n return writeFileTool(params as TWriteArgs, options);\n },\n );\n}\n\n/**\n * WriteTool instance — register with Robota agent tools registry.\n */\nexport const writeTool = createWriteTool();\n","/**\n * EditTool — perform string-replace edits on a file.\n *\n * By default, requires the oldString to appear exactly once in the file\n * (ensuring surgical edits). Pass replaceAll:true to replace all occurrences.\n */\n\nimport { readFile } from 'node:fs/promises';\n\nimport { z } from 'zod';\n\nimport { atomicWriteUtf8File } from './atomic-file-write.js';\nimport { checkPathWithinCwd } from './path-guard.js';\nimport { createZodFunctionTool } from '../implementations/function-tool';\n\nimport type { FunctionTool } from '../implementations/function-tool';\nimport type { ISandboxToolOptions } from '../sandbox/types.js';\nimport type { TToolResult } from '../types/tool-result.js';\n\nconst EditSchema = z.object({\n filePath: z.string().describe('The absolute path to the file to modify'),\n oldString: z\n .string()\n .describe('The text to replace (must be an exact match of existing content)'),\n newString: z.string().describe('The text to replace it with (must be different from old_string)'),\n replaceAll: z\n .boolean()\n .optional()\n .describe(\n 'Replace all occurrences of old_string (default: false). Useful for renaming variables',\n ),\n});\n\ntype TEditArgs = z.infer<typeof EditSchema>;\n\nasync function editFileTool(args: TEditArgs, options: ISandboxToolOptions = {}): Promise<string> {\n const { filePath, oldString, newString, replaceAll = false } = args;\n\n if (!options.sandboxClient) {\n const pathError = checkPathWithinCwd(filePath, options.cwd);\n if (pathError !== undefined) return pathError;\n }\n\n let content: string;\n try {\n content = options.sandboxClient\n ? await options.sandboxClient.readFile(filePath)\n : await readFile(filePath, 'utf8');\n } catch (err) {\n // allow-fallback: read failure before edit → TToolResult error (file not found)\n const result: TToolResult = {\n success: false,\n output: '',\n error: `File not found: ${filePath}`,\n };\n return JSON.stringify(result);\n }\n\n if (!content.includes(oldString)) {\n const result: TToolResult = {\n success: false,\n output: '',\n error: `oldString not found in file: ${filePath}`,\n };\n return JSON.stringify(result);\n }\n\n // Uniqueness check when not in replaceAll mode\n if (!replaceAll) {\n const firstIdx = content.indexOf(oldString);\n const lastIdx = content.lastIndexOf(oldString);\n if (firstIdx !== lastIdx) {\n const occurrences = content.split(oldString).length - 1;\n const result: TToolResult = {\n success: false,\n output: '',\n error:\n `oldString is not unique in file (found ${occurrences} occurrences). ` +\n 'Provide more context to make it unique, or use replaceAll:true.',\n };\n return JSON.stringify(result);\n }\n }\n\n const updated = replaceAll\n ? content.split(oldString).join(newString)\n : content.slice(0, content.indexOf(oldString)) +\n newString +\n content.slice(content.indexOf(oldString) + oldString.length);\n\n try {\n if (options.sandboxClient) {\n await options.sandboxClient.writeFile(filePath, updated);\n } else {\n await atomicWriteUtf8File(filePath, updated);\n }\n } catch (err) {\n // allow-fallback: write failure after edit → TToolResult error\n const result: TToolResult = {\n success: false,\n output: '',\n error: err instanceof Error ? err.message : String(err),\n };\n return JSON.stringify(result);\n }\n\n const count = replaceAll ? content.split(oldString).length - 1 : 1;\n // Calculate start line number from the original content\n const matchIdx = content.indexOf(oldString);\n const startLine = matchIdx >= 0 ? content.substring(0, matchIdx).split('\\n').length : 1;\n const result: TToolResult = {\n success: true,\n output: `Replaced ${count} occurrence(s) in ${filePath}`,\n startLine,\n };\n return JSON.stringify(result);\n}\n\n/**\n * Create an EditTool instance — register with Robota agent tools registry.\n */\nexport function createEditTool(options: ISandboxToolOptions = {}): FunctionTool {\n return createZodFunctionTool(\n 'Edit',\n 'Performs exact string replacements in files.\\n\\nYou must use the Read tool at least once before editing. When editing text from Read output, preserve the exact indentation.\\n\\nThe edit will FAIL if old_string is not unique in the file. Either provide more surrounding context to make it unique, or use replace_all to change every instance.\\n\\nALWAYS prefer editing existing files over creating new ones.',\n EditSchema,\n async (params) => {\n return editFileTool(params as TEditArgs, options);\n },\n );\n}\n\n/**\n * EditTool instance — register with Robota agent tools registry.\n */\nexport const editTool = createEditTool();\n","/**\n * GlobTool — fast file pattern search using fast-glob.\n *\n * Excludes node_modules and .git by default.\n * Results are sorted by modification time (most recently modified first).\n */\n\nimport { stat } from 'node:fs/promises';\nimport { resolve } from 'node:path';\n\nimport fg from 'fast-glob';\nimport pLimit from 'p-limit';\nimport { z } from 'zod';\n\nimport { createZodFunctionTool } from '../implementations/function-tool';\n\nimport type { TToolResult } from '../types/tool-result.js';\n\nconst DEFAULT_MAX_RESULTS = 1000;\n\nconst GlobSchema = z.object({\n pattern: z\n .string()\n .describe('The glob pattern to match files against (e.g. \"**/*.ts\", \"src/**/*.tsx\")'),\n path: z\n .string()\n .optional()\n .describe(\n 'The directory to search in. Defaults to the current working directory. Must be a valid directory path if provided',\n ),\n limit: z\n .number()\n .optional()\n .describe(\n 'Maximum number of results to return (default: 1000). Use a smaller limit to save context space',\n ),\n});\n\ntype TGlobArgs = z.infer<typeof GlobSchema>;\n\ninterface IFileWithMtime {\n path: string;\n mtime: number;\n}\n\nasync function globFileTool(args: TGlobArgs): Promise<string> {\n const { pattern, path: basePath } = args;\n const cwd = basePath ? resolve(basePath) : process.cwd();\n\n let matches: string[];\n try {\n matches = await fg(pattern, {\n cwd,\n ignore: ['**/node_modules/**', '**/.git/**'],\n dot: true,\n absolute: false,\n });\n } catch (err) {\n const result: TToolResult = {\n success: false,\n output: '',\n error: err instanceof Error ? err.message : String(err),\n };\n return JSON.stringify(result);\n }\n\n // Sort by mtime (most recent first); cap concurrent stat calls to avoid I/O explosion\n const limit = pLimit(100);\n const withMtime: IFileWithMtime[] = await Promise.all(\n matches.map((p) =>\n limit(async () => {\n const absPath = resolve(cwd, p);\n try {\n const s = await stat(absPath);\n return { path: p, mtime: s.mtimeMs };\n } catch {\n // allow-fallback: stat failure on a matched path returns mtime=0 (sort-last), not a logic fallback\n return { path: p, mtime: 0 };\n }\n }),\n ),\n );\n\n withMtime.sort((a, b) => b.mtime - a.mtime);\n\n const maxResults = args.limit ?? DEFAULT_MAX_RESULTS;\n const totalMatches = withMtime.length;\n const truncated = totalMatches > maxResults;\n const limited = truncated ? withMtime.slice(0, maxResults) : withMtime;\n const sorted = limited.map((f) => f.path);\n\n let output = sorted.length > 0 ? sorted.join('\\n') : '(no matches)';\n if (truncated) {\n output += `\\n\\n[Showing ${maxResults} of ${totalMatches} matches. Use limit parameter to see more.]`;\n }\n\n const result: TToolResult = {\n success: true,\n output,\n };\n return JSON.stringify(result);\n}\n\n/**\n * GlobTool instance — register with Robota agent tools registry.\n */\nexport const globTool = createZodFunctionTool(\n 'Glob',\n \"Fast file pattern matching tool that works with any codebase size.\\n\\nSupports glob patterns like '**/*.js' or 'src/**/*.ts'. Returns matching file paths sorted by modification time.\\n\\nUse this tool when you need to find files by name patterns. When doing an open-ended search that may require multiple rounds, use the Agent tool instead.\\n\\nDefault limit is 1000 results. Use the limit parameter if you need fewer results to save context space.\",\n GlobSchema,\n async (params) => {\n return globFileTool(params as TGlobArgs);\n },\n);\n","/**\n * GrepTool — recursive regex content search.\n *\n * Supports two output modes:\n * - files_with_matches (default): return only file paths that contain a match\n * - content: return matching lines with optional context lines\n */\n\nimport { readFile, readdir, stat } from 'node:fs/promises';\nimport { join, resolve } from 'node:path';\n\nimport { z } from 'zod';\n\nimport { createZodFunctionTool } from '../implementations/function-tool';\n\nimport type { TToolResult } from '../types/tool-result.js';\n\nconst GrepSchema = z.object({\n pattern: z.string().describe('The regular expression pattern to search for in file contents'),\n path: z\n .string()\n .optional()\n .describe('File or directory to search in. Defaults to the current working directory'),\n glob: z\n .string()\n .optional()\n .describe(\n 'Glob pattern to filter files (e.g. \"*.ts\", \"*.{ts,tsx}\"). Only files matching this pattern will be searched',\n ),\n contextLines: z\n .number()\n .optional()\n .describe(\n 'Number of context lines to show before and after each match. Only applies when outputMode is \"content\". Default: 0',\n ),\n outputMode: z\n .enum(['files_with_matches', 'content'])\n .optional()\n .describe(\n 'Output mode: \"files_with_matches\" shows only file paths (default), \"content\" shows matching lines with context',\n ),\n});\n\ntype TGrepArgs = z.infer<typeof GrepSchema>;\n\n/** Convert a simple glob to a RegExp for file name filtering. */\nfunction globToRegex(glob: string): RegExp {\n const escaped = glob\n .replace(/[.+^${}()|[\\]\\\\]/g, '\\\\$&')\n .replace(/\\*\\*/g, '.+')\n .replace(/\\*/g, '[^/]*');\n return new RegExp(`^${escaped}$`);\n}\n\n/** Check if a file name matches an optional glob filter. */\nfunction matchesGlob(filename: string, glob: string | undefined): boolean {\n if (glob === undefined) return true;\n return globToRegex(glob).test(filename);\n}\n\n/** Gather all files under a directory recursively, excluding node_modules/.git. */\nasync function collectFiles(dirPath: string, glob: string | undefined): Promise<string[]> {\n const results: string[] = [];\n\n async function walk(current: string): Promise<void> {\n let entryNames: string[];\n try {\n entryNames = await readdir(current);\n } catch {\n return;\n }\n\n for (const name of entryNames) {\n if (name === 'node_modules' || name === '.git') continue;\n\n const fullPath = join(current, name);\n let fileStat: Awaited<ReturnType<typeof stat>>;\n try {\n fileStat = await stat(fullPath);\n } catch {\n continue;\n }\n\n if (fileStat.isDirectory()) {\n await walk(fullPath);\n } else if (fileStat.isFile()) {\n if (matchesGlob(name, glob)) {\n results.push(fullPath);\n }\n }\n }\n }\n\n await walk(dirPath);\n return results;\n}\n\n/** Search a single file for lines matching the regex. */\nfunction searchFile(\n content: string,\n filePath: string,\n regex: RegExp,\n contextLines: number,\n outputMode: 'files_with_matches' | 'content',\n): string[] {\n const lines = content.split('\\n');\n const matchingIndices: number[] = [];\n\n for (let i = 0; i < lines.length; i++) {\n if (regex.test(lines[i])) {\n matchingIndices.push(i);\n }\n }\n\n if (matchingIndices.length === 0) return [];\n\n if (outputMode === 'files_with_matches') {\n return [filePath];\n }\n\n // content mode — include context lines\n const includedIndices = new Set<number>();\n for (const idx of matchingIndices) {\n for (\n let c = Math.max(0, idx - contextLines);\n c <= Math.min(lines.length - 1, idx + contextLines);\n c++\n ) {\n includedIndices.add(c);\n }\n }\n\n const outputLines: string[] = [];\n const sortedIndices = Array.from(includedIndices).sort((a, b) => a - b);\n\n let prevIdx: number | undefined;\n for (const idx of sortedIndices) {\n if (prevIdx !== undefined && idx > prevIdx + 1) {\n outputLines.push('--');\n }\n const lineNum = idx + 1;\n const marker = matchingIndices.includes(idx) ? ':' : '-';\n outputLines.push(`${filePath}:${lineNum}${marker}${lines[idx]}`);\n prevIdx = idx;\n }\n\n return outputLines;\n}\n\nasync function grepFileTool(args: TGrepArgs): Promise<string> {\n const {\n pattern,\n path: searchPath,\n glob,\n contextLines = 0,\n outputMode = 'files_with_matches',\n } = args;\n const targetPath = searchPath ? resolve(searchPath) : process.cwd();\n\n let regex: RegExp;\n try {\n regex = new RegExp(pattern);\n } catch (err) {\n const result: TToolResult = {\n success: false,\n output: '',\n error: `Invalid regex pattern: ${pattern}`,\n };\n return JSON.stringify(result);\n }\n\n // Determine whether targetPath is a file or directory\n let targetStat: Awaited<ReturnType<typeof stat>>;\n try {\n targetStat = await stat(targetPath);\n } catch {\n const result: TToolResult = {\n success: false,\n output: '',\n error: `Path not found: ${targetPath}`,\n };\n return JSON.stringify(result);\n }\n\n let files: string[];\n if (targetStat.isFile()) {\n files = [targetPath];\n } else {\n files = await collectFiles(targetPath, glob);\n }\n\n const allOutputLines: string[] = [];\n\n for (const filePath of files) {\n let content: string;\n try {\n const buffer = await readFile(filePath);\n // Skip binary files\n const checkLen = Math.min(buffer.length, 8192);\n let hasBinary = false;\n for (let i = 0; i < checkLen; i++) {\n if (buffer[i] === 0) {\n hasBinary = true;\n break;\n }\n }\n if (hasBinary) continue;\n content = buffer.toString('utf8');\n } catch {\n continue;\n }\n\n const fileMatches = searchFile(content, filePath, regex, contextLines, outputMode);\n allOutputLines.push(...fileMatches);\n }\n\n const result: TToolResult = {\n success: true,\n output: allOutputLines.length > 0 ? allOutputLines.join('\\n') : '(no matches)',\n };\n return JSON.stringify(result);\n}\n\n/**\n * GrepTool instance — register with Robota agent tools registry.\n */\nexport const grepTool = createZodFunctionTool(\n 'Grep',\n \"A powerful search tool built on regex matching.\\n\\nSupports full regex syntax (e.g., 'log.*Error', 'function\\\\\\\\s+\\\\\\\\w+'). Filter files with glob parameter (e.g., '*.js', '**/*.tsx').\\n\\nOutput modes: 'content' shows matching lines with context, 'files_with_matches' shows only file paths (default), 'count' shows match counts.\\n\\nUse this tool for ALL search tasks. NEVER invoke grep or rg as a Bash command.\\n\\nUse head_limit to control result size and save context space.\",\n GrepSchema,\n async (params) => {\n return grepFileTool(params as TGrepArgs);\n },\n);\n","/**\n * WebFetchTool — fetch a URL and return its content as text.\n *\n * HTML is stripped to plain text for readability. Uses Node.js native fetch.\n * Output is capped at 30K chars (same as other tools).\n */\n\nimport { z } from 'zod';\n\nimport { createZodFunctionTool } from '../implementations/function-tool';\n\nimport type { TToolResult } from '../types/tool-result.js';\n\nconst DEFAULT_TIMEOUT_MS = 30_000;\nconst MAX_RESPONSE_BYTES = 5_000_000; // 5 MB max download\n\nconst WebFetchSchema = z.object({\n url: z.string().describe('The URL to fetch'),\n headers: z.record(z.string()).optional().describe('Optional HTTP headers as key-value pairs'),\n});\n\ntype TWebFetchArgs = z.infer<typeof WebFetchSchema>;\n\n/** Strip HTML tags and decode common entities to produce readable text. */\nfunction htmlToText(html: string): string {\n return html\n .replace(/<script[\\s\\S]*?<\\/script>/gi, '')\n .replace(/<style[\\s\\S]*?<\\/style>/gi, '')\n .replace(/<[^>]+>/g, ' ')\n .replace(/&amp;/g, '&')\n .replace(/&lt;/g, '<')\n .replace(/&gt;/g, '>')\n .replace(/&quot;/g, '\"')\n .replace(/&#39;/g, \"'\")\n .replace(/&nbsp;/g, ' ')\n .replace(/\\s+/g, ' ')\n .trim();\n}\n\nexport function classifyFetchError(err: unknown): string {\n if (!(err instanceof Error)) return String(err);\n\n if (err.name === 'AbortError') {\n return `Request timed out after ${DEFAULT_TIMEOUT_MS / 1000}s. The server did not respond in time.`;\n }\n\n const code = (err as NodeJS.ErrnoException).code;\n if (code === 'ENOTFOUND' || code === 'EAI_AGAIN') {\n return `Network error: DNS resolution failed for this host. The URL may be incorrect or the host does not exist. Do not retry with the same URL.`;\n }\n if (code === 'ECONNREFUSED') {\n return `Network error: Connection refused. The server is not accepting connections at this address. Do not retry with the same URL.`;\n }\n if (code === 'ECONNRESET') {\n return `Network error: Connection was reset by the server. The server may be temporarily unavailable.`;\n }\n if (code === 'ETIMEDOUT') {\n return `Network error: Connection timed out. The server is not reachable within the expected time.`;\n }\n if (code === 'CERT_HAS_EXPIRED' || code === 'UNABLE_TO_VERIFY_LEAF_SIGNATURE') {\n return `Network error: SSL certificate error (${code}). The server's certificate is invalid. Do not retry with the same URL.`;\n }\n\n return `Network error: ${err.message} Check that the URL is correct and the server is reachable.`;\n}\n\nasync function runWebFetch(args: TWebFetchArgs): Promise<string> {\n const { url, headers } = args;\n\n try {\n new URL(url);\n } catch {\n // allow-fallback: URL parse failure is a structured tool result, not a thrown error\n const result: TToolResult = {\n success: false,\n output: '',\n error: `Invalid URL: \"${url}\". Fix the URL format before retrying.`,\n };\n return JSON.stringify(result);\n }\n\n try {\n const controller = new AbortController();\n const timeout = setTimeout(() => controller.abort(), DEFAULT_TIMEOUT_MS);\n\n const response = await fetch(url, {\n headers: {\n 'User-Agent': 'Robota-CLI/3.0',\n ...(headers ?? {}),\n },\n signal: controller.signal,\n redirect: 'follow',\n });\n\n clearTimeout(timeout);\n\n if (!response.ok) {\n const retryHint =\n response.status >= 500\n ? ' The server is temporarily unavailable — retrying may help.'\n : ' Do not retry with the same URL.';\n const result: TToolResult = {\n success: false,\n output: '',\n error: `HTTP ${response.status} ${response.statusText}.${retryHint}`,\n };\n return JSON.stringify(result);\n }\n\n const contentType = response.headers.get('content-type') ?? '';\n const buffer = await response.arrayBuffer();\n\n if (buffer.byteLength > MAX_RESPONSE_BYTES) {\n const result: TToolResult = {\n success: false,\n output: '',\n error: `Response too large: ${buffer.byteLength} bytes (max ${MAX_RESPONSE_BYTES}). Consider fetching a more specific URL or a paginated endpoint.`,\n };\n return JSON.stringify(result);\n }\n\n let text = new TextDecoder().decode(buffer);\n\n // Strip HTML if content-type indicates HTML\n if (contentType.includes('html')) {\n text = htmlToText(text);\n }\n\n const result: TToolResult = { success: true, output: text };\n return JSON.stringify(result);\n } catch (err) {\n // allow-fallback: fetch errors are structured tool results returned to the LLM, not thrown\n const result: TToolResult = { success: false, output: '', error: classifyFetchError(err) };\n return JSON.stringify(result);\n }\n}\n\nexport const webFetchTool = createZodFunctionTool(\n 'WebFetch',\n 'Fetch a URL and return its content as text. HTML pages are converted to plain text.',\n WebFetchSchema,\n async (params) => runWebFetch(params as TWebFetchArgs),\n);\n","/**\n * WebSearchTool — search the web and return results.\n *\n * Uses Brave Search API when BRAVE_API_KEY is set.\n * Returns an error with setup instructions otherwise.\n */\n\nimport { z } from 'zod';\n\nimport { createZodFunctionTool } from '../implementations/function-tool';\n\nimport type { TToolResult } from '../types/tool-result.js';\n\nconst DEFAULT_LIMIT = 10;\nconst DEFAULT_TIMEOUT_MS = 15_000;\n\nconst WebSearchSchema = z.object({\n query: z.string().describe('The search query'),\n limit: z\n .number()\n .optional()\n .describe(`Maximum number of results to return (default: ${DEFAULT_LIMIT})`),\n});\n\ntype TWebSearchArgs = z.infer<typeof WebSearchSchema>;\n\ninterface IBraveResult {\n title: string;\n url: string;\n description: string;\n}\n\ninterface IBraveResponse {\n web?: {\n results?: IBraveResult[];\n };\n}\n\nasync function runWebSearch(args: TWebSearchArgs): Promise<string> {\n const { query, limit = DEFAULT_LIMIT } = args;\n const apiKey = process.env['BRAVE_API_KEY'];\n\n if (!apiKey) {\n const result: TToolResult = {\n success: false,\n output: '',\n error:\n 'Web search requires BRAVE_API_KEY environment variable. ' +\n 'Get a free API key at https://brave.com/search/api/ (2,000 queries/month free).',\n };\n return JSON.stringify(result);\n }\n\n try {\n const controller = new AbortController();\n const timeout = setTimeout(() => controller.abort(), DEFAULT_TIMEOUT_MS);\n\n const params = new URLSearchParams({\n q: query,\n count: String(Math.min(limit, 20)),\n });\n\n const response = await fetch(`https://api.search.brave.com/res/v1/web/search?${params}`, {\n headers: {\n Accept: 'application/json',\n 'Accept-Encoding': 'gzip',\n 'X-Subscription-Token': apiKey,\n },\n signal: controller.signal,\n });\n\n clearTimeout(timeout);\n\n if (!response.ok) {\n const result: TToolResult = {\n success: false,\n output: '',\n error: `Brave Search API error: HTTP ${response.status} ${response.statusText}`,\n };\n return JSON.stringify(result);\n }\n\n const data = (await response.json()) as IBraveResponse;\n const results = (data.web?.results ?? []).map((r) => ({\n title: r.title,\n url: r.url,\n snippet: r.description,\n }));\n\n const result: TToolResult = { success: true, output: JSON.stringify(results, null, 2) };\n return JSON.stringify(result);\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n const result: TToolResult = { success: false, output: '', error: message };\n return JSON.stringify(result);\n }\n}\n\nexport const webSearchTool = createZodFunctionTool(\n 'WebSearch',\n 'Search the web and return results with title, URL, and snippet.',\n WebSearchSchema,\n async (params) => runWebSearch(params as TWebSearchArgs),\n);\n"],"mappings":";;;;;;;;;AA4CA,IAAa,mBAAb,MAAwD;CACtD;CACA;CACA;CAEA,YAAY,SAAmC;EAC7C,KAAK,UAAU,QAAQ;EACvB,KAAK,iBAAiB,QAAQ;EAC9B,KAAK,4BAA4B,QAAQ;CAC3C;CAEA,MAAM,IAAI,SAAiB,SAA0D;EACnF,MAAM,SAAS,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e,QAAQ,IAAI,UAAU,OAAO,GAAG;EACU;EACzE,OAAO,KAAK,UAAU,MAAM;CAC9B;AACF;AAEA,MAAa,gBAAgB,sBAC3B,aACA,mEACA,iBACA,OAAO,WAAW,aAAa,MAAwB,CACzD"}
1
+ {"version":3,"file":"index.js","names":["DEFAULT_TIMEOUT_MS","DEFAULT_LIMIT","DEFAULT_TIMEOUT_MS"],"sources":["../../src/sandbox/e2b-sandbox-client.ts","../../src/sandbox/in-memory-sandbox-client.ts","../../src/sandbox/workspace-manifest.ts","../../src/registry/tool-registry.ts","../../src/implementations/function-tool/parameter-validator.ts","../../src/implementations/function-tool/schema-converter.ts","../../src/implementations/function-tool.ts","../../src/builtins/bash-tool.ts","../../src/builtins/path-guard.ts","../../src/builtins/read-tool.ts","../../src/builtins/atomic-file-write.ts","../../src/builtins/write-tool.ts","../../src/builtins/edit-tool.ts","../../src/builtins/glob-tool.ts","../../src/builtins/grep-tool.ts","../../src/builtins/web-fetch-tool.ts","../../src/builtins/web-search-tool.ts"],"sourcesContent":["import type { ISandboxClient, ISandboxRunOptions, ISandboxRunResult } from './types.js';\n\ninterface IE2BCommandStartOptions {\n timeoutMs?: number;\n cwd?: string;\n background?: false;\n}\n\ninterface IE2BCommandResult {\n stdout?: string;\n stderr?: string;\n exitCode?: number;\n exit_code?: number;\n}\n\ninterface IE2BCommands {\n run(command: string, options?: IE2BCommandStartOptions): Promise<IE2BCommandResult>;\n}\n\ninterface IE2BFiles {\n read(path: string): Promise<string | Uint8Array>;\n write(path: string, content: string): Promise<void>;\n}\n\ninterface IE2BSnapshot {\n snapshotId?: string;\n id?: string;\n}\n\nexport interface IE2BSandboxAdapter {\n sandboxId?: string;\n commands: IE2BCommands;\n files: IE2BFiles;\n pause?(): Promise<boolean | string | void>;\n connect?(): Promise<IE2BSandboxAdapter>;\n createSnapshot?(): Promise<IE2BSnapshot>;\n}\n\nexport interface IE2BSandboxClientOptions {\n sandbox: IE2BSandboxAdapter;\n connectSandbox?: (sandboxId: string) => Promise<IE2BSandboxAdapter>;\n createSandboxFromSnapshot?: (snapshotId: string) => Promise<IE2BSandboxAdapter>;\n}\n\nexport class E2BSandboxClient implements ISandboxClient {\n private sandbox: IE2BSandboxAdapter;\n private readonly connectSandbox?: (sandboxId: string) => Promise<IE2BSandboxAdapter>;\n private readonly createSandboxFromSnapshot?: (snapshotId: string) => Promise<IE2BSandboxAdapter>;\n\n constructor(options: IE2BSandboxClientOptions) {\n this.sandbox = options.sandbox;\n this.connectSandbox = options.connectSandbox;\n this.createSandboxFromSnapshot = options.createSandboxFromSnapshot;\n }\n\n async run(command: string, options?: ISandboxRunOptions): Promise<ISandboxRunResult> {\n const result = await this.sandbox.commands.run(command, {\n background: false,\n timeoutMs: options?.timeoutMs,\n cwd: options?.workingDirectory,\n });\n\n return {\n stdout: result.stdout ?? '',\n stderr: result.stderr ?? '',\n exitCode: result.exitCode ?? result.exit_code ?? 0,\n };\n }\n\n async readFile(path: string): Promise<string> {\n const content = await this.sandbox.files.read(path);\n return typeof content === 'string' ? content : Buffer.from(content).toString('utf8');\n }\n\n async writeFile(path: string, content: string): Promise<void> {\n await this.sandbox.files.write(path, content);\n }\n\n async snapshot(): Promise<string> {\n if (this.sandbox.createSnapshot) {\n const snapshot = await this.sandbox.createSnapshot();\n const snapshotId = snapshot.snapshotId ?? snapshot.id;\n if (!snapshotId) {\n throw new Error('E2B createSnapshot() did not return a snapshot id.');\n }\n return snapshotId;\n }\n const sandboxId = this.sandbox.sandboxId;\n if (!sandboxId) {\n throw new Error('E2B sandboxId is required to create a resumable sandbox snapshot.');\n }\n if (!this.sandbox.pause) {\n throw new Error('E2B sandbox adapter does not expose pause().');\n }\n await this.sandbox.pause();\n return sandboxId;\n }\n\n async restore(snapshotId: string): Promise<void> {\n if (this.createSandboxFromSnapshot) {\n this.sandbox = await this.createSandboxFromSnapshot(snapshotId);\n return;\n }\n if (this.connectSandbox) {\n this.sandbox = await this.connectSandbox(snapshotId);\n return;\n }\n if (this.sandbox.sandboxId === snapshotId && this.sandbox.connect) {\n this.sandbox = await this.sandbox.connect();\n return;\n }\n throw new Error(\n 'E2B sandbox restore requires connectSandbox(snapshotId) or sandbox.connect().',\n );\n }\n}\n","import type { ISandboxClient, ISandboxRunOptions, ISandboxRunResult } from './types.js';\n\nexport type TInMemorySandboxRunHandler = (\n command: string,\n options: ISandboxRunOptions | undefined,\n files: ReadonlyMap<string, string>,\n) => Promise<ISandboxRunResult> | ISandboxRunResult;\n\nexport interface IInMemorySandboxClientOptions {\n files?: Record<string, string>;\n runHandler?: TInMemorySandboxRunHandler;\n}\n\nexport class InMemorySandboxClient implements ISandboxClient {\n private readonly files = new Map<string, string>();\n private readonly snapshots = new Map<string, Map<string, string>>();\n private readonly runHandler?: TInMemorySandboxRunHandler;\n private snapshotSequence = 0;\n\n constructor(options: IInMemorySandboxClientOptions = {}) {\n for (const [path, content] of Object.entries(options.files ?? {})) {\n this.files.set(path, content);\n }\n this.runHandler = options.runHandler;\n }\n\n async run(command: string, options?: ISandboxRunOptions): Promise<ISandboxRunResult> {\n if (this.runHandler) {\n return this.runHandler(command, options, this.files);\n }\n return { stdout: '', stderr: '', exitCode: 0 };\n }\n\n async readFile(path: string): Promise<string> {\n const content = this.files.get(path);\n if (content === undefined) {\n throw new Error(`Sandbox file not found: ${path}`);\n }\n return content;\n }\n\n async writeFile(path: string, content: string): Promise<void> {\n this.files.set(path, content);\n }\n\n async snapshot(): Promise<string> {\n const snapshotId = `snapshot-${++this.snapshotSequence}`;\n this.snapshots.set(snapshotId, new Map(this.files));\n return snapshotId;\n }\n\n async restore(snapshotId: string): Promise<void> {\n const snapshot = this.snapshots.get(snapshotId);\n if (!snapshot) {\n throw new Error(`Sandbox snapshot not found: ${snapshotId}`);\n }\n this.files.clear();\n for (const [path, content] of snapshot.entries()) {\n this.files.set(path, content);\n }\n }\n\n getFile(path: string): string | undefined {\n return this.files.get(path);\n }\n}\n","import { readdir, readFile } from 'node:fs/promises';\nimport { isAbsolute, join, posix, resolve } from 'node:path';\n\nimport type {\n ISandboxClient,\n IWorkspaceManifest,\n IWorkspaceManifestAppliedEntry,\n IWorkspaceManifestApplyOptions,\n IWorkspaceManifestApplyResult,\n TWorkspaceManifestEntry,\n} from './types.js';\n\nconst DEFAULT_TARGET_ROOT = '/workspace';\nconst WINDOWS_ABSOLUTE_PATH_PATTERN = /^[A-Za-z]:[\\\\/]/;\nconst SHELL_QUOTE_PATTERN = /'/g;\n\nexport async function applyWorkspaceManifest(\n sandboxClient: ISandboxClient,\n manifest: IWorkspaceManifest,\n options: IWorkspaceManifestApplyOptions = {},\n): Promise<IWorkspaceManifestApplyResult> {\n if (sandboxClient.applyManifest) {\n return sandboxClient.applyManifest(manifest, options);\n }\n\n const targetRoot = normalizeSandboxRoot(options.targetRoot ?? DEFAULT_TARGET_ROOT);\n const appliedEntries: IWorkspaceManifestAppliedEntry[] = [];\n\n for (const [rawPath, entry] of Object.entries(manifest.entries)) {\n const path = validateWorkspaceManifestPath(rawPath);\n const targetPath = joinSandboxPath(targetRoot, path);\n appliedEntries.push(\n await applyManifestEntry(sandboxClient, path, targetPath, targetRoot, entry, options),\n );\n }\n\n return { entries: appliedEntries };\n}\n\nexport function validateWorkspaceManifestPath(path: string): string {\n if (path.length === 0) {\n throw new Error('workspace manifest path must not be empty');\n }\n if (path.includes('\\0')) {\n throw new Error('workspace manifest path must not contain NUL bytes');\n }\n if (path.startsWith('/') || path.startsWith('\\\\') || WINDOWS_ABSOLUTE_PATH_PATTERN.test(path)) {\n throw new Error('workspace manifest path must be workspace-relative');\n }\n\n const parts = path.replace(/\\\\/g, '/').split('/').filter(Boolean);\n if (parts.length === 0) {\n throw new Error('workspace manifest path must not resolve to the workspace root');\n }\n if (parts.some((part) => part === '..')) {\n throw new Error('workspace manifest path cannot contain traversal segments');\n }\n\n const normalizedParts = parts.filter((part) => part !== '.');\n if (normalizedParts.length === 0) {\n throw new Error('workspace manifest path must not resolve to the workspace root');\n }\n\n return normalizedParts.join('/');\n}\n\nasync function applyManifestEntry(\n sandboxClient: ISandboxClient,\n path: string,\n targetPath: string,\n targetRoot: string,\n entry: TWorkspaceManifestEntry,\n options: IWorkspaceManifestApplyOptions,\n): Promise<IWorkspaceManifestAppliedEntry> {\n switch (entry.type) {\n case 'file':\n await writeSandboxFile(sandboxClient, targetPath, targetRoot, entry.content);\n return createAppliedEntry(path, entry.type);\n case 'dir':\n await createSandboxDirectory(sandboxClient, targetPath);\n return createAppliedEntry(path, entry.type);\n case 'localFile':\n await copyLocalFile(sandboxClient, entry.src, targetPath, targetRoot, options);\n return createAppliedEntry(path, entry.type);\n case 'localDir':\n await copyLocalDirectory(sandboxClient, entry.src, targetPath, options);\n return createAppliedEntry(path, entry.type);\n case 'gitRepo':\n await cloneGitRepository(sandboxClient, entry, targetPath);\n return createAppliedEntry(path, entry.type);\n case 's3Mount':\n case 'gcsMount':\n case 'r2Mount':\n case 'azureBlobMount':\n return {\n path,\n type: entry.type,\n status: 'unsupported',\n message: `${entry.type} requires a provider-specific sandbox adapter.`,\n };\n default:\n return assertUnreachable(entry);\n }\n}\n\nfunction createAppliedEntry(\n path: string,\n type: TWorkspaceManifestEntry['type'],\n): IWorkspaceManifestAppliedEntry {\n return { path, type, status: 'applied' };\n}\n\nasync function copyLocalFile(\n sandboxClient: ISandboxClient,\n source: string,\n targetPath: string,\n targetRoot: string,\n options: IWorkspaceManifestApplyOptions,\n): Promise<void> {\n const hostSourcePath = resolveHostSourcePath(source, options.hostRoot);\n const content = await readFile(hostSourcePath, 'utf8');\n await writeSandboxFile(sandboxClient, targetPath, targetRoot, content);\n}\n\nasync function copyLocalDirectory(\n sandboxClient: ISandboxClient,\n source: string,\n targetPath: string,\n options: IWorkspaceManifestApplyOptions,\n): Promise<void> {\n const hostSourcePath = resolveHostSourcePath(source, options.hostRoot);\n await copyLocalDirectoryRecursive(sandboxClient, hostSourcePath, targetPath);\n}\n\nasync function copyLocalDirectoryRecursive(\n sandboxClient: ISandboxClient,\n sourcePath: string,\n targetPath: string,\n): Promise<void> {\n await createSandboxDirectory(sandboxClient, targetPath);\n const entries = await readdir(sourcePath, { withFileTypes: true });\n\n for (const entry of entries) {\n const childSourcePath = join(sourcePath, entry.name);\n const childTargetPath = joinSandboxPath(targetPath, entry.name);\n if (entry.isDirectory()) {\n await copyLocalDirectoryRecursive(sandboxClient, childSourcePath, childTargetPath);\n continue;\n }\n if (entry.isFile()) {\n const content = await readFile(childSourcePath, 'utf8');\n await sandboxClient.writeFile(childTargetPath, content);\n }\n }\n}\n\nasync function cloneGitRepository(\n sandboxClient: ISandboxClient,\n entry: Extract<TWorkspaceManifestEntry, { type: 'gitRepo' }>,\n targetPath: string,\n): Promise<void> {\n const shallowArgs = entry.shallow === false ? '' : ' --depth 1';\n const refArgs = entry.ref ? ` --branch ${quoteShellArg(entry.ref)}` : '';\n await runSandboxCommand(\n sandboxClient,\n `git clone${shallowArgs}${refArgs} ${quoteShellArg(entry.url)} ${quoteShellArg(targetPath)}`,\n );\n}\n\nasync function writeSandboxFile(\n sandboxClient: ISandboxClient,\n targetPath: string,\n targetRoot: string,\n content: string,\n): Promise<void> {\n const parentPath = posix.dirname(targetPath);\n if (parentPath !== targetRoot) {\n await createSandboxDirectory(sandboxClient, parentPath);\n }\n await sandboxClient.writeFile(targetPath, content);\n}\n\nasync function createSandboxDirectory(\n sandboxClient: ISandboxClient,\n targetPath: string,\n): Promise<void> {\n await runSandboxCommand(sandboxClient, `mkdir -p ${quoteShellArg(targetPath)}`);\n}\n\nasync function runSandboxCommand(sandboxClient: ISandboxClient, command: string): Promise<void> {\n const result = await sandboxClient.run(command);\n if (result.exitCode !== 0) {\n throw new Error(\n `workspace manifest command failed: ${command}\\n${result.stderr ?? result.stdout}`,\n );\n }\n}\n\nfunction resolveHostSourcePath(source: string, hostRoot: string | undefined): string {\n return isAbsolute(source) ? resolve(source) : resolve(hostRoot ?? process.cwd(), source);\n}\n\nfunction normalizeSandboxRoot(root: string): string {\n const normalized = root.replace(/\\\\/g, '/').replace(/\\/+$/, '');\n if (!normalized.startsWith('/')) {\n throw new Error('workspace manifest targetRoot must be an absolute sandbox path');\n }\n return normalized.length === 0 ? '/' : normalized;\n}\n\nfunction joinSandboxPath(root: string, path: string): string {\n const normalizedRoot = normalizeSandboxRoot(root);\n if (normalizedRoot === '/') {\n return `/${path}`;\n }\n return `${normalizedRoot}/${path}`;\n}\n\nfunction quoteShellArg(value: string): string {\n return `'${value.replace(SHELL_QUOTE_PATTERN, \"'\\\\''\")}'`;\n}\n\nfunction assertUnreachable(value: never): never {\n throw new Error(`unsupported workspace manifest entry: ${JSON.stringify(value)}`);\n}\n","import { ValidationError } from '@robota-sdk/agent-core';\nimport { logger } from '@robota-sdk/agent-core';\n\nimport type { ITool, IToolRegistry } from '@robota-sdk/agent-core';\nimport type { IToolSchema } from '@robota-sdk/agent-core';\n\n/**\n * Tool registry implementation\n * Manages tool registration, validation, and retrieval\n */\nexport class ToolRegistry implements IToolRegistry {\n private tools = new Map<string, ITool>();\n\n /**\n * Register a tool\n */\n register(tool: ITool): void {\n if (!tool.schema?.name) {\n throw new ValidationError('Tool must have a valid schema with name');\n }\n\n const toolName = tool.schema.name;\n\n // Validate tool schema\n this.validateToolSchema(tool.schema);\n\n // Check for duplicate registration\n if (this.tools.has(toolName)) {\n logger.warn(`Tool \"${toolName}\" is already registered, overriding`, {\n toolName,\n existingTool: this.tools.get(toolName)?.constructor.name,\n });\n }\n\n this.tools.set(toolName, tool);\n logger.debug(`Tool \"${toolName}\" registered successfully`, {\n toolName,\n toolType: tool.constructor.name,\n parameters: Object.keys(tool.schema.parameters?.properties || {}),\n });\n }\n\n /**\n * Unregister a tool\n */\n unregister(name: string): void {\n if (!this.tools.has(name)) {\n logger.warn(`Attempted to unregister non-existent tool \"${name}\"`);\n return;\n }\n\n this.tools.delete(name);\n logger.debug(`Tool \"${name}\" unregistered successfully`);\n }\n\n /**\n * Get tool by name\n */\n get(name: string): ITool | undefined {\n return this.tools.get(name);\n }\n\n /**\n * Get all registered tools\n */\n getAll(): ITool[] {\n return Array.from(this.tools.values());\n }\n\n /**\n * Get tool schemas\n */\n getSchemas(): IToolSchema[] {\n const tools = this.getAll();\n\n // 🔍 [TOOL-FLOW] ToolRegistry.getSchemas() - Extracting schemas from tools\n logger.debug('[TOOL-FLOW] ToolRegistry.getSchemas() - Tools before schema extraction', {\n count: tools.length,\n tools: tools.map((t) => ({\n name: t.schema?.name ?? 'unnamed',\n hasSchema: !!t.schema,\n schemaType: typeof t.schema,\n toolType: t.constructor?.name || 'unknown',\n })),\n });\n\n return this.getAll().map((tool) => tool.schema);\n }\n\n /**\n * Check if tool exists\n */\n has(name: string): boolean {\n return this.tools.has(name);\n }\n\n /**\n * Clear all tools\n */\n clear(): void {\n const toolCount = this.tools.size;\n this.tools.clear();\n logger.debug(`Cleared ${toolCount} tools from registry`);\n }\n\n /**\n * Get tool names\n */\n getToolNames(): string[] {\n return Array.from(this.tools.keys());\n }\n\n /**\n * Get tools by pattern\n */\n getToolsByPattern(pattern: string | RegExp): ITool[] {\n const regex = typeof pattern === 'string' ? new RegExp(pattern) : pattern;\n return this.getAll().filter((tool) => regex.test(tool.schema.name));\n }\n\n /**\n * Get tool count\n */\n size(): number {\n return this.tools.size;\n }\n\n /**\n * Validate tool schema\n */\n private validateToolSchema(schema: IToolSchema): void {\n if (!schema.name || typeof schema.name !== 'string') {\n throw new ValidationError('Tool schema must have a valid name');\n }\n\n if (!schema.description || typeof schema.description !== 'string') {\n throw new ValidationError('Tool schema must have a description');\n }\n\n if (\n !schema.parameters ||\n typeof schema.parameters !== 'object' ||\n schema.parameters === null ||\n Array.isArray(schema.parameters)\n ) {\n throw new ValidationError('Tool schema must have parameters object');\n }\n\n if (schema.parameters.type !== 'object') {\n throw new ValidationError('Tool parameters type must be \"object\"');\n }\n\n // Validate parameter properties\n if (schema.parameters.properties) {\n for (const propName of Object.keys(schema.parameters.properties)) {\n const propSchema = schema.parameters.properties[propName];\n if (!propSchema?.type) {\n throw new ValidationError(`Parameter \"${propName}\" must have a type`);\n }\n\n const validTypes = ['string', 'number', 'boolean', 'array', 'object'];\n if (!validTypes.includes(propSchema.type)) {\n throw new ValidationError(\n `Parameter \"${propName}\" has invalid type \"${propSchema.type}\"`,\n );\n }\n }\n }\n\n // Validate required fields exist in properties\n if (schema.parameters.required) {\n const properties = schema.parameters.properties || {};\n for (const requiredField of schema.parameters.required) {\n if (!properties[requiredField]) {\n throw new ValidationError(\n `Required parameter \"${requiredField}\" is not defined in properties`,\n );\n }\n }\n }\n }\n}\n","import type {\n IParameterSchema,\n TToolParameters,\n IParameterValidationResult,\n} from '@robota-sdk/agent-core';\nimport type { TUniversalValue } from '@robota-sdk/agent-core';\n\n/**\n * Validate individual parameter type against its schema.\n * Returns an error string if invalid, undefined if valid.\n */\nexport function validateParameterType(\n key: string,\n value: TUniversalValue,\n schema: IParameterSchema,\n): string | undefined {\n const expectedType = schema['type'];\n\n switch (expectedType) {\n case 'string':\n if (typeof value !== 'string') {\n return `Parameter \"${key}\" must be a string, got ${typeof value}`;\n }\n break;\n\n case 'number':\n if (typeof value !== 'number' || isNaN(value)) {\n return `Parameter \"${key}\" must be a number, got ${typeof value}`;\n }\n break;\n\n case 'boolean':\n if (typeof value !== 'boolean') {\n return `Parameter \"${key}\" must be a boolean, got ${typeof value}`;\n }\n break;\n\n case 'array':\n if (!Array.isArray(value)) {\n return `Parameter \"${key}\" must be an array, got ${typeof value}`;\n }\n // Check array items if specified\n if (schema.items) {\n for (let i = 0; i < value.length; i++) {\n const itemError = validateParameterType(`${key}[${i}]`, value[i], schema.items);\n if (itemError) {\n return itemError;\n }\n }\n }\n break;\n\n case 'object':\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n return `Parameter \"${key}\" must be an object, got ${typeof value}`;\n }\n break;\n }\n\n // Check enum constraints\n if (schema.enum && schema.enum.length > 0) {\n const enumValues = schema.enum;\n let isValidEnum = false;\n\n // Type-safe enum checking based on JSONSchemaEnum type\n for (const enumValue of enumValues) {\n if (value === enumValue) {\n isValidEnum = true;\n break;\n }\n }\n\n if (!isValidEnum) {\n return `Parameter \"${key}\" must be one of: ${enumValues.join(', ')}, got ${value}`;\n }\n }\n\n return undefined;\n}\n\n/**\n * Collect all validation errors for the given parameters against a schema.\n */\nexport function getValidationErrors(\n parameters: TToolParameters,\n schemaRequired: string[],\n schemaProperties: Record<string, IParameterSchema>,\n additionalProperties?: boolean | IParameterSchema,\n): string[] {\n const errors: string[] = [];\n\n // Check required parameters\n for (const field of schemaRequired) {\n if (!(field in parameters)) {\n errors.push(`Missing required parameter: ${field}`);\n }\n }\n\n // Check parameter types and constraints\n for (const [key, value] of Object.entries(parameters)) {\n const paramSchema = schemaProperties[key];\n if (!paramSchema) {\n if (additionalProperties === true) {\n continue;\n }\n if (additionalProperties && typeof additionalProperties === 'object') {\n const additionalTypeError = validateParameterType(key, value, additionalProperties);\n if (additionalTypeError) errors.push(additionalTypeError);\n continue;\n }\n errors.push(`Unknown parameter: ${key}`);\n continue;\n }\n\n const typeError = validateParameterType(key, value, paramSchema);\n if (typeError) {\n errors.push(typeError);\n }\n }\n\n return errors;\n}\n\n/**\n * Validate parameters and return a structured result.\n */\nexport function validateToolParameters(\n parameters: TToolParameters,\n schemaRequired: string[],\n schemaProperties: Record<string, IParameterSchema>,\n additionalProperties?: boolean | IParameterSchema,\n): IParameterValidationResult {\n const errors = getValidationErrors(\n parameters,\n schemaRequired,\n schemaProperties,\n additionalProperties,\n );\n return {\n isValid: errors.length === 0,\n errors,\n };\n}\n","/**\n * FunctionTool - Schema conversion utilities for Facade pattern\n *\n * REASON: Complex Zod to JSON schema conversion requires isolated utility functions\n * ALTERNATIVES_CONSIDERED:\n * 1. Keep conversion logic in main class (violates single responsibility)\n * 2. Use third-party library (adds external dependency)\n * 3. Manual conversion each time (code duplication)\n * 4. Runtime type checking only (loses compile-time safety)\n * 5. Remove Zod support (breaks backward compatibility)\n * TODO: Consider caching conversion results for performance\n */\n\nimport type { IZodSchema, ISchemaConversionOptions } from './types';\nimport type {\n IToolSchema,\n IParameterSchema,\n TJSONSchemaEnum,\n TUniversalValue,\n} from '@robota-sdk/agent-core';\n\n/**\n * Convert Zod schema to JSON Schema format with safe undefined handling\n */\nexport function zodToJsonSchema(\n schema: IZodSchema,\n options: ISchemaConversionOptions = {},\n): IToolSchema['parameters'] {\n const properties: Record<string, IParameterSchema> = {};\n const required: string[] = [];\n\n // Safe access to schema definition (no fallback).\n const schemaDef = schema._def;\n if (!schemaDef) {\n throw new Error('Zod schema is missing _def; cannot convert to JSON schema.');\n }\n\n // Handle object schemas with shape\n if (schemaDef.typeName === 'ZodObject' && schemaDef.shape) {\n // In Zod v3, shape is a property, not a function\n const shape = typeof schemaDef.shape === 'function' ? schemaDef.shape() : schemaDef.shape;\n\n for (const [key, typeObj] of Object.entries(shape)) {\n const property = convertZodTypeToProperty(typeObj);\n properties[key] = property;\n\n // Check if field is required (not optional/nullable)\n if (isRequiredField(typeObj)) {\n required.push(key);\n }\n }\n }\n\n return {\n type: 'object',\n properties,\n required,\n ...((options.allowAdditionalProperties || schemaDef.unknownKeys === 'passthrough') && {\n additionalProperties: true,\n }),\n };\n}\n\n/**\n * Convert individual Zod type to parameter schema with safe undefined handling\n */\nfunction convertZodTypeToProperty(typeObj: IZodSchema): IParameterSchema {\n // Safe access to type definition\n const typeDef = typeObj._def;\n if (!typeDef) {\n throw new Error('Zod type is missing _def; cannot convert to JSON schema.');\n }\n\n const base: Partial<IParameterSchema> = {};\n\n // Add description if available\n if (typeDef.description) {\n base.description = typeDef.description;\n }\n\n // Handle different Zod types\n switch (typeDef.typeName) {\n case 'ZodString':\n return { type: 'string', ...base };\n\n case 'ZodNumber':\n return { type: 'number', ...base };\n\n case 'ZodBoolean':\n return { type: 'boolean', ...base };\n\n case 'ZodArray': {\n if (!typeDef.type) {\n throw new Error('ZodArray is missing item type; cannot convert to JSON schema.');\n }\n const arrayItems = convertZodTypeToProperty(typeDef.type);\n return {\n type: 'array',\n items: arrayItems,\n ...base,\n };\n }\n\n case 'ZodObject':\n return { type: 'object', ...base };\n\n case 'ZodEnum': {\n const enumValues = typeDef.values;\n if (!enumValues || !Array.isArray(enumValues)) {\n throw new Error('ZodEnum is missing enum values; cannot convert to JSON schema.');\n }\n return {\n type: 'string',\n enum: enumValues as TJSONSchemaEnum,\n ...base,\n };\n }\n\n case 'ZodOptional':\n // Handle optional types by recursion\n if (typeDef.innerType) {\n const innerProperty = convertZodTypeToProperty(typeDef.innerType);\n return { ...innerProperty, ...base };\n }\n throw new Error('ZodOptional is missing innerType; cannot convert to JSON schema.');\n\n case 'ZodNullable':\n // Handle nullable types\n if (typeDef.innerType) {\n const innerProperty = convertZodTypeToProperty(typeDef.innerType);\n return { ...innerProperty, ...base };\n }\n throw new Error('ZodNullable is missing innerType; cannot convert to JSON schema.');\n\n case 'ZodDefault':\n // Handle default values by processing the inner type\n if (typeDef.innerType) {\n const innerProperty = convertZodTypeToProperty(typeDef.innerType);\n return { ...innerProperty, ...base };\n }\n throw new Error('ZodDefault is missing innerType; cannot convert to JSON schema.');\n\n case 'ZodRecord':\n // Handle Record<string, T> → JSON Schema additionalProperties\n if (typeDef.valueType) {\n const valueProperty = convertZodTypeToProperty(typeDef.valueType);\n return { type: 'object', additionalProperties: valueProperty, ...base };\n }\n return { type: 'object', additionalProperties: { type: 'string' }, ...base };\n\n default:\n throw new Error(`Unsupported Zod type: ${String(typeDef.typeName)}`);\n }\n}\n\n/**\n * Check if a Zod field is required (not optional or nullable)\n */\nfunction isRequiredField(typeObj: IZodSchema): boolean {\n const typeDef = typeObj._def;\n if (!typeDef) {\n throw new Error('Zod schema is missing _def; cannot determine required fields.');\n }\n\n // Field is optional if it's ZodOptional, ZodNullable, or ZodDefault\n return (\n typeDef.typeName !== 'ZodOptional' &&\n typeDef.typeName !== 'ZodNullable' &&\n typeDef.typeName !== 'ZodDefault'\n );\n}\n\n/**\n * Safely extract enum values from Zod schema\n */\nexport function extractEnumValues(schema: IZodSchema): TUniversalValue[] {\n const typeDef = schema._def;\n if (!typeDef) {\n throw new Error('Zod schema is missing _def; cannot extract enum values.');\n }\n if (!typeDef.values || !Array.isArray(typeDef.values)) {\n throw new Error('ZodEnum schema is missing enum values; cannot extract enum values.');\n }\n return typeDef.values;\n}\n\n/**\n * Check if schema has validation constraints\n */\nexport function hasValidationConstraints(schema: IZodSchema): boolean {\n const typeDef = schema._def;\n if (!typeDef) {\n throw new Error('Zod schema is missing _def; cannot determine validation constraints.');\n }\n\n return !!(typeDef.checks && typeDef.checks.length > 0);\n}\n\n/**\n * Safe schema type name extraction\n */\nexport function getSchemaTypeName(schema: IZodSchema): string {\n const typeDef = schema._def;\n if (!typeDef) {\n throw new Error('Zod schema is missing _def; cannot determine schema type name.');\n }\n if (!typeDef.typeName) {\n throw new Error('Zod schema has empty typeName; cannot determine schema type name.');\n }\n return typeDef.typeName;\n}\n","import { ToolExecutionError, ValidationError } from '@robota-sdk/agent-core';\n\nimport { getValidationErrors, validateToolParameters } from './function-tool/parameter-validator';\nimport { zodToJsonSchema } from './function-tool/schema-converter';\n\nimport type { IZodSchema } from './function-tool/types';\nimport type {\n IFunctionTool,\n IToolResult,\n IToolExecutionContext,\n IParameterValidationResult,\n TToolExecutor,\n TToolParameters,\n IEventService,\n} from '@robota-sdk/agent-core';\nimport type { IToolSchema } from '@robota-sdk/agent-core';\nimport type { TUniversalValue } from '@robota-sdk/agent-core';\n\n// Import from Facade pattern modules for type safety\n\n/**\n * Function tool implementation\n * Wraps a JavaScript function as a tool with schema validation\n *\n * Implements IFunctionTool without extending AbstractTool to avoid\n * circular runtime dependency (tools → agents → tools).\n */\nexport class FunctionTool implements IFunctionTool {\n readonly schema: IToolSchema;\n readonly fn: TToolExecutor;\n private eventService: IEventService | undefined;\n\n constructor(schema: IToolSchema, fn: TToolExecutor) {\n this.schema = schema;\n this.fn = fn;\n this.validateConstructorInputs();\n }\n\n /**\n * Get tool name\n */\n getName(): string {\n return this.schema.name;\n }\n\n /**\n * Set EventService for post-construction injection.\n * Accepts EventService as-is without transformation.\n * Caller is responsible for providing properly configured EventService.\n */\n setEventService(eventService: IEventService | undefined): void {\n this.eventService = eventService;\n }\n\n /**\n * Execute the function tool\n */\n async execute(\n parameters: TToolParameters,\n context?: IToolExecutionContext,\n ): Promise<IToolResult> {\n const toolName = this.schema.name;\n\n // Validate parameters before execution\n if (!this.validate(parameters)) {\n const errors = getValidationErrors(\n parameters,\n this.schema.parameters.required || [],\n this.schema.parameters.properties || {},\n this.schema.parameters.additionalProperties,\n );\n throw new ValidationError(`Invalid parameters for tool \"${toolName}\": ${errors.join(', ')}`);\n }\n\n // Execute the function\n const startTime = Date.now();\n let result: TUniversalValue;\n try {\n result = await this.fn(parameters, context);\n } catch (error) {\n if (error instanceof ToolExecutionError || error instanceof ValidationError) {\n throw error;\n }\n\n throw new ToolExecutionError(\n `Function tool execution failed: ${error instanceof Error ? error.message : String(error)}`,\n toolName,\n error instanceof Error ? error : new Error(String(error)),\n {\n parameterCount: Object.keys(parameters || {}).length,\n hasContext: !!context,\n },\n );\n }\n\n const executionTime = Date.now() - startTime;\n\n return {\n success: true,\n data: result,\n metadata: {\n executionTime,\n toolName,\n parameters,\n },\n };\n }\n\n /**\n * Validate parameters (simple boolean result)\n */\n validate(parameters: TToolParameters): boolean {\n return (\n getValidationErrors(\n parameters,\n this.schema.parameters.required || [],\n this.schema.parameters.properties || {},\n this.schema.parameters.additionalProperties,\n ).length === 0\n );\n }\n\n /**\n * Validate tool parameters with detailed result\n */\n validateParameters(parameters: TToolParameters): IParameterValidationResult {\n return validateToolParameters(\n parameters,\n this.schema.parameters.required || [],\n this.schema.parameters.properties || {},\n this.schema.parameters.additionalProperties,\n );\n }\n\n /**\n * Get tool description\n */\n getDescription(): string {\n return this.schema.description;\n }\n\n /**\n * Validate constructor inputs\n */\n private validateConstructorInputs(): void {\n if (!this.schema) {\n throw new ValidationError('Tool schema is required');\n }\n\n if (!this.fn || typeof this.fn !== 'function') {\n throw new ValidationError('Tool function is required and must be a function');\n }\n\n if (!this.schema.name) {\n throw new ValidationError('Tool schema must have a name');\n }\n }\n}\n\n/**\n * Helper function to create a function tool from a simple function\n */\nexport function createFunctionTool(\n name: string,\n description: string,\n parameters: IToolSchema['parameters'],\n fn: TToolExecutor,\n): FunctionTool {\n const schema: IToolSchema = {\n name,\n description,\n parameters,\n };\n\n return new FunctionTool(schema, fn);\n}\n\n/**\n * Helper function to create a function tool from Zod schema\n */\nexport function createZodFunctionTool(\n name: string,\n description: string,\n zodSchema: IZodSchema,\n fn: TToolExecutor,\n): FunctionTool {\n // Use comprehensive Zod to JSON schema conversion\n const parameters = zodToJsonSchema(zodSchema);\n\n const schema: IToolSchema = {\n name,\n description,\n parameters,\n };\n\n // Wrap the function with validation and ensure proper parameter handling\n const wrappedFn: TToolExecutor = async (\n parameters: TToolParameters,\n context?: IToolExecutionContext,\n ): Promise<TUniversalValue> => {\n // Use Zod for runtime validation\n const parseResult = zodSchema.safeParse(parameters);\n if (!parseResult.success) {\n throw new ValidationError(`Zod validation failed: ${parseResult.error}`);\n }\n\n const result = await fn((parseResult.data as TToolParameters) || parameters, context);\n // Ensure result is always a string for consistency with core package\n return typeof result === 'string' ? result : JSON.stringify(result);\n };\n\n return new FunctionTool(schema, wrappedFn);\n}\n\n// zodToJsonSchema function moved to Facade pattern schema-converter module\n","/**\n * BashTool — execute shell commands via child_process.spawn\n *\n * Returns TToolResult JSON string. Non-zero exit is returned as success:true\n * with exitCode set, matching Claude Code behaviour (the command ran, it just\n * exited non-zero — the LLM can decide what to do with that information).\n */\n\nimport { spawn } from 'node:child_process';\n\nimport { z } from 'zod';\n\nimport { createZodFunctionTool } from '../implementations/function-tool';\n\nimport type { FunctionTool } from '../implementations/function-tool';\nimport type { ISandboxToolOptions } from '../sandbox/types.js';\nimport type { TToolResult } from '../types/tool-result.js';\n\nconst DEFAULT_TIMEOUT_MS = 120_000; // 2 minutes\n\nconst BashSchema = z.object({\n command: z.string().describe('The bash command to execute'),\n timeout: z\n .number()\n .optional()\n .describe('Optional timeout in milliseconds (max 600000). Default is 120000 (2 minutes)'),\n workingDirectory: z\n .string()\n .optional()\n .describe('Working directory for the command. Defaults to the current working directory'),\n});\n\ntype TBashArgs = z.infer<typeof BashSchema>;\n\n/**\n * Run a shell command and return stdout + stderr.\n * Resolves with the TToolResult JSON string.\n */\nasync function runBash(args: TBashArgs, options: ISandboxToolOptions = {}): Promise<string> {\n const { command, timeout: rawTimeout = DEFAULT_TIMEOUT_MS, workingDirectory } = args;\n const timeout = Math.min(rawTimeout, 600_000);\n if (options.sandboxClient) {\n try {\n const sandboxResult = await options.sandboxClient.run(command, {\n timeoutMs: timeout,\n workingDirectory,\n });\n const output = sandboxResult.stderr\n ? `${sandboxResult.stdout}\\nstderr:\\n${sandboxResult.stderr}`\n : sandboxResult.stdout;\n const result: TToolResult = {\n success: true,\n output,\n exitCode: sandboxResult.exitCode,\n };\n return JSON.stringify(result);\n } catch (err) {\n const result: TToolResult = {\n success: false,\n output: '',\n error: err instanceof Error ? err.message : String(err),\n };\n return JSON.stringify(result);\n }\n }\n\n return new Promise<string>((resolve) => {\n const stdoutChunks: Buffer[] = [];\n const stderrChunks: Buffer[] = [];\n\n let timedOut = false;\n let settled = false;\n\n const child = spawn('sh', ['-c', command], {\n cwd: workingDirectory ?? process.cwd(),\n env: process.env,\n stdio: ['pipe', 'pipe', 'pipe'],\n });\n\n child.stdout.on('data', (chunk: Buffer) => {\n stdoutChunks.push(chunk);\n });\n\n child.stderr.on('data', (chunk: Buffer) => {\n stderrChunks.push(chunk);\n });\n\n const timer = setTimeout(() => {\n timedOut = true;\n child.kill('SIGTERM');\n // Resolve immediately on timeout — don't wait for close event.\n // The child process cleanup happens in the background.\n settle({\n success: false,\n output: Buffer.concat(stdoutChunks).toString('utf8'),\n error: `Command timed out after ${timeout}ms`,\n });\n }, timeout);\n\n function settle(result: TToolResult): void {\n if (settled) return;\n settled = true;\n clearTimeout(timer);\n resolve(JSON.stringify(result));\n }\n\n child.on('error', (err: Error) => {\n settle({\n success: false,\n output: '',\n error: err.message,\n });\n });\n\n child.on('close', (code: number | null) => {\n if (timedOut) {\n settle({\n success: false,\n output: Buffer.concat(stdoutChunks).toString('utf8'),\n error: `Command timed out after ${timeout}ms`,\n exitCode: code ?? undefined,\n });\n return;\n }\n\n const stdout = Buffer.concat(stdoutChunks).toString('utf8');\n const stderr = Buffer.concat(stderrChunks).toString('utf8');\n\n const exitCode = code ?? 0;\n const output = stderr ? `${stdout}\\nstderr:\\n${stderr}` : stdout;\n\n settle({\n success: true,\n output,\n exitCode,\n });\n });\n });\n}\n\n/**\n * Create a BashTool instance — register with Robota agent tools registry.\n */\nexport function createBashTool(options: ISandboxToolOptions = {}): FunctionTool {\n return createZodFunctionTool(\n 'Bash',\n 'Executes a given bash command and returns its output.\\n\\nThe working directory persists between commands, but shell state does not.\\n\\nIMPORTANT: Avoid using this tool to run `find`, `grep`, `cat`, `head`, `tail`, `sed`, `awk`, or `echo` commands. Instead, use the appropriate dedicated tool:\\n - File search: Use Glob (NOT find or ls)\\n - Content search: Use Grep (NOT grep or rg)\\n - Read files: Use Read (NOT cat/head/tail)\\n - Edit files: Use Edit (NOT sed/awk)\\n\\nFor simple commands, keep the description brief (5-10 words). For complex commands, include enough context to clarify what the command does.\\n\\nOutput is limited to 30,000 characters. Longer output will be middle-truncated.',\n BashSchema,\n async (params) => {\n // createZodFunctionTool passes validated params; cast is safe\n return runBash(params as TBashArgs, options);\n },\n );\n}\n\n/**\n * BashTool instance — register with Robota agent tools registry.\n */\nexport const bashTool = createBashTool();\n","import { resolve, sep } from 'node:path';\n\nimport type { TToolResult } from '../types/tool-result.js';\n\n/**\n * Returns a JSON-serialized TToolResult error when filePath is outside cwd.\n * Returns undefined when the path is within cwd or cwd is not set.\n */\nexport function checkPathWithinCwd(filePath: string, cwd: string | undefined): string | undefined {\n if (cwd === undefined) return undefined;\n\n const resolved = resolve(filePath);\n const cwdResolved = resolve(cwd);\n\n if (resolved !== cwdResolved && !resolved.startsWith(cwdResolved + sep)) {\n const result: TToolResult = {\n success: false,\n output: '',\n error: `Access denied: \"${filePath}\" is outside the working directory`,\n };\n return JSON.stringify(result);\n }\n\n return undefined;\n}\n","/**\n * ReadTool — read a file and return its contents with line numbers (cat -n style).\n *\n * Supports offset/limit for partial reads. Detects binary files and refuses to\n * return their raw bytes. Default limit is 2000 lines.\n */\n\nimport { readFile, stat } from 'node:fs/promises';\n\nimport { z } from 'zod';\n\nimport { checkPathWithinCwd } from './path-guard.js';\nimport { createZodFunctionTool } from '../implementations/function-tool';\n\nimport type { FunctionTool } from '../implementations/function-tool';\nimport type { ISandboxToolOptions } from '../sandbox/types.js';\nimport type { TToolResult } from '../types/tool-result.js';\n\nconst DEFAULT_LIMIT = 2000;\n\nconst ReadSchema = z.object({\n filePath: z.string().describe('The absolute path to the file to read'),\n offset: z\n .number()\n .optional()\n .describe(\n 'The line number to start reading from (1-based). Only provide if the file is too large to read at once',\n ),\n limit: z\n .number()\n .optional()\n .describe(\n `The number of lines to read (default: ${DEFAULT_LIMIT}). Only provide if the file is too large to read at once`,\n ),\n});\n\ntype TReadArgs = z.infer<typeof ReadSchema>;\n\n/**\n * Heuristic binary detection: scan the first 8 KB for null bytes.\n */\nfunction isBinary(buffer: Buffer): boolean {\n const checkLength = Math.min(buffer.length, 8192);\n for (let i = 0; i < checkLength; i++) {\n if (buffer[i] === 0) return true;\n }\n return false;\n}\n\n/**\n * Format lines with 1-based line numbers in cat -n style.\n * Pads line number to the width of the highest line number.\n */\nfunction formatWithLineNumbers(lines: string[], startLine: number): string {\n const lastLineNum = startLine + lines.length - 1;\n const width = String(lastLineNum).length;\n return lines\n .map((line, idx) => {\n const lineNum = String(startLine + idx).padStart(width, ' ');\n return `${lineNum}\\t${line}`;\n })\n .join('\\n');\n}\n\nfunction formatReadResult(\n filePath: string,\n content: string,\n startLine: number,\n limit: number,\n): string {\n const allLines = content.split('\\n');\n\n // Remove trailing empty line if file ends with newline (common in Unix files)\n if (allLines[allLines.length - 1] === '') {\n allLines.pop();\n }\n\n const zeroBasedStart = startLine - 1;\n const selectedLines = allLines.slice(zeroBasedStart, zeroBasedStart + limit);\n\n const output = formatWithLineNumbers(selectedLines, startLine);\n\n const totalLines = allLines.length;\n const returnedLines = selectedLines.length;\n const header =\n returnedLines < totalLines\n ? `[File: ${filePath} (lines ${startLine}-${startLine + returnedLines - 1} of ${totalLines})]\\n`\n : `[File: ${filePath} (${totalLines} lines)]\\n`;\n\n const result: TToolResult = {\n success: true,\n output: header + output,\n };\n return JSON.stringify(result);\n}\n\nasync function readFileTool(args: TReadArgs, options: ISandboxToolOptions = {}): Promise<string> {\n const { filePath, offset, limit = DEFAULT_LIMIT } = args;\n const startLine = offset !== undefined && offset > 0 ? offset : 1;\n\n if (options.sandboxClient) {\n try {\n const content = await options.sandboxClient.readFile(filePath);\n return formatReadResult(filePath, content, startLine, limit);\n } catch (err) {\n // allow-fallback: sandbox read failure → surface as TToolResult error\n const result: TToolResult = {\n success: false,\n output: '',\n error: err instanceof Error ? err.message : String(err),\n };\n return JSON.stringify(result);\n }\n }\n\n const pathError = checkPathWithinCwd(filePath, options.cwd);\n if (pathError !== undefined) return pathError;\n\n let fileStats: Awaited<ReturnType<typeof stat>> | undefined;\n try {\n fileStats = await stat(filePath);\n } catch (err) {\n // allow-fallback: stat failure means file not found → TToolResult error\n const result: TToolResult = {\n success: false,\n output: '',\n error: `File not found: ${filePath}`,\n };\n return JSON.stringify(result);\n }\n\n if (!fileStats.isFile()) {\n const result: TToolResult = {\n success: false,\n output: '',\n error: `Path is not a file: ${filePath}`,\n };\n return JSON.stringify(result);\n }\n\n let buffer: Buffer;\n try {\n buffer = await readFile(filePath);\n } catch (err) {\n // allow-fallback: read failure → TToolResult error (permissions, locks)\n const result: TToolResult = {\n success: false,\n output: '',\n error: err instanceof Error ? err.message : String(err),\n };\n return JSON.stringify(result);\n }\n\n if (isBinary(buffer)) {\n const result: TToolResult = {\n success: false,\n output: '',\n error: `Binary file not supported: ${filePath}`,\n };\n return JSON.stringify(result);\n }\n\n const content = buffer.toString('utf8');\n return formatReadResult(filePath, content, startLine, limit);\n}\n\n/**\n * Create a ReadTool instance — register with Robota agent tools registry.\n */\nexport function createReadTool(options: ISandboxToolOptions = {}): FunctionTool {\n return createZodFunctionTool(\n 'Read',\n 'Reads a file from the local filesystem.\\n\\nBy default, reads up to 2000 lines from the beginning of the file. You can optionally specify offset and limit for partial reads.\\n\\nResults are returned using cat -n format, with line numbers starting at 1.\\n\\nThe file_path parameter must be an absolute path, not a relative path.',\n ReadSchema,\n async (params) => {\n return readFileTool(params as TReadArgs, options);\n },\n );\n}\n\n/**\n * ReadTool instance — register with Robota agent tools registry.\n */\nexport const readTool = createReadTool();\n","import { randomBytes } from 'node:crypto';\nimport { chmod, mkdir, rename, rm, stat, writeFile } from 'node:fs/promises';\nimport { basename, dirname, join } from 'node:path';\n\nconst TEMP_RANDOM_BYTES = 6;\nconst PRESERVED_MODE_BITS = 0o7777;\nconst MISSING_FILE_ERROR_CODE = 'ENOENT';\n\nfunction createTempFilePath(filePath: string): string {\n const dir = dirname(filePath);\n const name = basename(filePath);\n const suffix = randomBytes(TEMP_RANDOM_BYTES).toString('hex');\n return join(dir, `.${name}.robota-tmp-${process.pid}-${Date.now()}-${suffix}`);\n}\n\nasync function readExistingMode(filePath: string): Promise<number | undefined> {\n try {\n const fileStats = await stat(filePath);\n return fileStats.mode & PRESERVED_MODE_BITS;\n } catch (error) {\n if (error instanceof Error && hasErrorCode(error, MISSING_FILE_ERROR_CODE)) return undefined;\n throw error;\n }\n}\n\nfunction hasErrorCode(error: Error, code: string): boolean {\n return 'code' in error && error.code === code;\n}\n\nexport async function atomicWriteUtf8File(filePath: string, content: string): Promise<void> {\n const dir = dirname(filePath);\n await mkdir(dir, { recursive: true });\n\n const existingMode = await readExistingMode(filePath);\n const tempFilePath = createTempFilePath(filePath);\n try {\n await writeFile(tempFilePath, content, 'utf8');\n if (existingMode !== undefined) {\n await chmod(tempFilePath, existingMode);\n }\n await rename(tempFilePath, filePath);\n } catch (error) {\n await rm(tempFilePath, { force: true }).catch(() => undefined);\n throw error;\n }\n}\n","/**\n * WriteTool — write content to a file, auto-creating parent directories.\n */\n\nimport { z } from 'zod';\n\nimport { atomicWriteUtf8File } from './atomic-file-write.js';\nimport { checkPathWithinCwd } from './path-guard.js';\nimport { createZodFunctionTool } from '../implementations/function-tool';\n\nimport type { FunctionTool } from '../implementations/function-tool';\nimport type { ISandboxToolOptions } from '../sandbox/types.js';\nimport type { TToolResult } from '../types/tool-result.js';\n\nconst WriteSchema = z.object({\n filePath: z.string().describe('The absolute path to the file to write'),\n content: z.string().describe('The content to write to the file'),\n});\n\ntype TWriteArgs = z.infer<typeof WriteSchema>;\n\nasync function writeFileTool(args: TWriteArgs, options: ISandboxToolOptions = {}): Promise<string> {\n const { filePath, content } = args;\n\n if (!options.sandboxClient) {\n const pathError = checkPathWithinCwd(filePath, options.cwd);\n if (pathError !== undefined) return pathError;\n }\n\n try {\n if (options.sandboxClient) {\n await options.sandboxClient.writeFile(filePath, content);\n } else {\n await atomicWriteUtf8File(filePath, content);\n }\n\n const result: TToolResult = {\n success: true,\n output: `Written ${Buffer.byteLength(content, 'utf8')} bytes to ${filePath}`,\n };\n return JSON.stringify(result);\n } catch (err) {\n // allow-fallback: write failure → TToolResult error (disk full, permissions)\n const result: TToolResult = {\n success: false,\n output: '',\n error: err instanceof Error ? err.message : String(err),\n };\n return JSON.stringify(result);\n }\n}\n\n/**\n * Create a WriteTool instance — register with Robota agent tools registry.\n */\nexport function createWriteTool(options: ISandboxToolOptions = {}): FunctionTool {\n return createZodFunctionTool(\n 'Write',\n 'Writes a file to the local filesystem. This will overwrite an existing file if one exists.\\n\\nALWAYS prefer the Edit tool for modifying existing files — it only sends the diff. Only use this tool to create new files or for complete rewrites.\\n\\nNEVER create documentation files (*.md) or README files unless explicitly requested by the user.',\n WriteSchema,\n async (params) => {\n return writeFileTool(params as TWriteArgs, options);\n },\n );\n}\n\n/**\n * WriteTool instance — register with Robota agent tools registry.\n */\nexport const writeTool = createWriteTool();\n","/**\n * EditTool — perform string-replace edits on a file.\n *\n * By default, requires the oldString to appear exactly once in the file\n * (ensuring surgical edits). Pass replaceAll:true to replace all occurrences.\n */\n\nimport { readFile } from 'node:fs/promises';\n\nimport { z } from 'zod';\n\nimport { atomicWriteUtf8File } from './atomic-file-write.js';\nimport { checkPathWithinCwd } from './path-guard.js';\nimport { createZodFunctionTool } from '../implementations/function-tool';\n\nimport type { FunctionTool } from '../implementations/function-tool';\nimport type { ISandboxToolOptions } from '../sandbox/types.js';\nimport type { TToolResult } from '../types/tool-result.js';\n\nconst EditSchema = z.object({\n filePath: z.string().describe('The absolute path to the file to modify'),\n oldString: z\n .string()\n .describe('The text to replace (must be an exact match of existing content)'),\n newString: z.string().describe('The text to replace it with (must be different from old_string)'),\n replaceAll: z\n .boolean()\n .optional()\n .describe(\n 'Replace all occurrences of old_string (default: false). Useful for renaming variables',\n ),\n});\n\ntype TEditArgs = z.infer<typeof EditSchema>;\n\nasync function editFileTool(args: TEditArgs, options: ISandboxToolOptions = {}): Promise<string> {\n const { filePath, oldString, newString, replaceAll = false } = args;\n\n if (!options.sandboxClient) {\n const pathError = checkPathWithinCwd(filePath, options.cwd);\n if (pathError !== undefined) return pathError;\n }\n\n let content: string;\n try {\n content = options.sandboxClient\n ? await options.sandboxClient.readFile(filePath)\n : await readFile(filePath, 'utf8');\n } catch (err) {\n // allow-fallback: read failure before edit → TToolResult error (file not found)\n const result: TToolResult = {\n success: false,\n output: '',\n error: `File not found: ${filePath}`,\n };\n return JSON.stringify(result);\n }\n\n if (!content.includes(oldString)) {\n const result: TToolResult = {\n success: false,\n output: '',\n error: `oldString not found in file: ${filePath}`,\n };\n return JSON.stringify(result);\n }\n\n // Uniqueness check when not in replaceAll mode\n if (!replaceAll) {\n const firstIdx = content.indexOf(oldString);\n const lastIdx = content.lastIndexOf(oldString);\n if (firstIdx !== lastIdx) {\n const occurrences = content.split(oldString).length - 1;\n const result: TToolResult = {\n success: false,\n output: '',\n error:\n `oldString is not unique in file (found ${occurrences} occurrences). ` +\n 'Provide more context to make it unique, or use replaceAll:true.',\n };\n return JSON.stringify(result);\n }\n }\n\n const updated = replaceAll\n ? content.split(oldString).join(newString)\n : content.slice(0, content.indexOf(oldString)) +\n newString +\n content.slice(content.indexOf(oldString) + oldString.length);\n\n try {\n if (options.sandboxClient) {\n await options.sandboxClient.writeFile(filePath, updated);\n } else {\n await atomicWriteUtf8File(filePath, updated);\n }\n } catch (err) {\n // allow-fallback: write failure after edit → TToolResult error\n const result: TToolResult = {\n success: false,\n output: '',\n error: err instanceof Error ? err.message : String(err),\n };\n return JSON.stringify(result);\n }\n\n const count = replaceAll ? content.split(oldString).length - 1 : 1;\n // Calculate start line number from the original content\n const matchIdx = content.indexOf(oldString);\n const startLine = matchIdx >= 0 ? content.substring(0, matchIdx).split('\\n').length : 1;\n const result: TToolResult = {\n success: true,\n output: `Replaced ${count} occurrence(s) in ${filePath}`,\n startLine,\n };\n return JSON.stringify(result);\n}\n\n/**\n * Create an EditTool instance — register with Robota agent tools registry.\n */\nexport function createEditTool(options: ISandboxToolOptions = {}): FunctionTool {\n return createZodFunctionTool(\n 'Edit',\n 'Performs exact string replacements in files.\\n\\nYou must use the Read tool at least once before editing. When editing text from Read output, preserve the exact indentation.\\n\\nThe edit will FAIL if old_string is not unique in the file. Either provide more surrounding context to make it unique, or use replace_all to change every instance.\\n\\nALWAYS prefer editing existing files over creating new ones.',\n EditSchema,\n async (params) => {\n return editFileTool(params as TEditArgs, options);\n },\n );\n}\n\n/**\n * EditTool instance — register with Robota agent tools registry.\n */\nexport const editTool = createEditTool();\n","/**\n * GlobTool — fast file pattern search using fast-glob.\n *\n * Excludes node_modules and .git by default.\n * Results are sorted by modification time (most recently modified first).\n */\n\nimport { stat } from 'node:fs/promises';\nimport { resolve } from 'node:path';\n\nimport fg from 'fast-glob';\nimport pLimit from 'p-limit';\nimport { z } from 'zod';\n\nimport { createZodFunctionTool } from '../implementations/function-tool';\n\nimport type { TToolResult } from '../types/tool-result.js';\n\nconst DEFAULT_MAX_RESULTS = 1000;\n\nconst GlobSchema = z.object({\n pattern: z\n .string()\n .describe('The glob pattern to match files against (e.g. \"**/*.ts\", \"src/**/*.tsx\")'),\n path: z\n .string()\n .optional()\n .describe(\n 'The directory to search in. Defaults to the current working directory. Must be a valid directory path if provided',\n ),\n limit: z\n .number()\n .optional()\n .describe(\n 'Maximum number of results to return (default: 1000). Use a smaller limit to save context space',\n ),\n});\n\ntype TGlobArgs = z.infer<typeof GlobSchema>;\n\ninterface IFileWithMtime {\n path: string;\n mtime: number;\n}\n\nasync function globFileTool(args: TGlobArgs): Promise<string> {\n const { pattern, path: basePath } = args;\n const cwd = basePath ? resolve(basePath) : process.cwd();\n\n let matches: string[];\n try {\n matches = await fg(pattern, {\n cwd,\n ignore: ['**/node_modules/**', '**/.git/**'],\n dot: true,\n absolute: false,\n });\n } catch (err) {\n const result: TToolResult = {\n success: false,\n output: '',\n error: err instanceof Error ? err.message : String(err),\n };\n return JSON.stringify(result);\n }\n\n // Sort by mtime (most recent first); cap concurrent stat calls to avoid I/O explosion\n const limit = pLimit(100);\n const withMtime: IFileWithMtime[] = await Promise.all(\n matches.map((p) =>\n limit(async () => {\n const absPath = resolve(cwd, p);\n try {\n const s = await stat(absPath);\n return { path: p, mtime: s.mtimeMs };\n } catch {\n // allow-fallback: stat failure on a matched path returns mtime=0 (sort-last), not a logic fallback\n return { path: p, mtime: 0 };\n }\n }),\n ),\n );\n\n withMtime.sort((a, b) => b.mtime - a.mtime);\n\n const maxResults = args.limit ?? DEFAULT_MAX_RESULTS;\n const totalMatches = withMtime.length;\n const truncated = totalMatches > maxResults;\n const limited = truncated ? withMtime.slice(0, maxResults) : withMtime;\n const sorted = limited.map((f) => f.path);\n\n let output = sorted.length > 0 ? sorted.join('\\n') : '(no matches)';\n if (truncated) {\n output += `\\n\\n[Showing ${maxResults} of ${totalMatches} matches. Use limit parameter to see more.]`;\n }\n\n const result: TToolResult = {\n success: true,\n output,\n };\n return JSON.stringify(result);\n}\n\n/**\n * GlobTool instance — register with Robota agent tools registry.\n */\nexport const globTool = createZodFunctionTool(\n 'Glob',\n \"Fast file pattern matching tool that works with any codebase size.\\n\\nSupports glob patterns like '**/*.js' or 'src/**/*.ts'. Returns matching file paths sorted by modification time.\\n\\nUse this tool when you need to find files by name patterns. When doing an open-ended search that may require multiple rounds, use the Agent tool instead.\\n\\nDefault limit is 1000 results. Use the limit parameter if you need fewer results to save context space.\",\n GlobSchema,\n async (params) => {\n return globFileTool(params as TGlobArgs);\n },\n);\n","/**\n * GrepTool — recursive regex content search.\n *\n * Supports three output modes:\n * - files_with_matches (default): return only file paths that contain a match\n * - content: return matching lines with optional context lines\n * - count: return per-file match counts as \"path:count\" rows\n *\n * headLimit caps the number of result lines; excess is truncated with a marker.\n */\n\nimport { readFile, readdir, stat } from 'node:fs/promises';\nimport { join, resolve } from 'node:path';\n\nimport { z } from 'zod';\n\nimport { createZodFunctionTool } from '../implementations/function-tool';\n\nimport type { TToolResult } from '../types/tool-result.js';\n\nconst GrepSchema = z.object({\n pattern: z.string().describe('The regular expression pattern to search for in file contents'),\n path: z\n .string()\n .optional()\n .describe('File or directory to search in. Defaults to the current working directory'),\n glob: z\n .string()\n .optional()\n .describe(\n 'Glob pattern to filter files (e.g. \"*.ts\", \"*.{ts,tsx}\"). Only files matching this pattern will be searched',\n ),\n contextLines: z\n .number()\n .optional()\n .describe(\n 'Number of context lines to show before and after each match. Only applies when outputMode is \"content\". Default: 0',\n ),\n outputMode: z\n .enum(['files_with_matches', 'content', 'count'])\n .optional()\n .describe(\n 'Output mode: \"files_with_matches\" shows only file paths (default), \"content\" shows matching lines with context, \"count\" shows per-file match counts',\n ),\n headLimit: z\n .number()\n .int()\n .positive()\n .optional()\n .describe(\n 'Maximum number of result lines (file paths, content lines, or count rows) to return. Excess results are truncated with a marker line',\n ),\n});\n\ntype TGrepArgs = z.infer<typeof GrepSchema>;\n\n/** Convert a simple glob to a RegExp for file name filtering. */\nfunction globToRegex(glob: string): RegExp {\n const escaped = glob\n .replace(/[.+^${}()|[\\]\\\\]/g, '\\\\$&')\n .replace(/\\*\\*/g, '.+')\n .replace(/\\*/g, '[^/]*');\n return new RegExp(`^${escaped}$`);\n}\n\n/** Check if a file name matches an optional glob filter. */\nfunction matchesGlob(filename: string, glob: string | undefined): boolean {\n if (glob === undefined) return true;\n return globToRegex(glob).test(filename);\n}\n\n/** Gather all files under a directory recursively, excluding node_modules/.git. */\nasync function collectFiles(dirPath: string, glob: string | undefined): Promise<string[]> {\n const results: string[] = [];\n\n async function walk(current: string): Promise<void> {\n let entryNames: string[];\n try {\n entryNames = await readdir(current);\n } catch {\n return;\n }\n\n for (const name of entryNames) {\n if (name === 'node_modules' || name === '.git') continue;\n\n const fullPath = join(current, name);\n let fileStat: Awaited<ReturnType<typeof stat>>;\n try {\n fileStat = await stat(fullPath);\n } catch {\n continue;\n }\n\n if (fileStat.isDirectory()) {\n await walk(fullPath);\n } else if (fileStat.isFile()) {\n if (matchesGlob(name, glob)) {\n results.push(fullPath);\n }\n }\n }\n }\n\n await walk(dirPath);\n return results;\n}\n\n/** Search a single file for lines matching the regex. */\nfunction searchFile(\n content: string,\n filePath: string,\n regex: RegExp,\n contextLines: number,\n outputMode: 'files_with_matches' | 'content' | 'count',\n): string[] {\n const lines = content.split('\\n');\n const matchingIndices: number[] = [];\n\n for (let i = 0; i < lines.length; i++) {\n if (regex.test(lines[i])) {\n matchingIndices.push(i);\n }\n }\n\n if (matchingIndices.length === 0) return [];\n\n if (outputMode === 'files_with_matches') {\n return [filePath];\n }\n\n if (outputMode === 'count') {\n return [`${filePath}:${matchingIndices.length}`];\n }\n\n // content mode — include context lines\n const includedIndices = new Set<number>();\n for (const idx of matchingIndices) {\n for (\n let c = Math.max(0, idx - contextLines);\n c <= Math.min(lines.length - 1, idx + contextLines);\n c++\n ) {\n includedIndices.add(c);\n }\n }\n\n const outputLines: string[] = [];\n const sortedIndices = Array.from(includedIndices).sort((a, b) => a - b);\n\n let prevIdx: number | undefined;\n for (const idx of sortedIndices) {\n if (prevIdx !== undefined && idx > prevIdx + 1) {\n outputLines.push('--');\n }\n const lineNum = idx + 1;\n const marker = matchingIndices.includes(idx) ? ':' : '-';\n outputLines.push(`${filePath}:${lineNum}${marker}${lines[idx]}`);\n prevIdx = idx;\n }\n\n return outputLines;\n}\n\nasync function grepFileTool(args: TGrepArgs): Promise<string> {\n const {\n pattern,\n path: searchPath,\n glob,\n contextLines = 0,\n outputMode = 'files_with_matches',\n headLimit,\n } = args;\n const targetPath = searchPath ? resolve(searchPath) : process.cwd();\n\n let regex: RegExp;\n try {\n regex = new RegExp(pattern);\n } catch (err) {\n const result: TToolResult = {\n success: false,\n output: '',\n error: `Invalid regex pattern: ${pattern}`,\n };\n return JSON.stringify(result);\n }\n\n // Determine whether targetPath is a file or directory\n let targetStat: Awaited<ReturnType<typeof stat>>;\n try {\n targetStat = await stat(targetPath);\n } catch {\n const result: TToolResult = {\n success: false,\n output: '',\n error: `Path not found: ${targetPath}`,\n };\n return JSON.stringify(result);\n }\n\n let files: string[];\n if (targetStat.isFile()) {\n files = [targetPath];\n } else {\n files = await collectFiles(targetPath, glob);\n }\n\n const allOutputLines: string[] = [];\n\n for (const filePath of files) {\n let content: string;\n try {\n const buffer = await readFile(filePath);\n // Skip binary files\n const checkLen = Math.min(buffer.length, 8192);\n let hasBinary = false;\n for (let i = 0; i < checkLen; i++) {\n if (buffer[i] === 0) {\n hasBinary = true;\n break;\n }\n }\n if (hasBinary) continue;\n content = buffer.toString('utf8');\n } catch {\n continue;\n }\n\n const fileMatches = searchFile(content, filePath, regex, contextLines, outputMode);\n allOutputLines.push(...fileMatches);\n }\n\n let outputLines = allOutputLines;\n if (headLimit !== undefined && outputLines.length > headLimit) {\n const truncatedCount = outputLines.length - headLimit;\n outputLines = [\n ...outputLines.slice(0, headLimit),\n `(+${truncatedCount} more results truncated by headLimit)`,\n ];\n }\n\n const result: TToolResult = {\n success: true,\n output: outputLines.length > 0 ? outputLines.join('\\n') : '(no matches)',\n };\n return JSON.stringify(result);\n}\n\n/**\n * GrepTool instance — register with Robota agent tools registry.\n */\nexport const grepTool = createZodFunctionTool(\n 'Grep',\n \"A powerful search tool built on regex matching.\\n\\nSupports full regex syntax (e.g., 'log.*Error', 'function\\\\\\\\s+\\\\\\\\w+'). Filter files with glob parameter (e.g., '*.js', '**/*.tsx').\\n\\nOutput modes: 'content' shows matching lines with context, 'files_with_matches' shows only file paths (default), 'count' shows per-file match counts.\\n\\nUse this tool for ALL search tasks. NEVER invoke grep or rg as a Bash command.\\n\\nUse headLimit to control result size and save context space.\",\n GrepSchema,\n async (params) => {\n return grepFileTool(params as TGrepArgs);\n },\n);\n","/**\n * WebFetchTool — fetch a URL and return its content as text.\n *\n * HTML is stripped to plain text for readability. Uses Node.js native fetch.\n * Output is capped at 30K chars (same as other tools).\n */\n\nimport { z } from 'zod';\n\nimport { createZodFunctionTool } from '../implementations/function-tool';\n\nimport type { TToolResult } from '../types/tool-result.js';\n\nconst DEFAULT_TIMEOUT_MS = 30_000;\nconst MAX_RESPONSE_BYTES = 5_000_000; // 5 MB max download\n\nconst WebFetchSchema = z.object({\n url: z.string().describe('The URL to fetch'),\n headers: z.record(z.string()).optional().describe('Optional HTTP headers as key-value pairs'),\n});\n\ntype TWebFetchArgs = z.infer<typeof WebFetchSchema>;\n\n/** Strip HTML tags and decode common entities to produce readable text. */\nfunction htmlToText(html: string): string {\n return html\n .replace(/<script[\\s\\S]*?<\\/script>/gi, '')\n .replace(/<style[\\s\\S]*?<\\/style>/gi, '')\n .replace(/<[^>]+>/g, ' ')\n .replace(/&amp;/g, '&')\n .replace(/&lt;/g, '<')\n .replace(/&gt;/g, '>')\n .replace(/&quot;/g, '\"')\n .replace(/&#39;/g, \"'\")\n .replace(/&nbsp;/g, ' ')\n .replace(/\\s+/g, ' ')\n .trim();\n}\n\nexport function classifyFetchError(err: unknown): string {\n if (!(err instanceof Error)) return String(err);\n\n if (err.name === 'AbortError') {\n return `Request timed out after ${DEFAULT_TIMEOUT_MS / 1000}s. The server did not respond in time.`;\n }\n\n const code = (err as NodeJS.ErrnoException).code;\n if (code === 'ENOTFOUND' || code === 'EAI_AGAIN') {\n return `Network error: DNS resolution failed for this host. The URL may be incorrect or the host does not exist. Do not retry with the same URL.`;\n }\n if (code === 'ECONNREFUSED') {\n return `Network error: Connection refused. The server is not accepting connections at this address. Do not retry with the same URL.`;\n }\n if (code === 'ECONNRESET') {\n return `Network error: Connection was reset by the server. The server may be temporarily unavailable.`;\n }\n if (code === 'ETIMEDOUT') {\n return `Network error: Connection timed out. The server is not reachable within the expected time.`;\n }\n if (code === 'CERT_HAS_EXPIRED' || code === 'UNABLE_TO_VERIFY_LEAF_SIGNATURE') {\n return `Network error: SSL certificate error (${code}). The server's certificate is invalid. Do not retry with the same URL.`;\n }\n\n return `Network error: ${err.message} Check that the URL is correct and the server is reachable.`;\n}\n\nasync function runWebFetch(args: TWebFetchArgs): Promise<string> {\n const { url, headers } = args;\n\n try {\n new URL(url);\n } catch {\n // allow-fallback: URL parse failure is a structured tool result, not a thrown error\n const result: TToolResult = {\n success: false,\n output: '',\n error: `Invalid URL: \"${url}\". Fix the URL format before retrying.`,\n };\n return JSON.stringify(result);\n }\n\n try {\n const controller = new AbortController();\n const timeout = setTimeout(() => controller.abort(), DEFAULT_TIMEOUT_MS);\n\n const response = await fetch(url, {\n headers: {\n 'User-Agent': 'Robota-CLI/3.0',\n ...(headers ?? {}),\n },\n signal: controller.signal,\n redirect: 'follow',\n });\n\n clearTimeout(timeout);\n\n if (!response.ok) {\n const retryHint =\n response.status >= 500\n ? ' The server is temporarily unavailable — retrying may help.'\n : ' Do not retry with the same URL.';\n const result: TToolResult = {\n success: false,\n output: '',\n error: `HTTP ${response.status} ${response.statusText}.${retryHint}`,\n };\n return JSON.stringify(result);\n }\n\n const contentType = response.headers.get('content-type') ?? '';\n const buffer = await response.arrayBuffer();\n\n if (buffer.byteLength > MAX_RESPONSE_BYTES) {\n const result: TToolResult = {\n success: false,\n output: '',\n error: `Response too large: ${buffer.byteLength} bytes (max ${MAX_RESPONSE_BYTES}). Consider fetching a more specific URL or a paginated endpoint.`,\n };\n return JSON.stringify(result);\n }\n\n let text = new TextDecoder().decode(buffer);\n\n // Strip HTML if content-type indicates HTML\n if (contentType.includes('html')) {\n text = htmlToText(text);\n }\n\n const result: TToolResult = { success: true, output: text };\n return JSON.stringify(result);\n } catch (err) {\n // allow-fallback: fetch errors are structured tool results returned to the LLM, not thrown\n const result: TToolResult = { success: false, output: '', error: classifyFetchError(err) };\n return JSON.stringify(result);\n }\n}\n\nexport const webFetchTool = createZodFunctionTool(\n 'WebFetch',\n 'Fetch a URL and return its content as text. HTML pages are converted to plain text.',\n WebFetchSchema,\n async (params) => runWebFetch(params as TWebFetchArgs),\n);\n","/**\n * WebSearchTool — search the web and return results.\n *\n * Uses Brave Search API when BRAVE_API_KEY is set.\n * Returns an error with setup instructions otherwise.\n */\n\nimport { z } from 'zod';\n\nimport { createZodFunctionTool } from '../implementations/function-tool';\n\nimport type { TToolResult } from '../types/tool-result.js';\n\nconst DEFAULT_LIMIT = 10;\nconst DEFAULT_TIMEOUT_MS = 15_000;\n\nconst WebSearchSchema = z.object({\n query: z.string().describe('The search query'),\n limit: z\n .number()\n .optional()\n .describe(`Maximum number of results to return (default: ${DEFAULT_LIMIT})`),\n});\n\ntype TWebSearchArgs = z.infer<typeof WebSearchSchema>;\n\ninterface IBraveResult {\n title: string;\n url: string;\n description: string;\n}\n\ninterface IBraveResponse {\n web?: {\n results?: IBraveResult[];\n };\n}\n\nasync function runWebSearch(args: TWebSearchArgs): Promise<string> {\n const { query, limit = DEFAULT_LIMIT } = args;\n const apiKey = process.env['BRAVE_API_KEY'];\n\n if (!apiKey) {\n const result: TToolResult = {\n success: false,\n output: '',\n error:\n 'Web search requires BRAVE_API_KEY environment variable. ' +\n 'Get a free API key at https://brave.com/search/api/ (2,000 queries/month free).',\n };\n return JSON.stringify(result);\n }\n\n try {\n const controller = new AbortController();\n const timeout = setTimeout(() => controller.abort(), DEFAULT_TIMEOUT_MS);\n\n const params = new URLSearchParams({\n q: query,\n count: String(Math.min(limit, 20)),\n });\n\n const response = await fetch(`https://api.search.brave.com/res/v1/web/search?${params}`, {\n headers: {\n Accept: 'application/json',\n 'Accept-Encoding': 'gzip',\n 'X-Subscription-Token': apiKey,\n },\n signal: controller.signal,\n });\n\n clearTimeout(timeout);\n\n if (!response.ok) {\n const result: TToolResult = {\n success: false,\n output: '',\n error: `Brave Search API error: HTTP ${response.status} ${response.statusText}`,\n };\n return JSON.stringify(result);\n }\n\n const data = (await response.json()) as IBraveResponse;\n const results = (data.web?.results ?? []).map((r) => ({\n title: r.title,\n url: r.url,\n snippet: r.description,\n }));\n\n const result: TToolResult = { success: true, output: JSON.stringify(results, null, 2) };\n return JSON.stringify(result);\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n const result: TToolResult = { success: false, output: '', error: message };\n return JSON.stringify(result);\n }\n}\n\nexport const webSearchTool = createZodFunctionTool(\n 'WebSearch',\n 'Search the web and return results with title, URL, and snippet.',\n WebSearchSchema,\n async (params) => runWebSearch(params as TWebSearchArgs),\n);\n"],"mappings":";;;;;;;;;AA4CA,IAAa,mBAAb,MAAwD;CACtD;CACA;CACA;CAEA,YAAY,SAAmC;EAC7C,KAAK,UAAU,QAAQ;EACvB,KAAK,iBAAiB,QAAQ;EAC9B,KAAK,4BAA4B,QAAQ;CAC3C;CAEA,MAAM,IAAI,SAAiB,SAA0D;EACnF,MAAM,SAAS,MAAM,KAAK,QAAQ,SAAS,IAAI,SAAS;GACtD,YAAY;GACZ,WAAW,SAAS;GACpB,KAAK,SAAS;EAChB,CAAC;EAED,OAAO;GACL,QAAQ,OAAO,UAAU;GACzB,QAAQ,OAAO,UAAU;GACzB,UAAU,OAAO,YAAY,OAAO,aAAa;EACnD;CACF;CAEA,MAAM,SAAS,MAA+B;EAC5C,MAAM,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GACvF,SAAS;IACP,QAAQ;IACR,mBAAmB;IACnB,wBAAwB;GAC1B;GACA,QAAQ,WAAW;EACrB,CAAC;EAED,aAAa,OAAO;EAEpB,IAAI,CAAC,SAAS,IAAI;GAChB,MAAM,SAAsB;IAC1B,SAAS;IACT,QAAQ;IACR,OAAO,gCAAgC,SAAS,OAAO,GAAG,SAAS;GACrE;GACA,OAAO,KAAK,UAAU,MAAM;EAC9B;EAGA,MAAM,YAAW,MADG,SAAS,KAAK,EAAA,CACZ,KAAK,WAAW,CAAC,EAAA,CAAG,KAAK,OAAO;GACpD,OAAO,EAAE;GACT,KAAK,EAAE;GACP,SAAS,EAAE;EACb,EAAE;EAEF,MAAM,SAAsB;GAAE,SAAS;GAAM,QAAQ,KAAK,UAAU,SAAS,MAAM,CAAC;EAAE;EACtF,OAAO,KAAK,UAAU,MAAM;CAC9B,SAAS,KAAK;EAEZ,MAAM,SAAsB;GAAE,SAAS;GAAO,QAAQ;GAAI,OAD1C,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;EACU;EACzE,OAAO,KAAK,UAAU,MAAM;CAC9B;AACF;AAEA,MAAa,gBAAgB,sBAC3B,aACA,mEACA,iBACA,OAAO,WAAW,aAAa,MAAwB,CACzD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@robota-sdk/agent-tools",
3
- "version": "3.0.0-beta.73",
3
+ "version": "3.0.0-beta.75",
4
4
  "description": "Tool registry and implementations for Robota SDK",
5
5
  "type": "module",
6
6
  "main": "dist/node/index.js",
@@ -34,20 +34,19 @@
34
34
  "dist"
35
35
  ],
36
36
  "dependencies": {
37
- "fast-glob": "^3.3.0",
37
+ "fast-glob": "^3.3.3",
38
38
  "p-limit": "^7.3.0",
39
- "zod": "^3.24.0"
39
+ "zod": "^3.25.76"
40
40
  },
41
41
  "peerDependencies": {
42
- "@robota-sdk/agent-core": "3.0.0-beta.73"
42
+ "@robota-sdk/agent-core": "3.0.0-beta.75"
43
43
  },
44
44
  "devDependencies": {
45
- "openapi-types": "^12.1.3",
46
- "rimraf": "^5.0.5",
47
- "tsdown": "^0.22.0",
48
- "typescript": "^5.3.3",
49
- "vitest": "^1.6.1",
50
- "@robota-sdk/agent-core": "3.0.0-beta.73"
45
+ "rimraf": "^5.0.10",
46
+ "tsdown": "^0.22.2",
47
+ "typescript": "^5.9.3",
48
+ "vitest": "^3.2.6",
49
+ "@robota-sdk/agent-core": "3.0.0-beta.75"
51
50
  },
52
51
  "license": "MIT",
53
52
  "publishConfig": {