{
  "schemaVersion": "1.0",
  "id": "ai-chat",
  "title": "Nhờ AI",
  "purpose": "Full-screen common assistant with suggested local examples and accessible manual path.",
  "roles": [
    "adult",
    "child"
  ],
  "group": "ai-assistant",
  "variantOf": null,
  "layout": {
    "canvas": {
      "width": 390,
      "height": 844
    },
    "responsive": {
      "minimumWidth": 360,
      "maximumWidth": 430,
      "scroll": "vertical",
      "safeAreaBottom": true,
      "fontScale": "native dynamic type; reflow without clipping",
      "keyboard": "composer sticky within resized viewport; dialog scrolls; no fixed keyboard overlay"
    },
    "regions": [
      {
        "id": "header",
        "order": 0,
        "type": "safe-area/header",
        "height": "intrinsic"
      },
      {
        "id": "content",
        "order": 1,
        "type": "purpose-specific assistant",
        "componentIds": [
          "screen-header",
          "ai-chat-0",
          "ai-chat-1",
          "ai-chat-2",
          "screen-actions"
        ]
      },
      {
        "id": "actions",
        "order": 2,
        "type": "one primary + secondary controls"
      },
      {
        "id": "navigation",
        "order": 3,
        "type": "none"
      }
    ]
  },
  "components": [
    {
      "id": "screen-header",
      "type": "Header",
      "props": {
        "homeLabel": "Nhà Lá",
        "scopeGate": "A/C scoped read + permitted commands only",
        "backTarget": "today",
        "settingsTarget": "settings"
      },
      "tokens": {
        "foreground": "{semantic.light.fg}",
        "darkForeground": "{semantic.dark.fg}"
      },
      "accessibility": {
        "label": "Thanh đầu màn hình",
        "readingOrder": 0,
        "focusOrder": "back then settings"
      }
    },
    {
      "id": "ai-chat-0",
      "type": "ChatThread",
      "props": {
        "user": "Tôi có thể nhờ bạn gì?",
        "assistant": "Bạn có thể tìm việc được phép xem, soạn việc mới hoặc sửa lịch. Mọi thay đổi đều cần bạn xem và xác nhận.",
        "noMutation": true
      },
      "tokens": {
        "background": "{semantic.light.surface}",
        "foreground": "{semantic.light.fg}",
        "darkBackground": "{semantic.dark.surface}",
        "darkForeground": "{semantic.dark.fg}",
        "bodySize": "{primitive.type.body}",
        "touchTarget": "{primitive.space.48}"
      },
      "accessibility": {
        "label": "Nhờ AI · ChatThread",
        "readingOrder": 1,
        "colorOnly": false,
        "fontScaling": true,
        "minimumTouchTarget": 48,
        "instructions": "Đọc theo thứ tự; công bố nhãn trạng thái và lỗi, không chỉ màu."
      }
    },
    {
      "id": "ai-chat-1",
      "type": "AssistantExamples",
      "props": {
        "contentText": "Ví dụ có sẵn · không gọi AI thật  Tạo việc lau bếp mỗi 2 ngày cho An  Tìm việc của tôi  Đổi lịch tưới cây"
      },
      "tokens": {
        "background": "{semantic.light.surface}",
        "foreground": "{semantic.light.fg}",
        "darkBackground": "{semantic.dark.surface}",
        "darkForeground": "{semantic.dark.fg}",
        "bodySize": "{primitive.type.body}",
        "touchTarget": "{primitive.space.48}"
      },
      "accessibility": {
        "label": "Nhờ AI · AssistantExamples",
        "readingOrder": 2,
        "colorOnly": false,
        "fontScaling": true,
        "minimumTouchTarget": 48,
        "instructions": "Đọc theo thứ tự; công bố nhãn trạng thái và lỗi, không chỉ màu."
      }
    },
    {
      "id": "ai-chat-2",
      "type": "Composer",
      "props": {
        "contentText": "Nhập điều bạn cần               Nhập việc bằng tay"
      },
      "tokens": {
        "background": "{semantic.light.surface}",
        "foreground": "{semantic.light.fg}",
        "darkBackground": "{semantic.dark.surface}",
        "darkForeground": "{semantic.dark.fg}",
        "bodySize": "{primitive.type.body}",
        "touchTarget": "{primitive.space.48}"
      },
      "accessibility": {
        "label": "Nhờ AI · Composer",
        "readingOrder": 3,
        "colorOnly": false,
        "fontScaling": true,
        "minimumTouchTarget": 48,
        "instructions": "Đọc theo thứ tự; công bố nhãn trạng thái và lỗi, không chỉ màu."
      }
    },
    {
      "id": "screen-actions",
      "type": "ActionGroup",
      "props": {
        "actions": [
          {
            "id": "link-today",
            "label": "Hôm nay",
            "kind": "navigate",
            "target": "today",
            "confirmationRequired": false
          },
          {
            "id": "link-settings",
            "label": "Cài đặt",
            "kind": "navigate",
            "target": "settings",
            "confirmationRequired": false
          },
          {
            "id": "link-microphone-permission",
            "label": "Nói thay vì gõ",
            "kind": "navigate",
            "target": "microphone-permission",
            "confirmationRequired": false
          },
          {
            "id": "link-task-create",
            "label": "Thêm một việc",
            "kind": "navigate",
            "target": "task-create",
            "confirmationRequired": false
          },
          {
            "id": "example",
            "label": "Chọn ví dụ trợ lý",
            "kind": "select",
            "target": null,
            "confirmationRequired": false
          },
          {
            "id": "send-message",
            "label": "Gửi tin nhắn",
            "kind": "submit",
            "target": "ai-proposal",
            "confirmationRequired": false
          }
        ],
        "primaryCount": 0
      },
      "tokens": {
        "lightBackground": "{component.light.button.background}",
        "lightForeground": "{component.light.button.foreground}",
        "darkBackground": "{component.dark.button.background}",
        "darkForeground": "{component.dark.button.foreground}",
        "height": "{primitive.space.48}"
      },
      "accessibility": {
        "label": "Hành động của màn hình",
        "keyboard": true,
        "focusVisible": true,
        "disabledOnlyLowContrast": true
      }
    }
  ],
  "fields": [],
  "states": [
    {
      "id": "empty",
      "when": "No conversation",
      "visibleUI": "Suggestions + pinned composer",
      "availableActions": [
        "link-today",
        "link-settings",
        "link-microphone-permission",
        "link-task-create",
        "example",
        "send-message"
      ],
      "mutationPolicy": "Actor, exact capability and current versions must still pass; this state never grants rights."
    },
    {
      "id": "typing",
      "when": "Text entered",
      "visibleUI": "Send enabled only nonblank",
      "availableActions": [
        "link-today",
        "link-settings",
        "link-microphone-permission",
        "link-task-create",
        "example",
        "send-message"
      ],
      "mutationPolicy": "Actor, exact capability and current versions must still pass; this state never grants rights."
    },
    {
      "id": "unsupported-freeform",
      "when": "Not a known local example",
      "visibleUI": "Specific clarification or manual route; no fake live AI",
      "availableActions": [
        "link-today",
        "link-settings",
        "link-microphone-permission",
        "link-task-create",
        "example",
        "send-message"
      ],
      "mutationPolicy": "Actor, exact capability and current versions must still pass; this state never grants rights."
    },
    {
      "id": "child",
      "when": "Actor child",
      "visibleUI": "Own chores only; no household/adult/Pro context",
      "availableActions": [
        "link-today",
        "link-settings",
        "link-microphone-permission",
        "link-task-create",
        "example",
        "send-message"
      ],
      "mutationPolicy": "Actor, exact capability and current versions must still pass; this state never grants rights."
    }
  ],
  "actions": [
    {
      "id": "link-today",
      "label": "Hôm nay",
      "kind": "navigate",
      "targetScreenId": "today",
      "permission": "A/C scoped read + permitted commands only",
      "confirmationRequired": false,
      "contractRef": "local navigation"
    },
    {
      "id": "link-settings",
      "label": "Cài đặt",
      "kind": "navigate",
      "targetScreenId": "settings",
      "permission": "A/C scoped read + permitted commands only",
      "confirmationRequired": false,
      "contractRef": "local navigation"
    },
    {
      "id": "link-microphone-permission",
      "label": "Nói thay vì gõ",
      "kind": "navigate",
      "targetScreenId": "microphone-permission",
      "permission": "A/C scoped read + permitted commands only",
      "confirmationRequired": false,
      "contractRef": "local navigation"
    },
    {
      "id": "link-task-create",
      "label": "Thêm một việc",
      "kind": "navigate",
      "targetScreenId": "task-create",
      "permission": "A/C scoped read + permitted commands only",
      "confirmationRequired": false,
      "contractRef": "local navigation"
    },
    {
      "id": "example",
      "label": "Chọn ví dụ trợ lý",
      "kind": "select",
      "targetScreenId": null,
      "permission": "A/C scoped read + permitted commands only",
      "confirmationRequired": false,
      "contractRef": "local view context"
    },
    {
      "id": "send-message",
      "label": "Gửi tin nhắn",
      "kind": "submit",
      "targetScreenId": "ai-proposal",
      "permission": "A/C scoped, no direct writes",
      "confirmationRequired": false,
      "contractRef": "PROPOSED ai.parse (deterministic examples only in preview)"
    }
  ],
  "dataBindings": [
    {
      "source": "localized local design scenario / proposed assistant adapter",
      "shape": {
        "messages": "{speaker,text}[] scoped and minimized",
        "intent": "allowlisted proposed command",
        "resolved_ids": "same-home IDs only"
      },
      "sample": {
        "messages": [
          {
            "speaker": "user",
            "text": "Tạo việc lau bếp mỗi 2 ngày cho An"
          }
        ],
        "intent": "create_task",
        "resolved_ids": {
          "room_id": "kitchen",
          "member_id": "an"
        }
      },
      "sampleOnly": true,
      "actorConstraint": "Adult example only; child requests MUST bind ChildTodayDto/ChildHistoryDto/ChildOccurrenceDto own scope; no adult IDs/contact/roster",
      "envelope": "API refs use CommandEnvelope; local review context is not an API property."
    }
  ],
  "copy": {
    "heading": "Nhờ AI",
    "primary": null,
    "empty": null,
    "notices": [],
    "locale": "vi",
    "demoLabel": "Bản thiết kế · dữ liệu mẫu · không kết nối dịch vụ"
  },
  "implementation": {
    "nativeRoute": "/design/ai-chat",
    "nativeRouteStatus": "proposed mapping, verify against implementing native navigator",
    "apiRefs": [],
    "newContractRefs": [
      "ai-agent-contract.json"
    ],
    "notes": [
      "Preview examples are deterministic local handlers. Future provider/STT/gating undecided. Child AI variant dynamically uses own data, not adult transcript.",
      "Tất cả ví dụ là dữ liệu thiết kế, không bằng chứng native/API/store đã chạy.",
      "Native route dưới đây là đề xuất mapping cho agent, không tuyên bố route source đã tồn tại.",
      "Mọi mutation dùng envelope {data,version,household_revision,replayed}, stable Idempotency-Key và expected_version khi sửa."
    ],
    "integrationStatus": "design complete; local static/draft interactions; native/API adapters pending",
    "sourceAuthority": [
      "docs/product-brief.md",
      "plans/261013-1409-sweepy-vietnam-mobile/mobile-flows.md",
      "plans/261013-1409-sweepy-vietnam-mobile/api-contracts.md",
      "packages/domain/src/contracts/phase2.ts",
      "packages/domain/src/index.ts",
      "packages/domain/src/contracts/phase3.ts",
      "packages/domain/src/contracts/billing.ts",
      "apps/mobile/src/lib/api.ts"
    ],
    "capability": "A/C scoped read + permitted commands only",
    "errors": {
      "401": "Stop queue; adult login or child re-pair without parent account.",
      "403": "Do not retry lost capability. FEATURE_REQUIRED never grants Pro.",
      "409": "Fetch canonical scoped state; review/reconfirm new intent, do not rewrite old replay payload.",
      "422": "Field error with retained draft.",
      "429": "Respect Retry-After.",
      "503": "Backoff only retryable commands with original key."
    }
  }
}
