导出成品
成品是文体稿交给某个平台的那一份:同一篇稿子可以按不同平台生成多份,各自记录渲染状态、校验问题和导出状态。目前开放的平台是 markdown@1 和 text@1,都通过导出交付;当前开放的平台和各自的限制用 praxis.studio.platforms.list 读取。
准备:完成快速开始里的企划、文体稿和写好正文的段落。下面先建一个带一个段落的企划,名称带 docs-example 前缀;api 是一个小函数,带上认证头调用 curl。
export BASE="${PRAXIS_API_BASE:-https://api.deepraxis.com}"export TAG=$(date +%s)api() { curl --fail-with-body -sS -H "Authorization: Bearer $PRAXIS_API_KEY" -H "Content-Type: application/json" "$@"; }export WORK=$(api -X POST "$BASE/studio/v1/works" -d "$(jq -n --arg t "docs-example-export-$TAG" '{title: $t, goal: {reader: "Shop owners", outcome: "Decide on a support agent", message: "An agent takes the routine questions."}}')" | jq -er '.slug')api -X POST "$BASE/studio/v1/works/$WORK/drafts" -d '{"genre": "blog_article", "key": "post", "outline": [{"kind": "section", "name": "Problem"}]}' > /dev/nullREV=$(api "$BASE/studio/v1/works/$WORK/units/1" | jq -er '.revision')api -X PATCH "$BASE/studio/v1/works/$WORK/units/1" -d "$(jq -n --argjson rev "$REV" '{expected_revision: $rev, body: "The same question, nine times a day."}')" > /dev/null1. 生成成品
render: true 让创建和渲染在同一次调用里完成;不带它,成品以 pending 开始,之后调用渲染接口。request_id 是你自己的唯一键,用同一个值重发返回第一次的成品,不会多建。
RENDITION_JSON=$(api -X POST "$BASE/studio/v1/works/$WORK/drafts/post/renditions" \ -d '{"platform": "markdown@1", "render": true, "request_id": "docs-example-render-1"}')export RENDITION=$(printf '%s' "$RENDITION_JSON" | jq -er '.id')printf '%s\n' "$RENDITION_JSON" | jq '{id, platform, render_state, stale, issues: [.issues[] | .code], parts: [.parts[] | {index, text}], publish: .publish.state}'期望:HTTP 201,render_state 为 rendered,stale 为 false,publish.state 为 none。parts[0].text 是全文;issues 里的 heading_missing 是警告,指某个段落还没有成品小标题。渲染遇到错误级别的问题时,render_state 是 invalid,不是 HTTP 错误:空文体稿得到 draft_empty,渲染服务不可用得到 failed 和 render_unavailable,稍后重渲即可。读 render_state 和 issues,不要只看状态码。
2. 改稿后成品过期
文体稿改过之后,已有成品的 stale 变为 true;过期的成品不能导出。
REV=$(api "$BASE/studio/v1/works/$WORK/units/1" | jq -er '.revision')api -X PATCH "$BASE/studio/v1/works/$WORK/units/1" \ -d "$(jq -n --argjson rev "$REV" '{expected_revision: $rev, body: "The same question, ten times a day."}')" > /dev/nullapi "$BASE/studio/v1/works/$WORK/renditions/$RENDITION" | jq '{stale, render_state}'curl -sS -X POST "$BASE/studio/v1/works/$WORK/renditions/$RENDITION:publish" \ -H "Authorization: Bearer $PRAXIS_API_KEY" | jq -c '.error | {code, message}'期望:stale 为 true;导出返回 HTTP 409 RENDITION_STALE。
3. 重渲再导出
api -X POST "$BASE/studio/v1/works/$WORK/renditions/$RENDITION:render" | jq '{render_state, parts: [.parts[].text]}'api -X POST "$BASE/studio/v1/works/$WORK/renditions/$RENDITION:publish" | jq '{render_state, publish: {method: .publish.method, state: .publish.state}}'期望:渲染答复里 parts[0].text 是新正文;导出答复里 publish.method 为 export,publish.state 为 exported。markdown@1 和 text@1 的产物就是 parts[].text,没有文件,所以 praxis.studio.works.renditions.retrieveContent 返回 409 RENDITION_NOT_RENDERED;需要下载链接的是产出文件的平台(如卡片图),那类成品用该接口取 url 和 expire_time。重渲会把 publish.state 重置为 none,要再导出一次。
不需要成品记录的快速读法是 praxis.studio.works.drafts.retrieveExport(format 取 markdown 或 text):同步返回全文,不产生成品记录。
清理
api -X DELETE "$BASE/studio/v1/works/$WORK/renditions/$RENDITION"api -X PATCH "$BASE/studio/v1/works/$WORK" -d '{"update_mask": ["archived"], "archived": true}' | jq '.value | {slug, archived}'期望:删除返回 {"deleted": true},文体稿不受影响;归档后企划不再出现在默认列表。
用 SDK 做同一件事
import { Praxis } from '@deepraxis/sdk';
const praxis = new Praxis({ apiKey: process.env.PRAXIS_API_KEY!, baseUrl: process.env.PRAXIS_API_BASE ?? 'https://api.deepraxis.com',});
// Prerequisite: a work "work" with a draft "post" whose unit 1 has a body (see the quickstart)const rendition = await praxis.studio.works.drafts.renditions.create({ path: { work, draft: 'post' }, body: { platform: 'markdown@1', render: true, request_id: 'docs-example-render-1' },});console.log(rendition.render_state, rendition.parts[0]?.text);
// After the draft changes, the rendition is stale: render it again, then exportconst stale = await praxis.studio.works.renditions.retrieve({ path: { work, rendition: rendition.id } });if (stale.stale) { await praxis.studio.works.renditions.render({ path: { work, rendition: rendition.id } });}const exported = await praxis.studio.works.renditions.publish({ path: { work, rendition: rendition.id } });console.log(exported.publish.state, exported.parts[0]?.text);校验与限制
- 成品的平台必须是文体能出的平台:用
blog_article建xiaohongshu@1返回 400PLATFORM_GENRE_MISMATCH。 - 平台键要带版本:写
docx返回 404PLATFORM_NOT_FOUND。 - 同一个成品同时渲染或导出两次返回 409
REVISION_CONFLICT,几秒后重试。 - 发布到平台账号(X、微信等)暂不可用,返回
PLATFORM_NOT_AVAILABLE,请改用导出。