@sowonai/crewx-sdk 0.1.0-dev.4 → 0.1.0-dev.6

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.
@@ -0,0 +1,332 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PropsValidator = void 0;
4
+ const layout_types_1 = require("../types/layout.types");
5
+ class PropsValidator {
6
+ constructor(options = {}) {
7
+ this.defaultMode = options.defaultMode ?? 'lenient';
8
+ }
9
+ validate(props, schema, mode = this.defaultMode) {
10
+ const errors = [];
11
+ const resolvedProps = this.validateObject(props ?? {}, schema, mode, ['props'], errors);
12
+ if (errors.length > 0 && mode === 'strict') {
13
+ throw new layout_types_1.PropsValidationError('Props validation failed in strict mode', errors);
14
+ }
15
+ return {
16
+ valid: errors.length === 0,
17
+ props: resolvedProps,
18
+ errors,
19
+ };
20
+ }
21
+ validateObject(provided, schema, mode, pathSegments, errors) {
22
+ const sanitized = {};
23
+ if (mode === 'strict') {
24
+ for (const key of Object.keys(provided)) {
25
+ if (!schema[key]) {
26
+ errors.push({
27
+ path: this.buildPath([...pathSegments, key]),
28
+ message: `Unknown prop '${key}'`,
29
+ value: provided[key],
30
+ });
31
+ }
32
+ }
33
+ }
34
+ for (const [key, propSchema] of Object.entries(schema)) {
35
+ const fullPath = [...pathSegments, key];
36
+ const rawValue = provided[key];
37
+ const result = this.resolveProp(rawValue, propSchema, fullPath, mode, errors);
38
+ if (result.shouldAssign) {
39
+ sanitized[key] = result.value;
40
+ }
41
+ }
42
+ if (mode === 'lenient') {
43
+ }
44
+ else if (mode === 'strict') {
45
+ }
46
+ return sanitized;
47
+ }
48
+ resolveProp(value, schema, pathSegments, mode, errors) {
49
+ const path = this.buildPath(pathSegments);
50
+ if (this.isNil(value)) {
51
+ if (schema.isRequired) {
52
+ errors.push({
53
+ path,
54
+ message: `Required prop '${pathSegments[pathSegments.length - 1]}' is missing`,
55
+ });
56
+ }
57
+ if (schema.defaultValue !== undefined) {
58
+ return { shouldAssign: true, value: this.cloneValue(schema.defaultValue) };
59
+ }
60
+ if (schema.type === 'shape' && schema.shape) {
61
+ const nestedDefaults = this.applyDefaults(schema.shape);
62
+ if (Object.keys(nestedDefaults).length > 0) {
63
+ return { shouldAssign: true, value: nestedDefaults };
64
+ }
65
+ }
66
+ return { shouldAssign: false };
67
+ }
68
+ const typeResult = this.validateType(value, schema, pathSegments, mode, errors);
69
+ if (!typeResult.valid) {
70
+ if (schema.type === 'shape' &&
71
+ typeResult.value &&
72
+ this.isPlainObject(typeResult.value)) {
73
+ return { shouldAssign: true, value: typeResult.value };
74
+ }
75
+ errors.push({ path, message: typeResult.error ?? 'Invalid value', value });
76
+ if (schema.defaultValue !== undefined) {
77
+ return { shouldAssign: true, value: this.cloneValue(schema.defaultValue) };
78
+ }
79
+ if (schema.type === 'shape' && schema.shape) {
80
+ const nestedDefaults = this.applyDefaults(schema.shape);
81
+ if (Object.keys(nestedDefaults).length > 0) {
82
+ return { shouldAssign: true, value: nestedDefaults };
83
+ }
84
+ }
85
+ return { shouldAssign: false };
86
+ }
87
+ return { shouldAssign: true, value: typeResult.value };
88
+ }
89
+ validateType(value, schema, pathSegments, mode, errors) {
90
+ const { type } = schema;
91
+ switch (type) {
92
+ case 'string':
93
+ return this.validateString(value, schema);
94
+ case 'number':
95
+ return this.validateNumber(value, schema);
96
+ case 'bool':
97
+ return this.validateBoolean(value);
98
+ case 'array':
99
+ return this.validateArray(value, schema);
100
+ case 'arrayOf':
101
+ return this.validateArrayOf(value, schema, pathSegments, mode, errors);
102
+ case 'object':
103
+ return this.validatePlainObject(value);
104
+ case 'shape':
105
+ return this.validateShape(value, schema, pathSegments, mode, errors);
106
+ case 'oneOfType':
107
+ return this.validateOneOfType(value, schema);
108
+ case 'func':
109
+ return this.validateFunction(value);
110
+ case 'node':
111
+ return { valid: true, value };
112
+ default:
113
+ return { valid: true, value };
114
+ }
115
+ }
116
+ validateString(value, schema) {
117
+ if (typeof value !== 'string') {
118
+ return { valid: false, error: `Expected string, got ${this.describeType(value)}` };
119
+ }
120
+ if (schema.oneOf && !schema.oneOf.includes(value)) {
121
+ return {
122
+ valid: false,
123
+ error: `Expected one of: ${schema.oneOf.join(', ')}`,
124
+ };
125
+ }
126
+ if (schema.minLength !== undefined && value.length < schema.minLength) {
127
+ return {
128
+ valid: false,
129
+ error: `String length must be >= ${schema.minLength}`,
130
+ };
131
+ }
132
+ if (schema.maxLength !== undefined && value.length > schema.maxLength) {
133
+ return {
134
+ valid: false,
135
+ error: `String length must be <= ${schema.maxLength}`,
136
+ };
137
+ }
138
+ if (schema.pattern) {
139
+ const pattern = new RegExp(schema.pattern);
140
+ if (!pattern.test(value)) {
141
+ return {
142
+ valid: false,
143
+ error: `String does not match pattern ${schema.pattern}`,
144
+ };
145
+ }
146
+ }
147
+ return { valid: true, value };
148
+ }
149
+ validateNumber(value, schema) {
150
+ if (typeof value !== 'number' || Number.isNaN(value)) {
151
+ return { valid: false, error: `Expected number, got ${this.describeType(value)}` };
152
+ }
153
+ if (schema.min !== undefined && value < schema.min) {
154
+ return { valid: false, error: `Number must be >= ${schema.min}` };
155
+ }
156
+ if (schema.max !== undefined && value > schema.max) {
157
+ return { valid: false, error: `Number must be <= ${schema.max}` };
158
+ }
159
+ if (schema.oneOf && !schema.oneOf.includes(value)) {
160
+ return {
161
+ valid: false,
162
+ error: `Expected one of: ${schema.oneOf.join(', ')}`,
163
+ };
164
+ }
165
+ return { valid: true, value };
166
+ }
167
+ validateBoolean(value) {
168
+ if (typeof value !== 'boolean') {
169
+ return { valid: false, error: `Expected boolean, got ${this.describeType(value)}` };
170
+ }
171
+ return { valid: true, value };
172
+ }
173
+ validateArray(value, schema) {
174
+ if (!Array.isArray(value)) {
175
+ return { valid: false, error: `Expected array, got ${this.describeType(value)}` };
176
+ }
177
+ if (schema.minLength !== undefined && value.length < schema.minLength) {
178
+ return {
179
+ valid: false,
180
+ error: `Array length must be >= ${schema.minLength}`,
181
+ };
182
+ }
183
+ if (schema.maxLength !== undefined && value.length > schema.maxLength) {
184
+ return {
185
+ valid: false,
186
+ error: `Array length must be <= ${schema.maxLength}`,
187
+ };
188
+ }
189
+ return { valid: true, value: [...value] };
190
+ }
191
+ validateArrayOf(value, schema, pathSegments, mode, errors) {
192
+ const base = this.validateArray(value, schema);
193
+ if (!base.valid) {
194
+ return base;
195
+ }
196
+ const itemValues = [];
197
+ const itemType = schema.itemType;
198
+ const itemOneOf = schema.itemOneOf;
199
+ const beforeErrors = errors.length;
200
+ base.value.forEach((item, index) => {
201
+ const itemPath = [...pathSegments, String(index)];
202
+ if (itemType) {
203
+ const result = this.validateType(item, { type: itemType }, itemPath, mode, errors);
204
+ if (!result.valid) {
205
+ errors.push({
206
+ path: this.buildPath(itemPath),
207
+ message: result.error ?? 'Invalid array item',
208
+ value: item,
209
+ });
210
+ }
211
+ else {
212
+ itemValues.push(result.value);
213
+ }
214
+ }
215
+ else {
216
+ itemValues.push(item);
217
+ }
218
+ if (itemOneOf && !itemOneOf.includes(item)) {
219
+ errors.push({
220
+ path: this.buildPath(itemPath),
221
+ message: `Array item must be one of: ${itemOneOf.join(', ')}`,
222
+ value: item,
223
+ });
224
+ }
225
+ });
226
+ return { valid: errors.length === beforeErrors, value: itemValues };
227
+ }
228
+ validatePlainObject(value) {
229
+ if (!this.isPlainObject(value)) {
230
+ return { valid: false, error: `Expected object, got ${this.describeType(value)}` };
231
+ }
232
+ return { valid: true, value: { ...value } };
233
+ }
234
+ validateFunction(value) {
235
+ if (typeof value !== 'function') {
236
+ return { valid: false, error: `Expected function, got ${this.describeType(value)}` };
237
+ }
238
+ return { valid: true, value };
239
+ }
240
+ validateShape(value, schema, pathSegments, mode, errors) {
241
+ if (!this.isPlainObject(value)) {
242
+ return { valid: false, error: `Expected object, got ${this.describeType(value)}` };
243
+ }
244
+ const beforeErrors = errors.length;
245
+ const nested = this.validateObject(value, schema.shape ?? {}, mode, pathSegments, errors);
246
+ return { valid: errors.length === beforeErrors, value: nested };
247
+ }
248
+ validateOneOfType(value, schema) {
249
+ const types = schema.types ?? [];
250
+ const matches = types.some(typeName => this.matchesType(value, typeName));
251
+ if (!matches) {
252
+ return {
253
+ valid: false,
254
+ error: `Value does not match any allowed type: ${types.join(', ')}`,
255
+ };
256
+ }
257
+ return { valid: true, value };
258
+ }
259
+ matchesType(value, typeName) {
260
+ switch (typeName) {
261
+ case 'string':
262
+ return typeof value === 'string';
263
+ case 'number':
264
+ return typeof value === 'number' && !Number.isNaN(value);
265
+ case 'bool':
266
+ case 'boolean':
267
+ return typeof value === 'boolean';
268
+ case 'array':
269
+ return Array.isArray(value);
270
+ case 'object':
271
+ return this.isPlainObject(value);
272
+ case 'func':
273
+ case 'function':
274
+ return typeof value === 'function';
275
+ case 'shape':
276
+ return this.isPlainObject(value);
277
+ case 'node':
278
+ return value === null || value === undefined || typeof value !== 'symbol';
279
+ default:
280
+ return true;
281
+ }
282
+ }
283
+ applyDefaults(schema) {
284
+ const defaults = {};
285
+ for (const [key, propSchema] of Object.entries(schema)) {
286
+ if (propSchema.defaultValue !== undefined) {
287
+ defaults[key] = this.cloneValue(propSchema.defaultValue);
288
+ continue;
289
+ }
290
+ if (propSchema.type === 'shape' && propSchema.shape) {
291
+ const nestedDefaults = this.applyDefaults(propSchema.shape);
292
+ if (Object.keys(nestedDefaults).length > 0) {
293
+ defaults[key] = nestedDefaults;
294
+ }
295
+ }
296
+ }
297
+ return defaults;
298
+ }
299
+ cloneValue(value) {
300
+ if (Array.isArray(value)) {
301
+ return value.map(item => this.cloneValue(item));
302
+ }
303
+ if (this.isPlainObject(value)) {
304
+ const cloned = {};
305
+ for (const [key, nested] of Object.entries(value)) {
306
+ cloned[key] = this.cloneValue(nested);
307
+ }
308
+ return cloned;
309
+ }
310
+ return value;
311
+ }
312
+ isPlainObject(value) {
313
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
314
+ }
315
+ isNil(value) {
316
+ return value === null || value === undefined;
317
+ }
318
+ buildPath(segments) {
319
+ return segments.join('.');
320
+ }
321
+ describeType(value) {
322
+ if (Array.isArray(value)) {
323
+ return 'array';
324
+ }
325
+ if (value === null) {
326
+ return 'null';
327
+ }
328
+ return typeof value;
329
+ }
330
+ }
331
+ exports.PropsValidator = PropsValidator;
332
+ //# sourceMappingURL=props-validator.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"props-validator.service.js","sourceRoot":"","sources":["../../src/services/props-validator.service.ts"],"names":[],"mappings":";;;AAAA,wDAK+B;AAc/B,MAAa,cAAc;IAGzB,YAAY,UAAiC,EAAE;QAC7C,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,SAAS,CAAC;IACtD,CAAC;IAED,QAAQ,CACN,KAAsC,EACtC,MAAkC,EAClC,OAAuB,IAAI,CAAC,WAAW;QAEvC,MAAM,MAAM,GAAsB,EAAE,CAAC;QACrC,MAAM,aAAa,GAAG,IAAI,CAAC,cAAc,CACvC,KAAK,IAAI,EAAE,EACX,MAAM,EACN,IAAI,EACJ,CAAC,OAAO,CAAC,EACT,MAAM,CACP,CAAC;QAEF,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC3C,MAAM,IAAI,mCAAoB,CAAC,wCAAwC,EAAE,MAAM,CAAC,CAAC;QACnF,CAAC;QAED,OAAO;YACL,KAAK,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC;YAC1B,KAAK,EAAE,aAAa;YACpB,MAAM;SACP,CAAC;IACJ,CAAC;IAEO,cAAc,CACpB,QAA6B,EAC7B,MAAkC,EAClC,IAAoB,EACpB,YAAsB,EACtB,MAAyB;QAEzB,MAAM,SAAS,GAAwB,EAAE,CAAC;QAG1C,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;YACtB,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;gBACxC,IAAI,CAAC,MAAM,CAAC,GAAG,C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AAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAiB,CAAC;QAClE,CAAC;QAED,IAAI,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;YAC9B,MAAM,MAAM,GAAwB,EAAE,CAAC;YACvC,KAAK,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAA4B,CAAC,EAAE,CAAC;gBACzE,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;YACxC,CAAC;YACD,OAAO,MAAW,CAAC;QACrB,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAEO,aAAa,CAAC,KAAU;QAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC9E,CAAC;IAEO,KAAK,CAAC,KAAU;QACtB,OAAO,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,CAAC;IAC/C,CAAC;IAEO,SAAS,CAAC,QAAkB;QAClC,OAAO,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC5B,CAAC;IAEO,YAAY,CAAC,KAAU;QAC7B,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,OAAO,OAAO,CAAC;QACjB,CAAC;QAED,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YACnB,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,OAAO,OAAO,KAAK,CAAC;IACtB,CAAC;CACF;AAhcD,wCAgcC"}
@@ -110,8 +110,13 @@ export interface AgentInfo {
110
110
  inline?: {
111
111
  type: 'agent';
112
112
  provider: 'claude' | 'gemini' | 'copilot';
113
- system_prompt: string;
113
+ system_prompt?: string;
114
+ prompt?: string;
114
115
  model?: string;
116
+ layout?: string | {
117
+ id: string;
118
+ props?: Record<string, any>;
119
+ };
115
120
  };
116
121
  remote?: RemoteAgentInfo;
117
122
  }
@@ -0,0 +1,77 @@
1
+ export interface PropSchema {
2
+ type: 'string' | 'number' | 'bool' | 'array' | 'arrayOf' | 'object' | 'shape' | 'oneOfType' | 'func' | 'node';
3
+ isRequired?: boolean;
4
+ defaultValue?: any;
5
+ oneOf?: any[];
6
+ min?: number;
7
+ max?: number;
8
+ minLength?: number;
9
+ maxLength?: number;
10
+ itemType?: string;
11
+ itemOneOf?: any[];
12
+ shape?: Record<string, PropSchema>;
13
+ types?: string[];
14
+ pattern?: string;
15
+ description?: string;
16
+ }
17
+ export interface LayoutDefinition {
18
+ id: string;
19
+ version: string;
20
+ description: string;
21
+ template: string;
22
+ propsSchema: Record<string, PropSchema>;
23
+ defaultProps: Record<string, any>;
24
+ }
25
+ export type InlineLayoutSpec = string | {
26
+ id: string;
27
+ props?: Record<string, any>;
28
+ };
29
+ export interface ValidationResult {
30
+ valid: boolean;
31
+ props: Record<string, any>;
32
+ errors: ValidationError[];
33
+ }
34
+ export interface ValidationError {
35
+ path: string;
36
+ message: string;
37
+ value?: any;
38
+ }
39
+ export interface LoaderOptions {
40
+ templatesPath: string;
41
+ validationMode?: 'strict' | 'lenient';
42
+ fallbackLayoutId?: string;
43
+ }
44
+ export interface RenderContext {
45
+ agent: {
46
+ id: string;
47
+ name: string;
48
+ inline: {
49
+ prompt: string;
50
+ };
51
+ };
52
+ documents: Record<string, {
53
+ content: string;
54
+ toc?: string;
55
+ summary?: string;
56
+ }>;
57
+ vars: Record<string, any>;
58
+ props: Record<string, any>;
59
+ }
60
+ export interface RawLayoutYaml {
61
+ id?: string;
62
+ version?: string;
63
+ description?: string;
64
+ propsSchema?: Record<string, any>;
65
+ template?: string;
66
+ layouts?: Record<string, string>;
67
+ }
68
+ export declare class LayoutLoadError extends Error {
69
+ readonly layoutId?: string | undefined;
70
+ readonly cause?: Error | undefined;
71
+ constructor(message: string, layoutId?: string | undefined, cause?: Error | undefined);
72
+ }
73
+ export declare class PropsValidationError extends Error {
74
+ readonly errors: ValidationError[];
75
+ readonly cause?: Error | undefined;
76
+ constructor(message: string, errors?: ValidationError[], cause?: Error | undefined);
77
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PropsValidationError = exports.LayoutLoadError = void 0;
4
+ class LayoutLoadError extends Error {
5
+ constructor(message, layoutId, cause) {
6
+ super(message);
7
+ this.layoutId = layoutId;
8
+ this.cause = cause;
9
+ this.name = 'LayoutLoadError';
10
+ }
11
+ }
12
+ exports.LayoutLoadError = LayoutLoadError;
13
+ class PropsValidationError extends Error {
14
+ constructor(message, errors = [], cause) {
15
+ super(message);
16
+ this.errors = errors;
17
+ this.cause = cause;
18
+ this.name = 'PropsValidationError';
19
+ }
20
+ }
21
+ exports.PropsValidationError = PropsValidationError;
22
+ //# sourceMappingURL=layout.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layout.types.js","sourceRoot":"","sources":["../../src/types/layout.types.ts"],"names":[],"mappings":";;;AAqHA,MAAa,eAAgB,SAAQ,KAAK;IACxC,YAAY,OAAe,EAAkB,QAAiB,EAAkB,KAAa;QAC3F,KAAK,CAAC,OAAO,CAAC,CAAC;QAD4B,aAAQ,GAAR,QAAQ,CAAS;QAAkB,UAAK,GAAL,KAAK,CAAQ;QAE3F,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AALD,0CAKC;AAKD,MAAa,oBAAqB,SAAQ,KAAK;IAC7C,YACE,OAAe,EACC,SAA4B,EAAE,EAC9B,KAAa;QAE7B,KAAK,CAAC,OAAO,CAAC,CAAC;QAHC,WAAM,GAAN,MAAM,CAAwB;QAC9B,UAAK,GAAL,KAAK,CAAQ;QAG7B,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACrC,CAAC;CACF;AATD,oDASC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sowonai/crewx-sdk",
3
- "version": "0.1.0-dev.4",
3
+ "version": "0.1.0-dev.6",
4
4
  "license": "Apache-2.0",
5
5
  "description": "SowonAI CrewX SDK",
6
6
  "type": "commonjs",