@delali/narsil 0.1.7 → 0.1.8
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 +44 -2
- package/dist/adapters/filesystem.d.ts +1 -1
- package/dist/adapters/filesystem.mjs +46 -2
- package/dist/adapters/indexeddb.d.ts +1 -1
- package/dist/adapters/indexeddb.mjs +1 -1
- package/dist/adapters/memory.d.ts +1 -1
- package/dist/{adapters-BbRkoiu9.d.ts → adapters-Bo2JQg8b.d.ts} +2 -1
- package/dist/chunk-ALB35PRQ.mjs +98 -0
- package/dist/{chunk-KHL4RPC3.mjs → chunk-FS7XLIUS.mjs} +2536 -2284
- package/dist/chunk-GQEHCZG7.mjs +6825 -0
- package/dist/chunk-KMMJMDUA.mjs +44 -0
- package/dist/chunk-RQLXC2YS.mjs +269 -0
- package/dist/chunk-S7RJJMHI.mjs +1086 -0
- package/dist/{chunk-I24SGLFS.mjs → chunk-TW6BXTOL.mjs} +5 -1
- package/dist/chunk-WISGW24C.mjs +455 -0
- package/dist/config-cQLlYR3U.d.ts +470 -0
- package/dist/direct-executor-FX56DYD3.mjs +4 -0
- package/dist/distribution/coordinator/etcd.d.ts +16 -0
- package/dist/distribution/coordinator/etcd.mjs +2 -0
- package/dist/distribution/coordinator/in-memory.d.ts +7 -0
- package/dist/distribution/coordinator/in-memory.mjs +1 -0
- package/dist/distribution.d.ts +122 -0
- package/dist/distribution.mjs +7410 -0
- package/dist/embeddings/openai.d.ts +1 -1
- package/dist/embeddings/openai.mjs +1 -1
- package/dist/index.browser.mjs +11469 -7481
- package/dist/index.d.ts +6 -450
- package/dist/index.mjs +7 -3236
- package/dist/invalidation/broadcast-channel.d.ts +1 -1
- package/dist/invalidation/filesystem.d.ts +1 -1
- package/dist/invalidation/noop.d.ts +1 -1
- package/dist/{language-ClUGLuoC.d.ts → language-ONQ3iVDf.d.ts} +1 -0
- package/dist/languages/arabic.d.ts +1 -1
- package/dist/languages/armenian.d.ts +1 -1
- package/dist/languages/bulgarian.d.ts +1 -1
- package/dist/languages/chinese.d.ts +1 -1
- package/dist/languages/dagbani.d.ts +1 -1
- package/dist/languages/danish.d.ts +1 -1
- package/dist/languages/dutch.d.ts +1 -1
- package/dist/languages/english.d.ts +1 -1
- package/dist/languages/english.mjs +1 -1
- package/dist/languages/ewe.d.ts +1 -1
- package/dist/languages/finnish.d.ts +1 -1
- package/dist/languages/french.d.ts +1 -1
- package/dist/languages/ga.d.ts +1 -1
- package/dist/languages/german.d.ts +1 -1
- package/dist/languages/greek.d.ts +1 -1
- package/dist/languages/hausa.d.ts +1 -1
- package/dist/languages/hindi.d.ts +1 -1
- package/dist/languages/hungarian.d.ts +1 -1
- package/dist/languages/igbo.d.ts +1 -1
- package/dist/languages/indonesian.d.ts +1 -1
- package/dist/languages/irish.d.ts +1 -1
- package/dist/languages/italian.d.ts +1 -1
- package/dist/languages/japanese.d.ts +1 -1
- package/dist/languages/nepali.d.ts +1 -1
- package/dist/languages/norwegian.d.ts +1 -1
- package/dist/languages/portuguese.d.ts +1 -1
- package/dist/languages/romanian.d.ts +1 -1
- package/dist/languages/russian.d.ts +1 -1
- package/dist/languages/sanskrit.d.ts +1 -1
- package/dist/languages/serbian.d.ts +1 -1
- package/dist/languages/slovenian.d.ts +1 -1
- package/dist/languages/spanish.d.ts +1 -1
- package/dist/languages/swahili.d.ts +1 -1
- package/dist/languages/swedish.d.ts +1 -1
- package/dist/languages/tamil.d.ts +1 -1
- package/dist/languages/turkish.d.ts +1 -1
- package/dist/languages/twi.d.ts +1 -1
- package/dist/languages/ukrainian.d.ts +1 -1
- package/dist/languages/yoruba.d.ts +1 -1
- package/dist/languages/zulu.d.ts +1 -1
- package/dist/narsil-ChTdkwPu.d.ts +68 -0
- package/dist/persistence/durability/checkpoint-worker.d.ts +41 -0
- package/dist/persistence/durability/checkpoint-worker.mjs +59 -0
- package/dist/schema-BVaw7nqz.d.ts +58 -0
- package/dist/serialization/crc32-worker.d.ts +20 -0
- package/dist/serialization/crc32-worker.mjs +61 -0
- package/dist/server.d.ts +218 -0
- package/dist/server.mjs +1185 -0
- package/dist/types-Bt7c4hDF.d.ts +73 -0
- package/dist/vector/hnsw-build-worker.mjs +1 -1
- package/dist/workers/entry.mjs +1 -1
- package/package.json +37 -2
- package/dist/chunk-R2C2EQGO.mjs +0 -53
- package/dist/chunk-VVORJOXR.mjs +0 -759
- package/dist/direct-executor-LBJLGMJ2.mjs +0 -4
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { N as Narsil } from './narsil-ChTdkwPu.js';
|
|
2
|
+
import { E as EmbeddingAdapter } from './adapters-Bo2JQg8b.js';
|
|
3
|
+
import './config-cQLlYR3U.js';
|
|
4
|
+
import './schema-BVaw7nqz.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Context handed to {@link OnRequestHook} for every inbound request, captured
|
|
8
|
+
* synchronously before any body is read. `remoteAddress` is the peer address
|
|
9
|
+
* decoded from the socket; behind a proxy it is the proxy's address, so trust
|
|
10
|
+
* forwarded headers only when the proxy is trusted.
|
|
11
|
+
*/
|
|
12
|
+
interface RequestContext {
|
|
13
|
+
method: string;
|
|
14
|
+
path: string;
|
|
15
|
+
headers: Record<string, string>;
|
|
16
|
+
remoteAddress: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Returned by an {@link OnRequestHook} to reject a request. The `status` is sent
|
|
20
|
+
* verbatim as the HTTP status; `code` and `message` populate the error envelope.
|
|
21
|
+
*/
|
|
22
|
+
interface RequestDenial {
|
|
23
|
+
status: number;
|
|
24
|
+
code: string;
|
|
25
|
+
message: string;
|
|
26
|
+
}
|
|
27
|
+
type OnRequestHook = (ctx: RequestContext) => undefined | RequestDenial | Promise<undefined | RequestDenial>;
|
|
28
|
+
interface CorsOptions {
|
|
29
|
+
origin?: string | string[];
|
|
30
|
+
methods?: string[];
|
|
31
|
+
headers?: string[];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Byte and batch ceilings the server enforces before handing work to the
|
|
35
|
+
* engine. Every field has a safe default; override only to fit a deployment.
|
|
36
|
+
*/
|
|
37
|
+
interface ServerLimits {
|
|
38
|
+
/** Cap for JSON request bodies (single doc, batch, search). Excess → 413. */
|
|
39
|
+
maxBodyBytes?: number;
|
|
40
|
+
/** Cap for the NDJSON import stream and binary restore body. Excess → 413. */
|
|
41
|
+
maxImportBytes?: number;
|
|
42
|
+
/** Cap for a single NDJSON line, so one unterminated line cannot exhaust memory. Excess → 413. */
|
|
43
|
+
maxLineBytes?: number;
|
|
44
|
+
/** Documents handed to the engine per batch during NDJSON import; the loop yields between batches. */
|
|
45
|
+
importBatchSize?: number;
|
|
46
|
+
/** Maximum requests executing engine work at once; excess is shed with 503. Omit or 0 to disable. */
|
|
47
|
+
maxConcurrentRequests?: number;
|
|
48
|
+
}
|
|
49
|
+
interface ServerOptions {
|
|
50
|
+
host?: string;
|
|
51
|
+
port?: number;
|
|
52
|
+
cors?: boolean | CorsOptions;
|
|
53
|
+
/** Authentication or admission gate run before every routed request. */
|
|
54
|
+
onRequest?: OnRequestHook;
|
|
55
|
+
/**
|
|
56
|
+
* Build identity reported verbatim at `/version`: the package version and the
|
|
57
|
+
* git commit the server was built from, with a dirty-tree flag. Supply it from
|
|
58
|
+
* the build (a stamped env var or build arg); omit it and `/version` reports
|
|
59
|
+
* nulls. The values are descriptive only and never gate a request.
|
|
60
|
+
*/
|
|
61
|
+
build?: {
|
|
62
|
+
version?: string;
|
|
63
|
+
gitSha?: string;
|
|
64
|
+
dirty?: boolean;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Named embedding adapters a JSON `createIndex` request can reference by name.
|
|
68
|
+
* Embedding adapters are functions and cannot cross JSON, so an index that
|
|
69
|
+
* needs query-time or ingest-time embedding names a server-registered adapter.
|
|
70
|
+
*/
|
|
71
|
+
embeddingAdapters?: Record<string, EmbeddingAdapter>;
|
|
72
|
+
limits?: ServerLimits;
|
|
73
|
+
/**
|
|
74
|
+
* Backing store for long-running task records. Defaults to an in-memory store
|
|
75
|
+
* that is lost on restart and not shared across instances. Supply any store
|
|
76
|
+
* that satisfies {@link TaskStore} (Redis, Upstash over HTTP, DynamoDB, a
|
|
77
|
+
* database) to survive restarts and share task status across instances.
|
|
78
|
+
*/
|
|
79
|
+
taskStore?: TaskStore;
|
|
80
|
+
/**
|
|
81
|
+
* Stable identifier for this server instance, stamped on every task it owns.
|
|
82
|
+
* Supply a stable value (a pod or container name) so that after a restart the
|
|
83
|
+
* instance can mark its own previously-running tasks as failed instead of
|
|
84
|
+
* leaving them stuck. Defaults to a random id, which disables that recovery.
|
|
85
|
+
*/
|
|
86
|
+
instanceId?: string;
|
|
87
|
+
/**
|
|
88
|
+
* Allows binding to a non-loopback address without an {@link onRequest} auth
|
|
89
|
+
* hook. The server otherwise refuses to start in that configuration because it
|
|
90
|
+
* exposes destructive admin endpoints. Set this only when the address is on a
|
|
91
|
+
* trusted private network where access is controlled elsewhere.
|
|
92
|
+
*/
|
|
93
|
+
allowInsecure?: boolean;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Pluggable backing store for task records. Every method is async so any
|
|
97
|
+
* backend works — an in-memory map, Redis, an HTTP key-value service, or a
|
|
98
|
+
* database. `set` upserts by `record.id`; `get` returns null for an unknown id.
|
|
99
|
+
* `ttlMs`, when honored by the backend, expires the record so terminal tasks do
|
|
100
|
+
* not accumulate. The server never calls a method that mutates a record it did
|
|
101
|
+
* not construct, so a backend may treat records as immutable snapshots.
|
|
102
|
+
*/
|
|
103
|
+
interface TaskStore {
|
|
104
|
+
set(record: TaskRecord, ttlMs?: number): Promise<void>;
|
|
105
|
+
get(id: string): Promise<TaskRecord | null>;
|
|
106
|
+
list(): Promise<TaskRecord[]>;
|
|
107
|
+
delete(id: string): Promise<void>;
|
|
108
|
+
shutdown?(): Promise<void>;
|
|
109
|
+
}
|
|
110
|
+
interface NarsilServer {
|
|
111
|
+
listen(): Promise<void>;
|
|
112
|
+
close(): Promise<void>;
|
|
113
|
+
readonly listeningPort: number;
|
|
114
|
+
}
|
|
115
|
+
interface ErrorEnvelope {
|
|
116
|
+
error: {
|
|
117
|
+
code: string;
|
|
118
|
+
message: string;
|
|
119
|
+
details?: Record<string, unknown>;
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
type TaskType = 'optimizeVectors' | 'rebalance' | 'restore';
|
|
123
|
+
type TaskStatus = 'queued' | 'running' | 'succeeded' | 'failed';
|
|
124
|
+
interface TaskRecord {
|
|
125
|
+
id: string;
|
|
126
|
+
type: TaskType;
|
|
127
|
+
indexName: string;
|
|
128
|
+
status: TaskStatus;
|
|
129
|
+
/** Identifier of the server instance running this task; see ServerOptions.instanceId. */
|
|
130
|
+
owner: string;
|
|
131
|
+
createdAt: number;
|
|
132
|
+
startedAt?: number;
|
|
133
|
+
completedAt?: number;
|
|
134
|
+
error?: {
|
|
135
|
+
code: string;
|
|
136
|
+
message: string;
|
|
137
|
+
details?: Record<string, unknown>;
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
/** Declarative index configuration accepted over HTTP. Function-valued engine
|
|
141
|
+
* options (custom tokenizer, stopWords-as-function, group reducer, embedding
|
|
142
|
+
* adapter object) are not representable here; the embedding adapter is named
|
|
143
|
+
* instead via {@link CreateIndexEmbedding}. */
|
|
144
|
+
interface CreateIndexRequest {
|
|
145
|
+
name: string;
|
|
146
|
+
config: HttpIndexConfig;
|
|
147
|
+
}
|
|
148
|
+
interface CreateIndexEmbedding {
|
|
149
|
+
adapter?: string;
|
|
150
|
+
fields: Record<string, string | string[]>;
|
|
151
|
+
}
|
|
152
|
+
interface HttpIndexConfig {
|
|
153
|
+
schema: Record<string, unknown>;
|
|
154
|
+
language?: string;
|
|
155
|
+
partitions?: {
|
|
156
|
+
maxDocsPerPartition?: number;
|
|
157
|
+
maxPartitions?: number;
|
|
158
|
+
};
|
|
159
|
+
defaultScoring?: 'local' | 'dfs' | 'broadcast';
|
|
160
|
+
bm25?: {
|
|
161
|
+
k1?: number;
|
|
162
|
+
b?: number;
|
|
163
|
+
};
|
|
164
|
+
stopWords?: string[];
|
|
165
|
+
trackPositions?: boolean;
|
|
166
|
+
vectorPromotion?: Record<string, unknown>;
|
|
167
|
+
strict?: boolean;
|
|
168
|
+
embedding?: CreateIndexEmbedding;
|
|
169
|
+
required?: string[];
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Wraps a Narsil engine in an HTTP server. The caller builds and owns the engine
|
|
174
|
+
* (durability, embedding, workers) and hands the live instance in; the server
|
|
175
|
+
* shares it across requests and never constructs or shuts it down. Start with
|
|
176
|
+
* `.listen()` and stop with `.close()`; the engine is shut down separately.
|
|
177
|
+
*/
|
|
178
|
+
declare function createServer(engine: Narsil, options?: ServerOptions): NarsilServer;
|
|
179
|
+
|
|
180
|
+
/** HTTP-layer error codes for failures that arise before or around the engine
|
|
181
|
+
* call (parsing, limits, routing). Engine failures carry their own
|
|
182
|
+
* {@link NarsilError} codes, mapped by {@link httpStatusForNarsilError}. */
|
|
183
|
+
declare const ServerErrorCodes: {
|
|
184
|
+
readonly INVALID_REQUEST: "INVALID_REQUEST";
|
|
185
|
+
readonly INVALID_JSON: "INVALID_JSON";
|
|
186
|
+
readonly EMPTY_BODY: "EMPTY_BODY";
|
|
187
|
+
readonly PAYLOAD_TOO_LARGE: "PAYLOAD_TOO_LARGE";
|
|
188
|
+
readonly UNSUPPORTED_MEDIA_TYPE: "UNSUPPORTED_MEDIA_TYPE";
|
|
189
|
+
readonly NOT_FOUND: "NOT_FOUND";
|
|
190
|
+
readonly TASK_NOT_FOUND: "TASK_NOT_FOUND";
|
|
191
|
+
readonly TOO_MANY_REQUESTS: "TOO_MANY_REQUESTS";
|
|
192
|
+
readonly HOOK_ERROR: "HOOK_ERROR";
|
|
193
|
+
readonly INTERNAL_ERROR: "INTERNAL_ERROR";
|
|
194
|
+
readonly REQUEST_ABORTED: "REQUEST_ABORTED";
|
|
195
|
+
};
|
|
196
|
+
/** Maps a {@link NarsilError} code to an HTTP status. Unknown or cluster-only
|
|
197
|
+
* codes fall through to 500 so an internal fault never leaks as a client error. */
|
|
198
|
+
declare function httpStatusForNarsilError(code: string): number;
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Default {@link TaskStore}: an in-process map, lost on restart and not shared
|
|
202
|
+
* across instances. It caps how many records it keeps and evicts the oldest
|
|
203
|
+
* terminal records first, so a long-lived server cannot accumulate task state
|
|
204
|
+
* without bound. `ttlMs` is ignored here; the cap plays that role. Records are
|
|
205
|
+
* copied in and out so a caller cannot mutate stored state by reference.
|
|
206
|
+
*/
|
|
207
|
+
declare class InMemoryTaskStore implements TaskStore {
|
|
208
|
+
private readonly maxRetained;
|
|
209
|
+
private readonly records;
|
|
210
|
+
constructor(maxRetained?: number);
|
|
211
|
+
set(record: TaskRecord): Promise<void>;
|
|
212
|
+
get(id: string): Promise<TaskRecord | null>;
|
|
213
|
+
list(): Promise<TaskRecord[]>;
|
|
214
|
+
delete(id: string): Promise<void>;
|
|
215
|
+
private prune;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export { type CorsOptions, type CreateIndexEmbedding, type CreateIndexRequest, type ErrorEnvelope, type HttpIndexConfig, InMemoryTaskStore, type NarsilServer, type OnRequestHook, type RequestContext, type RequestDenial, ServerErrorCodes, type ServerLimits, type ServerOptions, type TaskRecord, type TaskStatus, type TaskStore, type TaskType, createServer, httpStatusForNarsilError };
|