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
20 changes: 20 additions & 0 deletions .changeset/35928-record-update-starts-read.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
'@objectstack/spec': minor
'@objectstack/service-automation': patch
'@objectstack/trigger-record-change': patch
'@objectstack/runtime': patch
'@objectstack/client': patch
---

feat(automation): `POST /api/v1/automation/_record-starts` answers which flows a proposed update of one record would start

Clause-②: yes (widening) — one new public read: the route `POST /api/v1/automation/_record-starts` (`automation.listRecordUpdateStarts` in the API contract and in `@objectstack/client`); `@objectstack/spec/api` adds `RecordUpdateStartsRequestSchema`, `RecordUpdateStartSchema`, `RecordUpdateStartsResponseSchema` and their types; `@objectstack/spec/contracts` adds `RecordUpdateStartsInput` and the optional `IAutomationService.listRecordUpdateStarts`; `@objectstack/spec/automation` adds `recordChangeTriggerHookEvents` and `recordChangeTriggerFiresOnUpdate`; `_record-starts` joins the `/automation` domain's reserved position literals. Nothing existing is removed or re-typed.
Metadata-protocol: added — the three new `@objectstack/spec/api` schemas enter the `api` authorable-surface shard (10 keys: `RecordUpdateStart:name/label/startsApproval`, `RecordUpdateStartsRequest:object/recordId/changes`, `RecordUpdateStartsResponse:success/data/error/meta`); no flow or other metadata key is added
Skills-docs: none — no skill under `skills/**` teaches the console's stage confirms; `content/docs/automation/flows.mdx` gains the read in this change.

The console's stage confirms now name the flows a move would start (objectstack#35928, ruling record 7073655354). They ask the server:

- **Request** `{ object, recordId, changes }`; **response** `{ success, data: { flows: [{ name, label, startsApproval }] } }`.
- **Who is answered:** a signed-in caller who can read the record. The record is read as the caller through the `/data` door's own `get`, so a record they cannot read answers `404 RECORD_NOT_FOUND` exactly as an absent one, and the engine is never asked. Anonymous `401`; a malformed body `400 VALIDATION_FAILED`; a `changes` key that is not a declared field of the object `400 VALIDATION_FAILED` on that key, the engine never asked; a read that answers no record `404 RECORD_NOT_FOUND`; any query parameter `400 VALIDATION_ERROR`; an engine without the read `501`.
- **Which flows:** enabled `record_change` flows of the object, armed on their trigger, whose `triggerType` binds an update, and whose start condition holds for the record read with `changes` applied (`previous` is the record read). The condition goes through the engine's one start-condition gate, the one every run passes; the token grammar `@objectstack/trigger-record-change` binds hooks by moved into the spec (`recordChangeTriggerHookEvents`) so the preview reads the same rule, with no second copy. A condition that cannot be evaluated against the record is not listed. Hooks are never listed.
- **Per flow:** `name`, the authored `label` (a client translates it by name) and `startsApproval`, true for a flow holding an `approval` node (ADR-0019). No description, condition or nodes.
20 changes: 20 additions & 0 deletions .changeset/35928-stage-confirm-names-flows.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
'@object-ui/plugin-detail': patch
'@object-ui/plugin-grid': patch
'@object-ui/fields': patch
'@object-ui/i18n': patch
'@object-ui/app-shell': patch
---

feat(console): a stage confirm names the flows the move would start, in the list cell and on the record page

Clause-②: yes (widening) — `@object-ui/plugin-detail` adds the exports `useRecordUpdateStarts`, `StageChangeStarts`, `RECORD_UPDATE_STARTS_PATH` and the type `RecordUpdateStartsAsk`; `@object-ui/fields`' `RequiredFieldsDialog` takes an optional `notice`; `@object-ui/i18n` adds the export `activeFlowsBundle` (with the types `FlowsTranslation` and `TranslationResourceReader`, moved from `@object-ui/app-shell`'s internal `utils/flowsBundle`) and two keys to every pack: `detail.stageChangeStartsHeading`, `detail.stageChangeStartsApproval`. `@object-ui/plugin-grid`'s `StateChangeConfirm` gains an optional `ask`. Nothing existing is removed or re-typed.
Metadata-protocol: none
Skills-docs: none — no skill under `skills/**` teaches the console's stage confirms; `content/docs/frontend/plugins/plugin-grid.mdx` names the list in this change.

When a stage move would start a flow, its confirm now says so (objectstack#35928, ruling record 7073655354):

- The list cell's state-machine confirm and the record page's stage confirm (the path's press and the header's stage menu) keep their sentence and add, under it, 「保存后将启动以下流程:」 ("Saving this change starts these flows:") and each flow by its label in the reader's language. A flow that starts an approval is marked 「发起审批」 ("starts an approval").
- Both confirms ask one read, `POST /api/v1/automation/_record-starts`, through one shared hook, so the two surfaces cannot disagree. The server decides which flows start; nothing is judged in the browser.
- A move that starts nothing shows no list, and a read that fails or is refused leaves the confirm exactly as it was.
- A flow label is translated as the flow runner translates it: the app's `flows` translations, read through `activeFlowsBundle`, which now lives in `@object-ui/i18n` so the confirms' packages can read it; the console's flow runner and designer import it from there.
44 changes: 44 additions & 0 deletions content/docs/automation/flows.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2586,6 +2586,50 @@ uncached one: it is read live on every call and kept out of the ETag, so a
read that carries it is always answered in full, never with `304 Not
Modified`. It is the verdict of the engine in the process that answered.

### Which flows a record update would start

`POST /api/v1/automation/_record-starts` answers, before anything is written,
which flows a proposed update of one record would start. The console's stage
confirms read it: the list cell's state-machine confirm and the record page's
stage confirm name those flows under their sentence (objectstack#35928).

```json
// request
{ "object": "project", "recordId": "p1", "changes": { "status": "completed" } }
// response
{ "success": true, "data": { "flows": [
{ "name": "project_closure", "label": "Project Closure", "startsApproval": true }
] } }
```

- **Who is answered:** any signed-in caller who can read the record. The
record is read as the caller, through the `/data` door's own `get`, so a
record they cannot read answers `404 RECORD_NOT_FOUND` exactly as one that
does not exist. An anonymous call is refused `401`, a malformed body `400
VALIDATION_FAILED`, a `changes` key that is not a declared field of the
object `400 VALIDATION_FAILED`, any query parameter `400 VALIDATION_ERROR`,
and an engine without the read `501`.
- **Which flows:** enabled `record_change` flows of that object, armed on their
trigger, whose `triggerType` binds an update (`record-…-update` or
`record-…-write`), and whose start `condition` holds for the record with
`changes` applied, with `previous` as the record read. The condition is judged
by the same gate every run passes, on the record as the caller reads it. A
condition that cannot be evaluated against it is not listed. Hooks are never
listed.
- **What is served per flow:** its `name`, its authored `label` (a client
translates it by `name`, as it translates any flow label) and
`startsApproval`, true when the flow holds an `approval` node. No
description, condition or nodes.

The answer is a preview, not a promise: the write itself is judged when it
happens, and a condition that reads a field the caller cannot see is judged
here on what the caller sees. Of the caller, the preview binds the user id and
the tenant only. A live save also binds the writer's positions, the request's
params and its expand, so a condition that reads those is judged here without
them, and the preview can differ from the save in either direction: it can miss
a flow the save starts, or list one the save does not (a negated test of the
writer reads true here).

## Expressions in flows

A flow computes with **one expression dialect, CEL**: every condition is bare
Expand Down
10 changes: 8 additions & 2 deletions content/docs/frontend/plugins/plugin-grid.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,14 @@ row whose new value would sort it elsewhere stays in place until the next load
confirm that names the field and both values and says saving may trigger
related automation ("Status changes from On Hold to Active. Saving may
trigger related automation."). Cancel writes nothing and the cell keeps the
value it had; Change saves it as any commit is saved. The confirm does not
list the flows. A host asks this through `GridCellSelection.confirmCommit`.
value it had; Change saves it as any commit is saved. Under that sentence the
confirm names the flows the move would start, each by its label in the
reader's language and a flow that starts an approval marked so, as the
server's `POST /api/v1/automation/_record-starts` answers them (the record
page's stage confirm reads the same answer, through `@object-ui/plugin-detail`'s
`useRecordUpdateStarts`). A read that fails or names no flow leaves the
sentence alone (objectstack#35928). A host asks this through
`GridCellSelection.confirmCommit`.
- **A change that makes other fields required asks for them** (objectstack#35956).
When the new value makes a field's `requiredWhen` true while that field is
still empty (a win reason on "Won", say), nothing is written yet: a dialog
Expand Down
74 changes: 72 additions & 2 deletions content/docs/references/api/automation-api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ POST /api/v1/automation/:name/toggle — Enable/disable a packaged flo
POST /api/v1/automation/:name/clone — Copy a flow, switched off, into a package
GET /api/v1/automation/:name/runs — List execution runs
GET /api/v1/automation/:name/runs/:runId — Get single execution run
POST /api/v1/automation/_record-starts — Flows a proposed record update would start
```

<Callout type="info">
Expand All @@ -58,8 +59,8 @@ GET /api/v1/automation/:name/runs/:runId — Get single execution run
## TypeScript Usage

```typescript
import { AutomationApiErrorCode, AutomationFlowPathParamsSchema, AutomationRunPathParamsSchema, CloneFlowRequestSchema, CloneFlowResponseSchema, CreateFlowRequestSchema, CreateFlowResponseSchema, DeleteFlowRequestSchema, DeleteFlowResponseSchema, FlowFailureDetailsSchema, FlowInnerRefusalSchema, GetFlowRequestSchema, GetFlowResponseSchema, GetRunRequestSchema, GetRunResponseSchema, ListRunsRequestSchema, ListRunsResponseSchema, ResumeFailureDetailsSchema, ToggleFlowRequestSchema, ToggleFlowResponseSchema, TriggerFlowRequestSchema, TriggerFlowResponseSchema, UpdateFlowRequestSchema, UpdateFlowResponseSchema } from '@objectstack/spec/api';
import type { AutomationApiErrorCode, AutomationFlowPathParams, AutomationRunPathParams, CloneFlowRequest, CloneFlowResponse, CreateFlowRequest, CreateFlowResponse, DeleteFlowRequest, DeleteFlowResponse, FlowFailureDetails, FlowInnerRefusal, GetFlowRequest, GetFlowResponse, GetRunRequest, GetRunResponse, ListRunsRequest, ListRunsResponse, ResumeFailureDetails, ToggleFlowRequest, ToggleFlowResponse, TriggerFlowRequest, TriggerFlowResponse, UpdateFlowRequest, UpdateFlowResponse } from '@objectstack/spec/api';
import { AutomationApiErrorCode, AutomationFlowPathParamsSchema, AutomationRunPathParamsSchema, CloneFlowRequestSchema, CloneFlowResponseSchema, CreateFlowRequestSchema, CreateFlowResponseSchema, DeleteFlowRequestSchema, DeleteFlowResponseSchema, FlowFailureDetailsSchema, FlowInnerRefusalSchema, GetFlowRequestSchema, GetFlowResponseSchema, GetRunRequestSchema, GetRunResponseSchema, ListRunsRequestSchema, ListRunsResponseSchema, RecordUpdateStartSchema, RecordUpdateStartsRequestSchema, RecordUpdateStartsResponseSchema, ResumeFailureDetailsSchema, ToggleFlowRequestSchema, ToggleFlowResponseSchema, TriggerFlowRequestSchema, TriggerFlowResponseSchema, UpdateFlowRequestSchema, UpdateFlowResponseSchema } from '@objectstack/spec/api';
import type { AutomationApiErrorCode, AutomationFlowPathParams, AutomationRunPathParams, CloneFlowRequest, CloneFlowResponse, CreateFlowRequest, CreateFlowResponse, DeleteFlowRequest, DeleteFlowResponse, FlowFailureDetails, FlowInnerRefusal, GetFlowRequest, GetFlowResponse, GetRunRequest, GetRunResponse, ListRunsRequest, ListRunsResponse, RecordUpdateStart, RecordUpdateStartsRequest, RecordUpdateStartsResponse, ResumeFailureDetails, ToggleFlowRequest, ToggleFlowResponse, TriggerFlowRequest, TriggerFlowResponse, UpdateFlowRequest, UpdateFlowResponse } from '@objectstack/spec/api';

// Validate data
const result = AutomationApiErrorCode.parse(data);
Expand Down Expand Up @@ -1022,6 +1023,75 @@ const result = AutomationApiErrorCode.parse(data);
| **hasMore** | `boolean` | ✅ | Whether more runs matched than this response carries — widen `limit` to see them. Under `status`, `false` means no further match within the scanned window rather than none at all: the window is taken before the filter is applied. |


---

## RecordUpdateStart

### Properties

| Property | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| **name** | `string` | ✅ | The flow's machine name — the key a client translates its label by (`flows.<name>.label`). |
| **label** | `string` | ✅ | The flow's display label as authored (a client translates it by `name`). |
| **startsApproval** | `boolean` | ✅ | Whether the flow contains an approval node, so the update starts an approval. |


---

## RecordUpdateStartsRequest

### Properties

| Property | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| **object** | `string` | ✅ | Machine name of the record's object. |
| **recordId** | `string` | ✅ | Id of the record the update would write. |
| **changes** | `Record<string, any>` | ✅ | The proposed update: each field it sets and its new value, keyed by the field's machine name. Every key must be a declared field of `object`; the door refuses any other key `400 VALIDATION_FAILED` before the engine is asked. The record's other fields are read as stored. |


---

## RecordUpdateStartsResponse

### Properties

| Property | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| **success** | `boolean` | ✅ | Operation success status |
| **error** | `{ code: Enum<'VALIDATION_ERROR' \| 'INVALID_FIELD' \| 'MISSING_REQUIRED_FIELD' \| …>; declaredCode?: string; message: string; userMessage?: string; … }` | optional | Error details if success is false |
| **meta** | `{ timestamp: string; duration?: integer; requestId?: string; traceId?: string }` | optional | Response metadata |
| **data** | `{ flows: object[] }` | ✅ | |

### Nested Shape: `RecordUpdateStartsResponse.error`

| Property | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| **code** | `Enum<'VALIDATION_ERROR' \| 'INVALID_FIELD' \| 'MISSING_REQUIRED_FIELD' \| …>` | ✅ | Error code (e.g. VALIDATION_ERROR; StandardErrorCode ∪ the ledger the serving side registers — ERROR_CODE_LEDGER for framework packages) |
| **declaredCode** | `string` | optional | The producer-declared code, verbatim, when it is not a member of the closed `code` vocabulary — the open, author-authored channel (app-specific spellings; ADR-0112) |
| **message** | `string` | ✅ | Readable error message |
| **userMessage** | `string` | optional | Producer-marked user-facing refusal text, verbatim, in the request's locale: platform-composed text falls back to the workspace default locale, then `en`; an app-authored refusal falls back to its declared wording. Present exactly when the producer opted in at throw time; consumers render it to end users as received and keep their generic substitution for anything unmarked. Status-agnostic; never replaces `message`. |
| **refusal** | `true` | optional | Producer-declared: the 5xx this envelope carries is a deliberate refusal whose `message` is authored for the caller, so a boundary that reads the declaration keeps it verbatim (until the withhold arms read it, a declared refusal is still withheld). Absent (the default) on a declared fault, whose `message` is withheld from the body and logged for the operator; redundant on a 4xx. Presence is the declaration — `true` is the only value. |
| **category** | `string` | optional | Error category (e.g. validation, authorization) |
| **httpStatus** | `integer` | optional | HTTP status of the response carrying this error |
| **details** | `any` | optional | Additional error context (e.g. field validation errors) |
| **requestId** | `string` | optional | Request ID for tracking |

### Nested Shape: `RecordUpdateStartsResponse.meta`

| Property | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| **timestamp** | `string` | ✅ | |
| **duration** | `integer` | optional | Server-side processing duration in milliseconds |
| **requestId** | `string` | optional | |
| **traceId** | `string` | optional | |

### Nested Shape: `RecordUpdateStartsResponse.data`

| Property | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| **flows** | `{ name: string; label: string; startsApproval: boolean }[]` | ✅ | The flows the update would start, in no promised order. |


---

## ResumeFailureDetails
Expand Down
Loading
Loading