@bitkyc08/opencodex 2.96.0 → 2.98.0-preview.20261107
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 +215 -20
- package/gui/dist/assets/App-6TFtZsUF.css +1 -0
- package/gui/dist/assets/App-B8_sOxoz.js +59 -0
- package/gui/dist/assets/Tray-DpWEp6ee.js +1 -0
- package/gui/dist/assets/WantedSansVariable.split.0-Dwvb1WRx.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.1-1wKD2RxI.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.10-CAKA6LIP.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.11-k5H85R4b.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.12-BHboLsUv.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.13-9GV377ix.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.14-DovDXnrj.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.15-DTdykCig.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.16-CKz2ccgK.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.17-Z2RD_KRZ.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.18-BcKtfonJ.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.19-DEQPOSZn.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.2-DryboyuA.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.20-Bia5JMls.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.21-Cr4jFw-E.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.22-DjjB69TZ.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.23-CvUzJskt.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.24-i_eMg5ox.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.25-2aKHwPX-.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.26-B6wXoCEL.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.27-D4h1WfGM.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.28-kvRPCStd.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.29-DHAiwleD.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.3-7H--eyZi.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.30-C66cfAY2.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.31-FDmtiNim.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.32-DouHt2Dd.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.33-B8HVvkJX.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.34-BtkRu1FN.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.35-DBylQbtk.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.36-Sg089Kgh.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.37-CYtvbriS.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.38-DKkSLf8Z.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.39-CecotKZD.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.4-Bv8O3ZMb.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.40-DdCvkmOU.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.41-ESn674Hc.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.42-DL9V7NNV.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.43-yipO0cyk.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.44-6rTmLZhm.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.45-BJAj8lrm.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.46-BDTzMn2c.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.47-Bxd4wGgi.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.48-DxnFBLnH.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.49-DnVD0aOD.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.5-B1wI2pp5.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.50-D9JlkZd6.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.51-D9Vw6Bu3.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.52-ClEJk4kn.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.53-BSXU0vh-.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.54-EcuxkR9v.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.55-CYiFhQX8.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.56--Gk9g8BK.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.57-DnkOPZcy.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.58-9MB8504z.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.59-ByxIsN72.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.6-Bmk0dRVw.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.60-Bxwx_aWQ.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.61-DA2z5sm7.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.62-C5iJPJZn.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.63-DAqrmaEc.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.64-BgXFsljb.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.65-DKiWujvu.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.66-8po4vUZ4.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.67-Cy5qyI9O.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.68-BKny7Fy3.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.69-B4VU4u_b.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.7-BuqwNpgA.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.70-BCd4n346.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.71-CkQppaWn.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.72-Db7vaoFs.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.73-DI80TYWl.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.74-tMCtDAHB.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.75-Ciw0D5WG.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.76-DoLjFgp-.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.77-CpT2uvMy.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.78-CkcJ4iZ1.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.79-DsOUJjEM.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.8-DsjypPd6.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.80-C0VwHTte.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.81-DTelu57i.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.82-BiMndGN1.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.83-CVcC6eDG.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.84-DlhZVt_O.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.85-S8I2D3pA.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.86-DozXXpH5.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.87-Dsn0Vuuo.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.88-iNwxxDCr.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.89-B63u_9CZ.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.9-Bi3IzpMI.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.90-ByeH1Pqf.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.91-UQLlagpm.woff2 +0 -0
- package/gui/dist/assets/brand-mark-VPhzz-WE.js +1 -0
- package/gui/dist/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2 +0 -0
- package/gui/dist/assets/geist-cyrillic-wght-normal-BEAKL7Jp.woff2 +0 -0
- package/gui/dist/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
- package/gui/dist/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
- package/gui/dist/assets/geist-mono-cyrillic-ext-wght-normal-X_5orZeX.woff2 +0 -0
- package/gui/dist/assets/geist-mono-cyrillic-wght-normal-DiZS0aHC.woff2 +0 -0
- package/gui/dist/assets/geist-mono-latin-ext-wght-normal-Bwz-egvJ.woff2 +0 -0
- package/gui/dist/assets/geist-mono-latin-wght-normal-XN7g48iV.woff2 +0 -0
- package/gui/dist/assets/geist-mono-symbols2-wght-normal-CO5SzqOn.woff2 +0 -0
- package/gui/dist/assets/geist-mono-vietnamese-wght-normal-DadHysG0.woff2 +0 -0
- package/gui/dist/assets/geist-vietnamese-wght-normal-6IgcOCM7.woff2 +0 -0
- package/gui/dist/assets/index-5REODpG3.css +2 -0
- package/gui/dist/assets/index-BWKBeK77.js +94 -0
- package/gui/dist/assets/segment-thumb-features-BQYzrze9.js +1 -0
- package/gui/dist/classic/assets/App-Bz65x1J6.js +58 -0
- package/gui/dist/{assets/Tray-BOPQyDbH.js → classic/assets/Tray-kk7mdO6I.js} +1 -1
- package/gui/dist/classic/assets/index-Dp2j8bSc.js +94 -0
- package/gui/dist/classic/assets/quota-summary-CvamtHjB.js +1 -0
- package/gui/dist/classic/index.html +47 -0
- package/gui/dist/favicon.png +0 -0
- package/gui/dist/favicon.svg +14 -0
- package/gui/dist/index.html +15 -2
- package/package.json +1 -1
- package/src/adapters/anthropic.ts +17 -8
- package/src/adapters/command-code.ts +15 -16
- package/src/adapters/cursor/transport-retry.ts +2 -2
- package/src/adapters/devin/cloud-direct/chat.ts +15 -6
- package/src/adapters/google.ts +7 -7
- package/src/adapters/kiro/adapter.ts +18 -3
- package/src/adapters/kiro/conversation.ts +8 -8
- package/src/adapters/kiro/payload.ts +45 -12
- package/src/adapters/kiro/stream.ts +230 -14
- package/src/adapters/kiro/structured-output-json.ts +191 -0
- package/src/adapters/kiro/structured-output-schema.ts +542 -0
- package/src/adapters/kiro/structured-output.ts +367 -0
- package/src/adapters/kiro-constants.ts +24 -1
- package/src/adapters/kiro-events.ts +31 -1
- package/src/adapters/kiro-retry.ts +3 -3
- package/src/adapters/kiro-tools.ts +14 -9
- package/src/adapters/kiro-wire.ts +9 -5
- package/src/adapters/ollama-native.ts +11 -1
- package/src/adapters/openai-chat/messages.ts +58 -5
- package/src/adapters/openai-chat/mistral-image-limit.ts +50 -0
- package/src/adapters/openai-chat/passthrough.ts +5 -3
- package/src/adapters/openai-chat/tool-schema.ts +83 -13
- package/src/adapters/openai-responses/empty-assistant.ts +15 -3
- package/src/adapters/openai-responses/opengateway-input.ts +18 -6
- package/src/adapters/openai-responses/passthrough.ts +5 -4
- package/src/adapters/openai-responses/reasoning.ts +9 -4
- package/src/adapters/openai-responses/request-strips.ts +1 -1
- package/src/adapters/openai-responses/tool-output-recovery.ts +79 -0
- package/src/adapters/physical-send.ts +3 -3
- package/src/adapters/qoder/live-models.ts +115 -1
- package/src/adapters/zed-openai-stream.ts +2 -1
- package/src/bridge/errors.ts +11 -2
- package/src/bridge/response-json.ts +2 -1
- package/src/bridge/sse.ts +14 -6
- package/src/chat/failure-verdict.ts +21 -0
- package/src/chat/outbound.ts +139 -21
- package/src/claude/failure-verdict.ts +21 -0
- package/src/claude/inbound-content-options.ts +15 -2
- package/src/claude/inbound-model-options.ts +2 -1
- package/src/claude/inbound-records.ts +2 -0
- package/src/claude/inbound.ts +17 -11
- package/src/claude/outbound.ts +98 -22
- package/src/cli/capabilities-access-remote.ts +13 -0
- package/src/cli/capabilities-base.ts +26 -3
- package/src/cli/capabilities-command.ts +12 -3
- package/src/cli/capabilities-provider-models.ts +3 -3
- package/src/cli/capability-contracts.ts +2 -0
- package/src/cli/codex-launch-auth.ts +30 -1
- package/src/cli/codex-launcher.ts +12 -5
- package/src/cli/codex-shim-autorestore.ts +12 -4
- package/src/cli/config-command.ts +11 -2
- package/src/cli/connect.ts +17 -2
- package/src/cli/dispatch.ts +14 -177
- package/src/cli/doctor.ts +95 -7
- package/src/cli/help.ts +2 -2
- package/src/cli/index.ts +17 -8
- package/src/cli/link-apply-restart.ts +9 -2
- package/src/cli/link.ts +1 -1
- package/src/cli/models.ts +124 -38
- package/src/cli/registry.ts +12 -4
- package/src/cli/restart-failure.ts +17 -0
- package/src/cli/root.ts +8 -0
- package/src/cli/stop-approval.ts +2 -2
- package/src/cli/sync-command.ts +243 -0
- package/src/cli/sync-fanout-process.ts +92 -0
- package/src/cli/sync-fanout.ts +161 -0
- package/src/cli/sync-flags.ts +10 -0
- package/src/cli/sync-link-status.ts +39 -0
- package/src/cli/sync-update-guard.ts +18 -0
- package/src/cli/system-restart-client.ts +5 -0
- package/src/cli/uninstall-client-state.ts +12 -1
- package/src/cli/update-restart-child.ts +13 -3
- package/src/cli/update-restart-home.ts +6 -3
- package/src/cli/update-restart.ts +36 -19
- package/src/client/connect.ts +35 -15
- package/src/client/hub-client.ts +5 -0
- package/src/client/link-home.ts +3 -2
- package/src/client/link-management-relay.ts +39 -2
- package/src/client/link-readiness.ts +3 -1
- package/src/client/machine-api.ts +2 -1
- package/src/client/machine-listener.ts +10 -0
- package/src/client/orphan-token-recovery.ts +322 -0
- package/src/client/restore-ownership.ts +19 -1
- package/src/client/runtime-restart.ts +12 -4
- package/src/client/runtime.ts +40 -11
- package/src/client/stop-routing.ts +62 -0
- package/src/client/sync-runtime.ts +65 -0
- package/src/clients/config-export.ts +32 -3
- package/src/codex/auth-context.ts +49 -103
- package/src/codex/catalog/antigravity-discovery.ts +16 -5
- package/src/codex/catalog/provider-models.ts +18 -12
- package/src/codex/forward-transport-headers.ts +35 -6
- package/src/codex/inject/config-toml.ts +88 -0
- package/src/codex/inject/multi-agent-v2.ts +30 -4
- package/src/codex/inject/plan.ts +34 -7
- package/src/codex/inject-coordination.ts +11 -0
- package/src/codex/inject.ts +18 -7
- package/src/codex/lineage.ts +13 -7
- package/src/codex/native-profile-api.ts +27 -1
- package/src/codex/quota.ts +22 -6
- package/src/codex/request-owned-affinity-key.ts +11 -0
- package/src/codex/request-owned-affinity.ts +118 -0
- package/src/codex/request-owned-main-pin.ts +86 -0
- package/src/codex/role-capability.ts +52 -41
- package/src/codex/routing/active-account.ts +13 -5
- package/src/codex/routing/selection.ts +40 -1
- package/src/codex/routing/thread-affinity-store.ts +916 -0
- package/src/codex/routing/thread-affinity.ts +90 -12
- package/src/codex/shim-diagnostics.ts +7 -0
- package/src/codex/shim-legacy-record.ts +290 -0
- package/src/codex/shim-windows-refresh.ts +9 -2
- package/src/codex/shim-wrapper-write.ts +7 -0
- package/src/codex/shim.ts +80 -21
- package/src/codex/toml-source-lines.ts +72 -13
- package/src/combos/failover.ts +6 -109
- package/src/combos/request.ts +2 -2
- package/src/combos/resolve.ts +29 -11
- package/src/config/diagnostics.ts +9 -9
- package/src/config/load-degrade.ts +27 -27
- package/src/config/process-state.ts +5 -0
- package/src/config/provider-validation.ts +9 -2
- package/src/config/removed-opencode-free-backup.ts +6 -3
- package/src/config/schema/leaf-validators.ts +1 -0
- package/src/config/tracked-runtime-inspection.ts +3 -3
- package/src/generated/compatibility-version.json +595 -255
- package/src/images/loop.ts +4 -3
- package/src/lib/client-error-body.ts +215 -0
- package/src/lib/client-retry-after.ts +66 -0
- package/src/lib/config-ownership-removal.ts +422 -0
- package/src/lib/config-ownership.ts +650 -81
- package/src/lib/context-overflow-verdict.ts +113 -0
- package/src/lib/crash-guard.ts +4 -2
- package/src/lib/desktop-cli-handoff.d.mts +4 -5
- package/src/lib/desktop-cli-handoff.mjs +18 -17
- package/src/lib/empty-tool-catalog.ts +25 -3
- package/src/lib/error-destination.ts +47 -0
- package/src/lib/errors.ts +1 -0
- package/src/lib/failure-detail.ts +66 -0
- package/src/lib/local-management-capability.ts +3 -1
- package/src/lib/messages-error-body.ts +162 -0
- package/src/lib/messages-sse-error-presentation.ts +93 -0
- package/src/lib/model-identity.ts +44 -0
- package/src/lib/passive-read.ts +9 -4
- package/src/lib/private-sqlite-path.ts +124 -0
- package/src/lib/response-service-tier.ts +17 -0
- package/src/lib/retry-after.ts +3 -0
- package/src/lib/socks5-fetch.ts +21 -9
- package/src/lib/spend-ledger-owner.ts +43 -4
- package/src/lib/upstream-condition.ts +142 -0
- package/src/lib/upstream-retry.ts +95 -12
- package/src/lib/windows-owner-acl.ts +22 -9
- package/src/lib/winsw.ts +5 -5
- package/src/lib/workflow-budget.ts +3 -1
- package/src/link/remote-platform.ts +14 -0
- package/src/link/remote-windows.ts +51 -9
- package/src/link/ssh-argv.ts +63 -10
- package/src/oauth/generic-account-failover.ts +13 -11
- package/src/oauth/index.ts +42 -73
- package/src/oauth/oauth-errors.ts +67 -0
- package/src/oauth/store.ts +21 -11
- package/src/protocols/codecs/messages-ir.ts +15 -9
- package/src/protocols/codecs/ollama.ts +197 -0
- package/src/protocols/encoders/adapter-events.ts +30 -7
- package/src/protocols/encoders/chat.ts +18 -10
- package/src/protocols/encoders/messages.ts +72 -28
- package/src/protocols/trace.ts +18 -0
- package/src/providers/antigravity-models.ts +45 -12
- package/src/providers/fastwire.ts +3 -2
- package/src/providers/free-directory.ts +2 -2
- package/src/providers/quota/anthropic-usage-windows.ts +13 -3
- package/src/providers/quota/vendor-probes-key.ts +60 -24
- package/src/providers/reasoning-metadata.ts +2 -1
- package/src/providers/registry/entries-extended.ts +9 -0
- package/src/providers/request-pacing.ts +3 -2
- package/src/reasoning-effort.ts +7 -2
- package/src/remote/hub-usage.ts +3 -0
- package/src/responses/apply-patch-envelope.ts +45 -19
- package/src/responses/compaction-history-framing.ts +5 -1
- package/src/responses/freeform-wrapper-scan.ts +5 -3
- package/src/responses/progressive-freeform-input.ts +354 -45
- package/src/routing/fallback-policy.ts +3 -1
- package/src/server/admission-model-scope.ts +17 -6
- package/src/server/admitted-http-turn.ts +57 -0
- package/src/server/anthropic-rate-limit-headers.ts +75 -3
- package/src/server/auth-cors.ts +5 -0
- package/src/server/chat-completions.ts +45 -20
- package/src/server/chat-native-sse.ts +52 -7
- package/src/server/chat-native.ts +60 -35
- package/src/server/claude-bridge-pool-session.ts +59 -0
- package/src/server/claude-messages.ts +174 -84
- package/src/server/context-history.ts +5 -1
- package/src/server/gui-static.ts +4 -1
- package/src/server/hub-usage.ts +7 -2
- package/src/server/inbound-body-admission.ts +11 -4
- package/src/server/index/link-management.ts +8 -0
- package/src/server/index/ollama-routes.ts +91 -0
- package/src/server/index/serve-options.ts +44 -24
- package/src/server/index/startup-warnings.ts +5 -12
- package/src/server/index/websocket-handler.ts +5 -2
- package/src/server/index.ts +6 -36
- package/src/server/inference/client-encoder-delivery.ts +9 -3
- package/src/server/json-serialized-bytes.ts +44 -0
- package/src/server/management/agent-settings-routes.ts +24 -21
- package/src/server/management/codex-cli-update-routes.ts +2 -1
- package/src/server/management/logs-usage-routes.ts +89 -4
- package/src/server/management/provider-routes.ts +2 -22
- package/src/server/management/qoder-provider-probe.ts +105 -0
- package/src/server/management/route-registry.ts +4 -1
- package/src/server/management/usage-aggregate-cache.ts +15 -5
- package/src/server/management/usage-source-facets.ts +38 -0
- package/src/server/messages-native-scope.ts +2 -1
- package/src/server/messages-native-tool-guard.ts +12 -4
- package/src/server/messages-native.ts +123 -47
- package/src/server/messages-response-headers.ts +25 -11
- package/src/server/messages-shared.ts +99 -65
- package/src/server/messages-sse-error-filter.ts +199 -0
- package/src/server/native-final-log.ts +93 -0
- package/src/server/ollama-inbound.ts +349 -0
- package/src/server/ollama-native-paths.ts +21 -0
- package/src/server/ollama-route-policy.ts +73 -0
- package/src/server/relay.ts +22 -3
- package/src/server/request-decompress.ts +4 -2
- package/src/server/request-log-failure-attribution.ts +22 -0
- package/src/server/request-log-failure-detail.ts +80 -0
- package/src/server/request-log-terminal-status.ts +4 -2
- package/src/server/request-log.ts +91 -42
- package/src/server/response-log-body.ts +6 -1
- package/src/server/responses/account-change-state.ts +17 -6
- package/src/server/responses/adapter-continuation.ts +17 -6
- package/src/server/responses/adapter-delivery.ts +17 -10
- package/src/server/responses/adapter-dispatch.ts +32 -31
- package/src/server/responses/anthropic-thinking-recovery.ts +3 -0
- package/src/server/responses/codex-auth-error.ts +24 -19
- package/src/server/responses/codex-ws-exchange.ts +11 -8
- package/src/server/responses/codex-ws-metadata.ts +94 -21
- package/src/server/responses/codex-ws-request.ts +3 -1
- package/src/server/responses/codex-ws-wire.ts +19 -3
- package/src/server/responses/compact.ts +57 -24
- package/src/server/responses/compaction-recovery.ts +4 -2
- package/src/server/responses/compaction-routing.ts +9 -4
- package/src/server/responses/core-auth.ts +32 -14
- package/src/server/responses/core-codex-account.ts +17 -6
- package/src/server/responses/core-combo-failure.ts +7 -1
- package/src/server/responses/core-combo-native.ts +2 -1
- package/src/server/responses/core-combo.ts +43 -27
- package/src/server/responses/core-errors.ts +24 -21
- package/src/server/responses/core-lifetime.ts +6 -3
- package/src/server/responses/core-normalize.ts +1 -0
- package/src/server/responses/core-options.ts +9 -0
- package/src/server/responses/core-pipeline.ts +4 -3
- package/src/server/responses/empty-completion-guard.ts +4 -1
- package/src/server/responses/fetch-helpers.ts +7 -1
- package/src/server/responses/input-admission.ts +28 -2
- package/src/server/responses/native-injection.ts +1 -1
- package/src/server/responses/native-response-json.ts +13 -4
- package/src/server/responses/native-response-output.ts +1 -2
- package/src/server/responses/non-replayable-error.ts +2 -1
- package/src/server/responses/pacing-overload.ts +3 -2
- package/src/server/responses/passthrough-delivery.ts +55 -14
- package/src/server/responses/passthrough-dispatch.ts +20 -18
- package/src/server/responses/passthrough-error.ts +9 -9
- package/src/server/responses/policy-fallback.ts +2 -1
- package/src/server/responses/request-prepare.ts +69 -48
- package/src/server/responses/request-transport.ts +36 -31
- package/src/server/responses/response-effects.ts +3 -2
- package/src/server/responses/run-turn-execution.ts +6 -6
- package/src/server/responses/sidecar-execution.ts +16 -12
- package/src/server/responses/spend-storage-error.ts +2 -1
- package/src/server/responses/terminal-guard.ts +30 -0
- package/src/server/responses/ws-upstream.ts +9 -0
- package/src/server/responses-custom-tool-repair.ts +14 -3
- package/src/server/responses-terminal-repair.ts +5 -2
- package/src/server/responses-undeclared-tool-guard.ts +39 -16
- package/src/server/restart-replacement.ts +3 -1
- package/src/server/safe-response-headers.ts +162 -13
- package/src/server/sse-payload-rewrite.ts +23 -11
- package/src/server/turn-state-handles.ts +164 -0
- package/src/server/workflow-refusal.ts +2 -1
- package/src/server/ws-bridge.ts +4 -0
- package/src/service/definition.ts +36 -4
- package/src/service/launchd.ts +89 -32
- package/src/service/logging.ts +34 -7
- package/src/service/ownership-mutation-lease.d.mts +11 -2
- package/src/service/ownership-mutation-lease.mjs +53 -11
- package/src/service/plist-xml.ts +59 -0
- package/src/service/state.ts +8 -0
- package/src/service/systemd-env.ts +2 -0
- package/src/service/systemd.ts +31 -7
- package/src/service/windows-taskxml.ts +16 -7
- package/src/service-manager-probe.ts +4 -10
- package/src/types/config.ts +2 -0
- package/src/types/provider.ts +2 -0
- package/src/types/request.ts +13 -1
- package/src/update/config-preflight.ts +48 -0
- package/src/update/index.ts +148 -26
- package/src/update/npm-install.d.mts +8 -0
- package/src/update/npm-install.mjs +20 -1
- package/src/update/orchestrated-admission.d.mts +4 -0
- package/src/update/orchestrated-admission.mjs +12 -0
- package/src/update/orchestrated-arguments.d.mts +12 -0
- package/src/update/orchestrated-arguments.mjs +64 -0
- package/src/update/orchestrated-child.d.mts +12 -0
- package/src/update/orchestrated-child.mjs +70 -0
- package/src/update/orchestrated-entry.ts +234 -0
- package/src/update/orchestrated-identity-probe-entry.ts +20 -0
- package/src/update/orchestrated-identity.ts +53 -0
- package/src/update/orchestrated-live-identity.ts +48 -0
- package/src/update/orchestrated-node-driver.mjs +99 -0
- package/src/update/orchestrated-outcome.d.mts +21 -0
- package/src/update/orchestrated-outcome.mjs +40 -0
- package/src/update/orchestrated-plan.ts +49 -0
- package/src/update/orchestrated-pnpm.d.mts +8 -0
- package/src/update/orchestrated-pnpm.mjs +33 -0
- package/src/update/orchestrated-session.d.mts +37 -0
- package/src/update/orchestrated-session.mjs +264 -0
- package/src/update/orchestrated-token.d.mts +10 -0
- package/src/update/orchestrated-token.mjs +21 -0
- package/src/update/orchestrated-token.ts +3 -0
- package/src/update/orchestrated-tree.d.mts +1 -0
- package/src/update/orchestrated-tree.mjs +14 -0
- package/src/update/pnpm-global-install.d.mts +6 -0
- package/src/update/pnpm-global-install.mjs +9 -2
- package/src/update/posix-install-supervisor-entry.mjs +6 -0
- package/src/update/posix-install-supervisor.d.mts +10 -0
- package/src/update/posix-install-supervisor.mjs +88 -0
- package/src/update/sync-update-mutex.d.mts +10 -0
- package/src/update/sync-update-mutex.mjs +164 -0
- package/src/update/sync-update-mutex.ts +1 -0
- package/src/update/test-home-guard.mjs +33 -0
- package/src/update/transactional-install.mjs +2 -2
- package/src/usage/client.ts +43 -0
- package/src/usage/error-detail.ts +225 -0
- package/src/usage/log.ts +64 -27
- package/src/usage/source-facets.ts +51 -0
- package/src/usage/source-filter.ts +65 -0
- package/src/usage/summary.ts +50 -8
- package/src/web-search/anthropic-executor.ts +105 -24
- package/src/web-search/executor.ts +5 -3
- package/src/web-search/loop.ts +33 -6
- package/src/web-search/progress-stream.ts +64 -5
- package/gui/dist/assets/App-bwugJRKn.js +0 -58
- package/gui/dist/assets/index-ebuVUtB7.js +0 -94
- package/gui/dist/assets/quota-summary-6HsrHQAy.js +0 -1
- /package/gui/dist/{assets → classic/assets}/App-B4j-Txmb.css +0 -0
- /package/gui/dist/{assets → classic/assets}/index-CHWwDo9L.css +0 -0
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
import type { AdapterEvent, OcxParsedRequest, OcxUsage } from "../../types";
|
|
2
|
+
import { KIRO_STRUCTURED_OUTPUT_TOOL_NAME } from "../kiro-constants";
|
|
3
|
+
import { sanitizeKiroSchema } from "../kiro-tools";
|
|
4
|
+
import { readKiroJson } from "./structured-output-json";
|
|
5
|
+
import { assertKiroStrictSchemaSupported, kiroStrictSchemaProblem, rewriteKiroWrappedRefs } from "./structured-output-schema";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Structured output on Kiro, emulated through a private terminal tool.
|
|
9
|
+
*
|
|
10
|
+
* The CodeWhisperer wire has no schema-constrained response mode, which is why this adapter used to
|
|
11
|
+
* refuse `text.format` json_schema/json_object outright: a caller that expects parseable JSON and
|
|
12
|
+
* receives prose fails downstream. Refusing kept that promise but broke every caller that only asks
|
|
13
|
+
* for a small JSON answer — T3 Code titles each thread through a Messages `output_config.format`
|
|
14
|
+
* request, and Claude Code's own structured-output calls take the same path.
|
|
15
|
+
*
|
|
16
|
+
* The wire does carry tool input schemas, and a tool call's input is JSON by construction. So a
|
|
17
|
+
* structured-output turn advertises one tool whose input schema IS the caller's format, tells the
|
|
18
|
+
* model to answer by calling it, and relays the call's input as the assistant's text. The promise
|
|
19
|
+
* is unchanged: the client receives JSON that parsed and passed the checks below, or an error —
|
|
20
|
+
* never prose. A non-strict format gets light checks (root type and the root's `required` keys),
|
|
21
|
+
* the same position the Cursor prompt fallback takes. A `strict: true` format is validated against
|
|
22
|
+
* the whole schema (structured-output-schema.ts), and a strict schema that validator cannot enforce
|
|
23
|
+
* is refused before sending.
|
|
24
|
+
*/
|
|
25
|
+
export interface KiroStructuredOutputSpec {
|
|
26
|
+
/** The caller's schema exactly as sent; absent when only "a JSON object" was requested. */
|
|
27
|
+
schema?: Record<string, unknown>;
|
|
28
|
+
/** True when the caller asked for `strict: true`, so the value must conform to the whole schema. */
|
|
29
|
+
strict?: boolean;
|
|
30
|
+
/** The tool input schema actually advertised: sanitized, and wrapped when `wrapped` is true. */
|
|
31
|
+
toolSchema: Record<string, unknown>;
|
|
32
|
+
/**
|
|
33
|
+
* True when the answer rides the tool input's `value` property instead of BEING the input.
|
|
34
|
+
*
|
|
35
|
+
* Kiro, like Bedrock, accepts only an object-typed tool input root and refuses a root
|
|
36
|
+
* anyOf/oneOf/allOf. kiro-tools flattens such roots for ordinary tools, which is harmless for an
|
|
37
|
+
* argument bag but would silently change the meaning of a caller's output contract — a root
|
|
38
|
+
* `anyOf` would become "any of these properties". Wrapping keeps the schema intact one level down.
|
|
39
|
+
*/
|
|
40
|
+
wrapped: boolean;
|
|
41
|
+
name?: string;
|
|
42
|
+
description?: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
type JsonRecord = Record<string, unknown>;
|
|
46
|
+
|
|
47
|
+
/** A plain JSON object: not null and not an array. */
|
|
48
|
+
function isRecord(value: unknown): value is JsonRecord {
|
|
49
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** An object-typed root without root composition can be the tool input schema as it stands. */
|
|
53
|
+
function isPlainObjectRoot(schema: JsonRecord): boolean {
|
|
54
|
+
return schema.type === "object"
|
|
55
|
+
&& !["anyOf", "oneOf", "allOf", "$ref"].some(key => Object.hasOwn(schema, key));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The structured-output contract this turn carries, or undefined for an ordinary turn.
|
|
60
|
+
*
|
|
61
|
+
* `options.textFormat` is the source; `_structuredOutput` alone (no format object) still means the
|
|
62
|
+
* caller expects JSON, so it is honoured as the weakest form of the contract: a JSON object.
|
|
63
|
+
*/
|
|
64
|
+
export function kiroStructuredOutputSpec(parsed: OcxParsedRequest): KiroStructuredOutputSpec | undefined {
|
|
65
|
+
const format = parsed.options.textFormat;
|
|
66
|
+
if (!format && !parsed._structuredOutput) return undefined;
|
|
67
|
+
const meta = {
|
|
68
|
+
...(format?.type === "json_schema" && format.name ? { name: format.name } : {}),
|
|
69
|
+
...(format?.type === "json_schema" && format.description ? { description: format.description } : {}),
|
|
70
|
+
};
|
|
71
|
+
const schema = format?.type === "json_schema" && isRecord(format.schema) ? format.schema : undefined;
|
|
72
|
+
// A Messages schema is a conformance promise even when its translation states `strict: false`.
|
|
73
|
+
const strict = format?.type === "json_schema" && (format.strict === true || parsed._structuredOutputConformance === true);
|
|
74
|
+
// A strict format promises conformance to its schema; without an object schema (absent, or a
|
|
75
|
+
// boolean such as `false`) there is nothing this emulation can enforce, so it is refused.
|
|
76
|
+
if (!schema && strict) {
|
|
77
|
+
throw new Error("Kiro does not support Responses structured output: a strict format needs a JSON object schema");
|
|
78
|
+
}
|
|
79
|
+
if (!schema) return { toolSchema: { type: "object" }, wrapped: false, ...meta };
|
|
80
|
+
if (strict) assertKiroStrictSchemaSupported(schema);
|
|
81
|
+
const contract = { schema, ...(strict ? { strict } : {}) };
|
|
82
|
+
const sanitized = sanitizeKiroSchema(schema) as JsonRecord;
|
|
83
|
+
if (isPlainObjectRoot(schema)) return { ...contract, toolSchema: sanitized, wrapped: false, ...meta };
|
|
84
|
+
// `#/$defs/...` references resolve against the document root, which is now the wrapper. Hoist the
|
|
85
|
+
// definitions with them so a referenced schema still resolves after it moves under `value`, and
|
|
86
|
+
// re-point `#` and other root-relative references at `#/properties/value`, the original root.
|
|
87
|
+
// A root `$id` stays at the wrapper root with the hoisted definitions, so references keep the
|
|
88
|
+
// same base; moved under `value` it would start a new resource.
|
|
89
|
+
const { $defs, definitions, $id, ...inner } = rewriteKiroWrappedRefs(sanitized) as JsonRecord;
|
|
90
|
+
return {
|
|
91
|
+
...contract,
|
|
92
|
+
wrapped: true,
|
|
93
|
+
toolSchema: {
|
|
94
|
+
...($id !== undefined ? { $id } : {}),
|
|
95
|
+
type: "object",
|
|
96
|
+
properties: { value: inner },
|
|
97
|
+
required: ["value"],
|
|
98
|
+
...($defs !== undefined ? { $defs } : {}),
|
|
99
|
+
...(definitions !== undefined ? { definitions } : {}),
|
|
100
|
+
},
|
|
101
|
+
...meta,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** The private terminal tool advertised for a structured-output turn, with the caller's (sanitized, possibly wrapped) schema as its input schema. */
|
|
106
|
+
export function kiroStructuredOutputTool(spec: KiroStructuredOutputSpec): Record<string, unknown> {
|
|
107
|
+
const delivery = spec.wrapped
|
|
108
|
+
? "Put the complete final JSON value in `value`."
|
|
109
|
+
: "The tool input itself is the complete final JSON answer.";
|
|
110
|
+
return {
|
|
111
|
+
toolSpecification: {
|
|
112
|
+
name: KIRO_STRUCTURED_OUTPUT_TOOL_NAME,
|
|
113
|
+
// Same reasoning as the completion tool's description (payload.ts): this is the surface the
|
|
114
|
+
// model reads while choosing between tools, so it states terminality and the obligation here
|
|
115
|
+
// rather than leaving them to the prose contract alone.
|
|
116
|
+
description: `Terminal structured-output channel, not an ordinary work tool. The caller requires the final answer as JSON in exactly the format of this tool's input schema. When the task is complete, call this tool exactly once instead of writing the answer as ordinary assistant text. ${delivery} The call is complete when issued: it ends the turn, returns no tool result, and no text or tool call may follow it.`,
|
|
117
|
+
inputSchema: { json: spec.toolSchema },
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* The prose half of the structured-output contract, at most `maxChars` long.
|
|
124
|
+
*
|
|
125
|
+
* The caller's schema is restated verbatim because the advertised one is sanitized: Kiro's
|
|
126
|
+
* validator rejects `additionalProperties`, `pattern`, length and range keywords, so the tool schema
|
|
127
|
+
* alone would let the model miss constraints the caller wrote. A schema that does not fit the
|
|
128
|
+
* injected-instruction budget is dropped whole rather than cut mid-JSON.
|
|
129
|
+
*/
|
|
130
|
+
export function kiroStructuredOutputInstructions(
|
|
131
|
+
spec: KiroStructuredOutputSpec,
|
|
132
|
+
hasOrdinaryTools: boolean,
|
|
133
|
+
maxChars: number,
|
|
134
|
+
): string {
|
|
135
|
+
const kind = spec.schema ? "JSON matching the caller's JSON Schema" : "a single JSON object";
|
|
136
|
+
const delivery = spec.wrapped
|
|
137
|
+
? "with the complete final JSON value in its `value` property"
|
|
138
|
+
: "with the complete final JSON answer as the tool input";
|
|
139
|
+
const base = [
|
|
140
|
+
`[Final response format] The caller requires this turn's final answer as ${kind}.`,
|
|
141
|
+
`Deliver it only by calling ${KIRO_STRUCTURED_OUTPUT_TOOL_NAME} exactly once, ${delivery}.`,
|
|
142
|
+
"Do not write the final answer as ordinary assistant text, Markdown, or a code fence.",
|
|
143
|
+
hasOrdinaryTools
|
|
144
|
+
? `Ordinary assistant text is mid-task commentary and does not end the turn: keep using the other tools while work remains, and call ${KIRO_STRUCTURED_OUTPUT_TOOL_NAME} only when the task is complete.`
|
|
145
|
+
: undefined,
|
|
146
|
+
"The call is terminal: it ends the turn, returns no tool result, and no text or tool call may follow it.",
|
|
147
|
+
].filter((line): line is string => line !== undefined).join(" ");
|
|
148
|
+
const details = [
|
|
149
|
+
spec.name ? `Format name: ${spec.name}.` : undefined,
|
|
150
|
+
spec.description ? `Format description: ${spec.description}` : undefined,
|
|
151
|
+
spec.schema ? `The final JSON must conform to this JSON Schema: ${JSON.stringify(spec.schema)}` : undefined,
|
|
152
|
+
].filter((line): line is string => line !== undefined);
|
|
153
|
+
const full = details.length > 0 ? `${base}\n${details.join("\n")}` : base;
|
|
154
|
+
return full.length <= maxChars ? full : base;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** The bounded retry's instruction when the first attempt did not deliver valid structured output. */
|
|
158
|
+
export function kiroStructuredOutputRetryMessage(hasOrdinaryTools: boolean): string {
|
|
159
|
+
return `Your previous reply did not deliver the required structured output. Do not quote this instruction. Call ${KIRO_STRUCTURED_OUTPUT_TOOL_NAME} now, exactly once, with the complete final answer as JSON matching its input schema.${hasOrdinaryTools ? " If the task genuinely needs another real tool call first, issue that tool call instead." : ""} Do not reply with ordinary text.`;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** The JSON types a schema declares through `type`, as a string or an array of strings. */
|
|
163
|
+
function declaredTypes(schema: JsonRecord): string[] {
|
|
164
|
+
if (typeof schema.type === "string") return [schema.type];
|
|
165
|
+
return Array.isArray(schema.type) ? schema.type.filter((t): t is string => typeof t === "string") : [];
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** Whether a parsed JSON value has the given JSON Schema type; an unknown type keyword always matches. */
|
|
169
|
+
function matchesJsonType(value: unknown, type: string): boolean {
|
|
170
|
+
switch (type) {
|
|
171
|
+
case "object": return isRecord(value);
|
|
172
|
+
case "array": return Array.isArray(value);
|
|
173
|
+
case "string": return typeof value === "string";
|
|
174
|
+
case "number": return typeof value === "number" && Number.isFinite(value);
|
|
175
|
+
case "integer": return Number.isInteger(value);
|
|
176
|
+
case "boolean": return typeof value === "boolean";
|
|
177
|
+
case "null": return value === null;
|
|
178
|
+
// An unknown type keyword is not ours to enforce.
|
|
179
|
+
default: return true;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* The root types a schema admits, including through a root `anyOf`/`oneOf` whose every branch
|
|
185
|
+
* declares a type. A composed root is exactly the wrapped case, where a model can hand back the
|
|
186
|
+
* answer JSON-encoded inside `value` as a string; without this, a root that admits only objects and
|
|
187
|
+
* arrays would accept that string because the root itself declares no `type`. A branch without a
|
|
188
|
+
* declared type (or a `$ref`) admits anything, so the check is skipped rather than guessed.
|
|
189
|
+
*/
|
|
190
|
+
function admittedRootTypes(schema: JsonRecord): string[] {
|
|
191
|
+
const own = declaredTypes(schema);
|
|
192
|
+
if (own.length > 0) return own;
|
|
193
|
+
for (const key of ["anyOf", "oneOf"] as const) {
|
|
194
|
+
const branches = schema[key];
|
|
195
|
+
if (!Array.isArray(branches) || branches.length === 0) continue;
|
|
196
|
+
const perBranch = branches.map(branch => (isRecord(branch) ? declaredTypes(branch) : []));
|
|
197
|
+
if (perBranch.some(types => types.length === 0)) return [];
|
|
198
|
+
return [...new Set(perBranch.flat())];
|
|
199
|
+
}
|
|
200
|
+
return [];
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** The first reason `value` breaks the light contract, or undefined when it passes. */
|
|
204
|
+
function structuredValueProblem(spec: KiroStructuredOutputSpec, value: unknown): string | undefined {
|
|
205
|
+
const types = spec.schema ? admittedRootTypes(spec.schema) : ["object"];
|
|
206
|
+
if (types.length > 0 && !types.some(type => matchesJsonType(value, type))) {
|
|
207
|
+
return `expected a JSON ${types.join(" or ")} at the root`;
|
|
208
|
+
}
|
|
209
|
+
const required = spec.schema?.required;
|
|
210
|
+
if (isRecord(value) && Array.isArray(required)) {
|
|
211
|
+
const missing = required.find(key => typeof key === "string" && !Object.hasOwn(value, key));
|
|
212
|
+
// No property name: diagnostics carry fixed categories, never schema or answer text.
|
|
213
|
+
if (missing !== undefined) return "the root is missing a required property";
|
|
214
|
+
}
|
|
215
|
+
return undefined;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Strict validation of JSON `text` that already parsed: the JSON text to relay, or the problem.
|
|
220
|
+
*
|
|
221
|
+
* The strict validator reads the text again keeping every number's lexeme, so bounds, `const` and
|
|
222
|
+
* `enum` judge the exact bytes the client will receive. The wrapped form relays the original bytes
|
|
223
|
+
* of `value`, which keeps integers beyond 2^53 intact there too.
|
|
224
|
+
*/
|
|
225
|
+
function strictStructuredJson(schema: JsonRecord, text: string, wrapped: boolean): { json: string } | { problem: string } {
|
|
226
|
+
const document = readKiroJson(text);
|
|
227
|
+
if (!document) return { problem: "the value nests deeper than strict validation allows" };
|
|
228
|
+
const root = document.value;
|
|
229
|
+
const value = wrapped && root.kind === "object" ? root.entries.get("value") : root;
|
|
230
|
+
if (!value) return { problem: "missing `value`" };
|
|
231
|
+
const problem = kiroStrictSchemaProblem(schema, value, document.nodes);
|
|
232
|
+
if (problem) return { problem };
|
|
233
|
+
return { json: wrapped ? text.slice(value.start, value.end) : text };
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const FAILURE_PREFIX = "Kiro structured output did not match the requested format";
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Validate the structured-output tool's input and return the JSON text to relay.
|
|
240
|
+
*
|
|
241
|
+
* Both forms relay the model's own bytes rather than a re-serialization, so integers beyond 2^53,
|
|
242
|
+
* numbers past the double range and key order survive exactly as written. The wrapped form relays
|
|
243
|
+
* the original bytes of `value`.
|
|
244
|
+
*/
|
|
245
|
+
export function parseKiroStructuredToolInput(
|
|
246
|
+
spec: KiroStructuredOutputSpec,
|
|
247
|
+
raw: string,
|
|
248
|
+
): { json: string } | { error: string } {
|
|
249
|
+
const text = raw.trim() || "{}";
|
|
250
|
+
let input: unknown;
|
|
251
|
+
try {
|
|
252
|
+
input = JSON.parse(text);
|
|
253
|
+
} catch {
|
|
254
|
+
return { error: "Kiro returned invalid JSON for the structured-output tool" };
|
|
255
|
+
}
|
|
256
|
+
if (!isRecord(input)) return { error: "Kiro returned a non-object input for the structured-output tool" };
|
|
257
|
+
if (spec.wrapped && !Object.hasOwn(input, "value")) {
|
|
258
|
+
return { error: `${FAILURE_PREFIX}: missing \`value\`` };
|
|
259
|
+
}
|
|
260
|
+
const value = spec.wrapped ? input.value : input;
|
|
261
|
+
if (spec.strict && spec.schema) {
|
|
262
|
+
const strict = strictStructuredJson(spec.schema, text, spec.wrapped);
|
|
263
|
+
return "json" in strict ? strict : { error: `${FAILURE_PREFIX}: ${strict.problem}` };
|
|
264
|
+
}
|
|
265
|
+
const problem = structuredValueProblem(spec, value);
|
|
266
|
+
if (problem) return { error: `${FAILURE_PREFIX}: ${problem}` };
|
|
267
|
+
if (!spec.wrapped) return { json: text };
|
|
268
|
+
const wrappedText = wrappedValueText(text);
|
|
269
|
+
return wrappedText === undefined
|
|
270
|
+
? { error: `${FAILURE_PREFIX}: the value nests deeper than the proxy can relay exactly` }
|
|
271
|
+
: { json: wrappedText };
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* The original bytes of the wrapper's `value`, or undefined past the reader's nesting limit. Such a
|
|
276
|
+
* value is refused rather than re-serialized, because re-serializing rewrites large numbers.
|
|
277
|
+
*/
|
|
278
|
+
function wrappedValueText(text: string): string | undefined {
|
|
279
|
+
const root = readKiroJson(text)?.value;
|
|
280
|
+
const span = root?.kind === "object" ? root.entries.get("value") : undefined;
|
|
281
|
+
return span ? text.slice(span.start, span.end) : undefined;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const WHOLE_FENCE = /^```[A-Za-z0-9_-]*[ \t]*\r?\n([\s\S]*?)\r?\n?```$/;
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Accept a plain-text answer only when it already IS the requested JSON.
|
|
288
|
+
*
|
|
289
|
+
* A model that ignores the tool and writes the JSON as text has still answered correctly, and
|
|
290
|
+
* spending a second paid request to have it repeat the same bytes through a tool would be waste.
|
|
291
|
+
* One whole-message code fence is unwrapped because that is the most common way models present
|
|
292
|
+
* JSON; anything else — prose around the JSON, two fenced blocks, trailing commentary — is not JSON
|
|
293
|
+
* and is refused, which sends the turn to the bounded retry or to an error.
|
|
294
|
+
*/
|
|
295
|
+
export function parseKiroStructuredText(spec: KiroStructuredOutputSpec, text: string): string | undefined {
|
|
296
|
+
const trimmed = text.trim();
|
|
297
|
+
const candidate = WHOLE_FENCE.exec(trimmed)?.[1]?.trim() ?? trimmed;
|
|
298
|
+
if (!candidate) return undefined;
|
|
299
|
+
let value: unknown;
|
|
300
|
+
try {
|
|
301
|
+
value = JSON.parse(candidate);
|
|
302
|
+
} catch {
|
|
303
|
+
return undefined;
|
|
304
|
+
}
|
|
305
|
+
if (spec.strict && spec.schema) {
|
|
306
|
+
// A text answer is the value itself, even when the tool input would have wrapped it.
|
|
307
|
+
return "json" in strictStructuredJson(spec.schema, candidate, false) ? candidate : undefined;
|
|
308
|
+
}
|
|
309
|
+
return structuredValueProblem(spec, value) === undefined ? candidate : undefined;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Whether Kiro stopped the way a finished answer stops: no stop reason, END_TURN or STOP_SEQUENCE.
|
|
314
|
+
*
|
|
315
|
+
* Every other stop reason (MAX_TOKENS, a content filter, an exhausted context window) has already
|
|
316
|
+
* ended the inference upstream. Text cut by one of them is never accepted as the requested JSON,
|
|
317
|
+
* even when its prefix parses, and a failed structured answer under one of them earns no retry:
|
|
318
|
+
* the retry would hit the same limit or verdict, so the stop's own terminal handling runs instead.
|
|
319
|
+
*/
|
|
320
|
+
export function isKiroStructuredCleanStop(normalizedStopReason: string | undefined): boolean {
|
|
321
|
+
return normalizedStopReason === undefined
|
|
322
|
+
|| normalizedStopReason === "END_TURN"
|
|
323
|
+
|| normalizedStopReason === "STOP_SEQUENCE";
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/** Message for a bounded retry that answered in text that is not the requested JSON. */
|
|
327
|
+
export const KIRO_STRUCTURED_TEXT_FAILURE = `${FAILURE_PREFIX}: the model answered with text that is not the requested JSON`;
|
|
328
|
+
|
|
329
|
+
/** Message for a bounded retry that ended without text, a tool call, or a structured answer. */
|
|
330
|
+
export const KIRO_STRUCTURED_EMPTY_FAILURE = `${FAILURE_PREFIX}: the bounded retry produced no answer`;
|
|
331
|
+
|
|
332
|
+
/** Stop reasons Kiro documents; only these are named in a diagnostic. */
|
|
333
|
+
const KNOWN_STOP_REASONS = new Set([
|
|
334
|
+
"MAX_TOKENS", "MODEL_CONTEXT_WINDOW_EXCEEDED", "MALFORMED_TOOL_USE", "MALFORMED_MODEL_OUTPUT",
|
|
335
|
+
"TOOL_USE", "CONTENT_FILTERED", "GUARDRAIL_INTERVENED",
|
|
336
|
+
]);
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Message for a bounded retry whose text was cut by a stop that does not end a finished answer. The
|
|
340
|
+
* stop reason comes from upstream, so an unrecognized one is not echoed.
|
|
341
|
+
*/
|
|
342
|
+
export function kiroStructuredStopFailure(normalizedStopReason: string): string {
|
|
343
|
+
const stop = KNOWN_STOP_REASONS.has(normalizedStopReason) ? ` with ${normalizedStopReason}` : "";
|
|
344
|
+
return `${FAILURE_PREFIX}: the bounded retry stopped${stop} before a complete answer`;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* Terminal for a turn that, after its one bounded retry, still produced no valid structured output.
|
|
349
|
+
*
|
|
350
|
+
* A hard error with `retryable: false` rather than the retryable `incomplete` the completion
|
|
351
|
+
* contract uses for a malformed answer: the model has already been asked twice inside this turn, so
|
|
352
|
+
* the proxy must not replay the whole turn on its own. The status is the 502 every other Kiro
|
|
353
|
+
* model-output protocol error uses, which a client's own retry policy may still act on (Claude
|
|
354
|
+
* outbound reports it as `overloaded_error`); that choice stays with the client. The distinct code
|
|
355
|
+
* lets a caller tell this apart from a transport failure.
|
|
356
|
+
*/
|
|
357
|
+
export function kiroStructuredOutputFailure(message: string, usage: OcxUsage): AdapterEvent {
|
|
358
|
+
return {
|
|
359
|
+
type: "error",
|
|
360
|
+
message,
|
|
361
|
+
status: 502,
|
|
362
|
+
errorType: "upstream_error",
|
|
363
|
+
code: "invalid_kiro_structured_output",
|
|
364
|
+
retryable: false,
|
|
365
|
+
usage,
|
|
366
|
+
};
|
|
367
|
+
}
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
export const KIRO_COMPLETION_TOOL_NAME = "codex_kiro_final_answer";
|
|
2
|
+
/**
|
|
3
|
+
* Private terminal channel for Responses structured output (`text.format` json_schema/json_object).
|
|
4
|
+
*
|
|
5
|
+
* The CodeWhisperer wire has no schema-constrained response mode, but it does carry tool input
|
|
6
|
+
* schemas, and a tool call's input is JSON by construction. A turn that asks for structured output
|
|
7
|
+
* therefore advertises this tool INSTEAD of `KIRO_COMPLETION_TOOL_NAME` and relays its input as the
|
|
8
|
+
* assistant's text. Reserved in the same collision domain so a client tool can never claim it.
|
|
9
|
+
*/
|
|
10
|
+
export const KIRO_STRUCTURED_OUTPUT_TOOL_NAME = "codex_kiro_structured_output";
|
|
2
11
|
|
|
3
12
|
/**
|
|
4
13
|
* Request-scoped CodeWhisperer service profile for AWS Builder ID accounts.
|
|
@@ -31,9 +40,23 @@ export const KIRO_CONTINUATION_MESSAGE =
|
|
|
31
40
|
* The condition names a decision, information, AND clarification on purpose. A model blocked on a
|
|
32
41
|
* missing account id or an ambiguous path is stuck exactly as hard as one blocked on a choice, and
|
|
33
42
|
* "decision" alone would leave that common class of question with no endorsed move again.
|
|
43
|
+
*
|
|
44
|
+
* It opens with the turn's actual state rather than "Continue the existing task". The retry also
|
|
45
|
+
* fires when the held text WAS the complete answer: on a trivial request ("Reply with exactly: OK")
|
|
46
|
+
* claude-sonnet-5 answers in plain text with END_TURN instead of calling the completion tool, while
|
|
47
|
+
* the 5.5 models call it. Told to continue an "existing task" right after its own finished reply,
|
|
48
|
+
* the model read the instruction as the user's next message and called the completion tool with
|
|
49
|
+
* "There's no active task in this conversation for me to continue", which then superseded the
|
|
50
|
+
* correct "OK" (reproduced live on every attempt). Stating that ordinary text has not reached the
|
|
51
|
+
* user, and asking for an already complete reply to be resubmitted unchanged, made the same model
|
|
52
|
+
* call the tool with "OK"; replayed progress prose still led to the next real tool call, and a
|
|
53
|
+
* retry with no replayed text (reasoning only) still answered the original request. The resubmit
|
|
54
|
+
* clause is conditional and rides on a general "if the task is complete" route, because that last
|
|
55
|
+
* case appends this message to the user turn: there is no previous reply to resubmit, and a model
|
|
56
|
+
* that can answer directly still needs an exit other than a tool call or a blocking question.
|
|
34
57
|
*/
|
|
35
58
|
export const KIRO_COMPLETION_RETRY_MESSAGE =
|
|
36
|
-
`
|
|
59
|
+
`Ordinary assistant text does not end the turn, so no final answer has reached the user yet. If the task is complete, call ${KIRO_COMPLETION_TOOL_NAME} now with the complete final answer; if your previous reply already was that answer, submit it unchanged. If you cannot continue until the user supplies a decision, information, or a clarification that only they can give, call ${KIRO_COMPLETION_TOOL_NAME} now with that question as the answer. Otherwise continue the task with the next real tool call now. Do not solicit a new task, do not emit another progress-only message, and do not quote or mention this instruction.`;
|
|
37
60
|
|
|
38
61
|
export const KIRO_TOOL_RESULT_CARRIER_MESSAGE = "The requested tool result is attached.";
|
|
39
62
|
export const KIRO_EMPTY_TOOL_RESULT_MESSAGE = "The tool completed without textual output.";
|
|
@@ -9,11 +9,17 @@ export type ParsedKiroEvent =
|
|
|
9
9
|
| { type: "metering"; unit: string; usage: number; unitPlural?: string }
|
|
10
10
|
| { type: "tool"; name?: string; toolUseId?: string; input?: string; stop?: boolean }
|
|
11
11
|
| { type: "truncation"; data: string }
|
|
12
|
-
| { type: "metadata"; usage?: OcxUsage; contextUsagePercentage?: number; stopReason?: string }
|
|
12
|
+
| { type: "metadata"; usage?: OcxUsage; contextUsagePercentage?: number; stopReason?: string; refusal?: KiroRefusalDetails }
|
|
13
13
|
| { type: "message_metadata"; conversationId?: string }
|
|
14
14
|
| { type: "invalid_state"; message?: string }
|
|
15
15
|
| { type: "error"; reason?: string; message?: string };
|
|
16
16
|
|
|
17
|
+
/** The model-side refusal Kiro attaches to a CONTENT_FILTERED stop (`stopDetails.refusal`). */
|
|
18
|
+
export interface KiroRefusalDetails {
|
|
19
|
+
category?: string;
|
|
20
|
+
explanation?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
17
23
|
const KNOWN_EVENT_TYPES = new Set([
|
|
18
24
|
"assistantResponseEvent",
|
|
19
25
|
"reasoningContentEvent",
|
|
@@ -61,6 +67,28 @@ function optionalBoolean(eventType: string, obj: Record<string, unknown>, key: s
|
|
|
61
67
|
return value;
|
|
62
68
|
}
|
|
63
69
|
|
|
70
|
+
/**
|
|
71
|
+
* `stopDetails.refusal` is advisory copy for the user. Read it leniently: an unexpected shape drops
|
|
72
|
+
* the details rather than turning the refusal itself into a protocol error. Upstream-controlled
|
|
73
|
+
* text, so each field is bounded.
|
|
74
|
+
*/
|
|
75
|
+
function refusalDetails(obj: Record<string, unknown>): KiroRefusalDetails | undefined {
|
|
76
|
+
const stopDetails = obj.stopDetails;
|
|
77
|
+
if (!stopDetails || typeof stopDetails !== "object" || Array.isArray(stopDetails)) return undefined;
|
|
78
|
+
const refusal = (stopDetails as Record<string, unknown>).refusal;
|
|
79
|
+
if (!refusal || typeof refusal !== "object" || Array.isArray(refusal)) return undefined;
|
|
80
|
+
/** A non-empty trimmed string field of the refusal, cut to `max` characters, or undefined. */
|
|
81
|
+
const field = (key: string, max: number): string | undefined => {
|
|
82
|
+
const value = (refusal as Record<string, unknown>)[key];
|
|
83
|
+
return typeof value === "string" && value.trim() ? value.trim().slice(0, max) : undefined;
|
|
84
|
+
};
|
|
85
|
+
const category = field("category", 64);
|
|
86
|
+
const explanation = field("explanation", 400);
|
|
87
|
+
return category || explanation
|
|
88
|
+
? { ...(category ? { category } : {}), ...(explanation ? { explanation } : {}) }
|
|
89
|
+
: undefined;
|
|
90
|
+
}
|
|
91
|
+
|
|
64
92
|
function tokenCount(eventType: string, obj: Record<string, unknown>, key: string, required: boolean): number {
|
|
65
93
|
const value = obj[key];
|
|
66
94
|
if (value === undefined && !required) return 0;
|
|
@@ -217,6 +245,7 @@ export function parseKiroEvent(eventType: string, payload: Uint8Array): ParsedKi
|
|
|
217
245
|
return malformed(eventType, "contextUsagePercentage must be a finite number");
|
|
218
246
|
}
|
|
219
247
|
const stopReason = optionalString(eventType, parsed, "stopReason");
|
|
248
|
+
const refusal = refusalDetails(parsed);
|
|
220
249
|
return {
|
|
221
250
|
type: "metadata",
|
|
222
251
|
...(parseTokenUsage(eventType, parsed.tokenUsage) !== undefined
|
|
@@ -224,6 +253,7 @@ export function parseKiroEvent(eventType: string, payload: Uint8Array): ParsedKi
|
|
|
224
253
|
: {}),
|
|
225
254
|
...(typeof contextUsagePercentage === "number" ? { contextUsagePercentage } : {}),
|
|
226
255
|
...(stopReason !== undefined ? { stopReason } : {}),
|
|
256
|
+
...(refusal ? { refusal } : {}),
|
|
227
257
|
};
|
|
228
258
|
}
|
|
229
259
|
case "contextUsageEvent": {
|
|
@@ -6,7 +6,7 @@ import { readBoundedResponseBody } from "../lib/bounded-body";
|
|
|
6
6
|
import { resolveClientRetryAfter } from "../lib/retry-after";
|
|
7
7
|
import { parseRetryAfterMs } from "../combos";
|
|
8
8
|
import {
|
|
9
|
-
SendBudgetExhaustedError,
|
|
9
|
+
SendBudgetExhaustedError, errorDestinationLabel,
|
|
10
10
|
abortError,
|
|
11
11
|
cancelResponseBodyBestEffort,
|
|
12
12
|
fetchWithAttemptDeadline,
|
|
@@ -184,7 +184,7 @@ async function fetchWithResetRecovery(
|
|
|
184
184
|
});
|
|
185
185
|
destinationRebased = false;
|
|
186
186
|
if (decision && !decision.allowed) {
|
|
187
|
-
throw new SendBudgetExhaustedError(destination);
|
|
187
|
+
throw new SendBudgetExhaustedError(errorDestinationLabel(destination));
|
|
188
188
|
}
|
|
189
189
|
// Reported after admission and before dispatch, so a refused send is never counted and an
|
|
190
190
|
// admitted one is counted exactly once whichever way the fetch below settles.
|
|
@@ -202,7 +202,7 @@ async function fetchWithResetRecovery(
|
|
|
202
202
|
}, timeoutMs, ctx.abortSignal, ctx.stream, (async (input, init) => {
|
|
203
203
|
try {
|
|
204
204
|
const run = async (): Promise<Response> => {
|
|
205
|
-
if (permit && !permit.use()) throw new SendBudgetExhaustedError(destination);
|
|
205
|
+
if (permit && !permit.use()) throw new SendBudgetExhaustedError(errorDestinationLabel(destination));
|
|
206
206
|
notePhysicalSend(attempt > 0);
|
|
207
207
|
return (executor.unpacedFetch ?? executor)(input, init);
|
|
208
208
|
};
|
|
@@ -60,25 +60,30 @@ const KIRO_REJECTED_SCHEMA_KEYS = new Set([
|
|
|
60
60
|
// "format"/"pattern" would be deleted. We recurse into the value schemas but keep every name intact.
|
|
61
61
|
const SCHEMA_MAP_KEYS = new Set(["properties", "$defs", "definitions"]);
|
|
62
62
|
|
|
63
|
+
// Keys whose values are JSON data rather than schemas. Recursing into them would strip
|
|
64
|
+
// keyword-named keys from the data itself and turn `const: {"format":"pdf"}` into `const: {}`,
|
|
65
|
+
// silently changing the value a tool argument must equal.
|
|
66
|
+
const SCHEMA_LITERAL_KEYS = new Set(["const", "enum", "default", "examples"]);
|
|
67
|
+
|
|
63
68
|
function sanitizeSchemaMap(value: unknown): unknown {
|
|
64
69
|
if (!value || typeof value !== "object" || Array.isArray(value)) return sanitizeKiroSchema(value);
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
return out;
|
|
70
|
+
// fromEntries defines own properties: a property named "__proto__" stays a property instead of
|
|
71
|
+
// hitting the prototype setter and vanishing from the advertised schema.
|
|
72
|
+
return Object.fromEntries(Object.entries(value as Record<string, unknown>).map(([name, child]) => [name, sanitizeKiroSchema(child)]));
|
|
70
73
|
}
|
|
71
74
|
|
|
72
|
-
|
|
75
|
+
/** Strip the keywords Kiro's tool-spec validator rejects, everywhere in a schema tree. */
|
|
76
|
+
export function sanitizeKiroSchema(value: unknown): unknown {
|
|
73
77
|
if (Array.isArray(value)) return value.map(sanitizeKiroSchema);
|
|
74
78
|
if (!value || typeof value !== "object") return value;
|
|
75
|
-
const out:
|
|
79
|
+
const out: Array<[string, unknown]> = [];
|
|
76
80
|
for (const [key, child] of Object.entries(value as Record<string, unknown>)) {
|
|
77
81
|
if (KIRO_REJECTED_SCHEMA_KEYS.has(key)) continue;
|
|
78
82
|
if (key === "required" && Array.isArray(child) && child.length === 0) continue;
|
|
79
|
-
|
|
83
|
+
if (SCHEMA_LITERAL_KEYS.has(key)) out.push([key, child]);
|
|
84
|
+
else out.push([key, SCHEMA_MAP_KEYS.has(key) ? sanitizeSchemaMap(child) : sanitizeKiroSchema(child)]);
|
|
80
85
|
}
|
|
81
|
-
return out;
|
|
86
|
+
return Object.fromEntries(out);
|
|
82
87
|
}
|
|
83
88
|
|
|
84
89
|
function ensureRootObjectType(schema: unknown): Record<string, unknown> {
|
|
@@ -2,7 +2,7 @@ import { createHash, randomUUID } from "node:crypto";
|
|
|
2
2
|
import { hostname, userInfo } from "node:os";
|
|
3
3
|
import { normalizeKiroModelId } from "../providers/kiro-models";
|
|
4
4
|
import type { OcxParsedRequest } from "../types";
|
|
5
|
-
import { KIRO_COMPLETION_TOOL_NAME } from "./kiro-constants";
|
|
5
|
+
import { KIRO_COMPLETION_TOOL_NAME, KIRO_STRUCTURED_OUTPUT_TOOL_NAME } from "./kiro-constants";
|
|
6
6
|
|
|
7
7
|
let cachedFp: string | undefined;
|
|
8
8
|
|
|
@@ -77,15 +77,19 @@ export interface KiroToolNameRegistry {
|
|
|
77
77
|
readonly nameMap: Map<string, string>;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
/**
|
|
80
|
+
/** Proxy-owned terminal tools; neither may be claimed by a client tool or a replayed call. */
|
|
81
|
+
const KIRO_RESERVED_TOOL_NAMES: readonly string[] = [KIRO_COMPLETION_TOOL_NAME, KIRO_STRUCTURED_OUTPUT_TOOL_NAME];
|
|
82
|
+
|
|
83
|
+
/** One collision domain for advertised tools, replayed calls, and the private terminal tools. */
|
|
81
84
|
export function createKiroToolNameRegistry(): KiroToolNameRegistry {
|
|
82
|
-
const used = new Set<string>(
|
|
85
|
+
const used = new Set<string>(KIRO_RESERVED_TOOL_NAMES);
|
|
83
86
|
const wireToKiro = new Map<string, string>();
|
|
84
87
|
const nameMap = new Map<string, string>();
|
|
85
88
|
return {
|
|
89
|
+
/** Return the Kiro-safe alias for a wire tool name, registering it on first use; reserved names are refused. */
|
|
86
90
|
alias(wireName: string): string {
|
|
87
|
-
if (wireName
|
|
88
|
-
throw new Error(`Kiro reserves the tool name ${JSON.stringify(
|
|
91
|
+
if (KIRO_RESERVED_TOOL_NAMES.includes(wireName)) {
|
|
92
|
+
throw new Error(`Kiro reserves the tool name ${JSON.stringify(wireName)}`);
|
|
89
93
|
}
|
|
90
94
|
const existing = wireToKiro.get(wireName);
|
|
91
95
|
if (existing) return existing;
|
|
@@ -641,7 +641,17 @@ function usageFromNative(value: JsonRecord | undefined): OcxUsage | undefined {
|
|
|
641
641
|
const input = isFiniteNonNegativeInteger(value.prompt_eval_count) ? value.prompt_eval_count : undefined;
|
|
642
642
|
const output = isFiniteNonNegativeInteger(value.eval_count) ? value.eval_count : undefined;
|
|
643
643
|
if (input === undefined && output === undefined) return undefined;
|
|
644
|
-
|
|
644
|
+
// Ollama reports prompt_eval_cached_count as the cached subset of prompt_eval_count (api/types.go;
|
|
645
|
+
// its CLI prints prompt_eval_count - cached as the uncached share), which is OCX's cache-read
|
|
646
|
+
// convention. Omitted means unknown, so no cache field is invented; a count that exceeds the
|
|
647
|
+
// prompt is not a subset and is ignored rather than clamped (#8101).
|
|
648
|
+
const cached = input !== undefined && isFiniteNonNegativeInteger(value.prompt_eval_cached_count)
|
|
649
|
+
&& value.prompt_eval_cached_count <= input ? value.prompt_eval_cached_count : undefined;
|
|
650
|
+
return {
|
|
651
|
+
inputTokens: input ?? 0,
|
|
652
|
+
outputTokens: output ?? 0,
|
|
653
|
+
...(cached !== undefined ? { cachedInputTokens: cached, cacheReadInputTokens: cached } : {}),
|
|
654
|
+
};
|
|
645
655
|
}
|
|
646
656
|
|
|
647
657
|
function stopReasonFromNative(value: unknown): string | undefined {
|