@infinityi/engine-lib 1.3.1 → 1.4.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 (401) hide show
  1. package/README.md +81 -445
  2. package/dist/agent/index.js +14 -8
  3. package/dist/context/index.d.ts +1 -1
  4. package/dist/context/index.js +8 -5
  5. package/dist/context/providers.d.ts +3 -3
  6. package/dist/context/types.d.ts +16 -1
  7. package/dist/errors.d.ts +18 -0
  8. package/dist/errors.js +6 -1
  9. package/dist/events/index.js +2 -1
  10. package/dist/execution/index.js +9 -4
  11. package/dist/execution/types.d.ts +14 -0
  12. package/dist/index-37x76zdn.js +4 -0
  13. package/dist/index-4c15ysa8.js +84 -0
  14. package/dist/{index-pwr8179t.js → index-7nb9qwa1.js} +23 -14
  15. package/dist/{index-jxgj4z08.js → index-9egrqxkf.js} +4 -0
  16. package/dist/index-9rr5dkzh.js +0 -0
  17. package/dist/{index-w34cbktd.js → index-a67ej96j.js} +1 -0
  18. package/dist/{index-64tt9696.js → index-aed6fe4z.js} +3 -3
  19. package/dist/{index-7690reng.js → index-ajr3nk10.js} +15 -1
  20. package/dist/index-c6kgts41.js +0 -0
  21. package/dist/{index-xsv43c5j.js → index-e14g2e48.js} +2 -2
  22. package/dist/index-k0q7x4mz.js +54 -0
  23. package/dist/index-mnx5mqbs.js +102 -0
  24. package/dist/index-mr1hs98z.js +661 -0
  25. package/dist/{index-yrqrxwjt.js → index-nvdsr51v.js} +4 -38
  26. package/dist/{index-jp2b31xs.js → index-vwcyawfk.js} +4 -4
  27. package/dist/index-ycjsqfpq.js +39 -0
  28. package/dist/{index-bqg01r42.js → index-zdggff0y.js} +183 -180
  29. package/dist/index.d.ts +2 -2
  30. package/dist/index.js +49 -38
  31. package/dist/lifecycle/index.js +2 -0
  32. package/dist/messages/index.js +1 -0
  33. package/dist/providers/index.js +5 -4
  34. package/dist/retrieval/chunking.d.ts +8 -0
  35. package/dist/retrieval/context.d.ts +4 -0
  36. package/dist/retrieval/index.d.ts +19 -0
  37. package/dist/retrieval/index.js +747 -0
  38. package/dist/retrieval/loaders.d.ts +8 -0
  39. package/dist/retrieval/memory.d.ts +29 -0
  40. package/dist/retrieval/retriever.d.ts +8 -0
  41. package/dist/retrieval/types.d.ts +253 -0
  42. package/dist/retrieval/utils.d.ts +11 -0
  43. package/dist/retrieval/vector-store.d.ts +13 -0
  44. package/dist/runtime/index.js +2 -1
  45. package/dist/schema/index.js +10 -4
  46. package/dist/session/index.js +1 -0
  47. package/dist/session-stores/codec.d.ts +8 -0
  48. package/dist/session-stores/forge-data.d.ts +43 -0
  49. package/dist/session-stores/hooks.d.ts +4 -0
  50. package/dist/session-stores/ids.d.ts +3 -0
  51. package/dist/session-stores/index.d.ts +20 -0
  52. package/dist/session-stores/index.js +1382 -0
  53. package/dist/session-stores/jsonl.d.ts +26 -0
  54. package/dist/session-stores/redis.d.ts +45 -0
  55. package/dist/session-stores/types.d.ts +45 -0
  56. package/dist/session-stores/versioning.d.ts +6 -0
  57. package/dist/testing/conformance.js +5 -4
  58. package/dist/testing/index.js +1 -0
  59. package/dist/tools/index.js +5 -3
  60. package/dist/tools-fs/define.d.ts +2 -0
  61. package/dist/tools-fs/files.d.ts +40 -0
  62. package/dist/tools-fs/git.d.ts +14 -0
  63. package/dist/tools-fs/index.d.ts +19 -0
  64. package/dist/tools-fs/index.js +1695 -0
  65. package/dist/tools-fs/policy.d.ts +32 -0
  66. package/dist/tools-fs/schemas.d.ts +31 -0
  67. package/dist/tools-fs/search.d.ts +45 -0
  68. package/dist/tools-fs/symbols.d.ts +12 -0
  69. package/dist/tools-fs/types.d.ts +151 -0
  70. package/dist/tools-http/client.d.ts +12 -0
  71. package/dist/tools-http/define.d.ts +12 -0
  72. package/dist/tools-http/events.d.ts +22 -0
  73. package/dist/tools-http/index.d.ts +24 -0
  74. package/dist/tools-http/index.js +18 -0
  75. package/dist/tools-http/policy.d.ts +52 -0
  76. package/dist/tools-http/types.d.ts +116 -0
  77. package/dist/tools-shell/define.d.ts +23 -0
  78. package/dist/tools-shell/events.d.ts +38 -0
  79. package/dist/tools-shell/exec.d.ts +37 -0
  80. package/dist/tools-shell/index.d.ts +30 -0
  81. package/dist/tools-shell/index.js +327 -0
  82. package/dist/tools-shell/policy.d.ts +42 -0
  83. package/dist/tools-shell/types.d.ts +121 -0
  84. package/dist/tools-web/define.d.ts +11 -0
  85. package/dist/tools-web/html.d.ts +22 -0
  86. package/dist/tools-web/index.d.ts +21 -0
  87. package/dist/tools-web/index.js +472 -0
  88. package/dist/tools-web/types.d.ts +81 -0
  89. package/docs/README.md +58 -10
  90. package/docs/api/.nojekyll +1 -0
  91. package/docs/api/assets/hierarchy.js +1 -0
  92. package/docs/api/assets/highlight.css +99 -0
  93. package/docs/api/assets/icons.js +18 -0
  94. package/docs/api/assets/icons.svg +1 -0
  95. package/docs/api/assets/main.js +60 -0
  96. package/docs/api/assets/navigation.js +1 -0
  97. package/docs/api/assets/search.js +1 -0
  98. package/docs/api/assets/style.css +1633 -0
  99. package/docs/api/classes/errors.AgentError.html +47 -0
  100. package/docs/api/classes/errors.CancelledError.html +46 -0
  101. package/docs/api/classes/errors.ContextWindowError.html +48 -0
  102. package/docs/api/classes/errors.ExecutionError.html +46 -0
  103. package/docs/api/classes/errors.FilesystemPolicyError.html +48 -0
  104. package/docs/api/classes/errors.MaxHandoffsExceededError.html +47 -0
  105. package/docs/api/classes/errors.MaxStepsExceededError.html +47 -0
  106. package/docs/api/classes/errors.ProviderError.html +47 -0
  107. package/docs/api/classes/errors.SchemaValidationError.html +47 -0
  108. package/docs/api/classes/errors.ShellPolicyError.html +50 -0
  109. package/docs/api/classes/errors.ToolError.html +47 -0
  110. package/docs/api/classes/errors.ToolValidationError.html +48 -0
  111. package/docs/api/classes/index.InMemorySessionStore.html +11 -0
  112. package/docs/api/classes/index.Secret.html +20 -0
  113. package/docs/api/classes/providers.StreamAccumulator.html +8 -0
  114. package/docs/api/classes/session-stores.FilesystemJsonlSessionStore.html +13 -0
  115. package/docs/api/classes/session-stores.ForgeDataSessionStore.html +14 -0
  116. package/docs/api/classes/session-stores.RedisSessionStore.html +12 -0
  117. package/docs/api/classes/tools-http.HttpPolicyError.html +41 -0
  118. package/docs/api/functions/agent.createToolRegistry.html +3 -0
  119. package/docs/api/functions/agent.handoffProviderTools.html +3 -0
  120. package/docs/api/functions/agent.handoffToolName.html +2 -0
  121. package/docs/api/functions/agent.resolveHandoffTargets.html +8 -0
  122. package/docs/api/functions/context.applyContextWindow.html +5 -0
  123. package/docs/api/functions/context.estimateTokens.html +3 -0
  124. package/docs/api/functions/context.resolveContext.html +5 -0
  125. package/docs/api/functions/events.createRunTelemetry.html +3 -0
  126. package/docs/api/functions/events.eventFields.html +4 -0
  127. package/docs/api/functions/events.eventPayload.html +5 -0
  128. package/docs/api/functions/execution.addUsage.html +2 -0
  129. package/docs/api/functions/execution.emptyUsage.html +2 -0
  130. package/docs/api/functions/index.asSchema.html +4 -0
  131. package/docs/api/functions/index.asTool.html +8 -0
  132. package/docs/api/functions/index.assistant.html +2 -0
  133. package/docs/api/functions/index.createAgentRegistry.html +5 -0
  134. package/docs/api/functions/index.createAnthropic.html +5 -0
  135. package/docs/api/functions/index.createEventHub.html +2 -0
  136. package/docs/api/functions/index.createGoogle.html +5 -0
  137. package/docs/api/functions/index.createOpenAI.html +5 -0
  138. package/docs/api/functions/index.createOpenAICompatible.html +7 -0
  139. package/docs/api/functions/index.createSession.html +3 -0
  140. package/docs/api/functions/index.defineAgent.html +7 -0
  141. package/docs/api/functions/index.defineTool.html +7 -0
  142. package/docs/api/functions/index.dynamicContext.html +2 -0
  143. package/docs/api/functions/index.fromJsonSchema.html +3 -0
  144. package/docs/api/functions/index.isSecret.html +4 -0
  145. package/docs/api/functions/index.loggingSubscriber.html +4 -0
  146. package/docs/api/functions/index.messageBusSubscriber.html +6 -0
  147. package/docs/api/functions/index.normalizeContent.html +2 -0
  148. package/docs/api/functions/index.resolveSecret.html +4 -0
  149. package/docs/api/functions/index.runAgent.html +19 -0
  150. package/docs/api/functions/index.staticContext.html +3 -0
  151. package/docs/api/functions/index.summarizeOldest.html +4 -0
  152. package/docs/api/functions/index.system.html +2 -0
  153. package/docs/api/functions/index.text.html +2 -0
  154. package/docs/api/functions/index.toJsonSchema.html +2 -0
  155. package/docs/api/functions/index.toolResult.html +2 -0
  156. package/docs/api/functions/index.truncateOldest.html +5 -0
  157. package/docs/api/functions/index.user.html +2 -0
  158. package/docs/api/functions/index.validateJsonSchema.html +3 -0
  159. package/docs/api/functions/lifecycle.agentRuntimeComponent.html +5 -0
  160. package/docs/api/functions/providers.collectStream.html +2 -0
  161. package/docs/api/functions/providers.createProvider.html +4 -0
  162. package/docs/api/functions/providers.createProviderHttp.html +3 -0
  163. package/docs/api/functions/providers.defaultProviderResilience.html +3 -0
  164. package/docs/api/functions/providers.openSseStream.html +6 -0
  165. package/docs/api/functions/providers.parseSse.html +2 -0
  166. package/docs/api/functions/providers.toProviderError.html +2 -0
  167. package/docs/api/functions/session-stores.createPostgresSessionStore.html +1 -0
  168. package/docs/api/functions/session-stores.createSqliteSessionStore.html +1 -0
  169. package/docs/api/functions/session-stores.isCloseableSessionStore.html +1 -0
  170. package/docs/api/functions/session-stores.isVersionedSessionStore.html +1 -0
  171. package/docs/api/functions/session-stores.migrateSessionStore.html +1 -0
  172. package/docs/api/functions/session-stores.withSessionStoreHooks.html +2 -0
  173. package/docs/api/functions/testing.byteStreamOf.html +2 -0
  174. package/docs/api/functions/testing.collectProviderStream.html +2 -0
  175. package/docs/api/functions/testing.conversation.html +2 -0
  176. package/docs/api/functions/testing.expectValid.html +3 -0
  177. package/docs/api/functions/testing.inMemorySessionStore.html +2 -0
  178. package/docs/api/functions/testing.jsonFetch.html +3 -0
  179. package/docs/api/functions/testing.mockProvider.html +3 -0
  180. package/docs/api/functions/testing.scriptedProvider.html +4 -0
  181. package/docs/api/functions/testing.sseFetch.html +3 -0
  182. package/docs/api/functions/testing.textResult.html +3 -0
  183. package/docs/api/functions/testing.toolCallResult.html +3 -0
  184. package/docs/api/functions/testing_conformance.runProviderConformance.html +3 -0
  185. package/docs/api/functions/tools-fs.filesystemTools.html +1 -0
  186. package/docs/api/functions/tools-http.createHttpToolClient.html +2 -0
  187. package/docs/api/functions/tools-http.httpTools.html +2 -0
  188. package/docs/api/functions/tools-shell.shellTools.html +4 -0
  189. package/docs/api/functions/tools-web.webTools.html +2 -0
  190. package/docs/api/functions/tools.renderToolContent.html +6 -0
  191. package/docs/api/functions/tools.toProviderTool.html +3 -0
  192. package/docs/api/functions/tools.toToolResultMessage.html +4 -0
  193. package/docs/api/hierarchy.html +1 -0
  194. package/docs/api/index.html +1 -0
  195. package/docs/api/interfaces/agent.ToolRegistry.html +8 -0
  196. package/docs/api/interfaces/errors.SchemaIssue.html +4 -0
  197. package/docs/api/interfaces/events.RunTelemetry.html +10 -0
  198. package/docs/api/interfaces/events.SpanHandle.html +6 -0
  199. package/docs/api/interfaces/index.AgentDefinition.html +16 -0
  200. package/docs/api/interfaces/index.AgentHooks.html +21 -0
  201. package/docs/api/interfaces/index.AgentRegistry.html +16 -0
  202. package/docs/api/interfaces/index.AnthropicOptions.html +13 -0
  203. package/docs/api/interfaces/index.AsToolOptions.html +13 -0
  204. package/docs/api/interfaces/index.CompletionRequest.html +30 -0
  205. package/docs/api/interfaces/index.CompletionResult.html +14 -0
  206. package/docs/api/interfaces/index.ContextItem.html +6 -0
  207. package/docs/api/interfaces/index.ContextProvider.html +5 -0
  208. package/docs/api/interfaces/index.ContextStrategy.html +8 -0
  209. package/docs/api/interfaces/index.ContextStrategyContext.html +8 -0
  210. package/docs/api/interfaces/index.ContextWindowOptions.html +8 -0
  211. package/docs/api/interfaces/index.CreateSessionOptions.html +10 -0
  212. package/docs/api/interfaces/index.EngineContext.html +10 -0
  213. package/docs/api/interfaces/index.EventHub.html +4 -0
  214. package/docs/api/interfaces/index.EventHubOptions.html +8 -0
  215. package/docs/api/interfaces/index.GenerationSettings.html +12 -0
  216. package/docs/api/interfaces/index.GoogleOptions.html +11 -0
  217. package/docs/api/interfaces/index.ImagePart.html +5 -0
  218. package/docs/api/interfaces/index.InstructionContext.html +9 -0
  219. package/docs/api/interfaces/index.JsonSchema.html +18 -0
  220. package/docs/api/interfaces/index.LoggingSubscriberOptions.html +4 -0
  221. package/docs/api/interfaces/index.Message.html +8 -0
  222. package/docs/api/interfaces/index.MessageBusSubscriberOptions.html +4 -0
  223. package/docs/api/interfaces/index.OpenAICompatibleOptions.html +16 -0
  224. package/docs/api/interfaces/index.OpenAIOptions.html +16 -0
  225. package/docs/api/interfaces/index.Provider.html +11 -0
  226. package/docs/api/interfaces/index.ProviderCapabilities.html +9 -0
  227. package/docs/api/interfaces/index.ProviderTool.html +6 -0
  228. package/docs/api/interfaces/index.ResponseSchema.html +6 -0
  229. package/docs/api/interfaces/index.RunBridge.html +10 -0
  230. package/docs/api/interfaces/index.RunOptions.html +39 -0
  231. package/docs/api/interfaces/index.RunResult.html +20 -0
  232. package/docs/api/interfaces/index.Schema.html +13 -0
  233. package/docs/api/interfaces/index.Session.html +13 -0
  234. package/docs/api/interfaces/index.SessionState.html +5 -0
  235. package/docs/api/interfaces/index.SessionStore.html +15 -0
  236. package/docs/api/interfaces/index.TextPart.html +4 -0
  237. package/docs/api/interfaces/index.ToolCall.html +9 -0
  238. package/docs/api/interfaces/index.ToolCallPart.html +6 -0
  239. package/docs/api/interfaces/index.ToolContext.html +21 -0
  240. package/docs/api/interfaces/index.ToolDefinition.html +14 -0
  241. package/docs/api/interfaces/index.ToolFailure.html +9 -0
  242. package/docs/api/interfaces/index.ToolResultPart.html +8 -0
  243. package/docs/api/interfaces/index.ToolSpec.html +6 -0
  244. package/docs/api/interfaces/index.ToolSuccess.html +6 -0
  245. package/docs/api/interfaces/index.Usage.html +9 -0
  246. package/docs/api/interfaces/lifecycle.AgentRuntimeOptions.html +17 -0
  247. package/docs/api/interfaces/providers.AdapterSpec.html +17 -0
  248. package/docs/api/interfaces/providers.ProviderHttpOptions.html +14 -0
  249. package/docs/api/interfaces/providers.SseMessage.html +6 -0
  250. package/docs/api/interfaces/providers.SseRequest.html +8 -0
  251. package/docs/api/interfaces/runtime.Logger.html +22 -0
  252. package/docs/api/interfaces/runtime.Telemetry.html +9 -0
  253. package/docs/api/interfaces/schema.OptionalSchema.html +13 -0
  254. package/docs/api/interfaces/session-stores.CloseableSessionStore.html +11 -0
  255. package/docs/api/interfaces/session-stores.CreatePostgresSessionStoreOptions.html +6 -0
  256. package/docs/api/interfaces/session-stores.CreateSqliteSessionStoreOptions.html +7 -0
  257. package/docs/api/interfaces/session-stores.FilesystemJsonlSessionStoreOptions.html +3 -0
  258. package/docs/api/interfaces/session-stores.ForgeDataSessionStoreOptions.html +5 -0
  259. package/docs/api/interfaces/session-stores.RedisSessionStoreClient.html +9 -0
  260. package/docs/api/interfaces/session-stores.RedisSessionStoreOptions.html +4 -0
  261. package/docs/api/interfaces/session-stores.RedisSessionStoreTransaction.html +6 -0
  262. package/docs/api/interfaces/session-stores.SessionArchiveRecord.html +7 -0
  263. package/docs/api/interfaces/session-stores.SessionArchiver.html +2 -0
  264. package/docs/api/interfaces/session-stores.SessionCompactionResult.html +3 -0
  265. package/docs/api/interfaces/session-stores.SessionCompactor.html +3 -0
  266. package/docs/api/interfaces/session-stores.SessionStoreCodec.html +6 -0
  267. package/docs/api/interfaces/session-stores.SessionStoreHookContext.html +3 -0
  268. package/docs/api/interfaces/session-stores.SessionStoreHooks.html +3 -0
  269. package/docs/api/interfaces/session-stores.VersionedSessionStore.html +11 -0
  270. package/docs/api/interfaces/testing.MockProviderOptions.html +12 -0
  271. package/docs/api/interfaces/testing.RecordedCall.html +4 -0
  272. package/docs/api/interfaces/testing.RecordingFetch.html +4 -0
  273. package/docs/api/interfaces/testing_conformance.ConformanceFixtures.html +12 -0
  274. package/docs/api/interfaces/testing_conformance.ConformanceOptions.html +10 -0
  275. package/docs/api/interfaces/testing_conformance.ConformanceTestApi.html +4 -0
  276. package/docs/api/interfaces/testing_conformance.ProviderIO.html +7 -0
  277. package/docs/api/interfaces/tools-fs.ApplyPatchArgs.html +6 -0
  278. package/docs/api/interfaces/tools-fs.DiffStatusArgs.html +5 -0
  279. package/docs/api/interfaces/tools-fs.EditRangeArgs.html +7 -0
  280. package/docs/api/interfaces/tools-fs.EditReplaceArgs.html +7 -0
  281. package/docs/api/interfaces/tools-fs.FilesystemTools.html +13 -0
  282. package/docs/api/interfaces/tools-fs.FilesystemToolsConfig.html +12 -0
  283. package/docs/api/interfaces/tools-fs.FindFilesArgs.html +7 -0
  284. package/docs/api/interfaces/tools-fs.OpenWindowArgs.html +5 -0
  285. package/docs/api/interfaces/tools-fs.ReadArgs.html +9 -0
  286. package/docs/api/interfaces/tools-fs.RepoMapArgs.html +7 -0
  287. package/docs/api/interfaces/tools-fs.SearchSemanticArgs.html +8 -0
  288. package/docs/api/interfaces/tools-fs.SearchTextArgs.html +11 -0
  289. package/docs/api/interfaces/tools-fs.SymbolInfo.html +7 -0
  290. package/docs/api/interfaces/tools-fs.SymbolsArgs.html +5 -0
  291. package/docs/api/interfaces/tools-fs.ValidationCommandRequest.html +4 -0
  292. package/docs/api/interfaces/tools-fs.ValidationCommandResult.html +6 -0
  293. package/docs/api/interfaces/tools-fs.ValidationOptions.html +4 -0
  294. package/docs/api/interfaces/tools-fs.WriteFileArgs.html +6 -0
  295. package/docs/api/interfaces/tools-http.HeaderEntry.html +4 -0
  296. package/docs/api/interfaces/tools-http.HttpClientRequest.html +11 -0
  297. package/docs/api/interfaces/tools-http.HttpPolicy.html +13 -0
  298. package/docs/api/interfaces/tools-http.HttpRequestResult.html +17 -0
  299. package/docs/api/interfaces/tools-http.HttpRetryOptions.html +10 -0
  300. package/docs/api/interfaces/tools-http.HttpToolClient.html +5 -0
  301. package/docs/api/interfaces/tools-http.HttpTools.html +4 -0
  302. package/docs/api/interfaces/tools-http.HttpToolsConfig.html +38 -0
  303. package/docs/api/interfaces/tools-shell.ApprovalDecision.html +5 -0
  304. package/docs/api/interfaces/tools-shell.CommandRequest.html +14 -0
  305. package/docs/api/interfaces/tools-shell.CommandResult.html +21 -0
  306. package/docs/api/interfaces/tools-shell.EnvPolicy.html +9 -0
  307. package/docs/api/interfaces/tools-shell.ShellPolicy.html +7 -0
  308. package/docs/api/interfaces/tools-shell.ShellTools.html +6 -0
  309. package/docs/api/interfaces/tools-shell.ShellToolsConfig.html +26 -0
  310. package/docs/api/interfaces/tools-web.Citation.html +6 -0
  311. package/docs/api/interfaces/tools-web.SearchProvider.html +3 -0
  312. package/docs/api/interfaces/tools-web.SearchRequest.html +4 -0
  313. package/docs/api/interfaces/tools-web.SearchResult.html +7 -0
  314. package/docs/api/interfaces/tools-web.SourceMetadata.html +10 -0
  315. package/docs/api/interfaces/tools-web.WebTools.html +6 -0
  316. package/docs/api/interfaces/tools-web.WebToolsConfig.html +56 -0
  317. package/docs/api/modules/agent.html +5 -0
  318. package/docs/api/modules/context.html +5 -0
  319. package/docs/api/modules/errors.html +8 -0
  320. package/docs/api/modules/events.html +16 -0
  321. package/docs/api/modules/execution.html +4 -0
  322. package/docs/api/modules/index.html +16 -0
  323. package/docs/api/modules/lifecycle.html +6 -0
  324. package/docs/api/modules/messages.html +3 -0
  325. package/docs/api/modules/providers.html +10 -0
  326. package/docs/api/modules/runtime.html +4 -0
  327. package/docs/api/modules/schema.html +5 -0
  328. package/docs/api/modules/session-stores.html +6 -0
  329. package/docs/api/modules/session.html +4 -0
  330. package/docs/api/modules/testing.html +4 -0
  331. package/docs/api/modules/testing_conformance.html +21 -0
  332. package/docs/api/modules/tools-fs.html +9 -0
  333. package/docs/api/modules/tools-http.html +8 -0
  334. package/docs/api/modules/tools-shell.html +12 -0
  335. package/docs/api/modules/tools-web.html +7 -0
  336. package/docs/api/modules/tools.html +4 -0
  337. package/docs/api/types/events.Attrs.html +2 -0
  338. package/docs/api/types/index.AnyRunOptions.html +3 -0
  339. package/docs/api/types/index.BufferedRunOptions.html +2 -0
  340. package/docs/api/types/index.ContentPart.html +2 -0
  341. package/docs/api/types/index.FinishReason.html +2 -0
  342. package/docs/api/types/index.Infer.html +2 -0
  343. package/docs/api/types/index.Instructions.html +5 -0
  344. package/docs/api/types/index.LogLevel.html +2 -0
  345. package/docs/api/types/index.Role.html +2 -0
  346. package/docs/api/types/index.RunEvent.html +30 -0
  347. package/docs/api/types/index.RunHandle.html +7 -0
  348. package/docs/api/types/index.RunInput.html +2 -0
  349. package/docs/api/types/index.RunSubscriber.html +4 -0
  350. package/docs/api/types/index.SafeParseResult.html +2 -0
  351. package/docs/api/types/index.StreamEvent.html +8 -0
  352. package/docs/api/types/index.StreamingRunOptions.html +2 -0
  353. package/docs/api/types/index.TelemetryHandle.html +2 -0
  354. package/docs/api/types/index.TokenCounter.html +2 -0
  355. package/docs/api/types/index.ToolChoice.html +2 -0
  356. package/docs/api/types/index.ToolResult.html +2 -0
  357. package/docs/api/types/lifecycle.ProviderProbe.html +2 -0
  358. package/docs/api/types/session-stores.SessionStoreHookOperation.html +1 -0
  359. package/docs/api/types/testing_conformance.MakeProvider.html +2 -0
  360. package/docs/api/types/tools-fs.SymbolKind.html +1 -0
  361. package/docs/api/types/tools-http.HostPattern.html +2 -0
  362. package/docs/api/types/tools-shell.CommandPattern.html +2 -0
  363. package/docs/api/types/tools-web.RobotsPolicy.html +2 -0
  364. package/docs/api/variables/events.SPAN_PROVIDER.html +2 -0
  365. package/docs/api/variables/events.SPAN_RUN.html +2 -0
  366. package/docs/api/variables/events.SPAN_TOOL.html +2 -0
  367. package/docs/api/variables/execution.DEFAULT_MAX_HANDOFFS.html +2 -0
  368. package/docs/api/variables/execution.DEFAULT_MAX_STEPS.html +2 -0
  369. package/docs/api/variables/index.s.html +11 -0
  370. package/docs/api/variables/providers.DEFAULT_TIMEOUT_MS.html +2 -0
  371. package/docs/api/variables/session-stores.SESSION_STORE_SCHEMA_VERSION.html +1 -0
  372. package/docs/api/variables/session-stores.jsonSessionStoreCodec.html +2 -0
  373. package/docs/api/variables/tools-http.HTTP_EVENT.html +2 -0
  374. package/docs/api/variables/tools-shell.SHELL_EVENT.html +2 -0
  375. package/docs/events-and-telemetry.md +68 -0
  376. package/docs/execution.md +63 -0
  377. package/docs/getting-started.md +73 -0
  378. package/docs/multi-agent.md +52 -0
  379. package/docs/optional-tool-packs.md +93 -0
  380. package/docs/providers.md +68 -0
  381. package/docs/retrieval.md +83 -0
  382. package/docs/sessions-and-context.md +82 -0
  383. package/docs/testing-and-lifecycle.md +60 -0
  384. package/docs/tools.md +69 -0
  385. package/examples/01-minimal-agent.ts +19 -0
  386. package/examples/02-custom-tool.ts +32 -0
  387. package/examples/03-streaming.ts +46 -0
  388. package/examples/04-sessions-context.ts +40 -0
  389. package/examples/05-events-subscribers.ts +35 -0
  390. package/examples/06-multi-agent-handoff.ts +27 -0
  391. package/examples/07-sub-agent-tool.ts +26 -0
  392. package/examples/08-testing-agent.ts +31 -0
  393. package/examples/09-tools-filesystem.ts +49 -0
  394. package/examples/10-tools-http-web.ts +74 -0
  395. package/examples/11-shell-tools.ts +39 -0
  396. package/examples/12-provider-openai.ts +24 -0
  397. package/examples/13-lifecycle.ts +37 -0
  398. package/examples/14-retrieval.ts +65 -0
  399. package/examples/incident-analysis.ts +52 -0
  400. package/package.json +78 -4
  401. package/dist/index-02s1fjxr.js +0 -226
package/README.md CHANGED
@@ -6,483 +6,119 @@
6
6
  [![TypeScript](https://img.shields.io/badge/TypeScript-6.0.3%2B-blue.svg)](https://www.typescriptlang.org/)
7
7
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
8
8
 
9
- ---
10
-
11
9
  ## Project Goal
12
10
 
13
- Every project that wants to "add an agent" ends up rebuilding the same scaffolding:
14
- a provider client, a message/content model, a tool-calling loop, session state,
15
- context injection, and a way to observe what the agent is doing. It is tedious,
16
- error-prone, and almost never the interesting part of the product.
17
-
18
- **engine-lib** is the reusable layer that owns that scaffolding once. It provides a
19
- provider-agnostic way to define agents and tools, run them against any major LLM
20
- provider, manage their conversation state, and observe their behavior — so that a
21
- host application (a coding terminal, a server-management tool, an incident
22
- responder) can import it and start shipping agent features without re-implementing
23
- the plumbing.
11
+ Every project that wants to add an agent ends up rebuilding the same
12
+ scaffolding: a provider client, a message/content model, a tool-calling loop,
13
+ session state, context injection, and a way to observe what the agent is doing.
14
+ It is tedious, error-prone, and rarely the interesting part of the product.
24
15
 
25
- It is built on **Forge**, inheriting its config, telemetry, resilience, and
26
- lifecycle primitives rather than reinventing them. Where Forge is "the boring
27
- infrastructure layer your business logic deserves," engine-lib is the boring
28
- *agent* infrastructure layer your product deserves.
16
+ `engine-lib` is the reusable layer that owns that scaffolding once. It provides
17
+ a provider-agnostic way to define agents and tools, run them against major LLM
18
+ providers, manage conversation state, and observe behavior so a host
19
+ application can ship agent features without re-implementing the plumbing.
29
20
 
30
- ---
21
+ It is built on `@infinityi/forge`, inheriting its configuration, telemetry,
22
+ resilience, and lifecycle primitives rather than rebuilding those concerns.
23
+ Where Forge is the infrastructure layer for application services, `engine-lib`
24
+ is the agent infrastructure layer for products that need agent behavior.
31
25
 
32
26
  ## Target Users
33
27
 
34
- engine-lib is for **developers building agent-integrated products** including
35
- the author's own future projects. You are the audience if you are:
36
-
37
- - Adding an agent to a **coding terminal / dev tool** that needs to read files, run
38
- commands, and stream responses.
39
- - Building an **operations / server-management tool** that launches an agent to
40
- triage incidents, inspect logs, and propose remediations.
41
- - Writing **any backend service** that wants LLM-driven behavior with structured
42
- tool calls, durable sessions, and first-class observability.
28
+ `engine-lib` is for developers building agent-integrated products, including:
43
29
 
44
- You are **not** the audience if you want a no-code agent builder, a hosted agent
45
- runtime, or an opinionated framework that decides *what* your agent should do.
46
- engine-lib gives you the contracts and the runtime; the behavior is yours.
30
+ - coding terminals and developer tools that need file access, command execution,
31
+ streaming, and tool-calling behavior
32
+ - operations and server-management tools that need incident triage, log
33
+ inspection, and remediation workflows
34
+ - backend services that need LLM-driven behavior with structured tools, durable
35
+ sessions, and observability
47
36
 
48
- ---
37
+ It is not intended to be a no-code agent builder, hosted runtime, UI framework,
38
+ prompt template system, hosted RAG service, managed vector database, model host,
39
+ or evaluation platform.
49
40
 
50
41
  ## Core Concepts
51
42
 
52
- | Concept | What it is |
53
- | :--- | :--- |
54
- | **Provider** | A normalized adapter over an LLM API (OpenAI, Anthropic, Google, OpenAI-compatible). It exposes one shape for chat completion, streaming, tool calling, and usage — and declares its capabilities so callers can degrade gracefully. |
55
- | **Message & Content** | A provider-neutral representation of a conversation. Messages carry roles (`system`/`user`/`assistant`/`tool`) and typed content parts (text, tool calls, tool results, images), so history is portable across providers. |
56
- | **Agent** | A declarative definition: which model/provider to use, system instructions, the tools it may call, default generation settings, and lifecycle hooks. An agent is *data*, not a class hierarchy — you describe it, the runtime executes it. |
57
- | **Tool** | A named capability the model can invoke: a parameter schema (validated before execution), an `execute` function, and a typed, structured **tool result**. Tools are how the agent affects the world. |
58
- | **Execution** | The provider-native run loop. The model decides when to call tools using the provider's own tool-calling protocol; the runtime dispatches the calls, validates arguments, feeds results back, and repeats until the model produces a final answer. No hand-rolled ReAct prompt. |
59
- | **Session** | The durable home of a conversation: ordered message history plus metadata. A session can be in-memory (ephemeral) or backed by a store, and is responsible for staying within the model's context window. |
60
- | **Context** | Information injected into a run at execution time system facts, retrieved documents, environment state — supplied by **context providers** that the host wires in. engine-lib injects context; it does not decide *what* the context is. |
61
- | **Event Emitter** | A typed stream of everything that happens during a run (`run.start`, `message`, `tool.call`, `tool.result`, `token`, `run.finish`, `error`). External subscribers use it for UI streaming, logging, metrics, and auditing without coupling to the runtime internals. |
62
-
63
- ---
43
+ | Concept | Description |
44
+ | --- | --- |
45
+ | Provider | A normalized adapter over an LLM API. Built-in adapters cover OpenAI, Anthropic, Google, and OpenAI-compatible APIs. |
46
+ | Message and content | A provider-neutral conversation model with typed content parts for text, tool calls, tool results, and images. |
47
+ | Agent | A declarative definition containing provider, instructions, tools, generation defaults, hooks, and optional handoff targets. |
48
+ | Tool | A schema-validated capability the model can invoke. Tools return structured success or failure results. |
49
+ | Execution | The provider-native run loop that dispatches tool calls and repeats until a final answer, cancellation, or budget failure. |
50
+ | Session | Durable conversation state: ordered message history plus metadata behind a pluggable store. |
51
+ | Context | Request-time information injected by host-provided context providers and never persisted as conversation history. |
52
+ | Events | A typed event stream for UI streaming, logs, metrics, auditing, telemetry, and optional tool-pack audit data. |
64
53
 
65
54
  ## Design Principles
66
55
 
67
- 1. **Provider-native execution, no custom loop.** We do not invent a prompting
68
- strategy. We use each provider's first-class tool-calling / function-calling
69
- protocol and let the model drive. This keeps behavior aligned with how the
70
- model was trained and avoids brittle "Thought/Action/Observation" string
71
- parsing.
72
- 2. **Forge-backed, not reinvented.** Configuration and secrets come from
73
- `forge/config`, observability from `forge/telemetry`, provider-call hardening
74
- (timeout, retry, circuit breaking) from `forge/resilience`, and process
75
- wiring from `forge/lifecycle`. engine-lib adds the agent layer; Forge owns the
76
- infrastructure.
77
- 3. **Contracts over implementations.** `Provider`, `Tool`, `Agent`, `SessionStore`,
78
- and `ContextProvider` are interfaces first. Every interface ships with an
79
- in-memory double so consumers can test agents deterministically, mirroring
80
- Forge's "interfaces first" philosophy.
81
- 4. **Schema-validated boundaries, fail-fast.** Tool parameters and structured
82
- outputs are described by schemas and validated at the boundary. Bad arguments
83
- become a typed tool error fed back to the model — not an unhandled exception.
84
- 5. **Observable by default.** Every run, every provider call, and every tool
85
- invocation emits events and telemetry spans. You can reconstruct exactly what
86
- an agent did and why.
87
- 6. **Composable, not monolithic.** Use the provider layer without sessions. Use
88
- sessions without multi-agent coordination. There are no forced peer
89
- dependencies between sub-modules.
90
- 7. **Zero magic.** No global agent registry by default, no decorator-based DI, no
91
- hidden network calls. Wiring is explicit; the host stays in control.
92
- 8. **Developer ergonomics.** The common path (define a provider, define a tool,
93
- define an agent, run it) should be a handful of well-typed function calls with
94
- inferred types end-to-end.
95
-
96
- ---
97
-
98
- ## Constraints / What Is Not Shipped
99
-
100
- To stay a *library* and not a framework, engine-lib explicitly does **not** include:
101
-
102
- - **No UI or frontend.** No chat widgets, no terminal renderer. We emit events;
103
- rendering is the host's job.
104
- - **No opinionated agent logic.** No built-in "researcher" or "coder" personas, no
105
- default system prompts. You define behavior.
106
- - **No built-in tools.** No web search, no code execution, no file system access
107
- shipped in the box. Tools are yours to define (the library validates and runs
108
- them).
109
- - **No prompt template engine.** No templating DSL or prompt library. Instructions
110
- are plain strings/functions you own.
111
- - **No custom reasoning loop.** No ReAct/CoT/Tree-of-Thought framework — execution
112
- is provider-native tool calling.
113
- - **No RAG / vector store / embeddings engine.** Context injection is a hook;
114
- retrieval, chunking, and embedding storage are out of scope. Plug your own in.
115
- - **No model hosting or inference.** engine-lib calls external provider APIs; it
116
- does not run models.
117
- - **No fine-tuning, training, or evaluation harness.** Out of scope.
118
-
119
- If you need one of these, build it *on top of* engine-lib using the provided
120
- contracts.
121
-
122
- ---
123
-
124
- ## Getting Started
125
-
126
- ```bash
127
- bun install # install dependencies
128
- bun run check # type-check (tsc --noEmit)
129
- bun test # run the test suite
130
- bun run build # emit dist/ (JS + .d.ts)
131
- ```
132
-
133
- Public entry points:
134
-
135
- ```ts
136
- import { s, user, system, AgentError, createOpenAI, defineTool, defineAgent, runAgent, createSession, staticContext, createAgentRegistry, asTool } from "@infinityi/engine-lib";
137
- // or via subpaths:
138
- import { s } from "@infinityi/engine-lib/schema";
139
- import { user } from "@infinityi/engine-lib/messages";
140
- import { AgentError } from "@infinityi/engine-lib/errors";
141
- import { resolveSecret } from "@infinityi/engine-lib/runtime";
142
- import { createOpenAI } from "@infinityi/engine-lib/providers";
143
- import { defineTool } from "@infinityi/engine-lib/tools";
144
- import { defineAgent, createAgentRegistry, asTool } from "@infinityi/engine-lib/agent";
145
- import { runAgent } from "@infinityi/engine-lib/execution";
146
- import { createSession } from "@infinityi/engine-lib/session";
147
- import { staticContext, truncateOldest } from "@infinityi/engine-lib/context";
148
- import { createEventHub, loggingSubscriber, messageBusSubscriber } from "@infinityi/engine-lib/events";
149
- import { agentRuntimeComponent } from "@infinityi/engine-lib/lifecycle";
150
- // test-only doubles + the cross-provider conformance battery:
151
- import { mockProvider, scriptedProvider, textResult, toolCallResult } from "@infinityi/engine-lib/testing";
152
- import { runProviderConformance } from "@infinityi/engine-lib/testing/conformance";
153
- ```
154
-
155
- ### Stable public API
156
-
157
- For application code, prefer the root import or the domain subpaths above. The
158
- root barrel is intentionally focused on the stable, ergonomic surface:
159
-
160
- - schema, message, and error helpers (`s`, `user`, `system`, `AgentError`, ...)
161
- - provider factories (`createOpenAI`, `createAnthropic`, `createGoogle`,
162
- `createOpenAICompatible`)
163
- - agent/tool/run/session/context helpers (`defineTool`, `defineAgent`,
164
- `runAgent`, `createSession`, `staticContext`, `dynamicContext`)
165
- - multi-agent helpers (`createAgentRegistry`, `asTool`)
166
- - run-event subscribers (`createEventHub`, `loggingSubscriber`,
167
- `messageBusSubscriber`)
168
-
169
- Advanced adapter plumbing remains available from subpaths for custom providers
170
- and tests. For example, `@infinityi/engine-lib/providers` exports `createProvider`,
171
- `createProviderHttp`, `parseSse`, and stream accumulation helpers, while
172
- `@infinityi/engine-lib/events` exports event projection and telemetry helpers. Treat those
173
- as lower-level extension APIs rather than the common application surface.
174
-
175
- ### Providers
176
-
177
- Use the built-in factories for application code:
178
-
179
- ```ts
180
- const openai = createOpenAI({ apiKey: config.openaiApiKey, model: "gpt-5" });
181
- const anthropic = createAnthropic({ apiKey: config.anthropicApiKey, model: "claude-opus-4-7" });
182
- const google = createGoogle({ apiKey: config.googleApiKey, model: "gemini-2.5-pro" });
183
- const local = createOpenAICompatible({ baseUrl: "http://localhost:1234/v1", model: "local-model" });
184
- ```
185
-
186
- Provider API keys accept raw strings or Forge `Secret<string>` values. Factory
187
- `model` options become the provider's `defaultModel`; `CompletionRequest.model`
188
- can override the model per request.
189
-
190
- The stable provider contract is `Provider`, `CompletionRequest`,
191
- `CompletionResult`, `StreamEvent`, `Usage`, `ProviderCapabilities`, and the
192
- factory option types. `CompletionRequest` contains normalized generation fields
193
- (`temperature`, `topP`, `maxOutputTokens`, `stopSequences`), tool fields
194
- (`tools`, `toolChoice`, `responseSchema`), optional `metadata`, and
195
- `providerOptions` for vendor-specific request body fields that are not yet
196
- first-classed.
197
-
198
- `CompletionResult.raw` intentionally remains `unknown`: engine-lib keeps the
199
- portable normalized fields stable, while adapter-aware consumers may narrow the
200
- native response themselves. `ProviderCapabilities` should be treated as adapter
201
- truth; callers can degrade based on those flags, and the conformance suite
202
- checks the built-in adapters for capability honesty.
203
-
204
- `@infinityi/engine-lib/providers` also exports advanced extension helpers such as
205
- `createProvider`, `AdapterSpec`, HTTP/SSE utilities, `StreamAccumulator`, and
206
- `collectStream`. Use those for custom adapters and conformance tests, not for
207
- ordinary application wiring.
208
-
209
- Runnable, offline examples live in [`examples/`](./examples/) (`bun examples/incident-analysis.ts`),
210
- and the generated API reference is described in [`docs/`](./docs/README.md) (`bun run docs`).
211
-
212
- `runAgent` drives the provider-native tool-calling loop: it sends the
213
- conversation + tool schemas to the provider, validates and dispatches tool calls
214
- (in parallel, with per-call error isolation), feeds results back, and repeats
215
- until a final answer, the step budget (`MaxStepsExceededError`), or cancellation
216
- (`CancelledError`). It runs buffered (`await runAgent(agent, { input })` →
217
- `RunResult`) or streaming (`runAgent(agent, { input, stream: true })` → an
218
- async-iterable of `RunEvent`s).
219
-
220
- `runAgent` has three stable call shapes:
221
-
222
- ```ts
223
- const result = await runAgent(agent, { input: "go" });
224
- // Promise<RunResult>
225
-
226
- const handle = runAgent(agent, { input: "go", stream: true });
227
- // RunHandle: AsyncIterable<RunEvent> & { completed: Promise<RunResult> }
228
-
229
- const maybeStream: boolean = shouldStream();
230
- const resultOrHandle = runAgent(agent, { input: "go", stream: maybeStream });
231
- // Promise<RunResult> | RunHandle
232
- ```
233
-
234
- Streaming consumers should either drain the async iterable or await
235
- `handle.completed`. Successful streams emit a final `run.finish` event and then
236
- `completed` resolves with the same `RunResult`. If iteration throws,
237
- `completed` rejects with the same error; if iteration is abandoned early,
238
- `completed` rejects with `CancelledError`.
239
-
240
- Run events are ordered. Every run starts with `run.start`. Provider assistant
241
- turns are emitted as `message`; streaming text arrives as `token` before the
242
- assistant `message` that contains the accumulated text. Tool calls emit
243
- `tool.call`, then `tool.result`, then the tool-result `message`. Successful runs
244
- end with `run.finish`; failed runs emit `error` and then reject or throw the same
245
- `AgentError`. Tool validation failures, unknown tools, and thrown tool
246
- implementations are isolated as `{ ok: false }` tool results so the model can
247
- recover; provider failures, context/session failures, max-step/max-handoff
248
- limits, and cancellation fail the run.
249
-
250
- ### Tools and schemas
251
-
252
- Use `defineTool()` for application tools. It infers the `execute(args)` type from
253
- the parameter schema and keeps the definition shape stable for future releases:
254
-
255
- ```ts
256
- const readFile = defineTool({
257
- name: "read_file",
258
- description: "Read a file from the workspace.",
259
- parameters: s.object({
260
- path: s.string(),
261
- maxBytes: s.optional(s.number({ int: true })),
262
- }),
263
- execute: async ({ path, maxBytes }) => {
264
- const content = await workspace.read(path, { maxBytes });
265
- return { ok: true, content };
266
- },
267
- });
268
- ```
269
-
270
- Tool results are deliberately small: return `{ ok: true, content }` for success
271
- and `{ ok: false, error }` for expected/domain failures such as missing files or
272
- permission denials. Throw only for unexpected implementation faults; `runAgent`
273
- catches thrown tool errors and feeds them back to the model as recoverable
274
- tool-result errors.
275
-
276
- Tool content is rendered predictably for the model. Strings pass through,
277
- `null`/`undefined` become empty text, and non-string values are JSON-encoded.
278
- `error` is a string in the stable contract; use clear, user-actionable messages.
279
-
280
- The built-in `s` schema builder covers the JSON-Schema subset engine-lib
281
- validates and providers need for tool parameters. `s.object()` is strict by
282
- default (`additionalProperties: false`), required keys are derived from the
283
- shape, and `s.optional(...)` makes an object key optional in both TypeScript and
284
- runtime validation. Use `asSchema()` / `fromJsonSchema()` when adapting an
285
- external schema library or raw JSON Schema.
286
-
287
- ### Agents and composition
288
-
289
- Use `defineAgent()` for application agents. An agent definition is plain data:
290
- the provider to call, optional instructions, tools, default generation settings,
291
- hooks, and optional handoff targets. Construction validates the agent name and
292
- duplicate tool names, but does not call the provider or resolve handoff targets.
293
-
294
- Instructions may be a string or a function:
295
-
296
- ```ts
297
- const coder = defineAgent({
298
- name: "coder",
299
- provider,
300
- instructions: (ctx) => `You are ${ctx.agent.name}. Be precise.`,
301
- tools: [readFile],
302
- generation: { temperature: 0.2 },
303
- });
304
- ```
305
-
306
- Resolved instructions are injected into the provider request as system context.
307
- They are rebuilt every run and are not persisted to sessions.
308
-
309
- Hooks are awaited and receive the shared engine context. Public run events are
310
- emitted before the corresponding hook is invoked. Hook failures fail the run and
311
- flow through `onError`; if `onError` throws, the original run failure is
312
- preserved.
313
-
314
- Agent registries are explicit and host-owned. There is no global registry.
315
- String-named handoff targets require passing `registry` to `runAgent`; direct
316
- `AgentDefinition` handoff targets do not. Each handoff target is advertised as a
317
- synthetic `transfer_to_<agent>` tool, and a real tool with the same name is a
318
- configuration error.
319
-
320
- `asTool(agent)` wraps a child agent as a normal tool. The child runs to
321
- completion, its output is returned as the tool result, its usage is folded into
322
- the parent run, and its events surface as `agent.child` events. A failing child
323
- run becomes a tool error so the parent model can recover.
56
+ 1. Provider-native execution, no custom reasoning loop.
57
+ 2. Forge-backed configuration, telemetry, resilience, and lifecycle integration.
58
+ 3. Contracts over implementations for providers, tools, sessions, context, and
59
+ events.
60
+ 4. Schema-validated boundaries with fail-fast validation.
61
+ 5. Observable behavior by default.
62
+ 6. Composable modules instead of a monolithic framework.
63
+ 7. Explicit wiring and no hidden global runtime.
64
+ 8. Strong TypeScript ergonomics for common application paths.
324
65
 
325
- Durable conversation state and run-time context injection are wired into the
326
- loop. Pass `session` (from `createSession({ id })`, backed by a `SessionStore` —
327
- `InMemorySessionStore` ships built-in) to resume a conversation: prior history is
328
- read before the run and the new turn is appended after. Pass `context`
329
- (`staticContext` / `dynamicContext` providers) to inject run-time facts into the
330
- system layer — injected context and instructions are rebuilt every run and never
331
- persisted. Pass `contextWindow: { maxTokens, strategy }` to keep the request
332
- within budget via `truncateOldest()` or `summarizeOldest()`, raising
333
- `ContextWindowError` only when history is irreducible; trimming never mutates the
334
- persisted/returned history.
66
+ ## Scope
335
67
 
336
- ### Sessions and context
68
+ The root package exports the stable application surface:
337
69
 
338
- `createSession()` is synchronous. If no `id` is supplied it generates one; if an
339
- `id` is supplied with a shared store, the session resumes that history lazily on
340
- first use. Seed `messages` are written once and only when the backing store has
341
- no existing history for that id. `messages()` returns a snapshot, `append()`
342
- adds to the tail, and `clear()` deletes the history and prevents the seed from
343
- being re-applied.
70
+ - schema, message, and error helpers
71
+ - provider factories
72
+ - tool and agent definition helpers
73
+ - execution, session, and context helpers
74
+ - multi-agent helpers
75
+ - event subscribers and telemetry integration hooks
344
76
 
345
- `SessionStore` is the durable persistence contract: `load`, `append`, `save`,
346
- and `delete`. Store implementations must preserve message order, treat
347
- `append()` as an atomic tail add, and avoid exposing mutable internal arrays by
348
- reference.
77
+ Optional subpaths provide advanced or opt-in features:
349
78
 
350
- Successful runs append only conversation messages: user input, assistant turns,
351
- and tool-result messages. Instructions, injected context, and handoff-injected
352
- instructions are request-time system messages and are never persisted. Failed
353
- runs do not append new messages.
79
+ - provider adapter plumbing
80
+ - durable session stores
81
+ - shell, filesystem, HTTP, and web tool packs
82
+ - retrieval primitives for host-owned RAG pipelines
83
+ - testing doubles and provider conformance helpers
84
+ - Forge lifecycle integration
354
85
 
355
- Context providers resolve once per run before the first provider call.
356
- `staticContext()` injects fixed content; `dynamicContext()` computes content from
357
- the engine context. All provider output is folded into a system message for that
358
- request only and is never persisted.
86
+ The root barrel intentionally does not expose shell execution, filesystem
87
+ access, HTTP access, web crawling, browser automation, retrieval, or UI
88
+ components. Those capabilities are either explicit opt-in subpaths or outside
89
+ the library's scope.
359
90
 
360
- `contextWindow` applies only to the provider request view. It never mutates the
361
- canonical history returned from `runAgent` or stored in the session.
362
- `truncateOldest()` is the default stable strategy and drops oldest non-system
363
- messages while retaining system messages. `summarizeOldest()` is public, but it
364
- performs an additional provider call and should be chosen deliberately.
91
+ ## Documentation
365
92
 
366
- ### Events, subscribers, and telemetry
93
+ Consumer documentation lives in [`docs/`](./docs/README.md). The docs cover
94
+ installation, public import paths, providers, tools, execution, sessions,
95
+ context, events, multi-agent coordination, optional tool packs, testing, and
96
+ lifecycle integration.
367
97
 
368
- Use `onEvent` for a single callback and `subscribers` for fan-out:
98
+ API reference is generated with TypeDoc:
369
99
 
370
- ```ts
371
- await runAgent(agent, {
372
- input: "go",
373
- onEvent: (event) => ui.observe(event),
374
- subscribers: [loggingSubscriber(logger), messageBusSubscriber(messageBus)],
375
- });
376
- ```
377
-
378
- `onEvent` is registered first, followed by `subscribers` in array order. Each
379
- subscriber may be sync or async; subscribers are awaited in order, so slow sinks
380
- apply back-pressure. Subscriber failures are isolated: a thrown/rejected
381
- subscriber is reported to the hub's error reporter/logger and does not abort the
382
- run or prevent later subscribers from seeing the event. Undefined subscriber
383
- slots are ignored.
384
-
385
- `loggingSubscriber()` writes compact fields from `eventFields()`.
386
- `messageBusSubscriber()` publishes a serializable `eventPayload()` projection.
387
- Those projection helpers are stable on `@infinityi/engine-lib/events` for custom
388
- subscribers, but they are intentionally not root exports.
389
-
390
- For telemetry, the stable application path is passing a Forge telemetry handle
391
- to `runAgent`. That enables `agent.run`, `agent.provider.call`, and
392
- `agent.tool.execute` spans plus `agent.run.duration`, `agent.tool.duration`,
393
- `agent.tokens`, and `agent.runs` metrics. `createRunTelemetry()` and the span
394
- constants are available from `@infinityi/engine-lib/events` for advanced integrations and
395
- tests.
396
-
397
- ### Multi-agent coordination
398
-
399
- Compose agents in two complementary ways. Both reuse the same `runAgent` loop —
400
- no separate orchestrator.
401
-
402
- **Handoff / delegation.** Declare `handoffs` on an agent and each target becomes
403
- a synthetic `transfer_to_<name>` tool the model can call to transfer the running
404
- conversation to a specialist. The message history is preserved across the switch;
405
- the new agent's instructions are injected as an additional system message. The
406
- `RunResult` reports the agent that produced the final answer (`result.agent`) and
407
- the ordered `result.handoffs` trail. A `maxHandoffs` cap (default 8) bounds
408
- triage↔specialist ping-pong with `MaxHandoffsExceededError`. Targets may be given
409
- directly as an `AgentDefinition`, or by name as a `string` resolved through an
410
- `AgentRegistry` passed in `RunOptions.registry`.
411
-
412
- ```ts
413
- import { defineAgent, runAgent, createAgentRegistry } from "@infinityi/engine-lib";
414
-
415
- const billing = defineAgent({ name: "billing", provider, instructions: "Handle billing." });
416
- const triage = defineAgent({
417
- name: "triage",
418
- provider,
419
- instructions: "Route the user to the right specialist.",
420
- handoffs: [billing], // → exposes a `transfer_to_billing` tool
421
- });
422
-
423
- const result = await runAgent(triage, { input: "I want a refund" });
424
- result.agent; // "billing" — the specialist answered
425
- result.handoffs; // ["billing"] — the transfer trail
426
-
427
- // String-named targets resolve via a registry (no global state):
428
- const registry = createAgentRegistry([billing]);
429
- const router = defineAgent({ name: "router", provider, handoffs: ["billing"] });
430
- await runAgent(router, { input: "…", registry });
100
+ ```bash
101
+ bun run docs
431
102
  ```
432
103
 
433
- **Sub-agent-as-tool.** Wrap an agent as a `ToolDefinition` with `asTool(agent)`
434
- so a parent invokes it through the normal tool-calling path. The child runs to
435
- completion and its output is fed back as the tool result; the child's token usage
436
- is folded into the parent's total and its events surface to the parent as
437
- `agent.child` events (with `depth` tracking nesting).
104
+ Generated API output is written to `docs/api/`.
438
105
 
439
- ```ts
440
- import { asTool, defineAgent } from "@infinityi/engine-lib";
106
+ ## Development
441
107
 
442
- const researcher = defineAgent({ name: "researcher", provider, instructions: "Research deeply." });
443
- const lead = defineAgent({
444
- name: "lead",
445
- provider,
446
- tools: [asTool(researcher, { description: "Delegate research to a specialist." })],
447
- });
448
- // lead's model calls the "researcher" tool → child run executes → output fed back.
108
+ ```bash
109
+ bun install
110
+ bun run check
111
+ bun test
112
+ bun run build
449
113
  ```
450
114
 
451
- ### Developer experience & conformance
452
-
453
- Three things make the library trustworthy to adopt:
454
-
455
- - **Provider conformance suite** — a fixture-driven battery, shipped from
456
- `@infinityi/engine-lib/testing/conformance`, that every adapter must pass (buffered
457
- completion, streaming, tool calling, usage, capability honesty, error
458
- mapping). Each adapter supplies its native wire fixtures plus the canonical
459
- normalized values; the battery drives the public `Provider` seam through an
460
- injected fake `fetch`, so third-party adapters can prove parity with the
461
- in-house ones. Pass Bun's `{ describe, expect, it }` as `testApi` when
462
- registering the battery. All four built-in adapters are wired through it.
463
- - **Lifecycle adapter** — `agentRuntimeComponent()` (from `@infinityi/engine-lib/lifecycle`)
464
- adapts the runtime to a `forge/lifecycle` `Component`: `start()` fail-fast
465
- validates providers (and optionally probes them so a bad deploy rolls back in
466
- `forge.boot`), `healthcheck()` maps provider probes to a forge `HealthResult`,
467
- and `stop()` runs an `onStop` hook (e.g. flush/close a durable session store).
468
- - **Test doubles & examples** — network-free helpers in `@infinityi/engine-lib/testing`
469
- (`mockProvider`, `scriptedProvider`, `textResult`/`toolCallResult`,
470
- `jsonFetch`/`sseFetch`, `inMemorySessionStore`) let consumers unit-test agents
471
- deterministically, and [`examples/`](./examples/) holds runnable versions of
472
- the scenarios above.
473
-
474
- ```ts
475
- import { boot } from "@infinityi/forge/lifecycle";
476
- import { agentRuntimeComponent } from "@infinityi/engine-lib/lifecycle";
477
-
478
- const app = await boot({
479
- components: [agentRuntimeComponent({ providers: [provider], sessionStore, probeOnStart: true })],
480
- });
481
- // app.ready === true; app.stop() drains it (running the optional onStop hook).
482
- ```
115
+ Useful scripts:
483
116
 
484
- (An optional `forge/data`-backed `SessionStore` is deferred to a later change.)
117
+ - `bun run check` - type-check the repository
118
+ - `bun test` - run the test suite
119
+ - `bun run build` - emit JavaScript and declaration files to `dist/`
120
+ - `bun run docs` - generate TypeDoc API reference
485
121
 
486
122
  ## License
487
123
 
488
- MIT see [`LICENSE`](./LICENSE).
124
+ MIT - see [`LICENSE`](./LICENSE).
@@ -2,27 +2,33 @@ import {
2
2
  asTool,
3
3
  createAgentRegistry,
4
4
  defineAgent
5
- } from "../index-jp2b31xs.js";
5
+ } from "../index-vwcyawfk.js";
6
6
  import {
7
7
  createToolRegistry,
8
8
  handoffProviderTools,
9
9
  handoffToolName,
10
10
  resolveHandoffTargets
11
- } from "../index-pwr8179t.js";
12
- import"../index-yrqrxwjt.js";
11
+ } from "../index-7nb9qwa1.js";
13
12
  import"../index-fkr3rcq9.js";
14
- import"../index-02s1fjxr.js";
13
+ import"../index-ycjsqfpq.js";
14
+ import"../index-nvdsr51v.js";
15
+ import"../index-c6kgts41.js";
16
+ import"../index-k0q7x4mz.js";
15
17
  import"../index-zfgr4xx3.js";
16
- import"../index-7690reng.js";
17
- import {
18
- defineTool
19
- } from "../index-w34cbktd.js";
18
+ import"../index-9rr5dkzh.js";
20
19
  import {
21
20
  renderToolContent,
22
21
  toProviderTool,
23
22
  toToolResultMessage
24
23
  } from "../index-rentvdpp.js";
25
24
  import"../index-1p6mb2vz.js";
25
+ import"../index-mnx5mqbs.js";
26
+ import"../index-4c15ysa8.js";
27
+ import"../index-ajr3nk10.js";
28
+ import {
29
+ defineTool
30
+ } from "../index-a67ej96j.js";
31
+ import"../index-37x76zdn.js";
26
32
  export {
27
33
  toToolResultMessage,
28
34
  toProviderTool,
@@ -8,4 +8,4 @@
8
8
  */
9
9
  export { dynamicContext, resolveContext, staticContext } from "./providers";
10
10
  export { applyContextWindow, estimateTokens, summarizeOldest, truncateOldest, } from "./window";
11
- export type { ContextItem, ContextProvider, ContextStrategy, ContextStrategyContext, ContextWindowOptions, TokenCounter, } from "./types";
11
+ export type { ContextItem, ContextProvider, ContextResolveContext, ContextStrategy, ContextStrategyContext, ContextWindowOptions, TokenCounter, } from "./types";
@@ -1,15 +1,18 @@
1
1
  import"../index-d4xz3abn.js";
2
2
  import {
3
- applyContextWindow,
4
3
  dynamicContext,
5
- estimateTokens,
6
4
  resolveContext,
7
- staticContext,
5
+ staticContext
6
+ } from "../index-ycjsqfpq.js";
7
+ import {
8
+ applyContextWindow,
9
+ estimateTokens,
8
10
  summarizeOldest,
9
11
  truncateOldest
10
- } from "../index-yrqrxwjt.js";
11
- import"../index-7690reng.js";
12
+ } from "../index-nvdsr51v.js";
12
13
  import"../index-1p6mb2vz.js";
14
+ import"../index-ajr3nk10.js";
15
+ import"../index-37x76zdn.js";
13
16
  export {
14
17
  truncateOldest,
15
18
  summarizeOldest,