Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion engine/language_client_typescript/async_context_vars.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BamlSpan, RuntimeContextManager, BamlRuntime, BamlLogEvent } from './native';
import { BamlSpan, RuntimeContextManager, BamlRuntime, BamlLogEvent } from './native.js';
export declare class BamlCtxManager {
private rt;
private ctx;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 6 additions & 10 deletions engine/language_client_typescript/async_context_vars.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BamlCtxManager = void 0;
const native_1 = require("./native");
const async_hooks_1 = require("async_hooks");
class BamlCtxManager {
import { BamlSpan } from './native.js';
import { AsyncLocalStorage } from 'async_hooks';
export class BamlCtxManager {
rt;
ctx;
constructor(rt) {
this.rt = rt;
this.ctx = new async_hooks_1.AsyncLocalStorage();
this.ctx = new AsyncLocalStorage();
this.ctx.enterWith(rt.createContextManager());
process.on('exit', () => {
this.rt.flush();
Expand All @@ -25,7 +22,7 @@ class BamlCtxManager {
return true;
}
reset() {
this.ctx = new async_hooks_1.AsyncLocalStorage();
this.ctx = new AsyncLocalStorage();
this.ctx.enterWith(this.rt.createContextManager());
}
upsertTags(tags) {
Expand All @@ -42,7 +39,7 @@ class BamlCtxManager {
}
startTrace(name, args, envVars) {
const mng = this.cloneContext();
return [mng, native_1.BamlSpan.new(this.rt, name, args, mng, envVars)];
return [mng, BamlSpan.new(this.rt, name, args, mng, envVars)];
}
endTrace(span, response, envVars) {
const manager = this.ctx.getStore();
Expand Down Expand Up @@ -113,4 +110,3 @@ class BamlCtxManager {
});
}
}
exports.BamlCtxManager = BamlCtxManager;
6 changes: 1 addition & 5 deletions engine/language_client_typescript/audio.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BamlAudio = void 0;
/**
* Browser-compatible implementation of BamlAudio
*/
class BamlAudio {
export class BamlAudio {
type;
content;
mediaType;
Expand Down Expand Up @@ -93,4 +90,3 @@ class BamlAudio {
};
}
}
exports.BamlAudio = BamlAudio;
16 changes: 8 additions & 8 deletions engine/language_client_typescript/browser.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
* import { Image, Audio } from '@boundaryml/baml'
* ```
*/
import { BamlAudio } from "./audio";
import { BamlImage } from "./image";
import { BamlVideo } from "./video";
import { BamlPdf } from "./pdf";
import type { BamlAudio as BamlAudioType } from "./audio";
import type { BamlImage as BamlImageType } from "./image";
import type { BamlPdf as BamlPdfType } from "./pdf";
import type { BamlVideo as BamlVideoType } from "./video";
import { BamlAudio } from "./audio.js";
import { BamlImage } from "./image.js";
import { BamlVideo } from "./video.js";
import { BamlPdf } from "./pdf.js";
import type { BamlAudio as BamlAudioType } from "./audio.js";
import type { BamlImage as BamlImageType } from "./image.js";
import type { BamlPdf as BamlPdfType } from "./pdf.js";
import type { BamlVideo as BamlVideoType } from "./video.js";
declare const ImageImpl: typeof BamlImage;
declare const AudioImpl: typeof BamlAudio;
declare const PdfImpl: typeof BamlPdf;
Expand Down
2 changes: 1 addition & 1 deletion engine/language_client_typescript/browser.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 10 additions & 15 deletions engine/language_client_typescript/browser.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
"use strict";
/**
* @warning This file is intended for browser usage only.
* For Node.js environments, import Image and Audio directly from '@boundaryml/baml'.
Expand All @@ -11,13 +10,11 @@
* import { Image, Audio } from '@boundaryml/baml'
* ```
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Video = exports.Pdf = exports.Audio = exports.Image = void 0;
// Import actual implementations
const audio_1 = require("./audio");
const image_1 = require("./image");
const video_1 = require("./video");
const pdf_1 = require("./pdf");
import { BamlAudio } from "./audio.js";
import { BamlImage } from "./image.js";
import { BamlVideo } from "./video.js";
import { BamlPdf } from "./pdf.js";
// Detect if we're in server-side rendering environment
const isSSR = typeof window === "undefined";
// Create a proxy handler that logs warnings in SSR environment
Expand All @@ -32,11 +29,9 @@ function createSSRProxyHandler(name) {
};
}
// Create proxied versions that will work in both environments but warn in SSR
const ImageImpl = new Proxy(image_1.BamlImage, createSSRProxyHandler("Image"));
exports.Image = ImageImpl;
const AudioImpl = new Proxy(audio_1.BamlAudio, createSSRProxyHandler("Audio"));
exports.Audio = AudioImpl;
const PdfImpl = new Proxy(pdf_1.BamlPdf, createSSRProxyHandler("Pdf"));
exports.Pdf = PdfImpl;
const VideoImpl = new Proxy(video_1.BamlVideo, createSSRProxyHandler("Video"));
exports.Video = VideoImpl;
const ImageImpl = new Proxy(BamlImage, createSSRProxyHandler("Image"));
const AudioImpl = new Proxy(BamlAudio, createSSRProxyHandler("Audio"));
const PdfImpl = new Proxy(BamlPdf, createSSRProxyHandler("Pdf"));
const VideoImpl = new Proxy(BamlVideo, createSSRProxyHandler("Video"));
// Then export the implementations
export { ImageImpl as Image, AudioImpl as Audio, PdfImpl as Pdf, VideoImpl as Video, };
16 changes: 10 additions & 6 deletions engine/language_client_typescript/cli.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#!/usr/bin/env node

if (require.main === module) {
if (!process.env.BAML_LOG) {
process.env.BAML_LOG = 'info'
}
import { invoke_runtime_cli } from './native.js'

const baml = require('./native')
baml.invoke_runtime_cli(process.argv.slice(1))
if (!process.env.BAML_LOG) {
process.env.BAML_LOG = 'info'
}

try {
await invoke_runtime_cli(process.argv.slice(1))
} catch (error) {
console.error(error)
process.exitCode = 1
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: CLI Executes On Module Import

The CLI logic now runs unconditionally on module import. The require.main === module guard was removed during ESM conversion without an equivalent, causing unintended CLI execution and unexpected behavior when this module is imported.

Fix in Cursor Fix in Web

}
21 changes: 6 additions & 15 deletions engine/language_client_typescript/errors.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
"use strict";
// NOTE: Don't take a dependency on ./native here, it will break the browser code
Object.defineProperty(exports, "__esModule", { value: true });
exports.BamlAbortError = exports.BamlClientHttpError = exports.BamlValidationError = exports.BamlClientFinishReasonError = void 0;
exports.isBamlError = isBamlError;
exports.toBamlError = toBamlError;
class BamlClientFinishReasonError extends Error {
export class BamlClientFinishReasonError extends Error {
prompt;
raw_output;
finish_reason;
Expand Down Expand Up @@ -43,8 +38,7 @@ class BamlClientFinishReasonError extends Error {
return undefined;
}
}
exports.BamlClientFinishReasonError = BamlClientFinishReasonError;
class BamlValidationError extends Error {
export class BamlValidationError extends Error {
prompt;
raw_output;
detailed_message;
Expand Down Expand Up @@ -80,8 +74,7 @@ class BamlValidationError extends Error {
return undefined;
}
}
exports.BamlValidationError = BamlValidationError;
class BamlClientHttpError extends Error {
export class BamlClientHttpError extends Error {
client_name;
status_code;
detailed_message;
Expand Down Expand Up @@ -117,8 +110,7 @@ class BamlClientHttpError extends Error {
return undefined;
}
}
exports.BamlClientHttpError = BamlClientHttpError;
class BamlAbortError extends Error {
export class BamlAbortError extends Error {
reason;
detailed_message;
constructor(message, reason, detailed_message = '') {
Expand All @@ -143,7 +135,6 @@ class BamlAbortError extends Error {
return undefined;
}
}
exports.BamlAbortError = BamlAbortError;
function isError(error) {
if (typeof error === 'string') {
return false;
Expand Down Expand Up @@ -180,7 +171,7 @@ function createBamlErrorUnsafe(error) {
// otherwise return the original error
return error;
}
function isBamlError(error) {
export function isBamlError(error) {
if (error.type === 'BamlClientHttpError' ||
error.type === 'BamlValidationError' ||
error.type === 'BamlClientFinishReasonError' ||
Expand All @@ -198,7 +189,7 @@ function isBamlError(error) {
error instanceof BamlClientFinishReasonError ||
error instanceof BamlAbortError);
}
function toBamlError(error) {
export function toBamlError(error) {
try {
if (isBamlError(error)) {
return error;
Expand Down
6 changes: 1 addition & 5 deletions engine/language_client_typescript/image.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BamlImage = void 0;
/**
* Browser-compatible implementation of BamlImage
*/
class BamlImage {
export class BamlImage {
type;
content;
mediaType;
Expand Down Expand Up @@ -93,4 +90,3 @@ class BamlImage {
};
}
}
exports.BamlImage = BamlImage;
21 changes: 15 additions & 6 deletions engine/language_client_typescript/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
export * from './safe_imports';
export * from './errors';
export * from './logging';
export { BamlRuntime, FunctionResult, FunctionResultStream, BamlImage as Image, BamlAudio as Audio, BamlPdf as Pdf, BamlVideo as Video, invoke_runtime_cli, ClientRegistry, BamlLogEvent, Collector, FunctionLog, LlmCall, LlmStreamCall, Usage, HTTPRequest, HTTPResponse, SSEResponse, StreamTiming, Timing, TraceStats, } from './native';
export { BamlStream } from './stream';
export { BamlCtxManager } from './async_context_vars';
export * from './safe_imports.js';
export * from './errors.js';
export * from './logging.js';
export { BamlRuntime, FunctionResult, FunctionResultStream, invoke_runtime_cli, ClientRegistry, BamlLogEvent, Collector, FunctionLog, LlmCall, LlmStreamCall, Usage, HttpRequest as HTTPRequest, HttpResponse as HTTPResponse, SseResponse as SSEResponse, StreamTiming, Timing, TraceStats, } from './native.js';
export { BamlStream } from './stream.js';
export { BamlCtxManager } from './async_context_vars.js';
import { BamlAudio, BamlImage, BamlPdf, BamlVideo } from './native.js';
export declare const Image: typeof BamlImage;
export declare const Audio: typeof BamlAudio;
export declare const Pdf: typeof BamlPdf;
export declare const Video: typeof BamlVideo;
export type Image = BamlImage;
export type Audio = BamlAudio;
export type Pdf = BamlPdf;
export type Video = BamlVideo;
//# sourceMappingURL=index.d.ts.map
2 changes: 1 addition & 1 deletion engine/language_client_typescript/index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading