cencori 1.7.1 → 1.7.2

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/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 ?? 0,
312
- completionTokens: data.usage?.completion_tokens ?? 0,
313
- totalTokens: data.usage?.total_tokens ?? 0
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,21 @@ var WebNamespace = class {
1829
1833
  };
1830
1834
 
1831
1835
  // src/embedded/index.ts
1832
- async function request(config, method, path, body, extraHeaders) {
1836
+ var CencoriEmbeddedApiError = class extends Error {
1837
+ constructor(message, status, code, requestId, type, param) {
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.name = "CencoriEmbeddedApiError";
1845
+ }
1846
+ };
1847
+ async function request(config, method, path, body, extraHeaders, options) {
1833
1848
  const response = await fetch(`${config.baseUrl}${path}`, {
1834
1849
  method,
1850
+ signal: options?.signal,
1835
1851
  headers: {
1836
1852
  "CENCORI_API_KEY": config.apiKey,
1837
1853
  "Content-Type": "application/json",
@@ -1843,7 +1859,8 @@ async function request(config, method, path, body, extraHeaders) {
1843
1859
  if (!response.ok) {
1844
1860
  const errorData = await response.json().catch(() => ({ error: "Unknown error" }));
1845
1861
  const message = typeof errorData.error === "string" ? errorData.error : errorData.error?.message || response.statusText;
1846
- throw new Error(`Cencori API error: ${message}`);
1862
+ const details = typeof errorData.error === "object" ? errorData.error : null;
1863
+ throw new CencoriEmbeddedApiError(message, response.status, details?.code ?? null, details?.request_id ?? response.headers.get("X-Request-Id"), details?.type ?? null, details?.param ?? null);
1847
1864
  }
1848
1865
  if (response.status === 204) return void 0;
1849
1866
  return response.json();
@@ -1866,8 +1883,8 @@ var TenantsNamespace = class {
1866
1883
  list(params) {
1867
1884
  return request(this.config, "GET", `/v1/tenants${qs({ limit: params?.limit, cursor: params?.cursor, status: params?.status })}`);
1868
1885
  }
1869
- get(tenantId) {
1870
- return request(this.config, "GET", `/v1/tenants/${tenantId}`);
1886
+ get(tenantId, options) {
1887
+ return request(this.config, "GET", `/v1/tenants/${tenantId}`, void 0, void 0, options);
1871
1888
  }
1872
1889
  update(tenantId, params) {
1873
1890
  return request(this.config, "PATCH", `/v1/tenants/${tenantId}`, params);
@@ -1970,8 +1987,8 @@ var AgentVersionsNamespace = class {
1970
1987
  publish(agentId, version) {
1971
1988
  return request(this.config, "POST", `/v1/agents/${agentId}/versions/${version}/publish`, {});
1972
1989
  }
1973
- test(agentId, version, params) {
1974
- return request(this.config, "POST", `/v1/agents/${agentId}/versions/${version}/test`, params ?? {});
1990
+ test(agentId, version, params, options) {
1991
+ return request(this.config, "POST", `/v1/agents/${agentId}/versions/${version}/test`, params ?? {}, void 0, options);
1975
1992
  }
1976
1993
  deprecate(agentId, version) {
1977
1994
  return request(this.config, "POST", `/v1/agents/${agentId}/versions/${version}/deprecate`, {});
@@ -2013,17 +2030,17 @@ var RunsNamespace = class {
2013
2030
  constructor(config) {
2014
2031
  this.config = config;
2015
2032
  }
2016
- create(agentId, params, idempotencyKey) {
2017
- return request(this.config, "POST", `/v1/agents/${agentId}/runs`, params, idempotencyKey ? { "Idempotency-Key": idempotencyKey } : void 0);
2033
+ create(agentId, params, idempotencyKey, options) {
2034
+ return request(this.config, "POST", `/v1/agents/${agentId}/runs`, params, idempotencyKey ? { "Idempotency-Key": idempotencyKey } : void 0, options);
2018
2035
  }
2019
- get(runId) {
2020
- return request(this.config, "GET", `/v1/runs/${runId}`);
2036
+ get(runId, options) {
2037
+ return request(this.config, "GET", `/v1/runs/${runId}`, void 0, void 0, options);
2021
2038
  }
2022
2039
  events(runId, params) {
2023
2040
  return request(this.config, "GET", `/v1/runs/${runId}/events${qs({ after: params?.after, limit: params?.limit })}`);
2024
2041
  }
2025
- cancel(runId) {
2026
- return request(this.config, "POST", `/v1/runs/${runId}/cancel`, {});
2042
+ cancel(runId, options) {
2043
+ return request(this.config, "POST", `/v1/runs/${runId}/cancel`, {}, void 0, options);
2027
2044
  }
2028
2045
  delegate(runId, params, idempotencyKey) {
2029
2046
  return request(this.config, "POST", `/v1/runs/${runId}/delegate`, params, idempotencyKey ? { "Idempotency-Key": idempotencyKey } : void 0);
@@ -2821,6 +2838,7 @@ cencori.chat = cencori;
2821
2838
  AgentsNamespace,
2822
2839
  AuthenticationError,
2823
2840
  Cencori,
2841
+ CencoriEmbeddedApiError,
2824
2842
  CencoriError,
2825
2843
  ChatNamespace,
2826
2844
  ClientTokensNamespace,