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 +21 -0
- package/dist/index.d.mts +19 -1
- package/dist/index.d.ts +19 -1
- package/dist/index.js +120 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +119 -6
- package/dist/index.mjs.map +1 -1
- package/dist/judgment/index.d.mts +128 -0
- package/dist/judgment/index.d.ts +128 -0
- package/dist/judgment/index.js +79 -0
- package/dist/judgment/index.js.map +1 -0
- package/dist/judgment/index.mjs +54 -0
- package/dist/judgment/index.mjs.map +1 -0
- package/dist/vercel/index.js +66 -6
- package/dist/vercel/index.js.map +1 -1
- package/dist/vercel/index.mjs +66 -6
- package/dist/vercel/index.mjs.map +1 -1
- package/package.json +6 -1
package/dist/index.mjs
CHANGED
|
@@ -971,6 +971,57 @@ var VoiceNamespace = class {
|
|
|
971
971
|
}
|
|
972
972
|
};
|
|
973
973
|
|
|
974
|
+
// src/judgment/index.ts
|
|
975
|
+
var JudgmentNamespace = class {
|
|
976
|
+
constructor(config) {
|
|
977
|
+
this.config = config;
|
|
978
|
+
}
|
|
979
|
+
/**
|
|
980
|
+
* Judge a state against typed questions. Returns one answer per
|
|
981
|
+
* question id with probabilities your code can branch on.
|
|
982
|
+
*/
|
|
983
|
+
async judge(request2) {
|
|
984
|
+
if (request2.state === void 0 || request2.state === null) {
|
|
985
|
+
throw new Error("judgment.judge requires `state`");
|
|
986
|
+
}
|
|
987
|
+
if (!request2.questions || Object.keys(request2.questions).length === 0) {
|
|
988
|
+
throw new Error("judgment.judge requires a non-empty `questions` object");
|
|
989
|
+
}
|
|
990
|
+
const response = await fetch(`${this.config.baseUrl}/api/v1/judgments`, {
|
|
991
|
+
method: "POST",
|
|
992
|
+
headers: {
|
|
993
|
+
"CENCORI_API_KEY": this.config.apiKey,
|
|
994
|
+
"Content-Type": "application/json",
|
|
995
|
+
...this.config.headers
|
|
996
|
+
},
|
|
997
|
+
body: JSON.stringify(request2)
|
|
998
|
+
});
|
|
999
|
+
if (!response.ok) {
|
|
1000
|
+
throw await this.error(response, "judgment.judge");
|
|
1001
|
+
}
|
|
1002
|
+
return await response.json();
|
|
1003
|
+
}
|
|
1004
|
+
/** List the judgment models with their pricing. No API key required. */
|
|
1005
|
+
async listModels() {
|
|
1006
|
+
const response = await fetch(`${this.config.baseUrl}/api/v1/judgments`, {
|
|
1007
|
+
headers: this.config.headers
|
|
1008
|
+
});
|
|
1009
|
+
if (!response.ok) {
|
|
1010
|
+
throw await this.error(response, "judgment.listModels");
|
|
1011
|
+
}
|
|
1012
|
+
return await response.json();
|
|
1013
|
+
}
|
|
1014
|
+
async error(response, op) {
|
|
1015
|
+
const data = await response.json().catch(() => ({}));
|
|
1016
|
+
const message = data && typeof data === "object" && "message" in data && typeof data.message === "string" ? data.message : `${op} failed with status ${response.status}`;
|
|
1017
|
+
const code = data && typeof data === "object" && "error" in data && typeof data.error === "string" ? data.error : "request_failed";
|
|
1018
|
+
const err = new Error(message);
|
|
1019
|
+
err.code = code;
|
|
1020
|
+
err.details = data;
|
|
1021
|
+
return err;
|
|
1022
|
+
}
|
|
1023
|
+
};
|
|
1024
|
+
|
|
974
1025
|
// src/documents/index.ts
|
|
975
1026
|
function toBody2(request2, extra = {}) {
|
|
976
1027
|
const body = {
|
|
@@ -2542,6 +2593,7 @@ var Cencori = class {
|
|
|
2542
2593
|
this.chat = new ChatNamespace(this.config);
|
|
2543
2594
|
this.vision = new VisionNamespace(this.config);
|
|
2544
2595
|
this.voice = new VoiceNamespace(this.config);
|
|
2596
|
+
this.judgment = new JudgmentNamespace(this.config);
|
|
2545
2597
|
this.documents = new DocumentsNamespace(this.config);
|
|
2546
2598
|
this.agents = new AgentsNamespace(this.config);
|
|
2547
2599
|
this.compute = new ComputeNamespace();
|
|
@@ -2693,6 +2745,44 @@ function providerLogoUrl(providerId, baseUrl = DEFAULT_CATALOG_BASE_URL) {
|
|
|
2693
2745
|
}
|
|
2694
2746
|
|
|
2695
2747
|
// src/vercel/cencori-chat-model.ts
|
|
2748
|
+
function extractStreamError(chunk) {
|
|
2749
|
+
const error = chunk.error;
|
|
2750
|
+
if (typeof error === "string" && error) return error;
|
|
2751
|
+
if (error && typeof error === "object") {
|
|
2752
|
+
const record = error;
|
|
2753
|
+
if (typeof record.message === "string" && record.message) {
|
|
2754
|
+
return record.message;
|
|
2755
|
+
}
|
|
2756
|
+
try {
|
|
2757
|
+
return JSON.stringify(error);
|
|
2758
|
+
} catch {
|
|
2759
|
+
return "Provider stream error";
|
|
2760
|
+
}
|
|
2761
|
+
}
|
|
2762
|
+
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) {
|
|
2763
|
+
return chunk.message;
|
|
2764
|
+
}
|
|
2765
|
+
return void 0;
|
|
2766
|
+
}
|
|
2767
|
+
function extractHttpError(body, fallback) {
|
|
2768
|
+
if (!body || typeof body !== "object") return fallback;
|
|
2769
|
+
const record = body;
|
|
2770
|
+
if (typeof record.message === "string" && record.message) return record.message;
|
|
2771
|
+
const error = record.error;
|
|
2772
|
+
if (typeof error === "string" && error) {
|
|
2773
|
+
return typeof record.message === "string" && record.message ? record.message : error;
|
|
2774
|
+
}
|
|
2775
|
+
if (error && typeof error === "object") {
|
|
2776
|
+
const nested = error;
|
|
2777
|
+
if (typeof nested.message === "string" && nested.message) return nested.message;
|
|
2778
|
+
try {
|
|
2779
|
+
return JSON.stringify(error);
|
|
2780
|
+
} catch {
|
|
2781
|
+
return fallback;
|
|
2782
|
+
}
|
|
2783
|
+
}
|
|
2784
|
+
return fallback;
|
|
2785
|
+
}
|
|
2696
2786
|
var CencoriChatLanguageModel = class {
|
|
2697
2787
|
constructor(modelId, settings) {
|
|
2698
2788
|
this.specificationVersion = "v3";
|
|
@@ -2831,8 +2921,10 @@ var CencoriChatLanguageModel = class {
|
|
|
2831
2921
|
signal: options.abortSignal
|
|
2832
2922
|
});
|
|
2833
2923
|
if (!response.ok) {
|
|
2834
|
-
const
|
|
2835
|
-
throw new Error(
|
|
2924
|
+
const body = await response.json().catch(() => ({ error: "Unknown error" }));
|
|
2925
|
+
throw new Error(
|
|
2926
|
+
`Cencori API error: ${extractHttpError(body, response.statusText)}`
|
|
2927
|
+
);
|
|
2836
2928
|
}
|
|
2837
2929
|
const data = await response.json();
|
|
2838
2930
|
const content = [];
|
|
@@ -2883,8 +2975,10 @@ var CencoriChatLanguageModel = class {
|
|
|
2883
2975
|
signal: options.abortSignal
|
|
2884
2976
|
});
|
|
2885
2977
|
if (!response.ok) {
|
|
2886
|
-
const
|
|
2887
|
-
throw new Error(
|
|
2978
|
+
const body = await response.json().catch(() => ({ error: "Unknown error" }));
|
|
2979
|
+
throw new Error(
|
|
2980
|
+
`Cencori API error: ${extractHttpError(body, response.statusText)}`
|
|
2981
|
+
);
|
|
2888
2982
|
}
|
|
2889
2983
|
const reader = response.body?.getReader();
|
|
2890
2984
|
if (!reader) {
|
|
@@ -2939,6 +3033,15 @@ var CencoriChatLanguageModel = class {
|
|
|
2939
3033
|
}
|
|
2940
3034
|
try {
|
|
2941
3035
|
const chunk = JSON.parse(data);
|
|
3036
|
+
const streamError = extractStreamError(
|
|
3037
|
+
chunk
|
|
3038
|
+
);
|
|
3039
|
+
if (streamError) {
|
|
3040
|
+
controller.error(
|
|
3041
|
+
new Error(`Cencori API error: ${streamError}`)
|
|
3042
|
+
);
|
|
3043
|
+
return;
|
|
3044
|
+
}
|
|
2942
3045
|
if (chunk.delta) {
|
|
2943
3046
|
if (!started) {
|
|
2944
3047
|
started = true;
|
|
@@ -2954,8 +3057,9 @@ var CencoriChatLanguageModel = class {
|
|
|
2954
3057
|
delta: chunk.delta
|
|
2955
3058
|
});
|
|
2956
3059
|
}
|
|
2957
|
-
|
|
2958
|
-
|
|
3060
|
+
const toolCalls = chunk.tool_calls && chunk.tool_calls.length > 0 ? chunk.tool_calls : chunk.toolCalls && chunk.toolCalls.length > 0 ? chunk.toolCalls : void 0;
|
|
3061
|
+
if (toolCalls) {
|
|
3062
|
+
for (const tc of toolCalls) {
|
|
2959
3063
|
controller.enqueue({
|
|
2960
3064
|
type: "tool-call",
|
|
2961
3065
|
toolCallId: tc.id,
|
|
@@ -2966,6 +3070,14 @@ var CencoriChatLanguageModel = class {
|
|
|
2966
3070
|
}
|
|
2967
3071
|
}
|
|
2968
3072
|
if (chunk.finish_reason) {
|
|
3073
|
+
if (chunk.finish_reason === "error") {
|
|
3074
|
+
controller.error(
|
|
3075
|
+
new Error(
|
|
3076
|
+
`Cencori API error: ${extractStreamError(chunk) ?? "stream failed with error"}`
|
|
3077
|
+
)
|
|
3078
|
+
);
|
|
3079
|
+
return;
|
|
3080
|
+
}
|
|
2969
3081
|
if (started) {
|
|
2970
3082
|
controller.enqueue({
|
|
2971
3083
|
type: "text-end",
|
|
@@ -3047,6 +3159,7 @@ export {
|
|
|
3047
3159
|
DocumentsNamespace,
|
|
3048
3160
|
EndUsersNamespace,
|
|
3049
3161
|
InstallationsNamespace,
|
|
3162
|
+
JudgmentNamespace,
|
|
3050
3163
|
KnowledgeNamespace2 as KnowledgeNamespace,
|
|
3051
3164
|
MEMORY_FETCH_TOOL,
|
|
3052
3165
|
McpServersNamespace,
|