@ai-setting/roy-agent-core 1.4.12 → 1.4.14

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 (127) hide show
  1. package/dist/packages/core/src/config/index.js +32 -0
  2. package/dist/packages/core/src/env/agent/index.js +24 -0
  3. package/dist/packages/core/src/env/commands/index.js +14 -0
  4. package/dist/packages/core/src/env/debug/formatters/index.js +11 -0
  5. package/dist/packages/core/src/env/debug/index.js +26 -0
  6. package/dist/packages/core/src/env/hook/index.js +29 -0
  7. package/dist/packages/core/src/env/index.js +81 -0
  8. package/dist/packages/core/src/env/llm/index.js +40 -0
  9. package/dist/packages/core/src/env/log-trace/index.js +83 -0
  10. package/dist/packages/core/src/env/mcp/index.js +39 -0
  11. package/dist/packages/core/src/env/mcp/tool/index.js +14 -0
  12. package/dist/packages/core/src/env/memory/built-in/index.js +11 -0
  13. package/dist/packages/core/src/env/memory/index.js +56 -0
  14. package/dist/packages/core/src/env/memory/plugin/index.js +36 -0
  15. package/dist/packages/core/src/env/prompt/index.js +20 -0
  16. package/dist/packages/core/src/env/session/index.js +25 -0
  17. package/dist/packages/core/src/env/session/storage/index.js +18 -0
  18. package/dist/packages/core/src/env/skill/index.js +34 -0
  19. package/dist/packages/core/src/env/skill/tool/index.js +9 -0
  20. package/dist/packages/core/src/env/task/delegate/index.js +18 -0
  21. package/dist/packages/core/src/env/task/hooks/index.js +7 -0
  22. package/dist/packages/core/src/env/task/index.js +30 -0
  23. package/dist/packages/core/src/env/task/plugins/index.js +23 -0
  24. package/dist/packages/core/src/env/task/storage/index.js +14 -0
  25. package/dist/packages/core/src/env/task/tools/index.js +17 -0
  26. package/dist/packages/core/src/env/task/tools/operation/index.js +15 -0
  27. package/dist/packages/core/src/env/tool/built-in/index.js +25 -0
  28. package/dist/packages/core/src/env/tool/index.js +39 -0
  29. package/dist/packages/core/src/env/workflow/decorators/index.js +27 -0
  30. package/dist/packages/core/src/env/workflow/engine/index.js +28 -0
  31. package/dist/packages/core/src/env/workflow/index.js +132 -0
  32. package/dist/packages/core/src/env/workflow/nodes/index.js +19 -0
  33. package/dist/packages/core/src/env/workflow/service/index.js +13 -0
  34. package/dist/packages/core/src/env/workflow/storage/index.js +27 -0
  35. package/dist/packages/core/src/env/workflow/tools/index.js +159 -0
  36. package/dist/packages/core/src/env/workflow/types/index.js +94 -0
  37. package/dist/packages/core/src/env/workflow/utils/index.js +637 -0
  38. package/dist/packages/core/src/index.js +398 -0
  39. package/dist/shared/@ai-setting/roy-agent-core-04fm8177.js +393 -0
  40. package/dist/shared/@ai-setting/roy-agent-core-04qgbjbe.js +172 -0
  41. package/dist/shared/@ai-setting/roy-agent-core-084qqd7t.js +11 -0
  42. package/dist/shared/@ai-setting/roy-agent-core-0gekht4e.js +1130 -0
  43. package/dist/shared/@ai-setting/roy-agent-core-0hdry23r.js +419 -0
  44. package/dist/shared/@ai-setting/roy-agent-core-0sgn3de4.js +102 -0
  45. package/dist/{env/task/tools/index.js → shared/@ai-setting/roy-agent-core-12x57kf1.js} +1 -59
  46. package/dist/shared/@ai-setting/roy-agent-core-1f3xrrm6.js +393 -0
  47. package/dist/shared/@ai-setting/roy-agent-core-1k28kg7h.js +368 -0
  48. package/dist/shared/@ai-setting/roy-agent-core-1z1zv5g8.js +258 -0
  49. package/dist/shared/@ai-setting/roy-agent-core-2hqxnaf3.js +851 -0
  50. package/dist/shared/@ai-setting/roy-agent-core-3dfq8awb.js +587 -0
  51. package/dist/shared/@ai-setting/roy-agent-core-3takar0s.js +93 -0
  52. package/dist/shared/@ai-setting/roy-agent-core-3tnb2005.js +117 -0
  53. package/dist/shared/@ai-setting/roy-agent-core-4vmcvkav.js +14 -0
  54. package/dist/shared/@ai-setting/roy-agent-core-4ws8atva.js +107 -0
  55. package/dist/{env/workflow/nodes/index.js → shared/@ai-setting/roy-agent-core-5fbp24se.js} +8 -55
  56. package/dist/shared/@ai-setting/roy-agent-core-5my94ywp.js +66 -0
  57. package/dist/shared/@ai-setting/roy-agent-core-6j0zcmwk.js +2146 -0
  58. package/dist/shared/@ai-setting/roy-agent-core-6w4pmxc7.js +266 -0
  59. package/dist/shared/@ai-setting/roy-agent-core-7vrk3add.js +10 -0
  60. package/dist/shared/@ai-setting/roy-agent-core-8dvbn7tw.js +64 -0
  61. package/dist/{env/memory/built-in/index.js → shared/@ai-setting/roy-agent-core-8mbmrwzs.js} +22 -76
  62. package/dist/shared/@ai-setting/roy-agent-core-8wzz66qe.js +620 -0
  63. package/dist/shared/@ai-setting/roy-agent-core-9ykq91jc.js +762 -0
  64. package/dist/shared/@ai-setting/roy-agent-core-dde19zke.js +1305 -0
  65. package/dist/shared/@ai-setting/roy-agent-core-f7g67gce.js +913 -0
  66. package/dist/{env/workflow/types/index.js → shared/@ai-setting/roy-agent-core-fq5mtxsy.js} +16 -154
  67. package/dist/{env/task/hooks/index.js → shared/@ai-setting/roy-agent-core-fs0mn2jk.js} +3 -18
  68. package/dist/{config/index.js → shared/@ai-setting/roy-agent-core-fvd9g6k8.js} +140 -605
  69. package/dist/shared/@ai-setting/roy-agent-core-gv1hrn3x.js +378 -0
  70. package/dist/{env/task/tools/operation/index.js → shared/@ai-setting/roy-agent-core-gy0wp5h7.js} +1 -58
  71. package/dist/shared/@ai-setting/roy-agent-core-hyza1gm7.js +15 -0
  72. package/dist/shared/@ai-setting/roy-agent-core-j8zx62zr.js +154 -0
  73. package/dist/shared/@ai-setting/roy-agent-core-jb2exr0d.js +442 -0
  74. package/dist/shared/@ai-setting/roy-agent-core-jv3b7v9w.js +57 -0
  75. package/dist/shared/@ai-setting/roy-agent-core-k1rxf9ya.js +513 -0
  76. package/dist/shared/@ai-setting/roy-agent-core-kydc9nwb.js +60 -0
  77. package/dist/shared/@ai-setting/roy-agent-core-m2x48hw6.js +97 -0
  78. package/dist/shared/@ai-setting/roy-agent-core-m6y668cc.js +377 -0
  79. package/dist/shared/@ai-setting/roy-agent-core-nczzf0ms.js +15 -0
  80. package/dist/shared/@ai-setting/roy-agent-core-nfj6knp5.js +36 -0
  81. package/dist/shared/@ai-setting/roy-agent-core-ntrp979d.js +204 -0
  82. package/dist/shared/@ai-setting/roy-agent-core-pd7g8z5v.js +1387 -0
  83. package/dist/shared/@ai-setting/roy-agent-core-pzk1syce.js +14 -0
  84. package/dist/shared/@ai-setting/roy-agent-core-q50tg9m2.js +862 -0
  85. package/dist/shared/@ai-setting/roy-agent-core-qg9tcaph.js +11 -0
  86. package/dist/shared/@ai-setting/roy-agent-core-qhyerewk.js +20 -0
  87. package/dist/shared/@ai-setting/roy-agent-core-qxybm159.js +82 -0
  88. package/dist/shared/@ai-setting/roy-agent-core-rh9dpkpw.js +549 -0
  89. package/dist/shared/@ai-setting/roy-agent-core-rr9p1g43.js +205 -0
  90. package/dist/{env/workflow/decorators/index.js → shared/@ai-setting/roy-agent-core-sbzvpfn7.js} +8 -173
  91. package/dist/shared/@ai-setting/roy-agent-core-t22nqt4d.js +788 -0
  92. package/dist/shared/@ai-setting/roy-agent-core-tkr5ynkh.js +200 -0
  93. package/dist/shared/@ai-setting/roy-agent-core-v4aabsf0.js +303 -0
  94. package/dist/{env/hook/index.js → shared/@ai-setting/roy-agent-core-w75rafhy.js} +3 -74
  95. package/dist/{env/debug/formatters/index.js → shared/@ai-setting/roy-agent-core-w76hqkmg.js} +11 -66
  96. package/dist/shared/@ai-setting/roy-agent-core-yfbgwes2.js +408 -0
  97. package/dist/shared/@ai-setting/roy-agent-core-yn761yve.js +299 -0
  98. package/dist/shared/@ai-setting/roy-agent-core-yrzmn4m1.js +492 -0
  99. package/dist/{env/workflow/service/index.js → shared/@ai-setting/roy-agent-core-yt8wdh2w.js} +1 -57
  100. package/package.json +3 -2
  101. package/dist/env/agent/index.js +0 -3035
  102. package/dist/env/commands/index.js +0 -1685
  103. package/dist/env/debug/index.js +0 -2300
  104. package/dist/env/index.js +0 -12591
  105. package/dist/env/llm/index.js +0 -2736
  106. package/dist/env/log-trace/index.js +0 -1779
  107. package/dist/env/mcp/index.js +0 -2173
  108. package/dist/env/mcp/tool/index.js +0 -1149
  109. package/dist/env/memory/index.js +0 -2171
  110. package/dist/env/memory/plugin/index.js +0 -1263
  111. package/dist/env/prompt/index.js +0 -2107
  112. package/dist/env/session/index.js +0 -3594
  113. package/dist/env/session/storage/index.js +0 -2049
  114. package/dist/env/skill/index.js +0 -1635
  115. package/dist/env/skill/tool/index.js +0 -114
  116. package/dist/env/task/delegate/index.js +0 -1844
  117. package/dist/env/task/index.js +0 -3578
  118. package/dist/env/task/plugins/index.js +0 -1626
  119. package/dist/env/task/storage/index.js +0 -1464
  120. package/dist/env/tool/built-in/index.js +0 -1151
  121. package/dist/env/tool/index.js +0 -2284
  122. package/dist/env/workflow/engine/index.js +0 -4391
  123. package/dist/env/workflow/index.js +0 -6214
  124. package/dist/env/workflow/storage/index.js +0 -1236
  125. package/dist/env/workflow/tools/index.js +0 -1081
  126. package/dist/env/workflow/utils/index.js +0 -1631
  127. package/dist/index.js +0 -22778
@@ -1,528 +1,16 @@
1
- // @bun
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- function __accessProp(key) {
7
- return this[key];
8
- }
9
- var __toCommonJS = (from) => {
10
- var entry = (__moduleCache ??= new WeakMap).get(from), desc;
11
- if (entry)
12
- return entry;
13
- entry = __defProp({}, "__esModule", { value: true });
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (var key of __getOwnPropNames(from))
16
- if (!__hasOwnProp.call(entry, key))
17
- __defProp(entry, key, {
18
- get: __accessProp.bind(from, key),
19
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
20
- });
21
- }
22
- __moduleCache.set(from, entry);
23
- return entry;
24
- };
25
- var __moduleCache;
26
- var __returnValue = (v) => v;
27
- function __exportSetter(name, newValue) {
28
- this[name] = __returnValue.bind(null, newValue);
29
- }
30
- var __export = (target, all) => {
31
- for (var name in all)
32
- __defProp(target, name, {
33
- get: all[name],
34
- enumerable: true,
35
- configurable: true,
36
- set: __exportSetter.bind(all, name)
37
- });
38
- };
39
- var __legacyDecorateClassTS = function(decorators, target, key, desc) {
40
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
41
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
42
- r = Reflect.decorate(decorators, target, key, desc);
43
- else
44
- for (var i = decorators.length - 1;i >= 0; i--)
45
- if (d = decorators[i])
46
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
47
- return c > 3 && r && Object.defineProperty(target, key, r), r;
48
- };
49
- var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
50
- var __require = import.meta.require;
51
-
52
- // packages/core/src/env/hook/types.ts
53
- function createHook(meta, fn) {
54
- return {
55
- ...meta,
56
- execute: fn
57
- };
58
- }
59
- function createPriorityHook(name, fn, priority) {
60
- return createHook({ name, priority }, fn);
61
- }
62
- // packages/core/src/env/hook/hook-manager.ts
63
- class HookManager {
64
- _hooks = new Map;
65
- componentName;
66
- componentVersion;
67
- defaultPriority;
68
- constructor(options = {}) {
69
- this.componentName = options.componentName ?? "unknown";
70
- this.componentVersion = options.componentVersion ?? "0.0.0";
71
- this.defaultPriority = options.defaultPriority ?? 0;
72
- }
73
- register(hookPoint, hook) {
74
- const hooks = this.getOrCreateHooks(hookPoint);
75
- hooks.push(hook);
76
- }
77
- registerMany(hookPoint, hooks) {
78
- const hookList = this.getOrCreateHooks(hookPoint);
79
- hookList.push(...hooks);
80
- }
81
- unregister(hookPoint, name) {
82
- const hooks = this._hooks.get(hookPoint);
83
- if (!hooks)
84
- return false;
85
- const index = hooks.findIndex((h) => h.name === name);
86
- if (index === -1)
87
- return false;
88
- hooks.splice(index, 1);
89
- return true;
90
- }
91
- unregisterAll(hookPoint) {
92
- this._hooks.delete(hookPoint);
93
- }
94
- async execute(hookPoint, data, metadata = {}) {
95
- const hooks = this._hooks.get(hookPoint);
96
- if (!hooks || hooks.length === 0)
97
- return;
98
- const sortedHooks = this.sortHooks(hooks);
99
- const ctx = this.createContext(hookPoint, data, metadata, "before");
100
- for (const hook of sortedHooks) {
101
- await this.safeExecute(hook, ctx);
102
- }
103
- }
104
- async executeAndCollect(hookPoint, data, metadata = {}) {
105
- const hooks = this._hooks.get(hookPoint);
106
- if (!hooks || hooks.length === 0)
107
- return [];
108
- const sortedHooks = this.sortHooks(hooks);
109
- const ctx = this.createContext(hookPoint, data, metadata, "before");
110
- const results = [];
111
- for (const hook of sortedHooks) {
112
- const result = await this.safeExecuteAndReturn(hook, ctx);
113
- if (result !== undefined) {
114
- results.push(result);
115
- }
116
- }
117
- return results;
118
- }
119
- count(hookPoint) {
120
- return this._hooks.get(hookPoint)?.length ?? 0;
121
- }
122
- clear() {
123
- this._hooks.clear();
124
- }
125
- getHookPoints() {
126
- return Array.from(this._hooks.keys());
127
- }
128
- hasHooks(hookPoint) {
129
- return this.count(hookPoint) > 0;
130
- }
131
- setComponentInfo(name, version) {
132
- this.componentName = name;
133
- this.componentVersion = version;
134
- }
135
- get hooks() {
136
- return this._hooks;
137
- }
138
- async executeWithIntervention(hookPoint, data, metadata = {}) {
139
- const hooks = this._hooks.get(hookPoint);
140
- if (!hooks || hooks.length === 0) {
141
- return { stopped: false, results: [] };
142
- }
143
- const sortedHooks = this.sortHooks(hooks);
144
- const ctx = this.createContext(hookPoint, data, metadata, "before");
145
- const results = [];
146
- let stopped = false;
147
- let action;
148
- for (const hook of sortedHooks) {
149
- if (stopped)
150
- break;
151
- const result = await this.safeExecuteAndReturn(hook, ctx);
152
- results.push(result);
153
- if (result && typeof result === "object" && "stopped" in result) {
154
- const hookResult = result;
155
- if (hookResult.stopped) {
156
- stopped = true;
157
- action = hookResult.action;
158
- }
159
- }
160
- }
161
- return { stopped, action, results };
162
- }
163
- getOrCreateHooks(hookPoint) {
164
- let hooks = this._hooks.get(hookPoint);
165
- if (!hooks) {
166
- hooks = [];
167
- this._hooks.set(hookPoint, hooks);
168
- }
169
- return hooks;
170
- }
171
- sortHooks(hooks) {
172
- return [...hooks].sort((a, b) => {
173
- const priorityA = a.priority ?? this.defaultPriority;
174
- const priorityB = b.priority ?? this.defaultPriority;
175
- return priorityA - priorityB;
176
- });
177
- }
178
- createContext(hookPoint, data, metadata, phase) {
179
- return {
180
- component: {
181
- name: this.componentName,
182
- version: this.componentVersion
183
- },
184
- data,
185
- metadata,
186
- phase,
187
- hookPoint
188
- };
189
- }
190
- async safeExecute(hook, ctx) {
191
- try {
192
- await hook.execute(ctx);
193
- } catch (error) {
194
- console.error(`Hook "${hook.name}" failed:`, error);
195
- }
196
- }
197
- async safeExecuteAndReturn(hook, ctx) {
198
- try {
199
- return await hook.execute(ctx);
200
- } catch (error) {
201
- console.error(`Hook "${hook.name}" failed:`, error);
202
- return;
203
- }
204
- }
205
- }
206
- // packages/core/src/env/hook/global-hook-manager.ts
207
- var globalHookManager = new HookManager;
208
- var AgentHookPoints = {
209
- BEFORE_START: "agent:before.start",
210
- BEFORE_LLM: "agent:before.llm",
211
- AFTER_LLM: "agent:after.llm",
212
- BEFORE_TOOL: "agent:before.tool",
213
- AFTER_TOOL: "agent:after.tool",
214
- ON_ITERATION: "agent:on.iteration",
215
- ON_THRESHOLD: "agent:on.threshold",
216
- AFTER_COMPLETE: "agent:after.complete",
217
- ON_ERROR: "agent:on.error"
218
- };
219
- var LLMHookPoints = {
220
- BEFORE_INVOKE: "llm:before.invoke",
221
- AFTER_INVOKE: "llm:after.invoke",
222
- ON_STREAM: "llm:on.stream"
223
- };
224
- var ToolHookPoints = {
225
- BEFORE_EXECUTE: "tool:before.execute",
226
- AFTER_EXECUTE: "tool:after.execute",
227
- BEFORE_REGISTER: "tool:before.register",
228
- AFTER_REGISTER: "tool:after.register",
229
- ON_ERROR: "tool:on.error"
230
- };
231
- var hookPointAliases = {
232
- "before.tool": "tool:before.execute",
233
- "after.tool": "tool:after.execute",
234
- "llm.before-invoke": "llm:before.invoke",
235
- "llm.after-invoke": "llm:after.invoke",
236
- "llm.stream": "llm:on.stream"
237
- };
238
- function setupAliasHooks() {
239
- const originalRegister = globalHookManager.register.bind(globalHookManager);
240
- globalHookManager.register = function(hookPoint, hook) {
241
- originalRegister(hookPoint, hook);
242
- const alias = hookPointAliases[hookPoint];
243
- if (alias) {
244
- originalRegister(alias, hook);
245
- }
246
- };
247
- }
248
- setupAliasHooks();
249
- async function executeAgentHook(hookPoint, data, metadata = {}) {
250
- await globalHookManager.execute(hookPoint, data, metadata);
251
- }
252
- async function executeAgentHookWithIntervention(hookPoint, data, metadata = {}) {
253
- return globalHookManager.executeWithIntervention(hookPoint, data, metadata);
254
- }
255
- async function executeLLMHook(hookPoint, data, metadata = {}) {
256
- await globalHookManager.execute(hookPoint, data, metadata);
257
- }
258
- async function executeToolHook(hookPoint, data, metadata = {}) {
259
- await globalHookManager.execute(hookPoint, data, metadata);
260
- }
261
- // packages/core/src/env/component.ts
262
- class BaseComponent {
263
- _status = "created";
264
- _enabled = true;
265
- env;
266
- hookManager;
267
- constructor() {
268
- this.hookManager = new HookManager;
269
- }
270
- getStatus() {
271
- return this._status;
272
- }
273
- getConfig() {
274
- return {
275
- name: this.name,
276
- version: this.version,
277
- enabled: this._enabled,
278
- env: this.env
279
- };
280
- }
281
- isEnvInitialized() {
282
- return this._status !== "created";
283
- }
284
- setStatus(status) {
285
- this._status = status;
286
- }
287
- getEnv() {
288
- return this.env;
289
- }
290
- async init(config) {
291
- if (config?.env) {
292
- this.env = config.env;
293
- }
294
- this.setStatus("initializing");
295
- try {
296
- if (config?.name)
297
- Object.defineProperty(this, "name", { value: config.name, writable: false });
298
- if (config?.version)
299
- Object.defineProperty(this, "version", { value: config.version, writable: false });
300
- } catch {}
301
- if (config?.enabled !== undefined)
302
- this._enabled = config.enabled;
303
- this.hookManager.setComponentInfo(this.name, this.version);
304
- await this.onInit();
305
- this.setStatus("running");
306
- }
307
- async start() {
308
- if (this._started)
309
- return;
310
- this._started = true;
311
- await this.onStart();
312
- this.setStatus("running");
313
- }
314
- async stop() {
315
- this.setStatus("stopping");
316
- this.hookManager.clear();
317
- await this.onStop();
318
- this.setStatus("stopped");
319
- }
320
- async onInit() {}
321
- async onStart() {}
322
- async onStop() {}
323
- registerHook(hookPoint, hook) {
324
- this.hookManager.register(hookPoint, hook);
325
- }
326
- addHook(hookPoint, name, fn, priority) {
327
- this.hookManager.register(hookPoint, createHook({ name, priority }, fn));
328
- }
329
- removeHook(hookPoint, name) {
330
- return this.hookManager.unregister(hookPoint, name);
331
- }
332
- async executeHooks(hookPoint, data, metadata) {
333
- await this.hookManager.execute(hookPoint, data, metadata);
334
- }
335
- getConfigComponent() {
336
- return this.env?.getComponent("config");
337
- }
338
- getRuntimeConfig(key, defaultValue) {
339
- const configComponent = this.getConfigComponent();
340
- if (configComponent) {
341
- const value = configComponent.get(key);
342
- if (value !== undefined) {
343
- return value;
344
- }
345
- }
346
- return defaultValue;
347
- }
348
- }
349
-
350
- // packages/core/src/env/paths.ts
351
- import os from "os";
352
- import path from "path";
353
- var APP_NAME = "roy-agent";
354
- function getXdgBase() {
355
- const home = os.homedir();
356
- try {
357
- const xdg = __require("xdg-basedir");
358
- return {
359
- config: xdg.xdgConfig || path.join(home, ".config"),
360
- state: xdg.xdgState || path.join(home, ".local", "state"),
361
- data: xdg.xdgData || path.join(home, ".local", "share"),
362
- cache: xdg.xdgCache || path.join(home, ".cache")
363
- };
364
- } catch {
365
- return {
366
- config: path.join(home, ".config"),
367
- state: path.join(home, ".local", "state"),
368
- data: path.join(home, ".local", "share"),
369
- cache: path.join(home, ".cache")
370
- };
371
- }
372
- }
373
- function computeXDGPaths() {
374
- const home = os.homedir();
375
- const xdg = getXdgBase();
376
- return {
377
- home,
378
- config: path.join(xdg.config, APP_NAME),
379
- state: path.join(xdg.state, APP_NAME),
380
- data: path.join(xdg.data, APP_NAME),
381
- cache: path.join(xdg.cache, APP_NAME)
382
- };
383
- }
384
-
385
- class XDGPathsCalculator {
386
- _paths;
387
- get paths() {
388
- if (!this._paths) {
389
- this._paths = computeXDGPaths();
390
- }
391
- return this._paths;
392
- }
393
- getPath(type) {
394
- return this.paths[type];
395
- }
396
- getComponentPath(base, subPath) {
397
- return path.join(this.paths[base], subPath);
398
- }
399
- reset() {
400
- this._paths = undefined;
401
- }
402
- }
403
- var XDG_PATHS = new XDGPathsCalculator;
404
- function getXDGPaths() {
405
- return XDG_PATHS.paths;
406
- }
407
- function getXDGPath(type) {
408
- return XDG_PATHS.getPath(type);
409
- }
410
-
411
- // packages/core/src/config/protocol-resolver.ts
412
- var PROTOCOL_PATTERN = /^\$\{([^:]+):\/\/([^:#]+)(?:#([^:-]+))?(?::-(.*))?\}$/;
413
-
414
- class ProtocolResolver {
415
- _xdgDataHome;
416
- readFileFn;
417
- constructor(options = {}) {
418
- this._xdgDataHome = options.xdgDataHome ?? ProtocolResolver.getDefaultXDGDataHome();
419
- if (options.readFileFn) {
420
- this.readFileFn = options.readFileFn;
421
- } else {
422
- const fsSync = __require("fs");
423
- this.readFileFn = (path2) => fsSync.readFileSync(path2, "utf-8");
424
- }
425
- }
426
- get xdgDataHome() {
427
- return this._xdgDataHome;
428
- }
429
- set xdgDataHome(value) {
430
- this._xdgDataHome = value;
431
- }
432
- static getDefaultXDGDataHome() {
433
- return process.env.XDG_DATA_HOME ?? `${process.env.HOME ?? "~"}/.local/share`;
434
- }
435
- parse(ref) {
436
- const match = ref.match(PROTOCOL_PATTERN);
437
- if (!match)
438
- return null;
439
- const [, protocol, path2, key, defaultValue] = match;
440
- if (!["file", "env"].includes(protocol))
441
- return null;
442
- return {
443
- protocol,
444
- path: path2,
445
- key: key ?? "",
446
- defaultValue,
447
- raw: ref
448
- };
449
- }
450
- isProtocolRef(value) {
451
- return PROTOCOL_PATTERN.test(value);
452
- }
453
- resolve(ref) {
454
- const parsed = this.parse(ref);
455
- if (!parsed)
456
- return null;
457
- const value = this.resolveInternal(parsed);
458
- if (parsed.protocol === "file" && value === undefined) {
459
- return null;
460
- }
461
- if (value === undefined && parsed.protocol === "env" && parsed.defaultValue === undefined) {
462
- return null;
463
- }
464
- if (value === undefined && parsed.defaultValue !== undefined) {
465
- return {
466
- value: parsed.defaultValue,
467
- source: parsed.protocol
468
- };
469
- }
470
- return {
471
- value,
472
- source: parsed.protocol
473
- };
474
- }
475
- resolveFileRef(filePath, key) {
476
- const resolvedPath = this.resolvePath(filePath);
477
- try {
478
- const content = this.readFileFn(resolvedPath);
479
- let data;
480
- try {
481
- data = JSON.parse(content);
482
- } catch {
483
- return content;
484
- }
485
- return this.getNestedValue(data, key);
486
- } catch {
487
- return;
488
- }
489
- }
490
- resolveInternal(ref) {
491
- switch (ref.protocol) {
492
- case "env":
493
- return process.env[ref.path];
494
- case "file":
495
- return this.resolveFileRef(ref.path, ref.key);
496
- }
497
- }
498
- resolvePath(filePath) {
499
- if (filePath.startsWith("/")) {
500
- return filePath;
501
- }
502
- if (filePath.startsWith("~")) {
503
- return filePath.replace("~", process.env.HOME ?? "");
504
- }
505
- return `${this._xdgDataHome}/${filePath}`;
506
- }
507
- getNestedValue(obj, key) {
508
- if (key === "$" || key === "")
509
- return obj;
510
- const keys = key.split(".");
511
- let current = obj;
512
- for (const k of keys) {
513
- if (current === null || current === undefined || typeof current !== "object") {
514
- return;
515
- }
516
- current = current[k];
517
- }
518
- return current;
519
- }
520
- }
521
-
522
- // packages/core/src/config/file-source.ts
523
- import * as fsSync from "fs";
524
- import * as fsPromises from "fs/promises";
525
- import path2 from "path";
1
+ import {
2
+ XDG_PATHS
3
+ } from "./roy-agent-core-5my94ywp.js";
4
+ import {
5
+ fromEnvKey,
6
+ toEnvKey
7
+ } from "./roy-agent-core-jv3b7v9w.js";
8
+ import {
9
+ BaseComponent
10
+ } from "./roy-agent-core-m2x48hw6.js";
11
+ import {
12
+ __require
13
+ } from "./roy-agent-core-fs0mn2jk.js";
526
14
 
527
15
  // packages/core/src/config/config-parser.ts
528
16
  import { parse as parseJSONCInternal, ParseErrorCode } from "jsonc-parser";
@@ -633,6 +121,9 @@ function parseJSONCWithProtocols(content, resolver) {
633
121
  }
634
122
 
635
123
  // packages/core/src/config/file-source.ts
124
+ import * as fsSync from "fs";
125
+ import * as fsPromises from "fs/promises";
126
+ import path from "path";
636
127
  class FileSource {
637
128
  name = "file";
638
129
  priority = 10;
@@ -787,7 +278,7 @@ class FileSource {
787
278
  }
788
279
  persistToFile() {
789
280
  try {
790
- const dir = path2.dirname(this.filePath);
281
+ const dir = path.dirname(this.filePath);
791
282
  if (!fsSync.existsSync(dir)) {
792
283
  fsSync.mkdirSync(dir, { recursive: true });
793
284
  }
@@ -931,62 +422,6 @@ class FileSource {
931
422
  }
932
423
  }
933
424
 
934
- // packages/core/src/config/env-key.ts
935
- function toEnvKey(key, prefix) {
936
- let keyNormalized = key.replace(/[.-]/g, "_");
937
- keyNormalized = keyNormalized.replace(/([a-z])([A-Z])/g, "$1_$2").replace(/_+/g, "_").toUpperCase();
938
- if (prefix) {
939
- const separator = prefix.endsWith("_") ? "" : "_";
940
- return `${prefix}${separator}${keyNormalized}`;
941
- }
942
- return keyNormalized;
943
- }
944
- function fromEnvKey(envKey, prefix) {
945
- if (!prefix) {
946
- return envKey;
947
- }
948
- if (envKey.startsWith(prefix)) {
949
- const afterPrefix = envKey.slice(prefix.length);
950
- if (afterPrefix.startsWith("_")) {
951
- return afterPrefix.slice(1);
952
- }
953
- return afterPrefix;
954
- }
955
- return envKey;
956
- }
957
- function envKeyToConfigKey(envKey, prefix, componentName) {
958
- const prefixUpper = prefix.toUpperCase();
959
- if (!envKey.startsWith(prefixUpper)) {
960
- return;
961
- }
962
- const componentUpperNormalized = componentName.replace(/-/g, "_").toUpperCase();
963
- let keyPart = envKey.slice(prefixUpper.length);
964
- if (keyPart.startsWith("_")) {
965
- keyPart = keyPart.slice(1);
966
- }
967
- if (!keyPart) {
968
- return;
969
- }
970
- const firstUnderscore = keyPart.indexOf("_");
971
- let restPart;
972
- if (firstUnderscore === -1) {
973
- restPart = keyPart;
974
- } else {
975
- const firstPart = keyPart.slice(0, firstUnderscore);
976
- const remaining = keyPart.slice(firstUnderscore + 1);
977
- if (firstPart === componentUpperNormalized) {
978
- restPart = remaining;
979
- } else {
980
- restPart = keyPart;
981
- }
982
- }
983
- if (!restPart) {
984
- return;
985
- }
986
- const restPartConverted = restPart.replace(/_/g, ".");
987
- return `${componentName}.${restPartConverted.toLowerCase()}`;
988
- }
989
-
990
425
  // packages/core/src/config/env-source.ts
991
426
  class EnvSource {
992
427
  name = "env";
@@ -1178,13 +613,124 @@ class EnvSource {
1178
613
  }
1179
614
  }
1180
615
 
616
+ // packages/core/src/config/protocol-resolver.ts
617
+ var PROTOCOL_PATTERN = /^\$\{([^:]+):\/\/([^:#]+)(?:#([^:-]+))?(?::-(.*))?\}$/;
618
+
619
+ class ProtocolResolver {
620
+ _xdgDataHome;
621
+ readFileFn;
622
+ constructor(options = {}) {
623
+ this._xdgDataHome = options.xdgDataHome ?? ProtocolResolver.getDefaultXDGDataHome();
624
+ if (options.readFileFn) {
625
+ this.readFileFn = options.readFileFn;
626
+ } else {
627
+ const fsSync2 = __require("fs");
628
+ this.readFileFn = (path2) => fsSync2.readFileSync(path2, "utf-8");
629
+ }
630
+ }
631
+ get xdgDataHome() {
632
+ return this._xdgDataHome;
633
+ }
634
+ set xdgDataHome(value) {
635
+ this._xdgDataHome = value;
636
+ }
637
+ static getDefaultXDGDataHome() {
638
+ return process.env.XDG_DATA_HOME ?? `${process.env.HOME ?? "~"}/.local/share`;
639
+ }
640
+ parse(ref) {
641
+ const match = ref.match(PROTOCOL_PATTERN);
642
+ if (!match)
643
+ return null;
644
+ const [, protocol, path2, key, defaultValue] = match;
645
+ if (!["file", "env"].includes(protocol))
646
+ return null;
647
+ return {
648
+ protocol,
649
+ path: path2,
650
+ key: key ?? "",
651
+ defaultValue,
652
+ raw: ref
653
+ };
654
+ }
655
+ isProtocolRef(value) {
656
+ return PROTOCOL_PATTERN.test(value);
657
+ }
658
+ resolve(ref) {
659
+ const parsed = this.parse(ref);
660
+ if (!parsed)
661
+ return null;
662
+ const value = this.resolveInternal(parsed);
663
+ if (parsed.protocol === "file" && value === undefined) {
664
+ return null;
665
+ }
666
+ if (value === undefined && parsed.protocol === "env" && parsed.defaultValue === undefined) {
667
+ return null;
668
+ }
669
+ if (value === undefined && parsed.defaultValue !== undefined) {
670
+ return {
671
+ value: parsed.defaultValue,
672
+ source: parsed.protocol
673
+ };
674
+ }
675
+ return {
676
+ value,
677
+ source: parsed.protocol
678
+ };
679
+ }
680
+ resolveFileRef(filePath, key) {
681
+ const resolvedPath = this.resolvePath(filePath);
682
+ try {
683
+ const content = this.readFileFn(resolvedPath);
684
+ let data;
685
+ try {
686
+ data = JSON.parse(content);
687
+ } catch {
688
+ return content;
689
+ }
690
+ return this.getNestedValue(data, key);
691
+ } catch {
692
+ return;
693
+ }
694
+ }
695
+ resolveInternal(ref) {
696
+ switch (ref.protocol) {
697
+ case "env":
698
+ return process.env[ref.path];
699
+ case "file":
700
+ return this.resolveFileRef(ref.path, ref.key);
701
+ }
702
+ }
703
+ resolvePath(filePath) {
704
+ if (filePath.startsWith("/")) {
705
+ return filePath;
706
+ }
707
+ if (filePath.startsWith("~")) {
708
+ return filePath.replace("~", process.env.HOME ?? "");
709
+ }
710
+ return `${this._xdgDataHome}/${filePath}`;
711
+ }
712
+ getNestedValue(obj, key) {
713
+ if (key === "$" || key === "")
714
+ return obj;
715
+ const keys = key.split(".");
716
+ let current = obj;
717
+ for (const k of keys) {
718
+ if (current === null || current === undefined || typeof current !== "object") {
719
+ return;
720
+ }
721
+ current = current[k];
722
+ }
723
+ return current;
724
+ }
725
+ }
726
+
1181
727
  // packages/core/src/config/config-component.ts
1182
- import * as os2 from "os";
1183
- import * as path3 from "path";
728
+ import * as os from "os";
729
+ import * as path2 from "path";
1184
730
 
1185
731
  class ConfigSourceNotFoundError extends Error {
1186
- constructor(sourceType, path4) {
1187
- const message = path4 ? `Config source not found: ${sourceType} at ${path4}` : `Config source not found: ${sourceType}`;
732
+ constructor(sourceType, path3) {
733
+ const message = path3 ? `Config source not found: ${sourceType} at ${path3}` : `Config source not found: ${sourceType}`;
1188
734
  super(message);
1189
735
  this.name = "ConfigSourceNotFoundError";
1190
736
  }
@@ -1323,12 +869,12 @@ class ConfigComponent extends BaseComponent {
1323
869
  pendingSources = [];
1324
870
  sourceKeys = new Map;
1325
871
  getXdgDataHome() {
1326
- return this.__xdgDataHome ?? process.env.XDG_DATA_HOME ?? path3.join(os2.homedir(), ".local", "share");
872
+ return this.__xdgDataHome ?? process.env.XDG_DATA_HOME ?? path2.join(os.homedir(), ".local", "share");
1327
873
  }
1328
- setXdgDataHome(path4) {
1329
- this.__xdgDataHome = path4;
874
+ setXdgDataHome(path3) {
875
+ this.__xdgDataHome = path3;
1330
876
  if (this.protocolResolver) {
1331
- this.protocolResolver.xdgDataHome = path4;
877
+ this.protocolResolver.xdgDataHome = path3;
1332
878
  }
1333
879
  }
1334
880
  constructor(options = {}) {
@@ -1548,7 +1094,7 @@ class ConfigComponent extends BaseComponent {
1548
1094
  if (!relativePath) {
1549
1095
  throw new Error("File source requires relativePath");
1550
1096
  }
1551
- const isAbsolutePath = path3.isAbsolute(relativePath) || relativePath.startsWith("file://");
1097
+ const isAbsolutePath = path2.isAbsolute(relativePath) || relativePath.startsWith("file://");
1552
1098
  let filePath;
1553
1099
  if (isAbsolutePath) {
1554
1100
  filePath = relativePath.startsWith("file://") ? relativePath.replace(/^file:\/\//, "") : relativePath;
@@ -1556,7 +1102,7 @@ class ConfigComponent extends BaseComponent {
1556
1102
  if (this.protocolResolver) {
1557
1103
  this.protocolResolver.xdgDataHome = this.getXdgDataHome();
1558
1104
  }
1559
- filePath = path3.join(this.getXdgDataHome(), relativePath);
1105
+ filePath = path2.join(this.getXdgDataHome(), relativePath);
1560
1106
  }
1561
1107
  return new FileSource({
1562
1108
  filePath,
@@ -1655,16 +1201,5 @@ class ConfigComponent extends BaseComponent {
1655
1201
  return [...this.sources];
1656
1202
  }
1657
1203
  }
1658
- export {
1659
- substituteProtocolRefs,
1660
- substituteEnvVars,
1661
- parseJSONCWithProtocols,
1662
- parseJSONCWithEnv,
1663
- parseJSONC,
1664
- MemorySource,
1665
- FileSource,
1666
- EnvSource,
1667
- ConfigSourceNotFoundError,
1668
- ConfigFileNotFoundError,
1669
- ConfigComponent
1670
- };
1204
+
1205
+ export { parseJSONC, substituteEnvVars, parseJSONCWithEnv, substituteProtocolRefs, parseJSONCWithProtocols, FileSource, EnvSource, ConfigSourceNotFoundError, ConfigFileNotFoundError, MemorySource, ConfigComponent };