@typia/transform 12.0.0 → 12.0.2
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/lib/features/llm/LlmApplicationTransformer.d.ts +0 -6
- package/lib/features/llm/LlmApplicationTransformer.js +4 -82
- package/lib/features/llm/LlmApplicationTransformer.js.map +1 -1
- package/lib/features/llm/LlmApplicationTransformer.mjs +3 -80
- package/lib/features/llm/LlmApplicationTransformer.mjs.map +1 -1
- package/lib/features/llm/LlmControllerTransformer.js +64 -36
- package/lib/features/llm/LlmControllerTransformer.js.map +1 -1
- package/lib/features/llm/LlmControllerTransformer.mjs +64 -36
- package/lib/features/llm/LlmControllerTransformer.mjs.map +1 -1
- package/package.json +4 -4
- package/src/features/llm/LlmApplicationTransformer.ts +5 -142
- package/src/features/llm/LlmControllerTransformer.ts +84 -65
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
import { ITypiaContext } from "@typia/core";
|
|
2
1
|
import ts from "typescript";
|
|
3
2
|
import { ITransformProps } from "../../ITransformProps";
|
|
4
3
|
export declare namespace LlmApplicationTransformer {
|
|
5
4
|
const transform: (props: ITransformProps) => ts.Expression;
|
|
6
|
-
const getConfigArgument: (props: {
|
|
7
|
-
context: ITypiaContext;
|
|
8
|
-
argument: ts.Expression;
|
|
9
|
-
equals?: boolean | undefined;
|
|
10
|
-
}) => ts.ObjectLiteralExpression;
|
|
11
5
|
}
|
|
@@ -10,7 +10,7 @@ const TransformerError_1 = require("../../TransformerError");
|
|
|
10
10
|
var LlmApplicationTransformer;
|
|
11
11
|
(function (LlmApplicationTransformer) {
|
|
12
12
|
LlmApplicationTransformer.transform = (props) => {
|
|
13
|
-
var _a;
|
|
13
|
+
var _a, _b;
|
|
14
14
|
// GET GENERIC ARGUMENT
|
|
15
15
|
if (!((_a = props.expression.typeArguments) === null || _a === void 0 ? void 0 : _a.length))
|
|
16
16
|
throw new TransformerError_1.TransformerError({
|
|
@@ -66,88 +66,10 @@ var LlmApplicationTransformer;
|
|
|
66
66
|
metadata: analyze(false),
|
|
67
67
|
name: top.getFullText().trim(),
|
|
68
68
|
config,
|
|
69
|
+
configArgument: ((_b = props.expression.arguments) === null || _b === void 0 ? void 0 : _b[0]) !== undefined
|
|
70
|
+
? props.expression.arguments[0]
|
|
71
|
+
: undefined,
|
|
69
72
|
});
|
|
70
73
|
};
|
|
71
|
-
/** @internal */
|
|
72
|
-
LlmApplicationTransformer.decompose = (method, props) => {
|
|
73
|
-
var _a;
|
|
74
|
-
// GET GENERIC ARGUMENT
|
|
75
|
-
if (!((_a = props.expression.typeArguments) === null || _a === void 0 ? void 0 : _a.length))
|
|
76
|
-
throw new TransformerError_1.TransformerError({
|
|
77
|
-
code: `typia.llm.${method}`,
|
|
78
|
-
message: "no generic argument.",
|
|
79
|
-
});
|
|
80
|
-
const top = props.expression.typeArguments[0];
|
|
81
|
-
if (typescript_1.default.isTypeNode(top) === false)
|
|
82
|
-
return null;
|
|
83
|
-
// GET TYPE
|
|
84
|
-
const config = core_1.LlmMetadataFactory.getConfig({
|
|
85
|
-
context: props.context,
|
|
86
|
-
method,
|
|
87
|
-
node: props.expression.typeArguments[1],
|
|
88
|
-
});
|
|
89
|
-
const type = props.context.checker.getTypeFromTypeNode(top);
|
|
90
|
-
// VALIDATE TYPE
|
|
91
|
-
const analyze = (validate) => {
|
|
92
|
-
const result = core_1.MetadataFactory.analyze({
|
|
93
|
-
checker: props.context.checker,
|
|
94
|
-
transformer: props.context.transformer,
|
|
95
|
-
options: {
|
|
96
|
-
absorb: validate,
|
|
97
|
-
escape: true,
|
|
98
|
-
constant: true,
|
|
99
|
-
functional: true,
|
|
100
|
-
validate: validate === true
|
|
101
|
-
? (next) => core_1.LlmApplicationProgrammer.validate({
|
|
102
|
-
config,
|
|
103
|
-
metadata: next.metadata,
|
|
104
|
-
explore: next.explore,
|
|
105
|
-
top: next.top,
|
|
106
|
-
})
|
|
107
|
-
: undefined,
|
|
108
|
-
},
|
|
109
|
-
components: new core_1.MetadataCollection({
|
|
110
|
-
replace: core_1.MetadataCollection.replace,
|
|
111
|
-
}),
|
|
112
|
-
type,
|
|
113
|
-
});
|
|
114
|
-
if (result.success === false)
|
|
115
|
-
throw TransformerError_1.TransformerError.from({
|
|
116
|
-
code: `typia.llm.${method}`,
|
|
117
|
-
errors: result.errors,
|
|
118
|
-
});
|
|
119
|
-
return result.data;
|
|
120
|
-
};
|
|
121
|
-
analyze(true);
|
|
122
|
-
// GENERATE LLM APPLICATION
|
|
123
|
-
return {
|
|
124
|
-
application: core_1.LlmApplicationProgrammer.writeApplication({
|
|
125
|
-
context: props.context,
|
|
126
|
-
modulo: props.modulo,
|
|
127
|
-
metadata: analyze(false),
|
|
128
|
-
config,
|
|
129
|
-
name: top.getFullText().trim(),
|
|
130
|
-
}),
|
|
131
|
-
node: top,
|
|
132
|
-
type,
|
|
133
|
-
config,
|
|
134
|
-
};
|
|
135
|
-
};
|
|
136
|
-
LlmApplicationTransformer.getConfigArgument = (props) => {
|
|
137
|
-
const satisfiesTypeNode = typescript_1.default.factory.createTypeReferenceNode(typescript_1.default.factory.createIdentifier("Partial"), [
|
|
138
|
-
typescript_1.default.factory.createTypeReferenceNode(typescript_1.default.factory.createIdentifier("Pick"), [
|
|
139
|
-
typescript_1.default.factory.createImportTypeNode(typescript_1.default.factory.createLiteralTypeNode(typescript_1.default.factory.createStringLiteral("typia")), undefined, typescript_1.default.factory.createQualifiedName(typescript_1.default.factory.createIdentifier("ILlmApplication"), typescript_1.default.factory.createIdentifier("IConfig")), undefined, false),
|
|
140
|
-
typescript_1.default.factory.createUnionTypeNode([
|
|
141
|
-
typescript_1.default.factory.createLiteralTypeNode(typescript_1.default.factory.createStringLiteral("validate")),
|
|
142
|
-
]),
|
|
143
|
-
]),
|
|
144
|
-
]);
|
|
145
|
-
return typescript_1.default.factory.createObjectLiteralExpression([
|
|
146
|
-
typescript_1.default.factory.createSpreadAssignment(typescript_1.default.factory.createSatisfiesExpression(props.argument, satisfiesTypeNode)),
|
|
147
|
-
typescript_1.default.factory.createPropertyAssignment("equals", props.equals === true
|
|
148
|
-
? typescript_1.default.factory.createTrue()
|
|
149
|
-
: typescript_1.default.factory.createFalse()),
|
|
150
|
-
], true);
|
|
151
|
-
};
|
|
152
74
|
})(LlmApplicationTransformer || (exports.LlmApplicationTransformer = LlmApplicationTransformer = {}));
|
|
153
75
|
//# sourceMappingURL=LlmApplicationTransformer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LlmApplicationTransformer.js","sourceRoot":"","sources":["../../../src/features/llm/LlmApplicationTransformer.ts"],"names":[],"mappings":";;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"LlmApplicationTransformer.js","sourceRoot":"","sources":["../../../src/features/llm/LlmApplicationTransformer.ts"],"names":[],"mappings":";;;;;;AAAA,sCAMqB;AAErB,4DAA4B;AAG5B,6DAA0D;AAE1D,IAAiB,yBAAyB,CA2EzC;AA3ED,WAAiB,yBAAyB;IAC3B,mCAAS,GAAG,CAAC,KAAsB,EAAiB,EAAE;;QACjE,uBAAuB;QACvB,IAAI,CAAC,CAAA,MAAA,KAAK,CAAC,UAAU,CAAC,aAAa,0CAAE,MAAM,CAAA;YACzC,MAAM,IAAI,mCAAgB,CAAC;gBACzB,IAAI,EAAE,uBAAuB;gBAC7B,OAAO,EAAE,sBAAsB;aAChC,CAAC,CAAC;QACL,MAAM,GAAG,GAAY,KAAK,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC,CAAE,CAAC;QACxD,IAAI,oBAAE,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,KAAK;YAAE,OAAO,KAAK,CAAC,UAAU,CAAC;QAE1D,aAAa;QACb,MAAM,MAAM,GAMI,yBAAkB,CAAC,SAAS,CAAC;YAC3C,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,MAAM,EAAE,aAAa;YACrB,IAAI,EAAE,KAAK,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC;SACxC,CA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,EAAE,OAAO,CAAC,KAAK,CAAC;YACxB,IAAI,EAAE,GAAG,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE;YAC9B,MAAM;YACN,cAAc,EACZ,CAAA,MAAA,KAAK,CAAC,UAAU,CAAC,SAAS,0CAAG,CAAC,CAAC,MAAK,SAAS;gBAC3C,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC;gBAC/B,CAAC,CAAC,SAAS;SAChB,CAAC,CAAC;IACL,CAAC,CAAC;AAEJ,CAAC,EA3EgB,yBAAyB,yCAAzB,yBAAyB,QA2EzC"}
|
|
@@ -60,88 +60,11 @@ var LlmApplicationTransformer;
|
|
|
60
60
|
metadata: analyze(false),
|
|
61
61
|
name: top.getFullText().trim(),
|
|
62
62
|
config,
|
|
63
|
+
configArgument: props.expression.arguments?.[0] !== undefined
|
|
64
|
+
? props.expression.arguments[0]
|
|
65
|
+
: undefined,
|
|
63
66
|
});
|
|
64
67
|
};
|
|
65
|
-
/** @internal */
|
|
66
|
-
LlmApplicationTransformer.decompose = (method, props) => {
|
|
67
|
-
// GET GENERIC ARGUMENT
|
|
68
|
-
if (!props.expression.typeArguments?.length)
|
|
69
|
-
throw new TransformerError({
|
|
70
|
-
code: `typia.llm.${method}`,
|
|
71
|
-
message: "no generic argument.",
|
|
72
|
-
});
|
|
73
|
-
const top = props.expression.typeArguments[0];
|
|
74
|
-
if (ts.isTypeNode(top) === false)
|
|
75
|
-
return null;
|
|
76
|
-
// GET TYPE
|
|
77
|
-
const config = LlmMetadataFactory.getConfig({
|
|
78
|
-
context: props.context,
|
|
79
|
-
method,
|
|
80
|
-
node: props.expression.typeArguments[1],
|
|
81
|
-
});
|
|
82
|
-
const type = props.context.checker.getTypeFromTypeNode(top);
|
|
83
|
-
// VALIDATE TYPE
|
|
84
|
-
const analyze = (validate) => {
|
|
85
|
-
const result = MetadataFactory.analyze({
|
|
86
|
-
checker: props.context.checker,
|
|
87
|
-
transformer: props.context.transformer,
|
|
88
|
-
options: {
|
|
89
|
-
absorb: validate,
|
|
90
|
-
escape: true,
|
|
91
|
-
constant: true,
|
|
92
|
-
functional: true,
|
|
93
|
-
validate: validate === true
|
|
94
|
-
? (next) => LlmApplicationProgrammer.validate({
|
|
95
|
-
config,
|
|
96
|
-
metadata: next.metadata,
|
|
97
|
-
explore: next.explore,
|
|
98
|
-
top: next.top,
|
|
99
|
-
})
|
|
100
|
-
: undefined,
|
|
101
|
-
},
|
|
102
|
-
components: new MetadataCollection({
|
|
103
|
-
replace: MetadataCollection.replace,
|
|
104
|
-
}),
|
|
105
|
-
type,
|
|
106
|
-
});
|
|
107
|
-
if (result.success === false)
|
|
108
|
-
throw TransformerError.from({
|
|
109
|
-
code: `typia.llm.${method}`,
|
|
110
|
-
errors: result.errors,
|
|
111
|
-
});
|
|
112
|
-
return result.data;
|
|
113
|
-
};
|
|
114
|
-
analyze(true);
|
|
115
|
-
// GENERATE LLM APPLICATION
|
|
116
|
-
return {
|
|
117
|
-
application: LlmApplicationProgrammer.writeApplication({
|
|
118
|
-
context: props.context,
|
|
119
|
-
modulo: props.modulo,
|
|
120
|
-
metadata: analyze(false),
|
|
121
|
-
config,
|
|
122
|
-
name: top.getFullText().trim(),
|
|
123
|
-
}),
|
|
124
|
-
node: top,
|
|
125
|
-
type,
|
|
126
|
-
config,
|
|
127
|
-
};
|
|
128
|
-
};
|
|
129
|
-
LlmApplicationTransformer.getConfigArgument = (props) => {
|
|
130
|
-
const satisfiesTypeNode = ts.factory.createTypeReferenceNode(ts.factory.createIdentifier("Partial"), [
|
|
131
|
-
ts.factory.createTypeReferenceNode(ts.factory.createIdentifier("Pick"), [
|
|
132
|
-
ts.factory.createImportTypeNode(ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral("typia")), undefined, ts.factory.createQualifiedName(ts.factory.createIdentifier("ILlmApplication"), ts.factory.createIdentifier("IConfig")), undefined, false),
|
|
133
|
-
ts.factory.createUnionTypeNode([
|
|
134
|
-
ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral("validate")),
|
|
135
|
-
]),
|
|
136
|
-
]),
|
|
137
|
-
]);
|
|
138
|
-
return ts.factory.createObjectLiteralExpression([
|
|
139
|
-
ts.factory.createSpreadAssignment(ts.factory.createSatisfiesExpression(props.argument, satisfiesTypeNode)),
|
|
140
|
-
ts.factory.createPropertyAssignment("equals", props.equals === true
|
|
141
|
-
? ts.factory.createTrue()
|
|
142
|
-
: ts.factory.createFalse()),
|
|
143
|
-
], true);
|
|
144
|
-
};
|
|
145
68
|
})(LlmApplicationTransformer || (LlmApplicationTransformer = {}));
|
|
146
69
|
|
|
147
70
|
export { LlmApplicationTransformer };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LlmApplicationTransformer.mjs","sources":["../../../src/features/llm/LlmApplicationTransformer.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"LlmApplicationTransformer.mjs","sources":["../../../src/features/llm/LlmApplicationTransformer.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAaM,IAAW;AAAjB,CAAA,UAAiB,yBAAyB,EAAA;AAC3B,IAAA,yBAAA,CAAA,SAAS,GAAG,CAAC,KAAsB,KAAmB;;AAEjE,QAAA,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,aAAa,EAAE,MAAM;YACzC,MAAM,IAAI,gBAAgB,CAAC;AACzB,gBAAA,IAAI,EAAE,uBAAuB;AAC7B,gBAAA,OAAO,EAAE,sBAAsB;AAChC,aAAA,CAAC;QACJ,MAAM,GAAG,GAAY,KAAK,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC,CAAE;AACvD,QAAA,IAAI,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,KAAK;YAAE,OAAO,KAAK,CAAC,UAAU;;AAGzD,QAAA,MAAM,MAAM,GAMI,kBAAkB,CAAC,SAAS,CAAC;YAC3C,OAAO,EAAE,KAAK,CAAC,OAAO;AACtB,YAAA,MAAM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O,EAAE,KAAK,CAAC,OAAO;YACtB,MAAM,EAAE,KAAK,CAAC,MAAM;AACpB,YAAA,QAAQ,EAAE,OAAO,CAAC,KAAK,CAAC;AACxB,YAAA,IAAI,EAAE,GAAG,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE;YAC9B,MAAM;YACN,cAAc,EACZ,KAAK,CAAC,UAAU,CAAC,SAAS,GAAG,CAAC,CAAC,KAAK;kBAChC,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;AAC9B,kBAAE,SAAS;AAChB,SAAA,CAAC;AACJ,IAAA,CAAC;AAEH,CAAC,EA3EgB,yBAAyB,KAAzB,yBAAyB,GAAA,EAAA,CAAA,CAAA;;;;"}
|
|
@@ -7,52 +7,80 @@ exports.LlmControllerTransformer = void 0;
|
|
|
7
7
|
const core_1 = require("@typia/core");
|
|
8
8
|
const typescript_1 = __importDefault(require("typescript"));
|
|
9
9
|
const TransformerError_1 = require("../../TransformerError");
|
|
10
|
-
const LlmApplicationTransformer_1 = require("./LlmApplicationTransformer");
|
|
11
10
|
var LlmControllerTransformer;
|
|
12
11
|
(function (LlmControllerTransformer) {
|
|
13
12
|
LlmControllerTransformer.transform = (props) => {
|
|
14
|
-
var _a
|
|
15
|
-
|
|
16
|
-
if (
|
|
13
|
+
var _a;
|
|
14
|
+
// GET GENERIC ARGUMENT
|
|
15
|
+
if (!((_a = props.expression.typeArguments) === null || _a === void 0 ? void 0 : _a.length))
|
|
16
|
+
throw new TransformerError_1.TransformerError({
|
|
17
|
+
code: "typia.llm.controller",
|
|
18
|
+
message: "no generic argument.",
|
|
19
|
+
});
|
|
20
|
+
const top = props.expression.typeArguments[0];
|
|
21
|
+
if (typescript_1.default.isTypeNode(top) === false)
|
|
17
22
|
return props.expression;
|
|
18
|
-
|
|
23
|
+
if (props.expression.arguments[0] === undefined)
|
|
19
24
|
throw new TransformerError_1.TransformerError({
|
|
20
|
-
code:
|
|
21
|
-
message:
|
|
25
|
+
code: "typia.llm.controller",
|
|
26
|
+
message: "no identifier name.",
|
|
22
27
|
});
|
|
23
|
-
|
|
28
|
+
if (props.expression.arguments[1] === undefined)
|
|
24
29
|
throw new TransformerError_1.TransformerError({
|
|
25
|
-
code:
|
|
26
|
-
message:
|
|
30
|
+
code: "typia.llm.controller",
|
|
31
|
+
message: "no executor.",
|
|
27
32
|
});
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
33
|
+
// GET CONFIG
|
|
34
|
+
const config = core_1.LlmMetadataFactory.getConfig({
|
|
35
|
+
context: props.context,
|
|
36
|
+
method: "controller",
|
|
37
|
+
node: props.expression.typeArguments[1],
|
|
32
38
|
});
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
39
|
+
const type = props.context.checker.getTypeFromTypeNode(top);
|
|
40
|
+
// VALIDATE TYPE
|
|
41
|
+
const analyze = (validate) => {
|
|
42
|
+
const result = core_1.MetadataFactory.analyze({
|
|
43
|
+
checker: props.context.checker,
|
|
44
|
+
transformer: props.context.transformer,
|
|
45
|
+
options: {
|
|
46
|
+
absorb: validate,
|
|
47
|
+
escape: true,
|
|
48
|
+
constant: true,
|
|
49
|
+
functional: true,
|
|
50
|
+
validate: validate === true
|
|
51
|
+
? (next) => core_1.LlmApplicationProgrammer.validate({
|
|
52
|
+
config,
|
|
53
|
+
metadata: next.metadata,
|
|
54
|
+
explore: next.explore,
|
|
55
|
+
top: next.top,
|
|
56
|
+
})
|
|
57
|
+
: undefined,
|
|
58
|
+
},
|
|
59
|
+
components: new core_1.MetadataCollection({
|
|
60
|
+
replace: core_1.MetadataCollection.replace,
|
|
61
|
+
}),
|
|
62
|
+
type,
|
|
63
|
+
});
|
|
64
|
+
if (result.success === false)
|
|
65
|
+
throw TransformerError_1.TransformerError.from({
|
|
66
|
+
code: "typia.llm.controller",
|
|
67
|
+
errors: result.errors,
|
|
68
|
+
});
|
|
69
|
+
return result.data;
|
|
70
|
+
};
|
|
71
|
+
analyze(true);
|
|
72
|
+
// GENERATE LLM CONTROLLER
|
|
73
|
+
return core_1.LlmControllerProgrammer.write({
|
|
74
|
+
context: props.context,
|
|
75
|
+
modulo: props.modulo,
|
|
76
|
+
metadata: analyze(false),
|
|
77
|
+
className: top.getFullText().trim(),
|
|
78
|
+
config,
|
|
79
|
+
node: top,
|
|
80
|
+
nameArgument: props.expression.arguments[0],
|
|
81
|
+
executeArgument: props.expression.arguments[1],
|
|
82
|
+
configArgument: props.expression.arguments[2],
|
|
37
83
|
});
|
|
38
|
-
const value = typescript_1.default.factory.createObjectLiteralExpression([
|
|
39
|
-
typescript_1.default.factory.createPropertyAssignment("protocol", typescript_1.default.factory.createStringLiteral("class")),
|
|
40
|
-
typescript_1.default.factory.createPropertyAssignment("name", props.expression.arguments[0]),
|
|
41
|
-
typescript_1.default.factory.createPropertyAssignment("execute", props.expression.arguments[1]),
|
|
42
|
-
typescript_1.default.factory.createPropertyAssignment("application", typescript_1.default.factory.createCallExpression(props.context.importer.internal("llmApplicationFinalize"), undefined, [
|
|
43
|
-
typescript_1.default.factory.createAsExpression(typescript_1.default.factory.createSatisfiesExpression(core_1.LiteralFactory.write(dec.application), primitiveTypeNode), primitiveTypeNode),
|
|
44
|
-
...(((_a = props.expression.arguments) === null || _a === void 0 ? void 0 : _a[2]) !== undefined
|
|
45
|
-
? [
|
|
46
|
-
LlmApplicationTransformer_1.LlmApplicationTransformer.getConfigArgument({
|
|
47
|
-
context: props.context,
|
|
48
|
-
argument: props.expression.arguments[2],
|
|
49
|
-
equals: (_b = dec.config) === null || _b === void 0 ? void 0 : _b.equals,
|
|
50
|
-
}),
|
|
51
|
-
]
|
|
52
|
-
: []),
|
|
53
|
-
])),
|
|
54
|
-
], true);
|
|
55
|
-
return typescript_1.default.factory.createAsExpression(typescript_1.default.factory.createSatisfiesExpression(value, typeNode), typeNode);
|
|
56
84
|
};
|
|
57
85
|
})(LlmControllerTransformer || (exports.LlmControllerTransformer = LlmControllerTransformer = {}));
|
|
58
86
|
//# sourceMappingURL=LlmControllerTransformer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LlmControllerTransformer.js","sourceRoot":"","sources":["../../../src/features/llm/LlmControllerTransformer.ts"],"names":[],"mappings":";;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"LlmControllerTransformer.js","sourceRoot":"","sources":["../../../src/features/llm/LlmControllerTransformer.ts"],"names":[],"mappings":";;;;;;AAAA,sCAOqB;AAErB,4DAA4B;AAG5B,6DAA0D;AAE1D,IAAiB,wBAAwB,CAqFxC;AArFD,WAAiB,wBAAwB;IAC1B,kCAAS,GAAG,CAAC,KAAsB,EAAiB,EAAE;;QACjE,uBAAuB;QACvB,IAAI,CAAC,CAAA,MAAA,KAAK,CAAC,UAAU,CAAC,aAAa,0CAAE,MAAM,CAAA;YACzC,MAAM,IAAI,mCAAgB,CAAC;gBACzB,IAAI,EAAE,sBAAsB;gBAC5B,OAAO,EAAE,sBAAsB;aAChC,CAAC,CAAC;QACL,MAAM,GAAG,GAAY,KAAK,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC,CAAE,CAAC;QACxD,IAAI,oBAAE,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,KAAK;YAAE,OAAO,KAAK,CAAC,UAAU,CAAC;QAE1D,IAAI,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,SAAS;YAC7C,MAAM,IAAI,mCAAgB,CAAC;gBACzB,IAAI,EAAE,sBAAsB;gBAC5B,OAAO,EAAE,qBAAqB;aAC/B,CAAC,CAAC;QACL,IAAI,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,SAAS;YAC7C,MAAM,IAAI,mCAAgB,CAAC;gBACzB,IAAI,EAAE,sBAAsB;gBAC5B,OAAO,EAAE,cAAc;aACxB,CAAC,CAAC;QAEL,aAAa;QACb,MAAM,MAAM,GAMI,yBAAkB,CAAC,SAAS,CAAC;YAC3C,OAAO,EAAE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,OAAO,8BAAuB,CAAC,KAAK,CAAC;YACnC,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,QAAQ,EAAE,OAAO,CAAC,KAAK,CAAC;YACxB,SAAS,EAAE,GAAG,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE;YACnC,MAAM;YACN,IAAI,EAAE,GAAG;YACT,YAAY,EAAE,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC;YAC3C,eAAe,EAAE,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC;YAC9C,cAAc,EAAE,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC;SAC9C,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC,EArFgB,wBAAwB,wCAAxB,wBAAwB,QAqFxC"}
|
|
@@ -1,52 +1,80 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LlmMetadataFactory, LlmControllerProgrammer, MetadataFactory, MetadataCollection, LlmApplicationProgrammer } from '@typia/core';
|
|
2
2
|
import ts from 'typescript';
|
|
3
3
|
import { TransformerError } from '../../TransformerError.mjs';
|
|
4
|
-
import { LlmApplicationTransformer } from './LlmApplicationTransformer.mjs';
|
|
5
4
|
|
|
6
5
|
var LlmControllerTransformer;
|
|
7
6
|
(function (LlmControllerTransformer) {
|
|
8
7
|
LlmControllerTransformer.transform = (props) => {
|
|
9
|
-
|
|
10
|
-
if (
|
|
8
|
+
// GET GENERIC ARGUMENT
|
|
9
|
+
if (!props.expression.typeArguments?.length)
|
|
10
|
+
throw new TransformerError({
|
|
11
|
+
code: "typia.llm.controller",
|
|
12
|
+
message: "no generic argument.",
|
|
13
|
+
});
|
|
14
|
+
const top = props.expression.typeArguments[0];
|
|
15
|
+
if (ts.isTypeNode(top) === false)
|
|
11
16
|
return props.expression;
|
|
12
|
-
|
|
17
|
+
if (props.expression.arguments[0] === undefined)
|
|
13
18
|
throw new TransformerError({
|
|
14
|
-
code:
|
|
15
|
-
message:
|
|
19
|
+
code: "typia.llm.controller",
|
|
20
|
+
message: "no identifier name.",
|
|
16
21
|
});
|
|
17
|
-
|
|
22
|
+
if (props.expression.arguments[1] === undefined)
|
|
18
23
|
throw new TransformerError({
|
|
19
|
-
code:
|
|
20
|
-
message:
|
|
24
|
+
code: "typia.llm.controller",
|
|
25
|
+
message: "no executor.",
|
|
21
26
|
});
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
// GET CONFIG
|
|
28
|
+
const config = LlmMetadataFactory.getConfig({
|
|
29
|
+
context: props.context,
|
|
30
|
+
method: "controller",
|
|
31
|
+
node: props.expression.typeArguments[1],
|
|
26
32
|
});
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
33
|
+
const type = props.context.checker.getTypeFromTypeNode(top);
|
|
34
|
+
// VALIDATE TYPE
|
|
35
|
+
const analyze = (validate) => {
|
|
36
|
+
const result = MetadataFactory.analyze({
|
|
37
|
+
checker: props.context.checker,
|
|
38
|
+
transformer: props.context.transformer,
|
|
39
|
+
options: {
|
|
40
|
+
absorb: validate,
|
|
41
|
+
escape: true,
|
|
42
|
+
constant: true,
|
|
43
|
+
functional: true,
|
|
44
|
+
validate: validate === true
|
|
45
|
+
? (next) => LlmApplicationProgrammer.validate({
|
|
46
|
+
config,
|
|
47
|
+
metadata: next.metadata,
|
|
48
|
+
explore: next.explore,
|
|
49
|
+
top: next.top,
|
|
50
|
+
})
|
|
51
|
+
: undefined,
|
|
52
|
+
},
|
|
53
|
+
components: new MetadataCollection({
|
|
54
|
+
replace: MetadataCollection.replace,
|
|
55
|
+
}),
|
|
56
|
+
type,
|
|
57
|
+
});
|
|
58
|
+
if (result.success === false)
|
|
59
|
+
throw TransformerError.from({
|
|
60
|
+
code: "typia.llm.controller",
|
|
61
|
+
errors: result.errors,
|
|
62
|
+
});
|
|
63
|
+
return result.data;
|
|
64
|
+
};
|
|
65
|
+
analyze(true);
|
|
66
|
+
// GENERATE LLM CONTROLLER
|
|
67
|
+
return LlmControllerProgrammer.write({
|
|
68
|
+
context: props.context,
|
|
69
|
+
modulo: props.modulo,
|
|
70
|
+
metadata: analyze(false),
|
|
71
|
+
className: top.getFullText().trim(),
|
|
72
|
+
config,
|
|
73
|
+
node: top,
|
|
74
|
+
nameArgument: props.expression.arguments[0],
|
|
75
|
+
executeArgument: props.expression.arguments[1],
|
|
76
|
+
configArgument: props.expression.arguments[2],
|
|
31
77
|
});
|
|
32
|
-
const value = ts.factory.createObjectLiteralExpression([
|
|
33
|
-
ts.factory.createPropertyAssignment("protocol", ts.factory.createStringLiteral("class")),
|
|
34
|
-
ts.factory.createPropertyAssignment("name", props.expression.arguments[0]),
|
|
35
|
-
ts.factory.createPropertyAssignment("execute", props.expression.arguments[1]),
|
|
36
|
-
ts.factory.createPropertyAssignment("application", ts.factory.createCallExpression(props.context.importer.internal("llmApplicationFinalize"), undefined, [
|
|
37
|
-
ts.factory.createAsExpression(ts.factory.createSatisfiesExpression(LiteralFactory.write(dec.application), primitiveTypeNode), primitiveTypeNode),
|
|
38
|
-
...(props.expression.arguments?.[2] !== undefined
|
|
39
|
-
? [
|
|
40
|
-
LlmApplicationTransformer.getConfigArgument({
|
|
41
|
-
context: props.context,
|
|
42
|
-
argument: props.expression.arguments[2],
|
|
43
|
-
equals: dec.config?.equals,
|
|
44
|
-
}),
|
|
45
|
-
]
|
|
46
|
-
: []),
|
|
47
|
-
])),
|
|
48
|
-
], true);
|
|
49
|
-
return ts.factory.createAsExpression(ts.factory.createSatisfiesExpression(value, typeNode), typeNode);
|
|
50
78
|
};
|
|
51
79
|
})(LlmControllerTransformer || (LlmControllerTransformer = {}));
|
|
52
80
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LlmControllerTransformer.mjs","sources":["../../../src/features/llm/LlmControllerTransformer.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":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M;AACN,YAAA,IAAI,EAAE,GAAG;YACT,YAAY,EAAE,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC;YAC3C,eAAe,EAAE,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC;YAC9C,cAAc,EAAE,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC;AAC9C,SAAA,CAAC;AACJ,IAAA,CAAC;AACH,CAAC,EArFgB,wBAAwB,KAAxB,wBAAwB,GAAA,EAAA,CAAA,CAAA;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typia/transform",
|
|
3
|
-
"version": "12.0.
|
|
3
|
+
"version": "12.0.2",
|
|
4
4
|
"description": "Superfast runtime validators with only one line",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
},
|
|
23
23
|
"homepage": "https://typia.io",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@typia/
|
|
26
|
-
"@typia/interface": "^12.0.
|
|
27
|
-
"@typia/
|
|
25
|
+
"@typia/core": "^12.0.2",
|
|
26
|
+
"@typia/interface": "^12.0.2",
|
|
27
|
+
"@typia/utils": "^12.0.2"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@rollup/plugin-commonjs": "^29.0.0",
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
-
ITypiaContext,
|
|
3
2
|
LlmApplicationProgrammer,
|
|
4
3
|
LlmMetadataFactory,
|
|
5
4
|
MetadataCollection,
|
|
6
5
|
MetadataFactory,
|
|
7
6
|
MetadataSchema,
|
|
8
7
|
} from "@typia/core";
|
|
9
|
-
import {
|
|
8
|
+
import { ILlmSchema, ValidationPipe } from "@typia/interface";
|
|
10
9
|
import ts from "typescript";
|
|
11
10
|
|
|
12
11
|
import { ITransformProps } from "../../ITransformProps";
|
|
@@ -80,147 +79,11 @@ export namespace LlmApplicationTransformer {
|
|
|
80
79
|
metadata: analyze(false),
|
|
81
80
|
name: top.getFullText().trim(),
|
|
82
81
|
config,
|
|
82
|
+
configArgument:
|
|
83
|
+
props.expression.arguments?.[0] !== undefined
|
|
84
|
+
? props.expression.arguments[0]
|
|
85
|
+
: undefined,
|
|
83
86
|
});
|
|
84
87
|
};
|
|
85
88
|
|
|
86
|
-
/** @internal */
|
|
87
|
-
export const decompose = (
|
|
88
|
-
method: string,
|
|
89
|
-
props: ITransformProps,
|
|
90
|
-
): {
|
|
91
|
-
application: ILlmApplication.__IPrimitive;
|
|
92
|
-
type: ts.Type;
|
|
93
|
-
node: ts.TypeNode;
|
|
94
|
-
config:
|
|
95
|
-
| Partial<
|
|
96
|
-
ILlmSchema.IConfig & {
|
|
97
|
-
equals: boolean;
|
|
98
|
-
}
|
|
99
|
-
>
|
|
100
|
-
| undefined;
|
|
101
|
-
} | null => {
|
|
102
|
-
// GET GENERIC ARGUMENT
|
|
103
|
-
if (!props.expression.typeArguments?.length)
|
|
104
|
-
throw new TransformerError({
|
|
105
|
-
code: `typia.llm.${method}`,
|
|
106
|
-
message: "no generic argument.",
|
|
107
|
-
});
|
|
108
|
-
const top: ts.Node = props.expression.typeArguments[0]!;
|
|
109
|
-
if (ts.isTypeNode(top) === false) return null;
|
|
110
|
-
|
|
111
|
-
// GET TYPE
|
|
112
|
-
const config:
|
|
113
|
-
| Partial<
|
|
114
|
-
ILlmSchema.IConfig & {
|
|
115
|
-
equals: boolean;
|
|
116
|
-
}
|
|
117
|
-
>
|
|
118
|
-
| undefined = LlmMetadataFactory.getConfig({
|
|
119
|
-
context: props.context,
|
|
120
|
-
method,
|
|
121
|
-
node: props.expression.typeArguments[1],
|
|
122
|
-
});
|
|
123
|
-
const type: ts.Type = props.context.checker.getTypeFromTypeNode(top);
|
|
124
|
-
|
|
125
|
-
// VALIDATE TYPE
|
|
126
|
-
const analyze = (validate: boolean): MetadataSchema => {
|
|
127
|
-
const result: ValidationPipe<MetadataSchema, MetadataFactory.IError> =
|
|
128
|
-
MetadataFactory.analyze({
|
|
129
|
-
checker: props.context.checker,
|
|
130
|
-
transformer: props.context.transformer,
|
|
131
|
-
options: {
|
|
132
|
-
absorb: validate,
|
|
133
|
-
escape: true,
|
|
134
|
-
constant: true,
|
|
135
|
-
functional: true,
|
|
136
|
-
validate:
|
|
137
|
-
validate === true
|
|
138
|
-
? (next) =>
|
|
139
|
-
LlmApplicationProgrammer.validate({
|
|
140
|
-
config,
|
|
141
|
-
metadata: next.metadata,
|
|
142
|
-
explore: next.explore,
|
|
143
|
-
top: next.top,
|
|
144
|
-
})
|
|
145
|
-
: undefined,
|
|
146
|
-
},
|
|
147
|
-
components: new MetadataCollection({
|
|
148
|
-
replace: MetadataCollection.replace,
|
|
149
|
-
}),
|
|
150
|
-
type,
|
|
151
|
-
});
|
|
152
|
-
if (result.success === false)
|
|
153
|
-
throw TransformerError.from({
|
|
154
|
-
code: `typia.llm.${method}`,
|
|
155
|
-
errors: result.errors,
|
|
156
|
-
});
|
|
157
|
-
return result.data;
|
|
158
|
-
};
|
|
159
|
-
analyze(true);
|
|
160
|
-
|
|
161
|
-
// GENERATE LLM APPLICATION
|
|
162
|
-
return {
|
|
163
|
-
application: LlmApplicationProgrammer.writeApplication({
|
|
164
|
-
context: props.context,
|
|
165
|
-
modulo: props.modulo,
|
|
166
|
-
metadata: analyze(false),
|
|
167
|
-
config,
|
|
168
|
-
name: top.getFullText().trim(),
|
|
169
|
-
}),
|
|
170
|
-
node: top,
|
|
171
|
-
type,
|
|
172
|
-
config,
|
|
173
|
-
};
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
export const getConfigArgument = (props: {
|
|
177
|
-
context: ITypiaContext;
|
|
178
|
-
argument: ts.Expression;
|
|
179
|
-
equals?: boolean | undefined;
|
|
180
|
-
}) => {
|
|
181
|
-
const satisfiesTypeNode: ts.TypeNode = ts.factory.createTypeReferenceNode(
|
|
182
|
-
ts.factory.createIdentifier("Partial"),
|
|
183
|
-
[
|
|
184
|
-
ts.factory.createTypeReferenceNode(
|
|
185
|
-
ts.factory.createIdentifier("Pick"),
|
|
186
|
-
[
|
|
187
|
-
ts.factory.createImportTypeNode(
|
|
188
|
-
ts.factory.createLiteralTypeNode(
|
|
189
|
-
ts.factory.createStringLiteral("typia"),
|
|
190
|
-
),
|
|
191
|
-
undefined,
|
|
192
|
-
ts.factory.createQualifiedName(
|
|
193
|
-
ts.factory.createIdentifier("ILlmApplication"),
|
|
194
|
-
ts.factory.createIdentifier("IConfig"),
|
|
195
|
-
),
|
|
196
|
-
undefined,
|
|
197
|
-
false,
|
|
198
|
-
),
|
|
199
|
-
ts.factory.createUnionTypeNode([
|
|
200
|
-
ts.factory.createLiteralTypeNode(
|
|
201
|
-
ts.factory.createStringLiteral("validate"),
|
|
202
|
-
),
|
|
203
|
-
]),
|
|
204
|
-
],
|
|
205
|
-
),
|
|
206
|
-
],
|
|
207
|
-
);
|
|
208
|
-
return ts.factory.createObjectLiteralExpression(
|
|
209
|
-
[
|
|
210
|
-
ts.factory.createSpreadAssignment(
|
|
211
|
-
ts.factory.createSatisfiesExpression(
|
|
212
|
-
props.argument,
|
|
213
|
-
satisfiesTypeNode,
|
|
214
|
-
),
|
|
215
|
-
),
|
|
216
|
-
ts.factory.createPropertyAssignment(
|
|
217
|
-
"equals",
|
|
218
|
-
props.equals === true
|
|
219
|
-
? ts.factory.createTrue()
|
|
220
|
-
: ts.factory.createFalse(),
|
|
221
|
-
),
|
|
222
|
-
],
|
|
223
|
-
true,
|
|
224
|
-
);
|
|
225
|
-
};
|
|
226
89
|
}
|
|
@@ -1,81 +1,100 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
LlmApplicationProgrammer,
|
|
3
|
+
LlmControllerProgrammer,
|
|
4
|
+
LlmMetadataFactory,
|
|
5
|
+
MetadataCollection,
|
|
6
|
+
MetadataFactory,
|
|
7
|
+
MetadataSchema,
|
|
8
|
+
} from "@typia/core";
|
|
9
|
+
import { ILlmSchema, ValidationPipe } from "@typia/interface";
|
|
2
10
|
import ts from "typescript";
|
|
3
11
|
|
|
4
12
|
import { ITransformProps } from "../../ITransformProps";
|
|
5
13
|
import { TransformerError } from "../../TransformerError";
|
|
6
|
-
import { LlmApplicationTransformer } from "./LlmApplicationTransformer";
|
|
7
14
|
|
|
8
15
|
export namespace LlmControllerTransformer {
|
|
9
16
|
export const transform = (props: ITransformProps): ts.Expression => {
|
|
10
|
-
|
|
11
|
-
if (
|
|
12
|
-
else if (props.expression.arguments[0] === undefined)
|
|
17
|
+
// GET GENERIC ARGUMENT
|
|
18
|
+
if (!props.expression.typeArguments?.length)
|
|
13
19
|
throw new TransformerError({
|
|
14
|
-
code:
|
|
15
|
-
message:
|
|
20
|
+
code: "typia.llm.controller",
|
|
21
|
+
message: "no generic argument.",
|
|
16
22
|
});
|
|
17
|
-
|
|
23
|
+
const top: ts.Node = props.expression.typeArguments[0]!;
|
|
24
|
+
if (ts.isTypeNode(top) === false) return props.expression;
|
|
25
|
+
|
|
26
|
+
if (props.expression.arguments[0] === undefined)
|
|
27
|
+
throw new TransformerError({
|
|
28
|
+
code: "typia.llm.controller",
|
|
29
|
+
message: "no identifier name.",
|
|
30
|
+
});
|
|
31
|
+
if (props.expression.arguments[1] === undefined)
|
|
18
32
|
throw new TransformerError({
|
|
19
|
-
code:
|
|
20
|
-
message:
|
|
33
|
+
code: "typia.llm.controller",
|
|
34
|
+
message: "no executor.",
|
|
21
35
|
});
|
|
22
36
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
37
|
+
// GET CONFIG
|
|
38
|
+
const config:
|
|
39
|
+
| Partial<
|
|
40
|
+
ILlmSchema.IConfig & {
|
|
41
|
+
equals: boolean;
|
|
42
|
+
}
|
|
43
|
+
>
|
|
44
|
+
| undefined = LlmMetadataFactory.getConfig({
|
|
45
|
+
context: props.context,
|
|
46
|
+
method: "controller",
|
|
47
|
+
node: props.expression.typeArguments[1],
|
|
27
48
|
});
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
49
|
+
const type: ts.Type = props.context.checker.getTypeFromTypeNode(top);
|
|
50
|
+
|
|
51
|
+
// VALIDATE TYPE
|
|
52
|
+
const analyze = (validate: boolean): MetadataSchema => {
|
|
53
|
+
const result: ValidationPipe<MetadataSchema, MetadataFactory.IError> =
|
|
54
|
+
MetadataFactory.analyze({
|
|
55
|
+
checker: props.context.checker,
|
|
56
|
+
transformer: props.context.transformer,
|
|
57
|
+
options: {
|
|
58
|
+
absorb: validate,
|
|
59
|
+
escape: true,
|
|
60
|
+
constant: true,
|
|
61
|
+
functional: true,
|
|
62
|
+
validate:
|
|
63
|
+
validate === true
|
|
64
|
+
? (next) =>
|
|
65
|
+
LlmApplicationProgrammer.validate({
|
|
66
|
+
config,
|
|
67
|
+
metadata: next.metadata,
|
|
68
|
+
explore: next.explore,
|
|
69
|
+
top: next.top,
|
|
70
|
+
})
|
|
71
|
+
: undefined,
|
|
72
|
+
},
|
|
73
|
+
components: new MetadataCollection({
|
|
74
|
+
replace: MetadataCollection.replace,
|
|
75
|
+
}),
|
|
76
|
+
type,
|
|
77
|
+
});
|
|
78
|
+
if (result.success === false)
|
|
79
|
+
throw TransformerError.from({
|
|
80
|
+
code: "typia.llm.controller",
|
|
81
|
+
errors: result.errors,
|
|
82
|
+
});
|
|
83
|
+
return result.data;
|
|
84
|
+
};
|
|
85
|
+
analyze(true);
|
|
86
|
+
|
|
87
|
+
// GENERATE LLM CONTROLLER
|
|
88
|
+
return LlmControllerProgrammer.write({
|
|
89
|
+
context: props.context,
|
|
90
|
+
modulo: props.modulo,
|
|
91
|
+
metadata: analyze(false),
|
|
92
|
+
className: top.getFullText().trim(),
|
|
93
|
+
config,
|
|
94
|
+
node: top,
|
|
95
|
+
nameArgument: props.expression.arguments[0],
|
|
96
|
+
executeArgument: props.expression.arguments[1],
|
|
97
|
+
configArgument: props.expression.arguments[2],
|
|
32
98
|
});
|
|
33
|
-
const value: ts.ObjectLiteralExpression =
|
|
34
|
-
ts.factory.createObjectLiteralExpression(
|
|
35
|
-
[
|
|
36
|
-
ts.factory.createPropertyAssignment(
|
|
37
|
-
"protocol",
|
|
38
|
-
ts.factory.createStringLiteral("class"),
|
|
39
|
-
),
|
|
40
|
-
ts.factory.createPropertyAssignment(
|
|
41
|
-
"name",
|
|
42
|
-
props.expression.arguments[0],
|
|
43
|
-
),
|
|
44
|
-
ts.factory.createPropertyAssignment(
|
|
45
|
-
"execute",
|
|
46
|
-
props.expression.arguments[1],
|
|
47
|
-
),
|
|
48
|
-
ts.factory.createPropertyAssignment(
|
|
49
|
-
"application",
|
|
50
|
-
ts.factory.createCallExpression(
|
|
51
|
-
props.context.importer.internal("llmApplicationFinalize"),
|
|
52
|
-
undefined,
|
|
53
|
-
[
|
|
54
|
-
ts.factory.createAsExpression(
|
|
55
|
-
ts.factory.createSatisfiesExpression(
|
|
56
|
-
LiteralFactory.write(dec.application),
|
|
57
|
-
primitiveTypeNode,
|
|
58
|
-
),
|
|
59
|
-
primitiveTypeNode,
|
|
60
|
-
),
|
|
61
|
-
...(props.expression.arguments?.[2] !== undefined
|
|
62
|
-
? [
|
|
63
|
-
LlmApplicationTransformer.getConfigArgument({
|
|
64
|
-
context: props.context,
|
|
65
|
-
argument: props.expression.arguments[2],
|
|
66
|
-
equals: dec.config?.equals,
|
|
67
|
-
}),
|
|
68
|
-
]
|
|
69
|
-
: []),
|
|
70
|
-
],
|
|
71
|
-
),
|
|
72
|
-
),
|
|
73
|
-
],
|
|
74
|
-
true,
|
|
75
|
-
);
|
|
76
|
-
return ts.factory.createAsExpression(
|
|
77
|
-
ts.factory.createSatisfiesExpression(value, typeNode),
|
|
78
|
-
typeNode,
|
|
79
|
-
);
|
|
80
99
|
};
|
|
81
100
|
}
|