@jsonfirst/sdk 1.0.1 → 1.2.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/README.md +36 -0
- package/index.js +109 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -43,6 +43,42 @@ const client = new JsonFirst({
|
|
|
43
43
|
});
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
+
## Governance Modes
|
|
47
|
+
|
|
48
|
+
All 22 modes are available via `JsonFirst.MODES` or `client.modes()`.
|
|
49
|
+
|
|
50
|
+
| Mode | Plan | Category |
|
|
51
|
+
|------|------|----------|
|
|
52
|
+
| `ANTI_CREDIT_WASTE_V2` | free+ | efficiency |
|
|
53
|
+
| `EXPRESS_ROUTE` | explorer+ | speed |
|
|
54
|
+
| `STRICT_PROTOCOL` | explorer+ | compliance |
|
|
55
|
+
| `PERFORMANCE_MAX` | explorer+ | performance |
|
|
56
|
+
| `GUARDIAN_MODE` | explorer+ | safety |
|
|
57
|
+
| `FINANCE_ALGO` | explorer+ | finance |
|
|
58
|
+
| `ETHICAL_LOCK` | explorer+ | ethics |
|
|
59
|
+
| `SCOPE_LIMITER` | pro+ | governance |
|
|
60
|
+
| `SAFE_DEPLOY` | pro+ | deployment |
|
|
61
|
+
| `STANDARD_DEPLOY` | pro+ | deployment |
|
|
62
|
+
| `FAST_BUILD` | pro+ | build |
|
|
63
|
+
| `PRODUCTION_LOCK` | pro+ | deployment |
|
|
64
|
+
| `MEDICAL_EXPERT` | business+ | domain_lock |
|
|
65
|
+
| `LEGAL_EXPERT` | business+ | domain_lock |
|
|
66
|
+
| `FINANCE_EXPERT` | business+ | domain_lock |
|
|
67
|
+
| `CYBERSECURITY_EXPERT` | business+ | domain_lock |
|
|
68
|
+
| `SOFTWARE_ENGINEERING_EXPERT` | business+ | domain_lock |
|
|
69
|
+
| `AI_RESEARCH_EXPERT` | business+ | domain_lock |
|
|
70
|
+
| `NEWS_ANALYSIS_EXPERT` | business+ | domain_lock |
|
|
71
|
+
| `SCIENTIFIC_RESEARCH_EXPERT` | business+ | domain_lock |
|
|
72
|
+
| `BUSINESS_STRATEGY_EXPERT` | business+ | domain_lock |
|
|
73
|
+
| `DATA_SCIENCE_EXPERT` | business+ | domain_lock |
|
|
74
|
+
|
|
75
|
+
```javascript
|
|
76
|
+
// Access modes programmatically
|
|
77
|
+
const JsonFirst = require('@jsonfirst/sdk');
|
|
78
|
+
console.log(JsonFirst.MODE_IDS); // array of 22 mode IDs
|
|
79
|
+
console.log(JsonFirst.MODES['MEDICAL_EXPERT']); // { plan, category, description }
|
|
80
|
+
```
|
|
81
|
+
|
|
46
82
|
## Links
|
|
47
83
|
|
|
48
84
|
- [Documentation](https://jsonfirst.com/developers)
|
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @jsonfirst/sdk v1.
|
|
2
|
+
* @jsonfirst/sdk v1.2.0
|
|
3
3
|
* Official JavaScript/Node.js SDK for the JSONFIRST Protocol
|
|
4
4
|
*
|
|
5
5
|
* Usage:
|
|
@@ -21,6 +21,36 @@
|
|
|
21
21
|
|
|
22
22
|
const DEFAULT_BASE_URL = 'https://jsonfirst.com';
|
|
23
23
|
|
|
24
|
+
// All 22 governance modes
|
|
25
|
+
const MODES = {
|
|
26
|
+
// Base modes (all plans)
|
|
27
|
+
ANTI_CREDIT_WASTE_V2: { plan: 'free+', category: 'efficiency', description: 'Anti-token-waste enforcement. Minimal, direct, single-pass.' },
|
|
28
|
+
EXPRESS_ROUTE: { plan: 'explorer+', category: 'speed', description: 'Ultra-low latency routing. Fastest path to response.' },
|
|
29
|
+
STRICT_PROTOCOL: { plan: 'explorer+', category: 'compliance', description: 'Enforces strict JSONFIRST spec compliance on all outputs.' },
|
|
30
|
+
PERFORMANCE_MAX: { plan: 'explorer+', category: 'performance', description: 'Maximum throughput. Optimized for high-volume workloads.' },
|
|
31
|
+
GUARDIAN_MODE: { plan: 'explorer+', category: 'safety', description: 'Safety lock. Blocks risky actions until explicit confirmation.' },
|
|
32
|
+
FINANCE_ALGO: { plan: 'explorer+', category: 'finance', description: 'Financial computation mode. Precision over speed.' },
|
|
33
|
+
ETHICAL_LOCK: { plan: 'explorer+', category: 'ethics', description: 'Ethics enforcement. Refuses harmful or biased outputs.' },
|
|
34
|
+
SCOPE_LIMITER: { plan: 'pro+', category: 'governance', description: 'Restricts agent scope to explicitly defined boundaries.' },
|
|
35
|
+
SAFE_DEPLOY: { plan: 'pro+', category: 'deployment', description: 'Deployment gating. Requires validation before any deploy.' },
|
|
36
|
+
STANDARD_DEPLOY: { plan: 'pro+', category: 'deployment', description: 'Standard deployment flow with audit trail.' },
|
|
37
|
+
FAST_BUILD: { plan: 'pro+', category: 'build', description: 'Accelerated build mode. Speed-first, reduced validation.' },
|
|
38
|
+
PRODUCTION_LOCK: { plan: 'pro+', category: 'deployment', description: 'Production environment lock. No destructive actions.' },
|
|
39
|
+
// Domain Lock modes (business/enterprise)
|
|
40
|
+
MEDICAL_EXPERT: { plan: 'business+', category: 'domain_lock', description: 'Domain-locked to medicine. Refuses off-domain queries.' },
|
|
41
|
+
LEGAL_EXPERT: { plan: 'business+', category: 'domain_lock', description: 'Domain-locked to law and legal compliance.' },
|
|
42
|
+
FINANCE_EXPERT: { plan: 'business+', category: 'domain_lock', description: 'Domain-locked to financial analysis and accounting.' },
|
|
43
|
+
CYBERSECURITY_EXPERT: { plan: 'business+', category: 'domain_lock', description: 'Domain-locked to cybersecurity and threat analysis.' },
|
|
44
|
+
SOFTWARE_ENGINEERING_EXPERT: { plan: 'business+', category: 'domain_lock', description: 'Domain-locked to software engineering and architecture.' },
|
|
45
|
+
AI_RESEARCH_EXPERT: { plan: 'business+', category: 'domain_lock', description: 'Domain-locked to AI/ML research and model analysis.' },
|
|
46
|
+
NEWS_ANALYSIS_EXPERT: { plan: 'business+', category: 'domain_lock', description: 'Domain-locked to news analysis and geopolitics.' },
|
|
47
|
+
SCIENTIFIC_RESEARCH_EXPERT: { plan: 'business+', category: 'domain_lock', description: 'Domain-locked to scientific research and methodology.' },
|
|
48
|
+
BUSINESS_STRATEGY_EXPERT: { plan: 'business+', category: 'domain_lock', description: 'Domain-locked to business strategy and market analysis.' },
|
|
49
|
+
DATA_SCIENCE_EXPERT: { plan: 'business+', category: 'domain_lock', description: 'Domain-locked to data science and analytics.' },
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const MODE_IDS = Object.keys(MODES);
|
|
53
|
+
|
|
24
54
|
class JsonFirstError extends Error {
|
|
25
55
|
constructor(message, status, body) {
|
|
26
56
|
super(message);
|
|
@@ -85,20 +115,73 @@
|
|
|
85
115
|
}
|
|
86
116
|
|
|
87
117
|
/**
|
|
88
|
-
* Validate a JSON
|
|
89
|
-
* @param {Object} json - The JSON to validate
|
|
90
|
-
* @returns {{ valid: boolean, errors: string[] }}
|
|
118
|
+
* Validate a JSONFIRST output JSON against the JSONFIRST v2 spec.
|
|
119
|
+
* @param {Object} json - The JSONFIRST JSON to validate
|
|
120
|
+
* @returns {{ valid: boolean, errors: string[], warnings: string[] }}
|
|
91
121
|
*/
|
|
92
122
|
validate(json) {
|
|
93
123
|
const errors = [];
|
|
124
|
+
const warnings = [];
|
|
94
125
|
if (!json || typeof json !== 'object') {
|
|
95
|
-
return { valid: false, errors: ['Input must be a JSON object'] };
|
|
126
|
+
return { valid: false, errors: ['Input must be a JSON object'], warnings: [] };
|
|
96
127
|
}
|
|
97
128
|
if (json.spec !== 'JSONFIRST') errors.push('Missing or incorrect "spec" field (expected "JSONFIRST")');
|
|
98
129
|
if (!json.version) errors.push('Missing "version" field');
|
|
99
|
-
if (!json.jdons || !Array.isArray(json.jdons))
|
|
130
|
+
if (!json.jdons || !Array.isArray(json.jdons)) {
|
|
131
|
+
errors.push('Missing "jdons" array');
|
|
132
|
+
} else if (json.jdons.length === 0) {
|
|
133
|
+
warnings.push('"jdons" array is empty — no intents parsed');
|
|
134
|
+
}
|
|
100
135
|
if (!json.execution || typeof json.execution !== 'object') errors.push('Missing "execution" object');
|
|
101
|
-
return { valid: errors.length === 0, errors };
|
|
136
|
+
return { valid: errors.length === 0, errors, warnings };
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Validate a single JDON intent for completeness and executability.
|
|
141
|
+
* Checks required params, confidence threshold, and executable flag.
|
|
142
|
+
* @param {Object} intent - A single JDON object from jdons[]
|
|
143
|
+
* @param {Object} [options]
|
|
144
|
+
* @param {number} [options.minConfidence=0.5] - Minimum confidence threshold (0-1)
|
|
145
|
+
* @param {string[]} [options.requiredParams=[]] - List of required param keys in intent.object
|
|
146
|
+
* @returns {{ valid: boolean, executable: boolean, missing_params: string[], errors: string[], confidence: number }}
|
|
147
|
+
*/
|
|
148
|
+
validateIntent(intent, options = {}) {
|
|
149
|
+
const { minConfidence = 0.5, requiredParams = [] } = options;
|
|
150
|
+
const errors = [];
|
|
151
|
+
const missing_params = [];
|
|
152
|
+
|
|
153
|
+
if (!intent || typeof intent !== 'object') {
|
|
154
|
+
return { valid: false, executable: false, missing_params: [], errors: ['Intent must be a JSON object'], confidence: 0 };
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Action check
|
|
158
|
+
if (!intent.action || !intent.action.normalized) errors.push('Missing action.normalized');
|
|
159
|
+
|
|
160
|
+
// Confidence check
|
|
161
|
+
const confidence = intent.confidence || 0;
|
|
162
|
+
if (confidence < minConfidence) {
|
|
163
|
+
errors.push(`Confidence ${(confidence * 100).toFixed(0)}% is below minimum ${(minConfidence * 100).toFixed(0)}%`);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Required params check
|
|
167
|
+
const obj = intent.object || {};
|
|
168
|
+
for (const param of requiredParams) {
|
|
169
|
+
if (obj[param] === undefined || obj[param] === null) {
|
|
170
|
+
missing_params.push(param);
|
|
171
|
+
errors.push(`Missing required param: ${param}`);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Missing params from JSONFIRST spec
|
|
176
|
+
if (intent.missing_params && intent.missing_params.length > 0) {
|
|
177
|
+
for (const p of intent.missing_params) {
|
|
178
|
+
if (!missing_params.includes(p)) missing_params.push(p);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const executable = intent.executable === true && missing_params.length === 0 && errors.length === 0;
|
|
183
|
+
|
|
184
|
+
return { valid: errors.length === 0, executable, missing_params, errors, confidence };
|
|
102
185
|
}
|
|
103
186
|
|
|
104
187
|
/**
|
|
@@ -118,7 +201,26 @@
|
|
|
118
201
|
async usage() {
|
|
119
202
|
return this._request('GET', '/auth/me');
|
|
120
203
|
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* List all 22 governance modes with their metadata.
|
|
207
|
+
* @returns {Object} modes map
|
|
208
|
+
*/
|
|
209
|
+
modes() {
|
|
210
|
+
return MODES;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* List all mode IDs.
|
|
215
|
+
* @returns {string[]}
|
|
216
|
+
*/
|
|
217
|
+
modeIds() {
|
|
218
|
+
return MODE_IDS.slice();
|
|
219
|
+
}
|
|
121
220
|
}
|
|
122
221
|
|
|
222
|
+
JsonFirst.MODES = MODES;
|
|
223
|
+
JsonFirst.MODE_IDS = MODE_IDS;
|
|
224
|
+
|
|
123
225
|
return JsonFirst;
|
|
124
226
|
}));
|