cencori 1.8.1 → 1.8.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.
Files changed (44) hide show
  1. package/README.md +21 -0
  2. package/dist/ai/index.d.mts +1 -1
  3. package/dist/ai/index.d.ts +1 -1
  4. package/dist/ai/index.js +6 -2
  5. package/dist/ai/index.js.map +1 -1
  6. package/dist/ai/index.mjs +6 -2
  7. package/dist/ai/index.mjs.map +1 -1
  8. package/dist/compute/index.d.mts +1 -1
  9. package/dist/compute/index.d.ts +1 -1
  10. package/dist/documents/index.d.mts +1 -1
  11. package/dist/documents/index.d.ts +1 -1
  12. package/dist/index.d.mts +31 -3
  13. package/dist/index.d.ts +31 -3
  14. package/dist/index.js +126 -8
  15. package/dist/index.js.map +1 -1
  16. package/dist/index.mjs +125 -8
  17. package/dist/index.mjs.map +1 -1
  18. package/dist/judgment/index.d.mts +128 -0
  19. package/dist/judgment/index.d.ts +128 -0
  20. package/dist/judgment/index.js +79 -0
  21. package/dist/judgment/index.js.map +1 -0
  22. package/dist/judgment/index.mjs +54 -0
  23. package/dist/judgment/index.mjs.map +1 -0
  24. package/dist/memory/index.d.mts +1 -1
  25. package/dist/memory/index.d.ts +1 -1
  26. package/dist/storage/index.d.mts +1 -1
  27. package/dist/storage/index.d.ts +1 -1
  28. package/dist/telemetry/index.d.mts +1 -1
  29. package/dist/telemetry/index.d.ts +1 -1
  30. package/dist/{types-DbHh0iAg.d.mts → types-CAhDuNTz.d.mts} +4 -0
  31. package/dist/{types-DbHh0iAg.d.ts → types-CAhDuNTz.d.ts} +4 -0
  32. package/dist/vercel/index.js +66 -6
  33. package/dist/vercel/index.js.map +1 -1
  34. package/dist/vercel/index.mjs +66 -6
  35. package/dist/vercel/index.mjs.map +1 -1
  36. package/dist/vision/index.d.mts +1 -1
  37. package/dist/vision/index.d.ts +1 -1
  38. package/dist/voice/index.d.mts +1 -1
  39. package/dist/voice/index.d.ts +1 -1
  40. package/dist/web/index.d.mts +1 -1
  41. package/dist/web/index.d.ts +1 -1
  42. package/dist/workflow/index.d.mts +1 -1
  43. package/dist/workflow/index.d.ts +1 -1
  44. package/package.json +6 -1
package/dist/index.d.mts CHANGED
@@ -1,11 +1,13 @@
1
- import { C as CencoriConfig, i as RequestOptions } from './types-DbHh0iAg.mjs';
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-DbHh0iAg.mjs';
1
+ import { C as CencoriConfig, i as RequestOptions } from './types-CAhDuNTz.mjs';
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-CAhDuNTz.mjs';
3
3
  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
7
  import { VoiceNamespace } from './voice/index.mjs';
8
8
  export { AudioFormat, AudioInput, STTProvider, SpeakRequest, SpeakResult, TTSProvider, TranscribeRequest, TranscribeResult, TranscriptFormat, TranscriptSegment, TranscriptWord, VoiceModelInfo } from './voice/index.mjs';
9
+ import { JudgmentNamespace } from './judgment/index.mjs';
10
+ export { ChoiceAnswer, ChoiceQuestion, JudgeRequest, JudgeResult, JudgmentAnswer, JudgmentModelInfo, JudgmentModelsResponse, JudgmentQuestion, JudgmentQuestionType, JudgmentState, JudgmentUsage, NoulAnswer, NoulQuestion, ScoreAnswer, ScoreQuestion } from './judgment/index.mjs';
9
11
  import { DocumentsNamespace } from './documents/index.mjs';
10
12
  export { DocumentCost, DocumentExtractMethod, DocumentExtractResult, DocumentInput, DocumentKind, DocumentQueryRequest, DocumentQueryResult, DocumentRequest, DocumentSummarizeResult, DocumentUsage } from './documents/index.mjs';
11
13
  import { ComputeNamespace } from './compute/index.mjs';
@@ -256,6 +258,16 @@ interface ChatCompletionCreateParams {
256
258
  name: string;
257
259
  variables?: Record<string, string>;
258
260
  };
261
+ /**
262
+ * Per-request provider timeout in milliseconds (positive, capped
263
+ * server-side at 300000). Bounds one provider attempt.
264
+ */
265
+ timeout_ms?: number;
266
+ /**
267
+ * Per-request cost budget in USD (non-negative). Unary calls fail before
268
+ * returning; streams surface HTTP 402 `budget_exceeded` at final tally.
269
+ */
270
+ max_cost_usd?: number;
259
271
  }
260
272
  interface ChatCompletionResponse {
261
273
  id: string;
@@ -1019,6 +1031,22 @@ declare class Cencori {
1019
1031
  * });
1020
1032
  */
1021
1033
  readonly voice: VoiceNamespace;
1034
+ /**
1035
+ * Judgment - Structured decisions from decision models (TypeSafe Jev)
1036
+ *
1037
+ * @example
1038
+ * const result = await cencori.judgment.judge({
1039
+ * state: 'I was charged twice. Please refund the duplicate.',
1040
+ * questions: {
1041
+ * department: {
1042
+ * type: 'choice',
1043
+ * instructions: 'Which team should handle this?',
1044
+ * criteria: { billing: 'Payments, invoicing, refunds', technical: 'Bugs, outages' },
1045
+ * },
1046
+ * },
1047
+ * });
1048
+ */
1049
+ readonly judgment: JudgmentNamespace;
1022
1050
  /**
1023
1051
  * Documents - Extract text from PDFs and images, summarize, and query
1024
1052
  *
@@ -1229,4 +1257,4 @@ declare class SafetyError extends CencoriError {
1229
1257
  */
1230
1258
  declare function fetchWithRetry(url: string, options: RequestInit, maxRetries?: number): Promise<Response>;
1231
1259
 
1232
- 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 };
1260
+ 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, JudgmentNamespace, 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.d.ts CHANGED
@@ -1,11 +1,13 @@
1
- import { C as CencoriConfig, i as RequestOptions } from './types-DbHh0iAg.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-DbHh0iAg.js';
1
+ import { C as CencoriConfig, i as RequestOptions } from './types-CAhDuNTz.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-CAhDuNTz.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';
6
6
  export { VisionClassification, VisionClassifyResult, VisionCost, VisionDescribeResult, VisionImage, VisionOcrResult, VisionProvider, VisionRequest, VisionResult, VisionStreamChunk, VisionTask, VisionUsage } from './vision/index.js';
7
7
  import { VoiceNamespace } from './voice/index.js';
8
8
  export { AudioFormat, AudioInput, STTProvider, SpeakRequest, SpeakResult, TTSProvider, TranscribeRequest, TranscribeResult, TranscriptFormat, TranscriptSegment, TranscriptWord, VoiceModelInfo } from './voice/index.js';
9
+ import { JudgmentNamespace } from './judgment/index.js';
10
+ export { ChoiceAnswer, ChoiceQuestion, JudgeRequest, JudgeResult, JudgmentAnswer, JudgmentModelInfo, JudgmentModelsResponse, JudgmentQuestion, JudgmentQuestionType, JudgmentState, JudgmentUsage, NoulAnswer, NoulQuestion, ScoreAnswer, ScoreQuestion } from './judgment/index.js';
9
11
  import { DocumentsNamespace } from './documents/index.js';
10
12
  export { DocumentCost, DocumentExtractMethod, DocumentExtractResult, DocumentInput, DocumentKind, DocumentQueryRequest, DocumentQueryResult, DocumentRequest, DocumentSummarizeResult, DocumentUsage } from './documents/index.js';
11
13
  import { ComputeNamespace } from './compute/index.js';
@@ -256,6 +258,16 @@ interface ChatCompletionCreateParams {
256
258
  name: string;
257
259
  variables?: Record<string, string>;
258
260
  };
261
+ /**
262
+ * Per-request provider timeout in milliseconds (positive, capped
263
+ * server-side at 300000). Bounds one provider attempt.
264
+ */
265
+ timeout_ms?: number;
266
+ /**
267
+ * Per-request cost budget in USD (non-negative). Unary calls fail before
268
+ * returning; streams surface HTTP 402 `budget_exceeded` at final tally.
269
+ */
270
+ max_cost_usd?: number;
259
271
  }
260
272
  interface ChatCompletionResponse {
261
273
  id: string;
@@ -1019,6 +1031,22 @@ declare class Cencori {
1019
1031
  * });
1020
1032
  */
1021
1033
  readonly voice: VoiceNamespace;
1034
+ /**
1035
+ * Judgment - Structured decisions from decision models (TypeSafe Jev)
1036
+ *
1037
+ * @example
1038
+ * const result = await cencori.judgment.judge({
1039
+ * state: 'I was charged twice. Please refund the duplicate.',
1040
+ * questions: {
1041
+ * department: {
1042
+ * type: 'choice',
1043
+ * instructions: 'Which team should handle this?',
1044
+ * criteria: { billing: 'Payments, invoicing, refunds', technical: 'Bugs, outages' },
1045
+ * },
1046
+ * },
1047
+ * });
1048
+ */
1049
+ readonly judgment: JudgmentNamespace;
1022
1050
  /**
1023
1051
  * Documents - Extract text from PDFs and images, summarize, and query
1024
1052
  *
@@ -1229,4 +1257,4 @@ declare class SafetyError extends CencoriError {
1229
1257
  */
1230
1258
  declare function fetchWithRetry(url: string, options: RequestInit, maxRetries?: number): Promise<Response>;
1231
1259
 
1232
- 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 };
1260
+ 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, JudgmentNamespace, 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
@@ -36,6 +36,7 @@ __export(src_exports, {
36
36
  DocumentsNamespace: () => DocumentsNamespace,
37
37
  EndUsersNamespace: () => EndUsersNamespace,
38
38
  InstallationsNamespace: () => InstallationsNamespace,
39
+ JudgmentNamespace: () => JudgmentNamespace,
39
40
  KnowledgeNamespace: () => KnowledgeNamespace2,
40
41
  MEMORY_FETCH_TOOL: () => MEMORY_FETCH_TOOL,
41
42
  McpServersNamespace: () => McpServersNamespace,
@@ -597,7 +598,9 @@ var AINamespace = class {
597
598
  response_format: request2.response_format,
598
599
  include: request2.include,
599
600
  stream: false,
600
- user: request2.user
601
+ user: request2.user,
602
+ timeout_ms: request2.timeout_ms,
603
+ max_cost_usd: request2.max_cost_usd
601
604
  })
602
605
  });
603
606
  if (!response.ok) {
@@ -645,7 +648,9 @@ var AINamespace = class {
645
648
  response_format: request2.response_format,
646
649
  include: request2.include,
647
650
  stream: true,
648
- user: request2.user
651
+ user: request2.user,
652
+ timeout_ms: request2.timeout_ms,
653
+ max_cost_usd: request2.max_cost_usd
649
654
  })
650
655
  });
651
656
  if (!response.ok) {
@@ -1039,6 +1044,57 @@ var VoiceNamespace = class {
1039
1044
  }
1040
1045
  };
1041
1046
 
1047
+ // src/judgment/index.ts
1048
+ var JudgmentNamespace = class {
1049
+ constructor(config) {
1050
+ this.config = config;
1051
+ }
1052
+ /**
1053
+ * Judge a state against typed questions. Returns one answer per
1054
+ * question id with probabilities your code can branch on.
1055
+ */
1056
+ async judge(request2) {
1057
+ if (request2.state === void 0 || request2.state === null) {
1058
+ throw new Error("judgment.judge requires `state`");
1059
+ }
1060
+ if (!request2.questions || Object.keys(request2.questions).length === 0) {
1061
+ throw new Error("judgment.judge requires a non-empty `questions` object");
1062
+ }
1063
+ const response = await fetch(`${this.config.baseUrl}/api/v1/judgments`, {
1064
+ method: "POST",
1065
+ headers: {
1066
+ "CENCORI_API_KEY": this.config.apiKey,
1067
+ "Content-Type": "application/json",
1068
+ ...this.config.headers
1069
+ },
1070
+ body: JSON.stringify(request2)
1071
+ });
1072
+ if (!response.ok) {
1073
+ throw await this.error(response, "judgment.judge");
1074
+ }
1075
+ return await response.json();
1076
+ }
1077
+ /** List the judgment models with their pricing. No API key required. */
1078
+ async listModels() {
1079
+ const response = await fetch(`${this.config.baseUrl}/api/v1/judgments`, {
1080
+ headers: this.config.headers
1081
+ });
1082
+ if (!response.ok) {
1083
+ throw await this.error(response, "judgment.listModels");
1084
+ }
1085
+ return await response.json();
1086
+ }
1087
+ async error(response, op) {
1088
+ const data = await response.json().catch(() => ({}));
1089
+ const message = data && typeof data === "object" && "message" in data && typeof data.message === "string" ? data.message : `${op} failed with status ${response.status}`;
1090
+ const code = data && typeof data === "object" && "error" in data && typeof data.error === "string" ? data.error : "request_failed";
1091
+ const err = new Error(message);
1092
+ err.code = code;
1093
+ err.details = data;
1094
+ return err;
1095
+ }
1096
+ };
1097
+
1042
1098
  // src/documents/index.ts
1043
1099
  function toBody2(request2, extra = {}) {
1044
1100
  const body = {
@@ -2610,6 +2666,7 @@ var Cencori = class {
2610
2666
  this.chat = new ChatNamespace(this.config);
2611
2667
  this.vision = new VisionNamespace(this.config);
2612
2668
  this.voice = new VoiceNamespace(this.config);
2669
+ this.judgment = new JudgmentNamespace(this.config);
2613
2670
  this.documents = new DocumentsNamespace(this.config);
2614
2671
  this.agents = new AgentsNamespace(this.config);
2615
2672
  this.compute = new ComputeNamespace();
@@ -2761,6 +2818,44 @@ function providerLogoUrl(providerId, baseUrl = DEFAULT_CATALOG_BASE_URL) {
2761
2818
  }
2762
2819
 
2763
2820
  // src/vercel/cencori-chat-model.ts
2821
+ function extractStreamError(chunk) {
2822
+ const error = chunk.error;
2823
+ if (typeof error === "string" && error) return error;
2824
+ if (error && typeof error === "object") {
2825
+ const record = error;
2826
+ if (typeof record.message === "string" && record.message) {
2827
+ return record.message;
2828
+ }
2829
+ try {
2830
+ return JSON.stringify(error);
2831
+ } catch {
2832
+ return "Provider stream error";
2833
+ }
2834
+ }
2835
+ if (typeof chunk.message === "string" && chunk.message && chunk.delta === void 0 && chunk.finish_reason === void 0 && chunk.tool_calls === void 0 && chunk.toolCalls === void 0 && chunk.usage === void 0) {
2836
+ return chunk.message;
2837
+ }
2838
+ return void 0;
2839
+ }
2840
+ function extractHttpError(body, fallback) {
2841
+ if (!body || typeof body !== "object") return fallback;
2842
+ const record = body;
2843
+ if (typeof record.message === "string" && record.message) return record.message;
2844
+ const error = record.error;
2845
+ if (typeof error === "string" && error) {
2846
+ return typeof record.message === "string" && record.message ? record.message : error;
2847
+ }
2848
+ if (error && typeof error === "object") {
2849
+ const nested = error;
2850
+ if (typeof nested.message === "string" && nested.message) return nested.message;
2851
+ try {
2852
+ return JSON.stringify(error);
2853
+ } catch {
2854
+ return fallback;
2855
+ }
2856
+ }
2857
+ return fallback;
2858
+ }
2764
2859
  var CencoriChatLanguageModel = class {
2765
2860
  constructor(modelId, settings) {
2766
2861
  this.specificationVersion = "v3";
@@ -2899,8 +2994,10 @@ var CencoriChatLanguageModel = class {
2899
2994
  signal: options.abortSignal
2900
2995
  });
2901
2996
  if (!response.ok) {
2902
- const error = await response.json().catch(() => ({ error: "Unknown error" }));
2903
- throw new Error(`Cencori API error: ${error.error || response.statusText}`);
2997
+ const body = await response.json().catch(() => ({ error: "Unknown error" }));
2998
+ throw new Error(
2999
+ `Cencori API error: ${extractHttpError(body, response.statusText)}`
3000
+ );
2904
3001
  }
2905
3002
  const data = await response.json();
2906
3003
  const content = [];
@@ -2951,8 +3048,10 @@ var CencoriChatLanguageModel = class {
2951
3048
  signal: options.abortSignal
2952
3049
  });
2953
3050
  if (!response.ok) {
2954
- const error = await response.json().catch(() => ({ error: "Unknown error" }));
2955
- throw new Error(`Cencori API error: ${error.error || response.statusText}`);
3051
+ const body = await response.json().catch(() => ({ error: "Unknown error" }));
3052
+ throw new Error(
3053
+ `Cencori API error: ${extractHttpError(body, response.statusText)}`
3054
+ );
2956
3055
  }
2957
3056
  const reader = response.body?.getReader();
2958
3057
  if (!reader) {
@@ -3007,6 +3106,15 @@ var CencoriChatLanguageModel = class {
3007
3106
  }
3008
3107
  try {
3009
3108
  const chunk = JSON.parse(data);
3109
+ const streamError = extractStreamError(
3110
+ chunk
3111
+ );
3112
+ if (streamError) {
3113
+ controller.error(
3114
+ new Error(`Cencori API error: ${streamError}`)
3115
+ );
3116
+ return;
3117
+ }
3010
3118
  if (chunk.delta) {
3011
3119
  if (!started) {
3012
3120
  started = true;
@@ -3022,8 +3130,9 @@ var CencoriChatLanguageModel = class {
3022
3130
  delta: chunk.delta
3023
3131
  });
3024
3132
  }
3025
- if (chunk.tool_calls && chunk.tool_calls.length > 0) {
3026
- for (const tc of chunk.tool_calls) {
3133
+ const toolCalls = chunk.tool_calls && chunk.tool_calls.length > 0 ? chunk.tool_calls : chunk.toolCalls && chunk.toolCalls.length > 0 ? chunk.toolCalls : void 0;
3134
+ if (toolCalls) {
3135
+ for (const tc of toolCalls) {
3027
3136
  controller.enqueue({
3028
3137
  type: "tool-call",
3029
3138
  toolCallId: tc.id,
@@ -3034,6 +3143,14 @@ var CencoriChatLanguageModel = class {
3034
3143
  }
3035
3144
  }
3036
3145
  if (chunk.finish_reason) {
3146
+ if (chunk.finish_reason === "error") {
3147
+ controller.error(
3148
+ new Error(
3149
+ `Cencori API error: ${extractStreamError(chunk) ?? "stream failed with error"}`
3150
+ )
3151
+ );
3152
+ return;
3153
+ }
3037
3154
  if (started) {
3038
3155
  controller.enqueue({
3039
3156
  type: "text-end",
@@ -3116,6 +3233,7 @@ cencori.chat = cencori;
3116
3233
  DocumentsNamespace,
3117
3234
  EndUsersNamespace,
3118
3235
  InstallationsNamespace,
3236
+ JudgmentNamespace,
3119
3237
  KnowledgeNamespace,
3120
3238
  MEMORY_FETCH_TOOL,
3121
3239
  McpServersNamespace,