@boundaryml/baml
Advanced tools
Comparing version 0.69.0 to 0.70.0
@@ -1,4 +0,11 @@ | ||
export { BamlRuntime, FunctionResult, FunctionResultStream, BamlImage as Image, ClientBuilder, BamlAudio as Audio, invoke_runtime_cli, ClientRegistry, BamlLogEvent, } from './native'; | ||
export { BamlStream } from './stream'; | ||
export { BamlCtxManager } from './async_context_vars'; | ||
export { BamlRuntime, FunctionResult, FunctionResultStream, BamlImage as Image, ClientBuilder, BamlAudio as Audio, invoke_runtime_cli, ClientRegistry, BamlLogEvent, } from "./native"; | ||
export { BamlStream } from "./stream"; | ||
export { BamlCtxManager } from "./async_context_vars"; | ||
export declare class BamlClientFinishReasonError extends Error { | ||
prompt: string; | ||
raw_output: string; | ||
constructor(prompt: string, raw_output: string, message: string); | ||
toJSON(): string; | ||
static from(error: Error): BamlClientFinishReasonError | undefined; | ||
} | ||
export declare class BamlValidationError extends Error { | ||
@@ -8,6 +15,6 @@ prompt: string; | ||
constructor(prompt: string, raw_output: string, message: string); | ||
static from(error: Error): BamlValidationError | Error; | ||
toJSON(): string; | ||
static from(error: Error): BamlValidationError | undefined; | ||
} | ||
export declare function createBamlValidationError(error: Error): BamlValidationError | Error; | ||
export declare function createBamlValidationError(error: Error): BamlValidationError | BamlClientFinishReasonError | Error; | ||
//# sourceMappingURL=index.d.ts.map |
67
index.js
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createBamlValidationError = exports.BamlValidationError = exports.BamlCtxManager = exports.BamlStream = exports.BamlLogEvent = exports.ClientRegistry = exports.invoke_runtime_cli = exports.Audio = exports.ClientBuilder = exports.Image = exports.FunctionResultStream = exports.FunctionResult = exports.BamlRuntime = void 0; | ||
exports.createBamlValidationError = exports.BamlValidationError = exports.BamlClientFinishReasonError = exports.BamlCtxManager = exports.BamlStream = exports.BamlLogEvent = exports.ClientRegistry = exports.invoke_runtime_cli = exports.Audio = exports.ClientBuilder = exports.Image = exports.FunctionResultStream = exports.FunctionResult = exports.BamlRuntime = void 0; | ||
var native_1 = require("./native"); | ||
@@ -18,3 +18,3 @@ Object.defineProperty(exports, "BamlRuntime", { enumerable: true, get: function () { return native_1.BamlRuntime; } }); | ||
Object.defineProperty(exports, "BamlCtxManager", { enumerable: true, get: function () { return async_context_vars_1.BamlCtxManager; } }); | ||
class BamlValidationError extends Error { | ||
class BamlClientFinishReasonError extends Error { | ||
prompt; | ||
@@ -24,16 +24,24 @@ raw_output; | ||
super(message); | ||
this.name = 'BamlValidationError'; | ||
this.name = "BamlClientFinishReasonError"; | ||
this.prompt = prompt; | ||
this.raw_output = raw_output; | ||
Object.setPrototypeOf(this, BamlValidationError.prototype); | ||
Object.setPrototypeOf(this, BamlClientFinishReasonError.prototype); | ||
} | ||
toJSON() { | ||
return JSON.stringify({ | ||
name: this.name, | ||
message: this.message, | ||
raw_output: this.raw_output, | ||
prompt: this.prompt, | ||
}, null, 2); | ||
} | ||
static from(error) { | ||
if (error.message.includes('BamlValidationError')) { | ||
if (error.message.includes("BamlClientFinishReasonError")) { | ||
try { | ||
const errorData = JSON.parse(error.message); | ||
if (errorData.type === 'BamlValidationError') { | ||
return new BamlValidationError(errorData.prompt || '', errorData.raw_output || '', errorData.message || error.message); | ||
if (errorData.type === "BamlClientFinishReasonError") { | ||
return new BamlClientFinishReasonError(errorData.prompt || "", errorData.raw_output || "", errorData.message || error.message); | ||
} | ||
else { | ||
console.warn('Not a BamlValidationError:', error); | ||
console.warn("Not a BamlClientFinishReasonError:", error); | ||
} | ||
@@ -43,10 +51,22 @@ } | ||
// If JSON parsing fails, fall back to the original error | ||
console.warn('Failed to parse BamlValidationError:', parseError); | ||
console.warn("Failed to parse BamlClientFinishReasonError:", parseError); | ||
} | ||
} | ||
// If it's not a BamlValidationError or parsing failed, return the original error | ||
return error; | ||
return undefined; | ||
} | ||
} | ||
exports.BamlClientFinishReasonError = BamlClientFinishReasonError; | ||
class BamlValidationError extends Error { | ||
prompt; | ||
raw_output; | ||
constructor(prompt, raw_output, message) { | ||
super(message); | ||
this.name = "BamlValidationError"; | ||
this.prompt = prompt; | ||
this.raw_output = raw_output; | ||
Object.setPrototypeOf(this, BamlValidationError.prototype); | ||
} | ||
toJSON() { | ||
return JSON.stringify({ | ||
name: this.name, | ||
message: this.message, | ||
@@ -57,2 +77,16 @@ raw_output: this.raw_output, | ||
} | ||
static from(error) { | ||
if (error.message.includes("BamlValidationError")) { | ||
try { | ||
const errorData = JSON.parse(error.message); | ||
if (errorData.type === "BamlValidationError") { | ||
return new BamlValidationError(errorData.prompt || "", errorData.raw_output || "", errorData.message || error.message); | ||
} | ||
} | ||
catch (parseError) { | ||
console.warn("Failed to parse BamlValidationError:", parseError); | ||
} | ||
} | ||
return undefined; | ||
} | ||
} | ||
@@ -62,5 +96,14 @@ exports.BamlValidationError = BamlValidationError; | ||
function createBamlValidationError(error) { | ||
return BamlValidationError.from(error); | ||
const bamlValidationError = BamlValidationError.from(error); | ||
if (bamlValidationError) { | ||
return bamlValidationError; | ||
} | ||
const bamlClientFinishReasonError = BamlClientFinishReasonError.from(error); | ||
if (bamlClientFinishReasonError) { | ||
return bamlClientFinishReasonError; | ||
} | ||
// otherwise return the original error | ||
return error; | ||
} | ||
exports.createBamlValidationError = createBamlValidationError; | ||
// No need for a separate throwBamlValidationError function in TypeScript |
{ | ||
"name": "@boundaryml/baml", | ||
"version": "0.69.0", | ||
"version": "0.70.0", | ||
"description": "BAML typescript bindings (package.json)", | ||
@@ -87,10 +87,10 @@ "repository": { | ||
"optionalDependencies": { | ||
"@boundaryml/baml-darwin-arm64": "0.69.0", | ||
"@boundaryml/baml-linux-arm64-gnu": "0.69.0", | ||
"@boundaryml/baml-linux-arm64-musl": "0.69.0", | ||
"@boundaryml/baml-darwin-x64": "0.69.0", | ||
"@boundaryml/baml-win32-x64-msvc": "0.69.0", | ||
"@boundaryml/baml-linux-x64-gnu": "0.69.0", | ||
"@boundaryml/baml-linux-x64-musl": "0.69.0" | ||
"@boundaryml/baml-darwin-arm64": "0.70.0", | ||
"@boundaryml/baml-linux-arm64-gnu": "0.70.0", | ||
"@boundaryml/baml-linux-arm64-musl": "0.70.0", | ||
"@boundaryml/baml-darwin-x64": "0.70.0", | ||
"@boundaryml/baml-win32-x64-msvc": "0.70.0", | ||
"@boundaryml/baml-linux-x64-gnu": "0.70.0", | ||
"@boundaryml/baml-linux-x64-musl": "0.70.0" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
37076
1003