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; } -

Test Report

Started: 2024-12-01 23:40:27
Suites (1)
0 passed
1 failed
0 pending
Tests (67)
65 passed
2 failed
0 pending
Integ tests > should work for all inputs
single bool
passed
2.601s
Integ tests > should work for all inputs
single string list
passed
1.845s
Integ tests > should work for all inputs
return literal union
passed
0.507s
Integ tests > should work for all inputs
single class
passed
0.713s
Integ tests > should work for all inputs
multiple classes
passed
0.605s
Integ tests > should work for all inputs
single enum list
passed
0.517s
Integ tests > should work for all inputs
single float
passed
0.512s
Integ tests > should work for all inputs
single int
passed
0.606s
Integ tests > should work for all inputs
single literal int
passed
0.502s
Integ tests > should work for all inputs
single literal bool
passed
0.45s
Integ tests > should work for all inputs
single literal string
passed
0.443s
Integ tests > should work for all inputs
single class with literal prop
passed
0.864s
Integ tests > should work for all inputs
single class with literal union prop
passed
0.613s
Integ tests > should work for all inputs
single optional string
passed
0.466s
Integ tests > should work for all inputs
single map string to string
passed
0.594s
Integ tests > should work for all inputs
single map string to class
passed
0.862s
Integ tests > should work for all inputs
single map string to map
passed
0.633s
Integ tests > should work for all inputs
enum key in map
passed
1.007s
Integ tests > should work for all inputs
literal string union key in map
passed
0.899s
Integ tests > should work for all inputs
single literal string key in map
passed
0.64s
Integ tests
should work for all outputs
passed
5.602s
Integ tests
works with retries1
passed
2.254s
Integ tests
works with retries2
passed
2.803s
Integ tests
works with fallbacks
passed
2.568s
Integ tests
should work with image from url
passed
1.367s
Integ tests
should work with image from base 64
passed
9.909s
Integ tests
should work with audio base 64
passed
1.823s
Integ tests
should work with audio from url
passed
2.006s
Integ tests
should support streaming in OpenAI
passed
2.046s
Integ tests
should support streaming in Gemini
passed
9.545s
Integ tests
should support AWS
passed
1.963s
Integ tests
should support streaming in AWS
passed
1.827s
Integ tests
should allow overriding the region
passed
0.13s
Integ tests
should support OpenAI shorthand
passed
9.001s
Integ tests
should support OpenAI shorthand streaming
passed
10.386s
Integ tests
should support anthropic shorthand
passed
2.572s
Integ tests
should support anthropic shorthand streaming
passed
7.519s
Integ tests
should support streaming without iterating
passed
1.855s
Integ tests
should support streaming in Claude
passed
1.131s
Integ tests
should support vertex
failed
0.003s
Error: BamlError: Failed to read service account file: 
-
-Caused by:
-    No such file or directory (os error 2)
Integ tests
supports tracing sync
passed
0.013s
Integ tests
supports tracing async
passed
4.669s
Integ tests
should work with dynamic types single
passed
1.032s
Integ tests
should work with dynamic types enum
passed
1.022s
Integ tests
should work with dynamic literals
passed
1.126s
Integ tests
should work with dynamic types class
passed
1.129s
Integ tests
should work with dynamic inputs class
passed
0.582s
Integ tests
should work with dynamic inputs list
passed
0.699s
Integ tests
should work with dynamic output map
passed
0.81s
Integ tests
should work with dynamic output union
passed
1.702s
Integ tests
should work with nested classes
failed
0.119s
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)
Integ tests
should work with dynamic client
passed
0.793s
Integ tests
should work with 'onLogEvent'
passed
2.354s
Integ tests
should work with a sync client
passed
0.481s
Integ tests
should raise an error when appropriate
passed
1.575s
Integ tests
should raise a BAMLValidationError
passed
0.448s
Integ tests
should reset environment variables correctly
passed
2.103s
Integ tests
should use aliases when serializing input objects - classes
passed
1.127s
Integ tests
should use aliases when serializing, but still have original keys in jinja
passed
1.125s
Integ tests
should use aliases when serializing input objects - enums
passed
0.612s
Integ tests
should use aliases when serializing input objects - lists
passed
0.546s
Integ tests
constraints: should handle checks in return types
passed
0.686s
Integ tests
constraints: should handle checks in returned unions
passed
0.732s
Integ tests
constraints: should handle block-level checks
passed
1.088s
Integ tests
constraints: should handle nested-block-level checks
passed
0.669s
Integ tests
simple recursive type
passed
2.629s
Integ tests
mutually recursive type
passed
1.846s
\ No newline at end of file +

Test Report

Started: 2024-12-03 15:57:41
Suites (1)
1 passed
0 failed
0 pending
Tests (67)
1 passed
0 failed
66 pending
Integ tests > should work for all inputs
single bool
pending
0s
Integ tests > should work for all inputs
single string list
pending
0s
Integ tests > should work for all inputs
return literal union
pending
0s
Integ tests > should work for all inputs
single class
pending
0s
Integ tests > should work for all inputs
multiple classes
pending
0s
Integ tests > should work for all inputs
single enum list
pending
0s
Integ tests > should work for all inputs
single float
pending
0s
Integ tests > should work for all inputs
single int
pending
0s
Integ tests > should work for all inputs
single literal int
pending
0s
Integ tests > should work for all inputs
single literal bool
pending
0s
Integ tests > should work for all inputs
single literal string
pending
0s
Integ tests > should work for all inputs
single class with literal prop
pending
0s
Integ tests > should work for all inputs
single class with literal union prop
pending
0s
Integ tests > should work for all inputs
single optional string
pending
0s
Integ tests > should work for all inputs
single map string to string
pending
0s
Integ tests > should work for all inputs
single map string to class
pending
0s
Integ tests > should work for all inputs
single map string to map
pending
0s
Integ tests > should work for all inputs
enum key in map
pending
0s
Integ tests > should work for all inputs
literal string union key in map
pending
0s
Integ tests > should work for all inputs
single literal string key in map
pending
0s
Integ tests
should work for all outputs
pending
0s
Integ tests
works with retries1
pending
0s
Integ tests
works with retries2
pending
0s
Integ tests
works with fallbacks
pending
0s
Integ tests
should work with image from url
pending
0s
Integ tests
should work with image from base 64
pending
0s
Integ tests
should work with audio base 64
pending
0s
Integ tests
should work with audio from url
pending
0s
Integ tests
should support streaming in OpenAI
pending
0s
Integ tests
should support streaming in Gemini
pending
0s
Integ tests
should support AWS
pending
0s
Integ tests
should support streaming in AWS
pending
0s
Integ tests
should allow overriding the region
pending
0s
Integ tests
should support OpenAI shorthand
pending
0s
Integ tests
should support OpenAI shorthand streaming
pending
0s
Integ tests
should support anthropic shorthand
pending
0s
Integ tests
should support anthropic shorthand streaming
pending
0s
Integ tests
should support streaming without iterating
pending
0s
Integ tests
should support streaming in Claude
pending
0s
Integ tests
should support vertex
pending
0s
Integ tests
supports tracing sync
pending
0s
Integ tests
supports tracing async
pending
0s
Integ tests
should work with dynamic types single
pending
0s
Integ tests
should work with dynamic types enum
pending
0s
Integ tests
should work with dynamic literals
pending
0s
Integ tests
should work with dynamic types class
pending
0s
Integ tests
should work with dynamic inputs class
pending
0s
Integ tests
should work with dynamic inputs list
pending
0s
Integ tests
should work with dynamic output map
pending
0s
Integ tests
should work with dynamic output union
pending
0s
Integ tests
should work with nested classes
pending
0s
Integ tests
should work with dynamic client
pending
0s
Integ tests
should work with 'onLogEvent'
pending
0s
Integ tests
should work with a sync client
pending
0s
Integ tests
should raise an error when appropriate
pending
0s
Integ tests
should raise a BAMLValidationError
passed
0.875s
Integ tests
should reset environment variables correctly
pending
0s
Integ tests
should use aliases when serializing input objects - classes
pending
0s
Integ tests
should use aliases when serializing, but still have original keys in jinja
pending
0s
Integ tests
should use aliases when serializing input objects - enums
pending
0s
Integ tests
should use aliases when serializing input objects - lists
pending
0s
Integ tests
constraints: should handle checks in return types
pending
0s
Integ tests
constraints: should handle checks in returned unions
pending
0s
Integ tests
constraints: should handle block-level checks
pending
0s
Integ tests
constraints: should handle nested-block-level checks
pending
0s
Integ tests
simple recursive type
pending
0s
Integ tests
mutually recursive type
pending
0s
\ No newline at end of file