-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feat: Knowledge workflow save interface #4416
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -303,6 +303,21 @@ const getWorkflowAction: ( | |
| return get(`${prefix}/${knowledge_id}/action/${knowledge_action_id}`, {}, loading) | ||
| } | ||
|
|
||
| /** | ||
| * 保存知识库工作流 | ||
| * @param knowledge_id | ||
| * @param data | ||
| * @param loading | ||
| * @returns | ||
| */ | ||
| const putKnowledgeWorkflow: ( | ||
| knowledge_id: string, | ||
| data: any, | ||
| loading?: Ref<boolean>, | ||
| ) => Promise<Result<any>> = (knowledge_id, data, loading) => { | ||
| return put(`${prefix}/${knowledge_id}/workflow`, data, undefined, loading) | ||
| } | ||
|
|
||
| const publish: (knowledge_id: string, loading?: Ref<boolean>) => Promise<Result<any>> = ( | ||
| knowledge_id: string, | ||
| loading, | ||
|
|
@@ -342,6 +357,7 @@ export default { | |
| workflowAction, | ||
| getWorkflowAction, | ||
| publish, | ||
| putKnowledgeWorkflow, | ||
| listKnowledgeVersion | ||
| } as { | ||
| [key: string]: any | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code provided is a TypeScript module with three functions related to working with knowledge workflows in an enterprise system. There are no significant irregularities or problems with the code itself, but here are some suggestions for improvements:
Here’s an improved version of the code with these suggestions applied: // ... other imports ...
// Save Knowledge Workflow
const putKnowledgeWorkflow: (
knowledgeId: string,
data: any,
loading?: Ref<boolean>,
) => Promise<Result<any>> = async (knowledgeId, data, loading?) => {
try {
return await post(`${prefix}/${knowledgeId}/workflow`, data, { loading })
} catch (error) {
throw new Error('Error saving knowledge flow.')
}
}
export default {
// ... other functions ...
/**
* Update Workflows
* @param knowledgeId The unique identifier for the knowledge item.
* @param data The updated workflow information.
* @param loading A ref object indicating whether the component is currently in loading state.
* @returns A Promise that resolves to the response data resulting from the update request.
*/
updateWorkflows: putKnowledgeWorkflow,
// ... other functions ...
} as {
[key: string]: ((...args: any) => Promise<any>) | Record<string, any>
} satisfies Module<ReturnType<typeof import('@/modules/base').default>>;Key Changes:
These changes should help enhance clarity and maintainability of the codebase. |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -361,6 +361,21 @@ const getWorkflowAction: ( | |
| return get(`${prefix}/${knowledge_id}/action/${knowledge_action_id}`, {}, loading) | ||
| } | ||
|
|
||
| /** | ||
| * 保存知识库工作流 | ||
| * @param knowledge_id | ||
| * @param data | ||
| * @param loading | ||
| * @returns | ||
| */ | ||
| const putKnowledgeWorkflow: ( | ||
| knowledge_id: string, | ||
| data: any, | ||
| loading?: Ref<boolean>, | ||
| ) => Promise<Result<any>> = (knowledge_id, data, loading) => { | ||
| return put(`${prefix}/${knowledge_id}/workflow`, data, undefined, loading) | ||
| } | ||
|
|
||
| const publish: (knowledge_id: string, loading?: Ref<boolean>) => Promise<Result<any>> = ( | ||
| knowledge_id: string, | ||
| loading, | ||
|
|
@@ -404,6 +419,7 @@ export default { | |
| getKnowledgeWorkflowDatasourceDetails, | ||
| workflowAction, | ||
| publish, | ||
| putKnowledgeWorkflow, | ||
| listKnowledgeVersion, | ||
| } as { | ||
| [key: string]: any | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code provided looks mostly correct, but there are a few areas for improvement:
Here's an improved version of the function with added type annotations and ensuring consistency in the /**
* 保存知识库工作流
* @param knowledge_id
* @param data
* @param loading - Loading state reference
* @returns
*/
const putKnowledgeWorkflow: (
knowledge_id: string,
data: any,
loading: Ref<boolean>,
) => Promise<Result<any>> = (knowledge_id, data, loading) => {
return put(`${prefix}/${knowledge_id}/workflow`, data, undefined, loading);
};
export default {
getKnowledgeWorkflowDatasourceDetails,
workflowAction,
publish,
// Improved signature for putKnowledgeWorkflow
putKnowledgeWorkflow,
listKnowledgeVersion,
} as {
[key: string]: (...args: any[]) => void | Promise<void>;
};Key Changes:
|
||
|
|
||
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.
The code appears to be well-formed and correctly implements REST API functions related to managing knowledge and its workflows. However, there are a few minor improvements and considerations:
putKnowledgeWorkflowfunction should specify the HTTP method as "PUT" instead of "POST". This is because it's updating an existing resource with new data.Result. Using type definitions can help catch errors during development and make the code easier to read and maintain.Overall, the function names follow conventional naming conventions and seem self-explanatory based on their purpose. There doesn't appear to be any significant issues or optimizations needed at this time.