@core-pilot/sdk 0.0.0-beta.6 → 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 +332 -309
- package/dist/index.umd.cjs +1 -1
- 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
|
-
|
|
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
|
},
|
|
@@ -248,42 +252,44 @@ const sseRequester = function(e, c) {
|
|
|
248
252
|
tagList: this.tagList,
|
|
249
253
|
loading: this.isLoading,
|
|
250
254
|
agentName: "",
|
|
255
|
+
scene: this.activeScence,
|
|
251
256
|
onSubmit: this.handleSendMessage,
|
|
252
257
|
onCancel: this.cancelHandler,
|
|
253
|
-
onSceneChange: this.handleScenceChange
|
|
258
|
+
onSceneChange: this.handleScenceChange,
|
|
259
|
+
"onUpdate:scene": this.handleSceneUpdate
|
|
254
260
|
}, null)]);
|
|
255
261
|
}
|
|
256
262
|
});
|
|
257
|
-
function createMountManager(c, l, u, d
|
|
258
|
-
let
|
|
259
|
-
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);
|
|
260
266
|
if (e && !e.querySelector("[data-corepilot-host]")) {
|
|
261
|
-
let
|
|
262
|
-
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;
|
|
263
269
|
}
|
|
264
270
|
return e?.querySelector("[data-corepilot-host]");
|
|
265
271
|
};
|
|
266
272
|
return {
|
|
267
273
|
mount() {
|
|
268
|
-
if (
|
|
269
|
-
|
|
274
|
+
if (p = m(), !p) {
|
|
275
|
+
u.error(`Mount point "${s.selector}" not found or already in use.`);
|
|
270
276
|
return;
|
|
271
277
|
}
|
|
272
|
-
|
|
273
|
-
adapter:
|
|
274
|
-
hitlManager:
|
|
275
|
-
logger:
|
|
276
|
-
provider:
|
|
277
|
-
}),
|
|
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.");
|
|
278
284
|
},
|
|
279
285
|
unmount() {
|
|
280
|
-
|
|
286
|
+
f && (f.unmount(), f = null, u.log("Vue CorePilotHost unmounted.")), p && p.parentElement && (p.parentElement.innerHTML = "");
|
|
281
287
|
}
|
|
282
288
|
};
|
|
283
289
|
}
|
|
284
290
|
var HttpError = class extends Error {
|
|
285
|
-
constructor(e, c, l
|
|
286
|
-
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;
|
|
287
293
|
}
|
|
288
294
|
}, axios_default = new class {
|
|
289
295
|
constructor(e) {
|
|
@@ -298,72 +304,72 @@ var HttpError = class extends Error {
|
|
|
298
304
|
this.instance.interceptors.response.use((e) => e.data, (e) => Promise.reject(this.handleError(e)));
|
|
299
305
|
}
|
|
300
306
|
handleError(e) {
|
|
301
|
-
let
|
|
302
|
-
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) {
|
|
303
309
|
case 400:
|
|
304
|
-
|
|
310
|
+
s = "请求参数错误";
|
|
305
311
|
break;
|
|
306
312
|
case 401:
|
|
307
|
-
|
|
313
|
+
s = "未授权,请重新登录";
|
|
308
314
|
break;
|
|
309
315
|
case 403:
|
|
310
|
-
|
|
316
|
+
s = "拒绝访问";
|
|
311
317
|
break;
|
|
312
318
|
case 404:
|
|
313
|
-
|
|
319
|
+
s = "请求资源不存在";
|
|
314
320
|
break;
|
|
315
321
|
case 405:
|
|
316
|
-
|
|
322
|
+
s = "请求方法不允许";
|
|
317
323
|
break;
|
|
318
324
|
case 408:
|
|
319
|
-
|
|
325
|
+
s = "请求超时";
|
|
320
326
|
break;
|
|
321
327
|
case 500:
|
|
322
|
-
|
|
328
|
+
s = "服务器内部错误";
|
|
323
329
|
break;
|
|
324
330
|
case 501:
|
|
325
|
-
|
|
331
|
+
s = "服务未实现";
|
|
326
332
|
break;
|
|
327
333
|
case 502:
|
|
328
|
-
|
|
334
|
+
s = "网关错误";
|
|
329
335
|
break;
|
|
330
336
|
case 503:
|
|
331
|
-
|
|
337
|
+
s = "服务不可用";
|
|
332
338
|
break;
|
|
333
339
|
case 504:
|
|
334
|
-
|
|
340
|
+
s = "网关超时";
|
|
335
341
|
break;
|
|
336
|
-
default:
|
|
342
|
+
default: s = e.response.statusText || `连接错误 ${c}`;
|
|
337
343
|
}
|
|
338
|
-
else e.request ? (
|
|
339
|
-
else
|
|
340
|
-
return console.error(`[HttpClient] Error: ${
|
|
341
|
-
code:
|
|
342
|
-
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,
|
|
343
349
|
original: e
|
|
344
|
-
}), new HttpError(c, l,
|
|
350
|
+
}), new HttpError(s, c, l, e);
|
|
345
351
|
}
|
|
346
|
-
get(e,
|
|
347
|
-
return this.instance.get(e,
|
|
352
|
+
get(e, s) {
|
|
353
|
+
return this.instance.get(e, s);
|
|
348
354
|
}
|
|
349
|
-
post(e,
|
|
350
|
-
return this.instance.post(e,
|
|
355
|
+
post(e, s, c) {
|
|
356
|
+
return this.instance.post(e, s, c);
|
|
351
357
|
}
|
|
352
|
-
put(e,
|
|
353
|
-
return this.instance.put(e,
|
|
358
|
+
put(e, s, c) {
|
|
359
|
+
return this.instance.put(e, s, c);
|
|
354
360
|
}
|
|
355
|
-
delete(e,
|
|
356
|
-
return this.instance.delete(e,
|
|
361
|
+
delete(e, s) {
|
|
362
|
+
return this.instance.delete(e, s);
|
|
357
363
|
}
|
|
358
|
-
patch(e,
|
|
359
|
-
return this.instance.patch(e,
|
|
364
|
+
patch(e, s, c) {
|
|
365
|
+
return this.instance.patch(e, s, c);
|
|
360
366
|
}
|
|
361
|
-
upload(e,
|
|
362
|
-
let
|
|
363
|
-
return
|
|
364
|
-
...
|
|
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,
|
|
365
371
|
headers: {
|
|
366
|
-
...
|
|
372
|
+
...l?.headers,
|
|
367
373
|
"Content-Type": "multipart/form-data"
|
|
368
374
|
}
|
|
369
375
|
});
|
|
@@ -372,78 +378,84 @@ var HttpError = class extends Error {
|
|
|
372
378
|
return this.instance;
|
|
373
379
|
}
|
|
374
380
|
}({});
|
|
375
|
-
function createCoreAgentAdapter(e,
|
|
376
|
-
let { appId:
|
|
377
|
-
let
|
|
378
|
-
return await axios_default.post(`/openapi/v1/app/chat-messages/${
|
|
379
|
-
Authorization: `Bearer ${f}`,
|
|
380
|
-
appId: u
|
|
381
|
-
} }), Promise.resolve();
|
|
382
|
-
}, h = async (e) => {
|
|
383
|
-
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: {
|
|
384
385
|
Authorization: `Bearer ${d}`,
|
|
385
|
-
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
|
|
386
392
|
} });
|
|
387
|
-
return
|
|
388
|
-
},
|
|
389
|
-
let
|
|
393
|
+
return d.result === "success" ? d.data : [];
|
|
394
|
+
}, h = async (e) => {
|
|
395
|
+
let c = await s.getToken();
|
|
390
396
|
return await axios_default.get(`/openapi/v1/app/conversations?${new URLSearchParams(e).toString()}`, { headers: {
|
|
391
|
-
Authorization: `Bearer ${
|
|
392
|
-
appId:
|
|
397
|
+
Authorization: `Bearer ${c}`,
|
|
398
|
+
appId: l
|
|
393
399
|
} });
|
|
394
|
-
},
|
|
395
|
-
let
|
|
400
|
+
}, g = async (e) => {
|
|
401
|
+
let c = await s.getToken();
|
|
396
402
|
return await axios_default.get(`/openapi/v1/app/messages?${new URLSearchParams(e).toString()}`, { headers: {
|
|
397
|
-
Authorization: `Bearer ${
|
|
398
|
-
appId:
|
|
403
|
+
Authorization: `Bearer ${c}`,
|
|
404
|
+
appId: l
|
|
399
405
|
} });
|
|
400
|
-
},
|
|
401
|
-
let { hitlData:
|
|
402
|
-
query:
|
|
403
|
-
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 || {},
|
|
404
410
|
response_mode: "streaming",
|
|
405
|
-
conversation_id:
|
|
406
|
-
parent_message_id:
|
|
407
|
-
user:
|
|
411
|
+
conversation_id: u?.conversationId || null,
|
|
412
|
+
parent_message_id: u?.messageId || null,
|
|
413
|
+
user: f,
|
|
408
414
|
files: []
|
|
409
|
-
},
|
|
415
|
+
}, h = await s.getToken();
|
|
410
416
|
return {
|
|
411
417
|
url: "/openapi/v1/app/chat-messages",
|
|
412
418
|
config: {
|
|
413
419
|
method: "POST",
|
|
414
420
|
headers: {
|
|
415
421
|
"Content-Type": "application/json",
|
|
416
|
-
Authorization: `Bearer ${
|
|
417
|
-
appId:
|
|
422
|
+
Authorization: `Bearer ${h}`,
|
|
423
|
+
appId: l
|
|
418
424
|
},
|
|
419
|
-
body: JSON.stringify(
|
|
425
|
+
body: JSON.stringify(m)
|
|
420
426
|
}
|
|
421
427
|
};
|
|
422
|
-
},
|
|
423
|
-
let { data:
|
|
424
|
-
return JSON.parse(
|
|
425
|
-
},
|
|
426
|
-
|
|
427
|
-
},
|
|
428
|
-
|
|
429
|
-
},
|
|
430
|
-
|
|
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
|
+
}
|
|
431
443
|
}, C = async (e) => {
|
|
432
|
-
sseRequester(await
|
|
433
|
-
formatReuqest:
|
|
434
|
-
getSuggestionQuestions:
|
|
435
|
-
getConversationList:
|
|
436
|
-
getMessageHistory:
|
|
437
|
-
onMessage:
|
|
438
|
-
onClose:
|
|
439
|
-
onError:
|
|
440
|
-
onOpen:
|
|
441
|
-
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
|
|
442
454
|
});
|
|
443
455
|
}, w = async (e) => {
|
|
444
|
-
let
|
|
456
|
+
let s = [], c;
|
|
445
457
|
if (e.data.forEach((e) => {
|
|
446
|
-
e.parent_message_id ===
|
|
458
|
+
if (e.parent_message_id === c) s.pop(), s.push({
|
|
447
459
|
role: "ai",
|
|
448
460
|
showActions: !1,
|
|
449
461
|
content: e.answer,
|
|
@@ -454,41 +466,52 @@ function createCoreAgentAdapter(e, c, l) {
|
|
|
454
466
|
name: e.filename
|
|
455
467
|
})),
|
|
456
468
|
placement: "start"
|
|
457
|
-
})
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
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
|
+
}
|
|
478
501
|
}), e.has_more) {
|
|
479
|
-
let e = await
|
|
480
|
-
conversation_id:
|
|
481
|
-
user:
|
|
482
|
-
first_id:
|
|
502
|
+
let e = await g({
|
|
503
|
+
conversation_id: s[s.length - 1].conversationId,
|
|
504
|
+
user: f,
|
|
505
|
+
first_id: s[0].messageId
|
|
483
506
|
});
|
|
484
507
|
if (e.data) {
|
|
485
|
-
let
|
|
486
|
-
|
|
508
|
+
let c = await w(e);
|
|
509
|
+
s.unshift(...c);
|
|
487
510
|
}
|
|
488
511
|
}
|
|
489
|
-
return
|
|
512
|
+
return s;
|
|
490
513
|
}, T = async () => (pilotStore.getState().resetMessageHistory(), !0), E = async (e) => {
|
|
491
|
-
let
|
|
514
|
+
let s = {
|
|
492
515
|
messageId: void 0,
|
|
493
516
|
content: e.text,
|
|
494
517
|
role: "user",
|
|
@@ -496,41 +519,41 @@ function createCoreAgentAdapter(e, c, l) {
|
|
|
496
519
|
showActions: !1,
|
|
497
520
|
maxWidth: "100%"
|
|
498
521
|
};
|
|
499
|
-
pilotStore.getState().updateMessageHistory([
|
|
500
|
-
let
|
|
522
|
+
pilotStore.getState().updateMessageHistory([s]), pilotStore.getState().resetCurrentMessage();
|
|
523
|
+
let c = await _({
|
|
501
524
|
text: e.text,
|
|
502
525
|
prevMessage: void 0,
|
|
503
526
|
inputs: e.inputs
|
|
504
527
|
});
|
|
505
|
-
return pilotStore.getState().setActiveScence(e.inputs?.scence), sseRequester(
|
|
506
|
-
formatReuqest:
|
|
507
|
-
getSuggestionQuestions:
|
|
508
|
-
getConversationList:
|
|
509
|
-
getMessageHistory:
|
|
510
|
-
onMessage:
|
|
511
|
-
onClose:
|
|
512
|
-
onError:
|
|
513
|
-
onOpen:
|
|
514
|
-
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
|
|
515
538
|
});
|
|
516
539
|
};
|
|
517
540
|
return {
|
|
518
|
-
formatReuqest:
|
|
519
|
-
getSuggestionQuestions:
|
|
520
|
-
getConversationList:
|
|
521
|
-
getMessageHistory:
|
|
522
|
-
onMessage:
|
|
523
|
-
onClose:
|
|
524
|
-
onError:
|
|
525
|
-
onOpen:
|
|
526
|
-
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,
|
|
527
550
|
triggerEvent: async (e) => {
|
|
528
551
|
switch (e.action) {
|
|
529
|
-
case "get_suggestion_questions": return await
|
|
530
|
-
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);
|
|
531
554
|
case "get_message_history":
|
|
532
|
-
let
|
|
533
|
-
return pilotStore.getState().resetMessageHistory(
|
|
555
|
+
let s = await w(await g(e.payload));
|
|
556
|
+
return pilotStore.getState().resetMessageHistory(s), s;
|
|
534
557
|
case "submit_core_action": return await C(e.payload);
|
|
535
558
|
case "new_message": return await T();
|
|
536
559
|
case "submit_message": return await E(e.payload);
|
|
@@ -539,82 +562,82 @@ function createCoreAgentAdapter(e, c, l) {
|
|
|
539
562
|
}
|
|
540
563
|
};
|
|
541
564
|
}
|
|
542
|
-
function createProtocolAdapter(e, c, l
|
|
543
|
-
switch (
|
|
544
|
-
case "coreagent": return createCoreAgentAdapter(e,
|
|
545
|
-
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}`);
|
|
546
569
|
}
|
|
547
570
|
}
|
|
548
|
-
function createHitlManager(e,
|
|
549
|
-
let
|
|
550
|
-
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);
|
|
551
574
|
sseRequester({
|
|
552
|
-
url:
|
|
553
|
-
config:
|
|
554
|
-
}, e),
|
|
555
|
-
},
|
|
556
|
-
|
|
557
|
-
},
|
|
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) => {};
|
|
558
581
|
return {
|
|
559
582
|
async submit(e) {
|
|
560
583
|
try {
|
|
561
|
-
let
|
|
562
|
-
switch (
|
|
584
|
+
let s = l(e.hitlData?.action ?? "");
|
|
585
|
+
switch (c.log("[HITL] Submitting HITL data...", e), s) {
|
|
563
586
|
case "core":
|
|
564
|
-
await
|
|
587
|
+
await d(e);
|
|
565
588
|
break;
|
|
566
589
|
case "cust":
|
|
567
|
-
await
|
|
590
|
+
await f(e);
|
|
568
591
|
break;
|
|
569
592
|
case "inner":
|
|
570
|
-
await
|
|
593
|
+
await p(e);
|
|
571
594
|
break;
|
|
572
595
|
default: throw Error("Invalid action type.");
|
|
573
596
|
}
|
|
574
597
|
} catch (e) {
|
|
575
|
-
throw
|
|
598
|
+
throw c.error("Error submitting HITL data:", e), e;
|
|
576
599
|
}
|
|
577
600
|
},
|
|
578
601
|
subscribeEvent(e) {
|
|
579
|
-
|
|
602
|
+
u.includes(e) || u.push(e);
|
|
580
603
|
},
|
|
581
604
|
unsubscribeEvent(e) {
|
|
582
|
-
|
|
605
|
+
u.splice(u.indexOf(e), 1);
|
|
583
606
|
}
|
|
584
607
|
};
|
|
585
608
|
}
|
|
586
609
|
function createCorePilot(e) {
|
|
587
610
|
if (!e.appId) throw Error("CorePilot SDK: `appId` is required.");
|
|
588
611
|
if (!e.mount.selector) throw Error("CorePilot SDK: `mount.selector` is required.");
|
|
589
|
-
let
|
|
590
|
-
|
|
591
|
-
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);
|
|
592
615
|
return {
|
|
593
616
|
mount() {
|
|
594
|
-
|
|
617
|
+
s.log("Mounting CorePilot UI..."), f.mount();
|
|
595
618
|
},
|
|
596
619
|
unmount() {
|
|
597
|
-
|
|
620
|
+
s.log("Unmounting CorePilot UI..."), f.unmount();
|
|
598
621
|
},
|
|
599
622
|
reload(e) {
|
|
600
|
-
|
|
601
|
-
...
|
|
623
|
+
s.log("Reloading CorePilot instance...", e), f.unmount(), c = {
|
|
624
|
+
...c,
|
|
602
625
|
...e
|
|
603
|
-
},
|
|
604
|
-
let
|
|
605
|
-
|
|
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();
|
|
606
629
|
},
|
|
607
630
|
destroy() {
|
|
608
|
-
|
|
631
|
+
s.log("Destroying CorePilot instance..."), f.unmount(), s.destroy();
|
|
609
632
|
},
|
|
610
633
|
async triggerEvent(e) {
|
|
611
|
-
return await
|
|
634
|
+
return await u.triggerEvent(e);
|
|
612
635
|
},
|
|
613
636
|
subscribeEvent(e) {
|
|
614
|
-
|
|
637
|
+
d.subscribeEvent(e);
|
|
615
638
|
},
|
|
616
639
|
unsubscribeEvent(e) {
|
|
617
|
-
|
|
640
|
+
d.unsubscribeEvent(e);
|
|
618
641
|
}
|
|
619
642
|
};
|
|
620
643
|
}
|