@contractspec/module.context-storage 0.7.5 → 0.7.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -27
- package/dist/index.d.ts +1 -1
- package/dist/index.js +58 -58
- package/dist/node/index.js +58 -58
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -1,39 +1,66 @@
|
|
|
1
1
|
# @contractspec/module.context-storage
|
|
2
2
|
|
|
3
|
-
Website: https://contractspec.io
|
|
3
|
+
Website: https://contractspec.io
|
|
4
4
|
|
|
5
|
-
**Context storage module with persistence adapters
|
|
5
|
+
**Context storage module with persistence adapters.**
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## What It Provides
|
|
8
|
+
|
|
9
|
+
- **Layer**: module.
|
|
10
|
+
- **Consumers**: bundles (library), apps (registry-server).
|
|
11
|
+
- `src/pipeline/` contains pipeline stages and orchestration helpers.
|
|
12
|
+
- Related ContractSpec packages include `@contractspec/lib.context-storage`, `@contractspec/lib.contracts-integrations`, `@contractspec/lib.knowledge`, `@contractspec/lib.schema`, `@contractspec/tool.bun`, `@contractspec/tool.typescript`.
|
|
13
|
+
- `src/pipeline/` contains pipeline stages and orchestration helpers.
|
|
8
14
|
|
|
9
15
|
## Installation
|
|
10
16
|
|
|
11
|
-
|
|
12
|
-
bun add @contractspec/module.context-storage
|
|
13
|
-
```
|
|
17
|
+
`npm install @contractspec/module.context-storage`
|
|
14
18
|
|
|
15
|
-
|
|
19
|
+
or
|
|
16
20
|
|
|
17
|
-
|
|
18
|
-
- `./entities` — Schema entities (ContextPack, ContextSnapshot, ContextSnapshotItem)
|
|
19
|
-
- `./storage` — Postgres storage adapter (PostgresContextStorage)
|
|
20
|
-
- `./pipeline` — ContextSnapshotPipeline for building snapshots from packs
|
|
21
|
+
`bun add @contractspec/module.context-storage`
|
|
21
22
|
|
|
22
23
|
## Usage
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
25
|
+
Import the root entrypoint from `@contractspec/module.context-storage`, or choose a documented subpath when you only need one part of the package surface.
|
|
26
|
+
|
|
27
|
+
## Architecture
|
|
28
|
+
|
|
29
|
+
- `src/entities/` contains domain entities and value objects.
|
|
30
|
+
- `src/index.ts` is the root public barrel and package entrypoint.
|
|
31
|
+
- `src/pipeline/` contains pipeline stages and orchestration helpers.
|
|
32
|
+
- `src/storage/` contains persistence adapters and storage implementations.
|
|
33
|
+
|
|
34
|
+
## Public Entry Points
|
|
35
|
+
|
|
36
|
+
- Export `.` resolves through `./src/index.ts`.
|
|
37
|
+
- Export `./entities` resolves through `./src/entities/index.ts`.
|
|
38
|
+
- Export `./pipeline/context-snapshot-pipeline` resolves through `./src/pipeline/context-snapshot-pipeline.ts`.
|
|
39
|
+
- Export `./storage` resolves through `./src/storage/index.ts`.
|
|
40
|
+
|
|
41
|
+
## Local Commands
|
|
42
|
+
|
|
43
|
+
- `bun run dev` — contractspec-bun-build dev
|
|
44
|
+
- `bun run build` — bun run prebuild && bun run build:bundle && bun run build:types
|
|
45
|
+
- `bun run lint` — bun lint:fix
|
|
46
|
+
- `bun run lint:check` — biome check .
|
|
47
|
+
- `bun run lint:fix` — biome check --write --unsafe --only=nursery/useSortedClasses . && biome check --write .
|
|
48
|
+
- `bun run typecheck` — tsc --noEmit
|
|
49
|
+
- `bun run publish:pkg` — bun publish --tolerate-republish --ignore-scripts --verbose
|
|
50
|
+
- `bun run publish:pkg:canary` — bun publish:pkg --tag canary
|
|
51
|
+
- `bun run clean` — rimraf dist .turbo
|
|
52
|
+
- `bun run build:bundle` — contractspec-bun-build transpile
|
|
53
|
+
- `bun run build:types` — contractspec-bun-build types
|
|
54
|
+
- `bun run prebuild` — contractspec-bun-build prebuild
|
|
55
|
+
|
|
56
|
+
## Recent Updates
|
|
57
|
+
|
|
58
|
+
- Replace eslint+prettier by biomejs to optimize speed.
|
|
59
|
+
- Resolve lint, build, and type errors across nine packages.
|
|
60
|
+
- Add AI provider ranking system with ranking-driven model selection.
|
|
61
|
+
|
|
62
|
+
## Notes
|
|
63
|
+
|
|
64
|
+
- Depends on `lib.context-storage`, `lib.knowledge`, `lib.contracts-integrations`.
|
|
65
|
+
- Pipeline stages must be idempotent; re-running a snapshot should not duplicate data.
|
|
66
|
+
- Storage adapters are swappable -- always code against the interface, not the implementation.
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -65,6 +65,64 @@ var contextStorageSchemaContribution = {
|
|
|
65
65
|
entities: contextStorageEntities
|
|
66
66
|
};
|
|
67
67
|
|
|
68
|
+
// src/pipeline/context-snapshot-pipeline.ts
|
|
69
|
+
import { Buffer } from "buffer";
|
|
70
|
+
import {
|
|
71
|
+
DocumentProcessor
|
|
72
|
+
} from "@contractspec/lib.knowledge/ingestion";
|
|
73
|
+
|
|
74
|
+
class ContextSnapshotPipeline {
|
|
75
|
+
store;
|
|
76
|
+
processor;
|
|
77
|
+
embeddingService;
|
|
78
|
+
vectorIndexer;
|
|
79
|
+
constructor(options) {
|
|
80
|
+
this.store = options.store;
|
|
81
|
+
this.processor = options.documentProcessor ?? new DocumentProcessor;
|
|
82
|
+
this.embeddingService = options.embeddingService;
|
|
83
|
+
this.vectorIndexer = options.vectorIndexer;
|
|
84
|
+
}
|
|
85
|
+
async buildSnapshot(input) {
|
|
86
|
+
await this.store.upsertPack(input.pack);
|
|
87
|
+
const snapshot = await this.store.createSnapshot({
|
|
88
|
+
...input.snapshot,
|
|
89
|
+
itemCount: input.items.length
|
|
90
|
+
});
|
|
91
|
+
await this.store.addSnapshotItems(snapshot.snapshotId, input.items);
|
|
92
|
+
if (input.index !== false && this.embeddingService && this.vectorIndexer) {
|
|
93
|
+
const documents = input.items.map((item) => toRawDocument(item, snapshot.snapshotId));
|
|
94
|
+
const fragments = await this.collectFragments(documents);
|
|
95
|
+
const embeddings = await this.embeddingService.embedFragments(fragments);
|
|
96
|
+
await this.vectorIndexer.upsert(fragments, embeddings);
|
|
97
|
+
}
|
|
98
|
+
return { snapshot, itemCount: input.items.length };
|
|
99
|
+
}
|
|
100
|
+
async collectFragments(documents) {
|
|
101
|
+
const fragments = [];
|
|
102
|
+
for (const document of documents) {
|
|
103
|
+
const next = await this.processor.process(document);
|
|
104
|
+
fragments.push(...next);
|
|
105
|
+
}
|
|
106
|
+
return fragments;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function toRawDocument(item, snapshotId) {
|
|
110
|
+
const content = typeof item.content === "string" ? item.content : JSON.stringify(item.content);
|
|
111
|
+
const mimeType = typeof item.content === "string" ? "text/plain" : "application/json";
|
|
112
|
+
const metadata = {
|
|
113
|
+
snapshotId,
|
|
114
|
+
sourceKey: item.sourceKey,
|
|
115
|
+
sourceVersion: item.sourceVersion ?? "latest",
|
|
116
|
+
kind: item.kind
|
|
117
|
+
};
|
|
118
|
+
return {
|
|
119
|
+
id: item.itemId,
|
|
120
|
+
mimeType,
|
|
121
|
+
data: Buffer.from(content, "utf-8"),
|
|
122
|
+
metadata
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
68
126
|
// src/storage/index.ts
|
|
69
127
|
class PostgresContextStorage {
|
|
70
128
|
database;
|
|
@@ -336,64 +394,6 @@ function recordFromJson(value) {
|
|
|
336
394
|
}
|
|
337
395
|
return;
|
|
338
396
|
}
|
|
339
|
-
|
|
340
|
-
// src/pipeline/context-snapshot-pipeline.ts
|
|
341
|
-
import { Buffer } from "buffer";
|
|
342
|
-
import {
|
|
343
|
-
DocumentProcessor
|
|
344
|
-
} from "@contractspec/lib.knowledge/ingestion";
|
|
345
|
-
|
|
346
|
-
class ContextSnapshotPipeline {
|
|
347
|
-
store;
|
|
348
|
-
processor;
|
|
349
|
-
embeddingService;
|
|
350
|
-
vectorIndexer;
|
|
351
|
-
constructor(options) {
|
|
352
|
-
this.store = options.store;
|
|
353
|
-
this.processor = options.documentProcessor ?? new DocumentProcessor;
|
|
354
|
-
this.embeddingService = options.embeddingService;
|
|
355
|
-
this.vectorIndexer = options.vectorIndexer;
|
|
356
|
-
}
|
|
357
|
-
async buildSnapshot(input) {
|
|
358
|
-
await this.store.upsertPack(input.pack);
|
|
359
|
-
const snapshot = await this.store.createSnapshot({
|
|
360
|
-
...input.snapshot,
|
|
361
|
-
itemCount: input.items.length
|
|
362
|
-
});
|
|
363
|
-
await this.store.addSnapshotItems(snapshot.snapshotId, input.items);
|
|
364
|
-
if (input.index !== false && this.embeddingService && this.vectorIndexer) {
|
|
365
|
-
const documents = input.items.map((item) => toRawDocument(item, snapshot.snapshotId));
|
|
366
|
-
const fragments = await this.collectFragments(documents);
|
|
367
|
-
const embeddings = await this.embeddingService.embedFragments(fragments);
|
|
368
|
-
await this.vectorIndexer.upsert(fragments, embeddings);
|
|
369
|
-
}
|
|
370
|
-
return { snapshot, itemCount: input.items.length };
|
|
371
|
-
}
|
|
372
|
-
async collectFragments(documents) {
|
|
373
|
-
const fragments = [];
|
|
374
|
-
for (const document of documents) {
|
|
375
|
-
const next = await this.processor.process(document);
|
|
376
|
-
fragments.push(...next);
|
|
377
|
-
}
|
|
378
|
-
return fragments;
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
function toRawDocument(item, snapshotId) {
|
|
382
|
-
const content = typeof item.content === "string" ? item.content : JSON.stringify(item.content);
|
|
383
|
-
const mimeType = typeof item.content === "string" ? "text/plain" : "application/json";
|
|
384
|
-
const metadata = {
|
|
385
|
-
snapshotId,
|
|
386
|
-
sourceKey: item.sourceKey,
|
|
387
|
-
sourceVersion: item.sourceVersion ?? "latest",
|
|
388
|
-
kind: item.kind
|
|
389
|
-
};
|
|
390
|
-
return {
|
|
391
|
-
id: item.itemId,
|
|
392
|
-
mimeType,
|
|
393
|
-
data: Buffer.from(content, "utf-8"),
|
|
394
|
-
metadata
|
|
395
|
-
};
|
|
396
|
-
}
|
|
397
397
|
export {
|
|
398
398
|
contextStorageSchemaContribution,
|
|
399
399
|
contextStorageEntities,
|
package/dist/node/index.js
CHANGED
|
@@ -64,6 +64,64 @@ var contextStorageSchemaContribution = {
|
|
|
64
64
|
entities: contextStorageEntities
|
|
65
65
|
};
|
|
66
66
|
|
|
67
|
+
// src/pipeline/context-snapshot-pipeline.ts
|
|
68
|
+
import { Buffer } from "node:buffer";
|
|
69
|
+
import {
|
|
70
|
+
DocumentProcessor
|
|
71
|
+
} from "@contractspec/lib.knowledge/ingestion";
|
|
72
|
+
|
|
73
|
+
class ContextSnapshotPipeline {
|
|
74
|
+
store;
|
|
75
|
+
processor;
|
|
76
|
+
embeddingService;
|
|
77
|
+
vectorIndexer;
|
|
78
|
+
constructor(options) {
|
|
79
|
+
this.store = options.store;
|
|
80
|
+
this.processor = options.documentProcessor ?? new DocumentProcessor;
|
|
81
|
+
this.embeddingService = options.embeddingService;
|
|
82
|
+
this.vectorIndexer = options.vectorIndexer;
|
|
83
|
+
}
|
|
84
|
+
async buildSnapshot(input) {
|
|
85
|
+
await this.store.upsertPack(input.pack);
|
|
86
|
+
const snapshot = await this.store.createSnapshot({
|
|
87
|
+
...input.snapshot,
|
|
88
|
+
itemCount: input.items.length
|
|
89
|
+
});
|
|
90
|
+
await this.store.addSnapshotItems(snapshot.snapshotId, input.items);
|
|
91
|
+
if (input.index !== false && this.embeddingService && this.vectorIndexer) {
|
|
92
|
+
const documents = input.items.map((item) => toRawDocument(item, snapshot.snapshotId));
|
|
93
|
+
const fragments = await this.collectFragments(documents);
|
|
94
|
+
const embeddings = await this.embeddingService.embedFragments(fragments);
|
|
95
|
+
await this.vectorIndexer.upsert(fragments, embeddings);
|
|
96
|
+
}
|
|
97
|
+
return { snapshot, itemCount: input.items.length };
|
|
98
|
+
}
|
|
99
|
+
async collectFragments(documents) {
|
|
100
|
+
const fragments = [];
|
|
101
|
+
for (const document of documents) {
|
|
102
|
+
const next = await this.processor.process(document);
|
|
103
|
+
fragments.push(...next);
|
|
104
|
+
}
|
|
105
|
+
return fragments;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function toRawDocument(item, snapshotId) {
|
|
109
|
+
const content = typeof item.content === "string" ? item.content : JSON.stringify(item.content);
|
|
110
|
+
const mimeType = typeof item.content === "string" ? "text/plain" : "application/json";
|
|
111
|
+
const metadata = {
|
|
112
|
+
snapshotId,
|
|
113
|
+
sourceKey: item.sourceKey,
|
|
114
|
+
sourceVersion: item.sourceVersion ?? "latest",
|
|
115
|
+
kind: item.kind
|
|
116
|
+
};
|
|
117
|
+
return {
|
|
118
|
+
id: item.itemId,
|
|
119
|
+
mimeType,
|
|
120
|
+
data: Buffer.from(content, "utf-8"),
|
|
121
|
+
metadata
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
67
125
|
// src/storage/index.ts
|
|
68
126
|
class PostgresContextStorage {
|
|
69
127
|
database;
|
|
@@ -335,64 +393,6 @@ function recordFromJson(value) {
|
|
|
335
393
|
}
|
|
336
394
|
return;
|
|
337
395
|
}
|
|
338
|
-
|
|
339
|
-
// src/pipeline/context-snapshot-pipeline.ts
|
|
340
|
-
import { Buffer } from "node:buffer";
|
|
341
|
-
import {
|
|
342
|
-
DocumentProcessor
|
|
343
|
-
} from "@contractspec/lib.knowledge/ingestion";
|
|
344
|
-
|
|
345
|
-
class ContextSnapshotPipeline {
|
|
346
|
-
store;
|
|
347
|
-
processor;
|
|
348
|
-
embeddingService;
|
|
349
|
-
vectorIndexer;
|
|
350
|
-
constructor(options) {
|
|
351
|
-
this.store = options.store;
|
|
352
|
-
this.processor = options.documentProcessor ?? new DocumentProcessor;
|
|
353
|
-
this.embeddingService = options.embeddingService;
|
|
354
|
-
this.vectorIndexer = options.vectorIndexer;
|
|
355
|
-
}
|
|
356
|
-
async buildSnapshot(input) {
|
|
357
|
-
await this.store.upsertPack(input.pack);
|
|
358
|
-
const snapshot = await this.store.createSnapshot({
|
|
359
|
-
...input.snapshot,
|
|
360
|
-
itemCount: input.items.length
|
|
361
|
-
});
|
|
362
|
-
await this.store.addSnapshotItems(snapshot.snapshotId, input.items);
|
|
363
|
-
if (input.index !== false && this.embeddingService && this.vectorIndexer) {
|
|
364
|
-
const documents = input.items.map((item) => toRawDocument(item, snapshot.snapshotId));
|
|
365
|
-
const fragments = await this.collectFragments(documents);
|
|
366
|
-
const embeddings = await this.embeddingService.embedFragments(fragments);
|
|
367
|
-
await this.vectorIndexer.upsert(fragments, embeddings);
|
|
368
|
-
}
|
|
369
|
-
return { snapshot, itemCount: input.items.length };
|
|
370
|
-
}
|
|
371
|
-
async collectFragments(documents) {
|
|
372
|
-
const fragments = [];
|
|
373
|
-
for (const document of documents) {
|
|
374
|
-
const next = await this.processor.process(document);
|
|
375
|
-
fragments.push(...next);
|
|
376
|
-
}
|
|
377
|
-
return fragments;
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
function toRawDocument(item, snapshotId) {
|
|
381
|
-
const content = typeof item.content === "string" ? item.content : JSON.stringify(item.content);
|
|
382
|
-
const mimeType = typeof item.content === "string" ? "text/plain" : "application/json";
|
|
383
|
-
const metadata = {
|
|
384
|
-
snapshotId,
|
|
385
|
-
sourceKey: item.sourceKey,
|
|
386
|
-
sourceVersion: item.sourceVersion ?? "latest",
|
|
387
|
-
kind: item.kind
|
|
388
|
-
};
|
|
389
|
-
return {
|
|
390
|
-
id: item.itemId,
|
|
391
|
-
mimeType,
|
|
392
|
-
data: Buffer.from(content, "utf-8"),
|
|
393
|
-
metadata
|
|
394
|
-
};
|
|
395
|
-
}
|
|
396
396
|
export {
|
|
397
397
|
contextStorageSchemaContribution,
|
|
398
398
|
contextStorageEntities,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contractspec/module.context-storage",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.7",
|
|
4
4
|
"description": "Context storage module with persistence adapters",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"contractspec",
|
|
@@ -19,20 +19,20 @@
|
|
|
19
19
|
"dev": "contractspec-bun-build dev",
|
|
20
20
|
"clean": "rimraf dist .turbo",
|
|
21
21
|
"lint": "bun lint:fix",
|
|
22
|
-
"lint:fix": "
|
|
23
|
-
"lint:check": "
|
|
22
|
+
"lint:fix": "biome check --write --unsafe --only=nursery/useSortedClasses . && biome check --write .",
|
|
23
|
+
"lint:check": "biome check .",
|
|
24
24
|
"prebuild": "contractspec-bun-build prebuild",
|
|
25
25
|
"typecheck": "tsc --noEmit"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@contractspec/lib.context-storage": "0.7.
|
|
29
|
-
"@contractspec/lib.schema": "3.7.
|
|
30
|
-
"@contractspec/lib.contracts-integrations": "3.7.
|
|
31
|
-
"@contractspec/lib.knowledge": "3.7.
|
|
28
|
+
"@contractspec/lib.context-storage": "0.7.6",
|
|
29
|
+
"@contractspec/lib.schema": "3.7.6",
|
|
30
|
+
"@contractspec/lib.contracts-integrations": "3.7.7",
|
|
31
|
+
"@contractspec/lib.knowledge": "3.7.7"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@contractspec/tool.typescript": "3.7.
|
|
35
|
-
"@contractspec/tool.bun": "3.7.
|
|
34
|
+
"@contractspec/tool.typescript": "3.7.6",
|
|
35
|
+
"@contractspec/tool.bun": "3.7.6",
|
|
36
36
|
"typescript": "^5.9.3"
|
|
37
37
|
},
|
|
38
38
|
"exports": {
|