diff --git a/engine/language_client_typescript/index.d.ts b/engine/language_client_typescript/index.d.ts index dafbd2ff7..96f7782aa 100644 --- a/engine/language_client_typescript/index.d.ts +++ b/engine/language_client_typescript/index.d.ts @@ -1,12 +1,19 @@ -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 { prompt: string; raw_output: 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 \ No newline at end of file diff --git a/engine/language_client_typescript/index.d.ts.map b/engine/language_client_typescript/index.d.ts.map index 678922c63..c1b009247 100644 --- a/engine/language_client_typescript/index.d.ts.map +++ b/engine/language_client_typescript/index.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["typescript_src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,cAAc,EACd,oBAAoB,EACpB,SAAS,IAAI,KAAK,EAClB,aAAa,EACb,SAAS,IAAI,KAAK,EAClB,kBAAkB,EAClB,cAAc,EACd,YAAY,GACb,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAA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M,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,GAAG,mBAAmB,GAAG,SAAS;CAiB3D;AAGD,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,KAAK,GACX,mBAAmB,GAAG,2BAA2B,GAAG,KAAK,CAa3D"} \ No newline at end of file diff --git a/engine/language_client_typescript/index.js b/engine/language_client_typescript/index.js index c6a62e207..cdef3fe1b 100644 --- a/engine/language_client_typescript/index.js +++ b/engine/language_client_typescript/index.js @@ -1,6 +1,6 @@ "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"); Object.defineProperty(exports, "BamlRuntime", { enumerable: true, get: function () { return native_1.BamlRuntime; } }); Object.defineProperty(exports, "FunctionResult", { enumerable: true, get: function () { return native_1.FunctionResult; } }); @@ -15,47 +15,90 @@ var stream_1 = require("./stream"); Object.defineProperty(exports, "BamlStream", { enumerable: true, get: function () { return stream_1.BamlStream; } }); var async_context_vars_1 = require("./async_context_vars"); Object.defineProperty(exports, "BamlCtxManager", { enumerable: true, get: function () { return async_context_vars_1.BamlCtxManager; } }); -class BamlValidationError extends Error { +class BamlClientFinishReasonError extends Error { prompt; raw_output; constructor(prompt, raw_output, message) { 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); } } catch (parseError) { // 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, raw_output: this.raw_output, prompt: this.prompt, }, null, 2); } + 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; + } } exports.BamlValidationError = BamlValidationError; // Helper function to safely create a 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 diff --git a/integ-tests/typescript/test-report.html b/integ-tests/typescript/test-report.html index 550bec660..d497dffff 100644 --- a/integ-tests/typescript/test-report.html +++ b/integ-tests/typescript/test-report.html @@ -257,9 +257,4 @@ font-size: 1rem; padding: 0 0.5rem; } -
Error: BamlError: Failed to read service account file: - -Caused by: - No such file or directory (os error 2)
Error: BamlError: BamlClientError: Something went wrong with the LLM client: reqwest::Error { kind: Request, url: Url { scheme: "http", cannot_be_a_base: false, username: "", password: None, host: Some(Domain("localhost")), port: Some(11434), path: "/v1/chat/completions", query: None, fragment: None }, source: hyper_util::client::legacy::Error(Connect, ConnectError("tcp connect error", Os { code: 111, kind: ConnectionRefused, message: "Connection refused" })) } - at BamlStream.parsed [as getFinalResponse] (/workspaces/baml/engine/language_client_typescript/stream.js:58:39) - at Object.<anonymous> (/workspaces/baml/integ-tests/typescript/tests/integ-tests.test.ts:602:19)