@agentxm/knowledge-query 0.28.4-bootstrap.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/LICENSE +110 -0
- package/dist/src/index.d.ts +8 -0
- package/dist/src/index.js +8 -0
- package/dist/src/knowledge-capabilities.d.ts +46 -0
- package/dist/src/knowledge-capabilities.js +84 -0
- package/dist/src/knowledge-capture.d.ts +28 -0
- package/dist/src/knowledge-capture.js +49 -0
- package/dist/src/knowledge-graph.d.ts +40 -0
- package/dist/src/knowledge-graph.js +130 -0
- package/dist/src/knowledge-index.d.ts +76 -0
- package/dist/src/knowledge-index.js +373 -0
- package/dist/src/knowledge-projection.d.ts +61 -0
- package/dist/src/knowledge-projection.js +161 -0
- package/dist/src/knowledge-query.d.ts +116 -0
- package/dist/src/knowledge-query.js +117 -0
- package/dist/src/knowledge-revision.d.ts +36 -0
- package/dist/src/knowledge-revision.js +99 -0
- package/dist/src/live.d.ts +11 -0
- package/dist/src/live.js +19 -0
- package/package.json +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# Functional Source License, Version 1.1, MIT Future License
|
|
2
|
+
|
|
3
|
+
## Abbreviation
|
|
4
|
+
|
|
5
|
+
FSL-1.1-MIT
|
|
6
|
+
|
|
7
|
+
## Notice
|
|
8
|
+
|
|
9
|
+
Copyright 2025-2026 AgentXM, Inc.
|
|
10
|
+
|
|
11
|
+
## Terms and Conditions
|
|
12
|
+
|
|
13
|
+
### Licensor ("We")
|
|
14
|
+
|
|
15
|
+
The party offering the Software under these Terms and Conditions.
|
|
16
|
+
|
|
17
|
+
### The Software
|
|
18
|
+
|
|
19
|
+
The "Software" is each version of the software that we make available under
|
|
20
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
21
|
+
Conditions with the Software.
|
|
22
|
+
|
|
23
|
+
### License Grant
|
|
24
|
+
|
|
25
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
26
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to
|
|
27
|
+
use, copy, modify, create derivative works, publicly perform, publicly display
|
|
28
|
+
and redistribute the Software for any Permitted Purpose identified below.
|
|
29
|
+
|
|
30
|
+
### Permitted Purpose
|
|
31
|
+
|
|
32
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
33
|
+
means making the Software available to others in a commercial product or
|
|
34
|
+
service that:
|
|
35
|
+
|
|
36
|
+
1. substitutes for the Software;
|
|
37
|
+
|
|
38
|
+
2. substitutes for any other product or service we offer using the Software
|
|
39
|
+
that exists as of the date we make the Software available; or
|
|
40
|
+
|
|
41
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
42
|
+
|
|
43
|
+
Permitted Purposes specifically include using the Software:
|
|
44
|
+
|
|
45
|
+
1. for your internal use and access;
|
|
46
|
+
|
|
47
|
+
2. for non-commercial education;
|
|
48
|
+
|
|
49
|
+
3. for non-commercial research; and
|
|
50
|
+
|
|
51
|
+
4. in connection with professional services that you provide to a licensee
|
|
52
|
+
using the Software in accordance with these Terms and Conditions.
|
|
53
|
+
|
|
54
|
+
### Patents
|
|
55
|
+
|
|
56
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
57
|
+
patents, the license grant above includes a license under our patents. If you
|
|
58
|
+
make a claim against any party that the Software infringes or contributes to
|
|
59
|
+
the infringement of any patent, then your patent license to the Software ends
|
|
60
|
+
immediately.
|
|
61
|
+
|
|
62
|
+
### Redistribution
|
|
63
|
+
|
|
64
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
65
|
+
the Software.
|
|
66
|
+
|
|
67
|
+
If you redistribute any copies, modifications or derivatives of the Software,
|
|
68
|
+
you must include a copy of or a link to these Terms and Conditions and not
|
|
69
|
+
remove any copyright notices provided in or with the Software.
|
|
70
|
+
|
|
71
|
+
### Disclaimer
|
|
72
|
+
|
|
73
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
|
74
|
+
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
|
75
|
+
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
76
|
+
|
|
77
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
78
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
|
|
79
|
+
EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
80
|
+
|
|
81
|
+
### Trademarks
|
|
82
|
+
|
|
83
|
+
Except for displaying the License Details and identifying us as the origin of
|
|
84
|
+
the Software, you have no right under these Terms and Conditions to use our
|
|
85
|
+
trademarks, trade names, service marks or product names.
|
|
86
|
+
|
|
87
|
+
## Grant of Future License
|
|
88
|
+
|
|
89
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
|
90
|
+
the MIT license that is effective on the second anniversary of the date we make
|
|
91
|
+
the Software available. On or after that date, you may use the Software under
|
|
92
|
+
the MIT license, in which case the following will apply:
|
|
93
|
+
|
|
94
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
95
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
96
|
+
the Software without restriction, including without limitation the rights to
|
|
97
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
98
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
|
99
|
+
so, subject to the following conditions:
|
|
100
|
+
|
|
101
|
+
The above copyright notice and this permission notice shall be included in all
|
|
102
|
+
copies or substantial portions of the Software.
|
|
103
|
+
|
|
104
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
105
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
106
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
107
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
108
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
109
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
110
|
+
SOFTWARE.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { relatedKnowledgeConcepts, resolveKnowledgeConcept, type KnowledgeRelatedConcept, type KnowledgeRelation, type KnowledgeResolveCandidate, type KnowledgeResolveResult, } from "./knowledge-graph.js";
|
|
2
|
+
export { projectKnowledgeConcepts, resolveKnowledgeFrontmatterPointer, type KnowledgeBacklink, type KnowledgeBodyPassage, type KnowledgeFrontmatterPointerResult, type KnowledgeOutgoingLink, type KnowledgeProjectedConcept, type KnowledgeSearchableField, type KnowledgeSearchableUnit, } from "./knowledge-projection.js";
|
|
3
|
+
export { captureKnowledgeCorpus, computeKnowledgeCorpusFingerprint, computeKnowledgeProjectionRevision, computeKnowledgeSourceRevision, KnowledgeCorpusChangingError, type CapturedKnowledgeCorpus, type CapturedKnowledgeSource, type KnowledgeCorpusSource, } from "./knowledge-revision.js";
|
|
4
|
+
export { KNOWLEDGE_DISCOVERY_CAPABILITIES, KNOWLEDGE_DISCOVERY_CAPABILITIES_VERSION, KnowledgeDiscoveryCapabilitiesSchema, type KnowledgeDiscoveryCapabilities, } from "./knowledge-capabilities.js";
|
|
5
|
+
export { knowledgeQueryIdentity, KnowledgeQueryClauseSchema, KnowledgeQuerySchema, KnowledgeTextClauseSchema, makeKnowledgeQuery, KNOWLEDGE_DISCOVERY_OPERATIONS, KNOWLEDGE_LIFECYCLE_FILTER_FIELDS, KNOWLEDGE_METADATA_FILTER_FIELDS, KNOWLEDGE_QUERY_CONTRACT_VERSION, KNOWLEDGE_QUERY_OPERATORS, KNOWLEDGE_SEARCHABLE_FIELDS, type KnowledgeQuery, type KnowledgeQueryClause, type KnowledgeTextClause, } from "./knowledge-query.js";
|
|
6
|
+
export { getKnowledgeIndexConcept, KnowledgeCursorInvalidError, KnowledgeIndex, makeKnowledgeIndexSnapshot, queryKnowledgeIndex, queryKnowledgeIndexResult, type KnowledgeConceptResult, type KnowledgeCursorInvalidReason, type KnowledgeIndexBundleInput, type KnowledgeIndexedConcept, type KnowledgeIndexService, type KnowledgeIndexSnapshot, type KnowledgeMatchSpan, type KnowledgeQueryPage, type KnowledgeResultPassage, } from "./knowledge-index.js";
|
|
7
|
+
export { captureKnowledgeIndexBundles, KnowledgeCapturedSourceMissingError, type KnowledgeBundleCaptureDescriptor, } from "./knowledge-capture.js";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { relatedKnowledgeConcepts, resolveKnowledgeConcept, } from "./knowledge-graph.js";
|
|
2
|
+
export { projectKnowledgeConcepts, resolveKnowledgeFrontmatterPointer, } from "./knowledge-projection.js";
|
|
3
|
+
export { captureKnowledgeCorpus, computeKnowledgeCorpusFingerprint, computeKnowledgeProjectionRevision, computeKnowledgeSourceRevision, KnowledgeCorpusChangingError, } from "./knowledge-revision.js";
|
|
4
|
+
export { KNOWLEDGE_DISCOVERY_CAPABILITIES, KNOWLEDGE_DISCOVERY_CAPABILITIES_VERSION, KnowledgeDiscoveryCapabilitiesSchema, } from "./knowledge-capabilities.js";
|
|
5
|
+
export { knowledgeQueryIdentity, KnowledgeQueryClauseSchema, KnowledgeQuerySchema, KnowledgeTextClauseSchema, makeKnowledgeQuery, KNOWLEDGE_DISCOVERY_OPERATIONS, KNOWLEDGE_LIFECYCLE_FILTER_FIELDS, KNOWLEDGE_METADATA_FILTER_FIELDS, KNOWLEDGE_QUERY_CONTRACT_VERSION, KNOWLEDGE_QUERY_OPERATORS, KNOWLEDGE_SEARCHABLE_FIELDS, } from "./knowledge-query.js";
|
|
6
|
+
export { getKnowledgeIndexConcept, KnowledgeCursorInvalidError, KnowledgeIndex, makeKnowledgeIndexSnapshot, queryKnowledgeIndex, queryKnowledgeIndexResult, } from "./knowledge-index.js";
|
|
7
|
+
export { captureKnowledgeIndexBundles, KnowledgeCapturedSourceMissingError, } from "./knowledge-capture.js";
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import * as Schema from "effect/Schema";
|
|
2
|
+
export declare const KNOWLEDGE_DISCOVERY_CAPABILITIES_VERSION = "axm-knowledge-discovery-capabilities-v1";
|
|
3
|
+
export declare const KnowledgeDiscoveryCapabilitiesSchema: Schema.Struct<{
|
|
4
|
+
readonly version: Schema.Literal<"axm-knowledge-discovery-capabilities-v1">;
|
|
5
|
+
readonly operations: Schema.$Array<Schema.Literals<readonly ["resolve", "search", "query", "get", "related", "status"]>>;
|
|
6
|
+
readonly queryContractVersion: Schema.Literal<"axm-knowledge-query-v1">;
|
|
7
|
+
readonly strategies: Schema.$Array<Schema.Literal<"lexical">>;
|
|
8
|
+
readonly operators: Schema.$Array<Schema.Literals<readonly ["term", "phrase", "literal", "equals", "not-equals", "contains"]>>;
|
|
9
|
+
readonly tokenizerProfile: Schema.Struct<{
|
|
10
|
+
readonly id: Schema.Literal<"axm-knowledge-lexical-v1">;
|
|
11
|
+
readonly unicodeNormalization: Schema.Literal<"NFKC">;
|
|
12
|
+
readonly caseNormalization: Schema.Literal<"unicode-case-fold">;
|
|
13
|
+
readonly termBoundary: Schema.Literal<"unicode-whitespace-punctuation-camel-code">;
|
|
14
|
+
readonly stemming: Schema.Literal<false>;
|
|
15
|
+
}>;
|
|
16
|
+
readonly searchableFields: Schema.$Array<Schema.Literals<readonly ["bundle", "conceptId", "title", "description", "tag", "type", "body", "resource", "status", "staleAfter", "generated", "verified", "trust"]>>;
|
|
17
|
+
readonly metadataFilterFields: Schema.$Array<Schema.Literals<readonly ["bundle", "conceptId", "kind", "title", "description", "tag", "type", "resource"]>>;
|
|
18
|
+
readonly lifecycleFilterFields: Schema.$Array<Schema.Literals<readonly ["status", "staleAfter", "generated", "verified", "trust"]>>;
|
|
19
|
+
readonly extensionProperties: Schema.Struct<{
|
|
20
|
+
readonly addressing: Schema.Literal<"rfc6901-json-pointer">;
|
|
21
|
+
readonly source: Schema.Literal<"preserved-frontmatter">;
|
|
22
|
+
}>;
|
|
23
|
+
readonly limits: Schema.Struct<{
|
|
24
|
+
readonly defaultPageSize: Schema.Number;
|
|
25
|
+
readonly maximumPageSize: Schema.Number;
|
|
26
|
+
readonly defaultPassagesPerResult: Schema.Number;
|
|
27
|
+
readonly maximumPassagesPerResult: Schema.Number;
|
|
28
|
+
readonly defaultPassageLength: Schema.Number;
|
|
29
|
+
readonly maximumPassageLength: Schema.Number;
|
|
30
|
+
readonly maximumTraversalDepth: Schema.Number;
|
|
31
|
+
readonly maximumFuzzyCandidates: Schema.Number;
|
|
32
|
+
}>;
|
|
33
|
+
readonly cursor: Schema.Struct<{
|
|
34
|
+
readonly mechanism: Schema.Literal<"stateless-opaque">;
|
|
35
|
+
readonly maximumAgeSeconds: Schema.Number;
|
|
36
|
+
readonly binds: Schema.$Array<Schema.Literals<readonly ["corpus-fingerprint", "canonical-query-digest", "ordering-position"]>>;
|
|
37
|
+
}>;
|
|
38
|
+
readonly output: Schema.Struct<{
|
|
39
|
+
readonly envelope: Schema.Literal<"axm.machine-output/result-envelope-v1">;
|
|
40
|
+
readonly resultLevel: Schema.Literal<"concept">;
|
|
41
|
+
readonly paginationKeys: Schema.$Array<Schema.Literals<readonly ["items", "count", "hasMore", "cursor"]>>;
|
|
42
|
+
}>;
|
|
43
|
+
}>;
|
|
44
|
+
export type KnowledgeDiscoveryCapabilities = typeof KnowledgeDiscoveryCapabilitiesSchema.Type;
|
|
45
|
+
export declare const KNOWLEDGE_DISCOVERY_CAPABILITIES: KnowledgeDiscoveryCapabilities;
|
|
46
|
+
//# sourceMappingURL=knowledge-capabilities.d.ts.map
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import * as Schema from "effect/Schema";
|
|
2
|
+
import { KNOWLEDGE_SEARCH_TOKENIZER_PROFILE } from "@agentxm/registry-protocol/unstable/knowledge/knowledge-search";
|
|
3
|
+
import { KNOWLEDGE_DISCOVERY_OPERATIONS, KNOWLEDGE_LIFECYCLE_FILTER_FIELDS, KNOWLEDGE_METADATA_FILTER_FIELDS, KNOWLEDGE_QUERY_CONTRACT_VERSION, KNOWLEDGE_QUERY_OPERATORS, KNOWLEDGE_SEARCHABLE_FIELDS, } from "./knowledge-query.js";
|
|
4
|
+
export const KNOWLEDGE_DISCOVERY_CAPABILITIES_VERSION = "axm-knowledge-discovery-capabilities-v1";
|
|
5
|
+
export const KnowledgeDiscoveryCapabilitiesSchema = Schema.Struct({
|
|
6
|
+
version: Schema.Literal(KNOWLEDGE_DISCOVERY_CAPABILITIES_VERSION),
|
|
7
|
+
operations: Schema.Array(Schema.Literals(KNOWLEDGE_DISCOVERY_OPERATIONS)),
|
|
8
|
+
queryContractVersion: Schema.Literal(KNOWLEDGE_QUERY_CONTRACT_VERSION),
|
|
9
|
+
strategies: Schema.Array(Schema.Literal("lexical")),
|
|
10
|
+
operators: Schema.Array(Schema.Literals(KNOWLEDGE_QUERY_OPERATORS)),
|
|
11
|
+
tokenizerProfile: Schema.Struct({
|
|
12
|
+
id: Schema.Literal(KNOWLEDGE_SEARCH_TOKENIZER_PROFILE.id),
|
|
13
|
+
unicodeNormalization: Schema.Literal(KNOWLEDGE_SEARCH_TOKENIZER_PROFILE.unicodeNormalization),
|
|
14
|
+
caseNormalization: Schema.Literal(KNOWLEDGE_SEARCH_TOKENIZER_PROFILE.caseNormalization),
|
|
15
|
+
termBoundary: Schema.Literal(KNOWLEDGE_SEARCH_TOKENIZER_PROFILE.termBoundary),
|
|
16
|
+
stemming: Schema.Literal(KNOWLEDGE_SEARCH_TOKENIZER_PROFILE.stemming),
|
|
17
|
+
}),
|
|
18
|
+
searchableFields: Schema.Array(Schema.Literals(KNOWLEDGE_SEARCHABLE_FIELDS)),
|
|
19
|
+
metadataFilterFields: Schema.Array(Schema.Literals(KNOWLEDGE_METADATA_FILTER_FIELDS)),
|
|
20
|
+
lifecycleFilterFields: Schema.Array(Schema.Literals(KNOWLEDGE_LIFECYCLE_FILTER_FIELDS)),
|
|
21
|
+
extensionProperties: Schema.Struct({
|
|
22
|
+
addressing: Schema.Literal("rfc6901-json-pointer"),
|
|
23
|
+
source: Schema.Literal("preserved-frontmatter"),
|
|
24
|
+
}),
|
|
25
|
+
limits: Schema.Struct({
|
|
26
|
+
defaultPageSize: Schema.Number,
|
|
27
|
+
maximumPageSize: Schema.Number,
|
|
28
|
+
defaultPassagesPerResult: Schema.Number,
|
|
29
|
+
maximumPassagesPerResult: Schema.Number,
|
|
30
|
+
defaultPassageLength: Schema.Number,
|
|
31
|
+
maximumPassageLength: Schema.Number,
|
|
32
|
+
maximumTraversalDepth: Schema.Number,
|
|
33
|
+
maximumFuzzyCandidates: Schema.Number,
|
|
34
|
+
}),
|
|
35
|
+
cursor: Schema.Struct({
|
|
36
|
+
mechanism: Schema.Literal("stateless-opaque"),
|
|
37
|
+
maximumAgeSeconds: Schema.Number,
|
|
38
|
+
binds: Schema.Array(Schema.Literals(["corpus-fingerprint", "canonical-query-digest", "ordering-position"])),
|
|
39
|
+
}),
|
|
40
|
+
output: Schema.Struct({
|
|
41
|
+
envelope: Schema.Literal("axm.machine-output/result-envelope-v1"),
|
|
42
|
+
resultLevel: Schema.Literal("concept"),
|
|
43
|
+
paginationKeys: Schema.Array(Schema.Literals(["items", "count", "hasMore", "cursor"])),
|
|
44
|
+
}),
|
|
45
|
+
}).annotate({
|
|
46
|
+
identifier: "KnowledgeDiscoveryCapabilities",
|
|
47
|
+
title: "Knowledge Discovery Capabilities",
|
|
48
|
+
});
|
|
49
|
+
export const KNOWLEDGE_DISCOVERY_CAPABILITIES = {
|
|
50
|
+
version: KNOWLEDGE_DISCOVERY_CAPABILITIES_VERSION,
|
|
51
|
+
operations: KNOWLEDGE_DISCOVERY_OPERATIONS,
|
|
52
|
+
queryContractVersion: KNOWLEDGE_QUERY_CONTRACT_VERSION,
|
|
53
|
+
strategies: ["lexical"],
|
|
54
|
+
operators: KNOWLEDGE_QUERY_OPERATORS,
|
|
55
|
+
tokenizerProfile: KNOWLEDGE_SEARCH_TOKENIZER_PROFILE,
|
|
56
|
+
searchableFields: KNOWLEDGE_SEARCHABLE_FIELDS,
|
|
57
|
+
metadataFilterFields: KNOWLEDGE_METADATA_FILTER_FIELDS,
|
|
58
|
+
lifecycleFilterFields: KNOWLEDGE_LIFECYCLE_FILTER_FIELDS,
|
|
59
|
+
extensionProperties: {
|
|
60
|
+
addressing: "rfc6901-json-pointer",
|
|
61
|
+
source: "preserved-frontmatter",
|
|
62
|
+
},
|
|
63
|
+
limits: {
|
|
64
|
+
defaultPageSize: 25,
|
|
65
|
+
maximumPageSize: 100,
|
|
66
|
+
defaultPassagesPerResult: 3,
|
|
67
|
+
maximumPassagesPerResult: 10,
|
|
68
|
+
defaultPassageLength: 500,
|
|
69
|
+
maximumPassageLength: 2_000,
|
|
70
|
+
maximumTraversalDepth: 3,
|
|
71
|
+
maximumFuzzyCandidates: 10,
|
|
72
|
+
},
|
|
73
|
+
cursor: {
|
|
74
|
+
mechanism: "stateless-opaque",
|
|
75
|
+
maximumAgeSeconds: 86_400,
|
|
76
|
+
binds: ["corpus-fingerprint", "canonical-query-digest", "ordering-position"],
|
|
77
|
+
},
|
|
78
|
+
output: {
|
|
79
|
+
envelope: "axm.machine-output/result-envelope-v1",
|
|
80
|
+
resultLevel: "concept",
|
|
81
|
+
paginationKeys: ["items", "count", "hasMore", "cursor"],
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
//# sourceMappingURL=knowledge-capabilities.js.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as FileSystem from "effect/FileSystem";
|
|
3
|
+
import * as Path from "effect/Path";
|
|
4
|
+
import type { KnowledgeBundleFqn } from "@agentxm/extension-model/unstable/knowledge/concept-ref";
|
|
5
|
+
import type { KnowledgeIndexBundleInput } from "./knowledge-index.js";
|
|
6
|
+
import { type KnowledgeCorpusChangingError } from "./knowledge-revision.js";
|
|
7
|
+
export interface KnowledgeBundleCaptureDescriptor {
|
|
8
|
+
readonly bundle: KnowledgeBundleFqn;
|
|
9
|
+
readonly version: string;
|
|
10
|
+
readonly sourceRoot: string;
|
|
11
|
+
}
|
|
12
|
+
declare const KnowledgeCapturedSourceMissingError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
13
|
+
readonly _tag: "KnowledgeCapturedSourceMissingError";
|
|
14
|
+
} & Readonly<A>;
|
|
15
|
+
export declare class KnowledgeCapturedSourceMissingError extends KnowledgeCapturedSourceMissingError_base<{
|
|
16
|
+
readonly bundle: string;
|
|
17
|
+
readonly relativePath: string;
|
|
18
|
+
}> {
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Capture and parse all selected bundles from the same double-read corpus view.
|
|
22
|
+
* Absolute roots are used only for I/O and never enter revisions or results.
|
|
23
|
+
*/
|
|
24
|
+
export declare const captureKnowledgeIndexBundles: (descriptors: ReadonlyArray<KnowledgeBundleCaptureDescriptor>, options?: {
|
|
25
|
+
readonly maxAttempts?: number;
|
|
26
|
+
}) => Effect.Effect<ReadonlyArray<KnowledgeIndexBundleInput>, unknown | KnowledgeCorpusChangingError | KnowledgeCapturedSourceMissingError, FileSystem.FileSystem | Path.Path>;
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=knowledge-capture.d.ts.map
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// @effect-diagnostics anyUnknownInErrorContext:off — corpus readers deliberately preserve caller-owned foreign read errors
|
|
2
|
+
import * as Data from "effect/Data";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as FileSystem from "effect/FileSystem";
|
|
5
|
+
import * as Path from "effect/Path";
|
|
6
|
+
import { captureKnowledgeCorpus, } from "./knowledge-revision.js";
|
|
7
|
+
import { collectKnowledgeBundleEntries, inspectKnowledgeEntries, } from "@agentxm/registry-protocol/unstable/knowledge/okf";
|
|
8
|
+
export class KnowledgeCapturedSourceMissingError extends Data.TaggedError("KnowledgeCapturedSourceMissingError") {
|
|
9
|
+
}
|
|
10
|
+
const sourceKey = (bundle, relativePath) => `${bundle.length}:${bundle}${relativePath.length}:${relativePath}`;
|
|
11
|
+
/**
|
|
12
|
+
* Capture and parse all selected bundles from the same double-read corpus view.
|
|
13
|
+
* Absolute roots are used only for I/O and never enter revisions or results.
|
|
14
|
+
*/
|
|
15
|
+
export const captureKnowledgeIndexBundles = (descriptors, options) => Effect.gen(function* () {
|
|
16
|
+
const fs = yield* FileSystem.FileSystem;
|
|
17
|
+
const path = yield* Path.Path;
|
|
18
|
+
const prepared = yield* Effect.forEach([...descriptors].sort((left, right) => left.bundle.localeCompare(right.bundle)), (descriptor) => collectKnowledgeBundleEntries(descriptor.sourceRoot).pipe(Effect.map((entries) => ({ ...descriptor, entries }))), { concurrency: 16 });
|
|
19
|
+
const roots = new Map(prepared.map((descriptor) => [descriptor.bundle, descriptor.sourceRoot]));
|
|
20
|
+
const corpusSources = prepared.flatMap((descriptor) => descriptor.entries
|
|
21
|
+
.filter((entry) => entry.type === "File")
|
|
22
|
+
.map((entry) => ({ bundle: descriptor.bundle, relativePath: entry.relativePath })));
|
|
23
|
+
const readSource = (source) => {
|
|
24
|
+
const root = roots.get(source.bundle);
|
|
25
|
+
return root === undefined
|
|
26
|
+
? Effect.fail(new KnowledgeCapturedSourceMissingError({
|
|
27
|
+
bundle: source.bundle,
|
|
28
|
+
relativePath: source.relativePath,
|
|
29
|
+
}))
|
|
30
|
+
: fs.readFile(path.join(root, source.relativePath));
|
|
31
|
+
};
|
|
32
|
+
const captured = yield* captureKnowledgeCorpus(corpusSources, readSource, options);
|
|
33
|
+
const byPath = new Map(captured.sources.map((source) => [sourceKey(source.bundle, source.relativePath), source]));
|
|
34
|
+
return yield* Effect.forEach(prepared, (descriptor) => inspectKnowledgeEntries(descriptor.entries, (relativePath) => {
|
|
35
|
+
const source = byPath.get(sourceKey(descriptor.bundle, relativePath));
|
|
36
|
+
return source === undefined
|
|
37
|
+
? Effect.fail(new KnowledgeCapturedSourceMissingError({
|
|
38
|
+
bundle: descriptor.bundle,
|
|
39
|
+
relativePath,
|
|
40
|
+
}))
|
|
41
|
+
: Effect.succeed(new TextDecoder().decode(source.bytes));
|
|
42
|
+
}).pipe(Effect.map((inspection) => ({
|
|
43
|
+
bundle: descriptor.bundle,
|
|
44
|
+
version: descriptor.version,
|
|
45
|
+
inspection,
|
|
46
|
+
sources: captured.sources.filter((source) => source.bundle === descriptor.bundle),
|
|
47
|
+
}))), { concurrency: 16 });
|
|
48
|
+
});
|
|
49
|
+
//# sourceMappingURL=knowledge-capture.js.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type ConceptRef, type ResolvedConceptRef } from "@agentxm/extension-model/unstable/knowledge/concept-ref";
|
|
2
|
+
import { type KnowledgeIndexSnapshot } from "./knowledge-index.js";
|
|
3
|
+
export type KnowledgeRelation = "outgoing" | "backlink";
|
|
4
|
+
export interface KnowledgeRelatedConcept {
|
|
5
|
+
readonly ref: ResolvedConceptRef;
|
|
6
|
+
readonly title?: string;
|
|
7
|
+
readonly relation: KnowledgeRelation;
|
|
8
|
+
readonly depth: number;
|
|
9
|
+
readonly via: ConceptRef;
|
|
10
|
+
readonly evidence: {
|
|
11
|
+
readonly source: ConceptRef;
|
|
12
|
+
readonly sourceRelativePath: string;
|
|
13
|
+
readonly line: number;
|
|
14
|
+
};
|
|
15
|
+
readonly orderingKey: string;
|
|
16
|
+
}
|
|
17
|
+
/** Traverse authored outgoing links and derived backlinks with cycle suppression. */
|
|
18
|
+
export declare const relatedKnowledgeConcepts: (snapshot: KnowledgeIndexSnapshot, start: ConceptRef, maximumDepth?: number, options?: {
|
|
19
|
+
readonly includeIndexBacklinks?: boolean;
|
|
20
|
+
}) => ReadonlyArray<KnowledgeRelatedConcept>;
|
|
21
|
+
export interface KnowledgeResolveCandidate {
|
|
22
|
+
readonly ref: ResolvedConceptRef;
|
|
23
|
+
readonly title?: string;
|
|
24
|
+
readonly reason: "exact-reference" | "exact-concept-id" | "exact-title" | "token-match";
|
|
25
|
+
readonly score: number;
|
|
26
|
+
readonly orderingKey: string;
|
|
27
|
+
}
|
|
28
|
+
export type KnowledgeResolveResult = {
|
|
29
|
+
readonly outcome: "resolved";
|
|
30
|
+
readonly candidate: KnowledgeResolveCandidate;
|
|
31
|
+
} | {
|
|
32
|
+
readonly outcome: "ambiguous";
|
|
33
|
+
readonly candidates: ReadonlyArray<KnowledgeResolveCandidate>;
|
|
34
|
+
} | {
|
|
35
|
+
readonly outcome: "not-found";
|
|
36
|
+
readonly candidates: ReadonlyArray<never>;
|
|
37
|
+
};
|
|
38
|
+
/** Resolve an exact concept ref or return a bounded deterministic fuzzy candidate set. */
|
|
39
|
+
export declare const resolveKnowledgeConcept: (snapshot: KnowledgeIndexSnapshot, input: string, maximumCandidates?: number, fuzzy?: boolean) => KnowledgeResolveResult;
|
|
40
|
+
//# sourceMappingURL=knowledge-graph.d.ts.map
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import * as Result from "effect/Result";
|
|
2
|
+
import { parseConceptRef, } from "@agentxm/extension-model/unstable/knowledge/concept-ref";
|
|
3
|
+
import { getKnowledgeIndexConcept, } from "./knowledge-index.js";
|
|
4
|
+
import { tokenizeKnowledgeSearchText } from "@agentxm/registry-protocol/unstable/knowledge/knowledge-search";
|
|
5
|
+
const compactKey = (ref) => `${ref.bundle}#${ref.conceptId}`;
|
|
6
|
+
/** Traverse authored outgoing links and derived backlinks with cycle suppression. */
|
|
7
|
+
export const relatedKnowledgeConcepts = (snapshot, start, maximumDepth = 1, options) => {
|
|
8
|
+
const root = getKnowledgeIndexConcept(snapshot, start.bundle, start.conceptId);
|
|
9
|
+
if (root === undefined)
|
|
10
|
+
return [];
|
|
11
|
+
const depthLimit = Math.max(1, Math.min(3, maximumDepth));
|
|
12
|
+
const visited = new Set([compactKey(start)]);
|
|
13
|
+
const queue = [{ concept: root, depth: 0 }];
|
|
14
|
+
const results = [];
|
|
15
|
+
while (queue.length > 0) {
|
|
16
|
+
const current = queue.shift();
|
|
17
|
+
if (current === undefined || current.depth >= depthLimit)
|
|
18
|
+
continue;
|
|
19
|
+
const neighbors = [
|
|
20
|
+
...current.concept.projected.outgoingLinks.flatMap((link) => link.resolvedConceptId === undefined
|
|
21
|
+
? []
|
|
22
|
+
: [
|
|
23
|
+
{
|
|
24
|
+
relation: "outgoing",
|
|
25
|
+
conceptId: link.resolvedConceptId,
|
|
26
|
+
evidence: {
|
|
27
|
+
source: {
|
|
28
|
+
bundle: current.concept.ref.bundle,
|
|
29
|
+
conceptId: current.concept.ref.conceptId,
|
|
30
|
+
},
|
|
31
|
+
sourceRelativePath: current.concept.projected.relativePath,
|
|
32
|
+
line: link.line,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
]),
|
|
36
|
+
...current.concept.projected.backlinks.flatMap((link) => {
|
|
37
|
+
const source = getKnowledgeIndexConcept(snapshot, current.concept.ref.bundle, link.sourceConceptId);
|
|
38
|
+
if (source === undefined)
|
|
39
|
+
return [];
|
|
40
|
+
if (source.projected.kind === "index" && options?.includeIndexBacklinks !== true)
|
|
41
|
+
return [];
|
|
42
|
+
return [
|
|
43
|
+
{
|
|
44
|
+
relation: "backlink",
|
|
45
|
+
conceptId: link.sourceConceptId,
|
|
46
|
+
evidence: {
|
|
47
|
+
source: { bundle: source.ref.bundle, conceptId: source.ref.conceptId },
|
|
48
|
+
sourceRelativePath: link.sourceRelativePath,
|
|
49
|
+
line: link.line,
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
];
|
|
53
|
+
}),
|
|
54
|
+
].sort((left, right) => left.conceptId.localeCompare(right.conceptId) ||
|
|
55
|
+
left.relation.localeCompare(right.relation));
|
|
56
|
+
for (const neighbor of neighbors) {
|
|
57
|
+
const indexed = getKnowledgeIndexConcept(snapshot, current.concept.ref.bundle, neighbor.conceptId);
|
|
58
|
+
if (indexed === undefined)
|
|
59
|
+
continue;
|
|
60
|
+
const key = compactKey(indexed.ref);
|
|
61
|
+
if (visited.has(key))
|
|
62
|
+
continue;
|
|
63
|
+
visited.add(key);
|
|
64
|
+
const depth = current.depth + 1;
|
|
65
|
+
results.push({
|
|
66
|
+
ref: indexed.ref,
|
|
67
|
+
...(indexed.projected.title === undefined ? {} : { title: indexed.projected.title }),
|
|
68
|
+
relation: neighbor.relation,
|
|
69
|
+
depth,
|
|
70
|
+
via: {
|
|
71
|
+
bundle: current.concept.ref.bundle,
|
|
72
|
+
conceptId: current.concept.ref.conceptId,
|
|
73
|
+
},
|
|
74
|
+
evidence: neighbor.evidence,
|
|
75
|
+
orderingKey: `${String(depth).padStart(2, "0")}:${key}:${neighbor.relation}`,
|
|
76
|
+
});
|
|
77
|
+
queue.push({ concept: indexed, depth });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return results.sort((left, right) => left.orderingKey.localeCompare(right.orderingKey));
|
|
81
|
+
};
|
|
82
|
+
const normalized = (value) => value.normalize("NFKC").toUpperCase().toLowerCase();
|
|
83
|
+
const candidate = (concept, reason, score) => ({
|
|
84
|
+
ref: concept.ref,
|
|
85
|
+
...(concept.projected.title === undefined ? {} : { title: concept.projected.title }),
|
|
86
|
+
reason,
|
|
87
|
+
score,
|
|
88
|
+
orderingKey: `${concept.ref.bundle}#${concept.ref.conceptId}`,
|
|
89
|
+
});
|
|
90
|
+
/** Resolve an exact concept ref or return a bounded deterministic fuzzy candidate set. */
|
|
91
|
+
export const resolveKnowledgeConcept = (snapshot, input, maximumCandidates = 10, fuzzy = false) => {
|
|
92
|
+
const parsed = parseConceptRef(input);
|
|
93
|
+
if (Result.isSuccess(parsed)) {
|
|
94
|
+
const exact = getKnowledgeIndexConcept(snapshot, parsed.success.bundle, parsed.success.conceptId);
|
|
95
|
+
return exact === undefined
|
|
96
|
+
? { outcome: "not-found", candidates: [] }
|
|
97
|
+
: { outcome: "resolved", candidate: candidate(exact, "exact-reference", 100) };
|
|
98
|
+
}
|
|
99
|
+
if (!fuzzy)
|
|
100
|
+
return { outcome: "not-found", candidates: [] };
|
|
101
|
+
const expected = normalized(input);
|
|
102
|
+
const queryTokens = tokenizeKnowledgeSearchText(input);
|
|
103
|
+
const candidates = snapshot.concepts
|
|
104
|
+
.flatMap((concept) => {
|
|
105
|
+
if (normalized(concept.ref.conceptId) === expected) {
|
|
106
|
+
return [candidate(concept, "exact-concept-id", 80)];
|
|
107
|
+
}
|
|
108
|
+
if (concept.projected.title !== undefined &&
|
|
109
|
+
normalized(concept.projected.title) === expected) {
|
|
110
|
+
return [candidate(concept, "exact-title", 60)];
|
|
111
|
+
}
|
|
112
|
+
const candidateTokens = tokenizeKnowledgeSearchText(`${concept.ref.conceptId} ${concept.projected.title ?? ""}`);
|
|
113
|
+
if (queryTokens.length > 0 && queryTokens.every((token) => candidateTokens.includes(token))) {
|
|
114
|
+
return [candidate(concept, "token-match", 20 + queryTokens.length)];
|
|
115
|
+
}
|
|
116
|
+
return [];
|
|
117
|
+
})
|
|
118
|
+
.sort((left, right) => right.score - left.score || left.orderingKey.localeCompare(right.orderingKey))
|
|
119
|
+
.slice(0, Math.max(1, Math.min(10, maximumCandidates)));
|
|
120
|
+
if (candidates.length === 0)
|
|
121
|
+
return { outcome: "not-found", candidates: [] };
|
|
122
|
+
if (candidates.length === 1) {
|
|
123
|
+
const first = candidates[0];
|
|
124
|
+
return first === undefined
|
|
125
|
+
? { outcome: "not-found", candidates: [] }
|
|
126
|
+
: { outcome: "resolved", candidate: first };
|
|
127
|
+
}
|
|
128
|
+
return { outcome: "ambiguous", candidates };
|
|
129
|
+
};
|
|
130
|
+
//# sourceMappingURL=knowledge-graph.js.map
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as Result from "effect/Result";
|
|
3
|
+
import * as ServiceMap from "effect/Context";
|
|
4
|
+
import { type KnowledgeBundleFqn, type KnowledgeRevision, type ResolvedConceptRef } from "@agentxm/extension-model/unstable/knowledge/concept-ref";
|
|
5
|
+
import { type KnowledgeBodyPassage, type KnowledgeProjectedConcept, type KnowledgeSearchableField } from "./knowledge-projection.js";
|
|
6
|
+
import { type KnowledgeQuery } from "./knowledge-query.js";
|
|
7
|
+
import { type CapturedKnowledgeSource } from "./knowledge-revision.js";
|
|
8
|
+
import type { KnowledgeConcept, KnowledgeInspection } from "@agentxm/registry-protocol/unstable/knowledge/okf";
|
|
9
|
+
export interface KnowledgeIndexBundleInput {
|
|
10
|
+
readonly bundle: KnowledgeBundleFqn;
|
|
11
|
+
readonly version: string;
|
|
12
|
+
readonly inspection: KnowledgeInspection;
|
|
13
|
+
readonly sources: ReadonlyArray<CapturedKnowledgeSource>;
|
|
14
|
+
}
|
|
15
|
+
export interface KnowledgeIndexedConcept {
|
|
16
|
+
readonly ref: ResolvedConceptRef;
|
|
17
|
+
readonly projectionRevision: KnowledgeRevision;
|
|
18
|
+
readonly projected: KnowledgeProjectedConcept;
|
|
19
|
+
readonly source: KnowledgeConcept;
|
|
20
|
+
readonly sourceBytes: Uint8Array;
|
|
21
|
+
}
|
|
22
|
+
export interface KnowledgeIndexSnapshot {
|
|
23
|
+
readonly fingerprint: KnowledgeRevision;
|
|
24
|
+
readonly concepts: ReadonlyArray<KnowledgeIndexedConcept>;
|
|
25
|
+
}
|
|
26
|
+
export interface KnowledgeMatchSpan {
|
|
27
|
+
readonly clauseIndex: number;
|
|
28
|
+
readonly field: KnowledgeSearchableField;
|
|
29
|
+
readonly start: number;
|
|
30
|
+
readonly end: number;
|
|
31
|
+
}
|
|
32
|
+
export interface KnowledgeResultPassage extends KnowledgeBodyPassage {
|
|
33
|
+
readonly spans: ReadonlyArray<KnowledgeMatchSpan>;
|
|
34
|
+
}
|
|
35
|
+
export interface KnowledgeConceptResult {
|
|
36
|
+
readonly ref: ResolvedConceptRef;
|
|
37
|
+
readonly orderingKey: string;
|
|
38
|
+
readonly matchedFields: ReadonlyArray<KnowledgeSearchableField>;
|
|
39
|
+
readonly passages: ReadonlyArray<KnowledgeResultPassage>;
|
|
40
|
+
readonly kind: KnowledgeProjectedConcept["kind"];
|
|
41
|
+
readonly title?: string;
|
|
42
|
+
readonly description?: string;
|
|
43
|
+
readonly status?: string;
|
|
44
|
+
readonly staleAfter?: string;
|
|
45
|
+
readonly generated?: KnowledgeProjectedConcept["generated"];
|
|
46
|
+
readonly verified?: KnowledgeProjectedConcept["verified"];
|
|
47
|
+
readonly trust?: KnowledgeProjectedConcept["trust"];
|
|
48
|
+
readonly relativePath: string;
|
|
49
|
+
}
|
|
50
|
+
export interface KnowledgeQueryPage {
|
|
51
|
+
readonly items: ReadonlyArray<KnowledgeConceptResult>;
|
|
52
|
+
readonly count: number;
|
|
53
|
+
readonly hasMore: boolean;
|
|
54
|
+
readonly cursor?: string;
|
|
55
|
+
}
|
|
56
|
+
export type KnowledgeCursorInvalidReason = "invalid" | "expired" | "corpus-changed" | "query-changed";
|
|
57
|
+
declare const KnowledgeCursorInvalidError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
58
|
+
readonly _tag: "KnowledgeCursorInvalidError";
|
|
59
|
+
} & Readonly<A>;
|
|
60
|
+
export declare class KnowledgeCursorInvalidError extends KnowledgeCursorInvalidError_base<{
|
|
61
|
+
readonly reason: KnowledgeCursorInvalidReason;
|
|
62
|
+
}> {
|
|
63
|
+
}
|
|
64
|
+
export declare const makeKnowledgeIndexSnapshot: (bundles: ReadonlyArray<KnowledgeIndexBundleInput>) => KnowledgeIndexSnapshot;
|
|
65
|
+
export declare const queryKnowledgeIndexResult: (snapshot: KnowledgeIndexSnapshot, query: KnowledgeQuery, now: number) => Result.Result<KnowledgeQueryPage, KnowledgeCursorInvalidError>;
|
|
66
|
+
export declare const queryKnowledgeIndex: (snapshot: KnowledgeIndexSnapshot, query: KnowledgeQuery, now: number) => KnowledgeQueryPage;
|
|
67
|
+
export declare const getKnowledgeIndexConcept: (snapshot: KnowledgeIndexSnapshot, bundle: string, conceptId: string) => KnowledgeIndexedConcept | undefined;
|
|
68
|
+
export interface KnowledgeIndexService {
|
|
69
|
+
readonly makeSnapshot: (bundles: ReadonlyArray<KnowledgeIndexBundleInput>) => Effect.Effect<KnowledgeIndexSnapshot>;
|
|
70
|
+
readonly query: (snapshot: KnowledgeIndexSnapshot, query: KnowledgeQuery) => Effect.Effect<KnowledgeQueryPage, KnowledgeCursorInvalidError>;
|
|
71
|
+
}
|
|
72
|
+
declare const KnowledgeIndex_base: ServiceMap.ServiceClass<KnowledgeIndex, "@agentxm/knowledge-query/knowledge-index/KnowledgeIndex", KnowledgeIndexService>;
|
|
73
|
+
export declare class KnowledgeIndex extends KnowledgeIndex_base {
|
|
74
|
+
}
|
|
75
|
+
export {};
|
|
76
|
+
//# sourceMappingURL=knowledge-index.d.ts.map
|