@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
@@ -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.10",
4
4
  "type": "module",
5
5
  "description": "Core SDK for roy-agent - Environment, Components, Tools, Sessions, Tasks",
6
6
  "main": "./dist/index.js",