feat: manually mirror opencoze's code from bytedance
Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
18
frontend/packages/agent-ide/tool/src/utils/error.ts
Normal file
18
frontend/packages/agent-ide/tool/src/utils/error.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* 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 const generateError = (message: string) =>
|
||||
new Error(`[Bot Platform Tool Hooks]: ${message}`);
|
||||
29
frontend/packages/agent-ide/tool/src/utils/has-valid-key.ts
Normal file
29
frontend/packages/agent-ide/tool/src/utils/has-valid-key.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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, { type ReactElement, type ReactNode } from 'react';
|
||||
|
||||
import { type AgentSkillKey } from '@coze-agent-ide/tool-config';
|
||||
|
||||
export function hasValidAgentSkillKey(
|
||||
child: ReactNode,
|
||||
): child is ReactElement<unknown> & { key: AgentSkillKey } {
|
||||
return (
|
||||
React.isValidElement(child) &&
|
||||
child.key !== null &&
|
||||
typeof child.key === 'string'
|
||||
);
|
||||
}
|
||||
24
frontend/packages/agent-ide/tool/src/utils/is-tool-key.ts
Normal file
24
frontend/packages/agent-ide/tool/src/utils/is-tool-key.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* 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 AbilityKey,
|
||||
type AbilityScope,
|
||||
type ToolKey,
|
||||
} from '@coze-agent-ide/tool-config';
|
||||
|
||||
export const isToolKey = (_?: AbilityKey, scope?: AbilityScope): _ is ToolKey =>
|
||||
scope === 'tool';
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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 NonNullableType } from '../typings/index';
|
||||
|
||||
export const isValidContext = <T extends object>(
|
||||
context: T,
|
||||
): context is NonNullableType<T> =>
|
||||
Object.keys(context)
|
||||
.map(keyName => context[keyName as keyof T])
|
||||
.reduce(
|
||||
(prevResult, currentProperty) => prevResult && currentProperty !== null,
|
||||
true,
|
||||
);
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
import { type AbilityKey } from '@coze-agent-ide/tool-config';
|
||||
import { ModelFuncConfigType } from '@coze-arch/bot-api/developer_api';
|
||||
|
||||
// AbilityKey 到 ModelFuncConfigType 的映射
|
||||
const abilityKeyFuncConfigTypeMap: {
|
||||
// 确保每个 key 这里都有配置
|
||||
[key in AbilityKey]: ModelFuncConfigType | null;
|
||||
} = {
|
||||
plugin: ModelFuncConfigType.Plugin,
|
||||
workflow: ModelFuncConfigType.Workflow,
|
||||
knowledge: null,
|
||||
imageflow: ModelFuncConfigType.ImageFlow,
|
||||
variable: ModelFuncConfigType.Variable,
|
||||
database: ModelFuncConfigType.Database,
|
||||
longTermMemory: ModelFuncConfigType.LongTermMemory,
|
||||
fileBox: ModelFuncConfigType.FileBox,
|
||||
trigger: ModelFuncConfigType.Trigger,
|
||||
onboarding: ModelFuncConfigType.Onboarding,
|
||||
suggest: ModelFuncConfigType.Suggestion,
|
||||
voice: ModelFuncConfigType.TTS,
|
||||
background: ModelFuncConfigType.BackGroundImage,
|
||||
document: ModelFuncConfigType.KnowledgeText,
|
||||
table: ModelFuncConfigType.KnowledgeTable,
|
||||
photo: ModelFuncConfigType.KnowledgePhoto,
|
||||
shortcut: ModelFuncConfigType.ShortcutCommand,
|
||||
devHooks: ModelFuncConfigType.HookInfo,
|
||||
userInput: ModelFuncConfigType.TTS,
|
||||
};
|
||||
|
||||
export const abilityKey2ModelFunctionConfigType = (abilityKey: AbilityKey) =>
|
||||
abilityKeyFuncConfigTypeMap[abilityKey];
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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 ToolKey,
|
||||
TOOL_KEY_TO_API_STATUS_KEY_MAP,
|
||||
type AbilityKey,
|
||||
type SkillKeyEnum,
|
||||
} from '@coze-agent-ide/tool-config';
|
||||
|
||||
/**
|
||||
* `能力模块主键` 转 `接口定义的属性名` 函数
|
||||
* ⚠️ 命名需参看 @/services/auto-generate/developer_api/namespaces/developer_api > TabDisplayItems
|
||||
*/
|
||||
export const toolKeyToApiStatusKeyTransformer = (
|
||||
$key: AbilityKey | SkillKeyEnum,
|
||||
) => {
|
||||
const apiStatusKey = TOOL_KEY_TO_API_STATUS_KEY_MAP[$key as ToolKey];
|
||||
return apiStatusKey ?? `${$key}_tab_status`;
|
||||
};
|
||||
Reference in New Issue
Block a user