Edit a unit body block by block
Code Mode: praxis.studio.works.units.blocks.patch
HTTP: POST /studio/v1/works/{work}/units/{unit}/blocks:patch
Change a body by naming the blocks to insert, replace or delete instead of resending the whole text. This is the safe way for a writer that only touches part of a unit, because a block another writer changed after your revision is refused rather than overwritten. The revision is required, and the answer carries the unit with its blocks so the next edit can address them.
签名
praxis.studio.works.units.blocks.patch(args:{path:{/** e.g. "wu-gang" */ work:string;/** e.g. "12" */ unit:string};body:{/** Unit revision the caller read; it is required, and when a block this call touches changed after it the whole call is refused rather than applied partially. e.g. 6 */ expected_revision:number;/** Operations in the order they apply; each one addresses existing blocks by identifier, so an order that deletes before replacing what it deleted is refused. */ ops:Array<{/** Which operation this is: insert a new block, replace an existing one, or delete one. e.g. "insert" */ op:"insert"|"replace"|"delete";/** Block the new one follows, by its blk_ identifier; null inserts at the start of the body. e.g. "blk_01JQ8Z3M9K4V7B2N6C5X0YTRHW" */ after?:string;/** Block this operation acts on, by its blk_ identifier; used by replace and delete. e.g. "blk_01JQ8Z3M9K4V7B2N6C5X0YTRHW" */ block?:string;/** Markdown text of the block, used by insert and replace; it carries the block type and any media reference the genre allows. e.g. "排字房的铅字盘上,压着一张通缉令。" */ markdown?:string}>;/** Confirmation that a unit marked final may change; send it only when the person themselves asked for the change. e.g. false */ confirm_final_edit?:boolean}}):Promise<{value:({/** Unit identifier, stable when units are moved or renamed. e.g. "unt_01JQ8Z3M9K4V7B2N6C5X0YTRHW" */ id:string;/** Work this unit belongs to; it is the same value the work path segment carries. e.g. "wk_01JQ8Z3M9K4V7B2N6C5X0YTRHW" */ work?:string;/** Draft this unit belongs to; units never move between drafts. e.g. "drf_01JQ8Z3M9K4V7B2N6C5X0YTRHW" */ draft?:string;/** In-work number assigned in creation order, never reused and unchanged by a move; it is what the unit path segment takes. e.g. 12 */ number:number;/** Unit this one sits under, or null at the top level of the tree. e.g. "unt_01JQ8Z3M9K4V7B2N6C5X0YTRHW" */ parent?:string;/** Sort key among siblings; it is opaque, and moving a unit rewrites only its own row. e.g. "0|hzzzzz:" */ position?:string;/** Structural kind of this unit, which must be one the genre allows at this position of the tree. e.g. "chapter" */ kind:string;/** Structure name used by people and agents to manage the tree, such as the second scene of a chapter; it is not the published heading. e.g. "第二章 · 排字房" */ name:string;/** Heading the finished piece shows for this unit, or null when it shows none; a genre may require it or forbid it. e.g. "第二章 排字房" */ heading?:string;intent:{/** What this unit has to accomplish, written as the story so far for later units; it is what a reader of the outline sees. e.g. "主角在排字房看到通缉令,第一次动摇了立场。" */ synopsis:string;/** Points this unit hits, called beats, arguments or selling points depending on the genre. */ points:Array<string>;/** Keys of the brief points this unit claims, which is how the requirement coverage check knows a point landed. */ brief_points:Array<string>;/** Intent revision, moved whenever the synopsis or the points change; a body written against an older value is behind. e.g. 4 */ revision:number;/** Whether the writer confirmed the synopsis matches what the body actually says, rather than what was planned. */ synopsis_from_body:boolean};/** How far this unit has come, moving forward as intent and body are written; a unit marked final refuses changes without confirmation. */ status:"idea"|"outlined"|"writing"|"drafted"|"revised"|"final";/** Intent revision the current body was written against, or null when there is no body; an older value means the intent moved on. e.g. 4 */ body_from_intent?:number;/** Unit of the upstream draft this one was written from, present when the draft derives from another; a serial of a novel records it per section. e.g. "unt_01JQ8Z3M9K4V7B2N6C5X0YTRHW" */ source_unit?:string;/** Reference entries this unit is tied to, including the mentions detected in its text. */ links?:Array<{/** Identifier of the reference entry this unit is tied to. e.g. "ent_01JQ8Z3M9K4V7B2N6C5X0YTRHW" */ entry?:string;/** How the tie came about, which decides whether the entry reaches the context pack for this unit. */ kind?:"mention"|"attached"|"excluded";/** Role of the entry inside this genre, such as point-of-view character or main product; it lifts the entry's priority in the pack. e.g. "视角人物" */ role?:string}>;/** Characters in the body with whitespace removed, which is what the length checks measure. e.g. 2680 */ chars:number;/** Duration in seconds for units of a video genre, or null for a written unit. e.g. 42 */ seconds?:number;/** Unit revision, moved by any change to the unit; pass it as expected_revision when writing the body. e.g. 6 */ revision:number;last_editor?:{/** Whether the change came from a person, an agent or the platform itself; an agent session through the API is recorded as an agent. */ kind?:"user"|"agent"|"system";/** Identifier of that actor, such as a user identifier or an agent session identifier. e.g. "usr_01JQ8Z3M9K4V7B2N6C5X0YTRHW" */ id?:string;/** Display name of the actor when one is known, shown beside the change. e.g. "张三" */ label?:string};/** Body blocks, present only when the unit was read with its content; writing block by block needs their identifiers. */ blocks?:Array<{/** Block identifier, carried inline in Markdown as an anchor comment so an edit can address one block without rewriting the body. e.g. "blk_01JQ8Z3M9K4V7B2N6C5X0YTRHW" */ id:string;/** Unit revision at which this block was last changed; it decides whether an older precondition still allows a block edit. e.g. 6 */ revision:number;/** Element kind of this block, from the set the genre allows; it decides how the block is rendered in a rendition. */ type:"paragraph"|"heading"|"list"|"quote"|"code"|"image"|"video"|"divider"|"scene_break"|"callout"|"hashtags"|"link"|"cut"|"canvas";/** Markdown text of this block, empty for blocks that carry a reference instead of words. e.g. "排字房的铅字盘上,压着一张通缉令。" */ text:string;/** File this block shows, for image and video blocks, referenced by its file identifier. e.g. "file_01JQ8Z3M9K4V7B2N6C5X0YTRHW" */ file?:string;/** Caption shown with a media block and carried into renditions that keep captions. e.g. "1935 年的排字房" */ caption?:string;/** Heading depth for a heading block, one to four, which decides the outline level in the finished piece. e.g. 2 */ level?:number}>})&({/** Whole body as Markdown with block anchors kept inline, so a rewrite can round-trip the block identifiers. e.g. "第一段。<!-- blk_01JQ8Z3M9K4V7B2N6C5X0YTRHW -->" */ markdown?:string;intent_diff?:{/** Intent revision the current body was written against. e.g. 4 */ from_revision?:number;/** Synopsis at that revision, shown beside the newer one so a writer can see what moved. e.g. "主角在报馆第一次见到通缉令。" */ synopsis?:string;/** Intent points at that revision, in the order they were written. */ points?:Array<string>}});/** Deterministic checks of the genre run against the body after the operations. */ checks?:Array<{/** Key of the check that produced this row, such as unit_chars or body_total_chars; the genre lists which ones it runs. e.g. "unit_chars" */ check:string;/** Whether the check passed; a failed hard check blocks publishing until the text changes. */ ok:boolean;/** What the check found, in words, including the measured value and the bound it broke. e.g. "本章 2680 字,低于 3000 字的目标。" */ text:string;/** Unit the finding is about, present when the check is per unit. e.g. "unt_01JQ8Z3M9K4V7B2N6C5X0YTRHW" */ unit?:string;/** Block the finding is about, present when the check is per block, such as a missing image or a banned word. e.g. "blk_01JQ8Z3M9K4V7B2N6C5X0YTRHW" */ block?:string;/** How serious the finding is: an error fails the check, a warning is reported without failing it. */ severity:"error"|"warning";/** Whether this is a platform hard limit, which is the only kind a free-writing genre puts into its todo list. */ hard:boolean}>;/** First items of the draft todo list now, so a block-level writer can continue without another status read. */ next?:Array<{/** What is outstanding, chosen from a closed set so a caller can branch on it instead of reading the text. */ kind:"goal_incomplete"|"brief_points_unplaced"|"no_structure"|"intent_missing"|"intent_ahead_of_body"|"body_missing"|"draft_stale"|"work_adaptation_stale"|"prop_missing"|"check_failed"|"review_unresolved"|"rendition_stale"|"rendition_missing"|"publish_blocked";/** Which of the seven layers this item belongs to, used to order the list; the layers are always in the same order. */ layer:"goal"|"frame"|"task"|"reference"|"body"|"coherence"|"rendition";/** Unit this item is about, present when the item points at one unit rather than the whole draft. e.g. "unt_01JQ8Z3M9K4V7B2N6C5X0YTRHW" */ unit?:string;/** In-work number of that unit, which is what the unit path segment of a call takes. e.g. 12 */ number?:number;/** The item in words, written to be shown to a person as is. e.g. "第 12 节还没有正文" */ text:string;/** For a check_failed item, the key of the failing check, so a program can act on it without parsing the text; a unit that already has an item for it gets no separ e.g. "body_total_chars" */ check?:string;/** Suggested next call for this item, offered as guidance rather than a fixed script. e.g. "praxis.studio.works.units.retrieveContext" */ call?:string}>}>;参数
| 名称 | 位置 | 类型 | 必填 | 说明 |
|---|---|---|---|---|
| work | path | string | 是 | The work being addressed, either its organization-unique slug or its wk_ identifier; a slug case is what a person would say, and a renamed slug still resolves through its old value. |
| unit | path | string | 是 | Unit being addressed, written as its in-work number such as 12, as #12, or as its unt_ identifier; the number never changes when the unit is moved. |
请求体
| 必填 | 内容类型 | 说明 |
|---|---|---|
| 是 | application/json | The block operations to apply, in order, together with the revision the caller read and, for a final unit, the confirmation that it may change. |
响应
| 状态码 | 内容类型 | 说明 |
|---|---|---|
| 200 | application/json | The unit after the block operations, with its blocks, its checks and the next todos of the draft. |
| 400 | application/json | INVALID_PARAMS means a field is missing, malformed or not allowed for this resource; correct the named field and repeat the call. |
| 401 | application/json | The API key is missing, invalid or carries no organization; send a valid organization key in the Authorization header. |
| 404 | application/json | WORK_NOT_FOUND, DRAFT_NOT_FOUND or UNIT_NOT_FOUND means one address in the path names nothing reachable; use the numbers and keys from the outline rather than a remembered one, since a unit that was deleted never returns. |
| 409 | application/json | REVISION_CONFLICT means the resource changed since the expected_revision you sent, so nothing was written; re-read it, merge the other change into yours and repeat the call with the revision you just read. |
| 422 | application/json | BLOCK_TYPE_NOT_ALLOWED means the genre does not allow that block kind at all; read the genre block list and use one of the kinds it names. |
| 500 | application/json | INTERNAL means the request could not complete; re-read the resource before retrying a write, because the write may already have landed. |