feat: manually mirror opencoze's code from bytedance
Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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 FC } from 'react';
|
||||
|
||||
type IProps = Record<string, unknown>;
|
||||
|
||||
export const BizMessageInnerAddonBottom: FC<IProps> = () => (
|
||||
<div>hello world</div>
|
||||
);
|
||||
@@ -0,0 +1,18 @@
|
||||
import { type PluginRegistryEntry } from '@coze-common/chat-area';
|
||||
|
||||
import { type PluginBizContext } from './types/biz-context';
|
||||
import { BizPlugin } from './plugin';
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention -- 插件命名大写开头符合预期
|
||||
export const BizPluginRegistry: PluginRegistryEntry<PluginBizContext> = {
|
||||
/**
|
||||
* 贯穿插件生命周期、组件的上下文
|
||||
*/
|
||||
createPluginBizContext() {
|
||||
return {};
|
||||
},
|
||||
/**
|
||||
* 插件本体
|
||||
*/
|
||||
Plugin: BizPlugin,
|
||||
};
|
||||
@@ -0,0 +1,40 @@
|
||||
import {
|
||||
PluginMode,
|
||||
PluginName,
|
||||
WriteableChatAreaPlugin,
|
||||
createCustomComponents,
|
||||
createWriteableLifeCycleServices,
|
||||
} from '@coze-common/chat-area';
|
||||
|
||||
import { type PluginBizContext } from './types/biz-context';
|
||||
import { bizLifeCycleServiceGenerator } from './services/life-cycle';
|
||||
import { BizMessageInnerAddonBottom } from './custom-components/message-inner-addon-bottom';
|
||||
|
||||
export class BizPlugin extends WriteableChatAreaPlugin<PluginBizContext> {
|
||||
/**
|
||||
* 插件类型
|
||||
* PluginMode.Readonly = 只读模式
|
||||
* PluginMode.Writeable = 可写模式
|
||||
*/
|
||||
public pluginMode = PluginMode.Writeable;
|
||||
/**
|
||||
* 插件名称
|
||||
* 请点 PluginName 里面去定义
|
||||
*/
|
||||
public pluginName = PluginName.Demo;
|
||||
|
||||
/**
|
||||
* 生命周期服务
|
||||
*/
|
||||
public lifeCycleServices = createWriteableLifeCycleServices(
|
||||
this,
|
||||
bizLifeCycleServiceGenerator,
|
||||
);
|
||||
|
||||
/**
|
||||
* 自定义组件
|
||||
*/
|
||||
public customComponents = createCustomComponents({
|
||||
MessageInnerBottomSlot: BizMessageInnerAddonBottom,
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import { type WriteableAppLifeCycleServiceGenerator } from '@coze-common/chat-area';
|
||||
|
||||
import { type PluginBizContext } from '../../types/biz-context';
|
||||
|
||||
export const appLifeCycleServiceGenerator: WriteableAppLifeCycleServiceGenerator<
|
||||
PluginBizContext
|
||||
> = plugin => ({});
|
||||
@@ -0,0 +1,7 @@
|
||||
import { type WriteableCommandLifeCycleServiceGenerator } from '@coze-common/chat-area';
|
||||
|
||||
import { type PluginBizContext } from '../../types/biz-context';
|
||||
|
||||
export const commandLifeCycleServiceGenerator: WriteableCommandLifeCycleServiceGenerator<
|
||||
PluginBizContext
|
||||
> = plugin => ({});
|
||||
@@ -0,0 +1,16 @@
|
||||
import { type WriteableLifeCycleServiceGenerator } from '@coze-common/chat-area';
|
||||
|
||||
import { type PluginBizContext } from '../../types/biz-context';
|
||||
import { renderLifeCycleServiceGenerator } from './render';
|
||||
import { messageLifeCycleServiceGenerator } from './message';
|
||||
import { commandLifeCycleServiceGenerator } from './command';
|
||||
import { appLifeCycleServiceGenerator } from './app';
|
||||
|
||||
export const bizLifeCycleServiceGenerator: WriteableLifeCycleServiceGenerator<
|
||||
PluginBizContext
|
||||
> = plugin => ({
|
||||
appLifeCycleService: appLifeCycleServiceGenerator(plugin),
|
||||
messageLifeCycleService: messageLifeCycleServiceGenerator(plugin),
|
||||
commandLifeCycleService: commandLifeCycleServiceGenerator(plugin),
|
||||
renderLifeCycleService: renderLifeCycleServiceGenerator(plugin),
|
||||
});
|
||||
@@ -0,0 +1,7 @@
|
||||
import { type WriteableMessageLifeCycleServiceGenerator } from '@coze-common/chat-area';
|
||||
|
||||
import { type PluginBizContext } from '../../types/biz-context';
|
||||
|
||||
export const messageLifeCycleServiceGenerator: WriteableMessageLifeCycleServiceGenerator<
|
||||
PluginBizContext
|
||||
> = plugin => ({});
|
||||
@@ -0,0 +1,7 @@
|
||||
import { type WriteableRenderLifeCycleServiceGenerator } from '@coze-common/chat-area';
|
||||
|
||||
import { type PluginBizContext } from '../../types/biz-context';
|
||||
|
||||
export const renderLifeCycleServiceGenerator: WriteableRenderLifeCycleServiceGenerator<
|
||||
PluginBizContext
|
||||
> = plugin => ({});
|
||||
@@ -0,0 +1 @@
|
||||
export type PluginBizContext = Record<string, unknown>;
|
||||
1
common/_templates/chat-plugin-writeable-standard/src/typings.d.ts
vendored
Normal file
1
common/_templates/chat-plugin-writeable-standard/src/typings.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/// <reference types='@coze-arch/bot-typings' />
|
||||
Reference in New Issue
Block a user