@synapcores/sdk 0.2.1 → 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/dist/index.mjs CHANGED
@@ -254,20 +254,20 @@ var Collection = class {
254
254
  }
255
255
  async vectorSearch(options) {
256
256
  const { data } = await this.client._getHttpClient().post(
257
- `${this.basePath}/vector_search`,
257
+ `/vectors/collections/${this.name}/search`,
258
258
  {
259
259
  vector: options.vector,
260
- field: options.field || "embedding",
261
- top_k: options.topK || 10,
260
+ k: options.topK || 10,
262
261
  filter: options.filter,
263
- distance_metric: options.distanceMetric || "cosine",
264
- include_metadata: options.includeMetadata
262
+ include_metadata: options.includeMetadata !== false
265
263
  }
266
264
  );
265
+ const inner = data?.data ?? data;
266
+ const matches = Array.isArray(inner) ? inner : inner?.matches ?? inner?.results ?? inner?.documents ?? data?.matches ?? data?.results ?? data?.documents ?? [];
267
267
  return {
268
- documents: data.documents,
269
- total: data.total,
270
- tookMs: data.took_ms
268
+ documents: matches,
269
+ total: (inner && !Array.isArray(inner) ? inner.total : void 0) ?? matches.length,
270
+ tookMs: (inner && !Array.isArray(inner) ? inner.took_ms : void 0) ?? data?.took_ms
271
271
  };
272
272
  }
273
273
  async query(options = {}) {
@@ -405,27 +405,48 @@ var AutoMLClient = class {
405
405
  return new AutoMLModel(this, modelInfo);
406
406
  }
407
407
  async getModel(modelId) {
408
- const { data } = await this.synapCores._getHttpClient().get(
409
- `/automl/models/${modelId}`
410
- );
411
- const modelInfo = {
412
- id: data.id,
413
- name: data.name,
414
- task: data.task,
415
- status: data.status,
416
- accuracy: data.accuracy,
417
- createdAt: new Date(data.created_at ?? Date.now()),
418
- updatedAt: data.updated_at ? new Date(data.updated_at) : void 0,
419
- config: data.config ?? {}
420
- };
421
- return new AutoMLModel(this, modelInfo);
408
+ try {
409
+ const { data } = await this.synapCores._getHttpClient().get(
410
+ `/automl/models/${modelId}`
411
+ );
412
+ const m = data?.data ?? data;
413
+ const modelInfo = {
414
+ id: m.id ?? modelId,
415
+ name: m.name ?? modelId,
416
+ task: m.task,
417
+ status: m.status,
418
+ accuracy: m.accuracy,
419
+ createdAt: new Date(m.created_at ?? Date.now()),
420
+ updatedAt: m.updated_at ? new Date(m.updated_at) : void 0,
421
+ config: m.config ?? {}
422
+ };
423
+ return new AutoMLModel(this, modelInfo);
424
+ } catch (err) {
425
+ const status = err?.statusCode ?? err?.response?.status;
426
+ const code = err?.code;
427
+ if (status === 404 || code === "NOT_FOUND") {
428
+ const modelInfo = {
429
+ id: modelId,
430
+ name: modelId,
431
+ task: void 0,
432
+ status: "unknown",
433
+ accuracy: void 0,
434
+ createdAt: /* @__PURE__ */ new Date(),
435
+ updatedAt: void 0,
436
+ config: {}
437
+ };
438
+ return new AutoMLModel(this, modelInfo);
439
+ }
440
+ throw err;
441
+ }
422
442
  }
423
443
  async listModels(filters) {
424
444
  const { data } = await this.synapCores._getHttpClient().get("/automl/models", {
425
445
  params: filters
426
446
  });
427
- return (data.models ?? data ?? []).map((model) => ({
428
- id: model.id,
447
+ const list = Array.isArray(data) ? data : Array.isArray(data?.data) ? data.data : Array.isArray(data?.models) ? data.models : Array.isArray(data?.data?.items) ? data.data.items : [];
448
+ return list.map((model) => ({
449
+ id: model.id ?? model.name,
429
450
  name: model.name,
430
451
  task: model.task,
431
452
  status: model.status,
@@ -1936,23 +1957,24 @@ var GraphsApi = class {
1936
1957
  constructor(synapCores) {
1937
1958
  this.synapCores = synapCores;
1938
1959
  }
1960
+ // v0.3.0: gateway routes live under /graph/graphs, not /graphs.
1939
1961
  async list() {
1940
- const { data } = await this.synapCores._getHttpClient().get("/graphs");
1962
+ const { data } = await this.synapCores._getHttpClient().get("/graph/graphs");
1941
1963
  return (data.graphs ?? data ?? []).map((g) => this.normalize(g));
1942
1964
  }
1943
1965
  async create(name, opts = {}) {
1944
- const { data } = await this.synapCores._getHttpClient().post("/graphs", {
1966
+ const { data } = await this.synapCores._getHttpClient().post("/graph/graphs", {
1945
1967
  name,
1946
1968
  description: opts.description
1947
1969
  });
1948
1970
  return this.normalize(data);
1949
1971
  }
1950
1972
  async get(name) {
1951
- const { data } = await this.synapCores._getHttpClient().get(`/graphs/${name}`);
1973
+ const { data } = await this.synapCores._getHttpClient().get(`/graph/graphs/${name}`);
1952
1974
  return this.normalize(data);
1953
1975
  }
1954
1976
  async delete(name) {
1955
- await this.synapCores._getHttpClient().delete(`/graphs/${name}`);
1977
+ await this.synapCores._getHttpClient().delete(`/graph/graphs/${name}`);
1956
1978
  }
1957
1979
  normalize(data) {
1958
1980
  return {
@@ -2780,7 +2802,7 @@ var SynapCores = class {
2780
2802
  timeout: this.config.timeout,
2781
2803
  headers: {
2782
2804
  "Content-Type": "application/json",
2783
- "User-Agent": "synapcores-nodejs/0.2.0",
2805
+ "User-Agent": "synapcores-nodejs/0.3.0",
2784
2806
  ...authHeader
2785
2807
  },
2786
2808
  ...httpsAgent && { httpsAgent }
@@ -2946,15 +2968,35 @@ var SynapCores = class {
2946
2968
  this.collectionsCache.set(name, collection);
2947
2969
  return collection;
2948
2970
  }
2971
+ /**
2972
+ * Synchronous accessor that returns a Collection handle without round-tripping
2973
+ * to the gateway. Use this when you already know the collection exists and just
2974
+ * want to issue a vectorSearch / search / insert against it.
2975
+ *
2976
+ * v0.3.0: added so `client.collection(name).vectorSearch(...)` works without
2977
+ * a preceding await on getCollection().
2978
+ */
2979
+ collection(name) {
2980
+ if (this.collectionsCache.has(name)) {
2981
+ return this.collectionsCache.get(name);
2982
+ }
2983
+ const c = new Collection(this, name);
2984
+ this.collectionsCache.set(name, c);
2985
+ return c;
2986
+ }
2949
2987
  /**
2950
2988
  * List collections (legacy method for backward compatibility)
2951
2989
  */
2952
2990
  async listCollections() {
2953
2991
  const result = await this.listCollectionsDetailed();
2954
- return result.collections.map((c) => c.name);
2992
+ return (result.collections ?? []).map((c) => c.name);
2955
2993
  }
2956
2994
  /**
2957
2995
  * List collections with detailed information matching the database integration guide format
2996
+ *
2997
+ * v0.3.0: gateway returns an envelope { data: { items, total, page, page_size, ... }, meta }.
2998
+ * We normalise that into the SDK's { collections, total, page, pageSize } shape and also
2999
+ * accept legacy { collections: [...] } / bare arrays for forward-compat.
2958
3000
  */
2959
3001
  async listCollectionsDetailed(options) {
2960
3002
  const params = new URLSearchParams();
@@ -2966,7 +3008,14 @@ var SynapCores = class {
2966
3008
  const { data } = await this.httpClient.get(
2967
3009
  `/collections${params.toString() ? `?${params.toString()}` : ""}`
2968
3010
  );
2969
- return data;
3011
+ const inner = data?.data ?? data;
3012
+ const items = Array.isArray(inner) ? inner : inner?.items ?? inner?.collections ?? [];
3013
+ return {
3014
+ collections: items,
3015
+ total: inner?.total ?? items.length,
3016
+ page: inner?.page ?? 1,
3017
+ pageSize: inner?.page_size ?? inner?.pageSize ?? items.length
3018
+ };
2970
3019
  }
2971
3020
  async getDocuments(collectionName, page, pageSize) {
2972
3021
  const { data } = await this.httpClient.get(
@@ -3892,7 +3941,7 @@ var SynapCores = class {
3892
3941
 
3893
3942
  // src/index.ts
3894
3943
  import { z } from "zod";
3895
- var VERSION = "0.2.0";
3944
+ var VERSION = "0.3.0";
3896
3945
  export {
3897
3946
  AuthenticationError,
3898
3947
  AutoMLClient,