@lowgular/code-graph 0.0.1 → 0.1.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.
Files changed (155) hide show
  1. package/bin/cli.js +2463 -0
  2. package/lib.js +2430 -0
  3. package/package.json +26 -7
  4. package/apps/code-graph/src/main.js +0 -50
  5. package/libs/cli/code-graph/src/index.js +0 -39
  6. package/libs/cli/code-graph/src/lib/class-declarations/abstractions/service.js +0 -72
  7. package/libs/cli/code-graph/src/lib/class-declarations/abstractions/service.stateful.js +0 -68
  8. package/libs/cli/code-graph/src/lib/class-declarations/class-declarations.doc.js +0 -147
  9. package/libs/cli/code-graph/src/lib/class-declarations/class-declarations.graph.js +0 -55
  10. package/libs/cli/code-graph/src/lib/class-declarations/index.js +0 -27
  11. package/libs/cli/code-graph/src/lib/code.graph.factory.js +0 -63
  12. package/libs/cli/code-graph/src/lib/code.graph.js +0 -62
  13. package/libs/cli/code-graph/src/lib/core/core.js +0 -58
  14. package/libs/cli/code-graph/src/lib/core.js +0 -85
  15. package/libs/cli/code-graph/src/lib/decorators/index.js +0 -36
  16. package/libs/cli/code-graph/src/lib/docs/index.js +0 -21
  17. package/libs/cli/code-graph/src/lib/docs/specs.js +0 -36
  18. package/libs/cli/code-graph/src/lib/expressions/call-expressions.graph.js +0 -28
  19. package/libs/cli/code-graph/src/lib/fixtures/reactive-event-bus/src/app/examples.event-bus.js +0 -53
  20. package/libs/cli/code-graph/src/lib/method-declarations/index.js +0 -23
  21. package/libs/cli/code-graph/src/lib/method-declarations/method-declarations.doc.js +0 -106
  22. package/libs/cli/code-graph/src/lib/method-declarations/method-declarations.graph.js +0 -56
  23. package/libs/cli/code-graph/src/lib/parameters/index.js +0 -42
  24. package/libs/cli/code-graph/src/lib/property-declarations/abstractions/reactive-state.evals.js +0 -139
  25. package/libs/cli/code-graph/src/lib/property-declarations/abstractions/reactive-state.js +0 -104
  26. package/libs/cli/code-graph/src/lib/property-declarations/index.js +0 -25
  27. package/libs/cli/code-graph/src/lib/property-declarations/property-declarations.doc.js +0 -74
  28. package/libs/cli/code-graph/src/lib/property-declarations/property-declarations.graph.js +0 -43
  29. package/libs/cli/code-graph/src/lib/tools/index.js +0 -34
  30. package/libs/cli/code-graph/src/lib/tools/match-code-graph.tool.js +0 -64
  31. package/libs/cli/code-graph/src/lib/types/index.js +0 -99
  32. package/libs/cli/code-graph/src/lib/v2/extractors/extractor.doc.js +0 -345
  33. package/libs/cli/code-graph/src/lib/v2/extractors/extractor.js +0 -52
  34. package/libs/cli/code-graph/src/lib/v2/extractors/index.js +0 -23
  35. package/libs/cli/code-graph/src/lib/v2/graph-builder/code-graph.builder.js +0 -76
  36. package/libs/cli/code-graph/src/lib/v2/graph-builder/index.js +0 -21
  37. package/libs/cli/code-graph/src/lib/v2/graph-builder/node.processor.js +0 -48
  38. package/libs/cli/code-graph/src/lib/v2/graph-builder/relationship.processor.js +0 -79
  39. package/libs/cli/code-graph/src/lib/v2/graph-builder/type.processor.js +0 -45
  40. package/libs/cli/code-graph/src/lib/v2/index.js +0 -37
  41. package/libs/cli/code-graph/src/lib/v2/tools/build-code-graph.doc.js +0 -220
  42. package/libs/cli/code-graph/src/lib/v2/tools/build-code-graph.tool.js +0 -42
  43. package/libs/cli/cypher/src/index.js +0 -25
  44. package/libs/cli/cypher/src/lib/docs/features/advanced-optional-match.feature.js +0 -277
  45. package/libs/cli/cypher/src/lib/docs/features/anonymous-relationship.feature.js +0 -69
  46. package/libs/cli/cypher/src/lib/docs/features/anonymous-variable-length.feature.js +0 -105
  47. package/libs/cli/cypher/src/lib/docs/features/basic-filtering.feature.js +0 -70
  48. package/libs/cli/cypher/src/lib/docs/features/basic-optional-match.feature.js +0 -99
  49. package/libs/cli/cypher/src/lib/docs/features/basic-relationship.feature.js +0 -125
  50. package/libs/cli/cypher/src/lib/docs/features/index.js +0 -51
  51. package/libs/cli/cypher/src/lib/docs/features/limit.feature.js +0 -50
  52. package/libs/cli/cypher/src/lib/docs/features/match-nodes.feature.js +0 -106
  53. package/libs/cli/cypher/src/lib/docs/features/multiple-relationship-types.feature.js +0 -105
  54. package/libs/cli/cypher/src/lib/docs/features/order-by.feature.js +0 -143
  55. package/libs/cli/cypher/src/lib/docs/features/property-matching.feature.js +0 -152
  56. package/libs/cli/cypher/src/lib/docs/features/relationship-without-variable.feature.js +0 -48
  57. package/libs/cli/cypher/src/lib/docs/features/return-statement.feature.js +0 -65
  58. package/libs/cli/cypher/src/lib/docs/features/unidirected-relationship.feature.js +0 -82
  59. package/libs/cli/cypher/src/lib/docs/features/variable-length-path.feature.js +0 -136
  60. package/libs/cli/cypher/src/lib/docs/features/where-conditional.feature.js +0 -187
  61. package/libs/cli/cypher/src/lib/docs/features/where-operators.feature.js +0 -302
  62. package/libs/cli/cypher/src/lib/docs/prompts.js +0 -36
  63. package/libs/cli/cypher/src/lib/docs/specs.js +0 -181
  64. package/libs/cli/cypher/src/lib/executor/condition-evaluator.js +0 -158
  65. package/libs/cli/cypher/src/lib/executor/executor.js +0 -83
  66. package/libs/cli/cypher/src/lib/executor/graph.js +0 -15
  67. package/libs/cli/cypher/src/lib/executor/match-engine.js +0 -153
  68. package/libs/cli/cypher/src/lib/executor/pattern-matcher.js +0 -109
  69. package/libs/cli/cypher/src/lib/executor/relationship-navigator.js +0 -64
  70. package/libs/cli/cypher/src/lib/executor/result-formatter.js +0 -143
  71. package/libs/cli/cypher/src/lib/executor/traverse-engine.js +0 -164
  72. package/libs/cli/cypher/src/lib/executor/utils.js +0 -37
  73. package/libs/cli/cypher/src/lib/graph.stub.js +0 -63
  74. package/libs/cli/cypher/src/lib/index.js +0 -74
  75. package/libs/cli/cypher/src/lib/lexer.js +0 -398
  76. package/libs/cli/cypher/src/lib/parser.js +0 -602
  77. package/libs/cli/cypher/src/lib/validator/query-validator.js +0 -95
  78. package/libs/cli/cypher/src/lib/validator/supported-features.config.js +0 -111
  79. package/libs/cli/cypher/src/lib/validator/unsupported-features.config.js +0 -150
  80. package/libs/cli/shared/src/index.js +0 -53
  81. package/libs/cli/shared/src/lib/admin-token.js +0 -121
  82. package/libs/cli/shared/src/lib/config.js +0 -49
  83. package/libs/cli/shared/src/lib/consts.js +0 -57
  84. package/libs/cli/shared/src/lib/core.js +0 -46
  85. package/libs/cli/shared/src/lib/infrastructure/cli.js +0 -47
  86. package/libs/cli/shared/src/lib/infrastructure/config.js +0 -47
  87. package/libs/cli/shared/src/lib/infrastructure/config.reporitory.js +0 -51
  88. package/libs/cli/shared/src/lib/infrastructure/formatters/console-formatter.js +0 -96
  89. package/libs/cli/shared/src/lib/infrastructure/formatters/index.js +0 -41
  90. package/libs/cli/shared/src/lib/infrastructure/formatters/json-formatter.js +0 -64
  91. package/libs/cli/shared/src/lib/infrastructure/formatters/markdown-formatter.js +0 -120
  92. package/libs/cli/shared/src/lib/infrastructure/formatters/types.js +0 -15
  93. package/libs/cli/shared/src/lib/infrastructure/formatters/utils.js +0 -72
  94. package/libs/cli/shared/src/lib/infrastructure/git.js +0 -147
  95. package/libs/cli/shared/src/lib/infrastructure/http.js +0 -257
  96. package/libs/cli/shared/src/lib/infrastructure/markdown.js +0 -95
  97. package/libs/cli/shared/src/lib/infrastructure/transformers/embeddings.js +0 -88
  98. package/libs/cli/shared/src/lib/infrastructure/transformers/index.js +0 -25
  99. package/libs/cli/shared/src/lib/infrastructure/transformers/rag-eval.js +0 -154
  100. package/libs/cli/shared/src/lib/infrastructure/transformers/similarity.js +0 -210
  101. package/libs/cli/shared/src/lib/infrastructure/workspace.js +0 -297
  102. package/libs/cli/shared/src/lib/infrastructure/yaml.js +0 -237
  103. package/libs/cli/shared/src/lib/lowgular.config.js +0 -120
  104. package/libs/cli/shared/src/lib/token.js +0 -135
  105. package/libs/cli/shared/src/lib/utils/solution.util.js +0 -35
  106. package/libs/cli/shared/src/lib/utils/utils.js +0 -89
  107. package/libs/cli/typescript/src/index.js +0 -21
  108. package/libs/cli/typescript/src/lib/base/index.js +0 -23
  109. package/libs/cli/typescript/src/lib/base/nameable.js +0 -34
  110. package/libs/cli/typescript/src/lib/base/nodeable.js +0 -36
  111. package/libs/cli/typescript/src/lib/class.implementation.js +0 -52
  112. package/libs/cli/typescript/src/lib/core/declaration.registry.js +0 -107
  113. package/libs/cli/typescript/src/lib/core/design-pattern.js +0 -55
  114. package/libs/cli/typescript/src/lib/core/index.js +0 -35
  115. package/libs/cli/typescript/src/lib/core/navigable-declaration.js +0 -69
  116. package/libs/cli/typescript/src/lib/core/program-context.js +0 -71
  117. package/libs/cli/typescript/src/lib/core/syntax-kind.utils.js +0 -40
  118. package/libs/cli/typescript/src/lib/core/type.js +0 -374
  119. package/libs/cli/typescript/src/lib/declaration.abstraction.js +0 -90
  120. package/libs/cli/typescript/src/lib/decorator.implementation.js +0 -35
  121. package/libs/cli/typescript/src/lib/enum.implementation.js +0 -35
  122. package/libs/cli/typescript/src/lib/function-declaration.implementation.js +0 -35
  123. package/libs/cli/typescript/src/lib/index.js +0 -57
  124. package/libs/cli/typescript/src/lib/interface.implementation.js +0 -51
  125. package/libs/cli/typescript/src/lib/members/method-abstraction.resolver.js +0 -90
  126. package/libs/cli/typescript/src/lib/members/method-declaration.implementation.js +0 -44
  127. package/libs/cli/typescript/src/lib/members/method-signature.implementation.js +0 -46
  128. package/libs/cli/typescript/src/lib/members/method.util.js +0 -32
  129. package/libs/cli/typescript/src/lib/members/parameter.implementation.js +0 -38
  130. package/libs/cli/typescript/src/lib/members/property-declaration.implementation.js +0 -64
  131. package/libs/cli/typescript/src/lib/members/property-signature.implementation.js +0 -34
  132. package/libs/cli/typescript/src/lib/members/property.util.js +0 -61
  133. package/libs/cli/typescript/src/lib/members/statements/expressions/binary-expression.implementation.js +0 -42
  134. package/libs/cli/typescript/src/lib/members/statements/expressions/call-expression.implementation.js +0 -114
  135. package/libs/cli/typescript/src/lib/members/statements/expressions/expression.abstraction.js +0 -188
  136. package/libs/cli/typescript/src/lib/members/statements/expressions/property-access-expression.implementation.js +0 -35
  137. package/libs/cli/typescript/src/lib/members/statements/expressions/unary-expression.implementation.js +0 -51
  138. package/libs/cli/typescript/src/lib/members/statements/statement.implementation.js +0 -49
  139. package/libs/cli/typescript/src/lib/members/statements/utils.js +0 -51
  140. package/libs/cli/typescript/src/lib/plugins/built-in.plugin.js +0 -258
  141. package/libs/cli/typescript/src/lib/plugins/plugin.interface.js +0 -15
  142. package/libs/cli/typescript/src/lib/plugins/rxjs.plugin.js +0 -228
  143. package/libs/cli/typescript/src/lib/plugins/signal.plugin.js +0 -126
  144. package/libs/cli/typescript/src/lib/plugins/stubs.js +0 -66
  145. package/libs/cli/typescript/src/lib/type-alias.implementation.js +0 -72
  146. package/libs/cli/typescript/src/lib/utils.js +0 -39
  147. package/libs/cli/typescript/src/lib/variable-declaration.implementation.js +0 -35
  148. package/libs/core/codegular/src/index.js +0 -21
  149. package/libs/core/codegular/src/lib/index.js +0 -29
  150. package/libs/core/codegular/src/lib/node.js +0 -112
  151. package/libs/core/codegular/src/lib/program.js +0 -92
  152. package/libs/core/codegular/src/lib/string.js +0 -168
  153. package/libs/core/codegular/src/lib/type-checker.js +0 -170
  154. package/libs/core/codegular/src/lib/utils.js +0 -347
  155. package/main.js +0 -43
@@ -1,257 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
- var http_exports = {};
29
- __export(http_exports, {
30
- AuthClient: () => AuthClient,
31
- PlatformClient: () => PlatformClient
32
- });
33
- module.exports = __toCommonJS(http_exports);
34
- var http = __toESM(require("http"));
35
- var https = __toESM(require("https"));
36
- var import_utils = require("../utils/utils.js");
37
- const requestWithProtocol = function(protocol, options, body) {
38
- (0, import_utils.verboseLog)(options);
39
- return new Promise((resolve, reject) => {
40
- const req = protocol.request(
41
- options,
42
- (res) => resolveResponse(res, resolve, reject)
43
- );
44
- req.on("error", reject);
45
- if (body) {
46
- req.write((0, import_utils.stringifyJSON)(body));
47
- }
48
- req.end();
49
- });
50
- };
51
- const genericPost = function(protocol, hostname, path, body, headers, port) {
52
- return requestWithProtocol(
53
- protocol,
54
- { method: "POST", hostname, path, headers, port },
55
- body
56
- );
57
- };
58
- const genericPut = function(protocol, hostname, path, body, headers, port) {
59
- return requestWithProtocol(
60
- protocol,
61
- { method: "PUT", hostname, path, headers, port },
62
- body
63
- );
64
- };
65
- const genericPatch = function(protocol, hostname, path, body, headers, port) {
66
- return requestWithProtocol(
67
- protocol,
68
- { method: "PATCH", hostname, path, headers, port },
69
- body
70
- );
71
- };
72
- const genericGet = function(protocol, hostname, path, headers, port) {
73
- return requestWithProtocol(
74
- protocol,
75
- { method: "GET", hostname, path, headers, port },
76
- void 0
77
- );
78
- };
79
- function resolveResponse(res, resolve, reject) {
80
- const chunks = [];
81
- res.on("data", (data) => chunks.push(data));
82
- res.on("end", () => {
83
- let resBody = Buffer.concat(chunks);
84
- let parsedBody;
85
- switch (res.headers["content-type"]?.split(";")[0]) {
86
- case "application/json":
87
- parsedBody = JSON.parse(resBody.toString());
88
- break;
89
- default:
90
- parsedBody = resBody.toString();
91
- }
92
- (0, import_utils.verboseLog)("Response Status:", res.statusCode);
93
- (0, import_utils.verboseLog)("Response Headers:", res.headers);
94
- (0, import_utils.verboseLog)("Response Body:", parsedBody);
95
- if (res.statusCode === 403 && parsedBody.message === "Token is invalid") {
96
- reject(
97
- new Error(
98
- `Token expired: Please run 'lg refresh' to refresh your token and try again.`
99
- )
100
- );
101
- } else if (res.statusCode === 401 || res.statusCode === 403) {
102
- reject(
103
- new Error(
104
- `Unauthorized: ${parsedBody.message || "Authentication failed"}`
105
- )
106
- );
107
- } else if (res.statusCode >= 400 && res.statusCode < 500) {
108
- const errorMessage = parsedBody.message || parsedBody.error || "Request failed";
109
- reject(new Error(`Client Error (${res.statusCode}): ${errorMessage}`));
110
- } else if (res.statusCode >= 500) {
111
- const errorMessage = parsedBody.message || parsedBody.error || "Server error";
112
- reject(new Error(`Server Error (${res.statusCode}): ${errorMessage}`));
113
- } else {
114
- resolve(parsedBody);
115
- }
116
- });
117
- }
118
- class JsonClient {
119
- constructor() {
120
- this.protocol = https;
121
- this.headers = {
122
- "Content-Type": "application/json"
123
- };
124
- }
125
- get(path) {
126
- return genericGet(
127
- this.protocol,
128
- this.hostname,
129
- path,
130
- this.headers,
131
- this.port
132
- );
133
- }
134
- put(path, body) {
135
- return genericPut(
136
- this.protocol,
137
- this.hostname,
138
- path,
139
- body,
140
- this.headers,
141
- this.port
142
- );
143
- }
144
- post(path, body) {
145
- return genericPost(
146
- this.protocol,
147
- this.hostname,
148
- path,
149
- body,
150
- this.headers,
151
- this.port
152
- );
153
- }
154
- patch(path, body) {
155
- return genericPatch(
156
- this.protocol,
157
- this.hostname,
158
- path,
159
- body,
160
- this.headers,
161
- this.port
162
- );
163
- }
164
- }
165
- class PlatformClient extends JsonClient {
166
- constructor(tokenManager, env = "prod") {
167
- super();
168
- this.tokenManager = tokenManager;
169
- this.prefix = "";
170
- if (env === "dev") {
171
- this.hostname = "127.0.0.1";
172
- this.port = 5001;
173
- this.prefix = "/lowgular-platform-c0e93/us-central1";
174
- this.protocol = http;
175
- } else {
176
- this.hostname = "us-central1-lowgular-platform-c0e93.cloudfunctions.net";
177
- this.protocol = https;
178
- }
179
- }
180
- setTokenHeader() {
181
- this.headers.Authorization = `Bearer ${this.tokenManager.readAccessToken()}`;
182
- }
183
- async interceptTokenError(req) {
184
- try {
185
- this.setTokenHeader();
186
- return await req();
187
- } catch (error) {
188
- if (error.message.includes("Token expired")) {
189
- await this.tokenManager.refreshToken();
190
- this.setTokenHeader();
191
- return await req();
192
- }
193
- throw error;
194
- }
195
- }
196
- get(path) {
197
- return this.interceptTokenError(
198
- () => genericGet(
199
- this.protocol,
200
- this.hostname,
201
- this._fullPath(path),
202
- this.headers,
203
- this.port
204
- )
205
- );
206
- }
207
- put(path, body) {
208
- return this.interceptTokenError(
209
- () => genericPut(
210
- this.protocol,
211
- this.hostname,
212
- this._fullPath(path),
213
- body,
214
- this.headers,
215
- this.port
216
- )
217
- );
218
- }
219
- post(path, body) {
220
- return this.interceptTokenError(
221
- () => genericPost(
222
- this.protocol,
223
- this.hostname,
224
- this._fullPath(path),
225
- body,
226
- this.headers,
227
- this.port
228
- )
229
- );
230
- }
231
- patch(path, body) {
232
- return this.interceptTokenError(
233
- () => genericPatch(
234
- this.protocol,
235
- this.hostname,
236
- this._fullPath(path),
237
- body,
238
- this.headers,
239
- this.port
240
- )
241
- );
242
- }
243
- _fullPath(path) {
244
- return this.prefix ? `${this.prefix}${path}` : path;
245
- }
246
- }
247
- class AuthClient extends JsonClient {
248
- constructor() {
249
- super(...arguments);
250
- this.hostname = "us-central1-lowgular-extension.cloudfunctions.net";
251
- }
252
- }
253
- // Annotate the CommonJS export names for ESM import in node:
254
- 0 && (module.exports = {
255
- AuthClient,
256
- PlatformClient
257
- });
@@ -1,95 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var markdown_exports = {};
19
- __export(markdown_exports, {
20
- appendMarkdownMetadata: () => appendMarkdownMetadata,
21
- cleanupBlocks: () => cleanupBlocks,
22
- extractBlocks: () => extractBlocks,
23
- extractMarkdownContent: () => extractMarkdownContent,
24
- extractMarkdownMetadata: () => extractMarkdownMetadata,
25
- parseMarkdownFile: () => parseMarkdownFile,
26
- replaceMarkdownInclude: () => replaceMarkdownInclude
27
- });
28
- module.exports = __toCommonJS(markdown_exports);
29
- var import_yaml = require("./yaml");
30
- const metadataRegex = /^---\s*\n([\s\S]*?)\n---\s*\n([\s\S]*)$/;
31
- const extractMarkdownMetadata = (markdown) => {
32
- const metadata = markdown.match(metadataRegex)[1];
33
- if (!metadata) {
34
- return void 0;
35
- }
36
- return (0, import_yaml.parseTopLevelYamlStringsAndArrays)(metadata);
37
- };
38
- const extractMarkdownContent = (markdown) => {
39
- const content = markdown.match(
40
- /^---\s*\n([\s\S]*?)\n---\s*\n([\s\S]*)$/
41
- )?.[2];
42
- if (!content) {
43
- throw new Error("No content found after metadata in README.md");
44
- }
45
- return content.trim();
46
- };
47
- function extractBlocks(markdown) {
48
- const results = [];
49
- const fence = /(^|[\r\n])```([^\n]*)\n([\s\S]*?)\n?```/g;
50
- let match;
51
- while (match = fence.exec(markdown)) {
52
- const info = (match[2] || "").trim();
53
- const type = (info.split(/\s+/)[0] || "text").trim();
54
- const content = (match[3] || "").replace(/\s+$/, "");
55
- results.push({ type, content });
56
- }
57
- return results;
58
- }
59
- function cleanupBlocks(markdown) {
60
- return markdown.replace(/(^|[\r\n])```([^\n]*)\n([\s\S]*?)\n```/g, "");
61
- }
62
- const parseMarkdownFile = (markdown) => {
63
- if (markdown.match(metadataRegex) !== null) {
64
- return {
65
- metadata: extractMarkdownMetadata(markdown),
66
- content: extractMarkdownContent(markdown)
67
- };
68
- }
69
- return {
70
- metadata: {},
71
- content: markdown
72
- };
73
- };
74
- const appendMarkdownMetadata = (markdown, metadata) => {
75
- return `---${Object.entries(metadata).map(([key, value]) => `${key}: ${value}`).join("\n")}---
76
- ${markdown}`;
77
- };
78
- const replaceMarkdownInclude = (markdown, fileSystem) => {
79
- return markdown.replace(/<!--\s*include:\s*(.+?)\s*-->/g, (match, p1) => {
80
- if (p1 in fileSystem) {
81
- return fileSystem[p1];
82
- }
83
- return match;
84
- });
85
- };
86
- // Annotate the CommonJS export names for ESM import in node:
87
- 0 && (module.exports = {
88
- appendMarkdownMetadata,
89
- cleanupBlocks,
90
- extractBlocks,
91
- extractMarkdownContent,
92
- extractMarkdownMetadata,
93
- parseMarkdownFile,
94
- replaceMarkdownInclude
95
- });
@@ -1,88 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var embeddings_exports = {};
19
- __export(embeddings_exports, {
20
- embedText: () => embedText,
21
- embedTexts: () => embedTexts
22
- });
23
- module.exports = __toCommonJS(embeddings_exports);
24
- var import_transformers = require("@huggingface/transformers");
25
- const SMALL_MODEL_ID = "Xenova/bge-small-en-v1.5";
26
- const BASE_MODEL_ID = "Xenova/bge-base-en-v1.5";
27
- let smallExtractor;
28
- let baseExtractor;
29
- async function getExtractor(size = "small") {
30
- if (size === "small") {
31
- if (!smallExtractor) {
32
- smallExtractor = await (0, import_transformers.pipeline)("feature-extraction", SMALL_MODEL_ID, {
33
- dtype: "fp32"
34
- });
35
- }
36
- return smallExtractor;
37
- } else {
38
- if (!baseExtractor) {
39
- baseExtractor = await (0, import_transformers.pipeline)("feature-extraction", BASE_MODEL_ID, {
40
- dtype: "fp32"
41
- });
42
- }
43
- return baseExtractor;
44
- }
45
- }
46
- function toRows(out) {
47
- if (out?.data && out?.dims) {
48
- const [batchSize, dim] = out.dims;
49
- const data = Array.from(out.data);
50
- const rows = [];
51
- for (let i = 0; i < batchSize; i++) {
52
- rows.push(data.slice(i * dim, (i + 1) * dim));
53
- }
54
- return rows;
55
- }
56
- const d = out?.data ?? out;
57
- if (!d)
58
- throw new Error("embed: output has no data");
59
- if (ArrayBuffer.isView(d))
60
- return [Array.from(d)];
61
- if (Array.isArray(d)) {
62
- if (d.length > 0 && Array.isArray(d[0])) {
63
- return d;
64
- }
65
- return [d];
66
- }
67
- throw new Error(
68
- `embed: unknown output shape - ${JSON.stringify({ type: typeof out, hasData: !!out?.data, hasDims: !!out?.dims })}`
69
- );
70
- }
71
- async function embedTexts(texts, size = "small") {
72
- if (!texts?.length)
73
- throw new Error("embedTexts: texts is empty");
74
- const ex = await getExtractor(size);
75
- const raw = await ex(texts, { pooling: "mean", normalize: true });
76
- const rows = toRows(raw);
77
- const dim = rows[0].length;
78
- return rows.map((v) => Float32Array.from(v));
79
- }
80
- async function embedText(text, size = "small") {
81
- const [v] = await embedTexts([text], size);
82
- return Array.from(v);
83
- }
84
- // Annotate the CommonJS export names for ESM import in node:
85
- 0 && (module.exports = {
86
- embedText,
87
- embedTexts
88
- });
@@ -1,25 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __copyProps = (to, from, except, desc) => {
6
- if (from && typeof from === "object" || typeof from === "function") {
7
- for (let key of __getOwnPropNames(from))
8
- if (!__hasOwnProp.call(to, key) && key !== except)
9
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
- }
11
- return to;
12
- };
13
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
- var transformers_exports = {};
16
- module.exports = __toCommonJS(transformers_exports);
17
- __reExport(transformers_exports, require("./embeddings"), module.exports);
18
- __reExport(transformers_exports, require("./rag-eval"), module.exports);
19
- __reExport(transformers_exports, require("./similarity"), module.exports);
20
- // Annotate the CommonJS export names for ESM import in node:
21
- 0 && (module.exports = {
22
- ...require("./embeddings"),
23
- ...require("./rag-eval"),
24
- ...require("./similarity")
25
- });
@@ -1,154 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var rag_eval_exports = {};
19
- __export(rag_eval_exports, {
20
- aggregateRAGMetrics: () => aggregateRAGMetrics,
21
- evaluateRAG: () => evaluateRAG,
22
- formatRAGEvaluationResults: () => formatRAGEvaluationResults,
23
- precisionAtK: () => precisionAtK,
24
- recallAtK: () => recallAtK,
25
- validateNaming: () => validateNaming
26
- });
27
- module.exports = __toCommonJS(rag_eval_exports);
28
- var import_similarity = require("./similarity");
29
- async function validateNaming(userInput, expectedNames) {
30
- if (!userInput?.trim()) {
31
- throw new Error("userInput is empty");
32
- }
33
- if (!expectedNames?.length) {
34
- throw new Error("expectedNames is empty");
35
- }
36
- const stringScores = expectedNames.map((expected) => ({
37
- name: expected,
38
- score: (0, import_similarity.stringSimilarity)(userInput, expected)
39
- }));
40
- const semanticResults = await (0, import_similarity.findSimilarWords)(
41
- userInput,
42
- expectedNames,
43
- expectedNames.length
44
- // Get all results
45
- );
46
- const combinedScores = expectedNames.map((expected) => {
47
- const semantic = semanticResults.find((r) => r.word === expected)?.similarity ?? 0;
48
- const string = stringScores.find((s) => s.name === expected)?.score ?? 0;
49
- const combined = semantic * 0.6 + string * 0.4;
50
- return {
51
- name: expected,
52
- semantic,
53
- string,
54
- combined
55
- };
56
- });
57
- const bestMatch = combinedScores.reduce(
58
- (max, curr) => curr.combined > max.combined ? curr : max
59
- );
60
- return {
61
- bestMatch: bestMatch.name,
62
- similarity: bestMatch.combined,
63
- semanticScore: bestMatch.semantic,
64
- stringScore: bestMatch.string
65
- };
66
- }
67
- function precisionAtK(relevantCount, k) {
68
- if (relevantCount < 0 || k < 0) {
69
- throw new Error("All input values must be non-negative");
70
- }
71
- if (k === 0) {
72
- return 0;
73
- }
74
- return relevantCount / k;
75
- }
76
- function recallAtK(relevantCount, totalRelevant) {
77
- if (relevantCount < 0 || totalRelevant < 0) {
78
- throw new Error("All input values must be non-negative");
79
- }
80
- if (totalRelevant === 0) {
81
- return 0;
82
- }
83
- return relevantCount / totalRelevant;
84
- }
85
- function evaluateRAG(queries, searchResults, options) {
86
- const results = [];
87
- for (const queryItem of queries) {
88
- const { query, relevantDocumentIds } = queryItem;
89
- const retrievedIds = searchResults.map((r) => r.id);
90
- const relevantFound = retrievedIds.filter(
91
- (id) => relevantDocumentIds.includes(id)
92
- ).length;
93
- const precision = precisionAtK(relevantFound, options.topK);
94
- const recall = recallAtK(relevantFound, relevantDocumentIds.length);
95
- results.push({
96
- query,
97
- precisionAtK: precision,
98
- recallAtK: recall,
99
- relevantFound,
100
- totalRelevant: relevantDocumentIds.length,
101
- retrievedIds
102
- });
103
- }
104
- return results;
105
- }
106
- function aggregateRAGMetrics(results) {
107
- if (results.length === 0) {
108
- return {
109
- meanPrecision: 0,
110
- meanRecall: 0,
111
- totalQueries: 0,
112
- averageRelevantFound: 0,
113
- averageTotalRelevant: 0
114
- };
115
- }
116
- const meanPrecision = results.reduce((sum, r) => sum + r.precisionAtK, 0) / results.length;
117
- const meanRecall = results.reduce((sum, r) => sum + r.recallAtK, 0) / results.length;
118
- const averageRelevantFound = results.reduce((sum, r) => sum + r.relevantFound, 0) / results.length;
119
- const averageTotalRelevant = results.reduce((sum, r) => sum + r.totalRelevant, 0) / results.length;
120
- return {
121
- meanPrecision,
122
- meanRecall,
123
- totalQueries: results.length,
124
- averageRelevantFound,
125
- averageTotalRelevant
126
- };
127
- }
128
- function formatRAGEvaluationResults(results, k) {
129
- const lines = [];
130
- lines.push("=".repeat(80));
131
- lines.push(`Results with K=${k}:`);
132
- lines.push("=".repeat(80));
133
- for (const result of results) {
134
- lines.push(`Query: ${result.query}`);
135
- lines.push(` Retrieved: ${result.retrievedIds.length}`);
136
- lines.push(
137
- ` Precision@${k}: ${result.precisionAtK.toFixed(2)}, Recall@${k}: ${result.recallAtK.toFixed(2)}`
138
- );
139
- lines.push(
140
- ` Relevant found: ${result.relevantFound}/${result.totalRelevant}`
141
- );
142
- lines.push("");
143
- }
144
- return lines.join("\n");
145
- }
146
- // Annotate the CommonJS export names for ESM import in node:
147
- 0 && (module.exports = {
148
- aggregateRAGMetrics,
149
- evaluateRAG,
150
- formatRAGEvaluationResults,
151
- precisionAtK,
152
- recallAtK,
153
- validateNaming
154
- });