@upstash/qstash 2.7.14 → 2.7.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -62,16 +62,6 @@ declare class Receiver {
62
62
  private verifyBodyAndUrl;
63
63
  }
64
64
 
65
- type EmailProviderReturnType = {
66
- owner: "resend";
67
- baseUrl: "https://api.resend.com/emails" | "https://api.resend.com/emails/batch";
68
- token: string;
69
- };
70
- declare const resend: ({ token, batch, }: {
71
- token: string;
72
- batch?: boolean;
73
- }) => EmailProviderReturnType;
74
-
75
65
  type State = "CREATED" | "ACTIVE" | "DELIVERED" | "ERROR" | "RETRY" | "FAILED";
76
66
  type HTTPMethods = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
77
67
  type Event = {
@@ -116,31 +106,94 @@ type RateLimit = {
116
106
  reset: string | null;
117
107
  };
118
108
 
119
- type Owner = "upstash" | "openai" | "custom";
120
- type ProviderReturnType<TOwner extends Owner = Owner, TBaseUrl extends string = string, TToken extends string = string, TOrganization extends string | undefined = string | undefined> = {
121
- owner: TOwner;
122
- baseUrl: TBaseUrl;
123
- token: TToken;
124
- organization: TOrganization;
109
+ type ProviderInfo = {
110
+ /**
111
+ * full url used for request
112
+ */
113
+ url: string;
114
+ /**
115
+ * base url of the request
116
+ */
117
+ baseUrl: string;
118
+ /**
119
+ * route elements which will follow the baseUrl
120
+ */
121
+ route: string[];
122
+ /**
123
+ * headers to include in the request
124
+ */
125
+ appendHeaders: Record<string, string>;
126
+ /**
127
+ * provider owner
128
+ */
129
+ owner: Owner;
125
130
  };
126
- type AnalyticsConfig = {
127
- name: "helicone";
128
- token: string;
131
+ type ApiKind = "llm" | "email";
132
+ type Owner = EmailOwner | LLMOwner;
133
+ type PublishApi<TName extends ApiKind, TProvider extends BaseProvider<TName>> = {
134
+ name: TName;
135
+ provider?: TProvider;
129
136
  };
130
- type AnalyticsSetup = {
131
- baseURL?: string;
132
- defaultHeaders?: Record<string, string | undefined>;
137
+ /**
138
+ * Email
139
+ */
140
+ type EmailOwner = "resend";
141
+ type PublishEmailApi = Required<PublishApi<"email", BaseProvider<"email", EmailOwner>>>;
142
+ /**
143
+ * LLM
144
+ */
145
+ type LLMOwner = "upstash" | "openai" | "anthropic" | "custom";
146
+ type LLMOptions = {
147
+ analytics?: {
148
+ name: "helicone";
149
+ token: string;
150
+ };
133
151
  };
134
- declare const setupAnalytics: (analytics: AnalyticsConfig | undefined, providerApiKey: string, providerBaseUrl?: string, provider?: "openai" | "upstash" | "custom") => AnalyticsSetup;
135
- declare const upstash: () => ProviderReturnType<"upstash", "https://qstash.upstash.io/llm", "">;
136
- declare const openai: <TToken extends string = string, TOrganization extends string | undefined = undefined>({ token, organization, }: {
137
- token: TToken;
138
- organization?: TOrganization;
139
- }) => ProviderReturnType<"openai", "https://api.openai.com", TToken, TOrganization extends string ? TOrganization : undefined>;
140
- declare const custom: <TToken extends string = string>({ baseUrl, token, }: {
152
+ type PublishLLMApi = PublishApi<"llm", BaseProvider<"llm", LLMOwner>> & LLMOptions;
153
+
154
+ declare abstract class BaseProvider<TName extends ApiKind, TOwner = Owner> {
155
+ abstract readonly apiKind: TName;
156
+ readonly baseUrl: string;
157
+ token: string;
158
+ readonly owner: TOwner;
159
+ constructor(baseUrl: string, token: string, owner: TOwner);
160
+ /**
161
+ * called before returning the final request
162
+ *
163
+ * @param request
164
+ */
165
+ abstract onFinish(request: ProviderInfo, options: unknown): ProviderInfo;
166
+ abstract getRoute(): string[];
167
+ abstract getHeaders(options: unknown): Record<string, string>;
168
+ getUrl(): string;
169
+ }
170
+
171
+ declare class LLMProvider<TOwner extends LLMOwner> extends BaseProvider<"llm", LLMOwner> {
172
+ readonly apiKind = "llm";
173
+ readonly organization?: string;
174
+ constructor(baseUrl: string, token: string, owner: TOwner, organization?: string);
175
+ getRoute(): string[];
176
+ getHeaders(options: LLMOptions): Record<string, string>;
177
+ /**
178
+ * Checks if callback exists and adds analytics in place if it's set.
179
+ *
180
+ * @param request
181
+ * @param options
182
+ */
183
+ onFinish(providerInfo: ProviderInfo, options: LLMOptions): ProviderInfo;
184
+ }
185
+ declare const upstash: () => LLMProvider<"upstash">;
186
+ declare const openai: ({ token, organization, }: {
187
+ token: string;
188
+ organization?: string;
189
+ }) => LLMProvider<"openai">;
190
+ declare const anthropic: ({ token }: {
191
+ token: string;
192
+ }) => LLMProvider<"anthropic">;
193
+ declare const custom: ({ baseUrl, token, }: {
141
194
  baseUrl: string;
142
- token: TToken;
143
- }) => ProviderReturnType<"custom", string, TToken>;
195
+ token: string;
196
+ }) => LLMProvider<"custom">;
144
197
 
145
198
  type ChatCompletionMessage = {
146
199
  role: "system" | "assistant" | "user";
@@ -229,21 +282,21 @@ type ChatRequestFields = ChatRequestCommonFields & {
229
282
  messages: ChatCompletionMessage[];
230
283
  };
231
284
  type ChatRequestProviders = {
232
- provider: ProviderReturnType<"openai">;
285
+ provider: LLMProvider<"openai">;
233
286
  model: OpenAIChatModel;
234
287
  analytics?: {
235
288
  name: "helicone";
236
289
  token: string;
237
290
  };
238
291
  } | {
239
- provider: ProviderReturnType<"custom">;
292
+ provider: LLMProvider<"custom">;
240
293
  model: string;
241
294
  analytics?: {
242
295
  name: "helicone";
243
296
  token: string;
244
297
  };
245
298
  } | {
246
- provider: ProviderReturnType<"upstash">;
299
+ provider: LLMProvider<"upstash">;
247
300
  model: ChatModel;
248
301
  analytics?: {
249
302
  name: "helicone";
@@ -282,6 +335,11 @@ type UpstashRequest = {
282
335
  * @default true
283
336
  */
284
337
  parseResponseAsJson?: boolean;
338
+ /**
339
+ * optionally overwrite the baseUrl of the http.
340
+ *
341
+ * default value of the http is base qstash url.
342
+ */
285
343
  baseUrl?: string;
286
344
  };
287
345
  type UpstashResponse<TResult> = TResult & {
@@ -1633,14 +1691,7 @@ type PublishRequest<TBody = BodyInit> = {
1633
1691
  /**
1634
1692
  * The api endpoint the request should be sent to.
1635
1693
  */
1636
- api: {
1637
- name: "llm";
1638
- provider?: ProviderReturnType;
1639
- analytics?: {
1640
- name: "helicone";
1641
- token: string;
1642
- };
1643
- };
1694
+ api: PublishLLMApi;
1644
1695
  topic?: never;
1645
1696
  /**
1646
1697
  * Use a callback url to forward the response of your destination server to your callback url.
@@ -1656,10 +1707,7 @@ type PublishRequest<TBody = BodyInit> = {
1656
1707
  /**
1657
1708
  * The api endpoint the request should be sent to.
1658
1709
  */
1659
- api: {
1660
- name: "email";
1661
- provider: EmailProviderReturnType;
1662
- };
1710
+ api: PublishEmailApi;
1663
1711
  topic?: never;
1664
1712
  callback?: string;
1665
1713
  } | {
@@ -1815,4 +1863,4 @@ type PublishResponse<TRequest> = TRequest extends {
1815
1863
  urlGroup: string;
1816
1864
  } ? PublishToUrlGroupsResponse : PublishToApiResponse;
1817
1865
 
1818
- export { type AnalyticsConfig as $, type AddEndpointsRequest as A, type BodyInit as B, type ChatRateLimit as C, type ChatCompletion as D, type EventsRequest as E, type FailureFunctionPayload as F, type GetEventsResponse as G, type HTTPMethods as H, type ChatCompletionChunk as I, type StreamEnabled as J, type StreamDisabled as K, type StreamParameter as L, type Message as M, type PromptChatRequest as N, type OpenAIChatModel as O, type PublishBatchRequest as P, type QueueRequest as Q, type RateLimit as R, type Step as S, type ChatRequest as T, type UrlGroup as U, type VerifyRequest as V, type WithCursor as W, custom as X, openai as Y, upstash as Z, type ProviderReturnType as _, type ReceiverConfig as a, type AnalyticsSetup as a0, setupAnalytics as a1, resend as a2, type RouteFunction as a3, type WorkflowServeOptions as a4, Workflow as a5, processOptions as a6, serve as a7, WorkflowContext as a8, DisabledWorkflowContext as a9, type WorkflowClient as aa, type WorkflowReceiver as ab, StepTypes as ac, type StepType as ad, type RawStep as ae, type SyncStepFunction as af, type AsyncStepFunction as ag, type StepFunction as ah, type ParallelCallState as ai, type FinishCondition as aj, type RequiredExceptFields as ak, type LogLevel as al, type WorkflowLoggerOptions as am, WorkflowLogger as an, SignatureError as b, Receiver as c, type PublishRequest as d, type PublishJsonRequest as e, Client as f, type PublishToApiResponse as g, type PublishToUrlResponse as h, type PublishToUrlGroupsResponse as i, type PublishResponse as j, type MessagePayload as k, Messages as l, type Schedule as m, type CreateScheduleRequest as n, Schedules as o, type Endpoint as p, type RemoveEndpointsRequest as q, UrlGroups as r, type State as s, type Event as t, type EventPayload as u, type GetEventsPayload as v, type HeadersInit as w, type RequestOptions as x, Chat as y, type ChatCompletionMessage as z };
1866
+ export { upstash as $, type AddEndpointsRequest as A, BaseProvider as B, type ChatRateLimit as C, type RequestOptions as D, type EmailOwner as E, type FailureFunctionPayload as F, type GetEventsResponse as G, type HTTPMethods as H, Chat as I, type ChatCompletionMessage as J, type ChatCompletion as K, type LLMOwner as L, type Message as M, type ChatCompletionChunk as N, type StreamEnabled as O, type ProviderInfo as P, type QueueRequest as Q, type RateLimit as R, type Step as S, type StreamDisabled as T, type UrlGroup as U, type VerifyRequest as V, type WithCursor as W, type StreamParameter as X, type OpenAIChatModel as Y, type PromptChatRequest as Z, type ChatRequest as _, type ReceiverConfig as a, openai as a0, anthropic as a1, custom as a2, type RouteFunction as a3, type WorkflowServeOptions as a4, Workflow as a5, processOptions as a6, serve as a7, WorkflowContext as a8, DisabledWorkflowContext as a9, type WorkflowClient as aa, type WorkflowReceiver as ab, StepTypes as ac, type StepType as ad, type RawStep as ae, type SyncStepFunction as af, type AsyncStepFunction as ag, type StepFunction as ah, type ParallelCallState as ai, type FinishCondition as aj, type RequiredExceptFields as ak, type LogLevel as al, type WorkflowLoggerOptions as am, WorkflowLogger as an, SignatureError as b, Receiver as c, type PublishBatchRequest as d, type PublishRequest as e, type PublishJsonRequest as f, type EventsRequest as g, Client as h, type PublishToApiResponse as i, type PublishToUrlResponse as j, type PublishToUrlGroupsResponse as k, type PublishResponse as l, type MessagePayload as m, Messages as n, type Schedule as o, type CreateScheduleRequest as p, Schedules as q, type Endpoint as r, type RemoveEndpointsRequest as s, UrlGroups as t, type State as u, type Event as v, type EventPayload as w, type GetEventsPayload as x, type BodyInit as y, type HeadersInit as z };
package/cloudflare.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { a3 as RouteFunction, a4 as WorkflowServeOptions } from './client-kxUsvnWj.mjs';
1
+ import { a3 as RouteFunction, a4 as WorkflowServeOptions } from './client-RORrka04.mjs';
2
2
  import 'neverthrow';
3
3
 
4
4
  type WorkflowBindings = {
package/cloudflare.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { a3 as RouteFunction, a4 as WorkflowServeOptions } from './client-kxUsvnWj.js';
1
+ import { a3 as RouteFunction, a4 as WorkflowServeOptions } from './client-RORrka04.js';
2
2
  import 'neverthrow';
3
3
 
4
4
  type WorkflowBindings = {
package/cloudflare.js CHANGED
@@ -94,14 +94,6 @@ var Receiver = class {
94
94
  }
95
95
  };
96
96
 
97
- // src/client/api/utils.ts
98
- var appendAPIOptions = (request, headers) => {
99
- if (request.api?.name === "email") {
100
- headers.set("Authorization", request.api.provider.token);
101
- request.method = request.method ?? "POST";
102
- }
103
- };
104
-
105
97
  // src/client/dlq.ts
106
98
  var DLQ = class {
107
99
  http;
@@ -249,7 +241,7 @@ var HttpClient = class {
249
241
  attempts: 1,
250
242
  backoff: () => 0
251
243
  } : {
252
- attempts: config.retry?.retries ? config.retry.retries + 1 : 5,
244
+ attempts: config.retry?.retries ?? 5,
253
245
  backoff: config.retry?.backoff ?? ((retryCount) => Math.exp(retryCount) * 50)
254
246
  };
255
247
  }
@@ -294,13 +286,15 @@ var HttpClient = class {
294
286
  const [url, requestOptions] = this.processRequest(request);
295
287
  let response = void 0;
296
288
  let error = void 0;
297
- for (let index = 0; index < this.retry.attempts; index++) {
289
+ for (let index = 0; index <= this.retry.attempts; index++) {
298
290
  try {
299
291
  response = await fetch(url.toString(), requestOptions);
300
292
  break;
301
293
  } catch (error_) {
302
294
  error = error_;
303
- await new Promise((r) => setTimeout(r, this.retry.backoff(index)));
295
+ if (index < this.retry.attempts) {
296
+ await new Promise((r) => setTimeout(r, this.retry.backoff(index)));
297
+ }
304
298
  }
305
299
  }
306
300
  if (!response) {
@@ -472,7 +466,6 @@ var Chat = class _Chat {
472
466
  * @param request ChatRequest with messages
473
467
  * @returns Chat completion or stream
474
468
  */
475
- // eslint-disable-next-line @typescript-eslint/require-await
476
469
  createThirdParty = async (request) => {
477
470
  const { baseUrl, token, owner, organization } = request.provider;
478
471
  if (owner === "upstash")
@@ -533,63 +526,6 @@ var Chat = class _Chat {
533
526
  };
534
527
  };
535
528
 
536
- // src/client/llm/utils.ts
537
- function appendLLMOptionsIfNeeded(request, headers, http) {
538
- if (request.api?.name === "email" || !request.api)
539
- return;
540
- const provider = request.api.provider;
541
- const analytics = request.api.analytics;
542
- if (provider?.owner === "upstash") {
543
- handleUpstashProvider(request, headers, http, analytics);
544
- return;
545
- }
546
- if (!("provider" in request.api))
547
- return;
548
- const { baseUrl, token } = validateProviderConfig(provider);
549
- const analyticsConfig = analytics ? setupAnalytics({ name: analytics.name, token: analytics.token }, token, baseUrl, "custom") : void 0;
550
- if (analyticsConfig) {
551
- setAnalyticsHeaders(headers, analyticsConfig);
552
- request.url = analyticsConfig.baseURL;
553
- } else {
554
- request.url = `${baseUrl}/v1/chat/completions`;
555
- headers.set("Authorization", `Bearer ${token}`);
556
- }
557
- }
558
- function handleUpstashProvider(request, headers, http, analytics) {
559
- if (analytics) {
560
- const analyticsConfig = setupAnalytics(
561
- { name: analytics.name, token: analytics.token },
562
- //@ts-expect-error hacky way to get bearer token
563
- String(http.authorization).split("Bearer ")[1],
564
- request.api?.provider?.baseUrl,
565
- "upstash"
566
- );
567
- setAnalyticsHeaders(headers, analyticsConfig);
568
- request.url = analyticsConfig.baseURL;
569
- } else {
570
- request.api = { name: "llm" };
571
- }
572
- }
573
- function validateProviderConfig(provider) {
574
- if (!provider?.baseUrl)
575
- throw new Error("baseUrl cannot be empty or undefined!");
576
- if (!provider.token)
577
- throw new Error("token cannot be empty or undefined!");
578
- return { baseUrl: provider.baseUrl, token: provider.token };
579
- }
580
- function setAnalyticsHeaders(headers, analyticsConfig) {
581
- headers.set("Helicone-Auth", analyticsConfig.defaultHeaders?.["Helicone-Auth"] ?? "");
582
- headers.set("Authorization", analyticsConfig.defaultHeaders?.Authorization ?? "");
583
- if (analyticsConfig.defaultHeaders?.["Helicone-Target-Url"]) {
584
- headers.set("Helicone-Target-Url", analyticsConfig.defaultHeaders["Helicone-Target-Url"]);
585
- }
586
- }
587
- function ensureCallbackPresent(request) {
588
- if (request.api?.name === "llm" && !request.callback) {
589
- throw new TypeError("Callback cannot be undefined when using LLM");
590
- }
591
- }
592
-
593
529
  // src/client/messages.ts
594
530
  var Messages = class {
595
531
  http;
@@ -638,6 +574,147 @@ var Messages = class {
638
574
  }
639
575
  };
640
576
 
577
+ // src/client/api/base.ts
578
+ var BaseProvider = class {
579
+ baseUrl;
580
+ token;
581
+ owner;
582
+ constructor(baseUrl, token, owner) {
583
+ this.baseUrl = baseUrl;
584
+ this.token = token;
585
+ this.owner = owner;
586
+ }
587
+ getUrl() {
588
+ return `${this.baseUrl}/${this.getRoute().join("/")}`;
589
+ }
590
+ };
591
+
592
+ // src/client/api/llm.ts
593
+ var LLMProvider = class extends BaseProvider {
594
+ apiKind = "llm";
595
+ organization;
596
+ constructor(baseUrl, token, owner, organization) {
597
+ super(baseUrl, token, owner);
598
+ this.organization = organization;
599
+ }
600
+ getRoute() {
601
+ return this.owner === "anthropic" ? ["v1", "messages"] : ["v1", "chat", "completions"];
602
+ }
603
+ getHeaders(options) {
604
+ if (this.owner === "upstash" && !options.analytics) {
605
+ return { "content-type": "application/json" };
606
+ }
607
+ const header = this.owner === "anthropic" ? "x-api-key" : "authorization";
608
+ const headerValue = this.owner === "anthropic" ? this.token : `Bearer ${this.token}`;
609
+ const headers = {
610
+ [header]: headerValue,
611
+ "content-type": "application/json"
612
+ };
613
+ if (this.owner === "openai" && this.organization) {
614
+ headers["OpenAI-Organization"] = this.organization;
615
+ }
616
+ return headers;
617
+ }
618
+ /**
619
+ * Checks if callback exists and adds analytics in place if it's set.
620
+ *
621
+ * @param request
622
+ * @param options
623
+ */
624
+ onFinish(providerInfo, options) {
625
+ if (options.analytics) {
626
+ return updateWithAnalytics(providerInfo, options.analytics);
627
+ }
628
+ return providerInfo;
629
+ }
630
+ };
631
+ var upstash = () => {
632
+ return new LLMProvider("https://qstash.upstash.io/llm", "", "upstash");
633
+ };
634
+
635
+ // src/client/api/utils.ts
636
+ var getProviderInfo = (api, upstashToken) => {
637
+ const { name, provider, ...parameters } = api;
638
+ const finalProvider = provider ?? upstash();
639
+ if (finalProvider.owner === "upstash" && !finalProvider.token) {
640
+ finalProvider.token = upstashToken;
641
+ }
642
+ if (!finalProvider.baseUrl)
643
+ throw new TypeError("baseUrl cannot be empty or undefined!");
644
+ if (!finalProvider.token)
645
+ throw new TypeError("token cannot be empty or undefined!");
646
+ if (finalProvider.apiKind !== name) {
647
+ throw new TypeError(
648
+ `Unexpected api name. Expected '${finalProvider.apiKind}', received ${name}`
649
+ );
650
+ }
651
+ const providerInfo = {
652
+ url: finalProvider.getUrl(),
653
+ baseUrl: finalProvider.baseUrl,
654
+ route: finalProvider.getRoute(),
655
+ appendHeaders: finalProvider.getHeaders(parameters),
656
+ owner: finalProvider.owner
657
+ };
658
+ return finalProvider.onFinish(providerInfo, parameters);
659
+ };
660
+ var processApi = (request, upstashToken) => {
661
+ if (!request.api) {
662
+ return request;
663
+ }
664
+ const { url, appendHeaders, owner } = getProviderInfo(request.api, upstashToken);
665
+ if (request.api.name === "llm") {
666
+ const callback = request.callback;
667
+ if (!callback) {
668
+ throw new TypeError("Callback cannot be undefined when using LLM api.");
669
+ }
670
+ return {
671
+ ...request,
672
+ // @ts-expect-error undici header conflict
673
+ headers: new Headers({
674
+ ...request.headers,
675
+ ...appendHeaders
676
+ }),
677
+ ...owner === "upstash" && !request.api.analytics ? { api: { name: "llm" }, url: void 0, callback } : { url, api: void 0 }
678
+ };
679
+ } else {
680
+ return {
681
+ ...request,
682
+ // @ts-expect-error undici header conflict
683
+ headers: new Headers({
684
+ ...request.headers,
685
+ ...appendHeaders
686
+ }),
687
+ url,
688
+ api: void 0
689
+ };
690
+ }
691
+ };
692
+ function updateWithAnalytics(providerInfo, analytics) {
693
+ switch (analytics.name) {
694
+ case "helicone": {
695
+ providerInfo.appendHeaders["Helicone-Auth"] = `Bearer ${analytics.token}`;
696
+ if (providerInfo.owner === "upstash") {
697
+ updateProviderInfo(providerInfo, "https://qstash.helicone.ai", [
698
+ "llm",
699
+ ...providerInfo.route
700
+ ]);
701
+ } else {
702
+ providerInfo.appendHeaders["Helicone-Target-Url"] = providerInfo.baseUrl;
703
+ updateProviderInfo(providerInfo, "https://gateway.helicone.ai", providerInfo.route);
704
+ }
705
+ return providerInfo;
706
+ }
707
+ default: {
708
+ throw new Error("Unknown analytics provider");
709
+ }
710
+ }
711
+ }
712
+ function updateProviderInfo(providerInfo, baseUrl, route) {
713
+ providerInfo.baseUrl = baseUrl;
714
+ providerInfo.route = route;
715
+ providerInfo.url = `${baseUrl}/${route.join("/")}`;
716
+ }
717
+
641
718
  // src/client/utils.ts
642
719
  var isIgnoredHeader = (header) => {
643
720
  const lowerCaseHeader = header.toLowerCase();
@@ -670,7 +747,7 @@ function processHeaders(request) {
670
747
  if (request.deduplicationId !== void 0) {
671
748
  headers.set("Upstash-Deduplication-Id", request.deduplicationId);
672
749
  }
673
- if (request.contentBasedDeduplication !== void 0) {
750
+ if (request.contentBasedDeduplication) {
674
751
  headers.set("Upstash-Content-Based-Deduplication", "true");
675
752
  }
676
753
  if (request.retries !== void 0) {
@@ -696,9 +773,10 @@ function getRequestPath(request) {
696
773
  if (nonApiPath)
697
774
  return nonApiPath;
698
775
  if (request.api?.name === "llm")
699
- return `api/${request.api.name}`;
776
+ return `api/llm`;
700
777
  if (request.api?.name === "email") {
701
- return request.api.provider.baseUrl;
778
+ const providerInfo = getProviderInfo(request.api, "not-needed");
779
+ return providerInfo.baseUrl;
702
780
  }
703
781
  throw new QstashError(`Failed to infer request path for ${JSON.stringify(request)}`);
704
782
  }
@@ -815,12 +893,12 @@ var Queue = class {
815
893
  async enqueueJSON(request) {
816
894
  const headers = prefixHeaders(new Headers(request.headers));
817
895
  headers.set("Content-Type", "application/json");
818
- ensureCallbackPresent(request);
819
- appendLLMOptionsIfNeeded(request, headers, this.http);
820
- appendAPIOptions(request, headers);
896
+ request.headers = headers;
897
+ const upstashToken = String(this.http.authorization).split("Bearer ")[1];
898
+ const nonApiRequest = processApi(request, upstashToken);
821
899
  const response = await this.enqueue({
822
- ...request,
823
- body: JSON.stringify(request.body),
900
+ ...nonApiRequest,
901
+ body: JSON.stringify(nonApiRequest.body),
824
902
  headers
825
903
  });
826
904
  return response;
@@ -1118,13 +1196,12 @@ var Client = class {
1118
1196
  async publishJSON(request) {
1119
1197
  const headers = prefixHeaders(new Headers(request.headers));
1120
1198
  headers.set("Content-Type", "application/json");
1121
- ensureCallbackPresent(request);
1122
- appendLLMOptionsIfNeeded(request, headers, this.http);
1123
- appendAPIOptions(request, headers);
1199
+ request.headers = headers;
1200
+ const upstashToken = String(this.http.authorization).split("Bearer ")[1];
1201
+ const nonApiRequest = processApi(request, upstashToken);
1124
1202
  const response = await this.publish({
1125
- ...request,
1126
- headers,
1127
- body: JSON.stringify(request.body)
1203
+ ...nonApiRequest,
1204
+ body: JSON.stringify(nonApiRequest.body)
1128
1205
  });
1129
1206
  return response;
1130
1207
  }
@@ -1158,17 +1235,17 @@ var Client = class {
1158
1235
  * Batch publish messages to QStash, serializing each body to JSON.
1159
1236
  */
1160
1237
  async batchJSON(request) {
1161
- for (const message of request) {
1238
+ const batchPayload = request.map((message) => {
1162
1239
  if ("body" in message) {
1163
1240
  message.body = JSON.stringify(message.body);
1164
1241
  }
1165
1242
  message.headers = new Headers(message.headers);
1166
- ensureCallbackPresent(message);
1167
- appendLLMOptionsIfNeeded(message, message.headers, this.http);
1168
- appendAPIOptions(message, message.headers);
1169
- message.headers.set("Content-Type", "application/json");
1170
- }
1171
- const response = await this.batch(request);
1243
+ const upstashToken = String(this.http.authorization).split("Bearer ")[1];
1244
+ const nonApiMessage = processApi(message, upstashToken);
1245
+ nonApiMessage.headers.set("Content-Type", "application/json");
1246
+ return nonApiMessage;
1247
+ });
1248
+ const response = await this.batch(batchPayload);
1172
1249
  return response;
1173
1250
  }
1174
1251
  /**
package/cloudflare.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  serve
3
- } from "./chunk-Q2AGFQYM.mjs";
3
+ } from "./chunk-GWAFAA2M.mjs";
4
4
 
5
5
  // platforms/cloudflare.ts
6
6
  var getArgs = (args) => {
package/h3.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as h3 from 'h3';
2
2
  import { H3Event } from 'h3';
3
- import { a3 as RouteFunction, a4 as WorkflowServeOptions } from './client-kxUsvnWj.mjs';
3
+ import { a3 as RouteFunction, a4 as WorkflowServeOptions } from './client-RORrka04.mjs';
4
4
  import 'neverthrow';
5
5
 
6
6
  type VerifySignatureConfig = {
package/h3.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as h3 from 'h3';
2
2
  import { H3Event } from 'h3';
3
- import { a3 as RouteFunction, a4 as WorkflowServeOptions } from './client-kxUsvnWj.js';
3
+ import { a3 as RouteFunction, a4 as WorkflowServeOptions } from './client-RORrka04.js';
4
4
  import 'neverthrow';
5
5
 
6
6
  type VerifySignatureConfig = {