g-ai-robot3 1.0.4 → 1.0.6

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/README.md CHANGED
@@ -1,199 +1,238 @@
1
- # g-ai-robot3
2
-
3
- 内部数字人对话组件,基于 Vue 3,封装了文本问答、语音交互、数字人视频播放和工作流回调能力。
4
-
5
- ## 包说明
6
-
7
- - 这是内部业务 npm 包,默认会随包发布内部接口地址、默认 `bot_id`、默认代理前缀和默认 WS 地址。
8
- - 这些默认值已经集中到 [`packages/internal-defaults.ts`](E:/g-ai-robot3/packages/internal-defaults.ts) 统一管理。
9
- - 组件仍然保留原有覆盖能力。业务方可以通过 props 覆盖 `apiPrefix`、REST 地址、WS 地址和数字人接口地址。
10
-
11
- ## 安装
12
-
13
- ```bash
14
- npm install g-ai-robot3
15
- ```
16
-
17
- 本包要求宿主项目使用 Vue 3。
18
-
19
- ## 快速开始
20
-
21
- ```vue
22
- <script setup lang="ts">
23
- import GAiRobot3 from "g-ai-robot3";
24
- import "g-ai-robot3/style.css";
25
- </script>
26
-
27
- <template>
28
- <GAiRobot3
29
- :cozeInfo="{ bot_id: '7429224296222097443' }"
30
- apiPrefix="/api21216"
31
- />
32
- </template>
33
- ```
34
-
35
- ### Vite 项目额外配置
36
-
37
- 本组件包含图片等静态资源,Vite 项目需要引入配套插件以确保资源路径正确:
38
-
39
- ```ts
40
- // vite.config.ts
41
- import gAiRobot from "g-ai-robot3/vite-plugin";
42
-
43
- export default defineConfig({
44
- plugins: [
45
- vue(),
46
- gAiRobot(), // 确保图片等静态资源路径正确
47
- ],
48
- });
49
- ```
50
-
51
- > 该插件会将 `g-ai-robot3` 排除出 Vite 依赖预构建,同时保留其子依赖的预构建,避免 CJS/ESM 兼容问题。
52
-
53
- ## 仓库内示例
54
-
55
- - 当前仓库直接使用 [`examples/App.vue`](E:/g-ai-robot3/examples/App.vue) 作为示例页面。
56
- - 页面入口在 [`index.html`](E:/g-ai-robot3/index.html) 和 [`examples/main.ts`](E:/g-ai-robot3/examples/main.ts)。
57
- - 本地联调时在仓库根目录运行 `npm run dev` 即可。
58
-
59
- ## Vite 代理示例
60
-
61
- ```ts
62
- import { defineConfig } from "vite";
63
- import vue from "@vitejs/plugin-vue";
64
-
65
- export default defineConfig({
66
- plugins: [vue()],
67
- server: {
68
- proxy: {
69
- "/api21216": {
70
- target: "https://model.keepsoft.net:39002",
71
- changeOrigin: true,
72
- secure: false,
73
- rewrite: (path) => path.replace(/^\/api21216/, ""),
74
- },
75
- },
76
- },
77
- });
78
- ```
79
-
80
- ## 默认内部配置
81
-
82
- 以下默认值会随 npm 包一起发布,且都可以通过 props 覆盖:
83
-
84
- | 项目 | 默认值 |
85
- | --- | --- |
86
- | `apiPrefix` | `"/api21216"` |
87
- | `cozeInfo.bot_id` | `"7473691358872584226"` |
88
- | `createConversationUrl` | `${apiPrefix}/chatGlm/createConversation` |
89
- | `qaServer` | `${apiPrefix}/chatGlm/searchTextNew` |
90
- | `interrupt` | `${apiPrefix}/chatGlm/cancelChat` |
91
- | `wakeupAudio` | `${apiPrefix}/asr/saveWakeUpAudio` |
92
- | `offer` | `${apiPrefix}/metahuman/offer` |
93
- | `humanaudio` | `${apiPrefix}/metahuman/humanaudio` |
94
- | `stop_audio` | `${apiPrefix}/metahuman/stop_audio` |
95
- | `textDriven` | `${apiPrefix}/intelligentVoice/tts` |
96
- | `audioWs` | `wss://model.keepsoft.net:39002/funasrWs` |
97
- | `voiceprintWs` | `wss://model.keepsoft.net:39002/speakerWs` |
98
- | `instructWs` | `wss://model.keepsoft.net:39002/commandWs` |
99
-
100
- ## 常用 Props
101
-
102
- ### 核心配置
103
-
104
- | 参数 | 类型 | 默认值 | 说明 |
105
- | --- | --- | --- | --- |
106
- | `cozeInfo` | `{ bot_id: string }` | 内置默认值 | 智能体配置,建议显式传入 |
107
- | `apiPrefix` | `string` | `"/api21216"` | API 基础前缀 |
108
- | `modelType` | `"local" \| "online"` | `"online"` | 模型类型 |
109
- | `showModelTypeToggle` | `boolean` | `false` | 是否显示本地/联网切换 |
110
- | `isDebug` | `boolean` | `false` | 是否打印调试信息 |
111
- | `mode` | `"audio" \| "text" \| "video"` | `"video"` | 交互模式 |
112
-
113
- ### 对话框与数字人
114
-
115
- | 参数 | 类型 | 默认值 | 说明 |
116
- | --- | --- | --- | --- |
117
- | `placementBottom` | `number` | `100` | 对话框底部偏移 |
118
- | `placementLeft` | `number` | `450` | 对话框左侧偏移 |
119
- | `canvasWidth` | `number` | `180` | 画布宽度 |
120
- | `canvasHeight` | `number` | `180` | 画布高度 |
121
- | `videoStyle` | `CSSProperties` | `{ width: "180px", opacity: "0", pointerEvents: "none" }` | 视频样式 |
122
- | `digitalStyle` | `CSSProperties` | `{ width: "180px", height: "180px" }` | 数字人样式 |
123
- | `canvasStyle` | `CSSProperties` | `{ width: "180px", height: "180px" }` | Canvas 样式 |
124
- | `bubbleStyle` | `CSSProperties` | `{ width: "30%", height: "30%" }` | 状态图标样式 |
125
-
126
- ### 气泡与展示型对话
127
-
128
- | 参数 | 类型 | 默认值 | 说明 |
129
- | --- | --- | --- | --- |
130
- | `showMsgBubble` | `boolean` | `true` | 是否显示悬浮气泡 |
131
- | `showMsgNumber` | `number` | `5` | 悬浮气泡展示条数 |
132
- | `bubbleTheme` | `"dark" \| "light" \| "custom"` | `"dark"` | 气泡主题 |
133
- | `useCustomDialog` | `boolean` | `false` | 是否使用自定义气泡样式 |
134
- | `BubbleWidth` | `CSSProperties` | `{ width: "220px", bottom: "85%" }` | 气泡容器样式 |
135
- | `BubbleBottom` | `number` | | 额外气泡底部偏移 |
136
- | `suspensionStyle` | `CSSProperties` | `{ maxHeight: "33vh" }` | 悬浮区容器样式 |
137
- | `initialQuestion` | `string` | | 外部传入的首条问题,仅展示不请求接口 |
138
- | `streamChunks` | `StreamChunk[]` | `[]` | 外部传入的单条流式消息块 |
139
- | `conversations` | `ConversationInput[]` | `[]` | 外部传入的多轮对话展示数据 |
140
-
141
- ### 接口覆盖
142
-
143
- | 参数 | 类型 | 默认值说明 |
144
- | --- | --- | --- |
145
- | `createConversationUrl` | `string` | 默认由 `apiPrefix` 拼接 |
146
- | `qaServer` | `string` | 默认由 `apiPrefix` 拼接 |
147
- | `interrupt` | `string` | 默认由 `apiPrefix` 拼接 |
148
- | `wakeupAudio` | `string` | 默认由 `apiPrefix` 拼接 |
149
- | `audioWs` | `string` | 默认内部 WS |
150
- | `voiceprintWs` | `string` | 默认内部 WS |
151
- | `offer` | `string` | 默认由 `apiPrefix` 拼接 |
152
- | `human` | `string` | 默认由 `apiPrefix` 拼接 |
153
- | `humanaudio` | `string` | 默认由 `apiPrefix` 拼接 |
154
- | `stop_audio` | `string` | 默认由 `apiPrefix` 拼接 |
155
- | `textDriven` | `string` | 默认由 `apiPrefix` 拼接 |
156
-
157
- ## 类型导出
158
-
159
- 本包会导出常用类型,内部项目可以直接引用:
160
-
161
- ```ts
162
- import type {
163
- ConversationInput,
164
- IndexProps,
165
- StreamChunk,
166
- } from "g-ai-robot3";
167
- ```
168
-
169
- ## 工作流事件示例
170
-
171
- ```ts
172
- const eventFun = [
173
- {
174
- keywords: ["scene1_fuyangWeather"],
175
- trigger: "before",
176
- fun: (params: Record<string, any>) => {
177
- console.log("scene1_fuyangWeather", params);
178
- },
179
- },
180
- {
181
- keywords: ["scene2"],
182
- trigger: "after",
183
- fun: (params: Record<string, any>) => {
184
- console.log("scene2", params);
185
- },
186
- },
187
- ];
188
- ```
189
-
190
- ## 注意事项
191
-
192
- - 这是浏览器组件,不适用于 SSR 直接渲染。
193
- - 如果需要覆盖默认内部地址,优先通过 props 覆盖,不要直接改 `dist` 产物。
194
- - `stream`、`space`、`instructWs` 等旧字段仍保留兼容,但不建议新增使用。
195
- - 视频和动图资源体积较大,当前库产物会偏重,内部接入时建议通过缓存策略降低重复下载成本。
196
-
197
- ## 许可证
198
-
199
- 本项目遵循仓库内的 `LICENSE`。
1
+ # g-ai-robot3
2
+
3
+ 内部数字人对话组件,基于 Vue 3,封装了文本问答、语音交互、数字人视频播放和工作流回调能力。
4
+
5
+ ## 包说明
6
+
7
+ - 这是内部业务 npm 包,默认会随包发布内部接口地址、默认 `bot_id`、默认代理前缀和默认 WS 地址。
8
+ - 这些默认值已经集中到 [`packages/internal-defaults.ts`](E:/g-ai-robot3/packages/internal-defaults.ts) 统一管理。
9
+ - 组件仍然保留原有覆盖能力。业务方可以通过 props 覆盖 `apiPrefix`、REST 地址、WS 地址和数字人接口地址。
10
+
11
+ ## 安装
12
+
13
+ ```bash
14
+ npm install g-ai-robot3
15
+ ```
16
+
17
+ 本包要求宿主项目使用 Vue 3。
18
+
19
+ ## 快速开始
20
+
21
+ ```vue
22
+ <script setup lang="ts">
23
+ import GAiRobot3 from "g-ai-robot3";
24
+ import "g-ai-robot3/style.css";
25
+ </script>
26
+
27
+ <template>
28
+ <GAiRobot3
29
+ :cozeInfo="{ bot_id: '7429224296222097443' }"
30
+ apiPrefix="/api21216"
31
+ />
32
+ </template>
33
+ ```
34
+
35
+ ### Vite 项目额外配置
36
+
37
+ 本组件包含图片等静态资源,Vite 项目需要引入配套插件以确保资源路径正确:
38
+
39
+ ```ts
40
+ // vite.config.ts
41
+ import gAiRobot from "g-ai-robot3/vite-plugin";
42
+
43
+ export default defineConfig({
44
+ plugins: [
45
+ vue(),
46
+ gAiRobot(), // 确保图片等静态资源路径正确
47
+ ],
48
+ });
49
+ ```
50
+
51
+ > 该插件会将 `g-ai-robot3` 排除出 Vite 依赖预构建,同时保留其子依赖的预构建,避免 CJS/ESM 兼容问题。
52
+
53
+ ## 仓库内示例
54
+
55
+ - 当前仓库直接使用 [`examples/App.vue`](E:/g-ai-robot3/examples/App.vue) 作为示例页面。
56
+ - 页面入口在 [`index.html`](E:/g-ai-robot3/index.html) 和 [`examples/main.ts`](E:/g-ai-robot3/examples/main.ts)。
57
+ - 本地联调时在仓库根目录运行 `npm run dev` 即可。
58
+
59
+ ## Vite 代理示例
60
+
61
+ ```ts
62
+ import { defineConfig } from "vite";
63
+ import vue from "@vitejs/plugin-vue";
64
+
65
+ export default defineConfig({
66
+ plugins: [vue()],
67
+ server: {
68
+ proxy: {
69
+ "/api21216": {
70
+ target: "https://model.keepsoft.net:39002",
71
+ changeOrigin: true,
72
+ secure: false,
73
+ rewrite: (path) => path.replace(/^\/api21216/, ""),
74
+ },
75
+ },
76
+ },
77
+ });
78
+ ```
79
+
80
+ ## 默认内部配置
81
+
82
+ 以下默认值会随 npm 包一起发布,且都可以通过 props 覆盖:
83
+
84
+ | 项目 | 默认值 |
85
+ | --- | --- |
86
+ | `apiPrefix` | `"/api21216"` |
87
+ | `cozeInfo.bot_id` | `"7473691358872584226"` |
88
+ | `createConversationUrl` | `${apiPrefix}/chatGlm/createConversation` |
89
+ | `qaServer` | `${apiPrefix}/chatGlm/searchTextNew` |
90
+ | `interrupt` | `${apiPrefix}/chatGlm/cancelChat` |
91
+ | `wakeupAudio` | `${apiPrefix}/asr/saveWakeUpAudio` |
92
+ | `offer` | `${apiPrefix}/metahuman/offer` |
93
+ | `humanaudio` | `${apiPrefix}/metahuman/humanaudio` |
94
+ | `stop_audio` | `${apiPrefix}/metahuman/stop_audio` |
95
+ | `textDriven` | `${apiPrefix}/intelligentVoice/tts` |
96
+ | `audioWs` | `wss://model.keepsoft.net:39002/funasrWs` |
97
+ | `voiceprintWs` | `wss://model.keepsoft.net:39002/speakerWs` |
98
+ | `instructWs` | `wss://model.keepsoft.net:39002/commandWs` |
99
+
100
+ ## 常用 Props
101
+
102
+ ### 核心配置
103
+
104
+ | 参数 | 类型 | 默认值 | 说明 |
105
+ | --- | --- | --- | --- |
106
+ | `cozeInfo` | `{ bot_id: string }` | 内置默认值 | 智能体配置,建议显式传入 |
107
+ | `apiPrefix` | `string` | `"/api21216"` | API 基础前缀 |
108
+ | `modelType` | `"local" \| "online"` | `"online"` | 模型类型 |
109
+ | `showModelTypeToggle` | `boolean` | `false` | 是否显示本地/联网切换 |
110
+ | `isDebug` | `boolean` | `false` | 是否打印调试信息 |
111
+ | `mode` | `"audio" \| "text" \| "video"` | `"video"` | 交互模式 |
112
+ | `driverMode` | `"workflow" \| "agent"` | `"workflow"` | AI 响应驱动模式,`workflow` 保持关键词工作流,`agent` 直接透传 AI JSON |
113
+
114
+ ### 对话框与数字人
115
+
116
+ | 参数 | 类型 | 默认值 | 说明 |
117
+ | --- | --- | --- | --- |
118
+ | `placementBottom` | `number` | `100` | 对话框底部偏移 |
119
+ | `placementLeft` | `number` | `450` | 对话框左侧偏移 |
120
+ | `canvasWidth` | `number` | `180` | 画布宽度 |
121
+ | `canvasHeight` | `number` | `180` | 画布高度 |
122
+ | `videoStyle` | `CSSProperties` | `{ width: "180px", opacity: "0", pointerEvents: "none" }` | 视频样式 |
123
+ | `digitalStyle` | `CSSProperties` | `{ width: "180px", height: "180px" }` | 数字人样式 |
124
+ | `canvasStyle` | `CSSProperties` | `{ width: "180px", height: "180px" }` | Canvas 样式 |
125
+ | `bubbleStyle` | `CSSProperties` | `{ width: "30%", height: "30%" }` | 状态图标样式 |
126
+
127
+ ### 气泡与展示型对话
128
+
129
+ | 参数 | 类型 | 默认值 | 说明 |
130
+ | --- | --- | --- | --- |
131
+ | `showMsgBubble` | `boolean` | `true` | 是否显示悬浮气泡 |
132
+ | `showMsgNumber` | `number` | `5` | 悬浮气泡展示条数 |
133
+ | `bubbleTheme` | `"dark" \| "light" \| "custom"` | `"dark"` | 气泡主题 |
134
+ | `useCustomDialog` | `boolean` | `false` | 是否使用自定义气泡样式 |
135
+ | `BubbleWidth` | `CSSProperties` | `{ width: "220px", bottom: "85%" }` | 气泡容器样式 |
136
+ | `BubbleBottom` | `number` | | 额外气泡底部偏移 |
137
+ | `suspensionStyle` | `CSSProperties` | `{ maxHeight: "33vh" }` | 悬浮区容器样式 |
138
+ | `initialQuestion` | `string` | | 外部传入的首条问题,仅展示不请求接口 |
139
+ | `streamChunks` | `StreamChunk[]` | `[]` | 外部传入的单条流式消息块 |
140
+ | `conversations` | `ConversationInput[]` | `[]` | 外部传入的多轮对话展示数据 |
141
+
142
+ ### 接口覆盖
143
+
144
+ | 参数 | 类型 | 默认值说明 |
145
+ | --- | --- | --- |
146
+ | `createConversationUrl` | `string` | 默认由 `apiPrefix` 拼接 |
147
+ | `qaServer` | `string` | 默认由 `apiPrefix` 拼接 |
148
+ | `interrupt` | `string` | 默认由 `apiPrefix` 拼接 |
149
+ | `wakeupAudio` | `string` | 默认由 `apiPrefix` 拼接 |
150
+ | `audioWs` | `string` | 默认内部 WS |
151
+ | `voiceprintWs` | `string` | 默认内部 WS |
152
+ | `offer` | `string` | 默认由 `apiPrefix` 拼接 |
153
+ | `human` | `string` | 默认由 `apiPrefix` 拼接 |
154
+ | `humanaudio` | `string` | 默认由 `apiPrefix` 拼接 |
155
+ | `stop_audio` | `string` | 默认由 `apiPrefix` 拼接 |
156
+ | `textDriven` | `string` | 默认由 `apiPrefix` 拼接 |
157
+
158
+ ## 类型导出
159
+
160
+ 本包会导出常用类型,内部项目可以直接引用:
161
+
162
+ ```ts
163
+ import type {
164
+ ConversationInput,
165
+ IndexProps,
166
+ StreamChunk,
167
+ } from "g-ai-robot3";
168
+ ```
169
+
170
+ ## 工作流事件示例
171
+
172
+ ```ts
173
+ const eventFun = [
174
+ {
175
+ keywords: ["scene1_fuyangWeather"],
176
+ trigger: "before",
177
+ fun: (params: Record<string, any>) => {
178
+ console.log("scene1_fuyangWeather", params);
179
+ },
180
+ },
181
+ {
182
+ keywords: ["scene2"],
183
+ trigger: "after",
184
+ fun: (params: Record<string, any>) => {
185
+ console.log("scene2", params);
186
+ },
187
+ },
188
+ ];
189
+ ```
190
+
191
+ ## Agent 输出驱动模式
192
+
193
+ `driverMode` 默认为 `workflow`,老项目不需要改动。切换到 `agent` 后:
194
+
195
+ - 忽略 `eventFun`
196
+ - 不做关键词匹配
197
+ - 每次 AI 返回 `data` 时直接触发 `onAgentResponse`
198
+ - 由业务层自行决定如何处理返回 JSON
199
+
200
+ ```vue
201
+ <script setup lang="ts">
202
+ const handleAgentResponse = (params: any) => {
203
+ console.log("agent response", params);
204
+ };
205
+ </script>
206
+
207
+ <template>
208
+ <GAiRobot3
209
+ mode="video"
210
+ driverMode="agent"
211
+ @onAgentResponse="handleAgentResponse"
212
+ />
213
+ </template>
214
+ ```
215
+
216
+ 业务侧可以直接拿到类似下面的结构:
217
+
218
+ ```ts
219
+ function handleAgentResponse(params: any) {
220
+ // {
221
+ // reply,
222
+ // targetState,
223
+ // commands
224
+ // }
225
+ applyAgentResponse(params);
226
+ }
227
+ ```
228
+
229
+ ## 注意事项
230
+
231
+ - 这是浏览器组件,不适用于 SSR 直接渲染。
232
+ - 如果需要覆盖默认内部地址,优先通过 props 覆盖,不要直接改 `dist` 产物。
233
+ - `stream`、`space`、`instructWs` 等旧字段仍保留兼容,但不建议新增使用。
234
+ - 视频和动图资源体积较大,当前库产物会偏重,内部接入时建议通过缓存策略降低重复下载成本。
235
+
236
+ ## 许可证
237
+
238
+ 本项目遵循仓库内的 `LICENSE`。
@@ -1,5 +1,5 @@
1
1
  import { type Ref, type ComputedRef } from 'vue';
2
- import type { ConversationType, ConversationInput, StreamChunk } from '../type';
2
+ import type { ConversationType, ConversationInput, DriverMode, StreamChunk, WorkflowEventHandler } from '../type';
3
3
  export interface ConversationItem {
4
4
  type: ConversationType;
5
5
  singleText?: string;
@@ -17,6 +17,7 @@ export interface ConversationItem {
17
17
  export interface UseQADialogOptions {
18
18
  qaServer: string;
19
19
  stream: 'True' | 'False';
20
+ driverMode: DriverMode;
20
21
  isDebug: boolean;
21
22
  greet: string;
22
23
  waitTxt: string;
@@ -32,7 +33,8 @@ export interface UseQADialogDeps {
32
33
  matchEvent: Ref<any>;
33
34
  currentChatId: Ref<string>;
34
35
  currentConversationId: Ref<string>;
35
- matchEventFun: (action: string) => any;
36
+ eventFun: WorkflowEventHandler[];
37
+ onAgentResponse: (params: any) => void;
36
38
  cancelChat: (conversationId: string, chatId: string) => Promise<boolean>;
37
39
  input: Ref<string>;
38
40
  inputRecognitionType: Ref<string>;
@@ -1,11 +1,12 @@
1
1
  import { type Ref, type ComputedRef } from 'vue';
2
2
  import type { AvatarId } from '../constants/avatar';
3
- import type { MsgItem } from '../type';
3
+ import type { DriverMode, MsgItem, WorkflowEventHandler } from '../type';
4
4
  export interface UseStreamAnswerOptions {
5
5
  qaServer: string;
6
6
  stream: 'True' | 'False';
7
7
  isFuYangPro: boolean;
8
8
  mode: 'audio' | 'text' | 'video';
9
+ driverMode: DriverMode;
9
10
  isDebug: boolean;
10
11
  }
11
12
  export interface UseStreamAnswerDeps {
@@ -14,11 +15,8 @@ export interface UseStreamAnswerDeps {
14
15
  currentModelType: Ref<'local' | 'online'>;
15
16
  msgList: Ref<MsgItem[]>;
16
17
  digitalHumanRef: Ref<any>;
17
- eventFun: {
18
- keywords: string[];
19
- trigger: 'before' | 'after' | 'together';
20
- fun: (a: Record<string, any>) => void;
21
- }[];
18
+ eventFun: WorkflowEventHandler[];
19
+ onAgentResponse: (params: any) => void;
22
20
  stopOrderPlayAudio: () => void;
23
21
  addAudioToQueue: (url: string, interrupt: boolean) => void;
24
22
  }
@@ -33,9 +31,5 @@ export declare function useStreamAnswer(getOptions: () => UseStreamAnswerOptions
33
31
  cancelChat: (conversation_id: string, chat_id: string) => Promise<boolean>;
34
32
  getAnswer: (text: string) => Promise<void>;
35
33
  cancelCurrentStream: () => void;
36
- matchEventFun: (action: string) => {
37
- keywords: string[];
38
- trigger: "before" | "after" | "together";
39
- fun: (a: Record<string, any>) => void;
40
- } | undefined;
34
+ matchEventFun: (action: string) => WorkflowEventHandler | undefined;
41
35
  };
@@ -1,5 +1,4 @@
1
1
  import { type Ref } from 'vue';
2
- import 'recorder-core/src/extensions/waveview';
3
2
  import type { AvatarId } from '../constants/avatar';
4
3
  export interface UseVoiceRecognitionOptions {
5
4
  audioWs: string;