-
-
Notifications
You must be signed in to change notification settings - Fork 18
feat: implement AI settings and widgets creation with streaming response #1809
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,11 @@ | ||
| import { InTransactionEnum } from '../../enums/in-transaction.enum.js'; | ||
| import { FindOneConnectionDs } from '../connection/application/data-structures/find-one-connection.ds.js'; | ||
| import { RequestAISettingsCreationDs } from './application/data-structures/request-ai-settings-creation.ds.js'; | ||
| import { RequestInfoFromTableDSV2 } from './application/data-structures/request-info-from-table.ds.js'; | ||
|
|
||
| export interface IRequestInfoFromTableV2 { | ||
| execute(inputData: RequestInfoFromTableDSV2, inTransaction: InTransactionEnum): Promise<void>; | ||
| } | ||
|
|
||
| export interface IAISettingsAndWidgetsCreation { | ||
| execute(connectionData: FindOneConnectionDs, inTransaction: InTransactionEnum): Promise<void>; | ||
| execute(inputData: RequestAISettingsCreationDs, inTransaction: InTransactionEnum): Promise<void>; | ||
| } |
6 changes: 6 additions & 0 deletions
6
backend/src/entities/ai/application/data-structures/request-ai-settings-creation.ds.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { Response } from 'express'; | ||
| import { FindOneConnectionDs } from '../../../connection/application/data-structures/find-one-connection.ds.js'; | ||
|
|
||
| export class RequestAISettingsCreationDs extends FindOneConnectionDs { | ||
| response: Response; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
backend/src/entities/shared-jobs/utils/emit-settings-messages.util.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { TableSettingsEntity } from '../../table-settings/common-table-settings/table-settings.entity.js'; | ||
|
|
||
| export function emitSettingsMessages(setting: TableSettingsEntity, emit: (text: string) => void): void { | ||
| const tableName = setting.table_name; | ||
| const params: Array<[string, string]> = []; | ||
| if (setting.display_name) { | ||
| params.push(['display_name', `"${setting.display_name}"`]); | ||
| } | ||
| if (setting.search_fields && setting.search_fields.length > 0) { | ||
| params.push(['search_fields', setting.search_fields.join(', ')]); | ||
| } | ||
| if (setting.readonly_fields && setting.readonly_fields.length > 0) { | ||
| params.push(['readonly_fields', setting.readonly_fields.join(', ')]); | ||
| } | ||
| if (setting.columns_view && setting.columns_view.length > 0) { | ||
| params.push(['columns_view', setting.columns_view.join(', ')]); | ||
| } | ||
| if (setting.ordering) { | ||
| params.push(['ordering', String(setting.ordering)]); | ||
| } | ||
| if (setting.ordering_field) { | ||
| params.push(['ordering_field', `"${setting.ordering_field}"`]); | ||
| } | ||
| if (setting.identity_column) { | ||
| params.push(['identity_column', `"${setting.identity_column}"`]); | ||
| } | ||
|
|
||
| if (params.length === 0) { | ||
| emit(`Set up settings for table "${tableName}" with default parameters`); | ||
| return; | ||
| } | ||
| for (const [name, value] of params) { | ||
| emit(`Set up settings for table "${tableName}", ${name} parameter set to ${value}`); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🧩 Analysis chain
🏁 Script executed:
Repository: rocket-admin/rocketadmin
Length of output: 676
🏁 Script executed:
Repository: rocket-admin/rocketadmin
Length of output: 312
🏁 Script executed:
Repository: rocket-admin/rocketadmin
Length of output: 3790
Guard streaming writes/ends when the client disconnects; also replace string concatenation in
writeChunk.implementationcallswriteChunk(...)andresponse.end()with no writable-state checks (including in thecatchpath), so a mid-scan disconnect can triggerwrite after end-style failures and break error handling.writeChunkuses string concatenation (JSON.stringify(chunk) + '\n') instead of a template literal.Proposed fix
public async implementation(inputData: RequestAISettingsCreationDs): Promise<void> { const { connectionId, masterPwd, response } = inputData; @@ try { await this.sharedJobsService.scanDatabaseAndCreateSettingsAndWidgetsWithAI(connection, (chunk) => this.writeChunk(response, chunk), ); - this.writeChunk(response, { type: 'complete' }); - response.end(); + if (this.isWritable(response)) { + this.writeChunk(response, { type: 'complete' }); + response.end(); + } } catch (error) { Sentry.captureException(error); + if (!this.isWritable(response)) { + return; + } if (!response.headersSent) { response.status(500).send({ error: 'An error occurred while processing your request.' }); return; } this.writeChunk(response, { type: 'error', message: getErrorMessage(error) }); response.end(); } } @@ private writeChunk( response: Response, chunk: { type: 'message'; text: string } | { type: 'complete' } | { type: 'error'; message: string }, ): void { - response.write(JSON.stringify(chunk) + '\n'); + if (!this.isWritable(response)) { + return; + } + response.write(`${JSON.stringify(chunk)}\n`); } + + private isWritable(response: Response): boolean { + return !response.writableEnded && !response.destroyed; + }📝 Committable suggestion
🤖 Prompt for AI Agents