-
Notifications
You must be signed in to change notification settings - Fork 87
feat(api): feat: add async workflow execution and history tracking #115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughThe changes enhance asynchronous workflow execution across the codebase. A JSON file now marks the update as "minor" and details the new async execution and history tracking features in the Changes
Sequence Diagram(s)sequenceDiagram
participant U as User
participant AW as asyncWorkflow
participant C as Client API
U->>AW: Invoke asyncWorkflow()
AW->>C: Request workflow run creation (async)
C-->>AW: Return workflow details
loop Poll for workflow status
AW->>C: Fetch execution history
C-->>AW: Return current history/status
end
alt Status ≠ Running
AW->>AW: Break loop and conclude execution
else Status Running
AW->>AW: Wait 1 second and continue polling
end
AW->>AW: Handle any errors encountered
Possibly related PRs
Suggested reviewers
Poem
✨ Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (4)
examples/coze-js-node/src/workflow.ts (1)
51-77: Add error handling for workflow creation.The workflow creation call lacks error handling.
Consider adding try-catch:
async function asyncWorkflow() { assert(botId, 'botId is required'); assert(workflowId, 'workflowId is required'); + try { const workflow = await client.workflows.runs.create({ workflow_id: workflowId, parameters: { input: 'Hello World' }, is_async: true, }); console.log('workflow', workflow); + } catch (error) { + console.error('Error creating workflow:', error); + throw error; + } // ... rest of the function }packages/coze-js/test/resources/workflows.spec.ts (1)
105-120: Add test cases for error scenarios.The current test suite only covers the success case. Consider adding tests for:
- Invalid workflow ID
- Invalid execute ID
- API error responses
- Network failures
Example additional test:
it('should handle API errors when getting workflow history', async () => { const errorResponse = { status: 404, message: 'Workflow not found' }; vi.spyOn(client, 'get').mockRejectedValue(errorResponse); await expect( workflows.runs.history('invalid-id', 'run-id') ).rejects.toEqual(errorResponse); expect(client.get).toHaveBeenCalledWith( '/v1/workflows/invalid-id/run_histories/run-id', undefined, false, undefined ); });packages/coze-js/src/resources/workflows/runs/runs.ts (2)
97-115: Add input validation and improve JSDoc.The history method could benefit from input validation and improved documentation.
Consider these improvements:
/** * Get the workflow run history | 工作流异步运行后,查看执行结果 * @docs zh: https://www.coze.cn/open/docs/developer_guides/workflow_history * @param workflowId - Required The ID of the workflow. | 必选 工作流 ID。 * @param executeId - Required The ID of the workflow execution. | 必选 工作流执行 ID。 + * @throws {CozeError} When workflowId or executeId is empty * @returns WorkflowExecuteHistory[] | 工作流执行历史 */ async history( workflowId: string, executeId: string, options?: RequestOptions, ) { + if (!workflowId?.trim()) { + throw new CozeError('workflowId is required'); + } + if (!executeId?.trim()) { + throw new CozeError('executeId is required'); + } const apiUrl = `/v1/workflows/${workflowId}/run_histories/${executeId}`; const response = await this._client.get< undefined, { data: WorkflowExecuteHistory[] } >(apiUrl, undefined, false, options); return response.data; }
215-231: Add JSDoc comments to WorkflowExecuteHistory interface.The interface lacks documentation for its properties.
Consider adding JSDoc comments:
/** * Represents the execution history of a workflow */ export interface WorkflowExecuteHistory { /** Unique identifier for the workflow execution */ execute_id: string; /** Current status of the workflow execution */ execute_status: 'Success' | 'Running' | 'Fail'; /** ID of the bot that executed the workflow */ bot_id: string; /** ID of the connector used in the workflow */ connector_id: string; /** User ID associated with the connector */ connector_uid: string; /** Mode in which the workflow was run */ run_mode: 0 | 1 | 2; /** Log identifier for tracing */ logid: string; /** Timestamp when the execution was created */ create_time: number; /** Timestamp when the execution was last updated */ update_time: number; /** Output produced by the workflow */ output: string; /** Token used for the execution */ token: string; /** Cost associated with the execution */ cost: string; /** Error code if execution failed */ error_code: string; /** Error message if execution failed */ error_message: string; /** URL for debugging information */ debug_url: string; }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
common/changes/@coze/api/fix-workflow_2025-02-24-12-00.json(1 hunks)examples/coze-js-node/src/workflow.ts(1 hunks)packages/coze-js/src/resources/workflows/runs/runs.ts(3 hunks)packages/coze-js/test/resources/workflows.spec.ts(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Node.js v20 (ubuntu-latest)
🔇 Additional comments (1)
common/changes/@coze/api/fix-workflow_2025-02-24-12-00.json (1)
1-11: LGTM! Change log accurately documents the feature.The change log correctly captures the feature addition and uses appropriate version bump (minor) for new functionality.
Codecov ReportAll modified and coverable lines are covered by tests ✅ ❌ Your project status has failed because the head coverage (0.00%) is below the target coverage (90.00%). You can increase the head coverage or adjust the target coverage. @@ Coverage Diff @@
## main #115 +/- ##
=========================================
- Coverage 91.82% 0 -91.83%
=========================================
Files 117 0 -117
Lines 5469 0 -5469
Branches 1106 0 -1106
=========================================
- Hits 5022 0 -5022
+ Misses 447 0 -447
|
) Co-authored-by: shenxiaojie.316 <[email protected]>
Summary by CodeRabbit
New Features
Tests