cencori 1.8.2 → 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.
package/README.md CHANGED
@@ -196,6 +196,27 @@ import { VisionUploader } from 'cencori/react';
196
196
 
197
197
  Full API in [docs](https://cencori.com/docs/ai/endpoints/vision).
198
198
 
199
+ ### Judgment (Structured Decisions)
200
+
201
+ Yes/no, choice, and score answers with probabilities over any state — no generated text. Any `judgment` catalog model works here (TypeSafe's Jev today).
202
+
203
+ ```typescript
204
+ const result = await cencori.judgment.judge({
205
+ state: 'I was charged twice. Please refund the duplicate.',
206
+ questions: {
207
+ department: {
208
+ type: 'choice',
209
+ instructions: 'Which team should handle this?',
210
+ criteria: { billing: 'Payments, invoicing, refunds', technical: 'Bugs, outages' },
211
+ },
212
+ requests_refund: { type: 'noul', instructions: 'Does the customer request a refund?' },
213
+ },
214
+ });
215
+ // result.answers.department.choice === 'billing'
216
+ ```
217
+
218
+ Full API in [docs](https://cencori.com/docs/api/judgments).
219
+
199
220
  ### Documents (PDF & Image Extraction)
200
221
 
201
222
  Extract text from PDFs and images, summarize documents, and answer questions about them. Text-based PDFs use native parsing — no LLM tokens, free.
package/dist/index.d.mts CHANGED
@@ -6,6 +6,8 @@ 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';
@@ -1029,6 +1031,22 @@ declare class Cencori {
1029
1031
  * });
1030
1032
  */
1031
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;
1032
1050
  /**
1033
1051
  * Documents - Extract text from PDFs and images, summarize, and query
1034
1052
  *
@@ -1239,4 +1257,4 @@ declare class SafetyError extends CencoriError {
1239
1257
  */
1240
1258
  declare function fetchWithRetry(url: string, options: RequestInit, maxRetries?: number): Promise<Response>;
1241
1259
 
1242
- 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
@@ -6,6 +6,8 @@ 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';
@@ -1029,6 +1031,22 @@ declare class Cencori {
1029
1031
  * });
1030
1032
  */
1031
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;
1032
1050
  /**
1033
1051
  * Documents - Extract text from PDFs and images, summarize, and query
1034
1052
  *
@@ -1239,4 +1257,4 @@ declare class SafetyError extends CencoriError {
1239
1257
  */
1240
1258
  declare function fetchWithRetry(url: string, options: RequestInit, maxRetries?: number): Promise<Response>;
1241
1259
 
1242
- 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,
@@ -1043,6 +1044,57 @@ var VoiceNamespace = class {
1043
1044
  }
1044
1045
  };
1045
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
+
1046
1098
  // src/documents/index.ts
1047
1099
  function toBody2(request2, extra = {}) {
1048
1100
  const body = {
@@ -2614,6 +2666,7 @@ var Cencori = class {
2614
2666
  this.chat = new ChatNamespace(this.config);
2615
2667
  this.vision = new VisionNamespace(this.config);
2616
2668
  this.voice = new VoiceNamespace(this.config);
2669
+ this.judgment = new JudgmentNamespace(this.config);
2617
2670
  this.documents = new DocumentsNamespace(this.config);
2618
2671
  this.agents = new AgentsNamespace(this.config);
2619
2672
  this.compute = new ComputeNamespace();
@@ -2765,6 +2818,44 @@ function providerLogoUrl(providerId, baseUrl = DEFAULT_CATALOG_BASE_URL) {
2765
2818
  }
2766
2819
 
2767
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
+ }
2768
2859
  var CencoriChatLanguageModel = class {
2769
2860
  constructor(modelId, settings) {
2770
2861
  this.specificationVersion = "v3";
@@ -2903,8 +2994,10 @@ var CencoriChatLanguageModel = class {
2903
2994
  signal: options.abortSignal
2904
2995
  });
2905
2996
  if (!response.ok) {
2906
- const error = await response.json().catch(() => ({ error: "Unknown error" }));
2907
- 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
+ );
2908
3001
  }
2909
3002
  const data = await response.json();
2910
3003
  const content = [];
@@ -2955,8 +3048,10 @@ var CencoriChatLanguageModel = class {
2955
3048
  signal: options.abortSignal
2956
3049
  });
2957
3050
  if (!response.ok) {
2958
- const error = await response.json().catch(() => ({ error: "Unknown error" }));
2959
- 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
+ );
2960
3055
  }
2961
3056
  const reader = response.body?.getReader();
2962
3057
  if (!reader) {
@@ -3011,6 +3106,15 @@ var CencoriChatLanguageModel = class {
3011
3106
  }
3012
3107
  try {
3013
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
+ }
3014
3118
  if (chunk.delta) {
3015
3119
  if (!started) {
3016
3120
  started = true;
@@ -3026,8 +3130,9 @@ var CencoriChatLanguageModel = class {
3026
3130
  delta: chunk.delta
3027
3131
  });
3028
3132
  }
3029
- if (chunk.tool_calls && chunk.tool_calls.length > 0) {
3030
- 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) {
3031
3136
  controller.enqueue({
3032
3137
  type: "tool-call",
3033
3138
  toolCallId: tc.id,
@@ -3038,6 +3143,14 @@ var CencoriChatLanguageModel = class {
3038
3143
  }
3039
3144
  }
3040
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
+ }
3041
3154
  if (started) {
3042
3155
  controller.enqueue({
3043
3156
  type: "text-end",
@@ -3120,6 +3233,7 @@ cencori.chat = cencori;
3120
3233
  DocumentsNamespace,
3121
3234
  EndUsersNamespace,
3122
3235
  InstallationsNamespace,
3236
+ JudgmentNamespace,
3123
3237
  KnowledgeNamespace,
3124
3238
  MEMORY_FETCH_TOOL,
3125
3239
  McpServersNamespace,