ghc-proxy 0.5.1 → 0.5.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/main.mjs +53 -27
- package/dist/main.mjs.map +1 -1
- package/package.json +2 -1
package/dist/main.mjs
CHANGED
|
@@ -5698,6 +5698,9 @@ function fromTranslationFailure(failure) {
|
|
|
5698
5698
|
type: "translation_error"
|
|
5699
5699
|
} });
|
|
5700
5700
|
}
|
|
5701
|
+
function previewBody(text, maxLength = 500) {
|
|
5702
|
+
return text.length > maxLength ? `${text.slice(0, maxLength)}…` : text;
|
|
5703
|
+
}
|
|
5701
5704
|
function isStructuredErrorPayload(value) {
|
|
5702
5705
|
return typeof value === "object" && value !== null && "error" in value && typeof value.error === "object" && value.error !== null;
|
|
5703
5706
|
}
|
|
@@ -5706,12 +5709,13 @@ function isStructuredErrorPayload(value) {
|
|
|
5706
5709
|
* Used by CopilotClient when upstream returns a non-OK response.
|
|
5707
5710
|
*/
|
|
5708
5711
|
async function throwUpstreamError(message, response) {
|
|
5712
|
+
let rawText = "";
|
|
5709
5713
|
let body;
|
|
5710
5714
|
try {
|
|
5711
|
-
|
|
5712
|
-
const json = JSON.parse(
|
|
5715
|
+
rawText = await response.text();
|
|
5716
|
+
const json = JSON.parse(rawText);
|
|
5713
5717
|
body = isStructuredErrorPayload(json) ? json : { error: {
|
|
5714
|
-
message:
|
|
5718
|
+
message: rawText,
|
|
5715
5719
|
type: "upstream_error"
|
|
5716
5720
|
} };
|
|
5717
5721
|
} catch {
|
|
@@ -5720,7 +5724,13 @@ async function throwUpstreamError(message, response) {
|
|
|
5720
5724
|
type: "upstream_error"
|
|
5721
5725
|
} };
|
|
5722
5726
|
}
|
|
5723
|
-
consola.error("Upstream error:",
|
|
5727
|
+
consola.error("Upstream error:", {
|
|
5728
|
+
status: response.status,
|
|
5729
|
+
statusText: response.statusText,
|
|
5730
|
+
url: response.url,
|
|
5731
|
+
body,
|
|
5732
|
+
rawBody: rawText ? previewBody(rawText) : "<empty>"
|
|
5733
|
+
});
|
|
5724
5734
|
throw new HTTPError(response.status, body);
|
|
5725
5735
|
}
|
|
5726
5736
|
|
|
@@ -5751,10 +5761,7 @@ var CopilotClient = class {
|
|
|
5751
5761
|
body: options.body,
|
|
5752
5762
|
signal: options.signal
|
|
5753
5763
|
});
|
|
5754
|
-
if (!response.ok)
|
|
5755
|
-
consola.error(errorMessage, response);
|
|
5756
|
-
await throwUpstreamError(errorMessage, response);
|
|
5757
|
-
}
|
|
5764
|
+
if (!response.ok) await throwUpstreamError(errorMessage, response);
|
|
5758
5765
|
return response;
|
|
5759
5766
|
}
|
|
5760
5767
|
/** Fetch and parse JSON response */
|
|
@@ -6225,7 +6232,7 @@ const checkUsage = defineCommand({
|
|
|
6225
6232
|
|
|
6226
6233
|
//#endregion
|
|
6227
6234
|
//#region src/lib/version.ts
|
|
6228
|
-
const VERSION = "0.5.
|
|
6235
|
+
const VERSION = "0.5.2";
|
|
6229
6236
|
|
|
6230
6237
|
//#endregion
|
|
6231
6238
|
//#region src/debug.ts
|
|
@@ -46711,8 +46718,8 @@ function inferModelFamily(model) {
|
|
|
46711
46718
|
const baseProfile = {
|
|
46712
46719
|
id: "base",
|
|
46713
46720
|
family: "other",
|
|
46714
|
-
enableCacheControl:
|
|
46715
|
-
includeUsageOnStream:
|
|
46721
|
+
enableCacheControl: true,
|
|
46722
|
+
includeUsageOnStream: true,
|
|
46716
46723
|
applyThinking(request) {
|
|
46717
46724
|
const thinking = request.thinking;
|
|
46718
46725
|
if (!thinking || thinking.type === "disabled") return {};
|
|
@@ -48467,7 +48474,10 @@ function parseAnthropicCountTokensPayload(payload) {
|
|
|
48467
48474
|
//#region src/lib/validation/embeddings.ts
|
|
48468
48475
|
const embeddingRequestSchema = object({
|
|
48469
48476
|
input: union([string(), array(string())]),
|
|
48470
|
-
model: string().min(1)
|
|
48477
|
+
model: string().min(1),
|
|
48478
|
+
dimensions: nonNegativeIntegerSchema.optional(),
|
|
48479
|
+
encoding_format: _enum(["float", "base64"]).optional(),
|
|
48480
|
+
user: string().min(1).optional()
|
|
48471
48481
|
}).loose();
|
|
48472
48482
|
function parseEmbeddingRequest(payload) {
|
|
48473
48483
|
return parsePayload(embeddingRequestSchema, "openai.embeddings", payload);
|
|
@@ -48923,12 +48933,18 @@ function createCompletionRoutes() {
|
|
|
48923
48933
|
|
|
48924
48934
|
//#endregion
|
|
48925
48935
|
//#region src/routes/embeddings/handler.ts
|
|
48936
|
+
function normalizeEmbeddingRequest(payload) {
|
|
48937
|
+
return {
|
|
48938
|
+
...payload,
|
|
48939
|
+
input: typeof payload.input === "string" ? [payload.input] : payload.input
|
|
48940
|
+
};
|
|
48941
|
+
}
|
|
48926
48942
|
/**
|
|
48927
48943
|
* Core handler for creating embeddings.
|
|
48928
48944
|
*/
|
|
48929
48945
|
async function handleEmbeddingsCore(body) {
|
|
48930
48946
|
const payload = parseEmbeddingRequest(body);
|
|
48931
|
-
return await createCopilotClient().createEmbeddings(payload);
|
|
48947
|
+
return await createCopilotClient().createEmbeddings(normalizeEmbeddingRequest(payload));
|
|
48932
48948
|
}
|
|
48933
48949
|
|
|
48934
48950
|
//#endregion
|
|
@@ -48956,10 +48972,16 @@ function createAnthropicAdapter() {
|
|
|
48956
48972
|
|
|
48957
48973
|
//#endregion
|
|
48958
48974
|
//#region src/routes/messages/count-tokens-handler.ts
|
|
48959
|
-
const
|
|
48960
|
-
|
|
48961
|
-
|
|
48962
|
-
|
|
48975
|
+
const TOOL_OVERHEAD_TOKENS = {
|
|
48976
|
+
claude: 346,
|
|
48977
|
+
grok: 480,
|
|
48978
|
+
gpt: 346
|
|
48979
|
+
};
|
|
48980
|
+
const ESTIMATION_FACTOR = {
|
|
48981
|
+
claude: 1.15,
|
|
48982
|
+
grok: 1.03,
|
|
48983
|
+
gpt: 1.1
|
|
48984
|
+
};
|
|
48963
48985
|
/**
|
|
48964
48986
|
* Core handler for counting tokens.
|
|
48965
48987
|
*/
|
|
@@ -48984,13 +49006,13 @@ async function handleCountTokensCore({ body, headers }) {
|
|
|
48984
49006
|
let mcpToolExist = false;
|
|
48985
49007
|
if (anthropicBeta?.startsWith("claude-code")) mcpToolExist = anthropicPayload.tools.some((tool) => tool.name.startsWith("mcp__"));
|
|
48986
49008
|
if (!mcpToolExist) {
|
|
48987
|
-
|
|
48988
|
-
|
|
49009
|
+
const overhead = TOOL_OVERHEAD_TOKENS[inferModelFamily(anthropicPayload.model)];
|
|
49010
|
+
if (overhead) tokenCount.input = tokenCount.input + overhead;
|
|
48989
49011
|
}
|
|
48990
49012
|
}
|
|
48991
49013
|
let finalTokenCount = tokenCount.input + tokenCount.output;
|
|
48992
|
-
|
|
48993
|
-
|
|
49014
|
+
const factor = ESTIMATION_FACTOR[inferModelFamily(anthropicPayload.model)];
|
|
49015
|
+
if (factor) finalTokenCount = Math.round(finalTokenCount * factor);
|
|
48994
49016
|
consola.info("Token count:", finalTokenCount);
|
|
48995
49017
|
return { input_tokens: finalTokenCount };
|
|
48996
49018
|
}
|
|
@@ -49188,12 +49210,15 @@ function translateAssistantMessage(message) {
|
|
|
49188
49210
|
continue;
|
|
49189
49211
|
}
|
|
49190
49212
|
if (SignatureCodec.isReasoningSignature(block.signature)) {
|
|
49191
|
-
|
|
49192
|
-
|
|
49193
|
-
|
|
49194
|
-
|
|
49195
|
-
|
|
49196
|
-
|
|
49213
|
+
const { id } = SignatureCodec.decodeReasoning(block.signature);
|
|
49214
|
+
if (id) {
|
|
49215
|
+
flushPendingContent(pendingContent, items, {
|
|
49216
|
+
role: "assistant",
|
|
49217
|
+
phase: assistantPhase
|
|
49218
|
+
});
|
|
49219
|
+
items.push(createReasoningContent(block));
|
|
49220
|
+
continue;
|
|
49221
|
+
}
|
|
49197
49222
|
}
|
|
49198
49223
|
}
|
|
49199
49224
|
const converted = translateAssistantContentBlock(block);
|
|
@@ -49831,6 +49856,7 @@ var ResponsesStreamTranslator = class {
|
|
|
49831
49856
|
this.closeScalarBlock(`thinking:${rawEvent.output_index}`, events);
|
|
49832
49857
|
}
|
|
49833
49858
|
if (rawEvent.item.type === "function_call") {
|
|
49859
|
+
if (this.state.functionCallStateByOutputIndex.get(rawEvent.output_index)?.closed) return events;
|
|
49834
49860
|
const blockIndex = this.openFunctionCallBlock({
|
|
49835
49861
|
outputIndex: rawEvent.output_index,
|
|
49836
49862
|
toolCallId: rawEvent.item.call_id,
|