@eddacraft/kindling-core 0.1.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 +190 -0
- package/README.md +187 -0
- package/dist/capsule/index.d.ts +10 -0
- package/dist/capsule/index.d.ts.map +1 -0
- package/dist/capsule/index.js +10 -0
- package/dist/capsule/index.js.map +1 -0
- package/dist/capsule/lifecycle.d.ts +63 -0
- package/dist/capsule/lifecycle.d.ts.map +1 -0
- package/dist/capsule/lifecycle.js +108 -0
- package/dist/capsule/lifecycle.js.map +1 -0
- package/dist/capsule/manager.d.ts +79 -0
- package/dist/capsule/manager.d.ts.map +1 -0
- package/dist/capsule/manager.js +113 -0
- package/dist/capsule/manager.js.map +1 -0
- package/dist/capsule/types.d.ts +79 -0
- package/dist/capsule/types.d.ts.map +1 -0
- package/dist/capsule/types.js +5 -0
- package/dist/capsule/types.js.map +1 -0
- package/dist/export/bundle.d.ts +125 -0
- package/dist/export/bundle.d.ts.map +1 -0
- package/dist/export/bundle.js +136 -0
- package/dist/export/bundle.js.map +1 -0
- package/dist/export/index.d.ts +8 -0
- package/dist/export/index.d.ts.map +1 -0
- package/dist/export/index.js +8 -0
- package/dist/export/index.js.map +1 -0
- package/dist/export/restore.d.ts +111 -0
- package/dist/export/restore.d.ts.map +1 -0
- package/dist/export/restore.js +149 -0
- package/dist/export/restore.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/retrieval/index.d.ts +8 -0
- package/dist/retrieval/index.d.ts.map +1 -0
- package/dist/retrieval/index.js +8 -0
- package/dist/retrieval/index.js.map +1 -0
- package/dist/retrieval/orchestrator.d.ts +50 -0
- package/dist/retrieval/orchestrator.d.ts.map +1 -0
- package/dist/retrieval/orchestrator.js +86 -0
- package/dist/retrieval/orchestrator.js.map +1 -0
- package/dist/retrieval/tiering.d.ts +76 -0
- package/dist/retrieval/tiering.d.ts.map +1 -0
- package/dist/retrieval/tiering.js +122 -0
- package/dist/retrieval/tiering.js.map +1 -0
- package/dist/service/index.d.ts +6 -0
- package/dist/service/index.d.ts.map +1 -0
- package/dist/service/index.js +5 -0
- package/dist/service/index.js.map +1 -0
- package/dist/service/kindling-service.d.ts +219 -0
- package/dist/service/kindling-service.d.ts.map +1 -0
- package/dist/service/kindling-service.js +260 -0
- package/dist/service/kindling-service.js.map +1 -0
- package/dist/types/capsule.d.ts +80 -0
- package/dist/types/capsule.d.ts.map +1 -0
- package/dist/types/capsule.js +33 -0
- package/dist/types/capsule.js.map +1 -0
- package/dist/types/common.d.ts +56 -0
- package/dist/types/common.d.ts.map +1 -0
- package/dist/types/common.js +16 -0
- package/dist/types/common.js.map +1 -0
- package/dist/types/index.d.ts +17 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +11 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/observation.d.ts +60 -0
- package/dist/types/observation.d.ts.map +1 -0
- package/dist/types/observation.js +27 -0
- package/dist/types/observation.js.map +1 -0
- package/dist/types/pin.d.ts +65 -0
- package/dist/types/pin.d.ts.map +1 -0
- package/dist/types/pin.js +26 -0
- package/dist/types/pin.js.map +1 -0
- package/dist/types/retrieval.d.ts +81 -0
- package/dist/types/retrieval.d.ts.map +1 -0
- package/dist/types/retrieval.js +5 -0
- package/dist/types/retrieval.js.map +1 -0
- package/dist/types/summary.d.ts +49 -0
- package/dist/types/summary.d.ts.map +1 -0
- package/dist/types/summary.js +13 -0
- package/dist/types/summary.js.map +1 -0
- package/dist/validation/capsule.d.ts +18 -0
- package/dist/validation/capsule.d.ts.map +1 -0
- package/dist/validation/capsule.js +143 -0
- package/dist/validation/capsule.js.map +1 -0
- package/dist/validation/index.d.ts +8 -0
- package/dist/validation/index.d.ts.map +1 -0
- package/dist/validation/index.js +8 -0
- package/dist/validation/index.js.map +1 -0
- package/dist/validation/observation.d.ts +18 -0
- package/dist/validation/observation.d.ts.map +1 -0
- package/dist/validation/observation.js +110 -0
- package/dist/validation/observation.js.map +1 -0
- package/dist/validation/pin.d.ts +16 -0
- package/dist/validation/pin.d.ts.map +1 -0
- package/dist/validation/pin.js +116 -0
- package/dist/validation/pin.js.map +1 -0
- package/dist/validation/summary.d.ts +16 -0
- package/dist/validation/summary.d.ts.map +1 -0
- package/dist/validation/summary.js +117 -0
- package/dist/validation/summary.js.map +1 -0
- package/package.json +55 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Service-level import coordination
|
|
3
|
+
*
|
|
4
|
+
* Provides high-level import API for restoring from export bundles.
|
|
5
|
+
*/
|
|
6
|
+
import { validateBundle } from './bundle.js';
|
|
7
|
+
/**
|
|
8
|
+
* Restore from export bundle
|
|
9
|
+
*
|
|
10
|
+
* Coordinates import with validation and error handling.
|
|
11
|
+
*
|
|
12
|
+
* @param store - Import store
|
|
13
|
+
* @param bundle - Export bundle to restore
|
|
14
|
+
* @param options - Import options
|
|
15
|
+
* @returns Import result with counts and errors
|
|
16
|
+
*/
|
|
17
|
+
export function restoreFromBundle(store, bundle, options = {}) {
|
|
18
|
+
const { skipValidation = false, dryRun = false } = options;
|
|
19
|
+
// Validate bundle structure
|
|
20
|
+
if (!skipValidation) {
|
|
21
|
+
const validation = validateBundle(bundle);
|
|
22
|
+
if (!validation.valid) {
|
|
23
|
+
return {
|
|
24
|
+
observations: 0,
|
|
25
|
+
capsules: 0,
|
|
26
|
+
summaries: 0,
|
|
27
|
+
pins: 0,
|
|
28
|
+
errors: validation.errors,
|
|
29
|
+
dryRun,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
// Dry run: validate only, don't import
|
|
34
|
+
if (dryRun) {
|
|
35
|
+
return {
|
|
36
|
+
observations: bundle.dataset.observations.length,
|
|
37
|
+
capsules: bundle.dataset.capsules.length,
|
|
38
|
+
summaries: bundle.dataset.summaries.length,
|
|
39
|
+
pins: bundle.dataset.pins.length,
|
|
40
|
+
errors: [],
|
|
41
|
+
dryRun: true,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
// Import dataset
|
|
45
|
+
const result = store.importDatabase(bundle.dataset);
|
|
46
|
+
return {
|
|
47
|
+
...result,
|
|
48
|
+
dryRun: false,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Merge multiple export bundles
|
|
53
|
+
*
|
|
54
|
+
* Combines datasets from multiple bundles into a single bundle.
|
|
55
|
+
* Useful for consolidating exports from different sources.
|
|
56
|
+
*
|
|
57
|
+
* @param bundles - Bundles to merge
|
|
58
|
+
* @param metadata - Optional metadata for merged bundle
|
|
59
|
+
* @returns Merged bundle
|
|
60
|
+
*/
|
|
61
|
+
export function mergeBundles(bundles, metadata) {
|
|
62
|
+
if (bundles.length === 0) {
|
|
63
|
+
throw new Error('At least one bundle required for merge');
|
|
64
|
+
}
|
|
65
|
+
// Validate all bundles
|
|
66
|
+
for (const bundle of bundles) {
|
|
67
|
+
const validation = validateBundle(bundle);
|
|
68
|
+
if (!validation.valid) {
|
|
69
|
+
throw new Error(`Invalid bundle: ${validation.errors.join(', ')}`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// Merge datasets
|
|
73
|
+
const merged = {
|
|
74
|
+
observations: [],
|
|
75
|
+
capsules: [],
|
|
76
|
+
summaries: [],
|
|
77
|
+
pins: [],
|
|
78
|
+
};
|
|
79
|
+
for (const bundle of bundles) {
|
|
80
|
+
merged.observations.push(...bundle.dataset.observations);
|
|
81
|
+
merged.capsules.push(...bundle.dataset.capsules);
|
|
82
|
+
merged.summaries.push(...bundle.dataset.summaries);
|
|
83
|
+
merged.pins.push(...bundle.dataset.pins);
|
|
84
|
+
}
|
|
85
|
+
// Deduplicate by ID
|
|
86
|
+
const deduped = {
|
|
87
|
+
observations: deduplicateById(merged.observations),
|
|
88
|
+
capsules: deduplicateById(merged.capsules),
|
|
89
|
+
summaries: deduplicateById(merged.summaries),
|
|
90
|
+
pins: deduplicateById(merged.pins),
|
|
91
|
+
};
|
|
92
|
+
return {
|
|
93
|
+
bundleVersion: '1.0',
|
|
94
|
+
exportedAt: Date.now(),
|
|
95
|
+
metadata: metadata || {
|
|
96
|
+
description: `Merged from ${bundles.length} bundles`,
|
|
97
|
+
},
|
|
98
|
+
dataset: {
|
|
99
|
+
version: '1.0',
|
|
100
|
+
exportedAt: Date.now(),
|
|
101
|
+
...deduped,
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Deduplicate entities by ID
|
|
107
|
+
*
|
|
108
|
+
* Keeps first occurrence of each ID.
|
|
109
|
+
*
|
|
110
|
+
* @param entities - Entities to deduplicate
|
|
111
|
+
* @returns Deduplicated entities
|
|
112
|
+
*/
|
|
113
|
+
function deduplicateById(entities) {
|
|
114
|
+
const seen = new Set();
|
|
115
|
+
const deduped = [];
|
|
116
|
+
for (const entity of entities) {
|
|
117
|
+
if (!entity.id)
|
|
118
|
+
continue;
|
|
119
|
+
if (!seen.has(entity.id)) {
|
|
120
|
+
seen.add(entity.id);
|
|
121
|
+
deduped.push(entity);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return deduped;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Compare two bundles for differences
|
|
128
|
+
*
|
|
129
|
+
* @param bundle1 - First bundle
|
|
130
|
+
* @param bundle2 - Second bundle
|
|
131
|
+
* @returns Difference summary
|
|
132
|
+
*/
|
|
133
|
+
export function compareBundles(bundle1, bundle2) {
|
|
134
|
+
const compareArrays = (arr1, arr2) => {
|
|
135
|
+
const ids1 = new Set(arr1.map(e => e.id).filter(Boolean));
|
|
136
|
+
const ids2 = new Set(arr2.map(e => e.id).filter(Boolean));
|
|
137
|
+
const common = new Set([...ids1].filter(id => ids2.has(id)));
|
|
138
|
+
const added = ids2.size - common.size;
|
|
139
|
+
const removed = ids1.size - common.size;
|
|
140
|
+
return { added, removed, common: common.size };
|
|
141
|
+
};
|
|
142
|
+
return {
|
|
143
|
+
observations: compareArrays(bundle1.dataset.observations, bundle2.dataset.observations),
|
|
144
|
+
capsules: compareArrays(bundle1.dataset.capsules, bundle2.dataset.capsules),
|
|
145
|
+
summaries: compareArrays(bundle1.dataset.summaries, bundle2.dataset.summaries),
|
|
146
|
+
pins: compareArrays(bundle1.dataset.pins, bundle2.dataset.pins),
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=restore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"restore.js","sourceRoot":"","sources":["../../src/export/restore.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAuD7C;;;;;;;;;GASG;AACH,MAAM,UAAU,iBAAiB,CAC/B,KAAkB,EAClB,MAAoB,EACpB,UAAyB,EAAE;IAE3B,MAAM,EAAE,cAAc,GAAG,KAAK,EAAE,MAAM,GAAG,KAAK,EAAE,GAAG,OAAO,CAAC;IAE3D,4BAA4B;IAC5B,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,MAAM,UAAU,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC;QAC1C,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;YACtB,OAAO;gBACL,YAAY,EAAE,CAAC;gBACf,QAAQ,EAAE,CAAC;gBACX,SAAS,EAAE,CAAC;gBACZ,IAAI,EAAE,CAAC;gBACP,MAAM,EAAE,UAAU,CAAC,MAAM;gBACzB,MAAM;aACP,CAAC;QACJ,CAAC;IACH,CAAC;IAED,uCAAuC;IACvC,IAAI,MAAM,EAAE,CAAC;QACX,OAAO;YACL,YAAY,EAAE,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,MAAM;YAChD,QAAQ,EAAE,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM;YACxC,SAAS,EAAE,MAAM,CAAC,OAAO,CAA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C;KAChE,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kindling Core
|
|
3
|
+
*
|
|
4
|
+
* Domain model, capsule lifecycle, and retrieval orchestration.
|
|
5
|
+
*/
|
|
6
|
+
export * from './types/index.js';
|
|
7
|
+
export * from './validation/index.js';
|
|
8
|
+
export * from './capsule/index.js';
|
|
9
|
+
export * from './retrieval/index.js';
|
|
10
|
+
export * from './export/index.js';
|
|
11
|
+
export * from './service/index.js';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,cAAc,kBAAkB,CAAC;AAGjC,cAAc,uBAAuB,CAAC;AAGtC,cAAc,oBAAoB,CAAC;AAGnC,cAAc,sBAAsB,CAAC;AAGrC,cAAc,mBAAmB,CAAC;AAGlC,cAAc,oBAAoB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kindling Core
|
|
3
|
+
*
|
|
4
|
+
* Domain model, capsule lifecycle, and retrieval orchestration.
|
|
5
|
+
*/
|
|
6
|
+
// Re-export all types
|
|
7
|
+
export * from './types/index.js';
|
|
8
|
+
// Re-export all validation functions
|
|
9
|
+
export * from './validation/index.js';
|
|
10
|
+
// Re-export capsule lifecycle
|
|
11
|
+
export * from './capsule/index.js';
|
|
12
|
+
// Re-export retrieval orchestration
|
|
13
|
+
export * from './retrieval/index.js';
|
|
14
|
+
// Re-export export/import coordination
|
|
15
|
+
export * from './export/index.js';
|
|
16
|
+
// Re-export service orchestration
|
|
17
|
+
export * from './service/index.js';
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,sBAAsB;AACtB,cAAc,kBAAkB,CAAC;AAEjC,qCAAqC;AACrC,cAAc,uBAAuB,CAAC;AAEtC,8BAA8B;AAC9B,cAAc,oBAAoB,CAAC;AAEnC,oCAAoC;AACpC,cAAc,sBAAsB,CAAC;AAErC,uCAAuC;AACvC,cAAc,mBAAmB,CAAC;AAElC,kCAAkC;AAClC,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/retrieval/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/retrieval/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retrieval orchestrator
|
|
3
|
+
*
|
|
4
|
+
* Combines pins, summaries, and provider candidates into a unified retrieval response.
|
|
5
|
+
*/
|
|
6
|
+
import type { RetrieveOptions, RetrieveResult, RetrievalProvider } from '../types/retrieval.js';
|
|
7
|
+
import type { Pin, Observation, Summary, ID } from '../types/index.js';
|
|
8
|
+
/**
|
|
9
|
+
* Store interface for retrieval operations
|
|
10
|
+
*/
|
|
11
|
+
export interface RetrievalStore {
|
|
12
|
+
/**
|
|
13
|
+
* List active pins for a scope
|
|
14
|
+
*/
|
|
15
|
+
listActivePins(scopeIds?: Partial<Record<string, string>>, now?: number): Pin[];
|
|
16
|
+
/**
|
|
17
|
+
* Get observation by ID
|
|
18
|
+
*/
|
|
19
|
+
getObservationById(observationId: ID): Observation | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Get summary by ID
|
|
22
|
+
*/
|
|
23
|
+
getSummaryById(summaryId: ID): Summary | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Get open capsule for session
|
|
26
|
+
*/
|
|
27
|
+
getOpenCapsuleForSession(sessionId: string): {
|
|
28
|
+
id: ID;
|
|
29
|
+
summaryId?: ID;
|
|
30
|
+
} | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Get latest summary for capsule
|
|
33
|
+
*/
|
|
34
|
+
getLatestSummaryForCapsule(capsuleId: ID): Summary | undefined;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Retrieve relevant context for a query
|
|
38
|
+
*
|
|
39
|
+
* Orchestrates retrieval by combining:
|
|
40
|
+
* 1. Active pins (non-evictable, always included)
|
|
41
|
+
* 2. Current session summary (non-evictable if exists)
|
|
42
|
+
* 3. Provider candidates (ranked, budget-limited)
|
|
43
|
+
*
|
|
44
|
+
* @param store - Retrieval store
|
|
45
|
+
* @param provider - Retrieval provider
|
|
46
|
+
* @param options - Retrieval options
|
|
47
|
+
* @returns Retrieval result with pins, summary, and candidates
|
|
48
|
+
*/
|
|
49
|
+
export declare function retrieve(store: RetrievalStore, provider: RetrievalProvider, options: RetrieveOptions): Promise<RetrieveResult>;
|
|
50
|
+
//# sourceMappingURL=orchestrator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orchestrator.d.ts","sourceRoot":"","sources":["../../src/retrieval/orchestrator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,eAAe,EACf,cAAc,EAGd,iBAAiB,EAClB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AAEvE;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,cAAc,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,GAAG,EAAE,CAAC;IAEhF;;OAEG;IACH,kBAAkB,CAAC,aAAa,EAAE,EAAE,GAAG,WAAW,GAAG,SAAS,CAAC;IAE/D;;OAEG;IACH,cAAc,CAAC,SAAS,EAAE,EAAE,GAAG,OAAO,GAAG,SAAS,CAAC;IAEnD;;OAEG;IACH,wBAAwB,CAAC,SAAS,EAAE,MAAM,GAAG;QAAE,EAAE,EAAE,EAAE,CAAC;QAAC,SAAS,CAAC,EAAE,EAAE,CAAA;KAAE,GAAG,SAAS,CAAC;IAEpF;;OAEG;IACH,0BAA0B,CAAC,SAAS,EAAE,EAAE,GAAG,OAAO,GAAG,SAAS,CAAC;CAChE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,QAAQ,CAC5B,KAAK,EAAE,cAAc,EACrB,QAAQ,EAAE,iBAAiB,EAC3B,OAAO,EAAE,eAAe,GACvB,OAAO,CAAC,cAAc,CAAC,CAmFzB"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retrieval orchestrator
|
|
3
|
+
*
|
|
4
|
+
* Combines pins, summaries, and provider candidates into a unified retrieval response.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Retrieve relevant context for a query
|
|
8
|
+
*
|
|
9
|
+
* Orchestrates retrieval by combining:
|
|
10
|
+
* 1. Active pins (non-evictable, always included)
|
|
11
|
+
* 2. Current session summary (non-evictable if exists)
|
|
12
|
+
* 3. Provider candidates (ranked, budget-limited)
|
|
13
|
+
*
|
|
14
|
+
* @param store - Retrieval store
|
|
15
|
+
* @param provider - Retrieval provider
|
|
16
|
+
* @param options - Retrieval options
|
|
17
|
+
* @returns Retrieval result with pins, summary, and candidates
|
|
18
|
+
*/
|
|
19
|
+
export async function retrieve(store, provider, options) {
|
|
20
|
+
const { query, scopeIds, maxCandidates = 10, includeRedacted = false, } = options;
|
|
21
|
+
const now = Date.now();
|
|
22
|
+
// Step 1: Fetch active pins for scope
|
|
23
|
+
const pins = store.listActivePins(scopeIds, now);
|
|
24
|
+
// Step 2: Resolve pins to their targets
|
|
25
|
+
const pinResults = [];
|
|
26
|
+
const pinnedIds = new Set();
|
|
27
|
+
for (const pin of pins) {
|
|
28
|
+
let target;
|
|
29
|
+
if (pin.targetType === 'observation') {
|
|
30
|
+
target = store.getObservationById(pin.targetId);
|
|
31
|
+
}
|
|
32
|
+
else if (pin.targetType === 'summary') {
|
|
33
|
+
target = store.getSummaryById(pin.targetId);
|
|
34
|
+
}
|
|
35
|
+
if (target) {
|
|
36
|
+
// Skip redacted unless explicitly requested
|
|
37
|
+
if ('redacted' in target && target.redacted && !includeRedacted) {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
pinResults.push({ pin, target });
|
|
41
|
+
pinnedIds.add(target.id);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
// Step 3: Get current session summary (non-evictable)
|
|
45
|
+
let currentSummary;
|
|
46
|
+
if (scopeIds.sessionId) {
|
|
47
|
+
const capsule = store.getOpenCapsuleForSession(scopeIds.sessionId);
|
|
48
|
+
if (capsule) {
|
|
49
|
+
const summary = store.getLatestSummaryForCapsule(capsule.id);
|
|
50
|
+
if (summary) {
|
|
51
|
+
currentSummary = summary;
|
|
52
|
+
pinnedIds.add(summary.id);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// Step 4: Get provider candidates (exclude pinned and current summary)
|
|
57
|
+
const providerResults = await provider.search({
|
|
58
|
+
query,
|
|
59
|
+
scopeIds,
|
|
60
|
+
maxResults: maxCandidates,
|
|
61
|
+
excludeIds: Array.from(pinnedIds),
|
|
62
|
+
includeRedacted,
|
|
63
|
+
});
|
|
64
|
+
// Step 5: Convert provider results to candidates
|
|
65
|
+
const candidates = providerResults.map(result => ({
|
|
66
|
+
entity: result.entity,
|
|
67
|
+
score: result.score,
|
|
68
|
+
matchContext: result.matchContext,
|
|
69
|
+
}));
|
|
70
|
+
// Step 6: Build provenance
|
|
71
|
+
const provenance = {
|
|
72
|
+
query,
|
|
73
|
+
scopeIds,
|
|
74
|
+
totalCandidates: providerResults.length,
|
|
75
|
+
returnedCandidates: candidates.length,
|
|
76
|
+
truncatedDueToTokenBudget: false, // Token budgeting not implemented in v0.1
|
|
77
|
+
providerUsed: provider.name,
|
|
78
|
+
};
|
|
79
|
+
return {
|
|
80
|
+
pins: pinResults,
|
|
81
|
+
currentSummary,
|
|
82
|
+
candidates,
|
|
83
|
+
provenance,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=orchestrator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orchestrator.js","sourceRoot":"","sources":["../../src/retrieval/orchestrator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAyCH;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC5B,KAAqB,EACrB,QAA2B,EAC3B,OAAwB;IAExB,MAAM,EACJ,KAAK,EACL,QAAQ,EACR,aAAa,GAAG,EAAE,EAClB,eAAe,GAAG,KAAK,GACxB,GAAG,OAAO,CAAC;IAEZ,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAEvB,sCAAsC;IACtC,MAAM,IAAI,GAAG,KAAK,CAAC,cAAc,CAAC,QAA2C,EAAE,GAAG,CAAC,CAAC;IAEpF,wCAAwC;IACxC,MAAM,UAAU,GAAgB,EAAE,CAAC;IACnC,MAAM,SAAS,GAAG,IAAI,GAAG,EAAM,CAAC;IAEhC,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,IAAI,MAAyC,CAAC;QAE9C,IAAI,GAAG,CAAC,UAAU,KAAK,aAAa,EAAE,CAAC;YACrC,MAAM,GAAG,KAAK,CAAC,kBAAkB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAClD,CAAC;aAAM,IAAI,GAAG,CAAC,UA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Y,EAAE,MAAM,CAAC,YAAY;KAClC,CAAC,CAAC,CAAC;IAEJ,2BAA2B;IAC3B,MAAM,UAAU,GAAG;QACjB,KAAK;QACL,QAAQ;QACR,eAAe,EAAE,eAAe,CAAC,MAAM;QACvC,kBAAkB,EAAE,UAAU,CAAC,MAAM;QACrC,yBAAyB,EAAE,KAAK,EAAE,0CAA0C;QAC5E,YAAY,EAAE,QAAQ,CAAC,IAAI;KAC5B,CAAC;IAEF,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,cAAc;QACd,UAAU;QACV,UAAU;KACX,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retrieval tiering utilities
|
|
3
|
+
*
|
|
4
|
+
* Implements tiering rules for retrieval results:
|
|
5
|
+
* - Tier 0 (non-evictable): Pins and current session summary
|
|
6
|
+
* - Tier 1 (evictable): Provider candidates
|
|
7
|
+
*/
|
|
8
|
+
import type { PinResult, CandidateResult } from '../types/retrieval.js';
|
|
9
|
+
import type { Summary } from '../types/summary.js';
|
|
10
|
+
/**
|
|
11
|
+
* Tiering levels
|
|
12
|
+
*/
|
|
13
|
+
export declare enum Tier {
|
|
14
|
+
/** Non-evictable: pins and current summary */
|
|
15
|
+
PINNED = 0,
|
|
16
|
+
/** Evictable: provider candidates */
|
|
17
|
+
CANDIDATE = 1
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Result with tier assignment
|
|
21
|
+
*/
|
|
22
|
+
export interface TieredResult {
|
|
23
|
+
tier: Tier;
|
|
24
|
+
content: string;
|
|
25
|
+
id: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Assign tiers to retrieval results
|
|
29
|
+
*
|
|
30
|
+
* Tier 0 (non-evictable):
|
|
31
|
+
* - Active pins
|
|
32
|
+
* - Current session summary
|
|
33
|
+
*
|
|
34
|
+
* Tier 1 (evictable):
|
|
35
|
+
* - Provider candidates
|
|
36
|
+
*
|
|
37
|
+
* @param pins - Pin results
|
|
38
|
+
* @param currentSummary - Current session summary
|
|
39
|
+
* @param candidates - Provider candidates
|
|
40
|
+
* @returns Tiered results in priority order
|
|
41
|
+
*/
|
|
42
|
+
export declare function assignTiers(pins: PinResult[], currentSummary: Summary | undefined, candidates: CandidateResult[]): TieredResult[];
|
|
43
|
+
/**
|
|
44
|
+
* Filter tiered results by token budget
|
|
45
|
+
*
|
|
46
|
+
* Ensures tier 0 (non-evictable) items are always included.
|
|
47
|
+
* Tier 1 items are included until budget exhausted.
|
|
48
|
+
*
|
|
49
|
+
* @param tiered - Tiered results
|
|
50
|
+
* @param tokenBudget - Maximum tokens to include
|
|
51
|
+
* @param estimateTokens - Function to estimate tokens for content
|
|
52
|
+
* @returns Filtered results that fit within budget
|
|
53
|
+
*/
|
|
54
|
+
export declare function filterByTokenBudget(tiered: TieredResult[], tokenBudget: number, estimateTokens?: (content: string) => number): TieredResult[];
|
|
55
|
+
/**
|
|
56
|
+
* Simple token estimation (characters / 4)
|
|
57
|
+
*
|
|
58
|
+
* Rough approximation: ~4 characters per token on average
|
|
59
|
+
*
|
|
60
|
+
* @param content - Content to estimate
|
|
61
|
+
* @returns Estimated token count
|
|
62
|
+
*/
|
|
63
|
+
export declare function estimateTokensSimple(content: string): number;
|
|
64
|
+
/**
|
|
65
|
+
* Check if tier 0 results exceed token budget
|
|
66
|
+
*
|
|
67
|
+
* Returns true if non-evictable items (pins + current summary) exceed budget.
|
|
68
|
+
* This is a warning condition - tier 0 items are always included.
|
|
69
|
+
*
|
|
70
|
+
* @param tiered - Tiered results
|
|
71
|
+
* @param tokenBudget - Token budget
|
|
72
|
+
* @param estimateTokens - Token estimation function
|
|
73
|
+
* @returns True if tier 0 exceeds budget
|
|
74
|
+
*/
|
|
75
|
+
export declare function tier0ExceedsBudget(tiered: TieredResult[], tokenBudget: number, estimateTokens?: (content: string) => number): boolean;
|
|
76
|
+
//# sourceMappingURL=tiering.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tiering.d.ts","sourceRoot":"","sources":["../../src/retrieval/tiering.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAEnD;;GAEG;AACH,oBAAY,IAAI;IACd,8CAA8C;IAC9C,MAAM,IAAI;IACV,qCAAqC;IACrC,SAAS,IAAI;CACd;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,IAAI,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,EAAE,EAAE,MAAM,CAAC;CACZ;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,SAAS,EAAE,EACjB,cAAc,EAAE,OAAO,GAAG,SAAS,EACnC,UAAU,EAAE,eAAe,EAAE,GAC5B,YAAY,EAAE,CA+BhB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,YAAY,EAAE,EACtB,WAAW,EAAE,MAAM,EACnB,cAAc,GAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAA6B,GACjE,YAAY,EAAE,CAsBhB;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAE5D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,YAAY,EAAE,EACtB,WAAW,EAAE,MAAM,EACnB,cAAc,GAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAA6B,GACjE,OAAO,CAUT"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retrieval tiering utilities
|
|
3
|
+
*
|
|
4
|
+
* Implements tiering rules for retrieval results:
|
|
5
|
+
* - Tier 0 (non-evictable): Pins and current session summary
|
|
6
|
+
* - Tier 1 (evictable): Provider candidates
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Tiering levels
|
|
10
|
+
*/
|
|
11
|
+
export var Tier;
|
|
12
|
+
(function (Tier) {
|
|
13
|
+
/** Non-evictable: pins and current summary */
|
|
14
|
+
Tier[Tier["PINNED"] = 0] = "PINNED";
|
|
15
|
+
/** Evictable: provider candidates */
|
|
16
|
+
Tier[Tier["CANDIDATE"] = 1] = "CANDIDATE";
|
|
17
|
+
})(Tier || (Tier = {}));
|
|
18
|
+
/**
|
|
19
|
+
* Assign tiers to retrieval results
|
|
20
|
+
*
|
|
21
|
+
* Tier 0 (non-evictable):
|
|
22
|
+
* - Active pins
|
|
23
|
+
* - Current session summary
|
|
24
|
+
*
|
|
25
|
+
* Tier 1 (evictable):
|
|
26
|
+
* - Provider candidates
|
|
27
|
+
*
|
|
28
|
+
* @param pins - Pin results
|
|
29
|
+
* @param currentSummary - Current session summary
|
|
30
|
+
* @param candidates - Provider candidates
|
|
31
|
+
* @returns Tiered results in priority order
|
|
32
|
+
*/
|
|
33
|
+
export function assignTiers(pins, currentSummary, candidates) {
|
|
34
|
+
const tiered = [];
|
|
35
|
+
// Tier 0: Pins (non-evictable)
|
|
36
|
+
for (const pin of pins) {
|
|
37
|
+
tiered.push({
|
|
38
|
+
tier: Tier.PINNED,
|
|
39
|
+
content: pin.target.content,
|
|
40
|
+
id: pin.target.id,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
// Tier 0: Current summary (non-evictable)
|
|
44
|
+
if (currentSummary) {
|
|
45
|
+
tiered.push({
|
|
46
|
+
tier: Tier.PINNED,
|
|
47
|
+
content: currentSummary.content,
|
|
48
|
+
id: currentSummary.id,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
// Tier 1: Candidates (evictable, ordered by score)
|
|
52
|
+
for (const candidate of candidates) {
|
|
53
|
+
tiered.push({
|
|
54
|
+
tier: Tier.CANDIDATE,
|
|
55
|
+
content: candidate.entity.content,
|
|
56
|
+
id: candidate.entity.id,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return tiered;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Filter tiered results by token budget
|
|
63
|
+
*
|
|
64
|
+
* Ensures tier 0 (non-evictable) items are always included.
|
|
65
|
+
* Tier 1 items are included until budget exhausted.
|
|
66
|
+
*
|
|
67
|
+
* @param tiered - Tiered results
|
|
68
|
+
* @param tokenBudget - Maximum tokens to include
|
|
69
|
+
* @param estimateTokens - Function to estimate tokens for content
|
|
70
|
+
* @returns Filtered results that fit within budget
|
|
71
|
+
*/
|
|
72
|
+
export function filterByTokenBudget(tiered, tokenBudget, estimateTokens = estimateTokensSimple) {
|
|
73
|
+
const included = [];
|
|
74
|
+
let tokensUsed = 0;
|
|
75
|
+
for (const result of tiered) {
|
|
76
|
+
const tokens = estimateTokens(result.content);
|
|
77
|
+
// Always include tier 0 (pins and current summary)
|
|
78
|
+
if (result.tier === Tier.PINNED) {
|
|
79
|
+
included.push(result);
|
|
80
|
+
tokensUsed += tokens;
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
// Include tier 1 only if within budget
|
|
84
|
+
if (tokensUsed + tokens <= tokenBudget) {
|
|
85
|
+
included.push(result);
|
|
86
|
+
tokensUsed += tokens;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return included;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Simple token estimation (characters / 4)
|
|
93
|
+
*
|
|
94
|
+
* Rough approximation: ~4 characters per token on average
|
|
95
|
+
*
|
|
96
|
+
* @param content - Content to estimate
|
|
97
|
+
* @returns Estimated token count
|
|
98
|
+
*/
|
|
99
|
+
export function estimateTokensSimple(content) {
|
|
100
|
+
return Math.ceil(content.length / 4);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Check if tier 0 results exceed token budget
|
|
104
|
+
*
|
|
105
|
+
* Returns true if non-evictable items (pins + current summary) exceed budget.
|
|
106
|
+
* This is a warning condition - tier 0 items are always included.
|
|
107
|
+
*
|
|
108
|
+
* @param tiered - Tiered results
|
|
109
|
+
* @param tokenBudget - Token budget
|
|
110
|
+
* @param estimateTokens - Token estimation function
|
|
111
|
+
* @returns True if tier 0 exceeds budget
|
|
112
|
+
*/
|
|
113
|
+
export function tier0ExceedsBudget(tiered, tokenBudget, estimateTokens = estimateTokensSimple) {
|
|
114
|
+
let tier0Tokens = 0;
|
|
115
|
+
for (const result of tiered) {
|
|
116
|
+
if (result.tier === Tier.PINNED) {
|
|
117
|
+
tier0Tokens += estimateTokens(result.content);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return tier0Tokens > tokenBudget;
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=tiering.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tiering.js","sourceRoot":"","sources":["../../src/retrieval/tiering.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH;;GAEG;AACH,MAAM,CAAN,IAAY,IAKX;AALD,WAAY,IAAI;IACd,8CAA8C;IAC9C,mCAAU,CAAA;IACV,qCAAqC;IACrC,yCAAa,CAAA;AACf,CAAC,EALW,IAAI,KAAJ,IAAI,QAKf;AAWD;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,WAAW,CACzB,IAAiB,EACjB,cAAmC,EACnC,UAA6B;IAE7B,MAAM,MAAM,GAAmB,EAAE,CAAC;IAElC,+BAA+B;IAC/B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,MAAM,CAAC,IAAI,CAAC;YACV,IAAI,EAAE,IAAI,CAAC,MAAM;YACjB,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,OAAO;YAC3B,EAAE,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE;SAClB,CAAC,CAAC;IACL,CAAC;IAED,0CAA0C;IAC1C,IAAI,cAAc,EAAE,CAAC;QACnB,MAAM,C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,CAAC,CAAC,CAAC;AACvC,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,kBAAkB,CAChC,MAAsB,EACtB,WAAmB,EACnB,iBAA8C,oBAAoB;IAElE,IAAI,WAAW,GAAG,CAAC,CAAC;IAEpB,KAAK,MAAM,MAAM,IAAI,MAAM,EAAE,CAAC;QAC5B,IAAI,MAAM,CAAC,IAAI,KAAK,IAAI,CAAC,MAAM,EAAE,CAAC;YAChC,WAAW,IAAI,cAAc,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAChD,CAAC;IACH,CAAC;IAED,OAAO,WAAW,GAAG,WAAW,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Service orchestration layer
|
|
3
|
+
*/
|
|
4
|
+
export { KindlingService } from './kindling-service.js';
|
|
5
|
+
export type { KindlingStore, KindlingServiceConfig, AppendObservationOptions, CreatePinOptions, CloseCapsuleOptions, } from './kindling-service.js';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/service/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,YAAY,EACV,aAAa,EACb,qBAAqB,EACrB,wBAAwB,EACxB,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/service/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC"}
|