@opencode-ai/ai
Advanced tools
| /** | ||
| * allow partial strings like `"hello \u12` to be parsed as `"hello ` | ||
| */ | ||
| export declare const STR = 1; | ||
| /** | ||
| * allow partial numbers like `123.` to be parsed as `123` | ||
| */ | ||
| export declare const NUM = 2; | ||
| /** | ||
| * allow partial arrays like `[1, 2,` to be parsed as `[1, 2]` | ||
| */ | ||
| export declare const ARR = 4; | ||
| /** | ||
| * allow partial objects like `{"a": 1, "b":` to be parsed as `{"a": 1}` | ||
| */ | ||
| export declare const OBJ = 8; | ||
| /** | ||
| * allow `nu` to be parsed as `null` | ||
| */ | ||
| export declare const NULL = 16; | ||
| /** | ||
| * allow `tr` to be parsed as `true`, and `fa` to be parsed as `false` | ||
| */ | ||
| export declare const BOOL = 32; | ||
| /** | ||
| * allow `Na` to be parsed as `NaN` | ||
| */ | ||
| export declare const NAN = 64; | ||
| /** | ||
| * allow `Inf` to be parsed as `Infinity` | ||
| */ | ||
| export declare const INFINITY = 128; | ||
| /** | ||
| * allow `-Inf` to be parsed as `-Infinity` | ||
| */ | ||
| export declare const _INFINITY = 256; | ||
| export declare const INF: number; | ||
| export declare const SPECIAL: number; | ||
| export declare const ATOM: number; | ||
| export declare const COLLECTION: number; | ||
| export declare const ALL: number; | ||
| /** | ||
| * Control what types you allow to be partially parsed. | ||
| * The default is to allow all types to be partially parsed, which in most cases is the best option. | ||
| */ | ||
| export declare const Allow: { | ||
| STR: number; | ||
| NUM: number; | ||
| ARR: number; | ||
| OBJ: number; | ||
| NULL: number; | ||
| BOOL: number; | ||
| NAN: number; | ||
| INFINITY: number; | ||
| _INFINITY: number; | ||
| INF: number; | ||
| SPECIAL: number; | ||
| ATOM: number; | ||
| COLLECTION: number; | ||
| ALL: number; | ||
| }; | ||
| export default Allow; |
| /* | ||
| * Adapted from partial-json by the Promplate Dev Team: | ||
| * https://github.com/promplate/partial-json-parser-js/blob/main/src/options.ts | ||
| * Licensed under the MIT License; see partial-json.ts for the complete notice. | ||
| */ | ||
| /** | ||
| * allow partial strings like `"hello \u12` to be parsed as `"hello ` | ||
| */ | ||
| export const STR = 0b000000001; | ||
| /** | ||
| * allow partial numbers like `123.` to be parsed as `123` | ||
| */ | ||
| export const NUM = 0b000000010; | ||
| /** | ||
| * allow partial arrays like `[1, 2,` to be parsed as `[1, 2]` | ||
| */ | ||
| export const ARR = 0b000000100; | ||
| /** | ||
| * allow partial objects like `{"a": 1, "b":` to be parsed as `{"a": 1}` | ||
| */ | ||
| export const OBJ = 0b000001000; | ||
| /** | ||
| * allow `nu` to be parsed as `null` | ||
| */ | ||
| export const NULL = 0b000010000; | ||
| /** | ||
| * allow `tr` to be parsed as `true`, and `fa` to be parsed as `false` | ||
| */ | ||
| export const BOOL = 0b000100000; | ||
| /** | ||
| * allow `Na` to be parsed as `NaN` | ||
| */ | ||
| export const NAN = 0b001000000; | ||
| /** | ||
| * allow `Inf` to be parsed as `Infinity` | ||
| */ | ||
| export const INFINITY = 0b010000000; | ||
| /** | ||
| * allow `-Inf` to be parsed as `-Infinity` | ||
| */ | ||
| export const _INFINITY = 0b100000000; | ||
| export const INF = INFINITY | _INFINITY; | ||
| export const SPECIAL = NULL | BOOL | INF | NAN; | ||
| export const ATOM = STR | NUM | SPECIAL; | ||
| export const COLLECTION = ARR | OBJ; | ||
| export const ALL = ATOM | COLLECTION; | ||
| /** | ||
| * Control what types you allow to be partially parsed. | ||
| * The default is to allow all types to be partially parsed, which in most cases is the best option. | ||
| */ | ||
| export const Allow = { STR, NUM, ARR, OBJ, NULL, BOOL, NAN, INFINITY, _INFINITY, INF, SPECIAL, ATOM, COLLECTION, ALL }; | ||
| export default Allow; |
| export * from "./partial-json-options.js"; | ||
| export declare class PartialJSON extends Error { | ||
| } | ||
| export declare class MalformedJSON extends Error { | ||
| } | ||
| /** Parse complete or incomplete JSON, restricted by the supplied partial-value flags. */ | ||
| export declare function parseJSON(jsonString: string, allowPartial?: number): unknown; | ||
| export declare const parse: typeof parseJSON; |
| /* | ||
| * Adapted from partial-json by the Promplate Dev Team: | ||
| * https://github.com/promplate/partial-json-parser-js | ||
| * | ||
| * MIT License | ||
| * | ||
| * Copyright (c) 2023 Promplate Dev Team | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in all | ||
| * copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| * SOFTWARE. | ||
| */ | ||
| import { Schema } from "effect"; | ||
| import { Allow } from "./partial-json-options.js"; | ||
| export * from "./partial-json-options.js"; | ||
| export class PartialJSON extends Error { | ||
| } | ||
| export class MalformedJSON extends Error { | ||
| } | ||
| const decodeJson = Schema.decodeUnknownSync(Schema.fromJsonString(Schema.Unknown)); | ||
| /** Parse complete or incomplete JSON, restricted by the supplied partial-value flags. */ | ||
| export function parseJSON(jsonString, allowPartial = Allow.ALL) { | ||
| if (typeof jsonString !== "string") | ||
| throw new TypeError(`expecting str, got ${typeof jsonString}`); | ||
| const input = jsonString.trim(); | ||
| if (!input) | ||
| throw new Error(`${jsonString} is empty`); | ||
| try { | ||
| return decodeJson(input); | ||
| } | ||
| catch { } | ||
| return _parseJSON(input, allowPartial); | ||
| } | ||
| const _parseJSON = (jsonString, allow) => { | ||
| const length = jsonString.length; | ||
| let index = 0; | ||
| const markPartialJSON = (message) => { | ||
| throw new PartialJSON(`${message} at position ${index}`); | ||
| }; | ||
| const throwMalformedError = (message) => { | ||
| throw new MalformedJSON(`${message} at position ${index}`); | ||
| }; | ||
| const parseAny = () => { | ||
| skipBlank(); | ||
| if (index >= length) | ||
| markPartialJSON("Unexpected end of input"); | ||
| if (jsonString[index] === '"') | ||
| return parseStr(); | ||
| if (jsonString[index] === "{") | ||
| return parseObj(); | ||
| if (jsonString[index] === "[") | ||
| return parseArr(); | ||
| if (jsonString.substring(index, index + 4) === "null" || | ||
| (Allow.NULL & allow && length - index < 4 && "null".startsWith(jsonString.substring(index)))) { | ||
| index += 4; | ||
| return null; | ||
| } | ||
| if (jsonString.substring(index, index + 4) === "true" || | ||
| (Allow.BOOL & allow && length - index < 4 && "true".startsWith(jsonString.substring(index)))) { | ||
| index += 4; | ||
| return true; | ||
| } | ||
| if (jsonString.substring(index, index + 5) === "false" || | ||
| (Allow.BOOL & allow && length - index < 5 && "false".startsWith(jsonString.substring(index)))) { | ||
| index += 5; | ||
| return false; | ||
| } | ||
| if (jsonString.substring(index, index + 8) === "Infinity" || | ||
| (Allow.INFINITY & allow && length - index < 8 && "Infinity".startsWith(jsonString.substring(index)))) { | ||
| index += 8; | ||
| return Infinity; | ||
| } | ||
| if (jsonString.substring(index, index + 9) === "-Infinity" || | ||
| (Allow._INFINITY & allow && | ||
| 1 < length - index && | ||
| length - index < 9 && | ||
| "-Infinity".startsWith(jsonString.substring(index)))) { | ||
| index += 9; | ||
| return -Infinity; | ||
| } | ||
| if (jsonString.substring(index, index + 3) === "NaN" || | ||
| (Allow.NAN & allow && length - index < 3 && "NaN".startsWith(jsonString.substring(index)))) { | ||
| index += 3; | ||
| return NaN; | ||
| } | ||
| return parseNum(); | ||
| }; | ||
| const parseStr = () => { | ||
| const start = index; | ||
| let escape = false; | ||
| index++; | ||
| while (index < length && (jsonString[index] !== '"' || (escape && jsonString[index - 1] === "\\"))) { | ||
| escape = jsonString[index] === "\\" ? !escape : false; | ||
| index++; | ||
| } | ||
| if (jsonString.charAt(index) === '"') { | ||
| try { | ||
| return decodeJson(jsonString.substring(start, ++index - Number(escape))); | ||
| } | ||
| catch (error) { | ||
| throwMalformedError(String(error)); | ||
| } | ||
| } | ||
| if (Allow.STR & allow) { | ||
| try { | ||
| return decodeJson(`${jsonString.substring(start, index - Number(escape))}"`); | ||
| } | ||
| catch { | ||
| return decodeJson(`${jsonString.substring(start, jsonString.lastIndexOf("\\"))}"`); | ||
| } | ||
| } | ||
| return markPartialJSON("Unterminated string literal"); | ||
| }; | ||
| const parseObj = () => { | ||
| index++; | ||
| skipBlank(); | ||
| const object = {}; | ||
| try { | ||
| while (jsonString[index] !== "}") { | ||
| skipBlank(); | ||
| if (index >= length && Allow.OBJ & allow) | ||
| return object; | ||
| const key = parseStr(); | ||
| skipBlank(); | ||
| index++; | ||
| try { | ||
| object[key] = parseAny(); | ||
| } | ||
| catch (error) { | ||
| if (Allow.OBJ & allow) | ||
| return object; | ||
| throw error; | ||
| } | ||
| skipBlank(); | ||
| if (jsonString[index] === ",") | ||
| index++; | ||
| } | ||
| } | ||
| catch { | ||
| if (Allow.OBJ & allow) | ||
| return object; | ||
| return markPartialJSON("Expected '}' at end of object"); | ||
| } | ||
| index++; | ||
| return object; | ||
| }; | ||
| const parseArr = () => { | ||
| index++; | ||
| const array = []; | ||
| try { | ||
| while (jsonString[index] !== "]") { | ||
| array.push(parseAny()); | ||
| skipBlank(); | ||
| if (jsonString[index] === ",") | ||
| index++; | ||
| } | ||
| } | ||
| catch { | ||
| if (Allow.ARR & allow) | ||
| return array; | ||
| return markPartialJSON("Expected ']' at end of array"); | ||
| } | ||
| index++; | ||
| return array; | ||
| }; | ||
| const parseNum = () => { | ||
| if (index === 0) { | ||
| if (jsonString === "-") | ||
| throwMalformedError("Not sure what '-' is"); | ||
| try { | ||
| return decodeJson(jsonString); | ||
| } | ||
| catch (error) { | ||
| if (Allow.NUM & allow) { | ||
| try { | ||
| return decodeJson(jsonString.substring(0, jsonString.lastIndexOf("e"))); | ||
| } | ||
| catch { } | ||
| } | ||
| throwMalformedError(String(error)); | ||
| } | ||
| } | ||
| const start = index; | ||
| if (jsonString[index] === "-") | ||
| index++; | ||
| while (jsonString[index] && !",]}".includes(jsonString[index])) | ||
| index++; | ||
| if (index === length && !(Allow.NUM & allow)) | ||
| markPartialJSON("Unterminated number literal"); | ||
| try { | ||
| return decodeJson(jsonString.substring(start, index)); | ||
| } | ||
| catch (error) { | ||
| if (jsonString.substring(start, index) === "-") | ||
| markPartialJSON("Not sure what '-' is"); | ||
| try { | ||
| return decodeJson(jsonString.substring(start, jsonString.lastIndexOf("e"))); | ||
| } | ||
| catch { | ||
| throwMalformedError(String(error)); | ||
| } | ||
| } | ||
| }; | ||
| const skipBlank = () => { | ||
| while (index < length && " \n\r\t".includes(jsonString[index])) | ||
| index++; | ||
| }; | ||
| return parseAny(); | ||
| }; | ||
| export const parse = parseJSON; |
+3
-3
| { | ||
| "$schema": "https://json.schemastore.org/package.json", | ||
| "version": "0.0.0-dev-18136", | ||
| "version": "0.0.0-dev-18137", | ||
| "name": "@opencode-ai/ai", | ||
@@ -33,3 +33,3 @@ "type": "module", | ||
| "@effect/platform-node": "4.0.0-rc.111", | ||
| "@opencode-ai/http-recorder": "0.0.0-dev-18136", | ||
| "@opencode-ai/http-recorder": "0.0.0-dev-18137", | ||
| "@tsconfig/bun": "1.0.9", | ||
@@ -43,3 +43,3 @@ "@types/bun": "1.3.13", | ||
| "@smithy/util-utf8": "4.2.2", | ||
| "@opencode-ai/schema": "0.0.0-dev-18136", | ||
| "@opencode-ai/schema": "0.0.0-dev-18137", | ||
| "aws4fetch": "1.0.20", | ||
@@ -46,0 +46,0 @@ "effect": "4.0.0-rc.111", |
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
1258063
0.94%202
2.02%28915
1.21%+ Added
- Removed