cencori 1.7.0 → 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
  /**
@@ -922,6 +925,7 @@ var SessionsNamespace = class {
922
925
  if (params?.limit) searchParams.set("limit", String(params.limit));
923
926
  if (params?.status) searchParams.set("status", params.status);
924
927
  if (params?.agent_id) searchParams.set("agent_id", params.agent_id);
928
+ if (params?.tenant_id) searchParams.set("tenant_id", params.tenant_id);
925
929
  const qs2 = searchParams.toString();
926
930
  return this.request("GET", `/v1/sessions${qs2 ? `?${qs2}` : ""}`);
927
931
  }
@@ -1761,9 +1765,21 @@ var WebNamespace = class {
1761
1765
  };
1762
1766
 
1763
1767
  // src/embedded/index.ts
1764
- 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) {
1765
1780
  const response = await fetch(`${config.baseUrl}${path}`, {
1766
1781
  method,
1782
+ signal: options?.signal,
1767
1783
  headers: {
1768
1784
  "CENCORI_API_KEY": config.apiKey,
1769
1785
  "Content-Type": "application/json",
@@ -1775,7 +1791,8 @@ async function request(config, method, path, body, extraHeaders) {
1775
1791
  if (!response.ok) {
1776
1792
  const errorData = await response.json().catch(() => ({ error: "Unknown error" }));
1777
1793
  const message = typeof errorData.error === "string" ? errorData.error : errorData.error?.message || response.statusText;
1778
- 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);
1779
1796
  }
1780
1797
  if (response.status === 204) return void 0;
1781
1798
  return response.json();
@@ -1798,8 +1815,8 @@ var TenantsNamespace = class {
1798
1815
  list(params) {
1799
1816
  return request(this.config, "GET", `/v1/tenants${qs({ limit: params?.limit, cursor: params?.cursor, status: params?.status })}`);
1800
1817
  }
1801
- get(tenantId) {
1802
- 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);
1803
1820
  }
1804
1821
  update(tenantId, params) {
1805
1822
  return request(this.config, "PATCH", `/v1/tenants/${tenantId}`, params);
@@ -1902,8 +1919,8 @@ var AgentVersionsNamespace = class {
1902
1919
  publish(agentId, version) {
1903
1920
  return request(this.config, "POST", `/v1/agents/${agentId}/versions/${version}/publish`, {});
1904
1921
  }
1905
- test(agentId, version, params) {
1906
- 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);
1907
1924
  }
1908
1925
  deprecate(agentId, version) {
1909
1926
  return request(this.config, "POST", `/v1/agents/${agentId}/versions/${version}/deprecate`, {});
@@ -1945,17 +1962,17 @@ var RunsNamespace = class {
1945
1962
  constructor(config) {
1946
1963
  this.config = config;
1947
1964
  }
1948
- create(agentId, params, idempotencyKey) {
1949
- 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);
1950
1967
  }
1951
- get(runId) {
1952
- 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);
1953
1970
  }
1954
1971
  events(runId, params) {
1955
1972
  return request(this.config, "GET", `/v1/runs/${runId}/events${qs({ after: params?.after, limit: params?.limit })}`);
1956
1973
  }
1957
- cancel(runId) {
1958
- 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);
1959
1976
  }
1960
1977
  delegate(runId, params, idempotencyKey) {
1961
1978
  return request(this.config, "POST", `/v1/runs/${runId}/delegate`, params, idempotencyKey ? { "Idempotency-Key": idempotencyKey } : void 0);
@@ -2752,6 +2769,7 @@ export {
2752
2769
  AgentsNamespace,
2753
2770
  AuthenticationError,
2754
2771
  Cencori,
2772
+ CencoriEmbeddedApiError,
2755
2773
  CencoriError,
2756
2774
  ChatNamespace,
2757
2775
  ClientTokensNamespace,