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
@@ -22,29 +22,22 @@ __export(chat_entity_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(chat_entity_exports);
24
24
  var import_base = require("../../../common/base/base.entity.js");
25
- var import_agent_state = require("../../../agent/agent-state.js");
25
+ var import_agent_state = require("../../../harness/agent-state.js");
26
+ var import_agent_task = require("../../tasks/entities/agent-task.entity.js");
26
27
  var import_chat_message = require("./chat-message.entity");
27
28
  var import_chat_settings = require("./chat-settings.entity");
28
- var import_chat_context = require("./chat-context.entity");
29
- var import_agent_task = require("./agent-task.entity");
30
29
  class Chat extends import_base.BaseEntity {
31
- constructor(props, state, settings, messages, context = import_chat_context.ChatContext.fromJSON({}), tasks = [], traces) {
30
+ constructor(props, state, settings, messages) {
32
31
  super(props);
33
32
  this.props = props;
34
33
  this.state = state;
35
34
  this.settings = settings;
36
35
  this.messages = messages;
37
- this.context = context;
38
- this.tasks = tasks;
39
- this.traces = traces;
40
36
  }
41
37
  props;
42
38
  state;
43
39
  settings;
44
40
  messages;
45
- context;
46
- tasks;
47
- traces;
48
41
  static withDefaults(loopName) {
49
42
  const agentState = new import_agent_state.AgentState();
50
43
  agentState.cleanContext();
@@ -58,12 +51,11 @@ class Chat extends import_base.BaseEntity {
58
51
  props,
59
52
  props.state && import_agent_state.AgentState.fromJSON(props.state),
60
53
  props.settings && import_chat_settings.ChatSettings.fromJSON(props.settings),
61
- props.messages?.map((message) => import_chat_message.ChatMessage.factory(message)),
62
- import_chat_context.ChatContext.fromJSON(props.context ?? {}),
63
- props.tasks?.map((task) => import_agent_task.AgentTask.fromJSON(task)) ?? [],
64
- props.traces
54
+ props.messages?.map((message) => import_chat_message.ChatMessage.factory(message))
65
55
  );
66
56
  }
57
+ tasks = [];
58
+ pendingTraces = [];
67
59
  get lastAnswer() {
68
60
  return this.messages?.slice().reverse().find((message) => message.role === "assistant")?.content;
69
61
  }
@@ -76,27 +68,30 @@ class Chat extends import_base.BaseEntity {
76
68
  ...super.toJSON(),
77
69
  state: this.state?.toJSON(),
78
70
  settings: this.settings?.toJSON(),
79
- messages: this.messages?.map((message) => message.toJSON()),
80
- context: this.context.toJSON(),
81
- tasks: this.tasks.map((task) => task.toJSON()),
82
- traces: this.traces
71
+ messages: this.messages?.map((message) => message.toJSON())
83
72
  };
84
73
  }
85
74
  pushMessage(message) {
86
75
  this.messages ??= [];
87
- this.messages.push(import_chat_message.ChatMessage.factory(message));
76
+ const created = import_chat_message.ChatMessage.factory(message);
77
+ this.messages.push(created);
78
+ return created;
88
79
  }
89
80
  lastHistoryMessages(count = 6) {
90
81
  return this.messages?.slice(-count, -1);
91
82
  }
92
83
  addTrace(entry) {
93
- this.traces ??= [];
94
- this.traces.push({
84
+ this.pendingTraces.push({
95
85
  ...entry,
96
86
  taskId: entry.taskId ?? this.activeTask?.id,
97
87
  timestamp: /* @__PURE__ */ new Date()
98
88
  });
99
89
  }
90
+ drainTraces() {
91
+ const traces = this.pendingTraces;
92
+ this.pendingTraces = [];
93
+ return traces;
94
+ }
100
95
  setAgentState(contextState) {
101
96
  this.state = import_agent_state.AgentState.fromJSON(contextState);
102
97
  }
@@ -112,6 +107,7 @@ class Chat extends import_base.BaseEntity {
112
107
  }
113
108
  const continuesFromTask = opts?.continuesFrom ? this.getTask(opts.continuesFrom) : void 0;
114
109
  const newTask = import_agent_task.AgentTask.factory({
110
+ chatId: this._id,
115
111
  goal,
116
112
  threadId: continuesFromTask?.threadId,
117
113
  previousTaskId: opts?.continuesFrom,
@@ -1,28 +1,21 @@
1
1
  import "../../../chunk-CF3WOMB3.mjs";
2
2
  import { BaseEntity } from "../../../common/base/base.entity.js";
3
- import { AgentState } from "../../../agent/agent-state.js";
3
+ import { AgentState } from "../../../harness/agent-state.js";
4
+ import { AgentTask, TaskStatus } from "../../tasks/entities/agent-task.entity.js";
4
5
  import { ChatMessage } from "./chat-message.entity";
5
6
  import { ChatSettings } from "./chat-settings.entity";
6
- import { ChatContext } from "./chat-context.entity";
7
- import { AgentTask, TaskStatus } from "./agent-task.entity";
8
7
  class Chat extends BaseEntity {
9
- constructor(props, state, settings, messages, context = ChatContext.fromJSON({}), tasks = [], traces) {
8
+ constructor(props, state, settings, messages) {
10
9
  super(props);
11
10
  this.props = props;
12
11
  this.state = state;
13
12
  this.settings = settings;
14
13
  this.messages = messages;
15
- this.context = context;
16
- this.tasks = tasks;
17
- this.traces = traces;
18
14
  }
19
15
  props;
20
16
  state;
21
17
  settings;
22
18
  messages;
23
- context;
24
- tasks;
25
- traces;
26
19
  static withDefaults(loopName) {
27
20
  const agentState = new AgentState();
28
21
  agentState.cleanContext();
@@ -36,12 +29,11 @@ class Chat extends BaseEntity {
36
29
  props,
37
30
  props.state && AgentState.fromJSON(props.state),
38
31
  props.settings && ChatSettings.fromJSON(props.settings),
39
- props.messages?.map((message) => ChatMessage.factory(message)),
40
- ChatContext.fromJSON(props.context ?? {}),
41
- props.tasks?.map((task) => AgentTask.fromJSON(task)) ?? [],
42
- props.traces
32
+ props.messages?.map((message) => ChatMessage.factory(message))
43
33
  );
44
34
  }
35
+ tasks = [];
36
+ pendingTraces = [];
45
37
  get lastAnswer() {
46
38
  return this.messages?.slice().reverse().find((message) => message.role === "assistant")?.content;
47
39
  }
@@ -54,27 +46,30 @@ class Chat extends BaseEntity {
54
46
  ...super.toJSON(),
55
47
  state: this.state?.toJSON(),
56
48
  settings: this.settings?.toJSON(),
57
- messages: this.messages?.map((message) => message.toJSON()),
58
- context: this.context.toJSON(),
59
- tasks: this.tasks.map((task) => task.toJSON()),
60
- traces: this.traces
49
+ messages: this.messages?.map((message) => message.toJSON())
61
50
  };
62
51
  }
63
52
  pushMessage(message) {
64
53
  this.messages ??= [];
65
- this.messages.push(ChatMessage.factory(message));
54
+ const created = ChatMessage.factory(message);
55
+ this.messages.push(created);
56
+ return created;
66
57
  }
67
58
  lastHistoryMessages(count = 6) {
68
59
  return this.messages?.slice(-count, -1);
69
60
  }
70
61
  addTrace(entry) {
71
- this.traces ??= [];
72
- this.traces.push({
62
+ this.pendingTraces.push({
73
63
  ...entry,
74
64
  taskId: entry.taskId ?? this.activeTask?.id,
75
65
  timestamp: /* @__PURE__ */ new Date()
76
66
  });
77
67
  }
68
+ drainTraces() {
69
+ const traces = this.pendingTraces;
70
+ this.pendingTraces = [];
71
+ return traces;
72
+ }
78
73
  setAgentState(contextState) {
79
74
  this.state = AgentState.fromJSON(contextState);
80
75
  }
@@ -90,6 +85,7 @@ class Chat extends BaseEntity {
90
85
  }
91
86
  const continuesFromTask = opts?.continuesFrom ? this.getTask(opts.continuesFrom) : void 0;
92
87
  const newTask = AgentTask.factory({
88
+ chatId: this._id,
93
89
  goal,
94
90
  threadId: continuesFromTask?.threadId,
95
91
  previousTaskId: opts?.continuesFrom,
@@ -1,8 +1,10 @@
1
+ import { QueryParams } from '../../../../common/repositories/index.js';
1
2
  import { BaseUseCase, BaseUseCaseParams, BaseUseCaseOutput } from '../../../../common/base/base.use-case.js';
2
3
  import { ChatRepository } from '../../repositories';
3
4
  import { ChatProps } from '../../entities';
4
5
  export interface Params extends BaseUseCaseParams {
5
6
  id: string;
7
+ select?: QueryParams<ChatProps>['select'];
6
8
  }
7
9
  export interface Output extends BaseUseCaseOutput {
8
10
  data: ChatProps | null;
@@ -32,7 +32,7 @@ __export(get_chat_by_id_use_case_exports, {
32
32
  module.exports = __toCommonJS(get_chat_by_id_use_case_exports);
33
33
  var import_tsyringe = require("tsyringe");
34
34
  var import_base = require("../../../../common/base/base.use-case.js");
35
- var import_repositories = require("../../repositories");
35
+ var import_repositories2 = require("../../repositories");
36
36
  let GetChatByIdUseCase = class extends import_base.BaseUseCase {
37
37
  constructor(chatRepository) {
38
38
  super();
@@ -40,14 +40,14 @@ let GetChatByIdUseCase = class extends import_base.BaseUseCase {
40
40
  }
41
41
  chatRepository;
42
42
  async execute(params) {
43
- const { id } = params;
44
- const data = await this.chatRepository?.findById(id) || {};
43
+ const { id, select } = params;
44
+ const data = await this.chatRepository?.findById(id, select) || {};
45
45
  return { data };
46
46
  }
47
47
  };
48
48
  GetChatByIdUseCase = __decorateClass([
49
49
  (0, import_tsyringe.autoInjectable)(),
50
- __decorateParam(0, (0, import_tsyringe.inject)(import_repositories.ChatRepository))
50
+ __decorateParam(0, (0, import_tsyringe.inject)(import_repositories2.ChatRepository))
51
51
  ], GetChatByIdUseCase);
52
52
  // Annotate the CommonJS export names for ESM import in node:
53
53
  0 && (module.exports = {
@@ -12,8 +12,8 @@ let GetChatByIdUseCase = class extends BaseUseCase {
12
12
  }
13
13
  chatRepository;
14
14
  async execute(params) {
15
- const { id } = params;
16
- const data = await this.chatRepository?.findById(id) || {};
15
+ const { id, select } = params;
16
+ const data = await this.chatRepository?.findById(id, select) || {};
17
17
  return { data };
18
18
  }
19
19
  };
@@ -0,0 +1,111 @@
1
+ import { ObjectId } from 'mongodb';
2
+ import { BaseEntity, BaseEntityProps } from '../../../common/base/base.entity.js';
3
+ import { Tool, BaseParams } from '../../../tools/tool.js';
4
+ export type ActionStatus = 'pending' | 'running' | 'completed' | 'failed' | 'skipped';
5
+ export interface ActionErrorProps {
6
+ message: string;
7
+ retryable?: boolean;
8
+ [key: string]: any;
9
+ }
10
+ export interface AgentActionProps extends BaseEntityProps {
11
+ chatId?: string | ObjectId;
12
+ taskId?: string | ObjectId;
13
+ name?: string;
14
+ stepId?: string;
15
+ args?: Record<string, any>;
16
+ dependsOn?: string[];
17
+ status?: ActionStatus;
18
+ output?: any;
19
+ error?: ActionErrorProps;
20
+ reasoning?: string;
21
+ retries?: number;
22
+ author?: string;
23
+ approved?: boolean;
24
+ outputRef?: string;
25
+ outputChars?: number;
26
+ outputStub?: Record<string, any>;
27
+ requestedName?: string;
28
+ callId?: string;
29
+ turn?: number;
30
+ startedAt?: Date;
31
+ completedAt?: Date;
32
+ answerId?: string | ObjectId;
33
+ }
34
+ export interface OffloadedOutput {
35
+ ref: string;
36
+ totalChars: number;
37
+ outline: any;
38
+ preview: string;
39
+ }
40
+ export declare function truncateForPrompt(value: any, maxChars?: number): any;
41
+ export declare class AgentAction extends BaseEntity {
42
+ private readonly props;
43
+ chatId?: ObjectId | undefined;
44
+ taskId?: ObjectId | undefined;
45
+ name?: string | undefined;
46
+ stepId?: string | undefined;
47
+ args?: Record<string, any> | undefined;
48
+ dependsOn?: string[] | undefined;
49
+ status?: ActionStatus | undefined;
50
+ output?: any | undefined;
51
+ error?: ActionErrorProps | undefined;
52
+ reasoning?: string | undefined;
53
+ retries?: number | undefined;
54
+ author?: string | undefined;
55
+ approved?: boolean | undefined;
56
+ outputRef?: string | undefined;
57
+ outputChars?: number | undefined;
58
+ startedAt?: Date | undefined;
59
+ completedAt?: Date | undefined;
60
+ answerId?: ObjectId | undefined;
61
+ callId?: string | undefined;
62
+ turn?: number | undefined;
63
+ outputStub?: Record<string, any> | undefined;
64
+ requestedName?: string | undefined;
65
+ private logger;
66
+ static factory(action: AgentActionProps): AgentAction;
67
+ static fromJSON(props: AgentActionProps): AgentAction;
68
+ constructor(props: AgentActionProps, chatId?: ObjectId | undefined, taskId?: ObjectId | undefined, name?: string | undefined, stepId?: string | undefined, args?: Record<string, any> | undefined, dependsOn?: string[] | undefined, status?: ActionStatus | undefined, output?: any | undefined, error?: ActionErrorProps | undefined, reasoning?: string | undefined, retries?: number | undefined, author?: string | undefined, approved?: boolean | undefined, outputRef?: string | undefined, outputChars?: number | undefined, startedAt?: Date | undefined, completedAt?: Date | undefined, answerId?: ObjectId | undefined, callId?: string | undefined, turn?: number | undefined, outputStub?: Record<string, any> | undefined, requestedName?: string | undefined);
69
+ toJSON(): AgentActionProps;
70
+ get id(): string;
71
+ get isReady(): boolean;
72
+ get isTerminal(): boolean;
73
+ get canRetry(): boolean;
74
+ static unwrap(value: any): any;
75
+ get structuredOutput(): any;
76
+ observationOutput(stale: boolean, maxChars: number): any;
77
+ get clearedFields(): Record<string, ''>;
78
+ promptView(maxChars?: number): {
79
+ ref: string;
80
+ tool: string | undefined;
81
+ args: Record<string, any> | undefined;
82
+ status: ActionStatus | undefined;
83
+ output: any;
84
+ error: {
85
+ message: string;
86
+ } | undefined;
87
+ };
88
+ dependenciesSatisfiedBy(completedRefs: Set<string>): boolean;
89
+ approve(): void;
90
+ markRunning(): void;
91
+ markCompleted(output: any): void;
92
+ markFailed(error: ActionErrorProps): void;
93
+ markSkipped(): void;
94
+ private static stubOf;
95
+ offloadOutput(offloaded: OffloadedOutput): void;
96
+ keepOutputWithStub(offloaded: OffloadedOutput): void;
97
+ incrementRetries(): number;
98
+ resetForRetry(): void;
99
+ runTool(tool: Tool | undefined, args: Record<string, any>, baseParams: BaseParams): Promise<this>;
100
+ }
101
+ export interface ActionDescriptor {
102
+ name: string;
103
+ stepId?: string;
104
+ args?: Record<string, any>;
105
+ dependsOn?: string[];
106
+ reasoning?: string;
107
+ author?: string;
108
+ callId?: string;
109
+ turn?: number;
110
+ requestedName?: string;
111
+ }
@@ -0,0 +1,271 @@
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 agent_action_entity_exports = {};
20
+ __export(agent_action_entity_exports, {
21
+ AgentAction: () => AgentAction,
22
+ truncateForPrompt: () => truncateForPrompt
23
+ });
24
+ module.exports = __toCommonJS(agent_action_entity_exports);
25
+ var import_mongodb = require("mongodb");
26
+ var import_logger = require("../../../common/logger/index.js");
27
+ var import_base = require("../../../common/base/base.entity.js");
28
+ function stubNote(ref) {
29
+ return `Partial view: the preview is only the beginning of the result. Do not take values from it as the ones you need. Load them with read_context using name "${ref}": add "path" for a section, or "find" with the text to locate an entity by name inside the result. You cannot compare long lists by eye.`;
30
+ }
31
+ const CLEARABLE_FIELDS = ["error", "startedAt", "completedAt", "outputRef", "outputChars", "outputStub"];
32
+ function truncateForPrompt(value, maxChars = 3e3) {
33
+ if (value === void 0 || value === null) return value;
34
+ const text = typeof value === "string" ? value : JSON.stringify(value);
35
+ if (text.length <= maxChars) return value;
36
+ return { truncated: true, total_chars: text.length, preview: text.slice(0, maxChars) };
37
+ }
38
+ class AgentAction extends import_base.BaseEntity {
39
+ constructor(props, chatId, taskId, name, stepId, args, dependsOn, status, output, error, reasoning, retries, author, approved, outputRef, outputChars, startedAt, completedAt, answerId, callId, turn, outputStub, requestedName) {
40
+ super(props);
41
+ this.props = props;
42
+ this.chatId = chatId;
43
+ this.taskId = taskId;
44
+ this.name = name;
45
+ this.stepId = stepId;
46
+ this.args = args;
47
+ this.dependsOn = dependsOn;
48
+ this.status = status;
49
+ this.output = output;
50
+ this.error = error;
51
+ this.reasoning = reasoning;
52
+ this.retries = retries;
53
+ this.author = author;
54
+ this.approved = approved;
55
+ this.outputRef = outputRef;
56
+ this.outputChars = outputChars;
57
+ this.startedAt = startedAt;
58
+ this.completedAt = completedAt;
59
+ this.answerId = answerId;
60
+ this.callId = callId;
61
+ this.turn = turn;
62
+ this.outputStub = outputStub;
63
+ this.requestedName = requestedName;
64
+ }
65
+ props;
66
+ chatId;
67
+ taskId;
68
+ name;
69
+ stepId;
70
+ args;
71
+ dependsOn;
72
+ status;
73
+ output;
74
+ error;
75
+ reasoning;
76
+ retries;
77
+ author;
78
+ approved;
79
+ outputRef;
80
+ outputChars;
81
+ startedAt;
82
+ completedAt;
83
+ answerId;
84
+ callId;
85
+ turn;
86
+ outputStub;
87
+ requestedName;
88
+ logger = new import_logger.Logger();
89
+ static factory(action) {
90
+ const actionId = action._id && import_mongodb.ObjectId.isValid(action._id) ? new import_mongodb.ObjectId(action._id) : new import_mongodb.ObjectId();
91
+ return AgentAction.fromJSON({ ...action, _id: actionId, status: action.status ?? "pending" });
92
+ }
93
+ static fromJSON(props) {
94
+ return new AgentAction(
95
+ props,
96
+ import_base.BaseEntity.toObjectId(props.chatId),
97
+ import_base.BaseEntity.toObjectId(props.taskId),
98
+ props.name,
99
+ props.stepId,
100
+ props.args,
101
+ props.dependsOn,
102
+ props.status,
103
+ props.output,
104
+ props.error,
105
+ props.reasoning,
106
+ props.retries,
107
+ props.author,
108
+ props.approved,
109
+ props.outputRef,
110
+ props.outputChars,
111
+ props.startedAt,
112
+ props.completedAt,
113
+ import_base.BaseEntity.toObjectId(props.answerId),
114
+ props.callId,
115
+ props.turn,
116
+ props.outputStub,
117
+ props.requestedName
118
+ );
119
+ }
120
+ toJSON() {
121
+ return {
122
+ ...super.toJSON(),
123
+ chatId: this.chatId,
124
+ taskId: this.taskId,
125
+ name: this.name,
126
+ stepId: this.stepId,
127
+ args: this.args,
128
+ dependsOn: this.dependsOn,
129
+ status: this.status,
130
+ output: this.outputStub ?? this.structuredOutput,
131
+ error: this.error,
132
+ reasoning: this.reasoning,
133
+ retries: this.retries,
134
+ author: this.author,
135
+ approved: this.approved,
136
+ outputRef: this.outputRef,
137
+ outputChars: this.outputChars,
138
+ startedAt: this.startedAt,
139
+ completedAt: this.completedAt,
140
+ answerId: this.answerId,
141
+ callId: this.callId,
142
+ turn: this.turn,
143
+ outputStub: this.outputStub,
144
+ requestedName: this.requestedName
145
+ };
146
+ }
147
+ get id() {
148
+ return this._id.toString();
149
+ }
150
+ get isReady() {
151
+ return this.status === "pending";
152
+ }
153
+ get isTerminal() {
154
+ return this.status === "completed" || this.status === "failed";
155
+ }
156
+ get canRetry() {
157
+ return this.status === "failed" && this.error?.retryable !== false;
158
+ }
159
+ static unwrap(value) {
160
+ return value?.structuredContent ? value.structuredContent : value;
161
+ }
162
+ get structuredOutput() {
163
+ return AgentAction.unwrap(this.output);
164
+ }
165
+ observationOutput(stale, maxChars) {
166
+ if (this.outputStub) return stale ? this.outputStub : this.structuredOutput;
167
+ if (this.outputRef) return this.structuredOutput;
168
+ return truncateForPrompt(this.structuredOutput, maxChars);
169
+ }
170
+ get clearedFields() {
171
+ return CLEARABLE_FIELDS.reduce((acc, field) => {
172
+ if (this[field] === void 0) acc[field] = "";
173
+ return acc;
174
+ }, {});
175
+ }
176
+ promptView(maxChars = 3e3) {
177
+ return {
178
+ ref: this.stepId ?? this.id,
179
+ tool: this.name,
180
+ args: this.args,
181
+ status: this.status,
182
+ output: this.observationOutput(false, maxChars),
183
+ error: this.error ? { message: this.error.message } : void 0
184
+ };
185
+ }
186
+ dependenciesSatisfiedBy(completedRefs) {
187
+ if (!this.dependsOn?.length) return true;
188
+ return this.dependsOn.every((ref) => completedRefs.has(ref));
189
+ }
190
+ approve() {
191
+ this.approved = true;
192
+ }
193
+ markRunning() {
194
+ this.status = "running";
195
+ this.startedAt = /* @__PURE__ */ new Date();
196
+ }
197
+ markCompleted(output) {
198
+ this.status = "completed";
199
+ this.output = output;
200
+ this.error = void 0;
201
+ this.completedAt = /* @__PURE__ */ new Date();
202
+ }
203
+ markFailed(error) {
204
+ this.status = "failed";
205
+ this.error = error;
206
+ this.completedAt = /* @__PURE__ */ new Date();
207
+ }
208
+ markSkipped() {
209
+ this.status = "skipped";
210
+ this.completedAt = /* @__PURE__ */ new Date();
211
+ }
212
+ static stubOf(offloaded) {
213
+ return {
214
+ workspace_ref: offloaded.ref,
215
+ total_chars: offloaded.totalChars,
216
+ outline: offloaded.outline,
217
+ preview: offloaded.preview,
218
+ note: stubNote(offloaded.ref)
219
+ };
220
+ }
221
+ offloadOutput(offloaded) {
222
+ this.outputRef = offloaded.ref;
223
+ this.outputChars = offloaded.totalChars;
224
+ this.outputStub = void 0;
225
+ this.output = AgentAction.stubOf(offloaded);
226
+ }
227
+ keepOutputWithStub(offloaded) {
228
+ this.outputRef = offloaded.ref;
229
+ this.outputChars = offloaded.totalChars;
230
+ this.outputStub = AgentAction.stubOf(offloaded);
231
+ }
232
+ incrementRetries() {
233
+ this.retries = (this.retries ?? 0) + 1;
234
+ return this.retries;
235
+ }
236
+ resetForRetry() {
237
+ this.status = "pending";
238
+ this.error = void 0;
239
+ this.startedAt = void 0;
240
+ this.completedAt = void 0;
241
+ }
242
+ async runTool(tool, args, baseParams) {
243
+ if (!tool) {
244
+ this.markFailed({ message: `Tool "${this.name}" not found`, retryable: false });
245
+ return this;
246
+ }
247
+ const validationErrors = tool.validate(args);
248
+ if (validationErrors.length) {
249
+ this.logger.debug({ tool: tool.name, args, validationErrors }, "[Agent Action] Invalid arguments");
250
+ this.markFailed({ message: `Invalid arguments: ${validationErrors.join("; ")}`, retryable: false });
251
+ return this;
252
+ }
253
+ this.logger.debug({
254
+ tool: tool.name,
255
+ args
256
+ }, "[Agent Action] Running tool");
257
+ this.markRunning();
258
+ try {
259
+ const result = await tool.run({ ...args, ...baseParams });
260
+ this.markCompleted(result?.data);
261
+ } catch (error) {
262
+ this.markFailed({ message: error?.message ?? String(error), retryable: error?.retryable !== false });
263
+ }
264
+ return this;
265
+ }
266
+ }
267
+ // Annotate the CommonJS export names for ESM import in node:
268
+ 0 && (module.exports = {
269
+ AgentAction,
270
+ truncateForPrompt
271
+ });