# dsh-lark-bot as a profile bundle.
#
# Installed with `dsh plugin --profile <name> add dsh-lark-bot` (or the single
# `dsh-lark-bot setup` command), dsh appends this package to the profile's
# `dsh.profile.bundles` and applies this patch on boot:
#   - `dsh-lark-bot/plugin` starts the full bridge engine IN-PROCESS (Feishu
#     channel, workspace/session layers, notify server, nested dsh SDK
#     runtime) and exposes `ctx.larkBridge` (status / stop).
#   - `dsh-lark-bot/notify` mounts the `lark_notify` tool for the host agent
#     (mentions + cross-session messages).
#   - `dsh-lark-bot/file` mounts the `lark_send_file` result upload tool.
#   - `dsh-lark-bot/plan` mounts the host plan gate; managed SDK / ACP overlays
#     mount the same tool for their nested agents.
#   - `dsh-lark-bot/approval` answers official one-shot tool approvals through
#     Feishu/Lark cards for host agents.
# First boot without credentials prints a QR code for one-time binding.
# Set DSH_LARK_DISABLED=1 to keep the engine stopped.

- insert:
    - id: dsh-lark-bot
      name: 'dsh-lark-bot/plugin'
      config:
        profile: !!js process.env.DSH_LARK_PROFILE ?? 'default'
        home: !!js process.env.DSH_LARK_HOME
        tenant: !!js process.env.DSH_LARK_TENANT ?? 'feishu'
        appId: !!js process.env.DSH_LARK_APP_ID
        appSecret: !!js process.env.DSH_LARK_APP_SECRET
        workspace: !!js process.env.DSH_LARK_WORKSPACE
        adapter: !!js process.env.DSH_LARK_ADAPTER
        model: !!js process.env.DSH_LARK_MODEL
        scopeConcurrency: !!js 'process.env.DSH_LARK_SCOPE_CONCURRENCY ? Number(process.env.DSH_LARK_SCOPE_CONCURRENCY) : undefined'
        notificationDefault: !!js process.env.DSH_LARK_NOTIFICATION_DEFAULT
        disabled: !!js process.env.DSH_LARK_DISABLED === '1'

    - id: lark-notify
      name: 'dsh-lark-bot/notify'
      config:
        endpoint: !!js process.env.DSH_LARK_NOTIFY_URL
        token: !!js process.env.DSH_LARK_NOTIFY_TOKEN

    - id: lark-file
      name: 'dsh-lark-bot/file'
      config:
        endpoint: !!js process.env.DSH_LARK_FILE_URL
        token: !!js process.env.DSH_LARK_NOTIFY_TOKEN

    - id: lark-secret
      name: 'dsh-lark-bot/secret'
      config:
        endpoint: !!js process.env.DSH_LARK_SECRET_URL
        token: !!js process.env.DSH_LARK_NOTIFY_TOKEN

    - id: lark-ask
      name: 'dsh-lark-bot/ask'
      config:
        endpoint: !!js process.env.DSH_LARK_ASK_URL
        token: !!js process.env.DSH_LARK_NOTIFY_TOKEN

    - id: lark-plan-approval
      name: 'dsh-lark-bot/plan'
      config:
        endpoint: !!js process.env.DSH_LARK_PLAN_URL
        policyEndpoint: !!js process.env.DSH_LARK_APPROVAL_URL
        token: !!js process.env.DSH_LARK_NOTIFY_TOKEN
        mode: !!js process.env.DSH_LARK_PLAN_GATE

    - id: lark-approval-answerer
      name: 'dsh-lark-bot/approval'
      config:
        endpoint: !!js process.env.DSH_LARK_APPROVAL_URL
        token: !!js process.env.DSH_LARK_NOTIFY_TOKEN
