cencori 1.4.0 → 1.4.1

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,6 +4,8 @@ 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';
@@ -180,6 +182,118 @@ declare class SessionsNamespace {
180
182
  }>;
181
183
  }
182
184
 
185
+ /**
186
+ * Cencori Chat namespace — OpenAI-compatible chat completions with
187
+ * gateway-level memory.
188
+ *
189
+ * The magic path: one line makes chat stateful.
190
+ *
191
+ * @example
192
+ * ```typescript
193
+ * const response = await cencori.chat.completions.create({
194
+ * model: 'gpt-4o',
195
+ * messages: [{ role: 'user', content: 'What did we agree about pricing?' }],
196
+ * memory: { userId: session.user.id },
197
+ * });
198
+ * console.log(response.choices[0].message.content);
199
+ * console.log(response.memory?.retrieved); // facts injected into this reply
200
+ * ```
201
+ */
202
+
203
+ interface ChatMemoryOptions {
204
+ userId?: string;
205
+ sessionId?: string;
206
+ scope?: 'session' | 'user';
207
+ retrieve?: boolean;
208
+ write?: boolean;
209
+ topK?: number;
210
+ threshold?: number;
211
+ namespace?: string;
212
+ extract?: {
213
+ model?: string;
214
+ prompt?: string;
215
+ minImportance?: number;
216
+ };
217
+ }
218
+ interface ChatCompletionMessage {
219
+ role: 'system' | 'user' | 'assistant' | 'tool';
220
+ content: string;
221
+ }
222
+ interface ChatCompletionCreateParams {
223
+ model: string;
224
+ messages: ChatCompletionMessage[];
225
+ temperature?: number;
226
+ max_tokens?: number;
227
+ user?: string;
228
+ memory?: ChatMemoryOptions;
229
+ tools?: unknown[];
230
+ tool_choice?: unknown;
231
+ prompt?: {
232
+ name: string;
233
+ variables?: Record<string, string>;
234
+ };
235
+ }
236
+ interface ChatCompletionResponse {
237
+ id: string;
238
+ object: string;
239
+ created: number;
240
+ model: string;
241
+ choices: Array<{
242
+ index: number;
243
+ message: {
244
+ role: string;
245
+ content: string;
246
+ tool_calls?: unknown[];
247
+ };
248
+ finish_reason: string;
249
+ }>;
250
+ usage?: {
251
+ prompt_tokens: number;
252
+ completion_tokens: number;
253
+ total_tokens: number;
254
+ };
255
+ memory?: {
256
+ retrieved: Array<{
257
+ id: string;
258
+ score: number;
259
+ content: string;
260
+ }>;
261
+ written: Array<{
262
+ id: string;
263
+ content: string;
264
+ }>;
265
+ write_status: 'pending' | 'disabled';
266
+ };
267
+ }
268
+ interface ChatCompletionChunk {
269
+ delta: string;
270
+ raw: Record<string, unknown>;
271
+ }
272
+ interface ChatCompletionStream extends AsyncIterable<ChatCompletionChunk> {
273
+ /** Number of memories injected into this request (from X-Cencori-Memory-Retrieved). */
274
+ memoriesRetrieved: number;
275
+ }
276
+ declare class Completions {
277
+ private config;
278
+ constructor(config: Required<CencoriConfig>);
279
+ private endpoint;
280
+ private headers;
281
+ /**
282
+ * Create a chat completion. Include `memory: { userId }` to retrieve
283
+ * relevant facts before the model call and persist new ones after it.
284
+ */
285
+ create(params: ChatCompletionCreateParams): Promise<ChatCompletionResponse>;
286
+ /**
287
+ * Stream a chat completion (SSE). Memory writeback still runs after the
288
+ * stream completes; `memoriesRetrieved` reports the injected count.
289
+ */
290
+ stream(params: ChatCompletionCreateParams): Promise<ChatCompletionStream>;
291
+ }
292
+ declare class ChatNamespace {
293
+ readonly completions: Completions;
294
+ constructor(config: Required<CencoriConfig>);
295
+ }
296
+
183
297
  /**
184
298
  * Cencori - Unified AI Infrastructure SDK
185
299
  *
@@ -216,6 +330,18 @@ declare class Cencori {
216
330
  * await cencori.ai.chat({ model: 'gpt-4o', messages: [...] });
217
331
  */
218
332
  readonly ai: AINamespace;
333
+ /**
334
+ * Chat - OpenAI-compatible chat completions with gateway memory.
335
+ * One line makes chat stateful.
336
+ *
337
+ * @example
338
+ * const response = await cencori.chat.completions.create({
339
+ * model: 'gpt-4o',
340
+ * messages: [{ role: 'user', content: 'What did we agree about pricing?' }],
341
+ * memory: { userId: session.user.id },
342
+ * });
343
+ */
344
+ readonly chat: ChatNamespace;
219
345
  /**
220
346
  * Vision - Analyze, describe, OCR, and classify images
221
347
  *
@@ -231,6 +357,28 @@ declare class Cencori {
231
357
  * });
232
358
  */
233
359
  readonly vision: VisionNamespace;
360
+ /**
361
+ * Voice - Text-to-speech and speech-to-text across providers
362
+ *
363
+ * @example
364
+ * const { audio } = await cencori.voice.speak({
365
+ * input: 'Hello from Cencori.',
366
+ * model: 'aura-asteria-en', // Deepgram; provider inferred from model
367
+ * });
368
+ *
369
+ * @example
370
+ * const { text } = await cencori.voice.transcribe({
371
+ * audio: fileBytes,
372
+ * model: 'nova-3',
373
+ * });
374
+ *
375
+ * @example
376
+ * const { segments } = await cencori.voice.diarize({
377
+ * audio: fileBytes,
378
+ * model: 'assemblyai-universal',
379
+ * });
380
+ */
381
+ readonly voice: VoiceNamespace;
234
382
  /**
235
383
  * Documents - Extract text from PDFs and images, summarize, and query
236
384
  *
@@ -391,4 +539,4 @@ declare class SafetyError extends CencoriError {
391
539
  */
392
540
  declare function fetchWithRetry(url: string, options: RequestInit, maxRetries?: number): Promise<Response>;
393
541
 
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 };
542
+ 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, WorkflowNamespace, Cencori as default, fetchWithRetry };
package/dist/index.d.ts CHANGED
@@ -4,6 +4,8 @@ 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';
@@ -180,6 +182,118 @@ declare class SessionsNamespace {
180
182
  }>;
181
183
  }
182
184
 
185
+ /**
186
+ * Cencori Chat namespace — OpenAI-compatible chat completions with
187
+ * gateway-level memory.
188
+ *
189
+ * The magic path: one line makes chat stateful.
190
+ *
191
+ * @example
192
+ * ```typescript
193
+ * const response = await cencori.chat.completions.create({
194
+ * model: 'gpt-4o',
195
+ * messages: [{ role: 'user', content: 'What did we agree about pricing?' }],
196
+ * memory: { userId: session.user.id },
197
+ * });
198
+ * console.log(response.choices[0].message.content);
199
+ * console.log(response.memory?.retrieved); // facts injected into this reply
200
+ * ```
201
+ */
202
+
203
+ interface ChatMemoryOptions {
204
+ userId?: string;
205
+ sessionId?: string;
206
+ scope?: 'session' | 'user';
207
+ retrieve?: boolean;
208
+ write?: boolean;
209
+ topK?: number;
210
+ threshold?: number;
211
+ namespace?: string;
212
+ extract?: {
213
+ model?: string;
214
+ prompt?: string;
215
+ minImportance?: number;
216
+ };
217
+ }
218
+ interface ChatCompletionMessage {
219
+ role: 'system' | 'user' | 'assistant' | 'tool';
220
+ content: string;
221
+ }
222
+ interface ChatCompletionCreateParams {
223
+ model: string;
224
+ messages: ChatCompletionMessage[];
225
+ temperature?: number;
226
+ max_tokens?: number;
227
+ user?: string;
228
+ memory?: ChatMemoryOptions;
229
+ tools?: unknown[];
230
+ tool_choice?: unknown;
231
+ prompt?: {
232
+ name: string;
233
+ variables?: Record<string, string>;
234
+ };
235
+ }
236
+ interface ChatCompletionResponse {
237
+ id: string;
238
+ object: string;
239
+ created: number;
240
+ model: string;
241
+ choices: Array<{
242
+ index: number;
243
+ message: {
244
+ role: string;
245
+ content: string;
246
+ tool_calls?: unknown[];
247
+ };
248
+ finish_reason: string;
249
+ }>;
250
+ usage?: {
251
+ prompt_tokens: number;
252
+ completion_tokens: number;
253
+ total_tokens: number;
254
+ };
255
+ memory?: {
256
+ retrieved: Array<{
257
+ id: string;
258
+ score: number;
259
+ content: string;
260
+ }>;
261
+ written: Array<{
262
+ id: string;
263
+ content: string;
264
+ }>;
265
+ write_status: 'pending' | 'disabled';
266
+ };
267
+ }
268
+ interface ChatCompletionChunk {
269
+ delta: string;
270
+ raw: Record<string, unknown>;
271
+ }
272
+ interface ChatCompletionStream extends AsyncIterable<ChatCompletionChunk> {
273
+ /** Number of memories injected into this request (from X-Cencori-Memory-Retrieved). */
274
+ memoriesRetrieved: number;
275
+ }
276
+ declare class Completions {
277
+ private config;
278
+ constructor(config: Required<CencoriConfig>);
279
+ private endpoint;
280
+ private headers;
281
+ /**
282
+ * Create a chat completion. Include `memory: { userId }` to retrieve
283
+ * relevant facts before the model call and persist new ones after it.
284
+ */
285
+ create(params: ChatCompletionCreateParams): Promise<ChatCompletionResponse>;
286
+ /**
287
+ * Stream a chat completion (SSE). Memory writeback still runs after the
288
+ * stream completes; `memoriesRetrieved` reports the injected count.
289
+ */
290
+ stream(params: ChatCompletionCreateParams): Promise<ChatCompletionStream>;
291
+ }
292
+ declare class ChatNamespace {
293
+ readonly completions: Completions;
294
+ constructor(config: Required<CencoriConfig>);
295
+ }
296
+
183
297
  /**
184
298
  * Cencori - Unified AI Infrastructure SDK
185
299
  *
@@ -216,6 +330,18 @@ declare class Cencori {
216
330
  * await cencori.ai.chat({ model: 'gpt-4o', messages: [...] });
217
331
  */
218
332
  readonly ai: AINamespace;
333
+ /**
334
+ * Chat - OpenAI-compatible chat completions with gateway memory.
335
+ * One line makes chat stateful.
336
+ *
337
+ * @example
338
+ * const response = await cencori.chat.completions.create({
339
+ * model: 'gpt-4o',
340
+ * messages: [{ role: 'user', content: 'What did we agree about pricing?' }],
341
+ * memory: { userId: session.user.id },
342
+ * });
343
+ */
344
+ readonly chat: ChatNamespace;
219
345
  /**
220
346
  * Vision - Analyze, describe, OCR, and classify images
221
347
  *
@@ -231,6 +357,28 @@ declare class Cencori {
231
357
  * });
232
358
  */
233
359
  readonly vision: VisionNamespace;
360
+ /**
361
+ * Voice - Text-to-speech and speech-to-text across providers
362
+ *
363
+ * @example
364
+ * const { audio } = await cencori.voice.speak({
365
+ * input: 'Hello from Cencori.',
366
+ * model: 'aura-asteria-en', // Deepgram; provider inferred from model
367
+ * });
368
+ *
369
+ * @example
370
+ * const { text } = await cencori.voice.transcribe({
371
+ * audio: fileBytes,
372
+ * model: 'nova-3',
373
+ * });
374
+ *
375
+ * @example
376
+ * const { segments } = await cencori.voice.diarize({
377
+ * audio: fileBytes,
378
+ * model: 'assemblyai-universal',
379
+ * });
380
+ */
381
+ readonly voice: VoiceNamespace;
234
382
  /**
235
383
  * Documents - Extract text from PDFs and images, summarize, and query
236
384
  *
@@ -391,4 +539,4 @@ declare class SafetyError extends CencoriError {
391
539
  */
392
540
  declare function fetchWithRetry(url: string, options: RequestInit, maxRetries?: number): Promise<Response>;
393
541
 
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 };
542
+ 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, WorkflowNamespace, Cencori as default, fetchWithRetry };