Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions chat2db-community-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"build": "yarn run build:web:community",
"build:prod": "yarn run build:web:community",
"build:web": "umi build",
"prebuild:web:community": "yarn test:ipc-log-redaction && yarn test:community-boundary && yarn test:database-capabilities && yarn test:table-editor && yarn test:retired-ai && yarn test:tree-title-highlight && yarn test:tree-search-lifecycle && yarn test:driver-upload && yarn test:tree-loading && yarn test:tree-node-lookup && yarn test:tree-node-path && yarn test:data-source-authorization && yarn test:active-transactions && yarn test:data-source-mutation-refresh && yarn test:ai-model-config && yarn test:ai-model-select && yarn test:export-connections && yarn test:main-page-navigation && yarn test:shortcut && yarn test:console-tab-name && yarn test:workspace-tab-scroll && yarn test:workspace-split-lifecycle && yarn test:sql-completion-context && yarn test:file-manager-label && yarn test:local-file-encoding && yarn test:local-file-save && yarn test:local-file-tree-path && yarn test:saved-console-dirty && yarn test:editor-close && yarn test:result-set-ui && yarn test:result-pagination && yarn test:sql-execution-stream && yarn test:result-table-layout && yarn test:result-status && yarn test:data-source-identity && yarn test:data-source-execution-snapshot && yarn test:data-source-watermark && yarn test:hot-update && yarn test:update-check-schedule && yarn test:task-center && yarn test:import-preview && yarn test:application-exit && yarn test:monaco-lifecycle && yarn test:result-set-editor && yarn test:account-grants-request && yarn test:connection-close-request && yarn test:ssh-connection && yarn test:operation-log-filters && yarn test:dashboard-store && yarn test:view-table-target",
"prebuild:web:community": "yarn test:ipc-log-redaction && yarn test:community-boundary && yarn test:database-capabilities && yarn test:table-editor && yarn test:retired-ai && yarn test:tree-title-highlight && yarn test:tree-search-lifecycle && yarn test:driver-upload && yarn test:tree-loading && yarn test:tree-node-lookup && yarn test:tree-node-path && yarn test:data-source-authorization && yarn test:active-transactions && yarn test:data-source-mutation-refresh && yarn test:ai-model-config && yarn test:ai-model-select && yarn test:export-connections && yarn test:main-page-navigation && yarn test:shortcut && yarn test:console-tab-name && yarn test:workspace-tab-scroll && yarn test:workspace-split-lifecycle && yarn test:sql-completion-context && yarn test:file-manager-label && yarn test:local-file-encoding && yarn test:local-file-save && yarn test:local-file-tree-path && yarn test:saved-console-dirty && yarn test:editor-close && yarn test:result-set-ui && yarn test:result-pagination && yarn test:sql-execution-stream && yarn test:result-table-layout && yarn test:result-status && yarn test:data-source-identity && yarn test:data-source-execution-snapshot && yarn test:data-source-watermark && yarn test:hot-update && yarn test:update-check-schedule && yarn test:task-center && yarn test:import-preview && yarn test:application-exit && yarn test:monaco-lifecycle && yarn test:result-set-editor && yarn test:account-grants-request && yarn test:connection-close-request && yarn test:ssh-connection && yarn test:operation-log-filters && yarn test:dashboard-store && yarn test:view-table-target && yarn test:desktop-request-settlement",
"postbuild:web:community": "node ./scripts/verify-production-bundles.cjs",
"build:web:2java": "yarn run build:web:community && rm -rf ../chat2db-community-server/chat2db-community-start/src/main/resources/thymeleaf/* && cp -r dist/index.html ../chat2db-community-server/chat2db-community-start/src/main/resources/thymeleaf/",
"build:web:community": "cross-env UMI_ENV=community cross-env APP_NAME=chat2db-community cross-env APP_VERSION=${npm_config_app_version} cross-env PRINT_LOGS=${npm_config_print_logs} cross-env APP_PORT=${npm_config_app_port} umi build",
Expand Down Expand Up @@ -111,7 +111,8 @@
"start": "yarn run start:community:hot",
"start:community:hot": "cross-env UMI_ENV=community cross-env APP_NAME=chat2db-community cross-env DISABLE_MFSU=true cross-env UMI_DEV_SERVER_COMPRESS=none cross-env HOST=127.0.0.1 cross-env PORT=8889 node --require ./scripts/bind-dev-server-loopback.cjs ./node_modules/umi/bin/umi.js dev --public_path=/",
"ui": "yarn add @chat2db/ui",
"test:create-stream-index": "tsx src/blocks/RedisAllData/CreateStream/mapDisplayedIndex.test.ts"
"test:create-stream-index": "tsx src/blocks/RedisAllData/CreateStream/mapDisplayedIndex.test.ts",
"test:desktop-request-settlement": "tsx src/service/commandLine/requestSettlement.test.ts"
},
"dependencies": {
"@chat2db/ui": "^1.45.3",
Expand Down
12 changes: 6 additions & 6 deletions chat2db-community-client/src/hooks/useAbortRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

import { useCallback, useMemo, useState } from 'react';
import { isDesktop } from '@/utils/env';
import { DesktopRequestOptions, DesktopAbortControllerSignalParams } from '@/service/commandLine/commandLine';
import { useGlobalStore } from '@/store/global';
import {
DesktopRequestOptions,
DesktopAbortControllerSignalParams,
rejectCommandLineRequest,
} from '@/service/commandLine/commandLine';

type UseDiscardRequestReturnType = [(() => AbortSignal) | (() => DesktopRequestOptions['signal']), () => void];

Expand All @@ -20,10 +23,7 @@ const useAbortRequest: UseDiscardRequestType = () => {
const abortRequest = useCallback(() => {
if (isDesktop) {
if (!desktopController) return;
// Remove the request id so that a later backend response is ignored by the frontend.
useGlobalStore.getState().removeCommandLineRequestListItem(desktopController.id);
// Promise requested by the terminal
desktopController.reject({ message: 'signal is aborted without reason' });
rejectCommandLineRequest(desktopController.id, { message: 'signal is aborted without reason' });
return;
}

Expand Down
125 changes: 65 additions & 60 deletions chat2db-community-client/src/service/commandLine/commandLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import { ErrorCodesWithoutToast } from '@/constants/request';
import interceptorsResponse from '@/service/interceptorsResponse';
import { IErrorLevel, PermissionError } from '@/service/base';
import { staticMessage } from '@chat2db/ui';
import {
cleanupTrackedCommandLineRequest,
rejectTrackedCommandLineRequest,
settleTrackedCommandLineResponse,
} from './requestSettlement';
import { redactForLog } from './redactForLog';

export interface ICommandLineRequest {
Expand Down Expand Up @@ -50,6 +55,15 @@ export const TIMEOUT = 300000;
// TODO: must be deleted
// window._PRINT_LOGS = true;

const commandLineRequestRegistry = {
get: (id: string) => useGlobalStore.getState().commandLineRequestList[id],
remove: (id: string) => useGlobalStore.getState().removeCommandLineRequestListItem(id),
clearTimer: (timer: unknown) => clearTimeout(timer as ReturnType<typeof setTimeout>),
};

export const rejectCommandLineRequest = (id: string, reason: unknown) =>
rejectTrackedCommandLineRequest(id, reason, commandLineRequestRegistry);

// JCEF request requestJCEF
export const commandLineRequest = <R>(data: ICommandLineRequest, options: IOptions) => {
const language = useGlobalStore.getState().baseSetting.language;
Expand Down Expand Up @@ -85,7 +99,7 @@ export const commandLineRequest = <R>(data: ICommandLineRequest, options: IOptio
requestTimeoutTimer = setTimeout(() => {
const item = useGlobalStore.getState().commandLineRequestList[id];
if (item) {
useGlobalStore.getState().removeCommandLineRequestListItem(id);
cleanupTrackedCommandLineRequest(id, commandLineRequestRegistry);
reject?.(`timeout_error:${item.requestData.requestUrl}`);
}
}, TIMEOUT);
Expand All @@ -101,20 +115,29 @@ export const commandLineRequest = <R>(data: ICommandLineRequest, options: IOptio
};
useGlobalStore.getState().addCommandLineRequestListItem(commandLineRequestListItem);
if (typeof window.javaQuery === 'function') {
window.javaQuery({
request: JSON.stringify(res),
onSuccess: function (_data) {
// console.log('%cCHAT2DB_IPC_RESPONSE', 'color: #B8860B', _data);
pushMessageFlow(_data);
},
onFailure: function (error_code, error_message) {
alert(error_message);
console.log('error', error_message);
reject(error_message);
},
});
try {
window.javaQuery({
request: JSON.stringify(res),
onSuccess: function (_data) {
// console.log('%cCHAT2DB_IPC_RESPONSE', 'color: #B8860B', _data);
pushMessageFlow(_data);
},
onFailure: function (error_code, error_message) {
try {
alert(error_message);
console.log('error', error_code, error_message);
} finally {
rejectCommandLineRequest(id, error_message);
}
},
});
} catch (error) {
rejectCommandLineRequest(id, error);
}
} else {
console.error("JCEF's javaQuery is not available!");
const error = new Error("JCEF's javaQuery is not available");
console.error(error.message);
rejectCommandLineRequest(id, error);
}
});
};
Expand All @@ -125,7 +148,7 @@ export const pushMessageFlow = (_data) => {
if (__PRINT_LOGS__ || window._PRINT_LOGS) {
console.log('%cCHAT2DB_IPC_RESPONSE', 'color: #B8860B', new Date().toISOString(), redactForLog(data));
}
const { setServiceStatus, commandLineRequestList, removeCommandLineRequestListItem } = useGlobalStore.getState();
const { setServiceStatus } = useGlobalStore.getState();

// Special handling application startup
if (data === 'CHAT2DB_IPC_RESPONSE_SERVICE_STATUS_SUCCESS') {
Expand All @@ -134,52 +157,34 @@ export const pushMessageFlow = (_data) => {
}

// Only process logged requests
if (data?.uuid && commandLineRequestList?.[data.uuid]) {
if (data?.uuid) {
const { message: messageData, uuid } = data;

const { errorCode, success, errorMessage, errorDetail, solutionLink, eventualUrl } = messageData || {};

const { resolve, reject, options, requestData, requestTimeoutTimer } = commandLineRequestList[uuid];

// Clear timeout timer
if (requestTimeoutTimer) {
clearTimeout(requestTimeoutTimer);
}

// response interception
responseInterceptor(messageData, requestData, options);
// Process request results
if (success) {
resolve?.(options.fullResponse ? messageData : messageData?.data);
} else {
reject({
errorCode: errorCode,
errorMessage: errorMessage,
});
// If there is no need to pop up the toast error code
if (ErrorCodesWithoutToast.includes(errorCode)) {
return;
}
switch (options.errorLevel) {
case 'toast':
staticMessage.error(errorMessage);
break;
case 'notification':
useGlobalStore?.getState()?.systemErrorMessageApi?.({
errorCode,
errorMessage,
errorDetail,
solutionLink,
requestUrl: eventualUrl,
requestParams: JSON.stringify(requestData),
});
break;
default:
break;
}
}
// Remove request record
removeCommandLineRequestListItem(uuid);
settleTrackedCommandLineResponse({
requestId: uuid,
message: messageData || {},
registry: commandLineRequestRegistry,
beforeSettle: (request, message) => responseInterceptor(message, request.requestData, request.options),
suppressErrorReport: (errorCode) => ErrorCodesWithoutToast.includes(errorCode as any),
reportError: (request, message) => {
switch (request.options.errorLevel) {
case 'toast':
staticMessage.error(message.errorMessage);
break;
case 'notification':
useGlobalStore?.getState()?.systemErrorMessageApi?.({
errorCode: message.errorCode,
errorMessage: message.errorMessage,
errorDetail: message.errorDetail,
solutionLink: message.solutionLink,
requestUrl: message.eventualUrl,
requestParams: JSON.stringify(request.requestData),
});
break;
default:
break;
}
},
});
}
};

Expand Down
Loading
Loading