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.mjs CHANGED
@@ -198,6 +198,7 @@ var AINamespace = class {
198
198
  ];
199
199
  const response = await fetch(`${this.config.baseUrl}/api/ai/chat`, {
200
200
  method: "POST",
201
+ signal: request2.signal,
201
202
  headers: {
202
203
  "CENCORI_API_KEY": this.config.apiKey,
203
204
  "Content-Type": "application/json",
@@ -241,10 +242,12 @@ var AINamespace = class {
241
242
  return {
242
243
  object: parsedObject,
243
244
  usage: {
244
- promptTokens: data.usage?.prompt_tokens ?? 0,
245
- completionTokens: data.usage?.completion_tokens ?? 0,
246
- totalTokens: data.usage?.total_tokens ?? 0
247
- }
245
+ promptTokens: data.usage?.prompt_tokens ?? null,
246
+ completionTokens: data.usage?.completion_tokens ?? null,
247
+ totalTokens: data.usage?.total_tokens ?? null
248
+ },
249
+ costUsd: data.cost_usd ?? null,
250
+ requestId: response.headers.get("X-Request-Id")
248
251
  };
249
252
  }
250
253
  /**
@@ -1762,9 +1765,21 @@ var WebNamespace = class {
1762
1765
  };
1763
1766
 
1764
1767
  // src/embedded/index.ts
1765
- async function request(config, method, path, body, extraHeaders) {
1768
+ var CencoriEmbeddedApiError = class extends Error {
1769
+ constructor(message, status, code, requestId, type, param) {
1770
+ super(`Cencori API error: ${message}`);
1771
+ this.status = status;
1772
+ this.code = code;
1773
+ this.requestId = requestId;
1774
+ this.type = type;
1775
+ this.param = param;
1776
+ this.name = "CencoriEmbeddedApiError";
1777
+ }
1778
+ };
1779
+ async function request(config, method, path, body, extraHeaders, options) {
1766
1780
  const response = await fetch(`${config.baseUrl}${path}`, {
1767
1781
  method,
1782
+ signal: options?.signal,
1768
1783
  headers: {
1769
1784
  "CENCORI_API_KEY": config.apiKey,
1770
1785
  "Content-Type": "application/json",
@@ -1776,7 +1791,8 @@ async function request(config, method, path, body, extraHeaders) {
1776
1791
  if (!response.ok) {
1777
1792
  const errorData = await response.json().catch(() => ({ error: "Unknown error" }));
1778
1793
  const message = typeof errorData.error === "string" ? errorData.error : errorData.error?.message || response.statusText;
1779
- throw new Error(`Cencori API error: ${message}`);
1794
+ const details = typeof errorData.error === "object" ? errorData.error : null;
1795
+ throw new CencoriEmbeddedApiError(message, response.status, details?.code ?? null, details?.request_id ?? response.headers.get("X-Request-Id"), details?.type ?? null, details?.param ?? null);
1780
1796
  }
1781
1797
  if (response.status === 204) return void 0;
1782
1798
  return response.json();
@@ -1799,8 +1815,8 @@ var TenantsNamespace = class {
1799
1815
  list(params) {
1800
1816
  return request(this.config, "GET", `/v1/tenants${qs({ limit: params?.limit, cursor: params?.cursor, status: params?.status })}`);
1801
1817
  }
1802
- get(tenantId) {
1803
- return request(this.config, "GET", `/v1/tenants/${tenantId}`);
1818
+ get(tenantId, options) {
1819
+ return request(this.config, "GET", `/v1/tenants/${tenantId}`, void 0, void 0, options);
1804
1820
  }
1805
1821
  update(tenantId, params) {
1806
1822
  return request(this.config, "PATCH", `/v1/tenants/${tenantId}`, params);
@@ -1903,8 +1919,8 @@ var AgentVersionsNamespace = class {
1903
1919
  publish(agentId, version) {
1904
1920
  return request(this.config, "POST", `/v1/agents/${agentId}/versions/${version}/publish`, {});
1905
1921
  }
1906
- test(agentId, version, params) {
1907
- return request(this.config, "POST", `/v1/agents/${agentId}/versions/${version}/test`, params ?? {});
1922
+ test(agentId, version, params, options) {
1923
+ return request(this.config, "POST", `/v1/agents/${agentId}/versions/${version}/test`, params ?? {}, void 0, options);
1908
1924
  }
1909
1925
  deprecate(agentId, version) {
1910
1926
  return request(this.config, "POST", `/v1/agents/${agentId}/versions/${version}/deprecate`, {});
@@ -1946,17 +1962,17 @@ var RunsNamespace = class {
1946
1962
  constructor(config) {
1947
1963
  this.config = config;
1948
1964
  }
1949
- create(agentId, params, idempotencyKey) {
1950
- return request(this.config, "POST", `/v1/agents/${agentId}/runs`, params, idempotencyKey ? { "Idempotency-Key": idempotencyKey } : void 0);
1965
+ create(agentId, params, idempotencyKey, options) {
1966
+ return request(this.config, "POST", `/v1/agents/${agentId}/runs`, params, idempotencyKey ? { "Idempotency-Key": idempotencyKey } : void 0, options);
1951
1967
  }
1952
- get(runId) {
1953
- return request(this.config, "GET", `/v1/runs/${runId}`);
1968
+ get(runId, options) {
1969
+ return request(this.config, "GET", `/v1/runs/${runId}`, void 0, void 0, options);
1954
1970
  }
1955
1971
  events(runId, params) {
1956
1972
  return request(this.config, "GET", `/v1/runs/${runId}/events${qs({ after: params?.after, limit: params?.limit })}`);
1957
1973
  }
1958
- cancel(runId) {
1959
- return request(this.config, "POST", `/v1/runs/${runId}/cancel`, {});
1974
+ cancel(runId, options) {
1975
+ return request(this.config, "POST", `/v1/runs/${runId}/cancel`, {}, void 0, options);
1960
1976
  }
1961
1977
  delegate(runId, params, idempotencyKey) {
1962
1978
  return request(this.config, "POST", `/v1/runs/${runId}/delegate`, params, idempotencyKey ? { "Idempotency-Key": idempotencyKey } : void 0);
@@ -2753,6 +2769,7 @@ export {
2753
2769
  AgentsNamespace,
2754
2770
  AuthenticationError,
2755
2771
  Cencori,
2772
+ CencoriEmbeddedApiError,
2756
2773
  CencoriError,
2757
2774
  ChatNamespace,
2758
2775
  ClientTokensNamespace,