nexus-ai-pro 2.7.0 → 2.8.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/API_STABILITY.md +85 -3
- package/CHANGELOG.md +133 -1
- package/README.md +9 -2
- package/SECURITY.md +41 -1
- package/dist/batch/manager.js +16 -33
- package/dist/batch/openai-client.d.ts +83 -0
- package/dist/batch/openai-client.js +120 -0
- package/dist/batch/openai.d.ts +12 -21
- package/dist/batch/openai.js +33 -125
- package/dist/batch/poll.d.ts +18 -0
- package/dist/batch/poll.js +29 -0
- package/dist/cli/models.d.ts +36 -0
- package/dist/cli/models.js +170 -0
- package/dist/cli.js +11 -1
- package/dist/doctor/index.d.ts +16 -1
- package/dist/doctor/index.js +10 -5
- package/dist/embeddings/adapters.d.ts +2 -2
- package/dist/embeddings/adapters.js +24 -13
- package/dist/embeddings/batch-google.d.ts +40 -0
- package/dist/embeddings/batch-google.js +128 -0
- package/dist/embeddings/batch-mock.d.ts +45 -0
- package/dist/embeddings/batch-mock.js +71 -0
- package/dist/embeddings/batch-openai.d.ts +23 -0
- package/dist/embeddings/batch-openai.js +55 -0
- package/dist/embeddings/batch.d.ts +230 -0
- package/dist/embeddings/batch.js +282 -0
- package/dist/embeddings/cache.d.ts +81 -0
- package/dist/embeddings/cache.js +116 -0
- package/dist/embeddings/engine.d.ts +7 -0
- package/dist/embeddings/engine.js +110 -68
- package/dist/embeddings/google-wire.d.ts +32 -0
- package/dist/embeddings/google-wire.js +33 -0
- package/dist/embeddings/index.d.ts +1 -1
- package/dist/embeddings/inputs.d.ts +30 -0
- package/dist/embeddings/inputs.js +103 -0
- package/dist/embeddings/mock.d.ts +7 -1
- package/dist/embeddings/mock.js +8 -2
- package/dist/embeddings/models.js +21 -0
- package/dist/images/asset-stores.d.ts +47 -1
- package/dist/images/asset-stores.js +135 -2
- package/dist/images/asset-support.d.ts +94 -1
- package/dist/images/asset-support.js +159 -3
- package/dist/images/assets.d.ts +10 -3
- package/dist/images/assets.js +15 -2
- package/dist/media/index.d.ts +244 -0
- package/dist/media/index.js +262 -0
- package/dist/media/mistral.d.ts +34 -0
- package/dist/media/mistral.js +90 -0
- package/dist/media/mock.d.ts +36 -0
- package/dist/media/mock.js +45 -0
- package/dist/media/rag.d.ts +141 -0
- package/dist/media/rag.js +198 -0
- package/dist/models/data.d.ts +87 -0
- package/dist/models/data.js +235 -0
- package/dist/models/registry.d.ts +2 -1
- package/dist/models/registry.js +3 -2
- package/dist/postgres/embedding-cache.d.ts +29 -0
- package/dist/postgres/embedding-cache.js +58 -0
- package/dist/rag/chroma.d.ts +13 -1
- package/dist/rag/chroma.js +36 -13
- package/dist/rag/pinecone.js +2 -2
- package/dist/rag/pipeline.d.ts +17 -2
- package/dist/rag/pipeline.js +95 -14
- package/dist/rag/qdrant.js +2 -2
- package/dist/rag/redis.d.ts +2 -1
- package/dist/rag/redis.js +56 -18
- package/dist/rag/vector-helpers.d.ts +5 -0
- package/dist/rag/vector-helpers.js +7 -0
- package/dist/rag/weaviate.d.ts +15 -1
- package/dist/rag/weaviate.js +75 -12
- package/dist/sqlite/embedding-cache.d.ts +34 -0
- package/dist/sqlite/embedding-cache.js +61 -0
- package/dist/types/config.d.ts +5 -0
- package/dist/types/embeddings.d.ts +87 -5
- package/dist/types/images.d.ts +2 -2
- package/dist/types/lifecycle.d.ts +1 -1
- package/dist/utils/redis-command.d.ts +15 -0
- package/dist/utils/redis-command.js +5 -0
- package/dist/utils/sha256.d.ts +9 -0
- package/dist/utils/sha256.js +6 -0
- package/dist/utils/vector-bytes.d.ts +11 -0
- package/dist/utils/vector-bytes.js +18 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist-cjs/batch/manager.js +16 -33
- package/dist-cjs/batch/openai-client.d.ts +83 -0
- package/dist-cjs/batch/openai-client.js +125 -0
- package/dist-cjs/batch/openai.d.ts +12 -21
- package/dist-cjs/batch/openai.js +32 -124
- package/dist-cjs/batch/poll.d.ts +18 -0
- package/dist-cjs/batch/poll.js +32 -0
- package/dist-cjs/cli/models.d.ts +36 -0
- package/dist-cjs/cli/models.js +175 -0
- package/dist-cjs/doctor/index.d.ts +16 -1
- package/dist-cjs/doctor/index.js +10 -5
- package/dist-cjs/embeddings/adapters.d.ts +2 -2
- package/dist-cjs/embeddings/adapters.js +23 -12
- package/dist-cjs/embeddings/batch-google.d.ts +40 -0
- package/dist-cjs/embeddings/batch-google.js +132 -0
- package/dist-cjs/embeddings/batch-mock.d.ts +45 -0
- package/dist-cjs/embeddings/batch-mock.js +75 -0
- package/dist-cjs/embeddings/batch-openai.d.ts +23 -0
- package/dist-cjs/embeddings/batch-openai.js +59 -0
- package/dist-cjs/embeddings/batch.d.ts +230 -0
- package/dist-cjs/embeddings/batch.js +320 -0
- package/dist-cjs/embeddings/cache.d.ts +81 -0
- package/dist-cjs/embeddings/cache.js +125 -0
- package/dist-cjs/embeddings/engine.d.ts +7 -0
- package/dist-cjs/embeddings/engine.js +143 -68
- package/dist-cjs/embeddings/google-wire.d.ts +32 -0
- package/dist-cjs/embeddings/google-wire.js +38 -0
- package/dist-cjs/embeddings/index.d.ts +1 -1
- package/dist-cjs/embeddings/inputs.d.ts +30 -0
- package/dist-cjs/embeddings/inputs.js +141 -0
- package/dist-cjs/embeddings/mock.d.ts +7 -1
- package/dist-cjs/embeddings/mock.js +8 -2
- package/dist-cjs/embeddings/models.js +21 -0
- package/dist-cjs/images/asset-stores.d.ts +47 -1
- package/dist-cjs/images/asset-stores.js +133 -0
- package/dist-cjs/images/asset-support.d.ts +94 -1
- package/dist-cjs/images/asset-support.js +169 -3
- package/dist-cjs/images/assets.d.ts +10 -3
- package/dist-cjs/images/assets.js +17 -1
- package/dist-cjs/media/index.d.ts +244 -0
- package/dist-cjs/media/index.js +269 -0
- package/dist-cjs/media/mistral.d.ts +34 -0
- package/dist-cjs/media/mistral.js +94 -0
- package/dist-cjs/media/mock.d.ts +36 -0
- package/dist-cjs/media/mock.js +49 -0
- package/dist-cjs/media/rag.d.ts +141 -0
- package/dist-cjs/media/rag.js +202 -0
- package/dist-cjs/models/data.d.ts +87 -0
- package/dist-cjs/models/data.js +245 -0
- package/dist-cjs/models/registry.d.ts +2 -1
- package/dist-cjs/models/registry.js +3 -2
- package/dist-cjs/postgres/embedding-cache.d.ts +29 -0
- package/dist-cjs/postgres/embedding-cache.js +96 -0
- package/dist-cjs/rag/chroma.d.ts +13 -1
- package/dist-cjs/rag/chroma.js +35 -12
- package/dist-cjs/rag/pinecone.js +1 -1
- package/dist-cjs/rag/pipeline.d.ts +17 -2
- package/dist-cjs/rag/pipeline.js +95 -14
- package/dist-cjs/rag/qdrant.js +1 -1
- package/dist-cjs/rag/redis.d.ts +2 -1
- package/dist-cjs/rag/redis.js +55 -17
- package/dist-cjs/rag/vector-helpers.d.ts +5 -0
- package/dist-cjs/rag/vector-helpers.js +8 -0
- package/dist-cjs/rag/weaviate.d.ts +15 -1
- package/dist-cjs/rag/weaviate.js +74 -11
- package/dist-cjs/sqlite/embedding-cache.d.ts +34 -0
- package/dist-cjs/sqlite/embedding-cache.js +99 -0
- package/dist-cjs/types/config.d.ts +5 -0
- package/dist-cjs/types/embeddings.d.ts +87 -5
- package/dist-cjs/types/images.d.ts +2 -2
- package/dist-cjs/types/lifecycle.d.ts +1 -1
- package/dist-cjs/utils/redis-command.d.ts +15 -0
- package/dist-cjs/utils/redis-command.js +8 -0
- package/dist-cjs/utils/sha256.d.ts +9 -0
- package/dist-cjs/utils/sha256.js +7 -0
- package/dist-cjs/utils/vector-bytes.d.ts +11 -0
- package/dist-cjs/utils/vector-bytes.js +22 -0
- package/dist-cjs/version.d.ts +1 -1
- package/dist-cjs/version.js +1 -1
- package/llms.txt +2 -1
- package/package.json +162 -4
package/API_STABILITY.md
CHANGED
|
@@ -41,6 +41,87 @@ Both are covered by this policy:
|
|
|
41
41
|
Deep imports into `dist`, `dist-cjs`, or `src` are not supported. Import only from `nexus-ai-pro` or
|
|
42
42
|
one of its explicit subpaths.
|
|
43
43
|
|
|
44
|
+
## 2.8 stage (2.8.0)
|
|
45
|
+
|
|
46
|
+
Everything 2.8 adds is stable from the start and additive, unless this section says otherwise.
|
|
47
|
+
|
|
48
|
+
New and stable:
|
|
49
|
+
- `ChromaVectorStoreOptions.filterFields`;
|
|
50
|
+
- `EmbeddingCacheStore`, `EmbeddingCacheEntry`, and `EmbeddingCacheConfig` with its `store`;
|
|
51
|
+
`nexus-ai-pro/embeddings/cache`: `embeddingCacheKey()` and `EmbeddingCacheContext`, `packVector()`
|
|
52
|
+
and `unpackVector()`, `MemoryEmbeddingCache` and its options, `RedisEmbeddingCache` with its client
|
|
53
|
+
and options, and `tieredEmbeddingCache()`. A key's derivation and a vector's packed layout are part
|
|
54
|
+
of the promise, so a cache one release wrote is read by the next;
|
|
55
|
+
- `EmbeddingModality`, `EmbeddingPart`, and `EmbeddingParts` as `EmbeddingInput`;
|
|
56
|
+
`EmbeddingProviderRequest.contents` with `EmbeddingProviderPart`, `EmbeddingProviderTextPart`, and
|
|
57
|
+
`EmbeddingProviderMediaPart`; `inputModalities` on `EmbeddingProviderCapabilities` and
|
|
58
|
+
`EmbeddingModelCapabilities`, and `costPerImage`; `MockEmbeddingProviderOptions.describeMedia`. An
|
|
59
|
+
adapter that declares no `inputModalities` is sent text only, as before;
|
|
60
|
+
- `nexus-ai-pro/embeddings/batch`: `EmbeddingBatchManager` and its config and runtime, its request,
|
|
61
|
+
item, result, and output types, the `EmbeddingBatchProvider` contract with its info, capabilities,
|
|
62
|
+
request, and item, `batchEmbedder()` with `BatchEmbedder` and its options; the OpenAI and mock
|
|
63
|
+
adapters on `/openai` and `/mock`. `GoogleEmbeddingBatchProvider` on `/google` is experimental
|
|
64
|
+
until a live run is recorded;
|
|
65
|
+
- on `nexus-ai-pro/images/assets`: `AssetStore.putStream()` and `getStream()`, both optional;
|
|
66
|
+
`putAssetStream()` and `readAssetStream()`, `DEFAULT_BUFFERED_ASSET_BYTES`, `AssetByteSource`,
|
|
67
|
+
`StreamAssetInput`, `AssetByteRange`, `AssetStreamOptions`, `StreamAssetDescriptor`, and
|
|
68
|
+
`PutAssetStreamOptions`; `S3LikeClient.putObjectStream()` and `getObjectStream()`, both optional.
|
|
69
|
+
The images family stays experimental, and these with it;
|
|
70
|
+
- `nexus-ai-pro/models/data`: `RegistryData`, `REGISTRY_DATA_FORMAT`, `checkRegistryData()`,
|
|
71
|
+
`parseRegistryData()` with `RegistryDataError`, `bundledRegistryData()`, `withRegistryData()`,
|
|
72
|
+
`diffRegistryData()` with `RegistryDiff` and `RegistryFieldChange`, and `registryDataAgeDays()`;
|
|
73
|
+
`ModelRegistryConfig.verifiedAt` and `DoctorOptions.models`; the commands `nexus models export`,
|
|
74
|
+
`check`, and `refresh`. The `nexus-registry/1` format is read by every 2.x release;
|
|
75
|
+
- `nexus-ai-pro/media`, `/media/mistral`, `/media/mock`, and `/media/rag` are new and experimental: media
|
|
76
|
+
understanding graduates by the checklist, once a vision model and the OCR service pass its
|
|
77
|
+
conformance suite live. `OperationFamily` gains `media`, and `AssetProvenance.operation` gains
|
|
78
|
+
`upload`, both stable;
|
|
79
|
+
- `IngestionPipelineOptions.batchEmbed` and `batchesInFlight`, and `IngestionReport.batches` and
|
|
80
|
+
`batchesRecovered`. `IngestionPipelineOptions.embed` is optional when `batchEmbed` is given;
|
|
81
|
+
- `nexus-ai-pro/postgres/embedding-cache`: `PostgresEmbeddingCache`, its options, and
|
|
82
|
+
`embeddingCacheMigrations()`; `nexus-ai-pro/sqlite/embedding-cache`: `SqliteEmbeddingCache`, its
|
|
83
|
+
options, and `sqliteEmbeddingCacheMigrations()`.
|
|
84
|
+
|
|
85
|
+
Changed, each to keep a promise the surface already made:
|
|
86
|
+
- `OpenAIBatchProvider` refuses `endpoint: '/v1/embeddings'` with a `BatchCapabilityError`; it sent
|
|
87
|
+
chat bodies there, which never embedded anything.
|
|
88
|
+
- The Qdrant, Redis, Pinecone, Weaviate, and Chroma stores refuse a `topK` that is not a positive
|
|
89
|
+
integer with a `RangeError`. An absent `topK`, or 0, still means 5.
|
|
90
|
+
- A replacement in Chroma removes the metadata fields the new version lacks; before, Chroma merged
|
|
91
|
+
them. A Weaviate filter is typed by the collection's schema, so a value of another type than its
|
|
92
|
+
property matches nothing instead of failing the search.
|
|
93
|
+
|
|
94
|
+
### Graduation
|
|
95
|
+
|
|
96
|
+
The Qdrant, Redis, Weaviate, and Chroma vector stores leave experimental status, by the same
|
|
97
|
+
checklist as in 2.4. The live evidence comes from the scheduled live workflow, which runs every
|
|
98
|
+
check against each server; the stand-in evidence runs in CI on every change.
|
|
99
|
+
|
|
100
|
+
**The remote vector stores** (`QdrantVectorStore`, `RedisVectorStore`, `WeaviateVectorStore`,
|
|
101
|
+
`ChromaVectorStore`):
|
|
102
|
+
|
|
103
|
+
| Requirement | Evidence |
|
|
104
|
+
| --- | --- |
|
|
105
|
+
| API stability | Covered by the 2.x compatibility rules, with no planned breaking change |
|
|
106
|
+
| Conformance | The vector store contract and typed filters, against each real server, Redis over RESP3 and RESP2: `tests/vector-stores.live.ts`; against stand-ins that fail as the servers do: `tests/vector-stores.test.ts` |
|
|
107
|
+
| Crash recovery | n/a: a store keeps no run state, and a reload upserts the same ids |
|
|
108
|
+
| Concurrency | Ten writers replacing the same twenty ids at once leave each id as one writer's version, found only by that writer's filters, live and against stand-ins that interleave as a network does |
|
|
109
|
+
| Load | 2,000 chunks written, then 200 searches within a p95 budget of 200 ms on each server: `tests/vector-stores.live.ts` |
|
|
110
|
+
| Tenant isolation | Each store under `tenantVectorStore()`, live and in `tests/tenant-isolation.test.ts` |
|
|
111
|
+
| Security | [Review](./SECURITY.md#the-qdrant-redis-weaviate-and-chroma-vector-stores): four findings fixed, two documented limitations |
|
|
112
|
+
| Upgrade | What the published 2.7.0 wrote is read, filtered, replaced, and deleted by this release, live and in `tests/upgrade-remote-stores.test.ts` |
|
|
113
|
+
| Soak | 1,000 write, search, and delete cycles on each server, with the heap within 8 MB |
|
|
114
|
+
|
|
115
|
+
Chroma graduates in both modes. Without `filterFields`, two writers replacing one id at once can
|
|
116
|
+
leave a stale filter field, which its guide states; with `filterFields`, a replacement stays whole
|
|
117
|
+
under any race.
|
|
118
|
+
|
|
119
|
+
**Still experimental**, each with what remains:
|
|
120
|
+
- **The Pinecone store.** It passes every check against a stand-in, and the live workflow runs the
|
|
121
|
+
same checks against Pinecone once the repository's Pinecone secret is set.
|
|
122
|
+
- **Images.** Recorded live conformance must pass on all three backends. The live workflow records it
|
|
123
|
+
for each backend whose credential is set.
|
|
124
|
+
|
|
44
125
|
## 2.7 stage (2.7.0)
|
|
45
126
|
|
|
46
127
|
Everything 2.7 adds is stable from the start and additive.
|
|
@@ -996,7 +1077,8 @@ accounts are experimental in production readiness. Their contracts follow the 1.
|
|
|
996
1077
|
## Retrieval breadth stage (1.22.0)
|
|
997
1078
|
|
|
998
1079
|
The loaders, the SQLite vector store, the retrievers, and the MCP registry graduated in 2.4; see the
|
|
999
|
-
2.4 stage for their evidence. The Redis,
|
|
1080
|
+
2.4 stage for their evidence. The Redis, Weaviate, and Chroma stores graduated in 2.8; see the 2.8
|
|
1081
|
+
stage. The Pinecone store remains experimental.
|
|
1000
1082
|
|
|
1001
1083
|
The loaders (`nexus-ai-pro/loaders/*`), the Redis, Pinecone, Weaviate, Chroma, and SQLite vector
|
|
1002
1084
|
stores, the retrievers (`nexus-ai-pro/rag/retrievers`), and the MCP registry
|
|
@@ -1028,8 +1110,8 @@ are experimental in production readiness. Their contracts follow the 1.x rules.
|
|
|
1028
1110
|
|
|
1029
1111
|
## Retrieval stores stage (1.20.0)
|
|
1030
1112
|
|
|
1031
|
-
`PostgresVectorStore` graduated in 2.4
|
|
1032
|
-
|
|
1113
|
+
`PostgresVectorStore` graduated in 2.4, and `QdrantVectorStore` in 2.8; see those stages for their
|
|
1114
|
+
evidence.
|
|
1033
1115
|
|
|
1034
1116
|
`PostgresVectorStore` (`nexus-ai-pro/postgres/vectors`) and `QdrantVectorStore` (`nexus-ai-pro/rag/qdrant`)
|
|
1035
1117
|
are experimental in production readiness. The `VectorStore` contract they share with
|
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,137 @@ Notable changes to this project are recorded here. The format follows [Keep a Ch
|
|
|
4
4
|
|
|
5
5
|
## [Unreleased]
|
|
6
6
|
|
|
7
|
+
## [2.8.0] - 2026-10-14
|
|
8
|
+
|
|
9
|
+
Retrieval at production scale, and media that is understood.
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- **Graduation.** The Qdrant, Redis, Weaviate, and Chroma vector stores leave experimental status.
|
|
14
|
+
Each passes its contract and the graduation checklist against the real server in the scheduled
|
|
15
|
+
live workflow: ten writers racing on the same ids, what 2.7.0 wrote read by this release, tenant
|
|
16
|
+
isolation, a load budget, and a soak. The evidence is in `API_STABILITY.md`, and the threat review
|
|
17
|
+
in `SECURITY.md`. The Pinecone store passes the same checks against a stand-in, and graduates once
|
|
18
|
+
the live workflow runs them against Pinecone.
|
|
19
|
+
- **A shared embedding cache.** `embeddings.cache.store` takes an `EmbeddingCacheStore`, which
|
|
20
|
+
reads every input of a request in one `getMany()` and writes what was embedded in one `setMany()`.
|
|
21
|
+
Keys are SHA-256 hashes from `embeddingCacheKey()`, so no text is a key, and vectors are packed
|
|
22
|
+
float32. On `nexus-ai-pro/embeddings/cache`: `MemoryEmbeddingCache`, `RedisEmbeddingCache` (one
|
|
23
|
+
`MGET` and one script a batch, or a command a key on Redis Cluster), `tieredEmbeddingCache()`, and
|
|
24
|
+
`packVector()` with `unpackVector()`. `PostgresEmbeddingCache` is on
|
|
25
|
+
`nexus-ai-pro/postgres/embedding-cache`, and `SqliteEmbeddingCache` on
|
|
26
|
+
`nexus-ai-pro/sqlite/embedding-cache`, each with its versioned migrations and `purgeExpired()`.
|
|
27
|
+
- **Images, audio, and documents as embedding input.** An `EmbeddingInput` may hold `EmbeddingParts`:
|
|
28
|
+
the text, image, audio, and document parts a message takes, embedded as one vector in the same
|
|
29
|
+
space as text. A model takes the `EmbeddingModality` kinds its registry entry or adapter declares in
|
|
30
|
+
`inputModalities`, and anything else is refused before any call; a fallback that cannot take the
|
|
31
|
+
media is skipped. An adapter receives each input's parts in `EmbeddingProviderRequest.contents`,
|
|
32
|
+
media already resolved to base64 or a URL. Google sends media inline or by a Files API URI, and
|
|
33
|
+
writes `gemini-embedding-2`'s task as the text prefix that model reads instead of a task type; Cohere
|
|
34
|
+
sends text and data-URI images as `inputs`. `gemini-embedding-2` joins the registry, with
|
|
35
|
+
`costPerImage`, and `embed-v4.0` takes images. `MockEmbeddingProviderOptions.describeMedia` puts a
|
|
36
|
+
medium and its caption in one space for tests.
|
|
37
|
+
- **A batch tier for embeddings**, on the new `nexus-ai-pro/embeddings/batch`: `EmbeddingBatchManager`
|
|
38
|
+
submits, polls, collects, and prices at the provider's batch rate, usually half, with `submit()`,
|
|
39
|
+
`start()`, `resume()`, `status()`, and `cancel()`. Adapters: `OpenAIEmbeddingBatchProvider` on
|
|
40
|
+
`/openai`, `GoogleEmbeddingBatchProvider` (`asyncBatchEmbedContent`, media included) on `/google`,
|
|
41
|
+
and `MockEmbeddingBatchProvider` on `/mock`. `batchEmbedder()` gives an ingestion pipeline a batch
|
|
42
|
+
tier.
|
|
43
|
+
- **Ingestion through a batch tier.** `IngestionPipelineOptions.batchEmbed` takes a batch tier in
|
|
44
|
+
place of `embed`. Chunks are gathered into windows, each one provider batch, with `batchesInFlight`
|
|
45
|
+
(4) outstanding, and written in order. A durable run records each batch the moment it is
|
|
46
|
+
submitted, and a retry collects it rather than submitting it again. `IngestionReport` counts
|
|
47
|
+
`batches` and `batchesRecovered`.
|
|
48
|
+
- **Streaming asset stores.** `AssetStore` gains the optional `putStream()` and `getStream()`, and
|
|
49
|
+
`putAssetStream()` with `readAssetStream()` stream through any store, falling back to `put()` and
|
|
50
|
+
`get()`. The filesystem and S3 stores write a stream a chunk at a time, checking its size limit and
|
|
51
|
+
checksum as it flows and leaving nothing behind when either fails, and read it back whole or by an
|
|
52
|
+
`AssetByteRange`. `S3LikeClient` takes an optional `putObjectStream()` and `getObjectStream()`.
|
|
53
|
+
- **Registry data on its own**, on the new `nexus-ai-pro/models/data`: the model and embedding
|
|
54
|
+
registries as a `RegistryData` file (`nexus-registry/1`) the application supplies.
|
|
55
|
+
`checkRegistryData()` and `parseRegistryData()` name every problem with its path,
|
|
56
|
+
`withRegistryData()` layers a file under the application's own entries and over the bundled ones,
|
|
57
|
+
`bundledRegistryData()` exports the bundled data, and `diffRegistryData()` compares two files.
|
|
58
|
+
`models.verifiedAt` measures freshness from the file, in `checkRegistryFreshness()` and `nexus
|
|
59
|
+
doctor`, which takes the configuration as `models`. `nexus models export`, `check`, and `refresh`
|
|
60
|
+
work with the file; `refresh` compares it with each provider's own model list.
|
|
61
|
+
- **Media understanding**, on the new `nexus-ai-pro/media`: `MediaManager` reads a document's or an
|
|
62
|
+
image's text page by page, describes an image, and answers a question about media, routing each
|
|
63
|
+
task to the provider named, its default, or the first that can, and running each call as one
|
|
64
|
+
`media` operation of the client's lifecycle. `modelMediaProvider()` does all three through any
|
|
65
|
+
vision model and the client's own `complete()`; `MistralOcrProvider`, on `/mistral`, reads PDFs,
|
|
66
|
+
slides, and images into Markdown pages with their sizes and picture boxes; `MockMediaProvider`, on
|
|
67
|
+
`/mock`, stands in for tests. `runMediaConformance()` checks any provider. `OperationFamily` gains
|
|
68
|
+
`media`.
|
|
69
|
+
- **Media search and RAG**, on the new `nexus-ai-pro/media/rag`: `createMediaIndex()` keeps media in
|
|
70
|
+
any vector store as their pages' text, captions, and, on a model that takes them, their own
|
|
71
|
+
vectors, and keeps each medium in an asset store, or by its URL, so a hit can hand it back.
|
|
72
|
+
`search()` returns each medium once at its best chunk, `resolve()` returns the medium, and
|
|
73
|
+
`answerFromMedia()` hands the model the retrieved media themselves. `AssetProvenance.operation`
|
|
74
|
+
takes `upload`, for media an application brings in.
|
|
75
|
+
- `ChromaVectorStoreOptions.filterFields`: the fields a search can filter on. Every write then sets
|
|
76
|
+
each declared field, or removes it, so a replacement needs no read and stays whole under any race;
|
|
77
|
+
a filter on another field is refused.
|
|
78
|
+
|
|
79
|
+
### Changed
|
|
80
|
+
|
|
81
|
+
- The Qdrant, Redis, Pinecone, Weaviate, and Chroma stores refuse a `topK` that is not a positive
|
|
82
|
+
integer, before any request. An absent `topK`, or 0, still means 5.
|
|
83
|
+
- `RedisVectorStore` replaces a chunk with one atomic script instead of a delete and a write.
|
|
84
|
+
- An embedding `cache.adapter` is asked for every input at once, where it was asked for one input
|
|
85
|
+
after another: a 2,000-text request made 2,000 sequential reads. Its keys are unchanged, so
|
|
86
|
+
processes of this release and the last share entries during a rollout.
|
|
87
|
+
|
|
88
|
+
### Fixed
|
|
89
|
+
|
|
90
|
+
- `RedisVectorStore` failed on every command with an ioredis client, which also has a
|
|
91
|
+
`sendCommand()` that takes its own command object; it now uses `call()` whenever a client has it.
|
|
92
|
+
It also reads a search reply in RESP3, which ioredis 6 speaks by default, as well as RESP2.
|
|
93
|
+
- `WeaviateVectorStore` failed a search whose filter value had another type than its property, such
|
|
94
|
+
as `'3'` on a number. It now chooses the operand from the collection's schema, read once, so such a
|
|
95
|
+
filter matches nothing, as in every other store, and an `int` property gets `valueInt`.
|
|
96
|
+
- A `topK` from a request could change a Weaviate or Redis query, since both placed it in the query
|
|
97
|
+
text.
|
|
98
|
+
- A replacement could keep a filter field the new version lacks, so a filter, such as a tenant's,
|
|
99
|
+
still found the chunk by its old value. In Chroma, which merges metadata, it happened on every
|
|
100
|
+
replacement, and kept a replaced `source` too; in Redis, when two writers raced.
|
|
101
|
+
- `BatchManager` submitted a batch again when a worker died after submitting it and before collecting
|
|
102
|
+
it, so the provider ran, and billed, both. A submission now records its batch the moment it exists,
|
|
103
|
+
and a later attempt collects that one.
|
|
104
|
+
- `OpenAIBatchProvider` read only the output file, so every request that failed was missing from the
|
|
105
|
+
results; it now reads the error file too. It also refuses the `/v1/embeddings` endpoint its options
|
|
106
|
+
offered, since it sent chat bodies there: embeddings are batched by `OpenAIEmbeddingBatchProvider`.
|
|
107
|
+
- After two writers replaced one object, Weaviate's filter index could return it for a value it no
|
|
108
|
+
longer had. Every filtered hit is now checked against the object's own fields, and the store asks
|
|
109
|
+
for more when a stale entry took a place.
|
|
110
|
+
|
|
111
|
+
### Proof
|
|
112
|
+
|
|
113
|
+
- `npm run test:vectors:live` runs the contract and the graduation checklist against each server,
|
|
114
|
+
Redis over RESP3 and RESP2, and passes 35 of 35 checks locally against Qdrant, Weaviate 1.40.1,
|
|
115
|
+
Chroma 1.0, and Redis Stack with ioredis 6.0.0. The scheduled workflow keeps its measurements.
|
|
116
|
+
- The stand-ins now fail as the servers do: an ioredis-shaped client, RESP3 replies, Weaviate's typed
|
|
117
|
+
filter errors and stale filter entries, Chroma's merged metadata, and a seeded network delay that
|
|
118
|
+
interleaves racing writers. Each failure above reproduces against them on the previous code.
|
|
119
|
+
- `tests/upgrade-remote-stores.test.ts` reads, with this release, what the published 2.7.0 wrote into
|
|
120
|
+
each store.
|
|
121
|
+
- `tests/media-rag.test.ts`: with stand-in models, answers given the retrieved charts are right on
|
|
122
|
+
every question, and answers from the same hits' text on none.
|
|
123
|
+
- `tests/media.test.ts`: the vision-model, Mistral OCR, and mock providers pass the media conformance
|
|
124
|
+
suite, and the wire shapes each sends are asserted.
|
|
125
|
+
- `tests/registry-data.test.ts`: a price raised tenfold in a supplied file makes the next call cost
|
|
126
|
+
ten times as much, for completions and embeddings alike.
|
|
127
|
+
- `npm run bench:streams`, a step of the release gate: a gigabyte goes through the filesystem and S3
|
|
128
|
+
stores and back while memory grows by less than 128 MB.
|
|
129
|
+
- `tests/embedding-batch.test.ts`: an ingestion of 100,000 chunks through a batch tier dies while it
|
|
130
|
+
collects its third window, and across both attempts each of its ten windows is submitted once;
|
|
131
|
+
without the recorded batches, two are submitted twice.
|
|
132
|
+
- `tests/embeddings-media.test.ts`: a text query finds the image it describes through one vector
|
|
133
|
+
space, and media never reaches a model that takes text only.
|
|
134
|
+
- `tests/embedding-cache.test.ts`: a second process embeds a 2,000-text batch with no provider call
|
|
135
|
+
and one cache read, and every store keeps one contract, which the live suite also runs against
|
|
136
|
+
Redis over RESP3 and RESP2.
|
|
137
|
+
|
|
7
138
|
## [2.7.0] - 2026-10-12
|
|
8
139
|
|
|
9
140
|
Agents that do more, and evaluation that runs on its own.
|
|
@@ -2321,7 +2452,8 @@ shared policy vocabulary is in place for a future release that revisits this.
|
|
|
2321
2452
|
- URL fetching rejects unsafe private-network targets and limits response reads.
|
|
2322
2453
|
- CLI and audit findings no longer disclose detected secret values.
|
|
2323
2454
|
|
|
2324
|
-
[Unreleased]: https://github.com/mkhitar-abrahamyan/nexus-ai/compare/v2.
|
|
2455
|
+
[Unreleased]: https://github.com/mkhitar-abrahamyan/nexus-ai/compare/v2.8.0...HEAD
|
|
2456
|
+
[2.8.0]: https://github.com/mkhitar-abrahamyan/nexus-ai/compare/v2.7.0...v2.8.0
|
|
2325
2457
|
[2.7.0]: https://github.com/mkhitar-abrahamyan/nexus-ai/compare/v2.6.0...v2.7.0
|
|
2326
2458
|
[2.6.0]: https://github.com/mkhitar-abrahamyan/nexus-ai/compare/v2.5.0...v2.6.0
|
|
2327
2459
|
[2.5.0]: https://github.com/mkhitar-abrahamyan/nexus-ai/compare/v2.4.0...v2.5.0
|
package/README.md
CHANGED
|
@@ -155,6 +155,7 @@ from the doc comments. The guides live in the repository, so these links go to G
|
|
|
155
155
|
| [Loaders](https://github.com/mkhitar-abrahamyan/nexus-ai/blob/main/docs/loaders.md) | Files, Markdown, HTML, CSV, JSON, PDF, web pages, sitemaps, and Git repositories into retrieval |
|
|
156
156
|
| [Retrieval](https://github.com/mkhitar-abrahamyan/nexus-ai/blob/main/docs/retrieval.md) | Hybrid search, reranking, MMR, parent documents, and Redis, Pinecone, Weaviate, and Chroma stores |
|
|
157
157
|
| [Embeddings and retrieval](https://github.com/mkhitar-abrahamyan/nexus-ai/blob/main/docs/embeddings.md) | Embeddings as a routed operation family, and RAG helpers |
|
|
158
|
+
| [Media understanding](https://github.com/mkhitar-abrahamyan/nexus-ai/blob/main/docs/media.md) | Reading documents and images page by page, describing images, and answering questions about them, through any vision model or OCR |
|
|
158
159
|
| [Images (experimental)](https://github.com/mkhitar-abrahamyan/nexus-ai/blob/main/docs/images.md) | Generation and masked edits over three backends, input safety, moderation, asset stores |
|
|
159
160
|
| [Voice](https://github.com/mkhitar-abrahamyan/nexus-ai/blob/main/docs/voice.md) | Transcription, speech, voice turns, and voice sessions |
|
|
160
161
|
| [Realtime voice](https://github.com/mkhitar-abrahamyan/nexus-ai/blob/main/docs/realtime.md) | Browser and server realtime sessions with barge-in, tools, and exports |
|
|
@@ -279,11 +280,17 @@ Shipped so far:
|
|
|
279
280
|
- 2.7 agents that do more, and evaluation that runs on its own: workspace search and a multimodal
|
|
280
281
|
workspace, a container sandbox, an interpreter, helpers that run in the background and survive a
|
|
281
282
|
crash, and tool search on every provider; datasets generated from documents and from the
|
|
282
|
-
guardrails' attacks; and online evaluation on workers, within a budget
|
|
283
|
+
guardrails' attacks; and online evaluation on workers, within a budget;
|
|
284
|
+
- 2.8 retrieval at production scale, and media that is understood: the Qdrant, Redis, Weaviate, and
|
|
285
|
+
Chroma stores out of experimental after their checklist ran against the real servers; a shared
|
|
286
|
+
embedding cache; images, audio, and documents as embedding input; a half-price embedding batch tier
|
|
287
|
+
that ingestion survives a crash through; streaming asset stores; registry data you supply and
|
|
288
|
+
refresh; and reading, describing, and searching media, with answers given the media themselves.
|
|
283
289
|
|
|
284
290
|
Upgrading from 1.x: `npx nexus migrate src --write` moves your imports, and
|
|
285
291
|
[MIGRATING.md](https://github.com/mkhitar-abrahamyan/nexus-ai/blob/main/MIGRATING.md) covers the rest.
|
|
286
|
-
Next, the
|
|
292
|
+
Next, Pinecone, images, the Gemini embedding batch tier, and media understanding graduate once the
|
|
293
|
+
live workflow passes against each. The
|
|
287
294
|
[roadmap](https://github.com/mkhitar-abrahamyan/nexus-ai/blob/main/ROADMAP.md) lists what comes after, in the order
|
|
288
295
|
applications ask for it.
|
|
289
296
|
|
package/SECURITY.md
CHANGED
|
@@ -52,7 +52,7 @@ what it could do with that input. Each review is published here with its finding
|
|
|
52
52
|
before the surface graduates. A finding is closed in one of two ways: by a fix with a test that
|
|
53
53
|
names the attack, or by a documented limitation that the surface's guide states.
|
|
54
54
|
|
|
55
|
-
These reviews were done for 2.4, and for 2.5 where a review says so.
|
|
55
|
+
These reviews were done for 2.4, and for 2.5 and 2.8 where a review says so.
|
|
56
56
|
|
|
57
57
|
### SQLite adapters
|
|
58
58
|
|
|
@@ -77,6 +77,46 @@ Trust boundary: metadata filters, which applications often build from a request.
|
|
|
77
77
|
|
|
78
78
|
Findings: none.
|
|
79
79
|
|
|
80
|
+
### The Qdrant, Redis, Weaviate, and Chroma vector stores
|
|
81
|
+
|
|
82
|
+
Reviewed for 2.8, when they graduated. Pinecone's adapter was reviewed with them.
|
|
83
|
+
|
|
84
|
+
Trust boundary: a search's `topK` and metadata filter, which applications often build from a
|
|
85
|
+
request; and the server, which the store trusts as it trusts its own database. Credentials travel
|
|
86
|
+
only in headers, never in a URL or an error message.
|
|
87
|
+
- Qdrant, Pinecone, and Chroma receive a filter as JSON. Qdrant's keys are placed under `metadata.`,
|
|
88
|
+
so a filter cannot reach a chunk's content or vector.
|
|
89
|
+
- Redis filters only on the fields the index declares. A filter value is tagged with its type, and
|
|
90
|
+
every character that is not a letter or a digit is escaped.
|
|
91
|
+
- Weaviate's query is GraphQL. The collection and every filtered property must be a valid name, and
|
|
92
|
+
each value is a quoted literal.
|
|
93
|
+
|
|
94
|
+
Findings:
|
|
95
|
+
- **Fixed in 2.8: a `topK` from a request could change a Weaviate or Redis query.** Both stores
|
|
96
|
+
placed it in the query text, so `5) { … }` became part of the query. Every remote store now refuses
|
|
97
|
+
a `topK` that is not a positive integer before anything is sent. Proof: that value, a fraction, a
|
|
98
|
+
negative number, and `NaN` are refused by all five stores.
|
|
99
|
+
- **Fixed in 2.8: a replacement could keep a filter field the new version lacks.** A filter could
|
|
100
|
+
then still find the chunk by its old value, and that includes the `tenantId` that
|
|
101
|
+
`tenantVectorStore()` filters on.
|
|
102
|
+
- Chroma merges metadata on upsert, so it happened on every replacement.
|
|
103
|
+
- Redis deleted and rewrote a chunk in two commands, so it happened when two writers raced.
|
|
104
|
+
|
|
105
|
+
Chroma now removes each field the new version lacks, and Redis replaces a chunk in one atomic
|
|
106
|
+
script. Proof: ten writers race on the same twenty ids, live and against stand-ins that interleave
|
|
107
|
+
as a network does, and each id ends as exactly one writer's version.
|
|
108
|
+
- **Fixed in 2.8: Weaviate's filter index can keep an entry for a value an object no longer has**,
|
|
109
|
+
after two writers replace it at once (seen on Weaviate 1.40.1). The store now checks every filtered
|
|
110
|
+
hit against the object's own fields, and asks for more when a stale entry took a place. A result
|
|
111
|
+
always matches its filter.
|
|
112
|
+
- **Documented limitation: Chroma without `filterFields` reads before it replaces**, so two writers
|
|
113
|
+
replacing one id at once can leave a stale field. With `filterFields`, every write sets each
|
|
114
|
+
declared field, and a replacement stays whole under any race.
|
|
115
|
+
- **Documented limitation: the Redis store has no timeout of its own.** It sends through the client
|
|
116
|
+
you pass, so the client's command timeout applies.
|
|
117
|
+
- `tenantVectorStore()` checks each result's id and tenant stamp as well as filtering, so a stale
|
|
118
|
+
filter entry in any server cannot hand one tenant another's chunk.
|
|
119
|
+
|
|
80
120
|
### Loaders
|
|
81
121
|
|
|
82
122
|
Trust boundary: everything a loader reads is untrusted. A repository, a website, a sitemap, or an
|
package/dist/batch/manager.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { isTerminalBatchStatus } from '../types/batch.js';
|
|
2
1
|
import { OperationRunner } from '../operations/runner.js';
|
|
3
2
|
import { estimateCost } from '../optimizer/cost.js';
|
|
4
3
|
import { DEFAULT_CURRENCY } from '../optimizer/cost.js';
|
|
5
4
|
import { generateRequestId } from '../utils/ids.js';
|
|
6
5
|
import { withLifecycle } from '../lifecycle/run.js';
|
|
7
6
|
import { BatchCapabilityError, BatchProviderNotFoundError, BatchValidationError } from './errors.js';
|
|
7
|
+
import { pollUntilSettled } from './poll.js';
|
|
8
8
|
const DEFAULT_POLL_INTERVAL_MS = 30_000;
|
|
9
9
|
const DEFAULT_MAX_POLL_INTERVAL_MS = 300_000;
|
|
10
10
|
const DEFAULT_TIMEOUT_MS = 26 * 60 * 60 * 1000;
|
|
@@ -58,7 +58,11 @@ export class BatchManager {
|
|
|
58
58
|
idempotencyKey: request.idempotencyKey,
|
|
59
59
|
attempt: operation.attempt,
|
|
60
60
|
};
|
|
61
|
-
|
|
61
|
+
let ref = operation.previousHeartbeat?.batchRef;
|
|
62
|
+
if (!ref) {
|
|
63
|
+
ref = await provider.submit(request, context);
|
|
64
|
+
await operation.heartbeat({ batchRef: ref });
|
|
65
|
+
}
|
|
62
66
|
operation.report({ completed: 0, total: request.items.length, message: `submitted as ${ref.id}` });
|
|
63
67
|
return this.collect(provider, ref, request, operation, context);
|
|
64
68
|
}, (result) => ({ cost: result.cost.amount })), {
|
|
@@ -103,22 +107,16 @@ export class BatchManager {
|
|
|
103
107
|
});
|
|
104
108
|
}
|
|
105
109
|
async collect(provider, ref, request, operation, context) {
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
message: state.status,
|
|
117
|
-
});
|
|
118
|
-
await delay(interval, context.signal);
|
|
119
|
-
interval = Math.min(Math.round(interval * 1.5), maxInterval);
|
|
120
|
-
state = await provider.poll(ref, context);
|
|
121
|
-
}
|
|
110
|
+
const state = await pollUntilSettled(() => provider.poll(ref, context), {
|
|
111
|
+
intervalMs: request.pollIntervalMs ?? this.config.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS,
|
|
112
|
+
maxIntervalMs: this.config.maxPollIntervalMs ?? DEFAULT_MAX_POLL_INTERVAL_MS,
|
|
113
|
+
signal: context.signal,
|
|
114
|
+
onState: (current) => operation?.report({
|
|
115
|
+
completed: current.counts?.completed,
|
|
116
|
+
total: current.counts?.total,
|
|
117
|
+
message: current.status,
|
|
118
|
+
}),
|
|
119
|
+
});
|
|
122
120
|
const items = state.status === 'completed' ? await provider.results(ref, context) : [];
|
|
123
121
|
const counts = state.counts ?? countItems(items, request.items?.length);
|
|
124
122
|
const usage = sumUsage(items);
|
|
@@ -232,18 +230,3 @@ function sumUsage(items) {
|
|
|
232
230
|
}
|
|
233
231
|
return { inputTokens, outputTokens, totalTokens: inputTokens + outputTokens };
|
|
234
232
|
}
|
|
235
|
-
function delay(ms, signal) {
|
|
236
|
-
if (ms <= 0)
|
|
237
|
-
return Promise.resolve();
|
|
238
|
-
return new Promise((resolve) => {
|
|
239
|
-
const timer = setTimeout(() => {
|
|
240
|
-
signal?.removeEventListener('abort', onAbort);
|
|
241
|
-
resolve();
|
|
242
|
-
}, ms);
|
|
243
|
-
function onAbort() {
|
|
244
|
-
clearTimeout(timer);
|
|
245
|
-
resolve();
|
|
246
|
-
}
|
|
247
|
-
signal?.addEventListener('abort', onAbort, { once: true });
|
|
248
|
-
});
|
|
249
|
-
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { BatchJobRef, BatchJobState, BatchProviderCallContext } from '../types/batch.js';
|
|
2
|
+
/** What every OpenAI batch adapter needs to reach the API. */
|
|
3
|
+
export interface OpenAIBatchClientOptions {
|
|
4
|
+
/** OpenAI API key. */
|
|
5
|
+
apiKey: string;
|
|
6
|
+
/** API base URL. Defaults to `https://api.openai.com/v1`. */
|
|
7
|
+
baseUrl?: string;
|
|
8
|
+
/** Sent as the `OpenAI-Organization` header. */
|
|
9
|
+
organization?: string;
|
|
10
|
+
/** Headers added to every request. */
|
|
11
|
+
headers?: Record<string, string>;
|
|
12
|
+
/** Replaces the global `fetch`. */
|
|
13
|
+
fetch?: typeof fetch;
|
|
14
|
+
}
|
|
15
|
+
/** OpenAI's batch object, as far as the adapters read it. */
|
|
16
|
+
export interface OpenAIBatchPayload {
|
|
17
|
+
id?: string;
|
|
18
|
+
status?: string;
|
|
19
|
+
output_file_id?: string | null;
|
|
20
|
+
error_file_id?: string | null;
|
|
21
|
+
created_at?: number;
|
|
22
|
+
completed_at?: number;
|
|
23
|
+
expires_at?: number;
|
|
24
|
+
request_counts?: {
|
|
25
|
+
total?: number;
|
|
26
|
+
completed?: number;
|
|
27
|
+
failed?: number;
|
|
28
|
+
};
|
|
29
|
+
errors?: {
|
|
30
|
+
data?: Array<{
|
|
31
|
+
message?: string;
|
|
32
|
+
code?: string;
|
|
33
|
+
}>;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/** One line of a batch's output or error file. */
|
|
37
|
+
export interface OpenAIBatchLine {
|
|
38
|
+
custom_id?: string;
|
|
39
|
+
response?: {
|
|
40
|
+
status_code?: number;
|
|
41
|
+
body?: Record<string, unknown>;
|
|
42
|
+
};
|
|
43
|
+
error?: {
|
|
44
|
+
message?: string;
|
|
45
|
+
code?: string;
|
|
46
|
+
} | null;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* OpenAI's Batch API wire protocol, shared by the completion and embedding adapters: a JSONL upload,
|
|
50
|
+
* a batch pointing at it, and JSONL downloads of what succeeded and what failed.
|
|
51
|
+
*/
|
|
52
|
+
export declare class OpenAIBatchClient {
|
|
53
|
+
private readonly options;
|
|
54
|
+
constructor(options: OpenAIBatchClientOptions);
|
|
55
|
+
/** Uploads the lines as a JSONL file and creates a batch over them. */
|
|
56
|
+
create(lines: readonly unknown[], batch: {
|
|
57
|
+
endpoint: string;
|
|
58
|
+
completionWindow?: string;
|
|
59
|
+
metadata?: Record<string, string>;
|
|
60
|
+
}, context: BatchProviderCallContext): Promise<{
|
|
61
|
+
batch: OpenAIBatchPayload;
|
|
62
|
+
fileId: string;
|
|
63
|
+
}>;
|
|
64
|
+
/** Reads a batch. */
|
|
65
|
+
read(id: string, context: BatchProviderCallContext): Promise<OpenAIBatchPayload>;
|
|
66
|
+
/** Cancels a batch. */
|
|
67
|
+
cancel(id: string, context: BatchProviderCallContext): Promise<OpenAIBatchPayload>;
|
|
68
|
+
/**
|
|
69
|
+
* Every line a finished batch wrote: the output file holds what succeeded and the error file what
|
|
70
|
+
* failed, so both are read, or a failed request would be missing from the results altogether.
|
|
71
|
+
*/
|
|
72
|
+
lines(id: string, context: BatchProviderCallContext): Promise<OpenAIBatchLine[]>;
|
|
73
|
+
/** A batch as the neutral state. */
|
|
74
|
+
state(ref: BatchJobRef, batch: OpenAIBatchPayload): BatchJobState;
|
|
75
|
+
private json;
|
|
76
|
+
private send;
|
|
77
|
+
}
|
|
78
|
+
/** A failed line's reason: the error the line carries, or the error body of its response. */
|
|
79
|
+
export declare function lineError(line: OpenAIBatchLine): {
|
|
80
|
+
message: string;
|
|
81
|
+
code?: string;
|
|
82
|
+
status?: number;
|
|
83
|
+
} | undefined;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { BatchProviderResponseError } from './errors.js';
|
|
2
|
+
const STATUS_MAP = {
|
|
3
|
+
validating: 'validating',
|
|
4
|
+
in_progress: 'in_progress',
|
|
5
|
+
finalizing: 'finalizing',
|
|
6
|
+
completed: 'completed',
|
|
7
|
+
failed: 'failed',
|
|
8
|
+
expired: 'expired',
|
|
9
|
+
cancelling: 'cancelling',
|
|
10
|
+
cancelled: 'cancelled',
|
|
11
|
+
};
|
|
12
|
+
export class OpenAIBatchClient {
|
|
13
|
+
options;
|
|
14
|
+
constructor(options) {
|
|
15
|
+
this.options = options;
|
|
16
|
+
}
|
|
17
|
+
async create(lines, batch, context) {
|
|
18
|
+
const form = new FormData();
|
|
19
|
+
form.append('purpose', 'batch');
|
|
20
|
+
form.append('file', new Blob([lines.map((line) => JSON.stringify(line)).join('\n')], { type: 'application/jsonl' }), 'batch.jsonl');
|
|
21
|
+
const file = (await this.json('/files', { method: 'POST', body: form }, context));
|
|
22
|
+
if (!file.id)
|
|
23
|
+
throw new BatchProviderResponseError('openai', 'the file upload returned no id');
|
|
24
|
+
const created = (await this.json('/batches', {
|
|
25
|
+
method: 'POST',
|
|
26
|
+
headers: { 'content-type': 'application/json' },
|
|
27
|
+
body: JSON.stringify({
|
|
28
|
+
input_file_id: file.id,
|
|
29
|
+
endpoint: batch.endpoint,
|
|
30
|
+
completion_window: batch.completionWindow ?? '24h',
|
|
31
|
+
metadata: batch.metadata,
|
|
32
|
+
}),
|
|
33
|
+
}, context));
|
|
34
|
+
if (!created.id)
|
|
35
|
+
throw new BatchProviderResponseError('openai', 'the batch response returned no id');
|
|
36
|
+
return { batch: created, fileId: file.id };
|
|
37
|
+
}
|
|
38
|
+
read(id, context) {
|
|
39
|
+
return this.json(`/batches/${encodeURIComponent(id)}`, {}, context);
|
|
40
|
+
}
|
|
41
|
+
cancel(id, context) {
|
|
42
|
+
return this.json(`/batches/${encodeURIComponent(id)}/cancel`, { method: 'POST' }, context);
|
|
43
|
+
}
|
|
44
|
+
async lines(id, context) {
|
|
45
|
+
const batch = await this.read(id, context);
|
|
46
|
+
const lines = [];
|
|
47
|
+
for (const fileId of [batch.output_file_id, batch.error_file_id]) {
|
|
48
|
+
if (!fileId)
|
|
49
|
+
continue;
|
|
50
|
+
const response = await this.send(`/files/${encodeURIComponent(fileId)}/content`, {}, context);
|
|
51
|
+
for (const line of (await response.text()).split('\n')) {
|
|
52
|
+
if (!line.trim())
|
|
53
|
+
continue;
|
|
54
|
+
try {
|
|
55
|
+
lines.push(JSON.parse(line));
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
throw new BatchProviderResponseError('openai', 'an output line was not valid JSON', error);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return lines;
|
|
63
|
+
}
|
|
64
|
+
state(ref, batch) {
|
|
65
|
+
const counts = batch.request_counts;
|
|
66
|
+
return {
|
|
67
|
+
ref,
|
|
68
|
+
status: STATUS_MAP[batch.status ?? ''] ?? 'in_progress',
|
|
69
|
+
counts: counts
|
|
70
|
+
? { total: counts.total ?? 0, completed: counts.completed ?? 0, failed: counts.failed ?? 0 }
|
|
71
|
+
: undefined,
|
|
72
|
+
createdAt: batch.created_at ? new Date(batch.created_at * 1000).toISOString() : undefined,
|
|
73
|
+
completedAt: batch.completed_at ? new Date(batch.completed_at * 1000).toISOString() : undefined,
|
|
74
|
+
expiresAt: batch.expires_at ? new Date(batch.expires_at * 1000).toISOString() : undefined,
|
|
75
|
+
error: batch.errors?.data?.[0]
|
|
76
|
+
? { message: batch.errors.data[0].message ?? 'batch failed', code: batch.errors.data[0].code }
|
|
77
|
+
: undefined,
|
|
78
|
+
raw: batch,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
async json(path, init, context) {
|
|
82
|
+
return (await this.send(path, init, context)).json();
|
|
83
|
+
}
|
|
84
|
+
async send(path, init, context) {
|
|
85
|
+
const fetchImpl = this.options.fetch ?? fetch;
|
|
86
|
+
const baseUrl = (this.options.baseUrl || 'https://api.openai.com/v1').replace(/\/$/, '');
|
|
87
|
+
const headers = {
|
|
88
|
+
authorization: `Bearer ${this.options.apiKey}`,
|
|
89
|
+
...(this.options.organization ? { 'openai-organization': this.options.organization } : {}),
|
|
90
|
+
...this.options.headers,
|
|
91
|
+
...(init.headers ?? {}),
|
|
92
|
+
};
|
|
93
|
+
const response = await fetchImpl(`${baseUrl}${path}`, { ...init, headers, signal: context.signal });
|
|
94
|
+
if (!response.ok) {
|
|
95
|
+
throw new BatchProviderResponseError('openai', `${path} failed: ${response.status} ${await safeText(response)}`);
|
|
96
|
+
}
|
|
97
|
+
return response;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
export function lineError(line) {
|
|
101
|
+
if (line.error)
|
|
102
|
+
return { message: line.error.message ?? 'batch item failed', code: line.error.code };
|
|
103
|
+
const status = line.response?.status_code ?? 200;
|
|
104
|
+
if (status < 400 && line.response?.body)
|
|
105
|
+
return undefined;
|
|
106
|
+
const body = line.response?.body;
|
|
107
|
+
return {
|
|
108
|
+
message: body?.error?.message ?? `batch item failed with status ${status}`,
|
|
109
|
+
...(body?.error?.code ? { code: body.error.code } : {}),
|
|
110
|
+
status,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
async function safeText(response) {
|
|
114
|
+
try {
|
|
115
|
+
return (await response.text()).slice(0, 500);
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
return '';
|
|
119
|
+
}
|
|
120
|
+
}
|