beeai-framework 0.1.24 → 0.1.25

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 (227) hide show
  1. package/dist/adapters/a2a/agents/agent.d.cts +2 -2
  2. package/dist/adapters/a2a/agents/agent.d.ts +2 -2
  3. package/dist/adapters/a2a/agents/events.d.cts +1 -1
  4. package/dist/adapters/a2a/agents/events.d.ts +1 -1
  5. package/dist/adapters/a2a/agents/types.d.cts +2 -2
  6. package/dist/adapters/a2a/agents/types.d.ts +2 -2
  7. package/dist/adapters/a2a/serve/agent_executor.d.cts +3 -3
  8. package/dist/adapters/a2a/serve/agent_executor.d.ts +3 -3
  9. package/dist/adapters/a2a/serve/server.d.cts +2 -2
  10. package/dist/adapters/a2a/serve/server.d.ts +2 -2
  11. package/dist/adapters/acp/agents/agent.d.cts +2 -2
  12. package/dist/adapters/acp/agents/agent.d.ts +2 -2
  13. package/dist/adapters/acp/agents/events.d.cts +1 -1
  14. package/dist/adapters/acp/agents/events.d.ts +1 -1
  15. package/dist/adapters/agentstack/agents/agent.d.cts +2 -2
  16. package/dist/adapters/agentstack/agents/agent.d.ts +2 -2
  17. package/dist/adapters/agentstack/agents/events.d.cts +1 -1
  18. package/dist/adapters/agentstack/agents/events.d.ts +1 -1
  19. package/dist/adapters/amazon-bedrock/backend/chat.d.cts +2 -2
  20. package/dist/adapters/amazon-bedrock/backend/chat.d.ts +2 -2
  21. package/dist/adapters/amazon-bedrock/backend/embedding.d.cts +2 -2
  22. package/dist/adapters/amazon-bedrock/backend/embedding.d.ts +2 -2
  23. package/dist/adapters/anthropic/backend/chat.d.cts +3 -3
  24. package/dist/adapters/anthropic/backend/chat.d.ts +3 -3
  25. package/dist/adapters/anthropic/backend/embedding.d.cts +2 -2
  26. package/dist/adapters/anthropic/backend/embedding.d.ts +2 -2
  27. package/dist/adapters/azure-openai/backend/chat.d.cts +2 -2
  28. package/dist/adapters/azure-openai/backend/chat.d.ts +2 -2
  29. package/dist/adapters/azure-openai/backend/embedding.d.cts +2 -2
  30. package/dist/adapters/azure-openai/backend/embedding.d.ts +2 -2
  31. package/dist/adapters/dummy/backend/chat.d.cts +4 -2
  32. package/dist/adapters/dummy/backend/chat.d.ts +4 -2
  33. package/dist/adapters/dummy/backend/embedding.d.cts +2 -2
  34. package/dist/adapters/dummy/backend/embedding.d.ts +2 -2
  35. package/dist/adapters/google-vertex/backend/chat.d.cts +2 -2
  36. package/dist/adapters/google-vertex/backend/chat.d.ts +2 -2
  37. package/dist/adapters/google-vertex/backend/embedding.d.cts +2 -2
  38. package/dist/adapters/google-vertex/backend/embedding.d.ts +2 -2
  39. package/dist/adapters/groq/backend/chat.d.cts +2 -2
  40. package/dist/adapters/groq/backend/chat.d.ts +2 -2
  41. package/dist/adapters/groq/backend/embedding.d.cts +2 -2
  42. package/dist/adapters/groq/backend/embedding.d.ts +2 -2
  43. package/dist/adapters/langchain/backend/chat.d.cts +4 -2
  44. package/dist/adapters/langchain/backend/chat.d.ts +4 -2
  45. package/dist/adapters/langchain/backend/embedding.d.cts +2 -2
  46. package/dist/adapters/langchain/backend/embedding.d.ts +2 -2
  47. package/dist/adapters/langchain/tools.d.cts +1 -1
  48. package/dist/adapters/langchain/tools.d.ts +1 -1
  49. package/dist/adapters/ollama/backend/chat.d.cts +2 -2
  50. package/dist/adapters/ollama/backend/chat.d.ts +2 -2
  51. package/dist/adapters/ollama/backend/embedding.d.cts +2 -2
  52. package/dist/adapters/ollama/backend/embedding.d.ts +2 -2
  53. package/dist/adapters/openai/backend/chat.d.cts +2 -2
  54. package/dist/adapters/openai/backend/chat.d.ts +2 -2
  55. package/dist/adapters/openai/backend/embedding.d.cts +2 -2
  56. package/dist/adapters/openai/backend/embedding.d.ts +2 -2
  57. package/dist/adapters/vercel/backend/chat.d.cts +4 -2
  58. package/dist/adapters/vercel/backend/chat.d.ts +4 -2
  59. package/dist/adapters/vercel/backend/embedding.d.cts +2 -2
  60. package/dist/adapters/vercel/backend/embedding.d.ts +2 -2
  61. package/dist/adapters/vercel/backend/utils.d.cts +2 -2
  62. package/dist/adapters/vercel/backend/utils.d.ts +2 -2
  63. package/dist/adapters/watsonx/backend/chat.cjs +8 -0
  64. package/dist/adapters/watsonx/backend/chat.cjs.map +1 -1
  65. package/dist/adapters/watsonx/backend/chat.d.cts +4 -2
  66. package/dist/adapters/watsonx/backend/chat.d.ts +4 -2
  67. package/dist/adapters/watsonx/backend/chat.js +8 -0
  68. package/dist/adapters/watsonx/backend/chat.js.map +1 -1
  69. package/dist/adapters/watsonx/backend/embedding.d.cts +2 -2
  70. package/dist/adapters/watsonx/backend/embedding.d.ts +2 -2
  71. package/dist/adapters/xai/backend/chat.d.cts +2 -2
  72. package/dist/adapters/xai/backend/chat.d.ts +2 -2
  73. package/dist/{agent-Cy4QtsN8.d.cts → agent-CuJD7Szg.d.cts} +3 -3
  74. package/dist/{agent-DHLEPXEA.d.ts → agent-DIyHPkn2.d.ts} +3 -3
  75. package/dist/agents/base.d.cts +2 -2
  76. package/dist/agents/base.d.ts +2 -2
  77. package/dist/agents/experimental/replan/agent.d.cts +3 -3
  78. package/dist/agents/experimental/replan/agent.d.ts +3 -3
  79. package/dist/agents/experimental/replan/prompts.d.cts +1 -1
  80. package/dist/agents/experimental/replan/prompts.d.ts +1 -1
  81. package/dist/agents/experimental/streamlit/agent.d.cts +3 -3
  82. package/dist/agents/experimental/streamlit/agent.d.ts +3 -3
  83. package/dist/agents/react/agent.d.cts +4 -4
  84. package/dist/agents/react/agent.d.ts +4 -4
  85. package/dist/agents/react/runners/base.d.cts +4 -4
  86. package/dist/agents/react/runners/base.d.ts +4 -4
  87. package/dist/agents/react/runners/deep-think/runner.d.cts +4 -4
  88. package/dist/agents/react/runners/deep-think/runner.d.ts +4 -4
  89. package/dist/agents/react/runners/default/runner.d.cts +4 -4
  90. package/dist/agents/react/runners/default/runner.d.ts +4 -4
  91. package/dist/agents/react/runners/granite/runner.d.cts +4 -4
  92. package/dist/agents/react/runners/granite/runner.d.ts +4 -4
  93. package/dist/agents/react/types.d.cts +2 -2
  94. package/dist/agents/react/types.d.ts +2 -2
  95. package/dist/agents/requirement/agent.d.cts +4 -4
  96. package/dist/agents/requirement/agent.d.ts +4 -4
  97. package/dist/agents/requirement/requirements/conditional.d.cts +4 -4
  98. package/dist/agents/requirement/requirements/conditional.d.ts +4 -4
  99. package/dist/agents/requirement/requirements/requirement.d.cts +4 -4
  100. package/dist/agents/requirement/requirements/requirement.d.ts +4 -4
  101. package/dist/agents/requirement/requirements/utils.d.cts +1 -1
  102. package/dist/agents/requirement/requirements/utils.d.ts +1 -1
  103. package/dist/agents/requirement/runner.cjs +21 -13
  104. package/dist/agents/requirement/runner.cjs.map +1 -1
  105. package/dist/agents/requirement/runner.d.cts +4 -4
  106. package/dist/agents/requirement/runner.d.ts +4 -4
  107. package/dist/agents/requirement/runner.js +21 -13
  108. package/dist/agents/requirement/runner.js.map +1 -1
  109. package/dist/agents/requirement/types.d.cts +4 -4
  110. package/dist/agents/requirement/types.d.ts +4 -4
  111. package/dist/agents/requirement/utils/llm.d.cts +4 -4
  112. package/dist/agents/requirement/utils/llm.d.ts +4 -4
  113. package/dist/agents/requirement/utils/tool.cjs +13 -2
  114. package/dist/agents/requirement/utils/tool.cjs.map +1 -1
  115. package/dist/agents/requirement/utils/tool.d.cts +4 -4
  116. package/dist/agents/requirement/utils/tool.d.ts +4 -4
  117. package/dist/agents/requirement/utils/tool.js +11 -0
  118. package/dist/agents/requirement/utils/tool.js.map +1 -1
  119. package/dist/agents/toolCalling/agent.d.cts +3 -3
  120. package/dist/agents/toolCalling/agent.d.ts +3 -3
  121. package/dist/agents/toolCalling/types.d.cts +1 -1
  122. package/dist/agents/toolCalling/types.d.ts +1 -1
  123. package/dist/agents/types.d.cts +2 -2
  124. package/dist/agents/types.d.ts +2 -2
  125. package/dist/backend/backend.d.cts +2 -2
  126. package/dist/backend/backend.d.ts +2 -2
  127. package/dist/backend/chat.cjs +124 -45
  128. package/dist/backend/chat.cjs.map +1 -1
  129. package/dist/backend/chat.d.cts +2 -2
  130. package/dist/backend/chat.d.ts +2 -2
  131. package/dist/backend/chat.js +127 -48
  132. package/dist/backend/chat.js.map +1 -1
  133. package/dist/backend/core.d.cts +3 -3
  134. package/dist/backend/core.d.ts +3 -3
  135. package/dist/backend/embedding.d.cts +2 -2
  136. package/dist/backend/embedding.d.ts +2 -2
  137. package/dist/backend/errors.cjs +25 -0
  138. package/dist/backend/errors.cjs.map +1 -1
  139. package/dist/backend/errors.d.cts +34 -1
  140. package/dist/backend/errors.d.ts +34 -1
  141. package/dist/backend/errors.js +24 -1
  142. package/dist/backend/errors.js.map +1 -1
  143. package/dist/backend/utils.d.cts +2 -2
  144. package/dist/backend/utils.d.ts +2 -2
  145. package/dist/{base-CyFx7BRL.d.ts → base-BfhNzUYf.d.ts} +1 -1
  146. package/dist/{base-XfWeXQ-S.d.cts → base-BqzN2QwB.d.cts} +1 -1
  147. package/dist/{chat-D8SVtw5Q.d.ts → chat-DTxmaKP0.d.ts} +7 -1
  148. package/dist/{chat-CC0s8z23.d.cts → chat-DaqV3woF.d.cts} +7 -1
  149. package/dist/context.d.cts +1 -1
  150. package/dist/context.d.ts +1 -1
  151. package/dist/emitter/emitter.d.cts +1 -1
  152. package/dist/emitter/emitter.d.ts +1 -1
  153. package/dist/emitter/types.d.cts +1 -1
  154. package/dist/emitter/types.d.ts +1 -1
  155. package/dist/index.d.cts +3 -3
  156. package/dist/index.d.ts +3 -3
  157. package/dist/internals/fetcher.d.cts +1 -1
  158. package/dist/internals/fetcher.d.ts +1 -1
  159. package/dist/memory/summarizeMemory.d.cts +2 -2
  160. package/dist/memory/summarizeMemory.d.ts +2 -2
  161. package/dist/middleware/streamToolCall.cjs +9 -0
  162. package/dist/middleware/streamToolCall.cjs.map +1 -1
  163. package/dist/middleware/streamToolCall.d.cts +11 -3
  164. package/dist/middleware/streamToolCall.d.ts +11 -3
  165. package/dist/middleware/streamToolCall.js +9 -0
  166. package/dist/middleware/streamToolCall.js.map +1 -1
  167. package/dist/middleware/trajectory.d.cts +1 -1
  168. package/dist/middleware/trajectory.d.ts +1 -1
  169. package/dist/parsers/linePrefix.d.cts +1 -1
  170. package/dist/parsers/linePrefix.d.ts +1 -1
  171. package/dist/tools/arxiv.d.cts +1 -1
  172. package/dist/tools/arxiv.d.ts +1 -1
  173. package/dist/tools/base.d.cts +1 -1
  174. package/dist/tools/base.d.ts +1 -1
  175. package/dist/tools/calculator.d.cts +1 -1
  176. package/dist/tools/calculator.d.ts +1 -1
  177. package/dist/tools/custom.d.cts +2 -2
  178. package/dist/tools/custom.d.ts +2 -2
  179. package/dist/tools/database/elasticsearch.d.cts +1 -1
  180. package/dist/tools/database/elasticsearch.d.ts +1 -1
  181. package/dist/tools/database/milvus.d.cts +3 -3
  182. package/dist/tools/database/milvus.d.ts +3 -3
  183. package/dist/tools/database/qdrant.d.cts +1 -1
  184. package/dist/tools/database/qdrant.d.ts +1 -1
  185. package/dist/tools/database/sql.d.cts +1 -1
  186. package/dist/tools/database/sql.d.ts +1 -1
  187. package/dist/tools/handoff.d.cts +2 -2
  188. package/dist/tools/handoff.d.ts +2 -2
  189. package/dist/tools/llm.d.cts +2 -2
  190. package/dist/tools/llm.d.ts +2 -2
  191. package/dist/tools/mcp.d.cts +1 -1
  192. package/dist/tools/mcp.d.ts +1 -1
  193. package/dist/tools/openapi.d.cts +1 -1
  194. package/dist/tools/openapi.d.ts +1 -1
  195. package/dist/tools/python/output.d.cts +1 -1
  196. package/dist/tools/python/output.d.ts +1 -1
  197. package/dist/tools/python/python.d.cts +2 -2
  198. package/dist/tools/python/python.d.ts +2 -2
  199. package/dist/tools/search/base.d.cts +1 -1
  200. package/dist/tools/search/base.d.ts +1 -1
  201. package/dist/tools/search/duckDuckGoSearch.d.cts +1 -1
  202. package/dist/tools/search/duckDuckGoSearch.d.ts +1 -1
  203. package/dist/tools/search/googleSearch.d.cts +1 -1
  204. package/dist/tools/search/googleSearch.d.ts +1 -1
  205. package/dist/tools/search/searXNGSearch.d.cts +1 -1
  206. package/dist/tools/search/searXNGSearch.d.ts +1 -1
  207. package/dist/tools/search/wikipedia.d.cts +1 -1
  208. package/dist/tools/search/wikipedia.d.ts +1 -1
  209. package/dist/tools/similarity.d.cts +1 -1
  210. package/dist/tools/similarity.d.ts +1 -1
  211. package/dist/tools/think.d.cts +1 -1
  212. package/dist/tools/think.d.ts +1 -1
  213. package/dist/tools/weather/openMeteo.d.cts +1 -1
  214. package/dist/tools/weather/openMeteo.d.ts +1 -1
  215. package/dist/tools/web/webCrawler.d.cts +1 -1
  216. package/dist/tools/web/webCrawler.d.ts +1 -1
  217. package/dist/{types-Dyd4e1G6.d.ts → types-YT-WdK3m.d.ts} +11 -11
  218. package/dist/{types-D9pn62yF.d.cts → types-YoNQSxQH.d.cts} +11 -11
  219. package/dist/version.cjs +1 -1
  220. package/dist/version.js +1 -1
  221. package/dist/workflows/agent.d.cts +40 -40
  222. package/dist/workflows/agent.d.ts +40 -40
  223. package/dist/workflows/workflow.d.cts +1 -1
  224. package/dist/workflows/workflow.d.ts +1 -1
  225. package/package.json +1 -1
  226. package/dist/{emitter-36-9MnvA.d.ts → emitter-CL56qab4.d.ts} +1 -1
  227. package/dist/{emitter-jN55XZZq.d.cts → emitter-UkIkNrek.d.cts} +1 -1
@@ -3,17 +3,17 @@ import '../../backend/message.js';
3
3
  import '../../tools/base.js';
4
4
  import '../../errors.js';
5
5
  import '../../template.js';
6
- import '../../chat-D8SVtw5Q.js';
7
- import '../../base-CyFx7BRL.js';
6
+ import '../../chat-DTxmaKP0.js';
7
+ import '../../base-BfhNzUYf.js';
8
8
  import 'zod';
9
- export { h as RequirementAgentCallbacks, c as RequirementAgentExecutionConfig, f as RequirementAgentOutput, a as RequirementAgentRequest, e as RequirementAgentRunInput, g as RequirementAgentRunOptions, R as RequirementAgentRunState, l as RequirementAgentRunStateStep, b as RequirementAgentSystemPromptInputSchema, i as RequirementAgentTaskPromptInputSchema, d as RequirementAgentTemplates, j as RequirementAgentToolErrorPromptInputSchema, k as RequirementAgentToolNoResultPromptInputSchema } from '../../types-Dyd4e1G6.js';
9
+ export { h as RequirementAgentCallbacks, c as RequirementAgentExecutionConfig, f as RequirementAgentOutput, a as RequirementAgentRequest, e as RequirementAgentRunInput, g as RequirementAgentRunOptions, R as RequirementAgentRunState, l as RequirementAgentRunStateStep, b as RequirementAgentSystemPromptInputSchema, i as RequirementAgentTaskPromptInputSchema, d as RequirementAgentTemplates, j as RequirementAgentToolErrorPromptInputSchema, k as RequirementAgentToolNoResultPromptInputSchema } from '../../types-YT-WdK3m.js';
10
10
  import '../../internals/serializable.js';
11
11
  import '../../internals/types.js';
12
12
  import '../../internals/helpers/guards.js';
13
13
  import 'ai';
14
14
  import 'ajv';
15
15
  import '../../context.js';
16
- import '../../emitter-36-9MnvA.js';
16
+ import '../../emitter-CL56qab4.js';
17
17
  import '../../internals/helpers/promise.js';
18
18
  import 'promise-based-task';
19
19
  import '../../cache/base.js';
@@ -2,7 +2,7 @@ import { AnyTool } from '../../../tools/base.cjs';
2
2
  import { RunContext } from '../../../context.cjs';
3
3
  import { SystemMessage } from '../../../backend/message.cjs';
4
4
  import { PromptTemplate } from '../../../template.cjs';
5
- import { F as FinalAnswerTool, R as RequirementAgentRunState, a as RequirementAgentRequest, b as RequirementAgentSystemPromptInputSchema } from '../../../types-D9pn62yF.cjs';
5
+ import { F as FinalAnswerTool, R as RequirementAgentRunState, a as RequirementAgentRequest, b as RequirementAgentSystemPromptInputSchema } from '../../../types-YoNQSxQH.cjs';
6
6
  import { Requirement, Rule } from '../requirements/requirement.cjs';
7
7
  import 'ajv';
8
8
  import '../../../errors.cjs';
@@ -14,15 +14,15 @@ import '../../../cache/base.cjs';
14
14
  import '../../../internals/helpers/schema.cjs';
15
15
  import 'zod';
16
16
  import 'zod-to-json-schema';
17
- import '../../../emitter-jN55XZZq.cjs';
17
+ import '../../../emitter-UkIkNrek.cjs';
18
18
  import '../../../internals/helpers/promise.cjs';
19
19
  import 'ai';
20
20
  import '../../../memory/base.cjs';
21
- import '../../../chat-CC0s8z23.cjs';
21
+ import '../../../chat-DaqV3woF.cjs';
22
22
  import '../../../backend/constants.cjs';
23
23
  import '../../../logger/logger.cjs';
24
24
  import 'pino';
25
- import '../../../base-XfWeXQ-S.cjs';
25
+ import '../../../base-BqzN2QwB.cjs';
26
26
 
27
27
  /**
28
28
  * Copyright 2025 © BeeAI a Series of LF Projects, LLC
@@ -2,7 +2,7 @@ import { AnyTool } from '../../../tools/base.js';
2
2
  import { RunContext } from '../../../context.js';
3
3
  import { SystemMessage } from '../../../backend/message.js';
4
4
  import { PromptTemplate } from '../../../template.js';
5
- import { F as FinalAnswerTool, R as RequirementAgentRunState, a as RequirementAgentRequest, b as RequirementAgentSystemPromptInputSchema } from '../../../types-Dyd4e1G6.js';
5
+ import { F as FinalAnswerTool, R as RequirementAgentRunState, a as RequirementAgentRequest, b as RequirementAgentSystemPromptInputSchema } from '../../../types-YT-WdK3m.js';
6
6
  import { Requirement, Rule } from '../requirements/requirement.js';
7
7
  import 'ajv';
8
8
  import '../../../errors.js';
@@ -14,15 +14,15 @@ import '../../../cache/base.js';
14
14
  import '../../../internals/helpers/schema.js';
15
15
  import 'zod';
16
16
  import 'zod-to-json-schema';
17
- import '../../../emitter-36-9MnvA.js';
17
+ import '../../../emitter-CL56qab4.js';
18
18
  import '../../../internals/helpers/promise.js';
19
19
  import 'ai';
20
20
  import '../../../memory/base.js';
21
- import '../../../chat-D8SVtw5Q.js';
21
+ import '../../../chat-DTxmaKP0.js';
22
22
  import '../../../backend/constants.js';
23
23
  import '../../../logger/logger.js';
24
24
  import 'pino';
25
- import '../../../base-CyFx7BRL.js';
25
+ import '../../../base-BfhNzUYf.js';
26
26
 
27
27
  /**
28
28
  * Copyright 2025 © BeeAI a Series of LF Projects, LLC
@@ -1,14 +1,25 @@
1
1
  'use strict';
2
2
 
3
3
  var base_cjs = require('../../../tools/base.cjs');
4
- var errors_cjs = require('../../../errors.cjs');
4
+ var errors_cjs$1 = require('../../../errors.cjs');
5
5
  var emitter_cjs = require('../../../emitter/emitter.cjs');
6
6
  var zod = require('zod');
7
7
  var message_cjs = require('../../../backend/message.cjs');
8
+ var utils_cjs = require('../../../adapters/vercel/backend/utils.cjs');
9
+ var errors_cjs = require('../../../backend/errors.cjs');
8
10
 
9
11
  var __defProp = Object.defineProperty;
10
12
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
11
13
  async function runTool(tools, msg, context) {
14
+ if (!utils_cjs.isToolCallValid(msg)) {
15
+ throw new errors_cjs.ChatModelToolCallError(`Tool '${msg.toolName}' does not exist!`, [], {
16
+ generatedContent: JSON.stringify({
17
+ name: msg.toolName,
18
+ parameters: msg.input
19
+ }),
20
+ generatedError: "The generated tool call is invalid. Cannot parse the args."
21
+ });
22
+ }
12
23
  const result = {
13
24
  msg,
14
25
  tool: null,
@@ -28,7 +39,7 @@ async function runTool(tools, msg, context) {
28
39
  });
29
40
  } catch (e) {
30
41
  if (e instanceof base_cjs.ToolError) {
31
- result.error = errors_cjs.FrameworkError.ensure(e);
42
+ result.error = errors_cjs$1.FrameworkError.ensure(e);
32
43
  } else {
33
44
  throw e;
34
45
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/agents/requirement/utils/tool.ts"],"names":["runTool","tools","msg","context","result","tool","input","output","StringToolOutput","error","find","name","toolName","ToolError","run","toolCallMsg","Tool","contextKeys","Memory","state","memory","e","FrameworkError","ensure","FinalAnswerToolSchema","z","object","response","string","describe","FinalAnswerTool","description","instructions","customSchema","emitter","expectedOutput","undefined","ZodSchema","Emitter","root","child","namespace","creator","inputSchema","_run","_options","_ctx","answer","AssistantMessage","JSON","stringify"],"mappings":";;;;;;;;;;AAiCA,eAAsBA,OAAAA,CACpBC,KAAAA,EACAC,GAAAA,EACAC,OAAAA,EAA4B;AAE5B,EAAA,MAAMC,MAAAA,GAA+B;AACnCF,IAAAA,GAAAA;IACAG,IAAAA,EAAM,IAAA;AACN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AAA,CAAK6B,0BAA0BE,aAAAA,EAAW;AAE5C,MAAA,IAAA,CAAKlB,MAAM4B,MAAAA,GAAS,IAAIC,6BAAiBC,IAAAA,CAAKC,SAAAA,CAAU5C,KAAAA,CAAAA,CAAAA;KAC1D,MAAO;AAEL,MAAA,IAAA,CAAKa,KAAAA,CAAM4B,MAAAA,GAAS,IAAIC,4BAAAA,CAAiB1C,MAAMqB,QAAQ,CAAA;AACzD;AAEA,IAAA,OAAO,IAAInB,0BAAiB,uBAAA,CAAA;AAC9B;AACF","file":"tool.cjs","sourcesContent":["/**\n * Copyright 2025 © BeeAI a Series of LF Projects, LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n AnyTool,\n BaseToolRunOptions,\n StringToolOutput,\n Tool,\n ToolError,\n ToolOutput,\n} from \"@/tools/base.js\";\nimport { ToolCallPart } from \"ai\";\nimport { FrameworkError } from \"@/errors.js\";\nimport { Emitter } from \"@/emitter/emitter.js\";\nimport { z, ZodSchema } from \"zod\";\nimport { RequirementAgentRunState } from \"@/agents/requirement/types.js\";\nimport { AssistantMessage } from \"@/backend/message.js\";\nimport { RunContext } from \"@/context.js\";\n\n// Tool invocation result\nexport interface ToolInvocationResult {\n msg: ToolCallPart;\n tool: AnyTool | null;\n input: unknown;\n output: ToolOutput;\n error: FrameworkError | null;\n}\n\n/**\n * Run a single tool with error handling\n */\nexport async function runTool(\n tools: AnyTool[],\n msg: ToolCallPart,\n context: Record<string, any>,\n): Promise<ToolInvocationResult> {\n const result: ToolInvocationResult = {\n msg,\n tool: null,\n input: msg.input,\n output: new StringToolOutput(\"\"),\n error: null,\n };\n\n try {\n result.tool = tools.find((tool) => tool.name === msg.toolName) || null;\n if (!result.tool) {\n throw new ToolError(`Tool '${msg.toolName}' does not exist!`);\n }\n\n result.output = await result.tool.run(result.input).context({\n ...context,\n toolCallMsg: msg,\n [Tool.contextKeys.Memory]: context.state.memory,\n });\n } catch (e) {\n if (e instanceof ToolError) {\n result.error = FrameworkError.ensure(e);\n } else {\n throw e;\n }\n }\n\n return result;\n}\n\n// Final answer tool schema\nconst FinalAnswerToolSchema = z.object({\n response: z.string().describe(\"The final answer to the user\"),\n});\n\n/**\n * Special tool for capturing final answers\n */\nexport class FinalAnswerTool extends Tool {\n public readonly name = \"final_answer\";\n public readonly description = \"Sends the final answer to the user\";\n public instructions?: string;\n public customSchema: boolean;\n public readonly emitter: Emitter<any>;\n\n protected expectedOutput: string | ZodSchema | null;\n protected state: RequirementAgentRunState;\n\n constructor(expectedOutput: string | ZodSchema | null, state: RequirementAgentRunState) {\n super();\n this.expectedOutput = expectedOutput;\n this.state = state;\n this.instructions = typeof expectedOutput === \"string\" ? expectedOutput : undefined;\n this.customSchema = expectedOutput instanceof ZodSchema;\n this.emitter = Emitter.root.child({\n namespace: [\"tool\", \"final_answer\"],\n creator: this,\n });\n }\n\n inputSchema(): ZodSchema {\n const expectedOutput = this.expectedOutput;\n\n if (!expectedOutput) {\n return FinalAnswerToolSchema;\n } else if (expectedOutput instanceof ZodSchema) {\n return expectedOutput;\n } else if (typeof expectedOutput === \"string\") {\n return z.object({\n response: z.string().describe(expectedOutput),\n });\n } else {\n return FinalAnswerToolSchema;\n }\n }\n\n async _run(\n input: any,\n _options: BaseToolRunOptions,\n _ctx: RunContext<typeof this>,\n ): Promise<StringToolOutput> {\n this.state.result = input;\n\n if (this.expectedOutput instanceof ZodSchema) {\n // For custom schemas, serialize the entire input\n this.state.answer = new AssistantMessage(JSON.stringify(input));\n } else {\n // For string schemas, use the response field\n this.state.answer = new AssistantMessage(input.response);\n }\n\n return new StringToolOutput(\"Message has been sent\");\n }\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/agents/requirement/utils/tool.ts"],"names":["runTool","tools","msg","context","isToolCallValid","ChatModelToolCallError","toolName","generatedContent","JSON","stringify","name","parameters","input","generatedError","result","tool","output","StringToolOutput","error","find","ToolError","run","toolCallMsg","Tool","contextKeys","Memory","state","memory","e","FrameworkError","ensure","FinalAnswerToolSchema","z","object","response","string","describe","FinalAnswerTool","description","instructions","customSchema","emitter","expectedOutput","undefined","ZodSchema","Emitter","root","child","namespace","creator","inputSchema","_run","_options","_ctx","answer","AssistantMessage"],"mappings":";;;;;;;;;;;;AAmCA,eAAsBA,OAAAA,CACpBC,KAAAA,EACAC,GAAAA,EACAC,OAAAA,EAA4B;AAE5B,EAAA,IAAI,CAACC,yBAAAA,CAAgBF,GAAAA,CAAAA,EAAM;AACzB,IAAA,MAAM,IAAIG,iCAAAA,CAAuB,CAAA,MAAA,EAASH,IAAII,QAAQ,CAAA,iBAAA,CAAA,EAAqB,EAAA,EAAI;AAC7EC,MAAAA,gBAAAA,EAAkBC,KAAKC,SAAAA,CAAU;AAAEC,QAAAA,IAAAA,EAAMR,GAAAA,CAAII,QAAAA;AAAUK,QAAAA,UAAAA,EAAYT,GAAAA,CAAIU;OAAM,CAAA;MAC7EC,cAAAA,EAAgB;KAClB,CAAA;AACF;AAEA,EAAA,MAAMC,MAAAA,GAA+B;AACnCZ,IAAAA,GAAAA;IACAa,IAAAA,EAAM,IAAA;AACNH,IAAAA,KAAAA,EAAOV,GAAAA,CAAIU,KAAAA;IACXI,MAAAA,EAAQ,IAAIC,0BAAiB,EAAA,CAAA;IAC7BC,KAAAA,EAAO;AACT,GAAA;AAEA,EAAA,IAAI;AACFJ,IAAAA,MAAAA,CAAOC,IAAAA,GAAOd,MAAMkB,IAAAA,CAAK,CAACJ,SAASA,IAAAA,CAAKL,IAAAA,KAASR,GAAAA,CAAII,QAAQ,CAAA,IAAK,IAAA;AAClE,IAAA,IAAI,CAACQ,OAAOC,IAAAA,EAAM;AAChB,MAAA,MAAM,IAAIK,kBAAAA,CAAU,CAAA,MAAA,EAASlB,GAAAA,CAAII,QAAQ,CAAA,iBAAA,CAAmB,CAAA;AAC9D;AAEAQ,IAAAA,MAAAA,CAAOE,MAAAA,GAAS,MAAMF,MAAAA,CAAOC,IAAAA,CAAKM,IAAIP,MAAAA,CAAOF,KAAK,EAAET,O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ChCC,SAAAA,EAAW;AAAC,QAAA,MAAA;AAAQ,QAAA;;MACpBC,OAAAA,EAAS;KACX,CAAA;AACF;EAEAC,WAAAA,GAAyB;AACvB,IAAA,MAAMR,iBAAiB,IAAA,CAAKA,cAAAA;AAE5B,IAAA,IAAI,CAACA,cAAAA,EAAgB;AACnB,MAAA,OAAOX,qBAAAA;AACT,KAAA,MAAA,IAAWW,0BAA0BE,aAAAA,EAAW;AAC9C,MAAA,OAAOF,cAAAA;KACT,MAAA,IAAW,OAAOA,mBAAmB,QAAA,EAAU;AAC7C,MAAA,OAAOV,MAAEC,MAAAA,CAAO;AACdC,QAAAA,QAAAA,EAAUF,KAAAA,CAAEG,MAAAA,EAAM,CAAGC,QAAAA,CAASM,cAAAA;OAChC,CAAA;KACF,MAAO;AACL,MAAA,OAAOX,qBAAAA;AACT;AACF;EAEA,MAAMoB,IAAAA,CACJvC,KAAAA,EACAwC,QAAAA,EACAC,IAAAA,EAC2B;AAC3B,IAAA,IAAA,CAAK3B,MAAMZ,MAAAA,GAASF,KAAAA;AAEpB,IAAA,IAAI,IAAA,CAAK8B,0BAA0BE,aAAAA,EAAW;AAE5C,MAAA,IAAA,CAAKlB,MAAM4B,MAAAA,GAAS,IAAIC,6BAAiB/C,IAAAA,CAAKC,SAAAA,CAAUG,KAAAA,CAAAA,CAAAA;KAC1D,MAAO;AAEL,MAAA,IAAA,CAAKc,KAAAA,CAAM4B,MAAAA,GAAS,IAAIC,4BAAAA,CAAiB3C,MAAMsB,QAAQ,CAAA;AACzD;AAEA,IAAA,OAAO,IAAIjB,0BAAiB,uBAAA,CAAA;AAC9B;AACF","file":"tool.cjs","sourcesContent":["/**\n * Copyright 2025 © BeeAI a Series of LF Projects, LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n AnyTool,\n BaseToolRunOptions,\n StringToolOutput,\n Tool,\n ToolError,\n ToolOutput,\n} from \"@/tools/base.js\";\nimport { ToolCallPart } from \"ai\";\nimport { FrameworkError } from \"@/errors.js\";\nimport { Emitter } from \"@/emitter/emitter.js\";\nimport { z, ZodSchema } from \"zod\";\nimport { RequirementAgentRunState } from \"@/agents/requirement/types.js\";\nimport { AssistantMessage } from \"@/backend/message.js\";\nimport { RunContext } from \"@/context.js\";\nimport { isToolCallValid } from \"@/adapters/vercel/backend/utils.js\";\nimport { ChatModelToolCallError } from \"@/backend/errors.js\";\n\n// Tool invocation result\nexport interface ToolInvocationResult {\n msg: ToolCallPart;\n tool: AnyTool | null;\n input: unknown;\n output: ToolOutput;\n error: FrameworkError | null;\n}\n\n/**\n * Run a single tool with error handling\n */\nexport async function runTool(\n tools: AnyTool[],\n msg: ToolCallPart,\n context: Record<string, any>,\n): Promise<ToolInvocationResult> {\n if (!isToolCallValid(msg)) {\n throw new ChatModelToolCallError(`Tool '${msg.toolName}' does not exist!`, [], {\n generatedContent: JSON.stringify({ name: msg.toolName, parameters: msg.input }),\n generatedError: \"The generated tool call is invalid. Cannot parse the args.\",\n });\n }\n\n const result: ToolInvocationResult = {\n msg,\n tool: null,\n input: msg.input,\n output: new StringToolOutput(\"\"),\n error: null,\n };\n\n try {\n result.tool = tools.find((tool) => tool.name === msg.toolName) || null;\n if (!result.tool) {\n throw new ToolError(`Tool '${msg.toolName}' does not exist!`);\n }\n\n result.output = await result.tool.run(result.input).context({\n ...context,\n toolCallMsg: msg,\n [Tool.contextKeys.Memory]: context.state.memory,\n });\n } catch (e) {\n if (e instanceof ToolError) {\n result.error = FrameworkError.ensure(e);\n } else {\n throw e;\n }\n }\n\n return result;\n}\n\n// Final answer tool schema\nconst FinalAnswerToolSchema = z.object({\n response: z.string().describe(\"The final answer to the user\"),\n});\n\n/**\n * Special tool for capturing final answers\n */\nexport class FinalAnswerTool extends Tool {\n public readonly name = \"final_answer\";\n public readonly description = \"Sends the final answer to the user\";\n public instructions?: string;\n public customSchema: boolean;\n public readonly emitter: Emitter<any>;\n\n protected expectedOutput: string | ZodSchema | null;\n protected state: RequirementAgentRunState;\n\n constructor(expectedOutput: string | ZodSchema | null, state: RequirementAgentRunState) {\n super();\n this.expectedOutput = expectedOutput;\n this.state = state;\n this.instructions = typeof expectedOutput === \"string\" ? expectedOutput : undefined;\n this.customSchema = expectedOutput instanceof ZodSchema;\n this.emitter = Emitter.root.child({\n namespace: [\"tool\", \"final_answer\"],\n creator: this,\n });\n }\n\n inputSchema(): ZodSchema {\n const expectedOutput = this.expectedOutput;\n\n if (!expectedOutput) {\n return FinalAnswerToolSchema;\n } else if (expectedOutput instanceof ZodSchema) {\n return expectedOutput;\n } else if (typeof expectedOutput === \"string\") {\n return z.object({\n response: z.string().describe(expectedOutput),\n });\n } else {\n return FinalAnswerToolSchema;\n }\n }\n\n async _run(\n input: any,\n _options: BaseToolRunOptions,\n _ctx: RunContext<typeof this>,\n ): Promise<StringToolOutput> {\n this.state.result = input;\n\n if (this.expectedOutput instanceof ZodSchema) {\n // For custom schemas, serialize the entire input\n this.state.answer = new AssistantMessage(JSON.stringify(input));\n } else {\n // For string schemas, use the response field\n this.state.answer = new AssistantMessage(input.response);\n }\n\n return new StringToolOutput(\"Message has been sent\");\n }\n}\n"]}
@@ -1,9 +1,9 @@
1
1
  import '../../../tools/base.cjs';
2
2
  import 'ai';
3
3
  import '../../../errors.cjs';
4
- import '../../../emitter-jN55XZZq.cjs';
4
+ import '../../../emitter-UkIkNrek.cjs';
5
5
  import 'zod';
6
- export { F as FinalAnswerTool, T as ToolInvocationResult, r as runTool } from '../../../types-D9pn62yF.cjs';
6
+ export { F as FinalAnswerTool, T as ToolInvocationResult, r as runTool } from '../../../types-YoNQSxQH.cjs';
7
7
  import '../../../context.cjs';
8
8
  import 'ajv';
9
9
  import '../../../internals/serializable.cjs';
@@ -17,8 +17,8 @@ import '../../../internals/helpers/promise.cjs';
17
17
  import '../../../memory/base.cjs';
18
18
  import '../../../backend/message.cjs';
19
19
  import '../../../template.cjs';
20
- import '../../../chat-CC0s8z23.cjs';
20
+ import '../../../chat-DaqV3woF.cjs';
21
21
  import '../../../backend/constants.cjs';
22
22
  import '../../../logger/logger.cjs';
23
23
  import 'pino';
24
- import '../../../base-XfWeXQ-S.cjs';
24
+ import '../../../base-BqzN2QwB.cjs';
@@ -1,9 +1,9 @@
1
1
  import '../../../tools/base.js';
2
2
  import 'ai';
3
3
  import '../../../errors.js';
4
- import '../../../emitter-36-9MnvA.js';
4
+ import '../../../emitter-CL56qab4.js';
5
5
  import 'zod';
6
- export { F as FinalAnswerTool, T as ToolInvocationResult, r as runTool } from '../../../types-Dyd4e1G6.js';
6
+ export { F as FinalAnswerTool, T as ToolInvocationResult, r as runTool } from '../../../types-YT-WdK3m.js';
7
7
  import '../../../context.js';
8
8
  import 'ajv';
9
9
  import '../../../internals/serializable.js';
@@ -17,8 +17,8 @@ import '../../../internals/helpers/promise.js';
17
17
  import '../../../memory/base.js';
18
18
  import '../../../backend/message.js';
19
19
  import '../../../template.js';
20
- import '../../../chat-D8SVtw5Q.js';
20
+ import '../../../chat-DTxmaKP0.js';
21
21
  import '../../../backend/constants.js';
22
22
  import '../../../logger/logger.js';
23
23
  import 'pino';
24
- import '../../../base-CyFx7BRL.js';
24
+ import '../../../base-BfhNzUYf.js';
@@ -3,10 +3,21 @@ import { FrameworkError } from '../../../errors.js';
3
3
  import { Emitter } from '../../../emitter/emitter.js';
4
4
  import { z, ZodSchema } from 'zod';
5
5
  import { AssistantMessage } from '../../../backend/message.js';
6
+ import { isToolCallValid } from '../../../adapters/vercel/backend/utils.js';
7
+ import { ChatModelToolCallError } from '../../../backend/errors.js';
6
8
 
7
9
  var __defProp = Object.defineProperty;
8
10
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
11
  async function runTool(tools, msg, context) {
12
+ if (!isToolCallValid(msg)) {
13
+ throw new ChatModelToolCallError(`Tool '${msg.toolName}' does not exist!`, [], {
14
+ generatedContent: JSON.stringify({
15
+ name: msg.toolName,
16
+ parameters: msg.input
17
+ }),
18
+ generatedError: "The generated tool call is invalid. Cannot parse the args."
19
+ });
20
+ }
10
21
  const result = {
11
22
  msg,
12
23
  tool: null,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/agents/requirement/utils/tool.ts"],"names":["runTool","tools","msg","context","result","tool","input","output","StringToolOutput","error","find","name","toolName","ToolError","run","toolCallMsg","Tool","contextKeys","Memory","state","memory","e","FrameworkError","ensure","FinalAnswerToolSchema","z","object","response","string","describe","FinalAnswerTool","description","instructions","customSchema","emitter","expectedOutput","undefined","ZodSchema","Emitter","root","child","namespace","creator","inputSchema","_run","_options","_ctx","answer","AssistantMessage","JSON","stringify"],"mappings":";;;;;;;;AAiCA,eAAsBA,OAAAA,CACpBC,KAAAA,EACAC,GAAAA,EACAC,OAAAA,EAA4B;AAE5B,EAAA,MAAMC,MAAAA,GAA+B;AACnCF,IAAAA,GAAAA;IACAG,IAAAA,EAAM,IAAA;AACNC,IAAAA,KAAAA,EAAOJ,GAAAA,CAAII,KAAAA;IACXC,MAAAA,EAAQ,IAAIC,iBAAiB,EAAA,CAAA;IAC7BC,KAAAA,EAAO;AACT,GAAA;AAEA,EAAA,IAAI;AACFL,IAAAA,MAAAA,CAAOC,IAAAA,GAAOJ,MAAMS,IAAAA,CAAK,CAACL,SAASA,IAAAA,CAAKM,IAAAA,KAAST,GAAAA,CAAIU,QAAQ,CAAA,IAAK,IAAA;AAClE,IAAA,IAAI,CAACR,OAAOC,IAAAA,EAAM;AAChB,MAAA,MAAM,IAAIQ,SAAAA,CAAU,CAAA,MAAA,EAASX,GAAAA,CAAIU,QAAQ,CAAA,iBAAA,CAAmB,CAAA;AAC9D;AAEAR,IAAAA,MAAAA,CAAOG,MAAAA,GAAS,MAAMH,MAAAA,CAAOC,IAAAA,CAAKS,IAAIV,MAAAA,CAAOE,KAAK,EAAEH,OAAAA,CAAQ;MAC1D,GAAGA,OAAAA;MACHY,WAAAA,EAAab,GAAAA;AACb,MAAA,CAACc,IAAAA,CAAKC,WAAAA,CAAYC,MAAM,GAAGf,QAAQgB,KAAAA,CAAMC;KAC3C,C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AAE5B,IAAA,IAAI,CAACA,cAAAA,EAAgB;AACnB,MAAA,OAAOX,qBAAAA;AACT,KAAA,MAAA,IAAWW,0BAA0BE,SAAAA,EAAW;AAC9C,MAAA,OAAOF,cAAAA;KACT,MAAA,IAAW,OAAOA,mBAAmB,QAAA,EAAU;AAC7C,MAAA,OAAOV,EAAEC,MAAAA,CAAO;AACdC,QAAAA,QAAAA,EAAUF,CAAAA,CAAEG,MAAAA,EAAM,CAAGC,QAAAA,CAASM,cAAAA;OAChC,CAAA;KACF,MAAO;AACL,MAAA,OAAOX,qBAAAA;AACT;AACF;EAEA,MAAMoB,IAAAA,CACJtC,KAAAA,EACAuC,QAAAA,EACAC,IAAAA,EAC2B;AAC3B,IAAA,IAAA,CAAK3B,MAAMf,MAAAA,GAASE,KAAAA;AAEpB,IAAA,IAAI,IAAA,CAAK6B,0BAA0BE,SAAAA,EAAW;AAE5C,MAAA,IAAA,CAAKlB,MAAM4B,MAAAA,GAAS,IAAIC,iBAAiBC,IAAAA,CAAKC,SAAAA,CAAU5C,KAAAA,CAAAA,CAAAA;KAC1D,MAAO;AAEL,MAAA,IAAA,CAAKa,KAAAA,CAAM4B,MAAAA,GAAS,IAAIC,gBAAAA,CAAiB1C,MAAMqB,QAAQ,CAAA;AACzD;AAEA,IAAA,OAAO,IAAInB,iBAAiB,uBAAA,CAAA;AAC9B;AACF","file":"tool.js","sourcesContent":["/**\n * Copyright 2025 © BeeAI a Series of LF Projects, LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n AnyTool,\n BaseToolRunOptions,\n StringToolOutput,\n Tool,\n ToolError,\n ToolOutput,\n} from \"@/tools/base.js\";\nimport { ToolCallPart } from \"ai\";\nimport { FrameworkError } from \"@/errors.js\";\nimport { Emitter } from \"@/emitter/emitter.js\";\nimport { z, ZodSchema } from \"zod\";\nimport { RequirementAgentRunState } from \"@/agents/requirement/types.js\";\nimport { AssistantMessage } from \"@/backend/message.js\";\nimport { RunContext } from \"@/context.js\";\n\n// Tool invocation result\nexport interface ToolInvocationResult {\n msg: ToolCallPart;\n tool: AnyTool | null;\n input: unknown;\n output: ToolOutput;\n error: FrameworkError | null;\n}\n\n/**\n * Run a single tool with error handling\n */\nexport async function runTool(\n tools: AnyTool[],\n msg: ToolCallPart,\n context: Record<string, any>,\n): Promise<ToolInvocationResult> {\n const result: ToolInvocationResult = {\n msg,\n tool: null,\n input: msg.input,\n output: new StringToolOutput(\"\"),\n error: null,\n };\n\n try {\n result.tool = tools.find((tool) => tool.name === msg.toolName) || null;\n if (!result.tool) {\n throw new ToolError(`Tool '${msg.toolName}' does not exist!`);\n }\n\n result.output = await result.tool.run(result.input).context({\n ...context,\n toolCallMsg: msg,\n [Tool.contextKeys.Memory]: context.state.memory,\n });\n } catch (e) {\n if (e instanceof ToolError) {\n result.error = FrameworkError.ensure(e);\n } else {\n throw e;\n }\n }\n\n return result;\n}\n\n// Final answer tool schema\nconst FinalAnswerToolSchema = z.object({\n response: z.string().describe(\"The final answer to the user\"),\n});\n\n/**\n * Special tool for capturing final answers\n */\nexport class FinalAnswerTool extends Tool {\n public readonly name = \"final_answer\";\n public readonly description = \"Sends the final answer to the user\";\n public instructions?: string;\n public customSchema: boolean;\n public readonly emitter: Emitter<any>;\n\n protected expectedOutput: string | ZodSchema | null;\n protected state: RequirementAgentRunState;\n\n constructor(expectedOutput: string | ZodSchema | null, state: RequirementAgentRunState) {\n super();\n this.expectedOutput = expectedOutput;\n this.state = state;\n this.instructions = typeof expectedOutput === \"string\" ? expectedOutput : undefined;\n this.customSchema = expectedOutput instanceof ZodSchema;\n this.emitter = Emitter.root.child({\n namespace: [\"tool\", \"final_answer\"],\n creator: this,\n });\n }\n\n inputSchema(): ZodSchema {\n const expectedOutput = this.expectedOutput;\n\n if (!expectedOutput) {\n return FinalAnswerToolSchema;\n } else if (expectedOutput instanceof ZodSchema) {\n return expectedOutput;\n } else if (typeof expectedOutput === \"string\") {\n return z.object({\n response: z.string().describe(expectedOutput),\n });\n } else {\n return FinalAnswerToolSchema;\n }\n }\n\n async _run(\n input: any,\n _options: BaseToolRunOptions,\n _ctx: RunContext<typeof this>,\n ): Promise<StringToolOutput> {\n this.state.result = input;\n\n if (this.expectedOutput instanceof ZodSchema) {\n // For custom schemas, serialize the entire input\n this.state.answer = new AssistantMessage(JSON.stringify(input));\n } else {\n // For string schemas, use the response field\n this.state.answer = new AssistantMessage(input.response);\n }\n\n return new StringToolOutput(\"Message has been sent\");\n }\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/agents/requirement/utils/tool.ts"],"names":["runTool","tools","msg","context","isToolCallValid","ChatModelToolCallError","toolName","generatedContent","JSON","stringify","name","parameters","input","generatedError","result","tool","output","StringToolOutput","error","find","ToolError","run","toolCallMsg","Tool","contextKeys","Memory","state","memory","e","FrameworkError","ensure","FinalAnswerToolSchema","z","object","response","string","describe","FinalAnswerTool","description","instructions","customSchema","emitter","expectedOutput","undefined","ZodSchema","Emitter","root","child","namespace","creator","inputSchema","_run","_options","_ctx","answer","AssistantMessage"],"mappings":";;;;;;;;;;AAmCA,eAAsBA,OAAAA,CACpBC,KAAAA,EACAC,GAAAA,EACAC,OAAAA,EAA4B;AAE5B,EAAA,IAAI,CAACC,eAAAA,CAAgBF,GAAAA,CAAAA,EAAM;AACzB,IAAA,MAAM,IAAIG,sBAAAA,CAAuB,CAAA,MAAA,EAASH,IAAII,QAAQ,CAAA,iBAAA,CAAA,EAAqB,EAAA,EAAI;AAC7EC,MAAAA,gBAAAA,EAAkBC,KAAKC,SAAAA,CAAU;AAAEC,QAAAA,IAAAA,EAAMR,GAAAA,CAAII,QAAAA;AAAUK,QAAAA,UAAAA,EAAYT,GAAAA,CAAIU;OAAM,CAAA;MAC7EC,cAAAA,EAAgB;KAClB,CAAA;AACF;AAEA,EAAA,MAAMC,MAAAA,GAA+B;AACnCZ,IAAAA,GAAAA;IACAa,IAAAA,EAAM,IAAA;AACNH,IAAAA,KAAAA,EAAOV,GAAAA,CAAIU,KAAAA;IACXI,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A,CAAKlB,MAAM4B,MAAAA,GAAS,IAAIC,iBAAiB/C,IAAAA,CAAKC,SAAAA,CAAUG,KAAAA,CAAAA,CAAAA;KAC1D,MAAO;AAEL,MAAA,IAAA,CAAKc,KAAAA,CAAM4B,MAAAA,GAAS,IAAIC,gBAAAA,CAAiB3C,MAAMsB,QAAQ,CAAA;AACzD;AAEA,IAAA,OAAO,IAAIjB,iBAAiB,uBAAA,CAAA;AAC9B;AACF","file":"tool.js","sourcesContent":["/**\n * Copyright 2025 © BeeAI a Series of LF Projects, LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n AnyTool,\n BaseToolRunOptions,\n StringToolOutput,\n Tool,\n ToolError,\n ToolOutput,\n} from \"@/tools/base.js\";\nimport { ToolCallPart } from \"ai\";\nimport { FrameworkError } from \"@/errors.js\";\nimport { Emitter } from \"@/emitter/emitter.js\";\nimport { z, ZodSchema } from \"zod\";\nimport { RequirementAgentRunState } from \"@/agents/requirement/types.js\";\nimport { AssistantMessage } from \"@/backend/message.js\";\nimport { RunContext } from \"@/context.js\";\nimport { isToolCallValid } from \"@/adapters/vercel/backend/utils.js\";\nimport { ChatModelToolCallError } from \"@/backend/errors.js\";\n\n// Tool invocation result\nexport interface ToolInvocationResult {\n msg: ToolCallPart;\n tool: AnyTool | null;\n input: unknown;\n output: ToolOutput;\n error: FrameworkError | null;\n}\n\n/**\n * Run a single tool with error handling\n */\nexport async function runTool(\n tools: AnyTool[],\n msg: ToolCallPart,\n context: Record<string, any>,\n): Promise<ToolInvocationResult> {\n if (!isToolCallValid(msg)) {\n throw new ChatModelToolCallError(`Tool '${msg.toolName}' does not exist!`, [], {\n generatedContent: JSON.stringify({ name: msg.toolName, parameters: msg.input }),\n generatedError: \"The generated tool call is invalid. Cannot parse the args.\",\n });\n }\n\n const result: ToolInvocationResult = {\n msg,\n tool: null,\n input: msg.input,\n output: new StringToolOutput(\"\"),\n error: null,\n };\n\n try {\n result.tool = tools.find((tool) => tool.name === msg.toolName) || null;\n if (!result.tool) {\n throw new ToolError(`Tool '${msg.toolName}' does not exist!`);\n }\n\n result.output = await result.tool.run(result.input).context({\n ...context,\n toolCallMsg: msg,\n [Tool.contextKeys.Memory]: context.state.memory,\n });\n } catch (e) {\n if (e instanceof ToolError) {\n result.error = FrameworkError.ensure(e);\n } else {\n throw e;\n }\n }\n\n return result;\n}\n\n// Final answer tool schema\nconst FinalAnswerToolSchema = z.object({\n response: z.string().describe(\"The final answer to the user\"),\n});\n\n/**\n * Special tool for capturing final answers\n */\nexport class FinalAnswerTool extends Tool {\n public readonly name = \"final_answer\";\n public readonly description = \"Sends the final answer to the user\";\n public instructions?: string;\n public customSchema: boolean;\n public readonly emitter: Emitter<any>;\n\n protected expectedOutput: string | ZodSchema | null;\n protected state: RequirementAgentRunState;\n\n constructor(expectedOutput: string | ZodSchema | null, state: RequirementAgentRunState) {\n super();\n this.expectedOutput = expectedOutput;\n this.state = state;\n this.instructions = typeof expectedOutput === \"string\" ? expectedOutput : undefined;\n this.customSchema = expectedOutput instanceof ZodSchema;\n this.emitter = Emitter.root.child({\n namespace: [\"tool\", \"final_answer\"],\n creator: this,\n });\n }\n\n inputSchema(): ZodSchema {\n const expectedOutput = this.expectedOutput;\n\n if (!expectedOutput) {\n return FinalAnswerToolSchema;\n } else if (expectedOutput instanceof ZodSchema) {\n return expectedOutput;\n } else if (typeof expectedOutput === \"string\") {\n return z.object({\n response: z.string().describe(expectedOutput),\n });\n } else {\n return FinalAnswerToolSchema;\n }\n }\n\n async _run(\n input: any,\n _options: BaseToolRunOptions,\n _ctx: RunContext<typeof this>,\n ): Promise<StringToolOutput> {\n this.state.result = input;\n\n if (this.expectedOutput instanceof ZodSchema) {\n // For custom schemas, serialize the entire input\n this.state.answer = new AssistantMessage(JSON.stringify(input));\n } else {\n // For string schemas, use the response field\n this.state.answer = new AssistantMessage(input.response);\n }\n\n return new StringToolOutput(\"Message has been sent\");\n }\n}\n"]}
@@ -1,10 +1,10 @@
1
1
  import { GetRunContext, MiddlewareType } from '../../context.cjs';
2
- import { c as AgentMeta, a as BaseAgent } from '../../base-XfWeXQ-S.cjs';
2
+ import { c as AgentMeta, a as BaseAgent } from '../../base-BqzN2QwB.cjs';
3
3
  import { AnyTool } from '../../tools/base.cjs';
4
4
  import { BaseMemory } from '../../memory/base.cjs';
5
- import { E as Emitter } from '../../emitter-jN55XZZq.cjs';
5
+ import { E as Emitter } from '../../emitter-UkIkNrek.cjs';
6
6
  import { ToolCallingAgentTemplates, ToolCallingAgentExecutionConfig, ToolCallingAgentRunInput, ToolCallingAgentRunOutput, ToolCallingAgentRunOptions, ToolCallingAgentCallbacks } from './types.cjs';
7
- import { m as ChatModel } from '../../chat-CC0s8z23.cjs';
7
+ import { m as ChatModel } from '../../chat-DaqV3woF.cjs';
8
8
  import '../../internals/serializable.cjs';
9
9
  import '../../internals/types.cjs';
10
10
  import '../../internals/helpers/guards.cjs';
@@ -1,10 +1,10 @@
1
1
  import { GetRunContext, MiddlewareType } from '../../context.js';
2
- import { c as AgentMeta, a as BaseAgent } from '../../base-CyFx7BRL.js';
2
+ import { c as AgentMeta, a as BaseAgent } from '../../base-BfhNzUYf.js';
3
3
  import { AnyTool } from '../../tools/base.js';
4
4
  import { BaseMemory } from '../../memory/base.js';
5
- import { E as Emitter } from '../../emitter-36-9MnvA.js';
5
+ import { E as Emitter } from '../../emitter-CL56qab4.js';
6
6
  import { ToolCallingAgentTemplates, ToolCallingAgentExecutionConfig, ToolCallingAgentRunInput, ToolCallingAgentRunOutput, ToolCallingAgentRunOptions, ToolCallingAgentCallbacks } from './types.js';
7
- import { m as ChatModel } from '../../chat-D8SVtw5Q.js';
7
+ import { m as ChatModel } from '../../chat-DTxmaKP0.js';
8
8
  import '../../internals/serializable.js';
9
9
  import '../../internals/types.js';
10
10
  import '../../internals/helpers/guards.js';
@@ -1,6 +1,6 @@
1
1
  import { BaseMemory } from '../../memory/base.cjs';
2
2
  import { AssistantMessage } from '../../backend/message.cjs';
3
- import { C as Callback } from '../../emitter-jN55XZZq.cjs';
3
+ import { C as Callback } from '../../emitter-UkIkNrek.cjs';
4
4
  import { ToolCallingAgentSystemPrompt, ToolCallingAgentTaskPrompt } from './prompts.cjs';
5
5
  import { ZodSchema } from 'zod';
6
6
  import '../../errors.cjs';
@@ -1,6 +1,6 @@
1
1
  import { BaseMemory } from '../../memory/base.js';
2
2
  import { AssistantMessage } from '../../backend/message.js';
3
- import { C as Callback } from '../../emitter-36-9MnvA.js';
3
+ import { C as Callback } from '../../emitter-CL56qab4.js';
4
4
  import { ToolCallingAgentSystemPrompt, ToolCallingAgentTaskPrompt } from './prompts.js';
5
5
  import { ZodSchema } from 'zod';
6
6
  import '../../errors.js';
@@ -1,8 +1,8 @@
1
- export { e as AgentCallback, d as AgentCallbackValue, c as AgentMeta, b as AnyAgent, G as GetAgentInput, f as GetAgentOutput, I as InternalAgentCallbackValue, P as PublicAgentCallbackValue } from '../base-XfWeXQ-S.cjs';
1
+ export { e as AgentCallback, d as AgentCallbackValue, c as AgentMeta, b as AnyAgent, G as GetAgentInput, f as GetAgentOutput, I as InternalAgentCallbackValue, P as PublicAgentCallbackValue } from '../base-BqzN2QwB.cjs';
2
2
  import '../internals/types.cjs';
3
3
  import '../tools/base.cjs';
4
4
  import '../context.cjs';
5
- import '../emitter-jN55XZZq.cjs';
5
+ import '../emitter-UkIkNrek.cjs';
6
6
  import '../internals/serializable.cjs';
7
7
  import '../internals/helpers/guards.cjs';
8
8
  import '../internals/helpers/promise.cjs';
@@ -1,8 +1,8 @@
1
- export { e as AgentCallback, d as AgentCallbackValue, c as AgentMeta, b as AnyAgent, G as GetAgentInput, f as GetAgentOutput, I as InternalAgentCallbackValue, P as PublicAgentCallbackValue } from '../base-CyFx7BRL.js';
1
+ export { e as AgentCallback, d as AgentCallbackValue, c as AgentMeta, b as AnyAgent, G as GetAgentInput, f as GetAgentOutput, I as InternalAgentCallbackValue, P as PublicAgentCallbackValue } from '../base-BfhNzUYf.js';
2
2
  import '../internals/types.js';
3
3
  import '../tools/base.js';
4
4
  import '../context.js';
5
- import '../emitter-36-9MnvA.js';
5
+ import '../emitter-CL56qab4.js';
6
6
  import '../internals/serializable.js';
7
7
  import '../internals/helpers/guards.js';
8
8
  import '../internals/helpers/promise.js';
@@ -1,12 +1,12 @@
1
1
  import { Serializable } from '../internals/serializable.cjs';
2
- import { m as ChatModel, F as FullModelName } from '../chat-CC0s8z23.cjs';
2
+ import { m as ChatModel, F as FullModelName } from '../chat-DaqV3woF.cjs';
3
3
  import { EmbeddingModel } from './embedding.cjs';
4
4
  import { ProviderName } from './constants.cjs';
5
5
  import { OptionalExcept } from '../internals/types.cjs';
6
6
  import './message.cjs';
7
7
  import 'ai';
8
8
  import '../context.cjs';
9
- import '../emitter-jN55XZZq.cjs';
9
+ import '../emitter-UkIkNrek.cjs';
10
10
  import '../internals/helpers/promise.cjs';
11
11
  import '../errors.cjs';
12
12
  import 'promise-based-task';
@@ -1,12 +1,12 @@
1
1
  import { Serializable } from '../internals/serializable.js';
2
- import { m as ChatModel, F as FullModelName } from '../chat-D8SVtw5Q.js';
2
+ import { m as ChatModel, F as FullModelName } from '../chat-DTxmaKP0.js';
3
3
  import { EmbeddingModel } from './embedding.js';
4
4
  import { ProviderName } from './constants.js';
5
5
  import { OptionalExcept } from '../internals/types.js';
6
6
  import './message.js';
7
7
  import 'ai';
8
8
  import '../context.js';
9
- import '../emitter-36-9MnvA.js';
9
+ import '../emitter-CL56qab4.js';
10
10
  import '../internals/helpers/promise.js';
11
11
  import '../errors.js';
12
12
  import 'promise-based-task';
@@ -20,6 +20,7 @@ var template_cjs = require('../template.cjs');
20
20
  var promise_cjs = require('../internals/helpers/promise.cjs');
21
21
  var serializer_cjs = require('../serializer/serializer.cjs');
22
22
  var logger_cjs = require('../logger/logger.cjs');
23
+ var utils_cjs$2 = require('../adapters/vercel/backend/utils.cjs');
23
24
 
24
25
  var __defProp = Object.defineProperty;
25
26
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
@@ -41,6 +42,8 @@ class ChatModel extends serializable_cjs.Serializable {
41
42
  ];
42
43
  toolCallFallbackViaResponseFormat = true;
43
44
  modelSupportsToolCalling = true;
45
+ fixInvalidToolCalls = true;
46
+ retryOnEmptyResponse = true;
44
47
  create(input) {
45
48
  input = utils_cjs.shallowCopy(input);
46
49
  if (input.stream === void 0) {
@@ -64,56 +67,124 @@ class ChatModel extends serializable_cjs.Serializable {
64
67
  this.logger.warn(`The following tool choice value '${input.toolChoice}' is not supported. Ignoring.`);
65
68
  input.toolChoice = void 0;
66
69
  }
70
+ const modelInputMessagesBackup = input.messages.slice();
67
71
  const cacheEntry = await this.createCacheAccessor(input);
68
72
  try {
69
73
  await run.emitter.emit("start", {
70
74
  input
71
75
  });
72
- const chunks = [];
73
- const generator = cacheEntry.value ?? (input.stream ? this._createStream(input, run) : promise_cjs.toAsyncGenerator(this._create(input, run)));
74
- const controller = new AbortController();
75
- for await (const value of generator) {
76
- chunks.push(value);
77
- await run.emitter.emit("newToken", {
78
- value,
79
- callbacks: {
80
- abort: /* @__PURE__ */ __name(() => controller.abort(), "abort")
76
+ const result = await new retryable_cjs.Retryable({
77
+ executor: /* @__PURE__ */ __name(async () => {
78
+ const chunks = [];
79
+ const generator = cacheEntry.value ?? (input.stream ? this._createStream(input, run) : promise_cjs.toAsyncGenerator(this._create(input, run)));
80
+ const controller = new AbortController();
81
+ for await (const value of generator) {
82
+ chunks.push(value);
83
+ await run.emitter.emit("newToken", {
84
+ value,
85
+ callbacks: {
86
+ abort: /* @__PURE__ */ __name(() => controller.abort(), "abort")
87
+ }
88
+ });
89
+ if (controller.signal.aborted) {
90
+ break;
91
+ }
81
92
  }
82
- });
83
- if (controller.signal.aborted) {
84
- break;
85
- }
86
- }
87
- cacheEntry.resolve(chunks);
88
- const result = ChatModelOutput.fromChunks(chunks);
89
- for (const toolCall of result.getToolCalls()) {
90
- if (remeda.isString(toolCall.input)) {
91
- toolCall.input = JSON.parse(toolCall.input);
92
- }
93
- }
94
- if (forceToolCallViaResponseFormat && remeda.isEmpty(result.getToolCalls())) {
95
- const lastMsg = result.messages.at(-1);
96
- const toolCall = schema_cjs.parseBrokenJson(lastMsg.text, {
97
- pair: [
98
- "{",
99
- "}"
100
- ]
101
- });
102
- if (!toolCall || !toolCall.name || !toolCall.parameters) {
103
- throw new errors_cjs.ChatModelError(`Failed to produce a valid tool call. Generate output: ${lastMsg.text}`, [], {
104
- isFatal: true,
105
- isRetryable: false
106
- });
107
- }
108
- lastMsg.content.length = 0;
109
- lastMsg.content.push({
110
- type: "tool-call",
111
- toolCallId: `call_${remeda.randomString(8).toLowerCase()}`,
112
- toolName: toolCall.name,
113
- // todo: add types
114
- input: toolCall.parameters
115
- });
116
- }
93
+ const result2 = ChatModelOutput.fromChunks(chunks);
94
+ if (result2.isEmpty()) {
95
+ throw new errors_cjs.EmptyChatModelResponseError();
96
+ }
97
+ if (remeda.isEmpty(result2.getToolCalls()) && (forceToolCallViaResponseFormat || input.toolChoice === "required" || input.toolChoice instanceof base_cjs.Tool)) {
98
+ const lastMsg = result2.messages.at(-1);
99
+ let toolCall = schema_cjs.parseBrokenJson(lastMsg.text, {
100
+ pair: [
101
+ "{",
102
+ "}"
103
+ ]
104
+ });
105
+ if (toolCall && !toolCall.name && !toolCall.parameters && input.toolChoice instanceof base_cjs.Tool) {
106
+ toolCall = {
107
+ name: input.toolChoice.name,
108
+ parameters: toolCall
109
+ };
110
+ }
111
+ if (!toolCall || !toolCall.name || !toolCall.parameters) {
112
+ throw new errors_cjs.ChatModelToolCallError(`Failed to produce a valid tool call. Generate output: ${lastMsg.text}`, [], {
113
+ generatedContent: lastMsg.text,
114
+ generatedError: "Tool call was not produced.",
115
+ response: result2
116
+ });
117
+ }
118
+ lastMsg.content.length = 0;
119
+ lastMsg.content.push({
120
+ type: "tool-call",
121
+ toolCallId: `call_${remeda.randomString(8).toLowerCase()}`,
122
+ toolName: toolCall.name,
123
+ // todo: add types
124
+ input: toolCall.parameters
125
+ });
126
+ }
127
+ for (const toolCall of result2.getToolCalls()) {
128
+ const tool = input.tools?.find((t) => t.name === toolCall.toolName);
129
+ if (!tool) {
130
+ const availableTools = input.tools?.map((t) => t.name).join(",") || "None";
131
+ throw new errors_cjs.ChatModelToolCallError("Non existing tool call.", [], {
132
+ generatedError: `Error: Unknown tool '${toolCall.toolName}'.
133
+ Use on of the available tools: ${availableTools}`,
134
+ generatedContent: JSON.stringify({
135
+ name: toolCall.toolName,
136
+ input: remeda.isString(toolCall.input) ? toolCall.input : JSON.stringify(toolCall.input)
137
+ }),
138
+ response: result2
139
+ });
140
+ }
141
+ if (!utils_cjs$2.isToolCallValid(toolCall)) {
142
+ throw new errors_cjs.ChatModelToolCallError("Malformed tool call.", [], {
143
+ generatedContent: remeda.isString(toolCall.input) ? toolCall.input : JSON.stringify(toolCall.input),
144
+ generatedError: `The tool call for the '${toolCall.toolName}' tool has malformed parameters. It must be a valid JSON.`,
145
+ response: result2
146
+ });
147
+ }
148
+ if (remeda.isString(toolCall.input)) {
149
+ toolCall.input = JSON.parse(toolCall.input);
150
+ }
151
+ }
152
+ cacheEntry.resolve(chunks);
153
+ return result2;
154
+ }, "executor"),
155
+ config: {
156
+ maxRetries: input.maxRetries ?? 0
157
+ },
158
+ onRetry: /* @__PURE__ */ __name(async (_, lastError) => {
159
+ if (this.fixInvalidToolCalls && lastError instanceof errors_cjs.ChatModelToolCallError) {
160
+ input.messages = input.messages.slice();
161
+ if (lastError.data.generatedContent) {
162
+ input.messages.push(new message_cjs.AssistantMessage(lastError.data.generatedContent, {
163
+ tempMessage: true
164
+ }));
165
+ }
166
+ const toolNames = input.tools?.map((t) => t.name).join(", ") || "None";
167
+ input.messages.push(new message_cjs.UserMessage(`${lastError.data.generatedError}
168
+
169
+ Available Tools: ${toolNames}`, {
170
+ tempMessage: true
171
+ }));
172
+ } else if (this.retryOnEmptyResponse && lastError instanceof errors_cjs.EmptyChatModelResponseError) {
173
+ input.messages = input.messages.slice();
174
+ const lastMessage = input.messages.at(-1);
175
+ if (lastMessage && lastMessage instanceof message_cjs.AssistantMessage && lastMessage.meta["tempMessage"] && lastMessage.text === "") {
176
+ input.messages.push(new message_cjs.UserMessage("No output received. Please regenerate your previous response.", {
177
+ tempMessage: true
178
+ }));
179
+ } else {
180
+ input.messages.push(new message_cjs.AssistantMessage("", {
181
+ tempMessage: true
182
+ }));
183
+ }
184
+ }
185
+ }, "onRetry")
186
+ }).get();
187
+ input.messages = modelInputMessagesBackup;
117
188
  await run.emitter.emit("success", {
118
189
  value: result
119
190
  });
@@ -243,7 +314,9 @@ Validation Errors: {{errors}}`
243
314
  logger: this.logger,
244
315
  toolChoiceSupport: this.toolChoiceSupport.slice(),
245
316
  toolCallFallbackViaResponseFormat: this.toolCallFallbackViaResponseFormat,
246
- modelSupportsToolCalling: this.modelSupportsToolCalling
317
+ modelSupportsToolCalling: this.modelSupportsToolCalling,
318
+ retryOnEmptyResponse: this.retryOnEmptyResponse,
319
+ fixInvalidToolCalls: this.fixInvalidToolCalls
247
320
  };
248
321
  }
249
322
  destroy() {
@@ -303,6 +376,12 @@ class ChatModelOutput extends serializable_cjs.Serializable {
303
376
  chunks.forEach((cur) => final.merge(cur));
304
377
  return final;
305
378
  }
379
+ isEmpty() {
380
+ if (this.messages.length === 0) {
381
+ return true;
382
+ }
383
+ return this.getTextContent() === "" && this.getToolCalls().length === 0;
384
+ }
306
385
  merge(other) {
307
386
  if (other.messages.length > 0) {
308
387
  const clones = other.messages.map(cloneSync);