@nixxie-cms/ai-rag 1.0.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.
Files changed (65) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +163 -0
  3. package/dist/declarations/src/AiRagService.d.ts +50 -0
  4. package/dist/declarations/src/AiRagService.d.ts.map +1 -0
  5. package/dist/declarations/src/admin-page.d.ts +29 -0
  6. package/dist/declarations/src/admin-page.d.ts.map +1 -0
  7. package/dist/declarations/src/chunking.d.ts +8 -0
  8. package/dist/declarations/src/chunking.d.ts.map +1 -0
  9. package/dist/declarations/src/collection.d.ts +18 -0
  10. package/dist/declarations/src/collection.d.ts.map +1 -0
  11. package/dist/declarations/src/express.d.ts +36 -0
  12. package/dist/declarations/src/express.d.ts.map +1 -0
  13. package/dist/declarations/src/graphql.d.ts +23 -0
  14. package/dist/declarations/src/graphql.d.ts.map +1 -0
  15. package/dist/declarations/src/index.d.ts +39 -0
  16. package/dist/declarations/src/index.d.ts.map +1 -0
  17. package/dist/declarations/src/plugin.d.ts +53 -0
  18. package/dist/declarations/src/plugin.d.ts.map +1 -0
  19. package/dist/declarations/src/prompt.d.ts +14 -0
  20. package/dist/declarations/src/prompt.d.ts.map +1 -0
  21. package/dist/declarations/src/providers/AnthropicRagProvider.d.ts +16 -0
  22. package/dist/declarations/src/providers/AnthropicRagProvider.d.ts.map +1 -0
  23. package/dist/declarations/src/providers/GeminiRagProvider.d.ts +19 -0
  24. package/dist/declarations/src/providers/GeminiRagProvider.d.ts.map +1 -0
  25. package/dist/declarations/src/providers/OllamaRagProvider.d.ts +23 -0
  26. package/dist/declarations/src/providers/OllamaRagProvider.d.ts.map +1 -0
  27. package/dist/declarations/src/providers/OpenAiRagProvider.d.ts +17 -0
  28. package/dist/declarations/src/providers/OpenAiRagProvider.d.ts.map +1 -0
  29. package/dist/declarations/src/providers/ServiceRagProvider.d.ts +17 -0
  30. package/dist/declarations/src/providers/ServiceRagProvider.d.ts.map +1 -0
  31. package/dist/declarations/src/providers/index.d.ts +14 -0
  32. package/dist/declarations/src/providers/index.d.ts.map +1 -0
  33. package/dist/declarations/src/providers/types.d.ts +45 -0
  34. package/dist/declarations/src/providers/types.d.ts.map +1 -0
  35. package/dist/declarations/src/similarity.d.ts +12 -0
  36. package/dist/declarations/src/similarity.d.ts.map +1 -0
  37. package/dist/declarations/src/types.d.ts +319 -0
  38. package/dist/declarations/src/types.d.ts.map +1 -0
  39. package/dist/declarations/src/vector-store.d.ts +34 -0
  40. package/dist/declarations/src/vector-store.d.ts.map +1 -0
  41. package/dist/nixxie-cms-ai-rag.cjs.d.ts +2 -0
  42. package/dist/nixxie-cms-ai-rag.cjs.js +2507 -0
  43. package/dist/nixxie-cms-ai-rag.esm.js +2481 -0
  44. package/package.json +37 -0
  45. package/src/AiRagService.ts +640 -0
  46. package/src/admin-page.ts +135 -0
  47. package/src/chunking.ts +78 -0
  48. package/src/collection.ts +79 -0
  49. package/src/express.ts +212 -0
  50. package/src/graphql.ts +196 -0
  51. package/src/guard.ts +75 -0
  52. package/src/index.ts +102 -0
  53. package/src/plugin.ts +162 -0
  54. package/src/prompt.ts +62 -0
  55. package/src/providers/AnthropicRagProvider.ts +91 -0
  56. package/src/providers/GeminiRagProvider.ts +147 -0
  57. package/src/providers/OllamaRagProvider.ts +157 -0
  58. package/src/providers/OpenAiRagProvider.ts +108 -0
  59. package/src/providers/ServiceRagProvider.ts +44 -0
  60. package/src/providers/index.ts +67 -0
  61. package/src/providers/types.ts +44 -0
  62. package/src/semaphore.ts +26 -0
  63. package/src/similarity.ts +31 -0
  64. package/src/types.ts +346 -0
  65. package/src/vector-store.ts +136 -0
package/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Nixxie International DMCC
4
+ Portions Copyright (c) 2023 Thinkmill Labs Pty Ltd and contributors
5
+ (this software is derived from the KeystoneJS project, https://keystonejs.com)
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,163 @@
1
+ # @nixxie-cms/ai-rag
2
+
3
+ A custom, **RAG-trained AI assistant** for Nixxie CMS. It automatically creates a
4
+ knowledge-base collection that users fill with content, indexes that content into
5
+ embeddings, and answers questions **grounded in your data** — with inline citations and
6
+ hallucination guarding.
7
+
8
+ - 🧠 **RAG by default** — retrieval-augmented generation over a knowledge base you control.
9
+ - 🔌 **Pluggable models** — generation via **Anthropic, OpenAI (GPT), Google Gemini, or Ollama**
10
+ (local open models: Llama, Mistral, Phi, …); embeddings via OpenAI, Gemini, or Ollama. Mix and
11
+ match (e.g. local Ollama embeddings + Anthropic answers).
12
+ - 🗃️ **Auto-created lists** — `KnowledgeBase` (source rows) and `KnowledgeChunk`
13
+ (embeddings) are added to your schema by the plugin.
14
+ - 🧮 **Portable vector store** — a SQL-backed default works on any database; swap in
15
+ pgvector/Qdrant/Pinecone via the `VectorStore` interface.
16
+ - 🛡️ **Hallucination guarding** — refuses when the KB has nothing relevant, requires
17
+ citations, and (optionally) runs a second-pass grounding check.
18
+ - ⏱️ **Scheduled + incremental indexing** — re-embed on content change and on a cron.
19
+ - 🌐 **Surfaces** — programmatic service API, HTTP chat route with **SSE streaming**,
20
+ GraphQL queries/mutations, and an Admin UI console.
21
+
22
+ ## Install
23
+
24
+ ```bash
25
+ pnpm add @nixxie-cms/ai-rag
26
+ # plus the SDK(s) for the providers you use:
27
+ pnpm add @anthropic-ai/sdk openai
28
+ ```
29
+
30
+ ## Quick start
31
+
32
+ ```ts
33
+ // nixxie-cms.ts
34
+ import { config } from '@nixxie-cms/core'
35
+ import { createJobs } from '@nixxie-cms/jobs'
36
+ import { createAiRag, ragPlugin } from '@nixxie-cms/ai-rag'
37
+
38
+ const aiRag = createAiRag({
39
+ // Answering model — pick any provider.
40
+ generation: {
41
+ provider: 'anthropic',
42
+ apiKey: process.env.ANTHROPIC_API_KEY!,
43
+ model: 'claude-opus-4-8',
44
+ temperature: 0.2,
45
+ maxTokens: 1024,
46
+ },
47
+ // Embedding model — can be a different (even local) provider.
48
+ embedding: {
49
+ provider: 'openai',
50
+ apiKey: process.env.OPENAI_API_KEY!,
51
+ model: 'text-embedding-3-small',
52
+ },
53
+ retrieval: { topK: 6, minScore: 0.25 },
54
+ chunking: { strategy: 'recursive', chunkSize: 1200, chunkOverlap: 200 },
55
+ guard: { enabled: true, requireCitations: true, groundingCheck: true },
56
+ indexing: { auto: true, onConnect: true, schedule: '0 3 * * *' },
57
+ })
58
+
59
+ export default config({
60
+ db: { provider: 'postgresql', url: process.env.DATABASE_URL! },
61
+ jobs: createJobs(), // enables the scheduled reindex
62
+ collections: { /* your collections */ },
63
+ plugins: [ragPlugin({ service: aiRag })],
64
+ })
65
+ ```
66
+
67
+ `ragPlugin()` registers the service (`context.services.aiRag`), adds the `KnowledgeBase` +
68
+ `KnowledgeChunk` collections with auto-indexing hooks, mounts the HTTP + GraphQL surfaces,
69
+ and schedules re-indexing. Run a migration after adding it.
70
+
71
+ ## Using the service
72
+
73
+ Anywhere you have `context`:
74
+
75
+ ```ts
76
+ const ai = context.services.aiRag!
77
+
78
+ // Add / manage knowledge-base content
79
+ await ai.addDocument({ title: 'Refunds', content: '…', tags: ['billing'] })
80
+ await ai.updateDocument(id, { content: '…' })
81
+ await ai.removeDocument(id)
82
+ const docs = await ai.listDocuments({ tags: ['billing'] })
83
+
84
+ // Index (usually automatic)
85
+ await ai.reindex({ force: true })
86
+
87
+ // Retrieve + ask
88
+ const chunks = await ai.retrieve('how do refunds work?')
89
+ const answer = await ai.ask('How do refunds work?', { tags: ['billing'] })
90
+ // → { text, sources: [{ title, source, score, snippet }], grounded, refused, model }
91
+
92
+ // Streaming
93
+ for await (const event of ai.stream([{ role: 'user', content: 'Explain refunds' }])) {
94
+ if (event.type === 'token') process.stdout.write(event.token)
95
+ if (event.type === 'done') console.log(event.answer.sources)
96
+ }
97
+ ```
98
+
99
+ ## HTTP API
100
+
101
+ Mounted by the plugin at `/api/ai-rag` (configurable):
102
+
103
+ | Method & path | Body / query | Returns |
104
+ | ----------------------------- | ------------------------------------------- | ------- |
105
+ | `POST /api/ai-rag/chat` | `{ messages?, question?, topK?, tags?, stream? }` | JSON answer, or **SSE** (`sources`→`token`→`done`) when `stream: true` |
106
+ | `GET /api/ai-rag/documents` | `?take&skip&search` | `{ documents }` |
107
+ | `POST /api/ai-rag/documents` | `{ content, title?, source?, tags? }` | the created document |
108
+ | `DELETE /api/ai-rag/documents/:id` | — | `{ ok: true }` |
109
+ | `POST /api/ai-rag/reindex` | `{ force? }` | index stats |
110
+
111
+ ## GraphQL
112
+
113
+ Added to your schema: `ragAsk(question, topK, tags)`, `ragRetrieve(query, …)`,
114
+ `ragAddDocument(...)`, `ragRemoveDocument(id)`, `ragReindex(force)`.
115
+
116
+ ## Admin UI page
117
+
118
+ Add a chat + knowledge-base console to the dashboard:
119
+
120
+ ```ts
121
+ import { ragAdminPage } from '@nixxie-cms/ai-rag'
122
+
123
+ export default config({
124
+ ui: { getAdditionalFiles: [async () => [ragAdminPage()]] }, // served at /ai-rag
125
+ })
126
+ ```
127
+
128
+ ## Configuration reference
129
+
130
+ Everything in `AiRagConfig` is optional and deeply overridable:
131
+
132
+ - **`generation`** — `provider`, `apiKey`, `model`, `baseUrl`, `temperature`, `maxTokens`,
133
+ `topP`, `systemPrompt`, and `buildPrompt` (full control of prompt assembly). Pass
134
+ `service` to reuse an existing `NixxieAiService` (e.g. `context.services.ai`).
135
+ - **`embedding`** — same provider shape, plus `dimensions` and `batchSize`.
136
+ - **`retrieval`** — `topK`, `minScore`, `maxContextChars`, `candidateMultiplier`,
137
+ `vectorStore`, `rerank`.
138
+ - **`chunking`** — `strategy` (`recursive` | `sentence` | `fixed`), `chunkSize`, `chunkOverlap`.
139
+ - **`indexing`** — `auto`, `onConnect`, `schedule` (cron/ms), `concurrency`.
140
+ - **`guard`** — `enabled`, `refuseWhenNoContext`, `refusal`, `requireCitations`,
141
+ `groundingCheck`, `groundingModel`, `refuseWhenUngrounded`, `allowModelKnowledge`.
142
+ - **`chat`** — `historyLimit`, `streaming`.
143
+ - **`limits`** — `maxQueryChars`, `maxConcurrentChats`.
144
+ - **`collections`** — `documents`, `chunks` (collection names).
145
+
146
+ ## Custom vector store
147
+
148
+ ```ts
149
+ import { createAiRag, type VectorStore } from '@nixxie-cms/ai-rag'
150
+
151
+ const pgvector: VectorStore = {
152
+ async init(context) { /* … */ },
153
+ async upsert(documentId, records) { /* … */ },
154
+ async deleteByDocument(documentId) { /* … */ },
155
+ async query({ embedding, topK, tags, minScore }) { /* … return scored records */ },
156
+ }
157
+
158
+ const aiRag = createAiRag({ retrieval: { vectorStore: pgvector }, /* … */ })
159
+ ```
160
+
161
+ ## License
162
+
163
+ MIT
@@ -0,0 +1,50 @@
1
+ import type { NixxieAiMessage, NixxieAiRagService, NixxieContext, NixxieRagAnswer, NixxieRagAskOptions, NixxieRagChunk, NixxieRagDocument, NixxieRagDocumentInput, NixxieRagDocumentQuery, NixxieRagIndexStats, NixxieRagRetrieveOptions, NixxieRagStreamEvent } from '@nixxie-cms/core';
2
+ import type { AiRagConfig } from "./types.js";
3
+ /** The main RAG assistant. Create via `createAiRag()`; register via `ragPlugin()`. */
4
+ export declare class AiRagService implements NixxieAiRagService {
5
+ private documents;
6
+ private generation;
7
+ private embedder;
8
+ private vectorStore;
9
+ private rerank?;
10
+ private chatGate;
11
+ private r;
12
+ constructor(config?: AiRagConfig);
13
+ /** Names of the collections this service reads/writes (used by the plugin). */
14
+ get collections(): {
15
+ documents: string;
16
+ chunks: string;
17
+ };
18
+ get indexingSchedule(): string | number | undefined;
19
+ init(context: NixxieContext): Promise<void>;
20
+ private requireDelegate;
21
+ private requireDocuments;
22
+ addDocument(doc: NixxieRagDocumentInput): Promise<NixxieRagDocument>;
23
+ addDocuments(docs: NixxieRagDocumentInput[]): Promise<NixxieRagDocument[]>;
24
+ getDocument(id: string): Promise<NixxieRagDocument | undefined>;
25
+ listDocuments(query?: NixxieRagDocumentQuery): Promise<NixxieRagDocument[]>;
26
+ updateDocument(id: string, patch: Partial<NixxieRagDocumentInput>): Promise<NixxieRagDocument>;
27
+ removeDocument(id: string): Promise<void>;
28
+ /**
29
+ * Delete a document's indexed chunks without touching the document row. Used by the
30
+ * auto-index delete hook, where the KB row has already been removed by the CMS.
31
+ */
32
+ purgeChunks(documentId: string): Promise<void>;
33
+ index(documentId: string): Promise<void>;
34
+ reindex(options?: {
35
+ force?: boolean;
36
+ tags?: string[];
37
+ }): Promise<NixxieRagIndexStats>;
38
+ indexPending(): Promise<NixxieRagIndexStats>;
39
+ private embedBatched;
40
+ retrieve(query: string, options?: NixxieRagRetrieveOptions): Promise<NixxieRagChunk[]>;
41
+ ask(question: string, options?: NixxieRagAskOptions): Promise<NixxieRagAnswer>;
42
+ chat(messages: NixxieAiMessage[], options?: NixxieRagAskOptions): Promise<NixxieRagAnswer>;
43
+ stream(messages: NixxieAiMessage[], options?: NixxieRagAskOptions): AsyncIterable<NixxieRagStreamEvent>;
44
+ /** Shared retrieve → guard → prompt pipeline for chat/stream. */
45
+ private prepare;
46
+ /** Apply the grounding check and assemble the final answer with citations. */
47
+ private finalize;
48
+ close(): Promise<void>;
49
+ }
50
+ //# sourceMappingURL=AiRagService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AiRagService.d.ts","sourceRoot":"../../../src","sources":["AiRagService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,kBAAkB,EAClB,aAAa,EACb,eAAe,EACf,mBAAmB,EACnB,cAAc,EAEd,iBAAiB,EACjB,sBAAsB,EACtB,sBAAsB,EACtB,mBAAmB,EACnB,wBAAwB,EACxB,oBAAoB,EACrB,MAAM,kBAAkB,CAAA;AAYzB,OAAO,KAAK,EACV,WAAW,EAIZ,mBAAe;AAqChB,sFAAsF;AACtF,qBAAa,YAAa,YAAW,kBAAkB;IACrD,OAAO,CAAC,SAAS,CAAmB;IACpC,OAAO,CAAC,UAAU,CAAoB;IACtC,OAAO,CAAC,QAAQ,CAAmB;IACnC,OAAO,CAAC,WAAW,CAAa;IAChC,OAAO,CAAC,MAAM,CAAC,CAAwE;IACvF,OAAO,CAAC,QAAQ,CAAW;IAC3B,OAAO,CAAC,CAAC,CAAU;gBAEP,MAAM,GAAE,WAAgB;IA+CpC,+EAA+E;IAC/E,IAAI,WAAW,IAAI;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAEvD;IAED,IAAI,gBAAgB,IAAI,MAAM,GAAG,MAAM,GAAG,SAAS,CAElD;IAIK,IAAI,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAWjD,OAAO,CAAC,eAAe;IAWvB,OAAO,CAAC,gBAAgB;IAWlB,WAAW,CAAC,GAAG,EAAE,sBAAsB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAKpE,YAAY,CAAC,IAAI,EAAE,sBAAsB,EAAE,GAAG,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAgC1E,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,GAAG,SAAS,CAAC;IAK/D,aAAa,CAAC,KAAK,GAAE,sBAA2B,GAAG,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAwB/E,cAAc,CAClB,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,OAAO,CAAC,sBAAsB,CAAC,GACrC,OAAO,CAAC,iBAAiB,CAAC;IAqBvB,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAK/C;;;OAGG;IACG,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAM9C,KAAK,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAiDxC,OAAO,CAAC,OAAO,GAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;KAAO,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAkBzF,YAAY,IAAI,OAAO,CAAC,mBAAmB,CAAC;YAmBpC,YAAY;IAapB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,wBAA6B,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IA2B1F,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAwB,GAAG,OAAO,CAAC,eAAe,CAAC;IAIlF,IAAI,CAAC,QAAQ,EAAE,eAAe,EAAE,EAAE,OAAO,GAAE,mBAAwB,GAAG,OAAO,CAAC,eAAe,CAAC;IAoB7F,MAAM,CACX,QAAQ,EAAE,eAAe,EAAE,EAC3B,OAAO,GAAE,mBAAwB,GAChC,aAAa,CAAC,oBAAoB,CAAC;IAoDtC,iEAAiE;YACnD,OAAO;IAgFrB,8EAA8E;YAChE,QAAQ;IA+BhB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7B"}
@@ -0,0 +1,29 @@
1
+ import type { AdminFileToWrite } from '@nixxie-cms/core/types';
2
+ export type RagAdminPageOptions = {
3
+ /**
4
+ * Route the page is served at inside the Admin UI (also its filename under `pages/`).
5
+ * @default 'ai-rag'
6
+ */
7
+ route?: string;
8
+ /**
9
+ * Base path of the HTTP routes the page talks to (must match `ragPlugin({ routes })`).
10
+ * @default '/api/ai-rag'
11
+ */
12
+ apiPath?: string;
13
+ /** Heading shown at the top of the page. @default 'AI Assistant' */
14
+ title?: string;
15
+ };
16
+ /**
17
+ * Returns an `AdminFileToWrite` that adds a chat + knowledge-base console page to the
18
+ * Admin UI. Spread it into `ui.getAdditionalFiles`:
19
+ *
20
+ * @example
21
+ * import { ragAdminPage } from '@nixxie-cms/ai-rag'
22
+ * export default config({
23
+ * ui: { getAdditionalFiles: [async () => [ragAdminPage()]] },
24
+ * })
25
+ *
26
+ * The page appears at `/<route>` (default `/ai-rag`) in the Admin UI.
27
+ */
28
+ export declare function ragAdminPage(options?: RagAdminPageOptions): AdminFileToWrite;
29
+ //# sourceMappingURL=admin-page.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"admin-page.d.ts","sourceRoot":"../../../src","sources":["admin-page.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAE9D,MAAM,MAAM,mBAAmB,GAAG;IAChC;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,oEAAoE;IACpE,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAkGD;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,OAAO,GAAE,mBAAwB,GAAG,gBAAgB,CAShF"}
@@ -0,0 +1,8 @@
1
+ import type { RagChunkingConfig } from "./types.js";
2
+ /**
3
+ * Split text into overlapping chunks. The recursive strategy prefers to cut on the
4
+ * coarsest natural boundary that keeps a chunk under `chunkSize`, falling back to finer
5
+ * boundaries (and finally a hard slice) so no chunk overruns the budget.
6
+ */
7
+ export declare function chunkText(text: string, config?: RagChunkingConfig): string[];
8
+ //# sourceMappingURL=chunking.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chunking.d.ts","sourceRoot":"../../../src","sources":["chunking.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,mBAAe;AAWhD;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,GAAE,iBAAsB,GAAG,MAAM,EAAE,CAiBhF"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * The knowledge-base source list the assistant is trained on. Users add rows here; each
3
+ * row's `content` is chunked, embedded and made retrievable. `ragPlugin()` adds this
4
+ * collection automatically, but you can register it yourself for full control over access.
5
+ *
6
+ * @example
7
+ * config({
8
+ * collections: { KnowledgeBase: knowledgeBaseCollection(), ...collections },
9
+ * })
10
+ */
11
+ export declare function knowledgeBaseCollection(): any;
12
+ /**
13
+ * The chunk/embedding list backing retrieval. Managed entirely by ai-rag — rows are written
14
+ * during indexing and deleted with their document. Hidden from create/delete in the Admin UI.
15
+ * `ragPlugin()` adds it automatically.
16
+ */
17
+ export declare function knowledgeChunkCollection(): any;
18
+ //# sourceMappingURL=collection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collection.d.ts","sourceRoot":"../../../src","sources":["collection.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,IAAI,GAAG,CAoC7C;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,IAAI,GAAG,CAuB9C"}
@@ -0,0 +1,36 @@
1
+ import type { NixxieAiRagService, NixxieContext } from '@nixxie-cms/core';
2
+ export type AiRagRoutesOptions = {
3
+ /** The service. Defaults to `context.services.aiRag`. */
4
+ service?: NixxieAiRagService;
5
+ /**
6
+ * Base path the routes mount under.
7
+ * @default '/api/ai-rag'
8
+ */
9
+ path?: string;
10
+ /**
11
+ * Authorize a request before it reaches the assistant. Receives a request-bound context;
12
+ * returning false answers 401. Applied to every route.
13
+ * @default requires a session
14
+ */
15
+ isAuthorized?: (context: NixxieContext) => boolean | Promise<boolean>;
16
+ /**
17
+ * Require authorization for read/chat routes too (not just mutations).
18
+ * @default true
19
+ */
20
+ protectReads?: boolean;
21
+ };
22
+ /**
23
+ * Mount the assistant's HTTP API on an Express app:
24
+ *
25
+ * - `POST <path>/chat` — body `{ messages?, question?, topK?, tags?, stream? }`. When
26
+ * `stream` is true (or `Accept: text/event-stream`), responds with SSE: `sources`,
27
+ * then `token` events, then a final `done` event carrying the full answer.
28
+ * - `GET <path>/documents` — list knowledge-base documents.
29
+ * - `POST <path>/documents` — add a document `{ content, title?, source?, tags? }`.
30
+ * - `DELETE <path>/documents/:id` — remove a document.
31
+ * - `POST <path>/reindex` — `{ force? }` → index stats.
32
+ *
33
+ * Call from `server.extendExpressApp`, or use `ragPlugin()` to wire it automatically.
34
+ */
35
+ export declare function installAiRagRoutes(app: any, context: NixxieContext, options?: AiRagRoutesOptions): void;
36
+ //# sourceMappingURL=express.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"express.d.ts","sourceRoot":"../../../src","sources":["express.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAwB,MAAM,kBAAkB,CAAA;AAE/F,MAAM,MAAM,kBAAkB,GAAG;IAC/B,yDAAyD;IACzD,OAAO,CAAC,EAAE,kBAAkB,CAAA;IAC5B;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;;;;OAIG;IACH,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,aAAa,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IACrE;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB,CAAA;AAkCD;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,GAAG,EACR,OAAO,EAAE,aAAa,EACtB,OAAO,GAAE,kBAAuB,GAC/B,IAAI,CA2IN"}
@@ -0,0 +1,23 @@
1
+ import type { NixxieAiRagService, NixxieContext } from '@nixxie-cms/core';
2
+ /** How the GraphQL resolvers obtain the service (defaults to `context.services.aiRag`). */
3
+ export type RagGraphqlOptions = {
4
+ /** Override the service lookup. By default reads `context.services.aiRag`. */
5
+ getService?: (context: NixxieContext) => NixxieAiRagService | null | undefined;
6
+ /**
7
+ * Gate the mutating operations (ingest/remove/reindex). Returning false rejects the call.
8
+ * Reads (`ragAsk`, `ragRetrieve`) are always allowed — guard them with collection access if needed.
9
+ * @default requires a session
10
+ */
11
+ isAuthorized?: (context: NixxieContext) => boolean | Promise<boolean>;
12
+ };
13
+ /**
14
+ * Build the `extendGraphqlSchema` function that adds the assistant's queries and mutations:
15
+ *
16
+ * - `ragAsk(question, topK?, tags?)` → grounded answer with citations
17
+ * - `ragRetrieve(query, topK?, tags?)` → raw retrieved chunks
18
+ * - `ragAddDocument(...)` / `ragRemoveDocument(id)` / `ragReindex(force?)`
19
+ *
20
+ * `ragPlugin()` wires this automatically; use it directly only if you compose the schema yourself.
21
+ */
22
+ export declare function ragGraphqlExtension(options?: RagGraphqlOptions): (schema: import("graphql").GraphQLSchema) => import("graphql").GraphQLSchema;
23
+ //# sourceMappingURL=graphql.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graphql.d.ts","sourceRoot":"../../../src","sources":["graphql.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,kBAAkB,EAClB,aAAa,EAMd,MAAM,kBAAkB,CAAA;AAEzB,2FAA2F;AAC3F,MAAM,MAAM,iBAAiB,GAAG;IAC9B,8EAA8E;IAC9E,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,aAAa,KAAK,kBAAkB,GAAG,IAAI,GAAG,SAAS,CAAA;IAC9E;;;;OAIG;IACH,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,aAAa,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;CACtE,CAAA;AAsBD;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,iBAAsB,gFA+IlE"}
@@ -0,0 +1,39 @@
1
+ import { AiRagService } from "./AiRagService.js";
2
+ import type { AiRagConfig } from "./types.js";
3
+ /**
4
+ * Create a custom, RAG-trained assistant backed by a knowledge-base collection.
5
+ *
6
+ * Register it with `ragPlugin()` so the knowledge-base collections, HTTP + GraphQL surfaces
7
+ * and scheduled indexing are wired automatically:
8
+ *
9
+ * @example
10
+ * import { createAiRag, ragPlugin } from '@nixxie-cms/ai-rag'
11
+ * const aiRag = createAiRag({
12
+ * generation: { provider: 'anthropic', apiKey: process.env.ANTHROPIC_API_KEY! },
13
+ * embedding: { provider: 'openai', apiKey: process.env.OPENAI_API_KEY! },
14
+ * retrieval: { topK: 6, minScore: 0.25 },
15
+ * guard: { groundingCheck: true },
16
+ * indexing: { schedule: '0 3 * * *' },
17
+ * })
18
+ * export default config({ db: { ... }, plugins: [ragPlugin({ service: aiRag })] })
19
+ *
20
+ * Then anywhere you have context:
21
+ * await context.services.aiRag!.addDocument({ title, content })
22
+ * const answer = await context.services.aiRag!.ask('How do refunds work?')
23
+ */
24
+ export declare function createAiRag(config?: AiRagConfig): AiRagService;
25
+ export { AiRagService } from "./AiRagService.js";
26
+ export { ragPlugin, type RagPluginOptions } from "./plugin.js";
27
+ export { installAiRagRoutes, type AiRagRoutesOptions } from "./express.js";
28
+ export { ragGraphqlExtension, type RagGraphqlOptions } from "./graphql.js";
29
+ export { ragAdminPage, type RagAdminPageOptions } from "./admin-page.js";
30
+ export { knowledgeBaseCollection, knowledgeChunkCollection } from "./collection.js";
31
+ export { resolveGenerationProvider, resolveEmbeddingProvider, AnthropicRagProvider, OpenAiRagProvider, GeminiRagProvider, OllamaRagProvider, ServiceRagProvider, } from "./providers/index.js";
32
+ export type { GenerationProvider, EmbeddingProvider, RagMessage, RagGenerateOptions, RagGenerateResult, RagStreamChunk, } from "./providers/index.js";
33
+ export { SqlVectorStore, InMemoryVectorStore } from "./vector-store.js";
34
+ export { chunkText } from "./chunking.js";
35
+ export { cosineSimilarity, normalize } from "./similarity.js";
36
+ export { buildRagPrompt, renderContext, DEFAULT_SYSTEM_PROMPT } from "./prompt.js";
37
+ export type { AiRagConfig, RagProviderName, RagProviderConfig, RagGenerationConfig, RagEmbeddingConfig, RagRetrievalConfig, RagChunkingConfig, RagChunkingStrategy, RagIndexingConfig, RagGuardConfig, RagChatConfig, RagLimitsConfig, RagCollectionsConfig, VectorStore, VectorRecord, VectorQuery, PromptBuildArgs, PromptBuildResult, } from "./types.js";
38
+ export type { NixxieAiRagService, NixxieRagDocument, NixxieRagDocumentInput, NixxieRagDocumentQuery, NixxieRagChunk, NixxieRagCitation, NixxieRagAnswer, NixxieRagAskOptions, NixxieRagRetrieveOptions, NixxieRagStreamEvent, NixxieRagIndexStats, } from '@nixxie-cms/core';
39
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"../../../src","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,0BAAsB;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAE,mBAAe;AAE1C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,WAAW,CAAC,MAAM,GAAE,WAAgB,GAAG,YAAY,CAElE;AAED,OAAO,EAAE,YAAY,EAAE,0BAAsB;AAG7C,OAAO,EAAE,SAAS,EAAE,KAAK,gBAAgB,EAAE,oBAAgB;AAC3D,OAAO,EAAE,kBAAkB,EAAE,KAAK,kBAAkB,EAAE,qBAAiB;AACvE,OAAO,EAAE,mBAAmB,EAAE,KAAK,iBAAiB,EAAE,qBAAiB;AACvE,OAAO,EAAE,YAAY,EAAE,KAAK,mBAAmB,EAAE,wBAAoB;AAGrE,OAAO,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,wBAAoB;AAGhF,OAAO,EACL,yBAAyB,EACzB,wBAAwB,EACxB,oBAAoB,EACpB,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,GACnB,6BAAmB;AACpB,YAAY,EACV,kBAAkB,EAClB,iBAAiB,EACjB,UAAU,EACV,kBAAkB,EAClB,iBAAiB,EACjB,cAAc,GACf,6BAAmB;AAGpB,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,0BAAsB;AAGpE,OAAO,EAAE,SAAS,EAAE,sBAAkB;AACtC,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,wBAAoB;AAC1D,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,qBAAqB,EAAE,oBAAgB;AAG/E,YAAY,EACV,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,EACnB,iBAAiB,EACjB,cAAc,EACd,aAAa,EACb,eAAe,EACf,oBAAoB,EACpB,WAAW,EACX,YAAY,EACZ,WAAW,EACX,eAAe,EACf,iBAAiB,GAClB,mBAAe;AAGhB,YAAY,EACV,kBAAkB,EAClB,iBAAiB,EACjB,sBAAsB,EACtB,sBAAsB,EACtB,cAAc,EACd,iBAAiB,EACjB,eAAe,EACf,mBAAmB,EACnB,wBAAwB,EACxB,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,kBAAkB,CAAA"}
@@ -0,0 +1,53 @@
1
+ import type { NixxiePlugin } from '@nixxie-cms/core/types';
2
+ import type { AiRagService } from "./AiRagService.js";
3
+ import { type AiRagRoutesOptions } from "./express.js";
4
+ import { type RagGraphqlOptions } from "./graphql.js";
5
+ export type RagPluginOptions = {
6
+ /** The service created with `createAiRag()`. */
7
+ service: AiRagService;
8
+ /**
9
+ * Add the knowledge-base + chunk collections to the schema.
10
+ * Disable if you register them yourself (e.g. to customise access control).
11
+ * @default true
12
+ */
13
+ collections?: boolean;
14
+ /**
15
+ * Re-index a knowledge-base row whenever it's created/updated through the CMS, and drop
16
+ * its chunks when it's deleted. Overrides the service's `indexing.auto` for CMS writes.
17
+ * @default the service's `indexing.auto`
18
+ */
19
+ autoIndex?: boolean;
20
+ /**
21
+ * Mount the HTTP routes (chat + streaming + document CRUD). Pass `false` to skip, or an
22
+ * options object to configure the path / auth.
23
+ * @default true (mounted at /api/ai-rag)
24
+ */
25
+ routes?: boolean | Omit<AiRagRoutesOptions, 'service'>;
26
+ /**
27
+ * Add the GraphQL queries/mutations (ragAsk, ragRetrieve, ragAddDocument, …).
28
+ * Pass `false` to skip, or options to configure auth.
29
+ * @default true
30
+ */
31
+ graphql?: boolean | RagGraphqlOptions;
32
+ /** Name of the scheduled reindex job registered with the jobs service. @default 'ai-rag-reindex' */
33
+ jobName?: string;
34
+ };
35
+ /**
36
+ * One-call wiring for the RAG assistant. Registers the service, adds the knowledge-base
37
+ * collections (with auto-indexing hooks), mounts the HTTP + GraphQL surfaces and schedules
38
+ * re-indexing.
39
+ *
40
+ * @example
41
+ * import { createAiRag, ragPlugin } from '@nixxie-cms/ai-rag'
42
+ * const aiRag = createAiRag({
43
+ * generation: { provider: 'anthropic', apiKey: process.env.ANTHROPIC_API_KEY! },
44
+ * embedding: { provider: 'openai', apiKey: process.env.OPENAI_API_KEY! },
45
+ * indexing: { schedule: '0 3 * * *' },
46
+ * })
47
+ * export default config({
48
+ * db: { ... },
49
+ * plugins: [ragPlugin({ service: aiRag })],
50
+ * })
51
+ */
52
+ export declare function ragPlugin(options: RagPluginOptions): NixxiePlugin;
53
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"../../../src","sources":["plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiB,YAAY,EAAE,MAAM,wBAAwB,CAAA;AACzE,OAAO,KAAK,EAAE,YAAY,EAAE,0BAAsB;AAElD,OAAO,EAAsB,KAAK,kBAAkB,EAAE,qBAAiB;AACvE,OAAO,EAAuB,KAAK,iBAAiB,EAAE,qBAAiB;AAEvE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,gDAAgD;IAChD,OAAO,EAAE,YAAY,CAAA;IACrB;;;;OAIG;IACH,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB;;;;OAIG;IACH,MAAM,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC,kBAAkB,EAAE,SAAS,CAAC,CAAA;IACtD;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,GAAG,iBAAiB,CAAA;IACrC,oGAAoG;IACpG,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA;AAkDD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,YAAY,CA2DjE"}
@@ -0,0 +1,14 @@
1
+ import type { NixxieRagChunk } from '@nixxie-cms/core';
2
+ import type { PromptBuildArgs, PromptBuildResult } from "./types.js";
3
+ export declare const DEFAULT_SYSTEM_PROMPT: string;
4
+ export declare const ALLOW_KNOWLEDGE_SYSTEM_PROMPT: string;
5
+ /** Render retrieved chunks as a numbered, citable source block. */
6
+ export declare function renderContext(chunks: NixxieRagChunk[], maxChars: number): string;
7
+ /**
8
+ * Default prompt assembly: a system prompt carrying the numbered context + citation rules,
9
+ * the trimmed history, and the user's question. Overridable via `generation.buildPrompt`.
10
+ */
11
+ export declare function buildRagPrompt(args: PromptBuildArgs, options: {
12
+ maxContextChars: number;
13
+ }): PromptBuildResult;
14
+ //# sourceMappingURL=prompt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt.d.ts","sourceRoot":"../../../src","sources":["prompt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACtD,OAAO,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,mBAAe;AAEjE,eAAO,MAAM,qBAAqB,QAGE,CAAA;AAEpC,eAAO,MAAM,6BAA6B,QAGN,CAAA;AAEpC,mEAAmE;AACnE,wBAAgB,aAAa,CAAC,MAAM,EAAE,cAAc,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAahF;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,eAAe,EACrB,OAAO,EAAE;IAAE,eAAe,EAAE,MAAM,CAAA;CAAE,GACnC,iBAAiB,CAyBnB"}
@@ -0,0 +1,16 @@
1
+ import type { RagProviderConfig } from "../types.js";
2
+ import type { GenerationProvider, RagGenerateOptions, RagGenerateResult, RagMessage, RagStreamChunk } from "./types.js";
3
+ /** Anthropic (Claude) generation provider with native streaming. */
4
+ export declare class AnthropicRagProvider implements GenerationProvider {
5
+ readonly name = "anthropic";
6
+ readonly defaultModel = "claude-opus-4-8";
7
+ private client;
8
+ private model;
9
+ private maxTokens;
10
+ private extra;
11
+ constructor(config: RagProviderConfig);
12
+ private buildBody;
13
+ generate(messages: RagMessage[], options?: RagGenerateOptions): Promise<RagGenerateResult>;
14
+ stream(messages: RagMessage[], options?: RagGenerateOptions): AsyncIterable<RagStreamChunk>;
15
+ }
16
+ //# sourceMappingURL=AnthropicRagProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AnthropicRagProvider.d.ts","sourceRoot":"../../../../src/providers","sources":["AnthropicRagProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,oBAAgB;AACjD,OAAO,KAAK,EACV,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,UAAU,EACV,cAAc,EACf,mBAAe;AAchB,oEAAoE;AACpE,qBAAa,oBAAqB,YAAW,kBAAkB;IAC7D,QAAQ,CAAC,IAAI,eAAc;IAC3B,QAAQ,CAAC,YAAY,qBAAgB;IACrC,OAAO,CAAC,MAAM,CAAK;IACnB,OAAO,CAAC,KAAK,CAAQ;IACrB,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,KAAK,CAAyB;gBAE1B,MAAM,EAAE,iBAAiB;IASrC,OAAO,CAAC,SAAS;IAaX,QAAQ,CAAC,QAAQ,EAAE,UAAU,EAAE,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAazF,MAAM,CACX,QAAQ,EAAE,UAAU,EAAE,EACtB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,aAAa,CAAC,cAAc,CAAC;CAsBjC"}
@@ -0,0 +1,19 @@
1
+ import type { RagProviderConfig } from "../types.js";
2
+ import type { EmbeddingProvider, GenerationProvider, RagGenerateOptions, RagGenerateResult, RagMessage, RagStreamChunk } from "./types.js";
3
+ /** Google Gemini provider over the public REST API — generation, streaming and embeddings. */
4
+ export declare class GeminiRagProvider implements GenerationProvider, EmbeddingProvider {
5
+ readonly name = "gemini";
6
+ readonly defaultModel = "gemini-2.0-flash";
7
+ private apiKey;
8
+ private model;
9
+ private embeddingModel;
10
+ private base;
11
+ private extra;
12
+ constructor(config: RagProviderConfig);
13
+ private buildBody;
14
+ private extractText;
15
+ generate(messages: RagMessage[], options?: RagGenerateOptions): Promise<RagGenerateResult>;
16
+ stream(messages: RagMessage[], options?: RagGenerateOptions): AsyncIterable<RagStreamChunk>;
17
+ embed(texts: string[], model?: string): Promise<number[][]>;
18
+ }
19
+ //# sourceMappingURL=GeminiRagProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GeminiRagProvider.d.ts","sourceRoot":"../../../../src/providers","sources":["GeminiRagProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,oBAAgB;AACjD,OAAO,KAAK,EACV,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,UAAU,EACV,cAAc,EACf,mBAAe;AAMhB,8FAA8F;AAC9F,qBAAa,iBAAkB,YAAW,kBAAkB,EAAE,iBAAiB;IAC7E,QAAQ,CAAC,IAAI,YAAW;IACxB,QAAQ,CAAC,YAAY,sBAAgB;IACrC,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,KAAK,CAAQ;IACrB,OAAO,CAAC,cAAc,CAAQ;IAC9B,OAAO,CAAC,IAAI,CAAQ;IACpB,OAAO,CAAC,KAAK,CAAyB;gBAE1B,MAAM,EAAE,iBAAiB;IASrC,OAAO,CAAC,SAAS;IAmBjB,OAAO,CAAC,WAAW;IAKb,QAAQ,CAAC,QAAQ,EAAE,UAAU,EAAE,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAsBzF,MAAM,CACX,QAAQ,EAAE,UAAU,EAAE,EACtB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,aAAa,CAAC,cAAc,CAAC;IA0B1B,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;CAgBlE"}
@@ -0,0 +1,23 @@
1
+ import type { RagProviderConfig } from "../types.js";
2
+ import type { EmbeddingProvider, GenerationProvider, RagGenerateOptions, RagGenerateResult, RagMessage, RagStreamChunk } from "./types.js";
3
+ /**
4
+ * Ollama provider for local (or remote) open models — generation, streaming and embeddings.
5
+ * Runs any Ollama model family (Llama, Mistral, Phi, Gemma, Qwen, …). No API key needed for a
6
+ * local server; point `baseUrl` at your Ollama host if it isn't on localhost.
7
+ */
8
+ export declare class OllamaRagProvider implements GenerationProvider, EmbeddingProvider {
9
+ readonly name = "ollama";
10
+ readonly defaultModel = "llama3.1";
11
+ private base;
12
+ private model;
13
+ private embeddingModel;
14
+ private apiKey?;
15
+ private extra;
16
+ constructor(config: RagProviderConfig);
17
+ private headers;
18
+ private buildBody;
19
+ generate(messages: RagMessage[], options?: RagGenerateOptions): Promise<RagGenerateResult>;
20
+ stream(messages: RagMessage[], options?: RagGenerateOptions): AsyncIterable<RagStreamChunk>;
21
+ embed(texts: string[], model?: string): Promise<number[][]>;
22
+ }
23
+ //# sourceMappingURL=OllamaRagProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OllamaRagProvider.d.ts","sourceRoot":"../../../../src/providers","sources":["OllamaRagProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,oBAAgB;AACjD,OAAO,KAAK,EACV,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,UAAU,EACV,cAAc,EACf,mBAAe;AAMhB;;;;GAIG;AACH,qBAAa,iBAAkB,YAAW,kBAAkB,EAAE,iBAAiB;IAC7E,QAAQ,CAAC,IAAI,YAAW;IACxB,QAAQ,CAAC,YAAY,cAAgB;IACrC,OAAO,CAAC,IAAI,CAAQ;IACpB,OAAO,CAAC,KAAK,CAAQ;IACrB,OAAO,CAAC,cAAc,CAAQ;IAC9B,OAAO,CAAC,MAAM,CAAC,CAAQ;IACvB,OAAO,CAAC,KAAK,CAAyB;gBAE1B,MAAM,EAAE,iBAAiB;IAQrC,OAAO,CAAC,OAAO;IAOf,OAAO,CAAC,SAAS;IAkBX,QAAQ,CAAC,QAAQ,EAAE,UAAU,EAAE,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAezF,MAAM,CACX,QAAQ,EAAE,UAAU,EAAE,EACtB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,aAAa,CAAC,cAAc,CAAC;IAuB1B,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;CA0BlE"}
@@ -0,0 +1,17 @@
1
+ import type { RagProviderConfig } from "../types.js";
2
+ import type { EmbeddingProvider, GenerationProvider, RagGenerateOptions, RagGenerateResult, RagMessage, RagStreamChunk } from "./types.js";
3
+ /** OpenAI (GPT) provider — generation, streaming and embeddings. */
4
+ export declare class OpenAiRagProvider implements GenerationProvider, EmbeddingProvider {
5
+ readonly name = "openai";
6
+ readonly defaultModel = "gpt-4o";
7
+ private client;
8
+ private model;
9
+ private embeddingModel;
10
+ private extra;
11
+ constructor(config: RagProviderConfig);
12
+ private buildMessages;
13
+ generate(messages: RagMessage[], options?: RagGenerateOptions): Promise<RagGenerateResult>;
14
+ stream(messages: RagMessage[], options?: RagGenerateOptions): AsyncIterable<RagStreamChunk>;
15
+ embed(texts: string[], model?: string): Promise<number[][]>;
16
+ }
17
+ //# sourceMappingURL=OpenAiRagProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OpenAiRagProvider.d.ts","sourceRoot":"../../../../src/providers","sources":["OpenAiRagProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,oBAAgB;AACjD,OAAO,KAAK,EACV,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,UAAU,EACV,cAAc,EACf,mBAAe;AAehB,oEAAoE;AACpE,qBAAa,iBAAkB,YAAW,kBAAkB,EAAE,iBAAiB;IAC7E,QAAQ,CAAC,IAAI,YAAW;IACxB,QAAQ,CAAC,YAAY,YAAgB;IACrC,OAAO,CAAC,MAAM,CAAK;IACnB,OAAO,CAAC,KAAK,CAAQ;IACrB,OAAO,CAAC,cAAc,CAAQ;IAC9B,OAAO,CAAC,KAAK,CAAyB;gBAE1B,MAAM,EAAE,iBAAiB;IASrC,OAAO,CAAC,aAAa;IAOf,QAAQ,CAAC,QAAQ,EAAE,UAAU,EAAE,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAoBzF,MAAM,CACX,QAAQ,EAAE,UAAU,EAAE,EACtB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,aAAa,CAAC,cAAc,CAAC;IAyB1B,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;CAWlE"}
@@ -0,0 +1,17 @@
1
+ import type { NixxieAiService } from '@nixxie-cms/core';
2
+ import type { EmbeddingProvider, GenerationProvider, RagGenerateOptions, RagGenerateResult, RagMessage, RagStreamChunk } from "./types.js";
3
+ /**
4
+ * Adapts an existing `NixxieAiService` (e.g. `context.services.ai` from @nixxie-cms/ai)
5
+ * into a RAG provider. Streaming is emulated by emitting the full answer as one delta,
6
+ * since `NixxieAiService` has no streaming surface.
7
+ */
8
+ export declare class ServiceRagProvider implements GenerationProvider, EmbeddingProvider {
9
+ private service;
10
+ readonly name = "service";
11
+ readonly defaultModel = "service";
12
+ constructor(service: NixxieAiService);
13
+ generate(messages: RagMessage[], options?: RagGenerateOptions): Promise<RagGenerateResult>;
14
+ stream(messages: RagMessage[], options?: RagGenerateOptions): AsyncIterable<RagStreamChunk>;
15
+ embed(texts: string[]): Promise<number[][]>;
16
+ }
17
+ //# sourceMappingURL=ServiceRagProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ServiceRagProvider.d.ts","sourceRoot":"../../../../src/providers","sources":["ServiceRagProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AACvD,OAAO,KAAK,EACV,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,UAAU,EACV,cAAc,EACf,mBAAe;AAEhB;;;;GAIG;AACH,qBAAa,kBAAmB,YAAW,kBAAkB,EAAE,iBAAiB;IAIlE,OAAO,CAAC,OAAO;IAH3B,QAAQ,CAAC,IAAI,aAAY;IACzB,QAAQ,CAAC,YAAY,aAAY;gBAEb,OAAO,EAAE,eAAe;IAEtC,QAAQ,CAAC,QAAQ,EAAE,UAAU,EAAE,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAUzF,MAAM,CACX,QAAQ,EAAE,UAAU,EAAE,EACtB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,aAAa,CAAC,cAAc,CAAC;IAM1B,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;CAGlD"}