dsh-plugin-marginalia 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/client.js +838 -162
  2. package/index.js +12 -2
  3. package/package.json +1 -1
package/client.js CHANGED
@@ -6,26 +6,30 @@ window.__ModuleLoader__.load({
6
6
 
7
7
  const PLUGIN_ID = 'dsh-plugin-marginalia';
8
8
  const TAB_KIND = 'marginalia';
9
- const STORAGE_PREFIX = 'dsh.marginalia.v1.';
9
+ const STORAGE_PREFIX = 'dsh.marginalia.v2.';
10
10
  const MAX_STORED_MESSAGES = 40;
11
11
 
12
12
  const en = {
13
13
  'tab.title': 'Marginalia',
14
14
  'guide.title': 'Marginalia',
15
- 'guide.description': 'Ask side-channel questions about the main conversation',
16
- 'header.tooltip': 'Ask Marginalia (Sidebar Q&A)',
17
- 'mode.side': 'Side-Ask',
15
+ 'guide.description': 'Select text or ask side-channel questions about the main chat',
16
+ 'header.tooltip': 'Ask Marginalia (Side Chat)',
17
+ 'sel.addToChat': 'Add to chat',
18
+ 'sel.askSide': 'Ask in side chat',
19
+ 'mode.side': 'Side Chat',
18
20
  'mode.main': 'To Main Chat',
19
21
  'context.on': 'With main context',
20
- 'context.off': 'No main context',
21
- 'clear': 'Clear',
22
- 'empty.title': 'Ask anything without interrupting',
23
- 'empty.subtitle.side': 'Side-Ask reads the main conversation context and answers here in the sidebar without cluttering the main thread.',
22
+ 'context.off': 'Standalone',
23
+ 'newChat': 'New side chat',
24
+ 'quote.count': '{n} selected snippet',
25
+ 'quote.countPlural': '{n} selected snippets',
26
+ 'empty.title': 'Ask anything in the side chat',
27
+ 'empty.subtitle.side': 'Select any text in the main conversation and click "Ask in side chat", or type a question below without interrupting the main thread.',
24
28
  'empty.subtitle.main': 'Send a prompt directly into the main conversation queue from the sidebar.',
25
29
  'chip.summarize': 'Summarize progress so far',
26
30
  'chip.explain': 'Explain the latest response',
27
31
  'chip.next': 'What should we do next?',
28
- 'placeholder.side': 'Ask a side question about this conversation…',
32
+ 'placeholder.side': 'Ask about this conversation…',
29
33
  'placeholder.main': 'Send a message to the main conversation…',
30
34
  'send': 'Send',
31
35
  'stop': 'Stop',
@@ -33,29 +37,33 @@ window.__ModuleLoader__.load({
33
37
  'copied': 'Copied',
34
38
  'promote': 'Send to main',
35
39
  'sentToMain': 'Sent to main conversation',
40
+ 'addedToMain': 'Copied & sent to main chat',
36
41
  'thinking': 'Thinking…',
37
42
  'error.noSession': 'Open or start a conversation first.',
38
43
  'error.sendFailed': 'Failed to send request',
39
- 'hint.enter': 'Enter to send · Shift+Enter for newline',
40
44
  };
41
45
 
42
46
  const zh = {
43
- 'tab.title': '旁注问',
44
- 'guide.title': '旁注问 Marginalia',
45
- 'guide.description': '在侧边栏向主对话提问,不打断主流程',
46
- 'header.tooltip': '打开旁注问 (Marginalia)',
47
+ 'tab.title': '旁注提问',
48
+ 'guide.title': '旁注提问 Marginalia',
49
+ 'guide.description': '划词或直接在右侧边栏向主对话提问,不打断主流程',
50
+ 'header.tooltip': '打开旁注提问 (Marginalia)',
51
+ 'sel.addToChat': '添加到对话',
52
+ 'sel.askSide': '在侧边聊天中提问',
47
53
  'mode.side': '旁注提问',
48
54
  'mode.main': '直发主对话',
49
55
  'context.on': '携带主对话上下文',
50
- 'context.off': '仅独立提问',
51
- 'clear': '清空',
52
- 'empty.title': '随时旁注提问,不打扰主对话',
53
- 'empty.subtitle.side': '「旁注提问」会读取当前主对话上下文并在此处独立回答,不会污染或打断主对话。',
56
+ 'context.off': '独立提问',
57
+ 'newChat': '新旁注对话',
58
+ 'quote.count': '{n} 个已选文本片段',
59
+ 'quote.countPlural': '{n} 个已选文本片段',
60
+ 'empty.title': '在侧边聊天中随时提问',
61
+ 'empty.subtitle.side': '在主对话中划选任意文字即可「在侧边聊天中提问」,也可以直接输入问题,不会打断或污染主对话。',
54
62
  'empty.subtitle.main': '「直发主对话」会将你的问题直接排队或插队发送到主会话中。',
55
63
  'chip.summarize': '总结目前为止的进展',
56
64
  'chip.explain': '解释一下刚才的回复',
57
65
  'chip.next': '接下来建议做什么?',
58
- 'placeholder.side': '针对当前主对话提个旁注问题…',
66
+ 'placeholder.side': '针对当前对话提问…',
59
67
  'placeholder.main': '直接发送消息到主对话…',
60
68
  'send': '发送',
61
69
  'stop': '停止',
@@ -63,10 +71,10 @@ window.__ModuleLoader__.load({
63
71
  'copied': '已复制',
64
72
  'promote': '发到主对话',
65
73
  'sentToMain': '已发送到主对话',
74
+ 'addedToMain': '已添加到主对话',
66
75
  'thinking': '思考中…',
67
76
  'error.noSession': '请先打开或创建一个会话。',
68
77
  'error.sendFailed': '发送失败',
69
- 'hint.enter': 'Enter 发送 · Shift+Enter 换行',
70
78
  };
71
79
 
72
80
  const CSS = `
@@ -88,6 +96,41 @@ window.__ModuleLoader__.load({
88
96
  background: var(--dsw-alias-bg-layer-2);
89
97
  color: var(--dsw-alias-label-primary);
90
98
  }
99
+ .mg-sel-bar {
100
+ position: fixed;
101
+ z-index: 9999;
102
+ display: inline-flex;
103
+ align-items: center;
104
+ padding: 3px;
105
+ border-radius: 12px;
106
+ background: var(--dsw-alias-bg-overlay);
107
+ border: 1px solid var(--dsw-alias-border-l1);
108
+ box-shadow: 0 6px 20px rgba(0, 0, 0, 0.14), 0 1px 3px rgba(0, 0, 0, 0.08);
109
+ transform: translate(-50%, -100%);
110
+ pointer-events: auto;
111
+ user-select: none;
112
+ }
113
+ .mg-sel-btn {
114
+ border: none;
115
+ background: transparent;
116
+ color: var(--dsw-alias-label-primary);
117
+ font-size: 13px;
118
+ font-weight: 500;
119
+ padding: 6px 12px;
120
+ border-radius: 9px;
121
+ cursor: pointer;
122
+ white-space: nowrap;
123
+ transition: background-color 0.12s ease;
124
+ }
125
+ .mg-sel-btn:hover {
126
+ background: var(--dsw-alias-bg-layer-2);
127
+ }
128
+ .mg-sel-sep {
129
+ width: 1px;
130
+ height: 16px;
131
+ background: var(--dsw-alias-border-l1);
132
+ margin: 0 1px;
133
+ }
91
134
  .mg-root {
92
135
  display: flex;
93
136
  flex-direction: column;
@@ -95,33 +138,32 @@ window.__ModuleLoader__.load({
95
138
  min-height: 0;
96
139
  background: var(--dsw-alias-bg-base);
97
140
  color: var(--dsw-alias-label-primary);
98
- font-size: 13px;
99
- line-height: 1.5;
141
+ font-size: 14px;
142
+ line-height: 1.65;
100
143
  }
101
144
  .mg-toolbar {
102
145
  display: flex;
103
146
  align-items: center;
104
147
  justify-content: space-between;
105
148
  gap: 8px;
106
- padding: 10px 12px;
149
+ padding: 8px 14px;
107
150
  border-bottom: 1px solid var(--dsw-alias-border-l1);
108
151
  flex-wrap: wrap;
109
152
  }
110
153
  .mg-seg {
111
154
  display: inline-flex;
112
155
  padding: 2px;
113
- border-radius: 8px;
156
+ border-radius: 10px;
114
157
  background: var(--dsw-alias-bg-layer-2);
115
- border: 1px solid var(--dsw-alias-border-l1);
116
158
  }
117
159
  .mg-seg-btn {
118
160
  border: none;
119
161
  background: transparent;
120
162
  color: var(--dsw-alias-label-secondary);
121
- font-size: 12px;
163
+ font-size: 12.5px;
122
164
  font-weight: 500;
123
165
  padding: 4px 10px;
124
- border-radius: 6px;
166
+ border-radius: 8px;
125
167
  cursor: pointer;
126
168
  transition: background-color 0.15s ease, color 0.15s ease;
127
169
  }
@@ -136,17 +178,20 @@ window.__ModuleLoader__.load({
136
178
  gap: 6px;
137
179
  }
138
180
  .mg-pill-btn {
181
+ display: inline-flex;
182
+ align-items: center;
183
+ gap: 4px;
139
184
  border: 1px solid var(--dsw-alias-border-l1);
140
- background: var(--dsw-alias-bg-layer-1);
185
+ background: transparent;
141
186
  color: var(--dsw-alias-label-secondary);
142
- font-size: 11.5px;
143
- padding: 3px 8px;
187
+ font-size: 12px;
188
+ padding: 3px 9px;
144
189
  border-radius: 999px;
145
190
  cursor: pointer;
146
191
  transition: border-color 0.15s ease, color 0.15s ease, background-color 0.15s ease;
147
192
  }
148
193
  .mg-pill-btn:hover {
149
- border-color: var(--dsw-alias-border-l2);
194
+ background: var(--dsw-alias-bg-layer-2);
150
195
  color: var(--dsw-alias-label-primary);
151
196
  }
152
197
  .mg-pill-btn.is-on {
@@ -157,43 +202,54 @@ window.__ModuleLoader__.load({
157
202
  flex: 1;
158
203
  min-height: 0;
159
204
  overflow-y: auto;
160
- padding: 12px;
205
+ padding: 16px 16px 12px;
161
206
  display: flex;
162
207
  flex-direction: column;
163
- gap: 10px;
208
+ gap: 18px;
164
209
  }
165
210
  .mg-empty {
166
211
  margin: auto 0;
167
- padding: 18px 12px;
212
+ padding: 24px 12px;
168
213
  text-align: center;
169
214
  display: flex;
170
215
  flex-direction: column;
171
216
  align-items: center;
172
217
  gap: 10px;
173
218
  }
219
+ .mg-empty-icon {
220
+ width: 36px;
221
+ height: 36px;
222
+ border-radius: 12px;
223
+ display: inline-flex;
224
+ align-items: center;
225
+ justify-content: center;
226
+ background: var(--dsw-alias-bg-layer-2);
227
+ color: var(--dsw-alias-brand-primary);
228
+ }
174
229
  .mg-empty-title {
175
- font-size: 14px;
230
+ font-size: 15px;
176
231
  font-weight: 600;
177
232
  color: var(--dsw-alias-label-primary);
178
233
  }
179
234
  .mg-empty-sub {
180
- font-size: 12px;
235
+ font-size: 13px;
181
236
  color: var(--dsw-alias-label-secondary);
182
- max-width: 280px;
237
+ max-width: 300px;
238
+ line-height: 1.55;
183
239
  }
184
240
  .mg-chips {
185
241
  display: flex;
186
242
  flex-wrap: wrap;
187
243
  justify-content: center;
188
- gap: 6px;
189
- margin-top: 4px;
244
+ gap: 8px;
245
+ margin-top: 6px;
190
246
  }
191
247
  .mg-chip {
192
248
  border: 1px solid var(--dsw-alias-border-l1);
193
249
  background: var(--dsw-alias-bg-layer-1);
194
250
  color: var(--dsw-alias-label-primary);
195
- font-size: 12px;
196
- padding: 5px 10px;
251
+ font-size: 12.5px;
252
+ padding: 6px 12px;
197
253
  border-radius: 999px;
198
254
  cursor: pointer;
199
255
  transition: border-color 0.15s ease, background-color 0.15s ease;
@@ -205,7 +261,7 @@ window.__ModuleLoader__.load({
205
261
  .mg-msg {
206
262
  display: flex;
207
263
  flex-direction: column;
208
- gap: 4px;
264
+ gap: 6px;
209
265
  }
210
266
  .mg-msg.is-user {
211
267
  align-items: flex-end;
@@ -213,51 +269,151 @@ window.__ModuleLoader__.load({
213
269
  .mg-msg.is-assistant {
214
270
  align-items: flex-start;
215
271
  }
216
- .mg-bubble {
217
- max-width: 92%;
218
- padding: 8px 11px;
219
- border-radius: 12px;
272
+ .mg-user-quotes {
273
+ display: flex;
274
+ flex-wrap: wrap;
275
+ justify-content: flex-end;
276
+ gap: 4px;
277
+ max-width: 88%;
278
+ }
279
+ .mg-user-bubble {
280
+ max-width: 88%;
281
+ padding: 9px 14px;
282
+ border-radius: 18px;
283
+ background: var(--dsw-alias-bg-layer-2);
284
+ color: var(--dsw-alias-label-primary);
220
285
  white-space: pre-wrap;
221
286
  word-break: break-word;
287
+ font-size: 14px;
288
+ line-height: 1.55;
222
289
  }
223
- .mg-msg.is-user .mg-bubble {
224
- background: var(--dsw-alias-bg-layer-2);
225
- border: 1px solid var(--dsw-alias-border-l1);
290
+ .mg-assistant-body {
291
+ width: 100%;
226
292
  color: var(--dsw-alias-label-primary);
293
+ word-break: break-word;
294
+ font-size: 14px;
295
+ line-height: 1.65;
227
296
  }
228
- .mg-msg.is-assistant .mg-bubble {
297
+ .mg-assistant-body.is-error {
298
+ padding: 10px 12px;
299
+ border-radius: 12px;
229
300
  background: var(--dsw-alias-bg-layer-1);
301
+ border: 1px solid var(--dsw-alias-state-error-primary);
302
+ color: var(--dsw-alias-state-error-primary);
303
+ }
304
+ .mg-md p {
305
+ margin: 0 0 10px;
306
+ }
307
+ .mg-md p:last-child {
308
+ margin-bottom: 0;
309
+ }
310
+ .mg-md h1, .mg-md h2, .mg-md h3, .mg-md h4 {
311
+ margin: 14px 0 6px;
312
+ font-weight: 600;
313
+ line-height: 1.35;
314
+ }
315
+ .mg-md h1 { font-size: 17px; }
316
+ .mg-md h2 { font-size: 15.5px; }
317
+ .mg-md h3, .mg-md h4 { font-size: 14.5px; }
318
+ .mg-md ul, .mg-md ol {
319
+ margin: 6px 0 10px;
320
+ padding-left: 20px;
321
+ }
322
+ .mg-md li {
323
+ margin: 3px 0;
324
+ }
325
+ .mg-md blockquote {
326
+ margin: 8px 0;
327
+ padding: 4px 12px;
328
+ border-left: 3px solid var(--dsw-alias-border-l2);
329
+ color: var(--dsw-alias-label-secondary);
330
+ }
331
+ .mg-md a {
332
+ color: var(--dsw-alias-brand-primary);
333
+ text-decoration: none;
334
+ }
335
+ .mg-md a:hover {
336
+ text-decoration: underline;
337
+ }
338
+ .mg-md code {
339
+ font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
340
+ font-size: 12.5px;
341
+ padding: 1px 5px;
342
+ border-radius: 5px;
343
+ background: var(--dsw-alias-bg-layer-2);
344
+ }
345
+ .mg-code-wrap {
346
+ margin: 10px 0;
347
+ border-radius: 10px;
348
+ overflow: hidden;
230
349
  border: 1px solid var(--dsw-alias-border-l1);
231
- color: var(--dsw-alias-label-primary);
350
+ background: var(--dsw-alias-bg-layer-1);
232
351
  }
233
- .mg-msg.is-error .mg-bubble {
234
- border-color: var(--dsw-alias-state-error-primary);
235
- color: var(--dsw-alias-state-error-primary);
352
+ .mg-code-head {
353
+ display: flex;
354
+ align-items: center;
355
+ justify-content: space-between;
356
+ padding: 5px 10px;
357
+ font-size: 11.5px;
358
+ color: var(--dsw-alias-label-secondary);
359
+ border-bottom: 1px solid var(--dsw-alias-border-l1);
360
+ background: var(--dsw-alias-bg-layer-2);
361
+ }
362
+ .mg-code-pre {
363
+ margin: 0;
364
+ padding: 10px 12px;
365
+ overflow-x: auto;
366
+ font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
367
+ font-size: 12.5px;
368
+ line-height: 1.5;
369
+ }
370
+ .mg-thinking {
371
+ display: inline-flex;
372
+ align-items: center;
373
+ gap: 6px;
374
+ color: var(--dsw-alias-label-secondary);
375
+ font-size: 13px;
376
+ }
377
+ .mg-dot {
378
+ width: 7px;
379
+ height: 7px;
380
+ border-radius: 50%;
381
+ background: var(--dsw-alias-brand-primary);
382
+ animation: mgPulse 1.1s ease-in-out infinite;
383
+ }
384
+ @keyframes mgPulse {
385
+ 0%, 100% { opacity: 0.35; transform: scale(0.85); }
386
+ 50% { opacity: 1; transform: scale(1.1); }
236
387
  }
237
388
  .mg-msg-meta {
238
389
  display: flex;
239
390
  align-items: center;
240
- gap: 8px;
241
- font-size: 11px;
391
+ gap: 10px;
392
+ font-size: 12px;
242
393
  color: var(--dsw-alias-label-secondary);
243
- padding: 0 2px;
394
+ padding: 2px 0;
244
395
  }
245
396
  .mg-action-link {
397
+ display: inline-flex;
398
+ align-items: center;
399
+ gap: 4px;
246
400
  border: none;
247
401
  background: transparent;
248
402
  color: var(--dsw-alias-label-secondary);
249
- font-size: 11px;
250
- padding: 0;
403
+ font-size: 12px;
404
+ padding: 2px 4px;
405
+ border-radius: 6px;
251
406
  cursor: pointer;
252
407
  }
253
408
  .mg-action-link:hover {
254
- color: var(--dsw-alias-brand-primary);
409
+ background: var(--dsw-alias-bg-layer-2);
410
+ color: var(--dsw-alias-label-primary);
255
411
  }
256
412
  .mg-notice {
257
- margin: 0 12px 6px;
258
- padding: 6px 10px;
259
- border-radius: 8px;
260
- font-size: 12px;
413
+ margin: 0 14px 8px;
414
+ padding: 7px 12px;
415
+ border-radius: 10px;
416
+ font-size: 12.5px;
261
417
  background: var(--dsw-alias-bg-layer-2);
262
418
  border: 1px solid var(--dsw-alias-border-l1);
263
419
  color: var(--dsw-alias-state-success-primary);
@@ -266,45 +422,78 @@ window.__ModuleLoader__.load({
266
422
  color: var(--dsw-alias-state-error-primary);
267
423
  border-color: var(--dsw-alias-state-error-primary);
268
424
  }
269
- .mg-header-btn:focus-visible,
270
- .mg-seg-btn:focus-visible,
271
- .mg-pill-btn:focus-visible,
272
- .mg-chip:focus-visible,
273
- .mg-action-link:focus-visible,
274
- .mg-send-btn:focus-visible,
275
- .mg-stop-btn:focus-visible {
276
- outline: 2px solid var(--dsw-alias-brand-primary);
277
- outline-offset: 1px;
278
- }
279
425
  .mg-composer {
280
- padding: 10px 12px 12px;
281
- border-top: 1px solid var(--dsw-alias-border-l1);
426
+ padding: 8px 14px 14px;
282
427
  background: var(--dsw-alias-bg-base);
283
428
  }
284
429
  .mg-input-box {
285
430
  display: flex;
286
431
  flex-direction: column;
287
432
  gap: 8px;
288
- padding: 8px 10px;
289
- border-radius: 12px;
433
+ padding: 10px 12px;
434
+ border-radius: 18px;
290
435
  border: 1px solid var(--dsw-alias-border-l1);
291
436
  background: var(--dsw-alias-bg-layer-1);
437
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
292
438
  }
293
439
  .mg-input-box:focus-within {
294
- border-color: var(--dsw-alias-brand-primary);
440
+ border-color: var(--dsw-alias-border-l2);
441
+ }
442
+ .mg-quote-strip {
443
+ display: flex;
444
+ flex-direction: column;
445
+ gap: 6px;
446
+ }
447
+ .mg-quote-chip {
448
+ display: inline-flex;
449
+ align-items: center;
450
+ gap: 6px;
451
+ align-self: flex-start;
452
+ padding: 4px 10px;
453
+ border-radius: 10px;
454
+ background: var(--dsw-alias-bg-layer-2);
455
+ border: 1px solid var(--dsw-alias-border-l1);
456
+ color: var(--dsw-alias-label-primary);
457
+ font-size: 12.5px;
458
+ font-weight: 500;
459
+ cursor: pointer;
460
+ }
461
+ .mg-quote-x {
462
+ border: none;
463
+ background: transparent;
464
+ color: var(--dsw-alias-label-secondary);
465
+ font-size: 14px;
466
+ line-height: 1;
467
+ padding: 0 2px;
468
+ cursor: pointer;
469
+ }
470
+ .mg-quote-x:hover {
471
+ color: var(--dsw-alias-label-primary);
472
+ }
473
+ .mg-quote-preview {
474
+ padding: 6px 10px;
475
+ border-radius: 8px;
476
+ background: var(--dsw-alias-bg-base);
477
+ border: 1px solid var(--dsw-alias-border-l1);
478
+ font-size: 12px;
479
+ color: var(--dsw-alias-label-secondary);
480
+ max-height: 96px;
481
+ overflow-y: auto;
482
+ white-space: pre-wrap;
295
483
  }
296
484
  .mg-textarea {
297
485
  width: 100%;
298
- min-height: 44px;
299
- max-height: 150px;
486
+ min-height: 24px;
487
+ max-height: 160px;
300
488
  resize: none;
301
489
  border: none;
302
490
  outline: none;
303
491
  background: transparent;
304
492
  color: var(--dsw-alias-label-primary);
305
493
  font-family: inherit;
306
- font-size: 13px;
307
- line-height: 1.45;
494
+ font-size: 14px;
495
+ line-height: 1.5;
496
+ padding: 0;
308
497
  }
309
498
  .mg-textarea::placeholder {
310
499
  color: var(--dsw-alias-label-secondary);
@@ -315,34 +504,40 @@ window.__ModuleLoader__.load({
315
504
  justify-content: space-between;
316
505
  gap: 8px;
317
506
  }
318
- .mg-hint {
319
- font-size: 11px;
507
+ .mg-composer-tag {
508
+ font-size: 12px;
320
509
  color: var(--dsw-alias-label-secondary);
321
510
  }
322
- .mg-send-btn {
511
+ .mg-circle-btn {
512
+ display: inline-flex;
513
+ align-items: center;
514
+ justify-content: center;
515
+ width: 30px;
516
+ height: 30px;
323
517
  border: none;
324
- border-radius: 8px;
325
- padding: 5px 12px;
326
- font-size: 12px;
327
- font-weight: 500;
518
+ border-radius: 50%;
328
519
  cursor: pointer;
329
520
  background: var(--dsw-alias-brand-primary);
330
521
  color: #ffffff;
331
- transition: opacity 0.15s ease;
522
+ transition: opacity 0.15s ease, transform 0.1s ease;
332
523
  }
333
- .mg-send-btn:disabled {
334
- opacity: 0.45;
524
+ .mg-circle-btn:disabled {
525
+ opacity: 0.35;
335
526
  cursor: not-allowed;
336
527
  }
337
- .mg-stop-btn {
338
- border: 1px solid var(--dsw-alias-border-l2);
339
- border-radius: 8px;
340
- padding: 5px 12px;
341
- font-size: 12px;
342
- font-weight: 500;
343
- cursor: pointer;
344
- background: var(--dsw-alias-bg-layer-2);
345
- color: var(--dsw-alias-label-primary);
528
+ .mg-circle-btn.is-stop {
529
+ background: var(--dsw-alias-label-primary);
530
+ color: var(--dsw-alias-bg-base);
531
+ }
532
+ .mg-header-btn:focus-visible,
533
+ .mg-sel-btn:focus-visible,
534
+ .mg-seg-btn:focus-visible,
535
+ .mg-pill-btn:focus-visible,
536
+ .mg-chip:focus-visible,
537
+ .mg-action-link:focus-visible,
538
+ .mg-circle-btn:focus-visible {
539
+ outline: 2px solid var(--dsw-alias-brand-primary);
540
+ outline-offset: 1px;
346
541
  }
347
542
  `;
348
543
 
@@ -364,10 +559,186 @@ window.__ModuleLoader__.load({
364
559
  },
365
560
  h('rect', { x: 3.5, y: 4, width: 9.5, height: 16, rx: 2 }),
366
561
  h('path', { d: 'M6.5 8.5h3.5M6.5 12h3.5M6.5 15.5h2' }),
367
- h('path', { d: 'M14 7.5a2 2 0 0 1 2-2h3a2 2 0 0 1 2 2v6a2 2 0 0 1-2 2h-1.8L15 17.5V15.5a1.5 1.5 0 0 1-1-1.4V7.5z' }),
562
+ h('path', {
563
+ d: 'M14 7.5a2 2 0 0 1 2-2h3a2 2 0 0 1 2 2v6a2 2 0 0 1-2 2h-1.8L15 17.5V15.5a1.5 1.5 0 0 1-1-1.4V7.5z',
564
+ }),
368
565
  );
369
566
  }
370
567
 
568
+ function renderInline(text, keyPrefix) {
569
+ const nodes = [];
570
+ const tokenRe = /(`[^`]+`|\*\*[^*]+\*\*|\*[^*]+\*|\[[^\]]+\]\(https?:\/\/[^)]+\))/g;
571
+ let last = 0;
572
+ let match;
573
+ let idx = 0;
574
+ while ((match = tokenRe.exec(text)) !== null) {
575
+ if (match.index > last) {
576
+ nodes.push(text.slice(last, match.index));
577
+ }
578
+ const tok = match[0];
579
+ const k = keyPrefix + '-' + idx++;
580
+ if (tok.startsWith('`') && tok.endsWith('`')) {
581
+ nodes.push(h('code', { key: k }, tok.slice(1, -1)));
582
+ } else if (tok.startsWith('**') && tok.endsWith('**')) {
583
+ nodes.push(h('strong', { key: k }, tok.slice(2, -2)));
584
+ } else if (tok.startsWith('*') && tok.endsWith('*')) {
585
+ nodes.push(h('em', { key: k }, tok.slice(1, -1)));
586
+ } else if (tok.startsWith('[')) {
587
+ const split = tok.indexOf('](');
588
+ const label = tok.slice(1, split);
589
+ const href = tok.slice(split + 2, -1);
590
+ nodes.push(
591
+ h(
592
+ 'a',
593
+ { key: k, href, target: '_blank', rel: 'noopener noreferrer' },
594
+ label,
595
+ ),
596
+ );
597
+ }
598
+ last = tokenRe.lastIndex;
599
+ }
600
+ if (last < text.length) {
601
+ nodes.push(text.slice(last));
602
+ }
603
+ return nodes;
604
+ }
605
+
606
+ function MarkdownBlock({ text, copyLabel, copiedLabel }) {
607
+ const [copiedCodeIdx, setCopiedCodeIdx] = React.useState(null);
608
+ if (!text) return null;
609
+
610
+ const blocks = [];
611
+ const fenceRe = /```([a-zA-Z0-9_-]*)\n([\s\S]*?)```/g;
612
+ let last = 0;
613
+ let m;
614
+ let partIdx = 0;
615
+ while ((m = fenceRe.exec(text)) !== null) {
616
+ if (m.index > last) {
617
+ blocks.push({ kind: 'prose', content: text.slice(last, m.index), key: 'p-' + partIdx++ });
618
+ }
619
+ blocks.push({ kind: 'code', lang: m[1] || 'code', content: m[2].replace(/\n$/, ''), key: 'c-' + partIdx++ });
620
+ last = fenceRe.lastIndex;
621
+ }
622
+ if (last < text.length) {
623
+ blocks.push({ kind: 'prose', content: text.slice(last), key: 'p-' + partIdx++ });
624
+ }
625
+
626
+ const elements = [];
627
+ for (const blk of blocks) {
628
+ if (blk.kind === 'code') {
629
+ const codeKey = blk.key;
630
+ elements.push(
631
+ h(
632
+ 'div',
633
+ { key: codeKey, className: 'mg-code-wrap' },
634
+ h(
635
+ 'div',
636
+ { className: 'mg-code-head' },
637
+ h('span', null, blk.lang),
638
+ h(
639
+ 'button',
640
+ {
641
+ type: 'button',
642
+ className: 'mg-action-link',
643
+ onClick: () => {
644
+ navigator.clipboard?.writeText(blk.content).then(() => {
645
+ setCopiedCodeIdx(codeKey);
646
+ window.setTimeout(() => {
647
+ setCopiedCodeIdx((c) => (c === codeKey ? null : c));
648
+ }, 1500);
649
+ }).catch(() => {});
650
+ },
651
+ },
652
+ copiedCodeIdx === codeKey ? copiedLabel : copyLabel,
653
+ ),
654
+ ),
655
+ h('pre', { className: 'mg-code-pre' }, h('code', null, blk.content)),
656
+ ),
657
+ );
658
+ continue;
659
+ }
660
+
661
+ const lines = blk.content.split(/\r?\n/);
662
+ let listItems = [];
663
+ let listOrdered = false;
664
+ let pLines = [];
665
+ let subIdx = 0;
666
+
667
+ const flushPara = () => {
668
+ if (pLines.length === 0) return;
669
+ const joined = pLines.join('\n').trim();
670
+ pLines = [];
671
+ if (!joined) return;
672
+ elements.push(h('p', { key: blk.key + '-p-' + subIdx++ }, renderInline(joined, blk.key + '-i-' + subIdx)));
673
+ };
674
+
675
+ const flushList = () => {
676
+ if (listItems.length === 0) return;
677
+ const items = listItems;
678
+ const ordered = listOrdered;
679
+ listItems = [];
680
+ elements.push(
681
+ h(
682
+ ordered ? 'ol' : 'ul',
683
+ { key: blk.key + '-l-' + subIdx++ },
684
+ items.map((item, i) =>
685
+ h('li', { key: i }, renderInline(item, blk.key + '-li-' + subIdx + '-' + i)),
686
+ ),
687
+ ),
688
+ );
689
+ };
690
+
691
+ for (const line of lines) {
692
+ const trimmed = line.trim();
693
+ if (!trimmed) {
694
+ flushPara();
695
+ flushList();
696
+ continue;
697
+ }
698
+ const headingMatch = trimmed.match(/^(#{1,4})\s+(.+)$/);
699
+ if (headingMatch) {
700
+ flushPara();
701
+ flushList();
702
+ const lvl = headingMatch[1].length;
703
+ elements.push(
704
+ h('h' + lvl, { key: blk.key + '-h-' + subIdx++ }, renderInline(headingMatch[2], blk.key + '-hi-' + subIdx)),
705
+ );
706
+ continue;
707
+ }
708
+ const ulMatch = trimmed.match(/^[-*]\s+(.+)$/);
709
+ if (ulMatch) {
710
+ flushPara();
711
+ if (listItems.length > 0 && listOrdered) flushList();
712
+ listOrdered = false;
713
+ listItems.push(ulMatch[1]);
714
+ continue;
715
+ }
716
+ const olMatch = trimmed.match(/^\d+\.\s+(.+)$/);
717
+ if (olMatch) {
718
+ flushPara();
719
+ if (listItems.length > 0 && !listOrdered) flushList();
720
+ listOrdered = true;
721
+ listItems.push(olMatch[1]);
722
+ continue;
723
+ }
724
+ if (trimmed.startsWith('> ')) {
725
+ flushPara();
726
+ flushList();
727
+ elements.push(
728
+ h('blockquote', { key: blk.key + '-q-' + subIdx++ }, renderInline(trimmed.slice(2), blk.key + '-qi-' + subIdx)),
729
+ );
730
+ continue;
731
+ }
732
+ flushList();
733
+ pLines.push(line);
734
+ }
735
+ flushPara();
736
+ flushList();
737
+ }
738
+
739
+ return h('div', { className: 'mg-md' }, elements);
740
+ }
741
+
371
742
  function loadStoredMessages(sessionId) {
372
743
  if (!sessionId) return [];
373
744
  try {
@@ -387,6 +758,7 @@ window.__ModuleLoader__.load({
387
758
  id: m.id,
388
759
  role: m.role,
389
760
  text: m.text,
761
+ quotes: m.quotes,
390
762
  model: m.model,
391
763
  error: m.error,
392
764
  }));
@@ -404,11 +776,31 @@ window.__ModuleLoader__.load({
404
776
  }
405
777
 
406
778
  return {
407
- inject: ['slots', 'locale', 'sidebarRight', 'sidebarRightTabs', 'remote'],
779
+ inject: ['slots', 'locale', 'sidebarRight', 'sidebarRightTabs', 'remote', 'uiSession'],
408
780
  apply(ctx) {
409
781
  ctx.effect(() => ctx.locale.register('marginalia', { en, zh }), 'marginalia: locale');
410
782
  const t = ctx.locale.bind('marginalia');
411
783
 
784
+ // Shared quote bus so selecting text in the main chat immediately populates the side chat.
785
+ let pendingQuotes = [];
786
+ const quoteListeners = new Set();
787
+ function pushQuote(text) {
788
+ const clean = (text || '').trim();
789
+ if (!clean) return;
790
+ if (!pendingQuotes.includes(clean)) {
791
+ pendingQuotes = [...pendingQuotes, clean].slice(-5);
792
+ }
793
+ for (const fn of quoteListeners) fn(pendingQuotes);
794
+ }
795
+ function clearQuotes() {
796
+ pendingQuotes = [];
797
+ for (const fn of quoteListeners) fn(pendingQuotes);
798
+ }
799
+ function removeQuoteAt(index) {
800
+ pendingQuotes = pendingQuotes.filter((_, i) => i !== index);
801
+ for (const fn of quoteListeners) fn(pendingQuotes);
802
+ }
803
+
412
804
  ctx.effect(() => {
413
805
  const styleEl = document.createElement('style');
414
806
  styleEl.setAttribute('data-marginalia-styles', 'true');
@@ -440,6 +832,119 @@ window.__ModuleLoader__.load({
440
832
  'marginalia: tab-type',
441
833
  );
442
834
 
835
+ function SelectionFloatingBar() {
836
+ const [, setTick] = React.useState(0);
837
+ const [sel, setSel] = React.useState(null);
838
+
839
+ React.useEffect(() => ctx.locale.subscribe(() => setTick((v) => v + 1)), []);
840
+
841
+ React.useEffect(() => {
842
+ const updateSelection = () => {
843
+ const s = window.getSelection();
844
+ if (!s || s.isCollapsed || s.rangeCount === 0) {
845
+ setSel(null);
846
+ return;
847
+ }
848
+ const text = s.toString().trim();
849
+ if (text.length < 2) {
850
+ setSel(null);
851
+ return;
852
+ }
853
+ const anchorEl =
854
+ s.anchorNode?.nodeType === 1 ? s.anchorNode : s.anchorNode?.parentElement;
855
+ if (!anchorEl) {
856
+ setSel(null);
857
+ return;
858
+ }
859
+ if (
860
+ anchorEl.closest('[data-marginalia-root]') ||
861
+ anchorEl.closest('input, textarea, [contenteditable="true"]')
862
+ ) {
863
+ setSel(null);
864
+ return;
865
+ }
866
+ const range = s.getRangeAt(0);
867
+ const rect = range.getBoundingClientRect();
868
+ if (!rect || (rect.width === 0 && rect.height === 0)) {
869
+ setSel(null);
870
+ return;
871
+ }
872
+ const left = Math.min(Math.max(rect.left + rect.width / 2, 130), window.innerWidth - 130);
873
+ const top = Math.max(rect.top - 8, 48);
874
+ setSel({ text, left, top });
875
+ };
876
+
877
+ const onMouseUp = () => window.setTimeout(updateSelection, 10);
878
+ const onKeyUp = () => window.setTimeout(updateSelection, 10);
879
+ const onScroll = () => setSel(null);
880
+
881
+ document.addEventListener('mouseup', onMouseUp);
882
+ document.addEventListener('keyup', onKeyUp);
883
+ window.addEventListener('scroll', onScroll, true);
884
+ return () => {
885
+ document.removeEventListener('mouseup', onMouseUp);
886
+ document.removeEventListener('keyup', onKeyUp);
887
+ window.removeEventListener('scroll', onScroll, true);
888
+ };
889
+ }, []);
890
+
891
+ if (!sel) return null;
892
+
893
+ const currentSessionId = ctx.uiSession?.adapter?.current?.getSnapshot()?.key;
894
+
895
+ return h(
896
+ 'div',
897
+ {
898
+ className: 'mg-sel-bar',
899
+ style: { left: sel.left + 'px', top: sel.top + 'px' },
900
+ onMouseDown: (e) => e.preventDefault(),
901
+ },
902
+ h(
903
+ 'button',
904
+ {
905
+ type: 'button',
906
+ className: 'mg-sel-btn',
907
+ onClick: () => {
908
+ const quoted = '> ' + sel.text.replace(/\n/g, '\n> ') + '\n\n';
909
+ navigator.clipboard?.writeText(quoted).catch(() => {});
910
+ if (currentSessionId && typeof ctx.remote?.session?.prompt === 'function') {
911
+ // Focus main composer if available; otherwise copy quote.
912
+ const composer = document.querySelector('textarea:not([data-marginalia-input])');
913
+ if (composer) {
914
+ composer.focus();
915
+ const setter = Object.getOwnPropertyDescriptor(
916
+ window.HTMLTextAreaElement.prototype,
917
+ 'value',
918
+ )?.set;
919
+ const nextVal = (composer.value ? composer.value + '\n' : '') + quoted;
920
+ setter?.call(composer, nextVal);
921
+ composer.dispatchEvent(new Event('input', { bubbles: true }));
922
+ }
923
+ }
924
+ window.getSelection()?.removeAllRanges();
925
+ setSel(null);
926
+ },
927
+ },
928
+ t('sel.addToChat'),
929
+ ),
930
+ h('div', { className: 'mg-sel-sep' }),
931
+ h(
932
+ 'button',
933
+ {
934
+ type: 'button',
935
+ className: 'mg-sel-btn',
936
+ onClick: () => {
937
+ pushQuote(sel.text);
938
+ window.getSelection()?.removeAllRanges();
939
+ setSel(null);
940
+ ctx.sidebarRight.openTab(TAB_KIND);
941
+ },
942
+ },
943
+ t('sel.askSide'),
944
+ ),
945
+ );
946
+ }
947
+
443
948
  function HeaderTrigger() {
444
949
  const [, setTick] = React.useState(0);
445
950
  React.useEffect(() => ctx.locale.subscribe(() => setTick((v) => v + 1)), []);
@@ -461,8 +966,10 @@ window.__ModuleLoader__.load({
461
966
 
462
967
  function MarginaliaBody(props) {
463
968
  const sessionId = props?.sessionId;
464
- const sessionStatus = typeof props?.useSessionStatus === 'function' ? props.useSessionStatus() : undefined;
465
- const isMainRunning = Boolean(sessionStatus?.running);
969
+ const isMainRunning =
970
+ typeof props?.useSessionStatus === 'function'
971
+ ? Boolean(props.useSessionStatus((s) => Boolean(s?.running)))
972
+ : false;
466
973
 
467
974
  const [, setLocaleTick] = React.useState(0);
468
975
  React.useEffect(() => ctx.locale.subscribe(() => setLocaleTick((v) => v + 1)), []);
@@ -470,6 +977,8 @@ window.__ModuleLoader__.load({
470
977
  const [mode, setMode] = React.useState('side');
471
978
  const [includeContext, setIncludeContext] = React.useState(true);
472
979
  const [messages, setMessages] = React.useState(() => loadStoredMessages(sessionId));
980
+ const [quotes, setQuotes] = React.useState(() => pendingQuotes);
981
+ const [showQuotePreview, setShowQuotePreview] = React.useState(false);
473
982
  const [draft, setDraft] = React.useState('');
474
983
  const [streaming, setStreaming] = React.useState(false);
475
984
  const [copiedId, setCopiedId] = React.useState(null);
@@ -479,6 +988,18 @@ window.__ModuleLoader__.load({
479
988
  const scrollRef = React.useRef(null);
480
989
  const textareaRef = React.useRef(null);
481
990
 
991
+ React.useEffect(() => {
992
+ const listener = (nextQuotes) => {
993
+ setQuotes(nextQuotes);
994
+ if (nextQuotes.length > 0) {
995
+ setMode('side');
996
+ window.setTimeout(() => textareaRef.current?.focus(), 40);
997
+ }
998
+ };
999
+ quoteListeners.add(listener);
1000
+ return () => quoteListeners.delete(listener);
1001
+ }, []);
1002
+
482
1003
  React.useEffect(() => {
483
1004
  if (abortRef.current) {
484
1005
  abortRef.current.abort();
@@ -500,6 +1021,13 @@ window.__ModuleLoader__.load({
500
1021
  }
501
1022
  }, [messages, streaming]);
502
1023
 
1024
+ React.useEffect(() => {
1025
+ const el = textareaRef.current;
1026
+ if (!el) return;
1027
+ el.style.height = 'auto';
1028
+ el.style.height = Math.min(el.scrollHeight, 160) + 'px';
1029
+ }, [draft]);
1030
+
503
1031
  React.useEffect(() => {
504
1032
  return () => {
505
1033
  if (abortRef.current) {
@@ -545,22 +1073,43 @@ window.__ModuleLoader__.load({
545
1073
 
546
1074
  async function handleSubmit(overrideText) {
547
1075
  const text = (typeof overrideText === 'string' ? overrideText : draft).trim();
548
- if (!text || streaming) return;
1076
+ const activeQuotes = quotes.slice();
1077
+ if ((!text && activeQuotes.length === 0) || streaming) return;
549
1078
 
550
1079
  if (mode === 'main') {
1080
+ const combined =
1081
+ activeQuotes.length > 0
1082
+ ? activeQuotes.map((q) => '> ' + q.replace(/\n/g, '\n> ')).join('\n\n') +
1083
+ (text ? '\n\n' + text : '')
1084
+ : text;
551
1085
  setDraft('');
552
- await sendToMainChat(text);
1086
+ clearQuotes();
1087
+ await sendToMainChat(combined);
553
1088
  return;
554
1089
  }
555
1090
 
556
1091
  if (!overrideText) setDraft('');
557
- const userMsg = { id: makeId(), role: 'user', text };
1092
+ clearQuotes();
1093
+ setShowQuotePreview(false);
1094
+
1095
+ const userMsg = {
1096
+ id: makeId(),
1097
+ role: 'user',
1098
+ text: text || activeQuotes[0],
1099
+ quotes: text ? activeQuotes : [],
1100
+ };
558
1101
  const assistantId = makeId();
559
1102
  const assistantMsg = { id: assistantId, role: 'assistant', text: '' };
560
1103
 
561
1104
  const priorHistory = messages
562
1105
  .filter((m) => !m.error && m.text)
563
- .map((m) => ({ role: m.role, text: m.text }));
1106
+ .map((m) => ({
1107
+ role: m.role,
1108
+ text:
1109
+ m.quotes && m.quotes.length > 0
1110
+ ? m.quotes.map((q) => '> ' + q).join('\n') + '\n\n' + m.text
1111
+ : m.text,
1112
+ }));
564
1113
 
565
1114
  setMessages((prev) => [...prev, userMsg, assistantMsg]);
566
1115
  setStreaming(true);
@@ -576,6 +1125,7 @@ window.__ModuleLoader__.load({
576
1125
  body: JSON.stringify({
577
1126
  sessionId: sessionId || '',
578
1127
  question: text,
1128
+ quotes: activeQuotes,
579
1129
  includeContext,
580
1130
  history: priorHistory,
581
1131
  }),
@@ -644,7 +1194,9 @@ window.__ModuleLoader__.load({
644
1194
  const msg = err instanceof Error ? err.message : String(err);
645
1195
  setMessages((prev) =>
646
1196
  prev.map((m) =>
647
- m.id === assistantId ? { ...m, text: msg || t('error.sendFailed'), error: true } : m,
1197
+ m.id === assistantId
1198
+ ? { ...m, text: msg || t('error.sendFailed'), error: true }
1199
+ : m,
648
1200
  ),
649
1201
  );
650
1202
  }
@@ -666,19 +1218,25 @@ window.__ModuleLoader__.load({
666
1218
 
667
1219
  function handleCopy(msg) {
668
1220
  if (!msg?.text || !navigator.clipboard) return;
669
- navigator.clipboard.writeText(msg.text).then(() => {
670
- setCopiedId(msg.id);
671
- window.setTimeout(() => {
672
- setCopiedId((curr) => (curr === msg.id ? null : curr));
673
- }, 1600);
674
- }).catch(() => {});
1221
+ navigator.clipboard
1222
+ .writeText(msg.text)
1223
+ .then(() => {
1224
+ setCopiedId(msg.id);
1225
+ window.setTimeout(() => {
1226
+ setCopiedId((curr) => (curr === msg.id ? null : curr));
1227
+ }, 1600);
1228
+ })
1229
+ .catch(() => {});
675
1230
  }
676
1231
 
677
1232
  const chips = [t('chip.summarize'), t('chip.explain'), t('chip.next')];
1233
+ const quoteLabel = (
1234
+ quotes.length === 1 ? t('quote.count') : t('quote.countPlural')
1235
+ ).replace('{n}', String(quotes.length));
678
1236
 
679
1237
  return h(
680
1238
  'div',
681
- { className: 'mg-root' },
1239
+ { className: 'mg-root', 'data-marginalia-root': 'true' },
682
1240
  h(
683
1241
  'div',
684
1242
  { className: 'mg-toolbar' },
@@ -733,7 +1291,7 @@ window.__ModuleLoader__.load({
733
1291
  saveStoredMessages(sessionId, []);
734
1292
  },
735
1293
  },
736
- t('clear'),
1294
+ t('newChat'),
737
1295
  )
738
1296
  : null,
739
1297
  ),
@@ -745,6 +1303,7 @@ window.__ModuleLoader__.load({
745
1303
  ? h(
746
1304
  'div',
747
1305
  { className: 'mg-empty' },
1306
+ h('div', { className: 'mg-empty-icon' }, h(MarginaliaGlyph, { size: 20 })),
748
1307
  h('div', { className: 'mg-empty-title' }, t('empty.title')),
749
1308
  h(
750
1309
  'div',
@@ -771,48 +1330,75 @@ window.__ModuleLoader__.load({
771
1330
  : null,
772
1331
  )
773
1332
  : messages.map((msg) =>
774
- h(
775
- 'div',
776
- {
777
- key: msg.id,
778
- className:
779
- 'mg-msg ' +
780
- (msg.role === 'user' ? 'is-user' : 'is-assistant') +
781
- (msg.error ? ' is-error' : ''),
782
- },
783
- h(
784
- 'div',
785
- { className: 'mg-bubble' },
786
- msg.text || (streaming && msg.role === 'assistant' ? t('thinking') : ''),
787
- ),
788
- msg.text
789
- ? h(
790
- 'div',
791
- { className: 'mg-msg-meta' },
792
- msg.model ? h('span', null, msg.model) : null,
793
- h(
794
- 'button',
795
- {
796
- type: 'button',
797
- className: 'mg-action-link',
798
- onClick: () => handleCopy(msg),
799
- },
800
- copiedId === msg.id ? t('copied') : t('copy'),
801
- ),
802
- !msg.error
803
- ? h(
1333
+ msg.role === 'user'
1334
+ ? h(
1335
+ 'div',
1336
+ { key: msg.id, className: 'mg-msg is-user' },
1337
+ msg.quotes && msg.quotes.length > 0
1338
+ ? h(
1339
+ 'div',
1340
+ { className: 'mg-user-quotes' },
1341
+ h(
1342
+ 'span',
1343
+ { className: 'mg-quote-chip' },
1344
+ (msg.quotes.length === 1 ? t('quote.count') : t('quote.countPlural')).replace(
1345
+ '{n}',
1346
+ String(msg.quotes.length),
1347
+ ),
1348
+ ),
1349
+ )
1350
+ : null,
1351
+ h('div', { className: 'mg-user-bubble' }, msg.text),
1352
+ )
1353
+ : h(
1354
+ 'div',
1355
+ { key: msg.id, className: 'mg-msg is-assistant' },
1356
+ msg.text
1357
+ ? h(
1358
+ 'div',
1359
+ { className: 'mg-assistant-body' + (msg.error ? ' is-error' : '') },
1360
+ msg.error
1361
+ ? msg.text
1362
+ : h(MarkdownBlock, {
1363
+ text: msg.text,
1364
+ copyLabel: t('copy'),
1365
+ copiedLabel: t('copied'),
1366
+ }),
1367
+ )
1368
+ : h(
1369
+ 'div',
1370
+ { className: 'mg-thinking' },
1371
+ h('span', { className: 'mg-dot' }),
1372
+ h('span', null, t('thinking')),
1373
+ ),
1374
+ msg.text
1375
+ ? h(
1376
+ 'div',
1377
+ { className: 'mg-msg-meta' },
1378
+ msg.model ? h('span', null, msg.model) : null,
1379
+ h(
804
1380
  'button',
805
1381
  {
806
1382
  type: 'button',
807
1383
  className: 'mg-action-link',
808
- onClick: () => sendToMainChat(msg.text),
1384
+ onClick: () => handleCopy(msg),
809
1385
  },
810
- t('promote'),
811
- )
812
- : null,
813
- )
814
- : null,
815
- ),
1386
+ copiedId === msg.id ? t('copied') : t('copy'),
1387
+ ),
1388
+ !msg.error
1389
+ ? h(
1390
+ 'button',
1391
+ {
1392
+ type: 'button',
1393
+ className: 'mg-action-link',
1394
+ onClick: () => sendToMainChat(msg.text),
1395
+ },
1396
+ t('promote'),
1397
+ )
1398
+ : null,
1399
+ )
1400
+ : null,
1401
+ ),
816
1402
  ),
817
1403
  ),
818
1404
  notice
@@ -824,9 +1410,59 @@ window.__ModuleLoader__.load({
824
1410
  h(
825
1411
  'div',
826
1412
  { className: 'mg-input-box' },
1413
+ quotes.length > 0
1414
+ ? h(
1415
+ 'div',
1416
+ { className: 'mg-quote-strip' },
1417
+ h(
1418
+ 'div',
1419
+ {
1420
+ className: 'mg-quote-chip',
1421
+ onClick: () => setShowQuotePreview((v) => !v),
1422
+ },
1423
+ h('span', null, quoteLabel),
1424
+ h(
1425
+ 'button',
1426
+ {
1427
+ type: 'button',
1428
+ className: 'mg-quote-x',
1429
+ 'aria-label': 'Clear',
1430
+ onClick: (e) => {
1431
+ e.stopPropagation();
1432
+ clearQuotes();
1433
+ setShowQuotePreview(false);
1434
+ },
1435
+ },
1436
+ '×',
1437
+ ),
1438
+ ),
1439
+ showQuotePreview
1440
+ ? quotes.map((q, idx) =>
1441
+ h(
1442
+ 'div',
1443
+ { key: idx, className: 'mg-quote-preview' },
1444
+ q,
1445
+ quotes.length > 1
1446
+ ? h(
1447
+ 'button',
1448
+ {
1449
+ type: 'button',
1450
+ className: 'mg-quote-x',
1451
+ onClick: () => removeQuoteAt(idx),
1452
+ },
1453
+ ' ×',
1454
+ )
1455
+ : null,
1456
+ ),
1457
+ )
1458
+ : null,
1459
+ )
1460
+ : null,
827
1461
  h('textarea', {
828
1462
  ref: textareaRef,
1463
+ 'data-marginalia-input': 'true',
829
1464
  className: 'mg-textarea',
1465
+ rows: 1,
830
1466
  value: draft,
831
1467
  placeholder: mode === 'side' ? t('placeholder.side') : t('placeholder.main'),
832
1468
  onChange: (e) => setDraft(e.target.value),
@@ -841,26 +1477,55 @@ window.__ModuleLoader__.load({
841
1477
  h(
842
1478
  'div',
843
1479
  { className: 'mg-composer-foot' },
844
- h('span', { className: 'mg-hint' }, t('hint.enter')),
1480
+ h(
1481
+ 'span',
1482
+ { className: 'mg-composer-tag' },
1483
+ mode === 'side'
1484
+ ? includeContext
1485
+ ? t('context.on')
1486
+ : t('context.off')
1487
+ : t('mode.main'),
1488
+ ),
845
1489
  streaming
846
1490
  ? h(
847
1491
  'button',
848
1492
  {
849
1493
  type: 'button',
850
- className: 'mg-stop-btn',
1494
+ className: 'mg-circle-btn is-stop',
1495
+ title: t('stop'),
1496
+ 'aria-label': t('stop'),
851
1497
  onClick: handleStop,
852
1498
  },
853
- t('stop'),
1499
+ h(
1500
+ 'svg',
1501
+ { width: 12, height: 12, viewBox: '0 0 12 12', fill: 'currentColor' },
1502
+ h('rect', { x: 2, y: 2, width: 8, height: 8, rx: 1.5 }),
1503
+ ),
854
1504
  )
855
1505
  : h(
856
1506
  'button',
857
1507
  {
858
1508
  type: 'button',
859
- className: 'mg-send-btn',
860
- disabled: !draft.trim(),
1509
+ className: 'mg-circle-btn',
1510
+ title: t('send'),
1511
+ 'aria-label': t('send'),
1512
+ disabled: !draft.trim() && quotes.length === 0,
861
1513
  onClick: () => handleSubmit(),
862
1514
  },
863
- t('send'),
1515
+ h(
1516
+ 'svg',
1517
+ {
1518
+ width: 15,
1519
+ height: 15,
1520
+ viewBox: '0 0 24 24',
1521
+ fill: 'none',
1522
+ stroke: 'currentColor',
1523
+ strokeWidth: 2.3,
1524
+ strokeLinecap: 'round',
1525
+ strokeLinejoin: 'round',
1526
+ },
1527
+ h('path', { d: 'M12 19V5M5 12l7-7 7 7' }),
1528
+ ),
864
1529
  ),
865
1530
  ),
866
1531
  ),
@@ -890,6 +1555,17 @@ window.__ModuleLoader__.load({
890
1555
  HeaderTrigger,
891
1556
  ),
892
1557
  );
1558
+
1559
+ ctx.slots.inject('shell.overlay', () =>
1560
+ ctx.slots.register(
1561
+ {
1562
+ name: 'shell.overlay',
1563
+ id: 'marginalia-selection-bar',
1564
+ order: 50,
1565
+ },
1566
+ SelectionFloatingBar,
1567
+ ),
1568
+ );
893
1569
  },
894
1570
  };
895
1571
  },