@babav/knowledge-core-client 0.23.2 → 0.23.3

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 CHANGED
@@ -398,7 +398,9 @@ export declare class KnowledgeCoreClient extends HttpBase {
398
398
  /** @param opts.apiKey a TENANT key, supplied by the caller. */
399
399
  constructor(opts: ClientOptions);
400
400
  query(agentId: UUID, body: QueryRequest): Promise<QueryResponse>;
401
- /** Streaming query (SSE). Resolves when the stream ends. */
401
+ /** Streaming query (SSE). Resolves when the stream ends (the Promise resolving is normal, not an
402
+ * error). Pass `signal` and abort() on unmount / when the user cancels or navigates away so the
403
+ * connection doesn't linger. Transient (ends on `done`) — no reopen logic needed. */
402
404
  queryStream(agentId: UUID, body: QueryRequest, handlers: StreamHandlers, signal?: AbortSignal): Promise<void>;
403
405
  /** Shared SSE reader for the document-status streams (documents.events / folders.events).
404
406
  * Resolves when the stream ends (server sends `complete` once nothing is in-flight, or the
@@ -519,7 +521,8 @@ export declare class KnowledgeCoreClient extends HttpBase {
519
521
  limit?: number;
520
522
  cursor?: string;
521
523
  }) => Promise<Page<Document>>;
522
- /** Live ingestion-status stream for ONE folder (same contract as documents.events). */
524
+ /** Live ingestion-status stream for ONE folder. Same contract AND lifecycle rules as
525
+ * `documents.events` (abort on unmount, one per view, open lazily, don't reopen on complete). */
523
526
  events: (folderId: UUID, handlers: DocumentEventHandlers, signal?: AbortSignal) => Promise<void>;
524
527
  };
525
528
  documents: {
@@ -540,9 +543,25 @@ export declare class KnowledgeCoreClient extends HttpBase {
540
543
  deleting: UUID[];
541
544
  count: number;
542
545
  }>;
543
- /** Live ingestion-status stream for a corpus (SSE PUSH — replaces polling count). Snapshot on
544
- * connect, then a delta per transition, then `complete` when nothing is in-flight. Abort via
545
- * the signal. 501 (onError) if the environment has no doc-status bus fall back to polling. */
546
+ /** Live ingestion-status stream for a corpus (SSE PUSH — replaces polling count). On connect:
547
+ * `onSnapshot` (current state), then `onDocument` deltas as docs transition (pending → ingesting
548
+ * indexed | failed, and deleting deleted), then `onComplete` when nothing is in-flight.
549
+ * 501 (onError) if the env has no doc-status bus — fall back to polling countDocuments().
550
+ *
551
+ * A watcher is a held connection — manage its lifecycle:
552
+ * 1. ALWAYS abort on unmount/navigation via `signal` (else it stays open until the ~30-min cap):
553
+ * const c = new AbortController();
554
+ * kc.documents.events(id, handlers, c.signal).catch(()=>{});
555
+ * return () => c.abort(); // e.g. React useEffect cleanup
556
+ * 2. ONE watcher per view — never one per document/row.
557
+ * 3. Open lazily — only while the view has in-flight docs, or right after an upload. If nothing
558
+ * is in-flight the server sends `complete` and closes immediately (nothing to hold).
559
+ * 4. Do NOT reopen on `onComplete` — that's a permanent connection. Reopen only on NEW work
560
+ * (another upload) or an unexpected disconnect while work remains.
561
+ * 5. De-dupe — keep the AbortController in a ref and abort the previous before opening a new one
562
+ * (guards against re-renders / StrictMode double-mount).
563
+ * 6. On a network drop, reconnect with backoff and rebuild from the fresh `snapshot` (authoritative).
564
+ * 7. The Promise RESOLVING is normal (stream ended: complete or the cap) — only onError is a failure. */
546
565
  events: (corpusId: UUID, handlers: DocumentEventHandlers, signal?: AbortSignal) => Promise<void>;
547
566
  };
548
567
  conversations: {
package/dist/index.js CHANGED
@@ -151,7 +151,9 @@ export class KnowledgeCoreClient extends HttpBase {
151
151
  query(agentId, body) {
152
152
  return this.request("POST", `/v1/agents/${agentId}/query`, { json: body });
153
153
  }
154
- /** Streaming query (SSE). Resolves when the stream ends. */
154
+ /** Streaming query (SSE). Resolves when the stream ends (the Promise resolving is normal, not an
155
+ * error). Pass `signal` and abort() on unmount / when the user cancels or navigates away so the
156
+ * connection doesn't linger. Transient (ends on `done`) — no reopen logic needed. */
155
157
  async queryStream(agentId, body, handlers, signal) {
156
158
  const res = await this.raw("POST", `/v1/agents/${agentId}/query/stream`, { json: body, signal });
157
159
  if (!res.ok || !res.body) {
@@ -301,7 +303,8 @@ export class KnowledgeCoreClient extends HttpBase {
301
303
  countDocuments: (folderId) => this.request("GET", `/v1/folders/${folderId}/documents/count`),
302
304
  /** Documents in the folder whose filename contains `q` (case-insensitive), paginated. */
303
305
  searchDocuments: (folderId, q, opts) => this.request("GET", `/v1/folders/${folderId}/documents/search`, { query: { q, ...opts } }),
304
- /** Live ingestion-status stream for ONE folder (same contract as documents.events). */
306
+ /** Live ingestion-status stream for ONE folder. Same contract AND lifecycle rules as
307
+ * `documents.events` (abort on unmount, one per view, open lazily, don't reopen on complete). */
305
308
  events: (folderId, handlers, signal) => this._streamDocEvents(`/v1/folders/${folderId}/documents/events`, handlers, signal),
306
309
  };
307
310
  // --- documents ---
@@ -317,9 +320,25 @@ export class KnowledgeCoreClient extends HttpBase {
317
320
  * one request. IDs not in the corpus are skipped. Completion observable via documents.events /
318
321
  * documents.get() → 404. Returns { deleting: ids, count }. */
319
322
  deleteMany: (corpusId, documentIds) => this.request("POST", `/v1/corpora/${corpusId}/documents/batch-delete`, { json: { document_ids: documentIds } }),
320
- /** Live ingestion-status stream for a corpus (SSE PUSH — replaces polling count). Snapshot on
321
- * connect, then a delta per transition, then `complete` when nothing is in-flight. Abort via
322
- * the signal. 501 (onError) if the environment has no doc-status bus fall back to polling. */
323
+ /** Live ingestion-status stream for a corpus (SSE PUSH — replaces polling count). On connect:
324
+ * `onSnapshot` (current state), then `onDocument` deltas as docs transition (pending → ingesting
325
+ * indexed | failed, and deleting deleted), then `onComplete` when nothing is in-flight.
326
+ * 501 (onError) if the env has no doc-status bus — fall back to polling countDocuments().
327
+ *
328
+ * A watcher is a held connection — manage its lifecycle:
329
+ * 1. ALWAYS abort on unmount/navigation via `signal` (else it stays open until the ~30-min cap):
330
+ * const c = new AbortController();
331
+ * kc.documents.events(id, handlers, c.signal).catch(()=>{});
332
+ * return () => c.abort(); // e.g. React useEffect cleanup
333
+ * 2. ONE watcher per view — never one per document/row.
334
+ * 3. Open lazily — only while the view has in-flight docs, or right after an upload. If nothing
335
+ * is in-flight the server sends `complete` and closes immediately (nothing to hold).
336
+ * 4. Do NOT reopen on `onComplete` — that's a permanent connection. Reopen only on NEW work
337
+ * (another upload) or an unexpected disconnect while work remains.
338
+ * 5. De-dupe — keep the AbortController in a ref and abort the previous before opening a new one
339
+ * (guards against re-renders / StrictMode double-mount).
340
+ * 6. On a network drop, reconnect with backoff and rebuild from the fresh `snapshot` (authoritative).
341
+ * 7. The Promise RESOLVING is normal (stream ended: complete or the cap) — only onError is a failure. */
323
342
  events: (corpusId, handlers, signal) => this._streamDocEvents(`/v1/corpora/${corpusId}/documents/events`, handlers, signal),
324
343
  };
325
344
  // --- conversations ---
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babav/knowledge-core-client",
3
- "version": "0.23.2",
3
+ "version": "0.23.3",
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
@@ -525,7 +525,9 @@ export class KnowledgeCoreClient extends HttpBase {
525
525
  return this.request("POST", `/v1/agents/${agentId}/query`, { json: body });
526
526
  }
527
527
 
528
- /** Streaming query (SSE). Resolves when the stream ends. */
528
+ /** Streaming query (SSE). Resolves when the stream ends (the Promise resolving is normal, not an
529
+ * error). Pass `signal` and abort() on unmount / when the user cancels or navigates away so the
530
+ * connection doesn't linger. Transient (ends on `done`) — no reopen logic needed. */
529
531
  async queryStream(agentId: UUID, body: QueryRequest, handlers: StreamHandlers, signal?: AbortSignal): Promise<void> {
530
532
  const res = await this.raw("POST", `/v1/agents/${agentId}/query/stream`, { json: body, signal });
531
533
  if (!res.ok || !res.body) {
@@ -693,7 +695,8 @@ export class KnowledgeCoreClient extends HttpBase {
693
695
  /** Documents in the folder whose filename contains `q` (case-insensitive), paginated. */
694
696
  searchDocuments: (folderId: UUID, q: string, opts?: { limit?: number; cursor?: string }) =>
695
697
  this.request<Page<Document>>("GET", `/v1/folders/${folderId}/documents/search`, { query: { q, ...opts } }),
696
- /** Live ingestion-status stream for ONE folder (same contract as documents.events). */
698
+ /** Live ingestion-status stream for ONE folder. Same contract AND lifecycle rules as
699
+ * `documents.events` (abort on unmount, one per view, open lazily, don't reopen on complete). */
697
700
  events: (folderId: UUID, handlers: DocumentEventHandlers, signal?: AbortSignal) =>
698
701
  this._streamDocEvents(`/v1/folders/${folderId}/documents/events`, handlers, signal),
699
702
  };
@@ -715,9 +718,25 @@ export class KnowledgeCoreClient extends HttpBase {
715
718
  deleteMany: (corpusId: UUID, documentIds: UUID[]) =>
716
719
  this.request<{ deleting: UUID[]; count: number }>(
717
720
  "POST", `/v1/corpora/${corpusId}/documents/batch-delete`, { json: { document_ids: documentIds } }),
718
- /** Live ingestion-status stream for a corpus (SSE PUSH — replaces polling count). Snapshot on
719
- * connect, then a delta per transition, then `complete` when nothing is in-flight. Abort via
720
- * the signal. 501 (onError) if the environment has no doc-status bus fall back to polling. */
721
+ /** Live ingestion-status stream for a corpus (SSE PUSH — replaces polling count). On connect:
722
+ * `onSnapshot` (current state), then `onDocument` deltas as docs transition (pending → ingesting
723
+ * indexed | failed, and deleting deleted), then `onComplete` when nothing is in-flight.
724
+ * 501 (onError) if the env has no doc-status bus — fall back to polling countDocuments().
725
+ *
726
+ * A watcher is a held connection — manage its lifecycle:
727
+ * 1. ALWAYS abort on unmount/navigation via `signal` (else it stays open until the ~30-min cap):
728
+ * const c = new AbortController();
729
+ * kc.documents.events(id, handlers, c.signal).catch(()=>{});
730
+ * return () => c.abort(); // e.g. React useEffect cleanup
731
+ * 2. ONE watcher per view — never one per document/row.
732
+ * 3. Open lazily — only while the view has in-flight docs, or right after an upload. If nothing
733
+ * is in-flight the server sends `complete` and closes immediately (nothing to hold).
734
+ * 4. Do NOT reopen on `onComplete` — that's a permanent connection. Reopen only on NEW work
735
+ * (another upload) or an unexpected disconnect while work remains.
736
+ * 5. De-dupe — keep the AbortController in a ref and abort the previous before opening a new one
737
+ * (guards against re-renders / StrictMode double-mount).
738
+ * 6. On a network drop, reconnect with backoff and rebuild from the fresh `snapshot` (authoritative).
739
+ * 7. The Promise RESOLVING is normal (stream ended: complete or the cap) — only onError is a failure. */
721
740
  events: (corpusId: UUID, handlers: DocumentEventHandlers, signal?: AbortSignal) =>
722
741
  this._streamDocEvents(`/v1/corpora/${corpusId}/documents/events`, handlers, signal),
723
742
  };