feat: manually mirror opencoze's code from bytedance
Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
/** @type { import('@storybook/react-vite').StorybookConfig } */
|
||||
const config = {
|
||||
stories: ['../stories/**/*.mdx', '../stories/**/*.stories.tsx'],
|
||||
addons: [
|
||||
'@storybook/addon-links',
|
||||
'@storybook/addon-essentials',
|
||||
'@storybook/addon-onboarding',
|
||||
'@storybook/addon-interactions',
|
||||
],
|
||||
framework: {
|
||||
name: '@storybook/react-vite',
|
||||
options: {},
|
||||
},
|
||||
docs: {
|
||||
autodocs: 'tag',
|
||||
},
|
||||
};
|
||||
export default config;
|
||||
@@ -0,0 +1,14 @@
|
||||
/** @type { import('@storybook/react').Preview } */
|
||||
const preview = {
|
||||
parameters: {
|
||||
actions: { argTypesRegex: "^on[A-Z].*" },
|
||||
controls: {
|
||||
matchers: {
|
||||
color: /(background|color)$/i,
|
||||
date: /Date$/i,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export default preview;
|
||||
@@ -0,0 +1,5 @@
|
||||
const { defineConfig } = require('@coze-arch/stylelint-config');
|
||||
|
||||
module.exports = defineConfig({
|
||||
extends: [],
|
||||
});
|
||||
16
frontend/packages/data/knowledge/common/stores/README.md
Normal file
16
frontend/packages/data/knowledge/common/stores/README.md
Normal file
@@ -0,0 +1,16 @@
|
||||
# @coze-data/utils
|
||||
|
||||
> Project template for react component with storybook and supports publish independently.
|
||||
|
||||
## Features
|
||||
|
||||
- [x] eslint & ts
|
||||
- [x] esm bundle
|
||||
- [x] umd bundle
|
||||
- [x] storybook
|
||||
|
||||
## Commands
|
||||
|
||||
- init: `rush update`
|
||||
- dev: `npm run dev`
|
||||
- build: `npm run build`
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"operationSettings": [
|
||||
{
|
||||
"operationName": "test:cov",
|
||||
"outputFolderNames": ["coverage"]
|
||||
},
|
||||
{
|
||||
"operationName": "ts-check",
|
||||
"outputFolderNames": ["./dist"]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
const { defineConfig } = require('@coze-arch/eslint-config');
|
||||
|
||||
module.exports = defineConfig({
|
||||
packageRoot: __dirname,
|
||||
preset: 'web',
|
||||
rules: {},
|
||||
});
|
||||
55
frontend/packages/data/knowledge/common/stores/package.json
Normal file
55
frontend/packages/data/knowledge/common/stores/package.json
Normal file
@@ -0,0 +1,55 @@
|
||||
{
|
||||
"name": "@coze-data/knowledge-stores",
|
||||
"version": "0.0.1",
|
||||
"description": "coze knowledge stores",
|
||||
"license": "Apache-2.0",
|
||||
"author": "fanchen@bytedance.com",
|
||||
"maintainers": [],
|
||||
"main": "src/index.ts",
|
||||
"unpkg": "./dist/umd/index.js",
|
||||
"module": "./dist/esm/index.js",
|
||||
"types": "./src/index.ts",
|
||||
"files": [
|
||||
"dist",
|
||||
"README.md"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "exit 0",
|
||||
"lint": "eslint ./ --cache",
|
||||
"test": "vitest --run --passWithNoTests",
|
||||
"test:cov": "npm run test -- --coverage"
|
||||
},
|
||||
"dependencies": {
|
||||
"@coze-arch/bot-api": "workspace:*",
|
||||
"@coze-arch/bot-error": "workspace:*",
|
||||
"@coze-arch/bot-typings": "workspace:*",
|
||||
"@coze-arch/i18n": "workspace:*",
|
||||
"@coze-arch/report-events": "workspace:*",
|
||||
"@coze-data/knowledge-resource-processor-core": "workspace:*",
|
||||
"ahooks": "^3.7.8",
|
||||
"classnames": "^2.3.2",
|
||||
"utility-types": "^3.10.0",
|
||||
"zustand": "^4.4.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@coze-arch/eslint-config": "workspace:*",
|
||||
"@coze-arch/stylelint-config": "workspace:*",
|
||||
"@coze-arch/ts-config": "workspace:*",
|
||||
"@coze-arch/vitest-config": "workspace:*",
|
||||
"@testing-library/jest-dom": "^6.1.5",
|
||||
"@testing-library/react": "^14.1.2",
|
||||
"@testing-library/react-hooks": "^8.0.1",
|
||||
"@types/react": "18.2.37",
|
||||
"@types/react-dom": "18.2.15",
|
||||
"@vitest/coverage-v8": "~3.0.5",
|
||||
"react": "~18.2.0",
|
||||
"react-dom": "~18.2.0",
|
||||
"typescript": "~5.8.2",
|
||||
"vitest": "~3.0.5"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": ">=18.2.0",
|
||||
"react-dom": ">=18.2.0"
|
||||
}
|
||||
}
|
||||
|
||||
119
frontend/packages/data/knowledge/common/stores/src/context.tsx
Normal file
119
frontend/packages/data/knowledge/common/stores/src/context.tsx
Normal file
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { createContext, type PropsWithChildren, type FC, useRef } from 'react';
|
||||
|
||||
import {
|
||||
type ProcessingKnowledgeStore,
|
||||
createProcessingKnowledgeStore,
|
||||
} from './processing-knowledge';
|
||||
import {
|
||||
type IParams,
|
||||
type ParamsStore,
|
||||
createParamsStore,
|
||||
} from './params-store';
|
||||
import {
|
||||
type KnowledgePreviewStore,
|
||||
createKnowledgePreviewStore,
|
||||
} from './knowledge-preview';
|
||||
|
||||
export type WidgetUIState = 'loading' | 'saving' | 'error' | 'normal';
|
||||
|
||||
export interface PluginNavType {
|
||||
toResource?: (
|
||||
res: string,
|
||||
resID?: string,
|
||||
query?: Record<string, string>,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
options?: Record<string, any>,
|
||||
) => void;
|
||||
// submodule
|
||||
upload?: (
|
||||
query?: Record<string, string>,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
options?: Record<string, any>,
|
||||
) => void;
|
||||
navigateTo?: (
|
||||
path: string,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
options?: Record<string, any>,
|
||||
) => void;
|
||||
}
|
||||
|
||||
export interface CallbacksType {
|
||||
onUpdateDisplayName?: (displayName: string) => void;
|
||||
onStatusChange?: (status: WidgetUIState) => void;
|
||||
}
|
||||
|
||||
interface TParamsStoreContext {
|
||||
paramsStore: ParamsStore | undefined;
|
||||
knowledgeStore: KnowledgePreviewStore | undefined;
|
||||
processingKnowledge: ProcessingKnowledgeStore | undefined;
|
||||
callbacks: CallbacksType;
|
||||
resourceNavigate: PluginNavType;
|
||||
}
|
||||
|
||||
export const KnowledgeParamsStoreContext = createContext<TParamsStoreContext>({
|
||||
paramsStore: undefined,
|
||||
knowledgeStore: undefined,
|
||||
processingKnowledge: undefined,
|
||||
callbacks: {},
|
||||
resourceNavigate: {},
|
||||
});
|
||||
|
||||
export const KnowledgeParamsStoreProvider: FC<
|
||||
PropsWithChildren<{
|
||||
params: IParams;
|
||||
onUpdateDisplayName?: (displayName: string) => void;
|
||||
onStatusChange?: (status: WidgetUIState) => void;
|
||||
resourceNavigate: PluginNavType;
|
||||
}>
|
||||
> = ({
|
||||
children,
|
||||
params,
|
||||
onUpdateDisplayName,
|
||||
onStatusChange,
|
||||
resourceNavigate,
|
||||
}) => {
|
||||
const paramsStoreRef = useRef<ParamsStore>();
|
||||
const knowledgeStoreRef = useRef<KnowledgePreviewStore>();
|
||||
const processingStoreRef = useRef<ProcessingKnowledgeStore>();
|
||||
|
||||
paramsStoreRef.current = createParamsStore(params);
|
||||
|
||||
if (!knowledgeStoreRef.current) {
|
||||
knowledgeStoreRef.current = createKnowledgePreviewStore({
|
||||
version: params.version,
|
||||
});
|
||||
}
|
||||
if (!processingStoreRef.current) {
|
||||
processingStoreRef.current = createProcessingKnowledgeStore();
|
||||
}
|
||||
|
||||
return (
|
||||
<KnowledgeParamsStoreContext.Provider
|
||||
value={{
|
||||
paramsStore: paramsStoreRef.current,
|
||||
knowledgeStore: knowledgeStoreRef.current,
|
||||
processingKnowledge: processingStoreRef.current,
|
||||
callbacks: { onUpdateDisplayName, onStatusChange },
|
||||
resourceNavigate,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</KnowledgeParamsStoreContext.Provider>
|
||||
);
|
||||
};
|
||||
97
frontend/packages/data/knowledge/common/stores/src/hooks.ts
Normal file
97
frontend/packages/data/knowledge/common/stores/src/hooks.ts
Normal file
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { useContext } from 'react';
|
||||
|
||||
import { useStoreWithEqualityFn } from 'zustand/traditional';
|
||||
import { shallow } from 'zustand/shallow';
|
||||
import { REPORT_EVENTS } from '@coze-arch/report-events';
|
||||
import { CustomError } from '@coze-arch/bot-error';
|
||||
|
||||
import {
|
||||
type ProcessingKnowledgeInfo,
|
||||
type ProcessingKnowledgeInfoAction,
|
||||
} from './processing-knowledge';
|
||||
import { type IParamsStore } from './params-store';
|
||||
import { type ILevelSegmentsSlice } from './level-segments-slice';
|
||||
import {
|
||||
type KnowledgePreviewAction,
|
||||
type KnowledgePreviewState,
|
||||
} from './knowledge-preview';
|
||||
import {
|
||||
type CallbacksType,
|
||||
type PluginNavType,
|
||||
KnowledgeParamsStoreContext,
|
||||
} from './context';
|
||||
|
||||
export const useKnowledgeParamsStore: <T>(
|
||||
selector: (store: IParamsStore) => T,
|
||||
) => T = selector => {
|
||||
const context = useContext(KnowledgeParamsStoreContext);
|
||||
|
||||
if (!context.paramsStore) {
|
||||
throw new CustomError(REPORT_EVENTS.normalError, 'params store context');
|
||||
}
|
||||
|
||||
return useStoreWithEqualityFn(context.paramsStore, selector, shallow);
|
||||
};
|
||||
|
||||
export const useKnowledgeParams = () => {
|
||||
const params = useKnowledgeParamsStore(store => store.params);
|
||||
return params;
|
||||
};
|
||||
|
||||
export const useDataCallbacks: () => CallbacksType = () => {
|
||||
const {
|
||||
callbacks: { onStatusChange, onUpdateDisplayName },
|
||||
} = useContext(KnowledgeParamsStoreContext);
|
||||
|
||||
return { onStatusChange, onUpdateDisplayName };
|
||||
};
|
||||
|
||||
export const useDataNavigate: () => PluginNavType = () => {
|
||||
const { resourceNavigate } = useContext(KnowledgeParamsStoreContext);
|
||||
|
||||
return resourceNavigate;
|
||||
};
|
||||
|
||||
export const useKnowledgeStore: <T>(
|
||||
selector: (
|
||||
store: KnowledgePreviewState & KnowledgePreviewAction & ILevelSegmentsSlice,
|
||||
) => T,
|
||||
) => T = selector => {
|
||||
const context = useContext(KnowledgeParamsStoreContext);
|
||||
|
||||
if (!context.knowledgeStore) {
|
||||
throw new CustomError(REPORT_EVENTS.normalError, 'params store context');
|
||||
}
|
||||
|
||||
return useStoreWithEqualityFn(context.knowledgeStore, selector, shallow);
|
||||
};
|
||||
|
||||
export const useProcessingStore: <T>(
|
||||
selector: (
|
||||
store: ProcessingKnowledgeInfo & ProcessingKnowledgeInfoAction,
|
||||
) => T,
|
||||
) => T = selector => {
|
||||
const context = useContext(KnowledgeParamsStoreContext);
|
||||
|
||||
if (!context.processingKnowledge) {
|
||||
throw new CustomError(REPORT_EVENTS.normalError, 'params store context');
|
||||
}
|
||||
|
||||
return useStoreWithEqualityFn(context.processingKnowledge, selector, shallow);
|
||||
};
|
||||
50
frontend/packages/data/knowledge/common/stores/src/index.ts
Normal file
50
frontend/packages/data/knowledge/common/stores/src/index.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export {
|
||||
useDataCallbacks,
|
||||
useDataNavigate,
|
||||
useKnowledgeParams,
|
||||
useKnowledgeParamsStore,
|
||||
useKnowledgeStore,
|
||||
useProcessingStore,
|
||||
} from './hooks';
|
||||
|
||||
export {
|
||||
KnowledgeParamsStoreContext,
|
||||
KnowledgeParamsStoreProvider,
|
||||
type WidgetUIState,
|
||||
type PluginNavType,
|
||||
} from './context';
|
||||
|
||||
export { type IParams as IKnowledgeParams } from './params-store';
|
||||
|
||||
export { FilterPhotoType } from './knowledge-preview';
|
||||
|
||||
export {
|
||||
getDefaultLevelSegmentsState,
|
||||
createLevelSegmentsSlice,
|
||||
ILevelSegmentsSlice,
|
||||
ILevelSegment,
|
||||
IImageDetail,
|
||||
ITableDetail,
|
||||
} from './level-segments-slice';
|
||||
|
||||
export {
|
||||
getDefaultStorageStrategyState,
|
||||
createStorageStrategySlice,
|
||||
IStorageStrategySlice,
|
||||
} from './storage-strategy-slice';
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { devtools } from 'zustand/middleware';
|
||||
import { create } from 'zustand';
|
||||
import { type DocumentInfo, type Dataset } from '@coze-arch/bot-api/knowledge';
|
||||
|
||||
import {
|
||||
createLevelSegmentsSlice,
|
||||
getDefaultLevelSegmentsState,
|
||||
type ILevelSegmentsSlice,
|
||||
} from './level-segments-slice';
|
||||
|
||||
export enum FilterPhotoType {
|
||||
/**
|
||||
* 全部
|
||||
*/
|
||||
All = 'All',
|
||||
/**
|
||||
* 已标注
|
||||
*/
|
||||
HasCaption = 'HasCaption',
|
||||
/**
|
||||
* 未标注
|
||||
*/
|
||||
NoCaption = 'NoCaption',
|
||||
}
|
||||
|
||||
export interface KnowledgePreviewState {
|
||||
canEdit?: boolean;
|
||||
dataSetDetail: Dataset;
|
||||
documentList: DocumentInfo[];
|
||||
searchValue: string;
|
||||
curDocId: string;
|
||||
/**
|
||||
* 图片类型是否已标注
|
||||
*/
|
||||
photoFilterValue: FilterPhotoType;
|
||||
}
|
||||
export interface KnowledgePreviewAction {
|
||||
setCanEdit: (editable: boolean) => void;
|
||||
setDataSetDetail: (dataSet: Dataset) => void;
|
||||
setDocumentList: (documentList: DocumentInfo[]) => void;
|
||||
setSearchValue: (v: string) => void;
|
||||
setPhotoFilterValue: (v: FilterPhotoType) => void;
|
||||
setCurDocId: (curDocId: string) => void;
|
||||
}
|
||||
|
||||
const getInitialState = (options?: { version?: string }) => ({
|
||||
canEdit: !options?.version,
|
||||
dataSetDetail: {},
|
||||
documentList: [],
|
||||
curDocId: '',
|
||||
searchValue: '',
|
||||
photoFilterValue: FilterPhotoType.All,
|
||||
});
|
||||
|
||||
export const createKnowledgePreviewStore = (options?: { version?: string }) =>
|
||||
create<
|
||||
KnowledgePreviewState & KnowledgePreviewAction & ILevelSegmentsSlice
|
||||
>()(
|
||||
devtools(
|
||||
(set, get, ...args) => ({
|
||||
...getInitialState(options),
|
||||
...getDefaultLevelSegmentsState(),
|
||||
...createLevelSegmentsSlice(set, get, ...args),
|
||||
setDataSetDetail: (dataSetDetail: Dataset) => {
|
||||
set({ dataSetDetail });
|
||||
set({ canEdit: dataSetDetail?.can_edit && !options?.version });
|
||||
},
|
||||
setDocumentList: (documentList: DocumentInfo[]) => {
|
||||
set({ documentList });
|
||||
},
|
||||
setSearchValue: (v: string) => {
|
||||
set({ searchValue: v });
|
||||
},
|
||||
setPhotoFilterValue: (v: FilterPhotoType) => {
|
||||
set({ photoFilterValue: v });
|
||||
},
|
||||
setCanEdit: editable => {
|
||||
set({ canEdit: editable });
|
||||
},
|
||||
setCurDocId: (curDocId: string) => {
|
||||
set({ curDocId });
|
||||
},
|
||||
reset: () => {
|
||||
set(getInitialState(options));
|
||||
},
|
||||
}),
|
||||
{ name: 'DEV_TOOLS_NAME_SPACE', enabled: IS_DEV_MODE },
|
||||
),
|
||||
);
|
||||
|
||||
export type KnowledgePreviewStore = ReturnType<
|
||||
typeof createKnowledgePreviewStore
|
||||
>;
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type StateCreator } from 'zustand';
|
||||
|
||||
export interface ITableDetail {
|
||||
tableIdx: number | null;
|
||||
tableName: string | null;
|
||||
caption: string | null;
|
||||
text: string | null;
|
||||
cells: string | null;
|
||||
}
|
||||
|
||||
export interface IImageDetail {
|
||||
base64: string | null;
|
||||
caption: string | null;
|
||||
links: string | null;
|
||||
token: string | null;
|
||||
name: string | null;
|
||||
}
|
||||
|
||||
export interface ILevelSegment {
|
||||
id: number;
|
||||
block_id: number | null;
|
||||
slide_index: number | null;
|
||||
slice_id?: string;
|
||||
slice_sequence?: number;
|
||||
type:
|
||||
| 'title'
|
||||
| 'section-title'
|
||||
| 'section-text'
|
||||
| 'text'
|
||||
| 'image'
|
||||
| 'table'
|
||||
| 'caption'
|
||||
| 'header-footer'
|
||||
| 'header'
|
||||
| 'footer'
|
||||
| 'formula'
|
||||
| 'footnote'
|
||||
| 'toc'
|
||||
| 'code'
|
||||
| 'page-title';
|
||||
level: number;
|
||||
parent: number;
|
||||
children: number[];
|
||||
text: string;
|
||||
label: string;
|
||||
html_text: string;
|
||||
positions: string | null;
|
||||
table_detail: ITableDetail;
|
||||
image_detail: IImageDetail;
|
||||
file_detail: string | null;
|
||||
}
|
||||
|
||||
export interface ILevelSegmentsState {
|
||||
levelSegments: ILevelSegment[];
|
||||
}
|
||||
|
||||
export interface ILevelSegmentsAction {
|
||||
setLevelSegments: (segments: ILevelSegment[]) => void;
|
||||
}
|
||||
|
||||
export type ILevelSegmentsSlice = ILevelSegmentsState & ILevelSegmentsAction;
|
||||
|
||||
export const getDefaultLevelSegmentsState = () => ({
|
||||
levelSegments: [],
|
||||
});
|
||||
|
||||
export const createLevelSegmentsSlice: StateCreator<
|
||||
ILevelSegmentsSlice
|
||||
> = set => ({
|
||||
...getDefaultLevelSegmentsState(),
|
||||
setLevelSegments: (content: ILevelSegment[]) =>
|
||||
set(() => ({
|
||||
levelSegments: content,
|
||||
})),
|
||||
});
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { devtools, subscribeWithSelector } from 'zustand/middleware';
|
||||
import { create } from 'zustand';
|
||||
import {
|
||||
type UnitType,
|
||||
type OptType,
|
||||
} from '@coze-data/knowledge-resource-processor-core';
|
||||
|
||||
export enum ActionType {
|
||||
ADD = 'add',
|
||||
REMOVE = 'remove',
|
||||
}
|
||||
export interface IParams {
|
||||
version?: string;
|
||||
|
||||
projectID?: string;
|
||||
datasetID?: string;
|
||||
spaceID?: string;
|
||||
tableID?: string;
|
||||
|
||||
type?: UnitType;
|
||||
opt?: OptType;
|
||||
docID?: string;
|
||||
|
||||
biz: 'agentIDE' | 'workflow' | 'project' | 'library';
|
||||
botID?: string;
|
||||
workflowID?: string;
|
||||
agentID?: string;
|
||||
actionType?: ActionType;
|
||||
initialTab?: 'structure' | 'draft' | 'online';
|
||||
/** 作用是跳转上传页时能在 url 里带上抖音标记,以在上传页做视图区分 */
|
||||
isDouyinBot?: boolean;
|
||||
pageMode?: 'modal' | 'normal';
|
||||
|
||||
first_auto_open_edit_document_id?: string;
|
||||
create?: string;
|
||||
}
|
||||
|
||||
export interface IParamsStore {
|
||||
params: IParams;
|
||||
}
|
||||
|
||||
export const createParamsStore = (initialState: IParams) =>
|
||||
create<IParamsStore>()(
|
||||
devtools(
|
||||
subscribeWithSelector((set, get) => ({
|
||||
params: initialState,
|
||||
//TODO: get
|
||||
})),
|
||||
{
|
||||
enabled: IS_DEV_MODE,
|
||||
name: 'knowledge.params',
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
export type ParamsStore = ReturnType<typeof createParamsStore>;
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { devtools } from 'zustand/middleware';
|
||||
import { create } from 'zustand';
|
||||
|
||||
const defaultState = {
|
||||
processingDatasets: new Set<string>(),
|
||||
};
|
||||
|
||||
export interface ProcessingKnowledgeInfo {
|
||||
processingDatasets: Set<string>;
|
||||
}
|
||||
|
||||
export interface ProcessingKnowledgeInfoAction {
|
||||
getIsProcessing: (datasetId: string) => boolean;
|
||||
addProcessingDataset: (datasetId: string) => void;
|
||||
clearProcessingSet: () => void;
|
||||
deleteProcessingDataset: (datasetId: string) => void;
|
||||
}
|
||||
|
||||
export const createProcessingKnowledgeStore = () =>
|
||||
create<ProcessingKnowledgeInfo & ProcessingKnowledgeInfoAction>()(
|
||||
devtools((set, get) => ({
|
||||
...defaultState,
|
||||
getIsProcessing: (datasetId: string) => {
|
||||
const { processingDatasets } = get();
|
||||
return processingDatasets.has(datasetId);
|
||||
},
|
||||
addProcessingDataset: (datasetId: string) => {
|
||||
const { processingDatasets } = get();
|
||||
processingDatasets.add(datasetId);
|
||||
set({
|
||||
processingDatasets,
|
||||
});
|
||||
},
|
||||
clearProcessingSet: () => {
|
||||
const { processingDatasets } = get();
|
||||
processingDatasets.clear();
|
||||
set({
|
||||
processingDatasets,
|
||||
});
|
||||
},
|
||||
deleteProcessingDataset: (datasetId: string) => {
|
||||
const { processingDatasets } = get();
|
||||
if (!processingDatasets.has(datasetId)) {
|
||||
return;
|
||||
}
|
||||
processingDatasets.delete(datasetId);
|
||||
set({
|
||||
processingDatasets,
|
||||
});
|
||||
},
|
||||
})),
|
||||
);
|
||||
|
||||
export type ProcessingKnowledgeStore = ReturnType<
|
||||
typeof createProcessingKnowledgeStore
|
||||
>;
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type StateCreator } from 'zustand';
|
||||
import {
|
||||
type OpenSearchConfig,
|
||||
StorageLocation,
|
||||
} from '@coze-arch/bot-api/knowledge';
|
||||
|
||||
export interface IStorageStrategyState {
|
||||
enableStorageStrategy: boolean;
|
||||
storageLocation: StorageLocation;
|
||||
openSearchConfig: OpenSearchConfig;
|
||||
testConnectionSuccess: boolean;
|
||||
}
|
||||
|
||||
export interface IStorageStrategyAction {
|
||||
setEnableStorageStrategy: (enableStorageStrategy: boolean) => void;
|
||||
setStorageLocation: (storageLocation: StorageLocation) => void;
|
||||
setOpenSearchConfig: (openSearchConfig: OpenSearchConfig) => void;
|
||||
setTestConnectionSuccess: (testConnectionSuccess: boolean) => void;
|
||||
}
|
||||
|
||||
export type IStorageStrategySlice = IStorageStrategyState &
|
||||
IStorageStrategyAction;
|
||||
|
||||
export const getDefaultStorageStrategyState = (): IStorageStrategyState => ({
|
||||
enableStorageStrategy: false,
|
||||
storageLocation: StorageLocation.Default,
|
||||
openSearchConfig: {},
|
||||
testConnectionSuccess: false,
|
||||
});
|
||||
|
||||
export const createStorageStrategySlice: StateCreator<
|
||||
IStorageStrategySlice
|
||||
> = set => ({
|
||||
...getDefaultStorageStrategyState(),
|
||||
setEnableStorageStrategy: (enableStorageStrategy: boolean) =>
|
||||
set({ enableStorageStrategy }),
|
||||
setStorageLocation: (storageLocation: StorageLocation) =>
|
||||
set({ storageLocation }),
|
||||
setOpenSearchConfig: (openSearchConfig: OpenSearchConfig) =>
|
||||
set({ openSearchConfig }),
|
||||
setTestConnectionSuccess: (testConnectionSuccess: boolean) =>
|
||||
set({ testConnectionSuccess }),
|
||||
});
|
||||
17
frontend/packages/data/knowledge/common/stores/src/typings.d.ts
vendored
Normal file
17
frontend/packages/data/knowledge/common/stores/src/typings.d.ts
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/// <reference types='@coze-arch/bot-typings' />
|
||||
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"extends": "@coze-arch/ts-config/tsconfig.web.json",
|
||||
"compilerOptions": {
|
||||
"types": [],
|
||||
"rootDir": "./src",
|
||||
"outDir": "./dist",
|
||||
"tsBuildInfoFile": "dist/tsconfig.build.tsbuildinfo"
|
||||
},
|
||||
"include": ["src"],
|
||||
"references": [
|
||||
{
|
||||
"path": "../../../../arch/bot-api/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../../../arch/bot-error/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../../../arch/bot-typings/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../../../arch/i18n/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../../../arch/report-events/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../../../../config/eslint-config/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../../../../config/stylelint-config/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../../../../config/ts-config/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../../../../config/vitest-config/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../knowledge-resource-processor-core/tsconfig.build.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
14
frontend/packages/data/knowledge/common/stores/tsconfig.json
Normal file
14
frontend/packages/data/knowledge/common/stores/tsconfig.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"compilerOptions": {
|
||||
"composite": true
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "./tsconfig.misc.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"extends": "@coze-arch/ts-config/tsconfig.web.json",
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"include": ["__tests__", "stories", "vitest.config.ts", "tailwind.config.ts"],
|
||||
"exclude": ["./dist"],
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.build.json"
|
||||
}
|
||||
],
|
||||
"compilerOptions": {
|
||||
"rootDir": "./",
|
||||
"outDir": "./dist",
|
||||
"types": ["vitest/globals"]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { defineConfig } from '@coze-arch/vitest-config';
|
||||
|
||||
export default defineConfig({
|
||||
dirname: __dirname,
|
||||
preset: 'web',
|
||||
});
|
||||
Reference in New Issue
Block a user