openloops 0.1.30 → 0.1.32

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 (251) hide show
  1. package/README.md +1 -1
  2. package/dist/clients/llm-client.d.ts +6 -1
  3. package/dist/clients/llm-client.js +77 -17
  4. package/dist/clients/llm-client.mjs +77 -17
  5. package/dist/clients/llm-error.d.ts +9 -0
  6. package/dist/clients/llm-error.js +69 -0
  7. package/dist/clients/llm-error.mjs +45 -0
  8. package/dist/clients/llm-types.d.ts +61 -0
  9. package/dist/clients/llm-types.js +16 -0
  10. package/dist/clients/llm-types.mjs +0 -0
  11. package/dist/clients/pi-ai-adapter.d.ts +7 -0
  12. package/dist/clients/pi-ai-adapter.js +137 -0
  13. package/dist/clients/pi-ai-adapter.mjs +113 -0
  14. package/dist/{agent → harness}/agent-loop.d.ts +11 -1
  15. package/dist/{agent → harness}/agent-state.js +1 -1
  16. package/dist/{agent → harness}/agent-state.mjs +1 -1
  17. package/dist/{agent → harness}/agent.d.ts +34 -3
  18. package/dist/harness/agent.js +546 -0
  19. package/dist/harness/agent.mjs +530 -0
  20. package/dist/{agent → harness}/index.js +5 -5
  21. package/dist/harness/native-tools.d.ts +23 -0
  22. package/dist/harness/native-tools.js +198 -0
  23. package/dist/harness/native-tools.mjs +174 -0
  24. package/dist/harness/tool-catalog.d.ts +16 -0
  25. package/dist/harness/tool-catalog.js +85 -0
  26. package/dist/harness/tool-catalog.mjs +59 -0
  27. package/dist/harness/tool-pipeline.d.ts +42 -0
  28. package/dist/harness/tool-pipeline.js +192 -0
  29. package/dist/harness/tool-pipeline.mjs +169 -0
  30. package/dist/harness/utils/describe-shape.d.ts +2 -0
  31. package/dist/harness/utils/describe-shape.js +56 -0
  32. package/dist/harness/utils/describe-shape.mjs +32 -0
  33. package/dist/harness/workspace.d.ts +44 -0
  34. package/dist/harness/workspace.js +95 -0
  35. package/dist/harness/workspace.mjs +78 -0
  36. package/dist/index.d.ts +1 -1
  37. package/dist/index.js +2 -2
  38. package/dist/index.mjs +1 -1
  39. package/dist/loops/agi/index.d.ts +1 -0
  40. package/dist/loops/agi/index.js +22 -0
  41. package/dist/loops/agi/index.mjs +1 -0
  42. package/dist/loops/agi/loop.d.ts +24 -0
  43. package/dist/loops/agi/loop.js +207 -0
  44. package/dist/loops/agi/loop.mjs +184 -0
  45. package/dist/loops/agi/skills/reasoning-engine.d.ts +14 -0
  46. package/dist/loops/agi/skills/reasoning-engine.js +93 -0
  47. package/dist/loops/agi/skills/reasoning-engine.mjs +70 -0
  48. package/dist/loops/index.d.ts +1 -0
  49. package/dist/loops/index.js +3 -1
  50. package/dist/loops/index.mjs +1 -0
  51. package/dist/loops/plan-execute/plan-execute-loop.d.ts +2 -1
  52. package/dist/loops/plan-execute/plan-execute-loop.js +90 -35
  53. package/dist/loops/plan-execute/plan-execute-loop.mjs +80 -25
  54. package/dist/loops/shared/skills/action-planner.js +7 -4
  55. package/dist/loops/shared/skills/action-planner.mjs +7 -4
  56. package/dist/loops/shared/skills/final-responder.js +4 -3
  57. package/dist/loops/shared/skills/final-responder.mjs +4 -3
  58. package/dist/loops/shared/skills/state-observer.js +6 -2
  59. package/dist/loops/shared/skills/state-observer.mjs +6 -2
  60. package/dist/services/chats/entities/chat-message.entity.d.ts +4 -1
  61. package/dist/services/chats/entities/chat-message.entity.js +7 -3
  62. package/dist/services/chats/entities/chat-message.entity.mjs +7 -3
  63. package/dist/services/chats/entities/chat.entity.d.ts +10 -11
  64. package/dist/services/chats/entities/chat.entity.js +17 -21
  65. package/dist/services/chats/entities/chat.entity.mjs +17 -21
  66. package/dist/services/chats/lambdas/get-chat-by-id/get-chat-by-id.use-case.d.ts +2 -0
  67. package/dist/services/chats/lambdas/get-chat-by-id/get-chat-by-id.use-case.js +4 -4
  68. package/dist/services/chats/lambdas/get-chat-by-id/get-chat-by-id.use-case.mjs +2 -2
  69. package/dist/services/llmcalls/entities/llmcall.entity.d.ts +1 -1
  70. package/dist/services/tasks/entities/agent-action.entity.d.ts +111 -0
  71. package/dist/services/tasks/entities/agent-action.entity.js +269 -0
  72. package/dist/services/tasks/entities/agent-action.entity.mjs +245 -0
  73. package/dist/services/tasks/entities/agent-task.entity.d.ts +172 -0
  74. package/dist/services/tasks/entities/agent-task.entity.js +665 -0
  75. package/dist/services/tasks/entities/agent-task.entity.mjs +633 -0
  76. package/dist/services/tasks/entities/index.d.ts +2 -0
  77. package/dist/services/tasks/entities/index.js +24 -0
  78. package/dist/services/tasks/entities/index.mjs +2 -0
  79. package/dist/services/tasks/index.d.ts +3 -0
  80. package/dist/services/tasks/index.js +26 -0
  81. package/dist/services/tasks/index.mjs +3 -0
  82. package/dist/services/tasks/lambdas/create-agent-action/create-agent-action.use-case.d.ts +14 -0
  83. package/dist/services/tasks/lambdas/create-agent-action/create-agent-action.use-case.js +60 -0
  84. package/dist/services/tasks/lambdas/create-agent-action/create-agent-action.use-case.mjs +31 -0
  85. package/dist/services/tasks/lambdas/create-agent-action/index.d.ts +1 -0
  86. package/dist/services/tasks/lambdas/create-agent-action/index.js +22 -0
  87. package/dist/services/tasks/lambdas/create-agent-action/index.mjs +1 -0
  88. package/dist/services/tasks/lambdas/create-agent-task/create-agent-task.use-case.d.ts +14 -0
  89. package/dist/services/tasks/lambdas/create-agent-task/create-agent-task.use-case.js +60 -0
  90. package/dist/services/tasks/lambdas/create-agent-task/create-agent-task.use-case.mjs +31 -0
  91. package/dist/services/tasks/lambdas/create-agent-task/index.d.ts +1 -0
  92. package/dist/services/tasks/lambdas/create-agent-task/index.js +22 -0
  93. package/dist/services/tasks/lambdas/create-agent-task/index.mjs +1 -0
  94. package/dist/services/tasks/lambdas/get-agent-task-by-id/get-agent-task-by-id.use-case.d.ts +14 -0
  95. package/dist/services/tasks/lambdas/get-agent-task-by-id/get-agent-task-by-id.use-case.js +55 -0
  96. package/dist/services/tasks/lambdas/get-agent-task-by-id/get-agent-task-by-id.use-case.mjs +26 -0
  97. package/dist/services/tasks/lambdas/get-agent-task-by-id/index.d.ts +1 -0
  98. package/dist/services/tasks/lambdas/get-agent-task-by-id/index.js +22 -0
  99. package/dist/services/tasks/lambdas/get-agent-task-by-id/index.mjs +1 -0
  100. package/dist/services/tasks/lambdas/index.d.ts +7 -0
  101. package/dist/services/tasks/lambdas/index.js +46 -0
  102. package/dist/services/tasks/lambdas/index.mjs +17 -0
  103. package/dist/services/tasks/lambdas/list-agent-actions-by-task/index.d.ts +1 -0
  104. package/dist/services/tasks/lambdas/list-agent-actions-by-task/index.js +22 -0
  105. package/dist/services/tasks/lambdas/list-agent-actions-by-task/index.mjs +1 -0
  106. package/dist/services/tasks/lambdas/list-agent-actions-by-task/list-agent-actions-by-task.use-case.d.ts +16 -0
  107. package/dist/services/tasks/lambdas/list-agent-actions-by-task/list-agent-actions-by-task.use-case.js +62 -0
  108. package/dist/services/tasks/lambdas/list-agent-actions-by-task/list-agent-actions-by-task.use-case.mjs +33 -0
  109. package/dist/services/tasks/lambdas/list-agent-tasks-by-chat/index.d.ts +1 -0
  110. package/dist/services/tasks/lambdas/list-agent-tasks-by-chat/index.js +22 -0
  111. package/dist/services/tasks/lambdas/list-agent-tasks-by-chat/index.mjs +1 -0
  112. package/dist/services/tasks/lambdas/list-agent-tasks-by-chat/list-agent-tasks-by-chat.use-case.d.ts +16 -0
  113. package/dist/services/tasks/lambdas/list-agent-tasks-by-chat/list-agent-tasks-by-chat.use-case.js +62 -0
  114. package/dist/services/tasks/lambdas/list-agent-tasks-by-chat/list-agent-tasks-by-chat.use-case.mjs +33 -0
  115. package/dist/services/tasks/lambdas/update-agent-action/index.d.ts +1 -0
  116. package/dist/services/tasks/lambdas/update-agent-action/index.js +22 -0
  117. package/dist/services/tasks/lambdas/update-agent-action/index.mjs +1 -0
  118. package/dist/services/tasks/lambdas/update-agent-action/update-agent-action.use-case.d.ts +15 -0
  119. package/dist/services/tasks/lambdas/update-agent-action/update-agent-action.use-case.js +67 -0
  120. package/dist/services/tasks/lambdas/update-agent-action/update-agent-action.use-case.mjs +38 -0
  121. package/dist/services/tasks/lambdas/update-agent-task/index.d.ts +1 -0
  122. package/dist/services/tasks/lambdas/update-agent-task/index.js +22 -0
  123. package/dist/services/tasks/lambdas/update-agent-task/index.mjs +1 -0
  124. package/dist/services/tasks/lambdas/update-agent-task/update-agent-task.use-case.d.ts +15 -0
  125. package/dist/services/tasks/lambdas/update-agent-task/update-agent-task.use-case.js +67 -0
  126. package/dist/services/tasks/lambdas/update-agent-task/update-agent-task.use-case.mjs +38 -0
  127. package/dist/services/tasks/module.d.ts +15 -0
  128. package/dist/services/tasks/module.js +76 -0
  129. package/dist/services/tasks/module.mjs +47 -0
  130. package/dist/services/tasks/repositories/agent-action.repository.d.ts +8 -0
  131. package/dist/services/tasks/repositories/agent-action.repository.js +62 -0
  132. package/dist/services/tasks/repositories/agent-action.repository.mjs +33 -0
  133. package/dist/services/tasks/repositories/agent-task.repository.d.ts +9 -0
  134. package/dist/services/tasks/repositories/agent-task.repository.js +65 -0
  135. package/dist/services/tasks/repositories/agent-task.repository.mjs +36 -0
  136. package/dist/services/tasks/repositories/index.d.ts +2 -0
  137. package/dist/services/tasks/repositories/index.js +24 -0
  138. package/dist/services/tasks/repositories/index.mjs +2 -0
  139. package/dist/services/traces/entities/agent-trace-entry.entity.d.ts +30 -0
  140. package/dist/services/traces/entities/agent-trace-entry.entity.js +85 -0
  141. package/dist/services/traces/entities/agent-trace-entry.entity.mjs +62 -0
  142. package/dist/services/traces/entities/index.d.ts +1 -0
  143. package/dist/services/traces/entities/index.js +22 -0
  144. package/dist/services/traces/entities/index.mjs +1 -0
  145. package/dist/services/traces/index.d.ts +3 -0
  146. package/dist/services/traces/index.js +26 -0
  147. package/dist/services/traces/index.mjs +3 -0
  148. package/dist/services/traces/lambdas/create-agent-traces/create-agent-traces.use-case.d.ts +16 -0
  149. package/dist/services/traces/lambdas/create-agent-traces/create-agent-traces.use-case.js +62 -0
  150. package/dist/services/traces/lambdas/create-agent-traces/create-agent-traces.use-case.mjs +33 -0
  151. package/dist/services/traces/lambdas/create-agent-traces/index.d.ts +1 -0
  152. package/dist/services/traces/lambdas/create-agent-traces/index.js +22 -0
  153. package/dist/services/traces/lambdas/create-agent-traces/index.mjs +1 -0
  154. package/dist/services/traces/lambdas/index.d.ts +2 -0
  155. package/dist/services/traces/lambdas/index.js +31 -0
  156. package/dist/services/traces/lambdas/index.mjs +7 -0
  157. package/dist/services/traces/lambdas/list-agent-traces-by-chat/index.d.ts +1 -0
  158. package/dist/services/traces/lambdas/list-agent-traces-by-chat/index.js +22 -0
  159. package/dist/services/traces/lambdas/list-agent-traces-by-chat/index.mjs +1 -0
  160. package/dist/services/traces/lambdas/list-agent-traces-by-chat/list-agent-traces-by-chat.use-case.d.ts +18 -0
  161. package/dist/services/traces/lambdas/list-agent-traces-by-chat/list-agent-traces-by-chat.use-case.js +67 -0
  162. package/dist/services/traces/lambdas/list-agent-traces-by-chat/list-agent-traces-by-chat.use-case.mjs +38 -0
  163. package/dist/services/traces/module.d.ts +5 -0
  164. package/dist/services/traces/module.js +41 -0
  165. package/dist/services/traces/module.mjs +17 -0
  166. package/dist/services/traces/repositories/agent-trace.repository.d.ts +7 -0
  167. package/dist/services/traces/repositories/agent-trace.repository.js +55 -0
  168. package/dist/services/traces/repositories/agent-trace.repository.mjs +26 -0
  169. package/dist/services/traces/repositories/index.d.ts +1 -0
  170. package/dist/services/traces/repositories/index.js +22 -0
  171. package/dist/services/traces/repositories/index.mjs +1 -0
  172. package/dist/services/workspaces/entities/index.d.ts +1 -0
  173. package/dist/services/workspaces/entities/index.js +22 -0
  174. package/dist/services/workspaces/entities/index.mjs +1 -0
  175. package/dist/services/workspaces/entities/workspace-item.entity.d.ts +33 -0
  176. package/dist/services/workspaces/entities/workspace-item.entity.js +95 -0
  177. package/dist/services/workspaces/entities/workspace-item.entity.mjs +72 -0
  178. package/dist/services/workspaces/index.d.ts +3 -0
  179. package/dist/services/workspaces/index.js +26 -0
  180. package/dist/services/workspaces/index.mjs +3 -0
  181. package/dist/services/workspaces/lambdas/delete-workspace-item/delete-workspace-item.use-case.d.ts +17 -0
  182. package/dist/services/workspaces/lambdas/delete-workspace-item/delete-workspace-item.use-case.js +68 -0
  183. package/dist/services/workspaces/lambdas/delete-workspace-item/delete-workspace-item.use-case.mjs +39 -0
  184. package/dist/services/workspaces/lambdas/delete-workspace-item/index.d.ts +1 -0
  185. package/dist/services/workspaces/lambdas/delete-workspace-item/index.js +22 -0
  186. package/dist/services/workspaces/lambdas/delete-workspace-item/index.mjs +1 -0
  187. package/dist/services/workspaces/lambdas/get-workspace-item/get-workspace-item.use-case.d.ts +17 -0
  188. package/dist/services/workspaces/lambdas/get-workspace-item/get-workspace-item.use-case.js +67 -0
  189. package/dist/services/workspaces/lambdas/get-workspace-item/get-workspace-item.use-case.mjs +38 -0
  190. package/dist/services/workspaces/lambdas/get-workspace-item/index.d.ts +1 -0
  191. package/dist/services/workspaces/lambdas/get-workspace-item/index.js +22 -0
  192. package/dist/services/workspaces/lambdas/get-workspace-item/index.mjs +1 -0
  193. package/dist/services/workspaces/lambdas/index.d.ts +5 -0
  194. package/dist/services/workspaces/lambdas/index.js +40 -0
  195. package/dist/services/workspaces/lambdas/index.mjs +13 -0
  196. package/dist/services/workspaces/lambdas/list-workspace-items/index.d.ts +1 -0
  197. package/dist/services/workspaces/lambdas/list-workspace-items/index.js +22 -0
  198. package/dist/services/workspaces/lambdas/list-workspace-items/index.mjs +1 -0
  199. package/dist/services/workspaces/lambdas/list-workspace-items/list-workspace-items.use-case.d.ts +18 -0
  200. package/dist/services/workspaces/lambdas/list-workspace-items/list-workspace-items.use-case.js +69 -0
  201. package/dist/services/workspaces/lambdas/list-workspace-items/list-workspace-items.use-case.mjs +40 -0
  202. package/dist/services/workspaces/lambdas/save-workspace-item/index.d.ts +1 -0
  203. package/dist/services/workspaces/lambdas/save-workspace-item/index.js +22 -0
  204. package/dist/services/workspaces/lambdas/save-workspace-item/index.mjs +1 -0
  205. package/dist/services/workspaces/lambdas/save-workspace-item/save-workspace-item.use-case.d.ts +14 -0
  206. package/dist/services/workspaces/lambdas/save-workspace-item/save-workspace-item.use-case.js +76 -0
  207. package/dist/services/workspaces/lambdas/save-workspace-item/save-workspace-item.use-case.mjs +47 -0
  208. package/dist/services/workspaces/lambdas/search-workspace-items/index.d.ts +1 -0
  209. package/dist/services/workspaces/lambdas/search-workspace-items/index.js +22 -0
  210. package/dist/services/workspaces/lambdas/search-workspace-items/index.mjs +1 -0
  211. package/dist/services/workspaces/lambdas/search-workspace-items/search-workspace-items.use-case.d.ts +19 -0
  212. package/dist/services/workspaces/lambdas/search-workspace-items/search-workspace-items.use-case.js +73 -0
  213. package/dist/services/workspaces/lambdas/search-workspace-items/search-workspace-items.use-case.mjs +44 -0
  214. package/dist/services/workspaces/module.d.ts +11 -0
  215. package/dist/services/workspaces/module.js +62 -0
  216. package/dist/services/workspaces/module.mjs +35 -0
  217. package/dist/services/workspaces/repositories/index.d.ts +1 -0
  218. package/dist/services/workspaces/repositories/index.js +22 -0
  219. package/dist/services/workspaces/repositories/index.mjs +1 -0
  220. package/dist/services/workspaces/repositories/workspace-item.repository.d.ts +18 -0
  221. package/dist/services/workspaces/repositories/workspace-item.repository.js +74 -0
  222. package/dist/services/workspaces/repositories/workspace-item.repository.mjs +45 -0
  223. package/dist/skills/runtime-context.d.ts +8 -0
  224. package/dist/skills/runtime-context.js +65 -0
  225. package/dist/skills/runtime-context.mjs +42 -0
  226. package/dist/skills/skill.d.ts +7 -0
  227. package/dist/skills/skill.js +26 -60
  228. package/dist/skills/skill.mjs +26 -60
  229. package/dist/tools/tool.d.ts +6 -0
  230. package/dist/tools/tool.js +56 -0
  231. package/dist/tools/tool.mjs +56 -0
  232. package/package.json +4 -4
  233. package/dist/agent/agent.js +0 -327
  234. package/dist/agent/agent.mjs +0 -303
  235. package/dist/services/chats/entities/agent-action.entity.d.ts +0 -58
  236. package/dist/services/chats/entities/agent-action.entity.js +0 -151
  237. package/dist/services/chats/entities/agent-action.entity.mjs +0 -128
  238. package/dist/services/chats/entities/agent-task.entity.d.ts +0 -59
  239. package/dist/services/chats/entities/agent-task.entity.js +0 -231
  240. package/dist/services/chats/entities/agent-task.entity.mjs +0 -207
  241. package/dist/services/chats/entities/chat-context.entity.d.ts +0 -39
  242. package/dist/services/chats/entities/chat-context.entity.js +0 -70
  243. package/dist/services/chats/entities/chat-context.entity.mjs +0 -47
  244. /package/dist/{agent → harness}/agent-loop.js +0 -0
  245. /package/dist/{agent → harness}/agent-loop.mjs +0 -0
  246. /package/dist/{agent → harness}/agent-state.d.ts +0 -0
  247. /package/dist/{agent → harness}/index.d.ts +0 -0
  248. /package/dist/{agent → harness}/index.mjs +0 -0
  249. /package/dist/{agent → harness}/utils/rank-tools-by-keywords.d.ts +0 -0
  250. /package/dist/{agent → harness}/utils/rank-tools-by-keywords.js +0 -0
  251. /package/dist/{agent → harness}/utils/rank-tools-by-keywords.mjs +0 -0
@@ -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,269 @@
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
+ const STUB_NOTE = "Partial view: the preview is only the beginning of the result. Do not take values from it as the ones you need; load the part you need with read_context.";
29
+ const CLEARABLE_FIELDS = ["error", "startedAt", "completedAt", "outputRef", "outputChars", "outputStub"];
30
+ function truncateForPrompt(value, maxChars = 3e3) {
31
+ if (value === void 0 || value === null) return value;
32
+ const text = typeof value === "string" ? value : JSON.stringify(value);
33
+ if (text.length <= maxChars) return value;
34
+ return { truncated: true, total_chars: text.length, preview: text.slice(0, maxChars) };
35
+ }
36
+ class AgentAction extends import_base.BaseEntity {
37
+ constructor(props, chatId, taskId, name, stepId, args, dependsOn, status, output, error, reasoning, retries, author, approved, outputRef, outputChars, startedAt, completedAt, answerId, callId, turn, outputStub, requestedName) {
38
+ super(props);
39
+ this.props = props;
40
+ this.chatId = chatId;
41
+ this.taskId = taskId;
42
+ this.name = name;
43
+ this.stepId = stepId;
44
+ this.args = args;
45
+ this.dependsOn = dependsOn;
46
+ this.status = status;
47
+ this.output = output;
48
+ this.error = error;
49
+ this.reasoning = reasoning;
50
+ this.retries = retries;
51
+ this.author = author;
52
+ this.approved = approved;
53
+ this.outputRef = outputRef;
54
+ this.outputChars = outputChars;
55
+ this.startedAt = startedAt;
56
+ this.completedAt = completedAt;
57
+ this.answerId = answerId;
58
+ this.callId = callId;
59
+ this.turn = turn;
60
+ this.outputStub = outputStub;
61
+ this.requestedName = requestedName;
62
+ }
63
+ props;
64
+ chatId;
65
+ taskId;
66
+ name;
67
+ stepId;
68
+ args;
69
+ dependsOn;
70
+ status;
71
+ output;
72
+ error;
73
+ reasoning;
74
+ retries;
75
+ author;
76
+ approved;
77
+ outputRef;
78
+ outputChars;
79
+ startedAt;
80
+ completedAt;
81
+ answerId;
82
+ callId;
83
+ turn;
84
+ outputStub;
85
+ requestedName;
86
+ logger = new import_logger.Logger();
87
+ static factory(action) {
88
+ const actionId = action._id && import_mongodb.ObjectId.isValid(action._id) ? new import_mongodb.ObjectId(action._id) : new import_mongodb.ObjectId();
89
+ return AgentAction.fromJSON({ ...action, _id: actionId, status: action.status ?? "pending" });
90
+ }
91
+ static fromJSON(props) {
92
+ return new AgentAction(
93
+ props,
94
+ import_base.BaseEntity.toObjectId(props.chatId),
95
+ import_base.BaseEntity.toObjectId(props.taskId),
96
+ props.name,
97
+ props.stepId,
98
+ props.args,
99
+ props.dependsOn,
100
+ props.status,
101
+ props.output,
102
+ props.error,
103
+ props.reasoning,
104
+ props.retries,
105
+ props.author,
106
+ props.approved,
107
+ props.outputRef,
108
+ props.outputChars,
109
+ props.startedAt,
110
+ props.completedAt,
111
+ import_base.BaseEntity.toObjectId(props.answerId),
112
+ props.callId,
113
+ props.turn,
114
+ props.outputStub,
115
+ props.requestedName
116
+ );
117
+ }
118
+ toJSON() {
119
+ return {
120
+ ...super.toJSON(),
121
+ chatId: this.chatId,
122
+ taskId: this.taskId,
123
+ name: this.name,
124
+ stepId: this.stepId,
125
+ args: this.args,
126
+ dependsOn: this.dependsOn,
127
+ status: this.status,
128
+ output: this.outputStub ?? this.structuredOutput,
129
+ error: this.error,
130
+ reasoning: this.reasoning,
131
+ retries: this.retries,
132
+ author: this.author,
133
+ approved: this.approved,
134
+ outputRef: this.outputRef,
135
+ outputChars: this.outputChars,
136
+ startedAt: this.startedAt,
137
+ completedAt: this.completedAt,
138
+ answerId: this.answerId,
139
+ callId: this.callId,
140
+ turn: this.turn,
141
+ outputStub: this.outputStub,
142
+ requestedName: this.requestedName
143
+ };
144
+ }
145
+ get id() {
146
+ return this._id.toString();
147
+ }
148
+ get isReady() {
149
+ return this.status === "pending";
150
+ }
151
+ get isTerminal() {
152
+ return this.status === "completed" || this.status === "failed";
153
+ }
154
+ get canRetry() {
155
+ return this.status === "failed" && this.error?.retryable !== false;
156
+ }
157
+ static unwrap(value) {
158
+ return value?.structuredContent ? value.structuredContent : value;
159
+ }
160
+ get structuredOutput() {
161
+ return AgentAction.unwrap(this.output);
162
+ }
163
+ observationOutput(stale, maxChars) {
164
+ if (this.outputStub) return stale ? this.outputStub : this.structuredOutput;
165
+ if (this.outputRef) return this.structuredOutput;
166
+ return truncateForPrompt(this.structuredOutput, maxChars);
167
+ }
168
+ get clearedFields() {
169
+ return CLEARABLE_FIELDS.reduce((acc, field) => {
170
+ if (this[field] === void 0) acc[field] = "";
171
+ return acc;
172
+ }, {});
173
+ }
174
+ promptView(maxChars = 3e3) {
175
+ return {
176
+ ref: this.stepId ?? this.id,
177
+ tool: this.name,
178
+ args: this.args,
179
+ status: this.status,
180
+ output: this.observationOutput(false, maxChars),
181
+ error: this.error ? { message: this.error.message } : void 0
182
+ };
183
+ }
184
+ dependenciesSatisfiedBy(completedRefs) {
185
+ if (!this.dependsOn?.length) return true;
186
+ return this.dependsOn.every((ref) => completedRefs.has(ref));
187
+ }
188
+ approve() {
189
+ this.approved = true;
190
+ }
191
+ markRunning() {
192
+ this.status = "running";
193
+ this.startedAt = /* @__PURE__ */ new Date();
194
+ }
195
+ markCompleted(output) {
196
+ this.status = "completed";
197
+ this.output = output;
198
+ this.error = void 0;
199
+ this.completedAt = /* @__PURE__ */ new Date();
200
+ }
201
+ markFailed(error) {
202
+ this.status = "failed";
203
+ this.error = error;
204
+ this.completedAt = /* @__PURE__ */ new Date();
205
+ }
206
+ markSkipped() {
207
+ this.status = "skipped";
208
+ this.completedAt = /* @__PURE__ */ new Date();
209
+ }
210
+ static stubOf(offloaded) {
211
+ return {
212
+ workspace_ref: offloaded.ref,
213
+ total_chars: offloaded.totalChars,
214
+ outline: offloaded.outline,
215
+ preview: offloaded.preview,
216
+ note: STUB_NOTE
217
+ };
218
+ }
219
+ offloadOutput(offloaded) {
220
+ this.outputRef = offloaded.ref;
221
+ this.outputChars = offloaded.totalChars;
222
+ this.outputStub = void 0;
223
+ this.output = AgentAction.stubOf(offloaded);
224
+ }
225
+ keepOutputWithStub(offloaded) {
226
+ this.outputRef = offloaded.ref;
227
+ this.outputChars = offloaded.totalChars;
228
+ this.outputStub = AgentAction.stubOf(offloaded);
229
+ }
230
+ incrementRetries() {
231
+ this.retries = (this.retries ?? 0) + 1;
232
+ return this.retries;
233
+ }
234
+ resetForRetry() {
235
+ this.status = "pending";
236
+ this.error = void 0;
237
+ this.startedAt = void 0;
238
+ this.completedAt = void 0;
239
+ }
240
+ async runTool(tool, args, baseParams) {
241
+ if (!tool) {
242
+ this.markFailed({ message: `Tool "${this.name}" not found`, retryable: false });
243
+ return this;
244
+ }
245
+ const validationErrors = tool.validate(args);
246
+ if (validationErrors.length) {
247
+ this.logger.debug({ tool: tool.name, args, validationErrors }, "[Agent Action] Invalid arguments");
248
+ this.markFailed({ message: `Invalid arguments: ${validationErrors.join("; ")}`, retryable: false });
249
+ return this;
250
+ }
251
+ this.logger.debug({
252
+ tool: tool.name,
253
+ args
254
+ }, "[Agent Action] Running tool");
255
+ this.markRunning();
256
+ try {
257
+ const result = await tool.run({ ...args, ...baseParams });
258
+ this.markCompleted(result?.data);
259
+ } catch (error) {
260
+ this.markFailed({ message: error?.message ?? String(error), retryable: error?.retryable !== false });
261
+ }
262
+ return this;
263
+ }
264
+ }
265
+ // Annotate the CommonJS export names for ESM import in node:
266
+ 0 && (module.exports = {
267
+ AgentAction,
268
+ truncateForPrompt
269
+ });
@@ -0,0 +1,245 @@
1
+ import "../../../chunk-CF3WOMB3.mjs";
2
+ import { ObjectId } from "mongodb";
3
+ import { Logger } from "../../../common/logger/index.js";
4
+ import { BaseEntity } from "../../../common/base/base.entity.js";
5
+ const STUB_NOTE = "Partial view: the preview is only the beginning of the result. Do not take values from it as the ones you need; load the part you need with read_context.";
6
+ const CLEARABLE_FIELDS = ["error", "startedAt", "completedAt", "outputRef", "outputChars", "outputStub"];
7
+ function truncateForPrompt(value, maxChars = 3e3) {
8
+ if (value === void 0 || value === null) return value;
9
+ const text = typeof value === "string" ? value : JSON.stringify(value);
10
+ if (text.length <= maxChars) return value;
11
+ return { truncated: true, total_chars: text.length, preview: text.slice(0, maxChars) };
12
+ }
13
+ class AgentAction extends BaseEntity {
14
+ constructor(props, chatId, taskId, name, stepId, args, dependsOn, status, output, error, reasoning, retries, author, approved, outputRef, outputChars, startedAt, completedAt, answerId, callId, turn, outputStub, requestedName) {
15
+ super(props);
16
+ this.props = props;
17
+ this.chatId = chatId;
18
+ this.taskId = taskId;
19
+ this.name = name;
20
+ this.stepId = stepId;
21
+ this.args = args;
22
+ this.dependsOn = dependsOn;
23
+ this.status = status;
24
+ this.output = output;
25
+ this.error = error;
26
+ this.reasoning = reasoning;
27
+ this.retries = retries;
28
+ this.author = author;
29
+ this.approved = approved;
30
+ this.outputRef = outputRef;
31
+ this.outputChars = outputChars;
32
+ this.startedAt = startedAt;
33
+ this.completedAt = completedAt;
34
+ this.answerId = answerId;
35
+ this.callId = callId;
36
+ this.turn = turn;
37
+ this.outputStub = outputStub;
38
+ this.requestedName = requestedName;
39
+ }
40
+ props;
41
+ chatId;
42
+ taskId;
43
+ name;
44
+ stepId;
45
+ args;
46
+ dependsOn;
47
+ status;
48
+ output;
49
+ error;
50
+ reasoning;
51
+ retries;
52
+ author;
53
+ approved;
54
+ outputRef;
55
+ outputChars;
56
+ startedAt;
57
+ completedAt;
58
+ answerId;
59
+ callId;
60
+ turn;
61
+ outputStub;
62
+ requestedName;
63
+ logger = new Logger();
64
+ static factory(action) {
65
+ const actionId = action._id && ObjectId.isValid(action._id) ? new ObjectId(action._id) : new ObjectId();
66
+ return AgentAction.fromJSON({ ...action, _id: actionId, status: action.status ?? "pending" });
67
+ }
68
+ static fromJSON(props) {
69
+ return new AgentAction(
70
+ props,
71
+ BaseEntity.toObjectId(props.chatId),
72
+ BaseEntity.toObjectId(props.taskId),
73
+ props.name,
74
+ props.stepId,
75
+ props.args,
76
+ props.dependsOn,
77
+ props.status,
78
+ props.output,
79
+ props.error,
80
+ props.reasoning,
81
+ props.retries,
82
+ props.author,
83
+ props.approved,
84
+ props.outputRef,
85
+ props.outputChars,
86
+ props.startedAt,
87
+ props.completedAt,
88
+ BaseEntity.toObjectId(props.answerId),
89
+ props.callId,
90
+ props.turn,
91
+ props.outputStub,
92
+ props.requestedName
93
+ );
94
+ }
95
+ toJSON() {
96
+ return {
97
+ ...super.toJSON(),
98
+ chatId: this.chatId,
99
+ taskId: this.taskId,
100
+ name: this.name,
101
+ stepId: this.stepId,
102
+ args: this.args,
103
+ dependsOn: this.dependsOn,
104
+ status: this.status,
105
+ output: this.outputStub ?? this.structuredOutput,
106
+ error: this.error,
107
+ reasoning: this.reasoning,
108
+ retries: this.retries,
109
+ author: this.author,
110
+ approved: this.approved,
111
+ outputRef: this.outputRef,
112
+ outputChars: this.outputChars,
113
+ startedAt: this.startedAt,
114
+ completedAt: this.completedAt,
115
+ answerId: this.answerId,
116
+ callId: this.callId,
117
+ turn: this.turn,
118
+ outputStub: this.outputStub,
119
+ requestedName: this.requestedName
120
+ };
121
+ }
122
+ get id() {
123
+ return this._id.toString();
124
+ }
125
+ get isReady() {
126
+ return this.status === "pending";
127
+ }
128
+ get isTerminal() {
129
+ return this.status === "completed" || this.status === "failed";
130
+ }
131
+ get canRetry() {
132
+ return this.status === "failed" && this.error?.retryable !== false;
133
+ }
134
+ static unwrap(value) {
135
+ return value?.structuredContent ? value.structuredContent : value;
136
+ }
137
+ get structuredOutput() {
138
+ return AgentAction.unwrap(this.output);
139
+ }
140
+ observationOutput(stale, maxChars) {
141
+ if (this.outputStub) return stale ? this.outputStub : this.structuredOutput;
142
+ if (this.outputRef) return this.structuredOutput;
143
+ return truncateForPrompt(this.structuredOutput, maxChars);
144
+ }
145
+ get clearedFields() {
146
+ return CLEARABLE_FIELDS.reduce((acc, field) => {
147
+ if (this[field] === void 0) acc[field] = "";
148
+ return acc;
149
+ }, {});
150
+ }
151
+ promptView(maxChars = 3e3) {
152
+ return {
153
+ ref: this.stepId ?? this.id,
154
+ tool: this.name,
155
+ args: this.args,
156
+ status: this.status,
157
+ output: this.observationOutput(false, maxChars),
158
+ error: this.error ? { message: this.error.message } : void 0
159
+ };
160
+ }
161
+ dependenciesSatisfiedBy(completedRefs) {
162
+ if (!this.dependsOn?.length) return true;
163
+ return this.dependsOn.every((ref) => completedRefs.has(ref));
164
+ }
165
+ approve() {
166
+ this.approved = true;
167
+ }
168
+ markRunning() {
169
+ this.status = "running";
170
+ this.startedAt = /* @__PURE__ */ new Date();
171
+ }
172
+ markCompleted(output) {
173
+ this.status = "completed";
174
+ this.output = output;
175
+ this.error = void 0;
176
+ this.completedAt = /* @__PURE__ */ new Date();
177
+ }
178
+ markFailed(error) {
179
+ this.status = "failed";
180
+ this.error = error;
181
+ this.completedAt = /* @__PURE__ */ new Date();
182
+ }
183
+ markSkipped() {
184
+ this.status = "skipped";
185
+ this.completedAt = /* @__PURE__ */ new Date();
186
+ }
187
+ static stubOf(offloaded) {
188
+ return {
189
+ workspace_ref: offloaded.ref,
190
+ total_chars: offloaded.totalChars,
191
+ outline: offloaded.outline,
192
+ preview: offloaded.preview,
193
+ note: STUB_NOTE
194
+ };
195
+ }
196
+ offloadOutput(offloaded) {
197
+ this.outputRef = offloaded.ref;
198
+ this.outputChars = offloaded.totalChars;
199
+ this.outputStub = void 0;
200
+ this.output = AgentAction.stubOf(offloaded);
201
+ }
202
+ keepOutputWithStub(offloaded) {
203
+ this.outputRef = offloaded.ref;
204
+ this.outputChars = offloaded.totalChars;
205
+ this.outputStub = AgentAction.stubOf(offloaded);
206
+ }
207
+ incrementRetries() {
208
+ this.retries = (this.retries ?? 0) + 1;
209
+ return this.retries;
210
+ }
211
+ resetForRetry() {
212
+ this.status = "pending";
213
+ this.error = void 0;
214
+ this.startedAt = void 0;
215
+ this.completedAt = void 0;
216
+ }
217
+ async runTool(tool, args, baseParams) {
218
+ if (!tool) {
219
+ this.markFailed({ message: `Tool "${this.name}" not found`, retryable: false });
220
+ return this;
221
+ }
222
+ const validationErrors = tool.validate(args);
223
+ if (validationErrors.length) {
224
+ this.logger.debug({ tool: tool.name, args, validationErrors }, "[Agent Action] Invalid arguments");
225
+ this.markFailed({ message: `Invalid arguments: ${validationErrors.join("; ")}`, retryable: false });
226
+ return this;
227
+ }
228
+ this.logger.debug({
229
+ tool: tool.name,
230
+ args
231
+ }, "[Agent Action] Running tool");
232
+ this.markRunning();
233
+ try {
234
+ const result = await tool.run({ ...args, ...baseParams });
235
+ this.markCompleted(result?.data);
236
+ } catch (error) {
237
+ this.markFailed({ message: error?.message ?? String(error), retryable: error?.retryable !== false });
238
+ }
239
+ return this;
240
+ }
241
+ }
242
+ export {
243
+ AgentAction,
244
+ truncateForPrompt
245
+ };