openclacky 1.5.26 → 1.5.27

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.
@@ -77,6 +77,7 @@
77
77
  "stt.goSettings": "Open settings",
78
78
  "alert.noSession": "No active session",
79
79
  "alert.startFailed": "Failed to start meeting: {{msg}}",
80
+ "alert.noMic": "This browser blocks the microphone on a plain http:// page. Open this page over https:// (or on localhost) and try again.",
80
81
  "end.displayMessage": "🛑 Meeting ended — generating meeting minutes…",
81
82
  "alert.cancelConfirm": "Discard this recording? The transcript will not be summarized.",
82
83
  "end.cancelled": "Recording discarded",
@@ -126,6 +127,7 @@
126
127
  "stt.goSettings": "去设置",
127
128
  "alert.noSession": "没有进行中的会话",
128
129
  "alert.startFailed": "开启会议失败:{{msg}}",
130
+ "alert.noMic": "浏览器不允许在 http:// 页面上使用麦克风。请改用 https:// 地址打开本页(或在本机 localhost 上使用)后重试。",
129
131
  "end.displayMessage": "🛑 会议结束 — 正在生成会议纪要…",
130
132
  "alert.cancelConfirm": "取消后这次录音会被丢弃,不会生成纪要。确定取消吗?",
131
133
  "end.cancelled": "已丢弃这次录音",
@@ -274,6 +276,13 @@
274
276
  }
275
277
 
276
278
  const idleLabel = state.resumable ? t("btn.resume") : t("btn.start");
279
+ // Browsers hide navigator.mediaDevices on a plain-http page (only https and
280
+ // localhost are treated as secure), so reaching for .getUserMedia there
281
+ // throws a TypeError that says nothing useful to the user.
282
+ if (!(navigator.mediaDevices && navigator.mediaDevices.getUserMedia)) {
283
+ alert(t("alert.noMic"));
284
+ return;
285
+ }
277
286
  setStartBtnBusy(btn, true, t(state.resumable ? "btn.resuming" : "btn.starting"));
278
287
 
279
288
  try {
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "fileutils"
4
4
  require "json"
5
+ require "yaml"
5
6
 
6
7
  module Clacky
7
8
  # Discovers extension containers across three source layers and resolves them
@@ -89,6 +90,42 @@ module Clacky
89
90
  File.join(DATA_DIR, id.to_s)
90
91
  end
91
92
 
93
+ # Owner-level settings for an extension's agents, written by the
94
+ # extension's own management API and read by AgentProfile:
95
+ #
96
+ # agents:
97
+ # knowledge:
98
+ # tools_allow: [kb_search, kb_read]
99
+ #
100
+ # Kept outside ext.yml because a package upgrade overwrites the manifest,
101
+ # and because this layer may LIFT a whitelist as well as narrow it: the
102
+ # manifest layers only ever intersect, so "give me the full toolset back"
103
+ # has no expression there.
104
+ def agent_settings_path(id)
105
+ File.join(data_dir_for(id), "agent_settings.yml")
106
+ end
107
+
108
+ # @return [Hash] parsed settings, {} when absent or unreadable
109
+ def agent_settings(id)
110
+ path = agent_settings_path(id)
111
+ return {} unless File.file?(path)
112
+ data = YAMLCompat.load_file(path)
113
+ data.is_a?(Hash) ? data : {}
114
+ rescue StandardError
115
+ {}
116
+ end
117
+
118
+ def save_agent_settings(id, data)
119
+ path = agent_settings_path(id)
120
+ if data.nil? || data.empty?
121
+ FileUtils.rm_f(path)
122
+ return path
123
+ end
124
+ FileUtils.mkdir_p(File.dirname(path))
125
+ File.write(path, YAML.dump(data))
126
+ path
127
+ end
128
+
92
129
  # Scan all layers, resolve overrides, return a structured Result.
93
130
  # `layers` maps layer name => root dir; defaults to the real three-layer
94
131
  # dirs. Tests inject temp dirs through it.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Clacky
4
- VERSION = "1.5.26"
4
+ VERSION = "1.5.27"
5
5
  end
@@ -6949,7 +6949,7 @@ body {
6949
6949
  .ns-ctx-popover--model {
6950
6950
  position: fixed;
6951
6951
  /* Position will be calculated dynamically via JavaScript */
6952
- min-width: 15rem;
6952
+ min-width: min(20rem, calc(100vw - 1.5rem));
6953
6953
  max-width: min(22rem, calc(100vw - 1.5rem));
6954
6954
  z-index: 1000;
6955
6955
  max-height: calc(100vh - 6rem);
@@ -578,6 +578,14 @@ Clacky.Router = Router;
578
578
 
579
579
  // ── Modal utility ─────────────────────────────────────────────────────────
580
580
  const Modal = (() => {
581
+ // Modals are static markup with data-i18n buttons. Auth can open one before
582
+ // boot's applyAll() runs, which would leave English labels next to a
583
+ // translated message — translate the overlay right before showing it.
584
+ function _show(overlay) {
585
+ if (typeof I18n !== "undefined" && I18n.applyAll) I18n.applyAll(overlay);
586
+ overlay.style.display = "flex";
587
+ }
588
+
581
589
  /** Show a yes/no confirmation dialog. Returns a Promise<boolean>. */
582
590
  function confirm(message) {
583
591
  return new Promise(resolve => {
@@ -588,7 +596,7 @@ const Modal = (() => {
588
596
  if (overlay.parentNode !== document.body || overlay.nextSibling) {
589
597
  document.body.appendChild(overlay);
590
598
  }
591
- overlay.style.display = "flex";
599
+ _show(overlay);
592
600
 
593
601
  const cleanup = (result) => {
594
602
  overlay.style.display = "none";
@@ -618,7 +626,7 @@ const Modal = (() => {
618
626
  if (overlay.parentNode !== document.body || overlay.nextSibling) {
619
627
  document.body.appendChild(overlay);
620
628
  }
621
- overlay.style.display = "flex";
629
+ _show(overlay);
622
630
 
623
631
  const cleanup = (result) => {
624
632
  overlay.style.display = "none";
@@ -650,7 +658,7 @@ const Modal = (() => {
650
658
  if (overlay.parentNode !== document.body || overlay.nextSibling) {
651
659
  document.body.appendChild(overlay);
652
660
  }
653
- overlay.style.display = "flex";
661
+ _show(overlay);
654
662
 
655
663
  const cleanup = (ok) => {
656
664
  overlay.style.display = "none";
@@ -673,7 +681,7 @@ const Modal = (() => {
673
681
  if (overlay.parentNode !== document.body || overlay.nextSibling) {
674
682
  document.body.appendChild(overlay);
675
683
  }
676
- overlay.style.display = "flex";
684
+ _show(overlay);
677
685
 
678
686
  // Auto-focus and select all text
679
687
  setTimeout(() => {
@@ -720,7 +728,7 @@ const Modal = (() => {
720
728
  if (overlay.parentNode !== document.body || overlay.nextSibling) {
721
729
  document.body.appendChild(overlay);
722
730
  }
723
- overlay.style.display = "flex";
731
+ _show(overlay);
724
732
 
725
733
  setTimeout(() => {
726
734
  input.focus();
@@ -3389,14 +3389,16 @@ const I18n = (() => {
3389
3389
  * data-i18n="key" → element.textContent
3390
3390
  * data-i18n-placeholder="key" → element.placeholder
3391
3391
  * data-i18n-title="key" → element.title
3392
+ * Pass `root` to translate a detached/early subtree (e.g. a modal opened
3393
+ * before boot ran applyAll on the document).
3392
3394
  */
3393
- function applyAll() {
3394
- document.querySelectorAll("[data-i18n]").forEach(el => {
3395
+ function applyAll(root = document) {
3396
+ root.querySelectorAll("[data-i18n]").forEach(el => {
3395
3397
  const key = el.getAttribute("data-i18n");
3396
3398
  const vars = _extractVars(el);
3397
3399
  el.textContent = t(key, vars);
3398
3400
  });
3399
- document.querySelectorAll("[data-i18n-placeholder]").forEach(el => {
3401
+ root.querySelectorAll("[data-i18n-placeholder]").forEach(el => {
3400
3402
  const key = el.getAttribute("data-i18n-placeholder");
3401
3403
  const vars = _extractVars(el);
3402
3404
  let ph = t(key, vars);
@@ -3408,12 +3410,12 @@ const I18n = (() => {
3408
3410
  // contenteditable composers render their placeholder via CSS :empty::before.
3409
3411
  if (el.isContentEditable) el.setAttribute("data-placeholder", ph);
3410
3412
  });
3411
- document.querySelectorAll("[data-i18n-title]").forEach(el => {
3413
+ root.querySelectorAll("[data-i18n-title]").forEach(el => {
3412
3414
  const key = el.getAttribute("data-i18n-title");
3413
3415
  const vars = _extractVars(el);
3414
3416
  el.title = t(key, vars);
3415
3417
  });
3416
- document.querySelectorAll("[data-i18n-tooltip]").forEach(el => {
3418
+ root.querySelectorAll("[data-i18n-tooltip]").forEach(el => {
3417
3419
  const key = el.getAttribute("data-i18n-tooltip");
3418
3420
  const vars = _extractVars(el);
3419
3421
  el.setAttribute("data-tooltip", t(key, vars));
@@ -2134,6 +2134,7 @@
2134
2134
  <script src="/core/ext.js"></script>
2135
2135
  <script src="/core/aside.js"></script>
2136
2136
  <script src="/lib/box-diagram.js"></script>
2137
+ <script src="/lib/audio-recorder.js"></script>
2137
2138
  <script src="/components/composer.js"></script>
2138
2139
  <script src="/components/chat-composer.js"></script>
2139
2140
  <script src="/components/mentions.js"></script>
@@ -0,0 +1,213 @@
1
+ // Microphone capture split into utterance-sized segments by a simple VAD.
2
+ //
3
+ // Browsers only expose navigator.mediaDevices on a secure page (https:// or
4
+ // localhost), so callers check secure()/supported() before offering a mic
5
+ // feature and use the same check to explain the failure when it is missing.
6
+
7
+ (function () {
8
+ const VAD_TICK_MS = 50;
9
+ const VAD_MIN_RMS = 0.004;
10
+ const VAD_NOISE_FACTOR = 3.0;
11
+ const VAD_SILENCE_HOLD_MS = 600;
12
+ const VAD_MIN_SPEECH_MS = 500;
13
+ const VAD_MIN_SPEECH_TICKS = 8;
14
+ const VAD_MAX_SEGMENT_MS = 30000;
15
+ const MIN_AUDIO_BYTES = 2000;
16
+ const WAV_SAMPLE_RATE = 16000;
17
+
18
+ function secure() {
19
+ if (window.isSecureContext) return true;
20
+ const host = location.hostname;
21
+ return host === "localhost" || host === "127.0.0.1" || host === "::1" || /\.localhost$/.test(host);
22
+ }
23
+
24
+ function supported() {
25
+ return secure() &&
26
+ !!(navigator.mediaDevices && navigator.mediaDevices.getUserMedia) &&
27
+ typeof window.MediaRecorder !== "undefined";
28
+ }
29
+
30
+ function getSupportedMime() {
31
+ if (typeof window.MediaRecorder === "undefined") return "";
32
+ const types = ["audio/webm;codecs=opus", "audio/webm", "audio/ogg;codecs=opus", "audio/mp4"];
33
+ for (let i = 0; i < types.length; i++) {
34
+ if (MediaRecorder.isTypeSupported(types[i])) return types[i];
35
+ }
36
+ return "";
37
+ }
38
+
39
+ let transcodeCtx = null;
40
+
41
+ // STT backends are happiest with 16 kHz mono PCM. Returns null when the
42
+ // browser cannot decode the container — the caller then sends it as-is.
43
+ async function toWav16k(blob) {
44
+ try {
45
+ if (!transcodeCtx) transcodeCtx = new (window.AudioContext || window.webkitAudioContext)();
46
+ const decoded = await transcodeCtx.decodeAudioData(await blob.arrayBuffer());
47
+ const frames = Math.ceil(decoded.duration * WAV_SAMPLE_RATE);
48
+ if (!frames) return null;
49
+
50
+ const offline = new OfflineAudioContext(1, frames, WAV_SAMPLE_RATE);
51
+ const source = offline.createBufferSource();
52
+ source.buffer = decoded;
53
+ source.connect(offline.destination);
54
+ source.start();
55
+ const pcm = (await offline.startRendering()).getChannelData(0);
56
+
57
+ const buffer = new ArrayBuffer(44 + pcm.length * 2);
58
+ const view = new DataView(buffer);
59
+ const tag = (offset, str) => {
60
+ for (let i = 0; i < str.length; i++) view.setUint8(offset + i, str.charCodeAt(i));
61
+ };
62
+ tag(0, "RIFF");
63
+ view.setUint32(4, 36 + pcm.length * 2, true);
64
+ tag(8, "WAVE");
65
+ tag(12, "fmt ");
66
+ view.setUint32(16, 16, true);
67
+ view.setUint16(20, 1, true);
68
+ view.setUint16(22, 1, true);
69
+ view.setUint32(24, WAV_SAMPLE_RATE, true);
70
+ view.setUint32(28, WAV_SAMPLE_RATE * 2, true);
71
+ view.setUint16(32, 2, true);
72
+ view.setUint16(34, 16, true);
73
+ tag(36, "data");
74
+ view.setUint32(40, pcm.length * 2, true);
75
+ for (let i = 0, offset = 44; i < pcm.length; i++, offset += 2) {
76
+ const s = Math.max(-1, Math.min(1, pcm[i]));
77
+ view.setInt16(offset, s < 0 ? s * 0x8000 : s * 0x7fff, true);
78
+ }
79
+ return new Blob([buffer], { type: "audio/wav" });
80
+ } catch (err) {
81
+ console.warn("[audio-recorder] wav transcode failed, sending original:", err);
82
+ return null;
83
+ }
84
+ }
85
+
86
+ // @return {Promise<{audio_base64: String, mime_type: String}|null>} — null
87
+ // when the clip is too short to carry any speech.
88
+ async function encode(blob) {
89
+ if (!blob || blob.size < MIN_AUDIO_BYTES) return null;
90
+ const wav = await toWav16k(blob);
91
+ const payload = wav || blob;
92
+ const bytes = new Uint8Array(await payload.arrayBuffer());
93
+ let binary = "";
94
+ for (let i = 0; i < bytes.length; i++) binary += String.fromCharCode(bytes[i]);
95
+ return { audio_base64: btoa(binary), mime_type: payload.type || blob.type || "audio/webm" };
96
+ }
97
+
98
+ // opts.onSegment(blob) fires for every utterance, including the tail segment
99
+ // produced by stop(). opts.onLevel(rms) drives input meters.
100
+ // Rejects with err.code = "insecure_context" / "unsupported" before touching
101
+ // the microphone, so callers can explain what the browser refused.
102
+ // @return {Promise<{stop: Function, level: Function}>}
103
+ async function start(opts) {
104
+ const options = opts || {};
105
+ if (!supported()) {
106
+ const err = new Error("microphone unavailable");
107
+ err.code = secure() ? "unsupported" : "insecure_context";
108
+ throw err;
109
+ }
110
+
111
+ const stream = await navigator.mediaDevices.getUserMedia({
112
+ audio: { echoCancellation: true, noiseSuppression: true, autoGainControl: true, channelCount: 1 },
113
+ });
114
+ const AudioCtx = window.AudioContext || window.webkitAudioContext;
115
+ const audioCtx = new AudioCtx();
116
+ // A context that came up suspended still feeds MediaRecorder but leaves the
117
+ // analyser reading pure silence, which would look like "the user never spoke".
118
+ if (audioCtx.state === "suspended") {
119
+ audioCtx.resume().catch((e) => console.warn("[audio-recorder] resume failed:", e));
120
+ }
121
+ const source = audioCtx.createMediaStreamSource(stream);
122
+ const analyser = audioCtx.createAnalyser();
123
+ analyser.fftSize = 1024;
124
+ source.connect(analyser);
125
+ const buf = new Float32Array(analyser.fftSize);
126
+ const mime = getSupportedMime();
127
+
128
+ let active = true;
129
+ let recorder = null;
130
+ let chunks = [];
131
+ let hadSpeech = false;
132
+ let speechTicks = 0;
133
+ let noiseFloor = 0.002;
134
+ let segmentStart = 0;
135
+ let silenceStart = 0;
136
+
137
+ function rms() {
138
+ analyser.getFloatTimeDomainData(buf);
139
+ let sum = 0;
140
+ for (let i = 0; i < buf.length; i++) sum += buf[i] * buf[i];
141
+ return Math.sqrt(sum / buf.length);
142
+ }
143
+
144
+ function newRecorder() {
145
+ const r = new MediaRecorder(stream, mime ? { mimeType: mime } : {});
146
+ chunks = [];
147
+ hadSpeech = false;
148
+ speechTicks = 0;
149
+ segmentStart = performance.now();
150
+ silenceStart = 0;
151
+ r.ondataavailable = (e) => { if (e.data && e.data.size > 0) chunks.push(e.data); };
152
+ r.onstop = () => {
153
+ const captured = chunks;
154
+ const spoke = speechTicks >= VAD_MIN_SPEECH_TICKS;
155
+ const started = segmentStart;
156
+ if (active) newRecorder();
157
+ if (spoke && performance.now() - started >= VAD_MIN_SPEECH_MS && captured.length && options.onSegment) {
158
+ options.onSegment(new Blob(captured, mime ? { type: mime } : {}));
159
+ }
160
+ };
161
+ r.start(200);
162
+ recorder = r;
163
+ }
164
+
165
+ function tick() {
166
+ if (!active) return;
167
+ const now = performance.now();
168
+ const level = rms();
169
+ if (options.onLevel) options.onLevel(level);
170
+ // Fast down, slow up: a quiet gap drops the floor immediately while
171
+ // speech lifts it only slightly, so it settles on the background level
172
+ // instead of chasing the speaker.
173
+ noiseFloor += (level - noiseFloor) * (level < noiseFloor ? 0.25 : 0.002);
174
+ const threshold = Math.max(VAD_MIN_RMS, noiseFloor * VAD_NOISE_FACTOR);
175
+
176
+ if (level >= threshold) {
177
+ speechTicks++;
178
+ hadSpeech = true;
179
+ silenceStart = 0;
180
+ } else if (hadSpeech) {
181
+ if (silenceStart === 0) silenceStart = now;
182
+ else if (now - silenceStart >= VAD_SILENCE_HOLD_MS && recorder.state === "recording") recorder.stop();
183
+ }
184
+
185
+ if (now - segmentStart >= VAD_MAX_SEGMENT_MS && recorder.state === "recording") recorder.stop();
186
+ }
187
+
188
+ newRecorder();
189
+ // setInterval, not requestAnimationFrame: rAF stops firing while the tab is
190
+ // hidden or covered, which would leave one endless segment running.
191
+ const timer = setInterval(tick, VAD_TICK_MS);
192
+
193
+ function stop() {
194
+ if (!active) return;
195
+ active = false;
196
+ clearInterval(timer);
197
+ if (recorder && recorder.state === "recording") recorder.stop();
198
+ stream.getTracks().forEach((track) => track.stop());
199
+ try { audioCtx.close(); } catch (_e) { /* already closed */ }
200
+ }
201
+
202
+ return { stop: stop, level: rms };
203
+ }
204
+
205
+ window.Clacky = window.Clacky || {};
206
+ window.Clacky.AudioRecorder = {
207
+ secure: secure,
208
+ supported: supported,
209
+ getSupportedMime: getSupportedMime,
210
+ encode: encode,
211
+ start: start,
212
+ };
213
+ })();
@@ -431,7 +431,11 @@ const FloatingDropdown = (() => {
431
431
  const viewport = window.innerHeight;
432
432
  const spaceBelow = viewport - rect.bottom - GAP - EDGE;
433
433
  const spaceAbove = rect.top - GAP - EDGE;
434
- const height = Math.min(dropdown.scrollHeight, cssMaxHeight(dropdown));
434
+ // Measure with our own clamp removed: a previously clamped height fed back
435
+ // in loses the border box on every pass, so a panel re-placed on scroll
436
+ // shrank ~2px per event until it collapsed.
437
+ dropdown.style.maxHeight = "";
438
+ const height = Math.min(dropdown.getBoundingClientRect().height, cssMaxHeight(dropdown));
435
439
  // Clamping below is preferable to flipping — it keeps the fields above in
436
440
  // view — unless the remaining room cannot show a usable number of rows.
437
441
  const openUp = spaceBelow < Math.min(height, MIN_READABLE_ROOM) && spaceAbove > spaceBelow;
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openclacky
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.26
4
+ version: 1.5.27
5
5
  platform: ruby
6
6
  authors:
7
7
  - windy
@@ -432,6 +432,7 @@ files:
432
432
  - lib/clacky/default_extensions/knowledge/lib/importer.rb
433
433
  - lib/clacky/default_extensions/knowledge/lib/index.rb
434
434
  - lib/clacky/default_extensions/knowledge/lib/knowledge.rb
435
+ - lib/clacky/default_extensions/knowledge/lib/stats.rb
435
436
  - lib/clacky/default_extensions/knowledge/lib/store.rb
436
437
  - lib/clacky/default_extensions/knowledge/panels/kb/view.js
437
438
  - lib/clacky/default_extensions/knowledge/tools/kb_read.rb
@@ -807,6 +808,7 @@ files:
807
808
  - lib/clacky/web/icon-dark.svg
808
809
  - lib/clacky/web/icon.svg
809
810
  - lib/clacky/web/index.html
811
+ - lib/clacky/web/lib/audio-recorder.js
810
812
  - lib/clacky/web/lib/box-diagram.js
811
813
  - lib/clacky/web/logo_nav_dark.png
812
814
  - lib/clacky/web/projects.js