@genkaku/dsh-worker-plugin 0.1.15 → 0.1.16
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/lib/client.js +43 -20
- package/package.json +3 -3
package/lib/client.js
CHANGED
|
@@ -38,10 +38,8 @@ var genkaku_mark_default = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAK4AAA
|
|
|
38
38
|
// src/client/index.tsx
|
|
39
39
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
40
40
|
var PANEL_ID = "genkaku-worker";
|
|
41
|
-
var
|
|
42
|
-
var
|
|
43
|
-
var OLLAMA_URL = `${ORIGIN}/genkaku/ollama`;
|
|
44
|
-
var DASHBOARD_URL = `${ORIGIN}/genkaku`;
|
|
41
|
+
var CANDIDATE_PORTS = [47821, 47822, 47823, 47824, 47825, 47826];
|
|
42
|
+
var originOf = (port) => `http://127.0.0.1:${port}`;
|
|
45
43
|
var inject = ["slots"];
|
|
46
44
|
var ZH = typeof navigator !== "undefined" && /^zh/i.test(navigator.language);
|
|
47
45
|
var t = (en, zh) => ZH ? zh : en;
|
|
@@ -162,24 +160,49 @@ function Page() {
|
|
|
162
160
|
const [pullModel, setPullModel] = (0, import_react.useState)("");
|
|
163
161
|
const [pull, setPull] = (0, import_react.useState)(null);
|
|
164
162
|
const seeded = (0, import_react.useRef)(false);
|
|
165
|
-
const
|
|
163
|
+
const [origin, setOrigin] = (0, import_react.useState)(originOf(CANDIDATE_PORTS[0]));
|
|
164
|
+
const originRef = (0, import_react.useRef)(origin);
|
|
165
|
+
originRef.current = origin;
|
|
166
|
+
const probe = (0, import_react.useCallback)(async (base) => {
|
|
166
167
|
try {
|
|
167
|
-
const res = await fetch(
|
|
168
|
-
if (!res.ok)
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
seeded.current = true;
|
|
174
|
-
setDraft(seedDraft(next));
|
|
175
|
-
}
|
|
176
|
-
} catch (e) {
|
|
177
|
-
setError(e instanceof Error ? e.message : String(e));
|
|
168
|
+
const res = await fetch(`${base}/genkaku/status`, { cache: "no-store", signal: AbortSignal.timeout(2500) });
|
|
169
|
+
if (!res.ok) return null;
|
|
170
|
+
const doc = await res.json();
|
|
171
|
+
return doc.role === "user" ? null : doc;
|
|
172
|
+
} catch {
|
|
173
|
+
return null;
|
|
178
174
|
}
|
|
179
175
|
}, []);
|
|
176
|
+
const loadStatus = (0, import_react.useCallback)(async () => {
|
|
177
|
+
let base = originRef.current;
|
|
178
|
+
let next = await probe(base);
|
|
179
|
+
if (next == null) {
|
|
180
|
+
for (const port of CANDIDATE_PORTS) {
|
|
181
|
+
const candidate = originOf(port);
|
|
182
|
+
if (candidate === base) continue;
|
|
183
|
+
const doc = await probe(candidate);
|
|
184
|
+
if (doc != null) {
|
|
185
|
+
base = candidate;
|
|
186
|
+
next = doc;
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
if (next == null) {
|
|
192
|
+
setError(t("Worker status unreachable on 47821\u201347826.", "47821\u201347826 \u4E0A\u90FD\u627E\u4E0D\u5230 worker \u72C0\u614B\u670D\u52D9\u3002"));
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
if (base !== originRef.current) setOrigin(base);
|
|
196
|
+
setStatus(next);
|
|
197
|
+
setError(null);
|
|
198
|
+
if (!seeded.current) {
|
|
199
|
+
seeded.current = true;
|
|
200
|
+
setDraft(seedDraft(next));
|
|
201
|
+
}
|
|
202
|
+
}, [probe]);
|
|
180
203
|
const loadOllama = (0, import_react.useCallback)(async () => {
|
|
181
204
|
try {
|
|
182
|
-
const res = await fetch(
|
|
205
|
+
const res = await fetch(`${originRef.current}/genkaku/ollama`, { cache: "no-store" });
|
|
183
206
|
if (!res.ok) throw new Error(`ollama ${res.status}`);
|
|
184
207
|
setOllama(await res.json());
|
|
185
208
|
} catch {
|
|
@@ -200,7 +223,7 @@ function Page() {
|
|
|
200
223
|
};
|
|
201
224
|
}, [loadStatus, loadOllama]);
|
|
202
225
|
const post = (0, import_react.useCallback)(async (path, body) => {
|
|
203
|
-
const res = await fetch(`${
|
|
226
|
+
const res = await fetch(`${originRef.current}${path}`, {
|
|
204
227
|
method: "POST",
|
|
205
228
|
headers: { "content-type": "application/json" },
|
|
206
229
|
body: JSON.stringify(body)
|
|
@@ -229,7 +252,7 @@ function Page() {
|
|
|
229
252
|
setNotice(null);
|
|
230
253
|
setPull({ status: t("starting", "\u958B\u59CB\u4E0B\u8F09") });
|
|
231
254
|
try {
|
|
232
|
-
const res = await fetch(`${
|
|
255
|
+
const res = await fetch(`${originRef.current}/genkaku/ollama/pull`, {
|
|
233
256
|
method: "POST",
|
|
234
257
|
headers: { "content-type": "application/json" },
|
|
235
258
|
body: JSON.stringify({ model })
|
|
@@ -551,7 +574,7 @@ function Page() {
|
|
|
551
574
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: dim, children: t("Addresses", "\u4F4D\u5740\u6578") }),
|
|
552
575
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: (status.peerAddrs ?? []).length })
|
|
553
576
|
] }),
|
|
554
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { ...row, justifyContent: "flex-start" }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", { href:
|
|
577
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { ...row, justifyContent: "flex-start" }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", { href: `${origin}/genkaku`, target: "_blank", rel: "noreferrer", style: { fontSize: 12 }, children: t("Open the full dashboard", "\u958B\u555F\u5B8C\u6574\u63A7\u5236\u53F0") }) })
|
|
555
578
|
] })
|
|
556
579
|
] });
|
|
557
580
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@genkaku/dsh-worker-plugin",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.16",
|
|
4
4
|
"description": "Share this machine's Ollama models on the GenKaKu network",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@genkaku/
|
|
42
|
-
"@genkaku/
|
|
41
|
+
"@genkaku/dsh-runtime": "0.1.15",
|
|
42
|
+
"@genkaku/protocol": "0.1.11"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"@deepseek-ai/cordis": "^4.1.0"
|