chainlesschain 0.166.85 → 0.166.87
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/README.md +8 -0
- package/package.json +3 -2
- package/src/assets/linux-subreaper/linux-arm64/manifest.json +1 -1
- package/src/assets/linux-subreaper/linux-x64/manifest.json +1 -1
- package/src/assets/web-panel/assets/{AIOps-Cgo7OFpi.js → AIOps-DdQjhXg9.js} +1 -1
- package/src/assets/web-panel/assets/{ActionButton-lUMnE2Ln.js → ActionButton-CuwA3hPA.js} +1 -1
- package/src/assets/web-panel/assets/{Analytics-CsvKzTot.js → Analytics-DTVXJSAC.js} +3 -3
- package/src/assets/web-panel/assets/{AppLayout-C2z1h1Pv.js → AppLayout-j06JBfEQ.js} +5 -5
- package/src/assets/web-panel/assets/{Artifacts-C5Q0ZhNb.js → Artifacts-BFAK8LEW.js} +1 -1
- package/src/assets/web-panel/assets/{Audit-DXnfPKsI.js → Audit-BiGxRpOf.js} +1 -1
- package/src/assets/web-panel/assets/{BackgroundAgents-DjbGcLm3.js → BackgroundAgents-B6uHaPkZ.js} +1 -1
- package/src/assets/web-panel/assets/{Backup-9bVrKvXE.js → Backup-BNAesB8q.js} +1 -1
- package/src/assets/web-panel/assets/{BaseInput-bx5ri7BD.js → BaseInput-BOuetfCd.js} +1 -1
- package/src/assets/web-panel/assets/{Chat-CCFmeUMY.js → Chat-cVzo3m_D.js} +4 -4
- package/src/assets/web-panel/assets/ChatBubbleRenderer-DZ2Ys-CI.js +1 -0
- package/src/assets/web-panel/assets/{Checkbox-ei7MQXe9.js → Checkbox-BaCTS-H8.js} +1 -1
- package/src/assets/web-panel/assets/{Codegen-CXgBJ9iu.js → Codegen-CBE8NiYh.js} +1 -1
- package/src/assets/web-panel/assets/{Col-DMkMsizS.js → Col-C9wLiUTN.js} +1 -1
- package/src/assets/web-panel/assets/{Community-CvpB_UFR.js → Community-jdClBSIp.js} +1 -1
- package/src/assets/web-panel/assets/{Compact-gay5hbFX.js → Compact-BIjauIlM.js} +1 -1
- package/src/assets/web-panel/assets/{Compliance-dG8JQyRL.js → Compliance-CZ-AoaNj.js} +1 -1
- package/src/assets/web-panel/assets/{Cowork-BA3xfaTW.js → Cowork-BbTKtDS4.js} +4 -4
- package/src/assets/web-panel/assets/{Cron-D1_HsxyY.js → Cron-ImKdtwNi.js} +2 -2
- package/src/assets/web-panel/assets/{Crosschain-DZqoqoy5.js → Crosschain-B54GSHf5.js} +1 -1
- package/src/assets/web-panel/assets/{DID-Cwnr8hCO.js → DID-BQt5WUzs.js} +2 -2
- package/src/assets/web-panel/assets/{Dashboard-CxevypiI.js → Dashboard--gNOffif.js} +2 -2
- package/src/assets/web-panel/assets/{Dropdown-Bs7-yWgr.js → Dropdown-342A5YJw.js} +1 -1
- package/src/assets/web-panel/assets/{EmailListRenderer-CcEs2Puo.js → EmailListRenderer-CtIZ3ZHd.js} +1 -1
- package/src/assets/web-panel/assets/{EvolutionSettings-C9ipBzAQ.js → EvolutionSettings-CyZPoTio.js} +1 -1
- package/src/assets/web-panel/assets/{FamilyGuardDashboard-Dt6--mGn.js → FamilyGuardDashboard-B1MCkFEu.js} +1 -1
- package/src/assets/web-panel/assets/{Federation-CD0JN5FF.js → Federation-DZWoERUy.js} +1 -1
- package/src/assets/web-panel/assets/{FormItemContext-POypz3Xv.js → FormItemContext-Onmb0mp3.js} +1 -1
- package/src/assets/web-panel/assets/{GenericCardRenderer-Dv9f-0F5.js → GenericCardRenderer-u1qhNNc7.js} +1 -1
- package/src/assets/web-panel/assets/{Git-BbTh5Atv.js → Git-BEowR1C5.js} +2 -2
- package/src/assets/web-panel/assets/{Governance-C71dgoir.js → Governance-BiYd3AAg.js} +1 -1
- package/src/assets/web-panel/assets/{Inference-DwSHxbJB.js → Inference-CsC4Vjh5.js} +1 -1
- package/src/assets/web-panel/assets/{KnowledgeGraph-Cx1oQYQZ.js → KnowledgeGraph-BXA7ikPM.js} +1 -1
- package/src/assets/web-panel/assets/{Logs-BAJWe00o.js → Logs-C9WoplQm.js} +2 -2
- package/src/assets/web-panel/assets/{MarkdownRenderer-CD8a7lHT.js → MarkdownRenderer-DecEsXsy.js} +1 -1
- package/src/assets/web-panel/assets/{Marketplace-fwuY7P7Y.js → Marketplace-CCoJBfRL.js} +1 -1
- package/src/assets/web-panel/assets/{McpTools-Di4693uc.js → McpTools-CzaOWBoA.js} +3 -3
- package/src/assets/web-panel/assets/{Memory-Cz3L-GUB.js → Memory-BPwh7u1-.js} +2 -2
- package/src/assets/web-panel/assets/{MobileBridge-BuXKIkSb.js → MobileBridge-Bk47v6z2.js} +1 -1
- package/src/assets/web-panel/assets/MobileProjects-D-CY--Sb.js +1 -0
- package/src/assets/web-panel/assets/{Mtc-LnACMFd0.js → Mtc-ExVyAGlW.js} +5 -5
- package/src/assets/web-panel/assets/{MtcAudit-BZy7yE0t.js → MtcAudit-Rrw10csE.js} +5 -5
- package/src/assets/web-panel/assets/{Multisig-BFG5iVrE.js → Multisig-8TxxwxZZ.js} +3 -3
- package/src/assets/web-panel/assets/{NLProgramming-DgXi04vJ.js → NLProgramming-CNckjtnY.js} +1 -1
- package/src/assets/web-panel/assets/Notes-C4j6cZTu.js +7 -0
- package/src/assets/web-panel/assets/{NotificationSettings-AixrsHw5.js → NotificationSettings-CchU8rWd.js} +1 -1
- package/src/assets/web-panel/assets/OrderTableRenderer-ZJBoyJ16.js +1 -0
- package/src/assets/web-panel/assets/{Organization-UNCBC3ux.js → Organization-F0Je7EdZ.js} +2 -2
- package/src/assets/web-panel/assets/{Overflow-Drh8oAFT.js → Overflow-B2k-JA3u.js} +1 -1
- package/src/assets/web-panel/assets/{P2P-bc2q0xEB.js → P2P-yui9Xxe6.js} +2 -2
- package/src/assets/web-panel/assets/{PdhVaultBrowser-BGwKxcDM.js → PdhVaultBrowser-CegM7hT6.js} +3 -3
- package/src/assets/web-panel/assets/{Permissions-DOnUxUzu.js → Permissions-CSFL0uvh.js} +4 -4
- package/src/assets/web-panel/assets/{PersonalDataHub-B3qPZkrr.js → PersonalDataHub-BrMcd-vr.js} +6 -6
- package/src/assets/web-panel/assets/{Pipeline-B6hfa4-i.js → Pipeline-fzrliaVP.js} +1 -1
- package/src/assets/web-panel/assets/{Privacy-Bun3c35F.js → Privacy-BrkUjJ_g.js} +1 -1
- package/src/assets/web-panel/assets/{ProjectInit-CCObdzk9.js → ProjectInit-CF_QCsW9.js} +2 -2
- package/src/assets/web-panel/assets/{ProjectSettings-C6lKrSXY.js → ProjectSettings-Duwrd8aC.js} +2 -2
- package/src/assets/web-panel/assets/{Projects-DYcta7MZ.js → Projects-B0dLVXzU.js} +1 -1
- package/src/assets/web-panel/assets/{Providers-BtykxKCe.js → Providers-Db8iS1xQ.js} +1 -1
- package/src/assets/web-panel/assets/{QrScannerModal-D9CDyroY.js → QrScannerModal-CHbNzEQs.js} +1 -1
- package/src/assets/web-panel/assets/{QuickAsk-CJauCxXx.js → QuickAsk-CIESMfeR.js} +1 -1
- package/src/assets/web-panel/assets/{Recommend-BbiYZofR.js → Recommend-BTMbCMtR.js} +1 -1
- package/src/assets/web-panel/assets/{RemoteSession-BymCrgFW.js → RemoteSession-DavyK6J-.js} +3 -3
- package/src/assets/web-panel/assets/{Reputation-BWrGpMpF.js → Reputation-BFKtMelA.js} +1 -1
- package/src/assets/web-panel/assets/{Row-9pOYIhiW.js → Row-BI9AZUvw.js} +1 -1
- package/src/assets/web-panel/assets/{RssFeed-D3bQJ4qB.js → RssFeed-1nwXt8NY.js} +2 -2
- package/src/assets/web-panel/assets/{Search-BpKOOFE0.js → Search-Ck8PDYbk.js} +1 -1
- package/src/assets/web-panel/assets/{Security-DC6C0NSz.js → Security-BgDqpCbq.js} +4 -4
- package/src/assets/web-panel/assets/{Services-Lkf1046J.js → Services-DF8anXm4.js} +2 -2
- package/src/assets/web-panel/assets/{Skeleton-eCQ_SsDb.js → Skeleton-CoHyY4ZX.js} +1 -1
- package/src/assets/web-panel/assets/Skills-dOaD4Ztl.js +1 -0
- package/src/assets/web-panel/assets/{Sla-BQbKy8XJ.js → Sla-XuOawvQY.js} +1 -1
- package/src/assets/web-panel/assets/{SpeechSettings-DHsRx-XA.js → SpeechSettings-DFJ7nAiu.js} +1 -1
- package/src/assets/web-panel/assets/{SyncSettings-CC281X_J.js → SyncSettings-B2xYj-Pi.js} +2 -2
- package/src/assets/web-panel/assets/Tasks-D_SzNTLi.js +1 -0
- package/src/assets/web-panel/assets/{Templates-Cr2vC0tg.js → Templates-BXFmKh7W.js} +1 -1
- package/src/assets/web-panel/assets/{Tenant-DeYO5pIG.js → Tenant-CRg2AXbd.js} +1 -1
- package/src/assets/web-panel/assets/{Terminal-DBNgbfPr.js → Terminal-DQgxnuep.js} +2 -2
- package/src/assets/web-panel/assets/{TimelineRenderer-MoxgaF3x.js → TimelineRenderer-BrPQhQVc.js} +1 -1
- package/src/assets/web-panel/assets/{Tokens-CT2QfAN7.js → Tokens-RByy4USy.js} +1 -1
- package/src/assets/web-panel/assets/{Trigger-DPUnomxs.js → Trigger-pE3y8u73.js} +1 -1
- package/src/assets/web-panel/assets/{Trust-DnufuaTx.js → Trust-DhID9C33.js} +1 -1
- package/src/assets/web-panel/assets/{UkeySign-CJ6iOdPs.js → UkeySign-CPxEPNBH.js} +1 -1
- package/src/assets/web-panel/assets/{VideoEditing-xBWkH8bL.js → VideoEditing-ZD8DUxeQ.js} +1 -1
- package/src/assets/web-panel/assets/{Wallet-WYV-4hMR.js → Wallet-Br9JREEd.js} +4 -4
- package/src/assets/web-panel/assets/{WebAuthn-DJ5Mhd9L.js → WebAuthn-Cn-YacJg.js} +4 -4
- package/src/assets/web-panel/assets/{WorkflowEditor-B__UdOjN.js → WorkflowEditor-BTu0oqMp.js} +1 -1
- package/src/assets/web-panel/assets/{chat-CLlmBVhp.js → chat-CEjws_QF.js} +1 -1
- package/src/assets/web-panel/assets/{colors-B8zoPQYm.js → colors-Bv2RNebW.js} +1 -1
- package/src/assets/web-panel/assets/{compact-item-CvJ-dUsH.js → compact-item-gSc3EofP.js} +1 -1
- package/src/assets/web-panel/assets/{createContext-LAtMm8SC.js → createContext-kyFDaqWC.js} +1 -1
- package/src/assets/web-panel/assets/devWarning-Dcc8pILJ.js +1 -0
- package/src/assets/web-panel/assets/{hasIn-CLYvg42H.js → hasIn-BuMWcjhx.js} +1 -1
- package/src/assets/web-panel/assets/{index-Cv7vwX3z.js → index--nrQmk8X.js} +1 -1
- package/src/assets/web-panel/assets/index-05NB95_V.js +1 -0
- package/src/assets/web-panel/assets/{index-BUVrYDNV.js → index-42PTBO7a.js} +1 -1
- package/src/assets/web-panel/assets/{index-B6zlMzZz.js → index-BCS5j4SQ.js} +1 -1
- package/src/assets/web-panel/assets/{index-oX216HRH.js → index-BSSIJ-rv.js} +1 -1
- package/src/assets/web-panel/assets/{index-B02qgCao.js → index-BUOCcXou.js} +1 -1
- package/src/assets/web-panel/assets/{index-B_RPWP_5.js → index-Bg5jis0q.js} +1 -1
- package/src/assets/web-panel/assets/{index-DX99e8Xy.js → index-C-LPpwe9.js} +1 -1
- package/src/assets/web-panel/assets/{index-DDm9m4vC.js → index-C56Drzol.js} +1 -1
- package/src/assets/web-panel/assets/{index-DHq2Of6z.js → index-C7Jo20JB.js} +1 -1
- package/src/assets/web-panel/assets/{index-C_dq-6_3.js → index-C9U9SjcT.js} +1 -1
- package/src/assets/web-panel/assets/{index-D0Z13xcZ.js → index-CF3TjDNz.js} +1 -1
- package/src/assets/web-panel/assets/{index-B1hHp9_M.js → index-CMS3Mk93.js} +1 -1
- package/src/assets/web-panel/assets/{index-DfOOACfd.js → index-CNt2X-aK.js} +1 -1
- package/src/assets/web-panel/assets/index-Cb6q8wlI.js +1 -0
- package/src/assets/web-panel/assets/{index-DYW4Z3y-.js → index-Cj4RA7oA.js} +1 -1
- package/src/assets/web-panel/assets/{index-C2KFnUsv.js → index-CkfvP2dN.js} +1 -1
- package/src/assets/web-panel/assets/{index-BkcQJvsz.js → index-Cm8K8Evn.js} +1 -1
- package/src/assets/web-panel/assets/{index-CVDcRQuX.js → index-CvSuM_CB.js} +1 -1
- package/src/assets/web-panel/assets/{index-BCzyJ1xS.js → index-Czo_hw97.js} +1 -1
- package/src/assets/web-panel/assets/{index-Cpda0SAz.js → index-D3m3EXbL.js} +1 -1
- package/src/assets/web-panel/assets/{index-iJ6s24bA.js → index-DR561Sqc.js} +1 -1
- package/src/assets/web-panel/assets/{index-Di9vKira.js → index-DRa4R7vv.js} +1 -1
- package/src/assets/web-panel/assets/{index-09YzRb6Z.js → index-DYKSuD02.js} +3 -3
- package/src/assets/web-panel/assets/{index-C5v7cEtm.js → index-DYcPWVN9.js} +1 -1
- package/src/assets/web-panel/assets/{index-BGrQ2uEl.js → index-DbVUA5l3.js} +1 -1
- package/src/assets/web-panel/assets/{index-4rr5jFOL.js → index-DbkyTMj-.js} +1 -1
- package/src/assets/web-panel/assets/{index-GR3omApz.js → index-Dej4AGOz.js} +1 -1
- package/src/assets/web-panel/assets/{index-f1ptYBMr.js → index-EpxWlmip.js} +1 -1
- package/src/assets/web-panel/assets/{index-C3uD5H7u.js → index-GpvWtvw3.js} +1 -1
- package/src/assets/web-panel/assets/{index-C6PETyel.js → index-NQ0c4hJ1.js} +1 -1
- package/src/assets/web-panel/assets/{index-CnLXLaEF.js → index-OjZUHz5z.js} +1 -1
- package/src/assets/web-panel/assets/{index-DpeV-6y4.js → index-U-ytt84A.js} +1 -1
- package/src/assets/web-panel/assets/{index-DNQUdPam.js → index-_0bfDTDu.js} +1 -1
- package/src/assets/web-panel/assets/{index-BM2HqHdT.js → index-jmMAqBAm.js} +1 -1
- package/src/assets/web-panel/assets/{index-Bu7-I2L4.js → index-nLemnBZ2.js} +1 -1
- package/src/assets/web-panel/assets/{index-CUcE6rIa.js → index-q65c1kp8.js} +1 -1
- package/src/assets/web-panel/assets/{index-DX0aHEHL.js → index-sJ1F5Txa.js} +1 -1
- package/src/assets/web-panel/assets/{index-CxJ4NPVq.js → index-xfS_WO9b.js} +1 -1
- package/src/assets/web-panel/assets/{initDefaultProps-QD-koeaw.js → initDefaultProps-B-wqiSu7.js} +1 -1
- package/src/assets/web-panel/assets/{motion-CTItLW4-.js → motion-BK4_B4MD.js} +1 -1
- package/src/assets/web-panel/assets/{move-CGsdTOdN.js → move-BU2TgDDO.js} +1 -1
- package/src/assets/web-panel/assets/{mtc-parser-C1kW_CNU.js → mtc-parser-DA3E4_EX.js} +1 -1
- package/src/assets/web-panel/assets/{omit-B4PilaYy.js → omit-CaHz1e_q.js} +1 -1
- package/src/assets/web-panel/assets/{pickAttrs-DBGUE12e.js → pickAttrs-NXZ19amf.js} +1 -1
- package/src/assets/web-panel/assets/{placementArrow-DZxCLjuo.js → placementArrow-BCXI9AHO.js} +1 -1
- package/src/assets/web-panel/assets/{responsiveObserve-CZjQiocN.js → responsiveObserve-DdlZ9tLk.js} +1 -1
- package/src/assets/web-panel/assets/{slide-Btz5hh2_.js → slide-DCZm_Vc4.js} +1 -1
- package/src/assets/web-panel/assets/{statusUtils-CfuxuLIt.js → statusUtils-CuEULKQr.js} +1 -1
- package/src/assets/web-panel/assets/{styleChecker-DdO0Obo_.js → styleChecker-Bo_UXG8x.js} +1 -1
- package/src/assets/web-panel/assets/{useFlexGapSupport-CxftJ-Zs.js → useFlexGapSupport-B9PaTcFH.js} +1 -1
- package/src/assets/web-panel/assets/{useFs-pVJChh6K.js → useFs-DwSTGdVR.js} +1 -1
- package/src/assets/web-panel/assets/{usePersonalDataHub-wv7Q0uNE.js → usePersonalDataHub-FswSxnDC.js} +1 -1
- package/src/assets/web-panel/assets/{vnode-DVOVfAqC.js → vnode-EUztvYTj.js} +1 -1
- package/src/assets/web-panel/assets/{zoom-B5tebZuT.js → zoom-D41MAgV-.js} +1 -1
- package/src/assets/web-panel/index.html +1 -1
- package/src/command-help-index.json +1 -1
- package/src/commands/eval.js +118 -18
- package/src/commands/memory.js +34 -15
- package/src/commands/sandbox.js +9 -0
- package/src/data/changelog.json +26 -0
- package/src/lib/causal-observability.js +6 -45
- package/src/lib/context-memory-kernel/durable-memory-port.js +54 -12
- package/src/lib/context-memory-kernel/index.js +1 -0
- package/src/lib/context-memory-kernel/memory-query-index.js +278 -0
- package/src/lib/context-memory-kernel/memory-service.js +60 -18
- package/src/lib/context-memory-kernel/runtime.js +5 -3
- package/src/lib/context-memory-kernel/segmented-memory-port.js +955 -0
- package/src/lib/eval/outcomes.js +20 -10
- package/src/lib/eval/runner.js +49 -5
- package/src/lib/eval/tasks.js +8 -3
- package/src/lib/eval/verify01-contracts.js +349 -0
- package/src/lib/eval/verify01-execution.js +605 -0
- package/src/lib/execution-support.js +58 -0
- package/src/lib/llm-pricing.js +98 -11
- package/src/lib/model-catalog-review.js +116 -0
- package/src/lib/model-context-catalog.js +23 -1
- package/src/lib/openai-responses.js +39 -0
- package/src/lib/packer/pack-update-applier.js +13 -8
- package/src/lib/permission-authority.js +146 -10
- package/src/lib/process-execution-broker/index.js +8 -0
- package/src/lib/process-execution-broker/linux-subreaper-process.js +24 -2
- package/src/lib/process-execution-broker/process-ownership-journal.js +168 -7
- package/src/lib/process-execution-broker/process-ownership-quarantine.js +56 -1
- package/src/lib/process-execution-broker/process-recovery-cgroup.js +272 -0
- package/src/lib/sandbox-egress-authority-monitor.js +62 -5
- package/src/lib/scoped-permission-store.js +104 -1
- package/src/lib/settings-authority-domain.cjs +37 -2
- package/src/lib/settings-loader.cjs +67 -34
- package/src/lib/settings-permission-authority.cjs +373 -0
- package/src/runtime/agent-core.js +88 -407
- package/src/runtime/headless-runner.js +8 -3
- package/src/runtime/headless-stream.js +10 -3
- package/src/runtime/permission-authority-host.js +151 -0
- package/src/runtime/provider-stream-state.js +379 -0
- package/src/assets/web-panel/assets/ChatBubbleRenderer-ClqsIfTT.js +0 -1
- package/src/assets/web-panel/assets/MobileProjects-Bk-lK4Um.js +0 -1
- package/src/assets/web-panel/assets/Notes-BAj0Kgg4.js +0 -7
- package/src/assets/web-panel/assets/OrderTableRenderer-Dwqk3FlG.js +0 -1
- package/src/assets/web-panel/assets/Skills-BvDSQ3-d.js +0 -1
- package/src/assets/web-panel/assets/Tasks-CHHSWHom.js +0 -1
- package/src/assets/web-panel/assets/devWarning-DgZ4fdGI.js +0 -1
- package/src/assets/web-panel/assets/index-jLEdASOV.js +0 -1
- package/src/assets/web-panel/assets/index-jesGo4rl.js +0 -1
|
@@ -15,6 +15,25 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import fs from "fs";
|
|
18
|
+
import {
|
|
19
|
+
_isNonNegativeSafeInteger,
|
|
20
|
+
_providerUsageCount,
|
|
21
|
+
_optionalProviderUsageCount,
|
|
22
|
+
_hasCompleteProviderUsage,
|
|
23
|
+
_providerReceiptId,
|
|
24
|
+
_anthropicInitState,
|
|
25
|
+
_anthropicReduceLine,
|
|
26
|
+
_anthropicFinalize,
|
|
27
|
+
_openaiCachedTokens,
|
|
28
|
+
_openaiInitState,
|
|
29
|
+
_openaiReduceLine,
|
|
30
|
+
_openaiFinalize,
|
|
31
|
+
} from "./provider-stream-state.js";
|
|
32
|
+
export {
|
|
33
|
+
_accumulateAnthropicStream,
|
|
34
|
+
_accumulateOpenAIStream,
|
|
35
|
+
} from "./provider-stream-state.js";
|
|
36
|
+
|
|
18
37
|
import path from "path";
|
|
19
38
|
import {
|
|
20
39
|
buildReadFilePage,
|
|
@@ -69,6 +88,7 @@ import {
|
|
|
69
88
|
} from "../lib/model-capabilities.js";
|
|
70
89
|
import {
|
|
71
90
|
createOpenAIResponsesBody,
|
|
91
|
+
createOpenAIResponsesReasoning,
|
|
72
92
|
createOpenAIResponsesStreamState,
|
|
73
93
|
finalizeOpenAIResponsesStream,
|
|
74
94
|
normalizeOpenAIResponsesResponse,
|
|
@@ -2427,6 +2447,7 @@ function projectPermissionAuthority({ authority, rules, tool, args, cwd }) {
|
|
|
2427
2447
|
version: authority?.version || authority?.policyVersion || null,
|
|
2428
2448
|
revision: authority?.revision ?? null,
|
|
2429
2449
|
settingsRevision: authority?.settingsRevision || null,
|
|
2450
|
+
persistentSettingsRevision: authority?.persistentSettingsRevision || null,
|
|
2430
2451
|
headHash: authority?.headHash || null,
|
|
2431
2452
|
verdict: {
|
|
2432
2453
|
decision: verdict.decision || null,
|
|
@@ -2635,10 +2656,19 @@ export async function executeTool(name, args, context = {}) {
|
|
|
2635
2656
|
let settingsPermissionAuthority = null;
|
|
2636
2657
|
let entrySettingsPermissionRevision = null;
|
|
2637
2658
|
try {
|
|
2659
|
+
const providerAuthority = permissionRulesProviderAuthority(
|
|
2660
|
+
context.permissionRulesProvider,
|
|
2661
|
+
);
|
|
2662
|
+
providerAuthority?.assertWorkspace?.(context.cwd || process.cwd());
|
|
2663
|
+
providerAuthority?.assertWritableRoots?.([
|
|
2664
|
+
...workspaceRootsFor(
|
|
2665
|
+
path.resolve(context.cwd || process.cwd()),
|
|
2666
|
+
context.additionalDirectories,
|
|
2667
|
+
),
|
|
2668
|
+
...(context.sandbox?.policy?.allowWrite || []),
|
|
2669
|
+
]);
|
|
2638
2670
|
if (name === "run_shell") {
|
|
2639
|
-
settingsPermissionAuthority =
|
|
2640
|
-
context.permissionRulesProvider,
|
|
2641
|
-
);
|
|
2671
|
+
settingsPermissionAuthority = providerAuthority;
|
|
2642
2672
|
entrySettingsPermissionRevision =
|
|
2643
2673
|
settingsPermissionAuthority?.getSnapshot() || null;
|
|
2644
2674
|
}
|
|
@@ -2653,14 +2683,36 @@ export async function executeTool(name, args, context = {}) {
|
|
|
2653
2683
|
},
|
|
2654
2684
|
};
|
|
2655
2685
|
}
|
|
2686
|
+
function settingsPermissionRevocation(cause) {
|
|
2687
|
+
const error = new Error(
|
|
2688
|
+
"Settings permission authority became unavailable after admission",
|
|
2689
|
+
{ cause },
|
|
2690
|
+
);
|
|
2691
|
+
error.code = "CC_SHELL_POLICY_AUTHORITY_CHANGED";
|
|
2692
|
+
return error;
|
|
2693
|
+
}
|
|
2656
2694
|
function assertSettingsPermissionRevision() {
|
|
2657
2695
|
if (!settingsPermissionAuthority) return;
|
|
2696
|
+
let currentRevision;
|
|
2697
|
+
try {
|
|
2698
|
+
settingsPermissionAuthority.assertWorkspace?.(cwd);
|
|
2699
|
+
settingsPermissionAuthority.assertWritableRoots?.([
|
|
2700
|
+
...workspaceRootsFor(cwd, context.additionalDirectories),
|
|
2701
|
+
...(context.sandbox?.policy?.allowWrite || []),
|
|
2702
|
+
]);
|
|
2703
|
+
currentRevision = settingsPermissionAuthority.getSnapshot();
|
|
2704
|
+
} catch (cause) {
|
|
2705
|
+
// A concurrent durable writer can expose its guard/prepared state. Once
|
|
2706
|
+
// admitted, losing the ready snapshot revokes that admission immediately;
|
|
2707
|
+
// do not wait for commit or let the lower-level load error change the
|
|
2708
|
+
// shell revocation contract. Initial admission retains its load errors.
|
|
2709
|
+
throw settingsPermissionRevocation(cause);
|
|
2710
|
+
}
|
|
2658
2711
|
if (
|
|
2659
2712
|
permissionRulesProviderAuthority(
|
|
2660
2713
|
liveExecutionContext.permissionRulesProvider,
|
|
2661
2714
|
) !== settingsPermissionAuthority ||
|
|
2662
|
-
|
|
2663
|
-
entrySettingsPermissionRevision
|
|
2715
|
+
currentRevision !== entrySettingsPermissionRevision
|
|
2664
2716
|
) {
|
|
2665
2717
|
const error = new Error(
|
|
2666
2718
|
"Settings permission authority changed after admission",
|
|
@@ -3633,11 +3685,19 @@ export async function executeTool(name, args, context = {}) {
|
|
|
3633
3685
|
let currentPermissionRules =
|
|
3634
3686
|
liveExecutionContext.permissionRules || null;
|
|
3635
3687
|
if (permissionRulesProvider) {
|
|
3636
|
-
|
|
3637
|
-
|
|
3638
|
-
|
|
3639
|
-
|
|
3640
|
-
|
|
3688
|
+
try {
|
|
3689
|
+
currentPermissionAuthority = await permissionRulesProvider({
|
|
3690
|
+
cwd,
|
|
3691
|
+
tool: name,
|
|
3692
|
+
args,
|
|
3693
|
+
});
|
|
3694
|
+
} catch (cause) {
|
|
3695
|
+
// A writer may start after the preceding snapshot read but
|
|
3696
|
+
// before the bound provider finishes observing its sources.
|
|
3697
|
+
if (settingsPermissionAuthority)
|
|
3698
|
+
throw settingsPermissionRevocation(cause);
|
|
3699
|
+
throw cause;
|
|
3700
|
+
}
|
|
3641
3701
|
currentPermissionRules =
|
|
3642
3702
|
currentPermissionAuthority?.rules ||
|
|
3643
3703
|
currentPermissionAuthority ||
|
|
@@ -6946,6 +7006,9 @@ async function executeToolInner(
|
|
|
6946
7006
|
const { createDockerEgressAuthorityMonitor } =
|
|
6947
7007
|
await import("../lib/sandbox-egress-authority-monitor.js");
|
|
6948
7008
|
authorityMonitor = createDockerEgressAuthorityMonitor({
|
|
7009
|
+
sessionId: sessionId || null,
|
|
7010
|
+
policyVersion:
|
|
7011
|
+
shellDispatchPolicyAuthority?.policyVersion || null,
|
|
6949
7012
|
async revalidate() {
|
|
6950
7013
|
await shellDispatchPolicyAuthority?.revalidate?.();
|
|
6951
7014
|
shellDispatchPolicyAuthority?.revalidateDockerSandbox?.();
|
|
@@ -7139,6 +7202,13 @@ async function executeToolInner(
|
|
|
7139
7202
|
result.authorityFailure = {
|
|
7140
7203
|
code: revoked.code || "CC_DOCKER_EGRESS_AUTHORITY_CHANGED",
|
|
7141
7204
|
...(revoked.cleanupError ? { cleanupFailed: true } : {}),
|
|
7205
|
+
...(authorityMonitor.getStopAcknowledgement()
|
|
7206
|
+
? {
|
|
7207
|
+
stopAcknowledgement: {
|
|
7208
|
+
...authorityMonitor.getStopAcknowledgement(),
|
|
7209
|
+
},
|
|
7210
|
+
}
|
|
7211
|
+
: {}),
|
|
7142
7212
|
};
|
|
7143
7213
|
if (result.exitCode === 0) {
|
|
7144
7214
|
result = {
|
|
@@ -11611,51 +11681,7 @@ function getEffectiveToolDefinitions(options = {}) {
|
|
|
11611
11681
|
});
|
|
11612
11682
|
}
|
|
11613
11683
|
|
|
11614
|
-
function _isNonNegativeSafeInteger(value) {
|
|
11615
|
-
return Number.isSafeInteger(value) && value >= 0;
|
|
11616
|
-
}
|
|
11617
|
-
|
|
11618
|
-
function _providerUsageCount(usage, canonical, alias) {
|
|
11619
|
-
if (!usage || typeof usage !== "object" || Array.isArray(usage)) return null;
|
|
11620
|
-
const hasCanonical = Object.prototype.hasOwnProperty.call(usage, canonical);
|
|
11621
|
-
const hasAlias = Object.prototype.hasOwnProperty.call(usage, alias);
|
|
11622
|
-
if (!hasCanonical && !hasAlias) return null;
|
|
11623
|
-
if (hasCanonical && hasAlias && usage[canonical] !== usage[alias])
|
|
11624
|
-
return null;
|
|
11625
|
-
const value = hasCanonical ? usage[canonical] : usage[alias];
|
|
11626
|
-
return _isNonNegativeSafeInteger(value) ? value : null;
|
|
11627
|
-
}
|
|
11628
|
-
|
|
11629
|
-
function _optionalProviderUsageCount(usage, canonical, alias) {
|
|
11630
|
-
if (!usage || typeof usage !== "object" || Array.isArray(usage)) return null;
|
|
11631
|
-
const hasCanonical = Object.prototype.hasOwnProperty.call(usage, canonical);
|
|
11632
|
-
const hasAlias = Object.prototype.hasOwnProperty.call(usage, alias);
|
|
11633
|
-
if (!hasCanonical && !hasAlias) return 0;
|
|
11634
|
-
if (hasCanonical && hasAlias && usage[canonical] !== usage[alias])
|
|
11635
|
-
return null;
|
|
11636
|
-
const value = hasCanonical ? usage[canonical] : usage[alias];
|
|
11637
|
-
return _isNonNegativeSafeInteger(value) ? value : null;
|
|
11638
|
-
}
|
|
11639
|
-
|
|
11640
|
-
function _hasCompleteProviderUsage(usage) {
|
|
11641
|
-
return (
|
|
11642
|
-
_providerUsageCount(usage, "input_tokens", "prompt_tokens") != null &&
|
|
11643
|
-
_providerUsageCount(usage, "output_tokens", "completion_tokens") != null &&
|
|
11644
|
-
_optionalProviderUsageCount(
|
|
11645
|
-
usage,
|
|
11646
|
-
"cache_read_input_tokens",
|
|
11647
|
-
"cache_read_tokens",
|
|
11648
|
-
) != null &&
|
|
11649
|
-
_optionalProviderUsageCount(
|
|
11650
|
-
usage,
|
|
11651
|
-
"cache_creation_input_tokens",
|
|
11652
|
-
"cache_creation_tokens",
|
|
11653
|
-
) != null
|
|
11654
|
-
);
|
|
11655
|
-
}
|
|
11656
|
-
|
|
11657
11684
|
const PROVIDER_REQUEST_ID_RE = /^[\x21-\x7e]{1,512}$/;
|
|
11658
|
-
const PROVIDER_RECEIPT_ID_RE = /^[A-Za-z0-9._:-]{1,256}$/;
|
|
11659
11685
|
|
|
11660
11686
|
function _normalizeProviderRequestId(value) {
|
|
11661
11687
|
if (value == null) return null;
|
|
@@ -11675,12 +11701,6 @@ function _physicalProviderRequestId(logicalRequestId, attempt) {
|
|
|
11675
11701
|
return `${logicalRequestId.slice(0, 512 - suffix.length)}${suffix}`;
|
|
11676
11702
|
}
|
|
11677
11703
|
|
|
11678
|
-
function _providerReceiptId(value) {
|
|
11679
|
-
return typeof value === "string" && PROVIDER_RECEIPT_ID_RE.test(value)
|
|
11680
|
-
? value
|
|
11681
|
-
: null;
|
|
11682
|
-
}
|
|
11683
|
-
|
|
11684
11704
|
function _isOfficialOpenAIEndpoint(provider, baseUrl) {
|
|
11685
11705
|
if (provider !== "openai") return false;
|
|
11686
11706
|
try {
|
|
@@ -12101,9 +12121,10 @@ export async function chatWithTools(rawMessages, options) {
|
|
|
12101
12121
|
model: effectiveModel,
|
|
12102
12122
|
messages,
|
|
12103
12123
|
tools,
|
|
12104
|
-
maxOutputTokens:
|
|
12105
|
-
reasoning: _openAIResponsesReasoningParams(options),
|
|
12124
|
+
maxOutputTokens: modelProfile.requestMaxOutputTokens,
|
|
12125
|
+
reasoning: _openAIResponsesReasoningParams(options, modelProfile),
|
|
12106
12126
|
stream: typeof options.onToken === "function",
|
|
12127
|
+
modelProfile,
|
|
12107
12128
|
});
|
|
12108
12129
|
if (typeof options.onToken === "function") {
|
|
12109
12130
|
return await _retryStreamingChat(
|
|
@@ -12719,179 +12740,6 @@ async function _chatOllamaStreaming(
|
|
|
12719
12740
|
return _ollamaFinalize(state);
|
|
12720
12741
|
}
|
|
12721
12742
|
|
|
12722
|
-
// ─── Anthropic streaming (SSE → {message, usage}, tool_use reassembled) ──────
|
|
12723
|
-
//
|
|
12724
|
-
// Anthropic /messages with stream:true emits SSE: message_start (input usage),
|
|
12725
|
-
// content_block_start (text or tool_use header), content_block_delta
|
|
12726
|
-
// (text_delta → onToken, or input_json_delta accumulating a tool's JSON args),
|
|
12727
|
-
// message_delta (output usage). We reduce per `data:` line and finalize into
|
|
12728
|
-
// the same shape chatWithTools returns non-streamed.
|
|
12729
|
-
|
|
12730
|
-
function _anthropicInitState() {
|
|
12731
|
-
return {
|
|
12732
|
-
text: "",
|
|
12733
|
-
blocks: {},
|
|
12734
|
-
inputTokens: null,
|
|
12735
|
-
outputTokens: null,
|
|
12736
|
-
cacheReadTokens: 0,
|
|
12737
|
-
cacheCreationTokens: 0,
|
|
12738
|
-
usageInvalid: false,
|
|
12739
|
-
};
|
|
12740
|
-
}
|
|
12741
|
-
|
|
12742
|
-
function _anthropicReduceLine(state, raw, onToken, onThinking) {
|
|
12743
|
-
const line = (raw || "").trim();
|
|
12744
|
-
if (!line.startsWith("data:")) return state;
|
|
12745
|
-
const payload = line.slice(5).trim();
|
|
12746
|
-
if (!payload) return state;
|
|
12747
|
-
let obj;
|
|
12748
|
-
try {
|
|
12749
|
-
obj = JSON.parse(payload);
|
|
12750
|
-
} catch {
|
|
12751
|
-
return state;
|
|
12752
|
-
}
|
|
12753
|
-
if (obj.type === "message_start") {
|
|
12754
|
-
const usage = obj.message?.usage;
|
|
12755
|
-
if (usage != null) {
|
|
12756
|
-
const inputTokens = _providerUsageCount(
|
|
12757
|
-
usage,
|
|
12758
|
-
"input_tokens",
|
|
12759
|
-
"prompt_tokens",
|
|
12760
|
-
);
|
|
12761
|
-
const cacheReadTokens = _optionalProviderUsageCount(
|
|
12762
|
-
usage,
|
|
12763
|
-
"cache_read_input_tokens",
|
|
12764
|
-
"cache_read_tokens",
|
|
12765
|
-
);
|
|
12766
|
-
const cacheCreationTokens = _optionalProviderUsageCount(
|
|
12767
|
-
usage,
|
|
12768
|
-
"cache_creation_input_tokens",
|
|
12769
|
-
"cache_creation_tokens",
|
|
12770
|
-
);
|
|
12771
|
-
if (
|
|
12772
|
-
inputTokens == null ||
|
|
12773
|
-
cacheReadTokens == null ||
|
|
12774
|
-
cacheCreationTokens == null
|
|
12775
|
-
) {
|
|
12776
|
-
state.usageInvalid = true;
|
|
12777
|
-
} else {
|
|
12778
|
-
state.inputTokens = inputTokens;
|
|
12779
|
-
state.cacheReadTokens = cacheReadTokens;
|
|
12780
|
-
state.cacheCreationTokens = cacheCreationTokens;
|
|
12781
|
-
}
|
|
12782
|
-
}
|
|
12783
|
-
} else if (obj.type === "content_block_start") {
|
|
12784
|
-
const cb = obj.content_block || {};
|
|
12785
|
-
state.blocks[obj.index] =
|
|
12786
|
-
cb.type === "tool_use"
|
|
12787
|
-
? { type: "tool_use", id: cb.id, name: cb.name, json: "" }
|
|
12788
|
-
: cb.type === "thinking"
|
|
12789
|
-
? { type: "thinking", thinking: "", signature: "" }
|
|
12790
|
-
: cb.type === "redacted_thinking"
|
|
12791
|
-
? { type: "redacted_thinking", data: cb.data || "" }
|
|
12792
|
-
: { type: "text" };
|
|
12793
|
-
} else if (obj.type === "content_block_delta") {
|
|
12794
|
-
const d = obj.delta || {};
|
|
12795
|
-
if (d.type === "text_delta" && d.text) {
|
|
12796
|
-
state.text += d.text;
|
|
12797
|
-
if (typeof onToken === "function") {
|
|
12798
|
-
try {
|
|
12799
|
-
onToken(d.text);
|
|
12800
|
-
} catch {
|
|
12801
|
-
// a failing UI hook must never break the run
|
|
12802
|
-
}
|
|
12803
|
-
}
|
|
12804
|
-
} else if (d.type === "input_json_delta" && state.blocks[obj.index]) {
|
|
12805
|
-
state.blocks[obj.index].json += d.partial_json || "";
|
|
12806
|
-
} else if (d.type === "thinking_delta" && state.blocks[obj.index]) {
|
|
12807
|
-
state.blocks[obj.index].thinking =
|
|
12808
|
-
(state.blocks[obj.index].thinking || "") + (d.thinking || "");
|
|
12809
|
-
if (typeof onThinking === "function" && d.thinking) {
|
|
12810
|
-
try {
|
|
12811
|
-
onThinking(d.thinking);
|
|
12812
|
-
} catch {
|
|
12813
|
-
// a failing UI hook must never break the run
|
|
12814
|
-
}
|
|
12815
|
-
}
|
|
12816
|
-
} else if (d.type === "signature_delta" && state.blocks[obj.index]) {
|
|
12817
|
-
state.blocks[obj.index].signature =
|
|
12818
|
-
(state.blocks[obj.index].signature || "") + (d.signature || "");
|
|
12819
|
-
}
|
|
12820
|
-
} else if (obj.type === "message_delta") {
|
|
12821
|
-
if (obj.usage != null) {
|
|
12822
|
-
const outputTokens = _providerUsageCount(
|
|
12823
|
-
obj.usage,
|
|
12824
|
-
"output_tokens",
|
|
12825
|
-
"completion_tokens",
|
|
12826
|
-
);
|
|
12827
|
-
if (outputTokens == null) {
|
|
12828
|
-
state.usageInvalid = true;
|
|
12829
|
-
} else {
|
|
12830
|
-
state.outputTokens = outputTokens;
|
|
12831
|
-
}
|
|
12832
|
-
}
|
|
12833
|
-
}
|
|
12834
|
-
return state;
|
|
12835
|
-
}
|
|
12836
|
-
|
|
12837
|
-
function _anthropicFinalize(state) {
|
|
12838
|
-
const toolCalls = [];
|
|
12839
|
-
const thinkingBlocks = [];
|
|
12840
|
-
for (const k of Object.keys(state.blocks).sort(
|
|
12841
|
-
(a, b) => Number(a) - Number(b),
|
|
12842
|
-
)) {
|
|
12843
|
-
const b = state.blocks[k];
|
|
12844
|
-
if (b.type === "tool_use") {
|
|
12845
|
-
let input = {};
|
|
12846
|
-
try {
|
|
12847
|
-
input = b.json ? JSON.parse(b.json) : {};
|
|
12848
|
-
} catch {
|
|
12849
|
-
input = {};
|
|
12850
|
-
}
|
|
12851
|
-
toolCalls.push({
|
|
12852
|
-
id: b.id,
|
|
12853
|
-
type: "function",
|
|
12854
|
-
function: { name: b.name, arguments: JSON.stringify(input) },
|
|
12855
|
-
});
|
|
12856
|
-
} else if (b.type === "thinking") {
|
|
12857
|
-
thinkingBlocks.push({
|
|
12858
|
-
type: "thinking",
|
|
12859
|
-
thinking: b.thinking || "",
|
|
12860
|
-
signature: b.signature || "",
|
|
12861
|
-
});
|
|
12862
|
-
} else if (b.type === "redacted_thinking") {
|
|
12863
|
-
thinkingBlocks.push({ type: "redacted_thinking", data: b.data || "" });
|
|
12864
|
-
}
|
|
12865
|
-
}
|
|
12866
|
-
const message = { role: "assistant", content: state.text };
|
|
12867
|
-
if (toolCalls.length) message.tool_calls = toolCalls;
|
|
12868
|
-
// Preserve thinking blocks verbatim (incl. signature) for replay on the next
|
|
12869
|
-
// tool turn — required by the API when extended thinking is on.
|
|
12870
|
-
if (thinkingBlocks.length) message._thinkingBlocks = thinkingBlocks;
|
|
12871
|
-
const out = { message };
|
|
12872
|
-
if (
|
|
12873
|
-
state.usageInvalid !== true &&
|
|
12874
|
-
_isNonNegativeSafeInteger(state.inputTokens) &&
|
|
12875
|
-
_isNonNegativeSafeInteger(state.outputTokens)
|
|
12876
|
-
) {
|
|
12877
|
-
out.usage = {
|
|
12878
|
-
input_tokens: state.inputTokens,
|
|
12879
|
-
output_tokens: state.outputTokens,
|
|
12880
|
-
cache_read_input_tokens: state.cacheReadTokens,
|
|
12881
|
-
cache_creation_input_tokens: state.cacheCreationTokens,
|
|
12882
|
-
};
|
|
12883
|
-
}
|
|
12884
|
-
return out;
|
|
12885
|
-
}
|
|
12886
|
-
|
|
12887
|
-
/** Pure reducer over Anthropic SSE lines — exported for tests (no HTTP). */
|
|
12888
|
-
export function _accumulateAnthropicStream(lines, onToken, onThinking) {
|
|
12889
|
-
const state = _anthropicInitState();
|
|
12890
|
-
for (const line of lines)
|
|
12891
|
-
_anthropicReduceLine(state, line, onToken, onThinking);
|
|
12892
|
-
return _anthropicFinalize(state);
|
|
12893
|
-
}
|
|
12894
|
-
|
|
12895
12743
|
async function _chatAnthropicStreaming(
|
|
12896
12744
|
apiUrl,
|
|
12897
12745
|
body,
|
|
@@ -12943,156 +12791,6 @@ async function _chatAnthropicStreaming(
|
|
|
12943
12791
|
return _anthropicFinalize(state);
|
|
12944
12792
|
}
|
|
12945
12793
|
|
|
12946
|
-
// ─── OpenAI-compatible streaming (SSE → {message, usage}) ────────────────────
|
|
12947
|
-
//
|
|
12948
|
-
// `data:` lines carry choices[0].delta.{content, tool_calls[]}; tool_calls
|
|
12949
|
-
// arrive fragmented and keyed by `index` (name in the first chunk, arguments
|
|
12950
|
-
// concatenated across chunks). usage rides the terminal chunk when
|
|
12951
|
-
// stream_options.include_usage was requested. Terminator: `data: [DONE]`.
|
|
12952
|
-
|
|
12953
|
-
// OpenAI-compatible cached-prompt-token count. OpenAI / volcengine report it as
|
|
12954
|
-
// usage.prompt_tokens_details.cached_tokens; DeepSeek as
|
|
12955
|
-
// usage.prompt_cache_hit_tokens. In BOTH, prompt_tokens already INCLUDES the
|
|
12956
|
-
// cached count (unlike Anthropic, where input_tokens is the uncached remainder)
|
|
12957
|
-
// — so callers subtract it to recover the uncached input and avoid pricing the
|
|
12958
|
-
// cached prefix twice. Verified live against volcengine (field present, 0 when
|
|
12959
|
-
// the provider does not auto-cache).
|
|
12960
|
-
function _openaiCachedTokens(usage) {
|
|
12961
|
-
if (!usage || typeof usage !== "object" || Array.isArray(usage)) return null;
|
|
12962
|
-
const candidates = [];
|
|
12963
|
-
const hasDirect =
|
|
12964
|
-
Object.prototype.hasOwnProperty.call(usage, "cache_read_input_tokens") ||
|
|
12965
|
-
Object.prototype.hasOwnProperty.call(usage, "cache_read_tokens");
|
|
12966
|
-
if (hasDirect) {
|
|
12967
|
-
const direct = _optionalProviderUsageCount(
|
|
12968
|
-
usage,
|
|
12969
|
-
"cache_read_input_tokens",
|
|
12970
|
-
"cache_read_tokens",
|
|
12971
|
-
);
|
|
12972
|
-
if (direct == null) return null;
|
|
12973
|
-
candidates.push(direct);
|
|
12974
|
-
}
|
|
12975
|
-
|
|
12976
|
-
if (Object.prototype.hasOwnProperty.call(usage, "prompt_tokens_details")) {
|
|
12977
|
-
const details = usage.prompt_tokens_details;
|
|
12978
|
-
if (!details || typeof details !== "object" || Array.isArray(details)) {
|
|
12979
|
-
return null;
|
|
12980
|
-
}
|
|
12981
|
-
if (Object.prototype.hasOwnProperty.call(details, "cached_tokens")) {
|
|
12982
|
-
if (!_isNonNegativeSafeInteger(details.cached_tokens)) return null;
|
|
12983
|
-
candidates.push(details.cached_tokens);
|
|
12984
|
-
}
|
|
12985
|
-
}
|
|
12986
|
-
|
|
12987
|
-
if (Object.prototype.hasOwnProperty.call(usage, "prompt_cache_hit_tokens")) {
|
|
12988
|
-
if (!_isNonNegativeSafeInteger(usage.prompt_cache_hit_tokens)) return null;
|
|
12989
|
-
candidates.push(usage.prompt_cache_hit_tokens);
|
|
12990
|
-
}
|
|
12991
|
-
|
|
12992
|
-
if (candidates.some((value) => value !== candidates[0])) return null;
|
|
12993
|
-
return candidates[0] ?? 0;
|
|
12994
|
-
}
|
|
12995
|
-
|
|
12996
|
-
function _openaiInitState() {
|
|
12997
|
-
return {
|
|
12998
|
-
responseId: null,
|
|
12999
|
-
text: "",
|
|
13000
|
-
tools: [],
|
|
13001
|
-
inputTokens: null,
|
|
13002
|
-
outputTokens: null,
|
|
13003
|
-
cacheReadTokens: 0,
|
|
13004
|
-
usageInvalid: false,
|
|
13005
|
-
};
|
|
13006
|
-
}
|
|
13007
|
-
|
|
13008
|
-
function _openaiReduceLine(state, raw, onToken) {
|
|
13009
|
-
const line = (raw || "").trim();
|
|
13010
|
-
if (!line.startsWith("data:")) return state;
|
|
13011
|
-
const payload = line.slice(5).trim();
|
|
13012
|
-
if (!payload || payload === "[DONE]") return state;
|
|
13013
|
-
let obj;
|
|
13014
|
-
try {
|
|
13015
|
-
obj = JSON.parse(payload);
|
|
13016
|
-
} catch {
|
|
13017
|
-
return state;
|
|
13018
|
-
}
|
|
13019
|
-
if (!state.responseId) state.responseId = _providerReceiptId(obj.id);
|
|
13020
|
-
const delta = obj.choices?.[0]?.delta;
|
|
13021
|
-
if (delta?.content) {
|
|
13022
|
-
state.text += delta.content;
|
|
13023
|
-
if (typeof onToken === "function") {
|
|
13024
|
-
try {
|
|
13025
|
-
onToken(delta.content);
|
|
13026
|
-
} catch {
|
|
13027
|
-
// a failing UI hook must never break the run
|
|
13028
|
-
}
|
|
13029
|
-
}
|
|
13030
|
-
}
|
|
13031
|
-
if (Array.isArray(delta?.tool_calls)) {
|
|
13032
|
-
for (const tc of delta.tool_calls) {
|
|
13033
|
-
const idx = tc.index ?? 0;
|
|
13034
|
-
if (!state.tools[idx])
|
|
13035
|
-
state.tools[idx] = { id: undefined, name: "", args: "" };
|
|
13036
|
-
if (tc.id) state.tools[idx].id = tc.id;
|
|
13037
|
-
if (tc.function?.name) state.tools[idx].name = tc.function.name;
|
|
13038
|
-
if (tc.function?.arguments)
|
|
13039
|
-
state.tools[idx].args += tc.function.arguments;
|
|
13040
|
-
}
|
|
13041
|
-
}
|
|
13042
|
-
if (obj.usage != null) {
|
|
13043
|
-
const usage = obj.usage;
|
|
13044
|
-
const prompt = _providerUsageCount(usage, "input_tokens", "prompt_tokens");
|
|
13045
|
-
const completion = _providerUsageCount(
|
|
13046
|
-
usage,
|
|
13047
|
-
"output_tokens",
|
|
13048
|
-
"completion_tokens",
|
|
13049
|
-
);
|
|
13050
|
-
const cached = _openaiCachedTokens(obj.usage);
|
|
13051
|
-
if (
|
|
13052
|
-
!_hasCompleteProviderUsage(usage) ||
|
|
13053
|
-
cached == null ||
|
|
13054
|
-
cached > prompt
|
|
13055
|
-
) {
|
|
13056
|
-
state.usageInvalid = true;
|
|
13057
|
-
} else {
|
|
13058
|
-
state.inputTokens = Math.max(0, prompt - cached);
|
|
13059
|
-
state.outputTokens = completion;
|
|
13060
|
-
state.cacheReadTokens = cached;
|
|
13061
|
-
}
|
|
13062
|
-
}
|
|
13063
|
-
return state;
|
|
13064
|
-
}
|
|
13065
|
-
|
|
13066
|
-
function _openaiFinalize(state) {
|
|
13067
|
-
const toolCalls = state.tools.filter(Boolean).map((t) => ({
|
|
13068
|
-
id: t.id || `call_${t.name || "tool"}`,
|
|
13069
|
-
type: "function",
|
|
13070
|
-
function: { name: t.name, arguments: t.args || "{}" },
|
|
13071
|
-
}));
|
|
13072
|
-
const message = { role: "assistant", content: state.text };
|
|
13073
|
-
if (toolCalls.length) message.tool_calls = toolCalls;
|
|
13074
|
-
const out = { message };
|
|
13075
|
-
if (
|
|
13076
|
-
state.usageInvalid !== true &&
|
|
13077
|
-
_isNonNegativeSafeInteger(state.inputTokens) &&
|
|
13078
|
-
_isNonNegativeSafeInteger(state.outputTokens)
|
|
13079
|
-
) {
|
|
13080
|
-
out.usage = {
|
|
13081
|
-
input_tokens: state.inputTokens,
|
|
13082
|
-
output_tokens: state.outputTokens,
|
|
13083
|
-
cache_read_input_tokens: state.cacheReadTokens,
|
|
13084
|
-
};
|
|
13085
|
-
}
|
|
13086
|
-
return out;
|
|
13087
|
-
}
|
|
13088
|
-
|
|
13089
|
-
/** Pure reducer over OpenAI-compatible SSE lines — exported for tests. */
|
|
13090
|
-
export function _accumulateOpenAIStream(lines, onToken) {
|
|
13091
|
-
const state = _openaiInitState();
|
|
13092
|
-
for (const line of lines) _openaiReduceLine(state, line, onToken);
|
|
13093
|
-
return _openaiFinalize(state);
|
|
13094
|
-
}
|
|
13095
|
-
|
|
13096
12794
|
async function _chatOpenAIStreaming(
|
|
13097
12795
|
apiUrl,
|
|
13098
12796
|
body,
|
|
@@ -13343,28 +13041,11 @@ function _intensityToEffort(want) {
|
|
|
13343
13041
|
}
|
|
13344
13042
|
|
|
13345
13043
|
/** Build an opt-in Responses reasoning request without changing default cost. */
|
|
13346
|
-
export function _openAIResponsesReasoningParams(
|
|
13347
|
-
|
|
13348
|
-
|
|
13349
|
-
|
|
13350
|
-
|
|
13351
|
-
"minimal",
|
|
13352
|
-
"low",
|
|
13353
|
-
"medium",
|
|
13354
|
-
"high",
|
|
13355
|
-
"xhigh",
|
|
13356
|
-
]);
|
|
13357
|
-
const requested =
|
|
13358
|
-
typeof options.thinkingEffort === "string"
|
|
13359
|
-
? options.thinkingEffort.toLowerCase()
|
|
13360
|
-
: null;
|
|
13361
|
-
return {
|
|
13362
|
-
effort:
|
|
13363
|
-
requested && allowed.has(requested)
|
|
13364
|
-
? requested
|
|
13365
|
-
: _intensityToEffort(want),
|
|
13366
|
-
summary: "auto",
|
|
13367
|
-
};
|
|
13044
|
+
export function _openAIResponsesReasoningParams(
|
|
13045
|
+
options = {},
|
|
13046
|
+
modelProfile = null,
|
|
13047
|
+
) {
|
|
13048
|
+
return createOpenAIResponsesReasoning(options, modelProfile);
|
|
13368
13049
|
}
|
|
13369
13050
|
|
|
13370
13051
|
/**
|
|
@@ -1027,15 +1027,20 @@ async function runAgentHeadlessInWorkspace(
|
|
|
1027
1027
|
let managedSettings = null;
|
|
1028
1028
|
let settingsFiles = [];
|
|
1029
1029
|
if (!hermeticExecution) {
|
|
1030
|
-
const {
|
|
1031
|
-
|
|
1030
|
+
const {
|
|
1031
|
+
createPermissionRulesProvider,
|
|
1032
|
+
loadPermissionAuthority,
|
|
1033
|
+
permissionRulesProviderAuthority,
|
|
1034
|
+
} = await import("../lib/permission-authority.js");
|
|
1032
1035
|
const authorityOptions = {
|
|
1033
1036
|
cwd,
|
|
1034
1037
|
settingsFile: options.settingsFile,
|
|
1035
1038
|
managedSettingsFile: options.managedSettingsFile,
|
|
1036
1039
|
baseRules: options.permissionRules || null,
|
|
1037
1040
|
};
|
|
1038
|
-
const loaded =
|
|
1041
|
+
const loaded = permissionRulesProviderAuthority(permissionRulesProvider)
|
|
1042
|
+
? permissionRulesProvider()
|
|
1043
|
+
: loadPermissionAuthority(authorityOptions);
|
|
1039
1044
|
managedSettings = loaded.managed;
|
|
1040
1045
|
settingsFiles = Array.isArray(loaded.files) ? loaded.files : [];
|
|
1041
1046
|
permissionRules = loaded.hasRules ? loaded.rules : null;
|
|
@@ -1930,15 +1930,22 @@ async function runAgentHeadlessStreamInWorkspace(
|
|
|
1930
1930
|
let permissionRulesProvider = options.permissionRulesProvider || null;
|
|
1931
1931
|
let managedSettings = null;
|
|
1932
1932
|
let settingsFiles = [];
|
|
1933
|
-
const {
|
|
1934
|
-
|
|
1933
|
+
const {
|
|
1934
|
+
createPermissionRulesProvider,
|
|
1935
|
+
loadPermissionAuthority,
|
|
1936
|
+
permissionRulesProviderAuthority,
|
|
1937
|
+
} = await import("../lib/permission-authority.js");
|
|
1935
1938
|
const authorityOptions = {
|
|
1936
1939
|
cwd,
|
|
1937
1940
|
settingsFile: options.settingsFile,
|
|
1938
1941
|
managedSettingsFile: options.managedSettingsFile,
|
|
1939
1942
|
baseRules: options.permissionRules || null,
|
|
1940
1943
|
};
|
|
1941
|
-
const loadedPermissionAuthority =
|
|
1944
|
+
const loadedPermissionAuthority = permissionRulesProviderAuthority(
|
|
1945
|
+
permissionRulesProvider,
|
|
1946
|
+
)
|
|
1947
|
+
? permissionRulesProvider()
|
|
1948
|
+
: loadPermissionAuthority(authorityOptions);
|
|
1942
1949
|
managedSettings = loadedPermissionAuthority.managed;
|
|
1943
1950
|
settingsFiles = Array.isArray(loadedPermissionAuthority.files)
|
|
1944
1951
|
? loadedPermissionAuthority.files
|