@nodetool-ai/deploy 0.7.0-rc.23 → 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -0
- package/dist/.nodetool-build-stamp +1 -0
- package/dist/admin-client.d.ts +5 -39
- package/dist/admin-client.d.ts.map +1 -1
- package/dist/admin-client.js +9 -230
- package/dist/admin-client.js.map +1 -1
- package/dist/api-user-manager.d.ts.map +1 -1
- package/dist/api-user-manager.js +5 -2
- package/dist/api-user-manager.js.map +1 -1
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +0 -3
- package/dist/auth.js.map +1 -1
- package/dist/compose.d.ts.map +1 -1
- package/dist/compose.js +5 -6
- package/dist/compose.js.map +1 -1
- package/dist/configure.d.ts +1 -43
- package/dist/configure.d.ts.map +1 -1
- package/dist/configure.js +2 -43
- package/dist/configure.js.map +1 -1
- package/dist/deployment-config.d.ts +28 -786
- package/dist/deployment-config.d.ts.map +1 -1
- package/dist/deployment-config.js +34 -218
- package/dist/deployment-config.js.map +1 -1
- package/dist/docker-run.d.ts +2 -1
- package/dist/docker-run.d.ts.map +1 -1
- package/dist/docker-run.js +6 -22
- package/dist/docker-run.js.map +1 -1
- package/dist/docker.d.ts +6 -21
- package/dist/docker.d.ts.map +1 -1
- package/dist/docker.js +6 -53
- package/dist/docker.js.map +1 -1
- package/dist/image-spec.d.ts +1 -1
- package/dist/index.d.ts +0 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -17
- package/dist/index.js.map +1 -1
- package/dist/manager.d.ts.map +1 -1
- package/dist/manager.js +0 -44
- package/dist/manager.js.map +1 -1
- package/dist/progress.d.ts.map +1 -1
- package/dist/progress.js +0 -1
- package/dist/progress.js.map +1 -1
- package/dist/remote-users.d.ts.map +1 -1
- package/dist/remote-users.js +1 -4
- package/dist/remote-users.js.map +1 -1
- package/dist/runpod-rest.d.ts +114 -0
- package/dist/runpod-rest.d.ts.map +1 -0
- package/dist/runpod-rest.js +150 -0
- package/dist/runpod-rest.js.map +1 -0
- package/dist/self-hosted.d.ts +17 -43
- package/dist/self-hosted.d.ts.map +1 -1
- package/dist/self-hosted.js +50 -124
- package/dist/self-hosted.js.map +1 -1
- package/dist/ssh.d.ts +9 -0
- package/dist/ssh.d.ts.map +1 -1
- package/dist/ssh.js +1 -5
- package/dist/ssh.js.map +1 -1
- package/dist/state.d.ts.map +1 -1
- package/dist/state.js +1 -11
- package/dist/state.js.map +1 -1
- package/dist/workflow-syncer.d.ts +3 -32
- package/dist/workflow-syncer.d.ts.map +1 -1
- package/dist/workflow-syncer.js +3 -162
- package/dist/workflow-syncer.js.map +1 -1
- package/package.json +29 -14
- package/dist/admin-operations.d.ts +0 -197
- package/dist/admin-operations.d.ts.map +0 -1
- package/dist/admin-operations.js +0 -433
- package/dist/admin-operations.js.map +0 -1
- package/dist/admin-routes.d.ts +0 -306
- package/dist/admin-routes.d.ts.map +0 -1
- package/dist/admin-routes.js +0 -383
- package/dist/admin-routes.js.map +0 -1
- package/dist/collection-routes.d.ts +0 -37
- package/dist/collection-routes.d.ts.map +0 -1
- package/dist/collection-routes.js +0 -43
- package/dist/collection-routes.js.map +0 -1
- package/dist/deploy-to-gcp.d.ts +0 -67
- package/dist/deploy-to-gcp.d.ts.map +0 -1
- package/dist/deploy-to-gcp.js +0 -268
- package/dist/deploy-to-gcp.js.map +0 -1
- package/dist/deploy-to-runpod.d.ts +0 -53
- package/dist/deploy-to-runpod.d.ts.map +0 -1
- package/dist/deploy-to-runpod.js +0 -207
- package/dist/deploy-to-runpod.js.map +0 -1
- package/dist/fly.d.ts +0 -40
- package/dist/fly.d.ts.map +0 -1
- package/dist/fly.js +0 -291
- package/dist/fly.js.map +0 -1
- package/dist/gcp.d.ts +0 -59
- package/dist/gcp.d.ts.map +0 -1
- package/dist/gcp.js +0 -339
- package/dist/gcp.js.map +0 -1
- package/dist/google-cloud-run-api.d.ts +0 -134
- package/dist/google-cloud-run-api.d.ts.map +0 -1
- package/dist/google-cloud-run-api.js +0 -532
- package/dist/google-cloud-run-api.js.map +0 -1
- package/dist/huggingface.d.ts +0 -69
- package/dist/huggingface.d.ts.map +0 -1
- package/dist/huggingface.js +0 -346
- package/dist/huggingface.js.map +0 -1
- package/dist/railway.d.ts +0 -65
- package/dist/railway.d.ts.map +0 -1
- package/dist/railway.js +0 -284
- package/dist/railway.js.map +0 -1
- package/dist/runpod-api.d.ts +0 -206
- package/dist/runpod-api.d.ts.map +0 -1
- package/dist/runpod-api.js +0 -703
- package/dist/runpod-api.js.map +0 -1
- package/dist/runpod.d.ts +0 -82
- package/dist/runpod.d.ts.map +0 -1
- package/dist/runpod.js +0 -188
- package/dist/runpod.js.map +0 -1
- package/dist/storage-routes.d.ts +0 -55
- package/dist/storage-routes.d.ts.map +0 -1
- package/dist/storage-routes.js +0 -160
- package/dist/storage-routes.js.map +0 -1
- package/dist/sync.d.ts +0 -38
- package/dist/sync.d.ts.map +0 -1
- package/dist/sync.js +0 -130
- package/dist/sync.js.map +0 -1
package/dist/admin-routes.d.ts
DELETED
|
@@ -1,306 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Admin route handler functions for the NodeTool server.
|
|
3
|
-
*
|
|
4
|
-
* This module exports pure handler functions with typed params and return
|
|
5
|
-
* values that can be wired to any HTTP framework (Express, Fastify, Hono,
|
|
6
|
-
* raw Node http, etc.). No framework-specific imports.
|
|
7
|
-
*
|
|
8
|
-
* Endpoints covered:
|
|
9
|
-
* - HuggingFace model download (SSE)
|
|
10
|
-
* - Ollama model download (SSE)
|
|
11
|
-
* - Cache scan and size
|
|
12
|
-
* - Delete HF model
|
|
13
|
-
* - Database CRUD via adapter
|
|
14
|
-
* - Collection management
|
|
15
|
-
* - Asset management
|
|
16
|
-
*/
|
|
17
|
-
import { type HFHubAdapter, type OllamaAdapter } from "./admin-operations.js";
|
|
18
|
-
/** Thrown by handlers to signal an HTTP error to the framework adapter. */
|
|
19
|
-
export declare class HttpError extends Error {
|
|
20
|
-
readonly statusCode: number;
|
|
21
|
-
constructor(statusCode: number, message: string);
|
|
22
|
-
}
|
|
23
|
-
export interface CollectionCreateRequest {
|
|
24
|
-
name: string;
|
|
25
|
-
embedding_model: string;
|
|
26
|
-
}
|
|
27
|
-
export interface CollectionResponse {
|
|
28
|
-
name: string;
|
|
29
|
-
count: number;
|
|
30
|
-
metadata: Record<string, unknown> | null;
|
|
31
|
-
workflow_name?: string | null;
|
|
32
|
-
}
|
|
33
|
-
export interface CollectionListResponse {
|
|
34
|
-
collections: CollectionResponse[];
|
|
35
|
-
count: number;
|
|
36
|
-
}
|
|
37
|
-
export interface CollectionModifyRequest {
|
|
38
|
-
name?: string;
|
|
39
|
-
metadata?: Record<string, string>;
|
|
40
|
-
}
|
|
41
|
-
export interface AddToCollectionRequest {
|
|
42
|
-
documents: string[];
|
|
43
|
-
ids: string[];
|
|
44
|
-
metadatas: Record<string, string>[];
|
|
45
|
-
embeddings: number[][];
|
|
46
|
-
}
|
|
47
|
-
export interface AssetResponse {
|
|
48
|
-
id: string;
|
|
49
|
-
user_id: string;
|
|
50
|
-
workflow_id?: string | null;
|
|
51
|
-
parent_id?: string | null;
|
|
52
|
-
name: string;
|
|
53
|
-
content_type: string;
|
|
54
|
-
size?: number | null;
|
|
55
|
-
metadata?: Record<string, unknown>;
|
|
56
|
-
created_at: string;
|
|
57
|
-
get_url?: string | null;
|
|
58
|
-
thumb_url?: string | null;
|
|
59
|
-
duration?: number | null;
|
|
60
|
-
}
|
|
61
|
-
export interface AssetListResponse {
|
|
62
|
-
next: string | null;
|
|
63
|
-
assets: AssetResponse[];
|
|
64
|
-
}
|
|
65
|
-
export interface CreateAssetRequest {
|
|
66
|
-
id?: string;
|
|
67
|
-
user_id?: string;
|
|
68
|
-
name?: string;
|
|
69
|
-
content_type?: string;
|
|
70
|
-
parent_id?: string;
|
|
71
|
-
workflow_id?: string;
|
|
72
|
-
metadata?: Record<string, unknown>;
|
|
73
|
-
}
|
|
74
|
-
export interface DbSaveRequest {
|
|
75
|
-
table: string;
|
|
76
|
-
item: Record<string, unknown>;
|
|
77
|
-
}
|
|
78
|
-
export interface HFDownloadRequest {
|
|
79
|
-
repo_id: string;
|
|
80
|
-
cache_dir?: string;
|
|
81
|
-
file_path?: string;
|
|
82
|
-
ignore_patterns?: string[];
|
|
83
|
-
allow_patterns?: string[];
|
|
84
|
-
stream?: boolean;
|
|
85
|
-
}
|
|
86
|
-
export interface OllamaDownloadRequest {
|
|
87
|
-
model_name: string;
|
|
88
|
-
stream?: boolean;
|
|
89
|
-
}
|
|
90
|
-
export interface IndexResponse {
|
|
91
|
-
path: string;
|
|
92
|
-
error?: string | null;
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Encode an async generator of objects into an SSE text stream.
|
|
96
|
-
* Each yielded value becomes a `data: <json>\n\n` line, terminated
|
|
97
|
-
* with `data: [DONE]\n\n`.
|
|
98
|
-
*/
|
|
99
|
-
export declare function encodeSSE(source: AsyncGenerator<Record<string, unknown>>): AsyncGenerator<string>;
|
|
100
|
-
/** Standard SSE response headers. */
|
|
101
|
-
export declare const SSE_HEADERS: Record<string, string>;
|
|
102
|
-
/**
|
|
103
|
-
* Database adapter interface matching the Python DatabaseAdapter pattern.
|
|
104
|
-
*/
|
|
105
|
-
export interface DatabaseAdapter {
|
|
106
|
-
get(key: string): Promise<Record<string, unknown> | null>;
|
|
107
|
-
save(item: Record<string, unknown>): Promise<void>;
|
|
108
|
-
delete(key: string): Promise<void>;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Resolves a DatabaseAdapter for the given table name.
|
|
112
|
-
*/
|
|
113
|
-
export type DatabaseAdapterFactory = (table: string) => Promise<DatabaseAdapter>;
|
|
114
|
-
/**
|
|
115
|
-
* Chroma-like collection interface.
|
|
116
|
-
*/
|
|
117
|
-
export interface CollectionHandle {
|
|
118
|
-
name: string;
|
|
119
|
-
metadata: Record<string, unknown> | null;
|
|
120
|
-
count(): Promise<number>;
|
|
121
|
-
modify(opts: {
|
|
122
|
-
name?: string;
|
|
123
|
-
metadata?: Record<string, unknown>;
|
|
124
|
-
}): Promise<void>;
|
|
125
|
-
add(opts: {
|
|
126
|
-
documents: string[];
|
|
127
|
-
ids: string[];
|
|
128
|
-
metadatas: Record<string, string>[];
|
|
129
|
-
embeddings: number[][];
|
|
130
|
-
}): Promise<void>;
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Vector store client interface.
|
|
134
|
-
*/
|
|
135
|
-
export interface VecStoreClient {
|
|
136
|
-
createCollection(opts: {
|
|
137
|
-
name: string;
|
|
138
|
-
metadata: Record<string, unknown>;
|
|
139
|
-
}): Promise<CollectionHandle>;
|
|
140
|
-
listCollections(): Promise<CollectionHandle[]>;
|
|
141
|
-
getCollection(opts: {
|
|
142
|
-
name: string;
|
|
143
|
-
}): Promise<CollectionHandle>;
|
|
144
|
-
deleteCollection(opts: {
|
|
145
|
-
name: string;
|
|
146
|
-
}): Promise<void>;
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Asset storage interface.
|
|
150
|
-
*/
|
|
151
|
-
export interface AssetStorage {
|
|
152
|
-
getUrl(fileName: string): Promise<string | null>;
|
|
153
|
-
delete(fileName: string): Promise<void>;
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Asset model interface (mirrors Python AssetModel).
|
|
157
|
-
*/
|
|
158
|
-
export interface AssetRecord {
|
|
159
|
-
id: string;
|
|
160
|
-
user_id: string;
|
|
161
|
-
workflow_id?: string | null;
|
|
162
|
-
parent_id?: string | null;
|
|
163
|
-
name: string;
|
|
164
|
-
content_type: string;
|
|
165
|
-
size?: number | null;
|
|
166
|
-
metadata?: Record<string, unknown>;
|
|
167
|
-
created_at: string;
|
|
168
|
-
file_name: string;
|
|
169
|
-
thumb_file_name: string;
|
|
170
|
-
has_thumbnail: boolean;
|
|
171
|
-
duration?: number | null;
|
|
172
|
-
delete(): Promise<void>;
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Asset model static operations.
|
|
176
|
-
*/
|
|
177
|
-
export interface AssetModel {
|
|
178
|
-
get(id: string): Promise<AssetRecord | null>;
|
|
179
|
-
find(userId: string, id: string): Promise<AssetRecord | null>;
|
|
180
|
-
create(data: CreateAssetRequest & {
|
|
181
|
-
user_id: string;
|
|
182
|
-
}): Promise<AssetRecord>;
|
|
183
|
-
paginate(opts: {
|
|
184
|
-
user_id: string;
|
|
185
|
-
parent_id?: string | null;
|
|
186
|
-
content_type?: string | null;
|
|
187
|
-
limit: number;
|
|
188
|
-
start_key?: string | null;
|
|
189
|
-
}): Promise<[AssetRecord[], string | null]>;
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Workflow model for looking up names.
|
|
193
|
-
*/
|
|
194
|
-
export interface WorkflowModel {
|
|
195
|
-
get(id: string): Promise<{
|
|
196
|
-
name: string;
|
|
197
|
-
} | null>;
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
* All injectable dependencies for the admin route handlers.
|
|
201
|
-
*/
|
|
202
|
-
export interface AdminDeps {
|
|
203
|
-
hub: HFHubAdapter;
|
|
204
|
-
ollama?: OllamaAdapter;
|
|
205
|
-
getDbAdapter: DatabaseAdapterFactory;
|
|
206
|
-
vecStore: VecStoreClient;
|
|
207
|
-
assetModel: AssetModel;
|
|
208
|
-
assetStorage: AssetStorage;
|
|
209
|
-
workflowModel: WorkflowModel;
|
|
210
|
-
getSecret?: (key: string, userId: string) => Promise<string | null>;
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* POST /admin/models/huggingface/download
|
|
214
|
-
*
|
|
215
|
-
* Returns an async generator of SSE strings.
|
|
216
|
-
*/
|
|
217
|
-
export declare function handleDownloadHuggingfaceModel(deps: AdminDeps, data: HFDownloadRequest): AsyncGenerator<string>;
|
|
218
|
-
/**
|
|
219
|
-
* POST /admin/models/ollama/download
|
|
220
|
-
*
|
|
221
|
-
* Returns an async generator of SSE strings.
|
|
222
|
-
*/
|
|
223
|
-
export declare function handleDownloadOllamaModel(deps: AdminDeps, data: OllamaDownloadRequest): AsyncGenerator<string>;
|
|
224
|
-
/**
|
|
225
|
-
* GET /admin/cache/scan
|
|
226
|
-
*/
|
|
227
|
-
export declare function handleScanCache(deps: AdminDeps): Promise<Record<string, unknown>>;
|
|
228
|
-
/**
|
|
229
|
-
* GET /admin/cache/size
|
|
230
|
-
*/
|
|
231
|
-
export declare function handleGetCacheSize(cacheDir?: string): Promise<Record<string, unknown>>;
|
|
232
|
-
/**
|
|
233
|
-
* DELETE /admin/models/huggingface/:repoId
|
|
234
|
-
*/
|
|
235
|
-
export declare function handleDeleteHuggingfaceModel(deps: AdminDeps, repoId: string): Promise<Record<string, unknown>>;
|
|
236
|
-
/**
|
|
237
|
-
* POST /admin/db/:table/save
|
|
238
|
-
*/
|
|
239
|
-
export declare function handleDbSave(deps: AdminDeps, table: string, item: Record<string, unknown>): Promise<{
|
|
240
|
-
status: string;
|
|
241
|
-
}>;
|
|
242
|
-
/**
|
|
243
|
-
* GET /admin/db/:table/:key
|
|
244
|
-
*/
|
|
245
|
-
export declare function handleDbGet(deps: AdminDeps, table: string, key: string): Promise<Record<string, unknown>>;
|
|
246
|
-
/**
|
|
247
|
-
* DELETE /admin/db/:table/:key
|
|
248
|
-
*/
|
|
249
|
-
export declare function handleDbDelete(deps: AdminDeps, table: string, key: string): Promise<{
|
|
250
|
-
status: string;
|
|
251
|
-
}>;
|
|
252
|
-
/**
|
|
253
|
-
* POST /admin/collections
|
|
254
|
-
*/
|
|
255
|
-
export declare function handleCreateCollection(deps: AdminDeps, req: CollectionCreateRequest): Promise<CollectionResponse>;
|
|
256
|
-
/**
|
|
257
|
-
* GET /admin/collections
|
|
258
|
-
*/
|
|
259
|
-
export declare function handleListCollections(deps: AdminDeps): Promise<CollectionListResponse>;
|
|
260
|
-
/**
|
|
261
|
-
* GET /admin/collections/:name
|
|
262
|
-
*/
|
|
263
|
-
export declare function handleGetCollection(deps: AdminDeps, name: string): Promise<CollectionResponse>;
|
|
264
|
-
/**
|
|
265
|
-
* PUT /admin/collections/:name
|
|
266
|
-
*/
|
|
267
|
-
export declare function handleUpdateCollection(deps: AdminDeps, name: string, req: CollectionModifyRequest): Promise<CollectionResponse>;
|
|
268
|
-
/**
|
|
269
|
-
* DELETE /admin/collections/:name
|
|
270
|
-
*/
|
|
271
|
-
export declare function handleDeleteCollection(deps: AdminDeps, name: string): Promise<{
|
|
272
|
-
message: string;
|
|
273
|
-
}>;
|
|
274
|
-
/**
|
|
275
|
-
* POST /admin/collections/:name/add
|
|
276
|
-
*/
|
|
277
|
-
export declare function handleAddToCollection(deps: AdminDeps, name: string, req: AddToCollectionRequest): Promise<{
|
|
278
|
-
message: string;
|
|
279
|
-
}>;
|
|
280
|
-
/**
|
|
281
|
-
* GET /admin/assets
|
|
282
|
-
*/
|
|
283
|
-
export declare function handleListAssets(deps: AdminDeps, opts: {
|
|
284
|
-
userId?: string;
|
|
285
|
-
parentId?: string | null;
|
|
286
|
-
contentType?: string | null;
|
|
287
|
-
cursor?: string | null;
|
|
288
|
-
pageSize?: number;
|
|
289
|
-
}): Promise<AssetListResponse>;
|
|
290
|
-
/**
|
|
291
|
-
* POST /admin/assets
|
|
292
|
-
*/
|
|
293
|
-
export declare function handleCreateAsset(deps: AdminDeps, data: CreateAssetRequest, currentUser?: string): Promise<AssetResponse>;
|
|
294
|
-
/**
|
|
295
|
-
* GET /admin/assets/:assetId
|
|
296
|
-
*/
|
|
297
|
-
export declare function handleGetAsset(deps: AdminDeps, assetId: string, userId?: string): Promise<AssetResponse>;
|
|
298
|
-
/**
|
|
299
|
-
* DELETE /admin/assets/:assetId
|
|
300
|
-
*
|
|
301
|
-
* Recursively deletes folders.
|
|
302
|
-
*/
|
|
303
|
-
export declare function handleDeleteAsset(deps: AdminDeps, assetId: string, currentUser: string): Promise<{
|
|
304
|
-
deleted_asset_ids: string[];
|
|
305
|
-
}>;
|
|
306
|
-
//# sourceMappingURL=admin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AC;IAC5B,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,GACA,OAAO,CAAC,iBAAiB,CAAC,CAuB5B;AAED;;GAEG;AACH,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,SAAS,EACf,IAAI,EAAE,kBAAkB,EACxB,WAAW,GAAE,MAAY,GACxB,OAAO,CAAC,aAAa,CAAC,CAUxB;AAED;;GAEG;AACH,wBAAsB,cAAc,CAClC,IAAI,EAAE,SAAS,EACf,OAAO,EAAE,MAAM,EACf,MAAM,GAAE,MAAY,GACnB,OAAO,CAAC,aAAa,CAAC,CAsBxB;AAED;;;;GAIG;AACH,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,SAAS,EACf,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC;IAAE,iBAAiB,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC,CA+D1C"}
|
package/dist/admin-routes.js
DELETED
|
@@ -1,383 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Admin route handler functions for the NodeTool server.
|
|
3
|
-
*
|
|
4
|
-
* This module exports pure handler functions with typed params and return
|
|
5
|
-
* values that can be wired to any HTTP framework (Express, Fastify, Hono,
|
|
6
|
-
* raw Node http, etc.). No framework-specific imports.
|
|
7
|
-
*
|
|
8
|
-
* Endpoints covered:
|
|
9
|
-
* - HuggingFace model download (SSE)
|
|
10
|
-
* - Ollama model download (SSE)
|
|
11
|
-
* - Cache scan and size
|
|
12
|
-
* - Delete HF model
|
|
13
|
-
* - Database CRUD via adapter
|
|
14
|
-
* - Collection management
|
|
15
|
-
* - Asset management
|
|
16
|
-
*/
|
|
17
|
-
import { downloadHFModel, downloadOllamaModel, scanHFCache, calculateCacheSize, deleteHFModel } from "./admin-operations.js";
|
|
18
|
-
// ── Shared types ───────────────────────────────────────────
|
|
19
|
-
/** Thrown by handlers to signal an HTTP error to the framework adapter. */
|
|
20
|
-
export class HttpError extends Error {
|
|
21
|
-
statusCode;
|
|
22
|
-
constructor(statusCode, message) {
|
|
23
|
-
super(message);
|
|
24
|
-
this.statusCode = statusCode;
|
|
25
|
-
this.name = "HttpError";
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
// ── SSE helper ─────────────────────────────────────────────
|
|
29
|
-
/**
|
|
30
|
-
* Encode an async generator of objects into an SSE text stream.
|
|
31
|
-
* Each yielded value becomes a `data: <json>\n\n` line, terminated
|
|
32
|
-
* with `data: [DONE]\n\n`.
|
|
33
|
-
*/
|
|
34
|
-
export async function* encodeSSE(source) {
|
|
35
|
-
try {
|
|
36
|
-
for await (const chunk of source) {
|
|
37
|
-
yield `data: ${JSON.stringify(chunk)}\n\n`;
|
|
38
|
-
}
|
|
39
|
-
yield "data: [DONE]\n\n";
|
|
40
|
-
}
|
|
41
|
-
catch (err) {
|
|
42
|
-
const errorData = { status: "error", error: String(err) };
|
|
43
|
-
yield `data: ${JSON.stringify(errorData)}\n\n`;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
/** Standard SSE response headers. */
|
|
47
|
-
export const SSE_HEADERS = {
|
|
48
|
-
"Content-Type": "text/event-stream",
|
|
49
|
-
"Cache-Control": "no-cache",
|
|
50
|
-
Connection: "keep-alive",
|
|
51
|
-
"Access-Control-Allow-Origin": "*",
|
|
52
|
-
"Access-Control-Allow-Headers": "Authorization, Content-Type",
|
|
53
|
-
"Access-Control-Allow-Methods": "POST, OPTIONS"
|
|
54
|
-
};
|
|
55
|
-
// ── Helper: AssetRecord → AssetResponse ────────────────────
|
|
56
|
-
async function assetFromRecord(asset, storage) {
|
|
57
|
-
const getUrl = asset.content_type !== "folder"
|
|
58
|
-
? await storage.getUrl(asset.file_name)
|
|
59
|
-
: null;
|
|
60
|
-
const thumbUrl = asset.has_thumbnail
|
|
61
|
-
? await storage.getUrl(asset.thumb_file_name)
|
|
62
|
-
: null;
|
|
63
|
-
return {
|
|
64
|
-
id: asset.id,
|
|
65
|
-
user_id: asset.user_id,
|
|
66
|
-
workflow_id: asset.workflow_id,
|
|
67
|
-
parent_id: asset.parent_id,
|
|
68
|
-
name: asset.name,
|
|
69
|
-
content_type: asset.content_type,
|
|
70
|
-
size: asset.size,
|
|
71
|
-
metadata: asset.metadata,
|
|
72
|
-
created_at: asset.created_at,
|
|
73
|
-
get_url: getUrl,
|
|
74
|
-
thumb_url: thumbUrl,
|
|
75
|
-
duration: asset.duration
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
// ── Route handlers ─────────────────────────────────────────
|
|
79
|
-
// -- Model downloads (SSE) --
|
|
80
|
-
/**
|
|
81
|
-
* POST /admin/models/huggingface/download
|
|
82
|
-
*
|
|
83
|
-
* Returns an async generator of SSE strings.
|
|
84
|
-
*/
|
|
85
|
-
export async function* handleDownloadHuggingfaceModel(deps, data) {
|
|
86
|
-
if (!data.repo_id) {
|
|
87
|
-
throw new HttpError(400, "repo_id is required");
|
|
88
|
-
}
|
|
89
|
-
const source = downloadHFModel(deps.hub, {
|
|
90
|
-
repoId: data.repo_id,
|
|
91
|
-
cacheDir: data.cache_dir,
|
|
92
|
-
filePath: data.file_path,
|
|
93
|
-
ignorePatterns: data.ignore_patterns,
|
|
94
|
-
allowPatterns: data.allow_patterns,
|
|
95
|
-
stream: data.stream ?? true,
|
|
96
|
-
getSecret: deps.getSecret
|
|
97
|
-
});
|
|
98
|
-
yield* encodeSSE(source);
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* POST /admin/models/ollama/download
|
|
102
|
-
*
|
|
103
|
-
* Returns an async generator of SSE strings.
|
|
104
|
-
*/
|
|
105
|
-
export async function* handleDownloadOllamaModel(deps, data) {
|
|
106
|
-
if (!data.model_name) {
|
|
107
|
-
throw new HttpError(400, "model_name is required");
|
|
108
|
-
}
|
|
109
|
-
if (!deps.ollama) {
|
|
110
|
-
throw new HttpError(500, "Ollama adapter not configured");
|
|
111
|
-
}
|
|
112
|
-
const source = downloadOllamaModel(deps.ollama, data.model_name, data.stream ?? true);
|
|
113
|
-
yield* encodeSSE(source);
|
|
114
|
-
}
|
|
115
|
-
// -- Cache --
|
|
116
|
-
/**
|
|
117
|
-
* GET /admin/cache/scan
|
|
118
|
-
*/
|
|
119
|
-
export async function handleScanCache(deps) {
|
|
120
|
-
const results = [];
|
|
121
|
-
for await (const chunk of scanHFCache(deps.hub)) {
|
|
122
|
-
results.push(chunk);
|
|
123
|
-
}
|
|
124
|
-
return results[0] ?? { status: "error", message: "No cache data" };
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* GET /admin/cache/size
|
|
128
|
-
*/
|
|
129
|
-
export async function handleGetCacheSize(cacheDir = "/app/.cache/huggingface/hub") {
|
|
130
|
-
const results = [];
|
|
131
|
-
for await (const chunk of calculateCacheSize(cacheDir)) {
|
|
132
|
-
results.push(chunk);
|
|
133
|
-
}
|
|
134
|
-
return results[0] ?? { status: "error", message: "No size data" };
|
|
135
|
-
}
|
|
136
|
-
// -- Delete model --
|
|
137
|
-
/**
|
|
138
|
-
* DELETE /admin/models/huggingface/:repoId
|
|
139
|
-
*/
|
|
140
|
-
export async function handleDeleteHuggingfaceModel(deps, repoId) {
|
|
141
|
-
const results = [];
|
|
142
|
-
for await (const chunk of deleteHFModel(deps.hub, repoId)) {
|
|
143
|
-
results.push(chunk);
|
|
144
|
-
}
|
|
145
|
-
return results[0] ?? { status: "error", message: "Delete failed" };
|
|
146
|
-
}
|
|
147
|
-
// -- Database adapter operations --
|
|
148
|
-
/**
|
|
149
|
-
* POST /admin/db/:table/save
|
|
150
|
-
*/
|
|
151
|
-
export async function handleDbSave(deps, table, item) {
|
|
152
|
-
const adapter = await deps.getDbAdapter(table);
|
|
153
|
-
await adapter.save(item);
|
|
154
|
-
return { status: "ok" };
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* GET /admin/db/:table/:key
|
|
158
|
-
*/
|
|
159
|
-
export async function handleDbGet(deps, table, key) {
|
|
160
|
-
const adapter = await deps.getDbAdapter(table);
|
|
161
|
-
const item = await adapter.get(key);
|
|
162
|
-
if (item === null) {
|
|
163
|
-
throw new HttpError(404, "Not found");
|
|
164
|
-
}
|
|
165
|
-
return item;
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* DELETE /admin/db/:table/:key
|
|
169
|
-
*/
|
|
170
|
-
export async function handleDbDelete(deps, table, key) {
|
|
171
|
-
const adapter = await deps.getDbAdapter(table);
|
|
172
|
-
await adapter.delete(key);
|
|
173
|
-
return { status: "ok" };
|
|
174
|
-
}
|
|
175
|
-
// -- Collection management --
|
|
176
|
-
/**
|
|
177
|
-
* POST /admin/collections
|
|
178
|
-
*/
|
|
179
|
-
export async function handleCreateCollection(deps, req) {
|
|
180
|
-
const metadata = { embedding_model: req.embedding_model };
|
|
181
|
-
const collection = await deps.vecStore.createCollection({
|
|
182
|
-
name: req.name,
|
|
183
|
-
metadata
|
|
184
|
-
});
|
|
185
|
-
return {
|
|
186
|
-
name: collection.name,
|
|
187
|
-
metadata: collection.metadata,
|
|
188
|
-
count: 0
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* GET /admin/collections
|
|
193
|
-
*/
|
|
194
|
-
export async function handleListCollections(deps) {
|
|
195
|
-
const collections = await deps.vecStore.listCollections();
|
|
196
|
-
const results = await Promise.all(collections.map(async (col) => {
|
|
197
|
-
const count = await col.count();
|
|
198
|
-
let workflowName = null;
|
|
199
|
-
const workflowId = col.metadata?.["workflow"];
|
|
200
|
-
if (typeof workflowId === "string") {
|
|
201
|
-
const wf = await deps.workflowModel.get(workflowId);
|
|
202
|
-
if (wf)
|
|
203
|
-
workflowName = wf.name;
|
|
204
|
-
}
|
|
205
|
-
return {
|
|
206
|
-
name: col.name,
|
|
207
|
-
metadata: col.metadata ?? {},
|
|
208
|
-
workflow_name: workflowName,
|
|
209
|
-
count
|
|
210
|
-
};
|
|
211
|
-
}));
|
|
212
|
-
return { collections: results, count: results.length };
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* GET /admin/collections/:name
|
|
216
|
-
*/
|
|
217
|
-
export async function handleGetCollection(deps, name) {
|
|
218
|
-
const collection = await deps.vecStore.getCollection({ name });
|
|
219
|
-
const count = await collection.count();
|
|
220
|
-
return {
|
|
221
|
-
name: collection.name,
|
|
222
|
-
metadata: collection.metadata,
|
|
223
|
-
count
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* PUT /admin/collections/:name
|
|
228
|
-
*/
|
|
229
|
-
export async function handleUpdateCollection(deps, name, req) {
|
|
230
|
-
const collection = await deps.vecStore.getCollection({ name });
|
|
231
|
-
const metadata = { ...(collection.metadata ?? {}), ...(req.metadata ?? {}) };
|
|
232
|
-
const newName = req.name ?? collection.name;
|
|
233
|
-
await collection.modify({ name: newName, metadata });
|
|
234
|
-
return {
|
|
235
|
-
name: collection.name,
|
|
236
|
-
metadata: collection.metadata,
|
|
237
|
-
count: await collection.count()
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
/**
|
|
241
|
-
* DELETE /admin/collections/:name
|
|
242
|
-
*/
|
|
243
|
-
export async function handleDeleteCollection(deps, name) {
|
|
244
|
-
await deps.vecStore.deleteCollection({ name });
|
|
245
|
-
return { message: `Collection ${name} deleted successfully` };
|
|
246
|
-
}
|
|
247
|
-
/**
|
|
248
|
-
* POST /admin/collections/:name/add
|
|
249
|
-
*/
|
|
250
|
-
export async function handleAddToCollection(deps, name, req) {
|
|
251
|
-
const collection = await deps.vecStore.getCollection({ name });
|
|
252
|
-
await collection.add({
|
|
253
|
-
documents: req.documents,
|
|
254
|
-
ids: req.ids,
|
|
255
|
-
metadatas: req.metadatas,
|
|
256
|
-
embeddings: req.embeddings
|
|
257
|
-
});
|
|
258
|
-
return { message: `Documents added to collection ${name} successfully` };
|
|
259
|
-
}
|
|
260
|
-
// -- Asset management --
|
|
261
|
-
/**
|
|
262
|
-
* GET /admin/assets
|
|
263
|
-
*/
|
|
264
|
-
export async function handleListAssets(deps, opts) {
|
|
265
|
-
const effectiveUser = opts.userId ?? "1";
|
|
266
|
-
let pageSize = opts.pageSize ?? 100;
|
|
267
|
-
if (pageSize > 10000)
|
|
268
|
-
pageSize = 10000;
|
|
269
|
-
let parentId = opts.parentId ?? null;
|
|
270
|
-
if (opts.contentType == null && parentId == null) {
|
|
271
|
-
parentId = effectiveUser;
|
|
272
|
-
}
|
|
273
|
-
const [assets, nextCursor] = await deps.assetModel.paginate({
|
|
274
|
-
user_id: effectiveUser,
|
|
275
|
-
parent_id: parentId,
|
|
276
|
-
content_type: opts.contentType ?? null,
|
|
277
|
-
limit: pageSize,
|
|
278
|
-
start_key: opts.cursor ?? null
|
|
279
|
-
});
|
|
280
|
-
const assetResponses = await Promise.all(assets.map((a) => assetFromRecord(a, deps.assetStorage)));
|
|
281
|
-
return { next: nextCursor, assets: assetResponses };
|
|
282
|
-
}
|
|
283
|
-
/**
|
|
284
|
-
* POST /admin/assets
|
|
285
|
-
*/
|
|
286
|
-
export async function handleCreateAsset(deps, data, currentUser = "1") {
|
|
287
|
-
const createData = {
|
|
288
|
-
...data,
|
|
289
|
-
user_id: data.user_id ?? currentUser,
|
|
290
|
-
name: data.name ?? "",
|
|
291
|
-
content_type: data.content_type ?? ""
|
|
292
|
-
};
|
|
293
|
-
const asset = await deps.assetModel.create(createData);
|
|
294
|
-
return assetFromRecord(asset, deps.assetStorage);
|
|
295
|
-
}
|
|
296
|
-
/**
|
|
297
|
-
* GET /admin/assets/:assetId
|
|
298
|
-
*/
|
|
299
|
-
export async function handleGetAsset(deps, assetId, userId = "1") {
|
|
300
|
-
// Special case: user root folder
|
|
301
|
-
if (assetId === userId) {
|
|
302
|
-
return {
|
|
303
|
-
user_id: userId,
|
|
304
|
-
id: userId,
|
|
305
|
-
name: "Home",
|
|
306
|
-
content_type: "folder",
|
|
307
|
-
parent_id: "",
|
|
308
|
-
workflow_id: null,
|
|
309
|
-
size: null,
|
|
310
|
-
get_url: null,
|
|
311
|
-
thumb_url: null,
|
|
312
|
-
created_at: ""
|
|
313
|
-
};
|
|
314
|
-
}
|
|
315
|
-
const asset = await deps.assetModel.get(assetId);
|
|
316
|
-
if (!asset) {
|
|
317
|
-
throw new HttpError(404, "Asset not found");
|
|
318
|
-
}
|
|
319
|
-
return assetFromRecord(asset, deps.assetStorage);
|
|
320
|
-
}
|
|
321
|
-
/**
|
|
322
|
-
* DELETE /admin/assets/:assetId
|
|
323
|
-
*
|
|
324
|
-
* Recursively deletes folders.
|
|
325
|
-
*/
|
|
326
|
-
export async function handleDeleteAsset(deps, assetId, currentUser) {
|
|
327
|
-
const asset = await deps.assetModel.get(assetId);
|
|
328
|
-
if (!asset) {
|
|
329
|
-
throw new HttpError(404, "Asset not found");
|
|
330
|
-
}
|
|
331
|
-
if (asset.user_id !== currentUser) {
|
|
332
|
-
throw new HttpError(403, "Asset access denied");
|
|
333
|
-
}
|
|
334
|
-
const deletedIds = [];
|
|
335
|
-
const deleteSingle = async (a) => {
|
|
336
|
-
await a.delete();
|
|
337
|
-
try {
|
|
338
|
-
await deps.assetStorage.delete(a.thumb_file_name);
|
|
339
|
-
}
|
|
340
|
-
catch {
|
|
341
|
-
// ignore
|
|
342
|
-
}
|
|
343
|
-
try {
|
|
344
|
-
await deps.assetStorage.delete(a.file_name);
|
|
345
|
-
}
|
|
346
|
-
catch {
|
|
347
|
-
// ignore
|
|
348
|
-
}
|
|
349
|
-
};
|
|
350
|
-
const deleteFolder = async (uid, folderId) => {
|
|
351
|
-
const ids = [];
|
|
352
|
-
const [children] = await deps.assetModel.paginate({
|
|
353
|
-
user_id: uid,
|
|
354
|
-
parent_id: folderId,
|
|
355
|
-
limit: 10000
|
|
356
|
-
});
|
|
357
|
-
for (const child of children) {
|
|
358
|
-
if (child.content_type === "folder") {
|
|
359
|
-
const subIds = await deleteFolder(uid, child.id);
|
|
360
|
-
ids.push(...subIds);
|
|
361
|
-
}
|
|
362
|
-
else {
|
|
363
|
-
await deleteSingle(child);
|
|
364
|
-
ids.push(child.id);
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
const folder = await deps.assetModel.find(uid, folderId);
|
|
368
|
-
if (folder) {
|
|
369
|
-
await deleteSingle(folder);
|
|
370
|
-
ids.push(folderId);
|
|
371
|
-
}
|
|
372
|
-
return ids;
|
|
373
|
-
};
|
|
374
|
-
if (asset.content_type === "folder") {
|
|
375
|
-
deletedIds.push(...(await deleteFolder(asset.user_id, assetId)));
|
|
376
|
-
}
|
|
377
|
-
else {
|
|
378
|
-
await deleteSingle(asset);
|
|
379
|
-
deletedIds.push(assetId);
|
|
380
|
-
}
|
|
381
|
-
return { deleted_asset_ids: deletedIds };
|
|
382
|
-
}
|
|
383
|
-
//# sourceMappingURL=admin-routes.js.map
|