workflow 4.2.0-beta.65 → 4.2.0-beta.66

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/docs/ai/index.mdx CHANGED
@@ -151,7 +151,7 @@ import { z } from "zod";
151
151
  export const tools = {
152
152
  searchFlights: tool({
153
153
  description: "Search for flights",
154
- inputSchema: z.object({ query: z.string() }),
154
+ inputSchema: z.object({ from: z.string(), to: z.string(), date: z.string() }),
155
155
  execute: searchFlights,
156
156
  }),
157
157
  };
@@ -209,7 +209,7 @@ Here's a more complex example showing how you might stream AI chat responses:
209
209
  import { getWritable } from "workflow";
210
210
  import { generateId, streamText, type UIMessageChunk } from "ai";
211
211
 
212
- export async function chat(messages: UIMessage[]) {
212
+ export async function chat(messages: ModelMessage[]) {
213
213
  "use workflow";
214
214
 
215
215
  // Get typed writable stream for UI message chunks
@@ -223,7 +223,7 @@ export async function chat(messages: UIMessage[]) {
223
223
  // Process messages in steps
224
224
  for (let i = 0; i < MAX_STEPS; i++) {
225
225
  const result = await streamTextStep(currentMessages, writable);
226
- currentMessages.push(result.messages);
226
+ currentMessages.push(...result.messages);
227
227
 
228
228
  if (result.finishReason !== "tool-calls") {
229
229
  break;
@@ -252,7 +252,7 @@ async function startStream(writable: WritableStream<UIMessageChunk>) {
252
252
  }
253
253
 
254
254
  async function streamTextStep(
255
- messages: UIMessage[],
255
+ messages: ModelMessage[],
256
256
  writable: WritableStream<UIMessageChunk>
257
257
  ) {
258
258
  "use step";
@@ -261,9 +261,8 @@ async function streamTextStep(
261
261
 
262
262
  // Call streamText from the AI SDK
263
263
  const result = streamText({
264
- model: "gpt-4",
264
+ model: myModel,
265
265
  messages,
266
- /* other options */
267
266
  });
268
267
 
269
268
  // Pipe the AI stream into the writable stream
@@ -89,9 +89,10 @@ export async function POST(request: Request) {
89
89
 
90
90
  try {
91
91
  const hook = await getHookByToken(token); // [!code highlight]
92
+ const metadata = hook.metadata as { allowedUserId?: string } | undefined;
92
93
 
93
94
  // Validate that the hook metadata matches the user
94
- if (hook.metadata?.allowedUserId !== userId) {
95
+ if (metadata?.allowedUserId !== userId) {
95
96
  return Response.json(
96
97
  { error: "Unauthorized to resume this hook" },
97
98
  { status: 403 }
@@ -85,7 +85,7 @@ export async function processPayment(orderId: string) {
85
85
  const payment = await hook; // [!code highlight]
86
86
  return { success: true, payment };
87
87
  } catch (error) {
88
- if (error instanceof WorkflowRuntimeError && error.slug === "hook-conflict") { // [!code highlight]
88
+ if (error instanceof WorkflowRuntimeError && error.message.includes("hook-conflict")) { // [!code highlight]
89
89
  // Another workflow is already processing this order
90
90
  return { success: false, reason: "duplicate-processing" };
91
91
  }
@@ -120,7 +120,7 @@ import { streamProcessingWorkflow } from "./workflows/streaming";
120
120
  export async function POST(request: Request) {
121
121
  // Streams can be passed as workflow arguments
122
122
  const run = await start(streamProcessingWorkflow, [request.body]); // [!code highlight]
123
- await run.result();
123
+ await run.returnValue;
124
124
 
125
125
  return Response.json({ status: "complete" });
126
126
  }
@@ -136,7 +136,7 @@ import { sleep, createWebhook } from "workflow";
136
136
  export async function documentReviewProcess(userId: string) {
137
137
  "use workflow";
138
138
 
139
- await sleep("1 month"); // Sleep will suspend without consuming any resources [!code highlight]
139
+ await sleep("30d"); // Sleep will suspend without consuming any resources [!code highlight]
140
140
 
141
141
  // Create a webhook for external workflow resumption
142
142
  const webhook = createWebhook();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "workflow",
3
- "version": "4.2.0-beta.65",
3
+ "version": "4.2.0-beta.66",
4
4
  "description": "Workflow DevKit - Build durable, resilient, and observable workflows",
5
5
  "main": "dist/typescript-plugin.cjs",
6
6
  "type": "module",
@@ -52,17 +52,17 @@
52
52
  },
53
53
  "dependencies": {
54
54
  "ms": "2.1.3",
55
- "@workflow/astro": "4.0.0-beta.39",
56
- "@workflow/cli": "4.2.0-beta.65",
57
- "@workflow/core": "4.2.0-beta.65",
55
+ "@workflow/astro": "4.0.0-beta.40",
56
+ "@workflow/core": "4.2.0-beta.66",
58
57
  "@workflow/errors": "4.1.0-beta.18",
58
+ "@workflow/cli": "4.2.0-beta.66",
59
59
  "@workflow/typescript-plugin": "4.0.1-beta.5",
60
- "@workflow/next": "4.0.1-beta.61",
61
- "@workflow/nest": "0.0.0-beta.14",
62
- "@workflow/nitro": "4.0.1-beta.60",
63
- "@workflow/nuxt": "4.0.1-beta.49",
64
- "@workflow/sveltekit": "4.0.0-beta.54",
65
- "@workflow/rollup": "4.0.0-beta.22"
60
+ "@workflow/next": "4.0.1-beta.62",
61
+ "@workflow/nest": "0.0.0-beta.15",
62
+ "@workflow/nitro": "4.0.1-beta.61",
63
+ "@workflow/nuxt": "4.0.1-beta.50",
64
+ "@workflow/sveltekit": "4.0.0-beta.55",
65
+ "@workflow/rollup": "4.0.0-beta.23"
66
66
  },
67
67
  "devDependencies": {
68
68
  "@types/ms": "2.1.0",