@infinityi/engine-lib 1.0.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +81 -445
- package/dist/agent/index.js +14 -8
- package/dist/context/index.d.ts +1 -1
- package/dist/context/index.js +8 -5
- package/dist/context/providers.d.ts +3 -3
- package/dist/context/types.d.ts +16 -1
- package/dist/errors.d.ts +18 -0
- package/dist/errors.js +6 -1
- package/dist/events/index.js +2 -1
- package/dist/execution/index.js +9 -4
- package/dist/execution/types.d.ts +14 -0
- package/dist/index-37x76zdn.js +4 -0
- package/dist/index-4c15ysa8.js +84 -0
- package/dist/{index-pwr8179t.js → index-7nb9qwa1.js} +23 -14
- package/dist/{index-jxgj4z08.js → index-9egrqxkf.js} +4 -0
- package/dist/index-9rr5dkzh.js +0 -0
- package/dist/{index-w34cbktd.js → index-a67ej96j.js} +1 -0
- package/dist/{index-64tt9696.js → index-aed6fe4z.js} +3 -3
- package/dist/{index-7690reng.js → index-ajr3nk10.js} +15 -1
- package/dist/index-c6kgts41.js +0 -0
- package/dist/{index-xsv43c5j.js → index-e14g2e48.js} +2 -2
- package/dist/index-k0q7x4mz.js +54 -0
- package/dist/index-mnx5mqbs.js +102 -0
- package/dist/index-mr1hs98z.js +661 -0
- package/dist/{index-yrqrxwjt.js → index-nvdsr51v.js} +4 -38
- package/dist/{index-jp2b31xs.js → index-vwcyawfk.js} +4 -4
- package/dist/index-ycjsqfpq.js +39 -0
- package/dist/{index-bqg01r42.js → index-zdggff0y.js} +183 -180
- package/dist/index.d.ts +2 -2
- package/dist/index.js +49 -38
- package/dist/lifecycle/index.js +2 -0
- package/dist/messages/index.js +1 -0
- package/dist/providers/index.js +5 -4
- package/dist/retrieval/chunking.d.ts +8 -0
- package/dist/retrieval/context.d.ts +4 -0
- package/dist/retrieval/index.d.ts +19 -0
- package/dist/retrieval/index.js +747 -0
- package/dist/retrieval/loaders.d.ts +8 -0
- package/dist/retrieval/memory.d.ts +29 -0
- package/dist/retrieval/retriever.d.ts +8 -0
- package/dist/retrieval/types.d.ts +253 -0
- package/dist/retrieval/utils.d.ts +11 -0
- package/dist/retrieval/vector-store.d.ts +13 -0
- package/dist/runtime/index.js +2 -1
- package/dist/schema/index.js +10 -4
- package/dist/session/index.js +1 -0
- package/dist/session-stores/codec.d.ts +8 -0
- package/dist/session-stores/forge-data.d.ts +43 -0
- package/dist/session-stores/hooks.d.ts +4 -0
- package/dist/session-stores/ids.d.ts +3 -0
- package/dist/session-stores/index.d.ts +20 -0
- package/dist/session-stores/index.js +1382 -0
- package/dist/session-stores/jsonl.d.ts +26 -0
- package/dist/session-stores/redis.d.ts +45 -0
- package/dist/session-stores/types.d.ts +45 -0
- package/dist/session-stores/versioning.d.ts +6 -0
- package/dist/testing/conformance.js +5 -4
- package/dist/testing/index.js +1 -0
- package/dist/tools/index.js +5 -3
- package/dist/tools-fs/define.d.ts +2 -0
- package/dist/tools-fs/files.d.ts +40 -0
- package/dist/tools-fs/git.d.ts +14 -0
- package/dist/tools-fs/index.d.ts +19 -0
- package/dist/tools-fs/index.js +1695 -0
- package/dist/tools-fs/policy.d.ts +32 -0
- package/dist/tools-fs/schemas.d.ts +31 -0
- package/dist/tools-fs/search.d.ts +45 -0
- package/dist/tools-fs/symbols.d.ts +12 -0
- package/dist/tools-fs/types.d.ts +151 -0
- package/dist/tools-http/client.d.ts +12 -0
- package/dist/tools-http/define.d.ts +12 -0
- package/dist/tools-http/events.d.ts +22 -0
- package/dist/tools-http/index.d.ts +24 -0
- package/dist/tools-http/index.js +18 -0
- package/dist/tools-http/policy.d.ts +52 -0
- package/dist/tools-http/types.d.ts +116 -0
- package/dist/tools-shell/define.d.ts +23 -0
- package/dist/tools-shell/events.d.ts +38 -0
- package/dist/tools-shell/exec.d.ts +37 -0
- package/dist/tools-shell/index.d.ts +30 -0
- package/dist/tools-shell/index.js +327 -0
- package/dist/tools-shell/policy.d.ts +42 -0
- package/dist/tools-shell/types.d.ts +121 -0
- package/dist/tools-web/define.d.ts +11 -0
- package/dist/tools-web/html.d.ts +22 -0
- package/dist/tools-web/index.d.ts +21 -0
- package/dist/tools-web/index.js +472 -0
- package/dist/tools-web/types.d.ts +81 -0
- package/docs/README.md +58 -10
- package/docs/api/.nojekyll +1 -0
- package/docs/api/assets/hierarchy.js +1 -0
- package/docs/api/assets/highlight.css +99 -0
- package/docs/api/assets/icons.js +18 -0
- package/docs/api/assets/icons.svg +1 -0
- package/docs/api/assets/main.js +60 -0
- package/docs/api/assets/navigation.js +1 -0
- package/docs/api/assets/search.js +1 -0
- package/docs/api/assets/style.css +1633 -0
- package/docs/api/classes/errors.AgentError.html +47 -0
- package/docs/api/classes/errors.CancelledError.html +46 -0
- package/docs/api/classes/errors.ContextWindowError.html +48 -0
- package/docs/api/classes/errors.ExecutionError.html +46 -0
- package/docs/api/classes/errors.FilesystemPolicyError.html +48 -0
- package/docs/api/classes/errors.MaxHandoffsExceededError.html +47 -0
- package/docs/api/classes/errors.MaxStepsExceededError.html +47 -0
- package/docs/api/classes/errors.ProviderError.html +47 -0
- package/docs/api/classes/errors.SchemaValidationError.html +47 -0
- package/docs/api/classes/errors.ShellPolicyError.html +50 -0
- package/docs/api/classes/errors.ToolError.html +47 -0
- package/docs/api/classes/errors.ToolValidationError.html +48 -0
- package/docs/api/classes/index.InMemorySessionStore.html +11 -0
- package/docs/api/classes/index.Secret.html +20 -0
- package/docs/api/classes/providers.StreamAccumulator.html +8 -0
- package/docs/api/classes/session-stores.FilesystemJsonlSessionStore.html +13 -0
- package/docs/api/classes/session-stores.ForgeDataSessionStore.html +14 -0
- package/docs/api/classes/session-stores.RedisSessionStore.html +12 -0
- package/docs/api/classes/tools-http.HttpPolicyError.html +41 -0
- package/docs/api/functions/agent.createToolRegistry.html +3 -0
- package/docs/api/functions/agent.handoffProviderTools.html +3 -0
- package/docs/api/functions/agent.handoffToolName.html +2 -0
- package/docs/api/functions/agent.resolveHandoffTargets.html +8 -0
- package/docs/api/functions/context.applyContextWindow.html +5 -0
- package/docs/api/functions/context.estimateTokens.html +3 -0
- package/docs/api/functions/context.resolveContext.html +5 -0
- package/docs/api/functions/events.createRunTelemetry.html +3 -0
- package/docs/api/functions/events.eventFields.html +4 -0
- package/docs/api/functions/events.eventPayload.html +5 -0
- package/docs/api/functions/execution.addUsage.html +2 -0
- package/docs/api/functions/execution.emptyUsage.html +2 -0
- package/docs/api/functions/index.asSchema.html +4 -0
- package/docs/api/functions/index.asTool.html +8 -0
- package/docs/api/functions/index.assistant.html +2 -0
- package/docs/api/functions/index.createAgentRegistry.html +5 -0
- package/docs/api/functions/index.createAnthropic.html +5 -0
- package/docs/api/functions/index.createEventHub.html +2 -0
- package/docs/api/functions/index.createGoogle.html +5 -0
- package/docs/api/functions/index.createOpenAI.html +5 -0
- package/docs/api/functions/index.createOpenAICompatible.html +7 -0
- package/docs/api/functions/index.createSession.html +3 -0
- package/docs/api/functions/index.defineAgent.html +7 -0
- package/docs/api/functions/index.defineTool.html +7 -0
- package/docs/api/functions/index.dynamicContext.html +2 -0
- package/docs/api/functions/index.fromJsonSchema.html +3 -0
- package/docs/api/functions/index.isSecret.html +4 -0
- package/docs/api/functions/index.loggingSubscriber.html +4 -0
- package/docs/api/functions/index.messageBusSubscriber.html +6 -0
- package/docs/api/functions/index.normalizeContent.html +2 -0
- package/docs/api/functions/index.resolveSecret.html +4 -0
- package/docs/api/functions/index.runAgent.html +19 -0
- package/docs/api/functions/index.staticContext.html +3 -0
- package/docs/api/functions/index.summarizeOldest.html +4 -0
- package/docs/api/functions/index.system.html +2 -0
- package/docs/api/functions/index.text.html +2 -0
- package/docs/api/functions/index.toJsonSchema.html +2 -0
- package/docs/api/functions/index.toolResult.html +2 -0
- package/docs/api/functions/index.truncateOldest.html +5 -0
- package/docs/api/functions/index.user.html +2 -0
- package/docs/api/functions/index.validateJsonSchema.html +3 -0
- package/docs/api/functions/lifecycle.agentRuntimeComponent.html +5 -0
- package/docs/api/functions/providers.collectStream.html +2 -0
- package/docs/api/functions/providers.createProvider.html +4 -0
- package/docs/api/functions/providers.createProviderHttp.html +3 -0
- package/docs/api/functions/providers.defaultProviderResilience.html +3 -0
- package/docs/api/functions/providers.openSseStream.html +6 -0
- package/docs/api/functions/providers.parseSse.html +2 -0
- package/docs/api/functions/providers.toProviderError.html +2 -0
- package/docs/api/functions/session-stores.createPostgresSessionStore.html +1 -0
- package/docs/api/functions/session-stores.createSqliteSessionStore.html +1 -0
- package/docs/api/functions/session-stores.isCloseableSessionStore.html +1 -0
- package/docs/api/functions/session-stores.isVersionedSessionStore.html +1 -0
- package/docs/api/functions/session-stores.migrateSessionStore.html +1 -0
- package/docs/api/functions/session-stores.withSessionStoreHooks.html +2 -0
- package/docs/api/functions/testing.byteStreamOf.html +2 -0
- package/docs/api/functions/testing.collectProviderStream.html +2 -0
- package/docs/api/functions/testing.conversation.html +2 -0
- package/docs/api/functions/testing.expectValid.html +3 -0
- package/docs/api/functions/testing.inMemorySessionStore.html +2 -0
- package/docs/api/functions/testing.jsonFetch.html +3 -0
- package/docs/api/functions/testing.mockProvider.html +3 -0
- package/docs/api/functions/testing.scriptedProvider.html +4 -0
- package/docs/api/functions/testing.sseFetch.html +3 -0
- package/docs/api/functions/testing.textResult.html +3 -0
- package/docs/api/functions/testing.toolCallResult.html +3 -0
- package/docs/api/functions/testing_conformance.runProviderConformance.html +3 -0
- package/docs/api/functions/tools-fs.filesystemTools.html +1 -0
- package/docs/api/functions/tools-http.createHttpToolClient.html +2 -0
- package/docs/api/functions/tools-http.httpTools.html +2 -0
- package/docs/api/functions/tools-shell.shellTools.html +4 -0
- package/docs/api/functions/tools-web.webTools.html +2 -0
- package/docs/api/functions/tools.renderToolContent.html +6 -0
- package/docs/api/functions/tools.toProviderTool.html +3 -0
- package/docs/api/functions/tools.toToolResultMessage.html +4 -0
- package/docs/api/hierarchy.html +1 -0
- package/docs/api/index.html +1 -0
- package/docs/api/interfaces/agent.ToolRegistry.html +8 -0
- package/docs/api/interfaces/errors.SchemaIssue.html +4 -0
- package/docs/api/interfaces/events.RunTelemetry.html +10 -0
- package/docs/api/interfaces/events.SpanHandle.html +6 -0
- package/docs/api/interfaces/index.AgentDefinition.html +16 -0
- package/docs/api/interfaces/index.AgentHooks.html +21 -0
- package/docs/api/interfaces/index.AgentRegistry.html +16 -0
- package/docs/api/interfaces/index.AnthropicOptions.html +13 -0
- package/docs/api/interfaces/index.AsToolOptions.html +13 -0
- package/docs/api/interfaces/index.CompletionRequest.html +30 -0
- package/docs/api/interfaces/index.CompletionResult.html +14 -0
- package/docs/api/interfaces/index.ContextItem.html +6 -0
- package/docs/api/interfaces/index.ContextProvider.html +5 -0
- package/docs/api/interfaces/index.ContextStrategy.html +8 -0
- package/docs/api/interfaces/index.ContextStrategyContext.html +8 -0
- package/docs/api/interfaces/index.ContextWindowOptions.html +8 -0
- package/docs/api/interfaces/index.CreateSessionOptions.html +10 -0
- package/docs/api/interfaces/index.EngineContext.html +10 -0
- package/docs/api/interfaces/index.EventHub.html +4 -0
- package/docs/api/interfaces/index.EventHubOptions.html +8 -0
- package/docs/api/interfaces/index.GenerationSettings.html +12 -0
- package/docs/api/interfaces/index.GoogleOptions.html +11 -0
- package/docs/api/interfaces/index.ImagePart.html +5 -0
- package/docs/api/interfaces/index.InstructionContext.html +9 -0
- package/docs/api/interfaces/index.JsonSchema.html +18 -0
- package/docs/api/interfaces/index.LoggingSubscriberOptions.html +4 -0
- package/docs/api/interfaces/index.Message.html +8 -0
- package/docs/api/interfaces/index.MessageBusSubscriberOptions.html +4 -0
- package/docs/api/interfaces/index.OpenAICompatibleOptions.html +16 -0
- package/docs/api/interfaces/index.OpenAIOptions.html +16 -0
- package/docs/api/interfaces/index.Provider.html +11 -0
- package/docs/api/interfaces/index.ProviderCapabilities.html +9 -0
- package/docs/api/interfaces/index.ProviderTool.html +6 -0
- package/docs/api/interfaces/index.ResponseSchema.html +6 -0
- package/docs/api/interfaces/index.RunBridge.html +10 -0
- package/docs/api/interfaces/index.RunOptions.html +39 -0
- package/docs/api/interfaces/index.RunResult.html +20 -0
- package/docs/api/interfaces/index.Schema.html +13 -0
- package/docs/api/interfaces/index.Session.html +13 -0
- package/docs/api/interfaces/index.SessionState.html +5 -0
- package/docs/api/interfaces/index.SessionStore.html +15 -0
- package/docs/api/interfaces/index.TextPart.html +4 -0
- package/docs/api/interfaces/index.ToolCall.html +9 -0
- package/docs/api/interfaces/index.ToolCallPart.html +6 -0
- package/docs/api/interfaces/index.ToolContext.html +21 -0
- package/docs/api/interfaces/index.ToolDefinition.html +14 -0
- package/docs/api/interfaces/index.ToolFailure.html +9 -0
- package/docs/api/interfaces/index.ToolResultPart.html +8 -0
- package/docs/api/interfaces/index.ToolSpec.html +6 -0
- package/docs/api/interfaces/index.ToolSuccess.html +6 -0
- package/docs/api/interfaces/index.Usage.html +9 -0
- package/docs/api/interfaces/lifecycle.AgentRuntimeOptions.html +17 -0
- package/docs/api/interfaces/providers.AdapterSpec.html +17 -0
- package/docs/api/interfaces/providers.ProviderHttpOptions.html +14 -0
- package/docs/api/interfaces/providers.SseMessage.html +6 -0
- package/docs/api/interfaces/providers.SseRequest.html +8 -0
- package/docs/api/interfaces/runtime.Logger.html +22 -0
- package/docs/api/interfaces/runtime.Telemetry.html +9 -0
- package/docs/api/interfaces/schema.OptionalSchema.html +13 -0
- package/docs/api/interfaces/session-stores.CloseableSessionStore.html +11 -0
- package/docs/api/interfaces/session-stores.CreatePostgresSessionStoreOptions.html +6 -0
- package/docs/api/interfaces/session-stores.CreateSqliteSessionStoreOptions.html +7 -0
- package/docs/api/interfaces/session-stores.FilesystemJsonlSessionStoreOptions.html +3 -0
- package/docs/api/interfaces/session-stores.ForgeDataSessionStoreOptions.html +5 -0
- package/docs/api/interfaces/session-stores.RedisSessionStoreClient.html +9 -0
- package/docs/api/interfaces/session-stores.RedisSessionStoreOptions.html +4 -0
- package/docs/api/interfaces/session-stores.RedisSessionStoreTransaction.html +6 -0
- package/docs/api/interfaces/session-stores.SessionArchiveRecord.html +7 -0
- package/docs/api/interfaces/session-stores.SessionArchiver.html +2 -0
- package/docs/api/interfaces/session-stores.SessionCompactionResult.html +3 -0
- package/docs/api/interfaces/session-stores.SessionCompactor.html +3 -0
- package/docs/api/interfaces/session-stores.SessionStoreCodec.html +6 -0
- package/docs/api/interfaces/session-stores.SessionStoreHookContext.html +3 -0
- package/docs/api/interfaces/session-stores.SessionStoreHooks.html +3 -0
- package/docs/api/interfaces/session-stores.VersionedSessionStore.html +11 -0
- package/docs/api/interfaces/testing.MockProviderOptions.html +12 -0
- package/docs/api/interfaces/testing.RecordedCall.html +4 -0
- package/docs/api/interfaces/testing.RecordingFetch.html +4 -0
- package/docs/api/interfaces/testing_conformance.ConformanceFixtures.html +12 -0
- package/docs/api/interfaces/testing_conformance.ConformanceOptions.html +10 -0
- package/docs/api/interfaces/testing_conformance.ConformanceTestApi.html +4 -0
- package/docs/api/interfaces/testing_conformance.ProviderIO.html +7 -0
- package/docs/api/interfaces/tools-fs.ApplyPatchArgs.html +6 -0
- package/docs/api/interfaces/tools-fs.DiffStatusArgs.html +5 -0
- package/docs/api/interfaces/tools-fs.EditRangeArgs.html +7 -0
- package/docs/api/interfaces/tools-fs.EditReplaceArgs.html +7 -0
- package/docs/api/interfaces/tools-fs.FilesystemTools.html +13 -0
- package/docs/api/interfaces/tools-fs.FilesystemToolsConfig.html +12 -0
- package/docs/api/interfaces/tools-fs.FindFilesArgs.html +7 -0
- package/docs/api/interfaces/tools-fs.OpenWindowArgs.html +5 -0
- package/docs/api/interfaces/tools-fs.ReadArgs.html +9 -0
- package/docs/api/interfaces/tools-fs.RepoMapArgs.html +7 -0
- package/docs/api/interfaces/tools-fs.SearchSemanticArgs.html +8 -0
- package/docs/api/interfaces/tools-fs.SearchTextArgs.html +11 -0
- package/docs/api/interfaces/tools-fs.SymbolInfo.html +7 -0
- package/docs/api/interfaces/tools-fs.SymbolsArgs.html +5 -0
- package/docs/api/interfaces/tools-fs.ValidationCommandRequest.html +4 -0
- package/docs/api/interfaces/tools-fs.ValidationCommandResult.html +6 -0
- package/docs/api/interfaces/tools-fs.ValidationOptions.html +4 -0
- package/docs/api/interfaces/tools-fs.WriteFileArgs.html +6 -0
- package/docs/api/interfaces/tools-http.HeaderEntry.html +4 -0
- package/docs/api/interfaces/tools-http.HttpClientRequest.html +11 -0
- package/docs/api/interfaces/tools-http.HttpPolicy.html +13 -0
- package/docs/api/interfaces/tools-http.HttpRequestResult.html +17 -0
- package/docs/api/interfaces/tools-http.HttpRetryOptions.html +10 -0
- package/docs/api/interfaces/tools-http.HttpToolClient.html +5 -0
- package/docs/api/interfaces/tools-http.HttpTools.html +4 -0
- package/docs/api/interfaces/tools-http.HttpToolsConfig.html +38 -0
- package/docs/api/interfaces/tools-shell.ApprovalDecision.html +5 -0
- package/docs/api/interfaces/tools-shell.CommandRequest.html +14 -0
- package/docs/api/interfaces/tools-shell.CommandResult.html +21 -0
- package/docs/api/interfaces/tools-shell.EnvPolicy.html +9 -0
- package/docs/api/interfaces/tools-shell.ShellPolicy.html +7 -0
- package/docs/api/interfaces/tools-shell.ShellTools.html +6 -0
- package/docs/api/interfaces/tools-shell.ShellToolsConfig.html +26 -0
- package/docs/api/interfaces/tools-web.Citation.html +6 -0
- package/docs/api/interfaces/tools-web.SearchProvider.html +3 -0
- package/docs/api/interfaces/tools-web.SearchRequest.html +4 -0
- package/docs/api/interfaces/tools-web.SearchResult.html +7 -0
- package/docs/api/interfaces/tools-web.SourceMetadata.html +10 -0
- package/docs/api/interfaces/tools-web.WebTools.html +6 -0
- package/docs/api/interfaces/tools-web.WebToolsConfig.html +56 -0
- package/docs/api/modules/agent.html +5 -0
- package/docs/api/modules/context.html +5 -0
- package/docs/api/modules/errors.html +8 -0
- package/docs/api/modules/events.html +16 -0
- package/docs/api/modules/execution.html +4 -0
- package/docs/api/modules/index.html +16 -0
- package/docs/api/modules/lifecycle.html +6 -0
- package/docs/api/modules/messages.html +3 -0
- package/docs/api/modules/providers.html +10 -0
- package/docs/api/modules/runtime.html +4 -0
- package/docs/api/modules/schema.html +5 -0
- package/docs/api/modules/session-stores.html +6 -0
- package/docs/api/modules/session.html +4 -0
- package/docs/api/modules/testing.html +4 -0
- package/docs/api/modules/testing_conformance.html +21 -0
- package/docs/api/modules/tools-fs.html +9 -0
- package/docs/api/modules/tools-http.html +8 -0
- package/docs/api/modules/tools-shell.html +12 -0
- package/docs/api/modules/tools-web.html +7 -0
- package/docs/api/modules/tools.html +4 -0
- package/docs/api/types/events.Attrs.html +2 -0
- package/docs/api/types/index.AnyRunOptions.html +3 -0
- package/docs/api/types/index.BufferedRunOptions.html +2 -0
- package/docs/api/types/index.ContentPart.html +2 -0
- package/docs/api/types/index.FinishReason.html +2 -0
- package/docs/api/types/index.Infer.html +2 -0
- package/docs/api/types/index.Instructions.html +5 -0
- package/docs/api/types/index.LogLevel.html +2 -0
- package/docs/api/types/index.Role.html +2 -0
- package/docs/api/types/index.RunEvent.html +30 -0
- package/docs/api/types/index.RunHandle.html +7 -0
- package/docs/api/types/index.RunInput.html +2 -0
- package/docs/api/types/index.RunSubscriber.html +4 -0
- package/docs/api/types/index.SafeParseResult.html +2 -0
- package/docs/api/types/index.StreamEvent.html +8 -0
- package/docs/api/types/index.StreamingRunOptions.html +2 -0
- package/docs/api/types/index.TelemetryHandle.html +2 -0
- package/docs/api/types/index.TokenCounter.html +2 -0
- package/docs/api/types/index.ToolChoice.html +2 -0
- package/docs/api/types/index.ToolResult.html +2 -0
- package/docs/api/types/lifecycle.ProviderProbe.html +2 -0
- package/docs/api/types/session-stores.SessionStoreHookOperation.html +1 -0
- package/docs/api/types/testing_conformance.MakeProvider.html +2 -0
- package/docs/api/types/tools-fs.SymbolKind.html +1 -0
- package/docs/api/types/tools-http.HostPattern.html +2 -0
- package/docs/api/types/tools-shell.CommandPattern.html +2 -0
- package/docs/api/types/tools-web.RobotsPolicy.html +2 -0
- package/docs/api/variables/events.SPAN_PROVIDER.html +2 -0
- package/docs/api/variables/events.SPAN_RUN.html +2 -0
- package/docs/api/variables/events.SPAN_TOOL.html +2 -0
- package/docs/api/variables/execution.DEFAULT_MAX_HANDOFFS.html +2 -0
- package/docs/api/variables/execution.DEFAULT_MAX_STEPS.html +2 -0
- package/docs/api/variables/index.s.html +11 -0
- package/docs/api/variables/providers.DEFAULT_TIMEOUT_MS.html +2 -0
- package/docs/api/variables/session-stores.SESSION_STORE_SCHEMA_VERSION.html +1 -0
- package/docs/api/variables/session-stores.jsonSessionStoreCodec.html +2 -0
- package/docs/api/variables/tools-http.HTTP_EVENT.html +2 -0
- package/docs/api/variables/tools-shell.SHELL_EVENT.html +2 -0
- package/docs/events-and-telemetry.md +68 -0
- package/docs/execution.md +63 -0
- package/docs/getting-started.md +73 -0
- package/docs/multi-agent.md +52 -0
- package/docs/optional-tool-packs.md +93 -0
- package/docs/providers.md +68 -0
- package/docs/retrieval.md +83 -0
- package/docs/sessions-and-context.md +82 -0
- package/docs/testing-and-lifecycle.md +60 -0
- package/docs/tools.md +69 -0
- package/examples/01-minimal-agent.ts +19 -0
- package/examples/02-custom-tool.ts +32 -0
- package/examples/03-streaming.ts +46 -0
- package/examples/04-sessions-context.ts +40 -0
- package/examples/05-events-subscribers.ts +35 -0
- package/examples/06-multi-agent-handoff.ts +27 -0
- package/examples/07-sub-agent-tool.ts +26 -0
- package/examples/08-testing-agent.ts +31 -0
- package/examples/09-tools-filesystem.ts +49 -0
- package/examples/10-tools-http-web.ts +74 -0
- package/examples/11-shell-tools.ts +39 -0
- package/examples/12-provider-openai.ts +24 -0
- package/examples/13-lifecycle.ts +37 -0
- package/examples/14-retrieval.ts +65 -0
- package/examples/incident-analysis.ts +39 -87
- package/package.json +78 -4
- package/dist/index-02s1fjxr.js +0 -226
- package/examples/README.md +0 -24
- package/examples/lifecycle.ts +0 -53
- package/examples/multi-agent.ts +0 -93
- package/examples/terminal-coder.ts +0 -80
package/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
|
}
|
package/dist/index-02s1fjxr.js
DELETED
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
SchemaValidationError
|
|
3
|
-
} from "./index-7690reng.js";
|
|
4
|
-
|
|
5
|
-
// src/schema/validate.ts
|
|
6
|
-
function issue(path, message) {
|
|
7
|
-
return { path: [...path], message };
|
|
8
|
-
}
|
|
9
|
-
function isPlainObject(value) {
|
|
10
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
11
|
-
}
|
|
12
|
-
function validateJsonSchema(node, input, path = []) {
|
|
13
|
-
const issues = [];
|
|
14
|
-
if (node.enum !== undefined) {
|
|
15
|
-
if (!node.enum.includes(input)) {
|
|
16
|
-
issues.push(issue(path, `expected one of ${JSON.stringify(node.enum)}`));
|
|
17
|
-
}
|
|
18
|
-
return issues;
|
|
19
|
-
}
|
|
20
|
-
switch (node.type) {
|
|
21
|
-
case "string":
|
|
22
|
-
if (typeof input !== "string")
|
|
23
|
-
issues.push(issue(path, "expected string"));
|
|
24
|
-
break;
|
|
25
|
-
case "boolean":
|
|
26
|
-
if (typeof input !== "boolean")
|
|
27
|
-
issues.push(issue(path, "expected boolean"));
|
|
28
|
-
break;
|
|
29
|
-
case "null":
|
|
30
|
-
if (input !== null)
|
|
31
|
-
issues.push(issue(path, "expected null"));
|
|
32
|
-
break;
|
|
33
|
-
case "number":
|
|
34
|
-
if (typeof input !== "number" || Number.isNaN(input)) {
|
|
35
|
-
issues.push(issue(path, "expected number"));
|
|
36
|
-
}
|
|
37
|
-
break;
|
|
38
|
-
case "integer":
|
|
39
|
-
if (typeof input !== "number" || !Number.isInteger(input)) {
|
|
40
|
-
issues.push(issue(path, "expected integer"));
|
|
41
|
-
}
|
|
42
|
-
break;
|
|
43
|
-
case "array": {
|
|
44
|
-
if (!Array.isArray(input)) {
|
|
45
|
-
issues.push(issue(path, "expected array"));
|
|
46
|
-
break;
|
|
47
|
-
}
|
|
48
|
-
if (node.items !== undefined) {
|
|
49
|
-
input.forEach((element, index) => {
|
|
50
|
-
issues.push(...validateJsonSchema(node.items, element, [...path, index]));
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
break;
|
|
54
|
-
}
|
|
55
|
-
case "object": {
|
|
56
|
-
if (!isPlainObject(input)) {
|
|
57
|
-
issues.push(issue(path, "expected object"));
|
|
58
|
-
break;
|
|
59
|
-
}
|
|
60
|
-
const properties = node.properties ?? {};
|
|
61
|
-
const required = node.required ?? [];
|
|
62
|
-
for (const key of required) {
|
|
63
|
-
if (input[key] === undefined) {
|
|
64
|
-
issues.push(issue([...path, key], "required"));
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
for (const [key, propSchema] of Object.entries(properties)) {
|
|
68
|
-
const value = input[key];
|
|
69
|
-
if (value === undefined)
|
|
70
|
-
continue;
|
|
71
|
-
issues.push(...validateJsonSchema(propSchema, value, [...path, key]));
|
|
72
|
-
}
|
|
73
|
-
if (node.additionalProperties === false) {
|
|
74
|
-
for (const key of Object.keys(input)) {
|
|
75
|
-
if (!(key in properties)) {
|
|
76
|
-
issues.push(issue([...path, key], "unexpected property"));
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
break;
|
|
81
|
-
}
|
|
82
|
-
default:
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
return issues;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// src/schema/builder.ts
|
|
89
|
-
var optionalSchemas = new WeakSet;
|
|
90
|
-
function makeSchema(jsonSchema) {
|
|
91
|
-
return {
|
|
92
|
-
jsonSchema,
|
|
93
|
-
safeParse(input) {
|
|
94
|
-
const issues = validateJsonSchema(jsonSchema, input);
|
|
95
|
-
if (issues.length === 0)
|
|
96
|
-
return { success: true, data: input };
|
|
97
|
-
return {
|
|
98
|
-
success: false,
|
|
99
|
-
error: new SchemaValidationError("schema validation failed", { issues })
|
|
100
|
-
};
|
|
101
|
-
},
|
|
102
|
-
parse(input) {
|
|
103
|
-
const result = this.safeParse(input);
|
|
104
|
-
if (!result.success)
|
|
105
|
-
throw result.error;
|
|
106
|
-
return result.data;
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
var s = {
|
|
111
|
-
string(opts) {
|
|
112
|
-
const node = { type: "string" };
|
|
113
|
-
if (opts?.description !== undefined)
|
|
114
|
-
node.description = opts.description;
|
|
115
|
-
if (opts?.enum !== undefined)
|
|
116
|
-
node.enum = opts.enum;
|
|
117
|
-
return makeSchema(node);
|
|
118
|
-
},
|
|
119
|
-
number(opts) {
|
|
120
|
-
const node = { type: opts?.int ? "integer" : "number" };
|
|
121
|
-
if (opts?.description !== undefined)
|
|
122
|
-
node.description = opts.description;
|
|
123
|
-
return makeSchema(node);
|
|
124
|
-
},
|
|
125
|
-
boolean(opts) {
|
|
126
|
-
const node = { type: "boolean" };
|
|
127
|
-
if (opts?.description !== undefined)
|
|
128
|
-
node.description = opts.description;
|
|
129
|
-
return makeSchema(node);
|
|
130
|
-
},
|
|
131
|
-
enum(values, opts) {
|
|
132
|
-
const node = { type: "string", enum: values };
|
|
133
|
-
if (opts?.description !== undefined)
|
|
134
|
-
node.description = opts.description;
|
|
135
|
-
return makeSchema(node);
|
|
136
|
-
},
|
|
137
|
-
array(item, opts) {
|
|
138
|
-
const node = { type: "array", items: item.jsonSchema };
|
|
139
|
-
if (opts?.description !== undefined)
|
|
140
|
-
node.description = opts.description;
|
|
141
|
-
return makeSchema(node);
|
|
142
|
-
},
|
|
143
|
-
object(props, opts) {
|
|
144
|
-
const properties = {};
|
|
145
|
-
const required = [];
|
|
146
|
-
for (const [key, prop] of Object.entries(props)) {
|
|
147
|
-
properties[key] = prop.jsonSchema;
|
|
148
|
-
if (!optionalSchemas.has(prop))
|
|
149
|
-
required.push(key);
|
|
150
|
-
}
|
|
151
|
-
const node = {
|
|
152
|
-
type: "object",
|
|
153
|
-
properties,
|
|
154
|
-
additionalProperties: false
|
|
155
|
-
};
|
|
156
|
-
if (required.length > 0)
|
|
157
|
-
node.required = required;
|
|
158
|
-
if (opts?.description !== undefined)
|
|
159
|
-
node.description = opts.description;
|
|
160
|
-
return makeSchema(node);
|
|
161
|
-
},
|
|
162
|
-
optional(inner) {
|
|
163
|
-
const schema = {
|
|
164
|
-
jsonSchema: inner.jsonSchema,
|
|
165
|
-
safeParse(input) {
|
|
166
|
-
if (input === undefined)
|
|
167
|
-
return { success: true, data: undefined };
|
|
168
|
-
return inner.safeParse(input);
|
|
169
|
-
},
|
|
170
|
-
parse(input) {
|
|
171
|
-
const result = this.safeParse(input);
|
|
172
|
-
if (!result.success)
|
|
173
|
-
throw result.error;
|
|
174
|
-
return result.data;
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
optionalSchemas.add(schema);
|
|
178
|
-
return schema;
|
|
179
|
-
}
|
|
180
|
-
};
|
|
181
|
-
// src/schema/json-schema.ts
|
|
182
|
-
function toJsonSchema(schema) {
|
|
183
|
-
return schema.jsonSchema;
|
|
184
|
-
}
|
|
185
|
-
function asSchema(impl) {
|
|
186
|
-
return {
|
|
187
|
-
jsonSchema: impl.jsonSchema,
|
|
188
|
-
parse: impl.parse.bind(impl),
|
|
189
|
-
safeParse: impl.safeParse?.bind(impl) ?? ((input) => {
|
|
190
|
-
try {
|
|
191
|
-
return { success: true, data: impl.parse(input) };
|
|
192
|
-
} catch (error) {
|
|
193
|
-
if (error instanceof SchemaValidationError)
|
|
194
|
-
return { success: false, error };
|
|
195
|
-
return {
|
|
196
|
-
success: false,
|
|
197
|
-
error: new SchemaValidationError("schema validation failed", {
|
|
198
|
-
cause: error,
|
|
199
|
-
issues: [{ path: [], message: String(error) }]
|
|
200
|
-
})
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
})
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
function fromJsonSchema(jsonSchema) {
|
|
207
|
-
return {
|
|
208
|
-
jsonSchema,
|
|
209
|
-
safeParse(input) {
|
|
210
|
-
const issues = validateJsonSchema(jsonSchema, input);
|
|
211
|
-
if (issues.length === 0)
|
|
212
|
-
return { success: true, data: input };
|
|
213
|
-
return {
|
|
214
|
-
success: false,
|
|
215
|
-
error: new SchemaValidationError("schema validation failed", { issues })
|
|
216
|
-
};
|
|
217
|
-
},
|
|
218
|
-
parse(input) {
|
|
219
|
-
const result = this.safeParse(input);
|
|
220
|
-
if (!result.success)
|
|
221
|
-
throw result.error;
|
|
222
|
-
return result.data;
|
|
223
|
-
}
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
export { validateJsonSchema, s, toJsonSchema, asSchema, fromJsonSchema };
|
package/examples/README.md
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
# Examples
|
|
2
|
-
|
|
3
|
-
Small, self-contained programs demonstrating the engine-lib API. Each one runs
|
|
4
|
-
**offline** with `bun` — they use the network-free test doubles from
|
|
5
|
-
`@infinityi/engine-lib/testing` (scripted providers) so no API key is required.
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
bun examples/incident-analysis.ts # context injection + a read-only tool
|
|
9
|
-
bun examples/terminal-coder.ts # streaming tokens + a persisted session
|
|
10
|
-
bun examples/multi-agent.ts # handoff/delegation + sub-agent-as-tool
|
|
11
|
-
bun examples/lifecycle.ts # forge.boot with agentRuntimeComponent
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
| File | Demonstrates |
|
|
15
|
-
| --- | --- |
|
|
16
|
-
| [`incident-analysis.ts`](./incident-analysis.ts) | `defineAgent` + `defineTool`, `staticContext` injection, `onEvent` tool-call observation |
|
|
17
|
-
| [`terminal-coder.ts`](./terminal-coder.ts) | streaming (`stream: true`) `token` events, `createSession` history persistence |
|
|
18
|
-
| [`multi-agent.ts`](./multi-agent.ts) | Phase 7 — `handoffs` / `transfer_to_<name>` and `asTool(agent)` |
|
|
19
|
-
| [`lifecycle.ts`](./lifecycle.ts) | Phase 8 — `agentRuntimeComponent` start/healthcheck/stop under `forge.boot` |
|
|
20
|
-
|
|
21
|
-
> The examples import from `@infinityi/engine-lib`, so they work both inside this
|
|
22
|
-
> repository and from the published package. In your own application, pass a real
|
|
23
|
-
> provider, e.g. `createOpenAI({ apiKey, model })` or
|
|
24
|
-
> `createAnthropic({ apiKey, model })`.
|
package/examples/lifecycle.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Example 4 — Forge lifecycle integration (Phase 8).
|
|
3
|
-
*
|
|
4
|
-
* Boot the engine-lib runtime as a `@infinityi/forge/lifecycle` component:
|
|
5
|
-
* `agentRuntimeComponent` validates providers on start, exposes a health probe,
|
|
6
|
-
* and runs an `onStop` hook on graceful shutdown — all orchestrated by
|
|
7
|
-
* `forge.boot`.
|
|
8
|
-
*
|
|
9
|
-
* Run it: `bun examples/lifecycle.ts`
|
|
10
|
-
*
|
|
11
|
-
* Uses in-memory doubles so it runs offline. `installSignals: false` + a no-op
|
|
12
|
-
* `exit` keep the example from installing real process signal handlers.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
import { boot } from "@infinityi/forge/lifecycle";
|
|
16
|
-
|
|
17
|
-
import { agentRuntimeComponent } from "@infinityi/engine-lib/lifecycle";
|
|
18
|
-
import {
|
|
19
|
-
inMemorySessionStore,
|
|
20
|
-
mockProvider,
|
|
21
|
-
} from "@infinityi/engine-lib/testing";
|
|
22
|
-
|
|
23
|
-
const store = inMemorySessionStore();
|
|
24
|
-
const runtime = agentRuntimeComponent({
|
|
25
|
-
providers: [mockProvider({ name: "openai", defaultModel: "gpt-5" })],
|
|
26
|
-
sessionStore: store,
|
|
27
|
-
// A real probe would issue a cheap completion; here it's a no-op success.
|
|
28
|
-
probe: () => Promise.resolve(),
|
|
29
|
-
probeOnStart: true,
|
|
30
|
-
onStop: () => console.log(" onStop: flushing session store"),
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
const app = await boot({
|
|
34
|
-
components: [runtime],
|
|
35
|
-
installSignals: false,
|
|
36
|
-
exit: () => {},
|
|
37
|
-
});
|
|
38
|
-
console.log(
|
|
39
|
-
"booted — ready:",
|
|
40
|
-
app.ready,
|
|
41
|
-
"| components:",
|
|
42
|
-
app.components.map((c) => c.name),
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
const health = await runtime.healthcheck?.({
|
|
46
|
-
signal: new AbortController().signal,
|
|
47
|
-
logger: console,
|
|
48
|
-
});
|
|
49
|
-
console.log("healthcheck:", health?.status, health?.data);
|
|
50
|
-
|
|
51
|
-
await app.stop("example-complete");
|
|
52
|
-
await app.done;
|
|
53
|
-
console.log("drained cleanly");
|
package/examples/multi-agent.ts
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Example 3 — multi-agent coordination (Phase 7).
|
|
3
|
-
*
|
|
4
|
-
* Two complementary composition patterns, both driven by the same `runAgent`
|
|
5
|
-
* loop (no separate orchestrator):
|
|
6
|
-
* 1. Handoff/delegation — a triage agent transfers the conversation to a
|
|
7
|
-
* specialist via a synthetic `transfer_to_<name>` tool.
|
|
8
|
-
* 2. Sub-agent-as-tool — a lead agent invokes a researcher agent through the
|
|
9
|
-
* normal tool-calling path with `asTool(...)`.
|
|
10
|
-
*
|
|
11
|
-
* Run it: `bun examples/multi-agent.ts`
|
|
12
|
-
*
|
|
13
|
-
* Uses scripted providers so it runs offline.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
import { asTool, defineAgent } from "@infinityi/engine-lib/agent";
|
|
17
|
-
import { runAgent } from "@infinityi/engine-lib/execution";
|
|
18
|
-
import {
|
|
19
|
-
scriptedProvider,
|
|
20
|
-
textResult,
|
|
21
|
-
toolCallResult,
|
|
22
|
-
} from "@infinityi/engine-lib/testing";
|
|
23
|
-
|
|
24
|
-
// --- 1. Handoff / delegation ---------------------------------------------
|
|
25
|
-
|
|
26
|
-
const billing = defineAgent({
|
|
27
|
-
name: "billing",
|
|
28
|
-
provider: scriptedProvider([
|
|
29
|
-
textResult("I've issued your refund — it'll land in 3-5 days."),
|
|
30
|
-
]),
|
|
31
|
-
instructions: "Handle billing and refunds.",
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
// Triage's model calls the synthetic `transfer_to_billing` tool to hand off.
|
|
35
|
-
const triage = defineAgent({
|
|
36
|
-
name: "triage",
|
|
37
|
-
provider: scriptedProvider([
|
|
38
|
-
toolCallResult([{ id: "h1", name: "transfer_to_billing", arguments: {} }]),
|
|
39
|
-
]),
|
|
40
|
-
instructions: "Route the user to the right specialist.",
|
|
41
|
-
handoffs: [billing],
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
const handoffResult = await runAgent(triage, { input: "I want a refund" });
|
|
45
|
-
console.log("=== handoff ===");
|
|
46
|
-
console.log("answer:", handoffResult.output);
|
|
47
|
-
console.log(
|
|
48
|
-
"final agent:",
|
|
49
|
-
handoffResult.agent,
|
|
50
|
-
"| trail:",
|
|
51
|
-
handoffResult.handoffs,
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
// --- 2. Sub-agent-as-tool -------------------------------------------------
|
|
55
|
-
|
|
56
|
-
const researcher = defineAgent({
|
|
57
|
-
name: "researcher",
|
|
58
|
-
provider: scriptedProvider([
|
|
59
|
-
textResult(
|
|
60
|
-
"Bun is a fast all-in-one JS runtime, bundler, and test runner.",
|
|
61
|
-
),
|
|
62
|
-
]),
|
|
63
|
-
instructions: "Research deeply and report concisely.",
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
const lead = defineAgent({
|
|
67
|
-
name: "lead",
|
|
68
|
-
// Turn 1: delegate to the researcher tool. Turn 2: summarize its finding.
|
|
69
|
-
provider: scriptedProvider([
|
|
70
|
-
toolCallResult([
|
|
71
|
-
{ id: "c1", name: "researcher", arguments: { input: "What is Bun?" } },
|
|
72
|
-
]),
|
|
73
|
-
textResult(
|
|
74
|
-
"Summary: Bun is a fast all-in-one JavaScript runtime/bundler/test-runner.",
|
|
75
|
-
),
|
|
76
|
-
]),
|
|
77
|
-
instructions: "Delegate research, then summarize.",
|
|
78
|
-
tools: [
|
|
79
|
-
asTool(researcher, { description: "Delegate research to a specialist." }),
|
|
80
|
-
],
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
const childEvents: string[] = [];
|
|
84
|
-
const toolResult = await runAgent(lead, {
|
|
85
|
-
input: "Give me a one-line summary of Bun.",
|
|
86
|
-
onEvent: (e) => {
|
|
87
|
-
if (e.type === "agent.child")
|
|
88
|
-
childEvents.push(`${e.agent}@depth${e.depth}: ${e.event.type}`);
|
|
89
|
-
},
|
|
90
|
-
});
|
|
91
|
-
console.log("\n=== sub-agent-as-tool ===");
|
|
92
|
-
console.log("answer:", toolResult.output);
|
|
93
|
-
console.log("child events:", childEvents.length, "(e.g.", childEvents[0] + ")");
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Example 2 — terminal coder.
|
|
3
|
-
*
|
|
4
|
-
* A coding terminal streams tokens to the screen, persists the conversation in a
|
|
5
|
-
* session (so history carries across prompts), and lets the agent call
|
|
6
|
-
* file/command tools. Mirrors README "Example 2".
|
|
7
|
-
*
|
|
8
|
-
* Run it: `bun examples/terminal-coder.ts`
|
|
9
|
-
*
|
|
10
|
-
* Uses a scripted provider so it runs offline. In an app, swap in a real
|
|
11
|
-
* provider such as `createOpenAI({ apiKey, model })`.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
import { defineAgent } from "@infinityi/engine-lib/agent";
|
|
15
|
-
import { runAgent } from "@infinityi/engine-lib/execution";
|
|
16
|
-
import { createSession } from "@infinityi/engine-lib/session";
|
|
17
|
-
import { defineTool } from "@infinityi/engine-lib/tools";
|
|
18
|
-
import { s } from "@infinityi/engine-lib/schema";
|
|
19
|
-
import {
|
|
20
|
-
scriptedProvider,
|
|
21
|
-
textResult,
|
|
22
|
-
toolCallResult,
|
|
23
|
-
} from "@infinityi/engine-lib/testing";
|
|
24
|
-
|
|
25
|
-
const readFile = defineTool({
|
|
26
|
-
name: "read_file",
|
|
27
|
-
description: "Read a file from the workspace.",
|
|
28
|
-
parameters: s.object({ path: s.string() }),
|
|
29
|
-
execute: ({ path }) => ({
|
|
30
|
-
ok: true,
|
|
31
|
-
content: `// ${path}\nexport const answer = 42;\n`,
|
|
32
|
-
}),
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
const runCommand = defineTool({
|
|
36
|
-
name: "run_command",
|
|
37
|
-
description: "Run a shell command in the workspace.",
|
|
38
|
-
parameters: s.object({ command: s.string() }),
|
|
39
|
-
execute: ({ command }) => ({ ok: true, content: `$ ${command}\nok` }),
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
const provider = scriptedProvider([
|
|
43
|
-
toolCallResult([
|
|
44
|
-
{ id: "c1", name: "read_file", arguments: { path: "src/index.ts" } },
|
|
45
|
-
]),
|
|
46
|
-
textResult(
|
|
47
|
-
"`src/index.ts` exports `answer = 42`. Want me to add a test for it?",
|
|
48
|
-
),
|
|
49
|
-
]);
|
|
50
|
-
|
|
51
|
-
const coder = defineAgent({
|
|
52
|
-
name: "terminal-coder",
|
|
53
|
-
provider,
|
|
54
|
-
instructions:
|
|
55
|
-
"You are a coding assistant operating inside the user's terminal.",
|
|
56
|
-
tools: [readFile, runCommand],
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
// One terminal tab = one session, so history persists across prompts (backed by
|
|
60
|
-
// the built-in InMemorySessionStore here).
|
|
61
|
-
const session = createSession({ id: "tab-1" });
|
|
62
|
-
|
|
63
|
-
async function onUserPrompt(prompt: string) {
|
|
64
|
-
process.stdout.write(`\n> ${prompt}\n`);
|
|
65
|
-
const stream = runAgent(coder, { input: prompt, session, stream: true });
|
|
66
|
-
for await (const event of stream) {
|
|
67
|
-
if (event.type === "token") process.stdout.write(event.delta); // live output
|
|
68
|
-
if (event.type === "tool.call")
|
|
69
|
-
process.stdout.write(`\n ↻ ${event.name}\n`); // tool spinner
|
|
70
|
-
}
|
|
71
|
-
const result = await stream.completed;
|
|
72
|
-
// `result.messages` is the full run history (incl. the system instruction);
|
|
73
|
-
// the session persists the new turn's messages, which `session.messages()` replays.
|
|
74
|
-
const persisted = await session.messages();
|
|
75
|
-
process.stdout.write(
|
|
76
|
-
`\n (turn done — ${result.messages.length} messages in history, ${persisted.length} persisted)\n`,
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
await onUserPrompt("What does src/index.ts export?");
|