a2ui-project / a2ui-project/a2ui

`A2uiMessage.fromJson` accepts objects carrying more than one of `createSurface`/`updateComponents`/`updateDataModel`/`deleteSurface`

未關閉
#1,895 1 則留言 0 個 reaction 已指派 1 人 已被 @andrewkolos 認領 在 GitHub 檢視
component: genui P3 status: first-line-handled type: bug
主要語言
TypeScript
星號
16.4k
分支
1.3k
平均合併
3 天 15 小時
30 天內合併 PR
134

描述

_↴ Ported from [flutter/genui#934](https://github.com/flutter/genui/issues/934) — originally opened by [andrewkolos](https://github.com/andrewkolos) on 2026-05-26._
_Original labels: front-line-handled_
_Original assignees: [andrewkolos](https://github.com/andrewkolos)_

---

[`A2uiMessage.fromJson`](https://github.com/flutter/genui/blob/ae53cc52b35b72312f01b80eeb565163e3c869d7/packages/genui/lib/src/model/a2ui_message.dart#L20). The message type is parsed in the order of 1) `createSurface`, 2) `updateComponents`, 3) `updateDataModel`, and then 4) `deleteSurface`). The function returns on the first match.

A payload that matches multiple of these checks will silently parse as whatever happens to come first instead of failing validation.

```dart
final message = A2uiMessage.fromJson({
'version': 'v0.9',
'createSurface': {'surfaceId': 's1', 'catalogId': 'c1'},
'updateComponents': {'surfaceId': 's1', 'components': []},
});
// Expected: A2uiValidationException
// Actual: parses as CreateSurface, drops updateComponents silently
```

I would normally consider this a corner case and not bother with fixing it, as I think an LLM is very unlikely to generate a message that matches multiple types. However, 1) I'd like `package:genui` to have as much parity with other renderers as possible ([`web_core` does include logic to catch this case](https://github.com/google/A2UI/blob/0e0375749bf8a940d57969d612e74f7221ad246e/renderers/web_core/src/v0_9/processing/message-processor.ts#L229-L262)) and 2) the 0.9 spec does explicitly specify `oneOf` and `additionalProperties: false` for each message type, so fixing this would also make the genui package follow the spec more closely.

貢獻指南

開啟貢獻指南

研究方向

此 issue 位於 Dart package `genui` 的檔案 `packages/genui/lib/src/model/a2ui_message.dart` 中。查看 `A2uiMessage.fromJson` 方法及其解析順序。與 web_core renderer 中的驗證邏輯(`renderers/web_core/src/v0_9/processing/message-processor.ts` 第 229-262 行)進行比較。修正應確保 JSON payload 恰好包含指定 message fields 中的一個,並在匹配到多個時拋出 `A2uiValidationException`。為無效情況撰寫測試。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
dart, typescript
領域
backend-api-design
Issue 類型
缺陷
難度
3/5
預估耗時
1-2 天
活躍度
冷清
描述清晰度
描述清楚
新手友好度
45/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。