@littlebigbrain/client 0.14.0 → 0.15.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/client.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { DurableImportSource, ImportLine, LbbClientOptions, ListResponse, RawLbbResponse, ReadConsistencyOptions, RdfImportDocument, RdfImportManyResult, RdfImportOptions, Schemas, SearchConsistency, SparqlResults } from "./types.js";
2
- import { type CallOptions, type RequestOptions } from "./transport.js";
2
+ import { type RequestOptions } from "./transport.js";
3
3
  import { EntityNamespace, GraphNamespace, OntologyNamespace, QueryNamespace, SchemaNamespace, SearchNamespace, EvalsNamespace, EmbeddingsNamespace } from "./namespaces.js";
4
4
  export { parseSparqlResults } from "./types.js";
5
5
  export type { AttributeFilter, AttributeFilterOp, AttributeFilterValue, EntityAttributeFilterOptions, EntityPropertiesLine, DurableImportLine, DurableImportSource, FetchLike, FlatProperties, ImportLine, LbbClientOptions, LbbRequestEvent, LbbResponseEvent, LbbRetryEvent, LbbErrorPayload, ListResponse, RawLbbResponse, ReadConsistencyOptions, RdfImportDocument, RdfImportManyResult, RdfImportOptions, Schemas, SearchConsistency, SparqlResults, SparqlResultsJson, SparqlTerm, CommitRequest, CommitResponse, Entity, EntitySelector, GraphMetadata, GraphSummary, SchemaView, Snapshot, } from "./types.js";
@@ -290,34 +290,6 @@ export declare class LbbClient {
290
290
  }): Promise<Schemas["SearchFeedbackResponse"]>;
291
291
  /** Export the stored relevance labels as qrels-style rows for training. */
292
292
  searchFeedbackExport(): Promise<Schemas["SearchFeedbackExportResponse"]>;
293
- /**
294
- * Ranked incoming/outgoing neighborhood for a graph entity.
295
- *
296
- * `edges` caps the edges returned per direction (default 1000, maximum
297
- * 10000). When a cap cuts a direction the response carries a `truncation`
298
- * block; an uncut response omits it entirely.
299
- */
300
- entityNeighborhood(opts: {
301
- id?: string;
302
- type?: string;
303
- name?: string;
304
- relations?: string[];
305
- asOf?: string;
306
- edges?: number;
307
- }): Promise<Schemas["EntityNeighborhoodResponse"]>;
308
- /** Exact type cardinality plus a bounded deterministic sample from Base. */
309
- entityTypeSample(opts: {
310
- type: string;
311
- limit?: number;
312
- } & CallOptions): Promise<Schemas["EntityTypeSampleResponse"]>;
313
- /** Stored entity object-ref status and index-coverage metadata (no
314
- * attributes — read those from `entityDetail`'s top-level `attributes`). */
315
- entityMetadata(opts: {
316
- id?: string;
317
- type?: string;
318
- name?: string;
319
- asOf?: string;
320
- }): Promise<Schemas["EntityMetadataResponse"]>;
321
293
  /**
322
294
  * Read projected attributes and current relationships from one RDF snapshot.
323
295
  * Inspect `unavailable_sections` before interpreting legacy provenance arrays.
@@ -341,14 +313,6 @@ export declare class LbbClient {
341
313
  * The caller supplies a bounded collection endpoint and its cursor.
342
314
  */
343
315
  listAll<T>(fetchPage: (cursor?: string) => Promise<ListResponse<T>>): AsyncGenerator<T, void, unknown>;
344
- /** Current state of an entity's relations, optionally as-of a timestamp. */
345
- currentState(body: Schemas["CurrentStateRequest"]): Promise<Schemas["CurrentStateResponse"]>;
346
- /** Full edge-event history for a relationship. */
347
- history(body: Schemas["RelationshipHistoryRequest"]): Promise<Schemas["RelationshipHistoryResponse"]>;
348
- /** Ordered state-transition log for an entity's relation, with dwell time. */
349
- transitions(body: Schemas["EntityTransitionsRequest"]): Promise<Schemas["EntityTransitionsResponse"]>;
350
- /** Lineage and evidence for a single edge. */
351
- why(body: Schemas["WhyRequest"]): Promise<Schemas["WhyResponse"]>;
352
316
  /**
353
317
  * SPARQL-subset SELECT/ASK/aggregate query (FILTER, HAVING, ORDER BY, ASK,
354
318
  * COUNT/SUM/AVG/MIN/MAX). GROUP BY is not limited to entity identity:
@@ -360,14 +324,27 @@ export declare class LbbClient {
360
324
  * `groups[].keys`.
361
325
  */
362
326
  sparql(body: Schemas["SparqlSelectRequest"], opts?: ReadConsistencyOptions): Promise<Schemas["SparqlSelectResponse"]>;
363
- /** SPARQL 1.1 query from text (SELECT/ASK) over the live graph; `results` is SPARQL 1.1 Query Results JSON. The text dialect carries `consistency`/`min_indexed_seq` on the URL; a floor with no explicit consistency implies a strong base-plus-delta read. */
327
+ /**
328
+ * SPARQL 1.1 query from text (SELECT/ASK) over the live graph; `results` is
329
+ * SPARQL 1.1 Query Results JSON. The text dialect carries
330
+ * `consistency`/`min_indexed_seq` on the URL; a floor with no explicit
331
+ * consistency implies a strong base-plus-delta read. `as_of_commit_seq` in
332
+ * the body reads the retained published generation of that exact commit.
333
+ *
334
+ * The query is read-only, so a retryable `429` (for example
335
+ * `read_your_writes_pending` while publication catches up to the floor) is
336
+ * retried within the retry budget. A `5xx` is not retried: a query that
337
+ * timed out would run again.
338
+ */
364
339
  sparqlText(body: Schemas["SparqlTextRequest"], opts?: ReadConsistencyOptions): Promise<Schemas["SparqlTextResponse"]>;
365
340
  /**
366
341
  * Run a SPARQL 1.1 text query and return parsed results — the ergonomic
367
342
  * complement to {@link sparqlText} (which hands back the raw results string).
368
- * Returns `{ vars, boolean, bindings, rows }` via {@link parseSparqlResults}:
369
- * `rows` is the bindings flattened to `{ variable: lexicalValue }`, `boolean`
370
- * is the ASK answer (or `null` for a SELECT).
343
+ * Returns `{ vars, boolean, bindings, rows, snapshot }` via
344
+ * {@link parseSparqlResults}: `rows` is the bindings flattened to
345
+ * `{ variable: lexicalValue }`, `boolean` is the ASK answer (or `null` for a
346
+ * SELECT), and `snapshot.served_at_seq` is the commit an eventual or pinned
347
+ * read answered from (`snapshot` is `null` for a plain strong read).
371
348
  */
372
349
  sparqlRows(body: Schemas["SparqlTextRequest"], opts?: ReadConsistencyOptions): Promise<SparqlResults>;
373
350
  /**
package/dist/client.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { parseSparqlResults } from "./types.js";
2
- import { bodyMarksTerminal, errorCodeFromBody, fullJitterBackoffMs, parseLbbError, parseResponseJson, retryAllowed, retryableStatus, retryDelayMs, sleep, } from "./transport.js";
2
+ import { bodyMarksTerminal, errorCodeFromBody, fullJitterBackoffMs, parseLbbError, parseResponseJson, retriesNetworkFailure, retriesStatus, retryAllowed, retryableStatus, retryDelayMs, sleep, } from "./transport.js";
3
3
  import { LbbCapabilityError } from "./transport.js";
4
4
  import { EntityNamespace, GraphNamespace, OntologyNamespace, QueryNamespace, SchemaNamespace, SearchNamespace, EvalsNamespace, EmbeddingsNamespace, } from "./namespaces.js";
5
5
  export { parseSparqlResults } from "./types.js";
@@ -237,7 +237,7 @@ export class LbbClient {
237
237
  if (opts.idempotencyKey !== undefined)
238
238
  headers["idempotency-key"] = opts.idempotencyKey;
239
239
  Object.assign(headers, opts.headers ?? {});
240
- const canRetry = opts.retry ?? retryAllowed(method, opts.idempotencyKey);
240
+ const retry = opts.retry ?? retryAllowed(method, opts.idempotencyKey);
241
241
  const body = opts.rawBody !== undefined
242
242
  ? opts.rawBody
243
243
  : opts.body !== undefined
@@ -302,7 +302,9 @@ export class LbbClient {
302
302
  cause: error,
303
303
  }), { name: "TimeoutError" })
304
304
  : error;
305
- if (!callerAborted && canRetry && attempt < maxRetries) {
305
+ if (!callerAborted &&
306
+ retriesNetworkFailure(retry) &&
307
+ attempt < maxRetries) {
306
308
  const delayMs = fullJitterBackoffMs(this.retryDelayMs, attempt);
307
309
  if (Date.now() + delayMs <= deadline) {
308
310
  this.onRetry?.({
@@ -329,7 +331,7 @@ export class LbbClient {
329
331
  attempt === maxRetries) {
330
332
  break;
331
333
  }
332
- if (!canRetry) {
334
+ if (!retriesStatus(retry, response.status)) {
333
335
  break;
334
336
  }
335
337
  // Honor the server's typed body verdict: a terminal error
@@ -804,45 +806,6 @@ export class LbbClient {
804
806
  searchFeedbackExport() {
805
807
  return this.request("GET", "/v1/search/feedback/export");
806
808
  }
807
- /**
808
- * Ranked incoming/outgoing neighborhood for a graph entity.
809
- *
810
- * `edges` caps the edges returned per direction (default 1000, maximum
811
- * 10000). When a cap cuts a direction the response carries a `truncation`
812
- * block; an uncut response omits it entirely.
813
- */
814
- entityNeighborhood(opts) {
815
- return this.request("GET", "/v1/graph/entity/neighborhood", {
816
- query: {
817
- id: opts.id,
818
- type: opts.type,
819
- name: opts.name,
820
- relations: opts.relations?.join(","),
821
- as_of: opts.asOf,
822
- edges: opts.edges,
823
- },
824
- });
825
- }
826
- /** Exact type cardinality plus a bounded deterministic sample from Base. */
827
- entityTypeSample(opts) {
828
- const { type, limit, ...request } = opts;
829
- return this.request("GET", "/v1/graph/entities/sample", {
830
- ...request,
831
- query: { type, limit },
832
- });
833
- }
834
- /** Stored entity object-ref status and index-coverage metadata (no
835
- * attributes — read those from `entityDetail`'s top-level `attributes`). */
836
- entityMetadata(opts) {
837
- return this.request("GET", "/v1/graph/entity/metadata", {
838
- query: {
839
- id: opts.id,
840
- type: opts.type,
841
- name: opts.name,
842
- as_of: opts.asOf,
843
- },
844
- });
845
- }
846
809
  /**
847
810
  * Read projected attributes and current relationships from one RDF snapshot.
848
811
  * Inspect `unavailable_sections` before interpreting legacy provenance arrays.
@@ -879,23 +842,7 @@ export class LbbClient {
879
842
  cursor = page.next_cursor;
880
843
  }
881
844
  }
882
- // --- temporal / lineage / shapes ---
883
- /** Current state of an entity's relations, optionally as-of a timestamp. */
884
- currentState(body) {
885
- return this.request("POST", "/v1/query/state", { body });
886
- }
887
- /** Full edge-event history for a relationship. */
888
- history(body) {
889
- return this.request("POST", "/v1/query/history", { body });
890
- }
891
- /** Ordered state-transition log for an entity's relation, with dwell time. */
892
- transitions(body) {
893
- return this.request("POST", "/v1/query/transitions", { body });
894
- }
895
- /** Lineage and evidence for a single edge. */
896
- why(body) {
897
- return this.request("POST", "/v1/query/why", { body });
898
- }
845
+ // --- query ---
899
846
  /**
900
847
  * SPARQL-subset SELECT/ASK/aggregate query (FILTER, HAVING, ORDER BY, ASK,
901
848
  * COUNT/SUM/AVG/MIN/MAX). GROUP BY is not limited to entity identity:
@@ -911,19 +858,33 @@ export class LbbClient {
911
858
  body: this.mergeReadConsistency(body, opts),
912
859
  });
913
860
  }
914
- /** SPARQL 1.1 query from text (SELECT/ASK) over the live graph; `results` is SPARQL 1.1 Query Results JSON. The text dialect carries `consistency`/`min_indexed_seq` on the URL; a floor with no explicit consistency implies a strong base-plus-delta read. */
861
+ /**
862
+ * SPARQL 1.1 query from text (SELECT/ASK) over the live graph; `results` is
863
+ * SPARQL 1.1 Query Results JSON. The text dialect carries
864
+ * `consistency`/`min_indexed_seq` on the URL; a floor with no explicit
865
+ * consistency implies a strong base-plus-delta read. `as_of_commit_seq` in
866
+ * the body reads the retained published generation of that exact commit.
867
+ *
868
+ * The query is read-only, so a retryable `429` (for example
869
+ * `read_your_writes_pending` while publication catches up to the floor) is
870
+ * retried within the retry budget. A `5xx` is not retried: a query that
871
+ * timed out would run again.
872
+ */
915
873
  sparqlText(body, opts) {
916
874
  return this.request("POST", "/v1/query/sparql-text", {
917
875
  body,
918
876
  query: this.readConsistencyQuery(opts),
877
+ retry: "rate_limited",
919
878
  });
920
879
  }
921
880
  /**
922
881
  * Run a SPARQL 1.1 text query and return parsed results — the ergonomic
923
882
  * complement to {@link sparqlText} (which hands back the raw results string).
924
- * Returns `{ vars, boolean, bindings, rows }` via {@link parseSparqlResults}:
925
- * `rows` is the bindings flattened to `{ variable: lexicalValue }`, `boolean`
926
- * is the ASK answer (or `null` for a SELECT).
883
+ * Returns `{ vars, boolean, bindings, rows, snapshot }` via
884
+ * {@link parseSparqlResults}: `rows` is the bindings flattened to
885
+ * `{ variable: lexicalValue }`, `boolean` is the ASK answer (or `null` for a
886
+ * SELECT), and `snapshot.served_at_seq` is the commit an eventual or pinned
887
+ * read answered from (`snapshot` is `null` for a plain strong read).
927
888
  */
928
889
  async sparqlRows(body, opts) {
929
890
  return parseSparqlResults(await this.sparqlText(body, opts));
@@ -61,20 +61,6 @@ export declare class SearchNamespace {
61
61
  export declare class EntityNamespace {
62
62
  private readonly client;
63
63
  constructor(client: LbbClient);
64
- /**
65
- * Return the exact type cardinality and a bounded deterministic sample from
66
- * the Base family pinned by the published generation.
67
- */
68
- sample(opts: {
69
- type: string;
70
- limit?: number;
71
- } & CallOptions): Promise<Schemas["EntityTypeSampleResponse"]>;
72
- get(opts: {
73
- id?: string;
74
- type?: string;
75
- name?: string;
76
- asOf?: string;
77
- }): Promise<Schemas["EntityMetadataResponse"]>;
78
64
  detail(opts: Parameters<LbbClient["entityDetail"]>[0]): Promise<Schemas["EntityDetailResponse"]>;
79
65
  /**
80
66
  * Filter entities already bound by relation patterns using typed attributes,
@@ -155,16 +155,6 @@ export class EntityNamespace {
155
155
  constructor(client) {
156
156
  this.client = client;
157
157
  }
158
- /**
159
- * Return the exact type cardinality and a bounded deterministic sample from
160
- * the Base family pinned by the published generation.
161
- */
162
- sample(opts) {
163
- return this.client.entityTypeSample(opts);
164
- }
165
- get(opts) {
166
- return this.client.entityMetadata(opts);
167
- }
168
158
  detail(opts) {
169
159
  return this.client.entityDetail(opts);
170
160
  }