@harperfast/harper 5.0.30 → 5.1.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -10
- package/agent/agent.ts +203 -0
- package/agent/loop.ts +205 -0
- package/agent/operations.ts +148 -0
- package/agent/session.ts +187 -0
- package/agent/tools/fsTools.ts +276 -0
- package/agent/tools/httpFetchTool.ts +112 -0
- package/agent/tools/scheduleTool.ts +68 -0
- package/agent/toolset.ts +43 -0
- package/agent/types.ts +85 -0
- package/bin/{BinObjects.js → BinObjects.ts} +4 -5
- package/bin/cliCredentials.ts +133 -0
- package/bin/cliOperations.ts +339 -0
- package/bin/copyDb.ts +10 -10
- package/bin/deployRenderer.ts +196 -0
- package/bin/{harper.js → harper.ts} +43 -19
- package/bin/{install.js → install.ts} +3 -3
- package/bin/lite.ts +2 -0
- package/bin/login.ts +134 -0
- package/bin/logout.ts +11 -0
- package/bin/mcp/client.ts +407 -0
- package/bin/mcp/doctor.ts +189 -0
- package/bin/mcp/index.ts +80 -0
- package/bin/mcp/options.ts +122 -0
- package/bin/mcp/printConfig.ts +89 -0
- package/bin/multipartBuilder.ts +74 -0
- package/bin/{restart.js → restart.ts} +27 -28
- package/bin/{run.js → run.ts} +41 -30
- package/bin/sseConsumer.ts +126 -0
- package/bin/{status.js → status.ts} +10 -10
- package/bin/{stop.js → stop.ts} +5 -5
- package/bin/upgrade.js +17 -24
- package/components/Application.ts +144 -18
- package/components/ApplicationScope.ts +2 -2
- package/components/ComponentV1.ts +2 -2
- package/components/EntryHandler.ts +159 -9
- package/components/OptionsWatcher.ts +75 -11
- package/components/Scope.ts +132 -18
- package/components/anthropic/index.ts +547 -0
- package/components/bedrock/index.ts +823 -0
- package/components/componentLoader.ts +64 -32
- package/components/deployLifecycle.ts +161 -0
- package/components/deploymentOperations.ts +173 -0
- package/components/deploymentRecorder.ts +427 -0
- package/components/deriveURLPath.ts +4 -4
- package/components/mcp/adapters/fastify.ts +87 -0
- package/components/mcp/adapters/harperHttp.ts +103 -0
- package/components/mcp/audit.ts +75 -0
- package/components/mcp/index.ts +134 -0
- package/components/mcp/jsonrpc.ts +134 -0
- package/components/mcp/lifecycle.ts +105 -0
- package/components/mcp/listChanged.ts +270 -0
- package/components/mcp/rateLimit.ts +217 -0
- package/components/mcp/resources.ts +607 -0
- package/components/mcp/session.ts +151 -0
- package/components/mcp/sessionRegistry.ts +140 -0
- package/components/mcp/toolRegistry.ts +294 -0
- package/components/mcp/tools/application.ts +761 -0
- package/components/mcp/tools/operations.ts +311 -0
- package/components/mcp/tools/schemas/derive.ts +356 -0
- package/components/mcp/tools/schemas/operationDescriptions.ts +241 -0
- package/components/mcp/tools/schemas/operations.ts +301 -0
- package/components/mcp/transport.ts +517 -0
- package/components/ollama/index.ts +316 -0
- package/components/openai/index.ts +563 -0
- package/components/operations.js +217 -60
- package/components/operationsValidation.js +12 -4
- package/components/packageComponent.ts +97 -29
- package/components/requestRestart.ts +17 -2
- package/components/status/crossThread.ts +14 -5
- package/components/status/errors.ts +1 -1
- package/config/RootConfigWatcher.ts +56 -2
- package/config/configUtils.js +29 -8
- package/config/harperConfigEnvVars.ts +1 -1
- package/config-root.schema.json +78 -4
- package/dataLayer/{CreateAttributeObject.js → CreateAttributeObject.ts} +4 -3
- package/dataLayer/{CreateTableObject.js → CreateTableObject.ts} +2 -1
- package/dataLayer/{DataLayerObjects.js → DataLayerObjects.ts} +17 -9
- package/dataLayer/{DeleteBeforeObject.js → DeleteBeforeObject.ts} +2 -1
- package/dataLayer/{DeleteObject.js → DeleteObject.ts} +3 -2
- package/dataLayer/{DropAttributeObject.js → DropAttributeObject.ts} +2 -1
- package/dataLayer/{GetBackupObject.js → GetBackupObject.ts} +3 -2
- package/dataLayer/{InsertObject.js → InsertObject.ts} +3 -2
- package/dataLayer/{ReadAuditLogObject.js → ReadAuditLogObject.ts} +3 -2
- package/dataLayer/{SQLSearch.js → SQLSearch.ts} +97 -43
- package/dataLayer/{SearchByConditionsObject.js → SearchByConditionsObject.ts} +5 -6
- package/dataLayer/{SearchByHashObject.js → SearchByHashObject.ts} +2 -1
- package/dataLayer/{SearchObject.js → SearchObject.ts} +2 -1
- package/dataLayer/{SqlSearchObject.js → SqlSearchObject.ts} +2 -1
- package/dataLayer/{UpdateObject.js → UpdateObject.ts} +3 -2
- package/dataLayer/{UpsertObject.js → UpsertObject.ts} +3 -2
- package/dataLayer/{bulkLoad.js → bulkLoad.ts} +40 -49
- package/dataLayer/{delete.js → delete.ts} +21 -26
- package/dataLayer/{export.js → export.ts} +22 -26
- package/dataLayer/{getBackup.js → getBackup.ts} +7 -9
- package/dataLayer/harperBridge/BridgeMethods.ts +102 -0
- package/dataLayer/harperBridge/ResourceBridge.ts +27 -26
- package/dataLayer/harperBridge/TableSizeObject.ts +1 -0
- package/dataLayer/harperBridge/bridgeUtility/insertUpdateValidate.js +4 -4
- package/dataLayer/harperBridge/{harperBridge.js → harperBridge.ts} +3 -3
- package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateAttribute.js +8 -6
- package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateRecords.js +4 -4
- package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateSchema.js +1 -1
- package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateTable.js +6 -4
- package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDeleteAuditLogsBefore.js +5 -4
- package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDeleteRecords.js +4 -4
- package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDropAttribute.js +6 -5
- package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDropSchema.js +5 -4
- package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDropTable.js +5 -5
- package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbFlush.js +1 -1
- package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbGetBackup.js +3 -3
- package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbGetDataByHash.js +1 -1
- package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbGetDataByValue.js +3 -2
- package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbReadAuditLog.js +5 -5
- package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbSearchByConditions.js +10 -8
- package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbSearchByHash.js +1 -1
- package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbSearchByValue.js +4 -3
- package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbUpdateRecords.js +3 -3
- package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbUpsertRecords.js +6 -5
- package/dataLayer/harperBridge/lmdbBridge/lmdbUtility/LMDBCreateAttributeObject.js +2 -1
- package/dataLayer/harperBridge/lmdbBridge/lmdbUtility/initializeHashSearch.js +3 -2
- package/dataLayer/harperBridge/lmdbBridge/lmdbUtility/initializePaths.js +2 -2
- package/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbCheckForNewAttributes.js +5 -4
- package/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbCreateTransactionsAuditEnvironment.js +6 -3
- package/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbGetTableSize.ts +1 -1
- package/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbProcessRows.js +4 -4
- package/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbSearch.js +5 -5
- package/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbWriteTransaction.js +4 -4
- package/dataLayer/{hdbInfoController.js → hdbInfoController.ts} +20 -26
- package/dataLayer/{insert.js → insert.ts} +24 -24
- package/dataLayer/{readAuditLog.js → readAuditLog.ts} +8 -10
- package/dataLayer/{schema.js → schema.ts} +32 -44
- package/dataLayer/{schemaDescribe.js → schemaDescribe.ts} +23 -26
- package/dataLayer/{search.js → search.ts} +9 -15
- package/dataLayer/{transaction.js → transaction.ts} +2 -5
- package/dataLayer/{update.js → update.ts} +19 -22
- package/dist/agent/agent.d.ts +35 -0
- package/dist/agent/agent.js +175 -0
- package/dist/agent/agent.js.map +1 -0
- package/dist/agent/loop.d.ts +34 -0
- package/dist/agent/loop.js +176 -0
- package/dist/agent/loop.js.map +1 -0
- package/dist/agent/operations.d.ts +17 -0
- package/dist/agent/operations.js +137 -0
- package/dist/agent/operations.js.map +1 -0
- package/dist/agent/session.d.ts +36 -0
- package/dist/agent/session.js +182 -0
- package/dist/agent/session.js.map +1 -0
- package/dist/agent/tools/fsTools.d.ts +19 -0
- package/dist/agent/tools/fsTools.js +286 -0
- package/dist/agent/tools/fsTools.js.map +1 -0
- package/dist/agent/tools/httpFetchTool.d.ts +9 -0
- package/dist/agent/tools/httpFetchTool.js +116 -0
- package/dist/agent/tools/httpFetchTool.js.map +1 -0
- package/dist/agent/tools/scheduleTool.d.ts +22 -0
- package/dist/agent/tools/scheduleTool.js +54 -0
- package/dist/agent/tools/scheduleTool.js.map +1 -0
- package/dist/agent/toolset.d.ts +24 -0
- package/dist/agent/toolset.js +33 -0
- package/dist/agent/toolset.js.map +1 -0
- package/dist/agent/types.d.ts +75 -0
- package/dist/agent/types.js +10 -0
- package/dist/agent/types.js.map +1 -0
- package/dist/bin/BinObjects.d.ts +2 -2
- package/dist/bin/BinObjects.js +6 -3
- package/dist/bin/BinObjects.js.map +1 -1
- package/dist/bin/cliCredentials.d.ts +27 -0
- package/dist/bin/cliCredentials.js +130 -0
- package/dist/bin/cliCredentials.js.map +1 -0
- package/dist/bin/cliOperations.d.ts +7 -7
- package/dist/bin/cliOperations.js +251 -37
- package/dist/bin/cliOperations.js.map +1 -1
- package/dist/bin/copyDb.js +16 -16
- package/dist/bin/copyDb.js.map +1 -1
- package/dist/bin/deployRenderer.d.ts +47 -0
- package/dist/bin/deployRenderer.js +185 -0
- package/dist/bin/deployRenderer.js.map +1 -0
- package/dist/bin/harper.d.ts +2 -1
- package/dist/bin/harper.js +87 -26
- package/dist/bin/harper.js.map +1 -1
- package/dist/bin/install.d.ts +1 -1
- package/dist/bin/install.js +41 -4
- package/dist/bin/install.js.map +1 -1
- package/dist/bin/lite.js +3 -4
- package/dist/bin/lite.js.map +1 -1
- package/dist/bin/login.d.ts +4 -0
- package/dist/bin/login.js +123 -0
- package/dist/bin/login.js.map +1 -0
- package/dist/bin/logout.d.ts +4 -0
- package/dist/bin/logout.js +16 -0
- package/dist/bin/logout.js.map +1 -0
- package/dist/bin/mcp/client.d.ts +34 -0
- package/dist/bin/mcp/client.js +395 -0
- package/dist/bin/mcp/client.js.map +1 -0
- package/dist/bin/mcp/doctor.d.ts +11 -0
- package/dist/bin/mcp/doctor.js +193 -0
- package/dist/bin/mcp/doctor.js.map +1 -0
- package/dist/bin/mcp/index.d.ts +10 -0
- package/dist/bin/mcp/index.js +81 -0
- package/dist/bin/mcp/index.js.map +1 -0
- package/dist/bin/mcp/options.d.ts +33 -0
- package/dist/bin/mcp/options.js +113 -0
- package/dist/bin/mcp/options.js.map +1 -0
- package/dist/bin/mcp/printConfig.d.ts +14 -0
- package/dist/bin/mcp/printConfig.js +85 -0
- package/dist/bin/mcp/printConfig.js.map +1 -0
- package/dist/bin/multipartBuilder.d.ts +26 -0
- package/dist/bin/multipartBuilder.js +55 -0
- package/dist/bin/multipartBuilder.js.map +1 -0
- package/dist/bin/restart.d.ts +3 -2
- package/dist/bin/restart.js +82 -45
- package/dist/bin/restart.js.map +1 -1
- package/dist/bin/run.d.ts +13 -9
- package/dist/bin/run.js +111 -65
- package/dist/bin/run.js.map +1 -1
- package/dist/bin/sseConsumer.d.ts +24 -0
- package/dist/bin/sseConsumer.js +127 -0
- package/dist/bin/sseConsumer.js.map +1 -0
- package/dist/bin/status.d.ts +1 -1
- package/dist/bin/status.js +48 -11
- package/dist/bin/status.js.map +1 -1
- package/dist/bin/stop.d.ts +1 -1
- package/dist/bin/stop.js +43 -6
- package/dist/bin/stop.js.map +1 -1
- package/dist/bin/upgrade.js +14 -22
- package/dist/bin/upgrade.js.map +1 -1
- package/dist/components/Application.d.ts +29 -17
- package/dist/components/Application.js +134 -28
- package/dist/components/Application.js.map +1 -1
- package/dist/components/ApplicationScope.js +2 -2
- package/dist/components/ComponentV1.d.ts +1 -1
- package/dist/components/ComponentV1.js +5 -5
- package/dist/components/ComponentV1.js.map +1 -1
- package/dist/components/EntryHandler.d.ts +26 -3
- package/dist/components/EntryHandler.js +153 -13
- package/dist/components/EntryHandler.js.map +1 -1
- package/dist/components/OptionsWatcher.d.ts +7 -2
- package/dist/components/OptionsWatcher.js +72 -10
- package/dist/components/OptionsWatcher.js.map +1 -1
- package/dist/components/Scope.d.ts +11 -6
- package/dist/components/Scope.js +112 -12
- package/dist/components/Scope.js.map +1 -1
- package/dist/components/anthropic/index.d.ts +40 -0
- package/dist/components/anthropic/index.js +428 -0
- package/dist/components/anthropic/index.js.map +1 -0
- package/dist/components/bedrock/index.d.ts +79 -0
- package/dist/components/bedrock/index.js +734 -0
- package/dist/components/bedrock/index.js.map +1 -0
- package/dist/components/componentLoader.d.ts +29 -0
- package/dist/components/componentLoader.js +65 -38
- package/dist/components/componentLoader.js.map +1 -1
- package/dist/components/deployLifecycle.d.ts +39 -0
- package/dist/components/deployLifecycle.js +156 -0
- package/dist/components/deployLifecycle.js.map +1 -0
- package/dist/components/deploymentOperations.d.ts +19 -0
- package/dist/components/deploymentOperations.js +185 -0
- package/dist/components/deploymentOperations.js.map +1 -0
- package/dist/components/deploymentRecorder.d.ts +97 -0
- package/dist/components/deploymentRecorder.js +425 -0
- package/dist/components/deploymentRecorder.js.map +1 -0
- package/dist/components/deriveURLPath.d.ts +2 -2
- package/dist/components/deriveURLPath.js +2 -2
- package/dist/components/deriveURLPath.js.map +1 -1
- package/dist/components/mcp/adapters/fastify.d.ts +35 -0
- package/dist/components/mcp/adapters/fastify.js +66 -0
- package/dist/components/mcp/adapters/fastify.js.map +1 -0
- package/dist/components/mcp/adapters/harperHttp.d.ts +38 -0
- package/dist/components/mcp/adapters/harperHttp.js +78 -0
- package/dist/components/mcp/adapters/harperHttp.js.map +1 -0
- package/dist/components/mcp/audit.d.ts +27 -0
- package/dist/components/mcp/audit.js +73 -0
- package/dist/components/mcp/audit.js.map +1 -0
- package/dist/components/mcp/index.d.ts +47 -0
- package/dist/components/mcp/index.js +109 -0
- package/dist/components/mcp/index.js.map +1 -0
- package/dist/components/mcp/jsonrpc.d.ts +71 -0
- package/dist/components/mcp/jsonrpc.js +93 -0
- package/dist/components/mcp/jsonrpc.js.map +1 -0
- package/dist/components/mcp/lifecycle.d.ts +69 -0
- package/dist/components/mcp/lifecycle.js +79 -0
- package/dist/components/mcp/lifecycle.js.map +1 -0
- package/dist/components/mcp/listChanged.d.ts +24 -0
- package/dist/components/mcp/listChanged.js +257 -0
- package/dist/components/mcp/listChanged.js.map +1 -0
- package/dist/components/mcp/rateLimit.d.ts +25 -0
- package/dist/components/mcp/rateLimit.js +226 -0
- package/dist/components/mcp/rateLimit.js.map +1 -0
- package/dist/components/mcp/resources.d.ts +90 -0
- package/dist/components/mcp/resources.js +526 -0
- package/dist/components/mcp/resources.js.map +1 -0
- package/dist/components/mcp/session.d.ts +36 -0
- package/dist/components/mcp/session.js +170 -0
- package/dist/components/mcp/session.js.map +1 -0
- package/dist/components/mcp/sessionRegistry.d.ts +63 -0
- package/dist/components/mcp/sessionRegistry.js +124 -0
- package/dist/components/mcp/sessionRegistry.js.map +1 -0
- package/dist/components/mcp/toolRegistry.d.ts +151 -0
- package/dist/components/mcp/toolRegistry.js +177 -0
- package/dist/components/mcp/toolRegistry.js.map +1 -0
- package/dist/components/mcp/tools/application.d.ts +72 -0
- package/dist/components/mcp/tools/application.js +660 -0
- package/dist/components/mcp/tools/application.js.map +1 -0
- package/dist/components/mcp/tools/operations.d.ts +23 -0
- package/dist/components/mcp/tools/operations.js +331 -0
- package/dist/components/mcp/tools/operations.js.map +1 -0
- package/dist/components/mcp/tools/schemas/derive.d.ts +50 -0
- package/dist/components/mcp/tools/schemas/derive.js +291 -0
- package/dist/components/mcp/tools/schemas/derive.js.map +1 -0
- package/dist/components/mcp/tools/schemas/operationDescriptions.d.ts +32 -0
- package/dist/components/mcp/tools/schemas/operationDescriptions.js +179 -0
- package/dist/components/mcp/tools/schemas/operationDescriptions.js.map +1 -0
- package/dist/components/mcp/tools/schemas/operations.d.ts +27 -0
- package/dist/components/mcp/tools/schemas/operations.js +299 -0
- package/dist/components/mcp/tools/schemas/operations.js.map +1 -0
- package/dist/components/mcp/transport.d.ts +38 -0
- package/dist/components/mcp/transport.js +467 -0
- package/dist/components/mcp/transport.js.map +1 -0
- package/dist/components/ollama/index.d.ts +46 -0
- package/dist/components/ollama/index.js +239 -0
- package/dist/components/ollama/index.js.map +1 -0
- package/dist/components/openai/index.d.ts +51 -0
- package/dist/components/openai/index.js +475 -0
- package/dist/components/openai/index.js.map +1 -0
- package/dist/components/operations.d.ts +6 -6
- package/dist/components/operations.js +205 -52
- package/dist/components/operations.js.map +1 -1
- package/dist/components/operationsValidation.d.ts +2 -2
- package/dist/components/operationsValidation.js +13 -4
- package/dist/components/operationsValidation.js.map +1 -1
- package/dist/components/packageComponent.d.ts +28 -6
- package/dist/components/packageComponent.js +87 -26
- package/dist/components/packageComponent.js.map +1 -1
- package/dist/components/requestRestart.d.ts +1 -0
- package/dist/components/requestRestart.js +12 -1
- package/dist/components/requestRestart.js.map +1 -1
- package/dist/components/status/crossThread.d.ts +5 -1
- package/dist/components/status/crossThread.js +12 -5
- package/dist/components/status/crossThread.js.map +1 -1
- package/dist/components/status/errors.js +7 -7
- package/dist/config/RootConfigWatcher.d.ts +3 -0
- package/dist/config/RootConfigWatcher.js +52 -1
- package/dist/config/RootConfigWatcher.js.map +1 -1
- package/dist/config/configUtils.js +31 -8
- package/dist/config/configUtils.js.map +1 -1
- package/dist/config/harperConfigEnvVars.js +1 -1
- package/dist/config/harperConfigEnvVars.js.map +1 -1
- package/dist/dataLayer/CreateAttributeObject.d.ts +3 -7
- package/dist/dataLayer/CreateAttributeObject.js +4 -3
- package/dist/dataLayer/CreateAttributeObject.js.map +1 -1
- package/dist/dataLayer/CreateTableObject.d.ts +2 -4
- package/dist/dataLayer/CreateTableObject.js +2 -1
- package/dist/dataLayer/CreateTableObject.js.map +1 -1
- package/dist/dataLayer/DataLayerObjects.d.ts +17 -16
- package/dist/dataLayer/DataLayerObjects.js +19 -5
- package/dist/dataLayer/DataLayerObjects.js.map +1 -1
- package/dist/dataLayer/DeleteBeforeObject.d.ts +3 -5
- package/dist/dataLayer/DeleteBeforeObject.js +2 -1
- package/dist/dataLayer/DeleteBeforeObject.js.map +1 -1
- package/dist/dataLayer/DeleteObject.d.ts +3 -7
- package/dist/dataLayer/DeleteObject.js +4 -3
- package/dist/dataLayer/DeleteObject.js.map +1 -1
- package/dist/dataLayer/DropAttributeObject.d.ts +2 -4
- package/dist/dataLayer/DropAttributeObject.js +2 -1
- package/dist/dataLayer/DropAttributeObject.js.map +1 -1
- package/dist/dataLayer/GetBackupObject.d.ts +3 -5
- package/dist/dataLayer/GetBackupObject.js +4 -3
- package/dist/dataLayer/GetBackupObject.js.map +1 -1
- package/dist/dataLayer/InsertObject.d.ts +3 -8
- package/dist/dataLayer/InsertObject.js +4 -3
- package/dist/dataLayer/InsertObject.js.map +1 -1
- package/dist/dataLayer/ReadAuditLogObject.d.ts +3 -7
- package/dist/dataLayer/ReadAuditLogObject.js +4 -3
- package/dist/dataLayer/ReadAuditLogObject.js.map +1 -1
- package/dist/dataLayer/SQLSearch.d.ts +68 -38
- package/dist/dataLayer/SQLSearch.js +140 -78
- package/dist/dataLayer/SQLSearch.js.map +1 -1
- package/dist/dataLayer/SearchByConditionsObject.d.ts +10 -58
- package/dist/dataLayer/SearchByConditionsObject.js +5 -7
- package/dist/dataLayer/SearchByConditionsObject.js.map +1 -1
- package/dist/dataLayer/SearchByHashObject.d.ts +3 -6
- package/dist/dataLayer/SearchByHashObject.js +2 -1
- package/dist/dataLayer/SearchByHashObject.js.map +1 -1
- package/dist/dataLayer/SearchObject.d.ts +3 -12
- package/dist/dataLayer/SearchObject.js +2 -1
- package/dist/dataLayer/SearchObject.js.map +1 -1
- package/dist/dataLayer/SqlSearchObject.d.ts +2 -4
- package/dist/dataLayer/SqlSearchObject.js +2 -1
- package/dist/dataLayer/SqlSearchObject.js.map +1 -1
- package/dist/dataLayer/UpdateObject.d.ts +3 -7
- package/dist/dataLayer/UpdateObject.js +4 -3
- package/dist/dataLayer/UpdateObject.js.map +1 -1
- package/dist/dataLayer/UpsertObject.d.ts +3 -7
- package/dist/dataLayer/UpsertObject.js +4 -3
- package/dist/dataLayer/UpsertObject.js.map +1 -1
- package/dist/dataLayer/bulkLoad.d.ts +4 -4
- package/dist/dataLayer/bulkLoad.js +122 -88
- package/dist/dataLayer/bulkLoad.js.map +1 -1
- package/dist/dataLayer/delete.d.ts +10 -11
- package/dist/dataLayer/delete.js +74 -39
- package/dist/dataLayer/delete.js.map +1 -1
- package/dist/dataLayer/export.d.ts +8 -8
- package/dist/dataLayer/export.js +90 -55
- package/dist/dataLayer/export.js.map +1 -1
- package/dist/dataLayer/getBackup.d.ts +4 -3
- package/dist/dataLayer/getBackup.js +43 -11
- package/dist/dataLayer/getBackup.js.map +1 -1
- package/dist/dataLayer/harperBridge/BridgeMethods.d.ts +39 -21
- package/dist/dataLayer/harperBridge/BridgeMethods.js +41 -20
- package/dist/dataLayer/harperBridge/BridgeMethods.js.map +1 -1
- package/dist/dataLayer/harperBridge/ResourceBridge.d.ts +2 -2
- package/dist/dataLayer/harperBridge/ResourceBridge.js +26 -25
- package/dist/dataLayer/harperBridge/ResourceBridge.js.map +1 -1
- package/dist/dataLayer/harperBridge/TableSizeObject.d.ts +1 -0
- package/dist/dataLayer/harperBridge/TableSizeObject.js.map +1 -1
- package/dist/dataLayer/harperBridge/bridgeUtility/insertUpdateValidate.d.ts +4 -4
- package/dist/dataLayer/harperBridge/bridgeUtility/insertUpdateValidate.js +4 -4
- package/dist/dataLayer/harperBridge/harperBridge.d.ts +2 -3
- package/dist/dataLayer/harperBridge/harperBridge.js +38 -4
- package/dist/dataLayer/harperBridge/harperBridge.js.map +1 -1
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateAttribute.d.ts +1 -2
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateAttribute.js +7 -6
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateAttribute.js.map +1 -1
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateRecords.d.ts +1 -2
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateRecords.js +4 -4
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateRecords.js.map +1 -1
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateSchema.js +1 -1
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateSchema.js.map +1 -1
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateTable.js +5 -4
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateTable.js.map +1 -1
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDeleteAuditLogsBefore.d.ts +1 -2
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDeleteAuditLogsBefore.js +4 -4
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDeleteAuditLogsBefore.js.map +1 -1
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDeleteRecords.js +4 -4
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDropAttribute.d.ts +1 -2
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDropAttribute.js +5 -5
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDropAttribute.js.map +1 -1
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDropSchema.js +4 -4
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDropSchema.js.map +1 -1
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDropTable.js +5 -5
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDropTable.js.map +1 -1
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbFlush.js +1 -1
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbGetBackup.js +3 -3
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbGetDataByHash.js +1 -1
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbGetDataByValue.js +2 -2
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbGetDataByValue.js.map +1 -1
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbReadAuditLog.js +5 -5
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbSearchByConditions.d.ts +1 -2
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbSearchByConditions.js +8 -8
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbSearchByConditions.js.map +1 -1
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbSearchByHash.d.ts +1 -1
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbSearchByHash.js +1 -1
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbSearchByValue.d.ts +1 -2
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbSearchByValue.js +3 -3
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbSearchByValue.js.map +1 -1
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbUpdateRecords.js +3 -3
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbUpsertRecords.d.ts +1 -2
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbUpsertRecords.js +5 -5
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbUpsertRecords.js.map +1 -1
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbUtility/LMDBCreateAttributeObject.d.ts +1 -2
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbUtility/LMDBCreateAttributeObject.js +1 -1
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbUtility/LMDBCreateAttributeObject.js.map +1 -1
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbUtility/initializeHashSearch.js +2 -2
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbUtility/initializeHashSearch.js.map +1 -1
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbUtility/initializePaths.js +2 -2
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbCheckForNewAttributes.js +4 -4
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbCheckForNewAttributes.js.map +1 -1
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbCreateTransactionsAuditEnvironment.d.ts +1 -2
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbCreateTransactionsAuditEnvironment.js +5 -3
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbCreateTransactionsAuditEnvironment.js.map +1 -1
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbGetTableSize.js +2 -2
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbProcessRows.d.ts +1 -2
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbProcessRows.js +4 -4
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbProcessRows.js.map +1 -1
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbSearch.js +5 -5
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbWriteTransaction.js +4 -4
- package/dist/dataLayer/hdbInfoController.d.ts +4 -8
- package/dist/dataLayer/hdbInfoController.js +66 -31
- package/dist/dataLayer/hdbInfoController.js.map +1 -1
- package/dist/dataLayer/insert.d.ts +14 -26
- package/dist/dataLayer/insert.js +63 -28
- package/dist/dataLayer/insert.js.map +1 -1
- package/dist/dataLayer/readAuditLog.d.ts +1 -3
- package/dist/dataLayer/readAuditLog.js +45 -13
- package/dist/dataLayer/readAuditLog.js.map +1 -1
- package/dist/dataLayer/schema.d.ts +10 -10
- package/dist/dataLayer/schema.js +124 -89
- package/dist/dataLayer/schema.js.map +1 -1
- package/dist/dataLayer/schemaDescribe.d.ts +4 -4
- package/dist/dataLayer/schemaDescribe.js +78 -41
- package/dist/dataLayer/schemaDescribe.js.map +1 -1
- package/dist/dataLayer/search.d.ts +4 -4
- package/dist/dataLayer/search.js +12 -13
- package/dist/dataLayer/search.js.map +1 -1
- package/dist/dataLayer/transaction.d.ts +1 -1
- package/dist/dataLayer/transaction.js +3 -4
- package/dist/dataLayer/transaction.js.map +1 -1
- package/dist/dataLayer/update.d.ts +2 -8
- package/dist/dataLayer/update.js +53 -18
- package/dist/dataLayer/update.js.map +1 -1
- package/dist/globals.d.ts +1 -1
- package/dist/globals.js +1 -0
- package/dist/globals.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/json/systemSchema.json +65 -0
- package/dist/launchServiceScripts/launchHarperDB.d.ts +1 -0
- package/dist/launchServiceScripts/launchHarperDB.js +3 -0
- package/dist/launchServiceScripts/launchHarperDB.js.map +1 -0
- package/dist/launchServiceScripts/utility/checkNodeVersion.js +3 -0
- package/dist/launchServiceScripts/utility/checkNodeVersion.js.map +1 -1
- package/dist/resources/DatabaseTransaction.d.ts +14 -6
- package/dist/resources/DatabaseTransaction.js +39 -15
- package/dist/resources/DatabaseTransaction.js.map +1 -1
- package/dist/resources/ErrorResource.d.ts +1 -1
- package/dist/resources/ErrorResource.js +3 -1
- package/dist/resources/ErrorResource.js.map +1 -1
- package/dist/resources/LMDBTransaction.d.ts +10 -13
- package/dist/resources/LMDBTransaction.js +18 -7
- package/dist/resources/LMDBTransaction.js.map +1 -1
- package/dist/resources/RecordEncoder.d.ts +10 -12
- package/dist/resources/RecordEncoder.js +38 -38
- package/dist/resources/RecordEncoder.js.map +1 -1
- package/dist/resources/RequestTarget.d.ts +1 -0
- package/dist/resources/RequestTarget.js.map +1 -1
- package/dist/resources/Resource.d.ts +25 -5
- package/dist/resources/Resource.js +43 -10
- package/dist/resources/Resource.js.map +1 -1
- package/dist/resources/ResourceInterface.d.ts +24 -5
- package/dist/resources/ResourceInterface.js +20 -0
- package/dist/resources/ResourceInterface.js.map +1 -1
- package/dist/resources/Resources.d.ts +3 -4
- package/dist/resources/Resources.js +7 -6
- package/dist/resources/Resources.js.map +1 -1
- package/dist/resources/RocksIndexStore.js +3 -0
- package/dist/resources/RocksIndexStore.js.map +1 -1
- package/dist/resources/RocksTransactionLogStore.d.ts +1 -1
- package/dist/resources/RocksTransactionLogStore.js +10 -3
- package/dist/resources/RocksTransactionLogStore.js.map +1 -1
- package/dist/resources/Table.d.ts +76 -329
- package/dist/resources/Table.js +306 -116
- package/dist/resources/Table.js.map +1 -1
- package/dist/resources/analytics/metadata.d.ts +1 -0
- package/dist/resources/analytics/metadata.js +1 -0
- package/dist/resources/analytics/metadata.js.map +1 -1
- package/dist/resources/analytics/read.d.ts +8 -1
- package/dist/resources/analytics/read.js +69 -8
- package/dist/resources/analytics/read.js.map +1 -1
- package/dist/resources/analytics/write.d.ts +28 -0
- package/dist/resources/analytics/write.js +232 -20
- package/dist/resources/analytics/write.js.map +1 -1
- package/dist/resources/auditStore.d.ts +18 -13
- package/dist/resources/auditStore.js +16 -8
- package/dist/resources/auditStore.js.map +1 -1
- package/dist/resources/blob.d.ts +16 -27
- package/dist/resources/blob.js +8 -8
- package/dist/resources/blob.js.map +1 -1
- package/dist/resources/dataLoader.d.ts +1 -1
- package/dist/resources/dataLoader.js +13 -13
- package/dist/resources/databases.d.ts +17 -0
- package/dist/resources/databases.js +175 -59
- package/dist/resources/databases.js.map +1 -1
- package/dist/resources/graphql.d.ts +1 -7
- package/dist/resources/graphql.js +267 -173
- package/dist/resources/graphql.js.map +1 -1
- package/dist/resources/indexes/HierarchicalNavigableSmallWorld.d.ts +17 -1
- package/dist/resources/indexes/HierarchicalNavigableSmallWorld.js +327 -59
- package/dist/resources/indexes/HierarchicalNavigableSmallWorld.js.map +1 -1
- package/dist/resources/indexes/vector.d.ts +1 -0
- package/dist/resources/indexes/vector.js +14 -0
- package/dist/resources/indexes/vector.js.map +1 -1
- package/dist/resources/jsonSchemaTypes.d.ts +60 -0
- package/dist/resources/jsonSchemaTypes.js +78 -0
- package/dist/resources/jsonSchemaTypes.js.map +1 -0
- package/dist/resources/loadEnv.d.ts +2 -5
- package/dist/resources/loadEnv.js +21 -18
- package/dist/resources/loadEnv.js.map +1 -1
- package/dist/resources/login.d.ts +2 -3
- package/dist/resources/login.js +5 -4
- package/dist/resources/login.js.map +1 -1
- package/dist/resources/models/Models.d.ts +45 -0
- package/dist/resources/models/Models.js +265 -0
- package/dist/resources/models/Models.js.map +1 -0
- package/dist/resources/models/TestBackend.d.ts +15 -0
- package/dist/resources/models/TestBackend.js +71 -0
- package/dist/resources/models/TestBackend.js.map +1 -0
- package/dist/resources/models/agentLoop.d.ts +125 -0
- package/dist/resources/models/agentLoop.js +746 -0
- package/dist/resources/models/agentLoop.js.map +1 -0
- package/dist/resources/models/analyticsTable.d.ts +65 -0
- package/dist/resources/models/analyticsTable.js +166 -0
- package/dist/resources/models/analyticsTable.js.map +1 -0
- package/dist/resources/models/backendHelpers.d.ts +57 -0
- package/dist/resources/models/backendHelpers.js +109 -0
- package/dist/resources/models/backendHelpers.js.map +1 -0
- package/dist/resources/models/backendRegistry.d.ts +36 -0
- package/dist/resources/models/backendRegistry.js +54 -0
- package/dist/resources/models/backendRegistry.js.map +1 -0
- package/dist/resources/models/bootstrap.d.ts +24 -0
- package/dist/resources/models/bootstrap.js +112 -0
- package/dist/resources/models/bootstrap.js.map +1 -0
- package/dist/resources/models/embedHook.d.ts +33 -0
- package/dist/resources/models/embedHook.js +127 -0
- package/dist/resources/models/embedHook.js.map +1 -0
- package/dist/resources/models/types.d.ts +301 -0
- package/dist/resources/models/types.js +11 -0
- package/dist/resources/models/types.js.map +1 -0
- package/dist/resources/openApi.js +74 -34
- package/dist/resources/openApi.js.map +1 -1
- package/dist/resources/replayLogs.js +7 -1
- package/dist/resources/replayLogs.js.map +1 -1
- package/dist/resources/replayLogsGuards.d.ts +9 -0
- package/dist/resources/replayLogsGuards.js +47 -0
- package/dist/resources/replayLogsGuards.js.map +1 -1
- package/dist/resources/roles.d.ts +1 -7
- package/dist/resources/roles.js +67 -71
- package/dist/resources/roles.js.map +1 -1
- package/dist/resources/search.d.ts +18 -1
- package/dist/resources/search.js +349 -140
- package/dist/resources/search.js.map +1 -1
- package/dist/resources/tracked.d.ts +1 -1
- package/dist/resources/tracked.js +23 -15
- package/dist/resources/tracked.js.map +1 -1
- package/dist/resources/transaction.d.ts +1 -1
- package/dist/resources/transaction.js +1 -1
- package/dist/resources/transaction.js.map +1 -1
- package/dist/resources/transactionBroadcast.d.ts +1 -1
- package/dist/resources/transactionBroadcast.js.map +1 -1
- package/dist/security/auth.d.ts +1 -5
- package/dist/security/auth.js +34 -25
- package/dist/security/auth.js.map +1 -1
- package/dist/security/certificateVerification/crlVerification.js +7 -1
- package/dist/security/certificateVerification/crlVerification.js.map +1 -1
- package/dist/security/cryptoHash.d.ts +2 -2
- package/dist/security/cryptoHash.js +37 -5
- package/dist/security/cryptoHash.js.map +1 -1
- package/dist/security/data_objects/PermissionAttributeResponseObject.d.ts +3 -4
- package/dist/security/data_objects/PermissionAttributeResponseObject.js +4 -1
- package/dist/security/data_objects/PermissionAttributeResponseObject.js.map +1 -1
- package/dist/security/data_objects/PermissionResponseObject.d.ts +9 -9
- package/dist/security/data_objects/PermissionResponseObject.js +15 -8
- package/dist/security/data_objects/PermissionResponseObject.js.map +1 -1
- package/dist/security/data_objects/PermissionTableResponseObject.d.ts +5 -6
- package/dist/security/data_objects/PermissionTableResponseObject.js +6 -1
- package/dist/security/data_objects/PermissionTableResponseObject.js.map +1 -1
- package/dist/security/fastifyAuth.d.ts +2 -2
- package/dist/security/fastifyAuth.js +131 -22
- package/dist/security/fastifyAuth.js.map +1 -1
- package/dist/security/impersonation.js +15 -15
- package/dist/security/jsLoader.js +18 -5
- package/dist/security/jsLoader.js.map +1 -1
- package/dist/security/keys.d.ts +45 -48
- package/dist/security/keys.js +160 -114
- package/dist/security/keys.js.map +1 -1
- package/dist/security/permissionsTranslator.js +2 -2
- package/dist/security/role.d.ts +5 -5
- package/dist/security/role.js +70 -35
- package/dist/security/role.js.map +1 -1
- package/dist/security/tokenAuthentication.d.ts +13 -0
- package/dist/security/tokenAuthentication.js +57 -27
- package/dist/security/tokenAuthentication.js.map +1 -1
- package/dist/security/user.js +74 -38
- package/dist/security/user.js.map +1 -1
- package/dist/server/DurableSubscriptionsSession.d.ts +4 -2
- package/dist/server/DurableSubscriptionsSession.js +71 -55
- package/dist/server/DurableSubscriptionsSession.js.map +1 -1
- package/dist/server/REST.d.ts +1 -8
- package/dist/server/REST.js +17 -16
- package/dist/server/REST.js.map +1 -1
- package/dist/server/Server.d.ts +23 -4
- package/dist/server/Server.js +1 -1
- package/dist/server/Server.js.map +1 -1
- package/dist/server/fastifyRoutes/helpers/getCORSOptions.js +1 -1
- package/dist/server/fastifyRoutes/helpers/getHeaderTimeoutConfig.js +1 -1
- package/dist/server/fastifyRoutes/helpers/getServerOptions.js +1 -1
- package/dist/server/fastifyRoutes.d.ts +1 -4
- package/dist/server/fastifyRoutes.js +34 -30
- package/dist/server/fastifyRoutes.js.map +1 -1
- package/dist/server/graphqlQuerying.d.ts +1 -1
- package/dist/server/graphqlQuerying.js +8 -7
- package/dist/server/graphqlQuerying.js.map +1 -1
- package/dist/server/http.d.ts +9 -4
- package/dist/server/http.js +523 -47
- package/dist/server/http.js.map +1 -1
- package/dist/server/itc/serverHandlers.js +66 -15
- package/dist/server/itc/serverHandlers.js.map +1 -1
- package/dist/server/jobs/JobObject.d.ts +3 -3
- package/dist/server/jobs/JobObject.js +53 -7
- package/dist/server/jobs/JobObject.js.map +1 -1
- package/dist/server/jobs/jobProcess.js +64 -24
- package/dist/server/jobs/jobProcess.js.map +1 -1
- package/dist/server/jobs/jobRunner.d.ts +7 -6
- package/dist/server/jobs/jobRunner.js +68 -30
- package/dist/server/jobs/jobRunner.js.map +1 -1
- package/dist/server/jobs/jobs.d.ts +18 -7
- package/dist/server/jobs/jobs.js +93 -61
- package/dist/server/jobs/jobs.js.map +1 -1
- package/dist/server/loadRootComponents.js +1 -1
- package/dist/server/middlewareChain.d.ts +80 -0
- package/dist/server/middlewareChain.js +252 -0
- package/dist/server/middlewareChain.js.map +1 -0
- package/dist/server/mqtt.d.ts +1 -8
- package/dist/server/mqtt.js +22 -17
- package/dist/server/mqtt.js.map +1 -1
- package/dist/server/nodeName.js +46 -13
- package/dist/server/nodeName.js.map +1 -1
- package/dist/server/operationsServer.d.ts +2 -2
- package/dist/server/operationsServer.js +106 -33
- package/dist/server/operationsServer.js.map +1 -1
- package/dist/server/serverHelpers/Headers.d.ts +4 -4
- package/dist/server/serverHelpers/Headers.js +2 -0
- package/dist/server/serverHelpers/Headers.js.map +1 -1
- package/dist/server/serverHelpers/JSONStream.d.ts +7 -1
- package/dist/server/serverHelpers/JSONStream.js +12 -3
- package/dist/server/serverHelpers/JSONStream.js.map +1 -1
- package/dist/server/serverHelpers/Request.d.ts +106 -8
- package/dist/server/serverHelpers/Request.js +370 -9
- package/dist/server/serverHelpers/Request.js.map +1 -1
- package/dist/server/serverHelpers/contentTypes.d.ts +1 -1
- package/dist/server/serverHelpers/contentTypes.js +36 -7
- package/dist/server/serverHelpers/contentTypes.js.map +1 -1
- package/dist/server/serverHelpers/multipartParser.d.ts +21 -0
- package/dist/server/serverHelpers/multipartParser.js +142 -0
- package/dist/server/serverHelpers/multipartParser.js.map +1 -0
- package/dist/server/serverHelpers/progressEmitter.d.ts +25 -0
- package/dist/server/serverHelpers/progressEmitter.js +103 -0
- package/dist/server/serverHelpers/progressEmitter.js.map +1 -0
- package/dist/server/serverHelpers/serverHandlers.d.ts +1 -1
- package/dist/server/serverHelpers/serverHandlers.js +38 -7
- package/dist/server/serverHelpers/serverHandlers.js.map +1 -1
- package/dist/server/serverHelpers/serverUtilities.d.ts +4 -2
- package/dist/server/serverHelpers/serverUtilities.js +97 -93
- package/dist/server/serverHelpers/serverUtilities.js.map +1 -1
- package/dist/server/static.js +8 -5
- package/dist/server/static.js.map +1 -1
- package/dist/server/status/index.js +3 -3
- package/dist/server/storageReclamation.d.ts +10 -0
- package/dist/server/storageReclamation.js +68 -9
- package/dist/server/storageReclamation.js.map +1 -1
- package/dist/server/threads/itc.js +7 -4
- package/dist/server/threads/itc.js.map +1 -1
- package/dist/server/threads/manageThreads.d.ts +1 -1
- package/dist/server/threads/manageThreads.js +110 -26
- package/dist/server/threads/manageThreads.js.map +1 -1
- package/dist/server/threads/socketRouter.d.ts +0 -1
- package/dist/server/threads/socketRouter.js +8 -271
- package/dist/server/threads/socketRouter.js.map +1 -1
- package/dist/server/threads/threadServer.d.ts +1 -0
- package/dist/server/threads/threadServer.js +360 -118
- package/dist/server/threads/threadServer.js.map +1 -1
- package/dist/server/threads/workerProcessGuard.d.ts +42 -0
- package/dist/server/threads/workerProcessGuard.js +114 -0
- package/dist/server/threads/workerProcessGuard.js.map +1 -0
- package/dist/server/throttle.js +17 -0
- package/dist/server/throttle.js.map +1 -1
- package/dist/sqlTranslator/SelectValidator.d.ts +21 -24
- package/dist/sqlTranslator/SelectValidator.js +86 -47
- package/dist/sqlTranslator/SelectValidator.js.map +1 -1
- package/dist/sqlTranslator/alasqlFunctionImporter.d.ts +6 -2
- package/dist/sqlTranslator/alasqlFunctionImporter.js +40 -3
- package/dist/sqlTranslator/alasqlFunctionImporter.js.map +1 -1
- package/dist/sqlTranslator/deleteTranslator.d.ts +4 -7
- package/dist/sqlTranslator/deleteTranslator.js +48 -14
- package/dist/sqlTranslator/deleteTranslator.js.map +1 -1
- package/dist/sqlTranslator/index.d.ts +10 -9
- package/dist/sqlTranslator/index.js +69 -30
- package/dist/sqlTranslator/index.js.map +1 -1
- package/dist/sqlTranslator/sql_statement_bucket.d.ts +10 -10
- package/dist/sqlTranslator/sql_statement_bucket.js +55 -13
- package/dist/sqlTranslator/sql_statement_bucket.js.map +1 -1
- package/dist/upgrade/UpgradeObjects.d.ts +2 -3
- package/dist/upgrade/UpgradeObjects.js +37 -4
- package/dist/upgrade/UpgradeObjects.js.map +1 -1
- package/dist/upgrade/directives/5-1-0.d.ts +6 -0
- package/dist/upgrade/directives/5-1-0.js +114 -0
- package/dist/upgrade/directives/5-1-0.js.map +1 -0
- package/dist/upgrade/directives/directivesController.d.ts +10 -10
- package/dist/upgrade/directives/directivesController.js +52 -11
- package/dist/upgrade/directives/directivesController.js.map +1 -1
- package/dist/upgrade/directivesManager.d.ts +1 -1
- package/dist/upgrade/directivesManager.js +53 -18
- package/dist/upgrade/directivesManager.js.map +1 -1
- package/dist/upgrade/upgradePrompt.d.ts +2 -8
- package/dist/upgrade/upgradePrompt.js +55 -60
- package/dist/upgrade/upgradePrompt.js.map +1 -1
- package/dist/upgrade/upgradeUtilities.d.ts +1 -1
- package/dist/upgrade/upgradeUtilities.js +37 -5
- package/dist/upgrade/upgradeUtilities.js.map +1 -1
- package/dist/utility/OperationFunctionCaller.d.ts +1 -1
- package/dist/utility/OperationFunctionCaller.js +45 -10
- package/dist/utility/OperationFunctionCaller.js.map +1 -1
- package/dist/utility/assignCmdEnvVariables.d.ts +1 -2
- package/dist/utility/assignCmdEnvVariables.js +8 -4
- package/dist/utility/assignCmdEnvVariables.js.map +1 -1
- package/dist/utility/common_utils.d.ts +80 -77
- package/dist/utility/common_utils.js +140 -79
- package/dist/utility/common_utils.js.map +1 -1
- package/dist/utility/environment/environmentManager.d.ts +12 -11
- package/dist/utility/environment/environmentManager.js +75 -29
- package/dist/utility/environment/environmentManager.js.map +1 -1
- package/dist/utility/environment/systemInformation.d.ts +4 -0
- package/dist/utility/environment/systemInformation.js +27 -16
- package/dist/utility/environment/systemInformation.js.map +1 -1
- package/dist/utility/errors/commonErrors.d.ts +192 -168
- package/dist/utility/errors/commonErrors.js +49 -18
- package/dist/utility/errors/commonErrors.js.map +1 -1
- package/dist/utility/errors/hdbError.d.ts +37 -51
- package/dist/utility/errors/hdbError.js +65 -26
- package/dist/utility/errors/hdbError.js.map +1 -1
- package/dist/utility/expandEnvVar.d.ts +61 -0
- package/dist/utility/expandEnvVar.js +113 -0
- package/dist/utility/expandEnvVar.js.map +1 -0
- package/dist/utility/functions/geo.js +2 -2
- package/dist/utility/functions/sql/alaSQLExtension.js +1 -1
- package/dist/utility/globalSchema.d.ts +13 -4
- package/dist/utility/globalSchema.js +14 -11
- package/dist/utility/globalSchema.js.map +1 -1
- package/dist/utility/hdbTerms.d.ts +54 -1
- package/dist/utility/hdbTerms.js +54 -1
- package/dist/utility/hdbTerms.js.map +1 -1
- package/dist/utility/install/checkJWTTokensExist.js +1 -1
- package/dist/utility/install/installer.d.ts +9 -12
- package/dist/utility/install/installer.js +117 -54
- package/dist/utility/install/installer.js.map +1 -1
- package/dist/utility/installation.js +3 -3
- package/dist/utility/lmdb/DBIDefinition.d.ts +4 -4
- package/dist/utility/lmdb/DBIDefinition.js +5 -1
- package/dist/utility/lmdb/DBIDefinition.js.map +1 -1
- package/dist/utility/lmdb/DeleteRecordsResponseObject.d.ts +3 -6
- package/dist/utility/lmdb/DeleteRecordsResponseObject.js +2 -1
- package/dist/utility/lmdb/DeleteRecordsResponseObject.js.map +1 -1
- package/dist/utility/lmdb/InsertRecordsResponseObject.d.ts +3 -5
- package/dist/utility/lmdb/InsertRecordsResponseObject.js +2 -1
- package/dist/utility/lmdb/InsertRecordsResponseObject.js.map +1 -1
- package/dist/utility/lmdb/OpenDBIObject.d.ts +12 -15
- package/dist/utility/lmdb/OpenDBIObject.js +68 -6
- package/dist/utility/lmdb/OpenDBIObject.js.map +1 -1
- package/dist/utility/lmdb/OpenEnvironmentObject.d.ts +5 -8
- package/dist/utility/lmdb/OpenEnvironmentObject.js +52 -4
- package/dist/utility/lmdb/OpenEnvironmentObject.js.map +1 -1
- package/dist/utility/lmdb/UpdateRecordsResponseObject.d.ts +3 -6
- package/dist/utility/lmdb/UpdateRecordsResponseObject.js +2 -1
- package/dist/utility/lmdb/UpdateRecordsResponseObject.js.map +1 -1
- package/dist/utility/lmdb/UpsertRecordsResponseObject.d.ts +3 -5
- package/dist/utility/lmdb/UpsertRecordsResponseObject.js +2 -1
- package/dist/utility/lmdb/UpsertRecordsResponseObject.js.map +1 -1
- package/dist/utility/lmdb/cleanLMDBMap.d.ts +1 -1
- package/dist/utility/lmdb/cleanLMDBMap.js +44 -7
- package/dist/utility/lmdb/cleanLMDBMap.js.map +1 -1
- package/dist/utility/lmdb/commonUtility.d.ts +8 -9
- package/dist/utility/lmdb/commonUtility.js +46 -17
- package/dist/utility/lmdb/commonUtility.js.map +1 -1
- package/dist/utility/lmdb/deleteUtility.d.ts +2 -3
- package/dist/utility/lmdb/deleteUtility.js +51 -16
- package/dist/utility/lmdb/deleteUtility.js.map +1 -1
- package/dist/utility/lmdb/environmentUtility.d.ts +69 -36
- package/dist/utility/lmdb/environmentUtility.js +91 -51
- package/dist/utility/lmdb/environmentUtility.js.map +1 -1
- package/dist/utility/lmdb/searchCursorFunctions.d.ts +19 -19
- package/dist/utility/lmdb/searchCursorFunctions.js +46 -14
- package/dist/utility/lmdb/searchCursorFunctions.js.map +1 -1
- package/dist/utility/lmdb/searchUtility.d.ts +142 -73
- package/dist/utility/lmdb/searchUtility.js +91 -55
- package/dist/utility/lmdb/searchUtility.js.map +1 -1
- package/dist/utility/lmdb/terms.d.ts +34 -34
- package/dist/utility/lmdb/terms.js +12 -22
- package/dist/utility/lmdb/terms.js.map +1 -1
- package/dist/utility/lmdb/writeUtility.d.ts +3 -6
- package/dist/utility/lmdb/writeUtility.js +61 -28
- package/dist/utility/lmdb/writeUtility.js.map +1 -1
- package/dist/utility/logging/harper_logger.d.ts +87 -103
- package/dist/utility/logging/harper_logger.js +177 -82
- package/dist/utility/logging/harper_logger.js.map +1 -1
- package/dist/utility/logging/logRotator.d.ts +2 -10
- package/dist/utility/logging/logRotator.js +67 -32
- package/dist/utility/logging/logRotator.js.map +1 -1
- package/dist/utility/logging/logger.js +4 -4
- package/dist/utility/logging/readLog.d.ts +1 -1
- package/dist/utility/logging/readLog.js +54 -17
- package/dist/utility/logging/readLog.js.map +1 -1
- package/dist/utility/logging/transactionLog.d.ts +2 -2
- package/dist/utility/logging/transactionLog.js +51 -16
- package/dist/utility/logging/transactionLog.js.map +1 -1
- package/dist/utility/mount_hdb.d.ts +1 -2
- package/dist/utility/mount_hdb.js +54 -17
- package/dist/utility/mount_hdb.js.map +1 -1
- package/dist/utility/npmUtilities.d.ts +1 -1
- package/dist/utility/npmUtilities.js +54 -19
- package/dist/utility/npmUtilities.js.map +1 -1
- package/dist/utility/operation_authorization.d.ts +36 -9
- package/dist/utility/operation_authorization.js +135 -86
- package/dist/utility/operation_authorization.js.map +1 -1
- package/dist/utility/packageUtils.d.ts +0 -2
- package/dist/utility/packageUtils.js +7 -17
- package/dist/utility/packageUtils.js.map +1 -1
- package/dist/utility/password.js +2 -2
- package/dist/utility/processManagement/processManagement.js +2 -2
- package/dist/utility/processManagement/servicesConfig.js +1 -1
- package/dist/utility/signalling.d.ts +2 -2
- package/dist/utility/signalling.js +51 -16
- package/dist/utility/signalling.js.map +1 -1
- package/dist/utility/watcherFallback.d.ts +36 -0
- package/dist/utility/watcherFallback.js +73 -0
- package/dist/utility/watcherFallback.js.map +1 -0
- package/dist/validation/analyticsValidator.d.ts +1 -0
- package/dist/validation/analyticsValidator.js +80 -0
- package/dist/validation/analyticsValidator.js.map +1 -0
- package/dist/validation/bulkDeleteValidator.d.ts +1 -2
- package/dist/validation/bulkDeleteValidator.js +49 -11
- package/dist/validation/bulkDeleteValidator.js.map +1 -1
- package/dist/validation/check_permissions.d.ts +1 -2
- package/dist/validation/check_permissions.js +38 -3
- package/dist/validation/check_permissions.js.map +1 -1
- package/dist/validation/common_validators.d.ts +20 -20
- package/dist/validation/common_validators.js +62 -31
- package/dist/validation/common_validators.js.map +1 -1
- package/dist/validation/configValidator.d.ts +4 -4
- package/dist/validation/configValidator.js +189 -54
- package/dist/validation/configValidator.js.map +1 -1
- package/dist/validation/deleteValidator.d.ts +1 -2
- package/dist/validation/deleteValidator.js +49 -11
- package/dist/validation/deleteValidator.js.map +1 -1
- package/dist/validation/fileLoadValidator.d.ts +4 -4
- package/dist/validation/fileLoadValidator.js +67 -32
- package/dist/validation/fileLoadValidator.js.map +1 -1
- package/dist/validation/insertValidator.d.ts +1 -2
- package/dist/validation/insertValidator.js +48 -10
- package/dist/validation/insertValidator.js.map +1 -1
- package/dist/validation/installValidator.d.ts +2 -2
- package/dist/validation/installValidator.js +47 -10
- package/dist/validation/installValidator.js.map +1 -1
- package/dist/validation/readLogValidator.d.ts +1 -2
- package/dist/validation/readLogValidator.js +60 -22
- package/dist/validation/readLogValidator.js.map +1 -1
- package/dist/validation/role_validation.d.ts +3 -3
- package/dist/validation/role_validation.js +55 -19
- package/dist/validation/role_validation.js.map +1 -1
- package/dist/validation/schemaMetadataValidator.d.ts +3 -4
- package/dist/validation/schemaMetadataValidator.js +11 -12
- package/dist/validation/schemaMetadataValidator.js.map +1 -1
- package/dist/validation/searchValidator.d.ts +1 -2
- package/dist/validation/searchValidator.js +82 -43
- package/dist/validation/searchValidator.js.map +1 -1
- package/dist/validation/statusValidator.d.ts +1 -1
- package/dist/validation/transactionLogValidator.d.ts +3 -3
- package/dist/validation/transactionLogValidator.js +52 -17
- package/dist/validation/transactionLogValidator.js.map +1 -1
- package/dist/validation/user_validation.d.ts +3 -3
- package/dist/validation/user_validation.js +38 -6
- package/dist/validation/user_validation.js.map +1 -1
- package/dist/validation/validationWrapper.d.ts +3 -3
- package/dist/validation/validationWrapper.js +4 -5
- package/dist/validation/validationWrapper.js.map +1 -1
- package/index.ts +5 -0
- package/json/systemSchema.json +65 -0
- package/launchServiceScripts/utility/checkNodeVersion.js +2 -0
- package/package.json +38 -24
- package/resources/DESIGN.md +98 -0
- package/resources/DatabaseTransaction.ts +58 -30
- package/resources/ErrorResource.ts +2 -1
- package/resources/LMDBTransaction.ts +38 -29
- package/resources/RecordEncoder.ts +41 -39
- package/resources/RequestTarget.ts +2 -0
- package/resources/Resource.ts +96 -56
- package/resources/ResourceInterface.ts +44 -21
- package/resources/Resources.ts +8 -8
- package/resources/RocksIndexStore.ts +3 -0
- package/resources/RocksTransactionLogStore.ts +13 -4
- package/resources/Table.ts +440 -223
- package/resources/analytics/metadata.ts +1 -0
- package/resources/analytics/read.ts +99 -10
- package/resources/analytics/write.ts +240 -17
- package/resources/auditStore.ts +30 -19
- package/resources/blob.ts +53 -53
- package/resources/dataLoader.ts +4 -4
- package/resources/databases.ts +208 -74
- package/resources/graphql.ts +267 -165
- package/resources/indexes/HierarchicalNavigableSmallWorld.ts +310 -65
- package/resources/indexes/vector.ts +17 -0
- package/resources/jsonSchemaTypes.ts +102 -0
- package/resources/loadEnv.ts +21 -17
- package/resources/login.ts +5 -3
- package/resources/models/Models.ts +304 -0
- package/resources/models/TestBackend.ts +83 -0
- package/resources/models/agentLoop.ts +895 -0
- package/resources/models/analyticsTable.ts +199 -0
- package/resources/models/backendHelpers.ts +116 -0
- package/resources/models/backendRegistry.ts +66 -0
- package/resources/models/bootstrap.ts +135 -0
- package/resources/models/embedHook.ts +138 -0
- package/resources/models/types.ts +296 -0
- package/resources/openApi.ts +65 -31
- package/resources/replayLogs.ts +20 -9
- package/resources/replayLogsGuards.ts +45 -0
- package/resources/roles.ts +62 -67
- package/resources/search.ts +355 -135
- package/resources/tracked.ts +18 -9
- package/resources/transaction.ts +8 -8
- package/resources/transactionBroadcast.ts +3 -3
- package/schema.graphql +7 -0
- package/security/auth.ts +35 -26
- package/security/certificateVerification/crlVerification.ts +11 -4
- package/security/{cryptoHash.js → cryptoHash.ts} +3 -8
- package/security/data_objects/{PermissionAttributeResponseObject.js → PermissionAttributeResponseObject.ts} +4 -4
- package/security/data_objects/{PermissionResponseObject.js → PermissionResponseObject.ts} +12 -11
- package/security/data_objects/{PermissionTableResponseObject.js → PermissionTableResponseObject.ts} +6 -4
- package/security/{fastifyAuth.js → fastifyAuth.ts} +93 -20
- package/security/impersonation.ts +3 -3
- package/security/jsLoader.ts +22 -8
- package/security/{keys.js → keys.ts} +113 -121
- package/security/permissionsTranslator.js +2 -2
- package/security/{role.js → role.ts} +26 -33
- package/security/tokenAuthentication.ts +34 -7
- package/security/user.ts +26 -22
- package/server/DESIGN.md +139 -0
- package/server/DurableSubscriptionsSession.ts +67 -50
- package/server/REST.ts +120 -107
- package/server/Server.ts +31 -12
- package/server/fastifyRoutes/helpers/getCORSOptions.js +1 -1
- package/server/fastifyRoutes/helpers/getHeaderTimeoutConfig.js +1 -1
- package/server/fastifyRoutes/helpers/getServerOptions.js +1 -1
- package/server/fastifyRoutes.ts +37 -33
- package/server/graphqlQuerying.ts +6 -5
- package/server/http.ts +517 -26
- package/server/itc/serverHandlers.js +75 -14
- package/server/jobs/{JobObject.js → JobObject.ts} +13 -6
- package/server/jobs/{jobProcess.js → jobProcess.ts} +20 -16
- package/server/jobs/{jobRunner.js → jobRunner.ts} +20 -21
- package/server/jobs/{jobs.js → jobs.ts} +41 -44
- package/server/loadRootComponents.js +1 -1
- package/server/middlewareChain.ts +270 -0
- package/server/mqtt.ts +35 -26
- package/server/nodeName.ts +3 -1
- package/server/operationsServer.ts +85 -10
- package/server/serverHelpers/Headers.ts +10 -8
- package/server/serverHelpers/JSONStream.ts +15 -5
- package/server/serverHelpers/Request.ts +370 -13
- package/server/serverHelpers/contentTypes.ts +42 -11
- package/server/serverHelpers/multipartParser.ts +152 -0
- package/server/serverHelpers/progressEmitter.ts +110 -0
- package/server/serverHelpers/serverHandlers.js +43 -7
- package/server/serverHelpers/serverUtilities.ts +40 -30
- package/server/static.ts +9 -6
- package/server/status/index.ts +2 -2
- package/server/storageReclamation.ts +39 -2
- package/server/threads/itc.js +7 -4
- package/server/threads/manageThreads.js +100 -26
- package/server/threads/socketRouter.ts +12 -275
- package/server/threads/threadServer.js +345 -105
- package/server/threads/workerProcessGuard.ts +93 -0
- package/server/throttle.ts +18 -0
- package/sqlTranslator/{SelectValidator.js → SelectValidator.ts} +41 -49
- package/sqlTranslator/{alasqlFunctionImporter.js → alasqlFunctionImporter.ts} +5 -5
- package/sqlTranslator/{deleteTranslator.js → deleteTranslator.ts} +13 -18
- package/sqlTranslator/{index.js → index.ts} +30 -33
- package/sqlTranslator/{sql_statement_bucket.js → sql_statement_bucket.ts} +49 -20
- package/static/README.md +10 -9
- package/static/defaultConfig.yaml +0 -1
- package/studio/web/assets/{index-CybLScHg.js → index-Dqr9oVhe.js} +5 -5
- package/studio/web/assets/index-Dqr9oVhe.js.map +1 -0
- package/studio/web/assets/{index.lazy-DKx5-iXF.js → index.lazy-CpKcKb7M.js} +2 -2
- package/studio/web/assets/{index.lazy-DKx5-iXF.js.map → index.lazy-CpKcKb7M.js.map} +1 -1
- package/studio/web/assets/{profile-BOjes0Wl.js → profile-C1cujdsg.js} +2 -2
- package/studio/web/assets/{profile-BOjes0Wl.js.map → profile-C1cujdsg.js.map} +1 -1
- package/studio/web/assets/{status-EWKUIrjT.js → status-CTiIIQlY.js} +2 -2
- package/studio/web/assets/{status-EWKUIrjT.js.map → status-CTiIIQlY.js.map} +1 -1
- package/studio/web/index.html +1 -1
- package/upgrade/{UpgradeObjects.js → UpgradeObjects.ts} +3 -6
- package/upgrade/directives/5-1-0.ts +89 -0
- package/upgrade/directives/{directivesController.js → directivesController.ts} +16 -16
- package/upgrade/{directivesManager.js → directivesManager.ts} +7 -11
- package/upgrade/{upgradePrompt.js → upgradePrompt.ts} +6 -54
- package/upgrade/{upgradeUtilities.js → upgradeUtilities.ts} +3 -7
- package/utility/{OperationFunctionCaller.js → OperationFunctionCaller.ts} +7 -7
- package/utility/{assignCmdEnvVariables.js → assignCmdEnvVariables.ts} +6 -8
- package/utility/{common_utils.js → common_utils.ts} +113 -139
- package/utility/environment/{environmentManager.js → environmentManager.ts} +34 -33
- package/utility/environment/systemInformation.ts +18 -4
- package/utility/errors/{commonErrors.js → commonErrors.ts} +9 -9
- package/utility/errors/{hdbError.js → hdbError.ts} +39 -45
- package/utility/expandEnvVar.ts +110 -0
- package/utility/functions/geo.js +2 -2
- package/utility/functions/sql/alaSQLExtension.js +1 -1
- package/utility/globalSchema.ts +30 -0
- package/utility/hdbTerms.ts +54 -1
- package/utility/install/checkJWTTokensExist.js +1 -1
- package/utility/install/{installer.js → installer.ts} +66 -42
- package/utility/installation.ts +2 -2
- package/utility/lmdb/{DBIDefinition.js → DBIDefinition.ts} +4 -1
- package/utility/lmdb/{DeleteRecordsResponseObject.js → DeleteRecordsResponseObject.ts} +2 -1
- package/utility/lmdb/{InsertRecordsResponseObject.js → InsertRecordsResponseObject.ts} +2 -1
- package/utility/lmdb/OpenDBIObject.ts +57 -0
- package/utility/lmdb/{OpenEnvironmentObject.js → OpenEnvironmentObject.ts} +19 -6
- package/utility/lmdb/{UpdateRecordsResponseObject.js → UpdateRecordsResponseObject.ts} +2 -1
- package/utility/lmdb/{UpsertRecordsResponseObject.js → UpsertRecordsResponseObject.ts} +2 -1
- package/utility/lmdb/{cleanLMDBMap.js → cleanLMDBMap.ts} +5 -5
- package/utility/lmdb/{commonUtility.js → commonUtility.ts} +13 -21
- package/utility/lmdb/{deleteUtility.js → deleteUtility.ts} +8 -12
- package/utility/lmdb/{environmentUtility.js → environmentUtility.ts} +43 -52
- package/utility/lmdb/{searchCursorFunctions.js → searchCursorFunctions.ts} +12 -26
- package/utility/lmdb/{searchUtility.js → searchUtility.ts} +75 -64
- package/utility/lmdb/{terms.js → terms.ts} +10 -23
- package/utility/lmdb/{writeUtility.js → writeUtility.ts} +37 -22
- package/utility/logging/{harper_logger.js → harper_logger.ts} +137 -90
- package/utility/logging/{logRotator.js → logRotator.ts} +15 -18
- package/utility/logging/logger.ts +1 -1
- package/utility/logging/{readLog.js → readLog.ts} +19 -19
- package/utility/logging/{transactionLog.js → transactionLog.ts} +10 -14
- package/utility/{mount_hdb.js → mount_hdb.ts} +15 -16
- package/utility/{npmUtilities.js → npmUtilities.ts} +14 -17
- package/utility/{operation_authorization.js → operation_authorization.ts} +173 -124
- package/utility/packageUtils.js +7 -16
- package/utility/password.ts +1 -1
- package/utility/processManagement/processManagement.js +2 -2
- package/utility/processManagement/servicesConfig.js +1 -1
- package/utility/{signalling.js → signalling.ts} +6 -11
- package/utility/watcherFallback.ts +74 -0
- package/validation/analyticsValidator.ts +44 -0
- package/validation/{bulkDeleteValidator.js → bulkDeleteValidator.ts} +5 -5
- package/validation/{check_permissions.js → check_permissions.ts} +3 -3
- package/validation/{common_validators.js → common_validators.ts} +12 -24
- package/validation/{configValidator.js → configValidator.ts} +114 -18
- package/validation/{deleteValidator.js → deleteValidator.ts} +5 -5
- package/validation/{fileLoadValidator.js → fileLoadValidator.ts} +12 -19
- package/validation/{insertValidator.js → insertValidator.ts} +5 -5
- package/validation/{installValidator.js → installValidator.ts} +8 -8
- package/validation/{readLogValidator.js → readLogValidator.ts} +10 -10
- package/validation/{role_validation.js → role_validation.ts} +26 -32
- package/validation/{schemaMetadataValidator.js → schemaMetadataValidator.ts} +5 -11
- package/validation/{searchValidator.js → searchValidator.ts} +12 -11
- package/validation/statusValidator.ts +1 -1
- package/validation/{transactionLogValidator.js → transactionLogValidator.ts} +4 -9
- package/validation/{user_validation.js → user_validation.ts} +4 -10
- package/validation/{validationWrapper.js → validationWrapper.ts} +3 -9
- package/bin/cliOperations.js +0 -159
- package/bin/lite.js +0 -5
- package/dataLayer/harperBridge/BridgeMethods.js +0 -85
- package/studio/web/assets/index-CybLScHg.js.map +0 -1
- package/utility/globalSchema.js +0 -35
- package/utility/lmdb/OpenDBIObject.js +0 -31
|
@@ -0,0 +1,895 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-process tool-call agent loop for `Models.generate({ toolMode: 'auto' })`.
|
|
3
|
+
*
|
|
4
|
+
* Each iteration: (1) call `models.generate` with the running message list,
|
|
5
|
+
* (2) if the model emitted tool calls, dispatch each via `opts.toolHandlers`,
|
|
6
|
+
* (3) append the tool results to the message list, repeat. Terminate when the
|
|
7
|
+
* model returns a non-`tool_calls` finish reason or when the iteration cap trips.
|
|
8
|
+
*
|
|
9
|
+
* Analytics: the loop calls back through `models.generate(..., {toolMode: 'return'})`
|
|
10
|
+
* per iteration so each backend round flows the single-shot path in `Models.ts` and
|
|
11
|
+
* writes its own `hdb_model_calls` row. The outer auto call stays out of the table.
|
|
12
|
+
*
|
|
13
|
+
* **Abort wiring** (commit 3). Each invocation creates a loop-level
|
|
14
|
+
* `AbortController` composed with the caller's signal via `AbortSignal.any`. The
|
|
15
|
+
* composed signal flows to both the inner `models.generate` call and the
|
|
16
|
+
* `ToolHandlerContext.signal` handlers receive. Today the loop-level controller is
|
|
17
|
+
* only fired externally (caller aborts → composed signal aborts); commit 4 wires
|
|
18
|
+
* it to also fire on budget trips so an in-flight LLM call cancels cleanly.
|
|
19
|
+
*
|
|
20
|
+
* Streaming auto path + `opts.conversation.append` hook on both sync and streaming.
|
|
21
|
+
* The streaming loop yields each round's content / tool-call deltas to the caller as
|
|
22
|
+
* they arrive, accumulates the round's tool-call assembly internally, and treats
|
|
23
|
+
* `finishReason` as an INTERNAL signal: it is stripped from every forwarded chunk and
|
|
24
|
+
* re-emitted as exactly one terminal chunk AFTER the terminal assistant turn has been
|
|
25
|
+
* persisted, so a consumer that stops on the finish-reason chunk can never race past
|
|
26
|
+
* the conversation append. Tools run between rounds; the next backend stream resumes.
|
|
27
|
+
* Budget / abort / error-mode semantics match the sync path, with one streaming-specific
|
|
28
|
+
* gap: `maxToolTokens` / `maxCostUsd` are not yet enforced for streamed calls because
|
|
29
|
+
* `GenerateChunk` doesn't expose `usage` in v1 (follow-up to extend the chunk shape +
|
|
30
|
+
* backend final-chunk handling).
|
|
31
|
+
*
|
|
32
|
+
* Resilience posture (this module is foundational infra — fail loud, never silent):
|
|
33
|
+
* - Handler lookup uses `Object.hasOwn` + a callable check; a model-emitted tool name
|
|
34
|
+
* that collides with an Object prototype member (`toString`, `constructor`, …) does
|
|
35
|
+
* NOT resolve a built-in as a handler.
|
|
36
|
+
* - Missing handler splits two ways: a name the caller DECLARED in `tools` but didn't
|
|
37
|
+
* supply a handler for is a caller config bug (hard `ClientError(400)`); an UNdeclared
|
|
38
|
+
* name is a model hallucination, surfaced as a recoverable tool error (`toolErrorMode`
|
|
39
|
+
* decides recover-vs-abort).
|
|
40
|
+
* - A token/cost budget set against a backend that reports no `usage` warns once that it
|
|
41
|
+
* is unenforceable rather than silently no-opping.
|
|
42
|
+
* - An incomplete streamed tool call (id without a name) is recorded in the trace + warned,
|
|
43
|
+
* not silently dropped.
|
|
44
|
+
* - `toolErrorMode: 'abort'` throws BEFORE the conversation sink sees the round's tool
|
|
45
|
+
* turns, so the store never holds a recover-style error turn the model never consumed.
|
|
46
|
+
*
|
|
47
|
+
* Modes still deferred to follow-ups throw 501 at entry:
|
|
48
|
+
* - `toolArgValidation: 'strict' | 'lenient'` → JSON Schema validator (TBD)
|
|
49
|
+
* - `maxToolTokens` / `maxCostUsd` (streaming) → backend `usage` on chunks (TBD)
|
|
50
|
+
*
|
|
51
|
+
* Registry seam: v1 dispatches via caller-supplied `opts.toolHandlers`. #615 replaces
|
|
52
|
+
* that lookup with a `scope.resources` resolution using the same call signature — the
|
|
53
|
+
* declared-vs-undeclared split maps onto resolvable-but-misconfigured vs unknown.
|
|
54
|
+
*/
|
|
55
|
+
import { ClientError, ServerError } from '../../utility/errors/hdbError.ts';
|
|
56
|
+
import { logger } from '../../utility/logging/logger.ts';
|
|
57
|
+
import type {
|
|
58
|
+
AccountingContext,
|
|
59
|
+
GenerateChunk,
|
|
60
|
+
GenerateInput,
|
|
61
|
+
GenerateOpts,
|
|
62
|
+
GenerateResult,
|
|
63
|
+
Message,
|
|
64
|
+
Models,
|
|
65
|
+
TokenUsage,
|
|
66
|
+
ToolCall,
|
|
67
|
+
ToolDef,
|
|
68
|
+
ToolHandler,
|
|
69
|
+
ToolHandlerContext,
|
|
70
|
+
ToolTraceEntry,
|
|
71
|
+
} from './types.ts';
|
|
72
|
+
|
|
73
|
+
const DEFAULT_MAX_ITERATIONS = 10;
|
|
74
|
+
const DEFAULT_MAX_RESULT_BYTES = 65_536;
|
|
75
|
+
|
|
76
|
+
export interface RunAgentLoopArgs {
|
|
77
|
+
models: Models;
|
|
78
|
+
input: GenerateInput;
|
|
79
|
+
opts: GenerateOpts;
|
|
80
|
+
accounting: AccountingContext;
|
|
81
|
+
signal?: AbortSignal;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export async function runAgentLoop(args: RunAgentLoopArgs): Promise<GenerateResult> {
|
|
85
|
+
const { models, opts, accounting, signal: callerSignal } = args;
|
|
86
|
+
|
|
87
|
+
// v1 gates: surface declared on GenerateOpts, runtime fills in incrementally.
|
|
88
|
+
// Throw a clear 501 at entry rather than silently downgrading to default behavior —
|
|
89
|
+
// the alternative (ignore unsupported mode) would mask caller mistakes.
|
|
90
|
+
guardUnsupportedModes(opts);
|
|
91
|
+
|
|
92
|
+
const maxIterations = opts.maxToolIterations ?? DEFAULT_MAX_ITERATIONS;
|
|
93
|
+
const maxResultBytes = opts.toolResultMaxBytes ?? DEFAULT_MAX_RESULT_BYTES;
|
|
94
|
+
const handlers = opts.toolHandlers ?? {};
|
|
95
|
+
const parallelism = opts.toolParallelism ?? 'parallel';
|
|
96
|
+
const errorMode = opts.toolErrorMode ?? 'recover';
|
|
97
|
+
const maxToolTokens = opts.maxToolTokens;
|
|
98
|
+
const maxCostUsd = opts.maxCostUsd;
|
|
99
|
+
const conversation = opts.conversation;
|
|
100
|
+
|
|
101
|
+
const { messages, tools, system } = normalizeInput(args.input);
|
|
102
|
+
// Names the CALLER declared as tools (object-form input). Used to split the
|
|
103
|
+
// missing-handler case: a declared tool with no handler is a caller config bug
|
|
104
|
+
// (hard fail); an UNdeclared name is a model hallucination (recover). See
|
|
105
|
+
// `runSingleToolCall`.
|
|
106
|
+
const declaredToolNames = collectDeclaredToolNames(tools);
|
|
107
|
+
const trace: ToolTraceEntry[] = [];
|
|
108
|
+
// Cumulative usage tallies across all iterations of this loop invocation. Used to
|
|
109
|
+
// trip `maxToolTokens` / `maxCostUsd` after each backend round.
|
|
110
|
+
let totalTokens = 0;
|
|
111
|
+
let totalCostUsd = 0;
|
|
112
|
+
// Warn-once latch: a token/cost budget is set but the backend isn't reporting
|
|
113
|
+
// usage, so the cap can't be measured. We refuse to silently pretend it's enforced.
|
|
114
|
+
let budgetUnmeasurableWarned = false;
|
|
115
|
+
|
|
116
|
+
// `conversation` is a one-way SINK for NEW turns produced by this loop — the loop
|
|
117
|
+
// does NOT re-append the caller's input messages, even when they include user
|
|
118
|
+
// turns. Echoing input back into the caller's store would corrupt it (the caller
|
|
119
|
+
// already added their own prompt) and scramble ordering for multi-turn history.
|
|
120
|
+
// The caller owns turn 0; the loop owns whatever assistant/tool turns it produces.
|
|
121
|
+
|
|
122
|
+
// Loop-level abort controller — fired internally on budget trips (commit 4 wires
|
|
123
|
+
// that) and on every loop exit (success, throw, abort) via the `finally` below.
|
|
124
|
+
// Composed with the caller's signal so an external `caller.abort()` ALSO fires
|
|
125
|
+
// the loop's signal (handlers and the in-flight backend call both react). The
|
|
126
|
+
// composed signal is the only signal that flows to inner calls.
|
|
127
|
+
const loopController = new AbortController();
|
|
128
|
+
const composedSignal = composeAbortSignal(callerSignal, loopController.signal);
|
|
129
|
+
|
|
130
|
+
// Strip loop-only knobs from what flows back into `models.generate`. The `toolMode:
|
|
131
|
+
// 'return'` override is what prevents the outer entry point from re-entering this loop.
|
|
132
|
+
// `signal` is swapped to the composed signal so `Models.generate` (and through it,
|
|
133
|
+
// the backend) see budget-trip and caller-abort cancellations the same way.
|
|
134
|
+
const innerOpts: GenerateOpts = { ...opts, toolMode: 'return', signal: composedSignal };
|
|
135
|
+
|
|
136
|
+
try {
|
|
137
|
+
for (let iteration = 1; iteration <= maxIterations; iteration++) {
|
|
138
|
+
// Pre-iteration abort check — if the caller (or a future budget trip) fired
|
|
139
|
+
// the composed signal between rounds, bail before paying for another backend
|
|
140
|
+
// call. The inner `models.generate` would itself throw on the in-flight check,
|
|
141
|
+
// but throwing here saves the round-trip and the spurious analytics row.
|
|
142
|
+
composedSignal.throwIfAborted();
|
|
143
|
+
|
|
144
|
+
const result = await models.generate(buildInnerInput(messages, tools, system), innerOpts);
|
|
145
|
+
|
|
146
|
+
// Re-check abort the instant the backend round returns, BEFORE any budget
|
|
147
|
+
// accounting, assistant append, or tool dispatch. A well-behaved backend
|
|
148
|
+
// throws on an in-flight abort; an ill-behaved one (community backend that
|
|
149
|
+
// ignores its signal) can resolve normally after the caller aborted. Without
|
|
150
|
+
// this check the loop would run side-effecting handlers for a cancelled
|
|
151
|
+
// request and then misreport the outcome as a budget/tool error instead of
|
|
152
|
+
// an abort.
|
|
153
|
+
composedSignal.throwIfAborted();
|
|
154
|
+
|
|
155
|
+
logger.debug?.(
|
|
156
|
+
`[models] auto-loop iteration ${iteration}: finishReason=${result.finishReason} toolCalls=${result.toolCalls?.length ?? 0} cumulativeTokens=${totalTokens}`
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
// A token/cost budget is only as good as the backend's usage reporting. If a
|
|
160
|
+
// cap is set but this round reported no usage, the cap is unmeasurable — warn
|
|
161
|
+
// once rather than letting the caller believe spend is bounded when it isn't.
|
|
162
|
+
if (
|
|
163
|
+
(maxToolTokens !== undefined || maxCostUsd !== undefined) &&
|
|
164
|
+
result.usage === undefined &&
|
|
165
|
+
!budgetUnmeasurableWarned
|
|
166
|
+
) {
|
|
167
|
+
budgetUnmeasurableWarned = true;
|
|
168
|
+
logger.warn?.(
|
|
169
|
+
`[models] auto-loop token/cost budget set but backend '${opts.model ?? 'default'}' reported no usage; budget is unenforceable for this run (maxToolIterations still applies)`
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Tally this round's usage BEFORE deciding terminal vs continue. A round
|
|
174
|
+
// that crosses the cap trips even if it would otherwise have been the last
|
|
175
|
+
// one — the cap is on what we paid for, not on what we'd have paid for next.
|
|
176
|
+
// Cost trip semantics: `>= cap`, so `maxCostUsd: 0` blocks every call rather
|
|
177
|
+
// than dormantly admitting all of them until a real rate card lands and then
|
|
178
|
+
// abruptly blocking everything. Token trip uses `>=` for symmetry.
|
|
179
|
+
//
|
|
180
|
+
// Discarded-content asymmetry: a TERMINAL round that trips returns
|
|
181
|
+
// BudgetExceededError instead of the final assistant content. The content is
|
|
182
|
+
// in `messages` (the loop's running state) but neither `partialTrace` nor the
|
|
183
|
+
// thrown error surfaces it. Callers that need terminal content even on
|
|
184
|
+
// budget-trip should set `maxToolTokens` / `maxCostUsd` conservatively or read
|
|
185
|
+
// the per-iteration analytics rows (one row per round in `hdb_model_calls`).
|
|
186
|
+
totalTokens += sumTokens(result.usage);
|
|
187
|
+
totalCostUsd += computeCallCostUsd(result.usage, opts.model);
|
|
188
|
+
if (maxToolTokens !== undefined && totalTokens >= maxToolTokens) {
|
|
189
|
+
throw new BudgetExceededError(
|
|
190
|
+
'tokens',
|
|
191
|
+
`agent loop exceeded maxToolTokens=${maxToolTokens} (cumulative=${totalTokens})`,
|
|
192
|
+
trace
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
if (maxCostUsd !== undefined && totalCostUsd >= maxCostUsd) {
|
|
196
|
+
throw new BudgetExceededError(
|
|
197
|
+
'cost',
|
|
198
|
+
`agent loop exceeded maxCostUsd=${maxCostUsd} (cumulative=${totalCostUsd})`,
|
|
199
|
+
trace
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const calls = result.toolCalls;
|
|
204
|
+
// Backends (notably OpenAI) leave `content` as `null` / undefined on tool-call
|
|
205
|
+
// rounds. `Message.content` and `ConversationTurn.content` are typed as a
|
|
206
|
+
// required string — coerce to '' at the seam.
|
|
207
|
+
const assistantContent = result.content ?? '';
|
|
208
|
+
if (result.finishReason !== 'tool_calls' || !calls || calls.length === 0) {
|
|
209
|
+
// Terminal: model produced a final answer (stop / length / content_filter), or it
|
|
210
|
+
// signaled tool_calls but emitted none. Append final assistant turn to the
|
|
211
|
+
// conversation hook (if set), then pass the result through; attach the trace
|
|
212
|
+
// when the caller asked for it.
|
|
213
|
+
if (conversation && assistantContent) {
|
|
214
|
+
await conversation.append({ role: 'assistant', content: assistantContent });
|
|
215
|
+
}
|
|
216
|
+
// A `tool_calls` finishReason with no dispatchable calls (e.g. the backend
|
|
217
|
+
// dropped malformed tool-call args) is terminal — coerce it to 'stop' so an
|
|
218
|
+
// auto-mode caller never sees a `tool_calls` finishReason (auto resolves calls
|
|
219
|
+
// internally) pointing at calls that aren't there, and never a `null` content.
|
|
220
|
+
// Mirrors the streaming path's terminalReason fold.
|
|
221
|
+
const terminal: GenerateResult =
|
|
222
|
+
result.finishReason === 'tool_calls'
|
|
223
|
+
? { ...result, finishReason: 'stop', content: assistantContent }
|
|
224
|
+
: result;
|
|
225
|
+
return opts.includeToolTrace ? { ...terminal, trace } : terminal;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
messages.push({ role: 'assistant', content: assistantContent, toolCalls: calls });
|
|
229
|
+
if (conversation) {
|
|
230
|
+
await conversation.append({
|
|
231
|
+
role: 'assistant',
|
|
232
|
+
content: assistantContent,
|
|
233
|
+
toolCalls: calls,
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const ctx: ToolHandlerContext = { signal: composedSignal, accounting };
|
|
238
|
+
const dispatched = await dispatchToolCalls(
|
|
239
|
+
calls,
|
|
240
|
+
handlers,
|
|
241
|
+
declaredToolNames,
|
|
242
|
+
ctx,
|
|
243
|
+
iteration,
|
|
244
|
+
maxResultBytes,
|
|
245
|
+
parallelism
|
|
246
|
+
);
|
|
247
|
+
|
|
248
|
+
// Post-dispatch abort check — covers the LAST-iteration case: if the signal
|
|
249
|
+
// fired during this round's handlers, we'd otherwise skip the top-of-loop check
|
|
250
|
+
// and throw `BudgetExceededError` (misleading: the budget never tripped). Fire
|
|
251
|
+
// the abort here so the caller gets the correct error class. Earlier iterations
|
|
252
|
+
// pick this up on the next round's top-of-loop check.
|
|
253
|
+
composedSignal.throwIfAborted();
|
|
254
|
+
|
|
255
|
+
// Trace + the in-memory message list always record every tool result in CALL
|
|
256
|
+
// order (the trace mirrors what the model emitted, not which handler finished
|
|
257
|
+
// first). The EXTERNAL conversation sink is handled separately below so the
|
|
258
|
+
// abort-mode throw can run BEFORE we persist turns the model never consumes.
|
|
259
|
+
for (const dispatchResult of dispatched) {
|
|
260
|
+
trace.push(dispatchResult.entry);
|
|
261
|
+
messages.push({
|
|
262
|
+
role: 'tool',
|
|
263
|
+
content: dispatchResult.toolMessageContent,
|
|
264
|
+
toolCallId: dispatchResult.entry.toolCallId,
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// `toolErrorMode: 'abort'`: any handler failure terminates the loop. Throw
|
|
269
|
+
// BEFORE the conversation sink sees this round's tool turns — abort mode
|
|
270
|
+
// returns the error to the caller instead of recovering, so persisting a
|
|
271
|
+
// recover-style tool-error turn the model never reads would leave the store
|
|
272
|
+
// inconsistent with what actually happened. The trace (built above) still
|
|
273
|
+
// carries the failing entry via `ToolHandlerError.partialTrace`.
|
|
274
|
+
if (errorMode === 'abort') {
|
|
275
|
+
const failed = dispatched.find((d) => d.originalError !== undefined);
|
|
276
|
+
if (failed) {
|
|
277
|
+
throw new ToolHandlerError(failed.entry.toolName, failed.entry.toolCallId, trace, failed.originalError);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// Continue path: persist this round's tool turns to the conversation sink.
|
|
282
|
+
if (conversation) {
|
|
283
|
+
for (const dispatchResult of dispatched) {
|
|
284
|
+
await conversation.append({
|
|
285
|
+
role: 'tool',
|
|
286
|
+
toolCallId: dispatchResult.entry.toolCallId,
|
|
287
|
+
content: dispatchResult.toolMessageContent,
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// Hit `maxToolIterations` without a terminal finishReason — the model kept calling tools.
|
|
294
|
+
// Always include the trace on the error path (independent of `includeToolTrace`) so
|
|
295
|
+
// callers can debug an exhausted budget without re-running with tracing on.
|
|
296
|
+
throw new BudgetExceededError('iterations', `agent loop exceeded maxToolIterations=${maxIterations}`, trace);
|
|
297
|
+
} finally {
|
|
298
|
+
// Always abort the loop controller on exit (success, throw, or external abort).
|
|
299
|
+
// Cleans up `AbortSignal.any`'s listener on `callerSignal` so a session-scoped caller
|
|
300
|
+
// signal doesn't accumulate listeners across many `runAgentLoop` invocations, and
|
|
301
|
+
// signals any sibling handlers still running in the background after a Promise.all
|
|
302
|
+
// rejection (missing-handler or aborted-mid-flight) to bail out promptly.
|
|
303
|
+
loopController.abort();
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
interface DispatchedToolCall {
|
|
308
|
+
entry: ToolTraceEntry;
|
|
309
|
+
toolMessageContent: string;
|
|
310
|
+
/**
|
|
311
|
+
* The original thrown value when the handler / serialization failed and recover
|
|
312
|
+
* mode caught it. Preserved alongside the formatted `entry.error` so abort mode
|
|
313
|
+
* can surface the cause unmodified via `ToolHandlerError.cause`. Undefined when
|
|
314
|
+
* the handler succeeded.
|
|
315
|
+
*/
|
|
316
|
+
originalError?: unknown;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
async function dispatchToolCalls(
|
|
320
|
+
calls: ToolCall[],
|
|
321
|
+
handlers: Record<string, ToolHandler>,
|
|
322
|
+
declaredToolNames: Set<string>,
|
|
323
|
+
ctx: ToolHandlerContext,
|
|
324
|
+
iteration: number,
|
|
325
|
+
maxResultBytes: number,
|
|
326
|
+
parallelism: 'parallel' | 'serial'
|
|
327
|
+
): Promise<DispatchedToolCall[]> {
|
|
328
|
+
// Single-call rounds use the serial path even when 'parallel' is selected — the
|
|
329
|
+
// settled-wrapping path adds nothing on one element and the serial path's stack
|
|
330
|
+
// trace is more readable in errors.
|
|
331
|
+
if (parallelism === 'serial' || calls.length <= 1) {
|
|
332
|
+
const out: DispatchedToolCall[] = [];
|
|
333
|
+
for (const call of calls) {
|
|
334
|
+
out.push(await runSingleToolCall(call, handlers, declaredToolNames, ctx, iteration, maxResultBytes));
|
|
335
|
+
}
|
|
336
|
+
return out;
|
|
337
|
+
}
|
|
338
|
+
// Parallel: handlers race concurrently. `runSingleToolCall` only throws on missing
|
|
339
|
+
// handler or cooperative abort — handler errors are caught inline and surface via
|
|
340
|
+
// `originalError`. `Promise.all` rejects on first throw, which is what we want for
|
|
341
|
+
// those two cases: surface the throw immediately so the loop's `finally` can fire
|
|
342
|
+
// `loopController.abort` and cancel siblings still in flight, instead of waiting
|
|
343
|
+
// for every sibling to complete (which `Promise.allSettled` would force).
|
|
344
|
+
//
|
|
345
|
+
// Concurrent-rejection caveat: when MULTIPLE siblings reject at the same time
|
|
346
|
+
// (e.g. several missing handlers, or several handlers reacting to a cooperative
|
|
347
|
+
// abort), `Promise.all` only awaits the first rejection — the rest become
|
|
348
|
+
// unhandled-rejection warnings (and crash under `--unhandled-rejections=throw`).
|
|
349
|
+
// Attach a no-op catch to each promise so the runtime sees every rejection as
|
|
350
|
+
// handled while still letting `Promise.all` settle on the first one.
|
|
351
|
+
const promises = calls.map((call) =>
|
|
352
|
+
runSingleToolCall(call, handlers, declaredToolNames, ctx, iteration, maxResultBytes)
|
|
353
|
+
);
|
|
354
|
+
for (const p of promises) p.catch(() => {});
|
|
355
|
+
return Promise.all(promises);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
async function runSingleToolCall(
|
|
359
|
+
call: ToolCall,
|
|
360
|
+
handlers: Record<string, ToolHandler>,
|
|
361
|
+
declaredToolNames: Set<string>,
|
|
362
|
+
ctx: ToolHandlerContext,
|
|
363
|
+
iteration: number,
|
|
364
|
+
maxResultBytes: number
|
|
365
|
+
): Promise<DispatchedToolCall> {
|
|
366
|
+
const entry: ToolTraceEntry = {
|
|
367
|
+
iteration,
|
|
368
|
+
toolCallId: call.id,
|
|
369
|
+
toolName: call.name,
|
|
370
|
+
// Shallow-copy so the trace's view of "what the model emitted" doesn't shift if a
|
|
371
|
+
// handler mutates its `args` parameter (legitimate pattern). Deep mutations to
|
|
372
|
+
// nested objects can still leak — common-case flat-object args are covered.
|
|
373
|
+
arguments: { ...call.arguments },
|
|
374
|
+
durationMs: 0,
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
// Handler resolution. Use `Object.hasOwn` + a callable check rather than a plain
|
|
378
|
+
// `handlers[call.name]` lookup: a model can emit a tool name that collides with an
|
|
379
|
+
// inherited Object prototype member (`toString`, `constructor`, `__proto__`, ...),
|
|
380
|
+
// and a bare index would resolve that built-in as a "handler" and invoke it. Model
|
|
381
|
+
// output is untrusted input at this boundary — only an own, callable property counts.
|
|
382
|
+
const handler =
|
|
383
|
+
Object.hasOwn(handlers, call.name) && typeof handlers[call.name] === 'function' ? handlers[call.name] : undefined;
|
|
384
|
+
if (!handler) {
|
|
385
|
+
if (declaredToolNames.has(call.name)) {
|
|
386
|
+
// The caller DECLARED this tool but supplied no (callable) handler for it.
|
|
387
|
+
// That's a caller config bug, not something the model can recover from —
|
|
388
|
+
// hard fail. (#615 swaps this lookup for a `scope.resources` registry
|
|
389
|
+
// resolution; same split — resolvable-but-misconfigured stays a hard fail.)
|
|
390
|
+
throw new ClientError(`No handler registered for declared tool '${call.name}' (call id ${call.id})`, 400);
|
|
391
|
+
}
|
|
392
|
+
// Undeclared tool name: the model hallucinated a tool that doesn't exist. This is
|
|
393
|
+
// the EXPECTED failure mode for an LLM, not a caller fault — surface it as a
|
|
394
|
+
// recoverable tool error so `toolErrorMode: 'recover'` feeds it back and the model
|
|
395
|
+
// can self-correct, while `'abort'` (via `originalError`) still stops the loop.
|
|
396
|
+
logger.warn?.(
|
|
397
|
+
`[models] auto-loop: model called unknown tool '${call.name}' (call id ${call.id}); no such tool declared`
|
|
398
|
+
);
|
|
399
|
+
const unknownToolError = new ClientError(`Unknown tool '${call.name}': no such tool is available`, 400);
|
|
400
|
+
entry.error = errorInfo(unknownToolError);
|
|
401
|
+
return {
|
|
402
|
+
entry,
|
|
403
|
+
toolMessageContent: JSON.stringify({ error: entry.error.message }),
|
|
404
|
+
originalError: unknownToolError,
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
const handlerStart = performance.now();
|
|
409
|
+
let toolMessageContent: string;
|
|
410
|
+
let originalError: unknown;
|
|
411
|
+
// Wrap BOTH the handler call AND result serialization in the recover catch.
|
|
412
|
+
// `JSON.stringify` throws on BigInt and circular refs — both trivially produced by
|
|
413
|
+
// handlers that return raw DB rows or Resource instances. Without this, a
|
|
414
|
+
// serialization failure crashes the entire loop instead of becoming a tool error
|
|
415
|
+
// the model can react to (the `toolErrorMode: 'recover'` contract).
|
|
416
|
+
try {
|
|
417
|
+
const handlerOutput = await handler(call.arguments, ctx);
|
|
418
|
+
const serialized = serializeToolResult(handlerOutput, maxResultBytes);
|
|
419
|
+
entry.result = serialized.content;
|
|
420
|
+
if (serialized.truncated) {
|
|
421
|
+
entry.truncated = true;
|
|
422
|
+
entry.totalBytes = serialized.totalBytes;
|
|
423
|
+
}
|
|
424
|
+
toolMessageContent = serialized.content;
|
|
425
|
+
} catch (err) {
|
|
426
|
+
// Cooperative cancellation is NOT a tool error — rethrow so the loop's
|
|
427
|
+
// abort path (top-of-loop / post-dispatch `throwIfAborted`) classifies it
|
|
428
|
+
// correctly. Without this, AbortError would land in `entry.error` and the
|
|
429
|
+
// caller would see `BudgetExceededError` on the last iteration, or a
|
|
430
|
+
// bogus `{error: 'aborted'}` tool message threaded into the conversation.
|
|
431
|
+
// The trace entry is abandoned (the loop builds an aborted-path trace later).
|
|
432
|
+
if (ctx.signal?.aborted) throw err;
|
|
433
|
+
// Handler error. Populate entry.error so the trace records the failure, build
|
|
434
|
+
// the recover-mode tool-message envelope, and stash the original throw so
|
|
435
|
+
// `toolErrorMode: 'abort'` (checked in the main loop after dispatch) can
|
|
436
|
+
// surface the cause unmodified.
|
|
437
|
+
originalError = err;
|
|
438
|
+
entry.error = errorInfo(err);
|
|
439
|
+
toolMessageContent = JSON.stringify({ error: entry.error.message });
|
|
440
|
+
}
|
|
441
|
+
entry.durationMs = performance.now() - handlerStart;
|
|
442
|
+
|
|
443
|
+
return { entry, toolMessageContent, originalError };
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* Mirror of `backendHelpers.composeSignal` but composing a caller signal with an
|
|
448
|
+
* INTERNAL controller's signal (not a timeout). Returns the internal signal alone
|
|
449
|
+
* when no caller signal exists, the caller signal alone when no internal controller
|
|
450
|
+
* is needed (today never — we always create one), and a composed signal otherwise.
|
|
451
|
+
*
|
|
452
|
+
* `AbortSignal.any` requires Node 20+, which matches Harper's engines floor.
|
|
453
|
+
*/
|
|
454
|
+
function composeAbortSignal(caller: AbortSignal | undefined, internal: AbortSignal): AbortSignal {
|
|
455
|
+
if (!caller) return internal;
|
|
456
|
+
return AbortSignal.any([caller, internal]);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
export async function* runAgentLoopStream(args: RunAgentLoopArgs): AsyncIterable<GenerateChunk> {
|
|
460
|
+
const { models, opts, accounting, signal: callerSignal } = args;
|
|
461
|
+
|
|
462
|
+
guardUnsupportedModes(opts);
|
|
463
|
+
|
|
464
|
+
const maxIterations = opts.maxToolIterations ?? DEFAULT_MAX_ITERATIONS;
|
|
465
|
+
const maxResultBytes = opts.toolResultMaxBytes ?? DEFAULT_MAX_RESULT_BYTES;
|
|
466
|
+
const handlers = opts.toolHandlers ?? {};
|
|
467
|
+
const parallelism = opts.toolParallelism ?? 'parallel';
|
|
468
|
+
const errorMode = opts.toolErrorMode ?? 'recover';
|
|
469
|
+
const conversation = opts.conversation;
|
|
470
|
+
// Streaming + token/cost budgets: backends don't emit `usage` on `GenerateChunk`
|
|
471
|
+
// in v1 (the type has no `usage` field on chunks), so cumulative usage isn't
|
|
472
|
+
// observable from the stream. The iteration budget still applies. Wiring
|
|
473
|
+
// streaming budgets requires extending `GenerateChunk` and updating each
|
|
474
|
+
// backend's stream-final-chunk handling — a follow-up to this PR.
|
|
475
|
+
if (opts.maxToolTokens !== undefined || opts.maxCostUsd !== undefined) {
|
|
476
|
+
throw new ServerError(
|
|
477
|
+
`maxToolTokens / maxCostUsd are not yet supported for generateStream (streamed usage not exposed in v1)`,
|
|
478
|
+
501
|
|
479
|
+
);
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
const { messages, tools, system } = normalizeInput(args.input);
|
|
483
|
+
const declaredToolNames = collectDeclaredToolNames(tools);
|
|
484
|
+
const trace: ToolTraceEntry[] = [];
|
|
485
|
+
|
|
486
|
+
const loopController = new AbortController();
|
|
487
|
+
const composedSignal = composeAbortSignal(callerSignal, loopController.signal);
|
|
488
|
+
const innerOpts: GenerateOpts = { ...opts, toolMode: 'return', signal: composedSignal };
|
|
489
|
+
|
|
490
|
+
// `conversation` is a one-way SINK for NEW turns produced by this loop — see
|
|
491
|
+
// `runAgentLoop` for the rationale. Streaming path applies the same contract.
|
|
492
|
+
|
|
493
|
+
try {
|
|
494
|
+
for (let iteration = 1; iteration <= maxIterations; iteration++) {
|
|
495
|
+
composedSignal.throwIfAborted();
|
|
496
|
+
|
|
497
|
+
// Stream this round: yield content + tool-call deltas to the caller as they
|
|
498
|
+
// arrive, while internally assembling the round's content and tool-call shape.
|
|
499
|
+
let accumulatedContent = '';
|
|
500
|
+
const toolCallAssembly = new Map<string, Partial<ToolCall>>();
|
|
501
|
+
let finishReason: GenerateResult['finishReason'] | undefined;
|
|
502
|
+
|
|
503
|
+
const stream = models.generateStream(buildInnerInput(messages, tools, system), innerOpts);
|
|
504
|
+
for await (const chunk of stream) {
|
|
505
|
+
// Defense-in-depth: well-behaved backends honor `opts.signal` via the
|
|
506
|
+
// fetch they hand it to. An ill-behaved community backend that doesn't
|
|
507
|
+
// observe its signal would otherwise keep streaming after a caller abort.
|
|
508
|
+
composedSignal.throwIfAborted();
|
|
509
|
+
|
|
510
|
+
if (chunk.deltaContent !== undefined) {
|
|
511
|
+
accumulatedContent += chunk.deltaContent;
|
|
512
|
+
}
|
|
513
|
+
if (chunk.deltaToolCalls) {
|
|
514
|
+
for (const delta of chunk.deltaToolCalls) {
|
|
515
|
+
mergeToolCallDelta(toolCallAssembly, delta);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
if (chunk.finishReason) {
|
|
519
|
+
finishReason = chunk.finishReason;
|
|
520
|
+
}
|
|
521
|
+
// `finishReason` is an INTERNAL signal — never forward it inline. We re-emit
|
|
522
|
+
// exactly one terminal chunk after the loop, AFTER the terminal turn has been
|
|
523
|
+
// appended to the conversation sink (see below). Forwarding it here would let a
|
|
524
|
+
// consumer that stops on the first finish-reason chunk close this generator at
|
|
525
|
+
// the `yield` before the append runs, delivering a response that never persists.
|
|
526
|
+
// The deltas (content / tool-call shape) still flow through untouched.
|
|
527
|
+
if (chunk.deltaContent !== undefined || chunk.deltaToolCalls) {
|
|
528
|
+
const cleaned: GenerateChunk = {};
|
|
529
|
+
if (chunk.deltaContent !== undefined) cleaned.deltaContent = chunk.deltaContent;
|
|
530
|
+
if (chunk.deltaToolCalls) cleaned.deltaToolCalls = chunk.deltaToolCalls;
|
|
531
|
+
yield cleaned;
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
const finalToolCalls = completeToolCallAssembly(toolCallAssembly);
|
|
536
|
+
// Surface any assembled-but-incomplete tool calls (id arrived, name never did)
|
|
537
|
+
// instead of silently dropping them. `completeToolCallAssembly` keeps only
|
|
538
|
+
// dispatchable (id + name) calls; a missing-name partial usually means a
|
|
539
|
+
// truncated stream. Record it in the trace + warn so the drop is observable.
|
|
540
|
+
if (finalToolCalls.length < toolCallAssembly.size) {
|
|
541
|
+
for (const [id, partial] of toolCallAssembly) {
|
|
542
|
+
if (!partial.name) {
|
|
543
|
+
logger.warn?.(
|
|
544
|
+
`[models] auto-loop: dropping incomplete streamed tool call id=${id} (no tool name assembled; stream likely truncated)`
|
|
545
|
+
);
|
|
546
|
+
trace.push({
|
|
547
|
+
iteration,
|
|
548
|
+
toolCallId: id,
|
|
549
|
+
toolName: '<incomplete>',
|
|
550
|
+
arguments: partial.arguments ?? {},
|
|
551
|
+
durationMs: 0,
|
|
552
|
+
error: { name: 'IncompleteToolCall', message: 'streamed tool call missing name; dropped' },
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
logger.debug?.(
|
|
559
|
+
`[models] auto-loop stream iteration ${iteration}: finishReason=${finishReason ?? 'none'} toolCalls=${finalToolCalls.length}`
|
|
560
|
+
);
|
|
561
|
+
|
|
562
|
+
// Continue-vs-terminal:
|
|
563
|
+
// - Hand off to tool dispatch when calls assembled AND the backend signalled
|
|
564
|
+
// tool_calls OR didn't signal anything at all. The "no finishReason" case
|
|
565
|
+
// covers proxy-truncated streams: every in-tree backend (openai, anthropic,
|
|
566
|
+
// bedrock) emits a tail-flush `deltaToolCalls` without a finishReason when
|
|
567
|
+
// the upstream connection drops mid-stream. Treating that as terminal would
|
|
568
|
+
// silently drop the assembled tool calls — the backend's recovery would be
|
|
569
|
+
// undone by this loop.
|
|
570
|
+
// - Otherwise, terminal: yield a synthetic 'stop' chunk if the consumer didn't
|
|
571
|
+
// receive a terminal finishReason inline (degenerate streams, or the
|
|
572
|
+
// suppressed `tool_calls` finishReason with zero assembled calls).
|
|
573
|
+
const hasToolCalls = finalToolCalls.length > 0;
|
|
574
|
+
const continueWithToolCalls = hasToolCalls && (finishReason === 'tool_calls' || finishReason === undefined);
|
|
575
|
+
|
|
576
|
+
if (!continueWithToolCalls) {
|
|
577
|
+
// Terminal. Persist the final assistant turn to the conversation sink FIRST,
|
|
578
|
+
// then emit exactly one terminal chunk. Because the loop suppressed every
|
|
579
|
+
// inline finishReason, this `yield` is the only finish-reason the consumer
|
|
580
|
+
// sees — and it lands after the append, so a consumer that stops on it cannot
|
|
581
|
+
// race past the persistence.
|
|
582
|
+
if (conversation && accumulatedContent) {
|
|
583
|
+
await conversation.append({ role: 'assistant', content: accumulatedContent });
|
|
584
|
+
}
|
|
585
|
+
// `tool_calls` with zero dispatchable calls can't honestly be reported as the
|
|
586
|
+
// terminal reason (there are no calls); fold it and the no-signal case to 'stop'.
|
|
587
|
+
const terminalReason = finishReason && finishReason !== 'tool_calls' ? finishReason : 'stop';
|
|
588
|
+
yield { finishReason: terminalReason };
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
// Continue the loop: dispatch tools, append messages, resume on next iteration.
|
|
593
|
+
const assistantMessage: Message = {
|
|
594
|
+
role: 'assistant',
|
|
595
|
+
content: accumulatedContent,
|
|
596
|
+
toolCalls: finalToolCalls,
|
|
597
|
+
};
|
|
598
|
+
messages.push(assistantMessage);
|
|
599
|
+
if (conversation) {
|
|
600
|
+
await conversation.append({
|
|
601
|
+
role: 'assistant',
|
|
602
|
+
content: accumulatedContent,
|
|
603
|
+
toolCalls: finalToolCalls,
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
const ctx: ToolHandlerContext = { signal: composedSignal, accounting };
|
|
608
|
+
const dispatched = await dispatchToolCalls(
|
|
609
|
+
finalToolCalls,
|
|
610
|
+
handlers,
|
|
611
|
+
declaredToolNames,
|
|
612
|
+
ctx,
|
|
613
|
+
iteration,
|
|
614
|
+
maxResultBytes,
|
|
615
|
+
parallelism
|
|
616
|
+
);
|
|
617
|
+
|
|
618
|
+
composedSignal.throwIfAborted();
|
|
619
|
+
|
|
620
|
+
// Trace + in-memory messages always record every result; the external
|
|
621
|
+
// conversation sink is deferred past the abort-mode throw (same rationale as
|
|
622
|
+
// the sync path — don't persist tool turns the model never consumes on abort).
|
|
623
|
+
for (const d of dispatched) {
|
|
624
|
+
trace.push(d.entry);
|
|
625
|
+
messages.push({
|
|
626
|
+
role: 'tool',
|
|
627
|
+
content: d.toolMessageContent,
|
|
628
|
+
toolCallId: d.entry.toolCallId,
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
if (errorMode === 'abort') {
|
|
633
|
+
const failed = dispatched.find((d) => d.originalError !== undefined);
|
|
634
|
+
if (failed) {
|
|
635
|
+
throw new ToolHandlerError(failed.entry.toolName, failed.entry.toolCallId, trace, failed.originalError);
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
if (conversation) {
|
|
640
|
+
for (const d of dispatched) {
|
|
641
|
+
await conversation.append({
|
|
642
|
+
role: 'tool',
|
|
643
|
+
toolCallId: d.entry.toolCallId,
|
|
644
|
+
content: d.toolMessageContent,
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
throw new BudgetExceededError('iterations', `agent loop exceeded maxToolIterations=${maxIterations}`, trace);
|
|
651
|
+
} finally {
|
|
652
|
+
loopController.abort();
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
/**
|
|
657
|
+
* Update the in-flight assembly map with one streamed tool-call delta. Streaming
|
|
658
|
+
* backends may send the same `id` multiple times with partial `name` / `arguments`;
|
|
659
|
+
* we merge them in arrival order. Some backends pre-assemble and send the full
|
|
660
|
+
* call as a single delta — same code path, single update.
|
|
661
|
+
*
|
|
662
|
+
* Backends that stream `arguments` as accumulating JSON string fragments must
|
|
663
|
+
* parse before yielding (delta.arguments is typed as `object`); shape assembly
|
|
664
|
+
* lives in this loop, fragment assembly lives in the backend.
|
|
665
|
+
*/
|
|
666
|
+
function mergeToolCallDelta(map: Map<string, Partial<ToolCall>>, delta: Partial<ToolCall>): void {
|
|
667
|
+
if (!delta.id) return;
|
|
668
|
+
const existing: Partial<ToolCall> = map.get(delta.id) ?? { id: delta.id };
|
|
669
|
+
if (delta.name) existing.name = delta.name;
|
|
670
|
+
if (delta.arguments) {
|
|
671
|
+
existing.arguments = { ...existing.arguments, ...delta.arguments };
|
|
672
|
+
}
|
|
673
|
+
map.set(delta.id, existing);
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
function completeToolCallAssembly(map: Map<string, Partial<ToolCall>>): ToolCall[] {
|
|
677
|
+
const out: ToolCall[] = [];
|
|
678
|
+
for (const partial of map.values()) {
|
|
679
|
+
if (partial.id && partial.name) {
|
|
680
|
+
out.push({
|
|
681
|
+
id: partial.id,
|
|
682
|
+
name: partial.name,
|
|
683
|
+
arguments: partial.arguments ?? {},
|
|
684
|
+
});
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
return out;
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
function guardUnsupportedModes(opts: GenerateOpts): void {
|
|
691
|
+
const validationMode = opts.toolArgValidation ?? 'none';
|
|
692
|
+
if (validationMode !== 'none') {
|
|
693
|
+
throw new ServerError(
|
|
694
|
+
`toolArgValidation: '${validationMode}' is not yet implemented; v1 supports 'none' only`,
|
|
695
|
+
501
|
|
696
|
+
);
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
function buildInnerInput(
|
|
701
|
+
messages: Message[],
|
|
702
|
+
tools: ToolDef[] | undefined,
|
|
703
|
+
system: string | undefined
|
|
704
|
+
): { messages: Message[]; tools?: ToolDef[]; system?: string } {
|
|
705
|
+
const inner: { messages: Message[]; tools?: ToolDef[]; system?: string } = { messages };
|
|
706
|
+
if (tools) inner.tools = tools;
|
|
707
|
+
if (system) inner.system = system;
|
|
708
|
+
return inner;
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
function normalizeInput(input: GenerateInput): {
|
|
712
|
+
messages: Message[];
|
|
713
|
+
tools?: ToolDef[];
|
|
714
|
+
system?: string;
|
|
715
|
+
} {
|
|
716
|
+
if (typeof input === 'string') {
|
|
717
|
+
return { messages: [{ role: 'user', content: input }] };
|
|
718
|
+
}
|
|
719
|
+
if (Array.isArray(input)) {
|
|
720
|
+
return { messages: [...input] };
|
|
721
|
+
}
|
|
722
|
+
return { messages: [...input.messages], tools: input.tools, system: input.system };
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
function collectDeclaredToolNames(tools: ToolDef[] | undefined): Set<string> {
|
|
726
|
+
const names = new Set<string>();
|
|
727
|
+
if (tools) for (const t of tools) names.add(t.name);
|
|
728
|
+
return names;
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
function errorInfo(err: unknown): { name: string; message: string } {
|
|
732
|
+
if (err instanceof Error) {
|
|
733
|
+
return { name: err.name, message: err.message };
|
|
734
|
+
}
|
|
735
|
+
// Some thrown values are plain objects with a `message` field but no Error chain —
|
|
736
|
+
// e.g. Harper's `BigInt.prototype.toJSON` throws `{message: 'Cannot serialize BigInt …'}`
|
|
737
|
+
// (server/serverHelpers/JSONStream.ts) to skip the cost of capturing a stack on a hot
|
|
738
|
+
// serialization path. Surface their message instead of String()-ing the whole object.
|
|
739
|
+
if (err && typeof err === 'object' && 'message' in err) {
|
|
740
|
+
const e = err as { name?: unknown; message?: unknown };
|
|
741
|
+
const name = typeof e.name === 'string' ? e.name : 'Error';
|
|
742
|
+
const message = typeof e.message === 'string' ? e.message : String(e.message);
|
|
743
|
+
return { name, message };
|
|
744
|
+
}
|
|
745
|
+
return { name: 'Error', message: String(err) };
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
interface SerializedResult {
|
|
749
|
+
content: string;
|
|
750
|
+
totalBytes: number;
|
|
751
|
+
truncated: boolean;
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
function serializeToolResult(value: unknown, maxBytes: number): SerializedResult {
|
|
755
|
+
// `JSON.stringify(Symbol())` (and `JSON.stringify(function(){})`) return `undefined`.
|
|
756
|
+
// `value ?? null` only catches null/undefined inputs, not unsupported types — fall
|
|
757
|
+
// back to the string 'null' so downstream `Buffer.byteLength` never sees undefined.
|
|
758
|
+
const json = JSON.stringify(value ?? null) ?? 'null';
|
|
759
|
+
const totalBytes = Buffer.byteLength(json, 'utf8');
|
|
760
|
+
// Common case: result fits. Skip buffer allocation entirely — read byte length
|
|
761
|
+
// without materializing a copy.
|
|
762
|
+
if (totalBytes <= maxBytes) {
|
|
763
|
+
return { content: json, totalBytes, truncated: false };
|
|
764
|
+
}
|
|
765
|
+
// Truncated form: head of the JSON + a marker that names the original size. The
|
|
766
|
+
// content is no longer valid JSON — that's intentional, the model reads it as text
|
|
767
|
+
// alongside the marker. Pre-slice the JSON string by CHARACTERS to `headBudget`
|
|
768
|
+
// before converting to a Buffer — any character takes at least one UTF-8 byte, so
|
|
769
|
+
// the pre-sliced string already fits in (4 * headBudget) bytes worst-case. Without
|
|
770
|
+
// this, a multi-MB JSON result would materialize a multi-MB Buffer copy just to
|
|
771
|
+
// throw away >99 % of it via `subarray`. After conversion, `subarray(0, headBudget)`
|
|
772
|
+
// trims to exact byte budget; `toString('utf8')` folds a split codepoint at the
|
|
773
|
+
// boundary into U+FFFD.
|
|
774
|
+
const marker = `…[truncated; full result is ${totalBytes} bytes]`;
|
|
775
|
+
const markerBytes = Buffer.byteLength(marker, 'utf8');
|
|
776
|
+
const headBudget = Math.max(0, maxBytes - markerBytes);
|
|
777
|
+
const buf = Buffer.from(json.slice(0, headBudget), 'utf8');
|
|
778
|
+
const body = buf.subarray(0, headBudget).toString('utf8');
|
|
779
|
+
return { content: body + marker, totalBytes, truncated: true };
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
/**
|
|
783
|
+
* Loop tripped one of its budgets (iterations, tokens, cost). The trace built so
|
|
784
|
+
* far rides along on `partialTrace` so callers can inspect what already ran. The
|
|
785
|
+
* loop always populates this regardless of `opts.includeToolTrace` so debugging an
|
|
786
|
+
* exhausted budget never needs a second run with tracing turned on.
|
|
787
|
+
*
|
|
788
|
+
* Extends `ClientError` — the caller set the budget, so exceeding it is a 4xx
|
|
789
|
+
* caller-bounds condition, not a Harper-internal fault. Anything that branches on
|
|
790
|
+
* `err instanceof ClientError` (e.g. "don't page on this") classifies it correctly.
|
|
791
|
+
*/
|
|
792
|
+
export class BudgetExceededError extends ClientError {
|
|
793
|
+
kind: 'iterations' | 'tokens' | 'cost';
|
|
794
|
+
partialTrace: ToolTraceEntry[];
|
|
795
|
+
constructor(kind: 'iterations' | 'tokens' | 'cost', message: string, partialTrace: ToolTraceEntry[]) {
|
|
796
|
+
// 429 (Too Many Requests) maps cleanest to "you exceeded the budget you set".
|
|
797
|
+
super(message, 429);
|
|
798
|
+
this.name = 'BudgetExceededError';
|
|
799
|
+
this.kind = kind;
|
|
800
|
+
this.partialTrace = partialTrace;
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
/**
|
|
805
|
+
* Surfaced under `toolErrorMode: 'abort'` when a tool handler throws (or its
|
|
806
|
+
* result fails to serialize). Carries the original throw on `.cause` and the
|
|
807
|
+
* partial trace — including the failing entry — on `.partialTrace` so callers
|
|
808
|
+
* always have the full picture on the abort path.
|
|
809
|
+
*
|
|
810
|
+
* `statusCode` mirrors the underlying error when it carries one (e.g. a handler
|
|
811
|
+
* throwing `ClientError(400)` surfaces as `ToolHandlerError(400)`), otherwise
|
|
812
|
+
* defaults to 500.
|
|
813
|
+
*
|
|
814
|
+
* **`instanceof` caveat:** extends `ServerError` regardless of `statusCode`, so a
|
|
815
|
+
* handler-thrown `ClientError(403)` becomes a `ToolHandlerError` whose `statusCode`
|
|
816
|
+
* is 403 but where `instanceof ClientError === false`. Callers that route on
|
|
817
|
+
* client-vs-server class should branch on `err.statusCode` or
|
|
818
|
+
* `err.cause instanceof ClientError`, not on `err instanceof ClientError` directly.
|
|
819
|
+
*/
|
|
820
|
+
export class ToolHandlerError extends ServerError {
|
|
821
|
+
toolName: string;
|
|
822
|
+
toolCallId: string;
|
|
823
|
+
partialTrace: ToolTraceEntry[];
|
|
824
|
+
constructor(toolName: string, toolCallId: string, partialTrace: ToolTraceEntry[], cause: unknown) {
|
|
825
|
+
const causeMessage = errorInfo(cause).message;
|
|
826
|
+
const causeStatus =
|
|
827
|
+
cause &&
|
|
828
|
+
typeof cause === 'object' &&
|
|
829
|
+
'statusCode' in cause &&
|
|
830
|
+
typeof (cause as { statusCode: unknown }).statusCode === 'number'
|
|
831
|
+
? (cause as { statusCode: number }).statusCode
|
|
832
|
+
: 500;
|
|
833
|
+
super(`Tool handler '${toolName}' (call ${toolCallId}) failed: ${causeMessage}`, causeStatus);
|
|
834
|
+
this.name = 'ToolHandlerError';
|
|
835
|
+
this.toolName = toolName;
|
|
836
|
+
this.toolCallId = toolCallId;
|
|
837
|
+
this.partialTrace = partialTrace;
|
|
838
|
+
this.cause = cause;
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
/**
|
|
843
|
+
* Cost computation hook. v1 returns 0 — no per-model rate card is wired today —
|
|
844
|
+
* so `maxCostUsd` never trips in production. The cap, the trip path, and the
|
|
845
|
+
* `BudgetExceededError({kind: 'cost'})` shape ARE wired and exercised by tests
|
|
846
|
+
* that inject a non-zero function via `_setComputeCallCostUsdForTests`. When the
|
|
847
|
+
* rate card lands, replace this implementation; no surface change needed.
|
|
848
|
+
*/
|
|
849
|
+
let computeCallCostUsd: (usage: TokenUsage | undefined, model: string | undefined) => number = () => 0;
|
|
850
|
+
|
|
851
|
+
/**
|
|
852
|
+
* Test-only override. Public callers must not depend on this — it exists so unit
|
|
853
|
+
* tests can prove the `maxCostUsd` trip path works end-to-end before a real rate
|
|
854
|
+
* card lands. Leading underscore marks the intent.
|
|
855
|
+
*/
|
|
856
|
+
export function _setComputeCallCostUsdForTests(
|
|
857
|
+
fn: (usage: TokenUsage | undefined, model: string | undefined) => number
|
|
858
|
+
): void {
|
|
859
|
+
computeCallCostUsd = fn;
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
/**
|
|
863
|
+
* Reset the cost function to the v1 stub. Pair with `_setComputeCallCostUsdForTests`
|
|
864
|
+
* in test `afterEach` so suites don't leak state into each other.
|
|
865
|
+
*/
|
|
866
|
+
export function _resetComputeCallCostUsdForTests(): void {
|
|
867
|
+
computeCallCostUsd = () => 0;
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
function sumTokens(usage: TokenUsage | undefined): number {
|
|
871
|
+
if (!usage) return 0;
|
|
872
|
+
let total = 0;
|
|
873
|
+
if (typeof usage.promptTokens === 'number' && usage.promptTokens > 0) total += usage.promptTokens;
|
|
874
|
+
if (typeof usage.completionTokens === 'number' && usage.completionTokens > 0) total += usage.completionTokens;
|
|
875
|
+
return total;
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
/**
|
|
879
|
+
* `toolArgValidation: 'strict'` rejected a tool call's arguments against its
|
|
880
|
+
* declared `parameters` JSON Schema. Surfaces as a 400 — the model produced output
|
|
881
|
+
* that doesn't satisfy the contract the caller declared. Reserved for the
|
|
882
|
+
* validator wiring (currently the strict mode is itself gated at loop entry).
|
|
883
|
+
*/
|
|
884
|
+
export class ToolValidationError extends ClientError {
|
|
885
|
+
toolName: string;
|
|
886
|
+
toolCallId: string;
|
|
887
|
+
validationErrors: object[];
|
|
888
|
+
constructor(toolName: string, toolCallId: string, validationErrors: object[], message: string) {
|
|
889
|
+
super(message, 400);
|
|
890
|
+
this.name = 'ToolValidationError';
|
|
891
|
+
this.toolName = toolName;
|
|
892
|
+
this.toolCallId = toolCallId;
|
|
893
|
+
this.validationErrors = validationErrors;
|
|
894
|
+
}
|
|
895
|
+
}
|