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.
- package/README.md +21 -0
- package/dist/ai/index.d.mts +1 -1
- package/dist/ai/index.d.ts +1 -1
- package/dist/ai/index.js +6 -2
- package/dist/ai/index.js.map +1 -1
- package/dist/ai/index.mjs +6 -2
- package/dist/ai/index.mjs.map +1 -1
- package/dist/compute/index.d.mts +1 -1
- package/dist/compute/index.d.ts +1 -1
- package/dist/documents/index.d.mts +1 -1
- package/dist/documents/index.d.ts +1 -1
- package/dist/index.d.mts +31 -3
- package/dist/index.d.ts +31 -3
- package/dist/index.js +126 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +125 -8
- 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/memory/index.d.mts +1 -1
- package/dist/memory/index.d.ts +1 -1
- package/dist/storage/index.d.mts +1 -1
- package/dist/storage/index.d.ts +1 -1
- package/dist/telemetry/index.d.mts +1 -1
- package/dist/telemetry/index.d.ts +1 -1
- package/dist/{types-DbHh0iAg.d.mts → types-CAhDuNTz.d.mts} +4 -0
- package/dist/{types-DbHh0iAg.d.ts → types-CAhDuNTz.d.ts} +4 -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/dist/vision/index.d.mts +1 -1
- package/dist/vision/index.d.ts +1 -1
- package/dist/voice/index.d.mts +1 -1
- package/dist/voice/index.d.ts +1 -1
- package/dist/web/index.d.mts +1 -1
- package/dist/web/index.d.ts +1 -1
- package/dist/workflow/index.d.mts +1 -1
- package/dist/workflow/index.d.ts +1 -1
- package/package.json +6 -1
package/dist/index.mjs
CHANGED
|
@@ -525,7 +525,9 @@ var AINamespace = class {
|
|
|
525
525
|
response_format: request2.response_format,
|
|
526
526
|
include: request2.include,
|
|
527
527
|
stream: false,
|
|
528
|
-
user: request2.user
|
|
528
|
+
user: request2.user,
|
|
529
|
+
timeout_ms: request2.timeout_ms,
|
|
530
|
+
max_cost_usd: request2.max_cost_usd
|
|
529
531
|
})
|
|
530
532
|
});
|
|
531
533
|
if (!response.ok) {
|
|
@@ -573,7 +575,9 @@ var AINamespace = class {
|
|
|
573
575
|
response_format: request2.response_format,
|
|
574
576
|
include: request2.include,
|
|
575
577
|
stream: true,
|
|
576
|
-
user: request2.user
|
|
578
|
+
user: request2.user,
|
|
579
|
+
timeout_ms: request2.timeout_ms,
|
|
580
|
+
max_cost_usd: request2.max_cost_usd
|
|
577
581
|
})
|
|
578
582
|
});
|
|
579
583
|
if (!response.ok) {
|
|
@@ -967,6 +971,57 @@ var VoiceNamespace = class {
|
|
|
967
971
|
}
|
|
968
972
|
};
|
|
969
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
|
+
|
|
970
1025
|
// src/documents/index.ts
|
|
971
1026
|
function toBody2(request2, extra = {}) {
|
|
972
1027
|
const body = {
|
|
@@ -2538,6 +2593,7 @@ var Cencori = class {
|
|
|
2538
2593
|
this.chat = new ChatNamespace(this.config);
|
|
2539
2594
|
this.vision = new VisionNamespace(this.config);
|
|
2540
2595
|
this.voice = new VoiceNamespace(this.config);
|
|
2596
|
+
this.judgment = new JudgmentNamespace(this.config);
|
|
2541
2597
|
this.documents = new DocumentsNamespace(this.config);
|
|
2542
2598
|
this.agents = new AgentsNamespace(this.config);
|
|
2543
2599
|
this.compute = new ComputeNamespace();
|
|
@@ -2689,6 +2745,44 @@ function providerLogoUrl(providerId, baseUrl = DEFAULT_CATALOG_BASE_URL) {
|
|
|
2689
2745
|
}
|
|
2690
2746
|
|
|
2691
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
|
+
}
|
|
2692
2786
|
var CencoriChatLanguageModel = class {
|
|
2693
2787
|
constructor(modelId, settings) {
|
|
2694
2788
|
this.specificationVersion = "v3";
|
|
@@ -2827,8 +2921,10 @@ var CencoriChatLanguageModel = class {
|
|
|
2827
2921
|
signal: options.abortSignal
|
|
2828
2922
|
});
|
|
2829
2923
|
if (!response.ok) {
|
|
2830
|
-
const
|
|
2831
|
-
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
|
+
);
|
|
2832
2928
|
}
|
|
2833
2929
|
const data = await response.json();
|
|
2834
2930
|
const content = [];
|
|
@@ -2879,8 +2975,10 @@ var CencoriChatLanguageModel = class {
|
|
|
2879
2975
|
signal: options.abortSignal
|
|
2880
2976
|
});
|
|
2881
2977
|
if (!response.ok) {
|
|
2882
|
-
const
|
|
2883
|
-
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
|
+
);
|
|
2884
2982
|
}
|
|
2885
2983
|
const reader = response.body?.getReader();
|
|
2886
2984
|
if (!reader) {
|
|
@@ -2935,6 +3033,15 @@ var CencoriChatLanguageModel = class {
|
|
|
2935
3033
|
}
|
|
2936
3034
|
try {
|
|
2937
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
|
+
}
|
|
2938
3045
|
if (chunk.delta) {
|
|
2939
3046
|
if (!started) {
|
|
2940
3047
|
started = true;
|
|
@@ -2950,8 +3057,9 @@ var CencoriChatLanguageModel = class {
|
|
|
2950
3057
|
delta: chunk.delta
|
|
2951
3058
|
});
|
|
2952
3059
|
}
|
|
2953
|
-
|
|
2954
|
-
|
|
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) {
|
|
2955
3063
|
controller.enqueue({
|
|
2956
3064
|
type: "tool-call",
|
|
2957
3065
|
toolCallId: tc.id,
|
|
@@ -2962,6 +3070,14 @@ var CencoriChatLanguageModel = class {
|
|
|
2962
3070
|
}
|
|
2963
3071
|
}
|
|
2964
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
|
+
}
|
|
2965
3081
|
if (started) {
|
|
2966
3082
|
controller.enqueue({
|
|
2967
3083
|
type: "text-end",
|
|
@@ -3043,6 +3159,7 @@ export {
|
|
|
3043
3159
|
DocumentsNamespace,
|
|
3044
3160
|
EndUsersNamespace,
|
|
3045
3161
|
InstallationsNamespace,
|
|
3162
|
+
JudgmentNamespace,
|
|
3046
3163
|
KnowledgeNamespace2 as KnowledgeNamespace,
|
|
3047
3164
|
MEMORY_FETCH_TOOL,
|
|
3048
3165
|
McpServersNamespace,
|