@cmflow/source-pack 0.0.0-stage → 3.20.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 +183 -2
- package/dist/GitRepository-VTAWT6j4.mjs +151 -0
- package/dist/GitRepository-VTAWT6j4.mjs.map +1 -0
- package/dist/bin/source-pack.d.mts +1 -0
- package/dist/bin/source-pack.mjs +3038 -0
- package/dist/bin/source-pack.mjs.map +1 -0
- package/dist/buildSourcePack-CaaMZ_tw.mjs +11280 -0
- package/dist/buildSourcePack-CaaMZ_tw.mjs.map +1 -0
- package/dist/buildSourcePack-DIp8G_uL.mjs +3 -0
- package/dist/constants-DkiLCuIK.mjs +25 -0
- package/dist/constants-DkiLCuIK.mjs.map +1 -0
- package/dist/defaults-BJs7a37e.mjs +52 -0
- package/dist/defaults-BJs7a37e.mjs.map +1 -0
- package/dist/index.d.mts +397 -0
- package/dist/index.mjs +73 -0
- package/dist/index.mjs.map +1 -0
- package/dist/initConfig-ByGsbShR.mjs +185 -0
- package/dist/initConfig-ByGsbShR.mjs.map +1 -0
- package/dist/loadConfig-CNrL90dq.mjs +224 -0
- package/dist/loadConfig-CNrL90dq.mjs.map +1 -0
- package/dist/logger-D1XGzzjT.mjs +15 -0
- package/dist/logger-D1XGzzjT.mjs.map +1 -0
- package/dist/packageVersion-B0749hF6.mjs +4646 -0
- package/dist/packageVersion-B0749hF6.mjs.map +1 -0
- package/dist/projectIdentity-F97vs1H-.mjs +3331 -0
- package/dist/projectIdentity-F97vs1H-.mjs.map +1 -0
- package/dist/publishSourcePack-Dj1cdWfT.mjs +3 -0
- package/dist/publishSourcePack-xNr9RBgv.mjs +296 -0
- package/dist/publishSourcePack-xNr9RBgv.mjs.map +1 -0
- package/dist/token-DMtao22Y.mjs +59 -0
- package/dist/token-DMtao22Y.mjs.map +1 -0
- package/dist/token-util-C3JYrW4-.mjs +498 -0
- package/dist/token-util-C3JYrW4-.mjs.map +1 -0
- package/dist/token-util-CbjlbIno.mjs +5 -0
- package/package.json +45 -3
- package/templates/circleci-job.yml +39 -0
- package/templates/gitlab-ci.yml +30 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//#region src/constants.ts
|
|
2
|
+
const PACKAGE_NAME = "@cmflow/source-pack";
|
|
3
|
+
/** Version of the archive layout (manifest, chunks, embeddings, attachments). */
|
|
4
|
+
const SOURCE_PACK_FORMAT_VERSION = 2;
|
|
5
|
+
/** Version of the chunking algorithm. Bump it whenever chunk boundaries or ids change. */
|
|
6
|
+
const CHUNKING_FORMAT_VERSION = 1;
|
|
7
|
+
const CHUNK_ID_ALGORITHM = "sha256(path:startLine:text)";
|
|
8
|
+
const EMBEDDING_INPUT_FORMAT = "path\\ntext";
|
|
9
|
+
const MANIFEST_FILE = "manifest.json";
|
|
10
|
+
const CHUNKS_FILE = "chunks.jsonl.gz";
|
|
11
|
+
const EMBEDDINGS_FILE = "embeddings.f32";
|
|
12
|
+
const ATTACHMENTS_DIR = "attachments";
|
|
13
|
+
const DEFAULT_CONFIG_FILE = "source-pack.config.ts";
|
|
14
|
+
const DEFAULT_OUTPUT_DIR = "./tmp/source-pack";
|
|
15
|
+
const DEFAULT_TAG_TEMPLATE = "version-{version}";
|
|
16
|
+
const DEFAULT_ASSET_NAME_TEMPLATE = "source-pack-{version}.tar.gz";
|
|
17
|
+
const DEFAULT_GITLAB_PACKAGE_NAME = "source-pack";
|
|
18
|
+
const DEFAULT_GITHUB_API_URL = "https://api.github.com";
|
|
19
|
+
const DEFAULT_GITLAB_API_URL = "https://gitlab.com/api/v4";
|
|
20
|
+
const GITHUB_TOKEN_ENV = "GITHUB_TOKEN";
|
|
21
|
+
const GITLAB_TOKEN_ENV = "GITLAB_TOKEN";
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
export { PACKAGE_NAME as _, DEFAULT_ASSET_NAME_TEMPLATE as a, DEFAULT_GITLAB_API_URL as c, DEFAULT_TAG_TEMPLATE as d, EMBEDDINGS_FILE as f, MANIFEST_FILE as g, GITLAB_TOKEN_ENV as h, CHUNK_ID_ALGORITHM as i, DEFAULT_GITLAB_PACKAGE_NAME as l, GITHUB_TOKEN_ENV as m, CHUNKING_FORMAT_VERSION as n, DEFAULT_CONFIG_FILE as o, EMBEDDING_INPUT_FORMAT as p, CHUNKS_FILE as r, DEFAULT_GITHUB_API_URL as s, ATTACHMENTS_DIR as t, DEFAULT_OUTPUT_DIR as u, SOURCE_PACK_FORMAT_VERSION as v };
|
|
25
|
+
//# sourceMappingURL=constants-DkiLCuIK.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants-DkiLCuIK.mjs","names":[],"sources":["../src/constants.ts"],"sourcesContent":["export const PACKAGE_NAME = \"@cmflow/source-pack\";\n\n/** Version of the archive layout (manifest, chunks, embeddings, attachments). */\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\";\nexport const ATTACHMENTS_DIR = \"attachments\";\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;AAC/B,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"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
//#region src/config/defaults.ts
|
|
2
|
+
const DEFAULT_INCLUDE = ["**/*.{ts,tsx,mts,cts,js,jsx,mjs,cjs,json,yaml,yml,md,mdx,feature,graphql,gql,sql,sh,py,java,kt,kts,go,rb,php,cs,css,scss,html,vue,svelte,toml,xml,properties,tf,gradle}", "**/Dockerfile"];
|
|
3
|
+
const LOCKFILES_BY_ECOSYSTEM = {
|
|
4
|
+
node: [
|
|
5
|
+
"**/package-lock.json",
|
|
6
|
+
"**/npm-shrinkwrap.json",
|
|
7
|
+
"**/yarn.lock",
|
|
8
|
+
"**/pnpm-lock.yaml",
|
|
9
|
+
"**/bun.lock",
|
|
10
|
+
"**/bun.lockb"
|
|
11
|
+
],
|
|
12
|
+
python: [
|
|
13
|
+
"**/poetry.lock",
|
|
14
|
+
"**/Pipfile.lock",
|
|
15
|
+
"**/uv.lock"
|
|
16
|
+
],
|
|
17
|
+
rust: ["**/Cargo.lock"],
|
|
18
|
+
go: ["**/go.sum"],
|
|
19
|
+
php: ["**/composer.lock"],
|
|
20
|
+
ruby: ["**/Gemfile.lock"],
|
|
21
|
+
jvm: ["**/gradle.lockfile"]
|
|
22
|
+
};
|
|
23
|
+
const LOCKFILES = Object.values(LOCKFILES_BY_ECOSYSTEM).flat();
|
|
24
|
+
const TEST_FILES_BY_ECOSYSTEM = {
|
|
25
|
+
node: ["**/*.spec.*", "**/*.test.*"],
|
|
26
|
+
python: ["**/test_*.py", "**/*_test.py"],
|
|
27
|
+
go: ["**/*_test.go"],
|
|
28
|
+
jvm: ["**/src/test/**"]
|
|
29
|
+
};
|
|
30
|
+
const TEST_FILES = Object.values(TEST_FILES_BY_ECOSYSTEM).flat();
|
|
31
|
+
/** Installed dependencies of a Node.js project. */
|
|
32
|
+
const NODE_DEPENDENCY_DIRS = ["**/node_modules/**", "**/.yarn/**"];
|
|
33
|
+
/** Generated build and coverage output, whatever the ecosystem. */
|
|
34
|
+
const BUILD_OUTPUT_DIRS = [
|
|
35
|
+
"**/dist/**",
|
|
36
|
+
"**/build/**",
|
|
37
|
+
"**/coverage/**"
|
|
38
|
+
];
|
|
39
|
+
const DEFAULT_EXCLUDE = [
|
|
40
|
+
...NODE_DEPENDENCY_DIRS,
|
|
41
|
+
...BUILD_OUTPUT_DIRS,
|
|
42
|
+
...LOCKFILES,
|
|
43
|
+
...TEST_FILES
|
|
44
|
+
];
|
|
45
|
+
const DEFAULT_MAX_FILE_BYTES = 1048576;
|
|
46
|
+
const DEFAULT_DIMENSIONS = 1536;
|
|
47
|
+
const DEFAULT_MAX_INPUT_CHARS = 12e3;
|
|
48
|
+
const DEFAULT_API_KEY_ENV = "LITELLM_API_KEY";
|
|
49
|
+
|
|
50
|
+
//#endregion
|
|
51
|
+
export { DEFAULT_INCLUDE as a, LOCKFILES_BY_ECOSYSTEM as c, DEFAULT_EXCLUDE as i, NODE_DEPENDENCY_DIRS as l, DEFAULT_API_KEY_ENV as n, DEFAULT_MAX_FILE_BYTES as o, DEFAULT_DIMENSIONS as r, DEFAULT_MAX_INPUT_CHARS as s, BUILD_OUTPUT_DIRS as t, TEST_FILES_BY_ECOSYSTEM as u };
|
|
52
|
+
//# sourceMappingURL=defaults-BJs7a37e.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults-BJs7a37e.mjs","names":[],"sources":["../src/config/defaults.ts"],"sourcesContent":["export const DEFAULT_INCLUDE = [\n \"**/*.{ts,tsx,mts,cts,js,jsx,mjs,cjs,json,yaml,yml,md,mdx,feature,graphql,gql,sql,sh,py,java,kt,kts,go,rb,php,cs,css,scss,html,vue,svelte,toml,xml,properties,tf,gradle}\",\n \"**/Dockerfile\"\n];\n\nexport const LOCKFILES_BY_ECOSYSTEM = {\n node: [\"**/package-lock.json\", \"**/npm-shrinkwrap.json\", \"**/yarn.lock\", \"**/pnpm-lock.yaml\", \"**/bun.lock\", \"**/bun.lockb\"],\n python: [\"**/poetry.lock\", \"**/Pipfile.lock\", \"**/uv.lock\"],\n rust: [\"**/Cargo.lock\"],\n go: [\"**/go.sum\"],\n php: [\"**/composer.lock\"],\n ruby: [\"**/Gemfile.lock\"],\n jvm: [\"**/gradle.lockfile\"]\n};\n\nexport const LOCKFILES = Object.values(LOCKFILES_BY_ECOSYSTEM).flat();\n\n// Test files are left out of the index: they double its size without describing production behavior.\nexport const TEST_FILES_BY_ECOSYSTEM = {\n node: [\"**/*.spec.*\", \"**/*.test.*\"],\n python: [\"**/test_*.py\", \"**/*_test.py\"],\n go: [\"**/*_test.go\"],\n jvm: [\"**/src/test/**\"]\n};\n\nexport const TEST_FILES = Object.values(TEST_FILES_BY_ECOSYSTEM).flat();\n\n/** Installed dependencies of a Node.js project. */\nexport const NODE_DEPENDENCY_DIRS = [\"**/node_modules/**\", \"**/.yarn/**\"];\n\n/** Generated build and coverage output, whatever the ecosystem. */\nexport const BUILD_OUTPUT_DIRS = [\"**/dist/**\", \"**/build/**\", \"**/coverage/**\"];\n\nexport const DEFAULT_EXCLUDE = [...NODE_DEPENDENCY_DIRS, ...BUILD_OUTPUT_DIRS, ...LOCKFILES, ...TEST_FILES];\n\nexport const DEFAULT_MAX_FILE_BYTES = 1024 * 1024;\nexport const DEFAULT_CHUNK_LINES = 100;\nexport const DEFAULT_CHUNK_OVERLAP = 15;\nexport const DEFAULT_DIMENSIONS = 1536;\nexport const DEFAULT_BATCH_SIZE = 64;\nexport const DEFAULT_EMBEDDING_CONCURRENCY = 4;\nexport const DEFAULT_MAX_RETRIES = 3;\nexport const DEFAULT_MAX_INPUT_CHARS = 12_000;\nexport const DEFAULT_API_KEY_ENV = \"LITELLM_API_KEY\";\n"],"mappings":";AAAA,MAAa,kBAAkB,CAC7B,2KACA,eACF;AAEA,MAAa,yBAAyB;CACpC,MAAM;EAAC;EAAwB;EAA0B;EAAgB;EAAqB;EAAe;CAAc;CAC3H,QAAQ;EAAC;EAAkB;EAAmB;CAAY;CAC1D,MAAM,CAAC,eAAe;CACtB,IAAI,CAAC,WAAW;CAChB,KAAK,CAAC,kBAAkB;CACxB,MAAM,CAAC,iBAAiB;CACxB,KAAK,CAAC,oBAAoB;AAC5B;AAEA,MAAa,YAAY,OAAO,OAAO,sBAAsB,CAAC,CAAC,KAAK;AAGpE,MAAa,0BAA0B;CACrC,MAAM,CAAC,eAAe,aAAa;CACnC,QAAQ,CAAC,gBAAgB,cAAc;CACvC,IAAI,CAAC,cAAc;CACnB,KAAK,CAAC,gBAAgB;AACxB;AAEA,MAAa,aAAa,OAAO,OAAO,uBAAuB,CAAC,CAAC,KAAK;;AAGtE,MAAa,uBAAuB,CAAC,sBAAsB,aAAa;;AAGxE,MAAa,oBAAoB;CAAC;CAAc;CAAe;AAAgB;AAE/E,MAAa,kBAAkB;CAAC,GAAG;CAAsB,GAAG;CAAmB,GAAG;CAAW,GAAG;AAAU;AAE1G,MAAa,yBAAyB;AAGtC,MAAa,qBAAqB;AAIlC,MAAa,0BAA0B;AACvC,MAAa,sBAAsB"}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
//#region src/config/interfaces/UserConfig.d.ts
|
|
2
|
+
type RepositoryProvider = "github" | "gitlab";
|
|
3
|
+
interface RepositoryConfig {
|
|
4
|
+
provider: RepositoryProvider;
|
|
5
|
+
/** GitHub owner or GitLab namespace (group/subgroup). */
|
|
6
|
+
owner?: string;
|
|
7
|
+
/** Repository / project name. */
|
|
8
|
+
name?: string;
|
|
9
|
+
/** GitLab numeric id or full path. Takes precedence over `owner`/`name` for GitLab. */
|
|
10
|
+
projectId?: string | number;
|
|
11
|
+
/** REST API base URL. Defaults to https://api.github.com or $CI_API_V4_URL / https://gitlab.com/api/v4. */
|
|
12
|
+
apiUrl?: string;
|
|
13
|
+
}
|
|
14
|
+
interface SourcesConfig {
|
|
15
|
+
/** Globs (minimatch, dot files included) of Git-tracked files to index. */
|
|
16
|
+
include?: string[];
|
|
17
|
+
/** Globs excluded from `include`. */
|
|
18
|
+
exclude?: string[];
|
|
19
|
+
/** Files larger than this are skipped. Default: 1 MiB. */
|
|
20
|
+
maxFileBytes?: number;
|
|
21
|
+
}
|
|
22
|
+
interface ChunkingConfig {
|
|
23
|
+
/** Lines per chunk. Default: 100. */
|
|
24
|
+
lines?: number;
|
|
25
|
+
/** Lines shared between two consecutive chunks. Default: 15. */
|
|
26
|
+
overlap?: number;
|
|
27
|
+
}
|
|
28
|
+
interface EmbeddingConfig {
|
|
29
|
+
/** OpenAI-compatible base URL (LiteLLM). `/v1` is appended when missing. */
|
|
30
|
+
baseUrl: string;
|
|
31
|
+
/** Primary model alias. */
|
|
32
|
+
model: string;
|
|
33
|
+
/** Aliases tried, in order, when the primary model fails. They must produce identical vectors. */
|
|
34
|
+
fallbackModels?: string[];
|
|
35
|
+
/** Model recorded in the manifest (the public model behind the gateway aliases). Default: `model`. */
|
|
36
|
+
referenceModel?: string;
|
|
37
|
+
/** Default: 1536. */
|
|
38
|
+
dimensions?: number;
|
|
39
|
+
/** Inputs per request. Default: 64. */
|
|
40
|
+
batchSize?: number;
|
|
41
|
+
/** Batches sent in parallel. Default: 4. */
|
|
42
|
+
concurrency?: number;
|
|
43
|
+
/** Retries per model and batch before switching to the next fallback. Default: 3. */
|
|
44
|
+
maxRetries?: number;
|
|
45
|
+
/** Embedded text is truncated to this length. Default: 12000. */
|
|
46
|
+
maxInputChars?: number;
|
|
47
|
+
/** Name of the environment variable holding the API key. Default: LITELLM_API_KEY. */
|
|
48
|
+
apiKeyEnv?: string;
|
|
49
|
+
}
|
|
50
|
+
/** Published on the release of the repository's provider (GitHub release asset or GitLab release link). */
|
|
51
|
+
interface PublishConfig {
|
|
52
|
+
/** Release tag template. Default: `version-{version}`. */
|
|
53
|
+
tag?: string;
|
|
54
|
+
/** Archive name template. Default: `source-pack-{version}.tar.gz`. */
|
|
55
|
+
assetName?: string;
|
|
56
|
+
/** GitLab Generic Package name. Default: `source-pack`. */
|
|
57
|
+
packageName?: string;
|
|
58
|
+
/** Create the release when the tag has none. Default: false (the release tool owns releases). */
|
|
59
|
+
createRelease?: boolean;
|
|
60
|
+
}
|
|
61
|
+
interface UserConfig {
|
|
62
|
+
/** Output directory, relative to the command's working directory. Default: `./tmp/source-pack`. */
|
|
63
|
+
outputDir?: string;
|
|
64
|
+
repository: RepositoryConfig;
|
|
65
|
+
sources?: SourcesConfig;
|
|
66
|
+
chunking?: ChunkingConfig;
|
|
67
|
+
/** Omit to build a lexical-only pack (no embeddings.f32). */
|
|
68
|
+
embedding?: EmbeddingConfig;
|
|
69
|
+
/** Git-tracked files copied verbatim into the pack under `attachments/`. */
|
|
70
|
+
attachments?: string[];
|
|
71
|
+
publish?: PublishConfig;
|
|
72
|
+
}
|
|
73
|
+
//#endregion
|
|
74
|
+
//#region src/fn/defineConfig.d.ts
|
|
75
|
+
declare function defineConfig(config: UserConfig): UserConfig;
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region src/interfaces/SourceChunk.d.ts
|
|
78
|
+
interface SourceChunk {
|
|
79
|
+
/** sha256 of `${path}:${startLine}:${text}` */
|
|
80
|
+
id: string;
|
|
81
|
+
/** POSIX path relative to the repository root */
|
|
82
|
+
path: string;
|
|
83
|
+
/** 1-based, inclusive */
|
|
84
|
+
startLine: number;
|
|
85
|
+
/** 1-based, inclusive */
|
|
86
|
+
endLine: number;
|
|
87
|
+
text: string;
|
|
88
|
+
}
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/interfaces/SourcePackManifest.d.ts
|
|
91
|
+
interface SourcePackProject {
|
|
92
|
+
provider: RepositoryProvider;
|
|
93
|
+
/** Stable project identifier, e.g. `github:ClubMediterranee/digital-api` or `gitlab:1234`. */
|
|
94
|
+
id: string;
|
|
95
|
+
owner?: string;
|
|
96
|
+
name?: string;
|
|
97
|
+
projectId?: string;
|
|
98
|
+
apiUrl: string;
|
|
99
|
+
}
|
|
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
|
+
interface SourcePackEmbeddingInfo {
|
|
109
|
+
/** Reference model (never the regional alias actually called) */
|
|
110
|
+
model: string;
|
|
111
|
+
dimensions: number;
|
|
112
|
+
/** How a chunk is turned into the embedded text */
|
|
113
|
+
input: string;
|
|
114
|
+
maxInputChars: number;
|
|
115
|
+
/** Little-endian float32, one vector per chunk, in chunk order */
|
|
116
|
+
encoding: "float32-le";
|
|
117
|
+
file: string;
|
|
118
|
+
}
|
|
119
|
+
interface SourcePackManifest {
|
|
120
|
+
formatVersion: number;
|
|
121
|
+
generator: {
|
|
122
|
+
name: string;
|
|
123
|
+
version: string;
|
|
124
|
+
};
|
|
125
|
+
project: SourcePackProject;
|
|
126
|
+
version: string;
|
|
127
|
+
tag: string;
|
|
128
|
+
ref: string;
|
|
129
|
+
sha: string;
|
|
130
|
+
committedAt: string;
|
|
131
|
+
createdAt: string;
|
|
132
|
+
/** Chunking algorithm; its parameters (`lines`, `overlap`) are in `config.chunking`. */
|
|
133
|
+
chunking: {
|
|
134
|
+
formatVersion: number;
|
|
135
|
+
idAlgorithm: string;
|
|
136
|
+
};
|
|
137
|
+
config: {
|
|
138
|
+
/** sha256 of the canonical JSON of `sources` + `chunking` (+ chunking format version) */
|
|
139
|
+
fingerprint: string;
|
|
140
|
+
sources: {
|
|
141
|
+
include: string[];
|
|
142
|
+
exclude: string[];
|
|
143
|
+
maxFileBytes: number;
|
|
144
|
+
};
|
|
145
|
+
chunking: {
|
|
146
|
+
lines: number;
|
|
147
|
+
overlap: number;
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
embedding: SourcePackEmbeddingInfo | null;
|
|
151
|
+
files: {
|
|
152
|
+
indexed: number;
|
|
153
|
+
skippedBinary: number;
|
|
154
|
+
skippedTooLarge: number;
|
|
155
|
+
};
|
|
156
|
+
chunks: {
|
|
157
|
+
count: number;
|
|
158
|
+
file: string;
|
|
159
|
+
};
|
|
160
|
+
attachments: SourcePackAttachment[];
|
|
161
|
+
publish: {
|
|
162
|
+
assetName: string;
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
//#endregion
|
|
166
|
+
//#region src/interfaces/SourcePack.d.ts
|
|
167
|
+
interface SourcePack {
|
|
168
|
+
manifest: SourcePackManifest;
|
|
169
|
+
chunks: SourceChunk[];
|
|
170
|
+
/** All vectors, concatenated in chunk order (`chunks.length * dimensions` floats), or null for a pack built without embeddings. */
|
|
171
|
+
embeddings: Float32Array | null;
|
|
172
|
+
/** Attachments keyed by their repository path. */
|
|
173
|
+
attachments: Map<string, Buffer>;
|
|
174
|
+
/** Vector of the chunk at `index` (a view on `embeddings`), or null. */
|
|
175
|
+
getEmbedding(index: number): Float32Array | null;
|
|
176
|
+
}
|
|
177
|
+
//#endregion
|
|
178
|
+
//#region src/pack/readSourcePack.d.ts
|
|
179
|
+
/**
|
|
180
|
+
* Reads a `source-pack-<version>.tar.gz` (file path or bytes) and checks its consistency
|
|
181
|
+
* (format version, chunk count, embedding size).
|
|
182
|
+
*/
|
|
183
|
+
declare function readSourcePack(source: string | Uint8Array): Promise<SourcePack>;
|
|
184
|
+
//#endregion
|
|
185
|
+
//#region src/config/interfaces/ResolvedConfig.d.ts
|
|
186
|
+
interface ResolvedRepositoryConfig {
|
|
187
|
+
provider: RepositoryProvider;
|
|
188
|
+
owner?: string;
|
|
189
|
+
name?: string;
|
|
190
|
+
projectId?: string;
|
|
191
|
+
apiUrl: string;
|
|
192
|
+
}
|
|
193
|
+
interface ResolvedEmbeddingConfig {
|
|
194
|
+
baseUrl: string;
|
|
195
|
+
model: string;
|
|
196
|
+
fallbackModels: string[];
|
|
197
|
+
referenceModel: string;
|
|
198
|
+
dimensions: number;
|
|
199
|
+
batchSize: number;
|
|
200
|
+
concurrency: number;
|
|
201
|
+
maxRetries: number;
|
|
202
|
+
maxInputChars: number;
|
|
203
|
+
apiKeyEnv: string;
|
|
204
|
+
}
|
|
205
|
+
interface ResolvedPublishConfig {
|
|
206
|
+
tag: string;
|
|
207
|
+
assetName: string;
|
|
208
|
+
packageName: string;
|
|
209
|
+
createRelease: boolean;
|
|
210
|
+
}
|
|
211
|
+
interface ResolvedConfig {
|
|
212
|
+
/** Absolute path of the loaded config file (empty when built in memory). */
|
|
213
|
+
configPath: string;
|
|
214
|
+
/** Directory the command runs from; relative paths are resolved against it. */
|
|
215
|
+
cwd: string;
|
|
216
|
+
outputDir: string;
|
|
217
|
+
repository: ResolvedRepositoryConfig;
|
|
218
|
+
sources: {
|
|
219
|
+
include: string[];
|
|
220
|
+
exclude: string[];
|
|
221
|
+
maxFileBytes: number;
|
|
222
|
+
};
|
|
223
|
+
chunking: {
|
|
224
|
+
lines: number;
|
|
225
|
+
overlap: number;
|
|
226
|
+
};
|
|
227
|
+
embedding: ResolvedEmbeddingConfig | null;
|
|
228
|
+
attachments: string[];
|
|
229
|
+
publish: ResolvedPublishConfig;
|
|
230
|
+
}
|
|
231
|
+
//#endregion
|
|
232
|
+
//#region src/utils/logger.d.ts
|
|
233
|
+
interface Logger {
|
|
234
|
+
info(message: string): void;
|
|
235
|
+
warn(message: string): void;
|
|
236
|
+
error(message: string): void;
|
|
237
|
+
}
|
|
238
|
+
//#endregion
|
|
239
|
+
//#region src/pack/buildSourcePack.d.ts
|
|
240
|
+
interface BuildSourcePackOptions {
|
|
241
|
+
config: ResolvedConfig;
|
|
242
|
+
/** Commit-ish to index. Default: `tag` when given, otherwise HEAD. */
|
|
243
|
+
ref?: string;
|
|
244
|
+
/** Release tag. Default: `publish.tag` rendered with the version. */
|
|
245
|
+
tag?: string;
|
|
246
|
+
/** Release version. Default: extracted from `tag`, otherwise `version` of package.json at the ref. */
|
|
247
|
+
version?: string;
|
|
248
|
+
/** Build the pack without embeddings.f32 (no LiteLLM call). */
|
|
249
|
+
skipEmbeddings?: boolean;
|
|
250
|
+
/** Compute chunks and sizes without calling LiteLLM nor writing anything. */
|
|
251
|
+
dryRun?: boolean;
|
|
252
|
+
env?: NodeJS.ProcessEnv;
|
|
253
|
+
fetch?: typeof globalThis.fetch;
|
|
254
|
+
logger?: Logger;
|
|
255
|
+
now?: () => Date;
|
|
256
|
+
}
|
|
257
|
+
interface BuildSourcePackResult {
|
|
258
|
+
manifest: SourcePackManifest;
|
|
259
|
+
chunks: SourceChunk[];
|
|
260
|
+
dryRun: boolean;
|
|
261
|
+
archivePath?: string;
|
|
262
|
+
/** Archive size (or estimate in dry-run: gzipped chunks + raw embeddings + attachments). */
|
|
263
|
+
bytes: number;
|
|
264
|
+
chunksBytes: number;
|
|
265
|
+
embeddingsBytes: number;
|
|
266
|
+
}
|
|
267
|
+
/** Builds the source pack of `config.repository` at a commit: chunks + embeddings + attachments + manifest. */
|
|
268
|
+
declare function buildSourcePack(options: BuildSourcePackOptions): Promise<BuildSourcePackResult>;
|
|
269
|
+
//#endregion
|
|
270
|
+
//#region src/pack/writeSourcePack.d.ts
|
|
271
|
+
interface WriteSourcePackOptions {
|
|
272
|
+
archivePath: string;
|
|
273
|
+
manifest: SourcePackManifest;
|
|
274
|
+
chunks: SourceChunk[];
|
|
275
|
+
embeddings: Float32Array | null;
|
|
276
|
+
/** Keyed by the archive path declared in `manifest.attachments[].file` */
|
|
277
|
+
attachments: Map<string, Buffer>;
|
|
278
|
+
}
|
|
279
|
+
interface WrittenSourcePack {
|
|
280
|
+
archivePath: string;
|
|
281
|
+
bytes: number;
|
|
282
|
+
chunksBytes: number;
|
|
283
|
+
embeddingsBytes: number;
|
|
284
|
+
}
|
|
285
|
+
/** Writes `manifest.json`, `chunks.jsonl.gz`, `embeddings.f32` and attachments into a deterministic `.tar.gz`. */
|
|
286
|
+
declare function writeSourcePack({ archivePath, manifest, chunks, embeddings, attachments }: WriteSourcePackOptions): Promise<WrittenSourcePack>;
|
|
287
|
+
//#endregion
|
|
288
|
+
//#region src/publish/interfaces/PublishContext.d.ts
|
|
289
|
+
interface PublishResult {
|
|
290
|
+
target: string;
|
|
291
|
+
dryRun: boolean;
|
|
292
|
+
/** Download URL of the published asset (planned URL in dry-run). */
|
|
293
|
+
url: string;
|
|
294
|
+
/** True when an asset with the same name was replaced. */
|
|
295
|
+
replaced: boolean;
|
|
296
|
+
}
|
|
297
|
+
//#endregion
|
|
298
|
+
//#region src/publish/publishSourcePack.d.ts
|
|
299
|
+
interface PublishSourcePackOptions {
|
|
300
|
+
config: ResolvedConfig;
|
|
301
|
+
/** Archive to publish. Default: the archive of the last `build` in `outputDir`. */
|
|
302
|
+
archivePath?: string;
|
|
303
|
+
dryRun?: boolean;
|
|
304
|
+
env?: NodeJS.ProcessEnv;
|
|
305
|
+
fetch?: typeof globalThis.fetch;
|
|
306
|
+
logger?: Logger;
|
|
307
|
+
}
|
|
308
|
+
/** Publishes a built source pack on the release of its tag, on the provider of `repository`. Idempotent. */
|
|
309
|
+
declare function publishSourcePack(options: PublishSourcePackOptions): Promise<PublishResult>;
|
|
310
|
+
//#endregion
|
|
311
|
+
//#region src/config/loadConfig.d.ts
|
|
312
|
+
/**
|
|
313
|
+
* Loads `source-pack.config.ts` (through tsx) or a `.mjs`/`.js` config, then validates it.
|
|
314
|
+
* Relative paths of the config are resolved against `cwd` (the command's directory).
|
|
315
|
+
*/
|
|
316
|
+
declare function loadConfig(configPath: string, { cwd, env }?: {
|
|
317
|
+
cwd?: string;
|
|
318
|
+
env?: NodeJS.ProcessEnv;
|
|
319
|
+
}): Promise<ResolvedConfig>;
|
|
320
|
+
//#endregion
|
|
321
|
+
//#region src/config/resolveConfig.d.ts
|
|
322
|
+
interface ResolveConfigOptions {
|
|
323
|
+
cwd?: string;
|
|
324
|
+
configPath?: string;
|
|
325
|
+
env?: NodeJS.ProcessEnv;
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Validates a raw user config and fills every default. Throws an explicit, field-level error message on invalid input.
|
|
329
|
+
*/
|
|
330
|
+
declare function resolveConfig(raw: unknown, { cwd, configPath, env }?: ResolveConfigOptions): ResolvedConfig;
|
|
331
|
+
//#endregion
|
|
332
|
+
//#region src/chunking/chunkText.d.ts
|
|
333
|
+
/**
|
|
334
|
+
* Splits a file into overlapping line windows. Identical to the state-control indexer:
|
|
335
|
+
* windows of `lines` lines advancing by `lines - overlap`, blank windows skipped,
|
|
336
|
+
* id = sha256(`${path}:${startLine}:${text}`).
|
|
337
|
+
*/
|
|
338
|
+
declare function chunkText(path: string, text: string, lines?: number, overlap?: number): SourceChunk[];
|
|
339
|
+
//#endregion
|
|
340
|
+
//#region src/chunking/embeddingInput.d.ts
|
|
341
|
+
/** Text sent to the embedding model for a chunk (`path\ntext`, truncated). Reuse it when re-embedding chunks. */
|
|
342
|
+
declare function embeddingInput(chunk: Pick<SourceChunk, "path" | "text">, maxChars?: number): string;
|
|
343
|
+
//#endregion
|
|
344
|
+
//#region src/chunking/configFingerprint.d.ts
|
|
345
|
+
interface FingerprintInput {
|
|
346
|
+
sources: {
|
|
347
|
+
include: string[];
|
|
348
|
+
exclude: string[];
|
|
349
|
+
maxFileBytes: number;
|
|
350
|
+
};
|
|
351
|
+
chunking: {
|
|
352
|
+
lines: number;
|
|
353
|
+
overlap: number;
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
/** Fingerprint of everything that determines the chunk set for a given commit. */
|
|
357
|
+
declare function configFingerprint({ sources, chunking }: FingerprintInput): string;
|
|
358
|
+
//#endregion
|
|
359
|
+
//#region src/embedding/embedTexts.d.ts
|
|
360
|
+
interface EmbedTextsOptions {
|
|
361
|
+
config: ResolvedEmbeddingConfig;
|
|
362
|
+
apiKey: string;
|
|
363
|
+
fetch?: typeof globalThis.fetch;
|
|
364
|
+
logger?: Logger;
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Embeds `inputs` in batches through an OpenAI-compatible `/v1/embeddings` endpoint, `concurrency` batches at a time.
|
|
368
|
+
* Each batch is retried `maxRetries` times per model; when the current model keeps failing,
|
|
369
|
+
* the next `fallbackModels` alias is used for this batch and the following ones.
|
|
370
|
+
* Returns the vectors concatenated in input order.
|
|
371
|
+
*/
|
|
372
|
+
declare function embedTexts(inputs: string[], { config, apiKey, fetch, logger }: EmbedTextsOptions): Promise<Float32Array>;
|
|
373
|
+
//#endregion
|
|
374
|
+
//#region src/constants.d.ts
|
|
375
|
+
declare const PACKAGE_NAME = "@cmflow/source-pack";
|
|
376
|
+
/** Version of the archive layout (manifest, chunks, embeddings, attachments). */
|
|
377
|
+
declare const SOURCE_PACK_FORMAT_VERSION = 2;
|
|
378
|
+
/** Version of the chunking algorithm. Bump it whenever chunk boundaries or ids change. */
|
|
379
|
+
declare const CHUNKING_FORMAT_VERSION = 1;
|
|
380
|
+
declare const CHUNK_ID_ALGORITHM = "sha256(path:startLine:text)";
|
|
381
|
+
declare const EMBEDDING_INPUT_FORMAT = "path\\ntext";
|
|
382
|
+
declare const MANIFEST_FILE = "manifest.json";
|
|
383
|
+
declare const CHUNKS_FILE = "chunks.jsonl.gz";
|
|
384
|
+
declare const EMBEDDINGS_FILE = "embeddings.f32";
|
|
385
|
+
declare const ATTACHMENTS_DIR = "attachments";
|
|
386
|
+
declare const DEFAULT_CONFIG_FILE = "source-pack.config.ts";
|
|
387
|
+
declare const DEFAULT_OUTPUT_DIR = "./tmp/source-pack";
|
|
388
|
+
declare const DEFAULT_TAG_TEMPLATE = "version-{version}";
|
|
389
|
+
declare const DEFAULT_ASSET_NAME_TEMPLATE = "source-pack-{version}.tar.gz";
|
|
390
|
+
declare const DEFAULT_GITLAB_PACKAGE_NAME = "source-pack";
|
|
391
|
+
declare const DEFAULT_GITHUB_API_URL = "https://api.github.com";
|
|
392
|
+
declare const DEFAULT_GITLAB_API_URL = "https://gitlab.com/api/v4";
|
|
393
|
+
declare const GITHUB_TOKEN_ENV = "GITHUB_TOKEN";
|
|
394
|
+
declare const GITLAB_TOKEN_ENV = "GITLAB_TOKEN";
|
|
395
|
+
//#endregion
|
|
396
|
+
export { ATTACHMENTS_DIR, 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 SourcePackAttachment, type SourcePackEmbeddingInfo, type SourcePackManifest, type SourcePackProject, type SourcesConfig, type UserConfig, buildSourcePack, chunkText, configFingerprint, defineConfig, embedTexts, embeddingInput, loadConfig, publishSourcePack, readSourcePack, resolveConfig, writeSourcePack };
|
|
397
|
+
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { _ as PACKAGE_NAME, a as DEFAULT_ASSET_NAME_TEMPLATE, c as DEFAULT_GITLAB_API_URL, d as DEFAULT_TAG_TEMPLATE, f as EMBEDDINGS_FILE, g as MANIFEST_FILE, h as GITLAB_TOKEN_ENV, i as CHUNK_ID_ALGORITHM, l as DEFAULT_GITLAB_PACKAGE_NAME, m as GITHUB_TOKEN_ENV, n as CHUNKING_FORMAT_VERSION, o as DEFAULT_CONFIG_FILE, p as EMBEDDING_INPUT_FORMAT, r as CHUNKS_FILE, s as DEFAULT_GITHUB_API_URL, t as ATTACHMENTS_DIR, u as DEFAULT_OUTPUT_DIR, v as SOURCE_PACK_FORMAT_VERSION } from "./constants-DkiLCuIK.mjs";
|
|
2
|
+
import { n as resolveConfig, t as loadConfig } from "./loadConfig-CNrL90dq.mjs";
|
|
3
|
+
import { n as readArchiveEntries, t as publishSourcePack } from "./publishSourcePack-xNr9RBgv.mjs";
|
|
4
|
+
import { a as configFingerprint, i as embeddingInput, n as writeSourcePack, o as chunkText, r as embedTexts, t as buildSourcePack } from "./buildSourcePack-CaaMZ_tw.mjs";
|
|
5
|
+
import { promisify } from "node:util";
|
|
6
|
+
import { gunzip } from "node:zlib";
|
|
7
|
+
|
|
8
|
+
//#region src/fn/defineConfig.ts
|
|
9
|
+
function defineConfig(config) {
|
|
10
|
+
return config;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/pack/decodeEmbeddings.ts
|
|
15
|
+
const LITTLE_ENDIAN_HOST = new Uint8Array(new Uint16Array([1]).buffer)[0] === 1;
|
|
16
|
+
/**
|
|
17
|
+
* Inverse of `encodeEmbeddings`. On a little-endian host the result is a view on the bytes when they are 4-byte aligned
|
|
18
|
+
* (one copy otherwise); a big-endian host decodes every value.
|
|
19
|
+
*/
|
|
20
|
+
function decodeEmbeddings(buffer, littleEndianHost = LITTLE_ENDIAN_HOST) {
|
|
21
|
+
if (buffer.byteLength % 4 !== 0) throw new Error(`Invalid embeddings file: ${buffer.byteLength} bytes is not a multiple of 4`);
|
|
22
|
+
if (littleEndianHost) {
|
|
23
|
+
const aligned = buffer.byteOffset % 4 === 0 ? buffer : new Uint8Array(buffer);
|
|
24
|
+
return new Float32Array(aligned.buffer, aligned.byteOffset, aligned.byteLength / 4);
|
|
25
|
+
}
|
|
26
|
+
const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
27
|
+
const vectors = new Float32Array(buffer.byteLength / 4);
|
|
28
|
+
for (let index = 0; index < vectors.length; index += 1) vectors[index] = view.getFloat32(index * 4, true);
|
|
29
|
+
return vectors;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/pack/readSourcePack.ts
|
|
34
|
+
const gunzipAsync = promisify(gunzip);
|
|
35
|
+
function required(files, name) {
|
|
36
|
+
const file = files.get(name);
|
|
37
|
+
if (!file) throw new Error(`Invalid source pack: ${name} is missing`);
|
|
38
|
+
return file;
|
|
39
|
+
}
|
|
40
|
+
function readEmbeddings(files, manifest) {
|
|
41
|
+
const { embedding, chunks } = manifest;
|
|
42
|
+
if (!embedding) return null;
|
|
43
|
+
const embeddings = decodeEmbeddings(required(files, embedding.file));
|
|
44
|
+
if (embeddings.length !== chunks.count * embedding.dimensions) throw new Error(`Invalid source pack: expected ${chunks.count} x ${embedding.dimensions} floats, found ${embeddings.length}`);
|
|
45
|
+
return embeddings;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Reads a `source-pack-<version>.tar.gz` (file path or bytes) and checks its consistency
|
|
49
|
+
* (format version, chunk count, embedding size).
|
|
50
|
+
*/
|
|
51
|
+
async function readSourcePack(source) {
|
|
52
|
+
const files = await readArchiveEntries(source);
|
|
53
|
+
const manifest = JSON.parse(required(files, MANIFEST_FILE).toString("utf8"));
|
|
54
|
+
if (manifest.formatVersion !== 2) throw new Error(`Unsupported source pack format ${manifest.formatVersion} (this reader supports ${2})`);
|
|
55
|
+
const chunks = (await gunzipAsync(required(files, manifest.chunks.file))).toString("utf8").split("\n").filter(Boolean).map((line) => JSON.parse(line));
|
|
56
|
+
if (chunks.length !== manifest.chunks.count) throw new Error(`Invalid source pack: manifest declares ${manifest.chunks.count} chunks, found ${chunks.length}`);
|
|
57
|
+
const embeddings = readEmbeddings(files, manifest);
|
|
58
|
+
const dimensions = manifest.embedding?.dimensions ?? 0;
|
|
59
|
+
return {
|
|
60
|
+
manifest,
|
|
61
|
+
chunks,
|
|
62
|
+
embeddings,
|
|
63
|
+
attachments: new Map(manifest.attachments.map((attachment) => [attachment.path, required(files, attachment.file)])),
|
|
64
|
+
getEmbedding(index) {
|
|
65
|
+
if (!embeddings || index < 0 || index >= chunks.length) return null;
|
|
66
|
+
return embeddings.subarray(index * dimensions, (index + 1) * dimensions);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
//#endregion
|
|
72
|
+
export { ATTACHMENTS_DIR, 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
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +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 manifest = JSON.parse(required(files, MANIFEST_FILE).toString(\"utf8\")) as SourcePackManifest;\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 const attachments = new Map(manifest.attachments.map((attachment) => [attachment.path, required(files, attachment.file)]));\n\n return {\n manifest,\n chunks,\n embeddings,\n attachments,\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,IAAI,WAAW,MAAM;EAE5E,OAAO,IAAI,aAAa,QAAQ,QAAQ,QAAQ,YAAY,QAAQ,aAAa,CAAC;CACpF;CAEA,MAAM,OAAO,IAAI,SAAS,OAAO,QAAQ,OAAO,YAAY,OAAO,UAAU;CAC7E,MAAM,UAAU,IAAI,aAAa,OAAO,aAAa,CAAC;CAEtD,KAAK,IAAI,QAAQ,GAAG,QAAQ,QAAQ,QAAQ,SAAS,GACnD,QAAQ,SAAS,KAAK,WAAW,QAAQ,GAAG,IAAI;CAGlD,OAAO;AACT;;;;AChBA,MAAM,cAAc,UAAU,MAAM;AAEpC,SAAS,SAAS,OAA4B,MAAsB;CAClE,MAAM,OAAO,MAAM,IAAI,IAAI;CAE3B,IAAI,CAAC,MACH,MAAM,IAAI,MAAM,wBAAwB,KAAK,YAAY;CAG3D,OAAO;AACT;AAEA,SAAS,eAAe,OAA4B,UAAmD;CACrG,MAAM,EAAE,WAAW,WAAW;CAE9B,IAAI,CAAC,WACH,OAAO;CAGT,MAAM,aAAa,iBAAiB,SAAS,OAAO,UAAU,IAAI,CAAC;CAEnE,IAAI,WAAW,WAAW,OAAO,QAAQ,UAAU,YACjD,MAAM,IAAI,MAAM,iCAAiC,OAAO,MAAM,KAAK,UAAU,WAAW,iBAAiB,WAAW,QAAQ;CAG9H,OAAO;AACT;;;;;AAMA,eAAsB,eAAe,QAAkD;CACrF,MAAM,QAAQ,MAAM,mBAAmB,MAAM;CAC7C,MAAM,WAAW,KAAK,MAAM,SAAS,OAAO,aAAa,CAAC,CAAC,SAAS,MAAM,CAAC;CAE3E,IAAI,SAAS,qBACX,MAAM,IAAI,MAAM,kCAAkC,SAAS,cAAc,2BAAoD,EAAE;CAGjI,MAAM,UAAU,MAAM,YAAY,SAAS,OAAO,SAAS,OAAO,IAAI,CAAC,EAAC,CACrE,SAAS,MAAM,CAAC,CAChB,MAAM,IAAI,CAAC,CACX,OAAO,OAAO,CAAC,CACf,KAAK,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;CAGrD,OAAO;EACL;EACA;EACA;EACA,iBANsB,IAAI,SAAS,YAAY,KAAK,eAAe,CAAC,WAAW,MAAM,SAAS,OAAO,WAAW,IAAI,CAAC,CAAC,CAM5G;EACV,aAAa,OAAO;GAClB,IAAI,CAAC,cAAc,QAAQ,KAAK,SAAS,OAAO,QAC9C,OAAO;GAGT,OAAO,WAAW,SAAS,QAAQ,aAAa,QAAQ,KAAK,UAAU;EACzE;CACF;AACF"}
|