g-ai-robot3 1.0.6 → 1.1.1

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
@@ -108,8 +108,9 @@ export default defineConfig({
108
108
  | `modelType` | `"local" \| "online"` | `"online"` | 模型类型 |
109
109
  | `showModelTypeToggle` | `boolean` | `false` | 是否显示本地/联网切换 |
110
110
  | `isDebug` | `boolean` | `false` | 是否打印调试信息 |
111
- | `mode` | `"audio" \| "text" \| "video"` | `"video"` | 交互模式 |
112
- | `driverMode` | `"workflow" \| "agent"` | `"workflow"` | AI 响应驱动模式,`workflow` 保持关键词工作流,`agent` 直接透传 AI JSON |
111
+ | `mode` | `"audio" \| "text" \| "video"` | `"video"` | 交互模式 |
112
+ | `driverMode` | `"workflow" \| "agent"` | `"workflow"` | AI 响应驱动模式,`workflow` 保持关键词工作流,`agent` 直接透传 AI JSON |
113
+ | `data` | `Record<string, any>` | `{}` | `agent` 模式下随消息透传给后端的动态上下文 |
113
114
 
114
115
  ### 对话框与数字人
115
116
 
@@ -192,39 +193,49 @@ const eventFun = [
192
193
 
193
194
  `driverMode` 默认为 `workflow`,老项目不需要改动。切换到 `agent` 后:
194
195
 
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
- };
196
+ - 忽略 `eventFun`
197
+ - 不做关键词匹配
198
+ - 每次 AI 返回 `data` 时直接触发 `agent-response`
199
+ - 由业务层自行决定如何处理返回 JSON
200
+ - 发送请求时 `searchText` 会升级为 `JSON.stringify({ msg, data })` 后的字符串;`msg` 为用户输入或补问组装文本,`data` 为外部传入的最新 `data` prop
201
+
202
+ ```vue
203
+ <script setup lang="ts">
204
+ import { ref } from "vue";
205
+
206
+ const agentContext = ref({
207
+ anything: "from parent",
208
+ });
209
+
210
+ const handleAgentResponse = (params: any) => {
211
+ console.log("agent response", params);
212
+ };
205
213
  </script>
206
214
 
207
215
  <template>
208
- <GAiRobot3
209
- mode="video"
210
- driverMode="agent"
211
- @onAgentResponse="handleAgentResponse"
212
- />
213
- </template>
216
+ <GAiRobot3
217
+ mode="video"
218
+ driverMode="agent"
219
+ :data="agentContext"
220
+ @agent-response="handleAgentResponse"
221
+ />
222
+ </template>
214
223
  ```
215
224
 
216
225
  业务侧可以直接拿到类似下面的结构:
217
226
 
218
227
  ```ts
219
- function handleAgentResponse(params: any) {
220
- // {
221
- // reply,
222
- // targetState,
223
- // commands
224
- // }
225
- applyAgentResponse(params);
226
- }
227
- ```
228
+ function handleAgentResponse(params: any) {
229
+ // {
230
+ // reply,
231
+ // targetState,
232
+ // commands
233
+ // }
234
+ applyAgentResponse(params);
235
+ }
236
+ ```
237
+
238
+ `workflow` 模式继续保持旧请求结构,不启用 `{ msg, data }` 和补问组装,老项目不需要调整后端接口。
228
239
 
229
240
  ## 注意事项
230
241
 
@@ -3,4 +3,6 @@ export { useAudioPlayback } from './useAudioPlayback';
3
3
  export { useVoiceRecognition } from './useVoiceRecognition';
4
4
  export { useStreamAnswer } from './useStreamAnswer';
5
5
  export { useQADialog } from './useQADialog';
6
+ export { buildSearchTextPayload, resolveNeedClarify, useClarifyContext } from './useClarifyContext';
6
7
  export type { ConversationItem } from './useQADialog';
8
+ export type { AgentContextData, AgentSearchTextPayload, BuildSearchTextPayloadParams, ClarifyResponseMessage, ClarifyContext, ClarifyResponsePayload, ClarifySendResult, SearchTextPayload, } from './useClarifyContext';
@@ -0,0 +1,42 @@
1
+ import { type ComputedRef, type Ref } from 'vue';
2
+ import type { DriverMode } from '../type';
3
+ /** *********************补问上下文类型*********************/
4
+ export type AgentContextData = Record<string, any>;
5
+ export interface ClarifySendResult {
6
+ sendText: string;
7
+ isComposed: boolean;
8
+ }
9
+ export interface AgentSearchTextPayload {
10
+ msg: string;
11
+ data: AgentContextData;
12
+ }
13
+ export type SearchTextPayload = string;
14
+ export interface ClarifyResponsePayload {
15
+ userInput: string;
16
+ answerText: string;
17
+ needClarify?: boolean;
18
+ }
19
+ export interface BuildSearchTextPayloadParams {
20
+ driverMode: DriverMode;
21
+ userInput: string;
22
+ data?: AgentContextData;
23
+ clarifyContext?: Pick<ClarifyContext, 'buildSendText'>;
24
+ }
25
+ export interface ClarifyResponseMessage {
26
+ data?: {
27
+ needClarify?: boolean;
28
+ } | null;
29
+ }
30
+ export interface ClarifyContext {
31
+ isClarifying: Ref<boolean>;
32
+ originalRequest: Ref<string>;
33
+ lastSystemQuestion: Ref<string>;
34
+ canCompose: ComputedRef<boolean>;
35
+ buildSendText: (userInput: string) => ClarifySendResult;
36
+ updateFromResponse: (payload: ClarifyResponsePayload) => void;
37
+ clearClarifyContext: () => void;
38
+ }
39
+ /** *********************请求协议组装*********************/
40
+ export declare const buildSearchTextPayload: ({ driverMode, userInput, data, clarifyContext, }: BuildSearchTextPayloadParams) => SearchTextPayload;
41
+ export declare const resolveNeedClarify: (message: ClarifyResponseMessage) => boolean | undefined;
42
+ export declare function useClarifyContext(): ClarifyContext;
@@ -1,5 +1,6 @@
1
1
  import { type Ref, type ComputedRef } from 'vue';
2
2
  import type { ConversationType, ConversationInput, DriverMode, StreamChunk, WorkflowEventHandler } from '../type';
3
+ import { type AgentContextData, type ClarifyContext } from './useClarifyContext';
3
4
  export interface ConversationItem {
4
5
  type: ConversationType;
5
6
  singleText?: string;
@@ -24,6 +25,7 @@ export interface UseQADialogOptions {
24
25
  initialQuestion?: string;
25
26
  streamChunks?: StreamChunk[];
26
27
  conversations?: ConversationInput[];
28
+ data?: AgentContextData;
27
29
  }
28
30
  export interface UseQADialogDeps {
29
31
  cozeInfoParams: ComputedRef<Record<string, any>>;
@@ -34,10 +36,11 @@ export interface UseQADialogDeps {
34
36
  currentChatId: Ref<string>;
35
37
  currentConversationId: Ref<string>;
36
38
  eventFun: WorkflowEventHandler[];
37
- onAgentResponse: (params: any) => void;
39
+ onAgentData: (params: any) => void;
38
40
  cancelChat: (conversationId: string, chatId: string) => Promise<boolean>;
39
41
  input: Ref<string>;
40
42
  inputRecognitionType: Ref<string>;
43
+ clarifyContext?: ClarifyContext;
41
44
  stopOrderPlayAudio: () => void;
42
45
  stopRecognition: () => void;
43
46
  scrollContainer: Ref<any>;
@@ -1,6 +1,7 @@
1
1
  import { type Ref, type ComputedRef } from 'vue';
2
2
  import type { AvatarId } from '../constants/avatar';
3
3
  import type { DriverMode, MsgItem, WorkflowEventHandler } from '../type';
4
+ import { type AgentContextData, type ClarifyContext } from './useClarifyContext';
4
5
  export interface UseStreamAnswerOptions {
5
6
  qaServer: string;
6
7
  stream: 'True' | 'False';
@@ -8,6 +9,7 @@ export interface UseStreamAnswerOptions {
8
9
  mode: 'audio' | 'text' | 'video';
9
10
  driverMode: DriverMode;
10
11
  isDebug: boolean;
12
+ data?: AgentContextData;
11
13
  }
12
14
  export interface UseStreamAnswerDeps {
13
15
  avatarId: Ref<AvatarId>;
@@ -16,9 +18,10 @@ export interface UseStreamAnswerDeps {
16
18
  msgList: Ref<MsgItem[]>;
17
19
  digitalHumanRef: Ref<any>;
18
20
  eventFun: WorkflowEventHandler[];
19
- onAgentResponse: (params: any) => void;
21
+ onAgentData: (params: any) => void;
20
22
  stopOrderPlayAudio: () => void;
21
23
  addAudioToQueue: (url: string, interrupt: boolean) => void;
24
+ clarifyContext?: ClarifyContext;
22
25
  }
23
26
  export declare function useStreamAnswer(getOptions: () => UseStreamAnswerOptions, deps: UseStreamAnswerDeps): {
24
27
  isGettingAnswer: Ref<boolean, boolean>;