• erio's avatar
    feat(channel-monitor): request templates with snapshot apply + headers/body override · a2964259
    erio authored
    Problem:
    Upstream channels can reject monitor probes based on client fingerprint
    (e.g. "only Claude Code clients allowed"). The monitor had no way to
    customize the outgoing request to bypass such restrictions.
    
    Solution:
    Introduce reusable request templates that carry extra_headers plus an
    optional body override; monitors reference a template and receive a
    snapshot copy on apply. Template edits do NOT auto-propagate — users
    must click "apply to associated monitors" to refresh snapshots, so a
    bad template edit cannot instantly break all production monitors.
    
    Data model (migration 112):
    - channel_monitor_request_templates: id, name, provider, description,
      extra_headers jsonb, body_override_mode ('off'|'merge'|'replace'),
      body_override jsonb. Unique (provider, name).
    - channel_monitors: +template_id (FK, ON DELETE SET NULL), +extra_headers,
      +body_override_mode, +body_override (the three runtime snapshot fields).
    
    Checker (channel_monitor_checker.go):
    - callProvider + runCheckForModel accept a CheckOptions carrying the
      snapshot fields. mergeHeaders applies user headers on top of adapter
      defaults (forbidden list: Host / Content-Length / Transfer-Encoding /
      Connection / Content-Encoding).
    - buildRequestBody:
        off     -> adapter default body
        merge   -> shallow-merge over default; per-provider deny list
                   (model/messages/contents) protects the challenge contract
        replace -> user body verbatim
    - Replace mode skips challenge validation; instead HTTP 2xx + non-empty
      extracted response text = operational, empty = failed.
    - 4 new unit tests cover all three modes + replace/empty-response case.
    
    Admin API:
    - /admin/channel-monitor-templates CRUD + /:id/apply (overwrite snapshot
      on all template_id=id monitors, returns affected count).
    - channel_monitor request/response DTOs gain the 4 new fields.
    
    Frontend:
    - channelMonitorTemplate.ts API client.
    - MonitorAdvancedRequestConfig.vue shared component for headers textarea
      + body mode radio + body JSON editor; used by both template and monitor
      forms.
    - MonitorTemplateManagerDialog.vue: provider tabs, list/create/edit/
      delete/apply, live "associated monitors" count per row.
    - MonitorFiltersBar: new 模板管理 button next to 新增监控.
    - MonitorFormDialog: collapsible 高级 section with template dropdown
      (filtered by form.provider, clears on provider change) + embedded
      AdvancedRequestConfig. Picking a template copies its fields into the
      form (snapshot semantics mirrored on the client).
    - i18n zh/en entries for all new copy.
    
    chore: bump version to 0.1.114.32
    a2964259
wire.go 17.9 KB