@bitkyc08/opencodex 2.92.0 → 2.93.0
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/bin/ocx.mjs +10 -5
- package/gui/dist/assets/{App-sUf_8afJ.js → App-CizjBqyk.js} +18 -18
- package/gui/dist/assets/{Tray-BSsxznDm.js → Tray-DamiMqcX.js} +1 -1
- package/gui/dist/assets/{index-BlFE_VB_.js → index-DQsht3vH.js} +12 -12
- package/gui/dist/assets/index-DRe8Hhfz.css +1 -0
- package/gui/dist/assets/{quota-summary-BRlbXgw0.js → quota-summary-BXu4zE8H.js} +1 -1
- package/gui/dist/index.html +2 -2
- package/package.json +5 -5
- package/src/adapters/anthropic.ts +28 -5
- package/src/adapters/coding-agent/batch-dispatcher.ts +122 -0
- package/src/adapters/coding-agent/profile.ts +54 -16
- package/src/adapters/coding-agent/turn.ts +30 -2
- package/src/adapters/command-code.ts +114 -7
- package/src/adapters/cursor/native-exec-fs.ts +11 -9
- package/src/adapters/devin/live-models.ts +4 -0
- package/src/adapters/google-wire-compiler.ts +1 -2
- package/src/adapters/kiro/reasoning.ts +2 -0
- package/src/adapters/kiro-refusal.ts +6 -1
- package/src/adapters/kiro-wire.ts +1 -1
- package/src/adapters/openai-chat/messages.ts +8 -2
- package/src/adapters/openai-chat/passthrough.ts +35 -14
- package/src/adapters/openai-chat/reasoning-replay.ts +27 -16
- package/src/adapters/openai-chat/reasoning-wire.ts +117 -8
- package/src/adapters/openai-chat/required-tool-result.ts +64 -0
- package/src/adapters/openai-chat.ts +7 -8
- package/src/adapters/openai-responses/passthrough.ts +7 -4
- package/src/adapters/openai-responses/reasoning.ts +13 -0
- package/src/adapters/openai-responses/request-strips.ts +1 -1
- package/src/adapters/qoder/adapter.ts +129 -8
- package/src/adapters/qoder/scaffold-guard.ts +5 -0
- package/src/adapters/reasoning-controls.ts +16 -0
- package/src/adapters/tool-call-id.ts +1 -3
- package/src/bridge/errors.ts +27 -0
- package/src/bridge.ts +1 -1
- package/src/chat/inbound.ts +4 -1
- package/src/chat/outbound.ts +9 -2
- package/src/chat/reasoning-details.ts +28 -5
- package/src/claude/desktop-first-party.ts +54 -4
- package/src/claude/desktop-picker.ts +11 -8
- package/src/claude/first-party-settings.ts +3 -1
- package/src/claude/inbound.ts +2 -1
- package/src/claude/intercept/local-ca.ts +2 -1
- package/src/claude/intercept/picker-ca-cleanup.ts +4 -2
- package/src/claude/intercept/picker-ca-startup.ts +3 -1
- package/src/claude/intercept/picker-models.ts +6 -3
- package/src/claude/intercept/picker-runtime.ts +3 -2
- package/src/claude/intercept/runtime.ts +6 -3
- package/src/claude/model-info.ts +31 -8
- package/src/cli/account-api.ts +11 -0
- package/src/cli/capabilities-agents-routing.ts +2 -2
- package/src/cli/capabilities-base.ts +7 -1
- package/src/cli/capabilities-observe-system.ts +10 -0
- package/src/cli/claude-desktop.ts +9 -8
- package/src/cli/claude.ts +3 -2
- package/src/cli/codex-shim-autorestore.ts +9 -0
- package/src/cli/combo-result.ts +7 -0
- package/src/cli/combo.ts +18 -0
- package/src/cli/cross-home-owner.ts +13 -1
- package/src/cli/dispatch.ts +25 -6
- package/src/cli/ensure-desired-integrations.ts +8 -6
- package/src/cli/export-command.ts +4 -1
- package/src/cli/help.ts +2 -1
- package/src/cli/index.ts +45 -45
- package/src/cli/integration-plan-dto.ts +4 -0
- package/src/cli/opencode.ts +20 -9
- package/src/cli/registry.ts +6 -4
- package/src/cli/root.ts +9 -0
- package/src/cli/status.ts +59 -1
- package/src/cli/stop-restore.ts +113 -0
- package/src/cli/sync-expectation.ts +60 -0
- package/src/cli/uninstall-integrations.ts +41 -7
- package/src/client/connect.ts +40 -3
- package/src/client/link-home.ts +10 -1
- package/src/client/machine-api.ts +3 -1
- package/src/client/sync-expectation.ts +118 -0
- package/src/clients/config-export/agent-clients.ts +96 -0
- package/src/clients/config-export/contracts.ts +25 -7
- package/src/clients/config-export/qoder.ts +38 -23
- package/src/clients/config-export/reasoning-metadata.ts +55 -8
- package/src/clients/config-export.ts +12 -0
- package/src/clients/lazycodex.ts +7 -2
- package/src/clients/reasoning-controls.ts +49 -0
- package/src/codex/auth-api/account-identity.ts +14 -0
- package/src/codex/auth-api/account-list.ts +29 -2
- package/src/codex/auth-api/http.ts +13 -0
- package/src/codex/auth-api/main-account-probe.ts +2 -2
- package/src/codex/auth-api/pool-mode-gate.ts +16 -3
- package/src/codex/auth-api/pool-quota-probe.ts +15 -0
- package/src/codex/auth-context.ts +15 -12
- package/src/codex/catalog/build-entries.ts +22 -0
- package/src/codex/catalog/configured-tiers.ts +70 -0
- package/src/codex/catalog/effort.ts +44 -10
- package/src/codex/catalog/gather-capture.ts +1 -0
- package/src/codex/catalog/heal-observation.ts +155 -13
- package/src/codex/catalog/metadata.ts +6 -0
- package/src/codex/catalog/model-hints.ts +60 -11
- package/src/codex/catalog/model-visibility.ts +3 -2
- package/src/codex/catalog/native-models.ts +18 -3
- package/src/codex/catalog/parsing.ts +10 -8
- package/src/codex/catalog/pinned-models.ts +2 -1
- package/src/codex/catalog/provider-models.ts +4 -5
- package/src/codex/catalog/retained-sync.ts +2 -1
- package/src/codex/catalog/routed-gather.ts +19 -20
- package/src/codex/catalog/write-audit.ts +3 -2
- package/src/codex/catalog-self-heal.ts +43 -23
- package/src/codex/collision-identity.ts +30 -5
- package/src/codex/convergence.ts +4 -3
- package/src/codex/data/roster-pinned-models.json +177 -1
- package/src/codex/desired-state.ts +6 -1
- package/src/codex/desktop-compatibility/installed-build.ts +88 -12
- package/src/codex/desktop-compatibility/runtime.ts +29 -5
- package/src/codex/desktop-compatibility/usage-controller.ts +2 -0
- package/src/codex/desktop-compatibility/windows-certificate-trust.ts +46 -12
- package/src/codex/inject/config-toml.ts +0 -18
- package/src/codex/inject/plan.ts +18 -3
- package/src/codex/inject/remove.ts +6 -2
- package/src/codex/inject.ts +1 -1
- package/src/codex/journal.ts +61 -1
- package/src/codex/model-entitlements.ts +1 -1
- package/src/codex/native-main-owner.ts +27 -1
- package/src/codex/native-profile-store.ts +2 -1
- package/src/codex/pool-credit-policy.ts +35 -1
- package/src/codex/quota-types.ts +3 -0
- package/src/codex/quota.ts +24 -4
- package/src/codex/role-auto-assign.ts +6 -2
- package/src/codex/subagent-defaults.ts +49 -4
- package/src/combos/failover.ts +17 -2
- package/src/combos/jev-decision-contract.ts +22 -1
- package/src/combos/jev-service-exchange.ts +3 -1
- package/src/combos/jev.ts +95 -9
- package/src/combos/resolve.ts +45 -1
- package/src/combos/types.ts +24 -0
- package/src/config/load-degrade.ts +5 -0
- package/src/config/paths.ts +19 -3
- package/src/config/pending-teardown.ts +22 -1
- package/src/config/provider-validation.ts +15 -4
- package/src/config/removed-opencode-free.ts +11 -0
- package/src/config/schema/leaf-validators.ts +5 -0
- package/src/generated/compatibility-version.json +314 -230
- package/src/generated/model-metadata.ts +5 -5
- package/src/images/loop.ts +16 -2
- package/src/integrations/catalog-refresh.ts +1 -1
- package/src/integrations/hermes-profiles.ts +251 -0
- package/src/integrations/merge.ts +8 -0
- package/src/integrations/mutation-plan.ts +19 -4
- package/src/integrations/registry.ts +5 -0
- package/src/integrations/state.ts +36 -1
- package/src/integrations/writer.ts +18 -4
- package/src/lib/bun-path-runtime.mjs +2 -1
- package/src/lib/errors.ts +62 -0
- package/src/lib/eventstream-decoder.ts +81 -37
- package/src/lib/opaque-proxy-tunnel.ts +32 -8
- package/src/lib/pinned-http.ts +35 -2
- package/src/lib/process-control.ts +13 -1
- package/src/lib/socks5-fetch.ts +59 -64
- package/src/lib/socks5-upload-waiter.ts +50 -0
- package/src/lib/sse-decoder.ts +7 -2
- package/src/lib/state-store-sweeper.ts +40 -14
- package/src/lib/windows-native-principal-worker.ts +14 -0
- package/src/lib/windows-native-principal.ts +188 -0
- package/src/lib/windows-secret-acl.ts +39 -3
- package/src/lib/windows-user-principal.ts +62 -18
- package/src/link/ssh-config.ts +35 -3
- package/src/providers/account-quota-disk.ts +12 -4
- package/src/providers/codebuddy-models.ts +6 -0
- package/src/providers/codex-capacity.ts +3 -1
- package/src/providers/derive.ts +28 -0
- package/src/providers/kiro-models.ts +3 -0
- package/src/providers/mimo-thinking.ts +12 -0
- package/src/providers/model-rename-fields.ts +1 -0
- package/src/providers/model-rename-migration.ts +10 -0
- package/src/providers/openai-sidecar-credit.ts +2 -2
- package/src/providers/reasoning-capabilities.ts +76 -0
- package/src/providers/registry/entries-core.ts +14 -12
- package/src/providers/registry/entries-extended.ts +63 -20
- package/src/providers/registry/model-ids.ts +2 -0
- package/src/providers/registry/model-seeds.ts +93 -28
- package/src/providers/registry/types.ts +10 -1
- package/src/providers/resolved-model-policy.ts +26 -6
- package/src/providers/routed-config.ts +9 -1
- package/src/providers/stale-model-roster-migration.ts +44 -7
- package/src/remote-control/workspace-pi-runtime.ts +11 -6
- package/src/responses/compaction-summary.ts +45 -0
- package/src/responses/muse-tool-name-alias.ts +1 -2
- package/src/responses/parser.ts +3 -2
- package/src/responses/schema.ts +1 -0
- package/src/responses/thought-signature-replay.ts +10 -2
- package/src/routing/capability.ts +8 -2
- package/src/routing/history/ingest.ts +28 -3
- package/src/server/auth-cors.ts +3 -2
- package/src/server/chat-completions.ts +7 -0
- package/src/server/chat-native-eligibility.ts +7 -0
- package/src/server/chat-native-reasoning.ts +14 -4
- package/src/server/direct-local-http.ts +5 -2
- package/src/server/effort-policy.ts +5 -1
- package/src/server/index/live-sideband.ts +18 -15
- package/src/server/index/serve-options.ts +5 -4
- package/src/server/management/agent-settings-routes.ts +27 -15
- package/src/server/management/combo-routes.ts +4 -0
- package/src/server/management/config-routes.ts +2 -2
- package/src/server/management/decision-discovery.ts +12 -2
- package/src/server/management/hermes-profile-routes.ts +156 -0
- package/src/server/management/integration-routes.ts +85 -24
- package/src/server/management/model-routes.ts +2 -2
- package/src/server/management/model-row-export-metadata.ts +25 -6
- package/src/server/management/model-rows.ts +15 -20
- package/src/server/management/native-integration-routes.ts +11 -8
- package/src/server/management/route-registry.ts +4 -0
- package/src/server/management-api.ts +5 -0
- package/src/server/models-capabilities.ts +21 -3
- package/src/server/responses/adapter-delivery.ts +11 -1
- package/src/server/responses/adapter-dispatch.ts +2 -2
- package/src/server/responses/codex-ws-exchange.ts +39 -9
- package/src/server/responses/codex-ws-session.ts +38 -4
- package/src/server/responses/codex-ws-wire.ts +6 -1
- package/src/server/responses/combo-required-tool-contract.ts +103 -0
- package/src/server/responses/combo-stream-preflight.ts +8 -1
- package/src/server/responses/compact.ts +4 -3
- package/src/server/responses/context-overflow.ts +8 -1
- package/src/server/responses/core-combo-failure.ts +10 -0
- package/src/server/responses/core-combo.ts +23 -15
- package/src/server/responses/core-lifetime.ts +3 -0
- package/src/server/responses/core-normalize.ts +11 -1
- package/src/server/responses/core-options.ts +2 -0
- package/src/server/responses/main-hard-lock-routing.ts +60 -44
- package/src/server/responses/passthrough-delivery.ts +40 -2
- package/src/server/responses/policy-fallback.ts +6 -1
- package/src/server/responses/request-compression.ts +12 -7
- package/src/server/responses/request-prepare.ts +22 -2
- package/src/server/responses/request-sidecar-auth.ts +2 -0
- package/src/server/responses/response-effects.ts +22 -10
- package/src/server/responses/sidecar-execution.ts +11 -3
- package/src/server/stop-teardown.ts +36 -1
- package/src/server/ws-bridge.ts +1 -1
- package/src/service/desktop-supervision.d.mts +7 -4
- package/src/service/desktop-supervision.mjs +90 -13
- package/src/service/ownership-mutation-lease.mjs +21 -7
- package/src/types/config.ts +8 -2
- package/src/types/provider.ts +20 -6
- package/src/types/request.ts +10 -0
- package/src/types.ts +1 -0
- package/src/update/bind-probe.ts +29 -0
- package/src/update/job.ts +10 -29
- package/src/update/npm-install-job.ps1 +173 -0
- package/src/update/npm-install.mjs +70 -0
- package/src/update/stop-contract.d.mts +1 -0
- package/src/update/stop-contract.mjs +14 -0
- package/src/update/stop-decision.d.mts +1 -1
- package/src/update/stop-decision.mjs +13 -3
- package/src/update/teardown-handover.ts +166 -0
- package/src/update/transactional-install.d.mts +14 -3
- package/src/update/transactional-install.mjs +33 -7
- package/src/usage/expected-prices.ts +64 -31
- package/src/usage/timeline.ts +19 -9
- package/src/vision/eligibility.ts +15 -5
- package/src/vision/plan.ts +2 -2
- package/src/web-search/loop.ts +16 -2
- package/gui/dist/assets/index-DPeB9HpV.css +0 -1
|
@@ -15,6 +15,12 @@ import { buildNonOpenAIToolCatalogNudgeForTools } from "./tool-catalog-nudge";
|
|
|
15
15
|
import { parseDataUrl } from "./image";
|
|
16
16
|
import { createAdapterPhysicalSend } from "./physical-send";
|
|
17
17
|
import { SendBudgetExhaustedError } from "../lib/upstream-retry";
|
|
18
|
+
import {
|
|
19
|
+
isVerifiedModelNotInPlanResponse,
|
|
20
|
+
markVerifiedModelNotInPlanResponse,
|
|
21
|
+
MODEL_NOT_IN_PLAN_CODE,
|
|
22
|
+
MODEL_NOT_IN_PLAN_REFUSAL_MARKER,
|
|
23
|
+
} from "../lib/errors";
|
|
18
24
|
import { CommandCodeToolTextFilter, type CommandCodeDeclaredTools } from "./command-code-tool-text";
|
|
19
25
|
import { EMPTY_COMMAND_CODE_PROJECT_CONTEXT, loadCommandCodeProjectContext } from "./command-code-project-context";
|
|
20
26
|
|
|
@@ -493,6 +499,35 @@ function isReasoningEffortRejection(status: number, payload: string): boolean {
|
|
|
493
499
|
return (status === 400 || status === 422) && /reasoning[_ -]?effort|unsupported effort|invalid effort/i.test(payload);
|
|
494
500
|
}
|
|
495
501
|
|
|
502
|
+
/** Command Code reports exhausted credits as BAD_REQUEST; normalize only that refusal
|
|
503
|
+
* so every caller can reuse the existing OAuth quota rotation and send budget. Key and
|
|
504
|
+
* forward rows keep the 400: a canonical key row has a same-key 429 retry ladder
|
|
505
|
+
* (`rateLimitRetryPolicyFor`) that would replay a credential whose credits are gone. */
|
|
506
|
+
async function normalizeCommandCodeCreditRefusal(
|
|
507
|
+
response: Response, oauth: boolean, signal?: AbortSignal,
|
|
508
|
+
): Promise<Response> {
|
|
509
|
+
if (!oauth || response.status !== 400) return response;
|
|
510
|
+
try {
|
|
511
|
+
const observed = await readBoundedResponseBody(response.clone(), {
|
|
512
|
+
signal,
|
|
513
|
+
maxBytes: 8 * 1024,
|
|
514
|
+
fatalUtf8: true,
|
|
515
|
+
});
|
|
516
|
+
if (!observed.displaySafe) return response;
|
|
517
|
+
const payload = JSON.parse(observed.text);
|
|
518
|
+
if (payload?.success !== false || payload.error?.code !== "BAD_REQUEST"
|
|
519
|
+
|| typeof payload.error?.message !== "string"
|
|
520
|
+
|| !payload.error.message.startsWith("You have insufficient credits to make this request.")) return response;
|
|
521
|
+
const headers = new Headers(response.headers);
|
|
522
|
+
headers.set("x-opencodex-upstream-status", "400");
|
|
523
|
+
headers.set("x-opencodex-refusal", "insufficient-credits");
|
|
524
|
+
return new Response(response.body, { status: 429, statusText: "Too Many Requests", headers });
|
|
525
|
+
} catch (error) {
|
|
526
|
+
if (signal?.aborted && error === signal.reason) throw error;
|
|
527
|
+
return response;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
|
|
496
531
|
function requestWithoutReasoningEffort(request: AdapterRequest): AdapterRequest | undefined {
|
|
497
532
|
try {
|
|
498
533
|
const body = JSON.parse(request.body) as { params?: Record<string, unknown> };
|
|
@@ -504,6 +539,75 @@ function requestWithoutReasoningEffort(request: AdapterRequest): AdapterRequest
|
|
|
504
539
|
}
|
|
505
540
|
}
|
|
506
541
|
|
|
542
|
+
/** The upstream's plan refusal prefix; `MODEL_NOT_IN_PLAN_OTHER` and later mentions do not count. */
|
|
543
|
+
const COMMAND_CODE_PLAN_REFUSAL = /^MODEL_NOT_IN_PLAN(?::|$)/;
|
|
544
|
+
/** A model id the message may quote; anything else is described without repeating it. */
|
|
545
|
+
const DISPLAYABLE_MODEL_ID = /^[A-Za-z0-9][A-Za-z0-9._:/-]{0,127}$/;
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* Fixed client copy for a plan refusal. The upstream detail is never quoted: it is free text this
|
|
549
|
+
* proxy does not control, and quota or reasoning-effort words in it would steer the downstream
|
|
550
|
+
* classifiers (quota recording, effort repair) on a refusal that no resend can change.
|
|
551
|
+
*/
|
|
552
|
+
function commandCodePlanRefusalMessage(modelId: string | undefined): string {
|
|
553
|
+
const model = modelId && DISPLAYABLE_MODEL_ID.test(modelId) ? `the model "${modelId}"` : "the requested model";
|
|
554
|
+
return `Command Code refused ${model}: this account's plan does not include it (MODEL_NOT_IN_PLAN). `
|
|
555
|
+
+ "Choose a model the plan includes or change the Command Code plan; retrying this request will not succeed.";
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
/**
|
|
559
|
+
* Command Code refuses a model the account's plan excludes with HTTP 403 and
|
|
560
|
+
* `MODEL_NOT_IN_PLAN: ...` (#7684). Codex reconnects on every 403 through its whole retry budget,
|
|
561
|
+
* and a combo reads a 403 as a provider-wide credential verdict. The refusal names one model on one
|
|
562
|
+
* account, so it becomes a 400 `invalid_request_error` carrying `model_not_in_plan`, which Codex
|
|
563
|
+
* reports without retrying and combo or policy fallback treat as target-local. Every auth mode
|
|
564
|
+
* gets it: no account, key or provider cooldown is involved. Any other 403 stays untouched.
|
|
565
|
+
*/
|
|
566
|
+
async function normalizeCommandCodePlanRefusal(
|
|
567
|
+
response: Response, modelId: string | undefined, signal?: AbortSignal,
|
|
568
|
+
): Promise<Response> {
|
|
569
|
+
if (response.status !== 403) return response;
|
|
570
|
+
try {
|
|
571
|
+
const observed = await readBoundedResponseBody(response.clone(), {
|
|
572
|
+
signal,
|
|
573
|
+
maxBytes: 8 * 1024,
|
|
574
|
+
fatalUtf8: true,
|
|
575
|
+
});
|
|
576
|
+
if (!observed.displaySafe || observed.truncated) return response;
|
|
577
|
+
const payload = JSON.parse(observed.text);
|
|
578
|
+
if (payload?.success !== false || payload.error?.code !== "FORBIDDEN"
|
|
579
|
+
|| typeof payload.error?.message !== "string"
|
|
580
|
+
|| !COMMAND_CODE_PLAN_REFUSAL.test(payload.error.message)) return response;
|
|
581
|
+
try { void response.body?.cancel().catch(() => {}); } catch { /* already closed */ }
|
|
582
|
+
const headers = new Headers({ "Content-Type": "application/json" });
|
|
583
|
+
headers.set("x-opencodex-upstream-status", "403");
|
|
584
|
+
headers.set("x-opencodex-refusal", MODEL_NOT_IN_PLAN_REFUSAL_MARKER);
|
|
585
|
+
const refusal = new Response(JSON.stringify({ error: {
|
|
586
|
+
type: "invalid_request_error", code: MODEL_NOT_IN_PLAN_CODE, message: commandCodePlanRefusalMessage(modelId),
|
|
587
|
+
} }), { status: 400, statusText: "Bad Request", headers });
|
|
588
|
+
// Identity is the provenance dispatch, combo and policy fallback check; the header is diagnostic.
|
|
589
|
+
markVerifiedModelNotInPlanResponse(refusal);
|
|
590
|
+
return refusal;
|
|
591
|
+
} catch (error) {
|
|
592
|
+
if (signal?.aborted && error === signal.reason) throw error;
|
|
593
|
+
return response;
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
/** Both Command Code refusal rewrites, in the order every send applies them. */
|
|
598
|
+
async function normalizeCommandCodeRefusal(
|
|
599
|
+
response: Response, oauth: boolean, modelId: string | undefined, signal?: AbortSignal,
|
|
600
|
+
): Promise<Response> {
|
|
601
|
+
return normalizeCommandCodePlanRefusal(await normalizeCommandCodeCreditRefusal(response, oauth, signal), modelId, signal);
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
function requestModelId(request: AdapterRequest): string | undefined {
|
|
605
|
+
try {
|
|
606
|
+
const model = (JSON.parse(request.body) as { params?: { model?: unknown } }).params?.model;
|
|
607
|
+
return typeof model === "string" ? model : undefined;
|
|
608
|
+
} catch { return undefined; }
|
|
609
|
+
}
|
|
610
|
+
|
|
507
611
|
async function fetchCommandCode(request: AdapterRequest, ctx: AdapterFetchContext | undefined, executor: typeof globalThis.fetch): Promise<Response> {
|
|
508
612
|
const timeout = new AbortController();
|
|
509
613
|
const timer = setTimeout(() => timeout.abort(new DOMException("Timeout elapsed", "TimeoutError")), ctx?.timeoutMs ?? 200_000);
|
|
@@ -589,6 +693,8 @@ function supportedCommandCodeEffort(provider: OcxProviderConfig, modelId: string
|
|
|
589
693
|
|
|
590
694
|
export function createCommandCodeAdapter(provider: OcxProviderConfig): ProviderAdapter {
|
|
591
695
|
const executor = (provider as OcxProviderConfig & { fetch?: typeof globalThis.fetch }).fetch ?? globalThis.fetch;
|
|
696
|
+
// Only an OAuth row has sibling accounts for the rewritten 429 to rotate to.
|
|
697
|
+
const creditRefusalRotates = provider.authMode === "oauth";
|
|
592
698
|
// The server builds one adapter per routed request and hands parseStream a guarded wrapper
|
|
593
699
|
// rather than the Response fetchResponse returned, so the stream reads the declared catalog of
|
|
594
700
|
// the request this instance last built. A parser with no built request restores nothing.
|
|
@@ -651,8 +757,12 @@ export function createCommandCodeAdapter(provider: OcxProviderConfig): ProviderA
|
|
|
651
757
|
},
|
|
652
758
|
async fetchResponse(request: AdapterRequest, ctx?: AdapterFetchContext): Promise<Response> {
|
|
653
759
|
const send = createAdapterPhysicalSend(ctx, executor);
|
|
654
|
-
const
|
|
655
|
-
|
|
760
|
+
const modelId = requestModelId(request);
|
|
761
|
+
const response = await normalizeCommandCodeRefusal(
|
|
762
|
+
await send({ url: request.url, dispatch: physical => fetchCommandCode(request, ctx, physical) }), creditRefusalRotates, modelId, ctx?.abortSignal,
|
|
763
|
+
);
|
|
764
|
+
// A plan refusal is final for this model: no effort downgrade can change the plan.
|
|
765
|
+
if (response.ok || isVerifiedModelNotInPlanResponse(response)) return response;
|
|
656
766
|
const currentEffort = (() => {
|
|
657
767
|
try { return (JSON.parse(request.body) as { params?: { reasoning_effort?: unknown } }).params?.reasoning_effort; } catch { return undefined; }
|
|
658
768
|
})();
|
|
@@ -664,9 +774,6 @@ export function createCommandCodeAdapter(provider: OcxProviderConfig): ProviderA
|
|
|
664
774
|
body = observed.text;
|
|
665
775
|
} catch { return response; }
|
|
666
776
|
if (!isReasoningEffortRejection(response.status, body)) return response;
|
|
667
|
-
const modelId = (() => {
|
|
668
|
-
try { return (JSON.parse(request.body) as { params?: { model?: unknown } }).params?.model; } catch { return undefined; }
|
|
669
|
-
})();
|
|
670
777
|
if (typeof modelId !== "string") return response;
|
|
671
778
|
// An operator who wrote this ladder authorized the rung deliberately. Replaying the turn
|
|
672
779
|
// without it would answer at the provider default and hide a wrong configuration behind a
|
|
@@ -678,9 +785,9 @@ export function createCommandCodeAdapter(provider: OcxProviderConfig): ProviderA
|
|
|
678
785
|
const retry = requestWithoutReasoningEffort(request);
|
|
679
786
|
if (!retry) return response;
|
|
680
787
|
try {
|
|
681
|
-
return await send({ url: retry.url, sendClass: "repair", recovery: "reasoning-effort-downgrade",
|
|
788
|
+
return await normalizeCommandCodeRefusal(await send({ url: retry.url, sendClass: "repair", recovery: "reasoning-effort-downgrade",
|
|
682
789
|
beforeDispatch: () => { try { void response.body?.cancel().catch(() => {}); } catch { /* already closed */ } },
|
|
683
|
-
dispatch: physical => fetchCommandCode(retry, ctx, physical) });
|
|
790
|
+
dispatch: physical => fetchCommandCode(retry, ctx, physical) }), creditRefusalRotates, modelId, ctx?.abortSignal);
|
|
684
791
|
} catch (error) {
|
|
685
792
|
if (error instanceof SendBudgetExhaustedError) return response;
|
|
686
793
|
throw error;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
2
|
-
import { basename, dirname, extname, join, relative, resolve } from "node:path";
|
|
2
|
+
import { basename, dirname, extname, join, relative, resolve, sep } from "node:path";
|
|
3
3
|
import { create } from "@bufbuild/protobuf";
|
|
4
4
|
import {
|
|
5
5
|
DeleteErrorSchema,
|
|
@@ -235,19 +235,21 @@ export function lsExec(execMsg: ExecServerMessage): Uint8Array {
|
|
|
235
235
|
}
|
|
236
236
|
}
|
|
237
237
|
|
|
238
|
-
function
|
|
239
|
-
if (!glob) return true;
|
|
240
|
-
|
|
241
|
-
|
|
238
|
+
function grepFileMatcher(root: string, glob?: string): (file: string) => boolean {
|
|
239
|
+
if (!glob) return () => true;
|
|
240
|
+
const matcher = new Bun.Glob(glob.replace(/^(?:\.\/)+/, ""));
|
|
241
|
+
// Bare patterns apply to each basename; slash patterns are relative to the selected root.
|
|
242
|
+
const pathPattern = glob.includes("/");
|
|
243
|
+
return file => matcher.match(pathPattern ? relative(root, file).split(sep).join("/") : basename(file));
|
|
242
244
|
}
|
|
243
245
|
|
|
244
|
-
function collectFiles(root: string,
|
|
246
|
+
function collectFiles(root: string, matchesFile: (file: string) => boolean, out: string[] = []): string[] {
|
|
245
247
|
if (out.length >= MAX_GREP_FILES) return out;
|
|
246
248
|
for (const entry of readdirSync(root, { withFileTypes: true })) {
|
|
247
249
|
if (entry.name === "node_modules" || entry.name === ".git") continue;
|
|
248
250
|
const path = join(root, entry.name);
|
|
249
|
-
if (entry.isDirectory()) collectFiles(path,
|
|
250
|
-
if (entry.isFile() &&
|
|
251
|
+
if (entry.isDirectory()) collectFiles(path, matchesFile, out);
|
|
252
|
+
if (entry.isFile() && matchesFile(path)) out.push(path);
|
|
251
253
|
if (out.length >= MAX_GREP_FILES) break;
|
|
252
254
|
}
|
|
253
255
|
return out;
|
|
@@ -269,7 +271,7 @@ export function grepExec(execMsg: ExecServerMessage): Uint8Array {
|
|
|
269
271
|
const root = resolve(args.path || process.cwd());
|
|
270
272
|
try {
|
|
271
273
|
const pattern = new RegExp(args.pattern, args.caseInsensitive ? "i" : "");
|
|
272
|
-
const files = existsSync(root) && statSync(root).isDirectory() ? collectFiles(root, args.glob) : [root];
|
|
274
|
+
const files = existsSync(root) && statSync(root).isDirectory() ? collectFiles(root, grepFileMatcher(root, args.glob)) : [root];
|
|
273
275
|
const matches = [];
|
|
274
276
|
for (const file of files) {
|
|
275
277
|
if (matches.length >= MAX_GREP_RESULTS) break;
|
|
@@ -27,6 +27,8 @@ export const DEVIN_STATIC_MODELS = [
|
|
|
27
27
|
// 260930 preemptive: GPT-6.1 Sol (devin.ai/blog/gpt-6-1-sol says it is live; the uid is not published).
|
|
28
28
|
// Spelled the way Devin spells gpt-5.6-sol; live discovery replaces this seed once a credential is present.
|
|
29
29
|
"gpt-6-1-sol",
|
|
30
|
+
// 261027 preemptive: GPT-6.1 Terra (mirrors Devin's GPT-6.1 Sol seed; uid unverified).
|
|
31
|
+
"gpt-6-1-terra",
|
|
30
32
|
"claude-opus-4-8",
|
|
31
33
|
"claude-fable-5-1",
|
|
32
34
|
"claude-sonnet-5",
|
|
@@ -66,6 +68,8 @@ export const DEVIN_MODEL_CONTEXT_WINDOWS: Record<string, number> = {
|
|
|
66
68
|
"gpt-6-luna": 1_000_000,
|
|
67
69
|
// 260930 preemptive: unmeasured; mirrors the GPT-6 Sol row Cognition serves.
|
|
68
70
|
"gpt-6-1-sol": 1_000_000,
|
|
71
|
+
// 261027 preemptive: GPT-6.1 Terra (unmeasured; mirrors Devin's GPT-6.1 Sol window).
|
|
72
|
+
"gpt-6-1-terra": 1_000_000,
|
|
69
73
|
"claude-opus-4-8": 1_000_000,
|
|
70
74
|
// 260923: read from the live catalog (devin/claude-opus-5-5 context_length 1_000_000).
|
|
71
75
|
"claude-opus-5-5": 1_000_000,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
1
|
import {
|
|
3
2
|
addGoogleToolSchemaLoss,
|
|
4
3
|
createGoogleToolSchemaLossReport,
|
|
@@ -59,7 +58,7 @@ function toolNameCodec(names: readonly string[]): {
|
|
|
59
58
|
const prefix = (cleaned || "tool").slice(0, 55);
|
|
60
59
|
for (let salt = 0; ; salt++) {
|
|
61
60
|
const hashInput = salt === 0 ? name : `${name}#${salt}`;
|
|
62
|
-
const suffix =
|
|
61
|
+
const suffix = Bun.SHA256.hash(hashInput, "hex").slice(0, 8);
|
|
63
62
|
const candidate = `${prefix}_${suffix}`;
|
|
64
63
|
if (used.has(candidate)) continue;
|
|
65
64
|
toWire.set(name, candidate);
|
|
@@ -28,6 +28,8 @@ export const KIRO_NATIVE_EFFORT_FIELDS: Record<string, "reasoning" | "output_con
|
|
|
28
28
|
"gpt-6-luna": "reasoning",
|
|
29
29
|
// 260930 preemptive (see kiro-models.ts): same native field as GPT-6 Sol.
|
|
30
30
|
"gpt-6.1-sol": "reasoning",
|
|
31
|
+
// 261027 preemptive: GPT-6.1 Terra (mirrors GPT-6.1 Sol; see kiro-models.ts).
|
|
32
|
+
"gpt-6.1-terra": "reasoning",
|
|
31
33
|
"claude-opus-5": "output_config",
|
|
32
34
|
// 260923 preemptive (see kiro-models.ts): same Claude-specific field as Opus 5.
|
|
33
35
|
"claude-opus-5.5": "output_config",
|
|
@@ -13,6 +13,10 @@ const SUSPENSION_WORDS = [
|
|
|
13
13
|
"locked your account", "locked it as a",
|
|
14
14
|
] as const;
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Classify a Kiro HTTP error for account rotation and quota or suspension evidence.
|
|
18
|
+
* Reads bounded, top-level JSON fields; unrecognized 429 bodies retain rate recovery.
|
|
19
|
+
*/
|
|
16
20
|
export function classifyKiroRefusal(status: number, bodyText: string): KiroRefusal {
|
|
17
21
|
if (Buffer.byteLength(bodyText, "utf8") > BOUNDED_BODY_MAX_BYTES)
|
|
18
22
|
return { kind: status === 429 ? "rate" : "other" };
|
|
@@ -25,7 +29,8 @@ export function classifyKiroRefusal(status: number, bodyText: string): KiroRefus
|
|
|
25
29
|
message = (row as Record<string, unknown>).message;
|
|
26
30
|
}
|
|
27
31
|
} catch { /* Unrecognised bodies cannot establish an account verdict. */ }
|
|
28
|
-
if ((status === 400 || status === 429)
|
|
32
|
+
if ((status === 400 || status === 429)
|
|
33
|
+
&& (reason === "MONTHLY_REQUEST_COUNT" || reason === "OVERAGE_REQUEST_LIMIT_EXCEEDED"))
|
|
29
34
|
return { kind: "monthly_quota" };
|
|
30
35
|
// A 400 whose own validator calls the body improperly formed is not proof that the request is
|
|
31
36
|
// impossible: Kiro answers this shape when the identity a request was routed under cannot serve
|
|
@@ -62,7 +62,7 @@ export function kiroToolName(wireName: string, used?: Set<string>): string {
|
|
|
62
62
|
const base = cleaned.slice(0, 55) || "tool";
|
|
63
63
|
for (let salt = 0; ; salt++) {
|
|
64
64
|
const hashInput = salt === 0 ? wireName : `${wireName}#${salt}`;
|
|
65
|
-
const suffix =
|
|
65
|
+
const suffix = Bun.SHA256.hash(hashInput, "hex").slice(0, 8);
|
|
66
66
|
const candidate = `${base}_${suffix}`;
|
|
67
67
|
if (!(used?.has(candidate))) {
|
|
68
68
|
used?.add(candidate);
|
|
@@ -7,7 +7,7 @@ import { EMPTY_TOOL_OUTPUT_ANNOTATION, isWhitespaceOnlyTextPartArray } from "../
|
|
|
7
7
|
import { identifyRoutedModel } from "../identity";
|
|
8
8
|
import { buildNonOpenAIToolCatalogNudgeForTools, shouldInjectNonOpenAIToolCatalogNudge } from "../tool-catalog-nudge";
|
|
9
9
|
import { peekReasoningForCall } from "../../responses/reasoning-replay-cache";
|
|
10
|
-
import { chatReasoningReplayPolicy } from "./reasoning-replay";
|
|
10
|
+
import { chatReasoningReplayPolicy, isReflectionThinkingModel } from "./reasoning-replay";
|
|
11
11
|
import type { ClaudeThinkingProjection } from "../../lib/claude-request-projection";
|
|
12
12
|
import { inlineDocumentDataUrl } from "../../responses/inline-document";
|
|
13
13
|
import type { OcxAssistantMessage, OcxContentPart, OcxParsedRequest, OcxProviderConfig, OcxTextContent, OcxThinkingContent, OcxToolCall } from "../../types";
|
|
@@ -282,9 +282,15 @@ export function messagesToChatFormat(parsed: OcxParsedRequest, provider: OcxProv
|
|
|
282
282
|
const chatMsg: Record<string, unknown> = { role: "assistant" };
|
|
283
283
|
if (textParts.length > 0) chatMsg.content = textParts.map(p => p.text).join("");
|
|
284
284
|
let reasoningContent = thinkingParts.map(p => p.thinking).join("");
|
|
285
|
+
// Reflection/Stealth replay a placeholder even on a tool-less turn, but never on an
|
|
286
|
+
// empty turn inside an unfinished tool batch: that turn is dropped below, and a
|
|
287
|
+
// fabricated reasoning block there would split the call from its real result.
|
|
288
|
+
const reflectionPlaceholder = isReflectionThinkingModel(parsed.modelId)
|
|
289
|
+
&& chatReasoningReplayPolicy(provider, parsed.modelId).placeholder
|
|
290
|
+
&& !(pendingToolCalls.length > 0 && !chatMsg.content && toolCalls.length === 0 && thinkingParts.length === 0);
|
|
285
291
|
if (
|
|
286
292
|
reasoningContent.length === 0
|
|
287
|
-
&& (toolCalls.length > 0 || thinkingParts.length > 0)
|
|
293
|
+
&& (toolCalls.length > 0 || thinkingParts.length > 0 || reflectionPlaceholder)
|
|
288
294
|
&& wireSerializesThinking
|
|
289
295
|
) {
|
|
290
296
|
const cached = toolCalls
|
|
@@ -10,10 +10,12 @@ import { applyGithubCopilotContextTier } from "../../providers/github-copilot-co
|
|
|
10
10
|
import { canonicalFastTierMarker, decideTier, type ResolvedFastPolicy } from "../../providers/fastwire";
|
|
11
11
|
import { debugProviderDiagnostic } from "../../lib/debug";
|
|
12
12
|
import { isDebugEnabled } from "../../lib/debug-settings";
|
|
13
|
-
import { modelRecordValue } from "../../reasoning-effort";
|
|
14
13
|
import { modelInList, type OcxProviderConfig } from "../../types";
|
|
14
|
+
import { mapReasoningEffort, modelRecordValue } from "../../reasoning-effort";
|
|
15
|
+
import { resolveReasoningCapabilities } from "../../providers/reasoning-capabilities";
|
|
15
16
|
import { chatParallelToolCallsWireValue } from "./parallel-tool-calls";
|
|
16
|
-
import { applyExplicitChatReasoningWirePolicy } from "./reasoning-wire";
|
|
17
|
+
import { applyExplicitChatReasoningWirePolicy, declaresIndependentChatReasoningControls } from "./reasoning-wire";
|
|
18
|
+
import { declaresThinkingToggleWire, reasoningControlsAreUnsupported } from "../reasoning-controls";
|
|
17
19
|
import { planNativeChatReasoningReplay } from "./reasoning-replay";
|
|
18
20
|
import type { OcxReasoningReplayScopeRef } from "../../types";
|
|
19
21
|
import { jsonUtf8Bytes } from "../../lib/json-byte-size";
|
|
@@ -87,22 +89,40 @@ export function buildOpenAIChatPassthroughRequest(
|
|
|
87
89
|
const replayPlan = planNativeChatReasoningReplay(body.messages, provider, modelId, replayScope,
|
|
88
90
|
Array.isArray(rawBody.tools) && rawBody.tools.length > 0, maxSerializedBytes);
|
|
89
91
|
if (protectGlmSummaryBudget(body, provider.baseUrl, body.reasoning_effort)) body.reasoning_effort = "low";
|
|
92
|
+
const toggleWire = declaresThinkingToggleWire(provider, modelId);
|
|
93
|
+
const independentControls = declaresIndependentChatReasoningControls(provider, modelId);
|
|
90
94
|
const rawEfforts = modelRecordValue(provider.modelReasoningEfforts, modelId) ?? provider.reasoningEfforts;
|
|
91
|
-
const reasoningDisabled = modelInList(provider.noReasoningModels, modelId)
|
|
95
|
+
const reasoningDisabled = modelInList(provider.noReasoningModels, modelId)
|
|
96
|
+
|| (!toggleWire && rawEfforts?.length === 0) || reasoningControlsAreUnsupported(provider, modelId);
|
|
92
97
|
if (reasoningDisabled) {
|
|
93
98
|
delete body.reasoning_effort;
|
|
94
99
|
}
|
|
95
100
|
const hasTools = Array.isArray(rawBody.tools) && rawBody.tools.length > 0;
|
|
96
101
|
const requestedEffort = typeof body.reasoning_effort === "string" ? body.reasoning_effort : undefined;
|
|
97
|
-
|
|
102
|
+
const explicitThinkingEnabled = rawBody.reasoning !== null && typeof rawBody.reasoning === "object"
|
|
103
|
+
&& typeof (rawBody.reasoning as { enabled?: unknown }).enabled === "boolean"
|
|
104
|
+
? (rawBody.reasoning as { enabled: boolean }).enabled
|
|
105
|
+
: undefined;
|
|
106
|
+
const explicitReasoning = applyExplicitChatReasoningWirePolicy({
|
|
98
107
|
provider,
|
|
99
108
|
modelId,
|
|
100
109
|
hasTools,
|
|
110
|
+
thinkingEnabled: explicitThinkingEnabled,
|
|
101
111
|
requestedEffort,
|
|
102
|
-
wireEffort: requestedEffort,
|
|
112
|
+
wireEffort: toggleWire && independentControls ? mapReasoningEffort(provider, modelId, requestedEffort) : requestedEffort,
|
|
103
113
|
reasoningDisabled,
|
|
104
114
|
body,
|
|
105
115
|
});
|
|
116
|
+
let reasoningLog = explicitReasoning.handled ? explicitReasoning.reasoningLog : undefined;
|
|
117
|
+
// A native caller's own thinking object is already in the upstream wire shape. Forward it only
|
|
118
|
+
// on a provider-declared toggle wire, below an explicit reasoning.enabled but above a default.
|
|
119
|
+
if (!reasoningDisabled && toggleWire && independentControls
|
|
120
|
+
&& resolveReasoningCapabilities(provider, modelId).supportsThinkingToggle !== false
|
|
121
|
+
&& explicitThinkingEnabled === undefined
|
|
122
|
+
&& rawBody.thinking !== undefined) {
|
|
123
|
+
body.thinking = rawBody.thinking;
|
|
124
|
+
reasoningLog = undefined;
|
|
125
|
+
}
|
|
106
126
|
|
|
107
127
|
const openRouterRouting = resolveOpenRouterRouting(provider, modelId);
|
|
108
128
|
if (openRouterRouting) body.provider = openRouterProviderPayload(openRouterRouting);
|
|
@@ -170,15 +190,13 @@ export function buildOpenAIChatPassthroughRequest(
|
|
|
170
190
|
// The binding constraint is the final size base + net, so a shrinking replay may legitimately
|
|
171
191
|
// measure a base above the cap; only a base above max - net makes the result unserializable.
|
|
172
192
|
let baseBytes = 0;
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
throw new TranslatorBudgetExceededError("request_copies", maxSerializedBytes);
|
|
179
|
-
}
|
|
180
|
-
throw error;
|
|
193
|
+
try {
|
|
194
|
+
baseBytes = jsonUtf8Bytes(transformedBody(), maxSerializedBytes - replayPlan.serializedBytes);
|
|
195
|
+
} catch (error) {
|
|
196
|
+
if (isTranslatorBudgetExceededError(error)) {
|
|
197
|
+
throw new TranslatorBudgetExceededError("request_copies", maxSerializedBytes);
|
|
181
198
|
}
|
|
199
|
+
throw error;
|
|
182
200
|
}
|
|
183
201
|
if (replayPlan.serializedBytes > maxSerializedBytes - baseBytes) {
|
|
184
202
|
throw new TranslatorBudgetExceededError("request_copies", maxSerializedBytes);
|
|
@@ -210,5 +228,8 @@ export function buildOpenAIChatPassthroughRequest(
|
|
|
210
228
|
});
|
|
211
229
|
}
|
|
212
230
|
|
|
213
|
-
return {
|
|
231
|
+
return {
|
|
232
|
+
url, method: "POST", headers, body: bodyJson,
|
|
233
|
+
...(reasoningLog ? { reasoningLog } : {}),
|
|
234
|
+
};
|
|
214
235
|
}
|
|
@@ -9,9 +9,15 @@ export const isChatRecord = (value: unknown): value is Rec =>
|
|
|
9
9
|
|
|
10
10
|
const REASONING_CONTENT_FIELD_BYTES = Buffer.byteLength('"reasoning_content":', "utf8");
|
|
11
11
|
|
|
12
|
-
const isDeepSeekThinkingModel = (modelId: string): boolean =>
|
|
12
|
+
export const isDeepSeekThinkingModel = (modelId: string): boolean =>
|
|
13
13
|
/(?:^|\/)deepseek-(?:v\d+(?:\.\d+)*-(?:flash|pro)|flash|pro)(?:$|[-_:])/i.test(modelId);
|
|
14
14
|
|
|
15
|
+
export const isReflectionThinkingModel = (modelId: string): boolean =>
|
|
16
|
+
/(?:^|\/)(?:reflection|stealth)(?:$|[-_:/.])/i.test(modelId);
|
|
17
|
+
|
|
18
|
+
export const isThinkingModelFamily = (modelId: string): boolean =>
|
|
19
|
+
isDeepSeekThinkingModel(modelId) || isReflectionThinkingModel(modelId);
|
|
20
|
+
|
|
15
21
|
/** DeepSeek thinking tool replay is a model contract, independent of the gateway's name. */
|
|
16
22
|
export function chatReasoningReplayPolicy(provider: OcxProviderConfig, modelId: string): {
|
|
17
23
|
preserve: boolean; placeholder: boolean;
|
|
@@ -19,7 +25,7 @@ export function chatReasoningReplayPolicy(provider: OcxProviderConfig, modelId:
|
|
|
19
25
|
// Match whole model-family tokens, including dotted versions, namespace and deployment suffixes.
|
|
20
26
|
// Legacy chat/reasoner and distilled R1 models do not share the thinking tool-call contract.
|
|
21
27
|
const preserve = provider.preserveReasoningContentModels === undefined
|
|
22
|
-
?
|
|
28
|
+
? isThinkingModelFamily(modelId)
|
|
23
29
|
: modelInList(provider.preserveReasoningContentModels, modelId);
|
|
24
30
|
return {
|
|
25
31
|
preserve,
|
|
@@ -59,21 +65,26 @@ export function planNativeChatReasoningReplay(
|
|
|
59
65
|
const plans: ReplayMessagePlan[] = [];
|
|
60
66
|
let serializedBytes = 0;
|
|
61
67
|
for (const message of messages) {
|
|
62
|
-
if (!isChatRecord(message) || message.role !== "assistant"
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
68
|
+
if (!isChatRecord(message) || message.role !== "assistant") continue;
|
|
69
|
+
if (typeof message.reasoning_content === "string" && message.reasoning_content.length > 0) continue;
|
|
70
|
+
let parts: string[];
|
|
71
|
+
if (typeof message.reasoning === "string" && message.reasoning.length > 0) {
|
|
72
|
+
parts = [message.reasoning];
|
|
73
|
+
} else {
|
|
74
|
+
const calls = Array.isArray(message.tool_calls) ? message.tool_calls : [];
|
|
75
|
+
// DeepSeek tools contract covers prior assistant turns when tools are present.
|
|
76
|
+
// Thinking models like reflection/beam require reasoning replay even without tools.
|
|
77
|
+
if (calls.length === 0 && !(hasTools && isDeepSeekThinkingModel(modelId)) && !isReflectionThinkingModel(modelId)) continue;
|
|
78
|
+
const cached = new Set<string>();
|
|
79
|
+
for (const tool of calls) {
|
|
80
|
+
if (!isChatRecord(tool) || typeof tool.id !== "string") continue;
|
|
81
|
+
const text = peekReasoningForCall(tool.id, scope);
|
|
82
|
+
if (text) cached.add(text);
|
|
83
|
+
}
|
|
84
|
+
parts = cached.size > 0
|
|
85
|
+
? [...cached]
|
|
86
|
+
: policy.placeholder ? [" "] : [];
|
|
73
87
|
}
|
|
74
|
-
const parts = cached.size > 0
|
|
75
|
-
? [...cached]
|
|
76
|
-
: policy.placeholder ? [" "] : [];
|
|
77
88
|
if (parts.length === 0) continue;
|
|
78
89
|
|
|
79
90
|
// The envelope delta around the joined value is exact for the plain JSON the Chat
|