@crewx/sdk 0.8.0-rc.79 → 0.8.0-rc.82

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 (292) hide show
  1. package/dist/__tests__/adapter/context-builder.test.d.ts +1 -0
  2. package/dist/__tests__/adapter/plugin-helper.test.d.ts +1 -0
  3. package/dist/__tests__/adapter/registration-integration.test.d.ts +1 -0
  4. package/dist/__tests__/adapter/scoped-store.test.d.ts +1 -0
  5. package/dist/__tests__/plugins/conversation.test.d.ts +1 -0
  6. package/dist/__tests__/testing/createMockContext.test.d.ts +1 -0
  7. package/dist/adapter/context-builder.d.ts +0 -9
  8. package/dist/adapter/index.d.ts +0 -1
  9. package/dist/adapter/plugin-helper.d.ts +0 -7
  10. package/dist/adapter/scoped-store.d.ts +0 -10
  11. package/dist/adapter/types.d.ts +0 -7
  12. package/dist/agent/resolver.d.ts +0 -13
  13. package/dist/boxing/box-storage.interface.d.ts +0 -4
  14. package/dist/boxing/box.service.d.ts +0 -4
  15. package/dist/boxing/box.types.d.ts +0 -4
  16. package/dist/boxing/context-builder.d.ts +0 -4
  17. package/dist/client/CrewxClient.d.ts +0 -32
  18. package/dist/client/index.d.ts +0 -1
  19. package/dist/client/index.js +1 -6
  20. package/dist/config/loader.browser.d.ts +0 -8
  21. package/dist/config/loader.d.ts +0 -12
  22. package/dist/conversation/__tests__/sqlite-provider.test.d.ts +1 -0
  23. package/dist/conversation/__tests__/to-task-reader.test.d.ts +1 -0
  24. package/dist/conversation/index.d.ts +0 -1
  25. package/dist/conversation/sqlite-provider.d.ts +0 -9
  26. package/dist/conversation/to-task-reader.d.ts +0 -11
  27. package/dist/conversation/to-template-messages.d.ts +0 -13
  28. package/dist/conversation/types.d.ts +0 -58
  29. package/dist/esm/client/index.js +1 -2
  30. package/dist/esm/hooks/index.js +7 -6
  31. package/dist/esm/index.js +79 -60
  32. package/dist/esm/plugins/index.js +52 -0
  33. package/dist/esm/testing/index.js +1 -0
  34. package/dist/esm/tools/node/index.js +36 -54
  35. package/dist/events/TypedEventEmitter.d.ts +0 -24
  36. package/dist/events/types.d.ts +0 -43
  37. package/dist/facade/Crewx.browser.d.ts +0 -40
  38. package/dist/facade/Crewx.d.ts +0 -163
  39. package/dist/hooks/define.d.ts +0 -1
  40. package/dist/hooks/dispatch.d.ts +0 -12
  41. package/dist/hooks/index.d.ts +0 -1
  42. package/dist/hooks/index.js +7 -24
  43. package/dist/hooks/observer.d.ts +0 -1
  44. package/dist/hooks/plugin.d.ts +0 -1
  45. package/dist/hooks/tool-normalize.d.ts +0 -26
  46. package/dist/hooks/types.d.ts +0 -1
  47. package/dist/hooks/yaml-plugin.d.ts +0 -1
  48. package/dist/index.browser.d.ts +0 -7
  49. package/dist/index.browser.js +2 -25
  50. package/dist/index.d.ts +0 -4
  51. package/dist/index.js +79 -151
  52. package/dist/layout/loader.d.ts +0 -20
  53. package/dist/layout/props-validator.d.ts +0 -6
  54. package/dist/layout/renderer.d.ts +0 -24
  55. package/dist/layout/types.d.ts +0 -42
  56. package/dist/parallel/agent-runtime.d.ts +0 -11
  57. package/dist/parallel/helpers.d.ts +0 -1
  58. package/dist/parallel/index.d.ts +0 -1
  59. package/dist/parallel/parallel-runner.d.ts +0 -8
  60. package/dist/parallel/types.d.ts +0 -24
  61. package/dist/parsers/agent-call.util.d.ts +0 -3
  62. package/dist/parsers/claude.parser.d.ts +0 -8
  63. package/dist/parsers/codex.parser.d.ts +0 -8
  64. package/dist/parsers/copilot.parser.d.ts +0 -9
  65. package/dist/parsers/gemini.parser.d.ts +0 -10
  66. package/dist/parsers/opencode.parser.d.ts +0 -10
  67. package/dist/parsers/router.d.ts +0 -5
  68. package/dist/paths.d.ts +1 -0
  69. package/dist/platform/BrowserFsAdapter.d.ts +0 -20
  70. package/dist/platform/IFsAdapter.d.ts +0 -23
  71. package/dist/platform/NodeFsAdapter.d.ts +0 -8
  72. package/dist/plugin/plugin-provider.d.ts +0 -22
  73. package/dist/plugin/types.d.ts +0 -31
  74. package/dist/plugin.d.ts +0 -27
  75. package/dist/plugins/conversation.d.ts +0 -2
  76. package/dist/plugins/file-logger.d.ts +0 -13
  77. package/dist/plugins/index.d.ts +0 -10
  78. package/dist/plugins/index.js +52 -19
  79. package/dist/plugins/sqlite-tracing.d.ts +0 -13
  80. package/dist/plugins/sqlite-tracing.spec.d.ts +1 -0
  81. package/dist/provider/bridge.browser.d.ts +0 -20
  82. package/dist/provider/bridge.d.ts +0 -47
  83. package/dist/provider/parse-usage.d.ts +0 -14
  84. package/dist/provider/register-api.d.ts +0 -7
  85. package/dist/provider/vercel-runtime.d.ts +0 -29
  86. package/dist/remote/index.d.ts +0 -6
  87. package/dist/remote/remote-agent-manager.d.ts +0 -31
  88. package/dist/remote/remote-provider.d.ts +0 -15
  89. package/dist/remote/remote-transport.d.ts +0 -17
  90. package/dist/remote/types.d.ts +0 -59
  91. package/dist/server/auth.d.ts +0 -16
  92. package/dist/server/handler.d.ts +0 -17
  93. package/dist/server/index.d.ts +0 -4
  94. package/dist/server/tool-adapter.d.ts +0 -16
  95. package/dist/template/engine.d.ts +0 -19
  96. package/dist/template/helpers/exec.browser.d.ts +0 -7
  97. package/dist/template/helpers/exec.d.ts +0 -45
  98. package/dist/template/helpers/fenced_code.d.ts +0 -16
  99. package/dist/template/helpers/format-conversation.d.ts +0 -22
  100. package/dist/template/helpers/include.d.ts +0 -15
  101. package/dist/template/helpers/p1p2.d.ts +0 -32
  102. package/dist/template/loader/DocumentLoader.d.ts +0 -30
  103. package/dist/template/types.d.ts +0 -30
  104. package/dist/testing/index.d.ts +0 -1
  105. package/dist/testing/index.js +1 -16
  106. package/dist/testing/mock-audit.d.ts +0 -1
  107. package/dist/testing/mock-context.d.ts +0 -1
  108. package/dist/testing/mock-logger.d.ts +0 -1
  109. package/dist/testing/mock-router.d.ts +0 -1
  110. package/dist/testing/mock-storage.d.ts +0 -1
  111. package/dist/testing/mock-store.d.ts +0 -1
  112. package/dist/tools/delegate.d.ts +0 -7
  113. package/dist/tools/index.d.ts +0 -4
  114. package/dist/tools/node/builtin.d.ts +0 -16
  115. package/dist/tools/node/index.d.ts +0 -20
  116. package/dist/tools/node/index.js +36 -59
  117. package/dist/types/index.d.ts +0 -20
  118. package/dist/types/task-log.types.d.ts +0 -4
  119. package/dist/utils/env-defaults.d.ts +0 -16
  120. package/dist/utils/glob-match.d.ts +0 -16
  121. package/dist/utils/id.d.ts +0 -15
  122. package/dist/utils/timestamp.d.ts +0 -1
  123. package/dist/utils/workspace.d.ts +0 -4
  124. package/package.json +24 -25
  125. package/dist/adapter/context-builder.js +0 -87
  126. package/dist/adapter/index.js +0 -21
  127. package/dist/adapter/plugin-helper.js +0 -45
  128. package/dist/adapter/scoped-store.js +0 -43
  129. package/dist/adapter/types.js +0 -23
  130. package/dist/agent/resolver.js +0 -46
  131. package/dist/boxing/box-storage.interface.js +0 -6
  132. package/dist/boxing/box.service.js +0 -73
  133. package/dist/boxing/box.types.js +0 -6
  134. package/dist/boxing/context-builder.js +0 -79
  135. package/dist/client/CrewxClient.js +0 -86
  136. package/dist/config/loader.browser.js +0 -59
  137. package/dist/config/loader.js +0 -95
  138. package/dist/conversation/index.js +0 -25
  139. package/dist/conversation/sqlite-provider.js +0 -178
  140. package/dist/conversation/to-task-reader.js +0 -28
  141. package/dist/conversation/to-template-messages.js +0 -34
  142. package/dist/conversation/types.js +0 -10
  143. package/dist/esm/agent/resolver.js +0 -41
  144. package/dist/esm/boxing/box-storage.interface.js +0 -5
  145. package/dist/esm/boxing/box.service.js +0 -69
  146. package/dist/esm/boxing/box.types.js +0 -5
  147. package/dist/esm/boxing/context-builder.js +0 -76
  148. package/dist/esm/client/CrewxClient.js +0 -82
  149. package/dist/esm/config/loader.browser.js +0 -54
  150. package/dist/esm/config/loader.js +0 -77
  151. package/dist/esm/events/TypedEventEmitter.js +0 -61
  152. package/dist/esm/events/types.js +0 -8
  153. package/dist/esm/facade/Crewx.browser.js +0 -310
  154. package/dist/esm/facade/Crewx.js +0 -941
  155. package/dist/esm/hooks/define.js +0 -10
  156. package/dist/esm/hooks/dispatch.js +0 -76
  157. package/dist/esm/hooks/observer.js +0 -56
  158. package/dist/esm/hooks/plugin.js +0 -12
  159. package/dist/esm/hooks/types.js +0 -9
  160. package/dist/esm/index.browser.js +0 -15
  161. package/dist/esm/layout/loader.js +0 -268
  162. package/dist/esm/layout/props-validator.js +0 -297
  163. package/dist/esm/layout/renderer.js +0 -180
  164. package/dist/esm/layout/types.js +0 -31
  165. package/dist/esm/parallel/agent-runtime.js +0 -21
  166. package/dist/esm/parallel/helpers.js +0 -214
  167. package/dist/esm/parallel/index.js +0 -5
  168. package/dist/esm/parallel/parallel-runner.js +0 -221
  169. package/dist/esm/parallel/types.js +0 -5
  170. package/dist/esm/parsers/agent-call.util.js +0 -15
  171. package/dist/esm/parsers/claude.parser.js +0 -64
  172. package/dist/esm/parsers/codex.parser.js +0 -97
  173. package/dist/esm/parsers/copilot.parser.js +0 -63
  174. package/dist/esm/parsers/gemini.parser.js +0 -43
  175. package/dist/esm/parsers/opencode.parser.js +0 -73
  176. package/dist/esm/parsers/router.js +0 -53
  177. package/dist/esm/platform/BrowserFsAdapter.js +0 -80
  178. package/dist/esm/platform/IFsAdapter.js +0 -2
  179. package/dist/esm/platform/NodeFsAdapter.js +0 -34
  180. package/dist/esm/plugin/plugin-provider.js +0 -202
  181. package/dist/esm/plugin/types.js +0 -8
  182. package/dist/esm/plugin.js +0 -25
  183. package/dist/esm/provider/bridge.browser.js +0 -43
  184. package/dist/esm/provider/bridge.js +0 -373
  185. package/dist/esm/provider/parse-usage.js +0 -80
  186. package/dist/esm/provider/register-api.js +0 -21
  187. package/dist/esm/provider/vercel-runtime.js +0 -310
  188. package/dist/esm/remote/index.js +0 -10
  189. package/dist/esm/remote/remote-agent-manager.js +0 -194
  190. package/dist/esm/remote/remote-provider.js +0 -98
  191. package/dist/esm/remote/remote-transport.js +0 -79
  192. package/dist/esm/remote/types.js +0 -8
  193. package/dist/esm/server/auth.js +0 -31
  194. package/dist/esm/server/handler.js +0 -72
  195. package/dist/esm/server/index.js +0 -5
  196. package/dist/esm/server/tool-adapter.js +0 -92
  197. package/dist/esm/template/engine.js +0 -100
  198. package/dist/esm/template/helpers/exec.browser.js +0 -31
  199. package/dist/esm/template/helpers/exec.js +0 -220
  200. package/dist/esm/template/helpers/fenced_code.js +0 -17
  201. package/dist/esm/template/helpers/include.js +0 -20
  202. package/dist/esm/template/helpers/p1p2.js +0 -83
  203. package/dist/esm/template/loader/DocumentLoader.js +0 -124
  204. package/dist/esm/template/types.js +0 -5
  205. package/dist/esm/tools/delegate.js +0 -57
  206. package/dist/esm/tools/index.js +0 -5
  207. package/dist/esm/tools/node/builtin.js +0 -541
  208. package/dist/esm/types/index.js +0 -27
  209. package/dist/esm/types/task-log.types.js +0 -5
  210. package/dist/esm/utils/env-defaults.js +0 -23
  211. package/dist/esm/utils/glob-match.js +0 -38
  212. package/dist/esm/utils/id.js +0 -46
  213. package/dist/esm/utils/workspace.js +0 -21
  214. package/dist/events/TypedEventEmitter.js +0 -65
  215. package/dist/events/types.js +0 -9
  216. package/dist/facade/Crewx.browser.js +0 -314
  217. package/dist/facade/Crewx.js +0 -1299
  218. package/dist/hooks/define.js +0 -13
  219. package/dist/hooks/dispatch.js +0 -147
  220. package/dist/hooks/observer.js +0 -60
  221. package/dist/hooks/plugin.js +0 -17
  222. package/dist/hooks/tool-normalize.js +0 -110
  223. package/dist/hooks/types.js +0 -12
  224. package/dist/hooks/yaml-plugin.js +0 -356
  225. package/dist/layout/loader.js +0 -305
  226. package/dist/layout/props-validator.js +0 -301
  227. package/dist/layout/renderer.js +0 -193
  228. package/dist/layout/types.js +0 -36
  229. package/dist/parallel/agent-runtime.js +0 -25
  230. package/dist/parallel/helpers.js +0 -219
  231. package/dist/parallel/index.js +0 -13
  232. package/dist/parallel/parallel-runner.js +0 -226
  233. package/dist/parallel/types.js +0 -6
  234. package/dist/parsers/agent-call.util.js +0 -19
  235. package/dist/parsers/api.parser.d.ts +0 -10
  236. package/dist/parsers/api.parser.js +0 -26
  237. package/dist/parsers/claude.parser.js +0 -67
  238. package/dist/parsers/codex.parser.js +0 -100
  239. package/dist/parsers/copilot.parser.js +0 -66
  240. package/dist/parsers/gemini.parser.js +0 -46
  241. package/dist/parsers/opencode.parser.js +0 -76
  242. package/dist/parsers/router.js +0 -56
  243. package/dist/platform/BrowserFsAdapter.js +0 -84
  244. package/dist/platform/IFsAdapter.js +0 -3
  245. package/dist/platform/NodeFsAdapter.js +0 -38
  246. package/dist/plugin/plugin-provider.js +0 -207
  247. package/dist/plugin/types.js +0 -9
  248. package/dist/plugin.js +0 -29
  249. package/dist/plugins/conversation.js +0 -59
  250. package/dist/plugins/file-logger.js +0 -87
  251. package/dist/plugins/sqlite-tracing.js +0 -112
  252. package/dist/provider/bridge.browser.js +0 -49
  253. package/dist/provider/bridge.js +0 -381
  254. package/dist/provider/mastra-runtime.d.ts +0 -45
  255. package/dist/provider/mastra-runtime.js +0 -208
  256. package/dist/provider/parse-usage.js +0 -83
  257. package/dist/provider/register-api.js +0 -24
  258. package/dist/provider/vercel-runtime.js +0 -347
  259. package/dist/remote/index.js +0 -32
  260. package/dist/remote/remote-agent-manager.js +0 -198
  261. package/dist/remote/remote-provider.js +0 -141
  262. package/dist/remote/remote-transport.js +0 -83
  263. package/dist/remote/types.js +0 -9
  264. package/dist/server/auth.js +0 -35
  265. package/dist/server/handler.js +0 -75
  266. package/dist/server/index.js +0 -9
  267. package/dist/server/tool-adapter.js +0 -95
  268. package/dist/template/engine.js +0 -137
  269. package/dist/template/helpers/exec.browser.js +0 -41
  270. package/dist/template/helpers/exec.js +0 -230
  271. package/dist/template/helpers/fenced_code.js +0 -20
  272. package/dist/template/helpers/format-conversation.js +0 -53
  273. package/dist/template/helpers/include.js +0 -23
  274. package/dist/template/helpers/p1p2.js +0 -90
  275. package/dist/template/loader/DocumentLoader.js +0 -128
  276. package/dist/template/types.js +0 -6
  277. package/dist/testing/mock-audit.js +0 -13
  278. package/dist/testing/mock-context.js +0 -68
  279. package/dist/testing/mock-logger.js +0 -27
  280. package/dist/testing/mock-router.js +0 -67
  281. package/dist/testing/mock-storage.js +0 -21
  282. package/dist/testing/mock-store.js +0 -8
  283. package/dist/tools/delegate.js +0 -60
  284. package/dist/tools/index.js +0 -9
  285. package/dist/tools/node/builtin.js +0 -547
  286. package/dist/types/index.js +0 -32
  287. package/dist/types/task-log.types.js +0 -6
  288. package/dist/utils/env-defaults.js +0 -27
  289. package/dist/utils/glob-match.js +0 -42
  290. package/dist/utils/id.js +0 -50
  291. package/dist/utils/timestamp.js +0 -13
  292. package/dist/utils/workspace.js +0 -58
@@ -1,10 +0,0 @@
1
- import { ToolObserverPlugin } from './observer';
2
- export function definePlugin(def) {
3
- return new (class extends ToolObserverPlugin {
4
- name = def.name;
5
- version = def.version;
6
- on = def.on;
7
- run = def.run;
8
- })();
9
- }
10
- //# sourceMappingURL=define.js.map
@@ -1,76 +0,0 @@
1
- import { resolve, relative } from 'path';
2
- const MAX_REASON_LENGTH = 200;
3
- export function sanitizeDenyReason(reason) {
4
- const cleaned = reason.replace(/[\x00-\x1f\x7f]/g, '');
5
- if (cleaned.length <= MAX_REASON_LENGTH) {
6
- return cleaned;
7
- }
8
- return cleaned.slice(0, MAX_REASON_LENGTH - 11) + ' [redacted]';
9
- }
10
- export function isPathSafe(pluginPath, projectRoot) {
11
- const resolved = resolve(pluginPath);
12
- const root = resolve(projectRoot);
13
- const rel = relative(root, resolved);
14
- if (rel.startsWith('..') || resolve(resolved).startsWith('/etc/') || resolve(resolved).startsWith('/usr/')) {
15
- return false;
16
- }
17
- if (resolved.includes('node_modules')) {
18
- return false;
19
- }
20
- return true;
21
- }
22
- export function buildHookContext(input, cwd) {
23
- return {
24
- event: 'beforeTool',
25
- traceId: input.tool_use_id || '',
26
- agent: { id: '', role: '', team: '' },
27
- provider: 'cli/claude',
28
- thread: { id: '' },
29
- tool: {
30
- name: input.tool_name,
31
- rawName: input.tool_name,
32
- input: input.tool_input,
33
- },
34
- cwd: cwd || input.cwd,
35
- sessionId: input.session_id,
36
- pass: () => ({ type: 'pass' }),
37
- deny: (r) => ({ type: 'deny', reason: r }),
38
- inject: (m) => ({ type: 'inject', message: m }),
39
- modify: (p) => ({ type: 'modify', patch: p }),
40
- };
41
- }
42
- export async function evaluateHook(plugin, input, cwd) {
43
- const ctx = buildHookContext(input, cwd);
44
- const result = await plugin.run(ctx);
45
- const baseOutput = {
46
- hookSpecificOutput: {
47
- hookEventName: input.hook_event_name,
48
- permissionDecision: 'allow',
49
- },
50
- };
51
- switch (result.type) {
52
- case 'pass':
53
- return { exitCode: 0, stdout: baseOutput };
54
- case 'deny': {
55
- const sanitizedReason = sanitizeDenyReason(result.reason);
56
- return {
57
- exitCode: 2,
58
- stdout: {
59
- hookSpecificOutput: {
60
- hookEventName: input.hook_event_name,
61
- permissionDecision: 'deny',
62
- permissionDecisionReason: sanitizedReason,
63
- },
64
- },
65
- };
66
- }
67
- case 'inject':
68
- case 'modify':
69
- console.error(`[crewx] Hook result type '${result.type}' is not supported in Phase 0. ` +
70
- `Plugin: ${plugin.name}. Treating as pass.`);
71
- return { exitCode: 0, stdout: baseOutput };
72
- default:
73
- return { exitCode: 0, stdout: baseOutput };
74
- }
75
- }
76
- //# sourceMappingURL=dispatch.js.map
@@ -1,56 +0,0 @@
1
- import { CrewxPlugin } from '../plugin';
2
- export class ToolObserverPlugin extends CrewxPlugin {
3
- unsubs = [];
4
- attach(crewx) {
5
- if (this.on.beforeTool) {
6
- const unsub = crewx.on('tool:observed:before', async (e) => {
7
- if (!this.matchesTool(this.on.beforeTool, e.tool.name))
8
- return;
9
- const ctx = this.buildContext('beforeTool', e);
10
- await this.run(ctx);
11
- });
12
- this.unsubs.push(unsub);
13
- }
14
- if (this.on.afterTool) {
15
- const unsub = crewx.on('tool:observed:after', async (e) => {
16
- if (!this.matchesTool(this.on.afterTool, e.tool.name))
17
- return;
18
- const ctx = this.buildContext('afterTool', e);
19
- await this.run(ctx);
20
- });
21
- this.unsubs.push(unsub);
22
- }
23
- }
24
- async detach(_crewx) {
25
- for (const unsub of this.unsubs)
26
- unsub();
27
- this.unsubs = [];
28
- }
29
- matchesTool(filter, toolName) {
30
- if (filter === true)
31
- return true;
32
- return filter.includes(toolName);
33
- }
34
- buildContext(event, e) {
35
- return {
36
- event,
37
- traceId: e.traceId,
38
- agent: {
39
- id: e.agentId || e.agentRef,
40
- role: '',
41
- team: '',
42
- },
43
- provider: e.provider,
44
- thread: { id: e.threadId || '' },
45
- tool: {
46
- name: e.tool.name,
47
- rawName: e.tool.rawName,
48
- input: 'input' in e.tool ? e.tool.input : undefined,
49
- },
50
- cwd: process.cwd(),
51
- sessionId: e.sessionId || '',
52
- pass: () => ({ type: 'pass' }),
53
- };
54
- }
55
- }
56
- //# sourceMappingURL=observer.js.map
@@ -1,12 +0,0 @@
1
- export class HookPlugin {
2
- capabilities = { required: [] };
3
- }
4
- export function defineHookPlugin(def) {
5
- return new (class extends HookPlugin {
6
- name = def.name;
7
- version = def.version;
8
- capabilities = def.capabilities ?? { required: [] };
9
- run = def.run;
10
- })();
11
- }
12
- //# sourceMappingURL=plugin.js.map
@@ -1,9 +0,0 @@
1
- export const Tools = {
2
- FileRead: 'file.read',
3
- FileWrite: 'file.write',
4
- FileEdit: 'file.edit',
5
- Shell: 'shell',
6
- Search: 'search',
7
- Other: 'other',
8
- };
9
- //# sourceMappingURL=types.js.map
@@ -1,15 +0,0 @@
1
- /**
2
- * @crewx/sdk browser entry point.
3
- *
4
- * Exports only browser-safe modules — no Node.js dependencies
5
- * (child_process, fs, path, crypto, events).
6
- */
7
- // Browser-safe facade
8
- export { Crewx } from './facade/Crewx.browser.js';
9
- // Browser-safe provider bridge (registry only, no CLI spawn)
10
- export { registerProviderFactory, createProvider, ProviderError } from './provider/bridge.browser.js';
11
- // Config — browser-safe (no fs import)
12
- export { parseYamlContent, ConfigLoadError } from './config/loader.browser.js';
13
- // Platform adapters
14
- export { BrowserFsAdapter } from './platform/BrowserFsAdapter.js';
15
- //# sourceMappingURL=index.browser.js.map
@@ -1,268 +0,0 @@
1
- /**
2
- * LayoutLoader — loads layout templates from templates/agents/*.yaml files.
3
- * Ported 1:1 from packages/sdk-bak/src/services/layout-loader.service.ts.
4
- * Only import paths and DEFAULT_OPTIONS.templatesPath are changed.
5
- */
6
- import { readFileSync, readdirSync, existsSync } from 'fs';
7
- import * as path from 'path';
8
- import { load as loadYaml } from 'js-yaml';
9
- import { LayoutLoadError, } from './types';
10
- /**
11
- * Default loader options — points to SDK's bundled templates directory.
12
- */
13
- const DEFAULT_OPTIONS = {
14
- templatesPath: path.join(__dirname, '../../../templates/agents'),
15
- validationMode: 'lenient',
16
- fallbackLayoutId: 'crewx/default',
17
- };
18
- /**
19
- * Layout loader service.
20
- * Loads and caches layout definitions from YAML files.
21
- * Provides fallback mechanism and prop override support.
22
- */
23
- export class LayoutLoader {
24
- layouts = new Map();
25
- options;
26
- constructor(options) {
27
- this.options = { ...DEFAULT_OPTIONS, ...options };
28
- this.loadAllLayouts();
29
- }
30
- /**
31
- * Load a layout by ID with optional props override.
32
- */
33
- load(layoutId, propsOverride) {
34
- let layout = this.layouts.get(layoutId);
35
- if (!layout) {
36
- const normalizedId = this.normalizeLayoutId(layoutId);
37
- layout = this.layouts.get(normalizedId);
38
- }
39
- if (!layout) {
40
- console.warn(`Layout not found: ${layoutId}, falling back to ${this.options.fallbackLayoutId}`);
41
- layout = this.layouts.get(this.options.fallbackLayoutId);
42
- if (!layout) {
43
- throw new LayoutLoadError(`Fallback layout not found: ${this.options.fallbackLayoutId}`, this.options.fallbackLayoutId);
44
- }
45
- }
46
- if (propsOverride && Object.keys(propsOverride).length > 0) {
47
- return {
48
- ...layout,
49
- defaultProps: { ...layout.defaultProps, ...propsOverride },
50
- };
51
- }
52
- return layout;
53
- }
54
- getLayoutIds() {
55
- return Array.from(this.layouts.keys());
56
- }
57
- hasLayout(layoutId) {
58
- if (this.layouts.has(layoutId))
59
- return true;
60
- const normalizedId = this.normalizeLayoutId(layoutId);
61
- return this.layouts.has(normalizedId);
62
- }
63
- reload() {
64
- this.layouts.clear();
65
- this.loadAllLayouts();
66
- }
67
- /**
68
- * Register or override a layout at runtime.
69
- */
70
- registerLayout(layoutId, layoutConfig) {
71
- if (!layoutId || typeof layoutId !== 'string') {
72
- throw new LayoutLoadError('Layout ID must be a non-empty string', layoutId);
73
- }
74
- const config = typeof layoutConfig === 'string'
75
- ? { template: layoutConfig }
76
- : layoutConfig;
77
- const template = typeof config.template === 'string' ? config.template : '';
78
- if (!template || template.trim().length === 0) {
79
- throw new LayoutLoadError(`Custom layout template is empty for ${layoutId}`, layoutId);
80
- }
81
- const propsSchemaRaw = config.propsSchema || {};
82
- const defaultPropsFromSchema = this.extractDefaultProps(propsSchemaRaw);
83
- const explicitDefaults = config.defaultProps || {};
84
- const layoutDefinition = {
85
- id: layoutId,
86
- version: config.version || '1.0.0',
87
- description: config.description || `Custom layout ${layoutId}`,
88
- template,
89
- propsSchema: this.parsePropsSchema(propsSchemaRaw),
90
- defaultProps: { ...defaultPropsFromSchema, ...explicitDefaults },
91
- };
92
- const existingLayout = this.layouts.get(layoutId);
93
- const templatesEqual = existingLayout?.template === template &&
94
- JSON.stringify(existingLayout?.defaultProps ?? {}) === JSON.stringify(layoutDefinition.defaultProps ?? {}) &&
95
- JSON.stringify(existingLayout?.propsSchema ?? {}) === JSON.stringify(layoutDefinition.propsSchema ?? {});
96
- this.layouts.set(layoutId, layoutDefinition);
97
- if (process.env.CREWX_VERBOSE === '1') {
98
- if (!existingLayout) {
99
- console.error(`Registered custom layout: ${layoutId}`);
100
- }
101
- else if (!templatesEqual) {
102
- console.error(`Updated custom layout: ${layoutId}`);
103
- }
104
- }
105
- }
106
- /**
107
- * Register multiple layouts from a map.
108
- */
109
- registerLayouts(layoutsMap) {
110
- for (const [id, config] of Object.entries(layoutsMap)) {
111
- try {
112
- this.registerLayout(id, config);
113
- }
114
- catch (error) {
115
- console.warn(`Failed to register custom layout ${id}:`, error instanceof Error ? error.message : error);
116
- }
117
- }
118
- }
119
- loadAllLayouts() {
120
- const layoutsDir = this.options.templatesPath;
121
- if (!existsSync(layoutsDir)) {
122
- throw new LayoutLoadError(`Templates directory not found: ${layoutsDir}`, undefined, new Error(`Directory does not exist: ${layoutsDir}`));
123
- }
124
- try {
125
- const files = readdirSync(layoutsDir).filter(f => f.endsWith('.yaml') || f.endsWith('.yml'));
126
- if (files.length === 0) {
127
- console.warn(`No layout files found in ${layoutsDir}`);
128
- }
129
- for (const file of files) {
130
- const layoutName = file.replace(/\.(yaml|yml)$/, '');
131
- const layoutPath = path.join(layoutsDir, file);
132
- try {
133
- const layout = this.loadLayoutFile(layoutPath, layoutName);
134
- const layoutId = `crewx/${layoutName}`;
135
- this.layouts.set(layoutId, layout);
136
- if (layoutId !== 'crewx/minimal') {
137
- if (process.env.CREWX_VERBOSE === '1')
138
- console.error(`Loaded layout: ${layoutId} from ${file}`);
139
- }
140
- }
141
- catch (error) {
142
- console.error(`Failed to load layout file ${file}:`, error);
143
- }
144
- }
145
- if (process.env.CREWX_VERBOSE === '1')
146
- console.error(`Loaded ${this.layouts.size} layouts from ${layoutsDir}`);
147
- }
148
- catch (error) {
149
- throw new LayoutLoadError(`Failed to read layouts directory: ${layoutsDir}`, undefined, error instanceof Error ? error : new Error(String(error)));
150
- }
151
- }
152
- loadLayoutFile(filePath, layoutName) {
153
- try {
154
- const content = readFileSync(filePath, 'utf-8');
155
- if (!content || content.trim().length === 0) {
156
- console.warn(`Empty YAML file: ${filePath}, will use fallback`);
157
- throw new LayoutLoadError(`Empty YAML file: ${filePath}`, layoutName, new Error('File content is empty'));
158
- }
159
- const parsed = loadYaml(content);
160
- if (!parsed || typeof parsed !== 'object') {
161
- console.warn(`Invalid YAML content in ${filePath} (parsed as ${typeof parsed}), will use fallback`);
162
- throw new LayoutLoadError(`Invalid or empty YAML in ${filePath}`, layoutName, new Error('YAML parsing returned null/undefined or non-object'));
163
- }
164
- // Format 2: layouts map (templates/agents/default.yaml format)
165
- if (parsed.layouts && typeof parsed.layouts === 'object') {
166
- const entry = this.resolveLayoutEntry(parsed.layouts, layoutName);
167
- if (!entry || entry.template.trim().length === 0) {
168
- console.warn(`Empty or missing layout template in ${filePath} for ${layoutName}`);
169
- throw new LayoutLoadError(`Layout template not found or empty in layouts map: ${layoutName}`, layoutName);
170
- }
171
- // propsSchema may be inline in the layout entry object (e.g. default.yaml) or at the top level
172
- const propsSchemaRaw = entry.propsSchema || parsed.propsSchema || {};
173
- return {
174
- id: `crewx/${layoutName}`,
175
- version: parsed.version || '1.0.0',
176
- description: parsed.description || `CrewX ${layoutName} layout`,
177
- template: entry.template,
178
- propsSchema: this.parsePropsSchema(propsSchemaRaw),
179
- defaultProps: this.extractDefaultProps(propsSchemaRaw),
180
- };
181
- }
182
- else {
183
- // Format 1: direct layout definition
184
- if (!parsed.template || (typeof parsed.template === 'string' && parsed.template.trim().length === 0)) {
185
- console.warn(`Empty or missing template field in ${filePath}`);
186
- throw new LayoutLoadError(`Layout template is missing or empty in ${filePath}`, layoutName);
187
- }
188
- return {
189
- id: parsed.id || `crewx/${layoutName}`,
190
- version: parsed.version || '1.0.0',
191
- description: parsed.description || '',
192
- template: parsed.template,
193
- propsSchema: this.parsePropsSchema(parsed.propsSchema || {}),
194
- defaultProps: this.extractDefaultProps(parsed.propsSchema || {}),
195
- };
196
- }
197
- }
198
- catch (error) {
199
- throw new LayoutLoadError(`Failed to load layout file: ${filePath}`, layoutName, error instanceof Error ? error : new Error(String(error)));
200
- }
201
- }
202
- parsePropsSchema(raw) {
203
- const schema = {};
204
- for (const [key, value] of Object.entries(raw)) {
205
- if (typeof value === 'object' && value !== null) {
206
- schema[key] = value;
207
- }
208
- }
209
- return schema;
210
- }
211
- extractDefaultProps(propsSchema) {
212
- const defaults = {};
213
- for (const [key, schema] of Object.entries(propsSchema)) {
214
- if (schema && typeof schema === 'object') {
215
- if ('defaultValue' in schema) {
216
- defaults[key] = schema.defaultValue;
217
- }
218
- else if ('default' in schema) {
219
- defaults[key] = schema.default;
220
- }
221
- }
222
- }
223
- return defaults;
224
- }
225
- normalizeLayoutId(layoutId) {
226
- if (!layoutId)
227
- return this.options.fallbackLayoutId;
228
- if (layoutId.includes('/'))
229
- return layoutId;
230
- return `crewx/${layoutId}`;
231
- }
232
- resolveLayoutEntry(layoutsMap, layoutName) {
233
- const candidates = new Set();
234
- if (layoutName) {
235
- candidates.add(layoutName);
236
- if (layoutName.includes('/')) {
237
- const parts = layoutName.split('/');
238
- const last = parts[parts.length - 1];
239
- if (last)
240
- candidates.add(last);
241
- }
242
- else {
243
- candidates.add(`crewx/${layoutName}`);
244
- }
245
- }
246
- candidates.add('default');
247
- for (const key of candidates) {
248
- const value = layoutsMap[key];
249
- if (typeof value === 'string' && value.trim().length > 0) {
250
- return { template: value };
251
- }
252
- if (value && typeof value === 'object' && typeof value.template === 'string' && value.template.trim().length > 0) {
253
- return { template: value.template, propsSchema: value.propsSchema };
254
- }
255
- }
256
- for (const value of Object.values(layoutsMap)) {
257
- if (typeof value === 'string' && value.trim().length > 0) {
258
- return { template: value };
259
- }
260
- const v = value;
261
- if (v && typeof v === 'object' && typeof v.template === 'string' && v.template.trim().length > 0) {
262
- return { template: v.template, propsSchema: v.propsSchema };
263
- }
264
- }
265
- return undefined;
266
- }
267
- }
268
- //# sourceMappingURL=loader.js.map