@xyd-js/ask-ai-widget 0.0.0-build-340e7ed-20251012221832 → 0.0.0-build-c348243-20251013000932

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyd-js/ask-ai-widget",
3
- "version": "0.0.0-build-340e7ed-20251012221832",
3
+ "version": "0.0.0-build-c348243-20251013000932",
4
4
  "type": "module",
5
5
  "main": "dist/server.js",
6
6
  "files": [
@@ -17,8 +17,8 @@
17
17
  "express": "^4.18.2",
18
18
  "react": "^19.0.0",
19
19
  "react-dom": "^19.0.0",
20
- "@xyd-js/ask-ai": "0.0.0-build-340e7ed-20251012221832",
21
- "@xyd-js/mcp-server": "0.0.0-build-340e7ed-20251012221832"
20
+ "@xyd-js/ask-ai": "0.0.0-build-c348243-20251013000932",
21
+ "@xyd-js/mcp-server": "0.0.0-build-c348243-20251013000932"
22
22
  },
23
23
  "scripts": {
24
24
  "build": "bun run build:widget && bun run build:server && bun run build:server-standalone",
package/widget.tsx CHANGED
@@ -8,14 +8,9 @@ import { AskWidget } from "./src/Widget";
8
8
 
9
9
  // Extract data attributes
10
10
  const config = {
11
- askAiServer:
12
- currentScript?.dataset["data-server-url"] || window.__askAi?.serverUrl,
11
+ askAiServer: resolveServerUrl(currentScript),
13
12
  };
14
13
 
15
- if (!config?.askAiServer) {
16
- config.askAiServer = "http://localhost:3500";
17
- }
18
-
19
14
  // Create a container div and append it to body
20
15
  const container = document.createElement("div");
21
16
  container.id = "xyd-ask-ai-widget";
@@ -31,3 +26,29 @@ import { AskWidget } from "./src/Widget";
31
26
  />
32
27
  );
33
28
  })();
29
+
30
+ // Function to resolve server URL with fallback logic
31
+ function resolveServerUrl(currentScript: HTMLScriptElement): string {
32
+ // Priority 1: data-server-url attribute
33
+ if (currentScript?.dataset["serverUrl"]) {
34
+ return currentScript.dataset["serverUrl"];
35
+ }
36
+
37
+ // Priority 2: window.__askAi?.serverUrl
38
+ if (window.__askAi?.serverUrl) {
39
+ return window.__askAi.serverUrl;
40
+ }
41
+
42
+ // Priority 3: Extract from current script's src
43
+ if (currentScript?.src) {
44
+ try {
45
+ const url = new URL(currentScript.src);
46
+ return `${url.protocol}//${url.hostname}${url.port ? `:${url.port}` : ''}`;
47
+ } catch (error) {
48
+ console.warn("Failed to parse script src URL:", error);
49
+ }
50
+ }
51
+
52
+ // Priority 4: Default fallback
53
+ return "http://localhost:3500";
54
+ }