Skip to content

Commit def6ca6

Browse files
committed
revert
1 parent fdf6103 commit def6ca6

File tree

3 files changed

+46
-34
lines changed

3 files changed

+46
-34
lines changed

workbench/nextjs-turbopack/app/api/trigger/route.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export async function POST(req: Request) {
5555

5656
try {
5757
const run = await start(workflow as any, args as any);
58-
console.log('Run:', run);
58+
console.log('Run', run.runId);
5959
return Response.json(run);
6060
} catch (err) {
6161
console.error(`Failed to start!!`, err);
@@ -98,13 +98,25 @@ export async function GET(req: Request) {
9898
const run = getRun(runId);
9999
const returnValue = await run.returnValue;
100100
console.log('Return value:', returnValue);
101+
102+
// Include run metadata in headers
103+
const [createdAt, startedAt, completedAt] = await Promise.all([
104+
run.createdAt,
105+
run.startedAt,
106+
run.completedAt,
107+
]);
108+
const headers: HeadersInit =
109+
returnValue instanceof ReadableStream
110+
? { 'Content-Type': 'application/octet-stream' }
111+
: {};
112+
113+
headers['X-Workflow-Run-Created-At'] = createdAt?.toISOString() || '';
114+
headers['X-Workflow-Run-Started-At'] = startedAt?.toISOString() || '';
115+
headers['X-Workflow-Run-Completed-At'] = completedAt?.toISOString() || '';
116+
101117
return returnValue instanceof ReadableStream
102-
? new Response(returnValue, {
103-
headers: {
104-
'Content-Type': 'application/octet-stream',
105-
},
106-
})
107-
: Response.json(returnValue);
118+
? new Response(returnValue, { headers })
119+
: Response.json(returnValue, { headers });
108120
} catch (error) {
109121
if (error instanceof Error) {
110122
if (WorkflowRunNotCompletedError.is(error)) {

workbench/nextjs-webpack/app/api/trigger/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export async function POST(req: Request) {
5454
}
5555

5656
const run = await start(workflow as any, args);
57-
console.log('Run:', run);
57+
console.log('Run:', run.runId);
5858
return Response.json(run);
5959
} catch (err) {
6060
console.error(`Failed to start!!`, err);

workbench/sveltekit/src/routes/api/trigger/+server.ts

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import type { RequestHandler } from "@sveltejs/kit";
2-
import { getRun, start } from "workflow/api";
1+
import type { RequestHandler } from '@sveltejs/kit';
2+
import { getRun, start } from 'workflow/api';
33
import {
44
WorkflowRunFailedError,
55
WorkflowRunNotCompletedError,
6-
} from "workflow/internal/errors";
7-
import { hydrateWorkflowArguments } from "workflow/internal/serialization";
8-
import { allWorkflows } from "$lib/_workflows.js";
6+
} from 'workflow/internal/errors';
7+
import { hydrateWorkflowArguments } from 'workflow/internal/serialization';
8+
import { allWorkflows } from '$lib/_workflows.js';
99

1010
export const POST: RequestHandler = async ({ request }) => {
1111
const url = new URL(request.url);
1212
const workflowFile =
13-
url.searchParams.get("workflowFile") || "workflows/99_e2e.ts";
13+
url.searchParams.get('workflowFile') || 'workflows/99_e2e.ts';
1414
if (!workflowFile) {
15-
return new Response("No workflowFile query parameter provided", {
15+
return new Response('No workflowFile query parameter provided', {
1616
status: 400,
1717
});
1818
}
@@ -23,9 +23,9 @@ export const POST: RequestHandler = async ({ request }) => {
2323
});
2424
}
2525

26-
const workflowFn = url.searchParams.get("workflowFn") || "simple";
26+
const workflowFn = url.searchParams.get('workflowFn') || 'simple';
2727
if (!workflowFn) {
28-
return new Response("No workflow query parameter provided", {
28+
return new Response('No workflow query parameter provided', {
2929
status: 400,
3030
});
3131
}
@@ -37,9 +37,9 @@ export const POST: RequestHandler = async ({ request }) => {
3737
let args: any[] = [];
3838

3939
// Args from query string
40-
const argsParam = url.searchParams.get("args");
40+
const argsParam = url.searchParams.get('args');
4141
if (argsParam) {
42-
args = argsParam.split(",").map((arg) => {
42+
args = argsParam.split(',').map((arg) => {
4343
const num = parseFloat(arg);
4444
return Number.isNaN(num) ? arg.trim() : num;
4545
});
@@ -56,7 +56,7 @@ export const POST: RequestHandler = async ({ request }) => {
5656

5757
try {
5858
const run = await start(workflow as any, args as any);
59-
console.log("Run:", run);
59+
console.log('Run:', run.runId);
6060
return Response.json(run);
6161
} catch (err) {
6262
console.error(`Failed to start!!`, err);
@@ -66,14 +66,14 @@ export const POST: RequestHandler = async ({ request }) => {
6666

6767
export const GET: RequestHandler = async ({ request }) => {
6868
const url = new URL(request.url);
69-
const runId = url.searchParams.get("runId");
69+
const runId = url.searchParams.get('runId');
7070
if (!runId) {
71-
return new Response("No runId provided", { status: 400 });
71+
return new Response('No runId provided', { status: 400 });
7272
}
7373

74-
const outputStreamParam = url.searchParams.get("output-stream");
74+
const outputStreamParam = url.searchParams.get('output-stream');
7575
if (outputStreamParam) {
76-
const namespace = outputStreamParam === "1" ? undefined : outputStreamParam;
76+
const namespace = outputStreamParam === '1' ? undefined : outputStreamParam;
7777
const run = getRun(runId);
7878
const stream = run.getReadable({
7979
namespace,
@@ -83,26 +83,26 @@ export const GET: RequestHandler = async ({ request }) => {
8383
transform(chunk, controller) {
8484
const data =
8585
chunk instanceof Uint8Array
86-
? { data: Buffer.from(chunk).toString("base64") }
86+
? { data: Buffer.from(chunk).toString('base64') }
8787
: chunk;
8888
controller.enqueue(`${JSON.stringify(data)}\n`);
8989
},
9090
});
9191
return new Response(stream.pipeThrough(streamWithFraming), {
9292
headers: {
93-
"Content-Type": "application/octet-stream",
93+
'Content-Type': 'application/octet-stream',
9494
},
9595
});
9696
}
9797

9898
try {
9999
const run = getRun(runId);
100100
const returnValue = await run.returnValue;
101-
console.log("Return value:", returnValue);
101+
console.log('Return value:', returnValue);
102102
return returnValue instanceof ReadableStream
103103
? new Response(returnValue, {
104104
headers: {
105-
"Content-Type": "application/octet-stream",
105+
'Content-Type': 'application/octet-stream',
106106
},
107107
})
108108
: Response.json(returnValue);
@@ -115,7 +115,7 @@ export const GET: RequestHandler = async ({ request }) => {
115115
name: error.name,
116116
message: error.message,
117117
},
118-
{ status: 202 },
118+
{ status: 202 }
119119
);
120120
}
121121

@@ -132,20 +132,20 @@ export const GET: RequestHandler = async ({ request }) => {
132132
code: cause.code,
133133
},
134134
},
135-
{ status: 400 },
135+
{ status: 400 }
136136
);
137137
}
138138
}
139139

140140
console.error(
141-
"Unexpected error while getting workflow return value:",
142-
error,
141+
'Unexpected error while getting workflow return value:',
142+
error
143143
);
144144
return Response.json(
145145
{
146-
error: "Internal server error",
146+
error: 'Internal server error',
147147
},
148-
{ status: 500 },
148+
{ status: 500 }
149149
);
150150
}
151151
};

0 commit comments

Comments
 (0)