chore: import upstream snapshot with attribution
CI / build (push) Has been cancelled

This commit is contained in:
wehub-resource-sync
2026-07-13 13:09:51 +08:00
commit 0232b4e2bb
3528 changed files with 291404 additions and 0 deletions
@@ -0,0 +1,16 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import { defineFlatConfig } from '@flowgram.ai/eslint-config';
import path from 'path';
import { fileURLToPath } from 'url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
export default defineFlatConfig({
preset: 'base',
packageRoot: __dirname,
});
+47
View File
@@ -0,0 +1,47 @@
{
"name": "@flowgram.ai/runtime-interface",
"version": "0.1.8",
"homepage": "https://flowgram.ai/",
"repository": "https://github.com/bytedance/flowgram.ai",
"license": "MIT",
"type": "module",
"exports": {
"types": "./dist/index.d.ts",
"import": "./dist/esm/index.js",
"require": "./dist/index.js"
},
"main": "./dist/index.js",
"module": "./dist/esm/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist"
],
"scripts": {
"dev": "npm run watch",
"build": "npm run build:fast -- --dts-resolve",
"build:fast": "tsup src/index.ts --format cjs,esm --sourcemap --legacy-output",
"build:watch": "npm run build:fast -- --dts-resolve",
"clean": "rimraf dist",
"test": "exit 0",
"test:cov": "exit 0",
"ts-check": "tsc --noEmit",
"watch": "npm run build:fast -- --dts-resolve --watch --ignore-watch dist",
"lint": "eslint ./src --cache",
"lint:fix": "eslint ./src --fix"
},
"dependencies": {
"zod": "^3.24.4"
},
"devDependencies": {
"@flowgram.ai/eslint-config": "workspace:*",
"@flowgram.ai/ts-config": "workspace:*",
"eslint": "^9.0.0",
"tsup": "^8.0.1",
"typescript": "^5.8.3",
"vitest": "^3.2.4"
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
}
}
@@ -0,0 +1,26 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
export enum FlowGramAPIMethod {
GET = 'GET',
POST = 'POST',
PUT = 'PUT',
DELETE = 'DELETE',
PATCH = 'PATCH',
}
export enum FlowGramAPIName {
ServerInfo = 'ServerInfo',
TaskRun = 'TaskRun',
TaskReport = 'TaskReport',
TaskResult = 'TaskResult',
TaskCancel = 'TaskCancel',
TaskValidate = 'TaskValidate',
}
export enum FlowGramAPIModule {
Info = 'Info',
Task = 'Task',
}
@@ -0,0 +1,24 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import { FlowGramAPIDefines } from './type';
import { TaskValidateDefine } from './task-validate';
import { TaskRunDefine } from './task-run';
import { TaskResultDefine } from './task-result';
import { TaskReportDefine } from './task-report';
import { TaskCancelDefine } from './task-cancel';
import { ServerInfoDefine } from './server-info';
import { FlowGramAPIName } from './constant';
export const FlowGramAPIs: FlowGramAPIDefines = {
[FlowGramAPIName.ServerInfo]: ServerInfoDefine,
[FlowGramAPIName.TaskRun]: TaskRunDefine,
[FlowGramAPIName.TaskReport]: TaskReportDefine,
[FlowGramAPIName.TaskResult]: TaskResultDefine,
[FlowGramAPIName.TaskCancel]: TaskCancelDefine,
[FlowGramAPIName.TaskValidate]: TaskValidateDefine,
};
export const FlowGramAPINames = Object.keys(FlowGramAPIs) as FlowGramAPIName[];
@@ -0,0 +1,15 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
export * from './type';
export * from './define';
export * from './constant';
export * from './task-run';
export * from './server-info';
export * from './task-report';
export * from './task-validate';
export * from './task-result';
export * from './task-cancel';
@@ -0,0 +1,56 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import z from 'zod';
const WorkflowIOZodSchema = z.record(z.string(), z.any());
const WorkflowSnapshotZodSchema = z.object({
id: z.string(),
nodeID: z.string(),
inputs: WorkflowIOZodSchema,
outputs: WorkflowIOZodSchema.optional(),
data: WorkflowIOZodSchema,
branch: z.string().optional(),
});
const WorkflowStatusZodShape = {
status: z.string(),
terminated: z.boolean(),
startTime: z.number(),
endTime: z.number().optional(),
timeCost: z.number(),
};
const WorkflowStatusZodSchema = z.object(WorkflowStatusZodShape);
const WorkflowNodeReportZodSchema = z.object({
id: z.string(),
...WorkflowStatusZodShape,
snapshots: z.array(WorkflowSnapshotZodSchema),
});
const WorkflowReportsZodSchema = z.record(z.string(), WorkflowNodeReportZodSchema);
const WorkflowMessageZodSchema = z.object({
id: z.string(),
type: z.enum(['log', 'info', 'debug', 'error', 'warning']),
message: z.string(),
nodeID: z.string().optional(),
timestamp: z.number(),
});
const WorkflowMessagesZodSchema = z.record(
z.enum(['log', 'info', 'debug', 'error', 'warning']),
z.array(WorkflowMessageZodSchema)
);
export const WorkflowZodSchema = {
Inputs: WorkflowIOZodSchema,
Outputs: WorkflowIOZodSchema,
Status: WorkflowStatusZodSchema,
Snapshot: WorkflowSnapshotZodSchema,
Reports: WorkflowReportsZodSchema,
Messages: WorkflowMessagesZodSchema,
};
@@ -0,0 +1,36 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import z from 'zod';
import { type FlowGramAPIDefine } from '@api/type';
import { FlowGramAPIMethod, FlowGramAPIModule, FlowGramAPIName } from '@api/constant';
export interface ServerInfoInput {}
export interface ServerInfoOutput {
name: string;
title: string;
description: string;
runtime: string;
version: string;
time: string;
}
export const ServerInfoDefine: FlowGramAPIDefine = {
name: FlowGramAPIName.ServerInfo,
method: FlowGramAPIMethod.GET,
path: '/info',
module: FlowGramAPIModule.Info,
schema: {
input: z.undefined(),
output: z.object({
name: z.string(),
runtime: z.string(),
version: z.string(),
time: z.string(),
}),
},
};
@@ -0,0 +1,32 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import z from 'zod';
import { FlowGramAPIDefine } from '@api/type';
import { FlowGramAPIName, FlowGramAPIMethod, FlowGramAPIModule } from '@api/constant';
export interface TaskCancelInput {
taskID: string;
}
export type TaskCancelOutput = {
success: boolean;
};
export const TaskCancelDefine: FlowGramAPIDefine = {
name: FlowGramAPIName.TaskCancel,
method: FlowGramAPIMethod.PUT,
path: '/task/cancel',
module: FlowGramAPIModule.Task,
schema: {
input: z.object({
taskID: z.string(),
}),
output: z.object({
success: z.boolean(),
}),
},
};
@@ -0,0 +1,37 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import z from 'zod';
import { IReport } from '@runtime/index';
import { FlowGramAPIDefine } from '@api/type';
import { WorkflowZodSchema } from '@api/schema';
import { FlowGramAPIName, FlowGramAPIMethod, FlowGramAPIModule } from '@api/constant';
export interface TaskReportInput {
taskID: string;
}
export type TaskReportOutput = IReport | undefined;
export const TaskReportDefine: FlowGramAPIDefine = {
name: FlowGramAPIName.TaskReport,
method: FlowGramAPIMethod.GET,
path: '/task/report',
module: FlowGramAPIModule.Task,
schema: {
input: z.object({
taskID: z.string(),
}),
output: z.object({
id: z.string(),
inputs: WorkflowZodSchema.Inputs,
outputs: WorkflowZodSchema.Outputs,
workflowStatus: WorkflowZodSchema.Status,
reports: WorkflowZodSchema.Reports,
messages: WorkflowZodSchema.Messages,
}),
},
};
@@ -0,0 +1,30 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import z from 'zod';
import { WorkflowOutputs } from '@runtime/index';
import { FlowGramAPIDefine } from '@api/type';
import { WorkflowZodSchema } from '@api/schema';
import { FlowGramAPIName, FlowGramAPIMethod, FlowGramAPIModule } from '@api/constant';
export interface TaskResultInput {
taskID: string;
}
export type TaskResultOutput = WorkflowOutputs | undefined;
export const TaskResultDefine: FlowGramAPIDefine = {
name: FlowGramAPIName.TaskResult,
method: FlowGramAPIMethod.GET,
path: '/task/result',
module: FlowGramAPIModule.Task,
schema: {
input: z.object({
taskID: z.string(),
}),
output: WorkflowZodSchema.Outputs,
},
};
@@ -0,0 +1,36 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import z from 'zod';
import { WorkflowInputs } from '@runtime/index';
import { FlowGramAPIDefine } from '@api/type';
import { WorkflowZodSchema } from '@api/schema';
import { FlowGramAPIMethod, FlowGramAPIModule, FlowGramAPIName } from '@api/constant';
export interface TaskRunInput {
inputs: WorkflowInputs;
schema: string;
}
export interface TaskRunOutput {
taskID: string;
}
export const TaskRunDefine: FlowGramAPIDefine = {
name: FlowGramAPIName.TaskRun,
method: FlowGramAPIMethod.POST,
path: '/task/run',
module: FlowGramAPIModule.Task,
schema: {
input: z.object({
schema: z.string(),
inputs: WorkflowZodSchema.Inputs,
}),
output: z.object({
taskID: z.string(),
}),
},
};
@@ -0,0 +1,35 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import z from 'zod';
import { ValidationResult, WorkflowInputs } from '@runtime/index';
import { FlowGramAPIDefine } from '@api/type';
import { WorkflowZodSchema } from '@api/schema';
import { FlowGramAPIMethod, FlowGramAPIModule, FlowGramAPIName } from '@api/constant';
export interface TaskValidateInput {
inputs: WorkflowInputs;
schema: string;
}
export interface TaskValidateOutput extends ValidationResult {}
export const TaskValidateDefine: FlowGramAPIDefine = {
name: FlowGramAPIName.TaskValidate,
method: FlowGramAPIMethod.POST,
path: '/task/validate',
module: FlowGramAPIModule.Task,
schema: {
input: z.object({
schema: z.string(),
inputs: WorkflowZodSchema.Inputs,
}),
output: z.object({
valid: z.boolean(),
errors: z.array(z.string()).optional(),
}),
},
};
@@ -0,0 +1,23 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import type z from 'zod';
import { FlowGramAPIMethod, FlowGramAPIModule, FlowGramAPIName } from './constant';
export interface FlowGramAPIDefine {
name: FlowGramAPIName;
method: FlowGramAPIMethod;
path: `/${string}`;
module: FlowGramAPIModule;
schema: {
input: z.ZodFirstPartySchemaTypes;
output: z.ZodFirstPartySchemaTypes;
};
}
export interface FlowGramAPIDefines {
[key: string]: FlowGramAPIDefine;
}
@@ -0,0 +1,28 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import type {
FlowGramAPIName,
TaskCancelInput,
TaskCancelOutput,
TaskReportInput,
TaskReportOutput,
TaskResultInput,
TaskResultOutput,
TaskRunInput,
TaskRunOutput,
TaskValidateInput,
TaskValidateOutput,
} from '@api/index';
export interface IRuntimeClient {
[FlowGramAPIName.TaskRun]: (input: TaskRunInput) => Promise<TaskRunOutput | undefined>;
[FlowGramAPIName.TaskReport]: (input: TaskReportInput) => Promise<TaskReportOutput | undefined>;
[FlowGramAPIName.TaskResult]: (input: TaskResultInput) => Promise<TaskResultOutput | undefined>;
[FlowGramAPIName.TaskCancel]: (input: TaskCancelInput) => Promise<TaskCancelOutput | undefined>;
[FlowGramAPIName.TaskValidate]: (
input: TaskValidateInput
) => Promise<TaskValidateOutput | undefined>;
}
+10
View File
@@ -0,0 +1,10 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
export * from './api';
export * from './schema';
export * from './node';
export * from './runtime';
export * from './client';
@@ -0,0 +1,11 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import { WorkflowNodeSchema } from '@schema/node';
import { FlowGramNode } from '@node/constant';
interface BreakNodeData {}
export type BreakNodeSchema = WorkflowNodeSchema<FlowGramNode.Break, BreakNodeData>;
@@ -0,0 +1,22 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import { IFlowValue } from '@schema/value';
import { WorkflowNodeSchema } from '@schema/node';
import { IJsonSchema } from '@schema/json-schema';
import { FlowGramNode } from '@node/constant';
interface CodeNodeData {
title: string;
inputsValues: Record<string, IFlowValue>;
inputs: IJsonSchema<'object'>;
outputs: IJsonSchema<'object'>;
script: {
language: 'javascript';
content: string;
};
}
export type CodeNodeSchema = WorkflowNodeSchema<FlowGramNode.Code, CodeNodeData>;
@@ -0,0 +1,35 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
export enum ConditionOperator {
/** Equal */
EQ = 'eq',
/** Not Equal */
NEQ = 'neq',
/** Greater Than */
GT = 'gt',
/** Greater Than or Equal */
GTE = 'gte',
/** Less Than */
LT = 'lt',
/** Less Than or Equal */
LTE = 'lte',
/** In */
IN = 'in',
/** Not In */
NIN = 'nin',
/** Contains */
CONTAINS = 'contains',
/** Not Contains */
NOT_CONTAINS = 'not_contains',
/** Is Empty */
IS_EMPTY = 'is_empty',
/** Is Not Empty */
IS_NOT_EMPTY = 'is_not_empty',
/** Is True */
IS_TRUE = 'is_true',
/** Is False */
IS_FALSE = 'is_false',
}
@@ -0,0 +1,27 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import { IFlowConstantRefValue, IFlowRefValue } from '@schema/value';
import { WorkflowNodeSchema } from '@schema/node';
import { FlowGramNode } from '@node/constant';
import { ConditionOperator } from './constant';
export { ConditionOperator };
export interface ConditionItem {
key: string;
value: {
left: IFlowRefValue;
operator: ConditionOperator;
right: IFlowConstantRefValue;
};
}
interface ConditionNodeData {
title: string;
conditions: ConditionItem[];
}
export type ConditionNodeSchema = WorkflowNodeSchema<FlowGramNode.Condition, ConditionNodeData>;
@@ -0,0 +1,21 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
export enum FlowGramNode {
Root = 'root',
Start = 'start',
End = 'end',
LLM = 'llm',
Code = 'code',
Condition = 'condition',
Loop = 'loop',
Comment = 'comment',
Group = 'group',
BlockStart = 'block-start',
BlockEnd = 'block-end',
HTTP = 'http',
Break = 'break',
Continue = 'continue',
}
@@ -0,0 +1,11 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import { WorkflowNodeSchema } from '@schema/node';
import { FlowGramNode } from '@node/constant';
interface ContinueNodeData {}
export type ContinueNodeSchema = WorkflowNodeSchema<FlowGramNode.Continue, ContinueNodeData>;
@@ -0,0 +1,17 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import { IFlowConstantRefValue } from '@schema/value';
import { WorkflowNodeSchema } from '@schema/node';
import { IJsonSchema } from '@schema/json-schema';
import { FlowGramNode } from '@node/constant';
interface EndNodeData {
title: string;
inputs: IJsonSchema<'object'>;
inputsValues: Record<string, IFlowConstantRefValue>;
}
export type EndNodeSchema = WorkflowNodeSchema<FlowGramNode.End, EndNodeData>;
@@ -0,0 +1,22 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
export enum HTTPMethod {
Get = 'GET',
Post = 'POST',
Put = 'PUT',
Delete = 'DELETE',
Patch = 'PATCH',
Head = 'HEAD',
}
export enum HTTPBodyType {
None = 'none',
FormData = 'form-data',
XWwwFormUrlencoded = 'x-www-form-urlencoded',
RawText = 'raw-text',
JSON = 'JSON',
Binary = 'binary',
}
@@ -0,0 +1,39 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import { IFlowConstantRefValue, IFlowTemplateValue } from '@schema/value';
import { WorkflowNodeSchema } from '@schema/node';
import { IJsonSchema } from '@schema/json-schema';
import { FlowGramNode } from '@node/constant';
import { HTTPBodyType, HTTPMethod } from './constant';
interface HTTPNodeData {
title: string;
outputs: IJsonSchema<'object'>;
api: {
method: HTTPMethod;
url: IFlowTemplateValue;
};
headers: IJsonSchema<'object'>;
headersValues: Record<string, IFlowConstantRefValue>;
params: IJsonSchema<'object'>;
paramsValues: Record<string, IFlowConstantRefValue>;
body: {
bodyType: HTTPBodyType;
json?: IFlowTemplateValue;
formData?: IJsonSchema<'object'>;
formDataValues?: Record<string, IFlowConstantRefValue>;
rawText?: IFlowTemplateValue;
binary?: IFlowTemplateValue;
xWwwFormUrlencoded?: IJsonSchema<'object'>;
xWwwFormUrlencodedValues?: Record<string, IFlowConstantRefValue>;
};
timeout: {
retryTimes: number;
timeout: number;
};
}
export { HTTPMethod, HTTPBodyType };
export type HTTPNodeSchema = WorkflowNodeSchema<FlowGramNode.HTTP, HTTPNodeData>;
@@ -0,0 +1,15 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
export { FlowGramNode } from './constant';
export { EndNodeSchema } from './end';
export { LLMNodeSchema } from './llm';
export { StartNodeSchema } from './start';
export { LoopNodeSchema } from './loop';
export { ConditionNodeSchema, ConditionOperator, ConditionItem } from './condition';
export { HTTPNodeSchema, HTTPMethod, HTTPBodyType } from './http';
export { CodeNodeSchema } from './code';
export { BreakNodeSchema } from './break';
export { ContinueNodeSchema } from './continue';
@@ -0,0 +1,25 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import { IFlowConstantRefValue, IFlowConstantValue, IFlowTemplateValue } from '@schema/value';
import { WorkflowNodeSchema } from '@schema/node';
import { IJsonSchema } from '@schema/json-schema';
import { FlowGramNode } from '@node/constant';
interface LLMNodeData {
title: string;
inputs: IJsonSchema<'object'>;
outputs: IJsonSchema<'object'>;
inputValues: {
apiKey: IFlowConstantRefValue;
modelType: IFlowConstantRefValue;
baseURL: IFlowConstantRefValue;
temperature: IFlowConstantRefValue;
systemPrompt: IFlowConstantValue | IFlowTemplateValue;
prompt: IFlowConstantValue | IFlowTemplateValue;
};
}
export type LLMNodeSchema = WorkflowNodeSchema<FlowGramNode.LLM, LLMNodeData>;
@@ -0,0 +1,16 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import { IFlowRefValue } from '@schema/value';
import { WorkflowNodeSchema } from '@schema/node';
import { FlowGramNode } from '@node/constant';
interface LoopNodeData {
title: string;
loopFor: IFlowRefValue;
loopOutputs: Record<string, IFlowRefValue>;
}
export type LoopNodeSchema = WorkflowNodeSchema<FlowGramNode.Loop, LoopNodeData>;
@@ -0,0 +1,15 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import { WorkflowNodeSchema } from '@schema/node';
import { IJsonSchema } from '@schema/json-schema';
import { FlowGramNode } from '@node/constant';
interface StartNodeData {
title: string;
outputs: IJsonSchema<'object'>;
}
export type StartNodeSchema = WorkflowNodeSchema<FlowGramNode.Start, StartNodeData>;
@@ -0,0 +1,8 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
export type { VOData } from './value-object';
export type { InvokeParams, WorkflowRuntimeInvoke } from './invoke';
export type { WorkflowInputs, WorkflowOutputs } from './inputs-outputs';
@@ -0,0 +1,7 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
export type WorkflowInputs = Record<string, any>;
export type WorkflowOutputs = Record<string, any>;
@@ -0,0 +1,14 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import { WorkflowSchema } from '@schema/index';
import { WorkflowInputs } from './inputs-outputs';
export interface InvokeParams {
schema: WorkflowSchema;
inputs: WorkflowInputs;
}
export type WorkflowRuntimeInvoke = (params: InvokeParams) => Promise<WorkflowInputs>;
@@ -0,0 +1,6 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
export type VOData<T> = Omit<T, 'id'>;
+13
View File
@@ -0,0 +1,13 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
export interface ICache<K = string, V = any> {
init(): void;
dispose(): void;
get(key: K): V;
set(key: K, value: V): this;
delete(key: K): boolean;
has(key: K): boolean;
}
@@ -0,0 +1,10 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
export type ContainerService = any;
export interface IContainer {
get<T = ContainerService>(key: any): T;
}
@@ -0,0 +1,34 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import { IVariableStore } from '@runtime/variable';
import { IStatusCenter } from '@runtime/status';
import { IState } from '@runtime/state';
import { ISnapshotCenter } from '@runtime/snapshot';
import { IReporter } from '@runtime/reporter';
import { IMessageCenter } from '@runtime/message';
import { IIOCenter } from '@runtime/io-center';
import { IDocument } from '@runtime/document';
import { ICache } from '@runtime/cache';
import { InvokeParams } from '@runtime/base';
export interface ContextData {
cache: ICache;
variableStore: IVariableStore;
state: IState;
document: IDocument;
ioCenter: IIOCenter;
snapshotCenter: ISnapshotCenter;
statusCenter: IStatusCenter;
messageCenter: IMessageCenter;
reporter: IReporter;
}
export interface IContext extends ContextData {
id: string;
init(params: InvokeParams): void;
dispose(): void;
sub(): IContext;
}
@@ -0,0 +1,19 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import { WorkflowSchema } from '@schema/index';
import { INode } from './node';
import { IEdge } from './edge';
export interface IDocument {
id: string;
nodes: INode[];
edges: IEdge[];
root: INode;
start: INode;
end: INode;
init(schema: WorkflowSchema): void;
dispose(): void;
}
@@ -0,0 +1,21 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import { IPort } from './port';
import { INode } from './node';
export interface IEdge {
id: string;
from: INode;
to: INode;
fromPort: IPort;
toPort: IPort;
}
export interface CreateEdgeParams {
id: string;
from: INode;
to: INode;
}
@@ -0,0 +1,9 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
export type { IDocument } from './document';
export type { IEdge, CreateEdgeParams } from './edge';
export type { NodeDeclare as NodeVariable, INode, CreateNodeParams } from './node';
export type { IPort, CreatePortParams } from './port';
@@ -0,0 +1,48 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import { IFlowValue, IJsonSchema, PositionSchema } from '@schema/index';
import { FlowGramNode } from '@node/constant';
import { IPort } from './port';
import { IEdge } from './edge';
export interface NodeDeclare {
inputsValues?: Record<string, IFlowValue>;
inputs?: IJsonSchema;
outputs?: IJsonSchema;
}
export interface INode<T = any> {
id: string;
type: FlowGramNode;
name: string;
position: PositionSchema;
declare: NodeDeclare;
data: T;
ports: {
inputs: IPort[];
outputs: IPort[];
};
edges: {
inputs: IEdge[];
outputs: IEdge[];
};
parent: INode | null;
children: INode[];
prev: INode[];
next: INode[];
successors: INode[];
predecessors: INode[];
isBranch: boolean;
}
export interface CreateNodeParams {
id: string;
type: FlowGramNode;
name: string;
position: PositionSchema;
variable?: NodeDeclare;
data?: any;
}
@@ -0,0 +1,21 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import { WorkflowPortType } from '@schema/index';
import { INode } from './node';
import { IEdge } from './edge';
export interface IPort {
id: string;
node: INode;
edges: IEdge[];
type: WorkflowPortType;
}
export interface CreatePortParams {
id: string;
node: INode;
type: WorkflowPortType;
}
@@ -0,0 +1,23 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import { IValidation } from '@runtime/validation';
import { ITask } from '../task';
import { IExecutor } from '../executor';
import { INode } from '../document';
import { IContext } from '../context';
import { InvokeParams } from '../base';
export interface EngineServices {
Validation: IValidation;
Executor: IExecutor;
}
export interface IEngine {
invoke(params: InvokeParams): ITask;
executeNode(params: { context: IContext; node: INode }): Promise<void>;
}
export const IEngine = Symbol.for('Engine');
@@ -0,0 +1,13 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import { ExecutionContext, ExecutionResult, INodeExecutor } from './node-executor';
export interface IExecutor {
execute: (context: ExecutionContext) => Promise<ExecutionResult>;
register: (executor: INodeExecutor) => void;
}
export const IExecutor = Symbol.for('Executor');
@@ -0,0 +1,12 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
export { IExecutor } from './executor';
export type {
ExecutionContext,
ExecutionResult,
INodeExecutor,
INodeExecutorFactory,
} from './node-executor';
@@ -0,0 +1,33 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import { FlowGramNode } from '@node/index';
import { ISnapshot } from '../snapshot';
import { INode } from '../document';
import { IContext } from '../context';
import { IContainer } from '../container';
import { WorkflowInputs, WorkflowOutputs } from '../base';
export interface ExecutionContext {
node: INode;
inputs: WorkflowInputs;
container: IContainer;
runtime: IContext;
snapshot: ISnapshot;
}
export interface ExecutionResult {
outputs: WorkflowOutputs;
branch?: string;
}
export interface INodeExecutor {
type: FlowGramNode;
execute: (context: ExecutionContext) => Promise<ExecutionResult>;
}
export interface INodeExecutorFactory {
new (): INodeExecutor;
}
@@ -0,0 +1,21 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
export * from './container';
export * from './base';
export * from './engine';
export * from './context';
export * from './document';
export * from './executor';
export * from './io-center';
export * from './snapshot';
export * from './reporter';
export * from './state';
export * from './status';
export * from './task';
export * from './validation';
export * from './variable';
export * from './message';
export * from './cache';
@@ -0,0 +1,22 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import { WorkflowInputs, WorkflowOutputs } from '../base';
export interface IOData {
inputs: WorkflowInputs;
outputs: WorkflowOutputs;
}
/** Input & Output */
export interface IIOCenter {
inputs: WorkflowInputs;
outputs: WorkflowOutputs;
setInputs(inputs: WorkflowInputs): void;
setOutputs(outputs: WorkflowOutputs): void;
init(inputs: WorkflowInputs): void;
dispose(): void;
export(): IOData;
}
@@ -0,0 +1,37 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
export enum WorkflowMessageType {
Log = 'log',
Info = 'info',
Debug = 'debug',
Error = 'error',
Warn = 'warning',
}
export interface MessageData {
message: string;
nodeID?: string;
timestamp?: number;
}
export interface IMessage extends MessageData {
id: string;
type: WorkflowMessageType;
timestamp: number;
}
export type WorkflowMessages = Record<WorkflowMessageType, IMessage[]>;
export interface IMessageCenter {
init(): void;
dispose(): void;
log(data: MessageData): IMessage;
info(data: MessageData): IMessage;
debug(data: MessageData): IMessage;
error(data: MessageData): IMessage;
warn(data: MessageData): IMessage;
export(): WorkflowMessages;
}
@@ -0,0 +1,34 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import { IMessageCenter, WorkflowMessages } from '@runtime/message';
import { StatusData, IStatusCenter } from '../status';
import { Snapshot, ISnapshotCenter } from '../snapshot';
import { WorkflowInputs, WorkflowOutputs } from '../base';
export interface NodeReport extends StatusData {
id: string;
snapshots: Snapshot[];
}
export type WorkflowReports = Record<string, NodeReport>;
export interface IReport {
id: string;
inputs: WorkflowInputs;
outputs: WorkflowOutputs;
workflowStatus: StatusData;
reports: WorkflowReports;
messages: WorkflowMessages;
}
export interface IReporter {
snapshotCenter: ISnapshotCenter;
statusCenter: IStatusCenter;
messageCenter: IMessageCenter;
init(): void;
dispose(): void;
export(): IReport;
}
@@ -0,0 +1,7 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
export type { ISnapshot, Snapshot, SnapshotData } from './snapshot';
export type { ISnapshotCenter } from './snapshot-center';
@@ -0,0 +1,15 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import { ISnapshot, Snapshot, SnapshotData } from './snapshot';
export interface ISnapshotCenter {
id: string;
create(snapshot: Partial<SnapshotData>): ISnapshot;
exportAll(): Snapshot[];
export(): Record<string, Snapshot[]>;
init(): void;
dispose(): void;
}
@@ -0,0 +1,27 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import { WorkflowInputs, WorkflowOutputs } from '../base';
export interface SnapshotData {
nodeID: string;
inputs: WorkflowInputs;
outputs: WorkflowOutputs;
data: any;
branch?: string;
error?: string;
}
export interface Snapshot extends SnapshotData {
id: string;
}
export interface ISnapshot {
id: string;
data: Partial<SnapshotData>;
update(data: Partial<SnapshotData>): void;
validate(): boolean;
export(): Snapshot;
}
@@ -0,0 +1,34 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import {
IFlowValue,
IFlowRefValue,
WorkflowVariableType,
IFlowTemplateValue,
IJsonSchema,
WorkflowSchema,
} from '@schema/index';
import { IVariableParseResult, IVariableStore } from '../variable';
import { INode } from '../document';
import { WorkflowInputs, WorkflowOutputs } from '../base';
export interface IState {
id: string;
variableStore: IVariableStore;
init(schema?: WorkflowSchema): void;
dispose(): void;
getNodeInputs(node: INode): WorkflowInputs;
setNodeOutputs(params: { node: INode; outputs: WorkflowOutputs }): void;
parseInputs(params: { values: Record<string, IFlowValue>; declare: IJsonSchema }): WorkflowInputs;
parseRef<T = unknown>(ref: IFlowRefValue): IVariableParseResult<T> | null;
parseTemplate(template: IFlowTemplateValue): IVariableParseResult<string> | null;
parseFlowValue<T = unknown>(params: {
flowValue: IFlowValue;
declareType: WorkflowVariableType;
}): IVariableParseResult<T> | null;
isExecutedNode(node: INode): boolean;
addExecutedNode(node: INode): void;
}
@@ -0,0 +1,38 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
export enum WorkflowStatus {
Pending = 'pending',
Processing = 'processing',
Succeeded = 'succeeded',
Failed = 'failed',
Cancelled = 'canceled',
}
export interface StatusData {
status: WorkflowStatus;
terminated: boolean;
startTime: number;
endTime?: number;
timeCost: number;
}
export interface IStatus extends StatusData {
id: string;
process(): void;
success(): void;
fail(): void;
cancel(): void;
export(): StatusData;
}
export interface IStatusCenter {
workflow: IStatus;
nodeStatus(nodeID: string): IStatus;
init(): void;
dispose(): void;
getStatusNodeIDs(status: WorkflowStatus): string[];
exportNodeStatus(): Record<string, StatusData>;
}
@@ -0,0 +1,19 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import { IContext } from '../context';
import { WorkflowOutputs } from '../base';
export interface ITask {
id: string;
processing: Promise<WorkflowOutputs>;
context: IContext;
cancel(): void;
}
export interface TaskParams {
processing: Promise<WorkflowOutputs>;
context: IContext;
}
@@ -0,0 +1,17 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import { InvokeParams } from '@runtime/base';
export interface ValidationResult {
valid: boolean;
errors?: string[];
}
export interface IValidation {
invoke(params: InvokeParams): ValidationResult;
}
export const IValidation = Symbol.for('Validation');
@@ -0,0 +1,49 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import { WorkflowVariableType } from '@schema/index';
interface VariableTypeInfo {
type: WorkflowVariableType;
itemsType?: WorkflowVariableType;
}
export interface IVariable<T = Object> extends VariableTypeInfo {
id: string;
nodeID: string;
key: string;
value: T;
}
export interface IVariableParseResult<T = unknown> extends VariableTypeInfo {
value: T;
type: WorkflowVariableType;
}
export interface IVariableStore {
id: string;
store: Map<string, Map<string, IVariable>>;
setParent(parent: IVariableStore): void;
setVariable(
params: {
nodeID: string;
key: string;
value: unknown;
} & VariableTypeInfo
): void;
setValue(params: {
nodeID: string;
variableKey: string;
variablePath?: string[];
value: unknown;
}): void;
getValue<T = unknown>(params: {
nodeID: string;
variableKey: string;
variablePath?: string[];
}): IVariableParseResult<T> | null;
init(): void;
dispose(): void;
}
@@ -0,0 +1,21 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
export enum WorkflowPortType {
Input = 'input',
Output = 'output',
}
export enum WorkflowVariableType {
String = 'string',
Integer = 'integer',
Number = 'number',
Boolean = 'boolean',
Object = 'object',
Array = 'array',
Map = 'map',
DateTime = 'date-time',
Null = 'null',
}
@@ -0,0 +1,11 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
export interface WorkflowEdgeSchema {
sourceNodeID: string;
targetNodeID: string;
sourcePortID?: string;
targetPortID?: string;
}
@@ -0,0 +1,15 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import { WorkflowNodeSchema } from './node';
export interface WorkflowGroupSchema extends WorkflowNodeSchema {
data: {
title?: string;
color?: string;
parentID: string;
blockIDs: string[];
};
}
@@ -0,0 +1,19 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
export { WorkflowEdgeSchema } from './edge';
export { JsonSchemaBasicType, IJsonSchema, IBasicJsonSchema } from './json-schema';
export { WorkflowNodeMetaSchema } from './node-meta';
export { WorkflowNodeSchema } from './node';
export { WorkflowSchema } from './workflow';
export { XYSchema, PositionSchema } from './xy';
export { WorkflowPortType, WorkflowVariableType } from './constant';
export {
IFlowConstantRefValue,
IFlowConstantValue,
IFlowRefValue,
IFlowValue,
IFlowTemplateValue,
} from './value';
@@ -0,0 +1,38 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
// TODO copy packages/materials/form-materials/src/typings/json-schema/index.ts
export type JsonSchemaBasicType =
| 'boolean'
| 'string'
| 'integer'
| 'number'
| 'object'
| 'array'
| 'map';
export interface IJsonSchema<T = string> {
type: T;
default?: any;
title?: string;
description?: string;
enum?: (string | number)[];
properties?: Record<string, IJsonSchema<T>>;
additionalProperties?: IJsonSchema<T>;
items?: IJsonSchema<T>;
required?: string[];
$ref?: string;
extra?: {
index?: number;
// Used in BaseType.isEqualWithJSONSchema, the type comparison will be weak
weak?: boolean;
// Set the render component
formComponent?: string;
[key: string]: any;
};
}
export type IBasicJsonSchema = IJsonSchema<JsonSchemaBasicType>;
@@ -0,0 +1,11 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import { PositionSchema } from './xy';
export interface WorkflowNodeMetaSchema {
position: PositionSchema;
canvasPosition?: PositionSchema;
}
@@ -0,0 +1,24 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import type { IFlowValue } from './value';
import type { WorkflowNodeMetaSchema } from './node-meta';
import { IJsonSchema } from './json-schema';
import type { WorkflowEdgeSchema } from './edge';
export interface WorkflowNodeSchema<T = string, D = any> {
id: string;
type: T;
meta: WorkflowNodeMetaSchema;
data: D & {
title?: string;
inputsValues?: Record<string, IFlowValue>;
inputs?: IJsonSchema;
outputs?: IJsonSchema;
[key: string]: any;
};
blocks?: WorkflowNodeSchema[];
edges?: WorkflowEdgeSchema[];
}
@@ -0,0 +1,34 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
// TODO copy packages/materials/form-materials/src/typings/flow-value/index.ts
export interface IFlowConstantValue {
type: 'constant';
content?: string | number | boolean;
}
export interface IFlowRefValue {
type: 'ref';
content?: string[];
}
export interface IFlowExpressionValue {
type: 'expression';
content?: string;
}
export interface IFlowTemplateValue {
type: 'template';
content?: string;
}
export type IFlowValue =
| IFlowConstantValue
| IFlowRefValue
| IFlowExpressionValue
| IFlowTemplateValue;
export type IFlowConstantRefValue = IFlowConstantValue | IFlowRefValue;
@@ -0,0 +1,16 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import type { WorkflowNodeSchema } from './node';
import type { IJsonSchema } from './json-schema';
import type { WorkflowGroupSchema } from './group';
import type { WorkflowEdgeSchema } from './edge';
export interface WorkflowSchema {
nodes: WorkflowNodeSchema[];
edges: WorkflowEdgeSchema[];
groups?: WorkflowGroupSchema[];
globalVariable?: IJsonSchema;
}
@@ -0,0 +1,11 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
export interface XYSchema {
x: number;
y: number;
}
export type PositionSchema = XYSchema;
+29
View File
@@ -0,0 +1,29 @@
{
"extends": "@flowgram.ai/ts-config/tsconfig.flow.path.json",
"compilerOptions": {
"baseUrl": "src",
"paths": {
"@api/*": [
"api/*"
],
"@node/*": [
"node/*"
],
"@runtime/*": [
"runtime/*"
],
"@schema/*": [
"schema/*"
],
"@client/*": [
"client/*"
]
}
},
"include": [
"./src"
],
"exclude": [
"node_modules"
]
}