@infinityi/engine-lib 1.3.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +52 -0
- package/package.json +78 -4
- package/dist/index-02s1fjxr.js +0 -226
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createSession,
|
|
3
|
+
defineAgent,
|
|
4
|
+
dynamicContext,
|
|
5
|
+
runAgent,
|
|
6
|
+
staticContext,
|
|
7
|
+
} from "@infinityi/engine-lib";
|
|
8
|
+
import { scriptedProvider, textResult } from "@infinityi/engine-lib/testing";
|
|
9
|
+
|
|
10
|
+
const session = createSession({ id: "example-user-1" });
|
|
11
|
+
const agent = defineAgent({
|
|
12
|
+
name: "assistant",
|
|
13
|
+
instructions: "Use injected context, but do not assume it is persistent.",
|
|
14
|
+
provider: scriptedProvider([
|
|
15
|
+
textResult("First turn recorded."),
|
|
16
|
+
textResult("Second turn used prior session history."),
|
|
17
|
+
]),
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
await runAgent(agent, {
|
|
21
|
+
input: "Remember this conversation.",
|
|
22
|
+
session,
|
|
23
|
+
context: [
|
|
24
|
+
staticContext("Plan: enterprise", "Account"),
|
|
25
|
+
dynamicContext("clock", () => "Today is 2026-06-11."),
|
|
26
|
+
],
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const second = await runAgent(agent, {
|
|
30
|
+
input: "What happened before?",
|
|
31
|
+
session,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const persisted = await session.messages();
|
|
35
|
+
|
|
36
|
+
console.log({
|
|
37
|
+
secondOutput: second.output,
|
|
38
|
+
persistedRoles: persisted.map((message) => message.role),
|
|
39
|
+
});
|
|
40
|
+
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { defineAgent, runAgent } from "@infinityi/engine-lib";
|
|
2
|
+
import type { RunSubscriber } from "@infinityi/engine-lib/events";
|
|
3
|
+
import { scriptedProvider, textResult } from "@infinityi/engine-lib/testing";
|
|
4
|
+
|
|
5
|
+
const auditLog: string[] = [];
|
|
6
|
+
const afterFailingSink: string[] = [];
|
|
7
|
+
|
|
8
|
+
const auditSubscriber: RunSubscriber = async (event) => {
|
|
9
|
+
auditLog.push(event.type);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const failingSubscriber: RunSubscriber = async () => {
|
|
13
|
+
throw new Error("audit sink is unavailable");
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const stillRunsSubscriber: RunSubscriber = async (event) => {
|
|
17
|
+
afterFailingSink.push(event.type);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const agent = defineAgent({
|
|
21
|
+
name: "observable",
|
|
22
|
+
provider: scriptedProvider([textResult("done")]),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const result = await runAgent(agent, {
|
|
26
|
+
input: "Emit events.",
|
|
27
|
+
subscribers: [auditSubscriber, failingSubscriber, stillRunsSubscriber],
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
console.log({
|
|
31
|
+
output: result.output,
|
|
32
|
+
auditLog,
|
|
33
|
+
afterFailingSink,
|
|
34
|
+
});
|
|
35
|
+
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { defineAgent, runAgent } from "@infinityi/engine-lib";
|
|
2
|
+
import { handoffToolName } from "@infinityi/engine-lib/agent";
|
|
3
|
+
import { scriptedProvider, textResult, toolCallResult } from "@infinityi/engine-lib/testing";
|
|
4
|
+
|
|
5
|
+
const billing = defineAgent({
|
|
6
|
+
name: "billing",
|
|
7
|
+
instructions: "Handle billing questions.",
|
|
8
|
+
provider: scriptedProvider([textResult("Refund issued by billing.")]),
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
const triage = defineAgent({
|
|
12
|
+
name: "triage",
|
|
13
|
+
instructions: "Route to the right specialist.",
|
|
14
|
+
handoffs: [billing],
|
|
15
|
+
provider: scriptedProvider([
|
|
16
|
+
toolCallResult([{ id: "handoff-1", name: handoffToolName("billing"), arguments: {} }]),
|
|
17
|
+
]),
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const result = await runAgent(triage, { input: "I need a refund." });
|
|
21
|
+
|
|
22
|
+
console.log({
|
|
23
|
+
output: result.output,
|
|
24
|
+
finalAgent: result.agent,
|
|
25
|
+
handoffs: result.handoffs,
|
|
26
|
+
});
|
|
27
|
+
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { asTool, defineAgent, runAgent } from "@infinityi/engine-lib";
|
|
2
|
+
import { scriptedProvider, textResult, toolCallResult } from "@infinityi/engine-lib/testing";
|
|
3
|
+
|
|
4
|
+
const researcher = defineAgent({
|
|
5
|
+
name: "researcher",
|
|
6
|
+
instructions: "Research the request and return concise findings.",
|
|
7
|
+
provider: scriptedProvider([textResult("Database latency increased after deploy 42.")]),
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
const lead = defineAgent({
|
|
11
|
+
name: "lead",
|
|
12
|
+
instructions: "Delegate research when useful, then answer.",
|
|
13
|
+
tools: [asTool(researcher)],
|
|
14
|
+
provider: scriptedProvider([
|
|
15
|
+
toolCallResult([{ id: "research-1", name: "researcher", arguments: { input: "latency" } }]),
|
|
16
|
+
textResult("Likely cause: deploy 42 increased database latency."),
|
|
17
|
+
]),
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const result = await runAgent(lead, { input: "Why did latency spike?" });
|
|
21
|
+
|
|
22
|
+
console.log({
|
|
23
|
+
output: result.output,
|
|
24
|
+
totalTokens: result.usage.totalTokens,
|
|
25
|
+
});
|
|
26
|
+
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { defineAgent, defineTool, runAgent, s } from "@infinityi/engine-lib";
|
|
2
|
+
import { scriptedProvider, textResult, toolCallResult } from "@infinityi/engine-lib/testing";
|
|
3
|
+
|
|
4
|
+
const double = defineTool({
|
|
5
|
+
name: "double",
|
|
6
|
+
parameters: s.object({ value: s.number({ int: true }) }),
|
|
7
|
+
execute: ({ value }) => ({ ok: true, content: value * 2 }),
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
const agent = defineAgent({
|
|
11
|
+
name: "testable",
|
|
12
|
+
tools: [double],
|
|
13
|
+
provider: scriptedProvider([
|
|
14
|
+
toolCallResult([{ id: "double-1", name: "double", arguments: { value: 21 } }]),
|
|
15
|
+
textResult("The answer is 42."),
|
|
16
|
+
]),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const result = await runAgent(agent, { input: "Double 21." });
|
|
20
|
+
|
|
21
|
+
if (result.output !== "The answer is 42.") {
|
|
22
|
+
throw new Error(`unexpected output: ${result.output}`);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const usedTool = result.messages.some((message) => message.role === "tool");
|
|
26
|
+
if (!usedTool) {
|
|
27
|
+
throw new Error("expected the agent to use the double tool");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
console.log("agent test passed");
|
|
31
|
+
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { mkdtemp, realpath, rm, writeFile } from "node:fs/promises";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
|
|
5
|
+
import type { ToolContext, ToolDefinition, ToolResult } from "@infinityi/engine-lib/tools";
|
|
6
|
+
import { filesystemTools } from "@infinityi/engine-lib/tools-fs";
|
|
7
|
+
|
|
8
|
+
const root = await realpath(await mkdtemp(join(tmpdir(), "engine-lib-example-fs-")));
|
|
9
|
+
const ctx: ToolContext = { toolCallId: "example-fs", agentName: "example" };
|
|
10
|
+
|
|
11
|
+
try {
|
|
12
|
+
await writeFile(join(root, "service.ts"), [
|
|
13
|
+
"export function status() {",
|
|
14
|
+
" return 'degraded';",
|
|
15
|
+
"}",
|
|
16
|
+
].join("\n"));
|
|
17
|
+
|
|
18
|
+
const fs = filesystemTools({ allowedRoots: [root] });
|
|
19
|
+
|
|
20
|
+
const map = await runTool(fs.repoMap, { include_symbols: true });
|
|
21
|
+
const search = await runTool(fs.searchText, { pattern: "degraded", mode: "literal" });
|
|
22
|
+
const read = await runTool(fs.read, { path: "service.ts", include_line_numbers: true });
|
|
23
|
+
const diff = await runTool(fs.diffStatus, {});
|
|
24
|
+
|
|
25
|
+
console.log({
|
|
26
|
+
root,
|
|
27
|
+
mapped: ok(map),
|
|
28
|
+
searched: ok(search),
|
|
29
|
+
read: ok(read),
|
|
30
|
+
diff: ok(diff),
|
|
31
|
+
});
|
|
32
|
+
} finally {
|
|
33
|
+
await rm(root, { recursive: true, force: true });
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async function runTool<TArgs>(
|
|
37
|
+
tool: ToolDefinition<TArgs>,
|
|
38
|
+
args: TArgs,
|
|
39
|
+
): Promise<ToolResult> {
|
|
40
|
+
return tool.execute(args, ctx);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function ok(result: ToolResult): boolean {
|
|
44
|
+
if (!result.ok) {
|
|
45
|
+
throw new Error(result.error);
|
|
46
|
+
}
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { ToolContext, ToolDefinition, ToolResult } from "@infinityi/engine-lib/tools";
|
|
2
|
+
import { httpTools } from "@infinityi/engine-lib/tools-http";
|
|
3
|
+
import { webTools, type SearchProvider } from "@infinityi/engine-lib/tools-web";
|
|
4
|
+
|
|
5
|
+
const html = [
|
|
6
|
+
"<html>",
|
|
7
|
+
"<head><title>Status</title></head>",
|
|
8
|
+
"<body>",
|
|
9
|
+
"<main><h1>Status</h1><p>All public systems are operational.</p></main>",
|
|
10
|
+
"<a href=\"/docs\">Docs</a>",
|
|
11
|
+
"</body>",
|
|
12
|
+
"</html>",
|
|
13
|
+
].join("");
|
|
14
|
+
|
|
15
|
+
const fakeFetch = (async (input: Parameters<typeof fetch>[0]) => {
|
|
16
|
+
const url = String(input);
|
|
17
|
+
if (url.endsWith("/robots.txt")) {
|
|
18
|
+
return new Response("User-agent: *\nAllow: /\n", {
|
|
19
|
+
headers: { "content-type": "text/plain" },
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
if (url.endsWith("/status")) {
|
|
23
|
+
return new Response(html, {
|
|
24
|
+
headers: { "content-type": "text/html" },
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return new Response(JSON.stringify({ ok: true }), {
|
|
28
|
+
headers: { "content-type": "application/json" },
|
|
29
|
+
});
|
|
30
|
+
}) as typeof fetch;
|
|
31
|
+
|
|
32
|
+
const searchProvider: SearchProvider = {
|
|
33
|
+
search: ({ query, maxResults }) => [
|
|
34
|
+
{
|
|
35
|
+
url: "https://example.com/status",
|
|
36
|
+
title: `Result for ${query}`,
|
|
37
|
+
snippet: `Returning ${maxResults} result(s).`,
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const ctx: ToolContext = { toolCallId: "example-web", agentName: "example" };
|
|
43
|
+
const http = httpTools({ allowedHosts: ["example.com"], fetch: fakeFetch });
|
|
44
|
+
const web = webTools({
|
|
45
|
+
allowedHosts: ["example.com"],
|
|
46
|
+
fetch: fakeFetch,
|
|
47
|
+
searchProvider,
|
|
48
|
+
robots: "enforce",
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const httpResult = await runTool(http.httpGet, { url: "https://example.com/api" });
|
|
52
|
+
const searchResult = await runTool(web.webSearch, { query: "status", max_results: 1 });
|
|
53
|
+
const pageResult = await runTool(web.fetchPage, { url: "https://example.com/status" });
|
|
54
|
+
|
|
55
|
+
console.log({
|
|
56
|
+
http: content(httpResult),
|
|
57
|
+
search: content(searchResult),
|
|
58
|
+
page: content(pageResult),
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
async function runTool<TArgs>(
|
|
62
|
+
tool: ToolDefinition<TArgs>,
|
|
63
|
+
args: TArgs,
|
|
64
|
+
): Promise<ToolResult> {
|
|
65
|
+
return tool.execute(args, ctx);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function content(result: ToolResult): unknown {
|
|
69
|
+
if (!result.ok) {
|
|
70
|
+
throw new Error(result.error);
|
|
71
|
+
}
|
|
72
|
+
return result.content;
|
|
73
|
+
}
|
|
74
|
+
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ToolContext, ToolDefinition, ToolResult } from "@infinityi/engine-lib/tools";
|
|
2
|
+
import { shellTools } from "@infinityi/engine-lib/tools-shell";
|
|
3
|
+
|
|
4
|
+
const cwd = process.cwd();
|
|
5
|
+
const shell = shellTools({
|
|
6
|
+
allowedCwds: [cwd],
|
|
7
|
+
policy: {
|
|
8
|
+
allow: [process.execPath],
|
|
9
|
+
deny: [/\brm\b/, /\bsudo\b/],
|
|
10
|
+
},
|
|
11
|
+
env: { allow: ["PATH"] },
|
|
12
|
+
requiresApproval: (request) => request.command !== process.execPath,
|
|
13
|
+
approve: () => ({ approved: false, reason: "example denies unrecognized commands" }),
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const result = await runTool(shell.runCommand, {
|
|
17
|
+
command: process.execPath,
|
|
18
|
+
args: ["-e", "console.log('hello from shell tool')"],
|
|
19
|
+
cwd,
|
|
20
|
+
timeoutMs: 5_000,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
console.log(content(result));
|
|
24
|
+
|
|
25
|
+
async function runTool<TArgs>(
|
|
26
|
+
tool: ToolDefinition<TArgs>,
|
|
27
|
+
args: TArgs,
|
|
28
|
+
): Promise<ToolResult> {
|
|
29
|
+
const ctx: ToolContext = { toolCallId: "example-shell", agentName: "example" };
|
|
30
|
+
return tool.execute(args, ctx);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function content(result: ToolResult): unknown {
|
|
34
|
+
if (!result.ok) {
|
|
35
|
+
throw new Error(result.error);
|
|
36
|
+
}
|
|
37
|
+
return result.content;
|
|
38
|
+
}
|
|
39
|
+
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createOpenAI, defineAgent, runAgent } from "@infinityi/engine-lib";
|
|
2
|
+
|
|
3
|
+
const apiKey = process.env.OPENAI_API_KEY;
|
|
4
|
+
|
|
5
|
+
if (apiKey === undefined || apiKey === "") {
|
|
6
|
+
console.log("Set OPENAI_API_KEY to run the real OpenAI provider example.");
|
|
7
|
+
process.exit(0);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const provider = createOpenAI({
|
|
11
|
+
apiKey,
|
|
12
|
+
model: process.env.OPENAI_MODEL ?? "gpt-5",
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
const agent = defineAgent({
|
|
16
|
+
name: "openai-example",
|
|
17
|
+
provider,
|
|
18
|
+
instructions: "Answer in one sentence.",
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const result = await runAgent(agent, { input: "What is engine-lib?" });
|
|
22
|
+
|
|
23
|
+
console.log(result.output);
|
|
24
|
+
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { agentRuntimeComponent } from "@infinityi/engine-lib/lifecycle";
|
|
2
|
+
import { mockProvider } from "@infinityi/engine-lib/testing";
|
|
3
|
+
|
|
4
|
+
const provider = mockProvider({ name: "mock-provider", defaultModel: "mock-model" });
|
|
5
|
+
const component = agentRuntimeComponent({
|
|
6
|
+
providers: [provider],
|
|
7
|
+
probeOnStart: true,
|
|
8
|
+
probe: async (candidate) => {
|
|
9
|
+
await candidate.complete({ messages: [] });
|
|
10
|
+
},
|
|
11
|
+
onStop: () => {
|
|
12
|
+
console.log("runtime stopped");
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const signal = new AbortController().signal;
|
|
17
|
+
const logger = {
|
|
18
|
+
trace: console.debug,
|
|
19
|
+
debug: console.debug,
|
|
20
|
+
info: console.log,
|
|
21
|
+
warn: console.warn,
|
|
22
|
+
error: console.error,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
if (component.start !== undefined) {
|
|
26
|
+
await component.start({ signal, logger } as Parameters<typeof component.start>[0]);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (component.healthcheck !== undefined) {
|
|
30
|
+
const health = await component.healthcheck({ signal, logger } as Parameters<typeof component.healthcheck>[0]);
|
|
31
|
+
console.log(health);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (component.stop !== undefined) {
|
|
35
|
+
await component.stop({ signal, logger } as Parameters<typeof component.stop>[0]);
|
|
36
|
+
}
|
|
37
|
+
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { defineAgent, runAgent } from "@infinityi/engine-lib";
|
|
2
|
+
import {
|
|
3
|
+
InMemoryVectorStore,
|
|
4
|
+
createTextChunker,
|
|
5
|
+
createVectorRetriever,
|
|
6
|
+
indexDocuments,
|
|
7
|
+
retrieverContext,
|
|
8
|
+
staticDocumentLoader,
|
|
9
|
+
type EmbeddingProvider,
|
|
10
|
+
} from "@infinityi/engine-lib/retrieval";
|
|
11
|
+
import { scriptedProvider, textResult } from "@infinityi/engine-lib/testing";
|
|
12
|
+
|
|
13
|
+
const embeddings: EmbeddingProvider = {
|
|
14
|
+
name: "toy-embeddings",
|
|
15
|
+
defaultModel: "toy-embedding",
|
|
16
|
+
dimensions: 4,
|
|
17
|
+
async embed(req) {
|
|
18
|
+
return {
|
|
19
|
+
model: req.model ?? "toy-embedding",
|
|
20
|
+
dimensions: 4,
|
|
21
|
+
vectors: req.input.map((text) => [
|
|
22
|
+
text.toLowerCase().includes("database") ? 1 : 0,
|
|
23
|
+
text.toLowerCase().includes("standby") ? 1 : 0,
|
|
24
|
+
text.toLowerCase().includes("cache") ? 1 : 0,
|
|
25
|
+
Math.min(text.length / 100, 1),
|
|
26
|
+
]),
|
|
27
|
+
};
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const store = new InMemoryVectorStore({ dimensions: 4 });
|
|
32
|
+
|
|
33
|
+
await indexDocuments({
|
|
34
|
+
loaders: [
|
|
35
|
+
staticDocumentLoader([
|
|
36
|
+
{
|
|
37
|
+
id: "database-runbook",
|
|
38
|
+
content: "When the database is unavailable, fail over to the standby and verify replication lag.",
|
|
39
|
+
source: { uri: "runbooks/database.md", title: "Database Runbook" },
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
id: "cache-runbook",
|
|
43
|
+
content: "When the cache is saturated, scale the cache tier before restarting workers.",
|
|
44
|
+
source: { uri: "runbooks/cache.md", title: "Cache Runbook" },
|
|
45
|
+
},
|
|
46
|
+
]),
|
|
47
|
+
],
|
|
48
|
+
chunker: createTextChunker({ maxChars: 120, overlapChars: 20 }),
|
|
49
|
+
embeddings,
|
|
50
|
+
store,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const retriever = createVectorRetriever({ embeddings, store, topK: 2 });
|
|
54
|
+
const agent = defineAgent({
|
|
55
|
+
name: "retrieval-demo",
|
|
56
|
+
instructions: "Answer from retrieved context and cite sources by marker.",
|
|
57
|
+
provider: scriptedProvider([textResult("Fail over to standby and verify replication lag. [1]")]),
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const result = await runAgent(agent, {
|
|
61
|
+
input: "How should I recover a database outage?",
|
|
62
|
+
context: [retrieverContext({ retriever, maxContextTokens: 500 })],
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
console.log(result.output);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createSession,
|
|
3
|
+
defineAgent,
|
|
4
|
+
defineTool,
|
|
5
|
+
runAgent,
|
|
6
|
+
s,
|
|
7
|
+
staticContext,
|
|
8
|
+
} from "@infinityi/engine-lib";
|
|
9
|
+
import { scriptedProvider, textResult, toolCallResult } from "@infinityi/engine-lib/testing";
|
|
10
|
+
|
|
11
|
+
const serviceStatus = defineTool({
|
|
12
|
+
name: "service_status",
|
|
13
|
+
description: "Read current status for a production service.",
|
|
14
|
+
parameters: s.object({
|
|
15
|
+
service: s.enum(["api", "worker", "billing"]),
|
|
16
|
+
}),
|
|
17
|
+
execute: ({ service }) => ({
|
|
18
|
+
ok: true,
|
|
19
|
+
content: {
|
|
20
|
+
service,
|
|
21
|
+
status: "degraded",
|
|
22
|
+
signals: ["p95 latency above SLO", "error rate normal", "recent deploy: 42"],
|
|
23
|
+
},
|
|
24
|
+
}),
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const incidentAgent = defineAgent({
|
|
28
|
+
name: "incident-analyst",
|
|
29
|
+
instructions: "Analyze incidents with evidence. Keep the final answer actionable.",
|
|
30
|
+
tools: [serviceStatus],
|
|
31
|
+
provider: scriptedProvider([
|
|
32
|
+
toolCallResult([{ id: "status-1", name: "service_status", arguments: { service: "api" } }]),
|
|
33
|
+
textResult("API latency is degraded. The leading suspect is deploy 42; roll back or inspect its database path."),
|
|
34
|
+
]),
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const session = createSession({ id: "incident-2026-06-11" });
|
|
38
|
+
const events: string[] = [];
|
|
39
|
+
|
|
40
|
+
const result = await runAgent(incidentAgent, {
|
|
41
|
+
input: "Why is the API slow?",
|
|
42
|
+
session,
|
|
43
|
+
context: [staticContext({ region: "us-east-1", severity: "sev2" }, "Incident")],
|
|
44
|
+
onEvent: (event) => events.push(event.type),
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
console.log({
|
|
48
|
+
output: result.output,
|
|
49
|
+
events,
|
|
50
|
+
persistedMessages: (await session.messages()).map((message) => message.role),
|
|
51
|
+
});
|
|
52
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@infinityi/engine-lib",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Agent infrastructure for TypeScript, built on @infinityi/forge.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"types": "./dist/index.d.ts",
|
|
29
29
|
"files": [
|
|
30
30
|
"dist",
|
|
31
|
-
"docs
|
|
31
|
+
"docs",
|
|
32
32
|
"examples"
|
|
33
33
|
],
|
|
34
34
|
"exports": {
|
|
@@ -60,6 +60,22 @@
|
|
|
60
60
|
"import": "./dist/tools/index.js",
|
|
61
61
|
"types": "./dist/tools/index.d.ts"
|
|
62
62
|
},
|
|
63
|
+
"./tools-shell": {
|
|
64
|
+
"import": "./dist/tools-shell/index.js",
|
|
65
|
+
"types": "./dist/tools-shell/index.d.ts"
|
|
66
|
+
},
|
|
67
|
+
"./tools-fs": {
|
|
68
|
+
"import": "./dist/tools-fs/index.js",
|
|
69
|
+
"types": "./dist/tools-fs/index.d.ts"
|
|
70
|
+
},
|
|
71
|
+
"./tools-http": {
|
|
72
|
+
"import": "./dist/tools-http/index.js",
|
|
73
|
+
"types": "./dist/tools-http/index.d.ts"
|
|
74
|
+
},
|
|
75
|
+
"./tools-web": {
|
|
76
|
+
"import": "./dist/tools-web/index.js",
|
|
77
|
+
"types": "./dist/tools-web/index.d.ts"
|
|
78
|
+
},
|
|
63
79
|
"./agent": {
|
|
64
80
|
"import": "./dist/agent/index.js",
|
|
65
81
|
"types": "./dist/agent/index.d.ts"
|
|
@@ -72,10 +88,18 @@
|
|
|
72
88
|
"import": "./dist/session/index.js",
|
|
73
89
|
"types": "./dist/session/index.d.ts"
|
|
74
90
|
},
|
|
91
|
+
"./session-stores": {
|
|
92
|
+
"import": "./dist/session-stores/index.js",
|
|
93
|
+
"types": "./dist/session-stores/index.d.ts"
|
|
94
|
+
},
|
|
75
95
|
"./context": {
|
|
76
96
|
"import": "./dist/context/index.js",
|
|
77
97
|
"types": "./dist/context/index.d.ts"
|
|
78
98
|
},
|
|
99
|
+
"./retrieval": {
|
|
100
|
+
"import": "./dist/retrieval/index.js",
|
|
101
|
+
"types": "./dist/retrieval/index.d.ts"
|
|
102
|
+
},
|
|
79
103
|
"./events": {
|
|
80
104
|
"import": "./dist/events/index.js",
|
|
81
105
|
"types": "./dist/events/index.d.ts"
|
|
@@ -95,20 +119,70 @@
|
|
|
95
119
|
},
|
|
96
120
|
"scripts": {
|
|
97
121
|
"clean": "bun -e \"const fs = require('fs'); fs.rmSync('dist', { recursive: true, force: true });\"",
|
|
98
|
-
"build:js": "bun build src/index.ts src/schema/index.ts src/messages/index.ts src/errors.ts src/runtime/index.ts src/providers/index.ts src/tools/index.ts src/agent/index.ts src/execution/index.ts src/session/index.ts src/context/index.ts src/events/index.ts src/testing/index.ts src/testing/conformance.ts src/lifecycle/index.ts --outdir dist --root src --splitting --external bun:test --target node",
|
|
122
|
+
"build:js": "bun build src/index.ts src/schema/index.ts src/messages/index.ts src/errors.ts src/runtime/index.ts src/providers/index.ts src/tools/index.ts src/tools-shell/index.ts src/tools-fs/index.ts src/tools-http/index.ts src/tools-web/index.ts src/agent/index.ts src/execution/index.ts src/session/index.ts src/session-stores/index.ts src/context/index.ts src/retrieval/index.ts src/events/index.ts src/testing/index.ts src/testing/conformance.ts src/lifecycle/index.ts --outdir dist --root src --splitting --external bun:test --external typescript --external @vscode/ripgrep --external diff --external fuse.js --external glob --external ignore --external minisearch --external @mozilla/readability --external linkedom --external robots-parser --target node",
|
|
99
123
|
"build:types": "tsc -p tsconfig.build.json",
|
|
100
124
|
"build": "bun run clean && bun run build:js && bun run build:types",
|
|
101
125
|
"check": "tsc --noEmit",
|
|
102
126
|
"test": "bun test",
|
|
103
127
|
"docs": "typedoc",
|
|
128
|
+
"examples": "bun run examples/incident-analysis.ts && bun run examples/01-minimal-agent.ts && bun run examples/02-custom-tool.ts && bun run examples/03-streaming.ts && bun run examples/04-sessions-context.ts && bun run examples/05-events-subscribers.ts && bun run examples/06-multi-agent-handoff.ts && bun run examples/07-sub-agent-tool.ts && bun run examples/08-testing-agent.ts && bun run examples/09-tools-filesystem.ts && bun run examples/10-tools-http-web.ts && bun run examples/11-shell-tools.ts && bun run examples/12-provider-openai.ts && bun run examples/13-lifecycle.ts && bun run examples/14-retrieval.ts",
|
|
104
129
|
"prepublishOnly": "bun run check && bun test && bun run build"
|
|
105
130
|
},
|
|
106
131
|
"devDependencies": {
|
|
132
|
+
"@mozilla/readability": "^0.6.0",
|
|
107
133
|
"@types/bun": "^1.3.14",
|
|
134
|
+
"@vscode/ripgrep": "^1.18.0",
|
|
135
|
+
"diff": "^9.0.0",
|
|
136
|
+
"fuse.js": "^7.4.2",
|
|
137
|
+
"glob": "^13.0.6",
|
|
138
|
+
"ignore": "^7.0.5",
|
|
139
|
+
"linkedom": "^0.18.12",
|
|
140
|
+
"minisearch": "^7.2.0",
|
|
141
|
+
"robots-parser": "^3.0.1",
|
|
108
142
|
"typedoc": "^0.28.19",
|
|
109
143
|
"typescript": "^6.0.3"
|
|
110
144
|
},
|
|
111
145
|
"dependencies": {
|
|
112
|
-
"@infinityi/forge": "^1.0.
|
|
146
|
+
"@infinityi/forge": "^1.0.1"
|
|
147
|
+
},
|
|
148
|
+
"peerDependencies": {
|
|
149
|
+
"@mozilla/readability": "^0.6.0",
|
|
150
|
+
"@vscode/ripgrep": "^1.18.0",
|
|
151
|
+
"diff": "^9.0.0",
|
|
152
|
+
"fuse.js": "^7.4.2",
|
|
153
|
+
"glob": "^13.0.6",
|
|
154
|
+
"ignore": "^7.0.5",
|
|
155
|
+
"linkedom": "^0.18.12",
|
|
156
|
+
"minisearch": "^7.2.0",
|
|
157
|
+
"robots-parser": "^3.0.1"
|
|
158
|
+
},
|
|
159
|
+
"peerDependenciesMeta": {
|
|
160
|
+
"@mozilla/readability": {
|
|
161
|
+
"optional": true
|
|
162
|
+
},
|
|
163
|
+
"@vscode/ripgrep": {
|
|
164
|
+
"optional": true
|
|
165
|
+
},
|
|
166
|
+
"diff": {
|
|
167
|
+
"optional": true
|
|
168
|
+
},
|
|
169
|
+
"fuse.js": {
|
|
170
|
+
"optional": true
|
|
171
|
+
},
|
|
172
|
+
"glob": {
|
|
173
|
+
"optional": true
|
|
174
|
+
},
|
|
175
|
+
"ignore": {
|
|
176
|
+
"optional": true
|
|
177
|
+
},
|
|
178
|
+
"linkedom": {
|
|
179
|
+
"optional": true
|
|
180
|
+
},
|
|
181
|
+
"minisearch": {
|
|
182
|
+
"optional": true
|
|
183
|
+
},
|
|
184
|
+
"robots-parser": {
|
|
185
|
+
"optional": true
|
|
186
|
+
}
|
|
113
187
|
}
|
|
114
188
|
}
|