1. 23 Apr, 2026 4 commits
    • erio's avatar
      sync: bring over remaining release/custom-0.1.115 changes · 748a84d8
      erio authored
      - Extract PublicSettingsInjectionPayload named struct with drift test
      - Add channel_monitor_default_interval_seconds to SSR injection
      - Add image_output_price to SupportedModelChip
      - Simplify AppSidebar buildSelfNavItems (admins see available channels)
      - Add gateway WARN logs for 503 no-available-accounts branches
      - Wire ChannelMonitorRunner into provideCleanup for graceful shutdown
      - Add migrations 130/131 (CC template userid fix + mimicry field cleanup)
      - Clean up fork-only features (sora, claude max simulation, client affinity)
      - Remove ~320 obsolete i18n keys
      - Add codexUsage utility, WechatServiceButton, BulkEditAccountModal
      - Tidy go.sum
      748a84d8
    • erio's avatar
      test(payment): cover ErrOrderNotFound sentinel contract · d5dac84e
      erio authored
      Service layer (payment_fulfillment_order_not_found_test.go):
      - TestHandlePaymentNotification_UnknownOrder_ReturnsSentinel: in-memory
        sqlite ent client, query for a non-existent out_trade_no → errors.Is
        must recognise ErrOrderNotFound (handler relies on this to ack 200).
      - TestHandlePaymentNotification_NonSuccessStatus_Skips: non-success
        notification short-circuits before DB lookup → nil error.
      - TestErrOrderNotFound_DistinctFromOtherErrors: generic errors must not
        match the sentinel (prevents silently swallowing DB failures).
      
      Handler layer (payment_webhook_handler_test.go):
      - TestUnknownOrderWebhookAcksWithSuccess: locks the two ingredients the
        handleNotify ack path depends on — fmt.Errorf %w wrapping preserves
        errors.Is recognition, and writeSuccessResponse(stripe) returns an
        empty 200 body that Stripe treats as acknowledged.
      d5dac84e
    • erio's avatar
      fix(payment): ack unknown-order webhooks with 2xx to stop provider retries · 75e1b40f
      erio authored
      Introduce a sentinel ErrOrderNotFound in the payment service layer so the
      webhook handler can distinguish "the out_trade_no does not exist in our DB"
      from other fulfillment failures, and downgrade the former to a WARN log +
      success response.
      
      Background
      - Providers (Stripe, Alipay, Wxpay, EasyPay, ...) retry webhooks whenever
        we answer non-2xx. When a webhook endpoint is misconfigured (e.g. a
        foreign environment points at us) or our orders table has been wiped,
        we return 500 forever and the provider retries for days, spamming logs.
      - The old code also collapsed "order not found" and "DB query failed" into
        the same branch — a DB blip would be reported as "order not found" and
        swallowed.
      
      Service layer (payment_fulfillment.go)
      - Add `var ErrOrderNotFound = errors.New("payment order not found")`.
      - In HandlePaymentNotification, distinguish the two error paths:
        * dbent.IsNotFound(err) → wrap with ErrOrderNotFound so callers can
          errors.Is(...) it.
        * anything else → wrap the original err with %w so it still bubbles up
          as 500 and the provider retries (DB hiccup should be retried).
      
      Handler layer (payment_webhook_handler.go)
      - Before returning 500, check errors.Is(err, service.ErrOrderNotFound):
        emit a WARN (with provider / outTradeNo / tradeNo for discoverability),
        then call writeSuccessResponse so the provider sees its expected 2xx
        body (Stripe empty body / Wxpay JSON / others "success").
      - Other errors retain the existing 500 behavior.
      
      Monitoring note: because this path now swallows unknown-order webhooks
      silently from the provider's perspective, the WARN log line is the only
      signal. Alert on "unknown order, acking to stop retries" if you want
      visibility into misrouted webhooks or accidental data loss.
      75e1b40f
    • erio's avatar
      fix(dto): drop obsolete public settings drift test · 1949425a
      erio authored
      The drift test referenced service.PublicSettingsInjectionPayload, a
      named type introduced by a5b05538 but dropped when we cherry-picked
      that commit into feat/channel-insights (we kept the inline struct from
      HEAD to avoid pulling fork-only helpers from setting_service.go). The
      test therefore could not compile. The 2 new public-settings fields
      (channel_monitor_enabled, available_channels_enabled) are still covered
      by manual wiring in GetPublicSettingsForInjection.
      1949425a
  2. 22 Apr, 2026 1 commit
    • erio's avatar
      fix(channels): supported models = mapping ∪ pricing with global LiteLLM fallback · 6cd7c605
      erio authored
      Why: channels with model pricing entries but no model mapping (e.g. azcc with
      3 priced claude models, no mapping) were rendering as 未配置模型 in the
      'Available Channels' page. The algorithm only iterated ModelMapping and
      silently dropped any platform without a mapping entry.
      
      Changes:
      - channel.go: SupportedModels now unions mapping + pricing entries.
        For exact mapping src → target, pricing is looked up by target (the actually
        billed name), not by src.
      - channel_available.go: ListAvailable enriches each entry with nil pricing
        via PricingService.GetModelPricing (global LiteLLM fallback) so the popover
        always shows a price.
      - channel_service.go: NewChannelService takes *PricingService as 4th param.
      - channel_test.go: rewrote 4 tests that froze the old mapping-only semantics;
        added pricing-only / mapping-target / target-missing coverage.
      6cd7c605
  3. 21 Apr, 2026 8 commits
    • erio's avatar
      feat(channels): themed model popover + group-badge with rate, subscription & exclusivity · ff4ef1b5
      erio authored
      Pricing popover:
      - Teleport to body + fixed-position re-measuring on hover/scroll/resize so it
        escapes the card's overflow-hidden clip that was chopping off the lower
        half of the panel.
      - Header + border adopt the platform theme via platformBorderClass /
        platformBadgeLightClass so each model card reads at a glance.
      
      Accessible groups:
      - Backend AvailableGroupRef / user DTO now expose subscription_type,
        rate_multiplier and is_exclusive. User-specific rates continue to come
        from /groups/rates (same pattern as the API keys page).
      - Table renders groups through the shared GroupBadge, which already deepens
        subscription-type colors and shows default vs custom rate as
        <s>default</s> <b>custom</b>.
      - Exclusive groups are labelled with a purple shield row, public groups
        with a grey globe row so admins and users can tell at a glance which
        groups they got via explicit grant vs. public access.
      
      i18n keys for exclusive / public / their tooltips added to zh + en.
      ff4ef1b5
    • erio's avatar
      fix(settings): inject channel_monitor & available_channels into SSR payload · 84b03efa
      erio authored
      Root cause: GetPublicSettingsForInjection used an inline struct that silently
      drifted from dto.PublicSettings and omitted channel_monitor_enabled /
      available_channels_enabled. On refresh window.__APP_CONFIG__ lacked these
      keys, so cachedPublicSettings.available_channels_enabled resolved to
      undefined and the opt-in sidebar entry (=== true) disappeared.
      
      Backend: extract PublicSettingsInjectionPayload as a named type with all
      feature-flag fields wired, and add a reflect-based drift test in the dto
      package so forgetting a future flag fails CI instead of the browser.
      
      Frontend: introduce utils/featureFlags.ts as the single registry for
      public-settings-driven toggles, with explicit opt-in / opt-out modes that
      encode the pre-load fallback. AppSidebar switches to makeSidebarFlag() so
      adding a new switch only touches the registry.
      84b03efa
    • erio's avatar
      feat(channels): aggregate by channel with platform sections + rowspan table · 3cdd5754
      erio authored
      Switch the user-facing 'Available Channels' view from "one row per
      platform" to "one channel row-group with N platform sections".
      
      Backend: userAvailableChannel now holds Platforms []section instead
      of being exploded. buildPlatformSections replaces
      explodeChannelByPlatform with the same per-platform grouping logic.
      
      Frontend: drop the DataTable wrapper for this view and write a
      four-column grid table (渠道名 / 平台 / 分组 / 支持模型) where the
      channel name only renders on the first platform row of each channel —
      visual rowspan without hacking DataTable.
      
      - api/channels.ts: UserChannelPlatformSection + platforms[]
      - AvailableChannelsTable: rewritten as native grid (header + per-
        channel section with hover row highlight)
      - AvailableChannelsView: search now filters platforms sub-array;
        channel-name / description hits still keep the whole channel
      - i18n: add availableChannels.columns.platform (zh/en)
      3cdd5754
    • erio's avatar
      feat(channels): explode available channels by platform + apply platform theme · 800802b8
      erio authored
      Backend: one source channel → N output rows, one per platform that
      has user-visible groups. Each row carries a single platform, so the
      frontend can color/icon an entire row without mixing sources.
      
      - userAvailableChannel: add Platform field
      - new explodeChannelByPlatform helper; drop now-redundant
        collectGroupPlatforms
      
      Frontend: use the row platform to drive theming and stop repeating
      "ANTHROPIC" / "OPENAI" labels on every model chip.
      
      - api/channels.ts: UserAvailableChannel.platform
      - AvailableChannelsTable: name cell — PlatformBadge next to channel
        name (replaces the two-line name/description block; description
        moves to the badge's title tooltip); groups cell — each chip uses
        platformBadgeLightClass + PlatformIcon; model list passes
        show-platform=false + platform-hint to child chips
      - SupportedModelChip: chip bg/border driven by platformBadgeClass,
        leading PlatformIcon; platform-hint fallback when model.platform
        missing
      800802b8
    • erio's avatar
      feat(channels): gate available channels behind feature switch (backend) · 9ba42aa5
      erio authored
      Add a DB-backed soft switch "available_channels_enabled" controlling
      the user-facing /channels/available endpoint and sidebar entry. Default
      to false (opt-in) — the feature stays invisible until an admin enables
      it under Admin Settings > Features.
      
      - domain_constants: SettingKeyAvailableChannelsEnabled
      - settings_view: AllSettings/PublicSettings + AvailableChannelsEnabled
      - setting_service: public+all read/write, seed default "false",
        GetAvailableChannelsRuntime helper (fail-closed on read error)
      - admin setting_handler: UpdateSettingsRequest *bool + update branch
        + audit diff entry
      - public setting_handler: expose via GET /api/v1/settings
      - available_channel_handler: featureEnabled() guard — returns empty
        list after auth when disabled (401 precedes the feature check to
        preserve existing behavior)
      9ba42aa5
    • erio's avatar
      chore(channels): drop admin-side available channels view · 59290e39
      erio authored
      Remove the admin-side "Available Channels" aggregate view — admins
      already see full channel configuration (groups, pricing, model
      mappings) in the channel edit dialog, making a read-only admin
      aggregate view redundant. The user-side "可用渠道" remains.
      
      Backend:
      - Delete handler/admin/available_channel_handler.go (+ test)
      - Drop AdminHandlers.AvailableChannel field and wire injection
      - Remove /admin/channels/available route
      
      Frontend:
      - Delete views/admin/AvailableChannelsView.vue
      - Drop /admin/available-channels router entry
      - Strip AvailableChannel types + listAvailable from api/admin/channels.ts
      59290e39
    • erio's avatar
      refactor(channels): normalize at cache fill and eliminate frontend as-cast · 4a3652ec
      erio authored
      - channel.go: convert normalizeBillingModelSource into a (*Channel) method for entity cohesion
      - channel_service.go: normalize in populateChannelCache so every cache-backed reader (gateway, billing, future endpoints) sees the default; drop the duplicate fallback inside resolveMapping
      - table: tighten Row with status?: ChannelStatus / billing_model_source?: BillingModelSource, remove the [key: string]: unknown index signature
      - admin view: drop the `as ChannelStatus` / `as BillingModelSource` assertions and add statusStyleOf / billingSourceLabelOf helpers with runtime fallback so unseen values render as "-" instead of crashing
      4a3652ec
    • erio's avatar
      refactor(channels): centralize BillingModelSource normalization and exhaustive enum maps · 375aefa2
      erio authored
      - service: add normalizeBillingModelSource helper, apply in Create/GetByID/Update/List/ListAvailable outputs
      - handler: drop channelToResponse fallback now that service owns the default; add passthrough test
      - frontend: replace ternary status/billing-source lookups with Record<Enum, ...> maps so new union members fail the build
      - chip/table: drop local type aliases, reuse UserSupportedModel/UserPricingInterval directly
      - tests: assert short-circuit on ListAll error, wrap-prefix preservation, and Name-based default lookup
      375aefa2
  4. 20 Apr, 2026 3 commits
    • erio's avatar
      refactor(channels): tighten types and error paths per second review · 88decb6e
      erio authored
      - service: drop groupRepo nil guard (DI must inject), switch SupportedModels to SliceStable to match doc
      - frontend: reuse user-side DTO types in SupportedModelChip/AvailableChannelsTable instead of duplicating shapes; narrow admin statusLabel param to ChannelStatus
      - tests: replace nil-groupRepo case with ListAll/ListActive error propagation and BillingModelSource default-backfill coverage
      88decb6e
    • erio's avatar
      refactor(channels): consolidate pricing index, tighten types, polish DTOs · 365ef1fd
      erio authored
      Follow-up to the available-channels review pass. No behavior change for
      end users; tightens internals based on three independent code reviews.
      
      Backend
      - service/channel.go: collapse buildPricingLookup + pricedNamesFor
        into a single platformPricingIndex (byLower + originalCase + ordered
        names), built once per SupportedModels call. Fixes a casing-
        consistency bug where the same logical model appeared with mapping
        case in the exact branch but pricing case in the wildcard branch —
        pricing's original case now wins everywhere.
      - service/channel.go: doc that a mapping key of just "*" expands to
        every priced model on the platform (intentional "passthrough all").
      - service/channel_available.go: normalize empty BillingModelSource to
        channel_mapped at construction time, removing the same fallback
        duplicated in the admin DTO mapper and the admin Vue template.
      - handler/admin/available_channel_handler.go: unexport
        availableChannelToAdminResponse (same-package usage only); mapper
        is now a pure passthrough.
      - handler/available_channel_handler.go: drop the middleware2 alias
        (no name collision in this file).
      
      Frontend
      - utils/pricing.ts: extract formatScaled, used by SupportedModelChip
        and PricingRow.
      - api/admin/channels.ts: re-export BillingMode from constants/channel;
        tighten Channel.status / billing_model_source to ChannelStatus /
        BillingModelSource (and same for AvailableChannel).
      - components/channels/AvailableChannelsTable.vue: drop dead
        withDefaults wrapper (loading is required, both call sites pass it).
      - views/admin/AvailableChannelsView.vue: drop the redundant
        || BILLING_MODEL_SOURCE_CHANNEL_MAPPED fallback (now applied in
        service layer); remove unused import.
      - i18n zh + en: delete unused tierLabel and tokenRange keys from
        both availableChannels.pricing and admin.availableChannels.pricing.
      
      Tests
      - New: SupportedModels_ExactKeyUsesPricedCaseWhenAvailable locks the
        pricing-case-wins rule.
      - New: SupportedModels_AsteriskOnlyMappingExpandsAllPriced documents
        the "*" expansion rule.
      - Admin handler: existing tests adjusted to pass an explicit
        BillingModelSource (default-fill is now exercised by service tests).
      365ef1fd
    • erio's avatar
      feat(channels): add "Available Channels" aggregate view · 654cfb64
      erio authored
      Add a read-only aggregate view per channel: its linked groups and a
      deterministic wildcard-free supported-model list with pricing details.
      
      Backend
      - service.Channel.SupportedModels(): combine ModelMapping keys with
        same-platform ModelPricing.Models; trailing "*" keys expand via
        pricing prefix match; platforms without a mapping produce no
        entries (intentional "no mapping = not shown" rule).
      - Extract splitWildcardSuffix() shared with toModelEntry.
      - Build a per-call pricing lookup map (platform+lowerName -> *pricing)
        to avoid O(N*M) scans in SupportedModels.
      - ChannelService.ListAvailable() aggregates channels + active groups;
        filters out group IDs no longer active.
      - Admin route GET /api/v1/admin/channels/available returns the full
        DTO (id, status, billing_model_source, restrict_models, groups,
        supported_models).
      - User route GET /api/v1/channels/available applies three filters:
        Status==active, visible-group intersection, and platform filter
        on supported_models (prevents cross-platform leak when a channel
        links to both a user-accessible group and an inaccessible one on
        another platform). Response is a plain array (matches the
        /groups/available sibling shape). Field whitelist omits
        billing_model_source, restrict_models, ids, status, sort_order.
      
      Frontend
      - New /admin/available-channels and /available-channels views backed
        by a shared AvailableChannelsTable component (admin adds status +
        billing-source columns via slots).
      - PricingRow extracted to its own SFC; SupportedModelChip references
        shared billing-mode constants in constants/channel.ts.
      - Sidebar: new entry above "渠道管理" for admin; matching entry in
        user nav.
      - i18n: zh + en coverage for both namespaces.
      
      Tests
      - SupportedModels: wildcard-only pricing skipped, prefix-matches-
        nothing, cross-platform bleed, case-insensitive dedup, empty
        platform mapping.
      - ListAvailable: nil groupRepo, inactive-group-ID dropped, stable
        case-insensitive name sort.
      - User handler: 401 on unauthenticated, visible-group intersection,
        platform filter on supported_models, JSON whitelist.
      - Admin handler: full DTO including default BillingModelSource
        fallback.
      
      Refs: issue #1729
      654cfb64
  5. 22 Apr, 2026 2 commits
    • erio's avatar
      refactor(channel-monitor): tighten runner lifecycle + add unit tests · c46744f3
      erio authored
      - pool 改在 NewChannelMonitorRunner 构造时初始化,消除 Start 在 mu 内
        赋值、fire/Stop 在 mu 外读取的竞态隐患
      - Schedule 在 !started 时由静默 return 改为 slog.Warn,错过的调度可见
      - Schedule 在 interval<=0 时升为 slog.Error:Create/Update validateInterval
        已保证不可达,真触发即数据/校验链 bug
      - 抽出 monitorRunnerSvc 内部接口(仅 ListEnabledMonitors+RunCheck),
        生产 *ChannelMonitorService 自然满足;runner 单元测试可注入轻量 stub
      - 新增 channel_monitor_runner_test.go(10 个用例,//go:build unit):
        覆盖 Schedule/Unschedule/Start/Stop 生命周期、in-flight 槽对称释放、
        Stop 等待正在执行的 RunCheck 退出(无游离 goroutine)
      
      启动失败的恢复策略:保持现状(log+return)。CLAUDE.md 明确"配置应保证启动
      成功(必填项校验+正确数据校验)",validate{Provider,Interval,Endpoint,
      APIKey,PrimaryModel} 已在 Create/Update 全部覆盖;DB 不可用是基础设施问题,
      不该靠应用层无限重试兜底。
      c46744f3
    • erio's avatar
      refactor(channel-monitor): event-driven scheduler + sidebar cleanup · c2f9ad7a
      erio authored
      后端 - ChannelMonitorRunner 重写为事件驱动调度
      - 删除 5 秒轮询架构(每次 ListEnabled + listDueForCheck 全表扫描),
        改为每个 enabled monitor 一个独立 goroutine + ticker(按各自 IntervalSeconds)
      - 新增 MonitorScheduler 接口,service 通过 setter 注入避免依赖环
      - ChannelMonitorService.Create/Update/Delete 直接回调 scheduler.Schedule/Unschedule
      - runner.Start 一次性加载所有 enabled monitor 建立任务表
      - 新建/启用立即触发首次检测,禁用/删除即时撤销 ticker
      - 保留 inFlight 去重 + pond 池并发上限 + 全局开关每次 fire 实时校验
      - 删除 listDueForCheck / monitorTickerInterval / monitorListDueTimeout
      
      前端 - 可用渠道改为用户级菜单
      - 从 adminNavItems 移除 /available-channels(admin 主菜单不再重复出现)
      - buildSelfNavItems 始终包含可用渠道入口,普通用户主菜单和
        管理员"我的账户"区都能看到
      c2f9ad7a
  6. 21 Apr, 2026 4 commits
    • erio's avatar
      feat(monitor): 30-day raw retention + timeline 4-tier style + CC template seed + JSON format button · a7415d4d
      erio authored
      - History retention 1d → 30d(60s × 30d ≈ 43200 行/model,PG 无压力);
        ComputeAvailability* 不再 UNION rollup 表,直接扫 histories 精度更高。
      - Timeline bar 四级高度+颜色双重编码:operational 高+绿 / degraded 中+黄 /
        failed+error 短+红 / 未测试 很短+灰。
      - migration 113 seed「Claude Code 伪装」模板(ON CONFLICT DO NOTHING)。
        user_id 用 legacy 格式(user_<64hex>_account_<uuid>_session_<uuid>),
        避免新版 JSON 字符串内嵌 JSON 在编辑器里一长串 \" 难读。
      - MonitorAdvancedRequestConfig 加「格式化」按钮 + white-space:pre
        让 body textarea 对长字符串不压扁。
      a7415d4d
    • erio's avatar
      feat(channel-monitor): apply template via subset picker; CC 2.1.114 baseline doc · 6925ac25
      erio authored
      Apply flow:
      - POST /admin/channel-monitor-templates/:id/apply now requires monitor_ids
        (non-empty array). Service applies the template only to the selected
        subset, gated by AND template_id = :id (so users can't sneak in
        unrelated monitor IDs).
      - New GET /admin/channel-monitor-templates/:id/monitors returns the
        associated monitor briefs (id/name/provider/enabled) for the picker.
      - ApplyToMonitors signature gains monitorIDs []int64; empty list returns
        ErrChannelMonitorTemplateApplyEmpty.
      
      Frontend:
      - New MonitorTemplateApplyPickerDialog.vue: list of associated monitors
        with checkboxes (default all checked), 全选 / 全不选 shortcuts, live
        selected/total count. Submit calls apply(id, ids).
      - MonitorTemplateManagerDialog replaces the old ConfirmDialog flow with
        the picker; onApplied refetches the list to refresh associated counts.
      
      i18n: applyPicker* + common.selectAll keys.
      
      chore: bump version to 0.1.114.33
      
      The CC 2.1.114 (sdk-cli) UA / APIKeyBetaHeader / JSON metadata.user_id
      baseline (already verified working via the in-process apply on prod
      template id=1) is documented in internal/pkg/claude/constants.go and
      is what the seed template in the manager UI should follow.
      6925ac25
    • 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
    • erio's avatar
      feat(channel-monitor): preserve upstream error body · b363bff1
      erio authored
      Monitor:
      - callProvider now returns both textPath-extracted text and raw body;
        runCheckForModel uses rawBody on non-2xx so history.message stops being
        "upstream HTTP 503: " with empty body (gjson textPath produces "" for
        error responses like {"error":{"message":"No available accounts..."}})
      - truncateForErrorBody collapses whitespace then caps at 300 bytes
        (monitorErrorBodySnippetMaxBytes); final truncateMessage still enforces
        the 500-byte DB column cap
      
      Frontend:
      - MonitorFormDialog: primary_model input text color and ModelTagInput tags
        now both track form.provider (via new getPlatformTextClass + existing
        getPlatformTagClass with platform prop).
      
      (cherry-picked from 1d3b0418; dropped gateway_handler logging改动,不在本 PR 范围)
      b363bff1
  7. 23 Apr, 2026 1 commit
    • erio's avatar
      fix(channel-monitor): drop soft delete, refactor feature flag to declarative form · ef6ec8a1
      erio authored
      ### 后端修复:日志表不该用软删除
      
      channel_monitor_histories / channel_monitor_daily_rollups 都是日志/聚合表,
      没有恢复需求。110 里加的 SoftDeleteMixin 会让 DELETE 自动变成 UPDATE deleted_at,
      导致行和索引只增不减,徒增磁盘占用和查询成本。
      
      改回分批物理删(参考 OpsCleanupService.deleteOldRowsByID 模板):
      
      - ent schema 移除 SoftDeleteMixin,重新 go generate
      - repo 新增 deleteChannelMonitorBatched 辅助 + 两条 prune SQL 常量
        (WITH batch AS SELECT id LIMIT 5000 → DELETE IN batch)
      - DeleteHistoryBefore / DeleteRollupsBefore 改调分批 raw SQL
      - 移除 ComputeAvailability / ComputeAvailabilityForMonitors / UpsertDailyRollupsFor /
        ListLatestPerModel / ListLatestForMonitorIDs / ListRecentHistoryForMonitors 等
        raw SQL 中的 deleted_at IS NULL 过滤
      - UpsertDailyRollupsFor 的 ON CONFLICT 去掉 deleted_at = NULL 重置
      - migration 111 DROP COLUMN deleted_at + 对应索引(110 已部署但 maintenance
        首跑在次日 02:00,此时尚无业务数据在依赖软删除)
      
      ### 前端重构:feature flag 声明式 + 复用
      
      AppSidebar.vue 里 7 处 `...(flag ? [item] : [])` 样板代码删光,改为 NavItem 加
      featureFlag?: () => boolean | undefined 字段,加一个 applyFeatureFlags 递归
      过滤(含 children)。语义统一为 `!== false`(宽容策略,undefined 时默认显示,
      避免 public settings 未加载完成时菜单闪烁消失 — 对应用户反馈"刷新后菜单消失
      要去保存设置才回来")。
      
      - 集中声明 4 个 flag getter:flagChannelMonitor / flagPayment /
        flagOpsMonitoring / flagAdminPayment
      - 提取 buildSelfNavItems 复用用户端主菜单和管理员"我的账户"子菜单
      - 未来新增开关:在统一位置加一个 flag getter + 给对应 NavItem 加字段
        (不用再动渲染逻辑)
      
      bump 0.1.114.29
      ef6ec8a1
  8. 21 Apr, 2026 1 commit
    • erio's avatar
      feat(channel-monitor): aggregate history to daily rollups + soft delete · 8cf83c98
      erio authored
      明细只保留 1 天,超过 1 天聚合到新表 channel_monitor_daily_rollups(按
      monitor_id/model/bucket_date 维度),聚合保留 30 天。两张表都用 SoftDeleteMixin
      软删除(DELETE 自动改为 UPDATE deleted_at = NOW())。
      
      聚合 + 清理任务由 OpsCleanupService 的 cron 统一调度,与运维监控的清理共享
      schedule(默认 0 2 * * *)和 leader lock。ChannelMonitorRunner 的 cleanupLoop
      被移除,只保留 dueCheckLoop。
      
      读取路径 ComputeAvailability* 改为 UNION 明细(今天 deleted_at IS NULL)+
      聚合(过去 windowDays 天 deleted_at IS NULL),SUM(ok)/SUM(total) 自然加权
      计算可用率,AVG latency 用 SUM(sum_latency_ms)/SUM(count_latency)。
      
      watermark 表 channel_monitor_aggregation_watermark 单行(id=1),记录
      last_aggregated_date,重启后从该日期 +1 继续聚合,首次为 nil 则从
      today - 30d 开始回填,单次最多 35 天上限避免长事务。
      
      raw SQL 的 ListLatestPerModel / ListLatestForMonitorIDs / ListRecentHistoryForMonitors
      都补上 deleted_at IS NULL 过滤(SoftDeleteMixin interceptor 只对 ent query 生效)。
      
      bump version to 0.1.114.28
      
      GroupBadge 在 MonitorKeyPickerDialog 中复用平台主题色 + 倍率/专属倍率
      (顺手优化)。
      8cf83c98
  9. 20 Apr, 2026 3 commits
    • erio's avatar
      feat(channel-monitor): add feature switch settings + fix extra_models save · 7da51240
      erio authored
      Settings:
      - New "功能开关" tab between 通用设置 and 安全与认证
      - ChannelMonitorEnabled toggle: runner skips scheduling when false,
        user-facing list returns empty
      - ChannelMonitorDefaultIntervalSeconds (15-3600): pre-fills interval
        when creating a new monitor; each monitor can still override
      
      Bug fix:
      - ModelTagInput now commits pending input on blur, not just Enter/Tab.
        Previously clicking "save" with an un-Enter'd extra model would drop
        the value (DB stored extra_models=[] even when user typed entries).
      
      Backend:
      - domain_constants: SettingKeyChannelMonitor{Enabled,DefaultIntervalSeconds}
      - SettingService.GetChannelMonitorRuntime: lightweight getter used by
        runner tick + user handler per-request (fail-open on DB error)
      - Runner tickDueChecks: bails early when feature disabled
      - ChannelMonitorUserHandler: checks feature flag before serving
      - Comment on runner doc: scheduler state is implicit (every tick re-reads
        ListEnabled from DB), so CRUD ops on monitors self-maintain the schedule
      
      Bump VERSION to 0.1.114.25
      7da51240
    • erio's avatar
      feat(channel-monitor): redesign user dashboard as card grid · a1425b45
      erio authored
      Reference check-cx UI: INTELLIGENCE MONITOR hero + 3-column card grid
      with 60-point timeline bars.
      
      Backend:
      - Add PrimaryPingLatencyMs + Timeline[60] to UserMonitorView
      - ListRecentHistoryForMonitors: batch CTE + ROW_NUMBER() window query
      - indexLatestByModel / indexAvailabilityByModel helpers
      
      Frontend:
      - 7 new components: ProviderIcon, MonitorMetricPair, MonitorAvailabilityRow,
        MonitorTimeline, MonitorHero, MonitorCard, MonitorCardGrid
      - ChannelStatusView 381→~180 lines (delegated to subcomponents)
      - AbortController reload concurrency protection
      - HSL 0-120° availability color mapping
      - Replace emoji with Icon component (bolt / globe)
      - i18n: monitorCommon.* shared namespace, channelStatus.hero.*
      
      Bump VERSION to 0.1.114.24
      a1425b45
    • erio's avatar
      feat(monitor): admin channel monitor MVP with SSRF protection and batch aggregation · 20a4e418
      erio authored
      新增 admin「渠道监控」模块(参考 BingZi-233/check-cx),独立于现有 Channel 体系。
      admin 配置 + 后台定时调用上游 LLM chat completions 健康检查 + 所有登录用户只读可见。
      
      后端:
      - ent: channel_monitor + channel_monitor_history(AES-256-GCM 加密 api_key)
      - service 按职责拆分:service/aggregator/validate/checker/runner/ssrf
      - provider strategy map 替代 switch(openai/anthropic/gemini)
      - repository batch 聚合(ListLatestForMonitorIDs + ComputeAvailabilityForMonitors)消除 N+1
      - runner: ticker(5s) + pond worker pool(5) + inFlight 防并发 + TrySubmit 防雪崩
        + 凌晨 3 点 cron 清理 30 天历史
      - SSRF 防护:强制 https + 私网/loopback/云元数据 IP 拒绝(127/8、10/8、172.16/12、
        192.168/16、169.254/16、100.64/10、::1、fc00::/7、fe80::/10)+ DialContext
        在 socket 层防 DNS rebinding
      - API key sanitize:擦除 url.Error 与上游响应 body 中的 sk-/sk-ant-/AIza/JWT 模式
      - APIKeyDecryptFailed 标志位 + 单 monitor 路径检测,避免空 key 调用上游
      
      handler:
      - admin: CRUD + 手动触发 + 历史接口(api_key 脱敏)
      - user: 只读列表 + 状态详情(去除 api_key/endpoint)
      - ParseChannelMonitorID 共用 + dto.ChannelMonitorExtraModelStatus 共用
      
      前端:
      - 路由 /admin/channels/{pricing,monitor} + /monitor(用户只读)
      - AppSidebar 父项 expandOnly 支持
      - ChannelMonitorView 拆为 8 个子组件 + ChannelStatusView 拆出 detail dialog
      - composables/useChannelMonitorFormat + constants/channelMonitor 共享
      - i18n monitorCommon namespace 消除 admin/user 两 view 重复
      
      合规:所有文件符合 CLAUDE.md(Go ≤ 500 行 / Vue ≤ 300 行 / 函数 ≤ 30 行)
      CI: go build / gofmt / golangci-lint(0 issues) / make test-unit / pnpm build 全绿
      20a4e418
  10. 23 Apr, 2026 2 commits
  11. 22 Apr, 2026 11 commits