cencori 1.8.3 → 1.9.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/README.md +1 -1
- package/dist/ai/index.d.mts +14 -1
- package/dist/ai/index.d.ts +14 -1
- package/dist/ai/index.js +43 -3
- package/dist/ai/index.js.map +1 -1
- package/dist/ai/index.mjs +43 -3
- package/dist/ai/index.mjs.map +1 -1
- package/dist/compute/index.d.mts +1 -1
- package/dist/compute/index.d.ts +1 -1
- package/dist/documents/index.d.mts +1 -1
- package/dist/documents/index.d.ts +1 -1
- package/dist/index.d.mts +50 -9
- package/dist/index.d.ts +50 -9
- package/dist/index.js +67 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +67 -13
- package/dist/index.mjs.map +1 -1
- package/dist/judgment/index.d.mts +1 -1
- package/dist/judgment/index.d.ts +1 -1
- package/dist/memory/index.d.mts +1 -1
- package/dist/memory/index.d.ts +1 -1
- package/dist/storage/index.d.mts +5 -7
- package/dist/storage/index.d.ts +5 -7
- package/dist/storage/index.js +6 -8
- package/dist/storage/index.js.map +1 -1
- package/dist/storage/index.mjs +6 -8
- package/dist/storage/index.mjs.map +1 -1
- package/dist/telemetry/index.d.mts +1 -1
- package/dist/telemetry/index.d.ts +1 -1
- package/dist/{types-CAhDuNTz.d.mts → types-D91o22Gb.d.mts} +28 -1
- package/dist/{types-CAhDuNTz.d.ts → types-D91o22Gb.d.ts} +28 -1
- package/dist/vision/index.d.mts +1 -1
- package/dist/vision/index.d.ts +1 -1
- package/dist/voice/index.d.mts +1 -1
- package/dist/voice/index.d.ts +1 -1
- package/dist/web/index.d.mts +1 -1
- package/dist/web/index.d.ts +1 -1
- package/dist/workflow/index.d.mts +1 -1
- package/dist/workflow/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -128,6 +128,25 @@ function throwCencoriError(response, body) {
|
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
// src/ai/index.ts
|
|
131
|
+
function toKnowledgeCitations(raw) {
|
|
132
|
+
return (raw ?? []).map((c) => ({
|
|
133
|
+
n: c.n,
|
|
134
|
+
chunkId: c.chunk_id,
|
|
135
|
+
sourceId: c.source_id,
|
|
136
|
+
ord: c.ord ?? null,
|
|
137
|
+
page: c.page ?? null,
|
|
138
|
+
score: c.score
|
|
139
|
+
}));
|
|
140
|
+
}
|
|
141
|
+
function citationsFromHeader(response) {
|
|
142
|
+
const raw = response.headers.get("X-Cencori-Knowledge-Citations");
|
|
143
|
+
if (!raw) return void 0;
|
|
144
|
+
try {
|
|
145
|
+
return toKnowledgeCitations(JSON.parse(raw));
|
|
146
|
+
} catch {
|
|
147
|
+
return void 0;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
131
150
|
var AINamespace = class {
|
|
132
151
|
constructor(config) {
|
|
133
152
|
this.config = config;
|
|
@@ -157,7 +176,8 @@ var AINamespace = class {
|
|
|
157
176
|
stream: false,
|
|
158
177
|
tools: request2.tools,
|
|
159
178
|
toolChoice: request2.toolChoice,
|
|
160
|
-
prompt: request2.prompt
|
|
179
|
+
prompt: request2.prompt,
|
|
180
|
+
knowledgeBases: request2.knowledgeBases
|
|
161
181
|
})
|
|
162
182
|
});
|
|
163
183
|
if (!response.ok) {
|
|
@@ -189,7 +209,13 @@ var AINamespace = class {
|
|
|
189
209
|
costUsd: data.cost_usd,
|
|
190
210
|
provider: data.provider,
|
|
191
211
|
requestId: response.headers.get("X-Request-Id"),
|
|
192
|
-
safety: data.safety
|
|
212
|
+
safety: data.safety,
|
|
213
|
+
...data.knowledge ? {
|
|
214
|
+
knowledge: {
|
|
215
|
+
knowledgeBases: data.knowledge.knowledge_bases,
|
|
216
|
+
citations: toKnowledgeCitations(data.knowledge.citations)
|
|
217
|
+
}
|
|
218
|
+
} : {}
|
|
193
219
|
};
|
|
194
220
|
}
|
|
195
221
|
/**
|
|
@@ -217,7 +243,8 @@ var AINamespace = class {
|
|
|
217
243
|
stream: true,
|
|
218
244
|
tools: request2.tools,
|
|
219
245
|
toolChoice: request2.toolChoice,
|
|
220
|
-
prompt: request2.prompt
|
|
246
|
+
prompt: request2.prompt,
|
|
247
|
+
knowledgeBases: request2.knowledgeBases
|
|
221
248
|
})
|
|
222
249
|
});
|
|
223
250
|
if (!response.ok) {
|
|
@@ -230,6 +257,7 @@ var AINamespace = class {
|
|
|
230
257
|
const reader = response.body.getReader();
|
|
231
258
|
const decoder = new TextDecoder();
|
|
232
259
|
let buffer = "";
|
|
260
|
+
let citations = citationsFromHeader(response);
|
|
233
261
|
try {
|
|
234
262
|
while (true) {
|
|
235
263
|
const { done, value } = await reader.read();
|
|
@@ -246,6 +274,10 @@ var AINamespace = class {
|
|
|
246
274
|
}
|
|
247
275
|
try {
|
|
248
276
|
const chunk = JSON.parse(data);
|
|
277
|
+
if (citations) {
|
|
278
|
+
chunk.citations = citations;
|
|
279
|
+
citations = void 0;
|
|
280
|
+
}
|
|
249
281
|
yield chunk;
|
|
250
282
|
} catch {
|
|
251
283
|
}
|
|
@@ -428,6 +460,10 @@ var AINamespace = class {
|
|
|
428
460
|
};
|
|
429
461
|
}
|
|
430
462
|
/**
|
|
463
|
+
* @deprecated `/api/ai/rag` is not available on the hosted gateway. Use
|
|
464
|
+
* knowledge bases instead: `cencori.ai.chat({ model, messages,
|
|
465
|
+
* knowledgeBases: ['kb_...'] })` returns the answer with citations.
|
|
466
|
+
*
|
|
431
467
|
* RAG (Retrieval-Augmented Generation) - Chat with automatic memory context
|
|
432
468
|
*
|
|
433
469
|
* Searches your memory namespace for relevant context and includes it
|
|
@@ -624,6 +660,10 @@ var AINamespace = class {
|
|
|
624
660
|
}
|
|
625
661
|
}
|
|
626
662
|
/**
|
|
663
|
+
* @deprecated `/api/ai/rag` is not available on the hosted gateway. Use
|
|
664
|
+
* `cencori.ai.chatStream({ ..., knowledgeBases: ['kb_...'] })`; the first
|
|
665
|
+
* chunk carries `citations`.
|
|
666
|
+
*
|
|
627
667
|
* Stream RAG responses with automatic memory context
|
|
628
668
|
*
|
|
629
669
|
* @example
|
|
@@ -1289,23 +1329,21 @@ var VectorsNamespace = class {
|
|
|
1289
1329
|
};
|
|
1290
1330
|
var KnowledgeNamespace = class {
|
|
1291
1331
|
/**
|
|
1292
|
-
*
|
|
1293
|
-
*
|
|
1294
|
-
* 🚧 Coming Soon - This feature is not yet available.
|
|
1332
|
+
* @deprecated Never implemented. Use `cencori.knowledge.search()`, or
|
|
1333
|
+
* ground a chat with `cencori.ai.chat({ knowledgeBases: [...] })`.
|
|
1295
1334
|
*/
|
|
1296
1335
|
async query(question) {
|
|
1297
1336
|
throw new Error(
|
|
1298
|
-
`cencori.storage.knowledge.query() is
|
|
1337
|
+
`cencori.storage.knowledge.query() is not available. Use cencori.knowledge.search(kbId, { query }), or cencori.ai.chat({ knowledgeBases: [kbId], ... }).`
|
|
1299
1338
|
);
|
|
1300
1339
|
}
|
|
1301
1340
|
/**
|
|
1302
|
-
*
|
|
1303
|
-
*
|
|
1304
|
-
* 🚧 Coming Soon - This feature is not yet available.
|
|
1341
|
+
* @deprecated Never implemented. Use `cencori.knowledge.addInlineSource()`
|
|
1342
|
+
* or `cencori.knowledge.addFileSource()`.
|
|
1305
1343
|
*/
|
|
1306
1344
|
async add(documents) {
|
|
1307
1345
|
throw new Error(
|
|
1308
|
-
`cencori.storage.knowledge.add() is
|
|
1346
|
+
`cencori.storage.knowledge.add() is not available. Use cencori.knowledge.addInlineSource(kbId, text) or cencori.knowledge.addFileSource(kbId, file).`
|
|
1309
1347
|
);
|
|
1310
1348
|
}
|
|
1311
1349
|
};
|
|
@@ -2074,16 +2112,17 @@ function parseRetryAfterSeconds(value, nowMs = Date.now()) {
|
|
|
2074
2112
|
return Math.max(0, Math.ceil((timestamp - nowMs) / 1e3));
|
|
2075
2113
|
}
|
|
2076
2114
|
async function request(config, method, path, body, extraHeaders, options) {
|
|
2115
|
+
const isForm = typeof FormData !== "undefined" && body instanceof FormData;
|
|
2077
2116
|
const response = await fetch(`${config.baseUrl}${path}`, {
|
|
2078
2117
|
method,
|
|
2079
2118
|
signal: options?.signal,
|
|
2080
2119
|
headers: {
|
|
2081
2120
|
"CENCORI_API_KEY": config.apiKey,
|
|
2082
|
-
"Content-Type": "application/json",
|
|
2121
|
+
...isForm ? {} : { "Content-Type": "application/json" },
|
|
2083
2122
|
...config.headers,
|
|
2084
2123
|
...extraHeaders
|
|
2085
2124
|
},
|
|
2086
|
-
body: body ? JSON.stringify(body) : void 0
|
|
2125
|
+
body: isForm ? body : body ? JSON.stringify(body) : void 0
|
|
2087
2126
|
});
|
|
2088
2127
|
if (!response.ok) {
|
|
2089
2128
|
const errorData = await response.json().catch(() => ({ error: "Unknown error" }));
|
|
@@ -2333,6 +2372,21 @@ var KnowledgeNamespace2 = class {
|
|
|
2333
2372
|
addInlineSource(kbId, text, metadata) {
|
|
2334
2373
|
return request(this.config, "POST", `/v1/knowledge-bases/${kbId}/sources`, { text, metadata });
|
|
2335
2374
|
}
|
|
2375
|
+
/**
|
|
2376
|
+
* Upload a file (PDF, DOCX, Markdown, HTML, CSV, JSON or plain text, up
|
|
2377
|
+
* to 8MB). It is extracted, chunked and embedded server-side.
|
|
2378
|
+
*
|
|
2379
|
+
* @example
|
|
2380
|
+
* const pdf = new Blob([await fs.readFile('handbook.pdf')], { type: 'application/pdf' });
|
|
2381
|
+
* await cencori.knowledge.addFileSource(kb.id, pdf, { filename: 'handbook.pdf' });
|
|
2382
|
+
*/
|
|
2383
|
+
addFileSource(kbId, file, options) {
|
|
2384
|
+
const form = new FormData();
|
|
2385
|
+
const filename = options?.filename ?? file.name ?? "upload";
|
|
2386
|
+
form.append("file", file, filename);
|
|
2387
|
+
if (options?.metadata) form.append("metadata", JSON.stringify(options.metadata));
|
|
2388
|
+
return request(this.config, "POST", `/v1/knowledge-bases/${kbId}/sources`, form);
|
|
2389
|
+
}
|
|
2336
2390
|
listSources(kbId) {
|
|
2337
2391
|
return request(this.config, "GET", `/v1/knowledge-bases/${kbId}/sources`);
|
|
2338
2392
|
}
|