@infinityi/engine-lib 1.0.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +81 -445
- package/dist/agent/index.js +14 -8
- package/dist/context/index.d.ts +1 -1
- package/dist/context/index.js +8 -5
- package/dist/context/providers.d.ts +3 -3
- package/dist/context/types.d.ts +16 -1
- package/dist/errors.d.ts +18 -0
- package/dist/errors.js +6 -1
- package/dist/events/index.js +2 -1
- package/dist/execution/index.js +9 -4
- package/dist/execution/types.d.ts +14 -0
- package/dist/index-37x76zdn.js +4 -0
- package/dist/index-4c15ysa8.js +84 -0
- package/dist/{index-pwr8179t.js → index-7nb9qwa1.js} +23 -14
- package/dist/{index-jxgj4z08.js → index-9egrqxkf.js} +4 -0
- package/dist/index-9rr5dkzh.js +0 -0
- package/dist/{index-w34cbktd.js → index-a67ej96j.js} +1 -0
- package/dist/{index-64tt9696.js → index-aed6fe4z.js} +3 -3
- package/dist/{index-7690reng.js → index-ajr3nk10.js} +15 -1
- package/dist/index-c6kgts41.js +0 -0
- package/dist/{index-xsv43c5j.js → index-e14g2e48.js} +2 -2
- package/dist/index-k0q7x4mz.js +54 -0
- package/dist/index-mnx5mqbs.js +102 -0
- package/dist/index-mr1hs98z.js +661 -0
- package/dist/{index-yrqrxwjt.js → index-nvdsr51v.js} +4 -38
- package/dist/{index-jp2b31xs.js → index-vwcyawfk.js} +4 -4
- package/dist/index-ycjsqfpq.js +39 -0
- package/dist/{index-bqg01r42.js → index-zdggff0y.js} +183 -180
- package/dist/index.d.ts +2 -2
- package/dist/index.js +49 -38
- package/dist/lifecycle/index.js +2 -0
- package/dist/messages/index.js +1 -0
- package/dist/providers/index.js +5 -4
- package/dist/retrieval/chunking.d.ts +8 -0
- package/dist/retrieval/context.d.ts +4 -0
- package/dist/retrieval/index.d.ts +19 -0
- package/dist/retrieval/index.js +747 -0
- package/dist/retrieval/loaders.d.ts +8 -0
- package/dist/retrieval/memory.d.ts +29 -0
- package/dist/retrieval/retriever.d.ts +8 -0
- package/dist/retrieval/types.d.ts +253 -0
- package/dist/retrieval/utils.d.ts +11 -0
- package/dist/retrieval/vector-store.d.ts +13 -0
- package/dist/runtime/index.js +2 -1
- package/dist/schema/index.js +10 -4
- package/dist/session/index.js +1 -0
- package/dist/session-stores/codec.d.ts +8 -0
- package/dist/session-stores/forge-data.d.ts +43 -0
- package/dist/session-stores/hooks.d.ts +4 -0
- package/dist/session-stores/ids.d.ts +3 -0
- package/dist/session-stores/index.d.ts +20 -0
- package/dist/session-stores/index.js +1382 -0
- package/dist/session-stores/jsonl.d.ts +26 -0
- package/dist/session-stores/redis.d.ts +45 -0
- package/dist/session-stores/types.d.ts +45 -0
- package/dist/session-stores/versioning.d.ts +6 -0
- package/dist/testing/conformance.js +5 -4
- package/dist/testing/index.js +1 -0
- package/dist/tools/index.js +5 -3
- package/dist/tools-fs/define.d.ts +2 -0
- package/dist/tools-fs/files.d.ts +40 -0
- package/dist/tools-fs/git.d.ts +14 -0
- package/dist/tools-fs/index.d.ts +19 -0
- package/dist/tools-fs/index.js +1695 -0
- package/dist/tools-fs/policy.d.ts +32 -0
- package/dist/tools-fs/schemas.d.ts +31 -0
- package/dist/tools-fs/search.d.ts +45 -0
- package/dist/tools-fs/symbols.d.ts +12 -0
- package/dist/tools-fs/types.d.ts +151 -0
- package/dist/tools-http/client.d.ts +12 -0
- package/dist/tools-http/define.d.ts +12 -0
- package/dist/tools-http/events.d.ts +22 -0
- package/dist/tools-http/index.d.ts +24 -0
- package/dist/tools-http/index.js +18 -0
- package/dist/tools-http/policy.d.ts +52 -0
- package/dist/tools-http/types.d.ts +116 -0
- package/dist/tools-shell/define.d.ts +23 -0
- package/dist/tools-shell/events.d.ts +38 -0
- package/dist/tools-shell/exec.d.ts +37 -0
- package/dist/tools-shell/index.d.ts +30 -0
- package/dist/tools-shell/index.js +327 -0
- package/dist/tools-shell/policy.d.ts +42 -0
- package/dist/tools-shell/types.d.ts +121 -0
- package/dist/tools-web/define.d.ts +11 -0
- package/dist/tools-web/html.d.ts +22 -0
- package/dist/tools-web/index.d.ts +21 -0
- package/dist/tools-web/index.js +472 -0
- package/dist/tools-web/types.d.ts +81 -0
- package/docs/README.md +58 -10
- package/docs/api/.nojekyll +1 -0
- package/docs/api/assets/hierarchy.js +1 -0
- package/docs/api/assets/highlight.css +99 -0
- package/docs/api/assets/icons.js +18 -0
- package/docs/api/assets/icons.svg +1 -0
- package/docs/api/assets/main.js +60 -0
- package/docs/api/assets/navigation.js +1 -0
- package/docs/api/assets/search.js +1 -0
- package/docs/api/assets/style.css +1633 -0
- package/docs/api/classes/errors.AgentError.html +47 -0
- package/docs/api/classes/errors.CancelledError.html +46 -0
- package/docs/api/classes/errors.ContextWindowError.html +48 -0
- package/docs/api/classes/errors.ExecutionError.html +46 -0
- package/docs/api/classes/errors.FilesystemPolicyError.html +48 -0
- package/docs/api/classes/errors.MaxHandoffsExceededError.html +47 -0
- package/docs/api/classes/errors.MaxStepsExceededError.html +47 -0
- package/docs/api/classes/errors.ProviderError.html +47 -0
- package/docs/api/classes/errors.SchemaValidationError.html +47 -0
- package/docs/api/classes/errors.ShellPolicyError.html +50 -0
- package/docs/api/classes/errors.ToolError.html +47 -0
- package/docs/api/classes/errors.ToolValidationError.html +48 -0
- package/docs/api/classes/index.InMemorySessionStore.html +11 -0
- package/docs/api/classes/index.Secret.html +20 -0
- package/docs/api/classes/providers.StreamAccumulator.html +8 -0
- package/docs/api/classes/session-stores.FilesystemJsonlSessionStore.html +13 -0
- package/docs/api/classes/session-stores.ForgeDataSessionStore.html +14 -0
- package/docs/api/classes/session-stores.RedisSessionStore.html +12 -0
- package/docs/api/classes/tools-http.HttpPolicyError.html +41 -0
- package/docs/api/functions/agent.createToolRegistry.html +3 -0
- package/docs/api/functions/agent.handoffProviderTools.html +3 -0
- package/docs/api/functions/agent.handoffToolName.html +2 -0
- package/docs/api/functions/agent.resolveHandoffTargets.html +8 -0
- package/docs/api/functions/context.applyContextWindow.html +5 -0
- package/docs/api/functions/context.estimateTokens.html +3 -0
- package/docs/api/functions/context.resolveContext.html +5 -0
- package/docs/api/functions/events.createRunTelemetry.html +3 -0
- package/docs/api/functions/events.eventFields.html +4 -0
- package/docs/api/functions/events.eventPayload.html +5 -0
- package/docs/api/functions/execution.addUsage.html +2 -0
- package/docs/api/functions/execution.emptyUsage.html +2 -0
- package/docs/api/functions/index.asSchema.html +4 -0
- package/docs/api/functions/index.asTool.html +8 -0
- package/docs/api/functions/index.assistant.html +2 -0
- package/docs/api/functions/index.createAgentRegistry.html +5 -0
- package/docs/api/functions/index.createAnthropic.html +5 -0
- package/docs/api/functions/index.createEventHub.html +2 -0
- package/docs/api/functions/index.createGoogle.html +5 -0
- package/docs/api/functions/index.createOpenAI.html +5 -0
- package/docs/api/functions/index.createOpenAICompatible.html +7 -0
- package/docs/api/functions/index.createSession.html +3 -0
- package/docs/api/functions/index.defineAgent.html +7 -0
- package/docs/api/functions/index.defineTool.html +7 -0
- package/docs/api/functions/index.dynamicContext.html +2 -0
- package/docs/api/functions/index.fromJsonSchema.html +3 -0
- package/docs/api/functions/index.isSecret.html +4 -0
- package/docs/api/functions/index.loggingSubscriber.html +4 -0
- package/docs/api/functions/index.messageBusSubscriber.html +6 -0
- package/docs/api/functions/index.normalizeContent.html +2 -0
- package/docs/api/functions/index.resolveSecret.html +4 -0
- package/docs/api/functions/index.runAgent.html +19 -0
- package/docs/api/functions/index.staticContext.html +3 -0
- package/docs/api/functions/index.summarizeOldest.html +4 -0
- package/docs/api/functions/index.system.html +2 -0
- package/docs/api/functions/index.text.html +2 -0
- package/docs/api/functions/index.toJsonSchema.html +2 -0
- package/docs/api/functions/index.toolResult.html +2 -0
- package/docs/api/functions/index.truncateOldest.html +5 -0
- package/docs/api/functions/index.user.html +2 -0
- package/docs/api/functions/index.validateJsonSchema.html +3 -0
- package/docs/api/functions/lifecycle.agentRuntimeComponent.html +5 -0
- package/docs/api/functions/providers.collectStream.html +2 -0
- package/docs/api/functions/providers.createProvider.html +4 -0
- package/docs/api/functions/providers.createProviderHttp.html +3 -0
- package/docs/api/functions/providers.defaultProviderResilience.html +3 -0
- package/docs/api/functions/providers.openSseStream.html +6 -0
- package/docs/api/functions/providers.parseSse.html +2 -0
- package/docs/api/functions/providers.toProviderError.html +2 -0
- package/docs/api/functions/session-stores.createPostgresSessionStore.html +1 -0
- package/docs/api/functions/session-stores.createSqliteSessionStore.html +1 -0
- package/docs/api/functions/session-stores.isCloseableSessionStore.html +1 -0
- package/docs/api/functions/session-stores.isVersionedSessionStore.html +1 -0
- package/docs/api/functions/session-stores.migrateSessionStore.html +1 -0
- package/docs/api/functions/session-stores.withSessionStoreHooks.html +2 -0
- package/docs/api/functions/testing.byteStreamOf.html +2 -0
- package/docs/api/functions/testing.collectProviderStream.html +2 -0
- package/docs/api/functions/testing.conversation.html +2 -0
- package/docs/api/functions/testing.expectValid.html +3 -0
- package/docs/api/functions/testing.inMemorySessionStore.html +2 -0
- package/docs/api/functions/testing.jsonFetch.html +3 -0
- package/docs/api/functions/testing.mockProvider.html +3 -0
- package/docs/api/functions/testing.scriptedProvider.html +4 -0
- package/docs/api/functions/testing.sseFetch.html +3 -0
- package/docs/api/functions/testing.textResult.html +3 -0
- package/docs/api/functions/testing.toolCallResult.html +3 -0
- package/docs/api/functions/testing_conformance.runProviderConformance.html +3 -0
- package/docs/api/functions/tools-fs.filesystemTools.html +1 -0
- package/docs/api/functions/tools-http.createHttpToolClient.html +2 -0
- package/docs/api/functions/tools-http.httpTools.html +2 -0
- package/docs/api/functions/tools-shell.shellTools.html +4 -0
- package/docs/api/functions/tools-web.webTools.html +2 -0
- package/docs/api/functions/tools.renderToolContent.html +6 -0
- package/docs/api/functions/tools.toProviderTool.html +3 -0
- package/docs/api/functions/tools.toToolResultMessage.html +4 -0
- package/docs/api/hierarchy.html +1 -0
- package/docs/api/index.html +1 -0
- package/docs/api/interfaces/agent.ToolRegistry.html +8 -0
- package/docs/api/interfaces/errors.SchemaIssue.html +4 -0
- package/docs/api/interfaces/events.RunTelemetry.html +10 -0
- package/docs/api/interfaces/events.SpanHandle.html +6 -0
- package/docs/api/interfaces/index.AgentDefinition.html +16 -0
- package/docs/api/interfaces/index.AgentHooks.html +21 -0
- package/docs/api/interfaces/index.AgentRegistry.html +16 -0
- package/docs/api/interfaces/index.AnthropicOptions.html +13 -0
- package/docs/api/interfaces/index.AsToolOptions.html +13 -0
- package/docs/api/interfaces/index.CompletionRequest.html +30 -0
- package/docs/api/interfaces/index.CompletionResult.html +14 -0
- package/docs/api/interfaces/index.ContextItem.html +6 -0
- package/docs/api/interfaces/index.ContextProvider.html +5 -0
- package/docs/api/interfaces/index.ContextStrategy.html +8 -0
- package/docs/api/interfaces/index.ContextStrategyContext.html +8 -0
- package/docs/api/interfaces/index.ContextWindowOptions.html +8 -0
- package/docs/api/interfaces/index.CreateSessionOptions.html +10 -0
- package/docs/api/interfaces/index.EngineContext.html +10 -0
- package/docs/api/interfaces/index.EventHub.html +4 -0
- package/docs/api/interfaces/index.EventHubOptions.html +8 -0
- package/docs/api/interfaces/index.GenerationSettings.html +12 -0
- package/docs/api/interfaces/index.GoogleOptions.html +11 -0
- package/docs/api/interfaces/index.ImagePart.html +5 -0
- package/docs/api/interfaces/index.InstructionContext.html +9 -0
- package/docs/api/interfaces/index.JsonSchema.html +18 -0
- package/docs/api/interfaces/index.LoggingSubscriberOptions.html +4 -0
- package/docs/api/interfaces/index.Message.html +8 -0
- package/docs/api/interfaces/index.MessageBusSubscriberOptions.html +4 -0
- package/docs/api/interfaces/index.OpenAICompatibleOptions.html +16 -0
- package/docs/api/interfaces/index.OpenAIOptions.html +16 -0
- package/docs/api/interfaces/index.Provider.html +11 -0
- package/docs/api/interfaces/index.ProviderCapabilities.html +9 -0
- package/docs/api/interfaces/index.ProviderTool.html +6 -0
- package/docs/api/interfaces/index.ResponseSchema.html +6 -0
- package/docs/api/interfaces/index.RunBridge.html +10 -0
- package/docs/api/interfaces/index.RunOptions.html +39 -0
- package/docs/api/interfaces/index.RunResult.html +20 -0
- package/docs/api/interfaces/index.Schema.html +13 -0
- package/docs/api/interfaces/index.Session.html +13 -0
- package/docs/api/interfaces/index.SessionState.html +5 -0
- package/docs/api/interfaces/index.SessionStore.html +15 -0
- package/docs/api/interfaces/index.TextPart.html +4 -0
- package/docs/api/interfaces/index.ToolCall.html +9 -0
- package/docs/api/interfaces/index.ToolCallPart.html +6 -0
- package/docs/api/interfaces/index.ToolContext.html +21 -0
- package/docs/api/interfaces/index.ToolDefinition.html +14 -0
- package/docs/api/interfaces/index.ToolFailure.html +9 -0
- package/docs/api/interfaces/index.ToolResultPart.html +8 -0
- package/docs/api/interfaces/index.ToolSpec.html +6 -0
- package/docs/api/interfaces/index.ToolSuccess.html +6 -0
- package/docs/api/interfaces/index.Usage.html +9 -0
- package/docs/api/interfaces/lifecycle.AgentRuntimeOptions.html +17 -0
- package/docs/api/interfaces/providers.AdapterSpec.html +17 -0
- package/docs/api/interfaces/providers.ProviderHttpOptions.html +14 -0
- package/docs/api/interfaces/providers.SseMessage.html +6 -0
- package/docs/api/interfaces/providers.SseRequest.html +8 -0
- package/docs/api/interfaces/runtime.Logger.html +22 -0
- package/docs/api/interfaces/runtime.Telemetry.html +9 -0
- package/docs/api/interfaces/schema.OptionalSchema.html +13 -0
- package/docs/api/interfaces/session-stores.CloseableSessionStore.html +11 -0
- package/docs/api/interfaces/session-stores.CreatePostgresSessionStoreOptions.html +6 -0
- package/docs/api/interfaces/session-stores.CreateSqliteSessionStoreOptions.html +7 -0
- package/docs/api/interfaces/session-stores.FilesystemJsonlSessionStoreOptions.html +3 -0
- package/docs/api/interfaces/session-stores.ForgeDataSessionStoreOptions.html +5 -0
- package/docs/api/interfaces/session-stores.RedisSessionStoreClient.html +9 -0
- package/docs/api/interfaces/session-stores.RedisSessionStoreOptions.html +4 -0
- package/docs/api/interfaces/session-stores.RedisSessionStoreTransaction.html +6 -0
- package/docs/api/interfaces/session-stores.SessionArchiveRecord.html +7 -0
- package/docs/api/interfaces/session-stores.SessionArchiver.html +2 -0
- package/docs/api/interfaces/session-stores.SessionCompactionResult.html +3 -0
- package/docs/api/interfaces/session-stores.SessionCompactor.html +3 -0
- package/docs/api/interfaces/session-stores.SessionStoreCodec.html +6 -0
- package/docs/api/interfaces/session-stores.SessionStoreHookContext.html +3 -0
- package/docs/api/interfaces/session-stores.SessionStoreHooks.html +3 -0
- package/docs/api/interfaces/session-stores.VersionedSessionStore.html +11 -0
- package/docs/api/interfaces/testing.MockProviderOptions.html +12 -0
- package/docs/api/interfaces/testing.RecordedCall.html +4 -0
- package/docs/api/interfaces/testing.RecordingFetch.html +4 -0
- package/docs/api/interfaces/testing_conformance.ConformanceFixtures.html +12 -0
- package/docs/api/interfaces/testing_conformance.ConformanceOptions.html +10 -0
- package/docs/api/interfaces/testing_conformance.ConformanceTestApi.html +4 -0
- package/docs/api/interfaces/testing_conformance.ProviderIO.html +7 -0
- package/docs/api/interfaces/tools-fs.ApplyPatchArgs.html +6 -0
- package/docs/api/interfaces/tools-fs.DiffStatusArgs.html +5 -0
- package/docs/api/interfaces/tools-fs.EditRangeArgs.html +7 -0
- package/docs/api/interfaces/tools-fs.EditReplaceArgs.html +7 -0
- package/docs/api/interfaces/tools-fs.FilesystemTools.html +13 -0
- package/docs/api/interfaces/tools-fs.FilesystemToolsConfig.html +12 -0
- package/docs/api/interfaces/tools-fs.FindFilesArgs.html +7 -0
- package/docs/api/interfaces/tools-fs.OpenWindowArgs.html +5 -0
- package/docs/api/interfaces/tools-fs.ReadArgs.html +9 -0
- package/docs/api/interfaces/tools-fs.RepoMapArgs.html +7 -0
- package/docs/api/interfaces/tools-fs.SearchSemanticArgs.html +8 -0
- package/docs/api/interfaces/tools-fs.SearchTextArgs.html +11 -0
- package/docs/api/interfaces/tools-fs.SymbolInfo.html +7 -0
- package/docs/api/interfaces/tools-fs.SymbolsArgs.html +5 -0
- package/docs/api/interfaces/tools-fs.ValidationCommandRequest.html +4 -0
- package/docs/api/interfaces/tools-fs.ValidationCommandResult.html +6 -0
- package/docs/api/interfaces/tools-fs.ValidationOptions.html +4 -0
- package/docs/api/interfaces/tools-fs.WriteFileArgs.html +6 -0
- package/docs/api/interfaces/tools-http.HeaderEntry.html +4 -0
- package/docs/api/interfaces/tools-http.HttpClientRequest.html +11 -0
- package/docs/api/interfaces/tools-http.HttpPolicy.html +13 -0
- package/docs/api/interfaces/tools-http.HttpRequestResult.html +17 -0
- package/docs/api/interfaces/tools-http.HttpRetryOptions.html +10 -0
- package/docs/api/interfaces/tools-http.HttpToolClient.html +5 -0
- package/docs/api/interfaces/tools-http.HttpTools.html +4 -0
- package/docs/api/interfaces/tools-http.HttpToolsConfig.html +38 -0
- package/docs/api/interfaces/tools-shell.ApprovalDecision.html +5 -0
- package/docs/api/interfaces/tools-shell.CommandRequest.html +14 -0
- package/docs/api/interfaces/tools-shell.CommandResult.html +21 -0
- package/docs/api/interfaces/tools-shell.EnvPolicy.html +9 -0
- package/docs/api/interfaces/tools-shell.ShellPolicy.html +7 -0
- package/docs/api/interfaces/tools-shell.ShellTools.html +6 -0
- package/docs/api/interfaces/tools-shell.ShellToolsConfig.html +26 -0
- package/docs/api/interfaces/tools-web.Citation.html +6 -0
- package/docs/api/interfaces/tools-web.SearchProvider.html +3 -0
- package/docs/api/interfaces/tools-web.SearchRequest.html +4 -0
- package/docs/api/interfaces/tools-web.SearchResult.html +7 -0
- package/docs/api/interfaces/tools-web.SourceMetadata.html +10 -0
- package/docs/api/interfaces/tools-web.WebTools.html +6 -0
- package/docs/api/interfaces/tools-web.WebToolsConfig.html +56 -0
- package/docs/api/modules/agent.html +5 -0
- package/docs/api/modules/context.html +5 -0
- package/docs/api/modules/errors.html +8 -0
- package/docs/api/modules/events.html +16 -0
- package/docs/api/modules/execution.html +4 -0
- package/docs/api/modules/index.html +16 -0
- package/docs/api/modules/lifecycle.html +6 -0
- package/docs/api/modules/messages.html +3 -0
- package/docs/api/modules/providers.html +10 -0
- package/docs/api/modules/runtime.html +4 -0
- package/docs/api/modules/schema.html +5 -0
- package/docs/api/modules/session-stores.html +6 -0
- package/docs/api/modules/session.html +4 -0
- package/docs/api/modules/testing.html +4 -0
- package/docs/api/modules/testing_conformance.html +21 -0
- package/docs/api/modules/tools-fs.html +9 -0
- package/docs/api/modules/tools-http.html +8 -0
- package/docs/api/modules/tools-shell.html +12 -0
- package/docs/api/modules/tools-web.html +7 -0
- package/docs/api/modules/tools.html +4 -0
- package/docs/api/types/events.Attrs.html +2 -0
- package/docs/api/types/index.AnyRunOptions.html +3 -0
- package/docs/api/types/index.BufferedRunOptions.html +2 -0
- package/docs/api/types/index.ContentPart.html +2 -0
- package/docs/api/types/index.FinishReason.html +2 -0
- package/docs/api/types/index.Infer.html +2 -0
- package/docs/api/types/index.Instructions.html +5 -0
- package/docs/api/types/index.LogLevel.html +2 -0
- package/docs/api/types/index.Role.html +2 -0
- package/docs/api/types/index.RunEvent.html +30 -0
- package/docs/api/types/index.RunHandle.html +7 -0
- package/docs/api/types/index.RunInput.html +2 -0
- package/docs/api/types/index.RunSubscriber.html +4 -0
- package/docs/api/types/index.SafeParseResult.html +2 -0
- package/docs/api/types/index.StreamEvent.html +8 -0
- package/docs/api/types/index.StreamingRunOptions.html +2 -0
- package/docs/api/types/index.TelemetryHandle.html +2 -0
- package/docs/api/types/index.TokenCounter.html +2 -0
- package/docs/api/types/index.ToolChoice.html +2 -0
- package/docs/api/types/index.ToolResult.html +2 -0
- package/docs/api/types/lifecycle.ProviderProbe.html +2 -0
- package/docs/api/types/session-stores.SessionStoreHookOperation.html +1 -0
- package/docs/api/types/testing_conformance.MakeProvider.html +2 -0
- package/docs/api/types/tools-fs.SymbolKind.html +1 -0
- package/docs/api/types/tools-http.HostPattern.html +2 -0
- package/docs/api/types/tools-shell.CommandPattern.html +2 -0
- package/docs/api/types/tools-web.RobotsPolicy.html +2 -0
- package/docs/api/variables/events.SPAN_PROVIDER.html +2 -0
- package/docs/api/variables/events.SPAN_RUN.html +2 -0
- package/docs/api/variables/events.SPAN_TOOL.html +2 -0
- package/docs/api/variables/execution.DEFAULT_MAX_HANDOFFS.html +2 -0
- package/docs/api/variables/execution.DEFAULT_MAX_STEPS.html +2 -0
- package/docs/api/variables/index.s.html +11 -0
- package/docs/api/variables/providers.DEFAULT_TIMEOUT_MS.html +2 -0
- package/docs/api/variables/session-stores.SESSION_STORE_SCHEMA_VERSION.html +1 -0
- package/docs/api/variables/session-stores.jsonSessionStoreCodec.html +2 -0
- package/docs/api/variables/tools-http.HTTP_EVENT.html +2 -0
- package/docs/api/variables/tools-shell.SHELL_EVENT.html +2 -0
- package/docs/events-and-telemetry.md +68 -0
- package/docs/execution.md +63 -0
- package/docs/getting-started.md +73 -0
- package/docs/multi-agent.md +52 -0
- package/docs/optional-tool-packs.md +93 -0
- package/docs/providers.md +68 -0
- package/docs/retrieval.md +83 -0
- package/docs/sessions-and-context.md +82 -0
- package/docs/testing-and-lifecycle.md +60 -0
- package/docs/tools.md +69 -0
- package/examples/01-minimal-agent.ts +19 -0
- package/examples/02-custom-tool.ts +32 -0
- package/examples/03-streaming.ts +46 -0
- package/examples/04-sessions-context.ts +40 -0
- package/examples/05-events-subscribers.ts +35 -0
- package/examples/06-multi-agent-handoff.ts +27 -0
- package/examples/07-sub-agent-tool.ts +26 -0
- package/examples/08-testing-agent.ts +31 -0
- package/examples/09-tools-filesystem.ts +49 -0
- package/examples/10-tools-http-web.ts +74 -0
- package/examples/11-shell-tools.ts +39 -0
- package/examples/12-provider-openai.ts +24 -0
- package/examples/13-lifecycle.ts +37 -0
- package/examples/14-retrieval.ts +65 -0
- package/examples/incident-analysis.ts +39 -87
- package/package.json +78 -4
- package/dist/index-02s1fjxr.js +0 -226
- package/examples/README.md +0 -24
- package/examples/lifecycle.ts +0 -53
- package/examples/multi-agent.ts +0 -93
- package/examples/terminal-coder.ts +0 -80
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import {
|
|
2
|
+
s
|
|
3
|
+
} from "../index-mnx5mqbs.js";
|
|
4
|
+
import"../index-4c15ysa8.js";
|
|
5
|
+
import {
|
|
6
|
+
ShellPolicyError
|
|
7
|
+
} from "../index-ajr3nk10.js";
|
|
8
|
+
import {
|
|
9
|
+
defineTool
|
|
10
|
+
} from "../index-a67ej96j.js";
|
|
11
|
+
import"../index-37x76zdn.js";
|
|
12
|
+
|
|
13
|
+
// src/tools-shell/events.ts
|
|
14
|
+
var SHELL_EVENT = {
|
|
15
|
+
policy: "shell.policy",
|
|
16
|
+
approval: "shell.approval",
|
|
17
|
+
execStart: "shell.exec.start",
|
|
18
|
+
execChunk: "shell.exec.chunk",
|
|
19
|
+
execEnd: "shell.exec.end"
|
|
20
|
+
};
|
|
21
|
+
function emit(ctx, name, data) {
|
|
22
|
+
ctx.run?.emit({ type: "custom", name, data });
|
|
23
|
+
}
|
|
24
|
+
function emitPolicy(ctx, decision, req, reason) {
|
|
25
|
+
emit(ctx, SHELL_EVENT.policy, {
|
|
26
|
+
decision,
|
|
27
|
+
command: req.command,
|
|
28
|
+
args: req.args,
|
|
29
|
+
mode: req.mode,
|
|
30
|
+
...reason !== undefined ? { reason } : {}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
function emitApproval(ctx, status, req, reason) {
|
|
34
|
+
emit(ctx, SHELL_EVENT.approval, {
|
|
35
|
+
status,
|
|
36
|
+
command: req.command,
|
|
37
|
+
args: req.args,
|
|
38
|
+
cwd: req.cwd,
|
|
39
|
+
mode: req.mode,
|
|
40
|
+
...reason !== undefined ? { reason } : {}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
function emitExecStart(ctx, req) {
|
|
44
|
+
emit(ctx, SHELL_EVENT.execStart, {
|
|
45
|
+
command: req.command,
|
|
46
|
+
args: req.args,
|
|
47
|
+
cwd: req.cwd,
|
|
48
|
+
mode: req.mode,
|
|
49
|
+
timeoutMs: req.timeoutMs
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
function emitExecChunk(ctx, stream, text) {
|
|
53
|
+
emit(ctx, SHELL_EVENT.execChunk, { stream, text });
|
|
54
|
+
}
|
|
55
|
+
function emitExecEnd(ctx, result) {
|
|
56
|
+
emit(ctx, SHELL_EVENT.execEnd, {
|
|
57
|
+
command: result.command,
|
|
58
|
+
exitCode: result.exitCode,
|
|
59
|
+
signal: result.signal,
|
|
60
|
+
timedOut: result.timedOut,
|
|
61
|
+
durationMs: result.durationMs,
|
|
62
|
+
stdoutTruncated: result.stdoutTruncated,
|
|
63
|
+
stderrTruncated: result.stderrTruncated
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
function emitExecError(ctx, req, error) {
|
|
67
|
+
emit(ctx, SHELL_EVENT.execEnd, {
|
|
68
|
+
command: req.command,
|
|
69
|
+
exitCode: null,
|
|
70
|
+
signal: null,
|
|
71
|
+
timedOut: false,
|
|
72
|
+
error
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// src/tools-shell/exec.ts
|
|
77
|
+
async function collectStream(stream, which, maxBytes, onChunk) {
|
|
78
|
+
if (stream === undefined)
|
|
79
|
+
return { text: "", truncated: false };
|
|
80
|
+
const reader = stream.getReader();
|
|
81
|
+
const chunkDecoder = new TextDecoder;
|
|
82
|
+
const kept = [];
|
|
83
|
+
let keptBytes = 0;
|
|
84
|
+
let truncated = false;
|
|
85
|
+
try {
|
|
86
|
+
for (;; ) {
|
|
87
|
+
const { done, value } = await reader.read();
|
|
88
|
+
if (done)
|
|
89
|
+
break;
|
|
90
|
+
if (value === undefined || value.length === 0)
|
|
91
|
+
continue;
|
|
92
|
+
if (onChunk !== undefined) {
|
|
93
|
+
onChunk({ stream: which, text: chunkDecoder.decode(value, { stream: true }) });
|
|
94
|
+
}
|
|
95
|
+
if (keptBytes < maxBytes) {
|
|
96
|
+
const remaining = maxBytes - keptBytes;
|
|
97
|
+
if (value.length <= remaining) {
|
|
98
|
+
kept.push(value);
|
|
99
|
+
keptBytes += value.length;
|
|
100
|
+
} else {
|
|
101
|
+
kept.push(value.subarray(0, remaining));
|
|
102
|
+
keptBytes = maxBytes;
|
|
103
|
+
truncated = true;
|
|
104
|
+
}
|
|
105
|
+
} else {
|
|
106
|
+
truncated = true;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (onChunk !== undefined) {
|
|
110
|
+
const tail = chunkDecoder.decode();
|
|
111
|
+
if (tail.length > 0)
|
|
112
|
+
onChunk({ stream: which, text: tail });
|
|
113
|
+
}
|
|
114
|
+
} finally {
|
|
115
|
+
reader.releaseLock();
|
|
116
|
+
}
|
|
117
|
+
const buf = new Uint8Array(keptBytes);
|
|
118
|
+
let offset = 0;
|
|
119
|
+
for (const part of kept) {
|
|
120
|
+
buf.set(part, offset);
|
|
121
|
+
offset += part.length;
|
|
122
|
+
}
|
|
123
|
+
return { text: new TextDecoder().decode(buf), truncated };
|
|
124
|
+
}
|
|
125
|
+
async function execCommand(opts) {
|
|
126
|
+
const startedAt = Date.now();
|
|
127
|
+
const proc = Bun.spawn({
|
|
128
|
+
cmd: [opts.command, ...opts.args],
|
|
129
|
+
cwd: opts.cwd,
|
|
130
|
+
env: opts.env,
|
|
131
|
+
stdout: "pipe",
|
|
132
|
+
stderr: "pipe"
|
|
133
|
+
});
|
|
134
|
+
let timedOut = false;
|
|
135
|
+
let abortKill = false;
|
|
136
|
+
const timer = setTimeout(() => {
|
|
137
|
+
timedOut = true;
|
|
138
|
+
proc.kill("SIGKILL");
|
|
139
|
+
}, opts.timeoutMs);
|
|
140
|
+
const onAbort = () => {
|
|
141
|
+
abortKill = true;
|
|
142
|
+
proc.kill("SIGKILL");
|
|
143
|
+
};
|
|
144
|
+
if (opts.signal !== undefined) {
|
|
145
|
+
if (opts.signal.aborted)
|
|
146
|
+
onAbort();
|
|
147
|
+
else
|
|
148
|
+
opts.signal.addEventListener("abort", onAbort, { once: true });
|
|
149
|
+
}
|
|
150
|
+
try {
|
|
151
|
+
const [out, err] = await Promise.all([
|
|
152
|
+
collectStream(proc.stdout, "stdout", opts.maxOutputBytes, opts.onChunk),
|
|
153
|
+
collectStream(proc.stderr, "stderr", opts.maxOutputBytes, opts.onChunk),
|
|
154
|
+
proc.exited
|
|
155
|
+
]);
|
|
156
|
+
return {
|
|
157
|
+
command: opts.command,
|
|
158
|
+
args: opts.args,
|
|
159
|
+
cwd: opts.cwd,
|
|
160
|
+
exitCode: proc.exitCode,
|
|
161
|
+
signal: proc.signalCode ?? null,
|
|
162
|
+
timedOut,
|
|
163
|
+
durationMs: Date.now() - startedAt,
|
|
164
|
+
stdout: out.text,
|
|
165
|
+
stderr: err.text,
|
|
166
|
+
stdoutTruncated: out.truncated,
|
|
167
|
+
stderrTruncated: err.truncated
|
|
168
|
+
};
|
|
169
|
+
} finally {
|
|
170
|
+
clearTimeout(timer);
|
|
171
|
+
opts.signal?.removeEventListener("abort", onAbort);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// src/tools-shell/policy.ts
|
|
176
|
+
import { isAbsolute, relative, resolve } from "node:path";
|
|
177
|
+
function normalizeAllowedCwds(allowedCwds) {
|
|
178
|
+
if (!Array.isArray(allowedCwds) || allowedCwds.length === 0) {
|
|
179
|
+
throw new ShellPolicyError("shellTools: `allowedCwds` must be a non-empty array of absolute paths");
|
|
180
|
+
}
|
|
181
|
+
return allowedCwds.map((dir) => {
|
|
182
|
+
if (typeof dir !== "string" || !isAbsolute(dir)) {
|
|
183
|
+
throw new ShellPolicyError(`shellTools: allowedCwds entry must be an absolute path, got ${JSON.stringify(dir)}`);
|
|
184
|
+
}
|
|
185
|
+
return resolve(dir);
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
function resolveCwd(requested, allowedRoots) {
|
|
189
|
+
const base = allowedRoots[0];
|
|
190
|
+
const abs = requested === undefined ? base : resolve(base, requested);
|
|
191
|
+
for (const root of allowedRoots) {
|
|
192
|
+
const rel = relative(root, abs);
|
|
193
|
+
if (rel === "" || !rel.startsWith("..") && !isAbsolute(rel))
|
|
194
|
+
return abs;
|
|
195
|
+
}
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
function matchesPattern(pattern, command, commandLine) {
|
|
199
|
+
if (typeof pattern === "string")
|
|
200
|
+
return pattern === command;
|
|
201
|
+
pattern.lastIndex = 0;
|
|
202
|
+
return pattern.test(commandLine);
|
|
203
|
+
}
|
|
204
|
+
function classifyCommand(command, args, policy) {
|
|
205
|
+
if (policy === undefined)
|
|
206
|
+
return { allowed: true };
|
|
207
|
+
const commandLine = [command, ...args].join(" ");
|
|
208
|
+
if (policy.deny?.some((p) => matchesPattern(p, command, commandLine))) {
|
|
209
|
+
return { allowed: false, reason: `command "${command}" is denied by policy` };
|
|
210
|
+
}
|
|
211
|
+
if (policy.allow !== undefined) {
|
|
212
|
+
const ok = policy.allow.some((p) => matchesPattern(p, command, commandLine));
|
|
213
|
+
if (!ok) {
|
|
214
|
+
return { allowed: false, reason: `command "${command}" is not in the allow-list` };
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return { allowed: true };
|
|
218
|
+
}
|
|
219
|
+
function filterEnv(processEnv, policy) {
|
|
220
|
+
const out = {};
|
|
221
|
+
const deny = new Set(policy?.deny ?? []);
|
|
222
|
+
for (const name of policy?.allow ?? []) {
|
|
223
|
+
if (deny.has(name))
|
|
224
|
+
continue;
|
|
225
|
+
const value = processEnv[name];
|
|
226
|
+
if (value !== undefined)
|
|
227
|
+
out[name] = value;
|
|
228
|
+
}
|
|
229
|
+
for (const [name, value] of Object.entries(policy?.extra ?? {})) {
|
|
230
|
+
if (deny.has(name))
|
|
231
|
+
continue;
|
|
232
|
+
out[name] = value;
|
|
233
|
+
}
|
|
234
|
+
return out;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// src/tools-shell/define.ts
|
|
238
|
+
var DEFAULT_TIMEOUT_MS = 30000;
|
|
239
|
+
var DEFAULT_MAX_TIMEOUT_MS = 600000;
|
|
240
|
+
var DEFAULT_MAX_OUTPUT_BYTES = 1e5;
|
|
241
|
+
var PARAMS = s.object({
|
|
242
|
+
command: s.string({ description: "Program to run (argv[0]). Not interpreted by a shell." }),
|
|
243
|
+
args: s.optional(s.array(s.string(), { description: "Arguments passed to the program." })),
|
|
244
|
+
cwd: s.optional(s.string({ description: "Working directory. Must resolve within an allowed root." })),
|
|
245
|
+
timeoutMs: s.optional(s.number({ int: true, description: "Kill the command after this many milliseconds." }))
|
|
246
|
+
});
|
|
247
|
+
function toDecision(value) {
|
|
248
|
+
return typeof value === "boolean" ? { approved: value } : value;
|
|
249
|
+
}
|
|
250
|
+
function shellTools(config) {
|
|
251
|
+
const allowedRoots = normalizeAllowedCwds(config.allowedCwds);
|
|
252
|
+
const defaultTimeout = config.defaultTimeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
253
|
+
const maxTimeout = config.maxTimeoutMs ?? DEFAULT_MAX_TIMEOUT_MS;
|
|
254
|
+
const maxOutputBytes = config.maxOutputBytes ?? DEFAULT_MAX_OUTPUT_BYTES;
|
|
255
|
+
const build = (mode) => {
|
|
256
|
+
const name = mode === "run" ? "run_command" : "spawn_command";
|
|
257
|
+
const description = mode === "run" ? "Run a command to completion and return its captured stdout, stderr, and exit code." : "Run a command to completion, streaming its output, and return its exit code.";
|
|
258
|
+
return defineTool({
|
|
259
|
+
name,
|
|
260
|
+
description,
|
|
261
|
+
parameters: PARAMS,
|
|
262
|
+
async execute(rawArgs, ctx) {
|
|
263
|
+
const args = rawArgs;
|
|
264
|
+
const cmdArgs = args.args ?? [];
|
|
265
|
+
const cwd = resolveCwd(args.cwd, allowedRoots);
|
|
266
|
+
if (cwd === null) {
|
|
267
|
+
const reason = `cwd ${JSON.stringify(args.cwd ?? ".")} is outside the allowed roots`;
|
|
268
|
+
emitPolicy(ctx, "deny", { command: args.command, args: cmdArgs, mode }, reason);
|
|
269
|
+
return { ok: false, error: reason };
|
|
270
|
+
}
|
|
271
|
+
const verdict = classifyCommand(args.command, cmdArgs, config.policy);
|
|
272
|
+
if (!verdict.allowed) {
|
|
273
|
+
emitPolicy(ctx, "deny", { command: args.command, args: cmdArgs, mode }, verdict.reason);
|
|
274
|
+
return { ok: false, error: verdict.reason ?? "command denied by policy" };
|
|
275
|
+
}
|
|
276
|
+
emitPolicy(ctx, "allow", { command: args.command, args: cmdArgs, mode });
|
|
277
|
+
const timeoutMs = Math.min(args.timeoutMs !== undefined && args.timeoutMs > 0 ? args.timeoutMs : defaultTimeout, maxTimeout);
|
|
278
|
+
const req = {
|
|
279
|
+
command: args.command,
|
|
280
|
+
args: cmdArgs,
|
|
281
|
+
cwd,
|
|
282
|
+
timeoutMs,
|
|
283
|
+
mode
|
|
284
|
+
};
|
|
285
|
+
if (config.requiresApproval?.(req) === true) {
|
|
286
|
+
emitApproval(ctx, "requested", req);
|
|
287
|
+
const decision = toDecision(config.approve === undefined ? false : await config.approve(req));
|
|
288
|
+
if (!decision.approved) {
|
|
289
|
+
emitApproval(ctx, "denied", req, decision.reason);
|
|
290
|
+
return {
|
|
291
|
+
ok: false,
|
|
292
|
+
error: decision.reason ?? `command "${args.command}" was not approved`
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
emitApproval(ctx, "approved", req, decision.reason);
|
|
296
|
+
}
|
|
297
|
+
const env = filterEnv(process.env, config.env);
|
|
298
|
+
emitExecStart(ctx, req);
|
|
299
|
+
let result;
|
|
300
|
+
try {
|
|
301
|
+
result = await execCommand({
|
|
302
|
+
command: req.command,
|
|
303
|
+
args: req.args,
|
|
304
|
+
cwd: req.cwd,
|
|
305
|
+
env,
|
|
306
|
+
timeoutMs,
|
|
307
|
+
maxOutputBytes,
|
|
308
|
+
...ctx.signal !== undefined ? { signal: ctx.signal } : {},
|
|
309
|
+
...mode === "spawn" ? { onChunk: (c) => emitExecChunk(ctx, c.stream, c.text) } : {}
|
|
310
|
+
});
|
|
311
|
+
} catch (err) {
|
|
312
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
313
|
+
const error = `failed to run "${req.command}": ${message}`;
|
|
314
|
+
emitExecError(ctx, req, error);
|
|
315
|
+
return { ok: false, error };
|
|
316
|
+
}
|
|
317
|
+
emitExecEnd(ctx, result);
|
|
318
|
+
return { ok: true, content: result };
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
};
|
|
322
|
+
return { runCommand: build("run"), spawnCommand: build("spawn") };
|
|
323
|
+
}
|
|
324
|
+
export {
|
|
325
|
+
shellTools,
|
|
326
|
+
SHELL_EVENT
|
|
327
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure policy functions for the `tools-shell` module: working-directory
|
|
3
|
+
* allowlisting, environment filtering, and command allow/deny classification.
|
|
4
|
+
*
|
|
5
|
+
* Everything here is side-effect-free and independently unit-testable — no
|
|
6
|
+
* spawning, no filesystem access. The tool's `execute` composes these gates
|
|
7
|
+
* before any process is created.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
import type { EnvPolicy, ShellPolicy } from "./types";
|
|
12
|
+
/** Validate `allowedCwds` at factory-build time; throws on misconfiguration. */
|
|
13
|
+
export declare function normalizeAllowedCwds(allowedCwds: readonly string[]): string[];
|
|
14
|
+
/**
|
|
15
|
+
* Resolve a requested cwd against the allowlist. Returns the absolute path when
|
|
16
|
+
* it is one of the allowed roots or a descendant; returns `null` when it
|
|
17
|
+
* escapes every root. `requested` is resolved relative to the *first* allowed
|
|
18
|
+
* root when given as a relative path, so a bare `"."` maps into the sandbox
|
|
19
|
+
* rather than the host process cwd.
|
|
20
|
+
*
|
|
21
|
+
* Containment is checked on **logical paths only** — symlinks are not resolved.
|
|
22
|
+
* A symlink placed inside an allowed root that points outside it (e.g.
|
|
23
|
+
* `/root/link -> /etc`) would pass this check. Hosts in security-sensitive
|
|
24
|
+
* contexts should pre-resolve their `allowedCwds` with `fs.realpathSync` and
|
|
25
|
+
* avoid placing outward-pointing symlinks inside their sandbox roots.
|
|
26
|
+
*/
|
|
27
|
+
export declare function resolveCwd(requested: string | undefined, allowedRoots: readonly string[]): string | null;
|
|
28
|
+
/**
|
|
29
|
+
* Decide whether a command is permitted by the allow/deny policy. Deny wins:
|
|
30
|
+
* a command matching any `deny` entry is rejected even if also allowed. When
|
|
31
|
+
* `allow` is present, the command must match at least one allow entry.
|
|
32
|
+
*/
|
|
33
|
+
export declare function classifyCommand(command: string, args: readonly string[], policy: ShellPolicy | undefined): {
|
|
34
|
+
allowed: boolean;
|
|
35
|
+
reason?: string;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Build the environment for a spawned command from the host process env and an
|
|
39
|
+
* {@link EnvPolicy}. With no `allow` list, **no** inherited variables are passed
|
|
40
|
+
* (only `extra`). `deny` strips names even when allowed; `extra` is merged last.
|
|
41
|
+
*/
|
|
42
|
+
export declare function filterEnv(processEnv: Readonly<Record<string, string | undefined>>, policy: EnvPolicy | undefined): Record<string, string>;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public types for the optional `@infinityi/engine-lib/tools-shell` module.
|
|
3
|
+
*
|
|
4
|
+
* This module is **not** part of the core library surface and is never imported
|
|
5
|
+
* by `runAgent`. It is an opt-in tool factory for hosts (coding terminals, ops
|
|
6
|
+
* agents) that need controlled command execution. Configuration lives entirely
|
|
7
|
+
* host-side — the model only ever supplies a {@link CommandRequest}, never the
|
|
8
|
+
* cwd allowlist, env filter, or policy.
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* A command the model asked to run, after schema validation but before any
|
|
14
|
+
* policy/approval gating. Passed to {@link ShellToolsConfig.requiresApproval}
|
|
15
|
+
* and {@link ShellToolsConfig.approve}, and echoed in policy/approval events.
|
|
16
|
+
*/
|
|
17
|
+
export interface CommandRequest {
|
|
18
|
+
/** Program to execute (argv[0]). */
|
|
19
|
+
readonly command: string;
|
|
20
|
+
/** Arguments passed to the program. */
|
|
21
|
+
readonly args: readonly string[];
|
|
22
|
+
/** Working directory the command will run in (already resolved to absolute). */
|
|
23
|
+
readonly cwd: string;
|
|
24
|
+
/** Effective timeout in milliseconds. */
|
|
25
|
+
readonly timeoutMs: number;
|
|
26
|
+
/** `"run_command"` (buffered) or `"spawn_command"` (streamed). */
|
|
27
|
+
readonly mode: "run" | "spawn";
|
|
28
|
+
}
|
|
29
|
+
/** The structured outcome of a command, returned as the tool's `content`. */
|
|
30
|
+
export interface CommandResult {
|
|
31
|
+
readonly command: string;
|
|
32
|
+
readonly args: readonly string[];
|
|
33
|
+
readonly cwd: string;
|
|
34
|
+
/** Process exit code, or `null` when killed by a signal (e.g. timeout). */
|
|
35
|
+
readonly exitCode: number | null;
|
|
36
|
+
/** Signal that killed the process, or `null`. */
|
|
37
|
+
readonly signal: string | null;
|
|
38
|
+
/** `true` when the process was killed because it exceeded its timeout. */
|
|
39
|
+
readonly timedOut: boolean;
|
|
40
|
+
/** Wall-clock duration in milliseconds. */
|
|
41
|
+
readonly durationMs: number;
|
|
42
|
+
/** Captured stdout (truncated to {@link ShellToolsConfig.maxOutputBytes}). */
|
|
43
|
+
readonly stdout: string;
|
|
44
|
+
/** Captured stderr (truncated to {@link ShellToolsConfig.maxOutputBytes}). */
|
|
45
|
+
readonly stderr: string;
|
|
46
|
+
/** `true` when stdout was truncated at the byte cap. */
|
|
47
|
+
readonly stdoutTruncated: boolean;
|
|
48
|
+
/** `true` when stderr was truncated at the byte cap. */
|
|
49
|
+
readonly stderrTruncated: boolean;
|
|
50
|
+
}
|
|
51
|
+
/** A pattern matched against a command — exact string (against argv[0]) or regex (against the full command line). */
|
|
52
|
+
export type CommandPattern = string | RegExp;
|
|
53
|
+
/** Allow/deny rules for which commands may run. Deny always wins. */
|
|
54
|
+
export interface ShellPolicy {
|
|
55
|
+
/**
|
|
56
|
+
* If present, a command must match at least one entry to be permitted.
|
|
57
|
+
* Omitted → all commands are permitted unless denied.
|
|
58
|
+
*/
|
|
59
|
+
readonly allow?: readonly CommandPattern[];
|
|
60
|
+
/** A command matching any entry is rejected, even if also allowed. */
|
|
61
|
+
readonly deny?: readonly CommandPattern[];
|
|
62
|
+
}
|
|
63
|
+
/** Inherited-environment filtering for spawned commands. */
|
|
64
|
+
export interface EnvPolicy {
|
|
65
|
+
/**
|
|
66
|
+
* Names of process env vars to pass through. Omitted → **no** inherited vars
|
|
67
|
+
* are passed (safest default); only {@link EnvPolicy.extra} is provided.
|
|
68
|
+
*/
|
|
69
|
+
readonly allow?: readonly string[];
|
|
70
|
+
/** Names always stripped, even if listed in {@link EnvPolicy.allow}. */
|
|
71
|
+
readonly deny?: readonly string[];
|
|
72
|
+
/** Extra vars merged on top of the (filtered) inherited set. */
|
|
73
|
+
readonly extra?: Readonly<Record<string, string>>;
|
|
74
|
+
}
|
|
75
|
+
/** A host's decision on an approval request. */
|
|
76
|
+
export interface ApprovalDecision {
|
|
77
|
+
readonly approved: boolean;
|
|
78
|
+
/** Optional human-readable reason, surfaced in the approval event and on denial. */
|
|
79
|
+
readonly reason?: string;
|
|
80
|
+
}
|
|
81
|
+
/** Host-side configuration for {@link shellTools}. Never exposed to the model. */
|
|
82
|
+
export interface ShellToolsConfig {
|
|
83
|
+
/**
|
|
84
|
+
* Absolute directory roots a command may run under. A request's `cwd` must
|
|
85
|
+
* resolve to one of these or a descendant. Required and non-empty — there is
|
|
86
|
+
* no implicit default, so a command can never run somewhere unintended.
|
|
87
|
+
*
|
|
88
|
+
* Containment is a logical-path check that does not resolve symlinks; in
|
|
89
|
+
* security-sensitive contexts pre-resolve these with `fs.realpathSync` and
|
|
90
|
+
* keep outward-pointing symlinks out of the roots.
|
|
91
|
+
*/
|
|
92
|
+
readonly allowedCwds: readonly string[];
|
|
93
|
+
/** Inherited-env filtering. Defaults to "no inherited vars". */
|
|
94
|
+
readonly env?: EnvPolicy;
|
|
95
|
+
/** Command allow/deny rules. Omitted → all commands allowed. */
|
|
96
|
+
readonly policy?: ShellPolicy;
|
|
97
|
+
/**
|
|
98
|
+
* Flag a command as destructive / requiring approval before it runs. When it
|
|
99
|
+
* returns `true`, {@link ShellToolsConfig.approve} is consulted; if `approve`
|
|
100
|
+
* is absent or denies, the command never executes.
|
|
101
|
+
*/
|
|
102
|
+
readonly requiresApproval?: (req: CommandRequest) => boolean;
|
|
103
|
+
/**
|
|
104
|
+
* Approval hook invoked only when {@link ShellToolsConfig.requiresApproval}
|
|
105
|
+
* returns `true`. Return `true`/`false` or an {@link ApprovalDecision}.
|
|
106
|
+
*/
|
|
107
|
+
readonly approve?: (req: CommandRequest) => boolean | ApprovalDecision | Promise<boolean | ApprovalDecision>;
|
|
108
|
+
/** Timeout applied when the model omits `timeoutMs`. Defaults to 30_000. */
|
|
109
|
+
readonly defaultTimeoutMs?: number;
|
|
110
|
+
/** Upper bound clamping any model-supplied `timeoutMs`. Defaults to 600_000. */
|
|
111
|
+
readonly maxTimeoutMs?: number;
|
|
112
|
+
/** Byte cap per stream (stdout / stderr) before truncation. Defaults to 100_000. */
|
|
113
|
+
readonly maxOutputBytes?: number;
|
|
114
|
+
}
|
|
115
|
+
/** The pair of tool definitions returned by {@link shellTools}. */
|
|
116
|
+
export interface ShellTools {
|
|
117
|
+
/** Buffered execution — awaits completion, returns captured output. */
|
|
118
|
+
readonly runCommand: import("../tools/types").ToolDefinition;
|
|
119
|
+
/** Streamed execution — emits output incrementally onto the run event stream. */
|
|
120
|
+
readonly spawnCommand: import("../tools/types").ToolDefinition;
|
|
121
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Higher-level web/search tool definitions.
|
|
3
|
+
*
|
|
4
|
+
* These tools intentionally stay static: they do not execute JavaScript, do not
|
|
5
|
+
* launch a browser, and require an injected search provider for web search.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import type { WebTools, WebToolsConfig } from "./types";
|
|
10
|
+
/** Build the web/search tools bound to host HTTP and robots policy. */
|
|
11
|
+
export declare function webTools(config: WebToolsConfig): WebTools;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Static HTML parsing helpers for `tools-web`.
|
|
3
|
+
*
|
|
4
|
+
* LinkeDOM is used as a local DOM implementation. Scripts are not executed and
|
|
5
|
+
* no browser is launched.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
export interface ParsedPage {
|
|
10
|
+
readonly title?: string;
|
|
11
|
+
readonly text: string;
|
|
12
|
+
readonly links: readonly {
|
|
13
|
+
readonly url: string;
|
|
14
|
+
readonly text?: string;
|
|
15
|
+
}[];
|
|
16
|
+
}
|
|
17
|
+
/** Parse title, visible-ish text, and absolute links from a static HTML string. */
|
|
18
|
+
export declare function parseStaticHtml(html: string, baseUrl: string, maxLinks?: number): ParsedPage;
|
|
19
|
+
/** Parse an HTML document for Readability. */
|
|
20
|
+
export declare function readabilityDocument(html: string): unknown;
|
|
21
|
+
/** Collapse arbitrary text into a compact model-facing string. */
|
|
22
|
+
export declare function compactText(text: string): string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@infinityi/engine-lib/tools-web` - optional static web/search tools.
|
|
3
|
+
*
|
|
4
|
+
* This subpath builds on `tools-http` and remains opt-in. It ships no search
|
|
5
|
+
* vendor adapter and does not execute JavaScript or launch a browser.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { webTools } from "@infinityi/engine-lib/tools-web";
|
|
10
|
+
*
|
|
11
|
+
* const web = webTools({
|
|
12
|
+
* allowPublicInternet: true,
|
|
13
|
+
* robots: "enforce",
|
|
14
|
+
* searchProvider,
|
|
15
|
+
* });
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @module
|
|
19
|
+
*/
|
|
20
|
+
export { webTools } from "./define";
|
|
21
|
+
export type { Citation, RobotsPolicy, SearchProvider, SearchRequest, SearchResult, SourceMetadata, WebTools, WebToolsConfig, } from "./types";
|