@upstash/workflow 0.2.6-canary.0 → 0.2.7

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/astro.d.mts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { APIContext, APIRoute } from 'astro';
2
- import { b as WorkflowContext, j as PublicServeOptions } from './types-DKLbLp0d.mjs';
2
+ import { b as WorkflowContext, j as PublicServeOptions } from './types-Cuqlx2Cr.mjs';
3
3
  import '@upstash/qstash';
4
+ import 'zod';
4
5
  import 'ai';
5
6
  import '@ai-sdk/openai';
6
7
 
package/astro.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { APIContext, APIRoute } from 'astro';
2
- import { b as WorkflowContext, j as PublicServeOptions } from './types-DKLbLp0d.js';
2
+ import { b as WorkflowContext, j as PublicServeOptions } from './types-Cuqlx2Cr.js';
3
3
  import '@upstash/qstash';
4
+ import 'zod';
4
5
  import 'ai';
5
6
  import '@ai-sdk/openai';
6
7
 
package/astro.js CHANGED
@@ -759,6 +759,9 @@ var triggerFirstInvocation = async ({
759
759
  retries: workflowContext.retries,
760
760
  telemetry
761
761
  });
762
+ if (workflowContext.headers.get("content-type")) {
763
+ headers["content-type"] = workflowContext.headers.get("content-type");
764
+ }
762
765
  if (useJSONContent) {
763
766
  headers["content-type"] = "application/json";
764
767
  }
@@ -1640,9 +1643,11 @@ you need from that agent.
1640
1643
  `;
1641
1644
 
1642
1645
  // src/agents/adapters.ts
1643
- var createWorkflowOpenAI = (context, baseURL) => {
1646
+ var createWorkflowOpenAI = (context, config) => {
1647
+ const { baseURL, apiKey } = config ?? {};
1644
1648
  return (0, import_openai2.createOpenAI)({
1645
1649
  baseURL,
1650
+ apiKey,
1646
1651
  compatibility: "strict",
1647
1652
  fetch: async (input, init) => {
1648
1653
  try {
@@ -1915,8 +1920,8 @@ var WorkflowAgents = class {
1915
1920
  */
1916
1921
  openai(...params) {
1917
1922
  const [model, settings] = params;
1918
- const { baseURL, ...otherSettings } = settings ?? {};
1919
- const openai2 = createWorkflowOpenAI(this.context, baseURL);
1923
+ const { baseURL, apiKey, ...otherSettings } = settings ?? {};
1924
+ const openai2 = createWorkflowOpenAI(this.context, { baseURL, apiKey });
1920
1925
  return openai2(model, otherSettings);
1921
1926
  }
1922
1927
  };
@@ -2672,7 +2677,8 @@ var processOptions = (options) => {
2672
2677
  return void 0;
2673
2678
  }
2674
2679
  try {
2675
- return JSON.parse(initialRequest);
2680
+ const parsed = JSON.parse(initialRequest);
2681
+ return options?.schema ? options.schema.parse(parsed) : parsed;
2676
2682
  } catch (error) {
2677
2683
  if (error instanceof SyntaxError) {
2678
2684
  return initialRequest;
package/astro.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  SDK_TELEMETRY,
3
3
  serveBase
4
- } from "./chunk-XGCTFI4M.mjs";
4
+ } from "./chunk-U6XFLG7W.mjs";
5
5
 
6
6
  // platforms/astro.ts
7
7
  function serve(routeFunction, options) {
@@ -772,6 +772,9 @@ var triggerFirstInvocation = async ({
772
772
  retries: workflowContext.retries,
773
773
  telemetry
774
774
  });
775
+ if (workflowContext.headers.get("content-type")) {
776
+ headers["content-type"] = workflowContext.headers.get("content-type");
777
+ }
775
778
  if (useJSONContent) {
776
779
  headers["content-type"] = "application/json";
777
780
  }
@@ -1653,9 +1656,11 @@ you need from that agent.
1653
1656
  `;
1654
1657
 
1655
1658
  // src/agents/adapters.ts
1656
- var createWorkflowOpenAI = (context, baseURL) => {
1659
+ var createWorkflowOpenAI = (context, config) => {
1660
+ const { baseURL, apiKey } = config ?? {};
1657
1661
  return createOpenAI({
1658
1662
  baseURL,
1663
+ apiKey,
1659
1664
  compatibility: "strict",
1660
1665
  fetch: async (input, init) => {
1661
1666
  try {
@@ -1928,8 +1933,8 @@ var WorkflowAgents = class {
1928
1933
  */
1929
1934
  openai(...params) {
1930
1935
  const [model, settings] = params;
1931
- const { baseURL, ...otherSettings } = settings ?? {};
1932
- const openai2 = createWorkflowOpenAI(this.context, baseURL);
1936
+ const { baseURL, apiKey, ...otherSettings } = settings ?? {};
1937
+ const openai2 = createWorkflowOpenAI(this.context, { baseURL, apiKey });
1933
1938
  return openai2(model, otherSettings);
1934
1939
  }
1935
1940
  };
@@ -2685,7 +2690,8 @@ var processOptions = (options) => {
2685
2690
  return void 0;
2686
2691
  }
2687
2692
  try {
2688
- return JSON.parse(initialRequest);
2693
+ const parsed = JSON.parse(initialRequest);
2694
+ return options?.schema ? options.schema.parse(parsed) : parsed;
2689
2695
  } catch (error) {
2690
2696
  if (error instanceof SyntaxError) {
2691
2697
  return initialRequest;
package/cloudflare.d.mts CHANGED
@@ -1,5 +1,6 @@
1
- import { R as RouteFunction, j as PublicServeOptions } from './types-DKLbLp0d.mjs';
1
+ import { R as RouteFunction, j as PublicServeOptions } from './types-Cuqlx2Cr.mjs';
2
2
  import '@upstash/qstash';
3
+ import 'zod';
3
4
  import 'ai';
4
5
  import '@ai-sdk/openai';
5
6
 
package/cloudflare.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { R as RouteFunction, j as PublicServeOptions } from './types-DKLbLp0d.js';
1
+ import { R as RouteFunction, j as PublicServeOptions } from './types-Cuqlx2Cr.js';
2
2
  import '@upstash/qstash';
3
+ import 'zod';
3
4
  import 'ai';
4
5
  import '@ai-sdk/openai';
5
6
 
package/cloudflare.js CHANGED
@@ -759,6 +759,9 @@ var triggerFirstInvocation = async ({
759
759
  retries: workflowContext.retries,
760
760
  telemetry
761
761
  });
762
+ if (workflowContext.headers.get("content-type")) {
763
+ headers["content-type"] = workflowContext.headers.get("content-type");
764
+ }
762
765
  if (useJSONContent) {
763
766
  headers["content-type"] = "application/json";
764
767
  }
@@ -1640,9 +1643,11 @@ you need from that agent.
1640
1643
  `;
1641
1644
 
1642
1645
  // src/agents/adapters.ts
1643
- var createWorkflowOpenAI = (context, baseURL) => {
1646
+ var createWorkflowOpenAI = (context, config) => {
1647
+ const { baseURL, apiKey } = config ?? {};
1644
1648
  return (0, import_openai2.createOpenAI)({
1645
1649
  baseURL,
1650
+ apiKey,
1646
1651
  compatibility: "strict",
1647
1652
  fetch: async (input, init) => {
1648
1653
  try {
@@ -1915,8 +1920,8 @@ var WorkflowAgents = class {
1915
1920
  */
1916
1921
  openai(...params) {
1917
1922
  const [model, settings] = params;
1918
- const { baseURL, ...otherSettings } = settings ?? {};
1919
- const openai2 = createWorkflowOpenAI(this.context, baseURL);
1923
+ const { baseURL, apiKey, ...otherSettings } = settings ?? {};
1924
+ const openai2 = createWorkflowOpenAI(this.context, { baseURL, apiKey });
1920
1925
  return openai2(model, otherSettings);
1921
1926
  }
1922
1927
  };
@@ -2672,7 +2677,8 @@ var processOptions = (options) => {
2672
2677
  return void 0;
2673
2678
  }
2674
2679
  try {
2675
- return JSON.parse(initialRequest);
2680
+ const parsed = JSON.parse(initialRequest);
2681
+ return options?.schema ? options.schema.parse(parsed) : parsed;
2676
2682
  } catch (error) {
2677
2683
  if (error instanceof SyntaxError) {
2678
2684
  return initialRequest;
package/cloudflare.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  SDK_TELEMETRY,
3
3
  serveBase
4
- } from "./chunk-XGCTFI4M.mjs";
4
+ } from "./chunk-U6XFLG7W.mjs";
5
5
 
6
6
  // platforms/cloudflare.ts
7
7
  var getArgs = (args) => {
package/express.d.mts CHANGED
@@ -1,6 +1,7 @@
1
- import { R as RouteFunction, W as WorkflowServeOptions } from './types-DKLbLp0d.mjs';
1
+ import { R as RouteFunction, W as WorkflowServeOptions } from './types-Cuqlx2Cr.mjs';
2
2
  import { Router } from 'express';
3
3
  import '@upstash/qstash';
4
+ import 'zod';
4
5
  import 'ai';
5
6
  import '@ai-sdk/openai';
6
7
 
package/express.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import { R as RouteFunction, W as WorkflowServeOptions } from './types-DKLbLp0d.js';
1
+ import { R as RouteFunction, W as WorkflowServeOptions } from './types-Cuqlx2Cr.js';
2
2
  import { Router } from 'express';
3
3
  import '@upstash/qstash';
4
+ import 'zod';
4
5
  import 'ai';
5
6
  import '@ai-sdk/openai';
6
7
 
package/express.js CHANGED
@@ -24431,6 +24431,9 @@ var triggerFirstInvocation = async ({
24431
24431
  retries: workflowContext.retries,
24432
24432
  telemetry
24433
24433
  });
24434
+ if (workflowContext.headers.get("content-type")) {
24435
+ headers["content-type"] = workflowContext.headers.get("content-type");
24436
+ }
24434
24437
  if (useJSONContent) {
24435
24438
  headers["content-type"] = "application/json";
24436
24439
  }
@@ -25312,9 +25315,11 @@ you need from that agent.
25312
25315
  `;
25313
25316
 
25314
25317
  // src/agents/adapters.ts
25315
- var createWorkflowOpenAI = (context, baseURL) => {
25318
+ var createWorkflowOpenAI = (context, config) => {
25319
+ const { baseURL, apiKey } = config ?? {};
25316
25320
  return (0, import_openai2.createOpenAI)({
25317
25321
  baseURL,
25322
+ apiKey,
25318
25323
  compatibility: "strict",
25319
25324
  fetch: async (input, init) => {
25320
25325
  try {
@@ -25587,8 +25592,8 @@ var WorkflowAgents = class {
25587
25592
  */
25588
25593
  openai(...params) {
25589
25594
  const [model, settings] = params;
25590
- const { baseURL, ...otherSettings } = settings ?? {};
25591
- const openai2 = createWorkflowOpenAI(this.context, baseURL);
25595
+ const { baseURL, apiKey, ...otherSettings } = settings ?? {};
25596
+ const openai2 = createWorkflowOpenAI(this.context, { baseURL, apiKey });
25592
25597
  return openai2(model, otherSettings);
25593
25598
  }
25594
25599
  };
@@ -26344,7 +26349,8 @@ var processOptions = (options) => {
26344
26349
  return void 0;
26345
26350
  }
26346
26351
  try {
26347
- return JSON.parse(initialRequest);
26352
+ const parsed = JSON.parse(initialRequest);
26353
+ return options?.schema ? options.schema.parse(parsed) : parsed;
26348
26354
  } catch (error) {
26349
26355
  if (error instanceof SyntaxError) {
26350
26356
  return initialRequest;
@@ -26538,6 +26544,9 @@ var serveBase = (routeFunction, telemetry, options) => {
26538
26544
 
26539
26545
  // platforms/express.ts
26540
26546
  var import_express = __toESM(require_express2());
26547
+ var isEmptyRequest = (req) => {
26548
+ return req.headers["content-type"] === "application/json" && req.headers["content-length"] === "0";
26549
+ };
26541
26550
  function serve(routeFunction, options) {
26542
26551
  const router = (0, import_express.Router)();
26543
26552
  const handler = async (request_, res) => {
@@ -26546,7 +26555,9 @@ function serve(routeFunction, options) {
26546
26555
  return;
26547
26556
  }
26548
26557
  let requestBody;
26549
- if (request_.headers["content-type"]?.includes("text/plain")) {
26558
+ if (isEmptyRequest(request_)) {
26559
+ requestBody = "";
26560
+ } else if (request_.headers["content-type"]?.includes("text/plain")) {
26550
26561
  requestBody = request_.body;
26551
26562
  } else if (request_.headers["content-type"]?.includes("application/json")) {
26552
26563
  requestBody = JSON.stringify(request_.body);
package/express.mjs CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  __require,
5
5
  __toESM,
6
6
  serveBase
7
- } from "./chunk-XGCTFI4M.mjs";
7
+ } from "./chunk-U6XFLG7W.mjs";
8
8
 
9
9
  // node_modules/depd/index.js
10
10
  var require_depd = __commonJS({
@@ -23667,6 +23667,9 @@ var require_express2 = __commonJS({
23667
23667
 
23668
23668
  // platforms/express.ts
23669
23669
  var import_express = __toESM(require_express2());
23670
+ var isEmptyRequest = (req) => {
23671
+ return req.headers["content-type"] === "application/json" && req.headers["content-length"] === "0";
23672
+ };
23670
23673
  function serve(routeFunction, options) {
23671
23674
  const router = (0, import_express.Router)();
23672
23675
  const handler = async (request_, res) => {
@@ -23675,7 +23678,9 @@ function serve(routeFunction, options) {
23675
23678
  return;
23676
23679
  }
23677
23680
  let requestBody;
23678
- if (request_.headers["content-type"]?.includes("text/plain")) {
23681
+ if (isEmptyRequest(request_)) {
23682
+ requestBody = "";
23683
+ } else if (request_.headers["content-type"]?.includes("text/plain")) {
23679
23684
  requestBody = request_.body;
23680
23685
  } else if (request_.headers["content-type"]?.includes("application/json")) {
23681
23686
  requestBody = JSON.stringify(request_.body);
package/h3.d.mts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as h3 from 'h3';
2
- import { R as RouteFunction, j as PublicServeOptions } from './types-DKLbLp0d.mjs';
2
+ import { R as RouteFunction, j as PublicServeOptions } from './types-Cuqlx2Cr.mjs';
3
3
  import '@upstash/qstash';
4
+ import 'zod';
4
5
  import 'ai';
5
6
  import '@ai-sdk/openai';
6
7
 
package/h3.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as h3 from 'h3';
2
- import { R as RouteFunction, j as PublicServeOptions } from './types-DKLbLp0d.js';
2
+ import { R as RouteFunction, j as PublicServeOptions } from './types-Cuqlx2Cr.js';
3
3
  import '@upstash/qstash';
4
+ import 'zod';
4
5
  import 'ai';
5
6
  import '@ai-sdk/openai';
6
7
 
package/h3.js CHANGED
@@ -1071,6 +1071,9 @@ var triggerFirstInvocation = async ({
1071
1071
  retries: workflowContext.retries,
1072
1072
  telemetry
1073
1073
  });
1074
+ if (workflowContext.headers.get("content-type")) {
1075
+ headers["content-type"] = workflowContext.headers.get("content-type");
1076
+ }
1074
1077
  if (useJSONContent) {
1075
1078
  headers["content-type"] = "application/json";
1076
1079
  }
@@ -1952,9 +1955,11 @@ you need from that agent.
1952
1955
  `;
1953
1956
 
1954
1957
  // src/agents/adapters.ts
1955
- var createWorkflowOpenAI = (context, baseURL) => {
1958
+ var createWorkflowOpenAI = (context, config) => {
1959
+ const { baseURL, apiKey } = config ?? {};
1956
1960
  return (0, import_openai2.createOpenAI)({
1957
1961
  baseURL,
1962
+ apiKey,
1958
1963
  compatibility: "strict",
1959
1964
  fetch: async (input, init) => {
1960
1965
  try {
@@ -2227,8 +2232,8 @@ var WorkflowAgents = class {
2227
2232
  */
2228
2233
  openai(...params) {
2229
2234
  const [model, settings] = params;
2230
- const { baseURL, ...otherSettings } = settings ?? {};
2231
- const openai2 = createWorkflowOpenAI(this.context, baseURL);
2235
+ const { baseURL, apiKey, ...otherSettings } = settings ?? {};
2236
+ const openai2 = createWorkflowOpenAI(this.context, { baseURL, apiKey });
2232
2237
  return openai2(model, otherSettings);
2233
2238
  }
2234
2239
  };
@@ -2984,7 +2989,8 @@ var processOptions = (options) => {
2984
2989
  return void 0;
2985
2990
  }
2986
2991
  try {
2987
- return JSON.parse(initialRequest);
2992
+ const parsed = JSON.parse(initialRequest);
2993
+ return options?.schema ? options.schema.parse(parsed) : parsed;
2988
2994
  } catch (error) {
2989
2995
  if (error instanceof SyntaxError) {
2990
2996
  return initialRequest;
package/h3.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  SDK_TELEMETRY,
3
3
  serveBase
4
- } from "./chunk-XGCTFI4M.mjs";
4
+ } from "./chunk-U6XFLG7W.mjs";
5
5
 
6
6
  // node_modules/defu/dist/defu.mjs
7
7
  function isPlainObject(value) {
package/hono.d.mts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { Context } from 'hono';
2
- import { R as RouteFunction, j as PublicServeOptions } from './types-DKLbLp0d.mjs';
2
+ import { R as RouteFunction, j as PublicServeOptions } from './types-Cuqlx2Cr.mjs';
3
3
  import { Variables } from 'hono/types';
4
4
  import '@upstash/qstash';
5
+ import 'zod';
5
6
  import 'ai';
6
7
  import '@ai-sdk/openai';
7
8
 
package/hono.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { Context } from 'hono';
2
- import { R as RouteFunction, j as PublicServeOptions } from './types-DKLbLp0d.js';
2
+ import { R as RouteFunction, j as PublicServeOptions } from './types-Cuqlx2Cr.js';
3
3
  import { Variables } from 'hono/types';
4
4
  import '@upstash/qstash';
5
+ import 'zod';
5
6
  import 'ai';
6
7
  import '@ai-sdk/openai';
7
8
 
package/hono.js CHANGED
@@ -759,6 +759,9 @@ var triggerFirstInvocation = async ({
759
759
  retries: workflowContext.retries,
760
760
  telemetry
761
761
  });
762
+ if (workflowContext.headers.get("content-type")) {
763
+ headers["content-type"] = workflowContext.headers.get("content-type");
764
+ }
762
765
  if (useJSONContent) {
763
766
  headers["content-type"] = "application/json";
764
767
  }
@@ -1640,9 +1643,11 @@ you need from that agent.
1640
1643
  `;
1641
1644
 
1642
1645
  // src/agents/adapters.ts
1643
- var createWorkflowOpenAI = (context, baseURL) => {
1646
+ var createWorkflowOpenAI = (context, config) => {
1647
+ const { baseURL, apiKey } = config ?? {};
1644
1648
  return (0, import_openai2.createOpenAI)({
1645
1649
  baseURL,
1650
+ apiKey,
1646
1651
  compatibility: "strict",
1647
1652
  fetch: async (input, init) => {
1648
1653
  try {
@@ -1915,8 +1920,8 @@ var WorkflowAgents = class {
1915
1920
  */
1916
1921
  openai(...params) {
1917
1922
  const [model, settings] = params;
1918
- const { baseURL, ...otherSettings } = settings ?? {};
1919
- const openai2 = createWorkflowOpenAI(this.context, baseURL);
1923
+ const { baseURL, apiKey, ...otherSettings } = settings ?? {};
1924
+ const openai2 = createWorkflowOpenAI(this.context, { baseURL, apiKey });
1920
1925
  return openai2(model, otherSettings);
1921
1926
  }
1922
1927
  };
@@ -2672,7 +2677,8 @@ var processOptions = (options) => {
2672
2677
  return void 0;
2673
2678
  }
2674
2679
  try {
2675
- return JSON.parse(initialRequest);
2680
+ const parsed = JSON.parse(initialRequest);
2681
+ return options?.schema ? options.schema.parse(parsed) : parsed;
2676
2682
  } catch (error) {
2677
2683
  if (error instanceof SyntaxError) {
2678
2684
  return initialRequest;
package/hono.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  SDK_TELEMETRY,
3
3
  serveBase
4
- } from "./chunk-XGCTFI4M.mjs";
4
+ } from "./chunk-U6XFLG7W.mjs";
5
5
 
6
6
  // platforms/hono.ts
7
7
  var serve = (routeFunction, options) => {
package/index.d.mts CHANGED
@@ -1,6 +1,7 @@
1
- import { R as RouteFunction, W as WorkflowServeOptions, N as NotifyResponse, a as Waiter, S as Step } from './types-DKLbLp0d.mjs';
2
- export { A as AsyncStepFunction, C as CallResponse, q as CallSettings, D as Duration, k as FailureFunctionPayload, F as FinishCondition, H as HeaderParams, L as LogLevel, o as NotifyStepResponse, P as ParallelCallState, j as PublicServeOptions, g as RawStep, l as RequiredExceptFields, i as StepFunction, f as StepType, e as StepTypes, h as SyncStepFunction, T as Telemetry, p as WaitEventOptions, m as WaitRequest, n as WaitStepResponse, c as WorkflowClient, b as WorkflowContext, s as WorkflowLogger, r as WorkflowLoggerOptions, d as WorkflowReceiver } from './types-DKLbLp0d.mjs';
1
+ import { R as RouteFunction, W as WorkflowServeOptions, E as ExclusiveValidationOptions, N as NotifyResponse, a as Waiter, S as Step } from './types-Cuqlx2Cr.mjs';
2
+ export { A as AsyncStepFunction, C as CallResponse, q as CallSettings, D as Duration, k as FailureFunctionPayload, F as FinishCondition, H as HeaderParams, L as LogLevel, o as NotifyStepResponse, P as ParallelCallState, j as PublicServeOptions, g as RawStep, l as RequiredExceptFields, i as StepFunction, f as StepType, e as StepTypes, h as SyncStepFunction, T as Telemetry, p as WaitEventOptions, m as WaitRequest, n as WaitStepResponse, c as WorkflowClient, b as WorkflowContext, s as WorkflowLogger, r as WorkflowLoggerOptions, d as WorkflowReceiver } from './types-Cuqlx2Cr.mjs';
3
3
  import { Client as Client$1, QstashError } from '@upstash/qstash';
4
+ import 'zod';
4
5
  import 'ai';
5
6
  import '@ai-sdk/openai';
6
7
 
@@ -12,7 +13,7 @@ import '@ai-sdk/openai';
12
13
  * @param options - Options including the client, onFinish callback, and initialPayloadParser.
13
14
  * @returns An async method that consumes incoming requests and runs the workflow.
14
15
  */
15
- declare const serve: <TInitialPayload = unknown, TRequest extends Request = Request, TResponse extends Response = Response>(routeFunction: RouteFunction<TInitialPayload>, options?: Omit<WorkflowServeOptions<TResponse, TInitialPayload>, "useJSONContent">) => {
16
+ declare const serve: <TInitialPayload = unknown, TRequest extends Request = Request, TResponse extends Response = Response>(routeFunction: RouteFunction<TInitialPayload>, options?: Omit<WorkflowServeOptions<TResponse, TInitialPayload>, "useJSONContent" | "schema" | "initialPayloadParser"> & ExclusiveValidationOptions<TInitialPayload>) => {
16
17
  handler: (request: TRequest) => Promise<TResponse>;
17
18
  };
18
19
 
@@ -191,4 +192,4 @@ declare class WorkflowAbort extends Error {
191
192
  constructor(stepName: string, stepInfo?: Step, cancelWorkflow?: boolean);
192
193
  }
193
194
 
194
- export { Client, NotifyResponse, RouteFunction, Step, Waiter, WorkflowAbort, WorkflowError, WorkflowServeOptions, serve };
195
+ export { Client, ExclusiveValidationOptions, NotifyResponse, RouteFunction, Step, Waiter, WorkflowAbort, WorkflowError, WorkflowServeOptions, serve };
package/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import { R as RouteFunction, W as WorkflowServeOptions, N as NotifyResponse, a as Waiter, S as Step } from './types-DKLbLp0d.js';
2
- export { A as AsyncStepFunction, C as CallResponse, q as CallSettings, D as Duration, k as FailureFunctionPayload, F as FinishCondition, H as HeaderParams, L as LogLevel, o as NotifyStepResponse, P as ParallelCallState, j as PublicServeOptions, g as RawStep, l as RequiredExceptFields, i as StepFunction, f as StepType, e as StepTypes, h as SyncStepFunction, T as Telemetry, p as WaitEventOptions, m as WaitRequest, n as WaitStepResponse, c as WorkflowClient, b as WorkflowContext, s as WorkflowLogger, r as WorkflowLoggerOptions, d as WorkflowReceiver } from './types-DKLbLp0d.js';
1
+ import { R as RouteFunction, W as WorkflowServeOptions, E as ExclusiveValidationOptions, N as NotifyResponse, a as Waiter, S as Step } from './types-Cuqlx2Cr.js';
2
+ export { A as AsyncStepFunction, C as CallResponse, q as CallSettings, D as Duration, k as FailureFunctionPayload, F as FinishCondition, H as HeaderParams, L as LogLevel, o as NotifyStepResponse, P as ParallelCallState, j as PublicServeOptions, g as RawStep, l as RequiredExceptFields, i as StepFunction, f as StepType, e as StepTypes, h as SyncStepFunction, T as Telemetry, p as WaitEventOptions, m as WaitRequest, n as WaitStepResponse, c as WorkflowClient, b as WorkflowContext, s as WorkflowLogger, r as WorkflowLoggerOptions, d as WorkflowReceiver } from './types-Cuqlx2Cr.js';
3
3
  import { Client as Client$1, QstashError } from '@upstash/qstash';
4
+ import 'zod';
4
5
  import 'ai';
5
6
  import '@ai-sdk/openai';
6
7
 
@@ -12,7 +13,7 @@ import '@ai-sdk/openai';
12
13
  * @param options - Options including the client, onFinish callback, and initialPayloadParser.
13
14
  * @returns An async method that consumes incoming requests and runs the workflow.
14
15
  */
15
- declare const serve: <TInitialPayload = unknown, TRequest extends Request = Request, TResponse extends Response = Response>(routeFunction: RouteFunction<TInitialPayload>, options?: Omit<WorkflowServeOptions<TResponse, TInitialPayload>, "useJSONContent">) => {
16
+ declare const serve: <TInitialPayload = unknown, TRequest extends Request = Request, TResponse extends Response = Response>(routeFunction: RouteFunction<TInitialPayload>, options?: Omit<WorkflowServeOptions<TResponse, TInitialPayload>, "useJSONContent" | "schema" | "initialPayloadParser"> & ExclusiveValidationOptions<TInitialPayload>) => {
16
17
  handler: (request: TRequest) => Promise<TResponse>;
17
18
  };
18
19
 
@@ -191,4 +192,4 @@ declare class WorkflowAbort extends Error {
191
192
  constructor(stepName: string, stepInfo?: Step, cancelWorkflow?: boolean);
192
193
  }
193
194
 
194
- export { Client, NotifyResponse, RouteFunction, Step, Waiter, WorkflowAbort, WorkflowError, WorkflowServeOptions, serve };
195
+ export { Client, ExclusiveValidationOptions, NotifyResponse, RouteFunction, Step, Waiter, WorkflowAbort, WorkflowError, WorkflowServeOptions, serve };
package/index.js CHANGED
@@ -772,6 +772,9 @@ var triggerFirstInvocation = async ({
772
772
  retries: workflowContext.retries,
773
773
  telemetry
774
774
  });
775
+ if (workflowContext.headers.get("content-type")) {
776
+ headers["content-type"] = workflowContext.headers.get("content-type");
777
+ }
775
778
  if (useJSONContent) {
776
779
  headers["content-type"] = "application/json";
777
780
  }
@@ -1653,9 +1656,11 @@ you need from that agent.
1653
1656
  `;
1654
1657
 
1655
1658
  // src/agents/adapters.ts
1656
- var createWorkflowOpenAI = (context, baseURL) => {
1659
+ var createWorkflowOpenAI = (context, config) => {
1660
+ const { baseURL, apiKey } = config ?? {};
1657
1661
  return (0, import_openai2.createOpenAI)({
1658
1662
  baseURL,
1663
+ apiKey,
1659
1664
  compatibility: "strict",
1660
1665
  fetch: async (input, init) => {
1661
1666
  try {
@@ -1928,8 +1933,8 @@ var WorkflowAgents = class {
1928
1933
  */
1929
1934
  openai(...params) {
1930
1935
  const [model, settings] = params;
1931
- const { baseURL, ...otherSettings } = settings ?? {};
1932
- const openai2 = createWorkflowOpenAI(this.context, baseURL);
1936
+ const { baseURL, apiKey, ...otherSettings } = settings ?? {};
1937
+ const openai2 = createWorkflowOpenAI(this.context, { baseURL, apiKey });
1933
1938
  return openai2(model, otherSettings);
1934
1939
  }
1935
1940
  };
@@ -2685,7 +2690,8 @@ var processOptions = (options) => {
2685
2690
  return void 0;
2686
2691
  }
2687
2692
  try {
2688
- return JSON.parse(initialRequest);
2693
+ const parsed = JSON.parse(initialRequest);
2694
+ return options?.schema ? options.schema.parse(parsed) : parsed;
2689
2695
  } catch (error) {
2690
2696
  if (error instanceof SyntaxError) {
2691
2697
  return initialRequest;
package/index.mjs CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  makeNotifyRequest,
10
10
  serve,
11
11
  triggerFirstInvocation
12
- } from "./chunk-XGCTFI4M.mjs";
12
+ } from "./chunk-U6XFLG7W.mjs";
13
13
 
14
14
  // src/client/index.ts
15
15
  import { Client as QStashClient } from "@upstash/qstash";
package/nextjs.d.mts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { NextApiHandler } from 'next';
2
- import { R as RouteFunction, j as PublicServeOptions } from './types-DKLbLp0d.mjs';
2
+ import { R as RouteFunction, j as PublicServeOptions } from './types-Cuqlx2Cr.mjs';
3
3
  import '@upstash/qstash';
4
+ import 'zod';
4
5
  import 'ai';
5
6
  import '@ai-sdk/openai';
6
7
 
package/nextjs.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { NextApiHandler } from 'next';
2
- import { R as RouteFunction, j as PublicServeOptions } from './types-DKLbLp0d.js';
2
+ import { R as RouteFunction, j as PublicServeOptions } from './types-Cuqlx2Cr.js';
3
3
  import '@upstash/qstash';
4
+ import 'zod';
4
5
  import 'ai';
5
6
  import '@ai-sdk/openai';
6
7
 
package/nextjs.js CHANGED
@@ -760,6 +760,9 @@ var triggerFirstInvocation = async ({
760
760
  retries: workflowContext.retries,
761
761
  telemetry
762
762
  });
763
+ if (workflowContext.headers.get("content-type")) {
764
+ headers["content-type"] = workflowContext.headers.get("content-type");
765
+ }
763
766
  if (useJSONContent) {
764
767
  headers["content-type"] = "application/json";
765
768
  }
@@ -1641,9 +1644,11 @@ you need from that agent.
1641
1644
  `;
1642
1645
 
1643
1646
  // src/agents/adapters.ts
1644
- var createWorkflowOpenAI = (context, baseURL) => {
1647
+ var createWorkflowOpenAI = (context, config) => {
1648
+ const { baseURL, apiKey } = config ?? {};
1645
1649
  return (0, import_openai2.createOpenAI)({
1646
1650
  baseURL,
1651
+ apiKey,
1647
1652
  compatibility: "strict",
1648
1653
  fetch: async (input, init) => {
1649
1654
  try {
@@ -1916,8 +1921,8 @@ var WorkflowAgents = class {
1916
1921
  */
1917
1922
  openai(...params) {
1918
1923
  const [model, settings] = params;
1919
- const { baseURL, ...otherSettings } = settings ?? {};
1920
- const openai2 = createWorkflowOpenAI(this.context, baseURL);
1924
+ const { baseURL, apiKey, ...otherSettings } = settings ?? {};
1925
+ const openai2 = createWorkflowOpenAI(this.context, { baseURL, apiKey });
1921
1926
  return openai2(model, otherSettings);
1922
1927
  }
1923
1928
  };
@@ -2673,7 +2678,8 @@ var processOptions = (options) => {
2673
2678
  return void 0;
2674
2679
  }
2675
2680
  try {
2676
- return JSON.parse(initialRequest);
2681
+ const parsed = JSON.parse(initialRequest);
2682
+ return options?.schema ? options.schema.parse(parsed) : parsed;
2677
2683
  } catch (error) {
2678
2684
  if (error instanceof SyntaxError) {
2679
2685
  return initialRequest;
package/nextjs.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  SDK_TELEMETRY,
3
3
  serveBase
4
- } from "./chunk-XGCTFI4M.mjs";
4
+ } from "./chunk-U6XFLG7W.mjs";
5
5
 
6
6
  // platforms/nextjs.ts
7
7
  var serve = (routeFunction, options) => {
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@upstash/workflow","version":"v0.2.6-canary.0","description":"Durable, Reliable and Performant Serverless Functions","main":"./index.js","module":"./index.mjs","types":"./index.d.ts","files":["./*"],"exports":{".":{"import":"./index.mjs","require":"./index.js"},"./dist/nextjs":{"import":"./nextjs.mjs","require":"./nextjs.js"},"./nextjs":{"import":"./nextjs.mjs","require":"./nextjs.js"},"./h3":{"import":"./h3.mjs","require":"./h3.js"},"./svelte":{"import":"./svelte.mjs","require":"./svelte.js"},"./solidjs":{"import":"./solidjs.mjs","require":"./solidjs.js"},"./workflow":{"import":"./workflow.mjs","require":"./workflow.js"},"./hono":{"import":"./hono.mjs","require":"./hono.js"},"./cloudflare":{"import":"./cloudflare.mjs","require":"./cloudflare.js"},"./astro":{"import":"./astro.mjs","require":"./astro.js"},"./express":{"import":"./express.mjs","require":"./express.js"}},"scripts":{"build":"tsup && cp README.md ./dist/ && cp package.json ./dist/ && cp LICENSE ./dist/","test":"bun test src","fmt":"prettier --write .","lint":"tsc && eslint \"{src,platforms}/**/*.{js,ts,tsx}\" --quiet --fix","check-exports":"bun run build && cd dist && attw -P"},"repository":{"type":"git","url":"git+https://github.com/upstash/workflow-ts.git"},"keywords":["upstash","qstash","workflow","serverless"],"author":"Cahid Arda Oz","license":"MIT","bugs":{"url":"https://github.com/upstash/workflow-ts/issues"},"homepage":"https://github.com/upstash/workflow-ts#readme","devDependencies":{"@commitlint/cli":"^19.5.0","@commitlint/config-conventional":"^19.5.0","@eslint/js":"^9.11.1","@solidjs/start":"^1.0.8","@sveltejs/kit":"^2.6.1","@types/bun":"^1.1.10","@types/express":"^5.0.0","astro":"^4.16.7","eslint":"^9.11.1","eslint-plugin-unicorn":"^55.0.0","express":"^4.21.1","globals":"^15.10.0","h3":"^1.12.0","hono":"^4.6.3","husky":"^9.1.6","next":"^14.2.14","prettier":"3.3.3","tsup":"^8.3.0","typescript":"^5.7.2","typescript-eslint":"^8.18.0"},"dependencies":{"@ai-sdk/openai":"^1.0.15","@upstash/qstash":"^2.7.20","ai":"^4.0.30","zod":"^3.24.1"},"directories":{"example":"examples"}}
1
+ {"name":"@upstash/workflow","version":"v0.2.7","description":"Durable, Reliable and Performant Serverless Functions","main":"./index.js","module":"./index.mjs","types":"./index.d.ts","files":["./*"],"exports":{".":{"import":"./index.mjs","require":"./index.js"},"./dist/nextjs":{"import":"./nextjs.mjs","require":"./nextjs.js"},"./nextjs":{"import":"./nextjs.mjs","require":"./nextjs.js"},"./h3":{"import":"./h3.mjs","require":"./h3.js"},"./svelte":{"import":"./svelte.mjs","require":"./svelte.js"},"./solidjs":{"import":"./solidjs.mjs","require":"./solidjs.js"},"./workflow":{"import":"./workflow.mjs","require":"./workflow.js"},"./hono":{"import":"./hono.mjs","require":"./hono.js"},"./cloudflare":{"import":"./cloudflare.mjs","require":"./cloudflare.js"},"./astro":{"import":"./astro.mjs","require":"./astro.js"},"./express":{"import":"./express.mjs","require":"./express.js"}},"scripts":{"build":"tsup && cp README.md ./dist/ && cp package.json ./dist/ && cp LICENSE ./dist/","test":"bun test src","fmt":"prettier --write .","lint":"tsc && eslint \"{src,platforms}/**/*.{js,ts,tsx}\" --quiet --fix","check-exports":"bun run build && cd dist && attw -P"},"repository":{"type":"git","url":"git+https://github.com/upstash/workflow-ts.git"},"keywords":["upstash","qstash","workflow","serverless"],"author":"Cahid Arda Oz","license":"MIT","bugs":{"url":"https://github.com/upstash/workflow-ts/issues"},"homepage":"https://github.com/upstash/workflow-ts#readme","devDependencies":{"@commitlint/cli":"^19.5.0","@commitlint/config-conventional":"^19.5.0","@eslint/js":"^9.11.1","@solidjs/start":"^1.0.8","@sveltejs/kit":"^2.6.1","@types/bun":"^1.1.10","@types/express":"^5.0.0","astro":"^4.16.7","eslint":"^9.11.1","eslint-plugin-unicorn":"^55.0.0","express":"^4.21.1","globals":"^15.10.0","h3":"^1.12.0","hono":"^4.6.3","husky":"^9.1.6","next":"^14.2.14","prettier":"3.3.3","tsup":"^8.3.0","typescript":"^5.7.2","typescript-eslint":"^8.18.0"},"dependencies":{"@ai-sdk/openai":"^1.0.15","@upstash/qstash":"^2.7.20","ai":"^4.0.30","zod":"^3.24.1"},"directories":{"example":"examples"}}
package/solidjs.d.mts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { APIEvent } from '@solidjs/start/server';
2
- import { R as RouteFunction, j as PublicServeOptions } from './types-DKLbLp0d.mjs';
2
+ import { R as RouteFunction, j as PublicServeOptions } from './types-Cuqlx2Cr.mjs';
3
3
  import '@upstash/qstash';
4
+ import 'zod';
4
5
  import 'ai';
5
6
  import '@ai-sdk/openai';
6
7
 
package/solidjs.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { APIEvent } from '@solidjs/start/server';
2
- import { R as RouteFunction, j as PublicServeOptions } from './types-DKLbLp0d.js';
2
+ import { R as RouteFunction, j as PublicServeOptions } from './types-Cuqlx2Cr.js';
3
3
  import '@upstash/qstash';
4
+ import 'zod';
4
5
  import 'ai';
5
6
  import '@ai-sdk/openai';
6
7
 
package/solidjs.js CHANGED
@@ -759,6 +759,9 @@ var triggerFirstInvocation = async ({
759
759
  retries: workflowContext.retries,
760
760
  telemetry
761
761
  });
762
+ if (workflowContext.headers.get("content-type")) {
763
+ headers["content-type"] = workflowContext.headers.get("content-type");
764
+ }
762
765
  if (useJSONContent) {
763
766
  headers["content-type"] = "application/json";
764
767
  }
@@ -1640,9 +1643,11 @@ you need from that agent.
1640
1643
  `;
1641
1644
 
1642
1645
  // src/agents/adapters.ts
1643
- var createWorkflowOpenAI = (context, baseURL) => {
1646
+ var createWorkflowOpenAI = (context, config) => {
1647
+ const { baseURL, apiKey } = config ?? {};
1644
1648
  return (0, import_openai2.createOpenAI)({
1645
1649
  baseURL,
1650
+ apiKey,
1646
1651
  compatibility: "strict",
1647
1652
  fetch: async (input, init) => {
1648
1653
  try {
@@ -1915,8 +1920,8 @@ var WorkflowAgents = class {
1915
1920
  */
1916
1921
  openai(...params) {
1917
1922
  const [model, settings] = params;
1918
- const { baseURL, ...otherSettings } = settings ?? {};
1919
- const openai2 = createWorkflowOpenAI(this.context, baseURL);
1923
+ const { baseURL, apiKey, ...otherSettings } = settings ?? {};
1924
+ const openai2 = createWorkflowOpenAI(this.context, { baseURL, apiKey });
1920
1925
  return openai2(model, otherSettings);
1921
1926
  }
1922
1927
  };
@@ -2672,7 +2677,8 @@ var processOptions = (options) => {
2672
2677
  return void 0;
2673
2678
  }
2674
2679
  try {
2675
- return JSON.parse(initialRequest);
2680
+ const parsed = JSON.parse(initialRequest);
2681
+ return options?.schema ? options.schema.parse(parsed) : parsed;
2676
2682
  } catch (error) {
2677
2683
  if (error instanceof SyntaxError) {
2678
2684
  return initialRequest;
package/solidjs.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  SDK_TELEMETRY,
3
3
  serveBase
4
- } from "./chunk-XGCTFI4M.mjs";
4
+ } from "./chunk-U6XFLG7W.mjs";
5
5
 
6
6
  // platforms/solidjs.ts
7
7
  var serve = (routeFunction, options) => {
package/svelte.d.mts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { RequestHandler } from '@sveltejs/kit';
2
- import { R as RouteFunction, j as PublicServeOptions } from './types-DKLbLp0d.mjs';
2
+ import { R as RouteFunction, j as PublicServeOptions } from './types-Cuqlx2Cr.mjs';
3
3
  import '@upstash/qstash';
4
+ import 'zod';
4
5
  import 'ai';
5
6
  import '@ai-sdk/openai';
6
7
 
package/svelte.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { RequestHandler } from '@sveltejs/kit';
2
- import { R as RouteFunction, j as PublicServeOptions } from './types-DKLbLp0d.js';
2
+ import { R as RouteFunction, j as PublicServeOptions } from './types-Cuqlx2Cr.js';
3
3
  import '@upstash/qstash';
4
+ import 'zod';
4
5
  import 'ai';
5
6
  import '@ai-sdk/openai';
6
7
 
package/svelte.js CHANGED
@@ -759,6 +759,9 @@ var triggerFirstInvocation = async ({
759
759
  retries: workflowContext.retries,
760
760
  telemetry
761
761
  });
762
+ if (workflowContext.headers.get("content-type")) {
763
+ headers["content-type"] = workflowContext.headers.get("content-type");
764
+ }
762
765
  if (useJSONContent) {
763
766
  headers["content-type"] = "application/json";
764
767
  }
@@ -1640,9 +1643,11 @@ you need from that agent.
1640
1643
  `;
1641
1644
 
1642
1645
  // src/agents/adapters.ts
1643
- var createWorkflowOpenAI = (context, baseURL) => {
1646
+ var createWorkflowOpenAI = (context, config) => {
1647
+ const { baseURL, apiKey } = config ?? {};
1644
1648
  return (0, import_openai2.createOpenAI)({
1645
1649
  baseURL,
1650
+ apiKey,
1646
1651
  compatibility: "strict",
1647
1652
  fetch: async (input, init) => {
1648
1653
  try {
@@ -1915,8 +1920,8 @@ var WorkflowAgents = class {
1915
1920
  */
1916
1921
  openai(...params) {
1917
1922
  const [model, settings] = params;
1918
- const { baseURL, ...otherSettings } = settings ?? {};
1919
- const openai2 = createWorkflowOpenAI(this.context, baseURL);
1923
+ const { baseURL, apiKey, ...otherSettings } = settings ?? {};
1924
+ const openai2 = createWorkflowOpenAI(this.context, { baseURL, apiKey });
1920
1925
  return openai2(model, otherSettings);
1921
1926
  }
1922
1927
  };
@@ -2672,7 +2677,8 @@ var processOptions = (options) => {
2672
2677
  return void 0;
2673
2678
  }
2674
2679
  try {
2675
- return JSON.parse(initialRequest);
2680
+ const parsed = JSON.parse(initialRequest);
2681
+ return options?.schema ? options.schema.parse(parsed) : parsed;
2676
2682
  } catch (error) {
2677
2683
  if (error instanceof SyntaxError) {
2678
2684
  return initialRequest;
package/svelte.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  SDK_TELEMETRY,
3
3
  serveBase
4
- } from "./chunk-XGCTFI4M.mjs";
4
+ } from "./chunk-U6XFLG7W.mjs";
5
5
 
6
6
  // platforms/svelte.ts
7
7
  var serve = (routeFunction, options) => {
@@ -1,4 +1,5 @@
1
1
  import { PublishRequest, Client, Receiver, HTTPMethods as HTTPMethods$1 } from '@upstash/qstash';
2
+ import { z } from 'zod';
2
3
  import * as ai from 'ai';
3
4
  import { CoreTool, generateText } from 'ai';
4
5
  import * as _ai_sdk_openai from '@ai-sdk/openai';
@@ -392,45 +393,16 @@ declare class WorkflowApi extends BaseWorkflowApi {
392
393
  }
393
394
 
394
395
  /**
395
- * An Agent which utilizes the model and tools available to it
396
- * to achieve a given task
396
+ * creates an AI SDK openai client with a custom
397
+ * fetch implementation which uses context.call.
397
398
  *
398
- * @param name Name of the agent
399
- * @param background Background of the agent
400
- * @param model LLM model to use
401
- * @param tools tools available to the agent
402
- * @param maxSteps number of times the agent can call the LLM at most. If
403
- * the agent abruptly stops execution after calling tools, you may need
404
- * to increase maxSteps
405
- * @param temparature temparature used when calling the LLM
399
+ * @param context workflow context
400
+ * @returns ai sdk openai
406
401
  */
407
- declare class Agent {
408
- readonly name: AgentParameters["name"];
409
- readonly tools: AgentParameters["tools"];
410
- readonly maxSteps: AgentParameters["maxSteps"];
411
- readonly background: AgentParameters["background"];
412
- readonly model: AgentParameters["model"];
413
- readonly temparature: AgentParameters["temparature"];
414
- private readonly context;
415
- constructor({ tools, maxSteps, background, name, model, temparature }: AgentParameters, context: WorkflowContext);
416
- /**
417
- * Trigger the agent by passing a prompt
418
- *
419
- * @param prompt task to assign to the agent
420
- * @returns Response as `{ text: string }`
421
- */
422
- call({ prompt }: {
423
- prompt: string;
424
- }): Promise<{
425
- text: string;
426
- }>;
427
- /**
428
- * Convert the agent to a tool which can be used by other agents.
429
- *
430
- * @returns the agent as a tool
431
- */
432
- asTool(): AISDKTool;
433
- }
402
+ declare const createWorkflowOpenAI: (context: WorkflowContext, config?: {
403
+ baseURL?: string;
404
+ apiKey?: string;
405
+ }) => _ai_sdk_openai.OpenAIProvider;
434
406
 
435
407
  type AISDKTool = CoreTool;
436
408
  type LangchainTool = {
@@ -502,20 +474,53 @@ type MultiAgentTaskParams = TaskParams & {
502
474
  */
503
475
  background?: string;
504
476
  };
505
-
506
477
  type ModelParams = Parameters<ReturnType<typeof createWorkflowOpenAI>>;
507
- type ModelSettingsWithBaseURL = ModelParams["1"] & {
478
+ type CustomModelSettings = ModelParams["1"] & {
508
479
  baseURL?: string;
480
+ apiKey?: string;
509
481
  };
510
- type ModelParamsWithBaseURL = [ModelParams[0], ModelSettingsWithBaseURL?];
482
+ type CustomModelParams = [ModelParams[0], CustomModelSettings?];
483
+
511
484
  /**
512
- * creates an AI SDK openai client with a custom
513
- * fetch implementation which uses context.call.
485
+ * An Agent which utilizes the model and tools available to it
486
+ * to achieve a given task
514
487
  *
515
- * @param context workflow context
516
- * @returns ai sdk openai
488
+ * @param name Name of the agent
489
+ * @param background Background of the agent
490
+ * @param model LLM model to use
491
+ * @param tools tools available to the agent
492
+ * @param maxSteps number of times the agent can call the LLM at most. If
493
+ * the agent abruptly stops execution after calling tools, you may need
494
+ * to increase maxSteps
495
+ * @param temparature temparature used when calling the LLM
517
496
  */
518
- declare const createWorkflowOpenAI: (context: WorkflowContext, baseURL?: string) => _ai_sdk_openai.OpenAIProvider;
497
+ declare class Agent {
498
+ readonly name: AgentParameters["name"];
499
+ readonly tools: AgentParameters["tools"];
500
+ readonly maxSteps: AgentParameters["maxSteps"];
501
+ readonly background: AgentParameters["background"];
502
+ readonly model: AgentParameters["model"];
503
+ readonly temparature: AgentParameters["temparature"];
504
+ private readonly context;
505
+ constructor({ tools, maxSteps, background, name, model, temparature }: AgentParameters, context: WorkflowContext);
506
+ /**
507
+ * Trigger the agent by passing a prompt
508
+ *
509
+ * @param prompt task to assign to the agent
510
+ * @returns Response as `{ text: string }`
511
+ */
512
+ call({ prompt }: {
513
+ prompt: string;
514
+ }): Promise<{
515
+ text: string;
516
+ }>;
517
+ /**
518
+ * Convert the agent to a tool which can be used by other agents.
519
+ *
520
+ * @returns the agent as a tool
521
+ */
522
+ asTool(): AISDKTool;
523
+ }
519
524
 
520
525
  /**
521
526
  * An Agent Task
@@ -627,7 +632,7 @@ declare class WorkflowAgents {
627
632
  /**
628
633
  * creates an openai model for agents
629
634
  */
630
- openai(...params: ModelParamsWithBaseURL): ai.LanguageModelV1;
635
+ openai(...params: CustomModelParams): ai.LanguageModelV1;
631
636
  }
632
637
 
633
638
  /**
@@ -1032,7 +1037,7 @@ type StepFunction<TResult> = AsyncStepFunction<TResult> | SyncStepFunction<TResu
1032
1037
  type ParallelCallState = "first" | "partial" | "discard" | "last";
1033
1038
  type RouteFunction<TInitialPayload> = (context: WorkflowContext<TInitialPayload>) => Promise<void>;
1034
1039
  type FinishCondition = "success" | "duplicate-step" | "fromCallback" | "auth-fail" | "failure-callback" | "workflow-already-ended";
1035
- type WorkflowServeOptions<TResponse extends Response = Response, TInitialPayload = unknown> = {
1040
+ type WorkflowServeOptions<TResponse extends Response = Response, TInitialPayload = unknown> = ValidationOptions<TInitialPayload> & {
1036
1041
  /**
1037
1042
  * QStash client
1038
1043
  */
@@ -1044,10 +1049,6 @@ type WorkflowServeOptions<TResponse extends Response = Response, TInitialPayload
1044
1049
  * @returns response
1045
1050
  */
1046
1051
  onStepFinish?: (workflowRunId: string, finishCondition: FinishCondition) => TResponse;
1047
- /**
1048
- * Function to parse the initial payload passed by the user
1049
- */
1050
- initialPayloadParser?: (initialPayload: string) => TInitialPayload;
1051
1052
  /**
1052
1053
  * Url of the endpoint where the workflow is set up.
1053
1054
  *
@@ -1128,6 +1129,17 @@ type WorkflowServeOptions<TResponse extends Response = Response, TInitialPayload
1128
1129
  * Set `disableTelemetry` to disable this behavior.
1129
1130
  */
1130
1131
  disableTelemetry?: boolean;
1132
+ } & ValidationOptions<TInitialPayload>;
1133
+ type ValidationOptions<TInitialPayload> = {
1134
+ schema?: z.ZodType<TInitialPayload>;
1135
+ initialPayloadParser?: (initialPayload: string) => TInitialPayload;
1136
+ };
1137
+ type ExclusiveValidationOptions<TInitialPayload> = {
1138
+ schema?: ValidationOptions<TInitialPayload>["schema"];
1139
+ initialPayloadParser?: never;
1140
+ } | {
1141
+ schema?: never;
1142
+ initialPayloadParser?: ValidationOptions<TInitialPayload>["initialPayloadParser"];
1131
1143
  };
1132
1144
  type Telemetry = {
1133
1145
  /**
@@ -1143,7 +1155,7 @@ type Telemetry = {
1143
1155
  */
1144
1156
  runtime?: string;
1145
1157
  };
1146
- type PublicServeOptions<TInitialPayload = unknown, TResponse extends Response = Response> = Omit<WorkflowServeOptions<TResponse, TInitialPayload>, "onStepFinish" | "useJSONContent">;
1158
+ type PublicServeOptions<TInitialPayload = unknown, TResponse extends Response = Response> = Omit<WorkflowServeOptions<TResponse, TInitialPayload>, "onStepFinish" | "useJSONContent" | "schema" | "initialPayloadParser"> & ExclusiveValidationOptions<TInitialPayload>;
1147
1159
  /**
1148
1160
  * Payload passed as body in failureFunction
1149
1161
  */
@@ -1301,4 +1313,4 @@ type HeaderParams = {
1301
1313
  callTimeout?: never;
1302
1314
  });
1303
1315
 
1304
- export { type AsyncStepFunction as A, type CallResponse as C, type Duration as D, type FinishCondition as F, type HeaderParams as H, type LogLevel as L, type NotifyResponse as N, type ParallelCallState as P, type RouteFunction as R, type Step as S, type Telemetry as T, type WorkflowServeOptions as W, type Waiter as a, WorkflowContext as b, type WorkflowClient as c, type WorkflowReceiver as d, StepTypes as e, type StepType as f, type RawStep as g, type SyncStepFunction as h, type StepFunction as i, type PublicServeOptions as j, type FailureFunctionPayload as k, type RequiredExceptFields as l, type WaitRequest as m, type WaitStepResponse as n, type NotifyStepResponse as o, type WaitEventOptions as p, type CallSettings as q, type WorkflowLoggerOptions as r, WorkflowLogger as s };
1316
+ export { type AsyncStepFunction as A, type CallResponse as C, type Duration as D, type ExclusiveValidationOptions as E, type FinishCondition as F, type HeaderParams as H, type LogLevel as L, type NotifyResponse as N, type ParallelCallState as P, type RouteFunction as R, type Step as S, type Telemetry as T, type WorkflowServeOptions as W, type Waiter as a, WorkflowContext as b, type WorkflowClient as c, type WorkflowReceiver as d, StepTypes as e, type StepType as f, type RawStep as g, type SyncStepFunction as h, type StepFunction as i, type PublicServeOptions as j, type FailureFunctionPayload as k, type RequiredExceptFields as l, type WaitRequest as m, type WaitStepResponse as n, type NotifyStepResponse as o, type WaitEventOptions as p, type CallSettings as q, type WorkflowLoggerOptions as r, WorkflowLogger as s };
@@ -1,4 +1,5 @@
1
1
  import { PublishRequest, Client, Receiver, HTTPMethods as HTTPMethods$1 } from '@upstash/qstash';
2
+ import { z } from 'zod';
2
3
  import * as ai from 'ai';
3
4
  import { CoreTool, generateText } from 'ai';
4
5
  import * as _ai_sdk_openai from '@ai-sdk/openai';
@@ -392,45 +393,16 @@ declare class WorkflowApi extends BaseWorkflowApi {
392
393
  }
393
394
 
394
395
  /**
395
- * An Agent which utilizes the model and tools available to it
396
- * to achieve a given task
396
+ * creates an AI SDK openai client with a custom
397
+ * fetch implementation which uses context.call.
397
398
  *
398
- * @param name Name of the agent
399
- * @param background Background of the agent
400
- * @param model LLM model to use
401
- * @param tools tools available to the agent
402
- * @param maxSteps number of times the agent can call the LLM at most. If
403
- * the agent abruptly stops execution after calling tools, you may need
404
- * to increase maxSteps
405
- * @param temparature temparature used when calling the LLM
399
+ * @param context workflow context
400
+ * @returns ai sdk openai
406
401
  */
407
- declare class Agent {
408
- readonly name: AgentParameters["name"];
409
- readonly tools: AgentParameters["tools"];
410
- readonly maxSteps: AgentParameters["maxSteps"];
411
- readonly background: AgentParameters["background"];
412
- readonly model: AgentParameters["model"];
413
- readonly temparature: AgentParameters["temparature"];
414
- private readonly context;
415
- constructor({ tools, maxSteps, background, name, model, temparature }: AgentParameters, context: WorkflowContext);
416
- /**
417
- * Trigger the agent by passing a prompt
418
- *
419
- * @param prompt task to assign to the agent
420
- * @returns Response as `{ text: string }`
421
- */
422
- call({ prompt }: {
423
- prompt: string;
424
- }): Promise<{
425
- text: string;
426
- }>;
427
- /**
428
- * Convert the agent to a tool which can be used by other agents.
429
- *
430
- * @returns the agent as a tool
431
- */
432
- asTool(): AISDKTool;
433
- }
402
+ declare const createWorkflowOpenAI: (context: WorkflowContext, config?: {
403
+ baseURL?: string;
404
+ apiKey?: string;
405
+ }) => _ai_sdk_openai.OpenAIProvider;
434
406
 
435
407
  type AISDKTool = CoreTool;
436
408
  type LangchainTool = {
@@ -502,20 +474,53 @@ type MultiAgentTaskParams = TaskParams & {
502
474
  */
503
475
  background?: string;
504
476
  };
505
-
506
477
  type ModelParams = Parameters<ReturnType<typeof createWorkflowOpenAI>>;
507
- type ModelSettingsWithBaseURL = ModelParams["1"] & {
478
+ type CustomModelSettings = ModelParams["1"] & {
508
479
  baseURL?: string;
480
+ apiKey?: string;
509
481
  };
510
- type ModelParamsWithBaseURL = [ModelParams[0], ModelSettingsWithBaseURL?];
482
+ type CustomModelParams = [ModelParams[0], CustomModelSettings?];
483
+
511
484
  /**
512
- * creates an AI SDK openai client with a custom
513
- * fetch implementation which uses context.call.
485
+ * An Agent which utilizes the model and tools available to it
486
+ * to achieve a given task
514
487
  *
515
- * @param context workflow context
516
- * @returns ai sdk openai
488
+ * @param name Name of the agent
489
+ * @param background Background of the agent
490
+ * @param model LLM model to use
491
+ * @param tools tools available to the agent
492
+ * @param maxSteps number of times the agent can call the LLM at most. If
493
+ * the agent abruptly stops execution after calling tools, you may need
494
+ * to increase maxSteps
495
+ * @param temparature temparature used when calling the LLM
517
496
  */
518
- declare const createWorkflowOpenAI: (context: WorkflowContext, baseURL?: string) => _ai_sdk_openai.OpenAIProvider;
497
+ declare class Agent {
498
+ readonly name: AgentParameters["name"];
499
+ readonly tools: AgentParameters["tools"];
500
+ readonly maxSteps: AgentParameters["maxSteps"];
501
+ readonly background: AgentParameters["background"];
502
+ readonly model: AgentParameters["model"];
503
+ readonly temparature: AgentParameters["temparature"];
504
+ private readonly context;
505
+ constructor({ tools, maxSteps, background, name, model, temparature }: AgentParameters, context: WorkflowContext);
506
+ /**
507
+ * Trigger the agent by passing a prompt
508
+ *
509
+ * @param prompt task to assign to the agent
510
+ * @returns Response as `{ text: string }`
511
+ */
512
+ call({ prompt }: {
513
+ prompt: string;
514
+ }): Promise<{
515
+ text: string;
516
+ }>;
517
+ /**
518
+ * Convert the agent to a tool which can be used by other agents.
519
+ *
520
+ * @returns the agent as a tool
521
+ */
522
+ asTool(): AISDKTool;
523
+ }
519
524
 
520
525
  /**
521
526
  * An Agent Task
@@ -627,7 +632,7 @@ declare class WorkflowAgents {
627
632
  /**
628
633
  * creates an openai model for agents
629
634
  */
630
- openai(...params: ModelParamsWithBaseURL): ai.LanguageModelV1;
635
+ openai(...params: CustomModelParams): ai.LanguageModelV1;
631
636
  }
632
637
 
633
638
  /**
@@ -1032,7 +1037,7 @@ type StepFunction<TResult> = AsyncStepFunction<TResult> | SyncStepFunction<TResu
1032
1037
  type ParallelCallState = "first" | "partial" | "discard" | "last";
1033
1038
  type RouteFunction<TInitialPayload> = (context: WorkflowContext<TInitialPayload>) => Promise<void>;
1034
1039
  type FinishCondition = "success" | "duplicate-step" | "fromCallback" | "auth-fail" | "failure-callback" | "workflow-already-ended";
1035
- type WorkflowServeOptions<TResponse extends Response = Response, TInitialPayload = unknown> = {
1040
+ type WorkflowServeOptions<TResponse extends Response = Response, TInitialPayload = unknown> = ValidationOptions<TInitialPayload> & {
1036
1041
  /**
1037
1042
  * QStash client
1038
1043
  */
@@ -1044,10 +1049,6 @@ type WorkflowServeOptions<TResponse extends Response = Response, TInitialPayload
1044
1049
  * @returns response
1045
1050
  */
1046
1051
  onStepFinish?: (workflowRunId: string, finishCondition: FinishCondition) => TResponse;
1047
- /**
1048
- * Function to parse the initial payload passed by the user
1049
- */
1050
- initialPayloadParser?: (initialPayload: string) => TInitialPayload;
1051
1052
  /**
1052
1053
  * Url of the endpoint where the workflow is set up.
1053
1054
  *
@@ -1128,6 +1129,17 @@ type WorkflowServeOptions<TResponse extends Response = Response, TInitialPayload
1128
1129
  * Set `disableTelemetry` to disable this behavior.
1129
1130
  */
1130
1131
  disableTelemetry?: boolean;
1132
+ } & ValidationOptions<TInitialPayload>;
1133
+ type ValidationOptions<TInitialPayload> = {
1134
+ schema?: z.ZodType<TInitialPayload>;
1135
+ initialPayloadParser?: (initialPayload: string) => TInitialPayload;
1136
+ };
1137
+ type ExclusiveValidationOptions<TInitialPayload> = {
1138
+ schema?: ValidationOptions<TInitialPayload>["schema"];
1139
+ initialPayloadParser?: never;
1140
+ } | {
1141
+ schema?: never;
1142
+ initialPayloadParser?: ValidationOptions<TInitialPayload>["initialPayloadParser"];
1131
1143
  };
1132
1144
  type Telemetry = {
1133
1145
  /**
@@ -1143,7 +1155,7 @@ type Telemetry = {
1143
1155
  */
1144
1156
  runtime?: string;
1145
1157
  };
1146
- type PublicServeOptions<TInitialPayload = unknown, TResponse extends Response = Response> = Omit<WorkflowServeOptions<TResponse, TInitialPayload>, "onStepFinish" | "useJSONContent">;
1158
+ type PublicServeOptions<TInitialPayload = unknown, TResponse extends Response = Response> = Omit<WorkflowServeOptions<TResponse, TInitialPayload>, "onStepFinish" | "useJSONContent" | "schema" | "initialPayloadParser"> & ExclusiveValidationOptions<TInitialPayload>;
1147
1159
  /**
1148
1160
  * Payload passed as body in failureFunction
1149
1161
  */
@@ -1301,4 +1313,4 @@ type HeaderParams = {
1301
1313
  callTimeout?: never;
1302
1314
  });
1303
1315
 
1304
- export { type AsyncStepFunction as A, type CallResponse as C, type Duration as D, type FinishCondition as F, type HeaderParams as H, type LogLevel as L, type NotifyResponse as N, type ParallelCallState as P, type RouteFunction as R, type Step as S, type Telemetry as T, type WorkflowServeOptions as W, type Waiter as a, WorkflowContext as b, type WorkflowClient as c, type WorkflowReceiver as d, StepTypes as e, type StepType as f, type RawStep as g, type SyncStepFunction as h, type StepFunction as i, type PublicServeOptions as j, type FailureFunctionPayload as k, type RequiredExceptFields as l, type WaitRequest as m, type WaitStepResponse as n, type NotifyStepResponse as o, type WaitEventOptions as p, type CallSettings as q, type WorkflowLoggerOptions as r, WorkflowLogger as s };
1316
+ export { type AsyncStepFunction as A, type CallResponse as C, type Duration as D, type ExclusiveValidationOptions as E, type FinishCondition as F, type HeaderParams as H, type LogLevel as L, type NotifyResponse as N, type ParallelCallState as P, type RouteFunction as R, type Step as S, type Telemetry as T, type WorkflowServeOptions as W, type Waiter as a, WorkflowContext as b, type WorkflowClient as c, type WorkflowReceiver as d, StepTypes as e, type StepType as f, type RawStep as g, type SyncStepFunction as h, type StepFunction as i, type PublicServeOptions as j, type FailureFunctionPayload as k, type RequiredExceptFields as l, type WaitRequest as m, type WaitStepResponse as n, type NotifyStepResponse as o, type WaitEventOptions as p, type CallSettings as q, type WorkflowLoggerOptions as r, WorkflowLogger as s };