@ai-setting/roy-agent-core 1.6.9 → 1.6.10

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.
Files changed (39) hide show
  1. package/dist/config/index.js +5 -3
  2. package/dist/env/agent/index.js +3 -3
  3. package/dist/env/commands/index.js +2 -2
  4. package/dist/env/event-source/index.js +3 -3
  5. package/dist/env/index.js +12 -12
  6. package/dist/env/llm/index.js +3 -2
  7. package/dist/env/log-trace/index.js +2 -2
  8. package/dist/env/mcp/index.js +2 -2
  9. package/dist/env/memory/index.js +2 -2
  10. package/dist/env/prompt/index.js +2 -2
  11. package/dist/env/session/index.js +2 -2
  12. package/dist/env/skill/index.js +2 -2
  13. package/dist/env/task/index.js +2 -2
  14. package/dist/env/tool/index.js +2 -2
  15. package/dist/env/workflow/engine/index.js +2 -2
  16. package/dist/env/workflow/index.js +6 -6
  17. package/dist/env/workflow/tools/index.js +3 -3
  18. package/dist/index.js +19 -18
  19. package/dist/shared/@ai-setting/{roy-agent-core-062gyaz8.js → roy-agent-core-0n2a8cbn.js} +48 -5
  20. package/dist/shared/@ai-setting/{roy-agent-core-brfryc0b.js → roy-agent-core-1gsnq4p2.js} +4 -196
  21. package/dist/shared/@ai-setting/{roy-agent-core-qdgaghhw.js → roy-agent-core-2ek596yd.js} +52 -12
  22. package/dist/shared/@ai-setting/{roy-agent-core-tbn8cerp.js → roy-agent-core-2yavqjsh.js} +1 -1
  23. package/dist/shared/@ai-setting/{roy-agent-core-7rsfynhz.js → roy-agent-core-38kbfarg.js} +1 -1
  24. package/dist/shared/@ai-setting/{roy-agent-core-np2vh6ya.js → roy-agent-core-3kbf53sh.js} +1 -1
  25. package/dist/shared/@ai-setting/{roy-agent-core-e34xdjwa.js → roy-agent-core-4mhrz08q.js} +3 -3
  26. package/dist/shared/@ai-setting/{roy-agent-core-qxhq8ven.js → roy-agent-core-7hh0brvs.js} +5 -0
  27. package/dist/shared/@ai-setting/{roy-agent-core-sd3v4kaq.js → roy-agent-core-ck0m8754.js} +34 -1
  28. package/dist/shared/@ai-setting/{roy-agent-core-qyarxwzg.js → roy-agent-core-g9p7e2ys.js} +1 -1
  29. package/dist/shared/@ai-setting/{roy-agent-core-g2ntbc33.js → roy-agent-core-jenchn33.js} +45 -2
  30. package/dist/shared/@ai-setting/{roy-agent-core-yk0n6j67.js → roy-agent-core-m38q2azm.js} +32 -10
  31. package/dist/shared/@ai-setting/{roy-agent-core-jmzz2yxs.js → roy-agent-core-nw39k111.js} +1 -1
  32. package/dist/shared/@ai-setting/{roy-agent-core-9zf4jmgh.js → roy-agent-core-nzpw62d3.js} +1 -1
  33. package/dist/shared/@ai-setting/{roy-agent-core-kxtkz66a.js → roy-agent-core-rga3f0hm.js} +1 -1
  34. package/dist/shared/@ai-setting/{roy-agent-core-q1ksqes1.js → roy-agent-core-txsswwhm.js} +1 -1
  35. package/dist/shared/@ai-setting/{roy-agent-core-1qcpvtp8.js → roy-agent-core-xxgazz27.js} +1 -1
  36. package/dist/shared/@ai-setting/roy-agent-core-y3g3ar7a.js +229 -0
  37. package/dist/shared/@ai-setting/{roy-agent-core-w1e55apa.js → roy-agent-core-z7f8hyv7.js} +1 -1
  38. package/dist/shared/@ai-setting/{roy-agent-core-sk4xg1dw.js → roy-agent-core-zs31w092.js} +1 -1
  39. package/package.json +1 -1
@@ -1,10 +1,9 @@
1
+ import {
2
+ EnvSource
3
+ } from "./roy-agent-core-y3g3ar7a.js";
1
4
  import {
2
5
  XDG_PATHS
3
6
  } from "./roy-agent-core-qxnbvgwe.js";
4
- import {
5
- fromEnvKey,
6
- toEnvKey
7
- } from "./roy-agent-core-qxhq8ven.js";
8
7
  import {
9
8
  BaseComponent
10
9
  } from "./roy-agent-core-j62bjagf.js";
@@ -426,197 +425,6 @@ class FileSource {
426
425
  }
427
426
  }
428
427
 
429
- // src/config/env-source.ts
430
- class EnvSource {
431
- name = "env";
432
- priority = 20;
433
- prefix;
434
- transform;
435
- pollInterval;
436
- watchers = new Set;
437
- pollTimer;
438
- lastValues = new Map;
439
- watchEnabled = true;
440
- constructor(options = {}) {
441
- this.prefix = options.prefix ?? "";
442
- this.transform = options.transform;
443
- this.pollInterval = options.pollInterval;
444
- this.watchEnabled = options.watch ?? true;
445
- }
446
- getEnvKey(key) {
447
- return toEnvKey(key, this.prefix);
448
- }
449
- getInternalKey(envKey) {
450
- return fromEnvKey(envKey, this.prefix);
451
- }
452
- read(key) {
453
- const envKey = this.getEnvKey(key);
454
- const value = process.env[envKey];
455
- if (value === undefined) {
456
- return;
457
- }
458
- if (this.transform) {
459
- return this.transform(value, key);
460
- }
461
- return value;
462
- }
463
- write(key, value) {
464
- const envKey = this.getEnvKey(key);
465
- const oldValue = process.env[envKey];
466
- const stringValue = String(value);
467
- process.env[envKey] = stringValue;
468
- const event = {
469
- type: oldValue === undefined ? "add" : "change",
470
- key,
471
- oldValue: oldValue !== undefined ? this.transformValue(oldValue, key) : undefined,
472
- newValue: this.transformValue(stringValue, key),
473
- source: this.name,
474
- timestamp: Date.now()
475
- };
476
- this.notifyWatchers(event);
477
- return true;
478
- }
479
- delete(key) {
480
- const envKey = this.getEnvKey(key);
481
- const oldValue = process.env[envKey];
482
- if (oldValue === undefined) {
483
- return false;
484
- }
485
- delete process.env[envKey];
486
- const event = {
487
- type: "delete",
488
- key,
489
- oldValue: this.transformValue(oldValue, key),
490
- newValue: undefined,
491
- source: this.name,
492
- timestamp: Date.now()
493
- };
494
- this.notifyWatchers(event);
495
- return true;
496
- }
497
- list() {
498
- const result = [];
499
- const prefix = this.prefix.toUpperCase();
500
- for (const envKey of Object.keys(process.env)) {
501
- if (prefix && !envKey.startsWith(prefix)) {
502
- continue;
503
- }
504
- const key = this.getInternalKey(envKey);
505
- const value = process.env[envKey];
506
- if (value !== undefined) {
507
- result.push({
508
- key,
509
- value: this.transformValue(value, key)
510
- });
511
- }
512
- }
513
- return result;
514
- }
515
- watch(callback) {
516
- this.watchers.add(callback);
517
- if (!this.watchEnabled) {
518
- return () => {
519
- this.watchers.delete(callback);
520
- };
521
- }
522
- this.ensurePolling();
523
- this.recordCurrentValues();
524
- return () => {
525
- this.watchers.delete(callback);
526
- if (this.watchers.size === 0) {
527
- this.stopPolling();
528
- }
529
- };
530
- }
531
- ensurePolling() {
532
- if (this.pollTimer !== undefined) {
533
- return;
534
- }
535
- const interval = this.pollInterval ?? 1000;
536
- this.pollTimer = setInterval(() => {
537
- this.checkForChanges();
538
- }, interval);
539
- }
540
- stopPolling() {
541
- if (this.pollTimer) {
542
- clearInterval(this.pollTimer);
543
- this.pollTimer = undefined;
544
- }
545
- }
546
- recordCurrentValues() {
547
- this.lastValues.clear();
548
- const entries = this.list();
549
- for (const entry of entries) {
550
- const envKey = this.getEnvKey(entry.key);
551
- const value = process.env[envKey];
552
- if (value !== undefined) {
553
- this.lastValues.set(envKey, value);
554
- }
555
- }
556
- }
557
- checkForChanges() {
558
- const currentEntries = this.list();
559
- const currentValues = new Map;
560
- for (const entry of currentEntries) {
561
- const envKey = this.getEnvKey(entry.key);
562
- const value = process.env[envKey];
563
- if (value !== undefined) {
564
- currentValues.set(envKey, value);
565
- }
566
- }
567
- for (const [envKey, oldValue] of this.lastValues.entries()) {
568
- if (!currentValues.has(envKey)) {
569
- const key = this.getInternalKey(envKey);
570
- this.notifyWatchers({
571
- type: "delete",
572
- key,
573
- oldValue: this.transformValue(oldValue, key),
574
- newValue: undefined,
575
- source: this.name,
576
- timestamp: Date.now()
577
- });
578
- }
579
- }
580
- for (const [envKey, newValue] of currentValues.entries()) {
581
- const key = this.getInternalKey(envKey);
582
- const oldValue = this.lastValues.get(envKey);
583
- if (oldValue === undefined) {
584
- this.notifyWatchers({
585
- type: "add",
586
- key,
587
- oldValue: undefined,
588
- newValue: this.transformValue(newValue, key),
589
- source: this.name,
590
- timestamp: Date.now()
591
- });
592
- } else if (oldValue !== newValue) {
593
- this.notifyWatchers({
594
- type: "change",
595
- key,
596
- oldValue: this.transformValue(oldValue, key),
597
- newValue: this.transformValue(newValue, key),
598
- source: this.name,
599
- timestamp: Date.now()
600
- });
601
- }
602
- }
603
- this.lastValues = currentValues;
604
- }
605
- transformValue(value, key) {
606
- if (this.transform) {
607
- return this.transform(value, key);
608
- }
609
- return value;
610
- }
611
- notifyWatchers(event) {
612
- this.watchers.forEach((cb) => cb(event));
613
- }
614
- close() {
615
- this.stopPolling();
616
- this.watchers.clear();
617
- }
618
- }
619
-
620
428
  // src/config/protocol-resolver.ts
621
429
  var PROTOCOL_PATTERN = /^\$\{([^:]+):\/\/([^:#]+)(?:#([^:-]+))?(?::-(.*))?\}$/;
622
430
 
@@ -1246,4 +1054,4 @@ class ConfigComponent extends BaseComponent {
1246
1054
  }
1247
1055
  }
1248
1056
 
1249
- export { parseJSONC, substituteEnvVars, parseJSONCWithEnv, substituteProtocolRefs, parseJSONCWithProtocols, FileSource, EnvSource, ConfigSourceNotFoundError, ConfigFileNotFoundError, MemorySource, ConfigComponent };
1057
+ export { parseJSONC, substituteEnvVars, parseJSONCWithEnv, substituteProtocolRefs, parseJSONCWithProtocols, FileSource, ConfigSourceNotFoundError, ConfigFileNotFoundError, MemorySource, ConfigComponent };
@@ -4,7 +4,7 @@ import {
4
4
  } from "./roy-agent-core-y5ymc4f8.js";
5
5
  import {
6
6
  envKeyToConfigKey
7
- } from "./roy-agent-core-qxhq8ven.js";
7
+ } from "./roy-agent-core-7hh0brvs.js";
8
8
  import {
9
9
  BaseComponent
10
10
  } from "./roy-agent-core-j62bjagf.js";
@@ -616,6 +616,50 @@ function matchEventType(eventType, patterns) {
616
616
  }
617
617
  return false;
618
618
  }
619
+ function buildLarkRecommendedAction(opts) {
620
+ const { profile, chatType, appId, chatId, messageId } = opts;
621
+ const profileFlag = profile ? `--profile ${profile} ` : "";
622
+ const profileWarn = profile ? `(⚠️ 必须用 profile="${profile}" 调 lark-cli;openId per-app 隔离,换 profile 会失败)` : "";
623
+ const isGroup = chatType === "group";
624
+ const scopeHint = isGroup ? '群聊消息;回复到 replyTo.chatId。如需 @mention 发件人,请在 Markdown 正文开头加 <at user_id="<senderId>"/>' : "p2p 私聊消息;回复到 replyTo.chatId";
625
+ const scopeWord = isGroup ? "群聊" : "p2p 私聊";
626
+ const action = [
627
+ `处理飞书 ${scopeWord}消息并以机器人身份回复${profileWarn}。`,
628
+ `scope: ${scopeHint}。`,
629
+ ``,
630
+ `## 安全传 Markdown(必读,避免飞书收到字面 $ 和字面反斜杠+n)`,
631
+ `多行 / 复杂 Markdown 必须先写入临时 .md 文件,再 cat 出来当 --markdown 的值。`,
632
+ `原因:agent 工具调用层不做 shell 展开。`,
633
+ ``,
634
+ `推荐调用模板(4 步缺一不可,照抄):`,
635
+ ` reply_file="$(mktemp /tmp/lark-reply.XXXXXX.md)" # 1. 唯一文件名(避免并发覆盖)`,
636
+ ` trap 'rm -f "$reply_file"' EXIT # 2. 注册退出清理(无论成败都删,避免 /tmp 累积)`,
637
+ ` cat > "$reply_file" <<'LARK_REPLY_EOF' # 3. 写入 Markdown(heredoc 单引号防 shell 展开)`,
638
+ ` ...(这里是回复的 Markdown 内容,可以多行 / 含特殊字符)`,
639
+ ` LARK_REPLY_EOF`,
640
+ ` lark-cli ${profileFlag}im +messages-reply --message-id <取自 replyTo.messageId> --as bot --markdown "$(cat "$reply_file")" # 4. 真正调用`,
641
+ ``,
642
+ `## 禁止(用 words 描述,避免被 LLM 当字面 trap 抄)`,
643
+ `- 禁止把多行 Markdown 直接拼进 --markdown 参数`,
644
+ `- 禁止 bash ANSI-C 引号语法(特征:dollar 符号紧跟单引号的引号形式)`,
645
+ `- 禁止字面反斜杠+n(即 \\n 两个字符,不是 0x0A 控制字符)`,
646
+ `- 禁止 stdin 形式传 Markdown(--markdown 后接一个短横线作为值的写法)`,
647
+ `- 禁止 at-file 形式传 Markdown(--markdown 后接 @ 符号加文件名的写法)`,
648
+ ``,
649
+ `## 必须使用 replyTo 里给定的值`,
650
+ `profile / chatId / messageId / --as bot 必须原样取自 recommendedAction.replyTo;不要凭印象自己拼接。`
651
+ ].join(`
652
+ `);
653
+ return {
654
+ action,
655
+ replyTo: {
656
+ appId,
657
+ profile,
658
+ chatId,
659
+ messageId
660
+ }
661
+ };
662
+ }
619
663
  function extractMetadata(rawEvent, eventType) {
620
664
  const event = rawEvent;
621
665
  const metadata = {};
@@ -654,17 +698,13 @@ function extractMetadata(rawEvent, eventType) {
654
698
  let recommendedAction;
655
699
  if (eventType === "im.message.receive_v1" || event.type === "im.message.receive_v1") {
656
700
  const profile2 = event.profile;
657
- const profileFlag = profile2 ? `--profile ${profile2} ` : "";
658
- const profileHint = profile2 ? `(⚠️ 必须使用 profile="${profile2}" 调用 lark-cli,否则会因 openId 跨 app 失败)` : "";
659
- recommendedAction = {
660
- action: `处理飞书消息并以机器人身份回复${profileHint},例如:lark-cli ${profileFlag}im +messages-reply --message-id "xxxxid" --as bot --markdown "Markdown 格式回复内容"`,
661
- replyTo: {
662
- appId: metadata.appId,
663
- profile: profile2,
664
- chatId: metadata.chatId,
665
- messageId: metadata.messageId
666
- }
667
- };
701
+ recommendedAction = buildLarkRecommendedAction({
702
+ profile: profile2,
703
+ chatType: metadata.chatType,
704
+ appId: metadata.appId,
705
+ chatId: metadata.chatId,
706
+ messageId: metadata.messageId
707
+ });
668
708
  }
669
709
  const profile = event.profile;
670
710
  const replyChannel = {
@@ -3,7 +3,7 @@ import {
3
3
  } from "./roy-agent-core-g1s2h0e5.js";
4
4
  import {
5
5
  envKeyToConfigKey
6
- } from "./roy-agent-core-qxhq8ven.js";
6
+ } from "./roy-agent-core-7hh0brvs.js";
7
7
  import {
8
8
  BaseComponent
9
9
  } from "./roy-agent-core-j62bjagf.js";
@@ -7,7 +7,7 @@ import {
7
7
  import {
8
8
  envKeyToConfigKey,
9
9
  toEnvKey
10
- } from "./roy-agent-core-qxhq8ven.js";
10
+ } from "./roy-agent-core-7hh0brvs.js";
11
11
  import {
12
12
  BaseComponent
13
13
  } from "./roy-agent-core-j62bjagf.js";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  envKeyToConfigKey,
3
3
  toEnvKey
4
- } from "./roy-agent-core-qxhq8ven.js";
4
+ } from "./roy-agent-core-7hh0brvs.js";
5
5
  import {
6
6
  BaseComponent
7
7
  } from "./roy-agent-core-j62bjagf.js";
@@ -6,7 +6,7 @@ import {
6
6
  WorkflowEngine,
7
7
  exports_engine,
8
8
  init_engine
9
- } from "./roy-agent-core-062gyaz8.js";
9
+ } from "./roy-agent-core-0n2a8cbn.js";
10
10
  import {
11
11
  askUserTool,
12
12
  createRunWorkflowTool,
@@ -18,7 +18,7 @@ import {
18
18
  createWorkflowSearchTool,
19
19
  createWorkflowTagListTool,
20
20
  createWorkflowValidateTool
21
- } from "./roy-agent-core-qyarxwzg.js";
21
+ } from "./roy-agent-core-g9p7e2ys.js";
22
22
  import {
23
23
  WorkflowService
24
24
  } from "./roy-agent-core-p2vpsd1d.js";
@@ -141,7 +141,7 @@ class WorkflowComponent extends BaseComponent {
141
141
  if (!agentRunner && this._workflowEnv) {
142
142
  const agentComponent = this._workflowEnv.getComponent("agent");
143
143
  if (agentComponent) {
144
- const { AgentComponentAdapter } = await import("./roy-agent-core-w1e55apa.js");
144
+ const { AgentComponentAdapter } = await import("./roy-agent-core-z7f8hyv7.js");
145
145
  agentRunner = new AgentComponentAdapter(agentComponent, {}, this.sessionComponent);
146
146
  }
147
147
  }
@@ -3,6 +3,11 @@ function toEnvKey(key, prefix) {
3
3
  let keyNormalized = key.replace(/[.-]/g, "_");
4
4
  keyNormalized = keyNormalized.replace(/([a-z])([A-Z])/g, "$1_$2").replace(/_+/g, "_").toUpperCase();
5
5
  if (prefix) {
6
+ const prefixCore = prefix.toUpperCase().replace(/^_+|_+$/g, "");
7
+ const prefixCoreWithSep = `${prefixCore}_`;
8
+ if (prefixCore && keyNormalized.startsWith(prefixCoreWithSep)) {
9
+ return keyNormalized;
10
+ }
6
11
  const separator = prefix.endsWith("_") ? "" : "_";
7
12
  return `${prefix}${separator}${keyNormalized}`;
8
13
  }
@@ -1,3 +1,6 @@
1
+ import {
2
+ EnvSource
3
+ } from "./roy-agent-core-y3g3ar7a.js";
1
4
  import {
2
5
  invoke
3
6
  } from "./roy-agent-core-dcd1s7ct.js";
@@ -8,7 +11,7 @@ import {
8
11
  import {
9
12
  envKeyToConfigKey,
10
13
  toEnvKey
11
- } from "./roy-agent-core-qxhq8ven.js";
14
+ } from "./roy-agent-core-7hh0brvs.js";
12
15
  import {
13
16
  BaseComponent
14
17
  } from "./roy-agent-core-j62bjagf.js";
@@ -541,12 +544,42 @@ class LLMComponent extends BaseComponent {
541
544
  await configComponent.set(configKey, value);
542
545
  }
543
546
  }
547
+ if (envSource instanceof EnvSource) {
548
+ const knownKeys = new Set([
549
+ "llm.defaultModel",
550
+ "llm.defaultProvider",
551
+ "llm.temperature",
552
+ "llm.maxTokens",
553
+ "llm.topP",
554
+ "llm.stream",
555
+ "llm.options",
556
+ "llm.default",
557
+ "llm.providers",
558
+ "llm.limits",
559
+ "llm.capabilities"
560
+ ]);
561
+ envSource.validateUnrecognizedEnvVars({
562
+ componentName: "llm",
563
+ knownKeys,
564
+ logger: {
565
+ warn: (msg) => logger.warn(msg)
566
+ }
567
+ });
568
+ }
544
569
  if (config) {
545
570
  const flatConfig = this.flattenConfig(config);
546
571
  for (const [key, value] of Object.entries(flatConfig)) {
547
572
  await configComponent.set(key, value);
548
573
  }
549
574
  }
575
+ const configuredProviders = configComponent.get("llm.providers");
576
+ const configuredDefaultProvider = configComponent.get("llm.defaultProvider");
577
+ if (typeof configuredDefaultProvider === "string" && configuredProviders && typeof configuredProviders === "object" && Object.keys(configuredProviders).length > 0) {
578
+ const providerKeys = Object.keys(configuredProviders);
579
+ if (!providerKeys.includes(configuredDefaultProvider)) {
580
+ throw new Error(`[LLM] Invalid llm.defaultProvider: "${configuredDefaultProvider}". ` + `Known providers: ${providerKeys.join(", ")}. ` + `Add it to llm.providers first, or remove the env var / config entry.`);
581
+ }
582
+ }
550
583
  this.registerConfigWatcher(configComponent);
551
584
  }
552
585
  flattenConfig(obj, prefix = "llm") {
@@ -14,7 +14,7 @@ import {
14
14
  } from "./roy-agent-core-c1v263jn.js";
15
15
  import {
16
16
  isValidSessionId
17
- } from "./roy-agent-core-jmzz2yxs.js";
17
+ } from "./roy-agent-core-nw39k111.js";
18
18
  import {
19
19
  TracedAs,
20
20
  init_decorator
@@ -68,6 +68,46 @@ function registerWorkflowJsonOutputPlugin(options = undefined) {
68
68
  });
69
69
  logger.info("Workflow JSON output plugin registered on agent:after.react");
70
70
  }
71
+ function readProviderReasoning(source) {
72
+ if (!source)
73
+ return;
74
+ const configComponent = source.configComponent;
75
+ if (!configComponent)
76
+ return;
77
+ const isConfigError = (e) => e instanceof Error && (e.name === "ConfigValidationError" || e.name === "ConfigError");
78
+ let providerId;
79
+ try {
80
+ providerId = configComponent.get("llm.defaultProvider");
81
+ } catch (e) {
82
+ if (isConfigError(e))
83
+ return;
84
+ throw e;
85
+ }
86
+ if (!providerId)
87
+ return;
88
+ let capabilities;
89
+ try {
90
+ const capKey = `llm.providers.${providerId}.capabilities`;
91
+ capabilities = configComponent.get(capKey);
92
+ } catch (e) {
93
+ if (isConfigError(e))
94
+ return;
95
+ throw e;
96
+ }
97
+ return { providerId, reasoning: capabilities?.reasoning === true };
98
+ }
99
+ function resolveProviderToolChoice(source) {
100
+ const ctx = readProviderReasoning(source);
101
+ if (!ctx)
102
+ return "required";
103
+ if (FIRST_PARTY_PROVIDERS.has(ctx.providerId)) {
104
+ return "required";
105
+ }
106
+ if (ctx.reasoning) {
107
+ return "auto";
108
+ }
109
+ return "required";
110
+ }
71
111
  async function runWorkflowJsonOutputExtraction(hookCtx) {
72
112
  const schema = hookCtx.context.metadata?.outputSchema;
73
113
  if (!schema) {
@@ -113,11 +153,13 @@ async function runWorkflowJsonOutputExtraction(hookCtx) {
113
153
  content: userQuery
114
154
  }
115
155
  ];
156
+ const resolvedToolChoice = resolveProviderToolChoice(agentComponentRef);
116
157
  const extractContext = {
117
158
  messages: messagesOverride,
118
159
  extraTools: [submitToolAsExtra],
119
160
  persistSession: false,
120
- abort: hookCtx.context.abort
161
+ abort: hookCtx.context.abort,
162
+ toolChoice: resolvedToolChoice
121
163
  };
122
164
  try {
123
165
  const result = await agentComponentRef.run("json-extract", "", extractContext);
@@ -134,7 +176,7 @@ async function runWorkflowJsonOutputExtraction(hookCtx) {
134
176
  logger.error(`Workflow JSON extraction: json-extract sub-agent threw: ${error instanceof Error ? error.message : String(error)}`);
135
177
  }
136
178
  }
137
- var logger, WORKFLOW_JSON_OUTPUT_SOURCE_ID = "workflow", WORKFLOW_JSON_OUTPUT_PLUGIN_NAME = "json-output", WORKFLOW_JSON_OUTPUT_PLUGIN_KEY, HOOK_POINT = "agent:after.react", HOOK_NAME, registered = false, agentComponentRef = null, tracedRunWorkflowJsonOutputExtraction;
179
+ var logger, WORKFLOW_JSON_OUTPUT_SOURCE_ID = "workflow", WORKFLOW_JSON_OUTPUT_PLUGIN_NAME = "json-output", WORKFLOW_JSON_OUTPUT_PLUGIN_KEY, HOOK_POINT = "agent:after.react", HOOK_NAME, registered = false, agentComponentRef = null, FIRST_PARTY_PROVIDERS, tracedRunWorkflowJsonOutputExtraction;
138
180
  var init_workflow_json_output_plugin = __esm(() => {
139
181
  init_global_hook_manager();
140
182
  init_workflow_hil();
@@ -144,6 +186,7 @@ var init_workflow_json_output_plugin = __esm(() => {
144
186
  logger = createLogger("WorkflowJsonOutputPlugin");
145
187
  WORKFLOW_JSON_OUTPUT_PLUGIN_KEY = `${WORKFLOW_JSON_OUTPUT_SOURCE_ID}:${WORKFLOW_JSON_OUTPUT_PLUGIN_NAME}`;
146
188
  HOOK_NAME = `${WORKFLOW_JSON_OUTPUT_PLUGIN_NAME}:${HOOK_POINT}`;
189
+ FIRST_PARTY_PROVIDERS = new Set(["openai", "anthropic", "google"]);
147
190
  tracedRunWorkflowJsonOutputExtraction = wrapFunction(runWorkflowJsonOutputExtraction, "workflow.json_output.extraction", { recordParams: true, recordResult: true, log: true });
148
191
  });
149
192
 
@@ -3,7 +3,7 @@ import {
3
3
  } from "./roy-agent-core-dcd1s7ct.js";
4
4
  import {
5
5
  truncateOutputInline
6
- } from "./roy-agent-core-sk4xg1dw.js";
6
+ } from "./roy-agent-core-zs31w092.js";
7
7
  import {
8
8
  AskUserError,
9
9
  init_workflow_hil
@@ -22,7 +22,7 @@ import {
22
22
  } from "./roy-agent-core-8x4ngxcy.js";
23
23
  import {
24
24
  envKeyToConfigKey
25
- } from "./roy-agent-core-qxhq8ven.js";
25
+ } from "./roy-agent-core-7hh0brvs.js";
26
26
  import {
27
27
  BaseComponent
28
28
  } from "./roy-agent-core-j62bjagf.js";
@@ -628,6 +628,22 @@ class AgentComponent extends BaseComponent {
628
628
  hookCtx.messages.push(message);
629
629
  this.notifyMessageAdded(message);
630
630
  }
631
+ consumeMetaProtocolUserMessage(hookCtx) {
632
+ const toolResultMeta = hookCtx.toolResult?.result?.metadata;
633
+ if (!toolResultMeta || !("toAddFakeUserMessage" in toolResultMeta)) {
634
+ return;
635
+ }
636
+ const userMsg = toolResultMeta.toAddFakeUserMessage;
637
+ delete toolResultMeta.toAddFakeUserMessage;
638
+ if (!userMsg || userMsg.role !== "user") {
639
+ return;
640
+ }
641
+ return userMsg;
642
+ }
643
+ flushPendingFakeUserMessage(hookCtx, pendingMsg, iter) {
644
+ this.pushMessage(hookCtx, pendingMsg);
645
+ logger.debug(`[ReAct] Meta-protocol: flushed user message AFTER all tool-results (iter=${iter})`);
646
+ }
631
647
  async _run(agentName, query, context) {
632
648
  await this.refreshDependencies();
633
649
  const agent = this.getAgent(agentName);
@@ -866,6 +882,7 @@ class AgentComponent extends BaseComponent {
866
882
  });
867
883
  iterAllToolCalls = llmOutput.toolCalls ?? [];
868
884
  iterProcessedCount = 0;
885
+ let pendingFakeUserMessage;
869
886
  for (const toolCall of iterAllToolCalls) {
870
887
  if (this.aborted.get(runId) || effectiveContext.abort?.aborted) {
871
888
  hookCtx._stopped = true;
@@ -918,19 +935,18 @@ class AgentComponent extends BaseComponent {
918
935
  }]
919
936
  });
920
937
  {
921
- const toolResultMeta = hookCtx.toolResult?.result?.metadata;
922
- if (toolResultMeta && "toAddFakeUserMessage" in toolResultMeta) {
923
- const userMsg = toolResultMeta.toAddFakeUserMessage;
924
- if (userMsg && userMsg.role === "user") {
925
- this.pushMessage(hookCtx, userMsg);
926
- logger.debug(`[ReAct] Meta-protocol: appended user message after tool result (tool=${toolResult.name}, iter=${iteration})`);
927
- delete toolResultMeta.toAddFakeUserMessage;
928
- }
938
+ const captured = this.consumeMetaProtocolUserMessage(hookCtx);
939
+ if (captured) {
940
+ pendingFakeUserMessage = captured;
941
+ logger.debug(`[ReAct] Meta-protocol: captured user message (tool=${toolResult.name}, iter=${iteration}); will flush after loop`);
929
942
  }
930
943
  }
931
944
  result.toolCalls.push(hookCtx.currentToolCall);
932
945
  iterProcessedCount++;
933
946
  }
947
+ if (pendingFakeUserMessage) {
948
+ this.flushPendingFakeUserMessage(hookCtx, pendingFakeUserMessage, iteration);
949
+ }
934
950
  await this.executePluginHooks(agent, "agent:on.iteration", hookCtx);
935
951
  }
936
952
  } catch (error) {
@@ -1499,6 +1515,12 @@ __legacyDecorateClassTS([
1499
1515
  __legacyDecorateClassTS([
1500
1516
  TracedAs("agent.component.resolveSystemPrompt", { recordParams: true, recordResult: true, log: true })
1501
1517
  ], AgentComponent.prototype, "resolveSystemPrompt", null);
1518
+ __legacyDecorateClassTS([
1519
+ TracedAs("agent.meta-protocol.consumeUserMessage", { recordParams: false, recordResult: false, log: true })
1520
+ ], AgentComponent.prototype, "consumeMetaProtocolUserMessage", null);
1521
+ __legacyDecorateClassTS([
1522
+ TracedAs("agent.meta-protocol.flushPendingUserMessage", { recordParams: false, recordResult: false, log: true })
1523
+ ], AgentComponent.prototype, "flushPendingFakeUserMessage", null);
1502
1524
  __legacyDecorateClassTS([
1503
1525
  TracedAs("agent.component.run", { recordParams: true, recordResult: true, log: true })
1504
1526
  ], AgentComponent.prototype, "_run", null);
@@ -9,7 +9,7 @@ import {
9
9
  } from "./roy-agent-core-95bbd2jv.js";
10
10
  import {
11
11
  envKeyToConfigKey
12
- } from "./roy-agent-core-qxhq8ven.js";
12
+ } from "./roy-agent-core-7hh0brvs.js";
13
13
  import {
14
14
  BaseComponent
15
15
  } from "./roy-agent-core-j62bjagf.js";
@@ -37,7 +37,7 @@ import {
37
37
  } from "./roy-agent-core-1pg0fepg.js";
38
38
  import {
39
39
  envKeyToConfigKey
40
- } from "./roy-agent-core-qxhq8ven.js";
40
+ } from "./roy-agent-core-7hh0brvs.js";
41
41
  import {
42
42
  BaseComponent
43
43
  } from "./roy-agent-core-j62bjagf.js";
@@ -11,7 +11,7 @@ import {
11
11
  } from "./roy-agent-core-4w6rgxs4.js";
12
12
  import {
13
13
  toEnvKey
14
- } from "./roy-agent-core-qxhq8ven.js";
14
+ } from "./roy-agent-core-7hh0brvs.js";
15
15
  import {
16
16
  BaseComponent
17
17
  } from "./roy-agent-core-j62bjagf.js";
@@ -3,7 +3,7 @@ import {
3
3
  } from "./roy-agent-core-psvxt4c9.js";
4
4
  import {
5
5
  envKeyToConfigKey
6
- } from "./roy-agent-core-qxhq8ven.js";
6
+ } from "./roy-agent-core-7hh0brvs.js";
7
7
  import {
8
8
  BaseComponent
9
9
  } from "./roy-agent-core-j62bjagf.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  envKeyToConfigKey
3
- } from "./roy-agent-core-qxhq8ven.js";
3
+ } from "./roy-agent-core-7hh0brvs.js";
4
4
  import {
5
5
  BaseComponent
6
6
  } from "./roy-agent-core-j62bjagf.js";