Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(maker-shared): keep declared ids and gate string props by kind
Eapp1e3ccd17cb3ca4
diff --git a/packages/maker-shared/src/__tests__/richAnswer.test.ts b/packages/maker-shared/src/__tests__/richAnswer.test.tsindex c3a2f9f027..bb2fb5224e 100644--- a/packages/maker-shared/src/__tests__/richAnswer.test.ts+++ b/packages/maker-shared/src/__tests__/richAnswer.test.ts@@ -391,3 +391,33 @@ describe('inline draft ids', () => {expect(doc.issues).toBe(0);});});++// #7627 review: a draft that names itself keeps that id, and a bare string only+// counts as text for the kinds that render `props.text`.+describe('inline draft ids and text-only props', () => {+ it('keeps an inline child id that the draft declares', () => {+ const doc = new RichAnswerStream().update(+ line(1, {+ op: 'create',+ id: 'tabs',+ kind: 'details',+ props: {+ label: 'x',+ children: [+ { id: 'second', kind: 'markdown', text: 'two' },+ { kind: 'markdown', text: 'three' },+ ],+ },+ }),+ );+ expect(doc.issues).toBe(0);+ expect(doc.nodes.get('tabs')?.children[0]).toBe('second');+ });+ it('drops a string props on a kind that never reads text', () => {+ const doc = new RichAnswerStream().update(+ line(1, { op: 'create', id: 'd', kind: 'details', props: 'plain string' }),+ );+ expect(doc.nodes.has('d')).toBe(false);+ expect(doc.issues).toBe(1);+ });+});diff --git a/packages/maker-shared/src/richAnswer.ts b/packages/maker-shared/src/richAnswer.tsindex 48578fcdae..2482abda1f 100644--- a/packages/maker-shared/src/richAnswer.ts+++ b/packages/maker-shared/src/richAnswer.ts@@ -65,6 +65,9 @@ const CONTAINER_KINDS = ["details","tabs",];++/** Kinds that render `props.text`; only these can carry a bare string. */+const TEXT_PROP_KINDS: RichAnswerKind[] = ["text", "markdown", "heading", "code"];const record = (v: unknown): v is Record<string, unknown> =>!!v && typeof v === "object" && !Array.isArray(v);const value = (v: unknown): v is RichValue =>@@ -199,7 +202,7 @@ export class RichAnswerStream {if (op.version !== undefined && op.version !== 1) throw Error("version");if (typeof op.id !== "string" || !ID.test(op.id)) throw Error("id");const current = this.nodes.get(op.id);- const props = this.props(op.props);+ const props = this.props(op.props, op.kind as RichAnswerKind);// Some real harness outputs place visual style beside props. Normalize once.if (record(op.style) && props.style === undefined)props.style = this.props(op.style);@@ -358,12 +361,17 @@ export class RichAnswerStream {try {props = this.props(draft.props ?? (typeof draft.text === "string" ? { text: draft.text } : {}),+ draft.kind as RichAnswerKind,);} catch {dropped();return;}- const id = this.inlineChildId(parentId, offset + 1);+ // A draft may name itself (`{id:"second"}`); `tabs.props.default` points at+ // that id, so a declared id wins while it is still free.+ const declared =+ typeof draft.id === "string" && ID.test(draft.id) && !this.nodes.has(draft.id);+ const id = declared ? (draft.id as string) : this.inlineChildId(parentId, offset + 1);this.nodes.set(id, {id,kind: draft.kind as RichAnswerKind,@@ -389,11 +397,14 @@ export class RichAnswerStream {if (!this.nodes.has(id)) return id;}}- private props(v: unknown): Record<string, unknown> {+ private props(v: unknown, kind?: RichAnswerKind): Record<string, unknown> {if (v === undefined) return {};// Models write the text straight into props (`"props": "hello"`); the protocol// default keeps that block readable instead of dropping the whole node (#7627).if (typeof v === "string") {+ // Only kinds that render `props.text` take a bare string; anywhere else the+ // text would be stored and never shown, so the draft counts as unreadable.+ if (kind && !TEXT_PROP_KINDS.includes(kind)) throw Error("props");// The limit is on the node that gets stored and replayed, which is the// object below: escaping can make it longer than the incoming string.const text = { text: v };