@codebolt/agent 1.2.1 → 2.2.3

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.
Files changed (285) hide show
  1. package/README.md +157 -66
  2. package/dist/{agent.js → builderpattern/agent.js} +2 -2
  3. package/dist/{followupquestionbuilder.d.ts → builderpattern/followupquestionbuilder.d.ts} +1 -1
  4. package/dist/{followupquestionbuilder.js → builderpattern/followupquestionbuilder.js} +1 -1
  5. package/dist/{index.d.ts → builderpattern/index.d.ts} +3 -3
  6. package/dist/{llmoutputhandler.d.ts → builderpattern/llmoutputhandler.d.ts} +1 -1
  7. package/dist/{llmoutputhandler.js → builderpattern/llmoutputhandler.js} +7 -7
  8. package/dist/{promptbuilder.d.ts → builderpattern/promptbuilder.d.ts} +3 -3
  9. package/dist/{taskInstruction.d.ts → builderpattern/taskInstruction.d.ts} +2 -2
  10. package/dist/{usermessage.d.ts → builderpattern/usermessage.d.ts} +9 -4
  11. package/dist/composablepattern/agent.d.ts +169 -0
  12. package/dist/composablepattern/agent.js +598 -0
  13. package/dist/composablepattern/codebolt-storage.d.ts +67 -0
  14. package/dist/composablepattern/codebolt-storage.js +320 -0
  15. package/dist/composablepattern/document.d.ts +149 -0
  16. package/dist/composablepattern/document.js +372 -0
  17. package/dist/composablepattern/examples/codebolt-integration-example.d.ts +12 -0
  18. package/dist/composablepattern/examples/codebolt-integration-example.js +218 -0
  19. package/dist/composablepattern/examples/codebolt-storage-example.d.ts +40 -0
  20. package/dist/composablepattern/examples/codebolt-storage-example.js +223 -0
  21. package/dist/composablepattern/examples/custom-steps-example.d.ts +20 -0
  22. package/dist/composablepattern/examples/custom-steps-example.js +455 -0
  23. package/dist/composablepattern/examples/document-agent.d.ts +17 -0
  24. package/dist/composablepattern/examples/document-agent.js +107 -0
  25. package/dist/composablepattern/examples/simple-codebolt-integration.d.ts +8 -0
  26. package/dist/composablepattern/examples/simple-codebolt-integration.js +164 -0
  27. package/dist/composablepattern/examples/weather-agent.d.ts +18 -0
  28. package/dist/composablepattern/examples/weather-agent.js +86 -0
  29. package/dist/composablepattern/examples/workflow-example.d.ts +12 -0
  30. package/dist/composablepattern/examples/workflow-example.js +463 -0
  31. package/dist/composablepattern/index.d.ts +63 -0
  32. package/dist/composablepattern/index.js +115 -0
  33. package/dist/composablepattern/memory.d.ts +89 -0
  34. package/dist/composablepattern/memory.js +141 -0
  35. package/dist/composablepattern/tool.d.ts +84 -0
  36. package/dist/composablepattern/tool.js +260 -0
  37. package/dist/composablepattern/types.d.ts +194 -0
  38. package/dist/composablepattern/types.js +6 -0
  39. package/dist/composablepattern/user-context.d.ts +214 -0
  40. package/dist/composablepattern/user-context.js +275 -0
  41. package/dist/composablepattern/workflow.d.ts +388 -0
  42. package/dist/composablepattern/workflow.js +562 -0
  43. package/dist/local-tools/fileTools.d.ts +26 -0
  44. package/dist/local-tools/fileTools.js +162 -0
  45. package/dist/processor/agent/agentStep.d.ts +49 -0
  46. package/dist/processor/agent/agentStep.js +241 -0
  47. package/dist/processor/agent/toolExecutor.d.ts +19 -0
  48. package/dist/processor/agent/toolExecutor.js +90 -0
  49. package/dist/processor/index.d.ts +7 -0
  50. package/dist/processor/index.js +36 -0
  51. package/dist/processor/messageModifiers/baseMessageModifier.d.ts +20 -0
  52. package/dist/processor/messageModifiers/baseMessageModifier.js +55 -0
  53. package/dist/processor/processors/baseProcessor.d.ts +14 -0
  54. package/dist/processor/processors/baseProcessor.js +29 -0
  55. package/dist/processor/tools/baseTool.d.ts +10 -0
  56. package/dist/processor/tools/baseTool.js +20 -0
  57. package/dist/processor/tools/toolList.d.ts +9 -0
  58. package/dist/processor/tools/toolList.js +22 -0
  59. package/dist/processor/types/interfaces.d.ts +117 -0
  60. package/dist/processor/types/interfaces.js +2 -0
  61. package/dist/processor-pieces/additionalModifiers/argumentProcessorModifier.d.ts +13 -0
  62. package/dist/processor-pieces/additionalModifiers/argumentProcessorModifier.js +68 -0
  63. package/dist/processor-pieces/additionalModifiers/atFileProcessorModifier.d.ts +15 -0
  64. package/dist/processor-pieces/additionalModifiers/atFileProcessorModifier.js +212 -0
  65. package/dist/processor-pieces/additionalModifiers/chatCompressionModifier.d.ts +19 -0
  66. package/dist/processor-pieces/additionalModifiers/chatCompressionModifier.js +110 -0
  67. package/dist/processor-pieces/additionalModifiers/chatRecordingModifier.d.ts +23 -0
  68. package/dist/processor-pieces/additionalModifiers/chatRecordingModifier.js +173 -0
  69. package/dist/processor-pieces/additionalModifiers/coreSystemPromptModifier.d.ts +14 -0
  70. package/dist/processor-pieces/additionalModifiers/coreSystemPromptModifier.js +93 -0
  71. package/dist/processor-pieces/additionalModifiers/directoryContextModifier.d.ts +30 -0
  72. package/dist/processor-pieces/additionalModifiers/directoryContextModifier.js +330 -0
  73. package/dist/processor-pieces/additionalModifiers/environmentContextModifier.d.ts +26 -0
  74. package/dist/processor-pieces/additionalModifiers/environmentContextModifier.js +269 -0
  75. package/dist/processor-pieces/additionalModifiers/fallbackHandlerModifier.d.ts +38 -0
  76. package/dist/processor-pieces/additionalModifiers/fallbackHandlerModifier.js +217 -0
  77. package/dist/processor-pieces/additionalModifiers/ideContextModifier.d.ts +34 -0
  78. package/dist/processor-pieces/additionalModifiers/ideContextModifier.js +147 -0
  79. package/dist/processor-pieces/additionalModifiers/index.d.ts +12 -0
  80. package/dist/processor-pieces/additionalModifiers/index.js +28 -0
  81. package/dist/processor-pieces/additionalModifiers/loopDetectionModifier.d.ts +29 -0
  82. package/dist/processor-pieces/additionalModifiers/loopDetectionModifier.js +155 -0
  83. package/dist/processor-pieces/additionalModifiers/memoryImportModifier.d.ts +15 -0
  84. package/dist/processor-pieces/additionalModifiers/memoryImportModifier.js +129 -0
  85. package/dist/processor-pieces/additionalModifiers/shellProcessorModifier.d.ts +25 -0
  86. package/dist/processor-pieces/additionalModifiers/shellProcessorModifier.js +169 -0
  87. package/dist/processor-pieces/additionalModifiers/toolInjectionModifier.d.ts +20 -0
  88. package/dist/processor-pieces/additionalModifiers/toolInjectionModifier.js +152 -0
  89. package/dist/processor-pieces/base/baseMessageModifier.d.ts +12 -0
  90. package/dist/processor-pieces/base/baseMessageModifier.js +15 -0
  91. package/dist/processor-pieces/base/basePostInferenceProcessor.d.ts +13 -0
  92. package/dist/processor-pieces/base/basePostInferenceProcessor.js +18 -0
  93. package/dist/processor-pieces/base/basePostToolCallProcessor.d.ts +15 -0
  94. package/dist/processor-pieces/base/basePostToolCallProcessor.js +25 -0
  95. package/dist/processor-pieces/base/basePreInferenceProcessor.d.ts +12 -0
  96. package/dist/processor-pieces/base/basePreInferenceProcessor.js +17 -0
  97. package/dist/processor-pieces/base/basePreToolCallProcessor.d.ts +18 -0
  98. package/dist/processor-pieces/base/basePreToolCallProcessor.js +66 -0
  99. package/dist/processor-pieces/base/index.d.ts +9 -0
  100. package/dist/processor-pieces/base/index.js +18 -0
  101. package/dist/processor-pieces/index.d.ts +1 -0
  102. package/dist/processor-pieces/index.js +59 -0
  103. package/dist/processor-pieces/messageModifiers/addCurrentDirectoryRootFilesModifier.d.ts +7 -0
  104. package/dist/processor-pieces/messageModifiers/addCurrentDirectoryRootFilesModifier.js +93 -0
  105. package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.d.ts +31 -0
  106. package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.js +145 -0
  107. package/dist/processor-pieces/messageModifiers/advancedSystemInstructionMessageModifier.d.ts +9 -0
  108. package/dist/processor-pieces/messageModifiers/advancedSystemInstructionMessageModifier.js +77 -0
  109. package/dist/processor-pieces/messageModifiers/argumentProcessorModifier.d.ts +13 -0
  110. package/dist/processor-pieces/messageModifiers/argumentProcessorModifier.js +68 -0
  111. package/dist/processor-pieces/messageModifiers/atFileProcessorModifier.d.ts +25 -0
  112. package/dist/processor-pieces/messageModifiers/atFileProcessorModifier.js +453 -0
  113. package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.d.ts +7 -0
  114. package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.js +67 -0
  115. package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.d.ts +9 -0
  116. package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.js +90 -0
  117. package/dist/processor-pieces/messageModifiers/chatCompressionModifier.d.ts +19 -0
  118. package/dist/processor-pieces/messageModifiers/chatCompressionModifier.js +110 -0
  119. package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.d.ts +18 -0
  120. package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.example.d.ts +20 -0
  121. package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.example.js +124 -0
  122. package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.js +104 -0
  123. package/dist/processor-pieces/messageModifiers/chatRecordingModifier.d.ts +23 -0
  124. package/dist/processor-pieces/messageModifiers/chatRecordingModifier.js +173 -0
  125. package/dist/processor-pieces/messageModifiers/coreSystemPromptModifier.d.ts +14 -0
  126. package/dist/processor-pieces/messageModifiers/coreSystemPromptModifier.js +130 -0
  127. package/dist/processor-pieces/messageModifiers/directoryContextModifier.d.ts +36 -0
  128. package/dist/processor-pieces/messageModifiers/directoryContextModifier.js +418 -0
  129. package/dist/processor-pieces/messageModifiers/environmentContext.d.ts +41 -0
  130. package/dist/processor-pieces/messageModifiers/environmentContext.js +355 -0
  131. package/dist/processor-pieces/messageModifiers/environmentContextModifier.d.ts +26 -0
  132. package/dist/processor-pieces/messageModifiers/environmentContextModifier.js +260 -0
  133. package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.d.ts +13 -0
  134. package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.js +59 -0
  135. package/dist/processor-pieces/messageModifiers/ideContextModifier.d.ts +34 -0
  136. package/dist/processor-pieces/messageModifiers/ideContextModifier.js +157 -0
  137. package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.d.ts +19 -0
  138. package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.js +221 -0
  139. package/dist/processor-pieces/messageModifiers/index.d.ts +11 -0
  140. package/dist/processor-pieces/messageModifiers/index.js +26 -0
  141. package/dist/processor-pieces/messageModifiers/memoryImportModifier.d.ts +15 -0
  142. package/dist/processor-pieces/messageModifiers/memoryImportModifier.js +129 -0
  143. package/dist/processor-pieces/messageModifiers/mentionedFilesModifier.d.ts +23 -0
  144. package/dist/processor-pieces/messageModifiers/mentionedFilesModifier.js +207 -0
  145. package/dist/processor-pieces/messageModifiers/simpleMessageModifier.d.ts +7 -0
  146. package/dist/processor-pieces/messageModifiers/simpleMessageModifier.js +26 -0
  147. package/dist/processor-pieces/messageModifiers/toolInjectionModifier.d.ts +20 -0
  148. package/dist/processor-pieces/messageModifiers/toolInjectionModifier.js +152 -0
  149. package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.d.ts +38 -0
  150. package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.js +392 -0
  151. package/dist/processor-pieces/postInference/llmOutputValidityProcessor.d.ts +1 -0
  152. package/dist/processor-pieces/postInference/llmOutputValidityProcessor.js +2 -0
  153. package/dist/processor-pieces/postInferenceProcessors/checkForNoToolCall.d.ts +7 -0
  154. package/dist/processor-pieces/postInferenceProcessors/checkForNoToolCall.js +24 -0
  155. package/dist/processor-pieces/postInferenceProcessors/loopDetectionModifier.d.ts +29 -0
  156. package/dist/processor-pieces/postInferenceProcessors/loopDetectionModifier.js +174 -0
  157. package/dist/processor-pieces/postToolCall/advancedLoopDetectionProcessor.d.ts +41 -0
  158. package/dist/processor-pieces/postToolCall/advancedLoopDetectionProcessor.js +197 -0
  159. package/dist/processor-pieces/postToolCall/chatCompressionProcessor.d.ts +26 -0
  160. package/dist/processor-pieces/postToolCall/chatCompressionProcessor.js +90 -0
  161. package/dist/processor-pieces/postToolCall/chatRecordingProcessor.d.ts +81 -0
  162. package/dist/processor-pieces/postToolCall/chatRecordingProcessor.js +329 -0
  163. package/dist/processor-pieces/postToolCall/contextManagementProcessor.d.ts +40 -0
  164. package/dist/processor-pieces/postToolCall/contextManagementProcessor.js +272 -0
  165. package/dist/processor-pieces/postToolCall/conversationCompactorProcessor.d.ts +49 -0
  166. package/dist/processor-pieces/postToolCall/conversationCompactorProcessor.js +291 -0
  167. package/dist/processor-pieces/postToolCall/conversationContinuityProcessor.d.ts +49 -0
  168. package/dist/processor-pieces/postToolCall/conversationContinuityProcessor.js +293 -0
  169. package/dist/processor-pieces/postToolCall/followUpConversationProcessor.d.ts +47 -0
  170. package/dist/processor-pieces/postToolCall/followUpConversationProcessor.js +249 -0
  171. package/dist/processor-pieces/postToolCall/loopDetectionProcessor.d.ts +30 -0
  172. package/dist/processor-pieces/postToolCall/loopDetectionProcessor.js +137 -0
  173. package/dist/processor-pieces/postToolCall/responseValidationProcessor.d.ts +30 -0
  174. package/dist/processor-pieces/postToolCall/responseValidationProcessor.js +228 -0
  175. package/dist/processor-pieces/postToolCall/telemetryProcessor.d.ts +99 -0
  176. package/dist/processor-pieces/postToolCall/telemetryProcessor.js +278 -0
  177. package/dist/processor-pieces/postToolCall/tokenManagementProcessor.d.ts +37 -0
  178. package/dist/processor-pieces/postToolCall/tokenManagementProcessor.js +178 -0
  179. package/dist/processor-pieces/postToolCall/toolExecutionProcessor.d.ts +43 -0
  180. package/dist/processor-pieces/postToolCall/toolExecutionProcessor.js +207 -0
  181. package/dist/processor-pieces/postToolCallProcessors/index.d.ts +1 -0
  182. package/dist/processor-pieces/postToolCallProcessors/index.js +2 -0
  183. package/dist/processor-pieces/postToolCallProcessors/shellProcessorModifier.d.ts +25 -0
  184. package/dist/processor-pieces/postToolCallProcessors/shellProcessorModifier.js +225 -0
  185. package/dist/processor-pieces/preInference/conversationCompactorProcessor.d.ts +52 -0
  186. package/dist/processor-pieces/preInference/conversationCompactorProcessor.js +264 -0
  187. package/dist/processor-pieces/preInference/conversationContinuityProcessor.d.ts +49 -0
  188. package/dist/processor-pieces/preInference/conversationContinuityProcessor.js +293 -0
  189. package/dist/processor-pieces/preInferenceProcessors/chatCompressionModifier.d.ts +35 -0
  190. package/dist/processor-pieces/preInferenceProcessors/chatCompressionModifier.js +255 -0
  191. package/dist/processor-pieces/preInferenceProcessors/conversationCompaction.d.ts +7 -0
  192. package/dist/processor-pieces/preInferenceProcessors/conversationCompaction.js +31 -0
  193. package/dist/processor-pieces/preInferenceProcessors/index.d.ts +1 -0
  194. package/dist/processor-pieces/preInferenceProcessors/index.js +2 -0
  195. package/dist/processor-pieces/preToolCall/index.d.ts +9 -0
  196. package/dist/processor-pieces/preToolCall/index.js +18 -0
  197. package/dist/processor-pieces/preToolCall/localToolInterceptorProcessor.d.ts +58 -0
  198. package/dist/processor-pieces/preToolCall/localToolInterceptorProcessor.js +444 -0
  199. package/dist/processor-pieces/preToolCall/toolParameterModifierProcessor.d.ts +44 -0
  200. package/dist/processor-pieces/preToolCall/toolParameterModifierProcessor.js +367 -0
  201. package/dist/processor-pieces/preToolCall/toolValidationProcessor.d.ts +58 -0
  202. package/dist/processor-pieces/preToolCall/toolValidationProcessor.js +391 -0
  203. package/dist/processor-pieces/pretoolCallProcessors/index.d.ts +1 -0
  204. package/dist/processor-pieces/pretoolCallProcessors/index.js +2 -0
  205. package/dist/processor-pieces/processors/advancedLoopDetectionProcessor.d.ts +41 -0
  206. package/dist/processor-pieces/processors/advancedLoopDetectionProcessor.js +197 -0
  207. package/dist/processor-pieces/processors/chatCompressionProcessor.d.ts +26 -0
  208. package/dist/processor-pieces/processors/chatCompressionProcessor.js +90 -0
  209. package/dist/processor-pieces/processors/chatRecordingProcessor.d.ts +81 -0
  210. package/dist/processor-pieces/processors/chatRecordingProcessor.js +329 -0
  211. package/dist/processor-pieces/processors/contextManagementProcessor.d.ts +40 -0
  212. package/dist/processor-pieces/processors/contextManagementProcessor.js +305 -0
  213. package/dist/processor-pieces/processors/loopDetectionProcessor.d.ts +30 -0
  214. package/dist/processor-pieces/processors/loopDetectionProcessor.js +137 -0
  215. package/dist/processor-pieces/processors/responseValidationProcessor.d.ts +30 -0
  216. package/dist/processor-pieces/processors/responseValidationProcessor.js +228 -0
  217. package/dist/processor-pieces/processors/telemetryProcessor.d.ts +99 -0
  218. package/dist/processor-pieces/processors/telemetryProcessor.js +311 -0
  219. package/dist/processor-pieces/processors/tokenManagementProcessor.d.ts +37 -0
  220. package/dist/processor-pieces/processors/tokenManagementProcessor.js +178 -0
  221. package/dist/processor-pieces/processors/toolExecutionProcessor.d.ts +43 -0
  222. package/dist/processor-pieces/processors/toolExecutionProcessor.js +207 -0
  223. package/dist/processor-pieces/tools/fileTools.d.ts +26 -0
  224. package/dist/processor-pieces/tools/fileTools.js +162 -0
  225. package/dist/processor-pieces/utils/messageModifierHelper.d.ts +4 -0
  226. package/dist/processor-pieces/utils/messageModifierHelper.js +58 -0
  227. package/dist/types/commonTypes.d.ts +4 -0
  228. package/dist/types/processorTypes.d.ts +67 -0
  229. package/dist/types/processorTypes.js +58 -0
  230. package/dist/unified/agent/agent.d.ts +17 -0
  231. package/dist/unified/agent/agent.js +79 -0
  232. package/dist/unified/agent/team.d.ts +2 -0
  233. package/dist/unified/agent/team.js +6 -0
  234. package/dist/unified/agent/tool.d.ts +99 -0
  235. package/dist/unified/agent/tool.js +440 -0
  236. package/dist/unified/agent/tools.d.ts +44 -0
  237. package/dist/unified/agent/tools.js +487 -0
  238. package/dist/unified/agent/workflow.d.ts +24 -0
  239. package/dist/unified/agent/workflow.js +275 -0
  240. package/dist/unified/agent/workflowControls.d.ts +11 -0
  241. package/dist/unified/agent/workflowControls.js +20 -0
  242. package/dist/unified/agent/workflowSteps.d.ts +63 -0
  243. package/dist/unified/agent/workflowSteps.js +284 -0
  244. package/dist/unified/base/agentStep.d.ts +32 -0
  245. package/dist/unified/base/agentStep.js +96 -0
  246. package/dist/unified/base/create/createInitialPromptGenerators.d.ts +5 -0
  247. package/dist/unified/base/create/createInitialPromptGenerators.js +17 -0
  248. package/dist/unified/base/index.d.ts +5 -0
  249. package/dist/unified/base/index.js +13 -0
  250. package/dist/unified/base/initialPromptGenerator.d.ts +48 -0
  251. package/dist/unified/base/initialPromptGenerator.js +118 -0
  252. package/dist/unified/base/responseExecutor.d.ts +36 -0
  253. package/dist/unified/base/responseExecutor.js +283 -0
  254. package/dist/unified/examples/agentExample.d.ts +46 -0
  255. package/dist/unified/examples/agentExample.js +464 -0
  256. package/dist/unified/examples/documentationPatternExample.d.ts +10 -0
  257. package/dist/unified/examples/documentationPatternExample.js +385 -0
  258. package/dist/unified/examples/followUpProcessorsExample.d.ts +45 -0
  259. package/dist/unified/examples/followUpProcessorsExample.js +311 -0
  260. package/dist/unified/examples/orchestratorExample.d.ts +16 -0
  261. package/dist/unified/examples/orchestratorExample.js +415 -0
  262. package/dist/unified/examples/preToolCallProcessorsExample.d.ts +36 -0
  263. package/dist/unified/examples/preToolCallProcessorsExample.js +458 -0
  264. package/dist/unified/examples/workflowExample.d.ts +12 -0
  265. package/dist/unified/examples/workflowExample.js +497 -0
  266. package/dist/unified/index.d.ts +18 -0
  267. package/dist/unified/index.js +42 -0
  268. package/dist/unified/orchestrator/orchestrator.d.ts +260 -0
  269. package/dist/unified/orchestrator/orchestrator.js +519 -0
  270. package/dist/unified/team/team.d.ts +1 -0
  271. package/dist/unified/team/team.js +2 -0
  272. package/dist/unified/types/libTypes.d.ts +378 -0
  273. package/dist/unified/types/libTypes.js +6 -0
  274. package/dist/unified/types/types.d.ts +212 -0
  275. package/dist/unified/types/types.js +43 -0
  276. package/dist/unified/utils/utils.d.ts +40 -0
  277. package/dist/unified/utils/utils.js +219 -0
  278. package/package.json +35 -13
  279. /package/dist/{agent.d.ts → builderpattern/agent.d.ts} +0 -0
  280. /package/dist/{index.js → builderpattern/index.js} +0 -0
  281. /package/dist/{promptbuilder.js → builderpattern/promptbuilder.js} +0 -0
  282. /package/dist/{systemprompt.d.ts → builderpattern/systemprompt.d.ts} +0 -0
  283. /package/dist/{systemprompt.js → builderpattern/systemprompt.js} +0 -0
  284. /package/dist/{taskInstruction.js → builderpattern/taskInstruction.js} +0 -0
  285. /package/dist/{usermessage.js → builderpattern/usermessage.js} +0 -0
@@ -0,0 +1,440 @@
1
+ "use strict";
2
+ /**
3
+ * Tool creation utilities for the Unified Agent Framework
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createTool = createTool;
7
+ exports.createTextTool = createTextTool;
8
+ exports.createFileTool = createFileTool;
9
+ exports.createHttpTool = createHttpTool;
10
+ exports.createValidationTool = createValidationTool;
11
+ exports.createTransformTool = createTransformTool;
12
+ exports.toolsToOpenAIFormat = toolsToOpenAIFormat;
13
+ exports.executeTool = executeTool;
14
+ const zod_1 = require("zod");
15
+ /**
16
+ * Creates a new tool with input/output validation and execution logic
17
+ *
18
+ * @template TInput - Type for tool input parameters
19
+ * @template TOutput - Type for tool output
20
+ * @param config - Tool configuration object
21
+ * @returns Fully configured tool with validation methods
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * const calculatorTool = createTool({
26
+ * id: 'calculator',
27
+ * name: 'Calculator',
28
+ * description: 'Performs basic mathematical calculations',
29
+ * inputSchema: z.object({
30
+ * expression: z.string().describe('Mathematical expression to evaluate'),
31
+ * }),
32
+ * outputSchema: z.object({
33
+ * result: z.number(),
34
+ * expression: z.string(),
35
+ * }),
36
+ * execute: async ({ input }) => {
37
+ * const result = eval(input.expression); // Note: eval is dangerous, use a proper parser
38
+ * return { result, expression: input.expression };
39
+ * },
40
+ * });
41
+ * ```
42
+ */
43
+ function createTool(config) {
44
+ const tool = {
45
+ ...config,
46
+ /**
47
+ * Validates input against the tool's input schema
48
+ * @param input - Raw input to validate
49
+ * @returns Validated and typed input
50
+ * @throws {Error} If validation fails
51
+ */
52
+ validateInput(input) {
53
+ try {
54
+ return config.inputSchema.parse(input);
55
+ }
56
+ catch (error) {
57
+ if (error instanceof zod_1.z.ZodError) {
58
+ const errorMessages = error.issues
59
+ .map((issue) => `${issue.path.join('.')}: ${issue.message}`)
60
+ .join(', ');
61
+ throw new Error(`Tool "${config.id}" input validation failed: ${errorMessages}`);
62
+ }
63
+ throw error;
64
+ }
65
+ },
66
+ /**
67
+ * Validates output against the tool's output schema (if provided)
68
+ * @param output - Raw output to validate
69
+ * @returns Validated and typed output
70
+ * @throws {Error} If validation fails
71
+ */
72
+ validateOutput(output) {
73
+ if (!config.outputSchema) {
74
+ return output;
75
+ }
76
+ try {
77
+ return config.outputSchema.parse(output);
78
+ }
79
+ catch (error) {
80
+ if (error instanceof zod_1.z.ZodError) {
81
+ const errorMessages = error.issues
82
+ .map((issue) => `${issue.path.join('.')}: ${issue.message}`)
83
+ .join(', ');
84
+ throw new Error(`Tool "${config.id}" output validation failed: ${errorMessages}`);
85
+ }
86
+ throw error;
87
+ }
88
+ },
89
+ /**
90
+ * Converts the tool to OpenAI function format
91
+ * @returns OpenAI function specification
92
+ */
93
+ toOpenAITool() {
94
+ return {
95
+ type: 'function',
96
+ function: {
97
+ name: config.id,
98
+ description: config.description,
99
+ parameters: zodSchemaToJsonSchema(config.inputSchema)
100
+ }
101
+ };
102
+ }
103
+ };
104
+ return tool;
105
+ }
106
+ /**
107
+ * Converts a Zod schema to JSON Schema format for OpenAI functions
108
+ */
109
+ function zodSchemaToJsonSchema(schema) {
110
+ // This is a simplified conversion - in a real implementation,
111
+ // you might want to use a library like zod-to-json-schema
112
+ if (schema instanceof zod_1.z.ZodObject) {
113
+ const shape = schema.shape;
114
+ const properties = {};
115
+ const required = [];
116
+ for (const [key, value] of Object.entries(shape)) {
117
+ properties[key] = zodTypeToJsonSchema(value);
118
+ // Check if field is required (not optional)
119
+ if (!value.isOptional()) {
120
+ required.push(key);
121
+ }
122
+ }
123
+ return {
124
+ type: 'object',
125
+ properties,
126
+ required: required.length > 0 ? required : undefined,
127
+ additionalProperties: false
128
+ };
129
+ }
130
+ return zodTypeToJsonSchema(schema);
131
+ }
132
+ /**
133
+ * Converts individual Zod types to JSON Schema
134
+ */
135
+ function zodTypeToJsonSchema(zodType) {
136
+ if (zodType instanceof zod_1.z.ZodString) {
137
+ const result = { type: 'string' };
138
+ // Add description if available
139
+ if (zodType._def.description) {
140
+ result.description = zodType._def.description;
141
+ }
142
+ // Add constraints
143
+ const checks = zodType._def.checks || [];
144
+ for (const check of checks) {
145
+ switch (check.kind) {
146
+ case 'min':
147
+ result.minLength = check.value;
148
+ break;
149
+ case 'max':
150
+ result.maxLength = check.value;
151
+ break;
152
+ case 'email':
153
+ result.format = 'email';
154
+ break;
155
+ case 'url':
156
+ result.format = 'uri';
157
+ break;
158
+ case 'regex':
159
+ result.pattern = check.regex.source;
160
+ break;
161
+ }
162
+ }
163
+ return result;
164
+ }
165
+ if (zodType instanceof zod_1.z.ZodNumber) {
166
+ const result = { type: 'number' };
167
+ if (zodType._def.description) {
168
+ result.description = zodType._def.description;
169
+ }
170
+ const checks = zodType._def.checks || [];
171
+ for (const check of checks) {
172
+ switch (check.kind) {
173
+ case 'min':
174
+ result.minimum = check.value;
175
+ break;
176
+ case 'max':
177
+ result.maximum = check.value;
178
+ break;
179
+ case 'int':
180
+ result.type = 'integer';
181
+ break;
182
+ }
183
+ }
184
+ return result;
185
+ }
186
+ if (zodType instanceof zod_1.z.ZodBoolean) {
187
+ const result = { type: 'boolean' };
188
+ if (zodType._def.description) {
189
+ result.description = zodType._def.description;
190
+ }
191
+ return result;
192
+ }
193
+ if (zodType instanceof zod_1.z.ZodArray) {
194
+ const result = {
195
+ type: 'array',
196
+ items: zodTypeToJsonSchema(zodType._def.type)
197
+ };
198
+ if (zodType._def.description) {
199
+ result.description = zodType._def.description;
200
+ }
201
+ const checks = zodType._def.checks || [];
202
+ for (const check of checks) {
203
+ switch (check.kind) {
204
+ case 'min':
205
+ result.minItems = check.value;
206
+ break;
207
+ case 'max':
208
+ result.maxItems = check.value;
209
+ break;
210
+ }
211
+ }
212
+ return result;
213
+ }
214
+ if (zodType instanceof zod_1.z.ZodEnum) {
215
+ const result = {
216
+ type: 'string',
217
+ enum: zodType._def.values
218
+ };
219
+ if (zodType._def.description) {
220
+ result.description = zodType._def.description;
221
+ }
222
+ return result;
223
+ }
224
+ if (zodType instanceof zod_1.z.ZodLiteral) {
225
+ const result = {
226
+ type: typeof zodType._def.value,
227
+ enum: [zodType._def.value]
228
+ };
229
+ if (zodType._def.description) {
230
+ result.description = zodType._def.description;
231
+ }
232
+ return result;
233
+ }
234
+ if (zodType instanceof zod_1.z.ZodUnion) {
235
+ const options = zodType._def.options;
236
+ const anyOf = options.map((option) => zodTypeToJsonSchema(option));
237
+ const result = { anyOf };
238
+ if (zodType._def.description) {
239
+ result.description = zodType._def.description;
240
+ }
241
+ return result;
242
+ }
243
+ if (zodType instanceof zod_1.z.ZodOptional) {
244
+ return zodTypeToJsonSchema(zodType._def.innerType);
245
+ }
246
+ if (zodType instanceof zod_1.z.ZodNullable) {
247
+ const innerSchema = zodTypeToJsonSchema(zodType._def.innerType);
248
+ return {
249
+ anyOf: [
250
+ innerSchema,
251
+ { type: 'null' }
252
+ ]
253
+ };
254
+ }
255
+ if (zodType instanceof zod_1.z.ZodObject) {
256
+ return zodSchemaToJsonSchema(zodType);
257
+ }
258
+ // Fallback for unknown types
259
+ return { type: 'string', description: 'Unknown type' };
260
+ }
261
+ /**
262
+ * Creates a simple text-based tool
263
+ */
264
+ function createTextTool(config) {
265
+ return createTool({
266
+ id: config.id,
267
+ name: config.name,
268
+ description: config.description,
269
+ inputSchema: zod_1.z.object({
270
+ text: zod_1.z.string().describe('Input text to process')
271
+ }),
272
+ outputSchema: zod_1.z.string(),
273
+ execute: async ({ input, context }) => {
274
+ return await config.execute(input.text, context);
275
+ },
276
+ timeout: config.timeout
277
+ });
278
+ }
279
+ /**
280
+ * Creates a file operation tool
281
+ */
282
+ function createFileTool(config) {
283
+ let inputSchema;
284
+ switch (config.operation) {
285
+ case 'read':
286
+ inputSchema = zod_1.z.object({
287
+ filePath: zod_1.z.string().describe('Path to the file to read'),
288
+ encoding: zod_1.z.string().optional().describe('File encoding (default: utf-8)')
289
+ });
290
+ break;
291
+ case 'write':
292
+ inputSchema = zod_1.z.object({
293
+ filePath: zod_1.z.string().describe('Path to the file to write'),
294
+ content: zod_1.z.string().describe('Content to write to the file'),
295
+ encoding: zod_1.z.string().optional().describe('File encoding (default: utf-8)')
296
+ });
297
+ break;
298
+ case 'delete':
299
+ inputSchema = zod_1.z.object({
300
+ filePath: zod_1.z.string().describe('Path to the file to delete')
301
+ });
302
+ break;
303
+ case 'list':
304
+ inputSchema = zod_1.z.object({
305
+ directoryPath: zod_1.z.string().describe('Path to the directory to list'),
306
+ recursive: zod_1.z.boolean().optional().describe('Whether to list recursively')
307
+ });
308
+ break;
309
+ default:
310
+ throw new Error(`Unknown file operation: ${config.operation}`);
311
+ }
312
+ return createTool({
313
+ id: config.id,
314
+ name: config.name,
315
+ description: config.description,
316
+ inputSchema,
317
+ execute: config.execute
318
+ });
319
+ }
320
+ /**
321
+ * Creates an HTTP request tool
322
+ */
323
+ function createHttpTool(config) {
324
+ const inputSchema = zod_1.z.object({
325
+ url: zod_1.z.string().describe('URL to make the request to'),
326
+ method: zod_1.z.enum(['GET', 'POST', 'PUT', 'DELETE', 'PATCH']).optional().describe('HTTP method'),
327
+ headers: zod_1.z.record(zod_1.z.string()).optional().describe('Request headers'),
328
+ body: zod_1.z.any().optional().describe('Request body'),
329
+ timeout: zod_1.z.number().optional().describe('Request timeout in milliseconds')
330
+ });
331
+ const defaultExecute = async ({ input }) => {
332
+ const url = config.baseUrl ? `${config.baseUrl}${input.url}` : input.url;
333
+ const method = input.method || config.method || 'GET';
334
+ const headers = { ...config.defaultHeaders, ...input.headers };
335
+ // This would use fetch or similar HTTP client
336
+ return {
337
+ url,
338
+ method,
339
+ headers,
340
+ status: 200,
341
+ data: 'HTTP request executed successfully'
342
+ };
343
+ };
344
+ return createTool({
345
+ id: config.id,
346
+ name: config.name,
347
+ description: config.description,
348
+ inputSchema,
349
+ execute: config.execute || defaultExecute
350
+ });
351
+ }
352
+ /**
353
+ * Creates a validation tool
354
+ */
355
+ function createValidationTool(config) {
356
+ return createTool({
357
+ id: config.id,
358
+ name: config.name,
359
+ description: config.description,
360
+ inputSchema: zod_1.z.object({
361
+ data: zod_1.z.any().describe('Data to validate')
362
+ }),
363
+ execute: async ({ input }) => {
364
+ try {
365
+ const validatedData = config.schema.parse(input.data);
366
+ const result = config.onValid ? await config.onValid(validatedData) : validatedData;
367
+ return {
368
+ valid: true,
369
+ data: result,
370
+ errors: []
371
+ };
372
+ }
373
+ catch (error) {
374
+ if (error instanceof zod_1.z.ZodError) {
375
+ const errors = error.issues.map(issue => `${issue.path.join('.')}: ${issue.message}`);
376
+ const result = config.onInvalid ? await config.onInvalid(errors) : null;
377
+ return {
378
+ valid: false,
379
+ data: result,
380
+ errors
381
+ };
382
+ }
383
+ throw error;
384
+ }
385
+ }
386
+ });
387
+ }
388
+ /**
389
+ * Creates a transformation tool
390
+ */
391
+ function createTransformTool(config) {
392
+ return createTool({
393
+ id: config.id,
394
+ name: config.name,
395
+ description: config.description,
396
+ inputSchema: config.inputSchema,
397
+ outputSchema: config.outputSchema,
398
+ execute: async ({ input, context }) => {
399
+ return await config.transform(input, context);
400
+ }
401
+ });
402
+ }
403
+ /**
404
+ * Utility to convert multiple tools to OpenAI format
405
+ */
406
+ function toolsToOpenAIFormat(tools) {
407
+ return tools.map(tool => tool.toOpenAITool());
408
+ }
409
+ /**
410
+ * Utility to execute a tool with validation
411
+ */
412
+ async function executeTool(tool, input, context, agent) {
413
+ // Validate input
414
+ const validatedInput = tool.validateInput(input);
415
+ // Execute with timeout if specified
416
+ let result;
417
+ if (tool.timeout) {
418
+ const timeoutPromise = new Promise((_, reject) => {
419
+ setTimeout(() => reject(new Error(`Tool execution timeout: ${tool.id}`)), tool.timeout);
420
+ });
421
+ const executionPromise = Promise.resolve(tool.execute({
422
+ input: validatedInput,
423
+ context,
424
+ agent
425
+ }));
426
+ result = await Promise.race([executionPromise, timeoutPromise]);
427
+ }
428
+ else {
429
+ result = await tool.execute({
430
+ input: validatedInput,
431
+ context,
432
+ agent
433
+ });
434
+ }
435
+ // Validate output if schema is provided
436
+ if (tool.validateOutput) {
437
+ return tool.validateOutput(result);
438
+ }
439
+ return result;
440
+ }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Tool creation utilities for the Unified Agent Framework
3
+ */
4
+ import { z, ZodType } from 'zod';
5
+ import type { OpenAITool } from '../types/libTypes';
6
+ import { ToolConfig, ToolInterface } from '@codebolt/types/agent';
7
+ export declare class Tool implements ToolInterface {
8
+ id: string;
9
+ description: string;
10
+ inputSchema: ZodType<any, any, any>;
11
+ outputSchema?: ZodType<any, any, any>;
12
+ executionFunction: (context: any) => any;
13
+ constructor(config: ToolConfig);
14
+ execute(input: any, context: any): Promise<{
15
+ success: boolean;
16
+ error: string | undefined;
17
+ result?: undefined;
18
+ } | {
19
+ success: boolean;
20
+ result: any;
21
+ error?: undefined;
22
+ }>;
23
+ getToolDescription(): string;
24
+ getToolSchema(): z.ZodType<any, any, any>;
25
+ private validateInput;
26
+ /**
27
+ * Validates output against the tool's output schema (if provided)
28
+ * @param output - Raw output to validate
29
+ * @returns Validated and typed output
30
+ * @throws {Error} If validation fails
31
+ */
32
+ private validateOutput;
33
+ /**
34
+ * Converts the tool to OpenAI function format
35
+ * @returns OpenAI function specification
36
+ */
37
+ toOpenAITool(): OpenAITool;
38
+ private zodSchemaToJsonSchema;
39
+ /**
40
+ * Converts individual Zod types to JSON Schema
41
+ */
42
+ private zodTypeToJsonSchema;
43
+ }
44
+ export declare function createTool(config: ToolConfig): Tool;