@konneal/engine 0.2.186 → 0.2.188
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/ask-TJK7DQ45.js +16 -0
- package/dist/{chunk-IZ3GSYMD.js → chunk-4AP763GX.js} +32 -25
- package/dist/{chunk-MZQEI4VJ.js → chunk-4BQA7PJ3.js} +1 -1
- package/dist/{chunk-PLONBTNM.js → chunk-A2HQNENL.js} +30 -28
- package/dist/{chunk-TKGBLDLK.js → chunk-G435JWGV.js} +4 -4
- package/dist/{chunk-BAOKHV2D.js → chunk-L32WSANI.js} +4 -4
- package/dist/{chunk-TLPUJMAF.js → chunk-NHYYMRZC.js} +1 -1
- package/dist/{chunk-5ISPTV5G.js → chunk-SLYQ6L52.js} +22 -16
- package/dist/{chunk-BMODSEKT.js → chunk-VT5ZHCOC.js} +3 -3
- package/dist/config.d.ts +17 -10
- package/dist/nameplate.d.ts +1 -1
- package/dist/quota.d.ts +3 -3
- package/dist/search-FJAOGMEO.js +14 -0
- package/dist/{tools-VMZSXLXM.js → tools-CYSL26HX.js} +4 -4
- package/dist/worker_mcp/src/index.js +2 -2
- package/dist/worker_public/src/config.js +3 -1
- package/dist/worker_public/src/index.js +10 -10
- package/dist/worker_public/src/requestScope.js +2 -2
- package/package.json +1 -1
- package/workers/worker_public/src/ai.ts +2 -3
- package/workers/worker_public/src/ask.ts +29 -23
- package/workers/worker_public/src/config.ts +41 -24
- package/workers/worker_public/src/quota.ts +12 -6
- package/workers/worker_public/src/understand.ts +6 -6
- package/dist/ask-CTYDXEQN.js +0 -16
- package/dist/search-5QSGBDBI.js +0 -14
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
handleAsk
|
|
3
|
+
} from "./chunk-A2HQNENL.js";
|
|
4
|
+
import "./chunk-IRCDOFP4.js";
|
|
5
|
+
import "./chunk-VT5ZHCOC.js";
|
|
6
|
+
import "./chunk-SLYQ6L52.js";
|
|
7
|
+
import "./chunk-L32WSANI.js";
|
|
8
|
+
import "./chunk-NHYYMRZC.js";
|
|
9
|
+
import "./chunk-ETLSWSZ7.js";
|
|
10
|
+
import "./chunk-4BQA7PJ3.js";
|
|
11
|
+
import "./chunk-4AP763GX.js";
|
|
12
|
+
import "./chunk-3FYJM7LH.js";
|
|
13
|
+
import "./chunk-YGQCVPX6.js";
|
|
14
|
+
export {
|
|
15
|
+
handleAsk
|
|
16
|
+
};
|
|
@@ -3,53 +3,56 @@ import {
|
|
|
3
3
|
} from "./chunk-3FYJM7LH.js";
|
|
4
4
|
|
|
5
5
|
// workers/worker_public/src/config.ts
|
|
6
|
+
var FLASH = "@cf/deepseek-ai/deepseek-v4.1-flash-1017";
|
|
6
7
|
var MODELS = {
|
|
7
8
|
embed: "@cf/qwen/qwen3-embedding-0.6b",
|
|
8
9
|
rerank: "@cf/baai/bge-reranker-base",
|
|
9
|
-
// ANSWER MODEL (all tiers
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
anon: "@cf/zai-org/glm-5.3-flash",
|
|
13
|
-
member: "@cf/zai-org/glm-5.3-flash",
|
|
10
|
+
// ANSWER MODEL (all tiers): natively multimodal (vision-unified contract)
|
|
11
|
+
anon: FLASH,
|
|
12
|
+
member: FLASH,
|
|
14
13
|
// figure captions + the vision lane (one-time, quality-first; the A/B
|
|
15
14
|
// lever is CAPTION_MODEL, the per-request arm is the admin route's
|
|
16
|
-
// body.model)
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
//
|
|
20
|
-
|
|
21
|
-
//
|
|
22
|
-
|
|
23
|
-
//
|
|
24
|
-
|
|
15
|
+
// body.model). It emptied on 8/24 figure images in the 2026-10-27 A/B —
|
|
16
|
+
// those captions fall to the serve-raw path.
|
|
17
|
+
caption: FLASH,
|
|
18
|
+
// the pairwise vision judge (sees the image; a THIRD model never judges
|
|
19
|
+
// its own arm) — no other live multimodal model exists in the policy
|
|
20
|
+
// line, so a v4.1 caption arm is judged by its own family
|
|
21
|
+
visionJudge: FLASH,
|
|
22
|
+
// the VLM figure rerank (TODO.sota/18.3): a vision-capable MoE scores
|
|
23
|
+
// figure IMAGES against figure-seeking questions — one bounded call per
|
|
24
|
+
// figure question, ablatable stage
|
|
25
|
+
vlmFigure: FLASH,
|
|
25
26
|
// the decision pass (TODO.decisions/01): clef-flash gates the
|
|
26
27
|
// requirement-shaped questions, clef decides the derived checklist
|
|
27
28
|
decisionsGate: "@cf/cloudflare/clef-flash",
|
|
28
29
|
decisionsModel: "@cf/cloudflare/clef",
|
|
29
|
-
// hot-path understanding/summarize
|
|
30
|
-
understand:
|
|
30
|
+
// hot-path understanding/summarize (cost-first lane)
|
|
31
|
+
understand: FLASH,
|
|
31
32
|
// the api_call act's intent-to-act mapping (TODO.ai-platform/09) — the
|
|
32
33
|
// operations deployment points ACTS_MODEL at the stronger reasoning
|
|
33
34
|
// tier; the floor is the understand lane
|
|
34
|
-
acts:
|
|
35
|
-
// generation fallback when the answer model is unavailable
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
acts: FLASH,
|
|
36
|
+
// generation fallback when the answer model is unavailable — the same
|
|
37
|
+
// model as the primary while it is the only live cheap option: the
|
|
38
|
+
// retry inside generateOnce is the only diversity this lane has
|
|
39
|
+
fallback: FLASH,
|
|
40
|
+
grader: FLASH,
|
|
41
|
+
// CRAG grader + judges
|
|
39
42
|
// contextual enrichment is the QUALITY-FIRST lane (one-time spend over
|
|
40
43
|
// the corpus, its quality persists into every future retrieval)
|
|
41
|
-
enrich: "@cf/
|
|
44
|
+
enrich: "@cf/zai-org/glm-5.3",
|
|
42
45
|
// final-tier listwise reranker for hard/member queries (cascade:
|
|
43
46
|
// cross-encoder prunes, listwise orders jointly)
|
|
44
47
|
listwise: "@cf/zai-org/glm-4.7-flash",
|
|
45
48
|
// deep-research loop (G10): bounded agentic iterations, members-only
|
|
46
|
-
escalation:
|
|
47
|
-
research:
|
|
49
|
+
escalation: FLASH,
|
|
50
|
+
research: FLASH,
|
|
48
51
|
// speculative draft-verify (TODO.sota/02 row 2): the strong verifier
|
|
49
52
|
// over the cheap drafts — the research-tier model verifies; the drafter
|
|
50
53
|
// is the standard answer model (MODELS.member). VERIFIER_MODEL swaps it
|
|
51
54
|
// live, same lever as every role.
|
|
52
|
-
verifier: "@cf/zai-org/glm-5.
|
|
55
|
+
verifier: "@cf/zai-org/glm-5.3"
|
|
53
56
|
};
|
|
54
57
|
var LIMITS = {
|
|
55
58
|
/** Attachment quotas (TODO.new-era/8): per-member ceilings so a member's
|
|
@@ -199,6 +202,9 @@ function effortBudget(effort) {
|
|
|
199
202
|
if (effort === "high" || effort === "max") return LIMITS.maxOutputTokens * 4;
|
|
200
203
|
return LIMITS.maxOutputTokens;
|
|
201
204
|
}
|
|
205
|
+
function generationSampling(model) {
|
|
206
|
+
return model.includes("deepseek") ? { temperature: 1, top_p: 1 } : { temperature: 0.6, top_p: 0.95 };
|
|
207
|
+
}
|
|
202
208
|
function requestEffort(env, session, requested) {
|
|
203
209
|
if (typeof requested !== "string" || !EFFORTS.has(requested)) return answerEffort(env);
|
|
204
210
|
if (requested === "low") return requested;
|
|
@@ -253,6 +259,7 @@ export {
|
|
|
253
259
|
roleModel,
|
|
254
260
|
answerEffort,
|
|
255
261
|
effortBudget,
|
|
262
|
+
generationSampling,
|
|
256
263
|
requestEffort,
|
|
257
264
|
DATASETS,
|
|
258
265
|
hasPermission,
|
|
@@ -33,7 +33,7 @@ import {
|
|
|
33
33
|
tableRetyped,
|
|
34
34
|
toolNote,
|
|
35
35
|
verdictNote
|
|
36
|
-
} from "./chunk-
|
|
36
|
+
} from "./chunk-VT5ZHCOC.js";
|
|
37
37
|
import {
|
|
38
38
|
NO_CONTEXT,
|
|
39
39
|
STAGE_NAMES,
|
|
@@ -76,18 +76,18 @@ import {
|
|
|
76
76
|
tokenBudget,
|
|
77
77
|
understandQuery,
|
|
78
78
|
usageTotal
|
|
79
|
-
} from "./chunk-
|
|
79
|
+
} from "./chunk-SLYQ6L52.js";
|
|
80
80
|
import {
|
|
81
81
|
embed,
|
|
82
82
|
generateOnce
|
|
83
|
-
} from "./chunk-
|
|
83
|
+
} from "./chunk-L32WSANI.js";
|
|
84
84
|
import {
|
|
85
85
|
corsHeaders,
|
|
86
86
|
err,
|
|
87
87
|
json,
|
|
88
88
|
readJson,
|
|
89
89
|
validateQuery
|
|
90
|
-
} from "./chunk-
|
|
90
|
+
} from "./chunk-NHYYMRZC.js";
|
|
91
91
|
import {
|
|
92
92
|
cacheableAnswer,
|
|
93
93
|
canonicalRefusal,
|
|
@@ -100,7 +100,7 @@ import {
|
|
|
100
100
|
requestSalt,
|
|
101
101
|
resolveRequestScope,
|
|
102
102
|
standardKeysFrom
|
|
103
|
-
} from "./chunk-
|
|
103
|
+
} from "./chunk-4BQA7PJ3.js";
|
|
104
104
|
import {
|
|
105
105
|
ESCALATION_DAILY_DEFAULT,
|
|
106
106
|
LIMITS,
|
|
@@ -108,11 +108,12 @@ import {
|
|
|
108
108
|
THRESHOLDS,
|
|
109
109
|
answerEffort,
|
|
110
110
|
effortBudget,
|
|
111
|
+
generationSampling,
|
|
111
112
|
num,
|
|
112
113
|
requestEffort,
|
|
113
114
|
roleModel,
|
|
114
115
|
sha256Hex
|
|
115
|
-
} from "./chunk-
|
|
116
|
+
} from "./chunk-4AP763GX.js";
|
|
116
117
|
import {
|
|
117
118
|
P
|
|
118
119
|
} from "./chunk-3FYJM7LH.js";
|
|
@@ -2296,8 +2297,7 @@ async function generateStream(env, model, messages, effort) {
|
|
|
2296
2297
|
stream: true,
|
|
2297
2298
|
max_tokens: effortBudget(effort ?? answerEffort(env)),
|
|
2298
2299
|
reasoning_effort: effort ?? answerEffort(env),
|
|
2299
|
-
|
|
2300
|
-
top_p: 0.95
|
|
2300
|
+
...generationSampling(model)
|
|
2301
2301
|
});
|
|
2302
2302
|
if (res && typeof res.getReader === "function") return res;
|
|
2303
2303
|
if (res && res.body && typeof res.body.getReader === "function") return res.body;
|
|
@@ -2318,13 +2318,14 @@ async function summarizeHistory(env, model, turns) {
|
|
|
2318
2318
|
},
|
|
2319
2319
|
{ role: "user", content: convo }
|
|
2320
2320
|
],
|
|
2321
|
-
|
|
2321
|
+
// reasoning tokens share this budget — DeepSeek-V4 needs 3072+ or
|
|
2322
|
+
// the summary is never reached
|
|
2323
|
+
max_tokens: model.includes("deepseek") ? 3072 : 2048,
|
|
2322
2324
|
reasoning_effort: "low",
|
|
2325
|
+
...generationSampling(model),
|
|
2323
2326
|
// Qwen3 thinking-mode sampling (model card) — prevents the
|
|
2324
2327
|
// repetition loops that eat the budget before the summary lands
|
|
2325
|
-
|
|
2326
|
-
top_p: 0.95,
|
|
2327
|
-
top_k: 20
|
|
2328
|
+
...model.includes("deepseek") ? {} : { top_k: 20 }
|
|
2328
2329
|
});
|
|
2329
2330
|
const text = typeof res?.response === "string" ? res.response : res?.choices?.[0]?.message?.content;
|
|
2330
2331
|
return typeof text === "string" && text.trim() ? text.trim().slice(0, 1200) : null;
|
|
@@ -2342,10 +2343,10 @@ function messageChars(messages) {
|
|
|
2342
2343
|
}
|
|
2343
2344
|
return n;
|
|
2344
2345
|
}
|
|
2345
|
-
async function chargeAnswerTokens(env, bucketId, stats, promptChars, answerChars, extraTokens = 0) {
|
|
2346
|
+
async function chargeAnswerTokens(env, bucketId, stats, promptChars, answerChars, extraTokens = 0, keyDayLimitAsks) {
|
|
2346
2347
|
const total = (usageTotal(stats?.usage) ?? estimateTokens(promptChars + answerChars)) + extraTokens;
|
|
2347
2348
|
await chargeTokens(env, bucketId, total);
|
|
2348
|
-
const budget = await tokenBudget(env, bucketId);
|
|
2349
|
+
const budget = await tokenBudget(env, bucketId, keyDayLimitAsks);
|
|
2349
2350
|
return { tokens_used: budget.used, token_limit: budget.limit };
|
|
2350
2351
|
}
|
|
2351
2352
|
async function* sseTokens(stream, stats) {
|
|
@@ -2407,14 +2408,15 @@ async function handleAsk(env, ctx, req, tier, key) {
|
|
|
2407
2408
|
const memberKey = tier === "key" ? key?.owner_sub ?? null : null;
|
|
2408
2409
|
const limit = memberKey ? num(env, "MEMBER_DAY_ASK", 300) : tier === "key" ? key.day_limit : tier === "member" || member ? num(env, "MEMBER_DAY_ASK", 300) : num(env, "ANON_DAY_ASK", 20);
|
|
2409
2410
|
const bucketId = memberKey ? `sub:${memberKey}` : tier === "key" ? `key:${key.id}` : member ? `sub:${member.sub}` : clientIp(req);
|
|
2411
|
+
const keyDayLimit = tier === "key" ? key?.day_limit : void 0;
|
|
2410
2412
|
const quota = await checkQuota(env, "ask", bucketId, limit, effort === "low" ? 1 : 2);
|
|
2411
2413
|
const creditPreview = creditEstimate({ effort, toolTurns: body?.multi_turn !== false ? 3 : 0, image: false });
|
|
2412
2414
|
if (!quota.ok) {
|
|
2413
2415
|
return err(429, "quota_exceeded", `Daily question limit reached (${quota.limit}). Try again tomorrow.`);
|
|
2414
2416
|
}
|
|
2415
|
-
const tokBudget = await tokenBudget(env, bucketId);
|
|
2417
|
+
const tokBudget = await tokenBudget(env, bucketId, keyDayLimit);
|
|
2416
2418
|
if (tokBudget.used >= tokBudget.limit) {
|
|
2417
|
-
const cb = await creditBudget(env, bucketId);
|
|
2419
|
+
const cb = await creditBudget(env, bucketId, keyDayLimit);
|
|
2418
2420
|
return err(429, "quota_exceeded", `Daily credits reached (${cb.credits_limit} credits, ${cb.credits_used} used). Try again tomorrow.`);
|
|
2419
2421
|
}
|
|
2420
2422
|
quota.tokens_used = tokBudget.used;
|
|
@@ -2705,7 +2707,7 @@ Certificates are issued per recommendation family \u2014 the register carries no
|
|
|
2705
2707
|
aggregateNoteText = aggregateNote(agg);
|
|
2706
2708
|
const queryHash2 = await sha256Hex(q2.query);
|
|
2707
2709
|
telemetry(env, ctx, tier, "ask", MODELS.member, true, answer2.length, queryHash2, q2.lang, void 0, telemetryMeta());
|
|
2708
|
-
const tq2 = await chargeAnswerTokens(env, bucketId, void 0, q2.query.length, answer2.length);
|
|
2710
|
+
const tq2 = await chargeAnswerTokens(env, bucketId, void 0, q2.query.length, answer2.length, keyDayLimit);
|
|
2709
2711
|
const payload = {
|
|
2710
2712
|
answer: answer2,
|
|
2711
2713
|
citations: [{ docidentifier: `${P().publisher.name}-CS certificate register (family ${agg.family})`, corpus: "register" }],
|
|
@@ -2716,7 +2718,7 @@ Certificates are issued per recommendation family \u2014 the register carries no
|
|
|
2716
2718
|
context_applied: NO_CONTEXT,
|
|
2717
2719
|
read: readAs(),
|
|
2718
2720
|
...ablate ? { ablate } : {},
|
|
2719
|
-
quota: { ...quota, ...tq2, credits: await creditBudget(env, bucketId), credit_estimate: creditPreview }
|
|
2721
|
+
quota: { ...quota, ...tq2, credits: await creditBudget(env, bucketId, keyDayLimit), credit_estimate: creditPreview }
|
|
2720
2722
|
};
|
|
2721
2723
|
if (live2) {
|
|
2722
2724
|
live2.send({ type: "citations", citations: payload.citations, quota: payload.quota, context_applied: NO_CONTEXT });
|
|
@@ -2761,8 +2763,8 @@ ${summary}` }] : [],
|
|
|
2761
2763
|
}
|
|
2762
2764
|
} catch {
|
|
2763
2765
|
}
|
|
2764
|
-
const tq2 = await chargeAnswerTokens(env, bucketId, stats, messageChars(messages2), full.length, probeTokensUsed);
|
|
2765
|
-
live2.send({ type: "quota", quota: { ...quota, ...tq2, credits: await creditBudget(env, bucketId), credit_estimate: creditPreview } });
|
|
2766
|
+
const tq2 = await chargeAnswerTokens(env, bucketId, stats, messageChars(messages2), full.length, probeTokensUsed, keyDayLimit);
|
|
2767
|
+
live2.send({ type: "quota", quota: { ...quota, ...tq2, credits: await creditBudget(env, bucketId, keyDayLimit), credit_estimate: creditPreview } });
|
|
2766
2768
|
live2.send({ type: "done", model, query_hash: queryHash2, context_applied: NO_CONTEXT, read: readAs() });
|
|
2767
2769
|
telemetry(env, ctx, tier, "ask", model, true, full.length, queryHash2, q2.lang, void 0, telemetryMeta());
|
|
2768
2770
|
live2.close();
|
|
@@ -2810,8 +2812,8 @@ ${summary}` }] : [],
|
|
|
2810
2812
|
live2.close();
|
|
2811
2813
|
return null;
|
|
2812
2814
|
}
|
|
2813
|
-
const tq2 = await chargeAnswerTokens(env, bucketId, void 0, q2.query.length, verdict.answer.length);
|
|
2814
|
-
return json({ answer: verdict.answer, citations: citations2, model, query_hash: queryHash2, follow_ups: [], context_applied: draftCtxApplied, read: readAs(), ...draftPayload ? { draft: draftPayload } : {}, ...ablate ? { ablate } : {}, quota: { ...quota, ...tq2, credits: await creditBudget(env, bucketId), credit_estimate: creditPreview } });
|
|
2815
|
+
const tq2 = await chargeAnswerTokens(env, bucketId, void 0, q2.query.length, verdict.answer.length, keyDayLimit);
|
|
2816
|
+
return json({ answer: verdict.answer, citations: citations2, model, query_hash: queryHash2, follow_ups: [], context_applied: draftCtxApplied, read: readAs(), ...draftPayload ? { draft: draftPayload } : {}, ...ablate ? { ablate } : {}, quota: { ...quota, ...tq2, credits: await creditBudget(env, bucketId, keyDayLimit), credit_estimate: creditPreview } });
|
|
2815
2817
|
}
|
|
2816
2818
|
if (apiCallIntent) {
|
|
2817
2819
|
const callCtxApplied = declaredCtx ? appliedContext(declaredCtx, null) : NO_CONTEXT;
|
|
@@ -2835,8 +2837,8 @@ ${summary}` }] : [],
|
|
|
2835
2837
|
live2.close();
|
|
2836
2838
|
return null;
|
|
2837
2839
|
}
|
|
2838
|
-
const tq2 = await chargeAnswerTokens(env, bucketId, void 0, q2.query.length, verdict.answer.length);
|
|
2839
|
-
return json({ answer: verdict.answer, citations: [], model, query_hash: queryHash2, follow_ups: [], context_applied: callCtxApplied, read: readAs(), ...draftPayload ? { draft: draftPayload } : {}, ...ablate ? { ablate } : {}, quota: { ...quota, ...tq2, credits: await creditBudget(env, bucketId), credit_estimate: creditPreview } });
|
|
2840
|
+
const tq2 = await chargeAnswerTokens(env, bucketId, void 0, q2.query.length, verdict.answer.length, keyDayLimit);
|
|
2841
|
+
return json({ answer: verdict.answer, citations: [], model, query_hash: queryHash2, follow_ups: [], context_applied: callCtxApplied, read: readAs(), ...draftPayload ? { draft: draftPayload } : {}, ...ablate ? { ablate } : {}, quota: { ...quota, ...tq2, credits: await creditBudget(env, bucketId, keyDayLimit), credit_estimate: creditPreview } });
|
|
2840
2842
|
}
|
|
2841
2843
|
let liveRecords;
|
|
2842
2844
|
let accountNote;
|
|
@@ -3299,8 +3301,8 @@ ${doc.text}` }
|
|
|
3299
3301
|
}
|
|
3300
3302
|
} catch {
|
|
3301
3303
|
}
|
|
3302
|
-
const tq2 = await chargeAnswerTokens(env, bucketId, stats, messageChars(messages), full.length, probeTokensUsed);
|
|
3303
|
-
send({ type: "quota", quota: { ...quota, ...tq2, credits: await creditBudget(env, bucketId), credit_estimate: creditPreview } });
|
|
3304
|
+
const tq2 = await chargeAnswerTokens(env, bucketId, stats, messageChars(messages), full.length, probeTokensUsed, keyDayLimit);
|
|
3305
|
+
send({ type: "quota", quota: { ...quota, ...tq2, credits: await creditBudget(env, bucketId, keyDayLimit), credit_estimate: creditPreview } });
|
|
3304
3306
|
if (register?.rows?.length && full.includes(refusalAnswer())) {
|
|
3305
3307
|
console.log("blind-answer(stream): regenerating once");
|
|
3306
3308
|
streamRestarts += 1;
|
|
@@ -3606,7 +3608,7 @@ ${doc.text}` }
|
|
|
3606
3608
|
text: h.text.slice(0, 1200),
|
|
3607
3609
|
...h.metadata.table_selection ? { sel: h.metadata.table_selection } : {}
|
|
3608
3610
|
}));
|
|
3609
|
-
const tq = await chargeAnswerTokens(env, bucketId, void 0, messageChars(messages), answer.length, probeTokensUsed);
|
|
3611
|
+
const tq = await chargeAnswerTokens(env, bucketId, void 0, messageChars(messages), answer.length, probeTokensUsed, keyDayLimit);
|
|
3610
3612
|
let cragPassages = null;
|
|
3611
3613
|
if (body?.manifest === true && used.length) {
|
|
3612
3614
|
const grades = await gradePassages(env.AI, roleModel(env, "grader"), q2.query, used.map((h) => h.text));
|
|
@@ -3632,7 +3634,7 @@ ${doc.text}` }
|
|
|
3632
3634
|
entailment,
|
|
3633
3635
|
total_ms: Date.now() - tStart
|
|
3634
3636
|
} } : {};
|
|
3635
|
-
return json({ ...out, context: contextOut, read: readAs(), ...manifestOut, quota: { ...quota, ...tq, credits: await creditBudget(env, bucketId), credit_estimate: creditPreview } }, 200, { ...corsHeaders(req), "server-timing": serverTiming() });
|
|
3637
|
+
return json({ ...out, context: contextOut, read: readAs(), ...manifestOut, quota: { ...quota, ...tq, credits: await creditBudget(env, bucketId, keyDayLimit), credit_estimate: creditPreview } }, 200, { ...corsHeaders(req), "server-timing": serverTiming() });
|
|
3636
3638
|
};
|
|
3637
3639
|
if (liveResponse) {
|
|
3638
3640
|
void pipeline(live, q).catch(() => {
|
|
@@ -6,24 +6,24 @@ import {
|
|
|
6
6
|
sessionFrom,
|
|
7
7
|
telemetry,
|
|
8
8
|
understandQuery
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-SLYQ6L52.js";
|
|
10
10
|
import {
|
|
11
11
|
corsHeaders,
|
|
12
12
|
err,
|
|
13
13
|
json,
|
|
14
14
|
readJson,
|
|
15
15
|
validateQuery
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-NHYYMRZC.js";
|
|
17
17
|
import {
|
|
18
18
|
entitlementScope,
|
|
19
19
|
standardKeysFrom
|
|
20
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-4BQA7PJ3.js";
|
|
21
21
|
import {
|
|
22
22
|
LIMITS,
|
|
23
23
|
MODELS,
|
|
24
24
|
num,
|
|
25
25
|
sha256Hex
|
|
26
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-4AP763GX.js";
|
|
27
27
|
import {
|
|
28
28
|
portModelRunner
|
|
29
29
|
} from "./chunk-YGQCVPX6.js";
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
answerEffort,
|
|
3
|
-
effortBudget
|
|
4
|
-
|
|
3
|
+
effortBudget,
|
|
4
|
+
generationSampling
|
|
5
|
+
} from "./chunk-4AP763GX.js";
|
|
5
6
|
|
|
6
7
|
// workers/worker_public/src/ai.ts
|
|
7
8
|
var delay = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
@@ -35,8 +36,7 @@ async function generateOnce(env, model, messages, effort) {
|
|
|
35
36
|
messages,
|
|
36
37
|
max_tokens: effortBudget(effort ?? answerEffort(env)),
|
|
37
38
|
reasoning_effort: effort ?? answerEffort(env),
|
|
38
|
-
|
|
39
|
-
top_p: 0.95
|
|
39
|
+
...generationSampling(model)
|
|
40
40
|
}),
|
|
41
41
|
new Promise((r) => setTimeout(() => r(null), 12e4))
|
|
42
42
|
]);
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
2
|
embed,
|
|
3
3
|
rerank
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-L32WSANI.js";
|
|
5
5
|
import {
|
|
6
6
|
bubbleConfirmPage,
|
|
7
7
|
isAllowedBubbleOrigin
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-NHYYMRZC.js";
|
|
9
9
|
import {
|
|
10
10
|
DATASETS,
|
|
11
11
|
LIMITS,
|
|
12
12
|
MODELS,
|
|
13
13
|
THRESHOLDS,
|
|
14
|
+
generationSampling,
|
|
14
15
|
num,
|
|
15
16
|
processExpansion,
|
|
16
17
|
sha256Hex,
|
|
17
18
|
today
|
|
18
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-4AP763GX.js";
|
|
19
20
|
import {
|
|
20
21
|
P
|
|
21
22
|
} from "./chunk-3FYJM7LH.js";
|
|
@@ -24839,16 +24840,15 @@ async function understandQuery(ai, model, query, history, entities = []) {
|
|
|
24839
24840
|
],
|
|
24840
24841
|
// the model always reasons; reasoning tokens share this budget — too
|
|
24841
24842
|
// small and the JSON is never reached (understanding silently degrades).
|
|
24842
|
-
// GLM-5
|
|
24843
|
-
// not honored, so GLM needs
|
|
24844
|
-
max_tokens:
|
|
24843
|
+
// DeepSeek-V4 needs 3072+; GLM-5 defaults to reasoning_effort "max"
|
|
24844
|
+
// when the parameter is not honored, so GLM needs the same headroom.
|
|
24845
|
+
max_tokens: 3072,
|
|
24845
24846
|
reasoning_effort: "low",
|
|
24847
|
+
...generationSampling(model),
|
|
24846
24848
|
// Qwen3 thinking-mode sampling (model card): greedy/1.0 sampling
|
|
24847
24849
|
// degrades into repetition loops — the 10s/5s timeout nulls were the
|
|
24848
24850
|
// budget being eaten by loops, not by reasoning
|
|
24849
|
-
|
|
24850
|
-
top_p: 0.95,
|
|
24851
|
-
top_k: 20
|
|
24851
|
+
...model.includes("deepseek") ? {} : { top_k: 20 }
|
|
24852
24852
|
};
|
|
24853
24853
|
const ATTEMPT_TIMEOUTS = [1e4, 5e3];
|
|
24854
24854
|
for (let attempt2 = 0; attempt2 < ATTEMPT_TIMEOUTS.length; attempt2++) {
|
|
@@ -24902,13 +24902,19 @@ function estimateTokens(chars) {
|
|
|
24902
24902
|
function tokenTier(bucketId) {
|
|
24903
24903
|
return bucketId.startsWith("key:") ? "key" : bucketId.startsWith("sub:") ? "member" : "anon";
|
|
24904
24904
|
}
|
|
24905
|
-
function tokenLimit(env, bucketId) {
|
|
24905
|
+
function tokenLimit(env, bucketId, keyDayLimitAsks) {
|
|
24906
24906
|
const tier = tokenTier(bucketId);
|
|
24907
|
-
return tier === "key" ?
|
|
24908
|
-
|
|
24909
|
-
|
|
24907
|
+
return tier === "key" ? (
|
|
24908
|
+
// the key's OWN day_limit is the one truth for both counters (the
|
|
24909
|
+
// owner's 2026-11-09 ruling: the serving cap is for USERS, not
|
|
24910
|
+
// operators): 1 ask ≈ 2000 tokens, so day_limit × 2000 — the
|
|
24911
|
+
// default 2000 asks reproduces the historic 4M exactly
|
|
24912
|
+
keyDayLimitAsks ? keyDayLimitAsks * 2e3 : num(env, "KEY_DAY_TOKENS", 4e6)
|
|
24913
|
+
) : tier === "member" ? num(env, "MEMBER_DAY_TOKENS", 15e5) : num(env, "ANON_DAY_TOKENS", 3e5);
|
|
24914
|
+
}
|
|
24915
|
+
async function tokenBudget(env, bucketId, keyDayLimitAsks) {
|
|
24910
24916
|
const used = Number(await env.CACHE.get(`t:${today()}:ask:${await sha256Hex(bucketId)}`) ?? "0");
|
|
24911
|
-
return { used, limit: tokenLimit(env, bucketId) };
|
|
24917
|
+
return { used, limit: tokenLimit(env, bucketId, keyDayLimitAsks) };
|
|
24912
24918
|
}
|
|
24913
24919
|
async function chargeTokens(env, bucketId, tokens2) {
|
|
24914
24920
|
if (!(tokens2 > 0)) return;
|
|
@@ -24926,8 +24932,8 @@ var CREDIT_TOKEN_UNIT = 1e3;
|
|
|
24926
24932
|
function creditLimit(env, bucketId) {
|
|
24927
24933
|
return Math.floor(tokenLimit(env, bucketId) / CREDIT_TOKEN_UNIT);
|
|
24928
24934
|
}
|
|
24929
|
-
async function creditBudget(env, bucketId) {
|
|
24930
|
-
const b = await tokenBudget(env, bucketId);
|
|
24935
|
+
async function creditBudget(env, bucketId, keyDayLimitAsks) {
|
|
24936
|
+
const b = await tokenBudget(env, bucketId, keyDayLimitAsks);
|
|
24931
24937
|
return { credits_used: Math.ceil(b.used / CREDIT_TOKEN_UNIT), credits_limit: creditLimit(env, bucketId) };
|
|
24932
24938
|
}
|
|
24933
24939
|
function creditEstimate(opts) {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
embed
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-L32WSANI.js";
|
|
4
4
|
import {
|
|
5
5
|
standardKeysFrom
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-4BQA7PJ3.js";
|
|
7
7
|
import {
|
|
8
8
|
THRESHOLDS
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-4AP763GX.js";
|
|
10
10
|
import {
|
|
11
11
|
P
|
|
12
12
|
} from "./chunk-3FYJM7LH.js";
|
package/dist/config.d.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
export declare const MODELS: {
|
|
2
2
|
readonly embed: "@cf/qwen/qwen3-embedding-0.6b";
|
|
3
3
|
readonly rerank: "@cf/baai/bge-reranker-base";
|
|
4
|
-
readonly anon: "@cf/
|
|
5
|
-
readonly member: "@cf/
|
|
6
|
-
readonly caption: "@cf/
|
|
4
|
+
readonly anon: "@cf/deepseek-ai/deepseek-v4.1-flash-1017";
|
|
5
|
+
readonly member: "@cf/deepseek-ai/deepseek-v4.1-flash-1017";
|
|
6
|
+
readonly caption: "@cf/deepseek-ai/deepseek-v4.1-flash-1017";
|
|
7
7
|
readonly visionJudge: "@cf/deepseek-ai/deepseek-v4.1-flash-1017";
|
|
8
8
|
readonly vlmFigure: "@cf/deepseek-ai/deepseek-v4.1-flash-1017";
|
|
9
9
|
readonly decisionsGate: "@cf/cloudflare/clef-flash";
|
|
10
10
|
readonly decisionsModel: "@cf/cloudflare/clef";
|
|
11
|
-
readonly understand: "@cf/
|
|
12
|
-
readonly acts: "@cf/
|
|
13
|
-
readonly fallback: "@cf/
|
|
14
|
-
readonly grader: "@cf/deepseek-ai/deepseek-v4-flash-
|
|
15
|
-
readonly enrich: "@cf/
|
|
11
|
+
readonly understand: "@cf/deepseek-ai/deepseek-v4.1-flash-1017";
|
|
12
|
+
readonly acts: "@cf/deepseek-ai/deepseek-v4.1-flash-1017";
|
|
13
|
+
readonly fallback: "@cf/deepseek-ai/deepseek-v4.1-flash-1017";
|
|
14
|
+
readonly grader: "@cf/deepseek-ai/deepseek-v4.1-flash-1017";
|
|
15
|
+
readonly enrich: "@cf/zai-org/glm-5.3";
|
|
16
16
|
readonly listwise: "@cf/zai-org/glm-4.7-flash";
|
|
17
17
|
readonly escalation: "@cf/deepseek-ai/deepseek-v4.1-flash-1017";
|
|
18
|
-
readonly research: "@cf/
|
|
19
|
-
readonly verifier: "@cf/zai-org/glm-5.
|
|
18
|
+
readonly research: "@cf/deepseek-ai/deepseek-v4.1-flash-1017";
|
|
19
|
+
readonly verifier: "@cf/zai-org/glm-5.3";
|
|
20
20
|
};
|
|
21
21
|
export declare const LIMITS: {
|
|
22
22
|
/** Attachment quotas (TODO.new-era/8): per-member ceilings so a member's
|
|
@@ -157,6 +157,13 @@ export declare function answerEffort(env: any): string;
|
|
|
157
157
|
* 2026-09-12: medium at the flat 3072 budget scored 5/38 on the golden
|
|
158
158
|
* set — empty answers — versus 37–38/38 at low). */
|
|
159
159
|
export declare function effortBudget(effort: string): number;
|
|
160
|
+
/** Sampling follows the model's card (the 2026-08-30/31 incidents): the
|
|
161
|
+
* DeepSeek-V4 family degrades under tight sampling (temp 1.0 / top_p 1.0);
|
|
162
|
+
* GLM and Qwen thinking modes take 0.6 / 0.95. */
|
|
163
|
+
export declare function generationSampling(model: string): {
|
|
164
|
+
temperature: number;
|
|
165
|
+
top_p: number;
|
|
166
|
+
};
|
|
160
167
|
export declare function requestEffort(env: any, session: unknown, requested: unknown): string;
|
|
161
168
|
/** The corpus catalog — single source for /api/datasets, the assistant's
|
|
162
169
|
* self-description, and per-corpus model guidance. `session: true`
|
package/dist/nameplate.d.ts
CHANGED
|
@@ -2,4 +2,4 @@ import { nameplateRegisterQuery, type Nameplate } from "./nameplate-parse.ts";
|
|
|
2
2
|
export type { Nameplate };
|
|
3
3
|
export { nameplateRegisterQuery };
|
|
4
4
|
export declare function extractNameplate(ai: any, model: string, image: string): Promise<Nameplate | null>;
|
|
5
|
-
export declare const nameplateModel: () => "@cf/
|
|
5
|
+
export declare const nameplateModel: () => "@cf/deepseek-ai/deepseek-v4.1-flash-1017";
|
package/dist/quota.d.ts
CHANGED
|
@@ -16,8 +16,8 @@ export declare function telemetry(env: Env, ctx: Background, tier: string, route
|
|
|
16
16
|
retries?: number;
|
|
17
17
|
}): void;
|
|
18
18
|
export declare function estimateTokens(chars: number): number;
|
|
19
|
-
export declare function tokenLimit(env: Env, bucketId: string): number;
|
|
20
|
-
export declare function tokenBudget(env: Env, bucketId: string): Promise<{
|
|
19
|
+
export declare function tokenLimit(env: Env, bucketId: string, keyDayLimitAsks?: number): number;
|
|
20
|
+
export declare function tokenBudget(env: Env, bucketId: string, keyDayLimitAsks?: number): Promise<{
|
|
21
21
|
used: number;
|
|
22
22
|
limit: number;
|
|
23
23
|
}>;
|
|
@@ -25,7 +25,7 @@ export declare function chargeTokens(env: Env, bucketId: string, tokens: number)
|
|
|
25
25
|
export declare function usageTotal(usage: unknown): number | null;
|
|
26
26
|
export declare const CREDIT_TOKEN_UNIT = 1000;
|
|
27
27
|
export declare function creditLimit(env: Env, bucketId: string): number;
|
|
28
|
-
export declare function creditBudget(env: Env, bucketId: string): Promise<{
|
|
28
|
+
export declare function creditBudget(env: Env, bucketId: string, keyDayLimitAsks?: number): Promise<{
|
|
29
29
|
credits_used: number;
|
|
30
30
|
credits_limit: number;
|
|
31
31
|
}>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {
|
|
2
|
+
handleSearch
|
|
3
|
+
} from "./chunk-G435JWGV.js";
|
|
4
|
+
import "./chunk-SLYQ6L52.js";
|
|
5
|
+
import "./chunk-L32WSANI.js";
|
|
6
|
+
import "./chunk-NHYYMRZC.js";
|
|
7
|
+
import "./chunk-ETLSWSZ7.js";
|
|
8
|
+
import "./chunk-4BQA7PJ3.js";
|
|
9
|
+
import "./chunk-4AP763GX.js";
|
|
10
|
+
import "./chunk-3FYJM7LH.js";
|
|
11
|
+
import "./chunk-YGQCVPX6.js";
|
|
12
|
+
export {
|
|
13
|
+
handleSearch
|
|
14
|
+
};
|
|
@@ -4,10 +4,10 @@ import {
|
|
|
4
4
|
parseToolCall,
|
|
5
5
|
runTool,
|
|
6
6
|
toolNote
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import "./chunk-
|
|
9
|
-
import "./chunk-
|
|
10
|
-
import "./chunk-
|
|
7
|
+
} from "./chunk-VT5ZHCOC.js";
|
|
8
|
+
import "./chunk-L32WSANI.js";
|
|
9
|
+
import "./chunk-4BQA7PJ3.js";
|
|
10
|
+
import "./chunk-4AP763GX.js";
|
|
11
11
|
import "./chunk-3FYJM7LH.js";
|
|
12
12
|
import "./chunk-YGQCVPX6.js";
|
|
13
13
|
export {
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
datasetAllowed,
|
|
11
11
|
datasetsFor,
|
|
12
12
|
effortBudget,
|
|
13
|
+
generationSampling,
|
|
13
14
|
hasPermission,
|
|
14
15
|
num,
|
|
15
16
|
processExpansion,
|
|
@@ -17,7 +18,7 @@ import {
|
|
|
17
18
|
roleModel,
|
|
18
19
|
sha256Hex,
|
|
19
20
|
today
|
|
20
|
-
} from "../../chunk-
|
|
21
|
+
} from "../../chunk-4AP763GX.js";
|
|
21
22
|
import "../../chunk-3FYJM7LH.js";
|
|
22
23
|
export {
|
|
23
24
|
DATASETS,
|
|
@@ -31,6 +32,7 @@ export {
|
|
|
31
32
|
datasetAllowed,
|
|
32
33
|
datasetsFor,
|
|
33
34
|
effortBudget,
|
|
35
|
+
generationSampling,
|
|
34
36
|
hasPermission,
|
|
35
37
|
num,
|
|
36
38
|
processExpansion,
|
|
@@ -9,16 +9,16 @@ import {
|
|
|
9
9
|
listUserDocuments,
|
|
10
10
|
scoreFaithfulness,
|
|
11
11
|
scoreJudge
|
|
12
|
-
} from "../../chunk-
|
|
12
|
+
} from "../../chunk-A2HQNENL.js";
|
|
13
13
|
import "../../chunk-IRCDOFP4.js";
|
|
14
14
|
import {
|
|
15
15
|
TOOLS_REGISTRY,
|
|
16
16
|
bindModelNode,
|
|
17
17
|
modelGroundingBlock
|
|
18
|
-
} from "../../chunk-
|
|
18
|
+
} from "../../chunk-VT5ZHCOC.js";
|
|
19
19
|
import {
|
|
20
20
|
handleSearch
|
|
21
|
-
} from "../../chunk-
|
|
21
|
+
} from "../../chunk-G435JWGV.js";
|
|
22
22
|
import {
|
|
23
23
|
buildMessages,
|
|
24
24
|
citations,
|
|
@@ -43,11 +43,11 @@ import {
|
|
|
43
43
|
sessionFrom,
|
|
44
44
|
telemetry,
|
|
45
45
|
understandQuery
|
|
46
|
-
} from "../../chunk-
|
|
46
|
+
} from "../../chunk-SLYQ6L52.js";
|
|
47
47
|
import {
|
|
48
48
|
embed,
|
|
49
49
|
generateOnce
|
|
50
|
-
} from "../../chunk-
|
|
50
|
+
} from "../../chunk-L32WSANI.js";
|
|
51
51
|
import {
|
|
52
52
|
authenticate,
|
|
53
53
|
corsHeaders,
|
|
@@ -56,14 +56,14 @@ import {
|
|
|
56
56
|
readJson,
|
|
57
57
|
validateQuery,
|
|
58
58
|
withCors
|
|
59
|
-
} from "../../chunk-
|
|
59
|
+
} from "../../chunk-NHYYMRZC.js";
|
|
60
60
|
import {
|
|
61
61
|
canonicalRefusal
|
|
62
62
|
} from "../../chunk-ETLSWSZ7.js";
|
|
63
63
|
import {
|
|
64
64
|
entitlementScope,
|
|
65
65
|
standardKeysFrom
|
|
66
|
-
} from "../../chunk-
|
|
66
|
+
} from "../../chunk-4BQA7PJ3.js";
|
|
67
67
|
import {
|
|
68
68
|
LIMITS,
|
|
69
69
|
MODELS,
|
|
@@ -74,7 +74,7 @@ import {
|
|
|
74
74
|
roleModel,
|
|
75
75
|
sha256Hex,
|
|
76
76
|
today
|
|
77
|
-
} from "../../chunk-
|
|
77
|
+
} from "../../chunk-4AP763GX.js";
|
|
78
78
|
import {
|
|
79
79
|
P,
|
|
80
80
|
setProfile
|
|
@@ -1183,13 +1183,13 @@ async function callToolOnce(env, ctx, _req, tier, key, name, args, t0) {
|
|
|
1183
1183
|
// stream:false forces the JSON lane (anon defaults to SSE)
|
|
1184
1184
|
body: JSON.stringify({ ...args, stream: false })
|
|
1185
1185
|
});
|
|
1186
|
-
const { runTool, TOOLS_REGISTRY: TOOLS_REGISTRY2 } = await import("../../tools-
|
|
1186
|
+
const { runTool, TOOLS_REGISTRY: TOOLS_REGISTRY2 } = await import("../../tools-CYSL26HX.js");
|
|
1187
1187
|
let payload;
|
|
1188
1188
|
if (TOOLS_REGISTRY2.some((t) => t.name === name && t.audiences.includes("mcp"))) {
|
|
1189
1189
|
const r = await runTool({ ...env, DB: env.DB }, { name, args }, "mcp");
|
|
1190
1190
|
payload = r ? { tool: r.name, query: r.query, result: r.output } : { error: { message: `tool ${name} returned nothing for the given arguments` } };
|
|
1191
1191
|
} else {
|
|
1192
|
-
const res = name === "ask" ? await (await import("../../ask-
|
|
1192
|
+
const res = name === "ask" ? await (await import("../../ask-TJK7DQ45.js")).handleAsk(env, ctx, inner, tier, key) : await (await import("../../search-FJAOGMEO.js")).handleSearch(env, ctx, inner, tier, key);
|
|
1193
1193
|
payload = await res.json().catch(() => ({ error: { message: "tool transport failed", status: res.status } }));
|
|
1194
1194
|
}
|
|
1195
1195
|
telemetry(env, ctx, tier, `mcp:${name}`, null, !payload?.error, JSON.stringify(payload).length, await sha256Hex(`${name}:${JSON.stringify(args ?? {})}`), void 0, void 0, { durationMs: Date.now() - t0 });
|
|
@@ -4,8 +4,8 @@ import {
|
|
|
4
4
|
requestSalt,
|
|
5
5
|
resolveRequestScope,
|
|
6
6
|
standardKeysFrom
|
|
7
|
-
} from "../../chunk-
|
|
8
|
-
import "../../chunk-
|
|
7
|
+
} from "../../chunk-4BQA7PJ3.js";
|
|
8
|
+
import "../../chunk-4AP763GX.js";
|
|
9
9
|
import "../../chunk-3FYJM7LH.js";
|
|
10
10
|
export {
|
|
11
11
|
entitlementScope,
|
package/package.json
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"playwright": "^1.62.1",
|
|
28
28
|
"yaml": "^2.9.1"
|
|
29
29
|
},
|
|
30
|
-
"version": "0.2.
|
|
30
|
+
"version": "0.2.188",
|
|
31
31
|
"description": "The Konneal engine: the publisher-agnostic build pipeline and API plane for standards intelligence (retrieval, answer contract, verdicts, evaluation).",
|
|
32
32
|
"license": "BSD-3-Clause",
|
|
33
33
|
"type": "module",
|
|
@@ -27,7 +27,7 @@ export async function embed(ai: ModelRunner, _model: string, text: string): Prom
|
|
|
27
27
|
throw new Error(`embed failed after retries: ${String(lastError)}`);
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
import { answerEffort, effortBudget } from "./config.ts";
|
|
30
|
+
import { answerEffort, effortBudget, generationSampling } from "./config.ts";
|
|
31
31
|
|
|
32
32
|
export async function rerank(
|
|
33
33
|
ai: AnyAi,
|
|
@@ -62,8 +62,7 @@ export async function generateOnce(env: any, model: string, messages: any[], eff
|
|
|
62
62
|
messages,
|
|
63
63
|
max_tokens: effortBudget(effort ?? answerEffort(env)),
|
|
64
64
|
reasoning_effort: effort ?? answerEffort(env),
|
|
65
|
-
|
|
66
|
-
top_p: 0.95,
|
|
65
|
+
...generationSampling(model),
|
|
67
66
|
}),
|
|
68
67
|
new Promise<null>((r) => setTimeout(() => r(null), 120_000)),
|
|
69
68
|
]);
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// echo — everything between "request validated" and "response written".
|
|
4
4
|
// index.ts routes here; this module owns the answer contract.
|
|
5
5
|
|
|
6
|
-
import { LIMITS, MODELS, THRESHOLDS, num, sha256Hex, roleModel, answerEffort, requestEffort, effortBudget } from "./config";
|
|
6
|
+
import { LIMITS, MODELS, THRESHOLDS, num, sha256Hex, roleModel, answerEffort, requestEffort, effortBudget, generationSampling } from "./config";
|
|
7
7
|
import { portModelRunner } from "./env.ts";
|
|
8
8
|
import { refCodec } from "./codecs";
|
|
9
9
|
import { buildMessages, citations, fill, promptVars, retrieve, retrievalQuery, identityNote, splitHistory, listwiseRerank, refusalAnswer, Hit } from "./pipeline";
|
|
@@ -227,8 +227,7 @@ async function generateStream(env: Env, model: string, messages: any[], effort?:
|
|
|
227
227
|
stream: true,
|
|
228
228
|
max_tokens: effortBudget(effort ?? answerEffort(env)),
|
|
229
229
|
reasoning_effort: effort ?? answerEffort(env),
|
|
230
|
-
|
|
231
|
-
top_p: 0.95,
|
|
230
|
+
...generationSampling(model),
|
|
232
231
|
});
|
|
233
232
|
if (res && typeof res.getReader === "function") return res as ReadableStream<Uint8Array>;
|
|
234
233
|
if (res && res.body && typeof res.body.getReader === "function") return res.body;
|
|
@@ -259,13 +258,14 @@ async function summarizeHistory(
|
|
|
259
258
|
},
|
|
260
259
|
{ role: "user", content: convo },
|
|
261
260
|
],
|
|
262
|
-
|
|
261
|
+
// reasoning tokens share this budget — DeepSeek-V4 needs 3072+ or
|
|
262
|
+
// the summary is never reached
|
|
263
|
+
max_tokens: model.includes("deepseek") ? 3072 : 2048,
|
|
263
264
|
reasoning_effort: "low",
|
|
265
|
+
...generationSampling(model),
|
|
264
266
|
// Qwen3 thinking-mode sampling (model card) — prevents the
|
|
265
267
|
// repetition loops that eat the budget before the summary lands
|
|
266
|
-
|
|
267
|
-
top_p: 0.95,
|
|
268
|
-
top_k: 20,
|
|
268
|
+
...(model.includes("deepseek") ? {} : { top_k: 20 }),
|
|
269
269
|
});
|
|
270
270
|
const text = typeof res?.response === "string" ? res.response : res?.choices?.[0]?.message?.content;
|
|
271
271
|
return typeof text === "string" && text.trim() ? text.trim().slice(0, 1200) : null;
|
|
@@ -288,10 +288,10 @@ function messageChars(messages: any[]): number {
|
|
|
288
288
|
/** Post-generation true-up: the model's own usage when the stream
|
|
289
289
|
* reported it, the character estimate otherwise — charged, then the
|
|
290
290
|
* budget's fresh state returned for the quota payload. */
|
|
291
|
-
async function chargeAnswerTokens(env: Env, bucketId: string, stats: { usage?: unknown } | undefined, promptChars: number, answerChars: number, extraTokens = 0): Promise<{ tokens_used: number; token_limit: number }> {
|
|
291
|
+
async function chargeAnswerTokens(env: Env, bucketId: string, stats: { usage?: unknown } | undefined, promptChars: number, answerChars: number, extraTokens = 0, keyDayLimitAsks?: number): Promise<{ tokens_used: number; token_limit: number }> {
|
|
292
292
|
const total = (usageTotal(stats?.usage) ?? estimateTokens(promptChars + answerChars)) + extraTokens;
|
|
293
293
|
await chargeTokens(env, bucketId, total);
|
|
294
|
-
const budget = await tokenBudget(env, bucketId);
|
|
294
|
+
const budget = await tokenBudget(env, bucketId, keyDayLimitAsks);
|
|
295
295
|
return { tokens_used: budget.used, token_limit: budget.limit };
|
|
296
296
|
}
|
|
297
297
|
|
|
@@ -421,6 +421,12 @@ async function handleAsk(
|
|
|
421
421
|
: tier === "member" || member ? num(env as any, "MEMBER_DAY_ASK", 300)
|
|
422
422
|
: num(env as any, "ANON_DAY_ASK", 20);
|
|
423
423
|
const bucketId = memberKey ? `sub:${memberKey}` : tier === "key" ? `key:${key!.id}` : member ? `sub:${member.sub}` : clientIp(req);
|
|
424
|
+
// the KEY'S OWN day_limit drives BOTH counters (asks and tokens) — the
|
|
425
|
+
// owner's 2026-11-09 ruling: the serving cap is for USERS, not
|
|
426
|
+
// operators; quota.ts derives tokens = asks × 2000, so an operator
|
|
427
|
+
// key minted at day_limit 50000 carries a 100M-token day, while the
|
|
428
|
+
// default user key stays at 4M
|
|
429
|
+
const keyDayLimit = tier === "key" ? key?.day_limit : undefined;
|
|
424
430
|
const quota = await checkQuota(env, "ask", bucketId, limit, effort === "low" ? 1 : 2);
|
|
425
431
|
const creditPreview = creditEstimate({ effort, toolTurns: body?.multi_turn !== false ? 3 : 0, image: false });
|
|
426
432
|
if (!quota.ok) {
|
|
@@ -428,12 +434,12 @@ async function handleAsk(
|
|
|
428
434
|
}
|
|
429
435
|
// the real allowance is the day's TOKENS (the 2026-09-29 shift): the
|
|
430
436
|
// request cap above is the anti-abuse backstop, this is the budget
|
|
431
|
-
const tokBudget = await tokenBudget(env, bucketId);
|
|
437
|
+
const tokBudget = await tokenBudget(env, bucketId, keyDayLimit);
|
|
432
438
|
// the credit preview (2026-10-11): what this ask will cost, shown in
|
|
433
439
|
// the refusal when the day's credits are spent — effort + armed tool
|
|
434
440
|
// turns + multimodality, one honest number
|
|
435
441
|
if (tokBudget.used >= tokBudget.limit) {
|
|
436
|
-
const cb = await creditBudget(env, bucketId);
|
|
442
|
+
const cb = await creditBudget(env, bucketId, keyDayLimit);
|
|
437
443
|
return err(429, "quota_exceeded", `Daily credits reached (${cb.credits_limit} credits, ${cb.credits_used} used). Try again tomorrow.`);
|
|
438
444
|
}
|
|
439
445
|
(quota as any).tokens_used = tokBudget.used;
|
|
@@ -897,7 +903,7 @@ let convEntities: Array<{ entity: string; kind: string }> = [];
|
|
|
897
903
|
aggregateNoteText = aggregateNote(agg);
|
|
898
904
|
const queryHash = await sha256Hex(q.query);
|
|
899
905
|
telemetry(env, ctx, tier, "ask", MODELS.member, true, answer!.length, queryHash, q.lang, undefined, telemetryMeta());
|
|
900
|
-
const tq = await chargeAnswerTokens(env, bucketId, undefined, q.query.length, answer!.length);
|
|
906
|
+
const tq = await chargeAnswerTokens(env, bucketId, undefined, q.query.length, answer!.length, keyDayLimit);
|
|
901
907
|
const payload = {
|
|
902
908
|
answer,
|
|
903
909
|
citations: [{ docidentifier: `${P().publisher.name}-CS certificate register (family ${agg.family})`, corpus: "register" }],
|
|
@@ -908,7 +914,7 @@ let convEntities: Array<{ entity: string; kind: string }> = [];
|
|
|
908
914
|
context_applied: NO_CONTEXT,
|
|
909
915
|
read: readAs(),
|
|
910
916
|
...(ablate ? { ablate } : {}),
|
|
911
|
-
quota: { ...quota, ...tq, credits: await creditBudget(env, bucketId), credit_estimate: creditPreview },
|
|
917
|
+
quota: { ...quota, ...tq, credits: await creditBudget(env, bucketId, keyDayLimit), credit_estimate: creditPreview },
|
|
912
918
|
};
|
|
913
919
|
if (live) {
|
|
914
920
|
live!.send({ type: "citations", citations: payload.citations, quota: payload.quota, context_applied: NO_CONTEXT });
|
|
@@ -978,8 +984,8 @@ let convEntities: Array<{ entity: string; kind: string }> = [];
|
|
|
978
984
|
} catch {
|
|
979
985
|
// stream ended prematurely — deliver what we have
|
|
980
986
|
}
|
|
981
|
-
const tq = await chargeAnswerTokens(env, bucketId, stats, messageChars(messages!), full.length, probeTokensUsed);
|
|
982
|
-
live!.send({ type: "quota", quota: { ...quota, ...tq, credits: await creditBudget(env, bucketId), credit_estimate: creditPreview } });
|
|
987
|
+
const tq = await chargeAnswerTokens(env, bucketId, stats, messageChars(messages!), full.length, probeTokensUsed, keyDayLimit);
|
|
988
|
+
live!.send({ type: "quota", quota: { ...quota, ...tq, credits: await creditBudget(env, bucketId, keyDayLimit), credit_estimate: creditPreview } });
|
|
983
989
|
live!.send({ type: "done", model, query_hash: queryHash, context_applied: NO_CONTEXT, read: readAs() });
|
|
984
990
|
telemetry(env, ctx, tier, "ask", model, true, full.length, queryHash, q.lang, undefined, telemetryMeta());
|
|
985
991
|
live!.close();
|
|
@@ -1043,8 +1049,8 @@ let convEntities: Array<{ entity: string; kind: string }> = [];
|
|
|
1043
1049
|
live!.close();
|
|
1044
1050
|
return null;
|
|
1045
1051
|
}
|
|
1046
|
-
const tq = await chargeAnswerTokens(env, bucketId, undefined, q.query.length, verdict.answer!.length);
|
|
1047
|
-
return json({ answer: verdict.answer, citations, model, query_hash: queryHash, follow_ups: [], context_applied: draftCtxApplied, read: readAs(), ...(draftPayload ? { draft: draftPayload } : {}), ...(ablate ? { ablate } : {}), quota: { ...quota, ...tq, credits: await creditBudget(env, bucketId), credit_estimate: creditPreview } });
|
|
1052
|
+
const tq = await chargeAnswerTokens(env, bucketId, undefined, q.query.length, verdict.answer!.length, keyDayLimit);
|
|
1053
|
+
return json({ answer: verdict.answer, citations, model, query_hash: queryHash, follow_ups: [], context_applied: draftCtxApplied, read: readAs(), ...(draftPayload ? { draft: draftPayload } : {}), ...(ablate ? { ablate } : {}), quota: { ...quota, ...tq, credits: await creditBudget(env, bucketId, keyDayLimit), credit_estimate: creditPreview } });
|
|
1048
1054
|
}
|
|
1049
1055
|
|
|
1050
1056
|
// ── The api_call draft (TODO.ai-platform/09) — the operations
|
|
@@ -1078,8 +1084,8 @@ let convEntities: Array<{ entity: string; kind: string }> = [];
|
|
|
1078
1084
|
live!.close();
|
|
1079
1085
|
return null;
|
|
1080
1086
|
}
|
|
1081
|
-
const tq = await chargeAnswerTokens(env, bucketId, undefined, q.query.length, verdict.answer!.length);
|
|
1082
|
-
return json({ answer: verdict.answer, citations: [], model, query_hash: queryHash, follow_ups: [], context_applied: callCtxApplied, read: readAs(), ...(draftPayload ? { draft: draftPayload } : {}), ...(ablate ? { ablate } : {}), quota: { ...quota, ...tq, credits: await creditBudget(env, bucketId), credit_estimate: creditPreview } });
|
|
1087
|
+
const tq = await chargeAnswerTokens(env, bucketId, undefined, q.query.length, verdict.answer!.length, keyDayLimit);
|
|
1088
|
+
return json({ answer: verdict.answer, citations: [], model, query_hash: queryHash, follow_ups: [], context_applied: callCtxApplied, read: readAs(), ...(draftPayload ? { draft: draftPayload } : {}), ...(ablate ? { ablate } : {}), quota: { ...quota, ...tq, credits: await creditBudget(env, bucketId, keyDayLimit), credit_estimate: creditPreview } });
|
|
1083
1089
|
}
|
|
1084
1090
|
|
|
1085
1091
|
// (declared before the retrieval try: the account block, the refusal
|
|
@@ -1782,8 +1788,8 @@ let convEntities: Array<{ entity: string; kind: string }> = [];
|
|
|
1782
1788
|
} catch {
|
|
1783
1789
|
// stream ended prematurely — deliver what we have
|
|
1784
1790
|
}
|
|
1785
|
-
const tq = await chargeAnswerTokens(env, bucketId, stats, messageChars(messages!), full.length, probeTokensUsed);
|
|
1786
|
-
send({ type: "quota", quota: { ...quota, ...tq, credits: await creditBudget(env, bucketId), credit_estimate: creditPreview } });
|
|
1791
|
+
const tq = await chargeAnswerTokens(env, bucketId, stats, messageChars(messages!), full.length, probeTokensUsed, keyDayLimit);
|
|
1792
|
+
send({ type: "quota", quota: { ...quota, ...tq, credits: await creditBudget(env, bucketId, keyDayLimit), credit_estimate: creditPreview } });
|
|
1787
1793
|
// the blind-answer guard ON THE STREAM PATH (the JSON path has
|
|
1788
1794
|
// had it since 0.2.80): the register note carries rows and the
|
|
1789
1795
|
// streamed text is the no-information refusal — the model
|
|
@@ -2228,7 +2234,7 @@ let convEntities: Array<{ entity: string; kind: string }> = [];
|
|
|
2228
2234
|
text: h.text.slice(0, 1200),
|
|
2229
2235
|
...((h.metadata as any).table_selection ? { sel: (h.metadata as any).table_selection } : {}),
|
|
2230
2236
|
}));
|
|
2231
|
-
const tq = await chargeAnswerTokens(env, bucketId, undefined, messageChars(messages!), answer!.length, probeTokensUsed);
|
|
2237
|
+
const tq = await chargeAnswerTokens(env, bucketId, undefined, messageChars(messages!), answer!.length, probeTokensUsed, keyDayLimit);
|
|
2232
2238
|
// the reproducibility manifest (TODO.sota/14.6, v1): an opt-in, one-object
|
|
2233
2239
|
// derivation record — the served snapshot identity, the answer model, the
|
|
2234
2240
|
// retrieval anatomy (rank, corpus score, rerank score per used passage),
|
|
@@ -2267,7 +2273,7 @@ let convEntities: Array<{ entity: string; kind: string }> = [];
|
|
|
2267
2273
|
total_ms: Date.now() - tStart,
|
|
2268
2274
|
} }
|
|
2269
2275
|
: {};
|
|
2270
|
-
return json({ ...out, context: contextOut, read: readAs(), ...manifestOut, quota: { ...quota, ...tq, credits: await creditBudget(env, bucketId), credit_estimate: creditPreview } }, 200, { ...corsHeaders(req), "server-timing": serverTiming() });
|
|
2276
|
+
return json({ ...out, context: contextOut, read: readAs(), ...manifestOut, quota: { ...quota, ...tq, credits: await creditBudget(env, bucketId, keyDayLimit), credit_estimate: creditPreview } }, 200, { ...corsHeaders(req), "server-timing": serverTiming() });
|
|
2271
2277
|
}
|
|
2272
2278
|
|
|
2273
2279
|
// THE DISPATCH: the streamed lane's response went out at the top — the
|
|
@@ -1,50 +1,60 @@
|
|
|
1
1
|
import { P } from "./profile.ts";
|
|
2
2
|
|
|
3
|
+
// Cloudflare deprecated glm-5.3-flash, glm-5.2, qwen3-30b-a3b-fp8,
|
|
4
|
+
// deepseek-v4-flash-0731 and deepseek-v4-pro-0813 on 2026-11-20 (HTTP 410)
|
|
5
|
+
// and every generation role died with them. Owner decision 2026-12-03:
|
|
6
|
+
// deepseek-v4.1-flash-1017 carries the generation roles — natively
|
|
7
|
+
// multimodal, 1M ctx, reasoning none/low/high/max with HIGH as the default,
|
|
8
|
+
// so every call site states its effort explicitly.
|
|
9
|
+
const FLASH = "@cf/deepseek-ai/deepseek-v4.1-flash-1017";
|
|
10
|
+
|
|
3
11
|
export const MODELS = {
|
|
4
12
|
embed: "@cf/qwen/qwen3-embedding-0.6b", rerank: "@cf/baai/bge-reranker-base",
|
|
5
|
-
// ANSWER MODEL (all tiers
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
anon: "@cf/zai-org/glm-5.3-flash",
|
|
9
|
-
member: "@cf/zai-org/glm-5.3-flash",
|
|
13
|
+
// ANSWER MODEL (all tiers): natively multimodal (vision-unified contract)
|
|
14
|
+
anon: FLASH,
|
|
15
|
+
member: FLASH,
|
|
10
16
|
// figure captions + the vision lane (one-time, quality-first; the A/B
|
|
11
17
|
// lever is CAPTION_MODEL, the per-request arm is the admin route's
|
|
12
|
-
// body.model)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
//
|
|
16
|
-
|
|
17
|
-
//
|
|
18
|
-
|
|
19
|
-
//
|
|
20
|
-
|
|
18
|
+
// body.model). It emptied on 8/24 figure images in the 2026-10-27 A/B —
|
|
19
|
+
// those captions fall to the serve-raw path.
|
|
20
|
+
caption: FLASH,
|
|
21
|
+
// the pairwise vision judge (sees the image; a THIRD model never judges
|
|
22
|
+
// its own arm) — no other live multimodal model exists in the policy
|
|
23
|
+
// line, so a v4.1 caption arm is judged by its own family
|
|
24
|
+
visionJudge: FLASH,
|
|
25
|
+
// the VLM figure rerank (TODO.sota/18.3): a vision-capable MoE scores
|
|
26
|
+
// figure IMAGES against figure-seeking questions — one bounded call per
|
|
27
|
+
// figure question, ablatable stage
|
|
28
|
+
vlmFigure: FLASH,
|
|
21
29
|
// the decision pass (TODO.decisions/01): clef-flash gates the
|
|
22
30
|
// requirement-shaped questions, clef decides the derived checklist
|
|
23
31
|
decisionsGate: "@cf/cloudflare/clef-flash",
|
|
24
32
|
decisionsModel: "@cf/cloudflare/clef",
|
|
25
|
-
// hot-path understanding/summarize
|
|
26
|
-
understand:
|
|
33
|
+
// hot-path understanding/summarize (cost-first lane)
|
|
34
|
+
understand: FLASH,
|
|
27
35
|
// the api_call act's intent-to-act mapping (TODO.ai-platform/09) — the
|
|
28
36
|
// operations deployment points ACTS_MODEL at the stronger reasoning
|
|
29
37
|
// tier; the floor is the understand lane
|
|
30
|
-
acts:
|
|
31
|
-
// generation fallback when the answer model is unavailable
|
|
32
|
-
|
|
33
|
-
|
|
38
|
+
acts: FLASH,
|
|
39
|
+
// generation fallback when the answer model is unavailable — the same
|
|
40
|
+
// model as the primary while it is the only live cheap option: the
|
|
41
|
+
// retry inside generateOnce is the only diversity this lane has
|
|
42
|
+
fallback: FLASH,
|
|
43
|
+
grader: FLASH, // CRAG grader + judges
|
|
34
44
|
// contextual enrichment is the QUALITY-FIRST lane (one-time spend over
|
|
35
45
|
// the corpus, its quality persists into every future retrieval)
|
|
36
|
-
enrich: "@cf/
|
|
46
|
+
enrich: "@cf/zai-org/glm-5.3",
|
|
37
47
|
// final-tier listwise reranker for hard/member queries (cascade:
|
|
38
48
|
// cross-encoder prunes, listwise orders jointly)
|
|
39
49
|
listwise: "@cf/zai-org/glm-4.7-flash",
|
|
40
50
|
// deep-research loop (G10): bounded agentic iterations, members-only
|
|
41
|
-
escalation:
|
|
42
|
-
research:
|
|
51
|
+
escalation: FLASH,
|
|
52
|
+
research: FLASH,
|
|
43
53
|
// speculative draft-verify (TODO.sota/02 row 2): the strong verifier
|
|
44
54
|
// over the cheap drafts — the research-tier model verifies; the drafter
|
|
45
55
|
// is the standard answer model (MODELS.member). VERIFIER_MODEL swaps it
|
|
46
56
|
// live, same lever as every role.
|
|
47
|
-
verifier: "@cf/zai-org/glm-5.
|
|
57
|
+
verifier: "@cf/zai-org/glm-5.3",
|
|
48
58
|
} as const;
|
|
49
59
|
|
|
50
60
|
export const LIMITS = {
|
|
@@ -224,6 +234,13 @@ export function effortBudget(effort: string): number {
|
|
|
224
234
|
return LIMITS.maxOutputTokens;
|
|
225
235
|
}
|
|
226
236
|
|
|
237
|
+
/** Sampling follows the model's card (the 2026-08-30/31 incidents): the
|
|
238
|
+
* DeepSeek-V4 family degrades under tight sampling (temp 1.0 / top_p 1.0);
|
|
239
|
+
* GLM and Qwen thinking modes take 0.6 / 0.95. */
|
|
240
|
+
export function generationSampling(model: string): { temperature: number; top_p: number } {
|
|
241
|
+
return model.includes("deepseek") ? { temperature: 1.0, top_p: 1.0 } : { temperature: 0.6, top_p: 0.95 };
|
|
242
|
+
}
|
|
243
|
+
|
|
227
244
|
export function requestEffort(env: any, session: unknown, requested: unknown): string {
|
|
228
245
|
if (typeof requested !== "string" || !EFFORTS.has(requested)) return answerEffort(env);
|
|
229
246
|
if (requested === "low") return requested;
|
|
@@ -68,18 +68,24 @@ function tokenTier(bucketId: string): "anon" | "member" | "key" {
|
|
|
68
68
|
return bucketId.startsWith("key:") ? "key" : bucketId.startsWith("sub:") ? "member" : "anon";
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
export function tokenLimit(env: Env, bucketId: string): number {
|
|
71
|
+
export function tokenLimit(env: Env, bucketId: string, keyDayLimitAsks?: number): number {
|
|
72
72
|
const tier = tokenTier(bucketId);
|
|
73
73
|
return tier === "key"
|
|
74
|
-
?
|
|
74
|
+
? // the key's OWN day_limit is the one truth for both counters (the
|
|
75
|
+
// owner's 2026-11-09 ruling: the serving cap is for USERS, not
|
|
76
|
+
// operators): 1 ask ≈ 2000 tokens, so day_limit × 2000 — the
|
|
77
|
+
// default 2000 asks reproduces the historic 4M exactly
|
|
78
|
+
keyDayLimitAsks
|
|
79
|
+
? keyDayLimitAsks * 2_000
|
|
80
|
+
: num(env as any, "KEY_DAY_TOKENS", 4_000_000)
|
|
75
81
|
: tier === "member"
|
|
76
82
|
? num(env as any, "MEMBER_DAY_TOKENS", 1_500_000)
|
|
77
83
|
: num(env as any, "ANON_DAY_TOKENS", 300_000);
|
|
78
84
|
}
|
|
79
85
|
|
|
80
|
-
export async function tokenBudget(env: Env, bucketId: string): Promise<{ used: number; limit: number }> {
|
|
86
|
+
export async function tokenBudget(env: Env, bucketId: string, keyDayLimitAsks?: number): Promise<{ used: number; limit: number }> {
|
|
81
87
|
const used = Number((await env.CACHE.get(`t:${today()}:ask:${await sha256Hex(bucketId)}`)) ?? "0");
|
|
82
|
-
return { used, limit: tokenLimit(env, bucketId) };
|
|
88
|
+
return { used, limit: tokenLimit(env, bucketId, keyDayLimitAsks) };
|
|
83
89
|
}
|
|
84
90
|
|
|
85
91
|
export async function chargeTokens(env: Env, bucketId: string, tokens: number): Promise<void> {
|
|
@@ -109,8 +115,8 @@ export function creditLimit(env: Env, bucketId: string): number {
|
|
|
109
115
|
return Math.floor(tokenLimit(env, bucketId) / CREDIT_TOKEN_UNIT);
|
|
110
116
|
}
|
|
111
117
|
|
|
112
|
-
export async function creditBudget(env: Env, bucketId: string): Promise<{ credits_used: number; credits_limit: number }> {
|
|
113
|
-
const b = await tokenBudget(env, bucketId);
|
|
118
|
+
export async function creditBudget(env: Env, bucketId: string, keyDayLimitAsks?: number): Promise<{ credits_used: number; credits_limit: number }> {
|
|
119
|
+
const b = await tokenBudget(env, bucketId, keyDayLimitAsks);
|
|
114
120
|
return { credits_used: Math.ceil(b.used / CREDIT_TOKEN_UNIT), credits_limit: creditLimit(env, bucketId) };
|
|
115
121
|
}
|
|
116
122
|
|
|
@@ -11,6 +11,7 @@ export type { QueryUnderstanding };
|
|
|
11
11
|
// The prompt is data (prompts/understanding.md), bundled as text.
|
|
12
12
|
import SYSTEM from "../prompts/understanding.md";
|
|
13
13
|
import { fill, promptVars } from "./pipeline.ts";
|
|
14
|
+
import { generationSampling } from "./config.ts";
|
|
14
15
|
|
|
15
16
|
/** Understand the query with the cheap model. Null = use the regex fallback. */
|
|
16
17
|
export async function understandQuery(
|
|
@@ -35,16 +36,15 @@ export async function understandQuery(
|
|
|
35
36
|
],
|
|
36
37
|
// the model always reasons; reasoning tokens share this budget — too
|
|
37
38
|
// small and the JSON is never reached (understanding silently degrades).
|
|
38
|
-
// GLM-5
|
|
39
|
-
// not honored, so GLM needs
|
|
40
|
-
max_tokens:
|
|
39
|
+
// DeepSeek-V4 needs 3072+; GLM-5 defaults to reasoning_effort "max"
|
|
40
|
+
// when the parameter is not honored, so GLM needs the same headroom.
|
|
41
|
+
max_tokens: 3072,
|
|
41
42
|
reasoning_effort: "low",
|
|
43
|
+
...generationSampling(model),
|
|
42
44
|
// Qwen3 thinking-mode sampling (model card): greedy/1.0 sampling
|
|
43
45
|
// degrades into repetition loops — the 10s/5s timeout nulls were the
|
|
44
46
|
// budget being eaten by loops, not by reasoning
|
|
45
|
-
|
|
46
|
-
top_p: 0.95,
|
|
47
|
-
top_k: 20,
|
|
47
|
+
...(model.includes("deepseek") ? {} : { top_k: 20 }),
|
|
48
48
|
};
|
|
49
49
|
// each attempt issues a FRESH call — re-racing a timed-out promise would
|
|
50
50
|
// retry nothing. Generous first attempt: reasoning + the full JSON must
|
package/dist/ask-CTYDXEQN.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
handleAsk
|
|
3
|
-
} from "./chunk-PLONBTNM.js";
|
|
4
|
-
import "./chunk-IRCDOFP4.js";
|
|
5
|
-
import "./chunk-BMODSEKT.js";
|
|
6
|
-
import "./chunk-5ISPTV5G.js";
|
|
7
|
-
import "./chunk-BAOKHV2D.js";
|
|
8
|
-
import "./chunk-TLPUJMAF.js";
|
|
9
|
-
import "./chunk-ETLSWSZ7.js";
|
|
10
|
-
import "./chunk-MZQEI4VJ.js";
|
|
11
|
-
import "./chunk-IZ3GSYMD.js";
|
|
12
|
-
import "./chunk-3FYJM7LH.js";
|
|
13
|
-
import "./chunk-YGQCVPX6.js";
|
|
14
|
-
export {
|
|
15
|
-
handleAsk
|
|
16
|
-
};
|
package/dist/search-5QSGBDBI.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
handleSearch
|
|
3
|
-
} from "./chunk-TKGBLDLK.js";
|
|
4
|
-
import "./chunk-5ISPTV5G.js";
|
|
5
|
-
import "./chunk-BAOKHV2D.js";
|
|
6
|
-
import "./chunk-TLPUJMAF.js";
|
|
7
|
-
import "./chunk-ETLSWSZ7.js";
|
|
8
|
-
import "./chunk-MZQEI4VJ.js";
|
|
9
|
-
import "./chunk-IZ3GSYMD.js";
|
|
10
|
-
import "./chunk-3FYJM7LH.js";
|
|
11
|
-
import "./chunk-YGQCVPX6.js";
|
|
12
|
-
export {
|
|
13
|
-
handleSearch
|
|
14
|
-
};
|