cencori 1.4.0 → 1.5.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 CHANGED
@@ -170,6 +170,31 @@ import { VisionUploader } from 'cencori/react';
170
170
 
171
171
  Full API in [docs](https://cencori.com/docs/ai/endpoints/vision).
172
172
 
173
+ ### Documents (PDF & Image Extraction)
174
+
175
+ Extract text from PDFs and images, summarize documents, and answer questions about them. Text-based PDFs use native parsing — no LLM tokens, free.
176
+
177
+ ```typescript
178
+ // Extract text — native PDF parsing, free
179
+ const { text, method } = await cencori.documents.extract({
180
+ document: { url: 'https://example.com/contract.pdf' },
181
+ });
182
+ console.log(method); // 'pdf_text' means free
183
+
184
+ // Summarize
185
+ const { summary } = await cencori.documents.summarize({
186
+ document: { url: 'https://example.com/report.pdf' },
187
+ });
188
+
189
+ // Q&A — strict "Not found" if the answer isn't in the doc
190
+ const { answer } = await cencori.documents.query({
191
+ document: { url: 'https://example.com/contract.pdf' },
192
+ question: 'What is the termination clause?',
193
+ });
194
+ ```
195
+
196
+ Full API in [docs](https://cencori.com/docs/ai/endpoints/documents). See the [Contract Analyzer tutorial](https://cencori.com/docs/guides/build-a-contract-analyzer) for an end-to-end example.
197
+
173
198
  ### Image Generation
174
199
 
175
200
  Generate images from text prompts using multiple providers:
package/dist/index.d.mts CHANGED
@@ -4,14 +4,19 @@ import { AINamespace } from './ai/index.mjs';
4
4
  export { StreamChunk } from './ai/index.mjs';
5
5
  import { VisionNamespace } from './vision/index.mjs';
6
6
  export { VisionClassification, VisionClassifyResult, VisionCost, VisionDescribeResult, VisionImage, VisionOcrResult, VisionProvider, VisionRequest, VisionResult, VisionStreamChunk, VisionTask, VisionUsage } from './vision/index.mjs';
7
+ import { VoiceNamespace } from './voice/index.mjs';
8
+ export { AudioFormat, AudioInput, STTProvider, SpeakRequest, SpeakResult, TTSProvider, TranscribeRequest, TranscribeResult, TranscriptFormat, TranscriptSegment, TranscriptWord, VoiceModelInfo } from './voice/index.mjs';
7
9
  import { DocumentsNamespace } from './documents/index.mjs';
8
10
  export { DocumentCost, DocumentExtractMethod, DocumentExtractResult, DocumentInput, DocumentKind, DocumentQueryRequest, DocumentQueryResult, DocumentRequest, DocumentSummarizeResult, DocumentUsage } from './documents/index.mjs';
9
11
  import { ComputeNamespace } from './compute/index.mjs';
10
12
  import { WorkflowNamespace } from './workflow/index.mjs';
11
13
  import { StorageNamespace } from './storage/index.mjs';
12
14
  import { MemoryClient } from './memory/index.mjs';
15
+ export { EntitiesResult, FetchedMemory, ForgetSuggestionsOptions, ForgetSuggestionsResult, GraphQueryOptions, GraphResult, ListEntitiesOptions, MEMORY_FETCH_TOOL, RecallOptions, RememberGraphOptions, RememberGraphResult, SearchScopedMemoryOptions } from './memory/index.mjs';
13
16
  import { TelemetryClient } from './telemetry/index.mjs';
14
17
  export { WebTelemetryPayload } from './telemetry/index.mjs';
18
+ import { WebNamespace } from './web/index.mjs';
19
+ export { WEB_FETCH_TOOL, WEB_SEARCH_TOOL, WebCrawlRequest, WebCrawlResponse, WebEvidenceSpan, WebExtractResult, WebFetchRequest, WebFetchResult, WebLink, WebSearchHit, WebSearchRequest, WebSearchResponse } from './web/index.mjs';
15
20
  export { CencoriChatSettings, CencoriProvider, CencoriProviderSettings, cencori, createCencori } from './vercel/index.mjs';
16
21
  import '@ai-sdk/provider';
17
22
 
@@ -180,6 +185,131 @@ declare class SessionsNamespace {
180
185
  }>;
181
186
  }
182
187
 
188
+ /**
189
+ * Cencori Chat namespace — OpenAI-compatible chat completions with
190
+ * gateway-level memory.
191
+ *
192
+ * The magic path: one line makes chat stateful.
193
+ *
194
+ * @example
195
+ * ```typescript
196
+ * const response = await cencori.chat.completions.create({
197
+ * model: 'gpt-4o',
198
+ * messages: [{ role: 'user', content: 'What did we agree about pricing?' }],
199
+ * memory: { userId: session.user.id },
200
+ * });
201
+ * console.log(response.choices[0].message.content);
202
+ * console.log(response.memory?.retrieved); // facts injected into this reply
203
+ * ```
204
+ */
205
+
206
+ interface ChatMemoryOptions {
207
+ userId?: string;
208
+ sessionId?: string;
209
+ scope?: 'session' | 'user';
210
+ retrieve?: boolean;
211
+ write?: boolean;
212
+ topK?: number;
213
+ threshold?: number;
214
+ namespace?: string;
215
+ /**
216
+ * Temporal recall: retrieve memory as it was valid at this instant
217
+ * (ISO 8601), including facts later superseded. Omit for current state.
218
+ */
219
+ asOf?: string;
220
+ /**
221
+ * How recalled memories are surfaced to the model:
222
+ * - 'inject' (default): full memory contents in context.
223
+ * - 'index': a compact table of contents (id + summary); the model fetches
224
+ * a full note on demand via GET /v1/memory/:id. Best for agents — avoids
225
+ * burying the signal under full-text every turn.
226
+ */
227
+ mode?: 'inject' | 'index';
228
+ extract?: {
229
+ model?: string;
230
+ prompt?: string;
231
+ minImportance?: number;
232
+ };
233
+ }
234
+ interface ChatCompletionMessage {
235
+ role: 'system' | 'user' | 'assistant' | 'tool';
236
+ content: string;
237
+ }
238
+ interface ChatCompletionCreateParams {
239
+ model: string;
240
+ messages: ChatCompletionMessage[];
241
+ temperature?: number;
242
+ max_tokens?: number;
243
+ user?: string;
244
+ memory?: ChatMemoryOptions;
245
+ tools?: unknown[];
246
+ tool_choice?: unknown;
247
+ prompt?: {
248
+ name: string;
249
+ variables?: Record<string, string>;
250
+ };
251
+ }
252
+ interface ChatCompletionResponse {
253
+ id: string;
254
+ object: string;
255
+ created: number;
256
+ model: string;
257
+ choices: Array<{
258
+ index: number;
259
+ message: {
260
+ role: string;
261
+ content: string;
262
+ tool_calls?: unknown[];
263
+ };
264
+ finish_reason: string;
265
+ }>;
266
+ usage?: {
267
+ prompt_tokens: number;
268
+ completion_tokens: number;
269
+ total_tokens: number;
270
+ };
271
+ memory?: {
272
+ retrieved: Array<{
273
+ id: string;
274
+ score: number;
275
+ content: string;
276
+ }>;
277
+ written: Array<{
278
+ id: string;
279
+ content: string;
280
+ }>;
281
+ write_status: 'pending' | 'disabled';
282
+ };
283
+ }
284
+ interface ChatCompletionChunk {
285
+ delta: string;
286
+ raw: Record<string, unknown>;
287
+ }
288
+ interface ChatCompletionStream extends AsyncIterable<ChatCompletionChunk> {
289
+ /** Number of memories injected into this request (from X-Cencori-Memory-Retrieved). */
290
+ memoriesRetrieved: number;
291
+ }
292
+ declare class Completions {
293
+ private config;
294
+ constructor(config: Required<CencoriConfig>);
295
+ private endpoint;
296
+ private headers;
297
+ /**
298
+ * Create a chat completion. Include `memory: { userId }` to retrieve
299
+ * relevant facts before the model call and persist new ones after it.
300
+ */
301
+ create(params: ChatCompletionCreateParams): Promise<ChatCompletionResponse>;
302
+ /**
303
+ * Stream a chat completion (SSE). Memory writeback still runs after the
304
+ * stream completes; `memoriesRetrieved` reports the injected count.
305
+ */
306
+ stream(params: ChatCompletionCreateParams): Promise<ChatCompletionStream>;
307
+ }
308
+ declare class ChatNamespace {
309
+ readonly completions: Completions;
310
+ constructor(config: Required<CencoriConfig>);
311
+ }
312
+
183
313
  /**
184
314
  * Cencori - Unified AI Infrastructure SDK
185
315
  *
@@ -216,6 +346,18 @@ declare class Cencori {
216
346
  * await cencori.ai.chat({ model: 'gpt-4o', messages: [...] });
217
347
  */
218
348
  readonly ai: AINamespace;
349
+ /**
350
+ * Chat - OpenAI-compatible chat completions with gateway memory.
351
+ * One line makes chat stateful.
352
+ *
353
+ * @example
354
+ * const response = await cencori.chat.completions.create({
355
+ * model: 'gpt-4o',
356
+ * messages: [{ role: 'user', content: 'What did we agree about pricing?' }],
357
+ * memory: { userId: session.user.id },
358
+ * });
359
+ */
360
+ readonly chat: ChatNamespace;
219
361
  /**
220
362
  * Vision - Analyze, describe, OCR, and classify images
221
363
  *
@@ -231,6 +373,28 @@ declare class Cencori {
231
373
  * });
232
374
  */
233
375
  readonly vision: VisionNamespace;
376
+ /**
377
+ * Voice - Text-to-speech and speech-to-text across providers
378
+ *
379
+ * @example
380
+ * const { audio } = await cencori.voice.speak({
381
+ * input: 'Hello from Cencori.',
382
+ * model: 'aura-asteria-en', // Deepgram; provider inferred from model
383
+ * });
384
+ *
385
+ * @example
386
+ * const { text } = await cencori.voice.transcribe({
387
+ * audio: fileBytes,
388
+ * model: 'nova-3',
389
+ * });
390
+ *
391
+ * @example
392
+ * const { segments } = await cencori.voice.diarize({
393
+ * audio: fileBytes,
394
+ * model: 'assemblyai-universal',
395
+ * });
396
+ */
397
+ readonly voice: VoiceNamespace;
234
398
  /**
235
399
  * Documents - Extract text from PDFs and images, summarize, and query
236
400
  *
@@ -320,6 +484,14 @@ declare class Cencori {
320
484
  * });
321
485
  */
322
486
  readonly telemetry: TelemetryClient;
487
+ /**
488
+ * Web - First-party retrieval, extraction, crawling, and search.
489
+ *
490
+ * @example
491
+ * await cencori.web.crawl({ seeds: ['https://docs.example.com'], maxPages: 10 });
492
+ * const results = await cencori.web.search({ query: 'authentication guide' });
493
+ */
494
+ readonly web: WebNamespace;
323
495
  /**
324
496
  * Create a new Cencori client
325
497
  *
@@ -391,4 +563,4 @@ declare class SafetyError extends CencoriError {
391
563
  */
392
564
  declare function fetchWithRetry(url: string, options: RequestInit, maxRetries?: number): Promise<Response>;
393
565
 
394
- export { AINamespace, type Agent, type AgentConfig, type AgentKey, type AgentListItem, AgentsNamespace, AuthenticationError, Cencori, CencoriConfig, CencoriError, ComputeNamespace, type CreateAgentKeyParams, type CreateAgentParams, type CreateSessionParams, DocumentsNamespace, MemoryClient, type PaginatedResponse, RateLimitError, RequestOptions, SafetyError, type Session, type SessionEvent, type SessionListParams, SessionsNamespace, StorageNamespace, TelemetryClient, type TurnParams, type UpdateAgentParams, VisionNamespace, WorkflowNamespace, Cencori as default, fetchWithRetry };
566
+ export { AINamespace, type Agent, type AgentConfig, type AgentKey, type AgentListItem, AgentsNamespace, AuthenticationError, Cencori, CencoriConfig, CencoriError, type ChatCompletionChunk, type ChatCompletionCreateParams, type ChatCompletionResponse, type ChatCompletionStream, type ChatMemoryOptions, ChatNamespace, ComputeNamespace, type CreateAgentKeyParams, type CreateAgentParams, type CreateSessionParams, DocumentsNamespace, MemoryClient, type PaginatedResponse, RateLimitError, RequestOptions, SafetyError, type Session, type SessionEvent, type SessionListParams, SessionsNamespace, StorageNamespace, TelemetryClient, type TurnParams, type UpdateAgentParams, VisionNamespace, VoiceNamespace, WebNamespace, WorkflowNamespace, Cencori as default, fetchWithRetry };
package/dist/index.d.ts CHANGED
@@ -4,14 +4,19 @@ import { AINamespace } from './ai/index.js';
4
4
  export { StreamChunk } from './ai/index.js';
5
5
  import { VisionNamespace } from './vision/index.js';
6
6
  export { VisionClassification, VisionClassifyResult, VisionCost, VisionDescribeResult, VisionImage, VisionOcrResult, VisionProvider, VisionRequest, VisionResult, VisionStreamChunk, VisionTask, VisionUsage } from './vision/index.js';
7
+ import { VoiceNamespace } from './voice/index.js';
8
+ export { AudioFormat, AudioInput, STTProvider, SpeakRequest, SpeakResult, TTSProvider, TranscribeRequest, TranscribeResult, TranscriptFormat, TranscriptSegment, TranscriptWord, VoiceModelInfo } from './voice/index.js';
7
9
  import { DocumentsNamespace } from './documents/index.js';
8
10
  export { DocumentCost, DocumentExtractMethod, DocumentExtractResult, DocumentInput, DocumentKind, DocumentQueryRequest, DocumentQueryResult, DocumentRequest, DocumentSummarizeResult, DocumentUsage } from './documents/index.js';
9
11
  import { ComputeNamespace } from './compute/index.js';
10
12
  import { WorkflowNamespace } from './workflow/index.js';
11
13
  import { StorageNamespace } from './storage/index.js';
12
14
  import { MemoryClient } from './memory/index.js';
15
+ export { EntitiesResult, FetchedMemory, ForgetSuggestionsOptions, ForgetSuggestionsResult, GraphQueryOptions, GraphResult, ListEntitiesOptions, MEMORY_FETCH_TOOL, RecallOptions, RememberGraphOptions, RememberGraphResult, SearchScopedMemoryOptions } from './memory/index.js';
13
16
  import { TelemetryClient } from './telemetry/index.js';
14
17
  export { WebTelemetryPayload } from './telemetry/index.js';
18
+ import { WebNamespace } from './web/index.js';
19
+ export { WEB_FETCH_TOOL, WEB_SEARCH_TOOL, WebCrawlRequest, WebCrawlResponse, WebEvidenceSpan, WebExtractResult, WebFetchRequest, WebFetchResult, WebLink, WebSearchHit, WebSearchRequest, WebSearchResponse } from './web/index.js';
15
20
  export { CencoriChatSettings, CencoriProvider, CencoriProviderSettings, cencori, createCencori } from './vercel/index.js';
16
21
  import '@ai-sdk/provider';
17
22
 
@@ -180,6 +185,131 @@ declare class SessionsNamespace {
180
185
  }>;
181
186
  }
182
187
 
188
+ /**
189
+ * Cencori Chat namespace — OpenAI-compatible chat completions with
190
+ * gateway-level memory.
191
+ *
192
+ * The magic path: one line makes chat stateful.
193
+ *
194
+ * @example
195
+ * ```typescript
196
+ * const response = await cencori.chat.completions.create({
197
+ * model: 'gpt-4o',
198
+ * messages: [{ role: 'user', content: 'What did we agree about pricing?' }],
199
+ * memory: { userId: session.user.id },
200
+ * });
201
+ * console.log(response.choices[0].message.content);
202
+ * console.log(response.memory?.retrieved); // facts injected into this reply
203
+ * ```
204
+ */
205
+
206
+ interface ChatMemoryOptions {
207
+ userId?: string;
208
+ sessionId?: string;
209
+ scope?: 'session' | 'user';
210
+ retrieve?: boolean;
211
+ write?: boolean;
212
+ topK?: number;
213
+ threshold?: number;
214
+ namespace?: string;
215
+ /**
216
+ * Temporal recall: retrieve memory as it was valid at this instant
217
+ * (ISO 8601), including facts later superseded. Omit for current state.
218
+ */
219
+ asOf?: string;
220
+ /**
221
+ * How recalled memories are surfaced to the model:
222
+ * - 'inject' (default): full memory contents in context.
223
+ * - 'index': a compact table of contents (id + summary); the model fetches
224
+ * a full note on demand via GET /v1/memory/:id. Best for agents — avoids
225
+ * burying the signal under full-text every turn.
226
+ */
227
+ mode?: 'inject' | 'index';
228
+ extract?: {
229
+ model?: string;
230
+ prompt?: string;
231
+ minImportance?: number;
232
+ };
233
+ }
234
+ interface ChatCompletionMessage {
235
+ role: 'system' | 'user' | 'assistant' | 'tool';
236
+ content: string;
237
+ }
238
+ interface ChatCompletionCreateParams {
239
+ model: string;
240
+ messages: ChatCompletionMessage[];
241
+ temperature?: number;
242
+ max_tokens?: number;
243
+ user?: string;
244
+ memory?: ChatMemoryOptions;
245
+ tools?: unknown[];
246
+ tool_choice?: unknown;
247
+ prompt?: {
248
+ name: string;
249
+ variables?: Record<string, string>;
250
+ };
251
+ }
252
+ interface ChatCompletionResponse {
253
+ id: string;
254
+ object: string;
255
+ created: number;
256
+ model: string;
257
+ choices: Array<{
258
+ index: number;
259
+ message: {
260
+ role: string;
261
+ content: string;
262
+ tool_calls?: unknown[];
263
+ };
264
+ finish_reason: string;
265
+ }>;
266
+ usage?: {
267
+ prompt_tokens: number;
268
+ completion_tokens: number;
269
+ total_tokens: number;
270
+ };
271
+ memory?: {
272
+ retrieved: Array<{
273
+ id: string;
274
+ score: number;
275
+ content: string;
276
+ }>;
277
+ written: Array<{
278
+ id: string;
279
+ content: string;
280
+ }>;
281
+ write_status: 'pending' | 'disabled';
282
+ };
283
+ }
284
+ interface ChatCompletionChunk {
285
+ delta: string;
286
+ raw: Record<string, unknown>;
287
+ }
288
+ interface ChatCompletionStream extends AsyncIterable<ChatCompletionChunk> {
289
+ /** Number of memories injected into this request (from X-Cencori-Memory-Retrieved). */
290
+ memoriesRetrieved: number;
291
+ }
292
+ declare class Completions {
293
+ private config;
294
+ constructor(config: Required<CencoriConfig>);
295
+ private endpoint;
296
+ private headers;
297
+ /**
298
+ * Create a chat completion. Include `memory: { userId }` to retrieve
299
+ * relevant facts before the model call and persist new ones after it.
300
+ */
301
+ create(params: ChatCompletionCreateParams): Promise<ChatCompletionResponse>;
302
+ /**
303
+ * Stream a chat completion (SSE). Memory writeback still runs after the
304
+ * stream completes; `memoriesRetrieved` reports the injected count.
305
+ */
306
+ stream(params: ChatCompletionCreateParams): Promise<ChatCompletionStream>;
307
+ }
308
+ declare class ChatNamespace {
309
+ readonly completions: Completions;
310
+ constructor(config: Required<CencoriConfig>);
311
+ }
312
+
183
313
  /**
184
314
  * Cencori - Unified AI Infrastructure SDK
185
315
  *
@@ -216,6 +346,18 @@ declare class Cencori {
216
346
  * await cencori.ai.chat({ model: 'gpt-4o', messages: [...] });
217
347
  */
218
348
  readonly ai: AINamespace;
349
+ /**
350
+ * Chat - OpenAI-compatible chat completions with gateway memory.
351
+ * One line makes chat stateful.
352
+ *
353
+ * @example
354
+ * const response = await cencori.chat.completions.create({
355
+ * model: 'gpt-4o',
356
+ * messages: [{ role: 'user', content: 'What did we agree about pricing?' }],
357
+ * memory: { userId: session.user.id },
358
+ * });
359
+ */
360
+ readonly chat: ChatNamespace;
219
361
  /**
220
362
  * Vision - Analyze, describe, OCR, and classify images
221
363
  *
@@ -231,6 +373,28 @@ declare class Cencori {
231
373
  * });
232
374
  */
233
375
  readonly vision: VisionNamespace;
376
+ /**
377
+ * Voice - Text-to-speech and speech-to-text across providers
378
+ *
379
+ * @example
380
+ * const { audio } = await cencori.voice.speak({
381
+ * input: 'Hello from Cencori.',
382
+ * model: 'aura-asteria-en', // Deepgram; provider inferred from model
383
+ * });
384
+ *
385
+ * @example
386
+ * const { text } = await cencori.voice.transcribe({
387
+ * audio: fileBytes,
388
+ * model: 'nova-3',
389
+ * });
390
+ *
391
+ * @example
392
+ * const { segments } = await cencori.voice.diarize({
393
+ * audio: fileBytes,
394
+ * model: 'assemblyai-universal',
395
+ * });
396
+ */
397
+ readonly voice: VoiceNamespace;
234
398
  /**
235
399
  * Documents - Extract text from PDFs and images, summarize, and query
236
400
  *
@@ -320,6 +484,14 @@ declare class Cencori {
320
484
  * });
321
485
  */
322
486
  readonly telemetry: TelemetryClient;
487
+ /**
488
+ * Web - First-party retrieval, extraction, crawling, and search.
489
+ *
490
+ * @example
491
+ * await cencori.web.crawl({ seeds: ['https://docs.example.com'], maxPages: 10 });
492
+ * const results = await cencori.web.search({ query: 'authentication guide' });
493
+ */
494
+ readonly web: WebNamespace;
323
495
  /**
324
496
  * Create a new Cencori client
325
497
  *
@@ -391,4 +563,4 @@ declare class SafetyError extends CencoriError {
391
563
  */
392
564
  declare function fetchWithRetry(url: string, options: RequestInit, maxRetries?: number): Promise<Response>;
393
565
 
394
- export { AINamespace, type Agent, type AgentConfig, type AgentKey, type AgentListItem, AgentsNamespace, AuthenticationError, Cencori, CencoriConfig, CencoriError, ComputeNamespace, type CreateAgentKeyParams, type CreateAgentParams, type CreateSessionParams, DocumentsNamespace, MemoryClient, type PaginatedResponse, RateLimitError, RequestOptions, SafetyError, type Session, type SessionEvent, type SessionListParams, SessionsNamespace, StorageNamespace, TelemetryClient, type TurnParams, type UpdateAgentParams, VisionNamespace, WorkflowNamespace, Cencori as default, fetchWithRetry };
566
+ export { AINamespace, type Agent, type AgentConfig, type AgentKey, type AgentListItem, AgentsNamespace, AuthenticationError, Cencori, CencoriConfig, CencoriError, type ChatCompletionChunk, type ChatCompletionCreateParams, type ChatCompletionResponse, type ChatCompletionStream, type ChatMemoryOptions, ChatNamespace, ComputeNamespace, type CreateAgentKeyParams, type CreateAgentParams, type CreateSessionParams, DocumentsNamespace, MemoryClient, type PaginatedResponse, RateLimitError, RequestOptions, SafetyError, type Session, type SessionEvent, type SessionListParams, SessionsNamespace, StorageNamespace, TelemetryClient, type TurnParams, type UpdateAgentParams, VisionNamespace, VoiceNamespace, WebNamespace, WorkflowNamespace, Cencori as default, fetchWithRetry };