dsh-magpie-connect 0.4.1 → 0.4.2
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/dsh.plugin.json +1 -1
- package/lib/client.js +34 -8
- package/lib/types/client/load-retry.d.ts +39 -0
- package/package.json +1 -1
package/dsh.plugin.json
CHANGED
package/lib/client.js
CHANGED
|
@@ -558,9 +558,16 @@ function createWriteQueue(write, onSettled) {
|
|
|
558
558
|
};
|
|
559
559
|
}
|
|
560
560
|
|
|
561
|
+
// src/client/load-retry.ts
|
|
562
|
+
var PENDING_RETRY_DELAY_MS = 1500;
|
|
563
|
+
var PENDING_RETRY_LIMIT = 6;
|
|
564
|
+
function shouldRetryPending(snapshot2, attempts, limit = PENDING_RETRY_LIMIT) {
|
|
565
|
+
return snapshot2?.status === "pending" && attempts < limit;
|
|
566
|
+
}
|
|
567
|
+
|
|
561
568
|
// src/client/page.tsx
|
|
562
569
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
563
|
-
var PLUGIN_VERSION = "0.4.
|
|
570
|
+
var PLUGIN_VERSION = "0.4.2";
|
|
564
571
|
var css2 = {
|
|
565
572
|
section: { display: "flex", flexDirection: "column", gap: 16, maxWidth: 780, paddingBottom: 32 },
|
|
566
573
|
title: { margin: 0, fontSize: 22, lineHeight: "30px", fontWeight: 600, color: "var(--dsw-alias-label-primary)" },
|
|
@@ -618,6 +625,7 @@ function MagpieSettings() {
|
|
|
618
625
|
const [modelsStatus, setModelsStatus] = (0, import_react3.useState)("idle");
|
|
619
626
|
const [modelsError, setModelsError] = (0, import_react3.useState)(void 0);
|
|
620
627
|
const [loaded, setLoaded] = (0, import_react3.useState)(false);
|
|
628
|
+
const credentialsDirty = (0, import_react3.useRef)(false);
|
|
621
629
|
const modelsQueue = (0, import_react3.useRef)(
|
|
622
630
|
createWriteQueue((next) => saveEnabledModels(next), (outcome) => {
|
|
623
631
|
if (outcome.ok) {
|
|
@@ -633,6 +641,16 @@ function MagpieSettings() {
|
|
|
633
641
|
let alive = true;
|
|
634
642
|
let retry;
|
|
635
643
|
let attempts = 0;
|
|
644
|
+
const rereadModels = async () => {
|
|
645
|
+
const value = await request("/api/magpie-models");
|
|
646
|
+
if (!alive) return;
|
|
647
|
+
setModels(value.models ?? []);
|
|
648
|
+
if (shouldRetryPending(value.snapshot, attempts)) {
|
|
649
|
+
attempts += 1;
|
|
650
|
+
retry = setTimeout(() => void rereadModels().catch(() => {
|
|
651
|
+
}), PENDING_RETRY_DELAY_MS);
|
|
652
|
+
}
|
|
653
|
+
};
|
|
636
654
|
const load = async () => {
|
|
637
655
|
const [settingsValue, modelsValue] = await Promise.all([
|
|
638
656
|
request("/api/magpie-settings"),
|
|
@@ -642,15 +660,17 @@ function MagpieSettings() {
|
|
|
642
660
|
const settings = settingsValue;
|
|
643
661
|
const listed = modelsValue.models ?? [];
|
|
644
662
|
const snapshot2 = modelsValue.snapshot;
|
|
645
|
-
|
|
646
|
-
|
|
663
|
+
if (!credentialsDirty.current) {
|
|
664
|
+
setBaseUrl(settings.baseUrl ?? "");
|
|
665
|
+
setApiKey(settings.apiKey ?? "");
|
|
666
|
+
}
|
|
647
667
|
setEnabled(settings.enabledModels);
|
|
648
668
|
setModels(listed);
|
|
649
669
|
setLoaded(true);
|
|
650
|
-
if (snapshot2
|
|
670
|
+
if (shouldRetryPending(snapshot2, attempts)) {
|
|
651
671
|
attempts += 1;
|
|
652
|
-
retry = setTimeout(() => void
|
|
653
|
-
}),
|
|
672
|
+
retry = setTimeout(() => void rereadModels().catch(() => {
|
|
673
|
+
}), PENDING_RETRY_DELAY_MS);
|
|
654
674
|
}
|
|
655
675
|
};
|
|
656
676
|
void load().catch((cause) => {
|
|
@@ -722,11 +742,17 @@ function MagpieSettings() {
|
|
|
722
742
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { style: css2.hint, children: text("requiredNote") }),
|
|
723
743
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: css2.field, children: [
|
|
724
744
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { style: css2.label, children: text("baseUrl") }),
|
|
725
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_dsh_client_ui_primitives2.Input, { value: baseUrl, placeholder: text("baseUrlPlaceholder"), disabled: working, onChange: (event) =>
|
|
745
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_dsh_client_ui_primitives2.Input, { value: baseUrl, placeholder: text("baseUrlPlaceholder"), disabled: working, onChange: (event) => {
|
|
746
|
+
credentialsDirty.current = true;
|
|
747
|
+
setBaseUrl(event.currentTarget.value);
|
|
748
|
+
} })
|
|
726
749
|
] }),
|
|
727
750
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: css2.field, children: [
|
|
728
751
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { style: css2.label, children: text("apiKey") }),
|
|
729
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_dsh_client_ui_primitives2.Input, { type: "password", value: apiKey, placeholder: text("apiKeyPlaceholder"), disabled: working, onChange: (event) =>
|
|
752
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_dsh_client_ui_primitives2.Input, { type: "password", value: apiKey, placeholder: text("apiKeyPlaceholder"), disabled: working, onChange: (event) => {
|
|
753
|
+
credentialsDirty.current = true;
|
|
754
|
+
setApiKey(event.currentTarget.value);
|
|
755
|
+
} })
|
|
730
756
|
] }),
|
|
731
757
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: css2.row, children: [
|
|
732
758
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_dsh_client_ui_primitives2.Button, { variant: "primary", disabled: working || incomplete, onClick: () => void save(), children: busy === "saving" ? text("saving") : text("save") }),
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Policy for the settings page's "catalog still warming up" re-read.
|
|
3
|
+
*
|
|
4
|
+
* The Host answers `GET /api/magpie-models` before its catalog has warmed, with
|
|
5
|
+
* a `pending` snapshot. The page re-reads until it turns `ready`, but the first
|
|
6
|
+
* version retried a *full* load (settings **and** models) every second for 20
|
|
7
|
+
* rounds. Each round unconditionally wrote `baseUrl`/`apiKey` back from the
|
|
8
|
+
* server, so a user editing the URL had their keystrokes overwritten about once
|
|
9
|
+
* a second — the field looked like it "auto-typed" the stored value. Extracted
|
|
10
|
+
* here so the policy is testable and the page cannot regress it.
|
|
11
|
+
*/
|
|
12
|
+
/** Status emitted by the catalog while no live directory has landed yet. */
|
|
13
|
+
export type SnapshotStatus = {
|
|
14
|
+
status?: string;
|
|
15
|
+
} | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Gap between pending re-reads. Long enough that a human typing is not fighting
|
|
18
|
+
* the loop, short enough that a local warm-up (usually well under a second) is
|
|
19
|
+
* caught on the first or second try.
|
|
20
|
+
*/
|
|
21
|
+
export declare const PENDING_RETRY_DELAY_MS = 1500;
|
|
22
|
+
/**
|
|
23
|
+
* Cap on re-reads. 20 rounds (~20 s) was both noisy and pointless: a gateway
|
|
24
|
+
* that is genuinely unreachable does not become reachable by polling, and the
|
|
25
|
+
* directory has its own refresh loop. Six rounds span ~9 s — plenty for a cold
|
|
26
|
+
* local catalog, far short of twenty seconds of churn.
|
|
27
|
+
*/
|
|
28
|
+
export declare const PENDING_RETRY_LIMIT = 6;
|
|
29
|
+
/**
|
|
30
|
+
* Whether a pending snapshot still warrants another read.
|
|
31
|
+
*
|
|
32
|
+
* Only `pending` retries: `ready`/`stale`/`error` are terminal — `stale` means a
|
|
33
|
+
* directory exists (re-reading would not change it), and `error` needs a user
|
|
34
|
+
* action (fix the URL/key), not a spin.
|
|
35
|
+
* @param snapshot - the catalog snapshot from the last models read.
|
|
36
|
+
* @param attempts - how many retries have already been scheduled.
|
|
37
|
+
* @param limit - maximum retries; defaults to {@link PENDING_RETRY_LIMIT}.
|
|
38
|
+
*/
|
|
39
|
+
export declare function shouldRetryPending(snapshot: SnapshotStatus, attempts: number, limit?: number): boolean;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-magpie-connect",
|
|
3
3
|
"description": "Magpie gateway models for DeepSeek Harness (DSH): native dsh-llm adapter plugin with image + responses + thinking levels.",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.2",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"repository": {
|