@babav/knowledge-core-client 0.23.3 → 0.24.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/dist/index.d.ts +55 -0
- package/dist/index.js +27 -0
- package/package.json +1 -1
- package/src/index.ts +70 -0
package/dist/index.d.ts
CHANGED
|
@@ -224,6 +224,24 @@ export interface BatchUploadUrls {
|
|
|
224
224
|
}>;
|
|
225
225
|
expires_in: number;
|
|
226
226
|
}
|
|
227
|
+
/** One RESUMABLE GCS upload session (corpora.createUploadSessions). Hand `upload_url` to the
|
|
228
|
+
* browser: it PUTs bytes straight to GCS there, needing NO KC/tenant credential (the URI is the
|
|
229
|
+
* per-object write capability). Resumable → a dropped connection resumes, not restarts. */
|
|
230
|
+
export interface UploadSession {
|
|
231
|
+
filename: string;
|
|
232
|
+
document_id: UUID;
|
|
233
|
+
upload_url: string;
|
|
234
|
+
gcs_uri: string;
|
|
235
|
+
method: "PUT";
|
|
236
|
+
headers: Record<string, string>;
|
|
237
|
+
expires_at: string;
|
|
238
|
+
}
|
|
239
|
+
/** Per-item result of corpora.finalizeUploads (idempotent registration). */
|
|
240
|
+
export interface FinalizeResult {
|
|
241
|
+
document_id: UUID;
|
|
242
|
+
status: "ingesting" | "failed";
|
|
243
|
+
error?: string;
|
|
244
|
+
}
|
|
227
245
|
export interface Conversation {
|
|
228
246
|
id: UUID;
|
|
229
247
|
title: string | null;
|
|
@@ -498,6 +516,43 @@ export declare class KnowledgeCoreClient extends HttpBase {
|
|
|
498
516
|
custom_metadata?: Record<string, unknown>;
|
|
499
517
|
concurrency?: number;
|
|
500
518
|
}) => Promise<Document[]>;
|
|
519
|
+
/** (server-side) Mint one RESUMABLE GCS upload session per file. Return only the sessions to the
|
|
520
|
+
* browser; the browser PUTs bytes to each `upload_url` and needs NO KC/tenant credential (the
|
|
521
|
+
* session URI IS the per-object write capability). `origin` = the browser app origin (scopes the
|
|
522
|
+
* session; the bucket CORS must allow PUT/POST from it). */
|
|
523
|
+
createUploadSessions: (id: UUID, files: Array<{
|
|
524
|
+
filename: string;
|
|
525
|
+
content_type?: string;
|
|
526
|
+
size?: number;
|
|
527
|
+
}>, opts?: {
|
|
528
|
+
origin?: string;
|
|
529
|
+
}) => Promise<{
|
|
530
|
+
items: UploadSession[];
|
|
531
|
+
}>;
|
|
532
|
+
/** (server-side) Register documents whose bytes the browser already PUT to GCS. IDEMPOTENT +
|
|
533
|
+
* PER-ITEM — safe to retry; each result is { document_id, status: 'ingesting' | 'failed' }. Call
|
|
534
|
+
* after the browser reports its PUTs done. folder_id/visibility/custom_metadata apply to all
|
|
535
|
+
* items. `document_id` is stable from createUploadSessions, so documents.events (SSE) tracks it. */
|
|
536
|
+
finalizeUploads: (id: UUID, items: Array<{
|
|
537
|
+
document_id: UUID;
|
|
538
|
+
filename: string;
|
|
539
|
+
content_type?: string;
|
|
540
|
+
}>, opts?: {
|
|
541
|
+
folder_id?: UUID;
|
|
542
|
+
visibility?: Visibility;
|
|
543
|
+
custom_metadata?: Record<string, unknown>;
|
|
544
|
+
}) => Promise<{
|
|
545
|
+
results: FinalizeResult[];
|
|
546
|
+
}>;
|
|
547
|
+
/** (server-side) Cancel upload sessions the browser gave up on (idempotent cleanup). Pass the
|
|
548
|
+
* `upload_url` from createUploadSessions so the resumable session is dropped; any pending row is
|
|
549
|
+
* removed too. Safe to call repeatedly. */
|
|
550
|
+
abortUploadSessions: (id: UUID, items: Array<{
|
|
551
|
+
document_id: UUID;
|
|
552
|
+
upload_url?: string;
|
|
553
|
+
}>) => Promise<{
|
|
554
|
+
aborted: UUID[];
|
|
555
|
+
}>;
|
|
501
556
|
};
|
|
502
557
|
parse(a: {
|
|
503
558
|
file: FileData;
|
package/dist/index.js
CHANGED
|
@@ -283,6 +283,33 @@ export class KnowledgeCoreClient extends HttpBase {
|
|
|
283
283
|
} });
|
|
284
284
|
return res.documents;
|
|
285
285
|
},
|
|
286
|
+
// --- browser direct-to-GCS uploads (ANY size; the browser NEVER needs an API key) ---
|
|
287
|
+
// Split flow so the browser uploads bytes ITSELF while the tenant key stays server-side:
|
|
288
|
+
// 1. (server) createUploadSessions -> returns a resumable GCS session URI per file
|
|
289
|
+
// 2. (browser) PUT the bytes straight to each session URI (resumable; no credential)
|
|
290
|
+
// 3. (server) finalizeUploads -> register + enqueue; or abortUploadSessions to cancel
|
|
291
|
+
// Use this instead of uploadMany when bytes must not pass through your worker (browser -> GCS
|
|
292
|
+
// direct), e.g. multi-GB files or a browser that can't hold the tenant key.
|
|
293
|
+
/** (server-side) Mint one RESUMABLE GCS upload session per file. Return only the sessions to the
|
|
294
|
+
* browser; the browser PUTs bytes to each `upload_url` and needs NO KC/tenant credential (the
|
|
295
|
+
* session URI IS the per-object write capability). `origin` = the browser app origin (scopes the
|
|
296
|
+
* session; the bucket CORS must allow PUT/POST from it). */
|
|
297
|
+
createUploadSessions: (id, files, opts) => this.request("POST", `/v1/corpora/${id}/documents/upload-sessions`, { json: {
|
|
298
|
+
items: files.map((f) => ({ filename: f.filename, content_type: f.content_type })),
|
|
299
|
+
origin: opts?.origin,
|
|
300
|
+
} }),
|
|
301
|
+
/** (server-side) Register documents whose bytes the browser already PUT to GCS. IDEMPOTENT +
|
|
302
|
+
* PER-ITEM — safe to retry; each result is { document_id, status: 'ingesting' | 'failed' }. Call
|
|
303
|
+
* after the browser reports its PUTs done. folder_id/visibility/custom_metadata apply to all
|
|
304
|
+
* items. `document_id` is stable from createUploadSessions, so documents.events (SSE) tracks it. */
|
|
305
|
+
finalizeUploads: (id, items, opts) => this.request("POST", `/v1/corpora/${id}/documents/finalize`, { json: {
|
|
306
|
+
items, folder_id: opts?.folder_id, visibility: opts?.visibility,
|
|
307
|
+
custom_metadata: opts?.custom_metadata,
|
|
308
|
+
} }),
|
|
309
|
+
/** (server-side) Cancel upload sessions the browser gave up on (idempotent cleanup). Pass the
|
|
310
|
+
* `upload_url` from createUploadSessions so the resumable session is dropped; any pending row is
|
|
311
|
+
* removed too. Safe to call repeatedly. */
|
|
312
|
+
abortUploadSessions: (id, items) => this.request("POST", `/v1/corpora/${id}/documents/abort-uploads`, { json: { items } }),
|
|
286
313
|
};
|
|
287
314
|
// --- parsing (utility: file -> text, stores nothing) ---
|
|
288
315
|
parse(a) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@babav/knowledge-core-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0",
|
|
4
4
|
"description": "TypeScript client for the Babav Knowledge Core API (Deno + Node 18+, zero deps). Includes the babav.visual grammar TYPES at the ./visual subpath (types only; all visual rendering is server-side).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
package/src/index.ts
CHANGED
|
@@ -240,6 +240,24 @@ export interface BatchUploadUrls {
|
|
|
240
240
|
items: Array<{ filename: string; document_id: UUID; upload_url: string; gcs_uri: string }>;
|
|
241
241
|
expires_in: number;
|
|
242
242
|
}
|
|
243
|
+
/** One RESUMABLE GCS upload session (corpora.createUploadSessions). Hand `upload_url` to the
|
|
244
|
+
* browser: it PUTs bytes straight to GCS there, needing NO KC/tenant credential (the URI is the
|
|
245
|
+
* per-object write capability). Resumable → a dropped connection resumes, not restarts. */
|
|
246
|
+
export interface UploadSession {
|
|
247
|
+
filename: string;
|
|
248
|
+
document_id: UUID;
|
|
249
|
+
upload_url: string;
|
|
250
|
+
gcs_uri: string;
|
|
251
|
+
method: "PUT";
|
|
252
|
+
headers: Record<string, string>;
|
|
253
|
+
expires_at: string;
|
|
254
|
+
}
|
|
255
|
+
/** Per-item result of corpora.finalizeUploads (idempotent registration). */
|
|
256
|
+
export interface FinalizeResult {
|
|
257
|
+
document_id: UUID;
|
|
258
|
+
status: "ingesting" | "failed";
|
|
259
|
+
error?: string;
|
|
260
|
+
}
|
|
243
261
|
export interface Conversation {
|
|
244
262
|
id: UUID;
|
|
245
263
|
title: string | null;
|
|
@@ -669,6 +687,58 @@ export class KnowledgeCoreClient extends HttpBase {
|
|
|
669
687
|
);
|
|
670
688
|
return res.documents;
|
|
671
689
|
},
|
|
690
|
+
|
|
691
|
+
// --- browser direct-to-GCS uploads (ANY size; the browser NEVER needs an API key) ---
|
|
692
|
+
// Split flow so the browser uploads bytes ITSELF while the tenant key stays server-side:
|
|
693
|
+
// 1. (server) createUploadSessions -> returns a resumable GCS session URI per file
|
|
694
|
+
// 2. (browser) PUT the bytes straight to each session URI (resumable; no credential)
|
|
695
|
+
// 3. (server) finalizeUploads -> register + enqueue; or abortUploadSessions to cancel
|
|
696
|
+
// Use this instead of uploadMany when bytes must not pass through your worker (browser -> GCS
|
|
697
|
+
// direct), e.g. multi-GB files or a browser that can't hold the tenant key.
|
|
698
|
+
|
|
699
|
+
/** (server-side) Mint one RESUMABLE GCS upload session per file. Return only the sessions to the
|
|
700
|
+
* browser; the browser PUTs bytes to each `upload_url` and needs NO KC/tenant credential (the
|
|
701
|
+
* session URI IS the per-object write capability). `origin` = the browser app origin (scopes the
|
|
702
|
+
* session; the bucket CORS must allow PUT/POST from it). */
|
|
703
|
+
createUploadSessions: (
|
|
704
|
+
id: UUID,
|
|
705
|
+
files: Array<{ filename: string; content_type?: string; size?: number }>,
|
|
706
|
+
opts?: { origin?: string },
|
|
707
|
+
): Promise<{ items: UploadSession[] }> =>
|
|
708
|
+
this.request<{ items: UploadSession[] }>(
|
|
709
|
+
"POST", `/v1/corpora/${id}/documents/upload-sessions`,
|
|
710
|
+
{ json: {
|
|
711
|
+
items: files.map((f) => ({ filename: f.filename, content_type: f.content_type })),
|
|
712
|
+
origin: opts?.origin,
|
|
713
|
+
} },
|
|
714
|
+
),
|
|
715
|
+
|
|
716
|
+
/** (server-side) Register documents whose bytes the browser already PUT to GCS. IDEMPOTENT +
|
|
717
|
+
* PER-ITEM — safe to retry; each result is { document_id, status: 'ingesting' | 'failed' }. Call
|
|
718
|
+
* after the browser reports its PUTs done. folder_id/visibility/custom_metadata apply to all
|
|
719
|
+
* items. `document_id` is stable from createUploadSessions, so documents.events (SSE) tracks it. */
|
|
720
|
+
finalizeUploads: (
|
|
721
|
+
id: UUID,
|
|
722
|
+
items: Array<{ document_id: UUID; filename: string; content_type?: string }>,
|
|
723
|
+
opts?: { folder_id?: UUID; visibility?: Visibility; custom_metadata?: Record<string, unknown> },
|
|
724
|
+
): Promise<{ results: FinalizeResult[] }> =>
|
|
725
|
+
this.request<{ results: FinalizeResult[] }>(
|
|
726
|
+
"POST", `/v1/corpora/${id}/documents/finalize`,
|
|
727
|
+
{ json: {
|
|
728
|
+
items, folder_id: opts?.folder_id, visibility: opts?.visibility,
|
|
729
|
+
custom_metadata: opts?.custom_metadata,
|
|
730
|
+
} },
|
|
731
|
+
),
|
|
732
|
+
|
|
733
|
+
/** (server-side) Cancel upload sessions the browser gave up on (idempotent cleanup). Pass the
|
|
734
|
+
* `upload_url` from createUploadSessions so the resumable session is dropped; any pending row is
|
|
735
|
+
* removed too. Safe to call repeatedly. */
|
|
736
|
+
abortUploadSessions: (
|
|
737
|
+
id: UUID,
|
|
738
|
+
items: Array<{ document_id: UUID; upload_url?: string }>,
|
|
739
|
+
): Promise<{ aborted: UUID[] }> =>
|
|
740
|
+
this.request<{ aborted: UUID[] }>(
|
|
741
|
+
"POST", `/v1/corpora/${id}/documents/abort-uploads`, { json: { items } }),
|
|
672
742
|
};
|
|
673
743
|
|
|
674
744
|
// --- parsing (utility: file -> text, stores nothing) ---
|