@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,69 +0,0 @@
1
- /**
2
- * SdkBoxService — manages box creation, retrieval, and listing.
3
- */
4
- import { generateId } from '../utils/id';
5
- const ID_PATTERN = /^[a-zA-Z0-9._-]+$/;
6
- export class SdkBoxService {
7
- storage;
8
- constructor(storage) {
9
- this.storage = storage;
10
- }
11
- listBoxes(threadId) {
12
- this.validateId(threadId);
13
- const rows = this.storage.listBoxes(threadId);
14
- const boxes = rows.map((row) => this.toBoxResponse(row));
15
- return { boxes, total: boxes.length };
16
- }
17
- getBox(threadId, boxId) {
18
- this.validateId(threadId);
19
- this.validateId(boxId);
20
- const row = this.storage.findBox(threadId, boxId);
21
- if (!row)
22
- return null;
23
- return this.toBoxResponse(row);
24
- }
25
- createBox(threadId, params) {
26
- this.validateId(threadId);
27
- const id = this.generateBoxId();
28
- const createdAt = new Date().toISOString();
29
- const row = this.storage.insertBox(threadId, {
30
- id,
31
- seq: params.seq,
32
- firstTaskId: params.firstTaskId,
33
- midTaskId: params.midTaskId,
34
- lastTaskId: params.lastTaskId,
35
- taskCount: params.taskCount,
36
- summary: params.summary ?? null,
37
- sourceTokens: params.sourceTokens,
38
- summaryTokens: params.summaryTokens ?? null,
39
- createdAt,
40
- });
41
- return this.toBoxResponse(row);
42
- }
43
- toBoxResponse(row) {
44
- return {
45
- id: row.id,
46
- threadId: row.thread_id,
47
- seq: row.seq,
48
- firstTaskId: row.first_task_id,
49
- lastTaskId: row.last_task_id,
50
- taskCount: row.task_count,
51
- sourceTokens: row.source_tokens,
52
- summaryTokens: row.summary_tokens,
53
- summary: row.summary,
54
- previewFirst: this.storage.getTaskPreview(row.first_task_id, 200),
55
- previewMid: this.storage.getTaskPreview(row.mid_task_id, 200),
56
- previewLast: this.storage.getTaskPreview(row.last_task_id, 200),
57
- createdAt: row.created_at,
58
- };
59
- }
60
- validateId(id) {
61
- if (!ID_PATTERN.test(id)) {
62
- throw new Error(`Invalid ID format: ${id}`);
63
- }
64
- }
65
- generateBoxId() {
66
- return generateId('box');
67
- }
68
- }
69
- //# sourceMappingURL=box.service.js.map
@@ -1,5 +0,0 @@
1
- /**
2
- * Boxing domain types — Box/Thread/Context types for SDK boxing module.
3
- */
4
- export {};
5
- //# sourceMappingURL=box.types.js.map
@@ -1,76 +0,0 @@
1
- /**
2
- * buildContext() — builds hot/warm context windows from thread messages and box summaries.
3
- */
4
- export function buildContext(threadId, taskReader, boxService, params, tokenizer) {
5
- const { maxTokens, hotzoneRatio, warmzoneRatio } = params;
6
- const hotBudget = maxTokens * hotzoneRatio;
7
- const warmBudget = maxTokens * warmzoneRatio;
8
- const totalBudget = hotBudget + warmBudget;
9
- const tasks = taskReader.getThreadMessages(threadId);
10
- const hotMessages = [];
11
- let hotTokens = 0;
12
- let hotOverflow = false;
13
- const taskPairs = [];
14
- for (let i = 0; i < tasks.length; i += 2) {
15
- const userMsg = tasks[i];
16
- const assistantMsg = tasks[i + 1];
17
- const prompt = userMsg?.content || '';
18
- const result = assistantMsg?.content || '';
19
- const tokens = tokenizer.countTokens(prompt + result);
20
- const msgs = [];
21
- if (userMsg)
22
- msgs.push(userMsg);
23
- if (assistantMsg)
24
- msgs.push(assistantMsg);
25
- taskPairs.push({ messages: msgs, tokens });
26
- }
27
- for (let i = taskPairs.length - 1; i >= 0; i--) {
28
- const pair = taskPairs[i];
29
- if (hotTokens + pair.tokens > hotBudget) {
30
- hotOverflow = true;
31
- break;
32
- }
33
- hotTokens += pair.tokens;
34
- hotMessages.unshift(...pair.messages);
35
- }
36
- const warmBoxes = [];
37
- let warmTokens = 0;
38
- if (hotOverflow && warmBudget > 0) {
39
- try {
40
- const { boxes } = boxService.listBoxes(threadId);
41
- for (let i = boxes.length - 1; i >= 0; i--) {
42
- const box = boxes[i];
43
- const tokens = box.summaryTokens ?? box.sourceTokens;
44
- if (warmTokens + tokens > warmBudget)
45
- break;
46
- warmTokens += tokens;
47
- warmBoxes.unshift({
48
- boxId: box.id,
49
- seq: box.seq,
50
- taskCount: box.taskCount,
51
- sourceTokens: box.sourceTokens,
52
- summary: box.summary,
53
- previewFirst: box.previewFirst,
54
- previewMid: box.previewMid,
55
- previewLast: box.previewLast,
56
- createdAt: box.createdAt,
57
- });
58
- }
59
- }
60
- catch (error) {
61
- if (error instanceof Error && !/not found/i.test(error.message)) {
62
- throw error;
63
- }
64
- }
65
- }
66
- return {
67
- hot: hotMessages,
68
- warm: warmBoxes,
69
- hotTokens,
70
- warmTokens,
71
- hotOverflow,
72
- totalBudget,
73
- config: { maxTokens, hotzoneRatio, warmzoneRatio },
74
- };
75
- }
76
- //# sourceMappingURL=context-builder.js.map
@@ -1,82 +0,0 @@
1
- /**
2
- * CrewxClient — Browser client for CrewX SDK.
3
- *
4
- * Communicates with a server running CrewX SDK via HTTP.
5
- * Handles the Client-Intercept pattern automatically:
6
- * registerTool() + query() — that's it.
7
- *
8
- * @example
9
- * ```ts
10
- * import { CrewxClient } from '@crewx/sdk/client';
11
- *
12
- * const crewx = new CrewxClient('http://localhost:3000');
13
- * crewx.registerTool('browser_storage_read', {
14
- * execute: async ({ key }) => localStorage.getItem(key),
15
- * });
16
- *
17
- * const result = await crewx.query('assistant', 'read my settings');
18
- * console.log(result.data);
19
- * ```
20
- */
21
- export class CrewxClient {
22
- baseUrl;
23
- tools = new Map();
24
- constructor(baseUrl) {
25
- this.baseUrl = baseUrl.replace(/\/$/, '');
26
- }
27
- /**
28
- * Register a browser-side tool.
29
- * When the server agent calls a tool with this name (and no server-side execute),
30
- * CrewxClient automatically runs it locally and sends the result back.
31
- */
32
- registerTool(name, definition) {
33
- this.tools.set(name, definition);
34
- }
35
- /**
36
- * Send a message to an agent.
37
- * The requires_action loop is handled automatically — if the agent calls a
38
- * client tool, CrewxClient executes it locally and continues the conversation.
39
- */
40
- async query(agent, message, callbacks) {
41
- let response = await this._post('/api/chat', { agent, message });
42
- while (response.status === 'requires_action') {
43
- const { toolCall, threadId } = response;
44
- if (!toolCall)
45
- break;
46
- const tool = this.tools.get(toolCall.toolName);
47
- if (callbacks?.onToolCall) {
48
- callbacks.onToolCall(toolCall);
49
- }
50
- let toolResult;
51
- if (tool?.execute) {
52
- try {
53
- const raw = await tool.execute(toolCall.args);
54
- toolResult = typeof raw === 'string' ? raw : JSON.stringify(raw);
55
- }
56
- catch (err) {
57
- toolResult = `Error: ${err.message}`;
58
- }
59
- }
60
- else {
61
- toolResult = `Error: No client handler for tool "${toolCall.toolName}"`;
62
- }
63
- response = await this._post('/api/chat/continue', {
64
- threadId,
65
- toolCallId: toolCall.toolCallId,
66
- result: toolResult,
67
- });
68
- }
69
- return response;
70
- }
71
- async _post(path, body) {
72
- const res = await fetch(`${this.baseUrl}${path}`, {
73
- method: 'POST',
74
- headers: { 'Content-Type': 'application/json' },
75
- body: JSON.stringify(body),
76
- });
77
- if (!res.ok)
78
- throw new Error(`HTTP ${res.status}`);
79
- return res.json();
80
- }
81
- }
82
- //# sourceMappingURL=CrewxClient.js.map
@@ -1,54 +0,0 @@
1
- /**
2
- * Browser-safe YAML config loader.
3
- * Only parseYamlContent — no file I/O.
4
- */
5
- import { load as loadYaml } from 'js-yaml';
6
- import { CrewxProjectConfigSchema } from '../types/index.js';
7
- export class ConfigLoadError extends Error {
8
- cause;
9
- constructor(message, cause) {
10
- super(message);
11
- this.cause = cause;
12
- this.name = 'ConfigLoadError';
13
- }
14
- }
15
- /**
16
- * Parse YAML string into a validated CrewxProjectConfig.
17
- */
18
- export function parseYamlContent(yamlString) {
19
- if (!yamlString || typeof yamlString !== 'string' || !yamlString.trim()) {
20
- throw new ConfigLoadError('YAML content must be a non-empty string');
21
- }
22
- let raw;
23
- try {
24
- raw = loadYaml(yamlString);
25
- }
26
- catch (err) {
27
- throw new ConfigLoadError(`YAML parse error: ${err.message}`, err);
28
- }
29
- const normalized = normalizeRaw(raw);
30
- const result = CrewxProjectConfigSchema.safeParse(normalized);
31
- if (!result.success) {
32
- throw new ConfigLoadError(`Config validation error: ${result.error.message}`);
33
- }
34
- return result.data;
35
- }
36
- function normalizeRaw(raw) {
37
- if (!raw || typeof raw !== 'object') {
38
- return { agents: [] };
39
- }
40
- const obj = raw;
41
- if (obj.agents && typeof obj.agents === 'object' && !Array.isArray(obj.agents)) {
42
- const agentsMap = obj.agents;
43
- const agentsArray = Object.entries(agentsMap).map(([id, cfg]) => {
44
- const agentCfg = (cfg && typeof cfg === 'object' ? cfg : {});
45
- return { id, ...agentCfg };
46
- });
47
- return { ...obj, agents: agentsArray };
48
- }
49
- if (!obj.agents) {
50
- return { ...obj, agents: [] };
51
- }
52
- return obj;
53
- }
54
- //# sourceMappingURL=loader.browser.js.map
@@ -1,77 +0,0 @@
1
- /**
2
- * YAML configuration loader for CrewX projects.
3
- * Reads crewx.yaml and validates it with Zod schema.
4
- */
5
- import { load as loadYaml } from 'js-yaml';
6
- import { readFileSync } from 'fs';
7
- import { CrewxProjectConfigSchema } from '../types';
8
- export class ConfigLoadError extends Error {
9
- cause;
10
- constructor(message, cause) {
11
- super(message);
12
- this.cause = cause;
13
- this.name = 'ConfigLoadError';
14
- }
15
- }
16
- /**
17
- * Parse YAML string into a validated CrewxProjectConfig.
18
- * Converts the agents record (keyed by id) into an array.
19
- */
20
- export function parseYamlContent(yamlString) {
21
- if (!yamlString || typeof yamlString !== 'string' || !yamlString.trim()) {
22
- throw new ConfigLoadError('YAML content must be a non-empty string');
23
- }
24
- let raw;
25
- try {
26
- raw = loadYaml(yamlString);
27
- }
28
- catch (err) {
29
- throw new ConfigLoadError(`YAML parse error: ${err.message}`, err);
30
- }
31
- // Normalize agents: YAML has agents as a map (Record<id, config>),
32
- // but our type uses an array with 'id' field.
33
- const normalized = normalizeRaw(raw);
34
- const result = CrewxProjectConfigSchema.safeParse(normalized);
35
- if (!result.success) {
36
- throw new ConfigLoadError(`Config validation error: ${result.error.message}`);
37
- }
38
- return result.data;
39
- }
40
- /**
41
- * Load and parse crewx.yaml from a file path.
42
- */
43
- export function loadYamlFile(filePath) {
44
- let content;
45
- try {
46
- content = readFileSync(filePath, 'utf-8');
47
- }
48
- catch (err) {
49
- throw new ConfigLoadError(`Cannot read file: ${filePath}`, err);
50
- }
51
- return parseYamlContent(content);
52
- }
53
- /**
54
- * Normalize raw YAML output:
55
- * - agents map (Record<id, agentConfig>) → agents array ([{ id, ...agentConfig }])
56
- */
57
- function normalizeRaw(raw) {
58
- if (!raw || typeof raw !== 'object') {
59
- return { agents: [] };
60
- }
61
- const obj = raw;
62
- // Convert agents map to array
63
- if (obj.agents && typeof obj.agents === 'object' && !Array.isArray(obj.agents)) {
64
- const agentsMap = obj.agents;
65
- const agentsArray = Object.entries(agentsMap).map(([id, cfg]) => {
66
- const agentCfg = (cfg && typeof cfg === 'object' ? cfg : {});
67
- return { id, ...agentCfg };
68
- });
69
- return { ...obj, agents: agentsArray };
70
- }
71
- // agents already array or absent
72
- if (!obj.agents) {
73
- return { ...obj, agents: [] };
74
- }
75
- return obj;
76
- }
77
- //# sourceMappingURL=loader.js.map
@@ -1,61 +0,0 @@
1
- /**
2
- * TypedEventEmitter — typed wrapper around Node's EventEmitter.
3
- *
4
- * Design:
5
- * - `on` / `once` are public (callers subscribe)
6
- * - `emit` is protected (only subclasses like Crewx can emit)
7
- * - Async listeners are supported (fire-and-forget, errors isolated)
8
- * - Returns an UnsubscribeFn from on/once for easy cleanup
9
- */
10
- import { EventEmitter } from 'events';
11
- /**
12
- * Wraps a listener to isolate errors and support async fire-and-forget.
13
- */
14
- function makeSafeListener(event, listener) {
15
- return (payload) => {
16
- try {
17
- const result = listener(payload);
18
- if (result instanceof Promise) {
19
- result.catch((err) => {
20
- // Fire-and-forget: isolate async listener errors
21
- console.error(`[crewx] event listener error (${event}): ${err instanceof Error ? err.message : String(err)}`);
22
- });
23
- }
24
- }
25
- catch (err) {
26
- // Synchronous listener error — log and continue
27
- console.error(`[crewx] event listener error (${event}): ${err instanceof Error ? err.message : String(err)}`);
28
- }
29
- };
30
- }
31
- export class TypedEventEmitter {
32
- _emitter = new EventEmitter();
33
- /**
34
- * Subscribe to an event. Returns an unsubscribe function.
35
- *
36
- * @example
37
- * const unsub = crewx.on('task:start', (e) => console.log(e.agentRef));
38
- * // later:
39
- * unsub();
40
- */
41
- on(event, listener) {
42
- const safeListener = makeSafeListener(event, listener);
43
- this._emitter.on(event, safeListener);
44
- return () => this._emitter.off(event, safeListener);
45
- }
46
- /**
47
- * Subscribe to an event exactly once.
48
- */
49
- once(event, listener) {
50
- const safeListener = makeSafeListener(event, listener);
51
- this._emitter.once(event, safeListener);
52
- return () => this._emitter.off(event, safeListener);
53
- }
54
- /**
55
- * Emit an event with payload. Only accessible to subclasses.
56
- */
57
- emit(event, payload) {
58
- this._emitter.emit(event, payload);
59
- }
60
- }
61
- //# sourceMappingURL=TypedEventEmitter.js.map
@@ -1,8 +0,0 @@
1
- /**
2
- * Event types for the CrewX SDK event system.
3
- *
4
- * SDK emits events; callers (CLI, users) subscribe to persist or react.
5
- * No DB dependencies in the SDK — storage is the caller's responsibility.
6
- */
7
- export {};
8
- //# sourceMappingURL=types.js.map