openclacky 1.5.22 → 1.5.24

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 (130) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +104 -0
  3. data/docs/secretary-prototype.md +286 -0
  4. data/lib/clacky/agent/cost_tracker.rb +55 -36
  5. data/lib/clacky/agent/hook_manager.rb +4 -1
  6. data/lib/clacky/agent/llm_caller.rb +46 -12
  7. data/lib/clacky/agent/memory_injector.rb +209 -0
  8. data/lib/clacky/agent/memory_updater.rb +16 -0
  9. data/lib/clacky/agent/session_serializer.rb +15 -11
  10. data/lib/clacky/agent/skill_manager.rb +30 -8
  11. data/lib/clacky/agent.rb +124 -17
  12. data/lib/clacky/agent_config.rb +7 -3
  13. data/lib/clacky/agent_profile.rb +33 -6
  14. data/lib/clacky/anthropic_stream_aggregator.rb +11 -1
  15. data/lib/clacky/bedrock_stream_aggregator.rb +11 -1
  16. data/lib/clacky/billing/platform_billing.rb +7 -0
  17. data/lib/clacky/cli.rb +4 -3
  18. data/lib/clacky/client.rb +30 -25
  19. data/lib/clacky/default_extensions/advisor/README.md +25 -0
  20. data/lib/clacky/default_extensions/advisor/README.zh.md +25 -0
  21. data/lib/clacky/default_extensions/advisor/ext.yml +1 -1
  22. data/lib/clacky/default_extensions/advisor/icon.svg +14 -0
  23. data/lib/clacky/default_extensions/advisor/panels/advisor/view.js +7 -1
  24. data/lib/clacky/default_extensions/coding/ext.yml +0 -1
  25. data/lib/clacky/default_extensions/computer-use/README.md +48 -0
  26. data/lib/clacky/default_extensions/computer-use/README.zh.md +48 -0
  27. data/lib/clacky/default_extensions/computer-use/ext.yml +1 -1
  28. data/lib/clacky/default_extensions/computer-use/icon.svg +16 -0
  29. data/lib/clacky/default_extensions/ext-studio/ext.yml +0 -1
  30. data/lib/clacky/default_extensions/general/ext.yml +0 -1
  31. data/lib/clacky/default_extensions/git/README.md +41 -0
  32. data/lib/clacky/default_extensions/git/README.zh.md +41 -0
  33. data/lib/clacky/default_extensions/git/ext.yml +1 -1
  34. data/lib/clacky/default_extensions/git/icon.svg +15 -0
  35. data/lib/clacky/default_extensions/git/panels/git/view.js +106 -27
  36. data/lib/clacky/default_extensions/meeting/README.md +46 -0
  37. data/lib/clacky/default_extensions/meeting/README.zh.md +47 -0
  38. data/lib/clacky/default_extensions/meeting/ext.yml +1 -1
  39. data/lib/clacky/default_extensions/meeting/icon.svg +13 -0
  40. data/lib/clacky/default_extensions/preview/README.md +29 -0
  41. data/lib/clacky/default_extensions/preview/README.zh.md +29 -0
  42. data/lib/clacky/default_extensions/preview/ext.yml +1 -1
  43. data/lib/clacky/default_extensions/preview/icon.svg +13 -0
  44. data/lib/clacky/default_extensions/secretary/README.md +69 -0
  45. data/lib/clacky/default_extensions/secretary/README.zh.md +69 -0
  46. data/lib/clacky/default_extensions/secretary/agents/secretary.md +41 -0
  47. data/lib/clacky/default_extensions/secretary/agents/worker.md +35 -0
  48. data/lib/clacky/default_extensions/secretary/api/handler.rb +8 -0
  49. data/lib/clacky/default_extensions/secretary/ext.yml +42 -0
  50. data/lib/clacky/default_extensions/secretary/icon.svg +17 -0
  51. data/lib/clacky/default_extensions/secretary/panels/work/view.js +344 -0
  52. data/lib/clacky/default_extensions/secretary/tools/delegate_work.rb +37 -0
  53. data/lib/clacky/default_extensions/secretary/tools/manage_work.rb +22 -0
  54. data/lib/clacky/default_extensions/secretary/tools/yield_work.rb +35 -0
  55. data/lib/clacky/default_extensions/time_machine/README.md +32 -0
  56. data/lib/clacky/default_extensions/time_machine/README.zh.md +32 -0
  57. data/lib/clacky/default_extensions/time_machine/ext.yml +1 -1
  58. data/lib/clacky/default_extensions/time_machine/icon.svg +14 -0
  59. data/lib/clacky/default_skills/channel-manager/SKILL.md +103 -13
  60. data/lib/clacky/default_skills/channel-manager/dingtalk_setup.rb +4 -2
  61. data/lib/clacky/default_skills/channel-manager/discord_setup.rb +9 -2
  62. data/lib/clacky/default_skills/channel-manager/weixin_setup.rb +10 -1
  63. data/lib/clacky/default_skills/cron-task-creator/SKILL.md +183 -206
  64. data/lib/clacky/default_skills/cron-task-creator/evals/evals.json +45 -0
  65. data/lib/clacky/default_skills/media-gen/SKILL.md +31 -14
  66. data/lib/clacky/default_skills/onboard/SKILL.md +5 -7
  67. data/lib/clacky/default_skills/persist-memory/SKILL.md +15 -1
  68. data/lib/clacky/extension/api_extension.rb +23 -2
  69. data/lib/clacky/extension/loader.rb +2 -0
  70. data/lib/clacky/extension/verifier.rb +2 -2
  71. data/lib/clacky/json_ui_controller.rb +14 -1
  72. data/lib/clacky/locales/en.rb +14 -0
  73. data/lib/clacky/locales/i18n.rb +25 -3
  74. data/lib/clacky/locales/zh.rb +14 -0
  75. data/lib/clacky/message_history.rb +15 -2
  76. data/lib/clacky/openai_responses_stream_aggregator.rb +11 -1
  77. data/lib/clacky/openai_stream_aggregator.rb +11 -1
  78. data/lib/clacky/prompts/base.md +1 -1
  79. data/lib/clacky/providers.rb +32 -17
  80. data/lib/clacky/server/backup_manager.rb +98 -2
  81. data/lib/clacky/server/browser_manager.rb +10 -5
  82. data/lib/clacky/server/channel/adapters/base.rb +18 -0
  83. data/lib/clacky/server/channel/adapters/feishu/message_parser.rb +1 -0
  84. data/lib/clacky/server/channel/adapters/telegram/adapter.rb +1 -0
  85. data/lib/clacky/server/channel/channel_config.rb +185 -48
  86. data/lib/clacky/server/channel/channel_manager.rb +247 -110
  87. data/lib/clacky/server/git_panel.rb +2 -1
  88. data/lib/clacky/server/http_server.rb +517 -175
  89. data/lib/clacky/server/preview.rb +26 -5
  90. data/lib/clacky/server/scheduler.rb +166 -85
  91. data/lib/clacky/server/web_ui_controller.rb +12 -0
  92. data/lib/clacky/session_manager.rb +4 -1
  93. data/lib/clacky/skill.rb +1 -1
  94. data/lib/clacky/tools/base.rb +7 -1
  95. data/lib/clacky/ui_interface.rb +5 -0
  96. data/lib/clacky/utils/file_processor.rb +23 -11
  97. data/lib/clacky/utils/model_pricing.rb +19 -0
  98. data/lib/clacky/version.rb +1 -1
  99. data/lib/clacky/web/app.css +621 -52
  100. data/lib/clacky/web/app.js +103 -9
  101. data/lib/clacky/web/components/code-editor.js +73 -4
  102. data/lib/clacky/web/components/custom-select.js +7 -18
  103. data/lib/clacky/web/components/hint-tip.js +172 -0
  104. data/lib/clacky/web/components/model-picker.js +1 -1
  105. data/lib/clacky/web/components/notify.js +37 -10
  106. data/lib/clacky/web/components/onboard.js +1 -1
  107. data/lib/clacky/web/components/sidebar.js +70 -0
  108. data/lib/clacky/web/features/backup/store.js +64 -27
  109. data/lib/clacky/web/features/backup/view.js +42 -11
  110. data/lib/clacky/web/features/channels/store.js +19 -4
  111. data/lib/clacky/web/features/channels/view.js +94 -33
  112. data/lib/clacky/web/features/extensions/view.js +15 -8
  113. data/lib/clacky/web/features/new-session/view.js +33 -22
  114. data/lib/clacky/web/features/profile/view.js +4 -4
  115. data/lib/clacky/web/features/tasks/store.js +5 -3
  116. data/lib/clacky/web/features/tasks/view.js +99 -26
  117. data/lib/clacky/web/features/trash/view.js +4 -4
  118. data/lib/clacky/web/features/workspace/view.js +193 -57
  119. data/lib/clacky/web/i18n.js +189 -17
  120. data/lib/clacky/web/index.html +165 -53
  121. data/lib/clacky/web/projects.js +15 -2
  122. data/lib/clacky/web/sessions.js +316 -86
  123. data/lib/clacky/web/settings.js +304 -75
  124. data/lib/clacky/web/utils.js +261 -0
  125. data/lib/clacky/web/ws-dispatcher.js +24 -3
  126. data/lib/clacky/web/ws.js +16 -4
  127. data/lib/clacky/work/service.rb +544 -0
  128. data/lib/clacky/work/store.rb +57 -0
  129. data/lib/clacky.rb +1 -0
  130. metadata +35 -1
@@ -12,6 +12,7 @@ const Settings = (() => {
12
12
  // backend's runtime inference decide.
13
13
  let _modalSelectedProviderId = null;
14
14
  let _modalProviderIsCustom = false;
15
+ let _noVisionTouched = false; // user clicked the no-vision box; stop auto-filling it
15
16
  let _apiFormatSelect = null;
16
17
  let _providerSelect = null;
17
18
  let _providerFilterSelect = null;
@@ -190,6 +191,37 @@ const Settings = (() => {
190
191
  if (noVision) noVision.style.display = _modalProviderIsCustom ? "" : "none";
191
192
  }
192
193
 
194
+ // Custom endpoints only: pre-fill "no vision" from what the presets declare
195
+ // for the same model name. Unknown or conflicting names leave the box alone.
196
+ function _syncNoVisionFromModel() {
197
+ if (!_modalProviderIsCustom || _noVisionTouched) return;
198
+ const vision = _knownVision(document.getElementById("model-modal-model").value);
199
+ if (vision !== null) document.getElementById("model-modal-no-vision").checked = !vision;
200
+ }
201
+
202
+ // "Z-AI/GLM_5.3" → "z-ai-glm-5-3", so relay prefixes/suffixes become plain segments.
203
+ function _modelKey(name) {
204
+ return String(name || "").trim().toLowerCase().replace(/[^a-z0-9]+/g, "-");
205
+ }
206
+
207
+ // The longest known name found as whole segments wins: "x-glm-5.3-flash" is glm-5.3-flash, not glm-5.3.
208
+ function _knownVision(name) {
209
+ const key = _modelKey(name);
210
+ if (!key) return null;
211
+ const padded = "-" + key + "-";
212
+ let best = 0;
213
+ let seen = new Set();
214
+ _providers.forEach(p => {
215
+ Object.entries(p.model_capabilities || {}).forEach(([m, caps]) => {
216
+ const known = _modelKey(m);
217
+ if (typeof caps.vision !== "boolean" || known.length < best || !padded.includes("-" + known + "-")) return;
218
+ if (known.length > best) { best = known.length; seen = new Set(); }
219
+ seen.add(caps.vision);
220
+ });
221
+ });
222
+ return seen.size === 1 ? seen.values().next().value : null;
223
+ }
224
+
193
225
  // Preset providers auto-fill Base URL and Model, which leaves users unsure
194
226
  // whether a key alone is enough. Only claim that when it is actually true:
195
227
  // a custom endpoint also needs a Base URL and model, and a saved key (edit /
@@ -349,6 +381,23 @@ const Settings = (() => {
349
381
 
350
382
  // ── Modal Functions ────────────────────────────────────────────────────────
351
383
 
384
+ // "Get API Key" link follows the currently resolved provider only; it must
385
+ // be re-synced on every modal open, or it leaks from the previous session.
386
+ function _syncApikeyLink() {
387
+ const link = document.getElementById("model-modal-apikey-link");
388
+ if (!link) return;
389
+ const preset = _modalSelectedProviderId
390
+ ? _providers.find(p => p.id === _modalSelectedProviderId)
391
+ : null;
392
+ if (preset && preset.website_url) {
393
+ link.href = preset.website_url;
394
+ link.style.display = "";
395
+ } else {
396
+ link.removeAttribute("href");
397
+ link.style.display = "none";
398
+ }
399
+ }
400
+
352
401
  function _openModal(index = -1) {
353
402
  const modal = document.getElementById("model-edit-modal");
354
403
  const titleEl = document.getElementById("model-modal-title");
@@ -358,6 +407,7 @@ const Settings = (() => {
358
407
  document.getElementById("model-modal-source-id").value = "";
359
408
  // Drop any model list fetched for a previously opened model/endpoint.
360
409
  _modalRemoteModels = null;
410
+ _noVisionTouched = false;
361
411
 
362
412
  // Populate provider dropdown
363
413
  _populateModalProviderDropdown();
@@ -401,6 +451,7 @@ const Settings = (() => {
401
451
  noVision.checked = !!(model.capabilities && model.capabilities.vision === false);
402
452
  _syncRemarkField();
403
453
  _syncApikeyHint();
454
+ _syncApikeyLink();
404
455
  } else {
405
456
  // Add mode
406
457
  titleEl.textContent = I18n.t("settings.models.modal.add");
@@ -424,6 +475,7 @@ const Settings = (() => {
424
475
  _syncApiFormatVisibility();
425
476
  _syncRemarkField();
426
477
  _syncApikeyHint();
478
+ _syncApikeyLink();
427
479
  const providerValue = document.getElementById("model-modal-provider-value");
428
480
  providerValue.textContent = I18n.t("settings.models.placeholder.provider");
429
481
  providerValue.classList.add("placeholder");
@@ -438,9 +490,7 @@ const Settings = (() => {
438
490
  document.getElementById("model-modal-test-result").textContent = "";
439
491
  document.getElementById("model-modal-test-result").className = "model-test-result";
440
492
 
441
- // Show promo hint by default for new models
442
- const promoHint = document.getElementById("model-modal-promo-hint");
443
- _showPromoHint(promoHint);
493
+ _syncPromoHint(document.getElementById("model-modal-promo-hint"));
444
494
 
445
495
  modal.style.display = "";
446
496
  document.body.style.overflow = "hidden";
@@ -493,6 +543,7 @@ const Settings = (() => {
493
543
  }
494
544
  _syncRemarkField();
495
545
  _syncApikeyHint();
546
+ _syncApikeyLink();
496
547
  }
497
548
 
498
549
  // API Format only applies to custom providers: preset routing is owned by
@@ -511,7 +562,7 @@ const Settings = (() => {
511
562
  dropdown.innerHTML = `
512
563
  <div class="custom-select-list">
513
564
  <div class="custom-select-option" data-value="">${I18n.t("settings.models.placeholder.provider")}</div>
514
- ${_providers.map(p => { const dn = _providerDisplayName(p); return `<div class="custom-select-option" data-value="${p.id}" data-label="${_esc(dn)}">${_esc(dn)}${p.id === "openclacky" ? ` <span class="provider-badge-recommended">${I18n.t("provider.recommended")}</span>` : ""}</div>`; }).join("")}
565
+ ${_providers.map(p => { const dn = _providerDisplayName(p); return `<div class="custom-select-option" data-value="${p.id}" data-label="${_esc(dn)}">${_esc(dn)}${p.id === "openclacky" ? ` <span class="provider-badge-recommended" data-tooltip-pos="right" data-tooltip-wide data-tooltip="${_esc(I18n.t("provider.recommended.tooltip"))}">${I18n.t("provider.recommended")}</span>` : ""}</div>`; }).join("")}
515
566
  </div>
516
567
  <div class="custom-select-option custom-select-option-custom" data-value="custom" data-label="${_esc(I18n.t("settings.models.custom"))}">
517
568
  <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 20h9"/><path d="M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"/></svg>
@@ -604,10 +655,10 @@ const Settings = (() => {
604
655
  const payload = { model, base_url, anthropic_format, api_format, provider_id: _modalProviderIsCustom ? "custom" : (_modalSelectedProviderId || null) };
605
656
  payload.remark = document.getElementById("model-modal-remark").value.trim();
606
657
  // Vision override only applies to custom (non-preset) providers — preset
607
- // capability tables live server-side. Checked → vision:false; unchecked →
608
- // {} so the backend clears any previously-saved override.
658
+ // capability tables live server-side. The box is only hidden for presets,
659
+ // so its stale state must not leak; {} clears any previously-saved override.
609
660
  const noVision = document.getElementById("model-modal-no-vision").checked;
610
- payload.capabilities = noVision ? { vision: false } : {};
661
+ payload.capabilities = (_modalProviderIsCustom && noVision) ? { vision: false } : {};
611
662
  const setDefault = document.getElementById("model-modal-set-default").checked;
612
663
  payload.type = setDefault ? "default" : null;
613
664
  if (setDefault) {
@@ -656,22 +707,14 @@ const Settings = (() => {
656
707
  }
657
708
 
658
709
  function _positionDropdownFixed(dropdown, anchor) {
659
- const rect = anchor.getBoundingClientRect();
660
- dropdown.style.position = "fixed";
661
- dropdown.style.top = (rect.bottom + 4) + "px";
662
- dropdown.style.left = rect.left + "px";
663
- dropdown.style.width = rect.width + "px";
664
- dropdown.style.right = "auto";
665
- dropdown.style.zIndex = "9999";
710
+ // Set the width before measuring: a narrower panel wraps more and needs
711
+ // more vertical room.
712
+ dropdown.style.width = anchor.getBoundingClientRect().width + "px";
713
+ FloatingDropdown.place(dropdown, anchor);
666
714
  }
667
715
 
668
716
  function _resetDropdownPosition(dropdown) {
669
- dropdown.style.position = "";
670
- dropdown.style.top = "";
671
- dropdown.style.left = "";
672
- dropdown.style.width = "";
673
- dropdown.style.right = "";
674
- dropdown.style.zIndex = "";
717
+ FloatingDropdown.reset(dropdown);
675
718
  }
676
719
 
677
720
  function _openProviderDropdown() {
@@ -716,14 +759,10 @@ const Settings = (() => {
716
759
  _syncApiFormatVisibility();
717
760
  _syncRemarkField();
718
761
  _syncApikeyHint();
762
+ _syncApikeyLink();
719
763
 
720
764
  // Show/hide promo hint
721
- const promoHint = document.getElementById("model-modal-promo-hint");
722
- if (value === "openclacky" || !value) {
723
- _showPromoHint(promoHint);
724
- } else {
725
- promoHint.classList.remove("visible");
726
- }
765
+ _syncPromoHint(document.getElementById("model-modal-promo-hint"));
727
766
 
728
767
  // Auto-fill if provider selected
729
768
  if (value && value !== "custom") {
@@ -732,14 +771,6 @@ const Settings = (() => {
732
771
  document.getElementById("model-modal-model").value = preset.default_model || "";
733
772
  document.getElementById("model-modal-baseurl").value = preset.base_url || "";
734
773
 
735
- const apikeyLink = document.getElementById("model-modal-apikey-link");
736
- if (preset.website_url) {
737
- apikeyLink.href = preset.website_url;
738
- apikeyLink.style.display = "";
739
- } else {
740
- apikeyLink.style.display = "none";
741
- }
742
-
743
774
  // Update model dropdown with provider's models
744
775
  setTimeout(() => _updateModalModelDropdown(), 0);
745
776
  }
@@ -748,7 +779,6 @@ const Settings = (() => {
748
779
  // clear leftover model/base_url so stale values never survive.
749
780
  document.getElementById("model-modal-model").value = "";
750
781
  document.getElementById("model-modal-baseurl").value = "";
751
- document.getElementById("model-modal-apikey-link").style.display = "none";
752
782
  setTimeout(() => _updateModalModelDropdown(), 0);
753
783
  }
754
784
  }
@@ -784,9 +814,11 @@ const Settings = (() => {
784
814
  _closeBaseUrlDropdown();
785
815
  _closeProviderDropdown();
786
816
  _updateModalModelDropdown();
787
- _positionDropdownFixed(modelDropdown, modelCombobox);
788
817
  modelDropdown.style.display = "block";
789
818
  document.body.appendChild(modelDropdown);
819
+ // Measure only after the panel is in the document, otherwise
820
+ // scrollHeight is 0 and the flip-up decision is blind.
821
+ _positionDropdownFixed(modelDropdown, modelCombobox);
790
822
  // Opening the dropdown is an explicit "show me what this endpoint
791
823
  // offers" intent — fetch when there is no fresh list yet. Masked keys
792
824
  // are allowed on this trigger only: the server resolves them from the
@@ -819,9 +851,9 @@ const Settings = (() => {
819
851
  _closeModelDropdown();
820
852
  _closeProviderDropdown();
821
853
  _updateModalBaseUrlDropdown();
822
- _positionDropdownFixed(baseUrlDropdown, baseUrlCombobox);
823
854
  baseUrlDropdown.style.display = "block";
824
855
  document.body.appendChild(baseUrlDropdown);
856
+ _positionDropdownFixed(baseUrlDropdown, baseUrlCombobox);
825
857
  }
826
858
 
827
859
  function _closeBaseUrlDropdown() {
@@ -855,6 +887,14 @@ const Settings = (() => {
855
887
  });
856
888
 
857
889
  document.getElementById("model-modal-apikey").addEventListener("input", _syncApikeyHint);
890
+ modelInput.addEventListener("change", _syncNoVisionFromModel);
891
+ // pointerdown fires before the model input blurs, so a click straight from
892
+ // the model field onto the box is not overridden by the change handler.
893
+ const noVisionField = document.getElementById("model-modal-no-vision-field");
894
+ noVisionField.addEventListener("pointerdown", () => { _noVisionTouched = true; });
895
+ document.getElementById("model-modal-no-vision").addEventListener("change", () => {
896
+ _noVisionTouched = true;
897
+ });
858
898
 
859
899
  // Close dropdowns on outside click
860
900
  document.addEventListener("mousedown", (e) => {
@@ -922,6 +962,7 @@ const Settings = (() => {
922
962
  opt.addEventListener("click", (e) => {
923
963
  e.stopPropagation();
924
964
  modelInput.value = opt.dataset.value;
965
+ _syncNoVisionFromModel();
925
966
  modelDropdown.style.display = "none";
926
967
  });
927
968
  });
@@ -1071,15 +1112,53 @@ const Settings = (() => {
1071
1112
  });
1072
1113
  }
1073
1114
 
1115
+ // The OpenClacky AI Keys ad appears twice (model modal + Secondary Models).
1116
+ // It's the same campaign, so one dismissal silences both — nobody wants to
1117
+ // hunt down a banner twice.
1118
+ const AI_KEYS_PROMO_DISMISSED_KEY = "clacky-ai-keys-promo-dismissed";
1119
+
1120
+ function _aiKeysPromoDismissed() {
1121
+ try { return localStorage.getItem(AI_KEYS_PROMO_DISMISSED_KEY) === "1"; } catch (_) { return false; }
1122
+ }
1123
+
1124
+ function _dismissAiKeysPromo() {
1125
+ try { localStorage.setItem(AI_KEYS_PROMO_DISMISSED_KEY, "1"); } catch (_) {}
1126
+ _updateMediaPromo();
1127
+ _syncPromoHint(document.getElementById("model-modal-promo-hint"));
1128
+ }
1129
+
1130
+ // The OpenClacky AI Keys promo only makes sense while the provider is still
1131
+ // unpicked (add flow) or is OpenClacky itself; editing e.g. a DeepSeek model
1132
+ // has nothing to gain from it.
1133
+ function _shouldShowPromo(providerId, isCustom) {
1134
+ if (_aiKeysPromoDismissed()) return false;
1135
+ if (isCustom) return false;
1136
+ return !providerId || providerId === "openclacky";
1137
+ }
1138
+
1139
+ function _syncPromoHint(promoHint) {
1140
+ if (!promoHint) return;
1141
+ if (_shouldShowPromo(_modalSelectedProviderId, _modalProviderIsCustom)) {
1142
+ _showPromoHint(promoHint);
1143
+ } else {
1144
+ promoHint.classList.remove("visible");
1145
+ }
1146
+ }
1147
+
1074
1148
  function _showPromoHint(promoHint) {
1075
1149
  const items = [
1076
1150
  I18n.t("provider.promo.openclacky.1"),
1077
1151
  I18n.t("provider.promo.openclacky.2"),
1078
1152
  I18n.t("provider.promo.openclacky.3"),
1079
1153
  ];
1080
- const title = `<div class="promo-title">${I18n.t("provider.promo.openclacky.title")}</div>`;
1081
- const body = items.map(s => `<div class="promo-item"><span class="promo-icon">✦</span>${s}</div>`).join("");
1154
+ const oc = _providers.find(p => p.id === "openclacky");
1155
+ const url = (oc && oc.website_url) || "https://www.openclacky.com/llm_keys";
1156
+ const arrow = `<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12h14"/><path d="M13 6l6 6-6 6"/></svg>`;
1157
+ const link = `<a class="promo-link" href="${_esc(url)}" target="_blank" rel="noopener">${I18n.t("settings.media.promo.btn")}${arrow}</a>`;
1158
+ const title = `<div class="promo-head"><span class="promo-title">${I18n.t("provider.promo.openclacky.title")}</span></div>`;
1159
+ const body = items.map(s => `<div class="promo-item"><span class="promo-dot" aria-hidden="true"></span><span>${s}</span></div>`).join("");
1082
1160
  promoHint.innerHTML = `<div class="promo-inner">${title}${body}</div>`;
1161
+ promoHint.querySelector(".promo-head").insertAdjacentHTML("beforeend", link);
1083
1162
  promoHint.classList.add("visible");
1084
1163
  }
1085
1164
 
@@ -1609,8 +1688,8 @@ const Settings = (() => {
1609
1688
  const toggleInput = document.getElementById("browser-toggle-input");
1610
1689
  const shotWrap = document.getElementById("browser-screenshot-settings");
1611
1690
 
1612
- // File doesn't exist → not set up yet
1613
- if (data.enabled === undefined || data.enabled === null) {
1691
+ // browser.yml missing → never set up, no toggle to offer
1692
+ if (data.configured === false) {
1614
1693
  desc.textContent = I18n.t("settings.browser.desc");
1615
1694
  btn.textContent = I18n.t("settings.browser.btn");
1616
1695
  toggleWrap.style.display = "none";
@@ -1625,6 +1704,11 @@ const Settings = (() => {
1625
1704
  toggleWrap.style.display = "inline-block";
1626
1705
  toggleInput.checked = data.enabled;
1627
1706
 
1707
+ const toggleHint = I18n.t(data.enabled ? "settings.browser.toggle.turnOff" : "settings.browser.toggle.turnOn");
1708
+ toggleWrap.setAttribute("data-tooltip", toggleHint);
1709
+ toggleWrap.setAttribute("data-tooltip-pos", "top");
1710
+ toggleInput.setAttribute("aria-label", toggleHint);
1711
+
1628
1712
  // Only bind once
1629
1713
  if (!toggleInput.dataset.bound) {
1630
1714
  toggleInput.dataset.bound = "1";
@@ -1681,11 +1765,23 @@ const Settings = (() => {
1681
1765
  try {
1682
1766
  const res = await fetch("/api/browser/toggle", { method: "POST" });
1683
1767
  const data = await res.json();
1684
- if (!data.ok) throw new Error(data.error || "toggle failed");
1768
+ if (!data.ok) {
1769
+ const err = new Error(data.error || "toggle failed");
1770
+ err.code = data.code;
1771
+ throw err;
1772
+ }
1685
1773
  await _loadBrowserStatus();
1686
- } catch (_) {
1687
- // Revert on failure
1688
- toggleInput.checked = !toggleInput.checked;
1774
+ } catch (e) {
1775
+ // Revert on failure — the switch must never claim a state the server rejected.
1776
+ toggleInput.checked = !toggleInput.checked;
1777
+ console.warn("[settings] browser toggle failed:", e);
1778
+ if (e.code === "not_configured") {
1779
+ // browser.yml vanished (or was never written) — fall back to the setup prompt.
1780
+ await _loadBrowserStatus();
1781
+ Modal.toast(I18n.t("settings.browser.toggle.notConfigured"), "error");
1782
+ } else {
1783
+ Modal.toast(I18n.t("settings.browser.toggle.failed"), "error");
1784
+ }
1689
1785
  } finally {
1690
1786
  toggleInput.disabled = false;
1691
1787
  }
@@ -2377,9 +2473,11 @@ const Settings = (() => {
2377
2473
  const comp = document.getElementById("settings-compression-toggle");
2378
2474
  const cache = document.getElementById("settings-prompt-caching-toggle");
2379
2475
  const mem = document.getElementById("settings-memory-update-toggle");
2476
+ const inject = document.getElementById("settings-memory-inject-toggle");
2380
2477
  if (comp) comp.checked = data.enable_compression !== false;
2381
2478
  if (cache) cache.checked = data.enable_prompt_caching !== false;
2382
2479
  if (mem) mem.checked = data.memory_update_enabled !== false;
2480
+ if (inject) inject.checked = data.memory_inject_enabled === true;
2383
2481
  }
2384
2482
  } catch (e) {
2385
2483
  console.error("Failed to load advanced settings:", e);
@@ -2409,6 +2507,9 @@ const Settings = (() => {
2409
2507
  document.getElementById("settings-memory-update-toggle")?.addEventListener("change", (e) => {
2410
2508
  _saveAdvancedSetting("memory_update_enabled", e.target.checked);
2411
2509
  });
2510
+ document.getElementById("settings-memory-inject-toggle")?.addEventListener("change", (e) => {
2511
+ _saveAdvancedSetting("memory_inject_enabled", e.target.checked);
2512
+ });
2412
2513
  }
2413
2514
 
2414
2515
  // ── About Tab ───────────────────────────────────────────────────────────────
@@ -2436,6 +2537,42 @@ const Settings = (() => {
2436
2537
  // { source, configured, model, base_url, api_key_masked, provider, available }
2437
2538
 
2438
2539
  const MEDIA_KINDS = ["image", "video", "audio", "stt", "video_understanding", "ocr"];
2540
+
2541
+ // Capability glyph shown before each row title, so the six rows can be
2542
+ // told apart at a glance. Stroke icons (24×24, currentColor) in the same
2543
+ // line style as the rest of the settings UI.
2544
+ const MEDIA_KIND_ICONS = {
2545
+ image: '<rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="9" cy="9" r="2"/><path d="m21 15-3.1-3.1a2 2 0 0 0-2.8 0L6 21"/>',
2546
+ video: '<rect x="2" y="6" width="14" height="12" rx="2"/><path d="m22 8-6 4 6 4V8Z"/>',
2547
+ audio: '<path d="M11 5 6 9H2v6h4l5 4V5Z"/><path d="M15.54 8.46a5 5 0 0 1 0 7.07"/><path d="M19.07 4.93a10 10 0 0 1 0 14.14"/>',
2548
+ stt: '<rect x="9" y="2" width="6" height="12" rx="3"/><path d="M19 10v1a7 7 0 0 1-14 0v-1"/><path d="M12 18v4"/><path d="M8 22h8"/>',
2549
+ video_understanding: '<rect x="2" y="4" width="20" height="16" rx="2"/><path d="m10 9 5 3-5 3V9Z"/>',
2550
+ ocr: '<path d="M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7S2 12 2 12Z"/><circle cx="12" cy="12" r="3"/>'
2551
+ };
2552
+
2553
+ function _mediaKindIcon(kind) {
2554
+ const el = document.createElement("span");
2555
+ el.className = "media-kind-icon";
2556
+ el.dataset.kind = kind;
2557
+ el.setAttribute("aria-hidden", "true");
2558
+ el.innerHTML = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" ' +
2559
+ 'stroke-linecap="round" stroke-linejoin="round">' + (MEDIA_KIND_ICONS[kind] || "") + "</svg>";
2560
+ return el;
2561
+ }
2562
+
2563
+ // "[vendor mark] Friendly Name" — reuses the model list's vendor badge so
2564
+ // a sidecar model looks the same here as it does in the model picker.
2565
+ function _mediaModelChip(modelId, text, extraClass) {
2566
+ const el = document.createElement("span");
2567
+ el.className = "media-model-chip" + (extraClass ? " " + extraClass : "");
2568
+ if (modelId) el.appendChild(ModelPicker.vendorBadge(modelId));
2569
+ const label = document.createElement("span");
2570
+ label.className = "media-model-chip-label";
2571
+ label.textContent = text || modelId || "";
2572
+ el.appendChild(label);
2573
+ return el;
2574
+ }
2575
+
2439
2576
  let _mediaState = null;
2440
2577
  let _mediaDefaults = null;
2441
2578
  const _mediaCustomDraft = {};
@@ -2461,7 +2598,23 @@ const Settings = (() => {
2461
2598
  }
2462
2599
  }
2463
2600
 
2601
+ // Promo for OpenClacky AI Keys: one key unlocks every secondary model.
2602
+ // Hidden when the user dismissed it, when the default provider is already
2603
+ // openclacky (nothing to sell) and in white-label builds (a third-party brand
2604
+ // shouldn't advertise us).
2605
+ function _updateMediaPromo() {
2606
+ const promo = document.getElementById("media-promo");
2607
+ if (!promo) return;
2608
+ const branded = typeof Brand !== "undefined" && Brand.branded;
2609
+ const provider = Object.values(_mediaDefaults || {})
2610
+ .map(d => d && d.provider)
2611
+ .find(Boolean);
2612
+ const show = !branded && !_aiKeysPromoDismissed() && provider !== "openclacky";
2613
+ promo.style.display = show ? "" : "none";
2614
+ }
2615
+
2464
2616
  function _renderMediaRows() {
2617
+ _updateMediaPromo();
2465
2618
  const container = document.getElementById("media-rows");
2466
2619
  if (!container) return;
2467
2620
  container.innerHTML = "";
@@ -2498,7 +2651,10 @@ const Settings = (() => {
2498
2651
 
2499
2652
  const title = document.createElement("span");
2500
2653
  title.className = "media-row-title";
2501
- title.textContent = I18n.t(`settings.media.kind.${kind}`);
2654
+ title.appendChild(_mediaKindIcon(kind));
2655
+ const titleText = document.createElement("span");
2656
+ titleText.textContent = I18n.t(`settings.media.kind.${kind}`);
2657
+ title.appendChild(titleText);
2502
2658
  head.appendChild(title);
2503
2659
 
2504
2660
  // When the default chat model already supports vision, the OCR sidecar
@@ -2512,7 +2668,7 @@ const Settings = (() => {
2512
2668
 
2513
2669
  const model = document.createElement("span");
2514
2670
  model.className = "media-vision-primary-model";
2515
- model.textContent = state.model || "";
2671
+ if (state.model) model.appendChild(_mediaModelChip(state.model, state.model));
2516
2672
  head.appendChild(model);
2517
2673
 
2518
2674
  row.appendChild(head);
@@ -2539,7 +2695,11 @@ const Settings = (() => {
2539
2695
 
2540
2696
  const status = document.createElement("span");
2541
2697
  status.className = "media-row-status";
2542
- status.textContent = _mediaStatusText(kind, state, def);
2698
+ const statusText = _mediaStatusText(kind, state, def);
2699
+ if (statusText) {
2700
+ status.appendChild(_mediaModelChip(state.model, statusText));
2701
+ status.title = state.model || "";
2702
+ }
2543
2703
  head.appendChild(status);
2544
2704
 
2545
2705
  row.appendChild(head);
@@ -2553,7 +2713,10 @@ const Settings = (() => {
2553
2713
  function _mediaStatusText(kind, state, def) {
2554
2714
  if (state.source === "off") return "";
2555
2715
  if (state.source === "auto") {
2556
- if (state.configured && state.model) return state.model;
2716
+ if (state.configured && state.model) {
2717
+ const aliases = (state.aliases && typeof state.aliases === "object") ? state.aliases : {};
2718
+ return aliases[state.model] || state.model;
2719
+ }
2557
2720
  return "";
2558
2721
  }
2559
2722
  return "";
@@ -2582,37 +2745,85 @@ const Settings = (() => {
2582
2745
  const modelField = _buildField(I18n.t("settings.media.field.model"));
2583
2746
  const opts = Array.isArray(state.available) ? state.available : [];
2584
2747
  const aliases = (state.aliases && typeof state.aliases === "object") ? state.aliases : {};
2585
- const labelOf = (m) => aliases[m] ? `${m} (${aliases[m]})` : m;
2748
+ // Friendly label: "Nano Banana 2.1 — 推荐 · 日常出图…". Raw model IDs
2749
+ // mean nothing to end users, so the alias leads and an optional
2750
+ // one-line hint (i18n key settings.media.modelHint.<id>) explains
2751
+ // when to pick it. Falls back to the raw ID when no alias exists.
2752
+ const hintOf = (m) => {
2753
+ const key = `settings.media.modelHint.${m}`;
2754
+ const h = I18n.t(key);
2755
+ return h === key ? "" : h;
2756
+ };
2757
+ const nameOf = (m) => aliases[m] || m;
2758
+ const labelOf = (m) => {
2759
+ const hint = hintOf(m);
2760
+ return hint ? `${nameOf(m)} — ${hint}` : nameOf(m);
2761
+ };
2586
2762
  if (opts.length > 1) {
2587
- const sel = document.createElement("select");
2588
- sel.className = "field-select";
2763
+ // Custom dropdown instead of a native <select>: native options
2764
+ // cannot render the vendor mark next to each model name.
2765
+ const wrapper = document.createElement("div");
2766
+ wrapper.className = "custom-select-wrapper media-model-select";
2767
+
2768
+ const trigger = document.createElement("div");
2769
+ trigger.className = "custom-select-trigger";
2770
+ trigger.tabIndex = 0;
2771
+ const valueSpan = document.createElement("span");
2772
+ valueSpan.className = "custom-select-value";
2773
+ const renderValue = (m) => {
2774
+ valueSpan.innerHTML = "";
2775
+ valueSpan.appendChild(_mediaModelChip(m, labelOf(m)));
2776
+ trigger.title = m;
2777
+ };
2778
+ renderValue(state.model);
2779
+ trigger.appendChild(valueSpan);
2780
+ trigger.insertAdjacentHTML("beforeend",
2781
+ '<svg class="custom-select-arrow" fill="none" stroke="currentColor" viewBox="0 0 24 24">' +
2782
+ '<path stroke-linecap="round" stroke-linejoin="round" d="M19 9l-7 7-7-7"/></svg>');
2783
+
2784
+ const dropdown = document.createElement("div");
2785
+ dropdown.className = "custom-select-dropdown media-model-dropdown";
2589
2786
  opts.forEach(m => {
2590
- const o = document.createElement("option");
2591
- o.value = m;
2592
- o.textContent = labelOf(m);
2593
- if (m === state.model) o.selected = true;
2594
- sel.appendChild(o);
2787
+ const o = document.createElement("div");
2788
+ o.className = "custom-select-option" + (m === state.model ? " selected" : "");
2789
+ o.dataset.value = m;
2790
+ o.title = m;
2791
+ o.appendChild(_mediaModelChip(m, labelOf(m)));
2792
+ dropdown.appendChild(o);
2595
2793
  });
2596
- sel.addEventListener("change", async () => {
2597
- const picked = sel.value;
2598
- const payload = picked === (def && def.model)
2599
- ? { source: "auto" }
2600
- : { source: "auto", model: picked };
2601
- sel.disabled = true;
2602
- _setMediaResult(kind, "testing", I18n.t("settings.media.action.saving"));
2603
- try {
2604
- await _saveMediaConfig(kind, payload);
2605
- await _reloadKind(kind);
2606
- } catch (e) {
2607
- sel.disabled = false;
2608
- _setMediaResult(kind, "fail", e.message);
2794
+
2795
+ wrapper.appendChild(trigger);
2796
+ wrapper.appendChild(dropdown);
2797
+
2798
+ const cs = CustomSelect.init({
2799
+ trigger,
2800
+ dropdown,
2801
+ portal: true,
2802
+ onSelect: async (picked) => {
2803
+ // CustomSelect.setValue wrote plain text; restore the chip.
2804
+ renderValue(picked);
2805
+ if (picked === state.model) return;
2806
+ const payload = picked === (def && def.model)
2807
+ ? { source: "auto" }
2808
+ : { source: "auto", model: picked };
2809
+ wrapper.classList.add("is-disabled");
2810
+ _setMediaResult(kind, "testing", I18n.t("settings.media.action.saving"));
2811
+ try {
2812
+ await _saveMediaConfig(kind, payload);
2813
+ await _reloadKind(kind);
2814
+ } catch (e) {
2815
+ wrapper.classList.remove("is-disabled");
2816
+ cs.setValue(state.model, "");
2817
+ renderValue(state.model);
2818
+ _setMediaResult(kind, "fail", e.message);
2819
+ }
2609
2820
  }
2610
2821
  });
2611
- modelField.appendChild(sel);
2822
+ modelField.appendChild(wrapper);
2612
2823
  } else {
2613
2824
  const ro = document.createElement("div");
2614
2825
  ro.className = "media-auto-readonly";
2615
- ro.textContent = labelOf(state.model);
2826
+ ro.appendChild(_mediaModelChip(state.model, labelOf(state.model)));
2616
2827
  modelField.appendChild(ro);
2617
2828
  }
2618
2829
  wrap.appendChild(modelField);
@@ -2621,8 +2832,8 @@ const Settings = (() => {
2621
2832
  const warn = document.createElement("div");
2622
2833
  warn.className = "media-row-hint is-warning";
2623
2834
  warn.textContent = I18n.t("settings.media.auto.stale", {
2624
- requested: labelOf(state.requested_model),
2625
- current: labelOf(state.model)
2835
+ requested: nameOf(state.requested_model),
2836
+ current: nameOf(state.model)
2626
2837
  });
2627
2838
  wrap.appendChild(warn);
2628
2839
  } else {
@@ -2662,7 +2873,11 @@ const Settings = (() => {
2662
2873
  lbl.textContent = I18n.t(lk);
2663
2874
  const val = document.createElement("span");
2664
2875
  val.className = "media-custom-readonly-value";
2665
- val.textContent = v || "—";
2876
+ if (lk === "settings.media.field.model" && v) {
2877
+ val.appendChild(_mediaModelChip(v, v));
2878
+ } else {
2879
+ val.textContent = v || "—";
2880
+ }
2666
2881
  row.appendChild(lbl);
2667
2882
  row.appendChild(val);
2668
2883
  list.appendChild(row);
@@ -2980,10 +3195,24 @@ const Settings = (() => {
2980
3195
  _initAccentColorBtns();
2981
3196
  _initBgThemeCards();
2982
3197
 
3198
+ const mediaPromoClose = document.getElementById("media-promo-close");
3199
+ if (mediaPromoClose) {
3200
+ const dismissLabel = I18n.t("settings.promo.dismiss");
3201
+ mediaPromoClose.setAttribute("aria-label", dismissLabel);
3202
+ mediaPromoClose.title = dismissLabel;
3203
+ mediaPromoClose.addEventListener("click", _dismissAiKeysPromo);
3204
+ }
3205
+
2983
3206
  // Re-render model cards when language changes (dynamic HTML, not data-i18n)
2984
3207
  document.addEventListener("langchange", () => {
2985
3208
  _renderCards();
2986
3209
  _renderMediaRows();
3210
+ const promoClose = document.getElementById("media-promo-close");
3211
+ if (promoClose) {
3212
+ const dismissLabel = I18n.t("settings.promo.dismiss");
3213
+ promoClose.setAttribute("aria-label", dismissLabel);
3214
+ promoClose.title = dismissLabel;
3215
+ }
2987
3216
  });
2988
3217
  }
2989
3218