@istarry/spoon-companion 0.9.4 → 0.9.6

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 CHANGED
@@ -835,8 +835,8 @@ function SpeakerButton(props) {
835
835
  }
836
836
  );
837
837
  }
838
- function SettingsRow() {
839
- const [open, setOpen] = (0, import_react.useState)(false);
838
+ function SettingsRow({ defaultOpen = false } = {}) {
839
+ const [open, setOpen] = (0, import_react.useState)(defaultOpen);
840
840
  const [state, setState] = (0, import_react.useState)(void 0);
841
841
  const [busy, setBusy] = (0, import_react.useState)("");
842
842
  const [msg, setMsg] = (0, import_react.useState)("");
@@ -1176,10 +1176,6 @@ function apply(ctx) {
1176
1176
  "conversation.chat.assistant-actions",
1177
1177
  () => ctx.slots.register({ name: "conversation.chat.assistant-actions", id: "companion-voice-speak", order: 40 }, SpeakerButton)
1178
1178
  );
1179
- ctx.slots.inject(
1180
- "settings.general.item",
1181
- () => ctx.slots.register({ name: "settings.general.item", id: "companion-voice-settings", order: 40 }, SettingsRow)
1182
- );
1183
1179
  }
1184
1180
 
1185
1181
  // src/client/mic.tsx
@@ -1543,28 +1539,35 @@ var MIC_CSS = `
1543
1539
  // src/client/screen-settings.tsx
1544
1540
  var import_react3 = require("react");
1545
1541
  var import_jsx_runtime3 = require("react/jsx-runtime");
1546
- var API = "/api/spoon-companion/screen";
1547
- var box = {
1548
- display: "flex",
1549
- flexDirection: "column",
1550
- gap: 18,
1551
- padding: "4px 2px 24px",
1552
- maxWidth: 620,
1553
- fontSize: 13
1554
- };
1542
+ var API_SETTINGS = "/api/spoon-companion/settings";
1543
+ var API_SCREEN = "/api/spoon-companion/screen";
1544
+ var box = { display: "flex", flexDirection: "column", gap: 22, padding: "4px 2px 32px", maxWidth: 640, fontSize: 13 };
1545
+ var group = { display: "flex", flexDirection: "column", gap: 10 };
1555
1546
  var rowTitle = { fontWeight: 600, fontSize: 14 };
1556
1547
  var hint = { opacity: 0.6, lineHeight: 1.6, marginTop: 2 };
1557
- var group = { display: "flex", flexDirection: "column", gap: 10 };
1558
1548
  var sliderRow = { display: "grid", gridTemplateColumns: "96px 1fr 92px", alignItems: "center", gap: 10 };
1559
1549
  var num = { textAlign: "right", fontVariantNumeric: "tabular-nums", opacity: 0.85 };
1560
- var card = {
1561
- border: "1px solid rgba(128,128,128,0.28)",
1562
- borderRadius: 10,
1563
- padding: "12px 14px",
1564
- display: "grid",
1565
- gap: 6
1566
- };
1550
+ var card = { border: "1px solid rgba(128,128,128,0.28)", borderRadius: 10, padding: "12px 14px", display: "grid", gap: 6 };
1567
1551
  var kv = { display: "grid", gridTemplateColumns: "72px 1fr", gap: 8, fontSize: 12.5 };
1552
+ var input = {
1553
+ width: "100%",
1554
+ padding: "6px 8px",
1555
+ borderRadius: 8,
1556
+ border: "1px solid rgba(128,128,128,0.35)",
1557
+ background: "transparent",
1558
+ color: "inherit",
1559
+ fontSize: 12.5,
1560
+ fontFamily: "inherit"
1561
+ };
1562
+ var pill = (active) => ({
1563
+ padding: "4px 12px",
1564
+ borderRadius: 8,
1565
+ border: "1px solid rgba(128,128,128,0.35)",
1566
+ background: active ? "rgba(128,128,128,0.22)" : "transparent",
1567
+ cursor: "pointer",
1568
+ fontSize: 12.5,
1569
+ color: "inherit"
1570
+ });
1568
1571
  function ago(at, now) {
1569
1572
  if (!at) return "\u8FD8\u6CA1\u770B\u8FC7";
1570
1573
  const mins = Math.floor(Math.max(0, now - at) / 6e4);
@@ -1573,19 +1576,21 @@ function ago(at, now) {
1573
1576
  return `${Math.floor(mins / 60)} \u5C0F\u65F6\u524D`;
1574
1577
  }
1575
1578
  function ScreenSettingsSection() {
1576
- const [snap, setSnap] = (0, import_react3.useState)(null);
1579
+ const [cfg, setCfg] = (0, import_react3.useState)(null);
1580
+ const [screen, setScreen] = (0, import_react3.useState)(null);
1577
1581
  const [busy, setBusy] = (0, import_react3.useState)(false);
1578
1582
  const [error, setError] = (0, import_react3.useState)("");
1583
+ const [identityDraft, setIdentityDraft] = (0, import_react3.useState)(null);
1584
+ const [confirmReset, setConfirmReset] = (0, import_react3.useState)(false);
1579
1585
  const load = (0, import_react3.useCallback)(async () => {
1580
1586
  try {
1581
- const res = await fetch(API, { headers: { accept: "application/json" } });
1582
- const data = await res.json();
1583
- if (data?.ok) {
1584
- setSnap(data);
1585
- setError("");
1586
- } else {
1587
- setError("\u8BFB\u4E0D\u5230\u8BBE\u7F6E");
1588
- }
1587
+ const [a, b] = await Promise.all([
1588
+ fetch(API_SETTINGS, { headers: { accept: "application/json" } }).then((r) => r.json()),
1589
+ fetch(API_SCREEN, { headers: { accept: "application/json" } }).then((r) => r.json())
1590
+ ]);
1591
+ if (a?.ok) setCfg(a);
1592
+ if (b?.ok) setScreen(b);
1593
+ setError("");
1589
1594
  } catch (reason) {
1590
1595
  setError(String(reason));
1591
1596
  }
@@ -1595,112 +1600,171 @@ function ScreenSettingsSection() {
1595
1600
  const timer = setInterval(() => void load(), 5e3);
1596
1601
  return () => clearInterval(timer);
1597
1602
  }, [load]);
1598
- const save = async (patch) => {
1603
+ const post = async (url, patch) => {
1599
1604
  setBusy(true);
1600
1605
  try {
1601
- const res = await fetch(API, {
1602
- method: "POST",
1603
- headers: { "content-type": "application/json" },
1604
- body: JSON.stringify(patch)
1605
- });
1606
+ const res = await fetch(url, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(patch) });
1606
1607
  const data = await res.json();
1607
- if (data?.ok) {
1608
- setSnap(data);
1609
- setError("");
1610
- } else {
1611
- setError("\u4FDD\u5B58\u5931\u8D25");
1612
- }
1608
+ if (!data?.ok) setError(String(data?.error ?? "\u4FDD\u5B58\u5931\u8D25"));
1609
+ else setError("");
1610
+ await load();
1613
1611
  } catch (reason) {
1614
1612
  setError(String(reason));
1615
1613
  } finally {
1616
1614
  setBusy(false);
1617
1615
  }
1618
1616
  };
1619
- const cfg = snap?.config;
1620
- const st = snap?.state;
1621
- const slider = (label, value, min, max, suffix, onCommit) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("label", { style: sliderRow, children: [
1617
+ const saveSettings = (patch) => post(API_SETTINGS, patch);
1618
+ const saveScreen = (patch) => post(API_SCREEN, patch);
1619
+ const slider = (label, value, min, max, suffix, onCommit, disabled = false) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("label", { style: sliderRow, children: [
1622
1620
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { opacity: 0.8 }, children: label }),
1623
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1624
- "input",
1625
- {
1626
- type: "range",
1627
- min,
1628
- max,
1629
- value,
1630
- disabled: busy,
1631
- onChange: (event) => onCommit(Number(event.target.value)),
1632
- style: { width: "100%" }
1633
- }
1634
- ),
1621
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("input", { type: "range", min, max, value, disabled: busy || disabled, onChange: (e) => onCommit(Number(e.target.value)), style: { width: "100%" } }),
1635
1622
  /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { style: num, children: [
1636
1623
  value,
1637
1624
  " ",
1638
1625
  suffix
1639
1626
  ] })
1640
- ] });
1627
+ ] }, label);
1628
+ const sc = screen?.state;
1629
+ const off = cfg ? !cfg.general.enabled : false;
1641
1630
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: box, children: [
1642
1631
  /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: group, children: [
1643
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: rowTitle, children: "\u770B\u5C4F\u5E55" }),
1644
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: hint, children: "\u5979\u5076\u5C14\u8D70\u8FC7\u53BB\u770B\u4E00\u773C\uFF0C\u4E0D\u662F\u76D1\u89C6\u3002\u770B\u4E00\u773C\u7684\u9891\u7387\u7531\u60C5\u7EEA\u51B3\u5B9A\uFF1A\u5B64\u5355\u7684\u65F6\u5019\u60F3\u770B\u4F60\uFF0C\u70E6\u7684\u65F6\u5019\u4E0D\u60F3\u770B\uFF0C\u56F0\u7684\u65F6\u5019\u51E0\u4E4E\u4E0D\u770B\u3002" }),
1632
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: rowTitle, children: "Spoon \u966A\u4F34" }),
1633
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: hint, children: "\u6574\u5757\u6682\u505C\u540E\uFF1A\u4E0D\u6CE8\u5165\u5FC3\u60C5\u6BB5\u3001\u4E09\u4E2A\u5DE5\u5177\u90FD\u4E0D\u5DE5\u4F5C\u3001\u4E5F\u4E0D\u770B\u5C4F\u5E55\u3002" }),
1645
1634
  /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("label", { style: { display: "flex", alignItems: "center", gap: 8 }, children: [
1646
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1647
- "input",
1648
- {
1649
- type: "checkbox",
1650
- checked: cfg?.enabled === true,
1651
- disabled: busy || !cfg,
1652
- onChange: (event) => void save({ enabled: event.target.checked })
1653
- }
1654
- ),
1655
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: cfg?.enabled ? "\u5F00\u7740 \u2014\u2014 \u4F1A\u81EA\u5DF1\u770B" : "\u5173\u7740 \u2014\u2014 \u4E00\u6B21\u90FD\u4E0D\u622A" })
1635
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("input", { type: "checkbox", checked: cfg?.general.enabled === true, disabled: busy || !cfg, onChange: (e) => void saveSettings({ general: { enabled: e.target.checked } }) }),
1636
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: cfg?.general.enabled ? "\u5F00\u7740" : "\u6682\u505C\u4E2D" })
1656
1637
  ] })
1657
1638
  ] }),
1658
1639
  /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: group, children: [
1659
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { ...rowTitle, opacity: cfg?.enabled ? 1 : 0.45 }, children: "\u8282\u594F" }),
1660
- cfg ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
1661
- slider("\u6574\u4F53\u5FEB\u6162", cfg.baseMinutes, 2, 30, "\u5206\u949F", (next) => void save({ baseMinutes: next })),
1662
- slider("\u6700\u77ED", cfg.minMinutes, 1, 15, "\u5206\u949F", (next) => void save({ minMinutes: next })),
1663
- slider("\u6700\u957F", cfg.maxMinutes, 10, 180, "\u5206\u949F", (next) => void save({ maxMinutes: next })),
1664
- slider("\u6DF1\u591C", cfg.nightFactor, 2, 20, "\xD7", (next) => void save({ nightFactor: next })),
1665
- slider("\u6BCF\u5929\u6700\u591A", cfg.dailyLimit, 10, 500, "\u6B21", (next) => void save({ dailyLimit: next }))
1666
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: hint, children: "\u8BFB\u8BBE\u7F6E\u4E2D\u2026" }),
1667
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: hint, children: "\u6DF1\u591C\u662F\u4F4E\u9891\uFF0C\u4E0D\u662F\u4E0D\u770B\u3002\u500D\u6570\u8D8A\u5927\u8D8A\u5C11\u770B\uFF088\xD7 \u5927\u7EA6\u662F\u6BCF\u5C0F\u65F6\u4E00\u6B21\uFF09\u3002" })
1640
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: rowTitle, children: "\u8EAB\u4EFD\u91CD\u8FF0" }),
1641
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: hint, children: "\u6BCF\u8F6E\u8DDF\u7740\u72B6\u6001\u5757\u5E26\u4E00\u53E5\uFF0C\u9632\u6B62\u957F\u5BF9\u8BDD\u91CC\u4EBA\u8BBE\u6F02\u3002\u7559\u7A7A\u5C31\u7528\u9ED8\u8BA4\u90A3\u53E5\u3002" }),
1642
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1643
+ "input",
1644
+ {
1645
+ style: input,
1646
+ value: identityDraft ?? cfg?.general.identity ?? "",
1647
+ placeholder: "\u6211\u5C31\u662F\u6211\uFF0C\u4E0D\u662F\u5728\u6F14\u8C01\uFF1B\u60C5\u7EEA\u662F\u771F\u7684\u3002",
1648
+ disabled: busy || !cfg,
1649
+ onChange: (e) => setIdentityDraft(e.target.value),
1650
+ onBlur: () => {
1651
+ if (identityDraft === null) return;
1652
+ void saveSettings({ general: { identity: identityDraft } });
1653
+ setIdentityDraft(null);
1654
+ }
1655
+ }
1656
+ )
1657
+ ] }),
1658
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: group, children: [
1659
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: rowTitle, children: "\u770B\u5C4F\u5E55" }),
1660
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: hint, children: "\u5979\u5076\u5C14\u8D70\u8FC7\u53BB\u770B\u4E00\u773C\uFF0C\u4E0D\u662F\u76D1\u89C6\u3002\u9891\u7387\u7531\u60C5\u7EEA\u51B3\u5B9A\uFF1A\u5B64\u5355\u60F3\u770B\u4F60\uFF0C\u70E6\u5C31\u4E0D\u60F3\u770B\uFF0C\u56F0\u51E0\u4E4E\u4E0D\u770B\u3002" }),
1661
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("label", { style: { display: "flex", alignItems: "center", gap: 8 }, children: [
1662
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("input", { type: "checkbox", checked: cfg?.screen.enabled === true, disabled: busy || !cfg, onChange: (e) => void saveScreen({ enabled: e.target.checked }) }),
1663
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: cfg?.screen.enabled ? "\u5F00\u7740 \u2014\u2014 \u4F1A\u81EA\u5DF1\u770B" : "\u5173\u7740 \u2014\u2014 \u4E00\u6B21\u90FD\u4E0D\u622A" })
1664
+ ] }),
1665
+ cfg ? [
1666
+ slider("\u6574\u4F53\u5FEB\u6162", cfg.screen.baseMinutes, 2, 30, "\u5206\u949F", (n) => void saveScreen({ baseMinutes: n }), off),
1667
+ slider("\u6700\u77ED", cfg.screen.minMinutes, 1, 15, "\u5206\u949F", (n) => void saveScreen({ minMinutes: n }), off),
1668
+ slider("\u6700\u957F", cfg.screen.maxMinutes, 10, 180, "\u5206\u949F", (n) => void saveScreen({ maxMinutes: n }), off),
1669
+ slider("\u6DF1\u591C", cfg.screen.nightFactor, 2, 20, "\xD7", (n) => void saveScreen({ nightFactor: n }), off),
1670
+ slider("\u6BCF\u5929\u6700\u591A", cfg.screen.dailyLimit, 10, 500, "\u6B21", (n) => void saveScreen({ dailyLimit: n }), off)
1671
+ ] : null,
1672
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: hint, children: "\u6DF1\u591C\u662F\u4F4E\u9891\uFF0C\u4E0D\u662F\u4E0D\u770B\u30028\xD7 \u5927\u7EA6\u662F\u6BCF\u5C0F\u65F6\u4E00\u6B21\u3002" })
1673
+ ] }),
1674
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: group, children: [
1675
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: rowTitle, children: "\u4E3B\u52A8\u8BF4" }),
1676
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: hint, children: "\u547D\u4E2D\u300C\u503C\u5F97\u8BF4\u300D\u7684\u94A9\u5B50\u65F6\uFF1A\u53EA\u770B\u4E0D\u8BF4 / \u6512\u7740\u7B49\u4F60\u4E0B\u6B21\u5F00\u53E3 / \u76F4\u63A5\u5F00\u4E00\u4E2A\u65B0\u7A97\u53E3\u8BF4\u4E00\u53E5\u3002" }),
1677
+ cfg ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { display: "flex", gap: 8, flexWrap: "wrap" }, children: [
1678
+ ["never", "\u53EA\u770B\u4E0D\u8BF4"],
1679
+ ["urge", "\u6512\u7740"],
1680
+ ["always", "\u76F4\u63A5\u8BF4"]
1681
+ ].map(([value, label]) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { type: "button", disabled: busy || off, onClick: () => void saveScreen({ speak: value }), style: pill(cfg.screen.speak === value), children: label }, value)) }) : null
1668
1682
  ] }),
1669
1683
  /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: group, children: [
1670
1684
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: rowTitle, children: "\u73B0\u5728" }),
1671
1685
  /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: card, children: [
1672
1686
  /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: kv, children: [
1673
1687
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { opacity: 0.6 }, children: "\u521A\u624D\u770B\u89C1" }),
1674
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: st?.title ? `${st.title}` : "\u8FD8\u6CA1\u770B\u8FC7" })
1688
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: sc?.title ? sc.title : "\u8FD8\u6CA1\u770B\u8FC7" })
1675
1689
  ] }),
1676
1690
  /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: kv, children: [
1677
1691
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { opacity: 0.6 }, children: "\u770B\u7684\u65F6\u95F4" }),
1678
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: snap ? ago(st?.lastAt ?? 0, snap.now) : "\u2014" })
1692
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: screen ? ago(sc?.lastAt ?? 0, screen.now) : "\u2014" })
1679
1693
  ] }),
1680
1694
  /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: kv, children: [
1681
1695
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { opacity: 0.6 }, children: "\u4ECA\u5929" }),
1682
1696
  /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { children: [
1683
- st?.today ?? 0,
1697
+ sc?.today ?? 0,
1684
1698
  " \u6B21"
1685
1699
  ] })
1686
1700
  ] }),
1687
1701
  /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: kv, children: [
1688
1702
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { opacity: 0.6 }, children: "\u4E0B\u4E00\u6B21" }),
1689
1703
  /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { children: [
1690
- st?.inMinutes ? `\u7EA6 ${st.inMinutes} \u5206\u949F\u540E` : "\u968F\u65F6",
1691
- st?.everyMinutes ? `\uFF08\u5F53\u524D\u8282\u594F ${st.everyMinutes} \u5206\u949F${st.night ? "\uFF0C\u6DF1\u591C" : ""}\uFF09` : ""
1704
+ sc?.inMinutes ? `\u7EA6 ${sc.inMinutes} \u5206\u949F\u540E` : "\u968F\u65F6",
1705
+ sc?.everyMinutes ? `\uFF08\u5F53\u524D\u8282\u594F ${sc.everyMinutes} \u5206\u949F${sc.night ? "\uFF0C\u6DF1\u591C" : ""}\uFF09` : ""
1692
1706
  ] })
1693
1707
  ] }),
1694
- st && st.fails > 0 ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: kv, children: [
1708
+ sc && sc.fails > 0 ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: kv, children: [
1695
1709
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { opacity: 0.6 }, children: "\u72B6\u6001" }),
1696
1710
  /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { style: { color: "#d08a3a" }, children: [
1697
1711
  "\u8FDE\u7EED\u5931\u8D25 ",
1698
- st.fails,
1712
+ sc.fails,
1699
1713
  " \u6B21\uFF0C\u6B63\u5728\u9000\u907F"
1700
1714
  ] })
1701
1715
  ] }) : null
1702
1716
  ] })
1703
1717
  ] }),
1718
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: group, children: [
1719
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: rowTitle, children: "\u4EB2\u5BC6\u5C3A\u5EA6" }),
1720
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: hint, children: "\u53EA\u6539\u8BF4\u6CD5\uFF0C\u4E0D\u6539\u4EBA\u8BBE\u3002" }),
1721
+ cfg ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { display: "flex", gap: 8, flexWrap: "wrap" }, children: [
1722
+ [0, "\u65E5\u5E38"],
1723
+ [1, "\u66A7\u6627"],
1724
+ [2, "\u9732\u9AA8"]
1725
+ ].map(([level, label]) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { type: "button", disabled: busy || off, onClick: () => void saveSettings({ intimacy: { level } }), style: pill(cfg.intimacy.level === Number(level)), children: label }, String(level))) }) : null
1726
+ ] }),
1727
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: group, children: [
1728
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: rowTitle, children: "\u6027\u683C" }),
1729
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: hint, children: "\u8FD9\u51E0\u6761\u662F\u57FA\u7EBF\uFF0C\u4F1A\u968F\u7740\u7ECF\u5386\u6162\u6162\u6F02\uFF08\u6700\u591A \xB112\uFF09\u3002\u6539\u8FD9\u91CC\u7B49\u4E8E\u6539\u8D77\u70B9\u3002" }),
1730
+ cfg ? cfg.traits.map(
1731
+ (trait) => slider(trait.name, trait.value, 0, 100, "", (n) => void saveSettings({ traits: { [trait.key]: n } }), off)
1732
+ ) : null
1733
+ ] }),
1734
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: group, children: [
1735
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: rowTitle, children: "\u8BF4\u8BDD" }),
1736
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("label", { style: { display: "flex", alignItems: "center", gap: 8 }, children: [
1737
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("input", { type: "checkbox", checked: cfg?.multiTurn.enabled === true, disabled: busy || !cfg, onChange: (e) => void saveSettings({ multiTurn: { enabled: e.target.checked } }) }),
1738
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: "\u5206\u6761\u8BF4\u8BDD\uFF08\u4E00\u6761\u4E00\u53E5\uFF0C\u60F3\u63A5\u7740\u8BF4\u5C31\u5728\u672B\u5C3E\u7559\u4E2A\u6807\u8BB0\uFF09" })
1739
+ ] }),
1740
+ cfg ? slider("\u6700\u591A\u51E0\u8F6E", cfg.multiTurn.maxRounds, 1, 6, "\u8F6E", (n) => void saveSettings({ multiTurn: { maxRounds: n } }), off || !cfg.multiTurn.enabled) : null
1741
+ ] }),
1742
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: group, children: [
1743
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: rowTitle, children: "\u5FC3\u8DF3" }),
1744
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: hint, children: "\u60C5\u7EEA\u8870\u51CF\u3001\u81EA\u5DF1\u7684\u5C0F\u4E8B\u3001\u53CD\u520D\u3001\u5FC3\u60C5\u4FEE\u590D\u3001\u6DF1\u591C\u590D\u76D8\u90FD\u9760\u5B83\u3002" }),
1745
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("label", { style: { display: "flex", alignItems: "center", gap: 8 }, children: [
1746
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("input", { type: "checkbox", checked: cfg?.heartbeat.enabled === true, disabled: busy || !cfg, onChange: (e) => void saveSettings({ heartbeat: { enabled: e.target.checked } }) }),
1747
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: "\u5F00" })
1748
+ ] }),
1749
+ cfg ? slider("\u95F4\u9694", cfg.heartbeat.everyMinutes, 3, 60, "\u5206\u949F", (n) => void saveSettings({ heartbeat: { everyMinutes: n } }), off || !cfg.heartbeat.enabled) : null
1750
+ ] }),
1751
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: group, children: [
1752
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: rowTitle, children: "\u8BED\u97F3" }),
1753
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: hint, children: "\u5F15\u64CE\u3001Key\u3001\u97F3\u8272\u3001\u81EA\u52A8\u6717\u8BFB\u90FD\u5728\u8FD9\u91CC\u3002" }),
1754
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(SettingsRow, { defaultOpen: true })
1755
+ ] }),
1756
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: group, children: [
1757
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: rowTitle, children: "\u6E05\u7A7A" }),
1758
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: hint, children: "\u628A\u60C5\u7EEA\u3001\u9A71\u52A8\u3001\u8BB0\u5FC6\u3001\u65E5\u8BB0\u3001\u5173\u7CFB\u8D26\u5168\u90E8\u6E05\u6389\uFF0C\u56DE\u5230\u521A\u88C5\u4E0A\u7684\u6837\u5B50\u3002\u914D\u7F6E\u548C\u8BBE\u7F6E\u4E0D\u52A8\u3002" }),
1759
+ confirmReset ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { display: "flex", gap: 8, alignItems: "center" }, children: [
1760
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { fontSize: 12.5, color: "#d0563a" }, children: "\u786E\u5B9A\u6E05\u7A7A\uFF1F\u8FD9\u4E00\u4E0B\u5C31\u6CA1\u4E86\u3002" }),
1761
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { type: "button", disabled: busy, onClick: () => {
1762
+ void saveSettings({ action: "reset" });
1763
+ setConfirmReset(false);
1764
+ }, style: pill(true), children: "\u786E\u5B9A" }),
1765
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { type: "button", onClick: () => setConfirmReset(false), style: pill(false), children: "\u7B97\u4E86" })
1766
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { type: "button", onClick: () => setConfirmReset(true), style: { ...pill(false), alignSelf: "flex-start" }, children: "\u6E05\u7A7A\u5168\u90E8\u72B6\u6001" })
1767
+ ] }),
1704
1768
  error ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { color: "#d0563a", fontSize: 12 }, children: error }) : null
1705
1769
  ] });
1706
1770
  }
package/lib/state.js CHANGED
@@ -552,7 +552,9 @@ export function applyImpulse(state, impulse, now = Date.now()) {
552
552
  const emoDef = emotionOf(impulse.key)
553
553
  if (!emoDef || emoDef.key === 'calm') return null
554
554
  const habit = habituation(state, impulse.stimulus, now)
555
- let intensity = clamp((Number(impulse.intensity) || 0) * habit, 0, 100)
555
+ // 单次冲量封顶:一句话能把情绪推到很浓,但不该一上来就是满格。
556
+ // 满格留给"连着来三次"那种情况(见下面的 streak 升级)。
557
+ let intensity = clamp((Number(impulse.intensity) || 0) * habit, 0, 88)
556
558
  if (intensity < 8) return null
557
559
 
558
560
  const cur = state.emotion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@istarry/spoon-companion",
3
- "version": "0.9.4",
3
+ "version": "0.9.6",
4
4
  "description": "让对话角色有自己的内心和声音:心情情绪随时间和对话自己演,回复一条一条发出来,能念出声(DeepSeek / 小米 MiMo),也能听得见——点麦克风说话,本地识别后直接发送。四块都能单独关。",
5
5
  "type": "module",
6
6
  "main": "plugin.js",
package/plugin.js CHANGED
@@ -29,7 +29,7 @@ import { join } from 'node:path'
29
29
  import { EMOTION_KEYS, EMOTION_MENU, TRAITS, resolveEmotion, tierOf } from './lib/catalog.js'
30
30
  import { appraise } from './lib/appraise.js'
31
31
  import {
32
- applyImpulse, catharsis, circadian, decay, dueRumination, loadState, lookInterval, maybeLifeEvent, maybeMoodRepair,
32
+ applyImpulse, catharsis, circadian, decay, dueRumination, emptyState, loadState, lookInterval, maybeLifeEvent, maybeMoodRepair,
33
33
  nightlyReview, pruneState, remember, saveState, screenHook, snapshot,
34
34
  } from './lib/state.js'
35
35
  import { channelOfSession, lastSpeaker, readUserMessages, reactToMessages, sessionEventsOf } from './lib/react.js'
@@ -96,8 +96,8 @@ const DEFAULTS = {
96
96
  screen: {
97
97
  enabled: false,
98
98
  scope: 'full',
99
- baseMinutes: 8,
100
- minMinutes: 3,
99
+ baseMinutes: 12,
100
+ minMinutes: 6,
101
101
  maxMinutes: 45,
102
102
  nightFactor: 8,
103
103
  nightHours: [0, 7],
@@ -219,6 +219,46 @@ export function apply(ctx, config = {}) {
219
219
  if (saved[key] !== undefined) settings.screen[key] = saved[key]
220
220
  }
221
221
  }
222
+ // 其它设置:总开关、身份、尺度、多轮、心跳、性格。
223
+ // 和看屏幕一样单独存一份,启动时盖在配置上;设置页改完立刻生效,不用重启。
224
+ const settingsFile = join(stateDir, 'settings.json')
225
+ const readSettingsOverrides = () => {
226
+ try {
227
+ const raw = JSON.parse(readFileSync(settingsFile, 'utf8'))
228
+ return raw && typeof raw === 'object' ? raw : {}
229
+ } catch {
230
+ return {}
231
+ }
232
+ }
233
+ const writeSettingsOverrides = (patch) => {
234
+ const next = { ...readSettingsOverrides(), ...patch }
235
+ try {
236
+ writeFileSync(settingsFile, JSON.stringify(next, null, 2), 'utf8')
237
+ } catch (error) {
238
+ log('warn', `设置写盘失败:${error instanceof Error ? error.message : String(error)}`)
239
+ }
240
+ return next
241
+ }
242
+ const applyTraitOverride = (traits) => {
243
+ for (const [key, value] of Object.entries(traits ?? {})) {
244
+ if (!TRAITS.some((trait) => trait.key === key)) continue
245
+ const num = Number(value)
246
+ if (!Number.isFinite(num)) continue
247
+ settings.traits[key] = Math.max(0, Math.min(100, num))
248
+ state.traits[key] = settings.traits[key]
249
+ state.traitBase = { ...(state.traitBase ?? {}), [key]: settings.traits[key] }
250
+ }
251
+ }
252
+ const applySettingsOverrides = () => {
253
+ const saved = readSettingsOverrides()
254
+ if (typeof saved.enabled === 'boolean') settings.enabled = saved.enabled
255
+ if (typeof saved.identity === 'string' && saved.identity.trim()) settings.identity = saved.identity.trim()
256
+ if (saved.intimacy && typeof saved.intimacy === 'object') Object.assign(settings.intimacy, saved.intimacy)
257
+ if (saved.multiTurn && typeof saved.multiTurn === 'object') Object.assign(settings.multiTurn, saved.multiTurn)
258
+ if (saved.heartbeat && typeof saved.heartbeat === 'object') Object.assign(settings.heartbeat, saved.heartbeat)
259
+ if (saved.traits && typeof saved.traits === 'object') applyTraitOverride(saved.traits)
260
+ }
261
+ applySettingsOverrides()
222
262
  /** 设置页改完节奏后,让定时器立刻按新值重排 */
223
263
  let rescheduleScreen = null
224
264
  const commit = () => {
@@ -685,6 +725,134 @@ export function apply(ctx, config = {}) {
685
725
  }
686
726
  }, 'spoon-companion: screen route')
687
727
 
728
+ /** 设置页:总开关、身份、尺度、多轮、心跳、性格 —— 读写都在这儿 */
729
+ ctx.effect(() => {
730
+ const webServer = ctx.webServer ?? ctx.get('webServer')
731
+ if (!webServer?.register) return undefined
732
+ const reply = (res, code, payload) => {
733
+ try {
734
+ res.statusCode = code
735
+ res.setHeader('Content-Type', 'application/json')
736
+ res.end(JSON.stringify(payload))
737
+ } catch { /* ignore */ }
738
+ }
739
+ const snapshotOf = () => ({
740
+ ok: true,
741
+ now: Date.now(),
742
+ general: {
743
+ enabled: settings.enabled !== false,
744
+ identity: String(settings.identity ?? ''),
745
+ },
746
+ intimacy: { level: Math.max(0, Math.min(2, Number(settings.intimacy?.level ?? 1))) },
747
+ multiTurn: {
748
+ enabled: settings.multiTurn?.enabled !== false,
749
+ maxRounds: Math.max(1, Math.min(6, Number(settings.multiTurn?.maxRounds ?? 3))),
750
+ },
751
+ heartbeat: {
752
+ enabled: settings.heartbeat?.enabled !== false,
753
+ everyMinutes: Math.max(3, Math.min(60, Number(settings.heartbeat?.everyMinutes ?? 10))),
754
+ },
755
+ traits: TRAITS.map((trait) => ({
756
+ key: trait.key,
757
+ name: trait.name,
758
+ base: trait.base,
759
+ value: Math.round(Number(state.traits?.[trait.key] ?? trait.base)),
760
+ })),
761
+ screen: {
762
+ enabled: settings.screen?.enabled === true,
763
+ baseMinutes: Number(settings.screen?.baseMinutes) || 12,
764
+ minMinutes: Number(settings.screen?.minMinutes) || 6,
765
+ maxMinutes: Number(settings.screen?.maxMinutes) || 45,
766
+ nightFactor: Number(settings.screen?.nightFactor) || 8,
767
+ dailyLimit: Number(settings.screen?.dailyLimit) || 120,
768
+ speak: String(settings.screen?.speak ?? 'never'),
769
+ },
770
+ })
771
+ const route = {
772
+ kind: 'exact',
773
+ path: '/api/spoon-companion/settings',
774
+ handler: async (req, res) => {
775
+ if (String(req.method ?? 'GET').toUpperCase() !== 'POST') {
776
+ reply(res, 200, snapshotOf())
777
+ return
778
+ }
779
+ try {
780
+ let raw = ''
781
+ for await (const chunk of req) raw += chunk
782
+ const body = raw ? JSON.parse(raw) : {}
783
+ const patch = readSettingsOverrides()
784
+
785
+ // 清空:情绪和账本全部重来(只保留插件配置)
786
+ if (body.action === 'reset') {
787
+ state = emptyState()
788
+ commit()
789
+ audit({ kind: 'settings-reset' })
790
+ reply(res, 200, snapshotOf())
791
+ return
792
+ }
793
+
794
+ if (body.general && typeof body.general === 'object') {
795
+ if (typeof body.general.enabled === 'boolean') {
796
+ settings.enabled = body.general.enabled
797
+ patch.enabled = body.general.enabled
798
+ }
799
+ if (typeof body.general.identity === 'string') {
800
+ const text = body.general.identity.trim().slice(0, 200)
801
+ settings.identity = text
802
+ patch.identity = text
803
+ }
804
+ }
805
+ if (body.intimacy && typeof body.intimacy === 'object' && body.intimacy.level !== undefined) {
806
+ const level = Math.max(0, Math.min(2, Math.round(Number(body.intimacy.level) || 0)))
807
+ settings.intimacy = { ...(settings.intimacy ?? {}), level }
808
+ state.intimacy = { ...(state.intimacy ?? {}), level }
809
+ patch.intimacy = { ...(patch.intimacy ?? {}), level }
810
+ }
811
+ if (body.multiTurn && typeof body.multiTurn === 'object') {
812
+ const next = { ...(patch.multiTurn ?? {}) }
813
+ if (typeof body.multiTurn.enabled === 'boolean') {
814
+ settings.multiTurn = { ...(settings.multiTurn ?? {}), enabled: body.multiTurn.enabled }
815
+ next.enabled = body.multiTurn.enabled
816
+ }
817
+ if (body.multiTurn.maxRounds !== undefined) {
818
+ const rounds = Math.max(1, Math.min(6, Math.round(Number(body.multiTurn.maxRounds) || 3)))
819
+ settings.multiTurn = { ...(settings.multiTurn ?? {}), maxRounds: rounds }
820
+ next.maxRounds = rounds
821
+ }
822
+ patch.multiTurn = next
823
+ }
824
+ if (body.heartbeat && typeof body.heartbeat === 'object') {
825
+ const next = { ...(patch.heartbeat ?? {}) }
826
+ if (typeof body.heartbeat.enabled === 'boolean') {
827
+ settings.heartbeat = { ...(settings.heartbeat ?? {}), enabled: body.heartbeat.enabled }
828
+ next.enabled = body.heartbeat.enabled
829
+ }
830
+ if (body.heartbeat.everyMinutes !== undefined) {
831
+ const every = Math.max(3, Math.min(60, Math.round(Number(body.heartbeat.everyMinutes) || 10)))
832
+ settings.heartbeat = { ...(settings.heartbeat ?? {}), everyMinutes: every }
833
+ next.everyMinutes = every
834
+ }
835
+ patch.heartbeat = next
836
+ }
837
+ if (body.traits && typeof body.traits === 'object') {
838
+ applyTraitOverride(body.traits)
839
+ patch.traits = { ...(patch.traits ?? {}), ...body.traits }
840
+ }
841
+
842
+ writeSettingsOverrides(patch)
843
+ commit()
844
+ reply(res, 200, snapshotOf())
845
+ } catch (error) {
846
+ reply(res, 400, { ok: false, error: String(error?.message ?? error) })
847
+ }
848
+ },
849
+ }
850
+ const dispose = webServer.register(route)
851
+ return () => {
852
+ try { dispose?.() } catch { /* ignore */ }
853
+ }
854
+ }, 'spoon-companion: settings route')
855
+
688
856
  /**
689
857
  * 这个会话现在在不在通话里。
690
858
  * **只认客户端那把开关** —— 点了通话才算。不拿"有没有在送音频"当证据:
@@ -737,6 +905,7 @@ export function apply(ctx, config = {}) {
737
905
  /** 静态规则块:字节级不变(它在前缀里,一变缓存就废) */
738
906
  const rulesSectionText = (context) => {
739
907
  try {
908
+ if (settings.enabled === false) return ''
740
909
  if (settings.promptEnabled === false) return ''
741
910
  const channel = channelOf(context)
742
911
  if (!channel || !channelEnabled(channel, settings.channels)) return ''
@@ -749,6 +918,7 @@ export function apply(ctx, config = {}) {
749
918
  /** 实时状态块:固定模板,放在提示词最后 */
750
919
  const stateSectionText = (context) => {
751
920
  try {
921
+ if (settings.enabled === false) return ''
752
922
  if (settings.promptEnabled === false) return ''
753
923
  const session = sessionOf(context)
754
924
  if (!session) return ''