@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
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import * as Schema from "effect/Schema";
|
|
2
|
+
import { WORKSPACE_SCOPES } from "@agentxm/extension-model/unstable/workspace-scope";
|
|
3
|
+
export declare const KNOWLEDGE_QUERY_CONTRACT_VERSION = "axm-knowledge-query-v1";
|
|
4
|
+
export declare const KNOWLEDGE_DISCOVERY_OPERATIONS: readonly ["resolve", "search", "query", "get", "related", "status"];
|
|
5
|
+
export declare const KNOWLEDGE_QUERY_OPERATORS: readonly ["term", "phrase", "literal", "equals", "not-equals", "contains"];
|
|
6
|
+
export declare const KNOWLEDGE_SEARCHABLE_FIELDS: readonly ["bundle", "conceptId", "title", "description", "tag", "type", "body", "resource", "status", "staleAfter", "generated", "verified", "trust"];
|
|
7
|
+
export declare const KNOWLEDGE_METADATA_FILTER_FIELDS: readonly ["bundle", "conceptId", "kind", "title", "description", "tag", "type", "resource"];
|
|
8
|
+
export declare const KNOWLEDGE_LIFECYCLE_FILTER_FIELDS: readonly ["status", "staleAfter", "generated", "verified", "trust"];
|
|
9
|
+
export declare const KnowledgeTextClauseSchema: Schema.Union<readonly [Schema.Struct<{
|
|
10
|
+
readonly kind: Schema.Literal<"term">;
|
|
11
|
+
readonly value: Schema.NonEmptyString;
|
|
12
|
+
}>, Schema.Struct<{
|
|
13
|
+
readonly kind: Schema.Literal<"phrase">;
|
|
14
|
+
readonly value: Schema.NonEmptyString;
|
|
15
|
+
}>, Schema.Struct<{
|
|
16
|
+
readonly kind: Schema.Literal<"literal">;
|
|
17
|
+
readonly value: Schema.NonEmptyString;
|
|
18
|
+
}>]>;
|
|
19
|
+
export type KnowledgeTextClause = typeof KnowledgeTextClauseSchema.Type;
|
|
20
|
+
export declare const KnowledgeQueryClauseSchema: Schema.Union<readonly [Schema.Union<readonly [Schema.Struct<{
|
|
21
|
+
readonly kind: Schema.Literal<"term">;
|
|
22
|
+
readonly value: Schema.NonEmptyString;
|
|
23
|
+
}>, Schema.Struct<{
|
|
24
|
+
readonly kind: Schema.Literal<"phrase">;
|
|
25
|
+
readonly value: Schema.NonEmptyString;
|
|
26
|
+
}>, Schema.Struct<{
|
|
27
|
+
readonly kind: Schema.Literal<"literal">;
|
|
28
|
+
readonly value: Schema.NonEmptyString;
|
|
29
|
+
}>]>, Schema.Struct<{
|
|
30
|
+
readonly kind: Schema.Literal<"field">;
|
|
31
|
+
readonly field: Schema.Literals<readonly ["bundle", "conceptId", "title", "description", "tag", "type", "body", "resource", "status", "staleAfter", "generated", "verified", "trust"]>;
|
|
32
|
+
readonly clause: Schema.Union<readonly [Schema.Struct<{
|
|
33
|
+
readonly kind: Schema.Literal<"term">;
|
|
34
|
+
readonly value: Schema.NonEmptyString;
|
|
35
|
+
}>, Schema.Struct<{
|
|
36
|
+
readonly kind: Schema.Literal<"phrase">;
|
|
37
|
+
readonly value: Schema.NonEmptyString;
|
|
38
|
+
}>, Schema.Struct<{
|
|
39
|
+
readonly kind: Schema.Literal<"literal">;
|
|
40
|
+
readonly value: Schema.NonEmptyString;
|
|
41
|
+
}>]>;
|
|
42
|
+
}>, Schema.Struct<{
|
|
43
|
+
readonly kind: Schema.Literal<"metadata">;
|
|
44
|
+
readonly field: Schema.Literals<readonly ["bundle", "conceptId", "kind", "title", "description", "tag", "type", "resource"]>;
|
|
45
|
+
readonly operator: Schema.Literals<readonly ["equals", "not-equals", "contains"]>;
|
|
46
|
+
readonly value: Schema.NonEmptyString;
|
|
47
|
+
}>, Schema.Struct<{
|
|
48
|
+
readonly kind: Schema.Literal<"lifecycle">;
|
|
49
|
+
readonly field: Schema.Literals<readonly ["status", "staleAfter", "generated", "verified", "trust"]>;
|
|
50
|
+
readonly operator: Schema.Literals<readonly ["equals", "not-equals"]>;
|
|
51
|
+
readonly value: Schema.NonEmptyString;
|
|
52
|
+
}>, Schema.Struct<{
|
|
53
|
+
readonly kind: Schema.Literal<"property">;
|
|
54
|
+
readonly pointer: Schema.NonEmptyString;
|
|
55
|
+
readonly operator: Schema.Literals<readonly ["equals", "not-equals", "contains"]>;
|
|
56
|
+
readonly value: Schema.NonEmptyString;
|
|
57
|
+
}>]>;
|
|
58
|
+
export type KnowledgeQueryClause = typeof KnowledgeQueryClauseSchema.Type;
|
|
59
|
+
export declare const KnowledgeQuerySchema: Schema.Struct<{
|
|
60
|
+
readonly version: Schema.Literal<"axm-knowledge-query-v1">;
|
|
61
|
+
readonly scope: Schema.Literals<readonly ["project", "user"]>;
|
|
62
|
+
readonly clauses: Schema.$Array<Schema.Union<readonly [Schema.Union<readonly [Schema.Struct<{
|
|
63
|
+
readonly kind: Schema.Literal<"term">;
|
|
64
|
+
readonly value: Schema.NonEmptyString;
|
|
65
|
+
}>, Schema.Struct<{
|
|
66
|
+
readonly kind: Schema.Literal<"phrase">;
|
|
67
|
+
readonly value: Schema.NonEmptyString;
|
|
68
|
+
}>, Schema.Struct<{
|
|
69
|
+
readonly kind: Schema.Literal<"literal">;
|
|
70
|
+
readonly value: Schema.NonEmptyString;
|
|
71
|
+
}>]>, Schema.Struct<{
|
|
72
|
+
readonly kind: Schema.Literal<"field">;
|
|
73
|
+
readonly field: Schema.Literals<readonly ["bundle", "conceptId", "title", "description", "tag", "type", "body", "resource", "status", "staleAfter", "generated", "verified", "trust"]>;
|
|
74
|
+
readonly clause: Schema.Union<readonly [Schema.Struct<{
|
|
75
|
+
readonly kind: Schema.Literal<"term">;
|
|
76
|
+
readonly value: Schema.NonEmptyString;
|
|
77
|
+
}>, Schema.Struct<{
|
|
78
|
+
readonly kind: Schema.Literal<"phrase">;
|
|
79
|
+
readonly value: Schema.NonEmptyString;
|
|
80
|
+
}>, Schema.Struct<{
|
|
81
|
+
readonly kind: Schema.Literal<"literal">;
|
|
82
|
+
readonly value: Schema.NonEmptyString;
|
|
83
|
+
}>]>;
|
|
84
|
+
}>, Schema.Struct<{
|
|
85
|
+
readonly kind: Schema.Literal<"metadata">;
|
|
86
|
+
readonly field: Schema.Literals<readonly ["bundle", "conceptId", "kind", "title", "description", "tag", "type", "resource"]>;
|
|
87
|
+
readonly operator: Schema.Literals<readonly ["equals", "not-equals", "contains"]>;
|
|
88
|
+
readonly value: Schema.NonEmptyString;
|
|
89
|
+
}>, Schema.Struct<{
|
|
90
|
+
readonly kind: Schema.Literal<"lifecycle">;
|
|
91
|
+
readonly field: Schema.Literals<readonly ["status", "staleAfter", "generated", "verified", "trust"]>;
|
|
92
|
+
readonly operator: Schema.Literals<readonly ["equals", "not-equals"]>;
|
|
93
|
+
readonly value: Schema.NonEmptyString;
|
|
94
|
+
}>, Schema.Struct<{
|
|
95
|
+
readonly kind: Schema.Literal<"property">;
|
|
96
|
+
readonly pointer: Schema.NonEmptyString;
|
|
97
|
+
readonly operator: Schema.Literals<readonly ["equals", "not-equals", "contains"]>;
|
|
98
|
+
readonly value: Schema.NonEmptyString;
|
|
99
|
+
}>]>>;
|
|
100
|
+
readonly ordering: Schema.Literals<readonly ["relevance", "metadata"]>;
|
|
101
|
+
readonly resultLimit: Schema.Number;
|
|
102
|
+
readonly passageLimit: Schema.Number;
|
|
103
|
+
readonly passageLength: Schema.Number;
|
|
104
|
+
readonly cursor: Schema.optional<Schema.NonEmptyString>;
|
|
105
|
+
}>;
|
|
106
|
+
export type KnowledgeQuery = typeof KnowledgeQuerySchema.Type;
|
|
107
|
+
export declare const makeKnowledgeQuery: (scope: (typeof WORKSPACE_SCOPES)[number], clauses: ReadonlyArray<KnowledgeQueryClause>, options?: {
|
|
108
|
+
readonly ordering?: "relevance" | "metadata";
|
|
109
|
+
readonly resultLimit?: number;
|
|
110
|
+
readonly passageLimit?: number;
|
|
111
|
+
readonly passageLength?: number;
|
|
112
|
+
readonly cursor?: string;
|
|
113
|
+
}) => KnowledgeQuery;
|
|
114
|
+
/** The cursor and bounds do not change which candidates a canonical query denotes. */
|
|
115
|
+
export declare const knowledgeQueryIdentity: (query: KnowledgeQuery) => unknown;
|
|
116
|
+
//# sourceMappingURL=knowledge-query.d.ts.map
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import * as Schema from "effect/Schema";
|
|
2
|
+
import { WORKSPACE_SCOPES } from "@agentxm/extension-model/unstable/workspace-scope";
|
|
3
|
+
export const KNOWLEDGE_QUERY_CONTRACT_VERSION = "axm-knowledge-query-v1";
|
|
4
|
+
export const KNOWLEDGE_DISCOVERY_OPERATIONS = [
|
|
5
|
+
"resolve",
|
|
6
|
+
"search",
|
|
7
|
+
"query",
|
|
8
|
+
"get",
|
|
9
|
+
"related",
|
|
10
|
+
"status",
|
|
11
|
+
];
|
|
12
|
+
export const KNOWLEDGE_QUERY_OPERATORS = [
|
|
13
|
+
"term",
|
|
14
|
+
"phrase",
|
|
15
|
+
"literal",
|
|
16
|
+
"equals",
|
|
17
|
+
"not-equals",
|
|
18
|
+
"contains",
|
|
19
|
+
];
|
|
20
|
+
export const KNOWLEDGE_SEARCHABLE_FIELDS = [
|
|
21
|
+
"bundle",
|
|
22
|
+
"conceptId",
|
|
23
|
+
"title",
|
|
24
|
+
"description",
|
|
25
|
+
"tag",
|
|
26
|
+
"type",
|
|
27
|
+
"body",
|
|
28
|
+
"resource",
|
|
29
|
+
"status",
|
|
30
|
+
"staleAfter",
|
|
31
|
+
"generated",
|
|
32
|
+
"verified",
|
|
33
|
+
"trust",
|
|
34
|
+
];
|
|
35
|
+
export const KNOWLEDGE_METADATA_FILTER_FIELDS = [
|
|
36
|
+
"bundle",
|
|
37
|
+
"conceptId",
|
|
38
|
+
"kind",
|
|
39
|
+
"title",
|
|
40
|
+
"description",
|
|
41
|
+
"tag",
|
|
42
|
+
"type",
|
|
43
|
+
"resource",
|
|
44
|
+
];
|
|
45
|
+
export const KNOWLEDGE_LIFECYCLE_FILTER_FIELDS = [
|
|
46
|
+
"status",
|
|
47
|
+
"staleAfter",
|
|
48
|
+
"generated",
|
|
49
|
+
"verified",
|
|
50
|
+
"trust",
|
|
51
|
+
];
|
|
52
|
+
const nonEmptyValue = Schema.NonEmptyString.annotate({
|
|
53
|
+
description: "A non-empty decoded query value.",
|
|
54
|
+
});
|
|
55
|
+
export const KnowledgeTextClauseSchema = Schema.Union([
|
|
56
|
+
Schema.Struct({ kind: Schema.Literal("term"), value: nonEmptyValue }),
|
|
57
|
+
Schema.Struct({ kind: Schema.Literal("phrase"), value: nonEmptyValue }),
|
|
58
|
+
Schema.Struct({ kind: Schema.Literal("literal"), value: nonEmptyValue }),
|
|
59
|
+
]).annotate({ identifier: "KnowledgeTextClause" });
|
|
60
|
+
export const KnowledgeQueryClauseSchema = Schema.Union([
|
|
61
|
+
KnowledgeTextClauseSchema,
|
|
62
|
+
Schema.Struct({
|
|
63
|
+
kind: Schema.Literal("field"),
|
|
64
|
+
field: Schema.Literals(KNOWLEDGE_SEARCHABLE_FIELDS),
|
|
65
|
+
clause: KnowledgeTextClauseSchema,
|
|
66
|
+
}),
|
|
67
|
+
Schema.Struct({
|
|
68
|
+
kind: Schema.Literal("metadata"),
|
|
69
|
+
field: Schema.Literals(KNOWLEDGE_METADATA_FILTER_FIELDS),
|
|
70
|
+
operator: Schema.Literals(["equals", "not-equals", "contains"]),
|
|
71
|
+
value: nonEmptyValue,
|
|
72
|
+
}),
|
|
73
|
+
Schema.Struct({
|
|
74
|
+
kind: Schema.Literal("lifecycle"),
|
|
75
|
+
field: Schema.Literals(KNOWLEDGE_LIFECYCLE_FILTER_FIELDS),
|
|
76
|
+
operator: Schema.Literals(["equals", "not-equals"]),
|
|
77
|
+
value: nonEmptyValue,
|
|
78
|
+
}),
|
|
79
|
+
Schema.Struct({
|
|
80
|
+
kind: Schema.Literal("property"),
|
|
81
|
+
pointer: Schema.NonEmptyString.check(Schema.makeFilter((value) => value.startsWith("/") ? undefined : "Expected an RFC 6901 JSON Pointer")),
|
|
82
|
+
operator: Schema.Literals(["equals", "not-equals", "contains"]),
|
|
83
|
+
value: nonEmptyValue,
|
|
84
|
+
}),
|
|
85
|
+
]).annotate({ identifier: "KnowledgeQueryClause" });
|
|
86
|
+
export const KnowledgeQuerySchema = Schema.Struct({
|
|
87
|
+
version: Schema.Literal(KNOWLEDGE_QUERY_CONTRACT_VERSION),
|
|
88
|
+
scope: Schema.Literals(WORKSPACE_SCOPES),
|
|
89
|
+
clauses: Schema.Array(KnowledgeQueryClauseSchema),
|
|
90
|
+
ordering: Schema.Literals(["relevance", "metadata"]),
|
|
91
|
+
resultLimit: Schema.Number.check(Schema.isInt(), Schema.isBetween({ minimum: 1, maximum: 100 })),
|
|
92
|
+
passageLimit: Schema.Number.check(Schema.isInt(), Schema.isBetween({ minimum: 0, maximum: 10 })),
|
|
93
|
+
passageLength: Schema.Number.check(Schema.isInt(), Schema.isBetween({ minimum: 1, maximum: 2_000 })),
|
|
94
|
+
cursor: Schema.optional(Schema.NonEmptyString),
|
|
95
|
+
}).annotate({
|
|
96
|
+
identifier: "KnowledgeQuery",
|
|
97
|
+
title: "Knowledge Query",
|
|
98
|
+
description: "Canonical, serializable Knowledge discovery query model.",
|
|
99
|
+
});
|
|
100
|
+
export const makeKnowledgeQuery = (scope, clauses, options) => ({
|
|
101
|
+
version: KNOWLEDGE_QUERY_CONTRACT_VERSION,
|
|
102
|
+
scope,
|
|
103
|
+
clauses,
|
|
104
|
+
ordering: options?.ordering ?? (clauses.length === 0 ? "metadata" : "relevance"),
|
|
105
|
+
resultLimit: options?.resultLimit ?? 25,
|
|
106
|
+
passageLimit: options?.passageLimit ?? 3,
|
|
107
|
+
passageLength: options?.passageLength ?? 500,
|
|
108
|
+
...(options?.cursor === undefined ? {} : { cursor: options.cursor }),
|
|
109
|
+
});
|
|
110
|
+
/** The cursor and bounds do not change which candidates a canonical query denotes. */
|
|
111
|
+
export const knowledgeQueryIdentity = (query) => ({
|
|
112
|
+
version: query.version,
|
|
113
|
+
scope: query.scope,
|
|
114
|
+
clauses: query.clauses,
|
|
115
|
+
ordering: query.ordering,
|
|
116
|
+
});
|
|
117
|
+
//# sourceMappingURL=knowledge-query.js.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import type { KnowledgeProjectedConcept } from "./knowledge-projection.js";
|
|
3
|
+
import { type KnowledgeRevision } from "@agentxm/extension-model/unstable/knowledge/concept-ref";
|
|
4
|
+
export interface KnowledgeCorpusSource {
|
|
5
|
+
readonly bundle: string;
|
|
6
|
+
readonly relativePath: string;
|
|
7
|
+
/** Filesystem observation metadata is explicitly excluded from the fingerprint. */
|
|
8
|
+
readonly modifiedAt?: number;
|
|
9
|
+
}
|
|
10
|
+
export interface CapturedKnowledgeSource extends KnowledgeCorpusSource {
|
|
11
|
+
readonly bytes: Uint8Array;
|
|
12
|
+
readonly sourceRevision: KnowledgeRevision;
|
|
13
|
+
}
|
|
14
|
+
export interface CapturedKnowledgeCorpus {
|
|
15
|
+
readonly fingerprint: KnowledgeRevision;
|
|
16
|
+
readonly sources: ReadonlyArray<CapturedKnowledgeSource>;
|
|
17
|
+
}
|
|
18
|
+
declare const KnowledgeCorpusChangingError_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 & {
|
|
19
|
+
readonly _tag: "KnowledgeCorpusChangingError";
|
|
20
|
+
} & Readonly<A>;
|
|
21
|
+
export declare class KnowledgeCorpusChangingError extends KnowledgeCorpusChangingError_base<{
|
|
22
|
+
readonly attempts: number;
|
|
23
|
+
}> {
|
|
24
|
+
}
|
|
25
|
+
export declare const computeKnowledgeSourceRevision: (bytes: Uint8Array) => KnowledgeRevision;
|
|
26
|
+
export declare const computeKnowledgeCorpusFingerprint: (sources: ReadonlyArray<CapturedKnowledgeSource>) => KnowledgeRevision;
|
|
27
|
+
export declare const computeKnowledgeProjectionRevision: (concept: KnowledgeProjectedConcept) => KnowledgeRevision;
|
|
28
|
+
/**
|
|
29
|
+
* Capture one internally consistent corpus. Every source is read twice; a
|
|
30
|
+
* changing source retries the complete capture and never yields a mixed view.
|
|
31
|
+
*/
|
|
32
|
+
export declare const captureKnowledgeCorpus: <E>(sources: ReadonlyArray<KnowledgeCorpusSource>, readSource: (source: KnowledgeCorpusSource) => Effect.Effect<Uint8Array, E>, options?: {
|
|
33
|
+
readonly maxAttempts?: number;
|
|
34
|
+
}) => Effect.Effect<CapturedKnowledgeCorpus, E | KnowledgeCorpusChangingError>;
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=knowledge-revision.d.ts.map
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import * as Data from "effect/Data";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as Schema from "effect/Schema";
|
|
5
|
+
import { KnowledgeRevisionSchema, } from "@agentxm/extension-model/unstable/knowledge/concept-ref";
|
|
6
|
+
export class KnowledgeCorpusChangingError extends Data.TaggedError("KnowledgeCorpusChangingError") {
|
|
7
|
+
}
|
|
8
|
+
const decodeRevision = Schema.decodeUnknownSync(KnowledgeRevisionSchema);
|
|
9
|
+
const revision = (domain, parts) => {
|
|
10
|
+
const hash = createHash("sha256");
|
|
11
|
+
const update = (part) => {
|
|
12
|
+
const bytes = typeof part === "string" ? new TextEncoder().encode(part) : part;
|
|
13
|
+
hash.update(String(bytes.byteLength));
|
|
14
|
+
hash.update(":");
|
|
15
|
+
hash.update(bytes);
|
|
16
|
+
hash.update(";");
|
|
17
|
+
};
|
|
18
|
+
update(domain);
|
|
19
|
+
for (const part of parts)
|
|
20
|
+
update(part);
|
|
21
|
+
return decodeRevision(`sha256:${hash.digest("hex")}`);
|
|
22
|
+
};
|
|
23
|
+
const normalizedRelativePath = (value) => value
|
|
24
|
+
.replace(/\\/gu, "/")
|
|
25
|
+
.split("/")
|
|
26
|
+
.filter((segment) => segment.length > 0 && segment !== ".")
|
|
27
|
+
.join("/");
|
|
28
|
+
const compareSource = (left, right) => left.bundle.localeCompare(right.bundle) ||
|
|
29
|
+
normalizedRelativePath(left.relativePath).localeCompare(normalizedRelativePath(right.relativePath));
|
|
30
|
+
export const computeKnowledgeSourceRevision = (bytes) => revision("axm-knowledge-source-revision-v1", [bytes]);
|
|
31
|
+
export const computeKnowledgeCorpusFingerprint = (sources) => {
|
|
32
|
+
const parts = [];
|
|
33
|
+
for (const source of [...sources].sort(compareSource)) {
|
|
34
|
+
parts.push(source.bundle, normalizedRelativePath(source.relativePath), source.bytes);
|
|
35
|
+
}
|
|
36
|
+
return revision("axm-knowledge-corpus-fingerprint-v1", parts);
|
|
37
|
+
};
|
|
38
|
+
const canonicalValue = (value, seen = new Map()) => {
|
|
39
|
+
if (value === null)
|
|
40
|
+
return "null";
|
|
41
|
+
switch (typeof value) {
|
|
42
|
+
case "string":
|
|
43
|
+
return `string:${value.length}:${value}`;
|
|
44
|
+
case "number":
|
|
45
|
+
return `number:${Object.is(value, -0) ? "-0" : String(value)}`;
|
|
46
|
+
case "boolean":
|
|
47
|
+
return value ? "boolean:true" : "boolean:false";
|
|
48
|
+
case "undefined":
|
|
49
|
+
return "undefined";
|
|
50
|
+
case "bigint":
|
|
51
|
+
return `bigint:${String(value)}`;
|
|
52
|
+
case "object":
|
|
53
|
+
if (value instanceof Uint8Array) {
|
|
54
|
+
return `bytes:${value.byteLength}:${Buffer.from(value).toString("base64")}`;
|
|
55
|
+
}
|
|
56
|
+
if (seen.has(value))
|
|
57
|
+
return `reference:${seen.get(value)}`;
|
|
58
|
+
seen.set(value, seen.size);
|
|
59
|
+
if (Array.isArray(value)) {
|
|
60
|
+
return `array:[${value.map((entry) => canonicalValue(entry, seen)).join(",")}]`;
|
|
61
|
+
}
|
|
62
|
+
return `object:{${Object.entries(value)
|
|
63
|
+
.sort(([left], [right]) => left.localeCompare(right))
|
|
64
|
+
.map(([key, entry]) => `${canonicalValue(key, seen)}=${canonicalValue(entry, seen)}`)
|
|
65
|
+
.join(",")}}`;
|
|
66
|
+
default:
|
|
67
|
+
return `${typeof value}:${String(value)}`;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
export const computeKnowledgeProjectionRevision = (concept) => revision("axm-knowledge-projection-revision-v1", [canonicalValue(concept)]);
|
|
71
|
+
const equalBytes = (left, right) => left.byteLength === right.byteLength && left.every((byte, index) => right[index] === byte);
|
|
72
|
+
const captureOnce = (sources, readSource) => Effect.forEach([...sources].sort(compareSource), (source) => readSource(source).pipe(Effect.map((bytes) => ({
|
|
73
|
+
...source,
|
|
74
|
+
relativePath: normalizedRelativePath(source.relativePath),
|
|
75
|
+
bytes,
|
|
76
|
+
sourceRevision: computeKnowledgeSourceRevision(bytes),
|
|
77
|
+
}))), { concurrency: 16 });
|
|
78
|
+
/**
|
|
79
|
+
* Capture one internally consistent corpus. Every source is read twice; a
|
|
80
|
+
* changing source retries the complete capture and never yields a mixed view.
|
|
81
|
+
*/
|
|
82
|
+
export const captureKnowledgeCorpus = (sources, readSource, options) => Effect.gen(function* () {
|
|
83
|
+
const maxAttempts = Math.max(1, options?.maxAttempts ?? 3);
|
|
84
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {
|
|
85
|
+
const captured = yield* captureOnce(sources, readSource);
|
|
86
|
+
const confirmed = yield* captureOnce(sources, readSource);
|
|
87
|
+
if (captured.length === confirmed.length &&
|
|
88
|
+
captured.every((source, index) => source.bundle === confirmed[index]?.bundle &&
|
|
89
|
+
source.relativePath === confirmed[index]?.relativePath &&
|
|
90
|
+
equalBytes(source.bytes, confirmed[index]?.bytes ?? new Uint8Array()))) {
|
|
91
|
+
return {
|
|
92
|
+
fingerprint: computeKnowledgeCorpusFingerprint(captured),
|
|
93
|
+
sources: captured,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return yield* new KnowledgeCorpusChangingError({ attempts: maxAttempts });
|
|
98
|
+
});
|
|
99
|
+
//# sourceMappingURL=knowledge-revision.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment-backed Layers for the knowledge-query feature. Only application
|
|
3
|
+
* composition imports this module; feature logic keeps the `KnowledgeIndex`
|
|
4
|
+
* requirement in its Effect environment.
|
|
5
|
+
*
|
|
6
|
+
* @experimental This API is unstable and may change without notice.
|
|
7
|
+
*/
|
|
8
|
+
import * as Layer from "effect/Layer";
|
|
9
|
+
import { KnowledgeIndex } from "./knowledge-index.js";
|
|
10
|
+
export declare const KnowledgeIndexLive: Layer.Layer<KnowledgeIndex, never, never>;
|
|
11
|
+
//# sourceMappingURL=live.d.ts.map
|
package/dist/src/live.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment-backed Layers for the knowledge-query feature. Only application
|
|
3
|
+
* composition imports this module; feature logic keeps the `KnowledgeIndex`
|
|
4
|
+
* requirement in its Effect environment.
|
|
5
|
+
*
|
|
6
|
+
* @experimental This API is unstable and may change without notice.
|
|
7
|
+
*/
|
|
8
|
+
import * as Clock from "effect/Clock";
|
|
9
|
+
import * as Effect from "effect/Effect";
|
|
10
|
+
import * as Layer from "effect/Layer";
|
|
11
|
+
import { KnowledgeIndex, makeKnowledgeIndexSnapshot, queryKnowledgeIndexResult, } from "./knowledge-index.js";
|
|
12
|
+
export const KnowledgeIndexLive = Layer.succeed(KnowledgeIndex, {
|
|
13
|
+
makeSnapshot: (bundles) => Effect.sync(() => makeKnowledgeIndexSnapshot(bundles)),
|
|
14
|
+
query: (snapshot, query) => Effect.gen(function* () {
|
|
15
|
+
const now = yield* Clock.currentTimeMillis;
|
|
16
|
+
return yield* Effect.fromResult(queryKnowledgeIndexResult(snapshot, query, now));
|
|
17
|
+
}),
|
|
18
|
+
});
|
|
19
|
+
//# sourceMappingURL=live.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agentxm/knowledge-query",
|
|
3
|
+
"version": "0.28.4-bootstrap.0",
|
|
4
|
+
"description": "AXM knowledge-query feature: Knowledge concept resolution, retrieval, search, related concepts, and status for the axm CLI. Unstable and unsupported — use the axm.sh CLI.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "FSL-1.1-MIT",
|
|
7
|
+
"homepage": "https://axm.sh",
|
|
8
|
+
"bugs": {
|
|
9
|
+
"url": "https://github.com/agentxm/axm/issues"
|
|
10
|
+
},
|
|
11
|
+
"author": "AgentXM <hello@agentxm.ai> (https://agentxm.ai)",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/agentxm/axm.git",
|
|
15
|
+
"directory": "packages/knowledge-query"
|
|
16
|
+
},
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/src/index.d.ts",
|
|
21
|
+
"default": "./dist/src/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./live": {
|
|
24
|
+
"types": "./dist/src/live.d.ts",
|
|
25
|
+
"default": "./dist/src/live.js"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"dist/src/",
|
|
30
|
+
"!**/*.map"
|
|
31
|
+
],
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
},
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=22.19.0"
|
|
37
|
+
},
|
|
38
|
+
"nx": {
|
|
39
|
+
"includedScripts": []
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"effect": "4.0.0-rc.112",
|
|
43
|
+
"@agentxm/extension-model": "^0.28.4-bootstrap.0",
|
|
44
|
+
"@agentxm/registry-protocol": "^0.28.4-bootstrap.0"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@effect/platform-node": "4.0.0-rc.112",
|
|
48
|
+
"@effect/vitest": "4.0.0-rc.112",
|
|
49
|
+
"@types/bun": "^1.3.14",
|
|
50
|
+
"@typescript/native": "npm:typescript@^7.0.2",
|
|
51
|
+
"typescript": "npm:@typescript/typescript6@^6.0.2",
|
|
52
|
+
"vitest": "^4.1.10"
|
|
53
|
+
}
|
|
54
|
+
}
|