dsh-ide-window 0.4.0 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +11 -3
- package/CHANGELOG.md +30 -0
- package/client.js +680 -113
- package/locale/en.json +17 -0
- package/locale/zh.json +17 -0
- package/package.json +2 -2
package/client.js
CHANGED
|
@@ -341,6 +341,7 @@ window.__ModuleLoader__.load({
|
|
|
341
341
|
"floatCollapse": "Collapse",
|
|
342
342
|
"floatExpand": "Expand assistant",
|
|
343
343
|
"floatEmpty": "Ask something; the answer lands in this session",
|
|
344
|
+
"floatLoadingOlder": "Loading earlier messages…",
|
|
344
345
|
"floatNoSession": "No session bound yet",
|
|
345
346
|
"floatNoWorkspace": "no workspace",
|
|
346
347
|
"floatPlaceholder": "Message or create a task, / for commands, @ for files or chats",
|
|
@@ -373,6 +374,17 @@ window.__ModuleLoader__.load({
|
|
|
373
374
|
"floatNoticeAttempt": "Attempt failed",
|
|
374
375
|
"floatNoticeRetry": "Model retry",
|
|
375
376
|
"floatNoticeApproval": "Approval requested",
|
|
377
|
+
"floatApprovalPending": "Waiting for approval",
|
|
378
|
+
"floatApprovalSettled": "Approval result",
|
|
379
|
+
"floatApprovalTitle": "A tool asks for more access",
|
|
380
|
+
"floatApprovalTool": "Tool",
|
|
381
|
+
"floatApprovalHint": "Approvals are answered in the conversation",
|
|
382
|
+
"floatApprovalGo": "Go to the conversation",
|
|
383
|
+
"floatApprovalBallHint": "An approval is waiting — click to open",
|
|
384
|
+
"floatApprovalAllowed": "Allowed once",
|
|
385
|
+
"floatApprovalRejected": "Rejected",
|
|
386
|
+
"floatApprovalCancelled": "Cancelled",
|
|
387
|
+
"floatApprovalUnavailable": "No answerer available",
|
|
376
388
|
"floatNoticeApprovalResult": "Approval result",
|
|
377
389
|
"floatNoticeApprovalPolicy": "Approval policy",
|
|
378
390
|
"floatNoticeWorkspace": "Workspace changed",
|
|
@@ -409,6 +421,7 @@ window.__ModuleLoader__.load({
|
|
|
409
421
|
"floatSessionFailed": "Switching the session failed",
|
|
410
422
|
"floatCurrentWorkspace": "current",
|
|
411
423
|
"settingsFloat": "Floating assistant",
|
|
424
|
+
"settingsFloatEnable": "Enable",
|
|
412
425
|
"settingsFloatHint": "When off, the floating card no longer opens in the code workspace",
|
|
413
426
|
"settingsOn": "On",
|
|
414
427
|
"settingsOff": "Off",
|
|
@@ -438,6 +451,10 @@ window.__ModuleLoader__.load({
|
|
|
438
451
|
"floatCloseViewer": "Close",
|
|
439
452
|
"settingsFloatDetach": "Detach from the workspace",
|
|
440
453
|
"settingsFloatDetachHint": "Keep the card on screen when you switch to another panel or back to the conversation",
|
|
454
|
+
"settingsFloatGroup": "Floating card",
|
|
455
|
+
"settingsFloatFollow": "Follow the current conversation",
|
|
456
|
+
"settingsFloatFollowHint": "When off, switching conversations in DSH leaves the card alone; switch inside the card's title menu instead",
|
|
457
|
+
"floatPinnedHint": "Not following DSH · pick a conversation below",
|
|
441
458
|
"settingsFloatEvents": "Show full detail",
|
|
442
459
|
"settingsFloatEventsHint": "List reasoning, context, Tool arguments and system events; off shows only the latest status line",
|
|
443
460
|
"floatWrap": "Wrap lines",
|
|
@@ -776,6 +793,7 @@ window.__ModuleLoader__.load({
|
|
|
776
793
|
"floatCollapse": "收起",
|
|
777
794
|
"floatExpand": "展开助手",
|
|
778
795
|
"floatEmpty": "问点什么,回答会出现在当前会话里",
|
|
796
|
+
"floatLoadingOlder": "正在加载更早的消息…",
|
|
779
797
|
"floatNoSession": "还没有绑定会话",
|
|
780
798
|
"floatNoWorkspace": "未选择工作区",
|
|
781
799
|
"floatPlaceholder": "发消息或创建任务,/ 调用指令,@ 文件或对话",
|
|
@@ -808,6 +826,17 @@ window.__ModuleLoader__.load({
|
|
|
808
826
|
"floatNoticeAttempt": "模型尝试失败",
|
|
809
827
|
"floatNoticeRetry": "模型重试",
|
|
810
828
|
"floatNoticeApproval": "审批请求",
|
|
829
|
+
"floatApprovalPending": "等待审批",
|
|
830
|
+
"floatApprovalSettled": "审批结果",
|
|
831
|
+
"floatApprovalTitle": "工具请求更高权限",
|
|
832
|
+
"floatApprovalTool": "工具",
|
|
833
|
+
"floatApprovalHint": "审批只能在对话里作答",
|
|
834
|
+
"floatApprovalGo": "去对话处理",
|
|
835
|
+
"floatApprovalBallHint": "有审批在等,点开处理",
|
|
836
|
+
"floatApprovalAllowed": "已允许这一次",
|
|
837
|
+
"floatApprovalRejected": "已拒绝",
|
|
838
|
+
"floatApprovalCancelled": "已取消",
|
|
839
|
+
"floatApprovalUnavailable": "没有可用的审批人",
|
|
811
840
|
"floatNoticeApprovalResult": "审批结果",
|
|
812
841
|
"floatNoticeApprovalPolicy": "审批策略",
|
|
813
842
|
"floatNoticeWorkspace": "文件变更",
|
|
@@ -844,6 +873,7 @@ window.__ModuleLoader__.load({
|
|
|
844
873
|
"floatSessionFailed": "切换会话失败",
|
|
845
874
|
"floatCurrentWorkspace": "当前",
|
|
846
875
|
"settingsFloat": "悬浮助手卡",
|
|
876
|
+
"settingsFloatEnable": "启用",
|
|
847
877
|
"settingsFloatHint": "关掉后进入代码工作区不再自动弹出悬浮卡",
|
|
848
878
|
"settingsOn": "已启用",
|
|
849
879
|
"settingsOff": "已关闭",
|
|
@@ -873,6 +903,10 @@ window.__ModuleLoader__.load({
|
|
|
873
903
|
"floatCloseViewer": "关闭",
|
|
874
904
|
"settingsFloatDetach": "脱离代码工作区",
|
|
875
905
|
"settingsFloatDetachHint": "开启后悬浮框不再跟着代码工作区出现与消失:切到其他插件视图或回到对话时它依然在",
|
|
906
|
+
"settingsFloatGroup": "悬浮助手卡",
|
|
907
|
+
"settingsFloatFollow": "跟随当前会话",
|
|
908
|
+
"settingsFloatFollowHint": "关闭后,在 DSH 里切换会话不会带动悬浮卡;只能在悬浮卡标题菜单里手动切换",
|
|
909
|
+
"floatPinnedHint": "不跟随当前会话 · 在下面手动切换",
|
|
876
910
|
"settingsFloatEvents": "显示详细过程",
|
|
877
911
|
"settingsFloatEventsHint": "把思考、上下文注入、工具参数与系统事件全部列出来;关闭时只显示最新一条状态",
|
|
878
912
|
"floatWrap": "自动换行",
|
|
@@ -2055,7 +2089,26 @@ html.iw-select-code .iw-code .iw-vision {
|
|
|
2055
2089
|
/* Every child measures like the card, or a 100%-wide textarea with its own
|
|
2056
2090
|
padding pokes through the right border (rounded on one side, square on the other). */
|
|
2057
2091
|
.iw-float, .iw-float *, .iw-float *::before, .iw-float *::after { box-sizing: border-box; }
|
|
2058
|
-
.iw-float-head {
|
|
2092
|
+
.iw-float-head {
|
|
2093
|
+
position: relative;
|
|
2094
|
+
display: flex;
|
|
2095
|
+
align-items: center;
|
|
2096
|
+
justify-content: center;
|
|
2097
|
+
gap: 6px;
|
|
2098
|
+
min-height: 24px;
|
|
2099
|
+
cursor: grab;
|
|
2100
|
+
user-select: none;
|
|
2101
|
+
touch-action: none;
|
|
2102
|
+
}
|
|
2103
|
+
/* 左右两簇贴边,标题才能在整个表头里居中(而不是在剩余空隙里居中)。 */
|
|
2104
|
+
.iw-float-head > .iw-float-dot { position: absolute; left: 0; }
|
|
2105
|
+
.iw-float-head-right {
|
|
2106
|
+
position: absolute;
|
|
2107
|
+
right: 0;
|
|
2108
|
+
display: flex;
|
|
2109
|
+
align-items: center;
|
|
2110
|
+
gap: 2px;
|
|
2111
|
+
}
|
|
2059
2112
|
.iw-float-head:active { cursor: grabbing; }
|
|
2060
2113
|
.iw-float-collapsed {
|
|
2061
2114
|
padding: 4px;
|
|
@@ -2595,9 +2648,11 @@ html.iw-select-code .iw-code .iw-vision {
|
|
|
2595
2648
|
.iw-float-title-btn {
|
|
2596
2649
|
display: inline-flex;
|
|
2597
2650
|
align-items: center;
|
|
2651
|
+
justify-content: center;
|
|
2598
2652
|
gap: 3px;
|
|
2599
2653
|
min-width: 0;
|
|
2600
|
-
|
|
2654
|
+
/* 20 个字左右:标题是最能区分会话的东西,别只剩半截;但要给右侧按钮组让位。 */
|
|
2655
|
+
max-width: min(calc(100% - 96px), 21em);
|
|
2601
2656
|
flex: 0 1 auto;
|
|
2602
2657
|
padding: 1px 4px;
|
|
2603
2658
|
border: 0;
|
|
@@ -2610,11 +2665,30 @@ html.iw-select-code .iw-code .iw-vision {
|
|
|
2610
2665
|
overflow: hidden;
|
|
2611
2666
|
}
|
|
2612
2667
|
/* The label truncates; the caret must never be the thing that gets clipped. */
|
|
2613
|
-
.iw-float-title
|
|
2668
|
+
/* 两个类的选择器:基础 .iw-float-title 也落在这个 span 上,靠顺序会被它压回去。 */
|
|
2669
|
+
.iw-float-title-btn .iw-float-title-text {
|
|
2614
2670
|
min-width: 0;
|
|
2671
|
+
max-width: 100%;
|
|
2672
|
+
font-size: 16px;
|
|
2673
|
+
line-height: 24px;
|
|
2674
|
+
letter-spacing: 0.1px;
|
|
2615
2675
|
overflow: hidden;
|
|
2616
2676
|
text-overflow: ellipsis;
|
|
2617
2677
|
white-space: nowrap;
|
|
2678
|
+
/* 按工作区取色(--iw-float-hue),再和正文主色混,浅色/深色都压得住对比度。 */
|
|
2679
|
+
color: color-mix(
|
|
2680
|
+
in oklab,
|
|
2681
|
+
hsl(var(--iw-float-hue, 214) 68% 52%) 72%,
|
|
2682
|
+
var(--dsw-alias-label-primary, currentColor)
|
|
2683
|
+
);
|
|
2684
|
+
}
|
|
2685
|
+
.iw-float-older {
|
|
2686
|
+
flex: 0 0 auto;
|
|
2687
|
+
padding: 2px 0 6px;
|
|
2688
|
+
text-align: center;
|
|
2689
|
+
font-size: 12.5px;
|
|
2690
|
+
line-height: 18px;
|
|
2691
|
+
color: var(--dsw-alias-label-tertiary, #81858c);
|
|
2618
2692
|
}
|
|
2619
2693
|
.iw-float-title-btn:hover { background: var(--dsw-alias-card-fill-hover, rgba(255, 255, 255, 0.08)); }
|
|
2620
2694
|
/* A model row must be clickable across its whole width, not just on the text. */
|
|
@@ -2670,7 +2744,6 @@ html.iw-select-code .iw-code .iw-vision {
|
|
|
2670
2744
|
overflow: hidden;
|
|
2671
2745
|
text-overflow: ellipsis;
|
|
2672
2746
|
white-space: nowrap;
|
|
2673
|
-
max-width: 150px;
|
|
2674
2747
|
}
|
|
2675
2748
|
.iw-float-model { font-size: 11px; color: var(--dsw-alias-label-tertiary, inherit); }
|
|
2676
2749
|
.iw-float-icon {
|
|
@@ -2776,6 +2849,27 @@ html.iw-select-code .iw-code .iw-vision {
|
|
|
2776
2849
|
.iw-float-ask-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
|
|
2777
2850
|
.iw-float-ask-hint { font-size: 12.5px; line-height: 18px; color: var(--dsw-alias-label-tertiary, #81858c); }
|
|
2778
2851
|
.iw-float-ask-go { flex: 0 0 auto; }
|
|
2852
|
+
/* 审批卡:和问答卡同一张纸,只是多一段「为什么要批」的说明。 */
|
|
2853
|
+
.iw-float-approval-done { opacity: 0.9; }
|
|
2854
|
+
/* 收起成球时,等着的审批用一个小告警点表示。 */
|
|
2855
|
+
.iw-float-ball-btn { position: relative; }
|
|
2856
|
+
.iw-float-ball-dot {
|
|
2857
|
+
position: absolute;
|
|
2858
|
+
top: 7px;
|
|
2859
|
+
right: 7px;
|
|
2860
|
+
width: 9px;
|
|
2861
|
+
height: 9px;
|
|
2862
|
+
border-radius: 50%;
|
|
2863
|
+
background: var(--dsw-alias-state-warn-primary, #d97706);
|
|
2864
|
+
box-shadow: 0 0 0 2px var(--dsw-alias-bg-layer-1, #ffffff);
|
|
2865
|
+
}
|
|
2866
|
+
.iw-float-approval-reason {
|
|
2867
|
+
font-size: 13px;
|
|
2868
|
+
line-height: 20px;
|
|
2869
|
+
color: var(--dsw-alias-label-secondary, #61666b);
|
|
2870
|
+
white-space: pre-wrap;
|
|
2871
|
+
overflow-wrap: anywhere;
|
|
2872
|
+
}
|
|
2779
2873
|
/* The问答 card, borrowed from the conversation: the bubble is the user's own,
|
|
2780
2874
|
header and question in the secondary colour, the picked answer in primary. */
|
|
2781
2875
|
.iw-float-question { display: flex; flex-direction: column; }
|
|
@@ -5034,6 +5128,10 @@ function ideCreateStore(refs) {
|
|
|
5034
5128
|
floatEvents: prefs.floatEvents === true,
|
|
5035
5129
|
// Detached cards stay on screen in every panel, not only the workspace.
|
|
5036
5130
|
floatDetached: prefs.floatDetached === true,
|
|
5131
|
+
// 跟随当前会话(默认):关掉后,DSH 里切会话不再带动卡片,只能在卡片里手动切。
|
|
5132
|
+
floatFollow: prefs.floatFollow !== false,
|
|
5133
|
+
// 不跟随时卡片自己钉住的会话(只本次进程有效,重启回到当前会话)。
|
|
5134
|
+
floatSessionId: null,
|
|
5037
5135
|
floatClosed: false,
|
|
5038
5136
|
// One reference waiting to be appended to the card's draft.
|
|
5039
5137
|
floatInsert: null,
|
|
@@ -5538,6 +5636,25 @@ function ideCreateStore(refs) {
|
|
|
5538
5636
|
if (next) patch({ floatOpen: true, floatClosed: false })
|
|
5539
5637
|
}
|
|
5540
5638
|
|
|
5639
|
+
/**
|
|
5640
|
+
* 悬浮卡要不要跟着当前会话走(持久化,默认跟)。
|
|
5641
|
+
* 关掉的瞬间把当前会话钉住,否则「当前会话」一变它又跟着跑了。
|
|
5642
|
+
*/
|
|
5643
|
+
function setFloatFollow(floatFollow) {
|
|
5644
|
+
const next = floatFollow !== false
|
|
5645
|
+
if (state.floatFollow === next) return
|
|
5646
|
+
ideWritePrefs({ floatFollow: next })
|
|
5647
|
+
// 关掉时把当前会话钉住;重新打开跟随就把钉子清掉,避免下次关掉时用旧值。
|
|
5648
|
+
patch(next ? { floatFollow: true, floatSessionId: null } : { floatFollow: false, floatSessionId: state.sessionId })
|
|
5649
|
+
}
|
|
5650
|
+
|
|
5651
|
+
/** 不跟随时,卡片自己选中的会话(`null` = 还没有手动选过)。 */
|
|
5652
|
+
function setFloatSessionId(floatSessionId) {
|
|
5653
|
+
const next = typeof floatSessionId === 'string' && floatSessionId !== '' ? floatSessionId : null
|
|
5654
|
+
if (state.floatSessionId === next) return
|
|
5655
|
+
patch({ floatSessionId: next })
|
|
5656
|
+
}
|
|
5657
|
+
|
|
5541
5658
|
/** Turn the floating card on or off (persisted). */
|
|
5542
5659
|
function setFloatEvents(floatEvents) {
|
|
5543
5660
|
const next = floatEvents === true
|
|
@@ -6242,6 +6359,8 @@ function ideCreateStore(refs) {
|
|
|
6242
6359
|
setFloatSize,
|
|
6243
6360
|
setFloatDefaultSize,
|
|
6244
6361
|
setFloatEnabled,
|
|
6362
|
+
setFloatFollow,
|
|
6363
|
+
setFloatSessionId,
|
|
6245
6364
|
setFloatEvents,
|
|
6246
6365
|
setFloatDetached,
|
|
6247
6366
|
setFloatClosed,
|
|
@@ -7951,6 +8070,20 @@ function ideIsMarkdownPath(path) {
|
|
|
7951
8070
|
|
|
7952
8071
|
function IdeCodeView({ tab, tr, store, navigate }) {
|
|
7953
8072
|
const scrollRef = useRef(null)
|
|
8073
|
+
// The scrolling element is not the same element for the whole life of this
|
|
8074
|
+
// view: a freshly opened tab first paints the "loading" placeholder and only
|
|
8075
|
+
// then the source, and the Markdown preview swaps the container too. Effects
|
|
8076
|
+
// that read `scrollRef.current` once would keep listening to an element that
|
|
8077
|
+
// is no longer on screen (the scroll listener never attached at all for a
|
|
8078
|
+
// file opened in this session), so the offset was never remembered and
|
|
8079
|
+
// returning to the window put the reader back at line 1. Mirroring the
|
|
8080
|
+
// element into state gives those effects a dependency that changes whenever
|
|
8081
|
+
// the real container does.
|
|
8082
|
+
const [scrollHost, setScrollHost] = useState(null)
|
|
8083
|
+
const holdScroll = useCallback((element) => {
|
|
8084
|
+
scrollRef.current = element
|
|
8085
|
+
setScrollHost(element)
|
|
8086
|
+
}, [])
|
|
7954
8087
|
// While this view is on screen, the page outside it is not selectable, so
|
|
7955
8088
|
// Cmd+A answers with the file instead of the whole shell.
|
|
7956
8089
|
useEffect(() => {
|
|
@@ -8612,6 +8745,8 @@ function IdeCodeView({ tab, tr, store, navigate }) {
|
|
|
8612
8745
|
// remembered offset — otherwise returning to a tab would always jump to the top.
|
|
8613
8746
|
const reveal = tab.reveal
|
|
8614
8747
|
useEffect(() => {
|
|
8748
|
+
// Read the ref rather than the state: the ref is attached during commit,
|
|
8749
|
+
// so the first paint already lands on the remembered line.
|
|
8615
8750
|
const element = scrollRef.current
|
|
8616
8751
|
if (element === null || tab.status !== 'ready') return
|
|
8617
8752
|
if (typeof reveal === 'number' && reveal > 0 && tab.revealApplied !== reveal) {
|
|
@@ -8621,12 +8756,12 @@ function IdeCodeView({ tab, tr, store, navigate }) {
|
|
|
8621
8756
|
return
|
|
8622
8757
|
}
|
|
8623
8758
|
element.scrollTop = store.getState().scroll[tab.path] ?? 0
|
|
8624
|
-
}, [tab.path, reveal, tab.revealApplied, tab.status, store])
|
|
8759
|
+
}, [tab.path, reveal, tab.revealApplied, tab.status, store, scrollHost])
|
|
8625
8760
|
|
|
8626
8761
|
// Persist the offset while reading, throttled so a scroll does not re-render
|
|
8627
8762
|
// the whole panel on every frame.
|
|
8628
8763
|
useEffect(() => {
|
|
8629
|
-
const element =
|
|
8764
|
+
const element = scrollHost
|
|
8630
8765
|
if (element === null) return undefined
|
|
8631
8766
|
let timer
|
|
8632
8767
|
const onScroll = () => {
|
|
@@ -8641,7 +8776,7 @@ function IdeCodeView({ tab, tr, store, navigate }) {
|
|
|
8641
8776
|
if (timer !== undefined) clearTimeout(timer)
|
|
8642
8777
|
element.removeEventListener('scroll', onScroll)
|
|
8643
8778
|
}
|
|
8644
|
-
}, [tab.path, store])
|
|
8779
|
+
}, [tab.path, store, scrollHost])
|
|
8645
8780
|
|
|
8646
8781
|
// Enrich the declarations on screen (counts) and the file once (blame). Both
|
|
8647
8782
|
// are cached per file version, so scrolling back costs nothing.
|
|
@@ -8705,7 +8840,7 @@ function IdeCodeView({ tab, tr, store, navigate }) {
|
|
|
8705
8840
|
|
|
8706
8841
|
const code = h('div', {
|
|
8707
8842
|
className: 'iw-code',
|
|
8708
|
-
ref:
|
|
8843
|
+
ref: holdScroll,
|
|
8709
8844
|
tabIndex: 0,
|
|
8710
8845
|
onClick: (event) => {
|
|
8711
8846
|
// A licence page parked after an LSP refusal opens on the next gesture.
|
|
@@ -8823,7 +8958,7 @@ function IdeCodeView({ tab, tr, store, navigate }) {
|
|
|
8823
8958
|
])
|
|
8824
8959
|
: null
|
|
8825
8960
|
const markdownView = isMarkdown && tab.status === 'ready' && mdSource !== true
|
|
8826
|
-
? h('div', { key: 'md', className: 'iw-md', ref:
|
|
8961
|
+
? h('div', { key: 'md', className: 'iw-md', ref: holdScroll, tabIndex: 0 }, h('div', {
|
|
8827
8962
|
key: 'body',
|
|
8828
8963
|
className: 'iw-md-body',
|
|
8829
8964
|
}, h(IdeFloatMarkdown, { text: tab.text, tr })))
|
|
@@ -9809,9 +9944,45 @@ function IdeWorkspaceSettingsSection(props) {
|
|
|
9809
9944
|
])
|
|
9810
9945
|
: null,
|
|
9811
9946
|
h('div', { key: 'basic', className: 'iw-settings-group' }, tr('settingsBasic')),
|
|
9947
|
+
h('div', { key: 'font', className: 'iw-settings-item' }, [
|
|
9948
|
+
h('span', { key: 'l', className: 'iw-settings-item-label' }, tr('settingsFont')),
|
|
9949
|
+
h('button', {
|
|
9950
|
+
key: 'b',
|
|
9951
|
+
type: 'button',
|
|
9952
|
+
className: 'iw-gesture-chip',
|
|
9953
|
+
onClick: () => setFontsOpen(!fontsOpen),
|
|
9954
|
+
}, fontsOpen ? tr('settingsCollapse') : `${codeSize} / ${treeSize} px`),
|
|
9955
|
+
]),
|
|
9956
|
+
fontsOpen
|
|
9957
|
+
? h('div', { key: 'fontbody', className: 'iw-settings-body' }, [
|
|
9958
|
+
stepper('code', tr('settingsCodeFont'), codeSize, (next) => store.setCodeFontSize(next)),
|
|
9959
|
+
stepper('tree', tr('settingsTreeFont'), treeSize, (next) => store.setTreeFontSize(next)),
|
|
9960
|
+
])
|
|
9961
|
+
: null,
|
|
9962
|
+
h('div', { key: 'maven', className: 'iw-settings-maven' }, [
|
|
9963
|
+
h('div', { key: 'row', className: 'iw-settings-maven-row' }, [
|
|
9964
|
+
h('span', { key: 'l', className: 'iw-settings-item-label' }, tr('settingsMavenRepo')),
|
|
9965
|
+
h('input', {
|
|
9966
|
+
key: 'i',
|
|
9967
|
+
className: 'iw-settings-input',
|
|
9968
|
+
type: 'text',
|
|
9969
|
+
spellCheck: false,
|
|
9970
|
+
defaultValue: state.mavenRepo,
|
|
9971
|
+
placeholder: tr('settingsMavenRepoAuto'),
|
|
9972
|
+
title: tr('settingsMavenRepoHint'),
|
|
9973
|
+
onKeyDown: (event) => {
|
|
9974
|
+
if (event.key === 'Enter') event.currentTarget.blur()
|
|
9975
|
+
},
|
|
9976
|
+
onBlur: (event) => store.setMavenRepo(event.target.value),
|
|
9977
|
+
}),
|
|
9978
|
+
]),
|
|
9979
|
+
mavenRowHint(tr, state),
|
|
9980
|
+
]),
|
|
9981
|
+
// 悬浮卡自己的那一组:启用、跟随、脱离、详细过程、默认大小,跟其它设置分开。
|
|
9982
|
+
h('div', { key: 'floatgroup', className: 'iw-settings-group' }, tr('settingsFloatGroup')),
|
|
9812
9983
|
// The floating card is on by default; this is where it is turned off.
|
|
9813
9984
|
h('div', { key: 'float', className: 'iw-settings-item' }, [
|
|
9814
|
-
h('span', { key: 'l', className: 'iw-settings-item-label' }, tr('
|
|
9985
|
+
h('span', { key: 'l', className: 'iw-settings-item-label' }, tr('settingsFloatEnable')),
|
|
9815
9986
|
h('button', {
|
|
9816
9987
|
key: 'b',
|
|
9817
9988
|
type: 'button',
|
|
@@ -9820,6 +9991,17 @@ function IdeWorkspaceSettingsSection(props) {
|
|
|
9820
9991
|
onClick: () => store.setFloatEnabled(state.floatEnabled === false),
|
|
9821
9992
|
}, state.floatEnabled !== false ? tr('settingsOn') : tr('settingsOff')),
|
|
9822
9993
|
]),
|
|
9994
|
+
// 默认跟随当前会话;关掉后 DSH 里切会话不带动卡片,只能在卡片里切。
|
|
9995
|
+
h('div', { key: 'floatfollow', className: 'iw-settings-item' }, [
|
|
9996
|
+
h('span', { key: 'l', className: 'iw-settings-item-label' }, tr('settingsFloatFollow')),
|
|
9997
|
+
h('button', {
|
|
9998
|
+
key: 'b',
|
|
9999
|
+
type: 'button',
|
|
10000
|
+
className: `iw-gesture-chip${state.floatFollow !== false ? ' on' : ''}`,
|
|
10001
|
+
title: tr('settingsFloatFollowHint'),
|
|
10002
|
+
onClick: () => store.setFloatFollow(state.floatFollow === false),
|
|
10003
|
+
}, state.floatFollow !== false ? tr('settingsOn') : tr('settingsOff')),
|
|
10004
|
+
]),
|
|
9823
10005
|
// A card that lives on its own stays visible in other panels too.
|
|
9824
10006
|
h('div', { key: 'floatdetach', className: 'iw-settings-item' }, [
|
|
9825
10007
|
h('span', { key: 'l', className: 'iw-settings-item-label' }, tr('settingsFloatDetach')),
|
|
@@ -9865,42 +10047,8 @@ function IdeWorkspaceSettingsSection(props) {
|
|
|
9865
10047
|
(next) => store.setFloatDefaultSize(floatWidth, next)),
|
|
9866
10048
|
])
|
|
9867
10049
|
: null,
|
|
9868
|
-
h('div', { key: 'font', className: 'iw-settings-item' }, [
|
|
9869
|
-
h('span', { key: 'l', className: 'iw-settings-item-label' }, tr('settingsFont')),
|
|
9870
|
-
h('button', {
|
|
9871
|
-
key: 'b',
|
|
9872
|
-
type: 'button',
|
|
9873
|
-
className: 'iw-gesture-chip',
|
|
9874
|
-
onClick: () => setFontsOpen(!fontsOpen),
|
|
9875
|
-
}, fontsOpen ? tr('settingsCollapse') : `${codeSize} / ${treeSize} px`),
|
|
9876
|
-
]),
|
|
9877
|
-
fontsOpen
|
|
9878
|
-
? h('div', { key: 'fontbody', className: 'iw-settings-body' }, [
|
|
9879
|
-
stepper('code', tr('settingsCodeFont'), codeSize, (next) => store.setCodeFontSize(next)),
|
|
9880
|
-
stepper('tree', tr('settingsTreeFont'), treeSize, (next) => store.setTreeFontSize(next)),
|
|
9881
|
-
])
|
|
9882
|
-
: null,
|
|
9883
10050
|
// Dependency sources come from a Maven repository; the Host detects the
|
|
9884
10051
|
// usual places, and this field covers repositories kept anywhere else.
|
|
9885
|
-
h('div', { key: 'maven', className: 'iw-settings-maven' }, [
|
|
9886
|
-
h('div', { key: 'row', className: 'iw-settings-maven-row' }, [
|
|
9887
|
-
h('span', { key: 'l', className: 'iw-settings-item-label' }, tr('settingsMavenRepo')),
|
|
9888
|
-
h('input', {
|
|
9889
|
-
key: 'i',
|
|
9890
|
-
className: 'iw-settings-input',
|
|
9891
|
-
type: 'text',
|
|
9892
|
-
spellCheck: false,
|
|
9893
|
-
defaultValue: state.mavenRepo,
|
|
9894
|
-
placeholder: tr('settingsMavenRepoAuto'),
|
|
9895
|
-
title: tr('settingsMavenRepoHint'),
|
|
9896
|
-
onKeyDown: (event) => {
|
|
9897
|
-
if (event.key === 'Enter') event.currentTarget.blur()
|
|
9898
|
-
},
|
|
9899
|
-
onBlur: (event) => store.setMavenRepo(event.target.value),
|
|
9900
|
-
}),
|
|
9901
|
-
]),
|
|
9902
|
-
mavenRowHint(tr, state),
|
|
9903
|
-
]),
|
|
9904
10052
|
]),
|
|
9905
10053
|
])
|
|
9906
10054
|
}
|
|
@@ -13684,12 +13832,151 @@ function ideDataWindowDecodeXml(text) {
|
|
|
13684
13832
|
.replace(/&/g, '&')
|
|
13685
13833
|
}
|
|
13686
13834
|
|
|
13835
|
+
/** 嵌套 `<include>` 最多展开这么多层,超过就按未解析处理,防止递归失控。 */
|
|
13836
|
+
const IDE_DATA_WINDOW_INCLUDE_DEPTH = 8
|
|
13837
|
+
|
|
13838
|
+
/**
|
|
13839
|
+
* 一个 mapper 文件里所有 `<sql id="...">` 片段,按 id 建索引。
|
|
13840
|
+
*
|
|
13841
|
+
* 片段是 mapper 语句的另一半:语句用 `<include refid="..."/>` 复用筛选条件块。
|
|
13842
|
+
* 早先这里直接把 include 标签删掉,于是 `WHERE <include .../>` 变成光秃秃的
|
|
13843
|
+
* `WHERE`,数据窗口拿到的 SQL 语法都不成立。
|
|
13844
|
+
*/
|
|
13845
|
+
function ideDataWindowSqlFragments(text) {
|
|
13846
|
+
const fragments = {}
|
|
13847
|
+
const pattern = /<sql\b[^>]*\bid\s*=\s*["']([^"']+)["'][^>]*>([\s\S]*?)<\/\s*sql\s*>/gi
|
|
13848
|
+
let match
|
|
13849
|
+
while ((match = pattern.exec(String(text ?? ''))) !== null) {
|
|
13850
|
+
fragments[match[1]] = match[2]
|
|
13851
|
+
}
|
|
13852
|
+
return fragments
|
|
13853
|
+
}
|
|
13854
|
+
|
|
13855
|
+
/** 把 refid 拆成「命名空间 + 片段名」,裸名字没有命名空间。 */
|
|
13856
|
+
function ideDataWindowRefId(refid) {
|
|
13857
|
+
const text = String(refid ?? '').trim()
|
|
13858
|
+
const dot = text.lastIndexOf('.')
|
|
13859
|
+
return dot > 0 ? { namespace: text.slice(0, dot), id: text.slice(dot + 1) } : { namespace: '', id: text }
|
|
13860
|
+
}
|
|
13861
|
+
|
|
13862
|
+
/** 某个命名空间的片段表;一次调用内只查一次,跨文件 include 靠它加载。 */
|
|
13863
|
+
async function ideDataWindowMapperFragments(root, files, namespace) {
|
|
13864
|
+
if (files.has(namespace)) return files.get(namespace)
|
|
13865
|
+
const found = await ideGrepQuery(root, `namespace="${namespace}"`, { extensions: ['xml'] })
|
|
13866
|
+
const paths = found.ok === true ? found.matches.map((match) => String(match.path ?? '')) : []
|
|
13867
|
+
const path = paths.find((entry) => entry.includes('/src/main/resources/')) ?? paths[0] ?? ''
|
|
13868
|
+
const text = path === '' ? '' : await ideDataWindowReadFile(root, path)
|
|
13869
|
+
const fragments = text === '' ? null : ideDataWindowSqlFragments(text)
|
|
13870
|
+
files.set(namespace, fragments)
|
|
13871
|
+
return fragments
|
|
13872
|
+
}
|
|
13873
|
+
|
|
13874
|
+
/** 文本里每个 `<include>` 的位置,成对(带 `<property>` 子标签)和自闭合都认。 */
|
|
13875
|
+
function ideDataWindowIncludes(body) {
|
|
13876
|
+
const text = String(body ?? '')
|
|
13877
|
+
const items = []
|
|
13878
|
+
const open = /<include\b/gi
|
|
13879
|
+
let match
|
|
13880
|
+
while ((match = open.exec(text)) !== null) {
|
|
13881
|
+
const start = match.index
|
|
13882
|
+
const end = text.indexOf('>', start)
|
|
13883
|
+
if (end < 0) break
|
|
13884
|
+
const raw = text.slice(start + '<include'.length, end)
|
|
13885
|
+
const head = raw.replace(/\/\s*$/, '')
|
|
13886
|
+
if (/\/\s*$/.test(raw)) {
|
|
13887
|
+
items.push({ index: start, length: end + 1 - start, attrs: head, body: '' })
|
|
13888
|
+
open.lastIndex = end + 1
|
|
13889
|
+
continue
|
|
13890
|
+
}
|
|
13891
|
+
// 自闭合标签后面紧跟的内容不属于它;只有成对标签才向后找 `</include>`。
|
|
13892
|
+
const closing = /<\/\s*include\s*>/i.exec(text.slice(end + 1))
|
|
13893
|
+
if (closing === null) {
|
|
13894
|
+
items.push({ index: start, length: end + 1 - start, attrs: head, body: '' })
|
|
13895
|
+
open.lastIndex = end + 1
|
|
13896
|
+
continue
|
|
13897
|
+
}
|
|
13898
|
+
const bodyEnd = end + 1 + closing.index
|
|
13899
|
+
items.push({
|
|
13900
|
+
index: start,
|
|
13901
|
+
length: bodyEnd + closing[0].length - start,
|
|
13902
|
+
attrs: head,
|
|
13903
|
+
body: text.slice(end + 1, bodyEnd),
|
|
13904
|
+
})
|
|
13905
|
+
open.lastIndex = bodyEnd + closing[0].length
|
|
13906
|
+
}
|
|
13907
|
+
return items
|
|
13908
|
+
}
|
|
13909
|
+
|
|
13910
|
+
/** `<include>` 里 `<property name=... value=.../>` 提供的占位符值。 */
|
|
13911
|
+
function ideDataWindowIncludeProps(body) {
|
|
13912
|
+
const props = {}
|
|
13913
|
+
for (const match of String(body ?? '').matchAll(/<property\b[^>]*\/?\s*>/gi)) {
|
|
13914
|
+
const attrs = ideDataWindowXmlAttrs(match[0])
|
|
13915
|
+
if (attrs.name !== undefined && attrs.value !== undefined) props[attrs.name] = attrs.value
|
|
13916
|
+
}
|
|
13917
|
+
return props
|
|
13918
|
+
}
|
|
13919
|
+
|
|
13920
|
+
/** 用 include 的 property 值替换片段里的 `${name}`,其余占位符留给参数填充。 */
|
|
13921
|
+
function ideDataWindowApplyProps(sql, props) {
|
|
13922
|
+
const names = Object.keys(props)
|
|
13923
|
+
if (names.length === 0) return String(sql ?? '')
|
|
13924
|
+
return String(sql ?? '').replace(/\$\{\s*([^}]+?)\s*\}/g, (whole, name) => (
|
|
13925
|
+
Object.prototype.hasOwnProperty.call(props, name) ? props[name] : whole
|
|
13926
|
+
))
|
|
13927
|
+
}
|
|
13928
|
+
|
|
13929
|
+
/**
|
|
13930
|
+
* 展开 `<include refid="..."/>`:同文件片段、跨命名空间片段、嵌套 include 与
|
|
13931
|
+
* include 自带的 property 都解析。
|
|
13932
|
+
*
|
|
13933
|
+
* 解析不出来的片段换成一条 SQL 注释而不是静默消失——注释能看出缺了谁,空洞
|
|
13934
|
+
* 只会让数据窗口执行一段语法错误的 SQL。`missing` 收集这些 refid 交给调用方
|
|
13935
|
+
* 写进头部注释。
|
|
13936
|
+
*/
|
|
13937
|
+
async function ideDataWindowExpandIncludes(root, files, namespace, body, seen, missing, depth) {
|
|
13938
|
+
const text = String(body ?? '')
|
|
13939
|
+
const items = ideDataWindowIncludes(text)
|
|
13940
|
+
if (items.length === 0 || depth > IDE_DATA_WINDOW_INCLUDE_DEPTH) return text
|
|
13941
|
+
let result = ''
|
|
13942
|
+
let cursor = 0
|
|
13943
|
+
for (const item of items) {
|
|
13944
|
+
result += text.slice(cursor, item.index)
|
|
13945
|
+
cursor = item.index + item.length
|
|
13946
|
+
const refid = String(ideDataWindowXmlAttrs(item.attrs).refid ?? '').trim()
|
|
13947
|
+
if (refid === '') {
|
|
13948
|
+
result += '/* include without refid */'
|
|
13949
|
+
missing.push('(without refid)')
|
|
13950
|
+
continue
|
|
13951
|
+
}
|
|
13952
|
+
const ref = ideDataWindowRefId(refid)
|
|
13953
|
+
const owner = ref.namespace === '' ? namespace : ref.namespace
|
|
13954
|
+
const key = `${owner}|${ref.id}`
|
|
13955
|
+
if (seen.has(key)) {
|
|
13956
|
+
result += `/* include cycle: ${refid} */`
|
|
13957
|
+
missing.push(refid)
|
|
13958
|
+
continue
|
|
13959
|
+
}
|
|
13960
|
+
const fragments = await ideDataWindowMapperFragments(root, files, owner)
|
|
13961
|
+
const fragment = fragments === null ? undefined : fragments[ref.id]
|
|
13962
|
+
if (fragment === undefined) {
|
|
13963
|
+
result += `/* include not found: ${refid} */`
|
|
13964
|
+
missing.push(refid)
|
|
13965
|
+
continue
|
|
13966
|
+
}
|
|
13967
|
+
const provided = ideDataWindowApplyProps(fragment, ideDataWindowIncludeProps(item.body))
|
|
13968
|
+
result += await ideDataWindowExpandIncludes(root, files, owner, provided, new Set(seen).add(key), missing, depth + 1)
|
|
13969
|
+
}
|
|
13970
|
+
result += text.slice(cursor)
|
|
13971
|
+
return result
|
|
13972
|
+
}
|
|
13973
|
+
|
|
13687
13974
|
/**
|
|
13688
|
-
* The SQL of one mapper statement from its XML file.
|
|
13975
|
+
* The SQL of one mapper statement from its XML file, with `<include>` expanded.
|
|
13689
13976
|
*
|
|
13690
13977
|
* The namespace search is a content grep, so the mapper does not have to sit at a
|
|
13691
|
-
* conventional path.
|
|
13692
|
-
*
|
|
13978
|
+
* conventional path. `missing` lists the refids that could not be resolved, so the
|
|
13979
|
+
* header can say which filter block is absent instead of pretending the SQL is whole.
|
|
13693
13980
|
*/
|
|
13694
13981
|
async function ideDataWindowXmlSql(root, fqcn, symbol) {
|
|
13695
13982
|
const found = await ideGrepQuery(root, `namespace="${fqcn}"`, { extensions: ['xml'] })
|
|
@@ -13707,7 +13994,10 @@ async function ideDataWindowXmlSql(root, fqcn, symbol) {
|
|
|
13707
13994
|
if (match === null) return null
|
|
13708
13995
|
const body = match[2]
|
|
13709
13996
|
if (body.trim() === '') return null
|
|
13710
|
-
|
|
13997
|
+
const files = new Map([[fqcn, ideDataWindowSqlFragments(text)]])
|
|
13998
|
+
const missing = []
|
|
13999
|
+
const expanded = await ideDataWindowExpandIncludes(root, files, fqcn, body, new Set(), missing, 0)
|
|
14000
|
+
return { sql: ideDataWindowDecodeXml(expanded).trim(), missing }
|
|
13711
14001
|
}
|
|
13712
14002
|
|
|
13713
14003
|
/** Parse the attributes of one XML-ish tag, single or double quoted. */
|
|
@@ -13803,6 +14093,8 @@ function ideDataWindowExpandForeach(sql, params) {
|
|
|
13803
14093
|
/** Remove the MyBatis dynamic tags, keeping the SQL they contain. */
|
|
13804
14094
|
function ideDataWindowStripTags(sql) {
|
|
13805
14095
|
let result = String(sql ?? '')
|
|
14096
|
+
// CDATA 里是原样 SQL,先去壳,否则会被下面「未知标签」那条清理连内容一起吞掉。
|
|
14097
|
+
result = result.replace(/<!\[CDATA\[([\s\S]*?)\]\]>/g, '$1')
|
|
13806
14098
|
result = result.replace(/<\s*script\b[^>]*>/gi, '').replace(/<\s*\/\s*script\s*>/gi, '')
|
|
13807
14099
|
result = result.replace(/<choose\b[^>]*>([\s\S]*?)<\/choose>/gi, (whole, body) => {
|
|
13808
14100
|
const when = /<when\b[^>]*>([\s\S]*?)<\/when>/i.exec(body)
|
|
@@ -13833,11 +14125,14 @@ function ideDataWindowStripTags(sql) {
|
|
|
13833
14125
|
result = result.replace(pattern, '$1')
|
|
13834
14126
|
}
|
|
13835
14127
|
result = result.replace(/<bind\b[^>]*\/?\s*>/gi, '')
|
|
13836
|
-
|
|
13837
|
-
//
|
|
13838
|
-
|
|
14128
|
+
// Anything left (foreach and include are already expanded) is an unsupported tag: drop it.
|
|
14129
|
+
// 只认「XML 形状」的标签(字母或 `!` 开头):`a < 5` 解出来是比较运算符,
|
|
14130
|
+
// 按 `<[^>]+>` 删会把 `<` 到后面某个 `>` 之间的真实 SQL 一起吞掉。
|
|
14131
|
+
result = result.replace(/<\/?[A-Za-z!][^>]*>/g, '')
|
|
13839
14132
|
// `<where>` may have wrapped its leading AND/OR inside a stripped `<if>`.
|
|
13840
14133
|
result = result.replace(/\bWHERE\s+(AND|OR)\b/gi, 'WHERE')
|
|
14134
|
+
// 条件被动态标签或解析失败的 include 吃光后只剩一个 WHERE,留着就是语法错误。
|
|
14135
|
+
result = result.replace(/\bWHERE\b(?=(?:\s*\/\*[\s\S]*?\*\/)*\s*(?:ORDER\s+BY|GROUP\s+BY|HAVING|LIMIT|UNION|FOR\s+UPDATE|\)|;|$))/gi, '')
|
|
13841
14136
|
return result
|
|
13842
14137
|
}
|
|
13843
14138
|
|
|
@@ -13867,6 +14162,9 @@ function ideDataWindowExecutableSql(raw, params) {
|
|
|
13867
14162
|
.filter((line) => line !== '')
|
|
13868
14163
|
.join('\n')
|
|
13869
14164
|
.replace(/\b(IN|in)\s*\(/g, 'IN (')
|
|
14165
|
+
// `WHERE` 独占一行时,看上去和「条件被吃掉了」的空 WHERE 一模一样;把紧跟着
|
|
14166
|
+
// 它的第一个条件接上去,一眼就能看出条件在不在。`SET` 同理。
|
|
14167
|
+
.replace(/\b(WHERE|SET)[ \t]*\n[ \t]*(?=\S)/gi, (whole, keyword) => `${keyword.toUpperCase()} `)
|
|
13870
14168
|
.trim()
|
|
13871
14169
|
}
|
|
13872
14170
|
|
|
@@ -13892,15 +14190,22 @@ async function ideDataWindowOpenMapper(store, tr, root, path, symbol, line) {
|
|
|
13892
14190
|
const fqcn = packageMatch === null ? typeName : `${packageMatch[1]}.${typeName}`
|
|
13893
14191
|
const methodOffset = ideDataWindowMethodOffset(text, name, line)
|
|
13894
14192
|
const params = ideDataWindowMethodParams(text, methodOffset)
|
|
13895
|
-
const
|
|
13896
|
-
|
|
13897
|
-
const
|
|
14193
|
+
const annotation = ideDataWindowAnnotationSql(text, name, line)
|
|
14194
|
+
const statement = annotation === '' ? await ideDataWindowXmlSql(root, fqcn, name) : { sql: annotation, missing: [] }
|
|
14195
|
+
const raw = statement === null ? '' : String(statement.sql ?? '')
|
|
14196
|
+
const sql = raw === '' ? '' : ideDataWindowExecutableSql(raw, params)
|
|
13898
14197
|
if (sql === '') {
|
|
13899
14198
|
store.setNotice(tr('dataWindowNoSql'))
|
|
13900
14199
|
return
|
|
13901
14200
|
}
|
|
13902
14201
|
const defaults = ideDataWindowDefaultSummary(params)
|
|
13903
|
-
|
|
14202
|
+
// 解析不出来的 include 必须说出来:否则用户以为拿到了完整条件,实际少了过滤块。
|
|
14203
|
+
const unresolved = [...new Set(statement?.missing ?? [])]
|
|
14204
|
+
const notes = [
|
|
14205
|
+
defaults === '' ? '' : `-- defaults: ${defaults}`,
|
|
14206
|
+
unresolved.length === 0 ? '' : `-- unresolved include: ${unresolved.join(', ')}`,
|
|
14207
|
+
].filter((line) => line !== '').join('\n')
|
|
14208
|
+
const header = notes === '' ? '' : `${notes}\n`
|
|
13904
14209
|
store.setNotice(tr('dataWindowOpening'))
|
|
13905
14210
|
const ack = await ideDataWindowRequest({
|
|
13906
14211
|
action: 'openSql',
|
|
@@ -13931,6 +14236,8 @@ async function ideDataWindowOpenMapper(store, tr, root, path, symbol, line) {
|
|
|
13931
14236
|
// everything but the last few rows off a long turn; the card scrolls, so the
|
|
13932
14237
|
// whole tail of the log is worth keeping.
|
|
13933
14238
|
const IDE_FLOAT_MESSAGES = 200
|
|
14239
|
+
/** 表头标题最多显示多少个字(超出加省略号)。 */
|
|
14240
|
+
const IDE_FLOAT_TITLE_CHARS = 20
|
|
13934
14241
|
/** Longest text a folded row shows once opened; longer payloads are clipped. */
|
|
13935
14242
|
const IDE_FLOAT_DETAIL_MAX = 6000
|
|
13936
14243
|
/** How long after `compositionend` an Enter still counts as "confirm the IME". */
|
|
@@ -14070,6 +14377,59 @@ function ideFloatCallsDetail(calls) {
|
|
|
14070
14377
|
}).join('\n\n')
|
|
14071
14378
|
}
|
|
14072
14379
|
|
|
14380
|
+
/** 还没决定的审批数量:折叠成球时靠它在球上点一个告警点。 */
|
|
14381
|
+
function ideFloatPendingApprovals(rows) {
|
|
14382
|
+
return Array.isArray(rows) ? rows.filter((row) => row?.role === 'approval' && row.pending === true).length : 0
|
|
14383
|
+
}
|
|
14384
|
+
|
|
14385
|
+
/**
|
|
14386
|
+
* 卡片当前展示哪个会话。
|
|
14387
|
+
*
|
|
14388
|
+
* 默认跟随面板(`state.sessionId`);设置里关掉「跟随当前会话」后,卡片只认自己
|
|
14389
|
+
* 钉住的那个 `state.floatSessionId`,DSH 里怎么切都不动。
|
|
14390
|
+
*/
|
|
14391
|
+
function ideFloatTargetSession(state) {
|
|
14392
|
+
const panel = typeof state?.sessionId === 'string' ? state.sessionId : ''
|
|
14393
|
+
if (state?.floatFollow !== false) return panel
|
|
14394
|
+
const pinned = typeof state?.floatSessionId === 'string' ? state.floatSessionId : ''
|
|
14395
|
+
return pinned !== '' ? pinned : panel
|
|
14396
|
+
}
|
|
14397
|
+
|
|
14398
|
+
/** 表头标题最多 `limit` 个字,超出用省略号——再长就分不清是哪个会话了。 */
|
|
14399
|
+
function ideFloatTitleText(text, limit = IDE_FLOAT_TITLE_CHARS) {
|
|
14400
|
+
const value = String(text ?? '').trim()
|
|
14401
|
+
const chars = [...value]
|
|
14402
|
+
if (chars.length <= limit) return value
|
|
14403
|
+
return `${chars.slice(0, limit).join('')}…`
|
|
14404
|
+
}
|
|
14405
|
+
|
|
14406
|
+
/**
|
|
14407
|
+
* 一个工作区固定一个色相:同一个目录永远是同一个颜色,不同工作区尽量分开。
|
|
14408
|
+
* 只给表头标题上色,且和正文主色混合,浅色/深色主题下都保持可读。
|
|
14409
|
+
*/
|
|
14410
|
+
function ideFloatWorkspaceHue(path) {
|
|
14411
|
+
const text = String(path ?? '').trim()
|
|
14412
|
+
if (text === '') return 214
|
|
14413
|
+
let hash = 0
|
|
14414
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
14415
|
+
hash = (hash * 33 + text.charCodeAt(index)) % 360
|
|
14416
|
+
}
|
|
14417
|
+
return hash
|
|
14418
|
+
}
|
|
14419
|
+
|
|
14420
|
+
/** 审批结果的一句话说法;后续版本出现新结果时原样显示,不吞掉。 */
|
|
14421
|
+
function ideFloatApprovalOutcome(outcome, tr) {
|
|
14422
|
+
const value = String(outcome ?? '')
|
|
14423
|
+
const labels = {
|
|
14424
|
+
'allowed-once': 'floatApprovalAllowed',
|
|
14425
|
+
rejected: 'floatApprovalRejected',
|
|
14426
|
+
cancelled: 'floatApprovalCancelled',
|
|
14427
|
+
unavailable: 'floatApprovalUnavailable',
|
|
14428
|
+
}
|
|
14429
|
+
const key = labels[value]
|
|
14430
|
+
return key === undefined ? `${tr('floatApprovalSettled')} · ${value}`.trim() : tr(key)
|
|
14431
|
+
}
|
|
14432
|
+
|
|
14073
14433
|
function ideFloatRow(row, tr, io) {
|
|
14074
14434
|
const { setViewing, store, pictures } = io
|
|
14075
14435
|
// Compact (the default) is about WHICH rows show, not about cutting the text:
|
|
@@ -14128,6 +14488,35 @@ function ideFloatRow(row, tr, io) {
|
|
|
14128
14488
|
// Questions cannot be answered here: DSH only accepts the answer in the
|
|
14129
14489
|
// Conversation, so the card's button navigates there instead.
|
|
14130
14490
|
const goToChat = typeof io.goToChat === 'function' ? io.goToChat : () => {}
|
|
14491
|
+
// 审批也一样:`approval/request` 是 waterfall 事件,唯一的作答入口是 DSH 自己的
|
|
14492
|
+
// 审批插件(它把审批卡挂在对话的输入区)。插件再抢这份事件会把对话那张卡顶掉,
|
|
14493
|
+
// 一旦卡片被收起,审批就彻底没人能答。所以这里只展示 + 把人送回对话。
|
|
14494
|
+
if (row.role === 'approval') {
|
|
14495
|
+
const settled = row.pending !== true
|
|
14496
|
+
return h('div', { key: row.key, className: 'iw-float-row' }, [
|
|
14497
|
+
h('div', { key: 'card', className: `iw-float-ask iw-float-approval${settled ? ' iw-float-approval-done' : ''}` }, [
|
|
14498
|
+
h('div', { key: 'head', className: 'iw-float-ask-head' }, [
|
|
14499
|
+
h('div', { key: 'e', className: 'iw-float-ask-eyebrow' },
|
|
14500
|
+
settled ? tr('floatApprovalSettled') : tr('floatApprovalPending')),
|
|
14501
|
+
h('div', { key: 't', className: 'iw-float-ask-title' },
|
|
14502
|
+
row.tool === '' ? tr('floatApprovalTitle') : `${tr('floatApprovalTool')} · ${row.tool}`),
|
|
14503
|
+
]),
|
|
14504
|
+
row.reason === '' ? null : h('div', { key: 'r', className: 'iw-float-approval-reason' }, row.reason),
|
|
14505
|
+
h('div', { key: 'foot', className: 'iw-float-ask-foot' }, [
|
|
14506
|
+
h('span', { key: 'hint', className: 'iw-float-ask-hint' },
|
|
14507
|
+
settled ? ideFloatApprovalOutcome(row.outcome, tr) : tr('floatApprovalHint')),
|
|
14508
|
+
settled
|
|
14509
|
+
? null
|
|
14510
|
+
: h('button', {
|
|
14511
|
+
key: 'go',
|
|
14512
|
+
type: 'button',
|
|
14513
|
+
className: 'iw-btn primary iw-float-ask-go',
|
|
14514
|
+
onClick: () => { goToChat() },
|
|
14515
|
+
}, tr('floatApprovalGo')),
|
|
14516
|
+
]),
|
|
14517
|
+
]),
|
|
14518
|
+
])
|
|
14519
|
+
}
|
|
14131
14520
|
if (row.role === 'files') {
|
|
14132
14521
|
return h('div', { key: row.key, className: 'iw-float-row iw-float-files' }, [
|
|
14133
14522
|
h('span', { key: 'who', className: 'iw-float-who' }, tr('floatFiles')),
|
|
@@ -14393,10 +14782,6 @@ function ideFloatNotice(event) {
|
|
|
14393
14782
|
labelKey: 'floatNoticeRetry',
|
|
14394
14783
|
text: ideFloatDetail(`第 ${data.retry ?? '?'} / ${data.maxRetries ?? '?'} 次\n${data.failure?.code ?? ''} ${data.failure?.message ?? ''}`.trim()),
|
|
14395
14784
|
}
|
|
14396
|
-
case 'approval/asked':
|
|
14397
|
-
return { labelKey: 'floatNoticeApproval', text: ideFloatDetail(`${data.toolName ?? ''}\n${data.reason ?? ''}`.trim()) }
|
|
14398
|
-
case 'approval/decided':
|
|
14399
|
-
return { labelKey: 'floatNoticeApprovalResult', text: String(data.outcome ?? '') }
|
|
14400
14785
|
case 'approval/policy':
|
|
14401
14786
|
return { labelKey: 'floatNoticeApprovalPolicy', text: String(data.policy ?? '') }
|
|
14402
14787
|
case 'workspace/changes':
|
|
@@ -14549,6 +14934,33 @@ function ideFloatTranscript(entries, limit = IDE_FLOAT_MESSAGES) {
|
|
|
14549
14934
|
}
|
|
14550
14935
|
continue
|
|
14551
14936
|
}
|
|
14937
|
+
// 审批请求自成一卡:它发生在某个工具调用「等批」期间,先把这一批收口,
|
|
14938
|
+
// 免得「等待审批」跑到那条命令上面去。
|
|
14939
|
+
if (event.type === 'approval/asked') {
|
|
14940
|
+
flushBatch()
|
|
14941
|
+
rows.push({
|
|
14942
|
+
key: `ap${event.seq}`,
|
|
14943
|
+
role: 'approval',
|
|
14944
|
+
text: '',
|
|
14945
|
+
images: [],
|
|
14946
|
+
tool: String(event.data?.toolName ?? ''),
|
|
14947
|
+
reason: String(event.data?.reason ?? ''),
|
|
14948
|
+
approvalId: String(event.data?.id ?? ''),
|
|
14949
|
+
pending: true,
|
|
14950
|
+
time: Number(event.time ?? 0),
|
|
14951
|
+
seq: event.seq,
|
|
14952
|
+
})
|
|
14953
|
+
continue
|
|
14954
|
+
}
|
|
14955
|
+
if (event.type === 'approval/decided') {
|
|
14956
|
+
const approvalId = String(event.data?.id ?? '')
|
|
14957
|
+
const settled = rows.find((row) => row.role === 'approval' && row.approvalId === approvalId)
|
|
14958
|
+
if (settled !== undefined) {
|
|
14959
|
+
settled.pending = false
|
|
14960
|
+
settled.outcome = String(event.data?.outcome ?? '')
|
|
14961
|
+
}
|
|
14962
|
+
continue
|
|
14963
|
+
}
|
|
14552
14964
|
// The conversation's own question card: `ask_user_question` is a tool call,
|
|
14553
14965
|
// and its answer comes back as the tool result with matching ids.
|
|
14554
14966
|
if (event.type === 'tool/call' && event.data?.name === 'ask_user_question') {
|
|
@@ -14607,28 +15019,57 @@ function ideFloatTranscript(entries, limit = IDE_FLOAT_MESSAGES) {
|
|
|
14607
15019
|
* scrolls away, once where it stays. Finished batches stay in the transcript,
|
|
14608
15020
|
* folded, because they are part of the record.
|
|
14609
15021
|
*/
|
|
14610
|
-
function ideFloatVisibleRows(rows, running, detail) {
|
|
15022
|
+
function ideFloatVisibleRows(rows, running, detail, history) {
|
|
14611
15023
|
if (!Array.isArray(rows)) return []
|
|
15024
|
+
// 还没作答的问题卡片、还没决定的审批不管在哪个位置都要露出来,否则用户永远
|
|
15025
|
+
// 看不到「要你选 / 要你批」。
|
|
15026
|
+
const pendingQuestion = (row) => row?.role === 'question' && !(Array.isArray(row?.answers) && row.answers.length > 0)
|
|
15027
|
+
const pendingApproval = (row) => row?.role === 'approval' && row.pending === true
|
|
15028
|
+
// 用户主动往回翻(滚到顶):把整个已加载窗口里的对话铺开,否则补进来的历史会
|
|
15029
|
+
// 被「只画本轮」过滤掉,看起来像什么都没加载。过程行(工具批次/思考/上下文/
|
|
15030
|
+
// notice)仍然不画——那是对话的事。
|
|
15031
|
+
if (detail !== true && history === true) {
|
|
15032
|
+
return rows.filter((row) => row?.role !== 'step' && row?.role !== 'reasoning' && row?.role !== 'context' && row?.role !== 'notice')
|
|
15033
|
+
}
|
|
14612
15034
|
if (detail !== true) {
|
|
14613
|
-
// The card is a status board
|
|
14614
|
-
//
|
|
14615
|
-
//
|
|
14616
|
-
|
|
14617
|
-
|
|
15035
|
+
// The card is a status board for the current turn: what you last said, then
|
|
15036
|
+
// every line the agent printed after it. An agent narrates between Tool calls
|
|
15037
|
+
// ("改完了,再补个用例"), and the conversation prints each narration as its own
|
|
15038
|
+
// message — keeping only the newest one dropped everything said before it,
|
|
15039
|
+
// which is exactly what the card used to do.
|
|
15040
|
+
let lastUser = -1
|
|
15041
|
+
for (let index = rows.length - 1; index >= 0; index -= 1) {
|
|
15042
|
+
if (rows[index]?.role === 'user') {
|
|
15043
|
+
lastUser = index
|
|
15044
|
+
break
|
|
15045
|
+
}
|
|
15046
|
+
}
|
|
15047
|
+
if (lastUser < 0) {
|
|
15048
|
+
// 没有 user 行可以锚定(历史被截断或会话是种子消息):退回「最新一条输出」。
|
|
15049
|
+
const keep = new Set()
|
|
14618
15050
|
for (let index = rows.length - 1; index >= 0; index -= 1) {
|
|
14619
|
-
if (
|
|
14620
|
-
keep.
|
|
14621
|
-
|
|
15051
|
+
if (rows[index]?.role === 'assistant') {
|
|
15052
|
+
keep.add(index)
|
|
15053
|
+
break
|
|
15054
|
+
}
|
|
15055
|
+
}
|
|
15056
|
+
for (let index = rows.length - 1; index >= 0; index -= 1) {
|
|
15057
|
+
if (rows[index]?.role === 'files') {
|
|
15058
|
+
keep.add(index)
|
|
15059
|
+
break
|
|
14622
15060
|
}
|
|
14623
15061
|
}
|
|
15062
|
+
rows.forEach((row, index) => {
|
|
15063
|
+
if (pendingQuestion(row) || pendingApproval(row)) keep.add(index)
|
|
15064
|
+
})
|
|
15065
|
+
return [...keep].sort((left, right) => left - right).map((index) => rows[index])
|
|
14624
15066
|
}
|
|
14625
|
-
|
|
14626
|
-
lastWhere((row) => row?.role === 'assistant')
|
|
14627
|
-
lastWhere((row) => row?.role === 'files')
|
|
15067
|
+
const keep = new Set([lastUser])
|
|
14628
15068
|
rows.forEach((row, index) => {
|
|
14629
|
-
if (row?.role === '
|
|
15069
|
+
if (index > lastUser && (row?.role === 'assistant' || row?.role === 'files' || row?.role === 'approval' || pendingQuestion(row))) keep.add(index)
|
|
15070
|
+
else if (index < lastUser && (pendingQuestion(row) || pendingApproval(row))) keep.add(index)
|
|
14630
15071
|
})
|
|
14631
|
-
return [...
|
|
15072
|
+
return [...keep].sort((left, right) => left - right).map((index) => rows[index])
|
|
14632
15073
|
}
|
|
14633
15074
|
// Detail mode: the whole record. The batch that is still running is pinned
|
|
14634
15075
|
// under the clock, so it leaves the transcript to avoid showing it twice.
|
|
@@ -15278,6 +15719,28 @@ function ideFloatSafeUrl(url, image = false) {
|
|
|
15278
15719
|
return ''
|
|
15279
15720
|
}
|
|
15280
15721
|
|
|
15722
|
+
/**
|
|
15723
|
+
* 本地绝对路径的图片走 DSH 自己的 `api/file` 路由——对话里就是这么显示的。
|
|
15724
|
+
*
|
|
15725
|
+
* 直接把 `/tmp/x.jpg` 塞进 `<img src>` 会变成「相对当前页面」的地址,浏览器只会
|
|
15726
|
+
* 拿到 404 和一张裂图标(alt 文字旁边那个 ⧉)。`https?` 与 `dsh-app:` 两种部署
|
|
15727
|
+
* 下都能用同一个相对路由,和 DSH 客户端自己的 `fileMediaUrl` 规则一致。
|
|
15728
|
+
*/
|
|
15729
|
+
function ideFloatFileUrl(path) {
|
|
15730
|
+
const text = String(path ?? '').trim()
|
|
15731
|
+
if (text === '') return ''
|
|
15732
|
+
// 只认绝对路径:Windows 的 `C:\x`、UNC 的 `\\host\share`、POSIX 的 `/tmp/x`。
|
|
15733
|
+
if (!/^(?:\/|[A-Za-z]:[\\/]|\\\\)/.test(text)) return ''
|
|
15734
|
+
const base = typeof document !== 'undefined' && typeof document.baseURI === 'string' ? document.baseURI : ''
|
|
15735
|
+
if (base === '') return ''
|
|
15736
|
+
if (!/^https?:/i.test(base) && !base.startsWith('dsh-app://')) return ''
|
|
15737
|
+
try {
|
|
15738
|
+
return new URL(`api/file?path=${encodeURIComponent(text)}`, base).href
|
|
15739
|
+
} catch (error) {
|
|
15740
|
+
return ''
|
|
15741
|
+
}
|
|
15742
|
+
}
|
|
15743
|
+
|
|
15281
15744
|
/** One inline markdown run: code, bold, emphasis, strike, links, images, autolinks. */
|
|
15282
15745
|
function ideFloatInline(text, prefix = '') {
|
|
15283
15746
|
const nodes = []
|
|
@@ -15315,12 +15778,14 @@ function ideFloatInline(text, prefix = '') {
|
|
|
15315
15778
|
nodes.push(h('code', { key, className: 'iw-float-md-code' }, token.slice(ticks, -ticks).replace(/^ | $/g, '')))
|
|
15316
15779
|
} else if (token.startsWith('![')) {
|
|
15317
15780
|
const image = /^!\[([^\]]*)\]\(([^)]+)\)$/.exec(token)
|
|
15318
|
-
const
|
|
15781
|
+
const localImage = image === null ? '' : ideFloatFileUrl(image[2])
|
|
15782
|
+
const src = localImage !== '' ? localImage : image === null ? '' : ideFloatSafeUrl(image[2], true)
|
|
15319
15783
|
if (src === '') pushText(image === null ? token : image[1])
|
|
15320
15784
|
else nodes.push(h('img', { key, className: 'iw-float-md-img', src, alt: image[1] }))
|
|
15321
15785
|
} else if (token.startsWith('[')) {
|
|
15322
15786
|
const link = /^\[([^\]]+)\]\(([^)]+)\)$/.exec(token)
|
|
15323
|
-
const
|
|
15787
|
+
const localLink = link === null ? '' : ideFloatFileUrl(link[2])
|
|
15788
|
+
const href = localLink !== '' ? localLink : link === null ? '' : ideFloatSafeUrl(link[2])
|
|
15324
15789
|
if (href === '') pushText(link === null ? token : link[1])
|
|
15325
15790
|
else nodes.push(h('a', { key, className: 'iw-float-md-link', href, target: '_blank', rel: 'noreferrer' }, link[1]))
|
|
15326
15791
|
} else if (token.startsWith('<http')) {
|
|
@@ -15612,6 +16077,15 @@ function IdeFloatingAsk({ store, sessions, modelDirectories, translate, openSess
|
|
|
15612
16077
|
const bodyRef = useRef(null)
|
|
15613
16078
|
// Whether the transcript should follow the newest line.
|
|
15614
16079
|
const stickRef = useRef(true)
|
|
16080
|
+
// 滚到顶时往回补历史:记录「正在加载」与补完要还原的滚动高度。
|
|
16081
|
+
const olderRef = useRef({ busy: false, pending: false, height: 0 })
|
|
16082
|
+
// 「+ 新建会话」之后,不跟随时把卡片收养到新会话上(只认卡片自己发起的创建)。
|
|
16083
|
+
const pinnedAdoptRef = useRef(false)
|
|
16084
|
+
const [olderBusy, setOlderBusy] = useState(false)
|
|
16085
|
+
// 卡片默认只画最后 200 行;用户主动往回翻时按步长放宽,别让补进来的行被裁掉。
|
|
16086
|
+
const [rowLimit, setRowLimit] = useState(IDE_FLOAT_MESSAGES)
|
|
16087
|
+
// 滚到顶 = 用户想看历史:整段对话铺开,直到发消息或切会话才回到「本轮状态板」。
|
|
16088
|
+
const [historyMode, setHistoryMode] = useState(false)
|
|
15615
16089
|
const [entries, setEntries] = useState([])
|
|
15616
16090
|
const [draft, setDraft] = useState('')
|
|
15617
16091
|
const [sending, setSending] = useState(false)
|
|
@@ -15710,6 +16184,72 @@ function IdeFloatingAsk({ store, sessions, modelDirectories, translate, openSess
|
|
|
15710
16184
|
stickRef.current = true
|
|
15711
16185
|
}, [state.floatOpen])
|
|
15712
16186
|
|
|
16187
|
+
// 不跟随时,第一次进入就把面板当前会话钉住;之后 DSH 里怎么切都不动。
|
|
16188
|
+
useEffect(() => {
|
|
16189
|
+
if (state.floatFollow !== false) return
|
|
16190
|
+
if (state.floatSessionId !== undefined && state.floatSessionId !== null) return
|
|
16191
|
+
if (typeof state.sessionId !== 'string' || state.sessionId === '') return
|
|
16192
|
+
store.setFloatSessionId(state.sessionId)
|
|
16193
|
+
}, [state.floatFollow, state.floatSessionId, state.sessionId, store])
|
|
16194
|
+
|
|
16195
|
+
// 卡片里点「+ 新建会话」:新会话属于卡片自己,不跟随时也要跟过去。
|
|
16196
|
+
useEffect(() => {
|
|
16197
|
+
if (pinnedAdoptRef.current !== true) return
|
|
16198
|
+
pinnedAdoptRef.current = false
|
|
16199
|
+
if (state.floatFollow !== false) return
|
|
16200
|
+
if (typeof state.sessionId !== 'string' || state.sessionId === '') return
|
|
16201
|
+
store.setFloatSessionId(state.sessionId)
|
|
16202
|
+
}, [state.sessionId, state.floatFollow, store])
|
|
16203
|
+
|
|
16204
|
+
// 滚到「更早」补一页:DSH 的会话窗口是分页的(首屏 ≥50 条消息、最多 500 条),
|
|
16205
|
+
// 卡片自己不请求就只能看到那一屏。补完把滚动位置往下推同样高度,视觉上停在原处。
|
|
16206
|
+
const loadOlderRows = async () => {
|
|
16207
|
+
const session = binding?.session
|
|
16208
|
+
const source = binding?.eventSource
|
|
16209
|
+
if (olderRef.current.busy) return
|
|
16210
|
+
const element = bodyRef.current
|
|
16211
|
+
const taller = () => (element === null || element === undefined ? 0 : element.scrollHeight)
|
|
16212
|
+
const hasMore = source?.getSnapshot()?.hasMore === true
|
|
16213
|
+
const canLoad = session !== undefined && session !== null && typeof session.loadOlder === 'function'
|
|
16214
|
+
// 已经到会话开头(或这条会话没有分页):不用请求,只把历史展开,
|
|
16215
|
+
// 让已经拿到的更早内容显示出来。
|
|
16216
|
+
if (!hasMore || !canLoad) {
|
|
16217
|
+
if (historyMode) return
|
|
16218
|
+
olderRef.current.height = taller()
|
|
16219
|
+
setHistoryMode(true)
|
|
16220
|
+
olderRef.current.pending = true
|
|
16221
|
+
return
|
|
16222
|
+
}
|
|
16223
|
+
olderRef.current.busy = true
|
|
16224
|
+
olderRef.current.height = taller()
|
|
16225
|
+
setOlderBusy(true)
|
|
16226
|
+
if (!historyMode) setHistoryMode(true)
|
|
16227
|
+
try {
|
|
16228
|
+
await session.loadOlder()
|
|
16229
|
+
// 窗口补进来了,但卡片只画最后 N 行;放宽上限,让补进来的行真的出现。
|
|
16230
|
+
setRowLimit((current) => Math.min(current + IDE_FLOAT_MESSAGES, IDE_FLOAT_MESSAGES * 10))
|
|
16231
|
+
olderRef.current.pending = true
|
|
16232
|
+
} catch (error) {
|
|
16233
|
+
ideLogRecord('warn', 'float', 'load older failed', error?.message ?? String(error))
|
|
16234
|
+
} finally {
|
|
16235
|
+
olderRef.current.busy = false
|
|
16236
|
+
setOlderBusy(false)
|
|
16237
|
+
}
|
|
16238
|
+
}
|
|
16239
|
+
|
|
16240
|
+
// 新行渲染完再量高度:把滚动条往下推「长出来的那一段」,视线不跳。
|
|
16241
|
+
useLayoutEffect(() => {
|
|
16242
|
+
const older = olderRef.current
|
|
16243
|
+
if (older.pending !== true) return
|
|
16244
|
+
const element = bodyRef.current
|
|
16245
|
+
if (element === null || element === undefined) return
|
|
16246
|
+
const grown = element.scrollHeight - older.height
|
|
16247
|
+
// 浏览器若已按 scroll anchoring 挪过位置,就保留它的结果,别把高度算两遍。
|
|
16248
|
+
if (grown > 0) element.scrollTop = Math.max(element.scrollTop, grown)
|
|
16249
|
+
older.height = element.scrollHeight
|
|
16250
|
+
older.pending = false
|
|
16251
|
+
})
|
|
16252
|
+
|
|
15713
16253
|
// The transcript shows the newest line: on mount, when it comes back into
|
|
15714
16254
|
// view, and after every new message. `stickRef` follows the user, so reading
|
|
15715
16255
|
// older content is not yanked back; sending forces the jump.
|
|
@@ -15726,7 +16266,8 @@ function IdeFloatingAsk({ store, sessions, modelDirectories, translate, openSess
|
|
|
15726
16266
|
}
|
|
15727
16267
|
})
|
|
15728
16268
|
|
|
15729
|
-
const sessionId = state
|
|
16269
|
+
const sessionId = ideFloatTargetSession(state)
|
|
16270
|
+
const follow = state.floatFollow !== false
|
|
15730
16271
|
const open = state.floatOpen === true && state.floatEnabled !== false && state.floatClosed !== true
|
|
15731
16272
|
const collapsed = state.floatCollapsed === true
|
|
15732
16273
|
|
|
@@ -15758,6 +16299,9 @@ function IdeFloatingAsk({ store, sessions, modelDirectories, translate, openSess
|
|
|
15758
16299
|
useEffect(() => {
|
|
15759
16300
|
if (binding === null) {
|
|
15760
16301
|
setEntries([])
|
|
16302
|
+
setRowLimit((current) => (current === IDE_FLOAT_MESSAGES ? current : IDE_FLOAT_MESSAGES))
|
|
16303
|
+
olderRef.current = { busy: false, pending: false, height: 0 }
|
|
16304
|
+
setHistoryMode(false)
|
|
15761
16305
|
return undefined
|
|
15762
16306
|
}
|
|
15763
16307
|
const source = binding.eventSource
|
|
@@ -15765,11 +16309,11 @@ function IdeFloatingAsk({ store, sessions, modelDirectories, translate, openSess
|
|
|
15765
16309
|
const raw = source.getSnapshot()?.entries
|
|
15766
16310
|
// The transcript drops Tool calls; the progress line needs them.
|
|
15767
16311
|
rawEntries.current = Array.isArray(raw) ? raw : []
|
|
15768
|
-
setEntries(ideFloatTranscript(raw))
|
|
16312
|
+
setEntries(ideFloatTranscript(raw, rowLimit))
|
|
15769
16313
|
}
|
|
15770
16314
|
read()
|
|
15771
16315
|
return source.subscribe(read)
|
|
15772
|
-
}, [binding])
|
|
16316
|
+
}, [binding, rowLimit])
|
|
15773
16317
|
|
|
15774
16318
|
// The session directory, for the switcher in the header. The Workspace snapshot
|
|
15775
16319
|
// carries the archive set, which is what keeps archived conversations out.
|
|
@@ -15911,9 +16455,11 @@ function IdeFloatingAsk({ store, sessions, modelDirectories, translate, openSess
|
|
|
15911
16455
|
className: 'iw-float-menu-item iw-float-menu-new',
|
|
15912
16456
|
onClick: () => {
|
|
15913
16457
|
setMenu('')
|
|
16458
|
+
pinnedAdoptRef.current = true
|
|
15914
16459
|
if (typeof startSession === 'function') startSession()
|
|
15915
16460
|
},
|
|
15916
16461
|
}, `+ ${tr('floatNewSession')}`),
|
|
16462
|
+
follow ? null : h('div', { key: 'pin', className: 'iw-float-menu-head' }, tr('floatPinnedHint')),
|
|
15917
16463
|
sessionRows.length === 0
|
|
15918
16464
|
? h('div', { key: 'empty', className: 'iw-float-menu-empty' }, tr('floatSessionEmpty'))
|
|
15919
16465
|
: sessionGroups.map((group) => h('div', {
|
|
@@ -15931,7 +16477,9 @@ function IdeFloatingAsk({ store, sessions, modelDirectories, translate, openSess
|
|
|
15931
16477
|
title: row.cwd === '' ? row.title : row.cwd,
|
|
15932
16478
|
onClick: () => {
|
|
15933
16479
|
setMenu('')
|
|
15934
|
-
|
|
16480
|
+
// 不跟随:只换卡片自己的会话,不动 DSH 面板;跟随:照旧打开那个会话。
|
|
16481
|
+
if (!follow) store.setFloatSessionId(row.sessionId)
|
|
16482
|
+
else if (typeof openSession === 'function') openSession(row.sessionId)
|
|
15935
16483
|
},
|
|
15936
16484
|
}, [
|
|
15937
16485
|
h('span', { key: 't', className: 'iw-float-menu-label' }, row.title),
|
|
@@ -16320,7 +16868,7 @@ function IdeFloatingAsk({ store, sessions, modelDirectories, translate, openSess
|
|
|
16320
16868
|
|
|
16321
16869
|
// The transcript holds the conversation; the Tool log is live status pinned to
|
|
16322
16870
|
// the card's footer, so it never scrolls away with the history.
|
|
16323
|
-
const visibleEntries = ideFloatVisibleRows(entries, running, state.floatEvents === true)
|
|
16871
|
+
const visibleEntries = ideFloatVisibleRows(entries, running, state.floatEvents === true, historyMode)
|
|
16324
16872
|
|
|
16325
16873
|
// The live line reads the RAW entries: `entries` is already folded into rows,
|
|
16326
16874
|
// and the streamed deltas live only in the window (they are not rows).
|
|
@@ -16565,6 +17113,8 @@ function IdeFloatingAsk({ store, sessions, modelDirectories, translate, openSess
|
|
|
16565
17113
|
const text = draft.trim()
|
|
16566
17114
|
const parts = ideFloatPromptParts(text, refs, images)
|
|
16567
17115
|
if (parts.length === 0 || binding === null || sending) return
|
|
17116
|
+
// 发新消息 = 回到实时状态板,不再停在历史视图里。
|
|
17117
|
+
setHistoryMode(false)
|
|
16568
17118
|
// Sending means the user wants to see their own message, wherever they were.
|
|
16569
17119
|
stickRef.current = true
|
|
16570
17120
|
setSending(true)
|
|
@@ -16783,20 +17333,27 @@ function IdeFloatingAsk({ store, sessions, modelDirectories, translate, openSess
|
|
|
16783
17333
|
width: `${box?.width ?? size.width}px`,
|
|
16784
17334
|
height: `${box?.height ?? size.height}px`,
|
|
16785
17335
|
fontSize: font,
|
|
17336
|
+
// 表头标题按工作区取色;同一个目录永远同一个色相。
|
|
17337
|
+
'--iw-float-hue': String(ideFloatWorkspaceHue(state.rootPath ?? '')),
|
|
16786
17338
|
},
|
|
16787
17339
|
}, children))
|
|
16788
17340
|
|
|
16789
17341
|
if (collapsed) {
|
|
16790
17342
|
// The ball is anchored to the window's bottom-right corner by CSS, so a
|
|
16791
17343
|
// window resize can never leave it stranded mid-screen.
|
|
17344
|
+
// 收起来时审批不会自己跳出来,球上点一个告警点,别让人错过要批的东西。
|
|
17345
|
+
const waiting = ideFloatPendingApprovals(entries)
|
|
16792
17346
|
return shell([h('button', {
|
|
16793
17347
|
key: 'b',
|
|
16794
17348
|
type: 'button',
|
|
16795
17349
|
className: 'iw-float-ball-btn',
|
|
16796
17350
|
onClick: () => store.setFloatCollapsed(false),
|
|
16797
|
-
title: tr('floatExpand'),
|
|
16798
|
-
'aria-label': tr('floatExpand'),
|
|
16799
|
-
},
|
|
17351
|
+
title: waiting > 0 ? tr('floatApprovalBallHint') : tr('floatExpand'),
|
|
17352
|
+
'aria-label': waiting > 0 ? tr('floatApprovalBallHint') : tr('floatExpand'),
|
|
17353
|
+
}, [
|
|
17354
|
+
'AI',
|
|
17355
|
+
waiting > 0 ? h('span', { key: 'dot', className: 'iw-float-ball-dot' }) : null,
|
|
17356
|
+
])], 'iw-float-collapsed', { width: IDE_FLOAT_BALL, height: IDE_FLOAT_BALL })
|
|
16800
17357
|
}
|
|
16801
17358
|
|
|
16802
17359
|
return shell([
|
|
@@ -16811,40 +17368,45 @@ function IdeFloatingAsk({ store, sessions, modelDirectories, translate, openSess
|
|
|
16811
17368
|
type: 'button',
|
|
16812
17369
|
ref: titleBtnRef,
|
|
16813
17370
|
className: 'iw-float-title iw-float-title-btn',
|
|
16814
|
-
|
|
17371
|
+
// 悬停给完整标题 + 工作区路径:标题本身最多 20 个字。
|
|
17372
|
+
title: `${sessionTitle} · ${state.rootPath ?? ''}`,
|
|
16815
17373
|
onClick: () => setMenu(menu === 'sessions' ? '' : 'sessions'),
|
|
16816
17374
|
}, [
|
|
16817
|
-
h('span', { key: 'text', className: 'iw-float-title iw-float-title-text' }, sessionTitle),
|
|
17375
|
+
h('span', { key: 'text', className: 'iw-float-title iw-float-title-text' }, ideFloatTitleText(sessionTitle)),
|
|
16818
17376
|
h('span', { key: 'caret', className: 'iw-float-title-caret' }, '▾'),
|
|
16819
17377
|
]),
|
|
16820
|
-
|
|
16821
|
-
|
|
16822
|
-
type: 'button',
|
|
16823
|
-
className: 'iw-float-new-btn',
|
|
16824
|
-
title: tr('floatNewSession'),
|
|
16825
|
-
'aria-label': tr('floatNewSession'),
|
|
16826
|
-
onClick: () => {
|
|
16827
|
-
setMenu('')
|
|
16828
|
-
if (typeof startSession === 'function') startSession()
|
|
16829
|
-
},
|
|
16830
|
-
}, '+'),
|
|
16831
|
-
h('div', { key: 'actions', className: 'iw-float-actions' }, [
|
|
16832
|
-
h('button', {
|
|
16833
|
-
key: 'shrink',
|
|
16834
|
-
type: 'button',
|
|
16835
|
-
className: 'iw-float-icon',
|
|
16836
|
-
title: tr('floatCollapse'),
|
|
16837
|
-
'aria-label': tr('floatCollapse'),
|
|
16838
|
-
onClick: () => store.setFloatCollapsed(true),
|
|
16839
|
-
}, '–'),
|
|
17378
|
+
// 右侧按钮组绝对定位,标题才能在表头里真正居中。
|
|
17379
|
+
h('div', { key: 'right', className: 'iw-float-head-right' }, [
|
|
16840
17380
|
h('button', {
|
|
16841
|
-
key: '
|
|
17381
|
+
key: 'new',
|
|
16842
17382
|
type: 'button',
|
|
16843
|
-
className: 'iw-float-
|
|
16844
|
-
title: tr('
|
|
16845
|
-
'aria-label': tr('
|
|
16846
|
-
onClick: () =>
|
|
16847
|
-
|
|
17383
|
+
className: 'iw-float-new-btn',
|
|
17384
|
+
title: tr('floatNewSession'),
|
|
17385
|
+
'aria-label': tr('floatNewSession'),
|
|
17386
|
+
onClick: () => {
|
|
17387
|
+
setMenu('')
|
|
17388
|
+
pinnedAdoptRef.current = true
|
|
17389
|
+
if (typeof startSession === 'function') startSession()
|
|
17390
|
+
},
|
|
17391
|
+
}, '+'),
|
|
17392
|
+
h('div', { key: 'actions', className: 'iw-float-actions' }, [
|
|
17393
|
+
h('button', {
|
|
17394
|
+
key: 'shrink',
|
|
17395
|
+
type: 'button',
|
|
17396
|
+
className: 'iw-float-icon',
|
|
17397
|
+
title: tr('floatCollapse'),
|
|
17398
|
+
'aria-label': tr('floatCollapse'),
|
|
17399
|
+
onClick: () => store.setFloatCollapsed(true),
|
|
17400
|
+
}, '–'),
|
|
17401
|
+
h('button', {
|
|
17402
|
+
key: 'close',
|
|
17403
|
+
type: 'button',
|
|
17404
|
+
className: 'iw-float-icon',
|
|
17405
|
+
title: tr('floatClose'),
|
|
17406
|
+
'aria-label': tr('floatClose'),
|
|
17407
|
+
onClick: () => store.setFloatClosed(true),
|
|
17408
|
+
}, '×'),
|
|
17409
|
+
]),
|
|
16848
17410
|
]),
|
|
16849
17411
|
]),
|
|
16850
17412
|
renderSessionsMenu(),
|
|
@@ -16858,8 +17420,12 @@ function IdeFloatingAsk({ store, sessions, modelDirectories, translate, openSess
|
|
|
16858
17420
|
onScroll: (event) => {
|
|
16859
17421
|
const element = event.currentTarget
|
|
16860
17422
|
stickRef.current = element.scrollTop + element.clientHeight >= element.scrollHeight - 40
|
|
17423
|
+
// 滚到最顶再往上拉:补一页更早的历史(没有更多时是空操作)。
|
|
17424
|
+
if (element.scrollTop <= 4) void loadOlderRows()
|
|
16861
17425
|
},
|
|
16862
|
-
},
|
|
17426
|
+
}, [
|
|
17427
|
+
olderBusy ? h('div', { key: 'older', className: 'iw-float-older' }, tr('floatLoadingOlder')) : null,
|
|
17428
|
+
visibleEntries.length === 0 && running !== true
|
|
16863
17429
|
? h('div', { key: 'empty', className: 'iw-float-empty' }, sessionId === '' ? tr('floatNoSession') : tr('floatEmpty'))
|
|
16864
17430
|
: visibleEntries.map((row) => {
|
|
16865
17431
|
// One malformed event must not take the whole card down: a throw inside
|
|
@@ -16870,7 +17436,8 @@ function IdeFloatingAsk({ store, sessions, modelDirectories, translate, openSess
|
|
|
16870
17436
|
ideLogRecord('warn', 'float', 'row render failed', { key: row.key, error: String(error) })
|
|
16871
17437
|
return h('div', { key: row.key, className: 'iw-float-row iw-float-assistant' }, String(row.text ?? ''))
|
|
16872
17438
|
}
|
|
16873
|
-
})
|
|
17439
|
+
}),
|
|
17440
|
+
]),
|
|
16874
17441
|
// The in-flight message renders in the transcript, exactly like the one the
|
|
16875
17442
|
// conversation is printing — no separate 「正在输出」 step.
|
|
16876
17443
|
streamRow === null
|