@bendyline/gezk 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +112 -9
- package/dist/index.js +302 -114
- package/dist/node.d.ts +1 -1
- package/dist/node.js +302 -114
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -147,12 +147,12 @@ var KnowledgeChunkingProfileSchema = z2.object({
|
|
|
147
147
|
});
|
|
148
148
|
|
|
149
149
|
// src/schemas/manifest.ts
|
|
150
|
-
import { z as
|
|
150
|
+
import { z as z4 } from "zod";
|
|
151
151
|
|
|
152
152
|
// src/format/constants.ts
|
|
153
|
-
var GEZK_FORMAT_VERSION = "0.
|
|
154
|
-
var GEZK_INDEX_SCHEMA_VERSION =
|
|
155
|
-
var GEZK_FORMAT_GENERATIONS = { "0.5": 2, "0.6": 3 };
|
|
153
|
+
var GEZK_FORMAT_VERSION = "0.7";
|
|
154
|
+
var GEZK_INDEX_SCHEMA_VERSION = 4;
|
|
155
|
+
var GEZK_FORMAT_GENERATIONS = { "0.5": 2, "0.6": 3, "0.7": 4 };
|
|
156
156
|
var GEZK_SUPPORTED_FORMAT_VERSIONS = Object.keys(GEZK_FORMAT_GENERATIONS);
|
|
157
157
|
var GEZK_SUPPORTED_INDEX_SCHEMA_VERSIONS = Object.values(GEZK_FORMAT_GENERATIONS);
|
|
158
158
|
function isSupportedFormatVersion(value) {
|
|
@@ -175,106 +175,250 @@ var MAX_KNOWLEDGE_DOCUMENT_META_BYTES = 16 * 1024;
|
|
|
175
175
|
var MAX_KNOWLEDGE_TOPIC_DEPTH = 16;
|
|
176
176
|
var ZIP_FIXED_MTIME = new Date(Date.UTC(2e3, 0, 1, 0, 0, 0));
|
|
177
177
|
|
|
178
|
+
// src/spatial.ts
|
|
179
|
+
import { z as z3 } from "zod";
|
|
180
|
+
var GEZK_EARTH_RADIUS_METERS = 6371e3;
|
|
181
|
+
var MAX_DOCUMENT_LOCATIONS = 256;
|
|
182
|
+
var KnowledgeLocationSchema = z3.object({
|
|
183
|
+
id: KnowledgeDocumentIdSchema,
|
|
184
|
+
latitude: z3.number().finite().min(-90).max(90),
|
|
185
|
+
longitude: z3.number().finite().min(-180).max(180),
|
|
186
|
+
role: z3.enum(["subject", "associated"]),
|
|
187
|
+
provenance: z3.record(z3.string(), z3.unknown()).optional()
|
|
188
|
+
}).strict();
|
|
189
|
+
var KnowledgeLocationsSchema = z3.array(KnowledgeLocationSchema).max(MAX_DOCUMENT_LOCATIONS).superRefine((locations, ctx) => {
|
|
190
|
+
const ids = /* @__PURE__ */ new Set();
|
|
191
|
+
for (const [index, location] of locations.entries()) {
|
|
192
|
+
if (ids.has(location.id))
|
|
193
|
+
ctx.addIssue({ code: "custom", path: [index, "id"], message: "duplicate location id" });
|
|
194
|
+
ids.add(location.id);
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
var KnowledgeRadiusSchema = z3.object({
|
|
198
|
+
latitude: z3.number().finite().min(-90).max(90),
|
|
199
|
+
longitude: z3.number().finite().min(-180).max(180),
|
|
200
|
+
radiusMeters: z3.number().finite().nonnegative()
|
|
201
|
+
}).strict();
|
|
202
|
+
var KnowledgeBoundsSchema = z3.object({
|
|
203
|
+
west: z3.number().finite().min(-180).max(180),
|
|
204
|
+
south: z3.number().finite().min(-90).max(90),
|
|
205
|
+
east: z3.number().finite().min(-180).max(180),
|
|
206
|
+
north: z3.number().finite().min(-90).max(90)
|
|
207
|
+
}).strict().refine((b) => b.west <= b.east && b.south <= b.north, "bounds must not wrap");
|
|
208
|
+
var KnowledgeSpatialManifestSchema = z3.object({
|
|
209
|
+
schema: z3.literal("document-points@1"),
|
|
210
|
+
crs: z3.literal("EPSG:4326"),
|
|
211
|
+
distanceModel: z3.literal("sphere-6371000"),
|
|
212
|
+
locationCount: z3.number().int().nonnegative(),
|
|
213
|
+
locatedDocuments: z3.number().int().nonnegative(),
|
|
214
|
+
coverage: z3.array(KnowledgeBoundsSchema).max(2)
|
|
215
|
+
}).strict().refine((s) => s.locatedDocuments <= s.locationCount, "located documents exceed locations");
|
|
216
|
+
function normalizeLongitude(longitude) {
|
|
217
|
+
return longitude === 180 ? -180 : longitude === 0 ? 0 : longitude;
|
|
218
|
+
}
|
|
219
|
+
function locationDistanceMeters(from, to) {
|
|
220
|
+
if (from.latitude === to.latitude && (Math.abs(from.latitude) === 90 || normalizeLongitude(from.longitude) === normalizeLongitude(to.longitude)))
|
|
221
|
+
return 0;
|
|
222
|
+
const radians = Math.PI / 180;
|
|
223
|
+
const dlat = (to.latitude - from.latitude) * radians;
|
|
224
|
+
const dlon = (normalizeLongitude(to.longitude) - normalizeLongitude(from.longitude)) * radians;
|
|
225
|
+
const a = Math.sin(dlat / 2) ** 2 + Math.cos(from.latitude * radians) * Math.cos(to.latitude * radians) * Math.sin(dlon / 2) ** 2;
|
|
226
|
+
const clamped = Math.max(0, Math.min(1, a));
|
|
227
|
+
return 2 * GEZK_EARTH_RADIUS_METERS * Math.atan2(Math.sqrt(clamped), Math.sqrt(1 - clamped));
|
|
228
|
+
}
|
|
229
|
+
function radiusBounds(raw) {
|
|
230
|
+
const radius = KnowledgeRadiusSchema.parse(raw);
|
|
231
|
+
if (radius.radiusMeters === 0) {
|
|
232
|
+
const longitude = normalizeLongitude(radius.longitude);
|
|
233
|
+
return [
|
|
234
|
+
{
|
|
235
|
+
west: Math.abs(radius.latitude) === 90 ? -180 : longitude,
|
|
236
|
+
east: Math.abs(radius.latitude) === 90 ? 180 : longitude,
|
|
237
|
+
south: radius.latitude,
|
|
238
|
+
north: radius.latitude
|
|
239
|
+
}
|
|
240
|
+
];
|
|
241
|
+
}
|
|
242
|
+
const radians = Math.PI / 180;
|
|
243
|
+
const delta = Math.min(Math.PI, radius.radiusMeters / GEZK_EARTH_RADIUS_METERS);
|
|
244
|
+
const lat = radius.latitude * radians;
|
|
245
|
+
const padding = radius.radiusMeters > 0 ? 1e-10 : 0;
|
|
246
|
+
const south = Math.max(-90, (lat - delta) / radians - padding);
|
|
247
|
+
const north = Math.min(90, (lat + delta) / radians + padding);
|
|
248
|
+
if (south <= -90 || north >= 90) return [{ west: -180, east: 180, south, north }];
|
|
249
|
+
const width = Math.asin(Math.min(1, Math.sin(delta) / Math.cos(lat))) / radians + padding;
|
|
250
|
+
const lon = normalizeLongitude(radius.longitude);
|
|
251
|
+
const west = lon - width;
|
|
252
|
+
const east = lon + width;
|
|
253
|
+
if (west < -180)
|
|
254
|
+
return [
|
|
255
|
+
{ west: west + 360, east: 180, south, north },
|
|
256
|
+
{ west: -180, east, south, north }
|
|
257
|
+
];
|
|
258
|
+
if (east >= 180)
|
|
259
|
+
return [
|
|
260
|
+
{ west, east: 180, south, north },
|
|
261
|
+
{ west: -180, east: east - 360, south, north }
|
|
262
|
+
];
|
|
263
|
+
return [{ west, east, south, north }];
|
|
264
|
+
}
|
|
265
|
+
function locationInBounds(location, bounds) {
|
|
266
|
+
const longitude = normalizeLongitude(location.longitude);
|
|
267
|
+
return location.latitude >= bounds.south && location.latitude <= bounds.north && longitude >= bounds.west && longitude <= bounds.east;
|
|
268
|
+
}
|
|
269
|
+
function spatialManifest(locations) {
|
|
270
|
+
const subjects = locations.filter((r) => r.location.role === "subject");
|
|
271
|
+
const coverage = [];
|
|
272
|
+
if (subjects.length) {
|
|
273
|
+
const latitudes = subjects.map((r) => r.location.latitude);
|
|
274
|
+
const longitudes = [
|
|
275
|
+
...new Set(subjects.map((r) => normalizeLongitude(r.location.longitude)))
|
|
276
|
+
].sort((a, b) => a - b);
|
|
277
|
+
let gap = -1;
|
|
278
|
+
let startIndex = 0;
|
|
279
|
+
for (let i = 0; i < longitudes.length; i++) {
|
|
280
|
+
const next = longitudes[(i + 1) % longitudes.length] + (i === longitudes.length - 1 ? 360 : 0);
|
|
281
|
+
if (next - longitudes[i] > gap) {
|
|
282
|
+
gap = next - longitudes[i];
|
|
283
|
+
startIndex = (i + 1) % longitudes.length;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
let south = 90;
|
|
287
|
+
let north = -90;
|
|
288
|
+
for (const latitude of latitudes) {
|
|
289
|
+
south = Math.min(south, latitude);
|
|
290
|
+
north = Math.max(north, latitude);
|
|
291
|
+
}
|
|
292
|
+
const west = longitudes[startIndex];
|
|
293
|
+
const east = longitudes[(startIndex + longitudes.length - 1) % longitudes.length];
|
|
294
|
+
if (west <= east) coverage.push({ west, east, south, north });
|
|
295
|
+
else coverage.push({ west, east: 180, south, north }, { west: -180, east, south, north });
|
|
296
|
+
}
|
|
297
|
+
return {
|
|
298
|
+
schema: "document-points@1",
|
|
299
|
+
crs: "EPSG:4326",
|
|
300
|
+
distanceModel: "sphere-6371000",
|
|
301
|
+
locationCount: locations.length,
|
|
302
|
+
locatedDocuments: new Set(locations.map((r) => r.documentId)).size,
|
|
303
|
+
coverage
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
|
|
178
307
|
// src/schemas/manifest.ts
|
|
179
308
|
var GEZK_MANIFEST_KIND = "gezk-catalog";
|
|
180
309
|
var GEZK_REGISTRY_KIND = "gezk-registry";
|
|
181
|
-
var KnowledgeManifestFileSchema =
|
|
182
|
-
path:
|
|
183
|
-
sizeBytes:
|
|
310
|
+
var KnowledgeManifestFileSchema = z4.object({
|
|
311
|
+
path: z4.string().min(1),
|
|
312
|
+
sizeBytes: z4.number().int().nonnegative(),
|
|
184
313
|
sha256: Sha256HexSchema
|
|
185
314
|
});
|
|
186
|
-
var KnowledgeSignatureSchema =
|
|
187
|
-
algorithm:
|
|
188
|
-
keyId:
|
|
189
|
-
canonicalization:
|
|
190
|
-
value:
|
|
315
|
+
var KnowledgeSignatureSchema = z4.object({
|
|
316
|
+
algorithm: z4.literal("ed25519"),
|
|
317
|
+
keyId: z4.string().min(1),
|
|
318
|
+
canonicalization: z4.literal("rfc8785"),
|
|
319
|
+
value: z4.string().min(1)
|
|
191
320
|
});
|
|
192
|
-
var KnowledgeCatalogManifestSchema =
|
|
193
|
-
kind:
|
|
194
|
-
formatVersion:
|
|
195
|
-
indexSchemaVersion:
|
|
321
|
+
var KnowledgeCatalogManifestSchema = z4.object({
|
|
322
|
+
kind: z4.literal(GEZK_MANIFEST_KIND),
|
|
323
|
+
formatVersion: z4.enum(GEZK_SUPPORTED_FORMAT_VERSIONS),
|
|
324
|
+
indexSchemaVersion: z4.union([z4.literal(2), z4.literal(3), z4.literal(4)]),
|
|
196
325
|
id: KnowledgeIdSchema,
|
|
197
326
|
version: KnowledgeVersionSchema,
|
|
198
|
-
name:
|
|
199
|
-
description:
|
|
200
|
-
language:
|
|
201
|
-
publisher:
|
|
327
|
+
name: z4.string().min(1),
|
|
328
|
+
description: z4.string().optional(),
|
|
329
|
+
language: z4.string().min(2),
|
|
330
|
+
publisher: z4.object({
|
|
202
331
|
id: KnowledgeIdSchema,
|
|
203
|
-
name:
|
|
204
|
-
url:
|
|
332
|
+
name: z4.string().min(1),
|
|
333
|
+
url: z4.string().optional()
|
|
205
334
|
}),
|
|
206
|
-
createdAt:
|
|
207
|
-
sourceSnapshot:
|
|
208
|
-
name:
|
|
209
|
-
date:
|
|
210
|
-
taxonomyVersion:
|
|
335
|
+
createdAt: z4.string(),
|
|
336
|
+
sourceSnapshot: z4.object({
|
|
337
|
+
name: z4.string(),
|
|
338
|
+
date: z4.string(),
|
|
339
|
+
taxonomyVersion: z4.string().optional()
|
|
211
340
|
}).optional(),
|
|
212
|
-
license:
|
|
213
|
-
name:
|
|
341
|
+
license: z4.object({
|
|
342
|
+
name: z4.string().min(1),
|
|
214
343
|
/** SPDX identifier when one exists (e.g. `CC-BY-SA-4.0`). */
|
|
215
|
-
spdx:
|
|
344
|
+
spdx: z4.string().optional(),
|
|
216
345
|
/** Archive path of the human-readable notice (`LICENSES/catalog.txt`). */
|
|
217
|
-
noticePath:
|
|
218
|
-
attributionRequired:
|
|
346
|
+
noticePath: z4.string().min(1),
|
|
347
|
+
attributionRequired: z4.boolean()
|
|
219
348
|
}),
|
|
220
349
|
embedding: KnowledgeEmbeddingProfileSchema,
|
|
221
350
|
chunking: KnowledgeChunkingProfileSchema,
|
|
222
|
-
topics:
|
|
223
|
-
|
|
351
|
+
topics: z4.array(
|
|
352
|
+
z4.object({
|
|
224
353
|
id: KnowledgeIdSchema,
|
|
225
|
-
name:
|
|
354
|
+
name: z4.string().min(1),
|
|
226
355
|
/** Absent for a root topic; names another entry of this list. */
|
|
227
356
|
parentId: KnowledgeIdSchema.optional(),
|
|
228
357
|
/** Sibling ordering key, identical to `topics.sort_key` in the router. */
|
|
229
|
-
sortKey:
|
|
230
|
-
description:
|
|
358
|
+
sortKey: z4.string().min(1).optional(),
|
|
359
|
+
description: z4.string().optional()
|
|
231
360
|
})
|
|
232
361
|
).min(1, "a catalog must ship a table of contents (at least one topic)"),
|
|
233
|
-
router:
|
|
234
|
-
shardTargetChunks:
|
|
235
|
-
shards:
|
|
236
|
-
|
|
237
|
-
id:
|
|
238
|
-
path:
|
|
239
|
-
chunks:
|
|
240
|
-
documents:
|
|
241
|
-
centroids:
|
|
362
|
+
router: z4.object({
|
|
363
|
+
shardTargetChunks: z4.number().int().positive(),
|
|
364
|
+
shards: z4.array(
|
|
365
|
+
z4.object({
|
|
366
|
+
id: z4.number().int().nonnegative(),
|
|
367
|
+
path: z4.string().min(1),
|
|
368
|
+
chunks: z4.number().int().nonnegative(),
|
|
369
|
+
documents: z4.number().int().nonnegative(),
|
|
370
|
+
centroids: z4.number().int().nonnegative(),
|
|
242
371
|
sha256: Sha256HexSchema
|
|
243
372
|
})
|
|
244
373
|
),
|
|
245
|
-
totalCentroids:
|
|
374
|
+
totalCentroids: z4.number().int().nonnegative()
|
|
246
375
|
}),
|
|
247
|
-
counts:
|
|
248
|
-
documents:
|
|
249
|
-
chunks:
|
|
250
|
-
shards:
|
|
376
|
+
counts: z4.object({
|
|
377
|
+
documents: z4.number().int().nonnegative(),
|
|
378
|
+
chunks: z4.number().int().nonnegative(),
|
|
379
|
+
shards: z4.number().int().positive(),
|
|
251
380
|
/** Files under `assets/` (0.6+). */
|
|
252
|
-
assets:
|
|
381
|
+
assets: z4.number().int().nonnegative().optional()
|
|
253
382
|
}),
|
|
254
|
-
files:
|
|
383
|
+
files: z4.array(KnowledgeManifestFileSchema).min(1),
|
|
384
|
+
spatial: KnowledgeSpatialManifestSchema.optional(),
|
|
255
385
|
/** What a reader must implement to open this catalog. */
|
|
256
|
-
requires:
|
|
257
|
-
formatVersion:
|
|
258
|
-
features:
|
|
386
|
+
requires: z4.object({
|
|
387
|
+
formatVersion: z4.enum(GEZK_SUPPORTED_FORMAT_VERSIONS),
|
|
388
|
+
features: z4.array(z4.string()).optional()
|
|
259
389
|
}),
|
|
260
|
-
smokeQueries:
|
|
261
|
-
|
|
262
|
-
query:
|
|
263
|
-
expectedDocumentIds:
|
|
390
|
+
smokeQueries: z4.array(
|
|
391
|
+
z4.object({
|
|
392
|
+
query: z4.string().min(1),
|
|
393
|
+
expectedDocumentIds: z4.array(KnowledgeDocumentIdSchema).min(1)
|
|
264
394
|
})
|
|
265
395
|
).optional(),
|
|
266
396
|
/** Which tool produced the archive — provenance, never a compatibility gate. */
|
|
267
|
-
toolchain:
|
|
268
|
-
name:
|
|
269
|
-
version:
|
|
270
|
-
node:
|
|
271
|
-
sqlite:
|
|
272
|
-
platform:
|
|
273
|
-
modelDigest:
|
|
274
|
-
tokenizerDigest:
|
|
397
|
+
toolchain: z4.object({
|
|
398
|
+
name: z4.string().min(1),
|
|
399
|
+
version: z4.string().min(1),
|
|
400
|
+
node: z4.string().optional(),
|
|
401
|
+
sqlite: z4.string().optional(),
|
|
402
|
+
platform: z4.string().optional(),
|
|
403
|
+
modelDigest: z4.string().optional(),
|
|
404
|
+
tokenizerDigest: z4.string().optional()
|
|
275
405
|
}).optional(),
|
|
276
406
|
signature: KnowledgeSignatureSchema.optional()
|
|
277
407
|
}).superRefine((manifest, ctx) => {
|
|
408
|
+
if (manifest.formatVersion === "0.7" && !manifest.spatial) {
|
|
409
|
+
ctx.addIssue({
|
|
410
|
+
code: "custom",
|
|
411
|
+
path: ["spatial"],
|
|
412
|
+
message: "0.7 requires a spatial summary, including catalogs with zero locations"
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
if (manifest.spatial && (manifest.formatVersion !== "0.7" || manifest.spatial.locatedDocuments > manifest.counts.documents)) {
|
|
416
|
+
ctx.addIssue({
|
|
417
|
+
code: "custom",
|
|
418
|
+
path: ["spatial"],
|
|
419
|
+
message: "spatial requires 0.7 and valid document counts"
|
|
420
|
+
});
|
|
421
|
+
}
|
|
278
422
|
if (GEZK_FORMAT_GENERATIONS[manifest.formatVersion] !== manifest.indexSchemaVersion) {
|
|
279
423
|
ctx.addIssue({
|
|
280
424
|
code: "custom",
|
|
@@ -318,75 +462,82 @@ var KnowledgeCatalogManifestSchema = z3.object({
|
|
|
318
462
|
});
|
|
319
463
|
});
|
|
320
464
|
var KNOWLEDGE_MANIFEST_INDEX_SCHEMA_VERSIONS = GEZK_SUPPORTED_INDEX_SCHEMA_VERSIONS;
|
|
321
|
-
var SourceNoticesSchema =
|
|
322
|
-
sources:
|
|
323
|
-
|
|
324
|
-
name:
|
|
325
|
-
url:
|
|
326
|
-
license:
|
|
327
|
-
licenseUrl:
|
|
465
|
+
var SourceNoticesSchema = z4.object({
|
|
466
|
+
sources: z4.array(
|
|
467
|
+
z4.object({
|
|
468
|
+
name: z4.string().min(1),
|
|
469
|
+
url: z4.string().optional(),
|
|
470
|
+
license: z4.string().min(1),
|
|
471
|
+
licenseUrl: z4.string().optional(),
|
|
328
472
|
/** Snapshot or revision the content was taken from. */
|
|
329
|
-
snapshot:
|
|
473
|
+
snapshot: z4.string().optional(),
|
|
330
474
|
/** Free-form notice text required by the source's license. */
|
|
331
|
-
notice:
|
|
475
|
+
notice: z4.string().optional()
|
|
332
476
|
})
|
|
333
477
|
).min(1)
|
|
334
478
|
});
|
|
335
479
|
|
|
336
480
|
// src/schemas/document.ts
|
|
337
|
-
import { z as
|
|
338
|
-
var KnowledgeOrdinalSchema =
|
|
339
|
-
var KnowledgeDocumentMetaSchema =
|
|
340
|
-
var
|
|
481
|
+
import { z as z5 } from "zod";
|
|
482
|
+
var KnowledgeOrdinalSchema = z5.number().int().min(-2147483648).max(2147483647);
|
|
483
|
+
var KnowledgeDocumentMetaSchema = z5.record(z5.string(), z5.unknown());
|
|
484
|
+
var KnowledgeTocReferenceSchema = z5.object({
|
|
485
|
+
topicPath: z5.array(KnowledgeIdSchema).min(1),
|
|
486
|
+
ordinal: KnowledgeOrdinalSchema.optional()
|
|
487
|
+
}).strict();
|
|
488
|
+
var CatalogDocumentSchema = z5.object({
|
|
341
489
|
id: KnowledgeDocumentIdSchema,
|
|
342
|
-
title:
|
|
343
|
-
slug:
|
|
344
|
-
summary:
|
|
345
|
-
language:
|
|
490
|
+
title: z5.string().min(1),
|
|
491
|
+
slug: z5.string().min(1),
|
|
492
|
+
summary: z5.string().optional(),
|
|
493
|
+
language: z5.string().min(2),
|
|
346
494
|
/**
|
|
347
495
|
* Root→leaf topic id path. Every segment must be a declared topic and each
|
|
348
496
|
* must be the parent of the next; the document is filed at the last one.
|
|
349
497
|
*/
|
|
350
|
-
topicPath:
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
498
|
+
topicPath: z5.array(KnowledgeIdSchema).min(1),
|
|
499
|
+
/** Additional root-to-leaf paths. Each leaf may list this document only once. */
|
|
500
|
+
tocReferences: z5.array(KnowledgeTocReferenceSchema).optional(),
|
|
501
|
+
markdown: z5.string(),
|
|
502
|
+
sourceUrl: z5.string().optional(),
|
|
503
|
+
sourceRevision: z5.string().optional(),
|
|
504
|
+
sourceUpdatedAt: z5.string().optional(),
|
|
505
|
+
attribution: z5.record(z5.string(), z5.string()).optional(),
|
|
506
|
+
aliases: z5.array(z5.string()).optional(),
|
|
357
507
|
/** Explicit position among the documents of its topic in a listing. */
|
|
358
508
|
ordinal: KnowledgeOrdinalSchema.optional(),
|
|
359
|
-
meta: KnowledgeDocumentMetaSchema.optional()
|
|
509
|
+
meta: KnowledgeDocumentMetaSchema.optional(),
|
|
510
|
+
locations: KnowledgeLocationsSchema.optional()
|
|
360
511
|
});
|
|
361
512
|
|
|
362
513
|
// src/schemas/registry.ts
|
|
363
|
-
import { z as
|
|
364
|
-
var KnowledgeRegistryEntrySchema =
|
|
514
|
+
import { z as z6 } from "zod";
|
|
515
|
+
var KnowledgeRegistryEntrySchema = z6.object({
|
|
365
516
|
catalogId: KnowledgeIdSchema,
|
|
366
|
-
version:
|
|
367
|
-
name:
|
|
368
|
-
description:
|
|
369
|
-
language:
|
|
370
|
-
documents:
|
|
517
|
+
version: z6.string().min(1),
|
|
518
|
+
name: z6.string().min(1),
|
|
519
|
+
description: z6.string().optional(),
|
|
520
|
+
language: z6.string().min(2),
|
|
521
|
+
documents: z6.number().int().nonnegative(),
|
|
371
522
|
/** Size of the `.gezk` archive itself (download accounting/preflight). */
|
|
372
|
-
archiveBytes:
|
|
523
|
+
archiveBytes: z6.number().int().nonnegative(),
|
|
373
524
|
/** sha256 of the `.gezk` archive — the ref's contentDigest after install. */
|
|
374
525
|
contentDigest: Sha256HexSchema,
|
|
375
526
|
/** Absolute download URL. Uploaded before the registry that names it. */
|
|
376
|
-
url:
|
|
377
|
-
license:
|
|
378
|
-
sourceSnapshot:
|
|
527
|
+
url: z6.string().url(),
|
|
528
|
+
license: z6.object({ name: z6.string().min(1), attributionRequired: z6.boolean() }),
|
|
529
|
+
sourceSnapshot: z6.object({ name: z6.string(), date: z6.string(), taxonomyVersion: z6.string().optional() }).optional()
|
|
379
530
|
});
|
|
380
|
-
var KnowledgeRegistryIndexSchema =
|
|
381
|
-
kind:
|
|
382
|
-
formatVersion:
|
|
383
|
-
publisher:
|
|
531
|
+
var KnowledgeRegistryIndexSchema = z6.object({
|
|
532
|
+
kind: z6.literal(GEZK_REGISTRY_KIND),
|
|
533
|
+
formatVersion: z6.enum(GEZK_SUPPORTED_FORMAT_VERSIONS),
|
|
534
|
+
publisher: z6.object({
|
|
384
535
|
id: KnowledgeIdSchema,
|
|
385
|
-
name:
|
|
386
|
-
url:
|
|
536
|
+
name: z6.string().min(1),
|
|
537
|
+
url: z6.string().optional()
|
|
387
538
|
}),
|
|
388
|
-
generatedAt:
|
|
389
|
-
catalogs:
|
|
539
|
+
generatedAt: z6.string(),
|
|
540
|
+
catalogs: z6.array(KnowledgeRegistryEntrySchema),
|
|
390
541
|
signature: KnowledgeSignatureSchema.optional()
|
|
391
542
|
});
|
|
392
543
|
|
|
@@ -470,6 +621,30 @@ CREATE TABLE documents(
|
|
|
470
621
|
CREATE INDEX documents_topic ON documents(topic_id, ordinal, slug);
|
|
471
622
|
CREATE INDEX documents_shard ON documents(shard_id);
|
|
472
623
|
|
|
624
|
+
CREATE TABLE document_locations(
|
|
625
|
+
document_id TEXT NOT NULL REFERENCES documents(id),
|
|
626
|
+
location_id TEXT NOT NULL,
|
|
627
|
+
latitude REAL NOT NULL CHECK (latitude BETWEEN -90 AND 90),
|
|
628
|
+
longitude REAL NOT NULL CHECK (longitude >= -180 AND longitude < 180),
|
|
629
|
+
role TEXT NOT NULL CHECK (role IN ('subject','associated')),
|
|
630
|
+
provenance_json TEXT,
|
|
631
|
+
PRIMARY KEY (document_id, location_id)
|
|
632
|
+
) WITHOUT ROWID;
|
|
633
|
+
CREATE INDEX document_locations_latitude ON document_locations(latitude, longitude, document_id);
|
|
634
|
+
CREATE INDEX document_locations_longitude ON document_locations(longitude, latitude, document_id);
|
|
635
|
+
|
|
636
|
+
-- Includes the primary placement in documents.topic_id/ordinal as well as
|
|
637
|
+
-- shared TOC references. Bodies, chunks and vectors remain keyed by document id.
|
|
638
|
+
CREATE TABLE topic_documents(
|
|
639
|
+
topic_id TEXT NOT NULL REFERENCES topics(id),
|
|
640
|
+
document_id TEXT NOT NULL REFERENCES documents(id),
|
|
641
|
+
ordinal INTEGER CHECK (ordinal IS NULL OR
|
|
642
|
+
(typeof(ordinal) = 'integer' AND ordinal BETWEEN -2147483648 AND 2147483647)),
|
|
643
|
+
PRIMARY KEY (topic_id, document_id)
|
|
644
|
+
) WITHOUT ROWID;
|
|
645
|
+
CREATE INDEX topic_documents_document ON topic_documents(document_id);
|
|
646
|
+
CREATE INDEX topic_documents_order ON topic_documents(topic_id, ordinal, document_id);
|
|
647
|
+
|
|
473
648
|
CREATE TABLE aliases(alias TEXT NOT NULL, document_id TEXT NOT NULL,
|
|
474
649
|
PRIMARY KEY (alias, document_id)) WITHOUT ROWID;
|
|
475
650
|
|
|
@@ -531,7 +706,7 @@ CREATE TABLE chunk_vectors_int8(
|
|
|
531
706
|
`;
|
|
532
707
|
|
|
533
708
|
// src/format/assets.ts
|
|
534
|
-
import { z as
|
|
709
|
+
import { z as z7 } from "zod";
|
|
535
710
|
var ASSETS_PREFIX = "assets/";
|
|
536
711
|
var KNOWLEDGE_ASSET_TYPES = {
|
|
537
712
|
png: "image/png",
|
|
@@ -546,7 +721,7 @@ var MAX_KNOWLEDGE_ASSETS_TOTAL_BYTES = 256 * 1024 * 1024;
|
|
|
546
721
|
var MAX_KNOWLEDGE_ASSET_COUNT = 8192;
|
|
547
722
|
var MAX_KNOWLEDGE_ASSET_PATH_LENGTH = 512;
|
|
548
723
|
var KNOWLEDGE_ASSET_PATH_PATTERN = /^assets\/(?:[A-Za-z0-9_-][A-Za-z0-9._-]{0,127}\/){0,15}[A-Za-z0-9_-][A-Za-z0-9._-]{0,127}\.(?:png|jpe?g|gif|webp|svg)$/i;
|
|
549
|
-
var KnowledgeAssetPathSchema =
|
|
724
|
+
var KnowledgeAssetPathSchema = z7.string().max(MAX_KNOWLEDGE_ASSET_PATH_LENGTH).regex(KNOWLEDGE_ASSET_PATH_PATTERN, "not a valid asset path");
|
|
550
725
|
function isKnowledgeAssetPath(path) {
|
|
551
726
|
return path.length <= MAX_KNOWLEDGE_ASSET_PATH_LENGTH && KNOWLEDGE_ASSET_PATH_PATTERN.test(path);
|
|
552
727
|
}
|
|
@@ -784,6 +959,7 @@ export {
|
|
|
784
959
|
DEFAULT_EMBEDDING_ONNX_FILE,
|
|
785
960
|
DEFAULT_EMBEDDING_TOKENIZER_FILE,
|
|
786
961
|
GEZK_APPLICATION_ID,
|
|
962
|
+
GEZK_EARTH_RADIUS_METERS,
|
|
787
963
|
GEZK_FORMAT_GENERATIONS,
|
|
788
964
|
GEZK_FORMAT_VERSION,
|
|
789
965
|
GEZK_INDEX_SCHEMA_VERSION,
|
|
@@ -798,6 +974,7 @@ export {
|
|
|
798
974
|
KNOWLEDGE_MANIFEST_INDEX_SCHEMA_VERSIONS,
|
|
799
975
|
KNOWLEDGE_VERSION_PATTERN,
|
|
800
976
|
KnowledgeAssetPathSchema,
|
|
977
|
+
KnowledgeBoundsSchema,
|
|
801
978
|
KnowledgeCatalogManifestSchema,
|
|
802
979
|
KnowledgeChunkUidSchema,
|
|
803
980
|
KnowledgeChunkingProfileSchema,
|
|
@@ -805,15 +982,21 @@ export {
|
|
|
805
982
|
KnowledgeDocumentMetaSchema,
|
|
806
983
|
KnowledgeEmbeddingProfileSchema,
|
|
807
984
|
KnowledgeIdSchema,
|
|
985
|
+
KnowledgeLocationSchema,
|
|
986
|
+
KnowledgeLocationsSchema,
|
|
808
987
|
KnowledgeManifestFileSchema,
|
|
809
988
|
KnowledgeOrdinalSchema,
|
|
989
|
+
KnowledgeRadiusSchema,
|
|
810
990
|
KnowledgeRegistryEntrySchema,
|
|
811
991
|
KnowledgeRegistryIndexSchema,
|
|
812
992
|
KnowledgeSignatureSchema,
|
|
993
|
+
KnowledgeSpatialManifestSchema,
|
|
994
|
+
KnowledgeTocReferenceSchema,
|
|
813
995
|
KnowledgeVectorEncodingSchema,
|
|
814
996
|
KnowledgeVersionSchema,
|
|
815
997
|
LICENSE_NOTICE_PATH,
|
|
816
998
|
MANIFEST_PATH,
|
|
999
|
+
MAX_DOCUMENT_LOCATIONS,
|
|
817
1000
|
MAX_KNOWLEDGE_ASSETS_TOTAL_BYTES,
|
|
818
1001
|
MAX_KNOWLEDGE_ASSET_BYTES,
|
|
819
1002
|
MAX_KNOWLEDGE_ASSET_COUNT,
|
|
@@ -845,13 +1028,18 @@ export {
|
|
|
845
1028
|
isSupportedFormatVersion,
|
|
846
1029
|
isSupportedIndexSchemaVersion,
|
|
847
1030
|
l2Normalize,
|
|
1031
|
+
locationDistanceMeters,
|
|
1032
|
+
locationInBounds,
|
|
1033
|
+
normalizeLongitude,
|
|
848
1034
|
parseKnowledgeUri,
|
|
849
1035
|
quantizeBinary,
|
|
850
1036
|
quantizeBinaryForProfile,
|
|
851
1037
|
quantizeInt8,
|
|
1038
|
+
radiusBounds,
|
|
852
1039
|
rerankScore,
|
|
853
1040
|
sameVectorSpace,
|
|
854
1041
|
sniffAssetType,
|
|
1042
|
+
spatialManifest,
|
|
855
1043
|
svgInertnessProblem,
|
|
856
1044
|
topicSortKeyForOrder
|
|
857
1045
|
};
|
package/dist/node.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { KnowledgeCatalogManifest, KnowledgeRegistryIndex } from './index.js';
|
|
2
|
-
export { ASSETS_PREFIX, ArtifactDigestSchema, BODY_CODEC_MIN_BYTES, CatalogDocument, CatalogDocumentSchema, DEFAULT_EMBEDDING_ONNX_FILE, DEFAULT_EMBEDDING_TOKENIZER_FILE, GEZK_APPLICATION_ID, GEZK_FORMAT_GENERATIONS, GEZK_FORMAT_VERSION, GEZK_INDEX_SCHEMA_VERSION, GEZK_MANIFEST_KIND, GEZK_MIME_TYPE, GEZK_REGISTRY_KIND, GEZK_SUPPORTED_FORMAT_VERSIONS, GEZK_SUPPORTED_INDEX_SCHEMA_VERSIONS, GezkFormatVersion, GezkIndexSchemaVersion, KNOWLEDGE_ASSET_PATH_PATTERN, KNOWLEDGE_ASSET_TYPES, KNOWLEDGE_ID_PATTERN, KNOWLEDGE_MANIFEST_INDEX_SCHEMA_VERSIONS, KNOWLEDGE_VERSION_PATTERN, KnowledgeAssetExtension, KnowledgeAssetKind, KnowledgeAssetPathSchema, KnowledgeCatalogManifestSchema, KnowledgeChunkUidSchema, KnowledgeChunkingProfile, KnowledgeChunkingProfileSchema, KnowledgeDocumentIdSchema, KnowledgeDocumentMeta, KnowledgeDocumentMetaSchema, KnowledgeEmbeddingProfile, KnowledgeEmbeddingProfileSchema, KnowledgeIdSchema, KnowledgeManifestFileSchema, KnowledgeOrdinalSchema, KnowledgeRegistryEntry, KnowledgeRegistryEntrySchema, KnowledgeRegistryIndexSchema, KnowledgeSignature, KnowledgeSignatureSchema, KnowledgeUri, KnowledgeVectorEncoding, KnowledgeVectorEncodingSchema, KnowledgeVersionSchema, LICENSE_NOTICE_PATH, MANIFEST_PATH, MAX_KNOWLEDGE_ASSETS_TOTAL_BYTES, MAX_KNOWLEDGE_ASSET_BYTES, MAX_KNOWLEDGE_ASSET_COUNT, MAX_KNOWLEDGE_ASSET_PATH_LENGTH, MAX_KNOWLEDGE_DOCUMENT_BYTES, MAX_KNOWLEDGE_DOCUMENT_META_BYTES, MAX_KNOWLEDGE_TOPIC_DEPTH, MIMETYPE_PATH, README_PATH, ROUTER_DB_PATH, ROUTER_DDL, RepoRelativePathSchema, SHARD_DDL, SOURCE_NOTICES_PATH, Sha256HexSchema, SourceNotices, SourceNoticesSchema, ZIP_FIXED_MTIME, assetContentType, assetExtension, assetKindForExtension, canonicalizeJson, centerVector, documentSlug, embeddingProfileArtifacts, embeddingProfileCenter, embeddingProfileCenterProblem, formatKnowledgeUri, isKnowledgeAssetPath, isSupportedFormatVersion, isSupportedIndexSchemaVersion, l2Normalize, parseKnowledgeUri, quantizeBinary, quantizeBinaryForProfile, quantizeInt8, rerankScore, sameVectorSpace, sniffAssetType, svgInertnessProblem, topicSortKeyForOrder } from './index.js';
|
|
2
|
+
export { ASSETS_PREFIX, ArtifactDigestSchema, BODY_CODEC_MIN_BYTES, CatalogDocument, CatalogDocumentSchema, DEFAULT_EMBEDDING_ONNX_FILE, DEFAULT_EMBEDDING_TOKENIZER_FILE, GEZK_APPLICATION_ID, GEZK_EARTH_RADIUS_METERS, GEZK_FORMAT_GENERATIONS, GEZK_FORMAT_VERSION, GEZK_INDEX_SCHEMA_VERSION, GEZK_MANIFEST_KIND, GEZK_MIME_TYPE, GEZK_REGISTRY_KIND, GEZK_SUPPORTED_FORMAT_VERSIONS, GEZK_SUPPORTED_INDEX_SCHEMA_VERSIONS, GezkFormatVersion, GezkIndexSchemaVersion, KNOWLEDGE_ASSET_PATH_PATTERN, KNOWLEDGE_ASSET_TYPES, KNOWLEDGE_ID_PATTERN, KNOWLEDGE_MANIFEST_INDEX_SCHEMA_VERSIONS, KNOWLEDGE_VERSION_PATTERN, KnowledgeAssetExtension, KnowledgeAssetKind, KnowledgeAssetPathSchema, KnowledgeBounds, KnowledgeBoundsSchema, KnowledgeCatalogManifestSchema, KnowledgeChunkUidSchema, KnowledgeChunkingProfile, KnowledgeChunkingProfileSchema, KnowledgeDocumentIdSchema, KnowledgeDocumentMeta, KnowledgeDocumentMetaSchema, KnowledgeEmbeddingProfile, KnowledgeEmbeddingProfileSchema, KnowledgeIdSchema, KnowledgeLocation, KnowledgeLocationSchema, KnowledgeLocationsSchema, KnowledgeManifestFileSchema, KnowledgeOrdinalSchema, KnowledgeRadius, KnowledgeRadiusSchema, KnowledgeRegistryEntry, KnowledgeRegistryEntrySchema, KnowledgeRegistryIndexSchema, KnowledgeSignature, KnowledgeSignatureSchema, KnowledgeSpatialManifest, KnowledgeSpatialManifestSchema, KnowledgeTocReference, KnowledgeTocReferenceSchema, KnowledgeUri, KnowledgeVectorEncoding, KnowledgeVectorEncodingSchema, KnowledgeVersionSchema, LICENSE_NOTICE_PATH, MANIFEST_PATH, MAX_DOCUMENT_LOCATIONS, MAX_KNOWLEDGE_ASSETS_TOTAL_BYTES, MAX_KNOWLEDGE_ASSET_BYTES, MAX_KNOWLEDGE_ASSET_COUNT, MAX_KNOWLEDGE_ASSET_PATH_LENGTH, MAX_KNOWLEDGE_DOCUMENT_BYTES, MAX_KNOWLEDGE_DOCUMENT_META_BYTES, MAX_KNOWLEDGE_TOPIC_DEPTH, MIMETYPE_PATH, README_PATH, ROUTER_DB_PATH, ROUTER_DDL, RepoRelativePathSchema, SHARD_DDL, SOURCE_NOTICES_PATH, Sha256HexSchema, SourceNotices, SourceNoticesSchema, ZIP_FIXED_MTIME, assetContentType, assetExtension, assetKindForExtension, canonicalizeJson, centerVector, documentSlug, embeddingProfileArtifacts, embeddingProfileCenter, embeddingProfileCenterProblem, formatKnowledgeUri, isKnowledgeAssetPath, isSupportedFormatVersion, isSupportedIndexSchemaVersion, l2Normalize, locationDistanceMeters, locationInBounds, normalizeLongitude, parseKnowledgeUri, quantizeBinary, quantizeBinaryForProfile, quantizeInt8, radiusBounds, rerankScore, sameVectorSpace, sniffAssetType, spatialManifest, svgInertnessProblem, topicSortKeyForOrder } from './index.js';
|
|
3
3
|
import 'zod';
|
|
4
4
|
|
|
5
5
|
/**
|