@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.
- 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 -2
- package/dist/esm/hooks/index.js +7 -6
- package/dist/esm/index.js +79 -60
- package/dist/esm/plugins/index.js +52 -0
- package/dist/esm/testing/index.js +1 -0
- package/dist/esm/tools/node/index.js +36 -54
- 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/esm/agent/resolver.js +0 -41
- package/dist/esm/boxing/box-storage.interface.js +0 -5
- package/dist/esm/boxing/box.service.js +0 -69
- package/dist/esm/boxing/box.types.js +0 -5
- package/dist/esm/boxing/context-builder.js +0 -76
- package/dist/esm/client/CrewxClient.js +0 -82
- package/dist/esm/config/loader.browser.js +0 -54
- package/dist/esm/config/loader.js +0 -77
- package/dist/esm/events/TypedEventEmitter.js +0 -61
- package/dist/esm/events/types.js +0 -8
- package/dist/esm/facade/Crewx.browser.js +0 -310
- package/dist/esm/facade/Crewx.js +0 -941
- package/dist/esm/hooks/define.js +0 -10
- package/dist/esm/hooks/dispatch.js +0 -76
- package/dist/esm/hooks/observer.js +0 -56
- package/dist/esm/hooks/plugin.js +0 -12
- package/dist/esm/hooks/types.js +0 -9
- package/dist/esm/index.browser.js +0 -15
- package/dist/esm/layout/loader.js +0 -268
- package/dist/esm/layout/props-validator.js +0 -297
- package/dist/esm/layout/renderer.js +0 -180
- package/dist/esm/layout/types.js +0 -31
- package/dist/esm/parallel/agent-runtime.js +0 -21
- package/dist/esm/parallel/helpers.js +0 -214
- package/dist/esm/parallel/index.js +0 -5
- package/dist/esm/parallel/parallel-runner.js +0 -221
- package/dist/esm/parallel/types.js +0 -5
- package/dist/esm/parsers/agent-call.util.js +0 -15
- package/dist/esm/parsers/claude.parser.js +0 -64
- package/dist/esm/parsers/codex.parser.js +0 -97
- package/dist/esm/parsers/copilot.parser.js +0 -63
- package/dist/esm/parsers/gemini.parser.js +0 -43
- package/dist/esm/parsers/opencode.parser.js +0 -73
- package/dist/esm/parsers/router.js +0 -53
- package/dist/esm/platform/BrowserFsAdapter.js +0 -80
- package/dist/esm/platform/IFsAdapter.js +0 -2
- package/dist/esm/platform/NodeFsAdapter.js +0 -34
- package/dist/esm/plugin/plugin-provider.js +0 -202
- package/dist/esm/plugin/types.js +0 -8
- package/dist/esm/plugin.js +0 -25
- package/dist/esm/provider/bridge.browser.js +0 -43
- package/dist/esm/provider/bridge.js +0 -373
- package/dist/esm/provider/parse-usage.js +0 -80
- package/dist/esm/provider/register-api.js +0 -21
- package/dist/esm/provider/vercel-runtime.js +0 -310
- package/dist/esm/remote/index.js +0 -10
- package/dist/esm/remote/remote-agent-manager.js +0 -194
- package/dist/esm/remote/remote-provider.js +0 -98
- package/dist/esm/remote/remote-transport.js +0 -79
- package/dist/esm/remote/types.js +0 -8
- package/dist/esm/server/auth.js +0 -31
- package/dist/esm/server/handler.js +0 -72
- package/dist/esm/server/index.js +0 -5
- package/dist/esm/server/tool-adapter.js +0 -92
- package/dist/esm/template/engine.js +0 -100
- package/dist/esm/template/helpers/exec.browser.js +0 -31
- package/dist/esm/template/helpers/exec.js +0 -220
- package/dist/esm/template/helpers/fenced_code.js +0 -17
- package/dist/esm/template/helpers/include.js +0 -20
- package/dist/esm/template/helpers/p1p2.js +0 -83
- package/dist/esm/template/loader/DocumentLoader.js +0 -124
- package/dist/esm/template/types.js +0 -5
- package/dist/esm/tools/delegate.js +0 -57
- package/dist/esm/tools/index.js +0 -5
- package/dist/esm/tools/node/builtin.js +0 -541
- package/dist/esm/types/index.js +0 -27
- package/dist/esm/types/task-log.types.js +0 -5
- package/dist/esm/utils/env-defaults.js +0 -23
- package/dist/esm/utils/glob-match.js +0 -38
- package/dist/esm/utils/id.js +0 -46
- package/dist/esm/utils/workspace.js +0 -21
- 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/api.parser.d.ts +0 -10
- package/dist/parsers/api.parser.js +0 -26
- 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/mastra-runtime.d.ts +0 -45
- package/dist/provider/mastra-runtime.js +0 -208
- 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
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* buildContext() — builds hot/warm context windows from thread messages and box summaries.
|
|
4
|
-
*/
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.buildContext = buildContext;
|
|
7
|
-
function buildContext(threadId, taskReader, boxService, params, tokenizer) {
|
|
8
|
-
const { maxTokens, hotzoneRatio, warmzoneRatio } = params;
|
|
9
|
-
const hotBudget = maxTokens * hotzoneRatio;
|
|
10
|
-
const warmBudget = maxTokens * warmzoneRatio;
|
|
11
|
-
const totalBudget = hotBudget + warmBudget;
|
|
12
|
-
const tasks = taskReader.getThreadMessages(threadId);
|
|
13
|
-
const hotMessages = [];
|
|
14
|
-
let hotTokens = 0;
|
|
15
|
-
let hotOverflow = false;
|
|
16
|
-
const taskPairs = [];
|
|
17
|
-
for (let i = 0; i < tasks.length; i += 2) {
|
|
18
|
-
const userMsg = tasks[i];
|
|
19
|
-
const assistantMsg = tasks[i + 1];
|
|
20
|
-
const prompt = userMsg?.content || '';
|
|
21
|
-
const result = assistantMsg?.content || '';
|
|
22
|
-
const tokens = tokenizer.countTokens(prompt + result);
|
|
23
|
-
const msgs = [];
|
|
24
|
-
if (userMsg)
|
|
25
|
-
msgs.push(userMsg);
|
|
26
|
-
if (assistantMsg)
|
|
27
|
-
msgs.push(assistantMsg);
|
|
28
|
-
taskPairs.push({ messages: msgs, tokens });
|
|
29
|
-
}
|
|
30
|
-
for (let i = taskPairs.length - 1; i >= 0; i--) {
|
|
31
|
-
const pair = taskPairs[i];
|
|
32
|
-
if (hotTokens + pair.tokens > hotBudget) {
|
|
33
|
-
hotOverflow = true;
|
|
34
|
-
break;
|
|
35
|
-
}
|
|
36
|
-
hotTokens += pair.tokens;
|
|
37
|
-
hotMessages.unshift(...pair.messages);
|
|
38
|
-
}
|
|
39
|
-
const warmBoxes = [];
|
|
40
|
-
let warmTokens = 0;
|
|
41
|
-
if (hotOverflow && warmBudget > 0) {
|
|
42
|
-
try {
|
|
43
|
-
const { boxes } = boxService.listBoxes(threadId);
|
|
44
|
-
for (let i = boxes.length - 1; i >= 0; i--) {
|
|
45
|
-
const box = boxes[i];
|
|
46
|
-
const tokens = box.summaryTokens ?? box.sourceTokens;
|
|
47
|
-
if (warmTokens + tokens > warmBudget)
|
|
48
|
-
break;
|
|
49
|
-
warmTokens += tokens;
|
|
50
|
-
warmBoxes.unshift({
|
|
51
|
-
boxId: box.id,
|
|
52
|
-
seq: box.seq,
|
|
53
|
-
taskCount: box.taskCount,
|
|
54
|
-
sourceTokens: box.sourceTokens,
|
|
55
|
-
summary: box.summary,
|
|
56
|
-
previewFirst: box.previewFirst,
|
|
57
|
-
previewMid: box.previewMid,
|
|
58
|
-
previewLast: box.previewLast,
|
|
59
|
-
createdAt: box.createdAt,
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
catch (error) {
|
|
64
|
-
if (error instanceof Error && !/not found/i.test(error.message)) {
|
|
65
|
-
throw error;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return {
|
|
70
|
-
hot: hotMessages,
|
|
71
|
-
warm: warmBoxes,
|
|
72
|
-
hotTokens,
|
|
73
|
-
warmTokens,
|
|
74
|
-
hotOverflow,
|
|
75
|
-
totalBudget,
|
|
76
|
-
config: { maxTokens, hotzoneRatio, warmzoneRatio },
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
//# sourceMappingURL=context-builder.js.map
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* CrewxClient — Browser client for CrewX SDK.
|
|
4
|
-
*
|
|
5
|
-
* Communicates with a server running CrewX SDK via HTTP.
|
|
6
|
-
* Handles the Client-Intercept pattern automatically:
|
|
7
|
-
* registerTool() + query() — that's it.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```ts
|
|
11
|
-
* import { CrewxClient } from '@crewx/sdk/client';
|
|
12
|
-
*
|
|
13
|
-
* const crewx = new CrewxClient('http://localhost:3000');
|
|
14
|
-
* crewx.registerTool('browser_storage_read', {
|
|
15
|
-
* execute: async ({ key }) => localStorage.getItem(key),
|
|
16
|
-
* });
|
|
17
|
-
*
|
|
18
|
-
* const result = await crewx.query('assistant', 'read my settings');
|
|
19
|
-
* console.log(result.data);
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.CrewxClient = void 0;
|
|
24
|
-
class CrewxClient {
|
|
25
|
-
baseUrl;
|
|
26
|
-
tools = new Map();
|
|
27
|
-
constructor(baseUrl) {
|
|
28
|
-
this.baseUrl = baseUrl.replace(/\/$/, '');
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Register a browser-side tool.
|
|
32
|
-
* When the server agent calls a tool with this name (and no server-side execute),
|
|
33
|
-
* CrewxClient automatically runs it locally and sends the result back.
|
|
34
|
-
*/
|
|
35
|
-
registerTool(name, definition) {
|
|
36
|
-
this.tools.set(name, definition);
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Send a message to an agent.
|
|
40
|
-
* The requires_action loop is handled automatically — if the agent calls a
|
|
41
|
-
* client tool, CrewxClient executes it locally and continues the conversation.
|
|
42
|
-
*/
|
|
43
|
-
async query(agent, message, callbacks) {
|
|
44
|
-
let response = await this._post('/api/chat', { agent, message });
|
|
45
|
-
while (response.status === 'requires_action') {
|
|
46
|
-
const { toolCall, threadId } = response;
|
|
47
|
-
if (!toolCall)
|
|
48
|
-
break;
|
|
49
|
-
const tool = this.tools.get(toolCall.toolName);
|
|
50
|
-
if (callbacks?.onToolCall) {
|
|
51
|
-
callbacks.onToolCall(toolCall);
|
|
52
|
-
}
|
|
53
|
-
let toolResult;
|
|
54
|
-
if (tool?.execute) {
|
|
55
|
-
try {
|
|
56
|
-
const raw = await tool.execute(toolCall.args);
|
|
57
|
-
toolResult = typeof raw === 'string' ? raw : JSON.stringify(raw);
|
|
58
|
-
}
|
|
59
|
-
catch (err) {
|
|
60
|
-
toolResult = `Error: ${err.message}`;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
toolResult = `Error: No client handler for tool "${toolCall.toolName}"`;
|
|
65
|
-
}
|
|
66
|
-
response = await this._post('/api/chat/continue', {
|
|
67
|
-
threadId,
|
|
68
|
-
toolCallId: toolCall.toolCallId,
|
|
69
|
-
result: toolResult,
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
return response;
|
|
73
|
-
}
|
|
74
|
-
async _post(path, body) {
|
|
75
|
-
const res = await fetch(`${this.baseUrl}${path}`, {
|
|
76
|
-
method: 'POST',
|
|
77
|
-
headers: { 'Content-Type': 'application/json' },
|
|
78
|
-
body: JSON.stringify(body),
|
|
79
|
-
});
|
|
80
|
-
if (!res.ok)
|
|
81
|
-
throw new Error(`HTTP ${res.status}`);
|
|
82
|
-
return res.json();
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
exports.CrewxClient = CrewxClient;
|
|
86
|
-
//# sourceMappingURL=CrewxClient.js.map
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Browser-safe YAML config loader.
|
|
4
|
-
* Only parseYamlContent — no file I/O.
|
|
5
|
-
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.ConfigLoadError = void 0;
|
|
8
|
-
exports.parseYamlContent = parseYamlContent;
|
|
9
|
-
const js_yaml_1 = require("js-yaml");
|
|
10
|
-
const index_js_1 = require("../types/index.js");
|
|
11
|
-
class ConfigLoadError extends Error {
|
|
12
|
-
cause;
|
|
13
|
-
constructor(message, cause) {
|
|
14
|
-
super(message);
|
|
15
|
-
this.cause = cause;
|
|
16
|
-
this.name = 'ConfigLoadError';
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
exports.ConfigLoadError = ConfigLoadError;
|
|
20
|
-
/**
|
|
21
|
-
* Parse YAML string into a validated CrewxProjectConfig.
|
|
22
|
-
*/
|
|
23
|
-
function parseYamlContent(yamlString) {
|
|
24
|
-
if (!yamlString || typeof yamlString !== 'string' || !yamlString.trim()) {
|
|
25
|
-
throw new ConfigLoadError('YAML content must be a non-empty string');
|
|
26
|
-
}
|
|
27
|
-
let raw;
|
|
28
|
-
try {
|
|
29
|
-
raw = (0, js_yaml_1.load)(yamlString);
|
|
30
|
-
}
|
|
31
|
-
catch (err) {
|
|
32
|
-
throw new ConfigLoadError(`YAML parse error: ${err.message}`, err);
|
|
33
|
-
}
|
|
34
|
-
const normalized = normalizeRaw(raw);
|
|
35
|
-
const result = index_js_1.CrewxProjectConfigSchema.safeParse(normalized);
|
|
36
|
-
if (!result.success) {
|
|
37
|
-
throw new ConfigLoadError(`Config validation error: ${result.error.message}`);
|
|
38
|
-
}
|
|
39
|
-
return result.data;
|
|
40
|
-
}
|
|
41
|
-
function normalizeRaw(raw) {
|
|
42
|
-
if (!raw || typeof raw !== 'object') {
|
|
43
|
-
return { agents: [] };
|
|
44
|
-
}
|
|
45
|
-
const obj = raw;
|
|
46
|
-
if (obj.agents && typeof obj.agents === 'object' && !Array.isArray(obj.agents)) {
|
|
47
|
-
const agentsMap = obj.agents;
|
|
48
|
-
const agentsArray = Object.entries(agentsMap).map(([id, cfg]) => {
|
|
49
|
-
const agentCfg = (cfg && typeof cfg === 'object' ? cfg : {});
|
|
50
|
-
return { id, ...agentCfg };
|
|
51
|
-
});
|
|
52
|
-
return { ...obj, agents: agentsArray };
|
|
53
|
-
}
|
|
54
|
-
if (!obj.agents) {
|
|
55
|
-
return { ...obj, agents: [] };
|
|
56
|
-
}
|
|
57
|
-
return obj;
|
|
58
|
-
}
|
|
59
|
-
//# sourceMappingURL=loader.browser.js.map
|
package/dist/config/loader.js
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* YAML configuration loader for CrewX projects.
|
|
4
|
-
* Reads crewx.yaml and validates it with Zod schema.
|
|
5
|
-
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.ConfigLoadError = void 0;
|
|
8
|
-
exports.parseYamlContent = parseYamlContent;
|
|
9
|
-
exports.loadYamlFile = loadYamlFile;
|
|
10
|
-
const js_yaml_1 = require("js-yaml");
|
|
11
|
-
const fs_1 = require("fs");
|
|
12
|
-
const types_1 = require("../types");
|
|
13
|
-
class ConfigLoadError extends Error {
|
|
14
|
-
cause;
|
|
15
|
-
constructor(message, cause) {
|
|
16
|
-
super(message);
|
|
17
|
-
this.cause = cause;
|
|
18
|
-
this.name = 'ConfigLoadError';
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
exports.ConfigLoadError = ConfigLoadError;
|
|
22
|
-
/**
|
|
23
|
-
* Parse YAML string into a validated CrewxProjectConfig.
|
|
24
|
-
* Converts the agents record (keyed by id) into an array.
|
|
25
|
-
*/
|
|
26
|
-
function parseYamlContent(yamlString) {
|
|
27
|
-
if (!yamlString || typeof yamlString !== 'string' || !yamlString.trim()) {
|
|
28
|
-
throw new ConfigLoadError('YAML content must be a non-empty string');
|
|
29
|
-
}
|
|
30
|
-
let raw;
|
|
31
|
-
try {
|
|
32
|
-
raw = (0, js_yaml_1.load)(yamlString);
|
|
33
|
-
}
|
|
34
|
-
catch (err) {
|
|
35
|
-
throw new ConfigLoadError(`YAML parse error: ${err.message}`, err);
|
|
36
|
-
}
|
|
37
|
-
// Normalize agents: YAML has agents as a map (Record<id, config>),
|
|
38
|
-
// but our type uses an array with 'id' field.
|
|
39
|
-
const normalized = normalizeRaw(raw);
|
|
40
|
-
const result = types_1.CrewxProjectConfigSchema.safeParse(normalized);
|
|
41
|
-
if (!result.success) {
|
|
42
|
-
throw new ConfigLoadError(`Config validation error: ${result.error.message}`);
|
|
43
|
-
}
|
|
44
|
-
return result.data;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Load and parse crewx.yaml from a file path.
|
|
48
|
-
*/
|
|
49
|
-
function loadYamlFile(filePath) {
|
|
50
|
-
let content;
|
|
51
|
-
try {
|
|
52
|
-
content = (0, fs_1.readFileSync)(filePath, 'utf-8');
|
|
53
|
-
}
|
|
54
|
-
catch (err) {
|
|
55
|
-
throw new ConfigLoadError(`Cannot read file: ${filePath}`, err);
|
|
56
|
-
}
|
|
57
|
-
return parseYamlContent(content);
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Normalize raw YAML output:
|
|
61
|
-
* - agents map (Record<id, agentConfig>) → agents array ([{ id, ...agentConfig }])
|
|
62
|
-
*/
|
|
63
|
-
function normalizeRaw(raw) {
|
|
64
|
-
if (!raw || typeof raw !== 'object') {
|
|
65
|
-
return { agents: [] };
|
|
66
|
-
}
|
|
67
|
-
const obj = raw;
|
|
68
|
-
// Gather agents as array (support map form and array form)
|
|
69
|
-
let agentsArray;
|
|
70
|
-
if (obj.agents && typeof obj.agents === 'object' && !Array.isArray(obj.agents)) {
|
|
71
|
-
const agentsMap = obj.agents;
|
|
72
|
-
agentsArray = Object.entries(agentsMap).map(([id, cfg]) => {
|
|
73
|
-
const agentCfg = (cfg && typeof cfg === 'object' ? cfg : {});
|
|
74
|
-
return { id, ...agentCfg };
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
else if (Array.isArray(obj.agents)) {
|
|
78
|
-
agentsArray = obj.agents;
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
return { ...obj, agents: [] };
|
|
82
|
-
}
|
|
83
|
-
// Normalize inline.provider → top-level provider (fallback for cross-repo yaml compat)
|
|
84
|
-
const normalizedAgents = agentsArray.map(agent => {
|
|
85
|
-
if (agent.provider === undefined && agent.inline && typeof agent.inline === 'object') {
|
|
86
|
-
const inline = agent.inline;
|
|
87
|
-
if (inline.provider !== undefined) {
|
|
88
|
-
return { ...agent, provider: inline.provider };
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return agent;
|
|
92
|
-
});
|
|
93
|
-
return { ...obj, agents: normalizedAgents };
|
|
94
|
-
}
|
|
95
|
-
//# sourceMappingURL=loader.js.map
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.toTemplateMessages = exports.toTaskReader = exports.SqliteConversationProvider = void 0;
|
|
18
|
-
__exportStar(require("./types.js"), exports);
|
|
19
|
-
var sqlite_provider_js_1 = require("./sqlite-provider.js");
|
|
20
|
-
Object.defineProperty(exports, "SqliteConversationProvider", { enumerable: true, get: function () { return sqlite_provider_js_1.SqliteConversationProvider; } });
|
|
21
|
-
var to_task_reader_js_1 = require("./to-task-reader.js");
|
|
22
|
-
Object.defineProperty(exports, "toTaskReader", { enumerable: true, get: function () { return to_task_reader_js_1.toTaskReader; } });
|
|
23
|
-
var to_template_messages_js_1 = require("./to-template-messages.js");
|
|
24
|
-
Object.defineProperty(exports, "toTemplateMessages", { enumerable: true, get: function () { return to_template_messages_js_1.toTemplateMessages; } });
|
|
25
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* SqliteConversationProvider — reads/writes conversation history from ~/.crewx/crewx.db.
|
|
4
|
-
*
|
|
5
|
-
* Security:
|
|
6
|
-
* - SEC-1: SELECT columns are explicitly whitelisted (no rendered_prompt, command, logs, metadata).
|
|
7
|
-
* - SEC-2: All queries use parameterized bindings (? placeholders).
|
|
8
|
-
* - Writes target `threads` table ONLY — `tasks` table writes are owned by SqliteTracingPlugin.
|
|
9
|
-
*/
|
|
10
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
11
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.SqliteConversationProvider = void 0;
|
|
15
|
-
const better_sqlite3_1 = __importDefault(require("better-sqlite3"));
|
|
16
|
-
const path_1 = require("path");
|
|
17
|
-
const os_1 = require("os");
|
|
18
|
-
const THREADS_DDL = `
|
|
19
|
-
CREATE TABLE IF NOT EXISTS threads (
|
|
20
|
-
id TEXT PRIMARY KEY,
|
|
21
|
-
workspace_id TEXT,
|
|
22
|
-
platform TEXT NOT NULL DEFAULT 'cli',
|
|
23
|
-
title TEXT,
|
|
24
|
-
first_message TEXT,
|
|
25
|
-
last_message TEXT,
|
|
26
|
-
message_count INTEGER NOT NULL DEFAULT 0,
|
|
27
|
-
created_at TEXT NOT NULL,
|
|
28
|
-
updated_at TEXT NOT NULL,
|
|
29
|
-
metadata TEXT
|
|
30
|
-
)
|
|
31
|
-
`;
|
|
32
|
-
const COLUMNS = [
|
|
33
|
-
'id', 'thread_id', 'prompt', 'result', 'started_at',
|
|
34
|
-
'trace_id', 'status', 'parent_task_id', 'agent_id',
|
|
35
|
-
];
|
|
36
|
-
function stripCliNoise(content) {
|
|
37
|
-
let cleaned = content.replace(/<conversation_history[^>]*>[\s\S]*?<\/conversation_history>/g, '');
|
|
38
|
-
const lines = cleaned.split('\n');
|
|
39
|
-
const cleanLines = lines.filter(line => {
|
|
40
|
-
if (line.startsWith('Loaded ') && line.includes('layouts from'))
|
|
41
|
-
return false;
|
|
42
|
-
if (line.includes('[dotenv@'))
|
|
43
|
-
return false;
|
|
44
|
-
if (line.includes('[Nest]') && line.includes('DEBUG'))
|
|
45
|
-
return false;
|
|
46
|
-
if (line.startsWith('Registered custom layout:'))
|
|
47
|
-
return false;
|
|
48
|
-
if (line.startsWith('Updated custom layout:'))
|
|
49
|
-
return false;
|
|
50
|
-
return true;
|
|
51
|
-
});
|
|
52
|
-
return cleanLines.join('\n').trim();
|
|
53
|
-
}
|
|
54
|
-
function cleanResult(raw) {
|
|
55
|
-
if (!raw)
|
|
56
|
-
return '';
|
|
57
|
-
let content = raw;
|
|
58
|
-
try {
|
|
59
|
-
const parsed = JSON.parse(content);
|
|
60
|
-
if (Array.isArray(parsed)) {
|
|
61
|
-
content = parsed
|
|
62
|
-
.filter((c) => c?.type === 'text' && c?.text)
|
|
63
|
-
.map((c) => c.text)
|
|
64
|
-
.join('\n');
|
|
65
|
-
}
|
|
66
|
-
else if (parsed && typeof parsed === 'object' && parsed.result !== undefined) {
|
|
67
|
-
content = parsed.result || '';
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
catch {
|
|
71
|
-
content = stripCliNoise(content);
|
|
72
|
-
}
|
|
73
|
-
return content;
|
|
74
|
-
}
|
|
75
|
-
class SqliteConversationProvider {
|
|
76
|
-
db;
|
|
77
|
-
constructor(dbPath) {
|
|
78
|
-
const resolved = dbPath ?? (0, path_1.join)((0, os_1.homedir)(), '.crewx', 'crewx.db');
|
|
79
|
-
this.db = new better_sqlite3_1.default(resolved);
|
|
80
|
-
this.init();
|
|
81
|
-
}
|
|
82
|
-
init() {
|
|
83
|
-
this.db.pragma('journal_mode = WAL');
|
|
84
|
-
this.db.exec(THREADS_DDL);
|
|
85
|
-
}
|
|
86
|
-
async ensureThread(threadId, platform, workspaceId) {
|
|
87
|
-
const row = this.db.prepare('SELECT platform FROM threads WHERE id = ?').get(threadId);
|
|
88
|
-
if (row) {
|
|
89
|
-
if (row.platform !== platform) {
|
|
90
|
-
throw new Error(`Thread '${threadId}' already exists with platform '${row.platform}' — cannot change to '${platform}' (platform is immutable)`);
|
|
91
|
-
}
|
|
92
|
-
// Backfill workspace_id if missing on existing thread (WI-CONV-003)
|
|
93
|
-
if (workspaceId) {
|
|
94
|
-
this.db.prepare('UPDATE threads SET workspace_id = COALESCE(workspace_id, ?) WHERE id = ?').run(workspaceId, threadId);
|
|
95
|
-
}
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
const now = new Date().toISOString();
|
|
99
|
-
this.db.prepare('INSERT INTO threads (id, platform, workspace_id, message_count, created_at, updated_at) VALUES (?, ?, ?, 0, ?, ?)').run(threadId, platform, workspaceId ?? null, now, now);
|
|
100
|
-
}
|
|
101
|
-
async fetchHistory(threadId, options) {
|
|
102
|
-
const limit = options?.limit ?? 100;
|
|
103
|
-
const conditions = [
|
|
104
|
-
'thread_id = ?',
|
|
105
|
-
'(parent_task_id IS NULL OR parent_task_id = \'\')',
|
|
106
|
-
'(status IN (\'done\', \'completed\', \'success\') OR status IS NULL)',
|
|
107
|
-
];
|
|
108
|
-
const params = [threadId];
|
|
109
|
-
if (options?.currentTraceId) {
|
|
110
|
-
conditions.push('trace_id != ?');
|
|
111
|
-
params.push(options.currentTraceId);
|
|
112
|
-
}
|
|
113
|
-
const where = conditions.join(' AND ');
|
|
114
|
-
const selectCols = COLUMNS.join(', ');
|
|
115
|
-
const sql = `SELECT ${selectCols} FROM tasks WHERE ${where} ORDER BY started_at ASC LIMIT ?`;
|
|
116
|
-
params.push(limit);
|
|
117
|
-
const rows = this.db.prepare(sql).all(...params);
|
|
118
|
-
const threadRow = this.db.prepare('SELECT platform, title, first_message, last_message, message_count, updated_at FROM threads WHERE id = ?').get(threadId);
|
|
119
|
-
const platform = threadRow?.platform ?? 'cli';
|
|
120
|
-
const messages = this.rowsToMessages(rows);
|
|
121
|
-
return {
|
|
122
|
-
threadId,
|
|
123
|
-
platform: platform,
|
|
124
|
-
messages,
|
|
125
|
-
metadata: {
|
|
126
|
-
title: threadRow?.title ?? undefined,
|
|
127
|
-
firstMessage: threadRow?.first_message ?? undefined,
|
|
128
|
-
lastMessage: threadRow?.last_message ?? undefined,
|
|
129
|
-
messageCount: threadRow?.message_count ?? 0,
|
|
130
|
-
updatedAt: threadRow?.updated_at ? new Date(threadRow.updated_at).getTime() : undefined,
|
|
131
|
-
},
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
async saveUserMessage(threadId, text, _userId, _metadata) {
|
|
135
|
-
const now = new Date().toISOString();
|
|
136
|
-
this.db.prepare(`UPDATE threads
|
|
137
|
-
SET first_message = COALESCE(first_message, ?),
|
|
138
|
-
last_message = ?,
|
|
139
|
-
message_count = message_count + 1,
|
|
140
|
-
updated_at = ?
|
|
141
|
-
WHERE id = ?`).run(text, text, now, threadId);
|
|
142
|
-
}
|
|
143
|
-
async saveAssistantMessage(threadId, text, _agentId, _metadata) {
|
|
144
|
-
const now = new Date().toISOString();
|
|
145
|
-
this.db.prepare(`UPDATE threads
|
|
146
|
-
SET last_message = ?,
|
|
147
|
-
updated_at = ?
|
|
148
|
-
WHERE id = ?`).run(text, now, threadId);
|
|
149
|
-
}
|
|
150
|
-
close() {
|
|
151
|
-
this.db.close();
|
|
152
|
-
}
|
|
153
|
-
rowsToMessages(rows) {
|
|
154
|
-
const messages = [];
|
|
155
|
-
for (const row of rows) {
|
|
156
|
-
if (row.prompt) {
|
|
157
|
-
messages.push({
|
|
158
|
-
id: `${row.id}-user`,
|
|
159
|
-
text: row.prompt,
|
|
160
|
-
isAssistant: false,
|
|
161
|
-
timestamp: new Date(row.started_at).getTime(),
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
const cleaned = cleanResult(row.result);
|
|
165
|
-
if (cleaned) {
|
|
166
|
-
messages.push({
|
|
167
|
-
id: `${row.id}-assistant`,
|
|
168
|
-
text: cleaned,
|
|
169
|
-
isAssistant: true,
|
|
170
|
-
timestamp: new Date(row.started_at).getTime(),
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
return messages;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
exports.SqliteConversationProvider = SqliteConversationProvider;
|
|
178
|
-
//# sourceMappingURL=sqlite-provider.js.map
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* toTaskReader — adapter from ConversationThread to boxing ITaskReader.
|
|
4
|
-
*
|
|
5
|
-
* SQ3 invariant:
|
|
6
|
-
* The returned ThreadMessage[] is structured as [user, assistant, user, assistant, ...]
|
|
7
|
-
* where each task produces exactly 2 consecutive elements (user first, then assistant).
|
|
8
|
-
* context-builder.ts:31~42 pairs messages as [i, i+1], so violating this invariant
|
|
9
|
-
* would corrupt context. Tasks without assistants (failed/running) are already
|
|
10
|
-
* filtered by fetchHistory — this adapter performs no additional filtering.
|
|
11
|
-
*/
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.toTaskReader = toTaskReader;
|
|
14
|
-
function toTaskReader(thread) {
|
|
15
|
-
const messages = thread.messages.map((msg) => ({
|
|
16
|
-
id: msg.id,
|
|
17
|
-
role: msg.isAssistant ? 'assistant' : 'user',
|
|
18
|
-
content: msg.text,
|
|
19
|
-
timestamp: new Date(msg.timestamp).toISOString(),
|
|
20
|
-
metadata: msg.metadata ?? null,
|
|
21
|
-
}));
|
|
22
|
-
return {
|
|
23
|
-
getThreadMessages(_threadId) {
|
|
24
|
-
return messages;
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
//# sourceMappingURL=to-task-reader.js.map
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* toTemplateMessages — maps ConversationThread messages to TemplateMessage[]
|
|
4
|
-
* for consumption by the formatConversation block helper.
|
|
5
|
-
*
|
|
6
|
-
* Includes SEC-M1 sanitization at the provider boundary:
|
|
7
|
-
* <, > are entity-escaped to prevent XML structure tag injection in the
|
|
8
|
-
* <conversation_history> block.
|
|
9
|
-
*/
|
|
10
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.toTemplateMessages = toTemplateMessages;
|
|
12
|
-
/**
|
|
13
|
-
* SEC-M1: sanitize message text to prevent conversation_history XML block pollution.
|
|
14
|
-
* User input containing </conversation_history> or <system_prompt> could be
|
|
15
|
-
* misinterpreted by the LLM as breaking out of the structured block.
|
|
16
|
-
*/
|
|
17
|
-
function sanitizeMessageText(text) {
|
|
18
|
-
if (typeof text !== 'string')
|
|
19
|
-
return '';
|
|
20
|
-
return text.replace(/</g, '<').replace(/>/g, '>');
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Convert a ConversationThread to a TemplateMessage array suitable for
|
|
24
|
-
* formatConversation block helper consumption.
|
|
25
|
-
*/
|
|
26
|
-
function toTemplateMessages(thread) {
|
|
27
|
-
return thread.messages.map(m => ({
|
|
28
|
-
text: sanitizeMessageText(m.text),
|
|
29
|
-
isAssistant: m.isAssistant,
|
|
30
|
-
metadata: m.metadata,
|
|
31
|
-
files: undefined,
|
|
32
|
-
}));
|
|
33
|
-
}
|
|
34
|
-
//# sourceMappingURL=to-template-messages.js.map
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Conversation history types — SDK public API for reading/writing thread history.
|
|
4
|
-
*
|
|
5
|
-
* **Security (SEC-3):** history content is untrusted user input.
|
|
6
|
-
* Consumers (e.g. Phase 2 CLI wiring) MUST delimit history from system prompts
|
|
7
|
-
* using structured blocks (e.g. `[HISTORY START]...[HISTORY END]`).
|
|
8
|
-
*/
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
//# sourceMappingURL=types.js.map
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Agent resolver: looks up an agent from a list by ref.
|
|
3
|
-
* Supports both bare id ('claude') and @mention format ('@claude').
|
|
4
|
-
* Falls back to built-in provider shorthands (claude, gemini, copilot, codex).
|
|
5
|
-
*/
|
|
6
|
-
export class AgentNotFoundError extends Error {
|
|
7
|
-
constructor(agentRef, availableIds) {
|
|
8
|
-
const available = availableIds.length > 0
|
|
9
|
-
? ` Available: ${availableIds.join(', ')}`
|
|
10
|
-
: '';
|
|
11
|
-
super(`Agent not found: "${agentRef}".${available}`);
|
|
12
|
-
this.name = 'AgentNotFoundError';
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
/** Built-in provider shorthands that can be used without a crewx.yaml entry. */
|
|
16
|
-
const BUILTIN_PROVIDERS = {
|
|
17
|
-
claude: { id: 'claude', provider: 'cli/claude' },
|
|
18
|
-
gemini: { id: 'gemini', provider: 'cli/gemini' },
|
|
19
|
-
copilot: { id: 'copilot', provider: 'cli/copilot' },
|
|
20
|
-
codex: { id: 'codex', provider: 'cli/codex' },
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* Resolve an agent by reference.
|
|
24
|
-
* @param agentRef - Agent reference: '@claude', 'claude', '@my_agent', etc.
|
|
25
|
-
* @param agents - List of available agent configs.
|
|
26
|
-
* @returns The matching AgentConfig.
|
|
27
|
-
* @throws AgentNotFoundError when no match is found.
|
|
28
|
-
*/
|
|
29
|
-
export function resolveAgent(agentRef, agents) {
|
|
30
|
-
const agentId = agentRef.startsWith('@') ? agentRef.slice(1) : agentRef;
|
|
31
|
-
// 1. Look in YAML-defined agents first
|
|
32
|
-
const agent = agents.find(a => a.id === agentId);
|
|
33
|
-
if (agent)
|
|
34
|
-
return agent;
|
|
35
|
-
// 2. Fall back to built-in provider shorthands
|
|
36
|
-
const builtin = BUILTIN_PROVIDERS[agentId];
|
|
37
|
-
if (builtin)
|
|
38
|
-
return builtin;
|
|
39
|
-
throw new AgentNotFoundError(agentRef, agents.map(a => a.id));
|
|
40
|
-
}
|
|
41
|
-
//# sourceMappingURL=resolver.js.map
|