@rapidhuman/graph-common 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunking/index.d.ts +3 -0
- package/dist/chunking/index.d.ts.map +1 -0
- package/dist/chunking/index.js +19 -0
- package/dist/chunking/index.js.map +1 -0
- package/dist/chunking/pipeline.d.ts +30 -0
- package/dist/chunking/pipeline.d.ts.map +1 -0
- package/dist/chunking/pipeline.js +194 -0
- package/dist/chunking/pipeline.js.map +1 -0
- package/dist/chunking/types.d.ts +101 -0
- package/dist/chunking/types.d.ts.map +1 -0
- package/dist/chunking/types.js +3 -0
- package/dist/chunking/types.js.map +1 -0
- package/dist/events/index.d.ts +4 -0
- package/dist/events/index.d.ts.map +1 -0
- package/dist/events/index.js +20 -0
- package/dist/events/index.js.map +1 -0
- package/dist/events/publisher.d.ts +36 -0
- package/dist/events/publisher.d.ts.map +1 -0
- package/dist/events/publisher.js +50 -0
- package/dist/events/publisher.js.map +1 -0
- package/dist/events/topics.d.ts +7 -0
- package/dist/events/topics.d.ts.map +1 -0
- package/dist/events/topics.js +10 -0
- package/dist/events/topics.js.map +1 -0
- package/dist/events/types.d.ts +49 -0
- package/dist/events/types.d.ts.map +1 -0
- package/dist/events/types.js +3 -0
- package/dist/events/types.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/relationships/helpers.d.ts +23 -0
- package/dist/relationships/helpers.d.ts.map +1 -0
- package/dist/relationships/helpers.js +54 -0
- package/dist/relationships/helpers.js.map +1 -0
- package/dist/relationships/index.d.ts +3 -0
- package/dist/relationships/index.d.ts.map +1 -0
- package/dist/relationships/index.js +19 -0
- package/dist/relationships/index.js.map +1 -0
- package/dist/relationships/types.d.ts +53 -0
- package/dist/relationships/types.d.ts.map +1 -0
- package/dist/relationships/types.js +50 -0
- package/dist/relationships/types.js.map +1 -0
- package/dist/schema/index.d.ts +2 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +18 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/schema/types.d.ts +152 -0
- package/dist/schema/types.d.ts.map +1 -0
- package/dist/schema/types.js +3 -0
- package/dist/schema/types.js.map +1 -0
- package/dist/uri/index.d.ts +3 -0
- package/dist/uri/index.d.ts.map +1 -0
- package/dist/uri/index.js +19 -0
- package/dist/uri/index.js.map +1 -0
- package/dist/uri/types.d.ts +31 -0
- package/dist/uri/types.d.ts.map +1 -0
- package/dist/uri/types.js +6 -0
- package/dist/uri/types.js.map +1 -0
- package/dist/uri/uri.d.ts +45 -0
- package/dist/uri/uri.d.ts.map +1 -0
- package/dist/uri/uri.js +136 -0
- package/dist/uri/uri.js.map +1 -0
- package/package.json +43 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/chunking/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./types"), exports);
|
|
18
|
+
__exportStar(require("./pipeline"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/chunking/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,6CAA2B"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ChunkConfig, ChunkResult } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Estimates the token count for a text string.
|
|
4
|
+
* Uses a simple approximation of ~4 characters per token.
|
|
5
|
+
* Actual tokenization happens in the embedding service; this is for chunk sizing heuristics.
|
|
6
|
+
*
|
|
7
|
+
* @param text - Text to estimate token count for
|
|
8
|
+
* @returns Estimated number of tokens
|
|
9
|
+
*/
|
|
10
|
+
export declare function estimateTokenCount(text: string): number;
|
|
11
|
+
/**
|
|
12
|
+
* Substitutes template variables in a context prefix template.
|
|
13
|
+
* Variables are in the format `{variable_name}`.
|
|
14
|
+
*
|
|
15
|
+
* @param template - Template string with {variable} placeholders, or null
|
|
16
|
+
* @param vars - Key-value pairs to substitute into the template
|
|
17
|
+
* @returns Resolved string, or empty string if template is null
|
|
18
|
+
*/
|
|
19
|
+
export declare function buildContextPrefix(template: string | null, vars: Record<string, string>): string;
|
|
20
|
+
/**
|
|
21
|
+
* Chunks content according to the provided configuration.
|
|
22
|
+
* Implements the base chunking pipeline: split → enforce limits → apply overlap → build metadata.
|
|
23
|
+
*
|
|
24
|
+
* @param content - Raw text content to chunk
|
|
25
|
+
* @param parentUri - URI of the parent artifact
|
|
26
|
+
* @param config - Chunking configuration for this artifact type
|
|
27
|
+
* @returns Array of ChunkResult objects with content and metadata
|
|
28
|
+
*/
|
|
29
|
+
export declare function chunkContent(content: string, parentUri: string, config: ChunkConfig): ChunkResult[];
|
|
30
|
+
//# sourceMappingURL=pipeline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipeline.d.ts","sourceRoot":"","sources":["../../src/chunking/pipeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEnD;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,MAAM,GAAG,IAAI,EACvB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC3B,MAAM,CAQR;AAuID;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,WAAW,GAClB,WAAW,EAAE,CAoCf"}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.estimateTokenCount = estimateTokenCount;
|
|
4
|
+
exports.buildContextPrefix = buildContextPrefix;
|
|
5
|
+
exports.chunkContent = chunkContent;
|
|
6
|
+
/**
|
|
7
|
+
* Estimates the token count for a text string.
|
|
8
|
+
* Uses a simple approximation of ~4 characters per token.
|
|
9
|
+
* Actual tokenization happens in the embedding service; this is for chunk sizing heuristics.
|
|
10
|
+
*
|
|
11
|
+
* @param text - Text to estimate token count for
|
|
12
|
+
* @returns Estimated number of tokens
|
|
13
|
+
*/
|
|
14
|
+
function estimateTokenCount(text) {
|
|
15
|
+
return Math.ceil(text.length / 4);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Substitutes template variables in a context prefix template.
|
|
19
|
+
* Variables are in the format `{variable_name}`.
|
|
20
|
+
*
|
|
21
|
+
* @param template - Template string with {variable} placeholders, or null
|
|
22
|
+
* @param vars - Key-value pairs to substitute into the template
|
|
23
|
+
* @returns Resolved string, or empty string if template is null
|
|
24
|
+
*/
|
|
25
|
+
function buildContextPrefix(template, vars) {
|
|
26
|
+
if (!template)
|
|
27
|
+
return '';
|
|
28
|
+
let result = template;
|
|
29
|
+
for (const [key, value] of Object.entries(vars)) {
|
|
30
|
+
result = result.replace(new RegExp(`\\{${key}\\}`, 'g'), value);
|
|
31
|
+
}
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Splits content into raw segments based on the configured split_on boundaries.
|
|
36
|
+
* Falls back to splitting by double newlines if no boundary types are configured.
|
|
37
|
+
*/
|
|
38
|
+
function splitContent(content, config) {
|
|
39
|
+
if (config.split_on.length === 0) {
|
|
40
|
+
// Default: split on double newlines (paragraph breaks)
|
|
41
|
+
const segments = content.split(/\n\n+/).filter((s) => s.trim().length > 0);
|
|
42
|
+
return segments.length > 0 ? segments : [content];
|
|
43
|
+
}
|
|
44
|
+
// Build regex from split_on boundaries
|
|
45
|
+
const patterns = [];
|
|
46
|
+
for (const boundary of config.split_on) {
|
|
47
|
+
switch (boundary) {
|
|
48
|
+
case 'heading':
|
|
49
|
+
case 'section':
|
|
50
|
+
patterns.push('(?=^#{1,6}\\s)');
|
|
51
|
+
break;
|
|
52
|
+
case 'speaker_turn':
|
|
53
|
+
patterns.push('(?=^[A-Z][a-zA-Z\\s]*:)');
|
|
54
|
+
break;
|
|
55
|
+
case 'paragraph':
|
|
56
|
+
patterns.push('\\n\\n+');
|
|
57
|
+
break;
|
|
58
|
+
case 'topic_shift':
|
|
59
|
+
patterns.push('\\n\\n+');
|
|
60
|
+
break;
|
|
61
|
+
case 'function':
|
|
62
|
+
case 'function_level':
|
|
63
|
+
patterns.push('(?=^(?:export\\s+)?(?:function|class|const|let|var)\\s)');
|
|
64
|
+
break;
|
|
65
|
+
default:
|
|
66
|
+
// Treat unknown boundaries as literal text separators
|
|
67
|
+
patterns.push(`(?=${boundary.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')})`);
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (patterns.length === 0) {
|
|
72
|
+
return [content];
|
|
73
|
+
}
|
|
74
|
+
const regex = new RegExp(patterns.join('|'), 'gm');
|
|
75
|
+
const segments = content.split(regex).filter((s) => s.trim().length > 0);
|
|
76
|
+
return segments.length > 0 ? segments : [content];
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Applies overlap by prepending tokens from the end of the previous chunk.
|
|
80
|
+
*/
|
|
81
|
+
function applyOverlap(segments, overlapTokens) {
|
|
82
|
+
if (overlapTokens <= 0 || segments.length <= 1)
|
|
83
|
+
return segments;
|
|
84
|
+
const overlapChars = overlapTokens * 4; // approximate chars for overlap
|
|
85
|
+
const result = [segments[0]];
|
|
86
|
+
for (let i = 1; i < segments.length; i++) {
|
|
87
|
+
const prev = segments[i - 1];
|
|
88
|
+
const overlapText = prev.slice(-overlapChars);
|
|
89
|
+
result.push(overlapText + segments[i]);
|
|
90
|
+
}
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Merges segments that are below the minimum token threshold with adjacent segments.
|
|
95
|
+
*/
|
|
96
|
+
function mergeSmallSegments(segments, minTokens) {
|
|
97
|
+
if (segments.length <= 1)
|
|
98
|
+
return segments;
|
|
99
|
+
const result = [];
|
|
100
|
+
let buffer = '';
|
|
101
|
+
for (const segment of segments) {
|
|
102
|
+
if (buffer.length === 0) {
|
|
103
|
+
buffer = segment;
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
buffer = buffer + '\n\n' + segment;
|
|
107
|
+
}
|
|
108
|
+
if (estimateTokenCount(buffer) >= minTokens) {
|
|
109
|
+
result.push(buffer);
|
|
110
|
+
buffer = '';
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
// Append any remaining buffer
|
|
114
|
+
if (buffer.length > 0) {
|
|
115
|
+
if (result.length > 0) {
|
|
116
|
+
result[result.length - 1] = result[result.length - 1] + '\n\n' + buffer;
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
result.push(buffer);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Splits segments that exceed the maximum token threshold.
|
|
126
|
+
*/
|
|
127
|
+
function splitLargeSegments(segments, maxTokens) {
|
|
128
|
+
const result = [];
|
|
129
|
+
const maxChars = maxTokens * 4;
|
|
130
|
+
for (const segment of segments) {
|
|
131
|
+
if (estimateTokenCount(segment) <= maxTokens) {
|
|
132
|
+
result.push(segment);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
// Split at sentence boundaries within the segment
|
|
136
|
+
const sentences = segment.split(/(?<=[.!?])\s+/);
|
|
137
|
+
let current = '';
|
|
138
|
+
for (const sentence of sentences) {
|
|
139
|
+
if (current.length + sentence.length > maxChars && current.length > 0) {
|
|
140
|
+
result.push(current.trim());
|
|
141
|
+
current = sentence;
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
current = current ? current + ' ' + sentence : sentence;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (current.trim().length > 0) {
|
|
148
|
+
result.push(current.trim());
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return result;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Chunks content according to the provided configuration.
|
|
156
|
+
* Implements the base chunking pipeline: split → enforce limits → apply overlap → build metadata.
|
|
157
|
+
*
|
|
158
|
+
* @param content - Raw text content to chunk
|
|
159
|
+
* @param parentUri - URI of the parent artifact
|
|
160
|
+
* @param config - Chunking configuration for this artifact type
|
|
161
|
+
* @returns Array of ChunkResult objects with content and metadata
|
|
162
|
+
*/
|
|
163
|
+
function chunkContent(content, parentUri, config) {
|
|
164
|
+
// Step 1: Split content based on strategy boundaries
|
|
165
|
+
let segments = splitContent(content, config);
|
|
166
|
+
// Step 2: Merge small chunks
|
|
167
|
+
segments = mergeSmallSegments(segments, config.min_tokens);
|
|
168
|
+
// Step 3: Split large chunks
|
|
169
|
+
segments = splitLargeSegments(segments, config.max_tokens);
|
|
170
|
+
// Step 4: Apply overlap
|
|
171
|
+
segments = applyOverlap(segments, config.overlap_tokens);
|
|
172
|
+
// Step 5: Build chunk results with metadata
|
|
173
|
+
const now = new Date().toISOString();
|
|
174
|
+
const totalChunks = segments.length;
|
|
175
|
+
const contextPrefix = buildContextPrefix(config.context_prefix_template, {
|
|
176
|
+
artifact_type: config.artifact_type,
|
|
177
|
+
parent_uri: parentUri,
|
|
178
|
+
});
|
|
179
|
+
return segments.map((segmentContent, index) => ({
|
|
180
|
+
chunk_id: `${parentUri}:chunk-${String(index).padStart(3, '0')}`,
|
|
181
|
+
parent_uri: parentUri,
|
|
182
|
+
chunk_index: index,
|
|
183
|
+
total_chunks: totalChunks,
|
|
184
|
+
content: segmentContent,
|
|
185
|
+
content_type: config.artifact_type,
|
|
186
|
+
section_label: `Chunk ${index + 1} of ${totalChunks}`,
|
|
187
|
+
token_count: estimateTokenCount(segmentContent),
|
|
188
|
+
overlap_tokens: index > 0 ? config.overlap_tokens : 0,
|
|
189
|
+
strategy_used: config.strategy,
|
|
190
|
+
context_prefix: contextPrefix,
|
|
191
|
+
created_at: now,
|
|
192
|
+
}));
|
|
193
|
+
}
|
|
194
|
+
//# sourceMappingURL=pipeline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipeline.js","sourceRoot":"","sources":["../../src/chunking/pipeline.ts"],"names":[],"mappings":";;AAUA,gDAEC;AAUD,gDAWC;AAgJD,oCAwCC;AAvND;;;;;;;GAOG;AACH,SAAgB,kBAAkB,CAAC,IAAY;IAC7C,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AACpC,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,kBAAkB,CAChC,QAAuB,EACvB,IAA4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 +1,101 @@
|
|
|
1
|
+
/** Available chunking strategies for splitting artifact content */
|
|
2
|
+
export type ChunkStrategy = 'semantic' | 'structural' | 'artifact' | 'hierarchical' | 'function_level';
|
|
3
|
+
/**
|
|
4
|
+
* Configuration for chunking a specific artifact type.
|
|
5
|
+
* Generated after artifact analysis — per-solution configs are not in this package.
|
|
6
|
+
*/
|
|
7
|
+
export interface ChunkConfig {
|
|
8
|
+
/** Artifact type this config applies to */
|
|
9
|
+
artifact_type: string;
|
|
10
|
+
/** Chunking strategy to use */
|
|
11
|
+
strategy: ChunkStrategy;
|
|
12
|
+
/** Target number of tokens per chunk */
|
|
13
|
+
target_tokens: number;
|
|
14
|
+
/** Maximum tokens per chunk (chunks exceeding this are sub-split) */
|
|
15
|
+
max_tokens: number;
|
|
16
|
+
/** Minimum tokens per chunk (chunks below this are merged with adjacent) */
|
|
17
|
+
min_tokens: number;
|
|
18
|
+
/** Number of overlapping tokens between consecutive chunks */
|
|
19
|
+
overlap_tokens: number;
|
|
20
|
+
/** Boundary types to split on (e.g., ["speaker_turn", "heading"]) */
|
|
21
|
+
split_on: string[];
|
|
22
|
+
/** Template for context prefix prepended to each chunk embedding */
|
|
23
|
+
context_prefix_template: string | null;
|
|
24
|
+
/** Artifact-specific rules for chunking behavior */
|
|
25
|
+
special_rules: Record<string, unknown>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Complete chunking configuration for a solution.
|
|
29
|
+
* Contains configs for all artifact types in that solution.
|
|
30
|
+
*/
|
|
31
|
+
export interface SolutionChunkConfig {
|
|
32
|
+
/** Solution code (rt, rr, ra, rs, rc) */
|
|
33
|
+
solution: string;
|
|
34
|
+
/** Embedding model identifier */
|
|
35
|
+
embedding_model: string;
|
|
36
|
+
/** Chunking configs keyed by artifact_type */
|
|
37
|
+
configs: Record<string, ChunkConfig>;
|
|
38
|
+
/** ISO 8601 timestamp of when the artifact analysis was run */
|
|
39
|
+
analyzed_at: string;
|
|
40
|
+
/** Number of sample artifacts analyzed */
|
|
41
|
+
sample_count: number;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Result of chunking a piece of content. Contains the chunk text
|
|
45
|
+
* and all metadata needed for embedding storage and retrieval.
|
|
46
|
+
*/
|
|
47
|
+
export interface ChunkResult {
|
|
48
|
+
/** Unique chunk identifier (e.g., "acme:rt:persona-001:chunk-003") */
|
|
49
|
+
chunk_id: string;
|
|
50
|
+
/** URI of the parent artifact */
|
|
51
|
+
parent_uri: string;
|
|
52
|
+
/** Zero-based index of this chunk */
|
|
53
|
+
chunk_index: number;
|
|
54
|
+
/** Total number of chunks for the parent artifact */
|
|
55
|
+
total_chunks: number;
|
|
56
|
+
/** The actual chunk text content */
|
|
57
|
+
content: string;
|
|
58
|
+
/** Content type of the chunk */
|
|
59
|
+
content_type: string;
|
|
60
|
+
/** Human-readable label for the section this chunk covers */
|
|
61
|
+
section_label: string;
|
|
62
|
+
/** Estimated number of tokens in this chunk */
|
|
63
|
+
token_count: number;
|
|
64
|
+
/** Number of overlapping tokens with adjacent chunks */
|
|
65
|
+
overlap_tokens: number;
|
|
66
|
+
/** Chunking strategy that produced this chunk */
|
|
67
|
+
strategy_used: ChunkStrategy;
|
|
68
|
+
/** Context prefix prepended for embedding */
|
|
69
|
+
context_prefix: string;
|
|
70
|
+
/** ISO 8601 timestamp of chunk creation */
|
|
71
|
+
created_at: string;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Metadata carried by every chunk, regardless of chunking strategy.
|
|
75
|
+
* Matches the chunk metadata schema from the spec (Section 8.4).
|
|
76
|
+
*/
|
|
77
|
+
export interface ChunkMetadata {
|
|
78
|
+
/** Unique chunk identifier */
|
|
79
|
+
chunk_id: string;
|
|
80
|
+
/** URI of the parent artifact */
|
|
81
|
+
parent_uri: string;
|
|
82
|
+
/** Zero-based index of this chunk */
|
|
83
|
+
chunk_index: number;
|
|
84
|
+
/** Total number of chunks for the parent artifact */
|
|
85
|
+
total_chunks: number;
|
|
86
|
+
/** Content type of the chunk */
|
|
87
|
+
content_type: string;
|
|
88
|
+
/** Human-readable label for the section this chunk covers */
|
|
89
|
+
section_label: string;
|
|
90
|
+
/** Estimated number of tokens in this chunk */
|
|
91
|
+
token_count: number;
|
|
92
|
+
/** Number of overlapping tokens with adjacent chunks */
|
|
93
|
+
overlap_tokens: number;
|
|
94
|
+
/** Chunking strategy that produced this chunk */
|
|
95
|
+
strategy_used: ChunkStrategy;
|
|
96
|
+
/** Context prefix for embedding */
|
|
97
|
+
context_prefix: string;
|
|
98
|
+
/** ISO 8601 timestamp of chunk creation */
|
|
99
|
+
created_at: string;
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/chunking/types.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,MAAM,MAAM,aAAa,GAAG,UAAU,GAAG,YAAY,GAAG,UAAU,GAAG,cAAc,GAAG,gBAAgB,CAAC;AAEvG;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,2CAA2C;IAC3C,aAAa,EAAE,MAAM,CAAC;IACtB,+BAA+B;IAC/B,QAAQ,EAAE,aAAa,CAAC;IACxB,wCAAwC;IACxC,aAAa,EAAE,MAAM,CAAC;IACtB,qEAAqE;IACrE,UAAU,EAAE,MAAM,CAAC;IACnB,4EAA4E;IAC5E,UAAU,EAAE,MAAM,CAAC;IACnB,8DAA8D;IAC9D,cAAc,EAAE,MAAM,CAAC;IACvB,qEAAqE;IACrE,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,oEAAoE;IACpE,uBAAuB,EAAE,MAAM,GAAG,IAAI,CAAC;IACvC,oDAAoD;IACpD,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACxC;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,yCAAyC;IACzC,QAAQ,EAAE,MAAM,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,EAAE,aAAa,CAAC;IAC7B,mCAAmC;IACnC,cAAc,EAAE,MAAM,CAAC;IACvB,2CAA2C;IAC3C,UAAU,EAAE,MAAM,CAAC;CACpB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/chunking/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/events/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./types"), exports);
|
|
18
|
+
__exportStar(require("./topics"), exports);
|
|
19
|
+
__exportStar(require("./publisher"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/events/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,2CAAyB;AACzB,8CAA4B"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { TraceabilityEdgeEvent, EmbeddingSyncEvent, CacheInvalidationEvent } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Interface for publishing Graph RAG events to Pub/Sub topics.
|
|
4
|
+
* Solutions use this to emit cross-solution edge events, embedding sync events,
|
|
5
|
+
* and cache invalidation events.
|
|
6
|
+
*/
|
|
7
|
+
export interface IEventPublisher {
|
|
8
|
+
/** Publish a traceability edge event. Returns the Pub/Sub message ID. */
|
|
9
|
+
publishTraceabilityEdge(event: TraceabilityEdgeEvent): Promise<string>;
|
|
10
|
+
/** Publish an embedding sync event. Returns the Pub/Sub message ID. */
|
|
11
|
+
publishEmbeddingSync(event: EmbeddingSyncEvent): Promise<string>;
|
|
12
|
+
/** Publish a cache invalidation event. Returns the Pub/Sub message ID. */
|
|
13
|
+
publishCacheInvalidation(event: CacheInvalidationEvent): Promise<string>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Pub/Sub implementation of IEventPublisher.
|
|
17
|
+
* Uses @google-cloud/pubsub to publish events to the appropriate topics.
|
|
18
|
+
*/
|
|
19
|
+
export declare class PubSubEventPublisher implements IEventPublisher {
|
|
20
|
+
private readonly pubsub;
|
|
21
|
+
constructor(projectId: string);
|
|
22
|
+
/** Publish a traceability edge event to the traceability-edges topic */
|
|
23
|
+
publishTraceabilityEdge(event: TraceabilityEdgeEvent): Promise<string>;
|
|
24
|
+
/** Publish an embedding sync event to the embedding-sync topic */
|
|
25
|
+
publishEmbeddingSync(event: EmbeddingSyncEvent): Promise<string>;
|
|
26
|
+
/** Publish a cache invalidation event to the cache-invalidation topic */
|
|
27
|
+
publishCacheInvalidation(event: CacheInvalidationEvent): Promise<string>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Factory function to create an IEventPublisher instance.
|
|
31
|
+
*
|
|
32
|
+
* @param projectId - GCP project ID for Pub/Sub
|
|
33
|
+
* @returns IEventPublisher implementation
|
|
34
|
+
*/
|
|
35
|
+
export declare function createEventPublisher(projectId: string): IEventPublisher;
|
|
36
|
+
//# sourceMappingURL=publisher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publisher.d.ts","sourceRoot":"","sources":["../../src/events/publisher.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAO5F;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,yEAAyE;IACzE,uBAAuB,CAAC,KAAK,EAAE,qBAAqB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACvE,uEAAuE;IACvE,oBAAoB,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACjE,0EAA0E;IAC1E,wBAAwB,CAAC,KAAK,EAAE,sBAAsB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC1E;AAED;;;GAGG;AACH,qBAAa,oBAAqB,YAAW,eAAe;IAC1D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;gBAEpB,SAAS,EAAE,MAAM;IAI7B,wEAAwE;IAClE,uBAAuB,CAAC,KAAK,EAAE,qBAAqB,GAAG,OAAO,CAAC,MAAM,CAAC;IAQ5E,kEAAkE;IAC5D,oBAAoB,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC;IAQtE,yEAAyE;IACnE,wBAAwB,CAAC,KAAK,EAAE,sBAAsB,GAAG,OAAO,CAAC,MAAM,CAAC;CAO/E;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,eAAe,CAEvE"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PubSubEventPublisher = void 0;
|
|
4
|
+
exports.createEventPublisher = createEventPublisher;
|
|
5
|
+
const pubsub_1 = require("@google-cloud/pubsub");
|
|
6
|
+
const topics_1 = require("./topics");
|
|
7
|
+
/**
|
|
8
|
+
* Pub/Sub implementation of IEventPublisher.
|
|
9
|
+
* Uses @google-cloud/pubsub to publish events to the appropriate topics.
|
|
10
|
+
*/
|
|
11
|
+
class PubSubEventPublisher {
|
|
12
|
+
constructor(projectId) {
|
|
13
|
+
this.pubsub = new pubsub_1.PubSub({ projectId });
|
|
14
|
+
}
|
|
15
|
+
/** Publish a traceability edge event to the traceability-edges topic */
|
|
16
|
+
async publishTraceabilityEdge(event) {
|
|
17
|
+
const topic = this.pubsub.topic(topics_1.TRACEABILITY_EDGES_TOPIC);
|
|
18
|
+
const messageId = await topic.publishMessage({
|
|
19
|
+
json: event,
|
|
20
|
+
});
|
|
21
|
+
return messageId;
|
|
22
|
+
}
|
|
23
|
+
/** Publish an embedding sync event to the embedding-sync topic */
|
|
24
|
+
async publishEmbeddingSync(event) {
|
|
25
|
+
const topic = this.pubsub.topic(topics_1.EMBEDDING_SYNC_TOPIC);
|
|
26
|
+
const messageId = await topic.publishMessage({
|
|
27
|
+
json: event,
|
|
28
|
+
});
|
|
29
|
+
return messageId;
|
|
30
|
+
}
|
|
31
|
+
/** Publish a cache invalidation event to the cache-invalidation topic */
|
|
32
|
+
async publishCacheInvalidation(event) {
|
|
33
|
+
const topic = this.pubsub.topic(topics_1.CACHE_INVALIDATION_TOPIC);
|
|
34
|
+
const messageId = await topic.publishMessage({
|
|
35
|
+
json: event,
|
|
36
|
+
});
|
|
37
|
+
return messageId;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.PubSubEventPublisher = PubSubEventPublisher;
|
|
41
|
+
/**
|
|
42
|
+
* Factory function to create an IEventPublisher instance.
|
|
43
|
+
*
|
|
44
|
+
* @param projectId - GCP project ID for Pub/Sub
|
|
45
|
+
* @returns IEventPublisher implementation
|
|
46
|
+
*/
|
|
47
|
+
function createEventPublisher(projectId) {
|
|
48
|
+
return new PubSubEventPublisher(projectId);
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=publisher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publisher.js","sourceRoot":"","sources":["../../src/events/publisher.ts"],"names":[],"mappings":";;;AAmEA,oDAEC;AArED,iDAA8C;AAE9C,qCAIkB;AAgBlB;;;GAGG;AACH,MAAa,oBAAoB;IAG/B,YAAY,SAAiB;QAC3B,IAAI,CAAC,MAAM,GAAG,IAAI,eAAM,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC;IAC1C,CAAC;IAED,wEAAwE;IACxE,KAAK,CAAC,uBAAuB,CAAC,KAA4B;QACxD,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,iCAAwB,CAAC,CAAC;QAC1D,MAAM,SAAS,GAAG,MAAM,KAAK,CAAC,cAAc,CAAC;YAC3C,IAAI,EAAE,KAAK;SACZ,CAAC,CAAC;QACH,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,kEAAkE;IAClE,KAAK,CAAC,oBAAoB,CAAC,KAAyB;QAClD,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,6BAAoB,CAAC,CAAC;QACtD,MAAM,SAAS,GAAG,MAAM,KAAK,CAAC,cAAc,CAAC;YAC3C,IAAI,EAAE,KAAK;SACZ,CAAC,CAAC;QACH,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,yEAAyE;IACzE,KAAK,CAAC,wBAAwB,CAAC,KAA6B;QAC1D,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,iCAAwB,CAAC,CAAC;QAC1D,MAAM,SAAS,GAAG,MAAM,KAAK,CAAC,cAAc,CAAC;YAC3C,IAAI,EAAE,KAAK;SACZ,CAAC,CAAC;QACH,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AAjCD,oDAiCC;AAED;;;;;GAKG;AACH,SAAgB,oBAAoB,CAAC,SAAiB;IACpD,OAAO,IAAI,oBAAoB,CAAC,SAAS,CAAC,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Pub/Sub topic for cross-solution traceability edge events */
|
|
2
|
+
export declare const TRACEABILITY_EDGES_TOPIC = "traceability-edges";
|
|
3
|
+
/** Pub/Sub topic for embedding sync events triggered by artifact changes */
|
|
4
|
+
export declare const EMBEDDING_SYNC_TOPIC = "embedding-sync";
|
|
5
|
+
/** Pub/Sub topic for cache invalidation events */
|
|
6
|
+
export declare const CACHE_INVALIDATION_TOPIC = "cache-invalidation";
|
|
7
|
+
//# sourceMappingURL=topics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"topics.d.ts","sourceRoot":"","sources":["../../src/events/topics.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,eAAO,MAAM,wBAAwB,uBAAuB,CAAC;AAE7D,4EAA4E;AAC5E,eAAO,MAAM,oBAAoB,mBAAmB,CAAC;AAErD,kDAAkD;AAClD,eAAO,MAAM,wBAAwB,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CACHE_INVALIDATION_TOPIC = exports.EMBEDDING_SYNC_TOPIC = exports.TRACEABILITY_EDGES_TOPIC = void 0;
|
|
4
|
+
/** Pub/Sub topic for cross-solution traceability edge events */
|
|
5
|
+
exports.TRACEABILITY_EDGES_TOPIC = 'traceability-edges';
|
|
6
|
+
/** Pub/Sub topic for embedding sync events triggered by artifact changes */
|
|
7
|
+
exports.EMBEDDING_SYNC_TOPIC = 'embedding-sync';
|
|
8
|
+
/** Pub/Sub topic for cache invalidation events */
|
|
9
|
+
exports.CACHE_INVALIDATION_TOPIC = 'cache-invalidation';
|
|
10
|
+
//# sourceMappingURL=topics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"topics.js","sourceRoot":"","sources":["../../src/events/topics.ts"],"names":[],"mappings":";;;AAAA,gEAAgE;AACnD,QAAA,wBAAwB,GAAG,oBAAoB,CAAC;AAE7D,4EAA4E;AAC/D,QAAA,oBAAoB,GAAG,gBAAgB,CAAC;AAErD,kDAAkD;AACrC,QAAA,wBAAwB,GAAG,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event payload published when a cross-solution traceability edge is created or modified.
|
|
3
|
+
* Published to the `traceability-edges` Pub/Sub topic.
|
|
4
|
+
*/
|
|
5
|
+
export interface TraceabilityEdgeEvent {
|
|
6
|
+
/** URI of the source artifact */
|
|
7
|
+
source_uri: string;
|
|
8
|
+
/** Cross-solution relationship type */
|
|
9
|
+
relationship: string;
|
|
10
|
+
/** URI of the target artifact */
|
|
11
|
+
target_uri: string;
|
|
12
|
+
/** Solution code of the source artifact */
|
|
13
|
+
source_solution: string;
|
|
14
|
+
/** Solution code of the target artifact */
|
|
15
|
+
target_solution: string;
|
|
16
|
+
/** Project identifier */
|
|
17
|
+
project_id: string;
|
|
18
|
+
/** ISO 8601 timestamp of when the event occurred */
|
|
19
|
+
timestamp: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Event payload published when an artifact's content changes and embeddings need regeneration.
|
|
23
|
+
* Published to the `embedding-sync` Pub/Sub topic.
|
|
24
|
+
*/
|
|
25
|
+
export interface EmbeddingSyncEvent {
|
|
26
|
+
/** URI of the artifact whose content changed */
|
|
27
|
+
artifact_uri: string;
|
|
28
|
+
/** Updated artifact content to chunk and embed */
|
|
29
|
+
content: string;
|
|
30
|
+
/** Content type for chunking strategy selection */
|
|
31
|
+
content_type: string;
|
|
32
|
+
/** Solution code of the artifact */
|
|
33
|
+
solution: string;
|
|
34
|
+
/** ISO 8601 timestamp of when the event occurred */
|
|
35
|
+
timestamp: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Event payload published when cached data needs invalidation.
|
|
39
|
+
* Published to the `cache-invalidation` Pub/Sub topic.
|
|
40
|
+
*/
|
|
41
|
+
export interface CacheInvalidationEvent {
|
|
42
|
+
/** URIs of artifacts whose cached data should be invalidated */
|
|
43
|
+
affected_uris: string[];
|
|
44
|
+
/** Human-readable reason for the invalidation */
|
|
45
|
+
reason: string;
|
|
46
|
+
/** ISO 8601 timestamp of when the event occurred */
|
|
47
|
+
timestamp: string;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/events/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,iCAAiC;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,uCAAuC;IACvC,YAAY,EAAE,MAAM,CAAC;IACrB,iCAAiC;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,2CAA2C;IAC3C,eAAe,EAAE,MAAM,CAAC;IACxB,2CAA2C;IAC3C,eAAe,EAAE,MAAM,CAAC;IACxB,yBAAyB;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,oDAAoD;IACpD,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,gDAAgD;IAChD,YAAY,EAAE,MAAM,CAAC;IACrB,kDAAkD;IAClD,OAAO,EAAE,MAAM,CAAC;IAChB,mDAAmD;IACnD,YAAY,EAAE,MAAM,CAAC;IACrB,oCAAoC;IACpC,QAAQ,EAAE,MAAM,CAAC;IACjB,oDAAoD;IACpD,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACrC,gEAAgE;IAChE,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,iDAAiD;IACjD,MAAM,EAAE,MAAM,CAAC;IACf,oDAAoD;IACpD,SAAS,EAAE,MAAM,CAAC;CACnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/events/types.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./uri"), exports);
|
|
18
|
+
__exportStar(require("./schema"), exports);
|
|
19
|
+
__exportStar(require("./relationships"), exports);
|
|
20
|
+
__exportStar(require("./events"), exports);
|
|
21
|
+
__exportStar(require("./chunking"), exports);
|
|
22
|
+
//# sourceMappingURL=index.js.map
|