@synapcores/sdk 0.2.0 → 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/CHANGELOG.md +61 -0
- package/dist/index.d.mts +19 -1
- package/dist/index.d.ts +19 -1
- package/dist/index.js +88 -34
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +88 -34
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
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
|
-
|
|
257
|
+
`/vectors/collections/${this.name}/search`,
|
|
258
258
|
{
|
|
259
259
|
vector: options.vector,
|
|
260
|
-
|
|
261
|
-
top_k: options.topK || 10,
|
|
260
|
+
k: options.topK || 10,
|
|
262
261
|
filter: options.filter,
|
|
263
|
-
|
|
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:
|
|
269
|
-
total:
|
|
270
|
-
tookMs:
|
|
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
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
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
|
-
|
|
428
|
-
|
|
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 {
|
|
@@ -1975,10 +1997,15 @@ var GraphClient = class {
|
|
|
1975
1997
|
}
|
|
1976
1998
|
/**
|
|
1977
1999
|
* Run a Cypher / MATCH query.
|
|
2000
|
+
*
|
|
2001
|
+
* The gateway's MatchRequest expects `sql: String` (see
|
|
2002
|
+
* crates/aidb-gateway/src/routes/graph.rs MatchRequest); we keep the
|
|
2003
|
+
* SDK-facing parameter named `query` because every caller writes
|
|
2004
|
+
* Cypher, not SQL — the gateway's field name is a historical artifact.
|
|
1978
2005
|
*/
|
|
1979
2006
|
async cypher(query, params = {}, graph) {
|
|
1980
2007
|
const { data } = await this.synapCores._getHttpClient().post("/graph/match", {
|
|
1981
|
-
query,
|
|
2008
|
+
sql: query,
|
|
1982
2009
|
params,
|
|
1983
2010
|
graph
|
|
1984
2011
|
});
|
|
@@ -1989,7 +2016,7 @@ var GraphClient = class {
|
|
|
1989
2016
|
*/
|
|
1990
2017
|
async cypherProfile(query, params = {}, graph) {
|
|
1991
2018
|
const { data } = await this.synapCores._getHttpClient().post("/graph/match/profile", {
|
|
1992
|
-
query,
|
|
2019
|
+
sql: query,
|
|
1993
2020
|
params,
|
|
1994
2021
|
graph
|
|
1995
2022
|
});
|
|
@@ -2775,7 +2802,7 @@ var SynapCores = class {
|
|
|
2775
2802
|
timeout: this.config.timeout,
|
|
2776
2803
|
headers: {
|
|
2777
2804
|
"Content-Type": "application/json",
|
|
2778
|
-
"User-Agent": "synapcores-nodejs/0.
|
|
2805
|
+
"User-Agent": "synapcores-nodejs/0.3.0",
|
|
2779
2806
|
...authHeader
|
|
2780
2807
|
},
|
|
2781
2808
|
...httpsAgent && { httpsAgent }
|
|
@@ -2941,15 +2968,35 @@ var SynapCores = class {
|
|
|
2941
2968
|
this.collectionsCache.set(name, collection);
|
|
2942
2969
|
return collection;
|
|
2943
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
|
+
}
|
|
2944
2987
|
/**
|
|
2945
2988
|
* List collections (legacy method for backward compatibility)
|
|
2946
2989
|
*/
|
|
2947
2990
|
async listCollections() {
|
|
2948
2991
|
const result = await this.listCollectionsDetailed();
|
|
2949
|
-
return result.collections.map((c) => c.name);
|
|
2992
|
+
return (result.collections ?? []).map((c) => c.name);
|
|
2950
2993
|
}
|
|
2951
2994
|
/**
|
|
2952
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.
|
|
2953
3000
|
*/
|
|
2954
3001
|
async listCollectionsDetailed(options) {
|
|
2955
3002
|
const params = new URLSearchParams();
|
|
@@ -2961,7 +3008,14 @@ var SynapCores = class {
|
|
|
2961
3008
|
const { data } = await this.httpClient.get(
|
|
2962
3009
|
`/collections${params.toString() ? `?${params.toString()}` : ""}`
|
|
2963
3010
|
);
|
|
2964
|
-
|
|
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
|
+
};
|
|
2965
3019
|
}
|
|
2966
3020
|
async getDocuments(collectionName, page, pageSize) {
|
|
2967
3021
|
const { data } = await this.httpClient.get(
|
|
@@ -3887,7 +3941,7 @@ var SynapCores = class {
|
|
|
3887
3941
|
|
|
3888
3942
|
// src/index.ts
|
|
3889
3943
|
import { z } from "zod";
|
|
3890
|
-
var VERSION = "0.
|
|
3944
|
+
var VERSION = "0.3.0";
|
|
3891
3945
|
export {
|
|
3892
3946
|
AuthenticationError,
|
|
3893
3947
|
AutoMLClient,
|