moi-computer 0.8.1-next.0 → 0.9.1-next.0
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/client/assets/hermes.png +0 -0
- package/client/components/shared/IconGhost.tsx +15 -18
- package/client/components/ui/button.tsx +2 -2
- package/client/components/ui/hover-card.tsx +1 -1
- package/client/components/ui/popover.tsx +3 -1
- package/client/features/chat/ChatEmptyState.tsx +25 -7
- package/client/features/chat/ChatPanel.tsx +70 -28
- package/client/features/chat/ChatPopup.tsx +3 -2
- package/client/features/chat/ChatPromptBubbles.tsx +1 -1
- package/client/features/chat/MarkdownContent.tsx +1 -1
- package/client/features/chat/attachment-staging.ts +153 -0
- package/client/features/chat/chat-send.ts +55 -0
- package/client/features/chat/chat-store.ts +32 -8
- package/client/features/chat/composer/ChatComposer.tsx +190 -77
- package/client/features/chat/{ModelPicker.tsx → composer/ModelPicker.tsx} +29 -25
- package/client/features/chat/composer/banners/ComposerBanner.tsx +1 -1
- package/client/features/chat/composer/banners/WorkspaceAgentAvailabilityBanner.tsx +4 -13
- package/client/features/chat/{model-order.ts → composer/model-order.ts} +16 -0
- package/client/features/chat/composer/useWorkspaceComposerState.tsx +9 -4
- package/client/features/chat/tool-group/format/claude.ts +48 -0
- package/client/features/chat/tool-group/format/codex.ts +126 -0
- package/client/features/chat/tool-group/format/hermes.ts +68 -0
- package/client/features/chat/tool-group/format/index.ts +34 -0
- package/client/features/chat/tool-group/format/mcp.ts +64 -0
- package/client/features/chat/tool-group/format/openclaw.ts +116 -0
- package/client/features/chat/tool-group/format/shared.ts +49 -0
- package/client/features/chat/useChat.ts +5 -10
- package/client/features/dev/ChatStatesPage.tsx +40 -2
- package/client/features/drawings/DrawingLayer.tsx +49 -0
- package/client/features/drawings/DrawingToolbar.tsx +95 -0
- package/client/features/drawings/annotation-availability.ts +10 -0
- package/client/features/drawings/capture-element.ts +45 -0
- package/client/features/drawings/useChatAnnotation.ts +222 -0
- package/client/features/drawings/useDrawingLayer.ts +758 -0
- package/client/features/drawings/useViewBuilderSketch.ts +151 -0
- package/client/features/home/workspace-presentation.tsx +6 -2
- package/client/features/home/workspace-setup/WorkspaceAgentStep.tsx +12 -6
- package/client/features/scratchpad/ScratchpadControls.tsx +19 -5
- package/client/features/views/ViewBuilder.tsx +224 -0
- package/client/features/views/api.ts +1 -0
- package/client/features/views/useViewBuilderActions.ts +24 -3
- package/client/features/views/useViewBuilderDrafts.ts +66 -0
- package/client/features/widgets/Widgets.tsx +23 -39
- package/client/features/workspace/CustomizePanel.tsx +1 -1
- package/client/features/workspace/WorkspaceScreen.tsx +157 -57
- package/client/features/workspace/WorkspaceTabs.tsx +3 -3
- package/client/features/workspace/useFitsSplitLayout.ts +14 -8
- package/client/index.css +8 -0
- package/client/store/ui.ts +19 -0
- package/client/theme.css +33 -8
- package/dist/chunk-3becmq75.js +81 -0
- package/dist/{chunk-kkj86722.js → chunk-6w6j9g4b.js} +78 -78
- package/dist/{chunk-xeyxk7ep.js → chunk-8ew39cvq.js} +4 -4
- package/dist/chunk-c8gtrjwp.js +1 -0
- package/dist/{chunk-2vaafjp4.js → chunk-pp62fnxh.js} +1 -1
- package/dist/{chunk-35fq49qa.js → chunk-sxc24vfp.js} +1 -1
- package/dist/{chunk-xzx7c9hq.js → chunk-v964b5g7.js} +1 -1
- package/dist/chunk-zx33ts9d.css +1 -0
- package/dist/hermes-pznd63x9.png +0 -0
- package/dist/index.html +1 -1
- package/lib/format.ts +21 -7
- package/lib/themes.ts +8 -8
- package/lib/types.ts +8 -1
- package/lib/workspace-types.ts +2 -1
- package/package.json +6 -4
- package/server/api.ts +21 -2
- package/server/bundler/build-applet.ts +35 -44
- package/server/cli-env.ts +2 -2
- package/server/cli.ts +227 -56
- package/server/constants.ts +8 -0
- package/server/control-client.ts +124 -0
- package/server/control.ts +2 -2
- package/server/harness/README.md +74 -23
- package/server/harness/acp/adapter.ts +220 -0
- package/server/harness/acp/archived.ts +88 -0
- package/server/harness/acp/client.ts +328 -0
- package/server/harness/acp/discovery.ts +130 -0
- package/server/harness/acp/run-durations.ts +68 -0
- package/server/harness/acp/session.ts +788 -0
- package/server/harness/acp/wire.ts +132 -0
- package/server/harness/executable.ts +15 -1
- package/server/harness/hermes/NOTES.md +815 -0
- package/server/harness/hermes/discovery.ts +155 -0
- package/server/harness/hermes/index.ts +155 -0
- package/server/harness/hermes/models.ts +79 -0
- package/server/harness/openclaw/NOTES.md +196 -94
- package/server/harness/openclaw/adapter.ts +28 -55
- package/server/harness/openclaw/compat.ts +4 -8
- package/server/harness/openclaw/session.ts +257 -238
- package/server/harness/openclaw/strip.ts +10 -34
- package/server/harness/openclaw/thinking.ts +5 -53
- package/server/harness/registry.ts +3 -1
- package/server/service.ts +2 -2
- package/server/view-builders.ts +4 -2
- package/server/workspace-import.ts +30 -1
- package/workspace/.claude/skills/moi-workspace/SKILL.md +6 -6
- package/client/features/chat/tool-group/format.ts +0 -359
- package/client/features/views/ViewBuilderTab.tsx +0 -152
- package/dist/chunk-gny990qx.css +0 -1
- package/dist/chunk-gt7n06ef.js +0 -1
- package/dist/chunk-n7pga5x3.js +0 -80
- /package/workspace/.claude/skills/moi-workspace/{DESIGN.md → references/DESIGN.md} +0 -0
- /package/workspace/.claude/skills/moi-workspace/{SCRATCHPAD.md → references/SCRATCHPAD.md} +0 -0
|
@@ -1,21 +1,15 @@
|
|
|
1
|
-
// Per-(workspaceId, sessionId) live OpenClaw session
|
|
1
|
+
// Per-(workspaceId, sessionId) live OpenClaw session.
|
|
2
2
|
//
|
|
3
|
-
//
|
|
4
|
-
// `session.message`
|
|
5
|
-
// the
|
|
6
|
-
//
|
|
7
|
-
//
|
|
3
|
+
// Holds the in-memory view for one session and keeps it current from the
|
|
4
|
+
// gateway's event stream: `session.message` rows build the turns, `chat` frames
|
|
5
|
+
// drive the streaming preview, tool frames drive the tool cards, and the
|
|
6
|
+
// run-end reconcile against `sessions.get` catches anything the wire dropped.
|
|
7
|
+
// The gateway is the source of truth — nothing is persisted here, so a cold
|
|
8
|
+
// open just re-seeds.
|
|
8
9
|
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
// StreamPreview broadcasts; cleared by the client when the durable turn
|
|
13
|
-
// lands carrying the matching `meta.apiMessageId`.
|
|
14
|
-
// - `session.tool` frames (phase start/update/result with full output) →
|
|
15
|
-
// tool cards flip pending→running→success/error mid-run;
|
|
16
|
-
// `reconcileAfterRun` remains the safety net for anything missed.
|
|
17
|
-
// - Disk persistence stays out — the gateway is the source of truth; we
|
|
18
|
-
// re-seed from `sessions.get` on cold start.
|
|
10
|
+
// The frame families and the order they arrive in are documented in NOTES.md
|
|
11
|
+
// §6; the rules that follow from it (who owns a tool card, why identity is
|
|
12
|
+
// decided once) are worth reading before changing anything here.
|
|
19
13
|
import { appendAttachmentNote } from '@/lib/attachment-note'
|
|
20
14
|
import {
|
|
21
15
|
type MoiContext,
|
|
@@ -54,11 +48,7 @@ import {
|
|
|
54
48
|
onGatewayReconnected,
|
|
55
49
|
releaseSessionSubscriptionRef
|
|
56
50
|
} from './gateway'
|
|
57
|
-
import {
|
|
58
|
-
openClawModelRefsEquivalent,
|
|
59
|
-
recordOpenClawThinkingProfile,
|
|
60
|
-
recordOpenClawThinkingRejection
|
|
61
|
-
} from './thinking'
|
|
51
|
+
import { recordOpenClawThinkingProfile, recordOpenClawThinkingRejection } from './thinking'
|
|
62
52
|
import { broadcast } from '../../state'
|
|
63
53
|
import { materializeToPath, resolveUploads } from '../../uploads'
|
|
64
54
|
import {
|
|
@@ -107,29 +97,26 @@ type SessionRecord = {
|
|
|
107
97
|
// per-run and cleared when the run terminalizes.
|
|
108
98
|
previewReasoning?: { runId: string; text: string }
|
|
109
99
|
previewTextBlocks?: { runId: string; blocks: PreviewBlock[] }
|
|
110
|
-
//
|
|
111
|
-
//
|
|
112
|
-
//
|
|
113
|
-
//
|
|
114
|
-
//
|
|
115
|
-
|
|
116
|
-
// Live
|
|
117
|
-
//
|
|
118
|
-
//
|
|
119
|
-
|
|
120
|
-
//
|
|
121
|
-
//
|
|
122
|
-
//
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
//
|
|
127
|
-
//
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
// Last model/thinking applied via sessions.patch, in `provider/model` form —
|
|
131
|
-
// avoids a patch round-trip per send when nothing changed.
|
|
132
|
-
appliedModel?: string
|
|
100
|
+
// Calls rendered as their own turn because no durable row owned them when the
|
|
101
|
+
// tool started, keyed by toolCallId. Permanent for the session: durable rows
|
|
102
|
+
// suppress these ids (adapter `omitToolCallIds`) so a row that later grows the
|
|
103
|
+
// matching block can't render the call twice. A broadcast turn can never be
|
|
104
|
+
// retracted, so ownership is decided once and then respected.
|
|
105
|
+
liveTools: Map<string, { name: string; input: unknown; seq: number }>
|
|
106
|
+
// Live reasoning spans from `agent`/item frames of kind `analysis`, keyed by
|
|
107
|
+
// itemId. Timing only — those frames carry no reasoning text (see
|
|
108
|
+
// handleReasoningItemFrame).
|
|
109
|
+
liveThinking: Map<string, { startedAt: number; endedAt?: number; seq?: number }>
|
|
110
|
+
// Highest `__openclaw.seq` ingested, and a monotonic tick for the synthetic
|
|
111
|
+
// turns that hang off it. Together they place a live card between the
|
|
112
|
+
// durable row that preceded it and the one that follows (see liveTurnSeq).
|
|
113
|
+
lastDurableSeq: number
|
|
114
|
+
liveTurnTick: number
|
|
115
|
+
// The model ref we last asked the gateway for, and the `provider/model` the
|
|
116
|
+
// last row reported. They differ only when something outside moi moved the
|
|
117
|
+
// session, which is the whole point of keeping both.
|
|
118
|
+
requestedModel?: string
|
|
119
|
+
wireModel?: string
|
|
133
120
|
appliedThinking?: string
|
|
134
121
|
// Last `reasoningLevel` applied. The gateway defaults this to `off`, which
|
|
135
122
|
// suppresses reasoning output entirely on providers that would emit it.
|
|
@@ -145,6 +132,10 @@ type SessionRecord = {
|
|
|
145
132
|
// In-flight reconcile, so the two run-end signals (sessions.changed + agent
|
|
146
133
|
// lifecycle) coalesce onto one transcript fetch instead of racing two.
|
|
147
134
|
reconcilePromise?: Promise<void>
|
|
135
|
+
// The run whose failure we already told the user about. A dying run reports
|
|
136
|
+
// itself on several frames with several wordings; the first with text wins
|
|
137
|
+
// and the rest are echoes (see reportRunError).
|
|
138
|
+
reportedErrorRunId?: string
|
|
148
139
|
}
|
|
149
140
|
|
|
150
141
|
const MAX_PENDING_USER_ECHOES = 16
|
|
@@ -318,13 +309,9 @@ export function killAllOpenClawSessions(): void {
|
|
|
318
309
|
for (const rec of [...sessions.values()]) teardownOpenClawSession(rec)
|
|
319
310
|
}
|
|
320
311
|
|
|
321
|
-
//
|
|
322
|
-
//
|
|
323
|
-
//
|
|
324
|
-
// a disconnect, a dropped frame, or a start/result race. On run end the gateway
|
|
325
|
-
// has flushed every durable row, so pulling a fresh transcript and merging any
|
|
326
|
-
// new toolResult rows flips lingering tool-call cards from `pending` to
|
|
327
|
-
// `success`/`error` with output. Idempotent.
|
|
312
|
+
// Run-end reconcile against the canonical transcript. `toolResult` rows never
|
|
313
|
+
// stream (NOTES.md §6) and a row can grow content after it streams, so this is
|
|
314
|
+
// how the view catches up. Idempotent.
|
|
328
315
|
function reconcileAfterRun(rec: SessionRecord): Promise<void> {
|
|
329
316
|
// Both sessions.changed and agent lifecycle can end a run; coalesce onto one
|
|
330
317
|
// in-flight transcript fetch rather than racing two.
|
|
@@ -337,10 +324,47 @@ function reconcileAfterRun(rec: SessionRecord): Promise<void> {
|
|
|
337
324
|
}
|
|
338
325
|
|
|
339
326
|
async function reconcileAfterRunImpl(rec: SessionRecord): Promise<void> {
|
|
327
|
+
// Snapshot the unfinished cards BEFORE the fetch: `rec.liveTools` is
|
|
328
|
+
// session-wide, and a follow-up run starting during the round-trip would
|
|
329
|
+
// otherwise have its fresh cards swept by this run's reconcile.
|
|
330
|
+
const stale = unfinishedLiveTools(rec)
|
|
340
331
|
const detail = await getOpenClawSessionMessages(rec.sessionId, rec.workspacePath, rec.agentId)
|
|
341
332
|
if (!detail?.messages) return
|
|
333
|
+
mergeTranscript(rec, detail.messages, stale)
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// Tool calls with a live card that has not reported a result yet.
|
|
337
|
+
function unfinishedLiveTools(rec: SessionRecord): string[] {
|
|
338
|
+
return [...rec.liveTools.keys()].filter(id => rec.results.get(id)?.running)
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// Test seam: the merge half of the reconcile, against a transcript the caller
|
|
342
|
+
// supplies instead of one fetched over the gateway.
|
|
343
|
+
export function reconcileForTest(rec: SessionRecord, messages: OpenClawMessage[]): void {
|
|
344
|
+
mergeTranscript(rec, messages, unfinishedLiveTools(rec))
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// Test seam: the two halves of the reconcile split, so a test can interleave a
|
|
348
|
+
// follow-up run's frames between the snapshot and the merge the way the real
|
|
349
|
+
// transcript round-trip does.
|
|
350
|
+
export function reconcileSnapshotForTest(rec: SessionRecord): string[] {
|
|
351
|
+
return unfinishedLiveTools(rec)
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
export function reconcileWithStaleForTest(
|
|
355
|
+
rec: SessionRecord,
|
|
356
|
+
messages: OpenClawMessage[],
|
|
357
|
+
stale: string[]
|
|
358
|
+
): void {
|
|
359
|
+
mergeTranscript(rec, messages, stale)
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// Fold a canonical transcript into the live view: adopt rows we're missing or
|
|
363
|
+
// behind on, refresh tool results, and end the cards in `stale` that the run
|
|
364
|
+
// left running.
|
|
365
|
+
function mergeTranscript(rec: SessionRecord, messages: OpenClawMessage[], stale: string[]): void {
|
|
342
366
|
const owners = new Set<OpenClawMessage>()
|
|
343
|
-
for (const msg of
|
|
367
|
+
for (const msg of messages) {
|
|
344
368
|
const result = toolResultFromMessage(msg)
|
|
345
369
|
if (result) {
|
|
346
370
|
const existing = rec.results.get(result.id)
|
|
@@ -363,11 +387,36 @@ async function reconcileAfterRunImpl(rec: SessionRecord): Promise<void> {
|
|
|
363
387
|
if (msg.role !== 'user' && msg.role !== 'assistant') continue
|
|
364
388
|
const id = msg.__openclaw?.id
|
|
365
389
|
if (typeof id !== 'string') continue
|
|
366
|
-
|
|
390
|
+
// Adopt rows we never saw AND rows whose content grew after they streamed.
|
|
391
|
+
// Both happen on the live wire: a row that fans out several tool calls is
|
|
392
|
+
// pushed as text and gains its `toolCall` blocks silently afterwards, so a
|
|
393
|
+
// has-the-id check alone leaves the view permanently behind the transcript.
|
|
394
|
+
const known = rec.messagesById.get(id)
|
|
395
|
+
if (!known || !sameContent(known, msg)) {
|
|
367
396
|
rec.messagesById.set(id, msg)
|
|
397
|
+
rememberSeq(rec, msg)
|
|
368
398
|
owners.add(msg)
|
|
369
399
|
}
|
|
370
400
|
}
|
|
401
|
+
// Cards still running when this run ended: nothing more is coming for them, so
|
|
402
|
+
// end them rather than leaving a permanent spinner. `stale` is captured before
|
|
403
|
+
// the transcript fetch — a follow-up run can start during it and add its own
|
|
404
|
+
// live cards, and finalizing those would strand the NEW run's tools.
|
|
405
|
+
//
|
|
406
|
+
// They end as errors, not successes. All we know is that no result arrived;
|
|
407
|
+
// reading that as "succeeded, with no output" would show a command that may
|
|
408
|
+
// well have failed as if it had worked.
|
|
409
|
+
for (const toolCallId of stale) {
|
|
410
|
+
const result = rec.results.get(toolCallId)
|
|
411
|
+
if (!result?.running) continue
|
|
412
|
+
rec.results.set(toolCallId, {
|
|
413
|
+
...result,
|
|
414
|
+
running: false,
|
|
415
|
+
isError: true,
|
|
416
|
+
output: result.output || 'No result was reported before the run ended.'
|
|
417
|
+
})
|
|
418
|
+
emitLiveToolTurn(rec, toolCallId)
|
|
419
|
+
}
|
|
371
420
|
if (owners.size === 0) return
|
|
372
421
|
let idx = 0
|
|
373
422
|
for (const m of rec.messagesById.values()) {
|
|
@@ -376,6 +425,13 @@ async function reconcileAfterRunImpl(rec: SessionRecord): Promise<void> {
|
|
|
376
425
|
}
|
|
377
426
|
}
|
|
378
427
|
|
|
428
|
+
// Do two versions of the same durable row carry the same content? Structural
|
|
429
|
+
// compare on the blocks only — the fields around them (usage, stopReason) can
|
|
430
|
+
// be filled in later without changing what the turn renders.
|
|
431
|
+
function sameContent(a: OpenClawMessage, b: OpenClawMessage): boolean {
|
|
432
|
+
return JSON.stringify(a.content) === JSON.stringify(b.content)
|
|
433
|
+
}
|
|
434
|
+
|
|
379
435
|
// Re-derive the view from the current messages + results map. Cheaper than
|
|
380
436
|
// it sounds because we keep the materialized `view` and re-build only when
|
|
381
437
|
// a tool-result update forces a re-emit.
|
|
@@ -409,7 +465,7 @@ function rebuildView(rec: SessionRecord): void {
|
|
|
409
465
|
prevModel = model
|
|
410
466
|
}
|
|
411
467
|
}
|
|
412
|
-
const turn = messageToTurn(msg, rec.sessionKey, i++, rec.results)
|
|
468
|
+
const turn = messageToTurn(msg, rec.sessionKey, i++, rec.results, liveToolIds(rec))
|
|
413
469
|
if (turn) view = applyEvent(view, { kind: 'turn', turn })
|
|
414
470
|
}
|
|
415
471
|
// Compaction notices have no durable twin in `sessions.get` — they exist
|
|
@@ -437,24 +493,32 @@ export function normalizeEchoText(text: string | undefined): string {
|
|
|
437
493
|
return stripMoiContext(text).replace(/\s+/g, ' ').trim()
|
|
438
494
|
}
|
|
439
495
|
|
|
496
|
+
// Synthetic turns (live tool cards, live thinking spans) have no transcript
|
|
497
|
+
// row, so they get a fractional position just past the last durable row we
|
|
498
|
+
// ingested. That keeps them after the text that introduced them and before
|
|
499
|
+
// whatever the backend commits next, without ever colliding with a real seq.
|
|
500
|
+
function liveTurnSeq(rec: SessionRecord): number {
|
|
501
|
+
rec.liveTurnTick += 1
|
|
502
|
+
return rec.lastDurableSeq + rec.liveTurnTick / 1000
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
// Tool calls owned by a live card, for the adapter to leave out of durable
|
|
506
|
+
// rows. `undefined` when there are none, so the common path allocates nothing.
|
|
507
|
+
function liveToolIds(rec: SessionRecord): ReadonlySet<string> | undefined {
|
|
508
|
+
return rec.liveTools.size > 0 ? new Set(rec.liveTools.keys()) : undefined
|
|
509
|
+
}
|
|
510
|
+
|
|
440
511
|
function emitTurn(rec: SessionRecord, msg: OpenClawMessage, idx: number): void {
|
|
441
|
-
const turn = messageToTurn(msg, rec.sessionKey, idx, rec.results)
|
|
512
|
+
const turn = messageToTurn(msg, rec.sessionKey, idx, rec.results, liveToolIds(rec))
|
|
442
513
|
if (!turn) return
|
|
443
|
-
// Optimistic-id rendezvous:
|
|
444
|
-
//
|
|
445
|
-
// 2026.6.x), fall back to first-matching-text for old rows and unknown
|
|
446
|
-
// runIds. Re-id to the optimistic id so the optimistic bubble upserts in
|
|
447
|
-
// place instead of duplicating.
|
|
514
|
+
// Optimistic-id rendezvous: re-id the durable user row to the bubble the
|
|
515
|
+
// client already drew, so it upserts in place instead of duplicating.
|
|
448
516
|
if (rec.pendingUserEchoes.length > 0 && turn.role === 'user') {
|
|
449
517
|
const idem = messageIdempotencyKey(msg)
|
|
450
|
-
//
|
|
451
|
-
//
|
|
452
|
-
//
|
|
453
|
-
//
|
|
454
|
-
// as the version-agnostic fallback: strip the moi-context envelope from
|
|
455
|
-
// both sides (the durable row is already stripped for display; the
|
|
456
|
-
// optimistic text never carries it) and collapse whitespace, so a
|
|
457
|
-
// trailing newline or metadata difference can't split the bubble.
|
|
518
|
+
// Three ways in, cheapest first: the send's own `<runId>:user` key; the
|
|
519
|
+
// same key with the runId read off the row (the echo can beat the
|
|
520
|
+
// `sessions.send` response); and normalized text, for rows carrying
|
|
521
|
+
// neither.
|
|
458
522
|
const idemRunId = idem?.endsWith(':user') ? idem.slice(0, -':user'.length) : undefined
|
|
459
523
|
let at = idem
|
|
460
524
|
? rec.pendingUserEchoes.findIndex(
|
|
@@ -470,20 +534,6 @@ function emitTurn(rec: SessionRecord, msg: OpenClawMessage, idx: number): void {
|
|
|
470
534
|
rec.pendingUserEchoes.splice(at, 1)
|
|
471
535
|
}
|
|
472
536
|
}
|
|
473
|
-
// Live-tool rendezvous: a durable assistant row carrying a toolCall we
|
|
474
|
-
// already rendered as a live tool turn re-ids to that live turn so the card
|
|
475
|
-
// upserts in place (the codex-app-server backend delivers the durable owner
|
|
476
|
-
// only in the run-end batch, after the live card is already on screen).
|
|
477
|
-
if (turn.role === 'assistant' && rec.liveTools.size > 0) {
|
|
478
|
-
const toolPart = turn.parts.find(p => p.type === 'tool-call')
|
|
479
|
-
const toolCallId = toolPart?.type === 'tool-call' ? toolPart.call.toolCallId : undefined
|
|
480
|
-
// Keep the mapping (don't delete): the run-end reconcile re-emits the same
|
|
481
|
-
// durable row, and it must re-id to the SAME live turn every time or it
|
|
482
|
-
// lands as a second card.
|
|
483
|
-
if (toolCallId && rec.liveTools.has(toolCallId)) {
|
|
484
|
-
turn.id = liveToolTurnId(rec.sessionKey, toolCallId)
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
537
|
// Stamp the run's preview slot id so the client clears the streaming
|
|
488
538
|
// preview when this turn upserts (chat deltas can trail the durable row).
|
|
489
539
|
// Only FRESH turns get the current run's slot — a re-emitted older turn
|
|
@@ -514,9 +564,9 @@ function reemitToolCallOwners(rec: SessionRecord, toolCallId: string): void {
|
|
|
514
564
|
}
|
|
515
565
|
}
|
|
516
566
|
|
|
517
|
-
// `chat` delta
|
|
518
|
-
//
|
|
519
|
-
//
|
|
567
|
+
// A `chat` delta frame carries the whole in-progress message; map its blocks to
|
|
568
|
+
// cumulative PreviewBlocks. Text and thinking only — tool calls have their own
|
|
569
|
+
// cards. Exported for tests.
|
|
520
570
|
export function chatPreviewBlocks(content: unknown): PreviewBlock[] {
|
|
521
571
|
if (typeof content === 'string') {
|
|
522
572
|
return content ? [{ index: 0, kind: 'text', text: content }] : []
|
|
@@ -525,30 +575,20 @@ export function chatPreviewBlocks(content: unknown): PreviewBlock[] {
|
|
|
525
575
|
const blocks: PreviewBlock[] = []
|
|
526
576
|
content.forEach((block, index) => {
|
|
527
577
|
if (!block || typeof block !== 'object') return
|
|
528
|
-
const b = block as { type?: unknown; text?: unknown; thinking?: unknown
|
|
578
|
+
const b = block as { type?: unknown; text?: unknown; thinking?: unknown }
|
|
529
579
|
if (b.type === 'text' && typeof b.text === 'string' && b.text) {
|
|
530
580
|
blocks.push({ index, kind: 'text', text: b.text })
|
|
531
|
-
} else if (b.type === 'thinking'
|
|
532
|
-
|
|
533
|
-
// lives in `thinking`, `reasoning`, or `text` depending on the line.
|
|
534
|
-
const text =
|
|
535
|
-
(typeof b.thinking === 'string' && b.thinking) ||
|
|
536
|
-
(typeof b.reasoning === 'string' && b.reasoning) ||
|
|
537
|
-
(typeof b.text === 'string' && b.text) ||
|
|
538
|
-
''
|
|
539
|
-
if (text) blocks.push({ index, kind: 'reasoning', text })
|
|
581
|
+
} else if (b.type === 'thinking' && typeof b.thinking === 'string' && b.thinking) {
|
|
582
|
+
blocks.push({ index, kind: 'reasoning', text: b.thinking })
|
|
540
583
|
}
|
|
541
584
|
})
|
|
542
585
|
return blocks
|
|
543
586
|
}
|
|
544
587
|
|
|
545
|
-
//
|
|
546
|
-
//
|
|
547
|
-
//
|
|
548
|
-
//
|
|
549
|
-
// emits both doesn't double-broadcast (which would flicker as the two
|
|
550
|
-
// cumulative snapshots race), and a gateway that emits only `agent` frames
|
|
551
|
-
// still streams instead of dumping the whole reply at run end.
|
|
588
|
+
// A gateway streams the assistant text on BOTH `chat` state=delta and `agent`
|
|
589
|
+
// stream=assistant, for the same run, in the same millisecond. Whichever emits
|
|
590
|
+
// first claims the run so the two cumulative snapshots can't race into a
|
|
591
|
+
// flicker; a gateway sending only one of them still streams.
|
|
552
592
|
type PreviewSource = 'chat' | 'agent'
|
|
553
593
|
// Exported for tests: only reads/writes the two preview-source fields.
|
|
554
594
|
export function claimPreviewSource(
|
|
@@ -574,14 +614,11 @@ function broadcastPreview(rec: SessionRecord, messageId: string, blocks: Preview
|
|
|
574
614
|
})
|
|
575
615
|
}
|
|
576
616
|
|
|
577
|
-
// Repaint the
|
|
578
|
-
//
|
|
579
|
-
//
|
|
580
|
-
//
|
|
581
|
-
//
|
|
582
|
-
// Both halves are keyed by runId rather than pinned on `previewRunId`, so
|
|
583
|
-
// reasoning can never consume the text source's claim (that would lock `chat`
|
|
584
|
-
// out of its own run and stop the answer from streaming at all).
|
|
617
|
+
// Repaint the preview from both streams at once: reasoning first (it precedes
|
|
618
|
+
// the answer), then the text. A preview replaces every block for its messageId,
|
|
619
|
+
// so broadcasting the two separately would erase one with the other. Keyed by
|
|
620
|
+
// runId rather than by the claim, so reasoning can never lock the text source
|
|
621
|
+
// out of its own run.
|
|
585
622
|
function emitMergedPreview(rec: SessionRecord, runId: string, messageId: string): void {
|
|
586
623
|
const blocks: PreviewBlock[] = []
|
|
587
624
|
const reasoning = rec.previewReasoning?.runId === runId ? rec.previewReasoning.text : ''
|
|
@@ -636,10 +673,25 @@ function handleAgentStreamFrame(rec: SessionRecord, payload: Record<string, unkn
|
|
|
636
673
|
emitMergedPreview(rec, runId, previewMessageId(rec.sessionKey, runId))
|
|
637
674
|
}
|
|
638
675
|
|
|
676
|
+
// A dying run says why on three different frames with three different wordings
|
|
677
|
+
// (NOTES.md §6), and the reason is something the user can act on. Report the
|
|
678
|
+
// first that carries text; the rest are echoes. Without this the chat just
|
|
679
|
+
// stops — spinner off, nothing said.
|
|
680
|
+
export function reportRunError(rec: SessionRecord, runId: string, message: unknown): void {
|
|
681
|
+
if (rec.reportedErrorRunId === runId) return
|
|
682
|
+
const text = typeof message === 'string' ? message.trim() : ''
|
|
683
|
+
if (!text) return
|
|
684
|
+
rec.reportedErrorRunId = runId
|
|
685
|
+
broadcast(rec.workspaceId, { kind: 'error', sessionId: rec.sessionId, content: text })
|
|
686
|
+
}
|
|
687
|
+
|
|
639
688
|
function handleChatFrame(rec: SessionRecord, payload: Record<string, unknown>): void {
|
|
640
|
-
if (!rec.streamEnabled) return
|
|
641
689
|
const runId = typeof payload.runId === 'string' ? payload.runId : rec.activeRunId
|
|
642
690
|
if (!runId) return
|
|
691
|
+
// Errors are reported whether or not the client asked for token streaming —
|
|
692
|
+
// the toggle governs previews, not whether failures are visible.
|
|
693
|
+
if (payload.state === 'error') reportRunError(rec, runId, payload.errorMessage)
|
|
694
|
+
if (!rec.streamEnabled) return
|
|
643
695
|
const messageId = previewMessageId(rec.sessionKey, runId)
|
|
644
696
|
const state = payload.state
|
|
645
697
|
if (state === 'delta') {
|
|
@@ -661,8 +713,8 @@ function handleChatFrame(rec: SessionRecord, payload: Record<string, unknown>):
|
|
|
661
713
|
}
|
|
662
714
|
}
|
|
663
715
|
|
|
664
|
-
// The id of the
|
|
665
|
-
//
|
|
716
|
+
// The id of the live tool turn for a toolCallId. Stable for the session, so
|
|
717
|
+
// every later frame for that call upserts the same card.
|
|
666
718
|
function liveToolTurnId(sessionKey: string, toolCallId: string): string {
|
|
667
719
|
return `openclaw:${sessionKey}:livetool:${toolCallId}`
|
|
668
720
|
}
|
|
@@ -692,26 +744,18 @@ function emitLiveToolTurn(rec: SessionRecord, toolCallId: string): void {
|
|
|
692
744
|
id: liveToolTurnId(rec.sessionKey, toolCallId),
|
|
693
745
|
role: 'assistant',
|
|
694
746
|
origin: { kind: 'user-input' },
|
|
695
|
-
parts: [{ type: 'tool-call', call }]
|
|
747
|
+
parts: [{ type: 'tool-call', call }],
|
|
748
|
+
seq: meta.seq
|
|
696
749
|
}
|
|
697
750
|
rec.view = applyEvent(rec.view, { kind: 'turn', turn })
|
|
698
751
|
broadcast(rec.workspaceId, { kind: 'turn', turn, sessionId: rec.sessionId })
|
|
699
752
|
}
|
|
700
753
|
|
|
701
|
-
// A run can die before it
|
|
702
|
-
//
|
|
703
|
-
//
|
|
704
|
-
//
|
|
705
|
-
//
|
|
706
|
-
//
|
|
707
|
-
// Verified live on 2026.7.2-beta.7: `sessions.patch { model }` makes OpenClaw
|
|
708
|
-
// persist the pick into the agent's effective `model.primary`, and that config
|
|
709
|
-
// write bumps the agent's prepared-model-runtime generation while the run is
|
|
710
|
-
// being admitted — the run dies with "prepared model runtime catalog
|
|
711
|
-
// generation was superseded" after `sessions.send` already returned
|
|
712
|
-
// `status: 'started'` and a runId. The frame carries no error text on this
|
|
713
|
-
// path, so the message says what the user can act on instead of inventing a
|
|
714
|
-
// cause. Resending works: the model is already applied, so no second write.
|
|
754
|
+
// A run can die during admission, before it reports any lifecycle phase. The
|
|
755
|
+
// gateway announces that only as `sessions.changed { reason:
|
|
756
|
+
// 'chat.dispatch-error' }` — no runId, no error text — so the runId-keyed
|
|
757
|
+
// clauses never fire and the composer would spin forever. With no cause on the
|
|
758
|
+
// wire, say the one thing the user can act on.
|
|
715
759
|
export function handleDispatchError(rec: SessionRecord): void {
|
|
716
760
|
setProcessing(rec, false, null)
|
|
717
761
|
broadcast(rec.workspaceId, {
|
|
@@ -726,18 +770,11 @@ function liveThinkingTurnId(sessionKey: string, itemId: string): string {
|
|
|
726
770
|
return `openclaw:${sessionKey}:livethink:${itemId}`
|
|
727
771
|
}
|
|
728
772
|
|
|
729
|
-
//
|
|
730
|
-
//
|
|
731
|
-
//
|
|
732
|
-
//
|
|
733
|
-
//
|
|
734
|
-
// So we render what the backend does give: a "Thinking" row that becomes
|
|
735
|
-
// "Thought for 1.2s". Without this a codex run shows a silent gap between the
|
|
736
|
-
// send and the first token, even though the model is visibly reasoning.
|
|
737
|
-
//
|
|
738
|
-
// Deliberately NOT durable: nothing in the transcript backs it, so a cold
|
|
739
|
-
// reload (re-seed from `sessions.get`) drops the row. Same tradeoff as the live
|
|
740
|
-
// tool cards — `applyEvent` upserts and can never retract.
|
|
773
|
+
// Some runtimes report reasoning as an `agent`/item frame of `kind: 'analysis'`
|
|
774
|
+
// (emitted by `extensions/codex`) — presence and timing, never text. Render
|
|
775
|
+
// what they do give: a "Thinking" row that becomes "Thought for 1.2s", instead
|
|
776
|
+
// of a silent gap before the first token. Not durable — nothing in the
|
|
777
|
+
// transcript backs it, so a cold reload drops the row.
|
|
741
778
|
export function handleReasoningItemFrame(
|
|
742
779
|
rec: SessionRecord,
|
|
743
780
|
payload: Record<string, unknown>
|
|
@@ -773,6 +810,9 @@ function emitLiveThinkingTurn(rec: SessionRecord, itemId: string): void {
|
|
|
773
810
|
id: liveThinkingTurnId(rec.sessionKey, itemId),
|
|
774
811
|
role: 'assistant',
|
|
775
812
|
origin: { kind: 'user-input' },
|
|
813
|
+
// Placed once, on the `start` frame — the `end` frame upserts the same
|
|
814
|
+
// turn, so the row must not hop to a new position when it finishes.
|
|
815
|
+
seq: (span.seq ??= liveTurnSeq(rec)),
|
|
776
816
|
parts: [
|
|
777
817
|
{
|
|
778
818
|
type: 'reasoning',
|
|
@@ -786,17 +826,11 @@ function emitLiveThinkingTurn(rec: SessionRecord, itemId: string): void {
|
|
|
786
826
|
broadcast(rec.workspaceId, { kind: 'turn', turn, sessionId: rec.sessionId })
|
|
787
827
|
}
|
|
788
828
|
|
|
789
|
-
// `session.tool` and `agent`/tool
|
|
790
|
-
//
|
|
791
|
-
//
|
|
792
|
-
//
|
|
793
|
-
|
|
794
|
-
// stays as the safety net. Exported for tests.
|
|
795
|
-
export function handleToolFrame(
|
|
796
|
-
rec: SessionRecord,
|
|
797
|
-
payload: Record<string, unknown>,
|
|
798
|
-
opts?: { fromAgentStream?: boolean }
|
|
799
|
-
): void {
|
|
829
|
+
// Live tool state, from either frame family: `session.tool` and `agent`/tool
|
|
830
|
+
// are the same payload sent to disjoint audiences (NOTES.md §6), so one
|
|
831
|
+
// handler serves both. start/update → running, result → success/error with
|
|
832
|
+
// output. Exported for tests.
|
|
833
|
+
export function handleToolFrame(rec: SessionRecord, payload: Record<string, unknown>): void {
|
|
800
834
|
const data = payload.data as
|
|
801
835
|
| {
|
|
802
836
|
phase?: unknown
|
|
@@ -812,29 +846,24 @@ export function handleToolFrame(
|
|
|
812
846
|
const name = typeof data.name === 'string' ? data.name : undefined
|
|
813
847
|
const toolName = name ? { toolName: name } : {}
|
|
814
848
|
if (data.phase === 'start' || data.phase === 'update') {
|
|
815
|
-
//
|
|
816
|
-
//
|
|
817
|
-
//
|
|
818
|
-
// (
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
// chat just sits frozen for the whole tool call. These cards are therefore
|
|
826
|
-
// live-only by nature and drop on a cold re-seed, same as the codex ones.
|
|
827
|
-
if ((rec.codexBackend || opts?.fromAgentStream) && name && !rec.liveTools.has(id)) {
|
|
828
|
-
rec.liveTools.set(id, { name, input: data.args })
|
|
849
|
+
// Does a durable row already own this call? If so it renders the card. If
|
|
850
|
+
// not, this frame is the only evidence the call exists, so give it a turn of
|
|
851
|
+
// its own. Which case applies is a property of the run, not of the backend
|
|
852
|
+
// (NOTES.md §6) — asking the messages map is exact and needs no guess.
|
|
853
|
+
if (
|
|
854
|
+
name &&
|
|
855
|
+
!rec.liveTools.has(id) &&
|
|
856
|
+
findToolCallOwners(rec.messagesById.values(), id).length === 0
|
|
857
|
+
) {
|
|
858
|
+
rec.liveTools.set(id, { name, input: data.args, seq: liveTurnSeq(rec) })
|
|
829
859
|
}
|
|
830
860
|
const existing = rec.results.get(id)
|
|
831
861
|
if (existing && !existing.running) return // final result already landed
|
|
832
862
|
rec.results.set(id, { output: '', isError: false, running: true, ...toolName })
|
|
833
863
|
} else if (data.phase === 'result') {
|
|
834
|
-
// Two result shapes on the wire: `
|
|
835
|
-
//
|
|
836
|
-
//
|
|
837
|
-
// tool card with an empty body.
|
|
864
|
+
// Two result shapes on the wire: `{ content: [...] }` from the exec-style
|
|
865
|
+
// tools, and a bare string from CLI-backed runtimes. Reading `.content` off
|
|
866
|
+
// a string yields undefined, which rendered those cards with an empty body.
|
|
838
867
|
const raw = data.result
|
|
839
868
|
const content =
|
|
840
869
|
typeof raw === 'string' ? raw : ((raw as { content?: unknown } | undefined)?.content ?? '')
|
|
@@ -851,13 +880,10 @@ export function handleToolFrame(
|
|
|
851
880
|
else if (rec.liveTools.has(id)) emitLiveToolTurn(rec, id)
|
|
852
881
|
}
|
|
853
882
|
|
|
854
|
-
// Debounced
|
|
855
|
-
//
|
|
856
|
-
//
|
|
857
|
-
//
|
|
858
|
-
// is what keeps titles/previews fresh there. A trailing flush covers bursts
|
|
859
|
-
// (create immediately followed by the title patch) that a leading-edge-only
|
|
860
|
-
// throttle would drop.
|
|
883
|
+
// Debounced session-list refresh. `sessions.changed` fires for every session
|
|
884
|
+
// under the agent and several records can hold subscriptions for one workspace,
|
|
885
|
+
// so bursts are the norm; the trailing flush catches the tail of one (a create
|
|
886
|
+
// followed straight away by the title patch).
|
|
861
887
|
const lastListRefresh = new Map<string, { at: number; trailing?: ReturnType<typeof setTimeout> }>()
|
|
862
888
|
const LIST_REFRESH_MIN_MS = 400
|
|
863
889
|
const LIST_REFRESH_REASONS = new Set([
|
|
@@ -939,6 +965,7 @@ export function ingest(rec: SessionRecord, msg: OpenClawMessage): void {
|
|
|
939
965
|
}
|
|
940
966
|
}
|
|
941
967
|
rec.messagesById.set(id, msg)
|
|
968
|
+
rememberSeq(rec, msg)
|
|
942
969
|
// Compute idx as insertion order — for an update use the existing position,
|
|
943
970
|
// for a new message it's the last slot.
|
|
944
971
|
let idx = 0
|
|
@@ -949,6 +976,13 @@ export function ingest(rec: SessionRecord, msg: OpenClawMessage): void {
|
|
|
949
976
|
emitTurn(rec, msg, idx)
|
|
950
977
|
}
|
|
951
978
|
|
|
979
|
+
// Track the furthest transcript position we've ingested, so synthetic turns
|
|
980
|
+
// can be placed just past it (liveTurnSeq).
|
|
981
|
+
function rememberSeq(rec: SessionRecord, msg: OpenClawMessage): void {
|
|
982
|
+
const seq = msg.__openclaw?.seq
|
|
983
|
+
if (typeof seq === 'number' && seq > rec.lastDurableSeq) rec.lastDurableSeq = seq
|
|
984
|
+
}
|
|
985
|
+
|
|
952
986
|
async function seed(rec: SessionRecord): Promise<void> {
|
|
953
987
|
const detail: OpenClawSessionDetail | null = await getOpenClawSessionMessages(
|
|
954
988
|
rec.sessionId,
|
|
@@ -967,6 +1001,7 @@ async function seed(rec: SessionRecord): Promise<void> {
|
|
|
967
1001
|
const id = msg.__openclaw?.id
|
|
968
1002
|
if (typeof id !== 'string') continue
|
|
969
1003
|
rec.messagesById.set(id, msg)
|
|
1004
|
+
rememberSeq(rec, msg)
|
|
970
1005
|
}
|
|
971
1006
|
rebuildView(rec)
|
|
972
1007
|
}
|
|
@@ -1027,7 +1062,7 @@ async function ensureSubscribed(rec: SessionRecord): Promise<void> {
|
|
|
1027
1062
|
| { model?: unknown; modelProvider?: unknown; thinkingLevel?: unknown }
|
|
1028
1063
|
| undefined
|
|
1029
1064
|
if (row && typeof row.model === 'string' && typeof row.modelProvider === 'string') {
|
|
1030
|
-
rec.
|
|
1065
|
+
rec.wireModel = `${row.modelProvider}/${row.model}`
|
|
1031
1066
|
}
|
|
1032
1067
|
if (row && typeof row.thinkingLevel === 'string') rec.appliedThinking = row.thinkingLevel
|
|
1033
1068
|
// Every row carries the model's resolved thinking menu — the only source
|
|
@@ -1051,36 +1086,24 @@ async function ensureSubscribed(rec: SessionRecord): Promise<void> {
|
|
|
1051
1086
|
} else if (event === 'agent') {
|
|
1052
1087
|
if (payload.sessionKey !== rec.sessionKey) return
|
|
1053
1088
|
const stream = payload.stream as string | undefined
|
|
1054
|
-
// `codex*` frames (`codex_app_server.lifecycle|item|hook|usage`, and any
|
|
1055
|
-
// future `codex.*` rename) are emitted only by the codex backend and
|
|
1056
|
-
// precede its tool frames within a run — the positive signal that live
|
|
1057
|
-
// tool synthesis is warranted for this session (see handleToolFrame). No
|
|
1058
|
-
// native stream name starts with `codex`, so this never false-positives.
|
|
1059
|
-
if (typeof stream === 'string' && stream.startsWith('codex')) {
|
|
1060
|
-
rec.codexBackend = true
|
|
1061
|
-
return
|
|
1062
|
-
}
|
|
1063
1089
|
// Streaming text/reasoning fallback for gateways that don't emit `chat`
|
|
1064
1090
|
// delta frames (handleAgentStreamFrame no-ops when `chat` already owns
|
|
1065
1091
|
// the run's TEXT; reasoning is merged in alongside it). `thinking` is a
|
|
1066
|
-
// second wire name for the reasoning stream — text-bearing on
|
|
1067
|
-
//
|
|
1068
|
-
//
|
|
1092
|
+
// second wire name for the reasoning stream — text-bearing on some
|
|
1093
|
+
// runtimes, a bare `{ progressTokens }` heartbeat on others, which the
|
|
1094
|
+
// empty-text check drops.
|
|
1069
1095
|
if (stream === 'assistant' || stream === 'reasoning' || stream === 'thinking') {
|
|
1070
1096
|
handleAgentStreamFrame(rec, payload)
|
|
1071
1097
|
return
|
|
1072
1098
|
}
|
|
1073
|
-
//
|
|
1074
|
-
//
|
|
1075
|
-
// `session.tool`, so route them through the shared handler. Neither
|
|
1076
|
-
// commits durable tool rows mid-run, which is what `fromAgentStream`
|
|
1077
|
-
// tells the handler: synthesize a live card, because nothing else will
|
|
1078
|
-
// render this tool.
|
|
1099
|
+
// Tool activity for runs WE started (see handleToolFrame for why the
|
|
1100
|
+
// same payload also arrives as `session.tool` for runs we only watch).
|
|
1079
1101
|
if (stream === 'tool') {
|
|
1080
|
-
handleToolFrame(rec, payload
|
|
1102
|
+
handleToolFrame(rec, payload)
|
|
1081
1103
|
return
|
|
1082
1104
|
}
|
|
1083
|
-
//
|
|
1105
|
+
// Reasoning also surfaces as an `item` frame of kind `analysis` —
|
|
1106
|
+
// timing, no text.
|
|
1084
1107
|
if (stream === 'item') {
|
|
1085
1108
|
handleReasoningItemFrame(rec, payload)
|
|
1086
1109
|
return
|
|
@@ -1089,8 +1112,9 @@ async function ensureSubscribed(rec: SessionRecord): Promise<void> {
|
|
|
1089
1112
|
// this, but `agent` lifecycle frames are the authoritative signal.
|
|
1090
1113
|
if (stream !== 'lifecycle') return
|
|
1091
1114
|
const runId = payload.runId as string | undefined
|
|
1092
|
-
const data = payload.data as { phase?: string } | undefined
|
|
1115
|
+
const data = payload.data as { phase?: string; error?: unknown } | undefined
|
|
1093
1116
|
const phase = data?.phase
|
|
1117
|
+
if (phase === 'error' && runId) reportRunError(rec, runId, data?.error)
|
|
1094
1118
|
if (phase === 'start' && runId) setProcessing(rec, true, runId)
|
|
1095
1119
|
else if ((phase === 'end' || phase === 'error') && runId) {
|
|
1096
1120
|
if (rec.activeRunId === runId) {
|
|
@@ -1143,7 +1167,9 @@ export async function getOrCreateOpenClawSession(input: {
|
|
|
1143
1167
|
pendingFrames: [],
|
|
1144
1168
|
pendingUserEchoes: [],
|
|
1145
1169
|
liveTools: new Map(),
|
|
1146
|
-
liveThinking: new Map()
|
|
1170
|
+
liveThinking: new Map(),
|
|
1171
|
+
lastDurableSeq: 0,
|
|
1172
|
+
liveTurnTick: 0
|
|
1147
1173
|
}
|
|
1148
1174
|
sessions.set(k, rec)
|
|
1149
1175
|
await ensureSubscribed(rec)
|
|
@@ -1222,34 +1248,27 @@ export async function sendOpenClawMessage(input: {
|
|
|
1222
1248
|
return sendOpenClawMessageImpl({ ...input, content })
|
|
1223
1249
|
}
|
|
1224
1250
|
|
|
1225
|
-
// Apply the picker's model/effort
|
|
1226
|
-
//
|
|
1227
|
-
//
|
|
1228
|
-
// and the effort from that model's own menu (thinking.ts), so a rejection means
|
|
1229
|
-
// our learned menu is stale — we relearn it from the error and move on.
|
|
1230
|
-
//
|
|
1251
|
+
// Apply the picker's model/effort to the gateway session before the send. The
|
|
1252
|
+
// effort comes from that model's own learned menu (thinking.ts), so a rejection
|
|
1253
|
+
// means the menu is stale — relearn from the error rather than failing the send.
|
|
1231
1254
|
// `reasoningLevel` rides along because it is the gateway's gate on emitting
|
|
1232
|
-
// reasoning at all
|
|
1233
|
-
//
|
|
1234
|
-
// *can* stream thinking never does. It is patched only when the user asked to
|
|
1235
|
-
// think, so a session left at `off` keeps the gateway's default behavior.
|
|
1255
|
+
// reasoning at all; it is only set when the user asked to think, so a session
|
|
1256
|
+
// left at `off` keeps the gateway's default.
|
|
1236
1257
|
async function applySessionSettings(
|
|
1237
1258
|
rec: SessionRecord,
|
|
1238
1259
|
model: string | undefined,
|
|
1239
1260
|
effort: string | undefined
|
|
1240
1261
|
): Promise<void> {
|
|
1241
1262
|
const patch: Record<string, unknown> = {}
|
|
1242
|
-
// Patch the model only on a real change
|
|
1243
|
-
//
|
|
1244
|
-
//
|
|
1245
|
-
//
|
|
1246
|
-
//
|
|
1247
|
-
//
|
|
1248
|
-
//
|
|
1249
|
-
|
|
1250
|
-
if (model &&
|
|
1251
|
-
patch.model = model
|
|
1252
|
-
}
|
|
1263
|
+
// Patch the model only on a real change — `sessions.patch { model }` writes
|
|
1264
|
+
// agent config, so it is not free.
|
|
1265
|
+
//
|
|
1266
|
+
// Both comparisons are exact: rows echo back the provider of the ref that was
|
|
1267
|
+
// patched, and `anthropic/claude-sonnet-5` and `claude-cli/claude-sonnet-5`
|
|
1268
|
+
// are separate catalog entries a user can pick between, so a switch between
|
|
1269
|
+
// them has to reach the gateway.
|
|
1270
|
+
const moved = rec.wireModel !== undefined && rec.wireModel !== rec.requestedModel
|
|
1271
|
+
if (model && (model !== rec.requestedModel || moved)) patch.model = model
|
|
1253
1272
|
if (effort && effort !== rec.appliedThinking) patch.thinkingLevel = effort
|
|
1254
1273
|
const reasoning = effort && effort !== 'off' ? 'stream' : undefined
|
|
1255
1274
|
if (reasoning && reasoning !== rec.appliedReasoning) patch.reasoningLevel = reasoning
|
|
@@ -1273,13 +1292,13 @@ async function applySessionSettings(
|
|
|
1273
1292
|
const { thinkingLevel: _dropped, ...rest } = patch
|
|
1274
1293
|
if (Object.keys(rest).length === 0) return
|
|
1275
1294
|
await gw.rpc('sessions.patch', { key: rec.sessionKey, ...rest })
|
|
1276
|
-
if (typeof rest.model === 'string') rec.
|
|
1295
|
+
if (typeof rest.model === 'string') rec.requestedModel = rest.model
|
|
1277
1296
|
if (typeof rest.reasoningLevel === 'string') rec.appliedReasoning = rest.reasoningLevel
|
|
1278
1297
|
return
|
|
1279
1298
|
}
|
|
1280
1299
|
throw err
|
|
1281
1300
|
}
|
|
1282
|
-
if (typeof patch.model === 'string') rec.
|
|
1301
|
+
if (typeof patch.model === 'string') rec.requestedModel = patch.model
|
|
1283
1302
|
if (typeof patch.thinkingLevel === 'string') rec.appliedThinking = patch.thinkingLevel
|
|
1284
1303
|
if (typeof patch.reasoningLevel === 'string') rec.appliedReasoning = patch.reasoningLevel
|
|
1285
1304
|
}
|
|
@@ -1307,22 +1326,20 @@ async function sendOpenClawMessageImpl(input: {
|
|
|
1307
1326
|
const gw = await getGateway()
|
|
1308
1327
|
const created = await gw.rpc<{ key?: string; sessionId?: string }>('sessions.create', {
|
|
1309
1328
|
agentId: input.agentId,
|
|
1310
|
-
// Carry the model IN the create
|
|
1329
|
+
// Carry the model IN the create rather than patching it just before
|
|
1311
1330
|
// the send. `sessions.patch { model }` persists the pick into the
|
|
1312
|
-
// agent's effective `model.primary`, and that config
|
|
1313
|
-
// prepared-model-runtime generation
|
|
1314
|
-
//
|
|
1315
|
-
//
|
|
1316
|
-
//
|
|
1317
|
-
// run was dead 2.0s later with `chat.dispatch-error` — which is why the
|
|
1318
|
-
// first message of a new chat failed and the resend always worked.
|
|
1331
|
+
// agent's effective `model.primary`, and on 2026.7.2-beta.x that config
|
|
1332
|
+
// write bumps the prepared-model-runtime generation and supersedes a run
|
|
1333
|
+
// being admitted right then: `sessions.send` answers `status: 'started'`
|
|
1334
|
+
// with a runId and the run is dead 2s later with `chat.dispatch-error`,
|
|
1335
|
+
// so the first message of a new chat fails and the resend works.
|
|
1319
1336
|
//
|
|
1320
|
-
//
|
|
1321
|
-
//
|
|
1322
|
-
//
|
|
1323
|
-
// `
|
|
1324
|
-
//
|
|
1325
|
-
//
|
|
1337
|
+
// Re-tested on the pinned 2026.7.1 and the race does NOT reproduce
|
|
1338
|
+
// there. Kept regardless: it is a round-trip fewer, the model belongs to
|
|
1339
|
+
// the session from the start, and it keeps new chats working on the beta
|
|
1340
|
+
// line. Only `model` may ride along — `sessions.create` rejects
|
|
1341
|
+
// `thinkingLevel` (`unexpected property`, verified live), and effort is
|
|
1342
|
+
// session-scoped anyway, so it stays a patch.
|
|
1326
1343
|
...(input.model ? { model: input.model } : {})
|
|
1327
1344
|
})
|
|
1328
1345
|
if (created?.sessionId && created.sessionId !== input.sessionId) {
|
|
@@ -1353,7 +1370,7 @@ async function sendOpenClawMessageImpl(input: {
|
|
|
1353
1370
|
// A fresh session has no wire row to seed the cache from (that path only
|
|
1354
1371
|
// fires once a row reports `modelProvider`/`model`), so this is the only
|
|
1355
1372
|
// thing standing between the fix and the race coming straight back.
|
|
1356
|
-
if (input.isNew && input.model) rec.
|
|
1373
|
+
if (input.isNew && input.model) rec.requestedModel = input.model
|
|
1357
1374
|
} catch (err) {
|
|
1358
1375
|
const message = err instanceof Error ? err.message : 'failed to start session'
|
|
1359
1376
|
broadcast(input.workspaceId, {
|
|
@@ -1497,7 +1514,9 @@ export function createOpenClawSessionForTest(input: {
|
|
|
1497
1514
|
pendingFrames: [],
|
|
1498
1515
|
pendingUserEchoes: [],
|
|
1499
1516
|
liveTools: new Map(),
|
|
1500
|
-
liveThinking: new Map()
|
|
1517
|
+
liveThinking: new Map(),
|
|
1518
|
+
lastDurableSeq: 0,
|
|
1519
|
+
liveTurnTick: 0
|
|
1501
1520
|
}
|
|
1502
1521
|
sessions.set(recKey(input.workspaceId, input.sessionId), rec)
|
|
1503
1522
|
return rec
|