Skip to content

Commit b99bd26

Browse files
authored
fix(workflow): rollup transformer issue (#600)
* fix(workflow): rollup transformer issue * chore: prettier
2 parents 3660477 + dbf547c commit b99bd26

7 files changed

Lines changed: 730 additions & 578 deletions

File tree

apps/website/docs/guide/05-official-plugins/10-commandkit-workflow.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ export const chatInput: ChatInputCommand = async (ctx) => {
117117
};
118118
```
119119

120+
## Using custom Worlds
121+
122+
You can use any world providers from
123+
[useworkflow.dev/worlds](https://useworkflow.dev/worlds) or create
124+
your own custom world. Refer to the
125+
[Building a World](https://useworkflow.dev/docs/deploying/building-a-world)
126+
documentation for more details.
127+
120128
## Project structure
121129

122130
Organize your workflows and steps in a clear structure:

packages/workflow/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ export const chatInput: ChatInputCommand = async (ctx) => {
6767
}
6868
```
6969

70+
## Using custom Worlds
71+
72+
You can use any world providers from [useworkflow.dev/worlds](https://useworkflow.dev/worlds) or create your own custom world. Refer to the [Building a World](https://useworkflow.dev/docs/deploying/building-a-world) documentation for more details.
73+
7074
## Documentation
7175
https://commandkit.dev/docs/next/api-reference/workflow
7276

packages/workflow/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"dependencies": {
5050
"@hono/node-server": "^1.19.6",
5151
"@workflow/builders": "catalog:workflow",
52+
"@workflow/rollup": "catalog:workflow",
5253
"hono": "^4.10.4"
5354
}
5455
}

packages/workflow/src/compiler-plugin.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,19 @@ import {
77
TransformedResult,
88
} from 'commandkit';
99
import { LocalBuilder } from './builder.js';
10-
import { workflowRollupPlugin } from 'workflow/rollup';
10+
import { workflowTransformPlugin as workflowRollupPlugin } from '@workflow/rollup';
11+
12+
const USE_WORKFLOW_DIRECTIVE = 'use workflow';
13+
const USE_STEP_DIRECTIVE = 'use step';
1114

1215
export interface WorkflowCompilerPluginOptions {}
1316

17+
const shouldTransform = (code: string): boolean => {
18+
return (
19+
code.includes(USE_WORKFLOW_DIRECTIVE) || code.includes(USE_STEP_DIRECTIVE)
20+
);
21+
};
22+
1423
export class WorkflowCompilerPlugin extends CompilerPlugin<WorkflowCompilerPluginOptions> {
1524
public readonly name = 'WorkflowCompilerPlugin';
1625
private builder: LocalBuilder | null = null;
@@ -33,7 +42,19 @@ export class WorkflowCompilerPlugin extends CompilerPlugin<WorkflowCompilerPlugi
3342
public async transform(
3443
params: PluginTransformParameters,
3544
): Promise<MaybeFalsey<TransformedResult>> {
36-
if (!/(use workflow)|(use step)/.test(params.code)) return;
37-
return this.workflowRollupPlugin?.transform(params.code, params.id);
45+
if (!shouldTransform(params.code)) return;
46+
if (typeof this.workflowRollupPlugin?.transform !== 'function') return;
47+
// @ts-ignore mismatched types
48+
const result = await this.workflowRollupPlugin.transform(
49+
params.code,
50+
params.id,
51+
);
52+
53+
if (!result) return null;
54+
if (typeof result === 'string') return { code: result };
55+
return {
56+
code: result.code,
57+
map: typeof result.map === 'string' ? result.map : null,
58+
};
3859
}
3960
}

packages/workflow/src/handler.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable */
22
// @ts-nocheck
33
import { Hono } from 'hono';
4-
import { serve } from '@hono/node-server';
4+
import { serve as nodeServe } from '@hono/node-server';
55
import { POST as WebhookPOST } from '{{webhookPath}}';
66
import { POST as StepPOST } from '{{stepsPath}}';
77
import { POST as FlowPOST } from '{{workflowPath}}';
@@ -24,7 +24,16 @@ if (!port || isNaN(Number(port))) {
2424
);
2525
}
2626

27-
serve({
28-
fetch: app.fetch,
29-
port: Number(port),
30-
});
27+
if (typeof Deno !== 'undefined') {
28+
Deno.serve({ port: Number(port) }, app.fetch);
29+
} else if (typeof Bun !== 'undefined') {
30+
Bun.serve({
31+
fetch: app.fetch,
32+
port: Number(port),
33+
});
34+
} else {
35+
nodeServe({
36+
fetch: app.fetch,
37+
port: Number(port),
38+
});
39+
}

0 commit comments

Comments
 (0)