@graphoria/server 0.1.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/LICENSE +201 -0
- package/NOTICE +10 -0
- package/README.md +129 -0
- package/cli.ts +105 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/src/ai/agent/agent.d.ts +37 -0
- package/dist/src/ai/agent/agent.d.ts.map +1 -0
- package/dist/src/ai/agent/index.d.ts +3 -0
- package/dist/src/ai/agent/index.d.ts.map +1 -0
- package/dist/src/ai/agent/providers/anthropic.d.ts +10 -0
- package/dist/src/ai/agent/providers/anthropic.d.ts.map +1 -0
- package/dist/src/ai/agent/providers/index.d.ts +8 -0
- package/dist/src/ai/agent/providers/index.d.ts.map +1 -0
- package/dist/src/ai/agent/providers/ollama.d.ts +11 -0
- package/dist/src/ai/agent/providers/ollama.d.ts.map +1 -0
- package/dist/src/ai/agent/providers/openai.d.ts +14 -0
- package/dist/src/ai/agent/providers/openai.d.ts.map +1 -0
- package/dist/src/ai/agent/types.d.ts +51 -0
- package/dist/src/ai/agent/types.d.ts.map +1 -0
- package/dist/src/ai/ask-field.test.d.ts +2 -0
- package/dist/src/ai/ask-field.test.d.ts.map +1 -0
- package/dist/src/ai/index.d.ts +7 -0
- package/dist/src/ai/index.d.ts.map +1 -0
- package/dist/src/ai/mcp/create-server.d.ts +14 -0
- package/dist/src/ai/mcp/create-server.d.ts.map +1 -0
- package/dist/src/ai/mcp/create-server.test.d.ts +2 -0
- package/dist/src/ai/mcp/create-server.test.d.ts.map +1 -0
- package/dist/src/ai/mcp/index.d.ts +13 -0
- package/dist/src/ai/mcp/index.d.ts.map +1 -0
- package/dist/src/ai/mcp/index.test.d.ts +2 -0
- package/dist/src/ai/mcp/index.test.d.ts.map +1 -0
- package/dist/src/ai/mcp/instructions.d.ts +2 -0
- package/dist/src/ai/mcp/instructions.d.ts.map +1 -0
- package/dist/src/ai/tools/agent.d.ts +4 -0
- package/dist/src/ai/tools/agent.d.ts.map +1 -0
- package/dist/src/ai/tools/agent.test.d.ts +2 -0
- package/dist/src/ai/tools/agent.test.d.ts.map +1 -0
- package/dist/src/ai/tools/core.d.ts +75 -0
- package/dist/src/ai/tools/core.d.ts.map +1 -0
- package/dist/src/ai/tools/query-data.d.ts +35 -0
- package/dist/src/ai/tools/query-data.d.ts.map +1 -0
- package/dist/src/analyzeQuery/analyzers/fragmentAnalyzer.d.ts +5 -0
- package/dist/src/analyzeQuery/analyzers/fragmentAnalyzer.d.ts.map +1 -0
- package/dist/src/analyzeQuery/analyzers/operationAnalyzer.d.ts +6 -0
- package/dist/src/analyzeQuery/analyzers/operationAnalyzer.d.ts.map +1 -0
- package/dist/src/analyzeQuery/analyzers/selectionAnalyzer.d.ts +6 -0
- package/dist/src/analyzeQuery/analyzers/selectionAnalyzer.d.ts.map +1 -0
- package/dist/src/analyzeQuery/analyzers/variableAnalyzer.d.ts +4 -0
- package/dist/src/analyzeQuery/analyzers/variableAnalyzer.d.ts.map +1 -0
- package/dist/src/analyzeQuery/depthLimit.d.ts +16 -0
- package/dist/src/analyzeQuery/depthLimit.d.ts.map +1 -0
- package/dist/src/analyzeQuery/depthLimit.test.d.ts +2 -0
- package/dist/src/analyzeQuery/depthLimit.test.d.ts.map +1 -0
- package/dist/src/analyzeQuery/directiveUtils.d.ts +4 -0
- package/dist/src/analyzeQuery/directiveUtils.d.ts.map +1 -0
- package/dist/src/analyzeQuery/directiveUtils.test.d.ts +2 -0
- package/dist/src/analyzeQuery/directiveUtils.test.d.ts.map +1 -0
- package/dist/src/analyzeQuery/index.d.ts +5 -0
- package/dist/src/analyzeQuery/index.d.ts.map +1 -0
- package/dist/src/analyzeQuery/index.test.d.ts +2 -0
- package/dist/src/analyzeQuery/index.test.d.ts.map +1 -0
- package/dist/src/analyzeQuery/resolveVariables.d.ts +71 -0
- package/dist/src/analyzeQuery/resolveVariables.d.ts.map +1 -0
- package/dist/src/analyzeQuery/resolveVariables.test.d.ts +2 -0
- package/dist/src/analyzeQuery/resolveVariables.test.d.ts.map +1 -0
- package/dist/src/analyzeQuery/staticValues.test.d.ts +2 -0
- package/dist/src/analyzeQuery/staticValues.test.d.ts.map +1 -0
- package/dist/src/analyzeQuery/typeUtils.d.ts +9 -0
- package/dist/src/analyzeQuery/typeUtils.d.ts.map +1 -0
- package/dist/src/analyzeQuery/types.d.ts +54 -0
- package/dist/src/analyzeQuery/types.d.ts.map +1 -0
- package/dist/src/analyzeQuery/valueExtractors.d.ts +4 -0
- package/dist/src/analyzeQuery/valueExtractors.d.ts.map +1 -0
- package/dist/src/authentication/duration.d.ts +14 -0
- package/dist/src/authentication/duration.d.ts.map +1 -0
- package/dist/src/authentication/duration.test.d.ts +2 -0
- package/dist/src/authentication/duration.test.d.ts.map +1 -0
- package/dist/src/authentication/index.d.ts +4 -0
- package/dist/src/authentication/index.d.ts.map +1 -0
- package/dist/src/authentication/index.test.d.ts +2 -0
- package/dist/src/authentication/index.test.d.ts.map +1 -0
- package/dist/src/authentication/jwt.d.ts +10 -0
- package/dist/src/authentication/jwt.d.ts.map +1 -0
- package/dist/src/authentication/jwt.test.d.ts +2 -0
- package/dist/src/authentication/jwt.test.d.ts.map +1 -0
- package/dist/src/authentication/paseto.d.ts +7 -0
- package/dist/src/authentication/paseto.d.ts.map +1 -0
- package/dist/src/authentication/paseto.test.d.ts +2 -0
- package/dist/src/authentication/paseto.test.d.ts.map +1 -0
- package/dist/src/authentication/tokenRepository.d.ts +14 -0
- package/dist/src/authentication/tokenRepository.d.ts.map +1 -0
- package/dist/src/authentication/tokenRepository.test.d.ts +2 -0
- package/dist/src/authentication/tokenRepository.test.d.ts.map +1 -0
- package/dist/src/authentication/types.d.ts +42 -0
- package/dist/src/authentication/types.d.ts.map +1 -0
- package/dist/src/cli/seedAuth.d.ts +4 -0
- package/dist/src/cli/seedAuth.d.ts.map +1 -0
- package/dist/src/cli/seedAuth.test.d.ts +2 -0
- package/dist/src/cli/seedAuth.test.d.ts.map +1 -0
- package/dist/src/cli/seedAuthArgs.d.ts +9 -0
- package/dist/src/cli/seedAuthArgs.d.ts.map +1 -0
- package/dist/src/config/helpers/cronHelper.d.ts +21 -0
- package/dist/src/config/helpers/cronHelper.d.ts.map +1 -0
- package/dist/src/config/helpers/cronHelper.test.d.ts +2 -0
- package/dist/src/config/helpers/cronHelper.test.d.ts.map +1 -0
- package/dist/src/config/helpers/index.d.ts +4 -0
- package/dist/src/config/helpers/index.d.ts.map +1 -0
- package/dist/src/config/helpers/operationHelper.d.ts +44 -0
- package/dist/src/config/helpers/operationHelper.d.ts.map +1 -0
- package/dist/src/config/helpers/queueHelper.d.ts +20 -0
- package/dist/src/config/helpers/queueHelper.d.ts.map +1 -0
- package/dist/src/config/helpers/queueHelper.test.d.ts +2 -0
- package/dist/src/config/helpers/queueHelper.test.d.ts.map +1 -0
- package/dist/src/config/index.d.ts +236 -0
- package/dist/src/config/index.d.ts.map +1 -0
- package/dist/src/config/types/ai.d.ts +29 -0
- package/dist/src/config/types/ai.d.ts.map +1 -0
- package/dist/src/config/types/auth.d.ts +112 -0
- package/dist/src/config/types/auth.d.ts.map +1 -0
- package/dist/src/config/types/configuration.d.ts +61 -0
- package/dist/src/config/types/configuration.d.ts.map +1 -0
- package/dist/src/config/types/cron.d.ts +81 -0
- package/dist/src/config/types/cron.d.ts.map +1 -0
- package/dist/src/config/types/db.d.ts +210 -0
- package/dist/src/config/types/db.d.ts.map +1 -0
- package/dist/src/config/types/index.d.ts +17 -0
- package/dist/src/config/types/index.d.ts.map +1 -0
- package/dist/src/config/types/operation.d.ts +226 -0
- package/dist/src/config/types/operation.d.ts.map +1 -0
- package/dist/src/config/types/queue.d.ts +142 -0
- package/dist/src/config/types/queue.d.ts.map +1 -0
- package/dist/src/config/types/remote-rest.d.ts +18 -0
- package/dist/src/config/types/remote-rest.d.ts.map +1 -0
- package/dist/src/config/types/remote-schema.d.ts +27 -0
- package/dist/src/config/types/remote-schema.d.ts.map +1 -0
- package/dist/src/config/types/virtual-columns.d.ts +89 -0
- package/dist/src/config/types/virtual-columns.d.ts.map +1 -0
- package/dist/src/config/types/virtual-columns.test.d.ts +2 -0
- package/dist/src/config/types/virtual-columns.test.d.ts.map +1 -0
- package/dist/src/configuration/getSchemas/index.d.ts +867 -0
- package/dist/src/configuration/getSchemas/index.d.ts.map +1 -0
- package/dist/src/configuration/getSchemas/mergeEntities/index.d.ts +412 -0
- package/dist/src/configuration/getSchemas/mergeEntities/index.d.ts.map +1 -0
- package/dist/src/configuration/getSchemas/type-definition-generator/index.d.ts +16 -0
- package/dist/src/configuration/getSchemas/type-definition-generator/index.d.ts.map +1 -0
- package/dist/src/configuration/getSchemas/type-definition-generator/index.test.d.ts +2 -0
- package/dist/src/configuration/getSchemas/type-definition-generator/index.test.d.ts.map +1 -0
- package/dist/src/configuration/gql/buildExecute.d.ts +31 -0
- package/dist/src/configuration/gql/buildExecute.d.ts.map +1 -0
- package/dist/src/configuration/gql/buildExecute.test.d.ts +2 -0
- package/dist/src/configuration/gql/buildExecute.test.d.ts.map +1 -0
- package/dist/src/configuration/gql/gqlAuthOperations.d.ts +9 -0
- package/dist/src/configuration/gql/gqlAuthOperations.d.ts.map +1 -0
- package/dist/src/configuration/gql/gqlAuthOperations.test.d.ts +2 -0
- package/dist/src/configuration/gql/gqlAuthOperations.test.d.ts.map +1 -0
- package/dist/src/configuration/gql/handleGraphQLRequestFactory.d.ts +28 -0
- package/dist/src/configuration/gql/handleGraphQLRequestFactory.d.ts.map +1 -0
- package/dist/src/configuration/gql/handleGraphQLRequestFactory.test.d.ts +2 -0
- package/dist/src/configuration/gql/handleGraphQLRequestFactory.test.d.ts.map +1 -0
- package/dist/src/configuration/gql/handleGraphQLSubscriptionFactory.d.ts +19 -0
- package/dist/src/configuration/gql/handleGraphQLSubscriptionFactory.d.ts.map +1 -0
- package/dist/src/configuration/index.d.ts +719 -0
- package/dist/src/configuration/index.d.ts.map +1 -0
- package/dist/src/configuration/rest/generateOpenAPI.d.ts +19 -0
- package/dist/src/configuration/rest/generateOpenAPI.d.ts.map +1 -0
- package/dist/src/configuration/rest/handleRESTRequestFactory.d.ts +12 -0
- package/dist/src/configuration/rest/handleRESTRequestFactory.d.ts.map +1 -0
- package/dist/src/configuration/rest/handleRESTRequestFactory.test.d.ts +2 -0
- package/dist/src/configuration/rest/handleRESTRequestFactory.test.d.ts.map +1 -0
- package/dist/src/configuration/rest/index.d.ts +20 -0
- package/dist/src/configuration/rest/index.d.ts.map +1 -0
- package/dist/src/configuration/rest/openApiErrors.d.ts +71 -0
- package/dist/src/configuration/rest/openApiErrors.d.ts.map +1 -0
- package/dist/src/console/App.d.ts +3 -0
- package/dist/src/console/App.d.ts.map +1 -0
- package/dist/src/console/Login.d.ts +6 -0
- package/dist/src/console/Login.d.ts.map +1 -0
- package/dist/src/console/api.d.ts +17 -0
- package/dist/src/console/api.d.ts.map +1 -0
- package/dist/src/console/api.test.d.ts +2 -0
- package/dist/src/console/api.test.d.ts.map +1 -0
- package/dist/src/console/client.d.ts +67 -0
- package/dist/src/console/client.d.ts.map +1 -0
- package/dist/src/console/frontend.d.ts +8 -0
- package/dist/src/console/frontend.d.ts.map +1 -0
- package/dist/src/console/pages/ConfigPage.d.ts +2 -0
- package/dist/src/console/pages/ConfigPage.d.ts.map +1 -0
- package/dist/src/console/pages/RolesPage.d.ts +2 -0
- package/dist/src/console/pages/RolesPage.d.ts.map +1 -0
- package/dist/src/console/pages/StatusPage.d.ts +2 -0
- package/dist/src/console/pages/StatusPage.d.ts.map +1 -0
- package/dist/src/console/pages/TablesPage.d.ts +2 -0
- package/dist/src/console/pages/TablesPage.d.ts.map +1 -0
- package/dist/src/console/useApi.d.ts +8 -0
- package/dist/src/console/useApi.d.ts.map +1 -0
- package/dist/src/cron/index.d.ts +63 -0
- package/dist/src/cron/index.d.ts.map +1 -0
- package/dist/src/databases/auth/auth-operations.d.ts +11 -0
- package/dist/src/databases/auth/auth-operations.d.ts.map +1 -0
- package/dist/src/databases/auth/password.d.ts +3 -0
- package/dist/src/databases/auth/password.d.ts.map +1 -0
- package/dist/src/databases/auth/password.test.d.ts +2 -0
- package/dist/src/databases/auth/password.test.d.ts.map +1 -0
- package/dist/src/databases/common.d.ts +53 -0
- package/dist/src/databases/common.d.ts.map +1 -0
- package/dist/src/databases/common.test.d.ts +2 -0
- package/dist/src/databases/common.test.d.ts.map +1 -0
- package/dist/src/databases/core/executor.d.ts +10 -0
- package/dist/src/databases/core/executor.d.ts.map +1 -0
- package/dist/src/databases/core/executor.test.d.ts +2 -0
- package/dist/src/databases/core/executor.test.d.ts.map +1 -0
- package/dist/src/databases/core/function-mapping.d.ts +38 -0
- package/dist/src/databases/core/function-mapping.d.ts.map +1 -0
- package/dist/src/databases/core/identifier.d.ts +2 -0
- package/dist/src/databases/core/identifier.d.ts.map +1 -0
- package/dist/src/databases/core/identifier.test.d.ts +2 -0
- package/dist/src/databases/core/identifier.test.d.ts.map +1 -0
- package/dist/src/databases/core/query-builder.d.ts +64 -0
- package/dist/src/databases/core/query-builder.d.ts.map +1 -0
- package/dist/src/databases/core/query-builder.test.d.ts +2 -0
- package/dist/src/databases/core/query-builder.test.d.ts.map +1 -0
- package/dist/src/databases/directives.d.ts +16 -0
- package/dist/src/databases/directives.d.ts.map +1 -0
- package/dist/src/databases/directives.test.d.ts +2 -0
- package/dist/src/databases/directives.test.d.ts.map +1 -0
- package/dist/src/databases/engines/mssql/auth.d.ts +9 -0
- package/dist/src/databases/engines/mssql/auth.d.ts.map +1 -0
- package/dist/src/databases/engines/mssql/auth.test.d.ts +2 -0
- package/dist/src/databases/engines/mssql/auth.test.d.ts.map +1 -0
- package/dist/src/databases/engines/mssql/connection.d.ts +14 -0
- package/dist/src/databases/engines/mssql/connection.d.ts.map +1 -0
- package/dist/src/databases/engines/mssql/format.d.ts +5 -0
- package/dist/src/databases/engines/mssql/format.d.ts.map +1 -0
- package/dist/src/databases/engines/mssql/getStructure.d.ts +48 -0
- package/dist/src/databases/engines/mssql/getStructure.d.ts.map +1 -0
- package/dist/src/databases/engines/mssql/getViews.d.ts +7 -0
- package/dist/src/databases/engines/mssql/getViews.d.ts.map +1 -0
- package/dist/src/databases/engines/mssql/query/index.d.ts +7 -0
- package/dist/src/databases/engines/mssql/query/index.d.ts.map +1 -0
- package/dist/src/databases/engines/mssql/query/index.test.d.ts +2 -0
- package/dist/src/databases/engines/mssql/query/index.test.d.ts.map +1 -0
- package/dist/src/databases/engines/mysql/auth.d.ts +9 -0
- package/dist/src/databases/engines/mysql/auth.d.ts.map +1 -0
- package/dist/src/databases/engines/mysql/auth.test.d.ts +2 -0
- package/dist/src/databases/engines/mysql/auth.test.d.ts.map +1 -0
- package/dist/src/databases/engines/mysql/connection.d.ts +14 -0
- package/dist/src/databases/engines/mysql/connection.d.ts.map +1 -0
- package/dist/src/databases/engines/mysql/format.d.ts +5 -0
- package/dist/src/databases/engines/mysql/format.d.ts.map +1 -0
- package/dist/src/databases/engines/mysql/getStructure.d.ts +48 -0
- package/dist/src/databases/engines/mysql/getStructure.d.ts.map +1 -0
- package/dist/src/databases/engines/mysql/getViews.d.ts +7 -0
- package/dist/src/databases/engines/mysql/getViews.d.ts.map +1 -0
- package/dist/src/databases/engines/mysql/query/index.d.ts +7 -0
- package/dist/src/databases/engines/mysql/query/index.d.ts.map +1 -0
- package/dist/src/databases/engines/mysql/query/index.test.d.ts +2 -0
- package/dist/src/databases/engines/mysql/query/index.test.d.ts.map +1 -0
- package/dist/src/databases/engines/postgresql/auth.d.ts +9 -0
- package/dist/src/databases/engines/postgresql/auth.d.ts.map +1 -0
- package/dist/src/databases/engines/postgresql/auth.test.d.ts +2 -0
- package/dist/src/databases/engines/postgresql/auth.test.d.ts.map +1 -0
- package/dist/src/databases/engines/postgresql/connection.d.ts +14 -0
- package/dist/src/databases/engines/postgresql/connection.d.ts.map +1 -0
- package/dist/src/databases/engines/postgresql/format.d.ts +5 -0
- package/dist/src/databases/engines/postgresql/format.d.ts.map +1 -0
- package/dist/src/databases/engines/postgresql/getStructure.d.ts +48 -0
- package/dist/src/databases/engines/postgresql/getStructure.d.ts.map +1 -0
- package/dist/src/databases/engines/postgresql/getViews.d.ts +7 -0
- package/dist/src/databases/engines/postgresql/getViews.d.ts.map +1 -0
- package/dist/src/databases/engines/postgresql/query/index.d.ts +7 -0
- package/dist/src/databases/engines/postgresql/query/index.d.ts.map +1 -0
- package/dist/src/databases/engines/postgresql/query/index.test.d.ts +2 -0
- package/dist/src/databases/engines/postgresql/query/index.test.d.ts.map +1 -0
- package/dist/src/databases/engines/shared/claims.d.ts +2 -0
- package/dist/src/databases/engines/shared/claims.d.ts.map +1 -0
- package/dist/src/databases/engines/shared/types.d.ts +8 -0
- package/dist/src/databases/engines/shared/types.d.ts.map +1 -0
- package/dist/src/databases/high-level-operations.d.ts +146 -0
- package/dist/src/databases/high-level-operations.d.ts.map +1 -0
- package/dist/src/databases/high-level-operations.test.d.ts +2 -0
- package/dist/src/databases/high-level-operations.test.d.ts.map +1 -0
- package/dist/src/databases/index.d.ts +8 -0
- package/dist/src/databases/index.d.ts.map +1 -0
- package/dist/src/databases/metadata/structure.d.ts +56 -0
- package/dist/src/databases/metadata/structure.d.ts.map +1 -0
- package/dist/src/databases/schemaBuilder/convert.d.ts +2 -0
- package/dist/src/databases/schemaBuilder/convert.d.ts.map +1 -0
- package/dist/src/databases/schemaBuilder/generateCreateTable/index.d.ts +15 -0
- package/dist/src/databases/schemaBuilder/generateCreateTable/index.d.ts.map +1 -0
- package/dist/src/databases/schemaBuilder/generateCreateTable/index.test.d.ts +2 -0
- package/dist/src/databases/schemaBuilder/generateCreateTable/index.test.d.ts.map +1 -0
- package/dist/src/databases/schemaBuilder/generateCreateView/index.d.ts +18 -0
- package/dist/src/databases/schemaBuilder/generateCreateView/index.d.ts.map +1 -0
- package/dist/src/databases/schemaBuilder/generateInsert/index.d.ts +8 -0
- package/dist/src/databases/schemaBuilder/generateInsert/index.d.ts.map +1 -0
- package/dist/src/databases/schemaBuilder/generateInsert/index.test.d.ts +2 -0
- package/dist/src/databases/schemaBuilder/generateInsert/index.test.d.ts.map +1 -0
- package/dist/src/databases/schemaBuilder/generateSchemaCreation/index.d.ts +7 -0
- package/dist/src/databases/schemaBuilder/generateSchemaCreation/index.d.ts.map +1 -0
- package/dist/src/databases/schemaBuilder/generateSchemaCreation/index.test.d.ts +2 -0
- package/dist/src/databases/schemaBuilder/generateSchemaCreation/index.test.d.ts.map +1 -0
- package/dist/src/databases/schemaBuilder/mssqlToPostgres/convertView.d.ts +2 -0
- package/dist/src/databases/schemaBuilder/mssqlToPostgres/convertView.d.ts.map +1 -0
- package/dist/src/databases/schemaBuilder/utils.d.ts +8 -0
- package/dist/src/databases/schemaBuilder/utils.d.ts.map +1 -0
- package/dist/src/databases/sqlTypeUtils.d.ts +24 -0
- package/dist/src/databases/sqlTypeUtils.d.ts.map +1 -0
- package/dist/src/databases/sqlTypeUtils.test.d.ts +2 -0
- package/dist/src/databases/sqlTypeUtils.test.d.ts.map +1 -0
- package/dist/src/databases/transformers/data-transformers.d.ts +215 -0
- package/dist/src/databases/transformers/data-transformers.d.ts.map +1 -0
- package/dist/src/databases/transformers/data-transformers.test.d.ts +2 -0
- package/dist/src/databases/transformers/data-transformers.test.d.ts.map +1 -0
- package/dist/src/databases/transformers/genResolverName.d.ts +2 -0
- package/dist/src/databases/transformers/genResolverName.d.ts.map +1 -0
- package/dist/src/databases/transformers/genResolverName.test.d.ts +2 -0
- package/dist/src/databases/transformers/genResolverName.test.d.ts.map +1 -0
- package/dist/src/index.d.ts +139 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/logging/index.d.ts +21 -0
- package/dist/src/logging/index.d.ts.map +1 -0
- package/dist/src/queues/kafka.d.ts +22 -0
- package/dist/src/queues/kafka.d.ts.map +1 -0
- package/dist/src/queues/rabbitmq.d.ts +34 -0
- package/dist/src/queues/rabbitmq.d.ts.map +1 -0
- package/dist/src/queues/rabbitmq.test.d.ts +2 -0
- package/dist/src/queues/rabbitmq.test.d.ts.map +1 -0
- package/dist/src/remoteREST/index.d.ts +13 -0
- package/dist/src/remoteREST/index.d.ts.map +1 -0
- package/dist/src/remoteREST/parse.d.ts +8 -0
- package/dist/src/remoteREST/parse.d.ts.map +1 -0
- package/dist/src/remoteREST/parse.test.d.ts +2 -0
- package/dist/src/remoteREST/parse.test.d.ts.map +1 -0
- package/dist/src/remoteREST/proxy.d.ts +6 -0
- package/dist/src/remoteREST/proxy.d.ts.map +1 -0
- package/dist/src/remoteREST/proxy.test.d.ts +2 -0
- package/dist/src/remoteREST/proxy.test.d.ts.map +1 -0
- package/dist/src/remoteREST/transform.d.ts +8 -0
- package/dist/src/remoteREST/transform.d.ts.map +1 -0
- package/dist/src/remoteREST/transform.test.d.ts +2 -0
- package/dist/src/remoteREST/transform.test.d.ts.map +1 -0
- package/dist/src/remoteREST/types.d.ts +37 -0
- package/dist/src/remoteREST/types.d.ts.map +1 -0
- package/dist/src/remoteSchemas/index.d.ts +13 -0
- package/dist/src/remoteSchemas/index.d.ts.map +1 -0
- package/dist/src/remoteSchemas/introspect.d.ts +7 -0
- package/dist/src/remoteSchemas/introspect.d.ts.map +1 -0
- package/dist/src/remoteSchemas/introspect.test.d.ts +2 -0
- package/dist/src/remoteSchemas/introspect.test.d.ts.map +1 -0
- package/dist/src/remoteSchemas/proxy.d.ts +7 -0
- package/dist/src/remoteSchemas/proxy.d.ts.map +1 -0
- package/dist/src/remoteSchemas/proxy.test.d.ts +2 -0
- package/dist/src/remoteSchemas/proxy.test.d.ts.map +1 -0
- package/dist/src/remoteSchemas/transform.d.ts +9 -0
- package/dist/src/remoteSchemas/transform.d.ts.map +1 -0
- package/dist/src/remoteSchemas/transform.test.d.ts +2 -0
- package/dist/src/remoteSchemas/transform.test.d.ts.map +1 -0
- package/dist/src/remoteSchemas/types.d.ts +41 -0
- package/dist/src/remoteSchemas/types.d.ts.map +1 -0
- package/dist/src/singletons/ai.d.ts +25 -0
- package/dist/src/singletons/ai.d.ts.map +1 -0
- package/dist/src/singletons/ai.test.d.ts +2 -0
- package/dist/src/singletons/ai.test.d.ts.map +1 -0
- package/dist/src/singletons/authentication.d.ts +4 -0
- package/dist/src/singletons/authentication.d.ts.map +1 -0
- package/dist/src/singletons/cache/index.d.ts +5 -0
- package/dist/src/singletons/cache/index.d.ts.map +1 -0
- package/dist/src/singletons/cache/lruCacheStore.d.ts +12 -0
- package/dist/src/singletons/cache/lruCacheStore.d.ts.map +1 -0
- package/dist/src/singletons/cache/lruCacheStore.test.d.ts +2 -0
- package/dist/src/singletons/cache/lruCacheStore.test.d.ts.map +1 -0
- package/dist/src/singletons/cache/redisCacheStore.d.ts +16 -0
- package/dist/src/singletons/cache/redisCacheStore.d.ts.map +1 -0
- package/dist/src/singletons/cache/redisClient.d.ts +3 -0
- package/dist/src/singletons/cache/redisClient.d.ts.map +1 -0
- package/dist/src/singletons/cache/registry.d.ts +7 -0
- package/dist/src/singletons/cache/registry.d.ts.map +1 -0
- package/dist/src/singletons/cache/registry.test.d.ts +2 -0
- package/dist/src/singletons/cache/registry.test.d.ts.map +1 -0
- package/dist/src/singletons/cache/types.d.ts +8 -0
- package/dist/src/singletons/cache/types.d.ts.map +1 -0
- package/dist/src/singletons/cron.d.ts +69 -0
- package/dist/src/singletons/cron.d.ts.map +1 -0
- package/dist/src/singletons/databases.d.ts +27 -0
- package/dist/src/singletons/databases.d.ts.map +1 -0
- package/dist/src/singletons/databases.test.d.ts +2 -0
- package/dist/src/singletons/databases.test.d.ts.map +1 -0
- package/dist/src/singletons/env.d.ts +494 -0
- package/dist/src/singletons/env.d.ts.map +1 -0
- package/dist/src/singletons/queues.d.ts +17 -0
- package/dist/src/singletons/queues.d.ts.map +1 -0
- package/dist/src/subscriptions/index.d.ts +4 -0
- package/dist/src/subscriptions/index.d.ts.map +1 -0
- package/dist/src/subscriptions/strategies/database.d.ts +12 -0
- package/dist/src/subscriptions/strategies/database.d.ts.map +1 -0
- package/dist/src/subscriptions/strategies/index.d.ts +12 -0
- package/dist/src/subscriptions/strategies/index.d.ts.map +1 -0
- package/dist/src/subscriptions/strategies/queue.d.ts +11 -0
- package/dist/src/subscriptions/strategies/queue.d.ts.map +1 -0
- package/dist/src/subscriptions/types.d.ts +67 -0
- package/dist/src/subscriptions/types.d.ts.map +1 -0
- package/dist/src/subscriptions/utils/polling.d.ts +17 -0
- package/dist/src/subscriptions/utils/polling.d.ts.map +1 -0
- package/dist/src/types/common.d.ts +44 -0
- package/dist/src/types/common.d.ts.map +1 -0
- package/dist/src/types/configuration.d.ts +28 -0
- package/dist/src/types/configuration.d.ts.map +1 -0
- package/dist/src/types/db.d.ts +43 -0
- package/dist/src/types/db.d.ts.map +1 -0
- package/dist/src/types/env.d.ts +2302 -0
- package/dist/src/types/env.d.ts.map +1 -0
- package/dist/src/types/env.test.d.ts +2 -0
- package/dist/src/types/env.test.d.ts.map +1 -0
- package/dist/src/types/resolver.d.ts +121 -0
- package/dist/src/types/resolver.d.ts.map +1 -0
- package/dist/src/types/zod/ai.d.ts +6 -0
- package/dist/src/types/zod/ai.d.ts.map +1 -0
- package/dist/src/types/zod/auth.d.ts +76 -0
- package/dist/src/types/zod/auth.d.ts.map +1 -0
- package/dist/src/types/zod/configuration.d.ts +1278 -0
- package/dist/src/types/zod/configuration.d.ts.map +1 -0
- package/dist/src/types/zod/configuration.test.d.ts +2 -0
- package/dist/src/types/zod/configuration.test.d.ts.map +1 -0
- package/dist/src/types/zod/cron.d.ts +32 -0
- package/dist/src/types/zod/cron.d.ts.map +1 -0
- package/dist/src/types/zod/db.d.ts +441 -0
- package/dist/src/types/zod/db.d.ts.map +1 -0
- package/dist/src/types/zod/db.test.d.ts +2 -0
- package/dist/src/types/zod/db.test.d.ts.map +1 -0
- package/dist/src/types/zod/mcp.d.ts +6 -0
- package/dist/src/types/zod/mcp.d.ts.map +1 -0
- package/dist/src/types/zod/operation.d.ts +9 -0
- package/dist/src/types/zod/operation.d.ts.map +1 -0
- package/dist/src/types/zod/queue.d.ts +656 -0
- package/dist/src/types/zod/queue.d.ts.map +1 -0
- package/dist/src/types/zod/queue.test.d.ts +2 -0
- package/dist/src/types/zod/queue.test.d.ts.map +1 -0
- package/dist/src/types/zod/remoteREST.d.ts +6 -0
- package/dist/src/types/zod/remoteREST.d.ts.map +1 -0
- package/dist/src/types/zod/remoteSchema.d.ts +6 -0
- package/dist/src/types/zod/remoteSchema.d.ts.map +1 -0
- package/dist/src/utils/benchmark.d.ts +2 -0
- package/dist/src/utils/benchmark.d.ts.map +1 -0
- package/dist/src/utils/event-emitter.d.ts +19 -0
- package/dist/src/utils/event-emitter.d.ts.map +1 -0
- package/dist/src/utils/responses.d.ts +19 -0
- package/dist/src/utils/responses.d.ts.map +1 -0
- package/dist/src/utils/responses.test.d.ts +2 -0
- package/dist/src/utils/responses.test.d.ts.map +1 -0
- package/dist/src/utils/safeJSONParse.d.ts +2 -0
- package/dist/src/utils/safeJSONParse.d.ts.map +1 -0
- package/dist/src/utils/selection.d.ts +3 -0
- package/dist/src/utils/selection.d.ts.map +1 -0
- package/dist/src/utils/selection.test.d.ts +2 -0
- package/dist/src/utils/selection.test.d.ts.map +1 -0
- package/dist/src/utils/sessionVariables.d.ts +47 -0
- package/dist/src/utils/sessionVariables.d.ts.map +1 -0
- package/dist/src/utils/sessionVariables.test.d.ts +2 -0
- package/dist/src/utils/sessionVariables.test.d.ts.map +1 -0
- package/dist/src/utils/writeSchema.d.ts +3 -0
- package/dist/src/utils/writeSchema.d.ts.map +1 -0
- package/dist/standalone.d.ts +3 -0
- package/dist/standalone.d.ts.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +119 -0
- package/playgrounds/console/index.html +25 -0
- package/playgrounds/graphiql/index.html +1144 -0
- package/playgrounds/scalar/index.html +19 -0
- package/src/ai/agent/agent.ts +222 -0
- package/src/ai/agent/index.ts +2 -0
- package/src/ai/agent/providers/anthropic.ts +113 -0
- package/src/ai/agent/providers/index.ts +62 -0
- package/src/ai/agent/providers/ollama.ts +128 -0
- package/src/ai/agent/providers/openai.ts +100 -0
- package/src/ai/agent/types.ts +65 -0
- package/src/ai/index.ts +8 -0
- package/src/ai/mcp/create-server.ts +444 -0
- package/src/ai/mcp/index.ts +80 -0
- package/src/ai/mcp/instructions.ts +103 -0
- package/src/ai/tools/agent.ts +111 -0
- package/src/ai/tools/core.ts +486 -0
- package/src/ai/tools/query-data.ts +109 -0
- package/src/analyzeQuery/analyzers/fragmentAnalyzer.ts +29 -0
- package/src/analyzeQuery/analyzers/operationAnalyzer.ts +50 -0
- package/src/analyzeQuery/analyzers/selectionAnalyzer.ts +135 -0
- package/src/analyzeQuery/analyzers/variableAnalyzer.ts +17 -0
- package/src/analyzeQuery/depthLimit.ts +124 -0
- package/src/analyzeQuery/directiveUtils.ts +99 -0
- package/src/analyzeQuery/index.ts +66 -0
- package/src/analyzeQuery/resolveVariables.ts +394 -0
- package/src/analyzeQuery/typeUtils.ts +47 -0
- package/src/analyzeQuery/types.ts +57 -0
- package/src/analyzeQuery/valueExtractors.ts +96 -0
- package/src/authentication/duration.ts +50 -0
- package/src/authentication/index.ts +34 -0
- package/src/authentication/jwt.ts +220 -0
- package/src/authentication/paseto.ts +256 -0
- package/src/authentication/tokenRepository.ts +75 -0
- package/src/authentication/types.ts +78 -0
- package/src/cli/seedAuth.ts +51 -0
- package/src/cli/seedAuthArgs.ts +50 -0
- package/src/config/helpers/cronHelper.ts +29 -0
- package/src/config/helpers/index.ts +8 -0
- package/src/config/helpers/operationHelper.ts +146 -0
- package/src/config/helpers/queueHelper.ts +27 -0
- package/src/config/index.ts +315 -0
- package/src/config/types/ai.ts +35 -0
- package/src/config/types/auth.ts +147 -0
- package/src/config/types/configuration.ts +69 -0
- package/src/config/types/cron.ts +140 -0
- package/src/config/types/db.ts +256 -0
- package/src/config/types/index.ts +129 -0
- package/src/config/types/operation.ts +253 -0
- package/src/config/types/queue.ts +172 -0
- package/src/config/types/remote-rest.ts +28 -0
- package/src/config/types/remote-schema.ts +39 -0
- package/src/config/types/virtual-columns.ts +157 -0
- package/src/configuration/getSchemas/index.ts +82 -0
- package/src/configuration/getSchemas/mergeEntities/index.ts +221 -0
- package/src/configuration/getSchemas/type-definition-generator/index.ts +511 -0
- package/src/configuration/gql/buildExecute.ts +54 -0
- package/src/configuration/gql/gqlAuthOperations.ts +150 -0
- package/src/configuration/gql/handleGraphQLRequestFactory.ts +415 -0
- package/src/configuration/gql/handleGraphQLSubscriptionFactory.ts +249 -0
- package/src/configuration/index.ts +138 -0
- package/src/configuration/rest/generateOpenAPI.ts +361 -0
- package/src/configuration/rest/handleRESTRequestFactory.ts +335 -0
- package/src/configuration/rest/index.ts +167 -0
- package/src/configuration/rest/openApiErrors.ts +106 -0
- package/src/console/api.ts +270 -0
- package/src/cron/index.ts +251 -0
- package/src/databases/auth/auth-operations.ts +36 -0
- package/src/databases/auth/password.ts +4 -0
- package/src/databases/common.ts +642 -0
- package/src/databases/core/executor.ts +97 -0
- package/src/databases/core/function-mapping.ts +176 -0
- package/src/databases/core/identifier.ts +8 -0
- package/src/databases/core/query-builder.ts +47 -0
- package/src/databases/directives.ts +112 -0
- package/src/databases/engines/mssql/auth.ts +112 -0
- package/src/databases/engines/mssql/connection.ts +151 -0
- package/src/databases/engines/mssql/format.ts +23 -0
- package/src/databases/engines/mssql/getStructure.ts +112 -0
- package/src/databases/engines/mssql/getViews.ts +17 -0
- package/src/databases/engines/mssql/query/index.ts +306 -0
- package/src/databases/engines/mysql/auth.ts +100 -0
- package/src/databases/engines/mysql/connection.ts +100 -0
- package/src/databases/engines/mysql/format.ts +23 -0
- package/src/databases/engines/mysql/getStructure.ts +116 -0
- package/src/databases/engines/mysql/getViews.ts +20 -0
- package/src/databases/engines/mysql/query/index.ts +291 -0
- package/src/databases/engines/postgresql/auth.ts +98 -0
- package/src/databases/engines/postgresql/connection.ts +99 -0
- package/src/databases/engines/postgresql/format.ts +23 -0
- package/src/databases/engines/postgresql/getStructure.ts +149 -0
- package/src/databases/engines/postgresql/getViews.ts +20 -0
- package/src/databases/engines/postgresql/query/index.ts +291 -0
- package/src/databases/engines/shared/claims.ts +26 -0
- package/src/databases/engines/shared/types.ts +7 -0
- package/src/databases/high-level-operations.ts +272 -0
- package/src/databases/index.ts +28 -0
- package/src/databases/metadata/structure.ts +12 -0
- package/src/databases/schemaBuilder/convert.ts +121 -0
- package/src/databases/schemaBuilder/generateCreateTable/index.ts +133 -0
- package/src/databases/schemaBuilder/generateCreateView/index.ts +101 -0
- package/src/databases/schemaBuilder/generateInsert/index.ts +47 -0
- package/src/databases/schemaBuilder/generateSchemaCreation/index.ts +29 -0
- package/src/databases/schemaBuilder/mssqlToPostgres/convertView.ts +47 -0
- package/src/databases/schemaBuilder/utils.ts +17 -0
- package/src/databases/sqlTypeUtils.ts +91 -0
- package/src/databases/transformers/data-transformers.ts +128 -0
- package/src/databases/transformers/genResolverName.ts +18 -0
- package/src/index.ts +461 -0
- package/src/logging/index.ts +69 -0
- package/src/queues/kafka.ts +409 -0
- package/src/queues/rabbitmq.ts +331 -0
- package/src/remoteREST/index.ts +46 -0
- package/src/remoteREST/parse.ts +68 -0
- package/src/remoteREST/proxy.ts +92 -0
- package/src/remoteREST/transform.ts +121 -0
- package/src/remoteREST/types.ts +38 -0
- package/src/remoteSchemas/index.ts +48 -0
- package/src/remoteSchemas/introspect.ts +44 -0
- package/src/remoteSchemas/proxy.ts +146 -0
- package/src/remoteSchemas/transform.ts +210 -0
- package/src/remoteSchemas/types.ts +43 -0
- package/src/singletons/ai.ts +91 -0
- package/src/singletons/authentication.ts +13 -0
- package/src/singletons/cache/index.ts +4 -0
- package/src/singletons/cache/lruCacheStore.ts +34 -0
- package/src/singletons/cache/redisCacheStore.ts +81 -0
- package/src/singletons/cache/redisClient.ts +12 -0
- package/src/singletons/cache/registry.ts +51 -0
- package/src/singletons/cache/types.ts +7 -0
- package/src/singletons/cron.ts +21 -0
- package/src/singletons/databases.ts +68 -0
- package/src/singletons/env.ts +3 -0
- package/src/singletons/queues.ts +101 -0
- package/src/subscriptions/index.ts +20 -0
- package/src/subscriptions/strategies/database.ts +68 -0
- package/src/subscriptions/strategies/index.ts +38 -0
- package/src/subscriptions/strategies/queue.ts +61 -0
- package/src/subscriptions/types.ts +74 -0
- package/src/subscriptions/utils/polling.ts +119 -0
- package/src/types/common.ts +57 -0
- package/src/types/configuration.ts +52 -0
- package/src/types/db.ts +87 -0
- package/src/types/env.ts +137 -0
- package/src/types/resolver.ts +181 -0
- package/src/types/zod/ai.ts +8 -0
- package/src/types/zod/auth.ts +96 -0
- package/src/types/zod/configuration.ts +46 -0
- package/src/types/zod/cron.ts +35 -0
- package/src/types/zod/db.ts +146 -0
- package/src/types/zod/mcp.ts +8 -0
- package/src/types/zod/operation.ts +37 -0
- package/src/types/zod/queue.ts +182 -0
- package/src/types/zod/remoteREST.ts +8 -0
- package/src/types/zod/remoteSchema.ts +11 -0
- package/src/utils/benchmark.ts +13 -0
- package/src/utils/event-emitter.ts +217 -0
- package/src/utils/responses.ts +42 -0
- package/src/utils/safeJSONParse.ts +10 -0
- package/src/utils/selection.ts +35 -0
- package/src/utils/sessionVariables.ts +131 -0
- package/src/utils/writeSchema.ts +13 -0
- package/standalone.ts +32 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { RemoteSchemaConfig } from "../config";
|
|
2
|
+
import type { RemoteSchemaResolved } from "./types";
|
|
3
|
+
|
|
4
|
+
import { introspectRemoteSchema } from "./introspect";
|
|
5
|
+
import { transformRemoteSchema } from "./transform";
|
|
6
|
+
import { logger } from "../logging";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Resolve a single remote schema: introspect → transform → produce RemoteSchemaResolved
|
|
10
|
+
*/
|
|
11
|
+
export const resolveRemoteSchema = async (
|
|
12
|
+
config: RemoteSchemaConfig,
|
|
13
|
+
): Promise<RemoteSchemaResolved> => {
|
|
14
|
+
const schema = await introspectRemoteSchema(config);
|
|
15
|
+
return transformRemoteSchema(schema, config);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Resolve all enabled remote schemas in parallel.
|
|
20
|
+
* Returns an array of successfully resolved schemas; logs warnings for failures.
|
|
21
|
+
*/
|
|
22
|
+
export const resolveRemoteSchemas = async (
|
|
23
|
+
configs: RemoteSchemaConfig[],
|
|
24
|
+
): Promise<RemoteSchemaResolved[]> => {
|
|
25
|
+
const enabled = configs.filter((c) => c.enabled !== false);
|
|
26
|
+
|
|
27
|
+
if (enabled.length === 0) return [];
|
|
28
|
+
|
|
29
|
+
const results = await Promise.allSettled(enabled.map((config) => resolveRemoteSchema(config)));
|
|
30
|
+
|
|
31
|
+
const resolved: RemoteSchemaResolved[] = [];
|
|
32
|
+
|
|
33
|
+
for (let i = 0; i < results.length; i++) {
|
|
34
|
+
const result = results[i];
|
|
35
|
+
if (result.status === "fulfilled") {
|
|
36
|
+
resolved.push(result.value);
|
|
37
|
+
} else {
|
|
38
|
+
logger("remote-schemas").warn(
|
|
39
|
+
{ schema: enabled[i].name, err: result.reason },
|
|
40
|
+
"failed to introspect remote schema",
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return resolved;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export type { RemoteSchemaResolved } from "./types";
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { buildClientSchema, getIntrospectionQuery } from "graphql";
|
|
2
|
+
|
|
3
|
+
import type { RemoteSchemaConfig } from "../config";
|
|
4
|
+
import type { GraphQLSchema, IntrospectionQuery } from "graphql";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Send an introspection query to a remote GraphQL endpoint and return the parsed schema.
|
|
8
|
+
*/
|
|
9
|
+
export const introspectRemoteSchema = async (
|
|
10
|
+
config: RemoteSchemaConfig,
|
|
11
|
+
): Promise<GraphQLSchema> => {
|
|
12
|
+
const headers: Record<string, string> = {
|
|
13
|
+
"Content-Type": "application/json",
|
|
14
|
+
...(config.headers ?? {}),
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const controller = new AbortController();
|
|
18
|
+
const timeoutId = setTimeout(() => controller.abort(), config.timeout ?? 10000);
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
const response = await fetch(config.url, {
|
|
22
|
+
method: "POST",
|
|
23
|
+
headers,
|
|
24
|
+
body: JSON.stringify({ query: getIntrospectionQuery() }),
|
|
25
|
+
signal: controller.signal,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
if (!response.ok) {
|
|
29
|
+
throw new Error(
|
|
30
|
+
`Remote schema "${config.name}" introspection failed: HTTP ${response.status}`,
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const json = (await response.json()) as { data?: IntrospectionQuery };
|
|
35
|
+
|
|
36
|
+
if (!json.data) {
|
|
37
|
+
throw new Error(`Remote schema "${config.name}" introspection returned no data`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return buildClientSchema(json.data);
|
|
41
|
+
} finally {
|
|
42
|
+
clearTimeout(timeoutId);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import type { SelectionAnalysis } from "../analyzeQuery/types";
|
|
2
|
+
import type { RemoteSchemaResolved } from "./types";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Build the sub-query string for a remote field by stripping the prefix from
|
|
6
|
+
* the field name and type references.
|
|
7
|
+
*/
|
|
8
|
+
const buildRemoteSubQuery = (
|
|
9
|
+
field: SelectionAnalysis,
|
|
10
|
+
originalFieldName: string,
|
|
11
|
+
prefixMap: RemoteSchemaResolved["prefixMap"],
|
|
12
|
+
): string => {
|
|
13
|
+
const args = buildArgumentsString(field.arguments);
|
|
14
|
+
const selections = field.selections?.length
|
|
15
|
+
? ` { ${buildSelectionsString(field.selections, prefixMap)} }`
|
|
16
|
+
: "";
|
|
17
|
+
|
|
18
|
+
return `${originalFieldName}${args}${selections}`;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Recursively build a selections string, un-prefixing any type references in inline fragments.
|
|
23
|
+
*/
|
|
24
|
+
const buildSelectionsString = (
|
|
25
|
+
selections: SelectionAnalysis[],
|
|
26
|
+
prefixMap: RemoteSchemaResolved["prefixMap"],
|
|
27
|
+
): string =>
|
|
28
|
+
selections
|
|
29
|
+
.map((sel) => {
|
|
30
|
+
const subSelections = sel.selections?.length
|
|
31
|
+
? ` { ${buildSelectionsString(sel.selections, prefixMap)} }`
|
|
32
|
+
: "";
|
|
33
|
+
|
|
34
|
+
const aliasPrefix = sel.alias ? `${sel.alias}: ` : "";
|
|
35
|
+
return `${aliasPrefix}${sel.name}${buildArgumentsString(sel.arguments)}${subSelections}`;
|
|
36
|
+
})
|
|
37
|
+
.join(" ");
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Serialize arguments back to GraphQL argument syntax.
|
|
41
|
+
*/
|
|
42
|
+
const buildArgumentsString = (args: Record<string, unknown> | undefined): string => {
|
|
43
|
+
if (!args || Object.keys(args).length === 0) return "";
|
|
44
|
+
|
|
45
|
+
const parts = Object.entries(args).map(([key, value]) => `${key}: ${serializeValue(value)}`);
|
|
46
|
+
|
|
47
|
+
return `(${parts.join(", ")})`;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Serialize a value to GraphQL literal syntax.
|
|
52
|
+
*/
|
|
53
|
+
const serializeValue = (value: unknown): string => {
|
|
54
|
+
if (value === null || value === undefined) return "null";
|
|
55
|
+
if (typeof value === "string") return JSON.stringify(value);
|
|
56
|
+
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
57
|
+
if (Array.isArray(value)) return `[${value.map(serializeValue).join(", ")}]`;
|
|
58
|
+
if (typeof value === "object") {
|
|
59
|
+
const entries = Object.entries(value as Record<string, unknown>).map(
|
|
60
|
+
([k, v]) => `${k}: ${serializeValue(v)}`,
|
|
61
|
+
);
|
|
62
|
+
return `{${entries.join(", ")}}`;
|
|
63
|
+
}
|
|
64
|
+
return String(value);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Build headers for the remote request by merging:
|
|
69
|
+
* 1. Static headers from configuration
|
|
70
|
+
* 2. Forwarded headers from the client request
|
|
71
|
+
*/
|
|
72
|
+
const buildHeaders = (
|
|
73
|
+
config: RemoteSchemaResolved["config"],
|
|
74
|
+
clientRequest?: Request,
|
|
75
|
+
): Record<string, string> => {
|
|
76
|
+
const headers: Record<string, string> = {
|
|
77
|
+
"Content-Type": "application/json",
|
|
78
|
+
...(config.headers ?? {}),
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
if (clientRequest && config.forwardHeaders?.length) {
|
|
82
|
+
for (const headerName of config.forwardHeaders) {
|
|
83
|
+
const value = clientRequest.headers.get(headerName);
|
|
84
|
+
if (value) {
|
|
85
|
+
headers[headerName] = value;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return headers;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Execute a proxied GraphQL query/mutation against a remote schema endpoint.
|
|
95
|
+
*/
|
|
96
|
+
export const proxyRemoteField = async (
|
|
97
|
+
field: SelectionAnalysis,
|
|
98
|
+
remoteSchema: RemoteSchemaResolved,
|
|
99
|
+
originalFieldName: string,
|
|
100
|
+
variables: Record<string, unknown>,
|
|
101
|
+
operationType: "query" | "mutation",
|
|
102
|
+
clientRequest?: Request,
|
|
103
|
+
): Promise<unknown> => {
|
|
104
|
+
const subQuery = buildRemoteSubQuery(field, originalFieldName, remoteSchema.prefixMap);
|
|
105
|
+
|
|
106
|
+
const fullQuery = `${operationType} { ${subQuery} }`;
|
|
107
|
+
|
|
108
|
+
const headers = buildHeaders(remoteSchema.config, clientRequest);
|
|
109
|
+
|
|
110
|
+
const controller = new AbortController();
|
|
111
|
+
const timeoutId = setTimeout(() => controller.abort(), remoteSchema.config.timeout ?? 10000);
|
|
112
|
+
|
|
113
|
+
try {
|
|
114
|
+
const response = await fetch(remoteSchema.config.url, {
|
|
115
|
+
method: "POST",
|
|
116
|
+
headers,
|
|
117
|
+
body: JSON.stringify({
|
|
118
|
+
query: fullQuery,
|
|
119
|
+
variables,
|
|
120
|
+
}),
|
|
121
|
+
signal: controller.signal,
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
if (!response.ok) {
|
|
125
|
+
throw new Error(
|
|
126
|
+
`Remote schema "${remoteSchema.config.name}" returned HTTP ${response.status}`,
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const json = (await response.json()) as {
|
|
131
|
+
data?: Record<string, unknown>;
|
|
132
|
+
errors?: Array<{ message: string }>;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
if (json.errors?.length) {
|
|
136
|
+
throw new Error(
|
|
137
|
+
`Remote schema "${remoteSchema.config.name}" error: ${json.errors[0].message}`,
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Extract the result for the original field name
|
|
142
|
+
return json.data?.[originalFieldName] ?? null;
|
|
143
|
+
} finally {
|
|
144
|
+
clearTimeout(timeoutId);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isEnumType,
|
|
3
|
+
isInputObjectType,
|
|
4
|
+
isListType,
|
|
5
|
+
isNonNullType,
|
|
6
|
+
isObjectType,
|
|
7
|
+
isScalarType,
|
|
8
|
+
isUnionType,
|
|
9
|
+
} from "graphql";
|
|
10
|
+
|
|
11
|
+
import type { RemoteSchemaConfig } from "../config";
|
|
12
|
+
import type {
|
|
13
|
+
GraphQLArgument,
|
|
14
|
+
GraphQLField,
|
|
15
|
+
GraphQLNamedType,
|
|
16
|
+
GraphQLSchema,
|
|
17
|
+
GraphQLType,
|
|
18
|
+
} from "graphql";
|
|
19
|
+
import type { PrefixMap, RemoteSchemaField, RemoteSchemaResolved } from "./types";
|
|
20
|
+
|
|
21
|
+
// Built-in GraphQL scalar names that must not be prefixed
|
|
22
|
+
const BUILTIN_SCALARS = new Set(["String", "Int", "Float", "Boolean", "ID"]);
|
|
23
|
+
|
|
24
|
+
// Built-in introspection types
|
|
25
|
+
const INTROSPECTION_TYPES = new Set([
|
|
26
|
+
"__Schema",
|
|
27
|
+
"__Type",
|
|
28
|
+
"__Field",
|
|
29
|
+
"__InputValue",
|
|
30
|
+
"__EnumValue",
|
|
31
|
+
"__Directive",
|
|
32
|
+
"__DirectiveLocation",
|
|
33
|
+
]);
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Determine if a named type should be prefixed
|
|
37
|
+
*/
|
|
38
|
+
const shouldPrefix = (typeName: string): boolean =>
|
|
39
|
+
!BUILTIN_SCALARS.has(typeName) && !INTROSPECTION_TYPES.has(typeName);
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Prefix a type name if it should be prefixed
|
|
43
|
+
*/
|
|
44
|
+
const prefixTypeName = (name: string, prefix: string): string =>
|
|
45
|
+
shouldPrefix(name) ? `${prefix}${name}` : name;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Convert a GraphQL type reference to SDL string with prefixing
|
|
49
|
+
*/
|
|
50
|
+
const typeToSDL = (type: GraphQLType, prefix: string): string => {
|
|
51
|
+
if (isNonNullType(type)) {
|
|
52
|
+
return `${typeToSDL(type.ofType, prefix)}!`;
|
|
53
|
+
}
|
|
54
|
+
if (isListType(type)) {
|
|
55
|
+
return `[${typeToSDL(type.ofType, prefix)}]`;
|
|
56
|
+
}
|
|
57
|
+
const named = type as GraphQLNamedType;
|
|
58
|
+
return prefixTypeName(named.name, prefix);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Convert a GraphQL argument to SDL string
|
|
63
|
+
*/
|
|
64
|
+
const argumentToSDL = (arg: GraphQLArgument, prefix: string): string => {
|
|
65
|
+
const typeStr = typeToSDL(arg.type, prefix);
|
|
66
|
+
if (arg.defaultValue !== undefined) {
|
|
67
|
+
return `${arg.name}: ${typeStr} = ${JSON.stringify(arg.defaultValue)}`;
|
|
68
|
+
}
|
|
69
|
+
return `${arg.name}: ${typeStr}`;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Generate SDL for a field's arguments
|
|
74
|
+
*/
|
|
75
|
+
const argsToSDL = (args: readonly GraphQLArgument[], prefix: string): string =>
|
|
76
|
+
args.length ? `(${args.map((a) => argumentToSDL(a, prefix)).join(", ")})` : "";
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Generate SDL for an object type (type or input)
|
|
80
|
+
*/
|
|
81
|
+
const objectTypeToSDL = (type: GraphQLNamedType, prefix: string): string => {
|
|
82
|
+
if (isInputObjectType(type)) {
|
|
83
|
+
const fields = Object.values(type.getFields());
|
|
84
|
+
const fieldLines = fields.map((f) => ` ${f.name}: ${typeToSDL(f.type, prefix)}`).join("\n");
|
|
85
|
+
return `input ${prefixTypeName(type.name, prefix)} {\n${fieldLines}\n}`;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (isObjectType(type)) {
|
|
89
|
+
const fields = Object.values(type.getFields());
|
|
90
|
+
const fieldLines = fields
|
|
91
|
+
.map((f) => {
|
|
92
|
+
const args = argsToSDL(f.args, prefix);
|
|
93
|
+
return ` ${f.name}${args}: ${typeToSDL(f.type, prefix)}`;
|
|
94
|
+
})
|
|
95
|
+
.join("\n");
|
|
96
|
+
return `type ${prefixTypeName(type.name, prefix)} {\n${fieldLines}\n}`;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (isEnumType(type)) {
|
|
100
|
+
const values = type.getValues();
|
|
101
|
+
const valueLines = values.map((v) => ` ${v.name}`).join("\n");
|
|
102
|
+
return `enum ${prefixTypeName(type.name, prefix)} {\n${valueLines}\n}`;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (isUnionType(type)) {
|
|
106
|
+
const members = type
|
|
107
|
+
.getTypes()
|
|
108
|
+
.map((t) => prefixTypeName(t.name, prefix))
|
|
109
|
+
.join(" | ");
|
|
110
|
+
return `union ${prefixTypeName(type.name, prefix)} = ${members}`;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (isScalarType(type) && shouldPrefix(type.name)) {
|
|
114
|
+
return `scalar ${prefixTypeName(type.name, prefix)}`;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return "";
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Build a RemoteSchemaField from a GraphQL field
|
|
122
|
+
*/
|
|
123
|
+
const buildRemoteField = (
|
|
124
|
+
field: GraphQLField<unknown, unknown>,
|
|
125
|
+
prefix: string,
|
|
126
|
+
kind: "query" | "mutation",
|
|
127
|
+
): RemoteSchemaField => {
|
|
128
|
+
const args = argsToSDL(field.args, prefix);
|
|
129
|
+
const returnType = typeToSDL(field.type, prefix);
|
|
130
|
+
const prefixedName = `${prefix}${field.name}`;
|
|
131
|
+
|
|
132
|
+
return {
|
|
133
|
+
originalName: field.name,
|
|
134
|
+
prefixedName,
|
|
135
|
+
sdl: `${prefixedName}${args}: ${returnType}`,
|
|
136
|
+
kind,
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Collect all named types reachable from the schema (excluding built-ins and introspection types)
|
|
142
|
+
*/
|
|
143
|
+
const collectUserTypes = (schema: GraphQLSchema): GraphQLNamedType[] => {
|
|
144
|
+
const typeMap = schema.getTypeMap();
|
|
145
|
+
return Object.values(typeMap).filter(
|
|
146
|
+
(type) =>
|
|
147
|
+
shouldPrefix(type.name) &&
|
|
148
|
+
type.name !== "Query" &&
|
|
149
|
+
type.name !== "Mutation" &&
|
|
150
|
+
type.name !== "Subscription",
|
|
151
|
+
);
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Transform a remote GraphQL schema by applying a prefix to all types and fields.
|
|
156
|
+
* Returns a RemoteSchemaResolved containing the transformed SDL, field mappings, and prefix map.
|
|
157
|
+
*/
|
|
158
|
+
export const transformRemoteSchema = (
|
|
159
|
+
schema: GraphQLSchema,
|
|
160
|
+
config: RemoteSchemaConfig,
|
|
161
|
+
): RemoteSchemaResolved => {
|
|
162
|
+
const prefix = config.prefix ?? `${config.name}_`;
|
|
163
|
+
|
|
164
|
+
// Collect all user-defined types
|
|
165
|
+
const userTypes = collectUserTypes(schema);
|
|
166
|
+
|
|
167
|
+
// Build prefix map
|
|
168
|
+
const prefixMap: PrefixMap = {
|
|
169
|
+
toOriginal: {},
|
|
170
|
+
toPrefixed: {},
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
for (const type of userTypes) {
|
|
174
|
+
const prefixed = prefixTypeName(type.name, prefix);
|
|
175
|
+
prefixMap.toOriginal[prefixed] = type.name;
|
|
176
|
+
prefixMap.toPrefixed[type.name] = prefixed;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Generate SDL for all types
|
|
180
|
+
const typeSDLs = userTypes.map((type) => objectTypeToSDL(type, prefix)).filter(Boolean);
|
|
181
|
+
|
|
182
|
+
// Extract query fields
|
|
183
|
+
const queryType = schema.getQueryType();
|
|
184
|
+
const queryFields: RemoteSchemaField[] = [];
|
|
185
|
+
if (queryType) {
|
|
186
|
+
const fields = queryType.getFields();
|
|
187
|
+
for (const field of Object.values(fields)) {
|
|
188
|
+
queryFields.push(buildRemoteField(field, prefix, "query"));
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// Extract mutation fields
|
|
193
|
+
const mutationType = schema.getMutationType();
|
|
194
|
+
const mutationFields: RemoteSchemaField[] = [];
|
|
195
|
+
if (mutationType) {
|
|
196
|
+
const fields = mutationType.getFields();
|
|
197
|
+
for (const field of Object.values(fields)) {
|
|
198
|
+
mutationFields.push(buildRemoteField(field, prefix, "mutation"));
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return {
|
|
203
|
+
config,
|
|
204
|
+
prefix,
|
|
205
|
+
typeDefsSDL: typeSDLs.join("\n\n"),
|
|
206
|
+
queryFields,
|
|
207
|
+
mutationFields,
|
|
208
|
+
prefixMap,
|
|
209
|
+
};
|
|
210
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { RemoteSchemaConfig } from "../config";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A resolved remote query or mutation field from introspection
|
|
5
|
+
*/
|
|
6
|
+
export type RemoteSchemaField = {
|
|
7
|
+
/** Original field name (without prefix) */
|
|
8
|
+
originalName: string;
|
|
9
|
+
/** Prefixed field name used in the merged schema */
|
|
10
|
+
prefixedName: string;
|
|
11
|
+
/** GraphQL SDL for this field (with arguments) in the merged schema */
|
|
12
|
+
sdl: string;
|
|
13
|
+
/** Whether this field is a query or mutation */
|
|
14
|
+
kind: "query" | "mutation";
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Mapping from prefixed type name to original type name
|
|
19
|
+
*/
|
|
20
|
+
export type PrefixMap = {
|
|
21
|
+
/** Map prefixed name → original name */
|
|
22
|
+
toOriginal: Record<string, string>;
|
|
23
|
+
/** Map original name → prefixed name */
|
|
24
|
+
toPrefixed: Record<string, string>;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Fully resolved remote schema after introspection and transformation
|
|
29
|
+
*/
|
|
30
|
+
export type RemoteSchemaResolved = {
|
|
31
|
+
/** The original configuration */
|
|
32
|
+
config: RemoteSchemaConfig;
|
|
33
|
+
/** Effective prefix (with trailing underscore) */
|
|
34
|
+
prefix: string;
|
|
35
|
+
/** Transformed SDL type definitions (prefixed types, inputs, enums, etc.) */
|
|
36
|
+
typeDefsSDL: string;
|
|
37
|
+
/** Remote query fields (prefixed) */
|
|
38
|
+
queryFields: RemoteSchemaField[];
|
|
39
|
+
/** Remote mutation fields (prefixed) */
|
|
40
|
+
mutationFields: RemoteSchemaField[];
|
|
41
|
+
/** Type name prefix mapping */
|
|
42
|
+
prefixMap: PrefixMap;
|
|
43
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { buildAgentTools, createAgent, type RoleEntities } from "../ai";
|
|
2
|
+
import type { AIConfig } from "../types/zod/ai";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Default system prompt: pins the agent to the list → describe → execute
|
|
6
|
+
* workflow and forbids fabrication. Overridable via `ai.systemPrompt`.
|
|
7
|
+
*/
|
|
8
|
+
export const DEFAULT_AI_SYSTEM_PROMPT = `You are a database assistant for a Graphoria GraphQL API. Answer the user's question using ONLY the provided tools. Never fabricate, invent, or guess data.
|
|
9
|
+
|
|
10
|
+
Required workflow (STOP after step 3 — present results immediately):
|
|
11
|
+
1. list_entities — find relevant tables (REQUIRES \`kind\` or \`search\`; search matches names AND descriptions, so try natural-language keywords).
|
|
12
|
+
2. describe_entity — read the table's columns, the aggregateField signature, and the pre-built \`examples\` (list / filter / aggregate). Prefer copying an example over composing a query from scratch.
|
|
13
|
+
3. query_data — run ONE query (pick aggregate OR list, not both). Then STOP and present the answer.
|
|
14
|
+
|
|
15
|
+
For counts, totals, grouping, breakdowns, or summaries: use query_data with operation "aggregate" and groupBy. Never fetch all rows and count client-side.
|
|
16
|
+
|
|
17
|
+
Aggregate shape (\`key\` is an object and must be sub-selected):
|
|
18
|
+
|
|
19
|
+
query {
|
|
20
|
+
<entity>_aggregate(groupBy: [<col>]) {
|
|
21
|
+
key { <col> }
|
|
22
|
+
count
|
|
23
|
+
items { <fields> }
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
CRITICAL: After query_data returns data, present the answer IMMEDIATELY. Do NOT call more tools. Do NOT re-query with a different operation. One query → present results → done. Use a Markdown table for grouped results.`;
|
|
28
|
+
|
|
29
|
+
export const DEFAULT_AI_PROMPT_TEMPLATE = `Database-query request from the user:
|
|
30
|
+
|
|
31
|
+
> {prompt}
|
|
32
|
+
|
|
33
|
+
You MUST follow this EXACT workflow — do NOT skip steps, do NOT answer before completing all steps:
|
|
34
|
+
|
|
35
|
+
STEP 1 — list_entities: Call with \`kind\` and/or \`search\` to find relevant tables. The result includes a \`name\` field (e.g. "pg_public_contacts"). MEMORIZE the \`tableName\` field (e.g. "contacts") — you will need it for step 3.
|
|
36
|
+
|
|
37
|
+
STEP 2 — describe_entity: Call using the EXACT \`name\` string from step 1 (do NOT shorten, transform, or guess it — "pg_public_contacts" is NOT "contacts"). The result contains the table's columns — copy the column names EXACTLY for step 3.
|
|
38
|
+
|
|
39
|
+
STEP 3 — query_data: Send a structured JSON query. Pick ONE operation — aggregate (for grouping/counts) OR list (for row data). Do NOT call both. The entity must be the EXACT resolverName from step 1 (e.g. "pg_public_contacts"). For aggregates, use operation "aggregate" with groupBy. ALWAYS include \`"filters": { "deleted_at": { "is_null": true } }\` unless the user asks for deleted data.
|
|
40
|
+
|
|
41
|
+
STEP 4 — STOP AND PRESENT: After query_data returns, present the answer IMMEDIATELY. Do NOT call more tools. Do NOT re-query. Format grouped results as a Markdown table. You are DONE after this step.
|
|
42
|
+
|
|
43
|
+
CRITICAL RULES:
|
|
44
|
+
- NEVER fabricate, invent, or guess query results. ONLY report data returned by query_data.
|
|
45
|
+
- After getting data, STOP. Do not query again. One query_data call is enough.
|
|
46
|
+
- Copy column names EXACTLY from describe_entity — do not guess or invent field names.
|
|
47
|
+
- For aggregates: set \`"operation": "aggregate"\`, provide \`"groupBy"\` as an array of column names.
|
|
48
|
+
- For lists: set \`"operation": "list"\`, provide \`"columns"\` as an array of column names.
|
|
49
|
+
- The \`entity\` field is the EXACT resolverName from step 1 (e.g. "pg_public_contacts", NOT "contacts").
|
|
50
|
+
- Filter operators: eq, neq, like, ilike, gt, gte, lt, lte, is_null. Use \`{ "is_null": true }\` for NULL checks.
|
|
51
|
+
- If you are unsure about ANYTHING, call a tool. Do not guess.`;
|
|
52
|
+
|
|
53
|
+
let agent: ((prompt: string) => Promise<string>) | null = null;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Build and store the agent, bound to the given role's schema (the agent's
|
|
57
|
+
* tools see exactly what that role can see). Called at boot when `ai.enabled`.
|
|
58
|
+
*
|
|
59
|
+
* Precedence for systemPrompt / promptTemplate:
|
|
60
|
+
* 1. Env-var override (`AI_SYSTEM_PROMPT` / `AI_PROMPT_TEMPLATE`)
|
|
61
|
+
* 2. Config-file value (`ai.systemPrompt`)
|
|
62
|
+
* 3. Built-in default
|
|
63
|
+
*/
|
|
64
|
+
export const instantiateAI = (
|
|
65
|
+
aiConfig: AIConfig,
|
|
66
|
+
role: RoleEntities,
|
|
67
|
+
envOverrides?: { systemPrompt?: string; promptTemplate?: string },
|
|
68
|
+
): void => {
|
|
69
|
+
const systemPrompt =
|
|
70
|
+
envOverrides?.systemPrompt ?? aiConfig.systemPrompt ?? DEFAULT_AI_SYSTEM_PROMPT;
|
|
71
|
+
const template = envOverrides?.promptTemplate ?? DEFAULT_AI_PROMPT_TEMPLATE;
|
|
72
|
+
|
|
73
|
+
const tools = buildAgentTools(role);
|
|
74
|
+
agent = createAgent({
|
|
75
|
+
tools,
|
|
76
|
+
systemPrompt,
|
|
77
|
+
wrap: (prompt: string) => template.replaceAll("{prompt}", prompt),
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export const getAgent = (): ((prompt: string) => Promise<string>) => {
|
|
82
|
+
if (!agent) {
|
|
83
|
+
throw new Error("AI agent is not enabled. Set `ai.enabled = true` in your configuration.");
|
|
84
|
+
}
|
|
85
|
+
return agent;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/** Test-only reset. */
|
|
89
|
+
export const resetAI = (): void => {
|
|
90
|
+
agent = null;
|
|
91
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { TokenService } from "../authentication/types";
|
|
2
|
+
|
|
3
|
+
import { createJWTService } from "../authentication/jwt";
|
|
4
|
+
import { env } from "./env";
|
|
5
|
+
|
|
6
|
+
// Default to JWT; overridden after configuration is parsed via setTokenService()
|
|
7
|
+
let tokenService: TokenService = createJWTService(env);
|
|
8
|
+
|
|
9
|
+
export const getTokenService = (): TokenService => tokenService;
|
|
10
|
+
|
|
11
|
+
export const setTokenService = (service: TokenService): void => {
|
|
12
|
+
tokenService = service;
|
|
13
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { LRUCache } from "lru-cache";
|
|
2
|
+
|
|
3
|
+
import type { CacheStore } from "./types";
|
|
4
|
+
|
|
5
|
+
// oxlint-disable-next-line typescript/no-explicit-any
|
|
6
|
+
export class LruCacheStore implements CacheStore {
|
|
7
|
+
// oxlint-disable-next-line typescript/no-explicit-any
|
|
8
|
+
private cache: LRUCache<string, any>;
|
|
9
|
+
|
|
10
|
+
// oxlint-disable-next-line typescript/no-explicit-any
|
|
11
|
+
constructor(options: LRUCache.Options<string, any, unknown>) {
|
|
12
|
+
this.cache = new LRUCache(options);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async get(key: string): Promise<unknown | undefined> {
|
|
16
|
+
return this.cache.get(key);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async set(key: string, value: unknown): Promise<void> {
|
|
20
|
+
this.cache.set(key, value);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async delete(key: string): Promise<void> {
|
|
24
|
+
this.cache.delete(key);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async clear(): Promise<void> {
|
|
28
|
+
this.cache.clear();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async keys(): Promise<string[]> {
|
|
32
|
+
return [...this.cache.keys()];
|
|
33
|
+
}
|
|
34
|
+
}
|