dsh-skill-hub 0.3.23 → 0.3.25

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/CONTRIBUTING.md CHANGED
@@ -39,7 +39,7 @@ src/client/locales/ dictionaries by view (common/skills/market/sources/detai
39
39
  ```bash
40
40
  npm install
41
41
  npm run typecheck # tsc --noEmit
42
- npm test # vitest (288 tests across 14 suites)
42
+ npm test # vitest (294 tests across 16 suites)
43
43
  npm run build # tsc declarations + tsdown bundles (lib/index.js + lib/client.js)
44
44
  ```
45
45
 
package/README.md CHANGED
@@ -108,7 +108,7 @@ Host uses only `ctx.skills.snapshot/get`, `ctx.webServer.register`, `ctx.systemP
108
108
 
109
109
  ```bash
110
110
  npm run typecheck # tsc --noEmit
111
- npm test # 288 tests, 14 suites
111
+ npm test # 294 tests, 16 suites
112
112
  npm run build # tsc + tsdown → lib/index.js + lib/client.js
113
113
  ```
114
114
 
package/README.zh.md CHANGED
@@ -108,7 +108,7 @@ GitHub 仓库 ──扫描/导入──▶ ~/.dsh/skills
108
108
 
109
109
  ```bash
110
110
  npm run typecheck # tsc --noEmit
111
- npm test # 288 tests, 14 suites
111
+ npm test # 294 tests, 16 suites
112
112
  npm run build # tsc + tsdown → lib/index.js + lib/client.js
113
113
  ```
114
114
 
package/lib/client.js CHANGED
@@ -96,6 +96,36 @@ window.__ModuleLoader__.load({
96
96
  return body;
97
97
  }
98
98
  /**
99
+ * Resolve one route path against the page's base.
100
+ *
101
+ * Every route in this family is registered on the server as a root-absolute
102
+ * path (`/api/skill-hub/...`), which is right there but wrong in a browser
103
+ * behind a reverse proxy that owns a path prefix: the page loads from
104
+ * `https://host/app/dsh/` while a root-absolute URL drops the prefix entirely,
105
+ * so the gateway answers 404 HTML and `readJson` reports "invalid JSON
106
+ * response" (issue #18). Resolving against `document.baseURI` is the host's own
107
+ * convention — `dsh-client-connection` opens its browser carrier with
108
+ * `new URL(path.slice(1), document.baseURI)` — so a root deployment resolves to
109
+ * exactly the same absolute path while a prefixed one keeps its prefix, and the
110
+ * gateway strips it before forwarding: the server still receives
111
+ * `/api/skill-hub/*`.
112
+ *
113
+ * `SKILL_HUB_API_ROOT` must stay absolute (the same constant registers the
114
+ * routes on the server), which is why the prefix is applied here at the single
115
+ * outbound boundary rather than in the constants.
116
+ * @param path - one route path, root-absolute unless it is already a full URL.
117
+ * @returns the URL to fetch.
118
+ */
119
+ function resolveApiUrl(path) {
120
+ if (!path.startsWith("/")) return path;
121
+ if (typeof document === "undefined") return path;
122
+ try {
123
+ return new URL(path.slice(1), document.baseURI).href;
124
+ } catch {
125
+ return path;
126
+ }
127
+ }
128
+ /**
99
129
  * Fetch with a hard timeout: a hung connection (proxy, stalled keep-alive,
100
130
  * host wedged) must never leave the panel stuck on "loading" forever — it
101
131
  * fails fast and surfaces the error banner instead.
@@ -104,7 +134,7 @@ window.__ModuleLoader__.load({
104
134
  const controller = new AbortController();
105
135
  const timer = setTimeout(() => controller.abort(), ms);
106
136
  try {
107
- return await fetch(input, {
137
+ return await fetch(typeof input === "string" ? resolveApiUrl(input) : input, {
108
138
  ...init,
109
139
  signal: controller.signal
110
140
  });