@ai-setting/roy-agent-core 1.7.76 → 1.7.85
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/dist/config/config-protection.d.ts +89 -0
- package/dist/config/index.d.ts +1 -0
- package/dist/config/index.js +16 -0
- package/dist/env/agent/agent-component.d.ts +42 -21
- package/dist/env/agent/agent-component.js +3 -3
- package/dist/env/agent/index.js +3 -3
- package/dist/env/agent/types.d.ts +32 -12
- package/dist/env/error-reply.d.ts +6 -0
- package/dist/env/error-reply.js +1 -1
- package/dist/env/event-source/bounty-im-handler.d.ts +8 -0
- package/dist/env/event-source/es-command.d.ts +39 -0
- package/dist/env/event-source/es-plugins.d.ts +68 -0
- package/dist/env/event-source/event-source-component.d.ts +15 -0
- package/dist/env/event-source/event-source-handlers.d.ts +68 -0
- package/dist/env/event-source/event-source-handlers.js +22 -10
- package/dist/env/event-source/index.d.ts +5 -1
- package/dist/env/event-source/index.js +59 -10
- package/dist/env/event-source/types.d.ts +101 -1
- package/dist/env/event-source/wecom-card-action-handler.d.ts +141 -0
- package/dist/env/event-source/wecom-card-builder.d.ts +220 -0
- package/dist/env/event-source/wecom-cli-handler.d.ts +266 -0
- package/dist/env/event-source/wecom-cli-sender.d.ts +88 -0
- package/dist/env/event-source/wecom-media.d.ts +130 -0
- package/dist/env/event-source/wecom-respond-registry.d.ts +151 -0
- package/dist/env/event-source/wecom-ws-bridge.d.ts +213 -0
- package/dist/env/index.js +19 -17
- package/dist/env/task/backend/index.js +37 -1
- package/dist/env/task/backend/task-store-backend.d.ts +12 -0
- package/dist/env/task/backend/types.d.ts +19 -0
- package/dist/env/task/delegate/delegate-tool.d.ts +62 -2
- package/dist/env/task/delegate/delegate-tool.js +3 -1
- package/dist/env/task/delegate/index.js +1 -1
- package/dist/env/task/index.js +4 -4
- package/dist/env/task/mcp/index.js +3 -0
- package/dist/env/task/mcp/task-mcp-server.d.ts +1 -1
- package/dist/env/task/plugins/fake-user-message-helper.d.ts +10 -2
- package/dist/env/task/plugins/index.d.ts +3 -0
- package/dist/env/task/plugins/index.js +36 -4
- package/dist/env/task/plugins/lark-card-patch-notifier.d.ts +41 -2
- package/dist/env/task/plugins/lark-card-patch-notifier.js +1 -1
- package/dist/env/task/plugins/lark-cli-task-notify-plugin.d.ts +16 -0
- package/dist/env/task/plugins/task-op-watermark-plugin.d.ts +112 -0
- package/dist/env/task/plugins/wecom-card-state-store.d.ts +121 -0
- package/dist/env/task/plugins/wecom-task-notify-plugin.d.ts +224 -0
- package/dist/env/task/storage/index.js +2 -2
- package/dist/env/task/storage/sqlite-task-store.d.ts +54 -0
- package/dist/env/task/task-component.d.ts +16 -0
- package/dist/env/task/tools/operation/operation-types.d.ts +13 -13
- package/dist/env/tool/built-in/index.d.ts +2 -0
- package/dist/env/tool/built-in/index.js +6 -1
- package/dist/env/tool/index.js +3 -2
- package/dist/env/workflow/index.js +3 -3
- package/dist/env/workflow/plugins/index.js +2 -2
- package/dist/env/workflow/tools/index.js +2 -2
- package/dist/env/workflow/types/event.d.ts +4 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +71 -20
- package/dist/shared/@ai-setting/{roy-agent-core-v87njmq7.js → roy-agent-core-0dh8npnz.js} +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-2stt4rp5.js +134 -0
- package/dist/shared/@ai-setting/{roy-agent-core-mww0mnd9.js → roy-agent-core-7bpj859q.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-nmx9934r.js → roy-agent-core-7dd0s3xb.js} +15 -5
- package/dist/shared/@ai-setting/{roy-agent-core-ghnagzrh.js → roy-agent-core-b31v3qpv.js} +853 -48
- package/dist/shared/@ai-setting/{roy-agent-core-cxy143m4.js → roy-agent-core-begm7ytz.js} +63 -2
- package/dist/shared/@ai-setting/{roy-agent-core-aa2j7bk9.js → roy-agent-core-cha0jc7n.js} +40 -26
- package/dist/shared/@ai-setting/{roy-agent-core-p3zv1mx5.js → roy-agent-core-d1n4jbza.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-q5r75vev.js → roy-agent-core-dkrvmjsh.js} +17 -75
- package/dist/shared/@ai-setting/{roy-agent-core-abqhkbn3.js → roy-agent-core-ezvpreqz.js} +23 -0
- package/dist/shared/@ai-setting/{roy-agent-core-99nwgj84.js → roy-agent-core-fzw9xzm1.js} +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-h21gngxf.js +247 -0
- package/dist/shared/@ai-setting/roy-agent-core-m3vjepzz.js +544 -0
- package/dist/shared/@ai-setting/{roy-agent-core-zycadbpx.js → roy-agent-core-p6ks90tb.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-ntq0gz7q.js → roy-agent-core-q813vafd.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-z43aj03k.js → roy-agent-core-qk9hd89p.js} +21 -2
- package/dist/shared/@ai-setting/{roy-agent-core-6cy43nss.js → roy-agent-core-rykf7c04.js} +49 -9
- package/dist/shared/@ai-setting/{roy-agent-core-8ez6mccb.js → roy-agent-core-tk98f92b.js} +4 -0
- package/dist/shared/@ai-setting/{roy-agent-core-bxkjk7zx.js → roy-agent-core-vx8zc847.js} +4 -1
- package/dist/shared/@ai-setting/roy-agent-core-vyr6svt6.js +31 -0
- package/dist/shared/@ai-setting/{roy-agent-core-t3rrb959.js → roy-agent-core-xf6z96qy.js} +2086 -163
- package/package.json +10 -1
- package/dist/shared/@ai-setting/roy-agent-core-f77k3gqt.js +0 -71
- /package/dist/shared/@ai-setting/{roy-agent-core-b4x6x4k2.js → roy-agent-core-m1fgtnrc.js} +0 -0
- /package/dist/shared/@ai-setting/{roy-agent-core-v85n42ve.js → roy-agent-core-ze5cqpf2.js} +0 -0
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import {
|
|
2
|
+
init_decorator,
|
|
3
|
+
wrapFunction
|
|
4
|
+
} from "./roy-agent-core-qq96p0tj.js";
|
|
5
|
+
import {
|
|
6
|
+
createLogger,
|
|
7
|
+
init_logger
|
|
8
|
+
} from "./roy-agent-core-7f7t9wwp.js";
|
|
9
|
+
|
|
10
|
+
// src/env/task/plugins/task-op-watermark-plugin.ts
|
|
11
|
+
init_logger();
|
|
12
|
+
|
|
13
|
+
// src/env/task/plugins/fake-user-message-helper.ts
|
|
14
|
+
init_decorator();
|
|
15
|
+
var KIND_PRIORITY = {
|
|
16
|
+
delegate: 10,
|
|
17
|
+
"task-ops": 20,
|
|
18
|
+
"max-iter": 30
|
|
19
|
+
};
|
|
20
|
+
var KIND_FIELD = "__fakeUserMessageKind";
|
|
21
|
+
function ensureMetadata(toolResult) {
|
|
22
|
+
if (!toolResult)
|
|
23
|
+
return;
|
|
24
|
+
if (!toolResult.result)
|
|
25
|
+
toolResult.result = {};
|
|
26
|
+
if (!toolResult.result.metadata)
|
|
27
|
+
toolResult.result.metadata = {};
|
|
28
|
+
return toolResult.result.metadata;
|
|
29
|
+
}
|
|
30
|
+
function stringContent(msg) {
|
|
31
|
+
const c = msg?.content;
|
|
32
|
+
return typeof c === "string" ? c : JSON.stringify(c);
|
|
33
|
+
}
|
|
34
|
+
function enqueueToAddFakeUserMessageImpl(toolResult, newMsg, newKind) {
|
|
35
|
+
const meta = ensureMetadata(toolResult);
|
|
36
|
+
if (!meta)
|
|
37
|
+
return { willMerge: false, finalKind: newKind };
|
|
38
|
+
const existing = meta.toAddFakeUserMessage;
|
|
39
|
+
const existingKind = meta[KIND_FIELD];
|
|
40
|
+
if (!existing) {
|
|
41
|
+
meta.toAddFakeUserMessage = newMsg;
|
|
42
|
+
meta[KIND_FIELD] = newKind;
|
|
43
|
+
return { willMerge: false, finalKind: newKind };
|
|
44
|
+
}
|
|
45
|
+
let merged;
|
|
46
|
+
if (KIND_PRIORITY[newKind] >= KIND_PRIORITY[existingKind ?? newKind]) {
|
|
47
|
+
merged = {
|
|
48
|
+
role: "user",
|
|
49
|
+
content: `${stringContent(existing)}
|
|
50
|
+
|
|
51
|
+
${stringContent(newMsg)}`
|
|
52
|
+
};
|
|
53
|
+
} else {
|
|
54
|
+
merged = {
|
|
55
|
+
role: "user",
|
|
56
|
+
content: `${stringContent(newMsg)}
|
|
57
|
+
|
|
58
|
+
${stringContent(existing)}`
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
meta.toAddFakeUserMessage = merged;
|
|
62
|
+
const finalKind = KIND_PRIORITY[newKind] >= KIND_PRIORITY[existingKind ?? newKind] ? newKind : existingKind ?? newKind;
|
|
63
|
+
meta[KIND_FIELD] = finalKind;
|
|
64
|
+
return { willMerge: true, finalKind };
|
|
65
|
+
}
|
|
66
|
+
var enqueueToAddFakeUserMessage = wrapFunction(enqueueToAddFakeUserMessageImpl, "plugin.fake-user-message.enqueue", {
|
|
67
|
+
recordParams: false,
|
|
68
|
+
recordResult: false,
|
|
69
|
+
log: true,
|
|
70
|
+
resultFilter: (result) => ({
|
|
71
|
+
"fake-user-message.will_merge": result.willMerge,
|
|
72
|
+
"fake-user-message.final_kind": result.finalKind
|
|
73
|
+
})
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// src/env/task/plugins/task-op-watermark-plugin.ts
|
|
77
|
+
var logger = createLogger("TaskOpWatermarkPlugin");
|
|
78
|
+
var TASK_OP_WATERMARK_MAX_REMINDERS = 5;
|
|
79
|
+
var TASK_OP_WATERMARK_MESSAGE_LIMIT = 1500;
|
|
80
|
+
var TASK_OP_WATERMARK_AUDIT_INTERVAL = 15;
|
|
81
|
+
var MAX_DETAIL_ITEMS = 3;
|
|
82
|
+
var MAX_DESC_LENGTH = 200;
|
|
83
|
+
var UNKNOWN_SESSION = "unknown";
|
|
84
|
+
var TRUNCATION_SUFFIX = "…(已截断)";
|
|
85
|
+
function truncate(s, max) {
|
|
86
|
+
if (s.length <= max)
|
|
87
|
+
return s;
|
|
88
|
+
return `${s.slice(0, max)}…(已截断)`;
|
|
89
|
+
}
|
|
90
|
+
function buildReminderMessage(taskId, taskTitle, ops) {
|
|
91
|
+
const count = ops.length;
|
|
92
|
+
const lines = [];
|
|
93
|
+
lines.push(`[task-ops] Task #${taskId}${taskTitle ? `「${taskTitle}」` : ""} 有 ${count} 条由**其他 agent** 新增的操作记录,请读取并按需调整你的行为。`);
|
|
94
|
+
lines.push("");
|
|
95
|
+
lines.push("最新记录:");
|
|
96
|
+
const details = ops.slice(0, MAX_DETAIL_ITEMS);
|
|
97
|
+
for (const op of details) {
|
|
98
|
+
const desc = op.milestoneDescription ? truncate(op.milestoneDescription.split(`
|
|
99
|
+
`)[0], MAX_DESC_LENGTH) : "";
|
|
100
|
+
lines.push(`- [${op.milestoneType}] ${op.milestoneTitle}${desc ? `
|
|
101
|
+
${desc}` : ""}`);
|
|
102
|
+
}
|
|
103
|
+
if (count > MAX_DETAIL_ITEMS) {
|
|
104
|
+
lines.push(`(其余 ${count - MAX_DETAIL_ITEMS} 条较旧记录省略,可用 task_operation_list 查看全部)`);
|
|
105
|
+
}
|
|
106
|
+
lines.push("");
|
|
107
|
+
lines.push(`请调用 task_operation_list(task_id=${taskId}) 读取全部新记录,判断是否需要修改你的计划、产出或下一步动作。`);
|
|
108
|
+
lines.push("若这些记录与你的当前工作无关,忽略即可,无需回复。");
|
|
109
|
+
return lines.join(`
|
|
110
|
+
`);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
class TaskOpWatermarkPlugin {
|
|
114
|
+
name = "TaskOpWatermarkPlugin";
|
|
115
|
+
version = "1.0.0";
|
|
116
|
+
description = "Task #5081 — agent:after.tool 水位比对:同一 task 出现他人(sessionId 过滤 + unknown 过滤)新增的 operation 时,经共享 meta-protocol 注入 user role 提醒(N 聚 1 / 限流 5 / 长度 1500 / 15 次兜底对账 / fresh 旁路绕 operationsCache)。";
|
|
117
|
+
priority = 40;
|
|
118
|
+
watermarks = new Map;
|
|
119
|
+
resolveTaskComponent;
|
|
120
|
+
constructor(config) {
|
|
121
|
+
this.resolveTaskComponent = config?.resolveTaskComponent;
|
|
122
|
+
}
|
|
123
|
+
async execute(ctx) {
|
|
124
|
+
try {
|
|
125
|
+
await this.check(ctx);
|
|
126
|
+
} catch (err) {
|
|
127
|
+
logger.warn(`[TaskOpWatermark] check failed (fail-open): ${err?.message}`);
|
|
128
|
+
}
|
|
129
|
+
return { continue: true };
|
|
130
|
+
}
|
|
131
|
+
async check(ctx) {
|
|
132
|
+
const sessionId = ctx.context?.sessionId;
|
|
133
|
+
if (!sessionId)
|
|
134
|
+
return;
|
|
135
|
+
const taskComponent = this.resolveTaskComponent?.();
|
|
136
|
+
if (!taskComponent)
|
|
137
|
+
return;
|
|
138
|
+
const taskIds = await this.resolveTaskIds(taskComponent, sessionId);
|
|
139
|
+
if (taskIds.length === 0)
|
|
140
|
+
return;
|
|
141
|
+
const taskKey = taskIds.join(",");
|
|
142
|
+
let wm = this.watermarks.get(sessionId);
|
|
143
|
+
if (!wm || wm.taskIds.join(",") !== taskKey) {
|
|
144
|
+
wm = {
|
|
145
|
+
lastSeenOpId: 0,
|
|
146
|
+
lastNotifiedOpId: 0,
|
|
147
|
+
taskIds,
|
|
148
|
+
reminderCount: 0,
|
|
149
|
+
toolsSinceAudit: 0
|
|
150
|
+
};
|
|
151
|
+
this.watermarks.set(sessionId, wm);
|
|
152
|
+
}
|
|
153
|
+
wm.toolsSinceAudit++;
|
|
154
|
+
const isAuditTurn = wm.toolsSinceAudit >= TASK_OP_WATERMARK_AUDIT_INTERVAL;
|
|
155
|
+
if (isAuditTurn)
|
|
156
|
+
wm.toolsSinceAudit = 0;
|
|
157
|
+
const lowerBound = isAuditTurn || wm.lastSeenOpId === 0 ? wm.lastNotifiedOpId : wm.lastSeenOpId;
|
|
158
|
+
let newOps = [];
|
|
159
|
+
let maxIdSeen = wm.lastSeenOpId;
|
|
160
|
+
for (const taskId of taskIds) {
|
|
161
|
+
const ops = await this.listOps(taskComponent, taskId);
|
|
162
|
+
const othersNew = ops.filter((op) => op.id > lowerBound && !this.isSelf(op, sessionId));
|
|
163
|
+
for (const op of othersNew) {
|
|
164
|
+
newOps.push(op);
|
|
165
|
+
if (op.id > maxIdSeen)
|
|
166
|
+
maxIdSeen = op.id;
|
|
167
|
+
}
|
|
168
|
+
const selfMax = ops.filter((op) => this.isSelf(op, sessionId)).reduce((m, op) => Math.max(m, op.id), 0);
|
|
169
|
+
maxIdSeen = Math.max(maxIdSeen, selfMax);
|
|
170
|
+
}
|
|
171
|
+
const seen = new Set;
|
|
172
|
+
newOps = newOps.filter((op) => seen.has(op.id) ? false : (seen.add(op.id), true)).sort((a, b) => b.id - a.id);
|
|
173
|
+
wm.lastSeenOpId = Math.max(wm.lastSeenOpId, maxIdSeen);
|
|
174
|
+
if (newOps.length === 0)
|
|
175
|
+
return;
|
|
176
|
+
if (wm.reminderCount >= TASK_OP_WATERMARK_MAX_REMINDERS) {
|
|
177
|
+
logger.info(`[TaskOpWatermark] session=${sessionId.slice(0, 12)}... reminder limit reached (${wm.reminderCount}) — watermark advanced silently`);
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
if (!ctx.toolResult)
|
|
181
|
+
return;
|
|
182
|
+
const byTask = new Map;
|
|
183
|
+
for (const op of newOps) {
|
|
184
|
+
const arr = byTask.get(op.taskId) ?? [];
|
|
185
|
+
arr.push(op);
|
|
186
|
+
byTask.set(op.taskId, arr);
|
|
187
|
+
}
|
|
188
|
+
const sections = [];
|
|
189
|
+
for (const [taskId, ops] of byTask) {
|
|
190
|
+
const title = (await safeGetTask(taskComponent, taskId))?.title;
|
|
191
|
+
sections.push(buildReminderMessage(taskId, title, ops));
|
|
192
|
+
}
|
|
193
|
+
const content = sections.join(`
|
|
194
|
+
|
|
195
|
+
`);
|
|
196
|
+
const finalContent = content.length > TASK_OP_WATERMARK_MESSAGE_LIMIT ? `${content.slice(0, TASK_OP_WATERMARK_MESSAGE_LIMIT - TRUNCATION_SUFFIX.length)}${TRUNCATION_SUFFIX}` : content;
|
|
197
|
+
enqueueToAddFakeUserMessage(ctx.toolResult, { role: "user", content: finalContent }, "task-ops");
|
|
198
|
+
wm.reminderCount++;
|
|
199
|
+
const maxNotified = newOps.reduce((m, op) => Math.max(m, op.id), 0);
|
|
200
|
+
wm.lastNotifiedOpId = Math.max(wm.lastNotifiedOpId, maxNotified);
|
|
201
|
+
logger.info(`[TaskOpWatermark] reminder injected: session=${sessionId.slice(0, 12)}..., tasks=${[...byTask.keys()].join(",")}, newOps=${newOps.length}, reminderCount=${wm.reminderCount}`);
|
|
202
|
+
}
|
|
203
|
+
isSelf(op, sessionId) {
|
|
204
|
+
return op.sessionId === sessionId || op.sessionId === UNKNOWN_SESSION;
|
|
205
|
+
}
|
|
206
|
+
async resolveTaskIds(tc, sessionId) {
|
|
207
|
+
if (typeof tc.getTaskIdsBySessionId === "function") {
|
|
208
|
+
const ids = await tc.getTaskIdsBySessionId(sessionId);
|
|
209
|
+
return Array.isArray(ids) ? ids : [];
|
|
210
|
+
}
|
|
211
|
+
if (typeof tc.getTaskIdBySessionId === "function") {
|
|
212
|
+
const id = await tc.getTaskIdBySessionId(sessionId);
|
|
213
|
+
return typeof id === "number" ? [id] : [];
|
|
214
|
+
}
|
|
215
|
+
return [];
|
|
216
|
+
}
|
|
217
|
+
async listOps(tc, taskId) {
|
|
218
|
+
if (typeof tc.listOperationsFresh === "function") {
|
|
219
|
+
return await tc.listOperationsFresh({ taskId, limit: 50 });
|
|
220
|
+
}
|
|
221
|
+
if (typeof tc.invalidateOperationsCache === "function") {
|
|
222
|
+
tc.invalidateOperationsCache(taskId);
|
|
223
|
+
}
|
|
224
|
+
return await tc.listOperations({ taskId, limit: 50 });
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
async function safeGetTask(tc, taskId) {
|
|
228
|
+
try {
|
|
229
|
+
return await tc.getTask(taskId);
|
|
230
|
+
} catch {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
function createTaskOpWatermarkPlugin(config) {
|
|
235
|
+
const inst = new TaskOpWatermarkPlugin(config);
|
|
236
|
+
return {
|
|
237
|
+
name: inst.name,
|
|
238
|
+
version: inst.version,
|
|
239
|
+
description: inst.description,
|
|
240
|
+
hooks: [{ point: "agent:after.tool", priority: inst.priority }],
|
|
241
|
+
execute: async (ctx) => {
|
|
242
|
+
return inst.execute(ctx);
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export { enqueueToAddFakeUserMessage, TASK_OP_WATERMARK_MAX_REMINDERS, TASK_OP_WATERMARK_MESSAGE_LIMIT, TASK_OP_WATERMARK_AUDIT_INTERVAL, TaskOpWatermarkPlugin, createTaskOpWatermarkPlugin };
|