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,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 {
definePluginCreator,
type PluginCreator,
} from '@flowgram-adapter/free-layout-editor';
import { TestFormService, TestFormServiceImpl } from './test-form-service';
export const createTestRunPlugin: PluginCreator<object> =
definePluginCreator<object>({
onBind({ bind }) {
bind(TestFormService).to(TestFormServiceImpl).inSingletonScope();
},
});

View File

@@ -0,0 +1,26 @@
/*
* 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 { TestRunService } from './test-run-service';
export {
TestRunReporterService,
PickReporterParams,
ReporterEventName,
ReporterParams,
} from './test-run-reporter';
export { createTestRunPlugin } from './create-test-run-plugin';
export { useTestFormService } from './test-form-service';

View File

@@ -0,0 +1,44 @@
/*
* 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 { injectable } from 'inversify';
import { useService } from '@flowgram-adapter/free-layout-editor';
export type FormDataType = any;
export const TestFormService = Symbol('TestFormService');
export interface TestFormService {
/** 表单缓存值 */
cacheValues: Map<string, FormDataType>;
getCacheValues: (id: string) => null | FormDataType;
setCacheValues: (id: string, value: FormDataType) => void;
}
@injectable()
export class TestFormServiceImpl implements TestFormService {
cacheValues = new Map();
getCacheValues(id: string) {
return this.cacheValues.get(id) || null;
}
setCacheValues(id: string, value: FormDataType) {
this.cacheValues.set(id, value);
}
}
export const useTestFormService = () =>
useService<TestFormService>(TestFormService);

View File

@@ -0,0 +1,22 @@
/*
* 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 {
TestRunReporterService,
PickReporterParams,
EventName as ReporterEventName,
Params as ReporterParams,
} from './test-run-reporter-service';

View File

@@ -0,0 +1,101 @@
/*
* 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 TestRunReporterService = Symbol('TestRunReporterService');
export enum EventName {
TryStart = 'workflow_testrun_sdk_try_start',
RunEnd = 'workflow_testrun_sdk_run_end',
/*****************************************************************************
* form 相关
*/
/** 表单 schema 计算 */
FormSchemaGen = 'workflow_testrun_sdk_form_schema_gen',
/** 表单 UI 模式 */
FormRunUIMode = 'workflow_testrun_sdk_form_run_ui_mode',
/** 表单数据填充 */
FormGenDataOrigin = 'workflow_testrun_sdk_form_gen_data_origin',
/** log 相关 */
LogOutputDifference = 'workflow_testrun_sdk_log_output_difference',
LogOutputMarkdown = 'workflow_testrun_sdk_log_output_markdown',
/** trace 相关 */
TraceOpen = 'workflow_testrun_sdk_trace_open',
}
interface WorkflowCommonParams {
space_id?: string;
project_id?: string;
workflow_id?: string;
workflow_mode?: number;
}
export interface Params {
[EventName.TryStart]: WorkflowCommonParams & {
scene: 'toolbar' | 'publish' | 'node' | 'form' | 'trigger';
};
[EventName.RunEnd]: WorkflowCommonParams & {
execute_id?: string;
testrun_type?: 'flow' | 'node' | 'trigger';
testrun_result?: 'success' | 'fail' | 'cancel' | 'error';
};
[EventName.FormSchemaGen]: WorkflowCommonParams & {
node_type?: string;
duration: number;
};
[EventName.FormRunUIMode]: WorkflowCommonParams & {
form_ui_mode: 'form' | 'json';
};
[EventName.FormGenDataOrigin]: WorkflowCommonParams & {
gen_data_origin:
| 'cache'
| 'testset'
| 'history'
| 'ai'
| 'ai_backup'
| 'ai_failed';
};
[EventName.LogOutputDifference]: WorkflowCommonParams & {
is_difference: boolean;
error_msg?: string;
log_node_type?: string;
};
[EventName.LogOutputMarkdown]: WorkflowCommonParams & {
action_type: 'render' | 'preview';
};
[EventName.TraceOpen]: WorkflowCommonParams & {
panel_type?: 'list' | 'detail';
log_id?: string;
};
}
export type PickReporterParams<
T extends EventName,
X extends keyof Params[T],
> = Pick<Params[T], X>;
export interface TestRunReporterService {
/** 日志原始输出异同解析 */
logRawOutputDifference: (
params: Pick<
Params[EventName.LogOutputDifference],
'error_msg' | 'log_node_type' | 'is_difference'
>,
) => void;
/** 日志 Markdown 解析 */
logOutputMarkdown: (
params: PickReporterParams<EventName.LogOutputMarkdown, 'action_type'>,
) => void;
}

View File

@@ -0,0 +1,28 @@
/*
* 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 TestRunService = Symbol('TestRunService');
export interface TestRunService {
/**
* 停止试运行
*/
pauseTestRun: () => void;
/**
* 继续试运行
*/
continueTestRun: () => void;
}