@hiai-gg/docsmint 0.3.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 (57) hide show
  1. package/LICENSE +171 -0
  2. package/README.md +348 -0
  3. package/backend/src/lib/logger.ts +18 -0
  4. package/backend/src/lib/redis-factory.ts +40 -0
  5. package/backend/src/lib/storage-factory.ts +56 -0
  6. package/frontend/src/lib/components/editor/shared-document.ts +237 -0
  7. package/frontend/src/lib/extensions/context.ts +60 -0
  8. package/frontend/src/lib/extensions/doc-tabs.ts +18 -0
  9. package/frontend/src/lib/extensions/resolve.ts +48 -0
  10. package/frontend/src/lib/extensions/types.ts +202 -0
  11. package/frontend/src/lib/hosts/DocsmintSharedDocumentHost.svelte +65 -0
  12. package/frontend/src/lib/hosts/HiaiDocsDashboardHost.svelte +1007 -0
  13. package/frontend/src/lib/hosts/HiaiDocsExtensionProvider.svelte +20 -0
  14. package/frontend/src/lib/hosts/HiaiDocsSearchHost.svelte +996 -0
  15. package/frontend/src/lib/hosts/index.ts +25 -0
  16. package/frontend/src/lib/index.ts +65 -0
  17. package/frontend/src/lib/stores/doc-tab-registry.svelte.ts +68 -0
  18. package/package.json +178 -0
  19. package/packages/cli/src/client.ts +271 -0
  20. package/packages/cli/src/commands/config.ts +47 -0
  21. package/packages/cli/src/commands/create.ts +35 -0
  22. package/packages/cli/src/commands/delete.ts +37 -0
  23. package/packages/cli/src/commands/export.ts +36 -0
  24. package/packages/cli/src/commands/folders.ts +88 -0
  25. package/packages/cli/src/commands/history.ts +55 -0
  26. package/packages/cli/src/commands/list.ts +61 -0
  27. package/packages/cli/src/commands/read.ts +38 -0
  28. package/packages/cli/src/commands/restore.ts +30 -0
  29. package/packages/cli/src/commands/search.ts +56 -0
  30. package/packages/cli/src/commands/snapshot.ts +35 -0
  31. package/packages/cli/src/commands/update.ts +54 -0
  32. package/packages/cli/src/config.ts +83 -0
  33. package/packages/cli/src/format.ts +153 -0
  34. package/packages/cli/src/index.ts +73 -0
  35. package/packages/db/src/client.ts +20 -0
  36. package/packages/db/src/index.ts +5 -0
  37. package/packages/db/src/schema.ts +692 -0
  38. package/packages/db/src/with-tenant.ts +75 -0
  39. package/packages/mcp-server/src/client.ts +172 -0
  40. package/packages/mcp-server/src/index.ts +109 -0
  41. package/packages/mcp-server/src/tools/create-document.ts +32 -0
  42. package/packages/mcp-server/src/tools/create-folder.ts +24 -0
  43. package/packages/mcp-server/src/tools/create-snapshot.ts +30 -0
  44. package/packages/mcp-server/src/tools/export-document.ts +22 -0
  45. package/packages/mcp-server/src/tools/get-document.ts +20 -0
  46. package/packages/mcp-server/src/tools/list-documents.ts +42 -0
  47. package/packages/mcp-server/src/tools/list-folders.ts +25 -0
  48. package/packages/mcp-server/src/tools/search.ts +42 -0
  49. package/packages/mcp-server/src/tools/update-document.ts +30 -0
  50. package/packages/mcp-server/src/tools/version-history.ts +32 -0
  51. package/packages/mcp-server/src/types.ts +126 -0
  52. package/packages/sdk/dist/client.d.ts +187 -0
  53. package/packages/sdk/dist/client.js +568 -0
  54. package/packages/sdk/dist/index.d.ts +3 -0
  55. package/packages/sdk/dist/index.js +1 -0
  56. package/packages/sdk/dist/types.d.ts +391 -0
  57. package/packages/sdk/dist/types.js +8 -0
package/LICENSE ADDED
@@ -0,0 +1,171 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work.
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is based on (or derived from) the Work and for which the
41
+ editorial revisions, annotations, elaborations, or other modifications
42
+ represent, as a whole, an original work of authorship. For the purposes
43
+ of this License, Derivative Works shall not include works that remain
44
+ separable from, or merely link (or bind by name) to the interfaces of,
45
+ the Work and Derivative Works thereof.
46
+
47
+ "Contribution" shall mean any work of authorship, including
48
+ the original version of the Work and any modifications or additions
49
+ to that Work or Derivative Works thereof, that is intentionally
50
+ submitted to Licensor for inclusion in the Work by the copyright owner
51
+ or by an individual or Legal Entity authorized to submit on behalf of
52
+ the copyright owner. For the purposes of this definition, "submitted"
53
+ means any form of electronic, verbal, or written communication sent
54
+ to the Licensor or its representatives, including but not limited to
55
+ communication on electronic mailing lists, source code control systems,
56
+ and issue tracking systems that are managed by, or on behalf of, the
57
+ Licensor for the purpose of discussing and improving the Work, but
58
+ excluding communication that is conspicuously marked or otherwise
59
+ designated in writing by the copyright owner as "Not a Contribution."
60
+
61
+ "Contributor" shall mean Licensor and any individual or Legal Entity
62
+ on behalf of whom a Contribution has been received by Licensor and
63
+ subsequently incorporated within the Work.
64
+
65
+ 2. Grant of Copyright License. Subject to the terms and conditions of
66
+ this License, each Contributor hereby grants to You a perpetual,
67
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
68
+ copyright license to reproduce, prepare Derivative Works of,
69
+ publicly display, publicly perform, sublicense, and distribute the
70
+ Work and such Derivative Works in Source or Object form.
71
+
72
+ 3. Grant of Patent License. Subject to the terms and conditions of
73
+ this License, each Contributor hereby grants to You a perpetual,
74
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
75
+ (except as stated in this section) patent license to make, have made,
76
+ use, offer to sell, sell, import, and otherwise transfer the Work,
77
+ where such license applies only to those patent claims licensable
78
+ by such Contributor that are necessarily infringed by their
79
+ Contribution(s) alone or by combination of their Contribution(s)
80
+ with the Work to which such Contribution(s) was submitted. If You
81
+ institute patent litigation against any entity (including a
82
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
83
+ or a Contribution incorporated within the Work constitutes direct
84
+ or contributory patent infringement, then any patent licenses
85
+ granted to You under this License for that Work shall terminate
86
+ as of the date such litigation is filed.
87
+
88
+ 4. Redistribution. You may reproduce and distribute copies of the
89
+ Work or Derivative Works thereof in any medium, with or without
90
+ modifications, and in Source or Object form, provided that You
91
+ meet the following conditions:
92
+
93
+ (a) You must give any other recipients of the Work or Derivative Works
94
+ a copy of this License; and
95
+
96
+ (b) You must cause any modified files to carry prominent notices
97
+ stating that You changed the files; and
98
+
99
+ (c) You must retain, in the Source form of any Derivative Works that
100
+ You distribute, all copyright, patent, trademark, and attribution
101
+ notices from the Source form of the Work, excluding those notices
102
+ that do not pertain to any part of the Derivative Works; and
103
+
104
+ (d) If the Work includes a "NOTICE" text file as part of its
105
+ distribution, then any Derivative Works that You distribute must
106
+ include a readable copy of the attribution notices contained
107
+ within such NOTICE file, excluding those notices that do not
108
+ pertain to any part of the Derivative Works, in at least one
109
+ of the following places: within a NOTICE text file distributed
110
+ as part of the Derivative Works; within the Source form or
111
+ documentation, if provided along with the Derivative Works; or,
112
+ within a display generated by the Derivative Works, if and
113
+ wherever such third-party notices normally appear. The contents
114
+ of the NOTICE file are for informational purposes only and
115
+ do not modify the License. You may add Your own attribution
116
+ notices within Derivative Works that You distribute, alongside
117
+ or as an addendum to the NOTICE text from the Work, provided
118
+ that such additional attribution notices cannot be construed
119
+ as modifying the License.
120
+
121
+ You may add Your own copyright statement to Your modifications and
122
+ may provide additional or different license terms and conditions
123
+ for use, reproduction, or distribution of Your modifications, or
124
+ for any such Derivative Works as a whole, provided Your use,
125
+ reproduction, and distribution of the Work otherwise complies with
126
+ the conditions stated in this License.
127
+
128
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
129
+ any Contribution intentionally submitted for inclusion in the Work
130
+ by You to the Licensor shall be under the terms and conditions of
131
+ this License, without any additional terms or conditions.
132
+
133
+ 6. Trademarks. This License does not grant permission to use the trade
134
+ names, trademarks, service marks, or product names of the Licensor,
135
+ except as required for reasonable and customary use in describing the
136
+ origin of the Work and reproducing the content of the NOTICE file.
137
+
138
+ 7. Disclaimer of Warranty. Unless required by applicable law or
139
+ agreed to in writing, Licensor provides the Work (and each
140
+ Contributor provides its Contributions) on an "AS IS" BASIS,
141
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
142
+ implied, including, without limitation, any warranties or conditions
143
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
144
+ PARTICULAR PURPOSE. You are solely responsible for determining the
145
+ appropriateness of using or redistributing the Work and assume any
146
+ risks associated with Your exercise of permissions under this License.
147
+
148
+ 8. Limitation of Liability. In no event and under no legal theory,
149
+ whether in tort (including negligence), contract, or otherwise,
150
+ unless required by applicable law (such as deliberate and grossly
151
+ negligent acts) or agreed to in writing, shall any Contributor be
152
+ liable to You for damages, including any direct, indirect, special,
153
+ incidental, or consequential damages of any character arising as a
154
+ result of this License or out of the use or inability to use the
155
+ Work (including but not limited to damages for loss of goodwill,
156
+ work stoppage, computer failure or malfunction, or any and all
157
+ other commercial damages or losses), even if such Contributor
158
+ has been advised of the possibility of such damages.
159
+
160
+ 9. Accepting Warranty or Additional Liability. While redistributing
161
+ the Work or Derivative Works thereof, You may choose to offer,
162
+ and charge a fee for, acceptance of support, warranty, indemnity,
163
+ or other liability obligations and/or rights consistent with this
164
+ License. However, in accepting such obligations, You may act only
165
+ on Your own behalf and on Your sole responsibility, not on behalf
166
+ of any other Contributor, and only if You agree to indemnify,
167
+ defend, and hold each Contributor harmless for any liability
168
+ incurred by, or claims asserted against, such Contributor by reason
169
+ of your accepting any such warranty or additional liability.
170
+
171
+ END OF TERMS AND CONDITIONS
package/README.md ADDED
@@ -0,0 +1,348 @@
1
+ # HiAi-Docs / DocsMint
2
+
3
+ **A self-hosted, AI-native knowledge workspace for people, applications, and agents.**
4
+
5
+ HiAi-Docs is the open-source module and repository. **DocsMint** is the current
6
+ product branding used by the standalone installable web application. Typed
7
+ frontend hosts and extension contracts support self-hosted customization.
8
+
9
+ HiAi-Docs stores documents in a structured JSON editor model first. Markdown is
10
+ the convenient second format for editing, importing, and exporting content.
11
+ Automatic chunking, 1024-dimensional embeddings, multilingual hybrid search,
12
+ and GraphRAG make the same knowledge base useful to people, applications, and
13
+ agents through the web application, REST API, TypeScript SDK, CLI, and MCP
14
+ server.
15
+
16
+ [![Apache-2.0 License](https://img.shields.io/badge/License-Apache--2.0-green.svg)](LICENSE)
17
+ [![Release](https://img.shields.io/github/v/release/hiai-gg/docsmint?sort=semver)](https://github.com/hiai-gg/docsmint/releases)
18
+ [![Stars](https://img.shields.io/github/stars/hiai-gg/docsmint)](https://github.com/hiai-gg/docsmint/stargazers)
19
+ [![CI](https://github.com/hiai-gg/docsmint/actions/workflows/ci.yml/badge.svg)](https://github.com/hiai-gg/docsmint/actions/workflows/ci.yml)
20
+ [![Bun](https://img.shields.io/badge/Runtime-Bun_1.3-black?logo=bun&logoColor=white)](https://bun.sh)
21
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.x-3178C6?logo=typescript&logoColor=white)](https://www.typescriptlang.org)
22
+ [![Svelte](https://img.shields.io/badge/Svelte-5.x-FF3E00?logo=svelte&logoColor=white)](https://svelte.dev)
23
+ [![Elysia](https://img.shields.io/badge/Elysia-1.4-lightgrey?logo=elysia&logoColor=white)](https://elysiajs.com)
24
+ [![Tailwind_CSS](https://img.shields.io/badge/Tailwind_CSS-v4-06B6D4?logo=tailwindcss&logoColor=white)](https://tailwindcss.com)
25
+ [![Drizzle_ORM](https://img.shields.io/badge/Drizzle_ORM-0.45-C5F74F?logo=drizzle&logoColor=black)](https://orm.drizzle.team)
26
+ [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md)
27
+
28
+ <img width="1920" height="974" alt="DocsMint installable document workspace" src="https://github.com/user-attachments/assets/94701d01-a361-4ca1-b16d-de2a0c64d684" />
29
+
30
+ ## Why HiAi-Docs?
31
+
32
+ - **Write naturally** in a rich visual editor or raw Markdown.
33
+ - **Find meaning, not only keywords** with exact, lexical, fuzzy, vector,
34
+ multilingual expansion, and graph retrieval fused through RRF.
35
+ - **Keep retrieval current** with automatic, incremental chunking and
36
+ re-embedding after document or metadata changes.
37
+ - **Connect agents directly** through REST, a typed SDK, CLI, or MCP.
38
+ - **Control access** with global keys or category-scoped `read`, `edit`, and
39
+ `write` permissions.
40
+ - **Own the full stack**: application data, vectors, graph, queue, and files run
41
+ on infrastructure you control.
42
+
43
+ ## What is new in the 0.3.0 release line?
44
+
45
+ - **Installable Progressive Web App (PWA)** with a manifest, service worker,
46
+ responsive mobile shell, install prompt, update safety, and an offline
47
+ fallback shell.
48
+ - **Offline document access** through identity-partitioned IndexedDB/Dexie
49
+ snapshots. Offline mode is cached read plus explicit local drafts; reconnect
50
+ never silently replays mutations.
51
+ - **Explicit local drafts** with local autosave, review/apply, optimistic
52
+ concurrency (`expectedUpdatedAt`), and actionable conflict handling.
53
+ - **Composable host integration** with typed dashboard/search hosts and
54
+ extension slots. Standalone HiAi-Docs remains owner-scoped.
55
+ - **Mobile-first editor polish** including a single responsive sidebar, safe
56
+ PWA updates, raw Markdown auto-height, and accessible narrow-screen controls.
57
+
58
+ Search terms: installable self-hosted PWA knowledge base, offline document
59
+ reading, local drafts, semantic multilingual search, GraphRAG, MCP, TypeScript
60
+ SDK, CLI, and frontend extension hosts.
61
+
62
+ For self-hosted customization, see [PWA hosting](docs/PWA_HOSTING.md) and
63
+ [extension points](docs/EXTENDING.md).
64
+
65
+ ## Fastest installation: give this prompt to your agent
66
+
67
+ If you are installing HiAi-Docs through an AI coding agent, use this path first.
68
+ It keeps the setup to Docker plus one provider choice and avoids unnecessary
69
+ source-code changes.
70
+
71
+ ```text
72
+ Install HiAi-Docs from https://github.com/HiAi-gg/docsmint.
73
+ Verify Docker and Docker Compose v2, clone the repository, and run
74
+ `bash scripts/quickstart.sh`. Do not print or commit .env. Ask me to enter only
75
+ an OpenRouter key or select Ollama, then run quickstart again. Verify
76
+ http://localhost:50701, http://localhost:50700/api/health, and
77
+ `docker compose ps`. Do not replace Bun, rewrite migrations, disable GraphRAG,
78
+ or delete volumes.
79
+ ```
80
+
81
+ After startup, open **http://localhost:50701** and create the first account.
82
+ For manual installation, use the Docker quickstart below.
83
+
84
+ ## Quickstart
85
+
86
+ ### Requirements
87
+
88
+ - Docker Engine or Docker Desktop
89
+ - Docker Compose v2
90
+ - One of:
91
+ - an [OpenRouter](https://openrouter.ai/) API key; or
92
+ - a local [Ollama](https://ollama.com/) instance
93
+
94
+ ### Start with Docker
95
+
96
+ ```bash
97
+ git clone https://github.com/HiAi-gg/docsmint.git
98
+ cd docsmint
99
+ bash scripts/quickstart.sh
100
+ ```
101
+ On its first run, the script creates an ignored root `.env`, generates the
102
+ database, authentication, and storage secrets, builds the PostgreSQL image,
103
+ applies migrations, and starts the complete application.
104
+
105
+ For OpenRouter, add one value to `.env` and run the script again:
106
+
107
+ ```dotenv
108
+ OPENROUTER_API_KEY=sk-or-your-key
109
+ ```
110
+ For Ollama, select the local provider instead:
111
+
112
+ ```dotenv
113
+ AI_PROVIDER=ollama
114
+ OLLAMA_PORT=11434
115
+ ```
116
+ Then make sure the configured local models are available:
117
+
118
+ ```bash
119
+ ollama pull bge-m3
120
+ ollama pull qwen3:8b
121
+ bash scripts/quickstart.sh
122
+ ```
123
+ Open **http://localhost:50701**. The API health endpoint is
124
+ **http://localhost:50700/api/health**.
125
+
126
+ ### First use
127
+
128
+ 1. Create your account in the web application.
129
+ 2. Create a category or folder and add or import a document.
130
+ 3. Wait for the document pipeline to finish chunking and embedding.
131
+ 4. Search using an exact phrase, a related concept, an alternate language, or
132
+ a misspelling.
133
+ 5. Open **Settings → API** when you want to connect a CLI, MCP client, or
134
+ external application.
135
+
136
+ The canonical local ports are:
137
+
138
+ | Service | Port |
139
+ |---|---:|
140
+ | Web application | `50701` |
141
+ | REST API | `50700` |
142
+ | PostgreSQL | `5437` |
143
+ | Redis | `6384` |
144
+ | SeaweedFS S3 gateway | `50702` |
145
+ | SeaweedFS filer UI | `50703` |
146
+
147
+ See [Deployment](docs/DEPLOYMENT.md) for domains, TLS, provider tuning,
148
+ backups, and production operation.
149
+
150
+ ## Use HiAi-Docs from the terminal
151
+
152
+ The published package includes the CLI. It connects to an already running
153
+ HiAi-Docs server; installing it does not deploy the server.
154
+
155
+ ```bash
156
+ bunx --package @hiai-gg/docsmint docsmint init \
157
+ --url http://localhost:50700 \
158
+ --key 'your-global-or-category-key'
159
+
160
+ bunx --package @hiai-gg/docsmint docsmint search "project architecture"
161
+ bunx --package @hiai-gg/docsmint docsmint list
162
+ bunx --package @hiai-gg/docsmint docsmint read <document-id>
163
+ bunx --package @hiai-gg/docsmint docsmint create \
164
+ --title "Release notes" --content "# Version 0.2.9"
165
+ ```
166
+ Credentials can also be supplied through `HIAI_DOCS_URL` and
167
+ `HIAI_DOCS_API_KEY`. See the [CLI guide](packages/cli/README.md) for every
168
+ command and configuration precedence.
169
+
170
+ ## Connect an MCP client
171
+
172
+ HiAi-Docs exposes document search, reading, creation, updates, folders,
173
+ snapshots, history, and export as MCP tools.
174
+
175
+ ```json
176
+ {
177
+ "mcpServers": {
178
+ "docsmint": {
179
+ "command": "bunx",
180
+ "args": ["--package", "@hiai-gg/docsmint", "docsmint-mcp"],
181
+ "env": {
182
+ "HIAI_DOCS_URL": "http://localhost:50700",
183
+ "HIAI_DOCS_API_KEY": "your-global-or-category-key"
184
+ }
185
+ }
186
+ }
187
+ }
188
+ ```
189
+ Run the server directly to verify the installation:
190
+
191
+ ```bash
192
+ bunx --package @hiai-gg/docsmint docsmint-mcp
193
+ ```
194
+ The server uses stdio and works with MCP-capable clients such as Claude
195
+ Desktop, Cursor, and coding agents that accept standard MCP configuration. See
196
+ the [MCP guide](packages/mcp-server/README.md) for its ten tools and routes.
197
+
198
+ ## Agent skills after installation
199
+
200
+ The MCP tools are the recommended portable agent skills. A category-bound agent
201
+ can receive only the knowledge and operations it needs; a trusted personal
202
+ agent can use a global key. Agents do not need database or filesystem access.
203
+ After startup, create an API key in **Settings → API** and add the MCP block
204
+ above to the agent client. For custom agent workflows, use the same key through
205
+ the CLI, SDK, or REST API.
206
+
207
+ ## TypeScript SDK
208
+
209
+ ```bash
210
+ bun add @hiai-gg/docsmint
211
+ ```
212
+ ```ts
213
+ import { DocsClient } from "@hiai-gg/docsmint";
214
+
215
+ const docs = new DocsClient({
216
+ baseUrl: "http://localhost:50700",
217
+ apiKey: process.env.HIAI_DOCS_API_KEY,
218
+ });
219
+
220
+ const created = await docs.createDoc({
221
+ title: "Meeting notes",
222
+ content: "# Agenda",
223
+ });
224
+
225
+ const results = await docs.search("what did we decide?");
226
+ console.log(created.id, results.items);
227
+ ```
228
+ The SDK is a typed `fetch` client with retries for transient failures. See the
229
+ [SDK reference](packages/sdk/README.md) and [REST API](docs/API.md).
230
+
231
+ ## API keys and integrations
232
+
233
+ Create and revoke integration keys from **Settings → API**.
234
+
235
+ | Credential | Intended use | Access |
236
+ |---|---|---|
237
+ | Global API key | Trusted owner-wide CLI, MCP, SDK, or service | All owner content |
238
+ | Category key | Least-privilege agent or product integration | One category with selected permissions |
239
+ | Operator key | Administration and reindex operations | `/api/admin/*` only |
240
+
241
+ Category permissions are explicit and non-hierarchical:
242
+
243
+ - `read` permits list, read, search, and export;
244
+ - `edit` permits updates to existing content, attachments, and versions;
245
+ - `write` permits create, move, delete, share, and publish operations.
246
+
247
+ Combine permissions when an integration needs more than one capability.
248
+ API-key lifecycle operations require the owning browser session; an API key
249
+ cannot create or elevate another key. Server-to-server integrations are not
250
+ affected by browser CORS. Browser integrations must add their exact origin to
251
+ `CORS_ORIGINS`.
252
+
253
+ ## What is included?
254
+
255
+ ```text
256
+ frontend/ SvelteKit workspace and TipTap editor
257
+ backend/ Elysia REST API, search, workers, and authentication
258
+ packages/db/ Drizzle schema and migrations
259
+ packages/sdk/ Typed API client
260
+ packages/cli/ Terminal client
261
+ packages/mcp-server/ MCP stdio server
262
+ postgres/ PostgreSQL image with vector and graph extensions
263
+ ```
264
+ The Docker deployment runs:
265
+
266
+ - **Web** — document editor, folders, categories, sharing, settings, and search;
267
+ - **API** — documents, attachments, versions, keys, search, and administration;
268
+ - **PostgreSQL 18** — relational data, pgvector/pgvectorscale vectors, and the
269
+ Apache AGE graph in one database;
270
+ - **Redis 8** — BullMQ queues, caching, retries, and job recovery;
271
+ - **SeaweedFS** — S3-compatible attachment storage.
272
+
273
+ ## How search works
274
+
275
+ Every document save schedules background work. Content is chunked, changed
276
+ chunks are embedded, and the completed generation is activated atomically. The
277
+ previous valid generation remains searchable if a provider call fails.
278
+
279
+ Search combines exact title matches, multilingual lexical search, typo-tolerant
280
+ fuzzy matching, semantic vectors, adaptive query expansion, and Apache AGE
281
+ graph neighbors. Reciprocal rank fusion combines the channels without allowing
282
+ one weak provider result to dominate. Authorization is applied before retrieval
283
+ and again before results are returned.
284
+
285
+ GraphRAG is part of the normal search path in the reference configuration. It
286
+ extracts entities after embeddings are ready and finds related documents beyond
287
+ direct keyword or vector similarity. It degrades gracefully when an external
288
+ model is unavailable.
289
+
290
+ For pipeline internals and tuning, see [Architecture](docs/ARCHITECTURE.md) and
291
+ [Deployment](docs/DEPLOYMENT.md).
292
+
293
+ ## Stack
294
+
295
+ - Bun, TypeScript, Elysia, Zod, and Pino
296
+ - Svelte 5, SvelteKit, Tailwind CSS, and TipTap
297
+ - Better Auth and Drizzle ORM
298
+ - PostgreSQL 18, pgvector, pgvectorscale, and Apache AGE
299
+ - Redis 8 and BullMQ
300
+ - SeaweedFS with its S3-compatible API
301
+ - OpenAI-compatible providers through OpenRouter or local Ollama
302
+
303
+ ## Comparison
304
+
305
+ HiAi-Docs overlaps with several excellent open-source knowledge tools, but its
306
+ focus is a compact knowledge runtime shared equally by humans and agents.
307
+
308
+ | Project | Primary strength | Difference from HiAi-Docs |
309
+ |---|---|---|
310
+ | [Outline](https://github.com/outline/outline) | Polished team wiki and collaboration | HiAi-Docs emphasizes built-in retrieval, GraphRAG, scoped agent access, CLI, and MCP |
311
+ | [Docmost](https://github.com/docmost/docmost) | Collaborative wiki and real-time editing | HiAi-Docs centers automatic embeddings and agent-facing integration surfaces |
312
+ | [AppFlowy](https://github.com/AppFlowy-IO/AppFlowy) | Broad local-first productivity workspace | HiAi-Docs is narrower: a self-hosted document and retrieval service |
313
+ | [AnythingLLM](https://github.com/Mintplex-Labs/anything-llm) | Chat-oriented RAG over imported sources | HiAi-Docs starts with the editable knowledge base and exposes it to many clients |
314
+ | [Danswer](https://github.com/danswer-ai/danswer) / Onyx | Enterprise search across external connectors | HiAi-Docs owns and edits its native corpus rather than primarily indexing other systems |
315
+
316
+ This is a product-positioning summary, not a claim that every listed project
317
+ lacks a feature. Check each project's current documentation when choosing a
318
+ deployment.
319
+
320
+ ## Documentation
321
+
322
+ - [Documentation index](docs/README.md)
323
+ - [Product usage](docs/USAGE.md)
324
+ - [REST API](docs/API.md) and [OpenAPI JSON](docs/openapi.json)
325
+ - [Architecture](docs/ARCHITECTURE.md)
326
+ - [Deployment and operations](docs/DEPLOYMENT.md)
327
+ - [Extension points](docs/EXTENDING.md)
328
+ - [Maintainer release flow](docs/RELEASING.md)
329
+ - [Security policy](SECURITY.md)
330
+ - [Changelog](CHANGELOG.md)
331
+
332
+ ## Development
333
+
334
+ ```bash
335
+ bun install
336
+ bun run lint
337
+ bun run typecheck
338
+ bun run test
339
+ bun run build
340
+ ```
341
+ Read [CONTRIBUTING.md](CONTRIBUTING.md) before opening a pull request. Please
342
+ report vulnerabilities through [SECURITY.md](SECURITY.md), not a public issue.
343
+
344
+ ## License
345
+
346
+ HiAi-Docs / DocsMint is released under the [Apache License 2.0](LICENSE).
347
+
348
+ Part of the [HiAi](https://hiai.gg) open-source ecosystem.
@@ -0,0 +1,18 @@
1
+ import pino from "pino";
2
+
3
+ // Read env directly to avoid circular dependency with config.ts
4
+ const level = (process.env.LOG_LEVEL ?? "info") as
5
+ | "trace"
6
+ | "debug"
7
+ | "info"
8
+ | "warn"
9
+ | "error"
10
+ | "fatal";
11
+ const isDev = process.env.NODE_ENV === "development";
12
+
13
+ export const logger = pino({
14
+ level,
15
+ transport: isDev
16
+ ? { target: "pino-pretty", options: { colorize: true } }
17
+ : undefined,
18
+ });
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Pure Redis factory — no module-eval side effects.
3
+ *
4
+ * This module MUST NOT import `./config` (which calls `envSchema.parse` and
5
+ * `process.exit(1)` at import time). External consumers (e.g. docsmint)
6
+ * import this through the npm export `@hiai-gg/docsmint/backend/lib/redis`
7
+ * to call `createRedis(cfg)` with their own config; pulling hiai-docs'
8
+ * env-validation into their process would crash it on the first missing
9
+ * variable.
10
+ *
11
+ * The singleton that powers hiai-docs' own runtime lives in `./redis.ts`
12
+ * and imports this factory.
13
+ */
14
+ import Redis from "ioredis";
15
+ import { logger } from "./logger";
16
+
17
+ export interface RedisConfig {
18
+ url: string;
19
+ maxRetriesPerRequest: number;
20
+ }
21
+
22
+ export function createRedis(cfg: RedisConfig): Redis {
23
+ const instance = new Redis(cfg.url, {
24
+ maxRetriesPerRequest: cfg.maxRetriesPerRequest,
25
+ retryStrategy(times) {
26
+ const delay = Math.min(times * 200, 2000);
27
+ return delay;
28
+ },
29
+ });
30
+
31
+ instance.on("error", (err) => {
32
+ logger.error({ err }, "Redis connection error");
33
+ });
34
+
35
+ instance.on("connect", () => {
36
+ logger.info("Redis connected");
37
+ });
38
+
39
+ return instance;
40
+ }
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Pure S3 (SeaweedFS) factory — no module-eval side effects.
3
+ *
4
+ * This module MUST NOT import `./config` (which calls `envSchema.parse` and
5
+ * `process.exit(1)` at import time). External consumers (e.g. docsmint)
6
+ * import this through the npm export `@hiai-gg/docsmint/backend/lib/storage`
7
+ * to call `createObjectStorageClient(cfg)` with their own config; pulling
8
+ * hiai-docs' env-validation into their process would crash it on the first
9
+ * missing variable.
10
+ *
11
+ * The singletons that power hiai-docs' own runtime live in `./storage.ts`
12
+ * and import this factory.
13
+ */
14
+ import { S3Client } from "@aws-sdk/client-s3";
15
+ import { logger } from "./logger";
16
+
17
+ export interface ObjectStorageConfig {
18
+ endpoint: string;
19
+ port: number;
20
+ accessKey: string;
21
+ secretKey: string;
22
+ useSSL: boolean;
23
+ region: string;
24
+ forcePathStyle: boolean;
25
+ }
26
+
27
+ export function createObjectStorageClient(cfg: ObjectStorageConfig): S3Client {
28
+ return new S3Client({
29
+ endpoint: cfg.useSSL
30
+ ? `https://${cfg.endpoint}:${cfg.port}`
31
+ : `http://${cfg.endpoint}:${cfg.port}`,
32
+ region: cfg.region,
33
+ credentials: {
34
+ accessKeyId: cfg.accessKey,
35
+ secretAccessKey: cfg.secretKey,
36
+ },
37
+ forcePathStyle: cfg.forcePathStyle,
38
+ requestChecksumCalculation: "WHEN_REQUIRED",
39
+ responseChecksumValidation: "WHEN_REQUIRED",
40
+ });
41
+ }
42
+
43
+ export async function ensureBucket(
44
+ client: S3Client,
45
+ bucket: string,
46
+ ): Promise<void> {
47
+ const { HeadBucketCommand, CreateBucketCommand } = await import(
48
+ "@aws-sdk/client-s3"
49
+ );
50
+ try {
51
+ await client.send(new HeadBucketCommand({ Bucket: bucket }));
52
+ } catch {
53
+ await client.send(new CreateBucketCommand({ Bucket: bucket }));
54
+ logger.info({ bucket }, "Created storage bucket");
55
+ }
56
+ }