@blueking/chat-helper 0.0.12-beta.12 → 0.0.12-beta.13

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,13 +1,11 @@
1
- import { type IMessageApi, type IMessageArtifact, type MessageRole, type MessageStatus } from '../message/type';
1
+ import { type IMessageApi, type MessageRole, type MessageStatus } from '../message/type';
2
2
  import type { JSONSchema4 } from 'json-schema';
3
3
  export declare enum CustomEventName {
4
- ArtifactsGenerated = "artifacts_generated",
5
4
  FlowAgentEnd = "flow_agent_end",
6
5
  FlowAgentResult = "flow_agent_result",
7
6
  FlowAgentStart = "flow_agent_start",
8
7
  FlowAgentUpdate = "flow_agent_update",
9
8
  FlowAgentRestart = "flow_agent_restart",
10
- Info = "info",
11
9
  KnowledgeRagEnd = "knowledge_rag_end",
12
10
  KnowledgeRagResult = "knowledge_rag_result",
13
11
  KnowledgeRagStart = "knowledge_rag_start",
@@ -116,11 +114,6 @@ export interface IActivitySnapshotEvent extends IBaseEvent {
116
114
  replace?: boolean;
117
115
  type: EventType.ActivitySnapshot;
118
116
  }
119
- export interface IArtifactsGeneratedCustomValue {
120
- artifacts: IMessageArtifact[];
121
- runId: string;
122
- status: 'complete' | 'empty';
123
- }
124
117
  export interface IBaseEvent {
125
118
  timestamp?: number;
126
119
  type: EventType;
@@ -132,7 +125,7 @@ export interface IBaseEvent {
132
125
  export interface ICustomEvent extends IBaseEvent {
133
126
  name: CustomEventName;
134
127
  type: EventType.Custom;
135
- value: IArtifactsGeneratedCustomValue | IFlowAgentEndCustomValue | IFlowAgentResultCustomValue | IFlowAgentStartCustomValue | IFlowAgentRestartCustomValue | IInfoCustomValue | IKnowledgeRagResultCustomValue | IKnowledgeRagTextContentCustomValue | IReferenceDocumentCustomValue | ITempMessageCustomValue | IApprovalResultCustomValue;
128
+ value: IFlowAgentEndCustomValue | IFlowAgentResultCustomValue | IFlowAgentStartCustomValue | IFlowAgentRestartCustomValue | IKnowledgeRagResultCustomValue | IKnowledgeRagTextContentCustomValue | IReferenceDocumentCustomValue | ITempMessageCustomValue | IApprovalResultCustomValue;
136
129
  }
137
130
  export type IEvent = IActivityDeltaEvent | IActivitySnapshotEvent | ICustomEvent | IMessagesSnapshotEvent | IRawEvent | IRunErrorEvent | IRunFinishedEvent | IRunStartedEvent | IStateDeltaEvent | IStateSnapshotEvent | IStepFinishedEvent | IStepStartedEvent | ITextMessageChunkEvent | ITextMessageContentEvent | ITextMessageEndEvent | ITextMessageStartEvent | IThinkingEndEvent | IThinkingStartEvent | IThinkingTextMessageContentEvent | IThinkingTextMessageEndEvent | IThinkingTextMessageStartEvent | IToolCallArgsEvent | IToolCallChunkEvent | IToolCallEndEvent | IToolCallResultEvent | IToolCallStartEvent;
138
131
  export type IFlowAgentEndCustomValue = {
@@ -159,10 +152,6 @@ export type IFlowAgentStartCustomValue = {
159
152
  task_id: string;
160
153
  }[];
161
154
  export type IFlowAgentRestartCustomValue = IFlowAgentStartCustomValue;
162
- export interface IInfoCustomValue {
163
- content: string;
164
- messageId: string;
165
- }
166
155
  export type IKnowledgeRagResultCustomValue = IReferenceDocumentCustomValue;
167
156
  export interface IKnowledgeRagTextContentCustomValue {
168
157
  cover: boolean;
@@ -24,13 +24,11 @@
24
24
  * IN THE SOFTWARE.
25
25
  */ export var CustomEventName;
26
26
  (function(CustomEventName) {
27
- CustomEventName["ArtifactsGenerated"] = "artifacts_generated";
28
27
  CustomEventName["FlowAgentEnd"] = "flow_agent_end";
29
28
  CustomEventName["FlowAgentResult"] = "flow_agent_result";
30
29
  CustomEventName["FlowAgentStart"] = "flow_agent_start";
31
30
  CustomEventName["FlowAgentUpdate"] = "flow_agent_update";
32
31
  CustomEventName["FlowAgentRestart"] = "flow_agent_restart";
33
- CustomEventName["Info"] = "info";
34
32
  CustomEventName["KnowledgeRagEnd"] = "knowledge_rag_end";
35
33
  CustomEventName["KnowledgeRagResult"] = "knowledge_rag_result";
36
34
  CustomEventName["KnowledgeRagStart"] = "knowledge_rag_start";
@@ -12,7 +12,6 @@ export declare const useHttp: (options: IUseChatHelperOptions) => {
12
12
  onError: (handler: import("./fetch").GlobalErrorHandler, options?: import("./fetch").ErrorHandlerOptions) => void;
13
13
  agent: {
14
14
  getAgentInfo: (config?: import("./fetch").IRequestConfig) => Promise<import("..").IAgentInfo>;
15
- getLlms: (params?: import("..").ILlmListQuery, config?: import("./fetch").IRequestConfig) => Promise<import("..").ILlmItem[]>;
16
15
  };
17
16
  session: {
18
17
  clearSession: (sessionCode: string, config?: import("./fetch").IRequestConfig) => Promise<unknown>;
@@ -39,7 +38,6 @@ export declare const useHttp: (options: IUseChatHelperOptions) => {
39
38
  uploadFile: (sessionCode: string, file: File, config?: import("./fetch").IRequestConfig) => Promise<{
40
39
  download_url?: string;
41
40
  }>;
42
- getPvFileDownloadUrl: (sessionCode: string, path: string, options?: import("..").GetPvFileDownloadUrlOptions, config?: import("./fetch").IRequestConfig) => Promise<import("..").IPvFileDownloadUrlResult>;
43
41
  isResumeSession: (sessionCode: string, config?: import("./fetch").IRequestConfig) => Promise<boolean>;
44
42
  };
45
43
  message: {
@@ -1,4 +1,3 @@
1
- import type { ILlmItem, ILlmListQuery } from '../../agent/type';
2
1
  import type { FetchClient, IRequestConfig } from '../fetch';
3
2
  /**
4
3
  * agent 相关 http 接口
@@ -7,5 +6,4 @@ import type { FetchClient, IRequestConfig } from '../fetch';
7
6
  */
8
7
  export declare const useAgent: (fetchClient: FetchClient) => {
9
8
  getAgentInfo: (config?: IRequestConfig) => Promise<import("../../agent/type").IAgentInfo>;
10
- getLlms: (params?: ILlmListQuery, config?: IRequestConfig) => Promise<ILlmItem[]>;
11
9
  };
@@ -22,7 +22,7 @@
22
22
  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
23
23
  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24
24
  * IN THE SOFTWARE.
25
- */ import { transferAgentInfoApi2AgentInfo, transferLlmListApi2LlmItems } from '../transform/agent.ts.js';
25
+ */ import { transferAgentInfoApi2AgentInfo } from '../transform/agent.ts.js';
26
26
  /**
27
27
  * agent 相关 http 接口
28
28
  * @param fetchClient - 请求客户端
@@ -30,24 +30,7 @@
30
30
  */ export const useAgent = (fetchClient)=>{
31
31
  // 获取 agent 信息
32
32
  const getAgentInfo = (config)=>fetchClient.get('agent/info/', undefined, config).then(transferAgentInfoApi2AgentInfo);
33
- /**
34
- * 获取当前空间可用模型列表(公开 + 空间授权 + 用户权限交集)
35
- * @param params 查询参数;未传 llm_type 时默认 chat.completion
36
- */ const getLlms = (params, config)=>{
37
- var _params_llm_type;
38
- const query = {
39
- llm_type: (_params_llm_type = params === null || params === void 0 ? void 0 : params.llm_type) !== null && _params_llm_type !== void 0 ? _params_llm_type : 'chat.completion'
40
- };
41
- if (params === null || params === void 0 ? void 0 : params.fuzzy) {
42
- query.fuzzy = params.fuzzy;
43
- }
44
- if (params === null || params === void 0 ? void 0 : params.supports) {
45
- query.supports = params.supports;
46
- }
47
- return fetchClient.get('llms/', query, config).then(transferLlmListApi2LlmItems);
48
- };
49
33
  return {
50
- getAgentInfo,
51
- getLlms
34
+ getAgentInfo
52
35
  };
53
36
  };
@@ -7,7 +7,6 @@ import type { FetchClient } from '../fetch';
7
7
  export declare const useModule: (fetchClient: FetchClient) => {
8
8
  agent: {
9
9
  getAgentInfo: (config?: import("../fetch").IRequestConfig) => Promise<import("../..").IAgentInfo>;
10
- getLlms: (params?: import("../..").ILlmListQuery, config?: import("../fetch").IRequestConfig) => Promise<import("../..").ILlmItem[]>;
11
10
  };
12
11
  session: {
13
12
  clearSession: (sessionCode: string, config?: import("../fetch").IRequestConfig) => Promise<unknown>;
@@ -34,7 +33,6 @@ export declare const useModule: (fetchClient: FetchClient) => {
34
33
  uploadFile: (sessionCode: string, file: File, config?: import("../fetch").IRequestConfig) => Promise<{
35
34
  download_url?: string;
36
35
  }>;
37
- getPvFileDownloadUrl: (sessionCode: string, path: string, options?: import("../..").GetPvFileDownloadUrlOptions, config?: import("../fetch").IRequestConfig) => Promise<import("../..").IPvFileDownloadUrlResult>;
38
36
  isResumeSession: (sessionCode: string, config?: import("../fetch").IRequestConfig) => Promise<boolean>;
39
37
  };
40
38
  message: {
@@ -50,7 +50,7 @@ function _object_spread(target) {
50
50
  }
51
51
  return target;
52
52
  }
53
- import { transferMessage2MessageApi, transferMessageApi2Message, mergeArtifactsActivityIntoMessages } from '../transform/message.ts.js';
53
+ import { transferMessage2MessageApi, transferMessageApi2Message } from '../transform/message.ts.js';
54
54
  /**
55
55
  * message 相关 http 接口
56
56
  * @param fetchClient - 请求客户端
@@ -60,7 +60,7 @@ import { transferMessage2MessageApi, transferMessageApi2Message, mergeArtifactsA
60
60
  const getMessages = (sessionCode, limit, config)=>fetchClient.get(`session_content/content/`, {
61
61
  session_code: sessionCode,
62
62
  limit
63
- }, config).then((res)=>mergeArtifactsActivityIntoMessages(res.map(transferMessageApi2Message)));
63
+ }, config).then((res)=>res.map(transferMessageApi2Message));
64
64
  // 新增会话内容
65
65
  const plusMessage = (data, config)=>fetchClient.post(`session_content/`, transferMessage2MessageApi(data), config).then(transferMessageApi2Message);
66
66
  // 修改会话内容
@@ -1,4 +1,4 @@
1
- import type { GetPvFileDownloadUrlOptions, IPvFileDownloadUrlResult, ISession, ISessionFeedback, ISessionListParams } from '../../session/type';
1
+ import type { ISession, ISessionFeedback, ISessionListParams } from '../../session/type';
2
2
  import type { FetchClient, IRequestConfig } from '../fetch';
3
3
  /**
4
4
  * session 相关 http 接口
@@ -30,6 +30,5 @@ export declare const useSession: (fetchClient: FetchClient) => {
30
30
  uploadFile: (sessionCode: string, file: File, config?: IRequestConfig) => Promise<{
31
31
  download_url?: string;
32
32
  }>;
33
- getPvFileDownloadUrl: (sessionCode: string, path: string, options?: GetPvFileDownloadUrlOptions, config?: IRequestConfig) => Promise<IPvFileDownloadUrlResult>;
34
33
  isResumeSession: (sessionCode: string, config?: IRequestConfig) => Promise<boolean>;
35
34
  };
@@ -78,8 +78,6 @@ import { transferSession2SessionApi, transferSessionApi2Session, transferSession
78
78
  import { resolveRequestValue } from '../fetch/index.ts.js';
79
79
  /** 上传接口传输用文件名前缀,与原始展示名解耦 */ const UPLOAD_FILE_NAME_PREFIX = 'upload_file';
80
80
  /** 会话列表默认每页条数 */ const DEFAULT_PAGE_SIZE = 20;
81
- const DEFAULT_PV_FILE_DOWNLOAD_EXPIRES_IN = 600;
82
- const DEFAULT_PV_FILE_DOWNLOAD_TIMEOUT = 20000;
83
81
  /**
84
82
  * 将会话列表接口响应统一为分页结构。
85
83
  * 兼容两类后台:
@@ -169,22 +167,6 @@ const DEFAULT_PV_FILE_DOWNLOAD_TIMEOUT = 20000;
169
167
  })
170
168
  })));
171
169
  };
172
- /**
173
- * 签发会话 PV 文件的临时 download_url / preview_url。
174
- * path 为文件相对路径(artifacts 的 outputId);URLSearchParams 会自动编码,勿二次 encode。
175
- */ const getPvFileDownloadUrl = (sessionCode, path, options, config)=>{
176
- var _options_expiresIn;
177
- const expiresIn = (_options_expiresIn = options === null || options === void 0 ? void 0 : options.expiresIn) !== null && _options_expiresIn !== void 0 ? _options_expiresIn : DEFAULT_PV_FILE_DOWNLOAD_EXPIRES_IN;
178
- var _options_timeout;
179
- const timeout = (_options_timeout = options === null || options === void 0 ? void 0 : options.timeout) !== null && _options_timeout !== void 0 ? _options_timeout : DEFAULT_PV_FILE_DOWNLOAD_TIMEOUT;
180
- var _config_timeout;
181
- return fetchClient.get(`session/${sessionCode}/pv_files/download_url/`, {
182
- expires_in: expiresIn,
183
- path
184
- }, _object_spread_props(_object_spread({}, config), {
185
- timeout: (_config_timeout = config === null || config === void 0 ? void 0 : config.timeout) !== null && _config_timeout !== void 0 ? _config_timeout : timeout
186
- }));
187
- };
188
170
  // 轮询接口,判断是否可以继续聊天
189
171
  const isResumeSession = (sessionCode, config)=>fetchClient.get(`session/${sessionCode}/is_resume/`, undefined, config);
190
172
  return {
@@ -199,7 +181,6 @@ const DEFAULT_PV_FILE_DOWNLOAD_TIMEOUT = 20000;
199
181
  getSessionFeedbackReasons,
200
182
  renameSession,
201
183
  uploadFile,
202
- getPvFileDownloadUrl,
203
184
  isResumeSession
204
185
  };
205
186
  };
@@ -1,15 +1,7 @@
1
- import type { IAgentInfo, IAgentInfoApi, ILlmItem, ILlmItemApi } from '../../agent/type';
1
+ import type { IAgentInfo, IAgentInfoApi } from '../../agent/type';
2
2
  /**
3
3
  * 将 API 返回的 agent 信息数据转换为前端使用的 agent 信息数据
4
4
  * @param data API 返回的 agent 信息数据
5
5
  * @returns 前端使用的 agent 信息数据
6
6
  */
7
7
  export declare const transferAgentInfoApi2AgentInfo: (data: IAgentInfoApi) => IAgentInfo;
8
- /**
9
- * 将 llms/ 接口单项规范化为前端 ILlmItem(补齐缺省字段,避免 UI 崩溃)
10
- */
11
- export declare const transferLlmApi2LlmItem: (data: ILlmItemApi) => ILlmItem;
12
- /**
13
- * 将 llms/ 列表响应规范化为 ILlmItem[]
14
- */
15
- export declare const transferLlmListApi2LlmItems: (data: ILlmItemApi[] | null | undefined) => ILlmItem[];
@@ -79,30 +79,3 @@
79
79
  resources: data === null || data === void 0 ? void 0 : data.resources
80
80
  };
81
81
  };
82
- /**
83
- * 将 llms/ 接口单项规范化为前端 ILlmItem(补齐缺省字段,避免 UI 崩溃)
84
- */ export const transferLlmApi2LlmItem = (data)=>{
85
- var _data_id, _data_llm_type, _data_icon, _data_description, _data_max_token_size, _data_property, _data_space_auth_mode, _data_user_auth_mode;
86
- return {
87
- id: (_data_id = data.id) !== null && _data_id !== void 0 ? _data_id : 0,
88
- llm_code: data.llm_code,
89
- llm_name: data.llm_name,
90
- llm_type: (_data_llm_type = data.llm_type) !== null && _data_llm_type !== void 0 ? _data_llm_type : 'chat.completion',
91
- icon: (_data_icon = data.icon) !== null && _data_icon !== void 0 ? _data_icon : '',
92
- description: (_data_description = data.description) !== null && _data_description !== void 0 ? _data_description : '',
93
- base_model: data.base_model,
94
- max_token_size: (_data_max_token_size = data.max_token_size) !== null && _data_max_token_size !== void 0 ? _data_max_token_size : 0,
95
- property: (_data_property = data.property) !== null && _data_property !== void 0 ? _data_property : {},
96
- space_auth_mode: (_data_space_auth_mode = data.space_auth_mode) !== null && _data_space_auth_mode !== void 0 ? _data_space_auth_mode : '',
97
- user_auth_mode: (_data_user_auth_mode = data.user_auth_mode) !== null && _data_user_auth_mode !== void 0 ? _data_user_auth_mode : '',
98
- tag_names: data.tag_names
99
- };
100
- };
101
- /**
102
- * 将 llms/ 列表响应规范化为 ILlmItem[]
103
- */ export const transferLlmListApi2LlmItems = (data)=>{
104
- if (!Array.isArray(data)) {
105
- return [];
106
- }
107
- return data.map(transferLlmApi2LlmItem);
108
- };
@@ -11,9 +11,3 @@ export declare const transferMessageApi2Message: (data: IMessageApi) => IMessage
11
11
  * @returns API 使用的消息数据
12
12
  */
13
13
  export declare const transferMessage2MessageApi: (data: IMessage) => IMessageApi;
14
- /**
15
- * 将历史/快照中的 artifacts_generated activity 合并到前一条 Assistant 的 property.artifacts,
16
- * 并过滤掉该 activity(UI 只从 Assistant.property.artifacts 渲染)。
17
- * 实时 SSE 已写过 property.artifacts;历史回填依赖此归一化。
18
- */
19
- export declare const mergeArtifactsActivityIntoMessages: (messages: IMessage[]) => IMessage[];
@@ -113,7 +113,6 @@ import { ActivityType, MessageRole, MessageType } from '../../message/type.ts.js
113
113
  break;
114
114
  }
115
115
  case ActivityType.FlowAgent:
116
- case ActivityType.ArtifactsGenerated:
117
116
  default:
118
117
  content = activityData.content;
119
118
  break;
@@ -121,7 +120,6 @@ import { ActivityType, MessageRole, MessageType } from '../../message/type.ts.js
121
120
  const result = _object_spread_props(_object_spread({}, baseMessage), {
122
121
  activityType: activityData.activity_type,
123
122
  content,
124
- property: activityData.property,
125
123
  role: activityData.role
126
124
  });
127
125
  return result;
@@ -384,7 +382,6 @@ import { ActivityType, MessageRole, MessageType } from '../../message/type.ts.js
384
382
  break;
385
383
  }
386
384
  case ActivityType.FlowAgent:
387
- case ActivityType.ArtifactsGenerated:
388
385
  default:
389
386
  content = activityData.content;
390
387
  break;
@@ -392,7 +389,6 @@ import { ActivityType, MessageRole, MessageType } from '../../message/type.ts.js
392
389
  const result = _object_spread_props(_object_spread({}, baseMessage), {
393
390
  activity_type: activityData.activityType,
394
391
  content,
395
- property: activityData.property,
396
392
  role: activityData.role
397
393
  });
398
394
  return result;
@@ -617,55 +613,3 @@ import { ActivityType, MessageRole, MessageType } from '../../message/type.ts.js
617
613
  }
618
614
  }
619
615
  };
620
- /**
621
- * 将历史/快照中的 artifacts_generated activity 合并到前一条 Assistant 的 property.artifacts,
622
- * 并过滤掉该 activity(UI 只从 Assistant.property.artifacts 渲染)。
623
- * 实时 SSE 已写过 property.artifacts;历史回填依赖此归一化。
624
- */ export const mergeArtifactsActivityIntoMessages = (messages)=>{
625
- const result = [];
626
- for (const message of messages){
627
- var _activity_content, _activity_property;
628
- if (message.role !== MessageRole.Activity) {
629
- result.push(message);
630
- continue;
631
- }
632
- const activity = message;
633
- if (activity.activityType !== ActivityType.ArtifactsGenerated) {
634
- result.push(message);
635
- continue;
636
- }
637
- const artifacts = (_activity_content = activity.content) === null || _activity_content === void 0 ? void 0 : _activity_content.artifacts;
638
- // status=empty 或无产物:丢弃 activity,不渲染
639
- if (!(artifacts === null || artifacts === void 0 ? void 0 : artifacts.length)) {
640
- continue;
641
- }
642
- const activityTurnId = (_activity_property = activity.property) === null || _activity_property === void 0 ? void 0 : _activity_property.turn_id;
643
- let matchedByTurn = -1;
644
- let nearestAssistant = -1;
645
- for(let i = result.length - 1; i >= 0; i -= 1){
646
- var _candidate_property;
647
- if (result[i].role !== MessageRole.Assistant) {
648
- continue;
649
- }
650
- const candidate = result[i];
651
- if (nearestAssistant < 0) {
652
- nearestAssistant = i;
653
- }
654
- if (activityTurnId && ((_candidate_property = candidate.property) === null || _candidate_property === void 0 ? void 0 : _candidate_property.turn_id) === activityTurnId) {
655
- matchedByTurn = i;
656
- break;
657
- }
658
- }
659
- const targetIndex = matchedByTurn >= 0 ? matchedByTurn : nearestAssistant;
660
- if (targetIndex >= 0) {
661
- const assistant = result[targetIndex];
662
- result[targetIndex] = _object_spread_props(_object_spread({}, assistant), {
663
- property: _object_spread_props(_object_spread({}, assistant.property), {
664
- artifacts
665
- })
666
- });
667
- }
668
- // 始终丢弃 artifacts_generated activity
669
- }
670
- return result;
671
- };