@harperfast/harper 5.2.0 → 5.2.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/bin/copyDb.ts +40 -11
- package/bin/harper.ts +20 -51
- package/bin/help.ts +216 -0
- package/components/Application.ts +236 -46
- package/components/ApplicationScope.ts +26 -0
- package/components/EntryHandler.ts +410 -105
- package/components/RuntimeModuleTracker.ts +189 -0
- package/components/Scope.ts +68 -24
- package/components/componentLoader.ts +70 -16
- package/components/deployLifecycle.ts +119 -33
- package/components/deploymentRecorder.ts +102 -11
- package/components/mcp/tools/operations.ts +6 -0
- package/components/operations.js +8 -6
- package/config/configUtils.ts +78 -20
- package/config/harperConfigEnvVars.ts +114 -17
- package/config-root.schema.json +10 -0
- package/dataLayer/harperBridge/ResourceBridge.ts +26 -5
- package/dataLayer/harperBridge/lmdbBridge/lmdbUtility/initializePaths.js +4 -4
- package/dataLayer/hdbInfoController.ts +8 -0
- package/dataLayer/schemaDescribe.ts +2 -1
- package/dist/bin/copyDb.js +33 -9
- package/dist/bin/copyDb.js.map +1 -1
- package/dist/bin/harper.d.ts +6 -0
- package/dist/bin/harper.js +18 -50
- package/dist/bin/harper.js.map +1 -1
- package/dist/bin/help.d.ts +8 -0
- package/dist/bin/help.js +192 -0
- package/dist/bin/help.js.map +1 -0
- package/dist/components/Application.d.ts +16 -1
- package/dist/components/Application.js +210 -38
- package/dist/components/Application.js.map +1 -1
- package/dist/components/ApplicationScope.d.ts +7 -0
- package/dist/components/ApplicationScope.js +22 -0
- package/dist/components/ApplicationScope.js.map +1 -1
- package/dist/components/EntryHandler.d.ts +4 -4
- package/dist/components/EntryHandler.js +386 -95
- package/dist/components/EntryHandler.js.map +1 -1
- package/dist/components/RuntimeModuleTracker.d.ts +11 -0
- package/dist/components/RuntimeModuleTracker.js +189 -0
- package/dist/components/RuntimeModuleTracker.js.map +1 -0
- package/dist/components/Scope.d.ts +1 -0
- package/dist/components/Scope.js +69 -22
- package/dist/components/Scope.js.map +1 -1
- package/dist/components/componentLoader.js +69 -10
- package/dist/components/componentLoader.js.map +1 -1
- package/dist/components/deployLifecycle.d.ts +6 -2
- package/dist/components/deployLifecycle.js +109 -31
- package/dist/components/deployLifecycle.js.map +1 -1
- package/dist/components/deploymentRecorder.d.ts +6 -0
- package/dist/components/deploymentRecorder.js +94 -12
- package/dist/components/deploymentRecorder.js.map +1 -1
- package/dist/components/mcp/tools/operations.js +6 -0
- package/dist/components/mcp/tools/operations.js.map +1 -1
- package/dist/components/operations.js +8 -6
- package/dist/components/operations.js.map +1 -1
- package/dist/config/configUtils.d.ts +6 -0
- package/dist/config/configUtils.js +78 -18
- package/dist/config/configUtils.js.map +1 -1
- package/dist/config/harperConfigEnvVars.js +108 -16
- package/dist/config/harperConfigEnvVars.js.map +1 -1
- package/dist/dataLayer/harperBridge/ResourceBridge.js +12 -5
- package/dist/dataLayer/harperBridge/ResourceBridge.js.map +1 -1
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbUtility/initializePaths.js +4 -4
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbUtility/initializePaths.js.map +1 -1
- package/dist/dataLayer/hdbInfoController.js +4 -0
- package/dist/dataLayer/hdbInfoController.js.map +1 -1
- package/dist/dataLayer/schemaDescribe.js +2 -1
- package/dist/dataLayer/schemaDescribe.js.map +1 -1
- package/dist/resources/DatabaseTransaction.d.ts +57 -0
- package/dist/resources/DatabaseTransaction.js +284 -104
- package/dist/resources/DatabaseTransaction.js.map +1 -1
- package/dist/resources/ResourceInterface.d.ts +8 -2
- package/dist/resources/ResourceInterface.js.map +1 -1
- package/dist/resources/Resources.js +22 -4
- package/dist/resources/Resources.js.map +1 -1
- package/dist/resources/Table.d.ts +8 -6
- package/dist/resources/Table.js +158 -31
- package/dist/resources/Table.js.map +1 -1
- package/dist/resources/analytics/write.js +6 -6
- package/dist/resources/analytics/write.js.map +1 -1
- package/dist/resources/auditStore.js +27 -1
- package/dist/resources/auditStore.js.map +1 -1
- package/dist/resources/blob.d.ts +0 -1
- package/dist/resources/blob.js +15 -7
- package/dist/resources/blob.js.map +1 -1
- package/dist/resources/databases.d.ts +22 -5
- package/dist/resources/databases.js +118 -9
- package/dist/resources/databases.js.map +1 -1
- package/dist/resources/indexes/HierarchicalNavigableSmallWorld.d.ts +15 -2
- package/dist/resources/indexes/HierarchicalNavigableSmallWorld.js +128 -39
- package/dist/resources/indexes/HierarchicalNavigableSmallWorld.js.map +1 -1
- package/dist/resources/jsResource.d.ts +4 -26
- package/dist/resources/jsResource.js +5 -59
- package/dist/resources/jsResource.js.map +1 -1
- package/dist/resources/models/Models.d.ts +11 -1
- package/dist/resources/models/Models.js +10 -1
- package/dist/resources/models/Models.js.map +1 -1
- package/dist/resources/models/backendRegistry.d.ts +9 -0
- package/dist/resources/models/backendRegistry.js +10 -0
- package/dist/resources/models/backendRegistry.js.map +1 -1
- package/dist/resources/models/openaiStream.d.ts +16 -1
- package/dist/resources/models/openaiStream.js +113 -21
- package/dist/resources/models/openaiStream.js.map +1 -1
- package/dist/resources/models/v1/chatCompletions.d.ts +54 -0
- package/dist/resources/models/v1/chatCompletions.js +115 -0
- package/dist/resources/models/v1/chatCompletions.js.map +1 -0
- package/dist/resources/models/v1/embeddings.d.ts +11 -0
- package/dist/resources/models/v1/embeddings.js +71 -0
- package/dist/resources/models/v1/embeddings.js.map +1 -0
- package/dist/resources/models/v1/errors.d.ts +54 -0
- package/dist/resources/models/v1/errors.js +130 -0
- package/dist/resources/models/v1/errors.js.map +1 -0
- package/dist/resources/models/v1/index.d.ts +36 -0
- package/dist/resources/models/v1/index.js +75 -0
- package/dist/resources/models/v1/index.js.map +1 -0
- package/dist/resources/models/v1/models.d.ts +26 -0
- package/dist/resources/models/v1/models.js +44 -0
- package/dist/resources/models/v1/models.js.map +1 -0
- package/dist/resources/models/v1/translation.d.ts +133 -0
- package/dist/resources/models/v1/translation.js +298 -0
- package/dist/resources/models/v1/translation.js.map +1 -0
- package/dist/resources/roles.d.ts +1 -1
- package/dist/resources/roles.js +54 -7
- package/dist/resources/roles.js.map +1 -1
- package/dist/resources/search.d.ts +1 -1
- package/dist/resources/search.js +7 -3
- package/dist/resources/search.js.map +1 -1
- package/dist/security/jsLoader.js +84 -33
- package/dist/security/jsLoader.js.map +1 -1
- package/dist/security/role.js +4 -0
- package/dist/security/role.js.map +1 -1
- package/dist/security/superUserGuard.d.ts +7 -0
- package/dist/security/superUserGuard.js +23 -0
- package/dist/security/superUserGuard.js.map +1 -0
- package/dist/security/tokenAuthentication.d.ts +0 -1
- package/dist/security/tokenAuthentication.js +6 -2
- package/dist/security/tokenAuthentication.js.map +1 -1
- package/dist/security/user.d.ts +6 -1
- package/dist/security/user.js +23 -1
- package/dist/security/user.js.map +1 -1
- package/dist/server/http.d.ts +23 -2
- package/dist/server/http.js +99 -12
- package/dist/server/http.js.map +1 -1
- package/dist/server/operationsServer.d.ts +0 -2
- package/dist/server/operationsServer.js.map +1 -1
- package/dist/server/serverHelpers/multipartParser.js +9 -0
- package/dist/server/serverHelpers/multipartParser.js.map +1 -1
- package/dist/server/serverHelpers/operationAuthorizationState.d.ts +2 -0
- package/dist/server/serverHelpers/operationAuthorizationState.js +13 -0
- package/dist/server/serverHelpers/operationAuthorizationState.js.map +1 -0
- package/dist/server/serverHelpers/registeredOperations.d.ts +3 -2
- package/dist/server/serverHelpers/registeredOperations.js +14 -13
- package/dist/server/serverHelpers/registeredOperations.js.map +1 -1
- package/dist/server/serverHelpers/serverHandlers.js +19 -3
- package/dist/server/serverHelpers/serverHandlers.js.map +1 -1
- package/dist/server/serverHelpers/serverUtilities.d.ts +1 -1
- package/dist/server/serverHelpers/serverUtilities.js +10 -7
- package/dist/server/serverHelpers/serverUtilities.js.map +1 -1
- package/dist/server/static.js +57 -18
- package/dist/server/static.js.map +1 -1
- package/dist/server/storageReclamation.d.ts +17 -0
- package/dist/server/storageReclamation.js +90 -6
- package/dist/server/storageReclamation.js.map +1 -1
- package/dist/server/threads/manageThreads.js +8 -0
- package/dist/server/threads/manageThreads.js.map +1 -1
- package/dist/server/threads/socketRouter.js +20 -0
- package/dist/server/threads/socketRouter.js.map +1 -1
- package/dist/server/threads/threadServer.js +12 -0
- package/dist/server/threads/threadServer.js.map +1 -1
- package/dist/sqlEngine/diff/differential.js +7 -3
- package/dist/sqlEngine/diff/differential.js.map +1 -1
- package/dist/sqlEngine/parser/normalizer.js +37 -9
- package/dist/sqlEngine/parser/normalizer.js.map +1 -1
- package/dist/sqlTranslator/index.js +6 -1
- package/dist/sqlTranslator/index.js.map +1 -1
- package/dist/upgrade/upgradePrompt.d.ts +2 -2
- package/dist/upgrade/upgradePrompt.js +22 -3
- package/dist/upgrade/upgradePrompt.js.map +1 -1
- package/dist/utility/environment/environmentManager.d.ts +11 -0
- package/dist/utility/environment/environmentManager.js +154 -0
- package/dist/utility/environment/environmentManager.js.map +1 -1
- package/dist/utility/errors/commonErrors.d.ts +1 -0
- package/dist/utility/errors/commonErrors.js +1 -0
- package/dist/utility/errors/commonErrors.js.map +1 -1
- package/dist/utility/hdbTerms.d.ts +2 -0
- package/dist/utility/hdbTerms.js +2 -0
- package/dist/utility/hdbTerms.js.map +1 -1
- package/dist/utility/install/installer.js +32 -0
- package/dist/utility/install/installer.js.map +1 -1
- package/dist/utility/lmdb/environmentUtility.js +2 -1
- package/dist/utility/lmdb/environmentUtility.js.map +1 -1
- package/dist/utility/logging/harper_logger.d.ts +7 -0
- package/dist/utility/logging/harper_logger.js +57 -24
- package/dist/utility/logging/harper_logger.js.map +1 -1
- package/npm-shrinkwrap.json +208 -198
- package/package.json +10 -8
- package/resources/DESIGN.md +1 -0
- package/resources/DatabaseTransaction.ts +313 -102
- package/resources/ResourceInterface.ts +8 -2
- package/resources/Resources.ts +22 -4
- package/resources/Table.ts +398 -259
- package/resources/analytics/write.ts +22 -20
- package/resources/auditStore.ts +32 -1
- package/resources/blob.ts +15 -8
- package/resources/databases.ts +123 -12
- package/resources/indexes/HierarchicalNavigableSmallWorld.ts +119 -45
- package/resources/jsResource.ts +5 -62
- package/resources/models/Models.ts +14 -1
- package/resources/models/backendRegistry.ts +10 -0
- package/resources/models/openaiStream.ts +131 -19
- package/resources/models/v1/chatCompletions.ts +128 -0
- package/resources/models/v1/embeddings.ts +70 -0
- package/resources/models/v1/errors.ts +141 -0
- package/resources/models/v1/index.ts +72 -0
- package/resources/models/v1/models.ts +53 -0
- package/resources/models/v1/translation.ts +362 -0
- package/resources/roles.ts +67 -7
- package/resources/search.ts +8 -3
- package/security/jsLoader.ts +84 -30
- package/security/role.ts +7 -0
- package/security/superUserGuard.ts +20 -0
- package/security/tokenAuthentication.ts +6 -3
- package/security/user.ts +26 -1
- package/server/DESIGN.md +45 -34
- package/server/http.ts +100 -13
- package/server/operationsServer.ts +0 -2
- package/server/serverHelpers/multipartParser.ts +9 -0
- package/server/serverHelpers/operationAuthorizationState.ts +11 -0
- package/server/serverHelpers/registeredOperations.ts +19 -15
- package/server/serverHelpers/serverHandlers.js +20 -3
- package/server/serverHelpers/serverUtilities.ts +10 -7
- package/server/static.ts +75 -20
- package/server/storageReclamation.ts +104 -8
- package/server/threads/manageThreads.js +8 -0
- package/server/threads/socketRouter.ts +20 -0
- package/server/threads/threadServer.js +11 -0
- package/sqlTranslator/index.ts +6 -1
- package/static/defaultConfig.yaml +2 -0
- package/studio/web/assets/{Chat-DoVWScmq.js → Chat-BMUjPklt.js} +5 -5
- package/studio/web/assets/{Chat-DoVWScmq.js.map → Chat-BMUjPklt.js.map} +1 -1
- package/studio/web/assets/{FloatingChat-UZ2NsUOZ.js → FloatingChat-Cbghuxe5.js} +5 -5
- package/studio/web/assets/{FloatingChat-UZ2NsUOZ.js.map → FloatingChat-Cbghuxe5.js.map} +1 -1
- package/studio/web/assets/{apiToken-BUI_04o7.js → apiToken-CkgTQAqc.js} +2 -2
- package/studio/web/assets/{apiToken-BUI_04o7.js.map → apiToken-CkgTQAqc.js.map} +1 -1
- package/studio/web/assets/{applications-D03NA7wW.js → applications-WvF4NOTN.js} +13 -13
- package/studio/web/assets/applications-WvF4NOTN.js.map +1 -0
- package/studio/web/assets/chevron-right-anDJCGlp.js +2 -0
- package/studio/web/assets/chevron-right-anDJCGlp.js.map +1 -0
- package/studio/web/assets/index-CDeqVx71.css +1 -0
- package/studio/web/assets/index-Sevt3MVx.js +819 -0
- package/studio/web/assets/index-Sevt3MVx.js.map +1 -0
- package/studio/web/assets/index.lazy-Dg5YYPGg.js +14 -0
- package/studio/web/assets/{index.lazy-Dx3MpyDC.js.map → index.lazy-Dg5YYPGg.js.map} +1 -1
- package/studio/web/assets/{jsonMode-Cjj7dtlr.js → jsonMode-CBSEleE7.js} +2 -2
- package/studio/web/assets/{jsonMode-Cjj7dtlr.js.map → jsonMode-CBSEleE7.js.map} +1 -1
- package/studio/web/assets/languageServices-gxedeeTo.js +2 -0
- package/studio/web/assets/languageServices-gxedeeTo.js.map +1 -0
- package/studio/web/assets/{notifications-0edoFTsb.js → notifications-Ap84YyQp.js} +2 -2
- package/studio/web/assets/{notifications-0edoFTsb.js.map → notifications-Ap84YyQp.js.map} +1 -1
- package/studio/web/assets/notifications-vehqyOLM.js +2 -0
- package/studio/web/assets/{notifications-CwKhipK7.js.map → notifications-vehqyOLM.js.map} +1 -1
- package/studio/web/assets/{pollUnlessForbidden-HHdQZW1N.js → pollUnlessForbidden-BhzefVRn.js} +2 -2
- package/studio/web/assets/pollUnlessForbidden-BhzefVRn.js.map +1 -0
- package/studio/web/assets/{profile-DUfEPQtx.js → profile-DzDpRLHY.js} +2 -2
- package/studio/web/assets/{profile-DUfEPQtx.js.map → profile-DzDpRLHY.js.map} +1 -1
- package/studio/web/assets/queryClient-CgtkoiCY.js +2 -0
- package/studio/web/assets/queryClient-CgtkoiCY.js.map +1 -0
- package/studio/web/assets/regions-DpJ8s7iN.js +2 -0
- package/studio/web/assets/regions-DpJ8s7iN.js.map +1 -0
- package/studio/web/assets/register-BDy01-q3.js +3 -0
- package/studio/web/assets/register-BDy01-q3.js.map +1 -0
- package/studio/web/assets/register-CQHRwNP4.js +3 -0
- package/studio/web/assets/register-CQHRwNP4.js.map +1 -0
- package/studio/web/assets/{setComponentFile-DMPo4UjC.js → setComponentFile-D0aPcI3W.js} +2 -2
- package/studio/web/assets/{setComponentFile-DMPo4UjC.js.map → setComponentFile-D0aPcI3W.js.map} +1 -1
- package/studio/web/assets/setup-I15FAF9H.js +3 -0
- package/studio/web/assets/{setup-B56Oz1_u.js.map → setup-I15FAF9H.js.map} +1 -1
- package/studio/web/assets/status-BF1eJshJ.js +62 -0
- package/studio/web/assets/status-BF1eJshJ.js.map +1 -0
- package/studio/web/assets/{swagger-ui-react-lQrBxfwM.js → swagger-ui-react-DwSPXXhl.js} +2 -2
- package/studio/web/assets/{swagger-ui-react-lQrBxfwM.js.map → swagger-ui-react-DwSPXXhl.js.map} +1 -1
- package/studio/web/assets/{textarea-DhLMZ3PA.js → table-DpOjNQHt.js} +2 -10
- package/studio/web/assets/table-DpOjNQHt.js.map +1 -0
- package/studio/web/assets/{tsMode-CrHCRjTK.js → tsMode-Bu51A-VG.js} +2 -2
- package/studio/web/assets/{tsMode-CrHCRjTK.js.map → tsMode-Bu51A-VG.js.map} +1 -1
- package/studio/web/assets/{useEntityRestURL-DoaBMEvU.js → useEntityRestURL-DrV1zMrN.js} +2 -2
- package/studio/web/assets/{useEntityRestURL-DoaBMEvU.js.map → useEntityRestURL-DrV1zMrN.js.map} +1 -1
- package/studio/web/index.html +6 -7
- package/upgrade/upgradePrompt.ts +22 -3
- package/utility/environment/environmentManager.ts +152 -0
- package/utility/errors/commonErrors.ts +2 -0
- package/utility/hdbTerms.ts +2 -0
- package/utility/install/installer.ts +37 -0
- package/utility/lmdb/environmentUtility.ts +2 -1
- package/utility/logging/harper_logger.ts +57 -26
- package/studio/web/assets/applications-D03NA7wW.js.map +0 -1
- package/studio/web/assets/index-Bh_CNAHr.js +0 -809
- package/studio/web/assets/index-Bh_CNAHr.js.map +0 -1
- package/studio/web/assets/index-C8Mv9kHV.css +0 -1
- package/studio/web/assets/index.lazy-Dx3MpyDC.js +0 -14
- package/studio/web/assets/notifications-CwKhipK7.js +0 -2
- package/studio/web/assets/pollUnlessForbidden-HHdQZW1N.js.map +0 -1
- package/studio/web/assets/queryClient-CbA8wM7J.js +0 -2
- package/studio/web/assets/queryClient-CbA8wM7J.js.map +0 -1
- package/studio/web/assets/setup-B56Oz1_u.js +0 -3
- package/studio/web/assets/status-BAod7p3o.js +0 -62
- package/studio/web/assets/status-BAod7p3o.js.map +0 -1
- package/studio/web/assets/textarea-DhLMZ3PA.js.map +0 -1
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `/v1/*` OpenAI-compatible gateway (#631).
|
|
3
|
+
*
|
|
4
|
+
* Registers three REST resources on the REST port:
|
|
5
|
+
* POST /v1/embeddings → V1Embeddings
|
|
6
|
+
* POST /v1/chat/completions → V1ChatCompletions
|
|
7
|
+
* GET /v1/models → V1Models
|
|
8
|
+
*
|
|
9
|
+
* Off by default, and `defaultConfig.yaml` deliberately ships no `modelsGateway`
|
|
10
|
+
* block: with the key absent the root loader skips the component before resolving
|
|
11
|
+
* it, so none of this module graph is imported on an instance that does not use
|
|
12
|
+
* the gateway. Opt in by adding the block to `harperdb-config.yaml` with
|
|
13
|
+
* `enabled: true`, or via `set_configuration` (`modelsGateway_enabled`).
|
|
14
|
+
* `enabled: false` is honored too, for an instance that wants the block present
|
|
15
|
+
* but inert — that costs the import, which is why it is not the shipped default.
|
|
16
|
+
*
|
|
17
|
+
* Example (opt in). `rest` is required: these are REST-served resources and the
|
|
18
|
+
* gateway deliberately does not force REST to start (see `handleApplication`).
|
|
19
|
+
* Without it the resources register but every `/v1/*` path 404s.
|
|
20
|
+
*
|
|
21
|
+
* ```yaml
|
|
22
|
+
* rest: true
|
|
23
|
+
* modelsGateway:
|
|
24
|
+
* enabled: true
|
|
25
|
+
* models:
|
|
26
|
+
* generative:
|
|
27
|
+
* default:
|
|
28
|
+
* backend: ollama
|
|
29
|
+
* model: llama3.2
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* All three endpoints require `super_user` permission. Anonymous or
|
|
33
|
+
* insufficient-privilege requests receive a well-formed OpenAI error envelope.
|
|
34
|
+
*/
|
|
35
|
+
import type { Scope } from '../../../components/Scope.ts';
|
|
36
|
+
export declare function handleApplication(scope: Scope): void;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* `/v1/*` OpenAI-compatible gateway (#631).
|
|
4
|
+
*
|
|
5
|
+
* Registers three REST resources on the REST port:
|
|
6
|
+
* POST /v1/embeddings → V1Embeddings
|
|
7
|
+
* POST /v1/chat/completions → V1ChatCompletions
|
|
8
|
+
* GET /v1/models → V1Models
|
|
9
|
+
*
|
|
10
|
+
* Off by default, and `defaultConfig.yaml` deliberately ships no `modelsGateway`
|
|
11
|
+
* block: with the key absent the root loader skips the component before resolving
|
|
12
|
+
* it, so none of this module graph is imported on an instance that does not use
|
|
13
|
+
* the gateway. Opt in by adding the block to `harperdb-config.yaml` with
|
|
14
|
+
* `enabled: true`, or via `set_configuration` (`modelsGateway_enabled`).
|
|
15
|
+
* `enabled: false` is honored too, for an instance that wants the block present
|
|
16
|
+
* but inert — that costs the import, which is why it is not the shipped default.
|
|
17
|
+
*
|
|
18
|
+
* Example (opt in). `rest` is required: these are REST-served resources and the
|
|
19
|
+
* gateway deliberately does not force REST to start (see `handleApplication`).
|
|
20
|
+
* Without it the resources register but every `/v1/*` path 404s.
|
|
21
|
+
*
|
|
22
|
+
* ```yaml
|
|
23
|
+
* rest: true
|
|
24
|
+
* modelsGateway:
|
|
25
|
+
* enabled: true
|
|
26
|
+
* models:
|
|
27
|
+
* generative:
|
|
28
|
+
* default:
|
|
29
|
+
* backend: ollama
|
|
30
|
+
* model: llama3.2
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* All three endpoints require `super_user` permission. Anonymous or
|
|
34
|
+
* insufficient-privilege requests receive a well-formed OpenAI error envelope.
|
|
35
|
+
*/
|
|
36
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
|
+
};
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.handleApplication = handleApplication;
|
|
41
|
+
const harper_logger_ts_1 = __importDefault(require("../../../utility/logging/harper_logger.js"));
|
|
42
|
+
const configUtils_ts_1 = require("../../../config/configUtils.js");
|
|
43
|
+
const embeddings_ts_1 = require("./embeddings.js");
|
|
44
|
+
const chatCompletions_ts_1 = require("./chatCompletions.js");
|
|
45
|
+
const models_ts_1 = require("./models.js");
|
|
46
|
+
function handleApplication(scope) {
|
|
47
|
+
if (!scope.options.get(['enabled']))
|
|
48
|
+
return;
|
|
49
|
+
// These resources are served by REST's middleware chain, so the instance must also
|
|
50
|
+
// have a `rest`/`REST` config section — the gateway deliberately does NOT force REST
|
|
51
|
+
// to start. Doing so requires reaching into REST's module state before application
|
|
52
|
+
// configs have loaded, which silently discards an app's own `rest` options (webSocket,
|
|
53
|
+
// urlPath/host, middleware ordering). Core has no supported way yet for a component to
|
|
54
|
+
// declare "I serve REST resources"; that gap is tracked separately.
|
|
55
|
+
//
|
|
56
|
+
// Warn rather than fail: an app loaded later may still declare `rest`, so absence here
|
|
57
|
+
// is not conclusive. But defaultConfig ships no `rest` section, so enabling the gateway
|
|
58
|
+
// alone yields three registered resources and a 404 on every /v1 path — worth a line in
|
|
59
|
+
// the log instead of silence.
|
|
60
|
+
const rootConfig = (0, configUtils_ts_1.getConfigObj)();
|
|
61
|
+
if (rootConfig && !rootConfig.rest && !rootConfig.REST) {
|
|
62
|
+
harper_logger_ts_1.default.warn('modelsGateway is enabled but no `rest` section is configured; /v1/* endpoints are only served when REST is active');
|
|
63
|
+
}
|
|
64
|
+
// Explicit protocol visibility: these are REST-only wire-protocol endpoints. Without a
|
|
65
|
+
// policy, the shared registry matches them for every protocol lookup — WS dispatch could
|
|
66
|
+
// reach V1ChatCompletions.connect() and then fail iterating its non-iterable badRequest
|
|
67
|
+
// envelope, and they would surface through MQTT/GraphQL/MCP enumeration too. `sse` stays
|
|
68
|
+
// enabled for chat only: an explicit `Accept: text/event-stream` POST is dispatched via
|
|
69
|
+
// the sse lookup (REST.ts) and is a supported streaming client shape (see connect()).
|
|
70
|
+
const restOnly = { rest: true, sse: false, ws: false, mqtt: false, graphql: false, mcp: false };
|
|
71
|
+
scope.resources.set('v1/models', models_ts_1.V1Models, restOnly);
|
|
72
|
+
scope.resources.set('v1/embeddings', embeddings_ts_1.V1Embeddings, restOnly);
|
|
73
|
+
scope.resources.set('v1/chat/completions', chatCompletions_ts_1.V1ChatCompletions, { ...restOnly, sse: true });
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../resources/models/v1/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;;;;;AASH,8CA6BC;AAnCD,iGAAqE;AACrE,mEAA8D;AAC9D,mDAA+C;AAC/C,6DAAyD;AACzD,2CAAuC;AAEvC,SAAgB,iBAAiB,CAAC,KAAY;IAC7C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC;QAAE,OAAO;IAC5C,mFAAmF;IACnF,qFAAqF;IACrF,mFAAmF;IACnF,uFAAuF;IACvF,uFAAuF;IACvF,oEAAoE;IACpE,EAAE;IACF,uFAAuF;IACvF,wFAAwF;IACxF,wFAAwF;IACxF,8BAA8B;IAC9B,MAAM,UAAU,GAAG,IAAA,6BAAY,GAAyC,CAAC;IACzE,IAAI,UAAU,IAAI,CAAC,UAAU,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;QACxD,0BAAY,CAAC,IAAI,CAChB,mHAAmH,CACnH,CAAC;IACH,CAAC;IACD,uFAAuF;IACvF,yFAAyF;IACzF,wFAAwF;IACxF,yFAAyF;IACzF,wFAAwF;IACxF,sFAAsF;IACtF,MAAM,QAAQ,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;IAChG,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,WAAW,EAAE,oBAAQ,EAAE,QAAQ,CAAC,CAAC;IACrD,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,eAAe,EAAE,4BAAY,EAAE,QAAQ,CAAC,CAAC;IAC7D,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,qBAAqB,EAAE,sCAAiB,EAAE,EAAE,GAAG,QAAQ,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC;AAC3F,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `GET /v1/models` — OpenAI-compatible model list endpoint (#631).
|
|
3
|
+
*
|
|
4
|
+
* Enumerates all registered embedding and generative backends from the
|
|
5
|
+
* process-wide `backendRegistry`. The response mirrors the OpenAI shape:
|
|
6
|
+
* `{ object: 'list', data: [{ id, object: 'model', created, owned_by }] }`.
|
|
7
|
+
*
|
|
8
|
+
* `logicalName` (not `backend.name`) is the `id` — it's what callers pass as
|
|
9
|
+
* `model` in subsequent requests.
|
|
10
|
+
*/
|
|
11
|
+
import { Resource } from '../../Resource.ts';
|
|
12
|
+
import { type OpenAIErrorResponse } from './errors.ts';
|
|
13
|
+
export interface OAIModelEntry {
|
|
14
|
+
id: string;
|
|
15
|
+
object: 'model';
|
|
16
|
+
created: number;
|
|
17
|
+
owned_by: string;
|
|
18
|
+
}
|
|
19
|
+
export interface OAIModelList {
|
|
20
|
+
object: 'list';
|
|
21
|
+
data: OAIModelEntry[];
|
|
22
|
+
}
|
|
23
|
+
export declare class V1Models extends Resource {
|
|
24
|
+
static reservedPath: boolean;
|
|
25
|
+
static get(_target: unknown, request: unknown): OAIModelList | OpenAIErrorResponse;
|
|
26
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* `GET /v1/models` — OpenAI-compatible model list endpoint (#631).
|
|
4
|
+
*
|
|
5
|
+
* Enumerates all registered embedding and generative backends from the
|
|
6
|
+
* process-wide `backendRegistry`. The response mirrors the OpenAI shape:
|
|
7
|
+
* `{ object: 'list', data: [{ id, object: 'model', created, owned_by }] }`.
|
|
8
|
+
*
|
|
9
|
+
* `logicalName` (not `backend.name`) is the `id` — it's what callers pass as
|
|
10
|
+
* `model` in subsequent requests.
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.V1Models = void 0;
|
|
14
|
+
const Resource_ts_1 = require("../../Resource.js");
|
|
15
|
+
const backendRegistry_ts_1 = require("../backendRegistry.js");
|
|
16
|
+
const errors_ts_1 = require("./errors.js");
|
|
17
|
+
// @ts-ignore — Resource base class is not typed for static dispatch; pattern mirrors login.ts
|
|
18
|
+
class V1Models extends Resource_ts_1.Resource {
|
|
19
|
+
// Reserve this fixed route: a later app registration at the same path becomes a
|
|
20
|
+
// loud conflict (ErrorResource) instead of silently replacing the gateway and its
|
|
21
|
+
// super_user gate. See Resources.set.
|
|
22
|
+
static reservedPath = true;
|
|
23
|
+
static get(_target, request) {
|
|
24
|
+
const authError = (0, errors_ts_1.authorizeV1Request)(request);
|
|
25
|
+
if (authError)
|
|
26
|
+
return authError;
|
|
27
|
+
const created = Math.floor(Date.now() / 1000);
|
|
28
|
+
// OpenAI model ids are unique; a logical name registered for both generative and
|
|
29
|
+
// embedding (e.g. `default` in each section) is one model id to callers.
|
|
30
|
+
const ids = new Set();
|
|
31
|
+
const data = [];
|
|
32
|
+
for (const kind of ['generative', 'embedding']) {
|
|
33
|
+
for (const { logicalName } of (0, backendRegistry_ts_1.listBackends)(kind)) {
|
|
34
|
+
if (ids.has(logicalName))
|
|
35
|
+
continue;
|
|
36
|
+
ids.add(logicalName);
|
|
37
|
+
data.push({ id: logicalName, object: 'model', created, owned_by: 'harper' });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return { object: 'list', data };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.V1Models = V1Models;
|
|
44
|
+
//# sourceMappingURL=models.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../../../resources/models/v1/models.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAEH,mDAA6C;AAC7C,8DAAqD;AACrD,2CAA2E;AAc3E,8FAA8F;AAC9F,MAAa,QAAS,SAAQ,sBAAQ;IACrC,gFAAgF;IAChF,kFAAkF;IAClF,sCAAsC;IACtC,MAAM,CAAC,YAAY,GAAG,IAAI,CAAC;IAE3B,MAAM,CAAC,GAAG,CAAC,OAAgB,EAAE,OAAgB;QAC5C,MAAM,SAAS,GAAG,IAAA,8BAAkB,EAAC,OAAc,CAAC,CAAC;QACrD,IAAI,SAAS;YAAE,OAAO,SAAS,CAAC;QAEhC,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;QAC9C,iFAAiF;QACjF,yEAAyE;QACzE,MAAM,GAAG,GAAG,IAAI,GAAG,EAAU,CAAC;QAC9B,MAAM,IAAI,GAAoB,EAAE,CAAC;QACjC,KAAK,MAAM,IAAI,IAAI,CAAC,YAAY,EAAE,WAAW,CAAU,EAAE,CAAC;YACzD,KAAK,MAAM,EAAE,WAAW,EAAE,IAAI,IAAA,iCAAY,EAAC,IAAI,CAAC,EAAE,CAAC;gBAClD,IAAI,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC;oBAAE,SAAS;gBACnC,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;gBACrB,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC;YAC9E,CAAC;QACF,CAAC;QACD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;IACjC,CAAC;;AAvBF,4BAwBC"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI ↔ Harper internal shape mappers for the `/v1/*` gateway (#631).
|
|
3
|
+
*
|
|
4
|
+
* All functions are pure (no I/O, no side-effects) so they can be unit-tested
|
|
5
|
+
* in isolation without a running Harper instance.
|
|
6
|
+
*/
|
|
7
|
+
import type { EmbedOpts, GenerateInput, GenerateOpts, GenerateResult, Message, ToolDef, TokenUsage } from '../types.ts';
|
|
8
|
+
export interface OAIMessageIn {
|
|
9
|
+
role: string;
|
|
10
|
+
/** May be null for assistant messages that only contain tool_calls. */
|
|
11
|
+
content: string | null;
|
|
12
|
+
tool_calls?: Array<{
|
|
13
|
+
id: string;
|
|
14
|
+
type: string;
|
|
15
|
+
function: {
|
|
16
|
+
name: string;
|
|
17
|
+
arguments: string;
|
|
18
|
+
};
|
|
19
|
+
}>;
|
|
20
|
+
/** Present on role === 'tool' messages. */
|
|
21
|
+
tool_call_id?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface OAIToolIn {
|
|
24
|
+
type: 'function';
|
|
25
|
+
function: {
|
|
26
|
+
name: string;
|
|
27
|
+
description?: string;
|
|
28
|
+
parameters?: object;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export interface OAIChatRequest {
|
|
32
|
+
model?: string;
|
|
33
|
+
messages: OAIMessageIn[];
|
|
34
|
+
tools?: OAIToolIn[];
|
|
35
|
+
/** Subset recognised: 'none' | 'auto' | 'required' | {type:'function', function:{name}}. */
|
|
36
|
+
tool_choice?: unknown;
|
|
37
|
+
temperature?: number;
|
|
38
|
+
/** OpenAI v1 field; superseded by max_completion_tokens in v1+. */
|
|
39
|
+
max_tokens?: number;
|
|
40
|
+
/** Preferred alias; takes precedence over max_tokens when both present. */
|
|
41
|
+
max_completion_tokens?: number;
|
|
42
|
+
response_format?: {
|
|
43
|
+
type: string;
|
|
44
|
+
json_schema?: unknown;
|
|
45
|
+
};
|
|
46
|
+
stream?: boolean;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Map an OpenAI `messages` array to Harper `Message[]`.
|
|
50
|
+
* Normalises `tool_calls[].function.arguments` from JSON strings to parsed
|
|
51
|
+
* objects (Harper's internal contract); maps `tool_call_id` to `toolCallId`.
|
|
52
|
+
*/
|
|
53
|
+
export declare function translateMessages(oaiMessages: OAIMessageIn[]): Message[];
|
|
54
|
+
/** Map OpenAI `tools[]` to Harper `ToolDef[]`. */
|
|
55
|
+
export declare function translateTools(oaiTools: OAIToolIn[]): ToolDef[];
|
|
56
|
+
/**
|
|
57
|
+
* Build Harper `GenerateInput` from translated messages and tool definitions.
|
|
58
|
+
* Uses the object form `{ messages, tools }` when tools are present, so that
|
|
59
|
+
* tool definitions travel alongside messages per Harper's type contract.
|
|
60
|
+
*/
|
|
61
|
+
export declare function toGenerateInput(messages: Message[], tools: ToolDef[] | undefined): GenerateInput;
|
|
62
|
+
/**
|
|
63
|
+
* Validate the OpenAI wire shapes this gateway maps, returning a client-facing
|
|
64
|
+
* message for a 400 or `null` when the request is well-formed.
|
|
65
|
+
*
|
|
66
|
+
* Kept separate from the mappers so malformed nested input (`messages: [null]`,
|
|
67
|
+
* `tool_calls: [{}]`, `tools: [{}]`) becomes an OpenAI-shaped 400 instead of a
|
|
68
|
+
* TypeError escaping the handler as an RFC 9457 500.
|
|
69
|
+
*/
|
|
70
|
+
export declare function validateChatRequest(body: OAIChatRequest): string | null;
|
|
71
|
+
/**
|
|
72
|
+
* Map an OpenAI chat-completion request body to `GenerateOpts`.
|
|
73
|
+
*
|
|
74
|
+
* `tool_choice` is honored by the caller, not here: `'none'` omits tools from the
|
|
75
|
+
* generate input entirely, and unrepresentable choices are rejected up front by
|
|
76
|
+
* `validateChatRequest`. Full in-process tool-call orchestration is #612 (out of
|
|
77
|
+
* scope for #631), so tool calls are always returned to the caller to invoke.
|
|
78
|
+
*
|
|
79
|
+
* Assumes `validateChatRequest` has already passed.
|
|
80
|
+
*/
|
|
81
|
+
export declare function toGenerateOpts(body: OAIChatRequest): GenerateOpts;
|
|
82
|
+
/** Map an OpenAI embeddings request body to `EmbedOpts`. */
|
|
83
|
+
export declare function toEmbedOpts(body: {
|
|
84
|
+
model?: string;
|
|
85
|
+
}): EmbedOpts;
|
|
86
|
+
interface OAIToolCallOut {
|
|
87
|
+
id: string;
|
|
88
|
+
type: 'function';
|
|
89
|
+
function: {
|
|
90
|
+
name: string;
|
|
91
|
+
arguments: string;
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
interface OAIAssistantMessage {
|
|
95
|
+
role: 'assistant';
|
|
96
|
+
/** null when the message contains only tool_calls. */
|
|
97
|
+
content: string | null;
|
|
98
|
+
tool_calls?: OAIToolCallOut[];
|
|
99
|
+
}
|
|
100
|
+
export interface OAIChatCompletion {
|
|
101
|
+
id: string;
|
|
102
|
+
object: 'chat.completion';
|
|
103
|
+
created: number;
|
|
104
|
+
model: string;
|
|
105
|
+
choices: Array<{
|
|
106
|
+
index: number;
|
|
107
|
+
message: OAIAssistantMessage;
|
|
108
|
+
finish_reason: string;
|
|
109
|
+
}>;
|
|
110
|
+
usage: {
|
|
111
|
+
prompt_tokens: number;
|
|
112
|
+
completion_tokens: number;
|
|
113
|
+
total_tokens: number;
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
/** Map a Harper `GenerateResult` to an OpenAI `chat.completion` response object. */
|
|
117
|
+
export declare function toChatCompletion(result: GenerateResult, model: string, id?: string): OAIChatCompletion;
|
|
118
|
+
export interface OAIEmbedResponse {
|
|
119
|
+
object: 'list';
|
|
120
|
+
data: Array<{
|
|
121
|
+
embedding: number[];
|
|
122
|
+
index: number;
|
|
123
|
+
object: 'embedding';
|
|
124
|
+
}>;
|
|
125
|
+
model: string;
|
|
126
|
+
usage: {
|
|
127
|
+
prompt_tokens: number;
|
|
128
|
+
total_tokens: number;
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
/** Map `Float32Array[]` from `models.embed()` to an OpenAI embeddings response. */
|
|
132
|
+
export declare function toEmbedResponse(vecs: Float32Array[], model: string, usage?: TokenUsage): OAIEmbedResponse;
|
|
133
|
+
export {};
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* OpenAI ↔ Harper internal shape mappers for the `/v1/*` gateway (#631).
|
|
4
|
+
*
|
|
5
|
+
* All functions are pure (no I/O, no side-effects) so they can be unit-tested
|
|
6
|
+
* in isolation without a running Harper instance.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.translateMessages = translateMessages;
|
|
10
|
+
exports.translateTools = translateTools;
|
|
11
|
+
exports.toGenerateInput = toGenerateInput;
|
|
12
|
+
exports.validateChatRequest = validateChatRequest;
|
|
13
|
+
exports.toGenerateOpts = toGenerateOpts;
|
|
14
|
+
exports.toEmbedOpts = toEmbedOpts;
|
|
15
|
+
exports.toChatCompletion = toChatCompletion;
|
|
16
|
+
exports.toEmbedResponse = toEmbedResponse;
|
|
17
|
+
const node_crypto_1 = require("node:crypto");
|
|
18
|
+
// ---------------------------------------------------------------------------
|
|
19
|
+
// OpenAI request → Harper internal
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
/**
|
|
22
|
+
* Map an OpenAI `messages` array to Harper `Message[]`.
|
|
23
|
+
* Normalises `tool_calls[].function.arguments` from JSON strings to parsed
|
|
24
|
+
* objects (Harper's internal contract); maps `tool_call_id` to `toolCallId`.
|
|
25
|
+
*/
|
|
26
|
+
function translateMessages(oaiMessages) {
|
|
27
|
+
return oaiMessages.map((m) => {
|
|
28
|
+
// Content parts are flattened to the text Harper's Message.content expects; shapes
|
|
29
|
+
// that cannot be flattened are rejected up front by validateChatRequest.
|
|
30
|
+
const content = Array.isArray(m.content)
|
|
31
|
+
? m.content.map((part) => part.text).join('')
|
|
32
|
+
: (m.content ?? '');
|
|
33
|
+
const base = {
|
|
34
|
+
// `developer` is OpenAI's successor to `system` (the API itself treats the two
|
|
35
|
+
// identically, converting `system` to `developer` on models that use the newer
|
|
36
|
+
// hierarchy). Harper's internal Message union carries the channel as `system`,
|
|
37
|
+
// which every provider adapter maps to its system-instruction slot — so the
|
|
38
|
+
// instruction's priority is preserved rather than degraded to `user`. Roles
|
|
39
|
+
// outside the union are rejected up front by validateChatRequest, so the cast
|
|
40
|
+
// below is over a vetted set.
|
|
41
|
+
role: m.role === 'developer' ? 'system' : m.role,
|
|
42
|
+
content,
|
|
43
|
+
};
|
|
44
|
+
if (m.tool_calls?.length) {
|
|
45
|
+
base.toolCalls = m.tool_calls.map((tc) => {
|
|
46
|
+
let args;
|
|
47
|
+
try {
|
|
48
|
+
args = JSON.parse(tc.function.arguments);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
// Preserve unparseable argument strings under a sentinel key rather
|
|
52
|
+
// than dropping them — backend can decide what to do.
|
|
53
|
+
args = { _raw: tc.function.arguments };
|
|
54
|
+
}
|
|
55
|
+
return { id: tc.id, name: tc.function.name, arguments: args };
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
if (m.tool_call_id)
|
|
59
|
+
base.toolCallId = m.tool_call_id;
|
|
60
|
+
return base;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/** Map OpenAI `tools[]` to Harper `ToolDef[]`. */
|
|
64
|
+
function translateTools(oaiTools) {
|
|
65
|
+
return oaiTools.map((t) => ({
|
|
66
|
+
name: t.function.name,
|
|
67
|
+
description: t.function.description ?? '',
|
|
68
|
+
parameters: t.function.parameters ?? {},
|
|
69
|
+
}));
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Build Harper `GenerateInput` from translated messages and tool definitions.
|
|
73
|
+
* Uses the object form `{ messages, tools }` when tools are present, so that
|
|
74
|
+
* tool definitions travel alongside messages per Harper's type contract.
|
|
75
|
+
*/
|
|
76
|
+
function toGenerateInput(messages, tools) {
|
|
77
|
+
if (tools?.length)
|
|
78
|
+
return { messages, tools };
|
|
79
|
+
return messages;
|
|
80
|
+
}
|
|
81
|
+
/** `tool_choice` values the internal contract can faithfully represent. */
|
|
82
|
+
function isRepresentableToolChoice(choice) {
|
|
83
|
+
return choice === undefined || choice === null || choice === 'auto' || choice === 'none';
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Validate the OpenAI wire shapes this gateway maps, returning a client-facing
|
|
87
|
+
* message for a 400 or `null` when the request is well-formed.
|
|
88
|
+
*
|
|
89
|
+
* Kept separate from the mappers so malformed nested input (`messages: [null]`,
|
|
90
|
+
* `tool_calls: [{}]`, `tools: [{}]`) becomes an OpenAI-shaped 400 instead of a
|
|
91
|
+
* TypeError escaping the handler as an RFC 9457 500.
|
|
92
|
+
*/
|
|
93
|
+
function validateChatRequest(body) {
|
|
94
|
+
const req = body;
|
|
95
|
+
// Top-level fields that control routing and framing first: a non-string `model`
|
|
96
|
+
// would silently invoke the configured default model (potentially expensive), and a
|
|
97
|
+
// truthy non-boolean `stream` ("false") would return SSE the client didn't ask for.
|
|
98
|
+
if (req.model !== undefined && typeof req.model !== 'string')
|
|
99
|
+
return "'model' must be a string";
|
|
100
|
+
if (req.stream !== undefined && typeof req.stream !== 'boolean')
|
|
101
|
+
return "'stream' must be a boolean";
|
|
102
|
+
if (req.temperature !== undefined) {
|
|
103
|
+
if (typeof req.temperature !== 'number' || !Number.isFinite(req.temperature)) {
|
|
104
|
+
return "'temperature' must be a finite number";
|
|
105
|
+
}
|
|
106
|
+
if (req.temperature < 0 || req.temperature > 2)
|
|
107
|
+
return "'temperature' must be between 0 and 2";
|
|
108
|
+
}
|
|
109
|
+
for (const field of ['max_tokens', 'max_completion_tokens']) {
|
|
110
|
+
const value = req[field];
|
|
111
|
+
if (value === undefined)
|
|
112
|
+
continue;
|
|
113
|
+
if (typeof value !== 'number' || !Number.isInteger(value) || value < 1) {
|
|
114
|
+
return `'${field}' must be a positive integer`;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (!Array.isArray(req.messages) || req.messages.length === 0)
|
|
118
|
+
return "'messages' must be a non-empty array";
|
|
119
|
+
for (let i = 0; i < req.messages.length; i++) {
|
|
120
|
+
const m = req.messages[i];
|
|
121
|
+
if (!m || typeof m !== 'object' || Array.isArray(m))
|
|
122
|
+
return `'messages[${i}]' must be an object`;
|
|
123
|
+
if (typeof m.role !== 'string')
|
|
124
|
+
return `'messages[${i}].role' must be a string`;
|
|
125
|
+
// Closed set: translateMessages casts into Harper's Message union, so an
|
|
126
|
+
// unknown role must be a loud 400 here — previously it was cast through and
|
|
127
|
+
// provider adapters degraded it to 'user', silently changing its priority.
|
|
128
|
+
// 'developer' is accepted and carried as 'system' (see translateMessages);
|
|
129
|
+
// the deprecated 'function' role is deliberately not supported.
|
|
130
|
+
if (!['system', 'developer', 'user', 'assistant', 'tool'].includes(m.role)) {
|
|
131
|
+
return `'messages[${i}].role' must be one of 'system', 'developer', 'user', 'assistant', 'tool'`;
|
|
132
|
+
}
|
|
133
|
+
// OpenAI allows content parts: [{ type: 'text', text: '...' }, ...]. Harper's
|
|
134
|
+
// Message.content is a string, so those are flattened in translateMessages; reject
|
|
135
|
+
// shapes we cannot flatten rather than passing a non-string downstream.
|
|
136
|
+
if (m.content !== undefined && m.content !== null && typeof m.content !== 'string') {
|
|
137
|
+
if (!Array.isArray(m.content))
|
|
138
|
+
return `'messages[${i}].content' must be a string, array of parts, or null`;
|
|
139
|
+
for (let p = 0; p < m.content.length; p++) {
|
|
140
|
+
const part = m.content[p];
|
|
141
|
+
if (!part || typeof part !== 'object')
|
|
142
|
+
return `'messages[${i}].content[${p}]' must be an object`;
|
|
143
|
+
if (part.type !== 'text' || typeof part.text !== 'string') {
|
|
144
|
+
return `'messages[${i}].content[${p}]' must be a text part ({ type: 'text', text: string }); other part types are not supported yet`;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (m.tool_calls !== undefined) {
|
|
149
|
+
if (!Array.isArray(m.tool_calls))
|
|
150
|
+
return `'messages[${i}].tool_calls' must be an array`;
|
|
151
|
+
for (let j = 0; j < m.tool_calls.length; j++) {
|
|
152
|
+
const tc = m.tool_calls[j];
|
|
153
|
+
const at = `'messages[${i}].tool_calls[${j}]`;
|
|
154
|
+
if (!tc || typeof tc !== 'object')
|
|
155
|
+
return `${at}' must be an object`;
|
|
156
|
+
if (!tc.function || typeof tc.function !== 'object')
|
|
157
|
+
return `${at}.function' is required`;
|
|
158
|
+
if (typeof tc.function.name !== 'string')
|
|
159
|
+
return `${at}.function.name' must be a string`;
|
|
160
|
+
if (typeof tc.function.arguments !== 'string')
|
|
161
|
+
return `${at}.function.arguments' must be a JSON string`;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (req.tools !== undefined) {
|
|
166
|
+
if (!Array.isArray(req.tools))
|
|
167
|
+
return "'tools' must be an array";
|
|
168
|
+
for (let i = 0; i < req.tools.length; i++) {
|
|
169
|
+
const t = req.tools[i];
|
|
170
|
+
if (!t || typeof t !== 'object')
|
|
171
|
+
return `'tools[${i}]' must be an object`;
|
|
172
|
+
if (!t.function || typeof t.function !== 'object')
|
|
173
|
+
return `'tools[${i}].function' is required`;
|
|
174
|
+
if (typeof t.function.name !== 'string')
|
|
175
|
+
return `'tools[${i}].function.name' must be a string`;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (!isRepresentableToolChoice(req.tool_choice)) {
|
|
179
|
+
// Better a clear 400 than silently downgrading 'required'/named selection to 'auto'.
|
|
180
|
+
return "'tool_choice' supports 'auto' and 'none'; 'required' and named function selection are not supported yet";
|
|
181
|
+
}
|
|
182
|
+
if (req.response_format !== undefined) {
|
|
183
|
+
const rf = req.response_format;
|
|
184
|
+
if (!rf || typeof rf !== 'object' || Array.isArray(rf))
|
|
185
|
+
return "'response_format' must be an object";
|
|
186
|
+
if (rf.type === 'json_schema') {
|
|
187
|
+
const wrapper = rf.json_schema;
|
|
188
|
+
if (!wrapper || typeof wrapper !== 'object') {
|
|
189
|
+
return "'response_format.json_schema' is required when type is 'json_schema'";
|
|
190
|
+
}
|
|
191
|
+
if (!wrapper.schema || typeof wrapper.schema !== 'object') {
|
|
192
|
+
return "'response_format.json_schema.schema' must be a JSON Schema object";
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Map an OpenAI chat-completion request body to `GenerateOpts`.
|
|
200
|
+
*
|
|
201
|
+
* `tool_choice` is honored by the caller, not here: `'none'` omits tools from the
|
|
202
|
+
* generate input entirely, and unrepresentable choices are rejected up front by
|
|
203
|
+
* `validateChatRequest`. Full in-process tool-call orchestration is #612 (out of
|
|
204
|
+
* scope for #631), so tool calls are always returned to the caller to invoke.
|
|
205
|
+
*
|
|
206
|
+
* Assumes `validateChatRequest` has already passed.
|
|
207
|
+
*/
|
|
208
|
+
function toGenerateOpts(body) {
|
|
209
|
+
const opts = { toolMode: 'return' };
|
|
210
|
+
if (typeof body.model === 'string')
|
|
211
|
+
opts.model = body.model;
|
|
212
|
+
if (typeof body.temperature === 'number')
|
|
213
|
+
opts.temperature = body.temperature;
|
|
214
|
+
const maxTokens = body.max_completion_tokens ?? body.max_tokens;
|
|
215
|
+
if (typeof maxTokens === 'number')
|
|
216
|
+
opts.maxTokens = maxTokens;
|
|
217
|
+
if (body.response_format) {
|
|
218
|
+
const rf = body.response_format;
|
|
219
|
+
if (rf.type === 'json_object') {
|
|
220
|
+
opts.responseFormat = 'json';
|
|
221
|
+
}
|
|
222
|
+
else if (rf.type === 'json_schema') {
|
|
223
|
+
// The wire value is a wrapper ({ name, strict, schema }); Harper's contract wants
|
|
224
|
+
// the JSON Schema itself. Passing the wrapper makes the backend wrap it again and
|
|
225
|
+
// send metadata where the provider expects the schema.
|
|
226
|
+
opts.responseFormat = { schema: rf.json_schema.schema };
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
opts.responseFormat = 'text';
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return opts;
|
|
233
|
+
}
|
|
234
|
+
/** Map an OpenAI embeddings request body to `EmbedOpts`. */
|
|
235
|
+
function toEmbedOpts(body) {
|
|
236
|
+
const opts = {};
|
|
237
|
+
if (typeof body.model === 'string')
|
|
238
|
+
opts.model = body.model;
|
|
239
|
+
return opts;
|
|
240
|
+
}
|
|
241
|
+
function toOAIToolCalls(toolCalls) {
|
|
242
|
+
return toolCalls.map((tc) => ({
|
|
243
|
+
id: tc.id,
|
|
244
|
+
type: 'function',
|
|
245
|
+
// Guard against backends that return arguments as a pre-serialised JSON string;
|
|
246
|
+
// passing a string through JSON.stringify would double-encode it.
|
|
247
|
+
function: {
|
|
248
|
+
name: tc.name,
|
|
249
|
+
arguments: typeof tc.arguments === 'string' ? tc.arguments : JSON.stringify(tc.arguments),
|
|
250
|
+
},
|
|
251
|
+
}));
|
|
252
|
+
}
|
|
253
|
+
/** Map a Harper `GenerateResult` to an OpenAI `chat.completion` response object. */
|
|
254
|
+
function toChatCompletion(result, model, id) {
|
|
255
|
+
const completionId = id ?? `chatcmpl-${(0, node_crypto_1.randomUUID)().replaceAll('-', '')}`;
|
|
256
|
+
const hasTools = !!result.toolCalls?.length;
|
|
257
|
+
const message = {
|
|
258
|
+
role: 'assistant',
|
|
259
|
+
// OpenAI sets content to null when there are tool calls and no text content.
|
|
260
|
+
content: result.content || (hasTools ? null : ''),
|
|
261
|
+
};
|
|
262
|
+
if (hasTools)
|
|
263
|
+
message.tool_calls = toOAIToolCalls(result.toolCalls);
|
|
264
|
+
const usage = result.usage ?? {};
|
|
265
|
+
return {
|
|
266
|
+
id: completionId,
|
|
267
|
+
object: 'chat.completion',
|
|
268
|
+
created: Math.floor(Date.now() / 1000),
|
|
269
|
+
model,
|
|
270
|
+
choices: [{ index: 0, message, finish_reason: result.finishReason }],
|
|
271
|
+
usage: {
|
|
272
|
+
prompt_tokens: usage.promptTokens ?? 0,
|
|
273
|
+
completion_tokens: usage.completionTokens ?? 0,
|
|
274
|
+
total_tokens: (usage.promptTokens ?? 0) + (usage.completionTokens ?? 0),
|
|
275
|
+
},
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
/** Map `Float32Array[]` from `models.embed()` to an OpenAI embeddings response. */
|
|
279
|
+
function toEmbedResponse(vecs, model, usage) {
|
|
280
|
+
return {
|
|
281
|
+
object: 'list',
|
|
282
|
+
data: vecs.map((vec, index) => ({
|
|
283
|
+
embedding: Array.from(vec),
|
|
284
|
+
index,
|
|
285
|
+
object: 'embedding',
|
|
286
|
+
})),
|
|
287
|
+
model,
|
|
288
|
+
// Embeddings have no completion side, so OpenAI reports the same count in both
|
|
289
|
+
// fields. Harper backends spell it `embeddingTokens` (with `promptTokens` as a
|
|
290
|
+
// fallback for backends that report it that way); mapping must be symmetric —
|
|
291
|
+
// a backend supplying only embeddingTokens must not leave prompt_tokens at 0.
|
|
292
|
+
usage: {
|
|
293
|
+
prompt_tokens: usage?.embeddingTokens ?? usage?.promptTokens ?? 0,
|
|
294
|
+
total_tokens: usage?.embeddingTokens ?? usage?.promptTokens ?? 0,
|
|
295
|
+
},
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
//# sourceMappingURL=translation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"translation.js","sourceRoot":"","sources":["../../../../resources/models/v1/translation.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAgEH,8CAkCC;AAGD,wCAMC;AAO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AAC,CAAC,GAAG,CAAC,KAAK,CAAC,gBAAgB,IAAI,CAAC,CAAC;SACvE;KACD,CAAC;AACH,CAAC;AASD,mFAAmF;AACnF,SAAgB,eAAe,CAAC,IAAoB,EAAE,KAAa,EAAE,KAAkB;IACtF,OAAO;QACN,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;YAC/B,SAAS,EAAE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC;YAC1B,KAAK;YACL,MAAM,EAAE,WAAW;SACnB,CAAC,CAAC;QACH,KAAK;QACL,+EAA+E;QAC/E,+EAA+E;QAC/E,8EAA8E;QAC9E,8EAA8E;QAC9E,KAAK,EAAE;YACN,aAAa,EAAE,KAAK,EAAE,eAAe,IAAI,KAAK,EAAE,YAAY,IAAI,CAAC;YACjE,YAAY,EAAE,KAAK,EAAE,eAAe,IAAI,KAAK,EAAE,YAAY,IAAI,CAAC;SAChE;KACD,CAAC;AACH,CAAC"}
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
* This is the component for handling role declarations in the Harper system. This will read roles.yaml for role
|
|
3
3
|
* definitions and ensure that they are created in the system database.
|
|
4
4
|
*/
|
|
5
|
-
export declare function handleApplication(scope: import('../components/Scope.ts').Scope): void;
|
|
5
|
+
export declare function handleApplication(scope: import('../components/Scope.ts').Scope, ensureRoleFn?: (role: any) => Promise<unknown>): void;
|