@blueking/chat-helper 0.0.10-beta.4 → 0.0.10-dev.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.
@@ -1,4 +1,4 @@
1
- import { ApprovalInterruptTicketStatus, RunFinishedOutcomeType, type IResume } from '../event';
1
+ import { ApprovalInterruptTicketStatus, ResumeStatus, RunFinishedOutcomeType, type IResume } from '../event';
2
2
  import { MessageRole, MessageStatus, UserOperation } from '../message';
3
3
  import type { IRequestConfig, ISSEProtocol } from '../http';
4
4
  import type { IMediatorModule } from '../mediator';
@@ -140,8 +140,8 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
140
140
  content: {
141
141
  result?: {
142
142
  interruptId: string;
143
- status: import("../event").ResumeStatus;
144
- payload: {
143
+ status: ResumeStatus;
144
+ payload?: {
145
145
  answers: {
146
146
  answer: {
147
147
  description: string;
@@ -1076,8 +1076,8 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
1076
1076
  content: {
1077
1077
  result?: {
1078
1078
  interruptId: string;
1079
- status: import("../event").ResumeStatus;
1080
- payload: {
1079
+ status: ResumeStatus;
1080
+ payload?: {
1081
1081
  answers: {
1082
1082
  answer: {
1083
1083
  description: string;
@@ -1894,6 +1894,7 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
1894
1894
  getAgentInfo: () => Promise<void>;
1895
1895
  reset: (protocol: ISSEProtocol) => void;
1896
1896
  pollResumeSession: (sessionCode: string) => void;
1897
+ clearLongPollTimer: () => void;
1897
1898
  userOperationStreamRequest: (sessionCode: string, operation: UserOperation, payload: IUserOperationPayload, config?: IRequestConfig) => Promise<void>;
1898
1899
  streamRequest: ({ sessionCode, url, config, resume, input, }: {
1899
1900
  sessionCode: string;
@@ -80,7 +80,7 @@ function _object_spread(target) {
80
80
  return target;
81
81
  }
82
82
  import { ref } from 'vue';
83
- import { AGUIProtocol, ApprovalInterruptTicketStatus, RunFinishedOutcomeType } from '../event/index.ts.js';
83
+ import { AGUIProtocol, ApprovalInterruptTicketStatus, ResumeStatus, RunFinishedOutcomeType } from '../event/index.ts.js';
84
84
  import { MessageRole, MessageStatus, UserOperation } from '../message/index.ts.js';
85
85
  import { SessionStatus } from '../session/type.ts.js';
86
86
  /**
@@ -93,6 +93,7 @@ import { SessionStatus } from '../session/type.ts.js';
93
93
  const isChatting = ref(false);
94
94
  let usedProtocol = protocol || new AGUIProtocol();
95
95
  let abortController = null;
96
+ let longPollTimer = null;
96
97
  const getAgentInfo = ()=>{
97
98
  var _mediator_http;
98
99
  isInfoLoading.value = true;
@@ -129,6 +130,9 @@ import { SessionStatus } from '../session/type.ts.js';
129
130
  sessionCode,
130
131
  config
131
132
  });
133
+ } else {
134
+ clearLongPollTimer();
135
+ pollResumeSession(sessionCode);
132
136
  }
133
137
  });
134
138
  };
@@ -165,6 +169,8 @@ import { SessionStatus } from '../session/type.ts.js';
165
169
  lastUserMessage.id = lastApiUserMessage.id;
166
170
  });
167
171
  }
172
+ // 轮询接口,判断是否可以继续聊天
173
+ pollResumeSession(sessionCode);
168
174
  };
169
175
  const onError = (error)=>{
170
176
  var _usedProtocol_onError;
@@ -187,11 +193,11 @@ import { SessionStatus } from '../session/type.ts.js';
187
193
  method: 'POST',
188
194
  data: {
189
195
  session_code: sessionCode,
190
- resume,
191
196
  input,
192
197
  execute_kwargs: {
193
198
  stream: true,
194
- persist_input: !!input
199
+ persist_input: !!input,
200
+ resume
195
201
  }
196
202
  },
197
203
  controller: abortController,
@@ -256,31 +262,47 @@ import { SessionStatus } from '../session/type.ts.js';
256
262
  * @param sessionCode - 会话编码
257
263
  * @returns 是否可以继续聊天
258
264
  */ const pollResumeSession = (sessionCode)=>{
259
- var _mediator_message, _lastMessage_content_outcome, _lastMessage_content, _lastMessage_content_outcome_interrupts, _lastMessage_content_outcome1, _lastMessage_content1;
265
+ var _mediator_message, _lastMessage_content_outcome, _lastMessage_content;
260
266
  const lastMessage = (_mediator_message = mediator.message) === null || _mediator_message === void 0 ? void 0 : _mediator_message.list.value.at(-1);
261
- const isInterruptMessage = (lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.role) === MessageRole.Interrupt;
262
- const isTicketPending = (lastMessage === null || lastMessage === void 0 ? void 0 : (_lastMessage_content = lastMessage.content) === null || _lastMessage_content === void 0 ? void 0 : (_lastMessage_content_outcome = _lastMessage_content.outcome) === null || _lastMessage_content_outcome === void 0 ? void 0 : _lastMessage_content_outcome.type) === RunFinishedOutcomeType.Interrupt && (lastMessage === null || lastMessage === void 0 ? void 0 : (_lastMessage_content1 = lastMessage.content) === null || _lastMessage_content1 === void 0 ? void 0 : (_lastMessage_content_outcome1 = _lastMessage_content1.outcome) === null || _lastMessage_content_outcome1 === void 0 ? void 0 : (_lastMessage_content_outcome_interrupts = _lastMessage_content_outcome1.interrupts) === null || _lastMessage_content_outcome_interrupts === void 0 ? void 0 : _lastMessage_content_outcome_interrupts.some((interrupt)=>{
267
+ const pendingApprovalInterrupt = (lastMessage === null || lastMessage === void 0 ? void 0 : (_lastMessage_content = lastMessage.content) === null || _lastMessage_content === void 0 ? void 0 : (_lastMessage_content_outcome = _lastMessage_content.outcome) === null || _lastMessage_content_outcome === void 0 ? void 0 : _lastMessage_content_outcome.type) === RunFinishedOutcomeType.Interrupt ? lastMessage.content.outcome.interrupts.find((interrupt)=>{
263
268
  var _interrupt_metadata_ticket, _interrupt_metadata;
264
- return ((_interrupt_metadata = interrupt.metadata) === null || _interrupt_metadata === void 0 ? void 0 : (_interrupt_metadata_ticket = _interrupt_metadata.ticket) === null || _interrupt_metadata_ticket === void 0 ? void 0 : _interrupt_metadata_ticket.status) === ApprovalInterruptTicketStatus.Pending;
265
- }));
266
- if (isInterruptMessage && isTicketPending) {
267
- setTimeout(()=>{
268
- var _mediator_session_current_value, _mediator_session_current, _mediator_session, // 轮询接口,判断是否可以继续聊天
269
- _mediator_http;
270
- // 如果会话不匹配,则不继续轮询
271
- if (sessionCode !== ((_mediator_session = mediator.session) === null || _mediator_session === void 0 ? void 0 : (_mediator_session_current = _mediator_session.current) === null || _mediator_session_current === void 0 ? void 0 : (_mediator_session_current_value = _mediator_session_current.value) === null || _mediator_session_current_value === void 0 ? void 0 : _mediator_session_current_value.sessionCode)) return;
272
- (_mediator_http = mediator.http) === null || _mediator_http === void 0 ? void 0 : _mediator_http.session.isResumeSession(sessionCode).then((res)=>{
273
- if (res) {
274
- // 可以继续聊天,重新发起聊天
275
- streamRequest({
276
- sessionCode
277
- });
278
- } else {
279
- // 不可以继续聊天,继续轮询
269
+ return [
270
+ ApprovalInterruptTicketStatus.Pending,
271
+ ApprovalInterruptTicketStatus.Draft
272
+ ].includes((_interrupt_metadata = interrupt.metadata) === null || _interrupt_metadata === void 0 ? void 0 : (_interrupt_metadata_ticket = _interrupt_metadata.ticket) === null || _interrupt_metadata_ticket === void 0 ? void 0 : _interrupt_metadata_ticket.status);
273
+ }) : undefined;
274
+ const getIsTicketLoading = ()=>{
275
+ const isInterruptMessage = (lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.role) === MessageRole.Interrupt;
276
+ return isInterruptMessage && !!pendingApprovalInterrupt;
277
+ };
278
+ if (getIsTicketLoading()) {
279
+ var // 轮询接口,判断是否可以继续聊天
280
+ _mediator_http;
281
+ (_mediator_http = mediator.http) === null || _mediator_http === void 0 ? void 0 : _mediator_http.session.isResumeSession(sessionCode).then((res)=>{
282
+ if (res) {
283
+ // 可以继续聊天,重新发起聊天(携带 execute_kwargs.resume 通知后端恢复中断)
284
+ streamRequest({
285
+ sessionCode,
286
+ resume: {
287
+ interruptId: pendingApprovalInterrupt.id,
288
+ status: ResumeStatus.Resolved
289
+ }
290
+ });
291
+ } else {
292
+ longPollTimer = setTimeout(()=>{
293
+ var _mediator_session_current_value, _mediator_session_current, _mediator_session;
294
+ // 如果会话不匹配,则不继续轮询
295
+ if (sessionCode !== ((_mediator_session = mediator.session) === null || _mediator_session === void 0 ? void 0 : (_mediator_session_current = _mediator_session.current) === null || _mediator_session_current === void 0 ? void 0 : (_mediator_session_current_value = _mediator_session_current.value) === null || _mediator_session_current_value === void 0 ? void 0 : _mediator_session_current_value.sessionCode)) return;
280
296
  pollResumeSession(sessionCode);
281
- }
282
- });
283
- }, 30000);
297
+ }, 30000);
298
+ }
299
+ });
300
+ }
301
+ };
302
+ const clearLongPollTimer = ()=>{
303
+ if (longPollTimer) {
304
+ clearTimeout(longPollTimer);
305
+ longPollTimer = null;
284
306
  }
285
307
  };
286
308
  /**
@@ -379,6 +401,7 @@ import { SessionStatus } from '../session/type.ts.js';
379
401
  getAgentInfo,
380
402
  reset,
381
403
  pollResumeSession,
404
+ clearLongPollTimer,
382
405
  userOperationStreamRequest,
383
406
  streamRequest
384
407
  };
@@ -401,14 +401,23 @@ import { CustomEventName, EventType, FlowTaskState, RunFinishedOutcomeType } fro
401
401
  /**
402
402
  * 处理工具调用结果事件
403
403
  */ handleToolCallResultEvent(event) {
404
- this.messageModule.plusMessage({
405
- role: MessageRole.Tool,
406
- content: event.content,
407
- duration: event.duration,
408
- status: MessageStatus.Complete,
409
- toolCallId: event.toolCallId,
410
- messageId: event.messageId
411
- });
404
+ const message = this.messageModule.getCurrentLoadingMessage();
405
+ if ((message === null || message === void 0 ? void 0 : message.role) === MessageRole.Interrupt) {
406
+ // 如果是中断消息,则更新消息内容
407
+ message.content.result = JSON.parse(event.content);
408
+ message.content.outcome.type = RunFinishedOutcomeType.Success;
409
+ message.status = MessageStatus.Complete;
410
+ } else {
411
+ // 否则创建一个工具调用结果消息
412
+ this.messageModule.plusMessage({
413
+ role: MessageRole.Tool,
414
+ content: event.content,
415
+ duration: event.duration,
416
+ status: MessageStatus.Complete,
417
+ toolCallId: event.toolCallId,
418
+ messageId: event.messageId
419
+ });
420
+ }
412
421
  }
413
422
  /**
414
423
  * 处理工具调用开始事件
@@ -218,7 +218,7 @@ export type IUserQuestionInterrupt = IInterrupt<InterruptReason.UserQuestion, {
218
218
  export interface IResume {
219
219
  interruptId: string;
220
220
  status: ResumeStatus;
221
- payload: {
221
+ payload?: {
222
222
  answers: {
223
223
  answer: {
224
224
  description: string;
@@ -95,7 +95,7 @@ import { transferMessage2MessageApi, transferMessageApi2Message } from '../trans
95
95
  task_id: taskId
96
96
  }, config);
97
97
  // 用户操作
98
- const userOperation = (sessionCode, operation, payload, config)=>fetchClient.post(`plugin_api/user_operation/`, {
98
+ const userOperation = (sessionCode, operation, payload, config)=>fetchClient.post(`user_operation/`, {
99
99
  session_code: sessionCode,
100
100
  operation,
101
101
  payload
package/dist/index.d.ts CHANGED
@@ -143,7 +143,7 @@ export declare const useChatHelper: (options: IUseChatHelperOptions) => {
143
143
  result?: {
144
144
  interruptId: string;
145
145
  status: import("./event").ResumeStatus;
146
- payload: {
146
+ payload?: {
147
147
  answers: {
148
148
  answer: {
149
149
  description: string;
@@ -1079,7 +1079,7 @@ export declare const useChatHelper: (options: IUseChatHelperOptions) => {
1079
1079
  result?: {
1080
1080
  interruptId: string;
1081
1081
  status: import("./event").ResumeStatus;
1082
- payload: {
1082
+ payload?: {
1083
1083
  answers: {
1084
1084
  answer: {
1085
1085
  description: string;
@@ -1896,6 +1896,7 @@ export declare const useChatHelper: (options: IUseChatHelperOptions) => {
1896
1896
  getAgentInfo: () => Promise<void>;
1897
1897
  reset: (protocol: import("./http").ISSEProtocol) => void;
1898
1898
  pollResumeSession: (sessionCode: string) => void;
1899
+ clearLongPollTimer: () => void;
1899
1900
  userOperationStreamRequest: (sessionCode: string, operation: import("./message").UserOperation, payload: import("./message").IUserOperationPayload, config?: import("./http").IRequestConfig) => Promise<void>;
1900
1901
  streamRequest: ({ sessionCode, url, config, resume, input, }: {
1901
1902
  sessionCode: string;
@@ -1996,7 +1997,7 @@ export declare const useChatHelper: (options: IUseChatHelperOptions) => {
1996
1997
  result?: {
1997
1998
  interruptId: string;
1998
1999
  status: import("./event").ResumeStatus;
1999
- payload: {
2000
+ payload?: {
2000
2001
  answers: {
2001
2002
  answer: {
2002
2003
  description: string;
@@ -2873,7 +2874,7 @@ export declare const useChatHelper: (options: IUseChatHelperOptions) => {
2873
2874
  result?: {
2874
2875
  interruptId: string;
2875
2876
  status: import("./event").ResumeStatus;
2876
- payload: {
2877
+ payload?: {
2877
2878
  answers: {
2878
2879
  answer: {
2879
2880
  description: string;
@@ -3771,7 +3772,7 @@ export declare const useChatHelper: (options: IUseChatHelperOptions) => {
3771
3772
  result?: {
3772
3773
  interruptId: string;
3773
3774
  status: import("./event").ResumeStatus;
3774
- payload: {
3775
+ payload?: {
3775
3776
  answers: {
3776
3777
  answer: {
3777
3778
  description: string;
@@ -4648,7 +4649,7 @@ export declare const useChatHelper: (options: IUseChatHelperOptions) => {
4648
4649
  result?: {
4649
4650
  interruptId: string;
4650
4651
  status: import("./event").ResumeStatus;
4651
- payload: {
4652
+ payload?: {
4652
4653
  answers: {
4653
4654
  answer: {
4654
4655
  description: string;
@@ -5547,7 +5548,7 @@ export declare const useChatHelper: (options: IUseChatHelperOptions) => {
5547
5548
  result?: {
5548
5549
  interruptId: string;
5549
5550
  status: import("./event").ResumeStatus;
5550
- payload: {
5551
+ payload?: {
5551
5552
  answers: {
5552
5553
  answer: {
5553
5554
  description: string;
@@ -6424,7 +6425,7 @@ export declare const useChatHelper: (options: IUseChatHelperOptions) => {
6424
6425
  result?: {
6425
6426
  interruptId: string;
6426
6427
  status: import("./event").ResumeStatus;
6427
- payload: {
6428
+ payload?: {
6428
6429
  answers: {
6429
6430
  answer: {
6430
6431
  description: string;
@@ -7322,7 +7323,7 @@ export declare const useChatHelper: (options: IUseChatHelperOptions) => {
7322
7323
  result?: {
7323
7324
  interruptId: string;
7324
7325
  status: import("./event").ResumeStatus;
7325
- payload: {
7326
+ payload?: {
7326
7327
  answers: {
7327
7328
  answer: {
7328
7329
  description: string;
@@ -8199,7 +8200,7 @@ export declare const useChatHelper: (options: IUseChatHelperOptions) => {
8199
8200
  result?: {
8200
8201
  interruptId: string;
8201
8202
  status: import("./event").ResumeStatus;
8202
- payload: {
8203
+ payload?: {
8203
8204
  answers: {
8204
8205
  answer: {
8205
8206
  description: string;
@@ -9114,7 +9115,7 @@ export declare const useChatHelper: (options: IUseChatHelperOptions) => {
9114
9115
  result?: {
9115
9116
  interruptId: string;
9116
9117
  status: import("./event").ResumeStatus;
9117
- payload: {
9118
+ payload?: {
9118
9119
  answers: {
9119
9120
  answer: {
9120
9121
  description: string;
@@ -9988,7 +9989,7 @@ export declare const useChatHelper: (options: IUseChatHelperOptions) => {
9988
9989
  result?: {
9989
9990
  interruptId: string;
9990
9991
  status: import("./event").ResumeStatus;
9991
- payload: {
9992
+ payload?: {
9992
9993
  answers: {
9993
9994
  answer: {
9994
9995
  description: string;
@@ -10867,7 +10868,7 @@ export declare const useChatHelper: (options: IUseChatHelperOptions) => {
10867
10868
  result?: {
10868
10869
  interruptId: string;
10869
10870
  status: import("./event").ResumeStatus;
10870
- payload: {
10871
+ payload?: {
10871
10872
  answers: {
10872
10873
  answer: {
10873
10874
  description: string;
@@ -11742,7 +11743,7 @@ export declare const useChatHelper: (options: IUseChatHelperOptions) => {
11742
11743
  result?: {
11743
11744
  interruptId: string;
11744
11745
  status: import("./event").ResumeStatus;
11745
- payload: {
11746
+ payload?: {
11746
11747
  answers: {
11747
11748
  answer: {
11748
11749
  description: string;
@@ -49,7 +49,7 @@ export type IUserOperationPayload = {
49
49
  node_id: string;
50
50
  task_id: string;
51
51
  } | {
52
- interrupt_id: number;
52
+ interrupt_id: number | string;
53
53
  };
54
54
  export interface IActivityMessage extends IBaseMessage {
55
55
  activityType: ActivityType;
@@ -80,7 +80,7 @@ export declare const useMessage: (mediator: IMediatorModule) => {
80
80
  result?: {
81
81
  interruptId: string;
82
82
  status: import("..").ResumeStatus;
83
- payload: {
83
+ payload?: {
84
84
  answers: {
85
85
  answer: {
86
86
  description: string;
@@ -954,7 +954,7 @@ export declare const useMessage: (mediator: IMediatorModule) => {
954
954
  result?: {
955
955
  interruptId: string;
956
956
  status: import("..").ResumeStatus;
957
- payload: {
957
+ payload?: {
958
958
  answers: {
959
959
  answer: {
960
960
  description: string;
@@ -1833,7 +1833,7 @@ export declare const useMessage: (mediator: IMediatorModule) => {
1833
1833
  result?: {
1834
1834
  interruptId: string;
1835
1835
  status: import("..").ResumeStatus;
1836
- payload: {
1836
+ payload?: {
1837
1837
  answers: {
1838
1838
  answer: {
1839
1839
  description: string;
@@ -2708,7 +2708,7 @@ export declare const useMessage: (mediator: IMediatorModule) => {
2708
2708
  result?: {
2709
2709
  interruptId: string;
2710
2710
  status: import("..").ResumeStatus;
2711
- payload: {
2711
+ payload?: {
2712
2712
  answers: {
2713
2713
  answer: {
2714
2714
  description: string;
@@ -96,7 +96,7 @@ export declare const useSession: (mediator: IMediatorModule) => {
96
96
  result?: {
97
97
  interruptId: string;
98
98
  status: import("..").ResumeStatus;
99
- payload: {
99
+ payload?: {
100
100
  answers: {
101
101
  answer: {
102
102
  description: string;
@@ -973,7 +973,7 @@ export declare const useSession: (mediator: IMediatorModule) => {
973
973
  result?: {
974
974
  interruptId: string;
975
975
  status: import("..").ResumeStatus;
976
- payload: {
976
+ payload?: {
977
977
  answers: {
978
978
  answer: {
979
979
  description: string;
@@ -1871,7 +1871,7 @@ export declare const useSession: (mediator: IMediatorModule) => {
1871
1871
  result?: {
1872
1872
  interruptId: string;
1873
1873
  status: import("..").ResumeStatus;
1874
- payload: {
1874
+ payload?: {
1875
1875
  answers: {
1876
1876
  answer: {
1877
1877
  description: string;
@@ -2748,7 +2748,7 @@ export declare const useSession: (mediator: IMediatorModule) => {
2748
2748
  result?: {
2749
2749
  interruptId: string;
2750
2750
  status: import("..").ResumeStatus;
2751
- payload: {
2751
+ payload?: {
2752
2752
  answers: {
2753
2753
  answer: {
2754
2754
  description: string;
@@ -3647,7 +3647,7 @@ export declare const useSession: (mediator: IMediatorModule) => {
3647
3647
  result?: {
3648
3648
  interruptId: string;
3649
3649
  status: import("..").ResumeStatus;
3650
- payload: {
3650
+ payload?: {
3651
3651
  answers: {
3652
3652
  answer: {
3653
3653
  description: string;
@@ -4524,7 +4524,7 @@ export declare const useSession: (mediator: IMediatorModule) => {
4524
4524
  result?: {
4525
4525
  interruptId: string;
4526
4526
  status: import("..").ResumeStatus;
4527
- payload: {
4527
+ payload?: {
4528
4528
  answers: {
4529
4529
  answer: {
4530
4530
  description: string;
@@ -5422,7 +5422,7 @@ export declare const useSession: (mediator: IMediatorModule) => {
5422
5422
  result?: {
5423
5423
  interruptId: string;
5424
5424
  status: import("..").ResumeStatus;
5425
- payload: {
5425
+ payload?: {
5426
5426
  answers: {
5427
5427
  answer: {
5428
5428
  description: string;
@@ -6299,7 +6299,7 @@ export declare const useSession: (mediator: IMediatorModule) => {
6299
6299
  result?: {
6300
6300
  interruptId: string;
6301
6301
  status: import("..").ResumeStatus;
6302
- payload: {
6302
+ payload?: {
6303
6303
  answers: {
6304
6304
  answer: {
6305
6305
  description: string;
package/package.json CHANGED
@@ -1,12 +1,9 @@
1
1
  {
2
2
  "name": "@blueking/chat-helper",
3
- "version": "0.0.10-beta.4",
3
+ "version": "0.0.10-dev.1",
4
4
  "description": "",
5
5
  "main": "./dist/index.ts.js",
6
6
  "types": "./dist/index.d.ts",
7
- "scripts": {
8
- "build": "bk-cli-service build && vue-tsc --emitDeclarationOnly"
9
- },
10
7
  "keywords": [
11
8
  "chat-helper"
12
9
  ],
@@ -20,7 +17,6 @@
20
17
  "url": "https://github.com/TencentBlueKing/bk-aidev-agent.git",
21
18
  "directory": "src/frontend/ai-blueking/packages/chat-helper"
22
19
  },
23
- "packageManager": "pnpm@10.17.1",
24
20
  "peerDependencies": {
25
21
  "vue": "^3.5.24"
26
22
  },
@@ -32,5 +28,8 @@
32
28
  },
33
29
  "dependencies": {
34
30
  "@types/json-schema": "^7.0.15"
31
+ },
32
+ "scripts": {
33
+ "build": "bk-cli-service build && vue-tsc --emitDeclarationOnly"
35
34
  }
36
- }
35
+ }