@grackle-ai/knowledge-core 0.63.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/dist/chunker.d.ts +20 -0
- package/dist/chunker.d.ts.map +1 -0
- package/dist/chunker.js +7 -0
- package/dist/chunker.js.map +1 -0
- package/dist/client.d.ts +68 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +150 -0
- package/dist/client.js.map +1 -0
- package/dist/constants.d.ts +33 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +33 -0
- package/dist/constants.js.map +1 -0
- package/dist/edge-store.d.ts +32 -0
- package/dist/edge-store.d.ts.map +1 -0
- package/dist/edge-store.js +145 -0
- package/dist/edge-store.js.map +1 -0
- package/dist/embedder.d.ts +35 -0
- package/dist/embedder.d.ts.map +1 -0
- package/dist/embedder.js +7 -0
- package/dist/embedder.js.map +1 -0
- package/dist/expand.d.ts +42 -0
- package/dist/expand.d.ts.map +1 -0
- package/dist/expand.js +150 -0
- package/dist/expand.js.map +1 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/ingest.d.ts +23 -0
- package/dist/ingest.d.ts.map +1 -0
- package/dist/ingest.js +27 -0
- package/dist/ingest.js.map +1 -0
- package/dist/local-embedder.d.ts +25 -0
- package/dist/local-embedder.d.ts.map +1 -0
- package/dist/local-embedder.js +88 -0
- package/dist/local-embedder.js.map +1 -0
- package/dist/logger.d.ts +9 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +15 -0
- package/dist/logger.js.map +1 -0
- package/dist/node-store.d.ts +116 -0
- package/dist/node-store.d.ts.map +1 -0
- package/dist/node-store.js +268 -0
- package/dist/node-store.js.map +1 -0
- package/dist/pass-through-chunker.d.ts +16 -0
- package/dist/pass-through-chunker.d.ts.map +1 -0
- package/dist/pass-through-chunker.js +21 -0
- package/dist/pass-through-chunker.js.map +1 -0
- package/dist/schema.d.ts +23 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +73 -0
- package/dist/schema.js.map +1 -0
- package/dist/search.d.ts +43 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +123 -0
- package/dist/search.js.map +1 -0
- package/dist/transcript-chunker.d.ts +29 -0
- package/dist/transcript-chunker.d.ts.map +1 -0
- package/dist/transcript-chunker.js +142 -0
- package/dist/transcript-chunker.js.map +1 -0
- package/dist/types.d.ts +122 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +71 -0
- package/dist/types.js.map +1 -0
- package/package.json +45 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session transcript chunker that splits JSONL session logs by conversation turn.
|
|
3
|
+
*
|
|
4
|
+
* Accepts the raw JSONL content of a session's `stream.jsonl` file and groups
|
|
5
|
+
* events into semantic turns (user input → agent response) for embedding.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
/** Default event types that are excluded from chunks. */
|
|
10
|
+
const DEFAULT_SKIP_TYPES = ["status", "signal", "usage", "system"];
|
|
11
|
+
/** Default maximum characters per chunk. */
|
|
12
|
+
const DEFAULT_MAX_CHUNK_SIZE = 4000;
|
|
13
|
+
/** Labels used when rendering events into readable text. */
|
|
14
|
+
const EVENT_LABELS = {
|
|
15
|
+
user_input: "User",
|
|
16
|
+
text: "Assistant",
|
|
17
|
+
tool_use: "Tool",
|
|
18
|
+
tool_result: "Result",
|
|
19
|
+
error: "Error",
|
|
20
|
+
finding: "Finding",
|
|
21
|
+
subtask_create: "Subtask",
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Create a chunker that splits JSONL session transcripts by conversation turn.
|
|
25
|
+
*
|
|
26
|
+
* A "turn" starts at a `user_input` event and includes all subsequent events
|
|
27
|
+
* until the next `user_input`. Events before the first `user_input` are grouped
|
|
28
|
+
* into an initial turn (turn 0). Turns exceeding {@link TranscriptChunkerOptions.maxChunkSize}
|
|
29
|
+
* are split into sub-chunks.
|
|
30
|
+
*
|
|
31
|
+
* @param options - Optional chunker configuration.
|
|
32
|
+
* @returns A {@link Chunker} for session transcript JSONL content.
|
|
33
|
+
*/
|
|
34
|
+
export function createTranscriptChunker(options) {
|
|
35
|
+
const maxChunkSize = options?.maxChunkSize ?? DEFAULT_MAX_CHUNK_SIZE;
|
|
36
|
+
const skipTypes = new Set(options?.skipEventTypes ?? DEFAULT_SKIP_TYPES);
|
|
37
|
+
return {
|
|
38
|
+
chunk(content, metadata) {
|
|
39
|
+
const entries = parseJsonl(content);
|
|
40
|
+
if (entries.length === 0) {
|
|
41
|
+
return [];
|
|
42
|
+
}
|
|
43
|
+
// Group on all entries first so user_input boundaries are preserved
|
|
44
|
+
// even if user_input is in skipTypes. Filter when rendering.
|
|
45
|
+
const turns = groupByTurn(entries);
|
|
46
|
+
const chunks = [];
|
|
47
|
+
for (let turnIndex = 0; turnIndex < turns.length; turnIndex++) {
|
|
48
|
+
const turnEntries = turns[turnIndex];
|
|
49
|
+
const visible = turnEntries.filter((e) => !skipTypes.has(e.type));
|
|
50
|
+
if (visible.length === 0) {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const text = renderTurn(visible);
|
|
54
|
+
const timestamps = visible.map((e) => e.timestamp);
|
|
55
|
+
const eventTypes = [...new Set(visible.map((e) => e.type))];
|
|
56
|
+
const turnMetadata = {
|
|
57
|
+
...metadata,
|
|
58
|
+
turnIndex,
|
|
59
|
+
timestampStart: timestamps[0],
|
|
60
|
+
timestampEnd: timestamps[timestamps.length - 1],
|
|
61
|
+
eventTypes,
|
|
62
|
+
};
|
|
63
|
+
if (text.length <= maxChunkSize) {
|
|
64
|
+
chunks.push({ text, index: chunks.length, metadata: turnMetadata });
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
const subChunks = splitText(text, maxChunkSize);
|
|
68
|
+
for (const subChunk of subChunks) {
|
|
69
|
+
chunks.push({ text: subChunk, index: chunks.length, metadata: turnMetadata });
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return chunks;
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/** Parse a JSONL string into an array of log entries, skipping malformed lines. */
|
|
78
|
+
function parseJsonl(content) {
|
|
79
|
+
const entries = [];
|
|
80
|
+
for (const line of content.split("\n")) {
|
|
81
|
+
const trimmed = line.trim();
|
|
82
|
+
if (!trimmed) {
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
entries.push(JSON.parse(trimmed));
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
// Skip malformed lines
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return entries;
|
|
93
|
+
}
|
|
94
|
+
/** Group log entries into turns, splitting on `user_input` events. */
|
|
95
|
+
function groupByTurn(entries) {
|
|
96
|
+
const turns = [];
|
|
97
|
+
let current = [];
|
|
98
|
+
for (const entry of entries) {
|
|
99
|
+
if (entry.type === "user_input" && current.length > 0) {
|
|
100
|
+
turns.push(current);
|
|
101
|
+
current = [];
|
|
102
|
+
}
|
|
103
|
+
current.push(entry);
|
|
104
|
+
}
|
|
105
|
+
if (current.length > 0) {
|
|
106
|
+
turns.push(current);
|
|
107
|
+
}
|
|
108
|
+
return turns;
|
|
109
|
+
}
|
|
110
|
+
/** Render a turn's events into human-readable text. */
|
|
111
|
+
function renderTurn(entries) {
|
|
112
|
+
return entries
|
|
113
|
+
.map((e) => {
|
|
114
|
+
const label = EVENT_LABELS[e.type] ?? e.type;
|
|
115
|
+
return `${label}: ${e.content}`;
|
|
116
|
+
})
|
|
117
|
+
.join("\n");
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Split text into sub-chunks at line boundaries, targeting at most maxSize characters.
|
|
121
|
+
* A single line longer than maxSize will be emitted as-is (not split mid-line).
|
|
122
|
+
*/
|
|
123
|
+
function splitText(text, maxSize) {
|
|
124
|
+
const lines = text.split("\n");
|
|
125
|
+
const subChunks = [];
|
|
126
|
+
let current = "";
|
|
127
|
+
for (const line of lines) {
|
|
128
|
+
const candidate = current ? current + "\n" + line : line;
|
|
129
|
+
if (candidate.length > maxSize && current) {
|
|
130
|
+
subChunks.push(current);
|
|
131
|
+
current = line;
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
current = candidate;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (current) {
|
|
138
|
+
subChunks.push(current);
|
|
139
|
+
}
|
|
140
|
+
return subChunks;
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=transcript-chunker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transcript-chunker.js","sourceRoot":"","sources":["../src/transcript-chunker.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AA0BH,yDAAyD;AACzD,MAAM,kBAAkB,GAAa,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;AAE7E,4CAA4C;AAC5C,MAAM,sBAAsB,GAAW,IAAI,CAAC;AAE5C,4DAA4D;AAC5D,MAAM,YAAY,GAA2B;IAC3C,UAAU,EAAE,MAAM;IAClB,IAAI,EAAE,WAAW;IACjB,QAAQ,EAAE,MAAM;IAChB,WAAW,EAAE,QAAQ;IACrB,KAAK,EAAE,OAAO;IACd,OAAO,EAAE,SAAS;IAClB,cAAc,EAAE,SAAS;CAC1B,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,UAAU,uBAAuB,CAAC,OAAkC;IACxE,MAAM,YAAY,GAAW,OAAO,EAAE,YAAY,IAAI,sBAAsB,CAAC;IAC7E,MAAM,SAAS,GAAgB,IAAI,GAAG,CAAC,OAAO,EAAE,cAAc,IAAI,kBAAkB,CAAC,CAAC;IAEtF,OAAO;QACL,KAAK,CAAC,OAAe,EAAE,QAAkC;YACvD,MAAM,OAAO,GAAe,U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C;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core domain types for the knowledge graph.
|
|
3
|
+
*
|
|
4
|
+
* Defines the two node kinds (reference and native), edge types, and
|
|
5
|
+
* runtime type guards for discriminating between node variants.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
/** Discriminator for knowledge graph node kinds. */
|
|
10
|
+
export declare const NODE_KIND: {
|
|
11
|
+
/** Points to an entity in Grackle's relational DB. No duplicated content. */
|
|
12
|
+
readonly REFERENCE: "reference";
|
|
13
|
+
/** Exists only in the graph. Owns its content. */
|
|
14
|
+
readonly NATIVE: "native";
|
|
15
|
+
};
|
|
16
|
+
/** Union of all node kind values. */
|
|
17
|
+
export type NodeKind = (typeof NODE_KIND)[keyof typeof NODE_KIND];
|
|
18
|
+
/**
|
|
19
|
+
* Recommended reference source values.
|
|
20
|
+
*
|
|
21
|
+
* Consumers can use these or define their own — the {@link ReferenceSource}
|
|
22
|
+
* type accepts any string.
|
|
23
|
+
*/
|
|
24
|
+
export declare const REFERENCE_SOURCE: {
|
|
25
|
+
readonly TASK: "task";
|
|
26
|
+
readonly SESSION: "session";
|
|
27
|
+
readonly FINDING: "finding";
|
|
28
|
+
readonly WORKSPACE: "workspace";
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Entity type that a reference node points to.
|
|
32
|
+
*
|
|
33
|
+
* Open `string` type — not restricted to the values in {@link REFERENCE_SOURCE}.
|
|
34
|
+
* Consumers can define their own source types (e.g., `"ado-work-item"`, `"webpage"`).
|
|
35
|
+
*/
|
|
36
|
+
export type ReferenceSource = string;
|
|
37
|
+
/**
|
|
38
|
+
* Recommended native node categories.
|
|
39
|
+
*
|
|
40
|
+
* Consumers can use these or define their own — the {@link NativeCategory}
|
|
41
|
+
* type accepts any string.
|
|
42
|
+
*/
|
|
43
|
+
export declare const NATIVE_CATEGORY: {
|
|
44
|
+
readonly DECISION: "decision";
|
|
45
|
+
readonly INSIGHT: "insight";
|
|
46
|
+
readonly CONCEPT: "concept";
|
|
47
|
+
readonly SNIPPET: "snippet";
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Category for native nodes that exist only in the knowledge graph.
|
|
51
|
+
*
|
|
52
|
+
* Open `string` type — not restricted to the values in {@link NATIVE_CATEGORY}.
|
|
53
|
+
* Consumers can define their own categories (e.g., `"research-note"`, `"requirement"`).
|
|
54
|
+
*/
|
|
55
|
+
export type NativeCategory = string;
|
|
56
|
+
/** Relationship types between knowledge graph nodes. */
|
|
57
|
+
export declare const EDGE_TYPE: {
|
|
58
|
+
readonly RELATES_TO: "RELATES_TO";
|
|
59
|
+
readonly DEPENDS_ON: "DEPENDS_ON";
|
|
60
|
+
readonly DERIVED_FROM: "DERIVED_FROM";
|
|
61
|
+
readonly MENTIONS: "MENTIONS";
|
|
62
|
+
readonly PART_OF: "PART_OF";
|
|
63
|
+
};
|
|
64
|
+
/** Union of all edge type values. */
|
|
65
|
+
export type EdgeType = (typeof EDGE_TYPE)[keyof typeof EDGE_TYPE];
|
|
66
|
+
/** Properties common to all knowledge graph nodes. */
|
|
67
|
+
export interface KnowledgeNodeBase {
|
|
68
|
+
/** Unique node identifier (UUID). */
|
|
69
|
+
id: string;
|
|
70
|
+
/** Which kind of node this is. */
|
|
71
|
+
kind: NodeKind;
|
|
72
|
+
/** Dense vector embedding for similarity search. */
|
|
73
|
+
embedding: number[];
|
|
74
|
+
/** ISO 8601 creation timestamp. */
|
|
75
|
+
createdAt: string;
|
|
76
|
+
/** ISO 8601 last-updated timestamp. */
|
|
77
|
+
updatedAt: string;
|
|
78
|
+
/** Workspace scope (empty string = global). */
|
|
79
|
+
workspaceId: string;
|
|
80
|
+
}
|
|
81
|
+
/** A reference node — points to an entity in Grackle's relational DB. */
|
|
82
|
+
export interface ReferenceNode extends KnowledgeNodeBase {
|
|
83
|
+
kind: typeof NODE_KIND.REFERENCE;
|
|
84
|
+
/** Which entity type this refers to. */
|
|
85
|
+
sourceType: ReferenceSource;
|
|
86
|
+
/** The ID of the entity in Grackle's relational DB. */
|
|
87
|
+
sourceId: string;
|
|
88
|
+
/** Human-readable label derived from the source (e.g., task title). */
|
|
89
|
+
label: string;
|
|
90
|
+
}
|
|
91
|
+
/** A native node — owns its content directly. */
|
|
92
|
+
export interface NativeNode extends KnowledgeNodeBase {
|
|
93
|
+
kind: typeof NODE_KIND.NATIVE;
|
|
94
|
+
/** Subcategory of the native node. */
|
|
95
|
+
category: NativeCategory;
|
|
96
|
+
/** Title or summary. */
|
|
97
|
+
title: string;
|
|
98
|
+
/** Full content owned by this node. */
|
|
99
|
+
content: string;
|
|
100
|
+
/** Free-form tags for categorization. */
|
|
101
|
+
tags: string[];
|
|
102
|
+
}
|
|
103
|
+
/** Discriminated union of all knowledge graph node types. */
|
|
104
|
+
export type KnowledgeNode = ReferenceNode | NativeNode;
|
|
105
|
+
/** An edge (relationship) in the knowledge graph. */
|
|
106
|
+
export interface KnowledgeEdge {
|
|
107
|
+
/** Source node ID. */
|
|
108
|
+
fromId: string;
|
|
109
|
+
/** Target node ID. */
|
|
110
|
+
toId: string;
|
|
111
|
+
/** Relationship type. */
|
|
112
|
+
type: EdgeType;
|
|
113
|
+
/** Optional metadata (e.g., confidence score, context snippet). */
|
|
114
|
+
metadata?: Record<string, unknown>;
|
|
115
|
+
/** ISO 8601 timestamp when the edge was created. */
|
|
116
|
+
createdAt: string;
|
|
117
|
+
}
|
|
118
|
+
/** Returns true if the node is a {@link ReferenceNode}. */
|
|
119
|
+
export declare function isReferenceNode(node: KnowledgeNode): node is ReferenceNode;
|
|
120
|
+
/** Returns true if the node is a {@link NativeNode}. */
|
|
121
|
+
export declare function isNativeNode(node: KnowledgeNode): node is NativeNode;
|
|
122
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","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MAAM,WAAW,UAAW,SAAQ,iBAAiB;IACnD,IAAI,EAAE,OAAO,SAAS,CAAC,MAAM,CAAC;IAC9B,sCAAsC;IACtC,QAAQ,EAAE,cAAc,CAAC;IACzB,wBAAwB;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,uCAAuC;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB,yCAAyC;IACzC,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB;AAED,6DAA6D;AAC7D,MAAM,MAAM,aAAa,GAAG,aAAa,GAAG,UAAU,CAAC;AAMvD,qDAAqD;AACrD,MAAM,WAAW,aAAa;IAC5B,sBAAsB;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,sBAAsB;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,yBAAyB;IACzB,IAAI,EAAE,QAAQ,CAAC;IACf,mEAAmE;IACnE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,oDAAoD;IACpD,SAAS,EAAE,MAAM,CAAC;CACnB;AAMD,2DAA2D;AAC3D,wBAAgB,eAAe,CAAC,IAAI,EAAE,aAAa,GAAG,IAAI,IAAI,aAAa,CAE1E;AAED,wDAAwD;AACxD,wBAAgB,YAAY,CAAC,IAAI,EAAE,aAAa,GAAG,IAAI,IAAI,UAAU,CAEpE"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core domain types for the knowledge graph.
|
|
3
|
+
*
|
|
4
|
+
* Defines the two node kinds (reference and native), edge types, and
|
|
5
|
+
* runtime type guards for discriminating between node variants.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
// Node kind discriminator
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
/** Discriminator for knowledge graph node kinds. */
|
|
13
|
+
export const NODE_KIND = {
|
|
14
|
+
/** Points to an entity in Grackle's relational DB. No duplicated content. */
|
|
15
|
+
REFERENCE: "reference",
|
|
16
|
+
/** Exists only in the graph. Owns its content. */
|
|
17
|
+
NATIVE: "native",
|
|
18
|
+
};
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
// Reference node source types
|
|
21
|
+
// ---------------------------------------------------------------------------
|
|
22
|
+
/**
|
|
23
|
+
* Recommended reference source values.
|
|
24
|
+
*
|
|
25
|
+
* Consumers can use these or define their own — the {@link ReferenceSource}
|
|
26
|
+
* type accepts any string.
|
|
27
|
+
*/
|
|
28
|
+
export const REFERENCE_SOURCE = {
|
|
29
|
+
TASK: "task",
|
|
30
|
+
SESSION: "session",
|
|
31
|
+
FINDING: "finding",
|
|
32
|
+
WORKSPACE: "workspace",
|
|
33
|
+
};
|
|
34
|
+
// ---------------------------------------------------------------------------
|
|
35
|
+
// Native node categories
|
|
36
|
+
// ---------------------------------------------------------------------------
|
|
37
|
+
/**
|
|
38
|
+
* Recommended native node categories.
|
|
39
|
+
*
|
|
40
|
+
* Consumers can use these or define their own — the {@link NativeCategory}
|
|
41
|
+
* type accepts any string.
|
|
42
|
+
*/
|
|
43
|
+
export const NATIVE_CATEGORY = {
|
|
44
|
+
DECISION: "decision",
|
|
45
|
+
INSIGHT: "insight",
|
|
46
|
+
CONCEPT: "concept",
|
|
47
|
+
SNIPPET: "snippet",
|
|
48
|
+
};
|
|
49
|
+
// ---------------------------------------------------------------------------
|
|
50
|
+
// Edge types
|
|
51
|
+
// ---------------------------------------------------------------------------
|
|
52
|
+
/** Relationship types between knowledge graph nodes. */
|
|
53
|
+
export const EDGE_TYPE = {
|
|
54
|
+
RELATES_TO: "RELATES_TO",
|
|
55
|
+
DEPENDS_ON: "DEPENDS_ON",
|
|
56
|
+
DERIVED_FROM: "DERIVED_FROM",
|
|
57
|
+
MENTIONS: "MENTIONS",
|
|
58
|
+
PART_OF: "PART_OF",
|
|
59
|
+
};
|
|
60
|
+
// ---------------------------------------------------------------------------
|
|
61
|
+
// Type guards
|
|
62
|
+
// ---------------------------------------------------------------------------
|
|
63
|
+
/** Returns true if the node is a {@link ReferenceNode}. */
|
|
64
|
+
export function isReferenceNode(node) {
|
|
65
|
+
return node.kind === NODE_KIND.REFERENCE;
|
|
66
|
+
}
|
|
67
|
+
/** Returns true if the node is a {@link NativeNode}. */
|
|
68
|
+
export function isNativeNode(node) {
|
|
69
|
+
return node.kind === NODE_KIND.NATIVE;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,8EAA8E;AAC9E,0BAA0B;AAC1B,8EAA8E;AAE9E,oDAAoD;AACpD,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,6EAA6E;IAC7E,SAAS,EAAE,WAAW;IACtB,kDAAkD;IAClD,MAAM,EAAE,QAAQ;CACR,CAAC;AAKX,8EAA8E;AAC9E,8BAA8B;AAC9B,8EAA8E;AAE9E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,IAAI,EAAE,MAAM;IACZ,OAAO,EAAE,SAAS;IAClB,OAAO,EAAE,SAAS;IAClB,SAAS,EAAE,WAAW;CACd,CAAC;AAUX,8EAA8E;AAC9E,yBAAyB;AACzB,8EAA8E;AAE9E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,QAAQ,EAAE,UAAU;IACpB,OAAO,EAAE,SAAS;IAClB,OAAO,EAAE,SAAS;IAClB,OAAO,EAAE,SAAS;CACV,CAAC;AAUX,8EAA8E;AAC9E,aAAa;AACb,8EAA8E;AAE9E,wDAAwD;AACxD,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,UAAU,EAAE,YAAY;IACxB,UAAU,EAAE,YAAY;IACxB,YAAY,EAAE,cAAc;IAC5B,QAAQ,EAAE,UAAU;IACpB,OAAO,EAAE,SAAS;CACV,CAAC;AAsEX,8EAA8E;AAC9E,cAAc;AACd,8EAA8E;AAE9E,2DAA2D;AAC3D,MAAM,UAAU,eAAe,CAAC,IAAmB;IACjD,OAAO,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,SAAS,CAAC;AAC3C,CAAC;AAED,wDAAwD;AACxD,MAAM,UAAU,YAAY,CAAC,IAAmB;IAC9C,OAAO,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,MAAM,CAAC;AACxC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@grackle-ai/knowledge-core",
|
|
3
|
+
"version": "0.63.0",
|
|
4
|
+
"description": "Generic knowledge graph SDK on top of Neo4j with vector search, graph traversal, and pluggable embedders/chunkers",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/nick-pape/grackle.git",
|
|
9
|
+
"directory": "packages/knowledge-core"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"knowledge-graph",
|
|
13
|
+
"neo4j",
|
|
14
|
+
"vector-search",
|
|
15
|
+
"embeddings",
|
|
16
|
+
"graph-traversal"
|
|
17
|
+
],
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=22.0.0"
|
|
20
|
+
},
|
|
21
|
+
"type": "module",
|
|
22
|
+
"main": "dist/index.js",
|
|
23
|
+
"types": "dist/index.d.ts",
|
|
24
|
+
"files": [
|
|
25
|
+
"dist/"
|
|
26
|
+
],
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@huggingface/transformers": "^3.4.0",
|
|
29
|
+
"neo4j-driver": "^6.0.1",
|
|
30
|
+
"pino": "^10.3.1"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@rushstack/heft": "1.2.4",
|
|
34
|
+
"@types/node": "^22.0.0",
|
|
35
|
+
"vitest": "^3.1.1",
|
|
36
|
+
"@grackle-ai/heft-rig": "0.0.1"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "heft build --clean",
|
|
40
|
+
"test": "vitest run",
|
|
41
|
+
"clean": "heft clean",
|
|
42
|
+
"_phase:build": "heft run --only build -- --clean",
|
|
43
|
+
"_phase:test": "vitest run"
|
|
44
|
+
}
|
|
45
|
+
}
|