@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.
- package/LICENSE +171 -0
- package/README.md +348 -0
- package/backend/src/lib/logger.ts +18 -0
- package/backend/src/lib/redis-factory.ts +40 -0
- package/backend/src/lib/storage-factory.ts +56 -0
- package/frontend/src/lib/components/editor/shared-document.ts +237 -0
- package/frontend/src/lib/extensions/context.ts +60 -0
- package/frontend/src/lib/extensions/doc-tabs.ts +18 -0
- package/frontend/src/lib/extensions/resolve.ts +48 -0
- package/frontend/src/lib/extensions/types.ts +202 -0
- package/frontend/src/lib/hosts/DocsmintSharedDocumentHost.svelte +65 -0
- package/frontend/src/lib/hosts/HiaiDocsDashboardHost.svelte +1007 -0
- package/frontend/src/lib/hosts/HiaiDocsExtensionProvider.svelte +20 -0
- package/frontend/src/lib/hosts/HiaiDocsSearchHost.svelte +996 -0
- package/frontend/src/lib/hosts/index.ts +25 -0
- package/frontend/src/lib/index.ts +65 -0
- package/frontend/src/lib/stores/doc-tab-registry.svelte.ts +68 -0
- package/package.json +178 -0
- package/packages/cli/src/client.ts +271 -0
- package/packages/cli/src/commands/config.ts +47 -0
- package/packages/cli/src/commands/create.ts +35 -0
- package/packages/cli/src/commands/delete.ts +37 -0
- package/packages/cli/src/commands/export.ts +36 -0
- package/packages/cli/src/commands/folders.ts +88 -0
- package/packages/cli/src/commands/history.ts +55 -0
- package/packages/cli/src/commands/list.ts +61 -0
- package/packages/cli/src/commands/read.ts +38 -0
- package/packages/cli/src/commands/restore.ts +30 -0
- package/packages/cli/src/commands/search.ts +56 -0
- package/packages/cli/src/commands/snapshot.ts +35 -0
- package/packages/cli/src/commands/update.ts +54 -0
- package/packages/cli/src/config.ts +83 -0
- package/packages/cli/src/format.ts +153 -0
- package/packages/cli/src/index.ts +73 -0
- package/packages/db/src/client.ts +20 -0
- package/packages/db/src/index.ts +5 -0
- package/packages/db/src/schema.ts +692 -0
- package/packages/db/src/with-tenant.ts +75 -0
- package/packages/mcp-server/src/client.ts +172 -0
- package/packages/mcp-server/src/index.ts +109 -0
- package/packages/mcp-server/src/tools/create-document.ts +32 -0
- package/packages/mcp-server/src/tools/create-folder.ts +24 -0
- package/packages/mcp-server/src/tools/create-snapshot.ts +30 -0
- package/packages/mcp-server/src/tools/export-document.ts +22 -0
- package/packages/mcp-server/src/tools/get-document.ts +20 -0
- package/packages/mcp-server/src/tools/list-documents.ts +42 -0
- package/packages/mcp-server/src/tools/list-folders.ts +25 -0
- package/packages/mcp-server/src/tools/search.ts +42 -0
- package/packages/mcp-server/src/tools/update-document.ts +30 -0
- package/packages/mcp-server/src/tools/version-history.ts +32 -0
- package/packages/mcp-server/src/types.ts +126 -0
- package/packages/sdk/dist/client.d.ts +187 -0
- package/packages/sdk/dist/client.js +568 -0
- package/packages/sdk/dist/index.d.ts +3 -0
- package/packages/sdk/dist/index.js +1 -0
- package/packages/sdk/dist/types.d.ts +391 -0
- package/packages/sdk/dist/types.js +8 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared TypeScript types for hiai-docs REST API responses.
|
|
3
|
+
* Keep these minimal — only the fields consumed by MCP tools.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export interface Tag {
|
|
7
|
+
id: string;
|
|
8
|
+
name: string;
|
|
9
|
+
color: string | null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface DocumentSummary {
|
|
13
|
+
id: string;
|
|
14
|
+
title: string;
|
|
15
|
+
content?: string;
|
|
16
|
+
folderId: string | null;
|
|
17
|
+
createdAt: string;
|
|
18
|
+
updatedAt: string;
|
|
19
|
+
tags?: Tag[];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface DocumentDetail {
|
|
23
|
+
id: string;
|
|
24
|
+
ownerId: string;
|
|
25
|
+
folderId: string | null;
|
|
26
|
+
folderName?: string | null;
|
|
27
|
+
title: string;
|
|
28
|
+
content: string;
|
|
29
|
+
contentJson?: unknown;
|
|
30
|
+
createdAt: string;
|
|
31
|
+
updatedAt: string;
|
|
32
|
+
tags?: Tag[];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface SearchResultItem {
|
|
36
|
+
id: string;
|
|
37
|
+
title: string;
|
|
38
|
+
snippet: string;
|
|
39
|
+
score: number;
|
|
40
|
+
folder_id: string | null;
|
|
41
|
+
folder_name: string | null;
|
|
42
|
+
created_at: string;
|
|
43
|
+
updated_at: string;
|
|
44
|
+
tags?: Tag[];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface SearchResponse {
|
|
48
|
+
items: SearchResultItem[];
|
|
49
|
+
total: number;
|
|
50
|
+
page: number;
|
|
51
|
+
limit: number;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface ListDocumentsResponse {
|
|
55
|
+
items: DocumentSummary[];
|
|
56
|
+
total: number;
|
|
57
|
+
page: number;
|
|
58
|
+
limit: number;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface Folder {
|
|
62
|
+
id: string;
|
|
63
|
+
name: string;
|
|
64
|
+
parentId: string | null;
|
|
65
|
+
ownerId: string;
|
|
66
|
+
createdAt: string;
|
|
67
|
+
updatedAt: string;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface Version {
|
|
71
|
+
id: string;
|
|
72
|
+
documentId: string;
|
|
73
|
+
content: string;
|
|
74
|
+
contentJson?: unknown;
|
|
75
|
+
createdBy: string;
|
|
76
|
+
createdAt: string;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface ExportResponse {
|
|
80
|
+
markdown: string;
|
|
81
|
+
filename?: string;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface CreateDocumentInput {
|
|
85
|
+
title: string;
|
|
86
|
+
content?: string;
|
|
87
|
+
folderId?: string;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface UpdateDocumentInput {
|
|
91
|
+
title?: string;
|
|
92
|
+
content?: string;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export interface CreateSnapshotInput {
|
|
96
|
+
label: string;
|
|
97
|
+
description?: string;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export interface CreateFolderInput {
|
|
101
|
+
name: string;
|
|
102
|
+
parentId?: string;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export interface SearchInput {
|
|
106
|
+
query: string;
|
|
107
|
+
folder?: string;
|
|
108
|
+
tags?: string[];
|
|
109
|
+
limit?: number;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export interface ListDocumentsInput {
|
|
113
|
+
folderId?: string;
|
|
114
|
+
tag?: string;
|
|
115
|
+
page?: number;
|
|
116
|
+
limit?: number;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export interface ListFoldersInput {
|
|
120
|
+
parentId?: string;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export interface VersionHistoryInput {
|
|
124
|
+
documentId: string;
|
|
125
|
+
onlySnapshots?: boolean;
|
|
126
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* hiai-docs REST API client.
|
|
3
|
+
*
|
|
4
|
+
* Bun-native `fetch` wrapper. All authenticated requests send
|
|
5
|
+
* `Authorization: Bearer <apiKey>`. Non-OK responses throw
|
|
6
|
+
* `DocsApiError` carrying the HTTP status and parsed body. Transient
|
|
7
|
+
* failures (502 / 503 / 504 / timeout / network reset) are retried
|
|
8
|
+
* with exponential backoff up to `config.retries` attempts.
|
|
9
|
+
*/
|
|
10
|
+
import type { DocsApiKeyCreated, DocsApiKeyListResponse, DocsAttachment, DocsAttachmentConfirmInput, DocsAttachmentListResponse, DocsAttachmentPresignInput, DocsAttachmentPresignResponse, DocsCategory, DocsCategoryInput, DocsCategoryUpdate, DocsDocument, DocsDocumentCreateInput, DocsDocumentListResponse, DocsDocumentPipeline, DocsDocumentUpdateInput, DocsFolder, DocsFolderCreateInput, DocsFolderUpdateInput, DocsGraphEntitiesResponse, DocsGraphRelatedResponse, DocsGraphSearchResponse, DocsHealthResponse, DocsRequestContext, DocsSearchOptions, DocsSearchResponse, DocsSearchSuggestItem, DocsSharedContent, DocsShareLink, DocsShareListResponse, DocsShareRole, DocsTag, DocsVersion, DocsVersionDiff } from "./types.js";
|
|
11
|
+
export interface DocsClientConfig {
|
|
12
|
+
/** Base URL of the hiai-docs API, e.g. `http://localhost:50700`. */
|
|
13
|
+
baseUrl: string;
|
|
14
|
+
/** Bearer token used as `Authorization: Bearer <apiKey>`. */
|
|
15
|
+
apiKey?: string;
|
|
16
|
+
/** Default request-scoped credentials forwarded to every request. */
|
|
17
|
+
requestContext?: DocsRequestContext;
|
|
18
|
+
/** Injectable fetch implementation for hosts and contract tests. */
|
|
19
|
+
fetch?: typeof fetch;
|
|
20
|
+
/** Per-request timeout in milliseconds. Default: 10 000. */
|
|
21
|
+
timeout?: number;
|
|
22
|
+
/** Retry attempts for transient failures. Default: 3. */
|
|
23
|
+
retries?: number;
|
|
24
|
+
/** Initial backoff in milliseconds (doubles each attempt). Default: 250. */
|
|
25
|
+
retryBackoffMs?: number;
|
|
26
|
+
}
|
|
27
|
+
export declare class DocsApiError extends Error {
|
|
28
|
+
readonly status: number;
|
|
29
|
+
readonly body: unknown;
|
|
30
|
+
readonly url?: string;
|
|
31
|
+
readonly requestId?: string;
|
|
32
|
+
constructor(status: number, body: unknown, message?: string, metadata?: {
|
|
33
|
+
url?: string;
|
|
34
|
+
requestId?: string;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
export declare class DocsNetworkError extends Error {
|
|
38
|
+
readonly requestId?: string;
|
|
39
|
+
constructor(message: string, options?: {
|
|
40
|
+
cause?: unknown;
|
|
41
|
+
requestId?: string;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
export declare class DocsTimeoutError extends DocsNetworkError {
|
|
45
|
+
readonly timeout: number;
|
|
46
|
+
constructor(timeout: number, options?: {
|
|
47
|
+
cause?: unknown;
|
|
48
|
+
requestId?: string;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
export declare class DocsClient {
|
|
52
|
+
private readonly config;
|
|
53
|
+
constructor(config: DocsClientConfig);
|
|
54
|
+
/** Return a client with a merged request context for an incoming request. */
|
|
55
|
+
withRequestContext(context: DocsRequestContext): DocsClient;
|
|
56
|
+
createDoc(input: DocsDocumentCreateInput, context?: DocsRequestContext): Promise<DocsDocument>;
|
|
57
|
+
getDoc(id: string, context?: DocsRequestContext): Promise<DocsDocument>;
|
|
58
|
+
/**
|
|
59
|
+
* Fetch a document as raw markdown via the public export endpoint.
|
|
60
|
+
* Returns just the markdown body as a string.
|
|
61
|
+
*/
|
|
62
|
+
getDocMarkdown(id: string, context?: DocsRequestContext): Promise<string>;
|
|
63
|
+
updateDoc(id: string, updates: DocsDocumentUpdateInput, context?: DocsRequestContext): Promise<DocsDocument>;
|
|
64
|
+
deleteDoc(id: string, context?: DocsRequestContext): Promise<void>;
|
|
65
|
+
listDocs(options?: {
|
|
66
|
+
folderId?: string;
|
|
67
|
+
tag?: string;
|
|
68
|
+
page?: number;
|
|
69
|
+
limit?: number;
|
|
70
|
+
}, context?: DocsRequestContext): Promise<DocsDocumentListResponse>;
|
|
71
|
+
duplicateDoc(id: string, context?: DocsRequestContext): Promise<DocsDocument>;
|
|
72
|
+
getDocumentPipeline(id: string, context?: DocsRequestContext): Promise<DocsDocumentPipeline>;
|
|
73
|
+
publishDoc(id: string, context?: DocsRequestContext): Promise<DocsDocument>;
|
|
74
|
+
unpublishDoc(id: string, context?: DocsRequestContext): Promise<DocsDocument>;
|
|
75
|
+
/**
|
|
76
|
+
* Convenience alias for `getDocMarkdown` — both go through the same
|
|
77
|
+
* `/api/documents/:id/export` endpoint on the backend.
|
|
78
|
+
*/
|
|
79
|
+
exportDoc(id: string, context?: DocsRequestContext): Promise<string>;
|
|
80
|
+
/**
|
|
81
|
+
* Import a document from raw content. Posts JSON to
|
|
82
|
+
* `POST /api/documents/import`.
|
|
83
|
+
*/
|
|
84
|
+
importDoc(input: {
|
|
85
|
+
title?: string;
|
|
86
|
+
content: string;
|
|
87
|
+
folderId?: string;
|
|
88
|
+
}, context?: DocsRequestContext): Promise<DocsDocument>;
|
|
89
|
+
listFolders(parentId?: string, context?: DocsRequestContext): Promise<DocsFolder[]>;
|
|
90
|
+
getFolder(id: string, context?: DocsRequestContext): Promise<DocsFolder>;
|
|
91
|
+
createFolder(input: DocsFolderCreateInput, context?: DocsRequestContext): Promise<DocsFolder>;
|
|
92
|
+
updateFolder(id: string, updates: DocsFolderUpdateInput, context?: DocsRequestContext): Promise<DocsFolder>;
|
|
93
|
+
deleteFolder(id: string, context?: DocsRequestContext): Promise<void>;
|
|
94
|
+
listTags(context?: DocsRequestContext): Promise<DocsTag[]>;
|
|
95
|
+
createTag(input: {
|
|
96
|
+
name: string;
|
|
97
|
+
color?: string;
|
|
98
|
+
}, context?: DocsRequestContext): Promise<DocsTag>;
|
|
99
|
+
updateTag(id: string, updates: {
|
|
100
|
+
name?: string;
|
|
101
|
+
color?: string;
|
|
102
|
+
}, context?: DocsRequestContext): Promise<DocsTag>;
|
|
103
|
+
deleteTag(id: string, context?: DocsRequestContext): Promise<void>;
|
|
104
|
+
addTagToDoc(documentId: string, tagId: string, context?: DocsRequestContext): Promise<void>;
|
|
105
|
+
removeTagFromDoc(documentId: string, tagId: string, context?: DocsRequestContext): Promise<void>;
|
|
106
|
+
listCategories(context?: DocsRequestContext): Promise<DocsCategory[]>;
|
|
107
|
+
createCategory(input: DocsCategoryInput, context?: DocsRequestContext): Promise<DocsCategory>;
|
|
108
|
+
updateCategory(id: string, updates: DocsCategoryUpdate, context?: DocsRequestContext): Promise<DocsCategory>;
|
|
109
|
+
deleteCategory(id: string, context?: DocsRequestContext): Promise<void>;
|
|
110
|
+
createGlobalApiKey(name?: string, context?: DocsRequestContext): Promise<DocsApiKeyCreated>;
|
|
111
|
+
createCategoryApiKey(categoryId: string, name?: string, context?: DocsRequestContext): Promise<DocsApiKeyCreated>;
|
|
112
|
+
listApiKeys(context?: DocsRequestContext): Promise<DocsApiKeyListResponse>;
|
|
113
|
+
revealCategoryApiKey(id: string, context?: DocsRequestContext): Promise<{
|
|
114
|
+
key: string;
|
|
115
|
+
}>;
|
|
116
|
+
revokeApiKey(id: string, context?: DocsRequestContext): Promise<{
|
|
117
|
+
success: true;
|
|
118
|
+
}>;
|
|
119
|
+
search(query: string, options?: DocsSearchOptions, context?: DocsRequestContext): Promise<DocsSearchResponse>;
|
|
120
|
+
suggest(query: string, context?: DocsRequestContext): Promise<DocsSearchSuggestItem[]>;
|
|
121
|
+
/** Return entities linked to a document through the AGE graph. */
|
|
122
|
+
getGraphEntities(docId: string, context?: DocsRequestContext): Promise<DocsGraphEntitiesResponse>;
|
|
123
|
+
listGraphEntities(docId: string, context?: DocsRequestContext): Promise<DocsGraphEntitiesResponse>;
|
|
124
|
+
/** Return graph-related documents and their relation metadata. */
|
|
125
|
+
getRelatedDocuments(docId: string, context?: DocsRequestContext): Promise<DocsGraphRelatedResponse>;
|
|
126
|
+
listRelatedDocuments(docId: string, context?: DocsRequestContext): Promise<DocsGraphRelatedResponse>;
|
|
127
|
+
/** Bulk graph lookup for agent and product integrations. */
|
|
128
|
+
graphSearch(input: {
|
|
129
|
+
query?: string;
|
|
130
|
+
docIds: string[];
|
|
131
|
+
maxResults?: number;
|
|
132
|
+
}, context?: DocsRequestContext): Promise<DocsGraphSearchResponse>;
|
|
133
|
+
/** Compatibility alias for callers that prefer verb-first naming. */
|
|
134
|
+
searchGraph(input: {
|
|
135
|
+
query?: string;
|
|
136
|
+
docIds: string[];
|
|
137
|
+
maxResults?: number;
|
|
138
|
+
}, context?: DocsRequestContext): Promise<DocsGraphSearchResponse>;
|
|
139
|
+
createShare(input: {
|
|
140
|
+
documentId?: string;
|
|
141
|
+
folderId?: string;
|
|
142
|
+
password?: string;
|
|
143
|
+
expiresIn?: "1h" | "1d" | "7d" | "30d" | "never";
|
|
144
|
+
role?: DocsShareRole;
|
|
145
|
+
}, context?: DocsRequestContext): Promise<DocsShareLink>;
|
|
146
|
+
listShares(context?: DocsRequestContext): Promise<DocsShareListResponse>;
|
|
147
|
+
deleteShare(id: string, context?: DocsRequestContext): Promise<void>;
|
|
148
|
+
updateShare(id: string, updates: {
|
|
149
|
+
role?: DocsShareRole;
|
|
150
|
+
expiresIn?: "1h" | "1d" | "7d" | "30d" | "never";
|
|
151
|
+
}, context?: DocsRequestContext): Promise<DocsShareLink>;
|
|
152
|
+
/**
|
|
153
|
+
* Public endpoint — still sends `Authorization` if configured, but
|
|
154
|
+
* the backend does not require it.
|
|
155
|
+
*/
|
|
156
|
+
getShareByToken(token: string, context?: DocsRequestContext): Promise<DocsSharedContent>;
|
|
157
|
+
uploadAttachment(documentId: string, file: Blob | ArrayBuffer | Uint8Array, filename: string, mimeType: string, context?: DocsRequestContext): Promise<DocsAttachment>;
|
|
158
|
+
presignAttachment(documentId: string, input: DocsAttachmentPresignInput, context?: DocsRequestContext): Promise<DocsAttachmentPresignResponse>;
|
|
159
|
+
confirmAttachment(documentId: string, input: DocsAttachmentConfirmInput, context?: DocsRequestContext): Promise<DocsAttachment>;
|
|
160
|
+
listAttachments(documentId: string, context?: DocsRequestContext): Promise<DocsAttachmentListResponse>;
|
|
161
|
+
deleteAttachment(id: string, context?: DocsRequestContext): Promise<void>;
|
|
162
|
+
listVersions(documentId: string, options?: {
|
|
163
|
+
onlySnapshots?: boolean;
|
|
164
|
+
limit?: number;
|
|
165
|
+
}, context?: DocsRequestContext): Promise<DocsVersion[]>;
|
|
166
|
+
getVersion(documentId: string, versionId: string, context?: DocsRequestContext): Promise<DocsVersion>;
|
|
167
|
+
createSnapshot(documentId: string, input: {
|
|
168
|
+
label: string;
|
|
169
|
+
description?: string;
|
|
170
|
+
}, context?: DocsRequestContext): Promise<DocsVersion>;
|
|
171
|
+
restoreVersion(documentId: string, versionId: string, context?: DocsRequestContext): Promise<DocsDocument>;
|
|
172
|
+
diffVersions(documentId: string, from: string, to: string, context?: DocsRequestContext): Promise<DocsVersionDiff>;
|
|
173
|
+
health(context?: DocsRequestContext): Promise<DocsHealthResponse>;
|
|
174
|
+
private request;
|
|
175
|
+
private fetchRaw;
|
|
176
|
+
private buildUrl;
|
|
177
|
+
private cleanQuery;
|
|
178
|
+
private shouldRetryStatus;
|
|
179
|
+
private isRetryableError;
|
|
180
|
+
private backoffDelay;
|
|
181
|
+
private sleep;
|
|
182
|
+
private toApiError;
|
|
183
|
+
private wrapNetworkError;
|
|
184
|
+
private isTimeoutError;
|
|
185
|
+
private mergeContext;
|
|
186
|
+
private toBlob;
|
|
187
|
+
}
|