Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ version with its date and start a fresh empty `[Unreleased]` above it.
The toggle is off by default; off keeps the numbered tabs and the existing
interactions unchanged.

- When the selected model is at capacity, the waiting indicator now says so
with the queue position and estimated wait, e.g.
`Model is queued (3 ahead · ~12s wait)...`, and returns to the usual
wording as soon as the request leaves the queue.

## [1.0.14] - 2026-09-20

### Changed
Expand Down
1 change: 1 addition & 0 deletions src/core/types/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ export type StreamChunk =
| { type: 'tool_output'; id: string; content: string }
| { type: 'error'; content: string; code?: string }
| { type: 'notice'; content: string; level?: 'info' | 'warning' }
| { type: 'model_queue'; status: 'queued' | 'ready'; queueCount?: number; waitTimeMs?: number }
| { type: 'done' }
| { type: 'usage'; usage: UsageInfo; sessionId?: string | null }
| { type: 'context_compacted' }
Expand Down
4 changes: 4 additions & 0 deletions src/features/chat/controllers/stream-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ export class StreamController {
await this.appendText(`\n\n⚠️ **${chunk.level === 'warning' ? 'Blocked' : 'Notice'}:** ${chunk.content}`);
break;

case 'model_queue':
this.thinkingIndicator.setQueue(chunk);
break;

case 'error':
await this.handleError(chunk, msg);
break;
Expand Down
44 changes: 41 additions & 3 deletions src/features/chat/controllers/thinking-indicator-controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { formatDurationMmSs } from '../../../core/time/date';
import type { StreamChunk } from '../../../core/types';
import { FLAVOR_TEXTS } from '../flavor-texts';
import type { ChatState } from '../state/chat-state';

Expand All @@ -8,10 +9,21 @@ interface ThinkingIndicatorControllerDeps {
updateQueueIndicator: () => void;
}

type ModelQueueChunk = Extract<StreamChunk, { type: 'model_queue' }>;

const SHOW_DELAY_MS = 400;

function buildQueueLabel(chunk: ModelQueueChunk): string {
const parts: string[] = [];
if (chunk.queueCount && chunk.queueCount > 0) parts.push(`${chunk.queueCount} ahead`);
if (chunk.waitTimeMs && chunk.waitTimeMs > 0) parts.push(`~${Math.ceil(chunk.waitTimeMs / 1000)}s wait`);
return parts.length > 0 ? `Model is queued (${parts.join(' · ')})...` : 'Model is queued...';
}

/** Owns the delayed flavor-text indicator and its elapsed-time timer. */
export class ThinkingIndicatorController {
private queueLabel: string | null = null;

constructor(private readonly deps: ThinkingIndicatorControllerDeps) {}

show(overrideText?: string, overrideCls?: string): void {
Expand All @@ -35,10 +47,12 @@ export class ThinkingIndicatorController {
state.setThinkingIndicatorTimeout(null, null);
if (!state.currentContentEl || state.thinkingEl || state.currentThinkingState) return;

const cls = overrideCls ? `qoderian-thinking ${overrideCls}` : 'qoderian-thinking';
const queueActive = this.queueLabel !== null;
const queueCls = queueActive ? ' qoderian-thinking--queue' : '';
const cls = `qoderian-thinking${overrideCls ? ` ${overrideCls}` : queueCls}`;
state.thinkingEl = state.currentContentEl.createDiv({ cls });
const text = overrideText || FLAVOR_TEXTS[Math.floor(Math.random() * FLAVOR_TEXTS.length)];
state.thinkingEl.createSpan({ text });
const text = overrideText || this.queueLabel || FLAVOR_TEXTS[Math.floor(Math.random() * FLAVOR_TEXTS.length)];
state.thinkingEl.createSpan({ cls: 'qoderian-thinking-text', text });

const timerSpan = state.thinkingEl.createSpan({ cls: 'qoderian-thinking-hint' });
const updateTimer = () => {
Expand All @@ -64,8 +78,32 @@ export class ThinkingIndicatorController {
}, SHOW_DELAY_MS), timerWindow);
}

/** Reflects CLI model-capacity queue progress onto the waiting indicator. */
setQueue(chunk: ModelQueueChunk): void {
const { state } = this.deps;
if (chunk.status === 'ready') {
if (this.queueLabel === null) return;
this.queueLabel = null;
if (state.thinkingEl) {
state.thinkingEl.removeClass('qoderian-thinking--queue');
const label = state.thinkingEl.querySelector<HTMLElement>('.qoderian-thinking-text');
label?.setText(FLAVOR_TEXTS[Math.floor(Math.random() * FLAVOR_TEXTS.length)]);
}
return;
}

this.queueLabel = buildQueueLabel(chunk);
if (state.thinkingEl) {
state.thinkingEl.addClass('qoderian-thinking--queue');
state.thinkingEl.querySelector<HTMLElement>('.qoderian-thinking-text')?.setText(this.queueLabel);
return;
}
this.show(this.queueLabel, 'qoderian-thinking--queue');
}

hide(): void {
const { state } = this.deps;
this.queueLabel = null;
if (state.thinkingIndicatorTimeout) {
const activeWindow = this.deps.getMessagesEl().ownerDocument.defaultView ?? window;
state.clearThinkingIndicatorTimeout(activeWindow);
Expand Down
7 changes: 7 additions & 0 deletions src/qoder/stream/transform-qoder-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,13 @@ export function* transformSDKMessage(
if (notification) {
yield notification;
}
} else if (message.subtype === 'model_queue_status') {
yield {
type: 'model_queue',
status: message.status,
queueCount: message.queue_count,
waitTimeMs: message.wait_time_ms,
};
}
break;

Expand Down
4 changes: 4 additions & 0 deletions src/style/components/thinking.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
color: var(--qoderian-compact);
}

.qoderian-thinking.qoderian-thinking--queue {
color: var(--text-warning);
}

.qoderian-thinking-hint {
color: var(--text-muted);
font-style: normal;
Expand Down
46 changes: 46 additions & 0 deletions tests/unit/qoder/stream/transform-qoder-message.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,52 @@ describe('transformSDKMessage', () => {
},
]);
});

it('maps model_queue_status queued progress to a model_queue chunk', () => {
const message = msg({
type: 'system',
subtype: 'model_queue_status',
status: 'queued',
request_id: 'req-1',
request_set_id: 'set-1',
model_key: 'qoder-model-queue-test',
queue_count: 3,
wait_time_ms: 12000,
} as any);

const results = [...transformSDKMessage(message)];

expect(results).toEqual([
{
type: 'model_queue',
status: 'queued',
queueCount: 3,
waitTimeMs: 12000,
},
]);
});

it('maps model_queue_status ready without optional queue fields', () => {
const message = msg({
type: 'system',
subtype: 'model_queue_status',
status: 'ready',
request_id: 'req-2',
request_set_id: 'set-2',
model_key: 'qoder-model-queue-test',
} as any);

const results = [...transformSDKMessage(message)];

expect(results).toEqual([
{
type: 'model_queue',
status: 'ready',
queueCount: undefined,
waitTimeMs: undefined,
},
]);
});
});

describe('assistant messages', () => {
Expand Down
Loading