cencori 1.7.1 → 1.7.3
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/dist/ai/index.d.mts +1 -1
- package/dist/ai/index.d.ts +1 -1
- package/dist/ai/index.js +7 -4
- package/dist/ai/index.js.map +1 -1
- package/dist/ai/index.mjs +7 -4
- 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 +23 -9
- package/dist/index.d.ts +23 -9
- package/dist/index.js +66 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +65 -18
- package/dist/index.mjs.map +1 -1
- package/dist/memory/index.d.mts +1 -1
- package/dist/memory/index.d.ts +1 -1
- package/dist/storage/index.d.mts +1 -1
- package/dist/storage/index.d.ts +1 -1
- package/dist/telemetry/index.d.mts +1 -1
- package/dist/telemetry/index.d.ts +1 -1
- package/dist/{types-xSwLRBZw.d.mts → types-CZSIg4JQ.d.mts} +8 -3
- package/dist/{types-xSwLRBZw.d.ts → types-CZSIg4JQ.d.ts} +8 -3
- 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.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as CencoriConfig, i as RequestOptions } from './types-
|
|
2
|
-
export { j as ChatMessage, a as ChatRequest, b as ChatResponse, o as CodeInterpreterTool, c as CompletionRequest, E as EmbeddingRequest, d as EmbeddingResponse, F as FileSearchTool, l as ResponseInputItem, k as ResponsesOutputItem, R as ResponsesRequest, g as ResponsesResponse, m as ResponsesTool, U as UrlCitation, n as WebSearchTool } from './types-
|
|
1
|
+
import { C as CencoriConfig, i as RequestOptions } from './types-CZSIg4JQ.js';
|
|
2
|
+
export { j as ChatMessage, a as ChatRequest, b as ChatResponse, o as CodeInterpreterTool, c as CompletionRequest, E as EmbeddingRequest, d as EmbeddingResponse, F as FileSearchTool, l as ResponseInputItem, k as ResponsesOutputItem, R as ResponsesRequest, g as ResponsesResponse, m as ResponsesTool, U as UrlCitation, n as WebSearchTool } from './types-CZSIg4JQ.js';
|
|
3
3
|
import { AINamespace } from './ai/index.js';
|
|
4
4
|
export { StreamChunk } from './ai/index.js';
|
|
5
5
|
import { VisionNamespace } from './vision/index.js';
|
|
@@ -317,6 +317,19 @@ declare class ChatNamespace {
|
|
|
317
317
|
constructor(config: Required<CencoriConfig>);
|
|
318
318
|
}
|
|
319
319
|
|
|
320
|
+
interface EmbeddedRequestOptions {
|
|
321
|
+
signal?: AbortSignal;
|
|
322
|
+
}
|
|
323
|
+
declare class CencoriEmbeddedApiError extends Error {
|
|
324
|
+
readonly status: number;
|
|
325
|
+
readonly code: string | null;
|
|
326
|
+
readonly requestId: string | null;
|
|
327
|
+
readonly type: string | null;
|
|
328
|
+
readonly param: string | null;
|
|
329
|
+
readonly retryAfterSeconds: number | null;
|
|
330
|
+
readonly name = "CencoriEmbeddedApiError";
|
|
331
|
+
constructor(message: string, status: number, code: string | null, requestId: string | null, type: string | null, param: string | null, retryAfterSeconds?: number | null);
|
|
332
|
+
}
|
|
320
333
|
interface Tenant {
|
|
321
334
|
id: string;
|
|
322
335
|
external_id: string;
|
|
@@ -344,7 +357,7 @@ declare class TenantsNamespace {
|
|
|
344
357
|
data: Tenant[];
|
|
345
358
|
next_cursor: string | null;
|
|
346
359
|
}>;
|
|
347
|
-
get(tenantId: string): Promise<Tenant>;
|
|
360
|
+
get(tenantId: string, options?: EmbeddedRequestOptions): Promise<Tenant>;
|
|
348
361
|
update(tenantId: string, params: {
|
|
349
362
|
name?: string;
|
|
350
363
|
metadata?: Record<string, unknown>;
|
|
@@ -489,7 +502,7 @@ declare class AgentVersionsNamespace {
|
|
|
489
502
|
test(agentId: string, version: string, params?: {
|
|
490
503
|
input?: string;
|
|
491
504
|
test_connection_ids?: string[];
|
|
492
|
-
}): Promise<unknown>;
|
|
505
|
+
}, options?: EmbeddedRequestOptions): Promise<unknown>;
|
|
493
506
|
deprecate(agentId: string, version: string): Promise<unknown>;
|
|
494
507
|
retire(agentId: string, version: string): Promise<unknown>;
|
|
495
508
|
catalog(params?: {
|
|
@@ -535,8 +548,8 @@ declare class RunsNamespace {
|
|
|
535
548
|
input?: unknown;
|
|
536
549
|
response_format?: unknown;
|
|
537
550
|
session_id?: string;
|
|
538
|
-
}, idempotencyKey?: string): Promise<unknown>;
|
|
539
|
-
get(runId: string): Promise<unknown>;
|
|
551
|
+
}, idempotencyKey?: string, options?: EmbeddedRequestOptions): Promise<unknown>;
|
|
552
|
+
get(runId: string, options?: EmbeddedRequestOptions): Promise<unknown>;
|
|
540
553
|
events(runId: string, params?: {
|
|
541
554
|
after?: string;
|
|
542
555
|
limit?: number;
|
|
@@ -544,7 +557,7 @@ declare class RunsNamespace {
|
|
|
544
557
|
data: unknown[];
|
|
545
558
|
next_cursor: string | null;
|
|
546
559
|
}>;
|
|
547
|
-
cancel(runId: string): Promise<unknown>;
|
|
560
|
+
cancel(runId: string, options?: EmbeddedRequestOptions): Promise<unknown>;
|
|
548
561
|
delegate(runId: string, params: {
|
|
549
562
|
agent_version_id: string;
|
|
550
563
|
input?: unknown;
|
|
@@ -1105,7 +1118,8 @@ declare class AuthenticationError extends CencoriError {
|
|
|
1105
1118
|
constructor(message?: string);
|
|
1106
1119
|
}
|
|
1107
1120
|
declare class RateLimitError extends CencoriError {
|
|
1108
|
-
|
|
1121
|
+
retryAfterSeconds?: number | null | undefined;
|
|
1122
|
+
constructor(message?: string, retryAfterSeconds?: number | null | undefined);
|
|
1109
1123
|
}
|
|
1110
1124
|
declare class SafetyError extends CencoriError {
|
|
1111
1125
|
reasons?: string[] | undefined;
|
|
@@ -1121,4 +1135,4 @@ declare class SafetyError extends CencoriError {
|
|
|
1121
1135
|
*/
|
|
1122
1136
|
declare function fetchWithRetry(url: string, options: RequestInit, maxRetries?: number): Promise<Response>;
|
|
1123
1137
|
|
|
1124
|
-
export { AINamespace, ActionsNamespace, type Agent, type AgentConfig, type AgentKey, type AgentListItem, AgentVersionsNamespace, AgentsNamespace, AuthenticationError, Cencori, CencoriConfig, CencoriError, type ChatCompletionChunk, type ChatCompletionCreateParams, type ChatCompletionResponse, type ChatCompletionStream, type ChatMemoryOptions, ChatNamespace, ClientTokensNamespace, ComputeNamespace, ConnectionsNamespace, type CreateAgentKeyParams, type CreateAgentParams, type CreateSessionParams, DocumentsNamespace, EndUsersNamespace, InstallationsNamespace, KnowledgeNamespace, McpServersNamespace, MemoryClient, ModelsNamespace, type PaginatedResponse, ProviderConnectionsNamespace, RateLimitError, RatePlansNamespace, RequestOptions, RunsNamespace, SafetyError, type Session, type SessionEvent, type SessionListParams, SessionsNamespace, SkillImportsNamespace, SkillsNamespace, StorageNamespace, TelemetryClient, type Tenant, TenantsNamespace, type TurnParams, type UnifiedModel, type UpdateAgentParams, UsageNamespace, VisionNamespace, VoiceNamespace, WebNamespace, WebhooksNamespace, WorkflowNamespace, Cencori as default, fetchWithRetry };
|
|
1138
|
+
export { AINamespace, ActionsNamespace, type Agent, type AgentConfig, type AgentKey, type AgentListItem, AgentVersionsNamespace, AgentsNamespace, AuthenticationError, Cencori, CencoriConfig, CencoriEmbeddedApiError, CencoriError, type ChatCompletionChunk, type ChatCompletionCreateParams, type ChatCompletionResponse, type ChatCompletionStream, type ChatMemoryOptions, ChatNamespace, ClientTokensNamespace, ComputeNamespace, ConnectionsNamespace, type CreateAgentKeyParams, type CreateAgentParams, type CreateSessionParams, DocumentsNamespace, type EmbeddedRequestOptions, EndUsersNamespace, InstallationsNamespace, KnowledgeNamespace, McpServersNamespace, MemoryClient, ModelsNamespace, type PaginatedResponse, ProviderConnectionsNamespace, RateLimitError, RatePlansNamespace, RequestOptions, RunsNamespace, SafetyError, type Session, type SessionEvent, type SessionListParams, SessionsNamespace, SkillImportsNamespace, SkillsNamespace, StorageNamespace, TelemetryClient, type Tenant, TenantsNamespace, type TurnParams, type UnifiedModel, type UpdateAgentParams, UsageNamespace, VisionNamespace, VoiceNamespace, WebNamespace, WebhooksNamespace, WorkflowNamespace, Cencori as default, fetchWithRetry };
|
package/dist/index.js
CHANGED
|
@@ -26,6 +26,7 @@ __export(src_exports, {
|
|
|
26
26
|
AgentsNamespace: () => AgentsNamespace,
|
|
27
27
|
AuthenticationError: () => AuthenticationError,
|
|
28
28
|
Cencori: () => Cencori,
|
|
29
|
+
CencoriEmbeddedApiError: () => CencoriEmbeddedApiError,
|
|
29
30
|
CencoriError: () => CencoriError,
|
|
30
31
|
ChatNamespace: () => ChatNamespace,
|
|
31
32
|
ClientTokensNamespace: () => ClientTokensNamespace,
|
|
@@ -265,6 +266,7 @@ var AINamespace = class {
|
|
|
265
266
|
];
|
|
266
267
|
const response = await fetch(`${this.config.baseUrl}/api/ai/chat`, {
|
|
267
268
|
method: "POST",
|
|
269
|
+
signal: request2.signal,
|
|
268
270
|
headers: {
|
|
269
271
|
"CENCORI_API_KEY": this.config.apiKey,
|
|
270
272
|
"Content-Type": "application/json",
|
|
@@ -308,10 +310,12 @@ var AINamespace = class {
|
|
|
308
310
|
return {
|
|
309
311
|
object: parsedObject,
|
|
310
312
|
usage: {
|
|
311
|
-
promptTokens: data.usage?.prompt_tokens ??
|
|
312
|
-
completionTokens: data.usage?.completion_tokens ??
|
|
313
|
-
totalTokens: data.usage?.total_tokens ??
|
|
314
|
-
}
|
|
313
|
+
promptTokens: data.usage?.prompt_tokens ?? null,
|
|
314
|
+
completionTokens: data.usage?.completion_tokens ?? null,
|
|
315
|
+
totalTokens: data.usage?.total_tokens ?? null
|
|
316
|
+
},
|
|
317
|
+
costUsd: data.cost_usd ?? null,
|
|
318
|
+
requestId: response.headers.get("X-Request-Id")
|
|
315
319
|
};
|
|
316
320
|
}
|
|
317
321
|
/**
|
|
@@ -1829,9 +1833,27 @@ var WebNamespace = class {
|
|
|
1829
1833
|
};
|
|
1830
1834
|
|
|
1831
1835
|
// src/embedded/index.ts
|
|
1832
|
-
|
|
1836
|
+
var CencoriEmbeddedApiError = class extends Error {
|
|
1837
|
+
constructor(message, status, code, requestId, type, param, retryAfterSeconds = null) {
|
|
1838
|
+
super(`Cencori API error: ${message}`);
|
|
1839
|
+
this.status = status;
|
|
1840
|
+
this.code = code;
|
|
1841
|
+
this.requestId = requestId;
|
|
1842
|
+
this.type = type;
|
|
1843
|
+
this.param = param;
|
|
1844
|
+
this.retryAfterSeconds = retryAfterSeconds;
|
|
1845
|
+
this.name = "CencoriEmbeddedApiError";
|
|
1846
|
+
}
|
|
1847
|
+
};
|
|
1848
|
+
function parseRetryAfterSeconds(value) {
|
|
1849
|
+
if (!value) return null;
|
|
1850
|
+
const seconds = Number.parseInt(value.trim(), 10);
|
|
1851
|
+
return Number.isFinite(seconds) && seconds >= 0 ? seconds : null;
|
|
1852
|
+
}
|
|
1853
|
+
async function request(config, method, path, body, extraHeaders, options) {
|
|
1833
1854
|
const response = await fetch(`${config.baseUrl}${path}`, {
|
|
1834
1855
|
method,
|
|
1856
|
+
signal: options?.signal,
|
|
1835
1857
|
headers: {
|
|
1836
1858
|
"CENCORI_API_KEY": config.apiKey,
|
|
1837
1859
|
"Content-Type": "application/json",
|
|
@@ -1843,7 +1865,20 @@ async function request(config, method, path, body, extraHeaders) {
|
|
|
1843
1865
|
if (!response.ok) {
|
|
1844
1866
|
const errorData = await response.json().catch(() => ({ error: "Unknown error" }));
|
|
1845
1867
|
const message = typeof errorData.error === "string" ? errorData.error : errorData.error?.message || response.statusText;
|
|
1846
|
-
|
|
1868
|
+
const details = typeof errorData.error === "object" ? errorData.error : null;
|
|
1869
|
+
let retryAfterSeconds = parseRetryAfterSeconds(response.headers.get("Retry-After") ?? response.headers.get("retry-after"));
|
|
1870
|
+
if (retryAfterSeconds == null) {
|
|
1871
|
+
const secHint = details?.retry_after_seconds ?? errorData.retry_after_seconds ?? details?.retry_after ?? errorData.retry_after;
|
|
1872
|
+
if (typeof secHint === "number" && Number.isFinite(secHint) && secHint >= 0) {
|
|
1873
|
+
retryAfterSeconds = Math.ceil(secHint);
|
|
1874
|
+
} else {
|
|
1875
|
+
const msHint = details?.retry_after_ms ?? errorData.retry_after_ms;
|
|
1876
|
+
if (typeof msHint === "number" && Number.isFinite(msHint) && msHint >= 0) {
|
|
1877
|
+
retryAfterSeconds = Math.ceil(msHint / 1e3);
|
|
1878
|
+
}
|
|
1879
|
+
}
|
|
1880
|
+
}
|
|
1881
|
+
throw new CencoriEmbeddedApiError(message, response.status, details?.code ?? null, details?.request_id ?? response.headers.get("X-Request-Id"), details?.type ?? null, details?.param ?? null, retryAfterSeconds);
|
|
1847
1882
|
}
|
|
1848
1883
|
if (response.status === 204) return void 0;
|
|
1849
1884
|
return response.json();
|
|
@@ -1866,8 +1901,8 @@ var TenantsNamespace = class {
|
|
|
1866
1901
|
list(params) {
|
|
1867
1902
|
return request(this.config, "GET", `/v1/tenants${qs({ limit: params?.limit, cursor: params?.cursor, status: params?.status })}`);
|
|
1868
1903
|
}
|
|
1869
|
-
get(tenantId) {
|
|
1870
|
-
return request(this.config, "GET", `/v1/tenants/${tenantId}
|
|
1904
|
+
get(tenantId, options) {
|
|
1905
|
+
return request(this.config, "GET", `/v1/tenants/${tenantId}`, void 0, void 0, options);
|
|
1871
1906
|
}
|
|
1872
1907
|
update(tenantId, params) {
|
|
1873
1908
|
return request(this.config, "PATCH", `/v1/tenants/${tenantId}`, params);
|
|
@@ -1970,8 +2005,8 @@ var AgentVersionsNamespace = class {
|
|
|
1970
2005
|
publish(agentId, version) {
|
|
1971
2006
|
return request(this.config, "POST", `/v1/agents/${agentId}/versions/${version}/publish`, {});
|
|
1972
2007
|
}
|
|
1973
|
-
test(agentId, version, params) {
|
|
1974
|
-
return request(this.config, "POST", `/v1/agents/${agentId}/versions/${version}/test`, params ?? {});
|
|
2008
|
+
test(agentId, version, params, options) {
|
|
2009
|
+
return request(this.config, "POST", `/v1/agents/${agentId}/versions/${version}/test`, params ?? {}, void 0, options);
|
|
1975
2010
|
}
|
|
1976
2011
|
deprecate(agentId, version) {
|
|
1977
2012
|
return request(this.config, "POST", `/v1/agents/${agentId}/versions/${version}/deprecate`, {});
|
|
@@ -2013,17 +2048,17 @@ var RunsNamespace = class {
|
|
|
2013
2048
|
constructor(config) {
|
|
2014
2049
|
this.config = config;
|
|
2015
2050
|
}
|
|
2016
|
-
create(agentId, params, idempotencyKey) {
|
|
2017
|
-
return request(this.config, "POST", `/v1/agents/${agentId}/runs`, params, idempotencyKey ? { "Idempotency-Key": idempotencyKey } : void 0);
|
|
2051
|
+
create(agentId, params, idempotencyKey, options) {
|
|
2052
|
+
return request(this.config, "POST", `/v1/agents/${agentId}/runs`, params, idempotencyKey ? { "Idempotency-Key": idempotencyKey } : void 0, options);
|
|
2018
2053
|
}
|
|
2019
|
-
get(runId) {
|
|
2020
|
-
return request(this.config, "GET", `/v1/runs/${runId}
|
|
2054
|
+
get(runId, options) {
|
|
2055
|
+
return request(this.config, "GET", `/v1/runs/${runId}`, void 0, void 0, options);
|
|
2021
2056
|
}
|
|
2022
2057
|
events(runId, params) {
|
|
2023
2058
|
return request(this.config, "GET", `/v1/runs/${runId}/events${qs({ after: params?.after, limit: params?.limit })}`);
|
|
2024
2059
|
}
|
|
2025
|
-
cancel(runId) {
|
|
2026
|
-
return request(this.config, "POST", `/v1/runs/${runId}/cancel`, {});
|
|
2060
|
+
cancel(runId, options) {
|
|
2061
|
+
return request(this.config, "POST", `/v1/runs/${runId}/cancel`, {}, void 0, options);
|
|
2027
2062
|
}
|
|
2028
2063
|
delegate(runId, params, idempotencyKey) {
|
|
2029
2064
|
return request(this.config, "POST", `/v1/runs/${runId}/delegate`, params, idempotencyKey ? { "Idempotency-Key": idempotencyKey } : void 0);
|
|
@@ -2328,8 +2363,9 @@ var AuthenticationError = class _AuthenticationError extends CencoriError {
|
|
|
2328
2363
|
}
|
|
2329
2364
|
};
|
|
2330
2365
|
var RateLimitError = class _RateLimitError extends CencoriError {
|
|
2331
|
-
constructor(message = "Rate limit exceeded") {
|
|
2366
|
+
constructor(message = "Rate limit exceeded", retryAfterSeconds) {
|
|
2332
2367
|
super(message, 429, "RATE_LIMIT_EXCEEDED");
|
|
2368
|
+
this.retryAfterSeconds = retryAfterSeconds;
|
|
2333
2369
|
this.name = "RateLimitError";
|
|
2334
2370
|
Object.setPrototypeOf(this, _RateLimitError.prototype);
|
|
2335
2371
|
}
|
|
@@ -2453,7 +2489,18 @@ var Cencori = class {
|
|
|
2453
2489
|
throw new AuthenticationError(errorData.error || "Invalid API key");
|
|
2454
2490
|
}
|
|
2455
2491
|
if (response.status === 429) {
|
|
2456
|
-
|
|
2492
|
+
const rawRetryAfter = response.headers.get("Retry-After") ?? response.headers.get("retry-after");
|
|
2493
|
+
const parsed = rawRetryAfter ? Number.parseInt(rawRetryAfter.trim(), 10) : NaN;
|
|
2494
|
+
let retryAfterSeconds = Number.isFinite(parsed) && parsed >= 0 ? parsed : null;
|
|
2495
|
+
if (retryAfterSeconds == null) {
|
|
2496
|
+
const secHint = errorData.retry_after_seconds ?? errorData.retry_after;
|
|
2497
|
+
if (typeof secHint === "number" && Number.isFinite(secHint) && secHint >= 0) {
|
|
2498
|
+
retryAfterSeconds = Math.ceil(secHint);
|
|
2499
|
+
} else if (typeof errorData.retry_after_ms === "number" && Number.isFinite(errorData.retry_after_ms) && errorData.retry_after_ms >= 0) {
|
|
2500
|
+
retryAfterSeconds = Math.ceil(errorData.retry_after_ms / 1e3);
|
|
2501
|
+
}
|
|
2502
|
+
}
|
|
2503
|
+
throw new RateLimitError(errorData.error || "Rate limit exceeded", retryAfterSeconds);
|
|
2457
2504
|
}
|
|
2458
2505
|
if (response.status === 400 && errorData.reasons) {
|
|
2459
2506
|
throw new SafetyError(errorData.error, errorData.reasons);
|
|
@@ -2821,6 +2868,7 @@ cencori.chat = cencori;
|
|
|
2821
2868
|
AgentsNamespace,
|
|
2822
2869
|
AuthenticationError,
|
|
2823
2870
|
Cencori,
|
|
2871
|
+
CencoriEmbeddedApiError,
|
|
2824
2872
|
CencoriError,
|
|
2825
2873
|
ChatNamespace,
|
|
2826
2874
|
ClientTokensNamespace,
|