openloops 0.1.31 → 0.1.33

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 (252) hide show
  1. package/dist/clients/llm-client.d.ts +5 -0
  2. package/dist/clients/llm-client.js +73 -15
  3. package/dist/clients/llm-client.mjs +73 -15
  4. package/dist/clients/llm-error.d.ts +9 -0
  5. package/dist/clients/llm-error.js +69 -0
  6. package/dist/clients/llm-error.mjs +45 -0
  7. package/dist/clients/llm-types.d.ts +61 -0
  8. package/dist/clients/llm-types.js +16 -0
  9. package/dist/clients/llm-types.mjs +0 -0
  10. package/dist/clients/pi-ai-adapter.d.ts +7 -0
  11. package/dist/clients/pi-ai-adapter.js +137 -0
  12. package/dist/clients/pi-ai-adapter.mjs +113 -0
  13. package/dist/{agent → harness}/agent-loop.d.ts +11 -1
  14. package/dist/{agent → harness}/agent-state.js +1 -1
  15. package/dist/{agent → harness}/agent-state.mjs +1 -1
  16. package/dist/{agent → harness}/agent.d.ts +34 -3
  17. package/dist/harness/agent.js +546 -0
  18. package/dist/harness/agent.mjs +530 -0
  19. package/dist/{agent → harness}/index.js +5 -5
  20. package/dist/harness/native-tools.d.ts +23 -0
  21. package/dist/harness/native-tools.js +251 -0
  22. package/dist/harness/native-tools.mjs +227 -0
  23. package/dist/harness/tool-catalog.d.ts +16 -0
  24. package/dist/harness/tool-catalog.js +85 -0
  25. package/dist/harness/tool-catalog.mjs +59 -0
  26. package/dist/harness/tool-pipeline.d.ts +42 -0
  27. package/dist/harness/tool-pipeline.js +200 -0
  28. package/dist/harness/tool-pipeline.mjs +177 -0
  29. package/dist/harness/utils/describe-shape.d.ts +2 -0
  30. package/dist/harness/utils/describe-shape.js +56 -0
  31. package/dist/harness/utils/describe-shape.mjs +32 -0
  32. package/dist/harness/utils/grounding.d.ts +6 -0
  33. package/dist/harness/utils/grounding.js +79 -0
  34. package/dist/harness/utils/grounding.mjs +53 -0
  35. package/dist/harness/workspace.d.ts +44 -0
  36. package/dist/harness/workspace.js +95 -0
  37. package/dist/harness/workspace.mjs +78 -0
  38. package/dist/index.d.ts +1 -1
  39. package/dist/index.js +2 -2
  40. package/dist/index.mjs +1 -1
  41. package/dist/loops/agi/index.d.ts +1 -0
  42. package/dist/loops/agi/index.js +22 -0
  43. package/dist/loops/agi/index.mjs +1 -0
  44. package/dist/loops/agi/loop.d.ts +24 -0
  45. package/dist/loops/agi/loop.js +220 -0
  46. package/dist/loops/agi/loop.mjs +197 -0
  47. package/dist/loops/agi/skills/reasoning-engine.d.ts +14 -0
  48. package/dist/loops/agi/skills/reasoning-engine.js +94 -0
  49. package/dist/loops/agi/skills/reasoning-engine.mjs +71 -0
  50. package/dist/loops/index.d.ts +1 -0
  51. package/dist/loops/index.js +3 -1
  52. package/dist/loops/index.mjs +1 -0
  53. package/dist/loops/plan-execute/plan-execute-loop.d.ts +2 -1
  54. package/dist/loops/plan-execute/plan-execute-loop.js +90 -35
  55. package/dist/loops/plan-execute/plan-execute-loop.mjs +80 -25
  56. package/dist/loops/shared/skills/action-planner.js +7 -4
  57. package/dist/loops/shared/skills/action-planner.mjs +7 -4
  58. package/dist/loops/shared/skills/final-responder.js +4 -3
  59. package/dist/loops/shared/skills/final-responder.mjs +4 -3
  60. package/dist/loops/shared/skills/state-observer.js +6 -2
  61. package/dist/loops/shared/skills/state-observer.mjs +6 -2
  62. package/dist/services/chats/entities/chat-message.entity.d.ts +4 -1
  63. package/dist/services/chats/entities/chat-message.entity.js +7 -3
  64. package/dist/services/chats/entities/chat-message.entity.mjs +7 -3
  65. package/dist/services/chats/entities/chat.entity.d.ts +10 -11
  66. package/dist/services/chats/entities/chat.entity.js +17 -21
  67. package/dist/services/chats/entities/chat.entity.mjs +17 -21
  68. package/dist/services/chats/lambdas/get-chat-by-id/get-chat-by-id.use-case.d.ts +2 -0
  69. package/dist/services/chats/lambdas/get-chat-by-id/get-chat-by-id.use-case.js +4 -4
  70. package/dist/services/chats/lambdas/get-chat-by-id/get-chat-by-id.use-case.mjs +2 -2
  71. package/dist/services/tasks/entities/agent-action.entity.d.ts +111 -0
  72. package/dist/services/tasks/entities/agent-action.entity.js +271 -0
  73. package/dist/services/tasks/entities/agent-action.entity.mjs +247 -0
  74. package/dist/services/tasks/entities/agent-task.entity.d.ts +176 -0
  75. package/dist/services/tasks/entities/agent-task.entity.js +695 -0
  76. package/dist/services/tasks/entities/agent-task.entity.mjs +662 -0
  77. package/dist/services/tasks/entities/index.d.ts +2 -0
  78. package/dist/services/tasks/entities/index.js +24 -0
  79. package/dist/services/tasks/entities/index.mjs +2 -0
  80. package/dist/services/tasks/index.d.ts +3 -0
  81. package/dist/services/tasks/index.js +26 -0
  82. package/dist/services/tasks/index.mjs +3 -0
  83. package/dist/services/tasks/lambdas/create-agent-action/create-agent-action.use-case.d.ts +14 -0
  84. package/dist/services/tasks/lambdas/create-agent-action/create-agent-action.use-case.js +60 -0
  85. package/dist/services/tasks/lambdas/create-agent-action/create-agent-action.use-case.mjs +31 -0
  86. package/dist/services/tasks/lambdas/create-agent-action/index.d.ts +1 -0
  87. package/dist/services/tasks/lambdas/create-agent-action/index.js +22 -0
  88. package/dist/services/tasks/lambdas/create-agent-action/index.mjs +1 -0
  89. package/dist/services/tasks/lambdas/create-agent-task/create-agent-task.use-case.d.ts +14 -0
  90. package/dist/services/tasks/lambdas/create-agent-task/create-agent-task.use-case.js +60 -0
  91. package/dist/services/tasks/lambdas/create-agent-task/create-agent-task.use-case.mjs +31 -0
  92. package/dist/services/tasks/lambdas/create-agent-task/index.d.ts +1 -0
  93. package/dist/services/tasks/lambdas/create-agent-task/index.js +22 -0
  94. package/dist/services/tasks/lambdas/create-agent-task/index.mjs +1 -0
  95. package/dist/services/tasks/lambdas/get-agent-task-by-id/get-agent-task-by-id.use-case.d.ts +14 -0
  96. package/dist/services/tasks/lambdas/get-agent-task-by-id/get-agent-task-by-id.use-case.js +55 -0
  97. package/dist/services/tasks/lambdas/get-agent-task-by-id/get-agent-task-by-id.use-case.mjs +26 -0
  98. package/dist/services/tasks/lambdas/get-agent-task-by-id/index.d.ts +1 -0
  99. package/dist/services/tasks/lambdas/get-agent-task-by-id/index.js +22 -0
  100. package/dist/services/tasks/lambdas/get-agent-task-by-id/index.mjs +1 -0
  101. package/dist/services/tasks/lambdas/index.d.ts +7 -0
  102. package/dist/services/tasks/lambdas/index.js +46 -0
  103. package/dist/services/tasks/lambdas/index.mjs +17 -0
  104. package/dist/services/tasks/lambdas/list-agent-actions-by-task/index.d.ts +1 -0
  105. package/dist/services/tasks/lambdas/list-agent-actions-by-task/index.js +22 -0
  106. package/dist/services/tasks/lambdas/list-agent-actions-by-task/index.mjs +1 -0
  107. package/dist/services/tasks/lambdas/list-agent-actions-by-task/list-agent-actions-by-task.use-case.d.ts +16 -0
  108. package/dist/services/tasks/lambdas/list-agent-actions-by-task/list-agent-actions-by-task.use-case.js +62 -0
  109. package/dist/services/tasks/lambdas/list-agent-actions-by-task/list-agent-actions-by-task.use-case.mjs +33 -0
  110. package/dist/services/tasks/lambdas/list-agent-tasks-by-chat/index.d.ts +1 -0
  111. package/dist/services/tasks/lambdas/list-agent-tasks-by-chat/index.js +22 -0
  112. package/dist/services/tasks/lambdas/list-agent-tasks-by-chat/index.mjs +1 -0
  113. package/dist/services/tasks/lambdas/list-agent-tasks-by-chat/list-agent-tasks-by-chat.use-case.d.ts +16 -0
  114. package/dist/services/tasks/lambdas/list-agent-tasks-by-chat/list-agent-tasks-by-chat.use-case.js +62 -0
  115. package/dist/services/tasks/lambdas/list-agent-tasks-by-chat/list-agent-tasks-by-chat.use-case.mjs +33 -0
  116. package/dist/services/tasks/lambdas/update-agent-action/index.d.ts +1 -0
  117. package/dist/services/tasks/lambdas/update-agent-action/index.js +22 -0
  118. package/dist/services/tasks/lambdas/update-agent-action/index.mjs +1 -0
  119. package/dist/services/tasks/lambdas/update-agent-action/update-agent-action.use-case.d.ts +15 -0
  120. package/dist/services/tasks/lambdas/update-agent-action/update-agent-action.use-case.js +67 -0
  121. package/dist/services/tasks/lambdas/update-agent-action/update-agent-action.use-case.mjs +38 -0
  122. package/dist/services/tasks/lambdas/update-agent-task/index.d.ts +1 -0
  123. package/dist/services/tasks/lambdas/update-agent-task/index.js +22 -0
  124. package/dist/services/tasks/lambdas/update-agent-task/index.mjs +1 -0
  125. package/dist/services/tasks/lambdas/update-agent-task/update-agent-task.use-case.d.ts +15 -0
  126. package/dist/services/tasks/lambdas/update-agent-task/update-agent-task.use-case.js +67 -0
  127. package/dist/services/tasks/lambdas/update-agent-task/update-agent-task.use-case.mjs +38 -0
  128. package/dist/services/tasks/module.d.ts +15 -0
  129. package/dist/services/tasks/module.js +76 -0
  130. package/dist/services/tasks/module.mjs +47 -0
  131. package/dist/services/tasks/repositories/agent-action.repository.d.ts +8 -0
  132. package/dist/services/tasks/repositories/agent-action.repository.js +62 -0
  133. package/dist/services/tasks/repositories/agent-action.repository.mjs +33 -0
  134. package/dist/services/tasks/repositories/agent-task.repository.d.ts +9 -0
  135. package/dist/services/tasks/repositories/agent-task.repository.js +65 -0
  136. package/dist/services/tasks/repositories/agent-task.repository.mjs +36 -0
  137. package/dist/services/tasks/repositories/index.d.ts +2 -0
  138. package/dist/services/tasks/repositories/index.js +24 -0
  139. package/dist/services/tasks/repositories/index.mjs +2 -0
  140. package/dist/services/traces/entities/agent-trace-entry.entity.d.ts +30 -0
  141. package/dist/services/traces/entities/agent-trace-entry.entity.js +85 -0
  142. package/dist/services/traces/entities/agent-trace-entry.entity.mjs +62 -0
  143. package/dist/services/traces/entities/index.d.ts +1 -0
  144. package/dist/services/traces/entities/index.js +22 -0
  145. package/dist/services/traces/entities/index.mjs +1 -0
  146. package/dist/services/traces/index.d.ts +3 -0
  147. package/dist/services/traces/index.js +26 -0
  148. package/dist/services/traces/index.mjs +3 -0
  149. package/dist/services/traces/lambdas/create-agent-traces/create-agent-traces.use-case.d.ts +16 -0
  150. package/dist/services/traces/lambdas/create-agent-traces/create-agent-traces.use-case.js +62 -0
  151. package/dist/services/traces/lambdas/create-agent-traces/create-agent-traces.use-case.mjs +33 -0
  152. package/dist/services/traces/lambdas/create-agent-traces/index.d.ts +1 -0
  153. package/dist/services/traces/lambdas/create-agent-traces/index.js +22 -0
  154. package/dist/services/traces/lambdas/create-agent-traces/index.mjs +1 -0
  155. package/dist/services/traces/lambdas/index.d.ts +2 -0
  156. package/dist/services/traces/lambdas/index.js +31 -0
  157. package/dist/services/traces/lambdas/index.mjs +7 -0
  158. package/dist/services/traces/lambdas/list-agent-traces-by-chat/index.d.ts +1 -0
  159. package/dist/services/traces/lambdas/list-agent-traces-by-chat/index.js +22 -0
  160. package/dist/services/traces/lambdas/list-agent-traces-by-chat/index.mjs +1 -0
  161. package/dist/services/traces/lambdas/list-agent-traces-by-chat/list-agent-traces-by-chat.use-case.d.ts +18 -0
  162. package/dist/services/traces/lambdas/list-agent-traces-by-chat/list-agent-traces-by-chat.use-case.js +67 -0
  163. package/dist/services/traces/lambdas/list-agent-traces-by-chat/list-agent-traces-by-chat.use-case.mjs +38 -0
  164. package/dist/services/traces/module.d.ts +5 -0
  165. package/dist/services/traces/module.js +41 -0
  166. package/dist/services/traces/module.mjs +17 -0
  167. package/dist/services/traces/repositories/agent-trace.repository.d.ts +7 -0
  168. package/dist/services/traces/repositories/agent-trace.repository.js +55 -0
  169. package/dist/services/traces/repositories/agent-trace.repository.mjs +26 -0
  170. package/dist/services/traces/repositories/index.d.ts +1 -0
  171. package/dist/services/traces/repositories/index.js +22 -0
  172. package/dist/services/traces/repositories/index.mjs +1 -0
  173. package/dist/services/workspaces/entities/index.d.ts +1 -0
  174. package/dist/services/workspaces/entities/index.js +22 -0
  175. package/dist/services/workspaces/entities/index.mjs +1 -0
  176. package/dist/services/workspaces/entities/workspace-item.entity.d.ts +33 -0
  177. package/dist/services/workspaces/entities/workspace-item.entity.js +95 -0
  178. package/dist/services/workspaces/entities/workspace-item.entity.mjs +72 -0
  179. package/dist/services/workspaces/index.d.ts +3 -0
  180. package/dist/services/workspaces/index.js +26 -0
  181. package/dist/services/workspaces/index.mjs +3 -0
  182. package/dist/services/workspaces/lambdas/delete-workspace-item/delete-workspace-item.use-case.d.ts +17 -0
  183. package/dist/services/workspaces/lambdas/delete-workspace-item/delete-workspace-item.use-case.js +68 -0
  184. package/dist/services/workspaces/lambdas/delete-workspace-item/delete-workspace-item.use-case.mjs +39 -0
  185. package/dist/services/workspaces/lambdas/delete-workspace-item/index.d.ts +1 -0
  186. package/dist/services/workspaces/lambdas/delete-workspace-item/index.js +22 -0
  187. package/dist/services/workspaces/lambdas/delete-workspace-item/index.mjs +1 -0
  188. package/dist/services/workspaces/lambdas/get-workspace-item/get-workspace-item.use-case.d.ts +17 -0
  189. package/dist/services/workspaces/lambdas/get-workspace-item/get-workspace-item.use-case.js +67 -0
  190. package/dist/services/workspaces/lambdas/get-workspace-item/get-workspace-item.use-case.mjs +38 -0
  191. package/dist/services/workspaces/lambdas/get-workspace-item/index.d.ts +1 -0
  192. package/dist/services/workspaces/lambdas/get-workspace-item/index.js +22 -0
  193. package/dist/services/workspaces/lambdas/get-workspace-item/index.mjs +1 -0
  194. package/dist/services/workspaces/lambdas/index.d.ts +5 -0
  195. package/dist/services/workspaces/lambdas/index.js +40 -0
  196. package/dist/services/workspaces/lambdas/index.mjs +13 -0
  197. package/dist/services/workspaces/lambdas/list-workspace-items/index.d.ts +1 -0
  198. package/dist/services/workspaces/lambdas/list-workspace-items/index.js +22 -0
  199. package/dist/services/workspaces/lambdas/list-workspace-items/index.mjs +1 -0
  200. package/dist/services/workspaces/lambdas/list-workspace-items/list-workspace-items.use-case.d.ts +18 -0
  201. package/dist/services/workspaces/lambdas/list-workspace-items/list-workspace-items.use-case.js +69 -0
  202. package/dist/services/workspaces/lambdas/list-workspace-items/list-workspace-items.use-case.mjs +40 -0
  203. package/dist/services/workspaces/lambdas/save-workspace-item/index.d.ts +1 -0
  204. package/dist/services/workspaces/lambdas/save-workspace-item/index.js +22 -0
  205. package/dist/services/workspaces/lambdas/save-workspace-item/index.mjs +1 -0
  206. package/dist/services/workspaces/lambdas/save-workspace-item/save-workspace-item.use-case.d.ts +14 -0
  207. package/dist/services/workspaces/lambdas/save-workspace-item/save-workspace-item.use-case.js +76 -0
  208. package/dist/services/workspaces/lambdas/save-workspace-item/save-workspace-item.use-case.mjs +47 -0
  209. package/dist/services/workspaces/lambdas/search-workspace-items/index.d.ts +1 -0
  210. package/dist/services/workspaces/lambdas/search-workspace-items/index.js +22 -0
  211. package/dist/services/workspaces/lambdas/search-workspace-items/index.mjs +1 -0
  212. package/dist/services/workspaces/lambdas/search-workspace-items/search-workspace-items.use-case.d.ts +19 -0
  213. package/dist/services/workspaces/lambdas/search-workspace-items/search-workspace-items.use-case.js +73 -0
  214. package/dist/services/workspaces/lambdas/search-workspace-items/search-workspace-items.use-case.mjs +44 -0
  215. package/dist/services/workspaces/module.d.ts +11 -0
  216. package/dist/services/workspaces/module.js +62 -0
  217. package/dist/services/workspaces/module.mjs +35 -0
  218. package/dist/services/workspaces/repositories/index.d.ts +1 -0
  219. package/dist/services/workspaces/repositories/index.js +22 -0
  220. package/dist/services/workspaces/repositories/index.mjs +1 -0
  221. package/dist/services/workspaces/repositories/workspace-item.repository.d.ts +18 -0
  222. package/dist/services/workspaces/repositories/workspace-item.repository.js +74 -0
  223. package/dist/services/workspaces/repositories/workspace-item.repository.mjs +45 -0
  224. package/dist/skills/runtime-context.d.ts +8 -0
  225. package/dist/skills/runtime-context.js +65 -0
  226. package/dist/skills/runtime-context.mjs +42 -0
  227. package/dist/skills/skill.d.ts +7 -0
  228. package/dist/skills/skill.js +26 -60
  229. package/dist/skills/skill.mjs +26 -60
  230. package/dist/tools/tool.d.ts +6 -0
  231. package/dist/tools/tool.js +56 -0
  232. package/dist/tools/tool.mjs +56 -0
  233. package/package.json +3 -3
  234. package/dist/agent/agent.js +0 -327
  235. package/dist/agent/agent.mjs +0 -303
  236. package/dist/services/chats/entities/agent-action.entity.d.ts +0 -58
  237. package/dist/services/chats/entities/agent-action.entity.js +0 -151
  238. package/dist/services/chats/entities/agent-action.entity.mjs +0 -128
  239. package/dist/services/chats/entities/agent-task.entity.d.ts +0 -59
  240. package/dist/services/chats/entities/agent-task.entity.js +0 -231
  241. package/dist/services/chats/entities/agent-task.entity.mjs +0 -207
  242. package/dist/services/chats/entities/chat-context.entity.d.ts +0 -39
  243. package/dist/services/chats/entities/chat-context.entity.js +0 -70
  244. package/dist/services/chats/entities/chat-context.entity.mjs +0 -47
  245. /package/dist/{agent → harness}/agent-loop.js +0 -0
  246. /package/dist/{agent → harness}/agent-loop.mjs +0 -0
  247. /package/dist/{agent → harness}/agent-state.d.ts +0 -0
  248. /package/dist/{agent → harness}/index.d.ts +0 -0
  249. /package/dist/{agent → harness}/index.mjs +0 -0
  250. /package/dist/{agent → harness}/utils/rank-tools-by-keywords.d.ts +0 -0
  251. /package/dist/{agent → harness}/utils/rank-tools-by-keywords.js +0 -0
  252. /package/dist/{agent → harness}/utils/rank-tools-by-keywords.mjs +0 -0
@@ -0,0 +1,662 @@
1
+ import "../../../chunk-CF3WOMB3.mjs";
2
+ import { ObjectId } from "mongodb";
3
+ import { BaseEntity } from "../../../common/base/base.entity.js";
4
+ import { AgentAction, truncateForPrompt } from "./agent-action.entity";
5
+ var TaskStatus = /* @__PURE__ */ ((TaskStatus2) => {
6
+ TaskStatus2["PENDING"] = "pending";
7
+ TaskStatus2["IN_PROGRESS"] = "in_progress";
8
+ TaskStatus2["AWAITING_USER"] = "awaiting_user";
9
+ TaskStatus2["COMPLETED"] = "completed";
10
+ TaskStatus2["PAUSED"] = "paused";
11
+ TaskStatus2["ABANDONED"] = "abandoned";
12
+ TaskStatus2["CANCELLED"] = "cancelled";
13
+ TaskStatus2["FAILED"] = "failed";
14
+ return TaskStatus2;
15
+ })(TaskStatus || {});
16
+ const ASK_USER = "ask_user";
17
+ const SEARCH_TOOLS = "search_tools";
18
+ const RESPOND = "respond";
19
+ const NATIVE_TOOL_NAMES = [SEARCH_TOOLS, "read_context", "save_context", ASK_USER, RESPOND];
20
+ const TOOL_NAMESPACE = /^functions\./;
21
+ const INVALID_RESPONSE = "invalid_response";
22
+ const INVALID_ACTION = "invalid_action";
23
+ const STATE_KEYS = 12;
24
+ const KNOWN_ENTRIES = 40;
25
+ const KNOWN_KEY_CHARS = 80;
26
+ const KNOWN_VALUE_CHARS = 300;
27
+ const SCHEMA_TOOLS = 30;
28
+ const SCHEMA_PROPERTIES = 15;
29
+ const SCHEMA_SCAN_NODES = 2e4;
30
+ const SCHEMA_SCAN_DEPTH = 8;
31
+ const STATE_VALUE_CHARS = 800;
32
+ const REASONING_CHARS = 1500;
33
+ const TOOL_RESULT_CHARS = 1e5;
34
+ const FULL_OBSERVATION_TURNS = 1;
35
+ const PATH = "((?:\\.[\\w-]+|\\[\\d+\\])*)";
36
+ const STEP_REF = new RegExp(`^\\{\\{step_([\\w-]+)\\.output${PATH}\\}\\}$`);
37
+ const STEP_REF_GLOBAL = new RegExp(`\\{\\{step_([\\w-]+)\\.output${PATH}\\}\\}`, "g");
38
+ const CONTEXT_REF = new RegExp(`^\\{\\{context\\.([\\w-]+)${PATH}\\}\\}$`);
39
+ const CONTEXT_REF_GLOBAL = new RegExp(`\\{\\{context\\.([\\w-]+)${PATH}\\}\\}`, "g");
40
+ const LEFTOVER_REF = /\{\{\s*(?:step_|context\.)/;
41
+ const CLEARABLE_FIELDS = ["nextNode", "scratch"];
42
+ function normalizeToolName(name) {
43
+ return name.toLowerCase().replace(/-/g, "_");
44
+ }
45
+ function resolveToolName(name, declared) {
46
+ if (declared.includes(name)) return void 0;
47
+ const wanted = normalizeToolName(name);
48
+ const unique = (candidates) => candidates.length === 1 ? candidates[0] : void 0;
49
+ const sameName = unique(declared.filter((candidate) => normalizeToolName(candidate) === wanted));
50
+ if (sameName) return sameName;
51
+ const withoutPrefix = unique(declared.filter((candidate) => candidate.includes("__") && normalizeToolName(candidate).endsWith(`__${wanted}`)));
52
+ if (withoutPrefix) return withoutPrefix;
53
+ const separator = name.indexOf("__");
54
+ if (separator <= 0) return void 0;
55
+ const rest = normalizeToolName(name.slice(separator + 2));
56
+ return unique(declared.filter((candidate) => !candidate.includes("__") && normalizeToolName(candidate) === rest));
57
+ }
58
+ function findInvoker(tools) {
59
+ const invokers = tools.filter((tool) => tool.name.endsWith("__invoke_tool") && tool.parameters?.properties?.name && tool.parameters?.properties?.arguments);
60
+ return invokers.length === 1 ? invokers[0].name : void 0;
61
+ }
62
+ function seenHiddenTool(written, invoker, schemas) {
63
+ if (!schemas) return void 0;
64
+ const separator = written.indexOf("__");
65
+ const namespace = invoker.slice(0, invoker.indexOf("__"));
66
+ if (separator > 0 && normalizeToolName(written.slice(0, separator)) !== normalizeToolName(namespace)) return void 0;
67
+ const bare = normalizeToolName(separator > 0 ? written.slice(separator + 2) : written);
68
+ return Object.keys(schemas).find((key) => normalizeToolName(key) === bare);
69
+ }
70
+ function routeNote(action) {
71
+ if (!action.requestedName) return void 0;
72
+ return action.name?.endsWith("__invoke_tool") && action.args?.name && !/(^|__)invoke_tool$/.test(action.requestedName) ? `"${action.requestedName}" is a hidden tool and cannot be called directly, so it ran through "${action.name}" as "${action.args?.name}". Call hidden tools like that from now on: tool "${action.name}", arguments {"name": "${action.args?.name}", "arguments": {...}}, with the name written without the server prefix.` : `You wrote "${action.requestedName}" but the tool is named "${action.name}": the server prefix is part of the name. It ran as "${action.name}". Write the full name next time.`;
73
+ }
74
+ function propertyLabel(name, property) {
75
+ const type = Array.isArray(property?.type) ? property.type.join("|") : property?.type ?? property?.anyOf?.map((option) => option?.type).filter((option) => option && option !== "null").join("|");
76
+ return type ? `${name} (${type})` : name;
77
+ }
78
+ function summarizeSchema(schema) {
79
+ const properties = schema?.properties;
80
+ if (!properties || typeof properties !== "object" || Array.isArray(properties)) return void 0;
81
+ const required = Array.isArray(schema.required) ? schema.required.filter((name) => typeof name === "string") : [];
82
+ const names = Object.keys(properties);
83
+ return {
84
+ required: required.slice(0, SCHEMA_PROPERTIES).map((name) => propertyLabel(name, properties[name])),
85
+ optional: names.filter((name) => !required.includes(name)).slice(0, SCHEMA_PROPERTIES).map((name) => propertyLabel(name, properties[name]))
86
+ };
87
+ }
88
+ function findToolSchemas(value) {
89
+ const found = {};
90
+ let nodes = 0;
91
+ const visit = (node, depth) => {
92
+ if (node === null || typeof node !== "object" || depth > SCHEMA_SCAN_DEPTH || nodes++ > SCHEMA_SCAN_NODES) return;
93
+ if (Array.isArray(node)) {
94
+ node.forEach((item) => visit(item, depth + 1));
95
+ return;
96
+ }
97
+ const schema = node.input_schema ?? node.inputSchema;
98
+ if (typeof node.name === "string" && schema && typeof schema === "object") {
99
+ const summary = summarizeSchema(schema);
100
+ if (summary) found[node.name] = summary;
101
+ }
102
+ Object.values(node).forEach((child) => visit(child, depth + 1));
103
+ };
104
+ visit(value, 0);
105
+ return found;
106
+ }
107
+ function isNativeTool(name) {
108
+ return NATIVE_TOOL_NAMES.includes(name);
109
+ }
110
+ function capState(state) {
111
+ if (!state || typeof state !== "object" || Array.isArray(state)) return void 0;
112
+ const capped = {};
113
+ for (const key of Object.keys(state).slice(0, STATE_KEYS)) {
114
+ capped[key] = truncateForPrompt(state[key], STATE_VALUE_CHARS);
115
+ }
116
+ return capped;
117
+ }
118
+ function parseArguments(value) {
119
+ let args = value;
120
+ if (typeof args === "string") {
121
+ try {
122
+ args = JSON.parse(args);
123
+ } catch {
124
+ return { args: {}, invalid: '"arguments" must be a JSON object' };
125
+ }
126
+ }
127
+ if (args === void 0 || args === null) return { args: {} };
128
+ if (typeof args !== "object" || Array.isArray(args)) return { args: {}, invalid: '"arguments" must be a JSON object' };
129
+ return { args };
130
+ }
131
+ function stringifyValue(value) {
132
+ return typeof value === "object" ? JSON.stringify(value) : String(value);
133
+ }
134
+ function stableStringify(value) {
135
+ if (Array.isArray(value)) return `[${value.map(stableStringify).join(",")}]`;
136
+ if (value !== null && typeof value === "object") return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${stableStringify(value[key])}`).join(",")}}`;
137
+ return JSON.stringify(value) ?? "null";
138
+ }
139
+ function readPath(value, path) {
140
+ if (!path) return value;
141
+ const segments = /\.([\w-]+)|\[(\d+)\]/g;
142
+ let current = value;
143
+ let match;
144
+ while ((match = segments.exec(path)) !== null) {
145
+ if (current === null || current === void 0) return void 0;
146
+ current = current[match[1] ?? match[2]];
147
+ }
148
+ return current;
149
+ }
150
+ function scopeStepRefs(value, scope) {
151
+ if (typeof value === "string") {
152
+ return value.replace(/\{\{step_([\w-]+)(?=\.output)/g, (match, id) => {
153
+ const scoped = scope(id);
154
+ return scoped ? `{{step_${scoped}` : match;
155
+ });
156
+ }
157
+ if (Array.isArray(value)) return value.map((item) => scopeStepRefs(item, scope));
158
+ if (value !== null && typeof value === "object") {
159
+ const scoped = {};
160
+ for (const key of Object.keys(value)) scoped[key] = scopeStepRefs(value[key], scope);
161
+ return scoped;
162
+ }
163
+ return value;
164
+ }
165
+ function collectRefs(value, found = { steps: [], contexts: [] }) {
166
+ if (typeof value === "string") {
167
+ for (const match of value.matchAll(STEP_REF_GLOBAL)) found.steps.push(match[1]);
168
+ for (const match of value.matchAll(CONTEXT_REF_GLOBAL)) found.contexts.push(match[1]);
169
+ return found;
170
+ }
171
+ if (Array.isArray(value)) {
172
+ value.forEach((item) => collectRefs(item, found));
173
+ return found;
174
+ }
175
+ if (value !== null && typeof value === "object") {
176
+ Object.keys(value).forEach((key) => collectRefs(value[key], found));
177
+ }
178
+ return found;
179
+ }
180
+ class AgentTask extends BaseEntity {
181
+ constructor(props, chatId, status, goal, nextNode, threadId, previousTaskId, summary, loopName, planCount = 0, planOffset = 0, executedOffset = 0, scratch, opening, turns = [], known, schemas) {
182
+ super(props);
183
+ this.props = props;
184
+ this.chatId = chatId;
185
+ this.status = status;
186
+ this.goal = goal;
187
+ this.nextNode = nextNode;
188
+ this.threadId = threadId;
189
+ this.previousTaskId = previousTaskId;
190
+ this.summary = summary;
191
+ this.loopName = loopName;
192
+ this.planCount = planCount;
193
+ this.planOffset = planOffset;
194
+ this.executedOffset = executedOffset;
195
+ this.scratch = scratch;
196
+ this.opening = opening;
197
+ this.turns = turns;
198
+ this.known = known;
199
+ this.schemas = schemas;
200
+ }
201
+ props;
202
+ chatId;
203
+ status;
204
+ goal;
205
+ nextNode;
206
+ threadId;
207
+ previousTaskId;
208
+ summary;
209
+ loopName;
210
+ planCount;
211
+ planOffset;
212
+ executedOffset;
213
+ scratch;
214
+ opening;
215
+ turns;
216
+ known;
217
+ schemas;
218
+ static factory(task) {
219
+ const taskId = task._id && ObjectId.isValid(task._id) ? new ObjectId(task._id) : new ObjectId();
220
+ return AgentTask.fromJSON({
221
+ ...task,
222
+ _id: taskId,
223
+ status: task.status ?? "in_progress" /* IN_PROGRESS */
224
+ });
225
+ }
226
+ static fromJSON(props) {
227
+ return new AgentTask(
228
+ props,
229
+ BaseEntity.toObjectId(props.chatId),
230
+ props.status,
231
+ props.goal,
232
+ props.nextNode,
233
+ props.threadId,
234
+ props.previousTaskId,
235
+ props.summary,
236
+ props.loopName,
237
+ props.planCount ?? 0,
238
+ props.planOffset ?? 0,
239
+ props.executedOffset ?? 0,
240
+ props.scratch,
241
+ props.opening,
242
+ props.turns ?? [],
243
+ props.known,
244
+ props.schemas
245
+ );
246
+ }
247
+ static collectRefs(value) {
248
+ return collectRefs(value);
249
+ }
250
+ actions = [];
251
+ hydrated = true;
252
+ toJSON() {
253
+ return {
254
+ ...super.toJSON(),
255
+ chatId: this.chatId,
256
+ status: this.status,
257
+ goal: this.goal,
258
+ nextNode: this.nextNode,
259
+ threadId: this.threadId,
260
+ previousTaskId: this.previousTaskId,
261
+ summary: this.summary,
262
+ loopName: this.loopName,
263
+ planCount: this.planCount,
264
+ planOffset: this.planOffset,
265
+ executedOffset: this.executedOffset,
266
+ scratch: this.scratch,
267
+ opening: this.opening,
268
+ turns: this.turns.length ? this.turns : void 0,
269
+ known: this.known && Object.keys(this.known).length ? this.known : void 0,
270
+ schemas: this.schemas && Object.keys(this.schemas).length ? this.schemas : void 0
271
+ };
272
+ }
273
+ get id() {
274
+ return this._id.toString();
275
+ }
276
+ get clearedFields() {
277
+ return CLEARABLE_FIELDS.reduce((acc, field) => {
278
+ if (this[field] === void 0) acc[field] = "";
279
+ return acc;
280
+ }, {});
281
+ }
282
+ setActions(actions) {
283
+ this.actions = actions;
284
+ this.hydrated = true;
285
+ }
286
+ setScratch(key, value) {
287
+ this.scratch = { ...this.scratch, [key]: value };
288
+ }
289
+ getScratch(key) {
290
+ return this.scratch?.[key];
291
+ }
292
+ clearScratch(key) {
293
+ if (!this.scratch || !(key in this.scratch)) return;
294
+ const rest = { ...this.scratch };
295
+ delete rest[key];
296
+ this.scratch = Object.keys(rest).length ? rest : void 0;
297
+ }
298
+ addAction(descriptor) {
299
+ const action = AgentAction.factory({
300
+ chatId: this.chatId,
301
+ taskId: this._id,
302
+ name: descriptor.name,
303
+ stepId: descriptor.stepId,
304
+ args: descriptor.args,
305
+ dependsOn: descriptor.dependsOn,
306
+ reasoning: descriptor.reasoning,
307
+ author: descriptor.author,
308
+ callId: descriptor.callId,
309
+ turn: descriptor.turn,
310
+ requestedName: descriptor.requestedName
311
+ });
312
+ this.actions.push(action);
313
+ return action;
314
+ }
315
+ addPlan(steps, author) {
316
+ this.skipPending();
317
+ this.planCount += 1;
318
+ const generation = this.planCount;
319
+ const localIds = new Set(steps.map((step) => String(step.stepId)));
320
+ const scopedId = (id) => `${generation}_${id}`;
321
+ const scope = (id) => localIds.has(id) ? scopedId(id) : void 0;
322
+ return steps.map((step) => this.addAction({
323
+ name: step.name,
324
+ stepId: scopedId(step.stepId),
325
+ args: scopeStepRefs(step.args, scope),
326
+ dependsOn: step.dependsOn?.map(String).map((id) => scope(id) ?? id),
327
+ reasoning: step.reasoning,
328
+ author
329
+ }));
330
+ }
331
+ skipPending() {
332
+ const pending = this.actions.filter((a) => a.status === "pending");
333
+ pending.forEach((a) => a.markSkipped());
334
+ return pending.length;
335
+ }
336
+ approvePending() {
337
+ const pending = this.actions.filter((a) => a.status === "pending");
338
+ pending.forEach((a) => a.approve());
339
+ return pending.length;
340
+ }
341
+ getAction(ref) {
342
+ return this.actions.find((a) => a.id === ref || a.stepId === ref);
343
+ }
344
+ findLastByName(name) {
345
+ return this.actions.slice().reverse().find((a) => a.name === name);
346
+ }
347
+ findExecuted(name, args, opts) {
348
+ const signature = stableStringify(args ?? {});
349
+ return this.actions.find((a) => {
350
+ if (a === opts?.exclude || !a.isTerminal || a.name !== name) return false;
351
+ if (opts?.status && a.status !== opts.status) return false;
352
+ return stableStringify(a.args ?? {}) === signature;
353
+ });
354
+ }
355
+ hasExecuted(name, args) {
356
+ return Boolean(this.findExecuted(name, args));
357
+ }
358
+ get readyActions() {
359
+ const completedRefs = new Set(
360
+ this.actions.filter((a) => a.status === "completed").flatMap((a) => [a.id, a.stepId].filter(Boolean))
361
+ );
362
+ return this.actions.filter((a) => a.isReady && a.name !== ASK_USER && a.name !== RESPOND && a.dependenciesSatisfiedBy(completedRefs));
363
+ }
364
+ get pendingQuestion() {
365
+ const ask = this.actions.find((a) => a.name === ASK_USER && a.status === "pending");
366
+ return ask ? String(ask.args?.question ?? "") : void 0;
367
+ }
368
+ get turnCount() {
369
+ return this.turns.length;
370
+ }
371
+ get toolCallCount() {
372
+ return this.actions.filter((a) => a.turn !== void 0 && a.isTerminal && a.name !== ASK_USER && a.name !== RESPOND).length;
373
+ }
374
+ answerQuestion(answer) {
375
+ const ask = this.actions.find((a) => a.name === ASK_USER && a.status === "pending");
376
+ if (!ask) return false;
377
+ ask.markCompleted({ answer });
378
+ this.remember([{ key: `user_answer_${ask.stepId ?? ask.id}`, value: `${answer} | in answer to: ${String(ask.args?.question ?? "")}` }]);
379
+ return true;
380
+ }
381
+ get state() {
382
+ return this.turns.length ? this.turns[this.turns.length - 1].state : void 0;
383
+ }
384
+ get pendingAnswer() {
385
+ const respond = this.actions.find((a) => a.name === RESPOND && a.status === "pending");
386
+ return respond ? String(respond.args?.answer ?? "") : void 0;
387
+ }
388
+ get rejectedAnswers() {
389
+ return this.actions.filter((a) => a.name === RESPOND && a.status === "failed").length;
390
+ }
391
+ rejectAnswer(message) {
392
+ this.actions.find((a) => a.name === RESPOND && a.status === "pending")?.markFailed({ message, retryable: false });
393
+ }
394
+ forceAnswer(fallback) {
395
+ const answer = this.pendingAnswer || fallback;
396
+ this.skipPending();
397
+ return answer;
398
+ }
399
+ static answerFrom(output) {
400
+ const respond = (Array.isArray(output.actions) ? output.actions : []).find((request) => request?.tool === RESPOND);
401
+ const { args } = parseArguments(respond?.arguments);
402
+ const answer = String(args.answer ?? "").trim();
403
+ return answer || void 0;
404
+ }
405
+ deliverAnswer() {
406
+ this.actions.filter((a) => a.name === RESPOND && a.status === "pending").forEach((a) => a.markCompleted({ delivered: true }));
407
+ }
408
+ remember(learned) {
409
+ if (!Array.isArray(learned)) return;
410
+ const known = { ...this.known };
411
+ for (const item of learned) {
412
+ const key = typeof item?.key === "string" ? item.key.trim().slice(0, KNOWN_KEY_CHARS) : "";
413
+ const value = item?.value === void 0 || item?.value === null ? "" : stringifyValue(item.value).trim().slice(0, KNOWN_VALUE_CHARS);
414
+ if (!key || !value) continue;
415
+ const existing = Object.keys(known).find((candidate) => candidate.toLowerCase() === key.toLowerCase());
416
+ if (existing) delete known[existing];
417
+ known[key] = value;
418
+ }
419
+ const keys = Object.keys(known);
420
+ for (const key of keys.slice(0, Math.max(0, keys.length - KNOWN_ENTRIES))) delete known[key];
421
+ this.known = Object.keys(known).length ? known : void 0;
422
+ }
423
+ learnSchemas(output) {
424
+ const found = findToolSchemas(output);
425
+ const names = Object.keys(found);
426
+ if (!names.length) return;
427
+ const schemas = { ...this.schemas };
428
+ for (const name of names) {
429
+ delete schemas[name];
430
+ schemas[name] = found[name];
431
+ }
432
+ const keys = Object.keys(schemas);
433
+ for (const key of keys.slice(0, Math.max(0, keys.length - SCHEMA_TOOLS))) delete schemas[key];
434
+ this.schemas = schemas;
435
+ }
436
+ addTurn(output, opts) {
437
+ const turn = this.turns.reduce((max, t) => Math.max(max, t.turn), 0) + 1;
438
+ this.remember(output.learned);
439
+ this.turns.push({ turn, reasoning: output.reasoning?.toString().trim().slice(0, REASONING_CHARS) || void 0, state: capState(output.state) });
440
+ const requests = Array.isArray(output.actions) ? output.actions : [];
441
+ if (!requests.length) {
442
+ const action = this.addAction({ name: INVALID_RESPONSE, args: {}, stepId: `${turn}_1`, turn, author: opts?.author });
443
+ action.markFailed({ message: "Your response had no actions. Return at least one action; to finish the task use the respond tool with your final answer.", retryable: false });
444
+ return [action];
445
+ }
446
+ return requests.map((request, position) => {
447
+ const written = typeof request?.tool === "string" && request.tool.trim() ? request.tool.trim().replace(TOOL_NAMESPACE, "") : void 0;
448
+ const resolved = written && opts?.declaredTools ? resolveToolName(written, opts.declaredTools) : void 0;
449
+ const { args: given, invalid: badArguments } = parseArguments(request?.arguments);
450
+ const hiddenName = !resolved && written && opts?.invoker && opts.declaredTools && !opts.declaredTools.includes(written) && !NATIVE_TOOL_NAMES.includes(written) && !badArguments ? seenHiddenTool(written, opts.invoker, this.schemas) : void 0;
451
+ const hidden = Boolean(hiddenName);
452
+ const name = hidden ? opts.invoker : resolved ?? written;
453
+ const args = hidden ? { name: hiddenName, arguments: given } : given;
454
+ const action = this.addAction({ name: name ?? INVALID_ACTION, args, stepId: `${turn}_${position + 1}`, turn, author: opts?.author, requestedName: resolved || hidden ? written : void 0 });
455
+ const invalid = !name ? 'Each action needs a "tool" name' : badArguments ? badArguments : name === ASK_USER && !String(args.question ?? "").trim() ? 'ask_user requires a non-empty "question"' : name === RESPOND && !String(args.answer ?? "").trim() ? 'respond requires a non-empty "answer"' : void 0;
456
+ if (invalid) action.markFailed({ message: invalid, retryable: false });
457
+ return action;
458
+ });
459
+ }
460
+ history(notice) {
461
+ if (!this.opening) return [];
462
+ const byTurn = /* @__PURE__ */ new Map();
463
+ for (const action of this.actions) {
464
+ if (action.turn === void 0) continue;
465
+ byTurn.set(action.turn, [...byTurn.get(action.turn) ?? [], action]);
466
+ }
467
+ const messages = [{ role: "user", content: this.opening }];
468
+ const included = this.turns.filter((record) => {
469
+ const actions = byTurn.get(record.turn) ?? [];
470
+ return actions.length && actions.every((a) => a.isTerminal);
471
+ });
472
+ const freshFrom = included.length - FULL_OBSERVATION_TURNS;
473
+ for (const [index, record] of included.entries()) {
474
+ const actions = byTurn.get(record.turn) ?? [];
475
+ const stale = index < freshFrom;
476
+ messages.push({
477
+ role: "assistant",
478
+ content: JSON.stringify({
479
+ reasoning: record.reasoning,
480
+ ...record.state ? { state: record.state } : {},
481
+ actions: actions.filter((a) => a.name !== INVALID_RESPONSE).map((a) => ({ tool: a.name, arguments: a.args ?? {} }))
482
+ })
483
+ });
484
+ messages.push({
485
+ role: "user",
486
+ content: JSON.stringify({
487
+ OBSERVATIONS: actions.map((action) => {
488
+ const ref = action.stepId ?? action.id;
489
+ const routed = routeNote(action);
490
+ const note = routed ? { note: routed } : {};
491
+ if (action.status === "skipped") return { ref, tool: action.name, status: "skipped", ...note };
492
+ return action.status === "failed" ? { ref, tool: action.name, status: "failed", error: action.error?.message, ...note } : { ref, tool: action.name, status: "completed", output: action.observationOutput(stale, TOOL_RESULT_CHARS), ...note };
493
+ })
494
+ })
495
+ });
496
+ }
497
+ if (notice && Object.keys(notice).length) {
498
+ const last = messages[messages.length - 1];
499
+ let content = {};
500
+ try {
501
+ content = JSON.parse(String(last.content));
502
+ } catch {
503
+ content = {};
504
+ }
505
+ messages[messages.length - 1] = { role: "user", content: JSON.stringify({ ...content, HARNESS: notice }) };
506
+ }
507
+ return messages;
508
+ }
509
+ get workspaceStreak() {
510
+ const turns = /* @__PURE__ */ new Map();
511
+ for (const action of this.actions) {
512
+ if (action.turn === void 0 || !action.name) continue;
513
+ turns.set(action.turn, [...turns.get(action.turn) ?? [], action.name]);
514
+ }
515
+ let count = 0;
516
+ for (const turn of Array.from(turns.keys()).sort((a, b) => b - a)) {
517
+ if (!turns.get(turn).every((name) => name === "read_context" || name === "save_context")) break;
518
+ count++;
519
+ }
520
+ return count;
521
+ }
522
+ get sameToolStreak() {
523
+ const turns = /* @__PURE__ */ new Map();
524
+ for (const action of this.actions) {
525
+ if (action.turn === void 0 || !action.name) continue;
526
+ turns.set(action.turn, (turns.get(action.turn) ?? /* @__PURE__ */ new Set()).add(action.name));
527
+ }
528
+ let name;
529
+ let count = 0;
530
+ for (const turn of Array.from(turns.keys()).sort((a, b) => b - a)) {
531
+ const names = turns.get(turn);
532
+ const only = names.size === 1 ? Array.from(names)[0] : void 0;
533
+ if (!only || name && only !== name) break;
534
+ name = only;
535
+ count++;
536
+ }
537
+ return { name, count };
538
+ }
539
+ get discoveredToolNames() {
540
+ const names = this.actions.filter((a) => a.name === SEARCH_TOOLS && a.status === "completed").flatMap((a) => (a.structuredOutput?.tools ?? []).map((tool) => tool?.name)).filter((name) => typeof name === "string");
541
+ return Array.from(new Set(names));
542
+ }
543
+ get failedActions() {
544
+ return this.actions.filter((a) => a.status === "failed");
545
+ }
546
+ get executedActions() {
547
+ return this.actions.filter((a) => a.isTerminal);
548
+ }
549
+ get lastExecutedAction() {
550
+ return this.actions.slice().reverse().find((a) => a.isTerminal);
551
+ }
552
+ get replanCount() {
553
+ return Math.max(0, this.planCount - this.planOffset - 1);
554
+ }
555
+ get executedSinceOpen() {
556
+ return Math.max(0, this.executedActions.length - this.executedOffset);
557
+ }
558
+ executionHistory(maxChars = 1500) {
559
+ return this.executedActions.map((a) => a.promptView(maxChars));
560
+ }
561
+ setNextNode(node) {
562
+ this.nextNode = node;
563
+ }
564
+ complete(summary) {
565
+ this.status = "completed" /* COMPLETED */;
566
+ if (summary) this.summary = summary;
567
+ this.nextNode = void 0;
568
+ }
569
+ fail() {
570
+ this.status = "failed" /* FAILED */;
571
+ this.nextNode = void 0;
572
+ }
573
+ cancel() {
574
+ this.status = "cancelled" /* CANCELLED */;
575
+ this.nextNode = void 0;
576
+ }
577
+ pause() {
578
+ if (this.status === "in_progress" /* IN_PROGRESS */ || this.status === "awaiting_user" /* AWAITING_USER */) {
579
+ this.status = "paused" /* PAUSED */;
580
+ }
581
+ }
582
+ reopen() {
583
+ this.status = "in_progress" /* IN_PROGRESS */;
584
+ this.nextNode = void 0;
585
+ this.planOffset = this.planCount;
586
+ this.executedOffset = this.executedActions.length;
587
+ this.clearScratch("replan_feedback");
588
+ this.clearScratch("stop_reason");
589
+ }
590
+ findActionByRef(ref) {
591
+ return this.actions.find((a) => a.stepId === ref || a.id === ref);
592
+ }
593
+ referencedActions(value) {
594
+ const { steps } = collectRefs(value);
595
+ const found = steps.map((ref) => this.findActionByRef(ref)).filter((a) => Boolean(a));
596
+ return Array.from(new Set(found));
597
+ }
598
+ resolveArgs(action, sources, unresolved = []) {
599
+ return this.resolveValue(action.args, sources, unresolved);
600
+ }
601
+ resolveValue(value, sources, unresolved) {
602
+ if (typeof value === "string") {
603
+ const stepMatch = value.match(STEP_REF);
604
+ if (stepMatch) {
605
+ const resolved = this.readStepValue(stepMatch[1], stepMatch[2], sources);
606
+ if (resolved === void 0) {
607
+ unresolved.push(value);
608
+ return value;
609
+ }
610
+ return resolved;
611
+ }
612
+ const contextMatch = value.match(CONTEXT_REF);
613
+ if (contextMatch) {
614
+ const resolved = readPath(sources.context?.(contextMatch[1]), contextMatch[2]);
615
+ if (resolved === void 0) {
616
+ unresolved.push(value);
617
+ return value;
618
+ }
619
+ return resolved;
620
+ }
621
+ const replaced = value.replace(STEP_REF_GLOBAL, (match, ref, path) => {
622
+ const resolved = this.readStepValue(ref, path, sources);
623
+ return resolved !== void 0 ? stringifyValue(resolved) : match;
624
+ }).replace(CONTEXT_REF_GLOBAL, (match, name, path) => {
625
+ const resolved = readPath(sources.context?.(name), path);
626
+ return resolved !== void 0 ? stringifyValue(resolved) : match;
627
+ });
628
+ if (LEFTOVER_REF.test(replaced)) unresolved.push(replaced);
629
+ return replaced;
630
+ }
631
+ if (Array.isArray(value)) {
632
+ return value.map((item) => this.resolveValue(item, sources, unresolved));
633
+ }
634
+ if (value !== null && typeof value === "object") {
635
+ const resolved = {};
636
+ for (const key of Object.keys(value)) {
637
+ resolved[key] = this.resolveValue(value[key], sources, unresolved);
638
+ }
639
+ return resolved;
640
+ }
641
+ return value;
642
+ }
643
+ readStepValue(ref, path, sources) {
644
+ const target = this.findActionByRef(ref);
645
+ if (!target || target.status !== "completed") return void 0;
646
+ const output = sources.stepOutput?.(target) ?? target.structuredOutput;
647
+ return readPath(output, path);
648
+ }
649
+ }
650
+ export {
651
+ ASK_USER,
652
+ AgentTask,
653
+ NATIVE_TOOL_NAMES,
654
+ RESPOND,
655
+ SEARCH_TOOLS,
656
+ TaskStatus,
657
+ findInvoker,
658
+ readPath,
659
+ resolveToolName,
660
+ seenHiddenTool,
661
+ stableStringify
662
+ };
@@ -0,0 +1,2 @@
1
+ export * from './agent-action.entity';
2
+ export * from './agent-task.entity';
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+ var entities_exports = {};
17
+ module.exports = __toCommonJS(entities_exports);
18
+ __reExport(entities_exports, require("./agent-action.entity"), module.exports);
19
+ __reExport(entities_exports, require("./agent-task.entity"), module.exports);
20
+ // Annotate the CommonJS export names for ESM import in node:
21
+ 0 && (module.exports = {
22
+ ...require("./agent-action.entity"),
23
+ ...require("./agent-task.entity")
24
+ });
@@ -0,0 +1,2 @@
1
+ export * from "./agent-action.entity";
2
+ export * from "./agent-task.entity";