Repository navigation
Commit 0d68ce2
feat(chat): a Continue button for a stopped ask turn — spec resume field and data-turn-end part, plugin-chatbot UI (#38698)
<!-- claude-projects-attribution: {"github_login":"os-warren"} -->
_Requested by **Warren** · [project
thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ88TCniMD3icYaF2RmC5L5B5)_
Part of #38609
Clause-②: yes (widening)
Metadata-protocol: added
Skills-docs: none — the added keys are the AI chat route's wire
(`resume`) and its stream part and stored message field (`turnEnd`),
written by the AI service and read by the console chat; no metadata
author writes them and no published skill teaches the chat wire
## 维护者速读
-
用户能看到什么变化:在控制台的问答里,回答因时间、额度或轮数触顶而停下、且服务端表示可以续跑时,最后一条回答下出现「继续查」按钮并显示还能继续几次;点了不新增提问气泡,答案接着写进同一轮,刷新页面后按钮仍在。
- 为什么做:这是「继续查」的协议与界面一半,服务端续跑那一半在云端卡(AI 服务按同一轮重建并续跑)上;协议先落,云端那一半才能接。
- 出错会怎样:服务端没发「回合结束」信息之前界面什么都不画,现有对话不受影响;全是新增的可选字段,撤回即删。
- 要你做什么:无(契约审核由席位安排)。
## What changes
**Spec (`@objectstack/spec`) — three additions, all closed shapes:**
- `TurnEndSchema` + `TURN_END_PART_TYPE = 'data-turn-end'` in a new
`packages/spec/src/ai/turn-end.zod.ts` (modelled on
`draft-review.zod.ts`): `{ reason, wrapUp, resumable, resumesLeft,
turnId }`. `reason` is a non-empty string, not an enum: the producer's
vocabulary includes every turn-refusal kind and grows with it, and the
chat decides nothing from it. `resumable` is the server's verdict alone.
- `AiChatRequestSchema.resume`: optional `{ turnId }` (closed, `turnId`
non-empty). Its text says a resume names its turn itself (the top-level
`turnId` is not read on a resume, and `turnId`'s own description says
so) and that the resume stream's `start` chunk carries the request's
`messageId` or none.
- `AiConversationMessageSchema.turnEnd`: optional, nullable
`TurnEndSchema`, on the turn's last message, so a reload knows the turn
end too.
- Regenerated: `api-surface`, `export-origins`, `declaration-map`,
references docs, strictness ledger counts, authorable-surface and
json-schema manifest projections (`check:generated --fix`, only the five
it proved stale).
**UI (`@object-ui/plugin-chatbot`, `@object-ui/app-shell`,
`@object-ui/i18n`):**
- `mapMessages.extractTurnEnd` reads the newest `data-turn-end` part
through `TurnEndSchema` onto `ChatbotEnhancedMessage.turnEnd`; a refused
part is no turn end.
- New `chat/ContinueTurnButton.tsx` (the control) and
`chat/resumableTurn.ts` (`resumableTurnOf`, where it is drawn).
`ChatbotEnhanced` takes `onResumeTurn(turnId)` and draws Continue under
the conversation's **last** answer only when its turn end is `resumable`
with `resumesLeft > 0`, nothing streams, and the view is not read-only.
A message sent afterwards makes the answer no longer last, so the
control goes.
- New `resumeTurn.ts`; `useObjectChat` returns `resumeTurn(turnId)` in
API mode: the chat runtime's `sendMessage(undefined, { body: { resume: {
turnId } } })` sends the conversation as it stands (no user message, no
bubble) and streams into the last assistant message, sending the
answer's id as `messageId`. `withTurnId` stamps the turn id on every
request except a resume. The runtime's no-message send addresses the
newest answer holding an `approval-responded` tool part rather than the
last answer, and offers no public way to name the target, so the hook
offers `resumeTurn` only while that send addresses the last answer
(`resumeAddressesLastAnswer`); otherwise no Continue is drawn.
- The turn end is a kept data part (`STORED_ANSWER_DATA_PARTS.turnEnd`;
write in `storedAnswerParts`, read in `storedAnswerData`), so it
survives API mode's store rebuild and the message cache; `toUIMessages`
writes a stored `turnEnd` field back as that part, so server history and
cache are read by one reader.
- Console wiring: `ChatPane` passes `resumeTurn`; the schema renderer
passes it in both chat surfaces.
- `chatbot.continueTurn.*` strings in all eleven locales (zh-Hant
regenerated from zh-Hans by its generator); README and the frontend docs
page document the control.
**Where the stream comes from.** The console's ask chat is served by the
cloud AI service (agent route + stream encoder), not by this repository.
Until it sends `data-turn-end` and accepts `resume`, nothing is drawn
and no resume is sent. That half — persist `turnEnd`, emit the part,
accept and execute `resume`, and the ADR-0013 D3 amendment — is
objectstack-ai/cloud#5239. This PR is therefore `Part of`: the card's
done-when also needs the spec released into the pin cloud consumes and a
check against cloud#5239's endpoint.
## Why
Maintainer-directed (filing gate ③ on the card): a turn that stops on a
limit today can only be continued by typing, which starts a new turn
that cannot see the tool results the stopped one already read. A
server-side resume of the same turn needs the request field, an
end-of-turn signal the UI can read live and after a reload, and a
button.
## Tests
- `packages/spec/src/ai/turn-end.test.ts` — the part name; admits a
resumable wrap-up and a finished answer; refuses an unknown key
(`unrecognized_keys`), each missing key by path, a negative or
fractional count, an empty reason or turn id; `resume` admitted and
kept, refused when empty, missing `turnId` or carrying an unknown key;
`turnEnd` admitted, null or absent, and refused through the same closed
shape.
- `ui/packages/plugin-chatbot/src/__tests__/continueTurn-38609.test.tsx`
— the kept-part entry equals `TURN_END_PART_TYPE`; lift / refuse /
newest wins / stored-part round trip; where Continue is drawn and every
hide case (not resumable, none left, streaming, a later user or
assistant message, loading, read-only, no handler); the request body
(`resume` and `messageId`, no top-level `turnId`; CONTROL: without
`resume` it is stamped); and three tests through the **real** chat
runtime with a stubbed stream: a restored thread draws Continue, the
click sends `resume: { turnId }` with exactly the two existing messages,
`messageId: 'a1'` and no `turnId`, the rest of the answer lands in the
same bubble with no new user bubble, and the new turn end hides the
control; a `start` naming the request's `messageId` keeps one answer
bubble; CONTROL: a `start` naming another id draws a second answer; the
resume-target rule (last answer; an earlier answered approval wins; the
last answer holding one is still last); a restored thread with an
earlier `approval-responded` part draws no Continue and sends nothing
(CONTROL: with that approval already run, Continue resumes `a1`).
-
`ui/packages/app-shell/src/console/ai/__tests__/AiChatPage.turnEndReload-38609.test.tsx`
— server history (stored `turnEnd` field) and cache fallback both
restore Continue; CONTROL: a refused, null or absent stored turn end
offers nothing.
- Ablation (each reverted after): dropping the `resume` body turns the
request pin and the runtime test red (2 failed); not writing the stored
`turnEnd` back in `toUIMessages` turns the server-history pin red (1
failed); stamping `turnId` on a resume again turns the request pin and
the runtime test red (2 failed); offering `resumeTurn` whatever the
target turns the earlier-approval pin red (1 failed).
**Local gates:** the derived family run (`dispatch-gates.mjs
--commands`, 119 commands) ran beside the first CI run; its readings,
with the head they were taken on, are in the os-dev report comment on
#38609. Spec package: `pnpm --filter @objectstack/spec test` 914 files /
28919 tests passed, `typecheck` exit 0. Spec `check:generated`: all 14
artifacts up to date. UI `type-check` (plugin-chatbot, i18n, app-shell):
exit 0. UI tests (plugin-chatbot, i18n, app-shell `console/ai` +
`hooks`): 337 files, 1 failure (zh-Hant not regenerated) fixed by
running its generator, then green.
## Acceptance notes
- Surface beyond the claim's list: the `chatbot.continueTurn.*` keys in
every `ui/packages/i18n` locale (key-parity test), one prop line in
`ChatPane.tsx` and `ui/packages/plugin-chatbot/README.md` are admitted
by claim amendment 7269233060; the
`content/docs/frontend/plugins/plugin-chatbot.mdx` section
(`ui/AGENTS.md` commandment 2) is admitted by the seat's further
amendment after the contract review.
- `Clause-②:` is written `yes (widening)` (the claim's `yes`, with the
arm its own text states: additive, optional).
- `Metadata-protocol:` is `added`, not the claim's `none`: measured from
the diff, the change moves the `authorable-surface` shards
(`ai/TurnEnd:*`, `api/AiChatRequest:resume`,
`api/AiConversationMessage:turnEnd`), and `check-changeset-no-major`
reads that as a key entered. `@objectstack/spec` is graded `minor`
accordingly; the UI packages stay `patch`.
- `packages/spec/llms.txt` counts the new schema module (ai 18, 233 in
all) with a Turn End row, as `check:llms-txt` requires.
- No browser E2E against a live stack: the console's chat is served by
the cloud AI service, which neither emits `data-turn-end` nor accepts
`resume` before cloud#5239. The runtime-level test above drives the real
AI SDK chat with a stubbed stream instead; the card's "verified against
cloud#5239's resume endpoint" stays open.
- `extractTurnEnd` is not re-exported from the package root (only the
chat itself reads the part).
## For cloud#5239
Not fixed here: they belong to the server half, which picks them up from
this list (contract review comment 7271059472 on this PR).
- `AIConversationMessage` in `packages/spec/src/contracts/ai-service.ts`
names `AiConversationMessageSchema` as its wire shape but carries
`turnId` only, and `addMessage` has no way to write a turn end. How the
turn end is stored is the server half's; widen the contract there, so
the spec is not released twice for one feature.
- A turn replayed by its `turnId` (ADR-0013 D1, nothing ran) sends no
turn end, so a Retry of a wrapped-up answer loses Continue until a
reload restores it from the stored field. Declared behaviour and a
producer choice.
- A retried resume has no idempotency key: nothing in `resume: { turnId
}` tells a network retry of one press from the next press, so one press
can spend two resumes. The shape is closed, so any such key is a later
widening.
## Verification
Two minutes: `pnpm --dir ui exec vitest run
packages/plugin-chatbot/src/__tests__/continueTurn-38609.test.tsx` — 19
passed, including the runtime tests that click Continue, read the sent
body and count the answer bubbles.
Read first (by risk):
1. `ui/packages/plugin-chatbot/src/useObjectChat.ts` `resumeTurn` +
`resumeTurn.ts` — relies on the AI SDK sending the current messages and
streaming into the last assistant message when `sendMessage` gets no
message (ai 7.0.118, `AbstractChat.sendMessage` / `makeRequest`).
2. `packages/spec/src/api/protocol.zod.ts` — the two new keys on
published wire schemas.
3. `ui/packages/plugin-chatbot/src/chat/resumableTurn.ts`
`resumableTurnOf` — the show/hide rule.
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; `pnpm lint` passes (CI).
- [x] 4. One issue, one branch off an up-to-date `main`, one pull
request.
- [x] 5. A change that publishes carries a changeset, and both
declaration lines are filled in here and in the changeset.
- [x] 6. `packages/spec` touched: its generated artifacts are
regenerated and committed.
- [x] 7. No hand edits to `content/docs/references/`,
`packages/*/CHANGELOG.md` or `content/docs/releases/`.
- [x] 8. Title, body and comments are in English.
- [x] The *Before Submitting* list in CONTRIBUTING.md is done.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01JQwxbYmVBS2cvoZWKGbx92
---
_Generated by [Claude
Code](https://claude.ai/code/session_01JQwxbYmVBS2cvoZWKGbx92)_
<!-- signed: repo:objectstack@os-warren · os-warren ·
session_01JQwxbYmVBS2cvoZWKGbx92 -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent a1ef710 commit 0d68ce2
48 files changed
Lines changed: 1225 additions & 30 deletions
File tree
- .changeset
- content/docs
- frontend/plugins
- references
- ai
- docs/audits/2026-07-unknown-key-strictness-ledger.counts
- packages/spec
- api-surface
- authorable-surface
- declaration-map
- docs/references/api
- export-origins
- json-schema.manifest
- src
- ai
- api
- ui/packages
- app-shell/src
- console/ai
- __tests__
- hooks
- i18n/src/locales
- plugin-chatbot
- src
- __tests__
- chat
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
660 | 660 | | |
661 | 661 | | |
662 | 662 | | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
663 | 708 | | |
664 | 709 | | |
665 | 710 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
| 45 | + | |
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| 67 | + | |
67 | 68 | | |
68 | 69 | | |
69 | 70 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
290 | 290 | | |
291 | 291 | | |
292 | 292 | | |
| 293 | + | |
293 | 294 | | |
294 | 295 | | |
295 | 296 | | |
| |||
309 | 310 | | |
310 | 311 | | |
311 | 312 | | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
312 | 316 | | |
313 | 317 | | |
314 | 318 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
575 | 575 | | |
576 | 576 | | |
577 | 577 | | |
578 | | - | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
579 | 584 | | |
580 | 585 | | |
0 commit comments