Skip to content

Commit 047b9f3

Browse files
YunaiVgitee-org
authored andcommitted
!749 feat: AI工作流
Merge pull request !749 from Lesan/master-ai工作流
2 parents 3d4c8f2 + ce3b95d commit 047b9f3

File tree

10 files changed

+17511
-0
lines changed

10 files changed

+17511
-0
lines changed

src/api/ai/workflow/index.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import request from '@/config/axios'
2+
3+
export const getWorkflowPage = async (params) => {
4+
return await request.get({ url: '/ai/workflow/page', params })
5+
}
6+
7+
export const getWorkflow = async (id) => {
8+
return await request.get({ url: '/ai/workflow/get?id=' + id })
9+
}
10+
11+
export const createWorkflow = async (data) => {
12+
return await request.post({ url: '/ai/workflow/create', data })
13+
}
14+
15+
export const updateWorkflow = async (data) => {
16+
return await request.put({ url: '/ai/workflow/update', data })
17+
}
18+
19+
export const deleteWorkflow = async (id) => {
20+
return await request.delete({ url: '/ai/workflow/delete?id=' + id })
21+
}
22+
23+
export const updateWorkflowModel = async (data) => {
24+
return await request.put({ url: '/ai/workflow/updateWorkflowModel', data })
25+
}

src/components/Tinyflow/Tinyflow.vue

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<template>
2+
<div ref="divRef" :class="['tinyflow', className]" :style="style" style="height: 100%"> </div>
3+
</template>
4+
5+
<script setup lang="ts">
6+
import { Item, Tinyflow as TinyflowNative } from './ui'
7+
import './ui/index.css'
8+
import { onMounted, onUnmounted, ref } from 'vue'
9+
10+
const props = defineProps<{
11+
className?: string
12+
style?: Record<string, string>
13+
data?: Record<string, any>
14+
provider?: {
15+
llm?: () => Item[] | Promise<Item[]>
16+
knowledge?: () => Item[] | Promise<Item[]>
17+
internal?: () => Item[] | Promise<Item[]>
18+
}
19+
}>()
20+
21+
const divRef = ref<HTMLDivElement | null>(null)
22+
let tinyflow: TinyflowNative | null = null
23+
// 定义默认的 provider 方法
24+
const defaultProvider = {
25+
llm: () => [] as Item[],
26+
knowledge: () => [] as Item[],
27+
internal: () => [] as Item[]
28+
}
29+
30+
onMounted(() => {
31+
if (divRef.value) {
32+
// 合并默认 provider 和传入的 props.provider
33+
const mergedProvider = {
34+
...defaultProvider,
35+
...props.provider
36+
}
37+
tinyflow = new TinyflowNative({
38+
element: divRef.value as Element,
39+
data: props.data || {},
40+
provider: mergedProvider
41+
})
42+
}
43+
})
44+
45+
onUnmounted(() => {
46+
if (tinyflow) {
47+
tinyflow.destroy()
48+
tinyflow = null
49+
}
50+
})
51+
52+
const getData = () => {
53+
if (tinyflow) {
54+
return tinyflow.getData()
55+
}
56+
console.warn('Tinyflow instance is not initialized')
57+
return null
58+
}
59+
60+
defineExpose({
61+
getData
62+
})
63+
</script>

src/components/Tinyflow/ui/index.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/Tinyflow/ui/index.d.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { Edge } from '@xyflow/svelte';
2+
import { Node as Node_2 } from '@xyflow/svelte';
3+
import { useSvelteFlow } from '@xyflow/svelte';
4+
import { Viewport } from '@xyflow/svelte';
5+
6+
export declare type Item = {
7+
value: number | string;
8+
label: string;
9+
children?: Item[];
10+
};
11+
12+
export declare class Tinyflow {
13+
private options;
14+
private rootEl;
15+
private svelteFlowInstance;
16+
constructor(options: TinyflowOptions);
17+
private _init;
18+
private _setOptions;
19+
getOptions(): TinyflowOptions;
20+
getData(): {
21+
nodes: Node_2[];
22+
edges: Edge[];
23+
viewport: Viewport;
24+
};
25+
setData(data: TinyflowData): void;
26+
destroy(): void;
27+
}
28+
29+
export declare type TinyflowData = Partial<ReturnType<ReturnType<typeof useSvelteFlow>['toObject']>>;
30+
31+
export declare type TinyflowOptions = {
32+
element: string | Element;
33+
data?: TinyflowData;
34+
provider?: {
35+
llm?: () => Item[] | Promise<Item[]>;
36+
knowledge?: () => Item[] | Promise<Item[]>;
37+
internal?: () => Item[] | Promise<Item[]>;
38+
};
39+
};
40+
41+
export { }

0 commit comments

Comments
 (0)