@cmflow/source-pack 3.19.0 → 3.21.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/README.md +10 -11
- package/dist/bin/source-pack.mjs +8 -8
- package/dist/bin/source-pack.mjs.map +1 -1
- package/dist/buildSourcePack-59jTztr3.mjs +3 -0
- package/dist/{buildSourcePack-CaaMZ_tw.mjs → buildSourcePack-YCfD24d4.mjs} +8 -27
- package/dist/{buildSourcePack-CaaMZ_tw.mjs.map → buildSourcePack-YCfD24d4.mjs.map} +1 -1
- package/dist/{constants-DkiLCuIK.mjs → constants-o4tbCIrY.mjs} +3 -4
- package/dist/constants-o4tbCIrY.mjs.map +1 -0
- package/dist/index.d.mts +6 -23
- package/dist/index.mjs +6 -7
- package/dist/index.mjs.map +1 -1
- package/dist/{initConfig-ByGsbShR.mjs → initConfig-DawW5Lht.mjs} +2 -3
- package/dist/{initConfig-ByGsbShR.mjs.map → initConfig-DawW5Lht.mjs.map} +1 -1
- package/dist/{loadConfig-CNrL90dq.mjs → loadConfig-KYduEj2v.mjs} +3 -5
- package/dist/loadConfig-KYduEj2v.mjs.map +1 -0
- package/dist/{packageVersion-B0749hF6.mjs → packageVersion-CpvQqEy_.mjs} +2 -2
- package/dist/{packageVersion-B0749hF6.mjs.map → packageVersion-CpvQqEy_.mjs.map} +1 -1
- package/dist/{publishSourcePack-xNr9RBgv.mjs → publishSourcePack-BfPLD37B.mjs} +2 -2
- package/dist/{publishSourcePack-xNr9RBgv.mjs.map → publishSourcePack-BfPLD37B.mjs.map} +1 -1
- package/dist/publishSourcePack-BwAIlydQ.mjs +3 -0
- package/package.json +2 -1
- package/dist/buildSourcePack-DIp8G_uL.mjs +0 -3
- package/dist/constants-DkiLCuIK.mjs.map +0 -1
- package/dist/loadConfig-CNrL90dq.mjs.map +0 -1
- package/dist/publishSourcePack-Dj1cdWfT.mjs +0 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
//#region src/constants.ts
|
|
2
2
|
const PACKAGE_NAME = "@cmflow/source-pack";
|
|
3
|
-
/** Version of the archive layout (manifest, chunks, embeddings
|
|
3
|
+
/** Version of the archive layout (manifest, chunks, embeddings). */
|
|
4
4
|
const SOURCE_PACK_FORMAT_VERSION = 2;
|
|
5
5
|
/** Version of the chunking algorithm. Bump it whenever chunk boundaries or ids change. */
|
|
6
6
|
const CHUNKING_FORMAT_VERSION = 1;
|
|
@@ -9,7 +9,6 @@ const EMBEDDING_INPUT_FORMAT = "path\\ntext";
|
|
|
9
9
|
const MANIFEST_FILE = "manifest.json";
|
|
10
10
|
const CHUNKS_FILE = "chunks.jsonl.gz";
|
|
11
11
|
const EMBEDDINGS_FILE = "embeddings.f32";
|
|
12
|
-
const ATTACHMENTS_DIR = "attachments";
|
|
13
12
|
const DEFAULT_CONFIG_FILE = "source-pack.config.ts";
|
|
14
13
|
const DEFAULT_OUTPUT_DIR = "./tmp/source-pack";
|
|
15
14
|
const DEFAULT_TAG_TEMPLATE = "version-{version}";
|
|
@@ -21,5 +20,5 @@ const GITHUB_TOKEN_ENV = "GITHUB_TOKEN";
|
|
|
21
20
|
const GITLAB_TOKEN_ENV = "GITLAB_TOKEN";
|
|
22
21
|
|
|
23
22
|
//#endregion
|
|
24
|
-
export {
|
|
25
|
-
//# sourceMappingURL=constants-
|
|
23
|
+
export { SOURCE_PACK_FORMAT_VERSION as _, DEFAULT_CONFIG_FILE as a, DEFAULT_GITLAB_PACKAGE_NAME as c, EMBEDDINGS_FILE as d, EMBEDDING_INPUT_FORMAT as f, PACKAGE_NAME as g, MANIFEST_FILE as h, DEFAULT_ASSET_NAME_TEMPLATE as i, DEFAULT_OUTPUT_DIR as l, GITLAB_TOKEN_ENV as m, CHUNKS_FILE as n, DEFAULT_GITHUB_API_URL as o, GITHUB_TOKEN_ENV as p, CHUNK_ID_ALGORITHM as r, DEFAULT_GITLAB_API_URL as s, CHUNKING_FORMAT_VERSION as t, DEFAULT_TAG_TEMPLATE as u };
|
|
24
|
+
//# sourceMappingURL=constants-o4tbCIrY.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants-o4tbCIrY.mjs","names":[],"sources":["../src/constants.ts"],"sourcesContent":["export const PACKAGE_NAME = \"@cmflow/source-pack\";\n\n/** Version of the archive layout (manifest, chunks, embeddings). */\nexport const SOURCE_PACK_FORMAT_VERSION = 2;\n\n/** Version of the chunking algorithm. Bump it whenever chunk boundaries or ids change. */\nexport const CHUNKING_FORMAT_VERSION = 1;\n\nexport const CHUNK_ID_ALGORITHM = \"sha256(path:startLine:text)\";\n\nexport const EMBEDDING_INPUT_FORMAT = \"path\\\\ntext\";\n\nexport const MANIFEST_FILE = \"manifest.json\";\nexport const CHUNKS_FILE = \"chunks.jsonl.gz\";\nexport const EMBEDDINGS_FILE = \"embeddings.f32\";\n\nexport const DEFAULT_CONFIG_FILE = \"source-pack.config.ts\";\nexport const DEFAULT_OUTPUT_DIR = \"./tmp/source-pack\";\nexport const DEFAULT_TAG_TEMPLATE = \"version-{version}\";\nexport const DEFAULT_ASSET_NAME_TEMPLATE = \"source-pack-{version}.tar.gz\";\nexport const DEFAULT_GITLAB_PACKAGE_NAME = \"source-pack\";\nexport const DEFAULT_GITHUB_API_URL = \"https://api.github.com\";\nexport const DEFAULT_GITLAB_API_URL = \"https://gitlab.com/api/v4\";\nexport const GITHUB_TOKEN_ENV = \"GITHUB_TOKEN\";\nexport const GITLAB_TOKEN_ENV = \"GITLAB_TOKEN\";\n"],"mappings":";AAAA,MAAa,eAAe;;AAG5B,MAAa,6BAA6B;;AAG1C,MAAa,0BAA0B;AAEvC,MAAa,qBAAqB;AAElC,MAAa,yBAAyB;AAEtC,MAAa,gBAAgB;AAC7B,MAAa,cAAc;AAC3B,MAAa,kBAAkB;AAE/B,MAAa,sBAAsB;AACnC,MAAa,qBAAqB;AAClC,MAAa,uBAAuB;AACpC,MAAa,8BAA8B;AAC3C,MAAa,8BAA8B;AAC3C,MAAa,yBAAyB;AACtC,MAAa,yBAAyB;AACtC,MAAa,mBAAmB;AAChC,MAAa,mBAAmB"}
|
package/dist/index.d.mts
CHANGED
|
@@ -66,8 +66,6 @@ interface UserConfig {
|
|
|
66
66
|
chunking?: ChunkingConfig;
|
|
67
67
|
/** Omit to build a lexical-only pack (no embeddings.f32). */
|
|
68
68
|
embedding?: EmbeddingConfig;
|
|
69
|
-
/** Git-tracked files copied verbatim into the pack under `attachments/`. */
|
|
70
|
-
attachments?: string[];
|
|
71
69
|
publish?: PublishConfig;
|
|
72
70
|
}
|
|
73
71
|
//#endregion
|
|
@@ -97,14 +95,6 @@ interface SourcePackProject {
|
|
|
97
95
|
projectId?: string;
|
|
98
96
|
apiUrl: string;
|
|
99
97
|
}
|
|
100
|
-
interface SourcePackAttachment {
|
|
101
|
-
/** Path in the repository */
|
|
102
|
-
path: string;
|
|
103
|
-
/** Path inside the archive */
|
|
104
|
-
file: string;
|
|
105
|
-
bytes: number;
|
|
106
|
-
sha256: string;
|
|
107
|
-
}
|
|
108
98
|
interface SourcePackEmbeddingInfo {
|
|
109
99
|
/** Reference model (never the regional alias actually called) */
|
|
110
100
|
model: string;
|
|
@@ -157,7 +147,6 @@ interface SourcePackManifest {
|
|
|
157
147
|
count: number;
|
|
158
148
|
file: string;
|
|
159
149
|
};
|
|
160
|
-
attachments: SourcePackAttachment[];
|
|
161
150
|
publish: {
|
|
162
151
|
assetName: string;
|
|
163
152
|
};
|
|
@@ -169,8 +158,6 @@ interface SourcePack {
|
|
|
169
158
|
chunks: SourceChunk[];
|
|
170
159
|
/** All vectors, concatenated in chunk order (`chunks.length * dimensions` floats), or null for a pack built without embeddings. */
|
|
171
160
|
embeddings: Float32Array | null;
|
|
172
|
-
/** Attachments keyed by their repository path. */
|
|
173
|
-
attachments: Map<string, Buffer>;
|
|
174
161
|
/** Vector of the chunk at `index` (a view on `embeddings`), or null. */
|
|
175
162
|
getEmbedding(index: number): Float32Array | null;
|
|
176
163
|
}
|
|
@@ -225,7 +212,6 @@ interface ResolvedConfig {
|
|
|
225
212
|
overlap: number;
|
|
226
213
|
};
|
|
227
214
|
embedding: ResolvedEmbeddingConfig | null;
|
|
228
|
-
attachments: string[];
|
|
229
215
|
publish: ResolvedPublishConfig;
|
|
230
216
|
}
|
|
231
217
|
//#endregion
|
|
@@ -259,12 +245,12 @@ interface BuildSourcePackResult {
|
|
|
259
245
|
chunks: SourceChunk[];
|
|
260
246
|
dryRun: boolean;
|
|
261
247
|
archivePath?: string;
|
|
262
|
-
/** Archive size (or estimate in dry-run: gzipped chunks + raw embeddings
|
|
248
|
+
/** Archive size (or estimate in dry-run: gzipped chunks + raw embeddings). */
|
|
263
249
|
bytes: number;
|
|
264
250
|
chunksBytes: number;
|
|
265
251
|
embeddingsBytes: number;
|
|
266
252
|
}
|
|
267
|
-
/** Builds the source pack of `config.repository` at a commit: chunks + embeddings +
|
|
253
|
+
/** Builds the source pack of `config.repository` at a commit: chunks + embeddings + manifest. */
|
|
268
254
|
declare function buildSourcePack(options: BuildSourcePackOptions): Promise<BuildSourcePackResult>;
|
|
269
255
|
//#endregion
|
|
270
256
|
//#region src/pack/writeSourcePack.d.ts
|
|
@@ -273,8 +259,6 @@ interface WriteSourcePackOptions {
|
|
|
273
259
|
manifest: SourcePackManifest;
|
|
274
260
|
chunks: SourceChunk[];
|
|
275
261
|
embeddings: Float32Array | null;
|
|
276
|
-
/** Keyed by the archive path declared in `manifest.attachments[].file` */
|
|
277
|
-
attachments: Map<string, Buffer>;
|
|
278
262
|
}
|
|
279
263
|
interface WrittenSourcePack {
|
|
280
264
|
archivePath: string;
|
|
@@ -282,8 +266,8 @@ interface WrittenSourcePack {
|
|
|
282
266
|
chunksBytes: number;
|
|
283
267
|
embeddingsBytes: number;
|
|
284
268
|
}
|
|
285
|
-
/** Writes `manifest.json`, `chunks.jsonl.gz
|
|
286
|
-
declare function writeSourcePack({ archivePath, manifest, chunks, embeddings
|
|
269
|
+
/** Writes `manifest.json`, `chunks.jsonl.gz` and `embeddings.f32` into a deterministic `.tar.gz`. */
|
|
270
|
+
declare function writeSourcePack({ archivePath, manifest, chunks, embeddings }: WriteSourcePackOptions): Promise<WrittenSourcePack>;
|
|
287
271
|
//#endregion
|
|
288
272
|
//#region src/publish/interfaces/PublishContext.d.ts
|
|
289
273
|
interface PublishResult {
|
|
@@ -373,7 +357,7 @@ declare function embedTexts(inputs: string[], { config, apiKey, fetch, logger }:
|
|
|
373
357
|
//#endregion
|
|
374
358
|
//#region src/constants.d.ts
|
|
375
359
|
declare const PACKAGE_NAME = "@cmflow/source-pack";
|
|
376
|
-
/** Version of the archive layout (manifest, chunks, embeddings
|
|
360
|
+
/** Version of the archive layout (manifest, chunks, embeddings). */
|
|
377
361
|
declare const SOURCE_PACK_FORMAT_VERSION = 2;
|
|
378
362
|
/** Version of the chunking algorithm. Bump it whenever chunk boundaries or ids change. */
|
|
379
363
|
declare const CHUNKING_FORMAT_VERSION = 1;
|
|
@@ -382,7 +366,6 @@ declare const EMBEDDING_INPUT_FORMAT = "path\\ntext";
|
|
|
382
366
|
declare const MANIFEST_FILE = "manifest.json";
|
|
383
367
|
declare const CHUNKS_FILE = "chunks.jsonl.gz";
|
|
384
368
|
declare const EMBEDDINGS_FILE = "embeddings.f32";
|
|
385
|
-
declare const ATTACHMENTS_DIR = "attachments";
|
|
386
369
|
declare const DEFAULT_CONFIG_FILE = "source-pack.config.ts";
|
|
387
370
|
declare const DEFAULT_OUTPUT_DIR = "./tmp/source-pack";
|
|
388
371
|
declare const DEFAULT_TAG_TEMPLATE = "version-{version}";
|
|
@@ -393,5 +376,5 @@ declare const DEFAULT_GITLAB_API_URL = "https://gitlab.com/api/v4";
|
|
|
393
376
|
declare const GITHUB_TOKEN_ENV = "GITHUB_TOKEN";
|
|
394
377
|
declare const GITLAB_TOKEN_ENV = "GITLAB_TOKEN";
|
|
395
378
|
//#endregion
|
|
396
|
-
export {
|
|
379
|
+
export { type BuildSourcePackOptions, type BuildSourcePackResult, CHUNKING_FORMAT_VERSION, CHUNKS_FILE, CHUNK_ID_ALGORITHM, type ChunkingConfig, DEFAULT_ASSET_NAME_TEMPLATE, DEFAULT_CONFIG_FILE, DEFAULT_GITHUB_API_URL, DEFAULT_GITLAB_API_URL, DEFAULT_GITLAB_PACKAGE_NAME, DEFAULT_OUTPUT_DIR, DEFAULT_TAG_TEMPLATE, EMBEDDINGS_FILE, EMBEDDING_INPUT_FORMAT, type EmbeddingConfig, GITHUB_TOKEN_ENV, GITLAB_TOKEN_ENV, MANIFEST_FILE, PACKAGE_NAME, type PublishConfig, type PublishResult, type PublishSourcePackOptions, type RepositoryConfig, type RepositoryProvider, type ResolvedConfig, type ResolvedEmbeddingConfig, type ResolvedPublishConfig, type ResolvedRepositoryConfig, SOURCE_PACK_FORMAT_VERSION, type SourceChunk, type SourcePack, type SourcePackEmbeddingInfo, type SourcePackManifest, type SourcePackProject, type SourcesConfig, type UserConfig, buildSourcePack, chunkText, configFingerprint, defineConfig, embedTexts, embeddingInput, loadConfig, publishSourcePack, readSourcePack, resolveConfig, writeSourcePack };
|
|
397
380
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { _ as
|
|
2
|
-
import { n as resolveConfig, t as loadConfig } from "./loadConfig-
|
|
3
|
-
import { n as readArchiveEntries, t as publishSourcePack } from "./publishSourcePack-
|
|
4
|
-
import { a as configFingerprint, i as embeddingInput, n as writeSourcePack, o as chunkText, r as embedTexts, t as buildSourcePack } from "./buildSourcePack-
|
|
1
|
+
import { _ as SOURCE_PACK_FORMAT_VERSION, a as DEFAULT_CONFIG_FILE, c as DEFAULT_GITLAB_PACKAGE_NAME, d as EMBEDDINGS_FILE, f as EMBEDDING_INPUT_FORMAT, g as PACKAGE_NAME, h as MANIFEST_FILE, i as DEFAULT_ASSET_NAME_TEMPLATE, l as DEFAULT_OUTPUT_DIR, m as GITLAB_TOKEN_ENV, n as CHUNKS_FILE, o as DEFAULT_GITHUB_API_URL, p as GITHUB_TOKEN_ENV, r as CHUNK_ID_ALGORITHM, s as DEFAULT_GITLAB_API_URL, t as CHUNKING_FORMAT_VERSION, u as DEFAULT_TAG_TEMPLATE } from "./constants-o4tbCIrY.mjs";
|
|
2
|
+
import { n as resolveConfig, t as loadConfig } from "./loadConfig-KYduEj2v.mjs";
|
|
3
|
+
import { n as readArchiveEntries, t as publishSourcePack } from "./publishSourcePack-BfPLD37B.mjs";
|
|
4
|
+
import { a as configFingerprint, i as embeddingInput, n as writeSourcePack, o as chunkText, r as embedTexts, t as buildSourcePack } from "./buildSourcePack-YCfD24d4.mjs";
|
|
5
5
|
import { promisify } from "node:util";
|
|
6
6
|
import { gunzip } from "node:zlib";
|
|
7
7
|
|
|
@@ -50,7 +50,7 @@ function readEmbeddings(files, manifest) {
|
|
|
50
50
|
*/
|
|
51
51
|
async function readSourcePack(source) {
|
|
52
52
|
const files = await readArchiveEntries(source);
|
|
53
|
-
const manifest = JSON.parse(required(files, MANIFEST_FILE).toString("utf8"));
|
|
53
|
+
const { attachments: _legacyAttachments, ...manifest } = JSON.parse(required(files, MANIFEST_FILE).toString("utf8"));
|
|
54
54
|
if (manifest.formatVersion !== 2) throw new Error(`Unsupported source pack format ${manifest.formatVersion} (this reader supports ${2})`);
|
|
55
55
|
const chunks = (await gunzipAsync(required(files, manifest.chunks.file))).toString("utf8").split("\n").filter(Boolean).map((line) => JSON.parse(line));
|
|
56
56
|
if (chunks.length !== manifest.chunks.count) throw new Error(`Invalid source pack: manifest declares ${manifest.chunks.count} chunks, found ${chunks.length}`);
|
|
@@ -60,7 +60,6 @@ async function readSourcePack(source) {
|
|
|
60
60
|
manifest,
|
|
61
61
|
chunks,
|
|
62
62
|
embeddings,
|
|
63
|
-
attachments: new Map(manifest.attachments.map((attachment) => [attachment.path, required(files, attachment.file)])),
|
|
64
63
|
getEmbedding(index) {
|
|
65
64
|
if (!embeddings || index < 0 || index >= chunks.length) return null;
|
|
66
65
|
return embeddings.subarray(index * dimensions, (index + 1) * dimensions);
|
|
@@ -69,5 +68,5 @@ async function readSourcePack(source) {
|
|
|
69
68
|
}
|
|
70
69
|
|
|
71
70
|
//#endregion
|
|
72
|
-
export {
|
|
71
|
+
export { CHUNKING_FORMAT_VERSION, CHUNKS_FILE, CHUNK_ID_ALGORITHM, DEFAULT_ASSET_NAME_TEMPLATE, DEFAULT_CONFIG_FILE, DEFAULT_GITHUB_API_URL, DEFAULT_GITLAB_API_URL, DEFAULT_GITLAB_PACKAGE_NAME, DEFAULT_OUTPUT_DIR, DEFAULT_TAG_TEMPLATE, EMBEDDINGS_FILE, EMBEDDING_INPUT_FORMAT, GITHUB_TOKEN_ENV, GITLAB_TOKEN_ENV, MANIFEST_FILE, PACKAGE_NAME, SOURCE_PACK_FORMAT_VERSION, buildSourcePack, chunkText, configFingerprint, defineConfig, embedTexts, embeddingInput, loadConfig, publishSourcePack, readSourcePack, resolveConfig, writeSourcePack };
|
|
73
72
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/fn/defineConfig.ts","../src/pack/decodeEmbeddings.ts","../src/pack/readSourcePack.ts"],"sourcesContent":["import type { UserConfig } from \"../config/interfaces/UserConfig\";\n\nexport function defineConfig(config: UserConfig): UserConfig {\n return config;\n}\n","const LITTLE_ENDIAN_HOST = new Uint8Array(new Uint16Array([1]).buffer)[0] === 1;\n\n/**\n * Inverse of `encodeEmbeddings`. On a little-endian host the result is a view on the bytes when they are 4-byte aligned\n * (one copy otherwise); a big-endian host decodes every value.\n */\nexport function decodeEmbeddings(buffer: Uint8Array, littleEndianHost = LITTLE_ENDIAN_HOST): Float32Array {\n if (buffer.byteLength % 4 !== 0) {\n throw new Error(`Invalid embeddings file: ${buffer.byteLength} bytes is not a multiple of 4`);\n }\n\n if (littleEndianHost) {\n const aligned = buffer.byteOffset % 4 === 0 ? buffer : new Uint8Array(buffer);\n\n return new Float32Array(aligned.buffer, aligned.byteOffset, aligned.byteLength / 4);\n }\n\n const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);\n const vectors = new Float32Array(buffer.byteLength / 4);\n\n for (let index = 0; index < vectors.length; index += 1) {\n vectors[index] = view.getFloat32(index * 4, true);\n }\n\n return vectors;\n}\n","import { promisify } from \"node:util\";\nimport { gunzip } from \"node:zlib\";\nimport { MANIFEST_FILE, SOURCE_PACK_FORMAT_VERSION } from \"../constants\";\nimport type { SourceChunk } from \"../interfaces/SourceChunk\";\nimport type { SourcePack } from \"../interfaces/SourcePack\";\nimport type { SourcePackManifest } from \"../interfaces/SourcePackManifest\";\nimport { decodeEmbeddings } from \"./decodeEmbeddings\";\nimport { readArchiveEntries } from \"./readArchiveEntries\";\n\nconst gunzipAsync = promisify(gunzip);\n\nfunction required(files: Map<string, Buffer>, name: string): Buffer {\n const file = files.get(name);\n\n if (!file) {\n throw new Error(`Invalid source pack: ${name} is missing`);\n }\n\n return file;\n}\n\nfunction readEmbeddings(files: Map<string, Buffer>, manifest: SourcePackManifest): Float32Array | null {\n const { embedding, chunks } = manifest;\n\n if (!embedding) {\n return null;\n }\n\n const embeddings = decodeEmbeddings(required(files, embedding.file));\n\n if (embeddings.length !== chunks.count * embedding.dimensions) {\n throw new Error(`Invalid source pack: expected ${chunks.count} x ${embedding.dimensions} floats, found ${embeddings.length}`);\n }\n\n return embeddings;\n}\n\n/**\n * Reads a `source-pack-<version>.tar.gz` (file path or bytes) and checks its consistency\n * (format version, chunk count, embedding size).\n */\nexport async function readSourcePack(source: string | Uint8Array): Promise<SourcePack> {\n const files = await readArchiveEntries(source);\n const
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/fn/defineConfig.ts","../src/pack/decodeEmbeddings.ts","../src/pack/readSourcePack.ts"],"sourcesContent":["import type { UserConfig } from \"../config/interfaces/UserConfig\";\n\nexport function defineConfig(config: UserConfig): UserConfig {\n return config;\n}\n","const LITTLE_ENDIAN_HOST = new Uint8Array(new Uint16Array([1]).buffer)[0] === 1;\n\n/**\n * Inverse of `encodeEmbeddings`. On a little-endian host the result is a view on the bytes when they are 4-byte aligned\n * (one copy otherwise); a big-endian host decodes every value.\n */\nexport function decodeEmbeddings(buffer: Uint8Array, littleEndianHost = LITTLE_ENDIAN_HOST): Float32Array {\n if (buffer.byteLength % 4 !== 0) {\n throw new Error(`Invalid embeddings file: ${buffer.byteLength} bytes is not a multiple of 4`);\n }\n\n if (littleEndianHost) {\n const aligned = buffer.byteOffset % 4 === 0 ? buffer : new Uint8Array(buffer);\n\n return new Float32Array(aligned.buffer, aligned.byteOffset, aligned.byteLength / 4);\n }\n\n const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);\n const vectors = new Float32Array(buffer.byteLength / 4);\n\n for (let index = 0; index < vectors.length; index += 1) {\n vectors[index] = view.getFloat32(index * 4, true);\n }\n\n return vectors;\n}\n","import { promisify } from \"node:util\";\nimport { gunzip } from \"node:zlib\";\nimport { MANIFEST_FILE, SOURCE_PACK_FORMAT_VERSION } from \"../constants\";\nimport type { SourceChunk } from \"../interfaces/SourceChunk\";\nimport type { SourcePack } from \"../interfaces/SourcePack\";\nimport type { SourcePackManifest } from \"../interfaces/SourcePackManifest\";\nimport { decodeEmbeddings } from \"./decodeEmbeddings\";\nimport { readArchiveEntries } from \"./readArchiveEntries\";\n\nconst gunzipAsync = promisify(gunzip);\n\nfunction required(files: Map<string, Buffer>, name: string): Buffer {\n const file = files.get(name);\n\n if (!file) {\n throw new Error(`Invalid source pack: ${name} is missing`);\n }\n\n return file;\n}\n\nfunction readEmbeddings(files: Map<string, Buffer>, manifest: SourcePackManifest): Float32Array | null {\n const { embedding, chunks } = manifest;\n\n if (!embedding) {\n return null;\n }\n\n const embeddings = decodeEmbeddings(required(files, embedding.file));\n\n if (embeddings.length !== chunks.count * embedding.dimensions) {\n throw new Error(`Invalid source pack: expected ${chunks.count} x ${embedding.dimensions} floats, found ${embeddings.length}`);\n }\n\n return embeddings;\n}\n\n/**\n * Reads a `source-pack-<version>.tar.gz` (file path or bytes) and checks its consistency\n * (format version, chunk count, embedding size).\n */\nexport async function readSourcePack(source: string | Uint8Array): Promise<SourcePack> {\n const files = await readArchiveEntries(source);\n const parsed = JSON.parse(required(files, MANIFEST_FILE).toString(\"utf8\")) as SourcePackManifest & { attachments?: unknown };\n // Packs built by @cmflow/source-pack 3.19-3.20 may carry `manifest.attachments` and an `attachments/` directory: both are ignored.\n const { attachments: _legacyAttachments, ...manifest } = parsed;\n\n if (manifest.formatVersion !== SOURCE_PACK_FORMAT_VERSION) {\n throw new Error(`Unsupported source pack format ${manifest.formatVersion} (this reader supports ${SOURCE_PACK_FORMAT_VERSION})`);\n }\n\n const chunks = (await gunzipAsync(required(files, manifest.chunks.file)))\n .toString(\"utf8\")\n .split(\"\\n\")\n .filter(Boolean)\n .map((line) => JSON.parse(line) as SourceChunk);\n\n if (chunks.length !== manifest.chunks.count) {\n throw new Error(`Invalid source pack: manifest declares ${manifest.chunks.count} chunks, found ${chunks.length}`);\n }\n\n const embeddings = readEmbeddings(files, manifest);\n const dimensions = manifest.embedding?.dimensions ?? 0;\n\n return {\n manifest,\n chunks,\n embeddings,\n getEmbedding(index) {\n if (!embeddings || index < 0 || index >= chunks.length) {\n return null;\n }\n\n return embeddings.subarray(index * dimensions, (index + 1) * dimensions);\n }\n };\n}\n"],"mappings":";;;;;;;;AAEA,SAAgB,aAAa,QAAgC;CAC3D,OAAO;AACT;;;;ACJA,MAAM,qBAAqB,IAAI,WAAW,IAAI,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,OAAO;;;;;AAM9E,SAAgB,iBAAiB,QAAoB,mBAAmB,oBAAkC;CACxG,IAAI,OAAO,aAAa,MAAM,GAC5B,MAAM,IAAI,MAAM,4BAA4B,OAAO,WAAW,8BAA8B;CAG9F,IAAI,kBAAkB;EACpB,MAAM,UAAU,OAAO,aAAa,MAAM,IAAI,SAAS,I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SAAS,KAAK,MAAM,IAAI,CAAgB;CAEhD,IAAI,OAAO,WAAW,SAAS,OAAO,OACpC,MAAM,IAAI,MAAM,0CAA0C,SAAS,OAAO,MAAM,iBAAiB,OAAO,QAAQ;CAGlH,MAAM,aAAa,eAAe,OAAO,QAAQ;CACjD,MAAM,aAAa,SAAS,WAAW,cAAc;CAErD,OAAO;EACL;EACA;EACA;EACA,aAAa,OAAO;GAClB,IAAI,CAAC,cAAc,QAAQ,KAAK,SAAS,OAAO,QAC9C,OAAO;GAGT,OAAO,WAAW,SAAS,QAAQ,aAAa,QAAQ,KAAK,UAAU;EACzE;CACF;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { i as DEFAULT_ASSET_NAME_TEMPLATE, l as DEFAULT_OUTPUT_DIR, m as GITLAB_TOKEN_ENV, o as DEFAULT_GITHUB_API_URL, p as GITHUB_TOKEN_ENV, s as DEFAULT_GITLAB_API_URL, u as DEFAULT_TAG_TEMPLATE } from "./constants-o4tbCIrY.mjs";
|
|
2
2
|
import { a as DEFAULT_INCLUDE, c as LOCKFILES_BY_ECOSYSTEM, i as DEFAULT_EXCLUDE, l as NODE_DEPENDENCY_DIRS, n as DEFAULT_API_KEY_ENV, r as DEFAULT_DIMENSIONS, t as BUILD_OUTPUT_DIRS, u as TEST_FILES_BY_ECOSYSTEM } from "./defaults-BJs7a37e.mjs";
|
|
3
3
|
import { t as GitRepository } from "./GitRepository-VTAWT6j4.mjs";
|
|
4
4
|
import path from "node:path";
|
|
@@ -147,7 +147,6 @@ export default defineConfig({
|
|
|
147
147
|
dimensions: ${DEFAULT_DIMENSIONS},
|
|
148
148
|
batchSize: ${64}
|
|
149
149
|
},
|
|
150
|
-
attachments: [],
|
|
151
150
|
publish: {
|
|
152
151
|
tag: ${JSON.stringify(DEFAULT_TAG_TEMPLATE)},
|
|
153
152
|
assetName: ${JSON.stringify(DEFAULT_ASSET_NAME_TEMPLATE)}
|
|
@@ -182,4 +181,4 @@ async function initConfig({ configPath, force = false }) {
|
|
|
182
181
|
|
|
183
182
|
//#endregion
|
|
184
183
|
export { initConfig };
|
|
185
|
-
//# sourceMappingURL=initConfig-
|
|
184
|
+
//# sourceMappingURL=initConfig-DawW5Lht.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initConfig-ByGsbShR.mjs","names":[],"sources":["../src/git/parseRemoteUrl.ts","../src/init/detectProjectType.ts","../src/init/projectPresets.ts","../src/init/generateConfigSource.ts","../src/commands/initConfig.ts"],"sourcesContent":["import type { RepositoryProvider } from \"../config/interfaces/UserConfig\";\n\nexport interface ParsedRemote {\n provider: RepositoryProvider;\n host: string;\n owner: string;\n name: string;\n}\n\n/**\n * Parses an SSH (`git@host:owner/name.git`, `ssh://git@host:22/owner/name.git`) or HTTPS remote URL.\n * GitLab owners may contain subgroups (`group/sub`). Returns undefined for unknown hosts.\n */\nexport function parseRemoteUrl(remote: string): ParsedRemote | undefined {\n const trimmed = remote.trim();\n const scp = /^(?:[\\w.-]+@)?([\\w.-]+):(?!\\/\\/)(.+)$/.exec(trimmed);\n let host: string;\n let pathname: string;\n\n if (scp && !/^[a-z]+:\\/\\//i.test(trimmed)) {\n host = scp[1]!;\n pathname = scp[2]!;\n } else {\n try {\n const url = new URL(trimmed);\n host = url.hostname;\n pathname = url.pathname;\n } catch {\n return undefined;\n }\n }\n\n const segments = pathname\n .replace(/\\.git\\/?$/, \"\")\n .split(\"/\")\n .filter(Boolean);\n\n if (segments.length < 2) {\n return undefined;\n }\n\n const provider: RepositoryProvider | undefined = /(^|\\.)github\\./i.test(host) ? \"github\" : /gitlab/i.test(host) ? \"gitlab\" : undefined;\n\n if (!provider) {\n return undefined;\n }\n\n return { provider, host, owner: segments.slice(0, -1).join(\"/\"), name: segments.at(-1)! };\n}\n","import { existsSync } from \"node:fs\";\nimport path from \"node:path\";\n\nexport type ProjectType = \"node\" | \"python\" | \"jvm\" | \"go\" | \"generic\";\n\nconst MARKERS: Array<[ProjectType, string[]]> = [\n [\"node\", [\"package.json\"]],\n [\"python\", [\"pyproject.toml\", \"requirements.txt\", \"setup.py\"]],\n [\"jvm\", [\"pom.xml\", \"build.gradle\", \"build.gradle.kts\"]],\n [\"go\", [\"go.mod\"]]\n];\n\nexport function detectProjectType(directory: string): ProjectType {\n return MARKERS.find(([, files]) => files.some((file) => existsSync(path.join(directory, file))))?.[0] ?? \"generic\";\n}\n","import {\n BUILD_OUTPUT_DIRS,\n DEFAULT_EXCLUDE,\n DEFAULT_INCLUDE,\n LOCKFILES_BY_ECOSYSTEM,\n NODE_DEPENDENCY_DIRS,\n TEST_FILES_BY_ECOSYSTEM\n} from \"../config/defaults\";\nimport type { ProjectType } from \"./detectProjectType\";\n\nexport interface ProjectPreset {\n include: string[];\n exclude: string[];\n}\n\nexport const PROJECT_PRESETS: Record<ProjectType, ProjectPreset> = {\n node: {\n include: [\"**/*.{ts,tsx,mts,cts,js,jsx,mjs,cjs,json,yaml,yml,md,feature,graphql}\"],\n exclude: [...NODE_DEPENDENCY_DIRS, ...BUILD_OUTPUT_DIRS, ...LOCKFILES_BY_ECOSYSTEM.node, ...TEST_FILES_BY_ECOSYSTEM.node]\n },\n python: {\n include: [\"**/*.{py,pyi,toml,cfg,ini,json,yaml,yml,md}\"],\n exclude: [\n \"**/.venv/**\",\n \"**/venv/**\",\n \"**/__pycache__/**\",\n ...BUILD_OUTPUT_DIRS,\n ...LOCKFILES_BY_ECOSYSTEM.python,\n ...TEST_FILES_BY_ECOSYSTEM.python\n ]\n },\n jvm: {\n include: [\"**/*.{java,kt,kts,groovy,gradle,xml,properties,json,yaml,yml,md}\"],\n exclude: [\"**/target/**\", \"**/.gradle/**\", ...BUILD_OUTPUT_DIRS, ...LOCKFILES_BY_ECOSYSTEM.jvm, ...TEST_FILES_BY_ECOSYSTEM.jvm]\n },\n go: {\n include: [\"**/*.{go,mod,json,yaml,yml,md,sql}\"],\n exclude: [\"**/vendor/**\", \"**/bin/**\", ...BUILD_OUTPUT_DIRS, ...LOCKFILES_BY_ECOSYSTEM.go, ...TEST_FILES_BY_ECOSYSTEM.go]\n },\n generic: { include: DEFAULT_INCLUDE, exclude: DEFAULT_EXCLUDE }\n};\n","import {\n DEFAULT_API_KEY_ENV,\n DEFAULT_BATCH_SIZE,\n DEFAULT_CHUNK_LINES,\n DEFAULT_CHUNK_OVERLAP,\n DEFAULT_DIMENSIONS\n} from \"../config/defaults\";\nimport {\n DEFAULT_ASSET_NAME_TEMPLATE,\n DEFAULT_GITHUB_API_URL,\n DEFAULT_GITLAB_API_URL,\n DEFAULT_OUTPUT_DIR,\n DEFAULT_TAG_TEMPLATE,\n GITHUB_TOKEN_ENV,\n GITLAB_TOKEN_ENV\n} from \"../constants\";\nimport type { ParsedRemote } from \"../git/parseRemoteUrl\";\nimport type { ProjectType } from \"./detectProjectType\";\nimport { PROJECT_PRESETS } from \"./projectPresets\";\n\nexport interface GenerateConfigSourceOptions {\n remote?: ParsedRemote;\n projectType: ProjectType;\n}\n\nfunction list(values: string[], indent: string): string {\n return `[\\n${values.map((value) => `${indent} ${JSON.stringify(value)}`).join(\",\\n\")}\\n${indent}]`;\n}\n\nfunction apiUrlLine(remote: ParsedRemote | undefined): string {\n if (remote?.provider === \"gitlab\") {\n return remote.host === \"gitlab.com\"\n ? `// apiUrl: ${JSON.stringify(DEFAULT_GITLAB_API_URL)}`\n : `apiUrl: ${JSON.stringify(`https://${remote.host}/api/v4`)}`;\n }\n\n return remote && remote.host !== \"github.com\"\n ? `apiUrl: ${JSON.stringify(`https://${remote.host}/api/v3`)}`\n : `// apiUrl: ${JSON.stringify(DEFAULT_GITHUB_API_URL)}`;\n}\n\nfunction repositoryBlock(remote: ParsedRemote | undefined): string {\n const fields = [\n `provider: ${JSON.stringify(remote?.provider ?? \"github\")}`,\n `owner: ${JSON.stringify(remote?.owner ?? \"TODO-owner\")}`,\n `name: ${JSON.stringify(remote?.name ?? \"TODO-repository\")}`\n ];\n const apiUrl = apiUrlLine(remote);\n const lines = apiUrl.startsWith(\"//\") ? [fields.join(\",\\n \"), apiUrl] : [[...fields, apiUrl].join(\",\\n \")];\n\n return `{\\n ${lines.join(\"\\n \")}\\n }`;\n}\n\n/** Source of a default `source-pack.config.ts`, deduced from the Git remote and the project type. */\nexport function generateConfigSource({ remote, projectType }: GenerateConfigSourceOptions): string {\n const preset = PROJECT_PRESETS[projectType];\n\n return `import { defineConfig } from \"@cmflow/source-pack\";\n\n// Secrets are read from the environment only: ${DEFAULT_API_KEY_ENV} (embeddings), ${remote?.provider === \"gitlab\" ? GITLAB_TOKEN_ENV : GITHUB_TOKEN_ENV} (publish).\nexport default defineConfig({\n outputDir: ${JSON.stringify(DEFAULT_OUTPUT_DIR)},\n repository: ${repositoryBlock(remote)},\n sources: {\n include: ${list(preset.include, \" \")},\n // Adjust to the project: generated data, fixtures, mocks, vendored code...\n exclude: ${list(preset.exclude, \" \")}\n },\n chunking: { lines: ${DEFAULT_CHUNK_LINES}, overlap: ${DEFAULT_CHUNK_OVERLAP} },\n embedding: {\n baseUrl: \"https://apim-prdaiplatform-frc.azure-api.net/litellm-api\",\n model: \"text-embedding-3-small-gmdt\",\n fallbackModels: [\"text-embedding-3-small-swc-gmdt\", \"text-embedding-3-small-eus2-gmdt\"],\n referenceModel: \"text-embedding-3-small\",\n dimensions: ${DEFAULT_DIMENSIONS},\n batchSize: ${DEFAULT_BATCH_SIZE}\n },\n attachments: [],\n publish: {\n tag: ${JSON.stringify(DEFAULT_TAG_TEMPLATE)},\n assetName: ${JSON.stringify(DEFAULT_ASSET_NAME_TEMPLATE)}\n }\n});\n`;\n}\n","import { access, mkdir, writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { GitRepository } from \"../git/GitRepository\";\nimport { type ParsedRemote, parseRemoteUrl } from \"../git/parseRemoteUrl\";\nimport { detectProjectType, type ProjectType } from \"../init/detectProjectType\";\nimport { generateConfigSource } from \"../init/generateConfigSource\";\n\nexport interface InitConfigOptions {\n configPath: string;\n force?: boolean;\n}\n\nexport interface InitConfigResult {\n configPath: string;\n remote?: ParsedRemote;\n projectType: ProjectType;\n}\n\n/** Writes a default `source-pack.config.ts` next to `configPath`, deduced from the Git remote `origin`. */\nexport async function initConfig({ configPath, force = false }: InitConfigOptions): Promise<InitConfigResult> {\n const directory = path.dirname(configPath);\n\n if (!force) {\n const exists = await access(configPath).then(\n () => true,\n () => false\n );\n\n if (exists) {\n throw new Error(`${configPath} already exists. Use --force to overwrite it.`);\n }\n }\n\n const repository = await GitRepository.open(directory).catch(() => undefined);\n const remoteUrl = await repository?.remoteUrl();\n const remote = remoteUrl ? parseRemoteUrl(remoteUrl) : undefined;\n const projectType = detectProjectType(repository?.root ?? directory);\n\n await mkdir(directory, { recursive: true });\n await writeFile(configPath, generateConfigSource({ remote, projectType }), \"utf8\");\n\n return { configPath, remote, projectType };\n}\n"],"mappings":";;;;;;;;;;;;AAaA,SAAgB,eAAe,QAA0C;CACvE,MAAM,UAAU,OAAO,KAAK;CAC5B,MAAM,MAAM,wCAAwC,KAAK,OAAO;CAChE,IAAI;CACJ,IAAI;CAEJ,IAAI,OAAO,CAAC,gBAAgB,KAAK,OAAO,GAAG;EACzC,OAAO,IAAI;EACX,WAAW,IAAI;CACjB,OACE,IAAI;EACF,MAAM,MAAM,IAAI,IAAI,OAAO;EAC3B,OAAO,IAAI;EACX,WAAW,IAAI;CACjB,QAAQ;EACN;CACF;CAGF,MAAM,WAAW,SACd,QAAQ,aAAa,EAAE,CAAC,CACxB,MAAM,GAAG,CAAC,CACV,OAAO,OAAO;CAEjB,IAAI,SAAS,SAAS,GACpB;CAGF,MAAM,WAA2C,kBAAkB,KAAK,IAAI,IAAI,WAAW,UAAU,KAAK,IAAI,IAAI,WAAW;CAE7H,IAAI,CAAC,UACH;CAGF,OAAO;EAAE;EAAU;EAAM,OAAO,SAAS,MAAM,GAAG,EAAE,CAAC,CAAC,KAAK,GAAG;EAAG,MAAM,SAAS,GAAG,EAAE;CAAG;AAC1F;;;;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AAS,CAAC,CAAC,YAAY,MAAS;CAC5E,MAAM,YAAY,MAAM,YAAY,UAAU;CAC9C,MAAM,SAAS,YAAY,eAAe,SAAS,IAAI;CACvD,MAAM,cAAc,kBAAkB,YAAY,QAAQ,SAAS;CAEnE,MAAM,MAAM,WAAW,EAAE,WAAW,KAAK,CAAC;CAC1C,MAAM,UAAU,YAAY,qBAAqB;EAAE;EAAQ;CAAY,CAAC,GAAG,MAAM;CAEjF,OAAO;EAAE;EAAY;EAAQ;CAAY;AAC3C"}
|
|
1
|
+
{"version":3,"file":"initConfig-DawW5Lht.mjs","names":[],"sources":["../src/git/parseRemoteUrl.ts","../src/init/detectProjectType.ts","../src/init/projectPresets.ts","../src/init/generateConfigSource.ts","../src/commands/initConfig.ts"],"sourcesContent":["import type { RepositoryProvider } from \"../config/interfaces/UserConfig\";\n\nexport interface ParsedRemote {\n provider: RepositoryProvider;\n host: string;\n owner: string;\n name: string;\n}\n\n/**\n * Parses an SSH (`git@host:owner/name.git`, `ssh://git@host:22/owner/name.git`) or HTTPS remote URL.\n * GitLab owners may contain subgroups (`group/sub`). Returns undefined for unknown hosts.\n */\nexport function parseRemoteUrl(remote: string): ParsedRemote | undefined {\n const trimmed = remote.trim();\n const scp = /^(?:[\\w.-]+@)?([\\w.-]+):(?!\\/\\/)(.+)$/.exec(trimmed);\n let host: string;\n let pathname: string;\n\n if (scp && !/^[a-z]+:\\/\\//i.test(trimmed)) {\n host = scp[1]!;\n pathname = scp[2]!;\n } else {\n try {\n const url = new URL(trimmed);\n host = url.hostname;\n pathname = url.pathname;\n } catch {\n return undefined;\n }\n }\n\n const segments = pathname\n .replace(/\\.git\\/?$/, \"\")\n .split(\"/\")\n .filter(Boolean);\n\n if (segments.length < 2) {\n return undefined;\n }\n\n const provider: RepositoryProvider | undefined = /(^|\\.)github\\./i.test(host) ? \"github\" : /gitlab/i.test(host) ? \"gitlab\" : undefined;\n\n if (!provider) {\n return undefined;\n }\n\n return { provider, host, owner: segments.slice(0, -1).join(\"/\"), name: segments.at(-1)! };\n}\n","import { existsSync } from \"node:fs\";\nimport path from \"node:path\";\n\nexport type ProjectType = \"node\" | \"python\" | \"jvm\" | \"go\" | \"generic\";\n\nconst MARKERS: Array<[ProjectType, string[]]> = [\n [\"node\", [\"package.json\"]],\n [\"python\", [\"pyproject.toml\", \"requirements.txt\", \"setup.py\"]],\n [\"jvm\", [\"pom.xml\", \"build.gradle\", \"build.gradle.kts\"]],\n [\"go\", [\"go.mod\"]]\n];\n\nexport function detectProjectType(directory: string): ProjectType {\n return MARKERS.find(([, files]) => files.some((file) => existsSync(path.join(directory, file))))?.[0] ?? \"generic\";\n}\n","import {\n BUILD_OUTPUT_DIRS,\n DEFAULT_EXCLUDE,\n DEFAULT_INCLUDE,\n LOCKFILES_BY_ECOSYSTEM,\n NODE_DEPENDENCY_DIRS,\n TEST_FILES_BY_ECOSYSTEM\n} from \"../config/defaults\";\nimport type { ProjectType } from \"./detectProjectType\";\n\nexport interface ProjectPreset {\n include: string[];\n exclude: string[];\n}\n\nexport const PROJECT_PRESETS: Record<ProjectType, ProjectPreset> = {\n node: {\n include: [\"**/*.{ts,tsx,mts,cts,js,jsx,mjs,cjs,json,yaml,yml,md,feature,graphql}\"],\n exclude: [...NODE_DEPENDENCY_DIRS, ...BUILD_OUTPUT_DIRS, ...LOCKFILES_BY_ECOSYSTEM.node, ...TEST_FILES_BY_ECOSYSTEM.node]\n },\n python: {\n include: [\"**/*.{py,pyi,toml,cfg,ini,json,yaml,yml,md}\"],\n exclude: [\n \"**/.venv/**\",\n \"**/venv/**\",\n \"**/__pycache__/**\",\n ...BUILD_OUTPUT_DIRS,\n ...LOCKFILES_BY_ECOSYSTEM.python,\n ...TEST_FILES_BY_ECOSYSTEM.python\n ]\n },\n jvm: {\n include: [\"**/*.{java,kt,kts,groovy,gradle,xml,properties,json,yaml,yml,md}\"],\n exclude: [\"**/target/**\", \"**/.gradle/**\", ...BUILD_OUTPUT_DIRS, ...LOCKFILES_BY_ECOSYSTEM.jvm, ...TEST_FILES_BY_ECOSYSTEM.jvm]\n },\n go: {\n include: [\"**/*.{go,mod,json,yaml,yml,md,sql}\"],\n exclude: [\"**/vendor/**\", \"**/bin/**\", ...BUILD_OUTPUT_DIRS, ...LOCKFILES_BY_ECOSYSTEM.go, ...TEST_FILES_BY_ECOSYSTEM.go]\n },\n generic: { include: DEFAULT_INCLUDE, exclude: DEFAULT_EXCLUDE }\n};\n","import {\n DEFAULT_API_KEY_ENV,\n DEFAULT_BATCH_SIZE,\n DEFAULT_CHUNK_LINES,\n DEFAULT_CHUNK_OVERLAP,\n DEFAULT_DIMENSIONS\n} from \"../config/defaults\";\nimport {\n DEFAULT_ASSET_NAME_TEMPLATE,\n DEFAULT_GITHUB_API_URL,\n DEFAULT_GITLAB_API_URL,\n DEFAULT_OUTPUT_DIR,\n DEFAULT_TAG_TEMPLATE,\n GITHUB_TOKEN_ENV,\n GITLAB_TOKEN_ENV\n} from \"../constants\";\nimport type { ParsedRemote } from \"../git/parseRemoteUrl\";\nimport type { ProjectType } from \"./detectProjectType\";\nimport { PROJECT_PRESETS } from \"./projectPresets\";\n\nexport interface GenerateConfigSourceOptions {\n remote?: ParsedRemote;\n projectType: ProjectType;\n}\n\nfunction list(values: string[], indent: string): string {\n return `[\\n${values.map((value) => `${indent} ${JSON.stringify(value)}`).join(\",\\n\")}\\n${indent}]`;\n}\n\nfunction apiUrlLine(remote: ParsedRemote | undefined): string {\n if (remote?.provider === \"gitlab\") {\n return remote.host === \"gitlab.com\"\n ? `// apiUrl: ${JSON.stringify(DEFAULT_GITLAB_API_URL)}`\n : `apiUrl: ${JSON.stringify(`https://${remote.host}/api/v4`)}`;\n }\n\n return remote && remote.host !== \"github.com\"\n ? `apiUrl: ${JSON.stringify(`https://${remote.host}/api/v3`)}`\n : `// apiUrl: ${JSON.stringify(DEFAULT_GITHUB_API_URL)}`;\n}\n\nfunction repositoryBlock(remote: ParsedRemote | undefined): string {\n const fields = [\n `provider: ${JSON.stringify(remote?.provider ?? \"github\")}`,\n `owner: ${JSON.stringify(remote?.owner ?? \"TODO-owner\")}`,\n `name: ${JSON.stringify(remote?.name ?? \"TODO-repository\")}`\n ];\n const apiUrl = apiUrlLine(remote);\n const lines = apiUrl.startsWith(\"//\") ? [fields.join(\",\\n \"), apiUrl] : [[...fields, apiUrl].join(\",\\n \")];\n\n return `{\\n ${lines.join(\"\\n \")}\\n }`;\n}\n\n/** Source of a default `source-pack.config.ts`, deduced from the Git remote and the project type. */\nexport function generateConfigSource({ remote, projectType }: GenerateConfigSourceOptions): string {\n const preset = PROJECT_PRESETS[projectType];\n\n return `import { defineConfig } from \"@cmflow/source-pack\";\n\n// Secrets are read from the environment only: ${DEFAULT_API_KEY_ENV} (embeddings), ${remote?.provider === \"gitlab\" ? GITLAB_TOKEN_ENV : GITHUB_TOKEN_ENV} (publish).\nexport default defineConfig({\n outputDir: ${JSON.stringify(DEFAULT_OUTPUT_DIR)},\n repository: ${repositoryBlock(remote)},\n sources: {\n include: ${list(preset.include, \" \")},\n // Adjust to the project: generated data, fixtures, mocks, vendored code...\n exclude: ${list(preset.exclude, \" \")}\n },\n chunking: { lines: ${DEFAULT_CHUNK_LINES}, overlap: ${DEFAULT_CHUNK_OVERLAP} },\n embedding: {\n baseUrl: \"https://apim-prdaiplatform-frc.azure-api.net/litellm-api\",\n model: \"text-embedding-3-small-gmdt\",\n fallbackModels: [\"text-embedding-3-small-swc-gmdt\", \"text-embedding-3-small-eus2-gmdt\"],\n referenceModel: \"text-embedding-3-small\",\n dimensions: ${DEFAULT_DIMENSIONS},\n batchSize: ${DEFAULT_BATCH_SIZE}\n },\n publish: {\n tag: ${JSON.stringify(DEFAULT_TAG_TEMPLATE)},\n assetName: ${JSON.stringify(DEFAULT_ASSET_NAME_TEMPLATE)}\n }\n});\n`;\n}\n","import { access, mkdir, writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { GitRepository } from \"../git/GitRepository\";\nimport { type ParsedRemote, parseRemoteUrl } from \"../git/parseRemoteUrl\";\nimport { detectProjectType, type ProjectType } from \"../init/detectProjectType\";\nimport { generateConfigSource } from \"../init/generateConfigSource\";\n\nexport interface InitConfigOptions {\n configPath: string;\n force?: boolean;\n}\n\nexport interface InitConfigResult {\n configPath: string;\n remote?: ParsedRemote;\n projectType: ProjectType;\n}\n\n/** Writes a default `source-pack.config.ts` next to `configPath`, deduced from the Git remote `origin`. */\nexport async function initConfig({ configPath, force = false }: InitConfigOptions): Promise<InitConfigResult> {\n const directory = path.dirname(configPath);\n\n if (!force) {\n const exists = await access(configPath).then(\n () => true,\n () => false\n );\n\n if (exists) {\n throw new Error(`${configPath} already exists. Use --force to overwrite it.`);\n }\n }\n\n const repository = await GitRepository.open(directory).catch(() => undefined);\n const remoteUrl = await repository?.remoteUrl();\n const remote = remoteUrl ? parseRemoteUrl(remoteUrl) : undefined;\n const projectType = detectProjectType(repository?.root ?? directory);\n\n await mkdir(directory, { recursive: true });\n await writeFile(configPath, generateConfigSource({ remote, projectType }), \"utf8\");\n\n return { configPath, remote, projectType };\n}\n"],"mappings":";;;;;;;;;;;;AAaA,SAAgB,eAAe,QAA0C;CACvE,MAAM,UAAU,OAAO,KAAK;CAC5B,MAAM,MAAM,wCAAwC,KAAK,OAAO;CAChE,IAAI;CACJ,IAAI;CAEJ,IAAI,OAAO,CAAC,gBAAgB,KAAK,OAAO,GAAG;EACzC,OAAO,IAAI;EACX,WAAW,IAAI;CACjB,OACE,IAAI;EACF,MAAM,MAAM,IAAI,IAAI,OAAO;EAC3B,OAAO,IAAI;EACX,WAAW,IAAI;CACjB,QAAQ;EACN;CACF;CAGF,MAAM,WAAW,SACd,QAAQ,aAAa,EAAE,CAAC,CACxB,MAAM,GAAG,CAAC,CACV,OAAO,OAAO;CAEjB,IAAI,SAAS,SAAS,GACpB;CAGF,MAAM,WAA2C,kBAAkB,KAAK,IAAI,IAAI,WAAW,UAAU,KAAK,IAAI,IAAI,WAAW;CAE7H,IAAI,CAAC,UACH;CAGF,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UAAU,CAAC,CAAC,WAChC,YACA,KACR,GAGE,MAAM,IAAI,MAAM,GAAG,WAAW,8CAA8C;CAC9E;CAGF,MAAM,aAAa,MAAM,cAAc,KAAK,SAAS,CAAC,CAAC,YAAY,MAAS;CAC5E,MAAM,YAAY,MAAM,YAAY,UAAU;CAC9C,MAAM,SAAS,YAAY,eAAe,SAAS,IAAI;CACvD,MAAM,cAAc,kBAAkB,YAAY,QAAQ,SAAS;CAEnE,MAAM,MAAM,WAAW,EAAE,WAAW,KAAK,CAAC;CAC1C,MAAM,UAAU,YAAY,qBAAqB;EAAE;EAAQ;CAAY,CAAC,GAAG,MAAM;CAEjF,OAAO;EAAE;EAAY;EAAQ;CAAY;AAC3C"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { _ as strictObject, m as number, n as _enum, o as array, s as boolean, v as string, w as errorMessage, x as url, y as union } from "./packageVersion-
|
|
2
|
-
import {
|
|
1
|
+
import { _ as strictObject, m as number, n as _enum, o as array, s as boolean, v as string, w as errorMessage, x as url, y as union } from "./packageVersion-CpvQqEy_.mjs";
|
|
2
|
+
import { c as DEFAULT_GITLAB_PACKAGE_NAME, g as PACKAGE_NAME, i as DEFAULT_ASSET_NAME_TEMPLATE, l as DEFAULT_OUTPUT_DIR, o as DEFAULT_GITHUB_API_URL, s as DEFAULT_GITLAB_API_URL, u as DEFAULT_TAG_TEMPLATE } from "./constants-o4tbCIrY.mjs";
|
|
3
3
|
import { a as DEFAULT_INCLUDE, i as DEFAULT_EXCLUDE, n as DEFAULT_API_KEY_ENV, o as DEFAULT_MAX_FILE_BYTES, r as DEFAULT_DIMENSIONS, s as DEFAULT_MAX_INPUT_CHARS } from "./defaults-BJs7a37e.mjs";
|
|
4
4
|
import { register } from "node:module";
|
|
5
5
|
import path from "node:path";
|
|
@@ -101,7 +101,6 @@ const userConfigSchema = strictObject({
|
|
|
101
101
|
sources: sourcesSchema.optional(),
|
|
102
102
|
chunking: chunkingSchema.optional(),
|
|
103
103
|
embedding: embeddingSchema.optional(),
|
|
104
|
-
attachments: array(nonEmptyString, "expected an array of repository paths").optional(),
|
|
105
104
|
publish: publishSchema.optional()
|
|
106
105
|
});
|
|
107
106
|
|
|
@@ -171,7 +170,6 @@ function resolveConfig(raw, { cwd = process.cwd(), configPath = "", env = proces
|
|
|
171
170
|
maxInputChars: embedding.maxInputChars ?? 12e3,
|
|
172
171
|
apiKeyEnv: embedding.apiKeyEnv ?? "LITELLM_API_KEY"
|
|
173
172
|
} : null,
|
|
174
|
-
attachments: config.attachments ?? [],
|
|
175
173
|
publish: {
|
|
176
174
|
tag: config.publish?.tag ?? "version-{version}",
|
|
177
175
|
assetName: config.publish?.assetName ?? "source-pack-{version}.tar.gz",
|
|
@@ -221,4 +219,4 @@ async function loadConfig(configPath, { cwd = process.cwd(), env = process.env }
|
|
|
221
219
|
|
|
222
220
|
//#endregion
|
|
223
221
|
export { resolveConfig as n, loadConfig as t };
|
|
224
|
-
//# sourceMappingURL=loadConfig-
|
|
222
|
+
//# sourceMappingURL=loadConfig-KYduEj2v.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loadConfig-KYduEj2v.mjs","names":["z.string","z.array","z.number","z\n .strictObject","z.enum","z.union","z.url","z.strictObject","z\n .string","z.boolean"],"sources":["../src/config/registerSelfResolution.ts","../src/config/configSchema.ts","../src/config/formatConfigIssues.ts","../src/config/resolveConfig.ts","../src/config/loadConfig.ts"],"sourcesContent":["import { register } from \"node:module\";\nimport { PACKAGE_NAME } from \"../constants\";\n\nlet registered = false;\n\nconst hookSource = `\nlet selfUrl;\nexport function initialize(data) { selfUrl = data.selfUrl; }\nexport async function resolve(specifier, context, nextResolve) {\n try {\n return await nextResolve(specifier, context);\n } catch (error) {\n if (specifier === ${JSON.stringify(PACKAGE_NAME)} && selfUrl) {\n return { url: selfUrl, shortCircuit: true };\n }\n throw error;\n }\n}\n`;\n\n/**\n * Lets a config file `import { defineConfig } from \"@cmflow/source-pack\"` even when the package is not installed\n * in the project (e.g. `npx @cmflow/source-pack build` in CI): the import falls back to the running package.\n */\nexport function registerSelfResolution(): void {\n if (registered) {\n return;\n }\n\n let selfUrl: string;\n\n try {\n selfUrl = import.meta.resolve(PACKAGE_NAME);\n } catch {\n return;\n }\n\n register(`data:text/javascript,${encodeURIComponent(hookSource)}`, { data: { selfUrl } });\n registered = true;\n}\n","import { z } from \"zod\";\nimport { DEFAULT_CHUNK_LINES, DEFAULT_CHUNK_OVERLAP } from \"./defaults\";\n\nconst nonEmptyString = z.string().trim().min(1, \"expected a non-empty string\");\nconst globList = z.array(nonEmptyString, \"expected an array of glob strings\");\nconst positiveInt = z.number(\"expected a number\").int(\"expected an integer\").positive(\"expected a positive integer\");\n\nexport const repositorySchema = z\n .strictObject({\n provider: z.enum([\"github\", \"gitlab\"], 'expected \"github\" or \"gitlab\"'),\n owner: nonEmptyString.optional(),\n name: nonEmptyString.optional(),\n projectId: z.union([nonEmptyString, positiveInt], \"expected a GitLab project id or path\").optional(),\n apiUrl: z.url(\"expected an absolute URL\").optional()\n })\n .superRefine((repository, ctx) => {\n if (repository.provider === \"github\" && (!repository.owner || !repository.name)) {\n ctx.addIssue({ code: \"custom\", path: [repository.owner ? \"name\" : \"owner\"], message: \"required for a GitHub repository\" });\n }\n\n if (repository.provider === \"gitlab\" && repository.projectId === undefined && (!repository.owner || !repository.name)) {\n ctx.addIssue({ code: \"custom\", path: [\"projectId\"], message: \"required for a GitLab project (or set both owner and name)\" });\n }\n });\n\nexport const sourcesSchema = z.strictObject({\n include: globList.min(1, \"expected at least one glob\").optional(),\n exclude: globList.optional(),\n maxFileBytes: positiveInt.optional()\n});\n\nexport const chunkingSchema = z\n .strictObject({\n lines: positiveInt.optional(),\n overlap: z.number(\"expected a number\").int(\"expected an integer\").min(0, \"expected an integer >= 0\").optional()\n })\n .superRefine((chunking, ctx) => {\n if ((chunking.overlap ?? DEFAULT_CHUNK_OVERLAP) >= (chunking.lines ?? DEFAULT_CHUNK_LINES)) {\n ctx.addIssue({ code: \"custom\", path: [\"overlap\"], message: \"expected a value lower than chunking.lines\" });\n }\n });\n\nexport const embeddingSchema = z.strictObject({\n baseUrl: z.url(\"expected an absolute URL\"),\n model: nonEmptyString,\n fallbackModels: z.array(nonEmptyString, \"expected an array of model names\").optional(),\n referenceModel: nonEmptyString.optional(),\n dimensions: positiveInt.optional(),\n batchSize: positiveInt.max(2048, \"expected at most 2048\").optional(),\n concurrency: positiveInt.optional(),\n maxRetries: z.number(\"expected a number\").int(\"expected an integer\").min(0, \"expected an integer >= 0\").optional(),\n maxInputChars: positiveInt.optional(),\n apiKeyEnv: nonEmptyString.optional()\n});\n\nconst templateWithVersion = nonEmptyString.refine((value) => value.includes(\"{version}\"), 'expected a template containing \"{version}\"');\n\nexport const publishSchema = z.strictObject({\n tag: templateWithVersion.optional(),\n assetName: templateWithVersion.optional(),\n packageName: z\n .string()\n .regex(/^[A-Za-z0-9._-]+$/, \"expected letters, digits, dots, dashes or underscores\")\n .optional(),\n createRelease: z.boolean(\"expected a boolean\").optional()\n});\n\nexport const userConfigSchema = z.strictObject({\n outputDir: nonEmptyString.optional(),\n repository: repositorySchema,\n sources: sourcesSchema.optional(),\n chunking: chunkingSchema.optional(),\n embedding: embeddingSchema.optional(),\n publish: publishSchema.optional()\n});\n","import type { z } from \"zod\";\n\nfunction describeInput(input: unknown): string {\n if (input === undefined) {\n return \"nothing\";\n }\n\n const text = JSON.stringify(input) ?? String(input);\n\n return text.length > 80 ? `${text.slice(0, 77)}...` : text;\n}\n\n/**\n * Turns zod issues into one explicit line per field: `<field>: <expected> (received <value>)`.\n */\nexport function formatConfigIssues(issues: z.core.$ZodIssue[]): string[] {\n return issues.map((issue) => {\n const field = issue.path.length ? issue.path.map(String).join(\".\") : \"(root)\";\n\n if (issue.code === \"unrecognized_keys\") {\n return `${field}: unknown option(s) ${issue.keys.map((key) => `\"${key}\"`).join(\", \")}`;\n }\n\n const received = \"input\" in issue && issue.code !== \"custom\" ? ` (received ${describeInput(issue.input)})` : \"\";\n\n return `${field}: ${issue.message}${received}`;\n });\n}\n","import path from \"node:path\";\nimport {\n DEFAULT_ASSET_NAME_TEMPLATE,\n DEFAULT_GITHUB_API_URL,\n DEFAULT_GITLAB_API_URL,\n DEFAULT_GITLAB_PACKAGE_NAME,\n DEFAULT_OUTPUT_DIR,\n DEFAULT_TAG_TEMPLATE\n} from \"../constants\";\nimport { userConfigSchema } from \"./configSchema\";\nimport {\n DEFAULT_API_KEY_ENV,\n DEFAULT_BATCH_SIZE,\n DEFAULT_CHUNK_LINES,\n DEFAULT_CHUNK_OVERLAP,\n DEFAULT_DIMENSIONS,\n DEFAULT_EMBEDDING_CONCURRENCY,\n DEFAULT_EXCLUDE,\n DEFAULT_INCLUDE,\n DEFAULT_MAX_FILE_BYTES,\n DEFAULT_MAX_INPUT_CHARS,\n DEFAULT_MAX_RETRIES\n} from \"./defaults\";\nimport { formatConfigIssues } from \"./formatConfigIssues\";\nimport type { ResolvedConfig } from \"./interfaces/ResolvedConfig\";\n\nexport interface ResolveConfigOptions {\n cwd?: string;\n configPath?: string;\n env?: NodeJS.ProcessEnv;\n}\n\n/**\n * Validates a raw user config and fills every default. Throws an explicit, field-level error message on invalid input.\n */\nexport function resolveConfig(\n raw: unknown,\n { cwd = process.cwd(), configPath = \"\", env = process.env }: ResolveConfigOptions = {}\n): ResolvedConfig {\n const result = userConfigSchema.safeParse(raw, { reportInput: true });\n\n if (!result.success) {\n const lines = formatConfigIssues(result.error.issues);\n throw new Error(`Invalid source-pack config${configPath ? ` (${configPath})` : \"\"}:\\n${lines.map((line) => ` - ${line}`).join(\"\\n\")}`);\n }\n\n const config = result.data;\n const { repository } = config;\n const defaultApiUrl = repository.provider === \"github\" ? DEFAULT_GITHUB_API_URL : (env.CI_API_V4_URL ?? DEFAULT_GITLAB_API_URL);\n const embedding = config.embedding;\n\n return {\n configPath,\n cwd,\n outputDir: path.resolve(cwd, config.outputDir ?? DEFAULT_OUTPUT_DIR),\n repository: {\n provider: repository.provider,\n owner: repository.owner,\n name: repository.name,\n projectId: repository.projectId === undefined ? undefined : String(repository.projectId),\n apiUrl: (repository.apiUrl ?? defaultApiUrl).replace(/\\/+$/, \"\")\n },\n sources: {\n include: config.sources?.include ?? DEFAULT_INCLUDE,\n exclude: config.sources?.exclude ?? DEFAULT_EXCLUDE,\n maxFileBytes: config.sources?.maxFileBytes ?? DEFAULT_MAX_FILE_BYTES\n },\n chunking: {\n lines: config.chunking?.lines ?? DEFAULT_CHUNK_LINES,\n overlap: config.chunking?.overlap ?? DEFAULT_CHUNK_OVERLAP\n },\n embedding: embedding\n ? {\n baseUrl: embedding.baseUrl,\n model: embedding.model,\n fallbackModels: embedding.fallbackModels ?? [],\n referenceModel: embedding.referenceModel ?? embedding.model,\n dimensions: embedding.dimensions ?? DEFAULT_DIMENSIONS,\n batchSize: embedding.batchSize ?? DEFAULT_BATCH_SIZE,\n concurrency: embedding.concurrency ?? DEFAULT_EMBEDDING_CONCURRENCY,\n maxRetries: embedding.maxRetries ?? DEFAULT_MAX_RETRIES,\n maxInputChars: embedding.maxInputChars ?? DEFAULT_MAX_INPUT_CHARS,\n apiKeyEnv: embedding.apiKeyEnv ?? DEFAULT_API_KEY_ENV\n }\n : null,\n publish: {\n tag: config.publish?.tag ?? DEFAULT_TAG_TEMPLATE,\n assetName: config.publish?.assetName ?? DEFAULT_ASSET_NAME_TEMPLATE,\n packageName: config.publish?.packageName ?? DEFAULT_GITLAB_PACKAGE_NAME,\n createRelease: config.publish?.createRelease ?? false\n }\n };\n}\n","import { access } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport { errorMessage } from \"../utils/errorMessage\";\nimport type { ResolvedConfig } from \"./interfaces/ResolvedConfig\";\nimport { registerSelfResolution } from \"./registerSelfResolution\";\nimport { resolveConfig } from \"./resolveConfig\";\n\nasync function importConfigModule(filePath: string): Promise<unknown> {\n const url = pathToFileURL(filePath).href;\n\n if (!/\\.[cm]?ts$/.test(filePath)) {\n return import(url);\n }\n\n const { register } = await import(\"tsx/esm/api\");\n const unregister = register();\n\n try {\n return await import(url);\n } finally {\n await unregister();\n }\n}\n\n/**\n * Loads `source-pack.config.ts` (through tsx) or a `.mjs`/`.js` config, then validates it.\n * Relative paths of the config are resolved against `cwd` (the command's directory).\n */\nexport async function loadConfig(\n configPath: string,\n { cwd = process.cwd(), env = process.env }: { cwd?: string; env?: NodeJS.ProcessEnv } = {}\n): Promise<ResolvedConfig> {\n const filePath = path.resolve(cwd, configPath);\n\n try {\n await access(filePath);\n } catch {\n throw new Error(`source-pack config not found at ${filePath}. Run \"source-pack init\" or pass --config <path>.`);\n }\n\n registerSelfResolution();\n\n let mod: { default?: unknown };\n\n try {\n mod = (await importConfigModule(filePath)) as { default?: unknown };\n } catch (error) {\n throw new Error(`Unable to load source-pack config at ${filePath}: ${errorMessage(error)}`);\n }\n\n return resolveConfig(mod.default ?? mod, { cwd, configPath: filePath, env });\n}\n"],"mappings":";;;;;;;;;AAGA,IAAI,aAAa;AAEjB,MAAM,aAAa;;;;;;;wBAOK,KAAK,UAAU,YAAY,EAAE;;;;;;;;;;;AAYrD,SAAgB,yBAA+B;CAC7C,IAAI,YACF;CAGF,IAAI;CAEJ,IAAI;EACF,UAAU,YAAY,QAAQ,YAAY;CAC5C,QAAQ;EACN;CACF;CAEA,SAAS,wBAAwB,mBAAmB,UAAU,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;CACxF,aAAa;AACf;;;;ACpCA,MAAM,iBAAiBA,OAAS,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,GAAG,6BAA6B;AAC7E,MAAM,WAAWC,MAAQ,gBAAgB,mCAAmC;AAC5E,MAAM,cAAcC,OAAS,mBAAmB,CAAC,CAAC,IAAI,qBAAqB,CAAC,CAAC,SAAS,6BAA6B;AAEnH,MAAa,mBAAmBC,aAChB;CACZ,UAAUC,MAAO,CAAC,UAAU,QAAQ,GAAG,mCAA+B;CACtE,OA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;GACrB,WAAW,OAAO,SAAS;GAC3B,aAAa,OAAO,SAAS;GAC7B,eAAe,OAAO,SAAS,iBAAiB;EAClD;CACF;AACF;;;;ACpFA,eAAe,mBAAmB,UAAoC;CACpE,MAAM,MAAM,cAAc,QAAQ,CAAC,CAAC;CAEpC,IAAI,CAAC,aAAa,KAAK,QAAQ,GAC7B,OAAO,OAAO;CAGhB,MAAM,EAAE,aAAa,MAAM,OAAO;CAClC,MAAM,aAAa,SAAS;CAE5B,IAAI;EACF,OAAO,MAAM,OAAO;CACtB,UAAU;EACR,MAAM,WAAW;CACnB;AACF;;;;;AAMA,eAAsB,WACpB,YACA,EAAE,MAAM,QAAQ,IAAI,GAAG,MAAM,QAAQ,QAAmD,CAAC,GAChE;CACzB,MAAM,WAAW,KAAK,QAAQ,KAAK,UAAU;CAE7C,IAAI;EACF,MAAM,OAAO,QAAQ;CACvB,QAAQ;EACN,MAAM,IAAI,MAAM,mCAAmC,SAAS,kDAAkD;CAChH;CAEA,uBAAuB;CAEvB,IAAI;CAEJ,IAAI;EACF,MAAO,MAAM,mBAAmB,QAAQ;CAC1C,SAAS,OAAO;EACd,MAAM,IAAI,MAAM,wCAAwC,SAAS,IAAI,aAAa,KAAK,GAAG;CAC5F;CAEA,OAAO,cAAc,IAAI,WAAW,KAAK;EAAE;EAAK,YAAY;EAAU;CAAI,CAAC;AAC7E"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { g as PACKAGE_NAME } from "./constants-o4tbCIrY.mjs";
|
|
2
2
|
import { readFileSync } from "node:fs";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
|
|
@@ -4643,4 +4643,4 @@ function packageVersion() {
|
|
|
4643
4643
|
|
|
4644
4644
|
//#endregion
|
|
4645
4645
|
export { toJSONSchema as C, safeParseAsync as S, strictObject as _, any as a, unknown as b, custom as c, literal as d, looseObject as f, record as g, object as h, _null as i, discriminatedUnion as l, number as m, _enum as n, array as o, never as p, _instanceof as r, boolean as s, packageVersion as t, lazy as u, string as v, errorMessage as w, url as x, union as y };
|
|
4646
|
-
//# sourceMappingURL=packageVersion-
|
|
4646
|
+
//# sourceMappingURL=packageVersion-CpvQqEy_.mjs.map
|