@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,144 @@
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
+ */ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
26
+ try {
27
+ var info = gen[key](arg);
28
+ var value = info.value;
29
+ } catch (error) {
30
+ reject(error);
31
+ return;
32
+ }
33
+ if (info.done) {
34
+ resolve(value);
35
+ } else {
36
+ Promise.resolve(value).then(_next, _throw);
37
+ }
38
+ }
39
+ function _async_to_generator(fn) {
40
+ return function() {
41
+ var self = this, args = arguments;
42
+ return new Promise(function(resolve, reject) {
43
+ var gen = fn.apply(self, args);
44
+ function _next(value) {
45
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
46
+ }
47
+ function _throw(err) {
48
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
49
+ }
50
+ _next(undefined);
51
+ });
52
+ };
53
+ }
54
+ import { ref } from 'vue';
55
+ /**
56
+ * 使用会话模块,主要做业务的组合
57
+ * @param http - HTTP 模块
58
+ * @param message - 消息模块
59
+ * @returns 会话模块
60
+ */ export const useSession = (http, message, agent)=>{
61
+ const list = ref([]);
62
+ const current = ref(null);
63
+ const isCurrentLoading = ref(false);
64
+ const isListLoading = ref(false);
65
+ const isCreateLoading = ref(false);
66
+ const isUpdateLoading = ref(false);
67
+ const isDeleteLoading = ref(false);
68
+ const getSessions = ()=>{
69
+ isListLoading.value = true;
70
+ return http.session.getSessions().then((res)=>{
71
+ list.value = res;
72
+ }).finally(()=>{
73
+ isListLoading.value = false;
74
+ });
75
+ };
76
+ const chooseSession = function() {
77
+ var _ref = _async_to_generator(function*(sessionCode) {
78
+ yield agent.stopChat();
79
+ var _list_value_find;
80
+ // 选择会话
81
+ current.value = (_list_value_find = list.value.find((item)=>item.sessionCode === sessionCode)) !== null && _list_value_find !== void 0 ? _list_value_find : null;
82
+ // 获取会话内容
83
+ message.getMessages(sessionCode);
84
+ });
85
+ return function chooseSession(sessionCode) {
86
+ return _ref.apply(this, arguments);
87
+ };
88
+ }();
89
+ const getSession = (sessionCode)=>{
90
+ isCurrentLoading.value = true;
91
+ return http.session.getSession(sessionCode).then((res)=>{
92
+ current.value = res;
93
+ }).finally(()=>{
94
+ isCurrentLoading.value = false;
95
+ });
96
+ };
97
+ const createSession = (session)=>{
98
+ isCreateLoading.value = true;
99
+ return http.session.plusSession(session).then((res)=>{
100
+ list.value.push(current.value);
101
+ chooseSession(res.sessionCode);
102
+ }).finally(()=>{
103
+ isCreateLoading.value = false;
104
+ });
105
+ };
106
+ const updateSession = (session)=>{
107
+ isUpdateLoading.value = true;
108
+ return http.session.modifySession(session).then((res)=>{
109
+ current.value = res;
110
+ list.value = list.value.map((item)=>item.sessionCode === session.sessionCode ? current.value : item);
111
+ }).finally(()=>{
112
+ isUpdateLoading.value = false;
113
+ });
114
+ };
115
+ const deleteSession = (sessionCode)=>{
116
+ isDeleteLoading.value = true;
117
+ return http.session.deleteSession(sessionCode).then(()=>{
118
+ var _current_value;
119
+ list.value = list.value.filter((item)=>item.sessionCode !== sessionCode);
120
+ // 如果当前会话被删除,选择第一个会话
121
+ if (((_current_value = current.value) === null || _current_value === void 0 ? void 0 : _current_value.sessionCode) === sessionCode) {
122
+ var _list_value_;
123
+ chooseSession((_list_value_ = list.value[0]) === null || _list_value_ === void 0 ? void 0 : _list_value_.sessionCode);
124
+ }
125
+ }).finally(()=>{
126
+ isDeleteLoading.value = false;
127
+ });
128
+ };
129
+ return {
130
+ list,
131
+ current,
132
+ isCurrentLoading,
133
+ isListLoading,
134
+ isCreateLoading,
135
+ isUpdateLoading,
136
+ isDeleteLoading,
137
+ getSessions,
138
+ chooseSession,
139
+ getSession,
140
+ createSession,
141
+ updateSession,
142
+ deleteSession
143
+ };
144
+ };
package/dist/type.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ import type { ISSEProtocol, RequestConfig } from './http/fetch';
2
+ import type { Response } from './http/fetch';
3
+ export interface IUseChatHelperOptions {
4
+ protocol?: ISSEProtocol;
5
+ interceptors?: {
6
+ request?: (config: RequestConfig) => RequestConfig;
7
+ response?: (response: Response) => Response;
8
+ };
9
+ requestData: {
10
+ data?: (() => Record<string, unknown>) | Record<string, unknown>;
11
+ headers?: (() => Record<string, string>) | Record<string, string>;
12
+ urlPrefix: string;
13
+ };
14
+ }
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@blueking/chat-helper",
3
+ "version": "0.0.1-beta.1",
4
+ "description": "",
5
+ "main": "./dist/index.ts.js",
6
+ "scripts": {
7
+ "build": "bk-cli-service build && vue-tsc --emitDeclarationOnly"
8
+ },
9
+ "keywords": [
10
+ "chat-helper"
11
+ ],
12
+ "files": [
13
+ "dist"
14
+ ],
15
+ "author": "",
16
+ "license": "ISC",
17
+ "packageManager": "pnpm@10.17.1",
18
+ "peerDependencies": {
19
+ "vue": "^3.5.24"
20
+ },
21
+ "devDependencies": {
22
+ "@blueking/cli-service": "0.1.0-beta.31",
23
+ "eslint-plugin-simple-import-sort": "^10.0.0",
24
+ "typescript": "^5.5.4",
25
+ "vue-tsc": "^3.1.4"
26
+ }
27
+ }