From e25910626789f0e0fe2efac96a40a8db998ede3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=BE=B7=E5=AE=87?= Date: Sat, 19 Sep 2026 23:04:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8B=86=E5=87=BA=E5=BC=95=E7=94=A8=E8=8D=89?= =?UTF-8?q?=E7=A8=BF=E9=94=AE=E4=B8=8E=20token=20=E7=9A=84=E5=8F=96?= =?UTF-8?q?=E5=80=BC=20helper=20=E6=B6=88=E9=99=A4=E5=B5=8C=E5=A5=97?= =?UTF-8?q?=E4=B8=89=E5=85=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - apps/ai-game-creator-shell/src/features/project-workspace/ResourceReferenceInput.tsx 新增 referenceDraftKey/referenceDraftToken,替换 readDraftFromNodes 里构造 labels 时的嵌套三元表达式 - 行为与原先一致,只是把「resource 取 id、skill 取 name、其余取 label」的规则收敛到一处 --- .../ResourceReferenceInput.tsx | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/apps/ai-game-creator-shell/src/features/project-workspace/ResourceReferenceInput.tsx b/apps/ai-game-creator-shell/src/features/project-workspace/ResourceReferenceInput.tsx index b2f1ea468..155e0ac41 100644 --- a/apps/ai-game-creator-shell/src/features/project-workspace/ResourceReferenceInput.tsx +++ b/apps/ai-game-creator-shell/src/features/project-workspace/ResourceReferenceInput.tsx @@ -240,6 +240,20 @@ type DraftProjection = { content: DirectCodexUserContentPart[]; }; +/** 引用在草稿文本里的稳定键:resource 用资源 id,skill 用技能名,其余用显示名。 */ +function referenceDraftKey(reference: ChatReference) { + if (reference.type === 'resource') return reference.resourceId; + if (reference.type === 'skill') return reference.name; + return reference.label; +} + +/** 引用回读成草稿文本时的 token:skill 是 `$name`,resource 与 runtime region 是 `@显示名`。 */ +function referenceDraftToken(reference: ChatReference) { + return reference.type === 'skill' + ? `$${reference.name}` + : `@${reference.label}`; +} + /** 仅供编辑器内部派生引用(重建文本草稿时用);对外只暴露 canonical content。 */ function readDraftProjectionFromNodes(): DraftProjection { const references: ChatReference[] = []; @@ -256,12 +270,8 @@ function readDraftFromNodes(): ChatComposerDraft { const projection = readDraftProjectionFromNodes(); const labels = new Map( projection.references.map((reference) => [ - reference.type === 'resource' - ? reference.resourceId - : reference.type === 'skill' - ? reference.name - : reference.label, - reference.type === 'skill' ? `$${reference.name}` : `@${reference.label}`, + referenceDraftKey(reference), + referenceDraftToken(reference), ]), ); const text = projection.content