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 摘要。