feat: AI工作流
This commit is contained in:
63
src/components/Tinyflow/Tinyflow.vue
Normal file
63
src/components/Tinyflow/Tinyflow.vue
Normal file
@ -0,0 +1,63 @@
|
||||
<template>
|
||||
<div ref="divRef" :class="['tinyflow', className]" :style="style" style="height: 100%"> </div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { Item, Tinyflow as TinyflowNative } from './ui'
|
||||
import './ui/index.css'
|
||||
import { onMounted, onUnmounted, ref } from 'vue'
|
||||
|
||||
const props = defineProps<{
|
||||
className?: string
|
||||
style?: Record<string, string>
|
||||
data?: Record<string, any>
|
||||
provider?: {
|
||||
llm?: () => Item[] | Promise<Item[]>
|
||||
knowledge?: () => Item[] | Promise<Item[]>
|
||||
internal?: () => Item[] | Promise<Item[]>
|
||||
}
|
||||
}>()
|
||||
|
||||
const divRef = ref<HTMLDivElement | null>(null)
|
||||
let tinyflow: TinyflowNative | null = null
|
||||
// 定义默认的 provider 方法
|
||||
const defaultProvider = {
|
||||
llm: () => [] as Item[],
|
||||
knowledge: () => [] as Item[],
|
||||
internal: () => [] as Item[]
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
if (divRef.value) {
|
||||
// 合并默认 provider 和传入的 props.provider
|
||||
const mergedProvider = {
|
||||
...defaultProvider,
|
||||
...props.provider
|
||||
}
|
||||
tinyflow = new TinyflowNative({
|
||||
element: divRef.value as Element,
|
||||
data: props.data || {},
|
||||
provider: mergedProvider
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
if (tinyflow) {
|
||||
tinyflow.destroy()
|
||||
tinyflow = null
|
||||
}
|
||||
})
|
||||
|
||||
const getData = () => {
|
||||
if (tinyflow) {
|
||||
return tinyflow.getData()
|
||||
}
|
||||
console.warn('Tinyflow instance is not initialized')
|
||||
return null
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
getData
|
||||
})
|
||||
</script>
|
||||
1
src/components/Tinyflow/ui/index.css
Normal file
1
src/components/Tinyflow/ui/index.css
Normal file
File diff suppressed because one or more lines are too long
41
src/components/Tinyflow/ui/index.d.ts
vendored
Normal file
41
src/components/Tinyflow/ui/index.d.ts
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
import { Edge } from '@xyflow/svelte';
|
||||
import { Node as Node_2 } from '@xyflow/svelte';
|
||||
import { useSvelteFlow } from '@xyflow/svelte';
|
||||
import { Viewport } from '@xyflow/svelte';
|
||||
|
||||
export declare type Item = {
|
||||
value: number | string;
|
||||
label: string;
|
||||
children?: Item[];
|
||||
};
|
||||
|
||||
export declare class Tinyflow {
|
||||
private options;
|
||||
private rootEl;
|
||||
private svelteFlowInstance;
|
||||
constructor(options: TinyflowOptions);
|
||||
private _init;
|
||||
private _setOptions;
|
||||
getOptions(): TinyflowOptions;
|
||||
getData(): {
|
||||
nodes: Node_2[];
|
||||
edges: Edge[];
|
||||
viewport: Viewport;
|
||||
};
|
||||
setData(data: TinyflowData): void;
|
||||
destroy(): void;
|
||||
}
|
||||
|
||||
export declare type TinyflowData = Partial<ReturnType<ReturnType<typeof useSvelteFlow>['toObject']>>;
|
||||
|
||||
export declare type TinyflowOptions = {
|
||||
element: string | Element;
|
||||
data?: TinyflowData;
|
||||
provider?: {
|
||||
llm?: () => Item[] | Promise<Item[]>;
|
||||
knowledge?: () => Item[] | Promise<Item[]>;
|
||||
internal?: () => Item[] | Promise<Item[]>;
|
||||
};
|
||||
};
|
||||
|
||||
export { }
|
||||
16984
src/components/Tinyflow/ui/index.js
Normal file
16984
src/components/Tinyflow/ui/index.js
Normal file
File diff suppressed because it is too large
Load Diff
9
src/components/Tinyflow/ui/index.umd.js
Normal file
9
src/components/Tinyflow/ui/index.umd.js
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user