@ai-setting/roy-agent-core 1.7.35 → 1.7.36

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.
@@ -11,7 +11,7 @@ import {
11
11
  larkCliHandler,
12
12
  resolveBountyIMSystemPrompt,
13
13
  timerHandler
14
- } from "../../shared/@ai-setting/roy-agent-core-242peyss.js";
14
+ } from "../../shared/@ai-setting/roy-agent-core-tft0pa6h.js";
15
15
  import"../../shared/@ai-setting/roy-agent-core-1dacps3n.js";
16
16
  import {
17
17
  BUILT_IN_EVENT_SOURCE_TYPES,
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-242peyss.js";
18
+ } from "../shared/@ai-setting/roy-agent-core-tft0pa6h.js";
19
19
  import"../shared/@ai-setting/roy-agent-core-1dacps3n.js";
20
20
  import {
21
21
  EventSourceInitHooks,
package/dist/index.js CHANGED
@@ -92,7 +92,7 @@ import {
92
92
  larkCliHandler,
93
93
  resolveBountyIMSystemPrompt,
94
94
  timerHandler
95
- } from "./shared/@ai-setting/roy-agent-core-242peyss.js";
95
+ } from "./shared/@ai-setting/roy-agent-core-tft0pa6h.js";
96
96
  import {
97
97
  LogTraceComponent,
98
98
  LogTraceConfigSchema
@@ -864,55 +864,49 @@ function buildLarkRecommendedAction(opts) {
864
864
  const profileFlag = profile ? `--profile ${profile} ` : "";
865
865
  const profileWarn = profile ? `(⚠️ 必须用 profile="${profile}" 调 lark-cli;openId per-app 隔离,换 profile 会失败)` : "";
866
866
  const isGroup = chatType === "group";
867
- const scopeHint = isGroup ? `群聊消息;回复到 replyTo.chatId。如需 @mention 发件人,请在 Markdown 正文开头加空闭合的 <at user_id="<senderId>"></at>(飞书只认这种语法,自闭合的 <at user_id="<senderId>"/> 不工作,会渲染成原始标签文本)。` : "p2p 私聊消息;回复到 replyTo.chatId";
867
+ const scopeHint = isGroup ? `群聊消息;回复到 replyTo.chatId。如需 @发件人,用结构化 at 节点 {"tag":"at","user_id":"<senderId>"}(不要写 <at> 文本标签)` : "p2p 私聊消息;回复到 replyTo.chatId";
868
868
  const scopeWord = isGroup ? "群聊" : "p2p 私聊";
869
869
  const action = [
870
870
  `处理飞书 ${scopeWord}消息并以机器人身份回复${profileWarn}。`,
871
871
  `scope: ${scopeHint}。`,
872
872
  ``,
873
- `## ⭐ 关键 1: 所有飞书回复必须用 --markdown flag (不要用 --text, 也不要裸调用)`,
874
- `lark-cli 默认会让消息渲染成 plain text — 你的 Markdown 标签 (<at> mention、列表、`,
875
- `**bold**、code block、表格等) 会被当成字面字符显示, 用户看到的就是`,
876
- `一堆 raw 符号, 完全没法用。`,
877
- `正确做法: 调 im +messages-{send,reply} 时必须显式加 --markdown <content>,`,
878
- `飞书才会按 Markdown 渲染 rich format。`,
879
- `**严禁**: 使用 --text flag (直接导致 rich format 失效, 是最常见的回归路径)`,
880
- ` 使用 --msg-type text (同理, --msg-type post 也可以但需对应结构,`,
881
- ` 最稳的仍然是 --markdown flag)`,
882
- ` 不加任何 content flag (会按 plain text 默认值处理)`,
873
+ `## ⭐ 关键 1: 飞书回复必须用结构化 post content(--msg-type post --content)`,
874
+ `lark-cli 默认把消息当 plain text;而 @mention 只有在**结构化 at 节点**里才会被`,
875
+ `飞书识别为真实 @。所以回复统一走 post 的 --content JSON:`,
883
876
  ``,
884
- `## ⭐ 关键 2: @-mention 必须用空闭合标签 <at user_id="ou_xxx"></at>`,
885
- `飞书只识别空闭合形式: <at user_id="ou_xxx"></at> (开始标签 + 结束标签, 中间为空)。`,
886
- `自闭合形式 <at user_id="ou_xxx"/> 飞书不解析, 用户会看到原始 <at> 标签字面字符,`,
887
- `跟 plain text 一样坏掉 — mention 完全失效。`,
877
+ ` {"zh_cn":{"content":[`,
878
+ ` [ {"tag":"at","user_id":"ou_xxx"} ], // @某人:结构化节点(可多个/多段)`,
879
+ ` [ {"tag":"md","text":"正文 Markdown(标题/表格/加粗都支持)"} ] // 正文:单个 md 节点`,
880
+ ` ]}}`,
888
881
  ``,
889
- `正确示例 (群聊 @发件人):`,
890
- ` <at user_id="ou_1759934f98e0677e17f09591389c24f1"></at> 这里写正文内容`,
882
+ `- @mention:用 {"tag":"at","user_id":"ou_xxx"}(user_id 填对方 open_id;@所有人填 "all")`,
883
+ `- 正文:全部放进 {"tag":"md","text":"..."} 这一个节点里`,
884
+ `- 不需要 @ 时,content 里只放 md 节点:{"zh_cn":{"content":[[{"tag":"md","text":"..."}]]}}`,
885
+ `**严禁**: 用 --text(plain text,Markdown 全部失效)`,
886
+ ` 用 --markdown(无法携带结构化 at 节点,@ 会退化成普通文本)`,
887
+ ` 在正文里写 <at user_id="ou_xxx"/> 或 <at user_id="ou_xxx"></at> 文本标签`,
888
+ ` (飞书不识别文本标签,只认结构化 at 节点;写文本标签会显示成原始字符)`,
891
889
  ``,
892
- `**严禁**: 自闭合形式 <at user_id="ou_xxx"/>`,
893
- `**严禁**: 反引号/HTML entity 转义 (&lt;at&gt; / <at>)`,
894
- `**严禁**: 不用 <at> 直接 @userId 字符串 (飞书当成普通文本)`,
890
+ `## 关键 2: 安全构造 content(照抄,避免 JSON 转义地狱)`,
891
+ `把 Markdown 正文写进临时文件,再用 jq 组装(jq 会自动把换行转义为反斜杠+n):`,
895
892
  ``,
896
- `## 安全传 Markdown(必读,避免飞书收到字面 $ 和字面反斜杠+n)`,
897
- `多行 / 复杂 Markdown 必须先写入临时 .md 文件,再 cat 出来当 --markdown 的值。`,
898
- `原因:agent 工具调用层不做 shell 展开。`,
899
- ``,
900
- `推荐调用模板(4 步缺一不可,照抄):`,
901
- ` reply_file="$(mktemp /tmp/lark-reply.XXXXXX.md)" # 1. 唯一文件名(避免并发覆盖)`,
902
- ` trap 'rm -f "$reply_file"' EXIT # 2. 注册退出清理(无论成败都删,避免 /tmp 累积)`,
903
- ` cat > "$reply_file" <<'LARK_REPLY_EOF' # 3. 写入 Markdown(heredoc 单引号防 shell 展开)`,
904
- ` ...(这里是回复的 Markdown 内容,可以多行 / 含特殊字符)`,
893
+ ` body_file="$(mktemp /tmp/lark-reply.XXXXXX.md)"`,
894
+ ` trap 'rm -f "$body_file"' EXIT`,
895
+ ` cat > "$body_file" <<'LARK_REPLY_EOF'`,
896
+ ` ...(回复的 Markdown 正文,可多行 / 含表格 / 含特殊字符;不要写 <at> 标签)`,
905
897
  ` LARK_REPLY_EOF`,
906
- ` lark-cli ${profileFlag}im +messages-reply --message-id <取自 replyTo.messageId> --as bot --markdown "$(cat "$reply_file")" # 4. 真正调用 (注意 --markdown flag, 不要用 --text)`,
898
+ ` content="$(jq -nc --rawfile md "$body_file" --arg uid "<senderId>" '{zh_cn:{content:[[{tag:"at",user_id:$uid}],[{tag:"md",text:$md}]]}}')"`,
899
+ ` lark-cli ${profileFlag}im +messages-reply --message-id <取自 replyTo.messageId> --as bot --msg-type post --content "$content"`,
900
+ ``,
901
+ `不需要 @ 某人时,把 jq 表达式换成 '{zh_cn:{content:[[{tag:"md",text:$md}]]}}'。`,
907
902
  ``,
908
- `## 禁止(用 words 描述,避免被 LLM 当字面 trap 抄)`,
909
- `- 禁止把多行 Markdown 直接拼进 --markdown 参数`,
910
- `- 禁止 bash ANSI-C 引号语法(特征:dollar 符号紧跟单引号的引号形式)`,
903
+ `## 禁止`,
904
+ `- 禁止 --text / --msg-type text(plain text,Markdown 全部失效)`,
905
+ `- 禁止 --markdown(无法携带结构化 at 节点)`,
906
+ `- 禁止在正文里写 <at user_id=".."/> 或 <at user_id=".."></at> 文本标签`,
907
+ `- 禁止把多行 Markdown 直接拼进 --content 参数(必须走上面的 jq --rawfile)`,
911
908
  `- 禁止字面反斜杠+n(即 \\n 两个字符,不是 0x0A 控制字符)`,
912
- `- 禁止 stdin 形式传 Markdown(--markdown 后接一个短横线作为值的写法)`,
913
- `- 禁止 at-file 形式传 Markdown(--markdown 后接 @ 符号加文件名的写法)`,
914
- `- 禁止 --text flag(让 lark-cli 把消息当 plain text, rich format 全部失效 — 见顶部说明)`,
915
- `- 禁止 --msg-type text(同理, --msg-type post 可选但需对应结构, 仍不如 --markdown flag 稳)`,
909
+ `- 禁止 bash ANSI-C 引号语法(dollar 符号紧跟单引号)`,
916
910
  ``,
917
911
  `## 必须使用 replyTo 里给定的值`,
918
912
  `profile / chatId / messageId / --as bot 必须原样取自 recommendedAction.replyTo;不要凭印象自己拼接。`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-setting/roy-agent-core",
3
- "version": "1.7.35",
3
+ "version": "1.7.36",
4
4
  "type": "module",
5
5
  "description": "Core SDK for roy-agent - Environment, Components, Tools, Sessions, Tasks",
6
6
  "main": "./dist/index.js",