@ai-setting/roy-agent-cli 1.7.58 → 1.7.59
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/bin/roy-agent.js +140 -15
- package/dist/index.js +140 -15
- package/dist/roy-agent-linux-x64/bin/roy-agent +2 -2
- package/package.json +1 -1
package/dist/bin/roy-agent.js
CHANGED
|
@@ -9639,7 +9639,7 @@ class CliQuietModeService {
|
|
|
9639
9639
|
// package.json
|
|
9640
9640
|
var package_default = {
|
|
9641
9641
|
name: "@ai-setting/roy-agent-cli",
|
|
9642
|
-
version: "1.7.
|
|
9642
|
+
version: "1.7.59",
|
|
9643
9643
|
type: "module",
|
|
9644
9644
|
description: "CLI for roy-agent - Non-interactive command execution",
|
|
9645
9645
|
main: "./dist/index.js",
|
|
@@ -11799,6 +11799,15 @@ function isTelemetryEvent(type) {
|
|
|
11799
11799
|
return false;
|
|
11800
11800
|
return TELEMETRY_EVENT_TYPES.has(type);
|
|
11801
11801
|
}
|
|
11802
|
+
var RULE_NOTICE_EVENT_TYPES = new Set([
|
|
11803
|
+
"task.background.completed",
|
|
11804
|
+
"task.background.timeout"
|
|
11805
|
+
]);
|
|
11806
|
+
function isRuleNoticeEvent(type) {
|
|
11807
|
+
if (!type)
|
|
11808
|
+
return false;
|
|
11809
|
+
return RULE_NOTICE_EVENT_TYPES.has(type);
|
|
11810
|
+
}
|
|
11802
11811
|
var MAX_TITLE_CHARS = 40;
|
|
11803
11812
|
function pad2(n) {
|
|
11804
11813
|
return n < 10 ? `0${n}` : String(n);
|
|
@@ -11871,11 +11880,61 @@ ${parts.join(",")}`;
|
|
|
11871
11880
|
${progressMessage}`;
|
|
11872
11881
|
return text;
|
|
11873
11882
|
}
|
|
11883
|
+
function parseTimeoutMsFromError(error) {
|
|
11884
|
+
if (!error)
|
|
11885
|
+
return;
|
|
11886
|
+
const m = error.match(/timeout after\s+(\d+)\s*ms/i);
|
|
11887
|
+
if (!m)
|
|
11888
|
+
return;
|
|
11889
|
+
const n = Number(m[1]);
|
|
11890
|
+
return Number.isFinite(n) && n > 0 ? n : undefined;
|
|
11891
|
+
}
|
|
11892
|
+
function buildTerminalNoticeText(type, payload) {
|
|
11893
|
+
const p = payload ?? {};
|
|
11894
|
+
const taskId = pickNumber(p.associatedTaskId);
|
|
11895
|
+
const bgId = pickString(p.backgroundTaskId);
|
|
11896
|
+
const desc = truncateTitle(pickString(p.description) ?? "后台任务");
|
|
11897
|
+
let label;
|
|
11898
|
+
if (taskId !== undefined)
|
|
11899
|
+
label = `Task #${taskId}`;
|
|
11900
|
+
else if (bgId)
|
|
11901
|
+
label = bgId;
|
|
11902
|
+
else
|
|
11903
|
+
label = "后台任务";
|
|
11904
|
+
const elapsedMs = pickNumber(p.executionTimeMs);
|
|
11905
|
+
const elapsed = elapsedMs !== undefined ? formatElapsed(elapsedMs) : undefined;
|
|
11906
|
+
if (type === "task.background.timeout") {
|
|
11907
|
+
const timeoutMs = pickNumber(p.timeoutMs) ?? parseTimeoutMsFromError(p.error);
|
|
11908
|
+
const parts = [];
|
|
11909
|
+
if (elapsed)
|
|
11910
|
+
parts.push(`跑了 ${elapsed}`);
|
|
11911
|
+
if (timeoutMs !== undefined)
|
|
11912
|
+
parts.push(`timeout ${formatTimeoutLabel(timeoutMs)}`);
|
|
11913
|
+
const head = `⏱️ ${label}「${desc}」已超时`;
|
|
11914
|
+
return parts.length > 0 ? `${head}(${parts.join(",")})
|
|
11915
|
+
助手随后补充结论与下一步选项。` : `${head}
|
|
11916
|
+
助手随后补充结论与下一步选项。`;
|
|
11917
|
+
}
|
|
11918
|
+
if (type === "task.background.completed") {
|
|
11919
|
+
const head = `✅ ${label}「${desc}」已完成`;
|
|
11920
|
+
return elapsed ? `${head}(耗时 ${elapsed})
|
|
11921
|
+
助手随后补充交付摘要。` : `${head}
|
|
11922
|
+
助手随后补充交付摘要。`;
|
|
11923
|
+
}
|
|
11924
|
+
const bgStatus = type.replace("task.background.", "");
|
|
11925
|
+
return `ℹ️ ${label}「${desc}」${bgStatus}${elapsed ? `(耗时 ${elapsed})` : ""}`;
|
|
11926
|
+
}
|
|
11874
11927
|
var DEFAULT_SEND_TIMEOUT_MS = 5000;
|
|
11875
11928
|
var MAX_IDEMPOTENCY_KEY_LEN = 50;
|
|
11876
11929
|
function deriveTelemetryIdempotencyKey(eventId, chatId) {
|
|
11930
|
+
return deriveNoticeIdempotencyKey("telemetry", eventId, chatId);
|
|
11931
|
+
}
|
|
11932
|
+
function deriveRuleNoticeIdempotencyKey(eventId, chatId) {
|
|
11933
|
+
return deriveNoticeIdempotencyKey("rule", eventId, chatId);
|
|
11934
|
+
}
|
|
11935
|
+
function deriveNoticeIdempotencyKey(namespace, eventId, chatId) {
|
|
11877
11936
|
const anchor = pickString(eventId) ?? `ts-${Date.now()}-${Math.random()}`;
|
|
11878
|
-
return deriveIdempotencyKey([
|
|
11937
|
+
return deriveIdempotencyKey([namespace, anchor, chatId]);
|
|
11879
11938
|
}
|
|
11880
11939
|
function buildLarkSendArgs(input) {
|
|
11881
11940
|
const { chatId, text, profile, idempotencyKey } = input;
|
|
@@ -12181,17 +12240,50 @@ class EventHandler {
|
|
|
12181
12240
|
this.sendTelemetryNotice(event);
|
|
12182
12241
|
return;
|
|
12183
12242
|
}
|
|
12184
|
-
const
|
|
12243
|
+
const ruleNotice = isRuleNoticeEvent(event.type) ? await this.sendRuleNotice(event) : undefined;
|
|
12244
|
+
const formatted = await this.formatEvent(event, { ruleNotice });
|
|
12185
12245
|
this.enqueue(formatted);
|
|
12186
12246
|
}
|
|
12187
|
-
async
|
|
12247
|
+
async resolveNoticeTarget(event) {
|
|
12248
|
+
const metadata = event.metadata;
|
|
12249
|
+
const target = targetFromEventMetadata(metadata);
|
|
12250
|
+
if (target)
|
|
12251
|
+
return target;
|
|
12252
|
+
const triggerEventId = typeof metadata?.triggerEventId === "string" ? metadata.triggerEventId : undefined;
|
|
12253
|
+
return targetFromTriggerEvent(this.eventStore, triggerEventId);
|
|
12254
|
+
}
|
|
12255
|
+
async sendRuleNotice(event) {
|
|
12188
12256
|
try {
|
|
12189
|
-
const
|
|
12190
|
-
let target = targetFromEventMetadata(metadata);
|
|
12257
|
+
const target = await this.resolveNoticeTarget(event);
|
|
12191
12258
|
if (!target) {
|
|
12192
|
-
|
|
12193
|
-
target = await targetFromTriggerEvent(this.eventStore, triggerEventId);
|
|
12259
|
+
return { attempted: true, delivered: false, error: "no-target" };
|
|
12194
12260
|
}
|
|
12261
|
+
const text = buildTerminalNoticeText(event.type, event.payload);
|
|
12262
|
+
await this.telemetrySender({
|
|
12263
|
+
chatId: target.chatId,
|
|
12264
|
+
...target.profile ? { profile: target.profile } : {},
|
|
12265
|
+
text,
|
|
12266
|
+
idempotencyKey: deriveRuleNoticeIdempotencyKey(event.id, target.chatId)
|
|
12267
|
+
});
|
|
12268
|
+
return {
|
|
12269
|
+
attempted: true,
|
|
12270
|
+
delivered: true,
|
|
12271
|
+
chatId: target.chatId,
|
|
12272
|
+
text,
|
|
12273
|
+
sentAt: Date.now()
|
|
12274
|
+
};
|
|
12275
|
+
} catch (err) {
|
|
12276
|
+
console.error(`[EventHandler] rule notice failed (swallowed) type=${event.type}`, err);
|
|
12277
|
+
return {
|
|
12278
|
+
attempted: true,
|
|
12279
|
+
delivered: false,
|
|
12280
|
+
error: err instanceof Error ? err.message : String(err)
|
|
12281
|
+
};
|
|
12282
|
+
}
|
|
12283
|
+
}
|
|
12284
|
+
async sendTelemetryNotice(event) {
|
|
12285
|
+
try {
|
|
12286
|
+
const target = await this.resolveNoticeTarget(event);
|
|
12195
12287
|
if (!target) {
|
|
12196
12288
|
return;
|
|
12197
12289
|
}
|
|
@@ -12206,10 +12298,10 @@ class EventHandler {
|
|
|
12206
12298
|
console.error(`[EventHandler] telemetry notice failed (swallowed) type=${event.type}`, err);
|
|
12207
12299
|
}
|
|
12208
12300
|
}
|
|
12209
|
-
async formatEvent(event) {
|
|
12301
|
+
async formatEvent(event, opts = {}) {
|
|
12210
12302
|
if (NOTIFY_V2_TERMINAL_TYPES.has(event.type) && event.metadata?.triggerEventId && this.eventStore && this.getHandlerForEsType) {
|
|
12211
12303
|
try {
|
|
12212
|
-
const v2Formatted = await this.formatEventViaESPluginV2(event);
|
|
12304
|
+
const v2Formatted = await this.formatEventViaESPluginV2(event, opts.ruleNotice);
|
|
12213
12305
|
if (v2Formatted) {
|
|
12214
12306
|
return v2Formatted;
|
|
12215
12307
|
}
|
|
@@ -12219,7 +12311,26 @@ class EventHandler {
|
|
|
12219
12311
|
}
|
|
12220
12312
|
return this.formatter.formatWithEvent(event);
|
|
12221
12313
|
}
|
|
12222
|
-
|
|
12314
|
+
buildNotifyChannelInfo(triggerEvent, handler, profile) {
|
|
12315
|
+
const meta = triggerEvent.metadata ?? {};
|
|
12316
|
+
const ctx = handler.extractReplyContext?.(triggerEvent, profile);
|
|
12317
|
+
const chatId = ctx?.chatId || meta.chatId || undefined;
|
|
12318
|
+
const messageId = ctx?.messageId || meta.messageId || undefined;
|
|
12319
|
+
const senderId = ctx?.senderOpenId || meta.senderId || undefined;
|
|
12320
|
+
const resolvedProfile = ctx?.profile ?? profile ?? meta.profile;
|
|
12321
|
+
const rawChatType = meta.chatType;
|
|
12322
|
+
const chatType = rawChatType === "group" || rawChatType === "p2p" ? rawChatType : "unknown";
|
|
12323
|
+
return {
|
|
12324
|
+
esType: triggerEvent.esType ?? handler.type,
|
|
12325
|
+
...chatId ? { chatId } : {},
|
|
12326
|
+
chatType,
|
|
12327
|
+
...messageId ? { messageId } : {},
|
|
12328
|
+
...senderId ? { senderId } : {},
|
|
12329
|
+
...resolvedProfile ? { profile: resolvedProfile } : {},
|
|
12330
|
+
replyKind: chatId ? messageId ? "reply" : "send" : "none"
|
|
12331
|
+
};
|
|
12332
|
+
}
|
|
12333
|
+
async formatEventViaESPluginV2(event, ruleNotice) {
|
|
12223
12334
|
const triggerEventId = event.metadata.triggerEventId;
|
|
12224
12335
|
const triggerEvent = await this.eventStore.getEventById(triggerEventId);
|
|
12225
12336
|
if (!triggerEvent) {
|
|
@@ -12234,17 +12345,21 @@ class EventHandler {
|
|
|
12234
12345
|
summary: typeof payload?.result === "string" ? payload.result : typeof payload?.error === "string" ? payload.error : "(无结果)"
|
|
12235
12346
|
};
|
|
12236
12347
|
const profile = triggerEvent.metadata?.profile ?? undefined;
|
|
12348
|
+
const channel = this.buildNotifyChannelInfo(triggerEvent, handler, profile);
|
|
12237
12349
|
const prompt = handler.buildNotifyHandlePrompt({
|
|
12238
12350
|
notifyEvent: {
|
|
12239
12351
|
type: event.type,
|
|
12240
12352
|
taskId: typeof payload?.associatedTaskId === "number" ? payload.associatedTaskId : undefined,
|
|
12241
12353
|
description: typeof payload?.description === "string" ? payload.description : undefined,
|
|
12242
12354
|
result: typeof payload?.result === "string" ? payload.result : undefined,
|
|
12243
|
-
error: typeof payload?.error === "string" ? payload.error : undefined
|
|
12355
|
+
error: typeof payload?.error === "string" ? payload.error : undefined,
|
|
12356
|
+
subSessionId: typeof payload?.subSessionId === "string" ? payload.subSessionId : undefined
|
|
12244
12357
|
},
|
|
12245
12358
|
triggerEvent,
|
|
12246
12359
|
subAgentResult,
|
|
12247
|
-
profile
|
|
12360
|
+
profile,
|
|
12361
|
+
channel,
|
|
12362
|
+
...ruleNotice ? { ruleNotice } : {}
|
|
12248
12363
|
});
|
|
12249
12364
|
if (handler.postProcessNotifyEvent) {
|
|
12250
12365
|
const notifyEventForHook = {
|
|
@@ -12693,6 +12808,14 @@ __legacyDecorateClassTS([
|
|
|
12693
12808
|
]),
|
|
12694
12809
|
__legacyMetadataTS("design:returntype", typeof Promise === "undefined" ? Object : Promise)
|
|
12695
12810
|
], EventHandler.prototype, "handleEvent", null);
|
|
12811
|
+
__legacyDecorateClassTS([
|
|
12812
|
+
TracedAs5("event_handler.rule_notice", { recordParams: true, recordResult: false }),
|
|
12813
|
+
__legacyMetadataTS("design:type", Function),
|
|
12814
|
+
__legacyMetadataTS("design:paramtypes", [
|
|
12815
|
+
typeof EnvEvent === "undefined" ? Object : EnvEvent
|
|
12816
|
+
]),
|
|
12817
|
+
__legacyMetadataTS("design:returntype", typeof Promise === "undefined" ? Object : Promise)
|
|
12818
|
+
], EventHandler.prototype, "sendRuleNotice", null);
|
|
12696
12819
|
__legacyDecorateClassTS([
|
|
12697
12820
|
TracedAs5("event_handler.telemetry_notice", { recordParams: true, recordResult: false }),
|
|
12698
12821
|
__legacyMetadataTS("design:type", Function),
|
|
@@ -12705,7 +12828,8 @@ __legacyDecorateClassTS([
|
|
|
12705
12828
|
TracedAs5("cli.event-handler.formatEvent", { recordParams: true, recordResult: false }),
|
|
12706
12829
|
__legacyMetadataTS("design:type", Function),
|
|
12707
12830
|
__legacyMetadataTS("design:paramtypes", [
|
|
12708
|
-
typeof EnvEvent === "undefined" ? Object : EnvEvent
|
|
12831
|
+
typeof EnvEvent === "undefined" ? Object : EnvEvent,
|
|
12832
|
+
Object
|
|
12709
12833
|
]),
|
|
12710
12834
|
__legacyMetadataTS("design:returntype", typeof Promise === "undefined" ? Object : Promise)
|
|
12711
12835
|
], EventHandler.prototype, "formatEvent", null);
|
|
@@ -12713,7 +12837,8 @@ __legacyDecorateClassTS([
|
|
|
12713
12837
|
TracedAs5("event_handler.process_notify", { recordParams: true, recordResult: false }),
|
|
12714
12838
|
__legacyMetadataTS("design:type", Function),
|
|
12715
12839
|
__legacyMetadataTS("design:paramtypes", [
|
|
12716
|
-
typeof EnvEvent === "undefined" ? Object : EnvEvent
|
|
12840
|
+
typeof EnvEvent === "undefined" ? Object : EnvEvent,
|
|
12841
|
+
typeof RuleNoticeInfo === "undefined" ? Object : RuleNoticeInfo
|
|
12717
12842
|
]),
|
|
12718
12843
|
__legacyMetadataTS("design:returntype", typeof Promise === "undefined" ? Object : Promise)
|
|
12719
12844
|
], EventHandler.prototype, "formatEventViaESPluginV2", null);
|
package/dist/index.js
CHANGED
|
@@ -9638,7 +9638,7 @@ class CliQuietModeService {
|
|
|
9638
9638
|
// package.json
|
|
9639
9639
|
var package_default = {
|
|
9640
9640
|
name: "@ai-setting/roy-agent-cli",
|
|
9641
|
-
version: "1.7.
|
|
9641
|
+
version: "1.7.59",
|
|
9642
9642
|
type: "module",
|
|
9643
9643
|
description: "CLI for roy-agent - Non-interactive command execution",
|
|
9644
9644
|
main: "./dist/index.js",
|
|
@@ -11798,6 +11798,15 @@ function isTelemetryEvent(type) {
|
|
|
11798
11798
|
return false;
|
|
11799
11799
|
return TELEMETRY_EVENT_TYPES.has(type);
|
|
11800
11800
|
}
|
|
11801
|
+
var RULE_NOTICE_EVENT_TYPES = new Set([
|
|
11802
|
+
"task.background.completed",
|
|
11803
|
+
"task.background.timeout"
|
|
11804
|
+
]);
|
|
11805
|
+
function isRuleNoticeEvent(type) {
|
|
11806
|
+
if (!type)
|
|
11807
|
+
return false;
|
|
11808
|
+
return RULE_NOTICE_EVENT_TYPES.has(type);
|
|
11809
|
+
}
|
|
11801
11810
|
var MAX_TITLE_CHARS = 40;
|
|
11802
11811
|
function pad2(n) {
|
|
11803
11812
|
return n < 10 ? `0${n}` : String(n);
|
|
@@ -11870,11 +11879,61 @@ ${parts.join(",")}`;
|
|
|
11870
11879
|
${progressMessage}`;
|
|
11871
11880
|
return text;
|
|
11872
11881
|
}
|
|
11882
|
+
function parseTimeoutMsFromError(error) {
|
|
11883
|
+
if (!error)
|
|
11884
|
+
return;
|
|
11885
|
+
const m = error.match(/timeout after\s+(\d+)\s*ms/i);
|
|
11886
|
+
if (!m)
|
|
11887
|
+
return;
|
|
11888
|
+
const n = Number(m[1]);
|
|
11889
|
+
return Number.isFinite(n) && n > 0 ? n : undefined;
|
|
11890
|
+
}
|
|
11891
|
+
function buildTerminalNoticeText(type, payload) {
|
|
11892
|
+
const p = payload ?? {};
|
|
11893
|
+
const taskId = pickNumber(p.associatedTaskId);
|
|
11894
|
+
const bgId = pickString(p.backgroundTaskId);
|
|
11895
|
+
const desc = truncateTitle(pickString(p.description) ?? "后台任务");
|
|
11896
|
+
let label;
|
|
11897
|
+
if (taskId !== undefined)
|
|
11898
|
+
label = `Task #${taskId}`;
|
|
11899
|
+
else if (bgId)
|
|
11900
|
+
label = bgId;
|
|
11901
|
+
else
|
|
11902
|
+
label = "后台任务";
|
|
11903
|
+
const elapsedMs = pickNumber(p.executionTimeMs);
|
|
11904
|
+
const elapsed = elapsedMs !== undefined ? formatElapsed(elapsedMs) : undefined;
|
|
11905
|
+
if (type === "task.background.timeout") {
|
|
11906
|
+
const timeoutMs = pickNumber(p.timeoutMs) ?? parseTimeoutMsFromError(p.error);
|
|
11907
|
+
const parts = [];
|
|
11908
|
+
if (elapsed)
|
|
11909
|
+
parts.push(`跑了 ${elapsed}`);
|
|
11910
|
+
if (timeoutMs !== undefined)
|
|
11911
|
+
parts.push(`timeout ${formatTimeoutLabel(timeoutMs)}`);
|
|
11912
|
+
const head = `⏱️ ${label}「${desc}」已超时`;
|
|
11913
|
+
return parts.length > 0 ? `${head}(${parts.join(",")})
|
|
11914
|
+
助手随后补充结论与下一步选项。` : `${head}
|
|
11915
|
+
助手随后补充结论与下一步选项。`;
|
|
11916
|
+
}
|
|
11917
|
+
if (type === "task.background.completed") {
|
|
11918
|
+
const head = `✅ ${label}「${desc}」已完成`;
|
|
11919
|
+
return elapsed ? `${head}(耗时 ${elapsed})
|
|
11920
|
+
助手随后补充交付摘要。` : `${head}
|
|
11921
|
+
助手随后补充交付摘要。`;
|
|
11922
|
+
}
|
|
11923
|
+
const bgStatus = type.replace("task.background.", "");
|
|
11924
|
+
return `ℹ️ ${label}「${desc}」${bgStatus}${elapsed ? `(耗时 ${elapsed})` : ""}`;
|
|
11925
|
+
}
|
|
11873
11926
|
var DEFAULT_SEND_TIMEOUT_MS = 5000;
|
|
11874
11927
|
var MAX_IDEMPOTENCY_KEY_LEN = 50;
|
|
11875
11928
|
function deriveTelemetryIdempotencyKey(eventId, chatId) {
|
|
11929
|
+
return deriveNoticeIdempotencyKey("telemetry", eventId, chatId);
|
|
11930
|
+
}
|
|
11931
|
+
function deriveRuleNoticeIdempotencyKey(eventId, chatId) {
|
|
11932
|
+
return deriveNoticeIdempotencyKey("rule", eventId, chatId);
|
|
11933
|
+
}
|
|
11934
|
+
function deriveNoticeIdempotencyKey(namespace, eventId, chatId) {
|
|
11876
11935
|
const anchor = pickString(eventId) ?? `ts-${Date.now()}-${Math.random()}`;
|
|
11877
|
-
return deriveIdempotencyKey([
|
|
11936
|
+
return deriveIdempotencyKey([namespace, anchor, chatId]);
|
|
11878
11937
|
}
|
|
11879
11938
|
function buildLarkSendArgs(input) {
|
|
11880
11939
|
const { chatId, text, profile, idempotencyKey } = input;
|
|
@@ -12180,17 +12239,50 @@ class EventHandler {
|
|
|
12180
12239
|
this.sendTelemetryNotice(event);
|
|
12181
12240
|
return;
|
|
12182
12241
|
}
|
|
12183
|
-
const
|
|
12242
|
+
const ruleNotice = isRuleNoticeEvent(event.type) ? await this.sendRuleNotice(event) : undefined;
|
|
12243
|
+
const formatted = await this.formatEvent(event, { ruleNotice });
|
|
12184
12244
|
this.enqueue(formatted);
|
|
12185
12245
|
}
|
|
12186
|
-
async
|
|
12246
|
+
async resolveNoticeTarget(event) {
|
|
12247
|
+
const metadata = event.metadata;
|
|
12248
|
+
const target = targetFromEventMetadata(metadata);
|
|
12249
|
+
if (target)
|
|
12250
|
+
return target;
|
|
12251
|
+
const triggerEventId = typeof metadata?.triggerEventId === "string" ? metadata.triggerEventId : undefined;
|
|
12252
|
+
return targetFromTriggerEvent(this.eventStore, triggerEventId);
|
|
12253
|
+
}
|
|
12254
|
+
async sendRuleNotice(event) {
|
|
12187
12255
|
try {
|
|
12188
|
-
const
|
|
12189
|
-
let target = targetFromEventMetadata(metadata);
|
|
12256
|
+
const target = await this.resolveNoticeTarget(event);
|
|
12190
12257
|
if (!target) {
|
|
12191
|
-
|
|
12192
|
-
target = await targetFromTriggerEvent(this.eventStore, triggerEventId);
|
|
12258
|
+
return { attempted: true, delivered: false, error: "no-target" };
|
|
12193
12259
|
}
|
|
12260
|
+
const text = buildTerminalNoticeText(event.type, event.payload);
|
|
12261
|
+
await this.telemetrySender({
|
|
12262
|
+
chatId: target.chatId,
|
|
12263
|
+
...target.profile ? { profile: target.profile } : {},
|
|
12264
|
+
text,
|
|
12265
|
+
idempotencyKey: deriveRuleNoticeIdempotencyKey(event.id, target.chatId)
|
|
12266
|
+
});
|
|
12267
|
+
return {
|
|
12268
|
+
attempted: true,
|
|
12269
|
+
delivered: true,
|
|
12270
|
+
chatId: target.chatId,
|
|
12271
|
+
text,
|
|
12272
|
+
sentAt: Date.now()
|
|
12273
|
+
};
|
|
12274
|
+
} catch (err) {
|
|
12275
|
+
console.error(`[EventHandler] rule notice failed (swallowed) type=${event.type}`, err);
|
|
12276
|
+
return {
|
|
12277
|
+
attempted: true,
|
|
12278
|
+
delivered: false,
|
|
12279
|
+
error: err instanceof Error ? err.message : String(err)
|
|
12280
|
+
};
|
|
12281
|
+
}
|
|
12282
|
+
}
|
|
12283
|
+
async sendTelemetryNotice(event) {
|
|
12284
|
+
try {
|
|
12285
|
+
const target = await this.resolveNoticeTarget(event);
|
|
12194
12286
|
if (!target) {
|
|
12195
12287
|
return;
|
|
12196
12288
|
}
|
|
@@ -12205,10 +12297,10 @@ class EventHandler {
|
|
|
12205
12297
|
console.error(`[EventHandler] telemetry notice failed (swallowed) type=${event.type}`, err);
|
|
12206
12298
|
}
|
|
12207
12299
|
}
|
|
12208
|
-
async formatEvent(event) {
|
|
12300
|
+
async formatEvent(event, opts = {}) {
|
|
12209
12301
|
if (NOTIFY_V2_TERMINAL_TYPES.has(event.type) && event.metadata?.triggerEventId && this.eventStore && this.getHandlerForEsType) {
|
|
12210
12302
|
try {
|
|
12211
|
-
const v2Formatted = await this.formatEventViaESPluginV2(event);
|
|
12303
|
+
const v2Formatted = await this.formatEventViaESPluginV2(event, opts.ruleNotice);
|
|
12212
12304
|
if (v2Formatted) {
|
|
12213
12305
|
return v2Formatted;
|
|
12214
12306
|
}
|
|
@@ -12218,7 +12310,26 @@ class EventHandler {
|
|
|
12218
12310
|
}
|
|
12219
12311
|
return this.formatter.formatWithEvent(event);
|
|
12220
12312
|
}
|
|
12221
|
-
|
|
12313
|
+
buildNotifyChannelInfo(triggerEvent, handler, profile) {
|
|
12314
|
+
const meta = triggerEvent.metadata ?? {};
|
|
12315
|
+
const ctx = handler.extractReplyContext?.(triggerEvent, profile);
|
|
12316
|
+
const chatId = ctx?.chatId || meta.chatId || undefined;
|
|
12317
|
+
const messageId = ctx?.messageId || meta.messageId || undefined;
|
|
12318
|
+
const senderId = ctx?.senderOpenId || meta.senderId || undefined;
|
|
12319
|
+
const resolvedProfile = ctx?.profile ?? profile ?? meta.profile;
|
|
12320
|
+
const rawChatType = meta.chatType;
|
|
12321
|
+
const chatType = rawChatType === "group" || rawChatType === "p2p" ? rawChatType : "unknown";
|
|
12322
|
+
return {
|
|
12323
|
+
esType: triggerEvent.esType ?? handler.type,
|
|
12324
|
+
...chatId ? { chatId } : {},
|
|
12325
|
+
chatType,
|
|
12326
|
+
...messageId ? { messageId } : {},
|
|
12327
|
+
...senderId ? { senderId } : {},
|
|
12328
|
+
...resolvedProfile ? { profile: resolvedProfile } : {},
|
|
12329
|
+
replyKind: chatId ? messageId ? "reply" : "send" : "none"
|
|
12330
|
+
};
|
|
12331
|
+
}
|
|
12332
|
+
async formatEventViaESPluginV2(event, ruleNotice) {
|
|
12222
12333
|
const triggerEventId = event.metadata.triggerEventId;
|
|
12223
12334
|
const triggerEvent = await this.eventStore.getEventById(triggerEventId);
|
|
12224
12335
|
if (!triggerEvent) {
|
|
@@ -12233,17 +12344,21 @@ class EventHandler {
|
|
|
12233
12344
|
summary: typeof payload?.result === "string" ? payload.result : typeof payload?.error === "string" ? payload.error : "(无结果)"
|
|
12234
12345
|
};
|
|
12235
12346
|
const profile = triggerEvent.metadata?.profile ?? undefined;
|
|
12347
|
+
const channel = this.buildNotifyChannelInfo(triggerEvent, handler, profile);
|
|
12236
12348
|
const prompt = handler.buildNotifyHandlePrompt({
|
|
12237
12349
|
notifyEvent: {
|
|
12238
12350
|
type: event.type,
|
|
12239
12351
|
taskId: typeof payload?.associatedTaskId === "number" ? payload.associatedTaskId : undefined,
|
|
12240
12352
|
description: typeof payload?.description === "string" ? payload.description : undefined,
|
|
12241
12353
|
result: typeof payload?.result === "string" ? payload.result : undefined,
|
|
12242
|
-
error: typeof payload?.error === "string" ? payload.error : undefined
|
|
12354
|
+
error: typeof payload?.error === "string" ? payload.error : undefined,
|
|
12355
|
+
subSessionId: typeof payload?.subSessionId === "string" ? payload.subSessionId : undefined
|
|
12243
12356
|
},
|
|
12244
12357
|
triggerEvent,
|
|
12245
12358
|
subAgentResult,
|
|
12246
|
-
profile
|
|
12359
|
+
profile,
|
|
12360
|
+
channel,
|
|
12361
|
+
...ruleNotice ? { ruleNotice } : {}
|
|
12247
12362
|
});
|
|
12248
12363
|
if (handler.postProcessNotifyEvent) {
|
|
12249
12364
|
const notifyEventForHook = {
|
|
@@ -12692,6 +12807,14 @@ __legacyDecorateClassTS([
|
|
|
12692
12807
|
]),
|
|
12693
12808
|
__legacyMetadataTS("design:returntype", typeof Promise === "undefined" ? Object : Promise)
|
|
12694
12809
|
], EventHandler.prototype, "handleEvent", null);
|
|
12810
|
+
__legacyDecorateClassTS([
|
|
12811
|
+
TracedAs5("event_handler.rule_notice", { recordParams: true, recordResult: false }),
|
|
12812
|
+
__legacyMetadataTS("design:type", Function),
|
|
12813
|
+
__legacyMetadataTS("design:paramtypes", [
|
|
12814
|
+
typeof EnvEvent === "undefined" ? Object : EnvEvent
|
|
12815
|
+
]),
|
|
12816
|
+
__legacyMetadataTS("design:returntype", typeof Promise === "undefined" ? Object : Promise)
|
|
12817
|
+
], EventHandler.prototype, "sendRuleNotice", null);
|
|
12695
12818
|
__legacyDecorateClassTS([
|
|
12696
12819
|
TracedAs5("event_handler.telemetry_notice", { recordParams: true, recordResult: false }),
|
|
12697
12820
|
__legacyMetadataTS("design:type", Function),
|
|
@@ -12704,7 +12827,8 @@ __legacyDecorateClassTS([
|
|
|
12704
12827
|
TracedAs5("cli.event-handler.formatEvent", { recordParams: true, recordResult: false }),
|
|
12705
12828
|
__legacyMetadataTS("design:type", Function),
|
|
12706
12829
|
__legacyMetadataTS("design:paramtypes", [
|
|
12707
|
-
typeof EnvEvent === "undefined" ? Object : EnvEvent
|
|
12830
|
+
typeof EnvEvent === "undefined" ? Object : EnvEvent,
|
|
12831
|
+
Object
|
|
12708
12832
|
]),
|
|
12709
12833
|
__legacyMetadataTS("design:returntype", typeof Promise === "undefined" ? Object : Promise)
|
|
12710
12834
|
], EventHandler.prototype, "formatEvent", null);
|
|
@@ -12712,7 +12836,8 @@ __legacyDecorateClassTS([
|
|
|
12712
12836
|
TracedAs5("event_handler.process_notify", { recordParams: true, recordResult: false }),
|
|
12713
12837
|
__legacyMetadataTS("design:type", Function),
|
|
12714
12838
|
__legacyMetadataTS("design:paramtypes", [
|
|
12715
|
-
typeof EnvEvent === "undefined" ? Object : EnvEvent
|
|
12839
|
+
typeof EnvEvent === "undefined" ? Object : EnvEvent,
|
|
12840
|
+
typeof RuleNoticeInfo === "undefined" ? Object : RuleNoticeInfo
|
|
12716
12841
|
]),
|
|
12717
12842
|
__legacyMetadataTS("design:returntype", typeof Promise === "undefined" ? Object : Promise)
|
|
12718
12843
|
], EventHandler.prototype, "formatEventViaESPluginV2", null);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
[diffend] Oversized file quarantined before diffing.
|
|
2
2
|
name: package/dist/roy-agent-linux-x64/bin/roy-agent
|
|
3
|
-
size:
|
|
4
|
-
sha256:
|
|
3
|
+
size: 109906048 bytes
|
|
4
|
+
sha256: a97336c59bd5ce3cada998cc8b03fec204414ec9ecc0995b494c0a3f6613d1b2
|