moi-computer 0.8.1-next.0 → 0.9.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/features/chat/MarkdownContent.tsx +1 -1
- package/client/features/chat/tool-group/format.ts +28 -3
- package/client/features/dev/ChatStatesPage.tsx +40 -2
- package/dist/{chunk-xzx7c9hq.js → chunk-3b3rkjet.js} +1 -1
- package/dist/{chunk-n7pga5x3.js → chunk-ty1sqbmn.js} +41 -41
- package/dist/chunk-yz6wd5vc.css +1 -0
- package/dist/index.html +1 -1
- package/lib/format.ts +20 -6
- package/package.json +5 -4
- package/server/bundler/build-applet.ts +35 -44
- package/server/cli-env.ts +2 -2
- package/server/cli.ts +39 -53
- package/server/constants.ts +8 -0
- package/server/control-client.ts +124 -0
- package/server/control.ts +2 -2
- package/server/harness/README.md +10 -6
- 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/service.ts +2 -2
- package/workspace/.claude/skills/moi-workspace/SKILL.md +6 -6
- package/dist/chunk-gny990qx.css +0 -1
- /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
|
@@ -12,6 +12,12 @@ gateways. Protocol-3 gateways (≤ 2026.5.x) reject the handshake with
|
|
|
12
12
|
are detect-and-surface only (`compat.ts` → `classifyGatewayError`), never
|
|
13
13
|
silently degraded into empty lists.
|
|
14
14
|
|
|
15
|
+
Claims here are only as good as their last capture. §6 was rewritten against
|
|
16
|
+
live 2026.7.1 traffic (`ollama-cloud/glm-5.2:cloud`, `openai/gpt-5.5`,
|
|
17
|
+
`claude-cli/claude-sonnet-5`), transcribed into `wire-replay.test.ts`. Much of
|
|
18
|
+
what this file used to say about "backend-specific" frame behavior was one
|
|
19
|
+
capture on one config generalized too far — record a run before trusting it.
|
|
20
|
+
|
|
15
21
|
## 1. What OpenClaw is
|
|
16
22
|
|
|
17
23
|
A personal multi-channel AI assistant that runs on your own machine. The
|
|
@@ -148,8 +154,8 @@ first frame must be a `connect` request. On success the response payload is
|
|
|
148
154
|
`advertise:false` (`sessions.get`, `sessions.resolve`, `sessions.usage*`) are
|
|
149
155
|
omitted yet fully callable — both live gateways omit `sessions.get` from
|
|
150
156
|
`features.methods` and still answer it (verified live against 2026.7.1 /
|
|
151
|
-
2026.6.33).
|
|
152
|
-
|
|
157
|
+
2026.6.33). Absence proves nothing, so nothing in moi gates on the list; it is
|
|
158
|
+
carried for `/status` and for diagnosing a version mismatch.
|
|
153
159
|
|
|
154
160
|
Rule for params in the other direction: gateways validate with
|
|
155
161
|
`additionalProperties: false` and hard-reject unknown fields, so never send a
|
|
@@ -233,15 +239,21 @@ sendOpenClawMessageImpl`) and marks it applied on the record so
|
|
|
233
239
|
`applySessionSettings` skips the model patch. Note the asymmetry that decides
|
|
234
240
|
what may ride along on create:
|
|
235
241
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
242
|
+
`sessions.create` takes `model` on both lines. It does **not** take
|
|
243
|
+
`thinkingLevel` on either — re-checked live on 2026.7.1, which answers
|
|
244
|
+
`invalid sessions.create params: at root: unexpected property 'thinkingLevel'`
|
|
245
|
+
(an earlier revision of this file recorded it as 2026.7-only, which was wrong).
|
|
246
|
+
Create validates with `additionalProperties: false`, so passing it would
|
|
247
|
+
hard-reject every new chat. Effort stays a patch — it is session-scoped, writes
|
|
248
|
+
no config, and so cannot supersede a run.
|
|
249
|
+
|
|
250
|
+
**Scope of the race.** Re-tested on the pinned 2026.7.1: `sessions.patch
|
|
251
|
+
{ model }` immediately followed by `sessions.send` completed normally, no
|
|
252
|
+
`chat.dispatch-error`. So this is a 2026.7.2-beta.x regression, not a property
|
|
253
|
+
of every line. moi keeps carrying the model in `sessions.create` anyway — it
|
|
254
|
+
costs nothing, the model belongs to the session from the start, and it is one
|
|
255
|
+
round-trip fewer on a new chat — but the workaround is for the NEXT line, not
|
|
256
|
+
this one.
|
|
245
257
|
|
|
246
258
|
**Thinking levels are per model, not gateway-global** (an earlier version of
|
|
247
259
|
this doc claimed otherwise and moi shipped one static list because of it).
|
|
@@ -361,15 +373,55 @@ content blocks), `deltaText` just the increment:
|
|
|
361
373
|
```
|
|
362
374
|
|
|
363
375
|
**`session.message`** — durable transcript rows, pushed as they commit. The
|
|
364
|
-
`message` carries `__openclaw` meta (see §7)
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
376
|
+
`message` carries `__openclaw` meta (see §7), including **`seq` — the row's
|
|
377
|
+
position in the transcript**, mirrored as a top-level `messageSeq`. That number
|
|
378
|
+
is the only ordering authority: the gateway serializes its broadcasts behind a
|
|
379
|
+
promise queue (`server-session-events.ts` → `createTranscriptUpdateBroadcastHandler`,
|
|
380
|
+
"Preserve transcript update order even when counting messages requires an async
|
|
381
|
+
read"), but a frame can still be lost to a dropped socket and arrive later via
|
|
382
|
+
the reconcile. moi carries `seq` onto `Turn.seq`, and `lib/format.ts`
|
|
383
|
+
`applyEvent` places a new turn by it, so a late row lands where it belongs
|
|
384
|
+
rather than after the reply it preceded.
|
|
385
|
+
|
|
386
|
+
Rows without `__openclaw.id` are transient pre-envelope echoes — skip them; the
|
|
387
|
+
durable row follows.
|
|
388
|
+
|
|
389
|
+
Two things about this stream are easy to get wrong, and both were (verified
|
|
390
|
+
live on 2026.7.1 against `ollama-cloud/glm-5.2:cloud` and `openai/gpt-5.5`,
|
|
391
|
+
frame orders transcribed into `wire-replay.test.ts`):
|
|
392
|
+
|
|
393
|
+
- **`toolResult` rows do NOT stream.** In every capture the transcript ends up
|
|
394
|
+
with `user(1) · assistant(2) · toolResult(3) · assistant(4)` and the frames
|
|
395
|
+
delivered are seq 1, 2 and 4 — never 3. A tool's output reaches us live only
|
|
396
|
+
on the tool stream below; the run-end `sessions.get` reconcile is the
|
|
397
|
+
backstop, not a nicety.
|
|
398
|
+
- **A row can grow after it streams.** When a model fans out several calls at
|
|
399
|
+
once, the assistant row is pushed as text and its `toolCall` blocks are
|
|
400
|
+
attached afterwards, with no second frame. The live view therefore has a row
|
|
401
|
+
the transcript disagrees with, which is why the reconcile refreshes rows whose
|
|
402
|
+
content changed instead of only adopting ids it has never seen.
|
|
403
|
+
|
|
404
|
+
**`session.tool` and `agent`/`tool` are the same payload, split by audience —
|
|
405
|
+
not by backend.** This is the single most important fact about this stream, and
|
|
406
|
+
believing otherwise is what produced every duplicate-card bug this harness has
|
|
407
|
+
shipped. From `server-chat.ts`: the gateway sends `agent`/`tool` to the
|
|
408
|
+
connections registered as run-scoped tool recipients — the connection that
|
|
409
|
+
issued `sessions.send` — and mirrors the identical payload as `session.tool` to
|
|
410
|
+
every _other_ session subscriber, `excludeConnIds(sessionEventSubscribers,
|
|
411
|
+
runToolRecipients)`. The two audiences are disjoint by construction.
|
|
412
|
+
|
|
413
|
+
Demonstrated directly: two connections, same gateway, same run, one sends and
|
|
414
|
+
one only subscribes.
|
|
415
|
+
|
|
416
|
+
```
|
|
417
|
+
sender : agent/tool:start, agent/tool:update, agent/tool:result
|
|
418
|
+
observer: session.tool:start, session.tool:update, session.tool:result
|
|
419
|
+
```
|
|
370
420
|
|
|
371
|
-
|
|
372
|
-
|
|
421
|
+
So moi sees `agent`/`tool` for runs it starts and `session.tool` for everything
|
|
422
|
+
else — a channel message, a cron firing, another client, or a run already in
|
|
423
|
+
flight when it attached. `session.ts` routes both into one `handleToolFrame`.
|
|
424
|
+
Frame shape (`data.phase` `start`/`update`/`result`, full output inline):
|
|
373
425
|
|
|
374
426
|
```jsonc
|
|
375
427
|
{
|
|
@@ -379,11 +431,11 @@ with the **full output inline on both lines**:
|
|
|
379
431
|
"data": {
|
|
380
432
|
"phase": "result", // start: name/toolCallId/args · update: +partialResult
|
|
381
433
|
"name": "exec",
|
|
382
|
-
"toolCallId": "
|
|
434
|
+
"toolCallId": "call_y42lj8xv",
|
|
383
435
|
"isError": false,
|
|
384
436
|
"result": {
|
|
385
|
-
"content": [{ "type": "text", "text": "
|
|
386
|
-
"details": { "status": "completed", "exitCode": 0, "durationMs":
|
|
437
|
+
"content": [{ "type": "text", "text": "hello" }],
|
|
438
|
+
"details": { "status": "completed", "exitCode": 0, "durationMs": 228, "cwd": "/…" }
|
|
387
439
|
}
|
|
388
440
|
},
|
|
389
441
|
"session": {
|
|
@@ -398,77 +450,84 @@ with the **full output inline on both lines**:
|
|
|
398
450
|
start|update|end, kind, status, name, toolCallId }`), `command_output`
|
|
399
451
|
(`{ output, phase: delta|end, exitCode?, durationMs?, cwd? }`), `lifecycle`
|
|
400
452
|
(phases `start` → `finishing` `{ stopReason, aborted }` → `end`, or `error`
|
|
401
|
-
`{ error }`).
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
`
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
453
|
+
`{ error }`, plus `fallback_step` when a model chain retries).
|
|
454
|
+
|
|
455
|
+
### Who owns a tool card
|
|
456
|
+
|
|
457
|
+
The durable owner row and the tool `start` frame race, and which wins decides
|
|
458
|
+
what renders. Measured on both providers, single call:
|
|
459
|
+
|
|
460
|
+
```
|
|
461
|
+
11891 session.message assistant seq=2 blocks=toolCall ← owner commits first
|
|
462
|
+
11895 agent/tool phase=start call_y42lj8xv ← 4ms later
|
|
463
|
+
11936 agent/tool phase=result call_y42lj8xv
|
|
464
|
+
13638 session.message assistant seq=4 blocks=text
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
and the same run with three calls fanned out of one row:
|
|
468
|
+
|
|
469
|
+
```
|
|
470
|
+
30822 session.message assistant seq=2 blocks=text ← no toolCall blocks
|
|
471
|
+
30827 agent/tool phase=start call_d88i21w1 ← the only evidence
|
|
472
|
+
30831 agent/tool phase=start call_0f2nwkab these calls exist
|
|
473
|
+
30835 agent/tool phase=start call_p7i1myi5
|
|
474
|
+
34796 session.message assistant seq=6 blocks=text
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
So the rule is a question about the run, not about the backend: **does a
|
|
478
|
+
durable row own this call yet?** If yes, that row renders the card and the
|
|
479
|
+
frames only fill in its state. If no, the frame gets a card of its own
|
|
480
|
+
(`livetool:<toolCallId>`), placed just past the last durable row ingested, and
|
|
481
|
+
it keeps that call for the rest of the session — durable rows that later grow
|
|
482
|
+
the same block suppress it (adapter `omitToolCallIds`).
|
|
483
|
+
|
|
484
|
+
Ownership is decided once, at creation: `applyEvent` upserts by id and can never
|
|
485
|
+
retract, so a card that changes identity mid-run is a duplicate on screen
|
|
486
|
+
forever. Getting this wrong is what made every single-tool run render twice.
|
|
487
|
+
|
|
488
|
+
Tool ids were stable across `start`/`update`/`result`/durable in every capture,
|
|
489
|
+
on both providers.
|
|
490
|
+
|
|
491
|
+
**Run failures are reported on three frames.** A dying run says why on `chat`
|
|
492
|
+
`state:'error'` (`errorMessage`), on `agent`/`lifecycle` `phase:'error'`
|
|
493
|
+
(`data.error`), and as a bare `sessions.changed phase:'error'` with no text at
|
|
494
|
+
all — with three wordings (the raw reason, then a wrapped "⚠️ Agent failed
|
|
495
|
+
before reply: … Logs: openclaw logs --follow"). `reportRunError` takes the
|
|
496
|
+
first with text. The error rides on `chat`, which moi otherwise ignores when
|
|
497
|
+
token streaming is off, so failures are surfaced regardless of that toggle.
|
|
437
498
|
|
|
438
499
|
**Thinking blocks: who actually emits them.** The wire shape exists and moi
|
|
439
500
|
renders it — durable rows carry `{ type: 'thinking', thinking,
|
|
440
|
-
thinkingSignature }` and `adapter.ts` maps it to a `reasoning` part. What
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
|
446
|
-
|
|
|
447
|
-
|
|
|
448
|
-
|
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
first token. Like the live tool cards it is not durable — nothing in the
|
|
471
|
-
transcript backs it, so a cold reload drops the row.
|
|
501
|
+
thinkingSignature }` and `adapter.ts` maps it to a `reasoning` part. What varies
|
|
502
|
+
is whether a model produces one at all, and this varies by MODEL and by the
|
|
503
|
+
config it runs under, not by a fixed backend taxonomy. Measured on 2026.7.1
|
|
504
|
+
with the default config:
|
|
505
|
+
|
|
506
|
+
| model | reasoning on the wire | text? |
|
|
507
|
+
| ---------------------------- | ---------------------------------------------------------- | ----- |
|
|
508
|
+
| `openai/gpt-5.5` | `agent`/`thinking` deltas, then a durable `thinking` block | YES |
|
|
509
|
+
| `ollama-cloud/glm-5.2:cloud` | nothing — the model writes its reasoning as plain text | n/a |
|
|
510
|
+
|
|
511
|
+
An earlier revision of this file claimed OpenAI models route through a codex
|
|
512
|
+
app-server that never carries reasoning text. That is not what the default
|
|
513
|
+
config does on 2026.7.1: `openai/gpt-5.5` streams the words on `agent`/`thinking`
|
|
514
|
+
and commits them durably, and no `codex_app_server.*` frame appears anywhere in
|
|
515
|
+
the capture. (`models status` reporting "openai via codex" is about which auth
|
|
516
|
+
store the credential comes from, not which runtime serves the turn.) Treat
|
|
517
|
+
"which runtime is behind this model" as a config question, not something to
|
|
518
|
+
infer from frames — and never gate rendering on the answer.
|
|
519
|
+
|
|
520
|
+
`reasoningLevel` (§5) stays set whenever the picked effort is not `off`: it is
|
|
521
|
+
the gateway's documented gate (`reasoningMode = reasoningLevel ?? 'off'`,
|
|
522
|
+
further gated on `canShowReasoning = thinkingLevel !== 'off'`), and a model that
|
|
523
|
+
can surface reasoning needs it.
|
|
524
|
+
|
|
525
|
+
Some runtimes report reasoning only as an `agent`/`item` frame of
|
|
526
|
+
`kind:'analysis'` — presence and timing, no text. `session.ts →
|
|
527
|
+
handleReasoningItemFrame` turns that into a textless `{ type: 'reasoning',
|
|
528
|
+
text: '', redacted: true, durationMs }` part, so such a run shows "Thinking" →
|
|
529
|
+
"Thought for 1.1s" instead of a silent gap. Like the live tool cards it is not
|
|
530
|
+
durable — nothing in the transcript backs it, so a cold reload drops the row.
|
|
472
531
|
|
|
473
532
|
**`task`** — subagent runs (2026.7.x; the event family is new there):
|
|
474
533
|
|
|
@@ -494,6 +553,34 @@ completed?, ts }`.
|
|
|
494
553
|
health blob (`eventLoop`, `plugins`, `channels`, `sessions`); useful for
|
|
495
554
|
liveness, ignored otherwise. `tick` is the heartbeat.
|
|
496
555
|
|
|
556
|
+
### Tool vocabulary is per runtime
|
|
557
|
+
|
|
558
|
+
One agent's tools change name and argument shape depending on which runtime
|
|
559
|
+
serves the model, and all of them arrive as `provider: 'openclaw'`. Captured on
|
|
560
|
+
2026.7.1:
|
|
561
|
+
|
|
562
|
+
| runtime | shell | edit | read |
|
|
563
|
+
| -------------------------- | ----------------------------- | --------------------------------------------- | -------------------------- |
|
|
564
|
+
| built-in loop | `exec` / `bash` `{ command }` | `edit` `{ path }` | `read` `{ path }` |
|
|
565
|
+
| codex (`extensions/codex`) | `bash` `{ command, cwd }` | `apply_patch` `{ changes: [{ path, kind }] }` | none — reads run as `bash` |
|
|
566
|
+
| `claude-cli` | `Bash` `{ command }` | `Edit` `{ file_path }` | `Read` `{ file_path }` |
|
|
567
|
+
|
|
568
|
+
So there is no Read card on a codex-backed run: the model reads by shelling out
|
|
569
|
+
(`bash -lc "sed -n '1,120p' notes.txt"`), and that is what the transcript
|
|
570
|
+
records. Nothing is being dropped.
|
|
571
|
+
|
|
572
|
+
The client's tool-card labels and briefs live in
|
|
573
|
+
`client/features/chat/tool-group/format.ts`; the OpenClaw path falls back to the
|
|
574
|
+
Claude Code vocabulary for the `claude-cli` case.
|
|
575
|
+
|
|
576
|
+
**`agent`/`item` frames are not a second source of tool cards.** They carry
|
|
577
|
+
`itemId`, `kind`, `title`, `status`, `summary`, `meta` — and **no `toolCallId`
|
|
578
|
+
and no `args`** (`AgentItemEventData` in `src/infra/agent-activity-events.ts`,
|
|
579
|
+
confirmed on the wire: every `command`/`patch` item frame arrives with
|
|
580
|
+
`toolCallId` absent). Every one of them is paired with a `tool` frame that has
|
|
581
|
+
both, a few milliseconds apart. moi renders from the `tool` frames and reads
|
|
582
|
+
item frames only for the textless `analysis` reasoning span.
|
|
583
|
+
|
|
497
584
|
### `sessions.changed`
|
|
498
585
|
|
|
499
586
|
Two flavors share the event name (both lines, verified live):
|
|
@@ -615,18 +702,33 @@ subpath import wins over rolling a minimal client.
|
|
|
615
702
|
replay, wire tap), config-path resolution, one-shot client for discovery,
|
|
616
703
|
and the last connect outcome for `/status` (`getOpenClawGatewayStatus`).
|
|
617
704
|
- `compat.ts` — protocol-4 tolerance layer: `parseHelloOk`,
|
|
618
|
-
`
|
|
619
|
-
|
|
705
|
+
`classifyGatewayError`, `messageIdempotencyKey`. Read its header before
|
|
706
|
+
sending any new param to the gateway.
|
|
620
707
|
- `thinking.ts` — per-model thinking menus learned from session rows, plus the
|
|
621
708
|
relearn-from-rejection path. The effort picker reads it (§5).
|
|
622
709
|
- `discovery.ts` — agents → workspace candidates, models catalog, transcript
|
|
623
710
|
seeds (2 round-trips: `agents.list` + `sessions.list`, then per-agent
|
|
624
711
|
`agents.files.get(IDENTITY.md)`).
|
|
625
712
|
- `session.ts` — live session records: `sessions.get` seed, `session.message`
|
|
626
|
-
ingest, `chat` → StreamPreview,
|
|
627
|
-
|
|
713
|
+
ingest, `chat` → StreamPreview, tool frames → tool cards, `sessions.patch`
|
|
714
|
+
before sends, echo rendezvous, run-end reconcile, run-error reporting.
|
|
628
715
|
- `adapter.ts` — gateway rows/messages → moi turns; `strip.ts` — mirror of
|
|
629
716
|
upstream `strip-inbound-meta` (re-diff on every bump, see its header).
|
|
717
|
+
- `wire-replay.test.ts` — the frame orders a live gateway produces, replayed
|
|
718
|
+
through the real session code. **Record a run before changing how frames are
|
|
719
|
+
interpreted** (`docs/openclaw-sandbox.md` shows how), then transcribe what it
|
|
720
|
+
shows into a scenario there. Every ordering and duplication bug this harness
|
|
721
|
+
has shipped came from reasoning about frame order in the abstract; a
|
|
722
|
+
recording is the only thing that argues back.
|
|
723
|
+
|
|
724
|
+
Two rules the modules above depend on, both learned the hard way:
|
|
725
|
+
|
|
726
|
+
1. **Never branch on "which backend is this".** The frame families that look
|
|
727
|
+
backend-specific are audience-specific (§6), and which runtime serves a
|
|
728
|
+
model is a config choice. Ask about the state you actually have — does a
|
|
729
|
+
durable row own this call? — not about who is on the other end.
|
|
730
|
+
2. **A broadcast turn can be upserted but never retracted.** Any id a turn is
|
|
731
|
+
published under is permanent. Decide identity once, at creation.
|
|
630
732
|
|
|
631
733
|
## 12. Commands worth knowing
|
|
632
734
|
|
|
@@ -1,21 +1,13 @@
|
|
|
1
1
|
// Map OpenClaw gateway shapes into our agent-agnostic display format.
|
|
2
2
|
//
|
|
3
|
-
// OpenClaw stores one
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
// inline on the assistant turn,
|
|
9
|
-
// - no separate turn for toolResult rows — results are folded into the
|
|
10
|
-
// assistant's matching tool-call part so the UI shows them as expandable
|
|
11
|
-
// output under the call.
|
|
3
|
+
// OpenClaw stores one message per role-turn: `user` (the prompt, with AI-facing
|
|
4
|
+
// envelopes prepended — see `strip.ts`), `assistant` (text/thinking/toolCall
|
|
5
|
+
// blocks plus model metadata), and `toolResult` (one per executed call, keyed
|
|
6
|
+
// by `toolCallId`). Each user/assistant message becomes one Turn; toolResult
|
|
7
|
+
// rows get no turn of their own — they fold into the matching tool-call part.
|
|
12
8
|
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
// and tests.
|
|
16
|
-
// - `messageToTurnLive(msg, sessionKey, idx, results)` — incremental path used
|
|
17
|
-
// by the live session adapter (`openclaw-session.ts`) when a single
|
|
18
|
-
// `session.message` frame arrives.
|
|
9
|
+
// `toStreamEvents` is the cold path (REST replay); `messageToTurn` is the
|
|
10
|
+
// per-frame path the live session uses.
|
|
19
11
|
import type { Part, StreamEvent, ToolCall, ToolState, Turn, TurnMeta } from '@/lib/format'
|
|
20
12
|
import type { SessionInfo } from '@/lib/types'
|
|
21
13
|
|
|
@@ -79,15 +71,12 @@ export type ToolResultInfo = {
|
|
|
79
71
|
running?: boolean
|
|
80
72
|
}
|
|
81
73
|
|
|
82
|
-
// Pull a readable `output` string out of a `toolResult` message.
|
|
83
|
-
//
|
|
84
|
-
//
|
|
85
|
-
//
|
|
86
|
-
//
|
|
87
|
-
//
|
|
88
|
-
// So recurse: text/image blocks resolve directly, any other block that
|
|
89
|
-
// carries its own `content` array or `text`/`output` string is unwrapped one
|
|
90
|
-
// level, and only a truly opaque block falls back to `[type]`.
|
|
74
|
+
// Pull a readable `output` string out of a `toolResult` message. Rows are flat
|
|
75
|
+
// in practice (`content: [{ type: 'text', text: 'hello' }]`), but upstream
|
|
76
|
+
// types these blocks as an open `Record<string, unknown>` and says outright
|
|
77
|
+
// that provider SDKs spell them differently (`src/chat/tool-content.ts`), so a
|
|
78
|
+
// block carrying its own `content`/`text`/`output` is unwrapped one level
|
|
79
|
+
// rather than rendered as a bare `[toolResult]` placeholder.
|
|
91
80
|
export function flattenToolResultContent(content: OpenClawMessage['content'], depth = 0): string {
|
|
92
81
|
if (typeof content === 'string') return content
|
|
93
82
|
if (!Array.isArray(content)) return ''
|
|
@@ -146,7 +135,8 @@ function collectToolResults(messages: OpenClawMessage[]): Map<string, ToolResult
|
|
|
146
135
|
function blockToPart(
|
|
147
136
|
block: OpenClawContentBlock,
|
|
148
137
|
role: OpenClawMessage['role'],
|
|
149
|
-
results: Map<string, ToolResultInfo
|
|
138
|
+
results: Map<string, ToolResultInfo>,
|
|
139
|
+
omitToolCallIds?: ReadonlySet<string>
|
|
150
140
|
): Part | null {
|
|
151
141
|
switch (block.type) {
|
|
152
142
|
case 'text': {
|
|
@@ -158,39 +148,21 @@ function blockToPart(
|
|
|
158
148
|
if (!text) return null
|
|
159
149
|
return { type: 'text', text }
|
|
160
150
|
}
|
|
161
|
-
case 'thinking':
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
// never silently vanishes.
|
|
167
|
-
const b = block as {
|
|
168
|
-
thinking?: unknown
|
|
169
|
-
reasoning?: unknown
|
|
170
|
-
text?: unknown
|
|
171
|
-
thinkingSignature?: unknown
|
|
172
|
-
signature?: unknown
|
|
173
|
-
}
|
|
174
|
-
const text =
|
|
175
|
-
(typeof b.thinking === 'string' && b.thinking) ||
|
|
176
|
-
(typeof b.reasoning === 'string' && b.reasoning) ||
|
|
177
|
-
(typeof b.text === 'string' && b.text) ||
|
|
178
|
-
''
|
|
179
|
-
if (!text) return null
|
|
180
|
-
const sig =
|
|
181
|
-
(typeof b.thinkingSignature === 'string' && b.thinkingSignature) ||
|
|
182
|
-
(typeof b.signature === 'string' && b.signature) ||
|
|
183
|
-
undefined
|
|
184
|
-
return {
|
|
185
|
-
type: 'reasoning',
|
|
186
|
-
text,
|
|
187
|
-
...(sig ? { signature: sig } : {})
|
|
188
|
-
}
|
|
151
|
+
case 'thinking': {
|
|
152
|
+
const b = block as { thinking?: unknown; thinkingSignature?: unknown }
|
|
153
|
+
if (typeof b.thinking !== 'string' || !b.thinking) return null
|
|
154
|
+
const sig = typeof b.thinkingSignature === 'string' ? b.thinkingSignature : undefined
|
|
155
|
+
return { type: 'reasoning', text: b.thinking, ...(sig ? { signature: sig } : {}) }
|
|
189
156
|
}
|
|
190
157
|
case 'toolCall': {
|
|
191
158
|
const id = (block as { id?: unknown }).id
|
|
192
159
|
const name = (block as { name?: unknown }).name
|
|
193
160
|
if (typeof id !== 'string' || typeof name !== 'string') return null
|
|
161
|
+
// This call is already on screen as its own live card (the live session
|
|
162
|
+
// rendered it before this row carried the block). Rendering it here too
|
|
163
|
+
// would show the same call twice, and a broadcast card can't be
|
|
164
|
+
// retracted — so the live card keeps ownership for the session's life.
|
|
165
|
+
if (omitToolCallIds?.has(id)) return null
|
|
194
166
|
const result = results.get(id)
|
|
195
167
|
let state: ToolState = 'pending'
|
|
196
168
|
if (result) state = result.running ? 'running' : result.isError ? 'error' : 'success'
|
|
@@ -243,7 +215,8 @@ export function messageToTurn(
|
|
|
243
215
|
msg: OpenClawMessage,
|
|
244
216
|
sessionKey: string,
|
|
245
217
|
idx: number,
|
|
246
|
-
results: Map<string, ToolResultInfo
|
|
218
|
+
results: Map<string, ToolResultInfo>,
|
|
219
|
+
omitToolCallIds?: ReadonlySet<string>
|
|
247
220
|
): Turn | null {
|
|
248
221
|
if (msg.role !== 'user' && msg.role !== 'assistant') return null
|
|
249
222
|
const blocks: OpenClawContentBlock[] = Array.isArray(msg.content)
|
|
@@ -252,7 +225,7 @@ export function messageToTurn(
|
|
|
252
225
|
? [{ type: 'text', text: msg.content }]
|
|
253
226
|
: []
|
|
254
227
|
const parts = blocks
|
|
255
|
-
.map(b => blockToPart(b, msg.role, results))
|
|
228
|
+
.map(b => blockToPart(b, msg.role, results, omitToolCallIds))
|
|
256
229
|
.filter((p): p is Part => p !== null)
|
|
257
230
|
if (parts.length === 0) return null
|
|
258
231
|
const ocId = msg.__openclaw?.id
|
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
// `additionalProperties: false` and reject unknown fields outright — never
|
|
12
12
|
// send a param that only newer schemas know without gating on `GatewayInfo`.
|
|
13
13
|
|
|
14
|
-
// What the gateway announced in `hello-ok`. `methods`/`events` are advisory
|
|
15
|
-
// 2026.6.33 answers `sessions.get` while omitting it from
|
|
16
|
-
//
|
|
17
|
-
//
|
|
14
|
+
// What the gateway announced in `hello-ok`. `methods`/`events` are advisory
|
|
15
|
+
// and UNDER-REPORT: 2026.6.33 answers `sessions.get` while omitting it from
|
|
16
|
+
// `features.methods`. Absence proves nothing, so nothing gates on this — the
|
|
17
|
+
// sets are carried for `/status` and for debugging a version mismatch.
|
|
18
18
|
export type GatewayInfo = {
|
|
19
19
|
protocol?: number
|
|
20
20
|
serverVersion?: string
|
|
@@ -40,10 +40,6 @@ export function parseHelloOk(hello: unknown): GatewayInfo {
|
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
export function advertisesMethod(info: GatewayInfo | null, method: string): boolean {
|
|
44
|
-
return info?.methods.has(method) ?? false
|
|
45
|
-
}
|
|
46
|
-
|
|
47
43
|
export type GatewayFailureKind = 'protocol-mismatch' | 'auth' | 'unreachable' | 'unknown'
|
|
48
44
|
|
|
49
45
|
export type GatewayFailure = {
|