Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6ba95c6229 |
@@ -25,6 +25,23 @@ const WEEKDAY_LABELS = [
|
|||||||
['周六', '星期六'],
|
['周六', '星期六'],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const META_TASK_SPEC_PATTERNS = [
|
||||||
|
/^我要?(?:做|创建|设置|弄)?(?:一个|个)?(?:定时(?:自动)?)?执行(?:任务)?$/u,
|
||||||
|
/^帮我?(?:做|创建|设置|弄)?(?:一个|个)?(?:定时(?:自动)?)?执行(?:任务)?$/u,
|
||||||
|
/^请?(?:帮我)?(?:做|创建|设置|弄)?(?:一个|个)?(?:定时(?:自动)?)?执行(?:任务)?$/u,
|
||||||
|
/^定时(?:自动)?执行(?:任务)?$/u,
|
||||||
|
/^执行(?:任务)?$/u,
|
||||||
|
/^做(?:一个|个)?(?:定时(?:自动)?)?(?:执行)?任务$/u,
|
||||||
|
/^创建(?:一个|个)?定时(?:自动)?执行(?:任务)?$/u,
|
||||||
|
/^想(?:要)?(?:做|创建|设置)?(?:一个|个)?(?:定时(?:自动)?)?执行(?:任务)?$/u,
|
||||||
|
];
|
||||||
|
|
||||||
|
function isMetaScheduledTaskSpec(spec) {
|
||||||
|
const normalized = String(spec ?? '').replace(/\s+/g, '').trim();
|
||||||
|
if (!normalized) return true;
|
||||||
|
return META_TASK_SPEC_PATTERNS.some((pattern) => pattern.test(normalized));
|
||||||
|
}
|
||||||
|
|
||||||
function wantsScheduledTaskAutomation(compact) {
|
function wantsScheduledTaskAutomation(compact) {
|
||||||
if (SCHEDULE_MARKERS.test(compact)) return true;
|
if (SCHEDULE_MARKERS.test(compact)) return true;
|
||||||
if (!RECURRENCE_MARKERS.test(compact)) return false;
|
if (!RECURRENCE_MARKERS.test(compact)) return false;
|
||||||
@@ -48,6 +65,7 @@ function extractScheduledTaskSpec(text) {
|
|||||||
const original = String(text ?? '').trim();
|
const original = String(text ?? '').trim();
|
||||||
if (!original) return null;
|
if (!original) return null;
|
||||||
let spec = original
|
let spec = original
|
||||||
|
.replace(/^(?:不是|别是|并非)(?:待办|代办|提醒|日程|闹钟)[,,、::\s]*/u, '')
|
||||||
.replace(
|
.replace(
|
||||||
/^(?:帮我)?(?:设|设置|创建|添加|想创建)(?:一个|个)?(?:定时(?:自动)?任务|定时执行任务)?[::,,、\s]*/u,
|
/^(?:帮我)?(?:设|设置|创建|添加|想创建)(?:一个|个)?(?:定时(?:自动)?任务|定时执行任务)?[::,,、\s]*/u,
|
||||||
'',
|
'',
|
||||||
@@ -62,9 +80,12 @@ function extractScheduledTaskSpec(text) {
|
|||||||
)
|
)
|
||||||
.replace(/(?:周[一二三四五六日天]|星期[一二三四五六日天])/gu, ' ')
|
.replace(/(?:周[一二三四五六日天]|星期[一二三四五六日天])/gu, ' ')
|
||||||
.replace(/(?:帮我|请|麻烦)/gu, ' ')
|
.replace(/(?:帮我|请|麻烦)/gu, ' ')
|
||||||
|
.replace(/^执行[,,、::\s]+/u, '')
|
||||||
|
.replace(/[,,、::\s]+执行$/u, '')
|
||||||
.replace(/\s+/g, ' ')
|
.replace(/\s+/g, ' ')
|
||||||
.trim();
|
.trim();
|
||||||
if (!spec || spec.length < 3) return null;
|
if (!spec || spec.length < 3) return null;
|
||||||
|
if (isMetaScheduledTaskSpec(spec)) return null;
|
||||||
if (!EXECUTE_VERBS.test(spec.replace(/\s+/g, ''))) return null;
|
if (!EXECUTE_VERBS.test(spec.replace(/\s+/g, ''))) return null;
|
||||||
return spec;
|
return spec;
|
||||||
}
|
}
|
||||||
@@ -302,6 +323,7 @@ export function formatScheduledTaskListReply(tasks = []) {
|
|||||||
|
|
||||||
export {
|
export {
|
||||||
extractScheduledTaskSpec,
|
extractScheduledTaskSpec,
|
||||||
|
isMetaScheduledTaskSpec,
|
||||||
parseWeekday,
|
parseWeekday,
|
||||||
resolveOnceRunAtLocal,
|
resolveOnceRunAtLocal,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -90,3 +90,24 @@ test('isScheduledTaskIntent excludes none', () => {
|
|||||||
assert.equal(isScheduledTaskIntent({ action: 'create_scheduled_task' }), true);
|
assert.equal(isScheduledTaskIntent({ action: 'create_scheduled_task' }), true);
|
||||||
assert.equal(isScheduledTaskIntent({ action: 'none' }), false);
|
assert.equal(isScheduledTaskIntent({ action: 'none' }), false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('meta scheduled-task phrases require task_spec clarification', () => {
|
||||||
|
for (const text of [
|
||||||
|
'我要做一个定时执行任务',
|
||||||
|
'定时自动执行任务',
|
||||||
|
'不是待办,定时执行任务',
|
||||||
|
]) {
|
||||||
|
const intent = parseScheduledTaskIntent(text);
|
||||||
|
assert.equal(intent.action, 'create_scheduled_task', text);
|
||||||
|
assert.ok(intent.needsClarification?.includes('task_spec'), text);
|
||||||
|
assert.ok(intent.needsClarification?.includes('schedule'), text);
|
||||||
|
assert.equal(extractScheduledTaskSpec(text), null, text);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('combined phrase keeps substantive taskSpec after time prefix', () => {
|
||||||
|
const text = '帮我创建一个定时执行任务,23:00执行,搜索今日新闻';
|
||||||
|
const intent = parseScheduledTaskIntent(text);
|
||||||
|
assert.equal(intent.needsClarification, undefined);
|
||||||
|
assert.match(intent.taskSpec, /搜索今日新闻/u);
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user