chainlesschain 0.166.84 → 0.166.86
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 +17 -4
- 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-OYLnAlB5.js → AIOps-DZwiXAIh.js} +1 -1
- package/src/assets/web-panel/assets/{ActionButton-uc9kbLR6.js → ActionButton-aNzXoIJP.js} +1 -1
- package/src/assets/web-panel/assets/{Analytics-BH901FG0.js → Analytics-ETQk4ZXt.js} +3 -3
- package/src/assets/web-panel/assets/{AppLayout-qypKb8GL.js → AppLayout-D5oEbeEC.js} +4 -4
- package/src/assets/web-panel/assets/{Artifacts-Q-uPWyLY.js → Artifacts-ja48FAne.js} +1 -1
- package/src/assets/web-panel/assets/{Audit-B8hMGMim.js → Audit-DlN0YnDt.js} +1 -1
- package/src/assets/web-panel/assets/{BackgroundAgents-BSs8rJL_.js → BackgroundAgents-CzvyNsRg.js} +1 -1
- package/src/assets/web-panel/assets/{Backup-2YMU_nCd.js → Backup-DXgEC2MQ.js} +1 -1
- package/src/assets/web-panel/assets/{BaseInput-DyMppTuT.js → BaseInput-D9XqejLx.js} +1 -1
- package/src/assets/web-panel/assets/{Chat-B5QGMaDO.js → Chat-BTwuYUlN.js} +5 -5
- package/src/assets/web-panel/assets/{ChatBubbleRenderer-B8ts_JnN.js → ChatBubbleRenderer-0anIC2Wn.js} +1 -1
- package/src/assets/web-panel/assets/{Checkbox-DAvtgEGd.js → Checkbox-CLuaQbDt.js} +1 -1
- package/src/assets/web-panel/assets/{Codegen-BSChEVM3.js → Codegen-KwQUZs8A.js} +1 -1
- package/src/assets/web-panel/assets/{Col-G0zYohIP.js → Col-BCmROkzc.js} +1 -1
- package/src/assets/web-panel/assets/{Community-CzCN0B_p.js → Community-CXlUEHR4.js} +1 -1
- package/src/assets/web-panel/assets/{Compact-DrIN3G8z.js → Compact-Dzx-lWI2.js} +1 -1
- package/src/assets/web-panel/assets/{Compliance-CIsLa64Z.js → Compliance-CfXW82FF.js} +1 -1
- package/src/assets/web-panel/assets/{Cowork-CGYoafsB.js → Cowork-DIISTRm2.js} +3 -3
- package/src/assets/web-panel/assets/{Cron-DJ1JPXuH.js → Cron-nyJ-KcFE.js} +2 -2
- package/src/assets/web-panel/assets/{Crosschain-B-IqVFJl.js → Crosschain-Dtv1E4cV.js} +1 -1
- package/src/assets/web-panel/assets/{DID-CAAczPz_.js → DID-BCTpektS.js} +2 -2
- package/src/assets/web-panel/assets/{Dashboard-Dkpel8VE.js → Dashboard-C1Q_m0So.js} +2 -2
- package/src/assets/web-panel/assets/{Dropdown-ETNBf8-Z.js → Dropdown-BrQ5_PPL.js} +1 -1
- package/src/assets/web-panel/assets/{EmailListRenderer-CJGDyjVD.js → EmailListRenderer-DjoNlONP.js} +1 -1
- package/src/assets/web-panel/assets/{EvolutionSettings-CL_hvVYe.js → EvolutionSettings-DaGaE6bX.js} +1 -1
- package/src/assets/web-panel/assets/{FamilyGuardDashboard-iexOh6Dh.js → FamilyGuardDashboard-nJDWBECt.js} +1 -1
- package/src/assets/web-panel/assets/{Federation-DnDHvV5D.js → Federation-DhMUY_wG.js} +1 -1
- package/src/assets/web-panel/assets/{FormItemContext-DLCDJjUp.js → FormItemContext-CbONJPuc.js} +1 -1
- package/src/assets/web-panel/assets/{GenericCardRenderer-CaCgXCjS.js → GenericCardRenderer-CDdX4dX-.js} +1 -1
- package/src/assets/web-panel/assets/{Git-BVm-euUF.js → Git-DXbDVJdR.js} +2 -2
- package/src/assets/web-panel/assets/{Governance-DPnUvLWr.js → Governance-DbAfAvs1.js} +1 -1
- package/src/assets/web-panel/assets/{Inference-5qCWSYKl.js → Inference-Dy-fGea2.js} +1 -1
- package/src/assets/web-panel/assets/{KnowledgeGraph-DXdv2oEh.js → KnowledgeGraph-DAxRpGUF.js} +1 -1
- package/src/assets/web-panel/assets/{Logs-BF2f7bBA.js → Logs-5L1UCR8X.js} +2 -2
- package/src/assets/web-panel/assets/MarkdownRenderer-u0FPafvT.js +1 -0
- package/src/assets/web-panel/assets/{Marketplace-Bp-0Y7Ng.js → Marketplace-DUk_McDG.js} +1 -1
- package/src/assets/web-panel/assets/{McpTools-dm-Xdi63.js → McpTools-B6PNsZ_p.js} +2 -2
- package/src/assets/web-panel/assets/{Memory-TBHK031z.js → Memory-BUUs8j5F.js} +2 -2
- package/src/assets/web-panel/assets/{MobileBridge-BTILAlds.js → MobileBridge-pXRsgyuO.js} +1 -1
- package/src/assets/web-panel/assets/{MobileProjects-DC0Clgzs.js → MobileProjects-D7v-2Hwm.js} +1 -1
- package/src/assets/web-panel/assets/{Mtc-BvyWkmRw.js → Mtc-Deaj4faB.js} +4 -4
- package/src/assets/web-panel/assets/{MtcAudit-D7ksLoNa.js → MtcAudit-wUV0VUH1.js} +2 -2
- package/src/assets/web-panel/assets/{Multisig-Dpzu7X1t.js → Multisig-C67IIkts.js} +3 -3
- package/src/assets/web-panel/assets/{NLProgramming-DZ0ADHSB.js → NLProgramming-BCA_CWrW.js} +1 -1
- package/src/assets/web-panel/assets/{Notes-hIdkmRug.js → Notes-D9eu14hQ.js} +4 -4
- package/src/assets/web-panel/assets/{NotificationSettings-R3jyP6Vf.js → NotificationSettings-Cnd-J4LM.js} +1 -1
- package/src/assets/web-panel/assets/{OrderTableRenderer-d1zrFkqx.js → OrderTableRenderer-C4pHUuyZ.js} +1 -1
- package/src/assets/web-panel/assets/{Organization-DoA5WMcc.js → Organization-4YExAbnp.js} +4 -4
- package/src/assets/web-panel/assets/{Overflow-DHjIloAQ.js → Overflow-BF-wFuZz.js} +1 -1
- package/src/assets/web-panel/assets/{P2P-2TMon_Wy.js → P2P-CdiajqCT.js} +2 -2
- package/src/assets/web-panel/assets/{PdhVaultBrowser-DEUxGSWO.js → PdhVaultBrowser-BkjfS6Th.js} +5 -5
- package/src/assets/web-panel/assets/{Permissions-CxKcZ-8X.js → Permissions-DrZ4D78_.js} +4 -4
- package/src/assets/web-panel/assets/{PersonalDataHub-CcYtkHqc.js → PersonalDataHub-lDc6OXjz.js} +6 -6
- package/src/assets/web-panel/assets/{Pipeline-BxwOuq22.js → Pipeline-DqDS9ON1.js} +1 -1
- package/src/assets/web-panel/assets/{Privacy-VIx9pdsH.js → Privacy-BMekZRZu.js} +1 -1
- package/src/assets/web-panel/assets/{ProjectInit-COjp_erK.js → ProjectInit-LYS7NFvJ.js} +2 -2
- package/src/assets/web-panel/assets/{ProjectSettings-x9NrZU80.js → ProjectSettings-CcJNHk9A.js} +2 -2
- package/src/assets/web-panel/assets/{Projects-DMgkw7QJ.js → Projects-DrfAHgdF.js} +1 -1
- package/src/assets/web-panel/assets/{Providers-B_fR7Y7Y.js → Providers-aqsly9SR.js} +1 -1
- package/src/assets/web-panel/assets/{QrScannerModal-BUvzrn3V.js → QrScannerModal-ZWvR3zqg.js} +1 -1
- package/src/assets/web-panel/assets/{QuickAsk-C0sJwLy2.js → QuickAsk-BT5CgsvW.js} +1 -1
- package/src/assets/web-panel/assets/{Recommend-CJC7Wpce.js → Recommend-Cz8Dz2RN.js} +1 -1
- package/src/assets/web-panel/assets/{RemoteSession-B62J6ZP0.js → RemoteSession-BlxPVbtQ.js} +2 -2
- package/src/assets/web-panel/assets/{Reputation-4f48kVBn.js → Reputation-B3VGBE-1.js} +1 -1
- package/src/assets/web-panel/assets/{Row-EzEMaYoV.js → Row-Bwv7vSEA.js} +1 -1
- package/src/assets/web-panel/assets/{RssFeed-Dy0wD83j.js → RssFeed-DHI085r_.js} +3 -3
- package/src/assets/web-panel/assets/{Search-GeVRHQND.js → Search-DBler5T0.js} +1 -1
- package/src/assets/web-panel/assets/{Security-omLr1J7w.js → Security-BZdw43NW.js} +3 -3
- package/src/assets/web-panel/assets/{Services-DmGPaDAs.js → Services-Cslk5lUj.js} +2 -2
- package/src/assets/web-panel/assets/{Skeleton-CAla21Gm.js → Skeleton-Bur-C-25.js} +1 -1
- package/src/assets/web-panel/assets/Skills-v0zgLy0X.js +1 -0
- package/src/assets/web-panel/assets/{Sla-Cwi15-pZ.js → Sla-B1OWgQ51.js} +1 -1
- package/src/assets/web-panel/assets/{SpeechSettings-Cs8Zi1J8.js → SpeechSettings-CaBcEaV4.js} +1 -1
- package/src/assets/web-panel/assets/{SyncSettings-ipuJsDKP.js → SyncSettings-CBbG8L6J.js} +2 -2
- package/src/assets/web-panel/assets/Tasks-C7EjXrnN.js +1 -0
- package/src/assets/web-panel/assets/{Templates-slUp9yXF.js → Templates-VBBOZ1H5.js} +1 -1
- package/src/assets/web-panel/assets/{Tenant-6edCSG5K.js → Tenant-CtQTj7IF.js} +1 -1
- package/src/assets/web-panel/assets/{Terminal-DKq84G3h.js → Terminal-DXVTQjnl.js} +2 -2
- package/src/assets/web-panel/assets/{TimelineRenderer-Dg0Aw6se.js → TimelineRenderer-BRIno0aN.js} +1 -1
- package/src/assets/web-panel/assets/{Tokens-D63h7qYd.js → Tokens-uiiAfkYN.js} +1 -1
- package/src/assets/web-panel/assets/{Trigger-F7gTP_gv.js → Trigger-CPApN8o6.js} +1 -1
- package/src/assets/web-panel/assets/{Trust-zw8Zqp8k.js → Trust-T2jKVwCE.js} +1 -1
- package/src/assets/web-panel/assets/{UkeySign-C-YBUmod.js → UkeySign-C2U_gbzP.js} +1 -1
- package/src/assets/web-panel/assets/{VideoEditing-AhVxTgmC.js → VideoEditing-BCdlr3Kj.js} +1 -1
- package/src/assets/web-panel/assets/{Wallet-C58zxjIg.js → Wallet-CWnjoSc1.js} +4 -4
- package/src/assets/web-panel/assets/{WebAuthn-D-n-rlfI.js → WebAuthn-CqSbYqHq.js} +4 -4
- package/src/assets/web-panel/assets/{WorkflowEditor-Ddc8gGD4.js → WorkflowEditor-Dr_I3jcr.js} +1 -1
- package/src/assets/web-panel/assets/{chat-C66V_U7w.js → chat-Cg21FKdE.js} +1 -1
- package/src/assets/web-panel/assets/{colors-BcJyVZRj.js → colors-CK85tY9e.js} +1 -1
- package/src/assets/web-panel/assets/{compact-item-UgUXWcgP.js → compact-item-m-XYPC7W.js} +1 -1
- package/src/assets/web-panel/assets/{createContext-oxEKHKYP.js → createContext-BmiEeNvs.js} +1 -1
- package/src/assets/web-panel/assets/devWarning-CkMEODFC.js +1 -0
- package/src/assets/web-panel/assets/{hasIn-CbqzrKQO.js → hasIn-CCw4KAoc.js} +1 -1
- package/src/assets/web-panel/assets/{index-CH13yc9x.js → index-6jXf-Lln.js} +1 -1
- package/src/assets/web-panel/assets/{index-BdFgUn1S.js → index-8KzhlvJ9.js} +1 -1
- package/src/assets/web-panel/assets/{index-D3xNhHF3.js → index-B7xJkhtJ.js} +1 -1
- package/src/assets/web-panel/assets/{index-DAIuMvVR.js → index-B8IC9ZeZ.js} +1 -1
- package/src/assets/web-panel/assets/{index-CrG-1Kqs.js → index-BGUYgc96.js} +1 -1
- package/src/assets/web-panel/assets/{index-Bu1A2sXy.js → index-BGb1j2z9.js} +1 -1
- package/src/assets/web-panel/assets/{index-BQlGMcZ9.js → index-BHsiSoGY.js} +1 -1
- package/src/assets/web-panel/assets/{index-DWFNv_EG.js → index-BIOTRzaF.js} +1 -1
- package/src/assets/web-panel/assets/{index-BrWZmUdA.js → index-BStyjmLG.js} +1 -1
- package/src/assets/web-panel/assets/{index-C-p9hhAz.js → index-BUYyhYP6.js} +1 -1
- package/src/assets/web-panel/assets/{index-CM2S5TJZ.js → index-BcfVHmFK.js} +1 -1
- package/src/assets/web-panel/assets/{index-7lSY8B9T.js → index-BiVPFsat.js} +1 -1
- package/src/assets/web-panel/assets/index-BjE5qaKn.js +1 -0
- package/src/assets/web-panel/assets/{index-B-h0Jgtj.js → index-Br0ZNdu1.js} +1 -1
- package/src/assets/web-panel/assets/{index-D8rgeCoC.js → index-Br9t_I1X.js} +1 -1
- package/src/assets/web-panel/assets/{index-DRrxJygS.js → index-BtvVupUL.js} +1 -1
- package/src/assets/web-panel/assets/{index-DO-5vgTW.js → index-Bv90WEWa.js} +1 -1
- package/src/assets/web-panel/assets/{index-DBEL07sa.js → index-BvjC3t35.js} +1 -1
- package/src/assets/web-panel/assets/{index-UpN_kC9R.js → index-ByVvAXdl.js} +1 -1
- package/src/assets/web-panel/assets/{index-SzGgAqai.js → index-CBcgIWOe.js} +1 -1
- package/src/assets/web-panel/assets/{index-C3j9jTfB.js → index-CN2xbLGz.js} +1 -1
- package/src/assets/web-panel/assets/{index-Bmhw_Ler.js → index-CYEzWoyZ.js} +1 -1
- package/src/assets/web-panel/assets/{index-Crqqbu-W.js → index-Cf5arJie.js} +1 -1
- package/src/assets/web-panel/assets/index-CsFH-2Zk.js +1 -0
- package/src/assets/web-panel/assets/{index-BMOY4PSW.js → index-D1sU5-XA.js} +1 -1
- package/src/assets/web-panel/assets/{index-BT2PZ9df.js → index-D7gS_TJl.js} +1 -1
- package/src/assets/web-panel/assets/{index-YvNh1UdB.js → index-DAlGVix-.js} +1 -1
- package/src/assets/web-panel/assets/{index-BZ7mv_oS.js → index-DI9GJFcn.js} +1 -1
- package/src/assets/web-panel/assets/{index-Ov77O9mH.js → index-DIlGxS2W.js} +1 -1
- package/src/assets/web-panel/assets/{index-CJluGB2F.js → index-DMbrl43d.js} +1 -1
- package/src/assets/web-panel/assets/{index-C6X26RJu.js → index-DmSgfXuz.js} +1 -1
- package/src/assets/web-panel/assets/{index-DMbJ06sF.js → index-DpIy2HzE.js} +1 -1
- package/src/assets/web-panel/assets/{index-CUmYwZyf.js → index-DxRhnsEC.js} +1 -1
- package/src/assets/web-panel/assets/{index-BNIq0NAn.js → index-IskAKXhx.js} +1 -1
- package/src/assets/web-panel/assets/{index-DR4YKlLt.js → index-J81uvUMN.js} +1 -1
- package/src/assets/web-panel/assets/{index-RnxuL8wM.js → index-OIbfsi-o.js} +1 -1
- package/src/assets/web-panel/assets/{index-Bp9rfr-P.js → index-lhoexBDH.js} +1 -1
- package/src/assets/web-panel/assets/{index-BpqJNeIj.js → index-sWUmvT8H.js} +1 -1
- package/src/assets/web-panel/assets/{index-CuZupgUw.js → index-yYmjkf38.js} +3 -3
- package/src/assets/web-panel/assets/{initDefaultProps-BK9ncFiF.js → initDefaultProps-Cc1XOmNe.js} +1 -1
- package/src/assets/web-panel/assets/{motion-BxzXi1Pe.js → motion-BehsX88u.js} +1 -1
- package/src/assets/web-panel/assets/{move-CRmwRuah.js → move-BPx2YsqY.js} +1 -1
- package/src/assets/web-panel/assets/{mtc-parser-BQq5_Znx.js → mtc-parser-BSFJgFQA.js} +1 -1
- package/src/assets/web-panel/assets/{omit-Ch4VNY2j.js → omit-DBN5KUeo.js} +1 -1
- package/src/assets/web-panel/assets/{pickAttrs-CUioBhrz.js → pickAttrs-BDK1yZ-9.js} +1 -1
- package/src/assets/web-panel/assets/{placementArrow-Hj3o1CrW.js → placementArrow-C4rMmKNJ.js} +1 -1
- package/src/assets/web-panel/assets/{responsiveObserve-PfqJrlkI.js → responsiveObserve-BoeoOnxX.js} +1 -1
- package/src/assets/web-panel/assets/{slide-BXcnR-Lu.js → slide-BKlr1bl9.js} +1 -1
- package/src/assets/web-panel/assets/{statusUtils-C74a-ofo.js → statusUtils-Ky1apWPI.js} +1 -1
- package/src/assets/web-panel/assets/{styleChecker-Bq57I3ls.js → styleChecker-DxxR7uXk.js} +1 -1
- package/src/assets/web-panel/assets/{useFlexGapSupport-ITPUjcDw.js → useFlexGapSupport-DmsUqVe9.js} +1 -1
- package/src/assets/web-panel/assets/{useFs-DzPuXDIS.js → useFs-CwkG7sOg.js} +1 -1
- package/src/assets/web-panel/assets/{usePersonalDataHub-DYSgt9L5.js → usePersonalDataHub-CddgeEfF.js} +1 -1
- package/src/assets/web-panel/assets/{vnode-NPs_EJEk.js → vnode-C_-H8i4Y.js} +1 -1
- package/src/assets/web-panel/assets/{zoom-DZzO6KVS.js → zoom-aAsHUMNE.js} +1 -1
- package/src/assets/web-panel/index.html +1 -1
- package/src/commands/permissions.js +27 -2
- package/src/data/changelog.json +26 -0
- package/src/lib/background-interaction-resolver.js +4 -0
- package/src/lib/context-memory-kernel/durable-memory-port.js +71 -15
- package/src/lib/context-memory-kernel/index.js +1 -0
- package/src/lib/context-memory-kernel/memory-service.js +43 -16
- package/src/lib/context-memory-kernel/runtime.js +5 -3
- package/src/lib/context-memory-kernel/segmented-memory-port.js +687 -0
- package/src/lib/packer/pack-update-applier.js +41 -17
- package/src/lib/packer/pkg-config-generator.js +119 -2
- package/src/lib/packer/pkg-runner.js +7 -0
- package/src/lib/packer/pkg-targets.js +83 -0
- package/src/lib/packer/web-panel-builder.js +7 -0
- package/src/lib/permission-authority.js +157 -13
- package/src/lib/process-execution-broker/index.js +11 -0
- package/src/lib/process-execution-broker/linux-subreaper-helper.js +87 -13
- package/src/lib/process-execution-broker/packer-build-policy.js +31 -0
- package/src/lib/process-execution-broker/platform-sandbox.js +11 -3
- package/src/lib/sandbox-egress-authority-monitor.js +62 -5
- package/src/lib/scoped-permission-store.js +119 -6
- package/src/lib/settings-authority-domain.cjs +37 -2
- package/src/lib/settings-loader.cjs +112 -42
- package/src/lib/settings-permission-authority.cjs +373 -0
- package/src/runtime/agent-core.js +79 -383
- package/src/runtime/headless-runner.js +8 -3
- package/src/runtime/headless-stream.js +10 -3
- package/src/runtime/permission-authority-host.js +137 -0
- package/src/runtime/provider-stream-state.js +379 -0
- package/src/assets/web-panel/assets/MarkdownRenderer-qNJS3ygh.js +0 -1
- package/src/assets/web-panel/assets/Skills-QqEyIKOI.js +0 -1
- package/src/assets/web-panel/assets/Tasks-BbVAg9Z7.js +0 -1
- package/src/assets/web-panel/assets/devWarning-BoDvrsgY.js +0 -1
- package/src/assets/web-panel/assets/index-BhqRbl5P.js +0 -1
- package/src/assets/web-panel/assets/index-DreT6MIR.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,
|
|
@@ -2427,6 +2446,7 @@ function projectPermissionAuthority({ authority, rules, tool, args, cwd }) {
|
|
|
2427
2446
|
version: authority?.version || authority?.policyVersion || null,
|
|
2428
2447
|
revision: authority?.revision ?? null,
|
|
2429
2448
|
settingsRevision: authority?.settingsRevision || null,
|
|
2449
|
+
persistentSettingsRevision: authority?.persistentSettingsRevision || null,
|
|
2430
2450
|
headHash: authority?.headHash || null,
|
|
2431
2451
|
verdict: {
|
|
2432
2452
|
decision: verdict.decision || null,
|
|
@@ -2635,10 +2655,19 @@ export async function executeTool(name, args, context = {}) {
|
|
|
2635
2655
|
let settingsPermissionAuthority = null;
|
|
2636
2656
|
let entrySettingsPermissionRevision = null;
|
|
2637
2657
|
try {
|
|
2658
|
+
const providerAuthority = permissionRulesProviderAuthority(
|
|
2659
|
+
context.permissionRulesProvider,
|
|
2660
|
+
);
|
|
2661
|
+
providerAuthority?.assertWorkspace?.(context.cwd || process.cwd());
|
|
2662
|
+
providerAuthority?.assertWritableRoots?.([
|
|
2663
|
+
...workspaceRootsFor(
|
|
2664
|
+
path.resolve(context.cwd || process.cwd()),
|
|
2665
|
+
context.additionalDirectories,
|
|
2666
|
+
),
|
|
2667
|
+
...(context.sandbox?.policy?.allowWrite || []),
|
|
2668
|
+
]);
|
|
2638
2669
|
if (name === "run_shell") {
|
|
2639
|
-
settingsPermissionAuthority =
|
|
2640
|
-
context.permissionRulesProvider,
|
|
2641
|
-
);
|
|
2670
|
+
settingsPermissionAuthority = providerAuthority;
|
|
2642
2671
|
entrySettingsPermissionRevision =
|
|
2643
2672
|
settingsPermissionAuthority?.getSnapshot() || null;
|
|
2644
2673
|
}
|
|
@@ -2653,14 +2682,36 @@ export async function executeTool(name, args, context = {}) {
|
|
|
2653
2682
|
},
|
|
2654
2683
|
};
|
|
2655
2684
|
}
|
|
2685
|
+
function settingsPermissionRevocation(cause) {
|
|
2686
|
+
const error = new Error(
|
|
2687
|
+
"Settings permission authority became unavailable after admission",
|
|
2688
|
+
{ cause },
|
|
2689
|
+
);
|
|
2690
|
+
error.code = "CC_SHELL_POLICY_AUTHORITY_CHANGED";
|
|
2691
|
+
return error;
|
|
2692
|
+
}
|
|
2656
2693
|
function assertSettingsPermissionRevision() {
|
|
2657
2694
|
if (!settingsPermissionAuthority) return;
|
|
2695
|
+
let currentRevision;
|
|
2696
|
+
try {
|
|
2697
|
+
settingsPermissionAuthority.assertWorkspace?.(cwd);
|
|
2698
|
+
settingsPermissionAuthority.assertWritableRoots?.([
|
|
2699
|
+
...workspaceRootsFor(cwd, context.additionalDirectories),
|
|
2700
|
+
...(context.sandbox?.policy?.allowWrite || []),
|
|
2701
|
+
]);
|
|
2702
|
+
currentRevision = settingsPermissionAuthority.getSnapshot();
|
|
2703
|
+
} catch (cause) {
|
|
2704
|
+
// A concurrent durable writer can expose its guard/prepared state. Once
|
|
2705
|
+
// admitted, losing the ready snapshot revokes that admission immediately;
|
|
2706
|
+
// do not wait for commit or let the lower-level load error change the
|
|
2707
|
+
// shell revocation contract. Initial admission retains its load errors.
|
|
2708
|
+
throw settingsPermissionRevocation(cause);
|
|
2709
|
+
}
|
|
2658
2710
|
if (
|
|
2659
2711
|
permissionRulesProviderAuthority(
|
|
2660
2712
|
liveExecutionContext.permissionRulesProvider,
|
|
2661
2713
|
) !== settingsPermissionAuthority ||
|
|
2662
|
-
|
|
2663
|
-
entrySettingsPermissionRevision
|
|
2714
|
+
currentRevision !== entrySettingsPermissionRevision
|
|
2664
2715
|
) {
|
|
2665
2716
|
const error = new Error(
|
|
2666
2717
|
"Settings permission authority changed after admission",
|
|
@@ -3633,11 +3684,19 @@ export async function executeTool(name, args, context = {}) {
|
|
|
3633
3684
|
let currentPermissionRules =
|
|
3634
3685
|
liveExecutionContext.permissionRules || null;
|
|
3635
3686
|
if (permissionRulesProvider) {
|
|
3636
|
-
|
|
3637
|
-
|
|
3638
|
-
|
|
3639
|
-
|
|
3640
|
-
|
|
3687
|
+
try {
|
|
3688
|
+
currentPermissionAuthority = await permissionRulesProvider({
|
|
3689
|
+
cwd,
|
|
3690
|
+
tool: name,
|
|
3691
|
+
args,
|
|
3692
|
+
});
|
|
3693
|
+
} catch (cause) {
|
|
3694
|
+
// A writer may start after the preceding snapshot read but
|
|
3695
|
+
// before the bound provider finishes observing its sources.
|
|
3696
|
+
if (settingsPermissionAuthority)
|
|
3697
|
+
throw settingsPermissionRevocation(cause);
|
|
3698
|
+
throw cause;
|
|
3699
|
+
}
|
|
3641
3700
|
currentPermissionRules =
|
|
3642
3701
|
currentPermissionAuthority?.rules ||
|
|
3643
3702
|
currentPermissionAuthority ||
|
|
@@ -6946,6 +7005,9 @@ async function executeToolInner(
|
|
|
6946
7005
|
const { createDockerEgressAuthorityMonitor } =
|
|
6947
7006
|
await import("../lib/sandbox-egress-authority-monitor.js");
|
|
6948
7007
|
authorityMonitor = createDockerEgressAuthorityMonitor({
|
|
7008
|
+
sessionId: sessionId || null,
|
|
7009
|
+
policyVersion:
|
|
7010
|
+
shellDispatchPolicyAuthority?.policyVersion || null,
|
|
6949
7011
|
async revalidate() {
|
|
6950
7012
|
await shellDispatchPolicyAuthority?.revalidate?.();
|
|
6951
7013
|
shellDispatchPolicyAuthority?.revalidateDockerSandbox?.();
|
|
@@ -7139,6 +7201,13 @@ async function executeToolInner(
|
|
|
7139
7201
|
result.authorityFailure = {
|
|
7140
7202
|
code: revoked.code || "CC_DOCKER_EGRESS_AUTHORITY_CHANGED",
|
|
7141
7203
|
...(revoked.cleanupError ? { cleanupFailed: true } : {}),
|
|
7204
|
+
...(authorityMonitor.getStopAcknowledgement()
|
|
7205
|
+
? {
|
|
7206
|
+
stopAcknowledgement: {
|
|
7207
|
+
...authorityMonitor.getStopAcknowledgement(),
|
|
7208
|
+
},
|
|
7209
|
+
}
|
|
7210
|
+
: {}),
|
|
7142
7211
|
};
|
|
7143
7212
|
if (result.exitCode === 0) {
|
|
7144
7213
|
result = {
|
|
@@ -11611,51 +11680,7 @@ function getEffectiveToolDefinitions(options = {}) {
|
|
|
11611
11680
|
});
|
|
11612
11681
|
}
|
|
11613
11682
|
|
|
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
11683
|
const PROVIDER_REQUEST_ID_RE = /^[\x21-\x7e]{1,512}$/;
|
|
11658
|
-
const PROVIDER_RECEIPT_ID_RE = /^[A-Za-z0-9._:-]{1,256}$/;
|
|
11659
11684
|
|
|
11660
11685
|
function _normalizeProviderRequestId(value) {
|
|
11661
11686
|
if (value == null) return null;
|
|
@@ -11675,12 +11700,6 @@ function _physicalProviderRequestId(logicalRequestId, attempt) {
|
|
|
11675
11700
|
return `${logicalRequestId.slice(0, 512 - suffix.length)}${suffix}`;
|
|
11676
11701
|
}
|
|
11677
11702
|
|
|
11678
|
-
function _providerReceiptId(value) {
|
|
11679
|
-
return typeof value === "string" && PROVIDER_RECEIPT_ID_RE.test(value)
|
|
11680
|
-
? value
|
|
11681
|
-
: null;
|
|
11682
|
-
}
|
|
11683
|
-
|
|
11684
11703
|
function _isOfficialOpenAIEndpoint(provider, baseUrl) {
|
|
11685
11704
|
if (provider !== "openai") return false;
|
|
11686
11705
|
try {
|
|
@@ -12719,179 +12738,6 @@ async function _chatOllamaStreaming(
|
|
|
12719
12738
|
return _ollamaFinalize(state);
|
|
12720
12739
|
}
|
|
12721
12740
|
|
|
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
12741
|
async function _chatAnthropicStreaming(
|
|
12896
12742
|
apiUrl,
|
|
12897
12743
|
body,
|
|
@@ -12943,156 +12789,6 @@ async function _chatAnthropicStreaming(
|
|
|
12943
12789
|
return _anthropicFinalize(state);
|
|
12944
12790
|
}
|
|
12945
12791
|
|
|
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
12792
|
async function _chatOpenAIStreaming(
|
|
13097
12793
|
apiUrl,
|
|
13098
12794
|
body,
|
|
@@ -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
|