import{a as e,n as t}from"./lit-xS7RrYW6.js";import{F as n,R as r,U as i,V as a,g as o,h as s,o as c,p as l,r as u}from"./index-CLDLe9x8.js";function d(){return[{value:`ok`,label:`成功`},{value:`error`,label:`错误`},{value:`skipped`,label:`已跳过`}]}function f(){return[{value:`delivered`,label:`已投递`},{value:`not-delivered`,label:`未投递`},{value:`unknown`,label:`未知`},{value:`not-requested`,label:`未请求`}]}function p(e,t,n){let r=new Set(e);return n?r.add(t):r.delete(t),Array.from(r)}function m(e,t){return e.length===0?t:e.length<=2?e.join(`, `):`${e[0]} +${e.length-1}`}function h(e){var t;let n=[`last`,...e.channels.filter(Boolean)],r=(t=e.form.deliveryChannel)==null?void 0:t.trim();r&&!n.includes(r)&&n.push(r);let i=new Set;return n.filter(e=>i.has(e)?!1:(i.add(e),!0))}function g(e,t){var n,r;if(t===`last`)return`last`;let i=(n=e.channelMeta)==null?void 0:n.find(e=>e.id===t);return i!=null&&i.label?i.label:((r=e.channelLabels)==null?void 0:r[t])??t}function _(t){return e`
    <div class="field cron-filter-dropdown" data-filter=${t.id}>
      <span>${t.title}</span>
      <details class="cron-filter-dropdown__details">
        <summary class="btn cron-filter-dropdown__trigger">
          <span>${t.summary}</span>
        </summary>
        <div class="cron-filter-dropdown__panel">
          <div class="cron-filter-dropdown__list">
            ${t.options.map(n=>e`
                <label class="cron-filter-dropdown__option">
                  <input
                    type="checkbox"
                    value=${n.value}
                    .checked=${t.selected.includes(n.value)}
                    @change=${e=>{let r=e.target;t.onToggle(n.value,r.checked)}}
                  />
                  <span>${n.label}</span>
                </label>
              `)}
          </div>
          <div class="row">
            <button class="btn" type="button" @click=${t.onClear}>${`清除`}</button>
          </div>
        </div>
      </details>
    </div>
  `}function v(n,r){let i=Array.from(new Set(r.map(e=>e.trim()).filter(Boolean)));return i.length===0?t:e`<datalist id=${n}>
    ${i.map(t=>e`<option value=${t}></option> `)}
  </datalist>`}function y(e){return`cron-error-${e}`}function b(e){return e===`name`?`cron-name`:e===`scheduleAt`?`cron-schedule-at`:e===`everyAmount`?`cron-every-amount`:e===`cronExpr`?`cron-cron-expr`:e===`staggerAmount`?`cron-stagger-amount`:e===`payloadText`?`cron-payload-text`:e===`payloadModel`?`cron-payload-model`:e===`payloadThinking`?`cron-payload-thinking`:e===`timeoutSeconds`?`cron-timeout-seconds`:e===`failureAlertAfter`?`cron-failure-alert-after`:e===`failureAlertCooldownSeconds`?`cron-failure-alert-cooldown-seconds`:`cron-delivery-to`}function x(e,t,n){return e===`payloadText`?t.payloadKind===`systemEvent`?`主时间线消息`:`助手任务提示`:e===`deliveryTo`?n===`webhook`?`Webhook URL`:`收件人`:{name:`姓名`,scheduleAt:`运行时间`,everyAmount:`每隔`,cronExpr:`表达式`,staggerAmount:`抖动窗口`,payloadText:`助手任务提示`,payloadModel:`模型`,payloadThinking:`思考`,timeoutSeconds:`超时（秒）`,deliveryTo:`收件人`,failureAlertAfter:`Failure alert after`,failureAlertCooldownSeconds:`Failure alert cooldown`}[e]}function S(e,t,n){let r=[`name`,`scheduleAt`,`everyAmount`,`cronExpr`,`staggerAmount`,`payloadText`,`payloadModel`,`payloadThinking`,`timeoutSeconds`,`deliveryTo`,`failureAlertAfter`,`failureAlertCooldownSeconds`],i=[];for(let a of r){let r=e[a];r&&i.push({key:a,label:x(a,t,n),message:r,inputId:b(a)})}return i}function C(e){let t=document.getElementById(e);t instanceof HTMLElement&&(typeof t.scrollIntoView==`function`&&t.scrollIntoView({block:`center`,behavior:`smooth`}),t.focus())}function w(n,r=!1){return e`<span>
    ${n}
    ${r?e`
          <span class="cron-required-marker" aria-hidden="true">*</span>
          <span class="cron-required-sr">${`必填`}</span>
        `:t}
  </span>`}function T(n){var r,i,a;let o=!!n.editingJobId,l=n.form.payloadKind===`agentTurn`,u=n.form.scheduleKind===`cron`,b=h(n),x=n.runsJobId==null?void 0:n.jobs.find(e=>e.id===n.runsJobId),T=n.runsScope===`all`?`所有任务`:(x==null?void 0:x.name)??n.runsJobId??`（选择任务）`,k=n.runs.toSorted((e,t)=>n.runsSortDir===`asc`?e.ts-t.ts:t.ts-e.ts),A=d(),j=f(),M=A.filter(e=>n.runsStatuses.includes(e.value)).map(e=>e.label),N=j.filter(e=>n.runsDeliveryStatuses.includes(e.value)).map(e=>e.label),P=m(M,`全部状态`),F=m(N,`全部投递`),L=n.form.sessionTarget!==`main`&&n.form.payloadKind===`agentTurn`,R=n.form.deliveryMode===`announce`&&!L?`none`:n.form.deliveryMode,z=n.cronFormCollapsed===!0,B=o?`编辑任务`:`新建任务`,V=n.onToggleFormCollapsed,H=S(n.fieldErrors,n.form,R),U=!n.busy&&H.length>0,W=n.jobsQuery.trim().length>0||n.jobsEnabledFilter!==`all`||n.jobsScheduleKindFilter!==`all`||n.jobsLastStatusFilter!==`all`||n.jobsSortBy!==`nextRunAtMs`||n.jobsSortDir!==`asc`,G=U&&!n.canSubmit?(H.length,`修复 ${String(H.length)} 个字段以继续。`):``;return e`
    <section class="card cron-summary-strip">
      <div class="cron-summary-strip__left">
        <div class="cron-summary-item">
          <div class="cron-summary-label">${`已启用`}</div>
          <div class="cron-summary-value">
            <span class=${`chip ${(r=n.status)!=null&&r.enabled?`chip-ok`:`chip-danger`}`}>
              ${n.status?n.status.enabled?`是`:`否`:`不适用`}
            </span>
          </div>
        </div>
        <div class="cron-summary-item">
          <div class="cron-summary-label">${`任务数`}</div>
          <div class="cron-summary-value">${((i=n.status)==null?void 0:i.jobs)??`不适用`}</div>
        </div>
        <div class="cron-summary-item cron-summary-item--wide">
          <div class="cron-summary-label">${`下次唤醒`}</div>
          <div class="cron-summary-value">${c(((a=n.status)==null?void 0:a.nextWakeAtMs)??null)}</div>
        </div>
      </div>
      <div class="cron-summary-strip__actions">
        ${n.onQuickCreate?e` <button class="btn btn--primary" @click=${n.onQuickCreate}>+ New</button> `:t}
        <button
          class=${n.loading?`btn cron-refresh-btn--loading`:`btn`}
          ?disabled=${n.loading}
          @click=${n.onRefresh}
        >
          ${n.loading?`刷新中...`:`刷新`}
        </button>
        ${n.error?e`<span class="muted">${n.error}</span>`:t}
      </div>
    </section>

    <section class=${`cron-workspace ${z?`cron-workspace--form-collapsed`:``}`}>
      <div class="cron-workspace-main">
        <section class="card">
          <div
            class="row"
            style="justify-content: space-between; align-items: flex-start; gap: 12px;"
          >
            <div>
              <div class="card-title">${`任务列表`}</div>
              <div class="card-sub">${`网关中存储的所有定时任务。`}</div>
            </div>
            <div class="muted">
              ${`显示 ${String(n.jobs.length)} / 共 ${String(n.jobsTotal)}`}
            </div>
          </div>
          <div class="filters" style="margin-top: 12px;">
            <label class="field cron-filter-search">
              <span>${`搜索任务`}</span>
              <input
                .value=${n.jobsQuery}
                placeholder=${`名称、描述或代理`}
                @input=${e=>n.onJobsFiltersChange({cronJobsQuery:e.target.value})}
              />
            </label>
            <label class="field">
              <span>${`启用状态`}</span>
              <select
                .value=${n.jobsEnabledFilter}
                @change=${e=>n.onJobsFiltersChange({cronJobsEnabledFilter:e.target.value})}
              >
                <option value="all">${`全部`}</option>
                <option value="enabled">${`已启用`}</option>
                <option value="disabled">${`已禁用`}</option>
              </select>
            </label>
            <label class="field">
              <span>${`计划`}</span>
              <select
                data-test-id="cron-jobs-schedule-filter"
                .value=${n.jobsScheduleKindFilter}
                @change=${e=>n.onJobsFiltersChange({cronJobsScheduleKindFilter:e.target.value})}
              >
                <option value="all">${`全部`}</option>
                <option value="at">${`指定时间`}</option>
                <option value="every">${`每隔`}</option>
                <option value="cron">${`Cron`}</option>
              </select>
            </label>
            <label class="field">
              <span>${`上次运行`}</span>
              <select
                data-test-id="cron-jobs-last-status-filter"
                .value=${n.jobsLastStatusFilter}
                @change=${e=>n.onJobsFiltersChange({cronJobsLastStatusFilter:e.target.value})}
              >
                <option value="all">${`全部`}</option>
                <option value="ok">${`成功`}</option>
                <option value="error">${`错误`}</option>
                <option value="skipped">${`已跳过`}</option>
              </select>
            </label>
            <label class="field">
              <span>${`排序`}</span>
              <select
                .value=${n.jobsSortBy}
                @change=${e=>n.onJobsFiltersChange({cronJobsSortBy:e.target.value})}
              >
                <option value="nextRunAtMs">${`下次运行`}</option>
                <option value="updatedAtMs">${`最近更新`}</option>
                <option value="name">${`姓名`}</option>
              </select>
            </label>
            <label class="field">
              <span>${`方向`}</span>
              <select
                .value=${n.jobsSortDir}
                @change=${e=>n.onJobsFiltersChange({cronJobsSortDir:e.target.value})}
              >
                <option value="asc">${`升序`}</option>
                <option value="desc">${`降序`}</option>
              </select>
            </label>
            <label class="field">
              <span>${`重置`}</span>
              <button
                class="btn"
                data-test-id="cron-jobs-filters-reset"
                ?disabled=${!W}
                @click=${n.onJobsFiltersReset}
              >
                ${`重置`}
              </button>
            </label>
          </div>
          ${n.jobs.length===0?e` <div class="muted" style="margin-top: 12px">${`没有匹配的任务。`}</div> `:e`
                <div class="list" style="margin-top: 12px;">
                  ${n.jobs.map(e=>O(e,n))}
                </div>
              `}
          ${n.jobsHasMore?e`
                <div class="row" style="margin-top: 12px">
                  <button
                    class="btn"
                    ?disabled=${n.loading||n.jobsLoadingMore}
                    @click=${n.onLoadMoreJobs}
                  >
                    ${n.jobsLoadingMore?`加载中...`:`加载更多任务`}
                  </button>
                </div>
              `:t}
        </section>

        <section class="card">
          <div
            class="row"
            style="justify-content: space-between; align-items: flex-start; gap: 12px;"
          >
            <div>
              <div class="card-title">${`运行历史`}</div>
              <div class="card-sub">
                ${n.runsScope===`all`?`所有任务的最新运行记录。`:`${T} 的最新运行记录。`}
              </div>
            </div>
            <div class="muted">
              ${`显示 ${String(k.length)} / 共 ${String(n.runsTotal)}`}
            </div>
          </div>
          <div class="cron-run-filters">
            <div class="cron-run-filters__row cron-run-filters__row--primary">
              <label class="field">
                <span>${`范围`}</span>
                <select
                  .value=${n.runsScope}
                  @change=${e=>n.onRunsFiltersChange({cronRunsScope:e.target.value})}
                >
                  <option value="all">${`所有任务`}</option>
                  <option value="job" ?disabled=${n.runsJobId==null}>${`已选任务`}</option>
                </select>
              </label>
              <label class="field cron-run-filter-search">
                <span>${`搜索运行`}</span>
                <input
                  .value=${n.runsQuery}
                  placeholder=${`摘要、错误或任务`}
                  @input=${e=>n.onRunsFiltersChange({cronRunsQuery:e.target.value})}
                />
              </label>
              <label class="field">
                <span>${`排序`}</span>
                <select
                  .value=${n.runsSortDir}
                  @change=${e=>n.onRunsFiltersChange({cronRunsSortDir:e.target.value})}
                >
                  <option value="desc">${`最新优先`}</option>
                  <option value="asc">${`最早优先`}</option>
                </select>
              </label>
            </div>
            <div class="cron-run-filters__row cron-run-filters__row--secondary">
              ${_({id:`status`,title:`状态`,summary:P,options:A,selected:n.runsStatuses,onToggle:(e,t)=>{let r=p(n.runsStatuses,e,t);n.onRunsFiltersChange({cronRunsStatuses:r})},onClear:()=>{n.onRunsFiltersChange({cronRunsStatuses:[]})}})}
              ${_({id:`delivery`,title:`投递`,summary:F,options:j,selected:n.runsDeliveryStatuses,onToggle:(e,t)=>{let r=p(n.runsDeliveryStatuses,e,t);n.onRunsFiltersChange({cronRunsDeliveryStatuses:r})},onClear:()=>{n.onRunsFiltersChange({cronRunsDeliveryStatuses:[]})}})}
            </div>
          </div>
          ${n.runsScope===`job`&&n.runsJobId==null?e`
                <div class="muted" style="margin-top: 12px">
                  ${`请选择一个任务以查看运行历史。`}
                </div>
              `:k.length===0?e` <div class="muted" style="margin-top: 12px">${`没有匹配的运行记录。`}</div> `:e`
                  <div class="list" style="margin-top: 12px;">
                    ${k.map(e=>I(e,n.basePath,n.onNavigateToChat))}
                  </div>
                `}
          ${(n.runsScope===`all`||n.runsJobId!=null)&&n.runsHasMore?e`
                <div class="row" style="margin-top: 12px">
                  <button
                    class="btn"
                    ?disabled=${n.runsLoadingMore}
                    @click=${n.onLoadMoreRuns}
                  >
                    ${n.runsLoadingMore?`加载中...`:`加载更多运行`}
                  </button>
                </div>
              `:t}
        </section>
      </div>

      <section
        class=${`card cron-workspace-form ${z?`cron-workspace-form--collapsed`:``}`}
      >
        <div class="cron-form-header">
          <div class="cron-form-header__copy">
            <div class="card-title">${B}</div>
            ${z?t:e`
                  <div class="card-sub">
                    ${o?`更新所选定时任务。`:`创建定时唤醒或代理运行。`}
                  </div>
                `}
          </div>
          ${V?e`
                <button
                  type="button"
                  class="btn cron-form-collapse-toggle"
                  data-test-id="cron-form-collapse-toggle"
                  title=${z?`展开侧边栏`:`折叠侧边栏`}
                  aria-label=${z?`展开侧边栏`:`折叠侧边栏`}
                  aria-expanded=${z?`false`:`true`}
                  @click=${()=>V(!z)}
                >
                  <span aria-hidden="true">${z?`<`:`>`}</span>
                </button>
              `:t}
        </div>
        <div class="cron-form" ?hidden=${z}>
          <div class="cron-required-legend">
            <span class="cron-required-marker" aria-hidden="true">*</span> ${`必填`}
          </div>
          <section class="cron-form-section">
            <div class="cron-form-section__title">${`基本信息`}</div>
            <div class="cron-form-section__sub">${`命名、选择助手并设置启用状态。`}</div>
            <div class="form-grid cron-form-grid">
              <label class="field">
                ${w(`姓名`,!0)}
                <input
                  id="cron-name"
                  .value=${n.form.name}
                  placeholder=${`晨间简报`}
                  aria-invalid=${n.fieldErrors.name?`true`:`false`}
                  aria-describedby=${s(n.fieldErrors.name?y(`name`):void 0)}
                  @input=${e=>n.onFormChange({name:e.target.value})}
                />
                ${D(n.fieldErrors.name,y(`name`))}
              </label>
              <label class="field">
                <span>${`描述`}</span>
                <input
                  .value=${n.form.description}
                  placeholder=${`此任务的可选说明`}
                  @input=${e=>n.onFormChange({description:e.target.value})}
                />
              </label>
              <label class="field">
                ${w(`代理 ID`)}
                <input
                  id="cron-agent-id"
                  .value=${n.form.agentId}
                  list="cron-agent-suggestions"
                  ?disabled=${n.form.clearAgent}
                  @input=${e=>n.onFormChange({agentId:e.target.value})}
                  placeholder=${`main 或 ops`}
                />
                <div class="cron-help">${`输入以选择已知代理，或输入自定义 ID。`}</div>
              </label>
              <label class="field checkbox cron-checkbox cron-checkbox-inline">
                <input
                  type="checkbox"
                  .checked=${n.form.enabled}
                  @change=${e=>n.onFormChange({enabled:e.target.checked})}
                />
                <span class="field-checkbox__label">${`已启用`}</span>
              </label>
            </div>
          </section>

          <section class="cron-form-section">
            <div class="cron-form-section__title">${`计划`}</div>
            <div class="cron-form-section__sub">${`控制任务运行时间。`}</div>
            <div class="form-grid cron-form-grid">
              <label class="field cron-span-2">
                ${w(`计划`)}
                <select
                  id="cron-schedule-kind"
                  .value=${n.form.scheduleKind}
                  @change=${e=>n.onFormChange({scheduleKind:e.target.value})}
                >
                  <option value="every">${`每隔`}</option>
                  <option value="at">${`指定时间`}</option>
                  <option value="cron">${`Cron`}</option>
                </select>
              </label>
            </div>
            ${E(n)}
          </section>

          <section class="cron-form-section">
            <div class="cron-form-section__title">${`执行`}</div>
            <div class="cron-form-section__sub">${`选择唤醒时机和任务执行内容。`}</div>
            <div class="form-grid cron-form-grid">
              <label class="field">
                ${w(`会话`)}
                <select
                  id="cron-session-target"
                  .value=${n.form.sessionTarget}
                  @change=${e=>n.onFormChange({sessionTarget:e.target.value})}
                >
                  <option value="main">${`主会话`}</option>
                  <option value="isolated">${`隔离会话`}</option>
                </select>
                <div class="cron-help">${`主会话发布系统事件。隔离会话运行独立的代理轮次。`}</div>
              </label>
              <label class="field">
                ${w(`唤醒模式`)}
                <select
                  id="cron-wake-mode"
                  .value=${n.form.wakeMode}
                  @change=${e=>n.onFormChange({wakeMode:e.target.value})}
                >
                  <option value="now">${`立即`}</option>
                  <option value="next-heartbeat">${`下次心跳`}</option>
                </select>
                <div class="cron-help">${`立即模式立即触发。下次心跳等待下一个周期。`}</div>
              </label>
              <label class="field ${l?``:`cron-span-2`}">
                ${w(`执行内容`)}
                <select
                  id="cron-payload-kind"
                  .value=${n.form.payloadKind}
                  @change=${e=>n.onFormChange({payloadKind:e.target.value})}
                >
                  <option value="systemEvent">${`发布消息到主时间线`}</option>
                  <option value="agentTurn">${`运行助手任务（隔离）`}</option>
                </select>
                <div class="cron-help">
                  ${n.form.payloadKind===`systemEvent`?`将文本发送到网关主时间线（适用于提醒/触发）。`:`使用您的提示在独立会话中启动助手运行。`}
                </div>
              </label>
              ${l?e`
                    <label class="field">
                      ${w(`超时（秒）`)}
                      <input
                        id="cron-timeout-seconds"
                        .value=${n.form.timeoutSeconds}
                        placeholder=${`可选，如 90`}
                        aria-invalid=${n.fieldErrors.timeoutSeconds?`true`:`false`}
                        aria-describedby=${s(n.fieldErrors.timeoutSeconds?y(`timeoutSeconds`):void 0)}
                        @input=${e=>n.onFormChange({timeoutSeconds:e.target.value})}
                      />
                      <div class="cron-help">${`可选。留空以使用网关默认超时行为。`}</div>
                      ${D(n.fieldErrors.timeoutSeconds,y(`timeoutSeconds`))}
                    </label>
                  `:t}
            </div>
            <label class="field cron-span-2">
              ${w(n.form.payloadKind===`systemEvent`?`主时间线消息`:`助手任务提示`,!0)}
              <textarea
                id="cron-payload-text"
                .value=${n.form.payloadText}
                aria-invalid=${n.fieldErrors.payloadText?`true`:`false`}
                aria-describedby=${s(n.fieldErrors.payloadText?y(`payloadText`):void 0)}
                @input=${e=>n.onFormChange({payloadText:e.target.value})}
                rows="4"
              ></textarea>
              ${D(n.fieldErrors.payloadText,y(`payloadText`))}
            </label>
          </section>

          <section class="cron-form-section">
            <div class="cron-form-section__title">${`投递`}</div>
            <div class="cron-form-section__sub">${`选择运行摘要的发送位置。`}</div>
            <div class="form-grid cron-form-grid">
              <label class="field ${R===`none`?`cron-span-2`:``}">
                ${w(`结果投递`)}
                <select
                  id="cron-delivery-mode"
                  .value=${R}
                  @change=${e=>n.onFormChange({deliveryMode:e.target.value})}
                >
                  ${L?e` <option value="announce">${`发布摘要（默认）`}</option> `:t}
                  <option value="webhook">${`Webhook POST`}</option>
                  <option value="none">${`无（仅内部）`}</option>
                </select>
                <div class="cron-help">${`发布将摘要发送到聊天。无保持执行仅内部。`}</div>
              </label>
              ${R===`none`?t:e`
                    <label class="field ${R===`webhook`?`cron-span-2`:``}">
                      ${w(R===`webhook`?`Webhook URL`:`渠道`,R===`webhook`)}
                      ${R===`webhook`?e`
                            <input
                              id="cron-delivery-to"
                              .value=${n.form.deliveryTo}
                              list="cron-delivery-to-suggestions"
                              aria-invalid=${n.fieldErrors.deliveryTo?`true`:`false`}
                              aria-describedby=${s(n.fieldErrors.deliveryTo?y(`deliveryTo`):void 0)}
                              @input=${e=>n.onFormChange({deliveryTo:e.target.value})}
                              placeholder=${`https://example.com/cron`}
                            />
                          `:e`
                            <select
                              id="cron-delivery-channel"
                              .value=${n.form.deliveryChannel||`last`}
                              @change=${e=>n.onFormChange({deliveryChannel:e.target.value})}
                            >
                              ${b.map(t=>e`<option value=${t}>
                                    ${g(n,t)}
                                  </option>`)}
                            </select>
                          `}
                      ${R===`announce`?e` <div class="cron-help">${`选择接收摘要的已连接频道。`}</div> `:e` <div class="cron-help">${`将运行摘要发送到 Webhook 端点。`}</div> `}
                    </label>
                    ${R===`announce`?e`
                          <label class="field cron-span-2">
                            ${w(`收件人`)}
                            <input
                              id="cron-delivery-to"
                              .value=${n.form.deliveryTo}
                              list="cron-delivery-to-suggestions"
                              @input=${e=>n.onFormChange({deliveryTo:e.target.value})}
                              placeholder=${`+1555... 或聊天 ID`}
                            />
                            <div class="cron-help">
                              ${`可选收件人覆盖（聊天 ID、电话或用户 ID）。`}
                            </div>
                          </label>
                        `:t}
                    ${R===`webhook`?D(n.fieldErrors.deliveryTo,y(`deliveryTo`)):t}
                  `}
            </div>
          </section>

          <details class="cron-advanced">
            <summary class="cron-advanced__summary">${`高级`}</summary>
            <div class="cron-help">${`投递保证、调度抖动和模型控制的可选覆盖。`}</div>
            <div class="form-grid cron-form-grid">
              <label class="field checkbox cron-checkbox">
                <input
                  type="checkbox"
                  .checked=${n.form.deleteAfterRun}
                  @change=${e=>n.onFormChange({deleteAfterRun:e.target.checked})}
                />
                <span class="field-checkbox__label">${`运行后删除`}</span>
                <div class="cron-help">${`适用于应自动清理的一次性提醒。`}</div>
              </label>
              <label class="field checkbox cron-checkbox">
                <input
                  type="checkbox"
                  .checked=${n.form.clearAgent}
                  @change=${e=>n.onFormChange({clearAgent:e.target.checked})}
                />
                <span class="field-checkbox__label">${`清除代理覆盖`}</span>
                <div class="cron-help">${`强制此任务使用网关默认助手。`}</div>
              </label>
              <label class="field cron-span-2">
                ${w(`Session key`)}
                <input
                  id="cron-session-key"
                  .value=${n.form.sessionKey}
                  @input=${e=>n.onFormChange({sessionKey:e.target.value})}
                  placeholder="agent:main:main"
                />
                <div class="cron-help">Optional routing key for job delivery and wake routing.</div>
              </label>
              ${u?e`
                    <label class="field checkbox cron-checkbox cron-span-2">
                      <input
                        type="checkbox"
                        .checked=${n.form.scheduleExact}
                        @change=${e=>n.onFormChange({scheduleExact:e.target.checked})}
                      />
                      <span class="field-checkbox__label">${`精确时间（无抖动）`}</span>
                      <div class="cron-help">${`在精确的 cron 边界运行，无分散。`}</div>
                    </label>
                    <div class="cron-stagger-group cron-span-2">
                      <label class="field">
                        ${w(`抖动窗口`)}
                        <input
                          id="cron-stagger-amount"
                          .value=${n.form.staggerAmount}
                          ?disabled=${n.form.scheduleExact}
                          aria-invalid=${n.fieldErrors.staggerAmount?`true`:`false`}
                          aria-describedby=${s(n.fieldErrors.staggerAmount?y(`staggerAmount`):void 0)}
                          @input=${e=>n.onFormChange({staggerAmount:e.target.value})}
                          placeholder=${`30`}
                        />
                        ${D(n.fieldErrors.staggerAmount,y(`staggerAmount`))}
                      </label>
                      <label class="field">
                        <span>${`抖动单位`}</span>
                        <select
                          .value=${n.form.staggerUnit}
                          ?disabled=${n.form.scheduleExact}
                          @change=${e=>n.onFormChange({staggerUnit:e.target.value})}
                        >
                          <option value="seconds">${`秒`}</option>
                          <option value="minutes">${`分钟`}</option>
                        </select>
                      </label>
                    </div>
                  `:t}
              ${l?e`
                    <label class="field cron-span-2">
                      ${w(`Account ID`)}
                      <input
                        id="cron-delivery-account-id"
                        .value=${n.form.deliveryAccountId}
                        list="cron-delivery-account-suggestions"
                        ?disabled=${R!==`announce`}
                        @input=${e=>n.onFormChange({deliveryAccountId:e.target.value})}
                        placeholder="default"
                      />
                      <div class="cron-help">
                        Optional channel account ID for multi-account setups.
                      </div>
                    </label>
                    <label class="field checkbox cron-checkbox cron-span-2">
                      <input
                        type="checkbox"
                        .checked=${n.form.payloadLightContext}
                        @change=${e=>n.onFormChange({payloadLightContext:e.target.checked})}
                      />
                      <span class="field-checkbox__label">Light context</span>
                      <div class="cron-help">
                        Use lightweight bootstrap context for this agent job.
                      </div>
                    </label>
                    <label class="field">
                      ${w(`模型`)}
                      <input
                        id="cron-payload-model"
                        .value=${n.form.payloadModel}
                        list="cron-model-suggestions"
                        @input=${e=>n.onFormChange({payloadModel:e.target.value})}
                        placeholder=${`openai/gpt-5.2`}
                      />
                      <div class="cron-help">${`输入以选择已知模型，或输入自定义模型。`}</div>
                    </label>
                    <label class="field">
                      ${w(`思考`)}
                      <input
                        id="cron-payload-thinking"
                        .value=${n.form.payloadThinking}
                        list="cron-thinking-suggestions"
                        @input=${e=>n.onFormChange({payloadThinking:e.target.value})}
                        placeholder=${`low`}
                      />
                      <div class="cron-help">${`使用建议级别或输入提供商特定值。`}</div>
                    </label>
                  `:t}
              ${l?e`
                    <label class="field cron-span-2">
                      ${w(`Failure alerts`)}
                      <select
                        .value=${n.form.failureAlertMode}
                        @change=${e=>n.onFormChange({failureAlertMode:e.target.value})}
                      >
                        <option value="inherit">Inherit global setting</option>
                        <option value="disabled">Disable for this job</option>
                        <option value="custom">Custom per-job settings</option>
                      </select>
                      <div class="cron-help">
                        Control when this job sends repeated-failure alerts.
                      </div>
                    </label>
                    ${n.form.failureAlertMode===`custom`?e`
                          <label class="field">
                            ${w(`Alert after`)}
                            <input
                              id="cron-failure-alert-after"
                              .value=${n.form.failureAlertAfter}
                              aria-invalid=${n.fieldErrors.failureAlertAfter?`true`:`false`}
                              aria-describedby=${s(n.fieldErrors.failureAlertAfter?y(`failureAlertAfter`):void 0)}
                              @input=${e=>n.onFormChange({failureAlertAfter:e.target.value})}
                              placeholder="2"
                            />
                            <div class="cron-help">Consecutive errors before alerting.</div>
                            ${D(n.fieldErrors.failureAlertAfter,y(`failureAlertAfter`))}
                          </label>
                          <label class="field">
                            ${w(`Cooldown (seconds)`)}
                            <input
                              id="cron-failure-alert-cooldown-seconds"
                              .value=${n.form.failureAlertCooldownSeconds}
                              aria-invalid=${n.fieldErrors.failureAlertCooldownSeconds?`true`:`false`}
                              aria-describedby=${s(n.fieldErrors.failureAlertCooldownSeconds?y(`failureAlertCooldownSeconds`):void 0)}
                              @input=${e=>n.onFormChange({failureAlertCooldownSeconds:e.target.value})}
                              placeholder="3600"
                            />
                            <div class="cron-help">Minimum seconds between alerts.</div>
                            ${D(n.fieldErrors.failureAlertCooldownSeconds,y(`failureAlertCooldownSeconds`))}
                          </label>
                          <label class="field">
                            ${w(`Alert channel`)}
                            <select
                              .value=${n.form.failureAlertChannel||`last`}
                              @change=${e=>n.onFormChange({failureAlertChannel:e.target.value})}
                            >
                              ${b.map(t=>e`<option value=${t}>
                                    ${g(n,t)}
                                  </option>`)}
                            </select>
                          </label>
                          <label class="field">
                            ${w(`Alert to`)}
                            <input
                              .value=${n.form.failureAlertTo}
                              list="cron-delivery-to-suggestions"
                              @input=${e=>n.onFormChange({failureAlertTo:e.target.value})}
                              placeholder="+1555... or chat id"
                            />
                            <div class="cron-help">
                              Optional recipient override for failure alerts.
                            </div>
                          </label>
                          <label class="field">
                            ${w(`Alert mode`)}
                            <select
                              .value=${n.form.failureAlertDeliveryMode||`announce`}
                              @change=${e=>n.onFormChange({failureAlertDeliveryMode:e.target.value})}
                            >
                              <option value="announce">Announce (via channel)</option>
                              <option value="webhook">Webhook (HTTP POST)</option>
                            </select>
                          </label>
                          <label class="field">
                            ${w(`Alert account ID`)}
                            <input
                              .value=${n.form.failureAlertAccountId}
                              @input=${e=>n.onFormChange({failureAlertAccountId:e.target.value})}
                              placeholder="Account ID for multi-account setups"
                            />
                          </label>
                        `:t}
                  `:t}
              ${R===`none`?t:e`
                    <label class="field checkbox cron-checkbox cron-span-2">
                      <input
                        type="checkbox"
                        .checked=${n.form.deliveryBestEffort}
                        @change=${e=>n.onFormChange({deliveryBestEffort:e.target.checked})}
                      />
                      <span class="field-checkbox__label">${`尽力投递`}</span>
                      <div class="cron-help">${`投递失败时不使任务失败。`}</div>
                    </label>
                  `}
            </div>
          </details>
        </div>
        ${U?e`
              <div
                class="cron-form-status"
                role="status"
                aria-live="polite"
                ?hidden=${z}
              >
                <div class="cron-form-status__title">${`暂无法添加任务`}</div>
                <div class="cron-help">${`填写下方必填项以启用提交。`}</div>
                <ul class="cron-form-status__list">
                  ${H.map(t=>e`
                      <li>
                        <button
                          type="button"
                          class="cron-form-status__link"
                          @click=${()=>C(t.inputId)}
                        >
                          ${t.label}: ${t.message}
                        </button>
                      </li>
                    `)}
                </ul>
              </div>
            `:t}
        <div class="row cron-form-actions" ?hidden=${z}>
          <button
            class="btn primary"
            ?disabled=${n.busy||!n.canSubmit}
            @click=${n.onAdd}
          >
            ${n.busy?`保存中...`:o?`保存更改`:`添加任务`}
          </button>
          ${G?e`
                <div class="cron-submit-reason" aria-live="polite">${G}</div>
              `:t}
          ${o?e`
                <button class="btn" ?disabled=${n.busy} @click=${n.onCancelEdit}>
                  ${`取消`}
                </button>
              `:t}
        </div>
      </section>
    </section>

    ${v(`cron-agent-suggestions`,n.agentSuggestions)}
    ${v(`cron-model-suggestions`,n.modelSuggestions)}
    ${v(`cron-thinking-suggestions`,n.thinkingSuggestions)}
    ${v(`cron-tz-suggestions`,n.timezoneSuggestions)}
    ${v(`cron-delivery-to-suggestions`,n.deliveryToSuggestions)}
    ${v(`cron-delivery-account-suggestions`,n.accountSuggestions)}
  `}function E(t){let n=t.form;return n.scheduleKind===`at`?e`
      <label class="field cron-span-2" style="margin-top: 12px;">
        ${w(`运行时间`,!0)}
        <input
          id="cron-schedule-at"
          type="datetime-local"
          .value=${n.scheduleAt}
          aria-invalid=${t.fieldErrors.scheduleAt?`true`:`false`}
          aria-describedby=${s(t.fieldErrors.scheduleAt?y(`scheduleAt`):void 0)}
          @input=${e=>t.onFormChange({scheduleAt:e.target.value})}
        />
        ${D(t.fieldErrors.scheduleAt,y(`scheduleAt`))}
      </label>
    `:n.scheduleKind===`every`?e`
      <div class="form-grid cron-form-grid" style="margin-top: 12px;">
        <label class="field">
          ${w(`每隔`,!0)}
          <input
            id="cron-every-amount"
            .value=${n.everyAmount}
            aria-invalid=${t.fieldErrors.everyAmount?`true`:`false`}
            aria-describedby=${s(t.fieldErrors.everyAmount?y(`everyAmount`):void 0)}
            @input=${e=>t.onFormChange({everyAmount:e.target.value})}
            placeholder=${`30`}
          />
          ${D(t.fieldErrors.everyAmount,y(`everyAmount`))}
        </label>
        <label class="field">
          <span>${`单位`}</span>
          <select
            .value=${n.everyUnit}
            @change=${e=>t.onFormChange({everyUnit:e.target.value})}
          >
            <option value="minutes">${`分钟`}</option>
            <option value="hours">${`小时`}</option>
            <option value="days">${`天`}</option>
          </select>
        </label>
      </div>
    `:e`
    <div class="form-grid cron-form-grid" style="margin-top: 12px;">
      <label class="field">
        ${w(`表达式`,!0)}
        <input
          id="cron-cron-expr"
          .value=${n.cronExpr}
          aria-invalid=${t.fieldErrors.cronExpr?`true`:`false`}
          aria-describedby=${s(t.fieldErrors.cronExpr?y(`cronExpr`):void 0)}
          @input=${e=>t.onFormChange({cronExpr:e.target.value})}
          placeholder=${`0 7 * * *`}
        />
        ${D(t.fieldErrors.cronExpr,y(`cronExpr`))}
      </label>
      <label class="field">
        <span>${`时区（可选）`}</span>
        <input
          .value=${n.cronTz}
          list="cron-tz-suggestions"
          @input=${e=>t.onFormChange({cronTz:e.target.value})}
          placeholder=${`America/Los_Angeles`}
        />
        <div class="cron-help">${`选择常用时区或输入有效的 IANA 时区。`}</div>
      </label>
      <div class="cron-help cron-span-2">${`需要抖动？使用高级 → 抖动窗口 / 抖动单位。`}</div>
    </div>
  `}function D(n,r){return n?e`<div id=${s(r)} class="cron-help cron-error">${n}</div>`:t}function O(n,r){let i=`list-item list-item-clickable cron-job${r.runsJobId===n.id?` list-item-selected`:``}`,a=e=>{r.onLoadRuns(n.id),e()};return e`
    <div class=${i} @click=${()=>r.onLoadRuns(n.id)}>
      <div class="cron-job-header">
        <div class="list-main">
          <div class="list-title">${n.name}</div>
          <div class="list-sub">${u(n)}</div>
          ${n.agentId?e`<div class="muted cron-job-agent">${`代理`}: ${n.agentId}</div>`:t}
        </div>
        <div class="list-meta">${N(n)}</div>
      </div>
      ${k(n)}
      <div class="cron-job-footer">
        <div class="chip-row cron-job-chips">
          <span class=${`chip ${n.enabled?`chip-ok`:`chip-danger`}`}>
            ${n.enabled?`已启用`:`已禁用`}
          </span>
          <span class="chip">${n.sessionTarget}</span>
          <span class="chip">${n.wakeMode}</span>
        </div>
        <div class="row cron-job-actions">
          <button
            class="btn"
            ?disabled=${r.busy}
            @click=${e=>{e.stopPropagation(),a(()=>r.onEdit(n))}}
          >
            ${`编辑`}
          </button>
          <button
            class="btn"
            ?disabled=${r.busy}
            @click=${e=>{e.stopPropagation(),a(()=>r.onClone(n))}}
          >
            ${`克隆`}
          </button>
          <button
            class="btn"
            ?disabled=${r.busy}
            @click=${e=>{e.stopPropagation(),a(()=>r.onToggle(n,!n.enabled))}}
          >
            ${n.enabled?`禁用`:`启用`}
          </button>
          <button
            class="btn"
            ?disabled=${r.busy}
            @click=${e=>{e.stopPropagation(),a(()=>r.onRun(n,`force`))}}
          >
            ${`运行`}
          </button>
          <button
            class="btn"
            ?disabled=${r.busy}
            @click=${e=>{e.stopPropagation(),a(()=>r.onRun(n,`due`))}}
          >
            Run if due
          </button>
          <button
            class="btn"
            ?disabled=${r.busy}
            @click=${e=>{e.stopPropagation(),r.onLoadRuns(n.id)}}
          >
            ${`历史`}
          </button>
          <button
            class="btn danger"
            ?disabled=${r.busy}
            @click=${e=>{e.stopPropagation(),a(()=>r.onRemove(n))}}
          >
            ${`删除`}
          </button>
        </div>
      </div>
    </div>
  `}function k(n){let i=o(n);if(!i)return e``;if(i.kind===`systemEvent`)return e`<div class="cron-job-detail">
      <span class="cron-job-detail-label">${`系统`}</span>
      <span class="muted cron-job-detail-value">${i.text}</span>
    </div>`;let a=n.delivery,s=(a==null?void 0:a.mode)===`webhook`?a.to?` (${a.to})`:``:a!=null&&a.channel||a!=null&&a.to?` (${a.channel??`last`}${a.to?` -> ${a.to}`:``})`:``;return e`
    <div class="cron-job-detail">
      <div class="cron-job-detail-section">
        <span class="cron-job-detail-label">${`提示`}</span>
        <div class="muted cron-job-detail-value chat-text" @click=${A}>
          ${r(l(i.message))}
        </div>
      </div>
      ${a?e`<div class="cron-job-detail-section">
            <span class="cron-job-detail-label">${`投递`}</span>
            <span class="muted cron-job-detail-value">${a.mode}${s}</span>
          </div>`:t}
    </div>
  `}function A(e){let t=e.target;t!=null&&t.closest(`a,button,input,textarea,select,summary,[role='button'],[role='link']`)&&e.stopPropagation()}function j(e){return typeof e!=`number`||!Number.isFinite(e)?`不适用`:i(e)}function M(e,t=Date.now()){let n=i(e);return e>t?`下次 ${n}`:`到期 ${n}`}function N(t){var n,r,i;let o=(n=t.state)==null?void 0:n.lastStatus,s=o===`ok`?`cron-job-status-ok`:o===`error`?`cron-job-status-error`:o===`skipped`?`cron-job-status-skipped`:`cron-job-status-na`,c=o===`ok`?`成功`:o===`error`?`错误`:o===`skipped`?`已跳过`:`不适用`,l=(r=t.state)==null?void 0:r.nextRunAtMs,u=(i=t.state)==null?void 0:i.lastRunAtMs;return e`
    <div class="cron-job-state">
      <div class="cron-job-state-row">
        <span class="cron-job-state-key">${`状态`}</span>
        <span class=${`cron-job-status-pill ${s}`}>${c}</span>
      </div>
      <div class="cron-job-state-row">
        <span class="cron-job-state-key">${`下次`}</span>
        <span class="cron-job-state-value" title=${a(l)}>
          ${j(l)}
        </span>
      </div>
      <div class="cron-job-state-row">
        <span class="cron-job-state-key">${`上次`}</span>
        <span class="cron-job-state-value" title=${a(u)}>
          ${j(u)}
        </span>
      </div>
    </div>
  `}function P(e){switch(e){case`ok`:return`成功`;case`error`:return`错误`;case`skipped`:return`已跳过`;default:return`未知`}}function F(e){switch(e){case`delivered`:return`已投递`;case`not-delivered`:return`未投递`;case`not-requested`:return`未请求`;case`unknown`:return`未知`;default:return`未知`}}function I(i,o,s){let c=typeof i.sessionKey==`string`&&i.sessionKey.trim().length>0?`${n(`chat`,o)}?session=${encodeURIComponent(i.sessionKey)}`:null,u=P(i.status??`unknown`),d=F(i.deliveryStatus??`not-requested`),f=i.usage,p=f&&typeof f.total_tokens==`number`?`${f.total_tokens} tokens`:f&&typeof f.input_tokens==`number`&&typeof f.output_tokens==`number`?`${f.input_tokens} in / ${f.output_tokens} out`:null,m=i.summary||i.error||`无摘要。`,h=!!i.error&&!!i.summary;return e`
    <div class="list-item cron-run-entry">
      <div class="cron-run-entry__header">
        <div class="list-main cron-run-entry__main">
          <div class="list-title cron-run-entry__title">
            ${i.jobName??i.jobId}
            <span class="muted"> · ${u}</span>
          </div>
          <div class="chip-row" style="margin-top: 4px;">
            <span class="chip">${d}</span>
            ${i.model?e`<span class="chip">${i.model}</span>`:t}
            ${i.provider?e`<span class="chip">${i.provider}</span>`:t}
            ${p?e`<span class="chip">${p}</span>`:t}
          </div>
        </div>
        <div class="list-meta cron-run-entry__meta">
          <div>${a(i.ts)}</div>
          ${typeof i.runAtMs==`number`?e`<div class="muted">${`运行于`} ${a(i.runAtMs)}</div>`:t}
          <div class="muted">${i.durationMs??0}ms</div>
          ${typeof i.nextRunAtMs==`number`?e`<div class="muted">${M(i.nextRunAtMs)}</div>`:t}
          ${c?e`<div>
                <a
                  class="session-link"
                  href=${c}
                  @click=${e=>{e.defaultPrevented||e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||s&&i.sessionKey&&(e.preventDefault(),s(i.sessionKey))}}
                  >${`打开运行聊天`}</a
                >
              </div>`:t}
          ${h?e`<div class="muted">${i.error}</div>`:t}
          ${i.deliveryError?e`<div class="muted">${i.deliveryError}</div>`:t}
        </div>
      </div>
      <div class="cron-run-entry__body chat-text">
        ${r(l(m))}
      </div>
    </div>
  `}export{T as renderCron};
//# sourceMappingURL=cron-Bgq84gxg.js.map