Skip to content

Commit 3818d37

Browse files
authored
Support multiple AsyncContext shapes (#245)
* Support multiple `AsyncContext` shapes * Create sweet-tables-stare.md
1 parent 7c0da2b commit 3818d37

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

.changeset/sweet-tables-stare.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@inngest/agent-kit": patch
3+
---
4+
5+
Support multiple `AsyncContext` shapes following an update in `inngest@3.45.0`

packages/agent-kit/src/util.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { type Inngest } from "inngest";
2-
import { type InngestFunction, isInngestFunction } from "inngest";
3-
import { getAsyncCtx, type AsyncContext } from "inngest/experimental";
1+
import { type Inngest, type InngestFunction, isInngestFunction } from "inngest";
2+
import { type AsyncContext, getAsyncCtx } from "inngest/experimental";
43
import { type ZodType, ZodObject } from "zod";
54

65
export type MaybePromise<T> = T | Promise<T>;
@@ -35,9 +34,15 @@ export const stringifyError = (e: unknown): string => {
3534
export const getStepTools = async (): Promise<
3635
AsyncContext["ctx"]["step"] | undefined
3736
> => {
37+
// The shape of the experimental async context changed across versions.
38+
// This is now stable, but we support both shapes here for compatibility.
3839
const asyncCtx = await getAsyncCtx();
3940

40-
return asyncCtx?.ctx.step;
41+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
42+
const ctx = asyncCtx?.ctx || (asyncCtx as any)?.execution?.ctx;
43+
44+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-member-access
45+
return ctx?.step;
4146
};
4247

4348
export const isInngestFn = (fn: unknown): fn is InngestFunction.Any => {

0 commit comments

Comments
 (0)