dsh-model-allowance 1.0.4 → 1.0.5

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.
Files changed (3) hide show
  1. package/client.js +50 -25
  2. package/lib/status.js +3 -2
  3. package/package.json +1 -1
package/client.js CHANGED
@@ -354,6 +354,8 @@ var zh = {
354
354
  "status.partialOutage": "\u90E8\u5206\u670D\u52A1\u4E2D\u65AD",
355
355
  "status.majorOutage": "\u5927\u9762\u79EF\u4E2D\u65AD",
356
356
  "status.maintenance": "\u7EF4\u62A4\u4E2D",
357
+ "status.loading": "\u72B6\u6001\u52A0\u8F7D\u4E2D\u2026",
358
+ "status.unsupported": "\u672A\u63D0\u4F9B\u72B6\u6001\u670D\u52A1",
357
359
  "status.unknown": "\u72B6\u6001\u672A\u77E5",
358
360
  "schedule.peakTitle": "\u9AD8\u5CF0\u65F6\u6BB5",
359
361
  "schedule.offPeakTitle": "\u4F4E\u8C37\u65F6\u6BB5",
@@ -415,6 +417,8 @@ var en = {
415
417
  "status.partialOutage": "Partial outage",
416
418
  "status.majorOutage": "Major outage",
417
419
  "status.maintenance": "Maintenance",
420
+ "status.loading": "Loading status\u2026",
421
+ "status.unsupported": "No status service provided",
418
422
  "status.unknown": "Status unknown",
419
423
  "schedule.peakTitle": "Peak hours",
420
424
  "schedule.offPeakTitle": "Off-peak",
@@ -454,6 +458,8 @@ var STATUS_LABEL_KEYS = {
454
458
  "partial-outage": "status.partialOutage",
455
459
  "major-outage": "status.majorOutage",
456
460
  maintenance: "status.maintenance",
461
+ loading: "status.loading",
462
+ unsupported: "status.unsupported",
457
463
  unknown: "status.unknown"
458
464
  };
459
465
  function statusLabel(state, t) {
@@ -960,6 +966,11 @@ var STYLES = [
960
966
  ".dsh-model-allowance-status-help:focus-visible .dsh-model-allowance-status-tip{display:block}",
961
967
  ".dsh-model-allowance-status-dot{width:6px;height:6px;border-radius:50%;flex:none;",
962
968
  "background:var(--dsw-alias-state-success-primary)}",
969
+ '.dsh-model-allowance-status[data-state="loading"] .dsh-model-allowance-status-dot,',
970
+ '.dsh-model-allowance-status[data-state="unsupported"] .dsh-model-allowance-status-dot,',
971
+ '.dsh-model-allowance-status[data-state="unknown"] .dsh-model-allowance-status-dot{',
972
+ "background:var(--dsw-alias-state-idle-primary)}",
973
+ '.dsh-model-allowance-status[data-state="loading"] .dsh-model-allowance-status-dot{opacity:.5}',
963
974
  '.dsh-model-allowance-status[data-state="degraded"] .dsh-model-allowance-status-dot,',
964
975
  '.dsh-model-allowance-status[data-state="maintenance"] .dsh-model-allowance-status-dot{',
965
976
  "background:var(--dsw-alias-state-warn-primary)}",
@@ -1085,6 +1096,28 @@ var CATALOG_TTL_MS = 60 * 1e3;
1085
1096
  function describe(error) {
1086
1097
  return error instanceof Error ? error.message : String(error);
1087
1098
  }
1099
+ async function readProviderStatus(provider) {
1100
+ try {
1101
+ const api = await getBalanceApi();
1102
+ if (!api || typeof api.status !== "function") {
1103
+ return { provider, state: "unknown", error: "status API unavailable" };
1104
+ }
1105
+ const result = await api.status(provider);
1106
+ if (!result.ok) {
1107
+ const error = typeof result.error?.message === "string" ? result.error.message : typeof result.error === "string" ? result.error : "status reading failed";
1108
+ return { provider, state: "unknown", error };
1109
+ }
1110
+ return result.value;
1111
+ } catch (error) {
1112
+ console.error("[model-allowance] reading provider status failed", { provider, error });
1113
+ return { provider, state: "unknown", error: describe(error) };
1114
+ }
1115
+ }
1116
+ function statusDisplayState(status) {
1117
+ if (status === null) return "loading";
1118
+ if (status.state === "unknown" && !status.url && !status.error) return "unsupported";
1119
+ return status.state;
1120
+ }
1088
1121
  function BalanceBadge(props) {
1089
1122
  const { useProjection, ctx, t } = props;
1090
1123
  const selection = useProjection("modelSelection");
@@ -1339,15 +1372,8 @@ function BalanceBadge(props) {
1339
1372
  if (!activeProvider) return void 0;
1340
1373
  let cancelled = false;
1341
1374
  const readStatus = async () => {
1342
- try {
1343
- const api = await getBalanceApi();
1344
- if (!api || typeof api.status !== "function") return;
1345
- const result = await api.status(activeProvider);
1346
- if (cancelled || !result.ok) return;
1347
- setProviderStatus(result.value);
1348
- } catch (error) {
1349
- console.error("[model-allowance] reading provider status failed", { error });
1350
- }
1375
+ const status = await readProviderStatus(activeProvider);
1376
+ if (!cancelled) setProviderStatus(status);
1351
1377
  };
1352
1378
  void readStatus();
1353
1379
  const timer = setInterval(readStatus, STATUS_REFRESH_MS);
@@ -1385,10 +1411,8 @@ function BalanceBadge(props) {
1385
1411
  result = await api.refresh(activeProvider, void 0);
1386
1412
  }
1387
1413
  if (result.ok) setView(result.value);
1388
- if (typeof api.status === "function") {
1389
- const status = await api.status(activeProvider);
1390
- if (status.ok) setProviderStatus(status.value);
1391
- }
1414
+ const status = await readProviderStatus(activeProvider);
1415
+ setProviderStatus(status);
1392
1416
  } catch (error) {
1393
1417
  console.error("[model-allowance] refresh failed", {
1394
1418
  provider: activeProvider,
@@ -1530,7 +1554,8 @@ function BalanceBadge(props) {
1530
1554
  return t("badge.failed");
1531
1555
  }, [view, provider, activeProvider, nameOf, t]);
1532
1556
  if (!provider) return null;
1533
- const serviceState = providerStatus && providerStatus.provider === activeProvider ? providerStatus.state : "unknown";
1557
+ const currentStatus = providerStatus?.provider === activeProvider ? providerStatus : null;
1558
+ const serviceState = statusDisplayState(currentStatus);
1534
1559
  const MARK_SIZE = 26;
1535
1560
  const MARK_GAP = 4;
1536
1561
  const MENU_SIZE = 26;
@@ -1804,16 +1829,16 @@ function BalanceBadge(props) {
1804
1829
  // The platform status sits at the left edge of the footer, on
1805
1830
  // the same line as the reading time: the card gains no extra
1806
1831
  // row, and the state and the source page stay together.
1807
- serviceState !== "unknown" ? (0, import_react3.createElement)(
1832
+ (0, import_react3.createElement)(
1808
1833
  "span",
1809
1834
  { className: "dsh-model-allowance-status-wrap" },
1810
1835
  (0, import_react3.createElement)(
1811
- providerStatus.url ? "a" : "span",
1836
+ currentStatus?.url ? "a" : "span",
1812
1837
  {
1813
1838
  className: "dsh-model-allowance-status",
1814
- "data-state": providerStatus.state,
1815
- ...providerStatus.url ? {
1816
- href: providerStatus.url,
1839
+ "data-state": serviceState,
1840
+ ...currentStatus?.url ? {
1841
+ href: currentStatus.url,
1817
1842
  target: "_blank",
1818
1843
  rel: "noreferrer noopener"
1819
1844
  } : {}
@@ -1825,9 +1850,9 @@ function BalanceBadge(props) {
1825
1850
  (0, import_react3.createElement)(
1826
1851
  "span",
1827
1852
  { className: "dsh-model-allowance-status-label" },
1828
- statusLabel(providerStatus.state, t)
1853
+ statusLabel(serviceState, t)
1829
1854
  ),
1830
- ...providerStatus.url ? [
1855
+ ...currentStatus?.url ? [
1831
1856
  (0, import_react3.createElement)(
1832
1857
  "span",
1833
1858
  {
@@ -1841,13 +1866,13 @@ function BalanceBadge(props) {
1841
1866
  // The reason is a warning mark rather than another line:
1842
1867
  // the footer stays one row, and the detail is one hover
1843
1868
  // — or one keyboard focus — away.
1844
- providerStatus.summary ? (0, import_react3.createElement)(
1869
+ currentStatus?.summary ? (0, import_react3.createElement)(
1845
1870
  "span",
1846
1871
  {
1847
1872
  className: "dsh-model-allowance-status-help",
1848
1873
  tabIndex: 0,
1849
1874
  role: "note",
1850
- "aria-label": providerStatus.summary
1875
+ "aria-label": currentStatus.summary
1851
1876
  },
1852
1877
  (0, import_react3.createElement)(
1853
1878
  "span",
@@ -1859,10 +1884,10 @@ function BalanceBadge(props) {
1859
1884
  (0, import_react3.createElement)(
1860
1885
  "span",
1861
1886
  { className: "dsh-model-allowance-status-tip", role: "tooltip" },
1862
- providerStatus.summary
1887
+ currentStatus.summary
1863
1888
  )
1864
1889
  ) : null
1865
- ) : null,
1890
+ ),
1866
1891
  view?.updatedAt ? (0, import_react3.createElement)(
1867
1892
  "span",
1868
1893
  { className: "dsh-model-allowance-updated" },
package/lib/status.js CHANGED
@@ -90,8 +90,9 @@ export class StatusService {
90
90
  * Read one provider's platform status.
91
91
  *
92
92
  * A route whose vendor publishes no status page answers `unknown` without
93
- * touching the network: the browser hides the row, and a route that later
94
- * gains a source starts working without any other change.
93
+ * touching the network: the browser presents that source-free reading as
94
+ * "no status service", and a route that later gains a source starts working
95
+ * without any other change.
95
96
  *
96
97
  * @param {string} provider Provider route.
97
98
  * @returns {Promise<StatusView>} The reading.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-model-allowance",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "type": "module",
5
5
  "description": "Shows the current conversation model's provider balance or remaining allowance in the composer.",
6
6
  "license": "MIT",