Skip to content

Commit 6683db0

Browse files
fix(shims): Naively polyfill AsyncLocalStorage in browser (#41)
* fix(shims): Naively polyfill AsyncLocalStorage in browser * Create purple-oranges-shout.md --------- Co-authored-by: Dominik Kundel <[email protected]>
1 parent 78811c6 commit 6683db0

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

.changeset/purple-oranges-shout.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@openai/agents-core": patch
3+
---
4+
5+
fix(shims): Naively polyfill AsyncLocalStorage in browser

packages/agents-core/src/shims/shims-browser.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,16 @@ export const ReadableStreamController =
8787
export const TransformStream = globalThis.TransformStream;
8888

8989
export class AsyncLocalStorage {
90-
constructor() {}
91-
run() {}
92-
getStore() {}
93-
enterWith() {}
90+
context = null;
91+
constructor() { }
92+
run(context: any, fn: () => any) {
93+
this.context = context;
94+
return fn();
95+
}
96+
getStore() {
97+
return this.context;
98+
}
99+
enterWith() { }
94100
}
95101

96102
export function isBrowserEnvironment(): boolean {

0 commit comments

Comments
 (0)