@upstash/workflow 0.2.8-rc-invoke → 0.2.8

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.
package/h3.d.ts CHANGED
@@ -1,17 +1,15 @@
1
1
  import * as h3 from 'h3';
2
- import { R as RouteFunction, j as PublicServeOptions, t as InvokableWorkflow } from './types-C7Y7WUQd.js';
3
- import { s as serveManyBase } from './serve-many-Dw-UUnH6.js';
2
+ import { R as RouteFunction, k as PublicServeOptions } from './types-B62AnIU3.js';
4
3
  import '@upstash/qstash';
5
4
  import 'zod';
6
5
  import 'ai';
7
6
  import '@ai-sdk/openai';
8
7
 
9
- declare const serve: <TInitialPayload = unknown, TResult = unknown>(routeFunction: RouteFunction<TInitialPayload, TResult>, options?: PublicServeOptions<TInitialPayload>) => {
10
- handler: h3.EventHandler<h3.EventHandlerRequest, Promise<Response>>;
11
- };
12
- declare const createWorkflow: <TInitialPayload, TResult>(routeFunction: RouteFunction<TInitialPayload, TResult>, options?: PublicServeOptions<TInitialPayload> | undefined) => InvokableWorkflow<TInitialPayload, TResult, Parameters<ReturnType<typeof serve<TInitialPayload, TResult>>["handler"]>>;
13
- declare const serveMany: (workflows: Parameters<typeof serveManyBase>[0]["workflows"]) => {
14
- handler: (event: h3.H3Event<h3.EventHandlerRequest>) => Promise<any>;
8
+ declare const serve: <TInitialPayload = unknown>(routeFunction: RouteFunction<TInitialPayload>, options?: PublicServeOptions<TInitialPayload>) => {
9
+ handler: h3.EventHandler<h3.EventHandlerRequest, Promise<Response | {
10
+ status: number;
11
+ body: string;
12
+ }>>;
15
13
  };
16
14
 
17
- export { createWorkflow, serve, serveMany };
15
+ export { serve };
package/h3.js CHANGED
@@ -20,9 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // platforms/h3.ts
21
21
  var h3_exports = {};
22
22
  __export(h3_exports, {
23
- createWorkflow: () => createWorkflow,
24
- serve: () => serve,
25
- serveMany: () => serveMany
23
+ serve: () => serve
26
24
  });
27
25
  module.exports = __toCommonJS(h3_exports);
28
26
 
@@ -402,7 +400,7 @@ var WORKFLOW_PROTOCOL_VERSION_HEADER = "Upstash-Workflow-Sdk-Version";
402
400
  var DEFAULT_CONTENT_TYPE = "application/json";
403
401
  var NO_CONCURRENCY = 1;
404
402
  var DEFAULT_RETRIES = 3;
405
- var VERSION = "v0.2.7";
403
+ var VERSION = "v0.2.3";
406
404
  var SDK_TELEMETRY = `@upstash/workflow@${VERSION}`;
407
405
  var TELEMETRY_HEADER_SDK = "Upstash-Telemetry-Sdk";
408
406
  var TELEMETRY_HEADER_FRAMEWORK = "Upstash-Telemetry-Framework";
@@ -449,31 +447,6 @@ var formatWorkflowError = (error) => {
449
447
  };
450
448
  };
451
449
 
452
- // src/utils.ts
453
- var NANOID_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
454
- var NANOID_LENGTH = 21;
455
- function getRandomInt() {
456
- return Math.floor(Math.random() * NANOID_CHARS.length);
457
- }
458
- function nanoid() {
459
- return Array.from({ length: NANOID_LENGTH }).map(() => NANOID_CHARS[getRandomInt()]).join("");
460
- }
461
- function getWorkflowRunId(id) {
462
- return `wfr_${id ?? nanoid()}`;
463
- }
464
- function decodeBase64(base64) {
465
- try {
466
- const binString = atob(base64);
467
- const intArray = Uint8Array.from(binString, (m) => m.codePointAt(0));
468
- return new TextDecoder().decode(intArray);
469
- } catch (error) {
470
- console.warn(
471
- `Upstash Qstash: Failed while decoding base64 "${base64}". Decoding with atob and returning it instead. ${error}`
472
- );
473
- return atob(base64);
474
- }
475
- }
476
-
477
450
  // src/context/steps.ts
478
451
  var BaseLazyStep = class {
479
452
  stepName;
@@ -654,41 +627,6 @@ var LazyNotifyStep = class extends LazyFunctionStep {
654
627
  });
655
628
  }
656
629
  };
657
- var LazyInvokeStep = class extends BaseLazyStep {
658
- stepType = "Invoke";
659
- params;
660
- constructor(stepName, { workflow, body, headers = {}, workflowRunId, retries }) {
661
- super(stepName);
662
- this.params = {
663
- workflow,
664
- body,
665
- headers,
666
- workflowRunId: getWorkflowRunId(workflowRunId),
667
- retries
668
- };
669
- }
670
- getPlanStep(concurrent, targetStep) {
671
- return {
672
- stepId: 0,
673
- stepName: this.stepName,
674
- stepType: this.stepType,
675
- concurrent,
676
- targetStep
677
- };
678
- }
679
- /**
680
- * won't be used as it's the server who will add the result step
681
- * in Invoke step.
682
- */
683
- getResultStep(concurrent, stepId) {
684
- return Promise.resolve({
685
- stepId,
686
- stepName: this.stepName,
687
- stepType: this.stepType,
688
- concurrent
689
- });
690
- }
691
- };
692
630
 
693
631
  // node_modules/neverthrow/dist/index.es.js
694
632
  var defaultErrorConfig = {
@@ -1113,8 +1051,7 @@ var StepTypes = [
1113
1051
  "SleepUntil",
1114
1052
  "Call",
1115
1053
  "Wait",
1116
- "Notify",
1117
- "Invoke"
1054
+ "Notify"
1118
1055
  ];
1119
1056
 
1120
1057
  // src/workflow-requests.ts
@@ -1122,7 +1059,7 @@ var import_qstash3 = require("@upstash/qstash");
1122
1059
  var triggerFirstInvocation = async ({
1123
1060
  workflowContext,
1124
1061
  useJSONContent,
1125
- telemetry: telemetry2,
1062
+ telemetry,
1126
1063
  debug
1127
1064
  }) => {
1128
1065
  const { headers } = getHeaders({
@@ -1132,7 +1069,7 @@ var triggerFirstInvocation = async ({
1132
1069
  userHeaders: workflowContext.headers,
1133
1070
  failureUrl: workflowContext.failureUrl,
1134
1071
  retries: workflowContext.retries,
1135
- telemetry: telemetry2
1072
+ telemetry
1136
1073
  });
1137
1074
  if (workflowContext.headers.get("content-type")) {
1138
1075
  headers["content-type"] = workflowContext.headers.get("content-type");
@@ -1178,8 +1115,8 @@ var triggerRouteFunction = async ({
1178
1115
  debug
1179
1116
  }) => {
1180
1117
  try {
1181
- const result = await onStep();
1182
- await onCleanup(result);
1118
+ await onStep();
1119
+ await onCleanup();
1183
1120
  return ok("workflow-finished");
1184
1121
  } catch (error) {
1185
1122
  const error_ = error;
@@ -1200,15 +1137,14 @@ var triggerRouteFunction = async ({
1200
1137
  }
1201
1138
  }
1202
1139
  };
1203
- var triggerWorkflowDelete = async (workflowContext, result, debug, cancel = false) => {
1140
+ var triggerWorkflowDelete = async (workflowContext, debug, cancel = false) => {
1204
1141
  await debug?.log("SUBMIT", "SUBMIT_CLEANUP", {
1205
1142
  deletedWorkflowRunId: workflowContext.workflowRunId
1206
1143
  });
1207
1144
  await workflowContext.qstashClient.http.request({
1208
1145
  path: ["v2", "workflows", "runs", `${workflowContext.workflowRunId}?cancel=${cancel}`],
1209
1146
  method: "DELETE",
1210
- parseResponseAsJson: false,
1211
- body: JSON.stringify(result)
1147
+ parseResponseAsJson: false
1212
1148
  });
1213
1149
  await debug?.log(
1214
1150
  "SUBMIT",
@@ -1237,7 +1173,7 @@ var handleThirdPartyCallResult = async ({
1237
1173
  workflowUrl,
1238
1174
  failureUrl,
1239
1175
  retries,
1240
- telemetry: telemetry2,
1176
+ telemetry,
1241
1177
  debug
1242
1178
  }) => {
1243
1179
  try {
@@ -1305,7 +1241,7 @@ ${atob(callbackMessage.body ?? "")}`
1305
1241
  userHeaders,
1306
1242
  failureUrl,
1307
1243
  retries,
1308
- telemetry: telemetry2
1244
+ telemetry
1309
1245
  });
1310
1246
  const callResponse = {
1311
1247
  status: callbackMessage.status,
@@ -1344,11 +1280,11 @@ ${atob(callbackMessage.body ?? "")}`
1344
1280
  );
1345
1281
  }
1346
1282
  };
1347
- var getTelemetryHeaders = (telemetry2) => {
1283
+ var getTelemetryHeaders = (telemetry) => {
1348
1284
  return {
1349
- [TELEMETRY_HEADER_SDK]: telemetry2.sdk,
1350
- [TELEMETRY_HEADER_FRAMEWORK]: telemetry2.framework,
1351
- [TELEMETRY_HEADER_RUNTIME]: telemetry2.runtime ?? "unknown"
1285
+ [TELEMETRY_HEADER_SDK]: telemetry.sdk,
1286
+ [TELEMETRY_HEADER_FRAMEWORK]: telemetry.framework,
1287
+ [TELEMETRY_HEADER_RUNTIME]: telemetry.runtime ?? "unknown"
1352
1288
  };
1353
1289
  };
1354
1290
  var getHeaders = ({
@@ -1361,17 +1297,14 @@ var getHeaders = ({
1361
1297
  step,
1362
1298
  callRetries,
1363
1299
  callTimeout,
1364
- telemetry: telemetry2
1300
+ telemetry
1365
1301
  }) => {
1366
- const contentType = (userHeaders ? userHeaders.get("Content-Type") : void 0) ?? DEFAULT_CONTENT_TYPE;
1367
1302
  const baseHeaders = {
1368
1303
  [WORKFLOW_INIT_HEADER]: initHeaderValue,
1369
1304
  [WORKFLOW_ID_HEADER]: workflowRunId,
1370
1305
  [WORKFLOW_URL_HEADER]: workflowUrl,
1371
1306
  [WORKFLOW_FEATURE_HEADER]: "LazyFetch,InitialBody",
1372
- [WORKFLOW_PROTOCOL_VERSION_HEADER]: WORKFLOW_PROTOCOL_VERSION,
1373
- "content-type": contentType,
1374
- ...telemetry2 ? getTelemetryHeaders(telemetry2) : {}
1307
+ ...telemetry ? getTelemetryHeaders(telemetry) : {}
1375
1308
  };
1376
1309
  if (!step?.callUrl) {
1377
1310
  baseHeaders[`Upstash-Forward-${WORKFLOW_PROTOCOL_VERSION_HEADER}`] = WORKFLOW_PROTOCOL_VERSION;
@@ -1381,13 +1314,18 @@ var getHeaders = ({
1381
1314
  }
1382
1315
  if (failureUrl) {
1383
1316
  baseHeaders[`Upstash-Failure-Callback-Forward-${WORKFLOW_FAILURE_HEADER}`] = "true";
1317
+ baseHeaders[`Upstash-Failure-Callback-Forward-Upstash-Workflow-Failure-Callback`] = "true";
1318
+ baseHeaders["Upstash-Failure-Callback-Workflow-Runid"] = workflowRunId;
1319
+ baseHeaders["Upstash-Failure-Callback-Workflow-Init"] = "false";
1320
+ baseHeaders["Upstash-Failure-Callback-Workflow-Url"] = workflowUrl;
1321
+ baseHeaders["Upstash-Failure-Callback-Workflow-Calltype"] = "failureCall";
1322
+ if (retries !== void 0) {
1323
+ baseHeaders["Upstash-Failure-Callback-Retries"] = retries.toString();
1324
+ }
1384
1325
  if (!step?.callUrl) {
1385
1326
  baseHeaders["Upstash-Failure-Callback"] = failureUrl;
1386
1327
  }
1387
1328
  }
1388
- if (step?.stepType === "Invoke") {
1389
- baseHeaders["upstash-workflow-invoke"] = "true";
1390
- }
1391
1329
  if (step?.callUrl) {
1392
1330
  baseHeaders["Upstash-Retries"] = callRetries?.toString() ?? "0";
1393
1331
  baseHeaders[WORKFLOW_FEATURE_HEADER] = "WF_NoDelete,InitialBody";
@@ -1409,6 +1347,7 @@ var getHeaders = ({
1409
1347
  baseHeaders[`Upstash-Failure-Callback-Forward-${header}`] = userHeaders.get(header);
1410
1348
  }
1411
1349
  }
1350
+ const contentType = (userHeaders ? userHeaders.get("Content-Type") : void 0) ?? DEFAULT_CONTENT_TYPE;
1412
1351
  if (step?.callHeaders) {
1413
1352
  const forwardedHeaders = Object.fromEntries(
1414
1353
  Object.entries(step.callHeaders).map(([header, value]) => [
@@ -1448,8 +1387,8 @@ var getHeaders = ({
1448
1387
  Object.entries(baseHeaders).map(([header, value]) => [header, [value]])
1449
1388
  ),
1450
1389
  // to include telemetry headers:
1451
- ...telemetry2 ? Object.fromEntries(
1452
- Object.entries(getTelemetryHeaders(telemetry2)).map(([header, value]) => [
1390
+ ...telemetry ? Object.fromEntries(
1391
+ Object.entries(getTelemetryHeaders(telemetry)).map(([header, value]) => [
1453
1392
  header,
1454
1393
  [value]
1455
1394
  ])
@@ -1458,7 +1397,8 @@ var getHeaders = ({
1458
1397
  "Upstash-Workflow-Runid": [workflowRunId],
1459
1398
  [WORKFLOW_INIT_HEADER]: ["false"],
1460
1399
  [WORKFLOW_URL_HEADER]: [workflowUrl],
1461
- "Upstash-Workflow-CallType": ["step"]
1400
+ "Upstash-Workflow-CallType": ["step"],
1401
+ "Content-Type": [contentType]
1462
1402
  }
1463
1403
  };
1464
1404
  }
@@ -1504,10 +1444,10 @@ var AutoExecutor = class _AutoExecutor {
1504
1444
  stepCount = 0;
1505
1445
  planStepCount = 0;
1506
1446
  executingStep = false;
1507
- constructor(context, steps, telemetry2, debug) {
1447
+ constructor(context, steps, telemetry, debug) {
1508
1448
  this.context = context;
1509
1449
  this.steps = steps;
1510
- this.telemetry = telemetry2;
1450
+ this.telemetry = telemetry;
1511
1451
  this.debug = debug;
1512
1452
  this.nonPlanStepCount = this.steps.filter((step) => !step.targetStep).length;
1513
1453
  }
@@ -1753,23 +1693,7 @@ var AutoExecutor = class _AutoExecutor {
1753
1693
  method: "POST",
1754
1694
  parseResponseAsJson: false
1755
1695
  });
1756
- throw new WorkflowAbort(waitStep.stepName, waitStep);
1757
- }
1758
- if (steps.length === 1 && lazySteps[0] instanceof LazyInvokeStep) {
1759
- const invokeStep = steps[0];
1760
- const lazyInvokeStep = lazySteps[0];
1761
- await lazyInvokeStep.params.workflow.callback(
1762
- {
1763
- body: lazyInvokeStep.params.body,
1764
- headers: lazyInvokeStep.params.headers,
1765
- workflowRunId: lazyInvokeStep.params.workflowRunId,
1766
- workflow: lazyInvokeStep.params.workflow,
1767
- retries: lazyInvokeStep.params.retries
1768
- },
1769
- invokeStep,
1770
- this.context
1771
- );
1772
- throw new WorkflowAbort(invokeStep.stepName, invokeStep);
1696
+ throw new WorkflowAbort(steps[0].stepName, steps[0]);
1773
1697
  }
1774
1698
  const result = await this.context.qstashClient.batchJSON(
1775
1699
  steps.map((singleStep, index) => {
@@ -2088,9 +2012,10 @@ var wrapTools = ({
2088
2012
  return Object.fromEntries(
2089
2013
  Object.entries(tools).map((toolInfo) => {
2090
2014
  const [toolName, tool3] = toolInfo;
2015
+ const executeAsStep = "executeAsStep" in tool3 ? tool3.executeAsStep : true;
2091
2016
  const aiSDKTool = convertToAISDKTool(tool3);
2092
2017
  const execute = aiSDKTool.execute;
2093
- if (execute) {
2018
+ if (execute && executeAsStep) {
2094
2019
  const wrappedExecute = (...params) => {
2095
2020
  return context.run(`Run tool ${toolName}`, () => execute(...params));
2096
2021
  };
@@ -2455,7 +2380,7 @@ var WorkflowContext = class {
2455
2380
  initialPayload,
2456
2381
  env,
2457
2382
  retries,
2458
- telemetry: telemetry2
2383
+ telemetry
2459
2384
  }) {
2460
2385
  this.qstashClient = qstashClient;
2461
2386
  this.workflowRunId = workflowRunId;
@@ -2466,7 +2391,7 @@ var WorkflowContext = class {
2466
2391
  this.requestPayload = initialPayload;
2467
2392
  this.env = env ?? {};
2468
2393
  this.retries = retries ?? DEFAULT_RETRIES;
2469
- this.executor = new AutoExecutor(this, this.steps, telemetry2, debug);
2394
+ this.executor = new AutoExecutor(this, this.steps, telemetry, debug);
2470
2395
  }
2471
2396
  /**
2472
2397
  * Executes a workflow step
@@ -2686,13 +2611,6 @@ var WorkflowContext = class {
2686
2611
  return result;
2687
2612
  }
2688
2613
  }
2689
- async invoke(stepName, settings) {
2690
- const result = await this.addStep(new LazyInvokeStep(stepName, settings));
2691
- return {
2692
- ...result,
2693
- body: result.body ? JSON.parse(result.body) : void 0
2694
- };
2695
- }
2696
2614
  /**
2697
2615
  * Cancel the current workflow run
2698
2616
  *
@@ -2770,6 +2688,31 @@ var WorkflowLogger = class _WorkflowLogger {
2770
2688
  }
2771
2689
  };
2772
2690
 
2691
+ // src/utils.ts
2692
+ var NANOID_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
2693
+ var NANOID_LENGTH = 21;
2694
+ function getRandomInt() {
2695
+ return Math.floor(Math.random() * NANOID_CHARS.length);
2696
+ }
2697
+ function nanoid() {
2698
+ return Array.from({ length: NANOID_LENGTH }).map(() => NANOID_CHARS[getRandomInt()]).join("");
2699
+ }
2700
+ function getWorkflowRunId(id) {
2701
+ return `wfr_${id ?? nanoid()}`;
2702
+ }
2703
+ function decodeBase64(base64) {
2704
+ try {
2705
+ const binString = atob(base64);
2706
+ const intArray = Uint8Array.from(binString, (m) => m.codePointAt(0));
2707
+ return new TextDecoder().decode(intArray);
2708
+ } catch (error) {
2709
+ console.warn(
2710
+ `Upstash Qstash: Failed while decoding base64 "${base64}". Decoding with atob and returning it instead. ${error}`
2711
+ );
2712
+ return atob(base64);
2713
+ }
2714
+ }
2715
+
2773
2716
  // src/serve/authorization.ts
2774
2717
  var import_qstash8 = require("@upstash/qstash");
2775
2718
  var DisabledWorkflowContext = class _DisabledWorkflowContext extends WorkflowContext {
@@ -3107,7 +3050,7 @@ var determineUrls = async (request, url, baseUrl, failureFunction, failureUrl, d
3107
3050
  var AUTH_FAIL_MESSAGE = `Failed to authenticate Workflow request. If this is unexpected, see the caveat https://upstash.com/docs/workflow/basics/caveats#avoid-non-deterministic-code-outside-context-run`;
3108
3051
 
3109
3052
  // src/serve/index.ts
3110
- var serveBase = (routeFunction, telemetry2, options) => {
3053
+ var serveBase = (routeFunction, telemetry, options) => {
3111
3054
  const {
3112
3055
  qstashClient,
3113
3056
  onStepFinish,
@@ -3123,7 +3066,7 @@ var serveBase = (routeFunction, telemetry2, options) => {
3123
3066
  useJSONContent,
3124
3067
  disableTelemetry
3125
3068
  } = processOptions(options);
3126
- telemetry2 = disableTelemetry ? void 0 : telemetry2;
3069
+ telemetry = disableTelemetry ? void 0 : telemetry;
3127
3070
  const debug = WorkflowLogger.getLogger(verbose);
3128
3071
  const handler = async (request) => {
3129
3072
  await debug?.log("INFO", "ENDPOINT_START");
@@ -3181,7 +3124,7 @@ var serveBase = (routeFunction, telemetry2, options) => {
3181
3124
  debug,
3182
3125
  env,
3183
3126
  retries,
3184
- telemetry: telemetry2
3127
+ telemetry
3185
3128
  });
3186
3129
  const authCheck = await DisabledWorkflowContext.tryAuthentication(
3187
3130
  routeFunction,
@@ -3204,7 +3147,7 @@ var serveBase = (routeFunction, telemetry2, options) => {
3204
3147
  workflowUrl,
3205
3148
  failureUrl: workflowFailureUrl,
3206
3149
  retries,
3207
- telemetry: telemetry2,
3150
+ telemetry,
3208
3151
  debug
3209
3152
  });
3210
3153
  if (callReturnCheck.isErr()) {
@@ -3213,10 +3156,10 @@ var serveBase = (routeFunction, telemetry2, options) => {
3213
3156
  });
3214
3157
  throw callReturnCheck.error;
3215
3158
  } else if (callReturnCheck.value === "continue-workflow") {
3216
- const result = isFirstInvocation ? await triggerFirstInvocation({ workflowContext, useJSONContent, telemetry: telemetry2, debug }) : await triggerRouteFunction({
3159
+ const result = isFirstInvocation ? await triggerFirstInvocation({ workflowContext, useJSONContent, telemetry, debug }) : await triggerRouteFunction({
3217
3160
  onStep: async () => routeFunction(workflowContext),
3218
- onCleanup: async (result2) => {
3219
- await triggerWorkflowDelete(workflowContext, result2, debug);
3161
+ onCleanup: async () => {
3162
+ await triggerWorkflowDelete(workflowContext, debug);
3220
3163
  },
3221
3164
  onCancel: async () => {
3222
3165
  await makeCancelRequest(workflowContext.qstashClient.http, workflowRunId);
@@ -3248,91 +3191,6 @@ var serveBase = (routeFunction, telemetry2, options) => {
3248
3191
  return { handler: safeHandler };
3249
3192
  };
3250
3193
 
3251
- // src/serve/serve-many.ts
3252
- var serveManyBase = ({
3253
- workflows,
3254
- getWorkflowId
3255
- }) => {
3256
- const workflowIds = [];
3257
- const workflowMap = Object.fromEntries(
3258
- Object.entries(workflows).map((workflow) => {
3259
- const workflowId = workflow[0];
3260
- if (workflowIds.includes(workflowId)) {
3261
- throw new WorkflowError(
3262
- `Duplicate workflow name found: '${workflowId}'. Please set different workflow names in serveMany.`
3263
- );
3264
- }
3265
- if (workflowId.includes("/")) {
3266
- throw new WorkflowError(
3267
- `Invalid workflow name found: '${workflowId}'. Workflow name cannot contain '/'.`
3268
- );
3269
- }
3270
- workflowIds.push(workflowId);
3271
- workflow[1].workflowId = workflowId;
3272
- return [workflowId, workflow[1].handler];
3273
- })
3274
- );
3275
- return {
3276
- handler: async (...params) => {
3277
- const pickedWorkflowId = getWorkflowId(...params);
3278
- if (!pickedWorkflowId) {
3279
- throw new WorkflowError(`Unexpected request in serveMany. workflowId not set. Please update the URL of your request.`);
3280
- }
3281
- const workflow = workflowMap[pickedWorkflowId];
3282
- if (!workflow) {
3283
- throw new WorkflowError(`No workflows in serveMany found for '${pickedWorkflowId}'. Please update the URL of your request.`);
3284
- }
3285
- return await workflow(...params);
3286
- }
3287
- };
3288
- };
3289
- var createInvokeCallback = (telemetry2) => {
3290
- const invokeCallback = async (settings, invokeStep, context) => {
3291
- const { body, workflow, headers = {}, workflowRunId = getWorkflowRunId(), retries } = settings;
3292
- const { workflowId } = workflow;
3293
- if (!workflowId) {
3294
- throw new WorkflowError("You can only invoke workflow which has a workflowId");
3295
- }
3296
- const { headers: invokerHeaders } = getHeaders({
3297
- initHeaderValue: "false",
3298
- workflowRunId: context.workflowRunId,
3299
- workflowUrl: context.url,
3300
- userHeaders: context.headers,
3301
- failureUrl: context.failureUrl,
3302
- retries: context.retries,
3303
- telemetry: telemetry2
3304
- });
3305
- invokerHeaders["Upstash-Workflow-Runid"] = context.workflowRunId;
3306
- const newUrl = context.url.replace(/[^/]+$/, workflowId);
3307
- const { headers: triggerHeaders } = getHeaders({
3308
- initHeaderValue: "true",
3309
- workflowRunId,
3310
- workflowUrl: newUrl,
3311
- userHeaders: new Headers(headers),
3312
- retries,
3313
- telemetry: telemetry2
3314
- });
3315
- triggerHeaders["Upstash-Workflow-Invoke"] = "true";
3316
- const request = {
3317
- body: JSON.stringify(body),
3318
- headers: Object.fromEntries(
3319
- Object.entries(invokerHeaders).map((pairs) => [pairs[0], [pairs[1]]])
3320
- ),
3321
- workflowRunId,
3322
- workflowUrl: context.url,
3323
- step: invokeStep
3324
- };
3325
- await context.qstashClient.publish({
3326
- headers: triggerHeaders,
3327
- method: "POST",
3328
- body: JSON.stringify(request),
3329
- url: newUrl
3330
- });
3331
- return void 0;
3332
- };
3333
- return invokeCallback;
3334
- };
3335
-
3336
3194
  // platforms/h3.ts
3337
3195
  function transformHeaders(headers) {
3338
3196
  const formattedHeaders = Object.entries(headers).map(([key, value]) => [
@@ -3341,59 +3199,39 @@ function transformHeaders(headers) {
3341
3199
  ]);
3342
3200
  return formattedHeaders;
3343
3201
  }
3344
- function getUrl(event) {
3345
- const request_ = event.node.req;
3346
- const protocol = request_.headers["x-forwarded-proto"];
3347
- const host = request_.headers.host;
3348
- const url = `${protocol}://${host}${event.path}`;
3349
- return url;
3350
- }
3351
- var telemetry = {
3352
- sdk: SDK_TELEMETRY,
3353
- framework: "h3",
3354
- runtime: process.versions.bun ? `bun@${process.versions.bun}/node@${process.version}` : `node@${process.version}`
3355
- };
3356
3202
  var serve = (routeFunction, options) => {
3357
3203
  const handler = defineEventHandler(async (event) => {
3358
3204
  const method = event.node.req.method;
3359
3205
  if (method?.toUpperCase() !== "POST") {
3360
- return new Response("Only POST requests are allowed in worklfows", {
3361
- status: 405
3362
- });
3206
+ return {
3207
+ status: 405,
3208
+ body: "Only POST requests are allowed in worklfows"
3209
+ };
3363
3210
  }
3364
- const url = getUrl(event);
3365
- const headers = transformHeaders(event.node.req.headers);
3211
+ const request_ = event.node.req;
3212
+ const protocol = request_.headers["x-forwarded-proto"];
3213
+ const host = request_.headers.host;
3214
+ const url = `${protocol}://${host}${event.path}`;
3215
+ const headers = transformHeaders(request_.headers);
3366
3216
  const request = new Request(url, {
3367
3217
  headers,
3368
3218
  body: await readRawBody(event),
3369
3219
  method: "POST"
3370
3220
  });
3371
- const { handler: serveHandler } = serveBase(routeFunction, telemetry, options);
3221
+ const { handler: serveHandler } = serveBase(
3222
+ routeFunction,
3223
+ {
3224
+ sdk: SDK_TELEMETRY,
3225
+ framework: "h3",
3226
+ runtime: process.versions.bun ? `bun@${process.versions.bun}/node@${process.version}` : `node@${process.version}`
3227
+ },
3228
+ options
3229
+ );
3372
3230
  return await serveHandler(request);
3373
3231
  });
3374
3232
  return { handler };
3375
3233
  };
3376
- var createWorkflow = (...params) => {
3377
- const { handler } = serve(...params);
3378
- return {
3379
- callback: createInvokeCallback(telemetry),
3380
- handler,
3381
- workflowId: void 0
3382
- };
3383
- };
3384
- var serveMany = (workflows) => {
3385
- return serveManyBase({
3386
- workflows,
3387
- getWorkflowId(event) {
3388
- const url = getUrl(event);
3389
- const components = url.split("/");
3390
- return components[components.length - 1];
3391
- }
3392
- });
3393
- };
3394
3234
  // Annotate the CommonJS export names for ESM import in node:
3395
3235
  0 && (module.exports = {
3396
- createWorkflow,
3397
- serve,
3398
- serveMany
3236
+ serve
3399
3237
  });
package/h3.mjs CHANGED
@@ -1,11 +1,7 @@
1
- import {
2
- createInvokeCallback,
3
- serveManyBase
4
- } from "./chunk-LCZMBGEM.mjs";
5
1
  import {
6
2
  SDK_TELEMETRY,
7
3
  serveBase
8
- } from "./chunk-IWAW7GIG.mjs";
4
+ } from "./chunk-BPUSHNSD.mjs";
9
5
 
10
6
  // node_modules/defu/dist/defu.mjs
11
7
  function isPlainObject(value) {
@@ -327,58 +323,38 @@ function transformHeaders(headers) {
327
323
  ]);
328
324
  return formattedHeaders;
329
325
  }
330
- function getUrl(event) {
331
- const request_ = event.node.req;
332
- const protocol = request_.headers["x-forwarded-proto"];
333
- const host = request_.headers.host;
334
- const url = `${protocol}://${host}${event.path}`;
335
- return url;
336
- }
337
- var telemetry = {
338
- sdk: SDK_TELEMETRY,
339
- framework: "h3",
340
- runtime: process.versions.bun ? `bun@${process.versions.bun}/node@${process.version}` : `node@${process.version}`
341
- };
342
326
  var serve = (routeFunction, options) => {
343
327
  const handler = defineEventHandler(async (event) => {
344
328
  const method = event.node.req.method;
345
329
  if (method?.toUpperCase() !== "POST") {
346
- return new Response("Only POST requests are allowed in worklfows", {
347
- status: 405
348
- });
330
+ return {
331
+ status: 405,
332
+ body: "Only POST requests are allowed in worklfows"
333
+ };
349
334
  }
350
- const url = getUrl(event);
351
- const headers = transformHeaders(event.node.req.headers);
335
+ const request_ = event.node.req;
336
+ const protocol = request_.headers["x-forwarded-proto"];
337
+ const host = request_.headers.host;
338
+ const url = `${protocol}://${host}${event.path}`;
339
+ const headers = transformHeaders(request_.headers);
352
340
  const request = new Request(url, {
353
341
  headers,
354
342
  body: await readRawBody(event),
355
343
  method: "POST"
356
344
  });
357
- const { handler: serveHandler } = serveBase(routeFunction, telemetry, options);
345
+ const { handler: serveHandler } = serveBase(
346
+ routeFunction,
347
+ {
348
+ sdk: SDK_TELEMETRY,
349
+ framework: "h3",
350
+ runtime: process.versions.bun ? `bun@${process.versions.bun}/node@${process.version}` : `node@${process.version}`
351
+ },
352
+ options
353
+ );
358
354
  return await serveHandler(request);
359
355
  });
360
356
  return { handler };
361
357
  };
362
- var createWorkflow = (...params) => {
363
- const { handler } = serve(...params);
364
- return {
365
- callback: createInvokeCallback(telemetry),
366
- handler,
367
- workflowId: void 0
368
- };
369
- };
370
- var serveMany = (workflows) => {
371
- return serveManyBase({
372
- workflows,
373
- getWorkflowId(event) {
374
- const url = getUrl(event);
375
- const components = url.split("/");
376
- return components[components.length - 1];
377
- }
378
- });
379
- };
380
358
  export {
381
- createWorkflow,
382
- serve,
383
- serveMany
359
+ serve
384
360
  };