@in-the-loop-labs/pair-review 5.3.2 → 5.3.4
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/README.md +3 -3
- package/package.json +1 -1
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin-code-critic/.claude-plugin/plugin.json +1 -1
- package/plugin-pair-loop/.claude-plugin/plugin.json +1 -1
- package/public/js/components/ChatPanel.js +253 -14
- package/src/ai/claude-provider.js +35 -70
- package/src/ai/codex-provider.js +67 -64
- package/src/ai/provider.js +15 -7
- package/src/chat/omp-bridge.js +56 -0
- package/src/chat/pi-bridge.js +72 -5
- package/src/chat/session-manager.js +8 -1
- package/src/main.js +2 -3
- package/src/routes/chat.js +10 -0
package/README.md
CHANGED
|
@@ -632,7 +632,7 @@ pair-review integrates with AI providers via their CLI tools:
|
|
|
632
632
|
|
|
633
633
|
- **Claude**: Uses Claude Code CLI
|
|
634
634
|
- **Antigravity**: Uses the Antigravity CLI (`agy`), the successor to the Gemini CLI. Install it with `curl -fsSL https://antigravity.google/cli/install.sh | bash` (macOS/Linux; it is not an npm package) — see the [Antigravity docs](https://antigravity.google/docs). Antigravity is an analysis-only provider: it runs as an agentic reviewer in non-interactive print mode and has **no chat/ACP mode**.
|
|
635
|
-
- **Codex**: Uses Codex CLI
|
|
635
|
+
- **Codex**: Uses Codex CLI. GPT-5.6 Sol High (`gpt-5.6-sol-high`) remains the recommended default during rollout. GPT-6.1 Sol High (`gpt-6.1-sol-high`) and XHigh (`gpt-6.1-sol-xhigh`) are explicit choices for reviews and chat; Enterprise and Edu administrators must enable GPT-6.1 Sol access.
|
|
636
636
|
- **GitHub Copilot**: Uses Copilot CLI
|
|
637
637
|
- **OpenCode**: Uses OpenCode CLI (requires model configuration)
|
|
638
638
|
- **Cursor**: Uses Cursor Agent CLI (streaming output with sandbox mode)
|
|
@@ -726,7 +726,7 @@ You can override provider settings and define custom models in your config file.
|
|
|
726
726
|
| `advisor` | OMP only. Set to `true` to enable OMP's advisor runtime during analysis (`--advisor`). Defaults to `false`: pair-review disables the advisor via a bundled config overlay, even when it is enabled in your global OMP configuration. |
|
|
727
727
|
| `models` | Array of model definitions (see below) |
|
|
728
728
|
| `default_model` | Model `id` to use as the provider's default (in the picker and when no model is specified). Preferred over the per-model `default: true` flag. If it names an unknown or disabled model, the provider falls back to automatic selection. |
|
|
729
|
-
| `disabled_models` | Array of model
|
|
729
|
+
| `disabled_models` | Array of canonical model `id`s to hide. Aliases (such as `opus`, or a retired id that now redirects to a newer model) are not matched and log a warning. Disabled models disappear from the model picker for that provider. Works on built-in models too, so you can remove a built-in option without redefining the rest. A list that would hide *every* model is ignored. |
|
|
730
730
|
|
|
731
731
|
#### Model Configuration Fields
|
|
732
732
|
|
|
@@ -762,7 +762,7 @@ Use the provider-level `default_model` and `disabled_models` fields to tailor wh
|
|
|
762
762
|
}
|
|
763
763
|
```
|
|
764
764
|
|
|
765
|
-
- `disabled_models` removes those models from the picker. It matches
|
|
765
|
+
- `disabled_models` removes those models from the picker. It matches canonical ids only (`opus-5.5-xhigh`, not the `opus` alias). An alias entry is ignored with a warning, so hiding a retired id such as `opus-4.7-high` never hides the newer model it now redirects to. To find the built-in IDs for a provider, see the comments in `config.example.json` (e.g. Claude ships `opus-5.5-medium`, `sonnet-4.6`, `haiku`, …).
|
|
766
766
|
- `default_model` selects which of the *remaining* models is the default. If it points at a model that is unknown or also disabled, the provider falls back to automatic selection (the model marked `default: true`, then the first `balanced`-tier model, then the first model).
|
|
767
767
|
- Prefer `default_model` over the per-model `default: true` flag, which is deprecated. Setting `default_model` suppresses the deprecation warning.
|
|
768
768
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pair-review",
|
|
3
|
-
"version": "5.3.
|
|
3
|
+
"version": "5.3.4",
|
|
4
4
|
"description": "pair-review app integration — Open PRs and local changes in the pair-review web UI, run server-side AI analysis, and address review feedback. Requires the pair-review MCP server.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "in-the-loop-labs",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pair-loop",
|
|
3
|
-
"version": "5.3.
|
|
3
|
+
"version": "5.3.4",
|
|
4
4
|
"description": "Agent-orchestrated review loop — implement, review with pair-review multi-model councils via the headless CLI, triage, fix, and repeat until a final review returns no blockers. MCP-independent.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "in-the-loop-labs",
|
|
@@ -61,6 +61,8 @@ function getChatSpinnerHTML() {
|
|
|
61
61
|
* @property {string|null} sessionAnalysisRunId
|
|
62
62
|
* @property {HTMLElement} messagesEl - Per-tab scrollable messages container
|
|
63
63
|
* @property {HTMLElement|null} streamingMsgEl - Reference to the in-progress assistant bubble
|
|
64
|
+
* @property {boolean} abortPending - True from a user Stop until the aborted run's complete/error arrives
|
|
65
|
+
* @property {boolean} streamJoinedMidTurn - True while the streaming bubble was opened by agent output rather than sendMessage (see _ensureStreamingMessage)
|
|
64
66
|
* @property {boolean} userScrolledAway - Auto-scroll engagement flag
|
|
65
67
|
* @property {Function|null} wsUnsub - Unsubscribe handle for the per-session WS topic
|
|
66
68
|
* @property {Promise<void>|null} historyLoadPromise - Set while history is loading
|
|
@@ -167,6 +169,8 @@ class ChatPanel {
|
|
|
167
169
|
sessionAnalysisRunId: null,
|
|
168
170
|
messagesEl: null,
|
|
169
171
|
streamingMsgEl: null,
|
|
172
|
+
abortPending: false,
|
|
173
|
+
streamJoinedMidTurn: false,
|
|
170
174
|
userScrolledAway: false,
|
|
171
175
|
wsUnsub: null,
|
|
172
176
|
titleFromUser: false,
|
|
@@ -1969,6 +1973,9 @@ class ChatPanel {
|
|
|
1969
1973
|
// before writing.
|
|
1970
1974
|
const capturedEl = tab.messagesEl;
|
|
1971
1975
|
if (!capturedEl) return;
|
|
1976
|
+
// The tab is already subscribed, so live output can land while the fetch
|
|
1977
|
+
// is in flight. Remember what was here so that output can be told apart.
|
|
1978
|
+
const elsBeforeFetch = new Set(capturedEl.children);
|
|
1972
1979
|
|
|
1973
1980
|
let response;
|
|
1974
1981
|
try {
|
|
@@ -2015,6 +2022,13 @@ class ChatPanel {
|
|
|
2015
2022
|
const emptyState = capturedEl.querySelector('.chat-panel__empty');
|
|
2016
2023
|
if (emptyState) emptyState.remove();
|
|
2017
2024
|
|
|
2025
|
+
// Elements added during the fetch — an agent turn already under way when
|
|
2026
|
+
// the tab subscribed, its errors, anything the user sent meanwhile — are
|
|
2027
|
+
// newer than the history. A reply that finished live may also be in the
|
|
2028
|
+
// fetched history; the live bubble stands in for it.
|
|
2029
|
+
const liveEls = Array.from(capturedEl.children).filter(el => !elsBeforeFetch.has(el));
|
|
2030
|
+
const liveMessageIds = new Set(liveEls.map(el => Number(el.dataset?.messageId)).filter(Boolean));
|
|
2031
|
+
|
|
2018
2032
|
// Render into the target tab. The helper methods (_addContextCard,
|
|
2019
2033
|
// addMessage, etc.) read `this.messagesEl` via the active-tab getter, so
|
|
2020
2034
|
// we temporarily redirect the active marker for the synchronous render
|
|
@@ -2043,10 +2057,13 @@ class ChatPanel {
|
|
|
2043
2057
|
// Not JSON — skip malformed context
|
|
2044
2058
|
}
|
|
2045
2059
|
} else if (msg.type === 'message') {
|
|
2060
|
+
if (liveMessageIds.has(msg.id)) continue;
|
|
2046
2061
|
this.addMessage(msg.role, msg.content, msg.id);
|
|
2047
2062
|
}
|
|
2048
2063
|
}
|
|
2049
2064
|
});
|
|
2065
|
+
// History was appended after the live elements; move them back below it.
|
|
2066
|
+
for (const el of liveEls) capturedEl.appendChild(el);
|
|
2050
2067
|
|
|
2051
2068
|
// The tab was initialized as 'pending' (gray dot) before history loaded.
|
|
2052
2069
|
// Now that messages exist, promote to 'idle' (blue dot) — but don't
|
|
@@ -3021,6 +3038,9 @@ class ChatPanel {
|
|
|
3021
3038
|
tab.messages = [];
|
|
3022
3039
|
tab.streamingContent = '';
|
|
3023
3040
|
tab.streamingMsgEl = null;
|
|
3041
|
+
tab.streamJoinedMidTurn = false;
|
|
3042
|
+
// A Stop on the old session must not swallow the new session's turns.
|
|
3043
|
+
tab.abortPending = false;
|
|
3024
3044
|
tab.pendingContext = [];
|
|
3025
3045
|
tab.pendingContextData = [];
|
|
3026
3046
|
tab.latestDiffState = null;
|
|
@@ -3127,6 +3147,7 @@ class ChatPanel {
|
|
|
3127
3147
|
</div>
|
|
3128
3148
|
`;
|
|
3129
3149
|
tab.streamingMsgEl = null;
|
|
3150
|
+
tab.streamJoinedMidTurn = false;
|
|
3130
3151
|
}
|
|
3131
3152
|
|
|
3132
3153
|
/**
|
|
@@ -3329,6 +3350,7 @@ class ChatPanel {
|
|
|
3329
3350
|
|
|
3330
3351
|
// Display user message (just the user's actual text)
|
|
3331
3352
|
const msgElRef = this.addMessage('user', content, undefined, tab);
|
|
3353
|
+
const userMsgEntry = msgElRef ? tab.messages[tab.messages.length - 1] : null;
|
|
3332
3354
|
|
|
3333
3355
|
// Lazy session creation: create on first message, not on panel open
|
|
3334
3356
|
if (tab.sessionId == null) {
|
|
@@ -3357,8 +3379,11 @@ class ChatPanel {
|
|
|
3357
3379
|
}
|
|
3358
3380
|
// If sessionId is set (from MRU), just send — server auto-resumes
|
|
3359
3381
|
|
|
3360
|
-
// Prepare streaming UI. Clear any previous error on this tab
|
|
3382
|
+
// Prepare streaming UI. Clear any previous error on this tab, and any
|
|
3383
|
+
// Stop still waiting on its aborted run — this bubble is a new turn.
|
|
3361
3384
|
tab.errorMessage = null;
|
|
3385
|
+
tab.abortPending = false;
|
|
3386
|
+
tab.streamJoinedMidTurn = false;
|
|
3362
3387
|
tab.isStreaming = true;
|
|
3363
3388
|
this._updateTabStatus(tab, 'streaming');
|
|
3364
3389
|
if (this._getActiveTab() === tab) {
|
|
@@ -3369,6 +3394,7 @@ class ChatPanel {
|
|
|
3369
3394
|
}
|
|
3370
3395
|
tab.streamingContent = '';
|
|
3371
3396
|
this._addStreamingPlaceholder(tab);
|
|
3397
|
+
const placeholderEl = tab.streamingMsgEl;
|
|
3372
3398
|
|
|
3373
3399
|
// Build the API payload — may include pending context from "Ask about this"
|
|
3374
3400
|
const payload = { content };
|
|
@@ -3437,6 +3463,10 @@ class ChatPanel {
|
|
|
3437
3463
|
this._showStatusFlash('Resuming Agent Client Protocol');
|
|
3438
3464
|
}
|
|
3439
3465
|
|
|
3466
|
+
// The session the message is posted to. A tab switched to another session
|
|
3467
|
+
// mid-request has torn this send's bubble down.
|
|
3468
|
+
let sentSessionId = tab.sessionId;
|
|
3469
|
+
|
|
3440
3470
|
// Send to API
|
|
3441
3471
|
try {
|
|
3442
3472
|
console.debug('[ChatPanel] Sending message to session', tab.sessionId);
|
|
@@ -3462,6 +3492,9 @@ class ChatPanel {
|
|
|
3462
3492
|
// _localKey check (rather than orphaning this tab and spawning a new).
|
|
3463
3493
|
const wasActive = this._getActiveTab() === tab;
|
|
3464
3494
|
tab.sessionId = null;
|
|
3495
|
+
// Per-session flags: a Stop clicked on the dead session must not
|
|
3496
|
+
// swallow the replacement session's output.
|
|
3497
|
+
tab.abortPending = false;
|
|
3465
3498
|
if (wasActive) this.activeTabKey = tab._localKey;
|
|
3466
3499
|
const sessionData = await this._createSessionForTab(tab);
|
|
3467
3500
|
if (!this.tabs.includes(tab)) return;
|
|
@@ -3469,6 +3502,7 @@ class ChatPanel {
|
|
|
3469
3502
|
throw new Error('Failed to create replacement session');
|
|
3470
3503
|
}
|
|
3471
3504
|
|
|
3505
|
+
sentSessionId = tab.sessionId;
|
|
3472
3506
|
response = await fetch(`/api/chat/session/${tab.sessionId}/message`, {
|
|
3473
3507
|
method: 'POST',
|
|
3474
3508
|
headers: { 'Content-Type': 'application/json' },
|
|
@@ -3479,12 +3513,31 @@ class ChatPanel {
|
|
|
3479
3513
|
|
|
3480
3514
|
if (!response.ok) {
|
|
3481
3515
|
const err = await response.json().catch(() => ({}));
|
|
3482
|
-
|
|
3516
|
+
const sendError = new Error(err.error || 'Failed to send message');
|
|
3517
|
+
// 409: the agent still owns its previous turn and the server did not
|
|
3518
|
+
// store this message.
|
|
3519
|
+
sendError.notStored = response.status === 409;
|
|
3520
|
+
throw sendError;
|
|
3483
3521
|
}
|
|
3484
3522
|
console.debug('[ChatPanel] Message accepted, waiting for WebSocket events');
|
|
3485
3523
|
} catch (error) {
|
|
3486
3524
|
if (!this.tabs.includes(tab)) return;
|
|
3487
3525
|
if (acpResuming) this._hideStatusFlash();
|
|
3526
|
+
if (error.notStored) {
|
|
3527
|
+
// Take the unsent message back into the input so it can be sent once
|
|
3528
|
+
// the reply finishes — unless the user has moved on or typed again.
|
|
3529
|
+
if (msgElRef) msgElRef.remove();
|
|
3530
|
+
const idx = tab.messages.indexOf(userMsgEntry);
|
|
3531
|
+
if (idx !== -1) tab.messages.splice(idx, 1);
|
|
3532
|
+
if (this._getActiveTab() === tab && !this.inputEl.value) {
|
|
3533
|
+
this.inputEl.value = messageText;
|
|
3534
|
+
this._autoResizeTextarea();
|
|
3535
|
+
}
|
|
3536
|
+
// A tab switched to another session mid-request already dropped this
|
|
3537
|
+
// send's bubbles and pending state; the new session's streaming state
|
|
3538
|
+
// and context are not this send's to touch.
|
|
3539
|
+
if (tab.sessionId !== sentSessionId) return;
|
|
3540
|
+
}
|
|
3488
3541
|
// Restore pending state on the originating tab so it's not lost.
|
|
3489
3542
|
tab.pendingContext = savedContext;
|
|
3490
3543
|
tab.pendingContextData = savedContextData;
|
|
@@ -3496,6 +3549,30 @@ class ChatPanel {
|
|
|
3496
3549
|
// Restore removability on context cards that were locked before the failed send
|
|
3497
3550
|
this._restoreRemovableCards(tab);
|
|
3498
3551
|
console.error('[ChatPanel] Error sending message:', error);
|
|
3552
|
+
if (error.notStored) {
|
|
3553
|
+
// The busy turn's complete can beat this response (it is sent after
|
|
3554
|
+
// the server's busy check) and finalize this send's bubble with only
|
|
3555
|
+
// the output seen during the request. Show all of that reply.
|
|
3556
|
+
const savedId = Number(placeholderEl?.dataset.messageId);
|
|
3557
|
+
if (savedId) this._showSavedReply(tab, placeholderEl, savedId);
|
|
3558
|
+
if (tab.streamingMsgEl) {
|
|
3559
|
+
// The agent is still mid-turn — e.g. an OMP run paused on a
|
|
3560
|
+
// background job, seen from a page reloaded mid-reply. Keep the
|
|
3561
|
+
// bubble streaming, with Stop, so the rest of the turn renders
|
|
3562
|
+
// there; this page missed the turn's start, so complete swaps in
|
|
3563
|
+
// the saved reply. The notice goes above the bubble and, unlike
|
|
3564
|
+
// _showError, leaves the tab 'streaming'.
|
|
3565
|
+
if (tab.streamingMsgEl === placeholderEl) tab.streamJoinedMidTurn = true;
|
|
3566
|
+
if (this._appendErrorBubble('Failed to send message. The agent is still working on its previous reply. Wait for it to finish, or click Stop, then send your message again.', tab)) {
|
|
3567
|
+
tab.messagesEl.appendChild(tab.streamingMsgEl);
|
|
3568
|
+
if (this._getActiveTab() === tab) this.scrollToBottom();
|
|
3569
|
+
}
|
|
3570
|
+
return;
|
|
3571
|
+
}
|
|
3572
|
+
this._showError('Failed to send message. The agent was still finishing its previous reply, which has now ended. Send your message again.', tab);
|
|
3573
|
+
this._finalizeStreaming(tab);
|
|
3574
|
+
return;
|
|
3575
|
+
}
|
|
3499
3576
|
this._showError('Failed to send message. ' + error.message, tab);
|
|
3500
3577
|
this._finalizeStreaming(tab);
|
|
3501
3578
|
}
|
|
@@ -4888,7 +4965,17 @@ class ChatPanel {
|
|
|
4888
4965
|
}
|
|
4889
4966
|
|
|
4890
4967
|
async _recoverTabAfterReconnect(tab) {
|
|
4891
|
-
if (!tab
|
|
4968
|
+
if (!tab) return;
|
|
4969
|
+
if (!tab.isStreaming) {
|
|
4970
|
+
// A Stop's aborted run may have sent its complete/error while the
|
|
4971
|
+
// socket was down; left set, abortPending would drop every later
|
|
4972
|
+
// agent-started turn until the next send. Tradeoff: output still
|
|
4973
|
+
// trailing the stopped run after the reconnect can open a bubble.
|
|
4974
|
+
// Streaming tabs keep it: their Stop request is still in flight.
|
|
4975
|
+
tab.abortPending = false;
|
|
4976
|
+
return;
|
|
4977
|
+
}
|
|
4978
|
+
if (tab.sessionId == null) return;
|
|
4892
4979
|
const capturedSessionId = tab.sessionId;
|
|
4893
4980
|
try {
|
|
4894
4981
|
const response = await fetch(`/api/chat/session/${tab.sessionId}/messages`);
|
|
@@ -4946,22 +5033,32 @@ class ChatPanel {
|
|
|
4946
5033
|
if (!isActive) {
|
|
4947
5034
|
switch (data.type) {
|
|
4948
5035
|
case 'delta':
|
|
4949
|
-
if (!
|
|
5036
|
+
if (!this._ensureStreamingMessage(tab)) break;
|
|
4950
5037
|
tab.streamingContent += data.text;
|
|
4951
5038
|
this.updateStreamingMessage(tab.streamingContent, tab);
|
|
4952
5039
|
this._markStreaming(tab);
|
|
4953
5040
|
break;
|
|
4954
5041
|
case 'status':
|
|
4955
|
-
if (data.status === 'working') this._markStreaming(tab);
|
|
5042
|
+
if (data.status === 'working' && this._ensureStreamingMessage(tab)) this._markStreaming(tab);
|
|
4956
5043
|
break;
|
|
4957
|
-
case 'complete':
|
|
5044
|
+
case 'complete': {
|
|
5045
|
+
// Read before the finalize clears them; see _showSavedReply.
|
|
5046
|
+
const wasAborting = tab.abortPending;
|
|
5047
|
+
const hadBubble = !!tab.streamingMsgEl;
|
|
5048
|
+
const joinedMsgEl = tab.streamJoinedMidTurn ? tab.streamingMsgEl : null;
|
|
5049
|
+
tab.abortPending = false;
|
|
4958
5050
|
this._finalizeTabStream(tab, data.messageId);
|
|
4959
5051
|
tab.streamingContent = '';
|
|
4960
5052
|
tab.isStreaming = false;
|
|
4961
5053
|
tab.errorMessage = null;
|
|
4962
5054
|
this._updateTabStatus(tab, 'idle');
|
|
5055
|
+
if (data.messageId && (joinedMsgEl || (!hadBubble && !wasAborting))) {
|
|
5056
|
+
this._showSavedReply(tab, joinedMsgEl, data.messageId);
|
|
5057
|
+
}
|
|
4963
5058
|
break;
|
|
5059
|
+
}
|
|
4964
5060
|
case 'error':
|
|
5061
|
+
tab.abortPending = false;
|
|
4965
5062
|
// Render the error inline so the user sees what happened when
|
|
4966
5063
|
// they switch back to this tab.
|
|
4967
5064
|
this._showError(data.message || 'An error occurred', tab);
|
|
@@ -4976,21 +5073,34 @@ class ChatPanel {
|
|
|
4976
5073
|
// Foreground path — drive the DOM directly
|
|
4977
5074
|
switch (data.type) {
|
|
4978
5075
|
case 'delta':
|
|
5076
|
+
if (!this._ensureStreamingMessage(tab)) break;
|
|
4979
5077
|
this._hideThinkingIndicator(tab);
|
|
4980
5078
|
tab.streamingContent += data.text;
|
|
4981
5079
|
this.updateStreamingMessage(tab.streamingContent, tab);
|
|
4982
5080
|
break;
|
|
4983
5081
|
case 'tool_use':
|
|
5082
|
+
if (!this._ensureStreamingMessage(tab)) break;
|
|
4984
5083
|
this._showToolUse(data.toolName, data.status, data.toolInput, tab);
|
|
4985
5084
|
break;
|
|
4986
5085
|
case 'status':
|
|
5086
|
+
if (data.status === 'working' && !this._ensureStreamingMessage(tab)) break;
|
|
4987
5087
|
this._handleAgentStatus(data.status, tab);
|
|
4988
5088
|
break;
|
|
4989
|
-
case 'complete':
|
|
5089
|
+
case 'complete': {
|
|
5090
|
+
// Read before the finalize clears them; see _showSavedReply.
|
|
5091
|
+
const wasAborting = tab.abortPending;
|
|
5092
|
+
const hadBubble = !!tab.streamingMsgEl;
|
|
5093
|
+
const joinedMsgEl = tab.streamJoinedMidTurn ? tab.streamingMsgEl : null;
|
|
5094
|
+
tab.abortPending = false;
|
|
4990
5095
|
tab.errorMessage = null;
|
|
4991
5096
|
this.finalizeStreamingMessage(data.messageId, tab);
|
|
5097
|
+
if (data.messageId && (joinedMsgEl || (!hadBubble && !wasAborting))) {
|
|
5098
|
+
this._showSavedReply(tab, joinedMsgEl, data.messageId);
|
|
5099
|
+
}
|
|
4992
5100
|
break;
|
|
5101
|
+
}
|
|
4993
5102
|
case 'error':
|
|
5103
|
+
tab.abortPending = false;
|
|
4994
5104
|
tab.errorMessage = data.message || 'An error occurred';
|
|
4995
5105
|
this._updateTabStatus(tab, 'error');
|
|
4996
5106
|
this._showError(tab.errorMessage, tab);
|
|
@@ -5022,9 +5132,11 @@ class ChatPanel {
|
|
|
5022
5132
|
* @param {string} content - Message text
|
|
5023
5133
|
* @param {number} [id] - Optional message ID
|
|
5024
5134
|
* @param {ChatTab} [targetTab] - Explicit tab; defaults to active tab
|
|
5135
|
+
* @param {{forceScroll?: boolean}} [opts] - forceScroll: false keeps the
|
|
5136
|
+
* user's scroll position when they have scrolled away from the bottom
|
|
5025
5137
|
* @returns {HTMLElement} The message element that was appended
|
|
5026
5138
|
*/
|
|
5027
|
-
addMessage(role, content, id, targetTab) {
|
|
5139
|
+
addMessage(role, content, id, targetTab, { forceScroll = true } = {}) {
|
|
5028
5140
|
const tab = targetTab || this._getActiveTab();
|
|
5029
5141
|
if (!tab || !tab.messagesEl) return null;
|
|
5030
5142
|
|
|
@@ -5064,7 +5176,7 @@ class ChatPanel {
|
|
|
5064
5176
|
}
|
|
5065
5177
|
}
|
|
5066
5178
|
|
|
5067
|
-
if (this._getActiveTab() === tab) this.scrollToBottom({ force:
|
|
5179
|
+
if (this._getActiveTab() === tab) this.scrollToBottom({ force: forceScroll });
|
|
5068
5180
|
return msgEl;
|
|
5069
5181
|
}
|
|
5070
5182
|
|
|
@@ -5109,8 +5221,10 @@ class ChatPanel {
|
|
|
5109
5221
|
/**
|
|
5110
5222
|
* Add a streaming placeholder for the assistant's response on a tab.
|
|
5111
5223
|
* @param {ChatTab} [targetTab] - Defaults to active tab
|
|
5224
|
+
* @param {{forceScroll?: boolean}} [opts] - forceScroll: false keeps the
|
|
5225
|
+
* user's scroll position when they have scrolled away from the bottom
|
|
5112
5226
|
*/
|
|
5113
|
-
_addStreamingPlaceholder(targetTab) {
|
|
5227
|
+
_addStreamingPlaceholder(targetTab, { forceScroll = true } = {}) {
|
|
5114
5228
|
const tab = targetTab || this._getActiveTab();
|
|
5115
5229
|
if (!tab || !tab.messagesEl) return;
|
|
5116
5230
|
const msgEl = document.createElement('div');
|
|
@@ -5123,7 +5237,45 @@ class ChatPanel {
|
|
|
5123
5237
|
msgEl.appendChild(bubble);
|
|
5124
5238
|
tab.messagesEl.appendChild(msgEl);
|
|
5125
5239
|
tab.streamingMsgEl = msgEl;
|
|
5126
|
-
if (this._getActiveTab() === tab) this.scrollToBottom({ force:
|
|
5240
|
+
if (this._getActiveTab() === tab) this.scrollToBottom({ force: forceScroll });
|
|
5241
|
+
}
|
|
5242
|
+
|
|
5243
|
+
/**
|
|
5244
|
+
* Make sure a tab has a streaming bubble for incoming agent output.
|
|
5245
|
+
* sendMessage() normally creates it, but an agent can start a turn on its
|
|
5246
|
+
* own after the previous one completed — OMP resumes when an advisor steers
|
|
5247
|
+
* it or an async job delivers its result. Without a bubble that turn's
|
|
5248
|
+
* deltas and tool badges have nowhere to render, while its 'working' status
|
|
5249
|
+
* still marks the tab streaming, so sends are silently dropped until a page
|
|
5250
|
+
* refresh.
|
|
5251
|
+
*
|
|
5252
|
+
* Output that trails a user Stop is not a new turn: it belongs to the run
|
|
5253
|
+
* being aborted and is dropped until that run's complete/error arrives.
|
|
5254
|
+
*
|
|
5255
|
+
* The bubble is marked streamJoinedMidTurn: this page may have missed the
|
|
5256
|
+
* start of the turn (a reload mid-reply, or an OMP run resuming text the
|
|
5257
|
+
* bridge accumulated before its pause), so on complete the saved reply
|
|
5258
|
+
* replaces the streamed text. Every auto-opened bubble is marked — even
|
|
5259
|
+
* one opened by a 'working' status, since OMP emits one per LLM turn
|
|
5260
|
+
* inside a run — at the cost of one message fetch per such turn.
|
|
5261
|
+
* @param {ChatTab} tab
|
|
5262
|
+
* @returns {boolean} False when the event should be dropped
|
|
5263
|
+
*/
|
|
5264
|
+
_ensureStreamingMessage(tab) {
|
|
5265
|
+
if (tab.streamingMsgEl) return true;
|
|
5266
|
+
if (tab.abortPending) return false;
|
|
5267
|
+
// Agent output the user did not ask for must not yank them back down
|
|
5268
|
+
// from history they are reading.
|
|
5269
|
+
this._addStreamingPlaceholder(tab, { forceScroll: false });
|
|
5270
|
+
tab.streamJoinedMidTurn = true;
|
|
5271
|
+
this._markStreaming(tab);
|
|
5272
|
+
if (this.isOpen && this._getActiveTab() === tab) {
|
|
5273
|
+
this.sendBtn.disabled = true;
|
|
5274
|
+
this.sendBtn.style.display = 'none';
|
|
5275
|
+
this.stopBtn.style.display = '';
|
|
5276
|
+
this._updateActionButtons();
|
|
5277
|
+
}
|
|
5278
|
+
return true;
|
|
5127
5279
|
}
|
|
5128
5280
|
|
|
5129
5281
|
/**
|
|
@@ -5201,6 +5353,72 @@ class ChatPanel {
|
|
|
5201
5353
|
tab.messages.push({ role: 'assistant', content: tab.streamingContent, id: messageId });
|
|
5202
5354
|
}
|
|
5203
5355
|
tab.streamingMsgEl = null;
|
|
5356
|
+
tab.streamJoinedMidTurn = false;
|
|
5357
|
+
}
|
|
5358
|
+
|
|
5359
|
+
/**
|
|
5360
|
+
* Show a just-completed reply as saved. Runs after the synchronous
|
|
5361
|
+
* finalize, so the tab is already idle: a Stop, a send, or the agent's next
|
|
5362
|
+
* turn never race this fetch for the bubble.
|
|
5363
|
+
*
|
|
5364
|
+
* With msgEl, replace that finalized bubble's text: a bubble opened by
|
|
5365
|
+
* _ensureStreamingMessage may have seen only the tail of the turn, while
|
|
5366
|
+
* the saved message holds all of it.
|
|
5367
|
+
*
|
|
5368
|
+
* With msgEl null, add the reply as a new bubble. A page that loaded its
|
|
5369
|
+
* history mid-turn — during an OMP pause, before the reply was saved — and
|
|
5370
|
+
* saw no output before 'complete' (a Stop from another window, an OMP exit
|
|
5371
|
+
* or failed prompt ending the pause) has no bubble to fill. Callers skip
|
|
5372
|
+
* this after a Stop on this tab, whose finalize already shows the reply;
|
|
5373
|
+
* a reply already in tab.messages (history returned it) is skipped here.
|
|
5374
|
+
*
|
|
5375
|
+
* Message ids are numbers ('complete' and the saved rows); a dataset value
|
|
5376
|
+
* is a string, so it is converted with Number() where read.
|
|
5377
|
+
* @param {ChatTab} tab
|
|
5378
|
+
* @param {HTMLElement|null} msgEl - The finalized reply's message element, or null to add one
|
|
5379
|
+
* @param {number} messageId - Saved assistant message id from 'complete'
|
|
5380
|
+
*/
|
|
5381
|
+
async _showSavedReply(tab, msgEl, messageId) {
|
|
5382
|
+
const isShown = () => tab.messages.some(m => m.role === 'assistant' && m.id === messageId);
|
|
5383
|
+
if (!msgEl && isShown()) return;
|
|
5384
|
+
const capturedSessionId = tab.sessionId;
|
|
5385
|
+
let saved = null;
|
|
5386
|
+
try {
|
|
5387
|
+
const response = await fetch(`/api/chat/session/${capturedSessionId}/messages`);
|
|
5388
|
+
if (!response.ok) return;
|
|
5389
|
+
const result = await response.json();
|
|
5390
|
+
saved = (result.data?.messages || []).find(m => m.id === messageId) || null;
|
|
5391
|
+
} catch (err) {
|
|
5392
|
+
console.warn('[ChatPanel] Failed to load saved reply:', err);
|
|
5393
|
+
return;
|
|
5394
|
+
}
|
|
5395
|
+
if (!this.tabs.includes(tab) || tab.sessionId !== capturedSessionId) return;
|
|
5396
|
+
if (!saved?.content) return;
|
|
5397
|
+
|
|
5398
|
+
if (!msgEl) {
|
|
5399
|
+
// History that rendered during the fetch may show it by now. Otherwise
|
|
5400
|
+
// the bubble carries its id, so a history render still to come skips
|
|
5401
|
+
// the row and moves the bubble below the history.
|
|
5402
|
+
if (isShown()) return;
|
|
5403
|
+
// Agent output: don't pull a user reading history back down.
|
|
5404
|
+
this.addMessage('assistant', saved.content, messageId, tab, { forceScroll: false });
|
|
5405
|
+
if (tab.status === 'pending') this._updateTabStatus(tab, 'idle');
|
|
5406
|
+
return;
|
|
5407
|
+
}
|
|
5408
|
+
|
|
5409
|
+
const entry = tab.messages.find(m => m.role === 'assistant' && m.id === messageId);
|
|
5410
|
+
if (entry) {
|
|
5411
|
+
entry.content = saved.content;
|
|
5412
|
+
} else {
|
|
5413
|
+
// Nothing streamed, so the finalize recorded no message.
|
|
5414
|
+
tab.messages.push({ role: 'assistant', content: saved.content, id: messageId });
|
|
5415
|
+
}
|
|
5416
|
+
const bubble = msgEl.querySelector('.chat-panel__bubble');
|
|
5417
|
+
if (bubble) {
|
|
5418
|
+
bubble.innerHTML = this.renderMarkdown(saved.content);
|
|
5419
|
+
this._linkifyFileReferences(bubble);
|
|
5420
|
+
bubble.appendChild(this._createCopyButton(saved.content));
|
|
5421
|
+
}
|
|
5204
5422
|
}
|
|
5205
5423
|
|
|
5206
5424
|
/**
|
|
@@ -5211,12 +5429,19 @@ class ChatPanel {
|
|
|
5211
5429
|
async _stopAgent() {
|
|
5212
5430
|
const tab = this._getActiveTab();
|
|
5213
5431
|
if (!tab || !tab.isStreaming || tab.sessionId == null) return;
|
|
5432
|
+
// Output still in flight from the aborted run must not reopen a bubble
|
|
5433
|
+
// after the finalize below. Set before the request so a complete that
|
|
5434
|
+
// beats the response still clears it.
|
|
5435
|
+
tab.abortPending = true;
|
|
5214
5436
|
try {
|
|
5215
5437
|
await fetch(`/api/chat/session/${tab.sessionId}/abort`, { method: 'POST' });
|
|
5216
5438
|
} catch (error) {
|
|
5217
5439
|
console.error('[ChatPanel] Error aborting:', error);
|
|
5218
5440
|
}
|
|
5219
|
-
|
|
5441
|
+
// A cleared flag means the aborted run already finished (complete/error
|
|
5442
|
+
// finalized its bubble) or the tab moved to another session. Any bubble
|
|
5443
|
+
// now streaming belongs to a newer turn and must be left alone.
|
|
5444
|
+
if (!this.tabs.includes(tab) || !tab.abortPending) return;
|
|
5220
5445
|
// Finalize the streaming message with whatever content we have so far.
|
|
5221
5446
|
this.finalizeStreamingMessage(null, tab);
|
|
5222
5447
|
}
|
|
@@ -5232,6 +5457,7 @@ class ChatPanel {
|
|
|
5232
5457
|
tab.isStreaming = false;
|
|
5233
5458
|
tab.streamingContent = '';
|
|
5234
5459
|
tab.streamingMsgEl = null;
|
|
5460
|
+
tab.streamJoinedMidTurn = false;
|
|
5235
5461
|
this._updateTabStatus(tab, tab.errorMessage ? 'error' : 'idle');
|
|
5236
5462
|
}
|
|
5237
5463
|
if (!tab || this._getActiveTab() === tab) {
|
|
@@ -5431,8 +5657,21 @@ class ChatPanel {
|
|
|
5431
5657
|
tab.errorMessage = message;
|
|
5432
5658
|
this._updateTabStatus(tab, 'error');
|
|
5433
5659
|
}
|
|
5660
|
+
if (!this._appendErrorBubble(message, tab)) return;
|
|
5661
|
+
if (this._getActiveTab() === tab) this.scrollToBottom({ force: true });
|
|
5662
|
+
}
|
|
5663
|
+
|
|
5664
|
+
/**
|
|
5665
|
+
* Append an error bubble to a tab's messages without changing the tab's
|
|
5666
|
+
* status or errorMessage — for a notice that must not mark a turn still
|
|
5667
|
+
* streaming as errored. _showError does both.
|
|
5668
|
+
* @param {string} message - Error text
|
|
5669
|
+
* @param {ChatTab} [tab]
|
|
5670
|
+
* @returns {HTMLElement|null} The bubble, or null when the tab has no messages element
|
|
5671
|
+
*/
|
|
5672
|
+
_appendErrorBubble(message, tab) {
|
|
5434
5673
|
const messagesEl = tab?.messagesEl;
|
|
5435
|
-
if (!messagesEl) return;
|
|
5674
|
+
if (!messagesEl) return null;
|
|
5436
5675
|
const errorEl = document.createElement('div');
|
|
5437
5676
|
errorEl.className = 'chat-panel__message chat-panel__message--error';
|
|
5438
5677
|
errorEl.innerHTML = `
|
|
@@ -5444,7 +5683,7 @@ class ChatPanel {
|
|
|
5444
5683
|
</div>
|
|
5445
5684
|
`;
|
|
5446
5685
|
messagesEl.appendChild(errorEl);
|
|
5447
|
-
|
|
5686
|
+
return errorEl;
|
|
5448
5687
|
}
|
|
5449
5688
|
|
|
5450
5689
|
/**
|