@harperfast/harper-pro 5.0.25 → 5.1.0-beta.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/analytics/profile.ts +4 -0
- package/core/AGENTS.md +92 -6
- package/core/DESIGN.md +24 -0
- package/core/README.md +11 -10
- package/core/agent/agent.ts +203 -0
- package/core/agent/loop.ts +205 -0
- package/core/agent/operations.ts +148 -0
- package/core/agent/session.ts +187 -0
- package/core/agent/tools/fsTools.ts +276 -0
- package/core/agent/tools/httpFetchTool.ts +112 -0
- package/core/agent/tools/scheduleTool.ts +68 -0
- package/core/agent/toolset.ts +43 -0
- package/core/agent/types.ts +85 -0
- package/core/benchmarks/hnsw-search.js +157 -0
- package/core/benchmarks/ycsb/README.md +144 -0
- package/core/benchmarks/ycsb/analyze-profile.mts +120 -0
- package/core/benchmarks/ycsb/app/config.yaml +3 -0
- package/core/benchmarks/ycsb/app/schema.graphql +17 -0
- package/core/benchmarks/ycsb/harness.mts +328 -0
- package/core/benchmarks/ycsb/restClient.mts +120 -0
- package/core/benchmarks/ycsb/run-single-node.mts +97 -0
- package/core/benchmarks/ycsb/to-benchmark-json.mts +58 -0
- package/core/benchmarks/ycsb/workload.mts +499 -0
- package/core/benchmarks/ycsb/workload.test.mts +174 -0
- package/core/bin/{BinObjects.js → BinObjects.ts} +4 -5
- package/core/bin/cliCredentials.ts +133 -0
- package/core/bin/cliOperations.ts +339 -0
- package/core/bin/copyDb.ts +10 -10
- package/core/bin/deployRenderer.ts +196 -0
- package/core/bin/{harper.js → harper.ts} +48 -24
- package/core/bin/{install.js → install.ts} +3 -3
- package/core/bin/lite.ts +2 -0
- package/core/bin/login.ts +168 -0
- package/core/bin/logout.ts +11 -0
- package/core/bin/mcp/client.ts +407 -0
- package/core/bin/mcp/doctor.ts +189 -0
- package/core/bin/mcp/index.ts +80 -0
- package/core/bin/mcp/options.ts +122 -0
- package/core/bin/mcp/printConfig.ts +89 -0
- package/core/bin/multipartBuilder.ts +74 -0
- package/core/bin/{restart.js → restart.ts} +31 -32
- package/core/bin/{run.js → run.ts} +57 -46
- package/core/bin/sseConsumer.ts +126 -0
- package/core/bin/{status.js → status.ts} +10 -10
- package/core/bin/stop.ts +21 -0
- package/core/bin/upgrade.js +6 -6
- package/core/components/Application.ts +144 -18
- package/core/components/ApplicationScope.ts +2 -2
- package/core/components/ComponentV1.ts +2 -2
- package/core/components/EntryHandler.ts +159 -9
- package/core/components/OptionsWatcher.ts +75 -11
- package/core/components/Scope.ts +125 -15
- package/core/components/anthropic/index.ts +547 -0
- package/core/components/bedrock/index.ts +823 -0
- package/core/components/componentLoader.ts +63 -32
- package/core/components/deployLifecycle.ts +161 -0
- package/core/components/deploymentOperations.ts +173 -0
- package/core/components/deploymentRecorder.ts +402 -0
- package/core/components/deriveURLPath.ts +4 -4
- package/core/components/mcp/adapters/fastify.ts +87 -0
- package/core/components/mcp/adapters/harperHttp.ts +103 -0
- package/core/components/mcp/audit.ts +75 -0
- package/core/components/mcp/index.ts +134 -0
- package/core/components/mcp/jsonrpc.ts +134 -0
- package/core/components/mcp/lifecycle.ts +105 -0
- package/core/components/mcp/listChanged.ts +270 -0
- package/core/components/mcp/rateLimit.ts +217 -0
- package/core/components/mcp/resources.ts +593 -0
- package/core/components/mcp/session.ts +151 -0
- package/core/components/mcp/sessionRegistry.ts +140 -0
- package/core/components/mcp/toolRegistry.ts +292 -0
- package/core/components/mcp/tools/application.ts +603 -0
- package/core/components/mcp/tools/operations.ts +283 -0
- package/core/components/mcp/tools/schemas/derive.ts +256 -0
- package/core/components/mcp/tools/schemas/operations.ts +245 -0
- package/core/components/mcp/transport.ts +517 -0
- package/core/components/ollama/index.ts +316 -0
- package/core/components/openai/index.ts +563 -0
- package/core/components/operations.js +211 -60
- package/core/components/operationsValidation.js +3 -3
- package/core/components/packageComponent.ts +97 -29
- package/core/components/requestRestart.ts +17 -2
- package/core/components/status/crossThread.ts +14 -5
- package/core/components/status/errors.ts +1 -1
- package/core/config/RootConfigWatcher.ts +56 -2
- package/core/config/configUtils.js +29 -8
- package/core/config/harperConfigEnvVars.ts +1 -1
- package/core/dataLayer/{CreateAttributeObject.js → CreateAttributeObject.ts} +4 -3
- package/core/dataLayer/{CreateTableObject.js → CreateTableObject.ts} +2 -1
- package/core/dataLayer/{DataLayerObjects.js → DataLayerObjects.ts} +17 -9
- package/core/dataLayer/{DeleteBeforeObject.js → DeleteBeforeObject.ts} +2 -1
- package/core/dataLayer/{DeleteObject.js → DeleteObject.ts} +3 -2
- package/core/dataLayer/{DropAttributeObject.js → DropAttributeObject.ts} +2 -1
- package/core/dataLayer/{GetBackupObject.js → GetBackupObject.ts} +3 -2
- package/core/dataLayer/{InsertObject.js → InsertObject.ts} +3 -2
- package/core/dataLayer/{ReadAuditLogObject.js → ReadAuditLogObject.ts} +3 -2
- package/core/dataLayer/{SQLSearch.js → SQLSearch.ts} +97 -43
- package/core/dataLayer/{SearchByConditionsObject.js → SearchByConditionsObject.ts} +5 -6
- package/core/dataLayer/{SearchByHashObject.js → SearchByHashObject.ts} +2 -1
- package/core/dataLayer/{SearchObject.js → SearchObject.ts} +2 -1
- package/core/dataLayer/{SqlSearchObject.js → SqlSearchObject.ts} +2 -1
- package/core/dataLayer/{UpdateObject.js → UpdateObject.ts} +3 -2
- package/core/dataLayer/{UpsertObject.js → UpsertObject.ts} +3 -2
- package/core/dataLayer/{bulkLoad.js → bulkLoad.ts} +40 -49
- package/core/dataLayer/{delete.js → delete.ts} +21 -26
- package/core/dataLayer/{export.js → export.ts} +22 -26
- package/core/dataLayer/{getBackup.js → getBackup.ts} +7 -9
- package/core/dataLayer/harperBridge/BridgeMethods.ts +102 -0
- package/core/dataLayer/harperBridge/ResourceBridge.ts +27 -26
- package/core/dataLayer/harperBridge/TableSizeObject.ts +1 -0
- package/core/dataLayer/harperBridge/bridgeUtility/insertUpdateValidate.js +4 -4
- package/core/dataLayer/harperBridge/{harperBridge.js → harperBridge.ts} +3 -3
- package/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateAttribute.js +8 -6
- package/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateRecords.js +4 -4
- package/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateSchema.js +1 -1
- package/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateTable.js +6 -4
- package/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDeleteAuditLogsBefore.js +5 -4
- package/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDeleteRecords.js +4 -4
- package/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDropAttribute.js +6 -5
- package/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDropSchema.js +5 -4
- package/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDropTable.js +5 -5
- package/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbFlush.js +1 -1
- package/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbGetBackup.js +3 -3
- package/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbGetDataByHash.js +1 -1
- package/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbGetDataByValue.js +3 -2
- package/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbReadAuditLog.js +5 -5
- package/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbSearchByConditions.js +10 -8
- package/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbSearchByHash.js +1 -1
- package/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbSearchByValue.js +4 -3
- package/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbUpdateRecords.js +3 -3
- package/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbUpsertRecords.js +6 -5
- package/core/dataLayer/harperBridge/lmdbBridge/lmdbUtility/LMDBCreateAttributeObject.js +2 -1
- package/core/dataLayer/harperBridge/lmdbBridge/lmdbUtility/initializeHashSearch.js +3 -2
- package/core/dataLayer/harperBridge/lmdbBridge/lmdbUtility/initializePaths.js +2 -2
- package/core/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbCheckForNewAttributes.js +5 -4
- package/core/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbCreateTransactionsAuditEnvironment.js +6 -3
- package/core/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbGetTableSize.ts +1 -1
- package/core/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbProcessRows.js +4 -4
- package/core/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbSearch.js +5 -5
- package/core/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbWriteTransaction.js +4 -4
- package/core/dataLayer/{hdbInfoController.js → hdbInfoController.ts} +20 -26
- package/core/dataLayer/{insert.js → insert.ts} +24 -24
- package/core/dataLayer/{readAuditLog.js → readAuditLog.ts} +8 -10
- package/core/dataLayer/{schema.js → schema.ts} +32 -44
- package/core/dataLayer/{schemaDescribe.js → schemaDescribe.ts} +23 -26
- package/core/dataLayer/{search.js → search.ts} +9 -15
- package/core/dataLayer/{transaction.js → transaction.ts} +2 -5
- package/core/dataLayer/{update.js → update.ts} +19 -22
- package/core/index.ts +5 -0
- package/core/json/systemSchema.json +65 -0
- package/core/launchServiceScripts/utility/checkNodeVersion.js +2 -0
- package/core/package-lock.json +9051 -4318
- package/core/resources/DESIGN.md +98 -0
- package/core/resources/DatabaseTransaction.ts +58 -30
- package/core/resources/ErrorResource.ts +2 -1
- package/core/resources/LMDBTransaction.ts +38 -29
- package/core/resources/RecordEncoder.ts +12 -4
- package/core/resources/RequestTarget.ts +2 -0
- package/core/resources/Resource.ts +89 -56
- package/core/resources/ResourceInterface.ts +44 -21
- package/core/resources/Resources.ts +8 -8
- package/core/resources/RocksIndexStore.ts +3 -0
- package/core/resources/RocksTransactionLogStore.ts +47 -28
- package/core/resources/Table.ts +386 -214
- package/core/resources/analytics/metadata.ts +1 -0
- package/core/resources/analytics/read.ts +24 -6
- package/core/resources/analytics/write.ts +240 -17
- package/core/resources/auditStore.ts +28 -19
- package/core/resources/blob.ts +53 -53
- package/core/resources/dataLoader.ts +4 -4
- package/core/resources/databases.ts +190 -71
- package/core/resources/graphql.ts +227 -164
- package/core/resources/indexes/HierarchicalNavigableSmallWorld.ts +294 -65
- package/core/resources/indexes/vector.ts +17 -0
- package/core/resources/loadEnv.ts +21 -17
- package/core/resources/login.ts +5 -3
- package/core/resources/models/Models.ts +304 -0
- package/core/resources/models/TestBackend.ts +83 -0
- package/core/resources/models/agentLoop.ts +895 -0
- package/core/resources/models/analyticsTable.ts +199 -0
- package/core/resources/models/backendHelpers.ts +116 -0
- package/core/resources/models/backendRegistry.ts +66 -0
- package/core/resources/models/bootstrap.ts +135 -0
- package/core/resources/models/embedHook.ts +138 -0
- package/core/resources/models/types.ts +296 -0
- package/core/resources/replayLogs.ts +15 -7
- package/core/resources/roles.ts +62 -67
- package/core/resources/search.ts +355 -135
- package/core/resources/tracked.ts +8 -8
- package/core/resources/transaction.ts +8 -8
- package/core/resources/transactionBroadcast.ts +3 -3
- package/core/security/auth.ts +35 -26
- package/core/security/certificateVerification/crlVerification.ts +11 -4
- package/core/security/{cryptoHash.js → cryptoHash.ts} +3 -8
- package/core/security/data_objects/{PermissionAttributeResponseObject.js → PermissionAttributeResponseObject.ts} +4 -4
- package/core/security/data_objects/{PermissionResponseObject.js → PermissionResponseObject.ts} +12 -11
- package/core/security/data_objects/{PermissionTableResponseObject.js → PermissionTableResponseObject.ts} +6 -4
- package/core/security/{fastifyAuth.js → fastifyAuth.ts} +93 -20
- package/core/security/impersonation.ts +3 -3
- package/core/security/jsLoader.ts +22 -8
- package/core/security/{keys.js → keys.ts} +113 -121
- package/core/security/permissionsTranslator.js +2 -2
- package/core/security/{role.js → role.ts} +26 -33
- package/core/security/tokenAuthentication.ts +34 -7
- package/core/security/user.ts +26 -22
- package/core/server/DESIGN.md +139 -0
- package/core/server/DurableSubscriptionsSession.ts +67 -50
- package/core/server/REST.ts +120 -107
- package/core/server/Server.ts +31 -12
- package/core/server/fastifyRoutes/helpers/getCORSOptions.js +1 -1
- package/core/server/fastifyRoutes/helpers/getHeaderTimeoutConfig.js +1 -1
- package/core/server/fastifyRoutes/helpers/getServerOptions.js +1 -1
- package/core/server/fastifyRoutes.ts +37 -33
- package/core/server/graphqlQuerying.ts +6 -5
- package/core/server/http.ts +517 -26
- package/core/server/itc/serverHandlers.js +75 -14
- package/core/server/jobs/{JobObject.js → JobObject.ts} +13 -6
- package/core/server/jobs/{jobProcess.js → jobProcess.ts} +20 -16
- package/core/server/jobs/{jobRunner.js → jobRunner.ts} +20 -21
- package/core/server/jobs/{jobs.js → jobs.ts} +41 -44
- package/core/server/loadRootComponents.js +1 -1
- package/core/server/middlewareChain.ts +270 -0
- package/core/server/mqtt.ts +35 -26
- package/core/server/nodeName.ts +2 -1
- package/core/server/operationsServer.ts +85 -10
- package/core/server/serverHelpers/Headers.ts +10 -8
- package/core/server/serverHelpers/JSONStream.ts +15 -5
- package/core/server/serverHelpers/Request.ts +370 -13
- package/core/server/serverHelpers/contentTypes.ts +42 -11
- package/core/server/serverHelpers/multipartParser.ts +152 -0
- package/core/server/serverHelpers/progressEmitter.ts +110 -0
- package/core/server/serverHelpers/serverHandlers.js +43 -7
- package/core/server/serverHelpers/serverUtilities.ts +40 -30
- package/core/server/static.ts +9 -6
- package/core/server/status/index.ts +2 -2
- package/core/server/storageReclamation.ts +39 -2
- package/core/server/threads/itc.js +7 -4
- package/core/server/threads/manageThreads.js +100 -26
- package/core/server/threads/socketRouter.ts +12 -275
- package/core/server/threads/threadServer.js +345 -105
- package/core/server/threads/workerProcessGuard.ts +93 -0
- package/core/server/throttle.ts +18 -0
- package/core/sqlTranslator/{SelectValidator.js → SelectValidator.ts} +41 -49
- package/core/sqlTranslator/{alasqlFunctionImporter.js → alasqlFunctionImporter.ts} +5 -5
- package/core/sqlTranslator/{deleteTranslator.js → deleteTranslator.ts} +13 -18
- package/core/sqlTranslator/{index.js → index.ts} +30 -33
- package/core/sqlTranslator/{sql_statement_bucket.js → sql_statement_bucket.ts} +49 -20
- package/core/static/README.md +10 -9
- package/core/system/000004.log +0 -0
- package/core/system/CURRENT +1 -0
- package/core/system/IDENTITY +1 -0
- package/core/system/LOCK +0 -0
- package/core/system/LOG +1351 -0
- package/core/system/MANIFEST-000005 +0 -0
- package/core/system/OPTIONS-000013 +607 -0
- package/core/system/OPTIONS-000015 +734 -0
- package/core/upgrade/{UpgradeObjects.js → UpgradeObjects.ts} +3 -6
- package/core/upgrade/directives/5-2-0.ts +49 -0
- package/core/upgrade/directives/{directivesController.js → directivesController.ts} +16 -16
- package/core/upgrade/{directivesManager.js → directivesManager.ts} +7 -11
- package/core/upgrade/{upgradePrompt.js → upgradePrompt.ts} +8 -14
- package/core/upgrade/{upgradeUtilities.js → upgradeUtilities.ts} +3 -7
- package/core/utility/{OperationFunctionCaller.js → OperationFunctionCaller.ts} +7 -7
- package/core/utility/{assignCmdEnvVariables.js → assignCmdEnvVariables.ts} +6 -8
- package/core/utility/{common_utils.js → common_utils.ts} +113 -139
- package/core/utility/environment/{environmentManager.js → environmentManager.ts} +34 -33
- package/core/utility/environment/systemInformation.ts +18 -4
- package/core/utility/errors/{commonErrors.js → commonErrors.ts} +9 -9
- package/core/utility/errors/{hdbError.js → hdbError.ts} +39 -45
- package/core/utility/expandEnvVar.ts +110 -0
- package/core/utility/functions/geo.js +2 -2
- package/core/utility/functions/sql/alaSQLExtension.js +1 -1
- package/core/utility/globalSchema.ts +30 -0
- package/core/utility/hdbTerms.ts +56 -0
- package/core/utility/install/checkJWTTokensExist.js +1 -1
- package/core/utility/install/{installer.js → installer.ts} +58 -59
- package/core/utility/installation.ts +2 -2
- package/core/utility/lmdb/{DBIDefinition.js → DBIDefinition.ts} +4 -1
- package/core/utility/lmdb/{DeleteRecordsResponseObject.js → DeleteRecordsResponseObject.ts} +2 -1
- package/core/utility/lmdb/{InsertRecordsResponseObject.js → InsertRecordsResponseObject.ts} +2 -1
- package/core/utility/lmdb/OpenDBIObject.ts +43 -0
- package/core/utility/lmdb/{OpenEnvironmentObject.js → OpenEnvironmentObject.ts} +19 -6
- package/core/utility/lmdb/{UpdateRecordsResponseObject.js → UpdateRecordsResponseObject.ts} +2 -1
- package/core/utility/lmdb/{UpsertRecordsResponseObject.js → UpsertRecordsResponseObject.ts} +2 -1
- package/core/utility/lmdb/{cleanLMDBMap.js → cleanLMDBMap.ts} +5 -5
- package/core/utility/lmdb/{commonUtility.js → commonUtility.ts} +13 -21
- package/core/utility/lmdb/{deleteUtility.js → deleteUtility.ts} +8 -12
- package/core/utility/lmdb/{environmentUtility.js → environmentUtility.ts} +43 -52
- package/core/utility/lmdb/{searchCursorFunctions.js → searchCursorFunctions.ts} +12 -26
- package/core/utility/lmdb/{searchUtility.js → searchUtility.ts} +75 -64
- package/core/utility/lmdb/{terms.js → terms.ts} +10 -23
- package/core/utility/lmdb/{writeUtility.js → writeUtility.ts} +37 -22
- package/core/utility/logging/{harper_logger.js → harper_logger.ts} +136 -89
- package/core/utility/logging/{logRotator.js → logRotator.ts} +13 -13
- package/core/utility/logging/logger.ts +1 -1
- package/core/utility/logging/{readLog.js → readLog.ts} +19 -19
- package/core/utility/logging/{transactionLog.js → transactionLog.ts} +10 -14
- package/core/utility/{mount_hdb.js → mount_hdb.ts} +15 -16
- package/core/utility/{npmUtilities.js → npmUtilities.ts} +14 -17
- package/core/utility/{operation_authorization.js → operation_authorization.ts} +173 -124
- package/core/utility/packageUtils.js +7 -16
- package/core/utility/password.ts +1 -1
- package/core/utility/processManagement/processManagement.js +2 -2
- package/core/utility/processManagement/servicesConfig.js +1 -1
- package/core/utility/{signalling.js → signalling.ts} +6 -11
- package/core/utility/watcherFallback.ts +74 -0
- package/core/validation/analyticsValidator.ts +43 -0
- package/core/validation/{bulkDeleteValidator.js → bulkDeleteValidator.ts} +5 -5
- package/core/validation/{check_permissions.js → check_permissions.ts} +3 -3
- package/core/validation/{common_validators.js → common_validators.ts} +12 -24
- package/core/validation/{configValidator.js → configValidator.ts} +114 -18
- package/core/validation/{deleteValidator.js → deleteValidator.ts} +5 -5
- package/core/validation/{fileLoadValidator.js → fileLoadValidator.ts} +12 -19
- package/core/validation/{insertValidator.js → insertValidator.ts} +5 -5
- package/core/validation/{installValidator.js → installValidator.ts} +8 -8
- package/core/validation/{readLogValidator.js → readLogValidator.ts} +10 -10
- package/core/validation/{role_validation.js → role_validation.ts} +26 -32
- package/core/validation/{schemaMetadataValidator.js → schemaMetadataValidator.ts} +5 -11
- package/core/validation/{searchValidator.js → searchValidator.ts} +12 -11
- package/core/validation/statusValidator.ts +1 -1
- package/core/validation/{transactionLogValidator.js → transactionLogValidator.ts} +4 -9
- package/core/validation/{user_validation.js → user_validation.ts} +4 -10
- package/core/validation/{validationWrapper.js → validationWrapper.ts} +3 -9
- package/dist/analytics/profile.js +4 -0
- package/dist/analytics/profile.js.map +1 -1
- package/dist/cloneNode/cloneNode.js +224 -12
- package/dist/cloneNode/cloneNode.js.map +1 -1
- package/dist/core/agent/agent.js +175 -0
- package/dist/core/agent/agent.js.map +1 -0
- package/dist/core/agent/loop.js +176 -0
- package/dist/core/agent/loop.js.map +1 -0
- package/dist/core/agent/operations.js +137 -0
- package/dist/core/agent/operations.js.map +1 -0
- package/dist/core/agent/session.js +182 -0
- package/dist/core/agent/session.js.map +1 -0
- package/dist/core/agent/tools/fsTools.js +286 -0
- package/dist/core/agent/tools/fsTools.js.map +1 -0
- package/dist/core/agent/tools/httpFetchTool.js +116 -0
- package/dist/core/agent/tools/httpFetchTool.js.map +1 -0
- package/dist/core/agent/tools/scheduleTool.js +54 -0
- package/dist/core/agent/tools/scheduleTool.js.map +1 -0
- package/dist/core/agent/toolset.js +33 -0
- package/dist/core/agent/toolset.js.map +1 -0
- package/dist/core/agent/types.js +10 -0
- package/dist/core/agent/types.js.map +1 -0
- package/dist/core/bin/BinObjects.js +6 -3
- package/dist/core/bin/BinObjects.js.map +1 -1
- package/dist/core/bin/cliCredentials.js +130 -0
- package/dist/core/bin/cliCredentials.js.map +1 -0
- package/dist/core/bin/cliOperations.js +254 -40
- package/dist/core/bin/cliOperations.js.map +1 -1
- package/dist/core/bin/copyDb.js +16 -16
- package/dist/core/bin/copyDb.js.map +1 -1
- package/dist/core/bin/deployRenderer.js +185 -0
- package/dist/core/bin/deployRenderer.js.map +1 -0
- package/dist/core/bin/harper.js +92 -31
- package/dist/core/bin/harper.js.map +1 -1
- package/dist/core/bin/install.js +41 -4
- package/dist/core/bin/install.js.map +1 -1
- package/dist/core/bin/lite.js +3 -4
- package/dist/core/bin/lite.js.map +1 -1
- package/dist/core/bin/login.js +158 -0
- package/dist/core/bin/login.js.map +1 -0
- package/dist/core/bin/logout.js +16 -0
- package/dist/core/bin/logout.js.map +1 -0
- package/dist/core/bin/mcp/client.js +395 -0
- package/dist/core/bin/mcp/client.js.map +1 -0
- package/dist/core/bin/mcp/doctor.js +193 -0
- package/dist/core/bin/mcp/doctor.js.map +1 -0
- package/dist/core/bin/mcp/index.js +81 -0
- package/dist/core/bin/mcp/index.js.map +1 -0
- package/dist/core/bin/mcp/options.js +113 -0
- package/dist/core/bin/mcp/options.js.map +1 -0
- package/dist/core/bin/mcp/printConfig.js +85 -0
- package/dist/core/bin/mcp/printConfig.js.map +1 -0
- package/dist/core/bin/multipartBuilder.js +55 -0
- package/dist/core/bin/multipartBuilder.js.map +1 -0
- package/dist/core/bin/restart.js +85 -48
- package/dist/core/bin/restart.js.map +1 -1
- package/dist/core/bin/run.js +123 -77
- package/dist/core/bin/run.js.map +1 -1
- package/dist/core/bin/sseConsumer.js +127 -0
- package/dist/core/bin/sseConsumer.js.map +1 -0
- package/dist/core/bin/status.js +48 -11
- package/dist/core/bin/status.js.map +1 -1
- package/dist/core/bin/stop.js +44 -7
- package/dist/core/bin/stop.js.map +1 -1
- package/dist/core/bin/upgrade.js +6 -6
- package/dist/core/components/Application.js +134 -28
- package/dist/core/components/Application.js.map +1 -1
- package/dist/core/components/ApplicationScope.js +2 -2
- package/dist/core/components/ComponentV1.js +5 -5
- package/dist/core/components/ComponentV1.js.map +1 -1
- package/dist/core/components/EntryHandler.js +153 -13
- package/dist/core/components/EntryHandler.js.map +1 -1
- package/dist/core/components/OptionsWatcher.js +72 -10
- package/dist/core/components/OptionsWatcher.js.map +1 -1
- package/dist/core/components/Scope.js +105 -9
- package/dist/core/components/Scope.js.map +1 -1
- package/dist/core/components/anthropic/index.js +428 -0
- package/dist/core/components/anthropic/index.js.map +1 -0
- package/dist/core/components/bedrock/index.js +734 -0
- package/dist/core/components/bedrock/index.js.map +1 -0
- package/dist/core/components/componentLoader.js +63 -38
- package/dist/core/components/componentLoader.js.map +1 -1
- package/dist/core/components/deployLifecycle.js +156 -0
- package/dist/core/components/deployLifecycle.js.map +1 -0
- package/dist/core/components/deploymentOperations.js +185 -0
- package/dist/core/components/deploymentOperations.js.map +1 -0
- package/dist/core/components/deploymentRecorder.js +401 -0
- package/dist/core/components/deploymentRecorder.js.map +1 -0
- package/dist/core/components/deriveURLPath.js +2 -2
- package/dist/core/components/deriveURLPath.js.map +1 -1
- package/dist/core/components/mcp/adapters/fastify.js +66 -0
- package/dist/core/components/mcp/adapters/fastify.js.map +1 -0
- package/dist/core/components/mcp/adapters/harperHttp.js +78 -0
- package/dist/core/components/mcp/adapters/harperHttp.js.map +1 -0
- package/dist/core/components/mcp/audit.js +73 -0
- package/dist/core/components/mcp/audit.js.map +1 -0
- package/dist/core/components/mcp/index.js +109 -0
- package/dist/core/components/mcp/index.js.map +1 -0
- package/dist/core/components/mcp/jsonrpc.js +93 -0
- package/dist/core/components/mcp/jsonrpc.js.map +1 -0
- package/dist/core/components/mcp/lifecycle.js +79 -0
- package/dist/core/components/mcp/lifecycle.js.map +1 -0
- package/dist/core/components/mcp/listChanged.js +257 -0
- package/dist/core/components/mcp/listChanged.js.map +1 -0
- package/dist/core/components/mcp/rateLimit.js +226 -0
- package/dist/core/components/mcp/rateLimit.js.map +1 -0
- package/dist/core/components/mcp/resources.js +515 -0
- package/dist/core/components/mcp/resources.js.map +1 -0
- package/dist/core/components/mcp/session.js +170 -0
- package/dist/core/components/mcp/session.js.map +1 -0
- package/dist/core/components/mcp/sessionRegistry.js +124 -0
- package/dist/core/components/mcp/sessionRegistry.js.map +1 -0
- package/dist/core/components/mcp/toolRegistry.js +176 -0
- package/dist/core/components/mcp/toolRegistry.js.map +1 -0
- package/dist/core/components/mcp/tools/application.js +549 -0
- package/dist/core/components/mcp/tools/application.js.map +1 -0
- package/dist/core/components/mcp/tools/operations.js +303 -0
- package/dist/core/components/mcp/tools/operations.js.map +1 -0
- package/dist/core/components/mcp/tools/schemas/derive.js +216 -0
- package/dist/core/components/mcp/tools/schemas/derive.js.map +1 -0
- package/dist/core/components/mcp/tools/schemas/operations.js +243 -0
- package/dist/core/components/mcp/tools/schemas/operations.js.map +1 -0
- package/dist/core/components/mcp/transport.js +467 -0
- package/dist/core/components/mcp/transport.js.map +1 -0
- package/dist/core/components/ollama/index.js +239 -0
- package/dist/core/components/ollama/index.js.map +1 -0
- package/dist/core/components/openai/index.js +475 -0
- package/dist/core/components/openai/index.js.map +1 -0
- package/dist/core/components/operations.js +198 -52
- package/dist/core/components/operations.js.map +1 -1
- package/dist/core/components/operationsValidation.js +3 -3
- package/dist/core/components/packageComponent.js +87 -26
- package/dist/core/components/packageComponent.js.map +1 -1
- package/dist/core/components/requestRestart.js +12 -1
- package/dist/core/components/requestRestart.js.map +1 -1
- package/dist/core/components/status/crossThread.js +12 -5
- package/dist/core/components/status/crossThread.js.map +1 -1
- package/dist/core/components/status/errors.js +7 -7
- package/dist/core/config/RootConfigWatcher.js +52 -1
- package/dist/core/config/RootConfigWatcher.js.map +1 -1
- package/dist/core/config/configUtils.js +31 -8
- package/dist/core/config/configUtils.js.map +1 -1
- package/dist/core/config/harperConfigEnvVars.js +1 -1
- package/dist/core/config/harperConfigEnvVars.js.map +1 -1
- package/dist/core/dataLayer/CreateAttributeObject.js +4 -3
- package/dist/core/dataLayer/CreateAttributeObject.js.map +1 -1
- package/dist/core/dataLayer/CreateTableObject.js +2 -1
- package/dist/core/dataLayer/CreateTableObject.js.map +1 -1
- package/dist/core/dataLayer/DataLayerObjects.js +19 -5
- package/dist/core/dataLayer/DataLayerObjects.js.map +1 -1
- package/dist/core/dataLayer/DeleteBeforeObject.js +2 -1
- package/dist/core/dataLayer/DeleteBeforeObject.js.map +1 -1
- package/dist/core/dataLayer/DeleteObject.js +4 -3
- package/dist/core/dataLayer/DeleteObject.js.map +1 -1
- package/dist/core/dataLayer/DropAttributeObject.js +2 -1
- package/dist/core/dataLayer/DropAttributeObject.js.map +1 -1
- package/dist/core/dataLayer/GetBackupObject.js +4 -3
- package/dist/core/dataLayer/GetBackupObject.js.map +1 -1
- package/dist/core/dataLayer/InsertObject.js +4 -3
- package/dist/core/dataLayer/InsertObject.js.map +1 -1
- package/dist/core/dataLayer/ReadAuditLogObject.js +4 -3
- package/dist/core/dataLayer/ReadAuditLogObject.js.map +1 -1
- package/dist/core/dataLayer/SQLSearch.js +140 -78
- package/dist/core/dataLayer/SQLSearch.js.map +1 -1
- package/dist/core/dataLayer/SearchByConditionsObject.js +5 -7
- package/dist/core/dataLayer/SearchByConditionsObject.js.map +1 -1
- package/dist/core/dataLayer/SearchByHashObject.js +2 -1
- package/dist/core/dataLayer/SearchByHashObject.js.map +1 -1
- package/dist/core/dataLayer/SearchObject.js +2 -1
- package/dist/core/dataLayer/SearchObject.js.map +1 -1
- package/dist/core/dataLayer/SqlSearchObject.js +2 -1
- package/dist/core/dataLayer/SqlSearchObject.js.map +1 -1
- package/dist/core/dataLayer/UpdateObject.js +4 -3
- package/dist/core/dataLayer/UpdateObject.js.map +1 -1
- package/dist/core/dataLayer/UpsertObject.js +4 -3
- package/dist/core/dataLayer/UpsertObject.js.map +1 -1
- package/dist/core/dataLayer/bulkLoad.js +122 -88
- package/dist/core/dataLayer/bulkLoad.js.map +1 -1
- package/dist/core/dataLayer/delete.js +74 -39
- package/dist/core/dataLayer/delete.js.map +1 -1
- package/dist/core/dataLayer/export.js +90 -55
- package/dist/core/dataLayer/export.js.map +1 -1
- package/dist/core/dataLayer/getBackup.js +43 -11
- package/dist/core/dataLayer/getBackup.js.map +1 -1
- package/dist/core/dataLayer/harperBridge/BridgeMethods.js +41 -20
- package/dist/core/dataLayer/harperBridge/BridgeMethods.js.map +1 -1
- package/dist/core/dataLayer/harperBridge/ResourceBridge.js +26 -25
- package/dist/core/dataLayer/harperBridge/ResourceBridge.js.map +1 -1
- package/dist/core/dataLayer/harperBridge/TableSizeObject.js.map +1 -1
- package/dist/core/dataLayer/harperBridge/bridgeUtility/insertUpdateValidate.js +4 -4
- package/dist/core/dataLayer/harperBridge/harperBridge.js +38 -4
- package/dist/core/dataLayer/harperBridge/harperBridge.js.map +1 -1
- package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateAttribute.js +7 -6
- package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateAttribute.js.map +1 -1
- package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateRecords.js +4 -4
- package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateRecords.js.map +1 -1
- package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateSchema.js +1 -1
- package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateSchema.js.map +1 -1
- package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateTable.js +5 -4
- package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateTable.js.map +1 -1
- package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDeleteAuditLogsBefore.js +4 -4
- package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDeleteAuditLogsBefore.js.map +1 -1
- package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDeleteRecords.js +4 -4
- package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDropAttribute.js +5 -5
- package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDropAttribute.js.map +1 -1
- package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDropSchema.js +4 -4
- package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDropSchema.js.map +1 -1
- package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDropTable.js +5 -5
- package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDropTable.js.map +1 -1
- package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbFlush.js +1 -1
- package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbGetBackup.js +3 -3
- package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbGetDataByHash.js +1 -1
- package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbGetDataByValue.js +2 -2
- package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbGetDataByValue.js.map +1 -1
- package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbReadAuditLog.js +5 -5
- package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbSearchByConditions.js +8 -8
- package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbSearchByConditions.js.map +1 -1
- package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbSearchByHash.js +1 -1
- package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbSearchByValue.js +3 -3
- package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbSearchByValue.js.map +1 -1
- package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbUpdateRecords.js +3 -3
- package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbUpsertRecords.js +5 -5
- package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbUpsertRecords.js.map +1 -1
- package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbUtility/LMDBCreateAttributeObject.js +1 -1
- package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbUtility/LMDBCreateAttributeObject.js.map +1 -1
- package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbUtility/initializeHashSearch.js +2 -2
- package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbUtility/initializeHashSearch.js.map +1 -1
- package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbUtility/initializePaths.js +2 -2
- package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbCheckForNewAttributes.js +4 -4
- package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbCheckForNewAttributes.js.map +1 -1
- package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbCreateTransactionsAuditEnvironment.js +5 -3
- package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbCreateTransactionsAuditEnvironment.js.map +1 -1
- package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbGetTableSize.js +2 -2
- package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbProcessRows.js +4 -4
- package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbProcessRows.js.map +1 -1
- package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbSearch.js +5 -5
- package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbWriteTransaction.js +4 -4
- package/dist/core/dataLayer/hdbInfoController.js +66 -31
- package/dist/core/dataLayer/hdbInfoController.js.map +1 -1
- package/dist/core/dataLayer/insert.js +63 -28
- package/dist/core/dataLayer/insert.js.map +1 -1
- package/dist/core/dataLayer/readAuditLog.js +45 -13
- package/dist/core/dataLayer/readAuditLog.js.map +1 -1
- package/dist/core/dataLayer/schema.js +124 -89
- package/dist/core/dataLayer/schema.js.map +1 -1
- package/dist/core/dataLayer/schemaDescribe.js +78 -41
- package/dist/core/dataLayer/schemaDescribe.js.map +1 -1
- package/dist/core/dataLayer/search.js +12 -13
- package/dist/core/dataLayer/search.js.map +1 -1
- package/dist/core/dataLayer/transaction.js +3 -4
- package/dist/core/dataLayer/transaction.js.map +1 -1
- package/dist/core/dataLayer/update.js +53 -18
- package/dist/core/dataLayer/update.js.map +1 -1
- package/dist/core/globals.js +1 -0
- package/dist/core/globals.js.map +1 -1
- package/dist/core/index.js +4 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/json/systemSchema.json +65 -0
- package/dist/core/launchServiceScripts/utility/checkNodeVersion.js +3 -0
- package/dist/core/launchServiceScripts/utility/checkNodeVersion.js.map +1 -1
- package/dist/core/resources/DatabaseTransaction.js +39 -15
- package/dist/core/resources/DatabaseTransaction.js.map +1 -1
- package/dist/core/resources/ErrorResource.js +3 -1
- package/dist/core/resources/ErrorResource.js.map +1 -1
- package/dist/core/resources/LMDBTransaction.js +18 -7
- package/dist/core/resources/LMDBTransaction.js.map +1 -1
- package/dist/core/resources/RecordEncoder.js +5 -2
- package/dist/core/resources/RecordEncoder.js.map +1 -1
- package/dist/core/resources/RequestTarget.js.map +1 -1
- package/dist/core/resources/Resource.js +37 -10
- package/dist/core/resources/Resource.js.map +1 -1
- package/dist/core/resources/ResourceInterface.js +20 -0
- package/dist/core/resources/ResourceInterface.js.map +1 -1
- package/dist/core/resources/Resources.js +7 -6
- package/dist/core/resources/Resources.js.map +1 -1
- package/dist/core/resources/RocksIndexStore.js +3 -0
- package/dist/core/resources/RocksIndexStore.js.map +1 -1
- package/dist/core/resources/RocksTransactionLogStore.js +46 -27
- package/dist/core/resources/RocksTransactionLogStore.js.map +1 -1
- package/dist/core/resources/Table.js +267 -107
- package/dist/core/resources/Table.js.map +1 -1
- package/dist/core/resources/analytics/metadata.js +1 -0
- package/dist/core/resources/analytics/metadata.js.map +1 -1
- package/dist/core/resources/analytics/read.js +16 -5
- package/dist/core/resources/analytics/read.js.map +1 -1
- package/dist/core/resources/analytics/write.js +232 -20
- package/dist/core/resources/analytics/write.js.map +1 -1
- package/dist/core/resources/auditStore.js +13 -8
- package/dist/core/resources/auditStore.js.map +1 -1
- package/dist/core/resources/blob.js +8 -8
- package/dist/core/resources/blob.js.map +1 -1
- package/dist/core/resources/dataLoader.js +13 -13
- package/dist/core/resources/databases.js +160 -52
- package/dist/core/resources/databases.js.map +1 -1
- package/dist/core/resources/graphql.js +224 -174
- package/dist/core/resources/graphql.js.map +1 -1
- package/dist/core/resources/indexes/HierarchicalNavigableSmallWorld.js +308 -59
- package/dist/core/resources/indexes/HierarchicalNavigableSmallWorld.js.map +1 -1
- package/dist/core/resources/indexes/vector.js +14 -0
- package/dist/core/resources/indexes/vector.js.map +1 -1
- package/dist/core/resources/loadEnv.js +21 -18
- package/dist/core/resources/loadEnv.js.map +1 -1
- package/dist/core/resources/login.js +5 -4
- package/dist/core/resources/login.js.map +1 -1
- package/dist/core/resources/models/Models.js +265 -0
- package/dist/core/resources/models/Models.js.map +1 -0
- package/dist/core/resources/models/TestBackend.js +71 -0
- package/dist/core/resources/models/TestBackend.js.map +1 -0
- package/dist/core/resources/models/agentLoop.js +746 -0
- package/dist/core/resources/models/agentLoop.js.map +1 -0
- package/dist/core/resources/models/analyticsTable.js +166 -0
- package/dist/core/resources/models/analyticsTable.js.map +1 -0
- package/dist/core/resources/models/backendHelpers.js +109 -0
- package/dist/core/resources/models/backendHelpers.js.map +1 -0
- package/dist/core/resources/models/backendRegistry.js +54 -0
- package/dist/core/resources/models/backendRegistry.js.map +1 -0
- package/dist/core/resources/models/bootstrap.js +112 -0
- package/dist/core/resources/models/bootstrap.js.map +1 -0
- package/dist/core/resources/models/embedHook.js +127 -0
- package/dist/core/resources/models/embedHook.js.map +1 -0
- package/dist/core/resources/models/types.js +11 -0
- package/dist/core/resources/models/types.js.map +1 -0
- package/dist/core/resources/replayLogs.js +7 -1
- package/dist/core/resources/replayLogs.js.map +1 -1
- package/dist/core/resources/roles.js +67 -71
- package/dist/core/resources/roles.js.map +1 -1
- package/dist/core/resources/search.js +349 -140
- package/dist/core/resources/search.js.map +1 -1
- package/dist/core/resources/tracked.js +14 -14
- package/dist/core/resources/tracked.js.map +1 -1
- package/dist/core/resources/transaction.js +1 -1
- package/dist/core/resources/transaction.js.map +1 -1
- package/dist/core/resources/transactionBroadcast.js.map +1 -1
- package/dist/core/security/auth.js +34 -25
- package/dist/core/security/auth.js.map +1 -1
- package/dist/core/security/certificateVerification/crlVerification.js +7 -1
- package/dist/core/security/certificateVerification/crlVerification.js.map +1 -1
- package/dist/core/security/cryptoHash.js +37 -5
- package/dist/core/security/cryptoHash.js.map +1 -1
- package/dist/core/security/data_objects/PermissionAttributeResponseObject.js +4 -1
- package/dist/core/security/data_objects/PermissionAttributeResponseObject.js.map +1 -1
- package/dist/core/security/data_objects/PermissionResponseObject.js +15 -8
- package/dist/core/security/data_objects/PermissionResponseObject.js.map +1 -1
- package/dist/core/security/data_objects/PermissionTableResponseObject.js +6 -1
- package/dist/core/security/data_objects/PermissionTableResponseObject.js.map +1 -1
- package/dist/core/security/fastifyAuth.js +131 -22
- package/dist/core/security/fastifyAuth.js.map +1 -1
- package/dist/core/security/impersonation.js +15 -15
- package/dist/core/security/jsLoader.js +18 -5
- package/dist/core/security/jsLoader.js.map +1 -1
- package/dist/core/security/keys.js +160 -114
- package/dist/core/security/keys.js.map +1 -1
- package/dist/core/security/permissionsTranslator.js +2 -2
- package/dist/core/security/role.js +70 -35
- package/dist/core/security/role.js.map +1 -1
- package/dist/core/security/tokenAuthentication.js +57 -27
- package/dist/core/security/tokenAuthentication.js.map +1 -1
- package/dist/core/security/user.js +74 -38
- package/dist/core/security/user.js.map +1 -1
- package/dist/core/server/DurableSubscriptionsSession.js +71 -55
- package/dist/core/server/DurableSubscriptionsSession.js.map +1 -1
- package/dist/core/server/REST.js +17 -16
- package/dist/core/server/REST.js.map +1 -1
- package/dist/core/server/Server.js +1 -1
- package/dist/core/server/Server.js.map +1 -1
- package/dist/core/server/fastifyRoutes/helpers/getCORSOptions.js +1 -1
- package/dist/core/server/fastifyRoutes/helpers/getHeaderTimeoutConfig.js +1 -1
- package/dist/core/server/fastifyRoutes/helpers/getServerOptions.js +1 -1
- package/dist/core/server/fastifyRoutes.js +34 -30
- package/dist/core/server/fastifyRoutes.js.map +1 -1
- package/dist/core/server/graphqlQuerying.js +8 -7
- package/dist/core/server/graphqlQuerying.js.map +1 -1
- package/dist/core/server/http.js +523 -47
- package/dist/core/server/http.js.map +1 -1
- package/dist/core/server/itc/serverHandlers.js +66 -15
- package/dist/core/server/itc/serverHandlers.js.map +1 -1
- package/dist/core/server/jobs/JobObject.js +53 -7
- package/dist/core/server/jobs/JobObject.js.map +1 -1
- package/dist/core/server/jobs/jobProcess.js +64 -24
- package/dist/core/server/jobs/jobProcess.js.map +1 -1
- package/dist/core/server/jobs/jobRunner.js +68 -30
- package/dist/core/server/jobs/jobRunner.js.map +1 -1
- package/dist/core/server/jobs/jobs.js +93 -61
- package/dist/core/server/jobs/jobs.js.map +1 -1
- package/dist/core/server/loadRootComponents.js +1 -1
- package/dist/core/server/middlewareChain.js +252 -0
- package/dist/core/server/middlewareChain.js.map +1 -0
- package/dist/core/server/mqtt.js +22 -17
- package/dist/core/server/mqtt.js.map +1 -1
- package/dist/core/server/nodeName.js +44 -13
- package/dist/core/server/nodeName.js.map +1 -1
- package/dist/core/server/operationsServer.js +106 -33
- package/dist/core/server/operationsServer.js.map +1 -1
- package/dist/core/server/serverHelpers/Headers.js +2 -0
- package/dist/core/server/serverHelpers/Headers.js.map +1 -1
- package/dist/core/server/serverHelpers/JSONStream.js +12 -3
- package/dist/core/server/serverHelpers/JSONStream.js.map +1 -1
- package/dist/core/server/serverHelpers/Request.js +370 -9
- package/dist/core/server/serverHelpers/Request.js.map +1 -1
- package/dist/core/server/serverHelpers/contentTypes.js +36 -7
- package/dist/core/server/serverHelpers/contentTypes.js.map +1 -1
- package/dist/core/server/serverHelpers/multipartParser.js +142 -0
- package/dist/core/server/serverHelpers/multipartParser.js.map +1 -0
- package/dist/core/server/serverHelpers/progressEmitter.js +103 -0
- package/dist/core/server/serverHelpers/progressEmitter.js.map +1 -0
- package/dist/core/server/serverHelpers/serverHandlers.js +38 -7
- package/dist/core/server/serverHelpers/serverHandlers.js.map +1 -1
- package/dist/core/server/serverHelpers/serverUtilities.js +97 -93
- package/dist/core/server/serverHelpers/serverUtilities.js.map +1 -1
- package/dist/core/server/static.js +8 -5
- package/dist/core/server/static.js.map +1 -1
- package/dist/core/server/status/index.js +3 -3
- package/dist/core/server/storageReclamation.js +68 -9
- package/dist/core/server/storageReclamation.js.map +1 -1
- package/dist/core/server/threads/itc.js +7 -4
- package/dist/core/server/threads/itc.js.map +1 -1
- package/dist/core/server/threads/manageThreads.js +110 -26
- package/dist/core/server/threads/manageThreads.js.map +1 -1
- package/dist/core/server/threads/socketRouter.js +8 -271
- package/dist/core/server/threads/socketRouter.js.map +1 -1
- package/dist/core/server/threads/threadServer.js +360 -118
- package/dist/core/server/threads/threadServer.js.map +1 -1
- package/dist/core/server/threads/workerProcessGuard.js +114 -0
- package/dist/core/server/threads/workerProcessGuard.js.map +1 -0
- package/dist/core/server/throttle.js +17 -0
- package/dist/core/server/throttle.js.map +1 -1
- package/dist/core/sqlTranslator/SelectValidator.js +86 -47
- package/dist/core/sqlTranslator/SelectValidator.js.map +1 -1
- package/dist/core/sqlTranslator/alasqlFunctionImporter.js +40 -3
- package/dist/core/sqlTranslator/alasqlFunctionImporter.js.map +1 -1
- package/dist/core/sqlTranslator/deleteTranslator.js +48 -14
- package/dist/core/sqlTranslator/deleteTranslator.js.map +1 -1
- package/dist/core/sqlTranslator/index.js +69 -30
- package/dist/core/sqlTranslator/index.js.map +1 -1
- package/dist/core/sqlTranslator/sql_statement_bucket.js +55 -13
- package/dist/core/sqlTranslator/sql_statement_bucket.js.map +1 -1
- package/dist/core/upgrade/UpgradeObjects.js +37 -4
- package/dist/core/upgrade/UpgradeObjects.js.map +1 -1
- package/dist/core/upgrade/directives/5-2-0.js +77 -0
- package/dist/core/upgrade/directives/5-2-0.js.map +1 -0
- package/dist/core/upgrade/directives/directivesController.js +52 -11
- package/dist/core/upgrade/directives/directivesController.js.map +1 -1
- package/dist/core/upgrade/directivesManager.js +53 -18
- package/dist/core/upgrade/directivesManager.js.map +1 -1
- package/dist/core/upgrade/upgradePrompt.js +65 -30
- package/dist/core/upgrade/upgradePrompt.js.map +1 -1
- package/dist/core/upgrade/upgradeUtilities.js +37 -5
- package/dist/core/upgrade/upgradeUtilities.js.map +1 -1
- package/dist/core/utility/OperationFunctionCaller.js +45 -10
- package/dist/core/utility/OperationFunctionCaller.js.map +1 -1
- package/dist/core/utility/assignCmdEnvVariables.js +8 -4
- package/dist/core/utility/assignCmdEnvVariables.js.map +1 -1
- package/dist/core/utility/common_utils.js +140 -79
- package/dist/core/utility/common_utils.js.map +1 -1
- package/dist/core/utility/environment/environmentManager.js +75 -29
- package/dist/core/utility/environment/environmentManager.js.map +1 -1
- package/dist/core/utility/environment/systemInformation.js +27 -16
- package/dist/core/utility/environment/systemInformation.js.map +1 -1
- package/dist/core/utility/errors/commonErrors.js +49 -18
- package/dist/core/utility/errors/commonErrors.js.map +1 -1
- package/dist/core/utility/errors/hdbError.js +65 -26
- package/dist/core/utility/errors/hdbError.js.map +1 -1
- package/dist/core/utility/expandEnvVar.js +113 -0
- package/dist/core/utility/expandEnvVar.js.map +1 -0
- package/dist/core/utility/functions/geo.js +2 -2
- package/dist/core/utility/functions/sql/alaSQLExtension.js +1 -1
- package/dist/core/utility/globalSchema.js +14 -11
- package/dist/core/utility/globalSchema.js.map +1 -1
- package/dist/core/utility/hdbTerms.js +56 -0
- package/dist/core/utility/hdbTerms.js.map +1 -1
- package/dist/core/utility/install/checkJWTTokensExist.js +1 -1
- package/dist/core/utility/install/installer.js +106 -70
- package/dist/core/utility/install/installer.js.map +1 -1
- package/dist/core/utility/installation.js +3 -3
- package/dist/core/utility/lmdb/DBIDefinition.js +5 -1
- package/dist/core/utility/lmdb/DBIDefinition.js.map +1 -1
- package/dist/core/utility/lmdb/DeleteRecordsResponseObject.js +2 -1
- package/dist/core/utility/lmdb/DeleteRecordsResponseObject.js.map +1 -1
- package/dist/core/utility/lmdb/InsertRecordsResponseObject.js +2 -1
- package/dist/core/utility/lmdb/InsertRecordsResponseObject.js.map +1 -1
- package/dist/core/utility/lmdb/OpenDBIObject.js +54 -6
- package/dist/core/utility/lmdb/OpenDBIObject.js.map +1 -1
- package/dist/core/utility/lmdb/OpenEnvironmentObject.js +52 -4
- package/dist/core/utility/lmdb/OpenEnvironmentObject.js.map +1 -1
- package/dist/core/utility/lmdb/UpdateRecordsResponseObject.js +2 -1
- package/dist/core/utility/lmdb/UpdateRecordsResponseObject.js.map +1 -1
- package/dist/core/utility/lmdb/UpsertRecordsResponseObject.js +2 -1
- package/dist/core/utility/lmdb/UpsertRecordsResponseObject.js.map +1 -1
- package/dist/core/utility/lmdb/cleanLMDBMap.js +44 -7
- package/dist/core/utility/lmdb/cleanLMDBMap.js.map +1 -1
- package/dist/core/utility/lmdb/commonUtility.js +46 -17
- package/dist/core/utility/lmdb/commonUtility.js.map +1 -1
- package/dist/core/utility/lmdb/deleteUtility.js +51 -16
- package/dist/core/utility/lmdb/deleteUtility.js.map +1 -1
- package/dist/core/utility/lmdb/environmentUtility.js +91 -51
- package/dist/core/utility/lmdb/environmentUtility.js.map +1 -1
- package/dist/core/utility/lmdb/searchCursorFunctions.js +46 -14
- package/dist/core/utility/lmdb/searchCursorFunctions.js.map +1 -1
- package/dist/core/utility/lmdb/searchUtility.js +91 -55
- package/dist/core/utility/lmdb/searchUtility.js.map +1 -1
- package/dist/core/utility/lmdb/terms.js +12 -22
- package/dist/core/utility/lmdb/terms.js.map +1 -1
- package/dist/core/utility/lmdb/writeUtility.js +61 -28
- package/dist/core/utility/lmdb/writeUtility.js.map +1 -1
- package/dist/core/utility/logging/harper_logger.js +176 -81
- package/dist/core/utility/logging/harper_logger.js.map +1 -1
- package/dist/core/utility/logging/logRotator.js +65 -28
- package/dist/core/utility/logging/logRotator.js.map +1 -1
- package/dist/core/utility/logging/logger.js +4 -4
- package/dist/core/utility/logging/readLog.js +54 -17
- package/dist/core/utility/logging/readLog.js.map +1 -1
- package/dist/core/utility/logging/transactionLog.js +51 -16
- package/dist/core/utility/logging/transactionLog.js.map +1 -1
- package/dist/core/utility/mount_hdb.js +54 -17
- package/dist/core/utility/mount_hdb.js.map +1 -1
- package/dist/core/utility/npmUtilities.js +54 -19
- package/dist/core/utility/npmUtilities.js.map +1 -1
- package/dist/core/utility/operation_authorization.js +135 -86
- package/dist/core/utility/operation_authorization.js.map +1 -1
- package/dist/core/utility/packageUtils.js +7 -17
- package/dist/core/utility/packageUtils.js.map +1 -1
- package/dist/core/utility/password.js +2 -2
- package/dist/core/utility/processManagement/processManagement.js +2 -2
- package/dist/core/utility/processManagement/servicesConfig.js +1 -1
- package/dist/core/utility/signalling.js +51 -16
- package/dist/core/utility/signalling.js.map +1 -1
- package/dist/core/utility/watcherFallback.js +73 -0
- package/dist/core/utility/watcherFallback.js.map +1 -0
- package/dist/core/validation/analyticsValidator.js +79 -0
- package/dist/core/validation/analyticsValidator.js.map +1 -0
- package/dist/core/validation/bulkDeleteValidator.js +49 -11
- package/dist/core/validation/bulkDeleteValidator.js.map +1 -1
- package/dist/core/validation/check_permissions.js +38 -3
- package/dist/core/validation/check_permissions.js.map +1 -1
- package/dist/core/validation/common_validators.js +62 -31
- package/dist/core/validation/common_validators.js.map +1 -1
- package/dist/core/validation/configValidator.js +189 -54
- package/dist/core/validation/configValidator.js.map +1 -1
- package/dist/core/validation/deleteValidator.js +49 -11
- package/dist/core/validation/deleteValidator.js.map +1 -1
- package/dist/core/validation/fileLoadValidator.js +67 -32
- package/dist/core/validation/fileLoadValidator.js.map +1 -1
- package/dist/core/validation/insertValidator.js +48 -10
- package/dist/core/validation/insertValidator.js.map +1 -1
- package/dist/core/validation/installValidator.js +47 -10
- package/dist/core/validation/installValidator.js.map +1 -1
- package/dist/core/validation/readLogValidator.js +60 -22
- package/dist/core/validation/readLogValidator.js.map +1 -1
- package/dist/core/validation/role_validation.js +55 -19
- package/dist/core/validation/role_validation.js.map +1 -1
- package/dist/core/validation/schemaMetadataValidator.js +11 -12
- package/dist/core/validation/schemaMetadataValidator.js.map +1 -1
- package/dist/core/validation/searchValidator.js +82 -43
- package/dist/core/validation/searchValidator.js.map +1 -1
- package/dist/core/validation/transactionLogValidator.js +52 -17
- package/dist/core/validation/transactionLogValidator.js.map +1 -1
- package/dist/core/validation/user_validation.js +38 -6
- package/dist/core/validation/user_validation.js.map +1 -1
- package/dist/core/validation/validationWrapper.js +4 -5
- package/dist/core/validation/validationWrapper.js.map +1 -1
- package/dist/licensing/usageLicensing.js +30 -21
- package/dist/licensing/usageLicensing.js.map +1 -1
- package/dist/replication/knownNodes.js +173 -39
- package/dist/replication/knownNodes.js.map +1 -1
- package/dist/replication/replicationConnection.js +441 -85
- package/dist/replication/replicationConnection.js.map +1 -1
- package/dist/replication/replicator.js +44 -26
- package/dist/replication/replicator.js.map +1 -1
- package/dist/replication/setNode.js +22 -2
- package/dist/replication/setNode.js.map +1 -1
- package/dist/replication/subscriptionManager.js +121 -9
- package/dist/replication/subscriptionManager.js.map +1 -1
- package/dist/security/certificate.js +41 -6
- package/dist/security/certificate.js.map +1 -1
- package/dist/security/sshKeyOperations.js +35 -2
- package/dist/security/sshKeyOperations.js.map +1 -1
- package/licensing/usageLicensing.ts +32 -37
- package/npm-shrinkwrap.json +8994 -4305
- package/package.json +16 -11
- package/replication/DESIGN.md +139 -0
- package/replication/knownNodes.ts +166 -43
- package/replication/replicationConnection.ts +475 -92
- package/replication/replicator.ts +42 -25
- package/replication/setNode.ts +28 -9
- package/replication/subscriptionManager.ts +138 -14
- package/security/certificate.ts +8 -4
- package/security/sshKeyOperations.ts +1 -1
- package/static/defaultConfig.yaml +1 -0
- package/studio/web/assets/{index-CmtPP0YO.js → index-COfIkCT-.js} +5 -5
- package/studio/web/assets/index-COfIkCT-.js.map +1 -0
- package/studio/web/assets/{index.lazy-C8jvGtlu.js → index.lazy-CIvl7Fj9.js} +2 -2
- package/studio/web/assets/{index.lazy-C8jvGtlu.js.map → index.lazy-CIvl7Fj9.js.map} +1 -1
- package/studio/web/assets/{profile-O0DYlJUv.js → profile-B2ZVB--r.js} +2 -2
- package/studio/web/assets/{profile-O0DYlJUv.js.map → profile-B2ZVB--r.js.map} +1 -1
- package/studio/web/assets/{status-BIlJkJby.js → status-Db6WBmhf.js} +2 -2
- package/studio/web/assets/{status-BIlJkJby.js.map → status-Db6WBmhf.js.map} +1 -1
- package/studio/web/index.html +1 -1
- package/core/bin/cliOperations.js +0 -159
- package/core/bin/lite.js +0 -5
- package/core/bin/stop.js +0 -21
- package/core/dataLayer/harperBridge/BridgeMethods.js +0 -85
- package/core/utility/globalSchema.js +0 -35
- package/core/utility/lmdb/OpenDBIObject.js +0 -31
- package/studio/web/assets/index-CmtPP0YO.js.map +0 -1
package/analytics/profile.ts
CHANGED
|
@@ -32,6 +32,10 @@ const SAMPLING_INTERVAL_IN_MICROSECONDS = 50000;
|
|
|
32
32
|
export function handleApplication({ options }: Scope) {
|
|
33
33
|
setTimeout(async () => {
|
|
34
34
|
if (userCodeFolders.length === 0) return;
|
|
35
|
+
if (options.get(['profiling']) === false) {
|
|
36
|
+
log.info?.('Profiling disabled by configuration');
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
35
39
|
// start the profiler
|
|
36
40
|
if (!profilerStarted) {
|
|
37
41
|
profilerStarted = true;
|
package/core/AGENTS.md
CHANGED
|
@@ -59,19 +59,20 @@ The plugin/application loader. Applications export a `handleApplication(scope)`
|
|
|
59
59
|
Files within a component are discovered via micromatch glob patterns and automatically mapped to URL paths.
|
|
60
60
|
|
|
61
61
|
**Server** (`server/`)
|
|
62
|
-
|
|
62
|
+
Multiple HTTP entry points coexist:
|
|
63
63
|
|
|
64
|
-
- **Native layer** (`server/http.ts`) — direct socket handling for HTTP/1.1, HTTPS, HTTP/2, and WebSockets in one path; highest performance
|
|
65
|
-
- **
|
|
64
|
+
- **Native layer** (`server/http.ts`) — direct socket handling for application-level HTTP/1.1, HTTPS, HTTP/2, and WebSockets in one path; highest performance. Most user traffic goes through here.
|
|
65
|
+
- **Operations API** (`server/operationsServer.ts`) — Fastify-based JSON operations API (`{operation: 'create_table', ...}`); internal/admin surface.
|
|
66
|
+
- **Custom Functions (legacy)** (`server/fastifyRoutes.ts`) — legacy Fastify autoload for user-defined routes. Don't add new code here.
|
|
66
67
|
|
|
67
|
-
All inbound protocols (REST, GraphQL, MQTT, NATS, WebSockets) eventually resolve to the same **Resource interface**.
|
|
68
|
+
All inbound protocols (REST, GraphQL, MQTT, NATS, WebSockets) eventually resolve to the same **Resource interface**. See `server/DESIGN.md` for the file-by-file map and the `http.ts` section index.
|
|
68
69
|
|
|
69
70
|
**Resources** (`resources/`)
|
|
70
71
|
The universal abstraction. Everything that can be queried or mutated — database tables, caches, message topics, custom endpoints — extends `Resource` (`resources/Resource.ts`).
|
|
71
72
|
|
|
72
73
|
Static methods (`Resource.get`, `Resource.put`, `Resource.post`, `Resource.delete`, `Resource.patch`, `Resource.subscribe`) are the entry points and are automatically wrapped with `transactional()` for transaction management. Override instance methods (`get`, `put`, etc.) for custom behavior.
|
|
73
74
|
|
|
74
|
-
`Table.ts` is the database table implementation (
|
|
75
|
+
`Table.ts` is the database table implementation (4744 lines, one giant `makeTable()` factory) — the most complex file in the codebase. **Use `resources/DESIGN.md` as a section index instead of reading top-to-bottom.**
|
|
75
76
|
|
|
76
77
|
**Data Layer** (`dataLayer/`)
|
|
77
78
|
Legacy translation modules plus SQL translation (`sqlTranslator/`) via AlaSQL; these should be avoided. The storage engine is selectable via `HARPER_STORAGE_ENGINE=lmdb`.
|
|
@@ -80,7 +81,62 @@ Legacy translation modules plus SQL translation (`sqlTranslator/`) via AlaSQL; t
|
|
|
80
81
|
YAML-based. `configUtils.js` parses config; `RootConfigWatcher.ts` enables hot reload. Environment variables override YAML values.
|
|
81
82
|
|
|
82
83
|
**Utility** (`utility/`)
|
|
83
|
-
Logging, error types, helpers, async utilities.
|
|
84
|
+
Logging, error types, helpers, async utilities. Most-used: `utility/hdbTerms.ts` (global constants), `utility/logging/harper_logger.js`, `utility/errors/hdbError.js`.
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## Repository map
|
|
89
|
+
|
|
90
|
+
Use this to land in the right folder before grepping. Every top-level folder is listed; deeper docs are noted where they exist.
|
|
91
|
+
|
|
92
|
+
### Source — covered above
|
|
93
|
+
|
|
94
|
+
- **`components/`** — plugin/app loader. Entry: `Scope.ts`, `OptionsWatcher.ts`. Tests: `unitTests/components/`.
|
|
95
|
+
- **`server/`** — HTTP/WS/MQTT/etc. Entry: `operationsServer.ts` (boot), `http.ts` (native HTTP). **See [server/DESIGN.md](server/DESIGN.md).** Tests: `unitTests/server/`.
|
|
96
|
+
- **`resources/`** — universal Resource abstraction; tables. Entry: `Resource.ts`, `Table.ts`. **See [resources/DESIGN.md](resources/DESIGN.md).** Tests: `unitTests/resources/`.
|
|
97
|
+
- **`dataLayer/`** — legacy translation modules (`insert.js`, `search.js`, `update.js`). **Avoid for new code.** Tests: `unitTests/dataLayer/`.
|
|
98
|
+
- **`config/`** — YAML config + hot reload. Entry: `configUtils.js`, `RootConfigWatcher.ts`. Tests: `unitTests/config/`.
|
|
99
|
+
- **`utility/`** — logging, errors, helpers. Tests: `unitTests/utility/`.
|
|
100
|
+
|
|
101
|
+
### Other source folders
|
|
102
|
+
|
|
103
|
+
- **`bin/`** — CLI entry points. `harper.js` is the executable; `run.js` initializes and runs the server; `cliOperations.js` translates CLI args → API operations. Tests: `unitTests/bin/`. **Don't look here for** business logic.
|
|
104
|
+
- **`security/`** — auth, authz, certificate handling, context. Entry: `jsLoader.ts` exposes `getContext()`, `getResponse()`, `getUser()`; `user.ts` for User/Role; `certificateVerification/` for TLS validation; `data_objects/` for permission/role models. Tests: `unitTests/security/`.
|
|
105
|
+
- **`sqlTranslator/`** — SQL → internal operations via AlaSQL AST. Entry: `sqlTranslator/index.js` exports `evaluateSQL`, `processAST`, `convertSQLToAST`, `checkASTPermissions`. **Legacy — avoid for new code.** Tests: `unitTests/sqlTranslator/`.
|
|
106
|
+
- **`validation/`** — input shape validation (Joi + `validate.js`). Entry: `validationWrapper.js`. **Not authorization** — that's in `security/`. Tests: `unitTests/validation/`.
|
|
107
|
+
- **`upgrade/`** — version-upgrade orchestration. Entry: `directivesManager.js` exports `processDirectives()`. Per-version logic in `directives/`. Tests: `integrationTests/upgrade/`.
|
|
108
|
+
- **`launchServiceScripts/`** — thin launchers that delegate to `server/operationsServer.ts`. `checkNodeVersion.js` is the pre-flight Node version check.
|
|
109
|
+
- **`json/`** — system schema definitions. `systemSchema.json` defines built-in tables (`hdb_user`, `hdb_role`, `hdb_permission`). Loaded at startup; no code.
|
|
110
|
+
|
|
111
|
+
### Non-source
|
|
112
|
+
|
|
113
|
+
- **`bin/`** — covered above (it's source).
|
|
114
|
+
- **`benchmarks/`** — HNSW vector-search benchmark only (`hnsw-search.js`). Stand-alone; not part of CI.
|
|
115
|
+
- **`build-tools/`** — shell scripts for the build pipeline (`build.sh`, `build-studio.sh`, `download-prebuilds.js`). No tests.
|
|
116
|
+
- **`dev/`** — single dev utility (`sync-commits.js`) for cross-repo commit syncing. Not runtime.
|
|
117
|
+
- **`integrationTests/`** — end-to-end tests against a built distribution. Run with `npm run test:integration` / `npm run test:integration:all`. Subdirs mirror source. See `integrationTests/README.md`.
|
|
118
|
+
- **`unitTests/`** — Mocha unit tests; subdir per source layer. Run with `npm run test:unit:<layer>`.
|
|
119
|
+
- **`static/`** — assets only: `defaultConfig.yaml`, `ascii_logo.txt`.
|
|
120
|
+
|
|
121
|
+
### Top-level docs to consult
|
|
122
|
+
|
|
123
|
+
- **[DESIGN.md](DESIGN.md)** — running list of non-obvious internals (RecordObject prototype, getFromSource timing, blob orphan cleanup). Read this before debugging anything record-store-related.
|
|
124
|
+
- **[dependencies.md](dependencies.md)** — rationale for every npm dependency. Required reading before adding a new package.
|
|
125
|
+
- **[storage-format.md](storage-format.md)** — on-disk layout (RocksDB/LMDB).
|
|
126
|
+
- **[CONTRIBUTING.md](CONTRIBUTING.md)** — contribution workflow.
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## Detailed navigation
|
|
131
|
+
|
|
132
|
+
For megafiles and complex subsystems, jump to the section index instead of reading top-to-bottom:
|
|
133
|
+
|
|
134
|
+
| If you are touching… | Read first |
|
|
135
|
+
| ------------------------------------------------------ | ------------------------------------------ |
|
|
136
|
+
| Anything in `resources/` (especially `Table.ts`) | [resources/DESIGN.md](resources/DESIGN.md) |
|
|
137
|
+
| HTTP/WS/MQTT, middleware ordering, content types | [server/DESIGN.md](server/DESIGN.md) |
|
|
138
|
+
| Record-store internals (commit timing, blobs, encoder) | [DESIGN.md](DESIGN.md) |
|
|
139
|
+
| Adding a dependency | [dependencies.md](dependencies.md) |
|
|
84
140
|
|
|
85
141
|
---
|
|
86
142
|
|
|
@@ -98,6 +154,35 @@ Logging, error types, helpers, async utilities.
|
|
|
98
154
|
|
|
99
155
|
---
|
|
100
156
|
|
|
157
|
+
## Git / Worktree Setup — Read Before Any Git Operation
|
|
158
|
+
|
|
159
|
+
This repo lives as a submodule of `harper-pro`. The submodule's git data directory is at
|
|
160
|
+
`../harper-pro/.git/modules/core/` (relative to this repo's root). That directory must contain
|
|
161
|
+
**only git metadata** — `objects/`, `refs/`, `config`, `HEAD`, etc.
|
|
162
|
+
|
|
163
|
+
**Known recurring failure mode:** If `../harper-pro/.git/modules/core/config` is ever absent or
|
|
164
|
+
replaced by a directory, git silently treats the git data dir as its own work tree. The next
|
|
165
|
+
`git checkout` deposits source files there — including a `config/` directory from the harper
|
|
166
|
+
source tree — which permanently shadows git's config file. Every subsequent agent then hits
|
|
167
|
+
`fatal: unknown error occurred while reading the configuration files` and the cycle repeats.
|
|
168
|
+
|
|
169
|
+
**Rules to prevent recurrence:**
|
|
170
|
+
|
|
171
|
+
- Never run `git submodule deinit core` + re-init from the `harper-pro` parent — it regenerates
|
|
172
|
+
the module config without the required `core.worktree` setting.
|
|
173
|
+
- Never run `git checkout` or `git reset` while your working directory is inside
|
|
174
|
+
`harper-pro/.git/modules/core/`.
|
|
175
|
+
- If you ever recreate `../harper-pro/.git/modules/core/config` from scratch, it **must** include:
|
|
176
|
+
```
|
|
177
|
+
[core]
|
|
178
|
+
worktree = ../../../core
|
|
179
|
+
```
|
|
180
|
+
- If you see source-tree files (e.g. `server/`, `resources/`, `config/`) appearing inside
|
|
181
|
+
`../harper-pro/.git/modules/core/`, stop immediately and remove them — they are corrupting the
|
|
182
|
+
git data directory.
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
101
186
|
## Non-Obvious Constraints
|
|
102
187
|
|
|
103
188
|
- `Resource` static methods must stay wrapped with `transactional()` — removing this breaks transaction isolation.
|
|
@@ -105,3 +190,4 @@ Logging, error types, helpers, async utilities.
|
|
|
105
190
|
- `contextStorage` (AsyncLocalStorage) carries per-request context (user, transaction) across async boundaries — this is how authorization and transactions work without explicit parameter threading.
|
|
106
191
|
- Tests under `unitTests/apiTests/` require the server to be stopped first (`node ./dist/bin/harper.js stop`) — `test:unit:apitests` does this automatically.
|
|
107
192
|
- `@export` annotation on a schema class auto-generates a REST API for that table — this is the primary developer-facing API.
|
|
193
|
+
- Test style: write new unit tests with `node:assert/strict` against real modules — **do not add new uses of `sinon` or `rewire`**. Older tests in `unitTests/security/` and `unitTests/utility/` still depend on them but they are not the target shape; match newer tests in `unitTests/config/*`, `unitTests/resources/*`, `unitTests/components/*`. If you can't write a test without stubbing, comment on the issue describing what's missing and stop — don't reach for sinon/rewire as a shortcut.
|
package/core/DESIGN.md
CHANGED
|
@@ -71,3 +71,27 @@ The cross-thread subscription path (default `crossThreads`) drives every `Table.
|
|
|
71
71
|
- **`databaseSubscriptions.activeCount`** is the count of live `Subscription` instances on a database. It is incremented at the end of `addSubscription` (after the Subscription is created, so the `scope: 'full-database'` early-return path correctly skips counting) and decremented in `Subscription.end()`. `notifyFromTransactionData` short-circuits when this is zero — the reusable rocksdb iterator stays put and resumes from its position the next time a subscriber arrives. Without this short-circuit, an idle database with no subscribers still pays the audit-log iteration cost on every commit during replication backlog catch-up.
|
|
72
72
|
- **`notifyScheduled` + `setImmediate`** in the `'committed'` listener defers the iteration off the commit microtask. Multiple `'committed'` events that land in the same event-loop turn collapse into one notify pass. `notifyScheduled` stays set for the entire drain — including across yield-and-resume turns — so a re-entry from a new `'committed'` event cannot spawn a second concurrent notify on the same iterator.
|
|
73
73
|
- **Batched yielding** in `notifyFromTransactionData` (`NOTIFY_BATCH_SIZE`) is gated by `allowYield`. The `'committed'` path passes `allowYield = true`; the `listenToCommits` (same-thread `aftercommit`) path does not, because that path holds an inter-thread `'thread-local-writes'` lock that must not span event-loop turns. `subscribersWithTxns` is carried across yields via `subscriptions.pendingTxnSubscribers` so the `end_txn` signal fires exactly once when the iterator truly drains. When `activeCount` drops to zero mid-yield, the next continuation drops the carry-over to avoid invoking ended subscribers' listeners.
|
|
74
|
+
|
|
75
|
+
## `createBlob(readable)` and `table.put()` don't synchronously drain the source
|
|
76
|
+
|
|
77
|
+
When a blob attribute is created from a Node `Readable` (e.g. `createBlob(stream)` then `row.payload_blob = blob; await table.put(row)`), the put does **not** wait for the underlying stream to fully drain into the file before resolving. Internally `saveBlob` kicks off a `writeBlobWithStream` pipeline whose `storageInfo.saving` promise is tracked separately. The put resolves once encoding has captured the blob reference; the bytes finish writing concurrently.
|
|
78
|
+
|
|
79
|
+
Consequence for callers that wrap the source in a hashing `Transform`: calling `hash.digest('hex')` after `await table.put()` is unsafe — more `chunk.update()` calls can still fire as the stream drains, producing `Error [ERR_CRYPTO_HASH_FINALIZED]: Digest already called`. Options:
|
|
80
|
+
|
|
81
|
+
- Buffer first, then hash + put (what `components/deploymentRecorder.ts` does for Slice A — small payloads only).
|
|
82
|
+
- Hash via Transform while extraction reads the stream, and only finalize the hash on the Transform's `'end'` event before any second put with the final hash.
|
|
83
|
+
- Await `storageInfo.saving` directly if you have a handle to the FileBackedBlob (the cleanest path for streaming).
|
|
84
|
+
|
|
85
|
+
Future agents touching `components/deploymentRecorder.ts` for Slice B's streaming variant should pick one of the latter two patterns.
|
|
86
|
+
|
|
87
|
+
## System table bootstrap: `systemSchema.json` + upgrade directive
|
|
88
|
+
|
|
89
|
+
Adding a new system table (e.g. `hdb_deployment` in #641 Slice A) requires three changes:
|
|
90
|
+
|
|
91
|
+
1. **`json/systemSchema.json`** — the table entry. Fresh installs auto-create it via `utility/mount_hdb.ts:createTables()`, which iterates `Object.keys(systemSchema)` on first boot.
|
|
92
|
+
2. **`utility/hdbTerms.ts`** — add the table name to `SYSTEM_TABLE_NAMES`.
|
|
93
|
+
3. **`upgrade/directives/<version>.ts`** — provisions the table on existing installs that already have a system schema. Registered in `upgrade/directives/directivesController.ts` (which is otherwise empty — its `versions` Map gets populated by these imports). The directive shape is `{ version, sync_functions, async_functions }`; copy `5-2-0.ts` for the canonical pattern (uses `bridge.createTable` to match what `mount_hdb` does on a fresh install).
|
|
94
|
+
|
|
95
|
+
System tables replicate by default. To opt out, add the name to `NON_REPLICATING_SYSTEM_TABLES` in `resources/databases.ts`. The check happens after table init and sets `table.replicate = false` per-node.
|
|
96
|
+
|
|
97
|
+
If the table needs `audit: true`, set it both in the schema (for fresh installs) **and** on the `CreateTableObject` instance in the directive (for upgrades) — otherwise the two paths diverge.
|
package/core/README.md
CHANGED
|
@@ -18,18 +18,11 @@ Harper is an open-source Node.js unified development platform that fuses databas
|
|
|
18
18
|
|
|
19
19
|
---
|
|
20
20
|
|
|
21
|
-
##
|
|
21
|
+
## Quick Installation
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
2. [Create Your First App](https://docs.harperdb.io/docs/getting-started/quickstart)
|
|
23
|
+
`npm i -g harper`
|
|
25
24
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
This repository represents Harper's future direction as an open-source-first platform. The code here is under active development and targets the upcoming **Harper v5** release. If you're looking for production-ready Harper, please refer to **Harper v4** — our current closed-source release documented at https://docs.harper.fast . We're rebuilding Harper from the ground up with an open source core and modular source-available plugins. This code is not yet published or production-ready, but we're excited to build the next generation of Harper in the open. Follow along, provide feedback, and watch as we shape the future of the platform together.
|
|
29
|
-
|
|
30
|
-
## What is HarperDB?
|
|
31
|
-
|
|
32
|
-
HarperDB is our previous name. Earlier in 2025, [we rebranded](https://www.harper.fast/announcements/harperdb-proclaims-new-era-for-web-performance-with-corporate-rebrand) to just "Harper" to reflect our evolution from a database to a full performance platform. The core technology remains the same, but we've expanded our vision to encompass more than just database functionality. Since this repo was created from the existing Harper codebase, you may still see references to the old name "HarperDB" in certain places.
|
|
25
|
+
Get started building Harper applications by following our Learn guide: https://docs.harperdb.io/learn
|
|
33
26
|
|
|
34
27
|
## Contributing to Harper
|
|
35
28
|
|
|
@@ -43,6 +36,14 @@ For more information on how to contribute, please see our:
|
|
|
43
36
|
- [Code of Conduct](./CODE_OF_CONDUCT.md)
|
|
44
37
|
- [Support](./SUPPORT.md)
|
|
45
38
|
|
|
39
|
+
## Harper Pro
|
|
40
|
+
|
|
41
|
+
[Harper Pro](https://github.com/harperfast/harper-pro) is the source-available distribution of Harper, built on top of this open source `harper` core. It extends the core with enterprise features including multi-node replication, certificate management, and extended profiling and analytics. It is licensed under the [Elastic License 2.0](https://www.elastic.co/licensing/elastic-license).
|
|
42
|
+
|
|
43
|
+
## What is HarperDB?
|
|
44
|
+
|
|
45
|
+
HarperDB is our previous name. Earlier in 2025, [we rebranded](https://www.harper.fast/announcements/harperdb-proclaims-new-era-for-web-performance-with-corporate-rebrand) to just "Harper" to reflect our evolution from a database to a full performance platform. The core technology remains the same, but we've expanded our vision to encompass more than just database functionality. Since this repo was created from the existing Harper codebase, you may still see references to the old name "HarperDB" in certain places.
|
|
46
|
+
|
|
46
47
|
## Security
|
|
47
48
|
|
|
48
49
|
Please review our [Security Policy](./SECURITY.md) for reporting vulnerabilities.
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in Harper Agent component (#626).
|
|
3
|
+
*
|
|
4
|
+
* `startOnMainThread` is invoked once on the main thread by `componentLoader`.
|
|
5
|
+
* When `agent.enabled` is `false` (default) the component registers nothing
|
|
6
|
+
* and returns immediately — opt-in keeps surprise LLM costs at bay. When
|
|
7
|
+
* enabled, the six operations land on the operations API, the session table
|
|
8
|
+
* is realized lazily on first use, and the loop runs in-process.
|
|
9
|
+
*
|
|
10
|
+
* The component intentionally avoids `handleApplication`: it has nothing
|
|
11
|
+
* worker-thread-shaped to do. Operator-only tools (FS, schedule, fetch) are
|
|
12
|
+
* inline; registry-backed tools (#615/#617/#618) will fold in via toolset.ts
|
|
13
|
+
* once those land.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { dirname, isAbsolute, resolve as resolvePath } from 'node:path';
|
|
17
|
+
import { CONFIG_PARAMS } from '../utility/hdbTerms.ts';
|
|
18
|
+
import harperLogger from '../utility/logging/harper_logger.ts';
|
|
19
|
+
import { Models } from '../resources/models/Models.ts';
|
|
20
|
+
import { composeToolset } from './toolset.ts';
|
|
21
|
+
import { buildOperations } from './operations.ts';
|
|
22
|
+
import { runAgent, _resetInFlightForTests } from './loop.ts';
|
|
23
|
+
import { appendMessage, getSession } from './session.ts';
|
|
24
|
+
import type { AgentConfig, AgentScopes, AgentTool } from './types.ts';
|
|
25
|
+
|
|
26
|
+
const log = harperLogger.loggerWithTag('agent');
|
|
27
|
+
|
|
28
|
+
const DEFAULT_CONFIG: AgentConfig = {
|
|
29
|
+
enabled: false,
|
|
30
|
+
maxTurns: 50,
|
|
31
|
+
maxCostUsd: 5,
|
|
32
|
+
autoApprove: false,
|
|
33
|
+
allowDestructive: false,
|
|
34
|
+
user: 'hdb_agent',
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
interface StartOpts {
|
|
38
|
+
server: {
|
|
39
|
+
registerOperation: (def: { name: string; execute: (op: any) => any | Promise<any> }) => void;
|
|
40
|
+
};
|
|
41
|
+
// Component-level config plumbed by componentLoader (`...componentConfig`).
|
|
42
|
+
enabled?: boolean;
|
|
43
|
+
provider?: string;
|
|
44
|
+
model?: string;
|
|
45
|
+
maxTurns?: number;
|
|
46
|
+
maxCostUsd?: number;
|
|
47
|
+
autoApprove?: boolean;
|
|
48
|
+
allowDestructive?: boolean;
|
|
49
|
+
user?: string;
|
|
50
|
+
componentsScope?: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export async function startOnMainThread(opts: StartOpts): Promise<void> {
|
|
54
|
+
const config = mergeConfig(opts);
|
|
55
|
+
if (!config.enabled) {
|
|
56
|
+
log.info?.('Agent component disabled (agent.enabled=false); skipping registration');
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Lazily required to avoid pulling configUtils at module-eval time for tests.
|
|
61
|
+
const { getConfigPath, getConfigFilePath } = require('../config/configUtils.js');
|
|
62
|
+
const scopes = resolveScopes(config, getConfigPath, getConfigFilePath);
|
|
63
|
+
|
|
64
|
+
const models = new Models();
|
|
65
|
+
const abortControllers = new Map<string, AbortController>();
|
|
66
|
+
let liveConfig: AgentConfig = config;
|
|
67
|
+
let composed = composeToolset({
|
|
68
|
+
allowDestructive: liveConfig.allowDestructive,
|
|
69
|
+
onFollowup: handleFollowup,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// Only warn when the operator explicitly configured `maxCostUsd`. Logging on the default
|
|
73
|
+
// every boot would flood the log without telling anyone anything actionable.
|
|
74
|
+
if (opts.maxCostUsd !== undefined) {
|
|
75
|
+
log.warn?.(
|
|
76
|
+
`agent.maxCostUsd=${liveConfig.maxCostUsd} is advertised but not yet enforced; cost-cap wiring depends on #612 telemetry.`
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async function handleFollowup(sessionId: string, prompt: string): Promise<void> {
|
|
81
|
+
const session = await getSession(sessionId);
|
|
82
|
+
if (!session) {
|
|
83
|
+
log.warn?.(`schedule_followup target session ${sessionId} not found`);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
await appendMessage(sessionId, { role: 'user', content: prompt, createdAt: Date.now() });
|
|
87
|
+
startRun(sessionId);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function currentTools(): AgentTool[] {
|
|
91
|
+
return composed.tools;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function startRun(sessionId: string): void {
|
|
95
|
+
// A run is already active for this session. `runAgent` coalesces concurrent starts onto the
|
|
96
|
+
// existing in-flight promise (bound to the existing controller), so creating a second
|
|
97
|
+
// controller here would orphan it — `cancelRun` would then abort a controller nothing is
|
|
98
|
+
// listening to, leaving the live run uncancellable. Any message appended before this call
|
|
99
|
+
// (e.g. by a scheduled followup) is picked up by the in-flight loop on its next turn.
|
|
100
|
+
if (abortControllers.has(sessionId)) return;
|
|
101
|
+
const controller = new AbortController();
|
|
102
|
+
abortControllers.set(sessionId, controller);
|
|
103
|
+
runAgent({
|
|
104
|
+
sessionId,
|
|
105
|
+
models,
|
|
106
|
+
tools: currentTools(),
|
|
107
|
+
scopes,
|
|
108
|
+
maxTurns: liveConfig.maxTurns,
|
|
109
|
+
autoApprove: liveConfig.autoApprove,
|
|
110
|
+
signal: controller.signal,
|
|
111
|
+
generateOpts: { model: liveConfig.model },
|
|
112
|
+
})
|
|
113
|
+
.catch((err) => log.error?.(`Agent run failed for ${sessionId}: ${(err as Error)?.message ?? err}`))
|
|
114
|
+
.finally(() => {
|
|
115
|
+
if (abortControllers.get(sessionId) === controller) abortControllers.delete(sessionId);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function cancelRun(sessionId: string): boolean {
|
|
120
|
+
// Clear any scheduled followups first. Without this, a timer set via `schedule_followup`
|
|
121
|
+
// would fire after the operator cancelled, silently re-injecting a user prompt and kicking
|
|
122
|
+
// the loop off again — surprising behavior and avoidable LLM cost.
|
|
123
|
+
for (const [id, followup] of composed.scheduled.entries()) {
|
|
124
|
+
if (followup.sessionId === sessionId) {
|
|
125
|
+
clearTimeout(followup.timer);
|
|
126
|
+
composed.scheduled.delete(id);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
const controller = abortControllers.get(sessionId);
|
|
130
|
+
if (!controller) return false;
|
|
131
|
+
controller.abort(new Error('cancelled by operator'));
|
|
132
|
+
abortControllers.delete(sessionId);
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function setConfig(patch: Partial<AgentConfig>): AgentConfig {
|
|
137
|
+
const previousAllowDestructive = liveConfig.allowDestructive;
|
|
138
|
+
liveConfig = { ...liveConfig, ...patch };
|
|
139
|
+
if (liveConfig.allowDestructive !== previousAllowDestructive) {
|
|
140
|
+
composed = composeToolset({
|
|
141
|
+
allowDestructive: liveConfig.allowDestructive,
|
|
142
|
+
onFollowup: handleFollowup,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
// NOTE: an already in-flight run captured its toolset (and autoApprove) at start, so flipping
|
|
146
|
+
// allowDestructive here only affects subsequent runs — the live loop finishes on its existing
|
|
147
|
+
// toolset. Acceptable: the approval gate still applies on the next turn's run, and operators
|
|
148
|
+
// who need to halt a run immediately use cancel_agent_run. Tightening to per-turn re-evaluation
|
|
149
|
+
// would require threading a config getter into the loop; deferred until there's a need.
|
|
150
|
+
return liveConfig;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const operations = buildOperations({
|
|
154
|
+
getConfig: () => liveConfig,
|
|
155
|
+
setConfig,
|
|
156
|
+
startRun,
|
|
157
|
+
cancelRun,
|
|
158
|
+
});
|
|
159
|
+
for (const op of operations) opts.server.registerOperation(op);
|
|
160
|
+
|
|
161
|
+
log.info?.(`Agent component initialized with ${composed.tools.length} tools`);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function resolveScopes(
|
|
165
|
+
config: AgentConfig,
|
|
166
|
+
getConfigPath: (param: string) => string | undefined,
|
|
167
|
+
getConfigFilePath?: () => string
|
|
168
|
+
): AgentScopes {
|
|
169
|
+
const componentsRoot = getConfigPath(CONFIG_PARAMS.COMPONENTSROOT) ?? process.cwd();
|
|
170
|
+
const logDir = getConfigPath(CONFIG_PARAMS.LOGGING_ROOT) ?? process.cwd();
|
|
171
|
+
const rootPath = getConfigPath(CONFIG_PARAMS.ROOTPATH) ?? componentsRoot;
|
|
172
|
+
const configFile = getConfigFilePath?.();
|
|
173
|
+
const configDir = configFile ? dirname(configFile) : process.cwd();
|
|
174
|
+
// A relative `componentsScope` is resolved against rootPath, as documented in the schema —
|
|
175
|
+
// NOT against componentsRoot, which would double-nest (`./components` → componentsRoot/components).
|
|
176
|
+
// With no scope set, the full componentsRoot is the FS write scope.
|
|
177
|
+
const scopedComponents = config.componentsScope
|
|
178
|
+
? isAbsolute(config.componentsScope)
|
|
179
|
+
? config.componentsScope
|
|
180
|
+
: resolvePath(rootPath, config.componentsScope)
|
|
181
|
+
: componentsRoot;
|
|
182
|
+
return { componentsRoot: scopedComponents, logDir, configDir };
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function mergeConfig(opts: StartOpts): AgentConfig {
|
|
186
|
+
return {
|
|
187
|
+
...DEFAULT_CONFIG,
|
|
188
|
+
...(opts.enabled !== undefined && { enabled: !!opts.enabled }),
|
|
189
|
+
...(opts.provider !== undefined && { provider: String(opts.provider) }),
|
|
190
|
+
...(opts.model !== undefined && { model: String(opts.model) }),
|
|
191
|
+
...(opts.maxTurns !== undefined && { maxTurns: Number(opts.maxTurns) }),
|
|
192
|
+
...(opts.maxCostUsd !== undefined && { maxCostUsd: Number(opts.maxCostUsd) }),
|
|
193
|
+
...(opts.autoApprove !== undefined && { autoApprove: !!opts.autoApprove }),
|
|
194
|
+
...(opts.allowDestructive !== undefined && { allowDestructive: !!opts.allowDestructive }),
|
|
195
|
+
...(opts.user !== undefined && { user: String(opts.user) }),
|
|
196
|
+
...(opts.componentsScope !== undefined && { componentsScope: String(opts.componentsScope) }),
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** Test-only: reset module state between specs. */
|
|
201
|
+
export function _resetForTests(): void {
|
|
202
|
+
_resetInFlightForTests();
|
|
203
|
+
}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manual agent loop for the built-in agent (#626).
|
|
3
|
+
*
|
|
4
|
+
* Wraps `scope.models.generate({ ..., toolMode: 'return' })` and dispatches
|
|
5
|
+
* any tool calls the model returns. This is a temporary stand-in for the
|
|
6
|
+
* unified `toolMode: 'auto'` orchestrator landing in #612 — when that ships,
|
|
7
|
+
* tool-call dispatch and the per-turn loop collapse into a single
|
|
8
|
+
* `generate({ ..., toolMode: 'auto' })` call. The approval/abort gates here
|
|
9
|
+
* still live in the component (the orchestrator won't know about
|
|
10
|
+
* `destructive` or operator approval semantics).
|
|
11
|
+
*
|
|
12
|
+
* Per-session serialization (one concurrent run per session) is handled
|
|
13
|
+
* here via {@link runAgent}'s in-flight map. Multiple sessions interleave
|
|
14
|
+
* on the event loop naturally because each turn is mostly awaiting the LLM
|
|
15
|
+
* or a tool's I/O.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import type { GenerateOpts, GenerateResult, Message, Models, ToolCall, ToolDef } from '../resources/models/types.ts';
|
|
19
|
+
import { addPendingApproval, appendMessage, getSession, markApprovalConsumed, setStatus } from './session.ts';
|
|
20
|
+
import type { AgentMessage, AgentScopes, AgentTool, AgentToolContext } from './types.ts';
|
|
21
|
+
import { toolMapByName } from './toolset.ts';
|
|
22
|
+
|
|
23
|
+
export interface RunAgentOpts {
|
|
24
|
+
sessionId: string;
|
|
25
|
+
models: Pick<Models, 'generate'>;
|
|
26
|
+
tools: AgentTool[];
|
|
27
|
+
scopes: AgentScopes;
|
|
28
|
+
maxTurns: number;
|
|
29
|
+
/** When false, destructive tools pause the loop with a pending approval instead of executing. */
|
|
30
|
+
autoApprove?: boolean;
|
|
31
|
+
signal?: AbortSignal;
|
|
32
|
+
generateOpts?: Omit<GenerateOpts, 'toolMode' | 'signal'>;
|
|
33
|
+
/** System prompt injected as the first turn when the transcript is empty. */
|
|
34
|
+
systemPrompt?: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const inFlight = new Map<string, Promise<void>>();
|
|
38
|
+
|
|
39
|
+
export function runAgent(opts: RunAgentOpts): Promise<void> {
|
|
40
|
+
const existing = inFlight.get(opts.sessionId);
|
|
41
|
+
if (existing) return existing;
|
|
42
|
+
const run = doRun(opts).finally(() => {
|
|
43
|
+
if (inFlight.get(opts.sessionId) === run) inFlight.delete(opts.sessionId);
|
|
44
|
+
});
|
|
45
|
+
inFlight.set(opts.sessionId, run);
|
|
46
|
+
return run;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function doRun(opts: RunAgentOpts): Promise<void> {
|
|
50
|
+
const toolMap = toolMapByName(opts.tools);
|
|
51
|
+
const toolDefs: ToolDef[] = opts.tools.map((t) => t.def);
|
|
52
|
+
await setStatus(opts.sessionId, 'running');
|
|
53
|
+
const ctx: AgentToolContext = { sessionId: opts.sessionId, signal: opts.signal, scopes: opts.scopes };
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
// First, drain any resolved-but-unconsumed approvals from a prior pause. Either execute
|
|
57
|
+
// or refuse each saved call, recording an observation, so the next model turn sees the
|
|
58
|
+
// result of the operator decision.
|
|
59
|
+
await consumeResolvedApprovals(opts.sessionId, toolMap, ctx);
|
|
60
|
+
|
|
61
|
+
// If a turn produced multiple gated tool calls and the operator has only resolved some of
|
|
62
|
+
// them, the remaining approvals are still pending — meaning the assistant's tool_calls do
|
|
63
|
+
// not yet all have tool responses. Re-entering the generate loop now would send an
|
|
64
|
+
// incomplete tool-response set and the provider would 400. Stay paused until every gated
|
|
65
|
+
// call for this turn is resolved (each `approve_agent_action` re-runs this path).
|
|
66
|
+
const afterConsume = await getSession(opts.sessionId);
|
|
67
|
+
if (afterConsume?.pendingApprovals.some((a) => !a.resolved)) {
|
|
68
|
+
await setStatus(opts.sessionId, 'awaiting_approval');
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
for (let turn = 0; turn < opts.maxTurns; turn++) {
|
|
73
|
+
if (opts.signal?.aborted) return; // status was already set to `aborted` by cancelRun
|
|
74
|
+
const session = await getSession(opts.sessionId);
|
|
75
|
+
if (!session) throw new Error(`Session ${opts.sessionId} vanished mid-run`);
|
|
76
|
+
const messages = toModelMessages(session.messages, opts.systemPrompt);
|
|
77
|
+
const result: GenerateResult = await opts.models.generate(
|
|
78
|
+
{ messages, tools: toolDefs, system: opts.systemPrompt },
|
|
79
|
+
{ ...opts.generateOpts, toolMode: 'return', signal: opts.signal }
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
await appendMessage(opts.sessionId, {
|
|
83
|
+
role: 'assistant',
|
|
84
|
+
content: result.content ?? '',
|
|
85
|
+
toolCalls: result.toolCalls,
|
|
86
|
+
createdAt: Date.now(),
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
if (!result.toolCalls || result.toolCalls.length === 0) {
|
|
90
|
+
await setStatus(opts.sessionId, 'completed');
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const paused = await dispatchToolCalls(result.toolCalls, toolMap, ctx, opts);
|
|
95
|
+
if (paused || opts.signal?.aborted) return;
|
|
96
|
+
}
|
|
97
|
+
await setStatus(opts.sessionId, 'completed', `Reached maxTurns=${opts.maxTurns} without a final answer.`);
|
|
98
|
+
} catch (err) {
|
|
99
|
+
// If the abort signal fired, the cancel path already set the session to `aborted` —
|
|
100
|
+
// don't clobber that with `error`. The rejection here is just the awaited generate/tool
|
|
101
|
+
// honoring the signal, not a real failure.
|
|
102
|
+
if (opts.signal?.aborted) return;
|
|
103
|
+
await setStatus(opts.sessionId, 'error', err instanceof Error ? err.message : String(err));
|
|
104
|
+
throw err;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Returns `true` when the loop should pause (any destructive tool call required approval).
|
|
110
|
+
* Non-destructive calls execute inline and their observations are appended. Destructive calls
|
|
111
|
+
* register pending approvals but do NOT append a tool message — `consumeResolvedApprovals`
|
|
112
|
+
* writes the single tool response on the next run. This keeps the 1:1 mapping between
|
|
113
|
+
* assistant tool_calls and tool responses that LLM APIs enforce, including when the assistant
|
|
114
|
+
* message mixes destructive and non-destructive calls in the same turn.
|
|
115
|
+
*/
|
|
116
|
+
async function dispatchToolCalls(
|
|
117
|
+
calls: ToolCall[],
|
|
118
|
+
toolMap: Map<string, AgentTool>,
|
|
119
|
+
ctx: AgentToolContext,
|
|
120
|
+
opts: RunAgentOpts
|
|
121
|
+
): Promise<boolean> {
|
|
122
|
+
let needsApproval = false;
|
|
123
|
+
for (const call of calls) {
|
|
124
|
+
if (opts.signal?.aborted) return true;
|
|
125
|
+
const tool = toolMap.get(call.name);
|
|
126
|
+
const destructiveAndGated = tool?.destructive && !opts.autoApprove;
|
|
127
|
+
if (destructiveAndGated) {
|
|
128
|
+
await addPendingApproval(opts.sessionId, {
|
|
129
|
+
toolName: call.name,
|
|
130
|
+
arguments: call.arguments ?? {},
|
|
131
|
+
toolCallId: call.id,
|
|
132
|
+
reason: 'destructive',
|
|
133
|
+
});
|
|
134
|
+
needsApproval = true;
|
|
135
|
+
// Don't break — keep processing remaining calls so non-destructive ones in the same
|
|
136
|
+
// turn still execute and write their tool responses. Their results may be useful
|
|
137
|
+
// context for the operator deciding whether to approve.
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
const observation = await invokeTool(call, toolMap, ctx);
|
|
141
|
+
await appendMessage(opts.sessionId, {
|
|
142
|
+
role: 'tool',
|
|
143
|
+
content: observation,
|
|
144
|
+
toolCallId: call.id,
|
|
145
|
+
createdAt: Date.now(),
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
return needsApproval;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
async function consumeResolvedApprovals(
|
|
152
|
+
sessionId: string,
|
|
153
|
+
toolMap: Map<string, AgentTool>,
|
|
154
|
+
ctx: AgentToolContext
|
|
155
|
+
): Promise<void> {
|
|
156
|
+
const session = await getSession(sessionId);
|
|
157
|
+
if (!session) return;
|
|
158
|
+
const toConsume = session.pendingApprovals.filter((a) => a.resolved && !a.consumed);
|
|
159
|
+
for (const approval of toConsume) {
|
|
160
|
+
const observation = approval.approved
|
|
161
|
+
? await invokeTool(
|
|
162
|
+
{ id: approval.toolCallId, name: approval.toolName, arguments: approval.arguments },
|
|
163
|
+
toolMap,
|
|
164
|
+
ctx
|
|
165
|
+
)
|
|
166
|
+
: JSON.stringify({ ok: false, error: 'denied_by_operator', tool: approval.toolName });
|
|
167
|
+
await appendMessage(sessionId, {
|
|
168
|
+
role: 'tool',
|
|
169
|
+
content: observation,
|
|
170
|
+
toolCallId: approval.toolCallId,
|
|
171
|
+
createdAt: Date.now(),
|
|
172
|
+
});
|
|
173
|
+
await markApprovalConsumed(sessionId, approval.id);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
async function invokeTool(call: ToolCall, toolMap: Map<string, AgentTool>, ctx: AgentToolContext): Promise<string> {
|
|
178
|
+
const tool = toolMap.get(call.name);
|
|
179
|
+
if (!tool) return JSON.stringify({ error: 'unknown_tool', name: call.name });
|
|
180
|
+
try {
|
|
181
|
+
const result = await tool.handler(call.arguments ?? {}, ctx);
|
|
182
|
+
return JSON.stringify({ ok: true, result });
|
|
183
|
+
} catch (err) {
|
|
184
|
+
return JSON.stringify({ ok: false, error: err instanceof Error ? err.message : String(err) });
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function toModelMessages(items: AgentMessage[], systemPrompt: string | undefined): Message[] {
|
|
189
|
+
const out: Message[] = [];
|
|
190
|
+
if (systemPrompt && !items.some((m) => m.role === 'system')) {
|
|
191
|
+
out.push({ role: 'system', content: systemPrompt });
|
|
192
|
+
}
|
|
193
|
+
for (const item of items) {
|
|
194
|
+
const message: Message = { role: item.role, content: item.content };
|
|
195
|
+
if (item.toolCalls) message.toolCalls = item.toolCalls;
|
|
196
|
+
if (item.toolCallId) message.toolCallId = item.toolCallId;
|
|
197
|
+
out.push(message);
|
|
198
|
+
}
|
|
199
|
+
return out;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** Test-only: clear the in-flight tracking map. */
|
|
203
|
+
export function _resetInFlightForTests(): void {
|
|
204
|
+
inFlight.clear();
|
|
205
|
+
}
|