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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .changeset/38983-chat-review-card-publish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
'@objectstack/spec': minor
'@object-ui/plugin-chatbot': patch
'@object-ui/app-shell': patch
'@object-ui/i18n': patch
---

feat(console): the chat's draft review card publishes a draft, pinned to the version the turn saved

Clause-②: yes (widening)
Metadata-protocol: added

Widened: `DraftReviewItemSchema` (`@objectstack/spec/ai`, the row of the `data-draft-review` stream part) gains the optional `version`, the draft's version token as the turn's last save of it wrote it (the save receipt's `version`). `DraftReviewCardProps` and `ChatbotEnhancedProps` gain the optional `onPublishDraft`, and `@object-ui/plugin-chatbot` exports the type `DraftReviewPublishResult`; the card's Publish strings are added to every shipped locale pack.

The contract that nothing is published from the chat changes. The review card under an ask turn's answer now carries a Publish button per draft: one click publishes that one draft as the signed-in person, through the item's own publish (`POST /meta/:type/:name/publish?package=`), with the row's `version` sent as the body's `draftVersion`. A draft changed after the turn saved it is refused `409 METADATA_CONFLICT`, nothing is published, and the row says the draft changed since the turn. Any other refusal (a member who may not publish gets `PERMISSION_DENIED`) is shown on the row with the platform's code and sentence. Publish is offered only on a row that carries a `version` and whose verdict is `publishable`; a refused, withheld or unversioned row shows it disabled with the reason and is published in Studio through the review links, as before. The agent is given no publish: the click is always the person's. Nothing is discarded from the chat.

`verdictWithheld`'s description now also covers a draft the door left unjudged under a bound such as `MAX_RECORDS_EXCEEDED`, not only a verdict the person may not read; its shape is unchanged.

A host that fills the `data-draft-review` part must state each row's `version` for the button to be enabled; a part without it draws the card as before, with Publish disabled.

Why the protocol line reads added: `DraftReviewItem` is on the authorable surface the ratchet records (`packages/spec/authorable-surface/ai.json`), and `version` is a key that enters it. Nothing a released version accepts is refused now.
17 changes: 14 additions & 3 deletions content/docs/frontend/plugins/plugin-chatbot.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -627,17 +627,20 @@ itself; a part the schema refuses draws nothing.

```tsx
import { DraftReviewCard } from '@object-ui/plugin-chatbot';
import type { DraftReviewListParsed } from '@objectstack/spec/ai';
import type { DraftReviewPublishResult } from '@object-ui/plugin-chatbot';
import type { DraftReviewItemParsed, DraftReviewListParsed } from '@objectstack/spec/ai';

export function TurnDrafts({ review, navigate }: {
export function TurnDrafts({ review, navigate, publish }: {
review: DraftReviewListParsed;
navigate: (path: string) => void;
publish: (draft: DraftReviewItemParsed) => Promise<DraftReviewPublishResult>;
}) {
return (
<DraftReviewCard
review={review}
onOpenReviewLink={navigate} // in-app navigation keeps the live conversation
reviewLinkHref={(path) => `/_console${path}`} // the router's basename, for a new tab
onPublishDraft={publish} // one draft, as the person, pinned to its version
/>
);
}
Expand All @@ -649,7 +652,15 @@ export function TurnDrafts({ review, navigate }: {
by the save rather than at the turn's end says "checked when saved".
- Rows are grouped by package, in save order; each package has one "Review and
publish" link to its Changes drawer. `omitted` shows as "+N more".
- The card has no publish and no discard control: a person publishes or
- With `onPublishDraft`, each row has a Publish button that publishes that one
draft as the signed-in person. The host sends the item's own publish with
the row's `version` as the body's `draftVersion`, so a draft changed since
the turn is refused (`409 METADATA_CONFLICT`) and nothing is published. The
button is enabled only on a row with a `version` and a publishable verdict;
any other row shows it disabled with the reason. The row keeps the result:
"Published", "Changed since this turn", or the platform's refusal with its
code. The Console's chat pane passes a host that does exactly this.
Without the prop the card has no publish control. It never discards: a person
discards in Studio, through the links.
- A plain click on a link calls `onOpenReviewLink` with the Console path; a
modified or middle click keeps the browser's own behaviour, on the href
Expand Down
38 changes: 27 additions & 11 deletions content/docs/references/ai/draft-review.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ draws them in a card under the answer.
draft — `publishable` is "no refusal", `refusals` are what a publish would
refuse it on and `advisories` are findings that do not block it — read as
the person who asked. `null` when no verdict was read: `verdictWithheld`
then says why the person may not read one, or `verdictError` that reading
it failed. Both carry the door's `{ code, message, status }`.
then says why the door gave none (the person may not read one, or the door
left the draft unjudged under a bound such as `MAX_RECORDS_EXCEEDED`; the
`message` says which), or `verdictError` that reading it failed. Both carry
the door's `{ code, message, status }`.
- `verdictRead` says when the verdict was read: `turn-end`, after the turn's
last save, or `save`, by the save that wrote this draft (a later save in
the same turn can change it).
Expand All @@ -42,13 +44,25 @@ draws them in a card under the answer.
`studioItemReviewLink` in `@objectstack/types`): `changes`, the package's
Changes drawer, where it is published, and `item`, the draft's own review.
Both are Console paths, so each starts with one `/`.

## What the card does not do

Nothing is published or discarded from the chat: a person publishes in
Studio, through the review routes, as for any draft. The part is drawn live
only: it is not stored with the message, so a conversation reloaded from
history shows no card.
- `version` is the draft's version token as the turn's last save of it
wrote it (the save receipt's `version`), when the producer states one.

## What the card publishes

A person may publish a listed draft from the chat, one draft per click, as
the person signed in: the card sends that draft's own publish
(`POST /meta/:type/:name/publish?package=`) with `version` as the body's
`draftVersion` (`PublishMetaItemRequestSchema.draftVersion`). The pin is
what makes the click mean "publish what the card shows": a draft changed
after the turn saved it is refused `409 METADATA_CONFLICT` and nothing is
published. So the card offers Publish only on a row that carries a
`version` and whose `verdict` is `publishable`; any other row is published
in Studio, through the review routes, as for any draft. The agent is given
no publish: the click is always the person's. Nothing is discarded from the
chat.

The part is drawn live only: it is not stored with the message, so a
conversation reloaded from history shows no card.

<Callout type="info">
**Source:** `packages/spec/src/ai/draft-review.zod.ts`
Expand Down Expand Up @@ -77,10 +91,11 @@ const result = DraftReviewItemSchema.parse(data);
| **package** | `string` | ✅ | The package the draft was saved into |
| **label** | `string` | optional | The draft's display label, when it has one |
| **verdict** | `{ publishable: boolean; refusals: object[]; advisories: object[] } \| null` | ✅ | The door's `list_drafts` verdict, read as the person who asked; `null` when none was read (see `verdictWithheld` and `verdictError`) |
| **verdictWithheld** | `{ code: string; message: string; status: integer }` | optional | Why the person may not read a verdict, when `verdict` is `null` for that reason |
| **verdictWithheld** | `{ code: string; message: string; status: integer }` | optional | Why the door gave no verdict, when `verdict` is `null` for that reason: the person may not read it, or the door left the draft unjudged under a bound such as `MAX_RECORDS_EXCEEDED`; the `message` says which |
| **verdictError** | `{ code: string; message: string; status: integer }` | optional | That reading the verdict failed, when `verdict` is `null` for that reason |
| **verdictRead** | `Enum<'turn-end' \| 'save'>` | ✅ | When the verdict was read: `turn-end`, after the turn's last save, or `save`, by the save that wrote this draft |
| **review** | `{ changes: string; item: string }` | ✅ | |
| **version** | `string` | optional | The draft's version token as the turn's last save of it wrote it (the save receipt's `version`). The card's Publish sends it as the publish body's `draftVersion`, so a draft changed since is refused 409 `METADATA_CONFLICT`, never published; absent, the row offers no Publish in the chat |

### Nested Shape: `DraftReviewItem.verdict`

Expand Down Expand Up @@ -146,10 +161,11 @@ const result = DraftReviewItemSchema.parse(data);
| **package** | `string` | ✅ | The package the draft was saved into |
| **label** | `string` | optional | The draft's display label, when it has one |
| **verdict** | `{ publishable: boolean; refusals: object[]; advisories: object[] } \| null` | ✅ | The door's `list_drafts` verdict, read as the person who asked; `null` when none was read (see `verdictWithheld` and `verdictError`) |
| **verdictWithheld** | `{ code: string; message: string; status: integer }` | optional | Why the person may not read a verdict, when `verdict` is `null` for that reason |
| **verdictWithheld** | `{ code: string; message: string; status: integer }` | optional | Why the door gave no verdict, when `verdict` is `null` for that reason: the person may not read it, or the door left the draft unjudged under a bound such as `MAX_RECORDS_EXCEEDED`; the `message` says which |
| **verdictError** | `{ code: string; message: string; status: integer }` | optional | That reading the verdict failed, when `verdict` is `null` for that reason |
| **verdictRead** | `Enum<'turn-end' \| 'save'>` | ✅ | When the verdict was read: `turn-end`, after the turn's last save, or `save`, by the save that wrote this draft |
| **review** | `{ changes: string; item: string }` | ✅ | |
| **version** | `string` | optional | The draft's version token as the turn's last save of it wrote it (the save receipt's `version`). The card's Publish sends it as the publish body's `draftVersion`, so a draft changed since is refused 409 `METADATA_CONFLICT`, never published; absent, the row offers no Publish in the chat |


---
Expand Down
1 change: 1 addition & 0 deletions packages/spec/authorable-surface/ai.json
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@
"ai/DraftReviewItem:verdictError",
"ai/DraftReviewItem:verdictRead",
"ai/DraftReviewItem:verdictWithheld",
"ai/DraftReviewItem:version",
"ai/DraftReviewLinks:changes",
"ai/DraftReviewLinks:item",
"ai/DraftReviewList:drafts",
Expand Down
10 changes: 10 additions & 0 deletions packages/spec/src/ai/draft-review.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,16 @@ describe('DraftReviewItemSchema', () => {
expect(firstIssue(DraftReviewItemSchema, { ...ROW, [key]: '' })).toMatchObject({ code: 'too_small', path: [key] });
}
});

it('keeps the draft version the card pins its Publish to, optional, and refuses an empty or non-string one', () => {
const parsed = DraftReviewItemSchema.safeParse({ ...ROW, version: 'v-7f3a' });
expect(parsed.success).toBe(true);
expect(parsed.data!.version).toBe('v-7f3a');
// Absent stays absent: a row with no version is still a row (the card offers no Publish on it).
expect(DraftReviewItemSchema.safeParse(ROW).data).not.toHaveProperty('version');
expect(firstIssue(DraftReviewItemSchema, { ...ROW, version: '' })).toMatchObject({ code: 'too_small', path: ['version'] });
expect(firstIssue(DraftReviewItemSchema, { ...ROW, version: 7 })).toMatchObject({ code: 'invalid_type', path: ['version'] });
});
});

describe('DraftReviewListSchema and the data part', () => {
Expand Down
38 changes: 30 additions & 8 deletions packages/spec/src/ai/draft-review.zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ import { strictObject } from '../shared/strict-object';
* draft — `publishable` is "no refusal", `refusals` are what a publish would
* refuse it on and `advisories` are findings that do not block it — read as
* the person who asked. `null` when no verdict was read: `verdictWithheld`
* then says why the person may not read one, or `verdictError` that reading
* it failed. Both carry the door's `{ code, message, status }`.
* then says why the door gave none (the person may not read one, or the door
* left the draft unjudged under a bound such as `MAX_RECORDS_EXCEEDED`; the
* `message` says which), or `verdictError` that reading it failed. Both carry
* the door's `{ code, message, status }`.
* - `verdictRead` says when the verdict was read: `turn-end`, after the turn's
* last save, or `save`, by the save that wrote this draft (a later save in
* the same turn can change it).
Expand All @@ -42,13 +44,25 @@ import { strictObject } from '../shared/strict-object';
* `studioItemReviewLink` in `@objectstack/types`): `changes`, the package's
* Changes drawer, where it is published, and `item`, the draft's own review.
* Both are Console paths, so each starts with one `/`.
* - `version` is the draft's version token as the turn's last save of it
* wrote it (the save receipt's `version`), when the producer states one.
*
* ## What the card does not do
* ## What the card publishes
*
* Nothing is published or discarded from the chat: a person publishes in
* Studio, through the review routes, as for any draft. The part is drawn live
* only: it is not stored with the message, so a conversation reloaded from
* history shows no card.
* A person may publish a listed draft from the chat, one draft per click, as
* the person signed in: the card sends that draft's own publish
* (`POST /meta/:type/:name/publish?package=`) with `version` as the body's
* `draftVersion` (`PublishMetaItemRequestSchema.draftVersion`). The pin is
* what makes the click mean "publish what the card shows": a draft changed
* after the turn saved it is refused `409 METADATA_CONFLICT` and nothing is
* published. So the card offers Publish only on a row that carries a
* `version` and whose `verdict` is `publishable`; any other row is published
* in Studio, through the review routes, as for any draft. The agent is given
* no publish: the click is always the person's. Nothing is discarded from the
* chat.
*
* The part is drawn live only: it is not stored with the message, so a
* conversation reloaded from history shows no card.
*/

/**
Expand Down Expand Up @@ -133,12 +147,20 @@ export const DraftReviewItemSchema = lazySchema(() => strictObject(
'The door\'s `list_drafts` verdict, read as the person who asked; `null` when none was read '
+ '(see `verdictWithheld` and `verdictError`)',
),
verdictWithheld: DraftReviewVerdictRefusalSchema.optional().describe('Why the person may not read a verdict, when `verdict` is `null` for that reason'),
verdictWithheld: DraftReviewVerdictRefusalSchema.optional().describe(
'Why the door gave no verdict, when `verdict` is `null` for that reason: the person may not read it, or the door '
+ 'left the draft unjudged under a bound such as `MAX_RECORDS_EXCEEDED`; the `message` says which',
),
verdictError: DraftReviewVerdictRefusalSchema.optional().describe('That reading the verdict failed, when `verdict` is `null` for that reason'),
verdictRead: z.enum(['turn-end', 'save']).describe(
'When the verdict was read: `turn-end`, after the turn\'s last save, or `save`, by the save that wrote this draft',
),
review: DraftReviewLinksSchema,
version: z.string().min(1).optional().describe(
'The draft\'s version token as the turn\'s last save of it wrote it (the save receipt\'s `version`). '
+ 'The card\'s Publish sends it as the publish body\'s `draftVersion`, so a draft changed since is '
+ 'refused 409 `METADATA_CONFLICT`, never published; absent, the row offers no Publish in the chat',
),
},
));

Expand Down
3 changes: 3 additions & 0 deletions ui/packages/app-shell/src/console/ai/ChatPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ import { useUpload } from '@object-ui/fields';
import { isSpreadsheetAttachment, uploadChatAttachments, chatAttachmentNotes } from './chatAttachments.js';
import { listLinkTarget, recordOpenTarget, nextSectionOpening } from './aiChatLinks.js';
import { documentHref } from '../../views/documentHref.js';
import { useDraftReviewPublish } from './draftReviewPublish.js';
import { hydratedMessagesToChatMessages } from './aiChatHydration.js';
import { localizeAgentLabel, agentEmptyState, buildAgentSuggestions } from './agentCopy.js';
import { drawerSuggestions, type EmptyConversationSize } from './emptyConversationModel.js';
Expand Down Expand Up @@ -318,6 +319,7 @@ export function ChatPane({
[navigate, openLinksInNewTab, openInNewTab],
);
const reviewLinkHref = useCallback((path: string) => documentHref(routerRootHref, path), [routerRootHref]);
const publishReviewedDraft = useDraftReviewPublish();

// The pane's root, measured by the composer-draft handoff below.
const paneRef = useRef<HTMLDivElement | null>(null);
Expand Down Expand Up @@ -850,6 +852,7 @@ export function ChatPane({
onOpenList={openList}
onOpenReviewLink={openReviewLink}
reviewLinkHref={reviewLinkHref}
onPublishDraft={publishReviewedDraft}
// cloud#3565 — the record-write card's three buttons and its states.
onOpenRecordForm={openRecordForm}
recordWriteCreateTitle={(objectLabel) => t('console.ai.recordWriteCreateTitle', { object: objectLabel })}
Expand Down
Loading
Loading