@eaera-com/cms-sdk 0.1.98 → 0.1.100
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/chunks/{connection-DhqBa4cO.js → connection--KUpmDbP.js} +43 -3
- package/dist/server/ai/qwenpaw/chat/stop.post.js +2 -2
- package/dist/server/ai/qwenpaw/chat.post.js +2 -2
- package/dist/server/ai/qwenpaw/chats-id.delete.js +2 -2
- package/dist/server/ai/qwenpaw/chats.get.js +2 -2
- package/dist/server/ai/qwenpaw/history.get.js +2 -2
- package/dist/server/ai/qwenpaw/session.get.js +1 -1
- package/dist/server/ai/qwenpaw/session.post.js +3 -20
- package/dist/server/ai/qwenpaw/upload.post.js +2 -2
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@ import { getCookie, createError, setCookie } from 'h3';
|
|
|
2
2
|
import { ofetch } from 'ofetch';
|
|
3
3
|
import { useRuntimeConfig } from '#imports';
|
|
4
4
|
import { T as TOKEN_STORAGE_KEY } from './storage.constant-CVWam5ls.js';
|
|
5
|
-
import {
|
|
5
|
+
import { l as QWENPAW_RUNTIME_CONFIG_KEY, d as QWENPAW_DEFAULT_AGENT_ID, m as QWENPAW_EXCHANGE_ACTION_PATH, n as QWENPAW_EXCHANGE_TIMEOUT_MS, o as QWENPAW_CONFIGURATION_ERROR_CODES, p as QWENPAW_COOKIE_BASE_URL, q as QWENPAW_COOKIE_MAX_AGE } from './qwenpaw.constant-DHSj9A-0.js';
|
|
6
6
|
|
|
7
7
|
class QwenpawExchangeError extends Error {
|
|
8
8
|
constructor(code, configurationError, message) {
|
|
@@ -27,6 +27,11 @@ const setQwenpawSessionCookies = (event, connection) => {
|
|
|
27
27
|
path: "/",
|
|
28
28
|
maxAge: QWENPAW_COOKIE_MAX_AGE
|
|
29
29
|
};
|
|
30
|
+
console.log("[qwenpaw] exchange saved connection →", {
|
|
31
|
+
agentId: connection.agentId,
|
|
32
|
+
agentIdIsConstant: connection.agentId === QWENPAW_DEFAULT_AGENT_ID,
|
|
33
|
+
baseUrl: connection.baseUrl
|
|
34
|
+
});
|
|
30
35
|
setCookie(event, QWENPAW_COOKIE_BASE_URL, connection.baseUrl, common);
|
|
31
36
|
};
|
|
32
37
|
const readCookieValue = (event, name) => {
|
|
@@ -35,12 +40,47 @@ const readCookieValue = (event, name) => {
|
|
|
35
40
|
};
|
|
36
41
|
const resolveQwenpawConnection = (event, overrides = {}) => {
|
|
37
42
|
const config = resolveQwenpawServerConfig(event);
|
|
38
|
-
|
|
43
|
+
const resolved = {
|
|
39
44
|
baseUrl: overrides.baseUrl || readCookieValue(event, QWENPAW_COOKIE_BASE_URL) || config.baseUrl,
|
|
40
45
|
agentId: QWENPAW_DEFAULT_AGENT_ID
|
|
41
46
|
};
|
|
47
|
+
console.log("[qwenpaw] resolveQwenpawConnection →", {
|
|
48
|
+
agentId: resolved.agentId,
|
|
49
|
+
source: overrides.baseUrl ? "override" : readCookieValue(event, QWENPAW_COOKIE_BASE_URL) ? "cookie" : "runtimeConfig",
|
|
50
|
+
baseUrl: resolved.baseUrl
|
|
51
|
+
});
|
|
52
|
+
return resolved;
|
|
42
53
|
};
|
|
43
54
|
const hasQwenpawConnection = (event) => Boolean(resolveQwenpawConnection(event).baseUrl);
|
|
55
|
+
const resolveFreshQwenpawConnection = async (event) => {
|
|
56
|
+
let connection = resolveQwenpawConnection(event);
|
|
57
|
+
if (!connection.baseUrl) {
|
|
58
|
+
try {
|
|
59
|
+
await exchangeQwenpawSession(event);
|
|
60
|
+
} catch (error) {
|
|
61
|
+
handleExchangeError(error);
|
|
62
|
+
}
|
|
63
|
+
connection = resolveQwenpawConnection(event);
|
|
64
|
+
}
|
|
65
|
+
return connection;
|
|
66
|
+
};
|
|
67
|
+
const exchangeErrorStatus = (error) => {
|
|
68
|
+
if (error.code === "AI_NOT_AUTHENTICATED") return 401;
|
|
69
|
+
if (error.configurationError) return 403;
|
|
70
|
+
if (error.code === "AI_SESSION_EXCHANGE_FAILED") return 423;
|
|
71
|
+
return 502;
|
|
72
|
+
};
|
|
73
|
+
const handleExchangeError = (error) => {
|
|
74
|
+
if (error instanceof QwenpawExchangeError) {
|
|
75
|
+
throw createError({
|
|
76
|
+
statusCode: exchangeErrorStatus(error),
|
|
77
|
+
message: error.message,
|
|
78
|
+
data: { code: error.code }
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
console.error("qwenpaw-session", error);
|
|
82
|
+
throw createError({ statusCode: 502, message: "The AI agent is unreachable." });
|
|
83
|
+
};
|
|
44
84
|
const cmsBackendUrl = (event) => {
|
|
45
85
|
const pub = useRuntimeConfig(event).public ?? {};
|
|
46
86
|
const opts = pub.cmsSdkOptions ?? {};
|
|
@@ -107,4 +147,4 @@ const exchangeQwenpawSession = async (event) => {
|
|
|
107
147
|
return connection;
|
|
108
148
|
};
|
|
109
149
|
|
|
110
|
-
export {
|
|
150
|
+
export { resolveFreshQwenpawConnection as a, resolveQwenpawServerConfig as b, resolveQwenpawConnection as c, handleExchangeError as d, exchangeQwenpawSession as e, hasQwenpawConnection as h, requireCmsSession as r };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineEventHandler, readBody, createError } from 'h3';
|
|
2
2
|
import { c as qwenpawStop, p as postConsoleChatError } from '../../../../chunks/client-Ac6qgpZ8.js';
|
|
3
3
|
import { c as QWENPAW_MAX_SESSION_ID_LENGTH } from '../../../../chunks/qwenpaw.constant-DHSj9A-0.js';
|
|
4
|
-
import { r as requireCmsSession, a as
|
|
4
|
+
import { r as requireCmsSession, a as resolveFreshQwenpawConnection, b as resolveQwenpawServerConfig } from '../../../../chunks/connection--KUpmDbP.js';
|
|
5
5
|
|
|
6
6
|
const stop_post = defineEventHandler(async (event) => {
|
|
7
7
|
requireCmsSession(event);
|
|
@@ -10,7 +10,7 @@ const stop_post = defineEventHandler(async (event) => {
|
|
|
10
10
|
if (!sessionId || sessionId.length > QWENPAW_MAX_SESSION_ID_LENGTH) {
|
|
11
11
|
throw createError({ statusCode: 400, message: "Conversation session is required." });
|
|
12
12
|
}
|
|
13
|
-
const connection =
|
|
13
|
+
const connection = await resolveFreshQwenpawConnection(event);
|
|
14
14
|
try {
|
|
15
15
|
return await qwenpawStop({
|
|
16
16
|
config: resolveQwenpawServerConfig(event),
|
|
@@ -2,7 +2,7 @@ import { Readable } from 'node:stream';
|
|
|
2
2
|
import { defineEventHandler, readBody, createError, setResponseStatus, setResponseHeader, sendStream } from 'h3';
|
|
3
3
|
import { q as qwenpawChat, p as postConsoleChatError } from '../../../chunks/client-Ac6qgpZ8.js';
|
|
4
4
|
import { Q as QWENPAW_MAX_MESSAGE_LENGTH, a as QWENPAW_MAX_FILES, b as QWENPAW_MAX_FILE_NAME_LENGTH, c as QWENPAW_MAX_SESSION_ID_LENGTH } from '../../../chunks/qwenpaw.constant-DHSj9A-0.js';
|
|
5
|
-
import { r as requireCmsSession, a as
|
|
5
|
+
import { r as requireCmsSession, a as resolveFreshQwenpawConnection, b as resolveQwenpawServerConfig } from '../../../chunks/connection--KUpmDbP.js';
|
|
6
6
|
|
|
7
7
|
const chat_post = defineEventHandler(async (event) => {
|
|
8
8
|
requireCmsSession(event);
|
|
@@ -27,7 +27,7 @@ const chat_post = defineEventHandler(async (event) => {
|
|
|
27
27
|
if (!sessionId || sessionId.length > QWENPAW_MAX_SESSION_ID_LENGTH) {
|
|
28
28
|
throw createError({ statusCode: 400, message: "Conversation session is required." });
|
|
29
29
|
}
|
|
30
|
-
const connection =
|
|
30
|
+
const connection = await resolveFreshQwenpawConnection(event);
|
|
31
31
|
const upstreamAbort = new AbortController();
|
|
32
32
|
event.node.req.once("close", () => upstreamAbort.abort());
|
|
33
33
|
let upstream;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineEventHandler, getRouterParam, createError } from 'h3';
|
|
2
2
|
import { d as deleteQwenpawChat } from '../../../chunks/chats-BjSS83OW.js';
|
|
3
|
-
import { r as requireCmsSession, a as
|
|
3
|
+
import { r as requireCmsSession, a as resolveFreshQwenpawConnection } from '../../../chunks/connection--KUpmDbP.js';
|
|
4
4
|
|
|
5
5
|
const chatsId_delete = defineEventHandler(async (event) => {
|
|
6
6
|
requireCmsSession(event);
|
|
@@ -8,7 +8,7 @@ const chatsId_delete = defineEventHandler(async (event) => {
|
|
|
8
8
|
if (!chatId) {
|
|
9
9
|
throw createError({ statusCode: 400, message: "Missing chat id." });
|
|
10
10
|
}
|
|
11
|
-
const ok = await deleteQwenpawChat(
|
|
11
|
+
const ok = await deleteQwenpawChat(await resolveFreshQwenpawConnection(event), chatId);
|
|
12
12
|
if (!ok) {
|
|
13
13
|
throw createError({ statusCode: 502, message: "Delete failed." });
|
|
14
14
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { defineEventHandler } from 'h3';
|
|
2
2
|
import { l as listQwenpawChats, a as listQwenpawGroups } from '../../../chunks/chats-BjSS83OW.js';
|
|
3
3
|
import { d as QWENPAW_DEFAULT_AGENT_ID } from '../../../chunks/qwenpaw.constant-DHSj9A-0.js';
|
|
4
|
-
import { r as requireCmsSession, a as
|
|
4
|
+
import { r as requireCmsSession, a as resolveFreshQwenpawConnection } from '../../../chunks/connection--KUpmDbP.js';
|
|
5
5
|
|
|
6
6
|
const chats_get = defineEventHandler(async (event) => {
|
|
7
7
|
requireCmsSession(event);
|
|
8
|
-
const connection =
|
|
8
|
+
const connection = await resolveFreshQwenpawConnection(event);
|
|
9
9
|
const [chats, groups] = await Promise.all([
|
|
10
10
|
listQwenpawChats(connection),
|
|
11
11
|
listQwenpawGroups(connection)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineEventHandler, getQuery, createError } from 'h3';
|
|
2
2
|
import { f as fetchChatHistory } from '../../../chunks/chats-BjSS83OW.js';
|
|
3
|
-
import { r as requireCmsSession, a as
|
|
3
|
+
import { r as requireCmsSession, a as resolveFreshQwenpawConnection } from '../../../chunks/connection--KUpmDbP.js';
|
|
4
4
|
|
|
5
5
|
const history_get = defineEventHandler(async (event) => {
|
|
6
6
|
requireCmsSession(event);
|
|
@@ -9,7 +9,7 @@ const history_get = defineEventHandler(async (event) => {
|
|
|
9
9
|
if (!chatId) {
|
|
10
10
|
throw createError({ statusCode: 400, message: "Missing chat id." });
|
|
11
11
|
}
|
|
12
|
-
const connection =
|
|
12
|
+
const connection = await resolveFreshQwenpawConnection(event);
|
|
13
13
|
return await fetchChatHistory(connection, chatId);
|
|
14
14
|
});
|
|
15
15
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defineEventHandler } from 'h3';
|
|
2
|
-
import { r as requireCmsSession,
|
|
2
|
+
import { r as requireCmsSession, c as resolveQwenpawConnection, h as hasQwenpawConnection } from '../../../chunks/connection--KUpmDbP.js';
|
|
3
3
|
|
|
4
4
|
const session_get = defineEventHandler((event) => {
|
|
5
5
|
requireCmsSession(event);
|
|
@@ -1,23 +1,6 @@
|
|
|
1
|
-
import { defineEventHandler
|
|
2
|
-
import { r as requireCmsSession, e as exchangeQwenpawSession,
|
|
1
|
+
import { defineEventHandler } from 'h3';
|
|
2
|
+
import { r as requireCmsSession, e as exchangeQwenpawSession, d as handleExchangeError } from '../../../chunks/connection--KUpmDbP.js';
|
|
3
3
|
|
|
4
|
-
const exchangeErrorStatus = (error) => {
|
|
5
|
-
if (error.code === "AI_NOT_AUTHENTICATED") return 401;
|
|
6
|
-
if (error.configurationError) return 403;
|
|
7
|
-
if (error.code === "AI_SESSION_EXCHANGE_FAILED") return 423;
|
|
8
|
-
return 502;
|
|
9
|
-
};
|
|
10
|
-
const handleExchangeError = (error) => {
|
|
11
|
-
if (error instanceof QwenpawExchangeError) {
|
|
12
|
-
throw createError({
|
|
13
|
-
statusCode: exchangeErrorStatus(error),
|
|
14
|
-
message: error.message,
|
|
15
|
-
data: { code: error.code }
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
console.error("qwenpaw-session", error);
|
|
19
|
-
throw createError({ statusCode: 502, message: "The AI agent is unreachable." });
|
|
20
|
-
};
|
|
21
4
|
const session_post = defineEventHandler(async (event) => {
|
|
22
5
|
requireCmsSession(event);
|
|
23
6
|
try {
|
|
@@ -28,4 +11,4 @@ const session_post = defineEventHandler(async (event) => {
|
|
|
28
11
|
}
|
|
29
12
|
});
|
|
30
13
|
|
|
31
|
-
export { session_post as default
|
|
14
|
+
export { session_post as default };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineEventHandler, readMultipartFormData, createError } from 'h3';
|
|
2
2
|
import { d as qwenpawUpload, p as postConsoleChatError } from '../../../chunks/client-Ac6qgpZ8.js';
|
|
3
3
|
import { g as QWENPAW_MAX_UPLOAD_BYTES } from '../../../chunks/qwenpaw.constant-DHSj9A-0.js';
|
|
4
|
-
import { r as requireCmsSession, a as
|
|
4
|
+
import { r as requireCmsSession, a as resolveFreshQwenpawConnection, b as resolveQwenpawServerConfig } from '../../../chunks/connection--KUpmDbP.js';
|
|
5
5
|
|
|
6
6
|
const upload_post = defineEventHandler(async (event) => {
|
|
7
7
|
requireCmsSession(event);
|
|
@@ -13,7 +13,7 @@ const upload_post = defineEventHandler(async (event) => {
|
|
|
13
13
|
if (filePart.data.length > QWENPAW_MAX_UPLOAD_BYTES) {
|
|
14
14
|
throw createError({ statusCode: 413, message: "File too large (max 20 MB)." });
|
|
15
15
|
}
|
|
16
|
-
const connection =
|
|
16
|
+
const connection = await resolveFreshQwenpawConnection(event);
|
|
17
17
|
const form = new FormData();
|
|
18
18
|
form.append(
|
|
19
19
|
"file",
|