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
5 changes: 5 additions & 0 deletions .changeset/twenty-gifts-win.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@workflow/swc-plugin": patch
---

Add support for step functions defined as object properties
456 changes: 445 additions & 11 deletions packages/swc-plugin-workflow/transform/src/lib.rs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import * as z from 'zod';
import { tool } from 'ai';

export const weatherTool = tool({
description: 'Get the weather in a location',
inputSchema: z.object({
location: z.string().describe('The location to get the weather for'),
}),
execute: async ({ location }) => {
"use step";
return {
location,
temperature: 72 + Math.floor(Math.random() * 21) - 10,
};
},
});

export const timeTool = tool({
description: 'Get the current time',
execute: async function timeToolImpl () {
"use step";
return {
time: new Date().toISOString(),
};
},
});

export const weatherTool2 = tool({
description: 'Get the weather in a location',
inputSchema: z.object({
location: z.string().describe('The location to get the weather for'),
}),
async execute({ location }) {
"use step";
return {
location,
temperature: 72 + Math.floor(Math.random() * 21) - 10,
};
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import * as z from 'zod';
import { tool } from 'ai';
export const weatherTool = tool({
description: 'Get the weather in a location',
inputSchema: z.object({
location: z.string().describe('The location to get the weather for')
}),
execute: async ({ location })=>{
return {
location,
temperature: 72 + Math.floor(Math.random() * 21) - 10
};
}
});
export const timeTool = tool({
description: 'Get the current time',
execute: async function timeToolImpl() {
return {
time: new Date().toISOString()
};
}
});
export const weatherTool2 = tool({
description: 'Get the weather in a location',
inputSchema: z.object({
location: z.string().describe('The location to get the weather for')
}),
async execute ({ location }) {
return {
location,
temperature: 72 + Math.floor(Math.random() * 21) - 10
};
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { registerStepFunction } from "workflow/internal/private";
import * as z from 'zod';
import { tool } from 'ai';
/**__internal_workflows{"steps":{"input.js":{"timeTool/execute":{"stepId":"step//input.js//timeTool/execute"},"weatherTool/execute":{"stepId":"step//input.js//weatherTool/execute"},"weatherTool2/execute":{"stepId":"step//input.js//weatherTool2/execute"}}}}*/;
var weatherTool2$execute = async ({ location })=>{
return {
location,
temperature: 72 + Math.floor(Math.random() * 21) - 10
};
};
var timeTool$execute = async ()=>{
return {
time: new Date().toISOString()
};
};
var weatherTool$execute = async ({ location })=>{
return {
location,
temperature: 72 + Math.floor(Math.random() * 21) - 10
};
};
export const weatherTool = tool({
description: 'Get the weather in a location',
inputSchema: z.object({
location: z.string().describe('The location to get the weather for')
}),
execute: weatherTool$execute
});
export const timeTool = tool({
description: 'Get the current time',
execute: timeTool$execute
});
export const weatherTool2 = tool({
description: 'Get the weather in a location',
inputSchema: z.object({
location: z.string().describe('The location to get the weather for')
}),
execute: weatherTool2$execute
});
registerStepFunction("step//input.js//weatherTool/execute", weatherTool$execute);
registerStepFunction("step//input.js//timeTool/execute", timeTool$execute);
registerStepFunction("step//input.js//weatherTool2/execute", weatherTool2$execute);
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import * as z from 'zod';
import { tool } from 'ai';
/**__internal_workflows{"steps":{"input.js":{"timeTool/execute":{"stepId":"step//input.js//timeTool/execute"},"weatherTool/execute":{"stepId":"step//input.js//weatherTool/execute"},"weatherTool2/execute":{"stepId":"step//input.js//weatherTool2/execute"}}}}*/;
export const weatherTool = tool({
description: 'Get the weather in a location',
inputSchema: z.object({
location: z.string().describe('The location to get the weather for')
}),
execute: globalThis[Symbol.for("WORKFLOW_USE_STEP")]("step//input.js//weatherTool/execute")
});
export const timeTool = tool({
description: 'Get the current time',
execute: globalThis[Symbol.for("WORKFLOW_USE_STEP")]("step//input.js//timeTool/execute")
});
export const weatherTool2 = tool({
description: 'Get the weather in a location',
inputSchema: z.object({
location: z.string().describe('The location to get the weather for')
}),
execute: globalThis[Symbol.for("WORKFLOW_USE_STEP")]("step//input.js//weatherTool2/execute")
});
Loading