feat: manually mirror opencoze's code from bytedance
Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
5
frontend/packages/workflow/sdk/.stylelintrc.js
Normal file
5
frontend/packages/workflow/sdk/.stylelintrc.js
Normal file
@@ -0,0 +1,5 @@
|
||||
const { defineConfig } = require('@coze-arch/stylelint-config');
|
||||
|
||||
module.exports = defineConfig({
|
||||
extends: [],
|
||||
});
|
||||
84
frontend/packages/workflow/sdk/README.md
Normal file
84
frontend/packages/workflow/sdk/README.md
Normal file
@@ -0,0 +1,84 @@
|
||||
# @coze-workflow/sdk
|
||||
|
||||
workflow对外sdk
|
||||
|
||||
## Overview
|
||||
|
||||
This package is part of the Coze Studio monorepo and provides architecture functionality. It includes component, editor.
|
||||
|
||||
## Getting Started
|
||||
|
||||
### Installation
|
||||
|
||||
Add this package to your `package.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"dependencies": {
|
||||
"@coze-workflow/sdk": "workspace:*"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Then run:
|
||||
|
||||
```bash
|
||||
rush update
|
||||
```
|
||||
|
||||
### Usage
|
||||
|
||||
```typescript
|
||||
import { /* exported functions/components */ } from '@coze-workflow/sdk';
|
||||
|
||||
// Example usage
|
||||
// TODO: Add specific usage examples
|
||||
```
|
||||
|
||||
## Features
|
||||
|
||||
- Component
|
||||
- Editor
|
||||
|
||||
## API Reference
|
||||
|
||||
### Exports
|
||||
|
||||
- `schemaExtractor, nodeResultExtractor`
|
||||
- `ExpressionEditorEvent,
|
||||
ExpressionEditorToken,
|
||||
ExpressionEditorSegmentType,
|
||||
ExpressionEditorSignal,
|
||||
ExpressionEditorLeaf,
|
||||
ExpressionEditorSuggestion,
|
||||
ExpressionEditorCounter,
|
||||
ExpressionEditorRender,
|
||||
ExpressionEditorModel,
|
||||
ExpressionEditorParser,
|
||||
ExpressionEditorTreeHelper,
|
||||
ExpressionEditorValidator,
|
||||
useListeners,
|
||||
useSelectNode,
|
||||
useKeyboardSelect,
|
||||
useRenderEffect,
|
||||
useSuggestionReducer,`
|
||||
|
||||
|
||||
For detailed API documentation, please refer to the TypeScript definitions.
|
||||
|
||||
## Development
|
||||
|
||||
This package is built with:
|
||||
|
||||
- TypeScript
|
||||
- Modern JavaScript
|
||||
- Vitest for testing
|
||||
- ESLint for code quality
|
||||
|
||||
## Contributing
|
||||
|
||||
This package is part of the Coze Studio monorepo. Please follow the monorepo contribution guidelines.
|
||||
|
||||
## License
|
||||
|
||||
Apache-2.0
|
||||
0
frontend/packages/workflow/sdk/__tests__/.gitkeep
Normal file
0
frontend/packages/workflow/sdk/__tests__/.gitkeep
Normal file
@@ -0,0 +1,391 @@
|
||||
/*
|
||||
* 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 mockCanvasSchema = {
|
||||
nodes: [
|
||||
{
|
||||
blocks: [],
|
||||
data: {
|
||||
nodeMeta: {
|
||||
description: '工作流的起始节点,用于设定启动工作流需要的信息',
|
||||
icon: 'icon-Start-v2.jpg',
|
||||
subTitle: '',
|
||||
title: '开始',
|
||||
},
|
||||
outputs: [
|
||||
{
|
||||
name: 'input',
|
||||
required: false,
|
||||
type: 'string',
|
||||
},
|
||||
{
|
||||
defaultValue: '2000',
|
||||
name: 'timeout',
|
||||
required: false,
|
||||
type: 'integer',
|
||||
},
|
||||
],
|
||||
trigger_parameters: [],
|
||||
},
|
||||
edges: null,
|
||||
id: '100001',
|
||||
meta: {
|
||||
position: {
|
||||
x: 180,
|
||||
y: 39,
|
||||
},
|
||||
},
|
||||
type: '1',
|
||||
},
|
||||
{
|
||||
blocks: [],
|
||||
data: {
|
||||
inputs: {
|
||||
inputParameters: [
|
||||
{
|
||||
input: {
|
||||
type: 'string',
|
||||
value: {
|
||||
content: {
|
||||
blockID: '126762',
|
||||
name: 'output',
|
||||
source: 'block-output',
|
||||
},
|
||||
rawMeta: {
|
||||
type: 1,
|
||||
},
|
||||
type: 'ref',
|
||||
},
|
||||
},
|
||||
name: 'output',
|
||||
},
|
||||
],
|
||||
terminatePlan: 'returnVariables',
|
||||
},
|
||||
nodeMeta: {
|
||||
description: '工作流的最终节点,用于返回工作流运行后的结果信息',
|
||||
icon: 'icon-End-v2.jpg',
|
||||
subTitle: '',
|
||||
title: '结束',
|
||||
},
|
||||
},
|
||||
edges: null,
|
||||
id: '900001',
|
||||
meta: {
|
||||
position: {
|
||||
x: 1560,
|
||||
y: 26,
|
||||
},
|
||||
},
|
||||
type: '2',
|
||||
},
|
||||
{
|
||||
blocks: [],
|
||||
data: {
|
||||
inputs: {
|
||||
code: '// 在这里,您可以通过 ‘params’ 获取节点中的输入变量,并通过 \'ret\' 输出结果\n// \'params\' 和 \'ret\' 已经被正确地注入到环境中\n// 下面是一个示例,获取节点输入中参数名为‘input’的值:\n// const input = params.input; \n// 下面是一个示例,输出一个包含多种数据类型的 \'ret\' 对象:\n// const ret = { "name": ‘小明’, "hobbies": [“看书”, “旅游”] };\n\nasync function main({ params }: Args): Promise<Output> {\n const wait = ms => new Promise(resolve => {\n setTimeout(() => resolve(\'请回答问题:\'), ms);\n });\n\n const r = await wait(params.timeout);\n\n // 构建输出对象\n const ret = {\n "key0": r + params.input, // 拼接两次入参 input 的值\n "key1": ["hello", "world"], // 输出一个数组\n "key2": { // 输出一个Object\n "key21": "hi"\n },\n };\n\n return ret;\n}',
|
||||
inputParameters: [
|
||||
{
|
||||
input: {
|
||||
type: 'string',
|
||||
value: {
|
||||
content: {
|
||||
blockID: '100001',
|
||||
name: 'input',
|
||||
source: 'block-output',
|
||||
},
|
||||
rawMeta: {
|
||||
type: 1,
|
||||
},
|
||||
type: 'ref',
|
||||
},
|
||||
},
|
||||
name: 'input',
|
||||
},
|
||||
{
|
||||
input: {
|
||||
type: 'integer',
|
||||
value: {
|
||||
content: {
|
||||
blockID: '100001',
|
||||
name: 'timeout',
|
||||
source: 'block-output',
|
||||
},
|
||||
rawMeta: {
|
||||
type: 2,
|
||||
},
|
||||
type: 'ref',
|
||||
},
|
||||
},
|
||||
name: 'timeout',
|
||||
},
|
||||
],
|
||||
language: 5,
|
||||
settingOnError: {
|
||||
processType: 1,
|
||||
retryTimes: 0,
|
||||
timeoutMs: 60000,
|
||||
},
|
||||
},
|
||||
nodeMeta: {
|
||||
description: '编写代码,处理输入变量来生成返回值',
|
||||
icon: 'icon-Code-v2.jpg',
|
||||
mainColor: '#00B2B2',
|
||||
subTitle: '代码',
|
||||
title: '代码',
|
||||
},
|
||||
outputs: [
|
||||
{
|
||||
name: 'key0',
|
||||
type: 'string',
|
||||
},
|
||||
{
|
||||
name: 'key1',
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
type: 'list',
|
||||
},
|
||||
{
|
||||
name: 'key2',
|
||||
schema: [
|
||||
{
|
||||
name: 'key21',
|
||||
type: 'string',
|
||||
},
|
||||
],
|
||||
type: 'object',
|
||||
},
|
||||
],
|
||||
},
|
||||
edges: null,
|
||||
id: '172934',
|
||||
meta: {
|
||||
position: {
|
||||
x: 640,
|
||||
y: 26,
|
||||
},
|
||||
},
|
||||
type: '5',
|
||||
},
|
||||
{
|
||||
blocks: [],
|
||||
data: {
|
||||
inputs: {
|
||||
inputParameters: [
|
||||
{
|
||||
input: {
|
||||
type: 'string',
|
||||
value: {
|
||||
content: {
|
||||
blockID: '172934',
|
||||
name: 'key0',
|
||||
source: 'block-output',
|
||||
},
|
||||
rawMeta: {
|
||||
type: 1,
|
||||
},
|
||||
type: 'ref',
|
||||
},
|
||||
},
|
||||
name: 'input',
|
||||
},
|
||||
],
|
||||
llmParam: [
|
||||
{
|
||||
input: {
|
||||
type: 'integer',
|
||||
value: {
|
||||
content: '1737521813',
|
||||
rawMeta: {
|
||||
type: 2,
|
||||
},
|
||||
type: 'literal',
|
||||
},
|
||||
},
|
||||
name: 'modelType',
|
||||
},
|
||||
{
|
||||
input: {
|
||||
type: 'string',
|
||||
value: {
|
||||
content: '豆包·1.5·Pro·32k',
|
||||
rawMeta: {
|
||||
type: 1,
|
||||
},
|
||||
type: 'literal',
|
||||
},
|
||||
},
|
||||
name: 'modleName',
|
||||
},
|
||||
{
|
||||
input: {
|
||||
type: 'string',
|
||||
value: {
|
||||
content: 'balance',
|
||||
rawMeta: {
|
||||
type: 1,
|
||||
},
|
||||
type: 'literal',
|
||||
},
|
||||
},
|
||||
name: 'generationDiversity',
|
||||
},
|
||||
{
|
||||
input: {
|
||||
type: 'float',
|
||||
value: {
|
||||
content: '0.8',
|
||||
rawMeta: {
|
||||
type: 4,
|
||||
},
|
||||
type: 'literal',
|
||||
},
|
||||
},
|
||||
name: 'temperature',
|
||||
},
|
||||
{
|
||||
input: {
|
||||
type: 'integer',
|
||||
value: {
|
||||
content: '4096',
|
||||
rawMeta: {
|
||||
type: 2,
|
||||
},
|
||||
type: 'literal',
|
||||
},
|
||||
},
|
||||
name: 'maxTokens',
|
||||
},
|
||||
{
|
||||
input: {
|
||||
type: 'integer',
|
||||
value: {
|
||||
content: '2',
|
||||
rawMeta: {
|
||||
type: 2,
|
||||
},
|
||||
type: 'literal',
|
||||
},
|
||||
},
|
||||
name: 'responseFormat',
|
||||
},
|
||||
{
|
||||
input: {
|
||||
type: 'string',
|
||||
value: {
|
||||
content: '{{input}}',
|
||||
rawMeta: {
|
||||
type: 1,
|
||||
},
|
||||
type: 'literal',
|
||||
},
|
||||
},
|
||||
name: 'prompt',
|
||||
},
|
||||
{
|
||||
input: {
|
||||
type: 'boolean',
|
||||
value: {
|
||||
content: false,
|
||||
rawMeta: {
|
||||
type: 3,
|
||||
},
|
||||
type: 'literal',
|
||||
},
|
||||
},
|
||||
name: 'enableChatHistory',
|
||||
},
|
||||
{
|
||||
input: {
|
||||
type: 'integer',
|
||||
value: {
|
||||
content: '3',
|
||||
rawMeta: {
|
||||
type: 2,
|
||||
},
|
||||
type: 'literal',
|
||||
},
|
||||
},
|
||||
name: 'chatHistoryRound',
|
||||
},
|
||||
{
|
||||
input: {
|
||||
type: 'string',
|
||||
value: {
|
||||
content: '',
|
||||
rawMeta: {
|
||||
type: 1,
|
||||
},
|
||||
type: 'literal',
|
||||
},
|
||||
},
|
||||
name: 'systemPrompt',
|
||||
},
|
||||
],
|
||||
settingOnError: {
|
||||
processType: 1,
|
||||
retryTimes: 0,
|
||||
timeoutMs: 180000,
|
||||
},
|
||||
},
|
||||
nodeMeta: {
|
||||
description: '调用大语言模型,使用变量和提示词生成回复',
|
||||
icon: 'icon-LLM-v2.jpg',
|
||||
mainColor: '#5C62FF',
|
||||
subTitle: '大模型',
|
||||
title: '大模型',
|
||||
},
|
||||
outputs: [
|
||||
{
|
||||
name: 'output',
|
||||
type: 'string',
|
||||
},
|
||||
],
|
||||
version: '3',
|
||||
},
|
||||
edges: null,
|
||||
id: '126762',
|
||||
meta: {
|
||||
position: {
|
||||
x: 1100,
|
||||
y: 0,
|
||||
},
|
||||
},
|
||||
type: '3',
|
||||
},
|
||||
],
|
||||
edges: [
|
||||
{
|
||||
sourceNodeID: '100001',
|
||||
targetNodeID: '172934',
|
||||
sourcePortID: '',
|
||||
},
|
||||
{
|
||||
sourceNodeID: '126762',
|
||||
targetNodeID: '900001',
|
||||
sourcePortID: '',
|
||||
},
|
||||
{
|
||||
sourceNodeID: '172934',
|
||||
targetNodeID: '126762',
|
||||
sourcePortID: '',
|
||||
},
|
||||
],
|
||||
versions: {
|
||||
loop: 'v2',
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* 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 mockNodeResults = [
|
||||
{
|
||||
NodeName: 'start-node',
|
||||
NodeType: 'Start',
|
||||
errorInfo: '',
|
||||
errorLevel: '',
|
||||
executeId: '7509801470167547958',
|
||||
extra: '',
|
||||
input: '{"input":"世界上有多少个国家?","timeout":2000}',
|
||||
logVersion: 1,
|
||||
needAsync: false,
|
||||
nodeExeCost: '0.000s',
|
||||
nodeId: '100001',
|
||||
nodeStatus: 3,
|
||||
output: '{"input":"世界上有多少个国家?","timeout":2000}',
|
||||
raw_output: '{"input":"世界上有多少个国家?","timeout":2000}',
|
||||
},
|
||||
{
|
||||
NodeName: '结束',
|
||||
NodeType: 'End',
|
||||
errorInfo: '',
|
||||
errorLevel: '',
|
||||
executeId: '7509801470167547958',
|
||||
extra:
|
||||
'{"current_sub_execute_id":7509801470167547958,"response_extra":{"_WORKFLOW_INPUT_COST":"0","_WORKFLOW_INPUT_TOKEN":"19","_WORKFLOW_MODEL_CLASS":"9","_WORKFLOW_OUTPUT_COST":"0","_WORKFLOW_OUTPUT_TOKEN":"81","terminal_plan":1},"uuid":"1888900664","versions":{"commit_id":"Bot_7509424857970901004_Dev_3382534830832013_7509801338772242444","workflow_version":"v0.0.1"}}',
|
||||
input:
|
||||
'{"output":"截至2024年7月,世界上共有233个国家和地区,其中国家有197个(主权国家195个),地区有36个。\\n\\n联合国会员国目前有193个,此外梵蒂冈是联合国观察员国,巴勒斯坦是联合国观察员实体,这两个在国际上也被广泛承认为国家。 "}',
|
||||
logVersion: 1,
|
||||
needAsync: false,
|
||||
nodeExeCost: '0.000s',
|
||||
nodeId: '900001',
|
||||
nodeStatus: 3,
|
||||
output:
|
||||
'{"output":"截至2024年7月,世界上共有233个国家和地区,其中国家有197个(主权国家195个),地区有36个。\\n\\n联合国会员国目前有193个,此外梵蒂冈是联合国观察员国,巴勒斯坦是联合国观察员实体,这两个在国际上也被广泛承认为国家。 "}',
|
||||
tokenAndCost: {},
|
||||
},
|
||||
{
|
||||
NodeName: '代码',
|
||||
NodeType: 'Code',
|
||||
errorInfo: '',
|
||||
errorLevel: '',
|
||||
executeId: '7509801470167547958',
|
||||
extra:
|
||||
'{"current_sub_execute_id":7509801470167547958,"response_extra":{},"uuid":"1182674096","versions":{"commit_id":"Bot_7509424857970901004_Dev_3382534830832013_7509801338772242444","workflow_version":"v0.0.1"}}',
|
||||
input: '{"input":"世界上有多少个国家?","timeout":2000}',
|
||||
logVersion: 1,
|
||||
needAsync: false,
|
||||
nodeExeCost: '2s',
|
||||
nodeId: '172934',
|
||||
nodeStatus: 3,
|
||||
output:
|
||||
'{"key0":"请回答问题:世界上有多少个国家?","key1":["hello","world"],"key2":{"key21":"hi"}}',
|
||||
raw_output:
|
||||
'{"key0":"请回答问题:世界上有多少个国家?","key1":["hello","world"],"key2":{"key21":"hi"}}',
|
||||
tokenAndCost: {},
|
||||
},
|
||||
{
|
||||
NodeName: '大模型',
|
||||
NodeType: 'LLM',
|
||||
errorInfo: '',
|
||||
errorLevel: '',
|
||||
executeId: '7509801470167547958',
|
||||
extra:
|
||||
'{"current_sub_execute_id":7509801470167547958,"response_extra":{"fc_called_detail":{},"reasoning_content":""},"uuid":"1494046291","versions":{"commit_id":"Bot_7509424857970901004_Dev_3382534830832013_7509801338772242444","workflow_version":"v0.0.1"}}',
|
||||
input: '{"input":"请回答问题:世界上有多少个国家?"}',
|
||||
logVersion: 1,
|
||||
needAsync: false,
|
||||
nodeExeCost: '3s',
|
||||
nodeId: '126762',
|
||||
nodeStatus: 3,
|
||||
output:
|
||||
'{"output":"截至2024年7月,世界上共有233个国家和地区,其中国家有197个(主权国家195个),地区有36个。\\n\\n联合国会员国目前有193个,此外梵蒂冈是联合国观察员国,巴勒斯坦是联合国观察员实体,这两个在国际上也被广泛承认为国家。 "}',
|
||||
raw_output:
|
||||
'截至2024年7月,世界上共有233个国家和地区,其中国家有197个(主权国家195个),地区有36个。\n\n联合国会员国目前有193个,此外梵蒂冈是联合国观察员国,巴勒斯坦是联合国观察员实体,这两个在国际上也被广泛承认为国家。 ',
|
||||
tokenAndCost: {
|
||||
inputCost: '$0.00',
|
||||
inputTokens: '19 Tokens',
|
||||
outputCost: '$0.00',
|
||||
outputTokens: '81 Tokens',
|
||||
totalCost: '$0.00',
|
||||
totalTokens: '100 Tokens',
|
||||
},
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,118 @@
|
||||
[
|
||||
{
|
||||
"caseResult": [
|
||||
{
|
||||
"dataList": [
|
||||
{
|
||||
"data": {
|
||||
"input": "世界上有多少个国家?",
|
||||
"timeout": 2000,
|
||||
},
|
||||
"title": "输入",
|
||||
},
|
||||
],
|
||||
"imgList": [],
|
||||
},
|
||||
],
|
||||
"isBatch": undefined,
|
||||
"nodeId": "100001",
|
||||
"nodeType": "1",
|
||||
},
|
||||
{
|
||||
"caseResult": [
|
||||
{
|
||||
"dataList": [
|
||||
{
|
||||
"data": {
|
||||
"output": "截至2024年7月,世界上共有233个国家和地区,其中国家有197个(主权国家195个),地区有36个。
|
||||
|
||||
联合国会员国目前有193个,此外梵蒂冈是联合国观察员国,巴勒斯坦是联合国观察员实体,这两个在国际上也被广泛承认为国家。 ",
|
||||
},
|
||||
"title": "输出变量",
|
||||
},
|
||||
],
|
||||
"imgList": [],
|
||||
},
|
||||
],
|
||||
"isBatch": undefined,
|
||||
"nodeId": "900001",
|
||||
"nodeType": "2",
|
||||
},
|
||||
{
|
||||
"caseResult": [
|
||||
{
|
||||
"dataList": [
|
||||
{
|
||||
"data": {
|
||||
"input": "世界上有多少个国家?",
|
||||
"timeout": 2000,
|
||||
},
|
||||
"title": "输入",
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"key0": "请回答问题:世界上有多少个国家?",
|
||||
"key1": [
|
||||
"hello",
|
||||
"world",
|
||||
],
|
||||
"key2": {
|
||||
"key21": "hi",
|
||||
},
|
||||
},
|
||||
"title": "原始输出",
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"key0": "请回答问题:世界上有多少个国家?",
|
||||
"key1": [
|
||||
"hello",
|
||||
"world",
|
||||
],
|
||||
"key2": {
|
||||
"key21": "hi",
|
||||
},
|
||||
},
|
||||
"title": "最终输出",
|
||||
},
|
||||
],
|
||||
"imgList": [],
|
||||
},
|
||||
],
|
||||
"isBatch": undefined,
|
||||
"nodeId": "172934",
|
||||
"nodeType": "5",
|
||||
},
|
||||
{
|
||||
"caseResult": [
|
||||
{
|
||||
"dataList": [
|
||||
{
|
||||
"data": {
|
||||
"input": "请回答问题:世界上有多少个国家?",
|
||||
},
|
||||
"title": "输入",
|
||||
},
|
||||
{
|
||||
"data": "截至2024年7月,世界上共有233个国家和地区,其中国家有197个(主权国家195个),地区有36个。
|
||||
|
||||
联合国会员国目前有193个,此外梵蒂冈是联合国观察员国,巴勒斯坦是联合国观察员实体,这两个在国际上也被广泛承认为国家。 ",
|
||||
"title": "原始输出",
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"output": "截至2024年7月,世界上共有233个国家和地区,其中国家有197个(主权国家195个),地区有36个。
|
||||
|
||||
联合国会员国目前有193个,此外梵蒂冈是联合国观察员国,巴勒斯坦是联合国观察员实体,这两个在国际上也被广泛承认为国家。 ",
|
||||
},
|
||||
"title": "最终输出",
|
||||
},
|
||||
],
|
||||
"imgList": [],
|
||||
},
|
||||
],
|
||||
"isBatch": undefined,
|
||||
"nodeId": "126762",
|
||||
"nodeType": "3",
|
||||
},
|
||||
]
|
||||
@@ -0,0 +1,20 @@
|
||||
[
|
||||
{
|
||||
"nodeId": "172934",
|
||||
"nodeType": "5",
|
||||
"properties": {
|
||||
"title": "代码",
|
||||
},
|
||||
},
|
||||
{
|
||||
"nodeId": "126762",
|
||||
"nodeType": "3",
|
||||
"properties": {
|
||||
"llmParam": {
|
||||
"prompt": "{{input}}",
|
||||
"systemPrompt": "",
|
||||
},
|
||||
"title": "大模型",
|
||||
},
|
||||
},
|
||||
]
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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 { vi, describe, it, expect } from 'vitest';
|
||||
import { type WorkflowJSON } from '@coze-workflow/base';
|
||||
|
||||
import { mockNodeResults } from '../__mock_data__/node-results';
|
||||
import { mockCanvasSchema } from '../__mock_data__/canvas-schema';
|
||||
import { nodeResultExtractor } from '../../src/utils';
|
||||
|
||||
vi.mock('lottie-web', () => ({}));
|
||||
describe('node-result-extractor test in @coze-workflow/sdk', () => {
|
||||
it('should extract node result', async () => {
|
||||
const result = nodeResultExtractor({
|
||||
nodeResults: mockNodeResults,
|
||||
schema: mockCanvasSchema as unknown as WorkflowJSON,
|
||||
});
|
||||
await expect(result).toMatchFileSnapshot(
|
||||
'./__snapshots__/node-result-extractor.test.ts.snap',
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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 { vi, describe, it, expect } from 'vitest';
|
||||
import {
|
||||
type SchemaExtractorConfig,
|
||||
SchemaExtractorParserName,
|
||||
StandardNodeType,
|
||||
type WorkflowJSON,
|
||||
} from '@coze-workflow/base';
|
||||
|
||||
import { mockCanvasSchema } from '../__mock_data__/canvas-schema';
|
||||
import { schemaExtractor } from '../../src/utils';
|
||||
|
||||
vi.mock('lottie-web', () => ({}));
|
||||
|
||||
const config: SchemaExtractorConfig = {
|
||||
[StandardNodeType.Code]: [
|
||||
{
|
||||
name: 'title',
|
||||
path: 'nodeMeta.title',
|
||||
},
|
||||
],
|
||||
[StandardNodeType.LLM]: [
|
||||
{
|
||||
name: 'title',
|
||||
path: 'nodeMeta.title',
|
||||
},
|
||||
{
|
||||
name: 'llmParam',
|
||||
path: 'inputs.llmParam',
|
||||
parser: SchemaExtractorParserName.LLM_PARAM,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
describe('schema-extractor test in @coze-workflow/sdk', () => {
|
||||
it('should extract schema result', async () => {
|
||||
const result = schemaExtractor({
|
||||
schema: mockCanvasSchema as unknown as WorkflowJSON,
|
||||
config,
|
||||
});
|
||||
await expect(result).toMatchFileSnapshot(
|
||||
'./__snapshots__/schema-extractor.test.ts.snap',
|
||||
);
|
||||
});
|
||||
});
|
||||
12
frontend/packages/workflow/sdk/config/rush-project.json
Normal file
12
frontend/packages/workflow/sdk/config/rush-project.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"operationSettings": [
|
||||
{
|
||||
"operationName": "test:cov",
|
||||
"outputFolderNames": ["coverage"]
|
||||
},
|
||||
{
|
||||
"operationName": "ts-check",
|
||||
"outputFolderNames": ["./dist"]
|
||||
}
|
||||
]
|
||||
}
|
||||
7
frontend/packages/workflow/sdk/eslint.config.js
Normal file
7
frontend/packages/workflow/sdk/eslint.config.js
Normal file
@@ -0,0 +1,7 @@
|
||||
const { defineConfig } = require('@coze-arch/eslint-config');
|
||||
|
||||
module.exports = defineConfig({
|
||||
packageRoot: __dirname,
|
||||
preset: 'web',
|
||||
rules: {},
|
||||
});
|
||||
47
frontend/packages/workflow/sdk/package.json
Normal file
47
frontend/packages/workflow/sdk/package.json
Normal file
@@ -0,0 +1,47 @@
|
||||
{
|
||||
"name": "@coze-workflow/sdk",
|
||||
"version": "0.0.1",
|
||||
"description": "workflow对外sdk",
|
||||
"license": "Apache-2.0",
|
||||
"author": "lvxinsheng@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-workflow/base": "workspace:*",
|
||||
"@coze-workflow/components": "workspace:*"
|
||||
},
|
||||
"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",
|
||||
"stylelint": "^15.11.0",
|
||||
"vitest": "~3.0.5"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": ">=18.2.0",
|
||||
"react-dom": ">=18.2.0"
|
||||
}
|
||||
}
|
||||
|
||||
50
frontend/packages/workflow/sdk/src/index.ts
Normal file
50
frontend/packages/workflow/sdk/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 { schemaExtractor, nodeResultExtractor } from './utils';
|
||||
export {
|
||||
ExpressionEditorEvent,
|
||||
ExpressionEditorToken,
|
||||
ExpressionEditorSegmentType,
|
||||
ExpressionEditorSignal,
|
||||
ExpressionEditorLeaf,
|
||||
ExpressionEditorSuggestion,
|
||||
ExpressionEditorCounter,
|
||||
ExpressionEditorRender,
|
||||
ExpressionEditorModel,
|
||||
ExpressionEditorParser,
|
||||
ExpressionEditorTreeHelper,
|
||||
ExpressionEditorValidator,
|
||||
useListeners,
|
||||
useSelectNode,
|
||||
useKeyboardSelect,
|
||||
useRenderEffect,
|
||||
useSuggestionReducer,
|
||||
} from '@coze-workflow/components';
|
||||
|
||||
export type {
|
||||
ExpressionEditorEventParams,
|
||||
ExpressionEditorEventDisposer,
|
||||
ExpressionEditorSegment,
|
||||
ExpressionEditorVariable,
|
||||
ExpressionEditorTreeNode,
|
||||
ExpressionEditorParseData,
|
||||
ExpressionEditorLine,
|
||||
ExpressionEditorValidateData,
|
||||
ExpressionEditorRange,
|
||||
PlaygroundConfigEntity,
|
||||
SelectorBoxConfigEntity,
|
||||
} from '@coze-workflow/components';
|
||||
18
frontend/packages/workflow/sdk/src/utils/index.ts
Normal file
18
frontend/packages/workflow/sdk/src/utils/index.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 { schemaExtractor } from './schema-extractor';
|
||||
export { nodeResultExtractor } from './node-result-extractor';
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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 WorkflowJSON,
|
||||
type NodeResultExtracted,
|
||||
NodeResultExtractor,
|
||||
type NodeResult,
|
||||
} from '@coze-workflow/base';
|
||||
|
||||
export const nodeResultExtractor = (params: {
|
||||
nodeResults: NodeResult[];
|
||||
schema: WorkflowJSON;
|
||||
}): NodeResultExtracted[] => {
|
||||
const { nodeResults, schema } = params;
|
||||
const extractor = new NodeResultExtractor(nodeResults, schema);
|
||||
return extractor.extract();
|
||||
};
|
||||
32
frontend/packages/workflow/sdk/src/utils/schema-extractor.ts
Normal file
32
frontend/packages/workflow/sdk/src/utils/schema-extractor.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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 WorkflowJSON,
|
||||
type SchemaExtractorConfig,
|
||||
type SchemaExtracted,
|
||||
SchemaExtractor,
|
||||
} from '@coze-workflow/base';
|
||||
|
||||
export const schemaExtractor = (params: {
|
||||
schema: WorkflowJSON;
|
||||
config: SchemaExtractorConfig;
|
||||
}): SchemaExtracted[] => {
|
||||
const { schema, config } = params;
|
||||
const extractor = new SchemaExtractor(schema);
|
||||
const extractedSchema: SchemaExtracted[] = extractor.extract(config);
|
||||
return extractedSchema;
|
||||
};
|
||||
38
frontend/packages/workflow/sdk/tsconfig.build.json
Normal file
38
frontend/packages/workflow/sdk/tsconfig.build.json
Normal file
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"extends": "@coze-arch/ts-config/tsconfig.web.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": "./",
|
||||
"paths": {},
|
||||
"types": [],
|
||||
"jsx": "react",
|
||||
"isolatedModules": true,
|
||||
"preserveSymlinks": false,
|
||||
"strictPropertyInitialization": false,
|
||||
"module": "ESNext",
|
||||
"rootDir": "./src",
|
||||
"outDir": "./dist",
|
||||
"tsBuildInfoFile": "dist/tsconfig.build.tsbuildinfo"
|
||||
},
|
||||
"include": ["src"],
|
||||
"references": [
|
||||
{
|
||||
"path": "../base/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../components/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"
|
||||
}
|
||||
],
|
||||
"$schema": "https://json.schemastore.org/tsconfig"
|
||||
}
|
||||
15
frontend/packages/workflow/sdk/tsconfig.json
Normal file
15
frontend/packages/workflow/sdk/tsconfig.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"compilerOptions": {
|
||||
"composite": true
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "./tsconfig.misc.json"
|
||||
}
|
||||
],
|
||||
"exclude": ["**/*"]
|
||||
}
|
||||
23
frontend/packages/workflow/sdk/tsconfig.misc.json
Normal file
23
frontend/packages/workflow/sdk/tsconfig.misc.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"extends": "@coze-arch/ts-config/tsconfig.web.json",
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"include": ["__tests__", "stories", "vitest.config.ts", "tailwind.config.ts"],
|
||||
"exclude": ["**/node_modules", "./dist"],
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.build.json"
|
||||
}
|
||||
],
|
||||
"compilerOptions": {
|
||||
"baseUrl": "./",
|
||||
"paths": {},
|
||||
"types": ["react", "react-dom"],
|
||||
"jsx": "react",
|
||||
"isolatedModules": true,
|
||||
"preserveSymlinks": false,
|
||||
"strictPropertyInitialization": false,
|
||||
"module": "ESNext",
|
||||
"rootDir": "./",
|
||||
"outDir": "./dist"
|
||||
}
|
||||
}
|
||||
27
frontend/packages/workflow/sdk/vitest.config.ts
Normal file
27
frontend/packages/workflow/sdk/vitest.config.ts
Normal file
@@ -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 { defineConfig } from '@coze-arch/vitest-config';
|
||||
|
||||
export default defineConfig(
|
||||
{
|
||||
dirname: __dirname,
|
||||
preset: 'web',
|
||||
},
|
||||
{
|
||||
fixSemi: true,
|
||||
},
|
||||
);
|
||||
Reference in New Issue
Block a user