feat: manually mirror opencoze's code from bytedance

Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
fanlv
2025-07-20 17:36:12 +08:00
commit 890153324f
14811 changed files with 1923430 additions and 0 deletions

View File

@@ -0,0 +1,118 @@
# @coze-project-ide/client
A api & networking package for the Coze Studio monorepo
## Overview
This package is part of the Coze Studio monorepo and provides api & networking functionality. It includes component, store, service and more.
## Getting Started
### Installation
Add this package to your `package.json`:
```json
{
"dependencies": {
"@coze-project-ide/client": "workspace:*"
}
}
```
Then run:
```bash
rush update
```
### Usage
```typescript
import { /* exported functions/components */ } from '@coze-project-ide/client';
// Example usage
// TODO: Add specific usage examples
```
## Features
- Component
- Store
- Service
- Manager
## API Reference
### Exports
- `*`
- `type CustomTitleType,
type ViewOptionRegisterService,
type CustomPreferenceConfig,
type CustomTitleChanged,
LayoutPanelType,
ToolbarAlign,
ReactWidget,
ViewManager,
WidgetFactory,
WidgetManager,
CurrentResourceContext,
ReactWidgetContext,
ViewContribution,
useCurrentWidget,
useCurrentWidgetFromArea,
useCurrentResource,
Widget,
StatefulWidget,
ApplicationShell,
LayoutRestorer,
CustomPreferenceContribution,
ViewService,
FlowDockPanel,
HoverService,
MenuService,
DebugService,
DEBUG_BAR_DRAGGABLE,
SplitWidget,
BoxLayout,
DockLayout,
BoxPanel,
SplitLayout,
SplitPanel,
createBoxLayout,
createSplitLayout,
PerfectScrollbar,
DISABLE_HANDLE_EVENT,
TabBarToolbar,
ACTIVITY_BAR_CONTENT,
ViewRenderer,
DragService,
CustomTabBar,
TabBar,
type DragPropsType,
type PresetConfigType,
type ToolbarItem,`
- `createDefaultPreset`
- `type IDEClientOptions, IDEClientContext`
- `*`
For detailed API documentation, please refer to the TypeScript definitions.
## Development
This package is built with:
- TypeScript
- Modern JavaScript
- ESLint for code quality
## Contributing
This package is part of the Coze Studio monorepo. Please follow the monorepo contribution guidelines.
## License
Apache-2.0

View File

@@ -0,0 +1,9 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/rush/v5/rush-project.schema.json",
"operationSettings": [
{
"operationName": "ts-check",
"outputFolderNames": ["./lib-ts"]
}
]
}

View File

@@ -0,0 +1,17 @@
const { defineConfig } = require('@coze-arch/eslint-config');
module.exports = defineConfig({
packageRoot: __dirname,
preset: 'web',
rules: {
'no-restricted-syntax': 'off',
'@typescript-eslint/naming-convention': 'off',
'@typescript-eslint/no-magic-numbers': 'off',
'@coze-arch/no-batch-import-or-export': 'off',
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-non-null-assertion': 'off',
'rule-empty-line-before': 'off',
'alpha-value-notation': 'off',
'import/no-duplicates': 'off',
},
});

View File

@@ -0,0 +1,40 @@
{
"name": "@coze-project-ide/client",
"version": "0.0.1",
"author": "chenjiawei.inizio@bytedance.com",
"main": "./src/index.ts",
"scripts": {
"build": "exit 0",
"build:fast": "tsup src/index.ts --format cjs,esm --sourcemap --legacy-output",
"build:watch": "npm run build:fast -- --dts-resolve",
"clean": "rimraf dist",
"lint": "eslint ./ --cache --quiet",
"ts-check": "tsc --noEmit",
"watch": "npm run build:fast -- --dts-resolve --watch --ignore-watch dist"
},
"dependencies": {
"@coze-project-ide/core": "workspace:*",
"@coze-project-ide/view": "workspace:*",
"@flowgram-adapter/common": "workspace:*",
"inversify": "^6.0.1"
},
"devDependencies": {
"@coze-arch/eslint-config": "workspace:*",
"@coze-arch/ts-config": "workspace:*",
"@testing-library/react": "^14.1.2",
"@types/react": "18.2.37",
"@types/react-dom": "18.2.15",
"@vitest/coverage-v8": "~3.0.5",
"eslint": "~9.12.0",
"jsdom": "^22.1.0",
"reflect-metadata": "^0.1.13",
"tsup": "^8.0.1",
"typescript": "~5.8.2",
"vitest": "~3.0.5"
},
"peerDependencies": {
"react": ">=17",
"react-dom": ">=17"
}
}

View File

@@ -0,0 +1,65 @@
/*
* 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 React, {
useMemo,
forwardRef,
type ForwardRefRenderFunction,
} from 'react';
import { type interfaces } from 'inversify';
import {
IDEProvider,
IDERenderer,
type IDEProviderProps,
type IDEProviderRef,
} from '@coze-project-ide/core';
import { type IDEClientOptions, IDEClientContext } from '../types';
import { createDefaultPreset } from '../create-default-preset';
export interface IDEClientProps {
options: (ctx: IDEClientContext) => IDEClientOptions;
container?: interfaces.Container;
containerModules?: interfaces.ContainerModule[]; // 注入的 IOC 包
children?: React.ReactNode;
className?: string;
}
const IDEClientWithRef: ForwardRefRenderFunction<
IDEProviderRef,
IDEClientProps
> = ({ options, container, containerModules, children, className }, ref) => {
const props = useMemo<IDEProviderProps>(
() => ({
containerModules,
container,
plugins: createDefaultPreset<IDEClientContext>(options),
customPluginContext: c => IDEClientContext.create(c),
}),
[],
);
return (
<IDEProvider {...props} ref={ref}>
<>
<IDERenderer className={className} />
{children}
</>
</IDEProvider>
);
};
export const IDEClient = forwardRef(IDEClientWithRef);

View 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.
*/
export { IDEClient, type IDEClientProps } from './ide-client';

View File

@@ -0,0 +1,47 @@
/*
* 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.
*/
/* eslint-disable @typescript-eslint/no-empty-function */
import { inject, injectable } from 'inversify';
import {
OpenerService,
NavigationService,
type CommandContribution,
type CommandRegistry,
type LifecycleContribution,
} from '@coze-project-ide/core';
@injectable()
export class ClientDefaultContribution
implements CommandContribution, LifecycleContribution
{
@inject(NavigationService)
protected readonly navigationService: NavigationService;
@inject(OpenerService)
protected readonly openerService: OpenerService;
/**
* IDE 初始化阶段
*/
onInit() {}
/**
* 注册 commands
* @param registry
*/
registerCommands(registry: CommandRegistry) {}
}

View File

@@ -0,0 +1,106 @@
/*
* 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 { bindContributions } from '@flowgram-adapter/common';
import { createHistoryPlugin } from '@flowgram-adapter/common';
import {
createViewPlugin,
createContextMenuPlugin,
} from '@coze-project-ide/view';
import {
OpenHandler,
createEventPlugin,
createPreferencesPlugin,
CommandContribution,
createCommandPlugin,
createResourcePlugin,
createStylesPlugin,
type PluginsProvider,
type Plugin,
createShortcutsPlugin,
createLifecyclePlugin,
LifecycleContribution,
createNavigationPlugin,
createLabelPlugin,
} from '@coze-project-ide/core';
import { type IDEClientOptions, type IDEClientContext } from './types';
import { ClientDefaultContribution } from './contributions/client-default-contribution';
export function createDefaultPreset<CTX extends IDEClientContext>(
optionsProvider: (ctx: CTX) => IDEClientOptions,
): PluginsProvider<CTX> {
return (ctx: CTX) => {
const opts = optionsProvider(ctx);
const plugins: Plugin[] = [];
/**
* 注册内置插件
*/
plugins.push(
createResourcePlugin(opts.resource || {}), // 资源系统
createViewPlugin(
opts.view || {
widgetFactories: [],
defaultLayoutData: {
activityBarItems: [],
defaultWidgets: [],
},
},
), // 布局系统
// Breaking changebw 额外从业务侧引入
createNavigationPlugin(opts.navigation || {}),
createCommandPlugin(opts.command || {}), // 指令注册
createHistoryPlugin(opts.history || {}), // 历史注册
createLifecyclePlugin(opts), // IDE 生命周期注册
createLabelPlugin(opts.label || {}), // 标签注册
createShortcutsPlugin(opts.shortcut || {}), // 快捷键
createPreferencesPlugin(opts.preferences || {}), // 偏好设置
createStylesPlugin({}),
createContextMenuPlugin(), // 右键菜单注册
createEventPlugin(), // 全局事件注册
);
/**
* client 扩展
*/
plugins.push(
createLifecyclePlugin({
onBind({ bind }) {
bindContributions(bind, ClientDefaultContribution, [
CommandContribution,
LifecycleContribution,
]);
if (opts.openHandlers) {
opts.openHandlers.forEach(handler => {
if (typeof handler === 'function') {
bind(handler).toSelf().inSingletonScope();
bind(OpenHandler).toService(handler);
} else {
bind(OpenHandler).toConstantValue(handler);
}
});
}
},
}),
);
/**
* 注册业务扩展的插件
*/
if (opts.plugins) {
plugins.push(...opts.plugins);
}
return plugins;
};
}

View File

@@ -0,0 +1,69 @@
/*
* 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 * from '@coze-project-ide/core';
export {
type CustomTitleType,
type ViewOptionRegisterService,
type CustomPreferenceConfig,
type CustomTitleChanged,
LayoutPanelType,
ToolbarAlign,
ReactWidget,
ViewManager,
WidgetFactory,
WidgetManager,
CurrentResourceContext,
ReactWidgetContext,
ViewContribution,
useCurrentWidget,
useCurrentWidgetFromArea,
useCurrentResource,
Widget,
StatefulWidget,
ApplicationShell,
LayoutRestorer,
CustomPreferenceContribution,
ViewService,
FlowDockPanel,
HoverService,
MenuService,
DebugService,
DEBUG_BAR_DRAGGABLE,
SplitWidget,
BoxLayout,
DockLayout,
BoxPanel,
SplitLayout,
SplitPanel,
createBoxLayout,
createSplitLayout,
PerfectScrollbar,
DISABLE_HANDLE_EVENT,
TabBarToolbar,
ACTIVITY_BAR_CONTENT,
ViewRenderer,
DragService,
CustomTabBar,
TabBar,
type DragPropsType,
type PresetConfigType,
type ToolbarItem,
} from '@coze-project-ide/view';
export { createDefaultPreset } from './create-default-preset';
export { type IDEClientOptions, IDEClientContext } from './types';
export * from './components';

View 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.
*/
export { type IDEClientOptions, IDEClientContext } from './options';

View File

@@ -0,0 +1,86 @@
/*
* 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.
*/
/* eslint-disable @typescript-eslint/no-namespace */
import { type interfaces } from 'inversify';
import { type AsClass } from '@flowgram-adapter/common';
import {
type HistoryPluginOptions,
HistoryService,
} from '@flowgram-adapter/common';
import { type ViewPluginOptions } from '@coze-project-ide/view';
import {
type OpenHandler,
type NavigationPluginOptions,
type CommandPluginOptions,
CommandService,
type ShortcutsPluginOptions,
ResourceService,
type ResourcePluginOptions,
type LabelPluginOptions,
type PreferencesPluginOptions,
type URI,
type PluginContext,
type Plugin,
type LifecycleContribution,
} from '@coze-project-ide/core';
export interface IDEClientContext extends PluginContext {
resourceService: ResourceService;
historyService: HistoryService;
commandService: CommandService;
}
export namespace IDEClientContext {
export function create(container: interfaces.Container): IDEClientContext {
return {
container,
get resourceService() {
return container.get<ResourceService>(ResourceService)!;
},
get historyService() {
return container.get<HistoryService>(HistoryService)!;
},
get commandService() {
return container.get<CommandService>(CommandService)!;
},
get<T>(identifier: interfaces.ServiceIdentifier<T>): T {
return container.get<T>(identifier);
},
getAll<T>(identifier: interfaces.ServiceIdentifier<T>): T[] {
return container.getAll<T>(identifier);
},
};
}
}
export interface HandlerItem {
canHandle: (uri: URI) => number;
open: (uri: URI) => Promise<void>;
}
export interface IDEClientOptions extends LifecycleContribution {
openHandlers?: (AsClass<OpenHandler> | OpenHandler)[];
resource?: ResourcePluginOptions;
view?: ViewPluginOptions;
navigation?: NavigationPluginOptions;
command?: CommandPluginOptions;
history?: HistoryPluginOptions;
label?: LabelPluginOptions;
shortcut?: ShortcutsPluginOptions;
preferences?: PreferencesPluginOptions;
plugins?: Plugin[];
}

View File

@@ -0,0 +1,34 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "@coze-arch/ts-config/tsconfig.web.json",
"compilerOptions": {
"baseUrl": "./",
"paths": {},
"jsx": "react",
"isolatedModules": true,
"strictNullChecks": true,
"strictPropertyInitialization": false,
"types": ["react", "react-dom"],
"rootDir": "./src",
"outDir": "./lib-ts",
"tsBuildInfoFile": "./lib-ts/tsconfig.build.tsbuildinfo"
},
"include": ["./src", "./src/**/*.json"],
"references": [
{
"path": "../../common/flowgram-adapter/common/tsconfig.build.json"
},
{
"path": "../../../config/eslint-config/tsconfig.build.json"
},
{
"path": "../../../config/ts-config/tsconfig.build.json"
},
{
"path": "../core/tsconfig.build.json"
},
{
"path": "../view/tsconfig.build.json"
}
]
}

View File

@@ -0,0 +1,15 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"exclude": ["**/*"],
"compilerOptions": {
"composite": true
},
"references": [
{
"path": "./tsconfig.build.json"
},
{
"path": "./tsconfig.misc.json"
}
]
}

View File

@@ -0,0 +1,11 @@
{
"extends": "@coze-arch/ts-config/tsconfig.web.json",
"$schema": "https://json.schemastore.org/tsconfig",
"include": ["__mocks__", "__tests__", "vitest.config.ts", "vitest.setup.ts"],
"exclude": ["**/node_modules", "./dist"],
"references": [
{
"path": "./tsconfig.build.json"
}
]
}