@core-pilot/sdk 0.0.0-beta.7 → 0.0.0-beta.8
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/dist/index.css +1 -1
- package/dist/index.js +333 -318
- package/dist/index.umd.cjs +1 -7
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -13,106 +13,106 @@ function formatArgs(e) {
|
|
|
13
13
|
}
|
|
14
14
|
}).join(" ");
|
|
15
15
|
}
|
|
16
|
-
function createLogger(e,
|
|
17
|
-
let
|
|
18
|
-
if (!
|
|
19
|
-
let
|
|
20
|
-
|
|
21
|
-
let
|
|
22
|
-
navigator.sendBeacon ? navigator.sendBeacon(
|
|
16
|
+
function createLogger(e, s, c) {
|
|
17
|
+
let l = "[CorePilot]", u = [], d = null, f = c?.batchSize ?? 20, p = c?.flushInterval ?? 15e3, m = () => {
|
|
18
|
+
if (!c || u.length === 0) return;
|
|
19
|
+
let s = [...u];
|
|
20
|
+
u = [], e && console.log(`${l} Uploading ${s.length} log(s) to ${c.url}`);
|
|
21
|
+
let d = JSON.stringify(s);
|
|
22
|
+
navigator.sendBeacon ? navigator.sendBeacon(c.url, d) : fetch(c.url, {
|
|
23
23
|
method: "POST",
|
|
24
|
-
body:
|
|
24
|
+
body: d,
|
|
25
25
|
headers: { "Content-Type": "application/json" },
|
|
26
26
|
keepalive: !0
|
|
27
|
-
}).catch((
|
|
28
|
-
e && (console.error(`${
|
|
27
|
+
}).catch((c) => {
|
|
28
|
+
e && (console.error(`${l} Log upload failed:`, c), u.unshift(...s));
|
|
29
29
|
});
|
|
30
|
-
},
|
|
31
|
-
|
|
30
|
+
}, h = (e, ...l) => {
|
|
31
|
+
c && (u.push({
|
|
32
32
|
level: e,
|
|
33
33
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
34
|
-
message: formatArgs(
|
|
35
|
-
appId:
|
|
36
|
-
}),
|
|
34
|
+
message: formatArgs(l),
|
|
35
|
+
appId: s
|
|
36
|
+
}), u.length >= f && (d && clearTimeout(d), m(), d = window.setTimeout(m, p)));
|
|
37
37
|
};
|
|
38
|
-
return
|
|
39
|
-
log(...
|
|
40
|
-
e && console.log(
|
|
38
|
+
return c && (d = window.setTimeout(m, p)), {
|
|
39
|
+
log(...s) {
|
|
40
|
+
e && console.log(l, ...s), h("log", ...s);
|
|
41
41
|
},
|
|
42
|
-
error(...
|
|
43
|
-
e && console.error(
|
|
42
|
+
error(...s) {
|
|
43
|
+
e && console.error(l, ...s), h("error", ...s);
|
|
44
44
|
},
|
|
45
45
|
destroy() {
|
|
46
|
-
|
|
46
|
+
d && clearTimeout(d), m();
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
|
-
function createAuthManager(e,
|
|
51
|
-
let
|
|
50
|
+
function createAuthManager(e, s) {
|
|
51
|
+
let c = "";
|
|
52
52
|
return { async getToken() {
|
|
53
53
|
if (e.mode === "client") {
|
|
54
54
|
if (!e.token) throw Error("AuthManager: Missing token in client mode");
|
|
55
|
-
return
|
|
55
|
+
return c = e.token, c;
|
|
56
56
|
}
|
|
57
|
-
if (e.mode === "server") return
|
|
57
|
+
if (e.mode === "server") return c ||= await new Promise((e) => setTimeout(() => {
|
|
58
58
|
e("9269ca5c-5b35-46de-915f-b2e3ff41da13");
|
|
59
|
-
}, 1e3)),
|
|
59
|
+
}, 1e3)), c;
|
|
60
60
|
throw Error("AuthManager: Invalid configuration or missing token.");
|
|
61
61
|
} };
|
|
62
62
|
}
|
|
63
63
|
var createStoreImpl = (e) => {
|
|
64
|
-
let
|
|
65
|
-
let
|
|
66
|
-
if (!Object.is(
|
|
67
|
-
let e =
|
|
68
|
-
|
|
64
|
+
let s, c = /* @__PURE__ */ new Set(), l = (e, l) => {
|
|
65
|
+
let u = typeof e == "function" ? e(s) : e;
|
|
66
|
+
if (!Object.is(u, s)) {
|
|
67
|
+
let e = s;
|
|
68
|
+
s = l ?? (typeof u != "object" || !u) ? u : Object.assign({}, s, u), c.forEach((c) => c(s, e));
|
|
69
69
|
}
|
|
70
|
-
},
|
|
71
|
-
setState:
|
|
72
|
-
getState:
|
|
73
|
-
getInitialState: () =>
|
|
74
|
-
subscribe: (e) => (
|
|
75
|
-
},
|
|
76
|
-
return
|
|
70
|
+
}, u = () => s, d = {
|
|
71
|
+
setState: l,
|
|
72
|
+
getState: u,
|
|
73
|
+
getInitialState: () => f,
|
|
74
|
+
subscribe: (e) => (c.add(e), () => c.delete(e))
|
|
75
|
+
}, f = s = e(l, u, d);
|
|
76
|
+
return d;
|
|
77
77
|
};
|
|
78
78
|
const pilotStore = ((e) => e ? createStoreImpl(e) : createStoreImpl)((e) => ({
|
|
79
79
|
currentMessage: void 0,
|
|
80
80
|
isLoading: !1,
|
|
81
81
|
messageHistory: [],
|
|
82
82
|
activeScence: "ANC",
|
|
83
|
-
setActiveScence: (
|
|
84
|
-
updateMessage: (
|
|
85
|
-
let
|
|
86
|
-
...
|
|
83
|
+
setActiveScence: (s) => e({ activeScence: s }),
|
|
84
|
+
updateMessage: (s) => e((e) => {
|
|
85
|
+
let c = {
|
|
86
|
+
...s,
|
|
87
87
|
role: "ai",
|
|
88
88
|
showActions: !1,
|
|
89
89
|
maxWidth: "100%"
|
|
90
|
-
},
|
|
91
|
-
if (
|
|
90
|
+
}, l = [...e.messageHistory];
|
|
91
|
+
if (l.forEach((e) => {
|
|
92
92
|
e.isHistoryMessage = !0;
|
|
93
93
|
}), e.currentMessage) {
|
|
94
|
-
let
|
|
95
|
-
...
|
|
96
|
-
content: e.currentMessage.content + (
|
|
94
|
+
let u = {
|
|
95
|
+
...c,
|
|
96
|
+
content: e.currentMessage.content + (s.content || "")
|
|
97
97
|
};
|
|
98
|
-
return
|
|
99
|
-
currentMessage:
|
|
100
|
-
messageHistory:
|
|
98
|
+
return l.pop(), l.push(u), {
|
|
99
|
+
currentMessage: u,
|
|
100
|
+
messageHistory: l
|
|
101
101
|
};
|
|
102
102
|
}
|
|
103
|
-
return
|
|
104
|
-
currentMessage:
|
|
105
|
-
messageHistory:
|
|
103
|
+
return l.push(c), {
|
|
104
|
+
currentMessage: c,
|
|
105
|
+
messageHistory: l
|
|
106
106
|
};
|
|
107
107
|
}),
|
|
108
|
-
setLoading: (
|
|
108
|
+
setLoading: (s) => e({ isLoading: s }),
|
|
109
109
|
resetCurrentMessage: () => e({ currentMessage: void 0 }),
|
|
110
|
-
resetMessageHistory: (
|
|
111
|
-
updateMessageHistory: (
|
|
112
|
-
let
|
|
113
|
-
return
|
|
110
|
+
resetMessageHistory: (s) => e({ messageHistory: s || [] }),
|
|
111
|
+
updateMessageHistory: (s) => e((e) => {
|
|
112
|
+
let c = [...e.messageHistory];
|
|
113
|
+
return c.forEach((e) => {
|
|
114
114
|
e.isHistoryMessage = !0;
|
|
115
|
-
}), Array.isArray(
|
|
115
|
+
}), Array.isArray(s) ? { messageHistory: [...c, ...s] } : { messageHistory: [...c, s] };
|
|
116
116
|
})
|
|
117
117
|
}));
|
|
118
118
|
var MAX_RETRY_TIME = 0, EventStreamContentType = "text/event-stream", FatalError = class extends Error {
|
|
@@ -120,46 +120,46 @@ var MAX_RETRY_TIME = 0, EventStreamContentType = "text/event-stream", FatalError
|
|
|
120
120
|
super(e), this.name = "FatalError";
|
|
121
121
|
}
|
|
122
122
|
};
|
|
123
|
-
const sseRequester = function(e,
|
|
124
|
-
let { url:
|
|
125
|
-
function
|
|
126
|
-
|
|
123
|
+
const sseRequester = function(e, s) {
|
|
124
|
+
let { url: c, config: l = {} } = e, u = new AbortController();
|
|
125
|
+
function d() {
|
|
126
|
+
s.onCancel(pilotStore.getState().currentMessage, u), pilotStore.getState().setLoading(!1), pilotStore.getState().resetCurrentMessage();
|
|
127
127
|
}
|
|
128
|
-
function
|
|
129
|
-
let
|
|
130
|
-
|
|
131
|
-
taskId:
|
|
132
|
-
messageId:
|
|
133
|
-
conversationId:
|
|
128
|
+
function f(e) {
|
|
129
|
+
let c = s.onMessage(e);
|
|
130
|
+
c.event === "message" && pilotStore.getState().updateMessage({
|
|
131
|
+
taskId: c.task_id,
|
|
132
|
+
messageId: c.message_id,
|
|
133
|
+
conversationId: c.conversation_id,
|
|
134
134
|
role: "ai",
|
|
135
|
-
content:
|
|
135
|
+
content: c.answer
|
|
136
136
|
});
|
|
137
137
|
}
|
|
138
|
-
function
|
|
139
|
-
pilotStore.getState().setLoading(!0),
|
|
138
|
+
function p() {
|
|
139
|
+
pilotStore.getState().setLoading(!0), s.onOpen();
|
|
140
140
|
}
|
|
141
|
-
function
|
|
142
|
-
pilotStore.getState().setLoading(!1), pilotStore.getState().resetCurrentMessage(),
|
|
141
|
+
function h() {
|
|
142
|
+
pilotStore.getState().setLoading(!1), pilotStore.getState().resetCurrentMessage(), s.onClose();
|
|
143
143
|
}
|
|
144
|
-
let
|
|
145
|
-
return fetchEventSource(
|
|
146
|
-
...
|
|
147
|
-
signal:
|
|
144
|
+
let g = Math.max(MAX_RETRY_TIME - 1, 0);
|
|
145
|
+
return fetchEventSource(c, {
|
|
146
|
+
...l,
|
|
147
|
+
signal: u.signal,
|
|
148
148
|
openWhenHidden: !0,
|
|
149
|
-
onmessage:
|
|
150
|
-
onclose:
|
|
149
|
+
onmessage: f,
|
|
150
|
+
onclose: h,
|
|
151
151
|
onopen: async (e) => {
|
|
152
|
-
let
|
|
153
|
-
if (!
|
|
154
|
-
|
|
152
|
+
let s = e.headers.get("content-type");
|
|
153
|
+
if (!s || !s.includes(EventStreamContentType)) throw Error(`Expected content-type to be ${EventStreamContentType}, Actual: ${s}`);
|
|
154
|
+
p();
|
|
155
155
|
},
|
|
156
156
|
onerror: (e) => {
|
|
157
|
-
if (
|
|
158
|
-
|
|
157
|
+
if (g--, g < 0 && (h(), e instanceof TypeError)) throw new FatalError(e.message);
|
|
158
|
+
s.onError(e);
|
|
159
159
|
}
|
|
160
160
|
}).catch((e) => {
|
|
161
|
-
|
|
162
|
-
}), { cancel:
|
|
161
|
+
h(), s.onError(e);
|
|
162
|
+
}), { cancel: d };
|
|
163
163
|
}, CorePilotHost = /* @__PURE__ */ defineComponent({
|
|
164
164
|
props: {
|
|
165
165
|
adapter: {
|
|
@@ -180,59 +180,63 @@ const sseRequester = function(e, c) {
|
|
|
180
180
|
}
|
|
181
181
|
},
|
|
182
182
|
setup(e) {
|
|
183
|
-
let
|
|
184
|
-
let { isLoading:
|
|
185
|
-
l.value =
|
|
183
|
+
let s = ref([]), c = ref([]), f = ref(!1), p = ref(), m = ref("ANC"), h = ref(), g = pilotStore.subscribe((e) => {
|
|
184
|
+
let { isLoading: s, messageHistory: l } = e;
|
|
185
|
+
c.value = l, f.value = s, m.value = e.activeScence;
|
|
186
186
|
});
|
|
187
|
-
return watch(() =>
|
|
188
|
-
e && (
|
|
189
|
-
}), watch(() =>
|
|
190
|
-
c && e.hitlManager.submit({ hitlData: {
|
|
187
|
+
return watch(() => f.value, (e) => {
|
|
188
|
+
e && (h.value = void 0);
|
|
189
|
+
}), watch(() => h.value, (s, l) => {
|
|
190
|
+
s && c.value[c.value.length - 1]?.role === "ai" && e.hitlManager.submit({ hitlData: {
|
|
191
191
|
action: "cust_ai_output_finish",
|
|
192
192
|
payload: {
|
|
193
|
-
refConfig:
|
|
194
|
-
conversationId:
|
|
193
|
+
refConfig: h.value,
|
|
194
|
+
conversationId: c.value[c.value.length - 1]?.conversationId
|
|
195
195
|
}
|
|
196
196
|
} });
|
|
197
197
|
}), onBeforeUnmount(() => {
|
|
198
|
-
|
|
198
|
+
g?.();
|
|
199
199
|
}), {
|
|
200
|
-
messages:
|
|
201
|
-
isLoading:
|
|
202
|
-
handleSendMessage: async (
|
|
203
|
-
let
|
|
200
|
+
messages: c,
|
|
201
|
+
isLoading: f,
|
|
202
|
+
handleSendMessage: async (s) => {
|
|
203
|
+
let l = {
|
|
204
204
|
messageId: void 0,
|
|
205
|
-
content:
|
|
205
|
+
content: s.text,
|
|
206
206
|
role: "user",
|
|
207
207
|
placement: "end",
|
|
208
208
|
showActions: !1,
|
|
209
209
|
maxWidth: "100%"
|
|
210
|
-
},
|
|
211
|
-
pilotStore.getState().updateMessageHistory([
|
|
212
|
-
text:
|
|
213
|
-
prevMessage:
|
|
214
|
-
inputs: { scence:
|
|
210
|
+
}, u = c.value[c.value.length - 1];
|
|
211
|
+
pilotStore.getState().updateMessageHistory([l]), pilotStore.getState().resetCurrentMessage(), p.value = sseRequester(await e.adapter.formatReuqest({
|
|
212
|
+
text: s.text,
|
|
213
|
+
prevMessage: u,
|
|
214
|
+
inputs: { scence: m.value }
|
|
215
215
|
}), e.adapter).cancel;
|
|
216
216
|
},
|
|
217
217
|
cancelHandler: () => {
|
|
218
|
-
e.logger.log("Cancel handler called"),
|
|
218
|
+
e.logger.log("Cancel handler called"), p.value?.(), pilotStore.getState().resetCurrentMessage();
|
|
219
219
|
},
|
|
220
|
-
handleScenceChange: (
|
|
221
|
-
|
|
220
|
+
handleScenceChange: (s) => {
|
|
221
|
+
e.hitlManager.submit({ hitlData: {
|
|
222
222
|
action: "cust_scence_change",
|
|
223
|
-
payload: { scence:
|
|
223
|
+
payload: { scence: s.id }
|
|
224
224
|
} });
|
|
225
225
|
},
|
|
226
|
-
tagList:
|
|
227
|
-
coreSubmit: async (
|
|
226
|
+
tagList: s,
|
|
227
|
+
coreSubmit: async (s, c) => {
|
|
228
228
|
pilotStore.getState().resetCurrentMessage(), await e.hitlManager.submit({
|
|
229
|
-
hitlData:
|
|
230
|
-
prevMessage:
|
|
231
|
-
inputs: { scence:
|
|
229
|
+
hitlData: s,
|
|
230
|
+
prevMessage: c,
|
|
231
|
+
inputs: { scence: m.value }
|
|
232
232
|
});
|
|
233
233
|
},
|
|
234
234
|
handleRefConfigUpdate: (e) => {
|
|
235
|
-
|
|
235
|
+
h.value = e;
|
|
236
|
+
},
|
|
237
|
+
activeScence: m,
|
|
238
|
+
handleSceneUpdate: (e) => {
|
|
239
|
+
pilotStore.getState().setActiveScence(e);
|
|
236
240
|
}
|
|
237
241
|
};
|
|
238
242
|
},
|
|
@@ -245,46 +249,47 @@ const sseRequester = function(e, c) {
|
|
|
245
249
|
onCoreSubmit: this.coreSubmit,
|
|
246
250
|
onRefConfigUpdate: this.handleRefConfigUpdate
|
|
247
251
|
}, null), createVNode(EditorSender, {
|
|
248
|
-
sceneList: [],
|
|
249
252
|
tagList: this.tagList,
|
|
250
253
|
loading: this.isLoading,
|
|
251
254
|
agentName: "",
|
|
255
|
+
scene: this.activeScence,
|
|
252
256
|
onSubmit: this.handleSendMessage,
|
|
253
257
|
onCancel: this.cancelHandler,
|
|
254
|
-
onSceneChange: this.handleScenceChange
|
|
258
|
+
onSceneChange: this.handleScenceChange,
|
|
259
|
+
"onUpdate:scene": this.handleSceneUpdate
|
|
255
260
|
}, null)]);
|
|
256
261
|
}
|
|
257
262
|
});
|
|
258
|
-
function createMountManager(c, l, u, d
|
|
259
|
-
let
|
|
260
|
-
let e = (
|
|
263
|
+
function createMountManager(s, c, l, u, d) {
|
|
264
|
+
let f = null, p = null, m = () => {
|
|
265
|
+
let e = (s.container || document).querySelector(s.selector);
|
|
261
266
|
if (e && !e.querySelector("[data-corepilot-host]")) {
|
|
262
|
-
let
|
|
263
|
-
return
|
|
267
|
+
let s = document.createElement("div");
|
|
268
|
+
return s.setAttribute("data-corepilot-host", "true"), s.style.width = "100%", s.style.height = "100%", e.appendChild(s), s;
|
|
264
269
|
}
|
|
265
270
|
return e?.querySelector("[data-corepilot-host]");
|
|
266
271
|
};
|
|
267
272
|
return {
|
|
268
273
|
mount() {
|
|
269
|
-
if (
|
|
270
|
-
|
|
274
|
+
if (p = m(), !p) {
|
|
275
|
+
u.error(`Mount point "${s.selector}" not found or already in use.`);
|
|
271
276
|
return;
|
|
272
277
|
}
|
|
273
|
-
|
|
274
|
-
adapter:
|
|
275
|
-
hitlManager:
|
|
276
|
-
logger:
|
|
277
|
-
provider:
|
|
278
|
-
}),
|
|
278
|
+
f && (u.log("An app instance already exists. Unmounting first."), this.unmount()), f = createApp(CorePilotHost, {
|
|
279
|
+
adapter: c,
|
|
280
|
+
hitlManager: l,
|
|
281
|
+
logger: u,
|
|
282
|
+
provider: d
|
|
283
|
+
}), f.mount(p), u.log("Vue CorePilotHost mounted.");
|
|
279
284
|
},
|
|
280
285
|
unmount() {
|
|
281
|
-
|
|
286
|
+
f && (f.unmount(), f = null, u.log("Vue CorePilotHost unmounted.")), p && p.parentElement && (p.parentElement.innerHTML = "");
|
|
282
287
|
}
|
|
283
288
|
};
|
|
284
289
|
}
|
|
285
290
|
var HttpError = class extends Error {
|
|
286
|
-
constructor(e, c, l
|
|
287
|
-
super(e), this.name = "HttpError", this.code =
|
|
291
|
+
constructor(e, s, c, l) {
|
|
292
|
+
super(e), this.name = "HttpError", this.code = s, this.data = c, this.originalError = l;
|
|
288
293
|
}
|
|
289
294
|
}, axios_default = new class {
|
|
290
295
|
constructor(e) {
|
|
@@ -299,72 +304,72 @@ var HttpError = class extends Error {
|
|
|
299
304
|
this.instance.interceptors.response.use((e) => e.data, (e) => Promise.reject(this.handleError(e)));
|
|
300
305
|
}
|
|
301
306
|
handleError(e) {
|
|
302
|
-
let
|
|
303
|
-
if (axios.isAxiosError(e)) if (e.response) switch (
|
|
307
|
+
let s = "请求失败,请稍后重试", c = -1, l = null;
|
|
308
|
+
if (axios.isAxiosError(e)) if (e.response) switch (c = e.response.status, l = e.response.data, c) {
|
|
304
309
|
case 400:
|
|
305
|
-
|
|
310
|
+
s = "请求参数错误";
|
|
306
311
|
break;
|
|
307
312
|
case 401:
|
|
308
|
-
|
|
313
|
+
s = "未授权,请重新登录";
|
|
309
314
|
break;
|
|
310
315
|
case 403:
|
|
311
|
-
|
|
316
|
+
s = "拒绝访问";
|
|
312
317
|
break;
|
|
313
318
|
case 404:
|
|
314
|
-
|
|
319
|
+
s = "请求资源不存在";
|
|
315
320
|
break;
|
|
316
321
|
case 405:
|
|
317
|
-
|
|
322
|
+
s = "请求方法不允许";
|
|
318
323
|
break;
|
|
319
324
|
case 408:
|
|
320
|
-
|
|
325
|
+
s = "请求超时";
|
|
321
326
|
break;
|
|
322
327
|
case 500:
|
|
323
|
-
|
|
328
|
+
s = "服务器内部错误";
|
|
324
329
|
break;
|
|
325
330
|
case 501:
|
|
326
|
-
|
|
331
|
+
s = "服务未实现";
|
|
327
332
|
break;
|
|
328
333
|
case 502:
|
|
329
|
-
|
|
334
|
+
s = "网关错误";
|
|
330
335
|
break;
|
|
331
336
|
case 503:
|
|
332
|
-
|
|
337
|
+
s = "服务不可用";
|
|
333
338
|
break;
|
|
334
339
|
case 504:
|
|
335
|
-
|
|
340
|
+
s = "网关超时";
|
|
336
341
|
break;
|
|
337
|
-
default:
|
|
342
|
+
default: s = e.response.statusText || `连接错误 ${c}`;
|
|
338
343
|
}
|
|
339
|
-
else e.request ? (
|
|
340
|
-
else
|
|
341
|
-
return console.error(`[HttpClient] Error: ${
|
|
342
|
-
code:
|
|
343
|
-
data:
|
|
344
|
+
else e.request ? (s = "网络连接失败,请检查网络设置", c = 0) : s = e.message;
|
|
345
|
+
else s = e.message || "未知错误";
|
|
346
|
+
return console.error(`[HttpClient] Error: ${s}`, {
|
|
347
|
+
code: c,
|
|
348
|
+
data: l,
|
|
344
349
|
original: e
|
|
345
|
-
}), new HttpError(c, l,
|
|
350
|
+
}), new HttpError(s, c, l, e);
|
|
346
351
|
}
|
|
347
|
-
get(e,
|
|
348
|
-
return this.instance.get(e,
|
|
352
|
+
get(e, s) {
|
|
353
|
+
return this.instance.get(e, s);
|
|
349
354
|
}
|
|
350
|
-
post(e,
|
|
351
|
-
return this.instance.post(e,
|
|
355
|
+
post(e, s, c) {
|
|
356
|
+
return this.instance.post(e, s, c);
|
|
352
357
|
}
|
|
353
|
-
put(e,
|
|
354
|
-
return this.instance.put(e,
|
|
358
|
+
put(e, s, c) {
|
|
359
|
+
return this.instance.put(e, s, c);
|
|
355
360
|
}
|
|
356
|
-
delete(e,
|
|
357
|
-
return this.instance.delete(e,
|
|
361
|
+
delete(e, s) {
|
|
362
|
+
return this.instance.delete(e, s);
|
|
358
363
|
}
|
|
359
|
-
patch(e,
|
|
360
|
-
return this.instance.patch(e,
|
|
364
|
+
patch(e, s, c) {
|
|
365
|
+
return this.instance.patch(e, s, c);
|
|
361
366
|
}
|
|
362
|
-
upload(e,
|
|
363
|
-
let
|
|
364
|
-
return
|
|
365
|
-
...
|
|
367
|
+
upload(e, s, c = "file", l) {
|
|
368
|
+
let u = new FormData();
|
|
369
|
+
return u.append(c, s), this.instance.post(e, u, {
|
|
370
|
+
...l,
|
|
366
371
|
headers: {
|
|
367
|
-
...
|
|
372
|
+
...l?.headers,
|
|
368
373
|
"Content-Type": "multipart/form-data"
|
|
369
374
|
}
|
|
370
375
|
});
|
|
@@ -373,78 +378,84 @@ var HttpError = class extends Error {
|
|
|
373
378
|
return this.instance;
|
|
374
379
|
}
|
|
375
380
|
}({});
|
|
376
|
-
function createCoreAgentAdapter(e,
|
|
377
|
-
let { appId:
|
|
378
|
-
let
|
|
379
|
-
return await axios_default.post(`/openapi/v1/app/chat-messages/${
|
|
380
|
-
Authorization: `Bearer ${f}`,
|
|
381
|
-
appId: u
|
|
382
|
-
} }), Promise.resolve();
|
|
383
|
-
}, h = async (e) => {
|
|
384
|
-
let l = e.messageId, d = await c.getToken(), f = await axios_default.post(`/openapi/v1/app/chat-messages/${l}/suggested`, { user: p }, { headers: {
|
|
381
|
+
function createCoreAgentAdapter(e, s, c) {
|
|
382
|
+
let { appId: l, provider: u } = e, { extensions: d } = u, { user: f = "default" } = d || {}, p = async (e, c) => {
|
|
383
|
+
let u = e.taskId, d = await s.getToken();
|
|
384
|
+
return await axios_default.post(`/openapi/v1/app/chat-messages/${u}/stop`, { user: f }, { headers: {
|
|
385
385
|
Authorization: `Bearer ${d}`,
|
|
386
|
-
appId:
|
|
386
|
+
appId: l
|
|
387
|
+
} }), Promise.resolve();
|
|
388
|
+
}, m = async (e) => {
|
|
389
|
+
let c = e.messageId, u = await s.getToken(), d = await axios_default.post(`/openapi/v1/app/chat-messages/${c}/suggested`, { user: f }, { headers: {
|
|
390
|
+
Authorization: `Bearer ${u}`,
|
|
391
|
+
appId: l
|
|
387
392
|
} });
|
|
388
|
-
return
|
|
389
|
-
},
|
|
390
|
-
let
|
|
393
|
+
return d.result === "success" ? d.data : [];
|
|
394
|
+
}, h = async (e) => {
|
|
395
|
+
let c = await s.getToken();
|
|
391
396
|
return await axios_default.get(`/openapi/v1/app/conversations?${new URLSearchParams(e).toString()}`, { headers: {
|
|
392
|
-
Authorization: `Bearer ${
|
|
393
|
-
appId:
|
|
397
|
+
Authorization: `Bearer ${c}`,
|
|
398
|
+
appId: l
|
|
394
399
|
} });
|
|
395
|
-
},
|
|
396
|
-
let
|
|
400
|
+
}, g = async (e) => {
|
|
401
|
+
let c = await s.getToken();
|
|
397
402
|
return await axios_default.get(`/openapi/v1/app/messages?${new URLSearchParams(e).toString()}`, { headers: {
|
|
398
|
-
Authorization: `Bearer ${
|
|
399
|
-
appId:
|
|
403
|
+
Authorization: `Bearer ${c}`,
|
|
404
|
+
appId: l
|
|
400
405
|
} });
|
|
401
|
-
},
|
|
402
|
-
let { hitlData:
|
|
403
|
-
query:
|
|
404
|
-
inputs:
|
|
406
|
+
}, _ = async (e) => {
|
|
407
|
+
let { hitlData: c, prevMessage: u, text: d, inputs: p } = e, m = {
|
|
408
|
+
query: d || JSON.stringify(c || {}),
|
|
409
|
+
inputs: p || {},
|
|
405
410
|
response_mode: "streaming",
|
|
406
|
-
conversation_id:
|
|
407
|
-
parent_message_id:
|
|
408
|
-
user:
|
|
411
|
+
conversation_id: u?.conversationId || null,
|
|
412
|
+
parent_message_id: u?.messageId || null,
|
|
413
|
+
user: f,
|
|
409
414
|
files: []
|
|
410
|
-
},
|
|
415
|
+
}, h = await s.getToken();
|
|
411
416
|
return {
|
|
412
417
|
url: "/openapi/v1/app/chat-messages",
|
|
413
418
|
config: {
|
|
414
419
|
method: "POST",
|
|
415
420
|
headers: {
|
|
416
421
|
"Content-Type": "application/json",
|
|
417
|
-
Authorization: `Bearer ${
|
|
418
|
-
appId:
|
|
422
|
+
Authorization: `Bearer ${h}`,
|
|
423
|
+
appId: l
|
|
419
424
|
},
|
|
420
|
-
body: JSON.stringify(
|
|
425
|
+
body: JSON.stringify(m)
|
|
421
426
|
}
|
|
422
427
|
};
|
|
423
|
-
},
|
|
424
|
-
let { data:
|
|
425
|
-
return JSON.parse(
|
|
426
|
-
},
|
|
427
|
-
|
|
428
|
-
},
|
|
429
|
-
|
|
430
|
-
},
|
|
431
|
-
|
|
428
|
+
}, v = (e) => {
|
|
429
|
+
let { data: s } = e;
|
|
430
|
+
return JSON.parse(s || "{}");
|
|
431
|
+
}, y = async () => {
|
|
432
|
+
c.log("onClose");
|
|
433
|
+
}, b = async (e) => {
|
|
434
|
+
c.log("onError", e);
|
|
435
|
+
}, x = async () => {
|
|
436
|
+
c.log("onOpen");
|
|
437
|
+
}, S = (e) => {
|
|
438
|
+
try {
|
|
439
|
+
return JSON.parse(e || "{}")?.action?.startsWith("core_") || !1;
|
|
440
|
+
} catch {
|
|
441
|
+
return !1;
|
|
442
|
+
}
|
|
432
443
|
}, C = async (e) => {
|
|
433
|
-
sseRequester(await
|
|
434
|
-
formatReuqest:
|
|
435
|
-
getSuggestionQuestions:
|
|
436
|
-
getConversationList:
|
|
437
|
-
getMessageHistory:
|
|
438
|
-
onMessage:
|
|
439
|
-
onClose:
|
|
440
|
-
onError:
|
|
441
|
-
onOpen:
|
|
442
|
-
onCancel:
|
|
444
|
+
sseRequester(await _(e), {
|
|
445
|
+
formatReuqest: _,
|
|
446
|
+
getSuggestionQuestions: m,
|
|
447
|
+
getConversationList: h,
|
|
448
|
+
getMessageHistory: g,
|
|
449
|
+
onMessage: v,
|
|
450
|
+
onClose: y,
|
|
451
|
+
onError: b,
|
|
452
|
+
onOpen: x,
|
|
453
|
+
onCancel: p
|
|
443
454
|
});
|
|
444
455
|
}, w = async (e) => {
|
|
445
|
-
let
|
|
456
|
+
let s = [], c;
|
|
446
457
|
if (e.data.forEach((e) => {
|
|
447
|
-
e.parent_message_id ===
|
|
458
|
+
if (e.parent_message_id === c) s.pop(), s.push({
|
|
448
459
|
role: "ai",
|
|
449
460
|
showActions: !1,
|
|
450
461
|
content: e.answer,
|
|
@@ -455,48 +466,52 @@ function createCoreAgentAdapter(e, c, l) {
|
|
|
455
466
|
name: e.filename
|
|
456
467
|
})),
|
|
457
468
|
placement: "start"
|
|
458
|
-
})
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
469
|
+
});
|
|
470
|
+
else {
|
|
471
|
+
if (c = e.parent_message_id, !S(e.query)) s.push({
|
|
472
|
+
role: "user",
|
|
473
|
+
messageId: e.id,
|
|
474
|
+
content: e.query,
|
|
475
|
+
showActions: !1,
|
|
476
|
+
maxWidth: "100%",
|
|
477
|
+
placement: "end",
|
|
478
|
+
isHistoryMessage: !0
|
|
479
|
+
});
|
|
480
|
+
else {
|
|
481
|
+
let c = JSON.parse(e.query || "{}");
|
|
482
|
+
if (c?.payload) {
|
|
483
|
+
let e = s[s.length - 1];
|
|
484
|
+
e && (e.historyInputs = c.payload);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
s.push({
|
|
488
|
+
role: "ai",
|
|
489
|
+
content: e.answer,
|
|
490
|
+
showActions: !1,
|
|
491
|
+
maxWidth: "100%",
|
|
492
|
+
placement: "start",
|
|
493
|
+
files: e.message_files.map((e) => ({
|
|
494
|
+
id: e.id,
|
|
495
|
+
extension: e.type,
|
|
496
|
+
name: e.filename
|
|
497
|
+
})),
|
|
498
|
+
isHistoryMessage: !0
|
|
499
|
+
});
|
|
500
|
+
}
|
|
479
501
|
}), e.has_more) {
|
|
480
|
-
let e = await
|
|
481
|
-
conversation_id:
|
|
482
|
-
user:
|
|
483
|
-
first_id:
|
|
502
|
+
let e = await g({
|
|
503
|
+
conversation_id: s[s.length - 1].conversationId,
|
|
504
|
+
user: f,
|
|
505
|
+
first_id: s[0].messageId
|
|
484
506
|
});
|
|
485
507
|
if (e.data) {
|
|
486
|
-
let
|
|
487
|
-
|
|
508
|
+
let c = await w(e);
|
|
509
|
+
s.unshift(...c);
|
|
488
510
|
}
|
|
489
511
|
}
|
|
490
|
-
return
|
|
491
|
-
}, T = async () => (pilotStore.getState().resetMessageHistory(
|
|
492
|
-
|
|
493
|
-
content: "你好,我是智能小助手,可以帮助您:\n 1、查找页面并实现跳转\n 2、查询系统内的数据并以表格或图表方式展示\n\n 您可以对我说:\n 1、打开用户管理页面\n 2、查询在线用户数据",
|
|
494
|
-
showActions: !1,
|
|
495
|
-
maxWidth: "100%",
|
|
496
|
-
placement: "start",
|
|
497
|
-
isHistoryMessage: !0
|
|
498
|
-
}]), !0), E = async (e) => {
|
|
499
|
-
let c = {
|
|
512
|
+
return s;
|
|
513
|
+
}, T = async () => (pilotStore.getState().resetMessageHistory(), !0), E = async (e) => {
|
|
514
|
+
let s = {
|
|
500
515
|
messageId: void 0,
|
|
501
516
|
content: e.text,
|
|
502
517
|
role: "user",
|
|
@@ -504,41 +519,41 @@ function createCoreAgentAdapter(e, c, l) {
|
|
|
504
519
|
showActions: !1,
|
|
505
520
|
maxWidth: "100%"
|
|
506
521
|
};
|
|
507
|
-
pilotStore.getState().updateMessageHistory([
|
|
508
|
-
let
|
|
522
|
+
pilotStore.getState().updateMessageHistory([s]), pilotStore.getState().resetCurrentMessage();
|
|
523
|
+
let c = await _({
|
|
509
524
|
text: e.text,
|
|
510
525
|
prevMessage: void 0,
|
|
511
526
|
inputs: e.inputs
|
|
512
527
|
});
|
|
513
|
-
return pilotStore.getState().setActiveScence(e.inputs?.scence), sseRequester(
|
|
514
|
-
formatReuqest:
|
|
515
|
-
getSuggestionQuestions:
|
|
516
|
-
getConversationList:
|
|
517
|
-
getMessageHistory:
|
|
518
|
-
onMessage:
|
|
519
|
-
onClose:
|
|
520
|
-
onError:
|
|
521
|
-
onOpen:
|
|
522
|
-
onCancel:
|
|
528
|
+
return pilotStore.getState().setActiveScence(e.inputs?.scence), sseRequester(c, {
|
|
529
|
+
formatReuqest: _,
|
|
530
|
+
getSuggestionQuestions: m,
|
|
531
|
+
getConversationList: h,
|
|
532
|
+
getMessageHistory: g,
|
|
533
|
+
onMessage: v,
|
|
534
|
+
onClose: y,
|
|
535
|
+
onError: b,
|
|
536
|
+
onOpen: x,
|
|
537
|
+
onCancel: p
|
|
523
538
|
});
|
|
524
539
|
};
|
|
525
540
|
return {
|
|
526
|
-
formatReuqest:
|
|
527
|
-
getSuggestionQuestions:
|
|
528
|
-
getConversationList:
|
|
529
|
-
getMessageHistory:
|
|
530
|
-
onMessage:
|
|
531
|
-
onClose:
|
|
532
|
-
onError:
|
|
533
|
-
onOpen:
|
|
534
|
-
onCancel:
|
|
541
|
+
formatReuqest: _,
|
|
542
|
+
getSuggestionQuestions: m,
|
|
543
|
+
getConversationList: h,
|
|
544
|
+
getMessageHistory: g,
|
|
545
|
+
onMessage: v,
|
|
546
|
+
onClose: y,
|
|
547
|
+
onError: b,
|
|
548
|
+
onOpen: x,
|
|
549
|
+
onCancel: p,
|
|
535
550
|
triggerEvent: async (e) => {
|
|
536
551
|
switch (e.action) {
|
|
537
|
-
case "get_suggestion_questions": return await
|
|
538
|
-
case "get_conversation_list": return await
|
|
552
|
+
case "get_suggestion_questions": return await m(e.payload);
|
|
553
|
+
case "get_conversation_list": return await h(e.payload);
|
|
539
554
|
case "get_message_history":
|
|
540
|
-
let
|
|
541
|
-
return pilotStore.getState().resetMessageHistory(
|
|
555
|
+
let s = await w(await g(e.payload));
|
|
556
|
+
return pilotStore.getState().resetMessageHistory(s), s;
|
|
542
557
|
case "submit_core_action": return await C(e.payload);
|
|
543
558
|
case "new_message": return await T();
|
|
544
559
|
case "submit_message": return await E(e.payload);
|
|
@@ -547,82 +562,82 @@ function createCoreAgentAdapter(e, c, l) {
|
|
|
547
562
|
}
|
|
548
563
|
};
|
|
549
564
|
}
|
|
550
|
-
function createProtocolAdapter(e, c, l
|
|
551
|
-
switch (
|
|
552
|
-
case "coreagent": return createCoreAgentAdapter(e,
|
|
553
|
-
default: throw Error(`Unsupported provider: ${
|
|
565
|
+
function createProtocolAdapter(e, s, c, l) {
|
|
566
|
+
switch (l.log(`Creating adapter for provider: ${s}`), s.name) {
|
|
567
|
+
case "coreagent": return createCoreAgentAdapter(e, c, l);
|
|
568
|
+
default: throw Error(`Unsupported provider: ${s.name}`);
|
|
554
569
|
}
|
|
555
570
|
}
|
|
556
|
-
function createHitlManager(e,
|
|
557
|
-
let
|
|
558
|
-
let
|
|
571
|
+
function createHitlManager(e, s, c) {
|
|
572
|
+
let l = (e) => e.split("_")[0], u = [], d = async (s) => {
|
|
573
|
+
let l = await e.formatReuqest(s);
|
|
559
574
|
sseRequester({
|
|
560
|
-
url:
|
|
561
|
-
config:
|
|
562
|
-
}, e),
|
|
563
|
-
},
|
|
564
|
-
|
|
565
|
-
},
|
|
575
|
+
url: l.url,
|
|
576
|
+
config: l.config
|
|
577
|
+
}, e), c.log("HITL data submitted successfully.");
|
|
578
|
+
}, f = async (e) => {
|
|
579
|
+
u.forEach((s) => s(e.hitlData));
|
|
580
|
+
}, p = async (e) => {};
|
|
566
581
|
return {
|
|
567
582
|
async submit(e) {
|
|
568
583
|
try {
|
|
569
|
-
let
|
|
570
|
-
switch (
|
|
584
|
+
let s = l(e.hitlData?.action ?? "");
|
|
585
|
+
switch (c.log("[HITL] Submitting HITL data...", e), s) {
|
|
571
586
|
case "core":
|
|
572
|
-
await
|
|
587
|
+
await d(e);
|
|
573
588
|
break;
|
|
574
589
|
case "cust":
|
|
575
|
-
await
|
|
590
|
+
await f(e);
|
|
576
591
|
break;
|
|
577
592
|
case "inner":
|
|
578
|
-
await
|
|
593
|
+
await p(e);
|
|
579
594
|
break;
|
|
580
595
|
default: throw Error("Invalid action type.");
|
|
581
596
|
}
|
|
582
597
|
} catch (e) {
|
|
583
|
-
throw
|
|
598
|
+
throw c.error("Error submitting HITL data:", e), e;
|
|
584
599
|
}
|
|
585
600
|
},
|
|
586
601
|
subscribeEvent(e) {
|
|
587
|
-
|
|
602
|
+
u.includes(e) || u.push(e);
|
|
588
603
|
},
|
|
589
604
|
unsubscribeEvent(e) {
|
|
590
|
-
|
|
605
|
+
u.splice(u.indexOf(e), 1);
|
|
591
606
|
}
|
|
592
607
|
};
|
|
593
608
|
}
|
|
594
609
|
function createCorePilot(e) {
|
|
595
610
|
if (!e.appId) throw Error("CorePilot SDK: `appId` is required.");
|
|
596
611
|
if (!e.mount.selector) throw Error("CorePilot SDK: `mount.selector` is required.");
|
|
597
|
-
let
|
|
598
|
-
|
|
599
|
-
let
|
|
612
|
+
let s = createLogger(e.debug ?? !1, e.appId, e.eventTracker);
|
|
613
|
+
s.log("CorePilot SDK Initializing...", e);
|
|
614
|
+
let c = { ...e }, l = createAuthManager(c.auth, c.baseUrl), u = createProtocolAdapter(c, c.provider, l, s), d = createHitlManager(u, l, s), f = createMountManager(c.mount, u, d, s, c.provider);
|
|
600
615
|
return {
|
|
601
616
|
mount() {
|
|
602
|
-
|
|
617
|
+
s.log("Mounting CorePilot UI..."), f.mount();
|
|
603
618
|
},
|
|
604
619
|
unmount() {
|
|
605
|
-
|
|
620
|
+
s.log("Unmounting CorePilot UI..."), f.unmount();
|
|
606
621
|
},
|
|
607
622
|
reload(e) {
|
|
608
|
-
|
|
609
|
-
...
|
|
623
|
+
s.log("Reloading CorePilot instance...", e), f.unmount(), c = {
|
|
624
|
+
...c,
|
|
610
625
|
...e
|
|
611
|
-
},
|
|
612
|
-
let
|
|
613
|
-
|
|
626
|
+
}, u = createProtocolAdapter(c, c.provider, l, s);
|
|
627
|
+
let p = createMountManager(c.mount, u, d, s, c.provider);
|
|
628
|
+
f.mount = p.mount, f.unmount = p.unmount, s.log("CorePilot reloaded. Remounting UI..."), f.mount();
|
|
614
629
|
},
|
|
615
630
|
destroy() {
|
|
616
|
-
|
|
631
|
+
s.log("Destroying CorePilot instance..."), f.unmount(), s.destroy();
|
|
617
632
|
},
|
|
618
633
|
async triggerEvent(e) {
|
|
619
|
-
return await
|
|
634
|
+
return await u.triggerEvent(e);
|
|
620
635
|
},
|
|
621
636
|
subscribeEvent(e) {
|
|
622
|
-
|
|
637
|
+
d.subscribeEvent(e);
|
|
623
638
|
},
|
|
624
639
|
unsubscribeEvent(e) {
|
|
625
|
-
|
|
640
|
+
d.unsubscribeEvent(e);
|
|
626
641
|
}
|
|
627
642
|
};
|
|
628
643
|
}
|