@jsonfirst/sdk 1.0.0 → 1.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.
Files changed (3) hide show
  1. package/README.md +3 -3
  2. package/index.js +61 -8
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -39,14 +39,14 @@ console.log(valid, errors);
39
39
  ```javascript
40
40
  const client = new JsonFirst({
41
41
  apiKey: 'YOUR_API_KEY',
42
- baseUrl: 'https://jsonfirst.io' // optional override
42
+ baseUrl: 'https://jsonfirst.com' // optional override
43
43
  });
44
44
  ```
45
45
 
46
46
  ## Links
47
47
 
48
- - [Documentation](https://jsonfirst.io/developers)
49
- - [Templates](https://jsonfirst.io/templates)
48
+ - [Documentation](https://jsonfirst.com/developers)
49
+ - [Templates](https://jsonfirst.com/templates)
50
50
  - [GitHub](https://github.com/jsonfirst/sdk)
51
51
 
52
52
  ## License
package/index.js CHANGED
@@ -19,7 +19,7 @@
19
19
  }
20
20
  }(typeof globalThis !== 'undefined' ? globalThis : this, function() {
21
21
 
22
- const DEFAULT_BASE_URL = 'https://jsonfirst.io';
22
+ const DEFAULT_BASE_URL = 'https://jsonfirst.com';
23
23
 
24
24
  class JsonFirstError extends Error {
25
25
  constructor(message, status, body) {
@@ -34,7 +34,7 @@
34
34
  /**
35
35
  * @param {Object} options
36
36
  * @param {string} options.apiKey - Your JSONFIRST API key
37
- * @param {string} [options.baseUrl] - Override base URL (default: https://jsonfirst.io)
37
+ * @param {string} [options.baseUrl] - Override base URL (default: https://jsonfirst.com)
38
38
  */
39
39
  constructor(options = {}) {
40
40
  if (!options.apiKey) throw new Error('JsonFirst: apiKey is required');
@@ -85,20 +85,73 @@
85
85
  }
86
86
 
87
87
  /**
88
- * Validate a JSON object against the JSONFIRST spec.
89
- * @param {Object} json - The JSON to validate
90
- * @returns {{ valid: boolean, errors: string[] }}
88
+ * Validate a JSONFIRST output JSON against the JSONFIRST v2 spec.
89
+ * @param {Object} json - The JSONFIRST JSON to validate
90
+ * @returns {{ valid: boolean, errors: string[], warnings: string[] }}
91
91
  */
92
92
  validate(json) {
93
93
  const errors = [];
94
+ const warnings = [];
94
95
  if (!json || typeof json !== 'object') {
95
- return { valid: false, errors: ['Input must be a JSON object'] };
96
+ return { valid: false, errors: ['Input must be a JSON object'], warnings: [] };
96
97
  }
97
98
  if (json.spec !== 'JSONFIRST') errors.push('Missing or incorrect "spec" field (expected "JSONFIRST")');
98
99
  if (!json.version) errors.push('Missing "version" field');
99
- if (!json.jdons || !Array.isArray(json.jdons)) errors.push('Missing "jdons" array');
100
+ if (!json.jdons || !Array.isArray(json.jdons)) {
101
+ errors.push('Missing "jdons" array');
102
+ } else if (json.jdons.length === 0) {
103
+ warnings.push('"jdons" array is empty — no intents parsed');
104
+ }
100
105
  if (!json.execution || typeof json.execution !== 'object') errors.push('Missing "execution" object');
101
- return { valid: errors.length === 0, errors };
106
+ return { valid: errors.length === 0, errors, warnings };
107
+ }
108
+
109
+ /**
110
+ * Validate a single JDON intent for completeness and executability.
111
+ * Checks required params, confidence threshold, and executable flag.
112
+ * @param {Object} intent - A single JDON object from jdons[]
113
+ * @param {Object} [options]
114
+ * @param {number} [options.minConfidence=0.5] - Minimum confidence threshold (0-1)
115
+ * @param {string[]} [options.requiredParams=[]] - List of required param keys in intent.object
116
+ * @returns {{ valid: boolean, executable: boolean, missing_params: string[], errors: string[], confidence: number }}
117
+ */
118
+ validateIntent(intent, options = {}) {
119
+ const { minConfidence = 0.5, requiredParams = [] } = options;
120
+ const errors = [];
121
+ const missing_params = [];
122
+
123
+ if (!intent || typeof intent !== 'object') {
124
+ return { valid: false, executable: false, missing_params: [], errors: ['Intent must be a JSON object'], confidence: 0 };
125
+ }
126
+
127
+ // Action check
128
+ if (!intent.action || !intent.action.normalized) errors.push('Missing action.normalized');
129
+
130
+ // Confidence check
131
+ const confidence = intent.confidence || 0;
132
+ if (confidence < minConfidence) {
133
+ errors.push(`Confidence ${(confidence * 100).toFixed(0)}% is below minimum ${(minConfidence * 100).toFixed(0)}%`);
134
+ }
135
+
136
+ // Required params check
137
+ const obj = intent.object || {};
138
+ for (const param of requiredParams) {
139
+ if (obj[param] === undefined || obj[param] === null) {
140
+ missing_params.push(param);
141
+ errors.push(`Missing required param: ${param}`);
142
+ }
143
+ }
144
+
145
+ // Missing params from JSONFIRST spec
146
+ if (intent.missing_params && intent.missing_params.length > 0) {
147
+ for (const p of intent.missing_params) {
148
+ if (!missing_params.includes(p)) missing_params.push(p);
149
+ }
150
+ }
151
+
152
+ const executable = intent.executable === true && missing_params.length === 0 && errors.length === 0;
153
+
154
+ return { valid: errors.length === 0, executable, missing_params, errors, confidence };
102
155
  }
103
156
 
104
157
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsonfirst/sdk",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Official JavaScript/Node.js SDK for the JSONFIRST Protocol — Universal Intent Protocol for AI governance",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -23,13 +23,13 @@
23
23
  "claude",
24
24
  "gemini"
25
25
  ],
26
- "author": "JSONFIRST <contact@jsonfirst.io>",
26
+ "author": "JSONFIRST <contact@jsonfirst.com>",
27
27
  "license": "MIT",
28
28
  "repository": {
29
29
  "type": "git",
30
30
  "url": "https://github.com/jsonfirst/sdk"
31
31
  },
32
- "homepage": "https://jsonfirst.io",
32
+ "homepage": "https://jsonfirst.com",
33
33
  "engines": {
34
34
  "node": ">=14"
35
35
  }