@dan-ai-studio/dshopencodego 0.1.22 → 0.1.23
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 +303 -14
- package/lib/index.js +146 -6
- package/lib/types/conversion/stream.js +6 -0
- package/lib/types/index.js +3 -0
- package/lib/types/remotes.js +2 -1
- package/lib/types/update/check.d.ts +74 -0
- package/lib/types/update/check.js +132 -0
- package/lib/types/update/contract.d.ts +23 -0
- package/lib/types/update/contract.js +52 -0
- package/lib/types/update/index.d.ts +12 -0
- package/lib/types/update/index.js +10 -0
- package/lib/types/update/service.d.ts +28 -0
- package/lib/types/update/service.js +28 -0
- package/lib/types/update/version.d.ts +14 -0
- package/lib/types/update/version.js +16 -0
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -152,6 +152,44 @@ var catalogRemote = {
|
|
|
152
152
|
]
|
|
153
153
|
};
|
|
154
154
|
|
|
155
|
+
// src/update/contract.ts
|
|
156
|
+
function parseUpdateStatus(value) {
|
|
157
|
+
if (value === null || typeof value !== "object") throw new Error("invalid update reading");
|
|
158
|
+
const row = value;
|
|
159
|
+
if (typeof row["current"] !== "string") throw new Error("invalid update reading");
|
|
160
|
+
if (row["latest"] !== void 0 && typeof row["latest"] !== "string") throw new Error("invalid update reading");
|
|
161
|
+
if (typeof row["available"] !== "boolean") throw new Error("invalid update reading");
|
|
162
|
+
if (typeof row["checkedAt"] !== "number" || !Number.isFinite(row["checkedAt"])) {
|
|
163
|
+
throw new Error("invalid update reading");
|
|
164
|
+
}
|
|
165
|
+
return {
|
|
166
|
+
current: row["current"],
|
|
167
|
+
latest: typeof row["latest"] === "string" ? row["latest"] : void 0,
|
|
168
|
+
available: row["available"],
|
|
169
|
+
checkedAt: row["checkedAt"]
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
var codec2 = (typeSymbol, parse) => ({
|
|
173
|
+
mode: "strict",
|
|
174
|
+
typeSymbol,
|
|
175
|
+
schema: { parse },
|
|
176
|
+
create: () => ({ parse })
|
|
177
|
+
});
|
|
178
|
+
var updateRemote = {
|
|
179
|
+
package: "@dan-ai-studio/dshopencodego",
|
|
180
|
+
descriptors: [
|
|
181
|
+
{
|
|
182
|
+
id: "@dan-ai-studio/dshopencodego#opencodeGoUpdate/readUpdate",
|
|
183
|
+
service: "opencodeGoUpdate",
|
|
184
|
+
namespace: "opencodeGoUpdate",
|
|
185
|
+
method: "readUpdate",
|
|
186
|
+
invocation: { kind: "direct" },
|
|
187
|
+
parameters: [],
|
|
188
|
+
result: codec2("@dan-ai-studio/dshopencodego#UpdateStatus", parseUpdateStatus)
|
|
189
|
+
}
|
|
190
|
+
]
|
|
191
|
+
};
|
|
192
|
+
|
|
155
193
|
// src/usage/contract.ts
|
|
156
194
|
function parseWindow(value, key) {
|
|
157
195
|
if (value === null || typeof value !== "object") throw new Error(`invalid usage window "${key}"`);
|
|
@@ -206,7 +244,7 @@ function parseGoMeter(value) {
|
|
|
206
244
|
})
|
|
207
245
|
};
|
|
208
246
|
}
|
|
209
|
-
var
|
|
247
|
+
var codec3 = (typeSymbol, parse) => ({
|
|
210
248
|
mode: "strict",
|
|
211
249
|
typeSymbol,
|
|
212
250
|
schema: { parse },
|
|
@@ -222,7 +260,7 @@ var usageRemote = {
|
|
|
222
260
|
method: "readWindows",
|
|
223
261
|
invocation: { kind: "direct" },
|
|
224
262
|
parameters: [],
|
|
225
|
-
result:
|
|
263
|
+
result: codec3("@dan-ai-studio/dshopencodego#GoUsageWindows", parseUsageWindows)
|
|
226
264
|
},
|
|
227
265
|
{
|
|
228
266
|
id: "@dan-ai-studio/dshopencodego#opencodeGoUsage/readMeter",
|
|
@@ -231,7 +269,7 @@ var usageRemote = {
|
|
|
231
269
|
method: "readMeter",
|
|
232
270
|
invocation: { kind: "direct" },
|
|
233
271
|
parameters: [],
|
|
234
|
-
result:
|
|
272
|
+
result: codec3("@dan-ai-studio/dshopencodego#GoMeter", parseGoMeter)
|
|
235
273
|
}
|
|
236
274
|
]
|
|
237
275
|
};
|
|
@@ -302,7 +340,24 @@ var en = {
|
|
|
302
340
|
usageTokensUnit: "tokens",
|
|
303
341
|
usageCached: "cached read",
|
|
304
342
|
usageLocalHint: "The gateway publishes quota percentages only; token counts are what this process actually spent.",
|
|
305
|
-
usageLoading: "Loading\u2026"
|
|
343
|
+
usageLoading: "Loading\u2026",
|
|
344
|
+
updateTitle: "Plugin update",
|
|
345
|
+
updateChecking: "Checking for updates\u2026",
|
|
346
|
+
updateAvailable: "New version available:",
|
|
347
|
+
updateCurrent: "current",
|
|
348
|
+
updateNow: "Update now",
|
|
349
|
+
updateNotes: "Release notes",
|
|
350
|
+
updateRecheck: "Check again",
|
|
351
|
+
updateConfirmHint: "This removes the running version first, then installs",
|
|
352
|
+
updateConfirm: "Confirm update",
|
|
353
|
+
updateCancel: "Cancel",
|
|
354
|
+
updateApplying: "Updating\u2026 (removing the old version, then installing the new one)",
|
|
355
|
+
updateDone: "Updated to",
|
|
356
|
+
updateRestart: "Restart DSH to finish applying the update.",
|
|
357
|
+
updateFailed: "Update failed:",
|
|
358
|
+
updateStopProfile: "The running version cannot be removed without a restart; restart DSH first, then retry.",
|
|
359
|
+
updateIncompatible: "The new version is incompatible with this DSH build; finish the update from the plugin manager page (a version exemption needs your explicit approval).",
|
|
360
|
+
updatePendingBuilds: "Installation needs build-script approval; approve it on the plugin manager page, then retry."
|
|
306
361
|
};
|
|
307
362
|
var zh = {
|
|
308
363
|
nav: "OpenCode Go",
|
|
@@ -369,12 +424,34 @@ var zh = {
|
|
|
369
424
|
usageTokensUnit: "tokens",
|
|
370
425
|
usageCached: "\u7F13\u5B58\u8BFB\u53D6",
|
|
371
426
|
usageLocalHint: "\u7F51\u5173\u53EA\u516C\u5E03\u989D\u5EA6\u767E\u5206\u6BD4\uFF1Btoken \u6570\u4E3A\u672C\u8FDB\u7A0B\u5B9E\u9645\u6D88\u8017\u3002",
|
|
372
|
-
usageLoading: "\u52A0\u8F7D\u4E2D\u2026"
|
|
427
|
+
usageLoading: "\u52A0\u8F7D\u4E2D\u2026",
|
|
428
|
+
updateTitle: "\u63D2\u4EF6\u66F4\u65B0",
|
|
429
|
+
updateChecking: "\u6B63\u5728\u68C0\u67E5\u66F4\u65B0\u2026",
|
|
430
|
+
updateAvailable: "\u53D1\u73B0\u65B0\u7248\u672C\uFF1A",
|
|
431
|
+
updateCurrent: "\u5F53\u524D",
|
|
432
|
+
updateNow: "\u7ACB\u5373\u66F4\u65B0",
|
|
433
|
+
updateNotes: "\u66F4\u65B0\u8BF4\u660E",
|
|
434
|
+
updateRecheck: "\u91CD\u65B0\u68C0\u67E5",
|
|
435
|
+
updateConfirmHint: "\u5C06\u5148\u5378\u8F7D\u5F53\u524D\u8FD0\u884C\u7248\u672C\uFF0C\u518D\u5B89\u88C5",
|
|
436
|
+
updateConfirm: "\u786E\u8BA4\u66F4\u65B0",
|
|
437
|
+
updateCancel: "\u53D6\u6D88",
|
|
438
|
+
updateApplying: "\u66F4\u65B0\u4E2D\u2026\uFF08\u5148\u5378\u8F7D\u65E7\u7248\uFF0C\u518D\u5B89\u88C5\u65B0\u7248\uFF09",
|
|
439
|
+
updateDone: "\u5DF2\u66F4\u65B0\u5230",
|
|
440
|
+
updateRestart: "\u8BF7\u91CD\u542F DSH \u4EE5\u5B8C\u6210\u66F4\u65B0\u3002",
|
|
441
|
+
updateFailed: "\u66F4\u65B0\u5931\u8D25\uFF1A",
|
|
442
|
+
updateStopProfile: "\u8FD0\u884C\u4E2D\u7684\u7248\u672C\u9700\u91CD\u542F\u540E\u624D\u80FD\u79FB\u9664\uFF1B\u8BF7\u5148\u91CD\u542F DSH \u518D\u91CD\u8BD5\u3002",
|
|
443
|
+
updateIncompatible: "\u65B0\u7248\u672C\u4E0E\u5F53\u524D DSH \u4E0D\u517C\u5BB9\uFF0C\u8BF7\u524D\u5F80\u63D2\u4EF6\u7BA1\u7406\u9875\u5B8C\u6210\u66F4\u65B0\uFF08\u7248\u672C\u8C41\u514D\u9700\u660E\u786E\u6279\u51C6\uFF09\u3002",
|
|
444
|
+
updatePendingBuilds: "\u5B89\u88C5\u9700\u8981\u6279\u51C6\u6784\u5EFA\u811A\u672C\uFF1B\u8BF7\u524D\u5F80\u63D2\u4EF6\u7BA1\u7406\u9875\u6279\u51C6\u540E\u518D\u91CD\u8BD5\u3002"
|
|
373
445
|
};
|
|
374
446
|
|
|
375
447
|
// src/client/Section.tsx
|
|
376
448
|
var import_react = require("react");
|
|
377
449
|
|
|
450
|
+
// src/update/check.ts
|
|
451
|
+
var PACKAGE_NAME = "@dan-ai-studio/dshopencodego";
|
|
452
|
+
var REGISTRY_LATEST_URL = `https://registry.npmjs.org/${encodeURIComponent(PACKAGE_NAME)}/latest`;
|
|
453
|
+
var CHECK_CACHE_MS = 6 * 60 * 60 * 1e3;
|
|
454
|
+
|
|
378
455
|
// src/go-limits.ts
|
|
379
456
|
var SEED_TRANSCRIBED = "2026-09-25";
|
|
380
457
|
function monthlyRequestsRank(quota) {
|
|
@@ -453,16 +530,16 @@ function inputModalityLabels(model, t) {
|
|
|
453
530
|
return (model.inputModalities ?? []).map((modality) => t(MODALITY_KEYS[modality]));
|
|
454
531
|
}
|
|
455
532
|
|
|
456
|
-
// plugin-css
|
|
533
|
+
// plugin-css:/home/runner/work/dshopencodego/dshopencodego/src/client/section.module.css
|
|
457
534
|
var id = "@dan-ai-studio/dshopencodego/section.module.css";
|
|
458
535
|
if (!document.querySelector("style[data-plugin-css=" + JSON.stringify(id) + "]")) {
|
|
459
536
|
const style = document.createElement("style");
|
|
460
537
|
style.dataset.plugin = "@dan-ai-studio/dshopencodego";
|
|
461
538
|
style.dataset.pluginCss = id;
|
|
462
|
-
style.textContent = ".
|
|
539
|
+
style.textContent = ".d7lz0W_root{color:var(--dsw-alias-label-primary);flex-direction:column;gap:1.25rem;display:flex}.d7lz0W_title{margin:0;font-size:1.05rem}.d7lz0W_hint{color:var(--dsw-alias-label-secondary);margin:0;font-size:.8rem}.d7lz0W_warn{color:var(--dsw-alias-state-warn-primary);margin:0;font-size:.8rem}.d7lz0W_ok{color:var(--dsw-alias-state-success-primary);font-size:.8rem}.d7lz0W_block{border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-1);border-radius:.6rem;flex-direction:column;gap:.5rem;padding:.85rem;display:flex}.d7lz0W_row{flex-wrap:wrap;align-items:center;gap:.5rem;display:flex}.d7lz0W_row>strong{margin-right:auto}.d7lz0W_input{border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-base);min-width:10rem;color:var(--dsw-alias-label-primary);font:inherit;border-radius:.35rem;flex:14rem;padding:.35rem .5rem;font-size:.85rem}.d7lz0W_button{border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-primary);font:inherit;cursor:pointer;border-radius:.35rem;padding:.35rem .7rem;font-size:.8rem}.d7lz0W_button:disabled{color:var(--dsw-alias-state-idle-primary);cursor:default}.d7lz0W_number{border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-base);width:5rem;color:var(--dsw-alias-label-primary);font:inherit;border-radius:.35rem;padding:.25rem .4rem;font-size:.8rem}.d7lz0W_select{border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-base);width:auto;max-width:100%;color:var(--dsw-alias-label-primary);font:inherit;border-radius:.35rem;padding:.25rem .4rem;font-size:.8rem}.d7lz0W_list{flex-direction:column;display:flex}.d7lz0W_item{border-top:1px solid var(--dsw-alias-border-l1);align-items:flex-start;gap:.5rem;padding:.45rem .15rem;display:flex}.d7lz0W_item input[type=checkbox]{accent-color:var(--dsw-alias-brand-primary);margin-top:.15rem}.d7lz0W_itemBody{flex-direction:column;gap:.15rem;min-width:0;display:flex}.d7lz0W_itemMain{flex-wrap:wrap;align-items:baseline;gap:.6rem;display:flex}.d7lz0W_itemMeta{color:var(--dsw-alias-label-secondary);flex-wrap:wrap;gap:.75rem;font-size:.75rem;display:flex}.d7lz0W_itemModalities{color:var(--dsw-alias-label-secondary);font-size:.75rem}.d7lz0W_name{color:var(--dsw-alias-label-primary)}.d7lz0W_mono{color:var(--dsw-alias-label-secondary);font-family:ui-monospace,SFMono-Regular,Menlo,monospace}.d7lz0W_badge{color:var(--dsw-alias-brand-primary)}";
|
|
463
540
|
document.head.appendChild(style);
|
|
464
541
|
}
|
|
465
|
-
var section_default = { "
|
|
542
|
+
var section_default = { "button": "d7lz0W_button", "ok": "d7lz0W_ok", "list": "d7lz0W_list", "title": "d7lz0W_title", "root": "d7lz0W_root", "itemMeta": "d7lz0W_itemMeta", "input": "d7lz0W_input", "badge": "d7lz0W_badge", "number": "d7lz0W_number", "hint": "d7lz0W_hint", "itemMain": "d7lz0W_itemMain", "name": "d7lz0W_name", "select": "d7lz0W_select", "itemModalities": "d7lz0W_itemModalities", "block": "d7lz0W_block", "mono": "d7lz0W_mono", "item": "d7lz0W_item", "row": "d7lz0W_row", "itemBody": "d7lz0W_itemBody", "warn": "d7lz0W_warn" };
|
|
466
543
|
|
|
467
544
|
// src/client/Section.tsx
|
|
468
545
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
@@ -478,7 +555,8 @@ var INITIAL = {
|
|
|
478
555
|
settings: void 0,
|
|
479
556
|
writable: false,
|
|
480
557
|
saving: false,
|
|
481
|
-
filter: INITIAL_FILTER
|
|
558
|
+
filter: INITIAL_FILTER,
|
|
559
|
+
update: { phase: "idle", status: void 0, message: void 0 }
|
|
482
560
|
};
|
|
483
561
|
function settingsOf(value) {
|
|
484
562
|
if (value === null || typeof value !== "object") return void 0;
|
|
@@ -492,7 +570,7 @@ function settingsOf(value) {
|
|
|
492
570
|
refreshMinutes: minutes
|
|
493
571
|
};
|
|
494
572
|
}
|
|
495
|
-
var SectionController = class {
|
|
573
|
+
var SectionController = class _SectionController {
|
|
496
574
|
state = INITIAL;
|
|
497
575
|
listeners = /* @__PURE__ */ new Set();
|
|
498
576
|
services;
|
|
@@ -514,6 +592,7 @@ var SectionController = class {
|
|
|
514
592
|
}
|
|
515
593
|
void this.load(false);
|
|
516
594
|
void this.loadKey();
|
|
595
|
+
void this.checkUpdate(false);
|
|
517
596
|
}
|
|
518
597
|
subscribe = (listener) => {
|
|
519
598
|
this.listeners.add(listener);
|
|
@@ -556,6 +635,117 @@ var SectionController = class {
|
|
|
556
635
|
this.set({ keyConfigured: void 0 });
|
|
557
636
|
}
|
|
558
637
|
}
|
|
638
|
+
/**
|
|
639
|
+
* Ask the Host whether a newer release is published.
|
|
640
|
+
*
|
|
641
|
+
* The Host answers from a cached registry reading and fails silent, so an
|
|
642
|
+
* unreachable registry hides the panel instead of erroring the page. Runs
|
|
643
|
+
* once with the page and again only on explicit refresh.
|
|
644
|
+
*/
|
|
645
|
+
async checkUpdate(force) {
|
|
646
|
+
const previous = this.state.update;
|
|
647
|
+
this.set({ update: { ...previous, phase: "checking", message: void 0 } });
|
|
648
|
+
try {
|
|
649
|
+
const result = await this.services.remote.opencodeGoUpdate.readUpdate(force);
|
|
650
|
+
if (!result.ok) throw result.error;
|
|
651
|
+
const status = result.value;
|
|
652
|
+
this.set({
|
|
653
|
+
update: {
|
|
654
|
+
phase: status.available && status.latest !== void 0 ? "ready" : "idle",
|
|
655
|
+
status,
|
|
656
|
+
message: void 0
|
|
657
|
+
}
|
|
658
|
+
});
|
|
659
|
+
} catch (error) {
|
|
660
|
+
this.set({
|
|
661
|
+
update: {
|
|
662
|
+
...previous,
|
|
663
|
+
phase: previous.phase === "checking" ? "idle" : previous.phase,
|
|
664
|
+
message: error instanceof Error ? error.message : void 0
|
|
665
|
+
}
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
/** Arm the confirm step; the destructive two-step runs only from `applyUpdate`. */
|
|
670
|
+
armUpdate() {
|
|
671
|
+
if (this.state.update.phase === "ready") {
|
|
672
|
+
this.set({ update: { ...this.state.update, phase: "confirming" } });
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
/** Stand down from the confirm step without doing anything. */
|
|
676
|
+
disarmUpdate() {
|
|
677
|
+
if (this.state.update.phase === "confirming") {
|
|
678
|
+
this.set({ update: { ...this.state.update, phase: "ready" } });
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
/** Read one field off an unknown host answer without guessing its shape. */
|
|
682
|
+
static field(value, key) {
|
|
683
|
+
return value !== null && typeof value === "object" ? value[key] : void 0;
|
|
684
|
+
}
|
|
685
|
+
/**
|
|
686
|
+
* One-click update: inspect, then the host's own remove + install.
|
|
687
|
+
*
|
|
688
|
+
* This mirrors the official plugin-update button exactly — the plugin never
|
|
689
|
+
* touches its own files. `removeBundle` stops the running build first, so
|
|
690
|
+
* the install call that follows is issued by this page (which survives),
|
|
691
|
+
* not by the Host code being removed. Outcomes that need a human —
|
|
692
|
+
* incompatibility (never auto-exempted), pending build approvals, a removal
|
|
693
|
+
* that needs a restart first — surface as guidance, never as silent retries.
|
|
694
|
+
*/
|
|
695
|
+
async applyUpdate() {
|
|
696
|
+
const status = this.state.update.status;
|
|
697
|
+
const latest = status?.latest;
|
|
698
|
+
if (this.state.update.phase !== "confirming" || latest === void 0) return;
|
|
699
|
+
const manager = this.services.remote.pluginManager;
|
|
700
|
+
const spec = `${PACKAGE_NAME}@${latest}`;
|
|
701
|
+
this.set({ update: { phase: "updating", status, message: void 0 } });
|
|
702
|
+
const fail = (message) => {
|
|
703
|
+
this.set({ update: { phase: "failed", status, message } });
|
|
704
|
+
};
|
|
705
|
+
try {
|
|
706
|
+
const inspected = await manager.inspect(spec);
|
|
707
|
+
if (_SectionController.field(inspected, "bundle") === false) {
|
|
708
|
+
fail(`the registry target is not a DSH bundle: ${spec}`);
|
|
709
|
+
return;
|
|
710
|
+
}
|
|
711
|
+
} catch (error) {
|
|
712
|
+
fail(error instanceof Error ? error.message : `could not inspect ${spec}`);
|
|
713
|
+
return;
|
|
714
|
+
}
|
|
715
|
+
try {
|
|
716
|
+
const removed = await manager.removeBundle(PACKAGE_NAME);
|
|
717
|
+
if (!removed.ok) throw removed.error;
|
|
718
|
+
const stopCode = _SectionController.field(removed.value, "error");
|
|
719
|
+
const code = typeof stopCode === "object" && stopCode !== null ? _SectionController.field(stopCode, "code") : void 0;
|
|
720
|
+
if (code === "stop-profile") {
|
|
721
|
+
fail("stop-profile");
|
|
722
|
+
return;
|
|
723
|
+
}
|
|
724
|
+
} catch (error) {
|
|
725
|
+
fail(error instanceof Error ? error.message : `could not remove ${PACKAGE_NAME}`);
|
|
726
|
+
return;
|
|
727
|
+
}
|
|
728
|
+
try {
|
|
729
|
+
const installed = await manager.installBundle(spec, { saveExact: true });
|
|
730
|
+
if (!installed.ok) throw installed.error;
|
|
731
|
+
const value = installed.value ?? {};
|
|
732
|
+
if (value.error?.code === "incompatible-version") {
|
|
733
|
+
fail("incompatible-version");
|
|
734
|
+
return;
|
|
735
|
+
}
|
|
736
|
+
if (value.pendingBuilds !== void 0) {
|
|
737
|
+
fail("pending-builds");
|
|
738
|
+
return;
|
|
739
|
+
}
|
|
740
|
+
if (value.application === "restart-required") {
|
|
741
|
+
this.set({ update: { phase: "done", status, message: "restart-required" } });
|
|
742
|
+
return;
|
|
743
|
+
}
|
|
744
|
+
this.set({ update: { phase: "done", status, message: void 0 } });
|
|
745
|
+
} catch (error) {
|
|
746
|
+
fail(error instanceof Error ? error.message : `could not install ${spec}`);
|
|
747
|
+
}
|
|
748
|
+
}
|
|
559
749
|
async saveKey(value) {
|
|
560
750
|
const trimmed = value.trim();
|
|
561
751
|
if (trimmed.length === 0) return;
|
|
@@ -697,6 +887,104 @@ function quotaLabel(model, t) {
|
|
|
697
887
|
const requests = quota.monthlyRequests === "unlimited" ? t("quotaUnlimited") : `${compactCount(quota.monthlyRequests)} ${t("quotaPerMonth")}`;
|
|
698
888
|
return `${usd} \xB7 ${requests}`;
|
|
699
889
|
}
|
|
890
|
+
function UpdateBanner({ controller, t, busy, act, update }) {
|
|
891
|
+
if (update.phase === "idle") return null;
|
|
892
|
+
const status = update.status;
|
|
893
|
+
const notes = `https://www.npmjs.com/package/${encodeURIComponent(PACKAGE_NAME)}`;
|
|
894
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: section_default.block, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: section_default.row, children: [
|
|
895
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { children: t("updateTitle") }),
|
|
896
|
+
update.phase === "checking" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: section_default.hint, children: t("updateChecking") }),
|
|
897
|
+
update.phase === "ready" && status?.latest !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
898
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: section_default.hint, children: `${t("updateAvailable")} ${status.latest} (${t("updateCurrent")} ${status.current})` }),
|
|
899
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
900
|
+
"button",
|
|
901
|
+
{
|
|
902
|
+
type: "button",
|
|
903
|
+
className: section_default.button,
|
|
904
|
+
disabled: busy,
|
|
905
|
+
onClick: () => {
|
|
906
|
+
controller.armUpdate();
|
|
907
|
+
},
|
|
908
|
+
children: t("updateNow")
|
|
909
|
+
}
|
|
910
|
+
),
|
|
911
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", { className: section_default.hint, href: notes, target: "_blank", rel: "noreferrer", children: t("updateNotes") }),
|
|
912
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
913
|
+
"button",
|
|
914
|
+
{
|
|
915
|
+
type: "button",
|
|
916
|
+
className: section_default.button,
|
|
917
|
+
disabled: busy,
|
|
918
|
+
onClick: () => {
|
|
919
|
+
void act(async () => {
|
|
920
|
+
await controller.checkUpdate(true);
|
|
921
|
+
});
|
|
922
|
+
},
|
|
923
|
+
children: t("updateRecheck")
|
|
924
|
+
}
|
|
925
|
+
)
|
|
926
|
+
] }),
|
|
927
|
+
update.phase === "confirming" && status?.latest !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
928
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: section_default.hint, children: `${t("updateConfirmHint")} ${status.latest}` }),
|
|
929
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
930
|
+
"button",
|
|
931
|
+
{
|
|
932
|
+
type: "button",
|
|
933
|
+
className: section_default.button,
|
|
934
|
+
disabled: busy,
|
|
935
|
+
onClick: () => {
|
|
936
|
+
void act(async () => {
|
|
937
|
+
await controller.applyUpdate();
|
|
938
|
+
});
|
|
939
|
+
},
|
|
940
|
+
children: t("updateConfirm")
|
|
941
|
+
}
|
|
942
|
+
),
|
|
943
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
944
|
+
"button",
|
|
945
|
+
{
|
|
946
|
+
type: "button",
|
|
947
|
+
className: section_default.button,
|
|
948
|
+
disabled: busy,
|
|
949
|
+
onClick: () => {
|
|
950
|
+
controller.disarmUpdate();
|
|
951
|
+
},
|
|
952
|
+
children: t("updateCancel")
|
|
953
|
+
}
|
|
954
|
+
)
|
|
955
|
+
] }),
|
|
956
|
+
update.phase === "updating" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: section_default.hint, children: t("updateApplying") }),
|
|
957
|
+
update.phase === "done" && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
958
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: section_default.ok, children: `${t("updateDone")} ${status?.latest ?? ""}`.trim() }),
|
|
959
|
+
update.message === "restart-required" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: section_default.warn, children: t("updateRestart") })
|
|
960
|
+
] }),
|
|
961
|
+
update.phase === "failed" && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
962
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: section_default.warn, children: t("updateFailed") }),
|
|
963
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: section_default.hint, children: updateFailureText(update.message, t) }),
|
|
964
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
965
|
+
"button",
|
|
966
|
+
{
|
|
967
|
+
type: "button",
|
|
968
|
+
className: section_default.button,
|
|
969
|
+
disabled: busy,
|
|
970
|
+
onClick: () => {
|
|
971
|
+
void act(async () => {
|
|
972
|
+
await controller.checkUpdate(true);
|
|
973
|
+
});
|
|
974
|
+
},
|
|
975
|
+
children: t("updateRecheck")
|
|
976
|
+
}
|
|
977
|
+
)
|
|
978
|
+
] })
|
|
979
|
+
] }) });
|
|
980
|
+
}
|
|
981
|
+
function updateFailureText(message, t) {
|
|
982
|
+
if (message === void 0 || message.length === 0) return "";
|
|
983
|
+
if (message === "stop-profile") return t("updateStopProfile");
|
|
984
|
+
if (message === "incompatible-version") return t("updateIncompatible");
|
|
985
|
+
if (message === "pending-builds") return t("updatePendingBuilds");
|
|
986
|
+
return message;
|
|
987
|
+
}
|
|
700
988
|
function Section({ controller, t, getLocale }) {
|
|
701
989
|
const state = (0, import_react.useSyncExternalStore)(controller.subscribe, controller.snapshot, controller.snapshot);
|
|
702
990
|
const [keyDraft, setKeyDraft] = (0, import_react.useState)("");
|
|
@@ -720,6 +1008,7 @@ function Section({ controller, t, getLocale }) {
|
|
|
720
1008
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", { className: section_default.root, children: [
|
|
721
1009
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { className: section_default.title, children: t("nav") }),
|
|
722
1010
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: section_default.hint, children: t("intro") }),
|
|
1011
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(UpdateBanner, { controller, t, busy, act, update: state.update }),
|
|
723
1012
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: section_default.block, children: [
|
|
724
1013
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: section_default.row, children: [
|
|
725
1014
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { children: t("keyTitle") }),
|
|
@@ -954,16 +1243,16 @@ function Section({ controller, t, getLocale }) {
|
|
|
954
1243
|
// src/client/UsagePill.tsx
|
|
955
1244
|
var import_react2 = require("react");
|
|
956
1245
|
|
|
957
|
-
// plugin-css
|
|
1246
|
+
// plugin-css:/home/runner/work/dshopencodego/dshopencodego/src/client/pill.module.css
|
|
958
1247
|
var id2 = "@dan-ai-studio/dshopencodego/pill.module.css";
|
|
959
1248
|
if (!document.querySelector("style[data-plugin-css=" + JSON.stringify(id2) + "]")) {
|
|
960
1249
|
const style = document.createElement("style");
|
|
961
1250
|
style.dataset.plugin = "@dan-ai-studio/dshopencodego";
|
|
962
1251
|
style.dataset.pluginCss = id2;
|
|
963
|
-
style.textContent = ".
|
|
1252
|
+
style.textContent = ".mMNkkW_root{align-items:center;display:inline-flex;position:relative}.mMNkkW_trigger{border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-secondary);font:inherit;cursor:pointer;white-space:nowrap;border-radius:999px;padding:.35rem .6rem;font-size:.8rem;line-height:1}.mMNkkW_trigger:hover{color:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-border-l2)}.mMNkkW_panel{z-index:20;border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-overlay);width:18rem;color:var(--dsw-alias-label-primary);border-radius:.6rem;flex-direction:column;gap:.6rem;padding:.75rem .85rem;display:flex;position:absolute;bottom:calc(100% + .5rem);right:0;box-shadow:0 8px 24px #0000002e}.mMNkkW_window{flex-direction:column;gap:.25rem;display:flex}.mMNkkW_row{justify-content:space-between;gap:.5rem;font-size:.85rem;display:flex}.mMNkkW_hint{color:var(--dsw-alias-label-secondary);margin:0;font-size:.75rem}.mMNkkW_progress{width:100%;height:.35rem;accent-color:var(--dsw-alias-brand-primary)}.mMNkkW_limited{color:var(--dsw-alias-state-warn-primary);font-size:.75rem}.mMNkkW_warning{border:1px solid var(--dsw-alias-state-warn-primary);color:var(--dsw-alias-label-primary);border-radius:.4rem;padding:.4rem .5rem;font-size:.75rem}.mMNkkW_retry{border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary);font:inherit;cursor:pointer;border-radius:.35rem;align-self:flex-start;padding:.25rem .5rem;font-size:.75rem}.mMNkkW_local{border-top:1px solid var(--dsw-alias-border-l1);flex-direction:column;gap:.2rem;padding-top:.5rem;display:flex}";
|
|
964
1253
|
document.head.appendChild(style);
|
|
965
1254
|
}
|
|
966
|
-
var pill_default = { "
|
|
1255
|
+
var pill_default = { "warning": "mMNkkW_warning", "row": "mMNkkW_row", "root": "mMNkkW_root", "retry": "mMNkkW_retry", "window": "mMNkkW_window", "trigger": "mMNkkW_trigger", "hint": "mMNkkW_hint", "limited": "mMNkkW_limited", "local": "mMNkkW_local", "progress": "mMNkkW_progress", "panel": "mMNkkW_panel" };
|
|
967
1256
|
|
|
968
1257
|
// src/client/UsagePill.tsx
|
|
969
1258
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
@@ -1121,7 +1410,7 @@ function apply(ctx) {
|
|
|
1121
1410
|
ctx.effect(() => ctx.locale.register(NS, { zh, en }), "dshopencodego: copy dictionaries");
|
|
1122
1411
|
const mounted = ctx.remote.$mount({
|
|
1123
1412
|
package: usageRemote.package,
|
|
1124
|
-
descriptors: [...usageRemote.descriptors, ...catalogRemote.descriptors]
|
|
1413
|
+
descriptors: [...usageRemote.descriptors, ...catalogRemote.descriptors, ...updateRemote.descriptors]
|
|
1125
1414
|
});
|
|
1126
1415
|
ctx.effect(() => {
|
|
1127
1416
|
let dispose;
|
package/lib/index.js
CHANGED
|
@@ -1178,6 +1178,7 @@ var ACCOUNT_QUOTA_CODE = "ACCOUNT_QUOTA";
|
|
|
1178
1178
|
function classifyPiAiError(message) {
|
|
1179
1179
|
if (/\b(?:401|403)\b/.test(message)) return "AUTH";
|
|
1180
1180
|
if (isQuotaExceededError(message)) return ACCOUNT_QUOTA_CODE;
|
|
1181
|
+
if (/server_error/i.test(message)) return "SERVER";
|
|
1181
1182
|
if (/\b429\b|rate.?limit/i.test(message)) return "RATE_LIMIT";
|
|
1182
1183
|
if (/\b413\b|payload too large|request body too large|length limit exceeded/i.test(message)) return "INVALID_REQUEST";
|
|
1183
1184
|
if (/\b400\b|invalid.?request/i.test(message)) return "INVALID_REQUEST";
|
|
@@ -1766,6 +1767,44 @@ var catalogRemote = {
|
|
|
1766
1767
|
]
|
|
1767
1768
|
};
|
|
1768
1769
|
|
|
1770
|
+
// src/update/contract.ts
|
|
1771
|
+
function parseUpdateStatus(value) {
|
|
1772
|
+
if (value === null || typeof value !== "object") throw new Error("invalid update reading");
|
|
1773
|
+
const row = value;
|
|
1774
|
+
if (typeof row["current"] !== "string") throw new Error("invalid update reading");
|
|
1775
|
+
if (row["latest"] !== void 0 && typeof row["latest"] !== "string") throw new Error("invalid update reading");
|
|
1776
|
+
if (typeof row["available"] !== "boolean") throw new Error("invalid update reading");
|
|
1777
|
+
if (typeof row["checkedAt"] !== "number" || !Number.isFinite(row["checkedAt"])) {
|
|
1778
|
+
throw new Error("invalid update reading");
|
|
1779
|
+
}
|
|
1780
|
+
return {
|
|
1781
|
+
current: row["current"],
|
|
1782
|
+
latest: typeof row["latest"] === "string" ? row["latest"] : void 0,
|
|
1783
|
+
available: row["available"],
|
|
1784
|
+
checkedAt: row["checkedAt"]
|
|
1785
|
+
};
|
|
1786
|
+
}
|
|
1787
|
+
var codec2 = (typeSymbol, parse) => ({
|
|
1788
|
+
mode: "strict",
|
|
1789
|
+
typeSymbol,
|
|
1790
|
+
schema: { parse },
|
|
1791
|
+
create: () => ({ parse })
|
|
1792
|
+
});
|
|
1793
|
+
var updateRemote = {
|
|
1794
|
+
package: "@dan-ai-studio/dshopencodego",
|
|
1795
|
+
descriptors: [
|
|
1796
|
+
{
|
|
1797
|
+
id: "@dan-ai-studio/dshopencodego#opencodeGoUpdate/readUpdate",
|
|
1798
|
+
service: "opencodeGoUpdate",
|
|
1799
|
+
namespace: "opencodeGoUpdate",
|
|
1800
|
+
method: "readUpdate",
|
|
1801
|
+
invocation: { kind: "direct" },
|
|
1802
|
+
parameters: [],
|
|
1803
|
+
result: codec2("@dan-ai-studio/dshopencodego#UpdateStatus", parseUpdateStatus)
|
|
1804
|
+
}
|
|
1805
|
+
]
|
|
1806
|
+
};
|
|
1807
|
+
|
|
1769
1808
|
// src/usage/contract.ts
|
|
1770
1809
|
function parseWindow(value, key) {
|
|
1771
1810
|
if (value === null || typeof value !== "object") throw new Error(`invalid usage window "${key}"`);
|
|
@@ -1820,7 +1859,7 @@ function parseGoMeter(value) {
|
|
|
1820
1859
|
})
|
|
1821
1860
|
};
|
|
1822
1861
|
}
|
|
1823
|
-
var
|
|
1862
|
+
var codec3 = (typeSymbol, parse) => ({
|
|
1824
1863
|
mode: "strict",
|
|
1825
1864
|
typeSymbol,
|
|
1826
1865
|
schema: { parse },
|
|
@@ -1836,7 +1875,7 @@ var usageRemote = {
|
|
|
1836
1875
|
method: "readWindows",
|
|
1837
1876
|
invocation: { kind: "direct" },
|
|
1838
1877
|
parameters: [],
|
|
1839
|
-
result:
|
|
1878
|
+
result: codec3("@dan-ai-studio/dshopencodego#GoUsageWindows", parseUsageWindows)
|
|
1840
1879
|
},
|
|
1841
1880
|
{
|
|
1842
1881
|
id: "@dan-ai-studio/dshopencodego#opencodeGoUsage/readMeter",
|
|
@@ -1845,7 +1884,7 @@ var usageRemote = {
|
|
|
1845
1884
|
method: "readMeter",
|
|
1846
1885
|
invocation: { kind: "direct" },
|
|
1847
1886
|
parameters: [],
|
|
1848
|
-
result:
|
|
1887
|
+
result: codec3("@dan-ai-studio/dshopencodego#GoMeter", parseGoMeter)
|
|
1849
1888
|
}
|
|
1850
1889
|
]
|
|
1851
1890
|
};
|
|
@@ -1853,7 +1892,7 @@ var usageRemote = {
|
|
|
1853
1892
|
// src/remotes.ts
|
|
1854
1893
|
var contribution = {
|
|
1855
1894
|
package: usageRemote.package,
|
|
1856
|
-
descriptors: [...usageRemote.descriptors, ...catalogRemote.descriptors]
|
|
1895
|
+
descriptors: [...usageRemote.descriptors, ...catalogRemote.descriptors, ...updateRemote.descriptors]
|
|
1857
1896
|
};
|
|
1858
1897
|
function registerRemotes(ctx) {
|
|
1859
1898
|
ctx.inject(["typert"], (scope) => {
|
|
@@ -1948,6 +1987,106 @@ var OpencodeGoCatalogService = class extends TypertRemoteService {
|
|
|
1948
1987
|
}
|
|
1949
1988
|
};
|
|
1950
1989
|
|
|
1990
|
+
// src/update/check.ts
|
|
1991
|
+
var PACKAGE_NAME = "@dan-ai-studio/dshopencodego";
|
|
1992
|
+
var REGISTRY_LATEST_URL = `https://registry.npmjs.org/${encodeURIComponent(PACKAGE_NAME)}/latest`;
|
|
1993
|
+
var CHECK_CACHE_MS = 6 * 60 * 60 * 1e3;
|
|
1994
|
+
var CHECK_TIMEOUT_MS = 1e4;
|
|
1995
|
+
function parseVersion(value) {
|
|
1996
|
+
const match = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9a-zA-Z.-]+))?(?:\+[0-9a-zA-Z.-]+)?$/.exec(value.trim());
|
|
1997
|
+
if (match === void 0 || match === null) return void 0;
|
|
1998
|
+
const [, major, minor, patch, prerelease] = match;
|
|
1999
|
+
return {
|
|
2000
|
+
core: [Number(major), Number(minor), Number(patch)],
|
|
2001
|
+
prerelease: prerelease === void 0 ? void 0 : prerelease.split(".")
|
|
2002
|
+
};
|
|
2003
|
+
}
|
|
2004
|
+
function compareVersions(left, right) {
|
|
2005
|
+
const ours = parseVersion(left);
|
|
2006
|
+
const theirs = parseVersion(right);
|
|
2007
|
+
if (ours === void 0 || theirs === void 0) throw new Error(`dshopencodego: cannot compare versions "${left}" and "${right}"`);
|
|
2008
|
+
for (let index = 0; index < 3; index += 1) {
|
|
2009
|
+
const difference = (ours.core[index] ?? 0) - (theirs.core[index] ?? 0);
|
|
2010
|
+
if (difference !== 0) return difference;
|
|
2011
|
+
}
|
|
2012
|
+
if (ours.prerelease === void 0 && theirs.prerelease === void 0) return 0;
|
|
2013
|
+
if (ours.prerelease === void 0) return 1;
|
|
2014
|
+
if (theirs.prerelease === void 0) return -1;
|
|
2015
|
+
const width = Math.max(ours.prerelease.length, theirs.prerelease.length);
|
|
2016
|
+
for (let index = 0; index < width; index += 1) {
|
|
2017
|
+
const oursPart = ours.prerelease[index];
|
|
2018
|
+
const theirsPart = theirs.prerelease[index];
|
|
2019
|
+
if (oursPart === void 0) return -1;
|
|
2020
|
+
if (theirsPart === void 0) return 1;
|
|
2021
|
+
if (oursPart !== theirsPart) return oursPart < theirsPart ? -1 : 1;
|
|
2022
|
+
}
|
|
2023
|
+
return 0;
|
|
2024
|
+
}
|
|
2025
|
+
function isUpdateAvailable(current, latest) {
|
|
2026
|
+
if (latest === void 0) return false;
|
|
2027
|
+
try {
|
|
2028
|
+
return compareVersions(latest, current) > 0;
|
|
2029
|
+
} catch {
|
|
2030
|
+
return false;
|
|
2031
|
+
}
|
|
2032
|
+
}
|
|
2033
|
+
function parseLatestVersion(body) {
|
|
2034
|
+
if (body === null || typeof body !== "object") return void 0;
|
|
2035
|
+
const version = body["version"];
|
|
2036
|
+
return typeof version === "string" && parseVersion(version) !== void 0 ? version : void 0;
|
|
2037
|
+
}
|
|
2038
|
+
function createUpdateChecker(deps) {
|
|
2039
|
+
const now = deps.now ?? Date.now;
|
|
2040
|
+
const fetchImpl = deps.fetchImpl ?? fetch;
|
|
2041
|
+
let cached;
|
|
2042
|
+
let inflight;
|
|
2043
|
+
async function lookup() {
|
|
2044
|
+
const checkedAt = now();
|
|
2045
|
+
try {
|
|
2046
|
+
const response = await fetchImpl(REGISTRY_LATEST_URL, { signal: AbortSignal.timeout(CHECK_TIMEOUT_MS) });
|
|
2047
|
+
if (!response.ok) throw new Error(`registry answered ${response.status}`);
|
|
2048
|
+
const latest = parseLatestVersion(await response.json());
|
|
2049
|
+
return {
|
|
2050
|
+
current: deps.currentVersion,
|
|
2051
|
+
latest,
|
|
2052
|
+
available: isUpdateAvailable(deps.currentVersion, latest),
|
|
2053
|
+
checkedAt
|
|
2054
|
+
};
|
|
2055
|
+
} catch {
|
|
2056
|
+
return { current: deps.currentVersion, latest: void 0, available: false, checkedAt };
|
|
2057
|
+
}
|
|
2058
|
+
}
|
|
2059
|
+
return {
|
|
2060
|
+
check(force = false) {
|
|
2061
|
+
if (!force && cached !== void 0 && now() - cached.checkedAt < CHECK_CACHE_MS) return Promise.resolve(cached);
|
|
2062
|
+
inflight ??= lookup().then((status) => {
|
|
2063
|
+
cached = status;
|
|
2064
|
+
inflight = void 0;
|
|
2065
|
+
return status;
|
|
2066
|
+
});
|
|
2067
|
+
return inflight;
|
|
2068
|
+
}
|
|
2069
|
+
};
|
|
2070
|
+
}
|
|
2071
|
+
|
|
2072
|
+
// src/update/version.ts
|
|
2073
|
+
var PLUGIN_VERSION = true ? "0.1.23" : "0.0.0-dev";
|
|
2074
|
+
|
|
2075
|
+
// src/update/service.ts
|
|
2076
|
+
import { TypertRemoteService as TypertRemoteService2 } from "@deepseek-ai/dsh-typert-protocol";
|
|
2077
|
+
var OpencodeGoUpdateService = class extends TypertRemoteService2 {
|
|
2078
|
+
check;
|
|
2079
|
+
constructor(ctx, options) {
|
|
2080
|
+
super(ctx, "opencodeGoUpdate");
|
|
2081
|
+
const checker = createUpdateChecker({ currentVersion: options.currentVersion });
|
|
2082
|
+
this.check = (force) => checker.check(force);
|
|
2083
|
+
}
|
|
2084
|
+
/** Whether a newer release is published; `force` bypasses the cache. */
|
|
2085
|
+
readUpdate(force) {
|
|
2086
|
+
return this.check(force);
|
|
2087
|
+
}
|
|
2088
|
+
};
|
|
2089
|
+
|
|
1951
2090
|
// src/usage/meter.ts
|
|
1952
2091
|
var EMPTY = {
|
|
1953
2092
|
calls: 0,
|
|
@@ -2053,7 +2192,7 @@ async function readUsageWindows(options) {
|
|
|
2053
2192
|
|
|
2054
2193
|
// src/usage/service.ts
|
|
2055
2194
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
2056
|
-
import { RemoteError as RemoteError2, TypertRemoteService as
|
|
2195
|
+
import { RemoteError as RemoteError2, TypertRemoteService as TypertRemoteService3 } from "@deepseek-ai/dsh-typert-protocol";
|
|
2057
2196
|
import { LlmError as LlmError11 } from "@deepseek-ai/dsh-llm";
|
|
2058
2197
|
function usageFailure(error, source) {
|
|
2059
2198
|
const missing = error instanceof LlmError11 && error.code === "MISSING_CREDENTIAL";
|
|
@@ -2064,7 +2203,7 @@ function usageFailure(error, source) {
|
|
|
2064
2203
|
{ cause: error }
|
|
2065
2204
|
);
|
|
2066
2205
|
}
|
|
2067
|
-
var OpencodeGoUsageService = class extends
|
|
2206
|
+
var OpencodeGoUsageService = class extends TypertRemoteService3 {
|
|
2068
2207
|
identity;
|
|
2069
2208
|
options;
|
|
2070
2209
|
constructor(ctx, options) {
|
|
@@ -2157,6 +2296,7 @@ function apply(ctx, raw) {
|
|
|
2157
2296
|
catalog: () => adapter.catalogOf(current()),
|
|
2158
2297
|
visibility: () => current().modelVisibility
|
|
2159
2298
|
});
|
|
2299
|
+
ctx.plugin(OpencodeGoUpdateService, { currentVersion: PLUGIN_VERSION });
|
|
2160
2300
|
let registration;
|
|
2161
2301
|
let visibilityFacts = JSON.stringify(current().modelVisibility);
|
|
2162
2302
|
const applyRoute = (credentialConfigured) => {
|
|
@@ -51,6 +51,12 @@ export function classifyPiAiError(message) {
|
|
|
51
51
|
return 'AUTH';
|
|
52
52
|
if (isQuotaExceededError(message))
|
|
53
53
|
return ACCOUNT_QUOTA_CODE;
|
|
54
|
+
// A 429 typed as `server_error` is the gateway reporting an unavailable
|
|
55
|
+
// upstream, not the caller exceeding a rate limit: the remedy is waiting for
|
|
56
|
+
// the endpoint to recover rather than slowing down, so it classifies as
|
|
57
|
+
// SERVER even though the status code alone reads as a rate limit.
|
|
58
|
+
if (/server_error/i.test(message))
|
|
59
|
+
return 'SERVER';
|
|
54
60
|
if (/\b429\b|rate.?limit/i.test(message))
|
|
55
61
|
return 'RATE_LIMIT';
|
|
56
62
|
if (/\b413\b|payload too large|request body too large|length limit exceeded/i.test(message))
|
package/lib/types/index.js
CHANGED
|
@@ -36,6 +36,8 @@ import { DISPLAY_NAME, PROVIDER_ID, discoverCatalogModels } from "./catalog/inde
|
|
|
36
36
|
import { assertBaseURL, PlainConfig, readConfig } from "./config.js";
|
|
37
37
|
import { registerRemotes } from "./remotes.js";
|
|
38
38
|
import { OpencodeGoCatalogService } from "./catalog/service.js";
|
|
39
|
+
import { OpencodeGoUpdateService } from "./update/index.js";
|
|
40
|
+
import { PLUGIN_VERSION } from "./update/index.js";
|
|
39
41
|
import { OpencodeGoUsageService, UsageMeter } from "./usage/index.js";
|
|
40
42
|
export { OpencodeGoAdapter } from "./adapter.js";
|
|
41
43
|
export { DEFAULT_BASE_URL, CONSOLE_BASE_URL, DISPLAY_NAME, PROVIDER_ID, OpencodeGoCatalog, discoverCatalogModels } from "./catalog/index.js";
|
|
@@ -107,6 +109,7 @@ export function apply(ctx, raw) {
|
|
|
107
109
|
catalog: () => adapter.catalogOf(current()),
|
|
108
110
|
visibility: () => current().modelVisibility,
|
|
109
111
|
});
|
|
112
|
+
ctx.plugin(OpencodeGoUpdateService, { currentVersion: PLUGIN_VERSION });
|
|
110
113
|
let registration;
|
|
111
114
|
let visibilityFacts = JSON.stringify(current().modelVisibility);
|
|
112
115
|
/**
|
package/lib/types/remotes.js
CHANGED
|
@@ -8,11 +8,12 @@
|
|
|
8
8
|
* @module @dan-ai-studio/dshopencodego/remotes
|
|
9
9
|
*/
|
|
10
10
|
import { catalogRemote } from "./catalog/contract.js";
|
|
11
|
+
import { updateRemote } from "./update/contract.js";
|
|
11
12
|
import { usageRemote } from "./usage/contract.js";
|
|
12
13
|
/** Every Remote method this package owns, mounted as one contribution. */
|
|
13
14
|
const contribution = {
|
|
14
15
|
package: usageRemote.package,
|
|
15
|
-
descriptors: [...usageRemote.descriptors, ...catalogRemote.descriptors],
|
|
16
|
+
descriptors: [...usageRemote.descriptors, ...catalogRemote.descriptors, ...updateRemote.descriptors],
|
|
16
17
|
};
|
|
17
18
|
/** Register this package's Remote contribution for the mount's lifetime. */
|
|
18
19
|
export function registerRemotes(ctx) {
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Self update check: is a newer release of this package published?
|
|
3
|
+
*
|
|
4
|
+
* This module only *reads*: it asks the npm registry for the latest published
|
|
5
|
+
* version and compares it with the running build. It never downloads,
|
|
6
|
+
* installs, or replaces anything — the actual update stays with the host's
|
|
7
|
+
* `pluginManager` (`removeBundle` + `installBundle`), driven by an explicit
|
|
8
|
+
* user click on the settings page. Automatic self-replacement would bypass
|
|
9
|
+
* the host's manifest lock, peer-compatibility checks, build approvals, and
|
|
10
|
+
* HMR lifecycle, so it is deliberately not implemented here.
|
|
11
|
+
*
|
|
12
|
+
* The check runs only when the settings page asks (page open or manual
|
|
13
|
+
* refresh), never on the model-request path, and fails silent: an unreachable
|
|
14
|
+
* registry simply hides the banner instead of erroring the page.
|
|
15
|
+
*
|
|
16
|
+
* @module @dan-ai-studio/dshopencodego/update/check
|
|
17
|
+
*/
|
|
18
|
+
/** This package as addressed on the registry. */
|
|
19
|
+
export declare const PACKAGE_NAME = "@dan-ai-studio/dshopencodego";
|
|
20
|
+
/** Document address answering `{ "version": "x.y.z", ... }`. */
|
|
21
|
+
export declare const REGISTRY_LATEST_URL: string;
|
|
22
|
+
/** How long one lookup answers for before the registry is asked again. */
|
|
23
|
+
export declare const CHECK_CACHE_MS: number;
|
|
24
|
+
/** Bound on one registry round trip; expiry fails silent, never throws. */
|
|
25
|
+
export declare const CHECK_TIMEOUT_MS = 10000;
|
|
26
|
+
/** What the settings page renders. */
|
|
27
|
+
export interface UpdateStatus {
|
|
28
|
+
/** Version of the running build. */
|
|
29
|
+
readonly current: string;
|
|
30
|
+
/** Latest published version, when the registry answered. */
|
|
31
|
+
readonly latest: string | undefined;
|
|
32
|
+
/** True when the registry answered and `latest` is newer than `current`. */
|
|
33
|
+
readonly available: boolean;
|
|
34
|
+
/** Milliseconds since the epoch of the lookup backing this reading. */
|
|
35
|
+
readonly checkedAt: number;
|
|
36
|
+
}
|
|
37
|
+
interface ParsedVersion {
|
|
38
|
+
readonly core: readonly number[];
|
|
39
|
+
/** Absent for a release; present (lower precedence) for `1.2.3-tag.4`. */
|
|
40
|
+
readonly prerelease: readonly string[] | undefined;
|
|
41
|
+
}
|
|
42
|
+
/** Split `1.2.3-tag.4+build` into comparable parts; invalid input yields undefined. */
|
|
43
|
+
export declare function parseVersion(value: string): ParsedVersion | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Compare two version strings.
|
|
46
|
+
* @returns negative when `left` is older, positive when newer, zero when equal.
|
|
47
|
+
* @throws {Error} when either side is not a version.
|
|
48
|
+
*/
|
|
49
|
+
export declare function compareVersions(left: string, right: string): number;
|
|
50
|
+
/** True when `latest` is a newer release than `current`. Unparsable input is never an update. */
|
|
51
|
+
export declare function isUpdateAvailable(current: string, latest: string | undefined): boolean;
|
|
52
|
+
/** Read the `version` field out of a registry `latest` document. */
|
|
53
|
+
export declare function parseLatestVersion(body: unknown): string | undefined;
|
|
54
|
+
/** Dependencies the check needs, injectable for tests. */
|
|
55
|
+
export interface UpdateCheckDeps {
|
|
56
|
+
/** Running build's version (build-time constant in production). */
|
|
57
|
+
readonly currentVersion: string;
|
|
58
|
+
/** Fetch implementation; defaults to the global one. */
|
|
59
|
+
readonly fetchImpl?: typeof fetch;
|
|
60
|
+
/** Clock; defaults to `Date.now`. */
|
|
61
|
+
readonly now?: () => number;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Ask the registry for the latest published version, cached per process.
|
|
65
|
+
*
|
|
66
|
+
* Concurrent callers share one in-flight lookup. A lookup that fails for any
|
|
67
|
+
* reason — network, timeout, malformed document — resolves as "no update
|
|
68
|
+
* known" rather than rejecting, so the settings page never breaks because
|
|
69
|
+
* the registry is unreachable.
|
|
70
|
+
*/
|
|
71
|
+
export declare function createUpdateChecker(deps: UpdateCheckDeps): {
|
|
72
|
+
check(force?: boolean): Promise<UpdateStatus>;
|
|
73
|
+
};
|
|
74
|
+
export {};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Self update check: is a newer release of this package published?
|
|
3
|
+
*
|
|
4
|
+
* This module only *reads*: it asks the npm registry for the latest published
|
|
5
|
+
* version and compares it with the running build. It never downloads,
|
|
6
|
+
* installs, or replaces anything — the actual update stays with the host's
|
|
7
|
+
* `pluginManager` (`removeBundle` + `installBundle`), driven by an explicit
|
|
8
|
+
* user click on the settings page. Automatic self-replacement would bypass
|
|
9
|
+
* the host's manifest lock, peer-compatibility checks, build approvals, and
|
|
10
|
+
* HMR lifecycle, so it is deliberately not implemented here.
|
|
11
|
+
*
|
|
12
|
+
* The check runs only when the settings page asks (page open or manual
|
|
13
|
+
* refresh), never on the model-request path, and fails silent: an unreachable
|
|
14
|
+
* registry simply hides the banner instead of erroring the page.
|
|
15
|
+
*
|
|
16
|
+
* @module @dan-ai-studio/dshopencodego/update/check
|
|
17
|
+
*/
|
|
18
|
+
/** This package as addressed on the registry. */
|
|
19
|
+
export const PACKAGE_NAME = '@dan-ai-studio/dshopencodego';
|
|
20
|
+
/** Document address answering `{ "version": "x.y.z", ... }`. */
|
|
21
|
+
export const REGISTRY_LATEST_URL = `https://registry.npmjs.org/${encodeURIComponent(PACKAGE_NAME)}/latest`;
|
|
22
|
+
/** How long one lookup answers for before the registry is asked again. */
|
|
23
|
+
export const CHECK_CACHE_MS = 6 * 60 * 60 * 1000;
|
|
24
|
+
/** Bound on one registry round trip; expiry fails silent, never throws. */
|
|
25
|
+
export const CHECK_TIMEOUT_MS = 10_000;
|
|
26
|
+
/** Split `1.2.3-tag.4+build` into comparable parts; invalid input yields undefined. */
|
|
27
|
+
export function parseVersion(value) {
|
|
28
|
+
const match = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9a-zA-Z.-]+))?(?:\+[0-9a-zA-Z.-]+)?$/.exec(value.trim());
|
|
29
|
+
if (match === undefined || match === null)
|
|
30
|
+
return undefined;
|
|
31
|
+
const [, major, minor, patch, prerelease] = match;
|
|
32
|
+
return {
|
|
33
|
+
core: [Number(major), Number(minor), Number(patch)],
|
|
34
|
+
prerelease: prerelease === undefined ? undefined : prerelease.split('.'),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Compare two version strings.
|
|
39
|
+
* @returns negative when `left` is older, positive when newer, zero when equal.
|
|
40
|
+
* @throws {Error} when either side is not a version.
|
|
41
|
+
*/
|
|
42
|
+
export function compareVersions(left, right) {
|
|
43
|
+
const ours = parseVersion(left);
|
|
44
|
+
const theirs = parseVersion(right);
|
|
45
|
+
if (ours === undefined || theirs === undefined)
|
|
46
|
+
throw new Error(`dshopencodego: cannot compare versions "${left}" and "${right}"`);
|
|
47
|
+
for (let index = 0; index < 3; index += 1) {
|
|
48
|
+
const difference = (ours.core[index] ?? 0) - (theirs.core[index] ?? 0);
|
|
49
|
+
if (difference !== 0)
|
|
50
|
+
return difference;
|
|
51
|
+
}
|
|
52
|
+
if (ours.prerelease === undefined && theirs.prerelease === undefined)
|
|
53
|
+
return 0;
|
|
54
|
+
if (ours.prerelease === undefined)
|
|
55
|
+
return 1;
|
|
56
|
+
if (theirs.prerelease === undefined)
|
|
57
|
+
return -1;
|
|
58
|
+
const width = Math.max(ours.prerelease.length, theirs.prerelease.length);
|
|
59
|
+
for (let index = 0; index < width; index += 1) {
|
|
60
|
+
const oursPart = ours.prerelease[index];
|
|
61
|
+
const theirsPart = theirs.prerelease[index];
|
|
62
|
+
if (oursPart === undefined)
|
|
63
|
+
return -1;
|
|
64
|
+
if (theirsPart === undefined)
|
|
65
|
+
return 1;
|
|
66
|
+
if (oursPart !== theirsPart)
|
|
67
|
+
return oursPart < theirsPart ? -1 : 1;
|
|
68
|
+
}
|
|
69
|
+
return 0;
|
|
70
|
+
}
|
|
71
|
+
/** True when `latest` is a newer release than `current`. Unparsable input is never an update. */
|
|
72
|
+
export function isUpdateAvailable(current, latest) {
|
|
73
|
+
if (latest === undefined)
|
|
74
|
+
return false;
|
|
75
|
+
try {
|
|
76
|
+
return compareVersions(latest, current) > 0;
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/** Read the `version` field out of a registry `latest` document. */
|
|
83
|
+
export function parseLatestVersion(body) {
|
|
84
|
+
if (body === null || typeof body !== 'object')
|
|
85
|
+
return undefined;
|
|
86
|
+
const version = body['version'];
|
|
87
|
+
return typeof version === 'string' && parseVersion(version) !== undefined ? version : undefined;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Ask the registry for the latest published version, cached per process.
|
|
91
|
+
*
|
|
92
|
+
* Concurrent callers share one in-flight lookup. A lookup that fails for any
|
|
93
|
+
* reason — network, timeout, malformed document — resolves as "no update
|
|
94
|
+
* known" rather than rejecting, so the settings page never breaks because
|
|
95
|
+
* the registry is unreachable.
|
|
96
|
+
*/
|
|
97
|
+
export function createUpdateChecker(deps) {
|
|
98
|
+
const now = deps.now ?? Date.now;
|
|
99
|
+
const fetchImpl = deps.fetchImpl ?? fetch;
|
|
100
|
+
let cached;
|
|
101
|
+
let inflight;
|
|
102
|
+
async function lookup() {
|
|
103
|
+
const checkedAt = now();
|
|
104
|
+
try {
|
|
105
|
+
const response = await fetchImpl(REGISTRY_LATEST_URL, { signal: AbortSignal.timeout(CHECK_TIMEOUT_MS) });
|
|
106
|
+
if (!response.ok)
|
|
107
|
+
throw new Error(`registry answered ${response.status}`);
|
|
108
|
+
const latest = parseLatestVersion(await response.json());
|
|
109
|
+
return {
|
|
110
|
+
current: deps.currentVersion,
|
|
111
|
+
latest,
|
|
112
|
+
available: isUpdateAvailable(deps.currentVersion, latest),
|
|
113
|
+
checkedAt,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
return { current: deps.currentVersion, latest: undefined, available: false, checkedAt };
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
check(force = false) {
|
|
122
|
+
if (!force && cached !== undefined && now() - cached.checkedAt < CHECK_CACHE_MS)
|
|
123
|
+
return Promise.resolve(cached);
|
|
124
|
+
inflight ??= lookup().then((status) => {
|
|
125
|
+
cached = status;
|
|
126
|
+
inflight = undefined;
|
|
127
|
+
return status;
|
|
128
|
+
});
|
|
129
|
+
return inflight;
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire contract for the update Remote.
|
|
3
|
+
*
|
|
4
|
+
* `readUpdate` answers whether a newer release of this package is published.
|
|
5
|
+
* The reading is advisory — applying the update stays a user click that
|
|
6
|
+
* drives the host's `pluginManager`, never an automatic download.
|
|
7
|
+
*
|
|
8
|
+
* @module @dan-ai-studio/dshopencodego/update/contract
|
|
9
|
+
*/
|
|
10
|
+
import type { RemoteResult, TypertRemoteContribution } from '@deepseek-ai/dsh-typert-protocol';
|
|
11
|
+
import type { UpdateStatus } from './check.ts';
|
|
12
|
+
export type { UpdateStatus } from './check.ts';
|
|
13
|
+
/** Validate an update reading crossing the wire. */
|
|
14
|
+
export declare function parseUpdateStatus(value: unknown): UpdateStatus;
|
|
15
|
+
declare module '@deepseek-ai/dsh-typert-protocol' {
|
|
16
|
+
interface TypertRemoteNamespaceMap {
|
|
17
|
+
opencodeGoUpdate: {
|
|
18
|
+
readUpdate(force?: boolean): Promise<RemoteResult<UpdateStatus>>;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/** Remote methods this package owns, mounted together by the plugin. */
|
|
23
|
+
export declare const updateRemote: TypertRemoteContribution;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire contract for the update Remote.
|
|
3
|
+
*
|
|
4
|
+
* `readUpdate` answers whether a newer release of this package is published.
|
|
5
|
+
* The reading is advisory — applying the update stays a user click that
|
|
6
|
+
* drives the host's `pluginManager`, never an automatic download.
|
|
7
|
+
*
|
|
8
|
+
* @module @dan-ai-studio/dshopencodego/update/contract
|
|
9
|
+
*/
|
|
10
|
+
/** Validate an update reading crossing the wire. */
|
|
11
|
+
export function parseUpdateStatus(value) {
|
|
12
|
+
if (value === null || typeof value !== 'object')
|
|
13
|
+
throw new Error('invalid update reading');
|
|
14
|
+
const row = value;
|
|
15
|
+
if (typeof row['current'] !== 'string')
|
|
16
|
+
throw new Error('invalid update reading');
|
|
17
|
+
if (row['latest'] !== undefined && typeof row['latest'] !== 'string')
|
|
18
|
+
throw new Error('invalid update reading');
|
|
19
|
+
if (typeof row['available'] !== 'boolean')
|
|
20
|
+
throw new Error('invalid update reading');
|
|
21
|
+
if (typeof row['checkedAt'] !== 'number' || !Number.isFinite(row['checkedAt'])) {
|
|
22
|
+
throw new Error('invalid update reading');
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
current: row['current'],
|
|
26
|
+
latest: typeof row['latest'] === 'string' ? row['latest'] : undefined,
|
|
27
|
+
available: row['available'],
|
|
28
|
+
checkedAt: row['checkedAt'],
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/** Codec shape accepted by both released and source DSH builds. */
|
|
32
|
+
const codec = (typeSymbol, parse) => ({
|
|
33
|
+
mode: 'strict',
|
|
34
|
+
typeSymbol,
|
|
35
|
+
schema: { parse },
|
|
36
|
+
create: () => ({ parse }),
|
|
37
|
+
});
|
|
38
|
+
/** Remote methods this package owns, mounted together by the plugin. */
|
|
39
|
+
export const updateRemote = {
|
|
40
|
+
package: '@dan-ai-studio/dshopencodego',
|
|
41
|
+
descriptors: [
|
|
42
|
+
{
|
|
43
|
+
id: '@dan-ai-studio/dshopencodego#opencodeGoUpdate/readUpdate',
|
|
44
|
+
service: 'opencodeGoUpdate',
|
|
45
|
+
namespace: 'opencodeGoUpdate',
|
|
46
|
+
method: 'readUpdate',
|
|
47
|
+
invocation: { kind: 'direct' },
|
|
48
|
+
parameters: [],
|
|
49
|
+
result: codec('@dan-ai-studio/dshopencodego#UpdateStatus', parseUpdateStatus),
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Self update check (advisory only).
|
|
3
|
+
*
|
|
4
|
+
* @module @dan-ai-studio/dshopencodego/update
|
|
5
|
+
*/
|
|
6
|
+
export { PACKAGE_NAME, REGISTRY_LATEST_URL, CHECK_CACHE_MS, CHECK_TIMEOUT_MS } from './check.ts';
|
|
7
|
+
export type { UpdateStatus } from './check.ts';
|
|
8
|
+
export { compareVersions, createUpdateChecker, isUpdateAvailable, parseLatestVersion, parseVersion } from './check.ts';
|
|
9
|
+
export { PLUGIN_VERSION } from './version.ts';
|
|
10
|
+
export { OpencodeGoUpdateService } from './service.ts';
|
|
11
|
+
export type { UpdateServiceOptions } from './service.ts';
|
|
12
|
+
export { parseUpdateStatus, updateRemote } from './contract.ts';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Self update check (advisory only).
|
|
3
|
+
*
|
|
4
|
+
* @module @dan-ai-studio/dshopencodego/update
|
|
5
|
+
*/
|
|
6
|
+
export { PACKAGE_NAME, REGISTRY_LATEST_URL, CHECK_CACHE_MS, CHECK_TIMEOUT_MS } from "./check.js";
|
|
7
|
+
export { compareVersions, createUpdateChecker, isUpdateAvailable, parseLatestVersion, parseVersion } from "./check.js";
|
|
8
|
+
export { PLUGIN_VERSION } from "./version.js";
|
|
9
|
+
export { OpencodeGoUpdateService } from "./service.js";
|
|
10
|
+
export { parseUpdateStatus, updateRemote } from "./contract.js";
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host half of the update Remote.
|
|
3
|
+
*
|
|
4
|
+
* One method, one question: is a newer release of this package published?
|
|
5
|
+
* The service answers from the registry through the cached checker in
|
|
6
|
+
* `./check.ts`, so the settings page learns about updates without the model
|
|
7
|
+
* path ever touching the network. Applying an update is intentionally absent
|
|
8
|
+
* here — the page drives the host's own `pluginManager` (`removeBundle` then
|
|
9
|
+
* `installBundle`), which owns the manifest lock, peer checks, build
|
|
10
|
+
* approvals, and the HMR lifecycle a self-replacing plugin would bypass.
|
|
11
|
+
*
|
|
12
|
+
* @module @dan-ai-studio/dshopencodego/update/service
|
|
13
|
+
*/
|
|
14
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
15
|
+
import { TypertRemoteService } from '@deepseek-ai/dsh-typert-protocol';
|
|
16
|
+
import type { UpdateStatus } from './check.ts';
|
|
17
|
+
/** Host inputs for the update service. */
|
|
18
|
+
export interface UpdateServiceOptions {
|
|
19
|
+
/** Running build's version. */
|
|
20
|
+
readonly currentVersion: string;
|
|
21
|
+
}
|
|
22
|
+
/** Update Remote: the cached registry reading for the settings page. */
|
|
23
|
+
export declare class OpencodeGoUpdateService extends TypertRemoteService {
|
|
24
|
+
private readonly check;
|
|
25
|
+
constructor(ctx: Context, options: UpdateServiceOptions);
|
|
26
|
+
/** Whether a newer release is published; `force` bypasses the cache. */
|
|
27
|
+
readUpdate(force?: boolean): Promise<UpdateStatus>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host half of the update Remote.
|
|
3
|
+
*
|
|
4
|
+
* One method, one question: is a newer release of this package published?
|
|
5
|
+
* The service answers from the registry through the cached checker in
|
|
6
|
+
* `./check.ts`, so the settings page learns about updates without the model
|
|
7
|
+
* path ever touching the network. Applying an update is intentionally absent
|
|
8
|
+
* here — the page drives the host's own `pluginManager` (`removeBundle` then
|
|
9
|
+
* `installBundle`), which owns the manifest lock, peer checks, build
|
|
10
|
+
* approvals, and the HMR lifecycle a self-replacing plugin would bypass.
|
|
11
|
+
*
|
|
12
|
+
* @module @dan-ai-studio/dshopencodego/update/service
|
|
13
|
+
*/
|
|
14
|
+
import { TypertRemoteService } from '@deepseek-ai/dsh-typert-protocol';
|
|
15
|
+
import { createUpdateChecker } from "./check.js";
|
|
16
|
+
/** Update Remote: the cached registry reading for the settings page. */
|
|
17
|
+
export class OpencodeGoUpdateService extends TypertRemoteService {
|
|
18
|
+
check;
|
|
19
|
+
constructor(ctx, options) {
|
|
20
|
+
super(ctx, 'opencodeGoUpdate');
|
|
21
|
+
const checker = createUpdateChecker({ currentVersion: options.currentVersion });
|
|
22
|
+
this.check = (force) => checker.check(force);
|
|
23
|
+
}
|
|
24
|
+
/** Whether a newer release is published; `force` bypasses the cache. */
|
|
25
|
+
readUpdate(force) {
|
|
26
|
+
return this.check(force);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The running build's own version.
|
|
3
|
+
*
|
|
4
|
+
* `scripts/build.mjs` replaces `__DSHOPENCODEGO_VERSION__` with the package
|
|
5
|
+
* version at bundle time, so the Host knows what it is without reading its
|
|
6
|
+
* own files back from disk. Outside the bundle (tests, source runs) the
|
|
7
|
+
* constant is absent and the value reads as a development placeholder; the
|
|
8
|
+
* update check treats an unparsable current version as "no update known"
|
|
9
|
+
* rather than erroring.
|
|
10
|
+
*
|
|
11
|
+
* @module @dan-ai-studio/dshopencodego/update/version
|
|
12
|
+
*/
|
|
13
|
+
/** Version of this build, or a placeholder outside the bundle. */
|
|
14
|
+
export declare const PLUGIN_VERSION: string;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The running build's own version.
|
|
3
|
+
*
|
|
4
|
+
* `scripts/build.mjs` replaces `__DSHOPENCODEGO_VERSION__` with the package
|
|
5
|
+
* version at bundle time, so the Host knows what it is without reading its
|
|
6
|
+
* own files back from disk. Outside the bundle (tests, source runs) the
|
|
7
|
+
* constant is absent and the value reads as a development placeholder; the
|
|
8
|
+
* update check treats an unparsable current version as "no update known"
|
|
9
|
+
* rather than erroring.
|
|
10
|
+
*
|
|
11
|
+
* @module @dan-ai-studio/dshopencodego/update/version
|
|
12
|
+
*/
|
|
13
|
+
/** Version of this build, or a placeholder outside the bundle. */
|
|
14
|
+
export const PLUGIN_VERSION = typeof __DSHOPENCODEGO_VERSION__ === 'string'
|
|
15
|
+
? __DSHOPENCODEGO_VERSION__
|
|
16
|
+
: '0.0.0-dev';
|
package/package.json
CHANGED