@bitkyc08/opencodex 2.100.0 → 2.100.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/gui/dist/assets/App-BpJOzw4F.js +59 -0
- package/gui/dist/assets/Tray-BcaI-VCr.js +1 -0
- package/gui/dist/assets/brand-mark-DU-0Vdkr.js +1 -0
- package/gui/dist/assets/index-Bbor_y80.js +94 -0
- package/gui/dist/assets/index-DJEkIDAi.css +2 -0
- package/gui/dist/assets/{segment-thumb-features-CcxZBnxv.js → segment-thumb-features-e9A_FogJ.js} +1 -1
- package/gui/dist/classic/assets/{App-aYgIQMxI.js → App-BrIlUiLc.js} +18 -18
- package/gui/dist/classic/assets/{Tray-D8jfUXpQ.js → Tray-DT146AhS.js} +1 -1
- package/gui/dist/classic/assets/index-DyJHagvT.js +94 -0
- package/gui/dist/classic/assets/quota-summary-CakPe9Ni.js +1 -0
- package/gui/dist/classic/index.html +1 -1
- package/gui/dist/index.html +2 -2
- package/package.json +2 -2
- package/src/adapters/anthropic-image-normalize.ts +1 -1
- package/src/adapters/client-fingerprint.ts +6 -4
- package/src/adapters/cursor/native-exec.ts +3 -2
- package/src/adapters/cursor/tool-guidance.ts +3 -3
- package/src/adapters/cursor/tool-wording.ts +10 -1
- package/src/adapters/devin/cloud-direct/tool-schema.ts +20 -2
- package/src/adapters/google-antigravity-wire.ts +13 -6
- package/src/adapters/google-truncation.ts +4 -2
- package/src/adapters/google.ts +8 -2
- package/src/adapters/openai-chat/mistral-image-limit.ts +28 -15
- package/src/adapters/openai-chat/tool-schema.ts +9 -0
- package/src/adapters/openai-chat-images.ts +100 -0
- package/src/adapters/openai-chat.ts +6 -9
- package/src/adapters/openai-responses/tool-schema.ts +18 -4
- package/src/adapters/run-turn-queue.ts +139 -5
- package/src/adapters/upstream-http-error.ts +4 -2
- package/src/bridge/sse.ts +8 -1
- package/src/claude/chat-tool-dispatch.ts +233 -0
- package/src/claude/inbound-tool-loading.ts +42 -17
- package/src/cli/account-api.ts +6 -0
- package/src/cli/account-extended.ts +60 -6
- package/src/cli/account-key-quota.ts +22 -2
- package/src/cli/account.ts +1 -1
- package/src/cli/capabilities-access-remote.ts +10 -0
- package/src/cli/capabilities-agents-routing.ts +2 -2
- package/src/cli/capabilities-base.ts +2 -2
- package/src/cli/claude.ts +19 -14
- package/src/cli/config-command.ts +24 -1
- package/src/cli/connect.ts +36 -3
- package/src/cli/gui-pair-client.ts +23 -2
- package/src/cli/help.ts +1 -1
- package/src/cli/hub.ts +18 -1
- package/src/cli/link-child-ops.ts +136 -0
- package/src/cli/link-status-child.ts +94 -0
- package/src/cli/link.ts +22 -9
- package/src/cli/registry.ts +3 -2
- package/src/cli/sync-command.ts +3 -1
- package/src/cli/sync-fanout.ts +8 -81
- package/src/client/link-readiness.ts +16 -6
- package/src/client/link-tunnel-status.ts +76 -0
- package/src/clients/config-export.ts +14 -1
- package/src/codex/account-resume-health.ts +41 -0
- package/src/codex/auth-api/login-flow.ts +6 -0
- package/src/codex/auth-api/routes.ts +35 -2
- package/src/codex/catalog/gather-capture.ts +2 -0
- package/src/codex/catalog/provider-models.ts +13 -8
- package/src/codex/convergence-types.ts +2 -0
- package/src/codex/quota.ts +111 -6
- package/src/combos/cooldown-store.ts +208 -0
- package/src/combos/failover.ts +432 -35
- package/src/config/salvage.ts +1 -0
- package/src/config/schema/config-schema.ts +6 -3
- package/src/config/schema/leaf-validators.ts +34 -12
- package/src/generated/compatibility-version.json +227 -135
- package/src/lib/catalog-etag.ts +10 -0
- package/src/lib/client-error-body.ts +15 -0
- package/src/lib/config-ownership.ts +9 -2
- package/src/lib/context-overflow-verdict.ts +266 -9
- package/src/lib/failure-detail.ts +72 -3
- package/src/lib/hard-refusal.ts +259 -0
- package/src/link/child-activity.ts +57 -0
- package/src/link/child-catalog-freshness.ts +149 -0
- package/src/link/child-gated-ocx.ts +117 -0
- package/src/link/child-observations.ts +205 -0
- package/src/link/child-observe.ts +121 -0
- package/src/link/child-ops-engine.ts +162 -0
- package/src/link/child-update-contract.ts +165 -0
- package/src/link/paths.ts +5 -0
- package/src/link/remote-windows.ts +42 -6
- package/src/link/ssh-argv.ts +126 -32
- package/src/link/status-projection.ts +73 -0
- package/src/link/sync-fanout-classify.ts +98 -0
- package/src/link/tunnel-state.ts +10 -4
- package/src/messaging/mcp-queue-rpc.ts +2 -1
- package/src/messaging/mcp-queue-server.ts +5 -0
- package/src/messaging/mcp-reply-tools.ts +24 -9
- package/src/messaging/mcp-reply-wait.ts +70 -0
- package/src/oauth/account-resume-health.ts +60 -0
- package/src/oauth/anthropic-model-quota.ts +12 -0
- package/src/oauth/anthropic-routing.ts +11 -4
- package/src/oauth/index.ts +1 -0
- package/src/oauth/kiro-iam-identity-center.ts +4 -1
- package/src/oauth/store.ts +44 -1
- package/src/providers/api-key-pause-state.ts +23 -0
- package/src/providers/api-key-pause.ts +68 -10
- package/src/providers/api-key-selection-capture.ts +3 -1
- package/src/providers/api-key-selection.ts +3 -2
- package/src/providers/api-keys.ts +18 -5
- package/src/providers/claude-cli-identity.ts +9 -3
- package/src/providers/claude-cli-usage-state.ts +11 -6
- package/src/providers/claude-cli-usage.ts +27 -8
- package/src/providers/codex-capacity.ts +11 -2
- package/src/providers/key-failover.ts +13 -6
- package/src/providers/model-discovery-config.ts +31 -0
- package/src/providers/model-discovery-diagnostic.ts +34 -3
- package/src/providers/model-discovery.ts +43 -7
- package/src/providers/model-rename-fields.ts +2 -0
- package/src/providers/openai-sidecar.ts +15 -2
- package/src/providers/provider-id-rewrite.ts +3 -0
- package/src/providers/quota/account-cache.ts +52 -34
- package/src/providers/quota/anthropic-family-headers.ts +8 -1
- package/src/providers/quota/anthropic-usage-windows.ts +66 -9
- package/src/providers/quota/report-cache.ts +53 -5
- package/src/providers/quota/vendor-probes-key.ts +73 -0
- package/src/providers/quota/vendor-probes-oauth.ts +57 -3
- package/src/providers/quota-key-accounts.ts +12 -5
- package/src/providers/quota-mistral-budget.ts +18 -0
- package/src/providers/quota-types.ts +32 -0
- package/src/providers/quota.ts +22 -22
- package/src/providers/reasoning-metadata.ts +1051 -12
- package/src/providers/registry/entries-extended.ts +3 -1
- package/src/providers/registry/model-ids.ts +1 -0
- package/src/providers/registry/types.ts +6 -0
- package/src/quota/reset-observer.ts +4 -2
- package/src/quota/reset-seen-store.ts +9 -0
- package/src/quota/window-mapping.ts +1 -0
- package/src/quota-pool/assemble.ts +4 -1
- package/src/responses/hosted-tool-policy.ts +56 -12
- package/src/responses/retained-compaction.ts +31 -5
- package/src/router.ts +2 -0
- package/src/server/auth-cors.ts +11 -8
- package/src/server/catalog-download.ts +3 -5
- package/src/server/chat-native.ts +11 -2
- package/src/server/claude-messages.ts +2 -1
- package/src/server/images.ts +41 -13
- package/src/server/index/link-listener.ts +16 -2
- package/src/server/index/link-relay-sessions.ts +43 -2
- package/src/server/index/optional-listeners.ts +18 -0
- package/src/server/management/config-routes.ts +7 -1
- package/src/server/management/context.ts +1 -1
- package/src/server/management/link-child-ops-routes.ts +116 -0
- package/src/server/management/link-route-state.ts +10 -0
- package/src/server/management/link-routes.ts +10 -0
- package/src/server/management/oauth-account-routes.ts +33 -4
- package/src/server/management/provider-overwrite-carry.ts +28 -3
- package/src/server/management/provider-routes.ts +16 -11
- package/src/server/management/route-registry.ts +3 -0
- package/src/server/messages-native.ts +5 -0
- package/src/server/request-log-failure-detail.ts +59 -1
- package/src/server/responses/adapter-dispatch.ts +35 -44
- package/src/server/responses/combo-stream-preflight.ts +146 -29
- package/src/server/responses/compact.ts +27 -4
- package/src/server/responses/context-overflow.ts +58 -2
- package/src/server/responses/core-combo-failure.ts +29 -4
- package/src/server/responses/core-combo-native.ts +3 -1
- package/src/server/responses/core-combo.ts +30 -3
- package/src/server/responses/core-errors.ts +3 -1
- package/src/server/responses/core-opaque-recovery.ts +45 -2
- package/src/server/responses/core-options.ts +12 -0
- package/src/server/responses/passthrough-dispatch.ts +30 -38
- package/src/server/responses/request-transport.ts +43 -14
- package/src/server/responses/reset-replay.ts +58 -2
- package/src/server/responses/run-turn-execution.ts +56 -30
- package/src/types/claude-tool-loading.ts +48 -0
- package/src/types/config.ts +5 -35
- package/src/types/provider.ts +21 -0
- package/src/types.ts +1 -0
- package/src/web-search/parse.ts +44 -4
- package/gui/dist/assets/App-CitvEefy.js +0 -59
- package/gui/dist/assets/Tray-CeKVWQyB.js +0 -1
- package/gui/dist/assets/brand-mark-M92UnxX2.js +0 -1
- package/gui/dist/assets/index-BP47do6-.js +0 -94
- package/gui/dist/assets/index-DmDooSAG.css +0 -2
- package/gui/dist/classic/assets/index-CfGqHooN.js +0 -94
- package/gui/dist/classic/assets/quota-summary-R-ih7OlS.js +0 -1
|
@@ -26,6 +26,12 @@ import { join } from "node:path";
|
|
|
26
26
|
// and leaves COMBO_NAMESPACE in its temporal dead zone for entry points that start at combos/types.ts.
|
|
27
27
|
import { atomicWriteFile } from "../config/atomic-write";
|
|
28
28
|
import { getConfigDir, withConfigDirHardeningSettled } from "../config/paths";
|
|
29
|
+
import {
|
|
30
|
+
extractJsonEnvelope,
|
|
31
|
+
extractJsonEnvelopeWithContext,
|
|
32
|
+
isHardPolicyOrOriginRefusal,
|
|
33
|
+
} from "../lib/hard-refusal";
|
|
34
|
+
export { extractJsonEnvelope, extractJsonEnvelopeWithContext, isHardPolicyOrOriginRefusal };
|
|
29
35
|
import type { OcxProviderConfig } from "../types";
|
|
30
36
|
import { resolveProviderApiKey } from "./api-key-resolve";
|
|
31
37
|
|
|
@@ -428,7 +434,7 @@ export async function flushReasoningSupportCache(): Promise<void> {
|
|
|
428
434
|
* these beside the effort term is what separates "the gateway rejected reasoning effort" from
|
|
429
435
|
* "the gateway rejected something else and echoed the request back".
|
|
430
436
|
*/
|
|
431
|
-
const REJECTION_LANGUAGE = /unsupported|not supported|does not support|invalid|unrecognized|unknown|not allowed|not permitted|must be|requires|required|cannot|can't|out of range/i;
|
|
437
|
+
const REJECTION_LANGUAGE = /unsupported|not supported|does not support|invalid|not valid|unrecognized|unknown|not allowed|not permitted|must be|requires|required|cannot|can't|out of range/i;
|
|
432
438
|
|
|
433
439
|
/**
|
|
434
440
|
* How far from the effort term the rejection language may sit and still be about it. Kept
|
|
@@ -445,29 +451,1061 @@ const REJECTION_WINDOW = 48;
|
|
|
445
451
|
*/
|
|
446
452
|
const GENERIC_ERROR_TYPE = /invalid_request_error/gi;
|
|
447
453
|
|
|
454
|
+
const EFFORT_COMPATIBLE_CODES = new Set([
|
|
455
|
+
"",
|
|
456
|
+
"invalid_request_error",
|
|
457
|
+
"invalid_argument",
|
|
458
|
+
"invalid_parameter",
|
|
459
|
+
"unsupported_parameter",
|
|
460
|
+
"unsupported_value",
|
|
461
|
+
"invalid_parameter_error",
|
|
462
|
+
]);
|
|
463
|
+
const EFFORT_COMPATIBLE_TYPES = new Set([
|
|
464
|
+
"",
|
|
465
|
+
"invalid_request_error",
|
|
466
|
+
"upstream_error",
|
|
467
|
+
"bad_request",
|
|
468
|
+
]);
|
|
469
|
+
|
|
448
470
|
/**
|
|
449
|
-
*
|
|
471
|
+
* Error codes and types arrive as snake_case, kebab-case or PascalCase depending on the gateway
|
|
472
|
+
* (Volcengine Ark sends `InvalidParameter` / `BadRequest`). Fold all three to snake_case before the
|
|
473
|
+
* compatibility lookup so a generic vendor code is not read as naming some other field.
|
|
474
|
+
*/
|
|
475
|
+
function normalizeErrorTag(value: string): string {
|
|
476
|
+
return value.trim().replace(/([a-z0-9])([A-Z])/g, "$1_$2").toLowerCase().replaceAll("-", "_");
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
function isIncompleteStructuredWrapper(text: string): boolean {
|
|
480
|
+
let s = text.trim();
|
|
481
|
+
for (let d = 0; d < 3; d += 1) {
|
|
482
|
+
if (s.startsWith("Provider error 400: ")) {
|
|
483
|
+
s = s.slice("Provider error 400: ".length).trim();
|
|
484
|
+
} else if (s.startsWith("Provider error: ")) {
|
|
485
|
+
s = s.slice("Provider error: ".length).trim();
|
|
486
|
+
} else if (s.startsWith("Gateway error 400: ")) {
|
|
487
|
+
s = s.slice("Gateway error 400: ".length).trim();
|
|
488
|
+
} else if (s.startsWith("Gateway error: ")) {
|
|
489
|
+
s = s.slice("Gateway error: ".length).trim();
|
|
490
|
+
}
|
|
491
|
+
if (s.startsWith("data:") && !s.includes("\n")) {
|
|
492
|
+
s = s.slice("data:".length).trim();
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
if (s.startsWith("{") || s.startsWith("[")) {
|
|
496
|
+
try {
|
|
497
|
+
JSON.parse(s);
|
|
498
|
+
return false;
|
|
499
|
+
} catch {
|
|
500
|
+
return true;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
if (/^(?:(?:Provider|Gateway) error (?:400:\s*)?|data:\s*)[{\[]/i.test(text.trim())) {
|
|
504
|
+
return true;
|
|
505
|
+
}
|
|
506
|
+
const firstBrace = s.indexOf("{");
|
|
507
|
+
const lastBrace = s.lastIndexOf("}");
|
|
508
|
+
if (firstBrace !== -1) {
|
|
509
|
+
let openBraces = 0;
|
|
510
|
+
let inString = false;
|
|
511
|
+
let escape = false;
|
|
512
|
+
for (let i = 0; i < s.length; i += 1) {
|
|
513
|
+
const ch = s[i];
|
|
514
|
+
if (escape) {
|
|
515
|
+
escape = false;
|
|
516
|
+
continue;
|
|
517
|
+
}
|
|
518
|
+
if (ch === "\\") {
|
|
519
|
+
escape = true;
|
|
520
|
+
continue;
|
|
521
|
+
}
|
|
522
|
+
if (ch === '"') {
|
|
523
|
+
inString = !inString;
|
|
524
|
+
continue;
|
|
525
|
+
}
|
|
526
|
+
if (!inString) {
|
|
527
|
+
if (ch === "{") openBraces += 1;
|
|
528
|
+
else if (ch === "}") openBraces -= 1;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
if (openBraces !== 0) return true;
|
|
532
|
+
if (lastBrace > firstBrace && s.slice(firstBrace, lastBrace + 1).includes(":")) {
|
|
533
|
+
try {
|
|
534
|
+
JSON.parse(s.slice(firstBrace, lastBrace + 1));
|
|
535
|
+
} catch {
|
|
536
|
+
return true;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
const firstBracket = s.indexOf("[");
|
|
541
|
+
const lastBracket = s.lastIndexOf("]");
|
|
542
|
+
if (firstBracket !== -1) {
|
|
543
|
+
let openBrackets = 0;
|
|
544
|
+
let inString = false;
|
|
545
|
+
let escape = false;
|
|
546
|
+
for (let i = 0; i < s.length; i += 1) {
|
|
547
|
+
const ch = s[i];
|
|
548
|
+
if (escape) {
|
|
549
|
+
escape = false;
|
|
550
|
+
continue;
|
|
551
|
+
}
|
|
552
|
+
if (ch === "\\") {
|
|
553
|
+
escape = true;
|
|
554
|
+
continue;
|
|
555
|
+
}
|
|
556
|
+
if (ch === '"') {
|
|
557
|
+
inString = !inString;
|
|
558
|
+
continue;
|
|
559
|
+
}
|
|
560
|
+
if (!inString) {
|
|
561
|
+
if (ch === "[") openBrackets += 1;
|
|
562
|
+
else if (ch === "]") openBrackets -= 1;
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
if (openBrackets !== 0) return true;
|
|
566
|
+
const bracketSlice = s.slice(firstBracket, lastBracket + 1);
|
|
567
|
+
if (
|
|
568
|
+
lastBracket > firstBracket &&
|
|
569
|
+
(bracketSlice.includes('"') || bracketSlice.includes("'") || bracketSlice.includes(":") || bracketSlice.includes(","))
|
|
570
|
+
) {
|
|
571
|
+
try {
|
|
572
|
+
JSON.parse(bracketSlice);
|
|
573
|
+
} catch {
|
|
574
|
+
// "reasoning_effort must be one of ['low','medium','high']" is a value list in prose, not
|
|
575
|
+
// a truncated or reflected envelope (#8173).
|
|
576
|
+
if (!isEffortValueEnumeration(bracketSlice)) return true;
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
return false;
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
const EFFORT_PARAM_NAMES = new Set([
|
|
584
|
+
"reasoning_effort",
|
|
585
|
+
"reasoning.effort",
|
|
586
|
+
"reasoning",
|
|
587
|
+
"reasoning_parameters",
|
|
588
|
+
"effort",
|
|
589
|
+
// A thinking-budget field is the same subject on the Anthropic-shaped wires: a refusal that
|
|
590
|
+
// names it is about the reasoning control, not about some other parameter.
|
|
591
|
+
"thinking_budget",
|
|
592
|
+
"thinking.budget",
|
|
593
|
+
"thinking.budget_tokens",
|
|
594
|
+
]);
|
|
595
|
+
|
|
596
|
+
function cleanParam(str: string): string {
|
|
597
|
+
return str.trim().toLowerCase().replaceAll("-", "_").replace(/[^a-z0-9_]+$/gi, "").replace(/^[^a-z0-9_]+/gi, "");
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
const KNOWN_NON_EFFORT_PARAMS = new Set([
|
|
601
|
+
"temperature",
|
|
602
|
+
"top_p",
|
|
603
|
+
"top_k",
|
|
604
|
+
"max_tokens",
|
|
605
|
+
"max_completion_tokens",
|
|
606
|
+
"max_output_tokens",
|
|
607
|
+
"min_tokens",
|
|
608
|
+
"stop",
|
|
609
|
+
"stop_sequences",
|
|
610
|
+
"presence_penalty",
|
|
611
|
+
"frequency_penalty",
|
|
612
|
+
"repetition_penalty",
|
|
613
|
+
"logit_bias",
|
|
614
|
+
"logprobs",
|
|
615
|
+
"top_logprobs",
|
|
616
|
+
"seed",
|
|
617
|
+
"tools",
|
|
618
|
+
"tool_choice",
|
|
619
|
+
"functions",
|
|
620
|
+
"function_call",
|
|
621
|
+
"response_format",
|
|
622
|
+
"stream",
|
|
623
|
+
"stream_options",
|
|
624
|
+
"user",
|
|
625
|
+
"service_tier",
|
|
626
|
+
"modalities",
|
|
627
|
+
"prediction",
|
|
628
|
+
"parallel_tool_calls",
|
|
629
|
+
"messages",
|
|
630
|
+
"prompt",
|
|
631
|
+
"n",
|
|
632
|
+
"best_of",
|
|
633
|
+
]);
|
|
634
|
+
|
|
635
|
+
const GENERIC_PARAM_WORDS = new Set([
|
|
636
|
+
"request",
|
|
637
|
+
"requests",
|
|
638
|
+
"argument",
|
|
639
|
+
"arguments",
|
|
640
|
+
"parameter",
|
|
641
|
+
"parameters",
|
|
642
|
+
"param",
|
|
643
|
+
"params",
|
|
644
|
+
"payload",
|
|
645
|
+
"body",
|
|
646
|
+
"input",
|
|
647
|
+
"inputs",
|
|
648
|
+
"json",
|
|
649
|
+
"format",
|
|
650
|
+
"data",
|
|
651
|
+
"content",
|
|
652
|
+
"value",
|
|
653
|
+
"values",
|
|
654
|
+
"field",
|
|
655
|
+
"fields",
|
|
656
|
+
"call",
|
|
657
|
+
"type",
|
|
658
|
+
"error",
|
|
659
|
+
"message",
|
|
660
|
+
"model",
|
|
661
|
+
"url",
|
|
662
|
+
"header",
|
|
663
|
+
"headers",
|
|
664
|
+
"auth",
|
|
665
|
+
"api",
|
|
666
|
+
"key",
|
|
667
|
+
"token",
|
|
668
|
+
"status",
|
|
669
|
+
"code",
|
|
670
|
+
"response",
|
|
671
|
+
"gateway",
|
|
672
|
+
"provider",
|
|
673
|
+
"invalid",
|
|
674
|
+
"unsupported",
|
|
675
|
+
"unknown",
|
|
676
|
+
"unrecognized",
|
|
677
|
+
"unexpected",
|
|
678
|
+
"unallowed",
|
|
679
|
+
"it",
|
|
680
|
+
"this",
|
|
681
|
+
"that",
|
|
682
|
+
"these",
|
|
683
|
+
"those",
|
|
684
|
+
"which",
|
|
685
|
+
"what",
|
|
686
|
+
"all",
|
|
687
|
+
"each",
|
|
688
|
+
"every",
|
|
689
|
+
"both",
|
|
690
|
+
"either",
|
|
691
|
+
"neither",
|
|
692
|
+
"one",
|
|
693
|
+
"they",
|
|
694
|
+
"there",
|
|
695
|
+
"here",
|
|
696
|
+
"string",
|
|
697
|
+
"number",
|
|
698
|
+
"boolean",
|
|
699
|
+
"integer",
|
|
700
|
+
"array",
|
|
701
|
+
"object",
|
|
702
|
+
"null",
|
|
703
|
+
"none",
|
|
704
|
+
]);
|
|
705
|
+
|
|
706
|
+
const EFFORT_RUNGS = new Set([
|
|
707
|
+
"none",
|
|
708
|
+
"low",
|
|
709
|
+
"medium",
|
|
710
|
+
"high",
|
|
711
|
+
"max",
|
|
712
|
+
"xhigh",
|
|
713
|
+
"ultra",
|
|
714
|
+
"minimal",
|
|
715
|
+
"standard",
|
|
716
|
+
"default",
|
|
717
|
+
]);
|
|
718
|
+
|
|
719
|
+
/**
|
|
720
|
+
* Words that describe a diagnostic, never name a request field.
|
|
721
|
+
*
|
|
722
|
+
* "Unsupported parameter: 'reasoning_effort'" puts an adjective exactly where a field name sits
|
|
723
|
+
* in "`field` parameter", and "Unsupported value: 'max'" puts the refused value under a noun.
|
|
724
|
+
* Reading either as the competing subject made genuine effort refusals terminal (#8173).
|
|
725
|
+
*/
|
|
726
|
+
const DIAGNOSTIC_NOISE_WORDS = new Set([
|
|
727
|
+
"unsupported",
|
|
728
|
+
"invalid",
|
|
729
|
+
"unrecognized",
|
|
730
|
+
"unknown",
|
|
731
|
+
"unexpected",
|
|
732
|
+
"bad",
|
|
733
|
+
"malformed",
|
|
734
|
+
"value",
|
|
735
|
+
"values",
|
|
736
|
+
"parameter",
|
|
737
|
+
"parameters",
|
|
738
|
+
"param",
|
|
739
|
+
"params",
|
|
740
|
+
"field",
|
|
741
|
+
"fields",
|
|
742
|
+
"argument",
|
|
743
|
+
"arguments",
|
|
744
|
+
"arg",
|
|
745
|
+
"property",
|
|
746
|
+
"request",
|
|
747
|
+
"response",
|
|
748
|
+
"payload",
|
|
749
|
+
"body",
|
|
750
|
+
"error",
|
|
751
|
+
// Determiners and participles that introduce the subject: "The following parameter is not
|
|
752
|
+
// supported: reasoning_effort" puts one where a field name would sit.
|
|
753
|
+
"following",
|
|
754
|
+
"specified",
|
|
755
|
+
"given",
|
|
756
|
+
"provided",
|
|
757
|
+
"requested",
|
|
758
|
+
"supplied",
|
|
759
|
+
"above",
|
|
760
|
+
"a",
|
|
761
|
+
"an",
|
|
762
|
+
"the",
|
|
763
|
+
"same",
|
|
764
|
+
]);
|
|
765
|
+
|
|
766
|
+
/**
|
|
767
|
+
* A bare number (or numeric literal) is a value in every diagnostic that names a limit, never a
|
|
768
|
+
* field name, so "thinking budget 32000 is not supported" is not a competing-parameter refusal.
|
|
769
|
+
*/
|
|
770
|
+
const NUMERIC_VALUE_TOKEN = /^[0-9]+(?:\.[0-9]+)?$/;
|
|
771
|
+
|
|
772
|
+
/** Connectives and glue words allowed inside a published-value enumeration. */
|
|
773
|
+
const EFFORT_ENUMERATION_FILLER = new Set([
|
|
774
|
+
"and",
|
|
775
|
+
"or",
|
|
776
|
+
"values",
|
|
777
|
+
"value",
|
|
778
|
+
"supported",
|
|
779
|
+
"allowed",
|
|
780
|
+
"available",
|
|
781
|
+
"one",
|
|
782
|
+
"of",
|
|
783
|
+
"are",
|
|
784
|
+
"is",
|
|
785
|
+
]);
|
|
786
|
+
|
|
787
|
+
/**
|
|
788
|
+
* Whether a bracket slice is just a list of effort rungs, e.g. `['low','medium','high']`.
|
|
789
|
+
*
|
|
790
|
+
* "reasoning_effort must be one of ['low','medium','high']" is prose that lists the ladder. The
|
|
791
|
+
* structured-wrapper checks treat any bracket payload with commas and quotes as a malformed or
|
|
792
|
+
* reflected envelope, which made this genuine refusal terminal (#8173). A payload composed only
|
|
793
|
+
* of rung names is a value list, not an envelope.
|
|
794
|
+
*/
|
|
795
|
+
function isEffortValueEnumeration(slice: string): boolean {
|
|
796
|
+
const tokens = slice.match(/[A-Za-z_][A-Za-z0-9_.\-]*|[0-9]+(?:\.[0-9]+)?/g);
|
|
797
|
+
if (!tokens || tokens.length === 0) return false;
|
|
798
|
+
return tokens.every(token => {
|
|
799
|
+
const normalized = token.toLowerCase();
|
|
800
|
+
return EFFORT_RUNGS.has(normalized) || EFFORT_ENUMERATION_FILLER.has(normalized);
|
|
801
|
+
});
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
/** True when every bracketed group in the text is an effort-value enumeration. */
|
|
805
|
+
function carriesOnlyEffortEnumerations(text: string): boolean {
|
|
806
|
+
const groups = text.match(/\[[^\]]*\]/g);
|
|
807
|
+
return !!groups && groups.length > 0 && groups.every(isEffortValueEnumeration);
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
const STRUCTURAL_EFFORT_WORDS = new Set([
|
|
811
|
+
"level",
|
|
812
|
+
"mode",
|
|
813
|
+
"rung",
|
|
814
|
+
"rungs",
|
|
815
|
+
]);
|
|
816
|
+
|
|
817
|
+
const SUBJECT_FOLLOWING_VERBS = new Set([
|
|
818
|
+
"is",
|
|
819
|
+
"are",
|
|
820
|
+
"was",
|
|
821
|
+
"were",
|
|
822
|
+
"be",
|
|
823
|
+
"been",
|
|
824
|
+
"being",
|
|
825
|
+
"has",
|
|
826
|
+
"have",
|
|
827
|
+
"had",
|
|
828
|
+
"does",
|
|
829
|
+
"do",
|
|
830
|
+
"did",
|
|
831
|
+
"cannot",
|
|
832
|
+
"cant",
|
|
833
|
+
"can",
|
|
834
|
+
"could",
|
|
835
|
+
"will",
|
|
836
|
+
"would",
|
|
837
|
+
"shall",
|
|
838
|
+
"should",
|
|
839
|
+
"may",
|
|
840
|
+
"might",
|
|
841
|
+
"must",
|
|
842
|
+
]);
|
|
843
|
+
|
|
844
|
+
const REASONING_EFFORT_CONTEXT_REGEX = /\b(?:reasoning[._\s]+effort|reasoning[._\s]+parameters|reasoning|effort)\b/i;
|
|
845
|
+
|
|
846
|
+
/** How far from a rung value its own clause may name effort and still describe it. */
|
|
847
|
+
const EFFORT_DESCRIPTOR_WINDOW = 64;
|
|
848
|
+
|
|
849
|
+
function isExplicitFieldOrParameter(text: string, matchIndex: number, param: string): boolean {
|
|
850
|
+
if (SUBJECT_FOLLOWING_VERBS.has(param)) return false;
|
|
851
|
+
// "Unsupported parameter", "Invalid value", "Missing field" put a diagnostic word exactly
|
|
852
|
+
// where a field name sits. It is never the subject the sentence is about (#8173).
|
|
853
|
+
if (DIAGNOSTIC_NOISE_WORDS.has(param)) return false;
|
|
854
|
+
// A rung value is never a field name: "Invalid reasoning effort. The max field is invalid."
|
|
855
|
+
// names its subject explicitly in the sentence before, and no diagnostic says "the max field"
|
|
856
|
+
// about an unrelated field named max. Judging the value on its own words first keeps the
|
|
857
|
+
// quoted-field windows below from being applied to a ladder rung.
|
|
858
|
+
if (EFFORT_RUNGS.has(param) && !namesRungAsDeclaredField(text, matchIndex, param)) return false;
|
|
859
|
+
const pre = text.slice(Math.max(0, matchIndex - 48), matchIndex);
|
|
860
|
+
if (
|
|
861
|
+
/\b(?:reasoning[._\s]+effort|reasoning[._\s]+parameters|reasoning|effort)\s+(?:parameter|param|argument|arg|field|property)\s*(?:[:=]\s*['"`]?|['"`]|\s+)\s*$/i.test(
|
|
862
|
+
pre
|
|
863
|
+
)
|
|
864
|
+
) {
|
|
865
|
+
return false;
|
|
866
|
+
}
|
|
867
|
+
if (/\b(?:parameter|param|argument|arg|field|property)\s*(?:[:=]\s*['"`]?|['"`]|\s+)\s*$/i.test(pre)) return true;
|
|
868
|
+
const post = text.slice(matchIndex + param.length, Math.min(text.length, matchIndex + param.length + 32));
|
|
869
|
+
if (/^\s*['"`]?\s+(?:parameter|param|argument|arg|field|property)\b/i.test(post)) return true;
|
|
870
|
+
return false;
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
/**
|
|
874
|
+
* Whether the rung at `matchIndex` is introduced as a field in its own right — the shapes
|
|
875
|
+
* "the max field", "Invalid field: max", "parameter max" — rather than as a value under a
|
|
876
|
+
* diagnostic noun such as "Unsupported value: 'max'".
|
|
877
|
+
*/
|
|
878
|
+
function namesRungAsDeclaredField(text: string, matchIndex: number, param: string): boolean {
|
|
879
|
+
const pre = text.slice(Math.max(0, matchIndex - 48), matchIndex);
|
|
880
|
+
if (/\b(?:parameter|param|argument|arg|field|property)\s*(?:[:=]\s*['"`]?|['"`]|\s+)\s*$/i.test(pre)) return true;
|
|
881
|
+
const post = text.slice(matchIndex + param.length, Math.min(text.length, matchIndex + param.length + 32));
|
|
882
|
+
return /^\s*['"`]?\s+(?:parameter|param|argument|arg|field|property)\b/i.test(post);
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
function isEffortDescriptorInContext(text: string, matchIndex: number, param: string): boolean {
|
|
886
|
+
if (EFFORT_RUNGS.has(param)) {
|
|
887
|
+
if (namesRungAsDeclaredField(text, matchIndex, param)) return false;
|
|
888
|
+
// A rung is an effort descriptor when the surrounding words tie it to effort. The context
|
|
889
|
+
// window is the whole diagnostic minus OTHER parameters: a message that ends
|
|
890
|
+
// "Supported values are: 'low','medium','high'" must not turn the refused 'max' into a
|
|
891
|
+
// competing field merely because the same sentence lists a ladder.
|
|
892
|
+
const pre = text.slice(Math.max(0, matchIndex - EFFORT_DESCRIPTOR_WINDOW), matchIndex);
|
|
893
|
+
if (REASONING_EFFORT_CONTEXT_REGEX.test(pre)) return true;
|
|
894
|
+
const post = text.slice(matchIndex + param.length, Math.min(text.length, matchIndex + param.length + EFFORT_DESCRIPTOR_WINDOW));
|
|
895
|
+
return REASONING_EFFORT_CONTEXT_REGEX.test(post);
|
|
896
|
+
}
|
|
897
|
+
if (STRUCTURAL_EFFORT_WORDS.has(param)) {
|
|
898
|
+
const preText = text.slice(Math.max(0, matchIndex - 32), matchIndex);
|
|
899
|
+
return /(?:reasoning[._\s]+effort|reasoning|effort)\s*[:=]?\s*['"`]?$/i.test(preText);
|
|
900
|
+
}
|
|
901
|
+
return false;
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
function tokenStartIndex(m: RegExpExecArray, rawToken: string, isPrefixToken: boolean): number {
|
|
905
|
+
const offset = isPrefixToken ? m[0].indexOf(rawToken) : m[0].lastIndexOf(rawToken);
|
|
906
|
+
return offset >= 0 ? m.index + offset : m.index;
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
function isCompetingParameterToken(text: string, tokenIndex: number, rawToken: string): boolean {
|
|
910
|
+
const p = cleanParam(rawToken);
|
|
911
|
+
if (!p || EFFORT_PARAM_NAMES.has(p) || SUBJECT_FOLLOWING_VERBS.has(p)) return false;
|
|
912
|
+
// A diagnostic adjective or noun ("Unsupported", "invalid", "value", "field") occupies the
|
|
913
|
+
// syntactic slot of a field name without naming one. GENERIC_PARAM_WORDS covers most of them;
|
|
914
|
+
// "bad" and "malformed" were missing there, so the two sets stay separate.
|
|
915
|
+
if (DIAGNOSTIC_NOISE_WORDS.has(p)) return false;
|
|
916
|
+
// A bare number names a limit, not a request field ("thinking budget 32000 is not supported").
|
|
917
|
+
if (NUMERIC_VALUE_TOKEN.test(p)) return false;
|
|
918
|
+
if (isExplicitFieldOrParameter(text, tokenIndex, p)) return true;
|
|
919
|
+
if (GENERIC_PARAM_WORDS.has(p)) return false;
|
|
920
|
+
if (isEffortDescriptorInContext(text, tokenIndex, p)) return false;
|
|
921
|
+
return true;
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
/**
|
|
925
|
+
* Concrete request fields a diagnostic can name instead of effort. Unlike the heuristic subject
|
|
926
|
+
* patterns below, a member of this list is a real wire field, so naming one beside an
|
|
927
|
+
* authoritative effort param really is a different subject.
|
|
928
|
+
*/
|
|
929
|
+
const CONCRETE_FIELD_TERM =
|
|
930
|
+
/\b(?:temperature|top_p|top_k|max_tokens|max_completion_tokens|max_output_tokens|min_tokens|stop|stop_sequences|presence_penalty|frequency_penalty|repetition_penalty|logit_bias|logprobs|top_logprobs|seed|tools|tool_choice|functions|function_call|response_format|stream|stream_options|user|safety_identifier|service_tier|modalities|prediction|parallel_tool_calls|messages|prompt|input|image_url)\b/gi;
|
|
931
|
+
|
|
932
|
+
/**
|
|
933
|
+
* Whether the text names a concrete non-effort request field while rejecting something.
|
|
450
934
|
*
|
|
451
|
-
*
|
|
452
|
-
*
|
|
453
|
-
*
|
|
454
|
-
*
|
|
935
|
+
* This is the only inference allowed to override a structured `param` that already names
|
|
936
|
+
* reasoning effort. Everything heuristic in `diagnosticTextNamesOtherParameter` — adjective
|
|
937
|
+
* subjects, quoted rungs, "value:" prefixes — must not, or it would re-break every canonical
|
|
938
|
+
* effort refusal whose prose happens to quote the refused value (#8173).
|
|
939
|
+
*/
|
|
940
|
+
function diagnosticTextNamesConcreteOtherField(text: string): boolean {
|
|
941
|
+
for (let m = CONCRETE_FIELD_TERM.exec(text); m; m = CONCRETE_FIELD_TERM.exec(text)) {
|
|
942
|
+
const from = Math.max(0, m.index - REJECTION_WINDOW);
|
|
943
|
+
const to = Math.min(text.length, m.index + m[0].length + REJECTION_WINDOW);
|
|
944
|
+
if (REJECTION_LANGUAGE.test(text.slice(from, to))) return true;
|
|
945
|
+
}
|
|
946
|
+
return false;
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
function diagnosticTextNamesOtherParameter(text: string, authoritativeEffortSubject = false): boolean {
|
|
950
|
+
if (!text) return false;
|
|
951
|
+
const s = text.replace(GENERIC_ERROR_TYPE, " ");
|
|
952
|
+
if (authoritativeEffortSubject) return diagnosticTextNamesConcreteOtherField(s);
|
|
953
|
+
|
|
954
|
+
const paramPattern = /\b(?:parameter|param|argument|arg|field|property)\s*(?:[:=]\s*['"`]?|['"`]|\s+)['"`]?([a-zA-Z0-9_\-\.]+)['"`]?/gi;
|
|
955
|
+
for (let m = paramPattern.exec(s); m; m = paramPattern.exec(s)) {
|
|
956
|
+
const tokenIndex = tokenStartIndex(m, m[1], false);
|
|
957
|
+
if (isCompetingParameterToken(s, tokenIndex, m[1])) return true;
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
const prefixParamPattern = /\b['"`]?([a-zA-Z0-9_\-\.]+)['"`]?\s+(?:parameter|param|argument|arg|field|property)\b/gi;
|
|
961
|
+
for (let m = prefixParamPattern.exec(s); m; m = prefixParamPattern.exec(s)) {
|
|
962
|
+
const tokenIndex = tokenStartIndex(m, m[1], true);
|
|
963
|
+
if (isCompetingParameterToken(s, tokenIndex, m[1])) return true;
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
const subjectMustBe = /\b['"`]?([a-zA-Z0-9_\-\.]+)['"`]?\s+must\s+be\b/gi;
|
|
967
|
+
for (let m = subjectMustBe.exec(s); m; m = subjectMustBe.exec(s)) {
|
|
968
|
+
const tokenIndex = tokenStartIndex(m, m[1], true);
|
|
969
|
+
if (isCompetingParameterToken(s, tokenIndex, m[1])) return true;
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
const subjectIsRejection =
|
|
973
|
+
/\b['"`]?([a-zA-Z0-9_\-\.]+)['"`]?\s+(?:is|are)\s+(?:invalid|not\s+valid|unsupported|unrecognized|unknown|not\s+allowed|not\s+permitted|not\s+supported|required|missing)\b/gi;
|
|
974
|
+
for (let m = subjectIsRejection.exec(s); m; m = subjectIsRejection.exec(s)) {
|
|
975
|
+
const tokenIndex = tokenStartIndex(m, m[1], true);
|
|
976
|
+
if (isCompetingParameterToken(s, tokenIndex, m[1])) return true;
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
const subjectColon =
|
|
980
|
+
/\b['"`]?([a-zA-Z0-9_\-\.]+)['"`]?\s*:\s*(?:must\s+be|invalid|unsupported|unrecognized|unknown|expected|required|missing|not\s+allowed)\b/gi;
|
|
981
|
+
for (let m = subjectColon.exec(s); m; m = subjectColon.exec(s)) {
|
|
982
|
+
const tokenIndex = tokenStartIndex(m, m[1], true);
|
|
983
|
+
if (isCompetingParameterToken(s, tokenIndex, m[1])) return true;
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
const rejectionExtra =
|
|
987
|
+
/\b(?:unexpected|missing|cannot\s+(?:specify|use|set|pass|provide))\s+(?:field|param|parameter|argument|property)?\s*['"`]?([a-zA-Z0-9_\-\.]+)['"`]?/gi;
|
|
988
|
+
for (let m = rejectionExtra.exec(s); m; m = rejectionExtra.exec(s)) {
|
|
989
|
+
const tokenIndex = tokenStartIndex(m, m[1], false);
|
|
990
|
+
if (isCompetingParameterToken(s, tokenIndex, m[1])) return true;
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
const nonEffortTerm = /\b(?:temperature|top_p|top_k|max_tokens|max_completion_tokens|max_output_tokens|min_tokens|stop|stop_sequences|presence_penalty|frequency_penalty|repetition_penalty|logit_bias|logprobs|top_logprobs|seed|tools|tool_choice|functions|function_call|response_format|stream|stream_options|user|service_tier|modalities|prediction|parallel_tool_calls|messages|prompt)\b/gi;
|
|
994
|
+
for (let m = nonEffortTerm.exec(s); m; m = nonEffortTerm.exec(s)) {
|
|
995
|
+
const from = Math.max(0, m.index - REJECTION_WINDOW);
|
|
996
|
+
const to = Math.min(s.length, m.index + m[0].length + REJECTION_WINDOW);
|
|
997
|
+
if (REJECTION_LANGUAGE.test(s.slice(from, to))) return true;
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
const rejectionDirect = /\b(?:invalid|unsupported|unrecognized|unknown)\s+['"`]?([a-zA-Z0-9_\-\.]+)['"`]?/gi;
|
|
1001
|
+
for (let m = rejectionDirect.exec(s); m; m = rejectionDirect.exec(s)) {
|
|
1002
|
+
const tokenIndex = tokenStartIndex(m, m[1], false);
|
|
1003
|
+
if (isCompetingParameterToken(s, tokenIndex, m[1])) return true;
|
|
1004
|
+
}
|
|
1005
|
+
return false;
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
function isConflictingDiagnosticProse(str: string | undefined, authoritativeEffortSubject = false): boolean {
|
|
1009
|
+
if (!str) return false;
|
|
1010
|
+
const s = str.trim();
|
|
1011
|
+
if (!s) return false;
|
|
1012
|
+
if (
|
|
1013
|
+
/\b(?:permission[-_]denied|insufficient[-_]quota|rate[-_]limit[-_]exceeded|model[-_]not[-_]found|context[-_]length[-_]exceeded|access[-_]denied|unauthorized|invalid[-_]api[-_]key|account[-_]deactivated|billing[-_]hard[-_]limit)\b/i.test(s)
|
|
1014
|
+
) {
|
|
1015
|
+
return true;
|
|
1016
|
+
}
|
|
1017
|
+
const codeMatch = /\bcode\s*[:=]\s*["']?([a-zA-Z0-9_\-]+)["']?/i.exec(s);
|
|
1018
|
+
if (codeMatch && codeMatch[1]) {
|
|
1019
|
+
const code = normalizeErrorTag(codeMatch[1]);
|
|
1020
|
+
if (!EFFORT_COMPATIBLE_CODES.has(code) && !isHttpStatusText(code)) return true;
|
|
1021
|
+
}
|
|
1022
|
+
const typeMatch = /\btype\s*[:=]\s*["']?([a-zA-Z0-9_\-]+)["']?/i.exec(s);
|
|
1023
|
+
if (typeMatch && typeMatch[1]) {
|
|
1024
|
+
const type = normalizeErrorTag(typeMatch[1]);
|
|
1025
|
+
if (!EFFORT_COMPATIBLE_TYPES.has(type)) return true;
|
|
1026
|
+
}
|
|
1027
|
+
if (diagnosticTextNamesOtherParameter(s, authoritativeEffortSubject)) {
|
|
1028
|
+
return true;
|
|
1029
|
+
}
|
|
1030
|
+
return false;
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
/**
|
|
1034
|
+
* Whether a numeric code is the HTTP status echoed back rather than a vendor error code.
|
|
1035
|
+
*
|
|
1036
|
+
* Google answers a bad reasoning effort with `{"code":400,"error":{"message":"…"}}`, where the
|
|
1037
|
+
* numeric field is the response status. Treating it as an unrecognized semantic code made that
|
|
1038
|
+
* genuine refusal terminal (#8173). Only 4xx is accepted: a numeric 5xx is a server failure and
|
|
1039
|
+
* must keep its terminal verdict.
|
|
1040
|
+
*/
|
|
1041
|
+
function isHttpStatusText(token: string): boolean {
|
|
1042
|
+
if (!NUMERIC_VALUE_TOKEN.test(token)) return false;
|
|
1043
|
+
const value = Number(token);
|
|
1044
|
+
return Number.isInteger(value) && value >= 400 && value <= 499;
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
function isHttpStatusNumber(value: unknown): boolean {
|
|
1048
|
+
return typeof value === "number" && Number.isInteger(value) && value >= 400 && value <= 499;
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
/**
|
|
1052
|
+
* Rejects error envelopes that carry a conflicting code (e.g. permission_denied, insufficient_quota,
|
|
1053
|
+
* rate_limit_exceeded, model_not_found, malformed non-string code) or competing diagnostic parameters
|
|
1054
|
+
* (e.g. reasoning_effort at root with an inner error identifying temperature) so they stay terminal
|
|
1055
|
+
* or proceed to combo failover without false reasoning-effort learning or same-target ladder retries (#8173).
|
|
455
1056
|
*/
|
|
456
|
-
export function
|
|
1057
|
+
export function hasConflictingReasoningEffortCode(text: string | undefined): boolean {
|
|
457
1058
|
if (!text) return false;
|
|
1059
|
+
if (isIncompleteStructuredWrapper(text)) return true;
|
|
1060
|
+
let unescaped = text.trim();
|
|
1061
|
+
for (let d = 0; d < 3; d += 1) {
|
|
1062
|
+
if (unescaped.startsWith("Provider error 400: ")) {
|
|
1063
|
+
unescaped = unescaped.slice("Provider error 400: ".length).trim();
|
|
1064
|
+
}
|
|
1065
|
+
if (unescaped.startsWith("data:") && !unescaped.includes("\n")) {
|
|
1066
|
+
unescaped = unescaped.slice("data:".length).trim();
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
let parsed: unknown;
|
|
1070
|
+
let outerPrefix = "";
|
|
1071
|
+
let outerSuffix = "";
|
|
1072
|
+
try {
|
|
1073
|
+
parsed = JSON.parse(unescaped);
|
|
1074
|
+
} catch {
|
|
1075
|
+
const extracted = extractJsonEnvelopeWithContext(unescaped);
|
|
1076
|
+
if (extracted) {
|
|
1077
|
+
parsed = extracted.value;
|
|
1078
|
+
outerPrefix = extracted.prefix;
|
|
1079
|
+
outerSuffix = extracted.suffix;
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
if (isConflictingDiagnosticProse(outerPrefix) || isConflictingDiagnosticProse(outerSuffix)) {
|
|
1083
|
+
return true;
|
|
1084
|
+
}
|
|
1085
|
+
if (!parsed || typeof parsed !== "object") {
|
|
1086
|
+
if (isIncompleteStructuredWrapper(unescaped)) return true;
|
|
1087
|
+
const hasBraces = unescaped.includes("{") && unescaped.includes("}");
|
|
1088
|
+
const hasBrackets =
|
|
1089
|
+
unescaped.includes('["') ||
|
|
1090
|
+
(unescaped.includes("[") &&
|
|
1091
|
+
unescaped.includes("]") &&
|
|
1092
|
+
(unescaped.includes('"') || unescaped.includes("'") || unescaped.includes(",")));
|
|
1093
|
+
if (hasBraces || (hasBrackets && !carriesOnlyEffortEnumerations(unescaped))) return true;
|
|
1094
|
+
return isConflictingDiagnosticProse(unescaped);
|
|
1095
|
+
}
|
|
1096
|
+
try {
|
|
1097
|
+
const queue: unknown[] = [parsed];
|
|
1098
|
+
let examined = 0;
|
|
1099
|
+
while (queue.length > 0 && examined < 32) {
|
|
1100
|
+
const candidate = queue.shift();
|
|
1101
|
+
examined += 1;
|
|
1102
|
+
if (!candidate || typeof candidate !== "object") continue;
|
|
1103
|
+
if (Array.isArray(candidate)) {
|
|
1104
|
+
if (candidate.length > 32) return true;
|
|
1105
|
+
for (const item of candidate) {
|
|
1106
|
+
if (item && typeof item === "object") {
|
|
1107
|
+
queue.push(item);
|
|
1108
|
+
} else if (typeof item === "string") {
|
|
1109
|
+
if (item.length > 16_384) return true;
|
|
1110
|
+
let innerItem: unknown;
|
|
1111
|
+
let innerPrefix = "";
|
|
1112
|
+
let innerSuffix = "";
|
|
1113
|
+
try {
|
|
1114
|
+
innerItem = JSON.parse(item);
|
|
1115
|
+
} catch {
|
|
1116
|
+
const extractedItem = extractJsonEnvelopeWithContext(item);
|
|
1117
|
+
if (extractedItem) {
|
|
1118
|
+
innerItem = extractedItem.value;
|
|
1119
|
+
innerPrefix = extractedItem.prefix;
|
|
1120
|
+
innerSuffix = extractedItem.suffix;
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
if (innerItem && typeof innerItem === "object") {
|
|
1124
|
+
if (isConflictingDiagnosticProse(innerPrefix) || isConflictingDiagnosticProse(innerSuffix)) {
|
|
1125
|
+
return true;
|
|
1126
|
+
}
|
|
1127
|
+
queue.push(innerItem);
|
|
1128
|
+
} else if (isIncompleteStructuredWrapper(item)) {
|
|
1129
|
+
return true;
|
|
1130
|
+
} else {
|
|
1131
|
+
const trimmed = item.trim();
|
|
1132
|
+
if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
|
|
1133
|
+
try {
|
|
1134
|
+
const parsedItem = JSON.parse(item);
|
|
1135
|
+
if (parsedItem && typeof parsedItem === "object") {
|
|
1136
|
+
queue.push(parsedItem);
|
|
1137
|
+
} else {
|
|
1138
|
+
return true;
|
|
1139
|
+
}
|
|
1140
|
+
} catch {
|
|
1141
|
+
return true;
|
|
1142
|
+
}
|
|
1143
|
+
} else {
|
|
1144
|
+
const codeLike = normalizeErrorTag(trimmed);
|
|
1145
|
+
if (
|
|
1146
|
+
!codeLike.includes(" ") &&
|
|
1147
|
+
(codeLike.includes("_") || codeLike.length < 32) &&
|
|
1148
|
+
!EFFORT_COMPATIBLE_CODES.has(codeLike) &&
|
|
1149
|
+
!EFFORT_COMPATIBLE_TYPES.has(codeLike)
|
|
1150
|
+
) {
|
|
1151
|
+
return true;
|
|
1152
|
+
}
|
|
1153
|
+
if (isConflictingDiagnosticProse(trimmed)) {
|
|
1154
|
+
return true;
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
} else {
|
|
1159
|
+
return true;
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
continue;
|
|
1163
|
+
}
|
|
1164
|
+
const rec = candidate as Record<string, unknown>;
|
|
1165
|
+
// A structured param/field naming effort is authoritative about the subject. Text
|
|
1166
|
+
// inference may only override it by naming a concrete other request field, never by
|
|
1167
|
+
// reading a diagnostic adjective or the refused value as a field name (#8173).
|
|
1168
|
+
const authoritativeEffortSubject = typeof rec.param === "string" && EFFORT_PARAM_NAMES.has(rec.param.trim().toLowerCase());
|
|
1169
|
+
if (rec.param !== undefined && rec.param !== null) {
|
|
1170
|
+
if (typeof rec.param !== "string") return true;
|
|
1171
|
+
const param = rec.param.trim().toLowerCase();
|
|
1172
|
+
if (param.length > 0 && !EFFORT_PARAM_NAMES.has(param)) return true;
|
|
1173
|
+
}
|
|
1174
|
+
if (rec.code !== undefined && rec.code !== null) {
|
|
1175
|
+
if (isHttpStatusNumber(rec.code)) {
|
|
1176
|
+
// An HTTP status echoed into `code` says nothing about which field was refused.
|
|
1177
|
+
} else if (typeof rec.code !== "string") return true;
|
|
1178
|
+
else {
|
|
1179
|
+
const code = normalizeErrorTag(rec.code);
|
|
1180
|
+
if (!EFFORT_COMPATIBLE_CODES.has(code)) return true;
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
if (rec.type !== undefined && rec.type !== null) {
|
|
1184
|
+
if (typeof rec.type !== "string") return true;
|
|
1185
|
+
const type = normalizeErrorTag(rec.type);
|
|
1186
|
+
if (!EFFORT_COMPATIBLE_TYPES.has(type)) return true;
|
|
1187
|
+
}
|
|
1188
|
+
for (const field of ["message", "error", "details", "detail", "response", "last_error", "errors"] as const) {
|
|
1189
|
+
const val = rec[field];
|
|
1190
|
+
if (val && typeof val === "object") {
|
|
1191
|
+
queue.push(val);
|
|
1192
|
+
} else if (typeof val === "string") {
|
|
1193
|
+
let inner: unknown;
|
|
1194
|
+
let innerPrefix = "";
|
|
1195
|
+
let innerSuffix = "";
|
|
1196
|
+
try {
|
|
1197
|
+
inner = JSON.parse(val);
|
|
1198
|
+
} catch {
|
|
1199
|
+
const extracted = extractJsonEnvelopeWithContext(val);
|
|
1200
|
+
if (extracted) {
|
|
1201
|
+
inner = extracted.value;
|
|
1202
|
+
innerPrefix = extracted.prefix;
|
|
1203
|
+
innerSuffix = extracted.suffix;
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
if (inner && typeof inner === "object") {
|
|
1207
|
+
if (isConflictingDiagnosticProse(innerPrefix, authoritativeEffortSubject) || isConflictingDiagnosticProse(innerSuffix, authoritativeEffortSubject)) {
|
|
1208
|
+
return true;
|
|
1209
|
+
}
|
|
1210
|
+
queue.push(inner);
|
|
1211
|
+
} else if (isIncompleteStructuredWrapper(val)) {
|
|
1212
|
+
return true;
|
|
1213
|
+
} else if (isConflictingDiagnosticProse(val, authoritativeEffortSubject)) {
|
|
1214
|
+
return true;
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
if (queue.length > 0) {
|
|
1220
|
+
return true;
|
|
1221
|
+
}
|
|
1222
|
+
} catch {
|
|
1223
|
+
return false;
|
|
1224
|
+
}
|
|
1225
|
+
return false;
|
|
1226
|
+
}
|
|
1227
|
+
|
|
1228
|
+
function diagnosticTextBlamesReasoningEffort(text: string): boolean {
|
|
1229
|
+
if (diagnosticTextNamesOtherParameter(text)) return false;
|
|
458
1230
|
if (/unsupported.{0,24}effort/i.test(text)) return true;
|
|
459
|
-
// An upstream that names the offending parameter has already said which one it means.
|
|
460
|
-
if (/["']?param["']?\s*[:=]\s*["']?(?:reasoning[._ ]effort|reasoning)/i.test(text)) return true;
|
|
461
1231
|
const scanned = text.replace(GENERIC_ERROR_TYPE, " ");
|
|
462
1232
|
const term = /reasoning\.effort|reasoning_effort|reasoning effort|thinking budget|reasoning_parameters/gi;
|
|
463
1233
|
for (let match = term.exec(scanned); match; match = term.exec(scanned)) {
|
|
464
|
-
const
|
|
465
|
-
const
|
|
466
|
-
|
|
1234
|
+
const preText = scanned.slice(0, match.index);
|
|
1235
|
+
const postText = scanned.slice(match.index + match[0].length);
|
|
1236
|
+
const lastBoundary = Math.max(
|
|
1237
|
+
preText.lastIndexOf(";"),
|
|
1238
|
+
preText.lastIndexOf("\n"),
|
|
1239
|
+
preText.lastIndexOf("|"),
|
|
1240
|
+
preText.search(/\.(?:\s+|$)(?=[^.]*$)/)
|
|
1241
|
+
);
|
|
1242
|
+
const clauseStart = lastBoundary !== -1 ? lastBoundary + 1 : 0;
|
|
1243
|
+
const nextBoundary = postText.search(/[;\n|]|\.(?:\s+|$)/);
|
|
1244
|
+
const clauseEnd = nextBoundary !== -1 ? match.index + match[0].length + nextBoundary : scanned.length;
|
|
1245
|
+
|
|
1246
|
+
const from = Math.max(clauseStart, match.index - REJECTION_WINDOW);
|
|
1247
|
+
const to = Math.min(clauseEnd, match.index + match[0].length + REJECTION_WINDOW);
|
|
1248
|
+
const windowText = scanned.slice(from, to);
|
|
1249
|
+
if (REJECTION_LANGUAGE.test(windowText)) {
|
|
1250
|
+
if (!diagnosticTextNamesOtherParameter(windowText)) {
|
|
1251
|
+
return true;
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
return false;
|
|
1256
|
+
}
|
|
1257
|
+
|
|
1258
|
+
function diagnosticRecordBlamesReasoningEffort(rec: Record<string, unknown>, depth = 0): boolean {
|
|
1259
|
+
if (depth > 4) return false;
|
|
1260
|
+
if (typeof rec.param === "string") {
|
|
1261
|
+
const param = rec.param.trim().toLowerCase();
|
|
1262
|
+
if (EFFORT_PARAM_NAMES.has(param)) return true;
|
|
1263
|
+
return false;
|
|
1264
|
+
}
|
|
1265
|
+
if (typeof rec.message === "string") {
|
|
1266
|
+
if (rec.message.includes("{") || rec.message.startsWith("Provider error 400: ")) {
|
|
1267
|
+
return isReasoningEffortRejection(rec.message, depth + 1);
|
|
1268
|
+
}
|
|
1269
|
+
if (diagnosticTextBlamesReasoningEffort(rec.message)) return true;
|
|
1270
|
+
}
|
|
1271
|
+
if (typeof rec.error === "string") {
|
|
1272
|
+
if (rec.error.includes("{") || rec.error.startsWith("Provider error 400: ")) {
|
|
1273
|
+
return isReasoningEffortRejection(rec.error, depth + 1);
|
|
1274
|
+
}
|
|
1275
|
+
if (diagnosticTextBlamesReasoningEffort(rec.error)) return true;
|
|
1276
|
+
}
|
|
1277
|
+
if (typeof rec.detail === "string") {
|
|
1278
|
+
if (rec.detail.includes("{") || rec.detail.startsWith("Provider error 400: ")) {
|
|
1279
|
+
return isReasoningEffortRejection(rec.detail, depth + 1);
|
|
1280
|
+
}
|
|
1281
|
+
if (diagnosticTextBlamesReasoningEffort(rec.detail)) return true;
|
|
1282
|
+
} else if (Array.isArray(rec.detail)) {
|
|
1283
|
+
for (const item of rec.detail) {
|
|
1284
|
+
if (item && typeof item === "object") {
|
|
1285
|
+
if (diagnosticRecordBlamesReasoningEffort(item as Record<string, unknown>, depth + 1)) return true;
|
|
1286
|
+
} else if (typeof item === "string") {
|
|
1287
|
+
if (item.includes("{") || item.startsWith("Provider error 400: ")) {
|
|
1288
|
+
if (isReasoningEffortRejection(item, depth + 1)) return true;
|
|
1289
|
+
} else if (diagnosticTextBlamesReasoningEffort(item)) {
|
|
1290
|
+
return true;
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
} else if (rec.detail && typeof rec.detail === "object") {
|
|
1295
|
+
if (diagnosticRecordBlamesReasoningEffort(rec.detail as Record<string, unknown>, depth + 1)) return true;
|
|
1296
|
+
}
|
|
1297
|
+
if (typeof rec.details === "string") {
|
|
1298
|
+
if (rec.details.includes("{") || rec.details.startsWith("Provider error 400: ")) {
|
|
1299
|
+
return isReasoningEffortRejection(rec.details, depth + 1);
|
|
1300
|
+
}
|
|
1301
|
+
if (diagnosticTextBlamesReasoningEffort(rec.details)) return true;
|
|
1302
|
+
} else if (Array.isArray(rec.details)) {
|
|
1303
|
+
for (const item of rec.details) {
|
|
1304
|
+
if (item && typeof item === "object") {
|
|
1305
|
+
if (diagnosticRecordBlamesReasoningEffort(item as Record<string, unknown>, depth + 1)) return true;
|
|
1306
|
+
} else if (typeof item === "string") {
|
|
1307
|
+
if (item.includes("{") || item.startsWith("Provider error 400: ")) {
|
|
1308
|
+
if (isReasoningEffortRejection(item, depth + 1)) return true;
|
|
1309
|
+
} else if (diagnosticTextBlamesReasoningEffort(item)) {
|
|
1310
|
+
return true;
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
} else if (rec.details && typeof rec.details === "object") {
|
|
1315
|
+
if (diagnosticRecordBlamesReasoningEffort(rec.details as Record<string, unknown>, depth + 1)) return true;
|
|
1316
|
+
}
|
|
1317
|
+
if (typeof rec.last_error === "string") {
|
|
1318
|
+
if (rec.last_error.includes("{") || rec.last_error.startsWith("Provider error 400: ")) {
|
|
1319
|
+
return isReasoningEffortRejection(rec.last_error, depth + 1);
|
|
1320
|
+
}
|
|
1321
|
+
if (diagnosticTextBlamesReasoningEffort(rec.last_error)) return true;
|
|
1322
|
+
} else if (rec.last_error && typeof rec.last_error === "object") {
|
|
1323
|
+
if (diagnosticRecordBlamesReasoningEffort(rec.last_error as Record<string, unknown>, depth + 1)) return true;
|
|
467
1324
|
}
|
|
468
1325
|
return false;
|
|
469
1326
|
}
|
|
470
1327
|
|
|
1328
|
+
/**
|
|
1329
|
+
* Evidence test for a rejection body: does it blame reasoning effort?
|
|
1330
|
+
*
|
|
1331
|
+
* Restricts inspections to authoritative diagnostic carriers (error, errors, details, detail, last_error, response)
|
|
1332
|
+
* so echoed request context (e.g. request.param: "reasoning_effort") does not falsely classify unrelated 400s
|
|
1333
|
+
* (such as temperature or max_tokens errors) as effort refusals (#8173).
|
|
1334
|
+
*/
|
|
1335
|
+
export function isReasoningEffortRejection(text: string | undefined, depth = 0): boolean {
|
|
1336
|
+
if (!text || depth > 4) return false;
|
|
1337
|
+
if (isHardPolicyOrOriginRefusal(text)) return false;
|
|
1338
|
+
if (hasConflictingReasoningEffortCode(text)) return false;
|
|
1339
|
+
|
|
1340
|
+
let unescaped = text.trim();
|
|
1341
|
+
for (let d = 0; d < 3; d += 1) {
|
|
1342
|
+
if (unescaped.startsWith("Provider error 400: ")) {
|
|
1343
|
+
unescaped = unescaped.slice("Provider error 400: ".length).trim();
|
|
1344
|
+
}
|
|
1345
|
+
if (unescaped.startsWith("data:") && !unescaped.includes("\n")) {
|
|
1346
|
+
unescaped = unescaped.slice("data:".length).trim();
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1350
|
+
let parsed: unknown;
|
|
1351
|
+
try {
|
|
1352
|
+
parsed = JSON.parse(unescaped);
|
|
1353
|
+
} catch {
|
|
1354
|
+
parsed = extractJsonEnvelope(unescaped);
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
if (parsed && typeof parsed === "object") {
|
|
1358
|
+
if (Array.isArray(parsed)) {
|
|
1359
|
+
if (hasConflictingReasoningEffortCode(unescaped)) return false;
|
|
1360
|
+
for (const item of parsed) {
|
|
1361
|
+
if (item && typeof item === "object") {
|
|
1362
|
+
if (diagnosticRecordBlamesReasoningEffort(item as Record<string, unknown>, depth + 1)) return true;
|
|
1363
|
+
} else if (typeof item === "string") {
|
|
1364
|
+
if (item.includes("{") || item.startsWith("Provider error 400: ")) {
|
|
1365
|
+
if (isReasoningEffortRejection(item, depth + 1)) return true;
|
|
1366
|
+
} else if (diagnosticTextBlamesReasoningEffort(item)) {
|
|
1367
|
+
return true;
|
|
1368
|
+
}
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
return false;
|
|
1372
|
+
}
|
|
1373
|
+
|
|
1374
|
+
const root = parsed as Record<string, unknown>;
|
|
1375
|
+
|
|
1376
|
+
if (root.error !== undefined && root.error !== null) {
|
|
1377
|
+
if (typeof root.error === "object" && !Array.isArray(root.error)) {
|
|
1378
|
+
if (diagnosticRecordBlamesReasoningEffort(root.error as Record<string, unknown>, depth + 1)) return true;
|
|
1379
|
+
} else if (typeof root.error === "string") {
|
|
1380
|
+
if (root.error.includes("{") || root.error.startsWith("Provider error 400: ")) {
|
|
1381
|
+
if (isReasoningEffortRejection(root.error, depth + 1)) return true;
|
|
1382
|
+
} else if (diagnosticTextBlamesReasoningEffort(root.error)) {
|
|
1383
|
+
return true;
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1388
|
+
if (Array.isArray(root.errors)) {
|
|
1389
|
+
for (const item of root.errors) {
|
|
1390
|
+
if (item && typeof item === "object") {
|
|
1391
|
+
if (diagnosticRecordBlamesReasoningEffort(item as Record<string, unknown>, depth + 1)) return true;
|
|
1392
|
+
} else if (typeof item === "string") {
|
|
1393
|
+
if (item.includes("{") || item.startsWith("Provider error 400: ")) {
|
|
1394
|
+
if (isReasoningEffortRejection(item, depth + 1)) return true;
|
|
1395
|
+
} else if (diagnosticTextBlamesReasoningEffort(item)) {
|
|
1396
|
+
return true;
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1401
|
+
|
|
1402
|
+
if (Array.isArray(root.details)) {
|
|
1403
|
+
for (const item of root.details) {
|
|
1404
|
+
if (item && typeof item === "object") {
|
|
1405
|
+
if (diagnosticRecordBlamesReasoningEffort(item as Record<string, unknown>, depth + 1)) return true;
|
|
1406
|
+
} else if (typeof item === "string") {
|
|
1407
|
+
if (item.includes("{") || item.startsWith("Provider error 400: ")) {
|
|
1408
|
+
if (isReasoningEffortRejection(item, depth + 1)) return true;
|
|
1409
|
+
} else if (diagnosticTextBlamesReasoningEffort(item)) {
|
|
1410
|
+
return true;
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
} else if (typeof root.details === "string") {
|
|
1415
|
+
if (root.details.includes("{") || root.details.startsWith("Provider error 400: ")) {
|
|
1416
|
+
if (isReasoningEffortRejection(root.details, depth + 1)) return true;
|
|
1417
|
+
} else if (diagnosticTextBlamesReasoningEffort(root.details)) {
|
|
1418
|
+
return true;
|
|
1419
|
+
}
|
|
1420
|
+
} else if (root.details && typeof root.details === "object") {
|
|
1421
|
+
if (diagnosticRecordBlamesReasoningEffort(root.details as Record<string, unknown>, depth + 1)) return true;
|
|
1422
|
+
}
|
|
1423
|
+
|
|
1424
|
+
if (typeof root.detail === "string") {
|
|
1425
|
+
if (root.detail.includes("{") || root.detail.startsWith("Provider error 400: ")) {
|
|
1426
|
+
if (isReasoningEffortRejection(root.detail, depth + 1)) return true;
|
|
1427
|
+
} else if (diagnosticTextBlamesReasoningEffort(root.detail)) {
|
|
1428
|
+
return true;
|
|
1429
|
+
}
|
|
1430
|
+
} else if (Array.isArray(root.detail)) {
|
|
1431
|
+
for (const item of root.detail) {
|
|
1432
|
+
if (item && typeof item === "object") {
|
|
1433
|
+
if (diagnosticRecordBlamesReasoningEffort(item as Record<string, unknown>, depth + 1)) return true;
|
|
1434
|
+
} else if (typeof item === "string") {
|
|
1435
|
+
if (item.includes("{") || item.startsWith("Provider error 400: ")) {
|
|
1436
|
+
if (isReasoningEffortRejection(item, depth + 1)) return true;
|
|
1437
|
+
} else if (diagnosticTextBlamesReasoningEffort(item)) {
|
|
1438
|
+
return true;
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1442
|
+
} else if (root.detail && typeof root.detail === "object") {
|
|
1443
|
+
if (diagnosticRecordBlamesReasoningEffort(root.detail as Record<string, unknown>, depth + 1)) return true;
|
|
1444
|
+
}
|
|
1445
|
+
|
|
1446
|
+
if (typeof root.last_error === "string") {
|
|
1447
|
+
if (root.last_error.includes("{") || root.last_error.startsWith("Provider error 400: ")) {
|
|
1448
|
+
if (isReasoningEffortRejection(root.last_error, depth + 1)) return true;
|
|
1449
|
+
} else if (diagnosticTextBlamesReasoningEffort(root.last_error)) {
|
|
1450
|
+
return true;
|
|
1451
|
+
}
|
|
1452
|
+
} else if (root.last_error && typeof root.last_error === "object") {
|
|
1453
|
+
if (diagnosticRecordBlamesReasoningEffort(root.last_error as Record<string, unknown>, depth + 1)) return true;
|
|
1454
|
+
}
|
|
1455
|
+
|
|
1456
|
+
if (root.response && typeof root.response === "object") {
|
|
1457
|
+
const resp = root.response as Record<string, unknown>;
|
|
1458
|
+
if (resp.error && typeof resp.error === "object") {
|
|
1459
|
+
if (diagnosticRecordBlamesReasoningEffort(resp.error as Record<string, unknown>, depth + 1)) return true;
|
|
1460
|
+
}
|
|
1461
|
+
if (typeof resp.last_error === "string") {
|
|
1462
|
+
if (resp.last_error.includes("{") || resp.last_error.startsWith("Provider error 400: ")) {
|
|
1463
|
+
if (isReasoningEffortRejection(resp.last_error, depth + 1)) return true;
|
|
1464
|
+
} else if (diagnosticTextBlamesReasoningEffort(resp.last_error)) {
|
|
1465
|
+
return true;
|
|
1466
|
+
}
|
|
1467
|
+
} else if (resp.last_error && typeof resp.last_error === "object") {
|
|
1468
|
+
if (diagnosticRecordBlamesReasoningEffort(resp.last_error as Record<string, unknown>, depth + 1)) return true;
|
|
1469
|
+
}
|
|
1470
|
+
if (typeof resp.details === "string") {
|
|
1471
|
+
if (resp.details.includes("{") || resp.details.startsWith("Provider error 400: ")) {
|
|
1472
|
+
if (isReasoningEffortRejection(resp.details, depth + 1)) return true;
|
|
1473
|
+
} else if (diagnosticTextBlamesReasoningEffort(resp.details)) {
|
|
1474
|
+
return true;
|
|
1475
|
+
}
|
|
1476
|
+
} else if (resp.details && typeof resp.details === "object") {
|
|
1477
|
+
if (diagnosticRecordBlamesReasoningEffort(resp.details as Record<string, unknown>, depth + 1)) return true;
|
|
1478
|
+
}
|
|
1479
|
+
if (typeof resp.detail === "string") {
|
|
1480
|
+
if (resp.detail.includes("{") || resp.detail.startsWith("Provider error 400: ")) {
|
|
1481
|
+
if (isReasoningEffortRejection(resp.detail, depth + 1)) return true;
|
|
1482
|
+
} else if (diagnosticTextBlamesReasoningEffort(resp.detail)) {
|
|
1483
|
+
return true;
|
|
1484
|
+
}
|
|
1485
|
+
} else if (resp.detail && typeof resp.detail === "object") {
|
|
1486
|
+
if (diagnosticRecordBlamesReasoningEffort(resp.detail as Record<string, unknown>, depth + 1)) return true;
|
|
1487
|
+
}
|
|
1488
|
+
}
|
|
1489
|
+
|
|
1490
|
+
if (root.error === undefined || typeof root.error !== "object") {
|
|
1491
|
+
if (diagnosticRecordBlamesReasoningEffort(root, depth + 1)) return true;
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1494
|
+
return false;
|
|
1495
|
+
}
|
|
1496
|
+
|
|
1497
|
+
const hasBraces = unescaped.includes("{") && unescaped.includes("}");
|
|
1498
|
+
const hasBrackets =
|
|
1499
|
+
unescaped.includes('["') ||
|
|
1500
|
+
(unescaped.includes("[") &&
|
|
1501
|
+
unescaped.includes("]") &&
|
|
1502
|
+
(unescaped.includes('"') || unescaped.includes("'") || unescaped.includes(",")));
|
|
1503
|
+
if (hasBraces || (hasBrackets && !carriesOnlyEffortEnumerations(unescaped))) return false;
|
|
1504
|
+
if (isIncompleteStructuredWrapper(unescaped)) return false;
|
|
1505
|
+
|
|
1506
|
+
return diagnosticTextBlamesReasoningEffort(unescaped);
|
|
1507
|
+
}
|
|
1508
|
+
|
|
471
1509
|
/**
|
|
472
1510
|
* Plan a single-rung downgrade for a rejected request: records the refusal (so later turns
|
|
473
1511
|
* clamp before dispatch) and returns the next lower rung the model does publish.
|
|
@@ -478,6 +1516,7 @@ export function planReasoningEffortDowngrade(args: {
|
|
|
478
1516
|
requested?: string;
|
|
479
1517
|
rejectionText?: string;
|
|
480
1518
|
}): { effort: string; recorded: boolean } | undefined {
|
|
1519
|
+
if (args.rejectionText && (isHardPolicyOrOriginRefusal(args.rejectionText) || hasConflictingReasoningEffortCode(args.rejectionText))) return undefined;
|
|
481
1520
|
const requested = args.requested === "ultra" ? "max" : args.requested;
|
|
482
1521
|
if (!requested || !RANKED.includes(requested)) return undefined;
|
|
483
1522
|
const recorded = recordUnsupportedReasoningEffort(args.provider, args.modelId, requested, args.rejectionText);
|