@blueking/chat-helper 0.0.1-beta.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.
Files changed (51) hide show
  1. package/README.md +1112 -0
  2. package/dist/agent/index.d.ts +2 -0
  3. package/dist/agent/index.ts.js +26 -0
  4. package/dist/agent/type.d.ts +87 -0
  5. package/dist/agent/type.ts.js +25 -0
  6. package/dist/agent/use-agent.d.ts +540 -0
  7. package/dist/agent/use-agent.ts.js +102 -0
  8. package/dist/event/ag-ui.d.ts +137 -0
  9. package/dist/event/ag-ui.ts.js +434 -0
  10. package/dist/event/index.d.ts +2 -0
  11. package/dist/event/index.ts.js +26 -0
  12. package/dist/event/type.d.ts +329 -0
  13. package/dist/event/type.ts.js +64 -0
  14. package/dist/http/fetch/fetch.d.ts +84 -0
  15. package/dist/http/fetch/fetch.ts.js +503 -0
  16. package/dist/http/fetch/index.d.ts +6 -0
  17. package/dist/http/fetch/index.ts.js +41 -0
  18. package/dist/http/index.d.ts +38 -0
  19. package/dist/http/index.ts.js +36 -0
  20. package/dist/http/module/agent.d.ts +9 -0
  21. package/dist/http/module/agent.ts.js +36 -0
  22. package/dist/http/module/index.d.ts +36 -0
  23. package/dist/http/module/index.ts.js +41 -0
  24. package/dist/http/module/message.d.ts +14 -0
  25. package/dist/http/module/message.ts.js +52 -0
  26. package/dist/http/module/session.d.ts +25 -0
  27. package/dist/http/module/session.ts.js +67 -0
  28. package/dist/http/transform/agent.d.ts +7 -0
  29. package/dist/http/transform/agent.ts.js +71 -0
  30. package/dist/http/transform/index.d.ts +3 -0
  31. package/dist/http/transform/index.ts.js +27 -0
  32. package/dist/http/transform/message.d.ts +13 -0
  33. package/dist/http/transform/message.ts.js +155 -0
  34. package/dist/http/transform/session.d.ts +37 -0
  35. package/dist/http/transform/session.ts.js +100 -0
  36. package/dist/index.d.ts +3363 -0
  37. package/dist/index.ts.js +40 -0
  38. package/dist/message/index.d.ts +2 -0
  39. package/dist/message/index.ts.js +26 -0
  40. package/dist/message/type.d.ts +277 -0
  41. package/dist/message/type.ts.js +67 -0
  42. package/dist/message/use-message.d.ts +912 -0
  43. package/dist/message/use-message.ts.js +87 -0
  44. package/dist/session/index.d.ts +2 -0
  45. package/dist/session/index.ts.js +26 -0
  46. package/dist/session/type.d.ts +61 -0
  47. package/dist/session/type.ts.js +25 -0
  48. package/dist/session/use-session.d.ts +1898 -0
  49. package/dist/session/use-session.ts.js +144 -0
  50. package/dist/type.d.ts +14 -0
  51. package/package.json +27 -0
@@ -0,0 +1,36 @@
1
+ import type { FetchClient } from '../fetch';
2
+ /**
3
+ * 使用 HTTP 模块
4
+ * @param fetchClient - 请求客户端
5
+ * @returns HTTP 模块
6
+ */
7
+ export declare const useModule: (fetchClient: FetchClient) => {
8
+ agent: {
9
+ getAgentInfo: (config?: import("../fetch").RequestConfig) => Promise<import("../..").IAgentInfo>;
10
+ };
11
+ session: {
12
+ clearSession: (sessionCode: string, config?: import("../fetch").RequestConfig) => Promise<unknown>;
13
+ getSessions: (config?: import("../fetch").RequestConfig) => Promise<import("../..").ISession<unknown, unknown>[]>;
14
+ plusSession: (data: import("../..").ISession, config?: import("../fetch").RequestConfig) => Promise<import("../..").ISession<unknown, unknown>>;
15
+ modifySession: (data: import("../..").ISession, config?: import("../fetch").RequestConfig) => Promise<import("../..").ISession<unknown, unknown>>;
16
+ deleteSession: (sessionCode: string, config?: import("../fetch").RequestConfig) => Promise<unknown>;
17
+ batchDeleteSessions: (sessionCodes: string[], config?: import("../fetch").RequestConfig) => Promise<number>;
18
+ getSession: (sessionCode: string, config?: import("../fetch").RequestConfig) => Promise<import("../..").ISession<unknown, unknown>>;
19
+ postSessionFeedback: (data: import("../..").ISessionFeedback, config?: import("../fetch").RequestConfig) => Promise<{
20
+ sessionCode: string;
21
+ sessionContentIds: number[];
22
+ rate: number;
23
+ comment: string;
24
+ labels: string[];
25
+ }>;
26
+ getSessionFeedbackLabels: (rate: number, config?: import("../fetch").RequestConfig) => Promise<string[]>;
27
+ renameSession: (sessionCode: string, config?: import("../fetch").RequestConfig) => Promise<import("../..").ISession<unknown, unknown>>;
28
+ };
29
+ message: {
30
+ getMessages: (sessionCode: string, config?: import("../fetch").RequestConfig) => Promise<import("../..").IMessage[]>;
31
+ plusMessage: (data: import("../..").IMessage, config?: import("../fetch").RequestConfig) => Promise<import("../..").IMessageApi>;
32
+ modifyMessage: (data: import("../..").IMessage, config?: import("../fetch").RequestConfig) => Promise<import("../..").IMessageApi>;
33
+ deleteMessage: (id: number, config?: import("../fetch").RequestConfig) => Promise<import("../..").IMessageApi>;
34
+ batchDeleteMessages: (ids: number[], config?: import("../fetch").RequestConfig) => Promise<number>;
35
+ };
36
+ };
@@ -0,0 +1,41 @@
1
+ /*
2
+ * Tencent is pleased to support the open source community by making
3
+ * 蓝鲸智云PaaS平台 (BlueKing PaaS) available.
4
+ *
5
+ * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
6
+ *
7
+ * 蓝鲸智云PaaS平台 (BlueKing PaaS) is licensed under the MIT License.
8
+ *
9
+ * License for 蓝鲸智云PaaS平台 (BlueKing PaaS):
10
+ *
11
+ * ---------------------------------------------------
12
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
13
+ * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
14
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
15
+ * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
16
+ *
17
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of
18
+ * the Software.
19
+ *
20
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
21
+ * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
23
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24
+ * IN THE SOFTWARE.
25
+ */ import { useAgent } from './agent.ts.js';
26
+ import { useMessage } from './message.ts.js';
27
+ import { useSession } from './session.ts.js';
28
+ /**
29
+ * 使用 HTTP 模块
30
+ * @param fetchClient - 请求客户端
31
+ * @returns HTTP 模块
32
+ */ export const useModule = (fetchClient)=>{
33
+ const agent = useAgent(fetchClient);
34
+ const session = useSession(fetchClient);
35
+ const message = useMessage(fetchClient);
36
+ return {
37
+ agent,
38
+ session,
39
+ message
40
+ };
41
+ };
@@ -0,0 +1,14 @@
1
+ import type { IMessage, IMessageApi } from '../../message/type';
2
+ import type { FetchClient, RequestConfig } from '../fetch';
3
+ /**
4
+ * message 相关 http 接口
5
+ * @param fetchClient - 请求客户端
6
+ * @returns message 相关 http 接口
7
+ */
8
+ export declare const useMessage: (fetchClient: FetchClient) => {
9
+ getMessages: (sessionCode: string, config?: RequestConfig) => Promise<IMessage[]>;
10
+ plusMessage: (data: IMessage, config?: RequestConfig) => Promise<IMessageApi>;
11
+ modifyMessage: (data: IMessage, config?: RequestConfig) => Promise<IMessageApi>;
12
+ deleteMessage: (id: number, config?: RequestConfig) => Promise<IMessageApi>;
13
+ batchDeleteMessages: (ids: number[], config?: RequestConfig) => Promise<number>;
14
+ };
@@ -0,0 +1,52 @@
1
+ /*
2
+ * Tencent is pleased to support the open source community by making
3
+ * 蓝鲸智云PaaS平台 (BlueKing PaaS) available.
4
+ *
5
+ * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
6
+ *
7
+ * 蓝鲸智云PaaS平台 (BlueKing PaaS) is licensed under the MIT License.
8
+ *
9
+ * License for 蓝鲸智云PaaS平台 (BlueKing PaaS):
10
+ *
11
+ * ---------------------------------------------------
12
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
13
+ * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
14
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
15
+ * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
16
+ *
17
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of
18
+ * the Software.
19
+ *
20
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
21
+ * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
23
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24
+ * IN THE SOFTWARE.
25
+ */ import { transferMessage2MessageApi, transferMessageApi2Message } from '../transform/message.ts.js';
26
+ /**
27
+ * message 相关 http 接口
28
+ * @param fetchClient - 请求客户端
29
+ * @returns message 相关 http 接口
30
+ */ export const useMessage = (fetchClient)=>{
31
+ // 获取会话内容列表
32
+ const getMessages = (sessionCode, config)=>fetchClient.get(`session_content/content/`, {
33
+ session_code: sessionCode
34
+ }, config).then((res)=>res.map(transferMessageApi2Message));
35
+ // 新增会话内容
36
+ const plusMessage = (data, config)=>fetchClient.post(`session_content/`, transferMessage2MessageApi(data), config);
37
+ // 修改会话内容
38
+ const modifyMessage = (data, config)=>fetchClient.put(`session_content/${data.id}/`, transferMessage2MessageApi(data), config);
39
+ // 删除会话内容
40
+ const deleteMessage = (id, config)=>fetchClient.delete(`session_content/${id}/`, undefined, config);
41
+ // 批量删除聊天内容
42
+ const batchDeleteMessages = (ids, config)=>fetchClient.post(`session_content/batch_delete/`, {
43
+ ids
44
+ }, config);
45
+ return {
46
+ getMessages,
47
+ plusMessage,
48
+ modifyMessage,
49
+ deleteMessage,
50
+ batchDeleteMessages
51
+ };
52
+ };
@@ -0,0 +1,25 @@
1
+ import type { ISession, ISessionFeedback } from '../../session/type';
2
+ import type { FetchClient, RequestConfig } from '../fetch';
3
+ /**
4
+ * session 相关 http 接口
5
+ * @param fetchClient - 请求客户端
6
+ * @returns session 相关 http 接口
7
+ */
8
+ export declare const useSession: (fetchClient: FetchClient) => {
9
+ clearSession: (sessionCode: string, config?: RequestConfig) => Promise<unknown>;
10
+ getSessions: (config?: RequestConfig) => Promise<ISession<unknown, unknown>[]>;
11
+ plusSession: (data: ISession, config?: RequestConfig) => Promise<ISession<unknown, unknown>>;
12
+ modifySession: (data: ISession, config?: RequestConfig) => Promise<ISession<unknown, unknown>>;
13
+ deleteSession: (sessionCode: string, config?: RequestConfig) => Promise<unknown>;
14
+ batchDeleteSessions: (sessionCodes: string[], config?: RequestConfig) => Promise<number>;
15
+ getSession: (sessionCode: string, config?: RequestConfig) => Promise<ISession<unknown, unknown>>;
16
+ postSessionFeedback: (data: ISessionFeedback, config?: RequestConfig) => Promise<{
17
+ sessionCode: string;
18
+ sessionContentIds: number[];
19
+ rate: number;
20
+ comment: string;
21
+ labels: string[];
22
+ }>;
23
+ getSessionFeedbackLabels: (rate: number, config?: RequestConfig) => Promise<string[]>;
24
+ renameSession: (sessionCode: string, config?: RequestConfig) => Promise<ISession<unknown, unknown>>;
25
+ };
@@ -0,0 +1,67 @@
1
+ /*
2
+ * Tencent is pleased to support the open source community by making
3
+ * 蓝鲸智云PaaS平台 (BlueKing PaaS) available.
4
+ *
5
+ * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
6
+ *
7
+ * 蓝鲸智云PaaS平台 (BlueKing PaaS) is licensed under the MIT License.
8
+ *
9
+ * License for 蓝鲸智云PaaS平台 (BlueKing PaaS):
10
+ *
11
+ * ---------------------------------------------------
12
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
13
+ * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
14
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
15
+ * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
16
+ *
17
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of
18
+ * the Software.
19
+ *
20
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
21
+ * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
23
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24
+ * IN THE SOFTWARE.
25
+ */ import { transferSession2SessionApi, transferSessionApi2Session, transferSessionFeedback2SessionFeedbackApi, transferSessionFeedbackApi2SessionFeedback } from '../transform/session.ts.js';
26
+ /**
27
+ * session 相关 http 接口
28
+ * @param fetchClient - 请求客户端
29
+ * @returns session 相关 http 接口
30
+ */ export const useSession = (fetchClient)=>{
31
+ // 清除聊天上下文
32
+ const clearSession = (sessionCode, config)=>fetchClient.post(`chat_completion/${sessionCode}/clear/`, undefined, config);
33
+ // 获取会话列表
34
+ const getSessions = (config)=>fetchClient.get(`session/`, undefined, config).then((res)=>res.map(transferSessionApi2Session));
35
+ // 新增会话
36
+ const plusSession = (data, config)=>fetchClient.post(`session/`, transferSession2SessionApi(data), config).then((res)=>transferSessionApi2Session(res));
37
+ // 修改会话
38
+ const modifySession = (data, config)=>fetchClient.put(`session/${data.sessionCode}/`, transferSession2SessionApi(data), config).then((res)=>transferSessionApi2Session(res));
39
+ // 删除会话
40
+ const deleteSession = (sessionCode, config)=>fetchClient.delete(`session/${sessionCode}/`, undefined, config);
41
+ // 批量删除会话
42
+ const batchDeleteSessions = (sessionCodes, config)=>fetchClient.post(`session/batch_delete/`, {
43
+ session_codes: sessionCodes
44
+ }, config);
45
+ // 获取会话资源
46
+ const getSession = (sessionCode, config)=>fetchClient.get(`session/${sessionCode}/`, undefined, config).then((res)=>transferSessionApi2Session(res));
47
+ // 提交会话反馈
48
+ const postSessionFeedback = (data, config)=>fetchClient.post(`session_feedback/`, transferSessionFeedback2SessionFeedbackApi(data), config).then((res)=>transferSessionFeedbackApi2SessionFeedback(res));
49
+ // 获取反馈标签列表
50
+ const getSessionFeedbackLabels = (rate, config)=>fetchClient.get(`session_feedback/reasons/`, {
51
+ rate
52
+ }, config);
53
+ // 会话重命名
54
+ const renameSession = (sessionCode, config)=>fetchClient.post(`session/${sessionCode}/ai_rename/`, undefined, config).then((res)=>transferSessionApi2Session(res));
55
+ return {
56
+ clearSession,
57
+ getSessions,
58
+ plusSession,
59
+ modifySession,
60
+ deleteSession,
61
+ batchDeleteSessions,
62
+ getSession,
63
+ postSessionFeedback,
64
+ getSessionFeedbackLabels,
65
+ renameSession
66
+ };
67
+ };
@@ -0,0 +1,7 @@
1
+ import type { IAgentInfo, IAgentInfoApi } from '../../agent/type';
2
+ /**
3
+ * 将 API 返回的 agent 信息数据转换为前端使用的 agent 信息数据
4
+ * @param data API 返回的 agent 信息数据
5
+ * @returns 前端使用的 agent 信息数据
6
+ */
7
+ export declare const transferAgentInfoApi2AgentInfo: (data: IAgentInfoApi) => IAgentInfo;
@@ -0,0 +1,71 @@
1
+ /*
2
+ * Tencent is pleased to support the open source community by making
3
+ * 蓝鲸智云PaaS平台 (BlueKing PaaS) available.
4
+ *
5
+ * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
6
+ *
7
+ * 蓝鲸智云PaaS平台 (BlueKing PaaS) is licensed under the MIT License.
8
+ *
9
+ * License for 蓝鲸智云PaaS平台 (BlueKing PaaS):
10
+ *
11
+ * ---------------------------------------------------
12
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
13
+ * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
14
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
15
+ * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
16
+ *
17
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of
18
+ * the Software.
19
+ *
20
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
21
+ * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
23
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24
+ * IN THE SOFTWARE.
25
+ */ import { transferMessageApi2Message } from './message.ts.js';
26
+ /**
27
+ * 将 API 返回的 agent 信息数据转换为前端使用的 agent 信息数据
28
+ * @param data API 返回的 agent 信息数据
29
+ * @returns 前端使用的 agent 信息数据
30
+ */ export const transferAgentInfoApi2AgentInfo = (data)=>{
31
+ var _data_conversation_settings, _data_conversation_settings1, _data_conversation_settings_commands, _data_conversation_settings2, _data_conversation_settings3, _data_prompt_setting_content, _data_prompt_setting;
32
+ return {
33
+ conversationSettings: {
34
+ openingRemark: data === null || data === void 0 ? void 0 : (_data_conversation_settings = data.conversation_settings) === null || _data_conversation_settings === void 0 ? void 0 : _data_conversation_settings.opening_remark,
35
+ predefinedQuestions: data === null || data === void 0 ? void 0 : (_data_conversation_settings1 = data.conversation_settings) === null || _data_conversation_settings1 === void 0 ? void 0 : _data_conversation_settings1.predefined_questions,
36
+ commands: data === null || data === void 0 ? void 0 : (_data_conversation_settings2 = data.conversation_settings) === null || _data_conversation_settings2 === void 0 ? void 0 : (_data_conversation_settings_commands = _data_conversation_settings2.commands) === null || _data_conversation_settings_commands === void 0 ? void 0 : _data_conversation_settings_commands.map((command)=>({
37
+ id: command.id,
38
+ name: command.name,
39
+ icon: command.icon,
40
+ components: command.components.map((component)=>({
41
+ type: component.type,
42
+ name: component.name,
43
+ key: component.key,
44
+ placeholder: component.placeholder,
45
+ default: component.default,
46
+ required: component.required,
47
+ fillBack: component.fill_back,
48
+ fillRegx: component.fill_regx,
49
+ rows: component.rows,
50
+ min: component.min,
51
+ max: component.max,
52
+ options: component.options
53
+ })),
54
+ content: command.content,
55
+ agentId: command.agent_id,
56
+ status: command.status
57
+ })),
58
+ enableChatSession: data === null || data === void 0 ? void 0 : (_data_conversation_settings3 = data.conversation_settings) === null || _data_conversation_settings3 === void 0 ? void 0 : _data_conversation_settings3.enable_chat_session
59
+ },
60
+ promptSetting: {
61
+ content: data === null || data === void 0 ? void 0 : (_data_prompt_setting = data.prompt_setting) === null || _data_prompt_setting === void 0 ? void 0 : (_data_prompt_setting_content = _data_prompt_setting.content) === null || _data_prompt_setting_content === void 0 ? void 0 : _data_prompt_setting_content.map(transferMessageApi2Message)
62
+ },
63
+ agentName: data === null || data === void 0 ? void 0 : data.agent_name,
64
+ chatGroup: (data === null || data === void 0 ? void 0 : data.chat_group) ? {
65
+ enabled: data.chat_group.enabled,
66
+ staff: data.chat_group.staff,
67
+ username: data.chat_group.username
68
+ } : undefined,
69
+ saasUrl: data === null || data === void 0 ? void 0 : data.saas_url
70
+ };
71
+ };
@@ -0,0 +1,3 @@
1
+ export * from './agent';
2
+ export * from './message';
3
+ export * from './session';
@@ -0,0 +1,27 @@
1
+ /*
2
+ * Tencent is pleased to support the open source community by making
3
+ * 蓝鲸智云PaaS平台 (BlueKing PaaS) available.
4
+ *
5
+ * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
6
+ *
7
+ * 蓝鲸智云PaaS平台 (BlueKing PaaS) is licensed under the MIT License.
8
+ *
9
+ * License for 蓝鲸智云PaaS平台 (BlueKing PaaS):
10
+ *
11
+ * ---------------------------------------------------
12
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
13
+ * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
14
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
15
+ * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
16
+ *
17
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of
18
+ * the Software.
19
+ *
20
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
21
+ * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
23
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24
+ * IN THE SOFTWARE.
25
+ */ export * from './agent.ts.js';
26
+ export * from './message.ts.js';
27
+ export * from './session.ts.js';
@@ -0,0 +1,13 @@
1
+ import type { IMessage, IMessageApi } from '../../message/type';
2
+ /**
3
+ * 将 API 返回的 message 数据转换为前端使用的 message 数据
4
+ * @param data API 返回的 message 数据
5
+ * @returns 前端使用的 message 数据
6
+ */
7
+ export declare const transferMessageApi2Message: (data: IMessageApi) => IMessage;
8
+ /**
9
+ * 将前端使用的 message 数据转换为 API 返回的 message 数据
10
+ * @param data 前端使用的 message 数据
11
+ * @returns API 返回的 message 数据
12
+ */
13
+ export declare const transferMessage2MessageApi: (data: IMessage) => IMessageApi;
@@ -0,0 +1,155 @@
1
+ /*
2
+ * Tencent is pleased to support the open source community by making
3
+ * 蓝鲸智云PaaS平台 (BlueKing PaaS) available.
4
+ *
5
+ * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
6
+ *
7
+ * 蓝鲸智云PaaS平台 (BlueKing PaaS) is licensed under the MIT License.
8
+ *
9
+ * License for 蓝鲸智云PaaS平台 (BlueKing PaaS):
10
+ *
11
+ * ---------------------------------------------------
12
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
13
+ * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
14
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
15
+ * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
16
+ *
17
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of
18
+ * the Software.
19
+ *
20
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
21
+ * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
23
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24
+ * IN THE SOFTWARE.
25
+ */ import { MessageContentType } from '../../message/type.ts.js';
26
+ /**
27
+ * 将 API 返回的 message 数据转换为前端使用的 message 数据
28
+ * @param data API 返回的 message 数据
29
+ * @returns 前端使用的 message 数据
30
+ */ export const transferMessageApi2Message = (data)=>{
31
+ const message = {
32
+ id: data.id,
33
+ status: data.status,
34
+ role: data.role,
35
+ content: data.content.map(transferMessageContentApi2MessageContent),
36
+ property: data.property
37
+ };
38
+ return message;
39
+ };
40
+ /**
41
+ * 将前端使用的 message 数据转换为 API 返回的 message 数据
42
+ * @param data 前端使用的 message 数据
43
+ * @returns API 返回的 message 数据
44
+ */ export const transferMessage2MessageApi = (data)=>{
45
+ const messageApi = {
46
+ id: data.id,
47
+ status: data.status,
48
+ role: data.role,
49
+ content: data.content.map(transferMessageContent2MessageContentApi),
50
+ property: data.property
51
+ };
52
+ return messageApi;
53
+ };
54
+ /**
55
+ * 将 API 返回的 message 数据中的内容数据转换为前端使用的 message 内容数据
56
+ * @param content API 返回的 message 数据中的内容数据
57
+ * @returns 前端使用的 message 内容数据
58
+ */ const transferMessageContentApi2MessageContent = (content)=>{
59
+ switch(content.type){
60
+ case MessageContentType.Text:
61
+ return {
62
+ type: MessageContentType.Text,
63
+ id: content.id,
64
+ data: content.data,
65
+ status: content.status
66
+ };
67
+ case MessageContentType.Thinking:
68
+ return {
69
+ type: MessageContentType.Thinking,
70
+ data: content.data,
71
+ status: content.status
72
+ };
73
+ case MessageContentType.ToolCall:
74
+ return {
75
+ type: MessageContentType.ToolCall,
76
+ data: {
77
+ toolCallId: content.data.tool_call_id,
78
+ toolCallName: content.data.tool_call_name,
79
+ parentMessageId: content.data.parent_message_id,
80
+ args: content.data.args,
81
+ chunk: content.data.chunk,
82
+ result: content.data.result
83
+ },
84
+ status: content.status
85
+ };
86
+ case MessageContentType.Image:
87
+ return {
88
+ type: MessageContentType.Image,
89
+ data: content.data,
90
+ status: content.status
91
+ };
92
+ case MessageContentType.ReferenceDocument:
93
+ return {
94
+ type: MessageContentType.ReferenceDocument,
95
+ data: content.data.map((item)=>({
96
+ title: item.title,
97
+ icon: item.icon,
98
+ url: item.url,
99
+ originFileUrl: item.origin_file_url
100
+ })),
101
+ status: content.status
102
+ };
103
+ }
104
+ };
105
+ /**
106
+ * 将前端使用的 message 内容数据转换为 API 返回的 message 内容数据
107
+ * @param data 前端使用的 message 内容数据
108
+ * @returns API 返回的 message 内容数据
109
+ */ const transferMessageContent2MessageContentApi = (content)=>{
110
+ switch(content.type){
111
+ case MessageContentType.Text:
112
+ return {
113
+ type: MessageContentType.Text,
114
+ id: content.id,
115
+ data: content.data,
116
+ status: content.status
117
+ };
118
+ case MessageContentType.Thinking:
119
+ return {
120
+ type: MessageContentType.Thinking,
121
+ data: content.data,
122
+ status: content.status
123
+ };
124
+ case MessageContentType.ToolCall:
125
+ return {
126
+ type: MessageContentType.ToolCall,
127
+ data: {
128
+ tool_call_id: content.data.toolCallId,
129
+ tool_call_name: content.data.toolCallName,
130
+ parent_message_id: content.data.parentMessageId,
131
+ args: content.data.args,
132
+ chunk: content.data.chunk,
133
+ result: content.data.result
134
+ },
135
+ status: content.status
136
+ };
137
+ case MessageContentType.Image:
138
+ return {
139
+ type: MessageContentType.Image,
140
+ data: content.data,
141
+ status: content.status
142
+ };
143
+ case MessageContentType.ReferenceDocument:
144
+ return {
145
+ type: MessageContentType.ReferenceDocument,
146
+ data: content.data.map((item)=>({
147
+ title: item.title,
148
+ icon: item.icon,
149
+ url: item.url,
150
+ origin_file_url: item.originFileUrl
151
+ })),
152
+ status: content.status
153
+ };
154
+ }
155
+ };
@@ -0,0 +1,37 @@
1
+ import type { ISession, ISessionApi, ISessionFeedback, ISessionFeedbackApi } from '../../session/type';
2
+ /**
3
+ * 将 API 返回的 session 数据转换为前端使用的 session 数据
4
+ * @param data API 返回的 session 数据
5
+ * @returns 前端使用的 session 数据
6
+ */
7
+ export declare const transferSessionApi2Session: (data: ISessionApi) => ISession;
8
+ /**
9
+ * 将前端使用的 session 数据转换为 API 使用的 session 数据
10
+ * @param data 前端使用的 session 数据
11
+ * @returns API 使用的 session 数据
12
+ */
13
+ export declare const transferSession2SessionApi: (data: ISession) => ISessionApi;
14
+ /**
15
+ * 将前端使用的 session 反馈数据转换为 API 使用的 session 反馈数据
16
+ * @param data 前端使用的 session 反馈数据
17
+ * @returns API 使用的 session 反馈数据
18
+ */
19
+ export declare const transferSessionFeedback2SessionFeedbackApi: (data: ISessionFeedback) => {
20
+ session_code: string;
21
+ session_content_ids: number[];
22
+ rate: number;
23
+ comment: string;
24
+ labels: string[];
25
+ };
26
+ /**
27
+ * 将 API 返回的 session 反馈数据转换为前端使用的 session 反馈数据
28
+ * @param data API 返回的 session 反馈数据
29
+ * @returns 前端使用的 session 反馈数据
30
+ */
31
+ export declare const transferSessionFeedbackApi2SessionFeedback: (data: ISessionFeedbackApi) => {
32
+ sessionCode: string;
33
+ sessionContentIds: number[];
34
+ rate: number;
35
+ comment: string;
36
+ labels: string[];
37
+ };