@crewx/sdk 0.8.0-rc.80 → 0.8.0-rc.83
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.
- package/dist/__tests__/adapter/context-builder.test.d.ts +1 -0
- package/dist/__tests__/adapter/plugin-helper.test.d.ts +1 -0
- package/dist/__tests__/adapter/registration-integration.test.d.ts +1 -0
- package/dist/__tests__/adapter/scoped-store.test.d.ts +1 -0
- package/dist/__tests__/plugins/conversation.test.d.ts +1 -0
- package/dist/__tests__/testing/createMockContext.test.d.ts +1 -0
- package/dist/adapter/context-builder.d.ts +0 -9
- package/dist/adapter/index.d.ts +0 -1
- package/dist/adapter/plugin-helper.d.ts +0 -7
- package/dist/adapter/scoped-store.d.ts +0 -10
- package/dist/adapter/types.d.ts +0 -7
- package/dist/agent/resolver.d.ts +0 -13
- package/dist/boxing/box-storage.interface.d.ts +0 -4
- package/dist/boxing/box.service.d.ts +0 -4
- package/dist/boxing/box.types.d.ts +0 -4
- package/dist/boxing/context-builder.d.ts +0 -4
- package/dist/client/CrewxClient.d.ts +0 -32
- package/dist/client/index.d.ts +0 -1
- package/dist/client/index.js +1 -6
- package/dist/config/loader.browser.d.ts +0 -8
- package/dist/config/loader.d.ts +0 -12
- package/dist/conversation/__tests__/sqlite-provider.test.d.ts +1 -0
- package/dist/conversation/__tests__/to-task-reader.test.d.ts +1 -0
- package/dist/conversation/index.d.ts +0 -1
- package/dist/conversation/sqlite-provider.d.ts +0 -9
- package/dist/conversation/to-task-reader.d.ts +0 -11
- package/dist/conversation/to-template-messages.d.ts +0 -13
- package/dist/conversation/types.d.ts +0 -58
- package/dist/esm/client/index.js +1 -0
- package/dist/esm/hooks/index.js +7 -0
- package/dist/esm/index.js +79 -0
- package/dist/esm/plugins/index.js +52 -0
- package/dist/esm/testing/index.js +1 -0
- package/dist/esm/tools/node/index.js +36 -0
- package/dist/events/TypedEventEmitter.d.ts +0 -24
- package/dist/events/types.d.ts +0 -43
- package/dist/facade/Crewx.browser.d.ts +0 -40
- package/dist/facade/Crewx.d.ts +0 -163
- package/dist/hooks/define.d.ts +0 -1
- package/dist/hooks/dispatch.d.ts +0 -12
- package/dist/hooks/index.d.ts +0 -1
- package/dist/hooks/index.js +7 -24
- package/dist/hooks/observer.d.ts +0 -1
- package/dist/hooks/plugin.d.ts +0 -1
- package/dist/hooks/tool-normalize.d.ts +0 -26
- package/dist/hooks/types.d.ts +0 -1
- package/dist/hooks/yaml-plugin.d.ts +0 -1
- package/dist/index.browser.d.ts +0 -7
- package/dist/index.browser.js +2 -25
- package/dist/index.d.ts +0 -4
- package/dist/index.js +79 -151
- package/dist/layout/loader.d.ts +0 -20
- package/dist/layout/props-validator.d.ts +0 -6
- package/dist/layout/renderer.d.ts +0 -24
- package/dist/layout/types.d.ts +0 -42
- package/dist/parallel/agent-runtime.d.ts +0 -11
- package/dist/parallel/helpers.d.ts +0 -1
- package/dist/parallel/index.d.ts +0 -1
- package/dist/parallel/parallel-runner.d.ts +0 -8
- package/dist/parallel/types.d.ts +0 -24
- package/dist/parsers/agent-call.util.d.ts +0 -3
- package/dist/parsers/claude.parser.d.ts +0 -8
- package/dist/parsers/codex.parser.d.ts +0 -8
- package/dist/parsers/copilot.parser.d.ts +0 -9
- package/dist/parsers/gemini.parser.d.ts +0 -10
- package/dist/parsers/opencode.parser.d.ts +0 -10
- package/dist/parsers/router.d.ts +0 -5
- package/dist/paths.d.ts +1 -0
- package/dist/platform/BrowserFsAdapter.d.ts +0 -20
- package/dist/platform/IFsAdapter.d.ts +0 -23
- package/dist/platform/NodeFsAdapter.d.ts +0 -8
- package/dist/plugin/plugin-provider.d.ts +0 -22
- package/dist/plugin/types.d.ts +0 -31
- package/dist/plugin.d.ts +0 -27
- package/dist/plugins/conversation.d.ts +0 -2
- package/dist/plugins/file-logger.d.ts +0 -13
- package/dist/plugins/index.d.ts +0 -10
- package/dist/plugins/index.js +52 -19
- package/dist/plugins/sqlite-tracing.d.ts +0 -13
- package/dist/plugins/sqlite-tracing.spec.d.ts +1 -0
- package/dist/provider/bridge.browser.d.ts +0 -20
- package/dist/provider/bridge.d.ts +0 -47
- package/dist/provider/parse-usage.d.ts +0 -14
- package/dist/provider/register-api.d.ts +0 -7
- package/dist/provider/vercel-runtime.d.ts +0 -29
- package/dist/remote/index.d.ts +0 -6
- package/dist/remote/remote-agent-manager.d.ts +0 -31
- package/dist/remote/remote-provider.d.ts +0 -15
- package/dist/remote/remote-transport.d.ts +0 -17
- package/dist/remote/types.d.ts +0 -59
- package/dist/server/auth.d.ts +0 -16
- package/dist/server/handler.d.ts +0 -17
- package/dist/server/index.d.ts +0 -4
- package/dist/server/tool-adapter.d.ts +0 -16
- package/dist/template/engine.d.ts +0 -19
- package/dist/template/helpers/exec.browser.d.ts +0 -7
- package/dist/template/helpers/exec.d.ts +0 -45
- package/dist/template/helpers/fenced_code.d.ts +0 -16
- package/dist/template/helpers/format-conversation.d.ts +0 -22
- package/dist/template/helpers/include.d.ts +0 -15
- package/dist/template/helpers/p1p2.d.ts +0 -32
- package/dist/template/loader/DocumentLoader.d.ts +0 -30
- package/dist/template/types.d.ts +0 -30
- package/dist/testing/index.d.ts +0 -1
- package/dist/testing/index.js +1 -16
- package/dist/testing/mock-audit.d.ts +0 -1
- package/dist/testing/mock-context.d.ts +0 -1
- package/dist/testing/mock-logger.d.ts +0 -1
- package/dist/testing/mock-router.d.ts +0 -1
- package/dist/testing/mock-storage.d.ts +0 -1
- package/dist/testing/mock-store.d.ts +0 -1
- package/dist/tools/delegate.d.ts +0 -7
- package/dist/tools/index.d.ts +0 -4
- package/dist/tools/node/builtin.d.ts +0 -16
- package/dist/tools/node/index.d.ts +0 -20
- package/dist/tools/node/index.js +36 -59
- package/dist/types/index.d.ts +0 -20
- package/dist/types/task-log.types.d.ts +0 -4
- package/dist/utils/env-defaults.d.ts +0 -16
- package/dist/utils/glob-match.d.ts +0 -16
- package/dist/utils/id.d.ts +0 -15
- package/dist/utils/timestamp.d.ts +0 -1
- package/dist/utils/workspace.d.ts +0 -4
- package/package.json +24 -25
- package/dist/adapter/context-builder.js +0 -87
- package/dist/adapter/index.js +0 -21
- package/dist/adapter/plugin-helper.js +0 -45
- package/dist/adapter/scoped-store.js +0 -43
- package/dist/adapter/types.js +0 -23
- package/dist/agent/resolver.js +0 -46
- package/dist/boxing/box-storage.interface.js +0 -6
- package/dist/boxing/box.service.js +0 -73
- package/dist/boxing/box.types.js +0 -6
- package/dist/boxing/context-builder.js +0 -79
- package/dist/client/CrewxClient.js +0 -86
- package/dist/config/loader.browser.js +0 -59
- package/dist/config/loader.js +0 -95
- package/dist/conversation/index.js +0 -25
- package/dist/conversation/sqlite-provider.js +0 -178
- package/dist/conversation/to-task-reader.js +0 -28
- package/dist/conversation/to-template-messages.js +0 -34
- package/dist/conversation/types.js +0 -10
- package/dist/events/TypedEventEmitter.js +0 -65
- package/dist/events/types.js +0 -9
- package/dist/facade/Crewx.browser.js +0 -314
- package/dist/facade/Crewx.js +0 -1299
- package/dist/hooks/define.js +0 -13
- package/dist/hooks/dispatch.js +0 -147
- package/dist/hooks/observer.js +0 -60
- package/dist/hooks/plugin.js +0 -17
- package/dist/hooks/tool-normalize.js +0 -110
- package/dist/hooks/types.js +0 -12
- package/dist/hooks/yaml-plugin.js +0 -356
- package/dist/layout/loader.js +0 -305
- package/dist/layout/props-validator.js +0 -301
- package/dist/layout/renderer.js +0 -193
- package/dist/layout/types.js +0 -36
- package/dist/parallel/agent-runtime.js +0 -25
- package/dist/parallel/helpers.js +0 -219
- package/dist/parallel/index.js +0 -13
- package/dist/parallel/parallel-runner.js +0 -226
- package/dist/parallel/types.js +0 -6
- package/dist/parsers/agent-call.util.js +0 -19
- package/dist/parsers/claude.parser.js +0 -67
- package/dist/parsers/codex.parser.js +0 -100
- package/dist/parsers/copilot.parser.js +0 -66
- package/dist/parsers/gemini.parser.js +0 -46
- package/dist/parsers/opencode.parser.js +0 -76
- package/dist/parsers/router.js +0 -56
- package/dist/platform/BrowserFsAdapter.js +0 -84
- package/dist/platform/IFsAdapter.js +0 -3
- package/dist/platform/NodeFsAdapter.js +0 -38
- package/dist/plugin/plugin-provider.js +0 -207
- package/dist/plugin/types.js +0 -9
- package/dist/plugin.js +0 -29
- package/dist/plugins/conversation.js +0 -59
- package/dist/plugins/file-logger.js +0 -87
- package/dist/plugins/sqlite-tracing.js +0 -112
- package/dist/provider/bridge.browser.js +0 -49
- package/dist/provider/bridge.js +0 -381
- package/dist/provider/parse-usage.js +0 -83
- package/dist/provider/register-api.js +0 -24
- package/dist/provider/vercel-runtime.js +0 -347
- package/dist/remote/index.js +0 -32
- package/dist/remote/remote-agent-manager.js +0 -198
- package/dist/remote/remote-provider.js +0 -141
- package/dist/remote/remote-transport.js +0 -83
- package/dist/remote/types.js +0 -9
- package/dist/server/auth.js +0 -35
- package/dist/server/handler.js +0 -75
- package/dist/server/index.js +0 -9
- package/dist/server/tool-adapter.js +0 -95
- package/dist/template/engine.js +0 -137
- package/dist/template/helpers/exec.browser.js +0 -41
- package/dist/template/helpers/exec.js +0 -230
- package/dist/template/helpers/fenced_code.js +0 -20
- package/dist/template/helpers/format-conversation.js +0 -53
- package/dist/template/helpers/include.js +0 -23
- package/dist/template/helpers/p1p2.js +0 -90
- package/dist/template/loader/DocumentLoader.js +0 -128
- package/dist/template/types.js +0 -6
- package/dist/testing/mock-audit.js +0 -13
- package/dist/testing/mock-context.js +0 -68
- package/dist/testing/mock-logger.js +0 -27
- package/dist/testing/mock-router.js +0 -67
- package/dist/testing/mock-storage.js +0 -21
- package/dist/testing/mock-store.js +0 -8
- package/dist/tools/delegate.js +0 -60
- package/dist/tools/index.js +0 -9
- package/dist/tools/node/builtin.js +0 -547
- package/dist/types/index.js +0 -32
- package/dist/types/task-log.types.js +0 -6
- package/dist/utils/env-defaults.js +0 -27
- package/dist/utils/glob-match.js +0 -42
- package/dist/utils/id.js +0 -50
- package/dist/utils/timestamp.js +0 -13
- package/dist/utils/workspace.js +0 -58
package/dist/parallel/helpers.js
DELETED
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.runExecutesParallel = exports.runQueriesParallel = void 0;
|
|
4
|
-
const parallel_runner_1 = require("./parallel-runner");
|
|
5
|
-
const agent_runtime_1 = require("./agent-runtime");
|
|
6
|
-
const DEFAULT_CONCURRENCY = 3;
|
|
7
|
-
const DEFAULT_TIMEOUT_MS = 30_000;
|
|
8
|
-
const DEFAULT_RETRY_DELAY_MS = 500;
|
|
9
|
-
const normalizeConcurrency = (value) => {
|
|
10
|
-
if (typeof value !== 'number' || Number.isNaN(value) || !Number.isFinite(value)) {
|
|
11
|
-
return DEFAULT_CONCURRENCY;
|
|
12
|
-
}
|
|
13
|
-
const normalized = Math.floor(value);
|
|
14
|
-
return normalized > 0 ? normalized : DEFAULT_CONCURRENCY;
|
|
15
|
-
};
|
|
16
|
-
const normalizeTimeout = (value) => {
|
|
17
|
-
if (value === undefined)
|
|
18
|
-
return DEFAULT_TIMEOUT_MS;
|
|
19
|
-
if (typeof value !== 'number' || Number.isNaN(value) || value <= 0)
|
|
20
|
-
return DEFAULT_TIMEOUT_MS;
|
|
21
|
-
return value;
|
|
22
|
-
};
|
|
23
|
-
const normalizeRetryPolicy = (policy) => {
|
|
24
|
-
if (!policy)
|
|
25
|
-
return { maxRetries: 0, retryDelay: DEFAULT_RETRY_DELAY_MS };
|
|
26
|
-
const maxRetries = Number.isInteger(policy.maxRetries) && policy.maxRetries >= 0
|
|
27
|
-
? policy.maxRetries
|
|
28
|
-
: 0;
|
|
29
|
-
const retryDelay = typeof policy.retryDelay === 'number' && policy.retryDelay >= 0
|
|
30
|
-
? policy.retryDelay
|
|
31
|
-
: DEFAULT_RETRY_DELAY_MS;
|
|
32
|
-
return { maxRetries, retryDelay };
|
|
33
|
-
};
|
|
34
|
-
const createAbortError = (signal) => {
|
|
35
|
-
const reason = signal.reason;
|
|
36
|
-
if (reason instanceof Error)
|
|
37
|
-
return reason;
|
|
38
|
-
if (typeof reason === 'string')
|
|
39
|
-
return new Error(reason);
|
|
40
|
-
return new Error('Parallel operation aborted');
|
|
41
|
-
};
|
|
42
|
-
const waitForDelay = (delayMs, signal) => {
|
|
43
|
-
if (delayMs <= 0)
|
|
44
|
-
return Promise.resolve();
|
|
45
|
-
return new Promise((resolve, reject) => {
|
|
46
|
-
const timer = setTimeout(() => {
|
|
47
|
-
signal.removeEventListener('abort', onAbort);
|
|
48
|
-
resolve();
|
|
49
|
-
}, delayMs);
|
|
50
|
-
const onAbort = () => {
|
|
51
|
-
clearTimeout(timer);
|
|
52
|
-
reject(createAbortError(signal));
|
|
53
|
-
};
|
|
54
|
-
if (signal.aborted) {
|
|
55
|
-
onAbort();
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
signal.addEventListener('abort', onAbort, { once: true });
|
|
59
|
-
});
|
|
60
|
-
};
|
|
61
|
-
const executeWithRetry = async (execute, retryPolicy, signal) => {
|
|
62
|
-
let lastFailureResult;
|
|
63
|
-
let lastError;
|
|
64
|
-
for (let attempt = 0; attempt <= retryPolicy.maxRetries; attempt++) {
|
|
65
|
-
if (signal.aborted)
|
|
66
|
-
throw createAbortError(signal);
|
|
67
|
-
try {
|
|
68
|
-
const result = await execute();
|
|
69
|
-
lastFailureResult = result;
|
|
70
|
-
if (result.success || attempt === retryPolicy.maxRetries)
|
|
71
|
-
return result;
|
|
72
|
-
}
|
|
73
|
-
catch (error) {
|
|
74
|
-
lastError = error;
|
|
75
|
-
if (signal.aborted)
|
|
76
|
-
throw createAbortError(signal);
|
|
77
|
-
if (attempt === retryPolicy.maxRetries) {
|
|
78
|
-
throw error instanceof Error ? error : new Error(String(error));
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
if (attempt < retryPolicy.maxRetries) {
|
|
82
|
-
await waitForDelay(retryPolicy.retryDelay, signal);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
if (lastFailureResult)
|
|
86
|
-
return lastFailureResult;
|
|
87
|
-
if (lastError)
|
|
88
|
-
throw lastError instanceof Error ? lastError : new Error(String(lastError));
|
|
89
|
-
throw new Error('Parallel helper encountered an unexpected state');
|
|
90
|
-
};
|
|
91
|
-
const recordProgress = (config, state, wasSuccessful) => {
|
|
92
|
-
state.completed += 1;
|
|
93
|
-
if (wasSuccessful)
|
|
94
|
-
state.success += 1;
|
|
95
|
-
else
|
|
96
|
-
state.failure += 1;
|
|
97
|
-
try {
|
|
98
|
-
config.onProgress?.(state.completed, state.total);
|
|
99
|
-
}
|
|
100
|
-
catch (error) {
|
|
101
|
-
if (process.env['NODE_ENV'] !== 'production') {
|
|
102
|
-
console.warn('Parallel helper onProgress callback threw an error:', error);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
const buildAgentResults = (taskResults) => {
|
|
107
|
-
const decorated = taskResults.map((taskResult) => ({
|
|
108
|
-
metadata: taskResult.metadata,
|
|
109
|
-
taskResult,
|
|
110
|
-
}));
|
|
111
|
-
return decorated
|
|
112
|
-
.slice()
|
|
113
|
-
.sort((a, b) => a.metadata.index - b.metadata.index)
|
|
114
|
-
.map(({ metadata, taskResult }) => {
|
|
115
|
-
if (taskResult.value) {
|
|
116
|
-
const base = taskResult.value;
|
|
117
|
-
return {
|
|
118
|
-
...base,
|
|
119
|
-
agentId: base.agentId ?? metadata.request.agentId,
|
|
120
|
-
metadata: {
|
|
121
|
-
...base.metadata,
|
|
122
|
-
requestIndex: metadata.index,
|
|
123
|
-
mode: metadata.mode,
|
|
124
|
-
},
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
const error = taskResult.error ?? new Error('Unknown error');
|
|
128
|
-
return {
|
|
129
|
-
agentId: metadata.request.agentId,
|
|
130
|
-
content: error.message,
|
|
131
|
-
success: false,
|
|
132
|
-
metadata: {
|
|
133
|
-
error: error.message,
|
|
134
|
-
aborted: taskResult.aborted ?? false,
|
|
135
|
-
requestIndex: metadata.index,
|
|
136
|
-
mode: metadata.mode,
|
|
137
|
-
},
|
|
138
|
-
};
|
|
139
|
-
});
|
|
140
|
-
};
|
|
141
|
-
const collectErrors = (taskResults) => {
|
|
142
|
-
return taskResults
|
|
143
|
-
.filter((r) => !r.success)
|
|
144
|
-
.map((taskResult) => {
|
|
145
|
-
const meta = taskResult.metadata;
|
|
146
|
-
if (taskResult.error instanceof Error) {
|
|
147
|
-
return { index: meta.index, error: taskResult.error };
|
|
148
|
-
}
|
|
149
|
-
if (taskResult.value && !taskResult.value.success) {
|
|
150
|
-
const msg = String(taskResult.value.metadata?.['error'] ?? taskResult.value.content ?? 'Agent returned unsuccessful result');
|
|
151
|
-
return { index: meta.index, error: new Error(msg) };
|
|
152
|
-
}
|
|
153
|
-
return { index: meta.index, error: new Error('Unknown failure') };
|
|
154
|
-
});
|
|
155
|
-
};
|
|
156
|
-
const createCallbacks = (progressState, config) => ({
|
|
157
|
-
onTaskComplete: async (result) => {
|
|
158
|
-
recordProgress(config, progressState, result.success);
|
|
159
|
-
},
|
|
160
|
-
onError: async () => {
|
|
161
|
-
recordProgress(config, progressState, false);
|
|
162
|
-
},
|
|
163
|
-
});
|
|
164
|
-
const runAgentOperations = async (requests, mode, config = {}) => {
|
|
165
|
-
if (!Array.isArray(requests)) {
|
|
166
|
-
throw new TypeError('Parallel helpers expect an array of requests');
|
|
167
|
-
}
|
|
168
|
-
if (requests.length === 0) {
|
|
169
|
-
const emptyMetrics = {
|
|
170
|
-
totalTasks: 0, startedTasks: 0, completedTasks: 0,
|
|
171
|
-
successCount: 0, failureCount: 0, totalDurationMs: 0,
|
|
172
|
-
averageDurationMs: 0, throughput: 0,
|
|
173
|
-
};
|
|
174
|
-
const summary = {
|
|
175
|
-
total: 0, completed: 0, successCount: 0, failureCount: 0,
|
|
176
|
-
results: [], errors: [], metrics: emptyMetrics,
|
|
177
|
-
};
|
|
178
|
-
config.onComplete?.(summary);
|
|
179
|
-
return [];
|
|
180
|
-
}
|
|
181
|
-
const concurrency = normalizeConcurrency(config.concurrency);
|
|
182
|
-
const timeout = normalizeTimeout(config.timeout);
|
|
183
|
-
const retryPolicy = normalizeRetryPolicy(config.retryPolicy);
|
|
184
|
-
const runner = new parallel_runner_1.ParallelRunner();
|
|
185
|
-
const runtime = new agent_runtime_1.AgentRuntime();
|
|
186
|
-
const tasks = requests.map((request, index) => ({
|
|
187
|
-
id: `${mode}:${request.agentId ?? 'anonymous'}:${index}`,
|
|
188
|
-
metadata: { index, mode, request },
|
|
189
|
-
run: (context) => executeWithRetry(() => mode === 'query'
|
|
190
|
-
? runtime.query(request)
|
|
191
|
-
: runtime.execute(request), retryPolicy, context.signal),
|
|
192
|
-
}));
|
|
193
|
-
const progressState = { completed: 0, success: 0, failure: 0, total: requests.length };
|
|
194
|
-
const taskResults = await runner.run(tasks, {
|
|
195
|
-
maxConcurrency: concurrency,
|
|
196
|
-
timeoutMs: timeout,
|
|
197
|
-
evaluateTaskSuccess: (value) => value.success,
|
|
198
|
-
callbacks: createCallbacks(progressState, config),
|
|
199
|
-
});
|
|
200
|
-
const agentResults = buildAgentResults(taskResults);
|
|
201
|
-
const errors = collectErrors(taskResults);
|
|
202
|
-
const metrics = runner.getMetrics();
|
|
203
|
-
const summary = {
|
|
204
|
-
total: requests.length,
|
|
205
|
-
completed: requests.length,
|
|
206
|
-
successCount: agentResults.filter((r) => r.success).length,
|
|
207
|
-
failureCount: agentResults.filter((r) => !r.success).length,
|
|
208
|
-
results: agentResults,
|
|
209
|
-
errors,
|
|
210
|
-
metrics,
|
|
211
|
-
};
|
|
212
|
-
config.onComplete?.(summary);
|
|
213
|
-
return agentResults;
|
|
214
|
-
};
|
|
215
|
-
const runQueriesParallel = (queries, config) => runAgentOperations(queries, 'query', config);
|
|
216
|
-
exports.runQueriesParallel = runQueriesParallel;
|
|
217
|
-
const runExecutesParallel = (requests, config) => runAgentOperations(requests, 'execute', config);
|
|
218
|
-
exports.runExecutesParallel = runExecutesParallel;
|
|
219
|
-
//# sourceMappingURL=helpers.js.map
|
package/dist/parallel/index.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AgentRuntime = exports.runExecutesParallel = exports.runQueriesParallel = exports.ParallelRunnerTimeoutError = exports.ParallelRunner = void 0;
|
|
4
|
-
var parallel_runner_1 = require("./parallel-runner");
|
|
5
|
-
Object.defineProperty(exports, "ParallelRunner", { enumerable: true, get: function () { return parallel_runner_1.ParallelRunner; } });
|
|
6
|
-
var parallel_runner_2 = require("./parallel-runner");
|
|
7
|
-
Object.defineProperty(exports, "ParallelRunnerTimeoutError", { enumerable: true, get: function () { return parallel_runner_2.ParallelRunnerTimeoutError; } });
|
|
8
|
-
var helpers_1 = require("./helpers");
|
|
9
|
-
Object.defineProperty(exports, "runQueriesParallel", { enumerable: true, get: function () { return helpers_1.runQueriesParallel; } });
|
|
10
|
-
Object.defineProperty(exports, "runExecutesParallel", { enumerable: true, get: function () { return helpers_1.runExecutesParallel; } });
|
|
11
|
-
var agent_runtime_1 = require("./agent-runtime");
|
|
12
|
-
Object.defineProperty(exports, "AgentRuntime", { enumerable: true, get: function () { return agent_runtime_1.AgentRuntime; } });
|
|
13
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ParallelRunner = exports.ParallelRunnerTimeoutError = void 0;
|
|
4
|
-
const node_perf_hooks_1 = require("node:perf_hooks");
|
|
5
|
-
/**
|
|
6
|
-
* Error raised when a task exceeds the configured per-task timeout.
|
|
7
|
-
*/
|
|
8
|
-
class ParallelRunnerTimeoutError extends Error {
|
|
9
|
-
taskId;
|
|
10
|
-
timeoutMs;
|
|
11
|
-
constructor(taskId, timeoutMs) {
|
|
12
|
-
super(`Task ${taskId} timed out after ${timeoutMs}ms`);
|
|
13
|
-
this.taskId = taskId;
|
|
14
|
-
this.timeoutMs = timeoutMs;
|
|
15
|
-
this.name = 'ParallelRunnerTimeoutError';
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
exports.ParallelRunnerTimeoutError = ParallelRunnerTimeoutError;
|
|
19
|
-
/**
|
|
20
|
-
* Executes tasks with bounded concurrency and cooperative cancellation support.
|
|
21
|
-
* Framework-agnostic — usable from CLI, SDK, or any consumer.
|
|
22
|
-
*/
|
|
23
|
-
class ParallelRunner {
|
|
24
|
-
defaults;
|
|
25
|
-
metrics = {
|
|
26
|
-
totalTasks: 0,
|
|
27
|
-
startedTasks: 0,
|
|
28
|
-
completedTasks: 0,
|
|
29
|
-
successCount: 0,
|
|
30
|
-
failureCount: 0,
|
|
31
|
-
totalDurationMs: 0,
|
|
32
|
-
averageDurationMs: 0,
|
|
33
|
-
throughput: 0,
|
|
34
|
-
};
|
|
35
|
-
constructor(defaults = {}) {
|
|
36
|
-
this.defaults = defaults;
|
|
37
|
-
}
|
|
38
|
-
async run(tasks, options = {}) {
|
|
39
|
-
if (!Array.isArray(tasks)) {
|
|
40
|
-
throw new TypeError('ParallelRunner.run expects an array of tasks');
|
|
41
|
-
}
|
|
42
|
-
if (tasks.length === 0) {
|
|
43
|
-
this.metrics = {
|
|
44
|
-
totalTasks: 0,
|
|
45
|
-
startedTasks: 0,
|
|
46
|
-
completedTasks: 0,
|
|
47
|
-
successCount: 0,
|
|
48
|
-
failureCount: 0,
|
|
49
|
-
totalDurationMs: 0,
|
|
50
|
-
averageDurationMs: 0,
|
|
51
|
-
throughput: 0,
|
|
52
|
-
};
|
|
53
|
-
return [];
|
|
54
|
-
}
|
|
55
|
-
const merged = this.mergeOptions(options);
|
|
56
|
-
const maxConcurrency = Math.max(1, merged.maxConcurrency ?? 5);
|
|
57
|
-
const timeoutMs = merged.timeoutMs;
|
|
58
|
-
const failFast = merged.failFast ?? false;
|
|
59
|
-
const callbacks = merged.callbacks;
|
|
60
|
-
const evaluateTaskSuccess = merged.evaluateTaskSuccess ?? (() => true);
|
|
61
|
-
const results = [];
|
|
62
|
-
let successCount = 0;
|
|
63
|
-
let failureCount = 0;
|
|
64
|
-
let startedTasks = 0;
|
|
65
|
-
let aborted = false;
|
|
66
|
-
let cursor = 0;
|
|
67
|
-
const startedAt = node_perf_hooks_1.performance.now();
|
|
68
|
-
const executeTask = async (task) => {
|
|
69
|
-
if (callbacks?.onTaskStart) {
|
|
70
|
-
await callbacks.onTaskStart(task);
|
|
71
|
-
}
|
|
72
|
-
startedTasks += 1;
|
|
73
|
-
const controller = new AbortController();
|
|
74
|
-
const context = { signal: controller.signal };
|
|
75
|
-
let timeoutId;
|
|
76
|
-
let timeoutPromise;
|
|
77
|
-
if (typeof timeoutMs === 'number' && Number.isFinite(timeoutMs) && timeoutMs > 0) {
|
|
78
|
-
timeoutPromise = new Promise((_, reject) => {
|
|
79
|
-
timeoutId = setTimeout(() => {
|
|
80
|
-
const err = new ParallelRunnerTimeoutError(task.id, timeoutMs);
|
|
81
|
-
controller.abort(err);
|
|
82
|
-
reject(err);
|
|
83
|
-
}, timeoutMs);
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
const taskStartedAt = node_perf_hooks_1.performance.now();
|
|
87
|
-
const runPromise = task.run(context);
|
|
88
|
-
const combinedPromise = timeoutPromise
|
|
89
|
-
? Promise.race([runPromise, timeoutPromise])
|
|
90
|
-
: runPromise;
|
|
91
|
-
try {
|
|
92
|
-
const value = await combinedPromise;
|
|
93
|
-
const taskFinishedAt = node_perf_hooks_1.performance.now();
|
|
94
|
-
const durationMs = taskFinishedAt - taskStartedAt;
|
|
95
|
-
const success = evaluateTaskSuccess(value, task);
|
|
96
|
-
const result = {
|
|
97
|
-
taskId: task.id,
|
|
98
|
-
success,
|
|
99
|
-
value,
|
|
100
|
-
durationMs,
|
|
101
|
-
startedAt: taskStartedAt,
|
|
102
|
-
finishedAt: taskFinishedAt,
|
|
103
|
-
metadata: task.metadata,
|
|
104
|
-
aborted: false,
|
|
105
|
-
};
|
|
106
|
-
results.push(result);
|
|
107
|
-
success ? (successCount += 1) : (failureCount += 1);
|
|
108
|
-
if (callbacks?.onTaskComplete) {
|
|
109
|
-
await callbacks.onTaskComplete(result);
|
|
110
|
-
}
|
|
111
|
-
if (failFast && !success) {
|
|
112
|
-
aborted = true;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
catch (rawError) {
|
|
116
|
-
const taskFinishedAt = node_perf_hooks_1.performance.now();
|
|
117
|
-
const durationMs = taskFinishedAt - taskStartedAt;
|
|
118
|
-
const error = rawError instanceof Error ? rawError : new Error(String(rawError));
|
|
119
|
-
const result = {
|
|
120
|
-
taskId: task.id,
|
|
121
|
-
success: false,
|
|
122
|
-
error,
|
|
123
|
-
durationMs,
|
|
124
|
-
startedAt: taskStartedAt,
|
|
125
|
-
finishedAt: taskFinishedAt,
|
|
126
|
-
metadata: task.metadata,
|
|
127
|
-
aborted: controller.signal.aborted,
|
|
128
|
-
};
|
|
129
|
-
results.push(result);
|
|
130
|
-
failureCount += 1;
|
|
131
|
-
if (callbacks?.onError) {
|
|
132
|
-
await callbacks.onError(task, error, durationMs);
|
|
133
|
-
}
|
|
134
|
-
if (failFast) {
|
|
135
|
-
aborted = true;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
finally {
|
|
139
|
-
if (timeoutId)
|
|
140
|
-
clearTimeout(timeoutId);
|
|
141
|
-
// Prevent unhandled rejections if timeout fired before task finished
|
|
142
|
-
if (timeoutPromise)
|
|
143
|
-
runPromise.catch(() => undefined);
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
const worker = async () => {
|
|
147
|
-
while (true) {
|
|
148
|
-
if (aborted)
|
|
149
|
-
break;
|
|
150
|
-
const index = cursor;
|
|
151
|
-
if (index >= tasks.length)
|
|
152
|
-
break;
|
|
153
|
-
cursor += 1;
|
|
154
|
-
const task = tasks[index];
|
|
155
|
-
if (!task)
|
|
156
|
-
break;
|
|
157
|
-
await executeTask(task);
|
|
158
|
-
if (aborted)
|
|
159
|
-
break;
|
|
160
|
-
}
|
|
161
|
-
};
|
|
162
|
-
const workerCount = Math.min(maxConcurrency, tasks.length);
|
|
163
|
-
const workers = [];
|
|
164
|
-
for (let i = 0; i < workerCount; i++) {
|
|
165
|
-
workers.push(worker());
|
|
166
|
-
}
|
|
167
|
-
await Promise.all(workers);
|
|
168
|
-
const finishedAt = node_perf_hooks_1.performance.now();
|
|
169
|
-
const totalDurationMs = finishedAt - startedAt;
|
|
170
|
-
const averageDurationMs = results.length
|
|
171
|
-
? results.reduce((sum, r) => sum + r.durationMs, 0) / results.length
|
|
172
|
-
: 0;
|
|
173
|
-
const throughput = totalDurationMs > 0
|
|
174
|
-
? results.length / (totalDurationMs / 1000)
|
|
175
|
-
: results.length;
|
|
176
|
-
this.metrics = {
|
|
177
|
-
totalTasks: tasks.length,
|
|
178
|
-
startedTasks,
|
|
179
|
-
completedTasks: results.length,
|
|
180
|
-
successCount,
|
|
181
|
-
failureCount,
|
|
182
|
-
totalDurationMs,
|
|
183
|
-
averageDurationMs,
|
|
184
|
-
throughput,
|
|
185
|
-
};
|
|
186
|
-
return results;
|
|
187
|
-
}
|
|
188
|
-
getMetrics() {
|
|
189
|
-
return this.metrics;
|
|
190
|
-
}
|
|
191
|
-
mergeOptions(options) {
|
|
192
|
-
return {
|
|
193
|
-
maxConcurrency: options.maxConcurrency ?? this.defaults.maxConcurrency,
|
|
194
|
-
timeoutMs: options.timeoutMs ?? this.defaults.timeoutMs,
|
|
195
|
-
failFast: options.failFast ?? this.defaults.failFast,
|
|
196
|
-
evaluateTaskSuccess: options.evaluateTaskSuccess ?? this.defaults.evaluateTaskSuccess,
|
|
197
|
-
callbacks: this.mergeCallbacks(this.defaults.callbacks, options.callbacks),
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
mergeCallbacks(base, override) {
|
|
201
|
-
if (!base && !override)
|
|
202
|
-
return undefined;
|
|
203
|
-
return {
|
|
204
|
-
onTaskStart: async (task) => {
|
|
205
|
-
if (base?.onTaskStart)
|
|
206
|
-
await base.onTaskStart(task);
|
|
207
|
-
if (override?.onTaskStart)
|
|
208
|
-
await override.onTaskStart(task);
|
|
209
|
-
},
|
|
210
|
-
onTaskComplete: async (result) => {
|
|
211
|
-
if (base?.onTaskComplete)
|
|
212
|
-
await base.onTaskComplete(result);
|
|
213
|
-
if (override?.onTaskComplete)
|
|
214
|
-
await override.onTaskComplete(result);
|
|
215
|
-
},
|
|
216
|
-
onError: async (task, error, durationMs) => {
|
|
217
|
-
if (base?.onError)
|
|
218
|
-
await base.onError(task, error, durationMs);
|
|
219
|
-
if (override?.onError)
|
|
220
|
-
await override.onError(task, error, durationMs);
|
|
221
|
-
},
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
exports.ParallelRunner = ParallelRunner;
|
|
226
|
-
//# sourceMappingURL=parallel-runner.js.map
|
package/dist/parallel/types.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isAgentCallCommand = isAgentCallCommand;
|
|
4
|
-
exports.parseAgentCall = parseAgentCall;
|
|
5
|
-
/** Detect crewx execute/x command pattern */
|
|
6
|
-
function isAgentCallCommand(command) {
|
|
7
|
-
return /crewx\s+(x|execute)\s/.test(command);
|
|
8
|
-
}
|
|
9
|
-
/** Extract agent_call entry from crewx x "@agent ..." command */
|
|
10
|
-
function parseAgentCall(timestamp, command) {
|
|
11
|
-
const agentMatch = command.match(/@(\S+)/);
|
|
12
|
-
return {
|
|
13
|
-
timestamp,
|
|
14
|
-
type: 'agent_call',
|
|
15
|
-
targetAgent: agentMatch?.[1]?.replace(/["']/g, ''),
|
|
16
|
-
toolInput: command,
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
//# sourceMappingURL=agent-call.util.js.map
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseClaudeEvent = parseClaudeEvent;
|
|
4
|
-
const agent_call_util_1 = require("./agent-call.util");
|
|
5
|
-
/**
|
|
6
|
-
* Parse Claude stream-json events into TaskLogEntry[].
|
|
7
|
-
*
|
|
8
|
-
* Claude events:
|
|
9
|
-
* - { type: "assistant", message: { content: [{ type: "text"|"tool_use", ... }] } }
|
|
10
|
-
* - { type: "user", message: { content: [{ type: "tool_result", ... }] } }
|
|
11
|
-
*/
|
|
12
|
-
function parseClaudeEvent(timestamp, parsed) {
|
|
13
|
-
const msg = parsed.message;
|
|
14
|
-
const content = msg?.content;
|
|
15
|
-
if (!Array.isArray(content))
|
|
16
|
-
return [];
|
|
17
|
-
const entries = [];
|
|
18
|
-
for (const block of content) {
|
|
19
|
-
const entry = parseClaudeBlock(timestamp, block);
|
|
20
|
-
if (entry)
|
|
21
|
-
entries.push(entry);
|
|
22
|
-
}
|
|
23
|
-
return entries;
|
|
24
|
-
}
|
|
25
|
-
function parseClaudeBlock(timestamp, block) {
|
|
26
|
-
const blockType = block.type;
|
|
27
|
-
if (blockType === 'text') {
|
|
28
|
-
const text = String(block.text || '');
|
|
29
|
-
if (!text)
|
|
30
|
-
return null;
|
|
31
|
-
return { timestamp, type: 'text', content: text };
|
|
32
|
-
}
|
|
33
|
-
if (blockType === 'tool_use') {
|
|
34
|
-
const toolName = String(block.name || '');
|
|
35
|
-
const toolUseId = block.id;
|
|
36
|
-
const input = block.input;
|
|
37
|
-
const inputStr = input?.command
|
|
38
|
-
? String(input.command)
|
|
39
|
-
: JSON.stringify(input || {});
|
|
40
|
-
if (toolName === 'Bash' && (0, agent_call_util_1.isAgentCallCommand)(inputStr)) {
|
|
41
|
-
return (0, agent_call_util_1.parseAgentCall)(timestamp, inputStr);
|
|
42
|
-
}
|
|
43
|
-
return { timestamp, type: 'tool_use', toolUseId, toolName, toolInput: inputStr };
|
|
44
|
-
}
|
|
45
|
-
if (blockType === 'tool_result') {
|
|
46
|
-
const isError = Boolean(block.is_error);
|
|
47
|
-
const toolUseId = block.tool_use_id;
|
|
48
|
-
const raw = block.output ?? block.content ?? '';
|
|
49
|
-
let output;
|
|
50
|
-
if (typeof raw === 'string') {
|
|
51
|
-
output = raw;
|
|
52
|
-
}
|
|
53
|
-
else if (Array.isArray(raw)) {
|
|
54
|
-
// Claude tool_result content can be [{ type: "text", text: "..." }, ...]
|
|
55
|
-
output = raw
|
|
56
|
-
.filter(c => c.type === 'text' && typeof c.text === 'string')
|
|
57
|
-
.map(c => c.text)
|
|
58
|
-
.join('\n');
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
output = JSON.stringify(raw);
|
|
62
|
-
}
|
|
63
|
-
return { timestamp, type: 'tool_result', toolUseId, resultPreview: output, isError };
|
|
64
|
-
}
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
67
|
-
//# sourceMappingURL=claude.parser.js.map
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseCodexEvent = parseCodexEvent;
|
|
4
|
-
const agent_call_util_1 = require("./agent-call.util");
|
|
5
|
-
/**
|
|
6
|
-
* Parse Codex experimental-json events into TaskLogEntry[].
|
|
7
|
-
*
|
|
8
|
-
* Codex events:
|
|
9
|
-
* - { type: "item.started", item: { type: "command_execution", command } }
|
|
10
|
-
* - { type: "item.completed", item: { type: "command_execution"|"message"|"text"|"reasoning"|"tool_use"|"tool_result", ... } }
|
|
11
|
-
*/
|
|
12
|
-
function parseCodexEvent(timestamp, parsed) {
|
|
13
|
-
const type = parsed.type;
|
|
14
|
-
const item = parsed.item;
|
|
15
|
-
if (!item)
|
|
16
|
-
return [];
|
|
17
|
-
if (type === 'item.started') {
|
|
18
|
-
return parseItemStarted(timestamp, item);
|
|
19
|
-
}
|
|
20
|
-
if (type === 'item.completed') {
|
|
21
|
-
const entry = parseItemCompleted(timestamp, item);
|
|
22
|
-
return entry ? [entry] : [];
|
|
23
|
-
}
|
|
24
|
-
return [];
|
|
25
|
-
}
|
|
26
|
-
function parseItemStarted(timestamp, item) {
|
|
27
|
-
const itemType = item.type;
|
|
28
|
-
if (itemType === 'command_execution') {
|
|
29
|
-
const command = String(item.command || '');
|
|
30
|
-
if ((0, agent_call_util_1.isAgentCallCommand)(command)) {
|
|
31
|
-
return [(0, agent_call_util_1.parseAgentCall)(timestamp, command)];
|
|
32
|
-
}
|
|
33
|
-
return [{ timestamp, type: 'tool_use', toolName: 'Bash', toolInput: command }];
|
|
34
|
-
}
|
|
35
|
-
return [];
|
|
36
|
-
}
|
|
37
|
-
function parseItemCompleted(timestamp, item) {
|
|
38
|
-
const itemType = item.type;
|
|
39
|
-
// assistant_message / message / text
|
|
40
|
-
if (itemType === 'message' || itemType === 'text') {
|
|
41
|
-
const content = item.content;
|
|
42
|
-
if (Array.isArray(content)) {
|
|
43
|
-
for (const block of content) {
|
|
44
|
-
const entry = parseCodexBlock(timestamp, block);
|
|
45
|
-
if (entry)
|
|
46
|
-
return entry;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
if (typeof item.text === 'string') {
|
|
50
|
-
return { timestamp, type: 'text', content: item.text };
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
if (itemType === 'reasoning') {
|
|
54
|
-
return { timestamp, type: 'text', content: String(item.text || '') };
|
|
55
|
-
}
|
|
56
|
-
// command_execution completed → tool_result (with error support)
|
|
57
|
-
if (itemType === 'command_execution') {
|
|
58
|
-
const output = String(item.aggregated_output || item.output || '');
|
|
59
|
-
const isError = Boolean(item.is_error);
|
|
60
|
-
return { timestamp, type: 'tool_result', resultPreview: output, isError };
|
|
61
|
-
}
|
|
62
|
-
// tool_use from Codex item.completed
|
|
63
|
-
if (itemType === 'tool_use') {
|
|
64
|
-
const toolName = String(item.name || item.tool_name || '');
|
|
65
|
-
const input = item.input;
|
|
66
|
-
const inputStr = input?.command
|
|
67
|
-
? String(input.command)
|
|
68
|
-
: JSON.stringify(input || {});
|
|
69
|
-
if (toolName === 'Bash' && (0, agent_call_util_1.isAgentCallCommand)(inputStr)) {
|
|
70
|
-
return (0, agent_call_util_1.parseAgentCall)(timestamp, inputStr);
|
|
71
|
-
}
|
|
72
|
-
return { timestamp, type: 'tool_use', toolName, toolInput: inputStr };
|
|
73
|
-
}
|
|
74
|
-
// tool_result from Codex item.completed
|
|
75
|
-
if (itemType === 'tool_result') {
|
|
76
|
-
const isError = Boolean(item.is_error);
|
|
77
|
-
const output = String(item.output || item.content || '');
|
|
78
|
-
return { timestamp, type: 'tool_result', resultPreview: output, isError };
|
|
79
|
-
}
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
82
|
-
function parseCodexBlock(timestamp, block) {
|
|
83
|
-
const blockType = block.type;
|
|
84
|
-
if (blockType === 'text') {
|
|
85
|
-
return { timestamp, type: 'text', content: String(block.text || '') };
|
|
86
|
-
}
|
|
87
|
-
if (blockType === 'tool_use') {
|
|
88
|
-
const toolName = String(block.name || '');
|
|
89
|
-
const input = block.input;
|
|
90
|
-
const inputStr = input?.command
|
|
91
|
-
? String(input.command)
|
|
92
|
-
: JSON.stringify(input || {});
|
|
93
|
-
if (toolName === 'Bash' && (0, agent_call_util_1.isAgentCallCommand)(inputStr)) {
|
|
94
|
-
return (0, agent_call_util_1.parseAgentCall)(timestamp, inputStr);
|
|
95
|
-
}
|
|
96
|
-
return { timestamp, type: 'tool_use', toolName, toolInput: inputStr };
|
|
97
|
-
}
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
100
|
-
//# sourceMappingURL=codex.parser.js.map
|