@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/express.js CHANGED
@@ -23692,9 +23692,7 @@ var require_express2 = __commonJS({
23692
23692
  // platforms/express.ts
23693
23693
  var express_exports = {};
23694
23694
  __export(express_exports, {
23695
- createWorkflow: () => createWorkflow,
23696
- serve: () => serve,
23697
- serveMany: () => serveMany
23695
+ serve: () => serve
23698
23696
  });
23699
23697
  module.exports = __toCommonJS(express_exports);
23700
23698
 
@@ -23709,7 +23707,7 @@ var WORKFLOW_PROTOCOL_VERSION_HEADER = "Upstash-Workflow-Sdk-Version";
23709
23707
  var DEFAULT_CONTENT_TYPE = "application/json";
23710
23708
  var NO_CONCURRENCY = 1;
23711
23709
  var DEFAULT_RETRIES = 3;
23712
- var VERSION = "v0.2.7";
23710
+ var VERSION = "v0.2.3";
23713
23711
  var SDK_TELEMETRY = `@upstash/workflow@${VERSION}`;
23714
23712
  var TELEMETRY_HEADER_SDK = "Upstash-Telemetry-Sdk";
23715
23713
  var TELEMETRY_HEADER_FRAMEWORK = "Upstash-Telemetry-Framework";
@@ -23809,31 +23807,6 @@ var formatWorkflowError = (error) => {
23809
23807
  };
23810
23808
  };
23811
23809
 
23812
- // src/utils.ts
23813
- var NANOID_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
23814
- var NANOID_LENGTH = 21;
23815
- function getRandomInt() {
23816
- return Math.floor(Math.random() * NANOID_CHARS.length);
23817
- }
23818
- function nanoid() {
23819
- return Array.from({ length: NANOID_LENGTH }).map(() => NANOID_CHARS[getRandomInt()]).join("");
23820
- }
23821
- function getWorkflowRunId(id) {
23822
- return `wfr_${id ?? nanoid()}`;
23823
- }
23824
- function decodeBase64(base64) {
23825
- try {
23826
- const binString = atob(base64);
23827
- const intArray = Uint8Array.from(binString, (m) => m.codePointAt(0));
23828
- return new TextDecoder().decode(intArray);
23829
- } catch (error) {
23830
- console.warn(
23831
- `Upstash Qstash: Failed while decoding base64 "${base64}". Decoding with atob and returning it instead. ${error}`
23832
- );
23833
- return atob(base64);
23834
- }
23835
- }
23836
-
23837
23810
  // src/context/steps.ts
23838
23811
  var BaseLazyStep = class {
23839
23812
  stepName;
@@ -24014,41 +23987,6 @@ var LazyNotifyStep = class extends LazyFunctionStep {
24014
23987
  });
24015
23988
  }
24016
23989
  };
24017
- var LazyInvokeStep = class extends BaseLazyStep {
24018
- stepType = "Invoke";
24019
- params;
24020
- constructor(stepName, { workflow, body, headers = {}, workflowRunId, retries }) {
24021
- super(stepName);
24022
- this.params = {
24023
- workflow,
24024
- body,
24025
- headers,
24026
- workflowRunId: getWorkflowRunId(workflowRunId),
24027
- retries
24028
- };
24029
- }
24030
- getPlanStep(concurrent, targetStep) {
24031
- return {
24032
- stepId: 0,
24033
- stepName: this.stepName,
24034
- stepType: this.stepType,
24035
- concurrent,
24036
- targetStep
24037
- };
24038
- }
24039
- /**
24040
- * won't be used as it's the server who will add the result step
24041
- * in Invoke step.
24042
- */
24043
- getResultStep(concurrent, stepId) {
24044
- return Promise.resolve({
24045
- stepId,
24046
- stepName: this.stepName,
24047
- stepType: this.stepType,
24048
- concurrent
24049
- });
24050
- }
24051
- };
24052
23990
 
24053
23991
  // node_modules/neverthrow/dist/index.es.js
24054
23992
  var defaultErrorConfig = {
@@ -24473,8 +24411,7 @@ var StepTypes = [
24473
24411
  "SleepUntil",
24474
24412
  "Call",
24475
24413
  "Wait",
24476
- "Notify",
24477
- "Invoke"
24414
+ "Notify"
24478
24415
  ];
24479
24416
 
24480
24417
  // src/workflow-requests.ts
@@ -24482,7 +24419,7 @@ var import_qstash3 = require("@upstash/qstash");
24482
24419
  var triggerFirstInvocation = async ({
24483
24420
  workflowContext,
24484
24421
  useJSONContent,
24485
- telemetry: telemetry2,
24422
+ telemetry,
24486
24423
  debug
24487
24424
  }) => {
24488
24425
  const { headers } = getHeaders({
@@ -24492,7 +24429,7 @@ var triggerFirstInvocation = async ({
24492
24429
  userHeaders: workflowContext.headers,
24493
24430
  failureUrl: workflowContext.failureUrl,
24494
24431
  retries: workflowContext.retries,
24495
- telemetry: telemetry2
24432
+ telemetry
24496
24433
  });
24497
24434
  if (workflowContext.headers.get("content-type")) {
24498
24435
  headers["content-type"] = workflowContext.headers.get("content-type");
@@ -24538,8 +24475,8 @@ var triggerRouteFunction = async ({
24538
24475
  debug
24539
24476
  }) => {
24540
24477
  try {
24541
- const result = await onStep();
24542
- await onCleanup(result);
24478
+ await onStep();
24479
+ await onCleanup();
24543
24480
  return ok("workflow-finished");
24544
24481
  } catch (error) {
24545
24482
  const error_ = error;
@@ -24560,15 +24497,14 @@ var triggerRouteFunction = async ({
24560
24497
  }
24561
24498
  }
24562
24499
  };
24563
- var triggerWorkflowDelete = async (workflowContext, result, debug, cancel = false) => {
24500
+ var triggerWorkflowDelete = async (workflowContext, debug, cancel = false) => {
24564
24501
  await debug?.log("SUBMIT", "SUBMIT_CLEANUP", {
24565
24502
  deletedWorkflowRunId: workflowContext.workflowRunId
24566
24503
  });
24567
24504
  await workflowContext.qstashClient.http.request({
24568
24505
  path: ["v2", "workflows", "runs", `${workflowContext.workflowRunId}?cancel=${cancel}`],
24569
24506
  method: "DELETE",
24570
- parseResponseAsJson: false,
24571
- body: JSON.stringify(result)
24507
+ parseResponseAsJson: false
24572
24508
  });
24573
24509
  await debug?.log(
24574
24510
  "SUBMIT",
@@ -24597,7 +24533,7 @@ var handleThirdPartyCallResult = async ({
24597
24533
  workflowUrl,
24598
24534
  failureUrl,
24599
24535
  retries,
24600
- telemetry: telemetry2,
24536
+ telemetry,
24601
24537
  debug
24602
24538
  }) => {
24603
24539
  try {
@@ -24665,7 +24601,7 @@ ${atob(callbackMessage.body ?? "")}`
24665
24601
  userHeaders,
24666
24602
  failureUrl,
24667
24603
  retries,
24668
- telemetry: telemetry2
24604
+ telemetry
24669
24605
  });
24670
24606
  const callResponse = {
24671
24607
  status: callbackMessage.status,
@@ -24704,11 +24640,11 @@ ${atob(callbackMessage.body ?? "")}`
24704
24640
  );
24705
24641
  }
24706
24642
  };
24707
- var getTelemetryHeaders = (telemetry2) => {
24643
+ var getTelemetryHeaders = (telemetry) => {
24708
24644
  return {
24709
- [TELEMETRY_HEADER_SDK]: telemetry2.sdk,
24710
- [TELEMETRY_HEADER_FRAMEWORK]: telemetry2.framework,
24711
- [TELEMETRY_HEADER_RUNTIME]: telemetry2.runtime ?? "unknown"
24645
+ [TELEMETRY_HEADER_SDK]: telemetry.sdk,
24646
+ [TELEMETRY_HEADER_FRAMEWORK]: telemetry.framework,
24647
+ [TELEMETRY_HEADER_RUNTIME]: telemetry.runtime ?? "unknown"
24712
24648
  };
24713
24649
  };
24714
24650
  var getHeaders = ({
@@ -24721,17 +24657,14 @@ var getHeaders = ({
24721
24657
  step,
24722
24658
  callRetries,
24723
24659
  callTimeout,
24724
- telemetry: telemetry2
24660
+ telemetry
24725
24661
  }) => {
24726
- const contentType = (userHeaders ? userHeaders.get("Content-Type") : void 0) ?? DEFAULT_CONTENT_TYPE;
24727
24662
  const baseHeaders = {
24728
24663
  [WORKFLOW_INIT_HEADER]: initHeaderValue,
24729
24664
  [WORKFLOW_ID_HEADER]: workflowRunId,
24730
24665
  [WORKFLOW_URL_HEADER]: workflowUrl,
24731
24666
  [WORKFLOW_FEATURE_HEADER]: "LazyFetch,InitialBody",
24732
- [WORKFLOW_PROTOCOL_VERSION_HEADER]: WORKFLOW_PROTOCOL_VERSION,
24733
- "content-type": contentType,
24734
- ...telemetry2 ? getTelemetryHeaders(telemetry2) : {}
24667
+ ...telemetry ? getTelemetryHeaders(telemetry) : {}
24735
24668
  };
24736
24669
  if (!step?.callUrl) {
24737
24670
  baseHeaders[`Upstash-Forward-${WORKFLOW_PROTOCOL_VERSION_HEADER}`] = WORKFLOW_PROTOCOL_VERSION;
@@ -24741,13 +24674,18 @@ var getHeaders = ({
24741
24674
  }
24742
24675
  if (failureUrl) {
24743
24676
  baseHeaders[`Upstash-Failure-Callback-Forward-${WORKFLOW_FAILURE_HEADER}`] = "true";
24677
+ baseHeaders[`Upstash-Failure-Callback-Forward-Upstash-Workflow-Failure-Callback`] = "true";
24678
+ baseHeaders["Upstash-Failure-Callback-Workflow-Runid"] = workflowRunId;
24679
+ baseHeaders["Upstash-Failure-Callback-Workflow-Init"] = "false";
24680
+ baseHeaders["Upstash-Failure-Callback-Workflow-Url"] = workflowUrl;
24681
+ baseHeaders["Upstash-Failure-Callback-Workflow-Calltype"] = "failureCall";
24682
+ if (retries !== void 0) {
24683
+ baseHeaders["Upstash-Failure-Callback-Retries"] = retries.toString();
24684
+ }
24744
24685
  if (!step?.callUrl) {
24745
24686
  baseHeaders["Upstash-Failure-Callback"] = failureUrl;
24746
24687
  }
24747
24688
  }
24748
- if (step?.stepType === "Invoke") {
24749
- baseHeaders["upstash-workflow-invoke"] = "true";
24750
- }
24751
24689
  if (step?.callUrl) {
24752
24690
  baseHeaders["Upstash-Retries"] = callRetries?.toString() ?? "0";
24753
24691
  baseHeaders[WORKFLOW_FEATURE_HEADER] = "WF_NoDelete,InitialBody";
@@ -24769,6 +24707,7 @@ var getHeaders = ({
24769
24707
  baseHeaders[`Upstash-Failure-Callback-Forward-${header}`] = userHeaders.get(header);
24770
24708
  }
24771
24709
  }
24710
+ const contentType = (userHeaders ? userHeaders.get("Content-Type") : void 0) ?? DEFAULT_CONTENT_TYPE;
24772
24711
  if (step?.callHeaders) {
24773
24712
  const forwardedHeaders = Object.fromEntries(
24774
24713
  Object.entries(step.callHeaders).map(([header, value]) => [
@@ -24808,8 +24747,8 @@ var getHeaders = ({
24808
24747
  Object.entries(baseHeaders).map(([header, value]) => [header, [value]])
24809
24748
  ),
24810
24749
  // to include telemetry headers:
24811
- ...telemetry2 ? Object.fromEntries(
24812
- Object.entries(getTelemetryHeaders(telemetry2)).map(([header, value]) => [
24750
+ ...telemetry ? Object.fromEntries(
24751
+ Object.entries(getTelemetryHeaders(telemetry)).map(([header, value]) => [
24813
24752
  header,
24814
24753
  [value]
24815
24754
  ])
@@ -24818,7 +24757,8 @@ var getHeaders = ({
24818
24757
  "Upstash-Workflow-Runid": [workflowRunId],
24819
24758
  [WORKFLOW_INIT_HEADER]: ["false"],
24820
24759
  [WORKFLOW_URL_HEADER]: [workflowUrl],
24821
- "Upstash-Workflow-CallType": ["step"]
24760
+ "Upstash-Workflow-CallType": ["step"],
24761
+ "Content-Type": [contentType]
24822
24762
  }
24823
24763
  };
24824
24764
  }
@@ -24864,10 +24804,10 @@ var AutoExecutor = class _AutoExecutor {
24864
24804
  stepCount = 0;
24865
24805
  planStepCount = 0;
24866
24806
  executingStep = false;
24867
- constructor(context, steps, telemetry2, debug) {
24807
+ constructor(context, steps, telemetry, debug) {
24868
24808
  this.context = context;
24869
24809
  this.steps = steps;
24870
- this.telemetry = telemetry2;
24810
+ this.telemetry = telemetry;
24871
24811
  this.debug = debug;
24872
24812
  this.nonPlanStepCount = this.steps.filter((step) => !step.targetStep).length;
24873
24813
  }
@@ -25113,23 +25053,7 @@ var AutoExecutor = class _AutoExecutor {
25113
25053
  method: "POST",
25114
25054
  parseResponseAsJson: false
25115
25055
  });
25116
- throw new WorkflowAbort(waitStep.stepName, waitStep);
25117
- }
25118
- if (steps.length === 1 && lazySteps[0] instanceof LazyInvokeStep) {
25119
- const invokeStep = steps[0];
25120
- const lazyInvokeStep = lazySteps[0];
25121
- await lazyInvokeStep.params.workflow.callback(
25122
- {
25123
- body: lazyInvokeStep.params.body,
25124
- headers: lazyInvokeStep.params.headers,
25125
- workflowRunId: lazyInvokeStep.params.workflowRunId,
25126
- workflow: lazyInvokeStep.params.workflow,
25127
- retries: lazyInvokeStep.params.retries
25128
- },
25129
- invokeStep,
25130
- this.context
25131
- );
25132
- throw new WorkflowAbort(invokeStep.stepName, invokeStep);
25056
+ throw new WorkflowAbort(steps[0].stepName, steps[0]);
25133
25057
  }
25134
25058
  const result = await this.context.qstashClient.batchJSON(
25135
25059
  steps.map((singleStep, index) => {
@@ -25448,9 +25372,10 @@ var wrapTools = ({
25448
25372
  return Object.fromEntries(
25449
25373
  Object.entries(tools).map((toolInfo) => {
25450
25374
  const [toolName, tool3] = toolInfo;
25375
+ const executeAsStep = "executeAsStep" in tool3 ? tool3.executeAsStep : true;
25451
25376
  const aiSDKTool = convertToAISDKTool(tool3);
25452
25377
  const execute = aiSDKTool.execute;
25453
- if (execute) {
25378
+ if (execute && executeAsStep) {
25454
25379
  const wrappedExecute = (...params) => {
25455
25380
  return context.run(`Run tool ${toolName}`, () => execute(...params));
25456
25381
  };
@@ -25815,7 +25740,7 @@ var WorkflowContext = class {
25815
25740
  initialPayload,
25816
25741
  env,
25817
25742
  retries,
25818
- telemetry: telemetry2
25743
+ telemetry
25819
25744
  }) {
25820
25745
  this.qstashClient = qstashClient;
25821
25746
  this.workflowRunId = workflowRunId;
@@ -25826,7 +25751,7 @@ var WorkflowContext = class {
25826
25751
  this.requestPayload = initialPayload;
25827
25752
  this.env = env ?? {};
25828
25753
  this.retries = retries ?? DEFAULT_RETRIES;
25829
- this.executor = new AutoExecutor(this, this.steps, telemetry2, debug);
25754
+ this.executor = new AutoExecutor(this, this.steps, telemetry, debug);
25830
25755
  }
25831
25756
  /**
25832
25757
  * Executes a workflow step
@@ -26046,13 +25971,6 @@ var WorkflowContext = class {
26046
25971
  return result;
26047
25972
  }
26048
25973
  }
26049
- async invoke(stepName, settings) {
26050
- const result = await this.addStep(new LazyInvokeStep(stepName, settings));
26051
- return {
26052
- ...result,
26053
- body: result.body ? JSON.parse(result.body) : void 0
26054
- };
26055
- }
26056
25974
  /**
26057
25975
  * Cancel the current workflow run
26058
25976
  *
@@ -26130,6 +26048,31 @@ var WorkflowLogger = class _WorkflowLogger {
26130
26048
  }
26131
26049
  };
26132
26050
 
26051
+ // src/utils.ts
26052
+ var NANOID_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
26053
+ var NANOID_LENGTH = 21;
26054
+ function getRandomInt() {
26055
+ return Math.floor(Math.random() * NANOID_CHARS.length);
26056
+ }
26057
+ function nanoid() {
26058
+ return Array.from({ length: NANOID_LENGTH }).map(() => NANOID_CHARS[getRandomInt()]).join("");
26059
+ }
26060
+ function getWorkflowRunId(id) {
26061
+ return `wfr_${id ?? nanoid()}`;
26062
+ }
26063
+ function decodeBase64(base64) {
26064
+ try {
26065
+ const binString = atob(base64);
26066
+ const intArray = Uint8Array.from(binString, (m) => m.codePointAt(0));
26067
+ return new TextDecoder().decode(intArray);
26068
+ } catch (error) {
26069
+ console.warn(
26070
+ `Upstash Qstash: Failed while decoding base64 "${base64}". Decoding with atob and returning it instead. ${error}`
26071
+ );
26072
+ return atob(base64);
26073
+ }
26074
+ }
26075
+
26133
26076
  // src/serve/authorization.ts
26134
26077
  var import_qstash8 = require("@upstash/qstash");
26135
26078
  var DisabledWorkflowContext = class _DisabledWorkflowContext extends WorkflowContext {
@@ -26467,7 +26410,7 @@ var determineUrls = async (request, url, baseUrl, failureFunction, failureUrl, d
26467
26410
  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`;
26468
26411
 
26469
26412
  // src/serve/index.ts
26470
- var serveBase = (routeFunction, telemetry2, options) => {
26413
+ var serveBase = (routeFunction, telemetry, options) => {
26471
26414
  const {
26472
26415
  qstashClient,
26473
26416
  onStepFinish,
@@ -26483,7 +26426,7 @@ var serveBase = (routeFunction, telemetry2, options) => {
26483
26426
  useJSONContent,
26484
26427
  disableTelemetry
26485
26428
  } = processOptions(options);
26486
- telemetry2 = disableTelemetry ? void 0 : telemetry2;
26429
+ telemetry = disableTelemetry ? void 0 : telemetry;
26487
26430
  const debug = WorkflowLogger.getLogger(verbose);
26488
26431
  const handler = async (request) => {
26489
26432
  await debug?.log("INFO", "ENDPOINT_START");
@@ -26541,7 +26484,7 @@ var serveBase = (routeFunction, telemetry2, options) => {
26541
26484
  debug,
26542
26485
  env,
26543
26486
  retries,
26544
- telemetry: telemetry2
26487
+ telemetry
26545
26488
  });
26546
26489
  const authCheck = await DisabledWorkflowContext.tryAuthentication(
26547
26490
  routeFunction,
@@ -26564,7 +26507,7 @@ var serveBase = (routeFunction, telemetry2, options) => {
26564
26507
  workflowUrl,
26565
26508
  failureUrl: workflowFailureUrl,
26566
26509
  retries,
26567
- telemetry: telemetry2,
26510
+ telemetry,
26568
26511
  debug
26569
26512
  });
26570
26513
  if (callReturnCheck.isErr()) {
@@ -26573,10 +26516,10 @@ var serveBase = (routeFunction, telemetry2, options) => {
26573
26516
  });
26574
26517
  throw callReturnCheck.error;
26575
26518
  } else if (callReturnCheck.value === "continue-workflow") {
26576
- const result = isFirstInvocation ? await triggerFirstInvocation({ workflowContext, useJSONContent, telemetry: telemetry2, debug }) : await triggerRouteFunction({
26519
+ const result = isFirstInvocation ? await triggerFirstInvocation({ workflowContext, useJSONContent, telemetry, debug }) : await triggerRouteFunction({
26577
26520
  onStep: async () => routeFunction(workflowContext),
26578
- onCleanup: async (result2) => {
26579
- await triggerWorkflowDelete(workflowContext, result2, debug);
26521
+ onCleanup: async () => {
26522
+ await triggerWorkflowDelete(workflowContext, debug);
26580
26523
  },
26581
26524
  onCancel: async () => {
26582
26525
  await makeCancelRequest(workflowContext.qstashClient.http, workflowRunId);
@@ -26610,104 +26553,12 @@ var serveBase = (routeFunction, telemetry2, options) => {
26610
26553
 
26611
26554
  // platforms/express.ts
26612
26555
  var import_express = __toESM(require_express2());
26613
-
26614
- // src/serve/serve-many.ts
26615
- var serveManyBase = ({
26616
- workflows,
26617
- getWorkflowId
26618
- }) => {
26619
- const workflowIds = [];
26620
- const workflowMap = Object.fromEntries(
26621
- Object.entries(workflows).map((workflow) => {
26622
- const workflowId = workflow[0];
26623
- if (workflowIds.includes(workflowId)) {
26624
- throw new WorkflowError(
26625
- `Duplicate workflow name found: '${workflowId}'. Please set different workflow names in serveMany.`
26626
- );
26627
- }
26628
- if (workflowId.includes("/")) {
26629
- throw new WorkflowError(
26630
- `Invalid workflow name found: '${workflowId}'. Workflow name cannot contain '/'.`
26631
- );
26632
- }
26633
- workflowIds.push(workflowId);
26634
- workflow[1].workflowId = workflowId;
26635
- return [workflowId, workflow[1].handler];
26636
- })
26637
- );
26638
- return {
26639
- handler: async (...params) => {
26640
- const pickedWorkflowId = getWorkflowId(...params);
26641
- if (!pickedWorkflowId) {
26642
- throw new WorkflowError(`Unexpected request in serveMany. workflowId not set. Please update the URL of your request.`);
26643
- }
26644
- const workflow = workflowMap[pickedWorkflowId];
26645
- if (!workflow) {
26646
- throw new WorkflowError(`No workflows in serveMany found for '${pickedWorkflowId}'. Please update the URL of your request.`);
26647
- }
26648
- return await workflow(...params);
26649
- }
26650
- };
26651
- };
26652
- var createInvokeCallback = (telemetry2) => {
26653
- const invokeCallback = async (settings, invokeStep, context) => {
26654
- const { body, workflow, headers = {}, workflowRunId = getWorkflowRunId(), retries } = settings;
26655
- const { workflowId } = workflow;
26656
- if (!workflowId) {
26657
- throw new WorkflowError("You can only invoke workflow which has a workflowId");
26658
- }
26659
- const { headers: invokerHeaders } = getHeaders({
26660
- initHeaderValue: "false",
26661
- workflowRunId: context.workflowRunId,
26662
- workflowUrl: context.url,
26663
- userHeaders: context.headers,
26664
- failureUrl: context.failureUrl,
26665
- retries: context.retries,
26666
- telemetry: telemetry2
26667
- });
26668
- invokerHeaders["Upstash-Workflow-Runid"] = context.workflowRunId;
26669
- const newUrl = context.url.replace(/[^/]+$/, workflowId);
26670
- const { headers: triggerHeaders } = getHeaders({
26671
- initHeaderValue: "true",
26672
- workflowRunId,
26673
- workflowUrl: newUrl,
26674
- userHeaders: new Headers(headers),
26675
- retries,
26676
- telemetry: telemetry2
26677
- });
26678
- triggerHeaders["Upstash-Workflow-Invoke"] = "true";
26679
- const request = {
26680
- body: JSON.stringify(body),
26681
- headers: Object.fromEntries(
26682
- Object.entries(invokerHeaders).map((pairs) => [pairs[0], [pairs[1]]])
26683
- ),
26684
- workflowRunId,
26685
- workflowUrl: context.url,
26686
- step: invokeStep
26687
- };
26688
- await context.qstashClient.publish({
26689
- headers: triggerHeaders,
26690
- method: "POST",
26691
- body: JSON.stringify(request),
26692
- url: newUrl
26693
- });
26694
- return void 0;
26695
- };
26696
- return invokeCallback;
26697
- };
26698
-
26699
- // platforms/express.ts
26700
26556
  var isEmptyRequest = (req) => {
26701
26557
  return req.headers["content-type"] === "application/json" && req.headers["content-length"] === "0";
26702
26558
  };
26703
- var telemetry = {
26704
- sdk: SDK_TELEMETRY,
26705
- framework: "express",
26706
- runtime: process.versions.bun ? `bun@${process.versions.bun}/node@${process.version}` : `node@${process.version}`
26707
- };
26708
- function createExpressHandler(params) {
26709
- const [routeFunction, options] = params;
26710
- return async (request_, res) => {
26559
+ function serve(routeFunction, options) {
26560
+ const router = (0, import_express.Router)();
26561
+ const handler = async (request_, res) => {
26711
26562
  if (request_.method.toUpperCase() !== "POST") {
26712
26563
  res.status(405).json("Only POST requests are allowed in workflows");
26713
26564
  return;
@@ -26732,7 +26583,11 @@ function createExpressHandler(params) {
26732
26583
  });
26733
26584
  const { handler: serveHandler } = serveBase(
26734
26585
  routeFunction,
26735
- telemetry,
26586
+ {
26587
+ sdk: SDK_TELEMETRY,
26588
+ framework: "express",
26589
+ runtime: process.versions.bun ? `bun@${process.versions.bun}/node@${process.version}` : `node@${process.version}`
26590
+ },
26736
26591
  {
26737
26592
  ...options,
26738
26593
  useJSONContent: true
@@ -26741,38 +26596,12 @@ function createExpressHandler(params) {
26741
26596
  const response = await serveHandler(webRequest);
26742
26597
  res.status(response.status).json(await response.json());
26743
26598
  };
26744
- }
26745
- function serve(routeFunction, options) {
26746
- const router = (0, import_express.Router)();
26747
- const handler = createExpressHandler([routeFunction, options]);
26748
26599
  router.all("*", handler);
26749
26600
  return router;
26750
26601
  }
26751
- var createWorkflow = (...params) => {
26752
- const handler = createExpressHandler(params);
26753
- return {
26754
- callback: createInvokeCallback(telemetry),
26755
- handler,
26756
- workflowId: void 0
26757
- };
26758
- };
26759
- var serveMany = (workflows) => {
26760
- const router = (0, import_express.Router)();
26761
- const { handler } = serveManyBase({
26762
- workflows,
26763
- getWorkflowId(...params) {
26764
- const components = params[0].url.split("/");
26765
- return components[components.length - 1];
26766
- }
26767
- });
26768
- router.all("*", handler);
26769
- return router;
26770
- };
26771
26602
  // Annotate the CommonJS export names for ESM import in node:
26772
26603
  0 && (module.exports = {
26773
- createWorkflow,
26774
- serve,
26775
- serveMany
26604
+ serve
26776
26605
  });
26777
26606
  /*! Bundled license information:
26778
26607
 
package/express.mjs CHANGED
@@ -1,14 +1,10 @@
1
- import {
2
- createInvokeCallback,
3
- serveManyBase
4
- } from "./chunk-LCZMBGEM.mjs";
5
1
  import {
6
2
  SDK_TELEMETRY,
7
3
  __commonJS,
8
4
  __require,
9
5
  __toESM,
10
6
  serveBase
11
- } from "./chunk-IWAW7GIG.mjs";
7
+ } from "./chunk-BPUSHNSD.mjs";
12
8
 
13
9
  // node_modules/depd/index.js
14
10
  var require_depd = __commonJS({
@@ -23674,14 +23670,9 @@ var import_express = __toESM(require_express2());
23674
23670
  var isEmptyRequest = (req) => {
23675
23671
  return req.headers["content-type"] === "application/json" && req.headers["content-length"] === "0";
23676
23672
  };
23677
- var telemetry = {
23678
- sdk: SDK_TELEMETRY,
23679
- framework: "express",
23680
- runtime: process.versions.bun ? `bun@${process.versions.bun}/node@${process.version}` : `node@${process.version}`
23681
- };
23682
- function createExpressHandler(params) {
23683
- const [routeFunction, options] = params;
23684
- return async (request_, res) => {
23673
+ function serve(routeFunction, options) {
23674
+ const router = (0, import_express.Router)();
23675
+ const handler = async (request_, res) => {
23685
23676
  if (request_.method.toUpperCase() !== "POST") {
23686
23677
  res.status(405).json("Only POST requests are allowed in workflows");
23687
23678
  return;
@@ -23706,7 +23697,11 @@ function createExpressHandler(params) {
23706
23697
  });
23707
23698
  const { handler: serveHandler } = serveBase(
23708
23699
  routeFunction,
23709
- telemetry,
23700
+ {
23701
+ sdk: SDK_TELEMETRY,
23702
+ framework: "express",
23703
+ runtime: process.versions.bun ? `bun@${process.versions.bun}/node@${process.version}` : `node@${process.version}`
23704
+ },
23710
23705
  {
23711
23706
  ...options,
23712
23707
  useJSONContent: true
@@ -23715,37 +23710,11 @@ function createExpressHandler(params) {
23715
23710
  const response = await serveHandler(webRequest);
23716
23711
  res.status(response.status).json(await response.json());
23717
23712
  };
23718
- }
23719
- function serve(routeFunction, options) {
23720
- const router = (0, import_express.Router)();
23721
- const handler = createExpressHandler([routeFunction, options]);
23722
23713
  router.all("*", handler);
23723
23714
  return router;
23724
23715
  }
23725
- var createWorkflow = (...params) => {
23726
- const handler = createExpressHandler(params);
23727
- return {
23728
- callback: createInvokeCallback(telemetry),
23729
- handler,
23730
- workflowId: void 0
23731
- };
23732
- };
23733
- var serveMany = (workflows) => {
23734
- const router = (0, import_express.Router)();
23735
- const { handler } = serveManyBase({
23736
- workflows,
23737
- getWorkflowId(...params) {
23738
- const components = params[0].url.split("/");
23739
- return components[components.length - 1];
23740
- }
23741
- });
23742
- router.all("*", handler);
23743
- return router;
23744
- };
23745
23716
  export {
23746
- createWorkflow,
23747
- serve,
23748
- serveMany
23717
+ serve
23749
23718
  };
23750
23719
  /*! Bundled license information:
23751
23720
 
package/h3.d.mts 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.mjs';
3
- import { s as serveManyBase } from './serve-many-BlBvXfBS.mjs';
2
+ import { R as RouteFunction, k as PublicServeOptions } from './types-B62AnIU3.mjs';
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 };