cencori 1.8.3 → 1.10.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.
Files changed (48) hide show
  1. package/README.md +89 -1
  2. package/dist/agents/index.d.mts +433 -0
  3. package/dist/agents/index.d.ts +433 -0
  4. package/dist/agents/index.js +897 -0
  5. package/dist/agents/index.js.map +1 -0
  6. package/dist/agents/index.mjs +870 -0
  7. package/dist/agents/index.mjs.map +1 -0
  8. package/dist/ai/index.d.mts +14 -1
  9. package/dist/ai/index.d.ts +14 -1
  10. package/dist/ai/index.js +43 -3
  11. package/dist/ai/index.js.map +1 -1
  12. package/dist/ai/index.mjs +43 -3
  13. package/dist/ai/index.mjs.map +1 -1
  14. package/dist/compute/index.d.mts +1 -1
  15. package/dist/compute/index.d.ts +1 -1
  16. package/dist/documents/index.d.mts +1 -1
  17. package/dist/documents/index.d.ts +1 -1
  18. package/dist/index.d.mts +50 -9
  19. package/dist/index.d.ts +50 -9
  20. package/dist/index.js +67 -13
  21. package/dist/index.js.map +1 -1
  22. package/dist/index.mjs +67 -13
  23. package/dist/index.mjs.map +1 -1
  24. package/dist/judgment/index.d.mts +1 -1
  25. package/dist/judgment/index.d.ts +1 -1
  26. package/dist/memory/index.d.mts +1 -1
  27. package/dist/memory/index.d.ts +1 -1
  28. package/dist/react/index.d.mts +6 -6
  29. package/dist/react/index.d.ts +6 -6
  30. package/dist/storage/index.d.mts +5 -7
  31. package/dist/storage/index.d.ts +5 -7
  32. package/dist/storage/index.js +6 -8
  33. package/dist/storage/index.js.map +1 -1
  34. package/dist/storage/index.mjs +6 -8
  35. package/dist/storage/index.mjs.map +1 -1
  36. package/dist/telemetry/index.d.mts +1 -1
  37. package/dist/telemetry/index.d.ts +1 -1
  38. package/dist/{types-CAhDuNTz.d.mts → types-D91o22Gb.d.mts} +28 -1
  39. package/dist/{types-CAhDuNTz.d.ts → types-D91o22Gb.d.ts} +28 -1
  40. package/dist/vision/index.d.mts +1 -1
  41. package/dist/vision/index.d.ts +1 -1
  42. package/dist/voice/index.d.mts +1 -1
  43. package/dist/voice/index.d.ts +1 -1
  44. package/dist/web/index.d.mts +1 -1
  45. package/dist/web/index.d.ts +1 -1
  46. package/dist/workflow/index.d.mts +1 -1
  47. package/dist/workflow/index.d.ts +1 -1
  48. package/package.json +11 -3
package/dist/index.js CHANGED
@@ -201,6 +201,25 @@ function throwCencoriError(response, body) {
201
201
  }
202
202
 
203
203
  // src/ai/index.ts
204
+ function toKnowledgeCitations(raw) {
205
+ return (raw ?? []).map((c) => ({
206
+ n: c.n,
207
+ chunkId: c.chunk_id,
208
+ sourceId: c.source_id,
209
+ ord: c.ord ?? null,
210
+ page: c.page ?? null,
211
+ score: c.score
212
+ }));
213
+ }
214
+ function citationsFromHeader(response) {
215
+ const raw = response.headers.get("X-Cencori-Knowledge-Citations");
216
+ if (!raw) return void 0;
217
+ try {
218
+ return toKnowledgeCitations(JSON.parse(raw));
219
+ } catch {
220
+ return void 0;
221
+ }
222
+ }
204
223
  var AINamespace = class {
205
224
  constructor(config) {
206
225
  this.config = config;
@@ -230,7 +249,8 @@ var AINamespace = class {
230
249
  stream: false,
231
250
  tools: request2.tools,
232
251
  toolChoice: request2.toolChoice,
233
- prompt: request2.prompt
252
+ prompt: request2.prompt,
253
+ knowledgeBases: request2.knowledgeBases
234
254
  })
235
255
  });
236
256
  if (!response.ok) {
@@ -262,7 +282,13 @@ var AINamespace = class {
262
282
  costUsd: data.cost_usd,
263
283
  provider: data.provider,
264
284
  requestId: response.headers.get("X-Request-Id"),
265
- safety: data.safety
285
+ safety: data.safety,
286
+ ...data.knowledge ? {
287
+ knowledge: {
288
+ knowledgeBases: data.knowledge.knowledge_bases,
289
+ citations: toKnowledgeCitations(data.knowledge.citations)
290
+ }
291
+ } : {}
266
292
  };
267
293
  }
268
294
  /**
@@ -290,7 +316,8 @@ var AINamespace = class {
290
316
  stream: true,
291
317
  tools: request2.tools,
292
318
  toolChoice: request2.toolChoice,
293
- prompt: request2.prompt
319
+ prompt: request2.prompt,
320
+ knowledgeBases: request2.knowledgeBases
294
321
  })
295
322
  });
296
323
  if (!response.ok) {
@@ -303,6 +330,7 @@ var AINamespace = class {
303
330
  const reader = response.body.getReader();
304
331
  const decoder = new TextDecoder();
305
332
  let buffer = "";
333
+ let citations = citationsFromHeader(response);
306
334
  try {
307
335
  while (true) {
308
336
  const { done, value } = await reader.read();
@@ -319,6 +347,10 @@ var AINamespace = class {
319
347
  }
320
348
  try {
321
349
  const chunk = JSON.parse(data);
350
+ if (citations) {
351
+ chunk.citations = citations;
352
+ citations = void 0;
353
+ }
322
354
  yield chunk;
323
355
  } catch {
324
356
  }
@@ -501,6 +533,10 @@ var AINamespace = class {
501
533
  };
502
534
  }
503
535
  /**
536
+ * @deprecated `/api/ai/rag` is not available on the hosted gateway. Use
537
+ * knowledge bases instead: `cencori.ai.chat({ model, messages,
538
+ * knowledgeBases: ['kb_...'] })` returns the answer with citations.
539
+ *
504
540
  * RAG (Retrieval-Augmented Generation) - Chat with automatic memory context
505
541
  *
506
542
  * Searches your memory namespace for relevant context and includes it
@@ -697,6 +733,10 @@ var AINamespace = class {
697
733
  }
698
734
  }
699
735
  /**
736
+ * @deprecated `/api/ai/rag` is not available on the hosted gateway. Use
737
+ * `cencori.ai.chatStream({ ..., knowledgeBases: ['kb_...'] })`; the first
738
+ * chunk carries `citations`.
739
+ *
700
740
  * Stream RAG responses with automatic memory context
701
741
  *
702
742
  * @example
@@ -1362,23 +1402,21 @@ var VectorsNamespace = class {
1362
1402
  };
1363
1403
  var KnowledgeNamespace = class {
1364
1404
  /**
1365
- * Query the knowledge base
1366
- *
1367
- * 🚧 Coming Soon - This feature is not yet available.
1405
+ * @deprecated Never implemented. Use `cencori.knowledge.search()`, or
1406
+ * ground a chat with `cencori.ai.chat({ knowledgeBases: [...] })`.
1368
1407
  */
1369
1408
  async query(question) {
1370
1409
  throw new Error(
1371
- `cencori.storage.knowledge.query() is coming soon! Join our waitlist at https://cencori.com/memory`
1410
+ `cencori.storage.knowledge.query() is not available. Use cencori.knowledge.search(kbId, { query }), or cencori.ai.chat({ knowledgeBases: [kbId], ... }).`
1372
1411
  );
1373
1412
  }
1374
1413
  /**
1375
- * Add documents to knowledge base
1376
- *
1377
- * 🚧 Coming Soon - This feature is not yet available.
1414
+ * @deprecated Never implemented. Use `cencori.knowledge.addInlineSource()`
1415
+ * or `cencori.knowledge.addFileSource()`.
1378
1416
  */
1379
1417
  async add(documents) {
1380
1418
  throw new Error(
1381
- `cencori.storage.knowledge.add() is coming soon! Join our waitlist at https://cencori.com/memory`
1419
+ `cencori.storage.knowledge.add() is not available. Use cencori.knowledge.addInlineSource(kbId, text) or cencori.knowledge.addFileSource(kbId, file).`
1382
1420
  );
1383
1421
  }
1384
1422
  };
@@ -2147,16 +2185,17 @@ function parseRetryAfterSeconds(value, nowMs = Date.now()) {
2147
2185
  return Math.max(0, Math.ceil((timestamp - nowMs) / 1e3));
2148
2186
  }
2149
2187
  async function request(config, method, path, body, extraHeaders, options) {
2188
+ const isForm = typeof FormData !== "undefined" && body instanceof FormData;
2150
2189
  const response = await fetch(`${config.baseUrl}${path}`, {
2151
2190
  method,
2152
2191
  signal: options?.signal,
2153
2192
  headers: {
2154
2193
  "CENCORI_API_KEY": config.apiKey,
2155
- "Content-Type": "application/json",
2194
+ ...isForm ? {} : { "Content-Type": "application/json" },
2156
2195
  ...config.headers,
2157
2196
  ...extraHeaders
2158
2197
  },
2159
- body: body ? JSON.stringify(body) : void 0
2198
+ body: isForm ? body : body ? JSON.stringify(body) : void 0
2160
2199
  });
2161
2200
  if (!response.ok) {
2162
2201
  const errorData = await response.json().catch(() => ({ error: "Unknown error" }));
@@ -2406,6 +2445,21 @@ var KnowledgeNamespace2 = class {
2406
2445
  addInlineSource(kbId, text, metadata) {
2407
2446
  return request(this.config, "POST", `/v1/knowledge-bases/${kbId}/sources`, { text, metadata });
2408
2447
  }
2448
+ /**
2449
+ * Upload a file (PDF, DOCX, Markdown, HTML, CSV, JSON or plain text, up
2450
+ * to 8MB). It is extracted, chunked and embedded server-side.
2451
+ *
2452
+ * @example
2453
+ * const pdf = new Blob([await fs.readFile('handbook.pdf')], { type: 'application/pdf' });
2454
+ * await cencori.knowledge.addFileSource(kb.id, pdf, { filename: 'handbook.pdf' });
2455
+ */
2456
+ addFileSource(kbId, file, options) {
2457
+ const form = new FormData();
2458
+ const filename = options?.filename ?? file.name ?? "upload";
2459
+ form.append("file", file, filename);
2460
+ if (options?.metadata) form.append("metadata", JSON.stringify(options.metadata));
2461
+ return request(this.config, "POST", `/v1/knowledge-bases/${kbId}/sources`, form);
2462
+ }
2409
2463
  listSources(kbId) {
2410
2464
  return request(this.config, "GET", `/v1/knowledge-bases/${kbId}/sources`);
2411
2465
  }