@ai-setting/roy-agent-core 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/env/event-source/event-source-handlers.d.ts +11 -1
- package/dist/env/event-source/index.d.ts +1 -1
- package/dist/env/event-source/index.js +1 -1
- package/dist/env/event-source/types.d.ts +68 -0
- package/dist/env/index.d.ts +1 -1
- package/dist/env/index.js +1 -1
- package/dist/index.js +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-fy4mcj6x.js → roy-agent-core-6q5m1qk5.js} +53 -15
- package/package.json +1 -1
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* 支持通过 handleRule.plugins 加载外部 Plugin
|
|
6
6
|
*/
|
|
7
7
|
import { ChildProcess } from "child_process";
|
|
8
|
-
import type { EventSourceConfig, EventSourceHandler, EventSourceInstance, EventSourceStatus, EventSourceEventHandler, EventMetadata, ReplyChannel, RecommendedAction } from "./types";
|
|
8
|
+
import type { EventSourceConfig, EventSourceHandler, EventSourceInstance, EventSourceStatus, EventSourceEventHandler, EventMetadata, ReplyChannel, RecommendedAction, RuleNoticeInfo } from "./types";
|
|
9
9
|
import { timerHandler } from "./timer-handler";
|
|
10
10
|
import { bountyIMHandler } from "./bounty-im-handler";
|
|
11
11
|
import { bountyCliHandler } from "./bounty-cli-handler";
|
|
@@ -469,6 +469,16 @@ export declare class LarkCliInstance implements EventSourceInstance {
|
|
|
469
469
|
*/
|
|
470
470
|
private sendLarkMessage;
|
|
471
471
|
}
|
|
472
|
+
/**
|
|
473
|
+
* 渲染「系统回执」小节 —— 告诉主 agent:群里**已经**看到了什么。
|
|
474
|
+
*
|
|
475
|
+
* 三种状态必须分开,否则 agent 会二选一地犯两种错:
|
|
476
|
+
* - 已送达却把「已超时」再讲一遍 → 重复刷屏
|
|
477
|
+
* - 未送达却以为发了 → 用户永远不知道任务结束了(正是 #4561 的现场)
|
|
478
|
+
*
|
|
479
|
+
* @param headline 事件标题句(未送达时要求 agent 自己讲清这个事实)
|
|
480
|
+
*/
|
|
481
|
+
export declare function renderRuleNoticeSection(ruleNotice: RuleNoticeInfo | undefined, headline: string): string;
|
|
472
482
|
/**
|
|
473
483
|
* LarkCli Handler
|
|
474
484
|
*/
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 导出所有 EventSource 相关的类型、类和函数
|
|
5
5
|
*/
|
|
6
|
-
export type { EventSourceStatus, EventSourceType, EventSourceConfig, EventMetadata, RecommendedAction, ReplyChannel, EventSourceEventPayload, EventSourceEvent, EventSourceEventHandler, EventSourceStatusChangeEvent, EventSourcePersistenceConfig, EventSourceInstance, EventSourceHandler, EventSourceInitHook, EventSourceComponentInterface, EventSourceAgentHandlerConfig, } from "./types";
|
|
6
|
+
export type { EventSourceStatus, EventSourceType, EventSourceConfig, EventMetadata, RecommendedAction, ReplyChannel, EventSourceEventPayload, EventSourceEvent, EventSourceEventHandler, EventSourceStatusChangeEvent, EventSourcePersistenceConfig, EventSourceInstance, EventSourceHandler, EventSourceInitHook, EventSourceComponentInterface, EventSourceAgentHandlerConfig, NotifyChannelInfo, RuleNoticeInfo, } from "./types";
|
|
7
7
|
export { EventSourceInitHooks } from "./types";
|
|
8
8
|
export { BUILT_IN_EVENT_SOURCE_TYPES, BUILT_IN_EVENT_SOURCE_TYPE_LIST } from "./types";
|
|
9
9
|
export { isBuiltInEventSourceType, isValidEventSourceType, getDefaultConfigForType, validateEventSourceConfig, } from "./types";
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
larkCliHandler,
|
|
12
12
|
resolveBountyIMSystemPrompt,
|
|
13
13
|
timerHandler
|
|
14
|
-
} from "../../shared/@ai-setting/roy-agent-core-
|
|
14
|
+
} from "../../shared/@ai-setting/roy-agent-core-6q5m1qk5.js";
|
|
15
15
|
import {
|
|
16
16
|
BUILT_IN_EVENT_SOURCE_TYPES,
|
|
17
17
|
BUILT_IN_EVENT_SOURCE_TYPE_LIST,
|
|
@@ -580,6 +580,55 @@ export interface ReplyContext {
|
|
|
580
580
|
/** lark-cli profile(用于 im +messages-reply --profile) */
|
|
581
581
|
profile?: string;
|
|
582
582
|
}
|
|
583
|
+
/**
|
|
584
|
+
* 触发渠道信息(渠道无关的最小集合)。
|
|
585
|
+
*
|
|
586
|
+
* 由 CLI EventHandler 从 trigger event + handler.extractReplyContext 解析后
|
|
587
|
+
* 传给 buildNotifyHandlePrompt,让 prompt 能按**真实渠道**渲染:
|
|
588
|
+
* - 渠道类型(lark-cli / bounty-im / timer / ...)
|
|
589
|
+
* - 群 ID / 群聊还是私聊
|
|
590
|
+
* - 触发消息 ID、发送者、profile
|
|
591
|
+
*
|
|
592
|
+
* ★ 为什么不让每个 handler 自己从 triggerEvent 里抠字段:
|
|
593
|
+
* bounty-im 用 from/to 邮箱、lark 用 chatId/messageId,字段名完全不同;
|
|
594
|
+
* 统一在这里归一化,handler 只负责渲染「怎么发」。
|
|
595
|
+
*/
|
|
596
|
+
export interface NotifyChannelInfo {
|
|
597
|
+
/** EventSource 类型(lark-cli / bounty-im / timer / ...) */
|
|
598
|
+
esType: string;
|
|
599
|
+
/** 回复目标会话 ID(飞书为 oc_xxx) */
|
|
600
|
+
chatId?: string;
|
|
601
|
+
/** 群聊 / 私聊 / 未知(飞书 trigger event metadata.chatType) */
|
|
602
|
+
chatType?: "group" | "p2p" | "unknown";
|
|
603
|
+
/** 触发消息 ID(飞书为 om_xxx);reply 这条可保持话题线索 */
|
|
604
|
+
messageId?: string;
|
|
605
|
+
/** 触发者 ID(飞书为 ou_xxx) */
|
|
606
|
+
senderId?: string;
|
|
607
|
+
/** 多 appId 场景的 lark-cli profile */
|
|
608
|
+
profile?: string;
|
|
609
|
+
/** 回复方式:reply=回复触发消息 / send=新消息 / none=无可用通道 */
|
|
610
|
+
replyKind?: "reply" | "send" | "none";
|
|
611
|
+
}
|
|
612
|
+
/**
|
|
613
|
+
* 规则化回执(rule-based direct notice)的投递结果。
|
|
614
|
+
*
|
|
615
|
+
* 终态事件(completed / timeout)在进 lane 之前,会先用 telemetry 同一套
|
|
616
|
+
* 发送器直发一条**保底**消息到触发群;这里把「发没发出去」如实带给主 agent,
|
|
617
|
+
* 避免 prompt 谎称「已发送」而 agent 又重复/遗漏关键信息。
|
|
618
|
+
*/
|
|
619
|
+
export interface RuleNoticeInfo {
|
|
620
|
+
/** 是否尝试过直发(false = 该事件类型不在规则回执白名单) */
|
|
621
|
+
attempted: boolean;
|
|
622
|
+
/** 是否确实送到群里 */
|
|
623
|
+
delivered: boolean;
|
|
624
|
+
chatId?: string;
|
|
625
|
+
/** 实际发出的文案(送达时带,便于 prompt 里告知「回执已经说了什么」) */
|
|
626
|
+
text?: string;
|
|
627
|
+
/** 送达时刻(epoch ms) */
|
|
628
|
+
sentAt?: number;
|
|
629
|
+
/** 失败原因(未送达时带) */
|
|
630
|
+
error?: string;
|
|
631
|
+
}
|
|
583
632
|
/**
|
|
584
633
|
* buildNotifyHandlePrompt 输入
|
|
585
634
|
*/
|
|
@@ -591,6 +640,12 @@ export interface BuildNotifyHandlePromptInput {
|
|
|
591
640
|
description?: string;
|
|
592
641
|
result?: string;
|
|
593
642
|
error?: string;
|
|
643
|
+
/**
|
|
644
|
+
* 子 session ID —— 超时 / 失败后如需**续跑**,主 agent 可直接
|
|
645
|
+
* `delegate_task(existingSubSessionId=<此值>, ...)` 让子代理继承历史继续推进,
|
|
646
|
+
* 不必从零重来。
|
|
647
|
+
*/
|
|
648
|
+
subSessionId?: string;
|
|
594
649
|
};
|
|
595
650
|
/** 触发整个 delegate_task 的原始 event(从 EventStore 反查) */
|
|
596
651
|
triggerEvent: PersistedEvent;
|
|
@@ -605,6 +660,19 @@ export interface BuildNotifyHandlePromptInput {
|
|
|
605
660
|
* 让主 agent 拿到的回复命令带上正确的 `--profile`。
|
|
606
661
|
*/
|
|
607
662
|
profile?: string;
|
|
663
|
+
/**
|
|
664
|
+
* 触发渠道信息(渠道无关,由调用方归一化后传入)。
|
|
665
|
+
*
|
|
666
|
+
* 缺省时 handler 自行从 triggerEvent 反查(向后兼容)。
|
|
667
|
+
*/
|
|
668
|
+
channel?: NotifyChannelInfo;
|
|
669
|
+
/**
|
|
670
|
+
* 规则化回执的投递结果。
|
|
671
|
+
*
|
|
672
|
+
* 缺省 = 本事件不直发回执(如 failed / stopped / ask_user),
|
|
673
|
+
* prompt 需要引导 agent 把结果完整讲清楚。
|
|
674
|
+
*/
|
|
675
|
+
ruleNotice?: RuleNoticeInfo;
|
|
608
676
|
}
|
|
609
677
|
/**
|
|
610
678
|
* buildNotifyHandlePrompt 输出
|
package/dist/env/index.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export type { Task, TaskOperation, TaskStatus, TaskPriority, ActionType, CreateT
|
|
|
16
16
|
export { McpComponent, } from "./mcp";
|
|
17
17
|
export type { McpComponentConfig, McpComponentOptions, McpPath, McpServerConfig, McpServerStatus, DiscoveredMcpServer, } from "./mcp";
|
|
18
18
|
export { EventSourceComponent, larkCliHandler, builtInHandlers, } from "./event-source/event-source-component";
|
|
19
|
-
export type { EventSourceConfig, EventSourceStatus, EventSourceType, EventSourceEvent, EventSourceEventPayload, EventSourceEventHandler, EventSourceStatusChangeEvent, EventSourcePersistenceConfig, EventSourceComponentInterface, EventSourceHandler, EventSourceInstance, EventSourceAgentHandlerConfig, BUILT_IN_EVENT_SOURCE_TYPES, } from "./event-source/types";
|
|
19
|
+
export type { EventSourceConfig, EventSourceStatus, EventSourceType, EventSourceEvent, EventSourceEventPayload, EventSourceEventHandler, EventSourceStatusChangeEvent, EventSourcePersistenceConfig, EventSourceComponentInterface, EventSourceHandler, EventSourceInstance, EventSourceAgentHandlerConfig, NotifyChannelInfo, RuleNoticeInfo, BUILT_IN_EVENT_SOURCE_TYPES, } from "./event-source/types";
|
|
20
20
|
export { EventSourceInitHooks, isValidEventSourceType, isBuiltInEventSourceType, getDefaultConfigForType, validateEventSourceConfig, } from "./event-source/types";
|
|
21
21
|
export { WorkflowComponent, } from "./workflow/workflow-component";
|
|
22
22
|
export type { WorkflowComponentConfig, } from "./workflow/workflow-component";
|
package/dist/env/index.js
CHANGED
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
EventSourceComponent,
|
|
16
16
|
builtInHandlers,
|
|
17
17
|
larkCliHandler
|
|
18
|
-
} from "../shared/@ai-setting/roy-agent-core-
|
|
18
|
+
} from "../shared/@ai-setting/roy-agent-core-6q5m1qk5.js";
|
|
19
19
|
import {
|
|
20
20
|
EventSourceInitHooks,
|
|
21
21
|
getDefaultConfigForType,
|
package/dist/index.js
CHANGED
|
@@ -83,7 +83,7 @@ import {
|
|
|
83
83
|
larkCliHandler,
|
|
84
84
|
resolveBountyIMSystemPrompt,
|
|
85
85
|
timerHandler
|
|
86
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
86
|
+
} from "./shared/@ai-setting/roy-agent-core-6q5m1qk5.js";
|
|
87
87
|
import {
|
|
88
88
|
BUILT_IN_EVENT_SOURCE_TYPES,
|
|
89
89
|
BUILT_IN_EVENT_SOURCE_TYPE_LIST,
|
|
@@ -2621,6 +2621,24 @@ function describeNotifyEvent(type, taskId, desc) {
|
|
|
2621
2621
|
return { headline: `Sub-agent 更新了 Task #${taskId}「${desc}」。`, actionable };
|
|
2622
2622
|
}
|
|
2623
2623
|
}
|
|
2624
|
+
function renderRuleNoticeSection(ruleNotice, headline) {
|
|
2625
|
+
if (!ruleNotice || !ruleNotice.attempted) {
|
|
2626
|
+
return `(本事件不直发规则回执)
|
|
2627
|
+
` + `→ 你的回复要把结果讲**完整**(用户只能从你这条消息知道结论)。`;
|
|
2628
|
+
}
|
|
2629
|
+
if (ruleNotice.delivered) {
|
|
2630
|
+
const when = ruleNotice.sentAt ? new Date(ruleNotice.sentAt).toLocaleTimeString("zh-CN", {
|
|
2631
|
+
hour12: false,
|
|
2632
|
+
hour: "2-digit",
|
|
2633
|
+
minute: "2-digit"
|
|
2634
|
+
}) : "";
|
|
2635
|
+
const sent = ruleNotice.text ? `:「${ruleNotice.text.replace(/\s*\n+\s*/g, " ")}」` : "";
|
|
2636
|
+
return `✅ 系统已于 ${when || "刚才"} 把下面这条发到群里${sent}
|
|
2637
|
+
` + `→ 你的回复**只发增量**:不要再重复「任务已结束」这类回执原文,` + `直接讲结论/交付 + 下一步选项。`;
|
|
2638
|
+
}
|
|
2639
|
+
return `❌ **回执未送达**(原因:${ruleNotice.error ?? "unknown"})
|
|
2640
|
+
` + `→ 用户目前**还不知道**「${headline}」这件事,必须由你在回复里讲清楚,` + `并且不要假装系统已经通知过。`;
|
|
2641
|
+
}
|
|
2624
2642
|
var larkCliHandler = {
|
|
2625
2643
|
type: "lark-cli",
|
|
2626
2644
|
validateConfig(config) {
|
|
@@ -2683,47 +2701,67 @@ var larkCliHandler = {
|
|
|
2683
2701
|
senderOpenId: input.triggerEvent.metadata?.senderId ?? input.triggerEvent.senderId,
|
|
2684
2702
|
profile: input.profile
|
|
2685
2703
|
};
|
|
2686
|
-
const
|
|
2704
|
+
const esType = input.channel?.esType ?? ctx.esType ?? "lark-cli";
|
|
2705
|
+
const chatId = input.channel?.chatId || ctx.chatId;
|
|
2706
|
+
const messageId = input.channel?.messageId || ctx.messageId;
|
|
2707
|
+
const senderId = input.channel?.senderId || ctx.senderOpenId;
|
|
2708
|
+
const chatType = input.channel?.chatType ?? "unknown";
|
|
2709
|
+
const profile = input.channel?.profile ?? ctx.profile;
|
|
2710
|
+
const profileFlag = profile ? `--profile ${profile} ` : "";
|
|
2687
2711
|
const desc = input.notifyEvent.description ?? "(未命名任务)";
|
|
2688
2712
|
const result = input.subAgentResult.summary ?? input.notifyEvent.result ?? "";
|
|
2689
2713
|
const notifyType = input.notifyEvent.type;
|
|
2690
2714
|
const taskId = input.notifyEvent.taskId ?? "?";
|
|
2691
2715
|
const { headline, actionable } = describeNotifyEvent(notifyType, taskId, desc);
|
|
2716
|
+
const chatTypeLabel = chatType === "group" ? "群聊" : chatType === "p2p" ? "私聊" : "会话类型未知";
|
|
2717
|
+
const canReply = Boolean(chatId);
|
|
2718
|
+
const receiptSection = renderRuleNoticeSection(input.ruleNotice, headline);
|
|
2719
|
+
const replyCommand = messageId ? `lark-cli ${profileFlag}im +messages-reply --message-id ${messageId} --chat-id ${chatId} --as bot --markdown '<你的回复>'` : `lark-cli ${profileFlag}im +messages-send --chat-id ${chatId} --as bot --markdown '<你的回复>'`;
|
|
2720
|
+
const scopeWord = chatType === "group" ? "群聊" : chatType === "p2p" ? "私聊" : "会话";
|
|
2692
2721
|
const promptText = actionable ? `
|
|
2693
2722
|
## Notify Event: ${notifyType}
|
|
2694
2723
|
|
|
2695
2724
|
${headline}
|
|
2696
2725
|
|
|
2697
|
-
###
|
|
2698
|
-
- ES:
|
|
2699
|
-
- **chatId: ${
|
|
2700
|
-
- **messageId: ${
|
|
2701
|
-
- sender: ${
|
|
2702
|
-
${
|
|
2726
|
+
### 触发渠道(EventSource)
|
|
2727
|
+
- ES: ${esType}(飞书,${chatTypeLabel})
|
|
2728
|
+
- **chatId: ${chatId || "(缺失)"}** ← 关键!必须发到这里
|
|
2729
|
+
- **messageId: ${messageId || "(缺失)"}** ← ${messageId ? "reply 这条,保持话题线索" : "无触发消息,用 +messages-send"}
|
|
2730
|
+
- sender: ${senderId || "(未知)"}
|
|
2731
|
+
${input.notifyEvent.subSessionId ? `- 子 session: ${input.notifyEvent.subSessionId} ← 如需续跑:delegate_task(existingSubSessionId=<此值>, prompt=<新要求>)
|
|
2732
|
+
` : ""}${profile ? `- profile: ${profile} ← 调用 lark-cli 必须带 --profile
|
|
2703
2733
|
` : ""}
|
|
2734
|
+
### 系统回执(rule-based 直发)
|
|
2735
|
+
${receiptSection}
|
|
2736
|
+
|
|
2704
2737
|
### Sub-agent 输出
|
|
2705
2738
|
${result}
|
|
2706
2739
|
|
|
2707
|
-
### \uD83D\uDC49
|
|
2708
|
-
用
|
|
2709
|
-
|
|
2740
|
+
### \uD83D\uDC49 你要做什么
|
|
2741
|
+
1. 用 2~5 行总结:这次完成了什么 / 卡在哪(依据上面的输出与子 session)
|
|
2742
|
+
2. 给出 1~3 个下一步选项(继续推进 / 拆小 / 放弃),并**问用户选哪个**
|
|
2743
|
+
3. 用 lark-cli 把回复发到上面的${scopeWord}(见下)
|
|
2744
|
+
|
|
2745
|
+
### 发送方式(渠道 = lark-cli)
|
|
2746
|
+
${canReply ? ` ${replyCommand}` : `⚠️ 没有可用的 chatId —— 无法投递到触发会话。请在会话内汇报,并说明「未投递」的原因。`}
|
|
2710
2747
|
|
|
2711
2748
|
⚠️ 不要 fallback 到 lastReplyChannel 或 metadata.replyChannel — 那个 chatId
|
|
2712
2749
|
可能跟用户原始消息的 chatId 不一致(参见 #4035/#4038/#4039 bug)。
|
|
2750
|
+
⚠️ 必须 --as bot(否则会被自己的 lark-cli consumer 当用户消息回灌);不要用 user 身份。
|
|
2713
2751
|
` : `
|
|
2714
2752
|
## Notify Event: ${notifyType}
|
|
2715
2753
|
|
|
2716
2754
|
${headline}
|
|
2717
2755
|
|
|
2718
|
-
###
|
|
2719
|
-
- ES:
|
|
2720
|
-
- chatId: ${
|
|
2721
|
-
- messageId: ${
|
|
2756
|
+
### 触发渠道(EventSource)
|
|
2757
|
+
- ES: ${esType}(${chatTypeLabel})
|
|
2758
|
+
- chatId: ${chatId || "(缺失)"}
|
|
2759
|
+
- messageId: ${messageId || "(缺失)"}
|
|
2722
2760
|
|
|
2723
2761
|
(这是中间态通知:仅作状态同步,**不要**回复用户,也不要调用 lark-cli 发消息。
|
|
2724
2762
|
等收到 task.background.completed / failed / timeout / stopped 终态通知后再回复。)
|
|
2725
2763
|
`;
|
|
2726
|
-
const systemHint = actionable ? `回复必须用 lark-cli im +messages-reply(${profileFlag.trim() ? `带 ${profileFlag.trim()};` : ""}` + `chatId=${
|
|
2764
|
+
const systemHint = actionable ? `回复必须用 lark-cli im +messages-reply(${profileFlag.trim() ? `带 ${profileFlag.trim()};` : ""}` + `chatId=${chatId} / messageId=${messageId} 来自 trigger event(esType=${esType}),不要 fallback。` + (input.ruleNotice?.delivered ? "系统回执已送达,只发增量。" : "") : `这是 ${notifyType} 中间态通知,不要回复用户;仅等待终态通知。`;
|
|
2727
2765
|
return { promptText, systemHint };
|
|
2728
2766
|
},
|
|
2729
2767
|
setRunner(runner) {
|