@inkeep/agents-api 0.0.1
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/LICENSE.md +56 -0
- package/SUPPLEMENTAL_TERMS.md +40 -0
- package/dist/.well-known/workflow/v1/flow.cjs +46446 -0
- package/dist/.well-known/workflow/v1/flow.cjs.debug.json +8 -0
- package/dist/.well-known/workflow/v1/manifest.debug.json +93 -0
- package/dist/.well-known/workflow/v1/step.cjs +219923 -0
- package/dist/.well-known/workflow/v1/step.cjs.debug.json +8 -0
- package/dist/.well-known/workflow/v1/webhook.mjs +29 -0
- package/dist/createApp.d.ts +10 -0
- package/dist/createApp.js +170 -0
- package/dist/data/db/index.d.ts +4 -0
- package/dist/data/db/index.js +5 -0
- package/dist/data/db/manageDbClient.d.ts +6 -0
- package/dist/data/db/manageDbClient.js +9 -0
- package/dist/data/db/manageDbPool.d.ts +6 -0
- package/dist/data/db/manageDbPool.js +9 -0
- package/dist/data/db/runDbClient.d.ts +6 -0
- package/dist/data/db/runDbClient.js +9 -0
- package/dist/domains/evals/index.d.ts +13 -0
- package/dist/domains/evals/index.js +13 -0
- package/dist/domains/evals/routes/datasetTriggers.d.ts +7 -0
- package/dist/domains/evals/routes/datasetTriggers.js +65 -0
- package/dist/domains/evals/routes/evaluationTriggers.d.ts +11 -0
- package/dist/domains/evals/routes/evaluationTriggers.js +311 -0
- package/dist/domains/evals/routes/index.d.ts +7 -0
- package/dist/domains/evals/routes/index.js +12 -0
- package/dist/domains/evals/scripts/build-workflow.d.ts +1 -0
- package/dist/domains/evals/scripts/build-workflow.js +31 -0
- package/dist/domains/evals/services/EvaluationService.d.ts +96 -0
- package/dist/domains/evals/services/EvaluationService.js +863 -0
- package/dist/domains/evals/services/conversationEvaluation.d.ts +15 -0
- package/dist/domains/evals/services/conversationEvaluation.js +102 -0
- package/dist/domains/evals/services/datasetRun.d.ts +16 -0
- package/dist/domains/evals/services/datasetRun.js +43 -0
- package/dist/domains/evals/services/evaluationJob.d.ts +17 -0
- package/dist/domains/evals/services/evaluationJob.js +65 -0
- package/dist/domains/evals/services/startEvaluation.d.ts +19 -0
- package/dist/domains/evals/services/startEvaluation.js +18 -0
- package/dist/domains/evals/workflow/functions/evaluateConversation.d.ts +28 -0
- package/dist/domains/evals/workflow/functions/evaluateConversation.js +134 -0
- package/dist/domains/evals/workflow/functions/runDatasetItem.d.ts +36 -0
- package/dist/domains/evals/workflow/functions/runDatasetItem.js +204 -0
- package/dist/domains/evals/workflow/index.d.ts +4 -0
- package/dist/domains/evals/workflow/index.js +5 -0
- package/dist/domains/evals/workflow/routes.d.ts +7 -0
- package/dist/domains/evals/workflow/routes.js +106 -0
- package/dist/domains/evals/workflow/world.d.ts +4 -0
- package/dist/domains/evals/workflow/world.js +36 -0
- package/dist/domains/index.d.ts +4 -0
- package/dist/domains/index.js +5 -0
- package/dist/domains/manage/index.d.ts +12 -0
- package/dist/domains/manage/index.js +31 -0
- package/dist/domains/manage/routes/agent.d.ts +9 -0
- package/dist/domains/manage/routes/agent.js +264 -0
- package/dist/domains/manage/routes/agentFull.d.ts +9 -0
- package/dist/domains/manage/routes/agentFull.js +207 -0
- package/dist/domains/manage/routes/agentToolRelations.d.ts +9 -0
- package/dist/domains/manage/routes/agentToolRelations.js +289 -0
- package/dist/domains/manage/routes/apiKeys.d.ts +9 -0
- package/dist/domains/manage/routes/apiKeys.js +217 -0
- package/dist/domains/manage/routes/artifactComponents.d.ts +9 -0
- package/dist/domains/manage/routes/artifactComponents.js +210 -0
- package/dist/domains/manage/routes/branches.d.ts +9 -0
- package/dist/domains/manage/routes/branches.js +182 -0
- package/dist/domains/manage/routes/cliAuth.d.ts +9 -0
- package/dist/domains/manage/routes/cliAuth.js +60 -0
- package/dist/domains/manage/routes/contextConfigs.d.ts +9 -0
- package/dist/domains/manage/routes/contextConfigs.js +189 -0
- package/dist/domains/manage/routes/conversations.d.ts +7 -0
- package/dist/domains/manage/routes/conversations.js +59 -0
- package/dist/domains/manage/routes/credentialStores.d.ts +9 -0
- package/dist/domains/manage/routes/credentialStores.js +86 -0
- package/dist/domains/manage/routes/credentials.d.ts +9 -0
- package/dist/domains/manage/routes/credentials.js +207 -0
- package/dist/domains/manage/routes/dataComponents.d.ts +9 -0
- package/dist/domains/manage/routes/dataComponents.js +192 -0
- package/dist/domains/manage/routes/evals/datasetItems.d.ts +9 -0
- package/dist/domains/manage/routes/evals/datasetItems.js +310 -0
- package/dist/domains/manage/routes/evals/datasetRunConfigs.d.ts +9 -0
- package/dist/domains/manage/routes/evals/datasetRunConfigs.js +402 -0
- package/dist/domains/manage/routes/evals/datasetRuns.d.ts +9 -0
- package/dist/domains/manage/routes/evals/datasetRuns.js +256 -0
- package/dist/domains/manage/routes/evals/datasets.d.ts +9 -0
- package/dist/domains/manage/routes/evals/datasets.js +238 -0
- package/dist/domains/manage/routes/evals/evaluationJobConfigEvaluatorRelations.d.ts +9 -0
- package/dist/domains/manage/routes/evals/evaluationJobConfigEvaluatorRelations.js +146 -0
- package/dist/domains/manage/routes/evals/evaluationJobConfigs.d.ts +9 -0
- package/dist/domains/manage/routes/evals/evaluationJobConfigs.js +364 -0
- package/dist/domains/manage/routes/evals/evaluationResults.d.ts +7 -0
- package/dist/domains/manage/routes/evals/evaluationResults.js +192 -0
- package/dist/domains/manage/routes/evals/evaluationRunConfigs.d.ts +9 -0
- package/dist/domains/manage/routes/evals/evaluationRunConfigs.js +403 -0
- package/dist/domains/manage/routes/evals/evaluationSuiteConfigEvaluatorRelations.d.ts +9 -0
- package/dist/domains/manage/routes/evals/evaluationSuiteConfigEvaluatorRelations.js +146 -0
- package/dist/domains/manage/routes/evals/evaluationSuiteConfigs.d.ts +9 -0
- package/dist/domains/manage/routes/evals/evaluationSuiteConfigs.js +246 -0
- package/dist/domains/manage/routes/evals/evaluators.d.ts +9 -0
- package/dist/domains/manage/routes/evals/evaluators.js +281 -0
- package/dist/domains/manage/routes/evals/index.d.ts +9 -0
- package/dist/domains/manage/routes/evals/index.js +26 -0
- package/dist/domains/manage/routes/externalAgents.d.ts +9 -0
- package/dist/domains/manage/routes/externalAgents.js +199 -0
- package/dist/domains/manage/routes/functionTools.d.ts +9 -0
- package/dist/domains/manage/routes/functionTools.js +256 -0
- package/dist/domains/manage/routes/functions.d.ts +9 -0
- package/dist/domains/manage/routes/functions.js +285 -0
- package/dist/domains/manage/routes/index.d.ts +7 -0
- package/dist/domains/manage/routes/index.js +68 -0
- package/dist/domains/manage/routes/invitations.d.ts +9 -0
- package/dist/domains/manage/routes/invitations.js +41 -0
- package/dist/domains/manage/routes/mcp.d.ts +7 -0
- package/dist/domains/manage/routes/mcp.js +45 -0
- package/dist/domains/manage/routes/mcpCatalog.d.ts +9 -0
- package/dist/domains/manage/routes/mcpCatalog.js +454 -0
- package/dist/domains/manage/routes/oauth.d.ts +10 -0
- package/dist/domains/manage/routes/oauth.js +327 -0
- package/dist/domains/manage/routes/playgroundToken.d.ts +9 -0
- package/dist/domains/manage/routes/playgroundToken.js +127 -0
- package/dist/domains/manage/routes/projectFull.d.ts +9 -0
- package/dist/domains/manage/routes/projectFull.js +304 -0
- package/dist/domains/manage/routes/projectMembers.d.ts +9 -0
- package/dist/domains/manage/routes/projectMembers.js +201 -0
- package/dist/domains/manage/routes/projectPermissions.d.ts +9 -0
- package/dist/domains/manage/routes/projectPermissions.js +68 -0
- package/dist/domains/manage/routes/projects.d.ts +9 -0
- package/dist/domains/manage/routes/projects.js +279 -0
- package/dist/domains/manage/routes/ref.d.ts +9 -0
- package/dist/domains/manage/routes/ref.js +33 -0
- package/dist/domains/manage/routes/signoz.d.ts +10 -0
- package/dist/domains/manage/routes/signoz.js +159 -0
- package/dist/domains/manage/routes/subAgentArtifactComponents.d.ts +9 -0
- package/dist/domains/manage/routes/subAgentArtifactComponents.js +202 -0
- package/dist/domains/manage/routes/subAgentDataComponents.d.ts +9 -0
- package/dist/domains/manage/routes/subAgentDataComponents.js +201 -0
- package/dist/domains/manage/routes/subAgentExternalAgentRelations.d.ts +9 -0
- package/dist/domains/manage/routes/subAgentExternalAgentRelations.js +216 -0
- package/dist/domains/manage/routes/subAgentFunctionTools.d.ts +9 -0
- package/dist/domains/manage/routes/subAgentFunctionTools.js +205 -0
- package/dist/domains/manage/routes/subAgentRelations.d.ts +9 -0
- package/dist/domains/manage/routes/subAgentRelations.js +263 -0
- package/dist/domains/manage/routes/subAgentTeamAgentRelations.d.ts +9 -0
- package/dist/domains/manage/routes/subAgentTeamAgentRelations.js +216 -0
- package/dist/domains/manage/routes/subAgentToolRelations.d.ts +9 -0
- package/dist/domains/manage/routes/subAgentToolRelations.js +289 -0
- package/dist/domains/manage/routes/subAgents.d.ts +9 -0
- package/dist/domains/manage/routes/subAgents.js +220 -0
- package/dist/domains/manage/routes/thirdPartyMCPServers.d.ts +9 -0
- package/dist/domains/manage/routes/thirdPartyMCPServers.js +72 -0
- package/dist/domains/manage/routes/tools.d.ts +9 -0
- package/dist/domains/manage/routes/tools.js +261 -0
- package/dist/domains/manage/routes/triggers.d.ts +9 -0
- package/dist/domains/manage/routes/triggers.js +423 -0
- package/dist/domains/manage/routes/userOrganizations.d.ts +9 -0
- package/dist/domains/manage/routes/userOrganizations.js +58 -0
- package/dist/domains/run/a2a/client.d.ts +186 -0
- package/dist/domains/run/a2a/client.js +524 -0
- package/dist/domains/run/a2a/handlers.d.ts +7 -0
- package/dist/domains/run/a2a/handlers.js +582 -0
- package/dist/domains/run/a2a/transfer.d.ts +27 -0
- package/dist/domains/run/a2a/transfer.js +50 -0
- package/dist/domains/run/a2a/types.d.ts +79 -0
- package/dist/domains/run/a2a/types.js +22 -0
- package/dist/domains/run/agents/Agent.d.ts +273 -0
- package/dist/domains/run/agents/Agent.js +2104 -0
- package/dist/domains/run/agents/ModelFactory.d.ts +63 -0
- package/dist/domains/run/agents/ModelFactory.js +194 -0
- package/dist/domains/run/agents/SystemPromptBuilder.d.ts +21 -0
- package/dist/domains/run/agents/SystemPromptBuilder.js +48 -0
- package/dist/domains/run/agents/ToolSessionManager.d.ts +63 -0
- package/dist/domains/run/agents/ToolSessionManager.js +146 -0
- package/dist/domains/run/agents/generateTaskHandler.d.ts +44 -0
- package/dist/domains/run/agents/generateTaskHandler.js +384 -0
- package/dist/domains/run/agents/relationTools.d.ts +64 -0
- package/dist/domains/run/agents/relationTools.js +365 -0
- package/dist/domains/run/agents/types.d.ts +31 -0
- package/dist/domains/run/agents/types.js +1 -0
- package/dist/domains/run/agents/versions/v1/Phase1Config.d.ts +29 -0
- package/dist/domains/run/agents/versions/v1/Phase1Config.js +458 -0
- package/dist/domains/run/agents/versions/v1/Phase2Config.d.ts +33 -0
- package/dist/domains/run/agents/versions/v1/Phase2Config.js +341 -0
- package/dist/domains/run/constants/execution-limits/defaults.d.ts +51 -0
- package/dist/domains/run/constants/execution-limits/defaults.js +52 -0
- package/dist/domains/run/constants/execution-limits/index.d.ts +6 -0
- package/dist/domains/run/constants/execution-limits/index.js +21 -0
- package/dist/domains/run/context/ContextFetcher.d.ts +68 -0
- package/dist/domains/run/context/ContextFetcher.js +276 -0
- package/dist/domains/run/context/ContextResolver.d.ts +56 -0
- package/dist/domains/run/context/ContextResolver.js +273 -0
- package/dist/domains/run/context/context.d.ts +19 -0
- package/dist/domains/run/context/context.js +108 -0
- package/dist/domains/run/context/contextCache.d.ts +56 -0
- package/dist/domains/run/context/contextCache.js +174 -0
- package/dist/domains/run/context/index.d.ts +6 -0
- package/dist/domains/run/context/index.js +7 -0
- package/dist/domains/run/context/validation.d.ts +39 -0
- package/dist/domains/run/context/validation.js +255 -0
- package/dist/domains/run/data/agent.d.ts +7 -0
- package/dist/domains/run/data/agent.js +67 -0
- package/dist/domains/run/data/agents.d.ts +34 -0
- package/dist/domains/run/data/agents.js +131 -0
- package/dist/domains/run/data/conversations.d.ts +129 -0
- package/dist/domains/run/data/conversations.js +517 -0
- package/dist/domains/run/handlers/executionHandler.d.ts +42 -0
- package/dist/domains/run/handlers/executionHandler.js +484 -0
- package/dist/domains/run/index.d.ts +13 -0
- package/dist/domains/run/index.js +21 -0
- package/dist/domains/run/routes/agents.d.ts +13 -0
- package/dist/domains/run/routes/agents.js +141 -0
- package/dist/domains/run/routes/chat.d.ts +14 -0
- package/dist/domains/run/routes/chat.js +300 -0
- package/dist/domains/run/routes/chatDataStream.d.ts +14 -0
- package/dist/domains/run/routes/chatDataStream.js +381 -0
- package/dist/domains/run/routes/mcp.d.ts +14 -0
- package/dist/domains/run/routes/mcp.js +483 -0
- package/dist/domains/run/routes/webhooks.d.ts +15 -0
- package/dist/domains/run/routes/webhooks.js +396 -0
- package/dist/domains/run/services/AgentSession.d.ts +354 -0
- package/dist/domains/run/services/AgentSession.js +1203 -0
- package/dist/domains/run/services/ArtifactParser.d.ts +105 -0
- package/dist/domains/run/services/ArtifactParser.js +338 -0
- package/dist/domains/run/services/ArtifactService.d.ts +122 -0
- package/dist/domains/run/services/ArtifactService.js +629 -0
- package/dist/domains/run/services/BaseCompressor.d.ts +183 -0
- package/dist/domains/run/services/BaseCompressor.js +500 -0
- package/dist/domains/run/services/ConversationCompressor.d.ts +32 -0
- package/dist/domains/run/services/ConversationCompressor.js +91 -0
- package/dist/domains/run/services/IncrementalStreamParser.d.ts +98 -0
- package/dist/domains/run/services/IncrementalStreamParser.js +327 -0
- package/dist/domains/run/services/MidGenerationCompressor.d.ts +63 -0
- package/dist/domains/run/services/MidGenerationCompressor.js +104 -0
- package/dist/domains/run/services/PendingToolApprovalManager.d.ts +62 -0
- package/dist/domains/run/services/PendingToolApprovalManager.js +133 -0
- package/dist/domains/run/services/ResponseFormatter.d.ts +39 -0
- package/dist/domains/run/services/ResponseFormatter.js +152 -0
- package/dist/domains/run/services/evaluationRunConfigMatcher.d.ts +4 -0
- package/dist/domains/run/services/evaluationRunConfigMatcher.js +7 -0
- package/dist/domains/run/tools/NativeSandboxExecutor.d.ts +38 -0
- package/dist/domains/run/tools/NativeSandboxExecutor.js +432 -0
- package/dist/domains/run/tools/SandboxExecutorFactory.d.ts +36 -0
- package/dist/domains/run/tools/SandboxExecutorFactory.js +80 -0
- package/dist/domains/run/tools/VercelSandboxExecutor.d.ts +71 -0
- package/dist/domains/run/tools/VercelSandboxExecutor.js +340 -0
- package/dist/domains/run/tools/distill-conversation-history-tool.d.ts +62 -0
- package/dist/domains/run/tools/distill-conversation-history-tool.js +206 -0
- package/dist/domains/run/tools/distill-conversation-tool.d.ts +41 -0
- package/dist/domains/run/tools/distill-conversation-tool.js +141 -0
- package/dist/domains/run/tools/sandbox-utils.d.ts +18 -0
- package/dist/domains/run/tools/sandbox-utils.js +53 -0
- package/dist/domains/run/types/chat.d.ts +27 -0
- package/dist/domains/run/types/chat.js +1 -0
- package/dist/domains/run/types/executionContext.d.ts +40 -0
- package/dist/domains/run/types/executionContext.js +28 -0
- package/dist/domains/run/types/xml.d.ts +9 -0
- package/dist/domains/run/utils/SchemaProcessor.d.ts +52 -0
- package/dist/domains/run/utils/SchemaProcessor.js +182 -0
- package/dist/domains/run/utils/agent-operations.d.ts +62 -0
- package/dist/domains/run/utils/agent-operations.js +53 -0
- package/dist/domains/run/utils/artifact-component-schema.d.ts +42 -0
- package/dist/domains/run/utils/artifact-component-schema.js +186 -0
- package/dist/domains/run/utils/cleanup.d.ts +21 -0
- package/dist/domains/run/utils/cleanup.js +59 -0
- package/dist/domains/run/utils/data-component-schema.d.ts +2 -0
- package/dist/domains/run/utils/data-component-schema.js +3 -0
- package/dist/domains/run/utils/default-status-schemas.d.ts +20 -0
- package/dist/domains/run/utils/default-status-schemas.js +24 -0
- package/dist/domains/run/utils/json-postprocessor.d.ts +13 -0
- package/dist/domains/run/utils/json-postprocessor.js +19 -0
- package/dist/domains/run/utils/model-context-utils.d.ts +39 -0
- package/dist/domains/run/utils/model-context-utils.js +181 -0
- package/dist/domains/run/utils/model-resolver.d.ts +6 -0
- package/dist/domains/run/utils/model-resolver.js +24 -0
- package/dist/domains/run/utils/project.d.ts +207 -0
- package/dist/domains/run/utils/project.js +315 -0
- package/dist/domains/run/utils/schema-validation.d.ts +44 -0
- package/dist/domains/run/utils/schema-validation.js +97 -0
- package/dist/domains/run/utils/stream-helpers.d.ts +193 -0
- package/dist/domains/run/utils/stream-helpers.js +510 -0
- package/dist/domains/run/utils/stream-registry.d.ts +22 -0
- package/dist/domains/run/utils/stream-registry.js +33 -0
- package/dist/domains/run/utils/token-estimator.d.ts +23 -0
- package/dist/domains/run/utils/token-estimator.js +17 -0
- package/dist/domains/run/utils/tracer.d.ts +7 -0
- package/dist/domains/run/utils/tracer.js +7 -0
- package/dist/env.d.ts +89 -0
- package/dist/env.js +69 -0
- package/dist/factory.d.ts +1535 -0
- package/dist/factory.js +42 -0
- package/dist/index.d.ts +1530 -0
- package/dist/index.js +44 -0
- package/dist/initialization.d.ts +6 -0
- package/dist/initialization.js +65 -0
- package/dist/instrumentation.d.ts +17 -0
- package/dist/instrumentation.js +68 -0
- package/dist/logger.d.ts +2 -0
- package/dist/logger.js +3 -0
- package/dist/middleware/branchScopedDb.d.ts +31 -0
- package/dist/middleware/branchScopedDb.js +137 -0
- package/dist/middleware/cors.d.ts +36 -0
- package/dist/middleware/cors.js +131 -0
- package/dist/middleware/errorHandler.d.ts +12 -0
- package/dist/middleware/errorHandler.js +88 -0
- package/dist/middleware/evalsAuth.d.ts +16 -0
- package/dist/middleware/evalsAuth.js +52 -0
- package/dist/middleware/index.d.ts +8 -0
- package/dist/middleware/index.js +9 -0
- package/dist/middleware/manageAuth.d.ts +25 -0
- package/dist/middleware/manageAuth.js +80 -0
- package/dist/middleware/projectAccess.d.ts +31 -0
- package/dist/middleware/projectAccess.js +118 -0
- package/dist/middleware/projectConfig.d.ts +25 -0
- package/dist/middleware/projectConfig.js +89 -0
- package/dist/middleware/ref.d.ts +61 -0
- package/dist/middleware/ref.js +239 -0
- package/dist/middleware/requirePermission.d.ts +14 -0
- package/dist/middleware/requirePermission.js +80 -0
- package/dist/middleware/runAuth.d.ts +29 -0
- package/dist/middleware/runAuth.js +253 -0
- package/dist/middleware/sessionAuth.d.ts +17 -0
- package/dist/middleware/sessionAuth.js +58 -0
- package/dist/middleware/tenantAccess.d.ts +22 -0
- package/dist/middleware/tenantAccess.js +63 -0
- package/dist/middleware/tracing.d.ts +7 -0
- package/dist/middleware/tracing.js +50 -0
- package/dist/openapi.d.ts +7 -0
- package/dist/openapi.js +156 -0
- package/dist/ssoHelpers.d.ts +20 -0
- package/dist/ssoHelpers.js +51 -0
- package/dist/templates/v1/phase1/system-prompt.js +5 -0
- package/dist/templates/v1/phase1/thinking-preparation.js +5 -0
- package/dist/templates/v1/phase1/tool.js +5 -0
- package/dist/templates/v1/phase2/data-component.js +5 -0
- package/dist/templates/v1/phase2/data-components.js +5 -0
- package/dist/templates/v1/phase2/system-prompt.js +5 -0
- package/dist/templates/v1/shared/artifact-retrieval-guidance.js +5 -0
- package/dist/templates/v1/shared/artifact.js +5 -0
- package/dist/types/app.d.ts +64 -0
- package/dist/types/app.js +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.js +1 -0
- package/dist/types/runExecutionContext.d.ts +25 -0
- package/dist/types/runExecutionContext.js +28 -0
- package/dist/utils/oauthService.d.ts +71 -0
- package/dist/utils/oauthService.js +106 -0
- package/dist/utils/signozHelpers.d.ts +9 -0
- package/dist/utils/signozHelpers.js +33 -0
- package/dist/utils/speakeasy.d.ts +93 -0
- package/dist/utils/speakeasy.js +44 -0
- package/dist/utils/tempApiKeys.d.ts +17 -0
- package/dist/utils/tempApiKeys.js +26 -0
- package/dist/utils/workflowApiHelpers.d.ts +1 -0
- package/dist/utils/workflowApiHelpers.js +1 -0
- package/package.json +126 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { env } from "./env.js";
|
|
2
|
+
import { defaultSDK } from "./instrumentation.js";
|
|
3
|
+
import { createAgentsHono } from "./createApp.js";
|
|
4
|
+
import { initializeDefaultUser } from "./initialization.js";
|
|
5
|
+
import { createAuth0Provider, createOIDCProvider } from "./ssoHelpers.js";
|
|
6
|
+
import { createAgentsApp, createAgentsAuth } from "./factory.js";
|
|
7
|
+
import { Hono } from "hono";
|
|
8
|
+
import { CredentialStoreRegistry, createDefaultCredentialStores } from "@inkeep/agents-core";
|
|
9
|
+
|
|
10
|
+
//#region src/index.ts
|
|
11
|
+
defaultSDK.start();
|
|
12
|
+
const defaultConfig = {
|
|
13
|
+
port: 3002,
|
|
14
|
+
serverOptions: {
|
|
15
|
+
requestTimeout: 12e4,
|
|
16
|
+
keepAliveTimeout: 6e4,
|
|
17
|
+
keepAlive: true
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
const ssoProviders = await Promise.all([process.env.AUTH0_DOMAIN && process.env.AUTH0_CLIENT_ID && process.env.AUTH0_CLIENT_SECRET ? createAuth0Provider({
|
|
21
|
+
domain: process.env.AUTH0_DOMAIN,
|
|
22
|
+
clientId: process.env.AUTH0_CLIENT_ID,
|
|
23
|
+
clientSecret: process.env.AUTH0_CLIENT_SECRET
|
|
24
|
+
}) : null]);
|
|
25
|
+
const socialProviders = process.env.PUBLIC_GOOGLE_CLIENT_ID && process.env.GOOGLE_CLIENT_SECRET ? { google: {
|
|
26
|
+
prompt: "select_account",
|
|
27
|
+
display: "popup",
|
|
28
|
+
clientId: process.env.PUBLIC_GOOGLE_CLIENT_ID,
|
|
29
|
+
clientSecret: process.env.GOOGLE_CLIENT_SECRET
|
|
30
|
+
} } : void 0;
|
|
31
|
+
const auth = createAgentsAuth({
|
|
32
|
+
ssoProviders: ssoProviders.filter((p) => p !== null),
|
|
33
|
+
socialProviders
|
|
34
|
+
});
|
|
35
|
+
const app = createAgentsHono({
|
|
36
|
+
serverConfig: defaultConfig,
|
|
37
|
+
credentialStores: new CredentialStoreRegistry(createDefaultCredentialStores()),
|
|
38
|
+
auth
|
|
39
|
+
});
|
|
40
|
+
if (env.ENVIRONMENT === "development") initializeDefaultUser(auth);
|
|
41
|
+
var src_default = app;
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
export { Hono, auth, createAgentsApp, createAgentsHono, createAuth0Provider, createOIDCProvider, src_default as default, initializeDefaultUser };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { getLogger as getLogger$1 } from "./logger.js";
|
|
2
|
+
import { env } from "./env.js";
|
|
3
|
+
import runDbClient_default from "./data/db/runDbClient.js";
|
|
4
|
+
import { addUserToOrganization, getUserByEmail, upsertOrganization } from "@inkeep/agents-core";
|
|
5
|
+
|
|
6
|
+
//#region src/initialization.ts
|
|
7
|
+
const logger = getLogger$1("initialization");
|
|
8
|
+
async function initializeDefaultUser(authInstance) {
|
|
9
|
+
const { INKEEP_AGENTS_MANAGE_UI_USERNAME, INKEEP_AGENTS_MANAGE_UI_PASSWORD, DISABLE_AUTH } = env;
|
|
10
|
+
const hasCredentials = INKEEP_AGENTS_MANAGE_UI_USERNAME && INKEEP_AGENTS_MANAGE_UI_PASSWORD;
|
|
11
|
+
const orgId = env.TENANT_ID;
|
|
12
|
+
const { created } = await upsertOrganization(runDbClient_default)({
|
|
13
|
+
organizationId: orgId,
|
|
14
|
+
name: env.TENANT_ID,
|
|
15
|
+
slug: env.TENANT_ID,
|
|
16
|
+
logo: null,
|
|
17
|
+
metadata: null
|
|
18
|
+
});
|
|
19
|
+
if (created) logger.info({ organizationId: orgId }, "Created default organization");
|
|
20
|
+
else logger.info({ organizationId: orgId }, "Organization already exists");
|
|
21
|
+
if (!hasCredentials || DISABLE_AUTH || !authInstance) {
|
|
22
|
+
logger.info({ hasCredentials: false }, "Skipping default user creation");
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
let user = await getUserByEmail(runDbClient_default)(INKEEP_AGENTS_MANAGE_UI_USERNAME);
|
|
27
|
+
if (user) logger.info({
|
|
28
|
+
email: INKEEP_AGENTS_MANAGE_UI_USERNAME,
|
|
29
|
+
userId: user.id
|
|
30
|
+
}, "Default user already exists");
|
|
31
|
+
else {
|
|
32
|
+
logger.info({ email: INKEEP_AGENTS_MANAGE_UI_USERNAME }, "Creating default user with Better Auth...");
|
|
33
|
+
if (!(await authInstance.api.signUpEmail({ body: {
|
|
34
|
+
email: INKEEP_AGENTS_MANAGE_UI_USERNAME,
|
|
35
|
+
password: INKEEP_AGENTS_MANAGE_UI_PASSWORD,
|
|
36
|
+
name: INKEEP_AGENTS_MANAGE_UI_USERNAME.split("@")[0]
|
|
37
|
+
} })).user) throw new Error("signUpEmail returned no user");
|
|
38
|
+
user = await getUserByEmail(runDbClient_default)(INKEEP_AGENTS_MANAGE_UI_USERNAME);
|
|
39
|
+
if (!user) throw new Error("User was created but could not be retrieved from database");
|
|
40
|
+
logger.info({
|
|
41
|
+
email: user.email,
|
|
42
|
+
id: user.id
|
|
43
|
+
}, "Default user created from INKEEP_AGENTS_MANAGE_UI_USERNAME/INKEEP_AGENTS_MANAGE_UI_PASSWORD");
|
|
44
|
+
}
|
|
45
|
+
await addUserToOrganization(runDbClient_default)({
|
|
46
|
+
userId: user.id,
|
|
47
|
+
organizationId: orgId,
|
|
48
|
+
role: "owner"
|
|
49
|
+
});
|
|
50
|
+
logger.info({
|
|
51
|
+
organizationId: orgId,
|
|
52
|
+
organizationSlug: env.TENANT_ID,
|
|
53
|
+
userId: user.id,
|
|
54
|
+
email: INKEEP_AGENTS_MANAGE_UI_USERNAME
|
|
55
|
+
}, "Initialization complete - login with these credentials");
|
|
56
|
+
} catch (error) {
|
|
57
|
+
logger.error({
|
|
58
|
+
error,
|
|
59
|
+
email: INKEEP_AGENTS_MANAGE_UI_USERNAME
|
|
60
|
+
}, "Failed to create default user");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
//#endregion
|
|
65
|
+
export { initializeDefaultUser };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AsyncLocalStorageContextManager } from "@opentelemetry/context-async-hooks";
|
|
2
|
+
import { CompositePropagator } from "@opentelemetry/core";
|
|
3
|
+
import * as _opentelemetry_resources0 from "@opentelemetry/resources";
|
|
4
|
+
import { NodeSDK, NodeSDKConfiguration } from "@opentelemetry/sdk-node";
|
|
5
|
+
import { SpanProcessor } from "@opentelemetry/sdk-trace-base";
|
|
6
|
+
|
|
7
|
+
//#region src/instrumentation.d.ts
|
|
8
|
+
declare const defaultBatchProcessor: SpanProcessor;
|
|
9
|
+
declare const defaultResource: _opentelemetry_resources0.Resource;
|
|
10
|
+
declare const defaultInstrumentations: NonNullable<NodeSDKConfiguration['instrumentations']>;
|
|
11
|
+
declare const defaultSpanProcessors: SpanProcessor[];
|
|
12
|
+
declare const defaultContextManager: AsyncLocalStorageContextManager;
|
|
13
|
+
declare const defaultTextMapPropagator: CompositePropagator;
|
|
14
|
+
declare const defaultSDK: NodeSDK;
|
|
15
|
+
declare function flushBatchProcessor(): Promise<void>;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { defaultBatchProcessor, defaultContextManager, defaultInstrumentations, defaultResource, defaultSDK, defaultSpanProcessors, defaultTextMapPropagator, flushBatchProcessor };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { getLogger } from "./logger.js";
|
|
2
|
+
import { env } from "./env.js";
|
|
3
|
+
import { getNodeAutoInstrumentations } from "@opentelemetry/auto-instrumentations-node";
|
|
4
|
+
import { ALLOW_ALL_BAGGAGE_KEYS, BaggageSpanProcessor } from "@opentelemetry/baggage-span-processor";
|
|
5
|
+
import { AsyncLocalStorageContextManager } from "@opentelemetry/context-async-hooks";
|
|
6
|
+
import { CompositePropagator, W3CBaggagePropagator, W3CTraceContextPropagator } from "@opentelemetry/core";
|
|
7
|
+
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
|
|
8
|
+
import { resourceFromAttributes } from "@opentelemetry/resources";
|
|
9
|
+
import { NodeSDK } from "@opentelemetry/sdk-node";
|
|
10
|
+
import { BatchSpanProcessor, NoopSpanProcessor } from "@opentelemetry/sdk-trace-base";
|
|
11
|
+
import { ATTR_SERVICE_NAME } from "@opentelemetry/semantic-conventions";
|
|
12
|
+
|
|
13
|
+
//#region src/instrumentation.ts
|
|
14
|
+
const otlpExporter = new OTLPTraceExporter();
|
|
15
|
+
const logger = getLogger("instrumentation");
|
|
16
|
+
/**
|
|
17
|
+
* Creates a safe batch processor that falls back to no-op when SignOz is not configured
|
|
18
|
+
*/
|
|
19
|
+
function createSafeBatchProcessor() {
|
|
20
|
+
try {
|
|
21
|
+
return new BatchSpanProcessor(otlpExporter, {
|
|
22
|
+
scheduledDelayMillis: env.OTEL_BSP_SCHEDULE_DELAY,
|
|
23
|
+
maxExportBatchSize: env.OTEL_BSP_MAX_EXPORT_BATCH_SIZE
|
|
24
|
+
});
|
|
25
|
+
} catch (error) {
|
|
26
|
+
logger.warn({ error }, "Failed to create batch processor");
|
|
27
|
+
return new NoopSpanProcessor();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const defaultBatchProcessor = createSafeBatchProcessor();
|
|
31
|
+
const defaultResource = resourceFromAttributes({ [ATTR_SERVICE_NAME]: "inkeep-agents-run-api" });
|
|
32
|
+
const defaultInstrumentations = [getNodeAutoInstrumentations({
|
|
33
|
+
"@opentelemetry/instrumentation-http": {
|
|
34
|
+
enabled: true,
|
|
35
|
+
requestHook: (span, request) => {
|
|
36
|
+
const url = request?.url ?? request?.path;
|
|
37
|
+
if (!url) return;
|
|
38
|
+
const u = new URL(url, "http://localhost");
|
|
39
|
+
span.updateName(`${request?.method || "UNKNOWN"} ${u.pathname}`);
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"@opentelemetry/instrumentation-undici": { requestHook: (span) => {
|
|
43
|
+
const method = span.attributes?.["http.request.method"];
|
|
44
|
+
const host = span.attributes?.["server.address"];
|
|
45
|
+
const path = span.attributes?.["url.path"];
|
|
46
|
+
if (method && path) span.updateName(host ? `${method} ${host}${path}` : `${method} ${path}`);
|
|
47
|
+
} }
|
|
48
|
+
})];
|
|
49
|
+
const defaultSpanProcessors = [new BaggageSpanProcessor(ALLOW_ALL_BAGGAGE_KEYS), defaultBatchProcessor];
|
|
50
|
+
const defaultContextManager = new AsyncLocalStorageContextManager();
|
|
51
|
+
const defaultTextMapPropagator = new CompositePropagator({ propagators: [new W3CTraceContextPropagator(), new W3CBaggagePropagator()] });
|
|
52
|
+
const defaultSDK = new NodeSDK({
|
|
53
|
+
resource: defaultResource,
|
|
54
|
+
contextManager: defaultContextManager,
|
|
55
|
+
textMapPropagator: defaultTextMapPropagator,
|
|
56
|
+
spanProcessors: defaultSpanProcessors,
|
|
57
|
+
instrumentations: defaultInstrumentations
|
|
58
|
+
});
|
|
59
|
+
async function flushBatchProcessor() {
|
|
60
|
+
try {
|
|
61
|
+
await defaultBatchProcessor.forceFlush();
|
|
62
|
+
} catch (error) {
|
|
63
|
+
logger.warn({ error }, "Failed to flush batch processor");
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
//#endregion
|
|
68
|
+
export { defaultBatchProcessor, defaultContextManager, defaultInstrumentations, defaultResource, defaultSDK, defaultSpanProcessors, defaultTextMapPropagator, flushBatchProcessor };
|
package/dist/logger.d.ts
ADDED
package/dist/logger.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Context, Next } from "hono";
|
|
2
|
+
import { AgentsManageDatabaseClient } from "@inkeep/agents-core";
|
|
3
|
+
import { Pool } from "pg";
|
|
4
|
+
|
|
5
|
+
//#region src/middleware/branchScopedDb.d.ts
|
|
6
|
+
declare function isProjectDeleteOperation(path: string, method: string): boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Get the underlying connection pool from a Drizzle database client
|
|
9
|
+
*/
|
|
10
|
+
declare function getPoolFromClient(client: AgentsManageDatabaseClient): Pool | null;
|
|
11
|
+
/**
|
|
12
|
+
* Middleware that provides branch-scoped database connections
|
|
13
|
+
*
|
|
14
|
+
* Flow:
|
|
15
|
+
* 1. Get a dedicated connection from the pool
|
|
16
|
+
* 2. If ref is specified, checkout that branch/tag/commit on this connection
|
|
17
|
+
* 3. Create a Drizzle client wrapping this specific connection
|
|
18
|
+
* 4. Inject into context as 'db' (request-scoped database client)
|
|
19
|
+
* 5. Execute the route handler
|
|
20
|
+
* 6. For write operations on branches: auto-commit changes
|
|
21
|
+
* 7. Always cleanup: checkout main and release connection
|
|
22
|
+
*
|
|
23
|
+
* This ensures:
|
|
24
|
+
* - All operations in a request use the same connection (correct)
|
|
25
|
+
* - Only one checkout per request (performant)
|
|
26
|
+
* - Automatic commits for successful writes on branches
|
|
27
|
+
* - Proper connection cleanup
|
|
28
|
+
*/
|
|
29
|
+
declare const branchScopedDbMiddleware: (c: Context, next: Next) => Promise<void>;
|
|
30
|
+
//#endregion
|
|
31
|
+
export { branchScopedDbMiddleware, getPoolFromClient, isProjectDeleteOperation };
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { getLogger as getLogger$1 } from "../logger.js";
|
|
2
|
+
import manageDbClient_default from "../data/db/manageDbClient.js";
|
|
3
|
+
import { checkoutBranch, doltAddAndCommit, doltReset, doltStatus, generateId } from "@inkeep/agents-core";
|
|
4
|
+
import * as schema from "@inkeep/agents-core/db/manage-schema";
|
|
5
|
+
import { drizzle } from "drizzle-orm/node-postgres";
|
|
6
|
+
|
|
7
|
+
//#region src/middleware/branchScopedDb.ts
|
|
8
|
+
const logger = getLogger$1("branch-scoped-db");
|
|
9
|
+
function isProjectDeleteOperation(path, method) {
|
|
10
|
+
return method.toUpperCase() === "DELETE" && /^\/tenants\/[^/]+\/(?:projects|project-full)\/[^/]+\/?$/.test(path);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Get the underlying connection pool from a Drizzle database client
|
|
14
|
+
*/
|
|
15
|
+
function getPoolFromClient(client) {
|
|
16
|
+
if ("$client" in client && client.$client) return client.$client;
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Middleware that provides branch-scoped database connections
|
|
21
|
+
*
|
|
22
|
+
* Flow:
|
|
23
|
+
* 1. Get a dedicated connection from the pool
|
|
24
|
+
* 2. If ref is specified, checkout that branch/tag/commit on this connection
|
|
25
|
+
* 3. Create a Drizzle client wrapping this specific connection
|
|
26
|
+
* 4. Inject into context as 'db' (request-scoped database client)
|
|
27
|
+
* 5. Execute the route handler
|
|
28
|
+
* 6. For write operations on branches: auto-commit changes
|
|
29
|
+
* 7. Always cleanup: checkout main and release connection
|
|
30
|
+
*
|
|
31
|
+
* This ensures:
|
|
32
|
+
* - All operations in a request use the same connection (correct)
|
|
33
|
+
* - Only one checkout per request (performant)
|
|
34
|
+
* - Automatic commits for successful writes on branches
|
|
35
|
+
* - Proper connection cleanup
|
|
36
|
+
*/
|
|
37
|
+
const branchScopedDbMiddleware = async (c, next) => {
|
|
38
|
+
const resolvedRef = c.get("resolvedRef");
|
|
39
|
+
const method = c.req.method;
|
|
40
|
+
const userId = c.get("userId");
|
|
41
|
+
const userEmail = c.get("userEmail");
|
|
42
|
+
const pool = getPoolFromClient(manageDbClient_default);
|
|
43
|
+
if (!pool) {
|
|
44
|
+
logger.error({}, "Could not get connection pool from dbClient");
|
|
45
|
+
c.set("db", manageDbClient_default);
|
|
46
|
+
await next();
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (process.env.ENVIRONMENT === "test") {
|
|
50
|
+
c.set("db", manageDbClient_default);
|
|
51
|
+
await next();
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const connection = await pool.connect();
|
|
55
|
+
let tempBranch = null;
|
|
56
|
+
try {
|
|
57
|
+
const requestDb = drizzle(connection, { schema });
|
|
58
|
+
if (resolvedRef.type === "branch") {
|
|
59
|
+
logger.debug({ branch: resolvedRef.name }, "Checking out branch");
|
|
60
|
+
await checkoutBranch(requestDb)({
|
|
61
|
+
branchName: resolvedRef.name,
|
|
62
|
+
autoCommitPending: true
|
|
63
|
+
});
|
|
64
|
+
} else {
|
|
65
|
+
tempBranch = `temp_${resolvedRef.type}_${resolvedRef.hash}_${generateId()}`;
|
|
66
|
+
logger.debug({
|
|
67
|
+
tempBranch,
|
|
68
|
+
hash: resolvedRef.hash
|
|
69
|
+
}, "Creating temporary branch");
|
|
70
|
+
await connection.query(`SELECT DOLT_CHECKOUT('-b', $1, $2)`, [tempBranch, resolvedRef.hash]);
|
|
71
|
+
}
|
|
72
|
+
c.set("db", requestDb);
|
|
73
|
+
await next();
|
|
74
|
+
const status = c.res.status;
|
|
75
|
+
const projectDeleteOperation = isProjectDeleteOperation(c.req.path, method);
|
|
76
|
+
const operationSuccess = status >= 200 && status < 300;
|
|
77
|
+
if (resolvedRef.type === "branch" && operationSuccess && !projectDeleteOperation) try {
|
|
78
|
+
const statusResult = await doltStatus(requestDb)();
|
|
79
|
+
if (statusResult.length > 0 && operationSuccess) {
|
|
80
|
+
const path = c.req.path;
|
|
81
|
+
const commitMessage = generateCommitMessage(method, path);
|
|
82
|
+
logger.info({
|
|
83
|
+
branch: resolvedRef.name,
|
|
84
|
+
message: commitMessage
|
|
85
|
+
}, "Auto-committing changes");
|
|
86
|
+
await doltAddAndCommit(requestDb)({
|
|
87
|
+
message: commitMessage,
|
|
88
|
+
author: {
|
|
89
|
+
name: userId ?? "agents-api",
|
|
90
|
+
email: userEmail ?? "api@inkeep.com"
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
logger.info({ branch: resolvedRef.name }, "Successfully committed changes");
|
|
94
|
+
} else if (statusResult.length > 0 && !operationSuccess) {
|
|
95
|
+
await doltReset(requestDb)();
|
|
96
|
+
logger.info({ branch: resolvedRef.name }, "Successfully reset changes due to failed operation");
|
|
97
|
+
}
|
|
98
|
+
} catch (error) {
|
|
99
|
+
logger.error({
|
|
100
|
+
error,
|
|
101
|
+
branch: resolvedRef.name
|
|
102
|
+
}, "Failed to auto-commit changes");
|
|
103
|
+
}
|
|
104
|
+
} finally {
|
|
105
|
+
try {
|
|
106
|
+
await connection.query(`SELECT DOLT_CHECKOUT('main')`);
|
|
107
|
+
if (tempBranch) await connection.query(`SELECT DOLT_BRANCH('-D', $1)`, [tempBranch]);
|
|
108
|
+
} catch (cleanupError) {
|
|
109
|
+
logger.error({ error: cleanupError }, "Error during connection cleanup");
|
|
110
|
+
} finally {
|
|
111
|
+
connection.release();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* Generate a commit message based on HTTP method and path
|
|
117
|
+
*/
|
|
118
|
+
function generateCommitMessage(method, path) {
|
|
119
|
+
let operation;
|
|
120
|
+
switch (method) {
|
|
121
|
+
case "POST":
|
|
122
|
+
operation = "Create";
|
|
123
|
+
break;
|
|
124
|
+
case "PUT":
|
|
125
|
+
case "PATCH":
|
|
126
|
+
operation = "Update";
|
|
127
|
+
break;
|
|
128
|
+
case "DELETE":
|
|
129
|
+
operation = "Delete";
|
|
130
|
+
break;
|
|
131
|
+
default: operation = method;
|
|
132
|
+
}
|
|
133
|
+
return `${operation} ${path} via API`;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
//#endregion
|
|
137
|
+
export { branchScopedDbMiddleware, getPoolFromClient, isProjectDeleteOperation };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { cors } from "hono/cors";
|
|
2
|
+
|
|
3
|
+
//#region src/middleware/cors.d.ts
|
|
4
|
+
type CorsOptions = Parameters<typeof cors>[0];
|
|
5
|
+
/**
|
|
6
|
+
* Extract the base domain from a hostname (e.g., 'app.preview.inkeep.com' -> 'preview.inkeep.com')
|
|
7
|
+
*/
|
|
8
|
+
declare function getBaseDomain(hostname: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Check if a request origin is allowed for CORS
|
|
11
|
+
* Development: Allow any localhost origin
|
|
12
|
+
* Production: Allow same base domain or configured UI URL
|
|
13
|
+
*/
|
|
14
|
+
declare function isOriginAllowed(origin: string | undefined): origin is string;
|
|
15
|
+
/**
|
|
16
|
+
* CORS configuration for auth routes (Better Auth, session endpoints)
|
|
17
|
+
*/
|
|
18
|
+
declare const authCorsConfig: CorsOptions;
|
|
19
|
+
/**
|
|
20
|
+
* CORS configuration for default API routes
|
|
21
|
+
*/
|
|
22
|
+
declare const defaultCorsConfig: CorsOptions;
|
|
23
|
+
/**
|
|
24
|
+
* CORS configuration for playground routes
|
|
25
|
+
*/
|
|
26
|
+
declare const playgroundCorsConfig: CorsOptions;
|
|
27
|
+
/**
|
|
28
|
+
* CORS configuration for run routes (streaming, more permissive)
|
|
29
|
+
*/
|
|
30
|
+
declare const runCorsConfig: CorsOptions;
|
|
31
|
+
/**
|
|
32
|
+
* CORS configuration for SigNoz proxy routes
|
|
33
|
+
*/
|
|
34
|
+
declare const signozCorsConfig: CorsOptions;
|
|
35
|
+
//#endregion
|
|
36
|
+
export { authCorsConfig, defaultCorsConfig, getBaseDomain, isOriginAllowed, playgroundCorsConfig, runCorsConfig, signozCorsConfig };
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { env } from "../env.js";
|
|
2
|
+
|
|
3
|
+
//#region src/middleware/cors.ts
|
|
4
|
+
/**
|
|
5
|
+
* Extract the base domain from a hostname (e.g., 'app.preview.inkeep.com' -> 'preview.inkeep.com')
|
|
6
|
+
*/
|
|
7
|
+
function getBaseDomain(hostname) {
|
|
8
|
+
const parts = hostname.split(".");
|
|
9
|
+
if (parts.length >= 3) return parts.slice(-3).join(".");
|
|
10
|
+
return hostname;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Check if a request origin is allowed for CORS
|
|
14
|
+
* Development: Allow any localhost origin
|
|
15
|
+
* Production: Allow same base domain or configured UI URL
|
|
16
|
+
*/
|
|
17
|
+
function isOriginAllowed(origin) {
|
|
18
|
+
if (!origin) return false;
|
|
19
|
+
try {
|
|
20
|
+
const requestUrl = new URL(origin);
|
|
21
|
+
const apiUrl = new URL(env.INKEEP_AGENTS_API_URL || `http://localhost:3002`);
|
|
22
|
+
const uiUrl = env.INKEEP_AGENTS_MANAGE_UI_URL ? new URL(env.INKEEP_AGENTS_MANAGE_UI_URL) : null;
|
|
23
|
+
if (requestUrl.hostname === "localhost" || requestUrl.hostname === "127.0.0.1") return true;
|
|
24
|
+
if (uiUrl && requestUrl.hostname === uiUrl.hostname) return true;
|
|
25
|
+
if (getBaseDomain(requestUrl.hostname) === getBaseDomain(apiUrl.hostname)) return true;
|
|
26
|
+
return false;
|
|
27
|
+
} catch {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const originHandler = (origin) => isOriginAllowed(origin) ? origin : null;
|
|
32
|
+
/**
|
|
33
|
+
* CORS configuration for auth routes (Better Auth, session endpoints)
|
|
34
|
+
*/
|
|
35
|
+
const authCorsConfig = {
|
|
36
|
+
origin: originHandler,
|
|
37
|
+
allowHeaders: [
|
|
38
|
+
"content-type",
|
|
39
|
+
"Content-Type",
|
|
40
|
+
"authorization",
|
|
41
|
+
"Authorization",
|
|
42
|
+
"User-Agent"
|
|
43
|
+
],
|
|
44
|
+
allowMethods: [
|
|
45
|
+
"POST",
|
|
46
|
+
"GET",
|
|
47
|
+
"OPTIONS"
|
|
48
|
+
],
|
|
49
|
+
exposeHeaders: ["Content-Length"],
|
|
50
|
+
maxAge: 600,
|
|
51
|
+
credentials: true
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* CORS configuration for default API routes
|
|
55
|
+
*/
|
|
56
|
+
const defaultCorsConfig = {
|
|
57
|
+
origin: originHandler,
|
|
58
|
+
allowMethods: [
|
|
59
|
+
"GET",
|
|
60
|
+
"POST",
|
|
61
|
+
"PUT",
|
|
62
|
+
"DELETE",
|
|
63
|
+
"OPTIONS",
|
|
64
|
+
"PATCH"
|
|
65
|
+
],
|
|
66
|
+
allowHeaders: ["*"],
|
|
67
|
+
exposeHeaders: ["Content-Length"],
|
|
68
|
+
maxAge: 86400,
|
|
69
|
+
credentials: true
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* CORS configuration for playground routes
|
|
73
|
+
*/
|
|
74
|
+
const playgroundCorsConfig = {
|
|
75
|
+
origin: originHandler,
|
|
76
|
+
allowHeaders: [
|
|
77
|
+
"content-type",
|
|
78
|
+
"Content-Type",
|
|
79
|
+
"authorization",
|
|
80
|
+
"Authorization",
|
|
81
|
+
"User-Agent"
|
|
82
|
+
],
|
|
83
|
+
allowMethods: ["POST", "OPTIONS"],
|
|
84
|
+
exposeHeaders: ["Content-Length"],
|
|
85
|
+
maxAge: 600,
|
|
86
|
+
credentials: true
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* CORS configuration for run routes (streaming, more permissive)
|
|
90
|
+
*/
|
|
91
|
+
const runCorsConfig = {
|
|
92
|
+
origin: "*",
|
|
93
|
+
allowMethods: [
|
|
94
|
+
"GET",
|
|
95
|
+
"POST",
|
|
96
|
+
"PUT",
|
|
97
|
+
"DELETE",
|
|
98
|
+
"OPTIONS",
|
|
99
|
+
"PATCH"
|
|
100
|
+
],
|
|
101
|
+
allowHeaders: ["*"],
|
|
102
|
+
exposeHeaders: ["Content-Length"],
|
|
103
|
+
maxAge: 86400,
|
|
104
|
+
credentials: true
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* CORS configuration for SigNoz proxy routes
|
|
108
|
+
*/
|
|
109
|
+
const signozCorsConfig = {
|
|
110
|
+
origin: originHandler,
|
|
111
|
+
allowHeaders: [
|
|
112
|
+
"content-type",
|
|
113
|
+
"Content-Type",
|
|
114
|
+
"authorization",
|
|
115
|
+
"Authorization",
|
|
116
|
+
"User-Agent",
|
|
117
|
+
"Cookie",
|
|
118
|
+
"X-Forwarded-Cookie"
|
|
119
|
+
],
|
|
120
|
+
allowMethods: [
|
|
121
|
+
"GET",
|
|
122
|
+
"POST",
|
|
123
|
+
"OPTIONS"
|
|
124
|
+
],
|
|
125
|
+
exposeHeaders: ["Content-Length", "Set-Cookie"],
|
|
126
|
+
maxAge: 600,
|
|
127
|
+
credentials: true
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
//#endregion
|
|
131
|
+
export { authCorsConfig, defaultCorsConfig, getBaseDomain, isOriginAllowed, playgroundCorsConfig, runCorsConfig, signozCorsConfig };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Context } from "hono";
|
|
2
|
+
|
|
3
|
+
//#region src/middleware/errorHandler.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Global error handler for the Hono application
|
|
7
|
+
* Handles Zod validation errors, HTTP exceptions, and unexpected errors
|
|
8
|
+
* Returns RFC 7807 Problem Details format
|
|
9
|
+
*/
|
|
10
|
+
declare function errorHandler(err: Error, c: Context): Promise<Response>;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { errorHandler };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { getLogger as getLogger$1 } from "../logger.js";
|
|
2
|
+
import { handleApiError } from "@inkeep/agents-core";
|
|
3
|
+
import { HTTPException } from "hono/http-exception";
|
|
4
|
+
|
|
5
|
+
//#region src/middleware/errorHandler.ts
|
|
6
|
+
const logger = getLogger$1("error-handler");
|
|
7
|
+
/**
|
|
8
|
+
* Extract Zod validation issues from an error object
|
|
9
|
+
*/
|
|
10
|
+
function extractZodIssues(err) {
|
|
11
|
+
if (err && typeof err === "object") {
|
|
12
|
+
if ("cause" in err && err.cause && typeof err.cause === "object" && "issues" in err.cause) {
|
|
13
|
+
const issues = err.cause.issues;
|
|
14
|
+
if (Array.isArray(issues)) return issues;
|
|
15
|
+
}
|
|
16
|
+
if ("issues" in err && Array.isArray(err.issues)) return err.issues;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Format Zod validation errors into RFC 7807 problem detail format
|
|
21
|
+
*/
|
|
22
|
+
function formatZodValidationError(c, zodIssues) {
|
|
23
|
+
c.status(400);
|
|
24
|
+
c.header("Content-Type", "application/problem+json");
|
|
25
|
+
c.header("X-Content-Type-Options", "nosniff");
|
|
26
|
+
return c.json({
|
|
27
|
+
type: "https://docs.inkeep.com/agents-api/errors#bad_request",
|
|
28
|
+
title: "Validation Failed",
|
|
29
|
+
status: 400,
|
|
30
|
+
detail: "Request validation failed",
|
|
31
|
+
errors: zodIssues.map((issue) => ({
|
|
32
|
+
detail: issue.message,
|
|
33
|
+
pointer: issue.path ? `/${issue.path.join("/")}` : void 0,
|
|
34
|
+
name: issue.path ? issue.path.join(".") : void 0,
|
|
35
|
+
reason: issue.message
|
|
36
|
+
}))
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Log server errors with appropriate context
|
|
41
|
+
*/
|
|
42
|
+
function logServerError(err, path, requestId, status, isExpectedError) {
|
|
43
|
+
if (!isExpectedError) {
|
|
44
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
45
|
+
const errorStack = err instanceof Error ? err.stack : void 0;
|
|
46
|
+
logger.error({
|
|
47
|
+
error: err,
|
|
48
|
+
message: errorMessage,
|
|
49
|
+
stack: errorStack,
|
|
50
|
+
path,
|
|
51
|
+
requestId
|
|
52
|
+
}, "Unexpected server error occurred");
|
|
53
|
+
} else logger.error({
|
|
54
|
+
error: err,
|
|
55
|
+
path,
|
|
56
|
+
requestId,
|
|
57
|
+
status
|
|
58
|
+
}, "Server error occurred");
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Global error handler for the Hono application
|
|
62
|
+
* Handles Zod validation errors, HTTP exceptions, and unexpected errors
|
|
63
|
+
* Returns RFC 7807 Problem Details format
|
|
64
|
+
*/
|
|
65
|
+
async function errorHandler(err, c) {
|
|
66
|
+
const isExpectedError = err instanceof HTTPException;
|
|
67
|
+
const status = isExpectedError ? err.status : 500;
|
|
68
|
+
const requestId = c.get("requestId") || "unknown";
|
|
69
|
+
const zodIssues = extractZodIssues(err);
|
|
70
|
+
if (status === 400 && zodIssues) return formatZodValidationError(c, zodIssues);
|
|
71
|
+
if (status >= 500) logServerError(err, c.req.path, requestId, status, isExpectedError);
|
|
72
|
+
const errorResponse = await handleApiError(err, requestId);
|
|
73
|
+
c.status(errorResponse.status);
|
|
74
|
+
const responseBody = {
|
|
75
|
+
...errorResponse.code && { code: errorResponse.code },
|
|
76
|
+
title: errorResponse.title,
|
|
77
|
+
status: errorResponse.status,
|
|
78
|
+
detail: errorResponse.detail,
|
|
79
|
+
...errorResponse.instance && { instance: errorResponse.instance },
|
|
80
|
+
...errorResponse.error && { error: errorResponse.error }
|
|
81
|
+
};
|
|
82
|
+
c.header("Content-Type", "application/problem+json");
|
|
83
|
+
c.header("X-Content-Type-Options", "nosniff");
|
|
84
|
+
return c.body(JSON.stringify(responseBody));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
//#endregion
|
|
88
|
+
export { errorHandler };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as hono2 from "hono";
|
|
2
|
+
import { BaseExecutionContext } from "@inkeep/agents-core";
|
|
3
|
+
|
|
4
|
+
//#region src/middleware/evalsAuth.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Middleware to authenticate API requests using Bearer token authentication
|
|
8
|
+
* First checks if token matches INKEEP_AGENTS_EVAL_API_BYPASS_SECRET,
|
|
9
|
+
*/
|
|
10
|
+
declare const evalApiKeyAuth: () => hono2.MiddlewareHandler<{
|
|
11
|
+
Variables: {
|
|
12
|
+
executionContext: BaseExecutionContext;
|
|
13
|
+
};
|
|
14
|
+
}, string, {}, Response>;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { evalApiKeyAuth };
|