dsh-sub2api 0.10.3 → 0.11.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.11.0
4
+
5
+ - **Not being signed in now says so.** A request made without a login used to
6
+ leave the plugin, reach the gateway, and come back as `401 API key is required
7
+ in Authorization header` — a message about a key, for a user whose problem is
8
+ that they never signed in. The adapter refuses before touching the transport
9
+ and answers instead: 还没有登录 dsh-sub2api。打开 设置 → dsh-sub2api,用一个邮箱和密码
10
+ 登录或注册即可。
11
+ - **A reminder on the screen an empty conversation opens on.** While nobody is
12
+ signed in, `conversation.hero.options` shows a single line pointing at
13
+ 设置 → dsh-sub2api. It disappears the moment a login exists.
14
+
3
15
  ## 0.10.3
4
16
 
5
17
  - **A request can no longer go out with no key.** When the adapter could not
package/lib/adapter.js CHANGED
@@ -156,6 +156,18 @@ export class Sub2ApiAdapter extends LlmAdapter {
156
156
  }
157
157
 
158
158
  async *stream(options) {
159
+ // Refuse before touching the transport. A request with no key leaves here,
160
+ // comes back as "401 API key is required in Authorization header", and sends
161
+ // the user looking for a broken key when the real answer is "you are not
162
+ // signed in". Checking here turns that into a sentence they can act on.
163
+ const key = await this.deps.session?.()?.apiKey?.().catch(() => undefined);
164
+ if (typeof key !== "string" || key === "") {
165
+ throw new Sub2ApiError(
166
+ "还没有登录 dsh-sub2api。打开 设置 → dsh-sub2api,用一个邮箱和密码登录或注册即可。",
167
+ { code: "not_logged_in" },
168
+ );
169
+ }
170
+
159
171
  const service = await this.#service();
160
172
  const route = service.routes()[0];
161
173
  // An empty `models` array still yields a route object; without this check
package/lib/client.js CHANGED
@@ -1550,6 +1550,42 @@ window.__ModuleLoader__.load({
1550
1550
  return h("div", { "data-sub2api": "" }, h(Boundary, null, h(SectionInner, null)));
1551
1551
  }
1552
1552
 
1553
+ // ------------------------------------------------------ login nudge
1554
+
1555
+ /**
1556
+ * The line shown on the empty conversation screen while nobody is signed in.
1557
+ *
1558
+ * A user who installs the plugin and starts typing gets a 401; saying why on
1559
+ * the screen they are already looking at is the difference between "this
1560
+ * thing is broken" and "there is one step left". Renders nothing once a
1561
+ * login exists, so it never becomes furniture.
1562
+ */
1563
+ function LoginNudge() {
1564
+ const { state } = useStatus();
1565
+ if (state === null || state.loggedIn === true) return null;
1566
+
1567
+ return h("button", {
1568
+ type: "button",
1569
+ "data-sub2api": "",
1570
+ onClick: () => toastStore.push("打开 设置 → dsh-sub2api 登录或注册", "ok"),
1571
+ style: {
1572
+ display: "inline-flex",
1573
+ alignItems: "center",
1574
+ gap: 8,
1575
+ padding: "8px 14px",
1576
+ borderRadius: 999,
1577
+ border: "0.5px solid " + C.line,
1578
+ background: C.surface,
1579
+ color: C.second,
1580
+ fontSize: 12.5,
1581
+ cursor: "pointer",
1582
+ maxWidth: "100%",
1583
+ },
1584
+ },
1585
+ h("span", { style: { width: 7, height: 7, borderRadius: 999, background: C.warn, flex: "0 0 7px" } }),
1586
+ h("span", null, "还没登录 dsh-sub2api —— 去 设置 → dsh-sub2api 登录后即可使用这里的模型"));
1587
+ }
1588
+
1553
1589
  // ------------------------------------------------------------ badge
1554
1590
 
1555
1591
  /**
@@ -1689,6 +1725,18 @@ window.__ModuleLoader__.load({
1689
1725
  } catch {
1690
1726
  // The sidebar slot is optional.
1691
1727
  }
1728
+ try {
1729
+ // The hero area is what an empty conversation opens on, so the reminder
1730
+ // is already in view when someone starts typing without a login.
1731
+ ctx.slots.inject("conversation.hero.options", () =>
1732
+ ctx.slots.register(
1733
+ { name: "conversation.hero.options", id: "sub2api-login" },
1734
+ LoginNudge,
1735
+ ),
1736
+ );
1737
+ } catch {
1738
+ // Older hosts without the hero slot simply do not show the reminder.
1739
+ }
1692
1740
  try {
1693
1741
  ctx.slots.inject("conversation.input.right", () =>
1694
1742
  ctx.slots.register(
@@ -1705,6 +1753,7 @@ window.__ModuleLoader__.load({
1705
1753
  exports.inject = inject;
1706
1754
  exports.Section = Section;
1707
1755
  exports.BalanceBadge = BalanceBadge;
1756
+ exports.LoginNudge = LoginNudge;
1708
1757
  // Exposed for the load test: pure read/write of the remembered layout.
1709
1758
  exports.__sections = { readOpenSections, DEFAULT_OPEN, OPEN_KEY };
1710
1759
  return module.exports;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-sub2api",
3
- "version": "0.10.3",
3
+ "version": "0.11.0",
4
4
  "description": "Official Psapi provider for DeepSeek Harness: email sign-in or sign-up, automatic key and model provisioning, one panel for balance and recharge",
5
5
  "type": "module",
6
6
  "license": "GPL-3.0-only",