@svashevchenko/ez-know 0.1.0 → 0.2.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 +20 -18
- package/dist/cli.js +1038 -746
- package/dist/cli.js.map +4 -4
- package/dist/rest/server.js +520 -15
- package/dist/rest/server.js.map +4 -4
- package/dist/server.js +584 -292
- package/dist/server.js.map +4 -4
- package/package.json +1 -1
package/dist/rest/server.js
CHANGED
|
@@ -529,13 +529,131 @@ var KNOWLEDGE_EXTRACTION_TYPE_LOOKUP = new Map(
|
|
|
529
529
|
...definition.aliases.map((alias) => [alias, definition])
|
|
530
530
|
])
|
|
531
531
|
);
|
|
532
|
+
function listKnowledgeExtractionTypes() {
|
|
533
|
+
return KNOWLEDGE_EXTRACTION_TYPES.slice();
|
|
534
|
+
}
|
|
535
|
+
function getKnowledgeExtractionTypeDefinition(type) {
|
|
536
|
+
const normalized = type.trim().toLowerCase().replace(/-/g, "_");
|
|
537
|
+
const exactMatch = KNOWLEDGE_EXTRACTION_TYPE_LOOKUP.get(normalized);
|
|
538
|
+
if (exactMatch) {
|
|
539
|
+
return exactMatch;
|
|
540
|
+
}
|
|
541
|
+
return KNOWLEDGE_EXTRACTION_TYPE_LOOKUP.get(type.trim().toLowerCase());
|
|
542
|
+
}
|
|
543
|
+
function requireKnowledgeExtractionTypeDefinition(type) {
|
|
544
|
+
const definition = getKnowledgeExtractionTypeDefinition(type);
|
|
545
|
+
if (!definition) {
|
|
546
|
+
throw new Error(
|
|
547
|
+
`Unsupported extraction type "${type}". Supported types: ${KNOWLEDGE_EXTRACTION_TYPES.map(
|
|
548
|
+
(entry) => entry.collection
|
|
549
|
+
).join(", ")}`
|
|
550
|
+
);
|
|
551
|
+
}
|
|
552
|
+
return definition;
|
|
553
|
+
}
|
|
554
|
+
function buildKnowledgeExtractionSchemaUri(type) {
|
|
555
|
+
return `ez-know://extraction/schema/${requireKnowledgeExtractionTypeDefinition(type).collection}`;
|
|
556
|
+
}
|
|
557
|
+
function buildKnowledgeExtractionGuideUri(type) {
|
|
558
|
+
return `ez-know://extraction/guide/${requireKnowledgeExtractionTypeDefinition(type).collection}`;
|
|
559
|
+
}
|
|
532
560
|
|
|
533
561
|
// packages/core/src/knowledge/extraction-resources.ts
|
|
562
|
+
import { readFile } from "node:fs/promises";
|
|
534
563
|
import { z as z2 } from "zod/v4";
|
|
564
|
+
var KNOWLEDGE_EXTRACTION_TYPES_RESOURCE_URI = "ez-know://extraction/types";
|
|
565
|
+
var KNOWLEDGE_EXTRACTION_SCHEMA_RESOURCE_URI = "ez-know://extraction/schema/{type}";
|
|
566
|
+
var KNOWLEDGE_EXTRACTION_GUIDE_RESOURCE_URI = "ez-know://extraction/guide/{type}";
|
|
567
|
+
function createKnowledgeExtractionTypeResource(definition) {
|
|
568
|
+
return {
|
|
569
|
+
collection: definition.collection,
|
|
570
|
+
title: definition.title,
|
|
571
|
+
aliases: definition.aliases.slice(),
|
|
572
|
+
storageFile: definition.storageFile,
|
|
573
|
+
idConvention: { ...definition.idConvention },
|
|
574
|
+
schemaUri: buildKnowledgeExtractionSchemaUri(definition.collection),
|
|
575
|
+
guideUri: buildKnowledgeExtractionGuideUri(definition.collection)
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
function buildKnowledgeExtractionTypeIndexDocument() {
|
|
579
|
+
const supportedTypes = listKnowledgeExtractionTypes().map(
|
|
580
|
+
createKnowledgeExtractionTypeResource
|
|
581
|
+
);
|
|
582
|
+
return {
|
|
583
|
+
resource: {
|
|
584
|
+
uri: KNOWLEDGE_EXTRACTION_TYPES_RESOURCE_URI,
|
|
585
|
+
title: "Knowledge Extraction Types",
|
|
586
|
+
description: "Canonical registry of knowledge types supported by the extraction workflow."
|
|
587
|
+
},
|
|
588
|
+
source: {
|
|
589
|
+
kind: "registry",
|
|
590
|
+
count: supportedTypes.length
|
|
591
|
+
},
|
|
592
|
+
supportedTypes
|
|
593
|
+
};
|
|
594
|
+
}
|
|
595
|
+
function buildKnowledgeExtractionSchemaDocument(type) {
|
|
596
|
+
const definition = requireKnowledgeExtractionTypeDefinition(type);
|
|
597
|
+
const resource = createKnowledgeExtractionTypeResource(definition);
|
|
598
|
+
return {
|
|
599
|
+
resource: {
|
|
600
|
+
uri: resource.schemaUri,
|
|
601
|
+
title: `${definition.title} Extraction Schema`,
|
|
602
|
+
description: "Runtime JSON Schema view of the canonical knowledge object model."
|
|
603
|
+
},
|
|
604
|
+
source: {
|
|
605
|
+
kind: "runtime-zod",
|
|
606
|
+
collection: definition.collection,
|
|
607
|
+
schemaName: definition.schemaName,
|
|
608
|
+
storageFile: definition.storageFile,
|
|
609
|
+
guideUri: resource.guideUri
|
|
610
|
+
},
|
|
611
|
+
type: resource,
|
|
612
|
+
schema: z2.toJSONSchema(definition.schema)
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
async function readKnowledgeExtractionGuideMarkdown(type) {
|
|
616
|
+
const definition = requireKnowledgeExtractionTypeDefinition(type);
|
|
617
|
+
const guideFileName = definition.guideFilePath.split("/").pop();
|
|
618
|
+
if (!guideFileName) {
|
|
619
|
+
throw new Error(
|
|
620
|
+
`Invalid guide file path for extraction type "${definition.collection}".`
|
|
621
|
+
);
|
|
622
|
+
}
|
|
623
|
+
const guideUrl = new URL(`./guides/${guideFileName}`, import.meta.url);
|
|
624
|
+
const markdown = await readFile(guideUrl, "utf8");
|
|
625
|
+
return {
|
|
626
|
+
definition,
|
|
627
|
+
markdown
|
|
628
|
+
};
|
|
629
|
+
}
|
|
630
|
+
async function buildKnowledgeExtractionGuideDocument(type) {
|
|
631
|
+
const definition = requireKnowledgeExtractionTypeDefinition(type);
|
|
632
|
+
const resource = createKnowledgeExtractionTypeResource(definition);
|
|
633
|
+
const { markdown } = await readKnowledgeExtractionGuideMarkdown(type);
|
|
634
|
+
return {
|
|
635
|
+
resource: {
|
|
636
|
+
uri: resource.guideUri,
|
|
637
|
+
title: `${definition.title} Extraction Guide`,
|
|
638
|
+
description: "Checked-in Markdown guidance for extracting this knowledge type."
|
|
639
|
+
},
|
|
640
|
+
source: {
|
|
641
|
+
kind: "checked-in-markdown",
|
|
642
|
+
filePath: definition.guideFilePath
|
|
643
|
+
},
|
|
644
|
+
type: resource,
|
|
645
|
+
markdown
|
|
646
|
+
};
|
|
647
|
+
}
|
|
648
|
+
function listKnowledgeExtractionResourceTypes() {
|
|
649
|
+
return listKnowledgeExtractionTypes().map(
|
|
650
|
+
createKnowledgeExtractionTypeResource
|
|
651
|
+
);
|
|
652
|
+
}
|
|
535
653
|
|
|
536
654
|
// packages/core/src/knowledge/loader.ts
|
|
537
655
|
import { existsSync } from "node:fs";
|
|
538
|
-
import { readFile } from "node:fs/promises";
|
|
656
|
+
import { readFile as readFile2 } from "node:fs/promises";
|
|
539
657
|
import { basename, join } from "node:path";
|
|
540
658
|
import { z as z3 } from "zod/v4";
|
|
541
659
|
|
|
@@ -594,7 +712,7 @@ function readDiagnostic(kind, path, message, id) {
|
|
|
594
712
|
async function readCanonicalFile(filePath, schema) {
|
|
595
713
|
let raw;
|
|
596
714
|
try {
|
|
597
|
-
raw = await
|
|
715
|
+
raw = await readFile2(filePath, "utf8");
|
|
598
716
|
} catch (error) {
|
|
599
717
|
throw new KnowledgeStoreLoadError(
|
|
600
718
|
`Failed to read canonical knowledge file: ${filePath}`,
|
|
@@ -918,7 +1036,7 @@ async function loadKnowledgeStoreFromEnv(envValue, cwd = process.cwd()) {
|
|
|
918
1036
|
|
|
919
1037
|
// packages/core/src/knowledge/patch/storage.ts
|
|
920
1038
|
import { existsSync as existsSync2 } from "node:fs";
|
|
921
|
-
import { mkdir, readFile as
|
|
1039
|
+
import { mkdir, readFile as readFile3, readdir, writeFile } from "node:fs/promises";
|
|
922
1040
|
import { isAbsolute, join as join3, normalize, resolve as resolve4, sep } from "node:path";
|
|
923
1041
|
import "zod/v4";
|
|
924
1042
|
|
|
@@ -1118,7 +1236,7 @@ function buildDiagnostic(diagnostic) {
|
|
|
1118
1236
|
|
|
1119
1237
|
// packages/core/src/knowledge/patch/storage.ts
|
|
1120
1238
|
async function readJsonFile(filePath, schema) {
|
|
1121
|
-
const raw = await
|
|
1239
|
+
const raw = await readFile3(filePath, "utf8");
|
|
1122
1240
|
const parsed = JSON.parse(raw);
|
|
1123
1241
|
return schema.parse(parsed);
|
|
1124
1242
|
}
|
|
@@ -2067,6 +2185,404 @@ var knowledgeGraphSchema = new GraphQLSchema({
|
|
|
2067
2185
|
query: queryType
|
|
2068
2186
|
});
|
|
2069
2187
|
|
|
2188
|
+
// packages/core/src/knowledge/schema-discovery.ts
|
|
2189
|
+
import {
|
|
2190
|
+
isAbstractType,
|
|
2191
|
+
isCompositeType,
|
|
2192
|
+
isListType,
|
|
2193
|
+
isNonNullType,
|
|
2194
|
+
isObjectType,
|
|
2195
|
+
isScalarType,
|
|
2196
|
+
isUnionType
|
|
2197
|
+
} from "graphql";
|
|
2198
|
+
var KNOWLEDGE_SCHEMA_RESOURCE_URI = "ez-know://schema";
|
|
2199
|
+
var KNOWLEDGE_SCHEMA_LOOKUP_URI = "ez-know://lookup/{target}";
|
|
2200
|
+
function unwrapType(type) {
|
|
2201
|
+
if (isNonNullType(type) || isListType(type)) {
|
|
2202
|
+
return unwrapType(type.ofType);
|
|
2203
|
+
}
|
|
2204
|
+
if (isObjectType(type) || isScalarType(type) || isUnionType(type) || isAbstractType(type)) {
|
|
2205
|
+
return { name: type.name, composite: type };
|
|
2206
|
+
}
|
|
2207
|
+
return { name: "Unknown", composite: type };
|
|
2208
|
+
}
|
|
2209
|
+
function describeType(type) {
|
|
2210
|
+
if (isNonNullType(type)) {
|
|
2211
|
+
return `${describeType(type.ofType)}!`;
|
|
2212
|
+
}
|
|
2213
|
+
if (isListType(type)) {
|
|
2214
|
+
return `[${describeType(type.ofType)}]`;
|
|
2215
|
+
}
|
|
2216
|
+
if (isObjectType(type) || isScalarType(type) || isUnionType(type)) {
|
|
2217
|
+
return type.name;
|
|
2218
|
+
}
|
|
2219
|
+
if (isAbstractType(type)) {
|
|
2220
|
+
return type.name;
|
|
2221
|
+
}
|
|
2222
|
+
return "Unknown";
|
|
2223
|
+
}
|
|
2224
|
+
function formatDefaultValue(value) {
|
|
2225
|
+
if (value === void 0 || value === null) {
|
|
2226
|
+
return null;
|
|
2227
|
+
}
|
|
2228
|
+
return JSON.stringify(value) ?? String(value);
|
|
2229
|
+
}
|
|
2230
|
+
function summarizeField(field) {
|
|
2231
|
+
const traversedType = unwrapType(field.type).composite;
|
|
2232
|
+
const traversesTo = isCompositeType(traversedType) && !isScalarType(traversedType) ? traversedType.name : null;
|
|
2233
|
+
return {
|
|
2234
|
+
name: field.name,
|
|
2235
|
+
type: describeType(field.type),
|
|
2236
|
+
description: field.description ?? null,
|
|
2237
|
+
arguments: field.args?.map((argument) => ({
|
|
2238
|
+
name: argument.name,
|
|
2239
|
+
type: describeType(argument.type),
|
|
2240
|
+
description: argument.description ?? null,
|
|
2241
|
+
defaultValue: formatDefaultValue(argument.defaultValue)
|
|
2242
|
+
})) ?? [],
|
|
2243
|
+
traversesTo
|
|
2244
|
+
};
|
|
2245
|
+
}
|
|
2246
|
+
function summarizeObjectType(type) {
|
|
2247
|
+
const fields = Object.values(type.getFields()).map(summarizeField);
|
|
2248
|
+
return {
|
|
2249
|
+
name: type.name,
|
|
2250
|
+
description: type.description ?? null,
|
|
2251
|
+
fields,
|
|
2252
|
+
traversalFields: fields.filter((field) => field.traversesTo !== null).map((field) => field.name)
|
|
2253
|
+
};
|
|
2254
|
+
}
|
|
2255
|
+
function getObjectTypes(schema) {
|
|
2256
|
+
return Object.values(schema.getTypeMap()).filter((type) => isObjectType(type)).filter((type) => !type.name.startsWith("__")).filter((type) => type.name !== schema.getQueryType()?.name);
|
|
2257
|
+
}
|
|
2258
|
+
function buildKnowledgeSchemaDiscoveryDocument(schema) {
|
|
2259
|
+
const queryType2 = schema.getQueryType();
|
|
2260
|
+
if (!queryType2) {
|
|
2261
|
+
throw new Error("Knowledge GraphQL schema has no root query type.");
|
|
2262
|
+
}
|
|
2263
|
+
return {
|
|
2264
|
+
resource: {
|
|
2265
|
+
uri: KNOWLEDGE_SCHEMA_RESOURCE_URI,
|
|
2266
|
+
title: "Knowledge GraphQL Schema",
|
|
2267
|
+
description: "Canonical discovery view of the runtime knowledge GraphQL schema."
|
|
2268
|
+
},
|
|
2269
|
+
source: {
|
|
2270
|
+
kind: "runtime-schema",
|
|
2271
|
+
queryType: queryType2.name
|
|
2272
|
+
},
|
|
2273
|
+
rootQuery: summarizeObjectType(queryType2),
|
|
2274
|
+
objectTypes: getObjectTypes(schema).map(summarizeObjectType)
|
|
2275
|
+
};
|
|
2276
|
+
}
|
|
2277
|
+
function getLookupMetadata(schema, target) {
|
|
2278
|
+
const queryType2 = schema.getQueryType();
|
|
2279
|
+
if (!queryType2) {
|
|
2280
|
+
throw new Error("Knowledge GraphQL schema has no root query type.");
|
|
2281
|
+
}
|
|
2282
|
+
if (target === queryType2.name) {
|
|
2283
|
+
return {
|
|
2284
|
+
resource: {
|
|
2285
|
+
uri: `ez-know://lookup/${target}`,
|
|
2286
|
+
title: `Knowledge schema lookup: ${target}`,
|
|
2287
|
+
description: "Focused lookup of the root query fields and their arguments."
|
|
2288
|
+
},
|
|
2289
|
+
source: {
|
|
2290
|
+
kind: "runtime-schema",
|
|
2291
|
+
queryType: queryType2.name
|
|
2292
|
+
},
|
|
2293
|
+
lookup: {
|
|
2294
|
+
target: queryType2.name,
|
|
2295
|
+
kind: "root-query"
|
|
2296
|
+
},
|
|
2297
|
+
rootQuery: summarizeObjectType(queryType2)
|
|
2298
|
+
};
|
|
2299
|
+
}
|
|
2300
|
+
const rootField = queryType2.getFields()[target];
|
|
2301
|
+
if (rootField) {
|
|
2302
|
+
return {
|
|
2303
|
+
resource: {
|
|
2304
|
+
uri: `ez-know://lookup/${target}`,
|
|
2305
|
+
title: `Knowledge schema lookup: ${target}`,
|
|
2306
|
+
description: "Focused lookup of a single root query field and its arguments."
|
|
2307
|
+
},
|
|
2308
|
+
source: {
|
|
2309
|
+
kind: "runtime-schema",
|
|
2310
|
+
queryType: queryType2.name
|
|
2311
|
+
},
|
|
2312
|
+
lookup: {
|
|
2313
|
+
target,
|
|
2314
|
+
kind: "root-field"
|
|
2315
|
+
},
|
|
2316
|
+
field: summarizeField(rootField),
|
|
2317
|
+
parentType: queryType2.name
|
|
2318
|
+
};
|
|
2319
|
+
}
|
|
2320
|
+
const objectType = schema.getType(target);
|
|
2321
|
+
if (objectType && isObjectType(objectType)) {
|
|
2322
|
+
const typeSummary = summarizeObjectType(objectType);
|
|
2323
|
+
const rootFields = Object.values(queryType2.getFields()).filter((field) => unwrapType(field.type).name === target).map((field) => field.name);
|
|
2324
|
+
return {
|
|
2325
|
+
resource: {
|
|
2326
|
+
uri: `ez-know://lookup/${target}`,
|
|
2327
|
+
title: `Knowledge schema lookup: ${target}`,
|
|
2328
|
+
description: "Focused lookup of a single GraphQL type and its nested traversal fields."
|
|
2329
|
+
},
|
|
2330
|
+
source: {
|
|
2331
|
+
kind: "runtime-schema",
|
|
2332
|
+
queryType: queryType2.name
|
|
2333
|
+
},
|
|
2334
|
+
lookup: {
|
|
2335
|
+
target,
|
|
2336
|
+
kind: "object-type"
|
|
2337
|
+
},
|
|
2338
|
+
type: typeSummary,
|
|
2339
|
+
rootFields
|
|
2340
|
+
};
|
|
2341
|
+
}
|
|
2342
|
+
throw new Error(
|
|
2343
|
+
`Unknown schema lookup target "${target}". Use a root field name, a type name, or "Query".`
|
|
2344
|
+
);
|
|
2345
|
+
}
|
|
2346
|
+
function buildKnowledgeSchemaLookupDocument(schema, target) {
|
|
2347
|
+
return getLookupMetadata(schema, target);
|
|
2348
|
+
}
|
|
2349
|
+
function listKnowledgeSchemaTargets(schema) {
|
|
2350
|
+
const queryType2 = schema.getQueryType();
|
|
2351
|
+
if (!queryType2) {
|
|
2352
|
+
throw new Error("Knowledge GraphQL schema has no root query type.");
|
|
2353
|
+
}
|
|
2354
|
+
const objectTypeNames = getObjectTypes(schema).map((type) => type.name);
|
|
2355
|
+
const rootFieldNames = Object.keys(queryType2.getFields());
|
|
2356
|
+
const targetNames = ["Query", ...rootFieldNames, ...objectTypeNames];
|
|
2357
|
+
return Array.from(new Set(targetNames)).sort(
|
|
2358
|
+
(left, right) => left.localeCompare(right)
|
|
2359
|
+
);
|
|
2360
|
+
}
|
|
2361
|
+
|
|
2362
|
+
// packages/core/src/knowledge/resource-catalog.ts
|
|
2363
|
+
var KnowledgeResourceNotFoundError = class extends Error {
|
|
2364
|
+
constructor(uri, message = `Unknown ez-know resource URI "${uri}".`) {
|
|
2365
|
+
super(message);
|
|
2366
|
+
this.uri = uri;
|
|
2367
|
+
this.name = "KnowledgeResourceNotFoundError";
|
|
2368
|
+
}
|
|
2369
|
+
uri;
|
|
2370
|
+
code = "RESOURCE_NOT_FOUND";
|
|
2371
|
+
};
|
|
2372
|
+
var KnowledgeResourceUriError = class extends Error {
|
|
2373
|
+
constructor(uri, message) {
|
|
2374
|
+
super(message);
|
|
2375
|
+
this.uri = uri;
|
|
2376
|
+
this.name = "KnowledgeResourceUriError";
|
|
2377
|
+
}
|
|
2378
|
+
uri;
|
|
2379
|
+
code = "INVALID_RESOURCE_URI";
|
|
2380
|
+
};
|
|
2381
|
+
function createJsonResourceContent(uri, text) {
|
|
2382
|
+
return {
|
|
2383
|
+
uri,
|
|
2384
|
+
mimeType: "application/json",
|
|
2385
|
+
text
|
|
2386
|
+
};
|
|
2387
|
+
}
|
|
2388
|
+
function createMarkdownResourceContent(uri, text) {
|
|
2389
|
+
return {
|
|
2390
|
+
uri,
|
|
2391
|
+
mimeType: "text/markdown",
|
|
2392
|
+
text
|
|
2393
|
+
};
|
|
2394
|
+
}
|
|
2395
|
+
function createKnowledgeSchemaResourceDefinition() {
|
|
2396
|
+
return {
|
|
2397
|
+
uri: KNOWLEDGE_SCHEMA_RESOURCE_URI,
|
|
2398
|
+
name: "knowledge-schema",
|
|
2399
|
+
title: "Knowledge GraphQL Schema",
|
|
2400
|
+
description: "Canonical runtime GraphQL schema discovery payload for the knowledge layer.",
|
|
2401
|
+
mimeType: "application/json",
|
|
2402
|
+
read: () => ({
|
|
2403
|
+
resource: {
|
|
2404
|
+
uri: KNOWLEDGE_SCHEMA_RESOURCE_URI,
|
|
2405
|
+
title: "Knowledge GraphQL Schema",
|
|
2406
|
+
description: "Canonical runtime GraphQL schema discovery payload for the knowledge layer.",
|
|
2407
|
+
mimeType: "application/json"
|
|
2408
|
+
},
|
|
2409
|
+
content: createJsonResourceContent(
|
|
2410
|
+
KNOWLEDGE_SCHEMA_RESOURCE_URI,
|
|
2411
|
+
createKnowledgeSchemaDiscoveryText()
|
|
2412
|
+
)
|
|
2413
|
+
})
|
|
2414
|
+
};
|
|
2415
|
+
}
|
|
2416
|
+
function createKnowledgeExtractionTypesResourceDefinition() {
|
|
2417
|
+
return {
|
|
2418
|
+
uri: KNOWLEDGE_EXTRACTION_TYPES_RESOURCE_URI,
|
|
2419
|
+
name: "knowledge-extraction-types",
|
|
2420
|
+
title: "Knowledge Extraction Types",
|
|
2421
|
+
description: "Canonical registry of knowledge types supported by the extraction workflow.",
|
|
2422
|
+
mimeType: "application/json",
|
|
2423
|
+
read: () => ({
|
|
2424
|
+
resource: {
|
|
2425
|
+
uri: KNOWLEDGE_EXTRACTION_TYPES_RESOURCE_URI,
|
|
2426
|
+
title: "Knowledge Extraction Types",
|
|
2427
|
+
description: "Canonical registry of knowledge types supported by the extraction workflow.",
|
|
2428
|
+
mimeType: "application/json"
|
|
2429
|
+
},
|
|
2430
|
+
content: createJsonResourceContent(
|
|
2431
|
+
KNOWLEDGE_EXTRACTION_TYPES_RESOURCE_URI,
|
|
2432
|
+
JSON.stringify(buildKnowledgeExtractionTypeIndexDocument(), null, 2)
|
|
2433
|
+
)
|
|
2434
|
+
})
|
|
2435
|
+
};
|
|
2436
|
+
}
|
|
2437
|
+
function createKnowledgeSchemaLookupTemplateDefinition() {
|
|
2438
|
+
return {
|
|
2439
|
+
uriTemplate: KNOWLEDGE_SCHEMA_LOOKUP_URI,
|
|
2440
|
+
name: "knowledge-schema-lookup",
|
|
2441
|
+
title: "Knowledge Schema Lookup",
|
|
2442
|
+
description: "Focused runtime GraphQL schema lookup for a type name, root field, or Query.",
|
|
2443
|
+
mimeType: "application/json",
|
|
2444
|
+
list: () => listKnowledgeSchemaTargets(knowledgeGraphSchema).map((target) => ({
|
|
2445
|
+
uri: `ez-know://lookup/${target}`,
|
|
2446
|
+
name: target,
|
|
2447
|
+
title: `Knowledge schema lookup: ${target}`,
|
|
2448
|
+
description: target === "Query" ? "Focused lookup of the root query fields." : `Focused lookup of ${target}.`,
|
|
2449
|
+
mimeType: "application/json"
|
|
2450
|
+
})),
|
|
2451
|
+
read: (uri) => {
|
|
2452
|
+
const target = readUriSegment(uri, "ez-know://lookup/");
|
|
2453
|
+
try {
|
|
2454
|
+
return {
|
|
2455
|
+
resource: {
|
|
2456
|
+
uri,
|
|
2457
|
+
title: `Knowledge schema lookup: ${target}`,
|
|
2458
|
+
description: target === "Query" ? "Focused lookup of the root query fields and their arguments." : `Focused lookup of ${target}.`,
|
|
2459
|
+
mimeType: "application/json"
|
|
2460
|
+
},
|
|
2461
|
+
content: createJsonResourceContent(
|
|
2462
|
+
uri,
|
|
2463
|
+
createKnowledgeSchemaLookupText(target)
|
|
2464
|
+
)
|
|
2465
|
+
};
|
|
2466
|
+
} catch (error) {
|
|
2467
|
+
if (error instanceof Error) {
|
|
2468
|
+
throw new KnowledgeResourceUriError(uri, error.message);
|
|
2469
|
+
}
|
|
2470
|
+
throw error;
|
|
2471
|
+
}
|
|
2472
|
+
}
|
|
2473
|
+
};
|
|
2474
|
+
}
|
|
2475
|
+
function createKnowledgeExtractionSchemaTemplateDefinition() {
|
|
2476
|
+
return {
|
|
2477
|
+
uriTemplate: KNOWLEDGE_EXTRACTION_SCHEMA_RESOURCE_URI,
|
|
2478
|
+
name: "knowledge-extraction-schema",
|
|
2479
|
+
title: "Knowledge Extraction Schema",
|
|
2480
|
+
description: "Runtime JSON-schema discovery for a supported knowledge type.",
|
|
2481
|
+
mimeType: "application/json",
|
|
2482
|
+
list: () => listKnowledgeExtractionResourceTypes().map((definition) => ({
|
|
2483
|
+
uri: `ez-know://extraction/schema/${definition.collection}`,
|
|
2484
|
+
name: definition.collection,
|
|
2485
|
+
title: `${definition.title} Extraction Schema`,
|
|
2486
|
+
description: `Runtime schema discovery for ${definition.title.toLowerCase()}.`,
|
|
2487
|
+
mimeType: "application/json"
|
|
2488
|
+
})),
|
|
2489
|
+
read: (uri) => {
|
|
2490
|
+
const type = readUriSegment(uri, "ez-know://extraction/schema/");
|
|
2491
|
+
try {
|
|
2492
|
+
const document = buildKnowledgeExtractionSchemaDocument(type);
|
|
2493
|
+
return {
|
|
2494
|
+
resource: {
|
|
2495
|
+
uri: `ez-know://extraction/schema/${document.type.collection}`,
|
|
2496
|
+
title: `${document.type.title} Extraction Schema`,
|
|
2497
|
+
description: "Runtime JSON Schema view of the canonical knowledge object model.",
|
|
2498
|
+
mimeType: "application/json"
|
|
2499
|
+
},
|
|
2500
|
+
content: createJsonResourceContent(
|
|
2501
|
+
`ez-know://extraction/schema/${document.type.collection}`,
|
|
2502
|
+
JSON.stringify(document, null, 2)
|
|
2503
|
+
)
|
|
2504
|
+
};
|
|
2505
|
+
} catch (error) {
|
|
2506
|
+
if (error instanceof Error) {
|
|
2507
|
+
throw new KnowledgeResourceUriError(uri, error.message);
|
|
2508
|
+
}
|
|
2509
|
+
throw error;
|
|
2510
|
+
}
|
|
2511
|
+
}
|
|
2512
|
+
};
|
|
2513
|
+
}
|
|
2514
|
+
function createKnowledgeExtractionGuideTemplateDefinition() {
|
|
2515
|
+
return {
|
|
2516
|
+
uriTemplate: KNOWLEDGE_EXTRACTION_GUIDE_RESOURCE_URI,
|
|
2517
|
+
name: "knowledge-extraction-guide",
|
|
2518
|
+
title: "Knowledge Extraction Guide",
|
|
2519
|
+
description: "Checked-in Markdown guidance for a supported knowledge type.",
|
|
2520
|
+
mimeType: "text/markdown",
|
|
2521
|
+
list: () => listKnowledgeExtractionResourceTypes().map((definition) => ({
|
|
2522
|
+
uri: `ez-know://extraction/guide/${definition.collection}`,
|
|
2523
|
+
name: definition.collection,
|
|
2524
|
+
title: `${definition.title} Extraction Guide`,
|
|
2525
|
+
description: `Checked-in extraction guidance for ${definition.title.toLowerCase()}.`,
|
|
2526
|
+
mimeType: "text/markdown"
|
|
2527
|
+
})),
|
|
2528
|
+
read: async (uri) => {
|
|
2529
|
+
const type = readUriSegment(uri, "ez-know://extraction/guide/");
|
|
2530
|
+
try {
|
|
2531
|
+
const document = await buildKnowledgeExtractionGuideDocument(type);
|
|
2532
|
+
return {
|
|
2533
|
+
resource: {
|
|
2534
|
+
uri: `ez-know://extraction/guide/${document.type.collection}`,
|
|
2535
|
+
title: `${document.type.title} Extraction Guide`,
|
|
2536
|
+
description: "Checked-in Markdown guidance for extracting this knowledge type.",
|
|
2537
|
+
mimeType: "text/markdown"
|
|
2538
|
+
},
|
|
2539
|
+
content: createMarkdownResourceContent(
|
|
2540
|
+
`ez-know://extraction/guide/${document.type.collection}`,
|
|
2541
|
+
document.markdown
|
|
2542
|
+
)
|
|
2543
|
+
};
|
|
2544
|
+
} catch (error) {
|
|
2545
|
+
if (error instanceof Error) {
|
|
2546
|
+
throw new KnowledgeResourceUriError(uri, error.message);
|
|
2547
|
+
}
|
|
2548
|
+
throw error;
|
|
2549
|
+
}
|
|
2550
|
+
}
|
|
2551
|
+
};
|
|
2552
|
+
}
|
|
2553
|
+
function createKnowledgeSchemaDiscoveryText() {
|
|
2554
|
+
return JSON.stringify(buildKnowledgeSchemaDiscoveryDocument(knowledgeGraphSchema), null, 2);
|
|
2555
|
+
}
|
|
2556
|
+
function createKnowledgeSchemaLookupText(target) {
|
|
2557
|
+
return JSON.stringify(
|
|
2558
|
+
buildKnowledgeSchemaLookupDocument(knowledgeGraphSchema, target),
|
|
2559
|
+
null,
|
|
2560
|
+
2
|
|
2561
|
+
);
|
|
2562
|
+
}
|
|
2563
|
+
function readUriSegment(uri, prefix) {
|
|
2564
|
+
if (!uri.startsWith(prefix)) {
|
|
2565
|
+
throw new KnowledgeResourceNotFoundError(uri);
|
|
2566
|
+
}
|
|
2567
|
+
const segment = uri.slice(prefix.length);
|
|
2568
|
+
if (segment.length === 0 || segment.includes("/")) {
|
|
2569
|
+
throw new KnowledgeResourceUriError(
|
|
2570
|
+
uri,
|
|
2571
|
+
`Unsupported ez-know resource URI "${uri}".`
|
|
2572
|
+
);
|
|
2573
|
+
}
|
|
2574
|
+
return segment;
|
|
2575
|
+
}
|
|
2576
|
+
var KNOWLEDGE_RESOURCE_DEFINITIONS = [
|
|
2577
|
+
createKnowledgeSchemaResourceDefinition(),
|
|
2578
|
+
createKnowledgeExtractionTypesResourceDefinition()
|
|
2579
|
+
];
|
|
2580
|
+
var KNOWLEDGE_RESOURCE_TEMPLATE_DEFINITIONS = [
|
|
2581
|
+
createKnowledgeSchemaLookupTemplateDefinition(),
|
|
2582
|
+
createKnowledgeExtractionSchemaTemplateDefinition(),
|
|
2583
|
+
createKnowledgeExtractionGuideTemplateDefinition()
|
|
2584
|
+
];
|
|
2585
|
+
|
|
2070
2586
|
// packages/core/src/knowledge/patch/scope-audit.ts
|
|
2071
2587
|
import { z as z6 } from "zod/v4";
|
|
2072
2588
|
var compareScopeWithEvidenceInputSchema = z6.object({
|
|
@@ -2089,17 +2605,6 @@ var compareScopeWithEvidenceResultSchema = z6.object({
|
|
|
2089
2605
|
message: z6.string()
|
|
2090
2606
|
});
|
|
2091
2607
|
|
|
2092
|
-
// packages/core/src/knowledge/schema-discovery.ts
|
|
2093
|
-
import {
|
|
2094
|
-
isAbstractType,
|
|
2095
|
-
isCompositeType,
|
|
2096
|
-
isListType,
|
|
2097
|
-
isNonNullType,
|
|
2098
|
-
isObjectType,
|
|
2099
|
-
isScalarType,
|
|
2100
|
-
isUnionType
|
|
2101
|
-
} from "graphql";
|
|
2102
|
-
|
|
2103
2608
|
// packages/rest/src/constants.ts
|
|
2104
2609
|
var REST_SERVICE_NAME = "ez-know-rest";
|
|
2105
2610
|
var REST_V1_PREFIX = "/api/v1";
|