@blade-hq/agent-client 2612.0.0-beta.16 → 2612.0.0-beta.18

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/README.md CHANGED
@@ -670,28 +670,17 @@ function Message({ message }: { message: ChatMessage }) {
670
670
  }
671
671
  ```
672
672
 
673
- ### 让用户挑一个技能来做事
673
+ ### 在消息中引用技能
674
674
 
675
- 自己实现技能选择器时,用 `transformSlashCommand` 把选中的技能翻译成智能体能执行的一段话:
675
+ `SkillRef` 表示技能身份,`MessageRef` 是技能与插件引用的联合类型;`normalizeMessageRefs` 可校验和去重引用。自定义技能选择器把技能身份放进 `refs`,正文保留用户输入。运行时另行提供技能描述和文件路径,智能体根据原文判断解释、比较还是使用。
676
676
 
677
677
  ```ts
678
- import { transformSlashCommand, type SkillMentionAvailability } from "@blade-hq/agent-client"
679
-
680
- transformSlashCommand("org/data-analysis", "分析这份季度报表")
681
- // "请使用 org/data-analysis skill 完成任务\n分析这份季度报表"
682
- ```
683
-
684
- 第三个参数说明这个技能眼下能不能直接用。技能装没装、加载没加载,用户不需要知道,但智能体需要——传进来之后它会被翻译成对应的 CLI 步骤:
685
-
686
- ```ts
687
- // Blade Hub 上已安装、但当前会话还没加载:要求先 use
688
- transformSlashCommand(skillId, prompt, { local: false, installed: true })
689
-
690
- // Blade Hub 上还没安装:要求先 install 再 use
691
- transformSlashCommand(skillId, prompt, { local: false, installed: false })
678
+ session.send("@org/data-analysis 这是什么?", {
679
+ refs: [{ provider: "skill", id: "org/data-analysis", label: "org/data-analysis" }],
680
+ })
692
681
  ```
693
682
 
694
- 不传第三个参数时按本地已有处理,和不带这个参数的老用法结果一致。
683
+ 技能引用仅属于本条消息。`transformSlashCommand` 只把 `<skill>名称</skill>` 标记转换为 `@名称`,不会增加执行或安装指令;调用方仍需单独发送 `refs`。
695
684
 
696
685
  ## 运行错误说明:userFacingErrorText
697
686
 
@@ -213,7 +213,7 @@ var ToolProvider = class {
213
213
 
214
214
  // src/version.ts
215
215
  var SDK_NAME = "agent-client";
216
- var SDK_VERSION = true ? "2612.0.0-beta.16" : "1.1.1";
216
+ var SDK_VERSION = true ? "2612.0.0-beta.18" : "1.1.1";
217
217
 
218
218
  // src/auth-login.ts
219
219
  function isAuthCallbackMessage(value) {
@@ -457,6 +457,19 @@ function normalizePluginRefs(value) {
457
457
  return [{ provider: "plugin", plugin: item.plugin, server: item.server, id: item.id, label: item.label }];
458
458
  });
459
459
  }
460
+ function normalizeMessageRefs(value) {
461
+ if (!Array.isArray(value)) return [];
462
+ const seen = /* @__PURE__ */ new Set();
463
+ return value.flatMap((item) => {
464
+ if (!item || typeof item !== "object") return [];
465
+ const ref = item.provider === "skill" && typeof item.id === "string" && item.id && typeof item.label === "string" && item.label ? { provider: "skill", id: item.id, label: item.label } : normalizePluginRefs([item])[0];
466
+ if (!ref) return [];
467
+ const key = ref.provider === "skill" ? JSON.stringify([ref.provider, ref.id]) : JSON.stringify([ref.provider, ref.plugin, ref.server, ref.id]);
468
+ if (seen.has(key)) return [];
469
+ seen.add(key);
470
+ return [ref];
471
+ });
472
+ }
460
473
 
461
474
  // src/schemas/topic-assets.ts
462
475
  function normalizeTopicAssetRefs(value) {
@@ -1710,7 +1723,7 @@ var ClientProjectionBuilder = class {
1710
1723
  onUserMessage(_loopId, payload) {
1711
1724
  const entryId = String(payload.entry_id ?? this.nextTurnId("user"));
1712
1725
  const displayContent = payload.display_content ?? payload.content ?? "";
1713
- const refs = normalizePluginRefs(payload.refs);
1726
+ const refs = normalizeMessageRefs(payload.refs);
1714
1727
  const turn = {
1715
1728
  id: entryId,
1716
1729
  sequence: this.nextSeq(),
@@ -2423,6 +2436,10 @@ function projectHistory(entries) {
2423
2436
  // root Agent 工具调用兜底配对,工作流 fork 没有,子智能体卡会整体消失)。
2424
2437
  parent_fork_tool_call_id: stringOrNull(message._parent_fork_tool_call_id)
2425
2438
  };
2439
+ if (role === "user") {
2440
+ const refs = normalizeMessageRefs(message.refs);
2441
+ if (refs.length) turn.refs = refs;
2442
+ }
2426
2443
  const isNativeToolEntry = role === "assistant" && Array.isArray(message.tool_calls) && message.tool_calls.some(
2427
2444
  (toolCall) => isRecord(toolCall) && typeof toolCall.provider === "string"
2428
2445
  );
@@ -2844,7 +2861,7 @@ var HeadlessResource = class {
2844
2861
  return this.runTracked(session_id, prompt, options, true);
2845
2862
  }
2846
2863
  async runTracked(sessionId, prompt, options, returnEnvelope) {
2847
- if ((options.refs?.length ?? 0) > 20) throw new HeadlessError("\u6BCF\u6761\u6D88\u606F\u6700\u591A\u9009\u62E9 20 \u4E2A\u63D2\u4EF6\u6761\u76EE");
2864
+ if ((options.refs?.length ?? 0) > 20) throw new HeadlessError("\u6BCF\u6761\u6D88\u606F\u6700\u591A\u9009\u62E9 20 \u4E2A\u5F15\u7528");
2848
2865
  if ((options.topicAssetRefs?.length ?? 0) > 20) throw new HeadlessError("\u6BCF\u6761\u6D88\u606F\u6700\u591A\u5F15\u7528 20 \u4E2A\u4E3B\u9898\u8D44\u4EA7");
2849
2866
  const timeoutMs = options.timeoutMs ?? 3e5;
2850
2867
  const session_id = sessionId;
@@ -4654,15 +4671,8 @@ function contentPreview(content, maxLen = 80) {
4654
4671
  const text = getTextContent(content).trim();
4655
4672
  return text.length > maxLen ? `${text.slice(0, maxLen)}\u2026` : text;
4656
4673
  }
4657
- function transformSlashCommand(skillName, rawInput, { local = true, installed = true } = {}) {
4658
- const prompt = rawInput.replace(`<skill>${skillName}</skill>`, "").trim();
4659
- if (local) {
4660
- return prompt ? `\u8BF7\u4F7F\u7528 ${skillName} skill \u5B8C\u6210\u4EFB\u52A1
4661
- ${prompt}` : `\u8BF7\u4F7F\u7528 ${skillName} skill \u5B8C\u6210\u4EFB\u52A1`;
4662
- }
4663
- const steps = installed ? `\u8BF7\u5148\u8FD0\u884C blade hub skill use ${skillName} \u52A0\u8F7D\u6280\u80FD` : `\u8BE5\u6280\u80FD\u5C1A\u672A\u5B89\u88C5\u3002\u8BF7\u5148\u8FD0\u884C blade hub skill install ${skillName} \u5B89\u88C5\uFF0C\u518D\u8FD0\u884C blade hub skill use ${skillName} \u52A0\u8F7D`;
4664
- return prompt ? `${steps}\uFF0C\u7136\u540E\u5B8C\u6210\u4EFB\u52A1\uFF1A
4665
- ${prompt}` : `${steps}\uFF0C\u7136\u540E\u4F7F\u7528\u5B83\u5B8C\u6210\u4EFB\u52A1`;
4674
+ function transformSlashCommand(skillName, rawInput, _availability = {}) {
4675
+ return rawInput.replace(`<skill>${skillName}</skill>`, `@${skillName}`).trim();
4666
4676
  }
4667
4677
  var ATTACHMENT_TAG_RE = /\[附件:\s*([^\]]+)\](?:[ \t]*已上传到工作区路径:[ \t]*([^\r\n]+))?/g;
4668
4678
  var CONTEXT_PART_RE = /^\[上下文:\s*([^\]]+)\]\n([\s\S]*)$/;
@@ -8464,6 +8474,7 @@ export {
8464
8474
  SDK_VERSION,
8465
8475
  isRecord,
8466
8476
  normalizePluginRefs,
8477
+ normalizeMessageRefs,
8467
8478
  normalizeTopicAssetRefs,
8468
8479
  inferToolStatus,
8469
8480
  contextProjectionData,
@@ -8543,4 +8554,4 @@ export {
8543
8554
  createSocket,
8544
8555
  BladeClient
8545
8556
  };
8546
- //# sourceMappingURL=chunk-XW5HZ7IR.js.map
8557
+ //# sourceMappingURL=chunk-RS6763DB.js.map