fix(assistant): close review gaps in delivery and action recovery
Address PR4 comments 66-69 with safe delivery retries, capacity stops, preserved effect evidence and stale proposal rejection. Prevent archived queue snapshots from resurrecting cancelled reminders.
This commit is contained in:
1 parent
1d5dcead84
commit
5ceffb935a
24 files changed
+1425
-125
No files matched your search
@@ -10,6 +10,7 @@ window.AssistantContextPanel = {
|
||||
settings,
|
||||
isActive,
|
||||
onExecute,
|
||||
onReject,
|
||||
onRepair,
|
||||
showRight,
|
||||
ensureConversation,
|
||||
@@ -165,10 +166,13 @@ window.AssistantContextPanel = {
|
||||
list
|
||||
.map(
|
||||
({ a, t }) =>
|
||||
`<article class="assistant-action" data-action-card="${esc(a.id)}"><strong>${esc(a.label)}</strong><div class="small text-secondary mt-2">目标:${esc(a.targetId)}</div><div class="small text-secondary mt-1">影响:${esc({ check_storage: '发起一次存储连接检查', scan_bpm: '只读重新扫描,更新到达记录', retry_archive: '向原目标重试明确失败的归档', collect_field_samples: '读取待办样本并保存字段证据', collect_history_samples: '只读采集历史字段样本', prepare_field_mapping: '生成并检查草稿,不自动生效', repair_code: '在隔离 Git 工作区执行固定测试,不自动合并部署' }[a.kind] || '仅执行已列出的受控操作')}</div><div class="small text-secondary mt-1">操作编号:${esc(a.id)}</div>${['update_configuration', 'manage_schedule'].includes(a.kind) ? `<div class="aw-config-summary">${a.diff.map((d) => `<p>${esc(d.label)}:${esc(JSON.stringify(d.before))} → ${esc(JSON.stringify(d.after))}</p>`).join('')}<strong>风险与影响</strong><ul>${a.risks.map((r) => `<li>${esc(r)}</li>`).join('')}</ul><small>审查并授权后才会保存;建议过期或配置变化须重新生成。</small></div>` : ''}${a.kind === 'repair_code' ? `<p class="aw-verify-warning">以本机服务身份运行固定测试;工作区不是操作系统沙箱,通过后仍待人工审查。</p>${a.files.map((f) => `<details><summary>${esc(f.path)} · 查看修改前后</summary><div>修改前</div><pre>${esc(a.beforeFiles?.find((b) => b.path === f.path)?.content || '')}</pre><div>建议内容</div><pre>${esc(f.content)}</pre></details>`).join('')}` : ''}${a.progress ? `<p class="small mt-2">采样进度 ${esc(a.progress.completed)} / ${esc(a.progress.total)},成功 ${esc(a.progress.captured)},受阻 ${esc(a.progress.failed)}</p>` : ''}<div class="mt-3">${a.status === 'proposed' ? `<button class="btn btn-sm btn-outline-primary" type="button" data-assistant-action="${esc(a.id)}" ${(!settings.allowActions && a.kind !== 'manage_schedule') || conversation.archived || conversation.deletedAt || user.role === 'viewer' ? 'disabled' : ''}>${['update_configuration', 'manage_schedule'].includes(a.kind) ? '审查修改' : '执行:' + esc(a.label)}</button>` : `<strong>${esc(window.AssistantConversation.actionState(a))}</strong>`}</div>${a.error ? `<p class="small text-danger mt-2">${esc(a.error)}</p>` : ''}${a.result || ['success', 'error', 'needs_review', 'interrupted'].includes(a.status) ? `<details class="mt-2 aw-action-result"><summary>结果详情</summary><p class="mt-2">${esc(window.AssistantConversation.actionSummary(a))}</p>${a.result && (typeof a.result !== 'object' || Object.keys(a.result).length) ? `<pre>${esc(JSON.stringify(a.result, null, 2))}</pre>` : ''}</details>` : ''}${a.result?.link ? '<a class="btn btn-sm mt-2" href="' + esc(a.kind === 'update_configuration' ? a.result.link : '#rule-fields') + '">' + (a.kind === 'update_configuration' ? '查看设置' : '查看字段映射') + '</a>' : ''}</article>`,
|
||||
`<article class="assistant-action" data-action-card="${esc(a.id)}"><strong>${esc(a.label)}</strong><div class="small text-secondary mt-2">目标:${esc(a.targetId)}</div><div class="small text-secondary mt-1">影响:${esc({ check_storage: '发起一次存储连接检查', scan_bpm: '只读重新扫描,更新到达记录', retry_archive: '向原目标重试明确失败的归档', collect_field_samples: '读取待办样本并保存字段证据', collect_history_samples: '只读采集历史字段样本', prepare_field_mapping: '生成并检查草稿,不自动生效', repair_code: '在隔离 Git 工作区执行固定测试,不自动合并部署' }[a.kind] || '仅执行已列出的受控操作')}</div><div class="small text-secondary mt-1">操作编号:${esc(a.id)}</div>${['update_configuration', 'manage_schedule'].includes(a.kind) ? `<div class="aw-config-summary">${a.diff.map((d) => `<p>${esc(d.label)}:${esc(JSON.stringify(d.before))} → ${esc(JSON.stringify(d.after))}</p>`).join('')}<strong>风险与影响</strong><ul>${a.risks.map((r) => `<li>${esc(r)}</li>`).join('')}</ul><small>审查并授权后才会保存;建议过期或配置变化须重新生成。</small></div>` : ''}${a.kind === 'repair_code' ? `<p class="aw-verify-warning">以本机服务身份运行固定测试;工作区不是操作系统沙箱,通过后仍待人工审查。</p>${a.files.map((f) => `<details><summary>${esc(f.path)} · 查看修改前后</summary><div>修改前</div><pre>${esc(a.beforeFiles?.find((b) => b.path === f.path)?.content || '')}</pre><div>建议内容</div><pre>${esc(f.content)}</pre></details>`).join('')}` : ''}${a.progress ? `<p class="small mt-2">采样进度 ${esc(a.progress.completed)} / ${esc(a.progress.total)},成功 ${esc(a.progress.captured)},受阻 ${esc(a.progress.failed)}</p>` : ''}<div class="mt-3">${a.status === 'proposed' ? `<button class="btn btn-sm btn-outline-primary" type="button" data-assistant-action="${esc(a.id)}" ${(!settings.allowActions && a.kind !== 'manage_schedule') || conversation.archived || conversation.deletedAt || user.role === 'viewer' ? 'disabled' : ''}>${['update_configuration', 'manage_schedule'].includes(a.kind) ? '审查修改' : '执行:' + esc(a.label)}</button>${['update_configuration', 'manage_schedule'].includes(a.kind) ? `<button type="button" class="btn btn-sm ms-2" data-assistant-reject="${esc(a.id)}" ${conversation.archived || conversation.deletedAt || user.role === 'viewer' || (a.kind === 'update_configuration' && user.role !== 'admin') ? 'disabled' : ''}>拒绝建议</button>` : ''}` : `<strong>${esc(window.AssistantConversation.actionState(a))}</strong>`}</div>${a.error ? `<p class="small text-danger mt-2">${esc(a.error)}</p>` : ''}${a.result || ['success', 'error', 'needs_review', 'interrupted'].includes(a.status) ? `<details class="mt-2 aw-action-result"><summary>结果详情</summary><p class="mt-2">${esc(window.AssistantConversation.actionSummary(a))}</p>${a.result && (typeof a.result !== 'object' || Object.keys(a.result).length) ? `<pre>${esc(JSON.stringify(a.result, null, 2))}</pre>` : ''}</details>` : ''}${a.result?.link ? '<a class="btn btn-sm mt-2" href="' + esc(a.kind === 'update_configuration' ? a.result.link : '#rule-fields') + '">' + (a.kind === 'update_configuration' ? '查看设置' : '查看字段映射') + '</a>' : ''}</article>`,
|
||||
)
|
||||
.join('') +
|
||||
(list.length ? '' : '<p class="text-secondary">建议将在这里展示,确认前不会执行。</p>');
|
||||
panels.actions
|
||||
.querySelectorAll('[data-assistant-reject]')
|
||||
.forEach((b) => (b.onclick = () => onReject(b.dataset.assistantReject, b)));
|
||||
panels.actions
|
||||
.querySelectorAll('[data-assistant-action]')
|
||||
.forEach(
|
||||
|
||||
@@ -3,6 +3,7 @@ window.AssistantOperations = {
|
||||
mount(container, { api, esc, formatDate, user, settings, isActive, onRepair }) {
|
||||
const stepNames = {
|
||||
management_query: '查询受控管理资源',
|
||||
schedule_retry: '重试尚未调用的定时消息',
|
||||
schedule_create: '创建原生定时任务',
|
||||
schedule_update: '修改原生定时任务',
|
||||
schedule_delete: '删除原生定时任务',
|
||||
|
||||
@@ -19,6 +19,7 @@ window.AssistantScheduleManager = {
|
||||
['all', '全部'],
|
||||
['active', '进行中'],
|
||||
['inactive', '已结束'],
|
||||
['capacity', '容量停止'],
|
||||
]
|
||||
.map(
|
||||
([id, label]) =>
|
||||
@@ -31,7 +32,7 @@ window.AssistantScheduleManager = {
|
||||
'</button>',
|
||||
)
|
||||
.join('') +
|
||||
'</div><label class="visually-hidden" for="aw-task-search">搜索定时任务</label><input id="aw-task-search" class="form-control" type="search" maxlength="300" placeholder="搜索任务名称、内容或所属会话"><label class="visually-hidden" for="aw-task-session">筛选所属会话</label><select id="aw-task-session" class="form-select"><option value="">全部会话</option></select></div><p data-task-message class="small text-secondary" role="status">正在读取任务…</p><div data-task-list class="aw-task-list"></div><div data-task-editor hidden></div>';
|
||||
'</div><label class="visually-hidden" for="aw-task-search">搜索定时任务</label><input id="aw-task-search" class="form-control" type="search" maxlength="300" placeholder="搜索任务名称、内容或所属会话"><label class="visually-hidden" for="aw-task-session">筛选所属会话</label><select id="aw-task-session" class="form-select"><option value="">全部会话</option></select></div><p data-task-message class="small text-secondary" role="status">正在读取任务…</p><div data-task-recovery></div><div data-task-list class="aw-task-list"></div><div data-task-editor hidden></div>';
|
||||
root.append(page);
|
||||
let visible = false,
|
||||
disposed = false,
|
||||
@@ -52,6 +53,22 @@ window.AssistantScheduleManager = {
|
||||
message = page.querySelector('[data-task-message]'),
|
||||
newButton = page.querySelector('[data-task-create]');
|
||||
const alive = () => !disposed && visible && isActive();
|
||||
const recovery = window.AssistantScheduleRecovery.mount(
|
||||
page.querySelector('[data-task-recovery]'),
|
||||
{
|
||||
root,
|
||||
api,
|
||||
esc,
|
||||
formatDate,
|
||||
user,
|
||||
isActive: () => alive(),
|
||||
getConversations: () => conversations,
|
||||
onChanged: async (id) => {
|
||||
await onChanged(id);
|
||||
await refresh();
|
||||
},
|
||||
},
|
||||
);
|
||||
const editor = window.AssistantSchedules.mount(page.querySelector('[data-task-editor]'), {
|
||||
api,
|
||||
esc,
|
||||
@@ -86,7 +103,15 @@ window.AssistantScheduleManager = {
|
||||
return user.role !== 'viewer' && settled && !failed && !t?.conversationArchived;
|
||||
}
|
||||
function nativeTask(t) {
|
||||
const { conversationTitle, conversationArchived, ...value } = t;
|
||||
const {
|
||||
conversationTitle,
|
||||
conversationArchived,
|
||||
turnCount,
|
||||
remainingTurns,
|
||||
maxTurns,
|
||||
capacityWarning,
|
||||
...value
|
||||
} = t;
|
||||
return value;
|
||||
}
|
||||
function target(t) {
|
||||
@@ -95,10 +120,14 @@ window.AssistantScheduleManager = {
|
||||
}
|
||||
function draw() {
|
||||
newButton.disabled = !canWrite();
|
||||
recovery.update(history);
|
||||
const rows = tasks
|
||||
.filter(
|
||||
(t) =>
|
||||
(status === 'all' || t.status === status) &&
|
||||
(status === 'all' ||
|
||||
t.status === status ||
|
||||
(status === 'capacity' &&
|
||||
['capacity_stopped', 'capacity_stopping'].includes(t.status))) &&
|
||||
(!conversationFilter || t.sessionId === conversationFilter) &&
|
||||
(!query ||
|
||||
[t.title, t.prompt, t.conversationTitle, t.id, t.sessionId].some((v) =>
|
||||
@@ -119,7 +148,7 @@ window.AssistantScheduleManager = {
|
||||
tasks.length +
|
||||
' 个任务;新建、详情、编辑和删除均可在此操作。'
|
||||
: '正在读取任务…';
|
||||
const next = JSON.stringify([rows, settled, failed, user.role]);
|
||||
const next = JSON.stringify([rows, history, settled, failed, user.role]);
|
||||
if (next === signature) return;
|
||||
signature = next;
|
||||
list.innerHTML = rows.length
|
||||
@@ -129,14 +158,14 @@ window.AssistantScheduleManager = {
|
||||
'<article class="aw-task-row"><div class="aw-task-row-heading"><strong>' +
|
||||
esc(t.title) +
|
||||
'</strong><span class="aw-state">' +
|
||||
(t.status === 'active' ? '进行中' : '已结束') +
|
||||
esc(window.AssistantScheduleRecovery.taskStatus(t.status)) +
|
||||
'</span></div><p class="small text-secondary">' +
|
||||
esc(frequency(t)) +
|
||||
'<br>' +
|
||||
esc(
|
||||
t.status === 'active'
|
||||
? '下次触发:' + formatDate(t.scheduledAt)
|
||||
: '最后触发时间:' + formatDate(t.scheduledAt),
|
||||
window.AssistantScheduleRecovery.timeLabel(t.status) +
|
||||
':' +
|
||||
formatDate(t.scheduledAt),
|
||||
) +
|
||||
'<br>所属会话:' +
|
||||
esc(t.conversationTitle || '未命名会话') +
|
||||
@@ -144,6 +173,9 @@ window.AssistantScheduleManager = {
|
||||
esc(t.prompt) +
|
||||
'</p>' +
|
||||
(t.lastError ? '<p class="text-danger small">' + esc(t.lastError) + '</p>' : '') +
|
||||
(t.capacityWarning
|
||||
? '<p class="text-warning small">' + esc(t.capacityWarning) + '</p>'
|
||||
: '') +
|
||||
'<div class="btn-list"><button type="button" class="btn btn-sm" data-task-detail="' +
|
||||
esc(t.id) +
|
||||
'" aria-label="查看任务 ' +
|
||||
@@ -257,8 +289,8 @@ window.AssistantScheduleManager = {
|
||||
row('任务编号', t.id) +
|
||||
row('所属会话', t.conversationTitle || t.sessionId) +
|
||||
row('触发规则', frequency(t)) +
|
||||
row(t.status === 'active' ? '下次触发' : '最后触发时间', formatDate(t.scheduledAt)) +
|
||||
row('状态', t.status === 'active' ? '进行中' : '已结束') +
|
||||
row(window.AssistantScheduleRecovery.timeLabel(t.status), formatDate(t.scheduledAt)) +
|
||||
row('状态', window.AssistantScheduleRecovery.taskStatus(t.status)) +
|
||||
row('任务内容', t.prompt) +
|
||||
'</dl><h3 class="h4">调用记录</h3>' +
|
||||
(records.length
|
||||
@@ -274,6 +306,8 @@ window.AssistantScheduleManager = {
|
||||
running: '正在调用',
|
||||
success: '已回复',
|
||||
error: '调用失败',
|
||||
not_started: '尚未调用',
|
||||
waiting_capacity: '等待选择其他会话',
|
||||
cancelled: '已取消',
|
||||
needs_review: '待核实',
|
||||
}[h.status] || h.status,
|
||||
@@ -354,6 +388,7 @@ window.AssistantScheduleManager = {
|
||||
generation++;
|
||||
clearInterval(timer);
|
||||
editor.dispose();
|
||||
recovery.dispose();
|
||||
navButtons.forEach((b) => b.removeEventListener('click', close));
|
||||
body.hidden = false;
|
||||
page.remove();
|
||||
|
||||
@@ -0,0 +1,163 @@
|
||||
'use strict';
|
||||
|
||||
window.AssistantScheduleRecovery = {
|
||||
timeLabel(status) {
|
||||
return status === 'active'
|
||||
? '下次触发'
|
||||
: status === 'inactive'
|
||||
? '最后触发时间'
|
||||
: '停止前计划时间';
|
||||
},
|
||||
taskStatus(status) {
|
||||
return (
|
||||
{
|
||||
active: '进行中',
|
||||
inactive: '已结束',
|
||||
capacity_stopped: '容量已满,已停止',
|
||||
capacity_stopping: '停止结果待核实',
|
||||
}[status] || status
|
||||
);
|
||||
},
|
||||
mount(host, { root, api, esc, formatDate, user, isActive, getConversations, onChanged }) {
|
||||
let signature = '';
|
||||
let busy = false;
|
||||
let disposed = false;
|
||||
let history = [];
|
||||
|
||||
function open(row) {
|
||||
if (busy || disposed || !row.retryable || user.role === 'viewer') return;
|
||||
const choices = getConversations().filter((c) => !c.archived && c.remainingTurns !== 0);
|
||||
const dialog = document.createElement('dialog');
|
||||
dialog.className = 'page-leave-dialog aw-schedule-dialog';
|
||||
dialog.setAttribute('aria-label', '重试定时消息');
|
||||
dialog.innerHTML =
|
||||
'<form><h2 class="h3">重试定时消息</h2><p>' +
|
||||
esc(row.title) +
|
||||
'</p><p>仅重新入队这条尚未建轮的消息,沿用同次投递标识,避免重复调用。</p>' +
|
||||
(row.retryNeedsTarget
|
||||
? '<p class="text-warning">原会话已满,未来定时任务已停止。本次仅重试未调用消息;周期任务请在新会话重新安排。</p>'
|
||||
: '') +
|
||||
'<label class="form-label">目标会话<select class="form-select" name="target" aria-label="目标会话" required>' +
|
||||
choices
|
||||
.map(
|
||||
(c) =>
|
||||
'<option value="' +
|
||||
esc(c.id) +
|
||||
'">' +
|
||||
esc(c.title) +
|
||||
'(剩余 ' +
|
||||
esc(c.remainingTurns) +
|
||||
' 轮)</option>',
|
||||
)
|
||||
.join('') +
|
||||
'</select></label>' +
|
||||
(!choices.length ? '<p>请先新建对话,再回到此处选择目标会话。</p>' : '') +
|
||||
'<p class="small text-secondary">将使用目标会话的模型和历史,旧会话附件不会自动迁移,可能产生模型费用。不会自动执行邮件、配置或其他操作。</p><label class="form-check my-3"><input class="form-check-input" name="consent" type="checkbox"><span class="form-check-label">我确认仅重试这条未调用消息</span></label><p role="alert" class="text-danger" data-retry-error></p><div class="btn-list"><button type="button" class="btn" data-retry-cancel>取消</button><button type="submit" class="btn btn-primary" disabled>确认重试</button></div></form>';
|
||||
root.append(dialog);
|
||||
const form = dialog.querySelector('form');
|
||||
const save = form.querySelector('[type=submit]');
|
||||
const checkbox = form.elements.consent;
|
||||
const target = form.elements.target;
|
||||
target.value = choices.some((c) => c.id === row.conversationId)
|
||||
? row.conversationId
|
||||
: choices[0]?.id || '';
|
||||
checkbox.onchange = () => {
|
||||
save.disabled = !checkbox.checked || !choices.length || dialog.dataset.locked === 'true';
|
||||
};
|
||||
form.querySelector('[data-retry-cancel]').onclick = () => {
|
||||
if (!busy) dialog.close();
|
||||
};
|
||||
dialog.oncancel = (e) => {
|
||||
if (busy) e.preventDefault();
|
||||
};
|
||||
dialog.onclose = () => dialog.remove();
|
||||
form.onsubmit = async (e) => {
|
||||
e.preventDefault();
|
||||
if (busy || !checkbox.checked || !target.value || dialog.dataset.locked === 'true') return;
|
||||
busy = true;
|
||||
save.disabled = true;
|
||||
target.disabled = true;
|
||||
checkbox.disabled = true;
|
||||
try {
|
||||
const result = await api(
|
||||
'/assistant/conversations/' +
|
||||
row.conversationId +
|
||||
'/schedules/deliveries/' +
|
||||
row.id +
|
||||
'/retry',
|
||||
{ confirm: true, targetConversationId: target.value },
|
||||
{ managedOutcome: true },
|
||||
);
|
||||
if (disposed || !isActive()) return;
|
||||
dialog.close();
|
||||
await onChanged(result.conversationId);
|
||||
} catch (error) {
|
||||
if (dialog.isConnected && !disposed) {
|
||||
const uncertain = !error.status || error.status >= 500;
|
||||
dialog.dataset.locked = uncertain || error.status === 409 ? 'true' : '';
|
||||
form.querySelector('[data-retry-error]').textContent =
|
||||
error.message + (uncertain ? ' 请刷新调用记录核实,勿重复提交。' : '');
|
||||
target.disabled = false;
|
||||
checkbox.disabled = false;
|
||||
save.disabled = dialog.dataset.locked === 'true';
|
||||
}
|
||||
} finally {
|
||||
busy = false;
|
||||
}
|
||||
};
|
||||
dialog.showModal();
|
||||
}
|
||||
|
||||
return {
|
||||
update(rows) {
|
||||
history = rows;
|
||||
const pending = history.filter(
|
||||
(h) =>
|
||||
h.retryable || ['not_started', 'waiting_capacity', 'needs_review'].includes(h.status),
|
||||
);
|
||||
const next = JSON.stringify([pending, getConversations(), user.role]);
|
||||
if (next === signature) return;
|
||||
signature = next;
|
||||
host.hidden = !pending.length;
|
||||
host.innerHTML =
|
||||
'<h3 class="h4">需处理的定时调用</h3>' +
|
||||
pending
|
||||
.map(
|
||||
(h) =>
|
||||
'<article class="assistant-action"><strong>' +
|
||||
esc(h.title) +
|
||||
'</strong><p class="small text-secondary">' +
|
||||
esc(formatDate(h.scheduledAt)) +
|
||||
' · ' +
|
||||
esc(
|
||||
{
|
||||
not_started: '尚未调用,可确认后重试',
|
||||
waiting_capacity: '等待选择其他会话',
|
||||
needs_review: '已有调用记录,需人工核实',
|
||||
}[h.status] || h.status,
|
||||
) +
|
||||
'</p>' +
|
||||
(h.error ? '<p class="small">' + esc(h.error) + '</p>' : '') +
|
||||
(h.retryable && user.role !== 'viewer'
|
||||
? '<button type="button" class="btn btn-sm btn-outline-primary" data-retry-delivery="' +
|
||||
esc(h.id) +
|
||||
'" aria-label="重试定时消息 ' +
|
||||
esc(h.title) +
|
||||
'">重试未调用消息</button>'
|
||||
: '') +
|
||||
'</article>',
|
||||
)
|
||||
.join('');
|
||||
host
|
||||
.querySelectorAll('[data-retry-delivery]')
|
||||
.forEach(
|
||||
(b) => (b.onclick = () => open(history.find((h) => h.id === b.dataset.retryDelivery))),
|
||||
);
|
||||
},
|
||||
dispose() {
|
||||
disposed = true;
|
||||
history = [];
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -21,14 +21,31 @@ window.AssistantSchedules = {
|
||||
visible = false,
|
||||
tasks = [],
|
||||
history = [],
|
||||
conversations = [],
|
||||
timer = null,
|
||||
loading = false,
|
||||
lastSignature = '';
|
||||
const root = host.closest('.assistant-workspace');
|
||||
host.innerHTML =
|
||||
'<h3>定时任务</h3><p class="small text-secondary">使用 DSH 原生调度,在原会话中定时调用模型。关闭页面后仍可运行,服务停止期间不会调用模型。</p><div class="btn-list"><button type="button" class="btn btn-primary btn-sm" data-schedule-new>新建定时任务</button><button type="button" class="btn btn-sm" data-schedule-refresh>刷新任务</button></div><p role="alert" class="small text-danger" data-schedule-error></p><div data-schedule-tasks></div><h4 class="mt-3">最近调用</h4><div data-schedule-history></div>';
|
||||
'<h3>定时任务</h3><p class="small text-secondary">使用 DSH 原生调度,在原会话中定时调用模型。关闭页面后仍可运行,服务停止期间不会调用模型。</p><div class="btn-list"><button type="button" class="btn btn-primary btn-sm" data-schedule-new>新建定时任务</button><button type="button" class="btn btn-sm" data-schedule-refresh>刷新任务</button></div><p role="alert" class="small text-danger" data-schedule-error></p><div data-schedule-recovery></div><div data-schedule-tasks></div><h4 class="mt-3">最近调用</h4><div data-schedule-history></div>';
|
||||
const error = host.querySelector('[data-schedule-error]'),
|
||||
create = host.querySelector('[data-schedule-new]');
|
||||
const recovery = window.AssistantScheduleRecovery.mount(
|
||||
host.querySelector('[data-schedule-recovery]'),
|
||||
{
|
||||
root,
|
||||
api,
|
||||
esc,
|
||||
formatDate,
|
||||
user,
|
||||
isActive,
|
||||
getConversations: () => conversations,
|
||||
onChanged: async (id) => {
|
||||
await onChanged(id);
|
||||
await refresh();
|
||||
},
|
||||
},
|
||||
);
|
||||
const writable = () =>
|
||||
user.role !== 'viewer' && !getConversation()?.archived && !getConversation()?.deletedAt;
|
||||
function timing(t) {
|
||||
@@ -45,6 +62,7 @@ window.AssistantSchedules = {
|
||||
}
|
||||
function draw() {
|
||||
create.disabled = busy || !writable();
|
||||
recovery.update(history);
|
||||
const signature = JSON.stringify([tasks, history, busy, writable()]);
|
||||
if (signature === lastSignature) return;
|
||||
lastSignature = signature;
|
||||
@@ -60,12 +78,17 @@ window.AssistantSchedules = {
|
||||
esc(
|
||||
t.status === 'active'
|
||||
? '下次触发:' + formatDate(t.scheduledAt)
|
||||
: '已触发(不再重复)',
|
||||
: t.status === 'inactive'
|
||||
? '已触发(不再重复)'
|
||||
: window.AssistantScheduleRecovery.taskStatus(t.status),
|
||||
) +
|
||||
'</p><p class="aw-schedule-prompt">' +
|
||||
esc(t.prompt) +
|
||||
'</p>' +
|
||||
(t.lastError ? '<p class="text-danger">' + esc(t.lastError) + '</p>' : '') +
|
||||
(t.capacityWarning
|
||||
? '<p class="text-warning small">' + esc(t.capacityWarning) + '</p>'
|
||||
: '') +
|
||||
'<div class="btn-list"><button type="button" class="btn btn-sm" data-schedule-edit="' +
|
||||
esc(t.id) +
|
||||
'" aria-label="编辑任务 ' +
|
||||
@@ -95,6 +118,8 @@ window.AssistantSchedules = {
|
||||
running: '正在调用',
|
||||
success: '已回复',
|
||||
error: '调用失败',
|
||||
not_started: '尚未调用',
|
||||
waiting_capacity: '等待选择其他会话',
|
||||
cancelled: '已取消',
|
||||
needs_review: '待核实',
|
||||
}[h.status] || h.status,
|
||||
@@ -128,6 +153,7 @@ window.AssistantSchedules = {
|
||||
if (disposed || !isActive() || id !== cid || at !== generation) return;
|
||||
tasks = data.tasks;
|
||||
history = data.history;
|
||||
conversations = data.conversations || [];
|
||||
error.textContent = data.error || '';
|
||||
draw();
|
||||
} catch (e) {
|
||||
@@ -362,7 +388,17 @@ window.AssistantSchedules = {
|
||||
let body = { confirm: true, request },
|
||||
url = '/assistant/conversations/' + owner + '/schedules';
|
||||
if (task) {
|
||||
const { sessionId, status, lastDelivery, lastError, ...expected } = task;
|
||||
const {
|
||||
sessionId,
|
||||
status,
|
||||
lastDelivery,
|
||||
lastError,
|
||||
turnCount,
|
||||
remainingTurns,
|
||||
maxTurns,
|
||||
capacityWarning,
|
||||
...expected
|
||||
} = task;
|
||||
const changes = { title: request.title, prompt: request.prompt };
|
||||
if (timingChanged) changes.change = { kind: fields.kind.value, ...selector() };
|
||||
body = { confirm: true, expected, changes };
|
||||
@@ -432,6 +468,7 @@ window.AssistantSchedules = {
|
||||
},
|
||||
dispose() {
|
||||
disposed = true;
|
||||
recovery.dispose();
|
||||
generation++;
|
||||
clearInterval(timer);
|
||||
},
|
||||
|
||||
@@ -59,10 +59,13 @@
|
||||
isActive: live,
|
||||
showRight: () => layout.showRight(),
|
||||
onExecute: execute,
|
||||
onReject: (id, button) => execute(id, button, true),
|
||||
onRepair: repair,
|
||||
ensureConversation,
|
||||
onScheduleChanged: async (id) => {
|
||||
if (!live() || id !== currentId) return;
|
||||
if (!live()) return;
|
||||
await refreshList();
|
||||
if (id !== currentId) return;
|
||||
if (!eventClient) await select(id);
|
||||
else await loadCurrent();
|
||||
},
|
||||
@@ -76,7 +79,9 @@
|
||||
ensureConversation,
|
||||
isActive: live,
|
||||
onChanged: async (id) => {
|
||||
if (!live() || id !== currentId) return;
|
||||
if (!live()) return;
|
||||
await refreshList();
|
||||
if (id !== currentId) return;
|
||||
if (!eventClient) await select(id);
|
||||
else await loadCurrent();
|
||||
},
|
||||
@@ -593,7 +598,7 @@
|
||||
await select(owner.id);
|
||||
panel.showActions();
|
||||
}
|
||||
async function execute(actionId, button) {
|
||||
async function execute(actionId, button, rejectOnly = false) {
|
||||
if (pendingActions.has(actionId)) return;
|
||||
const id = currentId,
|
||||
at = revision;
|
||||
@@ -605,7 +610,7 @@
|
||||
.flatMap((t) => t.actions || [])
|
||||
.find((a) => a.id === actionId);
|
||||
let body = {};
|
||||
if (['update_configuration', 'manage_schedule'].includes(action?.kind)) {
|
||||
if (!rejectOnly && ['update_configuration', 'manage_schedule'].includes(action?.kind)) {
|
||||
body = await window.AssistantSettingsReview.open(root, {
|
||||
api,
|
||||
id,
|
||||
@@ -616,9 +621,17 @@
|
||||
}
|
||||
if (!live() || id !== currentId || revision !== at) return;
|
||||
watch();
|
||||
await api('/assistant/conversations/' + id + '/actions/' + actionId + '/execute', body, {
|
||||
managedOutcome: true,
|
||||
});
|
||||
await api(
|
||||
'/assistant/conversations/' +
|
||||
id +
|
||||
'/actions/' +
|
||||
actionId +
|
||||
(rejectOnly ? '/reject' : '/execute'),
|
||||
body,
|
||||
{
|
||||
managedOutcome: true,
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
if (live() && id === currentId && revision === at) showError(e);
|
||||
} finally {
|
||||
|
||||
@@ -47,3 +47,5 @@
|
||||
.aw-body[hidden],.aw-task-page[hidden]{display:none!important}.aw-task-page{flex:1;min-height:0;overflow:auto;padding:24px clamp(16px,4vw,48px);background:#fafbf9}.aw-task-heading{display:flex;align-items:center;justify-content:space-between;gap:16px;max-width:1200px;margin:0 auto 20px}.aw-task-heading h2{margin:16px 0 8px;font-size:22px}.aw-task-heading p{margin:0}.aw-task-filters{display:flex;gap:12px;flex-wrap:wrap;max-width:1200px;margin:0 auto 16px}.aw-task-filters [role=group]{display:flex;gap:4px}.aw-task-filters [aria-pressed=true]{background:#e1ece5;color:#245c3d}.aw-task-filters input{flex:1 1 220px;width:auto;min-width:0}.aw-task-filters select{flex:0 1 240px;width:auto;min-width:0}.aw-task-page>[data-task-message]{max-width:1200px;margin:0 auto 16px}.aw-task-list{display:grid;grid-template-columns:repeat(auto-fill,minmax(min(100%,340px),1fr));gap:16px;max-width:1200px;margin:auto}.aw-task-row{padding:20px;border:1px solid #dfe7e0;border-radius:14px;background:white;min-width:0;overflow-wrap:anywhere}.aw-task-row-heading{display:flex;align-items:flex-start;justify-content:space-between;gap:12px;margin-bottom:12px}.aw-task-row-heading strong{font-size:15px}.aw-task-row-heading .aw-state{white-space:nowrap}.aw-task-excerpt{display:-webkit-box;-webkit-line-clamp:3;-webkit-box-orient:vertical;overflow:hidden;white-space:pre-wrap}.aw-task-empty{grid-column:1/-1;padding:50px 16px;text-align:center}.aw-task-row .btn-list{margin-bottom:8px}.aw-schedule-dialog dd{white-space:pre-wrap;overflow-wrap:anywhere;margin-bottom:12px}@media(max-width:600px){.aw-task-heading{align-items:flex-start;flex-direction:column}.aw-task-heading>.btn-list{width:100%}.aw-task-heading>.btn-list>.btn{flex:1}.aw-task-filters{flex-direction:column}.aw-task-filters input,.aw-task-filters select{flex:auto;width:100%}}
|
||||
|
||||
.aw-permissions-dialog{width:min(900px,calc(100vw - 24px));max-height:90dvh;overflow:auto}.aw-permissions-dialog td,.aw-permissions-dialog p{overflow-wrap:anywhere}
|
||||
|
||||
.aw-task-page>[data-task-recovery]{max-width:1200px;margin:0 auto 16px}.aw-task-page>[data-task-recovery] .assistant-action{background:#fff;border:1px solid #dfe7e0;border-radius:12px;padding:16px;margin-bottom:12px}
|
||||
@@ -106,6 +106,7 @@
|
||||
"assistant-layout.js",
|
||||
"assistant-conversation.js",
|
||||
"assistant-commands.js",
|
||||
"assistant-schedule-recovery.js",
|
||||
"assistant-schedules.js",
|
||||
"assistant-schedule-manager.js",
|
||||
"assistant-context-panel.js",
|
||||
|
||||
Reference in new issue
Block a user