Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ export const chatInput: ChatInputCommand = async (ctx) => {
};
```

## Using custom Worlds

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.

## Project structure

Organize your workflows and steps in a clear structure:
Expand Down
4 changes: 4 additions & 0 deletions packages/workflow/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ export const chatInput: ChatInputCommand = async (ctx) => {
}
```

## Using custom Worlds

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.

## Documentation
https://commandkit.dev/docs/next/api-reference/workflow

1 change: 1 addition & 0 deletions packages/workflow/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"dependencies": {
"@hono/node-server": "^1.19.6",
"@workflow/builders": "catalog:workflow",
"@workflow/rollup": "catalog:workflow",
"hono": "^4.10.4"
}
}
27 changes: 24 additions & 3 deletions packages/workflow/src/compiler-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,19 @@ import {
TransformedResult,
} from 'commandkit';
import { LocalBuilder } from './builder.js';
import { workflowRollupPlugin } from 'workflow/rollup';
import { workflowTransformPlugin as workflowRollupPlugin } from '@workflow/rollup';

const USE_WORKFLOW_DIRECTIVE = 'use workflow';
const USE_STEP_DIRECTIVE = 'use step';

export interface WorkflowCompilerPluginOptions {}

const shouldTransform = (code: string): boolean => {
return (
code.includes(USE_WORKFLOW_DIRECTIVE) || code.includes(USE_STEP_DIRECTIVE)
);
};

export class WorkflowCompilerPlugin extends CompilerPlugin<WorkflowCompilerPluginOptions> {
public readonly name = 'WorkflowCompilerPlugin';
private builder: LocalBuilder | null = null;
Expand All @@ -33,7 +42,19 @@ export class WorkflowCompilerPlugin extends CompilerPlugin<WorkflowCompilerPlugi
public async transform(
params: PluginTransformParameters,
): Promise<MaybeFalsey<TransformedResult>> {
if (!/(use workflow)|(use step)/.test(params.code)) return;
return this.workflowRollupPlugin?.transform(params.code, params.id);
if (!shouldTransform(params.code)) return;
if (typeof this.workflowRollupPlugin?.transform !== 'function') return;
// @ts-ignore mismatched types
const result = await this.workflowRollupPlugin.transform(
params.code,
params.id,
);

if (!result) return null;
if (typeof result === 'string') return { code: result };
return {
code: result.code,
map: typeof result.map === 'string' ? result.map : null,
};
}
}
19 changes: 14 additions & 5 deletions packages/workflow/src/handler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable */
// @ts-nocheck
import { Hono } from 'hono';
import { serve } from '@hono/node-server';
import { serve as nodeServe } from '@hono/node-server';
import { POST as WebhookPOST } from '{{webhookPath}}';
import { POST as StepPOST } from '{{stepsPath}}';
import { POST as FlowPOST } from '{{workflowPath}}';
Expand All @@ -24,7 +24,16 @@ if (!port || isNaN(Number(port))) {
);
}

serve({
fetch: app.fetch,
port: Number(port),
});
if (typeof Deno !== 'undefined') {
Deno.serve({ port: Number(port) }, app.fetch);
} else if (typeof Bun !== 'undefined') {
Bun.serve({
fetch: app.fetch,
port: Number(port),
});
} else {
nodeServe({
fetch: app.fetch,
port: Number(port),
});
}
Loading