Skip to content

Commit

Permalink
readd ts files (#755)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronvg authored Jul 4, 2024
1 parent 49c768f commit b805a72
Show file tree
Hide file tree
Showing 27 changed files with 915 additions and 28 deletions.
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,6 @@ $RECYCLE.BIN/
/dist
/node_modules
/out/
engine/language_client_typescript/*.d.ts
engine/language_client_typescript/*.d.ts.map
engine/language_client_typescript/*.js
!engine/language_client_typescript/cli.js
engine/language_client_ruby/**/*.bundle
engine/target/
Cargo.lock
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file. See [conventional commits](https://www.conventionalcommits.org/) for commit guidelines.

## [0.48.0](https://github.com/boundaryml/baml/compare/0.47.0..0.48.0) - 2024-07-04


### UNMATCHED
- improve error handling when submitting logs to api (#754) - ([49c768f](https://github.com/boundaryml/baml/commit/49c768fbe8eb8023cba28b8dc68c2553d8b2318a)) - aaronvg
- readd ts files - ([1635bf0](https://github.com/boundaryml/baml/commit/1635bf06f87a18b1f933b6c112cd38044239d5c5)) - Aaron Villalpando

## [0.47.0](https://github.com/boundaryml/baml/compare/0.46.0..0.47.0) - 2024-07-03

### Bug Fixes
Expand Down
28 changes: 14 additions & 14 deletions engine/Cargo.lock

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

2 changes: 1 addition & 1 deletion engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ internal-baml-core = { path = "baml-lib/baml-core" }
internal-baml-jinja = { path = "baml-lib/jinja" }

[workspace.package]
version = "0.47.0"
version = "0.48.0"
authors = ["Boundary <[email protected]>"]

description = "BAML Toolchain"
Expand Down
2 changes: 1 addition & 1 deletion engine/language_client_python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "baml-py"
version = "0.47.0"
version = "0.48.0"
description = "BAML python bindings (pyproject.toml)"
readme = "README.md"
authors = [["Boundary", "[email protected]"]]
Expand Down
2 changes: 1 addition & 1 deletion engine/language_client_ruby/baml.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Gem::Specification.new do |spec|
spec.name = "baml"
spec.version = "0.47.0"
spec.version = "0.48.0"
spec.authors = ["BoundaryML"]
spec.email = ["[email protected]"]

Expand Down
15 changes: 15 additions & 0 deletions engine/language_client_typescript/async_context_vars.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { BamlSpan, RuntimeContextManager, BamlRuntime, BamlLogEvent } from './native';
export declare class BamlCtxManager {
private rt;
private ctx;
constructor(rt: BamlRuntime);
upsertTags(tags: Record<string, string>): void;
cloneContext(): RuntimeContextManager;
startTrace(name: string, args: Record<string, any>): [RuntimeContextManager, BamlSpan];
endTrace(span: BamlSpan, response: any): void;
flush(): void;
onLogEvent(callback: (event: BamlLogEvent) => void): void;
traceFnSync<ReturnType, F extends (...args: any[]) => ReturnType>(name: string, func: F): F;
traceFnAsync<ReturnType, F extends (...args: any[]) => Promise<ReturnType>>(name: string, func: F): F;
}
//# sourceMappingURL=async_context_vars.d.ts.map

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

98 changes: 98 additions & 0 deletions engine/language_client_typescript/async_context_vars.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
"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 {
rt;
ctx;
constructor(rt) {
this.rt = rt;
this.ctx = new async_hooks_1.AsyncLocalStorage();
this.ctx.enterWith(rt.createContextManager());
process.on('exit', () => {
this.rt.flush();
});
}
upsertTags(tags) {
const manager = this.ctx.getStore();
manager.upsertTags(tags);
}
cloneContext() {
let store = this.ctx.getStore();
if (store === undefined) {
store = this.rt.createContextManager();
this.ctx.enterWith(store);
}
return store.deepClone();
}
startTrace(name, args) {
const mng = this.cloneContext();
return [mng, native_1.BamlSpan.new(this.rt, name, args, mng)];
}
endTrace(span, response) {
const manager = this.ctx.getStore();
if (!manager) {
console.error('Context lost before span could be finished\n');
return;
}
try {
span.finish(response, manager);
}
catch (e) {
console.error('BAML internal error', e);
}
}
flush() {
this.rt.flush();
}
onLogEvent(callback) {
this.rt.setLogEventCallback((error, param) => {
if (!error) {
callback(param);
}
});
}
traceFnSync(name, func) {
return ((...args) => {
const params = args.reduce((acc, arg, i) => ({
...acc,
[`arg${i}`]: arg, // generic way to label args
}), {});
const [mng, span] = this.startTrace(name, params);
this.ctx.run(mng, () => {
try {
const response = func(...args);
this.endTrace(span, response);
return response;
}
catch (e) {
this.endTrace(span, e);
throw e;
}
});
});
}
traceFnAsync(name, func) {
const funcName = name;
return (async (...args) => {
const params = args.reduce((acc, arg, i) => ({
...acc,
[`arg${i}`]: arg, // generic way to label args
}), {});
const [mng, span] = this.startTrace(name, params);
await this.ctx.run(mng, async () => {
try {
const response = await func(...args);
this.endTrace(span, response);
return response;
}
catch (e) {
this.endTrace(span, e);
throw e;
}
});
});
}
}
exports.BamlCtxManager = BamlCtxManager;
4 changes: 4 additions & 0 deletions engine/language_client_typescript/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export { BamlRuntime, FunctionResult, FunctionResultStream, BamlImage as Image, BamlAudio as Audio, invoke_runtime_cli, } from './native';
export { BamlStream } from './stream';
export { BamlCtxManager } from './async_context_vars';
//# sourceMappingURL=index.d.ts.map
1 change: 1 addition & 0 deletions 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.

14 changes: 14 additions & 0 deletions engine/language_client_typescript/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BamlCtxManager = exports.BamlStream = exports.invoke_runtime_cli = exports.Audio = 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; } });
Object.defineProperty(exports, "FunctionResultStream", { enumerable: true, get: function () { return native_1.FunctionResultStream; } });
Object.defineProperty(exports, "Image", { enumerable: true, get: function () { return native_1.BamlImage; } });
Object.defineProperty(exports, "Audio", { enumerable: true, get: function () { return native_1.BamlAudio; } });
Object.defineProperty(exports, "invoke_runtime_cli", { enumerable: true, get: function () { return native_1.invoke_runtime_cli; } });
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; } });
Loading

0 comments on commit b805a72

Please sign in to comment.