diff --git a/.changeset/purple-oranges-shout.md b/.changeset/purple-oranges-shout.md new file mode 100644 index 00000000..1a4820f5 --- /dev/null +++ b/.changeset/purple-oranges-shout.md @@ -0,0 +1,5 @@ +--- +"@openai/agents-core": patch +--- + +fix(shims): Naively polyfill AsyncLocalStorage in browser diff --git a/packages/agents-core/src/shims/shims-browser.ts b/packages/agents-core/src/shims/shims-browser.ts index 993e3d28..0619119e 100644 --- a/packages/agents-core/src/shims/shims-browser.ts +++ b/packages/agents-core/src/shims/shims-browser.ts @@ -87,10 +87,16 @@ export const ReadableStreamController = export const TransformStream = globalThis.TransformStream; export class AsyncLocalStorage { - constructor() {} - run() {} - getStore() {} - enterWith() {} + context = null; + constructor() { } + run(context: any, fn: () => any) { + this.context = context; + return fn(); + } + getStore() { + return this.context; + } + enterWith() { } } export function isBrowserEnvironment(): boolean {