init
This commit is contained in:
29
conf/src/flows/example1.ts
Normal file
29
conf/src/flows/example1.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { createWorkflowChain, andThen } from '@xui/xbuild'
|
||||
import z from 'zod'
|
||||
import { exampleService } from '../beans/exampleService'
|
||||
|
||||
const example1 = createWorkflowChain({
|
||||
id: 'example1',
|
||||
name: 'Example1 Workflow',
|
||||
description: '一个简单的示例工作流,用于调用 exampleService 的 processServiceTask 方法。',
|
||||
input: z.object({ name: z.string() }),
|
||||
result: z.object({ greeting: z.string() }),
|
||||
})
|
||||
.andTask({
|
||||
id: 'processServiceTask',
|
||||
task: exampleService.processServiceTask,
|
||||
execute: ({ data }) => {
|
||||
return { taskName: `Hello, ${data.name}!`, description: `Hello, ${data.name}!` }
|
||||
},
|
||||
})
|
||||
.andThen({
|
||||
id: 'final',
|
||||
execute: ({ data , getStepResult}) => {
|
||||
const result = getStepResult('processServiceTask')
|
||||
console.log('result', result)
|
||||
return { greeting: `status=${data.status} mesasge=${data.message} !` }
|
||||
},
|
||||
})
|
||||
.toWorkflow()
|
||||
|
||||
export default example1
|
||||
43
conf/src/flows/example2.ts
Normal file
43
conf/src/flows/example2.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { createWorkflowChain, andThen } from '@xui/xbuild'
|
||||
import z from 'zod'
|
||||
import { exampleService } from '../beans/exampleService'
|
||||
|
||||
const example2 = createWorkflowChain({
|
||||
id: 'example2',
|
||||
name: 'Example2 Workflow',
|
||||
description: '一个简单的示例工作流,用于调用 exampleService 的 processServiceTask 方法。',
|
||||
input: z.object({ name: z.string() }),
|
||||
result: z.object({ greeting: z.string() }),
|
||||
})
|
||||
.andWhen({
|
||||
id: "conditional",
|
||||
condition: ({ data }) => data.name === 'wk',
|
||||
step: andThen({
|
||||
id: 'isConditionalThen',
|
||||
// task: exampleService.processOutboundTask,
|
||||
execute: ({ data }) => {
|
||||
return { taskName: '获取用户信息', description: 'TODO: 外呼, 获取用户详细信息' }
|
||||
},
|
||||
}),
|
||||
})
|
||||
.andTask({
|
||||
id: 'processServiceTask',
|
||||
task: exampleService.processServiceTask,
|
||||
execute: ({ data }) => {
|
||||
if ('taskName' in data) {
|
||||
return { taskName: data.taskName, description: data.description }
|
||||
}
|
||||
return { taskName: `Hello, ${data.name}!`, description: `Hello, ${data.name}!` }
|
||||
},
|
||||
})
|
||||
.andThen({
|
||||
id: 'final',
|
||||
execute: ({ data, getStepResult }) => {
|
||||
const result = getStepResult('processServiceTask')
|
||||
console.log('result', result)
|
||||
return { greeting: `status=${data.status} mesasge=${data.message} !` }
|
||||
},
|
||||
})
|
||||
.toWorkflow()
|
||||
|
||||
export default example2
|
||||
2
conf/src/tests/run_example1.ts
Normal file
2
conf/src/tests/run_example1.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
import workflow from '../flows/example1'
|
||||
await workflow.runTest({ name: 'wk' }, { verbose: true })
|
||||
10
conf/src/tests/write_example1.ts
Normal file
10
conf/src/tests/write_example1.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import fs from 'fs'
|
||||
import workflow from '../flows/example2'
|
||||
import { XBUILD_DIR } from '@xui/xbuild'
|
||||
|
||||
const element = workflow.buildElement()
|
||||
// console.log(JSON.stringify(element, null, 2))
|
||||
// write json to file example1.json
|
||||
const filePath = `${XBUILD_DIR}/cache/${element.id}.json`
|
||||
fs.writeFileSync(filePath, JSON.stringify(element, null, 2))
|
||||
console.log(`Written to ${filePath}`)
|
||||
Reference in New Issue
Block a user