@upstash/workflow 0.2.7 → 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/index.js CHANGED
@@ -26,6 +26,7 @@ __export(src_exports, {
26
26
  WorkflowContext: () => WorkflowContext,
27
27
  WorkflowError: () => WorkflowError,
28
28
  WorkflowLogger: () => WorkflowLogger,
29
+ WorkflowTool: () => WorkflowTool,
29
30
  serve: () => serve
30
31
  });
31
32
  module.exports = __toCommonJS(src_exports);
@@ -1015,6 +1016,14 @@ var getHeaders = ({
1015
1016
  }
1016
1017
  if (failureUrl) {
1017
1018
  baseHeaders[`Upstash-Failure-Callback-Forward-${WORKFLOW_FAILURE_HEADER}`] = "true";
1019
+ baseHeaders[`Upstash-Failure-Callback-Forward-Upstash-Workflow-Failure-Callback`] = "true";
1020
+ baseHeaders["Upstash-Failure-Callback-Workflow-Runid"] = workflowRunId;
1021
+ baseHeaders["Upstash-Failure-Callback-Workflow-Init"] = "false";
1022
+ baseHeaders["Upstash-Failure-Callback-Workflow-Url"] = workflowUrl;
1023
+ baseHeaders["Upstash-Failure-Callback-Workflow-Calltype"] = "failureCall";
1024
+ if (retries !== void 0) {
1025
+ baseHeaders["Upstash-Failure-Callback-Retries"] = retries.toString();
1026
+ }
1018
1027
  if (!step?.callUrl) {
1019
1028
  baseHeaders["Upstash-Failure-Callback"] = failureUrl;
1020
1029
  }
@@ -1705,9 +1714,10 @@ var wrapTools = ({
1705
1714
  return Object.fromEntries(
1706
1715
  Object.entries(tools).map((toolInfo) => {
1707
1716
  const [toolName, tool3] = toolInfo;
1717
+ const executeAsStep = "executeAsStep" in tool3 ? tool3.executeAsStep : true;
1708
1718
  const aiSDKTool = convertToAISDKTool(tool3);
1709
1719
  const execute = aiSDKTool.execute;
1710
- if (execute) {
1720
+ if (execute && executeAsStep) {
1711
1721
  const wrappedExecute = (...params) => {
1712
1722
  return context.run(`Run tool ${toolName}`, () => execute(...params));
1713
1723
  };
@@ -1728,6 +1738,37 @@ var convertLangchainTool = (langchainTool) => {
1728
1738
  execute: async (...param) => langchainTool.invoke(...param)
1729
1739
  });
1730
1740
  };
1741
+ var WorkflowTool = class {
1742
+ /**
1743
+ * description of the tool
1744
+ */
1745
+ description;
1746
+ /**
1747
+ * schema of the tool
1748
+ */
1749
+ schema;
1750
+ /**
1751
+ * function to invoke the tool
1752
+ */
1753
+ invoke;
1754
+ /**
1755
+ * whether the invoke method of the tool is to be wrapped with `context.run`
1756
+ */
1757
+ executeAsStep;
1758
+ /**
1759
+ *
1760
+ * @param description description of the tool
1761
+ * @param schema schema of the tool
1762
+ * @param invoke function to invoke the tool
1763
+ * @param executeAsStep whether the invoke method of the tool is to be wrapped with `context.run`
1764
+ */
1765
+ constructor(params) {
1766
+ this.description = params.description;
1767
+ this.schema = params.schema;
1768
+ this.invoke = params.invoke;
1769
+ this.executeAsStep = params.executeAsStep ?? true;
1770
+ }
1771
+ };
1731
1772
 
1732
1773
  // src/agents/agent.ts
1733
1774
  var import_zod = require("zod");
@@ -2898,7 +2939,7 @@ var import_qstash11 = require("@upstash/qstash");
2898
2939
  var Client4 = class {
2899
2940
  client;
2900
2941
  constructor(clientConfig) {
2901
- if (!clientConfig.token) {
2942
+ if (!clientConfig?.token) {
2902
2943
  console.error(
2903
2944
  "QStash token is required for Upstash Workflow!\n\nTo fix this:\n1. Get your token from the Upstash Console (https://console.upstash.com/qstash)\n2. Initialize the workflow client with:\n\n const client = new Client({\n token: '<YOUR_QSTASH_TOKEN>'\n });"
2904
2945
  );
@@ -3080,6 +3121,59 @@ var Client4 = class {
3080
3121
  throw result.error;
3081
3122
  }
3082
3123
  }
3124
+ /**
3125
+ * Fetches logs for workflow runs.
3126
+ *
3127
+ * @param workflowRunId - The ID of the workflow run to fetch logs for.
3128
+ * @param cursor - The cursor for pagination.
3129
+ * @param count - Number of runs to fetch. Default value is 10.
3130
+ * @param state - The state of the workflow run.
3131
+ * @param workflowUrl - The URL of the workflow. Should be an exact match.
3132
+ * @param workflowCreatedAt - The creation time of the workflow. If you have two workflow runs with the same URL, you can use this to filter them.
3133
+ * @returns A promise that resolves to either a `WorkflowRunLog` or a `WorkflowRunResponse`.
3134
+ *
3135
+ * @example
3136
+ * Fetch logs for a specific workflow run:
3137
+ * ```typescript
3138
+ * const { runs } = await client.logs({ workflowRunId: '12345' });
3139
+ * const steps = runs[0].steps; // access steps
3140
+ * ```
3141
+ *
3142
+ * @example
3143
+ * Fetch logs with pagination:
3144
+ * ```typescript
3145
+ * const { runs, cursor } = await client.logs();
3146
+ * const steps = runs[0].steps // access steps
3147
+ *
3148
+ * const { runs: nextRuns, cursor: nextCursor } = await client.logs({ cursor, count: 2 });
3149
+ * ```
3150
+ */
3151
+ async logs(params) {
3152
+ const { workflowRunId, cursor, count, state, workflowUrl, workflowCreatedAt } = params ?? {};
3153
+ const urlParams = new URLSearchParams({ "groupBy": "workflowRunId" });
3154
+ if (workflowRunId) {
3155
+ urlParams.append("workflowRunId", workflowRunId);
3156
+ }
3157
+ if (cursor) {
3158
+ urlParams.append("cursor", cursor);
3159
+ }
3160
+ if (count) {
3161
+ urlParams.append("count", count.toString());
3162
+ }
3163
+ if (state) {
3164
+ urlParams.append("state", state);
3165
+ }
3166
+ if (workflowUrl) {
3167
+ urlParams.append("workflowUrl", workflowUrl);
3168
+ }
3169
+ if (workflowCreatedAt) {
3170
+ urlParams.append("workflowCreatedAt", workflowCreatedAt.toString());
3171
+ }
3172
+ const result = await this.client.http.request({
3173
+ path: ["v2", "workflows", `events?${urlParams.toString()}`]
3174
+ });
3175
+ return result;
3176
+ }
3083
3177
  };
3084
3178
  // Annotate the CommonJS export names for ESM import in node:
3085
3179
  0 && (module.exports = {
@@ -3089,5 +3183,6 @@ var Client4 = class {
3089
3183
  WorkflowContext,
3090
3184
  WorkflowError,
3091
3185
  WorkflowLogger,
3186
+ WorkflowTool,
3092
3187
  serve
3093
3188
  });
package/index.mjs CHANGED
@@ -4,19 +4,20 @@ import {
4
4
  WorkflowContext,
5
5
  WorkflowError,
6
6
  WorkflowLogger,
7
+ WorkflowTool,
7
8
  getWorkflowRunId,
8
9
  makeGetWaitersRequest,
9
10
  makeNotifyRequest,
10
11
  serve,
11
12
  triggerFirstInvocation
12
- } from "./chunk-U6XFLG7W.mjs";
13
+ } from "./chunk-BPUSHNSD.mjs";
13
14
 
14
15
  // src/client/index.ts
15
16
  import { Client as QStashClient } from "@upstash/qstash";
16
17
  var Client = class {
17
18
  client;
18
19
  constructor(clientConfig) {
19
- if (!clientConfig.token) {
20
+ if (!clientConfig?.token) {
20
21
  console.error(
21
22
  "QStash token is required for Upstash Workflow!\n\nTo fix this:\n1. Get your token from the Upstash Console (https://console.upstash.com/qstash)\n2. Initialize the workflow client with:\n\n const client = new Client({\n token: '<YOUR_QSTASH_TOKEN>'\n });"
22
23
  );
@@ -198,6 +199,59 @@ var Client = class {
198
199
  throw result.error;
199
200
  }
200
201
  }
202
+ /**
203
+ * Fetches logs for workflow runs.
204
+ *
205
+ * @param workflowRunId - The ID of the workflow run to fetch logs for.
206
+ * @param cursor - The cursor for pagination.
207
+ * @param count - Number of runs to fetch. Default value is 10.
208
+ * @param state - The state of the workflow run.
209
+ * @param workflowUrl - The URL of the workflow. Should be an exact match.
210
+ * @param workflowCreatedAt - The creation time of the workflow. If you have two workflow runs with the same URL, you can use this to filter them.
211
+ * @returns A promise that resolves to either a `WorkflowRunLog` or a `WorkflowRunResponse`.
212
+ *
213
+ * @example
214
+ * Fetch logs for a specific workflow run:
215
+ * ```typescript
216
+ * const { runs } = await client.logs({ workflowRunId: '12345' });
217
+ * const steps = runs[0].steps; // access steps
218
+ * ```
219
+ *
220
+ * @example
221
+ * Fetch logs with pagination:
222
+ * ```typescript
223
+ * const { runs, cursor } = await client.logs();
224
+ * const steps = runs[0].steps // access steps
225
+ *
226
+ * const { runs: nextRuns, cursor: nextCursor } = await client.logs({ cursor, count: 2 });
227
+ * ```
228
+ */
229
+ async logs(params) {
230
+ const { workflowRunId, cursor, count, state, workflowUrl, workflowCreatedAt } = params ?? {};
231
+ const urlParams = new URLSearchParams({ "groupBy": "workflowRunId" });
232
+ if (workflowRunId) {
233
+ urlParams.append("workflowRunId", workflowRunId);
234
+ }
235
+ if (cursor) {
236
+ urlParams.append("cursor", cursor);
237
+ }
238
+ if (count) {
239
+ urlParams.append("count", count.toString());
240
+ }
241
+ if (state) {
242
+ urlParams.append("state", state);
243
+ }
244
+ if (workflowUrl) {
245
+ urlParams.append("workflowUrl", workflowUrl);
246
+ }
247
+ if (workflowCreatedAt) {
248
+ urlParams.append("workflowCreatedAt", workflowCreatedAt.toString());
249
+ }
250
+ const result = await this.client.http.request({
251
+ path: ["v2", "workflows", `events?${urlParams.toString()}`]
252
+ });
253
+ return result;
254
+ }
201
255
  };
202
256
  export {
203
257
  Client,
@@ -206,5 +260,6 @@ export {
206
260
  WorkflowContext,
207
261
  WorkflowError,
208
262
  WorkflowLogger,
263
+ WorkflowTool,
209
264
  serve
210
265
  };
package/nextjs.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { NextApiHandler } from 'next';
2
- import { R as RouteFunction, j as PublicServeOptions } from './types-Cuqlx2Cr.mjs';
2
+ import { R as RouteFunction, k as PublicServeOptions } from './types-B62AnIU3.mjs';
3
3
  import '@upstash/qstash';
4
4
  import 'zod';
5
5
  import 'ai';
package/nextjs.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { NextApiHandler } from 'next';
2
- import { R as RouteFunction, j as PublicServeOptions } from './types-Cuqlx2Cr.js';
2
+ import { R as RouteFunction, k as PublicServeOptions } from './types-B62AnIU3.js';
3
3
  import '@upstash/qstash';
4
4
  import 'zod';
5
5
  import 'ai';
package/nextjs.js CHANGED
@@ -1003,6 +1003,14 @@ var getHeaders = ({
1003
1003
  }
1004
1004
  if (failureUrl) {
1005
1005
  baseHeaders[`Upstash-Failure-Callback-Forward-${WORKFLOW_FAILURE_HEADER}`] = "true";
1006
+ baseHeaders[`Upstash-Failure-Callback-Forward-Upstash-Workflow-Failure-Callback`] = "true";
1007
+ baseHeaders["Upstash-Failure-Callback-Workflow-Runid"] = workflowRunId;
1008
+ baseHeaders["Upstash-Failure-Callback-Workflow-Init"] = "false";
1009
+ baseHeaders["Upstash-Failure-Callback-Workflow-Url"] = workflowUrl;
1010
+ baseHeaders["Upstash-Failure-Callback-Workflow-Calltype"] = "failureCall";
1011
+ if (retries !== void 0) {
1012
+ baseHeaders["Upstash-Failure-Callback-Retries"] = retries.toString();
1013
+ }
1006
1014
  if (!step?.callUrl) {
1007
1015
  baseHeaders["Upstash-Failure-Callback"] = failureUrl;
1008
1016
  }
@@ -1693,9 +1701,10 @@ var wrapTools = ({
1693
1701
  return Object.fromEntries(
1694
1702
  Object.entries(tools).map((toolInfo) => {
1695
1703
  const [toolName, tool3] = toolInfo;
1704
+ const executeAsStep = "executeAsStep" in tool3 ? tool3.executeAsStep : true;
1696
1705
  const aiSDKTool = convertToAISDKTool(tool3);
1697
1706
  const execute = aiSDKTool.execute;
1698
- if (execute) {
1707
+ if (execute && executeAsStep) {
1699
1708
  const wrappedExecute = (...params) => {
1700
1709
  return context.run(`Run tool ${toolName}`, () => execute(...params));
1701
1710
  };
package/nextjs.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  SDK_TELEMETRY,
3
3
  serveBase
4
- } from "./chunk-U6XFLG7W.mjs";
4
+ } from "./chunk-BPUSHNSD.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.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"}}
1
+ {"name":"@upstash/workflow","version":"v0.2.8","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,5 +1,5 @@
1
1
  import { APIEvent } from '@solidjs/start/server';
2
- import { R as RouteFunction, j as PublicServeOptions } from './types-Cuqlx2Cr.mjs';
2
+ import { R as RouteFunction, k as PublicServeOptions } from './types-B62AnIU3.mjs';
3
3
  import '@upstash/qstash';
4
4
  import 'zod';
5
5
  import 'ai';
package/solidjs.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { APIEvent } from '@solidjs/start/server';
2
- import { R as RouteFunction, j as PublicServeOptions } from './types-Cuqlx2Cr.js';
2
+ import { R as RouteFunction, k as PublicServeOptions } from './types-B62AnIU3.js';
3
3
  import '@upstash/qstash';
4
4
  import 'zod';
5
5
  import 'ai';
package/solidjs.js CHANGED
@@ -1002,6 +1002,14 @@ var getHeaders = ({
1002
1002
  }
1003
1003
  if (failureUrl) {
1004
1004
  baseHeaders[`Upstash-Failure-Callback-Forward-${WORKFLOW_FAILURE_HEADER}`] = "true";
1005
+ baseHeaders[`Upstash-Failure-Callback-Forward-Upstash-Workflow-Failure-Callback`] = "true";
1006
+ baseHeaders["Upstash-Failure-Callback-Workflow-Runid"] = workflowRunId;
1007
+ baseHeaders["Upstash-Failure-Callback-Workflow-Init"] = "false";
1008
+ baseHeaders["Upstash-Failure-Callback-Workflow-Url"] = workflowUrl;
1009
+ baseHeaders["Upstash-Failure-Callback-Workflow-Calltype"] = "failureCall";
1010
+ if (retries !== void 0) {
1011
+ baseHeaders["Upstash-Failure-Callback-Retries"] = retries.toString();
1012
+ }
1005
1013
  if (!step?.callUrl) {
1006
1014
  baseHeaders["Upstash-Failure-Callback"] = failureUrl;
1007
1015
  }
@@ -1692,9 +1700,10 @@ var wrapTools = ({
1692
1700
  return Object.fromEntries(
1693
1701
  Object.entries(tools).map((toolInfo) => {
1694
1702
  const [toolName, tool3] = toolInfo;
1703
+ const executeAsStep = "executeAsStep" in tool3 ? tool3.executeAsStep : true;
1695
1704
  const aiSDKTool = convertToAISDKTool(tool3);
1696
1705
  const execute = aiSDKTool.execute;
1697
- if (execute) {
1706
+ if (execute && executeAsStep) {
1698
1707
  const wrappedExecute = (...params) => {
1699
1708
  return context.run(`Run tool ${toolName}`, () => execute(...params));
1700
1709
  };
package/solidjs.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  SDK_TELEMETRY,
3
3
  serveBase
4
- } from "./chunk-U6XFLG7W.mjs";
4
+ } from "./chunk-BPUSHNSD.mjs";
5
5
 
6
6
  // platforms/solidjs.ts
7
7
  var serve = (routeFunction, options) => {
package/svelte.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { RequestHandler } from '@sveltejs/kit';
2
- import { R as RouteFunction, j as PublicServeOptions } from './types-Cuqlx2Cr.mjs';
2
+ import { R as RouteFunction, k as PublicServeOptions } from './types-B62AnIU3.mjs';
3
3
  import '@upstash/qstash';
4
4
  import 'zod';
5
5
  import 'ai';
package/svelte.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { RequestHandler } from '@sveltejs/kit';
2
- import { R as RouteFunction, j as PublicServeOptions } from './types-Cuqlx2Cr.js';
2
+ import { R as RouteFunction, k as PublicServeOptions } from './types-B62AnIU3.js';
3
3
  import '@upstash/qstash';
4
4
  import 'zod';
5
5
  import 'ai';
package/svelte.js CHANGED
@@ -1002,6 +1002,14 @@ var getHeaders = ({
1002
1002
  }
1003
1003
  if (failureUrl) {
1004
1004
  baseHeaders[`Upstash-Failure-Callback-Forward-${WORKFLOW_FAILURE_HEADER}`] = "true";
1005
+ baseHeaders[`Upstash-Failure-Callback-Forward-Upstash-Workflow-Failure-Callback`] = "true";
1006
+ baseHeaders["Upstash-Failure-Callback-Workflow-Runid"] = workflowRunId;
1007
+ baseHeaders["Upstash-Failure-Callback-Workflow-Init"] = "false";
1008
+ baseHeaders["Upstash-Failure-Callback-Workflow-Url"] = workflowUrl;
1009
+ baseHeaders["Upstash-Failure-Callback-Workflow-Calltype"] = "failureCall";
1010
+ if (retries !== void 0) {
1011
+ baseHeaders["Upstash-Failure-Callback-Retries"] = retries.toString();
1012
+ }
1005
1013
  if (!step?.callUrl) {
1006
1014
  baseHeaders["Upstash-Failure-Callback"] = failureUrl;
1007
1015
  }
@@ -1692,9 +1700,10 @@ var wrapTools = ({
1692
1700
  return Object.fromEntries(
1693
1701
  Object.entries(tools).map((toolInfo) => {
1694
1702
  const [toolName, tool3] = toolInfo;
1703
+ const executeAsStep = "executeAsStep" in tool3 ? tool3.executeAsStep : true;
1695
1704
  const aiSDKTool = convertToAISDKTool(tool3);
1696
1705
  const execute = aiSDKTool.execute;
1697
- if (execute) {
1706
+ if (execute && executeAsStep) {
1698
1707
  const wrappedExecute = (...params) => {
1699
1708
  return context.run(`Run tool ${toolName}`, () => execute(...params));
1700
1709
  };
package/svelte.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  SDK_TELEMETRY,
3
3
  serveBase
4
- } from "./chunk-U6XFLG7W.mjs";
4
+ } from "./chunk-BPUSHNSD.mjs";
5
5
 
6
6
  // platforms/svelte.ts
7
7
  var serve = (routeFunction, options) => {
@@ -1,5 +1,5 @@
1
1
  import { PublishRequest, Client, Receiver, HTTPMethods as HTTPMethods$1 } from '@upstash/qstash';
2
- import { z } from 'zod';
2
+ import { ZodType, z } from 'zod';
3
3
  import * as ai from 'ai';
4
4
  import { CoreTool, generateText } from 'ai';
5
5
  import * as _ai_sdk_openai from '@ai-sdk/openai';
@@ -403,6 +403,60 @@ declare const createWorkflowOpenAI: (context: WorkflowContext, config?: {
403
403
  baseURL?: string;
404
404
  apiKey?: string;
405
405
  }) => _ai_sdk_openai.OpenAIProvider;
406
+ declare class WorkflowTool<TSchema extends ZodType = ZodType> implements LangchainTool {
407
+ /**
408
+ * description of the tool
409
+ */
410
+ readonly description: string;
411
+ /**
412
+ * schema of the tool
413
+ */
414
+ readonly schema: TSchema;
415
+ /**
416
+ * function to invoke the tool
417
+ */
418
+ readonly invoke: (params: z.infer<TSchema>) => any;
419
+ /**
420
+ * whether the invoke method of the tool is to be wrapped with `context.run`
421
+ */
422
+ readonly executeAsStep: boolean;
423
+ /**
424
+ *
425
+ * @param description description of the tool
426
+ * @param schema schema of the tool
427
+ * @param invoke function to invoke the tool
428
+ * @param executeAsStep whether the invoke method of the tool is to be wrapped with `context.run`
429
+ */
430
+ constructor(params: {
431
+ /**
432
+ * description of the tool
433
+ */
434
+ description: string;
435
+ /**
436
+ * schema of the tool
437
+ */
438
+ schema: TSchema;
439
+ /**
440
+ * invoke function to invoke the tool
441
+ */
442
+ invoke: (params: z.infer<TSchema>) => any;
443
+ /**
444
+ * whether the invoke method is to be wrapped with `context.run`.
445
+ *
446
+ * When you pass a LangChain, AI SDK tool or a WorkflowTool to your agent,
447
+ * the execute/invoke method of the tool is wrapped with `context.run` by default.
448
+ *
449
+ * This option allows you to disable this behavior.
450
+ *
451
+ * You may want to disable wrapping with context.run if you want to run context.run,
452
+ * context.call or any other workflow step yourself in the execute/invoke method
453
+ * of the tool.
454
+ *
455
+ * @default true
456
+ */
457
+ executeAsStep?: boolean;
458
+ });
459
+ }
406
460
 
407
461
  type AISDKTool = CoreTool;
408
462
  type LangchainTool = {
@@ -412,7 +466,7 @@ type LangchainTool = {
412
466
  };
413
467
  type GenerateTextParams = Parameters<typeof generateText>[0];
414
468
  type Model = GenerateTextParams["model"];
415
- type AgentParameters<TTool extends AISDKTool | LangchainTool = AISDKTool> = {
469
+ type AgentParameters<TTool extends AISDKTool | LangchainTool | WorkflowTool = AISDKTool> = {
416
470
  /**
417
471
  * number of times the agent can call the LLM at most. If
418
472
  * the agent abruptly stops execution after calling tools, you may need
@@ -1313,4 +1367,4 @@ type HeaderParams = {
1313
1367
  callTimeout?: never;
1314
1368
  });
1315
1369
 
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 };
1370
+ 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 StepType as S, type Telemetry as T, type WorkflowServeOptions as W, type RawStep as a, type Waiter as b, type Step as c, WorkflowTool as d, WorkflowContext as e, type WorkflowClient as f, type WorkflowReceiver as g, StepTypes as h, type SyncStepFunction as i, type StepFunction as j, type PublicServeOptions as k, type FailureFunctionPayload as l, type RequiredExceptFields as m, type WaitRequest as n, type WaitStepResponse as o, type NotifyStepResponse as p, type WaitEventOptions as q, type CallSettings as r, type WorkflowLoggerOptions as s, WorkflowLogger as t };
@@ -1,5 +1,5 @@
1
1
  import { PublishRequest, Client, Receiver, HTTPMethods as HTTPMethods$1 } from '@upstash/qstash';
2
- import { z } from 'zod';
2
+ import { ZodType, z } from 'zod';
3
3
  import * as ai from 'ai';
4
4
  import { CoreTool, generateText } from 'ai';
5
5
  import * as _ai_sdk_openai from '@ai-sdk/openai';
@@ -403,6 +403,60 @@ declare const createWorkflowOpenAI: (context: WorkflowContext, config?: {
403
403
  baseURL?: string;
404
404
  apiKey?: string;
405
405
  }) => _ai_sdk_openai.OpenAIProvider;
406
+ declare class WorkflowTool<TSchema extends ZodType = ZodType> implements LangchainTool {
407
+ /**
408
+ * description of the tool
409
+ */
410
+ readonly description: string;
411
+ /**
412
+ * schema of the tool
413
+ */
414
+ readonly schema: TSchema;
415
+ /**
416
+ * function to invoke the tool
417
+ */
418
+ readonly invoke: (params: z.infer<TSchema>) => any;
419
+ /**
420
+ * whether the invoke method of the tool is to be wrapped with `context.run`
421
+ */
422
+ readonly executeAsStep: boolean;
423
+ /**
424
+ *
425
+ * @param description description of the tool
426
+ * @param schema schema of the tool
427
+ * @param invoke function to invoke the tool
428
+ * @param executeAsStep whether the invoke method of the tool is to be wrapped with `context.run`
429
+ */
430
+ constructor(params: {
431
+ /**
432
+ * description of the tool
433
+ */
434
+ description: string;
435
+ /**
436
+ * schema of the tool
437
+ */
438
+ schema: TSchema;
439
+ /**
440
+ * invoke function to invoke the tool
441
+ */
442
+ invoke: (params: z.infer<TSchema>) => any;
443
+ /**
444
+ * whether the invoke method is to be wrapped with `context.run`.
445
+ *
446
+ * When you pass a LangChain, AI SDK tool or a WorkflowTool to your agent,
447
+ * the execute/invoke method of the tool is wrapped with `context.run` by default.
448
+ *
449
+ * This option allows you to disable this behavior.
450
+ *
451
+ * You may want to disable wrapping with context.run if you want to run context.run,
452
+ * context.call or any other workflow step yourself in the execute/invoke method
453
+ * of the tool.
454
+ *
455
+ * @default true
456
+ */
457
+ executeAsStep?: boolean;
458
+ });
459
+ }
406
460
 
407
461
  type AISDKTool = CoreTool;
408
462
  type LangchainTool = {
@@ -412,7 +466,7 @@ type LangchainTool = {
412
466
  };
413
467
  type GenerateTextParams = Parameters<typeof generateText>[0];
414
468
  type Model = GenerateTextParams["model"];
415
- type AgentParameters<TTool extends AISDKTool | LangchainTool = AISDKTool> = {
469
+ type AgentParameters<TTool extends AISDKTool | LangchainTool | WorkflowTool = AISDKTool> = {
416
470
  /**
417
471
  * number of times the agent can call the LLM at most. If
418
472
  * the agent abruptly stops execution after calling tools, you may need
@@ -1313,4 +1367,4 @@ type HeaderParams = {
1313
1367
  callTimeout?: never;
1314
1368
  });
1315
1369
 
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 };
1370
+ 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 StepType as S, type Telemetry as T, type WorkflowServeOptions as W, type RawStep as a, type Waiter as b, type Step as c, WorkflowTool as d, WorkflowContext as e, type WorkflowClient as f, type WorkflowReceiver as g, StepTypes as h, type SyncStepFunction as i, type StepFunction as j, type PublicServeOptions as k, type FailureFunctionPayload as l, type RequiredExceptFields as m, type WaitRequest as n, type WaitStepResponse as o, type NotifyStepResponse as p, type WaitEventOptions as q, type CallSettings as r, type WorkflowLoggerOptions as s, WorkflowLogger as t };