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

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 (41) 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 +13 -13
  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/delegate/index.js +1 -1
  14. package/dist/env/task/index.js +3 -3
  15. package/dist/env/tool/index.js +2 -2
  16. package/dist/env/workflow/engine/index.js +2 -2
  17. package/dist/env/workflow/index.js +6 -6
  18. package/dist/env/workflow/tools/index.js +3 -3
  19. package/dist/index.js +20 -19
  20. package/dist/shared/@ai-setting/{roy-agent-core-e34xdjwa.js → roy-agent-core-06574wqa.js} +5 -4
  21. package/dist/shared/@ai-setting/{roy-agent-core-062gyaz8.js → roy-agent-core-0n2a8cbn.js} +48 -5
  22. package/dist/shared/@ai-setting/{roy-agent-core-brfryc0b.js → roy-agent-core-1gsnq4p2.js} +4 -196
  23. package/dist/shared/@ai-setting/{roy-agent-core-qdgaghhw.js → roy-agent-core-2ek596yd.js} +52 -12
  24. package/dist/shared/@ai-setting/{roy-agent-core-tbn8cerp.js → roy-agent-core-2yavqjsh.js} +1 -1
  25. package/dist/shared/@ai-setting/{roy-agent-core-7rsfynhz.js → roy-agent-core-38kbfarg.js} +1 -1
  26. package/dist/shared/@ai-setting/{roy-agent-core-np2vh6ya.js → roy-agent-core-3kbf53sh.js} +1 -1
  27. package/dist/shared/@ai-setting/{roy-agent-core-9zf4jmgh.js → roy-agent-core-3rs38pf7.js} +2 -2
  28. package/dist/shared/@ai-setting/{roy-agent-core-8bhncxep.js → roy-agent-core-5w9a1eqa.js} +43 -6
  29. package/dist/shared/@ai-setting/{roy-agent-core-qxhq8ven.js → roy-agent-core-7hh0brvs.js} +5 -0
  30. package/dist/shared/@ai-setting/{roy-agent-core-sd3v4kaq.js → roy-agent-core-ck0m8754.js} +34 -1
  31. package/dist/shared/@ai-setting/{roy-agent-core-g2ntbc33.js → roy-agent-core-jenchn33.js} +45 -2
  32. package/dist/shared/@ai-setting/{roy-agent-core-yk0n6j67.js → roy-agent-core-m38q2azm.js} +32 -10
  33. package/dist/shared/@ai-setting/{roy-agent-core-qyarxwzg.js → roy-agent-core-mb7b62sm.js} +52 -14
  34. package/dist/shared/@ai-setting/{roy-agent-core-jmzz2yxs.js → roy-agent-core-nw39k111.js} +1 -1
  35. package/dist/shared/@ai-setting/{roy-agent-core-kxtkz66a.js → roy-agent-core-rga3f0hm.js} +1 -1
  36. package/dist/shared/@ai-setting/{roy-agent-core-q1ksqes1.js → roy-agent-core-txsswwhm.js} +1 -1
  37. package/dist/shared/@ai-setting/{roy-agent-core-1qcpvtp8.js → roy-agent-core-xxgazz27.js} +1 -1
  38. package/dist/shared/@ai-setting/roy-agent-core-y3g3ar7a.js +229 -0
  39. package/dist/shared/@ai-setting/{roy-agent-core-w1e55apa.js → roy-agent-core-z7f8hyv7.js} +1 -1
  40. package/dist/shared/@ai-setting/{roy-agent-core-sk4xg1dw.js → roy-agent-core-zs31w092.js} +1 -1
  41. package/package.json +1 -1
@@ -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);
@@ -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
@@ -671,6 +671,48 @@ __legacyDecorateClassTS([
671
671
  recordResult: true
672
672
  })
673
673
  ], RunWorkflowToolRunner.prototype, "execute", null);
674
+
675
+ class RunWorkflowLifecycleTracer {
676
+ runner;
677
+ bgTaskId;
678
+ hooks;
679
+ constructor(runner, bgTaskId, hooks) {
680
+ this.runner = runner;
681
+ this.bgTaskId = bgTaskId;
682
+ this.hooks = hooks;
683
+ }
684
+ async execute(args, ctx) {
685
+ const hasHooks = !!this.hooks?.attachWorkflowRun;
686
+ const hasBgTask = !!this.bgTaskId;
687
+ const result = await this.runner.execute(args, ctx);
688
+ let detached = false;
689
+ if (this.bgTaskId && this.hooks?.detachWorkflowRun) {
690
+ const runId = result?.metadata?.run_id ?? result?.output?.run_id ?? "";
691
+ if (runId && result.success) {
692
+ this.hooks.detachWorkflowRun(this.bgTaskId, runId);
693
+ detached = true;
694
+ }
695
+ }
696
+ return {
697
+ ...result,
698
+ metadata: {
699
+ ...result.metadata,
700
+ __pre_attach: {
701
+ hasBgTask,
702
+ hasHooks,
703
+ detached,
704
+ success: !!result.success
705
+ }
706
+ }
707
+ };
708
+ }
709
+ }
710
+ __legacyDecorateClassTS([
711
+ TracedAs("workflow.run-tool.pre-attach", {
712
+ recordParams: true,
713
+ recordResult: true
714
+ })
715
+ ], RunWorkflowLifecycleTracer.prototype, "execute", null);
674
716
  function createRunWorkflowTool(workflowService, hooks) {
675
717
  const tool = {
676
718
  name: "workflow_run",
@@ -708,12 +750,19 @@ function createRunWorkflowTool(workflowService, hooks) {
708
750
  let timedOut = false;
709
751
  let capturedByCallback = false;
710
752
  let capturedRunId = session ? session : reservedRunId;
753
+ const bgTaskIdForAttach = getCurrentBgTaskId();
754
+ if (bgTaskIdForAttach && hooks?.attachWorkflowRun) {
755
+ hooks.attachWorkflowRun(bgTaskIdForAttach, reservedRunId);
756
+ }
711
757
  const onSessionCreated = (sid) => {
712
758
  capturedRunId = sid;
713
759
  capturedByCallback = true;
714
760
  if (timedOut) {
715
761
  attemptStopOnTimeout(workflowService, sid, "timed out");
716
762
  }
763
+ if (bgTaskIdForAttach && hooks?.replaceWorkflowRun) {
764
+ hooks.replaceWorkflowRun(bgTaskIdForAttach, reservedRunId, sid);
765
+ }
717
766
  };
718
767
  try {
719
768
  let result;
@@ -811,19 +860,8 @@ function createRunWorkflowTool(workflowService, hooks) {
811
860
  const runner = new RunWorkflowToolRunner(tool.execute);
812
861
  const wrappedExecute = async (args, ctx) => {
813
862
  const bgTaskId = getCurrentBgTaskId();
814
- if (!bgTaskId || !hooks?.attachWorkflowRun) {
815
- return runner.execute(args, ctx);
816
- }
817
- const initialRunId = "wf_attach_pending_placeholder";
818
- const result = await runner.execute(args, ctx);
819
- const runId = result?.metadata?.run_id ?? result?.output?.run_id ?? "";
820
- if (runId) {
821
- hooks.attachWorkflowRun?.(bgTaskId, runId);
822
- if (result.success) {
823
- hooks.detachWorkflowRun?.(bgTaskId, runId);
824
- }
825
- }
826
- return result;
863
+ const lifecycleTracer = new RunWorkflowLifecycleTracer(runner, bgTaskId, hooks);
864
+ return lifecycleTracer.execute(args, ctx);
827
865
  };
828
866
  return {
829
867
  ...tool,
@@ -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";
@@ -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";
@@ -0,0 +1,229 @@
1
+ import {
2
+ envKeyToConfigKey,
3
+ fromEnvKey,
4
+ toEnvKey
5
+ } from "./roy-agent-core-7hh0brvs.js";
6
+
7
+ // src/config/env-source.ts
8
+ class EnvSource {
9
+ name = "env";
10
+ priority = 20;
11
+ prefix;
12
+ transform;
13
+ pollInterval;
14
+ watchers = new Set;
15
+ pollTimer;
16
+ lastValues = new Map;
17
+ watchEnabled = true;
18
+ constructor(options = {}) {
19
+ this.prefix = options.prefix ?? "";
20
+ this.transform = options.transform;
21
+ this.pollInterval = options.pollInterval;
22
+ this.watchEnabled = options.watch ?? true;
23
+ }
24
+ getEnvKey(key) {
25
+ return toEnvKey(key, this.prefix);
26
+ }
27
+ getInternalKey(envKey) {
28
+ return fromEnvKey(envKey, this.prefix);
29
+ }
30
+ read(key) {
31
+ const envKey = this.getEnvKey(key);
32
+ const value = process.env[envKey];
33
+ if (value === undefined) {
34
+ return;
35
+ }
36
+ if (this.transform) {
37
+ return this.transform(value, key);
38
+ }
39
+ return value;
40
+ }
41
+ write(key, value) {
42
+ const envKey = this.getEnvKey(key);
43
+ const oldValue = process.env[envKey];
44
+ const stringValue = String(value);
45
+ process.env[envKey] = stringValue;
46
+ const event = {
47
+ type: oldValue === undefined ? "add" : "change",
48
+ key,
49
+ oldValue: oldValue !== undefined ? this.transformValue(oldValue, key) : undefined,
50
+ newValue: this.transformValue(stringValue, key),
51
+ source: this.name,
52
+ timestamp: Date.now()
53
+ };
54
+ this.notifyWatchers(event);
55
+ return true;
56
+ }
57
+ delete(key) {
58
+ const envKey = this.getEnvKey(key);
59
+ const oldValue = process.env[envKey];
60
+ if (oldValue === undefined) {
61
+ return false;
62
+ }
63
+ delete process.env[envKey];
64
+ const event = {
65
+ type: "delete",
66
+ key,
67
+ oldValue: this.transformValue(oldValue, key),
68
+ newValue: undefined,
69
+ source: this.name,
70
+ timestamp: Date.now()
71
+ };
72
+ this.notifyWatchers(event);
73
+ return true;
74
+ }
75
+ list() {
76
+ const result = [];
77
+ const prefix = this.prefix.toUpperCase();
78
+ for (const envKey of Object.keys(process.env)) {
79
+ if (prefix && !envKey.startsWith(prefix)) {
80
+ continue;
81
+ }
82
+ const key = this.getInternalKey(envKey);
83
+ const value = process.env[envKey];
84
+ if (value !== undefined) {
85
+ result.push({
86
+ key,
87
+ value: this.transformValue(value, key)
88
+ });
89
+ }
90
+ }
91
+ return result;
92
+ }
93
+ watch(callback) {
94
+ this.watchers.add(callback);
95
+ if (!this.watchEnabled) {
96
+ return () => {
97
+ this.watchers.delete(callback);
98
+ };
99
+ }
100
+ this.ensurePolling();
101
+ this.recordCurrentValues();
102
+ return () => {
103
+ this.watchers.delete(callback);
104
+ if (this.watchers.size === 0) {
105
+ this.stopPolling();
106
+ }
107
+ };
108
+ }
109
+ ensurePolling() {
110
+ if (this.pollTimer !== undefined) {
111
+ return;
112
+ }
113
+ const interval = this.pollInterval ?? 1000;
114
+ this.pollTimer = setInterval(() => {
115
+ this.checkForChanges();
116
+ }, interval);
117
+ }
118
+ stopPolling() {
119
+ if (this.pollTimer) {
120
+ clearInterval(this.pollTimer);
121
+ this.pollTimer = undefined;
122
+ }
123
+ }
124
+ recordCurrentValues() {
125
+ this.lastValues.clear();
126
+ const entries = this.list();
127
+ for (const entry of entries) {
128
+ const envKey = this.getEnvKey(entry.key);
129
+ const value = process.env[envKey];
130
+ if (value !== undefined) {
131
+ this.lastValues.set(envKey, value);
132
+ }
133
+ }
134
+ }
135
+ checkForChanges() {
136
+ const currentEntries = this.list();
137
+ const currentValues = new Map;
138
+ for (const entry of currentEntries) {
139
+ const envKey = this.getEnvKey(entry.key);
140
+ const value = process.env[envKey];
141
+ if (value !== undefined) {
142
+ currentValues.set(envKey, value);
143
+ }
144
+ }
145
+ for (const [envKey, oldValue] of this.lastValues.entries()) {
146
+ if (!currentValues.has(envKey)) {
147
+ const key = this.getInternalKey(envKey);
148
+ this.notifyWatchers({
149
+ type: "delete",
150
+ key,
151
+ oldValue: this.transformValue(oldValue, key),
152
+ newValue: undefined,
153
+ source: this.name,
154
+ timestamp: Date.now()
155
+ });
156
+ }
157
+ }
158
+ for (const [envKey, newValue] of currentValues.entries()) {
159
+ const key = this.getInternalKey(envKey);
160
+ const oldValue = this.lastValues.get(envKey);
161
+ if (oldValue === undefined) {
162
+ this.notifyWatchers({
163
+ type: "add",
164
+ key,
165
+ oldValue: undefined,
166
+ newValue: this.transformValue(newValue, key),
167
+ source: this.name,
168
+ timestamp: Date.now()
169
+ });
170
+ } else if (oldValue !== newValue) {
171
+ this.notifyWatchers({
172
+ type: "change",
173
+ key,
174
+ oldValue: this.transformValue(oldValue, key),
175
+ newValue: this.transformValue(newValue, key),
176
+ source: this.name,
177
+ timestamp: Date.now()
178
+ });
179
+ }
180
+ }
181
+ this.lastValues = currentValues;
182
+ }
183
+ transformValue(value, key) {
184
+ if (this.transform) {
185
+ return this.transform(value, key);
186
+ }
187
+ return value;
188
+ }
189
+ notifyWatchers(event) {
190
+ this.watchers.forEach((cb) => cb(event));
191
+ }
192
+ close() {
193
+ this.stopPolling();
194
+ this.watchers.clear();
195
+ }
196
+ validateUnrecognizedEnvVars(options = {}) {
197
+ const { componentName, knownKeys, logger } = options;
198
+ const prefixUpper = this.prefix.toUpperCase();
199
+ const unrecognized = [];
200
+ if (!knownKeys || knownKeys.size === 0) {
201
+ return unrecognized;
202
+ }
203
+ for (const envKey of Object.keys(process.env)) {
204
+ if (prefixUpper && !envKey.toUpperCase().startsWith(prefixUpper)) {
205
+ continue;
206
+ }
207
+ const configKey = componentName ? envKeyToConfigKey(envKey, this.prefix, componentName) : undefined;
208
+ const candidateKey = configKey ?? fromEnvKey(envKey, this.prefix).toLowerCase().replace(/_/g, ".");
209
+ const isKnown = Array.from(knownKeys).some((known) => {
210
+ if (known === candidateKey)
211
+ return true;
212
+ if (candidateKey.startsWith(known + "."))
213
+ return true;
214
+ return false;
215
+ });
216
+ if (!isKnown) {
217
+ const valuePreview = JSON.stringify(process.env[envKey]);
218
+ const truncated = valuePreview.length > 50 ? valuePreview.slice(0, 47) + "..." : valuePreview;
219
+ const msg = `[EnvSource] Unrecognized env var: ${envKey}=${truncated} ` + `(resolved config key "${candidateKey}" not in known keys: ${Array.from(knownKeys).join(", ") || "<empty>"}). ` + `Check spelling, or add the key to the component's known config keys.`;
220
+ unrecognized.push(envKey);
221
+ if (logger?.warn)
222
+ logger.warn(msg);
223
+ }
224
+ }
225
+ return unrecognized;
226
+ }
227
+ }
228
+
229
+ export { EnvSource };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  AgentComponentAdapter,
3
3
  init_agent_component_adapter
4
- } from "./roy-agent-core-g2ntbc33.js";
4
+ } from "./roy-agent-core-jenchn33.js";
5
5
  import"./roy-agent-core-1db4vpc6.js";
6
6
  import"./roy-agent-core-e25xkv53.js";
7
7
  import"./roy-agent-core-dbkkjmqz.js";
@@ -8,7 +8,7 @@ import {
8
8
  import {
9
9
  envKeyToConfigKey,
10
10
  toEnvKey
11
- } from "./roy-agent-core-qxhq8ven.js";
11
+ } from "./roy-agent-core-7hh0brvs.js";
12
12
  import {
13
13
  BaseComponent
14
14
  } from "./roy-agent-core-j62bjagf.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-setting/roy-agent-core",
3
- "version": "1.6.9",
3
+ "version": "1.6.11",
4
4
  "type": "module",
5
5
  "description": "Core SDK for roy-agent - Environment, Components, Tools, Sessions, Tasks",
6
6
  "main": "./dist/index.js",