chore: 初始化仓库,导入项目基线代码
Academy v0.8.3 完整代码基线:Go 后端(internal/cmd/cli/mcp-server/docreader)、 Vue 前端(frontend)、数据库迁移(migrations)、部署编排(docker/helm/deploy)与文档。 今日开发的培训推送管理改动随后单独提交。
This commit is contained in:
commit
7ec21f35b0
5767 files changed
+1436788
No files matched your search
@@ -0,0 +1,880 @@
|
||||
<template>
|
||||
<SettingDrawer :visible="visible" :title="automation?.name || ''" icon="time" width="720px" :min-width="480"
|
||||
:max-width="960" storage-key="setting-drawer:width:automation-detail" class="automation-detail-drawer" hide-footer
|
||||
@update:visible="(v: boolean) => !v && close()">
|
||||
<template #headerIcon><t-icon name="time" class="automation-detail__header-icon" /></template>
|
||||
<template v-if="automation" #subtitle>
|
||||
<span class="automation-detail__subtitle">
|
||||
<t-tag v-if="hasEndedOnceSchedule(automation)" size="small" variant="light" :title="t('automation.scheduleEndedHint')">{{ t('automation.scheduleEnded') }}</t-tag>
|
||||
<AutomationStatusTag v-else-if="!automation.enabled" status="paused" />
|
||||
<span>{{ describeTrigger(automation.trigger, t, locale) }} · {{ automation.trigger.timezone || 'UTC' }}</span>
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<template v-if="automation" #header-actions>
|
||||
<div class="automation-detail__actions">
|
||||
<t-popconfirm :content="t('automation.runConfirm', { name: automation.name })" theme="default" placement="bottom-right"
|
||||
:confirm-btn="{ content: t('automation.actions.runNow'), theme: 'primary' }" :cancel-btn="t('common.cancel')"
|
||||
:popup-props="{ zIndex: 2600, disabled: !!busy }" @confirm="runNow">
|
||||
<button type="button" class="automation-detail__icon-btn" :disabled="!!busy" :aria-busy="busy === 'run'"
|
||||
:title="t('automation.actions.runNow')" :aria-label="t('automation.actions.runNow')">
|
||||
<t-loading v-if="busy === 'run'" size="14px" />
|
||||
<ChatActionIcon v-else name="play" />
|
||||
</button>
|
||||
</t-popconfirm>
|
||||
<button v-if="!hasEndedOnceSchedule(automation)" type="button" class="automation-detail__icon-btn" :disabled="!!busy" :aria-busy="busy === 'toggle'"
|
||||
:title="automation.enabled ? t('automation.actions.pause') : t('automation.actions.resume')"
|
||||
:aria-label="automation.enabled ? t('automation.actions.pause') : t('automation.actions.resume')" @click="toggle">
|
||||
<t-loading v-if="busy === 'toggle'" size="14px" />
|
||||
<ChatActionIcon v-else :name="automation.enabled ? 'pause' : 'resume'" />
|
||||
</button>
|
||||
<button type="button" class="automation-detail__icon-btn" :title="t('common.edit')"
|
||||
:aria-label="t('common.edit')" @click="emit('edit', automation)">
|
||||
<ChatActionIcon name="edit" />
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template v-if="automation">
|
||||
<t-alert v-if="!automation.enabled && automation.paused_reason" theme="warning" class="automation-detail__alert"
|
||||
:message="t('automation.detail.pausedBecause', { reason: automation.paused_reason })" />
|
||||
<section class="automation-detail__brief" :aria-label="t('automation.detail.task')">
|
||||
<div class="automation-detail__brief-heading">
|
||||
<div class="automation-detail__brief-context">
|
||||
<h3>{{ t('automation.detail.task') }}</h3>
|
||||
<div class="automation-detail__execution">
|
||||
<span :title="t('automation.fields.accessLevel')">{{ t(`assistant.access.levels.${automation.access_level}.label`) }}</span>
|
||||
<span :title="t('automation.fields.sessionMode')">{{ t(`automation.sessionMode.${automation.session_mode}`) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<t-popup v-model:visible="grantsVisible" trigger="click" placement="bottom-right" :z-index="2600">
|
||||
<button type="button" class="automation-detail__grants-trigger" :class="{ 'is-attention': candidates.length }"
|
||||
:aria-expanded="grantsVisible">
|
||||
<t-icon name="secured" size="14px" />
|
||||
{{ t('automation.detail.grants') }}
|
||||
<span v-if="candidates.length || grants.length" class="automation-detail__count"
|
||||
:title="candidates.length ? t('automation.grants.candidates') : t('automation.grants.active')">
|
||||
{{ candidates.length || grants.length }}
|
||||
</span>
|
||||
<t-icon name="chevron-down" size="12px" />
|
||||
</button>
|
||||
<template #content>
|
||||
<div class="automation-detail__grants-panel" role="region" :aria-label="t('automation.detail.grants')">
|
||||
<h3>{{ t('automation.detail.grants') }}</h3>
|
||||
<p class="automation-detail__muted">{{ t('automation.grants.intro') }}</p>
|
||||
<div v-if="grantsLoading" class="automation-detail__loading"><t-loading size="small" /></div>
|
||||
<template v-else>
|
||||
<ul v-if="grants.length" class="automation-detail__list">
|
||||
<li v-for="grant in grants" :key="grant.id" class="automation-grant">
|
||||
<span class="automation-grant__label">{{ grant.label || grant.grant_key }}</span>
|
||||
<t-tag size="small" variant="light" :theme="grant.risk === 'destructive' ? 'danger' : 'warning'">
|
||||
{{ t(`automation.risk.${grant.risk}`, grant.risk) }}
|
||||
</t-tag>
|
||||
<span v-if="grant.lapse" class="automation-grant__lapse">{{ t('automation.grants.lapsed') }}</span>
|
||||
<t-link theme="danger" hover="color" class="automation-grant__action" @click="revoke(grant)">
|
||||
{{ t('automation.grants.revoke') }}
|
||||
</t-link>
|
||||
</li>
|
||||
</ul>
|
||||
<template v-if="candidates.length">
|
||||
<div class="automation-detail__subhead">{{ t('automation.grants.candidates') }}</div>
|
||||
<ul class="automation-detail__list">
|
||||
<li v-for="candidate in candidates" :key="candidate.prompt_id" class="automation-grant">
|
||||
<span class="automation-grant__label">{{ candidate.label || candidate.tool }}</span>
|
||||
<t-tag size="small" variant="light" :theme="candidate.risk === 'destructive' ? 'danger' : 'warning'">
|
||||
{{ t(`automation.risk.${candidate.risk}`, candidate.risk) }}
|
||||
</t-tag>
|
||||
<span v-if="candidate.service_name" class="automation-grant__meta">{{ candidate.service_name }}</span>
|
||||
<t-link theme="primary" hover="color" class="automation-grant__action" @click="allow(candidate)">
|
||||
{{ t('automation.grants.allow') }}
|
||||
</t-link>
|
||||
</li>
|
||||
</ul>
|
||||
</template>
|
||||
<p v-if="!grants.length && !candidates.length" class="automation-detail__muted">{{ t('automation.grants.none') }}</p>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
</t-popup>
|
||||
</div>
|
||||
<div
|
||||
ref="instructionScroller"
|
||||
class="automation-detail__instruction-scroll"
|
||||
:class="{
|
||||
'automation-detail__instruction-scroll--more': instructionHasMore,
|
||||
'automation-detail__instruction-scroll--expanded': instructionExpanded,
|
||||
}"
|
||||
:style="{ maxHeight: instructionExpanded ? 'none' : `${INSTRUCTION_PREVIEW_HEIGHT}px` }"
|
||||
@scroll="updateInstructionOverflow"
|
||||
>
|
||||
<p ref="instructionContent" class="automation-detail__instruction">{{ automation.instruction }}</p>
|
||||
</div>
|
||||
<button
|
||||
v-if="instructionCanExpand"
|
||||
type="button"
|
||||
class="automation-detail__instruction-toggle"
|
||||
:aria-label="t(instructionExpanded ? 'common.collapse' : 'common.expand')"
|
||||
:title="t(instructionExpanded ? 'common.collapse' : 'common.expand')"
|
||||
:aria-expanded="instructionExpanded"
|
||||
@click="toggleInstruction"
|
||||
>
|
||||
<t-icon :name="instructionExpanded ? 'chevron-up' : 'chevron-down'" size="16px" />
|
||||
</button>
|
||||
</section>
|
||||
|
||||
<section class="automation-detail__history" :aria-label="t('automation.detail.runs')">
|
||||
<div class="automation-detail__history-header">
|
||||
<h3 class="automation-detail__history-heading">
|
||||
{{ t('automation.detail.runs') }}<span class="automation-detail__count">{{ runsTotal }}</span>
|
||||
</h3>
|
||||
<span v-if="automation.enabled && automation.next_run_at" class="automation-detail__next-run">
|
||||
{{ t('automation.fields.nextRun') }}
|
||||
<time :datetime="automation.next_run_at">{{ when(automation.next_run_at) }}</time>
|
||||
</span>
|
||||
</div>
|
||||
<div v-if="runsLoading && !runs.length" class="automation-detail__loading"><t-loading size="small" /></div>
|
||||
<p v-else-if="!runs.length" class="automation-detail__muted">{{ t('automation.detail.noRuns') }}</p>
|
||||
<div v-else class="automation-detail__timeline">
|
||||
<section v-for="group in runGroups" :key="group.date" class="automation-detail__day">
|
||||
<h5 class="automation-detail__date">{{ group.date }}</h5>
|
||||
<ul class="automation-detail__runs">
|
||||
<li v-for="run in group.runs" :key="run.id" class="automation-run" :class="{ 'is-focused': run.id === focusRunId }">
|
||||
<span class="automation-run__marker"><AutomationStatusTag :status="run.status" icon-only /></span>
|
||||
<div class="automation-run__body">
|
||||
<div class="automation-run__head">
|
||||
<time class="automation-run__time" :datetime="run.scheduled_at">{{ runTime(run.scheduled_at) }}</time>
|
||||
<span class="automation-run__meta">
|
||||
{{ t(`automation.runTrigger.${run.trigger_kind}`) }}<template v-if="duration(run)"> · {{ duration(run) }}</template>
|
||||
</span>
|
||||
<t-link v-if="cancellable(run)" theme="danger" hover="color" class="automation-run__stop"
|
||||
:disabled="run.cancel_requested" @click="cancel(run)">
|
||||
{{ run.cancel_requested ? t('automation.detail.stopping') : t('automation.actions.stop') }}
|
||||
</t-link>
|
||||
</div>
|
||||
<component :is="run.session_id ? 'button' : 'div'" class="automation-run__result"
|
||||
:type="run.session_id ? 'button' : undefined"
|
||||
:aria-label="run.session_id ? `${when(run.scheduled_at)} · ${t('automation.actions.openConversation')}` : undefined"
|
||||
@click="run.session_id && openRun(run)">
|
||||
<p v-if="run.error" class="automation-run__text is-error">{{ run.error }}</p>
|
||||
<p v-else-if="run.answer" class="automation-run__text">{{ run.answer }}</p>
|
||||
<span v-else class="automation-detail__muted">{{ t(`automation.status.${run.status}`) }}</span>
|
||||
<t-icon v-if="run.session_id" name="arrow-right-up" size="16px" class="automation-run__chevron" />
|
||||
</component>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
</div>
|
||||
<div v-if="runs.length < runsTotal" class="automation-detail__more">
|
||||
<t-button size="small" variant="text" :loading="runsLoading" @click="loadRuns(false)">
|
||||
{{ t('common.loadMore') }}
|
||||
</t-button>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
</SettingDrawer>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onBeforeUnmount, ref, watch } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { DialogPlugin, MessagePlugin } from 'tdesign-vue-next'
|
||||
import {
|
||||
addAutomationGrant,
|
||||
cancelAutomationRun,
|
||||
listAutomationGrantCandidates,
|
||||
listAutomationGrants,
|
||||
listAutomationRuns,
|
||||
pauseAutomation,
|
||||
resumeAutomation,
|
||||
revokeAutomationGrant,
|
||||
runAutomationNow,
|
||||
type Automation,
|
||||
type AutomationGrant,
|
||||
type AutomationGrantCandidate,
|
||||
type AutomationRun,
|
||||
} from '@/api/automation'
|
||||
import { describeTrigger, formatInZone, hasEndedOnceSchedule } from '@/utils/automationSchedule'
|
||||
import { useAssistantDataChange } from '@/utils/assistantDataChange'
|
||||
import SettingDrawer from '@/components/settings/SettingDrawer.vue'
|
||||
import AutomationStatusTag from './AutomationStatusTag.vue'
|
||||
import ChatActionIcon from '@/components/ChatActionIcon.vue'
|
||||
|
||||
const props = defineProps<{
|
||||
visible: boolean
|
||||
automation: Automation | null
|
||||
focusRunId?: string
|
||||
}>()
|
||||
const emit = defineEmits<{
|
||||
'update:visible': [value: boolean]
|
||||
changed: [value: Automation]
|
||||
edit: [value: Automation]
|
||||
}>()
|
||||
|
||||
const { t, locale } = useI18n()
|
||||
const router = useRouter()
|
||||
|
||||
const PAGE = 20
|
||||
const busy = ref<'' | 'run' | 'toggle'>('')
|
||||
const grantsVisible = ref(false)
|
||||
const runs = ref<AutomationRun[]>([])
|
||||
const runsTotal = ref(0)
|
||||
const runsPage = ref(0)
|
||||
const runsLoading = ref(false)
|
||||
const grants = ref<AutomationGrant[]>([])
|
||||
const candidates = ref<AutomationGrantCandidate[]>([])
|
||||
const grantsLoading = ref(false)
|
||||
const instructionScroller = ref<HTMLElement | null>(null)
|
||||
const instructionContent = ref<HTMLElement | null>(null)
|
||||
const instructionHasMore = ref(false)
|
||||
const instructionCanExpand = ref(false)
|
||||
const instructionExpanded = ref(false)
|
||||
const INSTRUCTION_PREVIEW_HEIGHT = 160
|
||||
let poll: ReturnType<typeof setInterval> | undefined
|
||||
let detailVersion = 0
|
||||
let refreshRunsAfterLoad = false
|
||||
|
||||
function updateInstructionOverflow() {
|
||||
const el = instructionScroller.value
|
||||
instructionCanExpand.value = !!el && el.scrollHeight > INSTRUCTION_PREVIEW_HEIGHT + 1
|
||||
instructionHasMore.value = !instructionExpanded.value && !!el && el.scrollHeight - el.clientHeight - el.scrollTop > 1
|
||||
}
|
||||
|
||||
function toggleInstruction() {
|
||||
instructionExpanded.value = !instructionExpanded.value
|
||||
if (instructionScroller.value) instructionScroller.value.scrollTop = 0
|
||||
}
|
||||
|
||||
watch(instructionExpanded, updateInstructionOverflow, { flush: 'post' })
|
||||
|
||||
watch(
|
||||
[instructionScroller, instructionContent, () => props.visible, () => props.automation?.instruction],
|
||||
(_, __, onCleanup) => {
|
||||
updateInstructionOverflow()
|
||||
if (!props.visible || !instructionScroller.value || !instructionContent.value) return
|
||||
const observer = new ResizeObserver(updateInstructionOverflow)
|
||||
observer.observe(instructionScroller.value)
|
||||
observer.observe(instructionContent.value)
|
||||
onCleanup(() => observer.disconnect())
|
||||
},
|
||||
{ flush: 'post' },
|
||||
)
|
||||
|
||||
const when = (iso: string | null) => formatInZone(iso, props.automation?.trigger.timezone, locale.value)
|
||||
const runDateFormatter = computed(() => new Intl.DateTimeFormat(locale.value, {
|
||||
timeZone: props.automation?.trigger.timezone || 'UTC', year: 'numeric', month: 'long', day: 'numeric',
|
||||
}))
|
||||
const runTimeFormatter = computed(() => new Intl.DateTimeFormat(locale.value, {
|
||||
timeZone: props.automation?.trigger.timezone || 'UTC', hour: '2-digit', minute: '2-digit', hour12: false,
|
||||
}))
|
||||
const runTime = (iso: string) => runTimeFormatter.value.format(new Date(iso))
|
||||
const runGroups = computed(() => {
|
||||
const groups = new Map<string, AutomationRun[]>()
|
||||
for (const run of runs.value) {
|
||||
const date = runDateFormatter.value.format(new Date(run.scheduled_at))
|
||||
const group = groups.get(date) ?? []
|
||||
group.push(run)
|
||||
groups.set(date, group)
|
||||
}
|
||||
return [...groups].map(([date, runs]) => ({ date, runs }))
|
||||
})
|
||||
const cancellable = (run: AutomationRun) =>
|
||||
run.status === 'queued' || run.status === 'running' || run.status === 'awaiting_approval'
|
||||
|
||||
function duration(run: AutomationRun): string {
|
||||
if (!run.started_at || !run.finished_at) return ''
|
||||
const seconds = Math.round((Date.parse(run.finished_at) - Date.parse(run.started_at)) / 1000)
|
||||
if (!Number.isFinite(seconds) || seconds < 0) return ''
|
||||
if (seconds < 60) return t('automation.detail.durationSeconds', { n: Math.max(1, seconds) })
|
||||
return t('automation.detail.durationMinutes', { n: Math.round(seconds / 60) })
|
||||
}
|
||||
|
||||
function close() {
|
||||
emit('update:visible', false)
|
||||
}
|
||||
|
||||
async function loadRuns(reset: boolean) {
|
||||
const a = props.automation
|
||||
if (!a) return
|
||||
const version = detailVersion
|
||||
runsLoading.value = true
|
||||
try {
|
||||
const page = reset ? 1 : runsPage.value + 1
|
||||
const res = await listAutomationRuns(a.id, page, PAGE)
|
||||
if (version !== detailVersion) return
|
||||
const items = res.data ?? []
|
||||
runs.value = reset ? items : [...runs.value, ...items]
|
||||
runsTotal.value = res.total ?? runs.value.length
|
||||
runsPage.value = page
|
||||
} catch (e: any) {
|
||||
if (version === detailVersion) MessagePlugin.error(e?.message || t('common.operationFailed'))
|
||||
} finally {
|
||||
if (version === detailVersion) {
|
||||
runsLoading.value = false
|
||||
if (refreshRunsAfterLoad) {
|
||||
refreshRunsAfterLoad = false
|
||||
void refreshActive(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Refresh the first page in place while a run is in flight, so its status
|
||||
// moves without the user reopening the drawer.
|
||||
async function refreshActive(force = false) {
|
||||
const a = props.automation
|
||||
if (!props.visible || !a) return
|
||||
if (runsLoading.value) {
|
||||
if (force) refreshRunsAfterLoad = true
|
||||
return
|
||||
}
|
||||
if (!force && !runs.value.some(cancellable)) return
|
||||
const version = detailVersion
|
||||
try {
|
||||
const res = await listAutomationRuns(a.id, 1, PAGE)
|
||||
if (version !== detailVersion) return
|
||||
const fresh = new Map((res.data ?? []).map((run) => [run.id, run]))
|
||||
const known = new Set(runs.value.map((run) => run.id))
|
||||
runs.value = [
|
||||
...(res.data ?? []).filter((run) => !known.has(run.id)),
|
||||
...runs.value.map((run) => fresh.get(run.id) ?? run),
|
||||
]
|
||||
runsTotal.value = res.total ?? runsTotal.value
|
||||
} catch {
|
||||
// The next tick tries again.
|
||||
}
|
||||
}
|
||||
|
||||
useAssistantDataChange(changes => {
|
||||
if (changes.some(change => change.operation === 'automation.run_now')) void refreshActive(true)
|
||||
}, { areas: ['automation'] })
|
||||
|
||||
async function loadGrants() {
|
||||
const a = props.automation
|
||||
if (!a) return
|
||||
grantsLoading.value = true
|
||||
try {
|
||||
const [g, c] = await Promise.all([listAutomationGrants(a.id), listAutomationGrantCandidates(a.id)])
|
||||
grants.value = g.data ?? []
|
||||
candidates.value = c.data ?? []
|
||||
} catch (e: any) {
|
||||
MessagePlugin.error(e?.message || t('common.operationFailed'))
|
||||
} finally {
|
||||
grantsLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
watch([() => props.visible, () => props.automation?.id], ([open, id]) => {
|
||||
++detailVersion
|
||||
refreshRunsAfterLoad = false
|
||||
instructionExpanded.value = false
|
||||
clearInterval(poll)
|
||||
if (!open || !id) return
|
||||
grantsVisible.value = false
|
||||
runs.value = []
|
||||
runsTotal.value = 0
|
||||
grants.value = []
|
||||
candidates.value = []
|
||||
void loadRuns(true)
|
||||
void loadGrants()
|
||||
poll = setInterval(refreshActive, 5000)
|
||||
}, { immediate: true })
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
++detailVersion
|
||||
clearInterval(poll)
|
||||
})
|
||||
|
||||
async function runNow() {
|
||||
if (busy.value) return
|
||||
const a = props.automation
|
||||
if (!a) return
|
||||
busy.value = 'run'
|
||||
try {
|
||||
const res = await runAutomationNow(a.id)
|
||||
MessagePlugin.success(t('automation.messages.queued'))
|
||||
if (res.data) {
|
||||
grantsVisible.value = false
|
||||
runs.value = [res.data, ...runs.value]
|
||||
runsTotal.value += 1
|
||||
}
|
||||
} catch (e: any) {
|
||||
MessagePlugin.error(e?.message || t('common.operationFailed'))
|
||||
} finally {
|
||||
busy.value = ''
|
||||
}
|
||||
}
|
||||
|
||||
async function toggle() {
|
||||
const a = props.automation
|
||||
if (!a || busy.value) return
|
||||
if (hasEndedOnceSchedule(a)) {
|
||||
MessagePlugin.warning(t('automation.scheduleEndedHint'))
|
||||
return
|
||||
}
|
||||
busy.value = 'toggle'
|
||||
try {
|
||||
const res = a.enabled ? await pauseAutomation(a.id) : await resumeAutomation(a.id)
|
||||
emit('changed', res.data)
|
||||
} catch (e: any) {
|
||||
MessagePlugin.error(e?.message || t('common.operationFailed'))
|
||||
} finally {
|
||||
busy.value = ''
|
||||
}
|
||||
}
|
||||
|
||||
function openRun(run: AutomationRun) {
|
||||
close()
|
||||
void router.push(`/platform/chat/${encodeURIComponent(run.session_id)}`)
|
||||
}
|
||||
|
||||
async function cancel(run: AutomationRun) {
|
||||
try {
|
||||
const res = await cancelAutomationRun(run.id)
|
||||
runs.value = runs.value.map((r) => (r.id === run.id ? res.data : r))
|
||||
} catch (e: any) {
|
||||
MessagePlugin.error(e?.message || t('common.operationFailed'))
|
||||
}
|
||||
}
|
||||
|
||||
function allow(candidate: AutomationGrantCandidate) {
|
||||
const a = props.automation
|
||||
if (!a) return
|
||||
grantsVisible.value = false
|
||||
const destructive = candidate.risk === 'destructive'
|
||||
const dialog = DialogPlugin.confirm({
|
||||
header: t('automation.grants.allowTitle'),
|
||||
body: t(destructive ? 'automation.grants.allowDestructiveBody' : 'automation.grants.allowBody', {
|
||||
label: candidate.label || candidate.tool,
|
||||
}),
|
||||
theme: destructive ? 'danger' : 'warning',
|
||||
confirmBtn: { content: t('automation.grants.allow'), theme: destructive ? 'danger' : 'primary' },
|
||||
onConfirm: async () => {
|
||||
dialog.hide()
|
||||
try {
|
||||
await addAutomationGrant(a.id, candidate.prompt_id)
|
||||
await loadGrants()
|
||||
} catch (e: any) {
|
||||
MessagePlugin.error(e?.message || t('common.operationFailed'))
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
async function revoke(grant: AutomationGrant) {
|
||||
try {
|
||||
await revokeAutomationGrant(grant.id)
|
||||
await loadGrants()
|
||||
} catch (e: any) {
|
||||
MessagePlugin.error(e?.message || t('common.operationFailed'))
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.automation-detail__actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.automation-detail__icon-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
border-radius: var(--app-radius-sm);
|
||||
background: transparent;
|
||||
color: color-mix(in srgb, var(--td-text-color-primary) 55%, transparent);
|
||||
cursor: pointer;
|
||||
|
||||
&:hover:not(:disabled) {
|
||||
color: var(--td-text-color-secondary);
|
||||
background: color-mix(in srgb, var(--td-text-color-primary) 5%, transparent);
|
||||
}
|
||||
&:active:not(:disabled) {
|
||||
background: color-mix(in srgb, var(--td-text-color-primary) 9%, transparent);
|
||||
}
|
||||
&:focus-visible {
|
||||
outline: 2px solid var(--td-brand-color-focus);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
&:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.4;
|
||||
}
|
||||
}
|
||||
|
||||
.automation-detail__subtitle {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.automation-detail__alert {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.automation-detail__header-icon {
|
||||
color: var(--td-text-color-secondary);
|
||||
}
|
||||
|
||||
:global(.automation-detail-drawer .setting-drawer__header-icon) {
|
||||
color: var(--td-text-color-secondary);
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
}
|
||||
|
||||
.automation-detail__next-run {
|
||||
display: inline-flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: var(--app-text-xs);
|
||||
line-height: 1.6;
|
||||
|
||||
time { font-variant-numeric: tabular-nums; }
|
||||
}
|
||||
|
||||
.automation-detail__brief {
|
||||
padding: 14px 16px 16px;
|
||||
border-radius: var(--app-radius-lg);
|
||||
background: color-mix(in srgb, var(--td-bg-color-secondarycontainer) 40%, var(--td-bg-color-container));
|
||||
}
|
||||
|
||||
.automation-detail__brief-heading {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
margin-bottom: 14px;
|
||||
|
||||
h3 { margin: 0; font-size: var(--app-text-sm); font-weight: 600; color: var(--td-text-color-primary); }
|
||||
}
|
||||
|
||||
.automation-detail__brief-context { min-width: 0; }
|
||||
|
||||
.automation-detail__grants-trigger {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
padding: 4px 6px;
|
||||
border: 0;
|
||||
border-radius: var(--app-radius-sm);
|
||||
background: transparent;
|
||||
color: var(--td-text-color-secondary);
|
||||
font: inherit;
|
||||
font-size: var(--app-text-xs);
|
||||
cursor: pointer;
|
||||
|
||||
&:hover, &[aria-expanded="true"] { color: var(--td-text-color-primary); background: var(--td-bg-color-container-hover); }
|
||||
&:focus-visible { outline: 1px solid var(--td-brand-color-focus); outline-offset: 2px; }
|
||||
&.is-attention { color: var(--td-warning-color); }
|
||||
}
|
||||
|
||||
.automation-detail__count {
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-size: var(--app-text-xs);
|
||||
font-weight: 400;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.is-attention .automation-detail__count { color: inherit; }
|
||||
|
||||
.automation-detail__grants-panel {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 14px;
|
||||
box-sizing: border-box;
|
||||
width: min(380px, calc(100vw - 48px));
|
||||
max-height: min(480px, 65vh);
|
||||
overflow-y: auto;
|
||||
padding: 12px;
|
||||
|
||||
h3 { margin: 0; font-size: var(--app-text-md); font-weight: 600; color: var(--td-text-color-primary); }
|
||||
}
|
||||
|
||||
.automation-detail__execution {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 4px 0;
|
||||
margin-top: 4px;
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: var(--app-text-xs);
|
||||
line-height: 1.5;
|
||||
|
||||
> span + span::before { content: '·'; margin: 0 8px; color: var(--td-text-color-placeholder); }
|
||||
}
|
||||
|
||||
.automation-detail__history { margin-top: 24px; }
|
||||
|
||||
.automation-detail__history-header {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px 16px;
|
||||
margin-bottom: 18px;
|
||||
}
|
||||
|
||||
.automation-detail__history-heading {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin: 0;
|
||||
color: var(--td-text-color-primary);
|
||||
font-size: var(--app-text-md);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.automation-detail__instruction-scroll {
|
||||
box-sizing: border-box;
|
||||
overflow-y: auto;
|
||||
overscroll-behavior: contain;
|
||||
scrollbar-width: thin;
|
||||
|
||||
&--expanded {
|
||||
overflow: visible;
|
||||
overscroll-behavior: auto;
|
||||
}
|
||||
}
|
||||
|
||||
.automation-detail__instruction-scroll--more {
|
||||
mask-image: linear-gradient(to bottom, #000 calc(100% - 28px), transparent);
|
||||
}
|
||||
|
||||
.automation-detail__instruction-toggle {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 32px;
|
||||
height: 24px;
|
||||
margin: 6px auto -6px;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
border-radius: var(--app-radius-md);
|
||||
background: transparent;
|
||||
color: var(--td-text-color-secondary);
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
color: var(--td-text-color-primary);
|
||||
background: var(--td-bg-color-container);
|
||||
}
|
||||
|
||||
&:focus-visible {
|
||||
outline: 2px solid var(--td-text-color-secondary);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
}
|
||||
|
||||
.automation-detail__instruction {
|
||||
margin: 0;
|
||||
color: var(--td-text-color-primary);
|
||||
font-size: var(--app-text-md);
|
||||
line-height: 1.6;
|
||||
white-space: pre-wrap;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.automation-detail__muted {
|
||||
margin: 0;
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-size: var(--app-text-sm);
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.automation-detail__loading,
|
||||
.automation-detail__more {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.automation-detail__subhead {
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: var(--app-text-sm);
|
||||
}
|
||||
|
||||
.automation-detail__list {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border: 1px solid var(--td-component-stroke);
|
||||
border-radius: var(--app-radius-md);
|
||||
list-style: none;
|
||||
|
||||
> li + li {
|
||||
border-top: 1px solid var(--td-component-stroke);
|
||||
}
|
||||
}
|
||||
|
||||
.automation-detail__day + .automation-detail__day { margin-top: 20px; }
|
||||
|
||||
.automation-detail__date {
|
||||
margin: 0 0 12px;
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: var(--app-text-sm);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.automation-detail__runs {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
.automation-run {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 12px;
|
||||
padding-bottom: 20px;
|
||||
|
||||
&::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
left: 9px;
|
||||
top: 24px;
|
||||
bottom: 0;
|
||||
width: 1px;
|
||||
background: var(--td-component-stroke);
|
||||
}
|
||||
&:last-child { padding-bottom: 0; }
|
||||
&:last-child::before { display: none; }
|
||||
&.is-focused .automation-run__result {
|
||||
background: color-mix(in srgb, var(--td-brand-color) 5%, var(--td-bg-color-container));
|
||||
}
|
||||
}
|
||||
|
||||
.automation-run__marker {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
min-width: 20px;
|
||||
padding-top: 2px;
|
||||
}
|
||||
|
||||
.automation-run__result {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 12px;
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
margin-top: 8px;
|
||||
padding: 12px 14px;
|
||||
border: 0;
|
||||
border-radius: var(--app-radius-lg);
|
||||
background: color-mix(in srgb, var(--td-bg-color-secondarycontainer) 40%, var(--td-bg-color-container));
|
||||
text-align: left;
|
||||
font: inherit;
|
||||
transition: background-color var(--app-motion-fast) ease;
|
||||
}
|
||||
|
||||
button.automation-run__result {
|
||||
cursor: pointer;
|
||||
&:hover { background: var(--td-bg-color-container-hover); }
|
||||
&:focus-visible {
|
||||
outline: 1px solid var(--td-brand-color-focus);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
}
|
||||
|
||||
.automation-run__body {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.automation-run__head {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.automation-run__time {
|
||||
color: var(--td-text-color-primary);
|
||||
font-size: var(--app-text-md);
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.automation-run__meta {
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-size: var(--app-text-sm);
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.automation-run__stop {
|
||||
margin-left: auto;
|
||||
font-size: var(--app-text-sm);
|
||||
}
|
||||
|
||||
.automation-run__chevron {
|
||||
flex-shrink: 0;
|
||||
margin-left: auto;
|
||||
margin-top: 3px;
|
||||
color: var(--td-text-color-placeholder);
|
||||
}
|
||||
|
||||
.automation-run__text {
|
||||
display: -webkit-box;
|
||||
-webkit-box-orient: vertical;
|
||||
-webkit-line-clamp: 3;
|
||||
line-clamp: 3;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
color: var(--td-text-color-primary);
|
||||
font-size: var(--app-text-md);
|
||||
line-height: 1.6;
|
||||
white-space: pre-wrap;
|
||||
overflow-wrap: anywhere;
|
||||
|
||||
&.is-error {
|
||||
color: var(--td-error-color);
|
||||
}
|
||||
}
|
||||
|
||||
.automation-grant {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
min-width: 0;
|
||||
padding: 10px 14px;
|
||||
}
|
||||
|
||||
.automation-grant__label {
|
||||
min-width: 0;
|
||||
flex-basis: 100%;
|
||||
color: var(--td-text-color-primary);
|
||||
font-size: var(--app-text-sm);
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.automation-grant__meta,
|
||||
.automation-grant__lapse {
|
||||
font-size: var(--app-text-sm);
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.automation-grant__meta {
|
||||
color: var(--td-text-color-placeholder);
|
||||
}
|
||||
|
||||
.automation-grant__lapse {
|
||||
color: var(--td-warning-color);
|
||||
}
|
||||
|
||||
.automation-grant__action {
|
||||
flex-shrink: 0;
|
||||
margin-left: auto;
|
||||
font-size: var(--app-text-sm);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,750 @@
|
||||
<template>
|
||||
<SettingsModalShell :visible="visible"
|
||||
:title="automation ? t('automation.editor.editTitle') : t('automation.editor.createTitle')"
|
||||
v-model="section" :nav-groups="navGroups" :z-index="1000" @close="modalShell.requestClose">
|
||||
<div class="content-wrapper">
|
||||
<!-- 基本信息 -->
|
||||
<div v-show="section === 'basic'" class="section">
|
||||
<div class="section-header">
|
||||
<h2>{{ t('automation.editor.sections.basic.title') }}</h2>
|
||||
<p class="section-description">{{ t('automation.editor.sections.basic.desc') }}</p>
|
||||
</div>
|
||||
<div class="settings-group">
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ t('automation.fields.name') }}<span class="required">*</span></label>
|
||||
<p class="desc">{{ t('automation.editor.nameDesc') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-input v-model="form.name" :maxlength="100" :placeholder="t('automation.editor.namePlaceholder')" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ t('automation.editor.model') }}</label>
|
||||
<p class="desc">{{ t('automation.editor.modelHelp') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<ModelSelector v-model:selected-model-id="form.model_id" model-type="KnowledgeQA" clearable
|
||||
:placeholder="t('automation.editor.modelDefault')" @add-model="uiStore.openSettings('models', 'llm')" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="setting-row setting-row-vertical">
|
||||
<div class="setting-info">
|
||||
<label>{{ t('automation.fields.instruction') }}<span class="required">*</span></label>
|
||||
<p class="desc">{{ t('automation.editor.unattendedHint') }}</p>
|
||||
</div>
|
||||
<div class="setting-control setting-control-full automation-editor__stack">
|
||||
<t-textarea v-model="form.instruction" :autosize="{ minRows: 6, maxRows: 16 }" :maxlength="20000"
|
||||
:placeholder="t('automation.editor.instructionPlaceholder')" />
|
||||
<p class="automation-editor__hint">
|
||||
{{ t('automation.editor.variablesHint') }}
|
||||
<code v-for="tag in VARIABLE_TAGS" :key="tag">{{ tag }}</code>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 运行时间 -->
|
||||
<div v-show="section === 'schedule'" class="section">
|
||||
<div class="section-header">
|
||||
<h2>{{ t('automation.editor.sections.schedule.title') }}</h2>
|
||||
<p class="section-description">{{ t('automation.editor.sections.schedule.desc') }}</p>
|
||||
</div>
|
||||
<div class="settings-group">
|
||||
<div class="setting-row setting-row-vertical">
|
||||
<div class="setting-info">
|
||||
<label>{{ t('automation.editor.frequency') }}<span class="required">*</span></label>
|
||||
</div>
|
||||
<div class="setting-control setting-control-full">
|
||||
<div class="automation-editor__frequency" role="group" :aria-label="t('automation.editor.frequency')">
|
||||
<label v-for="kind in KINDS" :key="kind" class="automation-editor__frequency-option">
|
||||
<input v-model="schedule.kind" type="radio" name="automation-frequency" :value="kind" />
|
||||
<span>{{ t(`automation.schedule.kinds.${kind}`) }}</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="schedule.kind === 'weekly'" class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ t('automation.editor.weekdays') }}</label>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-checkbox-group v-model="schedule.days" class="automation-editor__days">
|
||||
<t-checkbox v-for="day in WEEK" :key="day" :value="day">{{ weekdayName(day, locale) }}</t-checkbox>
|
||||
</t-checkbox-group>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="schedule.kind === 'monthly'" class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ t('automation.schedule.dayOfMonth') }}</label>
|
||||
<p class="desc">{{ t('automation.editor.dayOfMonthDesc') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-input-number v-model="schedule.day" :min="1" :max="31" theme="column" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="schedule.kind === 'hourly'" class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ t('automation.schedule.atMinute') }}</label>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-input-number v-model="schedule.minute" :min="0" :max="59" theme="column" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else-if="schedule.kind === 'once'" class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ t('automation.editor.runAt') }}</label>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-date-picker v-model="schedule.at" enable-time-picker format="YYYY-MM-DD HH:mm"
|
||||
value-type="YYYY-MM-DD HH:mm" :placeholder="t('automation.schedule.pickTime')" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else-if="schedule.kind === 'custom'" class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ t('automation.editor.cron') }}</label>
|
||||
<p class="desc">{{ t('automation.schedule.customHint') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-input v-model="schedule.expr" class="automation-editor__mono" placeholder="0 9 * * 1-5" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ t('automation.editor.timeOfDay') }}</label>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-time-picker v-model="clock" format="HH:mm" :clearable="false" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ t('automation.fields.timezone') }}</label>
|
||||
<p class="desc">{{ t('automation.editor.timezoneDesc') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-select v-model="timezone" filterable>
|
||||
<t-option v-for="zone in zones" :key="zone" :value="zone" :label="zone" />
|
||||
</t-select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-row setting-row-vertical">
|
||||
<div class="setting-info">
|
||||
<label>{{ t('automation.schedule.nextRuns') }}</label>
|
||||
</div>
|
||||
<div class="setting-control setting-control-full">
|
||||
<div class="automation-editor__preview" :class="{ 'is-error': previewError }" aria-live="polite">
|
||||
<template v-if="previewError">
|
||||
<t-icon name="error-circle" size="16px" /> {{ previewError }}
|
||||
</template>
|
||||
<ul v-else-if="previewRuns.length" class="automation-editor__runs">
|
||||
<li v-for="run in previewRuns" :key="run">
|
||||
<t-icon name="time" size="14px" /> {{ formatInZone(run, timezone, locale) }}
|
||||
</li>
|
||||
</ul>
|
||||
<span v-else-if="previewLoading">{{ t('common.loading') }}</span>
|
||||
<span v-else class="automation-editor__muted">{{ t('automation.editor.previewEmpty') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 执行方式 -->
|
||||
<div v-show="section === 'execution'" class="section">
|
||||
<div class="section-header">
|
||||
<h2>{{ t('automation.editor.sections.execution.title') }}</h2>
|
||||
<p class="section-description">{{ t('automation.editor.sections.execution.desc') }}</p>
|
||||
</div>
|
||||
<div class="settings-group">
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ t('automation.fields.accessLevel') }}</label>
|
||||
<p class="desc">{{ t(`automation.editor.access.${form.access_level}`) }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-select v-model="form.access_level">
|
||||
<t-option v-for="level in ASSISTANT_ACCESS_LEVELS" :key="level" :value="level"
|
||||
:label="t(`assistant.access.levels.${level}.label`)" />
|
||||
</t-select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ t('automation.fields.sessionMode') }}</label>
|
||||
<p class="desc">{{ t(`automation.editor.sessionModeDesc.${form.session_mode}`) }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-select v-model="form.session_mode">
|
||||
<t-option value="per_run" :label="t('automation.sessionMode.per_run')" />
|
||||
<t-option value="persistent" :label="t('automation.sessionMode.persistent')" />
|
||||
</t-select>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="form.session_mode === 'per_run'" class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ t('automation.fields.carryLastResult') }}</label>
|
||||
<p class="desc">{{ t('automation.editor.carryDesc') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-switch v-model="form.carry_last_result" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ t('automation.fields.overlapPolicy') }}</label>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-select v-model="form.overlap_policy">
|
||||
<t-option value="skip" :label="t('automation.overlap.skip')" />
|
||||
<t-option value="queue" :label="t('automation.overlap.queue')" />
|
||||
</t-select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ t('automation.fields.misfirePolicy') }}</label>
|
||||
<p class="desc">{{ t('automation.editor.misfireDesc') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-select v-model="form.misfire_policy">
|
||||
<t-option value="skip" :label="t('automation.misfire.skip')" />
|
||||
<t-option value="run_once" :label="t('automation.misfire.run_once')" />
|
||||
</t-select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ t('automation.fields.maxDuration') }}</label>
|
||||
<p class="desc">{{ t('automation.editor.maxDurationDesc') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<div class="automation-editor__number">
|
||||
<t-input-number v-model="maxMinutes" :min="1" :max="240" :step="1" :decimal-places="0"
|
||||
theme="row" :allow-input-over-limit="false" :aria-label="t('automation.fields.maxDuration')" />
|
||||
<span>{{ t('automation.units.minutes') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 审批与通知 -->
|
||||
<div v-show="section === 'notify'" class="section">
|
||||
<div class="section-header">
|
||||
<h2>{{ t('automation.editor.sections.notify.title') }}</h2>
|
||||
<p class="section-description">{{ t('automation.editor.sections.notify.desc') }}</p>
|
||||
</div>
|
||||
<div class="settings-group">
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ t('automation.fields.approvalTimeout') }}</label>
|
||||
<p class="desc">{{ t('automation.editor.approvalTimeoutHelp') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<div class="automation-editor__number">
|
||||
<t-input-number v-model="approvalHours" :min="1" :max="168" :step="1" :decimal-places="0"
|
||||
theme="row" :allow-input-over-limit="false" :aria-label="t('automation.fields.approvalTimeout')" />
|
||||
<span>{{ t('automation.units.hours') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ t('automation.fields.notifyOnSuccess') }}</label>
|
||||
<p class="desc">{{ t('automation.editor.notifyHint') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-switch v-model="form.notify_on_success" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<template #footer-note>
|
||||
<p v-if="previewRuns.length && !previewError" class="automation-editor__next-run">
|
||||
<t-icon name="time" size="14px" />
|
||||
<span>{{ t('automation.fields.nextRun') }}</span>
|
||||
<time :datetime="previewRuns[0]">{{ formatInZone(previewRuns[0], timezone, locale) }}</time>
|
||||
</p>
|
||||
</template>
|
||||
<template #footer>
|
||||
<t-button theme="default" variant="outline" @click="modalShell.requestClose">{{ t('common.cancel') }}</t-button>
|
||||
<t-button theme="primary" :loading="saving" @click="save">
|
||||
{{ automation ? t('common.save') : t('common.create') }}
|
||||
</t-button>
|
||||
</template>
|
||||
</SettingsModalShell>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, reactive, ref, watch } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import SettingsModalShell from '@/components/SettingsModalShell.vue'
|
||||
import { useModalShell } from '@/composables/useModalShell'
|
||||
import {
|
||||
createAutomation,
|
||||
updateAutomation,
|
||||
validateAutomationTrigger,
|
||||
type Automation,
|
||||
type AutomationInput,
|
||||
} from '@/api/automation'
|
||||
import { ASSISTANT_ACCESS_LEVELS } from '@/api/assistant'
|
||||
import {
|
||||
browserTimezone,
|
||||
defaultScheduleForm,
|
||||
formatInZone,
|
||||
scheduleFormFromTrigger,
|
||||
timezoneOptions,
|
||||
triggerFromScheduleForm,
|
||||
weekdayName,
|
||||
type ScheduleKind,
|
||||
} from '@/utils/automationSchedule'
|
||||
import ModelSelector from '@/components/ModelSelector.vue'
|
||||
import { useUIStore } from '@/stores/ui'
|
||||
|
||||
const props = defineProps<{
|
||||
visible: boolean
|
||||
automation: Automation | null
|
||||
}>()
|
||||
const emit = defineEmits<{ 'update:visible': [value: boolean]; saved: [value: Automation] }>()
|
||||
|
||||
const { t, locale } = useI18n()
|
||||
const uiStore = useUIStore()
|
||||
|
||||
type Section = 'basic' | 'schedule' | 'execution' | 'notify'
|
||||
|
||||
const VARIABLE_TAGS = ['now', 'last_run_at', 'last_success_at', 'run_id', 'automation_name']
|
||||
.map((name) => `{{${name}}}`)
|
||||
const KINDS: ScheduleKind[] = ['daily', 'weekdays', 'weekly', 'monthly', 'hourly', 'once', 'custom']
|
||||
const WEEK = [1, 2, 3, 4, 5, 6, 0]
|
||||
|
||||
const section = ref<Section>('basic')
|
||||
const navGroups = computed(() => [
|
||||
{
|
||||
key: 'task',
|
||||
label: t('automation.editor.navGroups.task'),
|
||||
items: [
|
||||
{ key: 'basic', label: t('automation.editor.sections.basic.title'), icon: 'edit-1' },
|
||||
{ key: 'schedule', label: t('automation.editor.sections.schedule.title'), icon: 'time' },
|
||||
],
|
||||
},
|
||||
{
|
||||
key: 'run',
|
||||
label: t('automation.editor.navGroups.run'),
|
||||
items: [
|
||||
{ key: 'execution', label: t('automation.editor.sections.execution.title'), icon: 'secured' },
|
||||
{ key: 'notify', label: t('automation.editor.sections.notify.title'), icon: 'notification' },
|
||||
],
|
||||
},
|
||||
])
|
||||
|
||||
const blank = (): Required<Omit<AutomationInput, 'trigger' | 'limits' | 'description'>> => ({
|
||||
name: '',
|
||||
model_id: '',
|
||||
instruction: '',
|
||||
session_mode: 'per_run',
|
||||
carry_last_result: false,
|
||||
misfire_policy: 'skip',
|
||||
overlap_policy: 'skip',
|
||||
access_level: 'confirm',
|
||||
approval_timeout_minutes: 1440,
|
||||
notify_on_success: false,
|
||||
})
|
||||
|
||||
const form = reactive(blank())
|
||||
const schedule = reactive(defaultScheduleForm())
|
||||
const timezone = ref(browserTimezone())
|
||||
const maxMinutes = ref(30)
|
||||
const saving = ref(false)
|
||||
|
||||
const zones = computed(() => timezoneOptions(timezone.value))
|
||||
|
||||
const approvalHours = computed({
|
||||
get: () => Math.max(1, Math.round(form.approval_timeout_minutes / 60)),
|
||||
set: (v: number | undefined) => {
|
||||
if (v === undefined || !Number.isFinite(v)) return
|
||||
form.approval_timeout_minutes = Math.min(168, Math.max(1, Math.round(v))) * 60
|
||||
},
|
||||
})
|
||||
|
||||
const clock = computed({
|
||||
get: () => `${String(schedule.hour).padStart(2, '0')}:${String(schedule.minute).padStart(2, '0')}`,
|
||||
set: (v: string) => {
|
||||
const [h, m] = String(v || '').split(':').map(Number)
|
||||
if (Number.isFinite(h)) schedule.hour = h
|
||||
if (Number.isFinite(m)) schedule.minute = m
|
||||
},
|
||||
})
|
||||
|
||||
const trigger = computed(() => triggerFromScheduleForm(schedule, timezone.value))
|
||||
|
||||
function close() {
|
||||
emit('update:visible', false)
|
||||
}
|
||||
|
||||
const modalShell = useModalShell({
|
||||
visible: () => props.visible,
|
||||
close,
|
||||
snapshot: () => ({ form, schedule, timezone: timezone.value, maxMinutes: maxMinutes.value }),
|
||||
})
|
||||
|
||||
watch(() => props.visible, (open) => {
|
||||
if (!open) return
|
||||
const a = props.automation
|
||||
section.value = 'basic'
|
||||
Object.assign(form, blank())
|
||||
Object.assign(schedule, defaultScheduleForm())
|
||||
timezone.value = browserTimezone()
|
||||
maxMinutes.value = 30
|
||||
if (a) {
|
||||
Object.assign(form, {
|
||||
name: a.name,
|
||||
model_id: a.model_id || '',
|
||||
instruction: a.instruction,
|
||||
session_mode: a.session_mode,
|
||||
carry_last_result: a.carry_last_result,
|
||||
misfire_policy: a.misfire_policy,
|
||||
overlap_policy: a.overlap_policy,
|
||||
access_level: a.access_level,
|
||||
approval_timeout_minutes: a.approval_timeout_minutes,
|
||||
notify_on_success: a.notify_on_success,
|
||||
})
|
||||
Object.assign(schedule, scheduleFormFromTrigger(a.trigger))
|
||||
timezone.value = a.trigger.timezone || 'UTC'
|
||||
maxMinutes.value = a.limits?.max_duration_minutes || 30
|
||||
}
|
||||
previewRuns.value = []
|
||||
previewError.value = ''
|
||||
modalShell.markClean()
|
||||
}, { immediate: true })
|
||||
|
||||
const previewRuns = ref<string[]>([])
|
||||
const previewError = ref('')
|
||||
const previewLoading = ref(false)
|
||||
let previewSeq = 0
|
||||
let previewTimer: ReturnType<typeof setTimeout> | undefined
|
||||
|
||||
watch([trigger, () => props.visible], () => {
|
||||
clearTimeout(previewTimer)
|
||||
const current = trigger.value
|
||||
previewRuns.value = []
|
||||
previewError.value = ''
|
||||
if (!props.visible || !current) return
|
||||
previewLoading.value = true
|
||||
const seq = ++previewSeq
|
||||
previewTimer = setTimeout(async () => {
|
||||
try {
|
||||
const res = await validateAutomationTrigger(current)
|
||||
if (seq === previewSeq) previewRuns.value = res.data?.next_runs ?? []
|
||||
} catch (e: any) {
|
||||
if (seq === previewSeq) previewError.value = e?.message || t('automation.schedule.invalid')
|
||||
} finally {
|
||||
if (seq === previewSeq) previewLoading.value = false
|
||||
}
|
||||
}, 400)
|
||||
}, { deep: true })
|
||||
|
||||
// The first section with a problem, with what to tell the user.
|
||||
function firstProblem(): [Section, string] | null {
|
||||
if (!form.name.trim()) return ['basic', t('automation.editor.errors.name')]
|
||||
if (!form.instruction.trim()) return ['basic', t('automation.editor.errors.instruction')]
|
||||
if (!trigger.value || previewError.value) return ['schedule', previewError.value || t('automation.editor.errors.schedule')]
|
||||
return null
|
||||
}
|
||||
|
||||
async function save() {
|
||||
const problem = firstProblem()
|
||||
if (problem) {
|
||||
section.value = problem[0]
|
||||
MessagePlugin.warning(problem[1])
|
||||
return
|
||||
}
|
||||
saving.value = true
|
||||
const input: AutomationInput = {
|
||||
...form,
|
||||
name: form.name.trim(),
|
||||
trigger: trigger.value!,
|
||||
limits: { max_duration_minutes: maxMinutes.value },
|
||||
}
|
||||
try {
|
||||
const res = props.automation
|
||||
? await updateAutomation(props.automation.id, input)
|
||||
: await createAutomation(input)
|
||||
MessagePlugin.success(props.automation ? t('common.saveSuccess') : t('common.createSuccess'))
|
||||
modalShell.markClean()
|
||||
emit('saved', res.data)
|
||||
close()
|
||||
} catch (e: any) {
|
||||
MessagePlugin.error(e?.message || t('common.saveFailed'))
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.automation-editor__next-run {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 4px 6px;
|
||||
min-width: 0;
|
||||
margin: 0 auto 0 0;
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: var(--app-text-xs);
|
||||
line-height: 1.6;
|
||||
|
||||
> .t-icon { flex-shrink: 0; }
|
||||
> span { white-space: nowrap; }
|
||||
time { font-variant-numeric: tabular-nums; }
|
||||
}
|
||||
|
||||
.content-wrapper {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
min-height: 0;
|
||||
padding: 28px 40px 48px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.section {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.section-header {
|
||||
margin-bottom: 20px;
|
||||
|
||||
h2 {
|
||||
margin: 0 0 6px;
|
||||
color: var(--td-text-color-primary);
|
||||
font-size: var(--app-text-3xl);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.section-description {
|
||||
margin: 0;
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: var(--app-text-base);
|
||||
line-height: 1.5;
|
||||
}
|
||||
}
|
||||
|
||||
.settings-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.setting-row {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 24px;
|
||||
min-width: 0;
|
||||
padding: 16px 0;
|
||||
border-bottom: 1px solid var(--td-component-stroke);
|
||||
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
&.setting-row-vertical {
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
|
||||
.setting-info {
|
||||
flex: none;
|
||||
max-width: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.setting-info {
|
||||
flex: 0 0 42%;
|
||||
max-width: 42%;
|
||||
min-width: 0;
|
||||
|
||||
label {
|
||||
display: block;
|
||||
margin-bottom: 4px;
|
||||
color: var(--td-text-color-primary);
|
||||
font-size: var(--app-text-lg);
|
||||
font-weight: 500;
|
||||
|
||||
.required {
|
||||
margin-left: 2px;
|
||||
color: var(--td-error-color);
|
||||
}
|
||||
}
|
||||
|
||||
.desc {
|
||||
margin: 0;
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: var(--app-text-md);
|
||||
line-height: 1.5;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-control {
|
||||
display: flex;
|
||||
flex: 1 1 58%;
|
||||
justify-content: flex-end;
|
||||
align-items: flex-start;
|
||||
min-width: 0;
|
||||
max-width: 58%;
|
||||
|
||||
> :deep(.t-select__wrap),
|
||||
> :deep(.t-input__wrap),
|
||||
> :deep(.t-date-picker) {
|
||||
width: 100%;
|
||||
max-width: 320px;
|
||||
}
|
||||
|
||||
&.setting-control-full {
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
justify-content: flex-start;
|
||||
}
|
||||
}
|
||||
|
||||
.automation-editor__stack {
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.automation-editor__hint {
|
||||
margin: 0;
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-size: var(--app-text-sm);
|
||||
line-height: 1.8;
|
||||
|
||||
code {
|
||||
margin: 0 2px;
|
||||
padding: 1px 6px;
|
||||
border-radius: var(--app-radius-xs);
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: var(--app-text-xs);
|
||||
}
|
||||
}
|
||||
|
||||
.automation-editor__frequency {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.automation-editor__frequency-option {
|
||||
position: relative;
|
||||
cursor: pointer;
|
||||
|
||||
input {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
opacity: 0;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
span {
|
||||
display: block;
|
||||
padding: 8px 16px;
|
||||
border: 1px solid var(--td-component-stroke);
|
||||
border-radius: var(--app-radius-pill);
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: var(--app-text-base);
|
||||
transition: background-color var(--app-motion-fast) ease, border-color var(--app-motion-fast) ease;
|
||||
}
|
||||
|
||||
&:hover span { background: var(--td-bg-color-container-hover); }
|
||||
input:checked + span {
|
||||
color: var(--td-brand-color);
|
||||
border-color: color-mix(in srgb, var(--td-brand-color) 40%, var(--td-component-stroke));
|
||||
background: color-mix(in srgb, var(--td-brand-color) 7%, var(--td-bg-color-container));
|
||||
font-weight: 500;
|
||||
}
|
||||
input:focus-visible + span {
|
||||
outline: 2px solid var(--td-brand-color-focus);
|
||||
outline-offset: 3px;
|
||||
}
|
||||
}
|
||||
|
||||
.automation-editor__number {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
color: var(--td-text-color-secondary);
|
||||
white-space: nowrap;
|
||||
|
||||
:deep(.t-input-number) {
|
||||
width: 160px;
|
||||
flex: none;
|
||||
}
|
||||
}
|
||||
|
||||
.automation-editor__days {
|
||||
flex-wrap: wrap;
|
||||
justify-content: flex-end;
|
||||
row-gap: 4px;
|
||||
}
|
||||
|
||||
.automation-editor__mono :deep(input) {
|
||||
font-family: var(--app-font-family-mono);
|
||||
}
|
||||
|
||||
.automation-editor__preview {
|
||||
width: 100%;
|
||||
padding: 12px 16px;
|
||||
border-radius: var(--app-radius-md);
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
color: var(--td-text-color-primary);
|
||||
font-size: var(--app-text-base);
|
||||
|
||||
&.is-error {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
background: var(--td-error-color-light);
|
||||
color: var(--td-error-color);
|
||||
}
|
||||
}
|
||||
|
||||
.automation-editor__runs {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
font-variant-numeric: tabular-nums;
|
||||
|
||||
li {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
:deep(.t-icon) {
|
||||
color: var(--td-brand-color);
|
||||
}
|
||||
}
|
||||
|
||||
.automation-editor__muted {
|
||||
color: var(--td-text-color-placeholder);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,607 @@
|
||||
<template>
|
||||
<main class="automation-page">
|
||||
<header class="automation-page__header" style="--wails-draggable: drag">
|
||||
<div class="automation-page__title-row" style="--wails-draggable: drag">
|
||||
<h2 style="--wails-draggable: drag">
|
||||
<ResourceIcon type="automation" :size="24" />
|
||||
{{ t('automation.title') }}
|
||||
</h2>
|
||||
<div class="automation-page__tools" style="--wails-draggable: no-drag">
|
||||
<t-input v-if="automations.length > 0" v-model="query" class="automation-page__search"
|
||||
:placeholder="t('menu.search')" :aria-label="t('menu.search')" clearable>
|
||||
<template #prefix-icon><t-icon name="search" size="16px" /></template>
|
||||
</t-input>
|
||||
<t-button variant="text" theme="default" size="small" class="automation-page__add" @click="openEditor(null)">
|
||||
<template #icon><t-icon name="add" size="16px" /></template>
|
||||
{{ t('automation.add') }}
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
<p class="automation-page__subtitle" style="--wails-draggable: drag">{{ t('automation.description') }}</p>
|
||||
</header>
|
||||
|
||||
<div v-if="loading" class="loading-container">
|
||||
<t-loading :text="t('common.loading')" />
|
||||
</div>
|
||||
|
||||
<section v-else class="automation-page__main">
|
||||
<div v-if="automations.length > 0 && filtered.length === 0" class="empty-state">
|
||||
<t-empty :description="t('common.noResult')" />
|
||||
<t-button variant="outline" @click="query = ''">{{ t('common.clear') }}</t-button>
|
||||
</div>
|
||||
<div v-else class="automation-grid">
|
||||
<article v-for="item in filtered" :key="item.id" class="automation-card" :class="{ 'is-paused': !item.enabled }">
|
||||
<button type="button" class="automation-card__open" :aria-label="item.name" @click="openDetail(item)" />
|
||||
<div class="automation-card__header">
|
||||
<div class="automation-card__badge" aria-hidden="true"><t-icon name="time" size="14px" /></div>
|
||||
<h3 class="automation-card__title" :title="item.name">{{ item.name }}</h3>
|
||||
<div class="automation-card__actions">
|
||||
<t-popconfirm :content="t('automation.runConfirm', { name: item.name })"
|
||||
:confirm-btn="{ content: t('automation.actions.runNow'), theme: 'primary' }"
|
||||
:cancel-btn="t('common.cancel')" theme="default" placement="bottom"
|
||||
:popup-props="{ disabled: busy.has(item.id) }" @confirm="runNow(item)">
|
||||
<button type="button" class="automation-card__icon-btn" :title="t('automation.actions.runNow')"
|
||||
:aria-label="`${item.name} · ${t('automation.actions.runNow')}`" :disabled="busy.has(item.id)">
|
||||
<ChatActionIcon name="play" />
|
||||
</button>
|
||||
</t-popconfirm>
|
||||
<button type="button" class="automation-card__icon-btn" :title="t('common.edit')"
|
||||
:aria-label="`${item.name} · ${t('common.edit')}`" @click="openEditor(item)">
|
||||
<ChatActionIcon name="edit" />
|
||||
</button>
|
||||
<t-popconfirm :content="t('automation.deleteBody', { name: item.name })"
|
||||
:confirm-btn="{ content: t('common.delete'), theme: 'danger' }"
|
||||
:cancel-btn="t('common.cancel')" theme="danger" placement="bottom"
|
||||
:popup-props="{ disabled: busy.has(item.id) }" @confirm="remove(item)">
|
||||
<button type="button" class="automation-card__icon-btn" :title="t('common.delete')"
|
||||
:aria-label="`${item.name} · ${t('common.delete')}`" :disabled="busy.has(item.id)">
|
||||
<ChatActionIcon name="delete" />
|
||||
</button>
|
||||
</t-popconfirm>
|
||||
</div>
|
||||
</div>
|
||||
<p class="automation-card__schedule">{{ describeTrigger(item.trigger, t, locale) }}</p>
|
||||
<p v-if="!item.enabled && item.paused_reason" class="automation-card__paused" :title="item.paused_reason">
|
||||
{{ item.paused_reason }}
|
||||
</p>
|
||||
<div class="automation-card__footer">
|
||||
<div class="automation-card__meta">
|
||||
<span v-if="item.enabled && item.next_run_at">
|
||||
{{ t('automation.nextRunAt', { time: formatInZone(item.next_run_at, item.trigger.timezone, locale) }) }}
|
||||
</span>
|
||||
<AutomationStatusTag :status="item.active_run_status || item.last_run_status" />
|
||||
</div>
|
||||
<span v-if="hasEndedOnceSchedule(item)" class="automation-card__status is-ended" :title="t('automation.scheduleEndedHint')">
|
||||
{{ t('automation.scheduleEnded') }}
|
||||
</span>
|
||||
<button v-else type="button" role="switch" class="automation-card__status" :class="{ 'is-enabled': item.enabled }"
|
||||
:aria-checked="item.enabled" :aria-label="`${item.name} · ${t('automation.fields.enabled')}`"
|
||||
:disabled="busy.has(item.id)" @click="toggle(item)">
|
||||
<t-loading v-if="busy.has(item.id)" size="12px" />
|
||||
<span v-else class="automation-card__dot" aria-hidden="true" />
|
||||
{{ item.enabled ? t('common.on') : t('automation.paused') }}
|
||||
</button>
|
||||
</div>
|
||||
</article>
|
||||
<button type="button" class="automation-card automation-card--add" @click="openEditor(null)">
|
||||
<span class="automation-card--add__icon" aria-hidden="true"><t-icon name="add" /></span>
|
||||
<span class="automation-card--add__label">{{ t('automation.add') }}</span>
|
||||
<span class="automation-card--add__hint">{{ t('automation.addHint') }}</span>
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<AutomationEditor v-model:visible="editorVisible" :automation="editing" @saved="onSaved" />
|
||||
<AutomationDetail v-model:visible="detailVisible" :automation="detail"
|
||||
:focus-run-id="focusRunId" @changed="onSaved" @edit="openEditor" />
|
||||
</main>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import {
|
||||
deleteAutomation,
|
||||
getAutomation,
|
||||
listAutomations,
|
||||
pauseAutomation,
|
||||
resumeAutomation,
|
||||
runAutomationNow,
|
||||
type Automation,
|
||||
} from '@/api/automation'
|
||||
import { describeTrigger, formatInZone, hasEndedOnceSchedule } from '@/utils/automationSchedule'
|
||||
import { useAssistantDataChange } from '@/utils/assistantDataChange'
|
||||
import AutomationEditor from './AutomationEditor.vue'
|
||||
import AutomationDetail from './AutomationDetail.vue'
|
||||
import AutomationStatusTag from './AutomationStatusTag.vue'
|
||||
import ChatActionIcon from '@/components/ChatActionIcon.vue'
|
||||
import ResourceIcon from '@/components/icons/ResourceIcon.vue'
|
||||
|
||||
const { t, locale } = useI18n()
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
|
||||
const automations = ref<Automation[]>([])
|
||||
const loading = ref(true)
|
||||
const query = ref('')
|
||||
const busy = ref(new Set<string>())
|
||||
const editorVisible = ref(false)
|
||||
const editing = ref<Automation | null>(null)
|
||||
const detailVisible = ref(false)
|
||||
const detail = ref<Automation | null>(null)
|
||||
const focusRunId = ref('')
|
||||
let loadVersion = 0
|
||||
let poll: ReturnType<typeof setTimeout> | undefined
|
||||
let disposed = false
|
||||
|
||||
const filtered = computed(() => {
|
||||
const q = query.value.trim().toLowerCase()
|
||||
if (!q) return automations.value
|
||||
return automations.value.filter((a) =>
|
||||
a.name.toLowerCase().includes(q) || a.instruction.toLowerCase().includes(q))
|
||||
})
|
||||
|
||||
function schedulePoll() {
|
||||
clearTimeout(poll)
|
||||
if (!disposed) poll = setTimeout(() => { void load(true) }, 5000)
|
||||
}
|
||||
|
||||
async function load(silent = false) {
|
||||
if (disposed) return
|
||||
clearTimeout(poll)
|
||||
const version = ++loadVersion
|
||||
try {
|
||||
const res = await listAutomations()
|
||||
if (version !== loadVersion) return
|
||||
automations.value = res.data ?? []
|
||||
if (detail.value) {
|
||||
const fresh = automations.value.find(item => item.id === detail.value?.id)
|
||||
if (fresh) detail.value = fresh
|
||||
else {
|
||||
detailVisible.value = false
|
||||
detail.value = null
|
||||
}
|
||||
}
|
||||
} catch (e: any) {
|
||||
if (version === loadVersion && !silent) MessagePlugin.error(e?.message || t('common.operationFailed'))
|
||||
} finally {
|
||||
if (version === loadVersion) {
|
||||
loading.value = false
|
||||
schedulePoll()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
useAssistantDataChange(() => { void load() }, { areas: ['automation'] })
|
||||
onBeforeUnmount(() => {
|
||||
disposed = true
|
||||
++loadVersion
|
||||
clearTimeout(poll)
|
||||
})
|
||||
|
||||
function replace(item: Automation) {
|
||||
const index = automations.value.findIndex((a) => a.id === item.id)
|
||||
if (index >= 0) automations.value.splice(index, 1, item)
|
||||
else automations.value.unshift(item)
|
||||
if (detail.value?.id === item.id) detail.value = item
|
||||
}
|
||||
|
||||
function onSaved(item: Automation) {
|
||||
replace(item)
|
||||
void load(true)
|
||||
}
|
||||
|
||||
function openEditor(item: Automation | null) {
|
||||
editing.value = item
|
||||
detailVisible.value = false
|
||||
editorVisible.value = true
|
||||
}
|
||||
|
||||
function openDetail(item: Automation, runId = '') {
|
||||
detail.value = item
|
||||
focusRunId.value = runId
|
||||
detailVisible.value = true
|
||||
}
|
||||
|
||||
// Notifications link to /platform/automations/:id?run=…; the detail opens
|
||||
// over the list and the URL drops back to the list.
|
||||
async function openFromRoute() {
|
||||
const id = typeof route.params.automationId === 'string' ? route.params.automationId : ''
|
||||
if (!id) return
|
||||
const runId = typeof route.query.run === 'string' ? route.query.run : ''
|
||||
let item = automations.value.find((a) => a.id === id)
|
||||
if (!item) {
|
||||
try {
|
||||
item = (await getAutomation(id)).data
|
||||
} catch {
|
||||
MessagePlugin.warning(t('automation.messages.notFound'))
|
||||
}
|
||||
}
|
||||
if (item) openDetail(item, runId)
|
||||
const rest = { ...route.query }
|
||||
delete rest.run
|
||||
void router.replace({ name: 'automationList', query: rest })
|
||||
}
|
||||
|
||||
watch(() => route.params.automationId, () => {
|
||||
if (!loading.value) void openFromRoute()
|
||||
})
|
||||
|
||||
watch(detailVisible, (open) => {
|
||||
if (!open) focusRunId.value = ''
|
||||
})
|
||||
|
||||
async function toggle(item: Automation) {
|
||||
if (busy.value.has(item.id)) return
|
||||
if (hasEndedOnceSchedule(item)) {
|
||||
MessagePlugin.warning(t('automation.scheduleEndedHint'))
|
||||
return
|
||||
}
|
||||
busy.value.add(item.id)
|
||||
try {
|
||||
const res = item.enabled ? await pauseAutomation(item.id) : await resumeAutomation(item.id)
|
||||
onSaved(res.data)
|
||||
} catch (e: any) {
|
||||
MessagePlugin.error(e?.message || t('common.operationFailed'))
|
||||
} finally {
|
||||
busy.value.delete(item.id)
|
||||
}
|
||||
}
|
||||
|
||||
async function runNow(item: Automation) {
|
||||
if (busy.value.has(item.id)) return
|
||||
busy.value.add(item.id)
|
||||
try {
|
||||
const res = await runAutomationNow(item.id)
|
||||
MessagePlugin.success(t('automation.messages.queued'))
|
||||
openDetail(item, res.data?.id ?? '')
|
||||
void load(true)
|
||||
} catch (e: any) {
|
||||
MessagePlugin.error(e?.message || t('common.operationFailed'))
|
||||
} finally {
|
||||
busy.value.delete(item.id)
|
||||
}
|
||||
}
|
||||
|
||||
async function remove(item: Automation) {
|
||||
if (busy.value.has(item.id)) return
|
||||
busy.value.add(item.id)
|
||||
try {
|
||||
await deleteAutomation(item.id)
|
||||
++loadVersion
|
||||
schedulePoll()
|
||||
automations.value = automations.value.filter((a) => a.id !== item.id)
|
||||
if (detail.value?.id === item.id) detailVisible.value = false
|
||||
MessagePlugin.success(t('common.deleteSuccess'))
|
||||
} catch (e: any) {
|
||||
MessagePlugin.error(e?.message || t('common.deleteFailed'))
|
||||
} finally {
|
||||
busy.value.delete(item.id)
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await load()
|
||||
await openFromRoute()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
@import (reference) '@/components/css/provider-card.less';
|
||||
@import (reference) '@/components/css/resource-card.less';
|
||||
|
||||
.automation-page {
|
||||
.resource-list-content();
|
||||
color: var(--td-text-color-primary);
|
||||
}
|
||||
|
||||
.automation-page__header {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
margin-bottom: 16px;
|
||||
flex-shrink: 0;
|
||||
|
||||
h2 {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin: 0;
|
||||
font-family: var(--app-font-family);
|
||||
font-size: var(--app-text-4xl);
|
||||
font-weight: 600;
|
||||
line-height: 32px;
|
||||
}
|
||||
}
|
||||
|
||||
.automation-page__title-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: var(--app-space-4);
|
||||
}
|
||||
|
||||
.automation-page__tools {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.automation-page__search {
|
||||
width: 260px;
|
||||
max-width: 100%;
|
||||
|
||||
:deep(.t-input) {
|
||||
border-radius: var(--app-radius-sm);
|
||||
}
|
||||
}
|
||||
|
||||
.automation-page__add.t-button {
|
||||
flex-shrink: 0;
|
||||
min-height: 32px;
|
||||
padding: 0 12px;
|
||||
border: 1px solid var(--td-component-stroke);
|
||||
border-radius: var(--app-radius-sm);
|
||||
background: var(--td-bg-color-container);
|
||||
color: var(--td-text-color-primary);
|
||||
|
||||
:deep(.t-icon) {
|
||||
color: var(--td-text-color-secondary);
|
||||
}
|
||||
|
||||
&:hover {
|
||||
background: var(--td-bg-color-container-hover);
|
||||
border-color: var(--td-component-stroke);
|
||||
}
|
||||
}
|
||||
|
||||
.automation-page__subtitle {
|
||||
margin: 0;
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: var(--app-text-base);
|
||||
line-height: 20px;
|
||||
}
|
||||
|
||||
.automation-page__main {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
padding-bottom: var(--app-space-8);
|
||||
}
|
||||
|
||||
.loading-container {
|
||||
padding: 40px 0;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
padding: 80px 0;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.automation-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr));
|
||||
gap: 10px;
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
.automation-card {
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
min-width: 0;
|
||||
padding: 12px;
|
||||
border: 1px solid var(--td-component-stroke);
|
||||
border-radius: var(--app-radius-md);
|
||||
background: var(--td-bg-color-container);
|
||||
transition: background-color var(--app-motion-base) ease, box-shadow var(--app-motion-base) ease;
|
||||
|
||||
&:hover:not(.automation-card--add) {
|
||||
box-shadow: 0 3px 12px color-mix(in srgb, var(--td-text-color-primary) 6%, transparent);
|
||||
}
|
||||
|
||||
&.is-paused .automation-card__schedule {
|
||||
color: var(--td-text-color-placeholder);
|
||||
}
|
||||
|
||||
&--add {
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 4px;
|
||||
min-height: 112px;
|
||||
border-style: dashed;
|
||||
background: transparent;
|
||||
color: var(--td-text-color-placeholder);
|
||||
cursor: pointer;
|
||||
font: inherit;
|
||||
text-align: center;
|
||||
|
||||
&:hover,
|
||||
&:focus-visible {
|
||||
color: var(--td-text-color-primary);
|
||||
border-color: var(--td-component-border);
|
||||
background: color-mix(in srgb, var(--td-bg-color-secondarycontainer) 15%, var(--td-bg-color-container));
|
||||
box-shadow: 0 3px 12px color-mix(in srgb, var(--td-text-color-primary) 5%, transparent);
|
||||
}
|
||||
|
||||
&__icon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border-radius: var(--app-radius-md);
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
font-size: var(--app-text-2xl);
|
||||
}
|
||||
|
||||
&__label {
|
||||
font-size: var(--app-text-md);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
&__hint {
|
||||
font-size: var(--app-text-xs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The whole card opens the detail; the buttons on it sit above this layer.
|
||||
.automation-card__open {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
border: 0;
|
||||
border-radius: inherit;
|
||||
background: transparent;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.automation-card__header,
|
||||
.automation-card__footer,
|
||||
.automation-card__schedule,
|
||||
.automation-card__paused {
|
||||
position: relative;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.automation-card__actions,
|
||||
.automation-card__status {
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
.automation-card__header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
min-height: 28px;
|
||||
}
|
||||
|
||||
.automation-card__badge {
|
||||
.provider-card-badge(28px, 8px);
|
||||
}
|
||||
|
||||
.automation-card__title {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
font-size: var(--app-text-base);
|
||||
font-weight: 600;
|
||||
line-height: 20px;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.automation-card__actions {
|
||||
display: flex;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.automation-card__icon-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
border-radius: var(--app-radius-sm);
|
||||
background: none;
|
||||
color: color-mix(in srgb, var(--td-text-color-primary) 55%, transparent);
|
||||
cursor: pointer;
|
||||
|
||||
&:hover:not(:disabled) {
|
||||
color: var(--td-text-color-secondary);
|
||||
background: color-mix(in srgb, var(--td-text-color-primary) 5%, transparent);
|
||||
}
|
||||
|
||||
&:active:not(:disabled) {
|
||||
background: color-mix(in srgb, var(--td-text-color-primary) 9%, transparent);
|
||||
}
|
||||
|
||||
&:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.4;
|
||||
}
|
||||
}
|
||||
|
||||
.automation-card__schedule,
|
||||
.automation-card__paused {
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
font-size: var(--app-text-sm);
|
||||
line-height: 1.5;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
color: var(--td-text-color-secondary);
|
||||
}
|
||||
|
||||
.automation-card__paused {
|
||||
color: var(--td-warning-color);
|
||||
}
|
||||
|
||||
.automation-card__footer {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
margin-top: auto;
|
||||
}
|
||||
|
||||
.automation-card__meta {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 6px 8px;
|
||||
min-width: 0;
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-size: var(--app-text-xs);
|
||||
}
|
||||
|
||||
.automation-card__status {
|
||||
flex-shrink: 0;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
padding: 2px 4px;
|
||||
border: 0;
|
||||
border-radius: var(--app-radius-sm);
|
||||
background: none;
|
||||
color: var(--td-text-color-placeholder);
|
||||
cursor: pointer;
|
||||
font: inherit;
|
||||
font-size: var(--app-text-sm);
|
||||
|
||||
&.is-enabled {
|
||||
color: var(--td-success-color);
|
||||
}
|
||||
|
||||
&.is-ended { cursor: default; }
|
||||
|
||||
&:hover:not(:disabled):not(.is-ended) {
|
||||
background: var(--td-bg-color-container-hover);
|
||||
}
|
||||
|
||||
&:disabled {
|
||||
cursor: wait;
|
||||
}
|
||||
}
|
||||
|
||||
.automation-card__dot {
|
||||
width: 5px;
|
||||
height: 5px;
|
||||
border-radius: 50%;
|
||||
background: currentColor;
|
||||
}
|
||||
|
||||
.automation-card button:focus-visible,
|
||||
.automation-card--add:focus-visible {
|
||||
outline: 2px solid var(--td-text-color-secondary);
|
||||
outline-offset: -2px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,50 @@
|
||||
<template>
|
||||
<span v-if="status && (status === 'succeeded' || iconOnly)" class="automation-status-icon" :class="`is-${status}`" role="img"
|
||||
:aria-label="t(`automation.status.${status}`)" :title="t(`automation.status.${status}`)">
|
||||
<t-icon :name="ICONS[status] || 'time'" size="16px" />
|
||||
</span>
|
||||
<t-tag v-else-if="status" size="small" variant="light" :theme="theme">{{ t(`automation.status.${status}`) }}</t-tag>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import type { AutomationRunStatus } from '@/api/automation'
|
||||
|
||||
const props = defineProps<{ status: AutomationRunStatus | 'paused' | ''; iconOnly?: boolean }>()
|
||||
const { t } = useI18n()
|
||||
|
||||
const ICONS: Record<string, string> = {
|
||||
succeeded: 'check-circle', failed: 'error-circle', running: 'loading', queued: 'time',
|
||||
awaiting_approval: 'secured', needs_attention: 'error-circle', cancelled: 'close-circle',
|
||||
skipped: 'jump', paused: 'pause-circle',
|
||||
}
|
||||
|
||||
const THEMES: Record<string, 'default' | 'primary' | 'success' | 'warning' | 'danger'> = {
|
||||
queued: 'default',
|
||||
running: 'primary',
|
||||
awaiting_approval: 'warning',
|
||||
succeeded: 'success',
|
||||
failed: 'danger',
|
||||
cancelled: 'default',
|
||||
skipped: 'default',
|
||||
needs_attention: 'warning',
|
||||
paused: 'default',
|
||||
}
|
||||
|
||||
const theme = computed(() => THEMES[props.status] ?? 'default')
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.automation-status-icon {
|
||||
display: inline-flex;
|
||||
flex-shrink: 0;
|
||||
align-items: center;
|
||||
color: var(--td-text-color-secondary);
|
||||
|
||||
&.is-succeeded { color: var(--td-success-color); }
|
||||
&.is-running { color: var(--td-brand-color); }
|
||||
&.is-failed { color: var(--td-error-color); }
|
||||
&.is-awaiting_approval, &.is-needs_attention { color: var(--td-warning-color); }
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,427 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { createRequire } from 'node:module'
|
||||
import test, { type TestContext } from 'node:test'
|
||||
import { compileScript, compileTemplate, parse } from '@vue/compiler-sfc'
|
||||
import * as vue from 'vue'
|
||||
import { change, fixture, flush } from '../../test-utils/vueFixture.ts'
|
||||
import * as schedule from '../../utils/automationSchedule.ts'
|
||||
|
||||
const require = createRequire(import.meta.url)
|
||||
const useInputNumber = require('tdesign-vue-next/cjs/input-number/hooks/useInputNumber.js').default
|
||||
const numberProps = require('tdesign-vue-next/cjs/input-number/props.js').default
|
||||
|
||||
const automation = {
|
||||
id: 'automation-1', name: 'Reminder', instruction: 'Take a break',
|
||||
trigger: { type: 'cron', expr: '0 9 * * *', timezone: 'Asia/Shanghai' },
|
||||
approval_timeout_minutes: 1440, limits: { max_duration_minutes: 30 },
|
||||
enabled: true, session_mode: 'per_run', access_level: 'confirm',
|
||||
carry_last_result: false, misfire_policy: 'skip', overlap_policy: 'skip', notify_on_success: false,
|
||||
}
|
||||
|
||||
function setup(t: TestContext, file: string, api: Record<string, unknown>, props: Record<string, unknown>) {
|
||||
const f = fixture(t)
|
||||
const url = new URL(file, import.meta.url)
|
||||
const page = f.component(url, {
|
||||
'vue-i18n': { useI18n: () => ({ t: (key: string) => key, locale: vue.ref('en-US') }) },
|
||||
'vue-router': { useRoute: () => ({ params: {}, query: {} }), useRouter: () => ({ replace() {}, push() {} }) },
|
||||
'tdesign-vue-next': { MessagePlugin: { success() {}, error() {}, warning() {} } },
|
||||
'@/api/automation': api,
|
||||
'@/api/assistant': { ASSISTANT_ACCESS_LEVELS: ['read_only', 'confirm', 'auto_write'] },
|
||||
'@/stores/ui': { useUIStore: () => ({ openSettings() {} }) },
|
||||
'@/utils/automationSchedule': schedule,
|
||||
'@/composables/useModalShell': { useModalShell: () => ({ markClean() {}, requestClose() {} }) },
|
||||
}, props)
|
||||
const { descriptor } = parse(readFileSync(url, 'utf8'))
|
||||
const script = compileScript(descriptor, { id: 'automation-interactions' })
|
||||
const compiled = compileTemplate({
|
||||
source: descriptor.template!.content, filename: url.pathname, id: 'automation-interactions',
|
||||
compilerOptions: { bindingMetadata: script.bindings },
|
||||
})
|
||||
assert.deepEqual(compiled.errors, [])
|
||||
const { render } = f.evaluate(compiled.code, {
|
||||
vue: { ...vue, resolveComponent: (name: string) => name === 't-popup' ? { name } : name, resolveDynamicComponent: (name: string) => name,
|
||||
withCtx: (fn: unknown) => fn, withDirectives: (node: unknown) => node },
|
||||
})
|
||||
return { ...page, mount: f.mount, emit: f.emit, render: () => render(page.vm, [], props, page.vm, {}, {}) }
|
||||
}
|
||||
|
||||
function nodes(node: any): any[] {
|
||||
if (!node || typeof node !== 'object') return []
|
||||
if (Array.isArray(node)) return node.flatMap(nodes)
|
||||
const children = node.children
|
||||
return [node, ...(Array.isArray(children) ? nodes(children)
|
||||
: children && typeof children === 'object'
|
||||
? Object.values(children).flatMap(slot => typeof slot === 'function' ? nodes(slot()) : []) : [])]
|
||||
}
|
||||
|
||||
test('assistant mutations refresh the automation list and open detail without replacing an editor draft', async t => {
|
||||
let items = [{ ...automation }]
|
||||
let calls = 0
|
||||
const { vm, emit, close } = setup(t, './AutomationList.vue', {
|
||||
listAutomations: async () => { calls++; return { data: items } },
|
||||
}, {})
|
||||
await flush()
|
||||
vm.openDetail(vm.automations[0])
|
||||
vm.query = 'Reminder'
|
||||
vm.editing = { ...automation, name: 'Unsaved draft' }
|
||||
vm.editorVisible = true
|
||||
items = [{ ...automation, name: 'Updated reminder', enabled: false }, { ...automation, id: 'new' }]
|
||||
emit(change('agent.update'))
|
||||
t.mock.timers.tick(300)
|
||||
assert.equal(calls, 1)
|
||||
emit(change('automation.create'))
|
||||
emit(change('automation.update'))
|
||||
emit(change('automation.pause'))
|
||||
t.mock.timers.tick(300)
|
||||
await flush()
|
||||
assert.equal(calls, 2, 'one request per burst')
|
||||
assert.equal(vm.automations.length, 2)
|
||||
assert.equal(vm.detail.name, 'Updated reminder')
|
||||
assert.equal(vm.detail.enabled, false)
|
||||
assert.equal(vm.detailVisible, true)
|
||||
assert.equal(vm.query, 'Reminder')
|
||||
assert.equal(vm.editing.name, 'Unsaved draft')
|
||||
assert.equal(vm.editorVisible, true)
|
||||
items = []
|
||||
emit(change('automation.delete'))
|
||||
t.mock.timers.tick(300)
|
||||
await flush()
|
||||
assert.equal(vm.detailVisible, false)
|
||||
assert.equal(vm.detail, null)
|
||||
close()
|
||||
emit(change('automation.create'))
|
||||
t.mock.timers.tick(300)
|
||||
assert.equal(calls, 3, 'unmounted pages unsubscribe')
|
||||
})
|
||||
|
||||
test('a stale automation list response cannot overwrite a newer assistant refresh', async t => {
|
||||
const requests: Array<(result: unknown) => void> = []
|
||||
const { vm, emit } = setup(t, './AutomationList.vue', {
|
||||
listAutomations: () => new Promise(resolve => requests.push(resolve)),
|
||||
}, {})
|
||||
emit(change('automation.update'))
|
||||
t.mock.timers.tick(300)
|
||||
assert.equal(requests.length, 2)
|
||||
requests[1]({ data: [{ ...automation, name: 'Fresh' }] })
|
||||
await flush()
|
||||
requests[0]({ data: [{ ...automation, name: 'Stale' }] })
|
||||
await flush()
|
||||
assert.equal(vm.automations[0].name, 'Fresh')
|
||||
})
|
||||
|
||||
test('assistant run-now refreshes idle history after any in-flight load and preserves earlier pages', async t => {
|
||||
let first!: (value: unknown) => void
|
||||
let calls = 0
|
||||
const oldRun = { id: 'old', status: 'succeeded', scheduled_at: '2026-10-20T10:00:00Z' }
|
||||
const newRun = { id: 'new', status: 'queued', scheduled_at: '2026-10-20T11:00:00Z' }
|
||||
const { vm, emit } = setup(t, './AutomationDetail.vue', {
|
||||
listAutomationRuns: () => ++calls === 1 ? new Promise(resolve => { first = resolve })
|
||||
: Promise.resolve({ data: [newRun, oldRun], total: 3 }),
|
||||
listAutomationGrants: async () => ({ data: [] }),
|
||||
listAutomationGrantCandidates: async () => ({ data: [] }),
|
||||
}, { visible: true, automation })
|
||||
emit(change('automation.run_now'))
|
||||
t.mock.timers.tick(300)
|
||||
assert.equal(calls, 1, 'wait for the initial page before merging newer runs')
|
||||
first({ data: [oldRun, { ...oldRun, id: 'earlier' }], total: 2 })
|
||||
await flush()
|
||||
assert.equal(calls, 2)
|
||||
assert.deepEqual(Array.from(vm.runs, (run: any) => run.id), ['new', 'old', 'earlier'])
|
||||
assert.equal(vm.runsTotal, 3)
|
||||
vm.instructionExpanded = true
|
||||
vm.$.props.automation = { ...automation, name: 'Updated name' }
|
||||
await vue.nextTick()
|
||||
assert.equal(calls, 2, 'refreshing the same automation does not reset loaded history')
|
||||
assert.equal(vm.instructionExpanded, true)
|
||||
vm.$.props.visible = false
|
||||
await vue.nextTick()
|
||||
emit(change('automation.run_now'))
|
||||
t.mock.timers.tick(300)
|
||||
assert.equal(calls, 2, 'closed detail does not fetch history')
|
||||
})
|
||||
|
||||
test('task content fades only while more text remains below the scroll position', async t => {
|
||||
const { vm, render } = setup(t, './AutomationDetail.vue', {},
|
||||
{ visible: false, automation })
|
||||
const scroller = vue.markRaw({ scrollHeight: 320, clientHeight: 160, scrollTop: 0 })
|
||||
vm.instructionScroller = scroller
|
||||
await vue.nextTick()
|
||||
const scrollNode = () => nodes(render()).find(node =>
|
||||
String(node.props?.class).includes('automation-detail__instruction-scroll'))
|
||||
const toggle = () => nodes(render()).find(node =>
|
||||
node.props?.class === 'automation-detail__instruction-toggle')
|
||||
assert.equal(vm.instructionHasMore, true)
|
||||
assert.match(scrollNode().props.class, /instruction-scroll--more/)
|
||||
assert.doesNotMatch(scrollNode().props.class, /instruction-scroll--expanded/)
|
||||
assert.equal(toggle().props['aria-expanded'], false)
|
||||
toggle().props.onClick()
|
||||
await vue.nextTick()
|
||||
assert.equal(scrollNode().props.style.maxHeight, 'none')
|
||||
assert.match(scrollNode().props.class, /instruction-scroll--expanded/)
|
||||
assert.equal(vm.instructionHasMore, false, 'expanded text is not faded')
|
||||
assert.equal(toggle().props['aria-expanded'], true)
|
||||
toggle().props.onClick()
|
||||
await vue.nextTick()
|
||||
assert.equal(scrollNode().props.style.maxHeight, '160px')
|
||||
assert.doesNotMatch(scrollNode().props.class, /instruction-scroll--expanded/)
|
||||
assert.equal(vm.instructionHasMore, true)
|
||||
|
||||
scroller.scrollTop = 160
|
||||
scrollNode().props.onScroll()
|
||||
assert.equal(vm.instructionHasMore, false, 'the last line is fully visible at the bottom')
|
||||
assert.doesNotMatch(scrollNode().props.class, /instruction-scroll--more/)
|
||||
|
||||
scroller.scrollTop = 50
|
||||
scrollNode().props.onScroll()
|
||||
assert.equal(vm.instructionHasMore, true)
|
||||
scroller.scrollHeight = 100
|
||||
scroller.scrollTop = 0
|
||||
vm.updateInstructionOverflow()
|
||||
assert.equal(vm.instructionHasMore, false, 'short content has no fade')
|
||||
assert.equal(toggle(), undefined, 'short content has no expand control')
|
||||
})
|
||||
|
||||
test('cards refresh live run states and return to the last result after completion', async t => {
|
||||
let state = { ...automation, active_run_status: '', last_run_status: 'succeeded' }
|
||||
let calls = 0
|
||||
const { vm, render, close } = setup(t, './AutomationList.vue', {
|
||||
listAutomations: async () => { calls++; return { data: [{ ...state }] } },
|
||||
}, {})
|
||||
await flush()
|
||||
const status = () => nodes(render()).find(node => node.props && 'status' in node.props)?.props.status
|
||||
assert.equal(status(), 'succeeded')
|
||||
vm.openDetail(vm.automations[0])
|
||||
vm.editing = { ...automation, name: 'Unsaved draft' }
|
||||
vm.editorVisible = true
|
||||
for (const active of ['queued', 'running', 'awaiting_approval', '']) {
|
||||
state = { ...state, active_run_status: active }
|
||||
t.mock.timers.tick(5000)
|
||||
await flush()
|
||||
assert.equal(status(), active || 'succeeded')
|
||||
assert.equal(vm.detail.active_run_status, active)
|
||||
assert.equal(vm.editing.name, 'Unsaved draft')
|
||||
assert.equal(vm.loading, false, 'background refresh keeps cards visible')
|
||||
}
|
||||
assert.equal(calls, 5)
|
||||
close()
|
||||
t.mock.timers.tick(15000)
|
||||
await flush()
|
||||
assert.equal(calls, 5, 'leaving the list stops polling')
|
||||
})
|
||||
|
||||
test('list polling waits for a slow response and does not restart after unmount', async t => {
|
||||
let resolve!: (value: unknown) => void
|
||||
let calls = 0
|
||||
const { close } = setup(t, './AutomationList.vue', {
|
||||
listAutomations: () => {
|
||||
calls++
|
||||
return new Promise(done => { resolve = done })
|
||||
},
|
||||
}, {})
|
||||
t.mock.timers.tick(15000)
|
||||
assert.equal(calls, 1, 'no overlapping polling requests')
|
||||
resolve({ data: [automation] })
|
||||
await flush()
|
||||
t.mock.timers.tick(5000)
|
||||
assert.equal(calls, 2)
|
||||
close()
|
||||
resolve({ data: [automation] })
|
||||
await flush()
|
||||
t.mock.timers.tick(15000)
|
||||
assert.equal(calls, 2)
|
||||
})
|
||||
|
||||
test('a stale poll cannot restore a deleted card and polling recovers from errors', async t => {
|
||||
let resolve!: (value: unknown) => void
|
||||
let calls = 0
|
||||
const { vm } = setup(t, './AutomationList.vue', {
|
||||
listAutomations: async () => {
|
||||
calls++
|
||||
if (calls === 1) return { data: [automation] }
|
||||
if (calls === 2) return new Promise(done => { resolve = done })
|
||||
if (calls === 3) throw new Error('Temporarily unavailable')
|
||||
return { data: [] }
|
||||
},
|
||||
deleteAutomation: async () => {},
|
||||
}, {})
|
||||
await flush()
|
||||
t.mock.timers.tick(5000)
|
||||
await vm.remove(vm.automations[0])
|
||||
resolve({ data: [automation] })
|
||||
await flush()
|
||||
assert.equal(vm.automations.length, 0)
|
||||
t.mock.timers.tick(5000)
|
||||
await flush()
|
||||
assert.equal(calls, 3)
|
||||
t.mock.timers.tick(5000)
|
||||
await flush()
|
||||
assert.equal(calls, 4)
|
||||
assert.equal(vm.automations.length, 0)
|
||||
})
|
||||
|
||||
test('approval hours update in both directions and save as minutes, without resetting on an empty edit', async t => {
|
||||
let saved: any
|
||||
const props = { visible: false, automation }
|
||||
const { vm, render, mount } = setup(t, './AutomationEditor.vue', {
|
||||
updateAutomation: async (_id: string, input: unknown) => { saved = input; return { data: automation } },
|
||||
validateAutomationTrigger: async () => ({ data: { next_runs: [] } }),
|
||||
}, props)
|
||||
vm.$.props.visible = true
|
||||
await vue.nextTick()
|
||||
assert.equal(vm.approvalHours, 24)
|
||||
const input = nodes(render()).find(node => node.type === 't-input-number' && node.props.max === 168)
|
||||
assert.ok(input)
|
||||
assert.equal(input.props.theme, 'row', 'both controls stay visible with full-sized click targets')
|
||||
assert.equal(input.props.suffix, undefined, 'the unit cannot crowd the numeric input or controls')
|
||||
// Use TDesign's real step handlers against the editor's compiled v-model binding.
|
||||
let control: any
|
||||
const NumberControl = vue.defineComponent({
|
||||
props: numberProps,
|
||||
setup(props) { control = useInputNumber(props); return () => null },
|
||||
})
|
||||
mount({ setup: () => () => vue.h(NumberControl,
|
||||
nodes(render()).find(node => node.type === 't-input-number' && node.props.max === 168).props) })
|
||||
control.handleAdd({})
|
||||
await vue.nextTick()
|
||||
assert.equal(vm.form.approval_timeout_minutes, 1500)
|
||||
assert.equal(control.userInput.value, '25')
|
||||
control.handleReduce({})
|
||||
await vue.nextTick()
|
||||
assert.equal(vm.form.approval_timeout_minutes, 1440)
|
||||
assert.equal(control.userInput.value, '24')
|
||||
const update = input.props['onUpdate:modelValue']
|
||||
update(undefined)
|
||||
assert.equal(vm.approvalHours, 24)
|
||||
update(0)
|
||||
assert.equal(vm.approvalHours, 1)
|
||||
update(169)
|
||||
assert.equal(vm.approvalHours, 168)
|
||||
update(4)
|
||||
await vm.save()
|
||||
assert.equal(saved.approval_timeout_minutes, 240)
|
||||
})
|
||||
|
||||
test('the editor preserves, changes, and clears an automation model override', async t => {
|
||||
const saved: any[] = []
|
||||
const { vm } = setup(t, './AutomationEditor.vue', {
|
||||
updateAutomation: async (_id: string, input: unknown) => { saved.push(input); return { data: automation } },
|
||||
validateAutomationTrigger: async () => ({ data: { next_runs: [] } }),
|
||||
}, { visible: false, automation: { ...automation, model_id: 'model-one' } })
|
||||
vm.$.props.visible = true
|
||||
await vue.nextTick()
|
||||
assert.equal(vm.form.model_id, 'model-one')
|
||||
vm.form.model_id = 'model-two'
|
||||
await vm.save()
|
||||
assert.equal(saved[0].model_id, 'model-two')
|
||||
vm.form.model_id = ''
|
||||
await vm.save()
|
||||
assert.equal(saved[1].model_id, '', 'clearing restores the assistant default instead of omitting the patch')
|
||||
})
|
||||
|
||||
test('list run and delete actions call APIs only after their inline confirmation', async t => {
|
||||
let runCalls = 0
|
||||
let deleteCalls = 0
|
||||
const { vm, render } = setup(t, './AutomationList.vue', {
|
||||
listAutomations: async () => ({ data: [{ ...automation, active_run_status: runCalls ? 'queued' : '' }] }),
|
||||
runAutomationNow: async () => { runCalls++; return { data: { id: 'run-1' } } },
|
||||
deleteAutomation: async () => { deleteCalls++ },
|
||||
}, {})
|
||||
await flush()
|
||||
const popups = nodes(render()).filter(node => node.type === 't-popconfirm')
|
||||
assert.equal(popups.length, 2)
|
||||
for (const popup of popups) {
|
||||
const trigger = nodes(popup).find(node => node.type === 'button')
|
||||
assert.ok(trigger)
|
||||
trigger.props.onClick?.()
|
||||
popup.props.onCancel?.()
|
||||
}
|
||||
assert.equal(runCalls, 0)
|
||||
assert.equal(deleteCalls, 0)
|
||||
await popups[0].props.onConfirm()
|
||||
await flush()
|
||||
assert.equal(runCalls, 1)
|
||||
assert.equal(vm.detailVisible, true)
|
||||
assert.equal(vm.automations[0].active_run_status, 'queued', 'manual runs refresh without waiting for the next poll')
|
||||
await popups[1].props.onConfirm()
|
||||
assert.equal(deleteCalls, 1)
|
||||
assert.equal(vm.automations.length, 0)
|
||||
})
|
||||
|
||||
test('run history groups by the automation timezone and drawer run requires confirmation', async t => {
|
||||
let runCalls = 0
|
||||
const props = { visible: false, automation }
|
||||
const { vm, render } = setup(t, './AutomationDetail.vue', {
|
||||
runAutomationNow: async () => { runCalls++; return { data: { id: 'new-run' } } },
|
||||
}, props)
|
||||
vm.runs = [
|
||||
{ id: 'a', scheduled_at: '2026-10-20T16:30:00Z' },
|
||||
{ id: 'b', scheduled_at: '2026-10-20T16:00:00Z' },
|
||||
{ id: 'c', scheduled_at: '2026-10-20T15:59:00Z' },
|
||||
].map(run => ({ ...run, status: 'succeeded', session_id: 'chat', trigger_kind: 'schedule' }))
|
||||
assert.equal(vm.runGroups.length, 2)
|
||||
assert.equal(vm.runGroups[0].date, 'October 21, 2026')
|
||||
assert.equal(vm.runGroups[0].runs.length, 2)
|
||||
assert.equal(vm.runTime(vm.runs[0].scheduled_at), '00:30')
|
||||
const popup = nodes(render()).find(node => node.type === 't-popconfirm')
|
||||
assert.ok(popup)
|
||||
const trigger = nodes(popup).find(node => node.type === 'button')
|
||||
assert.equal(trigger.props['aria-label'], 'automation.actions.runNow')
|
||||
trigger.props.onClick?.()
|
||||
assert.equal(runCalls, 0)
|
||||
await popup.props.onConfirm()
|
||||
assert.equal(runCalls, 1)
|
||||
})
|
||||
|
||||
test('grant popup preserves history and dismisses when starting a run or reopening the drawer', async t => {
|
||||
const { vm, render } = setup(t, './AutomationDetail.vue', {
|
||||
listAutomationGrants: async () => ({ data: [] }),
|
||||
listAutomationGrantCandidates: async () => ({ data: [{ prompt_id: 'approval-1', label: 'Update document', risk: 'write' }] }),
|
||||
listAutomationRuns: async () => ({ data: [], total: 0 }),
|
||||
runAutomationNow: async () => ({ data: { id: 'new-run' } }),
|
||||
}, { visible: false, automation })
|
||||
assert.equal(vm.grantsVisible, false)
|
||||
const popup = nodes(render()).find(node => node.type?.name === 't-popup')
|
||||
popup.props['onUpdate:visible'](true)
|
||||
assert.equal(vm.grantsVisible, true)
|
||||
await vm.loadGrants()
|
||||
assert.equal(vm.grantsVisible, true, 'loading grants must not dismiss their popup')
|
||||
const trigger = nodes(render()).find(node => node.type === 'button' && node.props?.class?.includes('automation-detail__grants-trigger'))
|
||||
assert.ok(trigger.props.class.includes('is-attention'), 'candidates remain visible from the trigger')
|
||||
assert.equal(trigger.props['aria-expanded'], true)
|
||||
assert.ok(nodes(render()).some(node => node.props?.class === 'automation-detail__history'))
|
||||
await vm.runNow()
|
||||
assert.equal(vm.grantsVisible, false, 'a manual run dismisses the popup to reveal progress')
|
||||
assert.equal(vm.runs[0].id, 'new-run')
|
||||
popup.props['onUpdate:visible'](true)
|
||||
vm.$.props.visible = true
|
||||
await flush()
|
||||
assert.equal(vm.grantsVisible, false, 'reopening the drawer does not restore a stale popup')
|
||||
})
|
||||
|
||||
for (const file of ['./AutomationList.vue', './AutomationDetail.vue']) {
|
||||
test(`${file}: elapsed one-shot schedules have no resume entry, but manual run remains available`, async t => {
|
||||
let resumeCalls = 0
|
||||
const item = { ...automation, enabled: false, trigger: { type: 'once', at: new Date(Date.now() - 60_000).toISOString() } }
|
||||
const { vm, render } = setup(t, file, {
|
||||
listAutomations: async () => ({ data: [item] }),
|
||||
resumeAutomation: async () => { resumeCalls++; return { data: { ...item, enabled: true } } },
|
||||
}, { visible: false, automation: item })
|
||||
await flush()
|
||||
const resumeButton = () => nodes(render()).find(node => node.type === 'button'
|
||||
&& (node.props?.role === 'switch' || node.props?.['aria-label'] === 'automation.actions.resume'))
|
||||
assert.equal(resumeButton(), undefined)
|
||||
assert.ok(nodes(render()).some(node => node.type === 't-popconfirm'
|
||||
&& node.props?.['confirm-btn']?.content === 'automation.actions.runNow'))
|
||||
await vm.toggle(item)
|
||||
assert.equal(resumeCalls, 0, 'stale handlers cannot resume an elapsed schedule')
|
||||
|
||||
item.trigger.at = new Date(Date.now() + 60_000).toISOString()
|
||||
assert.ok(resumeButton(), 'a paused future one-shot can still be resumed')
|
||||
if (file.includes('Detail')) {
|
||||
assert.ok(nodes(render()).some(node => node.props?.name === 'resume'), 'resume uses its own icon')
|
||||
}
|
||||
await vm.toggle(item)
|
||||
assert.equal(resumeCalls, 1)
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user