lua-cli 3.5.0-alpha.4 → 3.5.0-alpha.5
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/api/http.client.js +5 -1
- package/dist/api/http.client.js.map +1 -1
- package/dist/commands/compile.d.ts +0 -1
- package/dist/commands/compile.js +14 -10
- package/dist/commands/compile.js.map +1 -1
- package/dist/commands/integrations.js +1 -1
- package/dist/commands/integrations.js.map +1 -1
- package/dist/commands/push.js +25 -6
- package/dist/commands/push.js.map +1 -1
- package/dist/commands/sync.js +9 -5
- package/dist/commands/sync.js.map +1 -1
- package/dist/compiler/agent-traverser.js +1 -1
- package/dist/compiler/agent-traverser.js.map +1 -1
- package/dist/compiler/bundler.d.ts +1 -1
- package/dist/compiler/bundler.js +2 -1
- package/dist/compiler/bundler.js.map +1 -1
- package/dist/compiler/compiler.js +3 -2
- package/dist/compiler/compiler.js.map +1 -1
- package/dist/compiler/plugins/base.d.ts +21 -1
- package/dist/compiler/plugins/base.js +37 -1
- package/dist/compiler/plugins/base.js.map +1 -1
- package/dist/compiler/plugins/job.plugin.js +15 -62
- package/dist/compiler/plugins/job.plugin.js.map +1 -1
- package/dist/compiler/plugins/mcp-server.plugin.js +15 -44
- package/dist/compiler/plugins/mcp-server.plugin.js.map +1 -1
- package/dist/compiler/plugins/postprocessor.plugin.js +1 -10
- package/dist/compiler/plugins/postprocessor.plugin.js.map +1 -1
- package/dist/compiler/plugins/preprocessor.plugin.js +4 -17
- package/dist/compiler/plugins/preprocessor.plugin.js.map +1 -1
- package/dist/compiler/plugins/processor-base.js +2 -9
- package/dist/compiler/plugins/processor-base.js.map +1 -1
- package/dist/compiler/plugins/skill.plugin.js +5 -23
- package/dist/compiler/plugins/skill.plugin.js.map +1 -1
- package/dist/compiler/plugins/tool.plugin.d.ts +1 -0
- package/dist/compiler/plugins/tool.plugin.js +9 -30
- package/dist/compiler/plugins/tool.plugin.js.map +1 -1
- package/dist/compiler/plugins/webhook.plugin.js +3 -18
- package/dist/compiler/plugins/webhook.plugin.js.map +1 -1
- package/dist/compiler/types.d.ts +5 -0
- package/dist/compiler/types.js +7 -0
- package/dist/compiler/types.js.map +1 -1
- package/dist/compiler/utils/ast-helpers.d.ts +13 -1
- package/dist/compiler/utils/ast-helpers.js +62 -42
- package/dist/compiler/utils/ast-helpers.js.map +1 -1
- package/dist/primitives/base.handler.d.ts +45 -6
- package/dist/primitives/base.handler.js +121 -17
- package/dist/primitives/base.handler.js.map +1 -1
- package/dist/primitives/index.d.ts +4 -5
- package/dist/primitives/index.js +7 -17
- package/dist/primitives/index.js.map +1 -1
- package/dist/primitives/job.handler.d.ts +0 -5
- package/dist/primitives/job.handler.js +1 -15
- package/dist/primitives/job.handler.js.map +1 -1
- package/dist/primitives/mcp-server.handler.d.ts +1 -1
- package/dist/primitives/mcp-server.handler.js +15 -6
- package/dist/primitives/mcp-server.handler.js.map +1 -1
- package/dist/primitives/postprocessor.handler.d.ts +0 -11
- package/dist/primitives/postprocessor.handler.js +1 -24
- package/dist/primitives/postprocessor.handler.js.map +1 -1
- package/dist/primitives/preprocessor.handler.d.ts +0 -11
- package/dist/primitives/preprocessor.handler.js +1 -24
- package/dist/primitives/preprocessor.handler.js.map +1 -1
- package/dist/primitives/skill.handler.d.ts +3 -1
- package/dist/primitives/skill.handler.js +10 -29
- package/dist/primitives/skill.handler.js.map +1 -1
- package/dist/primitives/types.d.ts +18 -0
- package/dist/primitives/types.js.map +1 -1
- package/dist/primitives/webhook.handler.d.ts +0 -5
- package/dist/primitives/webhook.handler.js +1 -15
- package/dist/primitives/webhook.handler.js.map +1 -1
- package/dist/utils/cli.js +3 -3
- package/dist/utils/cli.js.map +1 -1
- package/dist/utils/command-utils.d.ts +12 -10
- package/dist/utils/command-utils.js +19 -17
- package/dist/utils/command-utils.js.map +1 -1
- package/dist/utils/files.d.ts +10 -0
- package/dist/utils/files.js +34 -0
- package/dist/utils/files.js.map +1 -1
- package/dist/web/app.css +186 -912
- package/dist/web/app.js +46 -46
- package/docs/README.md +3 -3
- package/package.json +1 -1
- package/template/package.json +1 -1
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
* 2. Function-based (new): const myWebhook = defineWebhook({ ... })
|
|
7
7
|
*/
|
|
8
8
|
import { Node } from 'ts-morph';
|
|
9
|
-
import { PrimitiveKind, } from '../types.js';
|
|
10
9
|
import { BasePlugin, validationError, validationWarning } from './base.js';
|
|
11
10
|
import { extractSchemaProperty } from '../utils/ast-helpers.js';
|
|
12
11
|
import { zodToJsonSchema } from '../utils/schema-converter.js';
|
|
@@ -42,18 +41,10 @@ export class WebhookPlugin extends BasePlugin {
|
|
|
42
41
|
};
|
|
43
42
|
}
|
|
44
43
|
validate(metadata) {
|
|
45
|
-
const errors =
|
|
46
|
-
const warnings = [];
|
|
47
|
-
if (!metadata.name) {
|
|
48
|
-
errors.push(validationError('Webhook must have a name', { line: metadata.line }));
|
|
49
|
-
}
|
|
44
|
+
const { errors, warnings } = this.baseValidation(metadata);
|
|
50
45
|
if (!metadata.metadata.hasExecute) {
|
|
51
46
|
errors.push(validationError('Webhook must have an execute function', { line: metadata.line }));
|
|
52
47
|
}
|
|
53
|
-
if (!metadata.description) {
|
|
54
|
-
warnings.push(validationWarning('Webhook should have a description', { line: metadata.line }));
|
|
55
|
-
}
|
|
56
|
-
// Validate name format (URL-safe)
|
|
57
48
|
if (metadata.name && !/^[a-z][a-z0-9-]*$/.test(metadata.name)) {
|
|
58
49
|
warnings.push(validationWarning('Webhook name should be URL-safe (lowercase, hyphens only)', { line: metadata.line }));
|
|
59
50
|
}
|
|
@@ -108,20 +99,14 @@ export class WebhookPlugin extends BasePlugin {
|
|
|
108
99
|
return Object.keys(schemas).length > 0 ? schemas : undefined;
|
|
109
100
|
}
|
|
110
101
|
toManifestEntry(compiled, _context) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
name: compiled.name,
|
|
114
|
-
description: compiled.description,
|
|
115
|
-
path: `artifacts/${compiled.kind}/${compiled.name}.js`,
|
|
116
|
-
sourcePath: compiled.sourcePath,
|
|
117
|
-
hash: compiled.artifact.hash,
|
|
102
|
+
return {
|
|
103
|
+
...this.baseManifestFields(compiled),
|
|
118
104
|
schemas: compiled.schemas ? {
|
|
119
105
|
query: compiled.schemas.query,
|
|
120
106
|
headers: compiled.schemas.headers,
|
|
121
107
|
body: compiled.schemas.body,
|
|
122
108
|
} : undefined,
|
|
123
109
|
};
|
|
124
|
-
return webhook;
|
|
125
110
|
}
|
|
126
111
|
}
|
|
127
112
|
//# sourceMappingURL=webhook.plugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webhook.plugin.js","sourceRoot":"","sources":["../../../src/compiler/plugins/webhook.plugin.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAW,IAAI,EAA2B,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"webhook.plugin.js","sourceRoot":"","sources":["../../../src/compiler/plugins/webhook.plugin.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAW,IAAI,EAA2B,MAAM,UAAU,CAAC;AAWlE,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC3E,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAE/D;;;GAGG;AACH,MAAM,OAAO,aAAc,SAAQ,UAAiC;IAApE;;QACW,SAAI,GAAG,SAAS,CAAC;QACjB,gBAAW,GAAG,SAAS,CAAC;QACxB,mBAAc,GAAG,eAAe,CAAC;QACjC,qBAAgB,GAAG,CAAC,YAAY,CAAC,CAAC;IA2G7C,CAAC;IAzGC;;OAEG;IACO,iBAAiB,CACzB,MAA+B,EAC/B,UAAkB,EAClB,UAAkB,EAClB,QAA0C,EAC1C,OAA6B;QAE7B,MAAM,MAAM,GAAG,IAAI,CAAC,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AM,eAAe,CAAC,UAAU,CAAC,CAAC;wBACrD,MAAM,GAAG,GAAG,QAAQ,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;wBAC3C,OAAO,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC;oBAC5B,CAAC;oBAAC,OAAO,KAAK,EAAE,CAAC;wBACf,OAAO,CAAC,IAAI,CAAC,8BAA8B,QAAQ,QAAQ,QAAQ,CAAC,IAAI,GAAG,EAAE,KAAK,CAAC,CAAC;oBACtF,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;IAC/D,CAAC;IAED,eAAe,CAAC,QAA2B,EAAE,QAA0B;QACrE,OAAO;YACL,GAAG,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC;YACpC,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;gBAC1B,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,KAAK;gBAC7B,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,OAAO;gBACjC,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,IAAI;aAC5B,CAAC,CAAC,CAAC,SAAS;SACK,CAAC;IACvB,CAAC;CACF"}
|
package/dist/compiler/types.d.ts
CHANGED
|
@@ -204,6 +204,10 @@ export interface ProjectFile {
|
|
|
204
204
|
size: number;
|
|
205
205
|
type: 'source' | 'config' | 'other';
|
|
206
206
|
}
|
|
207
|
+
/** Manifest format version. Referenced by entry points, manifests, and minimal manifests. */
|
|
208
|
+
export declare const COMPILER_VERSION = "2.0.0";
|
|
209
|
+
/** esbuild compilation target. Referenced by bundler and MCP resolver bundler. */
|
|
210
|
+
export declare const ESBUILD_TARGET = "node18";
|
|
207
211
|
export declare enum PrimitiveKind {
|
|
208
212
|
TOOL = "tool",
|
|
209
213
|
SKILL = "skill",
|
|
@@ -225,6 +229,7 @@ export interface ManifestTool extends ManifestPrimitiveBase {
|
|
|
225
229
|
input?: JSONSchema;
|
|
226
230
|
output?: JSONSchema;
|
|
227
231
|
};
|
|
232
|
+
hasCondition?: boolean;
|
|
228
233
|
}
|
|
229
234
|
export interface ManifestSkill extends ManifestPrimitiveBase {
|
|
230
235
|
kind: PrimitiveKind.SKILL;
|
package/dist/compiler/types.js
CHANGED
|
@@ -5,6 +5,13 @@
|
|
|
5
5
|
* Uses discriminated unions for type-safe primitive handling.
|
|
6
6
|
*/
|
|
7
7
|
// =============================================================================
|
|
8
|
+
// COMPILER CONSTANTS
|
|
9
|
+
// =============================================================================
|
|
10
|
+
/** Manifest format version. Referenced by entry points, manifests, and minimal manifests. */
|
|
11
|
+
export const COMPILER_VERSION = '2.0.0';
|
|
12
|
+
/** esbuild compilation target. Referenced by bundler and MCP resolver bundler. */
|
|
13
|
+
export const ESBUILD_TARGET = 'node18';
|
|
14
|
+
// =============================================================================
|
|
8
15
|
// MANIFEST PRIMITIVES
|
|
9
16
|
// =============================================================================
|
|
10
17
|
export var PrimitiveKind;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/compiler/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAgRH,gFAAgF;AAChF,sBAAsB;AACtB,gFAAgF;AAEhF,MAAM,CAAN,IAAY,aAQX;AARD,WAAY,aAAa;IACvB,8BAAa,CAAA;IACb,gCAAe,CAAA;IACf,4BAAW,CAAA;IACX,oCAAmB,CAAA;IACnB,8CAA6B,CAAA;IAC7B,gDAA+B,CAAA;IAC/B,0CAAyB,CAAA;AAC3B,CAAC,EARW,aAAa,KAAb,aAAa,QAQxB"}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/compiler/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAgRH,gFAAgF;AAChF,qBAAqB;AACrB,gFAAgF;AAEhF,6FAA6F;AAC7F,MAAM,CAAC,MAAM,gBAAgB,GAAG,OAAO,CAAC;AAExC,kFAAkF;AAClF,MAAM,CAAC,MAAM,cAAc,GAAG,QAAQ,CAAC;AAEvC,gFAAgF;AAChF,sBAAsB;AACtB,gFAAgF;AAEhF,MAAM,CAAN,IAAY,aAQX;AARD,WAAY,aAAa;IACvB,8BAAa,CAAA;IACb,gCAAe,CAAA;IACf,4BAAW,CAAA;IACX,oCAAmB,CAAA;IACnB,8CAA6B,CAAA;IAC7B,gDAA+B,CAAA;IAC/B,0CAAyB,CAAA;AAC3B,CAAC,EARW,aAAa,KAAb,aAAa,QAQxB"}
|
|
@@ -3,19 +3,31 @@
|
|
|
3
3
|
*
|
|
4
4
|
* These utilities make it easy to extract typed values from
|
|
5
5
|
* object literal expressions in TypeScript source code.
|
|
6
|
+
*
|
|
7
|
+
* Uses ts-evaluator for full expression evaluation — handles any expression
|
|
8
|
+
* that can be statically resolved (literals, concatenation, variables,
|
|
9
|
+
* imported constants, template literals, function calls, etc.).
|
|
6
10
|
*/
|
|
7
11
|
import { Node, ObjectLiteralExpression, SourceFile } from 'ts-morph';
|
|
12
|
+
/** Evaluate an AST node as a string. */
|
|
13
|
+
export declare function evaluateNodeAsString(node: Node | undefined): string | undefined;
|
|
14
|
+
/** Evaluate an AST node as a number. */
|
|
15
|
+
export declare function evaluateNodeAsNumber(node: Node | undefined): number | undefined;
|
|
16
|
+
/** Evaluate an AST node as a boolean. */
|
|
17
|
+
export declare function evaluateNodeAsBoolean(node: Node | undefined): boolean | undefined;
|
|
8
18
|
/**
|
|
9
19
|
* Extract a string value from an object property.
|
|
10
|
-
*
|
|
20
|
+
* Uses ts-evaluator for full expression evaluation.
|
|
11
21
|
*/
|
|
12
22
|
export declare function extractStringProperty(obj: ObjectLiteralExpression, propertyName: string): string | undefined;
|
|
13
23
|
/**
|
|
14
24
|
* Extract a boolean value from an object property.
|
|
25
|
+
* Uses ts-evaluator for full expression evaluation.
|
|
15
26
|
*/
|
|
16
27
|
export declare function extractBooleanProperty(obj: ObjectLiteralExpression, propertyName: string): boolean | undefined;
|
|
17
28
|
/**
|
|
18
29
|
* Extract a number value from an object property.
|
|
30
|
+
* Uses ts-evaluator for full expression evaluation.
|
|
19
31
|
*/
|
|
20
32
|
export declare function extractNumberProperty(obj: ObjectLiteralExpression, propertyName: string): number | undefined;
|
|
21
33
|
/**
|
|
@@ -3,11 +3,66 @@
|
|
|
3
3
|
*
|
|
4
4
|
* These utilities make it easy to extract typed values from
|
|
5
5
|
* object literal expressions in TypeScript source code.
|
|
6
|
+
*
|
|
7
|
+
* Uses ts-evaluator for full expression evaluation — handles any expression
|
|
8
|
+
* that can be statically resolved (literals, concatenation, variables,
|
|
9
|
+
* imported constants, template literals, function calls, etc.).
|
|
10
|
+
*/
|
|
11
|
+
import { Node } from 'ts-morph';
|
|
12
|
+
import ts from 'typescript';
|
|
13
|
+
import { evaluate } from 'ts-evaluator';
|
|
14
|
+
/**
|
|
15
|
+
* Evaluate any AST expression node using ts-evaluator.
|
|
16
|
+
* Handles ALL expression types: literals, concatenation, variables,
|
|
17
|
+
* imported constants, template literals, function calls, etc.
|
|
18
|
+
*
|
|
19
|
+
* Uses the same sandboxed evaluation approach as zodToJsonSchema() in schema-converter.ts.
|
|
6
20
|
*/
|
|
7
|
-
|
|
21
|
+
function evaluateNode(node) {
|
|
22
|
+
if (!node)
|
|
23
|
+
return undefined;
|
|
24
|
+
try {
|
|
25
|
+
const tsNode = node.compilerNode;
|
|
26
|
+
const typeChecker = node.getSourceFile().getProject().getTypeChecker().compilerObject;
|
|
27
|
+
const result = evaluate({
|
|
28
|
+
node: tsNode,
|
|
29
|
+
typeChecker,
|
|
30
|
+
typescript: ts,
|
|
31
|
+
environment: { preset: 'NODE' },
|
|
32
|
+
policy: {
|
|
33
|
+
deterministic: false,
|
|
34
|
+
network: false,
|
|
35
|
+
console: false,
|
|
36
|
+
io: { read: true, write: false },
|
|
37
|
+
process: { exit: false, spawnChild: false },
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
if (result.success)
|
|
41
|
+
return result.value;
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
// ts-evaluator failed — return undefined
|
|
45
|
+
}
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
/** Evaluate an AST node as a string. */
|
|
49
|
+
export function evaluateNodeAsString(node) {
|
|
50
|
+
const val = evaluateNode(node);
|
|
51
|
+
return typeof val === 'string' ? val : undefined;
|
|
52
|
+
}
|
|
53
|
+
/** Evaluate an AST node as a number. */
|
|
54
|
+
export function evaluateNodeAsNumber(node) {
|
|
55
|
+
const val = evaluateNode(node);
|
|
56
|
+
return typeof val === 'number' ? val : undefined;
|
|
57
|
+
}
|
|
58
|
+
/** Evaluate an AST node as a boolean. */
|
|
59
|
+
export function evaluateNodeAsBoolean(node) {
|
|
60
|
+
const val = evaluateNode(node);
|
|
61
|
+
return typeof val === 'boolean' ? val : undefined;
|
|
62
|
+
}
|
|
8
63
|
/**
|
|
9
64
|
* Extract a string value from an object property.
|
|
10
|
-
*
|
|
65
|
+
* Uses ts-evaluator for full expression evaluation.
|
|
11
66
|
*/
|
|
12
67
|
export function extractStringProperty(obj, propertyName) {
|
|
13
68
|
const prop = obj.getProperty(propertyName);
|
|
@@ -16,62 +71,27 @@ export function extractStringProperty(obj, propertyName) {
|
|
|
16
71
|
const value = prop.getInitializer();
|
|
17
72
|
if (!value)
|
|
18
73
|
return undefined;
|
|
19
|
-
|
|
20
|
-
if (Node.isStringLiteral(value)) {
|
|
21
|
-
return value.getLiteralValue();
|
|
22
|
-
}
|
|
23
|
-
// Template literal without expressions: `value`
|
|
24
|
-
if (Node.isNoSubstitutionTemplateLiteral(value)) {
|
|
25
|
-
return value.getLiteralValue();
|
|
26
|
-
}
|
|
27
|
-
// Template literal with expressions: `${x}` - return the full text
|
|
28
|
-
if (Node.isTemplateExpression(value)) {
|
|
29
|
-
// For complex templates, return the raw text minus backticks
|
|
30
|
-
const text = value.getText();
|
|
31
|
-
return text.slice(1, -1);
|
|
32
|
-
}
|
|
33
|
-
return undefined;
|
|
74
|
+
return evaluateNodeAsString(value);
|
|
34
75
|
}
|
|
35
76
|
/**
|
|
36
77
|
* Extract a boolean value from an object property.
|
|
78
|
+
* Uses ts-evaluator for full expression evaluation.
|
|
37
79
|
*/
|
|
38
80
|
export function extractBooleanProperty(obj, propertyName) {
|
|
39
81
|
const prop = obj.getProperty(propertyName);
|
|
40
82
|
if (!prop || !Node.isPropertyAssignment(prop))
|
|
41
83
|
return undefined;
|
|
42
|
-
|
|
43
|
-
if (!value)
|
|
44
|
-
return undefined;
|
|
45
|
-
const kind = value.getKind();
|
|
46
|
-
// TrueKeyword = 110, FalseKeyword = 95 in ts-morph
|
|
47
|
-
if (kind === SyntaxKind.TrueKeyword)
|
|
48
|
-
return true;
|
|
49
|
-
if (kind === SyntaxKind.FalseKeyword)
|
|
50
|
-
return false;
|
|
51
|
-
// Handle string "true" or "false"
|
|
52
|
-
if (Node.isStringLiteral(value)) {
|
|
53
|
-
const text = value.getLiteralValue();
|
|
54
|
-
if (text === 'true')
|
|
55
|
-
return true;
|
|
56
|
-
if (text === 'false')
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
return undefined;
|
|
84
|
+
return evaluateNodeAsBoolean(prop.getInitializer());
|
|
60
85
|
}
|
|
61
86
|
/**
|
|
62
87
|
* Extract a number value from an object property.
|
|
88
|
+
* Uses ts-evaluator for full expression evaluation.
|
|
63
89
|
*/
|
|
64
90
|
export function extractNumberProperty(obj, propertyName) {
|
|
65
91
|
const prop = obj.getProperty(propertyName);
|
|
66
92
|
if (!prop || !Node.isPropertyAssignment(prop))
|
|
67
93
|
return undefined;
|
|
68
|
-
|
|
69
|
-
if (!value)
|
|
70
|
-
return undefined;
|
|
71
|
-
if (Node.isNumericLiteral(value)) {
|
|
72
|
-
return value.getLiteralValue();
|
|
73
|
-
}
|
|
74
|
-
return undefined;
|
|
94
|
+
return evaluateNodeAsNumber(prop.getInitializer());
|
|
75
95
|
}
|
|
76
96
|
/**
|
|
77
97
|
* Extract an object literal from an object property.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ast-helpers.js","sourceRoot":"","sources":["../../../src/compiler/utils/ast-helpers.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"ast-helpers.js","sourceRoot":"","sources":["../../../src/compiler/utils/ast-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,IAAI,EAAuC,MAAM,UAAU,CAAC;AACrE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC;;;;;;GAMG;AACH,SAAS,YAAY,CAAC,IAAsB;IAC1C,IAAI,CAAC,IAAI;QAAE,OAAO,SAAS,CAAC;IAE5B,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,CAAC,YAA6B,CAAC;QAClD,MAAM,WAAW,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC,UAAU,EAAE,CAAC,cAAc,EAAE,CAAC,cAAc,CAAC;QAEtF,MAAM,MAAM,GAAG,QAAQ,CAAC;YACtB,IAAI,EAAE,MAAM;YACZ,WAAW;YACX,UAAU,EAAE,EAAE;YACd,WAAW,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE;YAC/B,MAAM,EAAE;gBACN,aAAa,EAAE,KAAK;gBACpB,OAAO,EAAE,KAAK;gBACd,OAAO,EAAE,KAAK;gBACd,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE;gBAChC,OAAO,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE;aAC5C;SACF,CAAC,CAAC;QAEH,IAAI,MAAM,CAAC,OAAO;YAAE,OAAO,MAAM,CAAC,KAAK,CAAC;IAC1C,CAAC;IAAC,MAAM,CAA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qBAAqB,EAAE,EAAE,CAAC;QAC5D,MAAM,aAAa,GAAG,UAAU,CAAC,gBAAgB,EAAE,CAAC;QACpD,MAAM,YAAY,GAAG,UAAU,CAAC,eAAe,EAAE,CAAC;QAElD,iEAAiE;QACjE,MAAM,OAAO,GACX,CAAC,aAAa,IAAI,aAAa,CAAC,OAAO,EAAE,KAAK,UAAU,CAAC;YACzD,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,UAAU,CAAC,CAAC;QAE7D,IAAI,OAAO,EAAE,CAAC;YACZ,OAAO,iBAAiB,CACtB,UAAU,CAAC,uBAAuB,EAAE,EACpC,UAAU,CAAC,WAAW,EAAE,CACzB,CAAC;QACJ,CAAC;IACH,CAAC;IAED,8DAA8D;IAC9D,OAAO,UAAU,CAAC,WAAW,EAAE,CAAC;AAClC,CAAC"}
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { PrimitiveKind, CompilationManifest, ManifestPrimitive } from '../compiler/types.js';
|
|
11
11
|
import { YamlConfig } from '../types/yaml.types.js';
|
|
12
|
-
import type { VersionedPrimitiveHandler, PrimitiveHandler, SyncResult, YamlPrimitiveConfig } from './types.js';
|
|
12
|
+
import type { VersionedPrimitiveHandler, PrimitiveHandler, SyncResult, ServerSyncData, YamlPrimitiveConfig } from './types.js';
|
|
13
13
|
/** Default version for new primitives */
|
|
14
14
|
export declare const DEFAULT_VERSION: "1.0.0";
|
|
15
15
|
/**
|
|
@@ -29,11 +29,33 @@ export declare abstract class BaseVersionedHandler<T extends {
|
|
|
29
29
|
abstract readonly yamlConfig: YamlPrimitiveConfig;
|
|
30
30
|
protected abstract getApi(apiKey: string, agentId: string): unknown;
|
|
31
31
|
protected abstract fetchFromServer(api: unknown): Promise<any[] | null>;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Strip a YAML item to only the canonical fields: name, version, [idField].
|
|
34
|
+
* Override if your YAML type has additional fields.
|
|
35
|
+
*/
|
|
36
|
+
cleanItem(item: T): T;
|
|
37
|
+
/**
|
|
38
|
+
* Whether a server entity is considered active (for orphan detection).
|
|
39
|
+
* Default: true. Override for primitives with active/status fields.
|
|
40
|
+
*/
|
|
41
|
+
isActive(_serverItem: any): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Get the active version string from a server entity.
|
|
44
|
+
* Default: finds version with isActive === true. Override for different field names.
|
|
45
|
+
*/
|
|
46
|
+
getActiveVersion(serverItem: any): string | null;
|
|
35
47
|
protected getServerItemName(item: any): string;
|
|
36
48
|
protected shouldConsiderForOrphan(_item: any): boolean;
|
|
49
|
+
/** Phase 1 of parallel sync: fetch server state (HTTP only, no YAML writes) */
|
|
50
|
+
fetchServerState(apiKey: string, agentId: string): Promise<ServerSyncData>;
|
|
51
|
+
/**
|
|
52
|
+
* Phase 2 of parallel sync: apply fetched data to YAML.
|
|
53
|
+
* Optionally creates missing primitives on server if apiKey+agentId provided.
|
|
54
|
+
*/
|
|
55
|
+
applySyncToYaml(serverData: ServerSyncData, config: YamlConfig | null, manifest?: CompilationManifest, apiCredentials?: {
|
|
56
|
+
apiKey: string;
|
|
57
|
+
agentId: string;
|
|
58
|
+
}): Promise<SyncResult>;
|
|
37
59
|
syncWithServer(apiKey: string, agentId: string, config: YamlConfig | null, manifest?: CompilationManifest): Promise<SyncResult>;
|
|
38
60
|
/**
|
|
39
61
|
* Create a primitive on the server. Subclasses must implement this.
|
|
@@ -75,13 +97,26 @@ export declare abstract class BaseVersionedHandler<T extends {
|
|
|
75
97
|
* Get the highest version string from the server for conflict avoidance.
|
|
76
98
|
*/
|
|
77
99
|
getHighestServerVersion(apiKey: string, agentId: string, entityId: string): Promise<string | null>;
|
|
100
|
+
/**
|
|
101
|
+
* Fetch all server items once, extract highest version for each entity ID.
|
|
102
|
+
* More efficient than calling getHighestServerVersion() per entity.
|
|
103
|
+
*/
|
|
104
|
+
batchGetHighestVersions(apiKey: string, agentId: string, entityIds: string[]): Promise<Map<string, string | null>>;
|
|
78
105
|
/** Get the server ID from a YAML item using the configured idField. */
|
|
79
106
|
protected getItemId(item: T): string;
|
|
80
|
-
|
|
107
|
+
protected buildMaps(serverItems: any[], yamlItems: T[]): {
|
|
108
|
+
yamlById: Map<string, T>;
|
|
109
|
+
yamlByName: Map<string, T>;
|
|
110
|
+
serverByName: Map<string, any>;
|
|
111
|
+
};
|
|
81
112
|
/**
|
|
82
113
|
* For each YAML item, match to server by name, populate missing IDs, update versions.
|
|
83
114
|
*/
|
|
84
|
-
|
|
115
|
+
protected syncFromServer(yamlItems: T[], serverByName: Map<string, any>): {
|
|
116
|
+
items: T[];
|
|
117
|
+
changed: boolean;
|
|
118
|
+
msgs: string[];
|
|
119
|
+
};
|
|
85
120
|
}
|
|
86
121
|
/**
|
|
87
122
|
* For primitives without versions (e.g., MCP servers).
|
|
@@ -99,6 +134,10 @@ export declare abstract class BaseNonVersionedHandler<T extends {
|
|
|
99
134
|
abstract cleanItem(item: T): T;
|
|
100
135
|
protected abstract isActive(item: any): boolean;
|
|
101
136
|
protected getServerItemName(item: any): string;
|
|
137
|
+
/** Phase 1 of parallel sync: fetch server state (HTTP only, no YAML writes) */
|
|
138
|
+
fetchServerState(apiKey: string, agentId: string): Promise<ServerSyncData>;
|
|
139
|
+
/** Phase 2 of parallel sync: apply fetched data to YAML (orphan detection only for non-versioned) */
|
|
140
|
+
applySyncToYaml(serverData: ServerSyncData, config: YamlConfig | null, _manifest?: CompilationManifest): Promise<SyncResult>;
|
|
102
141
|
syncWithServer(apiKey: string, agentId: string, config: YamlConfig | null, _manifest?: CompilationManifest): Promise<SyncResult>;
|
|
103
142
|
updateYaml(items: T[], config: YamlConfig | null): void;
|
|
104
143
|
getFromYaml(config: YamlConfig | null): T[];
|
|
@@ -11,6 +11,7 @@ import { readYamlConfig, writeYamlConfig } from '../utils/files.js';
|
|
|
11
11
|
import { SKILL_DEFAULTS } from '../config/compile.constants.js';
|
|
12
12
|
import { findPrimitive, loadArtifact, compressForPush } from '../utils/artifact-loader.js';
|
|
13
13
|
import { maxSemver } from '../utils/semver.js';
|
|
14
|
+
import { AuthenticationError } from '../errors/auth.error.js';
|
|
14
15
|
/** Default version for new primitives */
|
|
15
16
|
export const DEFAULT_VERSION = SKILL_DEFAULTS.VERSION;
|
|
16
17
|
// =============================================================================
|
|
@@ -23,6 +24,32 @@ export const DEFAULT_VERSION = SKILL_DEFAULTS.VERSION;
|
|
|
23
24
|
* Must have at least { name: string; version: string; [idField]: string }.
|
|
24
25
|
*/
|
|
25
26
|
export class BaseVersionedHandler {
|
|
27
|
+
/**
|
|
28
|
+
* Strip a YAML item to only the canonical fields: name, version, [idField].
|
|
29
|
+
* Override if your YAML type has additional fields.
|
|
30
|
+
*/
|
|
31
|
+
cleanItem(item) {
|
|
32
|
+
return {
|
|
33
|
+
name: item.name || '',
|
|
34
|
+
version: item.version || DEFAULT_VERSION,
|
|
35
|
+
[this.yamlConfig.idField]: this.getItemId(item) || '',
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Whether a server entity is considered active (for orphan detection).
|
|
40
|
+
* Default: true. Override for primitives with active/status fields.
|
|
41
|
+
*/
|
|
42
|
+
isActive(_serverItem) {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Get the active version string from a server entity.
|
|
47
|
+
* Default: finds version with isActive === true. Override for different field names.
|
|
48
|
+
*/
|
|
49
|
+
getActiveVersion(serverItem) {
|
|
50
|
+
const active = serverItem.versions?.find((v) => v.isActive === true);
|
|
51
|
+
return active?.version ?? null;
|
|
52
|
+
}
|
|
26
53
|
getServerItemName(item) {
|
|
27
54
|
return item.name || 'unknown';
|
|
28
55
|
}
|
|
@@ -32,21 +59,41 @@ export class BaseVersionedHandler {
|
|
|
32
59
|
// ===========================================================================
|
|
33
60
|
// SERVER SYNC
|
|
34
61
|
// ===========================================================================
|
|
35
|
-
|
|
62
|
+
/** Phase 1 of parallel sync: fetch server state (HTTP only, no YAML writes) */
|
|
63
|
+
async fetchServerState(apiKey, agentId) {
|
|
64
|
+
try {
|
|
65
|
+
const api = this.getApi(apiKey, agentId);
|
|
66
|
+
const serverItems = await this.fetchFromServer(api);
|
|
67
|
+
return { serverItems };
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
if (AuthenticationError.isAuthenticationError(error))
|
|
71
|
+
throw error;
|
|
72
|
+
return { serverItems: null, fetchError: error instanceof Error ? error.message : String(error) };
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Phase 2 of parallel sync: apply fetched data to YAML.
|
|
77
|
+
* Optionally creates missing primitives on server if apiKey+agentId provided.
|
|
78
|
+
*/
|
|
79
|
+
async applySyncToYaml(serverData, config, manifest, apiCredentials) {
|
|
36
80
|
const messages = [];
|
|
37
81
|
let yamlUpdated = false;
|
|
38
82
|
let orphanedCount = 0;
|
|
39
83
|
try {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
84
|
+
if (!serverData.serverItems) {
|
|
85
|
+
if (serverData.fetchError) {
|
|
86
|
+
console.error(`❌ Error syncing server ${this.displayNamePlural}: ${serverData.fetchError}`);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
console.warn(`⚠️ Could not retrieve server ${this.displayNamePlural}. Skipping sync.`);
|
|
90
|
+
}
|
|
44
91
|
return { messages, yamlUpdated, orphanedCount };
|
|
45
92
|
}
|
|
46
93
|
const yamlItems = this.getFromYaml(config);
|
|
47
|
-
const { yamlById, yamlByName, serverByName } = this.buildMaps(serverItems, yamlItems);
|
|
48
|
-
// Part 1: Detect orphaned items
|
|
49
|
-
const orphans = serverItems.filter(item => {
|
|
94
|
+
const { yamlById, yamlByName, serverByName } = this.buildMaps(serverData.serverItems, yamlItems);
|
|
95
|
+
// Part 1: Detect orphaned items
|
|
96
|
+
const orphans = serverData.serverItems.filter(item => {
|
|
50
97
|
const id = item.id;
|
|
51
98
|
const name = item.name;
|
|
52
99
|
return !yamlById.has(id) && !yamlByName.has(name) &&
|
|
@@ -70,8 +117,9 @@ export class BaseVersionedHandler {
|
|
|
70
117
|
console.log(`✅ YAML ${this.displayNamePlural} synced with server`);
|
|
71
118
|
yamlUpdated = true;
|
|
72
119
|
}
|
|
73
|
-
// Part 3: Create primitives that don't exist on server (if manifest provided)
|
|
74
|
-
if (manifest) {
|
|
120
|
+
// Part 3: Create primitives that don't exist on server (if manifest + credentials provided)
|
|
121
|
+
if (manifest && apiCredentials) {
|
|
122
|
+
const api = this.getApi(apiCredentials.apiKey, apiCredentials.agentId);
|
|
75
123
|
const { created, updated: creationUpdated } = await this.createMissingOnServer(api, manifest);
|
|
76
124
|
if (created.length > 0) {
|
|
77
125
|
messages.push(...created.map(name => `Created "${name}" on server`));
|
|
@@ -87,6 +135,10 @@ export class BaseVersionedHandler {
|
|
|
87
135
|
}
|
|
88
136
|
return { messages, yamlUpdated, orphanedCount };
|
|
89
137
|
}
|
|
138
|
+
async syncWithServer(apiKey, agentId, config, manifest) {
|
|
139
|
+
const serverData = await this.fetchServerState(apiKey, agentId);
|
|
140
|
+
return this.applySyncToYaml(serverData, config, manifest, { apiKey, agentId });
|
|
141
|
+
}
|
|
90
142
|
/**
|
|
91
143
|
* Create primitives that have empty IDs in YAML.
|
|
92
144
|
* Called internally by syncWithServer when manifest is provided.
|
|
@@ -240,6 +292,38 @@ export class BaseVersionedHandler {
|
|
|
240
292
|
return null;
|
|
241
293
|
}
|
|
242
294
|
}
|
|
295
|
+
/**
|
|
296
|
+
* Fetch all server items once, extract highest version for each entity ID.
|
|
297
|
+
* More efficient than calling getHighestServerVersion() per entity.
|
|
298
|
+
*/
|
|
299
|
+
async batchGetHighestVersions(apiKey, agentId, entityIds) {
|
|
300
|
+
const result = new Map();
|
|
301
|
+
try {
|
|
302
|
+
const api = this.getApi(apiKey, agentId);
|
|
303
|
+
const serverItems = await this.fetchFromServer(api);
|
|
304
|
+
if (!serverItems) {
|
|
305
|
+
entityIds.forEach(id => result.set(id, null));
|
|
306
|
+
return result;
|
|
307
|
+
}
|
|
308
|
+
for (const entityId of entityIds) {
|
|
309
|
+
const entity = serverItems.find((item) => item.id === entityId);
|
|
310
|
+
if (!entity?.versions || !Array.isArray(entity.versions)) {
|
|
311
|
+
result.set(entityId, null);
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
const versions = entity.versions
|
|
315
|
+
.map((v) => v.version)
|
|
316
|
+
.filter((v) => typeof v === 'string');
|
|
317
|
+
result.set(entityId, versions.length > 0
|
|
318
|
+
? versions.reduce((h, v) => maxSemver(h, v), '0.0.0')
|
|
319
|
+
: null);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
catch {
|
|
323
|
+
entityIds.forEach(id => result.set(id, null));
|
|
324
|
+
}
|
|
325
|
+
return result;
|
|
326
|
+
}
|
|
243
327
|
// ===========================================================================
|
|
244
328
|
// INTERNAL
|
|
245
329
|
// ===========================================================================
|
|
@@ -310,15 +394,31 @@ export class BaseNonVersionedHandler {
|
|
|
310
394
|
getServerItemName(item) {
|
|
311
395
|
return item.name || 'unknown';
|
|
312
396
|
}
|
|
313
|
-
|
|
314
|
-
) {
|
|
315
|
-
const messages = [];
|
|
316
|
-
let orphanedCount = 0;
|
|
397
|
+
/** Phase 1 of parallel sync: fetch server state (HTTP only, no YAML writes) */
|
|
398
|
+
async fetchServerState(apiKey, agentId) {
|
|
317
399
|
try {
|
|
318
400
|
const api = this.getApi(apiKey, agentId);
|
|
319
401
|
const serverItems = await this.fetchFromServer(api);
|
|
320
|
-
|
|
321
|
-
|
|
402
|
+
return { serverItems };
|
|
403
|
+
}
|
|
404
|
+
catch (error) {
|
|
405
|
+
if (AuthenticationError.isAuthenticationError(error))
|
|
406
|
+
throw error;
|
|
407
|
+
return { serverItems: null, fetchError: error instanceof Error ? error.message : String(error) };
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
/** Phase 2 of parallel sync: apply fetched data to YAML (orphan detection only for non-versioned) */
|
|
411
|
+
async applySyncToYaml(serverData, config, _manifest) {
|
|
412
|
+
const messages = [];
|
|
413
|
+
let orphanedCount = 0;
|
|
414
|
+
try {
|
|
415
|
+
if (!serverData.serverItems) {
|
|
416
|
+
if (serverData.fetchError) {
|
|
417
|
+
console.error(`❌ Error syncing server ${this.displayNamePlural}: ${serverData.fetchError}`);
|
|
418
|
+
}
|
|
419
|
+
else {
|
|
420
|
+
console.warn(`⚠️ Could not retrieve server ${this.displayNamePlural}. Skipping sync.`);
|
|
421
|
+
}
|
|
322
422
|
return { messages, yamlUpdated: false, orphanedCount };
|
|
323
423
|
}
|
|
324
424
|
const yamlItems = this.getFromYaml(config);
|
|
@@ -326,7 +426,7 @@ export class BaseNonVersionedHandler {
|
|
|
326
426
|
const getId = (item) => item[idField] || '';
|
|
327
427
|
const yamlById = new Map(yamlItems.filter(i => getId(i)).map(i => [getId(i), i]));
|
|
328
428
|
const yamlByName = new Map(yamlItems.map(i => [i.name, i]));
|
|
329
|
-
const orphans = serverItems.filter(item => {
|
|
429
|
+
const orphans = serverData.serverItems.filter(item => {
|
|
330
430
|
const id = item.id;
|
|
331
431
|
const name = item.name;
|
|
332
432
|
return !yamlById.has(id) && !yamlByName.has(name) && this.isActive(item);
|
|
@@ -350,6 +450,10 @@ export class BaseNonVersionedHandler {
|
|
|
350
450
|
}
|
|
351
451
|
return { messages, yamlUpdated: false, orphanedCount };
|
|
352
452
|
}
|
|
453
|
+
async syncWithServer(apiKey, agentId, config, _manifest) {
|
|
454
|
+
const serverData = await this.fetchServerState(apiKey, agentId);
|
|
455
|
+
return this.applySyncToYaml(serverData, config);
|
|
456
|
+
}
|
|
353
457
|
updateYaml(items, config) {
|
|
354
458
|
const updatedConfig = {
|
|
355
459
|
...(config || {}),
|