@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,301 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* PropsValidator — React PropTypes style props validation.
|
|
4
|
-
* Ported 1:1 from packages/sdk-bak/src/services/props-validator.service.ts.
|
|
5
|
-
* Only the import path is changed.
|
|
6
|
-
*/
|
|
7
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.PropsValidator = void 0;
|
|
9
|
-
const types_1 = require("./types");
|
|
10
|
-
class PropsValidator {
|
|
11
|
-
defaultMode;
|
|
12
|
-
constructor(options = {}) {
|
|
13
|
-
this.defaultMode = options.defaultMode ?? 'lenient';
|
|
14
|
-
}
|
|
15
|
-
validate(props, schema, mode = this.defaultMode) {
|
|
16
|
-
const errors = [];
|
|
17
|
-
const resolvedProps = this.validateObject(props ?? {}, schema, mode, ['props'], errors);
|
|
18
|
-
if (errors.length > 0 && mode === 'strict') {
|
|
19
|
-
throw new types_1.PropsValidationError('Props validation failed in strict mode', errors);
|
|
20
|
-
}
|
|
21
|
-
return {
|
|
22
|
-
valid: errors.length === 0,
|
|
23
|
-
props: resolvedProps,
|
|
24
|
-
errors,
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
validateObject(provided, schema, mode, pathSegments, errors) {
|
|
28
|
-
const sanitized = {};
|
|
29
|
-
if (mode === 'strict') {
|
|
30
|
-
for (const key of Object.keys(provided)) {
|
|
31
|
-
if (!schema[key]) {
|
|
32
|
-
errors.push({
|
|
33
|
-
path: this.buildPath([...pathSegments, key]),
|
|
34
|
-
message: `Unknown prop '${key}'`,
|
|
35
|
-
value: provided[key],
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
for (const [key, propSchema] of Object.entries(schema)) {
|
|
41
|
-
const fullPath = [...pathSegments, key];
|
|
42
|
-
const rawValue = provided[key];
|
|
43
|
-
const result = this.resolveProp(rawValue, propSchema, fullPath, mode, errors);
|
|
44
|
-
if (result.shouldAssign) {
|
|
45
|
-
sanitized[key] = result.value;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return sanitized;
|
|
49
|
-
}
|
|
50
|
-
resolveProp(value, schema, pathSegments, mode, errors) {
|
|
51
|
-
const path = this.buildPath(pathSegments);
|
|
52
|
-
if (this.isNil(value)) {
|
|
53
|
-
if (schema.isRequired) {
|
|
54
|
-
errors.push({
|
|
55
|
-
path,
|
|
56
|
-
message: `Required prop '${pathSegments[pathSegments.length - 1]}' is missing`,
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
if (schema.defaultValue !== undefined) {
|
|
60
|
-
return { shouldAssign: true, value: this.cloneValue(schema.defaultValue) };
|
|
61
|
-
}
|
|
62
|
-
if (schema.type === 'shape' && schema.shape) {
|
|
63
|
-
const nestedDefaults = this.applyDefaults(schema.shape);
|
|
64
|
-
if (Object.keys(nestedDefaults).length > 0) {
|
|
65
|
-
return { shouldAssign: true, value: nestedDefaults };
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return { shouldAssign: false };
|
|
69
|
-
}
|
|
70
|
-
const typeResult = this.validateType(value, schema, pathSegments, mode, errors);
|
|
71
|
-
if (!typeResult.valid) {
|
|
72
|
-
if (schema.type === 'shape' &&
|
|
73
|
-
typeResult.value &&
|
|
74
|
-
this.isPlainObject(typeResult.value)) {
|
|
75
|
-
return { shouldAssign: true, value: typeResult.value };
|
|
76
|
-
}
|
|
77
|
-
errors.push({ path, message: typeResult.error ?? 'Invalid value', value });
|
|
78
|
-
if (schema.defaultValue !== undefined) {
|
|
79
|
-
return { shouldAssign: true, value: this.cloneValue(schema.defaultValue) };
|
|
80
|
-
}
|
|
81
|
-
if (schema.type === 'shape' && schema.shape) {
|
|
82
|
-
const nestedDefaults = this.applyDefaults(schema.shape);
|
|
83
|
-
if (Object.keys(nestedDefaults).length > 0) {
|
|
84
|
-
return { shouldAssign: true, value: nestedDefaults };
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return { shouldAssign: false };
|
|
88
|
-
}
|
|
89
|
-
return { shouldAssign: true, value: typeResult.value };
|
|
90
|
-
}
|
|
91
|
-
validateType(value, schema, pathSegments, mode, errors) {
|
|
92
|
-
const { type } = schema;
|
|
93
|
-
switch (type) {
|
|
94
|
-
case 'string':
|
|
95
|
-
return this.validateString(value, schema);
|
|
96
|
-
case 'number':
|
|
97
|
-
return this.validateNumber(value, schema);
|
|
98
|
-
case 'bool':
|
|
99
|
-
return this.validateBoolean(value);
|
|
100
|
-
case 'array':
|
|
101
|
-
return this.validateArray(value, schema);
|
|
102
|
-
case 'arrayOf':
|
|
103
|
-
return this.validateArrayOf(value, schema, pathSegments, mode, errors);
|
|
104
|
-
case 'object':
|
|
105
|
-
return this.validatePlainObject(value);
|
|
106
|
-
case 'shape':
|
|
107
|
-
return this.validateShape(value, schema, pathSegments, mode, errors);
|
|
108
|
-
case 'oneOfType':
|
|
109
|
-
return this.validateOneOfType(value, schema);
|
|
110
|
-
case 'func':
|
|
111
|
-
return this.validateFunction(value);
|
|
112
|
-
case 'node':
|
|
113
|
-
return { valid: true, value };
|
|
114
|
-
default:
|
|
115
|
-
return { valid: true, value };
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
validateString(value, schema) {
|
|
119
|
-
if (typeof value !== 'string') {
|
|
120
|
-
return { valid: false, error: `Expected string, got ${this.describeType(value)}` };
|
|
121
|
-
}
|
|
122
|
-
if (schema.oneOf && !schema.oneOf.includes(value)) {
|
|
123
|
-
return { valid: false, error: `Expected one of: ${schema.oneOf.join(', ')}` };
|
|
124
|
-
}
|
|
125
|
-
if (schema.minLength !== undefined && value.length < schema.minLength) {
|
|
126
|
-
return { valid: false, error: `String length must be >= ${schema.minLength}` };
|
|
127
|
-
}
|
|
128
|
-
if (schema.maxLength !== undefined && value.length > schema.maxLength) {
|
|
129
|
-
return { valid: false, error: `String length must be <= ${schema.maxLength}` };
|
|
130
|
-
}
|
|
131
|
-
if (schema.pattern) {
|
|
132
|
-
const pattern = new RegExp(schema.pattern);
|
|
133
|
-
if (!pattern.test(value)) {
|
|
134
|
-
return { valid: false, error: `String does not match pattern ${schema.pattern}` };
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
return { valid: true, value };
|
|
138
|
-
}
|
|
139
|
-
validateNumber(value, schema) {
|
|
140
|
-
if (typeof value !== 'number' || Number.isNaN(value)) {
|
|
141
|
-
return { valid: false, error: `Expected number, got ${this.describeType(value)}` };
|
|
142
|
-
}
|
|
143
|
-
if (schema.min !== undefined && value < schema.min) {
|
|
144
|
-
return { valid: false, error: `Number must be >= ${schema.min}` };
|
|
145
|
-
}
|
|
146
|
-
if (schema.max !== undefined && value > schema.max) {
|
|
147
|
-
return { valid: false, error: `Number must be <= ${schema.max}` };
|
|
148
|
-
}
|
|
149
|
-
if (schema.oneOf && !schema.oneOf.includes(value)) {
|
|
150
|
-
return { valid: false, error: `Expected one of: ${schema.oneOf.join(', ')}` };
|
|
151
|
-
}
|
|
152
|
-
return { valid: true, value };
|
|
153
|
-
}
|
|
154
|
-
validateBoolean(value) {
|
|
155
|
-
if (typeof value !== 'boolean') {
|
|
156
|
-
return { valid: false, error: `Expected boolean, got ${this.describeType(value)}` };
|
|
157
|
-
}
|
|
158
|
-
return { valid: true, value };
|
|
159
|
-
}
|
|
160
|
-
validateArray(value, schema) {
|
|
161
|
-
if (!Array.isArray(value)) {
|
|
162
|
-
return { valid: false, error: `Expected array, got ${this.describeType(value)}` };
|
|
163
|
-
}
|
|
164
|
-
if (schema.minLength !== undefined && value.length < schema.minLength) {
|
|
165
|
-
return { valid: false, error: `Array length must be >= ${schema.minLength}` };
|
|
166
|
-
}
|
|
167
|
-
if (schema.maxLength !== undefined && value.length > schema.maxLength) {
|
|
168
|
-
return { valid: false, error: `Array length must be <= ${schema.maxLength}` };
|
|
169
|
-
}
|
|
170
|
-
return { valid: true, value: [...value] };
|
|
171
|
-
}
|
|
172
|
-
validateArrayOf(value, schema, pathSegments, mode, errors) {
|
|
173
|
-
const base = this.validateArray(value, schema);
|
|
174
|
-
if (!base.valid)
|
|
175
|
-
return base;
|
|
176
|
-
const itemValues = [];
|
|
177
|
-
const itemType = schema.itemType;
|
|
178
|
-
const itemOneOf = schema.itemOneOf;
|
|
179
|
-
const beforeErrors = errors.length;
|
|
180
|
-
base.value.forEach((item, index) => {
|
|
181
|
-
const itemPath = [...pathSegments, String(index)];
|
|
182
|
-
if (itemType) {
|
|
183
|
-
const result = this.validateType(item, { type: itemType }, itemPath, mode, errors);
|
|
184
|
-
if (!result.valid) {
|
|
185
|
-
errors.push({
|
|
186
|
-
path: this.buildPath(itemPath),
|
|
187
|
-
message: result.error ?? 'Invalid array item',
|
|
188
|
-
value: item,
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
else {
|
|
192
|
-
itemValues.push(result.value);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
else {
|
|
196
|
-
itemValues.push(item);
|
|
197
|
-
}
|
|
198
|
-
if (itemOneOf && !itemOneOf.includes(item)) {
|
|
199
|
-
errors.push({
|
|
200
|
-
path: this.buildPath(itemPath),
|
|
201
|
-
message: `Array item must be one of: ${itemOneOf.join(', ')}`,
|
|
202
|
-
value: item,
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
});
|
|
206
|
-
return { valid: errors.length === beforeErrors, value: itemValues };
|
|
207
|
-
}
|
|
208
|
-
validatePlainObject(value) {
|
|
209
|
-
if (!this.isPlainObject(value)) {
|
|
210
|
-
return { valid: false, error: `Expected object, got ${this.describeType(value)}` };
|
|
211
|
-
}
|
|
212
|
-
return { valid: true, value: { ...value } };
|
|
213
|
-
}
|
|
214
|
-
validateFunction(value) {
|
|
215
|
-
if (typeof value !== 'function') {
|
|
216
|
-
return { valid: false, error: `Expected function, got ${this.describeType(value)}` };
|
|
217
|
-
}
|
|
218
|
-
return { valid: true, value };
|
|
219
|
-
}
|
|
220
|
-
validateShape(value, schema, pathSegments, mode, errors) {
|
|
221
|
-
if (!this.isPlainObject(value)) {
|
|
222
|
-
return { valid: false, error: `Expected object, got ${this.describeType(value)}` };
|
|
223
|
-
}
|
|
224
|
-
const beforeErrors = errors.length;
|
|
225
|
-
const nested = this.validateObject(value, schema.shape ?? {}, mode, pathSegments, errors);
|
|
226
|
-
return { valid: errors.length === beforeErrors, value: nested };
|
|
227
|
-
}
|
|
228
|
-
validateOneOfType(value, schema) {
|
|
229
|
-
const types = schema.types ?? [];
|
|
230
|
-
const matches = types.some(typeName => this.matchesType(value, typeName));
|
|
231
|
-
if (!matches) {
|
|
232
|
-
return {
|
|
233
|
-
valid: false,
|
|
234
|
-
error: `Value does not match any allowed type: ${types.join(', ')}`,
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
return { valid: true, value };
|
|
238
|
-
}
|
|
239
|
-
matchesType(value, typeName) {
|
|
240
|
-
switch (typeName) {
|
|
241
|
-
case 'string': return typeof value === 'string';
|
|
242
|
-
case 'number': return typeof value === 'number' && !Number.isNaN(value);
|
|
243
|
-
case 'bool':
|
|
244
|
-
case 'boolean': return typeof value === 'boolean';
|
|
245
|
-
case 'array': return Array.isArray(value);
|
|
246
|
-
case 'object': return this.isPlainObject(value);
|
|
247
|
-
case 'func':
|
|
248
|
-
case 'function': return typeof value === 'function';
|
|
249
|
-
case 'shape': return this.isPlainObject(value);
|
|
250
|
-
case 'node': return value === null || value === undefined || typeof value !== 'symbol';
|
|
251
|
-
default: return true;
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
applyDefaults(schema) {
|
|
255
|
-
const defaults = {};
|
|
256
|
-
for (const [key, propSchema] of Object.entries(schema)) {
|
|
257
|
-
if (propSchema.defaultValue !== undefined) {
|
|
258
|
-
defaults[key] = this.cloneValue(propSchema.defaultValue);
|
|
259
|
-
continue;
|
|
260
|
-
}
|
|
261
|
-
if (propSchema.type === 'shape' && propSchema.shape) {
|
|
262
|
-
const nestedDefaults = this.applyDefaults(propSchema.shape);
|
|
263
|
-
if (Object.keys(nestedDefaults).length > 0) {
|
|
264
|
-
defaults[key] = nestedDefaults;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
return defaults;
|
|
269
|
-
}
|
|
270
|
-
cloneValue(value) {
|
|
271
|
-
if (Array.isArray(value)) {
|
|
272
|
-
return value.map(item => this.cloneValue(item));
|
|
273
|
-
}
|
|
274
|
-
if (this.isPlainObject(value)) {
|
|
275
|
-
const cloned = {};
|
|
276
|
-
for (const [key, nested] of Object.entries(value)) {
|
|
277
|
-
cloned[key] = this.cloneValue(nested);
|
|
278
|
-
}
|
|
279
|
-
return cloned;
|
|
280
|
-
}
|
|
281
|
-
return value;
|
|
282
|
-
}
|
|
283
|
-
isPlainObject(value) {
|
|
284
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
285
|
-
}
|
|
286
|
-
isNil(value) {
|
|
287
|
-
return value === null || value === undefined;
|
|
288
|
-
}
|
|
289
|
-
buildPath(segments) {
|
|
290
|
-
return segments.join('.');
|
|
291
|
-
}
|
|
292
|
-
describeType(value) {
|
|
293
|
-
if (Array.isArray(value))
|
|
294
|
-
return 'array';
|
|
295
|
-
if (value === null)
|
|
296
|
-
return 'null';
|
|
297
|
-
return typeof value;
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
exports.PropsValidator = PropsValidator;
|
|
301
|
-
//# sourceMappingURL=props-validator.js.map
|
package/dist/layout/renderer.js
DELETED
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* LayoutRenderer — Handlebars-based layout rendering.
|
|
4
|
-
* Ported from packages/sdk-bak/src/services/layout-renderer.service.ts.
|
|
5
|
-
* Excluded: registerTemplateHelpers (exec/shell-quote).
|
|
6
|
-
* Exec is handled separately by TemplateEngine in the facade layer.
|
|
7
|
-
* WI-CONV-002: formatConversation helper restored.
|
|
8
|
-
*/
|
|
9
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.LayoutRenderer = exports.PropsValidationError = void 0;
|
|
14
|
-
const handlebars_1 = __importDefault(require("handlebars"));
|
|
15
|
-
const format_conversation_1 = require("../template/helpers/format-conversation");
|
|
16
|
-
const props_validator_1 = require("./props-validator");
|
|
17
|
-
const types_1 = require("./types");
|
|
18
|
-
var types_2 = require("./types");
|
|
19
|
-
Object.defineProperty(exports, "PropsValidationError", { enumerable: true, get: function () { return types_2.PropsValidationError; } });
|
|
20
|
-
/**
|
|
21
|
-
* LayoutRenderer — renders layout templates with Handlebars.
|
|
22
|
-
*/
|
|
23
|
-
class LayoutRenderer {
|
|
24
|
-
handlebars;
|
|
25
|
-
propsValidator;
|
|
26
|
-
constructor(propsValidator) {
|
|
27
|
-
this.handlebars = handlebars_1.default.create();
|
|
28
|
-
this.propsValidator = propsValidator ?? new props_validator_1.PropsValidator();
|
|
29
|
-
this.registerHelpers();
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Render a layout template with the given context.
|
|
33
|
-
*/
|
|
34
|
-
render(layout, context, options = {}) {
|
|
35
|
-
try {
|
|
36
|
-
const preparedContext = this.prepareRenderContext(layout, context, options);
|
|
37
|
-
const template = this.handlebars.compile(layout.template, { noEscape: true });
|
|
38
|
-
return template(preparedContext);
|
|
39
|
-
}
|
|
40
|
-
catch (error) {
|
|
41
|
-
if (error instanceof Error) {
|
|
42
|
-
throw new Error(`Template rendering failed for layout '${layout.id}': ${error.message}`);
|
|
43
|
-
}
|
|
44
|
-
throw new Error(`Unknown error rendering layout '${layout.id}'`);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Validate props against schema.
|
|
49
|
-
*/
|
|
50
|
-
validate(props, propsSchema, mode = 'lenient') {
|
|
51
|
-
return this.executeValidation(props, propsSchema, mode);
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Merge default props and runtime props, then validate.
|
|
55
|
-
*/
|
|
56
|
-
resolveProps(layout, props, mode = 'lenient') {
|
|
57
|
-
const mergedProps = this.mergeProps(layout.defaultProps, props);
|
|
58
|
-
if (!layout.propsSchema || Object.keys(layout.propsSchema).length === 0) {
|
|
59
|
-
return { valid: true, props: mergedProps, errors: [] };
|
|
60
|
-
}
|
|
61
|
-
return this.executeValidation(mergedProps, layout.propsSchema, mode);
|
|
62
|
-
}
|
|
63
|
-
prepareRenderContext(layout, context, options) {
|
|
64
|
-
const { validationMode = 'lenient', skipValidation = false } = options;
|
|
65
|
-
const resolvedProps = skipValidation
|
|
66
|
-
? this.mergeProps(layout.defaultProps, context.props)
|
|
67
|
-
: this.resolveProps(layout, context.props, validationMode).props;
|
|
68
|
-
return {
|
|
69
|
-
...context,
|
|
70
|
-
vars: this.sanitizeVars(context.vars),
|
|
71
|
-
props: resolvedProps,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Register built-in Handlebars helpers (no exec).
|
|
76
|
-
* WI-CONV-002: formatConversation block helper registered for conversation history.
|
|
77
|
-
*/
|
|
78
|
-
registerHelpers() {
|
|
79
|
-
// Conversation history block helper (WI-CONV-002)
|
|
80
|
-
this.handlebars.registerHelper('formatConversation', format_conversation_1.formatConversationHelper);
|
|
81
|
-
// Built-in block helpers
|
|
82
|
-
if (handlebars_1.default.helpers.each) {
|
|
83
|
-
this.handlebars.registerHelper('each', handlebars_1.default.helpers.each);
|
|
84
|
-
}
|
|
85
|
-
if (handlebars_1.default.helpers.if) {
|
|
86
|
-
this.handlebars.registerHelper('if', handlebars_1.default.helpers.if);
|
|
87
|
-
}
|
|
88
|
-
if (handlebars_1.default.helpers.unless) {
|
|
89
|
-
this.handlebars.registerHelper('unless', handlebars_1.default.helpers.unless);
|
|
90
|
-
}
|
|
91
|
-
if (handlebars_1.default.helpers.with) {
|
|
92
|
-
this.handlebars.registerHelper('with', handlebars_1.default.helpers.with);
|
|
93
|
-
}
|
|
94
|
-
this.handlebars.registerHelper('eq', function (a, b) {
|
|
95
|
-
return a === b;
|
|
96
|
-
});
|
|
97
|
-
this.handlebars.registerHelper('ne', function (a, b) {
|
|
98
|
-
return a !== b;
|
|
99
|
-
});
|
|
100
|
-
this.handlebars.registerHelper('gt', function (a, b) {
|
|
101
|
-
return a > b;
|
|
102
|
-
});
|
|
103
|
-
this.handlebars.registerHelper('lt', function (a, b) {
|
|
104
|
-
return a < b;
|
|
105
|
-
});
|
|
106
|
-
this.handlebars.registerHelper('json', function (obj) {
|
|
107
|
-
return new handlebars_1.default.SafeString(JSON.stringify(obj));
|
|
108
|
-
});
|
|
109
|
-
this.handlebars.registerHelper('raw', function (options) {
|
|
110
|
-
return typeof options?.fn === 'function' ? options.fn(this) : '';
|
|
111
|
-
});
|
|
112
|
-
this.handlebars.registerHelper('escapeHandlebars', function (text) {
|
|
113
|
-
if (typeof text !== 'string')
|
|
114
|
-
return '';
|
|
115
|
-
return text.replace(/\{\{/g, '{{').replace(/\}\}/g, '}}');
|
|
116
|
-
});
|
|
117
|
-
this.handlebars.registerHelper('formatFileSize', function (bytes) {
|
|
118
|
-
if (bytes === 0)
|
|
119
|
-
return '0 B';
|
|
120
|
-
const sizes = ['B', 'KB', 'MB', 'GB'];
|
|
121
|
-
const i = Math.floor(Math.log(bytes) / Math.log(1024));
|
|
122
|
-
return Math.round((bytes / Math.pow(1024, i)) * 100) / 100 + ' ' + sizes[i];
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
executeValidation(props, propsSchema, mode) {
|
|
126
|
-
try {
|
|
127
|
-
return this.propsValidator.validate(props, propsSchema, mode);
|
|
128
|
-
}
|
|
129
|
-
catch (error) {
|
|
130
|
-
if (error instanceof types_1.PropsValidationError && error.errors && error.errors.length > 0) {
|
|
131
|
-
const firstError = error.errors[0];
|
|
132
|
-
if (firstError) {
|
|
133
|
-
throw new types_1.PropsValidationError(firstError.message, error.errors);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
throw error;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
mergeProps(defaultProps, overrides) {
|
|
140
|
-
const base = this.cloneDeep(defaultProps ?? {});
|
|
141
|
-
if (!overrides)
|
|
142
|
-
return base;
|
|
143
|
-
return this.deepMerge(base, overrides);
|
|
144
|
-
}
|
|
145
|
-
deepMerge(target, source) {
|
|
146
|
-
for (const [key, value] of Object.entries(source)) {
|
|
147
|
-
if (this.isPlainObject(value)) {
|
|
148
|
-
const existing = target[key];
|
|
149
|
-
target[key] = this.deepMerge(this.isPlainObject(existing) ? existing : {}, value);
|
|
150
|
-
continue;
|
|
151
|
-
}
|
|
152
|
-
if (Array.isArray(value)) {
|
|
153
|
-
target[key] = this.cloneDeep(value);
|
|
154
|
-
continue;
|
|
155
|
-
}
|
|
156
|
-
target[key] = value;
|
|
157
|
-
}
|
|
158
|
-
return target;
|
|
159
|
-
}
|
|
160
|
-
cloneDeep(value) {
|
|
161
|
-
if (Array.isArray(value)) {
|
|
162
|
-
return value.map(item => this.cloneDeep(item));
|
|
163
|
-
}
|
|
164
|
-
if (this.isPlainObject(value)) {
|
|
165
|
-
const cloned = {};
|
|
166
|
-
for (const [key, nested] of Object.entries(value)) {
|
|
167
|
-
cloned[key] = this.cloneDeep(nested);
|
|
168
|
-
}
|
|
169
|
-
return cloned;
|
|
170
|
-
}
|
|
171
|
-
return value;
|
|
172
|
-
}
|
|
173
|
-
isPlainObject(value) {
|
|
174
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
175
|
-
}
|
|
176
|
-
sanitizeVars(vars) {
|
|
177
|
-
if (!vars)
|
|
178
|
-
return {};
|
|
179
|
-
const sanitizedVars = { ...vars };
|
|
180
|
-
if (typeof vars.user_input === 'string') {
|
|
181
|
-
sanitizedVars.user_input_raw = vars.user_input;
|
|
182
|
-
const escapedHandlebars = vars.user_input
|
|
183
|
-
.replace(/\{\{\{/g, '{{{')
|
|
184
|
-
.replace(/\}\}\}/g, '}}}')
|
|
185
|
-
.replace(/\{\{/g, '{{')
|
|
186
|
-
.replace(/\}\}/g, '}}');
|
|
187
|
-
sanitizedVars.user_input = this.handlebars.escapeExpression(escapedHandlebars);
|
|
188
|
-
}
|
|
189
|
-
return sanitizedVars;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
exports.LayoutRenderer = LayoutRenderer;
|
|
193
|
-
//# sourceMappingURL=renderer.js.map
|
package/dist/layout/types.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Layout system type definitions for CrewX SDK.
|
|
4
|
-
* Ported from packages/sdk-bak/src/types/layout.types.ts (1:1, import path only changed).
|
|
5
|
-
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.PropsValidationError = exports.LayoutLoadError = void 0;
|
|
8
|
-
/**
|
|
9
|
-
* Error thrown when layout loading fails.
|
|
10
|
-
*/
|
|
11
|
-
class LayoutLoadError extends Error {
|
|
12
|
-
layoutId;
|
|
13
|
-
cause;
|
|
14
|
-
constructor(message, layoutId, cause) {
|
|
15
|
-
super(message);
|
|
16
|
-
this.layoutId = layoutId;
|
|
17
|
-
this.cause = cause;
|
|
18
|
-
this.name = 'LayoutLoadError';
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
exports.LayoutLoadError = LayoutLoadError;
|
|
22
|
-
/**
|
|
23
|
-
* Error thrown when props validation fails (strict mode).
|
|
24
|
-
*/
|
|
25
|
-
class PropsValidationError extends Error {
|
|
26
|
-
errors;
|
|
27
|
-
cause;
|
|
28
|
-
constructor(message, errors = [], cause) {
|
|
29
|
-
super(message);
|
|
30
|
-
this.errors = errors;
|
|
31
|
-
this.cause = cause;
|
|
32
|
-
this.name = 'PropsValidationError';
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
exports.PropsValidationError = PropsValidationError;
|
|
36
|
-
//# sourceMappingURL=types.js.map
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Minimal AgentRuntime for the parallel execution module.
|
|
4
|
-
* Provides query/execute methods to run agent operations.
|
|
5
|
-
* Tests use vi.spyOn(AgentRuntime.prototype, 'query') to mock these methods.
|
|
6
|
-
*/
|
|
7
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.AgentRuntime = void 0;
|
|
9
|
-
/**
|
|
10
|
-
* Runtime that executes agent query/execute operations.
|
|
11
|
-
* Default implementation throws — callers must inject a working provider
|
|
12
|
-
* or mock the prototype methods in tests.
|
|
13
|
-
*/
|
|
14
|
-
class AgentRuntime {
|
|
15
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
16
|
-
async query(_request) {
|
|
17
|
-
throw new Error('AgentRuntime.query is not implemented. Provide a subclass or mock AgentRuntime.prototype.query.');
|
|
18
|
-
}
|
|
19
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
20
|
-
async execute(_request) {
|
|
21
|
-
throw new Error('AgentRuntime.execute is not implemented. Provide a subclass or mock AgentRuntime.prototype.execute.');
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
exports.AgentRuntime = AgentRuntime;
|
|
25
|
-
//# sourceMappingURL=agent-runtime.js.map
|