inngest
Version:
Official SDK for Inngest.com. Inngest is the reliability layer for modern applications. Inngest combines durable execution, events, and queues into a zero-infra platform with built-in observability.
309 lines (308 loc) • 14 kB
text/typescript
import { AsTuple, ExclusiveKeys, MaybePromise, SendEventPayload, Simplify } from "../../../helpers/types.cjs";
import { StepFetch } from "../../Fetch.cjs";
import { Jsonify } from "../../../helpers/jsonify.cjs";
import { DurationLike, InstantLike, ZonedDateTimeLike } from "../../../helpers/temporal.cjs";
import { createGroupTools } from "../../InngestGroupTools.cjs";
import { Middleware } from "../../middleware/middleware.cjs";
import { Realtime } from "../../realtime/types.cjs";
import { EventType } from "../../triggers/triggers.cjs";
import { InngestFunction } from "../../InngestFunction.cjs";
import { ClientOptions, EventPayload, InvocationResult, InvokeTargetFunctionDefinition, JsonError, SendEventBaseOutput, SendEventOutput, StepOptionsOrId, TimeStr, TimeStrBatch, TriggerEventFromFunction } from "../../../types.cjs";
import { GetFunctionOutputRaw, Inngest } from "../../Inngest.cjs";
import { Behaviour, Instrumentations } from "./util.cjs";
import * as _standard_schema_spec0 from "@standard-schema/spec";
import * as _inngest_ai0 from "@inngest/ai";
import * as _opentelemetry_api0 from "@opentelemetry/api";
import { DiagLogLevel } from "@opentelemetry/api";
//#region src/components/execution/otel/middleware.d.ts
/**
* A set of options for the Extended Traces middleware.
*/
interface ExtendedTracesMiddlewareOptions {
/**
* The behaviour of the Extended Traces middleware. This controls whether the
* middleware will create a new OpenTelemetry provider, extend an existing one, or
* do nothing. The default is "auto", which will attempt to extend an
* existing provider, and if that fails, create a new one.
*
* - `"auto"`: Attempt to extend an existing provider, and if that fails,
* create a new one.
* - `"createProvider"`: Create a new OpenTelemetry provider.
* - `"extendProvider"`: Attempt to extend an existing provider.
* - `"off"`: Do nothing.
*/
behaviour?: Behaviour;
/**
* Add additional instrumentations to the OpenTelemetry provider.
*
* Note that these only apply if the provider is created by the middleware;
* extending an existing provider cannot add instrumentations and it instead
* must be done wherever the provider is created.
*/
instrumentations?: Instrumentations;
/**
* The log level for the Extended Traces middleware, specifically a diagnostic logger
* attached to the global OpenTelemetry provider.
*
* Defaults to `DiagLogLevel.ERROR`.
*/
logLevel?: DiagLogLevel;
}
/**
* Middleware the captures and exports spans relevant to Inngest runs using
* OTel.
*
* This can be used to attach additional spans and data to the existing traces
* in your Inngest dashboard (or Dev Server).
*/
declare const extendedTracesMiddleware: ({
behaviour,
instrumentations,
logLevel
}?: ExtendedTracesMiddlewareOptions) => {
new ({
client
}: {
client: Inngest.Any;
}): {
readonly id: "inngest:extended-traces";
transformFunctionInput(arg: Middleware.TransformFunctionInputArgs): {
ctx: {
tracer: _opentelemetry_api0.Tracer;
event: Simplify<EventPayload>;
events: AsTuple<Simplify<EventPayload>>;
runId: string;
step: {
sendEvent: (idOrOptions: StepOptionsOrId, payload: SendEventPayload) => Promise<SendEventOutput<ClientOptions>>;
waitForSignal: <TData>(idOrOptions: StepOptionsOrId, opts: {
signal: string;
timeout: number | string | Date;
onConflict: "replace" | "fail";
}) => Promise<{
signal: string;
data: Jsonify<TData>;
} | null>;
realtime: {
publish: <TData>(idOrOptions: StepOptionsOrId, topicRef: Realtime.TopicRef<TData>, data: TData) => Promise<TData>;
};
sendSignal: (idOrOptions: StepOptionsOrId, opts: {
signal: string;
data?: unknown;
}) => Promise<null>;
waitForEvent: <TOpts extends {
event: string | EventType<string, any>;
timeout: number | string | Date;
} & ExclusiveKeys<{
match?: string;
if?: string;
}, "match", "if">>(idOrOptions: StepOptionsOrId, opts: TOpts) => Promise<TOpts extends {
event: EventType<infer TName extends string, _standard_schema_spec0.StandardSchemaV1<infer TData extends Record<string, unknown>>>;
} ? {
name: TName;
data: TData;
id: string;
ts: number;
v?: string;
} | null : TOpts extends {
event: EventType<infer TName_1 extends string, undefined>;
} ? {
name: TName_1;
data: Record<string, any>;
id: string;
ts: number;
v?: string;
} | null : TOpts extends {
event: infer TName_2 extends string;
schema: _standard_schema_spec0.StandardSchemaV1<infer TData_1 extends Record<string, unknown>>;
} ? {
name: TName_2;
data: TData_1;
id: string;
ts: number;
v?: string;
} | null : TOpts extends {
event: infer TName_3 extends string;
} ? {
name: TName_3;
data: Record<string, any>;
id: string;
ts: number;
v?: string;
} | null : EventPayload<any> | null>;
run: <TFn extends (...args: any[]) => unknown>(idOrOptions: StepOptionsOrId, fn: TFn, ...input: Parameters<TFn>) => Promise<Jsonify<TFn extends ((...args: Parameters<TFn>) => Promise<infer U>) ? Awaited<U extends void ? null : U> : ReturnType<TFn> extends void ? null : ReturnType<TFn>>>;
ai: {
infer: <TAdapter extends _inngest_ai0.AiAdapter>(idOrOptions: StepOptionsOrId, options: {
model: TAdapter;
body: _inngest_ai0.AiAdapter.Input<TAdapter>;
}) => Promise<_inngest_ai0.AiAdapter.Output<TAdapter>>;
wrap: <TFn extends (...args: any[]) => unknown>(idOrOptions: StepOptionsOrId, fn: TFn, ...input: Parameters<TFn>) => Promise<Jsonify<TFn extends ((...args: Parameters<TFn>) => Promise<infer U>) ? Awaited<U extends void ? null : U> : ReturnType<TFn> extends void ? null : ReturnType<TFn>>>;
models: {
anthropic: _inngest_ai0.AiAdapter.ModelCreator<[options: _inngest_ai0.Anthropic.AiModelOptions], _inngest_ai0.Anthropic.AiModel>;
gemini: _inngest_ai0.AiAdapter.ModelCreator<[options: _inngest_ai0.Gemini.AiModelOptions], _inngest_ai0.Gemini.AiModel>;
openai: _inngest_ai0.AiAdapter.ModelCreator<[options: _inngest_ai0.OpenAi.AiModelOptions], _inngest_ai0.OpenAi.AiModel>;
deepseek: _inngest_ai0.AiAdapter.ModelCreator<[options: _inngest_ai0.DeepSeek.AiModelOptions], _inngest_ai0.DeepSeek.AiModel>;
grok: _inngest_ai0.AiAdapter.ModelCreator<[options: _inngest_ai0.Grok.AiModelOptions], _inngest_ai0.Grok.AiModel>;
};
};
sleep: (idOrOptions: StepOptionsOrId, time: number | string | DurationLike) => Promise<void>;
sleepUntil: (idOrOptions: StepOptionsOrId, time: Date | string | InstantLike | ZonedDateTimeLike) => Promise<void>;
invoke: <TFunction extends InvokeTargetFunctionDefinition>(idOrOptions: StepOptionsOrId, opts: {
function: TFunction;
} & Omit<TriggerEventFromFunction<TFunction>, "id"> & {
timeout?: number | string | Date;
}) => InvocationResult<Jsonify<GetFunctionOutputRaw<TFunction>>>;
fetch: StepFetch;
};
group: ReturnType<typeof createGroupTools>;
attempt: number;
maxAttempts?: number | undefined;
};
fn: {
readonly opts: {
readonly triggers?: any;
readonly id: string;
readonly name?: string | undefined;
readonly description?: string | undefined;
readonly concurrency?: number | {
readonly limit: number;
readonly key?: string | undefined;
readonly scope?: "fn" | "env" | "account" | undefined;
} | readonly {
readonly limit: number;
readonly key?: string | undefined;
readonly scope?: "fn" | "env" | "account" | undefined;
}[] | undefined;
readonly batchEvents?: {
readonly maxSize: number;
readonly timeout: TimeStrBatch;
readonly key?: string | undefined;
readonly if?: string | undefined;
} | undefined;
readonly idempotency?: string | undefined;
readonly rateLimit?: {
readonly key?: string | undefined;
readonly limit: number;
readonly period: TimeStr;
} | undefined;
readonly throttle?: {
readonly key?: string | undefined;
readonly limit: number;
readonly period: TimeStr;
readonly burst?: number | undefined;
} | undefined;
readonly debounce?: {
readonly key?: string | undefined;
readonly period: TimeStr;
readonly timeout?: TimeStr | undefined;
} | undefined;
readonly priority?: {
readonly run?: string | undefined;
} | undefined;
readonly timeouts?: {
readonly start?: TimeStr | undefined;
readonly finish?: TimeStr | undefined;
} | undefined;
readonly singleton?: {
readonly key?: string | undefined;
readonly mode: "skip" | "cancel";
} | undefined;
readonly cancelOn?: readonly {
readonly event: string | {
readonly event: string;
readonly name: string;
readonly schema: any;
readonly version?: string | undefined;
readonly create: (...args: [data?: Record<string, unknown> | undefined, options?: {
id?: string;
ts?: number;
v?: string;
} | undefined] | [data: unknown, options?: {
id?: string;
ts?: number;
v?: string;
} | undefined]) => {
data: unknown;
name: string;
id?: string;
ts?: number;
v?: string;
} & {
validate: () => Promise<void>;
};
};
readonly if?: string | undefined;
readonly match?: string | undefined;
readonly timeout?: string | number | Readonly<Date> | undefined;
}[] | undefined;
readonly retries?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | undefined;
readonly onFailure?: any;
readonly middleware?: readonly Middleware.Class[] | undefined;
readonly optimizeParallelism?: boolean | undefined;
readonly experimentalCheckpointing?: boolean | {
readonly maxRuntime?: string | number | {
readonly [Symbol.toStringTag]: "Temporal.Duration";
} | undefined;
readonly bufferedSteps?: number | undefined;
readonly maxInterval?: string | number | {
readonly [Symbol.toStringTag]: "Temporal.Duration";
} | undefined;
} | undefined;
readonly checkpointing?: boolean | {
readonly maxRuntime?: string | number | {
readonly [Symbol.toStringTag]: "Temporal.Duration";
} | undefined;
readonly bufferedSteps?: number | undefined;
readonly maxInterval?: string | number | {
readonly [Symbol.toStringTag]: "Temporal.Duration";
} | undefined;
} | undefined;
};
readonly id: (prefix?: string) => string;
readonly name: string;
readonly description: string | undefined;
readonly [Symbol.toStringTag]: typeof InngestFunction.Tag;
};
steps: {
[x: string]: {
type: "data";
data: unknown;
} | {
type: "error";
error: JsonError;
} | {
type: "input";
input: unknown;
};
};
};
wrapRequest({
next
}: Middleware.WrapRequestArgs): Promise<Middleware.Response>;
readonly client: Inngest.Any;
functionOutputTransform: Middleware.DefaultStaticTransform;
stepOutputTransform: Middleware.DefaultStaticTransform;
onMemoizationEnd?(arg: Middleware.OnMemoizationEndArgs): MaybePromise<void>;
onRunComplete?(arg: Middleware.OnRunCompleteArgs): MaybePromise<void>;
onRunError?(arg: Middleware.OnRunErrorArgs): MaybePromise<void>;
onRunStart?(arg: Middleware.OnRunStartArgs): MaybePromise<void>;
onStepComplete?(arg: Middleware.OnStepCompleteArgs): MaybePromise<void>;
onStepError?(arg: Middleware.OnStepErrorArgs): MaybePromise<void>;
onStepStart?(arg: Middleware.OnStepStartArgs): MaybePromise<void>;
transformSendEvent?(arg: Middleware.TransformSendEventArgs): MaybePromise<Middleware.TransformSendEventArgs>;
transformStepInput?(arg: Middleware.TransformStepInputArgs): MaybePromise<Middleware.TransformStepInputArgs>;
wrapFunctionHandler?(args: Middleware.WrapFunctionHandlerArgs): Promise<unknown>;
wrapSendEvent?(args: Middleware.WrapSendEventArgs): Promise<SendEventBaseOutput>;
wrapStep?(args: Middleware.WrapStepArgs): Promise<unknown>;
wrapStepHandler?(args: Middleware.WrapStepHandlerArgs): Promise<unknown>;
};
/**
* Called by the Inngest constructor to associate the processor with the
* client.
*/
onRegister({
client
}: Middleware.OnRegisterArgs): void;
};
//#endregion
export { ExtendedTracesMiddlewareOptions, extendedTracesMiddleware };
//# sourceMappingURL=middleware.d.cts.map