@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
|
@@ -8,18 +8,18 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import type { Message } from "../messages/types";
|
|
10
10
|
import type { EngineContext } from "../runtime/types";
|
|
11
|
-
import type { ContextProvider } from "./types";
|
|
11
|
+
import type { ContextProvider, ContextResolveContext } from "./types";
|
|
12
12
|
/**
|
|
13
13
|
* Inject static facts verbatim. `content` is rendered as-is (strings) or
|
|
14
14
|
* JSON-encoded; an optional `title` becomes a markdown heading.
|
|
15
15
|
*/
|
|
16
16
|
export declare function staticContext(content: unknown, title?: string): ContextProvider;
|
|
17
17
|
/** Inject context computed lazily at run time from the {@link EngineContext}. */
|
|
18
|
-
export declare function dynamicContext(name: string, fn: (ctx: EngineContext) => unknown | Promise<unknown>, title?: string): ContextProvider;
|
|
18
|
+
export declare function dynamicContext(name: string, fn: (ctx: EngineContext, run?: ContextResolveContext) => unknown | Promise<unknown>, title?: string): ContextProvider;
|
|
19
19
|
/**
|
|
20
20
|
* Resolve all providers and fold their items into a single `system` message
|
|
21
21
|
* (the injected-context block), or `[]` when there is nothing to inject.
|
|
22
22
|
* Providers resolve concurrently; their declaration order is preserved in the
|
|
23
23
|
* output.
|
|
24
24
|
*/
|
|
25
|
-
export declare function resolveContext(providers: readonly ContextProvider[] | undefined, ctx: EngineContext): Promise<Message[]>;
|
|
25
|
+
export declare function resolveContext(providers: readonly ContextProvider[] | undefined, ctx: EngineContext, run?: ContextResolveContext): Promise<Message[]>;
|
package/dist/context/types.d.ts
CHANGED
|
@@ -22,13 +22,28 @@ export interface ContextItem {
|
|
|
22
22
|
/** Strings pass through; anything else is JSON-encoded when rendered. */
|
|
23
23
|
readonly content: unknown;
|
|
24
24
|
}
|
|
25
|
+
/** Run-specific facts made available while resolving context providers. */
|
|
26
|
+
export interface ContextResolveContext {
|
|
27
|
+
/** Active agent name for this run. */
|
|
28
|
+
readonly agentName: string;
|
|
29
|
+
/** Resolved agent instructions, when any. */
|
|
30
|
+
readonly instructions?: string;
|
|
31
|
+
/** New input messages for this run. */
|
|
32
|
+
readonly input: readonly Message[];
|
|
33
|
+
/** Prior conversation history loaded before this run's input. */
|
|
34
|
+
readonly prior: readonly Message[];
|
|
35
|
+
/** Prior history followed by this run's input, excluding instructions/context. */
|
|
36
|
+
readonly messages: readonly Message[];
|
|
37
|
+
/** Per-run context-window configuration, when supplied. */
|
|
38
|
+
readonly contextWindow?: ContextWindowOptions;
|
|
39
|
+
}
|
|
25
40
|
/**
|
|
26
41
|
* A host-supplied context source, resolved once per run before the first
|
|
27
42
|
* provider call. Results are injected as system context and are not persisted.
|
|
28
43
|
*/
|
|
29
44
|
export interface ContextProvider {
|
|
30
45
|
readonly name: string;
|
|
31
|
-
resolve(ctx: EngineContext): ContextItem[] | Promise<ContextItem[]>;
|
|
46
|
+
resolve(ctx: EngineContext, run?: ContextResolveContext): ContextItem[] | Promise<ContextItem[]>;
|
|
32
47
|
}
|
|
33
48
|
/** Counts tokens for a message list (pluggable; a char-based heuristic ships built-in). */
|
|
34
49
|
export type TokenCounter = (messages: readonly Message[]) => number;
|
package/dist/errors.d.ts
CHANGED
|
@@ -91,3 +91,21 @@ export declare class ContextWindowError extends AgentError {
|
|
|
91
91
|
limit?: number;
|
|
92
92
|
});
|
|
93
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* The optional `tools-shell` module was misconfigured (e.g. an `allowedCwds`
|
|
96
|
+
* entry that is not an absolute path). Thrown for host-side configuration
|
|
97
|
+
* faults at factory-build time — policy *denials* of a model's command are not
|
|
98
|
+
* errors; those return `{ ok: false, error }` from the tool so the model can
|
|
99
|
+
* recover.
|
|
100
|
+
*/
|
|
101
|
+
export declare class ShellPolicyError extends AgentError {
|
|
102
|
+
constructor(message: string, options?: ErrorOptions);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* The optional `tools-fs` module was misconfigured (for example, missing
|
|
106
|
+
* absolute `allowedRoots`). Per-call filesystem denials are returned as tool
|
|
107
|
+
* failures so the model can recover.
|
|
108
|
+
*/
|
|
109
|
+
export declare class FilesystemPolicyError extends AgentError {
|
|
110
|
+
constructor(message: string, options?: ErrorOptions);
|
|
111
|
+
}
|
package/dist/errors.js
CHANGED
|
@@ -3,20 +3,25 @@ import {
|
|
|
3
3
|
CancelledError,
|
|
4
4
|
ContextWindowError,
|
|
5
5
|
ExecutionError,
|
|
6
|
+
FilesystemPolicyError,
|
|
6
7
|
MaxHandoffsExceededError,
|
|
7
8
|
MaxStepsExceededError,
|
|
8
9
|
ProviderError,
|
|
9
10
|
SchemaValidationError,
|
|
11
|
+
ShellPolicyError,
|
|
10
12
|
ToolError,
|
|
11
13
|
ToolValidationError
|
|
12
|
-
} from "./index-
|
|
14
|
+
} from "./index-ajr3nk10.js";
|
|
15
|
+
import"./index-37x76zdn.js";
|
|
13
16
|
export {
|
|
14
17
|
ToolValidationError,
|
|
15
18
|
ToolError,
|
|
19
|
+
ShellPolicyError,
|
|
16
20
|
SchemaValidationError,
|
|
17
21
|
ProviderError,
|
|
18
22
|
MaxStepsExceededError,
|
|
19
23
|
MaxHandoffsExceededError,
|
|
24
|
+
FilesystemPolicyError,
|
|
20
25
|
ExecutionError,
|
|
21
26
|
ContextWindowError,
|
|
22
27
|
CancelledError,
|
package/dist/events/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
eventPayload,
|
|
4
4
|
loggingSubscriber,
|
|
5
5
|
messageBusSubscriber
|
|
6
|
-
} from "../index-
|
|
6
|
+
} from "../index-9egrqxkf.js";
|
|
7
7
|
import {
|
|
8
8
|
SPAN_PROVIDER,
|
|
9
9
|
SPAN_RUN,
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
createEventHub,
|
|
12
12
|
createRunTelemetry
|
|
13
13
|
} from "../index-fkr3rcq9.js";
|
|
14
|
+
import"../index-37x76zdn.js";
|
|
14
15
|
export {
|
|
15
16
|
messageBusSubscriber,
|
|
16
17
|
loggingSubscriber,
|
package/dist/execution/index.js
CHANGED
|
@@ -5,14 +5,19 @@ import {
|
|
|
5
5
|
addUsage,
|
|
6
6
|
emptyUsage,
|
|
7
7
|
runAgent
|
|
8
|
-
} from "../index-
|
|
9
|
-
import"../index-yrqrxwjt.js";
|
|
8
|
+
} from "../index-7nb9qwa1.js";
|
|
10
9
|
import"../index-fkr3rcq9.js";
|
|
11
|
-
import"../index-
|
|
10
|
+
import"../index-ycjsqfpq.js";
|
|
11
|
+
import"../index-nvdsr51v.js";
|
|
12
|
+
import"../index-c6kgts41.js";
|
|
13
|
+
import"../index-k0q7x4mz.js";
|
|
12
14
|
import"../index-zfgr4xx3.js";
|
|
13
|
-
import"../index-7690reng.js";
|
|
14
15
|
import"../index-rentvdpp.js";
|
|
15
16
|
import"../index-1p6mb2vz.js";
|
|
17
|
+
import"../index-mnx5mqbs.js";
|
|
18
|
+
import"../index-4c15ysa8.js";
|
|
19
|
+
import"../index-ajr3nk10.js";
|
|
20
|
+
import"../index-37x76zdn.js";
|
|
16
21
|
export {
|
|
17
22
|
runAgent,
|
|
18
23
|
emptyUsage,
|
|
@@ -89,6 +89,20 @@ export type RunEvent = {
|
|
|
89
89
|
readonly type: "agent.handoff";
|
|
90
90
|
readonly from: string;
|
|
91
91
|
readonly to: string;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* An extension event emitted by an optional module or a custom tool through
|
|
95
|
+
* {@link RunBridge.emit}. `name` namespaces the event (e.g. `"shell.exec.start"`)
|
|
96
|
+
* and `data` is a JSON-serializable payload. The core loop never produces this
|
|
97
|
+
* variant; it is the stable seam for surfacing module-specific metadata (policy
|
|
98
|
+
* decisions, approvals, streamed output) onto the same subscriber/auditing
|
|
99
|
+
* stream as built-in events. Subscribers that don't recognize a `name` should
|
|
100
|
+
* ignore it.
|
|
101
|
+
*/
|
|
102
|
+
| {
|
|
103
|
+
readonly type: "custom";
|
|
104
|
+
readonly name: string;
|
|
105
|
+
readonly data: Record<string, unknown>;
|
|
92
106
|
};
|
|
93
107
|
/**
|
|
94
108
|
* A handle the run loop hands to a tool so it can participate in its parent run:
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// src/schema/validate.ts
|
|
2
|
+
function issue(path, message) {
|
|
3
|
+
return { path: [...path], message };
|
|
4
|
+
}
|
|
5
|
+
function isPlainObject(value) {
|
|
6
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
7
|
+
}
|
|
8
|
+
function validateJsonSchema(node, input, path = []) {
|
|
9
|
+
const issues = [];
|
|
10
|
+
if (node.enum !== undefined) {
|
|
11
|
+
if (!node.enum.includes(input)) {
|
|
12
|
+
issues.push(issue(path, `expected one of ${JSON.stringify(node.enum)}`));
|
|
13
|
+
}
|
|
14
|
+
return issues;
|
|
15
|
+
}
|
|
16
|
+
switch (node.type) {
|
|
17
|
+
case "string":
|
|
18
|
+
if (typeof input !== "string")
|
|
19
|
+
issues.push(issue(path, "expected string"));
|
|
20
|
+
break;
|
|
21
|
+
case "boolean":
|
|
22
|
+
if (typeof input !== "boolean")
|
|
23
|
+
issues.push(issue(path, "expected boolean"));
|
|
24
|
+
break;
|
|
25
|
+
case "null":
|
|
26
|
+
if (input !== null)
|
|
27
|
+
issues.push(issue(path, "expected null"));
|
|
28
|
+
break;
|
|
29
|
+
case "number":
|
|
30
|
+
if (typeof input !== "number" || Number.isNaN(input)) {
|
|
31
|
+
issues.push(issue(path, "expected number"));
|
|
32
|
+
}
|
|
33
|
+
break;
|
|
34
|
+
case "integer":
|
|
35
|
+
if (typeof input !== "number" || !Number.isInteger(input)) {
|
|
36
|
+
issues.push(issue(path, "expected integer"));
|
|
37
|
+
}
|
|
38
|
+
break;
|
|
39
|
+
case "array": {
|
|
40
|
+
if (!Array.isArray(input)) {
|
|
41
|
+
issues.push(issue(path, "expected array"));
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
if (node.items !== undefined) {
|
|
45
|
+
input.forEach((element, index) => {
|
|
46
|
+
issues.push(...validateJsonSchema(node.items, element, [...path, index]));
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
case "object": {
|
|
52
|
+
if (!isPlainObject(input)) {
|
|
53
|
+
issues.push(issue(path, "expected object"));
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
const properties = node.properties ?? {};
|
|
57
|
+
const required = node.required ?? [];
|
|
58
|
+
for (const key of required) {
|
|
59
|
+
if (input[key] === undefined) {
|
|
60
|
+
issues.push(issue([...path, key], "required"));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
for (const [key, propSchema] of Object.entries(properties)) {
|
|
64
|
+
const value = input[key];
|
|
65
|
+
if (value === undefined)
|
|
66
|
+
continue;
|
|
67
|
+
issues.push(...validateJsonSchema(propSchema, value, [...path, key]));
|
|
68
|
+
}
|
|
69
|
+
if (node.additionalProperties === false) {
|
|
70
|
+
for (const key of Object.keys(input)) {
|
|
71
|
+
if (!(key in properties)) {
|
|
72
|
+
issues.push(issue([...path, key], "unexpected property"));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
default:
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
return issues;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export { validateJsonSchema };
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
applyContextWindow,
|
|
3
|
-
resolveContext
|
|
4
|
-
} from "./index-yrqrxwjt.js";
|
|
5
1
|
import {
|
|
6
2
|
SPAN_PROVIDER,
|
|
7
3
|
SPAN_RUN,
|
|
@@ -10,18 +6,14 @@ import {
|
|
|
10
6
|
createRunTelemetry
|
|
11
7
|
} from "./index-fkr3rcq9.js";
|
|
12
8
|
import {
|
|
13
|
-
|
|
14
|
-
} from "./index-
|
|
9
|
+
resolveContext
|
|
10
|
+
} from "./index-ycjsqfpq.js";
|
|
11
|
+
import {
|
|
12
|
+
applyContextWindow
|
|
13
|
+
} from "./index-nvdsr51v.js";
|
|
15
14
|
import {
|
|
16
15
|
StreamAccumulator
|
|
17
16
|
} from "./index-zfgr4xx3.js";
|
|
18
|
-
import {
|
|
19
|
-
AgentError,
|
|
20
|
-
CancelledError,
|
|
21
|
-
ExecutionError,
|
|
22
|
-
MaxHandoffsExceededError,
|
|
23
|
-
MaxStepsExceededError
|
|
24
|
-
} from "./index-7690reng.js";
|
|
25
17
|
import {
|
|
26
18
|
toProviderTool,
|
|
27
19
|
toToolResultMessage
|
|
@@ -30,6 +22,16 @@ import {
|
|
|
30
22
|
system,
|
|
31
23
|
user
|
|
32
24
|
} from "./index-1p6mb2vz.js";
|
|
25
|
+
import {
|
|
26
|
+
s
|
|
27
|
+
} from "./index-mnx5mqbs.js";
|
|
28
|
+
import {
|
|
29
|
+
AgentError,
|
|
30
|
+
CancelledError,
|
|
31
|
+
ExecutionError,
|
|
32
|
+
MaxHandoffsExceededError,
|
|
33
|
+
MaxStepsExceededError
|
|
34
|
+
} from "./index-ajr3nk10.js";
|
|
33
35
|
|
|
34
36
|
// src/agent/registry.ts
|
|
35
37
|
function createToolRegistry(tools) {
|
|
@@ -236,9 +238,16 @@ async function* executeAgent(agent, opts, tel) {
|
|
|
236
238
|
throwIfAborted(opts.signal);
|
|
237
239
|
yield { type: "run.start", agent: agent.name };
|
|
238
240
|
const instructions = await resolveInstructions(agent, engineCtx);
|
|
239
|
-
const contextMessages = await resolveContext(opts.context, engineCtx);
|
|
240
241
|
const prior = opts.session !== undefined ? await opts.session.messages() : opts.messages ?? [];
|
|
241
242
|
const inputMessages = normalizeInput(opts.input);
|
|
243
|
+
const contextMessages = await resolveContext(opts.context, engineCtx, {
|
|
244
|
+
agentName: agent.name,
|
|
245
|
+
...instructions !== undefined ? { instructions } : {},
|
|
246
|
+
input: inputMessages,
|
|
247
|
+
prior,
|
|
248
|
+
messages: [...prior, ...inputMessages],
|
|
249
|
+
...opts.contextWindow !== undefined ? { contextWindow: opts.contextWindow } : {}
|
|
250
|
+
});
|
|
242
251
|
const messages = [];
|
|
243
252
|
if (instructions !== undefined && instructions !== "")
|
|
244
253
|
messages.push(system(instructions));
|
|
@@ -35,6 +35,8 @@ function eventFields(event) {
|
|
|
35
35
|
return { agent: event.agent, depth: event.depth, child: event.event.type };
|
|
36
36
|
case "agent.handoff":
|
|
37
37
|
return { from: event.from, to: event.to };
|
|
38
|
+
case "custom":
|
|
39
|
+
return { name: event.name };
|
|
38
40
|
}
|
|
39
41
|
}
|
|
40
42
|
function eventPayload(event) {
|
|
@@ -63,6 +65,8 @@ function eventPayload(event) {
|
|
|
63
65
|
return { agent: event.agent, depth: event.depth, event: eventPayload(event.event) };
|
|
64
66
|
case "agent.handoff":
|
|
65
67
|
return { from: event.from, to: event.to };
|
|
68
|
+
case "custom":
|
|
69
|
+
return { name: event.name, data: event.data };
|
|
66
70
|
}
|
|
67
71
|
}
|
|
68
72
|
export { loggingSubscriber, messageBusSubscriber, eventFields, eventPayload };
|
|
File without changes
|
|
@@ -4,13 +4,13 @@ import {
|
|
|
4
4
|
exponentialBackoff,
|
|
5
5
|
retry,
|
|
6
6
|
timeout
|
|
7
|
-
} from "./index-
|
|
7
|
+
} from "./index-zdggff0y.js";
|
|
8
8
|
import {
|
|
9
9
|
resolveSecret
|
|
10
|
-
} from "./index-
|
|
10
|
+
} from "./index-e14g2e48.js";
|
|
11
11
|
import {
|
|
12
12
|
ProviderError
|
|
13
|
-
} from "./index-
|
|
13
|
+
} from "./index-ajr3nk10.js";
|
|
14
14
|
// node_modules/@infinityi/forge/dist/index-r6ez01fw.js
|
|
15
15
|
var PROBLEM_CONTENT_TYPE = "application/problem+json";
|
|
16
16
|
var DEFAULT_PROBLEM_TYPE = "about:blank";
|
|
@@ -93,4 +93,18 @@ class ContextWindowError extends AgentError {
|
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
|
|
96
|
+
class ShellPolicyError extends AgentError {
|
|
97
|
+
constructor(message, options) {
|
|
98
|
+
super(message, options);
|
|
99
|
+
this.name = "ShellPolicyError";
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
class FilesystemPolicyError extends AgentError {
|
|
104
|
+
constructor(message, options) {
|
|
105
|
+
super(message, options);
|
|
106
|
+
this.name = "FilesystemPolicyError";
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export { AgentError, ProviderError, ToolError, SchemaValidationError, ToolValidationError, ExecutionError, MaxStepsExceededError, MaxHandoffsExceededError, CancelledError, ContextWindowError, ShellPolicyError, FilesystemPolicyError };
|
|
File without changes
|
|
@@ -24,10 +24,10 @@ function isSecret(value) {
|
|
|
24
24
|
return value instanceof Secret;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
// node_modules/@infinityi/forge/dist/index-
|
|
27
|
+
// node_modules/@infinityi/forge/dist/index-2dnw7sq9.js
|
|
28
28
|
var LEAF_BRAND = Symbol.for("forge/config/leaf");
|
|
29
29
|
|
|
30
|
-
// node_modules/@infinityi/forge/dist/index-
|
|
30
|
+
// node_modules/@infinityi/forge/dist/index-zhbta8s6.js
|
|
31
31
|
var TRUE_TOKENS = new Set(["true", "1", "yes"]);
|
|
32
32
|
var FALSE_TOKENS = new Set(["false", "0", "no"]);
|
|
33
33
|
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {
|
|
2
|
+
validateJsonSchema
|
|
3
|
+
} from "./index-4c15ysa8.js";
|
|
4
|
+
import {
|
|
5
|
+
SchemaValidationError
|
|
6
|
+
} from "./index-ajr3nk10.js";
|
|
7
|
+
|
|
8
|
+
// src/schema/json-schema.ts
|
|
9
|
+
function toJsonSchema(schema) {
|
|
10
|
+
return schema.jsonSchema;
|
|
11
|
+
}
|
|
12
|
+
function asSchema(impl) {
|
|
13
|
+
return {
|
|
14
|
+
jsonSchema: impl.jsonSchema,
|
|
15
|
+
parse: impl.parse.bind(impl),
|
|
16
|
+
safeParse: impl.safeParse?.bind(impl) ?? ((input) => {
|
|
17
|
+
try {
|
|
18
|
+
return { success: true, data: impl.parse(input) };
|
|
19
|
+
} catch (error) {
|
|
20
|
+
if (error instanceof SchemaValidationError)
|
|
21
|
+
return { success: false, error };
|
|
22
|
+
return {
|
|
23
|
+
success: false,
|
|
24
|
+
error: new SchemaValidationError("schema validation failed", {
|
|
25
|
+
cause: error,
|
|
26
|
+
issues: [{ path: [], message: String(error) }]
|
|
27
|
+
})
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function fromJsonSchema(jsonSchema) {
|
|
34
|
+
return {
|
|
35
|
+
jsonSchema,
|
|
36
|
+
safeParse(input) {
|
|
37
|
+
const issues = validateJsonSchema(jsonSchema, input);
|
|
38
|
+
if (issues.length === 0)
|
|
39
|
+
return { success: true, data: input };
|
|
40
|
+
return {
|
|
41
|
+
success: false,
|
|
42
|
+
error: new SchemaValidationError("schema validation failed", { issues })
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
parse(input) {
|
|
46
|
+
const result = this.safeParse(input);
|
|
47
|
+
if (!result.success)
|
|
48
|
+
throw result.error;
|
|
49
|
+
return result.data;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export { toJsonSchema, asSchema, fromJsonSchema };
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import {
|
|
2
|
+
validateJsonSchema
|
|
3
|
+
} from "./index-4c15ysa8.js";
|
|
4
|
+
import {
|
|
5
|
+
SchemaValidationError
|
|
6
|
+
} from "./index-ajr3nk10.js";
|
|
7
|
+
|
|
8
|
+
// src/schema/builder.ts
|
|
9
|
+
var optionalSchemas = new WeakSet;
|
|
10
|
+
function makeSchema(jsonSchema) {
|
|
11
|
+
return {
|
|
12
|
+
jsonSchema,
|
|
13
|
+
safeParse(input) {
|
|
14
|
+
const issues = validateJsonSchema(jsonSchema, input);
|
|
15
|
+
if (issues.length === 0)
|
|
16
|
+
return { success: true, data: input };
|
|
17
|
+
return {
|
|
18
|
+
success: false,
|
|
19
|
+
error: new SchemaValidationError("schema validation failed", { issues })
|
|
20
|
+
};
|
|
21
|
+
},
|
|
22
|
+
parse(input) {
|
|
23
|
+
const result = this.safeParse(input);
|
|
24
|
+
if (!result.success)
|
|
25
|
+
throw result.error;
|
|
26
|
+
return result.data;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
var s = {
|
|
31
|
+
string(opts) {
|
|
32
|
+
const node = { type: "string" };
|
|
33
|
+
if (opts?.description !== undefined)
|
|
34
|
+
node.description = opts.description;
|
|
35
|
+
if (opts?.enum !== undefined)
|
|
36
|
+
node.enum = opts.enum;
|
|
37
|
+
return makeSchema(node);
|
|
38
|
+
},
|
|
39
|
+
number(opts) {
|
|
40
|
+
const node = { type: opts?.int ? "integer" : "number" };
|
|
41
|
+
if (opts?.description !== undefined)
|
|
42
|
+
node.description = opts.description;
|
|
43
|
+
return makeSchema(node);
|
|
44
|
+
},
|
|
45
|
+
boolean(opts) {
|
|
46
|
+
const node = { type: "boolean" };
|
|
47
|
+
if (opts?.description !== undefined)
|
|
48
|
+
node.description = opts.description;
|
|
49
|
+
return makeSchema(node);
|
|
50
|
+
},
|
|
51
|
+
enum(values, opts) {
|
|
52
|
+
const node = { type: "string", enum: values };
|
|
53
|
+
if (opts?.description !== undefined)
|
|
54
|
+
node.description = opts.description;
|
|
55
|
+
return makeSchema(node);
|
|
56
|
+
},
|
|
57
|
+
array(item, opts) {
|
|
58
|
+
const node = { type: "array", items: item.jsonSchema };
|
|
59
|
+
if (opts?.description !== undefined)
|
|
60
|
+
node.description = opts.description;
|
|
61
|
+
return makeSchema(node);
|
|
62
|
+
},
|
|
63
|
+
object(props, opts) {
|
|
64
|
+
const properties = {};
|
|
65
|
+
const required = [];
|
|
66
|
+
for (const [key, prop] of Object.entries(props)) {
|
|
67
|
+
properties[key] = prop.jsonSchema;
|
|
68
|
+
if (!optionalSchemas.has(prop))
|
|
69
|
+
required.push(key);
|
|
70
|
+
}
|
|
71
|
+
const node = {
|
|
72
|
+
type: "object",
|
|
73
|
+
properties,
|
|
74
|
+
additionalProperties: false
|
|
75
|
+
};
|
|
76
|
+
if (required.length > 0)
|
|
77
|
+
node.required = required;
|
|
78
|
+
if (opts?.description !== undefined)
|
|
79
|
+
node.description = opts.description;
|
|
80
|
+
return makeSchema(node);
|
|
81
|
+
},
|
|
82
|
+
optional(inner) {
|
|
83
|
+
const schema = {
|
|
84
|
+
jsonSchema: inner.jsonSchema,
|
|
85
|
+
safeParse(input) {
|
|
86
|
+
if (input === undefined)
|
|
87
|
+
return { success: true, data: undefined };
|
|
88
|
+
return inner.safeParse(input);
|
|
89
|
+
},
|
|
90
|
+
parse(input) {
|
|
91
|
+
const result = this.safeParse(input);
|
|
92
|
+
if (!result.success)
|
|
93
|
+
throw result.error;
|
|
94
|
+
return result.data;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
optionalSchemas.add(schema);
|
|
98
|
+
return schema;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export { s };
|