@infinityi/engine-lib 1.0.0 → 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.
- package/README.md +81 -445
- package/dist/agent/index.js +14 -8
- package/dist/context/index.d.ts +1 -1
- package/dist/context/index.js +8 -5
- package/dist/context/providers.d.ts +3 -3
- package/dist/context/types.d.ts +16 -1
- package/dist/errors.d.ts +18 -0
- package/dist/errors.js +6 -1
- package/dist/events/index.js +2 -1
- package/dist/execution/index.js +9 -4
- package/dist/execution/types.d.ts +14 -0
- package/dist/index-37x76zdn.js +4 -0
- package/dist/index-4c15ysa8.js +84 -0
- package/dist/{index-pwr8179t.js → index-7nb9qwa1.js} +23 -14
- package/dist/{index-jxgj4z08.js → index-9egrqxkf.js} +4 -0
- package/dist/index-9rr5dkzh.js +0 -0
- package/dist/{index-w34cbktd.js → index-a67ej96j.js} +1 -0
- package/dist/{index-64tt9696.js → index-aed6fe4z.js} +3 -3
- package/dist/{index-7690reng.js → index-ajr3nk10.js} +15 -1
- package/dist/index-c6kgts41.js +0 -0
- package/dist/{index-xsv43c5j.js → index-e14g2e48.js} +2 -2
- package/dist/index-k0q7x4mz.js +54 -0
- package/dist/index-mnx5mqbs.js +102 -0
- package/dist/index-mr1hs98z.js +661 -0
- package/dist/{index-yrqrxwjt.js → index-nvdsr51v.js} +4 -38
- package/dist/{index-jp2b31xs.js → index-vwcyawfk.js} +4 -4
- package/dist/index-ycjsqfpq.js +39 -0
- package/dist/{index-bqg01r42.js → index-zdggff0y.js} +183 -180
- package/dist/index.d.ts +2 -2
- package/dist/index.js +49 -38
- package/dist/lifecycle/index.js +2 -0
- package/dist/messages/index.js +1 -0
- package/dist/providers/index.js +5 -4
- package/dist/retrieval/chunking.d.ts +8 -0
- package/dist/retrieval/context.d.ts +4 -0
- package/dist/retrieval/index.d.ts +19 -0
- package/dist/retrieval/index.js +747 -0
- package/dist/retrieval/loaders.d.ts +8 -0
- package/dist/retrieval/memory.d.ts +29 -0
- package/dist/retrieval/retriever.d.ts +8 -0
- package/dist/retrieval/types.d.ts +253 -0
- package/dist/retrieval/utils.d.ts +11 -0
- package/dist/retrieval/vector-store.d.ts +13 -0
- package/dist/runtime/index.js +2 -1
- package/dist/schema/index.js +10 -4
- package/dist/session/index.js +1 -0
- package/dist/session-stores/codec.d.ts +8 -0
- package/dist/session-stores/forge-data.d.ts +43 -0
- package/dist/session-stores/hooks.d.ts +4 -0
- package/dist/session-stores/ids.d.ts +3 -0
- package/dist/session-stores/index.d.ts +20 -0
- package/dist/session-stores/index.js +1382 -0
- package/dist/session-stores/jsonl.d.ts +26 -0
- package/dist/session-stores/redis.d.ts +45 -0
- package/dist/session-stores/types.d.ts +45 -0
- package/dist/session-stores/versioning.d.ts +6 -0
- package/dist/testing/conformance.js +5 -4
- package/dist/testing/index.js +1 -0
- package/dist/tools/index.js +5 -3
- package/dist/tools-fs/define.d.ts +2 -0
- package/dist/tools-fs/files.d.ts +40 -0
- package/dist/tools-fs/git.d.ts +14 -0
- package/dist/tools-fs/index.d.ts +19 -0
- package/dist/tools-fs/index.js +1695 -0
- package/dist/tools-fs/policy.d.ts +32 -0
- package/dist/tools-fs/schemas.d.ts +31 -0
- package/dist/tools-fs/search.d.ts +45 -0
- package/dist/tools-fs/symbols.d.ts +12 -0
- package/dist/tools-fs/types.d.ts +151 -0
- package/dist/tools-http/client.d.ts +12 -0
- package/dist/tools-http/define.d.ts +12 -0
- package/dist/tools-http/events.d.ts +22 -0
- package/dist/tools-http/index.d.ts +24 -0
- package/dist/tools-http/index.js +18 -0
- package/dist/tools-http/policy.d.ts +52 -0
- package/dist/tools-http/types.d.ts +116 -0
- package/dist/tools-shell/define.d.ts +23 -0
- package/dist/tools-shell/events.d.ts +38 -0
- package/dist/tools-shell/exec.d.ts +37 -0
- package/dist/tools-shell/index.d.ts +30 -0
- package/dist/tools-shell/index.js +327 -0
- package/dist/tools-shell/policy.d.ts +42 -0
- package/dist/tools-shell/types.d.ts +121 -0
- package/dist/tools-web/define.d.ts +11 -0
- package/dist/tools-web/html.d.ts +22 -0
- package/dist/tools-web/index.d.ts +21 -0
- package/dist/tools-web/index.js +472 -0
- package/dist/tools-web/types.d.ts +81 -0
- package/docs/README.md +58 -10
- package/docs/api/.nojekyll +1 -0
- package/docs/api/assets/hierarchy.js +1 -0
- package/docs/api/assets/highlight.css +99 -0
- package/docs/api/assets/icons.js +18 -0
- package/docs/api/assets/icons.svg +1 -0
- package/docs/api/assets/main.js +60 -0
- package/docs/api/assets/navigation.js +1 -0
- package/docs/api/assets/search.js +1 -0
- package/docs/api/assets/style.css +1633 -0
- package/docs/api/classes/errors.AgentError.html +47 -0
- package/docs/api/classes/errors.CancelledError.html +46 -0
- package/docs/api/classes/errors.ContextWindowError.html +48 -0
- package/docs/api/classes/errors.ExecutionError.html +46 -0
- package/docs/api/classes/errors.FilesystemPolicyError.html +48 -0
- package/docs/api/classes/errors.MaxHandoffsExceededError.html +47 -0
- package/docs/api/classes/errors.MaxStepsExceededError.html +47 -0
- package/docs/api/classes/errors.ProviderError.html +47 -0
- package/docs/api/classes/errors.SchemaValidationError.html +47 -0
- package/docs/api/classes/errors.ShellPolicyError.html +50 -0
- package/docs/api/classes/errors.ToolError.html +47 -0
- package/docs/api/classes/errors.ToolValidationError.html +48 -0
- package/docs/api/classes/index.InMemorySessionStore.html +11 -0
- package/docs/api/classes/index.Secret.html +20 -0
- package/docs/api/classes/providers.StreamAccumulator.html +8 -0
- package/docs/api/classes/session-stores.FilesystemJsonlSessionStore.html +13 -0
- package/docs/api/classes/session-stores.ForgeDataSessionStore.html +14 -0
- package/docs/api/classes/session-stores.RedisSessionStore.html +12 -0
- package/docs/api/classes/tools-http.HttpPolicyError.html +41 -0
- package/docs/api/functions/agent.createToolRegistry.html +3 -0
- package/docs/api/functions/agent.handoffProviderTools.html +3 -0
- package/docs/api/functions/agent.handoffToolName.html +2 -0
- package/docs/api/functions/agent.resolveHandoffTargets.html +8 -0
- package/docs/api/functions/context.applyContextWindow.html +5 -0
- package/docs/api/functions/context.estimateTokens.html +3 -0
- package/docs/api/functions/context.resolveContext.html +5 -0
- package/docs/api/functions/events.createRunTelemetry.html +3 -0
- package/docs/api/functions/events.eventFields.html +4 -0
- package/docs/api/functions/events.eventPayload.html +5 -0
- package/docs/api/functions/execution.addUsage.html +2 -0
- package/docs/api/functions/execution.emptyUsage.html +2 -0
- package/docs/api/functions/index.asSchema.html +4 -0
- package/docs/api/functions/index.asTool.html +8 -0
- package/docs/api/functions/index.assistant.html +2 -0
- package/docs/api/functions/index.createAgentRegistry.html +5 -0
- package/docs/api/functions/index.createAnthropic.html +5 -0
- package/docs/api/functions/index.createEventHub.html +2 -0
- package/docs/api/functions/index.createGoogle.html +5 -0
- package/docs/api/functions/index.createOpenAI.html +5 -0
- package/docs/api/functions/index.createOpenAICompatible.html +7 -0
- package/docs/api/functions/index.createSession.html +3 -0
- package/docs/api/functions/index.defineAgent.html +7 -0
- package/docs/api/functions/index.defineTool.html +7 -0
- package/docs/api/functions/index.dynamicContext.html +2 -0
- package/docs/api/functions/index.fromJsonSchema.html +3 -0
- package/docs/api/functions/index.isSecret.html +4 -0
- package/docs/api/functions/index.loggingSubscriber.html +4 -0
- package/docs/api/functions/index.messageBusSubscriber.html +6 -0
- package/docs/api/functions/index.normalizeContent.html +2 -0
- package/docs/api/functions/index.resolveSecret.html +4 -0
- package/docs/api/functions/index.runAgent.html +19 -0
- package/docs/api/functions/index.staticContext.html +3 -0
- package/docs/api/functions/index.summarizeOldest.html +4 -0
- package/docs/api/functions/index.system.html +2 -0
- package/docs/api/functions/index.text.html +2 -0
- package/docs/api/functions/index.toJsonSchema.html +2 -0
- package/docs/api/functions/index.toolResult.html +2 -0
- package/docs/api/functions/index.truncateOldest.html +5 -0
- package/docs/api/functions/index.user.html +2 -0
- package/docs/api/functions/index.validateJsonSchema.html +3 -0
- package/docs/api/functions/lifecycle.agentRuntimeComponent.html +5 -0
- package/docs/api/functions/providers.collectStream.html +2 -0
- package/docs/api/functions/providers.createProvider.html +4 -0
- package/docs/api/functions/providers.createProviderHttp.html +3 -0
- package/docs/api/functions/providers.defaultProviderResilience.html +3 -0
- package/docs/api/functions/providers.openSseStream.html +6 -0
- package/docs/api/functions/providers.parseSse.html +2 -0
- package/docs/api/functions/providers.toProviderError.html +2 -0
- package/docs/api/functions/session-stores.createPostgresSessionStore.html +1 -0
- package/docs/api/functions/session-stores.createSqliteSessionStore.html +1 -0
- package/docs/api/functions/session-stores.isCloseableSessionStore.html +1 -0
- package/docs/api/functions/session-stores.isVersionedSessionStore.html +1 -0
- package/docs/api/functions/session-stores.migrateSessionStore.html +1 -0
- package/docs/api/functions/session-stores.withSessionStoreHooks.html +2 -0
- package/docs/api/functions/testing.byteStreamOf.html +2 -0
- package/docs/api/functions/testing.collectProviderStream.html +2 -0
- package/docs/api/functions/testing.conversation.html +2 -0
- package/docs/api/functions/testing.expectValid.html +3 -0
- package/docs/api/functions/testing.inMemorySessionStore.html +2 -0
- package/docs/api/functions/testing.jsonFetch.html +3 -0
- package/docs/api/functions/testing.mockProvider.html +3 -0
- package/docs/api/functions/testing.scriptedProvider.html +4 -0
- package/docs/api/functions/testing.sseFetch.html +3 -0
- package/docs/api/functions/testing.textResult.html +3 -0
- package/docs/api/functions/testing.toolCallResult.html +3 -0
- package/docs/api/functions/testing_conformance.runProviderConformance.html +3 -0
- package/docs/api/functions/tools-fs.filesystemTools.html +1 -0
- package/docs/api/functions/tools-http.createHttpToolClient.html +2 -0
- package/docs/api/functions/tools-http.httpTools.html +2 -0
- package/docs/api/functions/tools-shell.shellTools.html +4 -0
- package/docs/api/functions/tools-web.webTools.html +2 -0
- package/docs/api/functions/tools.renderToolContent.html +6 -0
- package/docs/api/functions/tools.toProviderTool.html +3 -0
- package/docs/api/functions/tools.toToolResultMessage.html +4 -0
- package/docs/api/hierarchy.html +1 -0
- package/docs/api/index.html +1 -0
- package/docs/api/interfaces/agent.ToolRegistry.html +8 -0
- package/docs/api/interfaces/errors.SchemaIssue.html +4 -0
- package/docs/api/interfaces/events.RunTelemetry.html +10 -0
- package/docs/api/interfaces/events.SpanHandle.html +6 -0
- package/docs/api/interfaces/index.AgentDefinition.html +16 -0
- package/docs/api/interfaces/index.AgentHooks.html +21 -0
- package/docs/api/interfaces/index.AgentRegistry.html +16 -0
- package/docs/api/interfaces/index.AnthropicOptions.html +13 -0
- package/docs/api/interfaces/index.AsToolOptions.html +13 -0
- package/docs/api/interfaces/index.CompletionRequest.html +30 -0
- package/docs/api/interfaces/index.CompletionResult.html +14 -0
- package/docs/api/interfaces/index.ContextItem.html +6 -0
- package/docs/api/interfaces/index.ContextProvider.html +5 -0
- package/docs/api/interfaces/index.ContextStrategy.html +8 -0
- package/docs/api/interfaces/index.ContextStrategyContext.html +8 -0
- package/docs/api/interfaces/index.ContextWindowOptions.html +8 -0
- package/docs/api/interfaces/index.CreateSessionOptions.html +10 -0
- package/docs/api/interfaces/index.EngineContext.html +10 -0
- package/docs/api/interfaces/index.EventHub.html +4 -0
- package/docs/api/interfaces/index.EventHubOptions.html +8 -0
- package/docs/api/interfaces/index.GenerationSettings.html +12 -0
- package/docs/api/interfaces/index.GoogleOptions.html +11 -0
- package/docs/api/interfaces/index.ImagePart.html +5 -0
- package/docs/api/interfaces/index.InstructionContext.html +9 -0
- package/docs/api/interfaces/index.JsonSchema.html +18 -0
- package/docs/api/interfaces/index.LoggingSubscriberOptions.html +4 -0
- package/docs/api/interfaces/index.Message.html +8 -0
- package/docs/api/interfaces/index.MessageBusSubscriberOptions.html +4 -0
- package/docs/api/interfaces/index.OpenAICompatibleOptions.html +16 -0
- package/docs/api/interfaces/index.OpenAIOptions.html +16 -0
- package/docs/api/interfaces/index.Provider.html +11 -0
- package/docs/api/interfaces/index.ProviderCapabilities.html +9 -0
- package/docs/api/interfaces/index.ProviderTool.html +6 -0
- package/docs/api/interfaces/index.ResponseSchema.html +6 -0
- package/docs/api/interfaces/index.RunBridge.html +10 -0
- package/docs/api/interfaces/index.RunOptions.html +39 -0
- package/docs/api/interfaces/index.RunResult.html +20 -0
- package/docs/api/interfaces/index.Schema.html +13 -0
- package/docs/api/interfaces/index.Session.html +13 -0
- package/docs/api/interfaces/index.SessionState.html +5 -0
- package/docs/api/interfaces/index.SessionStore.html +15 -0
- package/docs/api/interfaces/index.TextPart.html +4 -0
- package/docs/api/interfaces/index.ToolCall.html +9 -0
- package/docs/api/interfaces/index.ToolCallPart.html +6 -0
- package/docs/api/interfaces/index.ToolContext.html +21 -0
- package/docs/api/interfaces/index.ToolDefinition.html +14 -0
- package/docs/api/interfaces/index.ToolFailure.html +9 -0
- package/docs/api/interfaces/index.ToolResultPart.html +8 -0
- package/docs/api/interfaces/index.ToolSpec.html +6 -0
- package/docs/api/interfaces/index.ToolSuccess.html +6 -0
- package/docs/api/interfaces/index.Usage.html +9 -0
- package/docs/api/interfaces/lifecycle.AgentRuntimeOptions.html +17 -0
- package/docs/api/interfaces/providers.AdapterSpec.html +17 -0
- package/docs/api/interfaces/providers.ProviderHttpOptions.html +14 -0
- package/docs/api/interfaces/providers.SseMessage.html +6 -0
- package/docs/api/interfaces/providers.SseRequest.html +8 -0
- package/docs/api/interfaces/runtime.Logger.html +22 -0
- package/docs/api/interfaces/runtime.Telemetry.html +9 -0
- package/docs/api/interfaces/schema.OptionalSchema.html +13 -0
- package/docs/api/interfaces/session-stores.CloseableSessionStore.html +11 -0
- package/docs/api/interfaces/session-stores.CreatePostgresSessionStoreOptions.html +6 -0
- package/docs/api/interfaces/session-stores.CreateSqliteSessionStoreOptions.html +7 -0
- package/docs/api/interfaces/session-stores.FilesystemJsonlSessionStoreOptions.html +3 -0
- package/docs/api/interfaces/session-stores.ForgeDataSessionStoreOptions.html +5 -0
- package/docs/api/interfaces/session-stores.RedisSessionStoreClient.html +9 -0
- package/docs/api/interfaces/session-stores.RedisSessionStoreOptions.html +4 -0
- package/docs/api/interfaces/session-stores.RedisSessionStoreTransaction.html +6 -0
- package/docs/api/interfaces/session-stores.SessionArchiveRecord.html +7 -0
- package/docs/api/interfaces/session-stores.SessionArchiver.html +2 -0
- package/docs/api/interfaces/session-stores.SessionCompactionResult.html +3 -0
- package/docs/api/interfaces/session-stores.SessionCompactor.html +3 -0
- package/docs/api/interfaces/session-stores.SessionStoreCodec.html +6 -0
- package/docs/api/interfaces/session-stores.SessionStoreHookContext.html +3 -0
- package/docs/api/interfaces/session-stores.SessionStoreHooks.html +3 -0
- package/docs/api/interfaces/session-stores.VersionedSessionStore.html +11 -0
- package/docs/api/interfaces/testing.MockProviderOptions.html +12 -0
- package/docs/api/interfaces/testing.RecordedCall.html +4 -0
- package/docs/api/interfaces/testing.RecordingFetch.html +4 -0
- package/docs/api/interfaces/testing_conformance.ConformanceFixtures.html +12 -0
- package/docs/api/interfaces/testing_conformance.ConformanceOptions.html +10 -0
- package/docs/api/interfaces/testing_conformance.ConformanceTestApi.html +4 -0
- package/docs/api/interfaces/testing_conformance.ProviderIO.html +7 -0
- package/docs/api/interfaces/tools-fs.ApplyPatchArgs.html +6 -0
- package/docs/api/interfaces/tools-fs.DiffStatusArgs.html +5 -0
- package/docs/api/interfaces/tools-fs.EditRangeArgs.html +7 -0
- package/docs/api/interfaces/tools-fs.EditReplaceArgs.html +7 -0
- package/docs/api/interfaces/tools-fs.FilesystemTools.html +13 -0
- package/docs/api/interfaces/tools-fs.FilesystemToolsConfig.html +12 -0
- package/docs/api/interfaces/tools-fs.FindFilesArgs.html +7 -0
- package/docs/api/interfaces/tools-fs.OpenWindowArgs.html +5 -0
- package/docs/api/interfaces/tools-fs.ReadArgs.html +9 -0
- package/docs/api/interfaces/tools-fs.RepoMapArgs.html +7 -0
- package/docs/api/interfaces/tools-fs.SearchSemanticArgs.html +8 -0
- package/docs/api/interfaces/tools-fs.SearchTextArgs.html +11 -0
- package/docs/api/interfaces/tools-fs.SymbolInfo.html +7 -0
- package/docs/api/interfaces/tools-fs.SymbolsArgs.html +5 -0
- package/docs/api/interfaces/tools-fs.ValidationCommandRequest.html +4 -0
- package/docs/api/interfaces/tools-fs.ValidationCommandResult.html +6 -0
- package/docs/api/interfaces/tools-fs.ValidationOptions.html +4 -0
- package/docs/api/interfaces/tools-fs.WriteFileArgs.html +6 -0
- package/docs/api/interfaces/tools-http.HeaderEntry.html +4 -0
- package/docs/api/interfaces/tools-http.HttpClientRequest.html +11 -0
- package/docs/api/interfaces/tools-http.HttpPolicy.html +13 -0
- package/docs/api/interfaces/tools-http.HttpRequestResult.html +17 -0
- package/docs/api/interfaces/tools-http.HttpRetryOptions.html +10 -0
- package/docs/api/interfaces/tools-http.HttpToolClient.html +5 -0
- package/docs/api/interfaces/tools-http.HttpTools.html +4 -0
- package/docs/api/interfaces/tools-http.HttpToolsConfig.html +38 -0
- package/docs/api/interfaces/tools-shell.ApprovalDecision.html +5 -0
- package/docs/api/interfaces/tools-shell.CommandRequest.html +14 -0
- package/docs/api/interfaces/tools-shell.CommandResult.html +21 -0
- package/docs/api/interfaces/tools-shell.EnvPolicy.html +9 -0
- package/docs/api/interfaces/tools-shell.ShellPolicy.html +7 -0
- package/docs/api/interfaces/tools-shell.ShellTools.html +6 -0
- package/docs/api/interfaces/tools-shell.ShellToolsConfig.html +26 -0
- package/docs/api/interfaces/tools-web.Citation.html +6 -0
- package/docs/api/interfaces/tools-web.SearchProvider.html +3 -0
- package/docs/api/interfaces/tools-web.SearchRequest.html +4 -0
- package/docs/api/interfaces/tools-web.SearchResult.html +7 -0
- package/docs/api/interfaces/tools-web.SourceMetadata.html +10 -0
- package/docs/api/interfaces/tools-web.WebTools.html +6 -0
- package/docs/api/interfaces/tools-web.WebToolsConfig.html +56 -0
- package/docs/api/modules/agent.html +5 -0
- package/docs/api/modules/context.html +5 -0
- package/docs/api/modules/errors.html +8 -0
- package/docs/api/modules/events.html +16 -0
- package/docs/api/modules/execution.html +4 -0
- package/docs/api/modules/index.html +16 -0
- package/docs/api/modules/lifecycle.html +6 -0
- package/docs/api/modules/messages.html +3 -0
- package/docs/api/modules/providers.html +10 -0
- package/docs/api/modules/runtime.html +4 -0
- package/docs/api/modules/schema.html +5 -0
- package/docs/api/modules/session-stores.html +6 -0
- package/docs/api/modules/session.html +4 -0
- package/docs/api/modules/testing.html +4 -0
- package/docs/api/modules/testing_conformance.html +21 -0
- package/docs/api/modules/tools-fs.html +9 -0
- package/docs/api/modules/tools-http.html +8 -0
- package/docs/api/modules/tools-shell.html +12 -0
- package/docs/api/modules/tools-web.html +7 -0
- package/docs/api/modules/tools.html +4 -0
- package/docs/api/types/events.Attrs.html +2 -0
- package/docs/api/types/index.AnyRunOptions.html +3 -0
- package/docs/api/types/index.BufferedRunOptions.html +2 -0
- package/docs/api/types/index.ContentPart.html +2 -0
- package/docs/api/types/index.FinishReason.html +2 -0
- package/docs/api/types/index.Infer.html +2 -0
- package/docs/api/types/index.Instructions.html +5 -0
- package/docs/api/types/index.LogLevel.html +2 -0
- package/docs/api/types/index.Role.html +2 -0
- package/docs/api/types/index.RunEvent.html +30 -0
- package/docs/api/types/index.RunHandle.html +7 -0
- package/docs/api/types/index.RunInput.html +2 -0
- package/docs/api/types/index.RunSubscriber.html +4 -0
- package/docs/api/types/index.SafeParseResult.html +2 -0
- package/docs/api/types/index.StreamEvent.html +8 -0
- package/docs/api/types/index.StreamingRunOptions.html +2 -0
- package/docs/api/types/index.TelemetryHandle.html +2 -0
- package/docs/api/types/index.TokenCounter.html +2 -0
- package/docs/api/types/index.ToolChoice.html +2 -0
- package/docs/api/types/index.ToolResult.html +2 -0
- package/docs/api/types/lifecycle.ProviderProbe.html +2 -0
- package/docs/api/types/session-stores.SessionStoreHookOperation.html +1 -0
- package/docs/api/types/testing_conformance.MakeProvider.html +2 -0
- package/docs/api/types/tools-fs.SymbolKind.html +1 -0
- package/docs/api/types/tools-http.HostPattern.html +2 -0
- package/docs/api/types/tools-shell.CommandPattern.html +2 -0
- package/docs/api/types/tools-web.RobotsPolicy.html +2 -0
- package/docs/api/variables/events.SPAN_PROVIDER.html +2 -0
- package/docs/api/variables/events.SPAN_RUN.html +2 -0
- package/docs/api/variables/events.SPAN_TOOL.html +2 -0
- package/docs/api/variables/execution.DEFAULT_MAX_HANDOFFS.html +2 -0
- package/docs/api/variables/execution.DEFAULT_MAX_STEPS.html +2 -0
- package/docs/api/variables/index.s.html +11 -0
- package/docs/api/variables/providers.DEFAULT_TIMEOUT_MS.html +2 -0
- package/docs/api/variables/session-stores.SESSION_STORE_SCHEMA_VERSION.html +1 -0
- package/docs/api/variables/session-stores.jsonSessionStoreCodec.html +2 -0
- package/docs/api/variables/tools-http.HTTP_EVENT.html +2 -0
- package/docs/api/variables/tools-shell.SHELL_EVENT.html +2 -0
- package/docs/events-and-telemetry.md +68 -0
- package/docs/execution.md +63 -0
- package/docs/getting-started.md +73 -0
- package/docs/multi-agent.md +52 -0
- package/docs/optional-tool-packs.md +93 -0
- package/docs/providers.md +68 -0
- package/docs/retrieval.md +83 -0
- package/docs/sessions-and-context.md +82 -0
- package/docs/testing-and-lifecycle.md +60 -0
- package/docs/tools.md +69 -0
- package/examples/01-minimal-agent.ts +19 -0
- package/examples/02-custom-tool.ts +32 -0
- package/examples/03-streaming.ts +46 -0
- package/examples/04-sessions-context.ts +40 -0
- package/examples/05-events-subscribers.ts +35 -0
- package/examples/06-multi-agent-handoff.ts +27 -0
- package/examples/07-sub-agent-tool.ts +26 -0
- package/examples/08-testing-agent.ts +31 -0
- package/examples/09-tools-filesystem.ts +49 -0
- package/examples/10-tools-http-web.ts +74 -0
- package/examples/11-shell-tools.ts +39 -0
- package/examples/12-provider-openai.ts +24 -0
- package/examples/13-lifecycle.ts +37 -0
- package/examples/14-retrieval.ts +65 -0
- package/examples/incident-analysis.ts +39 -87
- package/package.json +78 -4
- package/dist/index-02s1fjxr.js +0 -226
- package/examples/README.md +0 -24
- package/examples/lifecycle.ts +0 -53
- package/examples/multi-agent.ts +0 -93
- package/examples/terminal-coder.ts +0 -80
package/README.md
CHANGED
|
@@ -6,483 +6,119 @@
|
|
|
6
6
|
[](https://www.typescriptlang.org/)
|
|
7
7
|
[](https://opensource.org/licenses/MIT)
|
|
8
8
|
|
|
9
|
-
---
|
|
10
|
-
|
|
11
9
|
## Project Goal
|
|
12
10
|
|
|
13
|
-
Every project that wants to
|
|
14
|
-
a provider client, a message/content model, a tool-calling loop,
|
|
15
|
-
context injection, and a way to observe what the agent is doing.
|
|
16
|
-
error-prone, and
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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 |
|
|
53
|
-
|
|
|
54
|
-
|
|
|
55
|
-
|
|
|
56
|
-
|
|
|
57
|
-
|
|
|
58
|
-
|
|
|
59
|
-
|
|
|
60
|
-
|
|
|
61
|
-
|
|
|
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.
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
-
|
|
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
|
-
|
|
68
|
+
The root package exports the stable application surface:
|
|
337
69
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
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
|
-
|
|
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
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
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
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
98
|
+
API reference is generated with TypeDoc:
|
|
369
99
|
|
|
370
|
-
```
|
|
371
|
-
|
|
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
|
-
|
|
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
|
-
|
|
440
|
-
import { asTool, defineAgent } from "@infinityi/engine-lib";
|
|
106
|
+
## Development
|
|
441
107
|
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
124
|
+
MIT - see [`LICENSE`](./LICENSE).
|
package/dist/agent/index.js
CHANGED
|
@@ -2,27 +2,33 @@ import {
|
|
|
2
2
|
asTool,
|
|
3
3
|
createAgentRegistry,
|
|
4
4
|
defineAgent
|
|
5
|
-
} from "../index-
|
|
5
|
+
} from "../index-vwcyawfk.js";
|
|
6
6
|
import {
|
|
7
7
|
createToolRegistry,
|
|
8
8
|
handoffProviderTools,
|
|
9
9
|
handoffToolName,
|
|
10
10
|
resolveHandoffTargets
|
|
11
|
-
} from "../index-
|
|
12
|
-
import"../index-yrqrxwjt.js";
|
|
11
|
+
} from "../index-7nb9qwa1.js";
|
|
13
12
|
import"../index-fkr3rcq9.js";
|
|
14
|
-
import"../index-
|
|
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-
|
|
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,
|
package/dist/context/index.d.ts
CHANGED
|
@@ -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";
|
package/dist/context/index.js
CHANGED
|
@@ -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-
|
|
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,
|