@crewx/sdk 0.8.0-rc.80 → 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 (217) 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 -0
  30. package/dist/esm/hooks/index.js +7 -0
  31. package/dist/esm/index.js +79 -0
  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 -0
  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/events/TypedEventEmitter.js +0 -65
  144. package/dist/events/types.js +0 -9
  145. package/dist/facade/Crewx.browser.js +0 -314
  146. package/dist/facade/Crewx.js +0 -1299
  147. package/dist/hooks/define.js +0 -13
  148. package/dist/hooks/dispatch.js +0 -147
  149. package/dist/hooks/observer.js +0 -60
  150. package/dist/hooks/plugin.js +0 -17
  151. package/dist/hooks/tool-normalize.js +0 -110
  152. package/dist/hooks/types.js +0 -12
  153. package/dist/hooks/yaml-plugin.js +0 -356
  154. package/dist/layout/loader.js +0 -305
  155. package/dist/layout/props-validator.js +0 -301
  156. package/dist/layout/renderer.js +0 -193
  157. package/dist/layout/types.js +0 -36
  158. package/dist/parallel/agent-runtime.js +0 -25
  159. package/dist/parallel/helpers.js +0 -219
  160. package/dist/parallel/index.js +0 -13
  161. package/dist/parallel/parallel-runner.js +0 -226
  162. package/dist/parallel/types.js +0 -6
  163. package/dist/parsers/agent-call.util.js +0 -19
  164. package/dist/parsers/claude.parser.js +0 -67
  165. package/dist/parsers/codex.parser.js +0 -100
  166. package/dist/parsers/copilot.parser.js +0 -66
  167. package/dist/parsers/gemini.parser.js +0 -46
  168. package/dist/parsers/opencode.parser.js +0 -76
  169. package/dist/parsers/router.js +0 -56
  170. package/dist/platform/BrowserFsAdapter.js +0 -84
  171. package/dist/platform/IFsAdapter.js +0 -3
  172. package/dist/platform/NodeFsAdapter.js +0 -38
  173. package/dist/plugin/plugin-provider.js +0 -207
  174. package/dist/plugin/types.js +0 -9
  175. package/dist/plugin.js +0 -29
  176. package/dist/plugins/conversation.js +0 -59
  177. package/dist/plugins/file-logger.js +0 -87
  178. package/dist/plugins/sqlite-tracing.js +0 -112
  179. package/dist/provider/bridge.browser.js +0 -49
  180. package/dist/provider/bridge.js +0 -381
  181. package/dist/provider/parse-usage.js +0 -83
  182. package/dist/provider/register-api.js +0 -24
  183. package/dist/provider/vercel-runtime.js +0 -347
  184. package/dist/remote/index.js +0 -32
  185. package/dist/remote/remote-agent-manager.js +0 -198
  186. package/dist/remote/remote-provider.js +0 -141
  187. package/dist/remote/remote-transport.js +0 -83
  188. package/dist/remote/types.js +0 -9
  189. package/dist/server/auth.js +0 -35
  190. package/dist/server/handler.js +0 -75
  191. package/dist/server/index.js +0 -9
  192. package/dist/server/tool-adapter.js +0 -95
  193. package/dist/template/engine.js +0 -137
  194. package/dist/template/helpers/exec.browser.js +0 -41
  195. package/dist/template/helpers/exec.js +0 -230
  196. package/dist/template/helpers/fenced_code.js +0 -20
  197. package/dist/template/helpers/format-conversation.js +0 -53
  198. package/dist/template/helpers/include.js +0 -23
  199. package/dist/template/helpers/p1p2.js +0 -90
  200. package/dist/template/loader/DocumentLoader.js +0 -128
  201. package/dist/template/types.js +0 -6
  202. package/dist/testing/mock-audit.js +0 -13
  203. package/dist/testing/mock-context.js +0 -68
  204. package/dist/testing/mock-logger.js +0 -27
  205. package/dist/testing/mock-router.js +0 -67
  206. package/dist/testing/mock-storage.js +0 -21
  207. package/dist/testing/mock-store.js +0 -8
  208. package/dist/tools/delegate.js +0 -60
  209. package/dist/tools/index.js +0 -9
  210. package/dist/tools/node/builtin.js +0 -547
  211. package/dist/types/index.js +0 -32
  212. package/dist/types/task-log.types.js +0 -6
  213. package/dist/utils/env-defaults.js +0 -27
  214. package/dist/utils/glob-match.js +0 -42
  215. package/dist/utils/id.js +0 -50
  216. package/dist/utils/timestamp.js +0 -13
  217. package/dist/utils/workspace.js +0 -58
@@ -1,66 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseCopilotEvent = parseCopilotEvent;
4
- const agent_call_util_1 = require("./agent-call.util");
5
- /**
6
- * Parse Copilot json events into TaskLogEntry[].
7
- *
8
- * Copilot events:
9
- * - { type: "tool.execution_start", data: { toolName, arguments } }
10
- * - { type: "tool.execution_complete", data: { result?: { content }, error?: { message } } }
11
- * - { type: "assistant.message", data: { content } }
12
- */
13
- function parseCopilotEvent(timestamp, parsed) {
14
- const type = parsed.type;
15
- const data = parsed.data;
16
- if (!data)
17
- return [];
18
- const toolCallId = data.toolCallId;
19
- if (type === 'tool.execution_start') {
20
- const toolName = String(data.toolName || '');
21
- const args = data.arguments;
22
- const inputStr = args?.command
23
- ? String(args.command)
24
- : JSON.stringify(args || {});
25
- if ((toolName === 'bash' || toolName === 'Bash') &&
26
- (0, agent_call_util_1.isAgentCallCommand)(inputStr)) {
27
- return [(0, agent_call_util_1.parseAgentCall)(timestamp, inputStr)];
28
- }
29
- return [{
30
- timestamp,
31
- type: 'tool_use',
32
- toolName,
33
- toolInput: inputStr,
34
- ...(toolCallId && { toolUseId: toolCallId }),
35
- }];
36
- }
37
- if (type === 'tool.execution_complete') {
38
- const error = data.error;
39
- if (error) {
40
- return [{
41
- timestamp,
42
- type: 'tool_result',
43
- isError: true,
44
- resultPreview: String(error.message || ''),
45
- ...(toolCallId && { toolUseId: toolCallId }),
46
- }];
47
- }
48
- const result = data.result;
49
- const content = String(result?.content || '');
50
- return [{
51
- timestamp,
52
- type: 'tool_result',
53
- resultPreview: content,
54
- isError: false,
55
- ...(toolCallId && { toolUseId: toolCallId }),
56
- }];
57
- }
58
- if (type === 'assistant.message') {
59
- const content = String(data.content || '');
60
- if (!content)
61
- return [];
62
- return [{ timestamp, type: 'text', content }];
63
- }
64
- return [];
65
- }
66
- //# sourceMappingURL=copilot.parser.js.map
@@ -1,46 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseGeminiEvent = parseGeminiEvent;
4
- const agent_call_util_1 = require("./agent-call.util");
5
- /**
6
- * Parse Gemini stream-json events into TaskLogEntry[].
7
- *
8
- * Gemini events:
9
- * - { type: "message", role: "assistant", delta: true, content: "..." }
10
- * - { type: "init", ... } (ignored)
11
- * - { type: "tool_use", tool_name, tool_id, parameters }
12
- * - { type: "tool_result", tool_id, status, output }
13
- */
14
- function parseGeminiEvent(timestamp, parsed) {
15
- const type = parsed.type;
16
- if (type === 'message') {
17
- const role = parsed.role;
18
- if (role !== 'assistant')
19
- return [];
20
- const content = parsed.content;
21
- if (!content)
22
- return [];
23
- return [{ timestamp, type: 'text', content }];
24
- }
25
- if (type === 'tool_use') {
26
- const toolName = String(parsed.tool_name || '');
27
- const toolUseId = parsed.tool_id;
28
- const parameters = parsed.parameters;
29
- const inputStr = parameters?.command
30
- ? String(parameters.command)
31
- : JSON.stringify(parameters || {});
32
- if (/^bash$/i.test(toolName) && (0, agent_call_util_1.isAgentCallCommand)(inputStr)) {
33
- return [(0, agent_call_util_1.parseAgentCall)(timestamp, inputStr)];
34
- }
35
- return [{ timestamp, type: 'tool_use', toolName, toolUseId, toolInput: inputStr }];
36
- }
37
- if (type === 'tool_result') {
38
- const toolUseId = parsed.tool_id;
39
- const output = String(parsed.output || '');
40
- const isError = parsed.status !== 'success';
41
- return [{ timestamp, type: 'tool_result', toolUseId, resultPreview: output, isError }];
42
- }
43
- // init and other events: skip
44
- return [];
45
- }
46
- //# sourceMappingURL=gemini.parser.js.map
@@ -1,76 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseOpencodeEvent = parseOpencodeEvent;
4
- /**
5
- * Parse OpenCode stream-json events (--format json) into TaskLogEntry[].
6
- *
7
- * OpenCode events:
8
- * - { type: "step_start", sessionID: "ses_...", part: { type: "step-start" } }
9
- * - { type: "text", part: { type: "text", text: "..." } }
10
- * - { type: "step_finish", part: { reason: "stop", tokens: { total, input, output, reasoning, cache: { write, read } }, cost: 0 } }
11
- * - { type: "tool_use", part: { type: "tool", tool: "bash"|"write"|..., callID: "...", state: { status, input, output } } }
12
- */
13
- function parseOpencodeEvent(timestamp, parsed) {
14
- const type = parsed.type;
15
- if (type === 'text') {
16
- const part = parsed.part;
17
- const text = part?.text;
18
- if (!text)
19
- return [];
20
- return [{ timestamp, type: 'text', content: text }];
21
- }
22
- if (type === 'tool_use') {
23
- const part = parsed.part;
24
- if (!part)
25
- return [];
26
- const tool = String(part.tool || '');
27
- const toolUseId = String(part.callID || '');
28
- const state = part.state;
29
- const status = String(state?.status || '');
30
- const input = state?.input;
31
- const inputStr = extractToolInput(input);
32
- const entries = [
33
- { timestamp, type: 'tool_use', toolName: tool, toolUseId, toolInput: inputStr },
34
- ];
35
- if (status === 'completed' && state?.output !== undefined) {
36
- const output = state.output;
37
- const outputStr = typeof output === 'string' ? output : JSON.stringify(output);
38
- entries.push({ timestamp, type: 'tool_result', toolUseId, resultPreview: outputStr, isError: false });
39
- }
40
- else if (status === 'error') {
41
- entries.push({
42
- timestamp,
43
- type: 'tool_result',
44
- toolUseId,
45
- resultPreview: String(state?.error || 'tool error'),
46
- isError: true,
47
- });
48
- }
49
- return entries;
50
- }
51
- // step_start, step_finish: skip (usage is extracted by parse-usage.ts)
52
- return [];
53
- }
54
- /**
55
- * Extract a human-friendly string from OpenCode tool input.
56
- *
57
- * Matches Claude/Gemini parser behaviour:
58
- * - bash-like → input.command ("mkdir -p /tmp/foo")
59
- * - file tools → input.filePath ("/tmp/foo/bar.ts")
60
- * - otherwise → JSON.stringify fallback
61
- */
62
- function extractToolInput(input) {
63
- if (typeof input === 'string')
64
- return input;
65
- if (!input || typeof input !== 'object')
66
- return JSON.stringify(input ?? {});
67
- const obj = input;
68
- if (obj.command)
69
- return String(obj.command);
70
- if (obj.filePath)
71
- return String(obj.filePath);
72
- if (obj.pattern)
73
- return String(obj.pattern);
74
- return JSON.stringify(obj);
75
- }
76
- //# sourceMappingURL=opencode.parser.js.map
@@ -1,56 +0,0 @@
1
- "use strict";
2
- /**
3
- * parseStdoutEvent — routes a single stdout JSONL event to the appropriate provider parser.
4
- * Returns TaskLogEntry[] (may be empty if event is not recognized or irrelevant).
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.parseStdoutEvent = parseStdoutEvent;
8
- const claude_parser_1 = require("./claude.parser");
9
- const copilot_parser_1 = require("./copilot.parser");
10
- const codex_parser_1 = require("./codex.parser");
11
- const gemini_parser_1 = require("./gemini.parser");
12
- const opencode_parser_1 = require("./opencode.parser");
13
- function parseStdoutEvent(timestamp, message) {
14
- let parsed;
15
- try {
16
- parsed = JSON.parse(message);
17
- }
18
- catch {
19
- return [];
20
- }
21
- const type = parsed.type;
22
- if (!type)
23
- return [];
24
- // Claude stream-json (system event excluded — meta event)
25
- if (type === 'assistant' || type === 'user') {
26
- return (0, claude_parser_1.parseClaudeEvent)(timestamp, parsed);
27
- }
28
- // Copilot json — assistant.* check must precede Gemini "message" check
29
- if (type.startsWith('tool.execution') || type.startsWith('assistant.') || type === 'user.message') {
30
- return (0, copilot_parser_1.parseCopilotEvent)(timestamp, parsed);
31
- }
32
- // Codex experimental-json
33
- if (type.startsWith('item.') || type.startsWith('turn.') || type.startsWith('thread.')) {
34
- return (0, codex_parser_1.parseCodexEvent)(timestamp, parsed);
35
- }
36
- // Gemini stream-json — tool_use/tool_result routed by structure below
37
- if (type === 'message' || type === 'init') {
38
- return (0, gemini_parser_1.parseGeminiEvent)(timestamp, parsed);
39
- }
40
- // tool_use / tool_result: disambiguate by schema structure.
41
- // OpenCode has a `part` object; Gemini is flat (tool_name, parameters).
42
- if (type === 'tool_use' || type === 'tool_result') {
43
- if (parsed.part && typeof parsed.part === 'object') {
44
- return (0, opencode_parser_1.parseOpencodeEvent)(timestamp, parsed);
45
- }
46
- return (0, gemini_parser_1.parseGeminiEvent)(timestamp, parsed);
47
- }
48
- // OpenCode stream-json (--format json)
49
- // Note: 'text' is a generic name but not used by any other provider currently.
50
- // 'step_start' and 'step_finish' are OpenCode-specific.
51
- if (type === 'text' || type === 'step_start' || type === 'step_finish') {
52
- return (0, opencode_parser_1.parseOpencodeEvent)(timestamp, parsed);
53
- }
54
- return [];
55
- }
56
- //# sourceMappingURL=router.js.map
@@ -1,84 +0,0 @@
1
- "use strict";
2
- /**
3
- * BrowserFsAdapter — IFsAdapter implementation for browser environments.
4
- *
5
- * Uses localStorage as the backing store with a key-prefix namespace.
6
- * Paths are normalized to forward-slash POSIX style.
7
- *
8
- * Usage:
9
- * const fs = new BrowserFsAdapter();
10
- * // Pre-load content before using with DocumentLoader:
11
- * fs.setItem('/docs/guide.md', '# Guide\n...');
12
- */
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.BrowserFsAdapter = void 0;
15
- const DEFAULT_PREFIX = 'crewx:fs:';
16
- class BrowserFsAdapter {
17
- prefix;
18
- store;
19
- /**
20
- * @param options.prefix - localStorage key prefix (default: 'crewx:fs:')
21
- * @param options.storage - optional external storage map (defaults to an in-memory Map;
22
- * pass a localStorage-backed wrapper for persistence)
23
- */
24
- constructor(options) {
25
- this.prefix = options?.prefix ?? DEFAULT_PREFIX;
26
- this.store = options?.storage ?? new Map();
27
- }
28
- async readFile(path) {
29
- const key = this.toKey(path);
30
- const content = this.store.get(key);
31
- if (content === undefined) {
32
- throw new Error(`BrowserFsAdapter: file not found: ${path}`);
33
- }
34
- return content;
35
- }
36
- async exists(path) {
37
- return this.store.has(this.toKey(path));
38
- }
39
- resolvePath(...segments) {
40
- // Simple POSIX-style path joining (no true "resolve" since there's no cwd)
41
- const joined = segments
42
- .map(s => s.replace(/\\/g, '/'))
43
- .join('/')
44
- .replace(/\/+/g, '/');
45
- // Normalize . and .. segments
46
- const parts = joined.split('/');
47
- const resolved = [];
48
- for (const part of parts) {
49
- if (part === '.' || part === '')
50
- continue;
51
- if (part === '..') {
52
- resolved.pop();
53
- }
54
- else {
55
- resolved.push(part);
56
- }
57
- }
58
- const result = resolved.join('/');
59
- return joined.startsWith('/') ? `/${result}` : result;
60
- }
61
- isAbsolute(path) {
62
- return path.startsWith('/');
63
- }
64
- // ── Browser-specific helpers ───────────────────────────────────────────────
65
- /** Store a virtual file for later reading. */
66
- setItem(path, content) {
67
- this.store.set(this.toKey(path), content);
68
- }
69
- /** Remove a virtual file. */
70
- removeItem(path) {
71
- this.store.delete(this.toKey(path));
72
- }
73
- /** List all stored virtual file paths. */
74
- keys() {
75
- return Array.from(this.store.keys())
76
- .filter(k => k.startsWith(this.prefix))
77
- .map(k => k.slice(this.prefix.length));
78
- }
79
- toKey(path) {
80
- return `${this.prefix}${path.replace(/\\/g, '/')}`;
81
- }
82
- }
83
- exports.BrowserFsAdapter = BrowserFsAdapter;
84
- //# sourceMappingURL=BrowserFsAdapter.js.map
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=IFsAdapter.js.map
@@ -1,38 +0,0 @@
1
- "use strict";
2
- /**
3
- * NodeFsAdapter — default IFsAdapter implementation using Node.js fs/path.
4
- *
5
- * This is the concrete adapter used in CLI and server contexts.
6
- * Full platform abstraction (WEB, browser) is deferred to a future round.
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.defaultFsAdapter = exports.NodeFsAdapter = void 0;
10
- const promises_1 = require("fs/promises");
11
- const path_1 = require("path");
12
- class NodeFsAdapter {
13
- async readFile(path) {
14
- return (0, promises_1.readFile)(path, 'utf-8');
15
- }
16
- async exists(path) {
17
- try {
18
- await (0, promises_1.access)(path);
19
- return true;
20
- }
21
- catch {
22
- return false;
23
- }
24
- }
25
- resolvePath(...segments) {
26
- if (segments.length === 1) {
27
- return (0, path_1.resolve)(segments[0]);
28
- }
29
- return (0, path_1.resolve)((0, path_1.join)(...segments));
30
- }
31
- isAbsolute(path) {
32
- return (0, path_1.isAbsolute)(path);
33
- }
34
- }
35
- exports.NodeFsAdapter = NodeFsAdapter;
36
- /** Singleton default adapter for convenience in CLI usage. */
37
- exports.defaultFsAdapter = new NodeFsAdapter();
38
- //# sourceMappingURL=NodeFsAdapter.js.map
@@ -1,207 +0,0 @@
1
- "use strict";
2
- /**
3
- * Plugin Provider Runtime
4
- *
5
- * Implements ProviderRuntime for `type: plugin` providers in crewx.yaml.
6
- * Wraps an arbitrary CLI tool as a CrewX agent via child_process.spawn (shell: false).
7
- *
8
- * Symmetric to remote/remote-provider.ts — registered as the `plugin` namespace factory.
9
- */
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.PluginProviderRuntime = void 0;
12
- exports.createPluginProviderFactory = createPluginProviderFactory;
13
- const child_process_1 = require("child_process");
14
- const bridge_js_1 = require("../provider/bridge.js");
15
- /**
16
- * ProviderRuntime implementation for plugin (CLI-wrapped) providers.
17
- *
18
- * Created by the `plugin` namespace factory when `createProvider('plugin/mock')` is called.
19
- * Spawns the configured CLI with args derived from query_args/execute_args,
20
- * applies `{model}` substitution, and routes the prompt via args or stdin.
21
- */
22
- class PluginProviderRuntime {
23
- config;
24
- providerStr;
25
- constructor(id, config) {
26
- this.config = config;
27
- this.providerStr = `plugin/${id}`;
28
- // Validate at construction time (fail early, not at call time)
29
- validateCliCommand(config.cli_command);
30
- validateCliArgs(config.query_args);
31
- validateCliArgs(config.execute_args);
32
- if (config.error_patterns)
33
- validateErrorPatterns(config.error_patterns);
34
- if (config.env)
35
- validateEnv(config.env);
36
- }
37
- async query(message, options) {
38
- const model = options?.model ?? this.config.default_model ?? 'default';
39
- const args = resolveArgs(this.config.query_args, model, message, this.config.prompt_in_args);
40
- const stdinMessage = this.config.prompt_in_args ? undefined : message;
41
- options?.onCommand?.(`${this.config.cli_command} ${args.join(' ')}`);
42
- const timeoutMs = this.config.timeout?.query ?? 600000;
43
- return this.runProcess(args, options, stdinMessage, timeoutMs);
44
- }
45
- async execute(message, options) {
46
- const model = options?.model ?? this.config.default_model ?? 'default';
47
- const args = resolveArgs(this.config.execute_args, model, message, this.config.prompt_in_args);
48
- const stdinMessage = this.config.prompt_in_args ? undefined : message;
49
- options?.onCommand?.(`${this.config.cli_command} ${args.join(' ')}`);
50
- const timeoutMs = this.config.timeout?.execute ?? 600000;
51
- return this.runProcess(args, options, stdinMessage, timeoutMs);
52
- }
53
- runProcess(args, options, stdinMessage, timeoutMs) {
54
- return new Promise((resolve, reject) => {
55
- // Merge env: process.env is the base; config.env values are added on top.
56
- // Never replaces process.env — only extends it.
57
- const mergedEnv = {
58
- ...process.env,
59
- ...(this.config.env ?? {}),
60
- };
61
- const proc = (0, child_process_1.spawn)(this.config.cli_command, args, {
62
- env: mergedEnv,
63
- shell: process.platform === 'win32', // Windows: .cmd/.bat requires shell
64
- stdio: ['pipe', 'pipe', 'pipe'],
65
- });
66
- // Write prompt to stdin when prompt_in_args is false
67
- if (stdinMessage !== undefined) {
68
- proc.stdin.write(stdinMessage);
69
- proc.stdin.end();
70
- }
71
- else {
72
- proc.stdin.end();
73
- }
74
- if (proc.pid !== undefined) {
75
- options?.onPid?.(proc.pid);
76
- }
77
- let stdout = '';
78
- let stderr = '';
79
- let stdoutBuf = '';
80
- let stderrBuf = '';
81
- proc.stdout.on('data', (chunk) => {
82
- const str = chunk.toString();
83
- stdout += str;
84
- stdoutBuf += str;
85
- const lines = stdoutBuf.split('\n');
86
- stdoutBuf = lines.pop() ?? '';
87
- for (const line of lines) {
88
- if (line.trim())
89
- options?.onOutput?.(line, 'stdout');
90
- }
91
- });
92
- proc.stderr.on('data', (chunk) => {
93
- const str = chunk.toString();
94
- stderr += str;
95
- stderrBuf += str;
96
- const lines = stderrBuf.split('\n');
97
- stderrBuf = lines.pop() ?? '';
98
- for (const line of lines) {
99
- if (line.trim())
100
- options?.onOutput?.(line, 'stderr');
101
- }
102
- });
103
- // Hard timeout — terminate and reject if exceeded
104
- const timeoutHandle = setTimeout(() => {
105
- proc.kill('SIGTERM');
106
- reject(new bridge_js_1.ProviderError(`Plugin provider "${this.providerStr}" timed out after ${timeoutMs}ms`, this.providerStr));
107
- }, timeoutMs);
108
- proc.on('error', (err) => {
109
- clearTimeout(timeoutHandle);
110
- if (err.code === 'ENOENT') {
111
- const hint = this.config.not_installed_message
112
- ?? `CLI command "${this.config.cli_command}" not found. Is ${this.config.id} installed?`;
113
- reject(new bridge_js_1.ProviderError(hint, this.providerStr));
114
- }
115
- else {
116
- reject(new bridge_js_1.ProviderError(`Spawn error: ${err.message}`, this.providerStr));
117
- }
118
- });
119
- proc.on('close', (code) => {
120
- clearTimeout(timeoutHandle);
121
- // Flush residual buffered content (no trailing newline)
122
- if (stdoutBuf.trim())
123
- options?.onOutput?.(stdoutBuf, 'stdout');
124
- if (stderrBuf.trim())
125
- options?.onOutput?.(stderrBuf, 'stderr');
126
- const exitCode = code ?? 0;
127
- options?.onExitCode?.(exitCode);
128
- // Check configured error patterns before exit code
129
- if (this.config.error_patterns) {
130
- const combined = stderr || stdout;
131
- for (const ep of this.config.error_patterns) {
132
- if (combined.includes(ep.pattern)) {
133
- reject(new bridge_js_1.ProviderError(ep.message, this.providerStr));
134
- return;
135
- }
136
- }
137
- }
138
- if (code !== 0) {
139
- reject(new bridge_js_1.ProviderError(`Process exited with code ${code}: ${stderr.slice(0, 500)}`, this.providerStr));
140
- return;
141
- }
142
- resolve(stdout.trim());
143
- });
144
- });
145
- }
146
- }
147
- exports.PluginProviderRuntime = PluginProviderRuntime;
148
- // ── Factory ─────────────────────────────────────────────────────────────────
149
- /**
150
- * Create a provider factory function for the `plugin` namespace.
151
- *
152
- * @param pluginConfigs - Map of plugin provider ID → config (from crewx.yaml `providers:` section)
153
- * @returns ProviderFactory to register via registerProviderFactory('plugin', factory)
154
- */
155
- function createPluginProviderFactory(pluginConfigs) {
156
- return (id, _providerStr) => {
157
- const config = pluginConfigs.get(id);
158
- if (!config) {
159
- throw new bridge_js_1.ProviderError(`Plugin provider "${id}" not found. Available: ${Array.from(pluginConfigs.keys()).join(', ') || '(none)'}`, `plugin/${id}`);
160
- }
161
- return new PluginProviderRuntime(id, config);
162
- };
163
- }
164
- // ── Helpers ─────────────────────────────────────────────────────────────────
165
- /**
166
- * Build the final args array for a CLI invocation:
167
- * 1. Replace `{model}` placeholders in each arg.
168
- * 2. If promptInArgs is true, append the prompt as a positional argument.
169
- */
170
- function resolveArgs(templateArgs, model, prompt, promptInArgs) {
171
- const args = templateArgs.map(arg => arg.replace(/\{model\}/g, model));
172
- if (promptInArgs) {
173
- args.push(prompt);
174
- }
175
- return args;
176
- }
177
- // ── Validation ───────────────────────────────────────────────────────────────
178
- function validateCliCommand(cliCommand) {
179
- if (!cliCommand || typeof cliCommand !== 'string') {
180
- throw new Error('Plugin provider requires a cli_command');
181
- }
182
- }
183
- function validateCliArgs(args) {
184
- if (!Array.isArray(args)) {
185
- throw new Error('CLI arguments must be an array');
186
- }
187
- for (const arg of args) {
188
- if (typeof arg !== 'string') {
189
- throw new Error('Each CLI argument must be a string');
190
- }
191
- }
192
- }
193
- function validateErrorPatterns(patterns) {
194
- for (const { pattern } of patterns) {
195
- if (typeof pattern !== 'string') {
196
- throw new Error('Error pattern must be a string');
197
- }
198
- }
199
- }
200
- function validateEnv(env) {
201
- for (const [key, value] of Object.entries(env)) {
202
- if (typeof key !== 'string' || typeof value !== 'string') {
203
- throw new Error('env entries must be string key/value pairs');
204
- }
205
- }
206
- }
207
- //# sourceMappingURL=plugin-provider.js.map
@@ -1,9 +0,0 @@
1
- "use strict";
2
- /**
3
- * Plugin Provider Types
4
- *
5
- * Configuration for `type: plugin` providers in crewx.yaml.
6
- * Plugin providers wrap arbitrary CLI tools as CrewX agents.
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- //# sourceMappingURL=types.js.map
package/dist/plugin.js DELETED
@@ -1,29 +0,0 @@
1
- "use strict";
2
- /**
3
- * CrewxPlugin — base class for SDK plugins.
4
- *
5
- * Plugins subscribe to Crewx events in attach() and clean up in detach().
6
- * Register via Crewx.use(plugin).
7
- *
8
- * @example
9
- * class MyPlugin extends CrewxPlugin {
10
- * readonly name = 'my-plugin';
11
- * attach(crewx: Crewx) {
12
- * crewx.on('task:start', (e) => console.log(e.traceId));
13
- * }
14
- * }
15
- * await crewx.use(new MyPlugin());
16
- */
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.CrewxPlugin = void 0;
19
- class CrewxPlugin {
20
- /**
21
- * Called on Crewx.close() in LIFO order.
22
- * Remove event listeners and release resources here.
23
- * Default: no-op.
24
- */
25
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
26
- detach(_crewx) { }
27
- }
28
- exports.CrewxPlugin = CrewxPlugin;
29
- //# sourceMappingURL=plugin.js.map
@@ -1,59 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ConversationPlugin = void 0;
4
- const plugin_1 = require("../plugin");
5
- const sqlite_provider_1 = require("../conversation/sqlite-provider");
6
- class ConversationPlugin extends plugin_1.CrewxPlugin {
7
- name = 'conversation';
8
- _provider;
9
- unsubStart = null;
10
- unsubEnd = null;
11
- constructor(opts) {
12
- super();
13
- this._provider = new sqlite_provider_1.SqliteConversationProvider(opts?.dbPath);
14
- }
15
- /** Expose provider for SDK history auto-fetch (WI-CONV-002). */
16
- get conversationProvider() {
17
- return this._provider;
18
- }
19
- attach(crewx) {
20
- // task:start — save user message + ensure thread
21
- this.unsubStart = crewx.on('task:start', async (event) => {
22
- if (!event.threadId)
23
- return;
24
- const platform = (event.platform ?? 'cli');
25
- try {
26
- await this._provider.ensureThread(event.threadId, platform, event.workspaceId);
27
- await this._provider.saveUserMessage(event.threadId, event.message ?? '');
28
- }
29
- catch {
30
- // Non-fatal: conversation persistence must never crash the main process
31
- }
32
- });
33
- // task:end — save assistant response (WI-CONV-002)
34
- this.unsubEnd = crewx.on('task:end', async (event) => {
35
- if (!event.result)
36
- return;
37
- // Resolve threadId from metadata propagated in task:start
38
- const threadId = event.metadata?.threadId;
39
- if (!threadId)
40
- return;
41
- const agentId = event.agentRef?.replace(/^@/, '') ?? '';
42
- try {
43
- await this._provider.saveAssistantMessage(threadId, event.result, agentId);
44
- }
45
- catch {
46
- // Non-fatal: conversation persistence must never crash the main process
47
- }
48
- });
49
- }
50
- detach(_crewx) {
51
- this.unsubStart?.();
52
- this.unsubStart = null;
53
- this.unsubEnd?.();
54
- this.unsubEnd = null;
55
- this._provider.close?.();
56
- }
57
- }
58
- exports.ConversationPlugin = ConversationPlugin;
59
- //# sourceMappingURL=conversation.js.map