浏览代码

fix(ui-agent-preset): read a refusal's cause by its detail, not its code

Yichen Jiang 1 月之前
父节点
当前提交
002af9f20b
共有 1 个文件被更改,包括 7 次插入 和 4 次删除
  1. 7 4
      packages/client/ui-agent-preset/src/client/seat-store.ts

+ 7 - 4
packages/client/ui-agent-preset/src/client/seat-store.ts

@@ -162,11 +162,14 @@ export class AgentPresetSeatController {
         const { error } = result
         this.set({
           busy: false,
-          // A mount failure carries its cause twice: `message` wraps it in the
+          // A refusal carries its cause twice: `message` wraps it in the
           // roster's own frame, which names the preset the surface reporting
-          // this already names, and `details.reason` holds the same cause
-          // without it.
-          error: error.code === 'agent-preset-invalid' ? error.details.reason : error.message,
+          // this already names, and a `reason` detail holds the same cause
+          // without it. Read by the detail rather than by the code, because
+          // every refusal that has a cause to give names it the same way.
+          error: 'reason' in error.details && typeof error.details.reason === 'string'
+            ? error.details.reason
+            : error.message,
           current: presetOf(session) ?? '',
         })
         return