@schema-platform/platform-shared 1.7.18 → 1.7.20
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/socket/index.d.ts +9 -1
- package/dist/socket/index.js +16 -16
- package/dist/utils/authPaths.js +10 -13
- package/package.json +1 -1
- package/socket/index.ts +10 -5
- package/utils/authPaths.ts +18 -14
package/dist/socket/index.d.ts
CHANGED
|
@@ -28,7 +28,15 @@ export interface AiPublishedEvent {
|
|
|
28
28
|
}
|
|
29
29
|
/** 注入 token 提供者(与 apiClient.setTokenProvider 用法一致) */
|
|
30
30
|
export declare function setSocketTokenProvider(provider: () => string | null): void;
|
|
31
|
-
/**
|
|
31
|
+
/**
|
|
32
|
+
* 解析 Socket.IO path。
|
|
33
|
+
*
|
|
34
|
+
* 不能按页面 pathname 猜环境:vigil 面板部署在 `/vigil/`、编辑器等部署在 `/schema-platform/*`,
|
|
35
|
+
* 按 pathname 判断会把 `/vigil/` 页面误判为开发环境、解析到生产 nginx 并不存在的根级 `/ws`,
|
|
36
|
+
* 握手落到 SPA HTML 兜底导致 `websocket error`。
|
|
37
|
+
*
|
|
38
|
+
* 改为按构建环境判定:开发环境走 dev 代理的 `/ws`,生产环境统一走 nginx 唯一暴露的 `/schema-platform/ws`。
|
|
39
|
+
*/
|
|
32
40
|
export declare function resolveSocketPath(explicit?: string): string;
|
|
33
41
|
/** 订阅连接状态变化(立即回调当前状态) */
|
|
34
42
|
export declare function onConnectionChange(handler: (connected: boolean) => void): () => void;
|
package/dist/socket/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { io as m } from "socket.io-client";
|
|
|
2
2
|
let n = null, o = !1;
|
|
3
3
|
const f = /* @__PURE__ */ new Set();
|
|
4
4
|
let r = null, t = null;
|
|
5
|
-
function
|
|
5
|
+
function b(e) {
|
|
6
6
|
r = e;
|
|
7
7
|
}
|
|
8
8
|
function s() {
|
|
@@ -15,9 +15,9 @@ function u() {
|
|
|
15
15
|
n && (n.removeAllListeners(), n.disconnect(), n = null, o = !1, l());
|
|
16
16
|
}
|
|
17
17
|
function h(e) {
|
|
18
|
-
return e ||
|
|
18
|
+
return e || "/schema-platform/ws";
|
|
19
19
|
}
|
|
20
|
-
function
|
|
20
|
+
function p(e) {
|
|
21
21
|
return e(o), f.add(e), () => {
|
|
22
22
|
f.delete(e);
|
|
23
23
|
};
|
|
@@ -29,14 +29,14 @@ function l() {
|
|
|
29
29
|
function v() {
|
|
30
30
|
return o;
|
|
31
31
|
}
|
|
32
|
-
function
|
|
32
|
+
function g(e) {
|
|
33
33
|
if (n != null && n.connected) return;
|
|
34
34
|
const i = (e == null ? void 0 : e.url) ?? (typeof window < "u" ? window.location.origin : ""), d = h(e == null ? void 0 : e.path);
|
|
35
35
|
if (!i) return;
|
|
36
36
|
const a = s();
|
|
37
37
|
if (!a) {
|
|
38
38
|
typeof window < "u" && !t && (t = () => {
|
|
39
|
-
s() && (c(),
|
|
39
|
+
s() && (c(), g(e));
|
|
40
40
|
}, window.addEventListener("storage", t)), console.warn("[socket] deferred connect: no auth token");
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
@@ -52,10 +52,10 @@ function p(e) {
|
|
|
52
52
|
console.warn("[socket] connection error:", w.message), /authentication|token|expired/i.test(w.message) && u();
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
|
-
function
|
|
55
|
+
function C() {
|
|
56
56
|
c(), u();
|
|
57
57
|
}
|
|
58
|
-
function
|
|
58
|
+
function y(e) {
|
|
59
59
|
n && o && n.emit("identify", { userId: e });
|
|
60
60
|
}
|
|
61
61
|
function A(e) {
|
|
@@ -73,10 +73,10 @@ function S(e) {
|
|
|
73
73
|
function E(e) {
|
|
74
74
|
n && o && n.emit("ai:apply", e);
|
|
75
75
|
}
|
|
76
|
-
function
|
|
76
|
+
function L(e) {
|
|
77
77
|
n && o && n.emit("ai:published", e);
|
|
78
78
|
}
|
|
79
|
-
function
|
|
79
|
+
function W(e) {
|
|
80
80
|
return n ? (n.on("flow:notification", e), () => {
|
|
81
81
|
n == null || n.off("flow:notification", e);
|
|
82
82
|
}) : () => {
|
|
@@ -126,25 +126,25 @@ function I(e) {
|
|
|
126
126
|
};
|
|
127
127
|
}
|
|
128
128
|
export {
|
|
129
|
-
|
|
130
|
-
|
|
129
|
+
g as connect,
|
|
130
|
+
C as disconnect,
|
|
131
131
|
E as emitAiApply,
|
|
132
|
-
|
|
132
|
+
L as emitAiPublished,
|
|
133
133
|
T as emitChatCancel,
|
|
134
134
|
_ as emitChatResume,
|
|
135
135
|
P as emitChatSend,
|
|
136
136
|
x as emitWorkflowSubscribe,
|
|
137
137
|
z as emitWorkflowUnsubscribe,
|
|
138
|
-
|
|
138
|
+
y as identify,
|
|
139
139
|
v as isConnected,
|
|
140
140
|
A as onAiApply,
|
|
141
141
|
S as onAiPublished,
|
|
142
142
|
N as onChatEvent,
|
|
143
|
-
|
|
144
|
-
|
|
143
|
+
p as onConnectionChange,
|
|
144
|
+
W as onFlowNotification,
|
|
145
145
|
H as onWorkflowError,
|
|
146
146
|
F as onWorkflowEvent,
|
|
147
147
|
I as onWorkflowNodeEvent,
|
|
148
148
|
h as resolveSocketPath,
|
|
149
|
-
|
|
149
|
+
b as setSocketTokenProvider
|
|
150
150
|
};
|
package/dist/utils/authPaths.js
CHANGED
|
@@ -21,27 +21,24 @@ function p(o) {
|
|
|
21
21
|
const e = f(window.location.pathname);
|
|
22
22
|
return e ? `${n}${a}/${e}/login?redirect=${encodeURIComponent(t)}` : `${n}/login?redirect=${encodeURIComponent(t)}`;
|
|
23
23
|
}
|
|
24
|
-
function
|
|
24
|
+
function P(o) {
|
|
25
25
|
s() || (window.location.href = p(o));
|
|
26
26
|
}
|
|
27
27
|
const h = /^\/schema-platform\/(editor|flow|ai|ua|docs)$/, $ = /^\/schema-platform\/(editor|flow|ai|ua|docs)(\/|$)/;
|
|
28
|
-
function
|
|
28
|
+
function g(o, n) {
|
|
29
29
|
const t = (o || "/").trim() || "/", e = n.endsWith("/") ? n : `${n}/`, r = e.replace(/\/$/, "") || "/";
|
|
30
|
-
if (
|
|
31
|
-
if (t === r || t === e
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return i.startsWith("/") || (i = `/${i}`), { mode: "router", path: i || "/" };
|
|
36
|
-
}
|
|
37
|
-
return { mode: "location", href: h.test(t) ? `${t}/` : t };
|
|
30
|
+
if (t === r || t === e || t.startsWith(e) || r !== "/" && t.startsWith(`${r}/`)) {
|
|
31
|
+
if (t === r || t === e)
|
|
32
|
+
return { mode: "router", path: "/" };
|
|
33
|
+
let i = t.slice(r.length);
|
|
34
|
+
return i.startsWith("/") || (i = `/${i}`), { mode: "router", path: i || "/" };
|
|
38
35
|
}
|
|
39
|
-
return { mode: "router", path: t.startsWith("/") ? t : `/${t}` };
|
|
36
|
+
return $.test(t) ? { mode: "location", href: h.test(t) ? `${t}/` : t } : { mode: "router", path: t.startsWith("/") ? t : `/${t}` };
|
|
40
37
|
}
|
|
41
38
|
export {
|
|
42
39
|
s as isAuthLoginPath,
|
|
43
40
|
u as isShellEmbedded,
|
|
44
|
-
|
|
41
|
+
P as redirectToLogin,
|
|
45
42
|
p as resolveLoginUrl,
|
|
46
|
-
|
|
43
|
+
g as resolvePostLoginNavigation
|
|
47
44
|
};
|
package/package.json
CHANGED
package/socket/index.ts
CHANGED
|
@@ -67,13 +67,18 @@ function teardownSocket(): void {
|
|
|
67
67
|
notifyConnectionChange()
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
/**
|
|
70
|
+
/**
|
|
71
|
+
* 解析 Socket.IO path。
|
|
72
|
+
*
|
|
73
|
+
* 不能按页面 pathname 猜环境:vigil 面板部署在 `/vigil/`、编辑器等部署在 `/schema-platform/*`,
|
|
74
|
+
* 按 pathname 判断会把 `/vigil/` 页面误判为开发环境、解析到生产 nginx 并不存在的根级 `/ws`,
|
|
75
|
+
* 握手落到 SPA HTML 兜底导致 `websocket error`。
|
|
76
|
+
*
|
|
77
|
+
* 改为按构建环境判定:开发环境走 dev 代理的 `/ws`,生产环境统一走 nginx 唯一暴露的 `/schema-platform/ws`。
|
|
78
|
+
*/
|
|
71
79
|
export function resolveSocketPath(explicit?: string): string {
|
|
72
80
|
if (explicit) return explicit
|
|
73
|
-
|
|
74
|
-
return '/schema-platform/ws'
|
|
75
|
-
}
|
|
76
|
-
return '/ws'
|
|
81
|
+
return import.meta.env.DEV ? '/ws' : '/schema-platform/ws'
|
|
77
82
|
}
|
|
78
83
|
|
|
79
84
|
/** 订阅连接状态变化(立即回调当前状态) */
|
package/utils/authPaths.ts
CHANGED
|
@@ -79,22 +79,26 @@ export function resolvePostLoginNavigation(
|
|
|
79
79
|
const base = routeBase.endsWith('/') ? routeBase : `${routeBase}/`
|
|
80
80
|
const baseNoSlash = base.replace(/\/$/, '') || '/'
|
|
81
81
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
if (!path.startsWith('/')) path = `/${path}`
|
|
95
|
-
return { mode: 'router', path: path || '/' }
|
|
82
|
+
// 同应用:落在当前 base 内 → 去掉 base 前缀后走 router。
|
|
83
|
+
// 不区分平台/非平台:redirect 存的是含 base 的完整 pathname(如 vigil 的 /vigil/llm),
|
|
84
|
+
// router.push 的 path 必须去掉 base,否则会拼成 /vigil/vigil/llm(地址栏倍增)。
|
|
85
|
+
const underCurrent =
|
|
86
|
+
raw === baseNoSlash ||
|
|
87
|
+
raw === base ||
|
|
88
|
+
raw.startsWith(base) ||
|
|
89
|
+
(baseNoSlash !== '/' && raw.startsWith(`${baseNoSlash}/`))
|
|
90
|
+
|
|
91
|
+
if (underCurrent) {
|
|
92
|
+
if (raw === baseNoSlash || raw === base) {
|
|
93
|
+
return { mode: 'router', path: '/' }
|
|
96
94
|
}
|
|
95
|
+
let path = raw.slice(baseNoSlash.length)
|
|
96
|
+
if (!path.startsWith('/')) path = `/${path}`
|
|
97
|
+
return { mode: 'router', path: path || '/' }
|
|
98
|
+
}
|
|
97
99
|
|
|
100
|
+
// 跨平台应用:硬跳转,「仅应用根路径」补尾斜杠,避免 nginx 无斜杠落到兜底 AI
|
|
101
|
+
if (PLATFORM_APP_PATH_RE.test(raw)) {
|
|
98
102
|
const href = PLATFORM_APP_ROOT_RE.test(raw) ? `${raw}/` : raw
|
|
99
103
|
return { mode: 'location', href }
|
|
100
104
|
}
|