Skip to content

Conversation

@fluidcat
Copy link
Contributor

@fluidcat fluidcat commented Dec 29, 2025

部分LLM厂商自定义请求体参数不止是的基本类型,而是JSON。目前custom_extra_body只支持string、boolean、number,这里谈价JSON类型支持

Modifications / 改动点

修改了dashboard/src/components/shared/ObjectEditor.vue,添加JSON类型的添加、回显、提交支持

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

image image

Checklist / 检查清单

  • 😊 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。/ If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
  • 👀 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。/ My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
  • 🤓 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到了 requirements.txtpyproject.toml 文件相应位置。/ I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
  • 😮 我的更改没有引入恶意代码。/ My changes do not introduce malicious code.

Summary by Sourcery

在用于 custom_extra_body 的仪表盘键值对象编辑器中添加对 JSON 类型值的支持。

新功能:

  • 允许用户在对象编辑器中添加键值对时选择 json 作为值类型,并通过专用文本字段输入 JSON。
  • 在编辑和提交过程中,通过适当的序列化和解析,在对象编辑器中持久化并恢复 JSON 值。
Original summary in English

Summary by Sourcery

Add support for JSON-typed values in the dashboard key-value object editor used for custom_extra_body.

New Features:

  • Allow users to select 'json' as a value type when adding key-value pairs in the object editor and input JSON through a dedicated text field.
  • Persist and restore JSON values in the object editor by serializing and parsing them appropriately during editing and submission.

@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Dec 29, 2025
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - 我发现了 1 个问题,并留下了一些整体反馈:

  • 在处理 json 值时,confirmDialog 中的 JSON.parse(pair.value) 如果输入不是合法 JSON 会抛出异常并导致对话框出错;建议在解析前增加校验/错误处理(例如使用 try/catch 并给用户反馈)。
  • initializeLocalKeyValuePairs 中,typeof value === 'object' 会把 null 和其他非普通对象也归类为 json;如果这不是期望的行为,可以收紧类型检查(例如排除 null 或特定类),或者显式处理这些情况。
给 AI Agents 的提示
Please address the comments from this code review:

## Overall Comments
- When handling `json` values, `JSON.parse(pair.value)` in `confirmDialog` can throw and break the dialog if the input is invalid JSON; consider adding validation/error handling (e.g., try/catch with user feedback) before parsing.
- In `initializeLocalKeyValuePairs`, `typeof value === 'object'` will classify `null` and other non-plain objects as `json`; if that’s not desired, tighten the type check (e.g., exclude `null` or specific classes) or handle these cases explicitly.

## Individual Comments

### Comment 1
<location> `dashboard/src/components/shared/ObjectEditor.vue:214-219` </location>
<code_context>
       case 'boolean':
         defaultValue = false
         break
+      case 'json':
+        defaultValue = "{}"
+        break
</code_context>

<issue_to_address>
**issue (bug_risk):** JSON.parse on user input can throw and currently isn’t guarded, which may break the confirm flow.

If `pair.value` contains invalid JSON, `JSON.parse` will throw and likely break `confirmDialog()` and the save flow. Please wrap this in try/catch and either show a validation error or handle it gracefully so bad input doesn’t crash the UI.
</issue_to_address>

Sourcery 对开源项目是免费的——如果你觉得我们的评审有帮助,欢迎分享 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的评审。
Original comment in English

Hey - I've found 1 issue, and left some high level feedback:

  • When handling json values, JSON.parse(pair.value) in confirmDialog can throw and break the dialog if the input is invalid JSON; consider adding validation/error handling (e.g., try/catch with user feedback) before parsing.
  • In initializeLocalKeyValuePairs, typeof value === 'object' will classify null and other non-plain objects as json; if that’s not desired, tighten the type check (e.g., exclude null or specific classes) or handle these cases explicitly.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- When handling `json` values, `JSON.parse(pair.value)` in `confirmDialog` can throw and break the dialog if the input is invalid JSON; consider adding validation/error handling (e.g., try/catch with user feedback) before parsing.
- In `initializeLocalKeyValuePairs`, `typeof value === 'object'` will classify `null` and other non-plain objects as `json`; if that’s not desired, tighten the type check (e.g., exclude `null` or specific classes) or handle these cases explicitly.

## Individual Comments

### Comment 1
<location> `dashboard/src/components/shared/ObjectEditor.vue:214-219` </location>
<code_context>
       case 'boolean':
         defaultValue = false
         break
+      case 'json':
+        defaultValue = "{}"
+        break
</code_context>

<issue_to_address>
**issue (bug_risk):** JSON.parse on user input can throw and currently isn’t guarded, which may break the confirm flow.

If `pair.value` contains invalid JSON, `JSON.parse` will throw and likely break `confirmDialog()` and the save flow. Please wrap this in try/catch and either show a validation error or handle it gracefully so bad input doesn’t crash the UI.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@dosubot dosubot bot added the area:webui The bug / feature is about webui(dashboard) of astrbot. label Dec 29, 2025
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Dec 29, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Dec 29, 2025
@Soulter Soulter merged commit c5773fe into AstrBotDevs:master Dec 29, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:webui The bug / feature is about webui(dashboard) of astrbot. lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants