@valni/cli-darwin-x64 0.1.6 → 0.1.7
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/package.json +1 -1
- package/runtime/extensions/switchboard-local/node_modules/partial-json/LICENSE +21 -0
- package/runtime/extensions/switchboard-local/node_modules/partial-json/README.md +131 -0
- package/runtime/extensions/switchboard-local/node_modules/partial-json/dist/index.js +220 -0
- package/runtime/extensions/switchboard-local/node_modules/partial-json/dist/options.js +72 -0
- package/runtime/extensions/switchboard-local/node_modules/partial-json/package.json +43 -0
- package/runtime/native/darwin/prebuilds/darwin-x64/darwin-modifiers.node +0 -0
- package/runtime/package.json +4 -4
- package/runtime/valni +1 -1
package/package.json
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Promplate Dev Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# Partial JSON Parser
|
|
2
|
+
|
|
3
|
+
Sometimes we need **LLM (Large Language Models)** to produce **structural information** instead of natural language. The easiest way is to use JSON.
|
|
4
|
+
|
|
5
|
+
But before receiving the last token of response, the JSON is broken, which means you can't use `JSON.parse` to decode it. But we still want to stream the data to the user.
|
|
6
|
+
|
|
7
|
+
Here comes `partial-json`, a lightweight and customizable library for parsing partial JSON strings. Here is a [demo](https://promplate.dev/partial-json-parser).
|
|
8
|
+
|
|
9
|
+
(Note that there is [a Python implementation](https://github.com/promplate/partial-json-parser) too)
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm i partial-json # or pnpm / bun / yarn
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
`partial-json` is implemented purely in JavaScript, and have both `commonjs` and `esm` builds.
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
### Importing the library
|
|
22
|
+
|
|
23
|
+
You can import the `parse` function and the `Allow` object from the library like this:
|
|
24
|
+
|
|
25
|
+
```js
|
|
26
|
+
import { parse, Allow } from "partial-json";
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
The `Allow` object is just an Enum for options. It determines what types can be partial. types not included in `allow` only appears after its completion can be ensured.
|
|
30
|
+
|
|
31
|
+
### Parsing complete / partial JSON strings
|
|
32
|
+
|
|
33
|
+
The `parse` function works just like the built-in `JSON.parse` when parsing a complete JSON string:
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
let result = parse('{"key":"value"}');
|
|
37
|
+
console.log(result); // Outputs: { key: 'value' }
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
You can parse a partial JSON string by passing an additional parameter to the `parse` function. This parameter is a **bitwise OR** of the constants from the `Allow` object:
|
|
41
|
+
|
|
42
|
+
(Note that you can directly import the constants you need from `partial-json`)
|
|
43
|
+
|
|
44
|
+
```js
|
|
45
|
+
import { parse, STR, OBJ } from "partial-json";
|
|
46
|
+
|
|
47
|
+
result = parse('{"key": "v', STR | OBJ);
|
|
48
|
+
console.log(result); // Outputs: { key: 'v' }
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
In this example, `Allow.STR` tells the parser that it's okay if a string is incomplete, and `Allow.OBJ` tells the parser so as an object. The parser then try to return as much data as it can.
|
|
52
|
+
|
|
53
|
+
If you don't allow partial strings, then it will not add `"key"` to the object because `"v` is not close:
|
|
54
|
+
|
|
55
|
+
```js
|
|
56
|
+
result = parse('{"key": "v', OBJ);
|
|
57
|
+
console.log(result); // Outputs: {}
|
|
58
|
+
|
|
59
|
+
result = parse('{"key": "value"', OBJ);
|
|
60
|
+
console.log(result); // Outputs: { key: 'value' }
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Similarity, you can parse partial arrays or even partial special values if you allow it:
|
|
64
|
+
|
|
65
|
+
(Note that `allow` defaults to `Allow.ALL`)
|
|
66
|
+
|
|
67
|
+
```js
|
|
68
|
+
result = parse('[ {"key1": "value1", "key2": [ "value2');
|
|
69
|
+
console.log(result); // Outputs: [ { key1: 'value1', key2: [ 'value2' ] } ]
|
|
70
|
+
|
|
71
|
+
result = parse("-Inf");
|
|
72
|
+
console.log(result); // Outputs: -Infinity
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Handling malformed JSON
|
|
76
|
+
|
|
77
|
+
If the JSON string is malformed, the `parse` function will throw an error:
|
|
78
|
+
|
|
79
|
+
```js
|
|
80
|
+
parse("wrong"); // MalformedJSON [Error]: SyntaxError: Unexpected token 'w', "wrong" is not valid JSON at position 0
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## API Reference
|
|
84
|
+
|
|
85
|
+
### parse(jsonString, [allowPartial])
|
|
86
|
+
|
|
87
|
+
- `jsonString` `<string>`: The JSON string to parse.
|
|
88
|
+
- `allowPartial` `<number>`: Specify what kind of partialness is allowed during JSON parsing (default: `Allow.ALL`).
|
|
89
|
+
|
|
90
|
+
Returns the parsed JavaScript value.
|
|
91
|
+
|
|
92
|
+
### Allow
|
|
93
|
+
|
|
94
|
+
An object that specifies what kind of partialness is allowed during JSON parsing. It has the following properties:
|
|
95
|
+
|
|
96
|
+
- `STR`: Allow partial string.
|
|
97
|
+
- `NUM`: Allow partial number.
|
|
98
|
+
- `ARR`: Allow partial array.
|
|
99
|
+
- `OBJ`: Allow partial object.
|
|
100
|
+
- `NULL`: Allow partial null.
|
|
101
|
+
- `BOOL`: Allow partial boolean.
|
|
102
|
+
- `NAN`: Allow partial NaN.
|
|
103
|
+
- `INFINITY`: Allow partial Infinity.
|
|
104
|
+
- `_INFINITY`: Allow partial -Infinity.
|
|
105
|
+
- `INF`: Allow both partial Infinity and -Infinity.
|
|
106
|
+
- `SPECIAL`: Allow all special values.
|
|
107
|
+
- `ATOM`: Allow all atomic values.
|
|
108
|
+
- `COLLECTION`: Allow all collection values.
|
|
109
|
+
- `ALL`: Allow all values.
|
|
110
|
+
|
|
111
|
+
## Testing
|
|
112
|
+
|
|
113
|
+
To run the tests for this library, you should clone the repository and install the dependencies:
|
|
114
|
+
|
|
115
|
+
```sh
|
|
116
|
+
git clone https://github.com/promplate/partial-json-parser-js.git
|
|
117
|
+
cd partial-json-parser-js
|
|
118
|
+
npm i
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Then, you can run the tests using [Vitest](https://vitest.dev/):
|
|
122
|
+
|
|
123
|
+
```sh
|
|
124
|
+
npm run test
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Please note that while we strive to cover as many edge cases as possible, it's always possible that some cases might not be covered.
|
|
128
|
+
|
|
129
|
+
## License
|
|
130
|
+
|
|
131
|
+
This project is licensed under the MIT License.
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.Allow = exports.MalformedJSON = exports.PartialJSON = exports.parseJSON = exports.parse = void 0;
|
|
18
|
+
const options_1 = require("./options");
|
|
19
|
+
Object.defineProperty(exports, "Allow", { enumerable: true, get: function () { return options_1.Allow; } });
|
|
20
|
+
__exportStar(require("./options"), exports);
|
|
21
|
+
class PartialJSON extends Error {
|
|
22
|
+
}
|
|
23
|
+
exports.PartialJSON = PartialJSON;
|
|
24
|
+
class MalformedJSON extends Error {
|
|
25
|
+
}
|
|
26
|
+
exports.MalformedJSON = MalformedJSON;
|
|
27
|
+
/**
|
|
28
|
+
* Parse incomplete JSON
|
|
29
|
+
* @param {string} jsonString Partial JSON to be parsed
|
|
30
|
+
* @param {number} allowPartial Specify what types are allowed to be partial, see {@link Allow} for details
|
|
31
|
+
* @returns The parsed JSON
|
|
32
|
+
* @throws {PartialJSON} If the JSON is incomplete (related to the `allow` parameter)
|
|
33
|
+
* @throws {MalformedJSON} If the JSON is malformed
|
|
34
|
+
*/
|
|
35
|
+
function parseJSON(jsonString, allowPartial = options_1.Allow.ALL) {
|
|
36
|
+
if (typeof jsonString !== "string") {
|
|
37
|
+
throw new TypeError(`expecting str, got ${typeof jsonString}`);
|
|
38
|
+
}
|
|
39
|
+
if (!jsonString.trim()) {
|
|
40
|
+
throw new Error(`${jsonString} is empty`);
|
|
41
|
+
}
|
|
42
|
+
return _parseJSON(jsonString.trim(), allowPartial);
|
|
43
|
+
}
|
|
44
|
+
exports.parseJSON = parseJSON;
|
|
45
|
+
;
|
|
46
|
+
const _parseJSON = (jsonString, allow) => {
|
|
47
|
+
const length = jsonString.length;
|
|
48
|
+
let index = 0;
|
|
49
|
+
const markPartialJSON = (msg) => {
|
|
50
|
+
throw new PartialJSON(`${msg} at position ${index}`);
|
|
51
|
+
};
|
|
52
|
+
const throwMalformedError = (msg) => {
|
|
53
|
+
throw new MalformedJSON(`${msg} at position ${index}`);
|
|
54
|
+
};
|
|
55
|
+
const parseAny = () => {
|
|
56
|
+
skipBlank();
|
|
57
|
+
if (index >= length)
|
|
58
|
+
markPartialJSON("Unexpected end of input");
|
|
59
|
+
if (jsonString[index] === '"')
|
|
60
|
+
return parseStr();
|
|
61
|
+
if (jsonString[index] === "{")
|
|
62
|
+
return parseObj();
|
|
63
|
+
if (jsonString[index] === "[")
|
|
64
|
+
return parseArr();
|
|
65
|
+
if (jsonString.substring(index, index + 4) === "null" || (options_1.Allow.NULL & allow && length - index < 4 && "null".startsWith(jsonString.substring(index)))) {
|
|
66
|
+
index += 4;
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
if (jsonString.substring(index, index + 4) === "true" || (options_1.Allow.BOOL & allow && length - index < 4 && "true".startsWith(jsonString.substring(index)))) {
|
|
70
|
+
index += 4;
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
if (jsonString.substring(index, index + 5) === "false" || (options_1.Allow.BOOL & allow && length - index < 5 && "false".startsWith(jsonString.substring(index)))) {
|
|
74
|
+
index += 5;
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
if (jsonString.substring(index, index + 8) === "Infinity" || (options_1.Allow.INFINITY & allow && length - index < 8 && "Infinity".startsWith(jsonString.substring(index)))) {
|
|
78
|
+
index += 8;
|
|
79
|
+
return Infinity;
|
|
80
|
+
}
|
|
81
|
+
if (jsonString.substring(index, index + 9) === "-Infinity" || (options_1.Allow._INFINITY & allow && 1 < length - index && length - index < 9 && "-Infinity".startsWith(jsonString.substring(index)))) {
|
|
82
|
+
index += 9;
|
|
83
|
+
return -Infinity;
|
|
84
|
+
}
|
|
85
|
+
if (jsonString.substring(index, index + 3) === "NaN" || (options_1.Allow.NAN & allow && length - index < 3 && "NaN".startsWith(jsonString.substring(index)))) {
|
|
86
|
+
index += 3;
|
|
87
|
+
return NaN;
|
|
88
|
+
}
|
|
89
|
+
return parseNum();
|
|
90
|
+
};
|
|
91
|
+
const parseStr = () => {
|
|
92
|
+
const start = index;
|
|
93
|
+
let escape = false;
|
|
94
|
+
index++; // skip initial quote
|
|
95
|
+
while (index < length && (jsonString[index] !== '"' || (escape && jsonString[index - 1] === "\\"))) {
|
|
96
|
+
escape = jsonString[index] === "\\" ? !escape : false;
|
|
97
|
+
index++;
|
|
98
|
+
}
|
|
99
|
+
if (jsonString.charAt(index) == '"') {
|
|
100
|
+
try {
|
|
101
|
+
return JSON.parse(jsonString.substring(start, ++index - Number(escape)));
|
|
102
|
+
}
|
|
103
|
+
catch (e) {
|
|
104
|
+
throwMalformedError(String(e));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
else if (options_1.Allow.STR & allow) {
|
|
108
|
+
try {
|
|
109
|
+
return JSON.parse(jsonString.substring(start, index - Number(escape)) + '"');
|
|
110
|
+
}
|
|
111
|
+
catch (e) {
|
|
112
|
+
// SyntaxError: Invalid escape sequence
|
|
113
|
+
return JSON.parse(jsonString.substring(start, jsonString.lastIndexOf("\\")) + '"');
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
markPartialJSON("Unterminated string literal");
|
|
117
|
+
};
|
|
118
|
+
const parseObj = () => {
|
|
119
|
+
index++; // skip initial brace
|
|
120
|
+
skipBlank();
|
|
121
|
+
const obj = {};
|
|
122
|
+
try {
|
|
123
|
+
while (jsonString[index] !== "}") {
|
|
124
|
+
skipBlank();
|
|
125
|
+
if (index >= length && options_1.Allow.OBJ & allow)
|
|
126
|
+
return obj;
|
|
127
|
+
const key = parseStr();
|
|
128
|
+
skipBlank();
|
|
129
|
+
index++; // skip colon
|
|
130
|
+
try {
|
|
131
|
+
const value = parseAny();
|
|
132
|
+
obj[key] = value;
|
|
133
|
+
}
|
|
134
|
+
catch (e) {
|
|
135
|
+
if (options_1.Allow.OBJ & allow)
|
|
136
|
+
return obj;
|
|
137
|
+
else
|
|
138
|
+
throw e;
|
|
139
|
+
}
|
|
140
|
+
skipBlank();
|
|
141
|
+
if (jsonString[index] === ",")
|
|
142
|
+
index++; // skip comma
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
catch (e) {
|
|
146
|
+
if (options_1.Allow.OBJ & allow)
|
|
147
|
+
return obj;
|
|
148
|
+
else
|
|
149
|
+
markPartialJSON("Expected '}' at end of object");
|
|
150
|
+
}
|
|
151
|
+
index++; // skip final brace
|
|
152
|
+
return obj;
|
|
153
|
+
};
|
|
154
|
+
const parseArr = () => {
|
|
155
|
+
index++; // skip initial bracket
|
|
156
|
+
const arr = [];
|
|
157
|
+
try {
|
|
158
|
+
while (jsonString[index] !== "]") {
|
|
159
|
+
arr.push(parseAny());
|
|
160
|
+
skipBlank();
|
|
161
|
+
if (jsonString[index] === ",") {
|
|
162
|
+
index++; // skip comma
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
catch (e) {
|
|
167
|
+
if (options_1.Allow.ARR & allow) {
|
|
168
|
+
return arr;
|
|
169
|
+
}
|
|
170
|
+
markPartialJSON("Expected ']' at end of array");
|
|
171
|
+
}
|
|
172
|
+
index++; // skip final bracket
|
|
173
|
+
return arr;
|
|
174
|
+
};
|
|
175
|
+
const parseNum = () => {
|
|
176
|
+
if (index === 0) {
|
|
177
|
+
if (jsonString === "-")
|
|
178
|
+
throwMalformedError("Not sure what '-' is");
|
|
179
|
+
try {
|
|
180
|
+
return JSON.parse(jsonString);
|
|
181
|
+
}
|
|
182
|
+
catch (e) {
|
|
183
|
+
if (options_1.Allow.NUM & allow)
|
|
184
|
+
try {
|
|
185
|
+
return JSON.parse(jsonString.substring(0, jsonString.lastIndexOf("e")));
|
|
186
|
+
}
|
|
187
|
+
catch (e) { }
|
|
188
|
+
throwMalformedError(String(e));
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
const start = index;
|
|
192
|
+
if (jsonString[index] === "-")
|
|
193
|
+
index++;
|
|
194
|
+
while (jsonString[index] && ",]}".indexOf(jsonString[index]) === -1)
|
|
195
|
+
index++;
|
|
196
|
+
if (index == length && !(options_1.Allow.NUM & allow))
|
|
197
|
+
markPartialJSON("Unterminated number literal");
|
|
198
|
+
try {
|
|
199
|
+
return JSON.parse(jsonString.substring(start, index));
|
|
200
|
+
}
|
|
201
|
+
catch (e) {
|
|
202
|
+
if (jsonString.substring(start, index) === "-")
|
|
203
|
+
markPartialJSON("Not sure what '-' is");
|
|
204
|
+
try {
|
|
205
|
+
return JSON.parse(jsonString.substring(start, jsonString.lastIndexOf("e")));
|
|
206
|
+
}
|
|
207
|
+
catch (e) {
|
|
208
|
+
throwMalformedError(String(e));
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
const skipBlank = () => {
|
|
213
|
+
while (index < length && " \n\r\t".includes(jsonString[index])) {
|
|
214
|
+
index++;
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
return parseAny();
|
|
218
|
+
};
|
|
219
|
+
const parse = parseJSON;
|
|
220
|
+
exports.parse = parse;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Sometimes you don't allow every type to be partially parsed.
|
|
4
|
+
* For example, you may not want a partial number because it may increase its size gradually before it's complete.
|
|
5
|
+
* In this case, you can use the `Allow` object to control what types you allow to be partially parsed.
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.Allow = exports.ALL = exports.COLLECTION = exports.ATOM = exports.SPECIAL = exports.INF = exports._INFINITY = exports.INFINITY = exports.NAN = exports.BOOL = exports.NULL = exports.OBJ = exports.ARR = exports.NUM = exports.STR = void 0;
|
|
10
|
+
/**
|
|
11
|
+
* allow partial strings like `"hello \u12` to be parsed as `"hello "`
|
|
12
|
+
*/
|
|
13
|
+
exports.STR = 0b000000001;
|
|
14
|
+
/**
|
|
15
|
+
* allow partial numbers like `123.` to be parsed as `123`
|
|
16
|
+
*/
|
|
17
|
+
exports.NUM = 0b000000010;
|
|
18
|
+
/**
|
|
19
|
+
* allow partial arrays like `[1, 2,` to be parsed as `[1, 2]`
|
|
20
|
+
*/
|
|
21
|
+
exports.ARR = 0b000000100;
|
|
22
|
+
/**
|
|
23
|
+
* allow partial objects like `{"a": 1, "b":` to be parsed as `{"a": 1}`
|
|
24
|
+
*/
|
|
25
|
+
exports.OBJ = 0b000001000;
|
|
26
|
+
/**
|
|
27
|
+
* allow `nu` to be parsed as `null`
|
|
28
|
+
*/
|
|
29
|
+
exports.NULL = 0b000010000;
|
|
30
|
+
/**
|
|
31
|
+
* allow `tr` to be parsed as `true`, and `fa` to be parsed as `false`
|
|
32
|
+
*/
|
|
33
|
+
exports.BOOL = 0b000100000;
|
|
34
|
+
/**
|
|
35
|
+
* allow `Na` to be parsed as `NaN`
|
|
36
|
+
*/
|
|
37
|
+
exports.NAN = 0b001000000;
|
|
38
|
+
/**
|
|
39
|
+
* allow `Inf` to be parsed as `Infinity`
|
|
40
|
+
*/
|
|
41
|
+
exports.INFINITY = 0b010000000;
|
|
42
|
+
/**
|
|
43
|
+
* allow `-Inf` to be parsed as `-Infinity`
|
|
44
|
+
*/
|
|
45
|
+
exports._INFINITY = 0b100000000;
|
|
46
|
+
exports.INF = exports.INFINITY | exports._INFINITY;
|
|
47
|
+
exports.SPECIAL = exports.NULL | exports.BOOL | exports.INF | exports.NAN;
|
|
48
|
+
exports.ATOM = exports.STR | exports.NUM | exports.SPECIAL;
|
|
49
|
+
exports.COLLECTION = exports.ARR | exports.OBJ;
|
|
50
|
+
exports.ALL = exports.ATOM | exports.COLLECTION;
|
|
51
|
+
/**
|
|
52
|
+
* Control what types you allow to be partially parsed.
|
|
53
|
+
* The default is to allow all types to be partially parsed, which in most casees is the best option.
|
|
54
|
+
* @example
|
|
55
|
+
* If you don't want to allow partial objects, you can use the following code:
|
|
56
|
+
* ```ts
|
|
57
|
+
* import { Allow, parse } from "partial-json";
|
|
58
|
+
* parse(`[{"a": 1, "b": 2}, {"a": 3,`, Allow.ARR); // [ { a: 1, b: 2 } ]
|
|
59
|
+
* ```
|
|
60
|
+
* Or you can use `~` to disallow a type:
|
|
61
|
+
* ```ts
|
|
62
|
+
* parse(`[{"a": 1, "b": 2}, {"a": 3,`, ~Allow.OBJ); // [ { a: 1, b: 2 } ]
|
|
63
|
+
* ```
|
|
64
|
+
* @example
|
|
65
|
+
* If you don't want to allow partial strings, you can use the following code:
|
|
66
|
+
* ```ts
|
|
67
|
+
* import { Allow, parse } from "partial-json";
|
|
68
|
+
* parse(`["complete string", "incompl`, ~Allow.STR); // [ 'complete string' ]
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
exports.Allow = { STR: exports.STR, NUM: exports.NUM, ARR: exports.ARR, OBJ: exports.OBJ, NULL: exports.NULL, BOOL: exports.BOOL, NAN: exports.NAN, INFINITY: exports.INFINITY, _INFINITY: exports._INFINITY, INF: exports.INF, SPECIAL: exports.SPECIAL, ATOM: exports.ATOM, COLLECTION: exports.COLLECTION, ALL: exports.ALL };
|
|
72
|
+
exports.default = exports.Allow;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "partial-json",
|
|
3
|
+
"version": "0.1.7",
|
|
4
|
+
"description": "Parse partial JSON generated by LLM",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"JSON",
|
|
7
|
+
"parser",
|
|
8
|
+
"LLM",
|
|
9
|
+
"nlp"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://promplate.dev/partial-json-parser",
|
|
12
|
+
"repository": "https://github.com/promplate/partial-json-parser-js",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"author": "Muspi Merol <me@promplate.dev>",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
|
+
},
|
|
20
|
+
"./options": {
|
|
21
|
+
"types": "./dist/options.d.ts",
|
|
22
|
+
"default": "./dist/options.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"main": "dist/index.js",
|
|
26
|
+
"module": "dist/index.js",
|
|
27
|
+
"types": "dist/index.d.ts",
|
|
28
|
+
"files": [
|
|
29
|
+
"dist"
|
|
30
|
+
],
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsc",
|
|
33
|
+
"coverage": "vitest run --coverage",
|
|
34
|
+
"test": "vitest",
|
|
35
|
+
"test:ui": "vitest --ui"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@vitest/coverage-istanbul": "^1.2.2",
|
|
39
|
+
"@vitest/ui": "^1.2.2",
|
|
40
|
+
"typescript": "^5.3.3",
|
|
41
|
+
"vitest": "^1.2.2"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
Binary file
|
package/runtime/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@valni/cli",
|
|
3
3
|
"private": true,
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.7",
|
|
5
5
|
"description": "Coding agent CLI with read, bash, edit, write tools and session management",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"valniConfig": {
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
"prepublishOnly": "npm run clean && npm run build && npm run shrinkwrap"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@valni/agent-core": "^0.1.
|
|
42
|
-
"@valni/ai": "^0.1.
|
|
43
|
-
"@valni/tui": "^0.1.
|
|
41
|
+
"@valni/agent-core": "^0.1.7",
|
|
42
|
+
"@valni/ai": "^0.1.7",
|
|
43
|
+
"@valni/tui": "^0.1.7",
|
|
44
44
|
"pi-switchboard": "git+https://github.com/Valni-Labs/pi-switchboard.git#774f1a7985a755fcd483313b729864aa8a9418c3",
|
|
45
45
|
"switchboard-local": "git+https://github.com/Valni-Labs/switchboard-local.git#4ec07263591a4f329fd12eab04d62d6c455be666",
|
|
46
46
|
"@silvia-odwyer/photon-node": "0.3.4",
|
package/runtime/valni
CHANGED