@hadoku/resume-bot 3.15.95 → 3.15.97
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/worker/llm.d.ts +18 -0
- package/dist/worker/llm.d.ts.map +1 -1
- package/dist/worker.js +41 -27
- package/package.json +2 -2
package/dist/worker/llm.d.ts
CHANGED
|
@@ -59,6 +59,24 @@ export type LLMEnv = Partial<Record<ProviderEnvKey, string>> & {
|
|
|
59
59
|
/** Substituted into Cloudflare's base URL, which carries it in the path. */
|
|
60
60
|
CLOUDFLARE_ACCOUNT_ID?: string;
|
|
61
61
|
};
|
|
62
|
+
/**
|
|
63
|
+
* The fetch every provider client uses. Two jobs:
|
|
64
|
+
*
|
|
65
|
+
* 1. A provider that names an `authHeader` wants its key THERE and NOWHERE
|
|
66
|
+
* ELSE, so the SDK's `Authorization: Bearer` is deleted from the outgoing
|
|
67
|
+
* Headers (a null defaultHeader is not reliably dropped on workerd).
|
|
68
|
+
*
|
|
69
|
+
* 2. An error body that is not shaped `{error: {...}}` is reshaped so it is.
|
|
70
|
+
* The openai SDK reads ONLY `body.error`, and when that key is missing it
|
|
71
|
+
* reports "400 status code (no body)" even though the body was there.
|
|
72
|
+
* Google's OpenAI-compatible surface answers errors as a JSON ARRAY,
|
|
73
|
+
* `[{"error": {...}}]`, so every Gemini refusal arrived as "(no body)" and
|
|
74
|
+
* its actual reason was thrown away. That blind spot is how a Gemini
|
|
75
|
+
* failure was misread as a header problem on 2026-09-15 and stayed broken.
|
|
76
|
+
*/
|
|
77
|
+
export declare function providerFetch(apiKey: string, authHeader?: string): (url: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
78
|
+
/** Rebuild a failed response so its body carries a top-level `error` the SDK can read. */
|
|
79
|
+
export declare function normalizeErrorBody(res: Response): Promise<Response>;
|
|
62
80
|
/**
|
|
63
81
|
* Build the provider chain from whatever keys are configured, in LLM_PROVIDERS
|
|
64
82
|
* order. Every provider speaks an OpenAI-compatible API, so a request can fall
|
package/dist/worker/llm.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"llm.d.ts","sourceRoot":"","sources":["../../worker/src/llm.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAA;AAC3B,OAAO,EAA6C,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAE/F;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,6EAA6E;IAC7E,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED;;;;;GAKG;AACH,qBAAa,qBAAsB,SAAQ,KAAK;gBAClC,OAAO,EAAE,MAAM;CAI5B;AAOD,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,WAAW,CAAA;IACrC,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAA;IACf;;;;;;;OAOG;IACH,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE;QACN,aAAa,EAAE,MAAM,CAAA;QACrB,iBAAiB,EAAE,MAAM,CAAA;QACzB,YAAY,EAAE,MAAM,CAAA;KACrB,CAAA;CACF;AAED,uFAAuF;AACvF,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;CACd;AAED,8EAA8E;AAC9E,MAAM,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAA;AAEpC,0EAA0E;AAC1E;;;;GAIG;AACH,MAAM,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC,GAAG;IAC7D,4EAA4E;IAC5E,qBAAqB,CAAC,EAAE,MAAM,CAAA;CAC/B,C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AAA;CAC/B,CAAA;AA2BD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,IACjD,KAAK,WAAW,GAAG,GAAG,EAAE,OAAO,WAAW,KAAG,OAAO,CAAC,QAAQ,CAAC,CAU7E;AAED,0FAA0F;AAC1F,wBAAsB,kBAAkB,CAAC,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAuBzE;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAqCrD;AA6FD;;;;;GAKG;AACH,wBAAsB,kBAAkB,CACtC,KAAK,EAAE,QAAQ,EACf,QAAQ,EAAE,WAAW,EAAE,EACvB,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,YAAY,CAAC,CAyBvB"}
|
package/dist/worker.js
CHANGED
|
@@ -41499,6 +41499,37 @@ function remainingMs(deadline) {
|
|
|
41499
41499
|
return deadline === void 0 ? Number.POSITIVE_INFINITY : deadline - Date.now();
|
|
41500
41500
|
}
|
|
41501
41501
|
const REQUEST_TIMEOUT_MS = 2e4;
|
|
41502
|
+
function providerFetch(apiKey, authHeader) {
|
|
41503
|
+
return async (url2, init) => {
|
|
41504
|
+
const headers = new Headers(init?.headers);
|
|
41505
|
+
if (authHeader) {
|
|
41506
|
+
headers.delete("authorization");
|
|
41507
|
+
headers.set(authHeader, apiKey);
|
|
41508
|
+
}
|
|
41509
|
+
const res = await fetch(url2, { ...init, headers });
|
|
41510
|
+
if (res.ok) return res;
|
|
41511
|
+
return normalizeErrorBody(res);
|
|
41512
|
+
};
|
|
41513
|
+
}
|
|
41514
|
+
async function normalizeErrorBody(res) {
|
|
41515
|
+
const text = await res.text();
|
|
41516
|
+
let body = text;
|
|
41517
|
+
let parsed;
|
|
41518
|
+
try {
|
|
41519
|
+
parsed = JSON.parse(text);
|
|
41520
|
+
} catch {
|
|
41521
|
+
parsed = void 0;
|
|
41522
|
+
}
|
|
41523
|
+
if (Array.isArray(parsed) && parsed.length > 0 && parsed[0] && typeof parsed[0] === "object") {
|
|
41524
|
+
body = JSON.stringify(parsed[0]);
|
|
41525
|
+
} else if (parsed !== void 0 && (typeof parsed !== "object" || parsed === null || !("error" in parsed))) {
|
|
41526
|
+
body = JSON.stringify({ error: { message: text.slice(0, 500) } });
|
|
41527
|
+
}
|
|
41528
|
+
const outHeaders = new Headers(res.headers);
|
|
41529
|
+
outHeaders.delete("content-encoding");
|
|
41530
|
+
outHeaders.delete("content-length");
|
|
41531
|
+
return new Response(body, { status: res.status, statusText: res.statusText, headers: outHeaders });
|
|
41532
|
+
}
|
|
41502
41533
|
function createLLMClient(env) {
|
|
41503
41534
|
const chain = [];
|
|
41504
41535
|
for (const p of LLM_PROVIDERS) {
|
|
@@ -41513,28 +41544,10 @@ function createLLMClient(env) {
|
|
|
41513
41544
|
client: new OpenAI({
|
|
41514
41545
|
apiKey,
|
|
41515
41546
|
baseURL: baseUrl,
|
|
41516
|
-
//
|
|
41517
|
-
//
|
|
41518
|
-
//
|
|
41519
|
-
|
|
41520
|
-
// bad request.
|
|
41521
|
-
//
|
|
41522
|
-
// Done in a fetch wrapper rather than `defaultHeaders: {Authorization:
|
|
41523
|
-
// null}`. The null form drops the header under openai 6.32 on Node, and
|
|
41524
|
-
// that is how it was verified, but the 400 persisted on workerd — so
|
|
41525
|
-
// the header was still reaching the wire. Deleting it from the outgoing
|
|
41526
|
-
// Headers is the only form that cannot be runtime-dependent.
|
|
41527
|
-
// Captured BEFORE the closure: narrowing `p.authHeader` at the `?:` does
|
|
41528
|
-
// not survive into a callback TypeScript must assume runs later, so the
|
|
41529
|
-
// header name has to be a plain string by the time it is used.
|
|
41530
|
-
...authHeader ? {
|
|
41531
|
-
fetch: (url2, init) => {
|
|
41532
|
-
const headers = new Headers(init?.headers);
|
|
41533
|
-
headers.delete("authorization");
|
|
41534
|
-
headers.set(authHeader, apiKey);
|
|
41535
|
-
return fetch(url2, { ...init, headers });
|
|
41536
|
-
}
|
|
41537
|
-
} : {},
|
|
41547
|
+
// Every provider goes through providerFetch: it moves the key for a
|
|
41548
|
+
// provider that names an `authHeader`, and unwraps an error body the SDK
|
|
41549
|
+
// would otherwise report as "(no body)". See providerFetch.
|
|
41550
|
+
fetch: providerFetch(apiKey, authHeader),
|
|
41538
41551
|
// Both of these MUST be set explicitly. The SDK defaults are a 10-minute
|
|
41539
41552
|
// timeout and 2 internal retries, which is catastrophic here: a hung
|
|
41540
41553
|
// provider would burn 30 minutes inside a request the edge gives 120s,
|
|
@@ -41612,18 +41625,19 @@ async function sendChatCompletion(chain, messages2, options) {
|
|
|
41612
41625
|
if (chain.length === 0) {
|
|
41613
41626
|
throw new Error("No LLM providers configured (set GROQ_API_KEY or GEMINI_API_KEY)");
|
|
41614
41627
|
}
|
|
41615
|
-
|
|
41628
|
+
const failures = [];
|
|
41616
41629
|
for (let i = 0; i < chain.length; i++) {
|
|
41617
41630
|
const isLast = i === chain.length - 1;
|
|
41618
41631
|
try {
|
|
41619
41632
|
return await callProvider(chain[i], messages2, options, isLast);
|
|
41620
41633
|
} catch (err) {
|
|
41621
|
-
|
|
41622
|
-
if (err instanceof DeadlineExceededError)
|
|
41623
|
-
|
|
41634
|
+
failures.push(`${chain[i].name}: ${err instanceof Error ? err.message : String(err)}`);
|
|
41635
|
+
if (err instanceof DeadlineExceededError) {
|
|
41636
|
+
throw new DeadlineExceededError(failures.join("; "));
|
|
41637
|
+
}
|
|
41624
41638
|
}
|
|
41625
41639
|
}
|
|
41626
|
-
throw
|
|
41640
|
+
throw new Error(`All LLM providers failed: ${failures.join("; ")}`);
|
|
41627
41641
|
}
|
|
41628
41642
|
const CACHE_TTL_SECONDS$2 = 2592e3;
|
|
41629
41643
|
function stripCodeFence(text) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hadoku/resume-bot",
|
|
3
|
-
"version": "3.15.
|
|
4
|
-
"gitHead": "
|
|
3
|
+
"version": "3.15.97",
|
|
4
|
+
"gitHead": "1e6d0dc996e2c392f1d075004fa956f019c40f2f",
|
|
5
5
|
"description": "AI-powered conversational interface for interactive resume exploration",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|