@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
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# Getting started
|
|
2
|
+
|
|
3
|
+
Install the package in an application:
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
bun add @infinityi/engine-lib
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
For local development in this repository:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
bun install
|
|
13
|
+
bun run check
|
|
14
|
+
bun test
|
|
15
|
+
bun run build
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Minimal run
|
|
19
|
+
|
|
20
|
+
Use a real provider in production and the testing provider in examples or unit
|
|
21
|
+
tests:
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { defineAgent, runAgent } from "@infinityi/engine-lib";
|
|
25
|
+
import { mockProvider, textResult } from "@infinityi/engine-lib/testing";
|
|
26
|
+
|
|
27
|
+
const agent = defineAgent({
|
|
28
|
+
name: "assistant",
|
|
29
|
+
provider: mockProvider({ result: () => textResult("hello") }),
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const result = await runAgent(agent, { input: "Say hello." });
|
|
33
|
+
console.log(result.output);
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Runnable version: [`../examples/01-minimal-agent.ts`](../examples/01-minimal-agent.ts).
|
|
37
|
+
|
|
38
|
+
## Import paths
|
|
39
|
+
|
|
40
|
+
Prefer the root import for stable application wiring:
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import { defineAgent, defineTool, runAgent, s } from "@infinityi/engine-lib";
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Use subpaths for domain-specific or optional surfaces:
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
import { createOpenAI } from "@infinityi/engine-lib/providers";
|
|
50
|
+
import { filesystemTools } from "@infinityi/engine-lib/tools-fs";
|
|
51
|
+
import { createSqliteSessionStore } from "@infinityi/engine-lib/session-stores";
|
|
52
|
+
import { mockProvider } from "@infinityi/engine-lib/testing";
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Optional tool packs may need optional peer dependencies from `package.json`
|
|
56
|
+
when consumed outside this repository.
|
|
57
|
+
|
|
58
|
+
## Examples and API docs
|
|
59
|
+
|
|
60
|
+
Run the offline examples:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
bun run examples
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Generate local API docs:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
bun run docs
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Then open `docs/api/index.html`.
|
|
73
|
+
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Multi-agent coordination
|
|
2
|
+
|
|
3
|
+
engine-lib supports two composition patterns without a separate orchestrator:
|
|
4
|
+
handoffs and sub-agents as tools.
|
|
5
|
+
|
|
6
|
+
## Handoffs
|
|
7
|
+
|
|
8
|
+
A handoff transfers the active run to another agent. The conversation history is
|
|
9
|
+
preserved and the final result records the trail.
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
const billing = defineAgent({ name: "billing", provider, instructions: "Handle billing." });
|
|
13
|
+
|
|
14
|
+
const triage = defineAgent({
|
|
15
|
+
name: "triage",
|
|
16
|
+
provider,
|
|
17
|
+
instructions: "Route the user.",
|
|
18
|
+
handoffs: [billing],
|
|
19
|
+
});
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Runnable version:
|
|
23
|
+
[`../examples/06-multi-agent-handoff.ts`](../examples/06-multi-agent-handoff.ts).
|
|
24
|
+
|
|
25
|
+
String-named handoff targets require a registry:
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
const registry = createAgentRegistry([billing]);
|
|
29
|
+
const triage = defineAgent({ name: "triage", provider, handoffs: ["billing"] });
|
|
30
|
+
await runAgent(triage, { input: "refund", registry });
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Use `maxHandoffs` to bound routing loops.
|
|
34
|
+
|
|
35
|
+
## Sub-agent as tool
|
|
36
|
+
|
|
37
|
+
`asTool(agent)` wraps a child agent as a normal tool. The parent model decides
|
|
38
|
+
when to call it. The child output is fed back as the tool result, child usage is
|
|
39
|
+
folded into parent usage, and child events surface as `agent.child`.
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
const researcher = defineAgent({ name: "researcher", provider });
|
|
43
|
+
const lead = defineAgent({
|
|
44
|
+
name: "lead",
|
|
45
|
+
provider,
|
|
46
|
+
tools: [asTool(researcher)],
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Runnable version:
|
|
51
|
+
[`../examples/07-sub-agent-tool.ts`](../examples/07-sub-agent-tool.ts).
|
|
52
|
+
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# Optional tool packs
|
|
2
|
+
|
|
3
|
+
The root package does not expose file, shell, HTTP, or web access. These modules
|
|
4
|
+
are opt-in subpaths and must be configured by the host application.
|
|
5
|
+
|
|
6
|
+
## Shell tools
|
|
7
|
+
|
|
8
|
+
Import:
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
import { shellTools } from "@infinityi/engine-lib/tools-shell";
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Safety controls:
|
|
15
|
+
|
|
16
|
+
- required `allowedCwds`
|
|
17
|
+
- environment allow/deny filtering
|
|
18
|
+
- command allow/deny policy
|
|
19
|
+
- optional approval hook
|
|
20
|
+
- timeout and output caps
|
|
21
|
+
- audit events for policy, approval, execution, chunks, and errors
|
|
22
|
+
|
|
23
|
+
Runnable version: [`../examples/11-shell-tools.ts`](../examples/11-shell-tools.ts).
|
|
24
|
+
|
|
25
|
+
## Filesystem tools
|
|
26
|
+
|
|
27
|
+
Import:
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import { filesystemTools } from "@infinityi/engine-lib/tools-fs";
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Capabilities:
|
|
34
|
+
|
|
35
|
+
- `repo_map`
|
|
36
|
+
- `find_files`
|
|
37
|
+
- `search_text`
|
|
38
|
+
- `search_semantic`
|
|
39
|
+
- `symbols`
|
|
40
|
+
- `read`
|
|
41
|
+
- `open_window`
|
|
42
|
+
- `edit_replace`
|
|
43
|
+
- `edit_range`
|
|
44
|
+
- `apply_patch`
|
|
45
|
+
- `write_file`
|
|
46
|
+
- `diff_status`
|
|
47
|
+
|
|
48
|
+
All paths must resolve inside configured `allowedRoots`.
|
|
49
|
+
|
|
50
|
+
Runnable version:
|
|
51
|
+
[`../examples/09-tools-filesystem.ts`](../examples/09-tools-filesystem.ts).
|
|
52
|
+
|
|
53
|
+
## HTTP tools
|
|
54
|
+
|
|
55
|
+
Import:
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
import { httpTools, createHttpToolClient } from "@infinityi/engine-lib/tools-http";
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Safety controls:
|
|
62
|
+
|
|
63
|
+
- explicit `allowedHosts` or `allowPublicInternet`
|
|
64
|
+
- denied hosts
|
|
65
|
+
- protocol allowlist
|
|
66
|
+
- private-network denial by default
|
|
67
|
+
- credentialed URL denial by default
|
|
68
|
+
- redirect target checks
|
|
69
|
+
- model-supplied header allowlist
|
|
70
|
+
- timeout, retry, response byte, and body character caps
|
|
71
|
+
|
|
72
|
+
## Web tools
|
|
73
|
+
|
|
74
|
+
Import:
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
import { webTools } from "@infinityi/engine-lib/tools-web";
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
The web pack builds on the HTTP client and adds:
|
|
81
|
+
|
|
82
|
+
- `web_search`
|
|
83
|
+
- `fetch_page`
|
|
84
|
+
- `extract_readable_text`
|
|
85
|
+
- `crawl_links`
|
|
86
|
+
|
|
87
|
+
Search requires an injected `SearchProvider`. No search vendor, browser
|
|
88
|
+
automation, JavaScript rendering, cookie jar, or authenticated session handling
|
|
89
|
+
is bundled.
|
|
90
|
+
|
|
91
|
+
Runnable HTTP and web example:
|
|
92
|
+
[`../examples/10-tools-http-web.ts`](../examples/10-tools-http-web.ts).
|
|
93
|
+
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Providers
|
|
2
|
+
|
|
3
|
+
Providers normalize LLM APIs behind one contract: `complete()` for buffered
|
|
4
|
+
turns and `stream()` for token/tool-call deltas.
|
|
5
|
+
|
|
6
|
+
Application imports:
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
import {
|
|
10
|
+
createAnthropic,
|
|
11
|
+
createGoogle,
|
|
12
|
+
createOpenAI,
|
|
13
|
+
createOpenAICompatible,
|
|
14
|
+
} from "@infinityi/engine-lib/providers";
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Root imports also expose the built-in factories.
|
|
18
|
+
|
|
19
|
+
## Built-in factories
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
const openai = createOpenAI({ apiKey: process.env.OPENAI_API_KEY!, model: "gpt-5" });
|
|
23
|
+
const anthropic = createAnthropic({ apiKey: process.env.ANTHROPIC_API_KEY!, model: "claude-opus-4-7" });
|
|
24
|
+
const google = createGoogle({ apiKey: process.env.GOOGLE_API_KEY!, model: "gemini-2.5-pro" });
|
|
25
|
+
const local = createOpenAICompatible({ baseUrl: "http://localhost:1234/v1", model: "local-model" });
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Provider API keys accept raw strings or Forge `Secret<string>` values.
|
|
29
|
+
|
|
30
|
+
Runnable real-provider example:
|
|
31
|
+
[`../examples/12-provider-openai.ts`](../examples/12-provider-openai.ts).
|
|
32
|
+
|
|
33
|
+
## Capabilities
|
|
34
|
+
|
|
35
|
+
Every provider declares:
|
|
36
|
+
|
|
37
|
+
- `tools`
|
|
38
|
+
- `streaming`
|
|
39
|
+
- `multimodalInput`
|
|
40
|
+
- `parallelToolCalls`
|
|
41
|
+
- `structuredOutput`
|
|
42
|
+
|
|
43
|
+
Treat these as adapter truth and degrade gracefully. For example, a UI can hide
|
|
44
|
+
streaming controls when `provider.capabilities.streaming` is false.
|
|
45
|
+
|
|
46
|
+
## Vendor-specific options
|
|
47
|
+
|
|
48
|
+
Use normalized request fields first: `temperature`, `topP`,
|
|
49
|
+
`maxOutputTokens`, `stopSequences`, `tools`, `toolChoice`, and
|
|
50
|
+
`responseSchema`.
|
|
51
|
+
|
|
52
|
+
Use `providerOptions` only for vendor-specific request body fields that are not
|
|
53
|
+
first-classed yet.
|
|
54
|
+
|
|
55
|
+
## Custom adapters
|
|
56
|
+
|
|
57
|
+
Advanced imports from `@infinityi/engine-lib/providers` include:
|
|
58
|
+
|
|
59
|
+
- `createProvider`
|
|
60
|
+
- `createProviderHttp`
|
|
61
|
+
- `parseSse`
|
|
62
|
+
- `StreamAccumulator`
|
|
63
|
+
- `collectStream`
|
|
64
|
+
- `AdapterSpec`
|
|
65
|
+
|
|
66
|
+
Adapter authors should also wire the conformance battery from
|
|
67
|
+
`@infinityi/engine-lib/testing/conformance`.
|
|
68
|
+
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# Retrieval
|
|
2
|
+
|
|
3
|
+
`@infinityi/engine-lib/retrieval` is an opt-in module for host-owned RAG
|
|
4
|
+
pipelines. It provides contracts and small local implementations, then adapts
|
|
5
|
+
retrievers back into the existing `ContextProvider` flow.
|
|
6
|
+
|
|
7
|
+
The module does not provide a hosted retrieval service, managed vector database,
|
|
8
|
+
or vendor embedding client. Applications supply those pieces behind the exported
|
|
9
|
+
interfaces.
|
|
10
|
+
|
|
11
|
+
## Index Documents
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import {
|
|
15
|
+
InMemoryVectorStore,
|
|
16
|
+
createTextChunker,
|
|
17
|
+
indexDocuments,
|
|
18
|
+
staticDocumentLoader,
|
|
19
|
+
type EmbeddingProvider,
|
|
20
|
+
} from "@infinityi/engine-lib/retrieval";
|
|
21
|
+
|
|
22
|
+
const embeddings: EmbeddingProvider = {
|
|
23
|
+
name: "toy",
|
|
24
|
+
defaultModel: "toy-embedding",
|
|
25
|
+
dimensions: 3,
|
|
26
|
+
async embed(req) {
|
|
27
|
+
return {
|
|
28
|
+
model: req.model ?? "toy-embedding",
|
|
29
|
+
vectors: req.input.map((text) => [text.length, text.includes("database") ? 1 : 0, 1]),
|
|
30
|
+
dimensions: 3,
|
|
31
|
+
};
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const store = new InMemoryVectorStore({ dimensions: 3 });
|
|
36
|
+
|
|
37
|
+
await indexDocuments({
|
|
38
|
+
loaders: [
|
|
39
|
+
staticDocumentLoader([
|
|
40
|
+
{
|
|
41
|
+
id: "runbook",
|
|
42
|
+
content: "If the database is unavailable, fail over to the standby.",
|
|
43
|
+
source: { uri: "runbooks/database.md", title: "Database Runbook" },
|
|
44
|
+
},
|
|
45
|
+
]),
|
|
46
|
+
],
|
|
47
|
+
chunker: createTextChunker({ maxChars: 1_000, overlapChars: 100 }),
|
|
48
|
+
embeddings,
|
|
49
|
+
store,
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
`InMemoryVectorStore` computes similarity by scanning every stored record. It is
|
|
54
|
+
intended for tests, examples, and small local corpora; production-scale or
|
|
55
|
+
latency-sensitive systems should implement `VectorStore` with a dedicated vector
|
|
56
|
+
database or search service.
|
|
57
|
+
|
|
58
|
+
## Inject Retrieved Context
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
import {
|
|
62
|
+
createVectorRetriever,
|
|
63
|
+
retrieverContext,
|
|
64
|
+
} from "@infinityi/engine-lib/retrieval";
|
|
65
|
+
|
|
66
|
+
const retriever = createVectorRetriever({ embeddings, store, topK: 4 });
|
|
67
|
+
|
|
68
|
+
await runAgent(agent, {
|
|
69
|
+
input: "How do I recover the database?",
|
|
70
|
+
context: [retrieverContext({ retriever, maxContextTokens: 1_500 })],
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
`retrieverContext` derives the query from the current run input by default,
|
|
75
|
+
renders citations such as `[1] Database Runbook, lines 1-3`, and returns no
|
|
76
|
+
context when there is no query or no retrieval hit.
|
|
77
|
+
|
|
78
|
+
## Hybrid Retrieval
|
|
79
|
+
|
|
80
|
+
Pass a `KeywordRetriever` hook to `createVectorRetriever` when a host wants to
|
|
81
|
+
combine lexical and vector search. `mergeHybridResults` normalizes the vector and
|
|
82
|
+
keyword score channels independently, de-duplicates by id, applies weights, and
|
|
83
|
+
returns ranked `RetrievalResult`s.
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# Sessions and context
|
|
2
|
+
|
|
3
|
+
Sessions store durable conversation history. Context providers inject
|
|
4
|
+
request-time information without persisting it.
|
|
5
|
+
|
|
6
|
+
Application imports:
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
import {
|
|
10
|
+
createSession,
|
|
11
|
+
dynamicContext,
|
|
12
|
+
staticContext,
|
|
13
|
+
truncateOldest,
|
|
14
|
+
} from "@infinityi/engine-lib";
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Runnable version:
|
|
18
|
+
[`../examples/04-sessions-context.ts`](../examples/04-sessions-context.ts).
|
|
19
|
+
|
|
20
|
+
## Sessions
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
const session = createSession({ id: "user-123" });
|
|
24
|
+
|
|
25
|
+
await runAgent(agent, { input: "first", session });
|
|
26
|
+
await runAgent(agent, { input: "second", session });
|
|
27
|
+
|
|
28
|
+
const history = await session.messages();
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Successful runs append only conversation messages:
|
|
32
|
+
|
|
33
|
+
- user input
|
|
34
|
+
- assistant turns
|
|
35
|
+
- tool-result messages
|
|
36
|
+
|
|
37
|
+
Instructions and injected context are rebuilt for each request and are not
|
|
38
|
+
persisted.
|
|
39
|
+
|
|
40
|
+
## Durable stores
|
|
41
|
+
|
|
42
|
+
Durable stores live on `@infinityi/engine-lib/session-stores`:
|
|
43
|
+
|
|
44
|
+
- `createSqliteSessionStore`
|
|
45
|
+
- `createPostgresSessionStore`
|
|
46
|
+
- `RedisSessionStore`
|
|
47
|
+
- `FilesystemJsonlSessionStore`
|
|
48
|
+
- `ForgeDataSessionStore`
|
|
49
|
+
|
|
50
|
+
Stores expose `migrate()` when they own schema setup and `close()` when they own
|
|
51
|
+
resources. Use `SessionStoreCodec` to add encryption at rest.
|
|
52
|
+
|
|
53
|
+
## Context
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
await runAgent(agent, {
|
|
57
|
+
input: "answer with account facts",
|
|
58
|
+
context: [
|
|
59
|
+
staticContext({ plan: "enterprise" }, "Account"),
|
|
60
|
+
dynamicContext("clock", () => new Date().toISOString()),
|
|
61
|
+
],
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Context providers resolve once per run before the first provider call.
|
|
66
|
+
|
|
67
|
+
## Context windows
|
|
68
|
+
|
|
69
|
+
Use `contextWindow` to trim the provider request view without mutating the
|
|
70
|
+
canonical session history:
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
await runAgent(agent, {
|
|
74
|
+
input: "newest",
|
|
75
|
+
messages: priorMessages,
|
|
76
|
+
contextWindow: {
|
|
77
|
+
maxTokens: 8_000,
|
|
78
|
+
strategy: truncateOldest(),
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Testing and lifecycle
|
|
2
|
+
|
|
3
|
+
## Testing helpers
|
|
4
|
+
|
|
5
|
+
Import:
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import {
|
|
9
|
+
mockProvider,
|
|
10
|
+
scriptedProvider,
|
|
11
|
+
textResult,
|
|
12
|
+
toolCallResult,
|
|
13
|
+
} from "@infinityi/engine-lib/testing";
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Use `mockProvider` for simple one-turn tests and request inspection. Use
|
|
17
|
+
`scriptedProvider` for multi-turn tests such as tool call followed by final
|
|
18
|
+
answer.
|
|
19
|
+
|
|
20
|
+
Runnable version:
|
|
21
|
+
[`../examples/08-testing-agent.ts`](../examples/08-testing-agent.ts).
|
|
22
|
+
|
|
23
|
+
Other helpers:
|
|
24
|
+
|
|
25
|
+
- `conversation`
|
|
26
|
+
- `collectProviderStream`
|
|
27
|
+
- `expectValid`
|
|
28
|
+
- `jsonFetch`
|
|
29
|
+
- `sseFetch`
|
|
30
|
+
- `inMemorySessionStore`
|
|
31
|
+
|
|
32
|
+
## Provider conformance
|
|
33
|
+
|
|
34
|
+
Adapter authors should use:
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { runProviderConformance } from "@infinityi/engine-lib/testing/conformance";
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The battery checks buffered completion, streaming, tool calling, usage,
|
|
41
|
+
capability honesty, and error mapping through fake transports.
|
|
42
|
+
|
|
43
|
+
## Lifecycle
|
|
44
|
+
|
|
45
|
+
Import:
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { agentRuntimeComponent } from "@infinityi/engine-lib/lifecycle";
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
`agentRuntimeComponent` adapts providers and optional session stores to a Forge
|
|
52
|
+
lifecycle component:
|
|
53
|
+
|
|
54
|
+
- `start()` validates provider names and default models
|
|
55
|
+
- `probeOnStart` can fail boot when providers are unhealthy
|
|
56
|
+
- `healthcheck()` maps provider probes to Forge health results
|
|
57
|
+
- `stop()` runs a host shutdown hook, such as closing a durable store
|
|
58
|
+
|
|
59
|
+
Runnable version: [`../examples/13-lifecycle.ts`](../examples/13-lifecycle.ts).
|
|
60
|
+
|
package/docs/tools.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Tools and schemas
|
|
2
|
+
|
|
3
|
+
Tools are named capabilities the model may call. Schemas validate model-supplied
|
|
4
|
+
arguments before execution.
|
|
5
|
+
|
|
6
|
+
Application imports:
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
import { defineTool, s } from "@infinityi/engine-lib";
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Define a tool
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
const lookupService = defineTool({
|
|
16
|
+
name: "lookup_service",
|
|
17
|
+
description: "Return status for an internal service.",
|
|
18
|
+
parameters: s.object({
|
|
19
|
+
service: s.enum(["api", "worker", "billing"]),
|
|
20
|
+
}),
|
|
21
|
+
execute: ({ service }) => ({
|
|
22
|
+
ok: true,
|
|
23
|
+
content: { service, status: "healthy" },
|
|
24
|
+
}),
|
|
25
|
+
});
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Runnable version: [`../examples/02-custom-tool.ts`](../examples/02-custom-tool.ts).
|
|
29
|
+
|
|
30
|
+
## Schema builder
|
|
31
|
+
|
|
32
|
+
The `s` builder covers the JSON-Schema subset needed for provider tool
|
|
33
|
+
parameters and structured outputs:
|
|
34
|
+
|
|
35
|
+
- `s.string()`
|
|
36
|
+
- `s.number()`
|
|
37
|
+
- `s.boolean()`
|
|
38
|
+
- `s.enum([...])`
|
|
39
|
+
- `s.array(item)`
|
|
40
|
+
- `s.object(shape)`
|
|
41
|
+
- `s.optional(inner)`
|
|
42
|
+
|
|
43
|
+
Objects are strict by default and reject unknown properties. Optional object
|
|
44
|
+
fields are derived from `s.optional(...)`.
|
|
45
|
+
|
|
46
|
+
Use `asSchema()` or `fromJsonSchema()` when adapting an external schema library
|
|
47
|
+
or raw JSON Schema.
|
|
48
|
+
|
|
49
|
+
## Tool results
|
|
50
|
+
|
|
51
|
+
Return success for expected output:
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
return { ok: true, content: data };
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Return failure for domain errors the model can recover from:
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
return { ok: false, error: "file not found" };
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Throw only for unexpected implementation faults. `runAgent` catches thrown tool
|
|
64
|
+
errors and feeds them back as tool-result errors instead of crashing the entire
|
|
65
|
+
run.
|
|
66
|
+
|
|
67
|
+
Example test pattern:
|
|
68
|
+
[`../examples/08-testing-agent.ts`](../examples/08-testing-agent.ts).
|
|
69
|
+
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { defineAgent, runAgent } from "@infinityi/engine-lib";
|
|
2
|
+
import { mockProvider, textResult } from "@infinityi/engine-lib/testing";
|
|
3
|
+
|
|
4
|
+
const agent = defineAgent({
|
|
5
|
+
name: "assistant",
|
|
6
|
+
provider: mockProvider({
|
|
7
|
+
result: () => textResult("Hello from a local mock provider."),
|
|
8
|
+
}),
|
|
9
|
+
instructions: "Answer briefly.",
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
const result = await runAgent(agent, { input: "Say hello." });
|
|
13
|
+
|
|
14
|
+
console.log({
|
|
15
|
+
output: result.output,
|
|
16
|
+
steps: result.steps,
|
|
17
|
+
finishReason: result.finishReason,
|
|
18
|
+
});
|
|
19
|
+
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { defineAgent, defineTool, runAgent, s } from "@infinityi/engine-lib";
|
|
2
|
+
import { scriptedProvider, textResult, toolCallResult } from "@infinityi/engine-lib/testing";
|
|
3
|
+
|
|
4
|
+
const lookupService = defineTool({
|
|
5
|
+
name: "lookup_service",
|
|
6
|
+
description: "Return status for an internal service.",
|
|
7
|
+
parameters: s.object({
|
|
8
|
+
service: s.enum(["api", "worker", "billing"]),
|
|
9
|
+
}),
|
|
10
|
+
execute: ({ service }) => ({
|
|
11
|
+
ok: true,
|
|
12
|
+
content: {
|
|
13
|
+
service,
|
|
14
|
+
status: service === "billing" ? "degraded" : "healthy",
|
|
15
|
+
since: "2026-06-11T12:00:00Z",
|
|
16
|
+
},
|
|
17
|
+
}),
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const agent = defineAgent({
|
|
21
|
+
name: "status",
|
|
22
|
+
tools: [lookupService],
|
|
23
|
+
provider: scriptedProvider([
|
|
24
|
+
toolCallResult([{ id: "call-1", name: "lookup_service", arguments: { service: "billing" } }]),
|
|
25
|
+
textResult("Billing is degraded and has been since 2026-06-11T12:00:00Z."),
|
|
26
|
+
]),
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const result = await runAgent(agent, { input: "Check billing." });
|
|
30
|
+
|
|
31
|
+
console.log(result.output);
|
|
32
|
+
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { defineAgent, defineTool, runAgent, s } from "@infinityi/engine-lib";
|
|
2
|
+
import type { RunEvent } from "@infinityi/engine-lib/execution";
|
|
3
|
+
import { scriptedProvider, textResult, toolCallResult } from "@infinityi/engine-lib/testing";
|
|
4
|
+
|
|
5
|
+
const echo = defineTool({
|
|
6
|
+
name: "echo",
|
|
7
|
+
parameters: s.object({ value: s.string() }),
|
|
8
|
+
execute: ({ value }) => ({ ok: true, content: value }),
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
const agent = defineAgent({
|
|
12
|
+
name: "streamer",
|
|
13
|
+
tools: [echo],
|
|
14
|
+
provider: scriptedProvider([
|
|
15
|
+
toolCallResult([{ id: "echo-1", name: "echo", arguments: { value: "checked" } }]),
|
|
16
|
+
textResult("Streaming run completed."),
|
|
17
|
+
]),
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const events: string[] = [];
|
|
21
|
+
const handle = runAgent(agent, { input: "Run with events.", stream: true });
|
|
22
|
+
|
|
23
|
+
for await (const event of handle) {
|
|
24
|
+
events.push(describeEvent(event));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const result = await handle.completed;
|
|
28
|
+
|
|
29
|
+
console.log({
|
|
30
|
+
events,
|
|
31
|
+
output: result.output,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
function describeEvent(event: RunEvent): string {
|
|
35
|
+
switch (event.type) {
|
|
36
|
+
case "token":
|
|
37
|
+
return `token:${event.delta}`;
|
|
38
|
+
case "tool.call":
|
|
39
|
+
return `tool.call:${event.name}`;
|
|
40
|
+
case "tool.result":
|
|
41
|
+
return `tool.result:${event.name}:${event.result.ok ? "ok" : "error"}`;
|
|
42
|
+
default:
|
|
43
|
+
return event.type;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|