@delali/narsil 0.1.7 → 0.1.9

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.
Files changed (87) hide show
  1. package/README.md +800 -111
  2. package/dist/adapters/filesystem.d.ts +1 -1
  3. package/dist/adapters/filesystem.mjs +46 -2
  4. package/dist/adapters/indexeddb.d.ts +1 -1
  5. package/dist/adapters/indexeddb.mjs +1 -1
  6. package/dist/adapters/memory.d.ts +1 -1
  7. package/dist/{adapters-BbRkoiu9.d.ts → adapters-Bo2JQg8b.d.ts} +2 -1
  8. package/dist/chunk-ALB35PRQ.mjs +98 -0
  9. package/dist/chunk-KMMJMDUA.mjs +44 -0
  10. package/dist/chunk-RQLXC2YS.mjs +269 -0
  11. package/dist/chunk-S7RJJMHI.mjs +1086 -0
  12. package/dist/chunk-SVDEEMO6.mjs +7023 -0
  13. package/dist/{chunk-I24SGLFS.mjs → chunk-TW6BXTOL.mjs} +5 -1
  14. package/dist/{chunk-KHL4RPC3.mjs → chunk-VWF7RKSF.mjs} +2566 -2282
  15. package/dist/chunk-WISGW24C.mjs +455 -0
  16. package/dist/config-DX--2Owg.d.ts +472 -0
  17. package/dist/direct-executor-KC5O5D2R.mjs +4 -0
  18. package/dist/distribution/coordinator/etcd.d.ts +16 -0
  19. package/dist/distribution/coordinator/etcd.mjs +2 -0
  20. package/dist/distribution/coordinator/in-memory.d.ts +7 -0
  21. package/dist/distribution/coordinator/in-memory.mjs +1 -0
  22. package/dist/distribution.d.ts +122 -0
  23. package/dist/distribution.mjs +7410 -0
  24. package/dist/embeddings/openai.d.ts +1 -1
  25. package/dist/embeddings/openai.mjs +6 -1
  26. package/dist/index.browser.mjs +11750 -7532
  27. package/dist/index.d.ts +6 -450
  28. package/dist/index.mjs +7 -3236
  29. package/dist/invalidation/broadcast-channel.d.ts +1 -1
  30. package/dist/invalidation/filesystem.d.ts +1 -1
  31. package/dist/invalidation/noop.d.ts +1 -1
  32. package/dist/{language-ClUGLuoC.d.ts → language-ONQ3iVDf.d.ts} +1 -0
  33. package/dist/languages/arabic.d.ts +1 -1
  34. package/dist/languages/armenian.d.ts +1 -1
  35. package/dist/languages/bulgarian.d.ts +1 -1
  36. package/dist/languages/chinese.d.ts +1 -1
  37. package/dist/languages/dagbani.d.ts +1 -1
  38. package/dist/languages/danish.d.ts +1 -1
  39. package/dist/languages/dutch.d.ts +1 -1
  40. package/dist/languages/english.d.ts +1 -1
  41. package/dist/languages/english.mjs +1 -1
  42. package/dist/languages/ewe.d.ts +1 -1
  43. package/dist/languages/finnish.d.ts +1 -1
  44. package/dist/languages/french.d.ts +1 -1
  45. package/dist/languages/ga.d.ts +1 -1
  46. package/dist/languages/german.d.ts +1 -1
  47. package/dist/languages/greek.d.ts +1 -1
  48. package/dist/languages/hausa.d.ts +1 -1
  49. package/dist/languages/hindi.d.ts +1 -1
  50. package/dist/languages/hungarian.d.ts +1 -1
  51. package/dist/languages/igbo.d.ts +1 -1
  52. package/dist/languages/indonesian.d.ts +1 -1
  53. package/dist/languages/irish.d.ts +1 -1
  54. package/dist/languages/italian.d.ts +1 -1
  55. package/dist/languages/japanese.d.ts +1 -1
  56. package/dist/languages/nepali.d.ts +1 -1
  57. package/dist/languages/norwegian.d.ts +1 -1
  58. package/dist/languages/portuguese.d.ts +1 -1
  59. package/dist/languages/romanian.d.ts +1 -1
  60. package/dist/languages/russian.d.ts +1 -1
  61. package/dist/languages/sanskrit.d.ts +1 -1
  62. package/dist/languages/serbian.d.ts +1 -1
  63. package/dist/languages/slovenian.d.ts +1 -1
  64. package/dist/languages/spanish.d.ts +1 -1
  65. package/dist/languages/swahili.d.ts +1 -1
  66. package/dist/languages/swedish.d.ts +1 -1
  67. package/dist/languages/tamil.d.ts +1 -1
  68. package/dist/languages/turkish.d.ts +1 -1
  69. package/dist/languages/twi.d.ts +1 -1
  70. package/dist/languages/ukrainian.d.ts +1 -1
  71. package/dist/languages/yoruba.d.ts +1 -1
  72. package/dist/languages/zulu.d.ts +1 -1
  73. package/dist/narsil-B3jKyXCr.d.ts +72 -0
  74. package/dist/persistence/durability/checkpoint-worker.d.ts +48 -0
  75. package/dist/persistence/durability/checkpoint-worker.mjs +59 -0
  76. package/dist/schema-C3VhNvfw.d.ts +60 -0
  77. package/dist/serialization/crc32-worker.d.ts +20 -0
  78. package/dist/serialization/crc32-worker.mjs +61 -0
  79. package/dist/server.d.ts +218 -0
  80. package/dist/server.mjs +1184 -0
  81. package/dist/types-CTVVm4GG.d.ts +73 -0
  82. package/dist/vector/hnsw-build-worker.mjs +1 -1
  83. package/dist/workers/entry.mjs +1 -1
  84. package/package.json +38 -2
  85. package/dist/chunk-R2C2EQGO.mjs +0 -53
  86. package/dist/chunk-VVORJOXR.mjs +0 -759
  87. package/dist/direct-executor-LBJLGMJ2.mjs +0 -4
@@ -0,0 +1,218 @@
1
+ import { N as Narsil } from './narsil-B3jKyXCr.js';
2
+ import { E as EmbeddingAdapter } from './adapters-Bo2JQg8b.js';
3
+ import './config-DX--2Owg.js';
4
+ import './schema-C3VhNvfw.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 };