Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/eight-clowns-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@workflow/web-shared": patch
"@workflow/core": patch
---

Fix hydration of eventData for sleep calls
3 changes: 2 additions & 1 deletion packages/core/src/observability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const streamPrintRevivers: Record<string, (value: any) => any> = {
ReadableStream: streamToStreamId,
WritableStream: streamToStreamId,
TransformStream: streamToStreamId,
StepFunction: (value) => `<fn:${value}>`,
};

const hydrateStepIO = <
Expand Down Expand Up @@ -109,7 +110,7 @@ const hydrateEventData = <
Object.entries(event.eventData).map(([key, value]) => [
key,
hydrateStepArguments(
value as any,
[value] as any,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devalue can be truly annoying. I feel like this was working at some point, and we might have changed something about our eventData return value? Unsure

[],
event.runId as string,
globalThis,
Expand Down
19 changes: 9 additions & 10 deletions packages/web-shared/src/api/workflow-server-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,15 @@ function getUserFacingMessage(error: Error): string {
return error.message || 'An unexpected error occurred';
}

const toJSONCompatible = <T>(data: T): T => {
if (data && typeof data === 'object') {
return JSON.parse(JSON.stringify(data)) as T;
}
return data;
};

const hydrate = <T>(data: T): T => {
data = toJSONCompatible(data);
try {
return hydrateResourceIO(data as any) as T;
} catch (error) {
Expand All @@ -148,16 +156,7 @@ const hydrate = <T>(data: T): T => {
* @returns ServerActionResult with success=true and the data
*/
function createResponse<T>(data: T): ServerActionResult<T> {
if (data && typeof data === 'object') {
// We can't pass non-serializable objects from client to server. To ensure
// we don't accidentally do this, we convert the object to JSON.
try {
data = JSON.parse(JSON.stringify(data)) as T;
} catch {
// If we can't serialize the data, we'll leave it to the API layer to
// throw an error if the data isn't transportable.
}
}
data = toJSONCompatible(data);
return {
success: true,
data,
Expand Down
2 changes: 1 addition & 1 deletion workbench/nitro-v2/server/api/trigger.post.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineEventHandler, getRequestURL, readRawBody } from 'h3';
import { start } from 'workflow/api';
import { hydrateWorkflowArguments } from 'workflow/internal/serialization';
import { allWorkflows } from '../_workflows.js';
import { allWorkflows } from '../../_workflows.js';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was previously causing turbo build to fail for me when run at the root, unsure if relevant

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh we shouldn't include it in this PR 🤔


export default defineEventHandler(async (event) => {
const url = getRequestURL(event);
Expand Down
Loading