openloops 0.1.38 → 0.2.1

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 (266) hide show
  1. package/README.md +60 -5
  2. package/dist/clients/index.d.ts +2 -2
  3. package/dist/clients/index.js +4 -4
  4. package/dist/clients/index.mjs +2 -2
  5. package/dist/clients/llm/index.d.ts +1 -0
  6. package/dist/{loops/plan-execute → clients/llm}/index.js +4 -4
  7. package/dist/clients/llm/index.mjs +1 -0
  8. package/dist/clients/{llm-client.d.ts → llm/llm-client.d.ts} +3 -14
  9. package/dist/clients/{llm-client.js → llm/llm-client.js} +14 -37
  10. package/dist/clients/{llm-client.mjs → llm/llm-client.mjs} +15 -38
  11. package/dist/clients/{llm-error.mjs → llm/llm-error.mjs} +1 -1
  12. package/dist/clients/{llm-types.d.ts → llm/llm-types.d.ts} +1 -1
  13. package/dist/clients/llm/model-resolution.d.ts +20 -0
  14. package/dist/clients/llm/model-resolution.js +83 -0
  15. package/dist/clients/llm/model-resolution.mjs +46 -0
  16. package/dist/clients/{pi-ai-adapter.mjs → llm/pi-ai-adapter.mjs} +1 -1
  17. package/dist/clients/serper/index.d.ts +1 -0
  18. package/dist/clients/serper/index.js +22 -0
  19. package/dist/clients/serper/index.mjs +1 -0
  20. package/dist/clients/{serper-client.js → serper/serper-client.js} +2 -2
  21. package/dist/clients/{serper-client.mjs → serper/serper-client.mjs} +3 -3
  22. package/dist/harness/agent-loop.d.ts +0 -1
  23. package/dist/harness/agent.d.ts +6 -1
  24. package/dist/harness/agent.js +21 -13
  25. package/dist/harness/agent.mjs +21 -13
  26. package/dist/harness/native-tools.d.ts +1 -1
  27. package/dist/{loops/shared → harness}/skills/approval-request.d.ts +1 -1
  28. package/dist/{loops/shared → harness}/skills/approval-request.js +1 -1
  29. package/dist/{loops/shared → harness}/skills/approval-request.mjs +2 -2
  30. package/dist/{loops/shared → harness}/skills/autonomous-answer.d.ts +1 -1
  31. package/dist/{loops/shared → harness}/skills/autonomous-answer.js +1 -1
  32. package/dist/{loops/shared → harness}/skills/autonomous-answer.mjs +2 -2
  33. package/dist/{loops/shared → harness}/skills/confirmation-gate.d.ts +1 -1
  34. package/dist/{loops/shared → harness}/skills/confirmation-gate.js +1 -1
  35. package/dist/{loops/shared → harness}/skills/confirmation-gate.mjs +2 -2
  36. package/dist/harness/skills/index.d.ts +4 -0
  37. package/dist/{loops/plan-execute → harness}/skills/index.js +8 -8
  38. package/dist/harness/skills/index.mjs +4 -0
  39. package/dist/{loops/shared → harness}/skills/mcp-change-review.d.ts +1 -1
  40. package/dist/{loops/shared → harness}/skills/mcp-change-review.js +1 -1
  41. package/dist/{loops/shared → harness}/skills/mcp-change-review.mjs +2 -2
  42. package/dist/harness/tool-catalog.d.ts +1 -1
  43. package/dist/loops/index.d.ts +0 -1
  44. package/dist/loops/index.js +0 -2
  45. package/dist/loops/index.mjs +0 -1
  46. package/dist/loops/shared/skills/index.d.ts +0 -4
  47. package/dist/loops/shared/skills/index.js +1 -9
  48. package/dist/loops/shared/skills/index.mjs +0 -4
  49. package/dist/services/agentic-jobs/entities/agentic-job-run.entity.d.ts +42 -0
  50. package/dist/services/agentic-jobs/entities/agentic-job-run.entity.js +103 -0
  51. package/dist/services/agentic-jobs/entities/agentic-job-run.entity.mjs +80 -0
  52. package/dist/services/agentic-jobs/entities/agentic-job.entity.d.ts +39 -0
  53. package/dist/services/agentic-jobs/entities/agentic-job.entity.js +113 -0
  54. package/dist/services/agentic-jobs/entities/agentic-job.entity.mjs +90 -0
  55. package/dist/services/agentic-jobs/entities/index.d.ts +3 -0
  56. package/dist/services/agentic-jobs/entities/index.js +26 -0
  57. package/dist/services/agentic-jobs/entities/index.mjs +3 -0
  58. package/dist/services/agentic-jobs/entities/recurrence.d.ts +18 -0
  59. package/dist/services/agentic-jobs/entities/recurrence.js +84 -0
  60. package/dist/services/agentic-jobs/entities/recurrence.mjs +59 -0
  61. package/dist/services/agentic-jobs/index.d.ts +4 -0
  62. package/dist/services/agentic-jobs/index.js +28 -0
  63. package/dist/services/agentic-jobs/index.mjs +4 -0
  64. package/dist/services/agentic-jobs/module.d.ts +31 -0
  65. package/dist/services/agentic-jobs/module.js +132 -0
  66. package/dist/services/agentic-jobs/module.mjs +95 -0
  67. package/dist/services/agentic-jobs/repositories/agentic-job-run.repository.d.ts +11 -0
  68. package/dist/services/agentic-jobs/repositories/agentic-job-run.repository.js +71 -0
  69. package/dist/services/agentic-jobs/repositories/agentic-job-run.repository.mjs +42 -0
  70. package/dist/services/agentic-jobs/repositories/agentic-job.repository.d.ts +27 -0
  71. package/dist/services/agentic-jobs/repositories/agentic-job.repository.js +127 -0
  72. package/dist/services/agentic-jobs/repositories/agentic-job.repository.mjs +98 -0
  73. package/dist/services/agentic-jobs/repositories/index.d.ts +2 -0
  74. package/dist/services/agentic-jobs/repositories/index.js +24 -0
  75. package/dist/services/agentic-jobs/repositories/index.mjs +2 -0
  76. package/dist/services/agentic-jobs/runner/agentic-job-runner.d.ts +48 -0
  77. package/dist/services/agentic-jobs/runner/agentic-job-runner.js +181 -0
  78. package/dist/services/agentic-jobs/runner/agentic-job-runner.mjs +157 -0
  79. package/dist/services/agentic-jobs/use-cases/attach-agentic-job-run-chat.use-case.d.ts +15 -0
  80. package/dist/services/agentic-jobs/use-cases/attach-agentic-job-run-chat.use-case.js +58 -0
  81. package/dist/services/agentic-jobs/use-cases/attach-agentic-job-run-chat.use-case.mjs +29 -0
  82. package/dist/services/agentic-jobs/use-cases/claim-due-agentic-jobs.use-case.d.ts +29 -0
  83. package/dist/services/agentic-jobs/use-cases/claim-due-agentic-jobs.use-case.js +110 -0
  84. package/dist/services/agentic-jobs/use-cases/claim-due-agentic-jobs.use-case.mjs +81 -0
  85. package/dist/services/agentic-jobs/use-cases/create-agentic-job.use-case.d.ts +14 -0
  86. package/dist/services/agentic-jobs/use-cases/create-agentic-job.use-case.js +73 -0
  87. package/dist/services/agentic-jobs/use-cases/create-agentic-job.use-case.mjs +44 -0
  88. package/dist/services/agentic-jobs/use-cases/delete-agentic-job.use-case.d.ts +15 -0
  89. package/dist/services/agentic-jobs/use-cases/delete-agentic-job.use-case.js +65 -0
  90. package/dist/services/agentic-jobs/use-cases/delete-agentic-job.use-case.mjs +36 -0
  91. package/dist/services/agentic-jobs/use-cases/finish-agentic-job-run.use-case.d.ts +19 -0
  92. package/dist/services/agentic-jobs/use-cases/finish-agentic-job-run.use-case.js +75 -0
  93. package/dist/services/agentic-jobs/use-cases/finish-agentic-job-run.use-case.mjs +46 -0
  94. package/dist/services/agentic-jobs/use-cases/get-agentic-job-by-id.use-case.d.ts +14 -0
  95. package/dist/services/agentic-jobs/use-cases/get-agentic-job-by-id.use-case.js +55 -0
  96. package/dist/services/agentic-jobs/use-cases/get-agentic-job-by-id.use-case.mjs +26 -0
  97. package/dist/services/agentic-jobs/use-cases/list-agentic-job-runs-by-job.use-case.d.ts +16 -0
  98. package/dist/services/agentic-jobs/use-cases/list-agentic-job-runs-by-job.use-case.js +57 -0
  99. package/dist/services/agentic-jobs/use-cases/list-agentic-job-runs-by-job.use-case.mjs +28 -0
  100. package/dist/services/agentic-jobs/use-cases/list-agentic-job-runs-by-user.use-case.d.ts +16 -0
  101. package/dist/services/agentic-jobs/use-cases/list-agentic-job-runs-by-user.use-case.js +57 -0
  102. package/dist/services/agentic-jobs/use-cases/list-agentic-job-runs-by-user.use-case.mjs +28 -0
  103. package/dist/services/agentic-jobs/use-cases/list-agentic-jobs-by-user.use-case.d.ts +15 -0
  104. package/dist/services/agentic-jobs/use-cases/list-agentic-jobs-by-user.use-case.js +57 -0
  105. package/dist/services/agentic-jobs/use-cases/list-agentic-jobs-by-user.use-case.mjs +28 -0
  106. package/dist/services/agentic-jobs/use-cases/preview-agentic-job-runs.use-case.d.ts +15 -0
  107. package/dist/services/agentic-jobs/use-cases/preview-agentic-job-runs.use-case.js +52 -0
  108. package/dist/services/agentic-jobs/use-cases/preview-agentic-job-runs.use-case.mjs +23 -0
  109. package/dist/services/agentic-jobs/use-cases/renew-agentic-job-lease.use-case.d.ts +18 -0
  110. package/dist/services/agentic-jobs/use-cases/renew-agentic-job-lease.use-case.js +58 -0
  111. package/dist/services/agentic-jobs/use-cases/renew-agentic-job-lease.use-case.mjs +29 -0
  112. package/dist/services/agentic-jobs/use-cases/start-agentic-job-run.use-case.d.ts +21 -0
  113. package/dist/services/agentic-jobs/use-cases/start-agentic-job-run.use-case.js +67 -0
  114. package/dist/services/agentic-jobs/use-cases/start-agentic-job-run.use-case.mjs +38 -0
  115. package/dist/services/agentic-jobs/use-cases/sync-agentic-job-run.use-case.d.ts +20 -0
  116. package/dist/services/agentic-jobs/use-cases/sync-agentic-job-run.use-case.js +86 -0
  117. package/dist/services/agentic-jobs/use-cases/sync-agentic-job-run.use-case.mjs +56 -0
  118. package/dist/services/agentic-jobs/use-cases/sync-agentic-job-runs.use-case.d.ts +19 -0
  119. package/dist/services/agentic-jobs/use-cases/sync-agentic-job-runs.use-case.js +68 -0
  120. package/dist/services/agentic-jobs/use-cases/sync-agentic-job-runs.use-case.mjs +39 -0
  121. package/dist/services/agentic-jobs/use-cases/update-agentic-job.use-case.d.ts +15 -0
  122. package/dist/services/agentic-jobs/use-cases/update-agentic-job.use-case.js +83 -0
  123. package/dist/services/agentic-jobs/use-cases/update-agentic-job.use-case.mjs +54 -0
  124. package/dist/services/agentic-jobs/utils/job-fields.d.ts +14 -0
  125. package/dist/services/agentic-jobs/utils/job-fields.js +61 -0
  126. package/dist/services/agentic-jobs/utils/job-fields.mjs +37 -0
  127. package/dist/services/agentic-jobs/utils/next-run.d.ts +4 -0
  128. package/dist/services/agentic-jobs/utils/next-run.js +62 -0
  129. package/dist/services/agentic-jobs/utils/next-run.mjs +37 -0
  130. package/dist/services/agentic-jobs/utils/open-run.d.ts +12 -0
  131. package/dist/services/agentic-jobs/utils/open-run.js +47 -0
  132. package/dist/services/agentic-jobs/utils/open-run.mjs +24 -0
  133. package/dist/services/agentic-jobs/utils/settings.d.ts +2 -0
  134. package/dist/services/agentic-jobs/utils/settings.js +34 -0
  135. package/dist/services/agentic-jobs/utils/settings.mjs +10 -0
  136. package/dist/services/chats/entities/chat.entity.d.ts +0 -5
  137. package/dist/services/chats/entities/chat.entity.js +0 -10
  138. package/dist/services/chats/entities/chat.entity.mjs +0 -10
  139. package/dist/services/llmcalls/module.d.ts +4 -2
  140. package/dist/services/llmcalls/module.js +13 -6
  141. package/dist/services/llmcalls/module.mjs +11 -5
  142. package/dist/services/llmcalls/use-cases/get-llm-usage-by-chat.use-case.d.ts +14 -0
  143. package/dist/services/llmcalls/use-cases/get-llm-usage-by-chat.use-case.js +62 -0
  144. package/dist/services/llmcalls/use-cases/get-llm-usage-by-chat.use-case.mjs +33 -0
  145. package/dist/services/llmcalls/use-cases/get-llm-usage-by-message.use-case.d.ts +14 -0
  146. package/dist/services/llmcalls/use-cases/{get-llm-usage.use-case.js → get-llm-usage-by-message.use-case.js} +18 -37
  147. package/dist/services/llmcalls/use-cases/get-llm-usage-by-message.use-case.mjs +33 -0
  148. package/dist/services/llmcalls/utils/usage-totals.d.ts +20 -0
  149. package/dist/services/llmcalls/utils/usage-totals.js +31 -0
  150. package/dist/services/llmcalls/utils/usage-totals.mjs +29 -0
  151. package/dist/services/tasks/entities/agent-task.entity.d.ts +2 -24
  152. package/dist/services/tasks/entities/agent-task.entity.js +2 -75
  153. package/dist/services/tasks/entities/agent-task.entity.mjs +2 -75
  154. package/dist/services/users/entities/user-default-model.d.ts +11 -0
  155. package/dist/services/users/entities/user-default-model.js +42 -0
  156. package/dist/services/users/entities/user-default-model.mjs +19 -0
  157. package/dist/services/users/entities/user-preferences.d.ts +4 -1
  158. package/dist/services/users/entities/user-preferences.js +8 -3
  159. package/dist/services/users/entities/user-preferences.mjs +8 -3
  160. package/dist/services/users/use-cases/create-user.use-case.js +3 -1
  161. package/dist/services/users/use-cases/create-user.use-case.mjs +3 -1
  162. package/dist/services/users/use-cases/update-user.use-case.js +4 -1
  163. package/dist/services/users/use-cases/update-user.use-case.mjs +4 -1
  164. package/dist/services/users/utils/default-model.d.ts +6 -0
  165. package/dist/services/users/utils/default-model.js +38 -0
  166. package/dist/services/users/utils/default-model.mjs +15 -0
  167. package/dist/skills/call-modes.d.ts +1 -1
  168. package/dist/skills/skill.d.ts +1 -1
  169. package/dist/skills/skill.js +1 -1
  170. package/dist/skills/skill.mjs +1 -1
  171. package/dist/tools/core/web-search/web-search.tool.js +1 -1
  172. package/dist/tools/core/web-search/web-search.tool.mjs +1 -1
  173. package/docs/README.md +46 -0
  174. package/docs/agent.md +202 -0
  175. package/docs/agentic-jobs.md +207 -0
  176. package/docs/assets/harness-car.svg +79 -0
  177. package/docs/authentication.md +40 -0
  178. package/docs/chats.md +88 -0
  179. package/docs/configuration.md +83 -0
  180. package/docs/guardrails.md +71 -0
  181. package/docs/harness.md +92 -0
  182. package/docs/integration-guide.md +138 -0
  183. package/docs/llms.txt +35 -0
  184. package/docs/loops.md +136 -0
  185. package/docs/mcp-servers.md +148 -0
  186. package/docs/skills.md +104 -0
  187. package/docs/tools.md +90 -0
  188. package/docs/usage.md +91 -0
  189. package/docs/users.md +108 -0
  190. package/examples/agentic-jobs/create-agentic-job.ts +24 -0
  191. package/examples/agentic-jobs/list-agentic-job-runs.ts +28 -0
  192. package/examples/agentic-jobs/list-agentic-jobs.ts +25 -0
  193. package/examples/agentic-jobs/preview-agentic-job-runs.ts +16 -0
  194. package/examples/agentic-jobs/run-agentic-job-now.ts +19 -0
  195. package/examples/agentic-jobs/run-agentic-job-worker.ts +29 -0
  196. package/examples/agentic-jobs/update-agentic-job.ts +36 -0
  197. package/examples/authentication/login.ts +17 -0
  198. package/examples/chats/delete-chat.ts +32 -0
  199. package/examples/chats/get-chat-by-id.ts +32 -0
  200. package/examples/chats/list-autonomous-chats.ts +23 -0
  201. package/examples/chats/list-chats.ts +20 -0
  202. package/examples/guardrails/custom-guard.ts +11 -0
  203. package/examples/loops/custom-loop.ts +50 -0
  204. package/examples/mcps/create-mcp.ts +24 -0
  205. package/examples/mcps/decide-mcp.ts +40 -0
  206. package/examples/mcps/delete-mcp.ts +32 -0
  207. package/examples/mcps/get-mcp-by-id.ts +17 -0
  208. package/examples/mcps/list-all-mcps.ts +14 -0
  209. package/examples/mcps/list-user-mcps.ts +23 -0
  210. package/examples/mcps/update-mcp.ts +23 -0
  211. package/examples/mcps/verify-mcp.ts +17 -0
  212. package/examples/run-agent/interrupt-agent.ts +16 -0
  213. package/examples/run-agent/run-agent-autonomous.ts +34 -0
  214. package/examples/run-agent/run-agent-strict-mode.ts +30 -0
  215. package/examples/run-agent/run-agent-with-confirmation.ts +49 -0
  216. package/examples/run-agent/run-agent-with-fallback-model.ts +25 -0
  217. package/examples/run-agent/run-agent-with-guards.ts +33 -0
  218. package/examples/run-agent/run-agent-with-hooks.ts +55 -0
  219. package/examples/run-agent/run-agent-with-identity.ts +36 -0
  220. package/examples/run-agent/run-agent-with-model.ts +33 -0
  221. package/examples/run-agent/run-agent-with-tools.ts +31 -0
  222. package/examples/tools/basic-tool.ts +35 -0
  223. package/examples/tools/destructive-tool.ts +34 -0
  224. package/examples/tools/web-search-tool.ts +37 -0
  225. package/examples/usage/get-chat-usage.ts +20 -0
  226. package/examples/usage/get-message-usage.ts +20 -0
  227. package/examples/usage/get-usage-stats-by-range.ts +23 -0
  228. package/examples/usage/get-usage-stats.ts +18 -0
  229. package/examples/users/create-user.ts +19 -0
  230. package/examples/users/delete-user.ts +36 -0
  231. package/examples/users/get-user-by-id.ts +18 -0
  232. package/examples/users/list-users.ts +18 -0
  233. package/examples/users/set-default-model.ts +36 -0
  234. package/examples/users/update-user.ts +22 -0
  235. package/package.json +9 -5
  236. package/dist/loops/plan-execute/index.d.ts +0 -1
  237. package/dist/loops/plan-execute/index.mjs +0 -1
  238. package/dist/loops/plan-execute/loop.d.ts +0 -26
  239. package/dist/loops/plan-execute/loop.js +0 -267
  240. package/dist/loops/plan-execute/loop.mjs +0 -249
  241. package/dist/loops/plan-execute/skills/action-planner.d.ts +0 -35
  242. package/dist/loops/plan-execute/skills/action-planner.js +0 -71
  243. package/dist/loops/plan-execute/skills/action-planner.mjs +0 -48
  244. package/dist/loops/plan-execute/skills/final-responder.d.ts +0 -7
  245. package/dist/loops/plan-execute/skills/final-responder.js +0 -58
  246. package/dist/loops/plan-execute/skills/final-responder.mjs +0 -35
  247. package/dist/loops/plan-execute/skills/index.d.ts +0 -4
  248. package/dist/loops/plan-execute/skills/index.mjs +0 -4
  249. package/dist/loops/plan-execute/skills/state-observer.d.ts +0 -10
  250. package/dist/loops/plan-execute/skills/state-observer.js +0 -61
  251. package/dist/loops/plan-execute/skills/state-observer.mjs +0 -38
  252. package/dist/loops/plan-execute/skills/strategy-engine.d.ts +0 -11
  253. package/dist/loops/plan-execute/skills/strategy-engine.js +0 -61
  254. package/dist/loops/plan-execute/skills/strategy-engine.mjs +0 -38
  255. package/dist/services/llmcalls/use-cases/get-llm-usage.use-case.d.ts +0 -24
  256. package/dist/services/llmcalls/use-cases/get-llm-usage.use-case.mjs +0 -51
  257. package/dist/skills/skill-runner.d.ts +0 -30
  258. package/dist/skills/skill-runner.js +0 -121
  259. package/dist/skills/skill-runner.mjs +0 -92
  260. /package/dist/clients/{llm-error.d.ts → llm/llm-error.d.ts} +0 -0
  261. /package/dist/clients/{llm-error.js → llm/llm-error.js} +0 -0
  262. /package/dist/clients/{llm-types.js → llm/llm-types.js} +0 -0
  263. /package/dist/clients/{llm-types.mjs → llm/llm-types.mjs} +0 -0
  264. /package/dist/clients/{pi-ai-adapter.d.ts → llm/pi-ai-adapter.d.ts} +0 -0
  265. /package/dist/clients/{pi-ai-adapter.js → llm/pi-ai-adapter.js} +0 -0
  266. /package/dist/clients/{serper-client.d.ts → serper/serper-client.d.ts} +0 -0
@@ -1,267 +0,0 @@
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 __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var loop_exports = {};
20
- __export(loop_exports, {
21
- PlanExecuteLoop: () => PlanExecuteLoop
22
- });
23
- module.exports = __toCommonJS(loop_exports);
24
- var import_harness = require("../../harness/index.js");
25
- var import_skills = require("../shared/skills");
26
- var import_skills2 = require("./skills");
27
- const MAX_STEP_RETRIES = 2;
28
- const MAX_REPLANS = 3;
29
- const MAX_TASK_ACTIONS = 25;
30
- const RETRY_BACKOFF_MS = 500;
31
- const HISTORY_OUTPUT_CHARS = 1500;
32
- const OBSERVER_OUTPUT_CHARS = 3e3;
33
- const FINAL_OUTPUT_CHARS = 6e3;
34
- class PlanExecuteLoop extends import_harness.AgentLoop {
35
- get initialNode() {
36
- return this.nodes.fast_responder;
37
- }
38
- get nodes() {
39
- return {
40
- fast_responder: this.fastResponder,
41
- strategy_engine: this.strategyEngine,
42
- action_planner: this.actionPlanner,
43
- execution_loop: this.executionLoop,
44
- state_observer: this.executionObserver,
45
- final_responder: this.finalResponder
46
- };
47
- }
48
- get name() {
49
- return "plan_execute";
50
- }
51
- get version() {
52
- return "1.1.0";
53
- }
54
- get author() {
55
- return {
56
- name: "Jose Barcos",
57
- email: "jose@openloops.xyz",
58
- website: "https://openloops.xyz/jose"
59
- };
60
- }
61
- stopTask(ctx, harness, reason) {
62
- const task = ctx.task;
63
- task.skipPending();
64
- task.setScratch("stop_reason", reason);
65
- harness.setNextNode(this.nodes.final_responder);
66
- }
67
- async fastResponder(ctx, harness) {
68
- ctx.chat.state?.setCurrentActivity("Analyzing requirement...");
69
- const chat_history = ctx.chat.lastHistoryMessages();
70
- const agentIdentity = ctx.identity;
71
- const result = await import_skills.fastResponder.run({
72
- ...ctx.skillParams,
73
- contextInjection: {
74
- ...agentIdentity && Object.keys(agentIdentity)?.length ? { agentIdentity } : {},
75
- ...chat_history?.length ? { chat_history } : {}
76
- }
77
- });
78
- ctx.chat.state?.setLanguage(result.detected_language);
79
- if (!result.can_answer) {
80
- harness.setNextNode(this.nodes.strategy_engine);
81
- } else {
82
- ctx.chat.state?.setStatus(import_harness.AgentStatus.IDLE);
83
- harness.setNextNode(this.nodes.fast_responder);
84
- harness.reply(result.answer ?? "");
85
- }
86
- }
87
- async strategyEngine(ctx, harness) {
88
- ctx.chat.state?.setCurrentActivity("Designing strategy...");
89
- await harness.ensureTools();
90
- const lastCompletedTask = ctx.task ? void 0 : ctx.chat.lastCompletedTask();
91
- const chatHistory = ctx.chat.lastHistoryMessages();
92
- const toolsMeta = ctx.tools?.map((tool) => tool.meta);
93
- const result = await import_skills2.strategyEngine.run({
94
- ...ctx.skillParams,
95
- contextInjection: {
96
- user_goal: ctx.currentMessage,
97
- ...toolsMeta?.length ? { toolsMeta } : {},
98
- ...chatHistory?.length ? { chat_history: chatHistory } : {},
99
- ...lastCompletedTask ? { last_completed_task: { goal: lastCompletedTask.goal, summary: lastCompletedTask.summary } } : {}
100
- }
101
- });
102
- ctx.chat.state?.setLanguage(result.detected_language);
103
- const reopened = result.is_continuation && lastCompletedTask ? await harness.reopenTask(lastCompletedTask.id) : void 0;
104
- const task = reopened ?? ctx.chat.createTask(result.goal ?? ctx.currentMessage);
105
- task.setScratch("strategy", result);
106
- harness.setNextNode(this.nodes.action_planner);
107
- }
108
- async actionPlanner(ctx, harness) {
109
- ctx.chat.state?.setCurrentActivity("Creating action plan...");
110
- await harness.ensureTools();
111
- const task = ctx.task;
112
- const strategy = task.getScratch("strategy");
113
- const replanFeedback = task.getScratch("replan_feedback");
114
- const history = task.executionHistory(HISTORY_OUTPUT_CHARS);
115
- const selectedNames = new Set(strategy?.tool_names ?? []);
116
- const tools = ctx.tools?.filter((tool) => selectedNames.has(tool.name)) ?? [];
117
- const result = await import_skills2.actionPlanner.run({
118
- ...ctx.skillParams,
119
- contextInjection: {
120
- active_task: {
121
- user_goal: task.goal,
122
- strategy: strategy?.hypothesis,
123
- required_capabilities: strategy?.required_capabilities
124
- },
125
- ...history.length ? { execution_history: history } : {},
126
- ...replanFeedback ? { replan_feedback: replanFeedback, replan_attempt: task.replanCount + 1 } : {},
127
- tools
128
- }
129
- });
130
- task.clearScratch("replan_feedback");
131
- const steps = result.steps ?? [];
132
- const isExecutionPlan = result.plan_status === "SUCCESS" || result.plan_status === "NEEDS_CONFIRMATION";
133
- if (isExecutionPlan && steps.length && steps.every((step) => task.hasExecuted(step.tool_name, step.arguments ?? step.args))) {
134
- this.stopTask(ctx, harness, "The planner only proposed steps identical to ones already executed, so there is no new approach to try");
135
- return;
136
- }
137
- const enqueueSteps = () => task.addPlan(steps.map((step) => ({
138
- stepId: step.step_id,
139
- name: step.tool_name,
140
- args: step.arguments ?? step.args,
141
- dependsOn: step.depends_on_steps ?? step.depends_on,
142
- reasoning: step.rationale
143
- })), "action_planner");
144
- switch (result.plan_status) {
145
- case "MISSING_TOOLS":
146
- ctx.chat.state?.setStatus(import_harness.AgentStatus.AWAITING_USER_INPUT);
147
- ctx.chat.failTask(task.id);
148
- harness.setNextNode(void 0);
149
- harness.reply(result.user_response);
150
- break;
151
- case "NEEDS_CLARIFICATION":
152
- ctx.chat.state?.setStatus(import_harness.AgentStatus.AWAITING_USER_INPUT);
153
- harness.setNextNode(void 0);
154
- harness.reply(result.clarification_prompt);
155
- break;
156
- case "NEEDS_CONFIRMATION": {
157
- const actions = enqueueSteps();
158
- const gated = actions.filter((action) => harness.requiresApproval(action));
159
- await harness.requestApproval(gated.length ? gated : actions, { resumeAt: this.nodes.execution_loop });
160
- break;
161
- }
162
- case "SUCCESS":
163
- enqueueSteps();
164
- harness.setNextNode(this.nodes.execution_loop);
165
- break;
166
- }
167
- }
168
- async executionLoop(ctx, harness) {
169
- await harness.ensureTools();
170
- const task = ctx.task;
171
- if (task.executedSinceOpen >= MAX_TASK_ACTIONS) {
172
- this.stopTask(ctx, harness, `The task reached the maximum of ${MAX_TASK_ACTIONS} executed actions`);
173
- return;
174
- }
175
- const [next] = task.readyActions;
176
- if (!next) {
177
- harness.setNextNode(this.nodes.final_responder);
178
- return;
179
- }
180
- if (harness.requiresApproval(next)) {
181
- if (task.replanCount >= MAX_REPLANS) {
182
- this.stopTask(ctx, harness, `The step "${next.name}" needs the user's confirmation but the replan budget is exhausted`);
183
- return;
184
- }
185
- task.setScratch("replan_feedback", `The step "${next.name}" uses a destructive tool and has not been confirmed by the user. Plan it again with plan_status NEEDS_CONFIRMATION and fill confirmation_details.`);
186
- harness.setNextNode(this.nodes.action_planner);
187
- return;
188
- }
189
- ctx.chat.state?.setCurrentActivity(`Running ${next.name}...`);
190
- const executed = await harness.runAction(next);
191
- if (executed.canRetry && (executed.retries ?? 0) < MAX_STEP_RETRIES) {
192
- const retries = executed.incrementRetries();
193
- executed.resetForRetry();
194
- await new Promise((resolve) => setTimeout(resolve, RETRY_BACKOFF_MS * retries));
195
- harness.setNextNode(this.nodes.execution_loop);
196
- return;
197
- }
198
- harness.setNextNode(this.nodes.state_observer);
199
- }
200
- async executionObserver(ctx, harness) {
201
- const task = ctx.task;
202
- const lastAction = task.lastExecutedAction;
203
- const replansRemaining = Math.max(0, MAX_REPLANS - task.replanCount);
204
- const result = await import_skills2.stateObserver.run({
205
- ...ctx.skillParams,
206
- contextInjection: {
207
- user_intent: task.goal,
208
- executed_step: lastAction?.promptView(OBSERVER_OUTPUT_CHARS),
209
- remaining_steps: task.readyActions.map((a) => a.promptView()),
210
- replans_remaining: replansRemaining
211
- }
212
- });
213
- ctx.chat.state?.setCurrentActivity(result.reasoning);
214
- switch (result.action) {
215
- case "REPLAN":
216
- if (replansRemaining <= 0) {
217
- this.stopTask(ctx, harness, `The replan budget is exhausted. Last diagnosis: ${result.feedback_for_planner}`);
218
- break;
219
- }
220
- task.setScratch("replan_feedback", result.feedback_for_planner);
221
- harness.setNextNode(this.nodes.action_planner);
222
- break;
223
- case "FINISH":
224
- task.skipPending();
225
- harness.setNextNode(this.nodes.final_responder);
226
- break;
227
- case "ASK_USER":
228
- ctx.chat.state?.setStatus(import_harness.AgentStatus.AWAITING_USER_INPUT);
229
- harness.setNextNode(void 0);
230
- harness.reply(result.user_prompt ?? "");
231
- break;
232
- case "CONTINUE":
233
- default: {
234
- const stillPending = task.actions.some((a) => a.status === "pending");
235
- harness.setNextNode(stillPending ? this.nodes.execution_loop : this.nodes.final_responder);
236
- break;
237
- }
238
- }
239
- }
240
- async finalResponder(ctx, harness) {
241
- ctx.chat.state?.setCurrentActivity("Generating final response...");
242
- const task = ctx.task;
243
- const stopReason = task.getScratch("stop_reason");
244
- const executionResults = task.executedActions.map((a) => a.promptView(FINAL_OUTPUT_CHARS));
245
- const result = await import_skills2.finalResponder.run({
246
- ...ctx.skillParams,
247
- contextInjection: {
248
- user_goal: task.goal,
249
- execution_results: executionResults,
250
- ...stopReason ? { stop_reason: stopReason } : {}
251
- }
252
- });
253
- harness.reply(result.final_response ?? "");
254
- if (stopReason) {
255
- task.summary = result.reasoning;
256
- ctx.chat.failTask(task.id);
257
- } else {
258
- ctx.chat.completeTask(task.id, result.reasoning);
259
- }
260
- ctx.chat.state?.setStatus(import_harness.AgentStatus.IDLE);
261
- harness.setNextNode(this.nodes.fast_responder);
262
- }
263
- }
264
- // Annotate the CommonJS export names for ESM import in node:
265
- 0 && (module.exports = {
266
- PlanExecuteLoop
267
- });
@@ -1,249 +0,0 @@
1
- import "../../chunk-CF3WOMB3.mjs";
2
- import { AgentLoop, AgentStatus } from "../../harness/index.js";
3
- import { fastResponder } from "../shared/skills";
4
- import {
5
- actionPlanner,
6
- stateObserver,
7
- finalResponder,
8
- strategyEngine
9
- } from "./skills";
10
- const MAX_STEP_RETRIES = 2;
11
- const MAX_REPLANS = 3;
12
- const MAX_TASK_ACTIONS = 25;
13
- const RETRY_BACKOFF_MS = 500;
14
- const HISTORY_OUTPUT_CHARS = 1500;
15
- const OBSERVER_OUTPUT_CHARS = 3e3;
16
- const FINAL_OUTPUT_CHARS = 6e3;
17
- class PlanExecuteLoop extends AgentLoop {
18
- get initialNode() {
19
- return this.nodes.fast_responder;
20
- }
21
- get nodes() {
22
- return {
23
- fast_responder: this.fastResponder,
24
- strategy_engine: this.strategyEngine,
25
- action_planner: this.actionPlanner,
26
- execution_loop: this.executionLoop,
27
- state_observer: this.executionObserver,
28
- final_responder: this.finalResponder
29
- };
30
- }
31
- get name() {
32
- return "plan_execute";
33
- }
34
- get version() {
35
- return "1.1.0";
36
- }
37
- get author() {
38
- return {
39
- name: "Jose Barcos",
40
- email: "jose@openloops.xyz",
41
- website: "https://openloops.xyz/jose"
42
- };
43
- }
44
- stopTask(ctx, harness, reason) {
45
- const task = ctx.task;
46
- task.skipPending();
47
- task.setScratch("stop_reason", reason);
48
- harness.setNextNode(this.nodes.final_responder);
49
- }
50
- async fastResponder(ctx, harness) {
51
- ctx.chat.state?.setCurrentActivity("Analyzing requirement...");
52
- const chat_history = ctx.chat.lastHistoryMessages();
53
- const agentIdentity = ctx.identity;
54
- const result = await fastResponder.run({
55
- ...ctx.skillParams,
56
- contextInjection: {
57
- ...agentIdentity && Object.keys(agentIdentity)?.length ? { agentIdentity } : {},
58
- ...chat_history?.length ? { chat_history } : {}
59
- }
60
- });
61
- ctx.chat.state?.setLanguage(result.detected_language);
62
- if (!result.can_answer) {
63
- harness.setNextNode(this.nodes.strategy_engine);
64
- } else {
65
- ctx.chat.state?.setStatus(AgentStatus.IDLE);
66
- harness.setNextNode(this.nodes.fast_responder);
67
- harness.reply(result.answer ?? "");
68
- }
69
- }
70
- async strategyEngine(ctx, harness) {
71
- ctx.chat.state?.setCurrentActivity("Designing strategy...");
72
- await harness.ensureTools();
73
- const lastCompletedTask = ctx.task ? void 0 : ctx.chat.lastCompletedTask();
74
- const chatHistory = ctx.chat.lastHistoryMessages();
75
- const toolsMeta = ctx.tools?.map((tool) => tool.meta);
76
- const result = await strategyEngine.run({
77
- ...ctx.skillParams,
78
- contextInjection: {
79
- user_goal: ctx.currentMessage,
80
- ...toolsMeta?.length ? { toolsMeta } : {},
81
- ...chatHistory?.length ? { chat_history: chatHistory } : {},
82
- ...lastCompletedTask ? { last_completed_task: { goal: lastCompletedTask.goal, summary: lastCompletedTask.summary } } : {}
83
- }
84
- });
85
- ctx.chat.state?.setLanguage(result.detected_language);
86
- const reopened = result.is_continuation && lastCompletedTask ? await harness.reopenTask(lastCompletedTask.id) : void 0;
87
- const task = reopened ?? ctx.chat.createTask(result.goal ?? ctx.currentMessage);
88
- task.setScratch("strategy", result);
89
- harness.setNextNode(this.nodes.action_planner);
90
- }
91
- async actionPlanner(ctx, harness) {
92
- ctx.chat.state?.setCurrentActivity("Creating action plan...");
93
- await harness.ensureTools();
94
- const task = ctx.task;
95
- const strategy = task.getScratch("strategy");
96
- const replanFeedback = task.getScratch("replan_feedback");
97
- const history = task.executionHistory(HISTORY_OUTPUT_CHARS);
98
- const selectedNames = new Set(strategy?.tool_names ?? []);
99
- const tools = ctx.tools?.filter((tool) => selectedNames.has(tool.name)) ?? [];
100
- const result = await actionPlanner.run({
101
- ...ctx.skillParams,
102
- contextInjection: {
103
- active_task: {
104
- user_goal: task.goal,
105
- strategy: strategy?.hypothesis,
106
- required_capabilities: strategy?.required_capabilities
107
- },
108
- ...history.length ? { execution_history: history } : {},
109
- ...replanFeedback ? { replan_feedback: replanFeedback, replan_attempt: task.replanCount + 1 } : {},
110
- tools
111
- }
112
- });
113
- task.clearScratch("replan_feedback");
114
- const steps = result.steps ?? [];
115
- const isExecutionPlan = result.plan_status === "SUCCESS" || result.plan_status === "NEEDS_CONFIRMATION";
116
- if (isExecutionPlan && steps.length && steps.every((step) => task.hasExecuted(step.tool_name, step.arguments ?? step.args))) {
117
- this.stopTask(ctx, harness, "The planner only proposed steps identical to ones already executed, so there is no new approach to try");
118
- return;
119
- }
120
- const enqueueSteps = () => task.addPlan(steps.map((step) => ({
121
- stepId: step.step_id,
122
- name: step.tool_name,
123
- args: step.arguments ?? step.args,
124
- dependsOn: step.depends_on_steps ?? step.depends_on,
125
- reasoning: step.rationale
126
- })), "action_planner");
127
- switch (result.plan_status) {
128
- case "MISSING_TOOLS":
129
- ctx.chat.state?.setStatus(AgentStatus.AWAITING_USER_INPUT);
130
- ctx.chat.failTask(task.id);
131
- harness.setNextNode(void 0);
132
- harness.reply(result.user_response);
133
- break;
134
- case "NEEDS_CLARIFICATION":
135
- ctx.chat.state?.setStatus(AgentStatus.AWAITING_USER_INPUT);
136
- harness.setNextNode(void 0);
137
- harness.reply(result.clarification_prompt);
138
- break;
139
- case "NEEDS_CONFIRMATION": {
140
- const actions = enqueueSteps();
141
- const gated = actions.filter((action) => harness.requiresApproval(action));
142
- await harness.requestApproval(gated.length ? gated : actions, { resumeAt: this.nodes.execution_loop });
143
- break;
144
- }
145
- case "SUCCESS":
146
- enqueueSteps();
147
- harness.setNextNode(this.nodes.execution_loop);
148
- break;
149
- }
150
- }
151
- async executionLoop(ctx, harness) {
152
- await harness.ensureTools();
153
- const task = ctx.task;
154
- if (task.executedSinceOpen >= MAX_TASK_ACTIONS) {
155
- this.stopTask(ctx, harness, `The task reached the maximum of ${MAX_TASK_ACTIONS} executed actions`);
156
- return;
157
- }
158
- const [next] = task.readyActions;
159
- if (!next) {
160
- harness.setNextNode(this.nodes.final_responder);
161
- return;
162
- }
163
- if (harness.requiresApproval(next)) {
164
- if (task.replanCount >= MAX_REPLANS) {
165
- this.stopTask(ctx, harness, `The step "${next.name}" needs the user's confirmation but the replan budget is exhausted`);
166
- return;
167
- }
168
- task.setScratch("replan_feedback", `The step "${next.name}" uses a destructive tool and has not been confirmed by the user. Plan it again with plan_status NEEDS_CONFIRMATION and fill confirmation_details.`);
169
- harness.setNextNode(this.nodes.action_planner);
170
- return;
171
- }
172
- ctx.chat.state?.setCurrentActivity(`Running ${next.name}...`);
173
- const executed = await harness.runAction(next);
174
- if (executed.canRetry && (executed.retries ?? 0) < MAX_STEP_RETRIES) {
175
- const retries = executed.incrementRetries();
176
- executed.resetForRetry();
177
- await new Promise((resolve) => setTimeout(resolve, RETRY_BACKOFF_MS * retries));
178
- harness.setNextNode(this.nodes.execution_loop);
179
- return;
180
- }
181
- harness.setNextNode(this.nodes.state_observer);
182
- }
183
- async executionObserver(ctx, harness) {
184
- const task = ctx.task;
185
- const lastAction = task.lastExecutedAction;
186
- const replansRemaining = Math.max(0, MAX_REPLANS - task.replanCount);
187
- const result = await stateObserver.run({
188
- ...ctx.skillParams,
189
- contextInjection: {
190
- user_intent: task.goal,
191
- executed_step: lastAction?.promptView(OBSERVER_OUTPUT_CHARS),
192
- remaining_steps: task.readyActions.map((a) => a.promptView()),
193
- replans_remaining: replansRemaining
194
- }
195
- });
196
- ctx.chat.state?.setCurrentActivity(result.reasoning);
197
- switch (result.action) {
198
- case "REPLAN":
199
- if (replansRemaining <= 0) {
200
- this.stopTask(ctx, harness, `The replan budget is exhausted. Last diagnosis: ${result.feedback_for_planner}`);
201
- break;
202
- }
203
- task.setScratch("replan_feedback", result.feedback_for_planner);
204
- harness.setNextNode(this.nodes.action_planner);
205
- break;
206
- case "FINISH":
207
- task.skipPending();
208
- harness.setNextNode(this.nodes.final_responder);
209
- break;
210
- case "ASK_USER":
211
- ctx.chat.state?.setStatus(AgentStatus.AWAITING_USER_INPUT);
212
- harness.setNextNode(void 0);
213
- harness.reply(result.user_prompt ?? "");
214
- break;
215
- case "CONTINUE":
216
- default: {
217
- const stillPending = task.actions.some((a) => a.status === "pending");
218
- harness.setNextNode(stillPending ? this.nodes.execution_loop : this.nodes.final_responder);
219
- break;
220
- }
221
- }
222
- }
223
- async finalResponder(ctx, harness) {
224
- ctx.chat.state?.setCurrentActivity("Generating final response...");
225
- const task = ctx.task;
226
- const stopReason = task.getScratch("stop_reason");
227
- const executionResults = task.executedActions.map((a) => a.promptView(FINAL_OUTPUT_CHARS));
228
- const result = await finalResponder.run({
229
- ...ctx.skillParams,
230
- contextInjection: {
231
- user_goal: task.goal,
232
- execution_results: executionResults,
233
- ...stopReason ? { stop_reason: stopReason } : {}
234
- }
235
- });
236
- harness.reply(result.final_response ?? "");
237
- if (stopReason) {
238
- task.summary = result.reasoning;
239
- ctx.chat.failTask(task.id);
240
- } else {
241
- ctx.chat.completeTask(task.id, result.reasoning);
242
- }
243
- ctx.chat.state?.setStatus(AgentStatus.IDLE);
244
- harness.setNextNode(this.nodes.fast_responder);
245
- }
246
- }
247
- export {
248
- PlanExecuteLoop
249
- };
@@ -1,35 +0,0 @@
1
- import { Skill } from '../../../skills/skill.js';
2
- interface PlanStepOutput {
3
- step_id: number;
4
- tool_name: string;
5
- arguments: Record<string, any>;
6
- expected_outcome: string;
7
- status: 'READY' | 'MISSING_PARAMS' | 'REQUIRES_CONFIRMATION' | 'COMPLETED' | 'FAILED';
8
- is_destructive: boolean;
9
- missing_fields: string[];
10
- rationale: string;
11
- depends_on_steps: number[];
12
- output: Record<string, any>;
13
- }
14
- interface ConfirmationDetails {
15
- actions: Array<{
16
- step_id: number;
17
- description: string;
18
- }>;
19
- impact_summary: string;
20
- confirm_label: string;
21
- }
22
- type ResponseSchema = {
23
- plan_status: 'SUCCESS' | 'MISSING_TOOLS' | 'NEEDS_CLARIFICATION' | 'NEEDS_CONFIRMATION';
24
- current_step_index: number;
25
- missing_tools_explanation: string;
26
- user_response: string;
27
- steps: PlanStepOutput[];
28
- needs_clarification: boolean;
29
- missing_entities: string[];
30
- clarification_prompt: string;
31
- confirmation_details: ConfirmationDetails | null;
32
- reasoning: string;
33
- };
34
- export declare const actionPlanner: Skill<ResponseSchema>;
35
- export {};
@@ -1,71 +0,0 @@
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 __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var action_planner_exports = {};
20
- __export(action_planner_exports, {
21
- actionPlanner: () => actionPlanner
22
- });
23
- module.exports = __toCommonJS(action_planner_exports);
24
- var import_skill = require("../../../skills/skill.js");
25
- const actionPlanner = new import_skill.Skill({
26
- name: "action_planner",
27
- version: "1.7.0",
28
- description: "Generates an ordered step-by-step tool execution plan based on IntentContext and candidate tools schema. Flags missing tools, missing required execution parameters, or steps requiring user confirmation for destructive actions.",
29
- temperature: 0.1,
30
- systemInstructions: {
31
- instruction_set: {
32
- goal: "Evaluate userIntent, extracted_entities, and candidate tools to output a structured execution plan. Detect missing capabilities, missing tool arguments, or destructive tool executions and ask for clarification or confirmation when necessary.",
33
- role: "Action planning, tool mapping, argument mapping, and execution strategy agent",
34
- logic_rules: [
35
- "TOOL_EVALUATION: Analyze available tool schemas against userIntent and extracted_entities in IntentContext. Select only the necessary tools required to achieve the goal.",
36
- "MISSING_TOOLS_CHECK: If no candidate tools fit the intent, or if essential actions cannot be mapped to any available tool: 1) Set 'plan_status' to 'MISSING_TOOLS', 2) Set 'current_step_index' to 0, 3) Provide a technical explanation in 'missing_tools_explanation' in English, 4) Generate a polite message in 'user_response' written in 'detected_language' explaining that no connected tools/integrations were found to complete the request and suggest checking their active integrations, 5) Set 'steps' to [], 6) Set 'needs_clarification' to false, 'missing_entities' to [], 'clarification_prompt' to '', and 'confirmation_details' to null.",
37
- "STEP_PLANNING: If tools are available, sequence them logically in 'steps'. Assign incremental 'step_id' starting at 1; ids are local to this plan, even when replanning. Set 'current_step_index' to 0 by default. Explicitly list any prerequisite step IDs in 'depends_on_steps' if a step requires output from a prior step. Define a clear 'expected_outcome' describing the precise expected result or data state after this step runs.",
38
- "ARGUMENT_MAPPING: Map extracted_entities and execution context (e.g., CONTEXT metadata like 'now_utc', 'now_local', 'timezone', user_details, and session_details) to tool parameters in 'arguments'. For relative time/date expressions (e.g., 'today', 'afternoon', 'yesterday at 4:30pm'), calculate and resolve the precise value (such as ISO 8601 strings) using the provided reference timestamp and timezone. If a parameter value comes from the output of another step, represent it as a reference string: '{{step_N.output.path}}' where N is the 'step_id' of an earlier step in THIS plan, or '{{step_REF.output.path}}' where REF is the 'ref' of an entry in CONTEXT.execution_history. The path uses dot and bracket notation into that step's output (e.g., '{{step_1.output.results[0].name}}'), or is omitted to use the whole output.",
39
- "REFERENCE_SAFETY: Only reference a path you are certain exists in that step's output, based on the tool description or on an output already visible in CONTEXT.execution_history. If the arguments of a step depend on the content of an output you cannot see yet (for example the results of a search or discovery tool), do NOT plan that dependent step: plan only up to the step that produces the data. After it runs, the plan will be revised with the real output in CONTEXT.execution_history. Never invent fields, and never pass empty arguments to a tool that has required parameters.",
40
- "ARGUMENT_LANGUAGE: Values inside 'arguments' follow the description of each tool parameter, not 'detected_language'. If a parameter description asks for a specific language (for example English keywords), write that value in that language, translating or extracting the relevant domain terms and entity names from the user request when needed. Only values that must be stored or displayed verbatim (names, titles, free text written by the user) keep the user's original language.",
41
- "REPLANNING: When CONTEXT.execution_history is present, you are revising a plan. Read each entry's 'status', 'output' and 'error', and CONTEXT.replan_feedback when present. Do not propose a step with the same tool and the same arguments as an entry already in the history; use the real outputs to build a different approach (different arguments, another candidate tool, or the data already discovered). If the history shows the goal is already achieved or no different approach is possible with the candidate tools, set 'plan_status' to 'NEEDS_CLARIFICATION' and ask the user for the specific information needed.",
42
- "PARAMETER_AND_SAFETY_VALIDATION: For each step, inspect the candidate tool schema properties and flags:",
43
- "1) Set 'is_destructive' to match the candidate tool's 'destructive' boolean flag.",
44
- "2) If any required parameter is MISSING and CANNOT be derived from CONTEXT: Set step 'status' to 'MISSING_PARAMS' and list the missing keys in 'missing_fields'.",
45
- "3) If ALL required parameters are present BUT 'is_destructive' is true: Set step 'status' to 'REQUIRES_CONFIRMATION' and 'missing_fields' to [].",
46
- "4) If ALL required parameters are present and 'is_destructive' is false: Set step 'status' to 'READY' and 'missing_fields' to [].",
47
- "CLARIFICATION_CHECK: If ANY step has status 'MISSING_PARAMS': 1) Set 'plan_status' to 'NEEDS_CLARIFICATION', 2) Set 'needs_clarification' to true, 3) Collect all unresolvable parameters in 'missing_entities' in English, 4) Provide a short, direct, and polite question in 'clarification_prompt' written in 'detected_language', 5) Set 'user_response' to '', and 'confirmation_details' to null.",
48
- "CONFIRMATION_CHECK: If NO step has 'MISSING_PARAMS' BUT at least one step has status 'REQUIRES_CONFIRMATION': 1) Set 'plan_status' to 'NEEDS_CONFIRMATION', 2) Set 'needs_clarification' to false, 3) Set 'missing_entities' to [], 4) Populate 'confirmation_details' with: 'actions' (one entry per step with status 'REQUIRES_CONFIRMATION', each with that step's 'step_id' and a short natural-language 'description' of exactly what it will do, naming the action and its target \u2014 never the raw tool name or parameter keys), 'impact_summary' summarizing the overall permanent changes in plain terms, and 'confirm_label' \u2014 a short call-to-action asking the user to approve or decline; this will always be shown as the LAST line of the message, so it must stand on its own as the actual yes/no ask, 5) Provide context in 'clarification_prompt' introducing why confirmation is needed \u2014 this field must NOT itself ask a yes/no question, since 'confirm_label' is the only field that does that, 6) Set 'user_response' to ''. CRITICAL: every piece of text produced in this rule ('actions[].description', 'impact_summary', 'confirm_label', 'clarification_prompt') MUST be written in 'detected_language' \u2014 never default to English here regardless of the language used anywhere else in this instruction set.",
49
- "SUCCESS_STATE: If all steps are 'READY' and no tools are missing or requiring confirmation: 1) Set 'plan_status' to 'SUCCESS', 2) Set 'missing_tools_explanation' to '', 3) Set 'user_response' to '', 4) Set 'needs_clarification' to false, 'missing_entities' to [], 'clarification_prompt' to '', and 'confirmation_details' to null.",
50
- "LANGUAGE_ENFORCEMENT: ONLY 'clarification_prompt', 'user_response', and every field inside 'confirmation_details' (including each entry's 'description') MUST be written in the user's actual conversation language \u2014 use CONTEXT.detected_language when present; only fall back to CONTEXT.user_details.preferred_language if 'detected_language' is absent. 'preferred_language' is the app's configured display language and does NOT necessarily match the language the user is typing in right now \u2014 never prefer it over 'detected_language' when both exist. These are the only fields the end user actually reads before approving or declining. ALL OTHER fields ('missing_tools_explanation', step 'rationale', step 'expected_outcome', 'missing_entities', and 'reasoning') MUST strictly be written in English, even when the user wrote in another language. The values inside step 'arguments' are governed by ARGUMENT_LANGUAGE.",
51
- "STRICT_OUTPUT: Return ONLY the JSON object matching response_schema."
52
- ],
53
- response_schema: {
54
- plan_status: "string (SUCCESS | MISSING_TOOLS | NEEDS_CLARIFICATION | NEEDS_CONFIRMATION)",
55
- // current_step_index: "number",
56
- missing_tools_explanation: "string",
57
- user_response: "string",
58
- steps: "array of objects with fields 'step_id' (number), 'tool_name' (string), 'arguments' (object), 'expected_outcome' (string), 'status' ('READY' | 'MISSING_PARAMS' | 'REQUIRES_CONFIRMATION'), 'is_destructive' (boolean), 'missing_fields' (array of strings), 'rationale' (string), 'depends_on_steps' (array of numbers)",
59
- needs_clarification: "boolean",
60
- missing_entities: "array of strings",
61
- clarification_prompt: "string",
62
- confirmation_details: "object containing 'actions' (array of objects with 'step_id' (number) and 'description' (string, natural language, in the user's detected_language)), 'impact_summary' (string, in the user's detected_language), and 'confirm_label' (short string, in the user's detected_language) \u2014 or null",
63
- reasoning: "string"
64
- }
65
- }
66
- }
67
- });
68
- // Annotate the CommonJS export names for ESM import in node:
69
- 0 && (module.exports = {
70
- actionPlanner
71
- });