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,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 { botInputLengthService } from './services';

View File

@@ -0,0 +1,40 @@
/*
* 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 BotInputLengthConfig } from './type';
const CN_INPUT_LENGTH_CONFIG: BotInputLengthConfig = {
botName: 20,
botDescription: 500,
onboarding: 300,
onboardingSuggestion: 50,
suggestionPrompt: 5000,
projectName: 20,
projectDescription: 500,
};
const OVERSEA_INPUT_LENGTH_CONFIG: BotInputLengthConfig = {
botName: 40,
botDescription: 800,
onboarding: 800,
onboardingSuggestion: 90,
suggestionPrompt: 5000,
projectName: 40,
projectDescription: 800,
};
export const getBotInputLengthConfig = () =>
IS_OVERSEA ? OVERSEA_INPUT_LENGTH_CONFIG : CN_INPUT_LENGTH_CONFIG;

View File

@@ -0,0 +1,75 @@
/*
* 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 { cloneDeep } from 'lodash-es';
import GraphemeSplitter from 'grapheme-splitter';
import {
type BotInputLengthConfig,
type WorkInfoOnboardingContent,
} from './type';
import { getBotInputLengthConfig } from './constants';
export class BotInputLengthService {
graphemeSplitter: GraphemeSplitter;
constructor(private getInputLengthConfig: () => BotInputLengthConfig) {
this.graphemeSplitter = new GraphemeSplitter();
}
getInputLengthLimit: (field: keyof BotInputLengthConfig) => number = field =>
this.getInputLengthConfig()[field];
getValueLength: (value: string | undefined) => number = value => {
if (typeof value === 'undefined') {
return 0;
}
return this.graphemeSplitter.countGraphemes(value);
};
sliceStringByMaxLength: (param: {
value: string;
field: keyof BotInputLengthConfig;
}) => string = ({ value, field }) =>
this.graphemeSplitter
.splitGraphemes(value)
.slice(0, this.getInputLengthLimit(field))
.join('');
sliceWorkInfoOnboardingByMaxLength = (
param: WorkInfoOnboardingContent,
): WorkInfoOnboardingContent => {
const { prologue, suggested_questions, suggested_questions_show_mode } =
cloneDeep(param);
return {
prologue: this.sliceStringByMaxLength({
value: prologue,
field: 'onboarding',
}),
suggested_questions: suggested_questions.map(sug => ({
...sug,
content: this.sliceStringByMaxLength({
value: sug.content,
field: 'onboardingSuggestion',
}),
})),
suggested_questions_show_mode,
};
};
}
export const botInputLengthService = new BotInputLengthService(
getBotInputLengthConfig,
);

View File

@@ -0,0 +1,45 @@
/*
* 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 SuggestedQuestionsShowMode } from '@coze-arch/bot-api/playground_api';
export interface BotInputLengthConfig {
/** Agent 名称的长度 */
botName: number;
/** Agent 描述的长度 */
botDescription: number;
/** Agent 开场白的长度 */
onboarding: number;
/** Agent 单条开场白建议的长度 */
onboardingSuggestion: number;
/** 用户问题建议自定义 prompt 长度 */
suggestionPrompt: number;
/** Project 名称的长度 */
projectName: number;
/** Project 描述的长度 */
projectDescription: number;
}
export interface SuggestQuestionMessage {
id: string;
content: string;
highlight?: boolean;
}
export interface WorkInfoOnboardingContent {
prologue: string;
suggested_questions: SuggestQuestionMessage[];
suggested_questions_show_mode: SuggestedQuestionsShowMode;
}

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.
*/
/// <reference types='@coze-arch/bot-typings' />