@yeaft/webchat-agent 0.1.1104 → 1.0.1
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/package.json +1 -1
- package/yeaft/llm/anthropic.js +8 -8
- package/yeaft/llm/router.js +16 -2
- package/yeaft/models.js +15 -2
package/package.json
CHANGED
package/yeaft/llm/anthropic.js
CHANGED
|
@@ -34,10 +34,10 @@ function thinkingV1Enabled() {
|
|
|
34
34
|
return process.env.YEAFT_THINKING_V1 === '1';
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
function applyAnthropicThinking(body, model, effort) {
|
|
38
|
-
const cap = getThinkingCapability(model);
|
|
37
|
+
function applyAnthropicThinking(body, model, effort, effortContext = {}) {
|
|
38
|
+
const cap = getThinkingCapability(model, effortContext);
|
|
39
39
|
if (!cap.supportsThinking) return;
|
|
40
|
-
if (!getModelEffortOptions(model).includes(effort)) return;
|
|
40
|
+
if (!getModelEffortOptions(model, effortContext).includes(effort)) return;
|
|
41
41
|
|
|
42
42
|
if (cap.thinkingProtocol === 'anthropic-adaptive') {
|
|
43
43
|
body.thinking = { type: 'adaptive' };
|
|
@@ -207,10 +207,10 @@ export class AnthropicAdapter extends LLMAdapter {
|
|
|
207
207
|
}
|
|
208
208
|
|
|
209
209
|
/**
|
|
210
|
-
* @param {{ model: string, system: string, messages: import('./adapter.js').UnifiedMessage[], tools?: import('./adapter.js').UnifiedToolDef[], maxTokens?: number, effort?: 'low'|'medium'|'high'|'xhigh'|'max', effortSource?: 'user'|'auto', signal?: AbortSignal }} params
|
|
210
|
+
* @param {{ model: string, system: string, messages: import('./adapter.js').UnifiedMessage[], tools?: import('./adapter.js').UnifiedToolDef[], maxTokens?: number, effort?: 'low'|'medium'|'high'|'xhigh'|'max', effortSource?: 'user'|'auto', effortContext?: object, signal?: AbortSignal, onRawExchange?: ({rawRequest, rawResponse}) => void }} params
|
|
211
211
|
* @returns {AsyncGenerator<import('./adapter.js').StreamEvent>}
|
|
212
212
|
*/
|
|
213
|
-
async *stream({ model, system, messages, tools, maxTokens = 16384, effort, effortSource, signal, onRawExchange }) {
|
|
213
|
+
async *stream({ model, system, messages, tools, maxTokens = 16384, effort, effortSource, effortContext, signal, onRawExchange }) {
|
|
214
214
|
if (signal?.aborted) throw new LLMAbortError();
|
|
215
215
|
|
|
216
216
|
const body = {
|
|
@@ -226,7 +226,7 @@ export class AnthropicAdapter extends LLMAdapter {
|
|
|
226
226
|
// models use budget_tokens. Unsupported combinations silently drop effort.
|
|
227
227
|
const normEffort = normalizeEffort(effort);
|
|
228
228
|
if ((thinkingV1Enabled() || effortSource === 'user') && normEffort) {
|
|
229
|
-
applyAnthropicThinking(body, model, normEffort);
|
|
229
|
+
applyAnthropicThinking(body, model, normEffort, effortContext);
|
|
230
230
|
}
|
|
231
231
|
|
|
232
232
|
const translatedTools = this.#translateTools(tools);
|
|
@@ -473,7 +473,7 @@ export class AnthropicAdapter extends LLMAdapter {
|
|
|
473
473
|
* models silently drop the param. max_tokens auto-widens to budget+1024
|
|
474
474
|
* when needed.
|
|
475
475
|
*/
|
|
476
|
-
async call({ model, system, messages, maxTokens = 4096, effort, effortSource, signal }) {
|
|
476
|
+
async call({ model, system, messages, maxTokens = 4096, effort, effortSource, effortContext, signal }) {
|
|
477
477
|
if (signal?.aborted) throw new LLMAbortError();
|
|
478
478
|
|
|
479
479
|
const body = {
|
|
@@ -486,7 +486,7 @@ export class AnthropicAdapter extends LLMAdapter {
|
|
|
486
486
|
// task-327c: mirror stream()'s thinking injection for side queries.
|
|
487
487
|
const normEffort = normalizeEffort(effort);
|
|
488
488
|
if ((thinkingV1Enabled() || effortSource === 'user') && normEffort) {
|
|
489
|
-
applyAnthropicThinking(body, model, normEffort);
|
|
489
|
+
applyAnthropicThinking(body, model, normEffort, effortContext);
|
|
490
490
|
}
|
|
491
491
|
|
|
492
492
|
let response;
|
package/yeaft/llm/router.js
CHANGED
|
@@ -552,9 +552,16 @@ export class AdapterRouter extends LLMAdapter {
|
|
|
552
552
|
*/
|
|
553
553
|
async *stream(params) {
|
|
554
554
|
const resolved = await this.#resolveAdapter(params.model);
|
|
555
|
+
const effortContext = {
|
|
556
|
+
protocol: resolved.protocol,
|
|
557
|
+
supportsEffort: resolved.entry?.supportsEffort,
|
|
558
|
+
effortOptions: resolved.entry?.effortOptions,
|
|
559
|
+
thinkingProtocol: resolved.entry?.thinkingProtocol,
|
|
560
|
+
maxBudgetTokens: resolved.entry?.maxBudgetTokens,
|
|
561
|
+
};
|
|
555
562
|
const filtered = filterEffortForModel({ ...params, model: resolved.modelId }, resolved);
|
|
556
563
|
const sanitized = sanitizeMessagesForWire(filtered);
|
|
557
|
-
yield* resolved.adapter.stream({ ...sanitized, model: resolved.modelId });
|
|
564
|
+
yield* resolved.adapter.stream({ ...sanitized, model: resolved.modelId, effortContext });
|
|
558
565
|
}
|
|
559
566
|
|
|
560
567
|
/**
|
|
@@ -565,9 +572,16 @@ export class AdapterRouter extends LLMAdapter {
|
|
|
565
572
|
*/
|
|
566
573
|
async call(params) {
|
|
567
574
|
const resolved = await this.#resolveAdapter(params.model);
|
|
575
|
+
const effortContext = {
|
|
576
|
+
protocol: resolved.protocol,
|
|
577
|
+
supportsEffort: resolved.entry?.supportsEffort,
|
|
578
|
+
effortOptions: resolved.entry?.effortOptions,
|
|
579
|
+
thinkingProtocol: resolved.entry?.thinkingProtocol,
|
|
580
|
+
maxBudgetTokens: resolved.entry?.maxBudgetTokens,
|
|
581
|
+
};
|
|
568
582
|
const filtered = filterEffortForModel({ ...params, model: resolved.modelId }, resolved);
|
|
569
583
|
const sanitized = sanitizeMessagesForWire(filtered);
|
|
570
|
-
return resolved.adapter.call({ ...sanitized, model: resolved.modelId });
|
|
584
|
+
return resolved.adapter.call({ ...sanitized, model: resolved.modelId, effortContext });
|
|
571
585
|
}
|
|
572
586
|
|
|
573
587
|
/**
|
package/yeaft/models.js
CHANGED
|
@@ -537,8 +537,13 @@ export function thinkingBudgetForEffort(model, effort) {
|
|
|
537
537
|
*/
|
|
538
538
|
export function getThinkingCapability(model, context = {}) {
|
|
539
539
|
const info = MODEL_REGISTRY.get(model);
|
|
540
|
+
const modelId = parseModelRef(model).modelId;
|
|
540
541
|
const overrideOptions = normalizeEffortOptions(context.effortOptions);
|
|
541
|
-
const overrideProtocol = context.thinkingProtocol || (
|
|
542
|
+
const overrideProtocol = context.thinkingProtocol || (
|
|
543
|
+
context.protocol === 'anthropic'
|
|
544
|
+
? (/^deepseek/i.test(modelId) ? 'anthropic-adaptive' : 'anthropic')
|
|
545
|
+
: context.protocol === 'openai-responses' ? 'openai-reasoning' : null
|
|
546
|
+
);
|
|
542
547
|
if (context.supportsEffort === true || overrideOptions) {
|
|
543
548
|
return {
|
|
544
549
|
supportsThinking: true,
|
|
@@ -560,7 +565,15 @@ export function getThinkingCapability(model, context = {}) {
|
|
|
560
565
|
};
|
|
561
566
|
}
|
|
562
567
|
if (context.protocol === 'anthropic' && inferred?.thinkingProtocol === 'openai-reasoning') {
|
|
563
|
-
|
|
568
|
+
if (/^deepseek/i.test(modelId)) {
|
|
569
|
+
inferred = {
|
|
570
|
+
...inferred,
|
|
571
|
+
thinkingProtocol: 'anthropic-adaptive',
|
|
572
|
+
effortOptions: DEEPSEEK_REASONING_EFFORT_OPTIONS,
|
|
573
|
+
};
|
|
574
|
+
} else {
|
|
575
|
+
inferred = null;
|
|
576
|
+
}
|
|
564
577
|
}
|
|
565
578
|
if ((!info || !info.supportsThinking) && !inferred) {
|
|
566
579
|
return {
|