@vyr/service-chat 0.0.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +18 -0
- package/src/ChatService.ts +104 -0
- package/src/chat/ChatHistory.ts +127 -0
- package/src/chat/ChatSession.ts +183 -0
- package/src/chat/ChatWindow.ts +92 -0
- package/src/chat/ChatWindowManager.ts +72 -0
- package/src/chat/index.ts +4 -0
- package/src/common/Draggable.ts +36 -0
- package/src/common/index.ts +1 -0
- package/src/components/ChatAgent.vue +44 -0
- package/src/components/ChatExecutor.vue +85 -0
- package/src/components/ChatProcess.vue +144 -0
- package/src/components/ChatView.vue +135 -0
- package/src/components/ChatWindow.vue +64 -0
- package/src/components/Input.vue +170 -0
- package/src/components/Welcome.vue +56 -0
- package/src/components/executor/ExecutorHeader.vue +72 -0
- package/src/components/executor/GearLoading.vue +104 -0
- package/src/components/executor/ParamSection.vue +243 -0
- package/src/components/executor/ToolItem.vue +262 -0
- package/src/components/executor/types.ts +27 -0
- package/src/components/executor/useExecutor.ts +117 -0
- package/src/components/index.ts +11 -0
- package/src/executor/index.ts +17 -0
- package/src/index.ts +10 -0
- package/src/locale/Language.ts +10 -0
- package/src/locale/LanguageProvider.ts +49 -0
- package/src/locale/index.ts +2 -0
- package/tsconfig.json +37 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { computed, ref } from 'vue'
|
|
2
|
+
import { copy } from '@vyr/design'
|
|
3
|
+
import { language } from '../../locale/Language'
|
|
4
|
+
import { ParamSectionType, TaskState, TaskItem } from './types'
|
|
5
|
+
|
|
6
|
+
export function useExecutor(props: { tasks: TaskItem[] }) {
|
|
7
|
+
// 展开状态管理
|
|
8
|
+
const expandedTasks = ref<Record<string | number, boolean>>({})
|
|
9
|
+
|
|
10
|
+
// 计算活跃任务数
|
|
11
|
+
const activeCount = computed(() => {
|
|
12
|
+
return props.tasks.filter(task => task.state === 'running').length
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
// 计算已完成任务数
|
|
16
|
+
const completedCount = computed(() => {
|
|
17
|
+
return props.tasks.filter(task => ['success', 'failed'].includes(task.state)).length
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
// 计算总任务数
|
|
21
|
+
const totalCount = computed(() => props.tasks.length)
|
|
22
|
+
|
|
23
|
+
// 判断是否有运行中的任务
|
|
24
|
+
const hasRunningTask = computed(() => activeCount.value > 0)
|
|
25
|
+
|
|
26
|
+
// 切换任务展开状态
|
|
27
|
+
const toggleTask = (taskId: string | number) => {
|
|
28
|
+
expandedTasks.value[taskId] = !expandedTasks.value[taskId]
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// 获取任务展开状态
|
|
32
|
+
const isTaskExpanded = (taskId: string | number) => {
|
|
33
|
+
return !!expandedTasks.value[taskId]
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// 复制内容到剪贴板
|
|
37
|
+
const copyToClipboard = async (
|
|
38
|
+
text: string,
|
|
39
|
+
type: ParamSectionType,
|
|
40
|
+
taskId: string | number,
|
|
41
|
+
emits: any
|
|
42
|
+
) => {
|
|
43
|
+
try {
|
|
44
|
+
await copy(text)
|
|
45
|
+
emits('copy:success', type, taskId)
|
|
46
|
+
return true
|
|
47
|
+
} catch (err) {
|
|
48
|
+
console.error(err)
|
|
49
|
+
emits('copy:error', type, taskId)
|
|
50
|
+
return false
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// 格式化JSON
|
|
55
|
+
const formatJSON = (data: any): string => {
|
|
56
|
+
if (data === undefined || data === null) return 'null'
|
|
57
|
+
if (typeof data === 'string') {
|
|
58
|
+
try {
|
|
59
|
+
const parsed = JSON.parse(data)
|
|
60
|
+
return JSON.stringify(parsed, null, 2)
|
|
61
|
+
} catch {
|
|
62
|
+
return data
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
return JSON.stringify(data, null, 2)
|
|
67
|
+
} catch {
|
|
68
|
+
return String(data)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// 获取参数预览
|
|
73
|
+
const getParamPreview = (params: any): string => {
|
|
74
|
+
if (!params) return ''
|
|
75
|
+
try {
|
|
76
|
+
const str = typeof params === 'string' ? params : JSON.stringify(params)
|
|
77
|
+
return str.length > 40 ? str.substring(0, 40) + '...' : str
|
|
78
|
+
} catch {
|
|
79
|
+
return language.get('executor.param.error.format')
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// 获取状态标签文本
|
|
84
|
+
const getStateTag = (state: TaskState): string => {
|
|
85
|
+
const map = {
|
|
86
|
+
running: language.get('executor.task.state.running'),
|
|
87
|
+
success: language.get('executor.task.state.success'),
|
|
88
|
+
failed: language.get('executor.task.state.failed')
|
|
89
|
+
}
|
|
90
|
+
return map[state]
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// 获取状态标签类名
|
|
94
|
+
const getStateTagClass = (state: TaskState): string => {
|
|
95
|
+
const map = {
|
|
96
|
+
running: 'running',
|
|
97
|
+
success: 'success',
|
|
98
|
+
failed: 'failed'
|
|
99
|
+
}
|
|
100
|
+
return map[state]
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
expandedTasks,
|
|
105
|
+
activeCount,
|
|
106
|
+
completedCount,
|
|
107
|
+
totalCount,
|
|
108
|
+
hasRunningTask,
|
|
109
|
+
toggleTask,
|
|
110
|
+
isTaskExpanded,
|
|
111
|
+
copyToClipboard,
|
|
112
|
+
formatJSON,
|
|
113
|
+
getParamPreview,
|
|
114
|
+
getStateTag,
|
|
115
|
+
getStateTagClass
|
|
116
|
+
}
|
|
117
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { runtime } from "@vyr/runtime"
|
|
2
|
+
import { api, GatewayService } from "@vyr/service-gateway"
|
|
3
|
+
import { ChatService } from "../ChatService"
|
|
4
|
+
|
|
5
|
+
const connection = async () => {
|
|
6
|
+
const chatService = runtime.get<ChatService>('chat')
|
|
7
|
+
chatService.initializeTask.run()
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const bindExecutor = (service: GatewayService) => {
|
|
11
|
+
service.listen(api.system.connection.path, connection)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export {
|
|
15
|
+
bindExecutor,
|
|
16
|
+
connection,
|
|
17
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Locale } from "@vyr/locale";
|
|
2
|
+
import { zhCnLanguageProvider, ZhCNLanguageProvider } from "./LanguageProvider";
|
|
3
|
+
|
|
4
|
+
Locale.register(zhCnLanguageProvider)
|
|
5
|
+
|
|
6
|
+
const language = Locale.getLanguage<ZhCNLanguageProvider>(zhCnLanguageProvider.name)
|
|
7
|
+
|
|
8
|
+
export {
|
|
9
|
+
language
|
|
10
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { LanguageProvider } from '@vyr/locale'
|
|
2
|
+
|
|
3
|
+
interface ZhCNLanguageProvider extends LanguageProvider {
|
|
4
|
+
'chat.introduction.title': string
|
|
5
|
+
'chat.introduction.message': string
|
|
6
|
+
'chat.input.placeholder': string
|
|
7
|
+
'chat.input.format.content.asset': string
|
|
8
|
+
'chat.input.format.content.node': string
|
|
9
|
+
'chat.input.format.content.prefab': string
|
|
10
|
+
'chat.user.stop': string
|
|
11
|
+
'executor.header.status': string
|
|
12
|
+
'executor.param.input': string
|
|
13
|
+
'executor.param.output': string
|
|
14
|
+
'executor.param.error': string
|
|
15
|
+
'executor.param.error.format': string
|
|
16
|
+
'executor.task.state.running': string
|
|
17
|
+
'executor.task.state.success': string
|
|
18
|
+
'executor.task.state.failed': string
|
|
19
|
+
'executor.task.status.running': string
|
|
20
|
+
'executor.task.execution.record': string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const zhCnLanguageProvider: ZhCNLanguageProvider = {
|
|
24
|
+
id: 'zh_CN',
|
|
25
|
+
name: '@vyr/service-chat',
|
|
26
|
+
|
|
27
|
+
'chat.introduction.title': '欢迎!我是您的AI伙伴,助您轻松完成任务。',
|
|
28
|
+
'chat.introduction.message': '您只需给我一个清晰的目标,我就会自动将它分解成具体步骤,并一步步为您完成。',
|
|
29
|
+
'chat.input.placeholder': '请输入您的问题,并按Enter发送,按Shift + Enter换行',
|
|
30
|
+
'chat.input.format.content.asset': '资产URL:{{url}};',
|
|
31
|
+
'chat.input.format.content.node': '节点UUID:{{uuid}},所属资产:{{url}};',
|
|
32
|
+
'chat.input.format.content.prefab': '预制体ID:{{id}};',
|
|
33
|
+
'chat.user.stop': '[系统] 用户手动停止。',
|
|
34
|
+
'executor.header.status': '已完成 {{completed}}/{{total}}',
|
|
35
|
+
'executor.param.input': '输入参数',
|
|
36
|
+
'executor.param.output': '输出参数',
|
|
37
|
+
'executor.param.error': '错误信息',
|
|
38
|
+
'executor.param.error.format': '参数格式错误',
|
|
39
|
+
'executor.task.state.running': '执行中',
|
|
40
|
+
'executor.task.state.success': '成功',
|
|
41
|
+
'executor.task.state.failed': '失败',
|
|
42
|
+
'executor.task.status.running': '正在执行',
|
|
43
|
+
'executor.task.execution.record': '执行记录',
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export {
|
|
47
|
+
ZhCNLanguageProvider,
|
|
48
|
+
zhCnLanguageProvider,
|
|
49
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNext",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "node",
|
|
6
|
+
"lib": [
|
|
7
|
+
"ESNext",
|
|
8
|
+
"DOM",
|
|
9
|
+
"DOM.Iterable"
|
|
10
|
+
],
|
|
11
|
+
"outDir": "build",
|
|
12
|
+
"declaration": true,
|
|
13
|
+
"resolveJsonModule": true,
|
|
14
|
+
"strict": true,
|
|
15
|
+
"jsx": "preserve",
|
|
16
|
+
"skipLibCheck": true,
|
|
17
|
+
"esModuleInterop": true,
|
|
18
|
+
"allowSyntheticDefaultImports": true,
|
|
19
|
+
"forceConsistentCasingInFileNames": true,
|
|
20
|
+
"useDefineForClassFields": true,
|
|
21
|
+
"sourceMap": false,
|
|
22
|
+
"baseUrl": ".",
|
|
23
|
+
"types": [
|
|
24
|
+
"webpack-env",
|
|
25
|
+
],
|
|
26
|
+
"paths": {}
|
|
27
|
+
},
|
|
28
|
+
"include": [
|
|
29
|
+
"src/**/*.ts",
|
|
30
|
+
"src/**/*.tsx",
|
|
31
|
+
"src/**/*.vue",
|
|
32
|
+
"src/shims-vue.d.ts"
|
|
33
|
+
],
|
|
34
|
+
"exclude": [
|
|
35
|
+
"node_modules"
|
|
36
|
+
]
|
|
37
|
+
}
|