Skip to content

Commit 2761b92

Browse files
authored
refactor: rename input parameters to flowInput and deps for clarity (#557)
# Rename input parameters in step handlers for better clarity This PR renames the input parameters in step handlers to improve clarity and better reflect their purpose: - Root steps (no dependencies) now use `flowInput` instead of `input.run` to directly access flow input - Dependent steps now use `deps` instead of `input` to access outputs from dependency steps - Context parameter is now consistently named `ctx` where used These changes make the code more intuitive by: 1. Clearly distinguishing between flow input and dependency outputs 2. Using parameter names that better reflect their content 3. Maintaining consistent naming conventions throughout the codebase The changes affect example code in the documentation as well as actual implementation code, ensuring consistency across the entire project.
1 parent 01687ab commit 2761b92

22 files changed

Lines changed: 189 additions & 189 deletions

File tree

apps/demo/src/lib/data/flow-code.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,50 +26,50 @@ export const FLOW_SECTIONS: Record<string, CodeSection> = {
2626
fetchArticle: {
2727
code: ` .step(
2828
{ slug: 'fetchArticle' },
29-
(input) => scrapeUrl(input.run.url)
29+
(flowInput) => scrapeUrl(flowInput.url)
3030
)`,
3131
mobileCode: ` .step(
3232
{ slug: 'fetchArticle' },
33-
(input) => scrapeUrl(
34-
input.run.url
33+
(flowInput) => scrapeUrl(
34+
flowInput.url
3535
)
3636
)`
3737
},
3838
summarize: {
3939
code: ` .step(
4040
{ slug: 'summarize', dependsOn: ['fetchArticle'] },
41-
(input) => summarize(schema, input.fetchArticle.content)
41+
(deps) => summarize(schema, deps.fetchArticle.content)
4242
)`,
4343
mobileCode: ` .step(
4444
{
4545
slug: 'summarize',
4646
dependsOn: ['fetchArticle']
4747
},
48-
(input) => summarize(
48+
(deps) => summarize(
4949
schema,
50-
input.fetchArticle.content
50+
deps.fetchArticle.content
5151
)
5252
)`
5353
},
5454
extractKeywords: {
5555
code: ` .step(
5656
{ slug: 'extractKeywords', dependsOn: ['fetchArticle'] },
57-
(input) => extractKeywords(input.fetchArticle.content)
57+
(deps) => extractKeywords(deps.fetchArticle.content)
5858
)`,
5959
mobileCode: ` .step(
6060
{
6161
slug: 'extractKeywords',
6262
dependsOn: ['fetchArticle']
6363
},
64-
(input) => extractKeywords(
65-
input.fetchArticle.content
64+
(deps) => extractKeywords(
65+
deps.fetchArticle.content
6666
)
6767
)`
6868
},
6969
publish: {
7070
code: ` .step(
7171
{ slug: 'publish', dependsOn: ['summarize', 'extractKeywords'] },
72-
(input) => publishArticle(input.summarize, input.extractKeywords)
72+
(deps) => publishArticle(deps.summarize, deps.extractKeywords)
7373
);`,
7474
mobileCode: ` .step(
7575
{
@@ -79,9 +79,9 @@ export const FLOW_SECTIONS: Record<string, CodeSection> = {
7979
'extractKeywords'
8080
]
8181
},
82-
(input) => publishArticle(
83-
input.summarize,
84-
input.extractKeywords
82+
(deps) => publishArticle(
83+
deps.summarize,
84+
deps.extractKeywords
8585
)
8686
);`
8787
}

apps/demo/supabase/functions/article_flow_worker/article_flow.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ export default new Flow<{ url: string }>({
1717
baseDelay: 1,
1818
maxAttempts: 2
1919
})
20-
.step({ slug: 'fetchArticle' }, async (input) => {
20+
.step({ slug: 'fetchArticle' }, async (flowInput) => {
2121
await sleep(SLEEP_MS);
2222
const startTime = Date.now();
23-
const result = await fetchArticle(input.run.url);
23+
const result = await fetchArticle(flowInput.url);
2424
const durationMs = Date.now() - startTime;
2525
return {
2626
...result,
@@ -30,16 +30,12 @@ export default new Flow<{ url: string }>({
3030
}
3131
};
3232
})
33-
.step({ slug: 'summarize', dependsOn: ['fetchArticle'], baseDelay: 1 }, async (input) =>
34-
summarizeArticle(input.fetchArticle.content)
33+
.step({ slug: 'summarize', dependsOn: ['fetchArticle'], baseDelay: 1 }, async (deps) =>
34+
summarizeArticle(deps.fetchArticle.content)
3535
)
36-
.step({ slug: 'extractKeywords', dependsOn: ['fetchArticle'] }, async (input) =>
37-
extractKeywords(input.fetchArticle.content)
36+
.step({ slug: 'extractKeywords', dependsOn: ['fetchArticle'] }, async (deps) =>
37+
extractKeywords(deps.fetchArticle.content)
3838
)
39-
.step({ slug: 'publish', dependsOn: ['summarize', 'extractKeywords'] }, async (input) =>
40-
publishArticle(
41-
input.summarize.summary,
42-
input.summarize.sentiment,
43-
input.extractKeywords.keywords
44-
)
39+
.step({ slug: 'publish', dependsOn: ['summarize', 'extractKeywords'] }, async (deps) =>
40+
publishArticle(deps.summarize.summary, deps.summarize.sentiment, deps.extractKeywords.keywords)
4541
);

pkgs/cli/__tests__/commands/install/create-flows-directory.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ describe('createFlowsDirectory', () => {
9292
// Second step should depend on first
9393
expect(greetUserContent).toContain("dependsOn: ['fullName']");
9494
// Second step should access result from first step
95-
expect(greetUserContent).toContain('input.fullName');
95+
expect(greetUserContent).toContain('deps.fullName');
9696
});
9797

9898
it('should not create files when they already exist', async () => {

pkgs/cli/examples/analyze_website.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ const AnalyzeWebsite = new Flow<WebsiteAnalysisInput>({
1414
timeout: 10,
1515
})
1616
// First step: scrape the website
17-
.step({ slug: 'website' }, async (input) => {
18-
console.log(`Scraping website: ${input.run.url}`);
17+
.step({ slug: 'website' }, async (flowInput) => {
18+
console.log(`Scraping website: ${flowInput.url}`);
1919
// In a real implementation, this would call an actual web scraper
2020
return {
21-
content: `Sample content from ${input.run.url}`,
21+
content: `Sample content from ${flowInput.url}`,
2222
title: 'Sample Website Title',
2323
links: ['https://example.com/page1', 'https://example.com/page2'],
2424
};
@@ -31,8 +31,8 @@ const AnalyzeWebsite = new Flow<WebsiteAnalysisInput>({
3131
timeout: 30,
3232
maxAttempts: 5,
3333
},
34-
async (input) => {
35-
console.log(`Analyzing sentiment for: ${input.website.title}`);
34+
async (deps) => {
35+
console.log(`Analyzing sentiment for: ${deps.website.title}`);
3636
// In a real implementation, this would call a sentiment analysis service
3737
return {
3838
score: 0.75,
@@ -42,19 +42,19 @@ const AnalyzeWebsite = new Flow<WebsiteAnalysisInput>({
4242
}
4343
)
4444
// Third step: generate summary (depends on website step)
45-
.step({ slug: 'summary', dependsOn: ['website'] }, async (input) => {
46-
console.log(`Generating summary for: ${input.website.title}`);
45+
.step({ slug: 'summary', dependsOn: ['website'] }, async (deps) => {
46+
console.log(`Generating summary for: ${deps.website.title}`);
4747
// In a real implementation, this might use an AI service
4848
return {
49-
aiSummary: `This is a summary of ${input.website.title}`,
50-
wordCount: input.website.content.split(' ').length,
49+
aiSummary: `This is a summary of ${deps.website.title}`,
50+
wordCount: deps.website.content.split(' ').length,
5151
};
5252
})
5353
// Fourth step: save results to database (depends on sentiment and summary)
5454
.step(
5555
{ slug: 'saveToDb', dependsOn: ['sentiment', 'summary'] },
56-
async (input) => {
57-
console.log(`Saving results to database for: ${input.run.url}`);
56+
async (_deps, ctx) => {
57+
console.log(`Saving results to database for: ${ctx.flowInput.url}`);
5858
// In a real implementation, this would save to a database
5959
return {
6060
status: 'success',

pkgs/cli/src/commands/install/create-flows-directory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ export const GreetUser = new Flow<Input>({
2121
})
2222
.step(
2323
{ slug: 'fullName' },
24-
(input) => \`\${input.run.firstName} \${input.run.lastName}\`
24+
(flowInput) => \`\${flowInput.firstName} \${flowInput.lastName}\`
2525
)
2626
.step(
2727
{ slug: 'greeting', dependsOn: ['fullName'] },
28-
(input) => \`Hello, \${input.fullName}!\`
28+
(deps) => \`Hello, \${deps.fullName}!\`
2929
);
3030
`;
3131

pkgs/cli/supabase/flows/test_flow_e2e.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ import { Flow } from '@pgflow/dsl';
44
export const TestFlowE2E = new Flow<{ value: string }>({
55
slug: 'test_flow_e2e',
66
maxAttempts: 3,
7-
}).step({ slug: 'step1' }, async (input) => ({
8-
result: `processed: ${input.run.value}`,
7+
}).step({ slug: 'step1' }, async (flowInput) => ({
8+
result: `processed: ${flowInput.value}`,
99
}));

pkgs/client/__tests__/e2e/full-stack-dsl.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,20 @@ describe('Full Stack DSL Integration', () => {
1919
const SimpleFlow = new Flow<{ url: string }>({
2020
slug: 'simple_dag_test',
2121
})
22-
.step({ slug: 'fetch' }, async (_input) => ({
22+
.step({ slug: 'fetch' }, async (_flowInput) => ({
2323
data: 'fetched content',
2424
status: 200,
2525
items: 10,
2626
}))
27-
.step({ slug: 'process', dependsOn: ['fetch'] }, async (input) => ({
27+
.step({ slug: 'process', dependsOn: ['fetch'] }, async (deps) => ({
2828
processed_data: 'cleaned and validated',
29-
item_count: input.fetch.items * 2,
29+
item_count: deps.fetch.items * 2,
3030
metadata: { stage: 'processed' },
3131
}))
32-
.step({ slug: 'save', dependsOn: ['process'] }, async (input) => ({
32+
.step({ slug: 'save', dependsOn: ['process'] }, async (deps) => ({
3333
saved: true,
3434
record_id: 'rec_12345',
35-
final_count: input.process.item_count,
35+
final_count: deps.process.item_count,
3636
}));
3737

3838
// Clean up flow data to ensure clean state
@@ -95,7 +95,7 @@ describe('Full Stack DSL Integration', () => {
9595
let tasks = await readAndStart(sql, sqlClient, SimpleFlow.slug, 1, 5);
9696
expect(tasks).toHaveLength(1);
9797
expect(tasks[0].step_slug).toBe('fetch');
98-
expect(tasks[0].input.run).toEqual(input);
98+
expect(tasks[0].flow_input).toEqual(input);
9999

100100
const fetchOutput = { data: 'fetched content', status: 200, items: 10 };
101101
await sqlClient.completeTask(tasks[0], fetchOutput);
@@ -111,7 +111,7 @@ describe('Full Stack DSL Integration', () => {
111111
tasks = await readAndStart(sql, sqlClient, SimpleFlow.slug, 1, 5);
112112
expect(tasks).toHaveLength(1);
113113
expect(tasks[0].step_slug).toBe('process');
114-
expect(tasks[0].input.run).toEqual(input);
114+
expect(tasks[0].flow_input).toEqual(input);
115115
expect(tasks[0].input.fetch).toEqual(fetchOutput); // Critical: dependency output included
116116

117117
const processOutput = {

pkgs/client/__tests__/e2e/happy-path-e2e.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ describe('Happy Path E2E Integration', () => {
7373
let tasks = await readAndStart(sql, sqlClient, testFlow.slug, 1, 5);
7474
expect(tasks).toHaveLength(1);
7575
expect(tasks[0].step_slug).toBe('fetch');
76-
expect(tasks[0].input.run).toEqual(input);
76+
expect(tasks[0].flow_input).toEqual(input);
7777

7878
const fetchOutput = { data: 'fetched content', status: 200, items: 10 };
7979
await sqlClient.completeTask(tasks[0], fetchOutput);
@@ -88,7 +88,7 @@ describe('Happy Path E2E Integration', () => {
8888
tasks = await readAndStart(sql, sqlClient, testFlow.slug, 1, 5);
8989
expect(tasks).toHaveLength(1);
9090
expect(tasks[0].step_slug).toBe('process');
91-
expect(tasks[0].input.run).toEqual(input);
91+
expect(tasks[0].flow_input).toEqual(input);
9292
expect(tasks[0].input.fetch).toEqual(fetchOutput);
9393

9494
const processOutput = {

pkgs/client/__tests__/e2e/real-flow-execution.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe('Real Flow Execution', () => {
4141
const tasks = await readAndStart(sql, sqlClient, testFlow.slug, 1, 5);
4242

4343
expect(tasks).toHaveLength(1);
44-
expect(tasks[0].input.run).toEqual(input);
44+
expect(tasks[0].flow_input).toEqual(input);
4545

4646
// Complete task with complex nested output to verify JSON parsing
4747
const taskOutput = {

pkgs/dsl/tests/context-inference.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ interface ExplicitContext {
7777
}
7878

7979
const ExplicitFlow = new Flow<{ userId: string }, ExplicitContext>({ slug: 'explicit-flow' })
80-
.step({ slug: 'get-user' }, async (input, context) => {
80+
.step({ slug: 'get-user' }, async (flowInput, context) => {
8181
// All ExplicitContext properties should be available
82-
const user = await context.sql.query(`SELECT * FROM users WHERE id = ${input.run.userId}`);
83-
await context.cache.set(`user:${input.run.userId}`, JSON.stringify(user));
82+
const user = await context.sql.query(`SELECT * FROM users WHERE id = ${flowInput.userId}`);
83+
await context.cache.set(`user:${flowInput.userId}`, JSON.stringify(user));
8484
context.pubsub.publish('user-fetched');
8585
return user;
8686
});
@@ -95,9 +95,9 @@ const _explicitTest: ExplicitFlowContext = {
9595

9696
// Test 5: Mixed approach - explicit base with inferred additions
9797
const MixedFlow = new Flow<{ id: string }, { sql: TestSql }>({ slug: 'mixed-flow' })
98-
.step({ slug: 'query' }, async (input, context) => {
98+
.step({ slug: 'query' }, async (flowInput, context) => {
9999
// Has sql from explicit type
100-
return await context.sql.query(`SELECT * FROM items WHERE id = ${input.run.id}`);
100+
return await context.sql.query(`SELECT * FROM items WHERE id = ${flowInput.id}`);
101101
})
102102
.step({ slug: 'enhance' }, async (input, context: Context & { sql: TestSql, ai: { generate: () => string } }) => {
103103
// Adds ai requirement via inference

0 commit comments

Comments
 (0)