zywlagent 0.1.0
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/README.md +39 -0
- package/dist/chunks/index-CRD1Z7Xy.js +13972 -0
- package/dist/gis-agent.js +71 -0
- package/package.json +32 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
const o = /* @__PURE__ */ new WeakMap();
|
|
2
|
+
function v({
|
|
3
|
+
mapContainerId: g = "myMap",
|
|
4
|
+
buttonId: s = `${g}-MapEngineAIAgent`,
|
|
5
|
+
style: m,
|
|
6
|
+
onEvent: y,
|
|
7
|
+
platform: f,
|
|
8
|
+
GIS_AGENT_PLATFORM_URL: a,
|
|
9
|
+
onError: u
|
|
10
|
+
} = {}) {
|
|
11
|
+
if (typeof s != "string" || !s.trim())
|
|
12
|
+
throw new TypeError("buttonId 必须是非空的元素 ID,不需要带 #。");
|
|
13
|
+
let h = f;
|
|
14
|
+
if (a !== void 0) {
|
|
15
|
+
let e;
|
|
16
|
+
try {
|
|
17
|
+
e = new URL(a);
|
|
18
|
+
} catch {
|
|
19
|
+
throw new TypeError("GIS_AGENT_PLATFORM_URL 必须是完整服务地址,例如 http://服务器IP:8135。");
|
|
20
|
+
}
|
|
21
|
+
if (typeof a != "string" || !["http:", "https:"].includes(e.protocol) || e.username || e.password || e.search || e.hash || e.pathname.replace(/\/+$/, "") !== "")
|
|
22
|
+
throw new TypeError("GIS_AGENT_PLATFORM_URL 只填写 HTTP(S) 服务地址和端口,不要包含 /platform、查询参数或账号密码。");
|
|
23
|
+
h = { ...f, baseUrl: `${e.origin}/platform` };
|
|
24
|
+
}
|
|
25
|
+
let r = !1, l, t, d;
|
|
26
|
+
const c = (e = t) => {
|
|
27
|
+
if (!e) return;
|
|
28
|
+
const n = o.get(e);
|
|
29
|
+
n && (n.destroyed = !0, e.removeEventListener("click", n.onClick), n.handle && n.handle.destroy(), o.delete(e)), e === t && (t = void 0, d = void 0);
|
|
30
|
+
}, w = (e) => {
|
|
31
|
+
if (r || !e || o.has(e)) return;
|
|
32
|
+
const n = {
|
|
33
|
+
destroyed: !1,
|
|
34
|
+
handle: void 0,
|
|
35
|
+
loading: void 0,
|
|
36
|
+
onClick: void 0
|
|
37
|
+
};
|
|
38
|
+
n.onClick = (E) => {
|
|
39
|
+
if (E.stopPropagation(), !n.destroyed) {
|
|
40
|
+
if (n.handle) {
|
|
41
|
+
n.handle.toggle();
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
n.loading || (n.loading = import("./chunks/index-CRD1Z7Xy.js").then(({ mountAgentChat: i }) => {
|
|
45
|
+
if (!n.destroyed)
|
|
46
|
+
return n.handle = i(document.body, {
|
|
47
|
+
anchorElement: e,
|
|
48
|
+
initialOpen: !0,
|
|
49
|
+
title: "智能助手",
|
|
50
|
+
onEvent: y,
|
|
51
|
+
platform: h,
|
|
52
|
+
style: m,
|
|
53
|
+
onError: u
|
|
54
|
+
}), n.handle;
|
|
55
|
+
}).catch((i) => {
|
|
56
|
+
n.loading = void 0, console.error("智能体对话框加载失败。", i), u?.({ code: "AGENT_LOAD_FAILED", message: i instanceof Error ? i.message : String(i) });
|
|
57
|
+
}));
|
|
58
|
+
}
|
|
59
|
+
}, e.addEventListener("click", n.onClick), o.set(e, n), t = e, d = n;
|
|
60
|
+
}, p = () => {
|
|
61
|
+
if (r) return;
|
|
62
|
+
const e = document.getElementById(s);
|
|
63
|
+
e !== t && (t && !t.isConnected && c(t), e && w(e)), t && !t.isConnected && c(t);
|
|
64
|
+
};
|
|
65
|
+
return p(), l = new MutationObserver(p), l.observe(document.body, { childList: !0, subtree: !0 }), () => {
|
|
66
|
+
r || (r = !0, l?.disconnect(), d && (d.destroyed = !0), c(t));
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
export {
|
|
70
|
+
v as mountCallerAgentChat
|
|
71
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "zywlagent",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "可独立接入 GIS 或业务页面的 Platform Agent 聊天组件",
|
|
5
|
+
"private": false,
|
|
6
|
+
"type": "module",
|
|
7
|
+
"module": "./dist/gis-agent.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/gis-agent.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=22.13.0"
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"dev": "vite --host 127.0.0.1 --port 5188 --strictPort",
|
|
21
|
+
"build": "vite build",
|
|
22
|
+
"test": "node scripts/test-platform-client.mjs",
|
|
23
|
+
"pack": "npm run build && npm pack"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@vitejs/plugin-react": "5.2.0",
|
|
27
|
+
"vite": "7.3.6",
|
|
28
|
+
"react": "19.2.8",
|
|
29
|
+
"react-dom": "19.2.8",
|
|
30
|
+
"lucide-react": "0.577.0"
|
|
31
|
+
}
|
|
32
|
+
}
|