easyai-plugin-dev-kit/composables/worklfow/node/PluginBaseNode.ts
2025-10-06 16:08:44 +08:00

80 lines
1.8 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { type INodeData, type INodeOutputSpec, NodeTypeEnum } from "~/composables/worklfow/node/node.interface";
export interface NodeOptions {
id?: string
title: string
}
export const NodeCategoryEnum = {
BASE: '基础',
FUNCTIONAL: '功能',
APP: '应用',
Agent: '智能体'
} as const
export type NodeCategoryEnum =
(typeof NodeCategoryEnum)[keyof typeof NodeCategoryEnum]
export interface NodeViewData {
type: NodeTypeEnum
label: string
description?: string
category: NodeCategoryEnum
id?: string // appId / agentId // component
previewUrl?: string
icon?: string
}
export abstract class PluginBaseNode {
id?: string
title: string
data: Record<string, unknown>
static nodeType = ''
static getNodeList(): NodeViewData[] {
return []
}
constructor(options: NodeOptions) {
this.id = options.id
this.title = options.title
this.data = this.initData(options)
}
/** 初始化节点数据 */
abstract initData(options?: NodeOptions): Record<string, unknown>
create(title: string, id?: string): INodeData {
return {
class_type: this.getNodeType() as NodeTypeEnum,
plugin_type: NodeTypeEnum.ApiPlugin, // 远程插件节点必填项
_meta: {
title
},
inputs: {},
data: this.data,
outputSpec: this.createOutputSpec(id)
}
}
/** 节点类型 */
getNodeType() {
return (this.constructor as typeof PluginBaseNode).nodeType
}
/** 输出规格(可选) */
createOutputSpec(_id?: string): undefined | INodeOutputSpec {
return undefined
}
/** 节点本体 UI */
static renderNode(): Component {
throw new Error('Not implemented')
}
/** 节点属性面板 UI可选 */
static renderProperties(): Component {
return {}
}
}