@botbotgo/runtime 1.0.0

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 (313) hide show
  1. package/.github/workflows/ci.yml +46 -0
  2. package/.github/workflows/release.yml +79 -0
  3. package/README.md +71 -0
  4. package/config/examples/memory.yaml +39 -0
  5. package/config/examples/model.yaml +21 -0
  6. package/config/examples/runtime.yaml +44 -0
  7. package/config/examples/skills.yaml +8 -0
  8. package/config/examples/tool.yaml +16 -0
  9. package/dist/config/index.d.ts +7 -0
  10. package/dist/config/index.d.ts.map +1 -0
  11. package/dist/config/index.js +4 -0
  12. package/dist/config/index.js.map +1 -0
  13. package/dist/config/loader.d.ts +41 -0
  14. package/dist/config/loader.d.ts.map +1 -0
  15. package/dist/config/loader.js +140 -0
  16. package/dist/config/loader.js.map +1 -0
  17. package/dist/config/resolveRuntimeConfig.d.ts +83 -0
  18. package/dist/config/resolveRuntimeConfig.d.ts.map +1 -0
  19. package/dist/config/resolveRuntimeConfig.js +85 -0
  20. package/dist/config/resolveRuntimeConfig.js.map +1 -0
  21. package/dist/config/resources.d.ts +112 -0
  22. package/dist/config/resources.d.ts.map +1 -0
  23. package/dist/config/resources.js +20 -0
  24. package/dist/config/resources.js.map +1 -0
  25. package/dist/config/runtimeConfigLoader.d.ts +28 -0
  26. package/dist/config/runtimeConfigLoader.d.ts.map +1 -0
  27. package/dist/config/runtimeConfigLoader.js +38 -0
  28. package/dist/config/runtimeConfigLoader.js.map +1 -0
  29. package/dist/index.d.ts +9 -0
  30. package/dist/index.d.ts.map +1 -0
  31. package/dist/index.js +5 -0
  32. package/dist/index.js.map +1 -0
  33. package/dist/runtime/agentMiddleware.d.ts +3 -0
  34. package/dist/runtime/agentMiddleware.d.ts.map +1 -0
  35. package/dist/runtime/agentMiddleware.js +2 -0
  36. package/dist/runtime/agentMiddleware.js.map +1 -0
  37. package/dist/runtime/bootstrap/runtimeFactory.d.ts +7 -0
  38. package/dist/runtime/bootstrap/runtimeFactory.d.ts.map +1 -0
  39. package/dist/runtime/bootstrap/runtimeFactory.js +139 -0
  40. package/dist/runtime/bootstrap/runtimeFactory.js.map +1 -0
  41. package/dist/runtime/bootstrap/runtimeModuleInitializer.d.ts +5 -0
  42. package/dist/runtime/bootstrap/runtimeModuleInitializer.d.ts.map +1 -0
  43. package/dist/runtime/bootstrap/runtimeModuleInitializer.js +32 -0
  44. package/dist/runtime/bootstrap/runtimeModuleInitializer.js.map +1 -0
  45. package/dist/runtime/context/agentContext.d.ts +5 -0
  46. package/dist/runtime/context/agentContext.d.ts.map +1 -0
  47. package/dist/runtime/context/agentContext.js +19 -0
  48. package/dist/runtime/context/agentContext.js.map +1 -0
  49. package/dist/runtime/context/globalContext.d.ts +19 -0
  50. package/dist/runtime/context/globalContext.d.ts.map +1 -0
  51. package/dist/runtime/context/globalContext.js +47 -0
  52. package/dist/runtime/context/globalContext.js.map +1 -0
  53. package/dist/runtime/events/eventPublisher.d.ts +15 -0
  54. package/dist/runtime/events/eventPublisher.d.ts.map +1 -0
  55. package/dist/runtime/events/eventPublisher.js +23 -0
  56. package/dist/runtime/events/eventPublisher.js.map +1 -0
  57. package/dist/runtime/execution/agentRunExecutor.d.ts +38 -0
  58. package/dist/runtime/execution/agentRunExecutor.d.ts.map +1 -0
  59. package/dist/runtime/execution/agentRunExecutor.js +378 -0
  60. package/dist/runtime/execution/agentRunExecutor.js.map +1 -0
  61. package/dist/runtime/execution/agentRunExecutor.types.d.ts +37 -0
  62. package/dist/runtime/execution/agentRunExecutor.types.d.ts.map +1 -0
  63. package/dist/runtime/execution/agentRunExecutor.types.js +2 -0
  64. package/dist/runtime/execution/agentRunExecutor.types.js.map +1 -0
  65. package/dist/runtime/execution/agentRunProgress.d.ts +8 -0
  66. package/dist/runtime/execution/agentRunProgress.d.ts.map +1 -0
  67. package/dist/runtime/execution/agentRunProgress.js +46 -0
  68. package/dist/runtime/execution/agentRunProgress.js.map +1 -0
  69. package/dist/runtime/execution/agentRunState.d.ts +44 -0
  70. package/dist/runtime/execution/agentRunState.d.ts.map +1 -0
  71. package/dist/runtime/execution/agentRunState.js +17 -0
  72. package/dist/runtime/execution/agentRunState.js.map +1 -0
  73. package/dist/runtime/execution/policies/runCompletionPolicy.d.ts +5 -0
  74. package/dist/runtime/execution/policies/runCompletionPolicy.d.ts.map +1 -0
  75. package/dist/runtime/execution/policies/runCompletionPolicy.js +30 -0
  76. package/dist/runtime/execution/policies/runCompletionPolicy.js.map +1 -0
  77. package/dist/runtime/execution/policies/runErrorPolicy.d.ts +7 -0
  78. package/dist/runtime/execution/policies/runErrorPolicy.d.ts.map +1 -0
  79. package/dist/runtime/execution/policies/runErrorPolicy.js +40 -0
  80. package/dist/runtime/execution/policies/runErrorPolicy.js.map +1 -0
  81. package/dist/runtime/execution/policies/runPromptBuilder.d.ts +10 -0
  82. package/dist/runtime/execution/policies/runPromptBuilder.d.ts.map +1 -0
  83. package/dist/runtime/execution/policies/runPromptBuilder.js +34 -0
  84. package/dist/runtime/execution/policies/runPromptBuilder.js.map +1 -0
  85. package/dist/runtime/execution/policies/runSummaryFormatter.d.ts +6 -0
  86. package/dist/runtime/execution/policies/runSummaryFormatter.d.ts.map +1 -0
  87. package/dist/runtime/execution/policies/runSummaryFormatter.js +47 -0
  88. package/dist/runtime/execution/policies/runSummaryFormatter.js.map +1 -0
  89. package/dist/runtime/execution/policies/runtimeDelay.d.ts +4 -0
  90. package/dist/runtime/execution/policies/runtimeDelay.d.ts.map +1 -0
  91. package/dist/runtime/execution/policies/runtimeDelay.js +6 -0
  92. package/dist/runtime/execution/policies/runtimeDelay.js.map +1 -0
  93. package/dist/runtime/execution/policies/toolConfigReader.d.ts +8 -0
  94. package/dist/runtime/execution/policies/toolConfigReader.d.ts.map +1 -0
  95. package/dist/runtime/execution/policies/toolConfigReader.js +91 -0
  96. package/dist/runtime/execution/policies/toolConfigReader.js.map +1 -0
  97. package/dist/runtime/human-loop/consoleHumanLoop.d.ts +21 -0
  98. package/dist/runtime/human-loop/consoleHumanLoop.d.ts.map +1 -0
  99. package/dist/runtime/human-loop/consoleHumanLoop.js +102 -0
  100. package/dist/runtime/human-loop/consoleHumanLoop.js.map +1 -0
  101. package/dist/runtime/human-loop/humanLoop.d.ts +44 -0
  102. package/dist/runtime/human-loop/humanLoop.d.ts.map +1 -0
  103. package/dist/runtime/human-loop/humanLoop.js +36 -0
  104. package/dist/runtime/human-loop/humanLoop.js.map +1 -0
  105. package/dist/runtime/index.d.ts +10 -0
  106. package/dist/runtime/index.d.ts.map +1 -0
  107. package/dist/runtime/index.js +6 -0
  108. package/dist/runtime/index.js.map +1 -0
  109. package/dist/runtime/middleware/agentToolMiddleware.d.ts +30 -0
  110. package/dist/runtime/middleware/agentToolMiddleware.d.ts.map +1 -0
  111. package/dist/runtime/middleware/agentToolMiddleware.js +259 -0
  112. package/dist/runtime/middleware/agentToolMiddleware.js.map +1 -0
  113. package/dist/runtime/middleware/commandPolicy.d.ts +8 -0
  114. package/dist/runtime/middleware/commandPolicy.d.ts.map +1 -0
  115. package/dist/runtime/middleware/commandPolicy.js +55 -0
  116. package/dist/runtime/middleware/commandPolicy.js.map +1 -0
  117. package/dist/runtime/middleware/frameworkPrompt.d.ts +4 -0
  118. package/dist/runtime/middleware/frameworkPrompt.d.ts.map +1 -0
  119. package/dist/runtime/middleware/frameworkPrompt.js +44 -0
  120. package/dist/runtime/middleware/frameworkPrompt.js.map +1 -0
  121. package/dist/runtime/middleware/index.d.ts +4 -0
  122. package/dist/runtime/middleware/index.d.ts.map +1 -0
  123. package/dist/runtime/middleware/index.js +3 -0
  124. package/dist/runtime/middleware/index.js.map +1 -0
  125. package/dist/runtime/middleware/skillPathMap.d.ts +3 -0
  126. package/dist/runtime/middleware/skillPathMap.d.ts.map +1 -0
  127. package/dist/runtime/middleware/skillPathMap.js +44 -0
  128. package/dist/runtime/middleware/skillPathMap.js.map +1 -0
  129. package/dist/runtime/middleware/toolArgsNormalizer.d.ts +21 -0
  130. package/dist/runtime/middleware/toolArgsNormalizer.d.ts.map +1 -0
  131. package/dist/runtime/middleware/toolArgsNormalizer.js +227 -0
  132. package/dist/runtime/middleware/toolArgsNormalizer.js.map +1 -0
  133. package/dist/runtime/middleware/toolCallGuard.d.ts +8 -0
  134. package/dist/runtime/middleware/toolCallGuard.d.ts.map +1 -0
  135. package/dist/runtime/middleware/toolCallGuard.js +60 -0
  136. package/dist/runtime/middleware/toolCallGuard.js.map +1 -0
  137. package/dist/runtime/middleware/toolFsHandlers.d.ts +12 -0
  138. package/dist/runtime/middleware/toolFsHandlers.d.ts.map +1 -0
  139. package/dist/runtime/middleware/toolFsHandlers.js +79 -0
  140. package/dist/runtime/middleware/toolFsHandlers.js.map +1 -0
  141. package/dist/runtime/middleware/toolRequestParser.d.ts +14 -0
  142. package/dist/runtime/middleware/toolRequestParser.d.ts.map +1 -0
  143. package/dist/runtime/middleware/toolRequestParser.js +72 -0
  144. package/dist/runtime/middleware/toolRequestParser.js.map +1 -0
  145. package/dist/runtime/middleware/types.d.ts +87 -0
  146. package/dist/runtime/middleware/types.d.ts.map +1 -0
  147. package/dist/runtime/middleware/types.js +3 -0
  148. package/dist/runtime/middleware/types.js.map +1 -0
  149. package/dist/runtime/providers/backendResolver.d.ts +26 -0
  150. package/dist/runtime/providers/backendResolver.d.ts.map +1 -0
  151. package/dist/runtime/providers/backendResolver.js +73 -0
  152. package/dist/runtime/providers/backendResolver.js.map +1 -0
  153. package/dist/runtime/providers/index.d.ts +14 -0
  154. package/dist/runtime/providers/index.d.ts.map +1 -0
  155. package/dist/runtime/providers/index.js +10 -0
  156. package/dist/runtime/providers/index.js.map +1 -0
  157. package/dist/runtime/providers/langchainRuntime.d.ts +11 -0
  158. package/dist/runtime/providers/langchainRuntime.d.ts.map +1 -0
  159. package/dist/runtime/providers/langchainRuntime.js +45 -0
  160. package/dist/runtime/providers/langchainRuntime.js.map +1 -0
  161. package/dist/runtime/providers/localShellBackend.d.ts +10 -0
  162. package/dist/runtime/providers/localShellBackend.d.ts.map +1 -0
  163. package/dist/runtime/providers/localShellBackend.js +23 -0
  164. package/dist/runtime/providers/localShellBackend.js.map +1 -0
  165. package/dist/runtime/providers/openaiDeepAgent.d.ts +9 -0
  166. package/dist/runtime/providers/openaiDeepAgent.d.ts.map +1 -0
  167. package/dist/runtime/providers/openaiDeepAgent.js +7 -0
  168. package/dist/runtime/providers/openaiDeepAgent.js.map +1 -0
  169. package/dist/runtime/providers/openaiLocalAgent.d.ts +17 -0
  170. package/dist/runtime/providers/openaiLocalAgent.d.ts.map +1 -0
  171. package/dist/runtime/providers/openaiLocalAgent.js +26 -0
  172. package/dist/runtime/providers/openaiLocalAgent.js.map +1 -0
  173. package/dist/runtime/providers/openaiLocalAgentFactory.d.ts +36 -0
  174. package/dist/runtime/providers/openaiLocalAgentFactory.d.ts.map +1 -0
  175. package/dist/runtime/providers/openaiLocalAgentFactory.js +139 -0
  176. package/dist/runtime/providers/openaiLocalAgentFactory.js.map +1 -0
  177. package/dist/runtime/providers/shared/agentProbe.d.ts +4 -0
  178. package/dist/runtime/providers/shared/agentProbe.d.ts.map +1 -0
  179. package/dist/runtime/providers/shared/agentProbe.js +17 -0
  180. package/dist/runtime/providers/shared/agentProbe.js.map +1 -0
  181. package/dist/runtime/providers/shared/moduleFallback.d.ts +2 -0
  182. package/dist/runtime/providers/shared/moduleFallback.d.ts.map +1 -0
  183. package/dist/runtime/providers/shared/moduleFallback.js +34 -0
  184. package/dist/runtime/providers/shared/moduleFallback.js.map +1 -0
  185. package/dist/runtime/providers/shared/resourceCloser.d.ts +6 -0
  186. package/dist/runtime/providers/shared/resourceCloser.d.ts.map +1 -0
  187. package/dist/runtime/providers/shared/resourceCloser.js +30 -0
  188. package/dist/runtime/providers/shared/resourceCloser.js.map +1 -0
  189. package/dist/runtime/runtimeService.d.ts +109 -0
  190. package/dist/runtime/runtimeService.d.ts.map +1 -0
  191. package/dist/runtime/runtimeService.js +90 -0
  192. package/dist/runtime/runtimeService.js.map +1 -0
  193. package/dist/runtime/stream/agentMessages.d.ts +40 -0
  194. package/dist/runtime/stream/agentMessages.d.ts.map +1 -0
  195. package/dist/runtime/stream/agentMessages.js +44 -0
  196. package/dist/runtime/stream/agentMessages.js.map +1 -0
  197. package/dist/runtime/stream/agentStream.d.ts +31 -0
  198. package/dist/runtime/stream/agentStream.d.ts.map +1 -0
  199. package/dist/runtime/stream/agentStream.js +106 -0
  200. package/dist/runtime/stream/agentStream.js.map +1 -0
  201. package/dist/runtime/stream/messageSummary.d.ts +20 -0
  202. package/dist/runtime/stream/messageSummary.d.ts.map +1 -0
  203. package/dist/runtime/stream/messageSummary.js +150 -0
  204. package/dist/runtime/stream/messageSummary.js.map +1 -0
  205. package/dist/runtime/stream/runArtifacts.d.ts +9 -0
  206. package/dist/runtime/stream/runArtifacts.d.ts.map +1 -0
  207. package/dist/runtime/stream/runArtifacts.js +48 -0
  208. package/dist/runtime/stream/runArtifacts.js.map +1 -0
  209. package/dist/state/index.d.ts +7 -0
  210. package/dist/state/index.d.ts.map +1 -0
  211. package/dist/state/index.js +4 -0
  212. package/dist/state/index.js.map +1 -0
  213. package/dist/state/runState.d.ts +36 -0
  214. package/dist/state/runState.d.ts.map +1 -0
  215. package/dist/state/runState.js +51 -0
  216. package/dist/state/runState.js.map +1 -0
  217. package/dist/state/todos.d.ts +19 -0
  218. package/dist/state/todos.d.ts.map +1 -0
  219. package/dist/state/todos.js +45 -0
  220. package/dist/state/todos.js.map +1 -0
  221. package/dist/state/workspaceRunSession.d.ts +32 -0
  222. package/dist/state/workspaceRunSession.d.ts.map +1 -0
  223. package/dist/state/workspaceRunSession.js +67 -0
  224. package/dist/state/workspaceRunSession.js.map +1 -0
  225. package/dist/state/workspaceState.d.ts +94 -0
  226. package/dist/state/workspaceState.d.ts.map +1 -0
  227. package/dist/state/workspaceState.js +119 -0
  228. package/dist/state/workspaceState.js.map +1 -0
  229. package/dist/types.d.ts +2 -0
  230. package/dist/types.d.ts.map +1 -0
  231. package/dist/types.js +2 -0
  232. package/dist/types.js.map +1 -0
  233. package/example/.tsbuildinfo +1 -0
  234. package/example/build/.tsbuildinfo +1 -0
  235. package/example/config/memory.yaml +35 -0
  236. package/example/config/model.yaml +14 -0
  237. package/example/config/runtime.yaml +46 -0
  238. package/example/config/tool.yaml +24 -0
  239. package/example/index.ts +159 -0
  240. package/example/package-lock.json +1396 -0
  241. package/example/package.json +26 -0
  242. package/example/serve-output.mjs +52 -0
  243. package/example/tsconfig.json +19 -0
  244. package/package.json +73 -0
  245. package/scripts/resolve-deps.js +40 -0
  246. package/src/config/index.ts +29 -0
  247. package/src/config/loader.ts +174 -0
  248. package/src/config/resolveRuntimeConfig.ts +160 -0
  249. package/src/config/resources.ts +152 -0
  250. package/src/config/runtimeConfigLoader.ts +68 -0
  251. package/src/external-modules.d.ts +20 -0
  252. package/src/index.ts +36 -0
  253. package/src/runtime/agentMiddleware.ts +6 -0
  254. package/src/runtime/bootstrap/runtimeFactory.ts +212 -0
  255. package/src/runtime/bootstrap/runtimeModuleInitializer.ts +34 -0
  256. package/src/runtime/context/agentContext.ts +24 -0
  257. package/src/runtime/context/globalContext.ts +70 -0
  258. package/src/runtime/events/eventPublisher.ts +45 -0
  259. package/src/runtime/execution/agentRunExecutor.ts +499 -0
  260. package/src/runtime/execution/agentRunExecutor.types.ts +39 -0
  261. package/src/runtime/execution/agentRunProgress.ts +67 -0
  262. package/src/runtime/execution/agentRunState.ts +66 -0
  263. package/src/runtime/execution/policies/runCompletionPolicy.ts +30 -0
  264. package/src/runtime/execution/policies/runErrorPolicy.ts +50 -0
  265. package/src/runtime/execution/policies/runPromptBuilder.ts +39 -0
  266. package/src/runtime/execution/policies/runSummaryFormatter.ts +57 -0
  267. package/src/runtime/execution/policies/runtimeDelay.ts +5 -0
  268. package/src/runtime/execution/policies/toolConfigReader.ts +107 -0
  269. package/src/runtime/human-loop/consoleHumanLoop.ts +113 -0
  270. package/src/runtime/human-loop/humanLoop.ts +90 -0
  271. package/src/runtime/index.ts +36 -0
  272. package/src/runtime/middleware/agentToolMiddleware.ts +329 -0
  273. package/src/runtime/middleware/commandPolicy.ts +65 -0
  274. package/src/runtime/middleware/frameworkPrompt.ts +51 -0
  275. package/src/runtime/middleware/index.ts +7 -0
  276. package/src/runtime/middleware/skillPathMap.ts +49 -0
  277. package/src/runtime/middleware/toolArgsNormalizer.ts +277 -0
  278. package/src/runtime/middleware/toolCallGuard.ts +73 -0
  279. package/src/runtime/middleware/toolFsHandlers.ts +94 -0
  280. package/src/runtime/middleware/toolRequestParser.ts +84 -0
  281. package/src/runtime/middleware/types.ts +91 -0
  282. package/src/runtime/providers/backendResolver.ts +127 -0
  283. package/src/runtime/providers/index.ts +19 -0
  284. package/src/runtime/providers/langchainRuntime.ts +67 -0
  285. package/src/runtime/providers/localShellBackend.ts +54 -0
  286. package/src/runtime/providers/openaiDeepAgent.ts +17 -0
  287. package/src/runtime/providers/openaiLocalAgent.ts +35 -0
  288. package/src/runtime/providers/openaiLocalAgentFactory.ts +185 -0
  289. package/src/runtime/providers/shared/agentProbe.ts +24 -0
  290. package/src/runtime/providers/shared/moduleFallback.ts +41 -0
  291. package/src/runtime/providers/shared/resourceCloser.ts +30 -0
  292. package/src/runtime/runtimeService.ts +205 -0
  293. package/src/runtime/stream/agentMessages.ts +72 -0
  294. package/src/runtime/stream/agentStream.ts +168 -0
  295. package/src/runtime/stream/messageSummary.ts +164 -0
  296. package/src/runtime/stream/runArtifacts.ts +72 -0
  297. package/src/state/index.ts +19 -0
  298. package/src/state/runState.ts +84 -0
  299. package/src/state/todos.ts +59 -0
  300. package/src/state/workspaceRunSession.ts +96 -0
  301. package/src/state/workspaceState.ts +199 -0
  302. package/src/types/easynet-agent-common.d.ts +62 -0
  303. package/src/types.ts +1 -0
  304. package/test/integration/runtime-live.integration.test.ts +30 -0
  305. package/test/unit/config/loader.test.ts +429 -0
  306. package/test/unit/runtime/agentContext.test.ts +23 -0
  307. package/test/unit/runtime/agentRuntime.test.ts +99 -0
  308. package/test/unit/runtime/consoleHumanLoop.test.ts +52 -0
  309. package/test/unit/runtime/events.test.ts +11 -0
  310. package/test/unit/runtime/globalContext.test.ts +34 -0
  311. package/test/unit/runtime/humanLoop.test.ts +104 -0
  312. package/test/unit/runtime/toolArgsNormalizer.test.ts +136 -0
  313. package/tsconfig.json +18 -0
@@ -0,0 +1,19 @@
1
+ export { createTodoPersister, normalizeTodos, TodoPersister } from "./todos.js";
2
+ export type {
3
+ CreateTodoPersisterOptions,
4
+ NormalizedTodo,
5
+ } from "./todos.js";
6
+
7
+ export { createAgentRunStateStore, AgentRunStateStore } from "./runState.js";
8
+ export type {
9
+ AgentRunState,
10
+ AgentRunStatus,
11
+ CreateAgentRunStateStoreOptions,
12
+ UpdateAgentRunStateOptions,
13
+ } from "./runState.js";
14
+
15
+ export { createAgentWorkspaceState, AgentWorkspaceStateManager } from "./workspaceState.js";
16
+ export type {
17
+ CreateAgentWorkspaceStateOptions,
18
+ AgentWorkspaceState,
19
+ } from "./workspaceState.js";
@@ -0,0 +1,84 @@
1
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
2
+ import { dirname } from "node:path";
3
+
4
+ export type AgentRunStatus = "running" | "completed" | "failed";
5
+
6
+ export interface AgentRunState {
7
+ prompt: string;
8
+ threadId: string;
9
+ status: AgentRunStatus;
10
+ startedAt: string;
11
+ updatedAt: string;
12
+ stepCount: number;
13
+ lastSummary: string;
14
+ artifacts: Record<string, unknown>;
15
+ }
16
+
17
+ export interface CreateAgentRunStateStoreOptions {
18
+ filePath: string;
19
+ getArtifacts?: () => Record<string, unknown>;
20
+ }
21
+
22
+ export interface UpdateAgentRunStateOptions {
23
+ prompt: string;
24
+ threadId: string;
25
+ previousState?: AgentRunState | null;
26
+ stepCount: number;
27
+ lastSummary: string;
28
+ status: AgentRunStatus;
29
+ updatedAt?: string;
30
+ }
31
+
32
+ export class AgentRunStateStore {
33
+ public readonly filePath: string;
34
+ private readonly getArtifacts: () => Record<string, unknown>;
35
+
36
+ public constructor(options: CreateAgentRunStateStoreOptions) {
37
+ this.filePath = options.filePath;
38
+ this.getArtifacts = options.getArtifacts ?? (() => ({}));
39
+ }
40
+
41
+ public async read(): Promise<AgentRunState | null> {
42
+ try {
43
+ return JSON.parse(await readFile(this.filePath, "utf8")) as AgentRunState;
44
+ } catch {
45
+ return null;
46
+ }
47
+ }
48
+
49
+ public async write(state: AgentRunState): Promise<void> {
50
+ await mkdir(dirname(this.filePath), { recursive: true });
51
+ await writeFile(this.filePath, `${JSON.stringify(state, null, 2)}\n`, "utf8");
52
+ }
53
+
54
+ public async update(params: UpdateAgentRunStateOptions): Promise<AgentRunState> {
55
+ const now = params.updatedAt ?? new Date().toISOString();
56
+ const state: AgentRunState = {
57
+ prompt: params.prompt,
58
+ threadId: params.threadId,
59
+ status: params.status,
60
+ startedAt: params.previousState?.status === "running"
61
+ ? params.previousState.startedAt
62
+ : now,
63
+ updatedAt: now,
64
+ stepCount: params.stepCount,
65
+ lastSummary: params.lastSummary,
66
+ artifacts: this.getArtifacts(),
67
+ };
68
+ await this.write(state);
69
+ return state;
70
+ }
71
+
72
+ public buildResumePrompt(basePrompt: string, previousState: AgentRunState | null, resumeHint: string): string {
73
+ if (previousState?.status !== "running") return basePrompt;
74
+ return `${basePrompt}\n\n${resumeHint}`;
75
+ }
76
+
77
+ public getThreadId(previousState: AgentRunState | null, fallbackThreadId: string): string {
78
+ return previousState?.status === "running" ? previousState.threadId : fallbackThreadId;
79
+ }
80
+ }
81
+
82
+ export function createAgentRunStateStore(options: CreateAgentRunStateStoreOptions) {
83
+ return new AgentRunStateStore(options);
84
+ }
@@ -0,0 +1,59 @@
1
+ import { mkdir, writeFile } from "node:fs/promises";
2
+ import { dirname } from "node:path";
3
+
4
+ export interface NormalizedTodo {
5
+ content: unknown;
6
+ status: string;
7
+ }
8
+
9
+ export interface CreateTodoPersisterOptions {
10
+ filePath: string;
11
+ logger?: (message: string) => void;
12
+ }
13
+
14
+ export function normalizeTodos(todos: unknown): NormalizedTodo[] {
15
+ return TodoPersister.normalize(todos);
16
+ }
17
+
18
+ export class TodoPersister {
19
+ private readonly filePath: string;
20
+ private readonly logger: (message: string) => void;
21
+ private lastPersistedJson = "";
22
+
23
+ public constructor(options: CreateTodoPersisterOptions) {
24
+ this.filePath = options.filePath;
25
+ this.logger = options.logger ?? (() => {});
26
+ }
27
+
28
+ public static normalize(todos: unknown): NormalizedTodo[] {
29
+ if (!Array.isArray(todos) || todos.length === 0) return [];
30
+
31
+ return todos
32
+ .map((todo) => {
33
+ if (!todo || typeof todo !== "object" || !("content" in todo)) return null;
34
+ return {
35
+ content: (todo as { content: unknown }).content,
36
+ status: (todo as { status?: string }).status ?? "pending",
37
+ };
38
+ })
39
+ .filter((todo): todo is NormalizedTodo => todo !== null);
40
+ }
41
+
42
+ public async persist(todos: unknown): Promise<void> {
43
+ const normalized = TodoPersister.normalize(todos);
44
+ if (normalized.length === 0) return;
45
+
46
+ const nextJson = JSON.stringify(normalized, null, 2);
47
+ if (nextJson === this.lastPersistedJson) return;
48
+ this.lastPersistedJson = nextJson;
49
+
50
+ await mkdir(dirname(this.filePath), { recursive: true });
51
+ await writeFile(this.filePath, nextJson, "utf8");
52
+ this.logger(`[todos] persisted ${normalized.length} item(s) -> ${this.filePath}`);
53
+ }
54
+ }
55
+
56
+ export function createTodoPersister(options: CreateTodoPersisterOptions) {
57
+ const persister = new TodoPersister(options);
58
+ return persister.persist.bind(persister);
59
+ }
@@ -0,0 +1,96 @@
1
+ import type { AgentRunState, AgentRunStateStore } from "./runState.js";
2
+ import type { AgentRuntimeEventPublisher } from "../runtime/events/eventPublisher.js";
3
+
4
+ export interface PreparedWorkspaceRun {
5
+ previousState: AgentRunState | null;
6
+ threadId: string;
7
+ config: {
8
+ configurable: {
9
+ thread_id: string;
10
+ };
11
+ };
12
+ input: {
13
+ messages: Array<{
14
+ role: "user";
15
+ content: string;
16
+ }>;
17
+ };
18
+ start(): Promise<void>;
19
+ update(stepCount: number, lastSummary: string): Promise<void>;
20
+ finish(stepCount: number, lastSummary: string): Promise<void>;
21
+ }
22
+
23
+ export class WorkspaceRunSessionFactory {
24
+ public static create(params: {
25
+ prompt: string;
26
+ threadId: string;
27
+ previousState: AgentRunState | null;
28
+ resumeHint: string;
29
+ runState: AgentRunStateStore;
30
+ events?: AgentRuntimeEventPublisher;
31
+ isCompleted: () => boolean;
32
+ }): PreparedWorkspaceRun {
33
+ return {
34
+ previousState: params.previousState,
35
+ threadId: params.threadId,
36
+ config: { configurable: { thread_id: params.threadId } },
37
+ input: {
38
+ messages: [{
39
+ role: "user",
40
+ content: params.runState.buildResumePrompt(params.prompt, params.previousState, params.resumeHint),
41
+ }],
42
+ },
43
+ start: async () => {
44
+ await params.runState.update({
45
+ prompt: params.prompt,
46
+ threadId: params.threadId,
47
+ stepCount: 0,
48
+ lastSummary: "",
49
+ status: "running",
50
+ previousState: params.previousState,
51
+ });
52
+ params.events?.emit({
53
+ name: "agent.runtime2.workspace.run.start",
54
+ from: "agent-runtime2.workspace",
55
+ to: "agent-runtime2.state",
56
+ payload: { threadId: params.threadId, prompt: params.prompt },
57
+ });
58
+ },
59
+ update: async (stepCount, lastSummary) => {
60
+ await params.runState.update({
61
+ prompt: params.prompt,
62
+ threadId: params.threadId,
63
+ stepCount,
64
+ lastSummary,
65
+ status: "running",
66
+ previousState: params.previousState,
67
+ updatedAt: new Date().toISOString(),
68
+ });
69
+ params.events?.emit({
70
+ name: "agent.runtime2.workspace.run.update",
71
+ from: "agent-runtime2.workspace",
72
+ to: "agent-runtime2.state",
73
+ payload: { threadId: params.threadId, stepCount, lastSummary },
74
+ });
75
+ },
76
+ finish: async (stepCount, lastSummary) => {
77
+ const status = params.isCompleted() ? "completed" : "failed";
78
+ await params.runState.update({
79
+ prompt: params.prompt,
80
+ threadId: params.threadId,
81
+ stepCount,
82
+ lastSummary,
83
+ status,
84
+ previousState: params.previousState,
85
+ updatedAt: new Date().toISOString(),
86
+ });
87
+ params.events?.emit({
88
+ name: "agent.runtime2.workspace.run.finish",
89
+ from: "agent-runtime2.workspace",
90
+ to: "agent-runtime2.state",
91
+ payload: { threadId: params.threadId, stepCount, lastSummary, status },
92
+ });
93
+ },
94
+ };
95
+ }
96
+ }
@@ -0,0 +1,199 @@
1
+ import { existsSync } from "node:fs";
2
+ import { unlink } from "node:fs/promises";
3
+ import { resolve } from "node:path";
4
+ import { AgentRunStateStore, createAgentRunStateStore, type AgentRunState } from "./runState.js";
5
+ import { createTodoPersister } from "./todos.js";
6
+ import { type AgentRuntimeEventPublisher } from "../runtime/events/eventPublisher.js";
7
+ import { WorkspaceRunSessionFactory, type PreparedWorkspaceRun } from "./workspaceRunSession.js";
8
+
9
+ export interface CreateAgentWorkspaceStateOptions {
10
+ rootDir: string;
11
+ artifacts?: Array<{ key: string; path: string }>;
12
+ stateDirName?: string;
13
+ legacyOutputState?: boolean;
14
+ todosLogger?: (message: string) => void;
15
+ events?: AgentRuntimeEventPublisher;
16
+ }
17
+
18
+ export interface AgentWorkspaceState {
19
+ stateDir: string;
20
+ todosFile: string;
21
+ runStateFile: string;
22
+ artifactFiles: Record<string, string>;
23
+ prepareRun(params: { prompt: string; fallbackThreadId?: string; resumeHint: string }): Promise<PreparedWorkspaceRun>;
24
+ readRunState(): Promise<AgentRunState | null>;
25
+ getThreadId(previousState: AgentRunState | null, fallbackThreadId: string): string;
26
+ buildResumePrompt(basePrompt: string, previousState: AgentRunState | null, resumeHint: string): string;
27
+ startRun(params: { prompt: string; threadId: string; previousState: AgentRunState | null }): Promise<void>;
28
+ updateRun(params: {
29
+ prompt: string;
30
+ threadId: string;
31
+ previousState: AgentRunState | null;
32
+ stepCount: number;
33
+ lastSummary: string;
34
+ }): Promise<void>;
35
+ finishRun(params: {
36
+ prompt: string;
37
+ threadId: string;
38
+ previousState: AgentRunState | null;
39
+ stepCount: number;
40
+ lastSummary: string;
41
+ }): Promise<void>;
42
+ resetForFreshRun(previousState: AgentRunState | null): Promise<void>;
43
+ persistTodos(todos: unknown): Promise<void>;
44
+ }
45
+
46
+ export class AgentWorkspaceStateManager implements AgentWorkspaceState {
47
+ public readonly stateDir: string;
48
+ public readonly todosFile: string;
49
+ public readonly runStateFile: string;
50
+ public readonly artifactFiles: Record<string, string>;
51
+
52
+ private readonly legacyOutputState: boolean;
53
+ private readonly legacyTodosFile: string;
54
+ private readonly legacyRunStateFile: string;
55
+ private readonly persistTodosHandler: (todos: unknown) => Promise<void>;
56
+ private readonly runState: AgentRunStateStore;
57
+ private readonly events?: AgentRuntimeEventPublisher;
58
+
59
+ public constructor(options: CreateAgentWorkspaceStateOptions) {
60
+ const {
61
+ rootDir,
62
+ artifacts = [],
63
+ stateDirName = ".agent",
64
+ legacyOutputState = true,
65
+ todosLogger,
66
+ events,
67
+ } = options;
68
+
69
+ this.stateDir = resolve(rootDir, stateDirName);
70
+ this.todosFile = resolve(this.stateDir, "todos.json");
71
+ this.runStateFile = resolve(this.stateDir, "run-state.json");
72
+ this.artifactFiles = Object.fromEntries(artifacts.map((artifact) => [artifact.key, resolve(rootDir, artifact.path)]));
73
+ this.legacyOutputState = legacyOutputState;
74
+ this.legacyTodosFile = resolve(rootDir, "output", "todos.json");
75
+ this.legacyRunStateFile = resolve(rootDir, "output", "run-state.json");
76
+ this.events = events;
77
+ this.persistTodosHandler = createTodoPersister({ filePath: this.todosFile, logger: todosLogger });
78
+ this.runState = createAgentRunStateStore({
79
+ filePath: this.runStateFile,
80
+ getArtifacts: () => ({
81
+ todosPath: this.todosFile,
82
+ todosPresent: existsSync(this.todosFile),
83
+ ...Object.fromEntries(
84
+ Object.entries(this.artifactFiles).flatMap(([key, file]) => [[`${key}Path`, file], [`${key}Present`, existsSync(file)]]),
85
+ ),
86
+ }),
87
+ });
88
+ }
89
+
90
+ public async prepareRun(params: {
91
+ prompt: string;
92
+ fallbackThreadId?: string;
93
+ resumeHint: string;
94
+ }): Promise<PreparedWorkspaceRun> {
95
+ const previousState = await this.runState.read();
96
+ const threadId = this.runState.getThreadId(previousState, params.fallbackThreadId ?? `t-${Date.now()}`);
97
+ this.events?.emit({
98
+ name: "agent.runtime2.workspace.prepare",
99
+ from: "agent-runtime2.runtime",
100
+ to: "agent-runtime2.workspace",
101
+ payload: { threadId, previousState },
102
+ });
103
+ await this.resetForFreshRun(previousState);
104
+ return WorkspaceRunSessionFactory.create({
105
+ prompt: params.prompt,
106
+ threadId,
107
+ previousState,
108
+ resumeHint: params.resumeHint,
109
+ runState: this.runState,
110
+ events: this.events,
111
+ isCompleted: this.isCompleted.bind(this),
112
+ });
113
+ }
114
+
115
+ public readRunState(): Promise<AgentRunState | null> {
116
+ return this.runState.read();
117
+ }
118
+
119
+ public getThreadId(previousState: AgentRunState | null, fallbackThreadId: string): string {
120
+ return this.runState.getThreadId(previousState, fallbackThreadId);
121
+ }
122
+
123
+ public buildResumePrompt(basePrompt: string, previousState: AgentRunState | null, resumeHint: string): string {
124
+ return this.runState.buildResumePrompt(basePrompt, previousState, resumeHint);
125
+ }
126
+
127
+ public async startRun(params: {
128
+ prompt: string;
129
+ threadId: string;
130
+ previousState: AgentRunState | null;
131
+ }): Promise<void> {
132
+ await this.runState.update({
133
+ prompt: params.prompt,
134
+ threadId: params.threadId,
135
+ stepCount: 0,
136
+ lastSummary: "",
137
+ status: "running",
138
+ previousState: params.previousState,
139
+ });
140
+ }
141
+
142
+ public async updateRun(params: {
143
+ prompt: string;
144
+ threadId: string;
145
+ previousState: AgentRunState | null;
146
+ stepCount: number;
147
+ lastSummary: string;
148
+ }): Promise<void> {
149
+ await this.runState.update({
150
+ prompt: params.prompt,
151
+ threadId: params.threadId,
152
+ stepCount: params.stepCount,
153
+ lastSummary: params.lastSummary,
154
+ status: "running",
155
+ previousState: params.previousState,
156
+ updatedAt: new Date().toISOString(),
157
+ });
158
+ }
159
+
160
+ public async finishRun(params: {
161
+ prompt: string;
162
+ threadId: string;
163
+ previousState: AgentRunState | null;
164
+ stepCount: number;
165
+ lastSummary: string;
166
+ }): Promise<void> {
167
+ await this.runState.update({
168
+ prompt: params.prompt,
169
+ threadId: params.threadId,
170
+ stepCount: params.stepCount,
171
+ lastSummary: params.lastSummary,
172
+ status: this.isCompleted() ? "completed" : "failed",
173
+ previousState: params.previousState,
174
+ updatedAt: new Date().toISOString(),
175
+ });
176
+ }
177
+
178
+ public async resetForFreshRun(previousState: AgentRunState | null): Promise<void> {
179
+ if (previousState?.status !== "running") return;
180
+ if (!this.legacyOutputState) {
181
+ await Promise.all([
182
+ unlink(this.legacyTodosFile).catch(() => {}),
183
+ unlink(this.legacyRunStateFile).catch(() => {}),
184
+ ]);
185
+ }
186
+ }
187
+
188
+ public async persistTodos(todos: unknown): Promise<void> {
189
+ await this.persistTodosHandler(todos);
190
+ }
191
+
192
+ private isCompleted(): boolean {
193
+ return Object.values(this.artifactFiles).every((file) => existsSync(file));
194
+ }
195
+ }
196
+
197
+ export function createAgentWorkspaceState(options: CreateAgentWorkspaceStateOptions): AgentWorkspaceState {
198
+ return new AgentWorkspaceStateManager(options);
199
+ }
@@ -0,0 +1,62 @@
1
+ declare module "@botbotgo/common/config" {
2
+ export function loadYamlFile<T = unknown>(filePath: string, options?: unknown): Promise<T | undefined>;
3
+ export function parseYamlContent<T = unknown>(content: string, options?: unknown): T;
4
+ }
5
+
6
+ declare module "@botbotgo/common/context" {
7
+ export interface AgentContext {
8
+ set<T>(token: symbol, value: T): void;
9
+ get<T>(token: symbol): T;
10
+ has(token: symbol): boolean;
11
+ tryGet<T>(token: symbol): T | undefined;
12
+ }
13
+
14
+ export const AgentContextTokens: Record<string, symbol>;
15
+ export function getDefaultAgentContext(): AgentContext;
16
+ }
17
+
18
+ declare module "@botbotgo/common/events" {
19
+ export interface AgentEvent<TPayload = unknown> {
20
+ id: string;
21
+ name: string;
22
+ from: string;
23
+ to: string;
24
+ at: string;
25
+ payload?: TPayload;
26
+ }
27
+
28
+ export type AgentEventListener = (event: AgentEvent) => void;
29
+
30
+ export interface AgentEventBus {
31
+ publish<TPayload = unknown>(event: Omit<AgentEvent<TPayload>, "id" | "at">): AgentEvent<TPayload>;
32
+ subscribe(listener: AgentEventListener): () => void;
33
+ }
34
+
35
+ export function createAgentEventBus(): AgentEventBus;
36
+ }
37
+
38
+ declare module "@botbotgo/common" {
39
+ export * from "@botbotgo/common/context";
40
+ export * from "@botbotgo/common/events";
41
+
42
+ export interface Runtime2EventDebugConfig {
43
+ run?: boolean;
44
+ workspace?: boolean;
45
+ toolCall?: boolean;
46
+ stream?: boolean;
47
+ close?: boolean;
48
+ }
49
+
50
+ export interface Runtime2EventRuntimeConfig {
51
+ debug?: Runtime2EventDebugConfig;
52
+ }
53
+
54
+ export interface Runtime2TreeEventListenerOptions {
55
+ writer?: (line: string) => void;
56
+ runtimeConfig?: Runtime2EventRuntimeConfig;
57
+ }
58
+
59
+ export function createRuntime2TreeEventListener(
60
+ options?: Runtime2TreeEventListenerOptions,
61
+ ): (event: AgentEvent) => void;
62
+ }
package/src/types.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./config/resources.js";
@@ -0,0 +1,30 @@
1
+ import test from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import { resolve } from "node:path";
4
+ import { createAgentRuntime2 } from "../../src/index.ts";
5
+
6
+ const shouldRun = process.env.RUN_REAL_RUNTIME2_INTEGRATION === "1";
7
+
8
+ test("createAgentRuntime2 runs against a real model backend", { timeout: 180_000 }, async (t) => {
9
+ if (!shouldRun) {
10
+ t.skip("Set RUN_REAL_RUNTIME2_INTEGRATION=1 to run the live runtime integration test.");
11
+ return;
12
+ }
13
+
14
+ const rootDir = resolve(process.cwd(), "example");
15
+ const runtime = await createAgentRuntime2({
16
+ rootDir,
17
+ configDir: resolve(rootDir, "config"),
18
+ modelConfigPath: resolve(rootDir, "config/model.yaml"),
19
+ memoryConfigPath: resolve(rootDir, "config/memory.yaml"),
20
+ toolConfigPath: resolve(rootDir, "config/tool.yaml"),
21
+ });
22
+
23
+ try {
24
+ const result = await runtime.run("Reply with the single word READY.");
25
+ assert.equal(typeof result.text, "string");
26
+ assert.match(result.text.toUpperCase(), /READY/);
27
+ } finally {
28
+ await runtime.close();
29
+ }
30
+ });