@ai-setting/roy-agent-core 1.5.51 → 1.5.52

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.
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  AgentComponent,
3
3
  AgentComponentConfigSchema
4
- } from "../../shared/@ai-setting/roy-agent-core-2k4r9grg.js";
4
+ } from "../../shared/@ai-setting/roy-agent-core-4mw6rs37.js";
5
5
  import"../../shared/@ai-setting/roy-agent-core-e25xkv53.js";
6
6
  import"../../shared/@ai-setting/roy-agent-core-emk3q2nt.js";
7
7
  import"../../shared/@ai-setting/roy-agent-core-qxnbvgwe.js";
@@ -9,7 +9,7 @@ import"../../shared/@ai-setting/roy-agent-core-ctdhjv68.js";
9
9
  import {
10
10
  SummaryAgent
11
11
  } from "../../shared/@ai-setting/roy-agent-core-kwhv9dcd.js";
12
- import"../../shared/@ai-setting/roy-agent-core-7b35emr7.js";
12
+ import"../../shared/@ai-setting/roy-agent-core-ew29335n.js";
13
13
  import"../../shared/@ai-setting/roy-agent-core-qxhq8ven.js";
14
14
  import"../../shared/@ai-setting/roy-agent-core-cssnkkkg.js";
15
15
  import"../../shared/@ai-setting/roy-agent-core-hd9p5490.js";
package/dist/env/index.js CHANGED
@@ -38,7 +38,7 @@ import"../shared/@ai-setting/roy-agent-core-1ce3fqrk.js";
38
38
  import {
39
39
  AgentComponent,
40
40
  AgentComponentConfigSchema
41
- } from "../shared/@ai-setting/roy-agent-core-2k4r9grg.js";
41
+ } from "../shared/@ai-setting/roy-agent-core-4mw6rs37.js";
42
42
  import"../shared/@ai-setting/roy-agent-core-e25xkv53.js";
43
43
  import {
44
44
  TaskComponent
@@ -62,7 +62,7 @@ import"../shared/@ai-setting/roy-agent-core-ctdhjv68.js";
62
62
  import"../shared/@ai-setting/roy-agent-core-fnv3ev18.js";
63
63
  import"../shared/@ai-setting/roy-agent-core-1bfmxx89.js";
64
64
  import"../shared/@ai-setting/roy-agent-core-kwhv9dcd.js";
65
- import"../shared/@ai-setting/roy-agent-core-7b35emr7.js";
65
+ import"../shared/@ai-setting/roy-agent-core-ew29335n.js";
66
66
  import"../shared/@ai-setting/roy-agent-core-qxhq8ven.js";
67
67
  import {
68
68
  BaseComponent
@@ -12,7 +12,7 @@ import {
12
12
  invoke,
13
13
  invokeNonStream,
14
14
  parseModelString
15
- } from "../../shared/@ai-setting/roy-agent-core-qjh1ec46.js";
15
+ } from "../../shared/@ai-setting/roy-agent-core-ct95gkee.js";
16
16
  import"../../shared/@ai-setting/roy-agent-core-ctdhjv68.js";
17
17
  import"../../shared/@ai-setting/roy-agent-core-qxhq8ven.js";
18
18
  import"../../shared/@ai-setting/roy-agent-core-cssnkkkg.js";
@@ -3,7 +3,7 @@ import {
3
3
  PromptConfigSchema,
4
4
  PromptPathSchema,
5
5
  PromptRenderer
6
- } from "../../shared/@ai-setting/roy-agent-core-h9tpga25.js";
6
+ } from "../../shared/@ai-setting/roy-agent-core-vbyct0e7.js";
7
7
  import"../../shared/@ai-setting/roy-agent-core-qxnbvgwe.js";
8
8
  import"../../shared/@ai-setting/roy-agent-core-qxhq8ven.js";
9
9
  import"../../shared/@ai-setting/roy-agent-core-cssnkkkg.js";
@@ -1,14 +1,14 @@
1
1
  import {
2
2
  SessionComponent
3
- } from "../../shared/@ai-setting/roy-agent-core-6de35s2n.js";
3
+ } from "../../shared/@ai-setting/roy-agent-core-9m9m6fe1.js";
4
4
  import"../../shared/@ai-setting/roy-agent-core-rvxg1wps.js";
5
5
  import {
6
6
  MemorySessionStore
7
- } from "../../shared/@ai-setting/roy-agent-core-6mcb7nqa.js";
7
+ } from "../../shared/@ai-setting/roy-agent-core-pcjenbaf.js";
8
8
  import"../../shared/@ai-setting/roy-agent-core-kwhv9dcd.js";
9
9
  import {
10
10
  SessionMessageConverter
11
- } from "../../shared/@ai-setting/roy-agent-core-7b35emr7.js";
11
+ } from "../../shared/@ai-setting/roy-agent-core-ew29335n.js";
12
12
  import"../../shared/@ai-setting/roy-agent-core-qxhq8ven.js";
13
13
  import"../../shared/@ai-setting/roy-agent-core-cssnkkkg.js";
14
14
  import"../../shared/@ai-setting/roy-agent-core-hd9p5490.js";
@@ -3,8 +3,8 @@ import {
3
3
  SQLiteSessionStore,
4
4
  getDefaultDataDir,
5
5
  getDefaultSessionDbPath
6
- } from "../../../shared/@ai-setting/roy-agent-core-6mcb7nqa.js";
7
- import"../../../shared/@ai-setting/roy-agent-core-7b35emr7.js";
6
+ } from "../../../shared/@ai-setting/roy-agent-core-pcjenbaf.js";
7
+ import"../../../shared/@ai-setting/roy-agent-core-ew29335n.js";
8
8
  import"../../../shared/@ai-setting/roy-agent-core-fs0mn2jk.js";
9
9
  export {
10
10
  getDefaultSessionDbPath,
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  PromptStore,
4
4
  getBuiltInPrompt,
5
5
  getBuiltInPromptNames
6
- } from "./shared/@ai-setting/roy-agent-core-h9tpga25.js";
6
+ } from "./shared/@ai-setting/roy-agent-core-vbyct0e7.js";
7
7
  import {
8
8
  LLMComponent,
9
9
  LLMConfigSchema,
@@ -15,7 +15,7 @@ import {
15
15
  invoke,
16
16
  invokeNonStream,
17
17
  parseModelString
18
- } from "./shared/@ai-setting/roy-agent-core-qjh1ec46.js";
18
+ } from "./shared/@ai-setting/roy-agent-core-ct95gkee.js";
19
19
  import {
20
20
  ConfigComponent
21
21
  } from "./shared/@ai-setting/roy-agent-core-e68xspar.js";
@@ -118,7 +118,7 @@ import"./shared/@ai-setting/roy-agent-core-1ce3fqrk.js";
118
118
  import {
119
119
  AgentComponent,
120
120
  AgentComponentConfigSchema
121
- } from "./shared/@ai-setting/roy-agent-core-2k4r9grg.js";
121
+ } from "./shared/@ai-setting/roy-agent-core-4mw6rs37.js";
122
122
  import {
123
123
  AskUserError,
124
124
  init_workflow_hil
@@ -167,13 +167,13 @@ import"./shared/@ai-setting/roy-agent-core-fnv3ev18.js";
167
167
  import"./shared/@ai-setting/roy-agent-core-1bfmxx89.js";
168
168
  import {
169
169
  SessionComponent
170
- } from "./shared/@ai-setting/roy-agent-core-6de35s2n.js";
170
+ } from "./shared/@ai-setting/roy-agent-core-9m9m6fe1.js";
171
171
  import"./shared/@ai-setting/roy-agent-core-rvxg1wps.js";
172
172
  import {
173
173
  MemorySessionStore
174
- } from "./shared/@ai-setting/roy-agent-core-6mcb7nqa.js";
174
+ } from "./shared/@ai-setting/roy-agent-core-pcjenbaf.js";
175
175
  import"./shared/@ai-setting/roy-agent-core-kwhv9dcd.js";
176
- import"./shared/@ai-setting/roy-agent-core-7b35emr7.js";
176
+ import"./shared/@ai-setting/roy-agent-core-ew29335n.js";
177
177
  import"./shared/@ai-setting/roy-agent-core-qxhq8ven.js";
178
178
  import {
179
179
  BaseComponent
@@ -10,7 +10,7 @@ import {
10
10
  } from "./roy-agent-core-ctdhjv68.js";
11
11
  import {
12
12
  SessionMessageConverter
13
- } from "./roy-agent-core-7b35emr7.js";
13
+ } from "./roy-agent-core-ew29335n.js";
14
14
  import {
15
15
  envKeyToConfigKey
16
16
  } from "./roy-agent-core-qxhq8ven.js";
@@ -671,7 +671,8 @@ class AgentComponent extends BaseComponent {
671
671
  if (typeof tc.function.arguments === "string") {
672
672
  argsStr = tc.function.arguments;
673
673
  try {
674
- argsObj = JSON.parse(argsStr);
674
+ const parsed = JSON.parse(argsStr);
675
+ argsObj = typeof parsed === "string" ? { _raw: parsed } : parsed;
675
676
  } catch {
676
677
  argsObj = { _raw: argsStr };
677
678
  }
@@ -683,7 +684,8 @@ class AgentComponent extends BaseComponent {
683
684
  if (typeof tc.arguments === "string") {
684
685
  argsStr = tc.arguments;
685
686
  try {
686
- argsObj = JSON.parse(argsStr);
687
+ const parsed = JSON.parse(argsStr);
688
+ argsObj = typeof parsed === "string" ? { _raw: parsed } : parsed;
687
689
  } catch {
688
690
  argsObj = { _raw: argsStr };
689
691
  }
@@ -721,7 +723,14 @@ class AgentComponent extends BaseComponent {
721
723
  }
722
724
  const func = toolCall.function;
723
725
  const tcName = func?.name || toolCall.name || "unknown";
724
- const tcArgs = func?.arguments ? typeof func.arguments === "string" ? JSON.parse(func.arguments) : func.arguments : toolCall.arguments;
726
+ const tcArgs = func?.arguments ? typeof func.arguments === "string" ? (() => {
727
+ const parsed = JSON.parse(func.arguments);
728
+ if (typeof parsed === "string") {
729
+ logger.warn(`[agent.component] Tool "${tcName}" arguments are double-stringified, wrapping in { _raw }`);
730
+ return { _raw: parsed };
731
+ }
732
+ return parsed;
733
+ })() : func.arguments : toolCall.arguments;
725
734
  hookCtx.currentToolCall = {
726
735
  id: toolCall.id,
727
736
  name: tcName,
@@ -789,11 +798,15 @@ class AgentComponent extends BaseComponent {
789
798
  });
790
799
  }
791
800
  for (const tc of llmOutput.toolCalls) {
801
+ const tcInput = typeof tc.function?.arguments === "string" ? (() => {
802
+ const parsed = JSON.parse(tc.function.arguments);
803
+ return typeof parsed === "string" ? { _raw: parsed } : parsed;
804
+ })() : tc.arguments || {};
792
805
  assistantParts.push({
793
806
  type: "tool-call",
794
807
  toolCallId: tc.id,
795
808
  toolName: tc.function?.name || tc.name || "unknown",
796
- input: typeof tc.function?.arguments === "string" ? JSON.parse(tc.function.arguments) : tc.arguments || {}
809
+ input: tcInput
797
810
  });
798
811
  }
799
812
  this.pushMessage(hookCtx, {
@@ -6,7 +6,7 @@ import {
6
6
  import {
7
7
  MemorySessionStore,
8
8
  SQLiteSessionStore
9
- } from "./roy-agent-core-6mcb7nqa.js";
9
+ } from "./roy-agent-core-pcjenbaf.js";
10
10
  import {
11
11
  SummaryAgent
12
12
  } from "./roy-agent-core-kwhv9dcd.js";
@@ -371,9 +371,10 @@ function convertToSDKMessages(messages) {
371
371
  if (tc.function?.arguments) {
372
372
  if (typeof tc.function.arguments === "string") {
373
373
  try {
374
- input = JSON.parse(tc.function.arguments);
374
+ const parsed = JSON.parse(tc.function.arguments);
375
+ input = typeof parsed === "string" ? { _raw: parsed } : parsed;
375
376
  } catch {
376
- input = tc.function.arguments;
377
+ input = { _raw: tc.function.arguments };
377
378
  }
378
379
  } else {
379
380
  input = tc.function.arguments;
@@ -381,9 +382,10 @@ function convertToSDKMessages(messages) {
381
382
  } else if (tc.arguments) {
382
383
  if (typeof tc.arguments === "string") {
383
384
  try {
384
- input = JSON.parse(tc.arguments);
385
+ const parsed = JSON.parse(tc.arguments);
386
+ input = typeof parsed === "string" ? { _raw: parsed } : parsed;
385
387
  } catch {
386
- input = tc.arguments;
388
+ input = { _raw: tc.arguments };
387
389
  }
388
390
  } else {
389
391
  input = tc.arguments;
@@ -529,9 +531,9 @@ function processThinkingStream(textDelta, config, state) {
529
531
  }
530
532
  const tags = config.tags || ["thinking"];
531
533
  let remainingText = textDelta;
532
- const reasoningEvents = [];
533
- let isOpen = state.isOpen;
534
- let currentContent = state.content;
534
+ const reasoningEvents2 = [];
535
+ let isOpen2 = state.isOpen;
536
+ let currentContent2 = state.content;
535
537
  for (const tag of tags) {
536
538
  const openTag = `<${tag}>`;
537
539
  const closeTag = `</${tag}>`;
@@ -542,35 +544,35 @@ function processThinkingStream(textDelta, config, state) {
542
544
  if (openIndex !== -1 && (closeIndex === -1 || openIndex < closeIndex)) {
543
545
  const beforeOpen = text.substring(0, openIndex);
544
546
  const afterOpen = text.substring(openIndex + openTag.length);
545
- if (!isOpen) {
546
- isOpen = true;
547
- currentContent = "";
548
- reasoningEvents.push("");
547
+ if (!isOpen2) {
548
+ isOpen2 = true;
549
+ currentContent2 = "";
550
+ reasoningEvents2.push("");
549
551
  }
550
552
  result += beforeOpen;
551
553
  const innerCloseIndex = afterOpen.toLowerCase().indexOf(closeTag.toLowerCase());
552
554
  if (innerCloseIndex !== -1) {
553
555
  const thinkingContent = afterOpen.substring(0, innerCloseIndex);
554
556
  const afterClose = afterOpen.substring(innerCloseIndex + closeTag.length);
555
- currentContent += thinkingContent;
556
- reasoningEvents.push(currentContent);
557
- isOpen = false;
558
- currentContent = "";
557
+ currentContent2 += thinkingContent;
558
+ reasoningEvents2.push(currentContent2);
559
+ isOpen2 = false;
560
+ currentContent2 = "";
559
561
  result += afterClose;
560
562
  } else {
561
- currentContent += afterOpen;
562
- reasoningEvents.push(currentContent);
563
+ currentContent2 += afterOpen;
564
+ reasoningEvents2.push(currentContent2);
563
565
  result += "";
564
566
  }
565
567
  remainingText = result;
566
568
  } else if (closeIndex !== -1) {
567
569
  const beforeClose = text.substring(0, closeIndex);
568
570
  const afterClose = text.substring(closeIndex + closeTag.length);
569
- if (isOpen) {
570
- currentContent += beforeClose;
571
- reasoningEvents.push(currentContent);
572
- isOpen = false;
573
- currentContent = "";
571
+ if (isOpen2) {
572
+ currentContent2 += beforeClose;
573
+ reasoningEvents2.push(currentContent2);
574
+ isOpen2 = false;
575
+ currentContent2 = "";
574
576
  result = afterClose;
575
577
  } else {
576
578
  result = text;
@@ -578,11 +580,16 @@ function processThinkingStream(textDelta, config, state) {
578
580
  remainingText = result;
579
581
  }
580
582
  }
583
+ if (isOpen2 && remainingText === textDelta) {
584
+ currentContent2 += remainingText;
585
+ reasoningEvents2.push(currentContent2);
586
+ remainingText = "";
587
+ }
581
588
  return {
582
589
  cleanedText: remainingText,
583
- isThinkingTagOpen: isOpen,
584
- currentThinkingContent: currentContent,
585
- reasoningEvents
590
+ isThinkingTagOpen: isOpen2,
591
+ currentThinkingContent: currentContent2,
592
+ reasoningEvents: reasoningEvents2
586
593
  };
587
594
  }
588
595
  async function invoke(config, options, ctx) {
@@ -705,9 +712,6 @@ async function invoke(config, options, ctx) {
705
712
  break;
706
713
  }
707
714
  case "reasoning-end":
708
- if (emitToEnv) {
709
- emitToEnv({ type: "reasoning", content: reasoningContent, phase: "end" });
710
- }
711
715
  break;
712
716
  case "tool-call": {
713
717
  const toolInput = streamPart.input;
@@ -26,7 +26,8 @@ class SessionMessageConverter {
26
26
  let parsedArgs = {};
27
27
  if (typeof toolPart.arguments === "string") {
28
28
  try {
29
- parsedArgs = JSON.parse(toolPart.arguments);
29
+ const parsed = JSON.parse(toolPart.arguments);
30
+ parsedArgs = typeof parsed === "string" ? { _raw: parsed } : parsed;
30
31
  } catch {
31
32
  parsedArgs = { _raw: toolPart.arguments };
32
33
  }
@@ -98,7 +99,7 @@ class SessionMessageConverter {
98
99
  type: "tool-call",
99
100
  toolCallId: p.toolCallId,
100
101
  toolName: p.toolName,
101
- arguments: p.input,
102
+ arguments: typeof p.input === "string" ? { _raw: p.input } : p.input,
102
103
  state: "pending"
103
104
  });
104
105
  } else if (p.type === "tool-result") {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  SessionMessageConverter
3
- } from "./roy-agent-core-7b35emr7.js";
3
+ } from "./roy-agent-core-ew29335n.js";
4
4
  import {
5
5
  __require
6
6
  } from "./roy-agent-core-fs0mn2jk.js";
@@ -110,23 +110,26 @@ var builtInPrompts = {
110
110
  | 工具 | 描述 |
111
111
  |------|------|
112
112
  | \`delegate_task\` | 委托复杂/多步骤任务给子智能体执行 |
113
- | \`bash\` | **仅**用于执行简单的 Roy Agent 相关命令(如 \`bun packages/cli/dist/bin/roy-agent.js ...\`) |
113
+ | \`bash\` | **仅**用于执行一行简单的 Roy Agent 命令或一次性操作 |
114
114
 
115
115
  ### 工具使用规则
116
116
 
117
- **\`delegate_task\`** — 用于一切复杂、多步骤、需要读文件、运行命令、搜索、实现功能等场景。这是你的主要工具。
117
+ **\`delegate_task\`** — 这是你的**主要工具**。用于一切复杂、多步骤、需要读文件、运行命令、代码分析、搜索、实现功能等场景。**当不确定用哪个时,选 \`delegate_task\`。**
118
118
 
119
- **\`bash\`** — **仅限**以下简单场景:
120
- - 执行简单的 \`roy-agent\` 命令(如 \`bun packages/cli/dist/bin/roy-agent.js act "你好"\`)
121
- - 检查 Roy Agent 版本或帮助信息
122
- - 运行已经由子智能体构建好的脚本
123
- - 创建简单的问候或快速测试
119
+ **\`bash\`** — **仅限**以下**一次性简单操作**:
120
+ - 调用一行 \`roy-agent\` 命令(如 \`bun packages/cli/dist/bin/roy-agent.js tasks list\`)
121
+ - 执行一个简单的 shell 命令(如 \`ls\`、\`echo hello\`)
122
+ - 检查版本或帮助信息
123
+
124
+ **\`bash\` 的边界判定:**
125
+ > 如果需要 **2 步以上**、涉及**条件判断**、需要**读取结果后再决策**,或者**不确认能否一行完成**,**一律用 \`delegate_task\`**。
124
126
 
125
127
  **\`bash\` 禁止用于:**
126
- - 任何需要多步骤的复杂逻辑
127
- - 代码分析、文件读写、搜索
128
- - 功能开发、调试、重构
129
- - 即使可以用 bash 实现,复杂任务也必须使用 \`delegate_task\`
128
+ - 任何需要多步骤的复杂逻辑
129
+ - 代码分析、文件读写、搜索
130
+ - 功能开发、调试、重构
131
+ - 读取文件内容、grep 代码
132
+ - ❌ 即使可以用 bash 实现,**只要超过 1 步**就必须用 \`delegate_task\`
130
133
 
131
134
  ## 何时委托
132
135
 
@@ -139,10 +142,12 @@ var builtInPrompts = {
139
142
  - **不明确的请求** — 需要探索才能明确方向的任务
140
143
  - **文件/代码/数据访问** — 任何需要读文件、运行命令或查询数据的请求
141
144
 
142
- **不需要委托的情况:**
145
+ **不需要委托的情况(极少):**
143
146
  - 简单的问候 / 闲聊
144
147
  - 你凭自身知识就能回答的一次性简单问题
145
148
 
149
+ > ⚠️ **当你不确定是否需要委托时,一律委托。** 宁可多委托一次,也不要自己用 bash 做多步骤操作。
150
+
146
151
  ## 子智能体选择策略
147
152
 
148
153
  你有两个子智能体。**默认首次委托使用 \`roy\`**。仅在需要严格 Plan→Execute→Verify 纪律时使用 \`strict-task-agent\`。
@@ -199,7 +204,7 @@ delegate_task(
199
204
  ## 行为规则
200
205
 
201
206
  1. **复杂任务必须委托** — 不要尝试自己解决复杂任务。使用 \`delegate_task\` 委托给子智能体。
202
- 2. **bash 仅限简单命令** — \`bash\` 只能用于执行简单的 Roy Agent 命令(如调用 \`bun packages/cli/dist/bin/roy-agent.js ...\`)。任何需要多步骤逻辑的复杂工作,即使可以用 bash 实现,也必须使用 \`delegate_task\`。
207
+ 2. **bash 仅限一次操作** — \`bash\` 只能用于执行一行简单的 shell 命令或 \`roy-agent\` 命令。**任何超过 1 步的操作,即使可以用一行 bash 实现,也必须使用 \`delegate_task\`**。如果不确定,就委托。
203
208
  3. **保持简洁** — 简短分析,然后立即委托。不要冗长。
204
209
  4. **首选 roy** — 首次委托默认使用 \`roy\`
205
210
  5. **次选 strict-task-agent** — 需要严格 Plan→Execute→Verify 纪律时使用
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-setting/roy-agent-core",
3
- "version": "1.5.51",
3
+ "version": "1.5.52",
4
4
  "type": "module",
5
5
  "description": "Core SDK for roy-agent - Environment, Components, Tools, Sessions, Tasks",
6
6
  "main": "./dist/index.js",