foliko 1.0.12 → 1.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +2 -1
- package/SPEC.md +51 -0
- package/package.json +1 -1
- package/plugins/telegram-plugin.js +25 -11
|
@@ -36,7 +36,8 @@
|
|
|
36
36
|
"Bash(node -c cli/src/ui/chat-ui.js && echo \"Syntax OK\")",
|
|
37
37
|
"Bash(node -c plugins/default-plugins.js && echo \"Syntax OK\")",
|
|
38
38
|
"Bash(node -c plugins/scheduler-plugin.js && echo \"Syntax OK\")",
|
|
39
|
-
"Bash(node -c plugins/telegram-plugin.js && node -c plugins/scheduler-plugin.js && echo \"Syntax OK\")"
|
|
39
|
+
"Bash(node -c plugins/telegram-plugin.js && node -c plugins/scheduler-plugin.js && echo \"Syntax OK\")",
|
|
40
|
+
"Bash(node -c plugins/telegram-plugin.js && echo \"Syntax OK\")"
|
|
40
41
|
]
|
|
41
42
|
}
|
|
42
43
|
}
|
package/SPEC.md
CHANGED
|
@@ -410,6 +410,10 @@ agent.chat('请重载 my-plugin 插件')
|
|
|
410
410
|
- 绑定主 Agent 持续对话
|
|
411
411
|
- 支持 MarkdownV2
|
|
412
412
|
- 图片/文档接收保存
|
|
413
|
+
- 监听 `scheduler:reminder` 事件发送定时提醒
|
|
414
|
+
|
|
415
|
+
**监听事件**:
|
|
416
|
+
- `scheduler:reminder` - 接收定时任务提醒并发送到 Telegram
|
|
413
417
|
|
|
414
418
|
**配置**:
|
|
415
419
|
```javascript
|
|
@@ -421,6 +425,53 @@ agent.chat('请重载 my-plugin 插件')
|
|
|
421
425
|
}
|
|
422
426
|
```
|
|
423
427
|
|
|
428
|
+
### 7.5 Scheduler Plugin (plugins/scheduler-plugin.js)
|
|
429
|
+
|
|
430
|
+
**功能**:
|
|
431
|
+
- 定时任务调度(Cron 表达式、相对时间、绝对时间)
|
|
432
|
+
- 支持 LLM 自动检测(简单提醒直接显示,需要处理的任务启用 LLM)
|
|
433
|
+
- 会话自动检测(自动发送到最近活跃的会话)
|
|
434
|
+
- 事件系统(供其他插件监听和响应)
|
|
435
|
+
|
|
436
|
+
**工具**:
|
|
437
|
+
- `schedule_task` - 创建定时任务
|
|
438
|
+
- `schedule_list` - 列出所有任务
|
|
439
|
+
- `schedule_cancel` - 取消任务
|
|
440
|
+
- `cron_examples` - Cron 表达式示例
|
|
441
|
+
|
|
442
|
+
**schedule_task 参数**:
|
|
443
|
+
```javascript
|
|
444
|
+
{
|
|
445
|
+
name: '任务名称', // 可选
|
|
446
|
+
scheduleTime: '10 minutes', // 必填,支持多种格式
|
|
447
|
+
message: '提醒内容', // 必填
|
|
448
|
+
repeat: false, // 可选,是否重复
|
|
449
|
+
cronExpression: '*/5 * * * *', // 可选,Cron 表达式
|
|
450
|
+
sessionId: 'telegram_123', // 可选,会话 ID
|
|
451
|
+
llm: true // 可选,是否需要 LLM 处理(自动检测)
|
|
452
|
+
}
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
**时间格式**:
|
|
456
|
+
| 格式 | 示例 | 说明 |
|
|
457
|
+
|------|------|------|
|
|
458
|
+
| 相对时间 | `10 seconds`, `5 minutes`, `1 hour`, `2 days` | 多久后执行 |
|
|
459
|
+
| 绝对时间 | `12:00`, `14:30:00` | 具体时间(次日开始) |
|
|
460
|
+
| Cron | `*/5 * * * *`, `0 9 * * *` | Cron 表达式 |
|
|
461
|
+
|
|
462
|
+
**自动 LLM 检测**:
|
|
463
|
+
- 简单提醒(喝水、吃饭)→ 直接显示
|
|
464
|
+
- 查询/分析任务(查看列表、分析数据)→ 启用 LLM
|
|
465
|
+
|
|
466
|
+
**事件**:
|
|
467
|
+
| 事件 | 时机 |
|
|
468
|
+
|------|------|
|
|
469
|
+
| `scheduler:task_created` | 任务创建时 |
|
|
470
|
+
| `scheduler:task_cancelled` | 任务取消时 |
|
|
471
|
+
| `scheduler:task_completed` | 任务完成时 |
|
|
472
|
+
| `scheduler:task_failed` | 任务失败时 |
|
|
473
|
+
| `scheduler:reminder` | 提醒触发时 |
|
|
474
|
+
|
|
424
475
|
## 八、使用示例
|
|
425
476
|
|
|
426
477
|
### 8.1 基础用法
|
package/package.json
CHANGED
|
@@ -124,26 +124,40 @@ module.exports = function(Plugin) {
|
|
|
124
124
|
async _handleScheduledReminder(data) {
|
|
125
125
|
const { taskName, message, sessionId } = data
|
|
126
126
|
|
|
127
|
+
// 构建提醒消息
|
|
128
|
+
const reminderText = `🔔 [${taskName}]\n\n${message}`
|
|
129
|
+
|
|
127
130
|
// 如果有 sessionId 是 telegram 类型的,发送到对应 chat
|
|
128
131
|
if (sessionId && sessionId.startsWith('telegram_')) {
|
|
129
132
|
const chatId = sessionId.replace('telegram_', '')
|
|
130
133
|
try {
|
|
131
|
-
await this._bot.sendMessage(chatId,
|
|
134
|
+
await this._bot.sendMessage(chatId, reminderText)
|
|
132
135
|
console.log(`[Telegram] Reminder sent to chat ${chatId}`)
|
|
133
136
|
} catch (err) {
|
|
134
137
|
console.error(`[Telegram] Failed to send reminder:`, err.message)
|
|
135
138
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
139
|
+
return
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// 其他情况(包括 null 或其他 sessionId),发送到最近的 Telegram 会话
|
|
143
|
+
if (this._sessions.size > 0) {
|
|
144
|
+
// 按最后活跃时间排序
|
|
145
|
+
const sortedSessions = Array.from(this._sessions.entries())
|
|
146
|
+
.sort((a, b) => {
|
|
147
|
+
const aTime = a[1].lastActive ? new Date(a[1].lastActive).getTime() : 0
|
|
148
|
+
const bTime = b[1].lastActive ? new Date(b[1].lastActive).getTime() : 0
|
|
149
|
+
return bTime - aTime
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
const [chatId] = sortedSessions[0]
|
|
153
|
+
try {
|
|
154
|
+
await this._bot.sendMessage(chatId, reminderText)
|
|
155
|
+
console.log(`[Telegram] Reminder sent to chat ${chatId}`)
|
|
156
|
+
} catch (err) {
|
|
157
|
+
console.error(`[Telegram] Failed to send reminder to ${chatId}:`, err.message)
|
|
146
158
|
}
|
|
159
|
+
} else {
|
|
160
|
+
console.log('[Telegram] No active Telegram sessions to send reminder')
|
|
147
161
|
}
|
|
148
162
|
}
|
|
149
163
|
|