@lcap/nasl 3.7.0-beta.6 → 3.7.0-beta.8

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.
Files changed (58) hide show
  1. package/dist/package.json +1 -1
  2. package/out/concepts/ConnectorTrigger__.d.ts +18 -0
  3. package/out/concepts/ConnectorTrigger__.js +145 -0
  4. package/out/concepts/ConnectorTrigger__.js.map +1 -1
  5. package/out/concepts/Connector__.d.ts +1 -1
  6. package/out/concepts/Connector__.js +4 -1
  7. package/out/concepts/Connector__.js.map +1 -1
  8. package/out/concepts/TriggerLauncher__.js +2 -2
  9. package/out/concepts/TriggerLauncher__.js.map +1 -1
  10. package/out/config.d.ts +5 -0
  11. package/out/config.js +1 -0
  12. package/out/config.js.map +1 -1
  13. package/out/generator/genBundleFiles.d.ts +3 -0
  14. package/out/generator/genBundleFiles.js +19 -0
  15. package/out/generator/genBundleFiles.js.map +1 -1
  16. package/out/generator/release-body/body.d.ts +7 -1
  17. package/out/generator/release-body/body.js +66 -1
  18. package/out/generator/release-body/body.js.map +1 -1
  19. package/out/generator/release-body/data.js +10 -1
  20. package/out/generator/release-body/data.js.map +1 -1
  21. package/out/generator/release-body/internal.d.ts +9 -0
  22. package/out/generator/release-body/internal.js.map +1 -1
  23. package/out/generator/release-body/utils.d.ts +9 -2
  24. package/out/generator/release-body/utils.js +30 -5
  25. package/out/generator/release-body/utils.js.map +1 -1
  26. package/out/natural/index.d.ts +0 -4
  27. package/out/natural/index.js +0 -4
  28. package/out/natural/index.js.map +1 -1
  29. package/out/server/naslServer.js +2 -1
  30. package/out/server/naslServer.js.map +1 -1
  31. package/package.json +1 -1
  32. package/src/concepts/ConnectorTrigger__.ts +160 -0
  33. package/src/concepts/Connector__.ts +4 -1
  34. package/src/concepts/TriggerLauncher__.ts +2 -2
  35. package/src/config.ts +5 -0
  36. package/src/generator/genBundleFiles.ts +22 -0
  37. package/src/generator/release-body/body.ts +68 -1
  38. package/src/generator/release-body/data.ts +15 -4
  39. package/src/generator/release-body/internal.ts +10 -0
  40. package/src/generator/release-body/utils.ts +35 -8
  41. package/src/natural/index.ts +0 -4
  42. package/src/server/naslServer.ts +2 -0
  43. package/out/natural/prompt/analyzeClaims.d.ts +0 -1
  44. package/out/natural/prompt/analyzeClaims.js +0 -35
  45. package/out/natural/prompt/analyzeClaims.js.map +0 -1
  46. package/out/natural/prompt/analyzeFormatOutput.d.ts +0 -1
  47. package/out/natural/prompt/analyzeFormatOutput.js +0 -19
  48. package/out/natural/prompt/analyzeFormatOutput.js.map +0 -1
  49. package/out/natural/prompt/analyzeTasks.d.ts +0 -1
  50. package/out/natural/prompt/analyzeTasks.js +0 -21
  51. package/out/natural/prompt/analyzeTasks.js.map +0 -1
  52. package/out/natural/prompt/executeClaims.d.ts +0 -1
  53. package/out/natural/prompt/executeClaims.js +0 -81
  54. package/out/natural/prompt/executeClaims.js.map +0 -1
  55. package/src/natural/prompt/analyzeClaims.ts +0 -30
  56. package/src/natural/prompt/analyzeFormatOutput.ts +0 -14
  57. package/src/natural/prompt/analyzeTasks.ts +0 -16
  58. package/src/natural/prompt/executeClaims.ts +0 -77
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lcap/nasl",
3
3
  "description": "NetEase Application Specific Language",
4
- "version": "3.7.0-beta.6",
4
+ "version": "3.7.0-beta.8",
5
5
  "author": "Forrest <rainforest92@126.com>",
6
6
  "scripts": {
7
7
  "clear": "rimraf ./out",
@@ -4,7 +4,20 @@ import Frontend from './Frontend__';
4
4
  import ProcessElement from './ProcessElement__';
5
5
  import Process from './Process__';
6
6
  import Interface from './Interface__';
7
+ import Namespace from './Namespace__';
8
+ import Connector from './Connector__';
7
9
  import type InterfaceTriggerEvent from './InterfaceTriggerEvent__';
10
+ import { EmbeddedTSFileGenerator } from '../utils';
11
+ import { CUSTOM_CONNECTOR_EDITABLE_SUFFIX } from './basics/constants';
12
+ import {
13
+ TranslatorState,
14
+ shiftState,
15
+ withSourceMap,
16
+ createCompilerState,
17
+ withSourceMapGenerator,
18
+ withGenerator,
19
+ TranslatorGenerator,
20
+ } from '../translator';
8
21
  //================================================================================
9
22
  // 从这里开始到结尾注释之间的代码由 NASL Workbench 自动生成,请不手动修改!
10
23
  // ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
@@ -182,6 +195,153 @@ export class ConnectorTrigger extends BaseNode {
182
195
  // });
183
196
  this.app?.emit('collect:end');
184
197
  }
198
+ /**
199
+ * 祖先 Connector
200
+ */
201
+ get connector() {
202
+ return this.getAncestor('Connector') as Connector;
203
+ }
204
+
205
+ // 是否来自于 集成中心
206
+ get integration() {
207
+ return this.getAncestor('Integration');
208
+ }
209
+
210
+ @withSourceMapGenerator
211
+ *toEmbeddedTS(state = createCompilerState()): TranslatorGenerator {
212
+ const self = this;
213
+ let code = '';
214
+ code += `export function ${self.tsName} () {\n`;
215
+ try {
216
+ // code += ';\n';
217
+ code += '}\n';
218
+ } catch (error) {
219
+ console.error('找不到目标服务端逻辑', error);
220
+ }
221
+ return code;
222
+ }
223
+
224
+ *toEmbeddedTSFile(): EmbeddedTSFileGenerator {
225
+ let code = `namespace ${this.getTsNamespace()} {\n`;
226
+ const state = createCompilerState(code, { tabSize: 1 });
227
+ try {
228
+ code += yield* this.toEmbeddedTS(state);
229
+ } catch (err) {
230
+ code += '';
231
+ console.log(err);
232
+ }
233
+ code += '}\n';
234
+
235
+ return {
236
+ code,
237
+ filePath: this.getEmbeddedFilePath(),
238
+ sourceMap: state.sourceMap,
239
+ };
240
+ }
241
+
242
+ getTsNamespace() {
243
+ if (this.parentNode?.concept === 'Connector') {
244
+ return `connector.${this.parentNode.tsName}.triggers`;
245
+ }
246
+ }
247
+
248
+ get tsName(): string {
249
+ const excludeds = [
250
+ 'abstract',
251
+ 'arguments',
252
+ 'await',
253
+ 'boolean',
254
+ 'break',
255
+ 'byte',
256
+ 'case',
257
+ 'catch',
258
+ 'char',
259
+ 'class',
260
+ 'const',
261
+ 'continue',
262
+ 'debugger',
263
+ 'default',
264
+ 'delete',
265
+ 'do',
266
+ 'double',
267
+ 'decimal',
268
+ 'else',
269
+ 'enum',
270
+ 'eval',
271
+ 'export',
272
+ 'extends',
273
+ 'false',
274
+ 'final',
275
+ 'finally',
276
+ 'float',
277
+ 'for',
278
+ 'function',
279
+ 'goto',
280
+ 'if',
281
+ 'implements',
282
+ 'import',
283
+ 'in',
284
+ 'instanceof',
285
+ 'int',
286
+ 'interface',
287
+ 'let',
288
+ 'long',
289
+ 'native',
290
+ 'new',
291
+ 'null',
292
+ 'package',
293
+ 'private',
294
+ 'protected',
295
+ 'public',
296
+ 'return',
297
+ 'short',
298
+ 'static',
299
+ 'super',
300
+ 'switch',
301
+ 'synchronized',
302
+ 'this',
303
+ 'throw',
304
+ 'throws',
305
+ 'transient',
306
+ 'true',
307
+ 'try',
308
+ 'typeof',
309
+ 'var',
310
+ 'void',
311
+ 'volatile',
312
+ 'while',
313
+ 'with',
314
+ 'yield,as',
315
+ 'any',
316
+ 'number',
317
+ 'string',
318
+ 'get',
319
+ 'type',
320
+ 'typeof',
321
+ 'instanceof',
322
+ 'require',
323
+ ];
324
+ if (excludeds.includes(this.name)) {
325
+ return `_${this.name}`;
326
+ }
327
+ // 来自集成中心,且是连接内部的逻辑,则认为是编辑态的,需要加上后缀
328
+ if (this.connector && this.integration) {
329
+ return `${this.name}${CUSTOM_CONNECTOR_EDITABLE_SUFFIX}`;
330
+ }
331
+ return this.name;
332
+ }
333
+
334
+ /**
335
+ * 生成宿主语言的文件路径
336
+ * @param name 一般不用传,用于 rename
337
+ */
338
+ getEmbeddedFilePath(name = this.name) {
339
+ // 自定义连接器 编辑态文件对应parentKey 为 connectors,
340
+
341
+ if (this.parentNode.concept === 'Connector') {
342
+ return `/embedded/${this.app.name}/${this.parentNode.parentKey}/${this.parentNode.name}/triggers/${name}.ts`;
343
+ }
344
+ }
185
345
 
186
346
  //================================================================================
187
347
  // 从这里开始到结尾注释之间的代码由 NASL Workbench 自动生成,请不手动修改!
@@ -1215,7 +1215,10 @@ export class Connector extends Module {
1215
1215
  name: namespace.name,
1216
1216
  expanded: true,
1217
1217
  unselectable: true, // 自定义属性。用于标注当前选项是否可以被选择
1218
- children: namespace.logics,
1218
+ children: namespace.logics?.map((logic: any) => {
1219
+ logic._exName = `${namespace.name}_${logic.name}`;
1220
+ return logic;
1221
+ }),
1219
1222
  };
1220
1223
  });
1221
1224
  }
@@ -167,6 +167,7 @@ export class TriggerLauncher extends BaseNode {
167
167
  // 仅仅作引用查找不需要入参校验
168
168
  if (self.concept === 'ConnectorTriggerLauncher') {
169
169
  const connectorTrigger = (self as unknown as ConnectorTriggerLauncher).connectorTrigger
170
+ code += `let trigger = connector.${(self as unknown as ConnectorTriggerLauncher).connector.name}.triggers.${connectorTrigger.tsName};\n`
170
171
  let stashParams = ''
171
172
  if (connectorTrigger?.triggerEvent?.callBackLogic?.typeArguments?.[0]) {
172
173
  stashParams = 'params'
@@ -179,9 +180,8 @@ export class TriggerLauncher extends BaseNode {
179
180
  }
180
181
  code += ` = ${self.callBackLogicKey}(${stashParams})`;
181
182
  } else {
182
- code += `${self.callBackLogicKey}`;
183
+ code += `${self.callBackLogicKey};\n`;
183
184
  }
184
- code += ';\n';
185
185
  code += '}\n';
186
186
  } catch (error) {
187
187
  console.error('找不到目标服务端逻辑', error);
package/src/config.ts CHANGED
@@ -31,6 +31,11 @@ export const config = {
31
31
  * 使用场景:导出源码
32
32
  */
33
33
  frontendPackagesResource: [] as {path: string, isDir: boolean, url: string}[],
34
+ assets: [] as Array<{
35
+ path: string,
36
+ isDir: boolean,
37
+ url: string;
38
+ }>,
34
39
  };
35
40
 
36
41
  /* eslint-disable no-redeclare */
@@ -11,6 +11,7 @@ import { compileComponent } from './compileComponent';
11
11
 
12
12
  import { genMetaData } from './genMetaData';
13
13
  import { integrateMicroApp } from './microApp';
14
+ import type { Asset } from './release-body/internal';
14
15
 
15
16
  export interface Route {
16
17
  path?: string;
@@ -38,6 +39,8 @@ interface Config {
38
39
  miniEnable: boolean;
39
40
  isPreviewFe?: boolean;
40
41
  previewVersion?: string;
42
+ assets: Array<Asset>;
43
+ assetsMap: Map<string, Asset>;
41
44
  }
42
45
 
43
46
  // 将metaData转成字符串
@@ -772,6 +775,25 @@ export function genBundleFiles(app: App, frontend: Frontend, config: Config) {
772
775
  ${microAppIntegration || 'loadAssets();'}
773
776
  })()
774
777
  `;
778
+ const assets = config.assets;
779
+ // 导出源码才处理
780
+ if (config.isExport && Array.isArray(assets) && assets.length) {
781
+ const assetsMap = config.assetsMap;
782
+ const regex = new RegExp(assets.map((asset) => asset.fileUrl).join("|"), "g");
783
+ content = content.replace(regex, (url) => {
784
+ const asset = assetsMap.get(url);
785
+ if (asset) {
786
+ const path = `/assets/${asset.name}`;
787
+ globalConfig.assets.push({
788
+ path,
789
+ isDir: false,
790
+ url,
791
+ });
792
+ return path;
793
+ }
794
+ return url;
795
+ });
796
+ }
775
797
  let minifyObj = { code: '' };
776
798
  // 开发环境加上sourceMap
777
799
  if (config.env === 'dev') {
@@ -10,6 +10,39 @@ import { genPermissionData, genLogicAuthFlag } from '../permission';
10
10
  import { getCallLogicData } from './validation';
11
11
 
12
12
  import * as utils from '../../utils';
13
+ import { config as globalConfig } from '../../config'
14
+
15
+ /**
16
+ * 替换端类型中的资源
17
+ * @param frontendTypes
18
+ * @param fn
19
+ */
20
+ export function replaceFrontendTypesAssets(frontendTypes: FrontendType[], fn: Function) {
21
+ frontendTypes.forEach((frontendType: FrontendType) => {
22
+ utils.traverse((current: {
23
+ node: any
24
+ }) => {
25
+ for (const key in current.node) {
26
+ const attr = current.node[key];
27
+ if (typeof attr === 'string') {
28
+ fn(current.node, key, attr);
29
+ }
30
+ }
31
+ }, { node: frontendType }, {
32
+ mode: 'anyObject', excludedKeySet: new Set([
33
+ 'parentNode',
34
+ 'sourceMap',
35
+ 'storageJSON',
36
+ 'tsErrorDetail',
37
+ 'NaslAnnotatedJSON',
38
+ 'calledFrom',
39
+ '_events',
40
+ '_collectingList',
41
+ '_historyList',
42
+ ])
43
+ });
44
+ });
45
+ }
13
46
 
14
47
  async function getNaslAnnotatedJSON(app: App, opt: InternalReleaseData) {
15
48
  await utils.delay(500);
@@ -35,6 +68,40 @@ async function getNaslAnnotatedJSON(app: App, opt: InternalReleaseData) {
35
68
  });
36
69
  }
37
70
 
71
+ const assets = opt.assets;
72
+ if (Array.isArray(assets) && assets.length) {
73
+ const assetsMap = opt.assetsMap;
74
+ const regex = new RegExp(assets.map((asset) => asset.fileUrl).join("|"), "g");
75
+ replaceFrontendTypesAssets(NaslAnnotatedJSON.frontendTypes, (node: any, key: string, url: string) => {
76
+ if (['staticStyle'].includes(key)) {
77
+ node[key] = url.replace(regex, (url) => {
78
+ const asset = assetsMap.get(url);
79
+ if (asset) {
80
+ const path = `/assets/${asset.name}`;
81
+ globalConfig.assets.push({
82
+ path,
83
+ isDir: false,
84
+ url,
85
+ });
86
+ return path;
87
+ }
88
+ return url;
89
+ });
90
+ } else {
91
+ const asset = assetsMap.get(url);
92
+ if (asset) {
93
+ const path = `/assets/${asset.name}`;
94
+ globalConfig.assets.push({
95
+ path,
96
+ isDir: false,
97
+ url,
98
+ });
99
+ node[key] = path;
100
+ }
101
+ }
102
+ });
103
+ }
104
+
38
105
  return {
39
106
  name: 'nasl-annotated.json',
40
107
  content: JSON.stringify(NaslAnnotatedJSON),
@@ -77,7 +144,7 @@ async function mergeBodyData(app: App, opt: InternalReleaseData) {
77
144
  await utils.delay(500);
78
145
 
79
146
  const authReport: ReturnType<typeof getAuthReport> = getAuthReport(app, opt.frontends);
80
- await opt.logPublishFunc?.('权限', '分析权限数据成功!');
147
+ await opt.logPublishFunc?.('权限', '分析权限数据成功!');
81
148
  const logicPageResourceDtoList = await genPermissionData(app);
82
149
  const allFrontends = getFrontendByTypes(app?.frontendTypes);
83
150
  const releaseFrontends = allFrontends.map((frontend: Frontend) => ({
@@ -1,9 +1,10 @@
1
1
  import type { App } from '../../concepts';
2
2
  import { ReleaseData, ReleaseMode } from './types';
3
3
  import type { NaslServer } from '../../server/naslServer';
4
- import type { InternalReleaseData } from './internal';
4
+ import type { InternalReleaseData, Asset } from './internal';
5
5
  import { genReleaseBody } from './body';
6
6
  import {
7
+ loadFiles,
7
8
  staticResourceSync,
8
9
  getContentType,
9
10
  getPackageInfos,
@@ -13,12 +14,13 @@ import {
13
14
  getValidationRules,
14
15
  } from './utils';
15
16
  import { Logger, File } from '../../utils';
17
+ import { config as globalConfig } from '../../config'
16
18
 
17
19
  export async function getReleaseData(app: App, data: ReleaseData, naslServer: NaslServer, inputLogger?: Logger) {
18
20
  const { http, logger: defaultLogger } = naslServer;
19
21
  const logger = inputLogger ?? defaultLogger;
20
22
  defaultLogger.time('前端生成器发布');
21
- const appInfo = await getAppInfo(http, data);
23
+ const appInfo = await getAppInfo(http, data);
22
24
  await logger.info('构建环境', '获取环境信息成功');
23
25
  const { version, fullVersion, dependencies } = await getVersionDetail(http, app);
24
26
  await logger.info('构建环境', '获取版本数据成功');
@@ -27,6 +29,13 @@ export async function getReleaseData(app: App, data: ReleaseData, naslServer: Na
27
29
  const releaseFrontends = inputFrontendNames.length > 0
28
30
  ? allFrontend.filter((item) => data.config.frontendNames.includes(item.name))
29
31
  : allFrontend;
32
+ // 当前应用使用到的资源
33
+ const assets = await loadFiles(http, data.appId);
34
+ const assetsMap = new Map();
35
+ assets.forEach((asset: Asset) => {
36
+ const { fileUrl } = asset;
37
+ assetsMap.set(fileUrl, asset);
38
+ });
30
39
  const result: InternalReleaseData = {
31
40
  appInfo: appInfo as any,
32
41
  env: data.env,
@@ -41,6 +50,8 @@ export async function getReleaseData(app: App, data: ReleaseData, naslServer: Na
41
50
  appSpecification: data.appSpecification,
42
51
  frontends: releaseFrontends,
43
52
  validations: {},
53
+ assets,
54
+ assetsMap,
44
55
  logPublishFunc: (text: string) => logger.info('前端生成器', text),
45
56
  };
46
57
 
@@ -52,7 +63,7 @@ export async function getReleaseData(app: App, data: ReleaseData, naslServer: Na
52
63
 
53
64
  // 私有化环境,需要同步资源;内部环境暂不需要,针对使用 CDN 场景增加判断
54
65
  if (String(appInfo.isPrivatized) === 'true') {
55
- result.staticUrl = await staticResourceSync(http, data.appId, data.env, releaseFrontends);
66
+ result.staticUrl = await staticResourceSync(http, assets, data.appId, data.env, releaseFrontends);
56
67
  await logger.info('构建环境', '私有化部署同步资源成功');
57
68
  }
58
69
 
@@ -85,7 +96,7 @@ export function getReleaseFormData(body: any) {
85
96
  const formData = new FormData();
86
97
 
87
98
  if (!body.isPreviewFe) {
88
- body.files = body.files.map(
99
+ body.files = body.files.map(
89
100
  (item: any) => new File([item.content], item.name, { type: getContentType(item.name) })
90
101
  ) as any;
91
102
  }
@@ -8,6 +8,14 @@ export interface ServerValidationData {
8
8
 
9
9
  export type InputServerValidationData = { [key in string]: ServerValidationData[] };
10
10
 
11
+ export interface Asset {
12
+ name: string;
13
+ type: string;
14
+ subType: string;
15
+ fileUrl: string;
16
+ contentType: string;
17
+ }
18
+
11
19
  /** @internal */
12
20
  export interface InternalReleaseData {
13
21
  env: string;
@@ -36,6 +44,8 @@ export interface InternalReleaseData {
36
44
  validations: InputServerValidationData;
37
45
  logPublishFunc: Function;
38
46
  appSpecification?: number;
47
+ assets: Array<Asset>;
48
+ assetsMap: Map<string, Asset>;
39
49
  }
40
50
 
41
51
  /** @internal */
@@ -10,7 +10,7 @@ import type {
10
10
  import { AxiosInstance } from 'axios';
11
11
  import * as asserts from '../../concepts/utils/asserts';
12
12
  import { ReleaseData, ReleaseMode } from './types';
13
- import { HttpData, VersionDetail, MaterialData, EnvData, TenantData, AppDetailData } from './internal';
13
+ import { HttpData, VersionDetail, MaterialData, EnvData, TenantData, AppDetailData, Asset } from './internal';
14
14
 
15
15
  /**
16
16
  * 权限上报数据
@@ -115,13 +115,24 @@ export function getFrontendByTypes(frontendTypes: FrontendType[] = []) {
115
115
  return (frontendTypes?.map((frontendType) => (frontendType?.frontends || [])) || []).flat(2);
116
116
  }
117
117
 
118
- export async function getUsedAssets(axios: AxiosInstance, id: string, frontends: Frontend[]) {
118
+ /**
119
+ * 当前应用使用到的资源
120
+ * @param axios
121
+ * @param id
122
+ * @returns
123
+ */
124
+ export async function loadFiles(axios: AxiosInstance, id: string) {
119
125
  const { data: res } = await axios.get('/api/v1/user/file', {
120
- params: {
121
- appId: id,
122
- },
126
+ params: {
127
+ appId: id,
128
+ },
123
129
  });
124
130
  const assets = (res as any).result?.list || [];
131
+ return assets;
132
+ }
133
+
134
+ export async function getUsedAssets(axios: AxiosInstance, id: string, frontends: Frontend[]) {
135
+ const assets = await loadFiles(axios, id);
125
136
  const urlNameMap: Record<string, string> = {};
126
137
  const assetSet = new Set<string>();
127
138
 
@@ -141,13 +152,29 @@ export async function getUsedAssets(axios: AxiosInstance, id: string, frontends:
141
152
  return Array.from(assetSet);
142
153
  }
143
154
 
144
- export async function staticResourceSync(axios: AxiosInstance, id: string, env: string, frontends: Frontend[]) {
155
+ export async function staticResourceSync(axios: AxiosInstance, assets: Array<Asset>, id: string, env: string, frontends: Frontend[]) {
156
+ const urlNameMap: Record<string, string> = {};
157
+ const assetSet = new Set<string>();
158
+
159
+ for (const { fileUrl, name } of assets) {
160
+ urlNameMap[fileUrl] = name;
161
+ }
162
+
163
+ frontends.forEach((frontend) => {
164
+ frontend.views.forEach((view) => {
165
+ view.traverseStrictChildren((ele) => {
166
+ if (asserts.isBindAttribute(ele) && urlNameMap[ele.value]) {
167
+ assetSet.add(urlNameMap[ele.value]);
168
+ }
169
+ });
170
+ });
171
+ });
145
172
  // 发起资源同步请求,传递nasl使用到的资源名称
146
- const assets = await getUsedAssets(axios, id, frontends);
173
+ const needSyncResourceNameList = Array.from(assetSet);
147
174
  const { data: res } = await axios.post(
148
175
  '/api/v1/app/env/staticResourceSync',
149
176
  {
150
- needSyncResourceNameList: assets,
177
+ needSyncResourceNameList,
151
178
  },
152
179
  {
153
180
  params: {
@@ -1,7 +1,3 @@
1
1
  export * from './genNaturalTS';
2
2
  export * from './transformTSCode';
3
- export * from './prompt/executeClaims';
4
- export * from './prompt/analyzeClaims';
5
- export * from './prompt/analyzeFormatOutput';
6
- export * from './prompt/analyzeTasks';
7
3
 
@@ -537,6 +537,7 @@ class NaslServer {
537
537
 
538
538
  const {
539
539
  namespaces = [],
540
+ triggers = [],
540
541
  } = module as Connector;
541
542
 
542
543
  const {
@@ -586,6 +587,7 @@ class NaslServer {
586
587
  yield* getTsFiles(triggerLaunchers, 'triggerLauncher');
587
588
  // yield* getTsFiles(authLogicsForCallInterface, 'authLogicForCallInterface');
588
589
  yield* getTsFiles(concat(namespaces, 'logics'), 'namespaces_logic');
590
+ yield* getTsFiles(triggers, 'connectorTrigger');
589
591
  }
590
592
 
591
593
  if (module instanceof App) {
@@ -1 +0,0 @@
1
- export declare const analyzeClaims: (params: any) => any;
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.analyzeClaims = void 0;
4
- const analyzeClaims = (params) => {
5
- const { logicType } = params;
6
- const claims = `
7
- - Knowledge 是你的知识库,你可以参考,但是你最终制定的计划中禁止包含方法或者函数名
8
- - requiredIndexes 用于下一步的具体实施,需要尽可能详细的返回所有和执行计划相关的模块或方法索引
9
- - 如果用户没有特别指明是打印(日志/输出结果),"输出结果"一律按照"返回输出结果"处理
10
- - 涉及到查询、获取数据时,先查找当前上下文[6/7/8/9]中是否有相关的方法,如果没有,再考虑实体的方法
11
- - 实体的 get 方法一次只能获取一条数据,返回一个对象,无法返回列表。
12
- - 如果用户的需求涉及定时或延时等操作,请提示用户:当前暂不支持定时或延时操作,请调整后重新输入。
13
- - 如果用户的需求需要调用某个方法并且当前上下文中不存在时,请提示用户:当前应用中暂无该方法,请先导入相关依赖库或连接器模块
14
- - 例如:加解密依赖库中的方法
15
- `;
16
- // global_logic、view_logic、event_logic、business_Logic
17
- const claimsMap = {
18
- global_logic: `
19
- - Knowledge 是你的知识库,你可以参考,但是你最终制定的计划中禁止包含方法或者函数名
20
- - requiredIndexes 用于下一步的具体实施,需要尽可能详细的返回所有和执行计划相关的模块或方法索引
21
- - 如果用户没有特别指明是打印(日志/输出结果),"输出结果"一律按照"返回输出结果"处理
22
- - 如果用户的需求涉及定时或延时等操作,请提示用户:当前暂不支持定时或延时操作,请调整后重新输入。
23
- - 如果用户的需求需要调用某个方法并且当前上下文中不存在时,请提示用户:当前应用中暂无该方法,请先导入相关依赖库或连接器模块
24
- - 例如:加解密依赖库中的方法
25
- - 当前逻辑类型下暂不支持跳转页面功能,请提示用户: 如果需要跳转页面,请切换到前端页面逻辑或事件逻辑。
26
- - 当前逻辑类型下暂不支持弹出消息/弹窗消息功能,请提示用户: 当前逻辑类型暂不支持此功能。
27
- - 分析用户的需求,当需要从实体中获取或者查询数据时
28
- - 优先使用 SQL 的查询和数据操纵能力: 例如 JOIN、SUM、GROUP_BY 等能力
29
- - 使用 SQL 语句同时实现查询和计算
30
- `
31
- };
32
- return claimsMap?.[logicType] || claims;
33
- };
34
- exports.analyzeClaims = analyzeClaims;
35
- //# sourceMappingURL=analyzeClaims.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"analyzeClaims.js","sourceRoot":"","sources":["../../../src/natural/prompt/analyzeClaims.ts"],"names":[],"mappings":";;;AAAO,MAAM,aAAa,GAAG,CAAC,MAAW,EAAE,EAAE;IAC3C,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;IAC7B,MAAM,MAAM,GAAG;;;;;;;;;CAShB,CAAC;IACA,qDAAqD;IACrD,MAAM,SAAS,GAAG;QAChB,YAAY,EAAE;;;;;;;;;;;;CAYjB;KACS,CAAC;IACT,OAAO,SAAS,EAAE,CAAC,SAAS,CAAC,IAAI,MAAM,CAAC;AAC1C,CAAC,CAAC;AA7BW,QAAA,aAAa,iBA6BxB"}
@@ -1 +0,0 @@
1
- export declare const analyzeFormatOutput: () => string;
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.analyzeFormatOutput = void 0;
4
- const analyzeFormatOutput = () => {
5
- return `\`\`\`json
6
- {
7
- "action": "Final Answer",
8
- "action_input": {
9
- "plan": ["plans"],
10
- "text": "question",
11
- "executable": boolean,
12
- "requiredIndexes": [index],
13
- "needQueryRepository": boolean
14
- }
15
- }
16
- \`\`\``;
17
- };
18
- exports.analyzeFormatOutput = analyzeFormatOutput;
19
- //# sourceMappingURL=analyzeFormatOutput.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"analyzeFormatOutput.js","sourceRoot":"","sources":["../../../src/natural/prompt/analyzeFormatOutput.ts"],"names":[],"mappings":";;;AAAO,MAAM,mBAAmB,GAAG,GAAG,EAAE;IACtC,OAAO;;;;;;;;;;;OAWF,CAAC;AACR,CAAC,CAAC;AAbW,QAAA,mBAAmB,uBAa9B"}
@@ -1 +0,0 @@
1
- export declare const analyzeTasks: () => string;
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.analyzeTasks = void 0;
4
- const analyzeTasks = () => {
5
- return `
6
- - plan:
7
- - 尽可能的帮助用户将需求梳理成可执行的计划,计划包含多个任务,每个任务下可能包含多个子任务(会缩进 4 个空格)
8
- - 当前逻辑和当前位置是制定计划的重要参考依据之一,你需要在当前逻辑的基础上, 为用户制定计划, 只做用户需要的部分
9
- - 制定的计划最终将会作为调用代码补全接口的输入, 所以你需要考虑计划内容是否完整与充分, 如果不充分,你可以继续询问用户
10
- - text: 如果你认为需求不够明确时,可以继续询问用户需求的细节,不可为空
11
- - executable
12
- - 类型为 boolean, 如果你认为需求比较明确并且 plan 可执行, 返回 true, 否则返回 false
13
- - requiredIndexes
14
- - 类型为 Array, 你需要根据用户的执行计划,从 Context Definition 中整理出执行需要用到的模块或者方法,返回对应的索引
15
- - 用于下一步的具体实施,需要尽可能详细的返回所有和执行计划相关的模块或方法索引。例如:"requiredIndexes": ['1','6-3','8-1-1-0']。
16
- - needQueryRepository
17
- - 类型为 boolean, 如果你认为需求相关的上下文信息不足,需要另外查询知识库时, 返回 true, 否则返回 false
18
- `;
19
- };
20
- exports.analyzeTasks = analyzeTasks;
21
- //# sourceMappingURL=analyzeTasks.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"analyzeTasks.js","sourceRoot":"","sources":["../../../src/natural/prompt/analyzeTasks.ts"],"names":[],"mappings":";;;AAAO,MAAM,YAAY,GAAG,GAAG,EAAE;IAC/B,OAAO;;;;;;;;;;;;;CAaR,CAAC;AACF,CAAC,CAAC;AAfW,QAAA,YAAY,gBAevB"}
@@ -1 +0,0 @@
1
- export declare const executeClaims: (params: any) => any;