@jami-studio/harness-config 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +159 -0
- package/README.md +44 -0
- package/model-catalog.json +257 -0
- package/model-catalog.schema.json +141 -0
- package/package.json +29 -0
- package/src/index.mjs +210 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
https://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction, and
|
|
10
|
+
distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by the
|
|
13
|
+
copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all other
|
|
16
|
+
entities that control, are controlled by, or are under common control with
|
|
17
|
+
that entity. For the purposes of this definition, "control" means (i) the
|
|
18
|
+
power, direct or indirect, to cause the direction or management of such
|
|
19
|
+
entity, whether by contract or otherwise, or (ii) ownership of fifty percent
|
|
20
|
+
or more of the outstanding shares, or (iii) beneficial ownership of such
|
|
21
|
+
entity.
|
|
22
|
+
|
|
23
|
+
"You" or "Your" shall mean an individual or Legal Entity exercising
|
|
24
|
+
permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation source, and
|
|
28
|
+
configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical transformation or
|
|
31
|
+
translation of a Source form, including but not limited to compiled object
|
|
32
|
+
code, generated documentation, and conversions to other media types.
|
|
33
|
+
|
|
34
|
+
"Work" shall mean the work of authorship, whether in Source or Object form,
|
|
35
|
+
made available under the License, as indicated by a copyright notice that is
|
|
36
|
+
included in or attached to the work.
|
|
37
|
+
|
|
38
|
+
"Derivative Works" shall mean any work, whether in Source or Object form,
|
|
39
|
+
that is based on or derived from the Work and for which the editorial
|
|
40
|
+
revisions, annotations, elaborations, or other modifications represent, as a
|
|
41
|
+
whole, an original work of authorship. For the purposes of this License,
|
|
42
|
+
Derivative Works shall not include works that remain separable from, or
|
|
43
|
+
merely link or bind by name to the interfaces of, the Work and Derivative
|
|
44
|
+
Works thereof.
|
|
45
|
+
|
|
46
|
+
"Contribution" shall mean any work of authorship, including the original
|
|
47
|
+
version of the Work and any modifications or additions to that Work or
|
|
48
|
+
Derivative Works thereof, that is intentionally submitted to Licensor for
|
|
49
|
+
inclusion in the Work by the copyright owner or by an individual or Legal
|
|
50
|
+
Entity authorized to submit on behalf of the copyright owner. For the purposes
|
|
51
|
+
of this definition, "submitted" means any form of electronic, verbal, or
|
|
52
|
+
written communication sent to the Licensor or its representatives, including
|
|
53
|
+
but not limited to communication on electronic mailing lists, source code
|
|
54
|
+
control systems, and issue tracking systems that are managed by, or on behalf
|
|
55
|
+
of, the Licensor for the purpose of discussing and improving the Work, but
|
|
56
|
+
excluding communication that is conspicuously marked or otherwise designated
|
|
57
|
+
in writing by the copyright owner as "Not a Contribution."
|
|
58
|
+
|
|
59
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on
|
|
60
|
+
behalf of whom a Contribution has been received by Licensor and subsequently
|
|
61
|
+
incorporated within the Work.
|
|
62
|
+
|
|
63
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this
|
|
64
|
+
License, each Contributor hereby grants to You a perpetual, worldwide,
|
|
65
|
+
non-exclusive, no-charge, royalty-free, irrevocable copyright license to
|
|
66
|
+
reproduce, prepare Derivative Works of, publicly display, publicly perform,
|
|
67
|
+
sublicense, and distribute the Work and such Derivative Works in Source or
|
|
68
|
+
Object form.
|
|
69
|
+
|
|
70
|
+
3. Grant of Patent License. Subject to the terms and conditions of this
|
|
71
|
+
License, each Contributor hereby grants to You a perpetual, worldwide,
|
|
72
|
+
non-exclusive, no-charge, royalty-free, irrevocable patent license to make,
|
|
73
|
+
have made, use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
74
|
+
where such license applies only to those patent claims licensable by such
|
|
75
|
+
Contributor that are necessarily infringed by their Contribution alone or by
|
|
76
|
+
combination of their Contribution with the Work to which such Contribution was
|
|
77
|
+
submitted. If You institute patent litigation against any entity alleging that
|
|
78
|
+
the Work or a Contribution incorporated within the Work constitutes direct or
|
|
79
|
+
contributory patent infringement, then any patent licenses granted to You
|
|
80
|
+
under this License for that Work shall terminate as of the date such
|
|
81
|
+
litigation is filed.
|
|
82
|
+
|
|
83
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or
|
|
84
|
+
Derivative Works thereof in any medium, with or without modifications, and in
|
|
85
|
+
Source or Object form, provided that You meet the following conditions:
|
|
86
|
+
|
|
87
|
+
(a) You must give any other recipients of the Work or Derivative Works a copy
|
|
88
|
+
of this License; and
|
|
89
|
+
|
|
90
|
+
(b) You must cause any modified files to carry prominent notices stating that
|
|
91
|
+
You changed the files; and
|
|
92
|
+
|
|
93
|
+
(c) You must retain, in the Source form of any Derivative Works that You
|
|
94
|
+
distribute, all copyright, patent, trademark, and attribution notices from the
|
|
95
|
+
Source form of the Work, excluding those notices that do not pertain to any
|
|
96
|
+
part of the Derivative Works; and
|
|
97
|
+
|
|
98
|
+
(d) If the Work includes a "NOTICE" text file as part of its distribution, then
|
|
99
|
+
any Derivative Works that You distribute must include a readable copy of the
|
|
100
|
+
attribution notices contained within such NOTICE file, excluding those notices
|
|
101
|
+
that do not pertain to any part of the Derivative Works, in at least one of
|
|
102
|
+
the following places: within a NOTICE text file distributed as part of the
|
|
103
|
+
Derivative Works; within the Source form or documentation, if provided along
|
|
104
|
+
with the Derivative Works; or within a display generated by the Derivative
|
|
105
|
+
Works, if and wherever such third-party notices normally appear. The contents
|
|
106
|
+
of the NOTICE file are for informational purposes only and do not modify the
|
|
107
|
+
License. You may add Your own attribution notices within Derivative Works that
|
|
108
|
+
You distribute, alongside or as an addendum to the NOTICE text from the Work,
|
|
109
|
+
provided that such additional attribution notices cannot be construed as
|
|
110
|
+
modifying the License.
|
|
111
|
+
|
|
112
|
+
You may add Your own copyright statement to Your modifications and may provide
|
|
113
|
+
additional or different license terms and conditions for use, reproduction, or
|
|
114
|
+
distribution of Your modifications, or for any such Derivative Works as a
|
|
115
|
+
whole, provided Your use, reproduction, and distribution of the Work otherwise
|
|
116
|
+
complies with the conditions stated in this License.
|
|
117
|
+
|
|
118
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any
|
|
119
|
+
Contribution intentionally submitted for inclusion in the Work by You to the
|
|
120
|
+
Licensor shall be under the terms and conditions of this License, without any
|
|
121
|
+
additional terms or conditions. Notwithstanding the above, nothing herein shall
|
|
122
|
+
supersede or modify the terms of any separate license agreement you may have
|
|
123
|
+
executed with Licensor regarding such Contributions.
|
|
124
|
+
|
|
125
|
+
6. Trademarks. This License does not grant permission to use the trade names,
|
|
126
|
+
trademarks, service marks, or product names of the Licensor, except as
|
|
127
|
+
required for reasonable and customary use in describing the origin of the Work
|
|
128
|
+
and reproducing the content of the NOTICE file.
|
|
129
|
+
|
|
130
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
|
|
131
|
+
writing, Licensor provides the Work on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
132
|
+
CONDITIONS OF ANY KIND, either express or implied, including, without
|
|
133
|
+
limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT,
|
|
134
|
+
MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely
|
|
135
|
+
responsible for determining the appropriateness of using or redistributing the
|
|
136
|
+
Work and assume any risks associated with Your exercise of permissions under
|
|
137
|
+
this License.
|
|
138
|
+
|
|
139
|
+
8. Limitation of Liability. In no event and under no legal theory, whether in
|
|
140
|
+
tort, contract, or otherwise, unless required by applicable law or agreed to in
|
|
141
|
+
writing, shall any Contributor be liable to You for damages, including any
|
|
142
|
+
direct, indirect, special, incidental, or consequential damages of any
|
|
143
|
+
character arising as a result of this License or out of the use or inability
|
|
144
|
+
to use the Work, including but not limited to damages for loss of goodwill,
|
|
145
|
+
work stoppage, computer failure or malfunction, or any and all other
|
|
146
|
+
commercial damages or losses, even if such Contributor has been advised of the
|
|
147
|
+
possibility of such damages.
|
|
148
|
+
|
|
149
|
+
9. Accepting Warranty or Additional Liability. While redistributing the Work or
|
|
150
|
+
Derivative Works thereof, You may choose to offer, and charge a fee for,
|
|
151
|
+
acceptance of support, warranty, indemnity, or other liability obligations
|
|
152
|
+
and/or rights consistent with this License. However, in accepting such
|
|
153
|
+
obligations, You may act only on Your own behalf and on Your sole
|
|
154
|
+
responsibility, not on behalf of any other Contributor, and only if You agree
|
|
155
|
+
to indemnify, defend, and hold each Contributor harmless for any liability
|
|
156
|
+
incurred by, or claims asserted against, such Contributor by reason of your
|
|
157
|
+
accepting any such warranty or additional liability.
|
|
158
|
+
|
|
159
|
+
END OF TERMS AND CONDITIONS
|
package/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# @jami-studio/harness-config
|
|
2
|
+
|
|
3
|
+
Source-locked **model catalog** for the harness `harness.provider.model` port.
|
|
4
|
+
|
|
5
|
+
The catalog is the single place where hosted provider/model metadata lives:
|
|
6
|
+
provider identity and BYOK environment variable names, per-model context window,
|
|
7
|
+
modality support (text / image / audio / tool-use), parameter bounds
|
|
8
|
+
(temperature, topP, maxOutputTokens), pricing, and per-provider source-lock
|
|
9
|
+
evidence (official documentation URLs + evidence date).
|
|
10
|
+
|
|
11
|
+
## Files
|
|
12
|
+
|
|
13
|
+
- `model-catalog.schema.json` — JSON Schema (draft 2020-12) for the catalog.
|
|
14
|
+
- `model-catalog.json` — the operator-maintained catalog data.
|
|
15
|
+
- `src/index.mjs` — loader + validator.
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
import { loadModelCatalog, getModel, validateModelCatalog, MODEL_CATALOG } from "@jami-studio/harness-config";
|
|
21
|
+
|
|
22
|
+
// Default catalog (already validated + frozen at import time).
|
|
23
|
+
const openaiGpt41 = getModel("provider_openai", "gpt-4.1");
|
|
24
|
+
console.log(openaiGpt41.contextWindowTokens); // 1047576
|
|
25
|
+
|
|
26
|
+
// Validate a custom catalog before use; loadModelCatalog throws on a bad one.
|
|
27
|
+
const { valid, errors } = validateModelCatalog(myCatalog);
|
|
28
|
+
const catalog = loadModelCatalog({ catalog: myCatalog });
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Fail-closed contract
|
|
32
|
+
|
|
33
|
+
`loadModelCatalog` validates against the bundled schema **and** a set of semantic
|
|
34
|
+
checks (no duplicate provider/model ids, `maxOutputTokens` within the context
|
|
35
|
+
window, consistent parameter bounds). A malformed catalog throws
|
|
36
|
+
`HarnessCatalogError` rather than returning a partially-trusted object, so no
|
|
37
|
+
hosted adapter can bind an unvalidated model.
|
|
38
|
+
|
|
39
|
+
## Maintenance
|
|
40
|
+
|
|
41
|
+
Pricing and model availability change frequently. Every provider entry carries a
|
|
42
|
+
`sourceLock` with the official documentation URLs and an `evidenceDate`; pricing
|
|
43
|
+
carries `pricedAsOf`. Operators must re-verify against those official sources
|
|
44
|
+
before relying on cost estimates or editing the model set.
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": "2026-06-24.model-catalog",
|
|
3
|
+
"generatedBy": "@jami-studio/harness-config seed catalog (JAMSTUD-4)",
|
|
4
|
+
"notes": "Operator-maintained, source-locked catalog for hosted BYOK adapters. Context windows, modalities, and parameter bounds are from each vendor's official documentation as of pricedAsOf/evidenceDate. Pricing and model availability move quickly: operators MUST re-verify against the linked official docs before relying on cost estimates or adding/removing models. The harness loader validates this file against model-catalog.schema.json and fails closed if it is malformed.",
|
|
5
|
+
"providers": [
|
|
6
|
+
{
|
|
7
|
+
"providerId": "provider_openai",
|
|
8
|
+
"displayName": "OpenAI",
|
|
9
|
+
"kind": "hosted",
|
|
10
|
+
"aiSdkPackage": "@ai-sdk/openai",
|
|
11
|
+
"auth": {
|
|
12
|
+
"type": "byok_bearer",
|
|
13
|
+
"apiKeyEnv": "JAMI_HARNESS_OPENAI_API_KEY",
|
|
14
|
+
"modelEnv": "JAMI_HARNESS_OPENAI_MODEL",
|
|
15
|
+
"baseUrlEnv": "JAMI_HARNESS_OPENAI_BASE_URL",
|
|
16
|
+
"keyPrefix": "sk-",
|
|
17
|
+
"minKeyLength": 20
|
|
18
|
+
},
|
|
19
|
+
"sourceLock": {
|
|
20
|
+
"sourceId": "openai-platform-models",
|
|
21
|
+
"evidenceDate": "2026-06-24",
|
|
22
|
+
"verification": "operator-maintained",
|
|
23
|
+
"officialDocs": [
|
|
24
|
+
"https://platform.openai.com/docs/models",
|
|
25
|
+
"https://platform.openai.com/docs/pricing"
|
|
26
|
+
]
|
|
27
|
+
},
|
|
28
|
+
"models": [
|
|
29
|
+
{
|
|
30
|
+
"modelId": "gpt-4.1",
|
|
31
|
+
"contextWindowTokens": 1047576,
|
|
32
|
+
"maxOutputTokens": 32768,
|
|
33
|
+
"modalities": { "inputText": true, "outputText": true, "inputImage": true, "toolUse": true },
|
|
34
|
+
"parameters": {
|
|
35
|
+
"temperature": { "min": 0, "max": 2, "default": 1 },
|
|
36
|
+
"topP": { "min": 0, "max": 1, "default": 1 },
|
|
37
|
+
"maxOutputTokens": { "min": 1, "max": 32768, "default": 4096 }
|
|
38
|
+
},
|
|
39
|
+
"pricing": { "currency": "USD", "inputPerMillionTokens": 2, "outputPerMillionTokens": 8, "cachedInputPerMillionTokens": 0.5, "pricedAsOf": "2026-06-24" }
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"modelId": "gpt-4o",
|
|
43
|
+
"contextWindowTokens": 128000,
|
|
44
|
+
"maxOutputTokens": 16384,
|
|
45
|
+
"modalities": { "inputText": true, "outputText": true, "inputImage": true, "toolUse": true },
|
|
46
|
+
"parameters": {
|
|
47
|
+
"temperature": { "min": 0, "max": 2, "default": 1 },
|
|
48
|
+
"topP": { "min": 0, "max": 1, "default": 1 },
|
|
49
|
+
"maxOutputTokens": { "min": 1, "max": 16384, "default": 4096 }
|
|
50
|
+
},
|
|
51
|
+
"pricing": { "currency": "USD", "inputPerMillionTokens": 2.5, "outputPerMillionTokens": 10, "cachedInputPerMillionTokens": 1.25, "pricedAsOf": "2026-06-24" }
|
|
52
|
+
}
|
|
53
|
+
]
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"providerId": "provider_anthropic",
|
|
57
|
+
"displayName": "Anthropic",
|
|
58
|
+
"kind": "hosted",
|
|
59
|
+
"aiSdkPackage": "@ai-sdk/anthropic",
|
|
60
|
+
"auth": {
|
|
61
|
+
"type": "byok_header",
|
|
62
|
+
"apiKeyEnv": "JAMI_HARNESS_ANTHROPIC_API_KEY",
|
|
63
|
+
"modelEnv": "JAMI_HARNESS_ANTHROPIC_MODEL",
|
|
64
|
+
"baseUrlEnv": "JAMI_HARNESS_ANTHROPIC_BASE_URL",
|
|
65
|
+
"keyPrefix": "sk-ant-",
|
|
66
|
+
"minKeyLength": 20
|
|
67
|
+
},
|
|
68
|
+
"sourceLock": {
|
|
69
|
+
"sourceId": "anthropic-models-overview",
|
|
70
|
+
"evidenceDate": "2026-06-24",
|
|
71
|
+
"verification": "operator-maintained",
|
|
72
|
+
"officialDocs": [
|
|
73
|
+
"https://docs.anthropic.com/en/docs/about-claude/models/overview",
|
|
74
|
+
"https://docs.anthropic.com/en/docs/about-claude/pricing"
|
|
75
|
+
]
|
|
76
|
+
},
|
|
77
|
+
"models": [
|
|
78
|
+
{
|
|
79
|
+
"modelId": "claude-sonnet-4-20250514",
|
|
80
|
+
"aliases": ["claude-sonnet-4"],
|
|
81
|
+
"contextWindowTokens": 200000,
|
|
82
|
+
"maxOutputTokens": 64000,
|
|
83
|
+
"modalities": { "inputText": true, "outputText": true, "inputImage": true, "toolUse": true },
|
|
84
|
+
"parameters": {
|
|
85
|
+
"temperature": { "min": 0, "max": 1, "default": 1 },
|
|
86
|
+
"topP": { "min": 0, "max": 1, "default": 1 },
|
|
87
|
+
"maxOutputTokens": { "min": 1, "max": 64000, "default": 8192 }
|
|
88
|
+
},
|
|
89
|
+
"pricing": { "currency": "USD", "inputPerMillionTokens": 3, "outputPerMillionTokens": 15, "cachedInputPerMillionTokens": 0.3, "pricedAsOf": "2026-06-24" }
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
"modelId": "claude-3-5-haiku-latest",
|
|
93
|
+
"contextWindowTokens": 200000,
|
|
94
|
+
"maxOutputTokens": 8192,
|
|
95
|
+
"modalities": { "inputText": true, "outputText": true, "inputImage": true, "toolUse": true },
|
|
96
|
+
"parameters": {
|
|
97
|
+
"temperature": { "min": 0, "max": 1, "default": 1 },
|
|
98
|
+
"topP": { "min": 0, "max": 1, "default": 1 },
|
|
99
|
+
"maxOutputTokens": { "min": 1, "max": 8192, "default": 4096 }
|
|
100
|
+
},
|
|
101
|
+
"pricing": { "currency": "USD", "inputPerMillionTokens": 0.8, "outputPerMillionTokens": 4, "cachedInputPerMillionTokens": 0.08, "pricedAsOf": "2026-06-24" }
|
|
102
|
+
}
|
|
103
|
+
]
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
"providerId": "provider_google",
|
|
107
|
+
"displayName": "Google Gemini",
|
|
108
|
+
"kind": "hosted",
|
|
109
|
+
"aiSdkPackage": "@ai-sdk/google",
|
|
110
|
+
"auth": {
|
|
111
|
+
"type": "byok_header",
|
|
112
|
+
"apiKeyEnv": "JAMI_HARNESS_GOOGLE_API_KEY",
|
|
113
|
+
"modelEnv": "JAMI_HARNESS_GOOGLE_MODEL",
|
|
114
|
+
"baseUrlEnv": "JAMI_HARNESS_GOOGLE_BASE_URL",
|
|
115
|
+
"minKeyLength": 20
|
|
116
|
+
},
|
|
117
|
+
"sourceLock": {
|
|
118
|
+
"sourceId": "google-gemini-models",
|
|
119
|
+
"evidenceDate": "2026-06-24",
|
|
120
|
+
"verification": "operator-maintained",
|
|
121
|
+
"officialDocs": [
|
|
122
|
+
"https://ai.google.dev/gemini-api/docs/models",
|
|
123
|
+
"https://ai.google.dev/gemini-api/docs/pricing"
|
|
124
|
+
]
|
|
125
|
+
},
|
|
126
|
+
"models": [
|
|
127
|
+
{
|
|
128
|
+
"modelId": "gemini-2.5-pro",
|
|
129
|
+
"contextWindowTokens": 1048576,
|
|
130
|
+
"maxOutputTokens": 65536,
|
|
131
|
+
"modalities": { "inputText": true, "outputText": true, "inputImage": true, "inputAudio": true, "toolUse": true },
|
|
132
|
+
"parameters": {
|
|
133
|
+
"temperature": { "min": 0, "max": 2, "default": 1 },
|
|
134
|
+
"topP": { "min": 0, "max": 1, "default": 0.95 },
|
|
135
|
+
"maxOutputTokens": { "min": 1, "max": 65536, "default": 8192 }
|
|
136
|
+
},
|
|
137
|
+
"pricing": { "currency": "USD", "inputPerMillionTokens": 1.25, "outputPerMillionTokens": 10, "pricedAsOf": "2026-06-24" }
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
"modelId": "gemini-2.0-flash",
|
|
141
|
+
"contextWindowTokens": 1048576,
|
|
142
|
+
"maxOutputTokens": 8192,
|
|
143
|
+
"modalities": { "inputText": true, "outputText": true, "inputImage": true, "inputAudio": true, "toolUse": true },
|
|
144
|
+
"parameters": {
|
|
145
|
+
"temperature": { "min": 0, "max": 2, "default": 1 },
|
|
146
|
+
"topP": { "min": 0, "max": 1, "default": 0.95 },
|
|
147
|
+
"maxOutputTokens": { "min": 1, "max": 8192, "default": 4096 }
|
|
148
|
+
},
|
|
149
|
+
"pricing": { "currency": "USD", "inputPerMillionTokens": 0.1, "outputPerMillionTokens": 0.4, "pricedAsOf": "2026-06-24" }
|
|
150
|
+
}
|
|
151
|
+
]
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
"providerId": "provider_xai",
|
|
155
|
+
"displayName": "xAI Grok",
|
|
156
|
+
"kind": "hosted",
|
|
157
|
+
"aiSdkPackage": "@ai-sdk/xai",
|
|
158
|
+
"auth": {
|
|
159
|
+
"type": "byok_bearer",
|
|
160
|
+
"apiKeyEnv": "JAMI_HARNESS_XAI_API_KEY",
|
|
161
|
+
"modelEnv": "JAMI_HARNESS_XAI_MODEL",
|
|
162
|
+
"baseUrlEnv": "JAMI_HARNESS_XAI_BASE_URL",
|
|
163
|
+
"keyPrefix": "xai-",
|
|
164
|
+
"minKeyLength": 20
|
|
165
|
+
},
|
|
166
|
+
"sourceLock": {
|
|
167
|
+
"sourceId": "xai-models",
|
|
168
|
+
"evidenceDate": "2026-06-24",
|
|
169
|
+
"verification": "operator-maintained",
|
|
170
|
+
"officialDocs": [
|
|
171
|
+
"https://docs.x.ai/docs/models",
|
|
172
|
+
"https://docs.x.ai/docs/pricing"
|
|
173
|
+
]
|
|
174
|
+
},
|
|
175
|
+
"models": [
|
|
176
|
+
{
|
|
177
|
+
"modelId": "grok-4",
|
|
178
|
+
"contextWindowTokens": 256000,
|
|
179
|
+
"maxOutputTokens": 8192,
|
|
180
|
+
"modalities": { "inputText": true, "outputText": true, "inputImage": true, "toolUse": true },
|
|
181
|
+
"parameters": {
|
|
182
|
+
"temperature": { "min": 0, "max": 2, "default": 1 },
|
|
183
|
+
"topP": { "min": 0, "max": 1, "default": 1 },
|
|
184
|
+
"maxOutputTokens": { "min": 1, "max": 8192, "default": 4096 }
|
|
185
|
+
},
|
|
186
|
+
"pricing": { "currency": "USD", "inputPerMillionTokens": 3, "outputPerMillionTokens": 15, "cachedInputPerMillionTokens": 0.75, "pricedAsOf": "2026-06-24" }
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
"modelId": "grok-3",
|
|
190
|
+
"contextWindowTokens": 131072,
|
|
191
|
+
"maxOutputTokens": 8192,
|
|
192
|
+
"modalities": { "inputText": true, "outputText": true, "toolUse": true },
|
|
193
|
+
"parameters": {
|
|
194
|
+
"temperature": { "min": 0, "max": 2, "default": 1 },
|
|
195
|
+
"topP": { "min": 0, "max": 1, "default": 1 },
|
|
196
|
+
"maxOutputTokens": { "min": 1, "max": 8192, "default": 4096 }
|
|
197
|
+
},
|
|
198
|
+
"pricing": { "currency": "USD", "inputPerMillionTokens": 3, "outputPerMillionTokens": 15, "pricedAsOf": "2026-06-24" }
|
|
199
|
+
}
|
|
200
|
+
]
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
"providerId": "provider_bedrock",
|
|
204
|
+
"displayName": "Amazon Bedrock",
|
|
205
|
+
"kind": "hosted",
|
|
206
|
+
"aiSdkPackage": "@ai-sdk/amazon-bedrock",
|
|
207
|
+
"auth": {
|
|
208
|
+
"type": "byok_header",
|
|
209
|
+
"apiKeyEnv": "AWS_ACCESS_KEY_ID",
|
|
210
|
+
"secretKeyEnv": "AWS_SECRET_ACCESS_KEY",
|
|
211
|
+
"sessionTokenEnv": "AWS_SESSION_TOKEN",
|
|
212
|
+
"regionEnv": "AWS_REGION",
|
|
213
|
+
"modelEnv": "JAMI_HARNESS_BEDROCK_MODEL",
|
|
214
|
+
"baseUrlEnv": "JAMI_HARNESS_BEDROCK_BASE_URL",
|
|
215
|
+
"minKeyLength": 16
|
|
216
|
+
},
|
|
217
|
+
"sourceLock": {
|
|
218
|
+
"sourceId": "amazon-bedrock-ai-sdk-provider",
|
|
219
|
+
"evidenceDate": "2026-07-01",
|
|
220
|
+
"verification": "operator-maintained",
|
|
221
|
+
"officialDocs": [
|
|
222
|
+
"https://ai-sdk.dev/providers/ai-sdk-providers/amazon-bedrock",
|
|
223
|
+
"https://docs.aws.amazon.com/bedrock/latest/userguide/models-supported.html",
|
|
224
|
+
"https://aws.amazon.com/bedrock/pricing/"
|
|
225
|
+
]
|
|
226
|
+
},
|
|
227
|
+
"models": [
|
|
228
|
+
{
|
|
229
|
+
"modelId": "us.amazon.nova-micro-v1:0",
|
|
230
|
+
"aliases": ["amazon.nova-micro-v1:0"],
|
|
231
|
+
"contextWindowTokens": 128000,
|
|
232
|
+
"maxOutputTokens": 5000,
|
|
233
|
+
"modalities": { "inputText": true, "outputText": true, "toolUse": true },
|
|
234
|
+
"parameters": {
|
|
235
|
+
"temperature": { "min": 0, "max": 1, "default": 0.7 },
|
|
236
|
+
"topP": { "min": 0, "max": 1, "default": 0.9 },
|
|
237
|
+
"maxOutputTokens": { "min": 1, "max": 5000, "default": 1024 }
|
|
238
|
+
},
|
|
239
|
+
"pricing": { "currency": "USD", "inputPerMillionTokens": 0.035, "outputPerMillionTokens": 0.14, "pricedAsOf": "2026-07-01" }
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
"modelId": "us.amazon.nova-lite-v1:0",
|
|
243
|
+
"aliases": ["amazon.nova-lite-v1:0"],
|
|
244
|
+
"contextWindowTokens": 300000,
|
|
245
|
+
"maxOutputTokens": 5000,
|
|
246
|
+
"modalities": { "inputText": true, "outputText": true, "inputImage": true, "toolUse": true },
|
|
247
|
+
"parameters": {
|
|
248
|
+
"temperature": { "min": 0, "max": 1, "default": 0.7 },
|
|
249
|
+
"topP": { "min": 0, "max": 1, "default": 0.9 },
|
|
250
|
+
"maxOutputTokens": { "min": 1, "max": 5000, "default": 1024 }
|
|
251
|
+
},
|
|
252
|
+
"pricing": { "currency": "USD", "inputPerMillionTokens": 0.06, "outputPerMillionTokens": 0.24, "pricedAsOf": "2026-07-01" }
|
|
253
|
+
}
|
|
254
|
+
]
|
|
255
|
+
}
|
|
256
|
+
]
|
|
257
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://jami.studio/schemas/harness/model-catalog.schema.json",
|
|
4
|
+
"title": "modelCatalog",
|
|
5
|
+
"description": "Source-locked catalog of hosted model providers and models that the harness.provider.model port can route to. Operators maintain this file; the loader validates it before any hosted adapter binds a model.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"required": ["schemaVersion", "generatedBy", "providers"],
|
|
8
|
+
"additionalProperties": false,
|
|
9
|
+
"properties": {
|
|
10
|
+
"schemaVersion": { "const": "2026-06-24.model-catalog" },
|
|
11
|
+
"generatedBy": { "type": "string", "minLength": 1 },
|
|
12
|
+
"notes": { "type": "string" },
|
|
13
|
+
"providers": {
|
|
14
|
+
"type": "array",
|
|
15
|
+
"minItems": 1,
|
|
16
|
+
"items": { "$ref": "#/$defs/provider" }
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"$defs": {
|
|
20
|
+
"provider": {
|
|
21
|
+
"type": "object",
|
|
22
|
+
"required": ["providerId", "displayName", "kind", "auth", "sourceLock", "models"],
|
|
23
|
+
"additionalProperties": false,
|
|
24
|
+
"properties": {
|
|
25
|
+
"providerId": { "type": "string", "pattern": "^provider_[a-z0-9][a-z0-9_-]*$" },
|
|
26
|
+
"displayName": { "type": "string", "minLength": 1 },
|
|
27
|
+
"kind": { "type": "string", "enum": ["hosted", "local"] },
|
|
28
|
+
"aiSdkPackage": { "type": "string" },
|
|
29
|
+
"auth": { "$ref": "#/$defs/auth" },
|
|
30
|
+
"sourceLock": { "$ref": "#/$defs/sourceLock" },
|
|
31
|
+
"models": {
|
|
32
|
+
"type": "array",
|
|
33
|
+
"minItems": 1,
|
|
34
|
+
"items": { "$ref": "#/$defs/model" }
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"auth": {
|
|
39
|
+
"type": "object",
|
|
40
|
+
"required": ["type", "apiKeyEnv", "modelEnv"],
|
|
41
|
+
"additionalProperties": false,
|
|
42
|
+
"properties": {
|
|
43
|
+
"type": { "type": "string", "enum": ["byok_bearer", "byok_header", "none"] },
|
|
44
|
+
"apiKeyEnv": { "type": "string", "pattern": "^[A-Z][A-Z0-9_]*$" },
|
|
45
|
+
"modelEnv": { "type": "string", "pattern": "^[A-Z][A-Z0-9_]*$" },
|
|
46
|
+
"baseUrlEnv": { "type": "string", "pattern": "^[A-Z][A-Z0-9_]*$" },
|
|
47
|
+
"secretKeyEnv": { "type": "string", "pattern": "^[A-Z][A-Z0-9_]*$" },
|
|
48
|
+
"sessionTokenEnv": { "type": "string", "pattern": "^[A-Z][A-Z0-9_]*$" },
|
|
49
|
+
"regionEnv": { "type": "string", "pattern": "^[A-Z][A-Z0-9_]*$" },
|
|
50
|
+
"keyPrefix": { "type": "string" },
|
|
51
|
+
"minKeyLength": { "type": "integer", "minimum": 1 }
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
"sourceLock": {
|
|
55
|
+
"type": "object",
|
|
56
|
+
"required": ["sourceId", "evidenceDate", "officialDocs"],
|
|
57
|
+
"additionalProperties": false,
|
|
58
|
+
"properties": {
|
|
59
|
+
"sourceId": { "type": "string", "minLength": 1 },
|
|
60
|
+
"evidenceDate": { "type": "string", "format": "date" },
|
|
61
|
+
"verification": {
|
|
62
|
+
"type": "string",
|
|
63
|
+
"enum": ["operator-maintained", "vendor-documented", "first-party"]
|
|
64
|
+
},
|
|
65
|
+
"officialDocs": {
|
|
66
|
+
"type": "array",
|
|
67
|
+
"minItems": 1,
|
|
68
|
+
"items": { "type": "string", "pattern": "^https://" }
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
"model": {
|
|
73
|
+
"type": "object",
|
|
74
|
+
"required": ["modelId", "contextWindowTokens", "maxOutputTokens", "modalities", "parameters"],
|
|
75
|
+
"additionalProperties": false,
|
|
76
|
+
"properties": {
|
|
77
|
+
"modelId": { "type": "string", "minLength": 1 },
|
|
78
|
+
"aliases": { "type": "array", "items": { "type": "string" } },
|
|
79
|
+
"contextWindowTokens": { "type": "integer", "minimum": 1 },
|
|
80
|
+
"maxOutputTokens": { "type": "integer", "minimum": 1 },
|
|
81
|
+
"modalities": { "$ref": "#/$defs/modalities" },
|
|
82
|
+
"parameters": { "$ref": "#/$defs/parameters" },
|
|
83
|
+
"pricing": { "$ref": "#/$defs/pricing" },
|
|
84
|
+
"deprecated": { "type": "boolean" }
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
"modalities": {
|
|
88
|
+
"type": "object",
|
|
89
|
+
"required": ["inputText", "outputText"],
|
|
90
|
+
"additionalProperties": false,
|
|
91
|
+
"properties": {
|
|
92
|
+
"inputText": { "type": "boolean" },
|
|
93
|
+
"outputText": { "type": "boolean" },
|
|
94
|
+
"inputImage": { "type": "boolean" },
|
|
95
|
+
"inputAudio": { "type": "boolean" },
|
|
96
|
+
"toolUse": { "type": "boolean" }
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
"parameters": {
|
|
100
|
+
"type": "object",
|
|
101
|
+
"additionalProperties": false,
|
|
102
|
+
"properties": {
|
|
103
|
+
"temperature": { "$ref": "#/$defs/bound" },
|
|
104
|
+
"topP": { "$ref": "#/$defs/bound" },
|
|
105
|
+
"maxOutputTokens": { "$ref": "#/$defs/intBound" }
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
"bound": {
|
|
109
|
+
"type": "object",
|
|
110
|
+
"required": ["min", "max", "default"],
|
|
111
|
+
"additionalProperties": false,
|
|
112
|
+
"properties": {
|
|
113
|
+
"min": { "type": "number" },
|
|
114
|
+
"max": { "type": "number" },
|
|
115
|
+
"default": { "type": "number" }
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
"intBound": {
|
|
119
|
+
"type": "object",
|
|
120
|
+
"required": ["min", "max", "default"],
|
|
121
|
+
"additionalProperties": false,
|
|
122
|
+
"properties": {
|
|
123
|
+
"min": { "type": "integer", "minimum": 1 },
|
|
124
|
+
"max": { "type": "integer", "minimum": 1 },
|
|
125
|
+
"default": { "type": "integer", "minimum": 1 }
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
"pricing": {
|
|
129
|
+
"type": "object",
|
|
130
|
+
"required": ["currency", "inputPerMillionTokens", "outputPerMillionTokens", "pricedAsOf"],
|
|
131
|
+
"additionalProperties": false,
|
|
132
|
+
"properties": {
|
|
133
|
+
"currency": { "type": "string", "pattern": "^[A-Z]{3}$" },
|
|
134
|
+
"inputPerMillionTokens": { "type": "number", "minimum": 0 },
|
|
135
|
+
"outputPerMillionTokens": { "type": "number", "minimum": 0 },
|
|
136
|
+
"cachedInputPerMillionTokens": { "type": "number", "minimum": 0 },
|
|
137
|
+
"pricedAsOf": { "type": "string", "format": "date" }
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jami-studio/harness-config",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Source-locked model catalog schema and loader for Jami Harness hosted provider routing.",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/studio-jami/jami-harness.git",
|
|
10
|
+
"directory": "packages/config"
|
|
11
|
+
},
|
|
12
|
+
"exports": {
|
|
13
|
+
".": "./src/index.mjs",
|
|
14
|
+
"./model-catalog.schema.json": "./model-catalog.schema.json",
|
|
15
|
+
"./model-catalog.json": "./model-catalog.json"
|
|
16
|
+
},
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"src/",
|
|
22
|
+
"model-catalog.schema.json",
|
|
23
|
+
"model-catalog.json",
|
|
24
|
+
"README.md"
|
|
25
|
+
],
|
|
26
|
+
"jamiRelease": {
|
|
27
|
+
"publishable": true
|
|
28
|
+
}
|
|
29
|
+
}
|
package/src/index.mjs
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
|
|
5
|
+
const packageRoot = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
6
|
+
const SCHEMA_PATH = join(packageRoot, "model-catalog.schema.json");
|
|
7
|
+
const CATALOG_PATH = join(packageRoot, "model-catalog.json");
|
|
8
|
+
|
|
9
|
+
export class HarnessCatalogError extends Error {
|
|
10
|
+
constructor(code, message, details = []) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = "HarnessCatalogError";
|
|
13
|
+
this.code = code;
|
|
14
|
+
this.details = details;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const MODEL_CATALOG_SCHEMA = Object.freeze(readJson(SCHEMA_PATH));
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Validate a model catalog object against the bundled JSON Schema.
|
|
22
|
+
* Returns { valid, errors } and never throws on a malformed catalog value.
|
|
23
|
+
*/
|
|
24
|
+
export function validateModelCatalog(catalog, schema = MODEL_CATALOG_SCHEMA) {
|
|
25
|
+
const errors = validateNode(schema, schema, catalog, "$");
|
|
26
|
+
if (errors.length === 0) {
|
|
27
|
+
const semantic = validateSemantics(catalog);
|
|
28
|
+
return { valid: semantic.length === 0, errors: semantic };
|
|
29
|
+
}
|
|
30
|
+
return { valid: false, errors };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Load, validate, and freeze the model catalog. Fails closed (throws) when the
|
|
35
|
+
* catalog is malformed so that no hosted adapter can bind an unvalidated model.
|
|
36
|
+
*/
|
|
37
|
+
export function loadModelCatalog(options = {}) {
|
|
38
|
+
const catalog = options.catalog ?? readJson(options.path ?? CATALOG_PATH);
|
|
39
|
+
const { valid, errors } = validateModelCatalog(catalog, options.schema ?? MODEL_CATALOG_SCHEMA);
|
|
40
|
+
if (!valid) {
|
|
41
|
+
throw new HarnessCatalogError("invalid_catalog", `model catalog failed validation: ${errors.slice(0, 8).join("; ")}`, errors);
|
|
42
|
+
}
|
|
43
|
+
return deepFreeze(catalog);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const MODEL_CATALOG = loadModelCatalog();
|
|
47
|
+
|
|
48
|
+
export function listProviders(catalog = MODEL_CATALOG) {
|
|
49
|
+
return catalog.providers.map((provider) => provider.providerId);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function getProvider(providerId, catalog = MODEL_CATALOG) {
|
|
53
|
+
return catalog.providers.find((provider) => provider.providerId === providerId);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function listModels(providerId, catalog = MODEL_CATALOG) {
|
|
57
|
+
const provider = getProvider(providerId, catalog);
|
|
58
|
+
return provider ? provider.models.map((model) => model.modelId) : [];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Resolve a model by id or alias within a provider. Returns the model entry
|
|
63
|
+
* (with a back-reference to its provider) or undefined when not catalogued.
|
|
64
|
+
*/
|
|
65
|
+
export function getModel(providerId, modelId, catalog = MODEL_CATALOG) {
|
|
66
|
+
const provider = getProvider(providerId, catalog);
|
|
67
|
+
if (!provider || typeof modelId !== "string") return undefined;
|
|
68
|
+
const model = provider.models.find(
|
|
69
|
+
(entry) => entry.modelId === modelId || (Array.isArray(entry.aliases) && entry.aliases.includes(modelId)),
|
|
70
|
+
);
|
|
71
|
+
if (!model) return undefined;
|
|
72
|
+
return { ...model, providerId, provider };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function validateSemantics(catalog) {
|
|
76
|
+
const errors = [];
|
|
77
|
+
const providerIds = new Set();
|
|
78
|
+
for (const provider of catalog.providers ?? []) {
|
|
79
|
+
if (providerIds.has(provider.providerId)) errors.push(`duplicate providerId ${provider.providerId}`);
|
|
80
|
+
providerIds.add(provider.providerId);
|
|
81
|
+
const modelIds = new Set();
|
|
82
|
+
for (const model of provider.models ?? []) {
|
|
83
|
+
const key = `${provider.providerId}/${model.modelId}`;
|
|
84
|
+
if (modelIds.has(model.modelId)) errors.push(`duplicate modelId ${key}`);
|
|
85
|
+
modelIds.add(model.modelId);
|
|
86
|
+
if (model.maxOutputTokens > model.contextWindowTokens) {
|
|
87
|
+
errors.push(`${key} maxOutputTokens exceeds contextWindowTokens`);
|
|
88
|
+
}
|
|
89
|
+
const bound = model.parameters?.maxOutputTokens;
|
|
90
|
+
if (bound && bound.max > model.maxOutputTokens) {
|
|
91
|
+
errors.push(`${key} parameters.maxOutputTokens.max exceeds model maxOutputTokens`);
|
|
92
|
+
}
|
|
93
|
+
for (const [name, b] of Object.entries(model.parameters ?? {})) {
|
|
94
|
+
if (b && (b.default < b.min || b.default > b.max || b.min > b.max)) {
|
|
95
|
+
errors.push(`${key} parameter ${name} bounds are inconsistent`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return errors;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// --- Minimal JSON Schema (draft 2020-12 subset) validator -----------------
|
|
104
|
+
// Supports the constructs used by model-catalog.schema.json: const, enum, type,
|
|
105
|
+
// pattern, format(date/date-time), minLength, minItems, minimum, required,
|
|
106
|
+
// additionalProperties:false, properties, items, and local $ref (#/...).
|
|
107
|
+
function validateNode(root, schema, value, path) {
|
|
108
|
+
if (schema.$ref) {
|
|
109
|
+
return validateNode(root, resolveRef(root, schema.$ref), value, path);
|
|
110
|
+
}
|
|
111
|
+
const errors = [];
|
|
112
|
+
|
|
113
|
+
if (schema.const !== undefined && value !== schema.const) {
|
|
114
|
+
errors.push(`${path} must equal ${JSON.stringify(schema.const)}`);
|
|
115
|
+
}
|
|
116
|
+
if (schema.enum && !schema.enum.includes(value)) {
|
|
117
|
+
errors.push(`${path} must be one of ${schema.enum.join(", ")}`);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (schema.type) {
|
|
121
|
+
const accepted = Array.isArray(schema.type) ? schema.type : [schema.type];
|
|
122
|
+
if (!accepted.some((type) => matchesType(type, value))) {
|
|
123
|
+
errors.push(`${path} must be ${accepted.join(" or ")}`);
|
|
124
|
+
return errors;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (typeof value === "string") {
|
|
129
|
+
if (schema.minLength !== undefined && value.length < schema.minLength) {
|
|
130
|
+
errors.push(`${path} must be at least ${schema.minLength} characters`);
|
|
131
|
+
}
|
|
132
|
+
if (schema.pattern && !new RegExp(schema.pattern).test(value)) {
|
|
133
|
+
errors.push(`${path} must match ${schema.pattern}`);
|
|
134
|
+
}
|
|
135
|
+
if (schema.format === "date-time" && Number.isNaN(Date.parse(value))) {
|
|
136
|
+
errors.push(`${path} must be a date-time`);
|
|
137
|
+
}
|
|
138
|
+
if (schema.format === "date" && !/^\d{4}-\d{2}-\d{2}$/.test(value)) {
|
|
139
|
+
errors.push(`${path} must be a date (YYYY-MM-DD)`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (typeof value === "number") {
|
|
144
|
+
if (schema.minimum !== undefined && value < schema.minimum) {
|
|
145
|
+
errors.push(`${path} must be >= ${schema.minimum}`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (Array.isArray(value)) {
|
|
150
|
+
if (schema.minItems !== undefined && value.length < schema.minItems) {
|
|
151
|
+
errors.push(`${path} must contain at least ${schema.minItems} items`);
|
|
152
|
+
}
|
|
153
|
+
if (schema.items) {
|
|
154
|
+
value.forEach((item, index) => errors.push(...validateNode(root, schema.items, item, `${path}[${index}]`)));
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (value !== null && typeof value === "object" && !Array.isArray(value)) {
|
|
159
|
+
for (const key of schema.required ?? []) {
|
|
160
|
+
if (!(key in value)) errors.push(`${path}.${key} is required`);
|
|
161
|
+
}
|
|
162
|
+
const properties = schema.properties ?? {};
|
|
163
|
+
if (schema.additionalProperties === false) {
|
|
164
|
+
for (const key of Object.keys(value)) {
|
|
165
|
+
if (!(key in properties)) errors.push(`${path}.${key} is not allowed`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
for (const [key, propertySchema] of Object.entries(properties)) {
|
|
169
|
+
if (key in value) errors.push(...validateNode(root, propertySchema, value[key], `${path}.${key}`));
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return errors;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function matchesType(type, value) {
|
|
177
|
+
if (type === "integer") return Number.isInteger(value);
|
|
178
|
+
if (type === "number") return typeof value === "number";
|
|
179
|
+
if (type === "array") return Array.isArray(value);
|
|
180
|
+
if (type === "object") return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
181
|
+
if (type === "null") return value === null;
|
|
182
|
+
return typeof value === type;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function resolveRef(root, ref) {
|
|
186
|
+
if (!ref.startsWith("#/")) {
|
|
187
|
+
throw new HarnessCatalogError("unsupported_ref", `only local refs are supported: ${ref}`);
|
|
188
|
+
}
|
|
189
|
+
const segments = ref.slice(2).split("/");
|
|
190
|
+
let node = root;
|
|
191
|
+
for (const segment of segments) {
|
|
192
|
+
node = node?.[decodeURIComponent(segment.replace(/~1/g, "/").replace(/~0/g, "~"))];
|
|
193
|
+
if (node === undefined) {
|
|
194
|
+
throw new HarnessCatalogError("unresolved_ref", `cannot resolve ${ref}`);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return node;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function readJson(path) {
|
|
201
|
+
return JSON.parse(readFileSync(path, "utf8"));
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function deepFreeze(value) {
|
|
205
|
+
if (value && typeof value === "object") {
|
|
206
|
+
for (const child of Object.values(value)) deepFreeze(child);
|
|
207
|
+
Object.freeze(value);
|
|
208
|
+
}
|
|
209
|
+
return value;
|
|
210
|
+
}
|